@sheinx/hooks 3.8.0-beta.5 → 3.8.0-beta.50
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 +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 +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-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/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 +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 +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-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/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
@@ -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"}
|
@@ -14,7 +14,9 @@ import usePersistFn from "../../common/use-persist-fn";
|
|
14
14
|
import { getDataAttributeName } from "../../utils/attribute";
|
15
15
|
import { insertValue, spliceValue } from "../../utils/flat";
|
16
16
|
import { usePrevious } from "../../common/use-default-value";
|
17
|
+
import { SchemaBuilder } from "./use-form-schema/form-schema-builder";
|
17
18
|
var globalKey = '__global__&&@@';
|
19
|
+
var SUBMIT_TIMEOUT = 10;
|
18
20
|
import { current, produce } from "../../utils/immer";
|
19
21
|
import { deepGet, deepRemove, deepSet, docScroll, extractEventHandlers, isArray, isObject, shallowEqual, wrapFormError, deepClone, getAllKeyPaths, getCompleteFieldKeys, devUseWarning, getFieldId, getClosestScrollContainer } from "../../utils";
|
20
22
|
var emptyObj = {};
|
@@ -61,7 +63,8 @@ var useForm = function useForm(props) {
|
|
61
63
|
resetTime: 0,
|
62
64
|
mounted: false,
|
63
65
|
unmounted: false,
|
64
|
-
removeLock: false
|
66
|
+
removeLock: false,
|
67
|
+
schema: props.name ? new SchemaBuilder(props.name) : null
|
65
68
|
}),
|
66
69
|
context = _React$useRef.current;
|
67
70
|
var getValue = usePersistFn(function (name) {
|
@@ -220,13 +223,13 @@ var useForm = function useForm(props) {
|
|
220
223
|
docScroll.top -= scrollToError;
|
221
224
|
}
|
222
225
|
}
|
223
|
-
});
|
226
|
+
}, SUBMIT_TIMEOUT + 10);
|
224
227
|
};
|
225
228
|
var onChange = usePersistFn(function (change) {
|
226
229
|
var _props$onChange;
|
227
230
|
var newValue = typeof change === 'function' ? produce(context.value, change) : change;
|
228
231
|
context.value = newValue;
|
229
|
-
(_props$onChange = props.onChange) === null || _props$onChange === void 0 || _props$onChange.call(props,
|
232
|
+
(_props$onChange = props.onChange) === null || _props$onChange === void 0 || _props$onChange.call(props, newValue);
|
230
233
|
});
|
231
234
|
var scrollToField = usePersistFn(function (name) {
|
232
235
|
var _document;
|
@@ -280,6 +283,9 @@ var useForm = function useForm(props) {
|
|
280
283
|
context.removeArr.forEach(function (n) {
|
281
284
|
deepRemove(v, n);
|
282
285
|
context.removeArr.delete(n);
|
286
|
+
if (context.errors[n]) {
|
287
|
+
delete context.errors[n];
|
288
|
+
}
|
283
289
|
});
|
284
290
|
});
|
285
291
|
};
|
@@ -329,6 +335,10 @@ var useForm = function useForm(props) {
|
|
329
335
|
Object.keys(context.defaultValues).forEach(function (df) {
|
330
336
|
var latestDefaultValue = getValue(df);
|
331
337
|
if (latestDefaultValue === undefined) {
|
338
|
+
// todo: Form组件传了clearToUndefined时,加入这部分判断?
|
339
|
+
// if(context.value.hasOwnProperty(df) && clearToUndefined){
|
340
|
+
// return;
|
341
|
+
// }
|
332
342
|
setValue(_defineProperty({}, df, context.defaultValues[df]), {
|
333
343
|
validate: false
|
334
344
|
});
|
@@ -421,7 +431,7 @@ var useForm = function useForm(props) {
|
|
421
431
|
var _other$onSubmit;
|
422
432
|
submit();
|
423
433
|
other === null || other === void 0 || (_other$onSubmit = other.onSubmit) === null || _other$onSubmit === void 0 || _other$onSubmit.call(other, e);
|
424
|
-
},
|
434
|
+
}, SUBMIT_TIMEOUT);
|
425
435
|
};
|
426
436
|
};
|
427
437
|
var validateFieldset = function validateFieldset(name, config) {
|
@@ -567,7 +577,11 @@ var useForm = function useForm(props) {
|
|
567
577
|
validateFieldset: validateFieldset,
|
568
578
|
insertError: insertError,
|
569
579
|
spliceError: spliceError,
|
570
|
-
scrollToField: scrollToField
|
580
|
+
scrollToField: scrollToField,
|
581
|
+
getFormSchema: function getFormSchema() {
|
582
|
+
var _context$schema;
|
583
|
+
return (_context$schema = context.schema) === null || _context$schema === void 0 ? void 0 : _context$schema.getFormSchema();
|
584
|
+
}
|
571
585
|
});
|
572
586
|
var formConfig = React.useMemo(function () {
|
573
587
|
return {
|
@@ -605,11 +619,6 @@ var useForm = function useForm(props) {
|
|
605
619
|
// 默认值更新
|
606
620
|
React.useEffect(function () {
|
607
621
|
context.removeLock = false;
|
608
|
-
// 内部 onChange 改的 value, 不需要更新
|
609
|
-
if (props.value === context.value) {
|
610
|
-
if (!isControl) update();
|
611
|
-
return;
|
612
|
-
}
|
613
622
|
if (initValidate && !context.resetTime) {
|
614
623
|
var keys = Object.keys(context.validateMap).filter(function (key) {
|
615
624
|
var oldValue = deepGet(preValue || emptyObj, key);
|
@@ -619,6 +628,7 @@ var useForm = function useForm(props) {
|
|
619
628
|
validateFields(keys).catch(function () {});
|
620
629
|
}
|
621
630
|
update();
|
631
|
+
if (!isControl) return;
|
622
632
|
// 默认值上位时会提前触发外部的onChange, 导致外部的多次setFormValue不能合并后生效的问题(ReactDOM.render方式渲染)
|
623
633
|
setTimeout(updateDefaultValue);
|
624
634
|
context.resetTime = 0;
|
@@ -640,7 +650,8 @@ var useForm = function useForm(props) {
|
|
640
650
|
ProviderProps: {
|
641
651
|
formValue: formValue,
|
642
652
|
formConfig: formConfig,
|
643
|
-
formFunc: formFunc
|
653
|
+
formFunc: formFunc,
|
654
|
+
formSchema: context.schema
|
644
655
|
},
|
645
656
|
formFunc: formFunc
|
646
657
|
};
|