Skip to content
This repository was archived by the owner on Jun 27, 2023. It is now read-only.

Commit 2896c04

Browse files
committed
feature(next): vue3 + ts setup
1 parent 5d9fcd6 commit 2896c04

File tree

11 files changed

+1749
-1060
lines changed

11 files changed

+1749
-1060
lines changed

dev/vue/main.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { createApp } from 'vue';
2+
3+
import App from './App.vue';
4+
5+
import { createDynamicForms } from '../../src/index';
6+
7+
const VueDynamicForms = createDynamicForms({
8+
theme: 'material',
9+
});
10+
11+
export const app = createApp(App);
12+
13+
app.use(VueDynamicForms).mount('#app');

package-lock.json

Lines changed: 1549 additions & 1011 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
},
1717
"scripts": {
1818
"serve": "vue-cli-service serve",
19-
"build": "vue-cli-service build --target lib --name as-dynamic-forms src/index.js",
19+
"build": "vue-cli-service build --target lib --name as-dynamic-forms src/index.ts",
2020
"lint": "vue-cli-service lint",
2121
"test:watch": "vue-cli-service test:unit --verbose --no-cache --watchAll",
2222
"test": "vue-cli-service test:unit",
@@ -26,30 +26,34 @@
2626
},
2727
"main": "dist/as-dynamic-forms.common.js",
2828
"dependencies": {
29-
"bootstrap": "^4.5.0",
30-
"core-js": "^3.6.5",
31-
"sass-resources-loader": "^2.0.3",
32-
"vue": "^2.6.11"
29+
"vue": "^3.0.0-0"
3330
},
3431
"devDependencies": {
32+
"@typescript-eslint/eslint-plugin": "^2.33.0",
33+
"@typescript-eslint/parser": "^2.33.0",
34+
"@vue/cli-service": "~4.5.3",
35+
"@vue/compiler-sfc": "^3.0.0-rc.5",
36+
"@vue/eslint-config-prettier": "^6.0.0",
37+
"@vue/eslint-config-typescript": "^5.0.2",
3538
"@vue/cli-plugin-babel": "4.5.3",
3639
"@vue/cli-plugin-eslint": "4.5.3",
3740
"@vue/cli-plugin-unit-jest": "4.5.3",
38-
"@vue/cli-service": "4.5.3",
39-
"@vue/eslint-config-prettier": "6.0.0",
40-
"@vue/test-utils": "1.0.3",
41+
"@vue/cli-plugin-typescript": "~4.5.3",
42+
"@vue/test-utils": "1.0.4",
4143
"babel-core": "7.0.0-bridge.0",
4244
"babel-eslint": "10.1.0",
43-
"babel-jest": "26.1.0",
44-
"eslint": "7.6.0",
45-
"eslint-plugin-prettier": "3.1.4",
46-
"eslint-plugin-vue": "6.2.2",
45+
"babel-jest": "26.3.0",
46+
"eslint": "7.7.0",
47+
"eslint-plugin-prettier": "^3.1.3",
48+
"eslint-plugin-vue": "^7.0.0-0",
4749
"node-sass": "4.14.1",
4850
"prettier": "2.0.5",
4951
"sass-loader": "9.0.3",
50-
"vue-select": "3.10.7",
52+
"vue-select": "3.10.8",
5153
"vue-template-compiler": "2.6.11",
5254
"vuepress": "1.5.3",
53-
"semantic-release": "17.1.1"
55+
"semantic-release": "17.1.1",
56+
"ts-node": "^8.10.2",
57+
"typescript": "~3.9.7"
5458
}
5559
}
Lines changed: 19 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,21 @@
11
<template>
2-
<div class="dynamic-form" v-if="fields">
3-
<form
4-
v-if="fields.length > 0 && !showFeedback"
5-
:id="id"
6-
:name="id"
7-
v-bind="formattedOptions"
8-
novalidate
9-
@submit.prevent="handleSubmit()"
10-
>
11-
<input type="hidden" name="form-name" :value="id" />
12-
<dynamic-input
13-
v-for="field in controls"
14-
:key="field.name"
15-
:form-control="field"
16-
>
17-
<template slot="custom-field" slot-scope="props">
18-
<div v-for="slot in deNormalizedScopedSlots" :key="slot">
19-
<slot
20-
v-if="props.control.name === slot"
21-
:name="slot"
22-
:control="normalizedControls[slot]"
23-
:valueChange="props.valueChange"
24-
:onFocus="props.onFocus"
25-
:onBlur="props.onBlur"
26-
></slot>
27-
</div>
28-
</template>
29-
</dynamic-input>
30-
</form>
31-
<div v-if="showFeedback" class="dynamic-form__feedback">
32-
{{ feedbackText }}
33-
</div>
34-
</div>
2+
<form class="dynamic-form" novalidate>
3+
{{ this.form.fields }}
4+
</form>
355
</template>
36-
<script src="./DynamicForm.js"></script>
6+
7+
<script lang="ts">
8+
import { defineComponent, PropType } from 'vue';
9+
import { DynamicForm } from './form';
10+
11+
const props = {
12+
form: Object as PropType<DynamicForm>,
13+
};
14+
15+
export default defineComponent({
16+
name: 'asDynamicForm',
17+
props,
18+
});
19+
</script>
20+
21+
<style></style>

src/core/models.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
export class InputBase<T> {
2+
value: T | undefined;
3+
key: string;
4+
label: string;
5+
required: boolean;
6+
order: number;
7+
type: string;
8+
9+
constructor(
10+
options: {
11+
value?: T | undefined;
12+
key?: string;
13+
label?: string;
14+
required?: boolean;
15+
order?: number;
16+
type?: string;
17+
} = {},
18+
) {
19+
this.value = options.value;
20+
this.key = options.key || '';
21+
this.label = options.label || '';
22+
this.required = !!options.required;
23+
this.order = options.order === undefined ? 1 : options.order;
24+
this.type = options.type || '';
25+
}
26+
}
27+
28+
export class TextInput extends InputBase<string> {
29+
type = 'text';
30+
}
31+
32+
export class SelectInput<T> extends InputBase<T> {
33+
options: { key: string; value: string }[];
34+
constructor(
35+
options: {
36+
value?: T | undefined;
37+
key?: string;
38+
label?: string;
39+
required?: boolean;
40+
order?: number;
41+
type?: string;
42+
options?: { key: string; value: string }[];
43+
} = {},
44+
) {
45+
super({
46+
value: options.value,
47+
key: options.key,
48+
label: options.label,
49+
required: options.required,
50+
order: options.order,
51+
});
52+
this.type = 'select';
53+
this.options = options.options || [];
54+
}
55+
}

src/core/utils/warning.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function warn(msg: string, ...args: any[]) {
2+
console.warn('[DynamicForms warn]: ' + msg, ...args);
3+
}

src/dynamicForms.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { App } from 'vue';
2+
import { dynamicFormsSymbol } from './useApi';
3+
import DynamicForm from './components/dynamic-form/DynamicForm.vue';
4+
5+
export interface DynamicFormsOptions {
6+
theme?: string;
7+
}
8+
9+
export interface DynamicFormsPlugin {
10+
options?: DynamicFormsOptions;
11+
install(app: App): void;
12+
}
13+
14+
export function createDynamicForms(
15+
options?: DynamicFormsOptions,
16+
): DynamicFormsPlugin {
17+
const vdf: DynamicFormsPlugin = {
18+
options,
19+
install(app: App) {
20+
const vdf = this;
21+
app.component('dynamic-form', DynamicForm);
22+
app.provide(dynamicFormsSymbol, vdf);
23+
},
24+
};
25+
26+
return vdf;
27+
}

src/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export * from './useApi';
2+
export * from './dynamicForms';
3+
export * from './core/models';
4+
export * from './components/dynamic-form/form';

src/useApi.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { inject, InjectionKey, provide, App } from 'vue';
2+
import { DynamicFormsOptions, DynamicFormsPlugin } from './dynamicForms';
3+
4+
export const dynamicFormsSymbol: InjectionKey<DynamicFormsPlugin> = Symbol();
5+
6+
/* const createDynamicForms = (
7+
config: DynamicFormsOptions,
8+
): DynamicFormsPlugin => {
9+
return ({
10+
options: {
11+
theme: config.theme,
12+
},
13+
});
14+
};
15+
16+
export function provideDynamicForms(config: DynamicFormsOptions) {
17+
const vdf = createDynamicForms(config);
18+
provide(dynamicFormsSymbol, vdf);
19+
} */
20+
21+
export function useDynamicForms() {
22+
const dynamicForms = inject(dynamicFormsSymbol);
23+
if (!dynamicForms) throw new Error('No dynamicForms provided!!!');
24+
25+
return dynamicForms;
26+
}

tsconfig.json

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"compilerOptions": {
3+
"target": "esnext",
4+
"module": "esnext",
5+
"strict": true,
6+
"jsx": "preserve",
7+
"importHelpers": true,
8+
"moduleResolution": "node",
9+
"skipLibCheck": true,
10+
"esModuleInterop": true,
11+
"resolveJsonModule": true,
12+
"allowSyntheticDefaultImports": true,
13+
"sourceMap": true,
14+
"noImplicitThis": true,
15+
"noImplicitAny": false,
16+
"allowJs": true,
17+
"baseUrl": ".",
18+
"rootDir": ".",
19+
"outDir": "dist",
20+
"types": ["webpack-env", "jest"],
21+
"paths": {
22+
"@/*": ["src/*"]
23+
},
24+
"lib": ["esnext", "dom", "dom.iterable", "scripthost"]
25+
},
26+
"include": [
27+
"src/**/*.ts",
28+
"src/**/*.tsx",
29+
"src/**/*.vue",
30+
"tests/**/*.ts",
31+
"tests/**/*.tsx"
32+
],
33+
"exclude": ["node_modules"]
34+
}

0 commit comments

Comments
 (0)