Skip to content

Commit

Permalink
Add Storybook
Browse files Browse the repository at this point in the history
  • Loading branch information
caleeli committed Feb 14, 2024
1 parent 1d74021 commit 273d2ef
Show file tree
Hide file tree
Showing 11 changed files with 17,080 additions and 4,430 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ module.exports = {
extends: [
"plugin:vue/recommended",
"airbnb-base",
"plugin:prettier/recommended"
"plugin:prettier/recommended",
"plugin:storybook/recommended"
],

parserOptions: {
Expand Down
18 changes: 18 additions & 0 deletions .storybook/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/** @type { import('@storybook/vue-vite').StorybookConfig } */
const config = {
stories: ["../src/**/*.mdx", "../src/**/*.stories.@(js|jsx|mjs|ts|tsx)"],
addons: [
"@storybook/addon-links",
"@storybook/addon-essentials",
"@storybook/addon-docs",
"@storybook/addon-interactions"
],
framework: {
name: "@storybook/vue-vite",
options: {}
},
docs: {
autodocs: "tag"
}
};
export default config;
6 changes: 6 additions & 0 deletions .storybook/manager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { addons } from '@storybook/manager-api';

addons.setConfig({
// Place the controls panel at the bottom of the canvas
panelPosition: 'bottom',
});
14 changes: 14 additions & 0 deletions .storybook/preview.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/** @type { import('@storybook/vue').Preview } */
const preview = {
parameters: {
actions: { argTypesRegex: "^on[A-Z].*" },
controls: {
matchers: {
color: /(background|color)$/i,
date: /Date$/i
}
}
}
};

export default preview;
20,720 changes: 16,573 additions & 4,147 deletions package-lock.json

Large diffs are not rendered by default.

18 changes: 17 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
"lint": "vue-cli-service lint",
"build-bundle": "npm run build",
"open-cypress": "nyc cypress open",
"run-cypress": "TZ=UTC nyc cypress run"
"run-cypress": "TZ=UTC nyc cypress run",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build",
"test-storybook": "test-storybook"
},
"main": "./dist/vue-form-builder.umd.js",
"module": "./dist/vue-form-builder.es.js",
Expand All @@ -28,6 +31,7 @@
],
"dependencies": {
"@chantouchsek/validatorjs": "1.2.3",
"@storybook/addon-docs": "^7.6.13",
"axios-extensions": "^3.1.6",
"lodash": "^4.17.21",
"lru-cache": "^10.0.1",
Expand All @@ -53,6 +57,14 @@
"@panter/vue-i18next": "^0.15.2",
"@processmaker/vue-form-elements": "0.51.0",
"@processmaker/vue-multiselect": "2.3.0",
"@storybook/addon-essentials": "^7.6.13",
"@storybook/addon-interactions": "^7.6.13",
"@storybook/addon-links": "^7.6.13",
"@storybook/blocks": "^7.6.13",
"@storybook/test": "^7.6.13",
"@storybook/test-runner": "^0.16.0",
"@storybook/vue": "^7.6.13",
"@storybook/vue-vite": "^7.6.13",
"@vitejs/plugin-vue2": "^2.3.1",
"@vue/test-utils": "^1.1.1",
"axios": "^1.6.0",
Expand All @@ -71,6 +83,7 @@
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-jest": "^22.4.1",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-storybook": "^0.6.15",
"eslint-plugin-vue": "^9.3.0",
"expr-eval": "^2.0.2",
"globby": "^11.1.0",
Expand All @@ -80,7 +93,10 @@
"mustache": "^3.0.1",
"nyc": "^15.1.0",
"prettier": "2.7.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"sass": "^1.53.0",
"storybook": "^7.6.13",
"v-calendar": "^0.9.7",
"validatorjs": "^3.14.2",
"vite": "^4.0.4",
Expand Down
285 changes: 285 additions & 0 deletions src/bootstrap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,285 @@
import Vue from "vue";
import "bootstrap/dist/css/bootstrap.css";
import "bootstrap-vue/dist/bootstrap-vue.css";
import "@fortawesome/fontawesome-free/css/all.min.css";
import i18next from "i18next";
import VueI18Next from "@panter/vue-i18next";
import "@processmaker/vue-form-elements/dist/vue-form-elements.css";
import Vuex from "vuex";
import axios from "axios";
import { cacheAdapterEnhancer } from "axios-extensions";
import { BootstrapVue, IconsPlugin } from "bootstrap-vue";
import { Multiselect } from "@processmaker/vue-multiselect";
import "@processmaker/vue-multiselect/dist/vue-multiselect.min.css";
import { LRUCache } from "lru-cache";
import VueFormElements from "@processmaker/vue-form-elements";
import undoRedoModule from "@/store/modules/undoRedoModule";
import globalErrorsModule from "@/store/modules/globalErrorsModule";
import ScreenBuilder from "@/components";

Vue.use(BootstrapVue);
Vue.use(IconsPlugin);
Vue.config.productionTip = false;

// Allow strings to be wrapped in $t(...) for translating
// outside this package. This standalone app just returns
// the English string
Vue.use(VueI18Next);
i18next.init({ lng: "en" });
Vue.mixin({ i18n: new VueI18Next(i18next) });
Vue.use(Vuex);
Vue.use(ScreenBuilder);
Vue.use(VueFormElements);
Vue.component("Multiselect", Multiselect);

// Stub for standalone. Real one is in core.
Vue.component("Required", {
template: '<div class="text-right"><small>* = Required</small></div>'
});

export const store = new Vuex.Store({
modules: {
globalErrorsModule,
undoRedoModule
}
});

window.exampleScreens = [
{
id: 1,
screen_category_id: 1,
title: "Sub screen example",
description: "A sub screen example",
type: "FORM",
config: [
{
name: "Sub screen example",
items: [
{
config: {
icon: "far fa-square",
label: "First name",
name: "firstname",
placeholder: "",
validation: "",
helper: null,
type: "text",
dataFormat: "string",
customCssSelector: "first-name"
},
inspector: [],
component: "FormInput",
"editor-component": "FormInput",
"editor-control": "FormInput",
label: "Line Input",
value: "__vue_devtool_undefined__"
},
{
config: {
icon: "far fa-square",
label: "Last name",
name: "lastname",
placeholder: "",
validation: "",
helper: null,
type: "text",
dataFormat: "string",
customCssSelector: ""
},
inspector: [],
component: "FormInput",
"editor-component": "FormInput",
"editor-control": "FormInput",
label: "Line Input",
value: "__vue_devtool_undefined__"
}
]
}
],
computed: [],
watchers: [],
custom_css: "[selector='first-name'] label { font-style: italic; }",
status: "ACTIVE"
}
];
// get cache config from header
const cacheEnabled = document.head.querySelector(
"meta[name='screen-cache-enabled']"
);
const cacheTimeout = document.head.querySelector(
"meta[name='screen-cache-timeout']"
);
// Get the current protocol, hostname, and port
const { protocol, hostname, port } = window.location;
window.ProcessMaker = {
isStub: true,
user: {
id: 1,
lang: "en"
},
app: {
url: `${protocol}//${hostname}:${port}` // Create a URL with the current port
},
apiClient: {
create() {
return this;
},
defaults: {
headers: {
common: {
"X-CSRF-TOKEN": "token"
}
}
},
get(url, params) {
return new Promise((resolve, reject) => {
let screen;
if (url.substr(0, 8) === "screens/") {
screen = window.exampleScreens.find((s) => s.id == url.substr(8));
}
if (url.substr(0, 8) === "screens/" && screen) {
resolve({ data: screen });
} else if (url === "screens") {
resolve({
data: {
data: window.exampleScreens
}
});
} else if (url === "/data_sources/1") {
resolve({
data: {
endpoints: {
list: {}
}
}
});
} else if (url === "/data_sources") {
resolve({
data: {
data: [
{
id: 1,
name: "Persons",
endpoints: {
list: {}
}
}
]
}
});
} else {
window.axios
.get(url, params)
.then((response) => resolve(response))
.catch((error) => reject(error));
}
});
},
post(url, body) {
return new Promise((resolve, reject) => {
switch (url) {
case "/requests/data_sources/1":
resolve({
data: {
response: [
{ value: 1, content: "James" },
{ value: 2, content: "John" },
{ value: 3, content: "Mary" },
{ value: 4, content: "Patricia" }
]
}
});
break;
default:
window.axios
.post(url, body)
.then((response) => resolve(response))
.catch((error) => reject(error));
}
});
},
put() {
return new Promise((resolve) => {
resolve({
data: {
response: []
}
});
});
},
delete() {
return new Promise((resolve) => {
resolve({
data: {
response: []
}
});
});
}
},
EventBus: new Vue(),
confirmModal(title, message, variant, callback) {
if (window.confirm(`${title}: ${message}`)) {
callback();
}
},
alert(message, variant) {
variant;
message;
},
screen: {
cacheEnabled: cacheEnabled ? cacheEnabled.content === "true" : false,
cacheTimeout: cacheTimeout ? Number(cacheTimeout.content) : 0
}
};
window.Echo = {
listeners: [],
watcherMocks(body, response) {
this.listeners.forEach((listener) => {
setTimeout(() => {
listener.callback({
type: ".ProcessMaker\\Events\\ScriptResponseEvent",
watcher: body.watcher,
response
});
}, 1000);
});
},
eventMocks(event, response) {
this.listeners.forEach((listener) => {
setTimeout(() => {
listener.callback({
type: event,
response
});
}, 1000);
});
},
private() {
return {
notification(callback) {
window.Echo.listeners.push({ callback });
},
stopListening() {
window.Echo.listeners.splice(0);
},
listen(event, callback) {
window.Echo.listeners.push({ event, callback });
}
};
}
};

window.axios = axios.create({
baseURL: "/api/1.0/",
adapter: cacheAdapterEnhancer(axios.getAdapter(axios.defaults.adapter), {
enabledByDefault: window.ProcessMaker.screen.cacheEnabled,
cacheFlag: "useCache",
defaultCache: new LRUCache({
ttl: window.ProcessMaker.screen.cacheTimeout,
max: 100
})
})
});

export default { ScreenBuilder };
Loading

0 comments on commit 273d2ef

Please sign in to comment.