@sheinx/hooks 3.8.0-beta.20 → 3.8.0-beta.22
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/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-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-schema/form-schema-builder.d.ts +49 -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 +311 -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 +10 -3
- package/cjs/components/use-form/use-form.type.d.ts +3 -0
- package/cjs/components/use-form/use-form.type.d.ts.map +1 -1
- 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/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-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-schema/form-schema-builder.d.ts +49 -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 +305 -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 +10 -3
- package/esm/components/use-form/use-form.type.d.ts +3 -0
- package/esm/components/use-form/use-form.type.d.ts.map +1 -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/package.json +1 -1
@@ -11,6 +11,7 @@ var _usePersistFn = _interopRequireDefault(require("../../common/use-persist-fn"
|
|
11
11
|
var _attribute = require("../../utils/attribute");
|
12
12
|
var _flat = require("../../utils/flat");
|
13
13
|
var _useDefaultValue = require("../../common/use-default-value");
|
14
|
+
var _formSchemaBuilder = require("./use-form-schema/form-schema-builder");
|
14
15
|
var _immer = require("../../utils/immer");
|
15
16
|
var _utils = require("../../utils");
|
16
17
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
@@ -71,7 +72,8 @@ var useForm = function useForm(props) {
|
|
71
72
|
resetTime: 0,
|
72
73
|
mounted: false,
|
73
74
|
unmounted: false,
|
74
|
-
removeLock: false
|
75
|
+
removeLock: false,
|
76
|
+
schema: props.name ? new _formSchemaBuilder.SchemaBuilder(props.name) : null
|
75
77
|
}),
|
76
78
|
context = _React$useRef.current;
|
77
79
|
var getValue = (0, _usePersistFn.default)(function (name) {
|
@@ -584,7 +586,11 @@ var useForm = function useForm(props) {
|
|
584
586
|
validateFieldset: validateFieldset,
|
585
587
|
insertError: insertError,
|
586
588
|
spliceError: spliceError,
|
587
|
-
scrollToField: scrollToField
|
589
|
+
scrollToField: scrollToField,
|
590
|
+
getFormSchema: function getFormSchema() {
|
591
|
+
var _context$schema;
|
592
|
+
return (_context$schema = context.schema) === null || _context$schema === void 0 ? void 0 : _context$schema.getFormSchema();
|
593
|
+
}
|
588
594
|
});
|
589
595
|
var formConfig = React.useMemo(function () {
|
590
596
|
return {
|
@@ -653,7 +659,8 @@ var useForm = function useForm(props) {
|
|
653
659
|
ProviderProps: {
|
654
660
|
formValue: formValue,
|
655
661
|
formConfig: formConfig,
|
656
|
-
formFunc: formFunc
|
662
|
+
formFunc: formFunc,
|
663
|
+
formSchema: context.schema
|
657
664
|
},
|
658
665
|
formFunc: formFunc
|
659
666
|
};
|
@@ -3,6 +3,7 @@ import { ReactNode } from 'react';
|
|
3
3
|
import { AddNoProps, ObjectType } from '../../common/type';
|
4
4
|
import { FormItemRule } from '../../utils/rule/rule.type';
|
5
5
|
import { FormError } from '../../utils';
|
6
|
+
import { SchemaBuilder } from './use-form-schema';
|
6
7
|
export type KeyType = string | number | symbol;
|
7
8
|
export interface ValidationError<T> {
|
8
9
|
values: T;
|
@@ -32,6 +33,7 @@ export interface ProviderProps {
|
|
32
33
|
formConfig: FormCommonConfig;
|
33
34
|
formValue: FormContextValueType;
|
34
35
|
formFunc: FormFunc;
|
36
|
+
formSchema: SchemaBuilder | null;
|
35
37
|
children?: ReactNode;
|
36
38
|
}
|
37
39
|
export interface FormLabelConfig {
|
@@ -220,6 +222,7 @@ export type FormContext = {
|
|
220
222
|
unmounted: boolean;
|
221
223
|
removeLock: boolean;
|
222
224
|
ignoreValidateFields: string[];
|
225
|
+
schema: SchemaBuilder | null;
|
223
226
|
};
|
224
227
|
export type UseFormSlotOwnProps = {
|
225
228
|
onSubmit: any;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"use-form.type.d.ts","sourceRoot":"","sources":["use-form.type.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;
|
1
|
+
{"version":3,"file":"use-form.type.d.ts","sourceRoot":"","sources":["use-form.type.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAElC,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,MAAM,MAAM,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;AAE/C,MAAM,WAAW,eAAe,CAAC,CAAC;IAChC,MAAM,EAAE,CAAC,CAAC;IACV,WAAW,EAAE;QACX,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,EAAE,MAAM,EAAE,CAAC;KAClB,EAAE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AC;IAEvB,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC;IACtC,KAAK,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;IACnB,UAAU,EAAE,OAAO,CAAC;IACpB,SAAS,EAAE,UAAU,GAAG,SAAS,CAAC;IAElC,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;IAEjB,SAAS,EAAE,UAAU,CACnB,GAAG,CACD,CACE,SAAS,EAAE,UAAU,EACrB,MAAM,EAAE,UAAU,CAAC,KAAK,GAAG,SAAS,CAAC,EACrC,YAAY,EAAE,UAAU,CAAC,KAAK,GAAG,SAAS,CAAC,KACxC,IAAI,CACV,CACF,CAAC;IAEF,OAAO,EAAE,UAAU,CAAC,GAAG,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC;IACrC,KAAK,EAAE,UAAU,CAAC;IAClB,MAAM,EAAE,UAAU,CAAC,KAAK,GAAG,SAAS,CAAC,CAAC;IACtC,YAAY,EAAE,UAAU,CAAC,KAAK,GAAG,SAAS,CAAC,CAAC;IAC5C,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,EAAE,OAAO,CAAC;IACpB,oBAAoB,EAAE,MAAM,EAAE,CAAC;IAC/B,MAAM,EAAE,aAAa,GAAG,IAAI,CAAC;CAC9B,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,QAAQ,EAAE,GAAG,CAAC;IACd,OAAO,EAAE,GAAG,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,gBAAgB,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,UAAU,CACzE,mBAAmB,EACnB,MAAM,CACP,CAAC"}
|
@@ -18,4 +18,5 @@ export declare function getClosestPositionedContainer(element: Element | HTMLEle
|
|
18
18
|
export declare function cssSupport(attr: keyof CSSStyleDeclaration, value: string): boolean;
|
19
19
|
export declare const parsePxToNumber: (str: string) => number;
|
20
20
|
export declare const getFieldId: (name?: string, formName?: string) => string | undefined;
|
21
|
+
export declare const getOriginField: (name?: string, formName?: string) => string;
|
21
22
|
//# sourceMappingURL=element.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"element.d.ts","sourceRoot":"","sources":["element.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAa1B;;;;;;GAMG;AACH,wBAAgB,QAAQ,CACtB,QAAQ,EAAE,KAAK,CAAC,SAAS,EACzB,WAAW,UAAQ,EACnB,SAAS,CAAC,EAAE,MAAM,GACjB,KAAK,CAAC,SAAS,CASjB;AAGD,eAAO,MAAM,iBAAiB,OACxB,WAAW,WACN,GAAG;;;gBA4Cb,CAAC;AAEF,wBAAgB,SAAS,CAAC,EAAE,EAAE,WAAW,GAAG,IAAI,GAAG,OAAO,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,WAAW,kBAmBxF;AAED,wBAAgB,YAAY,CAAC,EAAE,EAAE,WAAW,WAW3C;AAED,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI,GAAG,WAAW,GAAG,IAAI,CAqBzF;AAED,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,OAAO,GAAG,WAAW,GAAG,IAAI,EACrC,SAAS,GAAE,KAAK,CAAC,aAAa,CAAC,UAAU,CAAC,EAA0B,sBAuBrE;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,mBAAmB,EAAE,KAAK,EAAE,MAAM,WAYxE;AAED,eAAO,MAAM,eAAe,QAAS,MAAM,WAAwC,CAAC;AAEpF,eAAO,MAAM,UAAU,UAAW,MAAM,aAAa,MAAM,uBAG1D,CAAC"}
|
1
|
+
{"version":3,"file":"element.d.ts","sourceRoot":"","sources":["element.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAa1B;;;;;;GAMG;AACH,wBAAgB,QAAQ,CACtB,QAAQ,EAAE,KAAK,CAAC,SAAS,EACzB,WAAW,UAAQ,EACnB,SAAS,CAAC,EAAE,MAAM,GACjB,KAAK,CAAC,SAAS,CASjB;AAGD,eAAO,MAAM,iBAAiB,OACxB,WAAW,WACN,GAAG;;;gBA4Cb,CAAC;AAEF,wBAAgB,SAAS,CAAC,EAAE,EAAE,WAAW,GAAG,IAAI,GAAG,OAAO,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,WAAW,kBAmBxF;AAED,wBAAgB,YAAY,CAAC,EAAE,EAAE,WAAW,WAW3C;AAED,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI,GAAG,WAAW,GAAG,IAAI,CAqBzF;AAED,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,OAAO,GAAG,WAAW,GAAG,IAAI,EACrC,SAAS,GAAE,KAAK,CAAC,aAAa,CAAC,UAAU,CAAC,EAA0B,sBAuBrE;AAED,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,mBAAmB,EAAE,KAAK,EAAE,MAAM,WAYxE;AAED,eAAO,MAAM,eAAe,QAAS,MAAM,WAAwC,CAAC;AAEpF,eAAO,MAAM,UAAU,UAAW,MAAM,aAAa,MAAM,uBAG1D,CAAC;AAEF,eAAO,MAAM,cAAc,UAAW,MAAM,aAAa,MAAM,WAG9D,CAAC"}
|
package/cjs/utils/dom/element.js
CHANGED
@@ -7,7 +7,7 @@ exports.addResizeObserver = void 0;
|
|
7
7
|
exports.cssSupport = cssSupport;
|
8
8
|
exports.getClosestPositionedContainer = getClosestPositionedContainer;
|
9
9
|
exports.getClosestScrollContainer = getClosestScrollContainer;
|
10
|
-
exports.getFieldId = void 0;
|
10
|
+
exports.getOriginField = exports.getFieldId = void 0;
|
11
11
|
exports.getParent = getParent;
|
12
12
|
exports.isScrollable = isScrollable;
|
13
13
|
exports.parsePxToNumber = void 0;
|
@@ -197,4 +197,8 @@ var parsePxToNumber = exports.parsePxToNumber = function parsePxToNumber(str) {
|
|
197
197
|
var getFieldId = exports.getFieldId = function getFieldId(name, formName) {
|
198
198
|
if (!name) return undefined;
|
199
199
|
return "".concat(formName ? "".concat(formName, "_") : '').concat(name);
|
200
|
+
};
|
201
|
+
var getOriginField = exports.getOriginField = function getOriginField(name, formName) {
|
202
|
+
if (!name || !formName) return '';
|
203
|
+
return name.replace("".concat(formName, "_"), '');
|
200
204
|
};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Provider.d.ts","sourceRoot":"","sources":["Provider.tsx"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"Provider.d.ts","sourceRoot":"","sources":["Provider.tsx"],"names":[],"mappings":"AAMA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGhD,eAAO,MAAM,QAAQ,UAAW,aAAa,4CAa5C,CAAC"}
|
@@ -2,6 +2,7 @@ import { FormBindContext } from "./form-bind-context";
|
|
2
2
|
import { FormFuncContext } from "./form-func-context";
|
3
3
|
import { FormConfigContext } from "./form-config-context";
|
4
4
|
import FieldSetContext from "./use-form-fieldset/fieldset-context";
|
5
|
+
import { FormSchemaContext } from "./form-schema-context";
|
5
6
|
import * as React from 'react';
|
6
7
|
import { jsx as _jsx } from "react/jsx-runtime";
|
7
8
|
var topPath = {
|
@@ -12,7 +13,8 @@ export var Provider = function Provider(props) {
|
|
12
13
|
var children = props.children,
|
13
14
|
formConfig = props.formConfig,
|
14
15
|
formValue = props.formValue,
|
15
|
-
formFunc = props.formFunc
|
16
|
+
formFunc = props.formFunc,
|
17
|
+
formSchema = props.formSchema;
|
16
18
|
return /*#__PURE__*/_jsx(FormFuncContext.Provider, {
|
17
19
|
value: formFunc,
|
18
20
|
children: /*#__PURE__*/_jsx(FormBindContext.Provider, {
|
@@ -21,7 +23,10 @@ export var Provider = function Provider(props) {
|
|
21
23
|
value: topPath,
|
22
24
|
children: /*#__PURE__*/_jsx(FormConfigContext.Provider, {
|
23
25
|
value: formConfig,
|
24
|
-
children:
|
26
|
+
children: /*#__PURE__*/_jsx(FormSchemaContext.Provider, {
|
27
|
+
value: formSchema,
|
28
|
+
children: children
|
29
|
+
})
|
25
30
|
})
|
26
31
|
})
|
27
32
|
})
|
@@ -0,0 +1,6 @@
|
|
1
|
+
import * as React from 'react';
|
2
|
+
import { SchemaBuilder } from './use-form-schema/form-schema-builder';
|
3
|
+
export type FormSchemaContextValueType = SchemaBuilder;
|
4
|
+
export declare const FormSchemaContext: React.Context<SchemaBuilder | null>;
|
5
|
+
export declare const useFormSchema: () => SchemaBuilder | null;
|
6
|
+
//# sourceMappingURL=form-schema-context.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"form-schema-context.d.ts","sourceRoot":"","sources":["form-schema-context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,MAAM,uCAAuC,CAAC;AAEtE,MAAM,MAAM,0BAA0B,GAAG,aAAa,CAAA;AAEtD,eAAO,MAAM,iBAAiB,qCAA+D,CAAC;AAC9F,eAAO,MAAM,aAAa,4BAA4C,CAAC"}
|
@@ -0,0 +1,8 @@
|
|
1
|
+
"use client";
|
2
|
+
|
3
|
+
import * as React from 'react';
|
4
|
+
export var FormSchemaContext = /*#__PURE__*/React.createContext(null);
|
5
|
+
export var useFormSchema = function useFormSchema() {
|
6
|
+
return React.useContext(FormSchemaContext);
|
7
|
+
};
|
8
|
+
FormSchemaContext.displayName = 'FormSchemaContext';
|
@@ -3,8 +3,10 @@ export * from './use-form-item';
|
|
3
3
|
export * from './use-form-fieldset';
|
4
4
|
export * from './use-form-flow';
|
5
5
|
export * from './use-form-context';
|
6
|
+
export * from './use-form-schema';
|
6
7
|
export { default, default as useForm } from './use-form';
|
7
8
|
export { useFormConfig } from './form-config-context';
|
8
9
|
export { useFormFunc } from './form-func-context';
|
10
|
+
export { useFormSchema } from './form-schema-context';
|
9
11
|
export type { BaseFormProps, FormCommonConfig, FormLabelConfig } from './use-form.type';
|
10
12
|
//# sourceMappingURL=index.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC;AACnC,cAAc,mBAAmB,CAAC;AAElC,OAAO,EAAE,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,YAAY,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AACtD,YAAY,EAAE,aAAa,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC"}
|
@@ -4,6 +4,8 @@ export * from "./use-form-item";
|
|
4
4
|
export * from "./use-form-fieldset";
|
5
5
|
export * from "./use-form-flow";
|
6
6
|
export * from "./use-form-context";
|
7
|
+
export * from "./use-form-schema";
|
7
8
|
export { default, default as useForm } from "./use-form";
|
8
9
|
export { useFormConfig } from "./form-config-context";
|
9
|
-
export { useFormFunc } from "./form-func-context";
|
10
|
+
export { useFormFunc } from "./form-func-context";
|
11
|
+
export { useFormSchema } from "./form-schema-context";
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import { SchemaProperty } from './use-form-schema/form-schema-builder';
|
1
2
|
export interface FormRef<Value = any> {
|
2
3
|
/**
|
3
4
|
* @en return form value
|
@@ -51,5 +52,10 @@ export interface FormRef<Value = any> {
|
|
51
52
|
* @cn 滚动到指定字段
|
52
53
|
*/
|
53
54
|
scrollToField: (name: string, scrollIntoViewOptions?: ScrollIntoViewOptions) => void;
|
55
|
+
/**
|
56
|
+
* @en get form schema
|
57
|
+
* @cn 获取表单的 schema
|
58
|
+
*/
|
59
|
+
getFormSchema: () => SchemaProperty | undefined;
|
54
60
|
}
|
55
61
|
//# sourceMappingURL=use-form-context.type.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"use-form-context.type.d.ts","sourceRoot":"","sources":["use-form-context.type.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,OAAO,CAAC,KAAK,GAAG,GAAG;IAClC;;;OAGG;IACH,QAAQ,EAAE,CAAC,IAAI,CAAC,EAAE,MAAM,KAAK,GAAG,GAAG,KAAK,CAAC;IACzC;;;OAGG;IACH,QAAQ,EAAE,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,KAAK,OAAO,CAAC,KAAK,CAAC,CAAC;IACzD;;;OAGG;IACH,cAAc,EAAE,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;IAC5D;;;OAGG;IACH,uBAAuB,EAAE,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;IACtE;;;OAGG;IACH,uBAAuB,EAAE,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;IACrE;;;OAGG;IACH,aAAa,EAAE,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;IAC1C;;;OAGG;IACH,MAAM,EAAE,CAAC,YAAY,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IACzC;;;OAGG;IACH,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB;;;OAGG;IACH,GAAG,EAAE,CAAC,KAAK,EAAE;QAAE,CAAC,G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AC;IAC7C;;;OAGG;IACH,aAAa,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,qBAAqB,CAAC,EAAE,qBAAqB,KAAK,IAAI,CAAC;IAErF;;;OAGG;IACH,aAAa,EAAE,MAAM,cAAc,GAAG,SAAS,CAAC;CACjD"}
|
@@ -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"}
|
@@ -0,0 +1,49 @@
|
|
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
|
+
};
|
10
|
+
description?: string;
|
11
|
+
[key: string]: any;
|
12
|
+
}
|
13
|
+
export interface SchemaProperty {
|
14
|
+
type?: string;
|
15
|
+
properties?: Record<string, SchemaProperty>;
|
16
|
+
items?: SchemaProperty;
|
17
|
+
required?: string[];
|
18
|
+
title?: string;
|
19
|
+
description?: string;
|
20
|
+
format?: string;
|
21
|
+
enum?: any;
|
22
|
+
[key: string]: any;
|
23
|
+
}
|
24
|
+
export declare class SchemaBuilder {
|
25
|
+
private schema;
|
26
|
+
constructor(formName: string);
|
27
|
+
updateSchema({ path, meta }: {
|
28
|
+
path: string;
|
29
|
+
meta: SchemaMeta;
|
30
|
+
}): void;
|
31
|
+
/**
|
32
|
+
* 根据组件信息构建 schema meta
|
33
|
+
*/
|
34
|
+
buildSchemaFromComponent(params: {
|
35
|
+
componentElement: any;
|
36
|
+
rules?: any[];
|
37
|
+
label?: string;
|
38
|
+
finalFieldId?: string;
|
39
|
+
separator?: string;
|
40
|
+
}): SchemaMeta;
|
41
|
+
parsePath(path?: string): string[] | null;
|
42
|
+
mergeSchema(currentSchema: SchemaProperty, pathSegments: string[], meta: SchemaMeta): void;
|
43
|
+
handleArraySegment(currentSchema: SchemaProperty, remainingSegments: string[], meta: SchemaMeta): void;
|
44
|
+
handleObjectProperty(currentSchema: SchemaProperty, propertyName: string, remainingSegments: string[], meta: SchemaMeta): void;
|
45
|
+
handleRequired(parentSchema: SchemaProperty, propertyName: string, isRequired: boolean): void;
|
46
|
+
getFormSchema(): SchemaProperty;
|
47
|
+
}
|
48
|
+
export {};
|
49
|
+
//# 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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AAC,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,305 @@
|
|
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
|
+
switch (componentElement.type.name) {
|
71
|
+
case 'Input':
|
72
|
+
fieldSchemaInfo.type = 'string';
|
73
|
+
break;
|
74
|
+
case 'InputNumber':
|
75
|
+
fieldSchemaInfo.type = 'number';
|
76
|
+
break;
|
77
|
+
case 'InputPassword':
|
78
|
+
fieldSchemaInfo.type = 'string';
|
79
|
+
break;
|
80
|
+
case 'Textarea':
|
81
|
+
fieldSchemaInfo.type = 'string';
|
82
|
+
break;
|
83
|
+
case 'Select':
|
84
|
+
case 'TreeSelect':
|
85
|
+
{
|
86
|
+
var format = componentElement.props.format || componentElement.props.keygen;
|
87
|
+
if (typeof componentElement.props.keygen !== 'boolean') {
|
88
|
+
if (typeof format === 'string') {
|
89
|
+
var _data$;
|
90
|
+
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]);
|
91
|
+
} else if (typeof format === 'function') {
|
92
|
+
itemType = _typeof(format(data === null || data === void 0 ? void 0 : data[0]));
|
93
|
+
} else {
|
94
|
+
itemType = _typeof(data === null || data === void 0 ? void 0 : data[0]);
|
95
|
+
}
|
96
|
+
} else {
|
97
|
+
itemType = _typeof(data === null || data === void 0 ? void 0 : data[0]);
|
98
|
+
}
|
99
|
+
if (componentElement.props.multiple) {
|
100
|
+
fieldSchemaInfo.type = 'array';
|
101
|
+
fieldSchemaInfo.items = {
|
102
|
+
type: itemType
|
103
|
+
};
|
104
|
+
} else {
|
105
|
+
fieldSchemaInfo.type = itemType;
|
106
|
+
}
|
107
|
+
// props.data格式: [
|
108
|
+
// { "value": 1, "title": "年假" },
|
109
|
+
// { "value": 2, "title": "调休" },
|
110
|
+
// { "value": 3, "title": "事假" },
|
111
|
+
// { "value": 4, "title": "病假" },
|
112
|
+
// { "value": 5, "title": "其他" }
|
113
|
+
// ]
|
114
|
+
// 转换为jsonschema中的enum格式:
|
115
|
+
// "enum": {
|
116
|
+
// "anyOf": [
|
117
|
+
// { "const": 1, "title": "年假" },
|
118
|
+
// { "const": 2, "title": "调休" },
|
119
|
+
// { "const": 3, "title": "事假" },
|
120
|
+
// { "const": 4, "title": "病假" },
|
121
|
+
// { "const": 5, "title": "其他" }
|
122
|
+
// ]
|
123
|
+
// }
|
124
|
+
fieldSchemaInfo.enum = {
|
125
|
+
anyOf: componentElement.props.data.map(function (item) {
|
126
|
+
return {
|
127
|
+
const: (item === null || item === void 0 ? void 0 : item[format]) || item,
|
128
|
+
title: (item === null || item === void 0 ? void 0 : item.title) || item
|
129
|
+
};
|
130
|
+
})
|
131
|
+
};
|
132
|
+
break;
|
133
|
+
}
|
134
|
+
case 'DatePicker':
|
135
|
+
if (componentElement.props.range) {
|
136
|
+
if (finalFieldId !== null && finalFieldId !== void 0 && finalFieldId.includes(separator || '')) {
|
137
|
+
fieldSchemaInfo.type = 'string';
|
138
|
+
fieldSchemaInfo.format = 'date';
|
139
|
+
} else {
|
140
|
+
fieldSchemaInfo.type = 'array';
|
141
|
+
fieldSchemaInfo.items = {
|
142
|
+
type: 'string',
|
143
|
+
format: 'date'
|
144
|
+
};
|
145
|
+
}
|
146
|
+
} else {
|
147
|
+
fieldSchemaInfo.type = 'string';
|
148
|
+
fieldSchemaInfo.format = 'date';
|
149
|
+
}
|
150
|
+
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 || '', " ");
|
151
|
+
break;
|
152
|
+
case 'Checkbox':
|
153
|
+
fieldSchemaInfo.type = 'array';
|
154
|
+
fieldSchemaInfo.items = {
|
155
|
+
type: 'string'
|
156
|
+
};
|
157
|
+
break;
|
158
|
+
case 'Radio':
|
159
|
+
fieldSchemaInfo.type = 'string';
|
160
|
+
break;
|
161
|
+
case 'Rate':
|
162
|
+
fieldSchemaInfo.type = 'number';
|
163
|
+
break;
|
164
|
+
default:
|
165
|
+
if (Array.isArray(componentElement.props.value) && componentElement.props.value.length === 0) {
|
166
|
+
fieldSchemaInfo.type = 'array';
|
167
|
+
fieldSchemaInfo.items = {
|
168
|
+
type: 'string'
|
169
|
+
};
|
170
|
+
} else {
|
171
|
+
fieldSchemaInfo.type = _typeof(componentElement.props.value);
|
172
|
+
}
|
173
|
+
break;
|
174
|
+
}
|
175
|
+
}
|
176
|
+
return fieldSchemaInfo;
|
177
|
+
}
|
178
|
+
|
179
|
+
// 解析路径字符串,如 'a[0].b1' -> ['a', '[0]', 'b1']
|
180
|
+
}, {
|
181
|
+
key: "parsePath",
|
182
|
+
value: function parsePath(path) {
|
183
|
+
if (!path) return null;
|
184
|
+
var segments = [];
|
185
|
+
var current = '';
|
186
|
+
var inBracket = false;
|
187
|
+
for (var i = 0; i < path.length; i++) {
|
188
|
+
var char = path[i];
|
189
|
+
if (char === '[') {
|
190
|
+
if (current) {
|
191
|
+
segments.push(current);
|
192
|
+
current = '';
|
193
|
+
}
|
194
|
+
current = '[';
|
195
|
+
inBracket = true;
|
196
|
+
} else if (char === ']') {
|
197
|
+
current += ']';
|
198
|
+
segments.push(current);
|
199
|
+
current = '';
|
200
|
+
inBracket = false;
|
201
|
+
} else if (char === '.' && !inBracket) {
|
202
|
+
if (current) {
|
203
|
+
segments.push(current);
|
204
|
+
current = '';
|
205
|
+
}
|
206
|
+
} else {
|
207
|
+
current += char;
|
208
|
+
}
|
209
|
+
}
|
210
|
+
if (current) {
|
211
|
+
segments.push(current);
|
212
|
+
}
|
213
|
+
return segments;
|
214
|
+
}
|
215
|
+
|
216
|
+
// 递归合并 schema
|
217
|
+
}, {
|
218
|
+
key: "mergeSchema",
|
219
|
+
value: function mergeSchema(currentSchema, pathSegments, meta) {
|
220
|
+
if (pathSegments.length === 0) {
|
221
|
+
// 到达叶子节点,应用元数据
|
222
|
+
Object.assign(currentSchema, meta);
|
223
|
+
return;
|
224
|
+
}
|
225
|
+
var _pathSegments = _toArray(pathSegments),
|
226
|
+
currentSegment = _pathSegments[0],
|
227
|
+
remainingSegments = _pathSegments.slice(1);
|
228
|
+
if (currentSegment.startsWith('[') && currentSegment.endsWith(']')) {
|
229
|
+
// 处理数组索引,如 [0]
|
230
|
+
this.handleArraySegment(currentSchema, remainingSegments, meta);
|
231
|
+
} else {
|
232
|
+
// 处理对象属性
|
233
|
+
this.handleObjectProperty(currentSchema, currentSegment, remainingSegments, meta);
|
234
|
+
}
|
235
|
+
}
|
236
|
+
}, {
|
237
|
+
key: "handleArraySegment",
|
238
|
+
value: function handleArraySegment(currentSchema, remainingSegments, meta) {
|
239
|
+
// 当前节点应该是数组类型
|
240
|
+
if (!currentSchema.items) {
|
241
|
+
currentSchema.type = 'array';
|
242
|
+
currentSchema.items = {
|
243
|
+
type: 'object',
|
244
|
+
properties: {}
|
245
|
+
};
|
246
|
+
}
|
247
|
+
this.mergeSchema(currentSchema.items, remainingSegments, meta);
|
248
|
+
}
|
249
|
+
}, {
|
250
|
+
key: "handleObjectProperty",
|
251
|
+
value: function handleObjectProperty(currentSchema, propertyName, remainingSegments, meta) {
|
252
|
+
// 确保当前节点有 properties
|
253
|
+
if (!currentSchema.properties) {
|
254
|
+
currentSchema.properties = {};
|
255
|
+
}
|
256
|
+
|
257
|
+
// 如果属性不存在,创建它
|
258
|
+
if (!currentSchema.properties[propertyName]) {
|
259
|
+
currentSchema.properties[propertyName] = remainingSegments.length > 0 ? {
|
260
|
+
type: 'object'
|
261
|
+
} : {};
|
262
|
+
}
|
263
|
+
if (remainingSegments.length === 0) {
|
264
|
+
// 叶子节点,应用元数据并处理 required
|
265
|
+
var required = meta.required,
|
266
|
+
restMeta = _objectWithoutProperties(meta, _excluded);
|
267
|
+
Object.assign(currentSchema.properties[propertyName], restMeta);
|
268
|
+
if (typeof required === 'boolean') {
|
269
|
+
this.handleRequired(currentSchema, propertyName, required);
|
270
|
+
}
|
271
|
+
} else {
|
272
|
+
// 继续递归
|
273
|
+
this.mergeSchema(currentSchema.properties[propertyName], remainingSegments, meta);
|
274
|
+
}
|
275
|
+
}
|
276
|
+
}, {
|
277
|
+
key: "handleRequired",
|
278
|
+
value: function handleRequired(parentSchema, propertyName, isRequired) {
|
279
|
+
// 如果required是布尔值,转换为数组形式
|
280
|
+
if (typeof parentSchema.required === 'boolean') {
|
281
|
+
return;
|
282
|
+
}
|
283
|
+
if (!parentSchema.required) {
|
284
|
+
parentSchema.required = [];
|
285
|
+
}
|
286
|
+
var requiredIndex = parentSchema.required.indexOf(propertyName);
|
287
|
+
if (isRequired && requiredIndex === -1) {
|
288
|
+
parentSchema.required.push(propertyName);
|
289
|
+
} else if (!isRequired && requiredIndex !== -1) {
|
290
|
+
parentSchema.required.splice(requiredIndex, 1);
|
291
|
+
}
|
292
|
+
|
293
|
+
// 如果 required 数组为空,删除它
|
294
|
+
if (parentSchema.required.length === 0) {
|
295
|
+
delete parentSchema.required;
|
296
|
+
}
|
297
|
+
}
|
298
|
+
}, {
|
299
|
+
key: "getFormSchema",
|
300
|
+
value: function getFormSchema() {
|
301
|
+
return this.schema;
|
302
|
+
}
|
303
|
+
}]);
|
304
|
+
return SchemaBuilder;
|
305
|
+
}();
|
@@ -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"}
|