@dazhicheng/ui 1.5.33 → 1.5.35

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 (189) hide show
  1. package/dist/components/tt-area/TtArea.vue.d.ts +2 -0
  2. package/dist/components/tt-area/index.d.ts +1 -0
  3. package/dist/components/tt-button/components/AddButton.vue.d.ts +2 -0
  4. package/dist/components/tt-button/index.d.ts +1740 -0
  5. package/dist/components/tt-button/index.vue.d.ts +1004 -0
  6. package/dist/components/tt-checkbox/index.d.ts +36 -0
  7. package/dist/components/tt-checkbox/index.vue.d.ts +28 -0
  8. package/dist/components/tt-checkbox/type.d.ts +9 -0
  9. package/dist/components/tt-drawer/index.d.ts +3703 -0
  10. package/dist/components/tt-drawer/src/RenderDrawer.vue.d.ts +2121 -0
  11. package/dist/components/tt-drawer/src/components/DrawerFooter.vue.d.ts +94 -0
  12. package/dist/components/tt-drawer/src/components/DrawerHeader.vue.d.ts +27 -0
  13. package/dist/components/tt-drawer/src/hooks/useDrawerRender.d.ts +10 -0
  14. package/dist/components/tt-drawer/src/hooks/useResizable.d.ts +9 -0
  15. package/dist/components/tt-drawer/src/index.d.ts +10 -0
  16. package/dist/components/tt-drawer/src/props.d.ts +99 -0
  17. package/dist/components/tt-drawer/src/typing.d.ts +154 -0
  18. package/dist/components/tt-drawer/src/utils/drawer-api.d.ts +87 -0
  19. package/dist/components/tt-empty/index.d.ts +18 -0
  20. package/dist/components/tt-form/index.d.ts +15 -0
  21. package/dist/components/tt-form/src/components/ExpandableArrow.vue.d.ts +33 -0
  22. package/dist/components/tt-form/src/components/FormActions.vue.d.ts +34 -0
  23. package/dist/components/tt-form/src/components/Slot.d.ts +7 -0
  24. package/dist/components/tt-form/src/config.d.ts +6 -0
  25. package/dist/components/tt-form/src/form/FormControl.vue.d.ts +19 -0
  26. package/dist/components/tt-form/src/form/FormDescription.vue.d.ts +23 -0
  27. package/dist/components/tt-form/src/form/FormItem.vue.d.ts +23 -0
  28. package/dist/components/tt-form/src/form/FormLabel.vue.d.ts +23 -0
  29. package/dist/components/tt-form/src/form/FormMessage.vue.d.ts +2 -0
  30. package/dist/components/tt-form/src/form/FormMessageToolTip.vue.d.ts +8 -0
  31. package/dist/components/tt-form/src/form/FormWarnMessage.vue.d.ts +25 -0
  32. package/dist/components/tt-form/src/form/RenderContent.vue.d.ts +23 -0
  33. package/dist/components/tt-form/src/form/index.d.ts +10 -0
  34. package/dist/components/tt-form/src/form/injectionKeys.d.ts +2 -0
  35. package/dist/components/tt-form/src/form/useFormField.d.ts +11 -0
  36. package/dist/components/tt-form/src/form-render/FormField.vue.d.ts +28 -0
  37. package/dist/components/tt-form/src/form-render/FormLabel.vue.d.ts +27 -0
  38. package/dist/components/tt-form/src/form-render/context.d.ts +7 -0
  39. package/dist/components/tt-form/src/form-render/dependencies.d.ts +361 -0
  40. package/dist/components/tt-form/src/form-render/expandable.d.ts +9 -0
  41. package/dist/components/tt-form/src/form-render/form.vue.d.ts +41 -0
  42. package/dist/components/tt-form/src/form-render/helper.d.ts +11 -0
  43. package/dist/components/tt-form/src/form-render/index.d.ts +3 -0
  44. package/dist/components/tt-form/src/formApi.d.ts +71 -0
  45. package/dist/components/tt-form/src/group-form/FieldRenderer.d.ts +81 -0
  46. package/dist/components/tt-form/src/group-form/GroupForm.vue.d.ts +49 -0
  47. package/dist/components/tt-form/src/group-form/GroupSection.vue.d.ts +25 -0
  48. package/dist/components/tt-form/src/group-form/LazyFormField.vue.d.ts +13 -0
  49. package/dist/components/tt-form/src/group-form/index.d.ts +3 -0
  50. package/dist/components/tt-form/src/group-form/lazyContext.d.ts +37 -0
  51. package/dist/components/tt-form/src/group-form/types.d.ts +147 -0
  52. package/dist/components/tt-form/src/group-form/useGroupForm.d.ts +5 -0
  53. package/dist/components/tt-form/src/group-form/utils.d.ts +93 -0
  54. package/dist/components/tt-form/src/hooks/useEmitAsProps.d.ts +7 -0
  55. package/dist/components/tt-form/src/hooks/useFormFieldBus.d.ts +14 -0
  56. package/dist/components/tt-form/src/hooks/useForwardPriorityValues.d.ts +14 -0
  57. package/dist/components/tt-form/src/hooks/useForwardProps.d.ts +7 -0
  58. package/dist/components/tt-form/src/hooks/useForwardPropsEmits.d.ts +8 -0
  59. package/dist/components/tt-form/src/index.vue.d.ts +27 -0
  60. package/dist/components/tt-form/src/shared/createContext.d.ts +8 -0
  61. package/dist/components/tt-form/src/shared/global-state.d.ts +17 -0
  62. package/dist/components/tt-form/src/shared/store.d.ts +1 -0
  63. package/dist/components/tt-form/src/shared/zod-defaults.d.ts +54 -0
  64. package/dist/components/tt-form/src/types/common.d.ts +11 -0
  65. package/dist/components/tt-form/src/types/forms.d.ts +280 -0
  66. package/dist/components/tt-form/src/types/index.d.ts +3 -0
  67. package/dist/components/tt-form/src/types/paths.d.ts +142 -0
  68. package/dist/components/tt-form/src/types/shared.d.ts +19 -0
  69. package/dist/components/tt-form/src/types.d.ts +452 -0
  70. package/dist/components/tt-form/src/useForm.d.ts +2 -0
  71. package/dist/components/tt-form/src/useFormContext.d.ts +12 -0
  72. package/dist/components/tt-form-item-error-tooltip/index.d.ts +1549 -0
  73. package/dist/components/tt-form-item-error-tooltip/index.vue.d.ts +784 -0
  74. package/dist/components/tt-icon/components/AddIcon.vue.d.ts +7 -0
  75. package/dist/components/tt-icon/components/SubIcon.vue.d.ts +7 -0
  76. package/dist/components/tt-icon/index.d.ts +124 -0
  77. package/dist/components/tt-icon/index.vue.d.ts +32 -0
  78. package/dist/components/tt-image/index.d.ts +127 -0
  79. package/dist/components/tt-image/src/components/ImageViewer.d.ts +89 -0
  80. package/dist/components/tt-image/tt-image.d.ts +126 -0
  81. package/dist/components/tt-loading/index.d.ts +16 -0
  82. package/dist/components/tt-loading/src/directive.d.ts +9 -0
  83. package/dist/components/tt-loading/src/loading.vue.d.ts +12 -0
  84. package/dist/components/tt-loading/src/service.d.ts +25 -0
  85. package/dist/components/tt-loading/src/type.d.ts +20 -0
  86. package/dist/components/tt-modal/index.d.ts +1809 -0
  87. package/dist/components/tt-modal/src/RenderModal.vue.d.ts +1008 -0
  88. package/dist/components/tt-modal/src/components/ModalFooter.vue.d.ts +210 -0
  89. package/dist/components/tt-modal/src/components/ModalHeader.vue.d.ts +31 -0
  90. package/dist/components/tt-modal/src/components/ModalWrapper.vue.d.ts +224 -0
  91. package/dist/components/tt-modal/src/hooks/useModalRender.d.ts +110 -0
  92. package/dist/components/tt-modal/src/index.d.ts +5 -0
  93. package/dist/components/tt-modal/src/props.d.ts +161 -0
  94. package/dist/components/tt-modal/src/typing.d.ts +188 -0
  95. package/dist/components/tt-modal/src/utils/modal-api.d.ts +97 -0
  96. package/dist/components/tt-modal-form/hooks/useModalFormSlot.d.ts +6 -0
  97. package/dist/components/tt-modal-form/index.d.ts +2 -0
  98. package/dist/components/tt-modal-form/index.vue.d.ts +43 -0
  99. package/dist/components/tt-modal-form/props.d.ts +38 -0
  100. package/dist/components/tt-modal-form/useModalForm.d.ts +6 -0
  101. package/dist/components/tt-nav-anchor/index.d.ts +19 -0
  102. package/dist/components/tt-nav-anchor/src/TtNavAnchor.vue.d.ts +19 -0
  103. package/dist/components/tt-nav-anchor/src/types.d.ts +29 -0
  104. package/dist/components/tt-select/index.d.ts +7 -0
  105. package/dist/components/tt-select/src/Select.vue.d.ts +861 -0
  106. package/dist/components/tt-select/src/components/SelectTable.vue.d.ts +111 -0
  107. package/dist/components/tt-select/src/components/Table.vue.d.ts +250 -0
  108. package/dist/components/tt-select/src/const.d.ts +16 -0
  109. package/dist/components/tt-select/src/hooks/useDataSource.d.ts +115 -0
  110. package/dist/components/tt-select/src/hooks/useGrid.d.ts +32 -0
  111. package/dist/components/tt-select/src/hooks/useKeyboard.d.ts +59 -0
  112. package/dist/components/tt-select/src/hooks/usePagination.d.ts +16 -0
  113. package/dist/components/tt-select/src/hooks/useSelect.d.ts +87 -0
  114. package/dist/components/tt-select/src/hooks/useSelectTableEvent.d.ts +178 -0
  115. package/dist/components/tt-select/src/props.d.ts +190 -0
  116. package/dist/components/tt-select/src/types/index.d.ts +142 -0
  117. package/dist/components/tt-select/src/utils/index.d.ts +9 -0
  118. package/dist/components/tt-table/index.d.ts +127 -0
  119. package/dist/components/tt-table/src/Table.vue.d.ts +1685 -0
  120. package/dist/components/tt-table/src/componentMap.d.ts +8 -0
  121. package/dist/components/tt-table/src/components/RowContext.d.ts +24 -0
  122. package/dist/components/tt-table/src/components/TableAction.vue.d.ts +79 -0
  123. package/dist/components/tt-table/src/components/TableButtons.d.ts +30 -0
  124. package/dist/components/tt-table/src/components/TableColumnModal.vue.d.ts +26 -0
  125. package/dist/components/tt-table/src/components/TableToobalTools.vue.d.ts +1531 -0
  126. package/dist/components/tt-table/src/emits.d.ts +1 -0
  127. package/dist/components/tt-table/src/enum.d.ts +2 -0
  128. package/dist/components/tt-table/src/hooks/useCellArea.d.ts +15 -0
  129. package/dist/components/tt-table/src/hooks/useColumns.d.ts +27 -0
  130. package/dist/components/tt-table/src/hooks/useCustomColumns.d.ts +20 -0
  131. package/dist/components/tt-table/src/hooks/useDataSource.d.ts +29 -0
  132. package/dist/components/tt-table/src/hooks/useLeftRightSlot.d.ts +1082 -0
  133. package/dist/components/tt-table/src/hooks/usePagination.d.ts +102 -0
  134. package/dist/components/tt-table/src/hooks/useRowSelection.d.ts +30 -0
  135. package/dist/components/tt-table/src/hooks/useTable.d.ts +7 -0
  136. package/dist/components/tt-table/src/hooks/useTableContext.d.ts +43 -0
  137. package/dist/components/tt-table/src/hooks/useTableEvent.d.ts +101 -0
  138. package/dist/components/tt-table/src/hooks/useTableForm.d.ts +15 -0
  139. package/dist/components/tt-table/src/hooks/useTableFormEvent.d.ts +10 -0
  140. package/dist/components/tt-table/src/hooks/useTableHeight.d.ts +15 -0
  141. package/dist/components/tt-table/src/hooks/useTableRender.d.ts +93 -0
  142. package/dist/components/tt-table/src/hooks/useTableSlot.d.ts +11 -0
  143. package/dist/components/tt-table/src/props.d.ts +433 -0
  144. package/dist/components/tt-table/src/toolProps.d.ts +19 -0
  145. package/dist/components/tt-table/src/types/table.d.ts +489 -0
  146. package/dist/components/tt-table/src/types/tableAction.d.ts +26 -0
  147. package/dist/components/tt-table/src/types/tableForm.d.ts +64 -0
  148. package/dist/components/tt-table/src/types/tableTools.d.ts +10 -0
  149. package/dist/components/tt-table/src/utils/context.d.ts +18 -0
  150. package/dist/components/tt-table/src/utils/filters.d.ts +109 -0
  151. package/dist/components/tt-table/src/utils/table-api.d.ts +250 -0
  152. package/dist/components/tt-table/src/utils/table-form-api.d.ts +88 -0
  153. package/dist/components/tt-table/src/utils/vxeTable.d.ts +28 -0
  154. package/dist/components/tt-text/index.d.ts +76 -0
  155. package/dist/components/tt-text/index.vue.d.ts +50 -0
  156. package/dist/components/tt-tree-select/index.d.ts +5 -0
  157. package/dist/components/tt-tree-select/src/TtTreeSelect.vue.d.ts +6 -0
  158. package/dist/components/tt-tree-select/src/cache-options.d.ts +35 -0
  159. package/dist/components/tt-tree-select/src/select.d.ts +10 -0
  160. package/dist/components/tt-tree-select/src/tree.d.ts +23 -0
  161. package/dist/components/tt-tree-select/src/utils.d.ts +10 -0
  162. package/dist/components/tt-upload/index.d.ts +428 -0
  163. package/dist/components/tt-upload/src/TtUpload.d.ts +449 -0
  164. package/dist/components/tt-upload/src/typing.d.ts +251 -0
  165. package/dist/components/types.d.ts +230 -0
  166. package/dist/directives/auto-tip/index.d.ts +3 -0
  167. package/dist/directives/dialog-resize/index.d.ts +25 -0
  168. package/dist/directives/dialog-resize/use-css-variable.d.ts +1 -0
  169. package/dist/directives/dialog-resize/use-draggable.d.ts +4 -0
  170. package/dist/directives/dialog-resize/use-fullscreen.d.ts +1 -0
  171. package/dist/directives/dialog-resize/use-parse-translate.d.ts +4 -0
  172. package/dist/directives/dialog-resize/use-resizer.d.ts +2 -0
  173. package/dist/directives/disabled-tip/index.d.ts +17 -0
  174. package/dist/directives/index.d.ts +3 -0
  175. package/dist/hooks/useFormat.d.ts +73 -0
  176. package/dist/hooks/useLoading.d.ts +9 -0
  177. package/dist/hooks/useSetup.d.ts +8 -0
  178. package/dist/hooks/useTable.d.ts +5 -0
  179. package/dist/hooks/useTemplateSlot.d.ts +9 -0
  180. package/dist/{index-CMjNBMj5.js → index-NG5FNCLD.js} +2 -3
  181. package/dist/index.d.ts +47 -0
  182. package/dist/index.js +10239 -9224
  183. package/dist/{index.modern-BfZxYaPy.js → index.modern-DfItAsVf.js} +1 -1
  184. package/dist/plugins/index.d.ts +1 -0
  185. package/dist/plugins/vxeTable/switchStatus.d.ts +7 -0
  186. package/dist/plugins.d.ts +2 -0
  187. package/dist/plugins.js +29 -30
  188. package/dist/style.css +1 -1
  189. package/package.json +3 -10
@@ -0,0 +1,54 @@
1
+ import { z } from 'zod';
2
+ /**
3
+ * A type which represents all the simple Zod types
4
+ * that do not require special handling.
5
+ */
6
+ export type SimpleSupportedZodTypes = z.ZodBoolean | z.ZodNumber | z.ZodString | z.ZodArray<any>;
7
+ /**
8
+ * A type which represents all the supported Zod types
9
+ * that do not require special handling.
10
+ *
11
+ * Other special types like ZodUnion, ZodIntersection, etc.
12
+ * require special handling and are not included in this type.
13
+ *
14
+ * TODO: Add support for missing Zod types.
15
+ */
16
+ export type BaseSupportedZodTypes = SimpleSupportedZodTypes | z.ZodRecord<any, any> | z.ZodObject<any, any> | z.ZodTuple<[any, ...any[]]>;
17
+ /**
18
+ * A type which represents all the supported Zod types
19
+ * that require special handling because they are composed
20
+ * of multiple Zod types.
21
+ *
22
+ * TODO: Add support for missing Zod types.
23
+ */
24
+ export type AdvancedSupportedZodTypes = z.ZodDefault<any> | z.ZodOptional<any> | z.ZodUnion<any> | z.ZodIntersection<any, any>;
25
+ /**
26
+ * A type which represents all the supported Zod types.
27
+ */
28
+ export type SupportedZodTypes = BaseSupportedZodTypes | AdvancedSupportedZodTypes;
29
+ /**
30
+ * Returns the default values as an object for the provided schema.
31
+ *
32
+ * For example, given the following schema:
33
+ * ```typescript
34
+ * const schema = z.object({
35
+ * name: z.string(),
36
+ * age: z.number(),
37
+ * isStudent: z.boolean().default(true),
38
+ * });
39
+ * ```
40
+ *
41
+ * The default object would be:
42
+ * ```json
43
+ * {
44
+ * name: "",
45
+ * age: 0,
46
+ * isStudent: true
47
+ * }
48
+ * ```
49
+ * Note the default value for `isStudent` is `true` because it is specified in
50
+ * the schema.
51
+ *
52
+ * @param schema
53
+ */
54
+ export declare function getDefaultsForSchema<T extends z.ZodObject<any> | z.ZodUnion<any> | z.ZodIntersection<any, any>>(schema: T): Record<string, never> | z.infer<T>;
@@ -0,0 +1,11 @@
1
+ import { MaybeRef, Ref } from 'vue';
2
+ import { Path, PathValue } from './paths';
3
+ export type GenericObject = Record<string, any>;
4
+ export type MaybeArray<T> = T | T[];
5
+ export type MaybePromise<T> = T | Promise<T>;
6
+ export type FlattenAndSetPathsType<TRecord, TType> = {
7
+ [K in Path<TRecord>]: TType;
8
+ };
9
+ export type MapValuesPathsToRefs<TValues extends GenericObject, TPaths extends readonly [...MaybeRef<Path<TValues>>[]]> = {
10
+ readonly [K in keyof TPaths]: TPaths[K] extends MaybeRef<infer TKey> ? TKey extends Path<TValues> ? Ref<PathValue<TValues, TKey>> : Ref<unknown> : Ref<unknown>;
11
+ };
@@ -0,0 +1,280 @@
1
+ import { StandardSchemaV1 } from '@standard-schema/spec';
2
+ import { PartialDeep } from 'type-fest';
3
+ import { ComputedRef, MaybeRef, MaybeRefOrGetter, Ref } from 'vue';
4
+ import { FlattenAndSetPathsType, GenericObject, MapValuesPathsToRefs, MaybeArray, MaybePromise } from './common';
5
+ import { Path, PathValue } from './paths';
6
+ import { FieldValidationMetaInfo } from './shared';
7
+ export type ValidationResult<TValue = unknown> = {
8
+ errors: string[];
9
+ valid: boolean;
10
+ value?: TValue;
11
+ };
12
+ export type FlattenAndMapPathsValidationResult<TInput extends GenericObject, TOutput extends GenericObject> = {
13
+ [K in Path<TInput>]: ValidationResult<TOutput[K]>;
14
+ };
15
+ export type Locator = {
16
+ __locatorRef: string;
17
+ } & ((values: GenericObject) => unknown);
18
+ export interface FieldMeta<TValue> {
19
+ touched: boolean;
20
+ dirty: boolean;
21
+ valid: boolean;
22
+ validated: boolean;
23
+ pending: boolean;
24
+ initialValue?: TValue;
25
+ }
26
+ export interface FormMeta<TValues extends GenericObject> {
27
+ touched: boolean;
28
+ dirty: boolean;
29
+ valid: boolean;
30
+ pending: boolean;
31
+ initialValues?: Partial<TValues>;
32
+ }
33
+ export interface FieldState<TValue = unknown> {
34
+ value: TValue;
35
+ touched: boolean;
36
+ errors: string[];
37
+ }
38
+ export type InputType = "checkbox" | "radio" | "default";
39
+ /**
40
+ * validated-only: only mutate the previously validated fields
41
+ * silent: do not mutate any field
42
+ * force: validate all fields and mutate their state
43
+ */
44
+ export type SchemaValidationMode = "validated-only" | "silent" | "force" | "no-validated";
45
+ export type ValidationOptions = {
46
+ mode: SchemaValidationMode;
47
+ warn: boolean;
48
+ };
49
+ export type FieldValidator<TOutput> = (opts?: Partial<ValidationOptions>) => Promise<ValidationResult<TOutput>>;
50
+ export type PathStateConfig<TOutput> = {
51
+ bails: boolean;
52
+ label: MaybeRefOrGetter<string | undefined>;
53
+ type: InputType;
54
+ validate: FieldValidator<TOutput>;
55
+ schema?: MaybeRefOrGetter<StandardSchemaV1 | undefined>;
56
+ /**
57
+ * 在判断 dirty 状态时需要排除的字段列表(仅对对象类型有效)
58
+ * @example
59
+ * excludeKeys: ['_timestamp']
60
+ */
61
+ excludeKeys?: string[];
62
+ };
63
+ export type IssueCollection<TPath = string> = {
64
+ path: TPath;
65
+ messages: string[];
66
+ };
67
+ export type PathState<TInput = unknown, TOutput = TInput> = {
68
+ id: number | number[];
69
+ path: string;
70
+ touched: boolean;
71
+ dirty: boolean;
72
+ valid: boolean;
73
+ validated: boolean;
74
+ pending: boolean;
75
+ initialValue: TInput | undefined;
76
+ value: TInput | undefined;
77
+ errors: string[];
78
+ bails: boolean;
79
+ label: string | undefined;
80
+ type: InputType;
81
+ multiple: boolean;
82
+ fieldsCount: number;
83
+ __flags: {
84
+ pendingUnmount: Record<string, boolean>;
85
+ pendingReset: boolean;
86
+ };
87
+ validate?: FieldValidator<TOutput>;
88
+ };
89
+ export type FieldEntry<TValue = unknown> = {
90
+ value: TValue;
91
+ key: string | number;
92
+ isFirst: boolean;
93
+ isLast: boolean;
94
+ };
95
+ export type FieldArrayContext<TValue = unknown> = {
96
+ fields: Ref<FieldEntry<TValue>[]>;
97
+ remove: (idx: number) => void;
98
+ replace: (newArray: TValue[]) => void;
99
+ update: (idx: number, value: TValue) => void;
100
+ push: (value: TValue) => void;
101
+ swap: (indexA: number, indexB: number) => void;
102
+ insert: (idx: number, value: TValue) => void;
103
+ prepend: (value: TValue) => void;
104
+ move: (oldIdx: number, newIdx: number) => void;
105
+ };
106
+ export type PrivateFieldArrayContext<TValue = unknown> = {
107
+ reset: () => void;
108
+ path: MaybeRefOrGetter<string>;
109
+ } & FieldArrayContext<TValue>;
110
+ export type PrivateFieldContext<TInput = unknown, TOutput = TInput> = {
111
+ id: number;
112
+ name: MaybeRef<string>;
113
+ value: Ref<TInput>;
114
+ meta: FieldMeta<TInput>;
115
+ errors: Ref<string[]>;
116
+ errorMessage: Ref<string | undefined>;
117
+ label?: MaybeRefOrGetter<string | undefined>;
118
+ type?: string;
119
+ bails?: boolean;
120
+ keepValueOnUnmount?: MaybeRefOrGetter<boolean | undefined>;
121
+ checkedValue?: MaybeRefOrGetter<TInput>;
122
+ uncheckedValue?: MaybeRefOrGetter<TInput>;
123
+ checked?: Ref<boolean>;
124
+ resetField: (state?: Partial<FieldState<TInput>>) => void;
125
+ handleReset: () => void;
126
+ validate: FieldValidator<TOutput>;
127
+ handleChange: (e: Event | unknown, shouldValidate?: boolean) => void;
128
+ handleBlur: (e?: Event, shouldValidate?: boolean) => void;
129
+ handleFocus: (e?: Event) => void;
130
+ setState: (state: Partial<FieldState<TInput>>) => void;
131
+ setTouched: (isTouched: boolean) => void;
132
+ setErrors: (message: string | string[]) => void;
133
+ setValue: (value: TInput, shouldValidate?: boolean) => void;
134
+ };
135
+ export type FieldContext<TValue = unknown> = Omit<PrivateFieldContext<TValue>, "id" | "instances">;
136
+ export type GenericValidateFunction<TValue = unknown> = (value: TValue, ctx: FieldValidationMetaInfo) => MaybePromise<boolean | MaybeArray<string>>;
137
+ export interface FormState<TValues> {
138
+ values: PartialDeep<TValues>;
139
+ errors: Partial<Record<Path<TValues>, string | undefined>>;
140
+ touched: Partial<Record<Path<TValues>, boolean>>;
141
+ submitCount: number;
142
+ }
143
+ export type FormErrors<TValues extends GenericObject> = Partial<Record<Path<TValues> | "", string | undefined>>;
144
+ export type FormErrorBag<TValues extends GenericObject> = Partial<Record<Path<TValues> | "", string[]>>;
145
+ export interface ResetFormOpts {
146
+ force?: boolean;
147
+ }
148
+ export interface FormActions<TValues extends GenericObject, _TOutput = TValues> {
149
+ setFieldValue: <T extends Path<TValues>>(field: T, value: PathValue<TValues, T>, shouldValidate?: boolean) => void;
150
+ setFieldError: (field: Path<TValues>, message: string | string[] | undefined) => void;
151
+ setErrors: (fields: Partial<FlattenAndSetPathsType<TValues, string | string[] | undefined>>) => void;
152
+ setValues: (fields: Partial<TValues>, shouldValidate?: boolean) => void;
153
+ setFieldTouched: (field: Path<TValues>, isTouched: boolean) => void;
154
+ setTouched: (fields: Partial<Record<Path<TValues>, boolean>> | boolean) => void;
155
+ resetForm: (state?: Partial<FormState<TValues>>, opts?: Partial<ResetFormOpts>) => void;
156
+ resetField: (field: Path<TValues>, state?: Partial<FieldState>) => void;
157
+ }
158
+ export interface FormValidationResult<TInput extends GenericObject, TOutput extends GenericObject = TInput> {
159
+ valid: boolean;
160
+ results: Partial<FlattenAndMapPathsValidationResult<TInput, TOutput>>;
161
+ errors: Partial<Record<Path<TInput>, string>>;
162
+ values?: Partial<TOutput>;
163
+ source: "schema" | "fields" | "none";
164
+ }
165
+ export interface SubmissionContext<TInput extends GenericObject = GenericObject> extends FormActions<TInput> {
166
+ evt?: Event;
167
+ controlledValues: Partial<TInput>;
168
+ }
169
+ export type SubmissionHandler<TInput extends GenericObject = GenericObject, TOutput = TInput, TReturn = unknown> = (values: TOutput, ctx: SubmissionContext<TInput>) => TReturn;
170
+ export interface InvalidSubmissionContext<TInput extends GenericObject = GenericObject, TOutput extends GenericObject = TInput> {
171
+ values: TInput;
172
+ evt?: Event;
173
+ errors: Partial<Record<Path<TInput>, string>>;
174
+ results: FormValidationResult<TInput, TOutput>["results"];
175
+ }
176
+ export type InvalidSubmissionHandler<TInput extends GenericObject = GenericObject, TOutput extends GenericObject = TInput> = (ctx: InvalidSubmissionContext<TInput, TOutput>) => void;
177
+ export type RawFormSchema<TValues> = Record<Path<TValues>, string | GenericValidateFunction | GenericObject>;
178
+ export type FieldPathLookup<TValues extends GenericObject = GenericObject> = Partial<Record<Path<TValues>, PrivateFieldContext | PrivateFieldContext[]>>;
179
+ type HandleSubmitFactory<TValues extends GenericObject, TOutput extends GenericObject = TValues> = <TReturn = unknown>(cb: SubmissionHandler<TValues, TOutput, TReturn>, onSubmitValidationErrorCb?: InvalidSubmissionHandler<TValues, TOutput>) => (e?: Event) => Promise<TReturn | undefined>;
180
+ export type PublicPathState<TValue = unknown> = Omit<PathState<TValue>, "bails" | "label" | "multiple" | "fieldsCount" | "validate" | "id" | "type" | "__flags">;
181
+ export interface BaseFieldProps {
182
+ onBlur: () => void;
183
+ onChange: () => void;
184
+ onInput: () => void;
185
+ }
186
+ export interface InputBindsConfig<TValue = unknown, TExtraProps extends GenericObject = GenericObject> {
187
+ props: (state: PublicPathState<TValue>) => TExtraProps;
188
+ validateOnBlur: boolean;
189
+ label: MaybeRefOrGetter<string>;
190
+ validateOnChange: boolean;
191
+ validateOnInput: boolean;
192
+ validateOnModelUpdate: boolean;
193
+ }
194
+ export type LazyInputBindsConfig<TValue = unknown, TExtraProps extends GenericObject = GenericObject> = (state: PublicPathState<TValue>) => Partial<{
195
+ props: TExtraProps;
196
+ validateOnBlur: boolean;
197
+ validateOnChange: boolean;
198
+ validateOnInput: boolean;
199
+ validateOnModelUpdate: boolean;
200
+ }>;
201
+ export interface ComponentBindsConfig<TValue = unknown, TExtraProps extends GenericObject = GenericObject, TModel extends string = "modelValue"> {
202
+ mapProps: (state: PublicPathState<TValue>) => TExtraProps;
203
+ validateOnBlur: boolean;
204
+ validateOnModelUpdate: boolean;
205
+ model: TModel;
206
+ }
207
+ export type LazyComponentBindsConfig<TValue = unknown, TExtraProps extends GenericObject = GenericObject, TModel extends string = "modelValue"> = (state: PublicPathState<TValue>) => Partial<{
208
+ props: TExtraProps;
209
+ validateOnBlur: boolean;
210
+ validateOnModelUpdate: boolean;
211
+ model: TModel;
212
+ }>;
213
+ export interface ComponentModellessBinds {
214
+ onBlur: () => void;
215
+ }
216
+ export type ComponentModelBinds<TValue = any, TModel extends string = "modelValue"> = ComponentModellessBinds & {
217
+ [TKey in `onUpdate:${TModel}`]: (value: TValue) => void;
218
+ };
219
+ export type BaseComponentBinds<TValue = any, TModel extends string = "modelValue"> = ComponentModelBinds<TValue, TModel> & {
220
+ [k in TModel]: TValue;
221
+ };
222
+ export interface BaseInputBinds<TValue = unknown> {
223
+ value: TValue | undefined;
224
+ onBlur: (e: Event) => void;
225
+ onChange: (e: Event) => void;
226
+ onInput: (e: Event) => void;
227
+ }
228
+ export interface PrivateFormContext<TValues extends GenericObject = GenericObject, TOutput extends GenericObject = TValues> extends FormActions<TValues> {
229
+ name: string;
230
+ formId: number;
231
+ values: TValues;
232
+ initialValues: Ref<Partial<TValues>>;
233
+ controlledValues: Ref<TValues>;
234
+ fieldArrays: PrivateFieldArrayContext[];
235
+ submitCount: Ref<number>;
236
+ schema?: MaybeRef<RawFormSchema<TValues> | StandardSchemaV1<TValues, TOutput> | undefined>;
237
+ errorBag: Ref<FormErrorBag<TValues>>;
238
+ errors: ComputedRef<FormErrors<TValues>>;
239
+ meta: ComputedRef<FormMeta<TValues>>;
240
+ isSubmitting: Ref<boolean>;
241
+ isValidating: Ref<boolean>;
242
+ keepValuesOnUnmount: MaybeRef<boolean>;
243
+ validateSchema?: (mode: SchemaValidationMode) => Promise<FormValidationResult<TValues, TOutput>>;
244
+ validate: (opts?: Partial<ValidationOptions>) => Promise<FormValidationResult<TValues, TOutput>>;
245
+ validateField: <TPath extends Path<TValues>>(field: TPath, opts?: Partial<ValidationOptions>) => Promise<ValidationResult<TOutput[TPath]>>;
246
+ stageInitialValue: (path: string, value: unknown, updateOriginal?: boolean) => void;
247
+ unsetInitialValue: (path: string) => void;
248
+ handleSubmit: HandleSubmitFactory<TValues, TOutput> & {
249
+ withControlled: HandleSubmitFactory<TValues, TOutput>;
250
+ };
251
+ setFieldInitialValue: (path: string, value: unknown, updateOriginal?: boolean) => void;
252
+ createPathState: <TPath extends Path<TValues>>(path: MaybeRef<TPath>, config?: Partial<PathStateConfig<TOutput[TPath]>>) => PathState<PathValue<TValues, TPath>>;
253
+ getPathState: <TPath extends Path<TValues>>(path: TPath) => PathState<PathValue<TValues, TPath>> | undefined;
254
+ getAllPathStates: () => PathState[];
255
+ removePathState: <TPath extends Path<TValues>>(path: TPath, id: number) => void;
256
+ unsetPathValue: <TPath extends Path<TValues>>(path: TPath) => void;
257
+ destroyPath: (path: string) => void;
258
+ isFieldTouched: <TPath extends Path<TValues>>(path: TPath) => boolean;
259
+ isFieldDirty: <TPath extends Path<TValues>>(path: TPath) => boolean;
260
+ isFieldValid: <TPath extends Path<TValues>>(path: TPath) => boolean;
261
+ defineField: <TPath extends Path<TValues>, TValue = PathValue<TValues, TPath>, TExtras extends GenericObject = GenericObject>(path: MaybeRefOrGetter<TPath>, config?: Partial<InputBindsConfig<TValue, TExtras>> | LazyInputBindsConfig<TValue, TExtras>) => [Ref<TValue>, Ref<BaseFieldProps & TExtras>];
262
+ /**
263
+ * @deprecated use defineField instead
264
+ */
265
+ useFieldModel: (<TPath extends Path<TValues>>(path: TPath) => Ref<PathValue<TValues, TPath>>) & (<TPaths extends readonly [...MaybeRef<Path<TValues>>[]]>(paths: TPaths) => MapValuesPathsToRefs<TValues, TPaths>);
266
+ /**
267
+ * @deprecated use defineField instead
268
+ */
269
+ defineComponentBinds: <TPath extends Path<TValues>, TValue = PathValue<TValues, TPath>, TModel extends string = "modelValue", TExtras extends GenericObject = GenericObject>(path: MaybeRefOrGetter<TPath>, config?: Partial<ComponentBindsConfig<TValue, TExtras, TModel>> | LazyComponentBindsConfig<TValue, TExtras, TModel>) => Ref<BaseComponentBinds<TValue, TModel> & TExtras>;
270
+ /**
271
+ * @deprecated use defineField instead
272
+ */
273
+ defineInputBinds: <TPath extends Path<TValues>, TValue = PathValue<TValues, TPath>, TExtras extends GenericObject = GenericObject>(path: MaybeRefOrGetter<TPath>, config?: Partial<InputBindsConfig<TValue, TExtras>> | LazyInputBindsConfig<TValue, TExtras>) => Ref<BaseInputBinds<TValue> & TExtras>;
274
+ }
275
+ export interface FormContext<TValues extends GenericObject = GenericObject, TOutput extends GenericObject = TValues> extends Omit<PrivateFormContext<TValues, TOutput>, "formId" | "schema" | "initialValues" | "getPathState" | "getAllPathStates" | "removePathState" | "unsetPathValue" | "validateSchema" | "stageInitialValue" | "setFieldInitialValue" | "unsetInitialValue" | "fieldArrays" | "markForUnmount" | "keepValuesOnUnmount" | "values"> {
276
+ values: TValues;
277
+ handleReset: () => void;
278
+ submitForm: (e?: unknown) => Promise<void>;
279
+ }
280
+ export {};
@@ -0,0 +1,3 @@
1
+ export * from './common';
2
+ export * from './forms';
3
+ export * from './paths';
@@ -0,0 +1,142 @@
1
+ type BrowserNativeObject = Date | FileList | File;
2
+ type Primitive = null | undefined | string | number | boolean | symbol | bigint;
3
+ /**
4
+ * Checks whether the type is any
5
+ * See {@link https://stackoverflow.com/a/49928360/3406963}
6
+ * @typeParam T - type which may be any
7
+ * ```
8
+ * IsAny<any> = true
9
+ * IsAny<string> = false
10
+ * ```
11
+ */
12
+ export type IsAny<T> = 0 extends 1 & T ? true : false;
13
+ /**
14
+ * Checks whether T1 can be exactly (mutually) assigned to T2
15
+ * @typeParam T1 - type to check
16
+ * @typeParam T2 - type to check against
17
+ * ```
18
+ * IsEqual<string, string> = true
19
+ * IsEqual<'foo', 'foo'> = true
20
+ * IsEqual<string, number> = false
21
+ * IsEqual<string, number> = false
22
+ * IsEqual<string, 'foo'> = false
23
+ * IsEqual<'foo', string> = false
24
+ * IsEqual<'foo' | 'bar', 'foo'> = boolean // 'foo' is assignable, but 'bar' is not (true | false) -> boolean
25
+ * ```
26
+ */
27
+ export type IsEqual<T1, T2> = T1 extends T2 ? (<G>() => G extends T1 ? 1 : 2) extends <G>() => G extends T2 ? 1 : 2 ? true : false : false;
28
+ /**
29
+ * Type to query whether an array type T is a tuple type.
30
+ * @typeParam T - type which may be an array or tuple
31
+ * @example
32
+ * ```
33
+ * IsTuple<[number]> = true
34
+ * IsTuple<number[]> = false
35
+ * ```
36
+ */
37
+ type IsTuple<T extends ReadonlyArray<any>> = number extends T["length"] ? false : true;
38
+ /**
39
+ * Type which can be used to index an array or tuple type.
40
+ */
41
+ type ArrayKey = number;
42
+ /**
43
+ * Helper function to break apart T1 and check if any are equal to T2
44
+ *
45
+ * See {@link IsEqual}
46
+ */
47
+ type AnyIsEqual<T1, T2> = T1 extends T2 ? (IsEqual<T1, T2> extends true ? true : never) : never;
48
+ /**
49
+ * Type which given a tuple type returns its own keys, i.e. only its indices.
50
+ * @typeParam T - tuple type
51
+ * @example
52
+ * ```
53
+ * TupleKeys<[number, string]> = '0' | '1'
54
+ * ```
55
+ */
56
+ type TupleKeys<T extends ReadonlyArray<any>> = Exclude<keyof T, keyof any[]>;
57
+ /**
58
+ * Helper type to construct tuple key paths and recurse into its elements.
59
+ *
60
+ * See {@link Path}
61
+ */
62
+ type PathInternalTuple<TValue extends ReadonlyArray<any>, TraversedTypes> = {
63
+ [Key in TupleKeys<TValue> & string]: `[${Key}]` | `[${Key}]${PathInternal<TValue[Key], TraversedTypes, false>}`;
64
+ }[TupleKeys<TValue> & string];
65
+ /**
66
+ * Helper type to construct array key paths and recurse into its elements.
67
+ *
68
+ * See {@link Path}
69
+ */
70
+ type PathInternalArray<TValue extends ReadonlyArray<any>, TraversedTypes> = `[${ArrayKey}]` | `[${ArrayKey}]${PathInternal<TValue[ArrayKey], TraversedTypes, false>}`;
71
+ /**
72
+ * Helper type to construct object key paths and recurse into its nested values.
73
+ *
74
+ * See {@link Path}
75
+ */
76
+ type PathInternalObject<TValue, TraversedTypes, First extends boolean> = {
77
+ [Key in keyof TValue & string]: First extends true ? `${Key}` | `${Key}${PathInternal<TValue[Key], TraversedTypes, false>}` : `.${Key}` | `.${Key}${PathInternal<TValue[Key], TraversedTypes, false>}`;
78
+ }[keyof TValue & string];
79
+ /**
80
+ * Helper type to construct nested any object key paths.
81
+ *
82
+ * See {@link Path}
83
+ */
84
+ type PathInternalAny = `.${string}` | `[${string}]` | `[${string}].${string}`;
85
+ /**
86
+ * Helper type for recursively constructing paths through a type.
87
+ *
88
+ * This obscures internal type params TraversedTypes and First from ed contract.
89
+ *
90
+ * See {@link Path}
91
+ */
92
+ type PathInternal<TValue, TraversedTypes, First extends boolean> = TValue extends Primitive | BrowserNativeObject ? IsAny<TValue> extends true ? PathInternalAny : never : TValue extends ReadonlyArray<any> ? true extends AnyIsEqual<TraversedTypes, TValue> ? never : IsTuple<TValue> extends true ? PathInternalTuple<TValue, TraversedTypes | TValue> : PathInternalArray<TValue, TraversedTypes | TValue> : TValue extends Record<string, any> ? PathInternalObject<TValue, TraversedTypes | TValue, First> : "";
93
+ /**
94
+ * Helper type for recursively constructing paths through a type.
95
+ * This actually constructs the strings and recurses into nested
96
+ * object types.
97
+ *
98
+ * See {@link ArrayPath}
99
+ */
100
+ type ArrayPathImpl<K extends string | number, V, TraversedTypes> = V extends Primitive | BrowserNativeObject ? IsAny<V> extends true ? string : never : V extends ReadonlyArray<infer U> ? U extends Primitive | BrowserNativeObject ? IsAny<V> extends true ? string : never : true extends AnyIsEqual<TraversedTypes, V> ? never : `${K}` | `${K}.${ArrayPathInternal<V, TraversedTypes | V>}` : true extends AnyIsEqual<TraversedTypes, V> ? never : `${K}.${ArrayPathInternal<V, TraversedTypes | V>}`;
101
+ /**
102
+ * Helper type for recursively constructing paths through a type.
103
+ * This obscures the internal type param TraversedTypes from ed contract.
104
+ *
105
+ * See {@link ArrayPath}
106
+ */
107
+ type ArrayPathInternal<T, TraversedTypes = T> = T extends ReadonlyArray<infer V> ? IsTuple<T> extends true ? {
108
+ [K in TupleKeys<T>]-?: ArrayPathImpl<K & string, T[K], TraversedTypes>;
109
+ }[TupleKeys<T>] : ArrayPathImpl<ArrayKey, V, TraversedTypes> : {
110
+ [K in keyof T]-?: ArrayPathImpl<K & string, T[K], TraversedTypes>;
111
+ }[keyof T];
112
+ /**
113
+ * Type which eagerly collects all paths through a type which point to an array
114
+ * type.
115
+ * @typeParam T - type which should be introspected.
116
+ * @example
117
+ * ```
118
+ * Path<{foo: {bar: string[], baz: number[]}}> = 'foo.bar' | 'foo.baz'
119
+ * ```
120
+ */
121
+ type ArrayPath<T> = T extends any ? ArrayPathInternal<T> : never;
122
+ /**
123
+ * Type to evaluate the type which the given path points to.
124
+ * @typeParam T - deeply nested type which is indexed by the path
125
+ * @typeParam P - path into the deeply nested type
126
+ * @example
127
+ * ```
128
+ * PathValue<{foo: {bar: string}}, 'foo.bar'> = string
129
+ * PathValue<[number, string], '1'> = string
130
+ * ```
131
+ */
132
+ export type PathValue<T, P extends Path<T> | ArrayPath<T>> = T extends any ? P extends `${infer K}.${infer R}` ? K extends keyof T ? R extends Path<T[K]> ? PathValue<T[K], R> : never : K extends `${ArrayKey}` ? T extends ReadonlyArray<infer V> ? PathValue<V, R & Path<V>> : never : never : P extends keyof T ? T[P] : P extends `${ArrayKey}` ? T extends ReadonlyArray<infer V> ? V : never : never : never;
133
+ /**
134
+ * Type which eagerly collects all paths through a type
135
+ * @typeParam T - type which should be introspected
136
+ * @example
137
+ * ```
138
+ * Path<{foo: {bar: string}}> = 'foo' | 'foo.bar'
139
+ * ```
140
+ */
141
+ export type Path<T> = T extends any ? PathInternal<T, T, true> & string : never;
142
+ export {};
@@ -0,0 +1,19 @@
1
+ export type FieldValidationMetaInfo = {
2
+ field: string;
3
+ name: string;
4
+ label?: string;
5
+ value: unknown;
6
+ form: Record<string, unknown>;
7
+ rule?: {
8
+ name: string;
9
+ params?: Record<string, unknown> | unknown[];
10
+ };
11
+ };
12
+ export type ValidationRuleFunction<TValue = unknown, TParams = unknown[] | Record<string, unknown>> = (value: TValue, params: TParams, ctx: FieldValidationMetaInfo) => boolean | string | Promise<boolean | string>;
13
+ export type SimpleValidationRuleFunction<TValue = unknown, TParams = unknown[] | Record<string, unknown>> = (value: TValue, params: TParams) => boolean | string | Promise<boolean | string>;
14
+ export type ValidationMessageGenerator = (ctx: FieldValidationMetaInfo) => string;
15
+ export type Optional<T> = T extends Record<string, any> ? Partial<T> : T | undefined;
16
+ export type InterpolateOptions = {
17
+ prefix: string;
18
+ suffix: string;
19
+ };