@xiaohaih/json-form-vant 0.0.1

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 (213) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/README.md +807 -0
  3. package/TODO.md +36 -0
  4. package/components/area/index.ts +6 -0
  5. package/components/area/index.vue +120 -0
  6. package/components/area/types.ts +84 -0
  7. package/components/cascader/index.ts +6 -0
  8. package/components/cascader/index.vue +146 -0
  9. package/components/cascader/types.ts +75 -0
  10. package/components/checkbox/index.ts +6 -0
  11. package/components/checkbox/index.vue +59 -0
  12. package/components/checkbox/types.ts +54 -0
  13. package/components/checkbox-group/index.ts +6 -0
  14. package/components/checkbox-group/index.vue +67 -0
  15. package/components/checkbox-group/types.ts +63 -0
  16. package/components/component-definition/components.ts +29 -0
  17. package/components/component-definition/definition.ts +25 -0
  18. package/components/component-definition/index.ts +4 -0
  19. package/components/custom-render/index.ts +6 -0
  20. package/components/custom-render/index.vue +66 -0
  21. package/components/custom-render/types.ts +43 -0
  22. package/components/date-picker/index.ts +6 -0
  23. package/components/date-picker/index.vue +130 -0
  24. package/components/date-picker/types.ts +91 -0
  25. package/components/date-time-picker-group/index.ts +6 -0
  26. package/components/date-time-picker-group/index.vue +158 -0
  27. package/components/date-time-picker-group/types.ts +115 -0
  28. package/components/datetime-picker/index.ts +6 -0
  29. package/components/datetime-picker/index.vue +128 -0
  30. package/components/datetime-picker/types.ts +78 -0
  31. package/components/dynamic-group/index.ts +10 -0
  32. package/components/dynamic-group/index.vue +140 -0
  33. package/components/dynamic-group/types.ts +68 -0
  34. package/components/group/assist.ts +99 -0
  35. package/components/group/index.ts +7 -0
  36. package/components/group/index.vue +117 -0
  37. package/components/group/types.ts +57 -0
  38. package/components/group/virtual-group.vue +38 -0
  39. package/components/index.ts +10 -0
  40. package/components/input/index.ts +6 -0
  41. package/components/input/index.vue +83 -0
  42. package/components/input/types.ts +43 -0
  43. package/components/input-slot/index.ts +6 -0
  44. package/components/input-slot/index.vue +148 -0
  45. package/components/input-slot/types.ts +34 -0
  46. package/components/number-keyboard/index.ts +6 -0
  47. package/components/number-keyboard/index.vue +81 -0
  48. package/components/number-keyboard/types.ts +57 -0
  49. package/components/password-input/index.ts +6 -0
  50. package/components/password-input/index.vue +103 -0
  51. package/components/password-input/types.ts +64 -0
  52. package/components/picker/index.ts +6 -0
  53. package/components/picker/index.vue +136 -0
  54. package/components/picker/types.ts +94 -0
  55. package/components/radio/index.ts +6 -0
  56. package/components/radio/index.vue +68 -0
  57. package/components/radio/types.ts +58 -0
  58. package/components/radio-group/index.ts +6 -0
  59. package/components/radio-group/index.vue +74 -0
  60. package/components/radio-group/types.ts +65 -0
  61. package/components/rate/index.ts +6 -0
  62. package/components/rate/index.vue +63 -0
  63. package/components/rate/types.ts +47 -0
  64. package/components/share.ts +78 -0
  65. package/components/signature/index.ts +6 -0
  66. package/components/signature/index.vue +65 -0
  67. package/components/signature/instance.vue +161 -0
  68. package/components/signature/types.ts +79 -0
  69. package/components/slider/index.ts +6 -0
  70. package/components/slider/index.vue +63 -0
  71. package/components/slider/types.ts +53 -0
  72. package/components/stepper/index.ts +6 -0
  73. package/components/stepper/index.vue +62 -0
  74. package/components/stepper/types.ts +47 -0
  75. package/components/switch/index.ts +6 -0
  76. package/components/switch/index.vue +61 -0
  77. package/components/switch/types.ts +51 -0
  78. package/components/time-picker/index.ts +6 -0
  79. package/components/time-picker/index.vue +130 -0
  80. package/components/time-picker/types.ts +91 -0
  81. package/components/tree-select/index.ts +6 -0
  82. package/components/tree-select/index.vue +160 -0
  83. package/components/tree-select/types.ts +77 -0
  84. package/components/upload/index.ts +6 -0
  85. package/components/upload/index.vue +109 -0
  86. package/components/upload/types.ts +85 -0
  87. package/components/use.ts +45 -0
  88. package/components/utils.ts +52 -0
  89. package/components/wrapper/index.ts +6 -0
  90. package/components/wrapper/index.vue +117 -0
  91. package/components/wrapper/types.ts +94 -0
  92. package/dist/components/area/index.d.ts +5 -0
  93. package/dist/components/area/index.vue.d.ts +1843 -0
  94. package/dist/components/area/types.d.ts +1434 -0
  95. package/dist/components/cascader/index.d.ts +5 -0
  96. package/dist/components/cascader/index.vue.d.ts +2467 -0
  97. package/dist/components/cascader/types.d.ts +1419 -0
  98. package/dist/components/checkbox/index.d.ts +5 -0
  99. package/dist/components/checkbox/index.vue.d.ts +1550 -0
  100. package/dist/components/checkbox/types.d.ts +1313 -0
  101. package/dist/components/checkbox-group/index.d.ts +5 -0
  102. package/dist/components/checkbox-group/index.vue.d.ts +1643 -0
  103. package/dist/components/checkbox-group/types.d.ts +1372 -0
  104. package/dist/components/component-definition/components.d.ts +30 -0
  105. package/dist/components/component-definition/index.d.ts +4 -0
  106. package/dist/components/custom-render/index.d.ts +5 -0
  107. package/dist/components/custom-render/index.vue.d.ts +1473 -0
  108. package/dist/components/custom-render/types.d.ts +1175 -0
  109. package/dist/components/date-picker/index.d.ts +5 -0
  110. package/dist/components/date-picker/index.vue.d.ts +1888 -0
  111. package/dist/components/date-picker/types.d.ts +1458 -0
  112. package/dist/components/date-time-picker-group/index.d.ts +5 -0
  113. package/dist/components/date-time-picker-group/index.vue.d.ts +2181 -0
  114. package/dist/components/date-time-picker-group/types.d.ts +1549 -0
  115. package/dist/components/dynamic-group/index.d.ts +5 -0
  116. package/dist/components/dynamic-group/index.vue.d.ts +457 -0
  117. package/dist/components/dynamic-group/types.d.ts +403 -0
  118. package/dist/components/group/assist.d.ts +58 -0
  119. package/dist/components/group/index.d.ts +6 -0
  120. package/dist/components/group/index.vue.d.ts +139 -0
  121. package/dist/components/group/types.d.ts +189 -0
  122. package/dist/components/group/virtual-group.vue.d.ts +42 -0
  123. package/dist/components/index.d.ts +3 -0
  124. package/dist/components/input/index.d.ts +5 -0
  125. package/dist/components/input/index.vue.d.ts +2229 -0
  126. package/dist/components/input/types.d.ts +1258 -0
  127. package/dist/components/input-slot/index.d.ts +5 -0
  128. package/dist/components/input-slot/index.vue.d.ts +626 -0
  129. package/dist/components/input-slot/types.d.ts +311 -0
  130. package/dist/components/number-keyboard/index.d.ts +5 -0
  131. package/dist/components/number-keyboard/index.vue.d.ts +1643 -0
  132. package/dist/components/number-keyboard/types.d.ts +1324 -0
  133. package/dist/components/password-input/index.d.ts +5 -0
  134. package/dist/components/password-input/index.vue.d.ts +1715 -0
  135. package/dist/components/password-input/types.d.ts +1357 -0
  136. package/dist/components/picker/index.d.ts +5 -0
  137. package/dist/components/picker/index.vue.d.ts +1868 -0
  138. package/dist/components/picker/types.d.ts +1466 -0
  139. package/dist/components/radio/index.d.ts +5 -0
  140. package/dist/components/radio/index.vue.d.ts +1563 -0
  141. package/dist/components/radio/types.d.ts +1327 -0
  142. package/dist/components/radio-group/index.d.ts +5 -0
  143. package/dist/components/radio-group/index.vue.d.ts +1617 -0
  144. package/dist/components/radio-group/types.d.ts +1383 -0
  145. package/dist/components/rate/index.d.ts +5 -0
  146. package/dist/components/rate/index.vue.d.ts +1557 -0
  147. package/dist/components/rate/types.d.ts +1281 -0
  148. package/dist/components/share.d.ts +679 -0
  149. package/dist/components/signature/index.d.ts +5 -0
  150. package/dist/components/signature/index.vue.d.ts +3017 -0
  151. package/dist/components/signature/instance.vue.d.ts +1614 -0
  152. package/dist/components/signature/types.d.ts +1369 -0
  153. package/dist/components/slider/index.d.ts +5 -0
  154. package/dist/components/slider/index.vue.d.ts +1563 -0
  155. package/dist/components/slider/types.d.ts +1302 -0
  156. package/dist/components/stepper/index.d.ts +5 -0
  157. package/dist/components/stepper/index.vue.d.ts +1620 -0
  158. package/dist/components/stepper/types.d.ts +1281 -0
  159. package/dist/components/switch/index.d.ts +5 -0
  160. package/dist/components/switch/index.vue.d.ts +1529 -0
  161. package/dist/components/switch/types.d.ts +1296 -0
  162. package/dist/components/time-picker/index.d.ts +5 -0
  163. package/dist/components/time-picker/index.vue.d.ts +1936 -0
  164. package/dist/components/time-picker/types.d.ts +1458 -0
  165. package/dist/components/tree-select/index.d.ts +5 -0
  166. package/dist/components/tree-select/index.vue.d.ts +1802 -0
  167. package/dist/components/tree-select/types.d.ts +1411 -0
  168. package/dist/components/upload/index.d.ts +5 -0
  169. package/dist/components/upload/index.vue.d.ts +1697 -0
  170. package/dist/components/upload/types.d.ts +1376 -0
  171. package/dist/components/use.d.ts +53 -0
  172. package/dist/components/utils.d.ts +15 -0
  173. package/dist/components/wrapper/index.d.ts +5 -0
  174. package/dist/components/wrapper/index.vue.d.ts +1085 -0
  175. package/dist/components/wrapper/types.d.ts +541 -0
  176. package/dist/docs/.vitepress/config.d.ts +3 -0
  177. package/dist/docs/.vitepress/theme/index.d.ts +2 -0
  178. package/dist/index.cjs.js +5459 -0
  179. package/dist/index.cjs.js.map +1 -0
  180. package/dist/index.cjs.min.js +3568 -0
  181. package/dist/index.cjs.min.js.map +1 -0
  182. package/dist/index.esm.js +5264 -0
  183. package/dist/index.esm.js.map +1 -0
  184. package/dist/index.esm.min.js +3559 -0
  185. package/dist/index.esm.min.js.map +1 -0
  186. package/dist/index.umd.js +5465 -0
  187. package/dist/index.umd.js.map +1 -0
  188. package/dist/index.umd.min.js +3573 -0
  189. package/dist/index.umd.min.js.map +1 -0
  190. package/dist/src/assist.d.ts +32 -0
  191. package/dist/src/index.d.ts +5 -0
  192. package/dist/src/interface.d.ts +129 -0
  193. package/dist/src/utils.d.ts +9 -0
  194. package/dist/src/version.d.ts +2 -0
  195. package/docs/.vitepress/config.ts +99 -0
  196. package/docs/.vitepress/theme/index.ts +5 -0
  197. package/docs/README.md +20 -0
  198. package/docs/index.md +25 -0
  199. package/env.d.ts +8 -0
  200. package/package.json +71 -0
  201. package/scripts/generate-version.mjs +26 -0
  202. package/scripts/postinstall.cjs +13 -0
  203. package/scripts/utils.cjs +67 -0
  204. package/src/assist.ts +40 -0
  205. package/src/index.ts +5 -0
  206. package/src/interface.ts +293 -0
  207. package/src/utils.ts +22 -0
  208. package/src/version.ts +2 -0
  209. package/tsconfig.app.json +41 -0
  210. package/tsconfig.json +7 -0
  211. package/tsconfig.node.json +24 -0
  212. package/tsdown.config.ts +12 -0
  213. package/vite.config.ts +93 -0
@@ -0,0 +1,293 @@
1
+ import type { CoreOption, GetOptions, getProvideValue, usePlain } from '@xiaohaih/json-form-core';
2
+ import type { CellGroupProps as VanCellGroupProps, Form as VanForm } from 'vant';
3
+ import type { Ref } from 'vue';
4
+ import type { ComponentExposed, ComponentProps } from 'vue-component-type-helpers';
5
+ import type {
6
+ AreaProps as PureAreaProps,
7
+ CascaderProps as PureCascaderProps,
8
+ CheckboxGroupProps as PureCheckboxGroupProps,
9
+ CheckboxProps as PureCheckboxProps,
10
+ CustomRenderProps as PureCustomRenderProps,
11
+ DatePickerProps as PureDatePickerProps,
12
+ DateTimePickerGroupProps as PureDateTimePickerGroupProps,
13
+ DatetimePickerProps as PureDatetimePickerProps,
14
+ DynamicGroupProps as PureDynamicGroupProps,
15
+ GroupProps as PureGroupProps,
16
+ InputProps as PureInputProps,
17
+ NumberKeyboardProps as PureNumberKeyboardProps,
18
+ PasswordInputProps as PurePasswordInputProps,
19
+ PickerProps as PurePickerProps,
20
+ RadioGroupProps as PureRadioGroupProps,
21
+ RadioProps as PureRadioProps,
22
+ RateProps as PureRateProps,
23
+ SignatureProps as PureSignatureProps,
24
+ SliderProps as PureSliderProps,
25
+ StepperProps as PureStepperProps,
26
+ SwitchProps as PureSwitchProps,
27
+ TimePickerProps as PureTimePickerProps,
28
+ TreeSelectProps as PureTreeSelectProps,
29
+ UploadProps as PureUploadProps,
30
+ } from '../components/index';
31
+ import type { ComponentType } from '../components/share';
32
+
33
+ type BuiltInField<T = ''> = CoreOption.BuiltInField | keyof RewriteOption<any, any, any, any> | T;
34
+
35
+ /** 重写下列选项(函数内导出的属性无法被推断出来) */
36
+ interface RewriteOption<Field, Query extends Record<string, any>, Option, OptionQuery extends Record<string, any>> {
37
+ /** 提交的字段 */
38
+ field?: Field;
39
+ /** 提交的字段集(多选时, 每个下标对应的字段可能不一样)) */
40
+ fields?: Field[];
41
+ /** 数据源 */
42
+ options?: Option;
43
+ /** 获取数据源的方法 */
44
+ getOptions?: GetOptions<Query, OptionQuery>;
45
+ }
46
+
47
+ /** 条件声明集合 */
48
+ export type JSONFormOption<Field, Query extends Record<string, any>, Option, OptionQuery extends Record<string, any>>
49
+ = | AreaProps<Field, Query, Option, OptionQuery>
50
+ | CascaderProps<Field, Query, Option, OptionQuery>
51
+ | CheckboxGroupProps<Field, Query, Option, OptionQuery>
52
+ | CheckboxProps<Field, Query, Option, OptionQuery>
53
+ | CustomRenderProps<Field, Query, Option, OptionQuery>
54
+ | DatePickerProps<Field, Query, Option, OptionQuery>
55
+ | DateTimePickerGroupProps<Field, Query, Option, OptionQuery>
56
+ | DatetimePickerProps<Field, Query, Option, OptionQuery>
57
+ | DynamicGroupProps<Field, Query, Option, OptionQuery>
58
+ | GroupProps<Field, Query, Option, OptionQuery>
59
+ | CellGroupProps<Field, Query, Option, OptionQuery>
60
+ | InputProps<Field, Query, Option, OptionQuery>
61
+ | NumberKeyboardProps<Field, Query, Option, OptionQuery>
62
+ | PasswordInputProps<Field, Query, Option, OptionQuery>
63
+ | PickerProps<Field, Query, Option, OptionQuery>
64
+ | RadioGroupProps<Field, Query, Option, OptionQuery>
65
+ | RadioProps<Field, Query, Option, OptionQuery>
66
+ | RateProps<Field, Query, Option, OptionQuery>
67
+ | SignatureProps<Field, Query, Option, OptionQuery>
68
+ | SliderProps<Field, Query, Option, OptionQuery>
69
+ | StepperProps<Field, Query, Option, OptionQuery>
70
+ | SwitchProps<Field, Query, Option, OptionQuery>
71
+ | TimePickerProps<Field, Query, Option, OptionQuery>
72
+ | TreeSelectProps<Field, Query, Option, OptionQuery>
73
+ | UploadProps<Field, Query, Option, OptionQuery>;
74
+
75
+ export interface AreaProps<
76
+ Field,
77
+ Query extends Record<string, any>,
78
+ Option,
79
+ OptionQuery extends Record<string, any> = Record<string, any>,
80
+ > extends Omit<PureAreaProps<Query, OptionQuery>, BuiltInField>, RewriteOption<Field, Query, Option, OptionQuery> {
81
+ t: 'area';
82
+ }
83
+ export interface CascaderProps<
84
+ Field,
85
+ Query extends Record<string, any>,
86
+ Option,
87
+ OptionQuery extends Record<string, any> = Record<string, any>,
88
+ > extends Omit<PureCascaderProps<Query, OptionQuery>, BuiltInField>, RewriteOption<Field, Query, Option, OptionQuery> {
89
+ t: 'cascader';
90
+ }
91
+ export interface CheckboxGroupProps<
92
+ Field,
93
+ Query extends Record<string, any>,
94
+ Option,
95
+ OptionQuery extends Record<string, any> = Record<string, any>,
96
+ > extends Omit<PureCheckboxGroupProps<Query, OptionQuery>, BuiltInField>, RewriteOption<Field, Query, Option, OptionQuery> {
97
+ t: 'checkbox-group';
98
+ }
99
+ export interface CheckboxProps<
100
+ Field,
101
+ Query extends Record<string, any>,
102
+ Option,
103
+ OptionQuery extends Record<string, any> = Record<string, any>,
104
+ > extends Omit<PureCheckboxProps<Query, OptionQuery>, BuiltInField>, RewriteOption<Field, Query, Option, OptionQuery> {
105
+ t: 'checkbox';
106
+ }
107
+ export interface CustomRenderProps<
108
+ Field,
109
+ Query extends Record<string, any>,
110
+ Option,
111
+ OptionQuery extends Record<string, any> = Record<string, any>,
112
+ > extends Omit<PureCustomRenderProps<Query, OptionQuery>, BuiltInField>, RewriteOption<Field, Query, Option, OptionQuery> {
113
+ t: 'custom-render';
114
+ }
115
+ export interface DatePickerProps<
116
+ Field,
117
+ Query extends Record<string, any>,
118
+ Option,
119
+ OptionQuery extends Record<string, any> = Record<string, any>,
120
+ > extends Omit<PureDatePickerProps<Query, OptionQuery>, BuiltInField>, RewriteOption<Field, Query, Option, OptionQuery> {
121
+ t: 'date-picker';
122
+ }
123
+ export interface DateTimePickerGroupProps<
124
+ Field,
125
+ Query extends Record<string, any>,
126
+ Option,
127
+ OptionQuery extends Record<string, any> = Record<string, any>,
128
+ > extends Omit<PureDateTimePickerGroupProps<Query, OptionQuery>, BuiltInField>, RewriteOption<Field, Query, Option, OptionQuery> {
129
+ t: 'date-time-picker-group';
130
+ }
131
+ export interface DatetimePickerProps<
132
+ Field,
133
+ Query extends Record<string, any>,
134
+ Option,
135
+ OptionQuery extends Record<string, any> = Record<string, any>,
136
+ > extends Omit<PureDatetimePickerProps<Query, OptionQuery>, BuiltInField>, RewriteOption<Field, Query, Option, OptionQuery> {
137
+ /**
138
+ * @deprecated vant@3.x版本使用, vant@4.x版本使用 date-time-picker-group
139
+ */
140
+ t: 'datetime-picker';
141
+ }
142
+ export interface DynamicGroupProps<
143
+ Field,
144
+ Query extends Record<string, any>,
145
+ Option,
146
+ OptionQuery extends Record<string, any> = Record<string, any>,
147
+ > extends Omit<PureDynamicGroupProps<Query, OptionQuery>, BuiltInField | 'config'>, RewriteOption<Field, Query, Option, OptionQuery> {
148
+ t: 'dynamic-group';
149
+ /**
150
+ * 渲染的子条件(重写该属性以补充声明)
151
+ * 动态表单不是根级属性, 不应该暴露出来, 遂用 string 替代
152
+ */
153
+ config?: MaybeFunction<[{ item: Record<string, any>; index: number; checked: Record<string, any>[]; query: Query; plain: ReturnType<typeof usePlain> }], JSONFormOption<string, Query, Option, OptionQuery>[] | Record<keyof Query, JSONFormOption<string, Query, Option, OptionQuery>>>;
154
+ }
155
+ export interface GroupProps<
156
+ Field,
157
+ Query extends Record<string, any>,
158
+ Option,
159
+ OptionQuery extends Record<string, any> = Record<string, any>,
160
+ > extends Omit<PureGroupProps<Query, OptionQuery>, BuiltInField | 'config' | 'getFormRef'>, RewriteOption<Field, Query, Option, OptionQuery> {
161
+ t: 'group';
162
+ /** 渲染的子条件(重写该属性以补充声明) */
163
+ config?: MaybeFunction<[{ query: Query; wrapper?: ReturnType<typeof getProvideValue<Query, OptionQuery, Ref<ComponentExposed<typeof VanForm>>>> }], JSONFormOption<Field, Query, Option, OptionQuery>[] | Record<keyof Query, JSONFormOption<Field, Query, Option, OptionQuery>>>;
164
+ }
165
+ export interface CellGroupProps<
166
+ Field,
167
+ Query extends Record<string, any>,
168
+ Option,
169
+ OptionQuery extends Record<string, any> = Record<string, any>,
170
+ > extends Omit<PureGroupProps<Query, OptionQuery>, BuiltInField | 'config' | 'getFormRef' | 'slots' | 'tagSlots'>, RewriteOption<Field, Query, Option, OptionQuery>, Partial<VanCellGroupProps> {
171
+ t: 'cell-group';
172
+ /** 重写插槽声明 */
173
+ slots?: PureGroupProps<Query, OptionQuery>['slots'] & {
174
+ /** 自定义分组标题 */
175
+ title?: ComponentType<{ query: Query; wrapper?: ReturnType<typeof getProvideValue<Query, OptionQuery, Ref<ComponentExposed<typeof VanForm>>>> }>;
176
+ };
177
+ /** 渲染的子条件(重写该属性以补充声明) */
178
+ config?: MaybeFunction<[{ query: Query; wrapper?: ReturnType<typeof getProvideValue<Query, OptionQuery, Ref<ComponentExposed<typeof VanForm>>>> }], JSONFormOption<Field, Query, Option, OptionQuery>[] | Record<keyof Query, JSONFormOption<Field, Query, Option, OptionQuery>>>;
179
+ }
180
+ export interface InputProps<
181
+ Field,
182
+ Query extends Record<string, any>,
183
+ Option,
184
+ OptionQuery extends Record<string, any> = Record<string, any>,
185
+ > extends Omit<PureInputProps<Query, OptionQuery>, BuiltInField>, RewriteOption<Field, Query, Option, OptionQuery> {
186
+ t: 'input';
187
+ }
188
+ export interface NumberKeyboardProps<
189
+ Field,
190
+ Query extends Record<string, any>,
191
+ Option,
192
+ OptionQuery extends Record<string, any> = Record<string, any>,
193
+ > extends Omit<PureNumberKeyboardProps<Query, OptionQuery>, BuiltInField>, RewriteOption<Field, Query, Option, OptionQuery> {
194
+ t: 'number-keyboard';
195
+ }
196
+ export interface PasswordInputProps<
197
+ Field,
198
+ Query extends Record<string, any>,
199
+ Option,
200
+ OptionQuery extends Record<string, any> = Record<string, any>,
201
+ > extends Omit<PurePasswordInputProps<Query, OptionQuery>, BuiltInField>, RewriteOption<Field, Query, Option, OptionQuery> {
202
+ t: 'password-input';
203
+ }
204
+ export interface PickerProps<
205
+ Field,
206
+ Query extends Record<string, any>,
207
+ Option,
208
+ OptionQuery extends Record<string, any> = Record<string, any>,
209
+ > extends Omit<PurePickerProps<Query, OptionQuery>, BuiltInField>, RewriteOption<Field, Query, Option, OptionQuery> {
210
+ t: 'picker' | 'select';
211
+ }
212
+ export interface RadioGroupProps<
213
+ Field,
214
+ Query extends Record<string, any>,
215
+ Option,
216
+ OptionQuery extends Record<string, any> = Record<string, any>,
217
+ > extends Omit<PureRadioGroupProps<Query, OptionQuery>, BuiltInField>, RewriteOption<Field, Query, Option, OptionQuery> {
218
+ t: 'radio-group';
219
+ }
220
+ export interface RadioProps<
221
+ Field,
222
+ Query extends Record<string, any>,
223
+ Option,
224
+ OptionQuery extends Record<string, any> = Record<string, any>,
225
+ > extends Omit<PureRadioProps<Query, OptionQuery>, BuiltInField>, RewriteOption<Field, Query, Option, OptionQuery> {
226
+ t: 'radio';
227
+ }
228
+ export interface RateProps<
229
+ Field,
230
+ Query extends Record<string, any>,
231
+ Option,
232
+ OptionQuery extends Record<string, any> = Record<string, any>,
233
+ > extends Omit<PureRateProps<Query, OptionQuery>, BuiltInField>, RewriteOption<Field, Query, Option, OptionQuery> {
234
+ t: 'rate';
235
+ }
236
+ export interface SignatureProps<
237
+ Field,
238
+ Query extends Record<string, any>,
239
+ Option,
240
+ OptionQuery extends Record<string, any> = Record<string, any>,
241
+ > extends Omit<PureSignatureProps<Query, OptionQuery>, BuiltInField>, RewriteOption<Field, Query, Option, OptionQuery> {
242
+ t: 'signature';
243
+ }
244
+ export interface SliderProps<
245
+ Field,
246
+ Query extends Record<string, any>,
247
+ Option,
248
+ OptionQuery extends Record<string, any> = Record<string, any>,
249
+ > extends Omit<PureSliderProps<Query, OptionQuery>, BuiltInField>, RewriteOption<Field, Query, Option, OptionQuery> {
250
+ t: 'slider';
251
+ }
252
+ export interface StepperProps<
253
+ Field,
254
+ Query extends Record<string, any>,
255
+ Option,
256
+ OptionQuery extends Record<string, any> = Record<string, any>,
257
+ > extends Omit<PureStepperProps<Query, OptionQuery>, BuiltInField>, RewriteOption<Field, Query, Option, OptionQuery> {
258
+ t: 'stepper';
259
+ }
260
+ export interface SwitchProps<
261
+ Field,
262
+ Query extends Record<string, any>,
263
+ Option,
264
+ OptionQuery extends Record<string, any> = Record<string, any>,
265
+ > extends Omit<PureSwitchProps<Query, OptionQuery>, BuiltInField>, RewriteOption<Field, Query, Option, OptionQuery> {
266
+ t: 'switch';
267
+ }
268
+ export interface TimePickerProps<
269
+ Field,
270
+ Query extends Record<string, any>,
271
+ Option,
272
+ OptionQuery extends Record<string, any> = Record<string, any>,
273
+ > extends Omit<PureTimePickerProps<Query, OptionQuery>, BuiltInField>, RewriteOption<Field, Query, Option, OptionQuery> {
274
+ t: 'time-picker';
275
+ }
276
+ export interface TreeSelectProps<
277
+ Field,
278
+ Query extends Record<string, any>,
279
+ Option,
280
+ OptionQuery extends Record<string, any> = Record<string, any>,
281
+ > extends Omit<PureTreeSelectProps<Query, OptionQuery>, BuiltInField>, RewriteOption<Field, Query, Option, OptionQuery> {
282
+ t: 'tree-select';
283
+ }
284
+ export interface UploadProps<
285
+ Field,
286
+ Query extends Record<string, any>,
287
+ Option,
288
+ OptionQuery extends Record<string, any> = Record<string, any>,
289
+ > extends Omit<PureUploadProps<Query, OptionQuery>, BuiltInField>, RewriteOption<Field, Query, Option, OptionQuery> {
290
+ t: 'upload';
291
+ }
292
+
293
+ export type MaybeFunction<TParams extends any[], TResult> = TResult | ((...args: TParams) => TResult);
package/src/utils.ts ADDED
@@ -0,0 +1,22 @@
1
+ /**
2
+ * 选取对象中指定属性
3
+ */
4
+ export function pick<T extends object, TKeys extends keyof T>(obj: T, keys: TKeys[]): Pick<T, TKeys>;
5
+ export function pick<T extends object, TKeys extends string>(obj: T, keys: TKeys[]): T;
6
+ export function pick<T extends object, TKeys extends keyof T>(obj: T, keys: TKeys[]): Pick<T, TKeys> {
7
+ if (!obj) return {} as Pick<T, TKeys>;
8
+ return keys.reduce((acc, key) => {
9
+ if (Object.prototype.hasOwnProperty.call(obj, key)) acc[key] = obj[key];
10
+ return acc;
11
+ }, {} as Pick<T, TKeys>);
12
+ }
13
+
14
+ /**
15
+ * 数组扁平化
16
+ */
17
+ export function flat<T>(lists: readonly T[][]): T[] {
18
+ return lists.reduce((acc, list) => {
19
+ acc.push(...list);
20
+ return acc;
21
+ }, []);
22
+ }
package/src/version.ts ADDED
@@ -0,0 +1,2 @@
1
+ /** 版本号 */
2
+ export const version = '0.0.1';
@@ -0,0 +1,41 @@
1
+ {
2
+ "extends": [
3
+ "@vue/tsconfig/tsconfig.dom.json",
4
+ "@vue/tsconfig/tsconfig.lib.json"
5
+ ],
6
+ "compilerOptions": {
7
+ "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
8
+
9
+ "paths": {
10
+ "@/*": ["./src/*"]
11
+ },
12
+ /* 包含类型定义的文件夹. */
13
+ "typeRoots": ["node_modules/@types"],
14
+
15
+ /* Linting */
16
+ "allowImportingTsExtensions": true,
17
+ "allowJs": true,
18
+ "strict": true,
19
+ "allowUnusedLabels": true,
20
+ "noFallthroughCasesInSwitch": true,
21
+ /* 禁止隐式 any. */
22
+ "noImplicitAny": true,
23
+ "noUnusedLocals": false,
24
+ "noUnusedParameters": false,
25
+ /* 不解析符号链接的真实路径. */
26
+ "preserveSymlinks": true,
27
+ "noUncheckedSideEffectImports": true
28
+ },
29
+ "include": [
30
+ "components/**/*.ts",
31
+ "components/**/*.tsx",
32
+ "components/**/*.vue",
33
+ "src/**/*.ts",
34
+ "src/**/*.tsx",
35
+ "src/**/*.vue",
36
+ "tests/**/*.ts",
37
+ "tests/**/*.tsx",
38
+ "docs/.vitepress/**/*.ts",
39
+ "docs/**/*.md"
40
+ ]
41
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,7 @@
1
+ {
2
+ "references": [
3
+ { "path": "./tsconfig.app.json" },
4
+ { "path": "./tsconfig.node.json" }
5
+ ],
6
+ "files": []
7
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "compilerOptions": {
3
+ "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
4
+ "target": "es2023",
5
+ "lib": ["ES2023"],
6
+ "moduleDetection": "force",
7
+ "module": "esnext",
8
+
9
+ /* Bundler mode */
10
+ "moduleResolution": "bundler",
11
+ "types": ["node"],
12
+ "allowImportingTsExtensions": true,
13
+
14
+ "noFallthroughCasesInSwitch": true,
15
+ /* Linting */
16
+ "noUnusedLocals": true,
17
+ "noUnusedParameters": true,
18
+ "noEmit": true,
19
+ "verbatimModuleSyntax": true,
20
+ "erasableSyntaxOnly": true,
21
+ "skipLibCheck": true
22
+ },
23
+ "include": ["*.config.ts"]
24
+ }
@@ -0,0 +1,12 @@
1
+ import { defineConfig } from 'tsdown';
2
+ import Vue from 'unplugin-vue/rolldown';
3
+
4
+ export default defineConfig({
5
+ entry: ['./src/index.ts'],
6
+ clean: false,
7
+ external: ['vue', /^vant/],
8
+ tsconfig: './tsconfig.app.json',
9
+ platform: 'browser',
10
+ // plugins: [Vue({ })],
11
+ dts: { vue: true, emitDtsOnly: true },
12
+ });
package/vite.config.ts ADDED
@@ -0,0 +1,93 @@
1
+ import { resolve } from 'node:path';
2
+ import { fileURLToPath } from 'node:url';
3
+ import terser from '@rollup/plugin-terser';
4
+ import vue from '@vitejs/plugin-vue';
5
+ import vueJsx from '@vitejs/plugin-vue-jsx';
6
+ import dts from 'unplugin-dts/vite';
7
+ import type { UserConfig } from 'vite';
8
+ import { defineConfig } from 'vite';
9
+ import pkgJson from './package.json';
10
+
11
+ const external = ['vue', 'vant'];
12
+ const globals = { vue: 'Vue', vant: 'vant' };
13
+ const pkg = pkgJson.publishConfig || pkgJson;
14
+
15
+ /**
16
+ * 添加或删除名称中的 min
17
+ * @param {string} name
18
+ * @param {boolean} flag
19
+ */
20
+ function retainMinSuffix(name: string, flag: boolean) {
21
+ const _name = name.replace(/^dist\//, '').replace(/min/, '');
22
+ return flag ? _name.replace(/\.(m?)[j|t]s$/, '.min.$1js') : _name.replace(/\.(m?)ts$/, '.$1js');
23
+ }
24
+
25
+ const __dirname = fileURLToPath(new URL('.', import.meta.url));
26
+
27
+ /**
28
+ * @file vite 环境配置
29
+ */
30
+ // https://vitejs.dev/config/
31
+ export default defineConfig((env) => {
32
+ return {
33
+ define: {
34
+ 'process.env.NODE_ENV': env.command === 'build' ? JSON.stringify('production') : JSON.stringify('development'),
35
+ },
36
+ plugins: [
37
+ vue(),
38
+ vueJsx(),
39
+ dts({
40
+ tsconfigPath: './tsconfig.app.json',
41
+ // insertTypesEntry: true,
42
+ // rollupTypes: true,
43
+ // 由于 vant3 比 vant4 多一个组件, 打包时会自动检索所有文件
44
+ // 而处于高版本没法打包 vant3 的组件, 所以这里手动排除
45
+ exclude: [
46
+ 'components/component-definition/definition.ts',
47
+ 'components/datetime-picker/index.vue',
48
+ 'components/datetime-picker/index.ts',
49
+ 'components/datetime-picker/types.ts',
50
+ ],
51
+ }),
52
+ ],
53
+ optimizeDeps: {
54
+ exclude: ['vue-demi'],
55
+ },
56
+ build: {
57
+ lib: {
58
+ entry: resolve(__dirname, './src/index.ts'),
59
+ name: 'JSONForm',
60
+ fileName: 'index',
61
+ },
62
+ outDir: 'dist',
63
+ sourcemap: true,
64
+ minify: false,
65
+ rolldownOptions: {
66
+ external,
67
+ output: [
68
+ { entryFileNames: retainMinSuffix(pkg.module, false), format: 'es' },
69
+ {
70
+ entryFileNames: retainMinSuffix(pkg.module, true),
71
+ format: 'es',
72
+ plugins: [terser({ format: { comments: false } })],
73
+ },
74
+ { entryFileNames: retainMinSuffix(pkg.main, false), format: 'cjs', exports: 'named' },
75
+ {
76
+ entryFileNames: retainMinSuffix(pkg.main, true),
77
+ format: 'cjs',
78
+ exports: 'named',
79
+ plugins: [terser({ format: { comments: false } })],
80
+ },
81
+ { entryFileNames: retainMinSuffix(pkg.unpkg, false), format: 'umd', name: 'JSONForm', globals },
82
+ {
83
+ entryFileNames: retainMinSuffix(pkg.unpkg, true),
84
+ format: 'umd',
85
+ name: 'JSONForm',
86
+ globals,
87
+ plugins: [terser({ format: { comments: false } })],
88
+ },
89
+ ],
90
+ },
91
+ },
92
+ } as UserConfig;
93
+ });