@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,32 @@
1
+ import { CoreOption, getProvideValue } from '@xiaohaih/json-form-core';
2
+ import { Form as VanForm } from 'vant';
3
+ import { ComponentExposed } from 'vue-component-type-helpers';
4
+ import type * as JSONFormTs from './interface';
5
+ /** 对对象类型的泛型进行解析 - 推断出 query 和 optionsQuery */
6
+ type AssistOption<T extends Record<string, any>, O extends Partial<Record<keyof T, any>>> = {
7
+ [K in keyof T]?: JSONFormTs.JSONFormOption<T[K], T & TypeAll, O[K], O & TypeAll> | FalsyType;
8
+ };
9
+ /** 对数组类型的泛型进行解析 - 推断出 query 和 optionsQuery */
10
+ type AssistOptionArr<T extends Record<string, any>, O extends Record<keyof T, any>> = JSONFormTs.JSONFormOption<keyof T, CoreOption.Merge<T> & TypeAll, O[keyof O], CoreOption.Merge<Required<O>> & TypeAll>;
11
+ /** 假值类型 */
12
+ type FalsyType = number | boolean | string | null | undefined;
13
+ /** 允许调用任意字段 */
14
+ type TypeAll = Record<string | symbol | number, any>;
15
+ /**
16
+ * 定义配置项
17
+ * 未补充泛型声明时, 不建议通过函数返回对象形式的配置项(声明会报错)
18
+ */
19
+ export declare function defineOption<T extends Record<string, any>, O extends Partial<Record<keyof T, any>> = Partial<Record<keyof T, any>>>(config: (AssistOptionArr<T, O> | FalsyType)[]): AssistOptionArr<T, O>[];
20
+ export declare function defineOption<T extends Record<string, any>, O extends Partial<Record<keyof T, any>> = Partial<Record<keyof T, any>>>(config: (opt: DefineOptionParams<T, O>) => (AssistOptionArr<T, O> | FalsyType)[]): AssistOptionArr<T, O>[];
21
+ export declare function defineOption<T extends Record<string, any>, O extends Partial<Record<keyof T, any>> = Partial<Record<keyof T, any>>>(config: AssistOption<T, O>): AssistOption<T, O>;
22
+ export declare function defineOption<T extends Record<string, any>, O extends Partial<Record<keyof T, any>> = Partial<Record<keyof T, any>>>(config: (opt: DefineOptionParams<T, O>) => AssistOption<T, O>): AssistOption<T, O>;
23
+ /** defineOption 为函数时所携带的参数 */
24
+ export interface DefineOptionParams<Query extends Record<string, any>, Options extends Record<string, any>> {
25
+ /** 表单 model 对象 */
26
+ query: Query;
27
+ /** 表单封装的一些参数 */
28
+ wrapper: Pick<NonNullable<ReturnType<typeof getProvideValue<Query, Options>>>, 'disabled' | 'readonly' | 'options' | 'reset'> | undefined;
29
+ /** 表单实例 */
30
+ formRef: ComponentExposed<typeof VanForm> | undefined;
31
+ }
32
+ export {};
@@ -0,0 +1,5 @@
1
+ export * from '../components/index';
2
+ export * from './assist';
3
+ export * as JSONFormTs from './interface';
4
+ export * from './version';
5
+ export { version as coreVersion, provideKey, type ProvideValue } from '@xiaohaih/json-form-core';
@@ -0,0 +1,129 @@
1
+ import { CoreOption, GetOptions, getProvideValue, usePlain } from '@xiaohaih/json-form-core';
2
+ import { CellGroupProps as VanCellGroupProps, Form as VanForm } from 'vant';
3
+ import { Ref } from 'vue';
4
+ import { ComponentExposed } from 'vue-component-type-helpers';
5
+ import { AreaProps as PureAreaProps, CascaderProps as PureCascaderProps, CheckboxGroupProps as PureCheckboxGroupProps, CheckboxProps as PureCheckboxProps, CustomRenderProps as PureCustomRenderProps, DatePickerProps as PureDatePickerProps, DateTimePickerGroupProps as PureDateTimePickerGroupProps, DatetimePickerProps as PureDatetimePickerProps, DynamicGroupProps as PureDynamicGroupProps, GroupProps as PureGroupProps, InputProps as PureInputProps, NumberKeyboardProps as PureNumberKeyboardProps, PasswordInputProps as PurePasswordInputProps, PickerProps as PurePickerProps, RadioGroupProps as PureRadioGroupProps, RadioProps as PureRadioProps, RateProps as PureRateProps, SignatureProps as PureSignatureProps, SliderProps as PureSliderProps, StepperProps as PureStepperProps, SwitchProps as PureSwitchProps, TimePickerProps as PureTimePickerProps, TreeSelectProps as PureTreeSelectProps, UploadProps as PureUploadProps } from '../components/index';
6
+ import { ComponentType } from '../components/share';
7
+ type BuiltInField<T = ''> = CoreOption.BuiltInField | keyof RewriteOption<any, any, any, any> | T;
8
+ /** 重写下列选项(函数内导出的属性无法被推断出来) */
9
+ interface RewriteOption<Field, Query extends Record<string, any>, Option, OptionQuery extends Record<string, any>> {
10
+ /** 提交的字段 */
11
+ field?: Field;
12
+ /** 提交的字段集(多选时, 每个下标对应的字段可能不一样)) */
13
+ fields?: Field[];
14
+ /** 数据源 */
15
+ options?: Option;
16
+ /** 获取数据源的方法 */
17
+ getOptions?: GetOptions<Query, OptionQuery>;
18
+ }
19
+ /** 条件声明集合 */
20
+ export type JSONFormOption<Field, Query extends Record<string, any>, Option, OptionQuery extends Record<string, any>> = AreaProps<Field, Query, Option, OptionQuery> | CascaderProps<Field, Query, Option, OptionQuery> | CheckboxGroupProps<Field, Query, Option, OptionQuery> | CheckboxProps<Field, Query, Option, OptionQuery> | CustomRenderProps<Field, Query, Option, OptionQuery> | DatePickerProps<Field, Query, Option, OptionQuery> | DateTimePickerGroupProps<Field, Query, Option, OptionQuery> | DatetimePickerProps<Field, Query, Option, OptionQuery> | DynamicGroupProps<Field, Query, Option, OptionQuery> | GroupProps<Field, Query, Option, OptionQuery> | CellGroupProps<Field, Query, Option, OptionQuery> | InputProps<Field, Query, Option, OptionQuery> | NumberKeyboardProps<Field, Query, Option, OptionQuery> | PasswordInputProps<Field, Query, Option, OptionQuery> | PickerProps<Field, Query, Option, OptionQuery> | RadioGroupProps<Field, Query, Option, OptionQuery> | RadioProps<Field, Query, Option, OptionQuery> | RateProps<Field, Query, Option, OptionQuery> | SignatureProps<Field, Query, Option, OptionQuery> | SliderProps<Field, Query, Option, OptionQuery> | StepperProps<Field, Query, Option, OptionQuery> | SwitchProps<Field, Query, Option, OptionQuery> | TimePickerProps<Field, Query, Option, OptionQuery> | TreeSelectProps<Field, Query, Option, OptionQuery> | UploadProps<Field, Query, Option, OptionQuery>;
21
+ export interface AreaProps<Field, Query extends Record<string, any>, Option, OptionQuery extends Record<string, any> = Record<string, any>> extends Omit<PureAreaProps<Query, OptionQuery>, BuiltInField>, RewriteOption<Field, Query, Option, OptionQuery> {
22
+ t: 'area';
23
+ }
24
+ export interface CascaderProps<Field, Query extends Record<string, any>, Option, OptionQuery extends Record<string, any> = Record<string, any>> extends Omit<PureCascaderProps<Query, OptionQuery>, BuiltInField>, RewriteOption<Field, Query, Option, OptionQuery> {
25
+ t: 'cascader';
26
+ }
27
+ export interface CheckboxGroupProps<Field, Query extends Record<string, any>, Option, OptionQuery extends Record<string, any> = Record<string, any>> extends Omit<PureCheckboxGroupProps<Query, OptionQuery>, BuiltInField>, RewriteOption<Field, Query, Option, OptionQuery> {
28
+ t: 'checkbox-group';
29
+ }
30
+ export interface CheckboxProps<Field, Query extends Record<string, any>, Option, OptionQuery extends Record<string, any> = Record<string, any>> extends Omit<PureCheckboxProps<Query, OptionQuery>, BuiltInField>, RewriteOption<Field, Query, Option, OptionQuery> {
31
+ t: 'checkbox';
32
+ }
33
+ export interface CustomRenderProps<Field, Query extends Record<string, any>, Option, OptionQuery extends Record<string, any> = Record<string, any>> extends Omit<PureCustomRenderProps<Query, OptionQuery>, BuiltInField>, RewriteOption<Field, Query, Option, OptionQuery> {
34
+ t: 'custom-render';
35
+ }
36
+ export interface DatePickerProps<Field, Query extends Record<string, any>, Option, OptionQuery extends Record<string, any> = Record<string, any>> extends Omit<PureDatePickerProps<Query, OptionQuery>, BuiltInField>, RewriteOption<Field, Query, Option, OptionQuery> {
37
+ t: 'date-picker';
38
+ }
39
+ export interface DateTimePickerGroupProps<Field, Query extends Record<string, any>, Option, OptionQuery extends Record<string, any> = Record<string, any>> extends Omit<PureDateTimePickerGroupProps<Query, OptionQuery>, BuiltInField>, RewriteOption<Field, Query, Option, OptionQuery> {
40
+ t: 'date-time-picker-group';
41
+ }
42
+ export interface DatetimePickerProps<Field, Query extends Record<string, any>, Option, OptionQuery extends Record<string, any> = Record<string, any>> extends Omit<PureDatetimePickerProps<Query, OptionQuery>, BuiltInField>, RewriteOption<Field, Query, Option, OptionQuery> {
43
+ /**
44
+ * @deprecated vant@3.x版本使用, vant@4.x版本使用 date-time-picker-group
45
+ */
46
+ t: 'datetime-picker';
47
+ }
48
+ export interface DynamicGroupProps<Field, Query extends Record<string, any>, Option, OptionQuery extends Record<string, any> = Record<string, any>> extends Omit<PureDynamicGroupProps<Query, OptionQuery>, BuiltInField | 'config'>, RewriteOption<Field, Query, Option, OptionQuery> {
49
+ t: 'dynamic-group';
50
+ /**
51
+ * 渲染的子条件(重写该属性以补充声明)
52
+ * 动态表单不是根级属性, 不应该暴露出来, 遂用 string 替代
53
+ */
54
+ config?: MaybeFunction<[{
55
+ item: Record<string, any>;
56
+ index: number;
57
+ checked: Record<string, any>[];
58
+ query: Query;
59
+ plain: ReturnType<typeof usePlain>;
60
+ }], JSONFormOption<string, Query, Option, OptionQuery>[] | Record<keyof Query, JSONFormOption<string, Query, Option, OptionQuery>>>;
61
+ }
62
+ export interface GroupProps<Field, Query extends Record<string, any>, Option, OptionQuery extends Record<string, any> = Record<string, any>> extends Omit<PureGroupProps<Query, OptionQuery>, BuiltInField | 'config' | 'getFormRef'>, RewriteOption<Field, Query, Option, OptionQuery> {
63
+ t: 'group';
64
+ /** 渲染的子条件(重写该属性以补充声明) */
65
+ config?: MaybeFunction<[{
66
+ query: Query;
67
+ wrapper?: ReturnType<typeof getProvideValue<Query, OptionQuery, Ref<ComponentExposed<typeof VanForm>>>>;
68
+ }], JSONFormOption<Field, Query, Option, OptionQuery>[] | Record<keyof Query, JSONFormOption<Field, Query, Option, OptionQuery>>>;
69
+ }
70
+ export interface CellGroupProps<Field, Query extends Record<string, any>, Option, OptionQuery extends Record<string, any> = Record<string, any>> extends Omit<PureGroupProps<Query, OptionQuery>, BuiltInField | 'config' | 'getFormRef' | 'slots' | 'tagSlots'>, RewriteOption<Field, Query, Option, OptionQuery>, Partial<VanCellGroupProps> {
71
+ t: 'cell-group';
72
+ /** 重写插槽声明 */
73
+ slots?: PureGroupProps<Query, OptionQuery>['slots'] & {
74
+ /** 自定义分组标题 */
75
+ title?: ComponentType<{
76
+ query: Query;
77
+ wrapper?: ReturnType<typeof getProvideValue<Query, OptionQuery, Ref<ComponentExposed<typeof VanForm>>>>;
78
+ }>;
79
+ };
80
+ /** 渲染的子条件(重写该属性以补充声明) */
81
+ config?: MaybeFunction<[{
82
+ query: Query;
83
+ wrapper?: ReturnType<typeof getProvideValue<Query, OptionQuery, Ref<ComponentExposed<typeof VanForm>>>>;
84
+ }], JSONFormOption<Field, Query, Option, OptionQuery>[] | Record<keyof Query, JSONFormOption<Field, Query, Option, OptionQuery>>>;
85
+ }
86
+ export interface InputProps<Field, Query extends Record<string, any>, Option, OptionQuery extends Record<string, any> = Record<string, any>> extends Omit<PureInputProps<Query, OptionQuery>, BuiltInField>, RewriteOption<Field, Query, Option, OptionQuery> {
87
+ t: 'input';
88
+ }
89
+ export interface NumberKeyboardProps<Field, Query extends Record<string, any>, Option, OptionQuery extends Record<string, any> = Record<string, any>> extends Omit<PureNumberKeyboardProps<Query, OptionQuery>, BuiltInField>, RewriteOption<Field, Query, Option, OptionQuery> {
90
+ t: 'number-keyboard';
91
+ }
92
+ export interface PasswordInputProps<Field, Query extends Record<string, any>, Option, OptionQuery extends Record<string, any> = Record<string, any>> extends Omit<PurePasswordInputProps<Query, OptionQuery>, BuiltInField>, RewriteOption<Field, Query, Option, OptionQuery> {
93
+ t: 'password-input';
94
+ }
95
+ export interface PickerProps<Field, Query extends Record<string, any>, Option, OptionQuery extends Record<string, any> = Record<string, any>> extends Omit<PurePickerProps<Query, OptionQuery>, BuiltInField>, RewriteOption<Field, Query, Option, OptionQuery> {
96
+ t: 'picker' | 'select';
97
+ }
98
+ export interface RadioGroupProps<Field, Query extends Record<string, any>, Option, OptionQuery extends Record<string, any> = Record<string, any>> extends Omit<PureRadioGroupProps<Query, OptionQuery>, BuiltInField>, RewriteOption<Field, Query, Option, OptionQuery> {
99
+ t: 'radio-group';
100
+ }
101
+ export interface RadioProps<Field, Query extends Record<string, any>, Option, OptionQuery extends Record<string, any> = Record<string, any>> extends Omit<PureRadioProps<Query, OptionQuery>, BuiltInField>, RewriteOption<Field, Query, Option, OptionQuery> {
102
+ t: 'radio';
103
+ }
104
+ export interface RateProps<Field, Query extends Record<string, any>, Option, OptionQuery extends Record<string, any> = Record<string, any>> extends Omit<PureRateProps<Query, OptionQuery>, BuiltInField>, RewriteOption<Field, Query, Option, OptionQuery> {
105
+ t: 'rate';
106
+ }
107
+ export interface SignatureProps<Field, Query extends Record<string, any>, Option, OptionQuery extends Record<string, any> = Record<string, any>> extends Omit<PureSignatureProps<Query, OptionQuery>, BuiltInField>, RewriteOption<Field, Query, Option, OptionQuery> {
108
+ t: 'signature';
109
+ }
110
+ export interface SliderProps<Field, Query extends Record<string, any>, Option, OptionQuery extends Record<string, any> = Record<string, any>> extends Omit<PureSliderProps<Query, OptionQuery>, BuiltInField>, RewriteOption<Field, Query, Option, OptionQuery> {
111
+ t: 'slider';
112
+ }
113
+ export interface StepperProps<Field, Query extends Record<string, any>, Option, OptionQuery extends Record<string, any> = Record<string, any>> extends Omit<PureStepperProps<Query, OptionQuery>, BuiltInField>, RewriteOption<Field, Query, Option, OptionQuery> {
114
+ t: 'stepper';
115
+ }
116
+ export interface SwitchProps<Field, Query extends Record<string, any>, Option, OptionQuery extends Record<string, any> = Record<string, any>> extends Omit<PureSwitchProps<Query, OptionQuery>, BuiltInField>, RewriteOption<Field, Query, Option, OptionQuery> {
117
+ t: 'switch';
118
+ }
119
+ export interface TimePickerProps<Field, Query extends Record<string, any>, Option, OptionQuery extends Record<string, any> = Record<string, any>> extends Omit<PureTimePickerProps<Query, OptionQuery>, BuiltInField>, RewriteOption<Field, Query, Option, OptionQuery> {
120
+ t: 'time-picker';
121
+ }
122
+ export interface TreeSelectProps<Field, Query extends Record<string, any>, Option, OptionQuery extends Record<string, any> = Record<string, any>> extends Omit<PureTreeSelectProps<Query, OptionQuery>, BuiltInField>, RewriteOption<Field, Query, Option, OptionQuery> {
123
+ t: 'tree-select';
124
+ }
125
+ export interface UploadProps<Field, Query extends Record<string, any>, Option, OptionQuery extends Record<string, any> = Record<string, any>> extends Omit<PureUploadProps<Query, OptionQuery>, BuiltInField>, RewriteOption<Field, Query, Option, OptionQuery> {
126
+ t: 'upload';
127
+ }
128
+ export type MaybeFunction<TParams extends any[], TResult> = TResult | ((...args: TParams) => TResult);
129
+ export {};
@@ -0,0 +1,9 @@
1
+ /**
2
+ * 选取对象中指定属性
3
+ */
4
+ export declare function pick<T extends object, TKeys extends keyof T>(obj: T, keys: TKeys[]): Pick<T, TKeys>;
5
+ export declare function pick<T extends object, TKeys extends string>(obj: T, keys: TKeys[]): T;
6
+ /**
7
+ * 数组扁平化
8
+ */
9
+ export declare function flat<T>(lists: readonly T[][]): T[];
@@ -0,0 +1,2 @@
1
+ /** 版本号 */
2
+ export declare const version = "0.0.1";
@@ -0,0 +1,99 @@
1
+ import { readdirSync } from 'node:fs';
2
+ import { dirname, join, resolve } from 'node:path';
3
+ import { fileURLToPath, URL } from 'node:url';
4
+ import {
5
+ presetAttributify,
6
+ presetIcons,
7
+ presetUno,
8
+ transformerDirectives,
9
+ } from 'unocss';
10
+ import UnoCSS from 'unocss/vite';
11
+ import { createContentLoader, defineConfig } from 'vitepress';
12
+ import type { DefaultTheme } from 'vitepress/theme';
13
+
14
+ const __dirname = dirname(fileURLToPath(import.meta.url));
15
+
16
+ export default async () => {
17
+ const components = readdirSync(resolve(__dirname, '../options/components'))
18
+ .map((v) => {
19
+ if (v.slice(-3) !== '.md') return null;
20
+ return { text: v.slice(0, -3), link: `/options/components/${v.slice(0, -3)}` };
21
+ })
22
+ .filter(Boolean) as DefaultTheme.SidebarItem[];
23
+
24
+ // https://vitepress.dev/reference/site-config
25
+ return defineConfig({
26
+ title: 'json-form-plus',
27
+ description: '基于 json 驱动的表单',
28
+ lang: 'zh-CN',
29
+ base: '/json-form/docs-plus/',
30
+ head: [['meta', { name: 'algolia-site-verification', content: '61B7703469FD262F' }]],
31
+ themeConfig: {
32
+ search: {
33
+ provider: 'local',
34
+ // provider: 'algolia',
35
+ // options: {
36
+ // appId: '7I5QJDRVQQ',
37
+ // apiKey: '22b659ca38c3f820e963499fc03547b4',
38
+ // indexName: 'json-form-plus',
39
+ // },
40
+ },
41
+ // https://vitepress.dev/reference/default-theme-config
42
+ nav: [
43
+ { text: '首页', link: '/' },
44
+ { text: '配置项', link: '/options/shares/share-props' },
45
+ { text: '友情链接', link: '/friendly-links' },
46
+ { text: '示例', link: '/examples/index' },
47
+ { text: '更新日志', link: 'https://github.com/xiaohaiH/json-form/blob/master/packages/element-plus/CHANGELOG.md' },
48
+ ],
49
+ sidebar: {
50
+ '/options': [
51
+ {
52
+ text: '开始',
53
+ items: [
54
+ { text: '简介', link: '/options/guide/introduction' },
55
+ { text: '快速上手', link: '/options/guide/quick-start' },
56
+ { text: 'HForm', link: '/options/guide/form' },
57
+ ],
58
+ },
59
+ {
60
+ text: '共享属性',
61
+ items: [
62
+ { text: '共享 props', link: '/options/shares/share-props' },
63
+ { text: '共享 slots', link: '/options/shares/share-slots' },
64
+ ],
65
+ },
66
+ {
67
+ text: '配置项',
68
+ items: components,
69
+ },
70
+ ],
71
+ // '/friendly-links': [],
72
+ },
73
+ socialLinks: [
74
+ { icon: 'github', link: 'https://github.com/xiaohaiH/json-form/tree/master/packages/element-plus' },
75
+ ],
76
+ },
77
+ // outDir: './dist',
78
+ vite: {
79
+ server: { port: 2012 },
80
+ plugins: [
81
+ // eslint-disable-next-line ts/ban-ts-comment
82
+ // @ts-ignore 忽视 ts 报错
83
+ UnoCSS({
84
+ presets: [
85
+ presetUno(),
86
+ presetIcons({
87
+ extraProperties: {
88
+ 'display': 'inline-block',
89
+ 'vertical-align': 'middle',
90
+ },
91
+ }),
92
+ presetAttributify(),
93
+ ],
94
+ transformers: [transformerDirectives()],
95
+ }),
96
+ ],
97
+ },
98
+ });
99
+ };
@@ -0,0 +1,5 @@
1
+ import DefaultTheme from 'vitepress/theme';
2
+ // @ts-expect-error 忽视 unocss 模块找不到的错误
3
+ import 'virtual:uno.css';
4
+
5
+ export default DefaultTheme;
package/docs/README.md ADDED
@@ -0,0 +1,20 @@
1
+ # Vant 组件文档
2
+
3
+ 这是 Vant 组件的 JSON Form 封装库的完整文档.
4
+
5
+ ## 文档结构
6
+
7
+ ```
8
+ docs/
9
+ ├── README.md # 本文档
10
+ ├── index.md # 文档首页和快速开始
11
+ ├── options/*.md # 配置项相关的文档
12
+ ├── vue-components # 文档中使用的 vue 组件
13
+ └── friendly-links.md # 友情链接
14
+ ```
15
+
16
+ ## 相关链接
17
+
18
+ - [GitHub 仓库](https://github.com/xiaohaih/json-form)
19
+ - [Element Plus 官方文档](https://element-plus.org/)
20
+ - [核心库文档](https://github.com/xiaohaiH/json-form/tree/master/packages/core)
package/docs/index.md ADDED
@@ -0,0 +1,25 @@
1
+ ---
2
+ # https://vitepress.dev/reference/default-theme-home-page
3
+ layout: home
4
+
5
+ hero:
6
+ name: "json-form-vant"
7
+ text: "基于 json 驱动的表单"
8
+ tagline:
9
+ actions:
10
+ - theme: brand
11
+ text: 快速上手
12
+ link: /options/guide/introduction
13
+
14
+ - theme: alt
15
+ text: 查看配置项
16
+ link: /options/shares/share-props
17
+
18
+ # features:
19
+ # - title: Feature A
20
+ # details: Lorem ipsum dolor sit amet, consectetur adipiscing elit
21
+ # - title: Feature B
22
+ # details: Lorem ipsum dolor sit amet, consectetur adipiscing elit
23
+ # - title: Feature C
24
+ # details: Lorem ipsum dolor sit amet, consectetur adipiscing elit
25
+ ---
package/env.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ /// <reference types="vite/client" />
2
+
3
+ interface ImportMetaEnv {
4
+ }
5
+
6
+ interface ImportMeta {
7
+ readonly env: ImportMetaEnv;
8
+ }
package/package.json ADDED
@@ -0,0 +1,71 @@
1
+ {
2
+ "name": "@xiaohaih/json-form-vant",
3
+ "type": "module",
4
+ "version": "0.0.1",
5
+ "description": "基于vant实现, 通过JSON配置表单组件(表单项间可相互依赖)",
6
+ "author": "xiaohai",
7
+ "license": "MIT",
8
+ "homepage": "https://xiaohaih.github.io/json-form/example-vant-vue3/index.html",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/xiaohaiH/json-form/tree/master/packages/vant"
12
+ },
13
+ "keywords": [
14
+ "vue3",
15
+ "vant",
16
+ "JSON Form"
17
+ ],
18
+ "exports": {
19
+ ".": {
20
+ "browser": "./src/index.ts",
21
+ "types": "./src/index.ts",
22
+ "import": "./src/index.ts",
23
+ "require": "./dist/index.cjs.js"
24
+ },
25
+ "./*": "./*"
26
+ },
27
+ "main": "dist/index.cjs.js",
28
+ "module": "dist/index.esm.js",
29
+ "unpkg": "dist/index.umd.js",
30
+ "jsdelivr": "dist/index.umd.js",
31
+ "types": "src/index.ts",
32
+ "peerDependencies": {
33
+ "vant": "^3.0.0",
34
+ "vue": "^3.0.0"
35
+ },
36
+ "dependencies": {
37
+ "@xiaohaih/json-form-core": "0.2.8"
38
+ },
39
+ "devDependencies": {
40
+ "@docsearch/js": "^4.6.3",
41
+ "@popperjs/core": "^2.11.8",
42
+ "@rollup/plugin-terser": "^1.0.0",
43
+ "@vitejs/plugin-vue": "^6.0.7",
44
+ "@vitejs/plugin-vue-jsx": "^5.1.5",
45
+ "@vue/language-core": "^3.3.1",
46
+ "tsdown": "^0.22.0",
47
+ "typescript": "~6.0.3",
48
+ "unocss": "^66.5.0",
49
+ "unplugin-dts": "^1.0.1",
50
+ "unplugin-vue": "^7.2.0",
51
+ "vant": "^4.9.24",
52
+ "vite": "^8.0.13",
53
+ "vitepress": "2.0.0-alpha.12",
54
+ "vue": "^3.5.13",
55
+ "vue-component-type-helpers": "^3.3.1",
56
+ "vue-tsc": "^3.3.1"
57
+ },
58
+ "publishConfig": {
59
+ "registry": "https://registry.npmjs.org/",
60
+ "jsdelivr": "dist/index.umd.js"
61
+ },
62
+ "scripts": {
63
+ "build": "node ./scripts/generate-version.mjs && vite build",
64
+ "build:dts": "tsdown",
65
+ "postinstall": "node -e \"try{require('./scripts/postinstall.cjs')}catch(e){}\"",
66
+ "test": "echo \"Error: no test specified\" && exit 1",
67
+ "docs:dev": "vitepress dev docs",
68
+ "docs:build": "vitepress build docs",
69
+ "docs:preview": "vitepress preview docs"
70
+ }
71
+ }
@@ -0,0 +1,26 @@
1
+ import { readFileSync, writeFileSync } from 'node:fs';
2
+ import { dirname, resolve } from 'node:path';
3
+ import { fileURLToPath } from 'node:url';
4
+
5
+ /** 获取当前文件的目录名 */
6
+ const __filename = fileURLToPath(import.meta.url);
7
+ const __dirname = dirname(__filename);
8
+
9
+ /** 获取 package.json 的路径 */
10
+ const packageJsonPath = resolve(__dirname, '../package.json');
11
+
12
+ /** 读取 package.json 文件内容 */
13
+ const packageJson = readFileSync(packageJsonPath, 'utf8');
14
+
15
+ /** 解析 JSON 数据 */
16
+ const packageData = JSON.parse(packageJson);
17
+
18
+ /** 获取版本号 */
19
+ const version = packageData.version;
20
+
21
+ /** 生成版本号文件 */
22
+ const versionFilePath = resolve(__dirname, '../src/version.ts');
23
+ const versionFileContent = `/** 版本号 */\nexport const version = '${version}';\n`;
24
+
25
+ /** 写入版本号文件 */
26
+ writeFileSync(versionFilePath, versionFileContent);
@@ -0,0 +1,13 @@
1
+ const fs = require('node:fs');
2
+ const path = require('node:path');
3
+
4
+ const dir = path.resolve(__dirname, '..');
5
+
6
+ const { loadModule, reexport, writeContent } = require('./utils.cjs');
7
+
8
+ const Vant = loadModule('vant');
9
+ const isDebug = false;
10
+ if (Vant && (isDebug || dir.includes('node_modules'))) {
11
+ const newContent = reexport(fs.readFileSync(path.join(dir, './components/component-definition/definition.ts'), 'utf-8'), Vant);
12
+ writeContent(path.join(dir, './components/component-definition/components.ts'), newContent);
13
+ }
@@ -0,0 +1,67 @@
1
+ const fs = require('node:fs');
2
+ const path = require('node:path');
3
+
4
+ const dir = path.resolve(__dirname, '..', 'lib');
5
+
6
+ function loadModule(name) {
7
+ try {
8
+ return require(name);
9
+ }
10
+ catch (e) {
11
+ return undefined;
12
+ }
13
+ }
14
+
15
+ function writeContent(dest, content) {
16
+ // unlink for pnpm, #92
17
+ try {
18
+ fs.unlinkSync(dest);
19
+ }
20
+ catch (error) { }
21
+ fs.writeFileSync(dest, content, 'utf-8');
22
+ }
23
+
24
+ const reg = /(export\s+\*\s+from\s+'\.\.\/)([\w|\-]+)(\/index';)/;
25
+ const wordReg = /-\w/g;
26
+ /** 不经过 vant 的组件 */
27
+ const whiteList = ['custom-render'];
28
+ /** 引用了多个 vant 的组件 */
29
+ const multipleList = {
30
+ 'date-time-picker-group': ['date-picker', 'time-picker', 'picker-group'],
31
+ 'input': ['field'],
32
+ 'upload': ['Uploader'],
33
+ };
34
+ function reexport(content, Ui) {
35
+ const arr = content.split('\n');
36
+ const newContent = {
37
+ imp: [],
38
+ exp: [],
39
+ };
40
+ arr.forEach((item) => {
41
+ const result = item.match(reg);
42
+ if (!result) return;
43
+ const [all, $1, $2, $3] = result;
44
+ if (whiteList.includes($2) || hasComponent(Ui, $2)) return newContent.imp.push(all);
45
+ newContent.exp.push([
46
+ `export const ${camelize2(`h-${$2}`)} = { render: () => null };`,
47
+ `export interface ${camelize2(`${$2}-props`)}<A, B> {}`,
48
+ ].join('\n'));
49
+ });
50
+
51
+ return `${[newContent.imp.join('\n'), newContent.exp.join('\n')].filter(Boolean).join('\n\n')}\n`;
52
+ }
53
+
54
+ function hasComponent(Ui, name) {
55
+ if (multipleList[name]) return multipleList[name].every((o) => camelize2(o) in Ui);
56
+ return camelize2(name) in Ui;
57
+ }
58
+ function camelize(name) {
59
+ return name.replace(wordReg, ($1) => $1.slice(1).toUpperCase());
60
+ }
61
+ function camelize2(name) {
62
+ return camelize(`-${name}`);
63
+ }
64
+
65
+ module.exports.loadModule = loadModule;
66
+ module.exports.reexport = reexport;
67
+ module.exports.writeContent = writeContent;
package/src/assist.ts ADDED
@@ -0,0 +1,40 @@
1
+ import type { CoreOption, getProvideValue } from '@xiaohaih/json-form-core';
2
+ import type { Form as VanForm } from 'vant';
3
+ import type { ExtractPublicPropTypes, PropType, Ref } from 'vue';
4
+ import { ref } from 'vue';
5
+ import type { ComponentExposed } from 'vue-component-type-helpers';
6
+ import type * as JSONFormTs from './interface';
7
+
8
+ /** 对对象类型的泛型进行解析 - 推断出 query 和 optionsQuery */
9
+ type AssistOption<T extends Record<string, any>, O extends Partial<Record<keyof T, any>>> = {
10
+ /** 添加问号是允许泛型声明的字段可以多过配置项内的字段 */
11
+ [K in keyof T]?: JSONFormTs.JSONFormOption<T[K], T & TypeAll, O[K], O & TypeAll> | FalsyType;
12
+ };
13
+ /** 对数组类型的泛型进行解析 - 推断出 query 和 optionsQuery */
14
+ type AssistOptionArr<T extends Record<string, any>, O extends Record<keyof T, any>> = JSONFormTs.JSONFormOption<keyof T, CoreOption.Merge<T> & TypeAll, O[keyof O], CoreOption.Merge<Required<O>> & TypeAll>;
15
+ /** 假值类型 */
16
+ type FalsyType = number | boolean | string | null | undefined;
17
+ /** 允许调用任意字段 */
18
+ type TypeAll = Record<string | symbol | number, any>;
19
+
20
+ /**
21
+ * 定义配置项
22
+ * 未补充泛型声明时, 不建议通过函数返回对象形式的配置项(声明会报错)
23
+ */
24
+ export function defineOption<T extends Record<string, any>, O extends Partial<Record<keyof T, any>> = Partial<Record<keyof T, any>>>(config: (AssistOptionArr<T, O> | FalsyType)[]): AssistOptionArr<T, O>[];
25
+ export function defineOption<T extends Record<string, any>, O extends Partial<Record<keyof T, any>> = Partial<Record<keyof T, any>>>(config: (opt: DefineOptionParams<T, O>) => (AssistOptionArr<T, O> | FalsyType)[]): AssistOptionArr<T, O>[];
26
+ export function defineOption<T extends Record<string, any>, O extends Partial<Record<keyof T, any>> = Partial<Record<keyof T, any>>>(config: AssistOption<T, O>): AssistOption<T, O>;
27
+ export function defineOption<T extends Record<string, any>, O extends Partial<Record<keyof T, any>> = Partial<Record<keyof T, any>>>(config: (opt: DefineOptionParams<T, O>) => AssistOption<T, O>): AssistOption<T, O>;
28
+ export function defineOption(config: any) {
29
+ return config;
30
+ }
31
+
32
+ /** defineOption 为函数时所携带的参数 */
33
+ export interface DefineOptionParams<Query extends Record<string, any>, Options extends Record<string, any>> {
34
+ /** 表单 model 对象 */
35
+ query: Query;
36
+ /** 表单封装的一些参数 */
37
+ wrapper: Pick<NonNullable<ReturnType<typeof getProvideValue<Query, Options>>>, 'disabled' | 'readonly' | 'options' | 'reset'> | undefined;
38
+ /** 表单实例 */
39
+ formRef: ComponentExposed<typeof VanForm> | undefined;
40
+ }
package/src/index.ts ADDED
@@ -0,0 +1,5 @@
1
+ export * from '../components/index';
2
+ export * from './assist';
3
+ export * as JSONFormTs from './interface';
4
+ export * from './version';
5
+ export { version as coreVersion, provideKey, type ProvideValue } from '@xiaohaih/json-form-core';