@sheinx/hooks 3.8.0-beta.9 → 3.8.1-beta.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.
- package/cjs/common/use-filter/use-filter.d.ts.map +1 -1
- package/cjs/common/use-filter/use-filter.js +4 -1
- package/cjs/common/use-position-style/index.d.ts.map +1 -1
- package/cjs/common/use-position-style/index.js +11 -8
- package/cjs/components/use-check/use-check.d.ts.map +1 -1
- package/cjs/components/use-check/use-check.js +10 -2
- package/cjs/components/use-datepicker/use-datepicker-format.d.ts.map +1 -1
- package/cjs/components/use-datepicker/use-datepicker-format.js +1 -0
- package/cjs/components/use-datepicker/use-time.d.ts +10 -8
- package/cjs/components/use-datepicker/use-time.d.ts.map +1 -1
- package/cjs/components/use-datepicker/use-time.js +19 -5
- package/cjs/components/use-datepicker/use-time.type.d.ts +5 -1
- package/cjs/components/use-datepicker/use-time.type.d.ts.map +1 -1
- package/cjs/components/use-datepicker/util.d.ts.map +1 -1
- package/cjs/components/use-datepicker/util.js +10 -1
- package/cjs/components/use-form/Provider.d.ts.map +1 -1
- package/cjs/components/use-form/Provider.js +7 -2
- package/cjs/components/use-form/form-schema-context.d.ts +6 -0
- package/cjs/components/use-form/form-schema-context.d.ts.map +1 -0
- package/cjs/components/use-form/form-schema-context.js +16 -0
- package/cjs/components/use-form/index.d.ts +2 -0
- package/cjs/components/use-form/index.d.ts.map +1 -1
- package/cjs/components/use-form/index.js +21 -1
- package/cjs/components/use-form/use-form-context.type.d.ts +6 -0
- package/cjs/components/use-form/use-form-context.type.d.ts.map +1 -1
- package/cjs/components/use-form/use-form-control/use-form-control.d.ts.map +1 -1
- package/cjs/components/use-form/use-form-control/use-form-control.js +34 -4
- package/cjs/components/use-form/use-form-control/use-form-control.type.d.ts +8 -2
- package/cjs/components/use-form/use-form-control/use-form-control.type.d.ts.map +1 -1
- package/cjs/components/use-form/use-form-flow/use-form-datum.d.ts +8 -0
- package/cjs/components/use-form/use-form-flow/use-form-datum.d.ts.map +1 -1
- package/cjs/components/use-form/use-form-item/form-item-context.d.ts +1 -0
- package/cjs/components/use-form/use-form-item/form-item-context.d.ts.map +1 -1
- package/cjs/components/use-form/use-form-item/form-item-context.js +2 -1
- package/cjs/components/use-form/use-form-item/index.d.ts +1 -0
- package/cjs/components/use-form/use-form-item/index.d.ts.map +1 -1
- package/cjs/components/use-form/use-form-item/index.js +7 -0
- package/cjs/components/use-form/use-form-item/use-form-item.d.ts +1 -1
- package/cjs/components/use-form/use-form-schema/form-schema-builder.d.ts +50 -0
- package/cjs/components/use-form/use-form-schema/form-schema-builder.d.ts.map +1 -0
- package/cjs/components/use-form/use-form-schema/form-schema-builder.js +377 -0
- package/cjs/components/use-form/use-form-schema/index.d.ts +3 -0
- package/cjs/components/use-form/use-form-schema/index.d.ts.map +1 -0
- package/cjs/components/use-form/use-form-schema/index.js +13 -0
- package/cjs/components/use-form/use-form.d.ts +4 -0
- package/cjs/components/use-form/use-form.d.ts.map +1 -1
- package/cjs/components/use-form/use-form.js +19 -9
- package/cjs/components/use-form/use-form.type.d.ts +46 -39
- package/cjs/components/use-form/use-form.type.d.ts.map +1 -1
- package/cjs/components/use-input/use-input-number.d.ts.map +1 -1
- package/cjs/components/use-input/use-input-number.js +3 -1
- package/cjs/components/use-input/use-input-number.type.d.ts +1 -1
- package/cjs/components/use-input/use-input-number.type.d.ts.map +1 -1
- package/cjs/components/use-input/use-input.d.ts.map +1 -1
- package/cjs/components/use-input/use-input.js +4 -1
- package/cjs/components/use-pagination/use-pagination.d.ts.map +1 -1
- package/cjs/components/use-pagination/use-pagination.js +2 -1
- package/cjs/components/use-popup/use-popup.d.ts.map +1 -1
- package/cjs/components/use-popup/use-popup.js +12 -24
- package/cjs/components/use-select/use-select.type.d.ts +27 -18
- package/cjs/components/use-select/use-select.type.d.ts.map +1 -1
- package/cjs/components/use-table/use-table-virtual.d.ts +6 -1
- package/cjs/components/use-table/use-table-virtual.d.ts.map +1 -1
- package/cjs/components/use-table/use-table-virtual.js +5 -4
- package/cjs/components/use-table/use-table.type.d.ts +70 -92
- package/cjs/components/use-table/use-table.type.d.ts.map +1 -1
- package/cjs/components/use-tree/use-tree-node.d.ts +7 -1
- package/cjs/components/use-tree/use-tree-node.d.ts.map +1 -1
- package/cjs/components/use-tree/use-tree-node.js +19 -1
- package/cjs/components/use-tree/use-tree.d.ts.map +1 -1
- package/cjs/components/use-tree/use-tree.js +26 -19
- package/cjs/components/use-tree/use-tree.type.d.ts +7 -1
- package/cjs/components/use-tree/use-tree.type.d.ts.map +1 -1
- package/cjs/utils/dom/document.d.ts +4 -0
- package/cjs/utils/dom/document.d.ts.map +1 -1
- package/cjs/utils/dom/document.js +19 -2
- package/cjs/utils/dom/element.d.ts +1 -0
- package/cjs/utils/dom/element.d.ts.map +1 -1
- package/cjs/utils/dom/element.js +5 -1
- package/cjs/utils/highlight.d.ts.map +1 -1
- package/cjs/utils/highlight.js +24 -11
- package/cjs/utils/lazyload.d.ts.map +1 -1
- package/cjs/utils/lazyload.js +33 -1
- package/cjs/utils/object.d.ts +6 -0
- package/cjs/utils/object.d.ts.map +1 -1
- package/cjs/utils/object.js +21 -1
- package/esm/common/use-filter/use-filter.d.ts.map +1 -1
- package/esm/common/use-filter/use-filter.js +4 -1
- package/esm/common/use-position-style/index.d.ts.map +1 -1
- package/esm/common/use-position-style/index.js +12 -9
- package/esm/components/use-check/use-check.d.ts.map +1 -1
- package/esm/components/use-check/use-check.js +10 -2
- package/esm/components/use-datepicker/use-datepicker-format.d.ts.map +1 -1
- package/esm/components/use-datepicker/use-datepicker-format.js +1 -0
- package/esm/components/use-datepicker/use-time.d.ts +10 -8
- package/esm/components/use-datepicker/use-time.d.ts.map +1 -1
- package/esm/components/use-datepicker/use-time.js +19 -5
- package/esm/components/use-datepicker/use-time.type.d.ts +5 -1
- package/esm/components/use-datepicker/use-time.type.d.ts.map +1 -1
- package/esm/components/use-datepicker/util.d.ts.map +1 -1
- package/esm/components/use-datepicker/util.js +10 -1
- package/esm/components/use-form/Provider.d.ts.map +1 -1
- package/esm/components/use-form/Provider.js +7 -2
- package/esm/components/use-form/form-schema-context.d.ts +6 -0
- package/esm/components/use-form/form-schema-context.d.ts.map +1 -0
- package/esm/components/use-form/form-schema-context.js +8 -0
- package/esm/components/use-form/index.d.ts +2 -0
- package/esm/components/use-form/index.d.ts.map +1 -1
- package/esm/components/use-form/index.js +3 -1
- package/esm/components/use-form/use-form-context.type.d.ts +6 -0
- package/esm/components/use-form/use-form-context.type.d.ts.map +1 -1
- package/esm/components/use-form/use-form-control/use-form-control.d.ts.map +1 -1
- package/esm/components/use-form/use-form-control/use-form-control.js +34 -4
- package/esm/components/use-form/use-form-control/use-form-control.type.d.ts +8 -2
- package/esm/components/use-form/use-form-control/use-form-control.type.d.ts.map +1 -1
- package/esm/components/use-form/use-form-flow/use-form-datum.d.ts +8 -0
- package/esm/components/use-form/use-form-flow/use-form-datum.d.ts.map +1 -1
- package/esm/components/use-form/use-form-item/form-item-context.d.ts +1 -0
- package/esm/components/use-form/use-form-item/form-item-context.d.ts.map +1 -1
- package/esm/components/use-form/use-form-item/form-item-context.js +2 -1
- package/esm/components/use-form/use-form-item/index.d.ts +1 -0
- package/esm/components/use-form/use-form-item/index.d.ts.map +1 -1
- package/esm/components/use-form/use-form-item/index.js +2 -1
- package/esm/components/use-form/use-form-item/use-form-item.d.ts +1 -1
- package/esm/components/use-form/use-form-schema/form-schema-builder.d.ts +50 -0
- package/esm/components/use-form/use-form-schema/form-schema-builder.d.ts.map +1 -0
- package/esm/components/use-form/use-form-schema/form-schema-builder.js +371 -0
- package/esm/components/use-form/use-form-schema/index.d.ts +3 -0
- package/esm/components/use-form/use-form-schema/index.d.ts.map +1 -0
- package/esm/components/use-form/use-form-schema/index.js +2 -0
- package/esm/components/use-form/use-form.d.ts +4 -0
- package/esm/components/use-form/use-form.d.ts.map +1 -1
- package/esm/components/use-form/use-form.js +19 -9
- package/esm/components/use-form/use-form.type.d.ts +46 -39
- package/esm/components/use-form/use-form.type.d.ts.map +1 -1
- package/esm/components/use-input/use-input-number.d.ts.map +1 -1
- package/esm/components/use-input/use-input-number.js +3 -1
- package/esm/components/use-input/use-input-number.type.d.ts +1 -1
- package/esm/components/use-input/use-input-number.type.d.ts.map +1 -1
- package/esm/components/use-input/use-input.d.ts.map +1 -1
- package/esm/components/use-input/use-input.js +4 -1
- package/esm/components/use-pagination/use-pagination.d.ts.map +1 -1
- package/esm/components/use-pagination/use-pagination.js +2 -1
- package/esm/components/use-popup/use-popup.d.ts.map +1 -1
- package/esm/components/use-popup/use-popup.js +12 -24
- package/esm/components/use-select/use-select.type.d.ts +27 -18
- package/esm/components/use-select/use-select.type.d.ts.map +1 -1
- package/esm/components/use-table/use-table-virtual.d.ts +6 -1
- package/esm/components/use-table/use-table-virtual.d.ts.map +1 -1
- package/esm/components/use-table/use-table-virtual.js +5 -4
- package/esm/components/use-table/use-table.type.d.ts +70 -92
- package/esm/components/use-table/use-table.type.d.ts.map +1 -1
- package/esm/components/use-tree/use-tree-node.d.ts +7 -1
- package/esm/components/use-tree/use-tree-node.d.ts.map +1 -1
- package/esm/components/use-tree/use-tree-node.js +19 -1
- package/esm/components/use-tree/use-tree.d.ts.map +1 -1
- package/esm/components/use-tree/use-tree.js +26 -19
- package/esm/components/use-tree/use-tree.type.d.ts +7 -1
- package/esm/components/use-tree/use-tree.type.d.ts.map +1 -1
- package/esm/utils/dom/document.d.ts +4 -0
- package/esm/utils/dom/document.d.ts.map +1 -1
- package/esm/utils/dom/document.js +18 -1
- package/esm/utils/dom/element.d.ts +1 -0
- package/esm/utils/dom/element.d.ts.map +1 -1
- package/esm/utils/dom/element.js +4 -0
- package/esm/utils/highlight.d.ts.map +1 -1
- package/esm/utils/highlight.js +24 -10
- package/esm/utils/lazyload.d.ts.map +1 -1
- package/esm/utils/lazyload.js +33 -1
- package/esm/utils/object.d.ts +6 -0
- package/esm/utils/object.d.ts.map +1 -1
- package/esm/utils/object.js +20 -0
- package/package.json +3 -3
@@ -48,7 +48,8 @@ export default function useFormControl(props) {
|
|
48
48
|
defaultValue = props.defaultValue,
|
49
49
|
rules = props.rules,
|
50
50
|
onError = props.onError,
|
51
|
-
getValidateProps = props.getValidateProps
|
51
|
+
getValidateProps = props.getValidateProps,
|
52
|
+
clearToUndefined = props.clearToUndefined;
|
52
53
|
var _useFieldSetConsumer = useFieldSetConsumer({
|
53
54
|
name: props.name,
|
54
55
|
bind: props.bind
|
@@ -95,7 +96,9 @@ export default function useFormControl(props) {
|
|
95
96
|
var errors = arguments.length > 1 ? arguments[1] : undefined;
|
96
97
|
var severErrors = arguments.length > 2 ? arguments[2] : undefined;
|
97
98
|
if (!name) return;
|
98
|
-
|
99
|
+
// 加入defaultValue的判断,让其只对 https://github.com/sheinsight/shineout-next/pull/742 的场景生效
|
100
|
+
// 如果不加入defaultValue的判断,会导致 8ea43144-36a5-403a-9147-59d54087a110 的问题
|
101
|
+
if (isArray(name) && defaultValue !== undefined) {
|
99
102
|
var _value = getValue(name, formValue);
|
100
103
|
var _error = getError(name, errors, severErrors);
|
101
104
|
if (_error !== errorState) {
|
@@ -106,7 +109,11 @@ export default function useFormControl(props) {
|
|
106
109
|
var nextValue = [];
|
107
110
|
name.forEach(function (n, index) {
|
108
111
|
if (_value[index] === undefined && dv[index] !== undefined) {
|
109
|
-
|
112
|
+
if (clearToUndefined) {
|
113
|
+
nextValue[index] = undefined;
|
114
|
+
} else {
|
115
|
+
nextValue[index] = dv[index];
|
116
|
+
}
|
110
117
|
} else {
|
111
118
|
nextValue[index] = _value[index];
|
112
119
|
}
|
@@ -120,7 +127,11 @@ export default function useFormControl(props) {
|
|
120
127
|
}
|
121
128
|
if (!shallowEqual(_value2, latestInfo.valueState)) {
|
122
129
|
if (_value2 === undefined && defaultValue !== undefined) {
|
123
|
-
|
130
|
+
if (clearToUndefined) {
|
131
|
+
setValueState(undefined);
|
132
|
+
} else {
|
133
|
+
setValueState(defaultValue);
|
134
|
+
}
|
124
135
|
} else {
|
125
136
|
setValueState(_value2);
|
126
137
|
}
|
@@ -213,8 +224,27 @@ export default function useFormControl(props) {
|
|
213
224
|
if (onChangePo) onChangePo.apply(void 0, [v].concat(other));
|
214
225
|
if (validateFieldSet) validateFieldSet();
|
215
226
|
});
|
227
|
+
var initError = usePersistFn(function () {
|
228
|
+
var errors = formFunc === null || formFunc === void 0 ? void 0 : formFunc.getErrors();
|
229
|
+
if (isArray(name)) {
|
230
|
+
for (var i = 0; i < name.length; i++) {
|
231
|
+
var n = name[i];
|
232
|
+
var currentErrorInForm = errors === null || errors === void 0 ? void 0 : errors[n];
|
233
|
+
if (currentErrorInForm) {
|
234
|
+
setErrorState(currentErrorInForm);
|
235
|
+
break;
|
236
|
+
}
|
237
|
+
}
|
238
|
+
} else {
|
239
|
+
var _currentErrorInForm = errors === null || errors === void 0 ? void 0 : errors[name];
|
240
|
+
if (_currentErrorInForm) {
|
241
|
+
setErrorState(_currentErrorInForm);
|
242
|
+
}
|
243
|
+
}
|
244
|
+
});
|
216
245
|
useEffect(function () {
|
217
246
|
if (inForm && controlFunc) {
|
247
|
+
initError();
|
218
248
|
if (isArray(name)) {
|
219
249
|
var dv = isArray(defaultValue) ? defaultValue : [];
|
220
250
|
name.forEach(function (n, index) {
|
@@ -24,14 +24,20 @@ export interface BaseFormControlProps<T> {
|
|
24
24
|
*/
|
25
25
|
onError: ((error: Error | undefined) => void) | undefined;
|
26
26
|
/**
|
27
|
-
* @en
|
28
|
-
* @cn
|
27
|
+
* @en Array of field names that should be re-validated when current field's value changes. Enables field linkage validation for dependent fields. Commonly used in scenarios like password confirmation, related dropdown selections, or interdependent form calculations
|
28
|
+
* @cn 当前字段值改变时需要重新校验的字段名称数组。启用字段间的联动校验功能。常用于密码确认、关联下拉选择或相互依赖的表单计算等场景
|
29
29
|
*/
|
30
30
|
bind: string[] | undefined;
|
31
31
|
/**
|
32
32
|
* @private 内部属性 for validate
|
33
33
|
*/
|
34
34
|
getValidateProps: (() => ObjectType) | undefined;
|
35
|
+
/**
|
36
|
+
* @en If set to true, the form will not automatically delete the data after the component is uninstalled
|
37
|
+
* @cn 设置为 true 组件后,有defaultValue时,允许undefined作为最终值
|
38
|
+
* @version 3.8.0
|
39
|
+
*/
|
40
|
+
clearToUndefined?: boolean;
|
35
41
|
}
|
36
42
|
export interface FormControlContext {
|
37
43
|
mounted: boolean;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"use-form-control.type.d.ts","sourceRoot":"","sources":["use-form-control.type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAE7D,MAAM,WAAW,oBAAoB,CAAC,CAAC;IACrC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACxB;;;OAGG;IACH,YAAY,EAAE,CAAC,GAAG,SAAS,CAAC;IAC5B,QAAQ,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,GAAG,KAAK,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;IAC5D;;;OAGG;IACH,WAAW,EAAE,OAAO,GAAG,SAAS,CAAC;IACjC;;;;OAIG;IACH,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;IACnC;;OAEG;IACH,OAAO,EAAE,CAAC,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;IAC1D;;;OAGG;IACH,IAAI,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IAC3B;;OAEG;IACH,gBAAgB,EAAE,CAAC,MAAM,UAAU,CAAC,GAAG,SAAS,CAAC;
|
1
|
+
{"version":3,"file":"use-form-control.type.d.ts","sourceRoot":"","sources":["use-form-control.type.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAE7D,MAAM,WAAW,oBAAoB,CAAC,CAAC;IACrC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACxB;;;OAGG;IACH,YAAY,EAAE,CAAC,GAAG,SAAS,CAAC;IAC5B,QAAQ,EAAE,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,GAAG,KAAK,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;IAC5D;;;OAGG;IACH,WAAW,EAAE,OAAO,GAAG,SAAS,CAAC;IACjC;;;;OAIG;IACH,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC;IACnC;;OAEG;IACH,OAAO,EAAE,CAAC,CAAC,KAAK,EAAE,KAAK,GAAG,SAAS,KAAK,IAAI,CAAC,GAAG,SAAS,CAAC;IAC1D;;;OAGG;IACH,IAAI,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IAC3B;;OAEG;IACH,gBAAgB,EAAE,CAAC,MAAM,UAAU,CAAC,GAAG,SAAS,CAAC;IAEjD;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,OAAO,CAAC;CAClB"}
|
@@ -1,7 +1,15 @@
|
|
1
1
|
export interface FormDatum {
|
2
|
+
/**
|
3
|
+
* @en Set form field values. Accepts either an object to set multiple fields at once, or a field name with value to set a single field. Field names support nested paths like "user.name" or "items[0].price". Changes trigger form validation and re-render of affected Flow components
|
4
|
+
* @cn 设置表单字段值。可以接收对象以批量设置多个字段,或接收字段名和值以设置单个字段。字段名支持嵌套路径如 "user.name" 或 "items[0].price"。更改会触发表单校验和相关 Flow 组件的重新渲染
|
5
|
+
*/
|
2
6
|
set: (vals: {
|
3
7
|
[name: string]: any;
|
4
8
|
} | string, value?: any) => void;
|
9
|
+
/**
|
10
|
+
* @en Get form field value by name. When no name is provided, returns the entire form data object. Supports nested paths like "user.name" or "items[0].price" to access deeply nested values
|
11
|
+
* @cn 根据名称获取表单字段值。未提供名称时返回整个表单数据对象。支持嵌套路径如 "user.name" 或 "items[0].price" 来访问深层嵌套的值
|
12
|
+
*/
|
5
13
|
get: (name?: string) => any;
|
6
14
|
}
|
7
15
|
declare const useFormDatum: () => FormDatum | undefined;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"use-form-datum.d.ts","sourceRoot":"","sources":["use-form-datum.tsx"],"names":[],"mappings":"AAIA,MAAM,WAAW,SAAS;IACxB,GAAG,EAAE,CAAC,IAAI,EAAE;QAAE,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,GAAG,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG,KAAK,IAAI,CAAC;IACnE,GAAG,EAAE,CAAC,IAAI,CAAC,EAAE,MAAM,KAAK,GAAG,CAAC;CAC7B;AAED,QAAA,MAAM,YAAY,6BAgBjB,CAAC;AAEF,eAAe,YAAY,CAAC"}
|
1
|
+
{"version":3,"file":"use-form-datum.d.ts","sourceRoot":"","sources":["use-form-datum.tsx"],"names":[],"mappings":"AAIA,MAAM,WAAW,SAAS;IACxB;;;OAGG;IACH,GAAG,EAAE,CAAC,IAAI,EAAE;QAAE,CAAC,IAAI,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,GAAG,MAAM,EAAE,KAAK,CAAC,EAAE,GAAG,KAAK,IAAI,CAAC;IACnE;;;OAGG;IACH,GAAG,EAAE,CAAC,IAAI,CAAC,EAAE,MAAM,KAAK,GAAG,CAAC;CAC7B;AAED,QAAA,MAAM,YAAY,6BAgBjB,CAAC;AAEF,eAAe,YAAY,CAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"form-item-context.d.ts","sourceRoot":"","sources":["form-item-context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,MAAM,WAAW,wBAAwB;IACvC,WAAW,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,KAAK,IAAI,CAAC;CACpD;AAED,eAAO,MAAM,eAAe,yCAE1B,CAAC"}
|
1
|
+
{"version":3,"file":"form-item-context.d.ts","sourceRoot":"","sources":["form-item-context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,MAAM,WAAW,wBAAwB;IACvC,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,WAAW,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK,KAAK,IAAI,CAAC;CACpD;AAED,eAAO,MAAM,eAAe,yCAE1B,CAAC"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,iBAAiB,CAAC"}
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC"}
|
@@ -3,7 +3,7 @@ import type { FormItemContextValueType } from './form-item-context';
|
|
3
3
|
declare const UseFormItem: () => {
|
4
4
|
Provider: React.Provider<FormItemContextValueType>;
|
5
5
|
ProviderValue: FormItemContextValueType;
|
6
|
-
errors:
|
6
|
+
errors: Error[];
|
7
7
|
labelConfig: import("..").FormCommonConfig;
|
8
8
|
attributes: Record<string, string>;
|
9
9
|
showError: boolean;
|
@@ -0,0 +1,50 @@
|
|
1
|
+
interface SchemaMeta {
|
2
|
+
type?: string;
|
3
|
+
required?: boolean;
|
4
|
+
title?: string;
|
5
|
+
format?: string;
|
6
|
+
items?: any;
|
7
|
+
enum?: any[] | {
|
8
|
+
anyOf?: any[];
|
9
|
+
oneOf?: any[];
|
10
|
+
};
|
11
|
+
description?: string;
|
12
|
+
[key: string]: any;
|
13
|
+
}
|
14
|
+
export interface SchemaProperty {
|
15
|
+
type?: string;
|
16
|
+
properties?: Record<string, SchemaProperty>;
|
17
|
+
items?: SchemaProperty;
|
18
|
+
required?: string[];
|
19
|
+
title?: string;
|
20
|
+
description?: string;
|
21
|
+
format?: string;
|
22
|
+
enum?: any;
|
23
|
+
[key: string]: any;
|
24
|
+
}
|
25
|
+
export declare class SchemaBuilder {
|
26
|
+
private schema;
|
27
|
+
constructor(formName: string);
|
28
|
+
updateSchema({ path, meta }: {
|
29
|
+
path: string;
|
30
|
+
meta: SchemaMeta;
|
31
|
+
}): void;
|
32
|
+
/**
|
33
|
+
* 根据组件信息构建 schema meta
|
34
|
+
*/
|
35
|
+
buildSchemaFromComponent(params: {
|
36
|
+
componentElement: any;
|
37
|
+
rules?: any[];
|
38
|
+
label?: string;
|
39
|
+
finalFieldId?: string;
|
40
|
+
separator?: string;
|
41
|
+
}): SchemaMeta;
|
42
|
+
parsePath(path?: string): string[] | null;
|
43
|
+
mergeSchema(currentSchema: SchemaProperty, pathSegments: string[], meta: SchemaMeta): void;
|
44
|
+
handleArraySegment(currentSchema: SchemaProperty, remainingSegments: string[], meta: SchemaMeta): void;
|
45
|
+
handleObjectProperty(currentSchema: SchemaProperty, propertyName: string, remainingSegments: string[], meta: SchemaMeta): void;
|
46
|
+
handleRequired(parentSchema: SchemaProperty, propertyName: string, isRequired: boolean): void;
|
47
|
+
getFormSchema(): SchemaProperty;
|
48
|
+
}
|
49
|
+
export {};
|
50
|
+
//# sourceMappingURL=form-schema-builder.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"form-schema-builder.d.ts","sourceRoot":"","sources":["form-schema-builder.ts"],"names":[],"mappings":"AAAA,UAAU,UAAU;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,IAAI,CAAC,EAAE,GAAG,EAAE,GAAG;QAAE,KAAK,CAAC,EAAE,GAAG,EAAE,CAAC;QAAC,KAAK,CAAC,EAAE,GAAG,EAAE,CAAA;KAAE,CAAC;IAChD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAC5C,KAAK,CAAC,EAAE,cAAc,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAiB;gBACnB,QAAQ,EAAE,MAAM;IAQ5B,YAAY,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,UAAU,CAAA;KAAE,GAAG,IAAI;IAMtE;;OAEG;IACH,wBAAwB,CAAC,MAAM,EAAE;QAC/B,gBAAgB,EAAE,GAAG,CAAC;QACtB,KAAK,CAAC,EAAE,GAAG,EAAE,CAAC;QACd,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,GAAG,UAAU;IAuLd,SAAS,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI;IAuCzC,WAAW,CAAC,aAAa,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,UAAU,GAAG,IAAI;IAkB1F,kBAAkB,CAAC,aAAa,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,UAAU,GAAG,IAAI;IAatG,oBAAoB,CAAC,aAAa,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,UAAU,GAAG,IAAI;IA0B9H,cAAc,CAAC,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,GAAG,IAAI;IAwB7F,aAAa,IAAI,cAAc;CAGhC"}
|
@@ -0,0 +1,371 @@
|
|
1
|
+
var _excluded = ["required"];
|
2
|
+
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
3
|
+
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
4
|
+
function _toArray(arr) { return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest(); }
|
5
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
6
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
7
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
8
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
9
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
10
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
11
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
12
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
13
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
14
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
15
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
16
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
17
|
+
export var SchemaBuilder = /*#__PURE__*/function () {
|
18
|
+
function SchemaBuilder(formName) {
|
19
|
+
_classCallCheck(this, SchemaBuilder);
|
20
|
+
_defineProperty(this, "schema", void 0);
|
21
|
+
this.schema = {
|
22
|
+
type: 'object',
|
23
|
+
title: formName,
|
24
|
+
properties: {}
|
25
|
+
};
|
26
|
+
}
|
27
|
+
_createClass(SchemaBuilder, [{
|
28
|
+
key: "updateSchema",
|
29
|
+
value: function updateSchema(_ref) {
|
30
|
+
var path = _ref.path,
|
31
|
+
meta = _ref.meta;
|
32
|
+
var pathSegments = this.parsePath(path);
|
33
|
+
if (!pathSegments) return;
|
34
|
+
this.mergeSchema(this.schema, pathSegments, meta);
|
35
|
+
}
|
36
|
+
|
37
|
+
/**
|
38
|
+
* 根据组件信息构建 schema meta
|
39
|
+
*/
|
40
|
+
}, {
|
41
|
+
key: "buildSchemaFromComponent",
|
42
|
+
value: function buildSchemaFromComponent(params) {
|
43
|
+
var _componentElement$pro;
|
44
|
+
var componentElement = params.componentElement,
|
45
|
+
rules = params.rules,
|
46
|
+
label = params.label,
|
47
|
+
finalFieldId = params.finalFieldId,
|
48
|
+
separator = params.separator;
|
49
|
+
var fieldSchemaInfo = {
|
50
|
+
title: label
|
51
|
+
};
|
52
|
+
var data = componentElement.props.data;
|
53
|
+
var isRequired = rules === null || rules === void 0 ? void 0 : rules.some(function (rule) {
|
54
|
+
return rule.required;
|
55
|
+
});
|
56
|
+
fieldSchemaInfo.required = isRequired;
|
57
|
+
fieldSchemaInfo.description = '';
|
58
|
+
if (rules !== null && rules !== void 0 && rules.length) {
|
59
|
+
var messageRules = rules.filter(function (rule) {
|
60
|
+
return typeof rule.message === 'string';
|
61
|
+
});
|
62
|
+
if (messageRules.length) {
|
63
|
+
fieldSchemaInfo.description += "rules: ".concat(messageRules.map(function (rule) {
|
64
|
+
return rule.message;
|
65
|
+
}).join(', '), ";");
|
66
|
+
}
|
67
|
+
}
|
68
|
+
var itemType;
|
69
|
+
if (typeof componentElement.type === 'function') {
|
70
|
+
var componentName = componentElement.type.displayName || componentElement.type.name;
|
71
|
+
var format = componentElement.props.format || componentElement.props.keygen;
|
72
|
+
switch (componentName) {
|
73
|
+
case 'ShineoutInput':
|
74
|
+
case 'ShineoutEditableArea':
|
75
|
+
fieldSchemaInfo.type = 'string';
|
76
|
+
break;
|
77
|
+
case 'ShineoutInputNumber':
|
78
|
+
fieldSchemaInfo.type = 'number';
|
79
|
+
break;
|
80
|
+
case 'ShineoutInputPassword':
|
81
|
+
fieldSchemaInfo.type = 'string';
|
82
|
+
break;
|
83
|
+
case 'ShineoutTextarea':
|
84
|
+
fieldSchemaInfo.type = 'string';
|
85
|
+
break;
|
86
|
+
case 'ShineoutCascader':
|
87
|
+
case 'ShineoutSelect':
|
88
|
+
case 'ShineoutTreeSelect':
|
89
|
+
{
|
90
|
+
if (typeof componentElement.props.keygen !== 'boolean') {
|
91
|
+
if (typeof format === 'string') {
|
92
|
+
var _data$;
|
93
|
+
itemType = _typeof(data === null || data === void 0 ? void 0 : data[0]) === 'object' ? _typeof(data === null || data === void 0 || (_data$ = data[0]) === null || _data$ === void 0 ? void 0 : _data$[format]) : _typeof(data === null || data === void 0 ? void 0 : data[0]);
|
94
|
+
} else if (typeof format === 'function') {
|
95
|
+
itemType = _typeof(format(data === null || data === void 0 ? void 0 : data[0]));
|
96
|
+
} else {
|
97
|
+
itemType = _typeof(data === null || data === void 0 ? void 0 : data[0]);
|
98
|
+
}
|
99
|
+
} else {
|
100
|
+
itemType = _typeof(data === null || data === void 0 ? void 0 : data[0]);
|
101
|
+
}
|
102
|
+
if (componentElement.props.multiple) {
|
103
|
+
fieldSchemaInfo.type = 'array';
|
104
|
+
if (itemType !== 'undefined') {
|
105
|
+
fieldSchemaInfo.items = {
|
106
|
+
type: itemType
|
107
|
+
};
|
108
|
+
}
|
109
|
+
} else {
|
110
|
+
if (itemType !== 'undefined') {
|
111
|
+
fieldSchemaInfo.type = itemType;
|
112
|
+
}
|
113
|
+
}
|
114
|
+
if (itemType === 'object') {
|
115
|
+
// 对于对象类型,使用 oneOf 而不是 enum
|
116
|
+
if (componentElement.props.multiple) {
|
117
|
+
fieldSchemaInfo.items.oneOf = componentElement.props.data.map(function (item) {
|
118
|
+
return {
|
119
|
+
const: item,
|
120
|
+
title: (item === null || item === void 0 ? void 0 : item.title) || JSON.stringify(item)
|
121
|
+
};
|
122
|
+
});
|
123
|
+
} else {
|
124
|
+
fieldSchemaInfo.oneOf = componentElement.props.data.map(function (item) {
|
125
|
+
return {
|
126
|
+
const: item,
|
127
|
+
title: (item === null || item === void 0 ? void 0 : item.title) || JSON.stringify(item)
|
128
|
+
};
|
129
|
+
});
|
130
|
+
}
|
131
|
+
} else {
|
132
|
+
fieldSchemaInfo.enum = componentElement.props.data.map(function (item) {
|
133
|
+
return (item === null || item === void 0 ? void 0 : item[format]) || item;
|
134
|
+
});
|
135
|
+
}
|
136
|
+
break;
|
137
|
+
}
|
138
|
+
case 'ShineoutDatePicker':
|
139
|
+
if (componentElement.props.range) {
|
140
|
+
if (finalFieldId !== null && finalFieldId !== void 0 && finalFieldId.includes(separator || '')) {
|
141
|
+
fieldSchemaInfo.type = 'string';
|
142
|
+
fieldSchemaInfo.format = 'date';
|
143
|
+
} else {
|
144
|
+
fieldSchemaInfo.type = 'array';
|
145
|
+
fieldSchemaInfo.items = {
|
146
|
+
type: 'string',
|
147
|
+
format: 'date'
|
148
|
+
};
|
149
|
+
}
|
150
|
+
} else {
|
151
|
+
fieldSchemaInfo.type = 'string';
|
152
|
+
fieldSchemaInfo.format = 'date';
|
153
|
+
}
|
154
|
+
fieldSchemaInfo.description += "\u9ED8\u8BA4\u65F6\u95F4\uFF1A".concat(((_componentElement$pro = componentElement.props.defaultTime) === null || _componentElement$pro === void 0 ? void 0 : _componentElement$pro.toString()) || '', "; \u683C\u5F0F\uFF1A").concat(componentElement.props.format || '', " ");
|
155
|
+
break;
|
156
|
+
case 'ShineoutCheckbox':
|
157
|
+
case 'ShineoutCheckboxGroup':
|
158
|
+
{
|
159
|
+
if (typeof componentElement.props.keygen !== 'boolean') {
|
160
|
+
if (typeof format === 'string') {
|
161
|
+
var _data$2;
|
162
|
+
itemType = _typeof(data === null || data === void 0 ? void 0 : data[0]) === 'object' ? _typeof(data === null || data === void 0 || (_data$2 = data[0]) === null || _data$2 === void 0 ? void 0 : _data$2[format]) : _typeof(data === null || data === void 0 ? void 0 : data[0]);
|
163
|
+
} else if (typeof format === 'function') {
|
164
|
+
itemType = _typeof(format(data === null || data === void 0 ? void 0 : data[0]));
|
165
|
+
} else {
|
166
|
+
itemType = _typeof(data === null || data === void 0 ? void 0 : data[0]);
|
167
|
+
}
|
168
|
+
} else {
|
169
|
+
itemType = _typeof(data === null || data === void 0 ? void 0 : data[0]);
|
170
|
+
}
|
171
|
+
fieldSchemaInfo.type = 'array';
|
172
|
+
fieldSchemaInfo.items = {
|
173
|
+
type: itemType
|
174
|
+
};
|
175
|
+
|
176
|
+
// ShineoutCheckboxGroup 有 data 时(多选的)
|
177
|
+
if (itemType === 'object') {
|
178
|
+
fieldSchemaInfo.items.oneOf = componentElement.props.data.map(function (item) {
|
179
|
+
return {
|
180
|
+
const: item,
|
181
|
+
title: (item === null || item === void 0 ? void 0 : item.title) || JSON.stringify(item)
|
182
|
+
};
|
183
|
+
});
|
184
|
+
} else {
|
185
|
+
fieldSchemaInfo.items.enum = componentElement.props.data.map(function (item) {
|
186
|
+
return (item === null || item === void 0 ? void 0 : item[format]) || item;
|
187
|
+
});
|
188
|
+
}
|
189
|
+
break;
|
190
|
+
}
|
191
|
+
case 'ShineoutRadio':
|
192
|
+
case 'ShineoutRadioGroup':
|
193
|
+
{
|
194
|
+
if (typeof componentElement.props.keygen !== 'boolean') {
|
195
|
+
if (typeof format === 'string') {
|
196
|
+
var _data$3;
|
197
|
+
itemType = _typeof(data === null || data === void 0 ? void 0 : data[0]) === 'object' ? _typeof(data === null || data === void 0 || (_data$3 = data[0]) === null || _data$3 === void 0 ? void 0 : _data$3[format]) : _typeof(data === null || data === void 0 ? void 0 : data[0]);
|
198
|
+
} else if (typeof format === 'function') {
|
199
|
+
itemType = _typeof(format(data === null || data === void 0 ? void 0 : data[0]));
|
200
|
+
} else {
|
201
|
+
itemType = _typeof(data === null || data === void 0 ? void 0 : data[0]);
|
202
|
+
}
|
203
|
+
} else {
|
204
|
+
itemType = _typeof(data === null || data === void 0 ? void 0 : data[0]);
|
205
|
+
}
|
206
|
+
fieldSchemaInfo.type = itemType;
|
207
|
+
|
208
|
+
// ShineoutRadioGroup 有 data 时(单选的)
|
209
|
+
if (itemType === 'object') {
|
210
|
+
fieldSchemaInfo.oneOf = componentElement.props.data.map(function (item) {
|
211
|
+
return {
|
212
|
+
const: item,
|
213
|
+
title: (item === null || item === void 0 ? void 0 : item.title) || JSON.stringify(item)
|
214
|
+
};
|
215
|
+
});
|
216
|
+
} else {
|
217
|
+
fieldSchemaInfo.enum = componentElement.props.data.map(function (item) {
|
218
|
+
return (item === null || item === void 0 ? void 0 : item[format]) || item;
|
219
|
+
});
|
220
|
+
}
|
221
|
+
break;
|
222
|
+
}
|
223
|
+
case 'ShineoutSwitch':
|
224
|
+
fieldSchemaInfo.type = 'boolean';
|
225
|
+
break;
|
226
|
+
case 'ShineoutSlider':
|
227
|
+
case 'ShineoutRate':
|
228
|
+
fieldSchemaInfo.type = 'number';
|
229
|
+
break;
|
230
|
+
default:
|
231
|
+
if (Array.isArray(componentElement.props.value) && componentElement.props.value.length === 0) {
|
232
|
+
fieldSchemaInfo.type = 'array';
|
233
|
+
fieldSchemaInfo.items = {
|
234
|
+
type: 'string'
|
235
|
+
};
|
236
|
+
} else {
|
237
|
+
fieldSchemaInfo.type = _typeof(componentElement.props.value);
|
238
|
+
}
|
239
|
+
break;
|
240
|
+
}
|
241
|
+
}
|
242
|
+
return fieldSchemaInfo;
|
243
|
+
}
|
244
|
+
|
245
|
+
// 解析路径字符串,如 'a[0].b1' -> ['a', '[0]', 'b1']
|
246
|
+
}, {
|
247
|
+
key: "parsePath",
|
248
|
+
value: function parsePath(path) {
|
249
|
+
if (!path) return null;
|
250
|
+
var segments = [];
|
251
|
+
var current = '';
|
252
|
+
var inBracket = false;
|
253
|
+
for (var i = 0; i < path.length; i++) {
|
254
|
+
var char = path[i];
|
255
|
+
if (char === '[') {
|
256
|
+
if (current) {
|
257
|
+
segments.push(current);
|
258
|
+
current = '';
|
259
|
+
}
|
260
|
+
current = '[';
|
261
|
+
inBracket = true;
|
262
|
+
} else if (char === ']') {
|
263
|
+
current += ']';
|
264
|
+
segments.push(current);
|
265
|
+
current = '';
|
266
|
+
inBracket = false;
|
267
|
+
} else if (char === '.' && !inBracket) {
|
268
|
+
if (current) {
|
269
|
+
segments.push(current);
|
270
|
+
current = '';
|
271
|
+
}
|
272
|
+
} else {
|
273
|
+
current += char;
|
274
|
+
}
|
275
|
+
}
|
276
|
+
if (current) {
|
277
|
+
segments.push(current);
|
278
|
+
}
|
279
|
+
return segments;
|
280
|
+
}
|
281
|
+
|
282
|
+
// 递归合并 schema
|
283
|
+
}, {
|
284
|
+
key: "mergeSchema",
|
285
|
+
value: function mergeSchema(currentSchema, pathSegments, meta) {
|
286
|
+
if (pathSegments.length === 0) {
|
287
|
+
// 到达叶子节点,应用元数据
|
288
|
+
Object.assign(currentSchema, meta);
|
289
|
+
return;
|
290
|
+
}
|
291
|
+
var _pathSegments = _toArray(pathSegments),
|
292
|
+
currentSegment = _pathSegments[0],
|
293
|
+
remainingSegments = _pathSegments.slice(1);
|
294
|
+
if (currentSegment.startsWith('[') && currentSegment.endsWith(']')) {
|
295
|
+
// 处理数组索引,如 [0]
|
296
|
+
this.handleArraySegment(currentSchema, remainingSegments, meta);
|
297
|
+
} else {
|
298
|
+
// 处理对象属性
|
299
|
+
this.handleObjectProperty(currentSchema, currentSegment, remainingSegments, meta);
|
300
|
+
}
|
301
|
+
}
|
302
|
+
}, {
|
303
|
+
key: "handleArraySegment",
|
304
|
+
value: function handleArraySegment(currentSchema, remainingSegments, meta) {
|
305
|
+
// 当前节点应该是数组类型
|
306
|
+
if (!currentSchema.items) {
|
307
|
+
currentSchema.type = 'array';
|
308
|
+
currentSchema.items = {
|
309
|
+
type: 'object',
|
310
|
+
properties: {}
|
311
|
+
};
|
312
|
+
}
|
313
|
+
this.mergeSchema(currentSchema.items, remainingSegments, meta);
|
314
|
+
}
|
315
|
+
}, {
|
316
|
+
key: "handleObjectProperty",
|
317
|
+
value: function handleObjectProperty(currentSchema, propertyName, remainingSegments, meta) {
|
318
|
+
// 确保当前节点有 properties
|
319
|
+
if (!currentSchema.properties) {
|
320
|
+
currentSchema.properties = {};
|
321
|
+
}
|
322
|
+
|
323
|
+
// 如果属性不存在,创建它
|
324
|
+
if (!currentSchema.properties[propertyName]) {
|
325
|
+
currentSchema.properties[propertyName] = remainingSegments.length > 0 ? {
|
326
|
+
type: 'object'
|
327
|
+
} : {};
|
328
|
+
}
|
329
|
+
if (remainingSegments.length === 0) {
|
330
|
+
// 叶子节点,应用元数据并处理 required
|
331
|
+
var required = meta.required,
|
332
|
+
restMeta = _objectWithoutProperties(meta, _excluded);
|
333
|
+
Object.assign(currentSchema.properties[propertyName], restMeta);
|
334
|
+
if (typeof required === 'boolean') {
|
335
|
+
this.handleRequired(currentSchema, propertyName, required);
|
336
|
+
}
|
337
|
+
} else {
|
338
|
+
// 继续递归
|
339
|
+
this.mergeSchema(currentSchema.properties[propertyName], remainingSegments, meta);
|
340
|
+
}
|
341
|
+
}
|
342
|
+
}, {
|
343
|
+
key: "handleRequired",
|
344
|
+
value: function handleRequired(parentSchema, propertyName, isRequired) {
|
345
|
+
// 如果required是布尔值,转换为数组形式
|
346
|
+
if (typeof parentSchema.required === 'boolean') {
|
347
|
+
return;
|
348
|
+
}
|
349
|
+
if (!parentSchema.required) {
|
350
|
+
parentSchema.required = [];
|
351
|
+
}
|
352
|
+
var requiredIndex = parentSchema.required.indexOf(propertyName);
|
353
|
+
if (isRequired && requiredIndex === -1) {
|
354
|
+
parentSchema.required.push(propertyName);
|
355
|
+
} else if (!isRequired && requiredIndex !== -1) {
|
356
|
+
parentSchema.required.splice(requiredIndex, 1);
|
357
|
+
}
|
358
|
+
|
359
|
+
// 如果 required 数组为空,删除它
|
360
|
+
if (parentSchema.required.length === 0) {
|
361
|
+
delete parentSchema.required;
|
362
|
+
}
|
363
|
+
}
|
364
|
+
}, {
|
365
|
+
key: "getFormSchema",
|
366
|
+
value: function getFormSchema() {
|
367
|
+
return this.schema;
|
368
|
+
}
|
369
|
+
}]);
|
370
|
+
return SchemaBuilder;
|
371
|
+
}();
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,YAAY,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC"}
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import { SchemaBuilder } from './use-form-schema/form-schema-builder';
|
1
2
|
import { ProviderProps, UseFormProps, UseFormSlotProps, ValidateFnConfig } from './use-form.type';
|
2
3
|
import { ObjectType } from '../../common/type';
|
3
4
|
declare const useForm: <T extends ObjectType>(props: UseFormProps<T>) => {
|
@@ -24,7 +25,9 @@ declare const useForm: <T extends ObjectType>(props: UseFormProps<T>) => {
|
|
24
25
|
insertError: (name: string, index: number, error?: Error) => void;
|
25
26
|
spliceError: (name: string, index: number) => void;
|
26
27
|
scrollToField: (name: string, scrollIntoViewOptions?: ScrollIntoViewOptions) => void;
|
28
|
+
getFormSchema: () => import("./use-form-schema/form-schema-builder").SchemaProperty | undefined;
|
27
29
|
};
|
30
|
+
formSchema: SchemaBuilder | null;
|
28
31
|
};
|
29
32
|
formFunc: {
|
30
33
|
setValue: (vals: {
|
@@ -44,6 +47,7 @@ declare const useForm: <T extends ObjectType>(props: UseFormProps<T>) => {
|
|
44
47
|
insertError: (name: string, index: number, error?: Error) => void;
|
45
48
|
spliceError: (name: string, index: number) => void;
|
46
49
|
scrollToField: (name: string, scrollIntoViewOptions?: ScrollIntoViewOptions) => void;
|
50
|
+
getFormSchema: () => import("./use-form-schema/form-schema-builder").SchemaProperty | undefined;
|
47
51
|
};
|
48
52
|
};
|
49
53
|
export default useForm;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"use-form.d.ts","sourceRoot":"","sources":["use-form.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"use-form.d.ts","sourceRoot":"","sources":["use-form.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,aAAa,EAAE,MAAM,uCAAuC,CAAC;AA2BtE,OAAO,EAEL,aAAa,EACb,YAAY,EACZ,gBAAgB,EAGhB,gBAAgB,EAEjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAe,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI5D,QAAA,MAAM,OAAO;;;;;;;;;wBAySC;gBAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;gBAAC,WAAW,CAAC,EAAE,OAAO,CAAA;aAAE;8BAzPnB,MAAM;oCAwUD,OAAO,aAAoB,MAAM,IAAI;;6BAf3C,MAAM,KAAK,KAAK,GAAG,SAAS;;oCAdrB,MAAM,EAAE;sCAnSxC,MAAM,GAAG,MAAM,EAAE,WAAU,gBAAgB;qCAsWvB,MAAM,WAAW,gBAAgB;gCAhDzB,MAAM,SAAS,MAAM,UAAU,KAAK;gCAKpC,MAAM,SAAS,MAAM;kCAzJpD,MAAM,0BAAyB,qBAAqB;;;;;;;;oBA+EjD;YAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;YAAC,WAAW,CAAC,EAAE,OAAO,CAAA;SAAE;0BAzPnB,MAAM;gCAwUD,OAAO,aAAoB,MAAM,IAAI;;yBAf3C,MAAM,KAAK,KAAK,GAAG,SAAS;;gCAdrB,MAAM,EAAE;kCAnSxC,MAAM,GAAG,MAAM,EAAE,WAAU,gBAAgB;iCAsWvB,MAAM,WAAW,gBAAgB;4BAhDzB,MAAM,SAAS,MAAM,UAAU,KAAK;4BAKpC,MAAM,SAAS,MAAM;8BAzJpD,MAAM,0BAAyB,qBAAqB;;;CA4b9D,CAAC;AAEF,eAAe,OAAO,CAAC"}
|