@sheinx/hooks 3.8.0-beta.4 → 3.8.0-beta.40
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/check-border.d.ts +1 -0
- package/cjs/common/use-position-style/check-border.d.ts.map +1 -1
- package/cjs/common/use-position-style/check-border.js +2 -2
- package/cjs/common/use-position-style/index.d.ts.map +1 -1
- package/cjs/common/use-position-style/index.js +10 -4
- 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-date.d.ts.map +1 -1
- package/cjs/components/use-datepicker/use-date.js +12 -4
- package/cjs/components/use-datepicker/use-date.type.d.ts +2 -1
- package/cjs/components/use-datepicker/use-date.type.d.ts.map +1 -1
- package/cjs/components/use-datepicker/use-datepicker-format.d.ts +2 -1
- package/cjs/components/use-datepicker/use-datepicker-format.d.ts.map +1 -1
- package/cjs/components/use-datepicker/use-datepicker-format.js +22 -5
- package/cjs/components/use-datepicker/use-datepicker-range.js +2 -2
- 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 +7 -1
- package/cjs/components/use-datepicker/util.d.ts.map +1 -1
- package/cjs/components/use-datepicker/util.js +21 -2
- 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.d.ts.map +1 -1
- package/cjs/components/use-form/use-form-context.js +11 -5
- 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 +12 -3
- 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 +373 -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 +22 -11
- 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.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 +7 -4
- 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/cjs/utils/shallow-equal.d.ts +1 -0
- package/cjs/utils/shallow-equal.d.ts.map +1 -1
- package/cjs/utils/shallow-equal.js +9 -0
- 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/check-border.d.ts +1 -0
- package/esm/common/use-position-style/check-border.d.ts.map +1 -1
- package/esm/common/use-position-style/check-border.js +2 -2
- package/esm/common/use-position-style/index.d.ts.map +1 -1
- package/esm/common/use-position-style/index.js +11 -5
- 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-date.d.ts.map +1 -1
- package/esm/components/use-datepicker/use-date.js +12 -4
- package/esm/components/use-datepicker/use-date.type.d.ts +2 -1
- package/esm/components/use-datepicker/use-date.type.d.ts.map +1 -1
- package/esm/components/use-datepicker/use-datepicker-format.d.ts +2 -1
- package/esm/components/use-datepicker/use-datepicker-format.d.ts.map +1 -1
- package/esm/components/use-datepicker/use-datepicker-format.js +19 -5
- package/esm/components/use-datepicker/use-datepicker-range.js +2 -2
- 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 +7 -1
- package/esm/components/use-datepicker/util.d.ts.map +1 -1
- package/esm/components/use-datepicker/util.js +21 -2
- 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.d.ts.map +1 -1
- package/esm/components/use-form/use-form-context.js +11 -5
- 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 +12 -3
- 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 +367 -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 +22 -11
- 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.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 +7 -4
- 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/esm/utils/shallow-equal.d.ts +1 -0
- package/esm/utils/shallow-equal.d.ts.map +1 -1
- package/esm/utils/shallow-equal.js +8 -0
- package/package.json +3 -3
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"use-form-context.d.ts","sourceRoot":"","sources":["use-form-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAElD,eAAO,MAAM,WAAW,oBAA+B,CAAC;AAExD,wBAAgB,UAAU,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,
|
1
|
+
{"version":3,"file":"use-form-context.d.ts","sourceRoot":"","sources":["use-form-context.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,OAAO,EAAE,MAAM,yBAAyB,CAAC;AAElD,eAAO,MAAM,WAAW,oBAA+B,CAAC;AAExD,wBAAgB,UAAU,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,CAG7E;AAED,wBAAgB,eAAe,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAG/C"}
|
@@ -8,13 +8,19 @@ exports.useFormInstance = useFormInstance;
|
|
8
8
|
exports.useFormRef = useFormRef;
|
9
9
|
var _react = _interopRequireDefault(require("react"));
|
10
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
11
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
12
|
+
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."); }
|
13
|
+
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); }
|
14
|
+
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; }
|
15
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
16
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
11
17
|
var FormContext = exports.FormContext = /*#__PURE__*/_react.default.createContext({});
|
12
18
|
function useFormRef() {
|
13
|
-
var
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
return [
|
19
|
+
var _React$useState = _react.default.useState({}),
|
20
|
+
_React$useState2 = _slicedToArray(_React$useState, 2),
|
21
|
+
formRef = _React$useState2[0],
|
22
|
+
setFormRef = _React$useState2[1];
|
23
|
+
return [formRef, setFormRef];
|
18
24
|
}
|
19
25
|
function useFormInstance() {
|
20
26
|
var formCtx = _react.default.useContext(FormContext);
|
@@ -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,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,KAAK,IAAI,CAAC;IAC7C;;;OAGG;IACH,aAAa,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,qBAAqB,CAAC,EAAE,qBAAqB,KAAK,IAAI,CAAC;
|
1
|
+
{"version":3,"file":"use-form-context.type.d.ts","sourceRoot":"","sources":["use-form-context.type.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,cAAc,EAAE,MAAM,uCAAuC,CAAC;AAEvE,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,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;KAAE,KAAK,IAAI,CAAC;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":"use-form-control.d.ts","sourceRoot":"","sources":["use-form-control.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,oBAAoB,EAAsB,MAAM,yBAAyB,CAAC;AA4BnF,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,oBAAoB,CAAC,CAAC,CAAC;;
|
1
|
+
{"version":3,"file":"use-form-control.d.ts","sourceRoot":"","sources":["use-form-control.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,oBAAoB,EAAsB,MAAM,yBAAyB,CAAC;AA4BnF,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,oBAAoB,CAAC,CAAC,CAAC;;kBA0JpC,CAAC,YAAY,GAAG,EAAE;;;;;EA4DrD"}
|
@@ -57,7 +57,8 @@ function useFormControl(props) {
|
|
57
57
|
defaultValue = props.defaultValue,
|
58
58
|
rules = props.rules,
|
59
59
|
onError = props.onError,
|
60
|
-
getValidateProps = props.getValidateProps
|
60
|
+
getValidateProps = props.getValidateProps,
|
61
|
+
clearToUndefined = props.clearToUndefined;
|
61
62
|
var _useFieldSetConsumer = (0, _fieldsetContext.useFieldSetConsumer)({
|
62
63
|
name: props.name,
|
63
64
|
bind: props.bind
|
@@ -115,7 +116,11 @@ function useFormControl(props) {
|
|
115
116
|
var nextValue = [];
|
116
117
|
name.forEach(function (n, index) {
|
117
118
|
if (_value[index] === undefined && dv[index] !== undefined) {
|
118
|
-
|
119
|
+
if (clearToUndefined) {
|
120
|
+
nextValue[index] = undefined;
|
121
|
+
} else {
|
122
|
+
nextValue[index] = dv[index];
|
123
|
+
}
|
119
124
|
} else {
|
120
125
|
nextValue[index] = _value[index];
|
121
126
|
}
|
@@ -129,7 +134,11 @@ function useFormControl(props) {
|
|
129
134
|
}
|
130
135
|
if (!(0, _shallowEqual.shallowEqual)(_value2, latestInfo.valueState)) {
|
131
136
|
if (_value2 === undefined && defaultValue !== undefined) {
|
132
|
-
|
137
|
+
if (clearToUndefined) {
|
138
|
+
setValueState(undefined);
|
139
|
+
} else {
|
140
|
+
setValueState(defaultValue);
|
141
|
+
}
|
133
142
|
} else {
|
134
143
|
setValueState(_value2);
|
135
144
|
}
|
@@ -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"}
|
@@ -11,4 +11,5 @@ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return
|
|
11
11
|
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
12
12
|
var FormItemContext = exports.FormItemContext = /*#__PURE__*/React.createContext({
|
13
13
|
updateError: function updateError() {}
|
14
|
-
});
|
14
|
+
});
|
15
|
+
FormItemContext.displayName = 'FormItemContext';
|
@@ -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"}
|
@@ -4,6 +4,12 @@
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
5
5
|
value: true
|
6
6
|
});
|
7
|
+
Object.defineProperty(exports, "FormItemContext", {
|
8
|
+
enumerable: true,
|
9
|
+
get: function get() {
|
10
|
+
return _formItemContext.FormItemContext;
|
11
|
+
}
|
12
|
+
});
|
7
13
|
Object.defineProperty(exports, "default", {
|
8
14
|
enumerable: true,
|
9
15
|
get: function get() {
|
@@ -17,4 +23,5 @@ Object.defineProperty(exports, "useFormItem", {
|
|
17
23
|
}
|
18
24
|
});
|
19
25
|
var _useFormItem = _interopRequireDefault(require("./use-form-item"));
|
26
|
+
var _formItemContext = require("./form-item-context");
|
20
27
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
@@ -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;IAmLd,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,373 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.SchemaBuilder = void 0;
|
7
|
+
var _excluded = ["required"];
|
8
|
+
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; }
|
9
|
+
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; }
|
10
|
+
function _toArray(arr) { return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest(); }
|
11
|
+
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."); }
|
12
|
+
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); }
|
13
|
+
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; }
|
14
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
15
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
16
|
+
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); }
|
17
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
18
|
+
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); } }
|
19
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
20
|
+
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; }
|
21
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
22
|
+
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); }
|
23
|
+
var SchemaBuilder = exports.SchemaBuilder = /*#__PURE__*/function () {
|
24
|
+
function SchemaBuilder(formName) {
|
25
|
+
_classCallCheck(this, SchemaBuilder);
|
26
|
+
_defineProperty(this, "schema", void 0);
|
27
|
+
this.schema = {
|
28
|
+
type: 'object',
|
29
|
+
title: formName,
|
30
|
+
properties: {}
|
31
|
+
};
|
32
|
+
}
|
33
|
+
_createClass(SchemaBuilder, [{
|
34
|
+
key: "updateSchema",
|
35
|
+
value: function updateSchema(_ref) {
|
36
|
+
var path = _ref.path,
|
37
|
+
meta = _ref.meta;
|
38
|
+
var pathSegments = this.parsePath(path);
|
39
|
+
if (!pathSegments) return;
|
40
|
+
this.mergeSchema(this.schema, pathSegments, meta);
|
41
|
+
}
|
42
|
+
|
43
|
+
/**
|
44
|
+
* 根据组件信息构建 schema meta
|
45
|
+
*/
|
46
|
+
}, {
|
47
|
+
key: "buildSchemaFromComponent",
|
48
|
+
value: function buildSchemaFromComponent(params) {
|
49
|
+
var _componentElement$pro;
|
50
|
+
var componentElement = params.componentElement,
|
51
|
+
rules = params.rules,
|
52
|
+
label = params.label,
|
53
|
+
finalFieldId = params.finalFieldId,
|
54
|
+
separator = params.separator;
|
55
|
+
var fieldSchemaInfo = {
|
56
|
+
title: label
|
57
|
+
};
|
58
|
+
var data = componentElement.props.data;
|
59
|
+
var isRequired = rules === null || rules === void 0 ? void 0 : rules.some(function (rule) {
|
60
|
+
return rule.required;
|
61
|
+
});
|
62
|
+
fieldSchemaInfo.required = isRequired;
|
63
|
+
fieldSchemaInfo.description = '';
|
64
|
+
if (rules !== null && rules !== void 0 && rules.length) {
|
65
|
+
var messageRules = rules.filter(function (rule) {
|
66
|
+
return typeof rule.message === 'string';
|
67
|
+
});
|
68
|
+
if (messageRules.length) {
|
69
|
+
fieldSchemaInfo.description += "rules: ".concat(messageRules.map(function (rule) {
|
70
|
+
return rule.message;
|
71
|
+
}).join(', '), ";");
|
72
|
+
}
|
73
|
+
}
|
74
|
+
var itemType;
|
75
|
+
if (typeof componentElement.type === 'function') {
|
76
|
+
var componentName = componentElement.type.displayName || componentElement.type.name;
|
77
|
+
var format = componentElement.props.format || componentElement.props.keygen;
|
78
|
+
switch (componentName) {
|
79
|
+
case 'ShineoutInput':
|
80
|
+
case 'ShineoutEditableArea':
|
81
|
+
fieldSchemaInfo.type = 'string';
|
82
|
+
break;
|
83
|
+
case 'ShineoutInputNumber':
|
84
|
+
fieldSchemaInfo.type = 'number';
|
85
|
+
break;
|
86
|
+
case 'ShineoutInputPassword':
|
87
|
+
fieldSchemaInfo.type = 'string';
|
88
|
+
break;
|
89
|
+
case 'ShineoutTextarea':
|
90
|
+
fieldSchemaInfo.type = 'string';
|
91
|
+
break;
|
92
|
+
case 'ShineoutCascader':
|
93
|
+
case 'ShineoutSelect':
|
94
|
+
case 'ShineoutTreeSelect':
|
95
|
+
{
|
96
|
+
if (typeof componentElement.props.keygen !== 'boolean') {
|
97
|
+
if (typeof format === 'string') {
|
98
|
+
var _data$;
|
99
|
+
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]);
|
100
|
+
} else if (typeof format === 'function') {
|
101
|
+
itemType = _typeof(format(data === null || data === void 0 ? void 0 : data[0]));
|
102
|
+
} else {
|
103
|
+
itemType = _typeof(data === null || data === void 0 ? void 0 : data[0]);
|
104
|
+
}
|
105
|
+
} else {
|
106
|
+
itemType = _typeof(data === null || data === void 0 ? void 0 : data[0]);
|
107
|
+
}
|
108
|
+
if (componentElement.props.multiple) {
|
109
|
+
fieldSchemaInfo.type = 'array';
|
110
|
+
fieldSchemaInfo.items = {
|
111
|
+
type: itemType
|
112
|
+
};
|
113
|
+
} else {
|
114
|
+
fieldSchemaInfo.type = itemType;
|
115
|
+
}
|
116
|
+
if (itemType === 'object') {
|
117
|
+
// 对于对象类型,使用 oneOf 而不是 enum
|
118
|
+
if (componentElement.props.multiple) {
|
119
|
+
fieldSchemaInfo.items.oneOf = componentElement.props.data.map(function (item) {
|
120
|
+
return {
|
121
|
+
const: item,
|
122
|
+
title: (item === null || item === void 0 ? void 0 : item.title) || JSON.stringify(item)
|
123
|
+
};
|
124
|
+
});
|
125
|
+
} else {
|
126
|
+
fieldSchemaInfo.oneOf = componentElement.props.data.map(function (item) {
|
127
|
+
return {
|
128
|
+
const: item,
|
129
|
+
title: (item === null || item === void 0 ? void 0 : item.title) || JSON.stringify(item)
|
130
|
+
};
|
131
|
+
});
|
132
|
+
}
|
133
|
+
} else {
|
134
|
+
fieldSchemaInfo.enum = componentElement.props.data.map(function (item) {
|
135
|
+
return (item === null || item === void 0 ? void 0 : item[format]) || item;
|
136
|
+
});
|
137
|
+
}
|
138
|
+
break;
|
139
|
+
}
|
140
|
+
case 'ShineoutDatePicker':
|
141
|
+
if (componentElement.props.range) {
|
142
|
+
if (finalFieldId !== null && finalFieldId !== void 0 && finalFieldId.includes(separator || '')) {
|
143
|
+
fieldSchemaInfo.type = 'string';
|
144
|
+
fieldSchemaInfo.format = 'date';
|
145
|
+
} else {
|
146
|
+
fieldSchemaInfo.type = 'array';
|
147
|
+
fieldSchemaInfo.items = {
|
148
|
+
type: 'string',
|
149
|
+
format: 'date'
|
150
|
+
};
|
151
|
+
}
|
152
|
+
} else {
|
153
|
+
fieldSchemaInfo.type = 'string';
|
154
|
+
fieldSchemaInfo.format = 'date';
|
155
|
+
}
|
156
|
+
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 || '', " ");
|
157
|
+
break;
|
158
|
+
case 'ShineoutCheckbox':
|
159
|
+
case 'ShineoutCheckboxGroup':
|
160
|
+
{
|
161
|
+
if (typeof componentElement.props.keygen !== 'boolean') {
|
162
|
+
if (typeof format === 'string') {
|
163
|
+
var _data$2;
|
164
|
+
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]);
|
165
|
+
} else if (typeof format === 'function') {
|
166
|
+
itemType = _typeof(format(data === null || data === void 0 ? void 0 : data[0]));
|
167
|
+
} else {
|
168
|
+
itemType = _typeof(data === null || data === void 0 ? void 0 : data[0]);
|
169
|
+
}
|
170
|
+
} else {
|
171
|
+
itemType = _typeof(data === null || data === void 0 ? void 0 : data[0]);
|
172
|
+
}
|
173
|
+
fieldSchemaInfo.type = 'array';
|
174
|
+
fieldSchemaInfo.items = {
|
175
|
+
type: itemType
|
176
|
+
};
|
177
|
+
|
178
|
+
// ShineoutCheckboxGroup 有 data 时(多选的)
|
179
|
+
if (itemType === 'object') {
|
180
|
+
fieldSchemaInfo.items.oneOf = componentElement.props.data.map(function (item) {
|
181
|
+
return {
|
182
|
+
const: item,
|
183
|
+
title: (item === null || item === void 0 ? void 0 : item.title) || JSON.stringify(item)
|
184
|
+
};
|
185
|
+
});
|
186
|
+
} else {
|
187
|
+
fieldSchemaInfo.items.enum = componentElement.props.data.map(function (item) {
|
188
|
+
return (item === null || item === void 0 ? void 0 : item[format]) || item;
|
189
|
+
});
|
190
|
+
}
|
191
|
+
break;
|
192
|
+
}
|
193
|
+
case 'ShineoutRadio':
|
194
|
+
case 'ShineoutRadioGroup':
|
195
|
+
{
|
196
|
+
if (typeof componentElement.props.keygen !== 'boolean') {
|
197
|
+
if (typeof format === 'string') {
|
198
|
+
var _data$3;
|
199
|
+
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]);
|
200
|
+
} else if (typeof format === 'function') {
|
201
|
+
itemType = _typeof(format(data === null || data === void 0 ? void 0 : data[0]));
|
202
|
+
} else {
|
203
|
+
itemType = _typeof(data === null || data === void 0 ? void 0 : data[0]);
|
204
|
+
}
|
205
|
+
} else {
|
206
|
+
itemType = _typeof(data === null || data === void 0 ? void 0 : data[0]);
|
207
|
+
}
|
208
|
+
fieldSchemaInfo.type = itemType;
|
209
|
+
|
210
|
+
// ShineoutRadioGroup 有 data 时(单选的)
|
211
|
+
if (itemType === 'object') {
|
212
|
+
fieldSchemaInfo.oneOf = componentElement.props.data.map(function (item) {
|
213
|
+
return {
|
214
|
+
const: item,
|
215
|
+
title: (item === null || item === void 0 ? void 0 : item.title) || JSON.stringify(item)
|
216
|
+
};
|
217
|
+
});
|
218
|
+
} else {
|
219
|
+
fieldSchemaInfo.enum = componentElement.props.data.map(function (item) {
|
220
|
+
return (item === null || item === void 0 ? void 0 : item[format]) || item;
|
221
|
+
});
|
222
|
+
}
|
223
|
+
break;
|
224
|
+
}
|
225
|
+
case 'ShineoutSwitch':
|
226
|
+
fieldSchemaInfo.type = 'boolean';
|
227
|
+
break;
|
228
|
+
case 'ShineoutSlider':
|
229
|
+
case 'ShineoutRate':
|
230
|
+
fieldSchemaInfo.type = 'number';
|
231
|
+
break;
|
232
|
+
default:
|
233
|
+
if (Array.isArray(componentElement.props.value) && componentElement.props.value.length === 0) {
|
234
|
+
fieldSchemaInfo.type = 'array';
|
235
|
+
fieldSchemaInfo.items = {
|
236
|
+
type: 'string'
|
237
|
+
};
|
238
|
+
} else {
|
239
|
+
fieldSchemaInfo.type = _typeof(componentElement.props.value);
|
240
|
+
}
|
241
|
+
break;
|
242
|
+
}
|
243
|
+
}
|
244
|
+
return fieldSchemaInfo;
|
245
|
+
}
|
246
|
+
|
247
|
+
// 解析路径字符串,如 'a[0].b1' -> ['a', '[0]', 'b1']
|
248
|
+
}, {
|
249
|
+
key: "parsePath",
|
250
|
+
value: function parsePath(path) {
|
251
|
+
if (!path) return null;
|
252
|
+
var segments = [];
|
253
|
+
var current = '';
|
254
|
+
var inBracket = false;
|
255
|
+
for (var i = 0; i < path.length; i++) {
|
256
|
+
var char = path[i];
|
257
|
+
if (char === '[') {
|
258
|
+
if (current) {
|
259
|
+
segments.push(current);
|
260
|
+
current = '';
|
261
|
+
}
|
262
|
+
current = '[';
|
263
|
+
inBracket = true;
|
264
|
+
} else if (char === ']') {
|
265
|
+
current += ']';
|
266
|
+
segments.push(current);
|
267
|
+
current = '';
|
268
|
+
inBracket = false;
|
269
|
+
} else if (char === '.' && !inBracket) {
|
270
|
+
if (current) {
|
271
|
+
segments.push(current);
|
272
|
+
current = '';
|
273
|
+
}
|
274
|
+
} else {
|
275
|
+
current += char;
|
276
|
+
}
|
277
|
+
}
|
278
|
+
if (current) {
|
279
|
+
segments.push(current);
|
280
|
+
}
|
281
|
+
return segments;
|
282
|
+
}
|
283
|
+
|
284
|
+
// 递归合并 schema
|
285
|
+
}, {
|
286
|
+
key: "mergeSchema",
|
287
|
+
value: function mergeSchema(currentSchema, pathSegments, meta) {
|
288
|
+
if (pathSegments.length === 0) {
|
289
|
+
// 到达叶子节点,应用元数据
|
290
|
+
Object.assign(currentSchema, meta);
|
291
|
+
return;
|
292
|
+
}
|
293
|
+
var _pathSegments = _toArray(pathSegments),
|
294
|
+
currentSegment = _pathSegments[0],
|
295
|
+
remainingSegments = _pathSegments.slice(1);
|
296
|
+
if (currentSegment.startsWith('[') && currentSegment.endsWith(']')) {
|
297
|
+
// 处理数组索引,如 [0]
|
298
|
+
this.handleArraySegment(currentSchema, remainingSegments, meta);
|
299
|
+
} else {
|
300
|
+
// 处理对象属性
|
301
|
+
this.handleObjectProperty(currentSchema, currentSegment, remainingSegments, meta);
|
302
|
+
}
|
303
|
+
}
|
304
|
+
}, {
|
305
|
+
key: "handleArraySegment",
|
306
|
+
value: function handleArraySegment(currentSchema, remainingSegments, meta) {
|
307
|
+
// 当前节点应该是数组类型
|
308
|
+
if (!currentSchema.items) {
|
309
|
+
currentSchema.type = 'array';
|
310
|
+
currentSchema.items = {
|
311
|
+
type: 'object',
|
312
|
+
properties: {}
|
313
|
+
};
|
314
|
+
}
|
315
|
+
this.mergeSchema(currentSchema.items, remainingSegments, meta);
|
316
|
+
}
|
317
|
+
}, {
|
318
|
+
key: "handleObjectProperty",
|
319
|
+
value: function handleObjectProperty(currentSchema, propertyName, remainingSegments, meta) {
|
320
|
+
// 确保当前节点有 properties
|
321
|
+
if (!currentSchema.properties) {
|
322
|
+
currentSchema.properties = {};
|
323
|
+
}
|
324
|
+
|
325
|
+
// 如果属性不存在,创建它
|
326
|
+
if (!currentSchema.properties[propertyName]) {
|
327
|
+
currentSchema.properties[propertyName] = remainingSegments.length > 0 ? {
|
328
|
+
type: 'object'
|
329
|
+
} : {};
|
330
|
+
}
|
331
|
+
if (remainingSegments.length === 0) {
|
332
|
+
// 叶子节点,应用元数据并处理 required
|
333
|
+
var required = meta.required,
|
334
|
+
restMeta = _objectWithoutProperties(meta, _excluded);
|
335
|
+
Object.assign(currentSchema.properties[propertyName], restMeta);
|
336
|
+
if (typeof required === 'boolean') {
|
337
|
+
this.handleRequired(currentSchema, propertyName, required);
|
338
|
+
}
|
339
|
+
} else {
|
340
|
+
// 继续递归
|
341
|
+
this.mergeSchema(currentSchema.properties[propertyName], remainingSegments, meta);
|
342
|
+
}
|
343
|
+
}
|
344
|
+
}, {
|
345
|
+
key: "handleRequired",
|
346
|
+
value: function handleRequired(parentSchema, propertyName, isRequired) {
|
347
|
+
// 如果required是布尔值,转换为数组形式
|
348
|
+
if (typeof parentSchema.required === 'boolean') {
|
349
|
+
return;
|
350
|
+
}
|
351
|
+
if (!parentSchema.required) {
|
352
|
+
parentSchema.required = [];
|
353
|
+
}
|
354
|
+
var requiredIndex = parentSchema.required.indexOf(propertyName);
|
355
|
+
if (isRequired && requiredIndex === -1) {
|
356
|
+
parentSchema.required.push(propertyName);
|
357
|
+
} else if (!isRequired && requiredIndex !== -1) {
|
358
|
+
parentSchema.required.splice(requiredIndex, 1);
|
359
|
+
}
|
360
|
+
|
361
|
+
// 如果 required 数组为空,删除它
|
362
|
+
if (parentSchema.required.length === 0) {
|
363
|
+
delete parentSchema.required;
|
364
|
+
}
|
365
|
+
}
|
366
|
+
}, {
|
367
|
+
key: "getFormSchema",
|
368
|
+
value: function getFormSchema() {
|
369
|
+
return this.schema;
|
370
|
+
}
|
371
|
+
}]);
|
372
|
+
return SchemaBuilder;
|
373
|
+
}();
|