vue-form-craft 4.2.2 → 4.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,133 +1,133 @@
1
- # vue-form-craft
2
-
3
- 基于 [vue](https://github.com/vuejs/vue) 和 [element-plus](https://github.com/ElemeFE/element) 实现的表单设计器 + 渲染器
4
-
5
- 使用了最新的前端技术栈,可以让你免去vue项目中表单的烦恼。
6
-
7
- - [在线预览](https://xinnian999.github.io/vue-form-craft/zh/form-design)
8
- - [官方文档](https://xinnian999.github.io/vue-form-craft/zh/)
9
- - 作者:Elin
10
- - 联系方式:17803000829
11
-
12
- ![ui](./src/assets/ui.png)
13
-
14
- ## 特性
15
-
16
- - 可视化设计表单
17
- - 支持三十多种的表单组件(el所有表单组件、内置组件)
18
- - 支持收集Array数据(自增组件)
19
- - 用法简单,又非常灵活高效的表单联动
20
- - 可预览生成的json配置
21
- - 可预览生成的VUE组件
22
- - 高扩展性、支持自定义组件、支持各种ui组件库来替换ui
23
- - 支持表单填写校验
24
- - 组件无限深层嵌套,深层校验
25
-
26
- ## 第三方插件
27
-
28
- - vuedraggable
29
- - element-plus
30
- - vue-form-craft
31
- - lodash
32
-
33
- ## 使用
34
-
35
- ### 版本要求
36
-
37
- vue@3.x
38
-
39
- ### 安装
40
-
41
- ```js
42
- npm i vue-form-craft
43
- //或
44
- yarn add vue-form-craft
45
- //或
46
- pnpm i vue-form-craft
47
- ```
48
-
49
- ### 全局注册
50
-
51
- ```js
52
- import { createApp } from 'vue'
53
- import VueFormCraft from 'vue-form-craft'
54
- import ElementPlus from 'element-plus'
55
- import 'element-plus/dist/index.css'
56
- import App from './App.vue'
57
-
58
- const app = createApp(App)
59
-
60
- app.use(ElementPlus)
61
- app.use(VueFormCraft)
62
- app.mount('#app')
63
- ```
64
-
65
- ### 使用
66
-
67
- > 使用表单设计器
68
-
69
- ```vue
70
- <template>
71
- <div style="width:100vw;height:100vh">
72
- <FormDesign />
73
- </div>
74
- </template>
75
- ```
76
-
77
- > 使用表单渲染器
78
-
79
- ```vue
80
- <template>
81
- <FormRender v-model="formValues" :schema="schema" ref="formRef" />
82
- <el-button @click="handleSubmit">提交</el-button>
83
- </template>
84
-
85
- <script setup lang="ts">
86
- import { ref } from 'vue'
87
- import type { FormSchema,FormRenderInstance } from 'vue-form-craft'
88
-
89
- const formRef = ref<FormRenderInstance>()
90
-
91
- const formValues = ref({})
92
-
93
- const schema: FormSchema = {
94
- labelWidth: 150,
95
- labelAlign: 'right',
96
- size: 'default',
97
- items: [
98
- {
99
- label: '用户名',
100
- component: 'Input',
101
- name: 'username',
102
- required: true,
103
- props: {
104
- placeholder: '请输入用户名'
105
- }
106
- },
107
- {
108
- label: '密码',
109
- component: 'Password',
110
- name: 'password',
111
- required: true,
112
- props: {
113
- placeholder: '请输入密码'
114
- }
115
- }
116
- ]
117
- }
118
-
119
- const handleSubmit = async () => {
120
- await formRef.value?.validate()
121
- alert(JSON.stringify(formValues.value,null,2))
122
- }
123
- </script>
124
- ```
125
-
126
- ## 捐赠 vue-form-craft 的开发
127
-
128
- `vue-form-craft` 的文档和代码完全开源,如果该项目有帮助到你的开发工作,你可以捐赠`vue-form-craft`的研发工作,捐赠无门槛,哪怕是一杯可乐也好。
129
-
130
- <div style="display:flex;gap:15px">
131
- <img src="./docs/assets/wechat.png" style="height:400px" />
132
- <img src="./docs/assets/zhifubao.png" style="height:400px" />
133
- </div>
1
+ # vue-form-craft
2
+
3
+ 基于 [vue](https://github.com/vuejs/vue) 和 [element-plus](https://github.com/ElemeFE/element) 实现的表单设计器 + 渲染器
4
+
5
+ 使用了最新的前端技术栈,可以让你免去vue项目中表单的烦恼。
6
+
7
+ - [在线预览](https://xinnian999.github.io/vue-form-craft/zh/form-design)
8
+ - [官方文档](https://xinnian999.github.io/vue-form-craft/zh/)
9
+ - 作者:Elin
10
+ - 联系方式:17803000829
11
+
12
+ ![ui](./src/assets/ui.png)
13
+
14
+ ## 特性
15
+
16
+ - 可视化设计表单
17
+ - 支持三十多种的表单组件(el所有表单组件、内置组件)
18
+ - 支持收集Array数据(自增组件)
19
+ - 用法简单,又非常灵活高效的表单联动
20
+ - 可预览生成的json配置
21
+ - 可预览生成的VUE组件
22
+ - 高扩展性、支持自定义组件、支持各种ui组件库来替换ui
23
+ - 支持表单填写校验
24
+ - 组件无限深层嵌套,深层校验
25
+
26
+ ## 第三方插件
27
+
28
+ - vuedraggable
29
+ - element-plus
30
+ - vue-form-craft
31
+ - lodash
32
+
33
+ ## 使用
34
+
35
+ ### 版本要求
36
+
37
+ vue@3.x
38
+
39
+ ### 安装
40
+
41
+ ```js
42
+ npm i vue-form-craft
43
+ //或
44
+ yarn add vue-form-craft
45
+ //或
46
+ pnpm i vue-form-craft
47
+ ```
48
+
49
+ ### 全局注册
50
+
51
+ ```js
52
+ import { createApp } from 'vue'
53
+ import VueFormCraft from 'vue-form-craft'
54
+ import ElementPlus from 'element-plus'
55
+ import 'element-plus/dist/index.css'
56
+ import App from './App.vue'
57
+
58
+ const app = createApp(App)
59
+
60
+ app.use(ElementPlus)
61
+ app.use(VueFormCraft)
62
+ app.mount('#app')
63
+ ```
64
+
65
+ ### 使用
66
+
67
+ > 使用表单设计器
68
+
69
+ ```vue
70
+ <template>
71
+ <div style="width:100vw;height:100vh">
72
+ <FormDesign />
73
+ </div>
74
+ </template>
75
+ ```
76
+
77
+ > 使用表单渲染器
78
+
79
+ ```vue
80
+ <template>
81
+ <FormRender v-model="formValues" :schema="schema" ref="formRef" />
82
+ <el-button @click="handleSubmit">提交</el-button>
83
+ </template>
84
+
85
+ <script setup lang="ts">
86
+ import { ref } from 'vue'
87
+ import type { FormSchema,FormInstance } from 'vue-form-craft'
88
+
89
+ const formRef = ref<FormInstance>()
90
+
91
+ const formValues = ref({})
92
+
93
+ const schema: FormSchema = {
94
+ labelWidth: 150,
95
+ labelAlign: 'right',
96
+ size: 'default',
97
+ items: [
98
+ {
99
+ label: '用户名',
100
+ component: 'Input',
101
+ name: 'username',
102
+ required: true,
103
+ props: {
104
+ placeholder: '请输入用户名'
105
+ }
106
+ },
107
+ {
108
+ label: '密码',
109
+ component: 'Password',
110
+ name: 'password',
111
+ required: true,
112
+ props: {
113
+ placeholder: '请输入密码'
114
+ }
115
+ }
116
+ ]
117
+ }
118
+
119
+ const handleSubmit = async () => {
120
+ await formRef.value?.validate()
121
+ alert(JSON.stringify(formValues.value,null,2))
122
+ }
123
+ </script>
124
+ ```
125
+
126
+ ## 捐赠 vue-form-craft 的开发
127
+
128
+ `vue-form-craft` 的文档和代码完全开源,如果该项目有帮助到你的开发工作,你可以捐赠`vue-form-craft`的研发工作,捐赠无门槛,哪怕是一杯可乐也好。
129
+
130
+ <div style="display:flex;gap:15px">
131
+ <img src="./docs/assets/wechat.png" style="height:400px" />
132
+ <img src="./docs/assets/zhifubao.png" style="height:400px" />
133
+ </div>
package/dist/index.d.ts CHANGED
@@ -2,12 +2,15 @@ import { App } from 'vue';
2
2
  import { Component } from 'vue';
3
3
  import { ComponentOptionsMixin } from 'vue';
4
4
  import { ComponentProvideOptions } from 'vue';
5
- import { ComputedRef } from 'vue';
5
+ import { DeepReadonly } from 'vue';
6
6
  import { DefineComponent } from 'vue';
7
7
  import { ExtractPropTypes } from 'vue';
8
8
  import { FormValidationResult } from 'element-plus';
9
9
  import { PropType } from 'vue';
10
10
  import { PublicProps } from 'vue';
11
+ import { Ref } from 'vue';
12
+ import { ToRefs } from 'vue';
13
+ import { UnwrapNestedRefs } from 'vue';
11
14
  import { VNode } from 'vue';
12
15
 
13
16
  export declare type $Global = {
@@ -15,17 +18,6 @@ export declare type $Global = {
15
18
  elements: Record<string, FormElement>;
16
19
  };
17
20
 
18
- declare type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
19
-
20
- declare type __VLS_TypePropsToRuntimeProps<T> = {
21
- [K in keyof T]-?: {} extends Pick<T, K> ? {
22
- type: PropType<__VLS_NonUndefinedable<T[K]>>;
23
- } : {
24
- type: PropType<T[K]>;
25
- required: true;
26
- };
27
- };
28
-
29
21
  declare type __VLS_WithTemplateSlots<T, S> = T & {
30
22
  new (): {
31
23
  $slots: S;
@@ -36,7 +28,7 @@ declare const _default: {
36
28
  install: (app: App<Element>, options?: {
37
29
  request?: ((options: Record<string, any>) => Promise<Record<string, any>>) | undefined;
38
30
  extendElements?: Record<string, FormElement> | undefined;
39
- lang?: "zh" | "en" | undefined;
31
+ lang?: "en" | "zh" | undefined;
40
32
  } | undefined) => void;
41
33
  };
42
34
  export default _default;
@@ -94,6 +86,21 @@ export declare type FormElement = {
94
86
  attrSchema: FormSchema;
95
87
  };
96
88
 
89
+ export declare type FormInstance = DeepReadonly<UnwrapNestedRefs<FormInstanceSource>>;
90
+
91
+ declare interface FormInstanceSource extends ToRefs<FormRenderProps> {
92
+ formValues: Ref<Record<string, any>>;
93
+ selectData: Record<string, Record<string, any>>;
94
+ initialValues: Record<string, Record<string, any>>;
95
+ context: Ref<Record<string, any>>;
96
+ updateFormValues: (values: Record<string, any>) => void;
97
+ updateSelectData: (key: string, value: Record<string, any>) => void;
98
+ updateInitialValues: (values: Record<string, any>) => void;
99
+ validate: () => FormValidationResult | undefined;
100
+ resetFields: (names?: string[]) => void;
101
+ submit: () => Promise<void>;
102
+ }
103
+
97
104
  export declare interface FormItemType {
98
105
  label?: string;
99
106
  name: string;
@@ -109,45 +116,167 @@ export declare interface FormItemType {
109
116
  rules?: FormRule[];
110
117
  class?: any;
111
118
  style?: any;
112
- design?: boolean;
113
119
  change?: FormChange[];
114
120
  dialog?: boolean;
115
121
  }
116
122
 
117
- export declare const FormRender: __VLS_WithTemplateSlots<DefineComponent<ExtractPropTypes<__VLS_TypePropsToRuntimeProps<Readonly<{
118
- modelValue?: Record<string, any> | undefined;
119
- schema: FormSchema;
120
- schemaContext?: Record<string, any> | undefined;
121
- design?: boolean | undefined;
122
- footer?: boolean | undefined;
123
- read?: boolean | undefined;
124
- }>>>, {
123
+ export declare const FormRender: __VLS_WithTemplateSlots<DefineComponent<ExtractPropTypes< {
124
+ modelValue: PropType<Record<string, any>>;
125
+ schema: {
126
+ type: PropType<FormSchema>;
127
+ required: true;
128
+ };
129
+ schemaContext: {
130
+ type: PropType<Record<string, any>>;
131
+ };
132
+ design: {
133
+ type: PropType<boolean>;
134
+ };
135
+ footer: {
136
+ type: PropType<boolean>;
137
+ };
138
+ read: {
139
+ type: PropType<boolean>;
140
+ };
141
+ }>, {
142
+ formValues: {
143
+ readonly [x: string]: any;
144
+ };
145
+ selectData: {
146
+ readonly [x: string]: {
147
+ readonly [x: string]: any;
148
+ };
149
+ };
150
+ initialValues: {
151
+ readonly [x: string]: any;
152
+ };
153
+ context: {
154
+ readonly $values: {
155
+ readonly [x: string]: any;
156
+ };
157
+ readonly $selectData: {
158
+ readonly [x: string]: {
159
+ readonly [x: string]: any;
160
+ };
161
+ };
162
+ readonly $locale: {
163
+ readonly menus: {
164
+ readonly basicTitle: string;
165
+ readonly highBasicTitle: string;
166
+ readonly layoutTitle: string;
167
+ readonly assistTitle: string;
168
+ readonly useTemplateBtn: string;
169
+ };
170
+ readonly actions: {
171
+ readonly previewJson: string;
172
+ readonly previewVueCode: string;
173
+ readonly previewForm: string;
174
+ readonly clear: string;
175
+ readonly save: string;
176
+ };
177
+ readonly canvas: {
178
+ readonly emptyTip: string;
179
+ readonly wrapperEmptyTip: string;
180
+ };
181
+ readonly attr: {
182
+ readonly tab1: {
183
+ readonly title: string;
184
+ readonly emptyTip: string;
185
+ readonly linkage: {
186
+ readonly text: string;
187
+ readonly action1: string;
188
+ readonly action2: string;
189
+ };
190
+ };
191
+ readonly tab2: {
192
+ readonly title: string;
193
+ };
194
+ };
195
+ };
196
+ };
197
+ updateFormValues: (values: Record<string, any>) => void;
198
+ updateSelectData: (key: string, value: Record<string, any>) => void;
199
+ updateInitialValues: (values: Record<string, any>) => void;
125
200
  validate: () => FormValidationResult | undefined;
126
- context: ComputedRef< {
127
- $values: {};
128
- $selectData: Record<string, Record<string, any>>;
129
- $initialValues: Record<string, any>;
130
- $locale: Locale;
131
- }>;
132
201
  resetFields: (names?: string[] | undefined) => void;
202
+ submit: () => Promise<void>;
203
+ schema: {
204
+ readonly labelWidth?: number | undefined;
205
+ readonly labelAlign?: "top" | "left" | "right" | undefined;
206
+ readonly labelSuffix?: string | undefined;
207
+ readonly size?: "default" | "small" | "large" | undefined;
208
+ readonly disabled?: boolean | undefined;
209
+ readonly hideRequiredAsterisk?: boolean | undefined;
210
+ readonly labelBold?: boolean | undefined;
211
+ readonly items: readonly {
212
+ readonly label?: string | undefined;
213
+ readonly name: string;
214
+ readonly component: string;
215
+ readonly required?: boolean | undefined;
216
+ readonly props?: {
217
+ readonly [x: string]: any;
218
+ } | undefined;
219
+ readonly initialValue?: any;
220
+ readonly help?: string | undefined;
221
+ readonly children?: readonly any[] | undefined;
222
+ readonly hidden?: string | boolean | undefined;
223
+ readonly hideLabel?: boolean | undefined;
224
+ readonly designKey?: string | undefined;
225
+ readonly rules?: readonly {
226
+ readonly type: string;
227
+ readonly customReg?: string | undefined;
228
+ readonly message?: string | undefined;
229
+ readonly trigger: "blur" | "change";
230
+ }[] | undefined;
231
+ readonly class?: any;
232
+ readonly style?: any;
233
+ readonly change?: readonly {
234
+ readonly target: string;
235
+ readonly value?: any;
236
+ readonly condition?: any;
237
+ }[] | undefined;
238
+ readonly dialog?: boolean | undefined;
239
+ }[];
240
+ };
241
+ schemaContext: {
242
+ readonly [x: string]: any;
243
+ } | undefined;
244
+ design: boolean;
245
+ footer: boolean;
246
+ read: boolean;
133
247
  }, {}, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {
134
- "update:modelValue": (values: Record<string, any>) => void;
135
248
  onFinish: (values: Record<string, any>) => void;
136
- }, string, PublicProps, Readonly<ExtractPropTypes<__VLS_TypePropsToRuntimeProps<Readonly<{
137
- modelValue?: Record<string, any> | undefined;
138
- schema: FormSchema;
139
- schemaContext?: Record<string, any> | undefined;
140
- design?: boolean | undefined;
141
- footer?: boolean | undefined;
142
- read?: boolean | undefined;
143
- }>>>> & Readonly<{
144
- "onUpdate:modelValue"?: ((values: Record<string, any>) => any) | undefined;
249
+ }, string, PublicProps, Readonly<ExtractPropTypes< {
250
+ modelValue: PropType<Record<string, any>>;
251
+ schema: {
252
+ type: PropType<FormSchema>;
253
+ required: true;
254
+ };
255
+ schemaContext: {
256
+ type: PropType<Record<string, any>>;
257
+ };
258
+ design: {
259
+ type: PropType<boolean>;
260
+ };
261
+ footer: {
262
+ type: PropType<boolean>;
263
+ };
264
+ read: {
265
+ type: PropType<boolean>;
266
+ };
267
+ }>> & Readonly<{
145
268
  onOnFinish?: ((values: Record<string, any>) => any) | undefined;
146
269
  }>, {}, {}, {}, {}, string, ComponentProvideOptions, true, {}, any>, {
147
270
  default?(_: {}): any;
148
271
  }>;
149
272
 
150
- export declare type FormRenderInstance = InstanceType<typeof FormRender>;
273
+ declare interface FormRenderProps {
274
+ schema: FormSchema;
275
+ schemaContext?: Record<string, any>;
276
+ design?: boolean;
277
+ footer?: boolean;
278
+ read?: boolean;
279
+ }
151
280
 
152
281
  declare type FormRule = {
153
282
  type: 'email' | 'url' | 'custom' | string;
@@ -167,45 +296,12 @@ export declare type FormSchema = {
167
296
  items: FormItemType[];
168
297
  };
169
298
 
170
- declare type Locale = {
171
- menus: {
172
- basicTitle: string;
173
- highBasicTitle: string;
174
- layoutTitle: string;
175
- assistTitle: string;
176
- useTemplateBtn: string;
177
- };
178
- actions: {
179
- previewJson: string;
180
- previewVueCode: string;
181
- previewForm: string;
182
- clear: string;
183
- save: string;
184
- };
185
- canvas: {
186
- emptyTip: string;
187
- wrapperEmptyTip: string;
188
- };
189
- attr: {
190
- tab1: {
191
- title: string;
192
- emptyTip: string;
193
- linkage: {
194
- text: string;
195
- action1: string;
196
- action2: string;
197
- };
198
- };
199
- tab2: {
200
- title: string;
201
- };
202
- };
203
- };
204
-
205
299
  export declare type TemplateData = {
206
300
  name: string;
207
301
  schema: FormSchema;
208
302
  id?: string;
209
303
  }[];
210
304
 
305
+ export declare const useFormInstance: () => FormInstance;
306
+
211
307
  export { }