@qin-ui/vant-pro 1.0.5 → 1.1.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.
Files changed (87) hide show
  1. package/AI-CONTEXT.md +48 -33
  2. package/LICENSE +9 -0
  3. package/README.md +1 -1
  4. package/api.json +27 -22
  5. package/es/component-provider/{index-DC_k4_R3.js → index-cldbPMDQ.js} +5 -4
  6. package/es/component-provider/index-cldbPMDQ.js.map +1 -0
  7. package/es/component-provider/index.js +2 -1
  8. package/es/component-provider/index.js.map +1 -0
  9. package/es/components/component-provider/components/index.vue.d.ts +27 -0
  10. package/es/components/component-provider/components/index.vue.d.ts.map +1 -0
  11. package/es/components/component-provider/constants/index.d.ts +16 -0
  12. package/es/components/component-provider/constants/index.d.ts.map +1 -0
  13. package/es/components/component-provider/index.d.ts +4 -0
  14. package/es/components/component-provider/index.d.ts.map +1 -0
  15. package/es/components/component-provider/types/index.d.ts +16 -0
  16. package/es/components/component-provider/types/index.d.ts.map +1 -0
  17. package/es/components/form/components/BaseField/index.vue.d.ts +1323 -0
  18. package/es/components/form/components/BaseField/index.vue.d.ts.map +1 -0
  19. package/es/components/form/components/BaseField/utils/index.d.ts +3 -0
  20. package/es/components/form/components/BaseField/utils/index.d.ts.map +1 -0
  21. package/es/components/form/components/BaseFormItem/index.vue.d.ts +7 -0
  22. package/es/components/form/components/BaseFormItem/index.vue.d.ts.map +1 -0
  23. package/es/components/form/components/ContainerFragment/index.vue.d.ts +23 -0
  24. package/es/components/form/components/ContainerFragment/index.vue.d.ts.map +1 -0
  25. package/es/components/form/components/GroupedFieldAttrs/index.vue.d.ts +24 -0
  26. package/es/components/form/components/GroupedFieldAttrs/index.vue.d.ts.map +1 -0
  27. package/es/components/form/components/PathProvider/index.vue.d.ts +23 -0
  28. package/es/components/form/components/PathProvider/index.vue.d.ts.map +1 -0
  29. package/es/components/form/components/ProForm/index.vue.d.ts +34 -0
  30. package/es/components/form/components/ProForm/index.vue.d.ts.map +1 -0
  31. package/es/components/form/components/SlotComponent/index.vue.d.ts +7 -0
  32. package/es/components/form/components/SlotComponent/index.vue.d.ts.map +1 -0
  33. package/es/components/form/components/index.d.ts +12 -0
  34. package/es/components/form/components/index.d.ts.map +1 -0
  35. package/es/components/form/constants/index.d.ts +62 -0
  36. package/es/components/form/constants/index.d.ts.map +1 -0
  37. package/es/components/form/hooks/index.d.ts +6 -0
  38. package/es/components/form/hooks/index.d.ts.map +1 -0
  39. package/es/components/form/hooks/useFields.d.ts +57 -0
  40. package/es/components/form/hooks/useFields.d.ts.map +1 -0
  41. package/es/components/form/hooks/useForm.d.ts +101 -0
  42. package/es/components/form/hooks/useForm.d.ts.map +1 -0
  43. package/es/components/form/hooks/useFormPopup.d.ts +57 -0
  44. package/es/components/form/hooks/useFormPopup.d.ts.map +1 -0
  45. package/es/components/form/hooks/useFormRef.d.ts +30 -0
  46. package/es/components/form/hooks/useFormRef.d.ts.map +1 -0
  47. package/es/components/form/index.d.ts +7 -0
  48. package/es/components/form/index.d.ts.map +1 -0
  49. package/es/components/form/types/index.d.ts +152 -0
  50. package/es/components/form/types/index.d.ts.map +1 -0
  51. package/es/form/index.js +11 -7
  52. package/es/form/index.js.map +1 -0
  53. package/es/index.d.ts +58 -954
  54. package/es/index.d.ts.map +1 -0
  55. package/es/index.js +10 -21
  56. package/es/index.js.map +1 -0
  57. package/es/shared/core/index.d.ts +6 -0
  58. package/es/shared/core/index.d.ts.map +1 -0
  59. package/es/shared/ui/index.d.ts +2 -0
  60. package/es/shared/ui/index.d.ts.map +1 -0
  61. package/package.json +11 -12
  62. package/src/components/component-provider/components/index.vue +67 -0
  63. package/src/components/component-provider/constants/index.ts +110 -0
  64. package/src/components/component-provider/index.ts +6 -0
  65. package/src/components/component-provider/types/index.ts +31 -0
  66. package/src/components/form/components/BaseField/index.vue +340 -0
  67. package/src/components/form/components/BaseField/utils/index.ts +14 -0
  68. package/src/components/form/components/BaseFormItem/index.vue +77 -0
  69. package/src/components/form/components/ContainerFragment/index.vue +24 -0
  70. package/src/components/form/components/GroupedFieldAttrs/index.vue +51 -0
  71. package/src/components/form/components/PathProvider/index.vue +18 -0
  72. package/src/components/form/components/ProForm/index.vue +114 -0
  73. package/src/components/form/components/SlotComponent/index.vue +26 -0
  74. package/src/components/form/components/index.ts +15 -0
  75. package/src/components/form/constants/index.ts +109 -0
  76. package/src/components/form/hooks/index.ts +6 -0
  77. package/src/components/form/hooks/useFields.ts +67 -0
  78. package/src/components/form/hooks/useForm.ts +126 -0
  79. package/src/components/form/hooks/useFormPopup.ts +111 -0
  80. package/src/components/form/hooks/useFormRef.ts +35 -0
  81. package/src/components/form/index.ts +27 -0
  82. package/src/components/form/types/index.ts +220 -0
  83. package/src/index.ts +62 -0
  84. package/src/shared/core/index.ts +37 -0
  85. package/src/shared/ui/index.ts +26 -0
  86. package/es/core/index-B5vvm4Fj.js +0 -236
  87. package/es/vendor/utils/lodash-es-DN4QDiDm.js +0 -1079
package/src/index.ts ADDED
@@ -0,0 +1,62 @@
1
+ import type { App } from 'vue';
2
+ import ProForm from './components/form';
3
+ import ProComponentProvider from './components/component-provider';
4
+
5
+ export * from './components/form';
6
+ export * from './components/component-provider';
7
+
8
+ /**
9
+ * Schema 驱动的表单组件,基于 vant Form 封装
10
+ *
11
+ * @description 通过声明式 JSON Schema 配置即可快速生成表单,
12
+ * 提供极致的 TypeScript 类型推导与组件库插槽扩展能力。
13
+ *
14
+ * @example
15
+ * ```vue
16
+ * <script setup lang="ts">
17
+ * import { ProForm, useForm } from '@qin-ui/vant-pro'
18
+ * const form = useForm<User>({ name: '' }, [
19
+ * { path: 'name', label: '姓名', component: 'input' }
20
+ * ])
21
+ * </script>
22
+ * <template>
23
+ * <ProForm :form="form" />
24
+ * </template>
25
+ * ```
26
+ *
27
+ * 组件提供者,用于全局配置 ProForm 的默认行为
28
+ *
29
+ * @description 通过 `ProComponentProvider` 包裹应用根组件,
30
+ * 可以全局覆盖组件的默认属性。
31
+ *
32
+ * @example
33
+ * ```vue
34
+ * <template>
35
+ * <ProComponentProvider :component-props="customProps">
36
+ * <App />
37
+ * </ProComponentProvider>
38
+ * </template>
39
+ * ```
40
+ */
41
+ export { ProForm, ProComponentProvider };
42
+
43
+ export default {
44
+ /**
45
+ * @qin-ui/vant-pro 安装方法
46
+ * @description 全局注册所有组件(ProForm、ProComponentProvider)
47
+ *
48
+ * @param {App} app - Vue 应用实例
49
+ *
50
+ * @example
51
+ * ```ts
52
+ * import { createApp } from 'vue'
53
+ * import ProComponents from '@qin-ui/vant-pro'
54
+ * const app = createApp(App)
55
+ * app.use(ProComponents)
56
+ * ```
57
+ */
58
+ install(app: App) {
59
+ app.component(ProForm.name, ProForm);
60
+ app.component(ProComponentProvider.name!, ProComponentProvider);
61
+ },
62
+ };
@@ -0,0 +1,37 @@
1
+ /**
2
+ * 统一 re-export @qin-ui/pro-components-core,包内所有文件通过此文件引入 core 内容,
3
+ * 避免直接散列依赖 @qin-ui/pro-components-core,便于将来统一维护。
4
+ */
5
+ export {
6
+ // hooks
7
+ useForm,
8
+ useTable,
9
+ useFields,
10
+ useFormData,
11
+ useFormRef,
12
+ // injection keys
13
+ InjectionFormKey,
14
+ InjectionPathKey,
15
+ // utils
16
+ getObject,
17
+ toPath,
18
+ camelizeProperties,
19
+ cloneDeep,
20
+ omit,
21
+ pick,
22
+ isPlainObject,
23
+ // types
24
+ type Data,
25
+ type Path,
26
+ type Paths,
27
+ type KeyExpandString,
28
+ type ExtendWithAny,
29
+ type DeepPartial,
30
+ type PageParam,
31
+ type Fields,
32
+ type Form,
33
+ type Table,
34
+ type UseFieldsReturn,
35
+ type UseFormDataReturn,
36
+ type UseFormRefReturn,
37
+ } from '@qin-ui/pro-components-core';
@@ -0,0 +1,26 @@
1
+ export {
2
+ Form,
3
+ Field,
4
+ Button,
5
+ Popup,
6
+ Picker,
7
+ DatePicker,
8
+ TimePicker,
9
+ Cascader,
10
+ Area,
11
+ Signature,
12
+ Switch,
13
+ Stepper,
14
+ Rate,
15
+ Slider,
16
+ Uploader,
17
+ CheckboxGroup,
18
+ Checkbox,
19
+ RadioGroup,
20
+ Radio,
21
+ Space,
22
+ type FormProps,
23
+ type FormInstance,
24
+ type FieldInstance,
25
+ type FieldProps,
26
+ } from 'vant';
@@ -1,236 +0,0 @@
1
- import { ref, inject, reactive, provide, camelize } from "vue";
2
- import { i as isPlainObject, s as set, g as get, t as toPath } from "../vendor/utils/lodash-es-DN4QDiDm.js";
3
- const InjectionFormKey = Symbol("form");
4
- const InjectionPathKey = Symbol("path");
5
- function getObject(val) {
6
- return isPlainObject(val) ? val : {};
7
- }
8
- function camelizeProperties(obj) {
9
- return Object.fromEntries(
10
- Object.entries(obj).map(([key, value]) => [camelize(key), value])
11
- );
12
- }
13
- const useFields = (initFields) => {
14
- const fields = ref([]);
15
- fields.value = initFields || [];
16
- const _map = /* @__PURE__ */ new Map();
17
- const cacheMatch = (pathStr, updater) => {
18
- var _a;
19
- const fieldPath = _map.get(pathStr) || [];
20
- if (fieldPath.length === 0) return false;
21
- const fieldIndex = fieldPath[fieldPath.length - 1];
22
- const parentField = fieldPath.length === 1 ? fields.value : get(fields.value, fieldPath.slice(0, -2));
23
- const field = (_a = parentField == null ? void 0 : parentField.fields) == null ? void 0 : _a[fieldIndex];
24
- const _path = toPath((field == null ? void 0 : field.name) ?? (field == null ? void 0 : field.path)).join(".");
25
- if (_path === pathStr) {
26
- updater({ field, fieldIndex, parentField });
27
- return true;
28
- }
29
- return false;
30
- };
31
- const updaterMatch = (path, updater, options = {}) => {
32
- if (!path) return;
33
- const pathStr = typeof path === "function" ? "" : toPath(path).join(".");
34
- const { all = typeof path === "function" } = options;
35
- if (pathStr && _map.has(pathStr) && !all) {
36
- const bool = cacheMatch(pathStr, updater);
37
- if (bool) return;
38
- }
39
- const queue = fields.value.map((field, i) => ({
40
- field,
41
- fieldPath: [i],
42
- parentField: { fields: fields.value }
43
- }));
44
- while (queue.length) {
45
- const { field, fieldPath, parentField } = queue.shift();
46
- let matched = false;
47
- const _path = toPath(field.name ?? field.path).join(".");
48
- if (_path) _map.set(_path, fieldPath);
49
- if (typeof path === "function") {
50
- matched = path(field);
51
- } else if (_path) {
52
- matched = pathStr === _path;
53
- }
54
- if (matched) {
55
- const fieldIndex = fieldPath[fieldPath.length - 1];
56
- updater({ field, fieldIndex, parentField });
57
- if (!all) return;
58
- }
59
- if (Array.isArray(field.fields)) {
60
- field.fields.forEach((f, i) => {
61
- queue.push({
62
- field: f,
63
- fieldPath: [...fieldPath, "fields", i],
64
- parentField: field
65
- });
66
- });
67
- }
68
- }
69
- };
70
- function getField(path, options) {
71
- if (!path) return void 0;
72
- const res = [];
73
- updaterMatch(
74
- path,
75
- ({ field }) => {
76
- res.push(field);
77
- },
78
- options
79
- );
80
- return (options == null ? void 0 : options.all) ? res : res[0];
81
- }
82
- function setField(path, field, options) {
83
- if (!path) return;
84
- const { updateType = "merge", ...rest } = options || {};
85
- updaterMatch(
86
- path,
87
- ({ field: preField, fieldIndex, parentField }) => {
88
- let value = field;
89
- if (typeof field === "function") {
90
- value = field(preField);
91
- }
92
- if (!value) return;
93
- if (updateType === "rewrite") {
94
- parentField.fields[fieldIndex] = value;
95
- } else {
96
- Object.assign(preField, value);
97
- }
98
- },
99
- rest
100
- );
101
- }
102
- function deleteField(path, options) {
103
- if (!path) return;
104
- updaterMatch(
105
- path,
106
- ({ fieldIndex, parentField }) => {
107
- parentField.fields.splice(fieldIndex, 1);
108
- },
109
- options
110
- );
111
- }
112
- function appendField(path, field, options) {
113
- const newFields = Array.isArray(field) ? field : [field];
114
- addFields(path, newFields, options, "after");
115
- }
116
- function prependField(path, field, options) {
117
- const newFields = Array.isArray(field) ? field : [field];
118
- addFields(path, newFields, options, "before");
119
- }
120
- function getParentField(path, options) {
121
- if (!path) return void 0;
122
- const res = [];
123
- updaterMatch(
124
- path,
125
- ({ parentField }) => {
126
- res.push(parentField);
127
- },
128
- options
129
- );
130
- return (options == null ? void 0 : options.all) ? res : res[0];
131
- }
132
- function addFields(path, newFields, options, placement) {
133
- if (newFields.length === 0) return;
134
- if (path) {
135
- updaterMatch(
136
- path,
137
- ({ fieldIndex, parentField }) => {
138
- const index = placement === "after" ? fieldIndex + 1 : fieldIndex;
139
- parentField.fields.splice(index, 0, ...newFields);
140
- },
141
- options
142
- );
143
- } else if (placement === "after") {
144
- fields.value.push(...newFields);
145
- } else {
146
- fields.value.unshift(...newFields);
147
- }
148
- }
149
- return {
150
- fields,
151
- getField,
152
- setField,
153
- deleteField,
154
- appendField,
155
- prependField,
156
- getParentField
157
- };
158
- };
159
- const InjectionFormDataKey = Symbol("form-data");
160
- const useFormData = (initFormData) => {
161
- if (!initFormData) {
162
- const injectFormDataStore = inject(InjectionFormDataKey, void 0);
163
- if (injectFormDataStore) return injectFormDataStore;
164
- }
165
- const formData = reactive(initFormData ?? {});
166
- function getFormData(path) {
167
- if (!path) return void 0;
168
- return get(formData, path);
169
- }
170
- function setFormData(...args) {
171
- let path;
172
- let value;
173
- if (args.length >= 2) {
174
- [path, value] = args;
175
- if (!path) return;
176
- } else {
177
- [value] = args;
178
- }
179
- if (path) {
180
- if (typeof value === "function") {
181
- const preValue = getFormData(path);
182
- value = value(preValue);
183
- }
184
- set(formData, path, value);
185
- } else {
186
- if (typeof value === "function") {
187
- const preValue = formData;
188
- value = value(preValue);
189
- }
190
- if (!isPlainObject(value)) return;
191
- Object.keys(formData).forEach((key) => {
192
- delete formData[key];
193
- });
194
- Object.assign(formData, value);
195
- }
196
- }
197
- const formDataStore = { formData, getFormData, setFormData };
198
- provide(InjectionFormDataKey, formDataStore);
199
- return formDataStore;
200
- };
201
- const useFormRef = () => {
202
- const formRef = ref();
203
- const setFormRef = (inst) => {
204
- formRef.value = inst;
205
- };
206
- return { formRef, setFormRef };
207
- };
208
- function useForm(...args) {
209
- let initFormData = {}, initFields = [], root = true;
210
- if (args.length === 1) {
211
- root = args[0];
212
- } else if (args.length >= 2) {
213
- initFormData = args[0] ?? {};
214
- initFields = args[1];
215
- root = args[2] ?? root;
216
- }
217
- if (!root) {
218
- const injectForm = inject(InjectionFormKey);
219
- if (injectForm) return injectForm;
220
- }
221
- return {
222
- ...useFormData(initFormData),
223
- ...useFields(initFields),
224
- ...useFormRef()
225
- };
226
- }
227
- export {
228
- InjectionPathKey as I,
229
- InjectionFormKey as a,
230
- useFields as b,
231
- camelizeProperties as c,
232
- useFormRef as d,
233
- useFormData as e,
234
- getObject as g,
235
- useForm as u
236
- };