@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.
Files changed (195) hide show
  1. package/cjs/common/use-filter/use-filter.d.ts.map +1 -1
  2. package/cjs/common/use-filter/use-filter.js +4 -1
  3. package/cjs/common/use-position-style/check-border.d.ts +1 -0
  4. package/cjs/common/use-position-style/check-border.d.ts.map +1 -1
  5. package/cjs/common/use-position-style/check-border.js +2 -2
  6. package/cjs/common/use-position-style/index.d.ts.map +1 -1
  7. package/cjs/common/use-position-style/index.js +10 -4
  8. package/cjs/components/use-check/use-check.d.ts.map +1 -1
  9. package/cjs/components/use-check/use-check.js +10 -2
  10. package/cjs/components/use-datepicker/use-date.d.ts.map +1 -1
  11. package/cjs/components/use-datepicker/use-date.js +12 -4
  12. package/cjs/components/use-datepicker/use-date.type.d.ts +2 -1
  13. package/cjs/components/use-datepicker/use-date.type.d.ts.map +1 -1
  14. package/cjs/components/use-datepicker/use-datepicker-format.d.ts +2 -1
  15. package/cjs/components/use-datepicker/use-datepicker-format.d.ts.map +1 -1
  16. package/cjs/components/use-datepicker/use-datepicker-format.js +22 -5
  17. package/cjs/components/use-datepicker/use-datepicker-range.js +2 -2
  18. package/cjs/components/use-datepicker/use-time.d.ts +10 -8
  19. package/cjs/components/use-datepicker/use-time.d.ts.map +1 -1
  20. package/cjs/components/use-datepicker/use-time.js +19 -5
  21. package/cjs/components/use-datepicker/use-time.type.d.ts +5 -1
  22. package/cjs/components/use-datepicker/use-time.type.d.ts.map +1 -1
  23. package/cjs/components/use-datepicker/util.d.ts +7 -1
  24. package/cjs/components/use-datepicker/util.d.ts.map +1 -1
  25. package/cjs/components/use-datepicker/util.js +21 -2
  26. package/cjs/components/use-form/Provider.d.ts.map +1 -1
  27. package/cjs/components/use-form/Provider.js +7 -2
  28. package/cjs/components/use-form/form-schema-context.d.ts +6 -0
  29. package/cjs/components/use-form/form-schema-context.d.ts.map +1 -0
  30. package/cjs/components/use-form/form-schema-context.js +16 -0
  31. package/cjs/components/use-form/index.d.ts +2 -0
  32. package/cjs/components/use-form/index.d.ts.map +1 -1
  33. package/cjs/components/use-form/index.js +21 -1
  34. package/cjs/components/use-form/use-form-context.d.ts.map +1 -1
  35. package/cjs/components/use-form/use-form-context.js +11 -5
  36. package/cjs/components/use-form/use-form-context.type.d.ts +6 -0
  37. package/cjs/components/use-form/use-form-context.type.d.ts.map +1 -1
  38. package/cjs/components/use-form/use-form-control/use-form-control.d.ts.map +1 -1
  39. package/cjs/components/use-form/use-form-control/use-form-control.js +12 -3
  40. package/cjs/components/use-form/use-form-control/use-form-control.type.d.ts +8 -2
  41. package/cjs/components/use-form/use-form-control/use-form-control.type.d.ts.map +1 -1
  42. package/cjs/components/use-form/use-form-flow/use-form-datum.d.ts +8 -0
  43. package/cjs/components/use-form/use-form-flow/use-form-datum.d.ts.map +1 -1
  44. package/cjs/components/use-form/use-form-item/form-item-context.d.ts +1 -0
  45. package/cjs/components/use-form/use-form-item/form-item-context.d.ts.map +1 -1
  46. package/cjs/components/use-form/use-form-item/form-item-context.js +2 -1
  47. package/cjs/components/use-form/use-form-item/index.d.ts +1 -0
  48. package/cjs/components/use-form/use-form-item/index.d.ts.map +1 -1
  49. package/cjs/components/use-form/use-form-item/index.js +7 -0
  50. package/cjs/components/use-form/use-form-item/use-form-item.d.ts +1 -1
  51. package/cjs/components/use-form/use-form-schema/form-schema-builder.d.ts +50 -0
  52. package/cjs/components/use-form/use-form-schema/form-schema-builder.d.ts.map +1 -0
  53. package/cjs/components/use-form/use-form-schema/form-schema-builder.js +373 -0
  54. package/cjs/components/use-form/use-form-schema/index.d.ts +3 -0
  55. package/cjs/components/use-form/use-form-schema/index.d.ts.map +1 -0
  56. package/cjs/components/use-form/use-form-schema/index.js +13 -0
  57. package/cjs/components/use-form/use-form.d.ts +4 -0
  58. package/cjs/components/use-form/use-form.d.ts.map +1 -1
  59. package/cjs/components/use-form/use-form.js +22 -11
  60. package/cjs/components/use-form/use-form.type.d.ts +46 -39
  61. package/cjs/components/use-form/use-form.type.d.ts.map +1 -1
  62. package/cjs/components/use-input/use-input.d.ts.map +1 -1
  63. package/cjs/components/use-input/use-input.js +4 -1
  64. package/cjs/components/use-pagination/use-pagination.d.ts.map +1 -1
  65. package/cjs/components/use-pagination/use-pagination.js +2 -1
  66. package/cjs/components/use-popup/use-popup.d.ts.map +1 -1
  67. package/cjs/components/use-popup/use-popup.js +7 -4
  68. package/cjs/components/use-select/use-select.type.d.ts +27 -18
  69. package/cjs/components/use-select/use-select.type.d.ts.map +1 -1
  70. package/cjs/components/use-table/use-table-virtual.d.ts +6 -1
  71. package/cjs/components/use-table/use-table-virtual.d.ts.map +1 -1
  72. package/cjs/components/use-table/use-table-virtual.js +5 -4
  73. package/cjs/components/use-table/use-table.type.d.ts +70 -92
  74. package/cjs/components/use-table/use-table.type.d.ts.map +1 -1
  75. package/cjs/components/use-tree/use-tree-node.d.ts +7 -1
  76. package/cjs/components/use-tree/use-tree-node.d.ts.map +1 -1
  77. package/cjs/components/use-tree/use-tree-node.js +19 -1
  78. package/cjs/components/use-tree/use-tree.d.ts.map +1 -1
  79. package/cjs/components/use-tree/use-tree.js +26 -19
  80. package/cjs/components/use-tree/use-tree.type.d.ts +7 -1
  81. package/cjs/components/use-tree/use-tree.type.d.ts.map +1 -1
  82. package/cjs/utils/dom/document.d.ts +4 -0
  83. package/cjs/utils/dom/document.d.ts.map +1 -1
  84. package/cjs/utils/dom/document.js +19 -2
  85. package/cjs/utils/dom/element.d.ts +1 -0
  86. package/cjs/utils/dom/element.d.ts.map +1 -1
  87. package/cjs/utils/dom/element.js +5 -1
  88. package/cjs/utils/highlight.d.ts.map +1 -1
  89. package/cjs/utils/highlight.js +24 -11
  90. package/cjs/utils/lazyload.d.ts.map +1 -1
  91. package/cjs/utils/lazyload.js +33 -1
  92. package/cjs/utils/object.d.ts +6 -0
  93. package/cjs/utils/object.d.ts.map +1 -1
  94. package/cjs/utils/object.js +21 -1
  95. package/cjs/utils/shallow-equal.d.ts +1 -0
  96. package/cjs/utils/shallow-equal.d.ts.map +1 -1
  97. package/cjs/utils/shallow-equal.js +9 -0
  98. package/esm/common/use-filter/use-filter.d.ts.map +1 -1
  99. package/esm/common/use-filter/use-filter.js +4 -1
  100. package/esm/common/use-position-style/check-border.d.ts +1 -0
  101. package/esm/common/use-position-style/check-border.d.ts.map +1 -1
  102. package/esm/common/use-position-style/check-border.js +2 -2
  103. package/esm/common/use-position-style/index.d.ts.map +1 -1
  104. package/esm/common/use-position-style/index.js +11 -5
  105. package/esm/components/use-check/use-check.d.ts.map +1 -1
  106. package/esm/components/use-check/use-check.js +10 -2
  107. package/esm/components/use-datepicker/use-date.d.ts.map +1 -1
  108. package/esm/components/use-datepicker/use-date.js +12 -4
  109. package/esm/components/use-datepicker/use-date.type.d.ts +2 -1
  110. package/esm/components/use-datepicker/use-date.type.d.ts.map +1 -1
  111. package/esm/components/use-datepicker/use-datepicker-format.d.ts +2 -1
  112. package/esm/components/use-datepicker/use-datepicker-format.d.ts.map +1 -1
  113. package/esm/components/use-datepicker/use-datepicker-format.js +19 -5
  114. package/esm/components/use-datepicker/use-datepicker-range.js +2 -2
  115. package/esm/components/use-datepicker/use-time.d.ts +10 -8
  116. package/esm/components/use-datepicker/use-time.d.ts.map +1 -1
  117. package/esm/components/use-datepicker/use-time.js +19 -5
  118. package/esm/components/use-datepicker/use-time.type.d.ts +5 -1
  119. package/esm/components/use-datepicker/use-time.type.d.ts.map +1 -1
  120. package/esm/components/use-datepicker/util.d.ts +7 -1
  121. package/esm/components/use-datepicker/util.d.ts.map +1 -1
  122. package/esm/components/use-datepicker/util.js +21 -2
  123. package/esm/components/use-form/Provider.d.ts.map +1 -1
  124. package/esm/components/use-form/Provider.js +7 -2
  125. package/esm/components/use-form/form-schema-context.d.ts +6 -0
  126. package/esm/components/use-form/form-schema-context.d.ts.map +1 -0
  127. package/esm/components/use-form/form-schema-context.js +8 -0
  128. package/esm/components/use-form/index.d.ts +2 -0
  129. package/esm/components/use-form/index.d.ts.map +1 -1
  130. package/esm/components/use-form/index.js +3 -1
  131. package/esm/components/use-form/use-form-context.d.ts.map +1 -1
  132. package/esm/components/use-form/use-form-context.js +11 -5
  133. package/esm/components/use-form/use-form-context.type.d.ts +6 -0
  134. package/esm/components/use-form/use-form-context.type.d.ts.map +1 -1
  135. package/esm/components/use-form/use-form-control/use-form-control.d.ts.map +1 -1
  136. package/esm/components/use-form/use-form-control/use-form-control.js +12 -3
  137. package/esm/components/use-form/use-form-control/use-form-control.type.d.ts +8 -2
  138. package/esm/components/use-form/use-form-control/use-form-control.type.d.ts.map +1 -1
  139. package/esm/components/use-form/use-form-flow/use-form-datum.d.ts +8 -0
  140. package/esm/components/use-form/use-form-flow/use-form-datum.d.ts.map +1 -1
  141. package/esm/components/use-form/use-form-item/form-item-context.d.ts +1 -0
  142. package/esm/components/use-form/use-form-item/form-item-context.d.ts.map +1 -1
  143. package/esm/components/use-form/use-form-item/form-item-context.js +2 -1
  144. package/esm/components/use-form/use-form-item/index.d.ts +1 -0
  145. package/esm/components/use-form/use-form-item/index.d.ts.map +1 -1
  146. package/esm/components/use-form/use-form-item/index.js +2 -1
  147. package/esm/components/use-form/use-form-item/use-form-item.d.ts +1 -1
  148. package/esm/components/use-form/use-form-schema/form-schema-builder.d.ts +50 -0
  149. package/esm/components/use-form/use-form-schema/form-schema-builder.d.ts.map +1 -0
  150. package/esm/components/use-form/use-form-schema/form-schema-builder.js +367 -0
  151. package/esm/components/use-form/use-form-schema/index.d.ts +3 -0
  152. package/esm/components/use-form/use-form-schema/index.d.ts.map +1 -0
  153. package/esm/components/use-form/use-form-schema/index.js +2 -0
  154. package/esm/components/use-form/use-form.d.ts +4 -0
  155. package/esm/components/use-form/use-form.d.ts.map +1 -1
  156. package/esm/components/use-form/use-form.js +22 -11
  157. package/esm/components/use-form/use-form.type.d.ts +46 -39
  158. package/esm/components/use-form/use-form.type.d.ts.map +1 -1
  159. package/esm/components/use-input/use-input.d.ts.map +1 -1
  160. package/esm/components/use-input/use-input.js +4 -1
  161. package/esm/components/use-pagination/use-pagination.d.ts.map +1 -1
  162. package/esm/components/use-pagination/use-pagination.js +2 -1
  163. package/esm/components/use-popup/use-popup.d.ts.map +1 -1
  164. package/esm/components/use-popup/use-popup.js +7 -4
  165. package/esm/components/use-select/use-select.type.d.ts +27 -18
  166. package/esm/components/use-select/use-select.type.d.ts.map +1 -1
  167. package/esm/components/use-table/use-table-virtual.d.ts +6 -1
  168. package/esm/components/use-table/use-table-virtual.d.ts.map +1 -1
  169. package/esm/components/use-table/use-table-virtual.js +5 -4
  170. package/esm/components/use-table/use-table.type.d.ts +70 -92
  171. package/esm/components/use-table/use-table.type.d.ts.map +1 -1
  172. package/esm/components/use-tree/use-tree-node.d.ts +7 -1
  173. package/esm/components/use-tree/use-tree-node.d.ts.map +1 -1
  174. package/esm/components/use-tree/use-tree-node.js +19 -1
  175. package/esm/components/use-tree/use-tree.d.ts.map +1 -1
  176. package/esm/components/use-tree/use-tree.js +26 -19
  177. package/esm/components/use-tree/use-tree.type.d.ts +7 -1
  178. package/esm/components/use-tree/use-tree.type.d.ts.map +1 -1
  179. package/esm/utils/dom/document.d.ts +4 -0
  180. package/esm/utils/dom/document.d.ts.map +1 -1
  181. package/esm/utils/dom/document.js +18 -1
  182. package/esm/utils/dom/element.d.ts +1 -0
  183. package/esm/utils/dom/element.d.ts.map +1 -1
  184. package/esm/utils/dom/element.js +4 -0
  185. package/esm/utils/highlight.d.ts.map +1 -1
  186. package/esm/utils/highlight.js +24 -10
  187. package/esm/utils/lazyload.d.ts.map +1 -1
  188. package/esm/utils/lazyload.js +33 -1
  189. package/esm/utils/object.d.ts +6 -0
  190. package/esm/utils/object.d.ts.map +1 -1
  191. package/esm/utils/object.js +20 -0
  192. package/esm/utils/shallow-equal.d.ts +1 -0
  193. package/esm/utils/shallow-equal.d.ts.map +1 -1
  194. package/esm/utils/shallow-equal.js +8 -0
  195. package/package.json +3 -3
@@ -0,0 +1,367 @@
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
+ fieldSchemaInfo.items = {
105
+ type: itemType
106
+ };
107
+ } else {
108
+ fieldSchemaInfo.type = itemType;
109
+ }
110
+ if (itemType === 'object') {
111
+ // 对于对象类型,使用 oneOf 而不是 enum
112
+ if (componentElement.props.multiple) {
113
+ fieldSchemaInfo.items.oneOf = componentElement.props.data.map(function (item) {
114
+ return {
115
+ const: item,
116
+ title: (item === null || item === void 0 ? void 0 : item.title) || JSON.stringify(item)
117
+ };
118
+ });
119
+ } else {
120
+ fieldSchemaInfo.oneOf = componentElement.props.data.map(function (item) {
121
+ return {
122
+ const: item,
123
+ title: (item === null || item === void 0 ? void 0 : item.title) || JSON.stringify(item)
124
+ };
125
+ });
126
+ }
127
+ } else {
128
+ fieldSchemaInfo.enum = componentElement.props.data.map(function (item) {
129
+ return (item === null || item === void 0 ? void 0 : item[format]) || item;
130
+ });
131
+ }
132
+ break;
133
+ }
134
+ case 'ShineoutDatePicker':
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 'ShineoutCheckbox':
153
+ case 'ShineoutCheckboxGroup':
154
+ {
155
+ if (typeof componentElement.props.keygen !== 'boolean') {
156
+ if (typeof format === 'string') {
157
+ var _data$2;
158
+ 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]);
159
+ } else if (typeof format === 'function') {
160
+ itemType = _typeof(format(data === null || data === void 0 ? void 0 : data[0]));
161
+ } else {
162
+ itemType = _typeof(data === null || data === void 0 ? void 0 : data[0]);
163
+ }
164
+ } else {
165
+ itemType = _typeof(data === null || data === void 0 ? void 0 : data[0]);
166
+ }
167
+ fieldSchemaInfo.type = 'array';
168
+ fieldSchemaInfo.items = {
169
+ type: itemType
170
+ };
171
+
172
+ // ShineoutCheckboxGroup 有 data 时(多选的)
173
+ if (itemType === 'object') {
174
+ fieldSchemaInfo.items.oneOf = componentElement.props.data.map(function (item) {
175
+ return {
176
+ const: item,
177
+ title: (item === null || item === void 0 ? void 0 : item.title) || JSON.stringify(item)
178
+ };
179
+ });
180
+ } else {
181
+ fieldSchemaInfo.items.enum = componentElement.props.data.map(function (item) {
182
+ return (item === null || item === void 0 ? void 0 : item[format]) || item;
183
+ });
184
+ }
185
+ break;
186
+ }
187
+ case 'ShineoutRadio':
188
+ case 'ShineoutRadioGroup':
189
+ {
190
+ if (typeof componentElement.props.keygen !== 'boolean') {
191
+ if (typeof format === 'string') {
192
+ var _data$3;
193
+ 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]);
194
+ } else if (typeof format === 'function') {
195
+ itemType = _typeof(format(data === null || data === void 0 ? void 0 : data[0]));
196
+ } else {
197
+ itemType = _typeof(data === null || data === void 0 ? void 0 : data[0]);
198
+ }
199
+ } else {
200
+ itemType = _typeof(data === null || data === void 0 ? void 0 : data[0]);
201
+ }
202
+ fieldSchemaInfo.type = itemType;
203
+
204
+ // ShineoutRadioGroup 有 data 时(单选的)
205
+ if (itemType === 'object') {
206
+ fieldSchemaInfo.oneOf = componentElement.props.data.map(function (item) {
207
+ return {
208
+ const: item,
209
+ title: (item === null || item === void 0 ? void 0 : item.title) || JSON.stringify(item)
210
+ };
211
+ });
212
+ } else {
213
+ fieldSchemaInfo.enum = componentElement.props.data.map(function (item) {
214
+ return (item === null || item === void 0 ? void 0 : item[format]) || item;
215
+ });
216
+ }
217
+ break;
218
+ }
219
+ case 'ShineoutSwitch':
220
+ fieldSchemaInfo.type = 'boolean';
221
+ break;
222
+ case 'ShineoutSlider':
223
+ case 'ShineoutRate':
224
+ fieldSchemaInfo.type = 'number';
225
+ break;
226
+ default:
227
+ if (Array.isArray(componentElement.props.value) && componentElement.props.value.length === 0) {
228
+ fieldSchemaInfo.type = 'array';
229
+ fieldSchemaInfo.items = {
230
+ type: 'string'
231
+ };
232
+ } else {
233
+ fieldSchemaInfo.type = _typeof(componentElement.props.value);
234
+ }
235
+ break;
236
+ }
237
+ }
238
+ return fieldSchemaInfo;
239
+ }
240
+
241
+ // 解析路径字符串,如 'a[0].b1' -> ['a', '[0]', 'b1']
242
+ }, {
243
+ key: "parsePath",
244
+ value: function parsePath(path) {
245
+ if (!path) return null;
246
+ var segments = [];
247
+ var current = '';
248
+ var inBracket = false;
249
+ for (var i = 0; i < path.length; i++) {
250
+ var char = path[i];
251
+ if (char === '[') {
252
+ if (current) {
253
+ segments.push(current);
254
+ current = '';
255
+ }
256
+ current = '[';
257
+ inBracket = true;
258
+ } else if (char === ']') {
259
+ current += ']';
260
+ segments.push(current);
261
+ current = '';
262
+ inBracket = false;
263
+ } else if (char === '.' && !inBracket) {
264
+ if (current) {
265
+ segments.push(current);
266
+ current = '';
267
+ }
268
+ } else {
269
+ current += char;
270
+ }
271
+ }
272
+ if (current) {
273
+ segments.push(current);
274
+ }
275
+ return segments;
276
+ }
277
+
278
+ // 递归合并 schema
279
+ }, {
280
+ key: "mergeSchema",
281
+ value: function mergeSchema(currentSchema, pathSegments, meta) {
282
+ if (pathSegments.length === 0) {
283
+ // 到达叶子节点,应用元数据
284
+ Object.assign(currentSchema, meta);
285
+ return;
286
+ }
287
+ var _pathSegments = _toArray(pathSegments),
288
+ currentSegment = _pathSegments[0],
289
+ remainingSegments = _pathSegments.slice(1);
290
+ if (currentSegment.startsWith('[') && currentSegment.endsWith(']')) {
291
+ // 处理数组索引,如 [0]
292
+ this.handleArraySegment(currentSchema, remainingSegments, meta);
293
+ } else {
294
+ // 处理对象属性
295
+ this.handleObjectProperty(currentSchema, currentSegment, remainingSegments, meta);
296
+ }
297
+ }
298
+ }, {
299
+ key: "handleArraySegment",
300
+ value: function handleArraySegment(currentSchema, remainingSegments, meta) {
301
+ // 当前节点应该是数组类型
302
+ if (!currentSchema.items) {
303
+ currentSchema.type = 'array';
304
+ currentSchema.items = {
305
+ type: 'object',
306
+ properties: {}
307
+ };
308
+ }
309
+ this.mergeSchema(currentSchema.items, remainingSegments, meta);
310
+ }
311
+ }, {
312
+ key: "handleObjectProperty",
313
+ value: function handleObjectProperty(currentSchema, propertyName, remainingSegments, meta) {
314
+ // 确保当前节点有 properties
315
+ if (!currentSchema.properties) {
316
+ currentSchema.properties = {};
317
+ }
318
+
319
+ // 如果属性不存在,创建它
320
+ if (!currentSchema.properties[propertyName]) {
321
+ currentSchema.properties[propertyName] = remainingSegments.length > 0 ? {
322
+ type: 'object'
323
+ } : {};
324
+ }
325
+ if (remainingSegments.length === 0) {
326
+ // 叶子节点,应用元数据并处理 required
327
+ var required = meta.required,
328
+ restMeta = _objectWithoutProperties(meta, _excluded);
329
+ Object.assign(currentSchema.properties[propertyName], restMeta);
330
+ if (typeof required === 'boolean') {
331
+ this.handleRequired(currentSchema, propertyName, required);
332
+ }
333
+ } else {
334
+ // 继续递归
335
+ this.mergeSchema(currentSchema.properties[propertyName], remainingSegments, meta);
336
+ }
337
+ }
338
+ }, {
339
+ key: "handleRequired",
340
+ value: function handleRequired(parentSchema, propertyName, isRequired) {
341
+ // 如果required是布尔值,转换为数组形式
342
+ if (typeof parentSchema.required === 'boolean') {
343
+ return;
344
+ }
345
+ if (!parentSchema.required) {
346
+ parentSchema.required = [];
347
+ }
348
+ var requiredIndex = parentSchema.required.indexOf(propertyName);
349
+ if (isRequired && requiredIndex === -1) {
350
+ parentSchema.required.push(propertyName);
351
+ } else if (!isRequired && requiredIndex !== -1) {
352
+ parentSchema.required.splice(requiredIndex, 1);
353
+ }
354
+
355
+ // 如果 required 数组为空,删除它
356
+ if (parentSchema.required.length === 0) {
357
+ delete parentSchema.required;
358
+ }
359
+ }
360
+ }, {
361
+ key: "getFormSchema",
362
+ value: function getFormSchema() {
363
+ return this.schema;
364
+ }
365
+ }]);
366
+ return SchemaBuilder;
367
+ }();
@@ -0,0 +1,3 @@
1
+ export { SchemaBuilder } from "./form-schema-builder";
2
+ export type { SchemaProperty } from "./form-schema-builder";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -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"}
@@ -0,0 +1,2 @@
1
+ "use client";
2
+ export { SchemaBuilder } from "./form-schema-builder";
@@ -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":"AA+BA,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;;;;;;;;;wBAoSC;gBAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;gBAAC,WAAW,CAAC,EAAE,OAAO,CAAA;aAAE;8BArPnB,MAAM;oCAgUD,OAAO,aAAoB,MAAM,IAAI;;6BAf3C,MAAM,KAAK,KAAK,GAAG,SAAS;;oCAdrB,MAAM,EAAE;sCA3RxC,MAAM,GAAG,MAAM,EAAE,WAAU,gBAAgB;qCA8VvB,MAAM,WAAW,gBAAgB;gCAhDzB,MAAM,SAAS,MAAM,UAAU,KAAK;gCAKpC,MAAM,SAAS,MAAM;kCAjJpD,MAAM,0BAAyB,qBAAqB;;;;;;oBA2EjD;YAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;YAAC,WAAW,CAAC,EAAE,OAAO,CAAA;SAAE;0BArPnB,MAAM;gCAgUD,OAAO,aAAoB,MAAM,IAAI;;yBAf3C,MAAM,KAAK,KAAK,GAAG,SAAS;;gCAdrB,MAAM,EAAE;kCA3RxC,MAAM,GAAG,MAAM,EAAE,WAAU,gBAAgB;iCA8VvB,MAAM,WAAW,gBAAgB;4BAhDzB,MAAM,SAAS,MAAM,UAAU,KAAK;4BAKpC,MAAM,SAAS,MAAM;8BAjJpD,MAAM,0BAAyB,qBAAqB;;CAqb9D,CAAC;AAEF,eAAe,OAAO,CAAC"}
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;;;;;;;;;wBAqSC;gBAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;gBAAC,WAAW,CAAC,EAAE,OAAO,CAAA;aAAE;8BArPnB,MAAM;oCAoUD,OAAO,aAAoB,MAAM,IAAI;;6BAf3C,MAAM,KAAK,KAAK,GAAG,SAAS;;oCAdrB,MAAM,EAAE;sCA/RxC,MAAM,GAAG,MAAM,EAAE,WAAU,gBAAgB;qCAkWvB,MAAM,WAAW,gBAAgB;gCAhDzB,MAAM,SAAS,MAAM,UAAU,KAAK;gCAKpC,MAAM,SAAS,MAAM;kCArJpD,MAAM,0BAAyB,qBAAqB;;;;;;;;oBA2EjD;YAAE,QAAQ,CAAC,EAAE,OAAO,CAAC;YAAC,WAAW,CAAC,EAAE,OAAO,CAAA;SAAE;0BArPnB,MAAM;gCAoUD,OAAO,aAAoB,MAAM,IAAI;;yBAf3C,MAAM,KAAK,KAAK,GAAG,SAAS;;gCAdrB,MAAM,EAAE;kCA/RxC,MAAM,GAAG,MAAM,EAAE,WAAU,gBAAgB;iCAkWvB,MAAM,WAAW,gBAAgB;4BAhDzB,MAAM,SAAS,MAAM,UAAU,KAAK;4BAKpC,MAAM,SAAS,MAAM;8BArJpD,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, context.value);
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;
@@ -329,6 +332,10 @@ var useForm = function useForm(props) {
329
332
  Object.keys(context.defaultValues).forEach(function (df) {
330
333
  var latestDefaultValue = getValue(df);
331
334
  if (latestDefaultValue === undefined) {
335
+ // todo: Form组件传了clearToUndefined时,加入这部分判断?
336
+ // if(context.value.hasOwnProperty(df) && clearToUndefined){
337
+ // return;
338
+ // }
332
339
  setValue(_defineProperty({}, df, context.defaultValues[df]), {
333
340
  validate: false
334
341
  });
@@ -421,7 +428,7 @@ var useForm = function useForm(props) {
421
428
  var _other$onSubmit;
422
429
  submit();
423
430
  other === null || other === void 0 || (_other$onSubmit = other.onSubmit) === null || _other$onSubmit === void 0 || _other$onSubmit.call(other, e);
424
- }, 10);
431
+ }, SUBMIT_TIMEOUT);
425
432
  };
426
433
  };
427
434
  var validateFieldset = function validateFieldset(name, config) {
@@ -514,6 +521,9 @@ var useForm = function useForm(props) {
514
521
  context.names.delete(n);
515
522
  delete context.defaultValues[n];
516
523
  }
524
+ if (context.errors[n]) {
525
+ delete context.errors[n];
526
+ }
517
527
  var finalReserveAble = (_props$reserveAble = props.reserveAble) !== null && _props$reserveAble !== void 0 ? _props$reserveAble : reserveAble;
518
528
  if (!finalReserveAble && !context.removeLock) {
519
529
  addRemove(n);
@@ -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
  };