@sheinx/hooks 3.8.0-beta.8 → 3.8.0-fix.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) 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-input-able/use-Input-able.d.ts.map +1 -1
  4. package/cjs/common/use-input-able/use-Input-able.js +6 -7
  5. package/cjs/common/use-position-style/check-border.d.ts +1 -0
  6. package/cjs/common/use-position-style/check-border.d.ts.map +1 -1
  7. package/cjs/common/use-position-style/check-border.js +2 -2
  8. package/cjs/common/use-position-style/index.d.ts.map +1 -1
  9. package/cjs/common/use-position-style/index.js +10 -4
  10. package/cjs/components/use-check/use-check.d.ts.map +1 -1
  11. package/cjs/components/use-check/use-check.js +10 -2
  12. package/cjs/components/use-datepicker/use-datepicker-format.d.ts.map +1 -1
  13. package/cjs/components/use-datepicker/use-datepicker-format.js +1 -0
  14. package/cjs/components/use-datepicker/use-time.d.ts +10 -8
  15. package/cjs/components/use-datepicker/use-time.d.ts.map +1 -1
  16. package/cjs/components/use-datepicker/use-time.js +19 -5
  17. package/cjs/components/use-datepicker/use-time.type.d.ts +5 -1
  18. package/cjs/components/use-datepicker/use-time.type.d.ts.map +1 -1
  19. package/cjs/components/use-datepicker/util.d.ts.map +1 -1
  20. package/cjs/components/use-datepicker/util.js +10 -1
  21. package/cjs/components/use-form/Provider.d.ts.map +1 -1
  22. package/cjs/components/use-form/Provider.js +7 -2
  23. package/cjs/components/use-form/form-schema-context.d.ts +6 -0
  24. package/cjs/components/use-form/form-schema-context.d.ts.map +1 -0
  25. package/cjs/components/use-form/form-schema-context.js +16 -0
  26. package/cjs/components/use-form/index.d.ts +2 -0
  27. package/cjs/components/use-form/index.d.ts.map +1 -1
  28. package/cjs/components/use-form/index.js +21 -1
  29. package/cjs/components/use-form/use-form-context.d.ts.map +1 -1
  30. package/cjs/components/use-form/use-form-context.js +11 -5
  31. package/cjs/components/use-form/use-form-context.type.d.ts +6 -0
  32. package/cjs/components/use-form/use-form-context.type.d.ts.map +1 -1
  33. package/cjs/components/use-form/use-form-control/use-form-control.d.ts.map +1 -1
  34. package/cjs/components/use-form/use-form-control/use-form-control.js +34 -4
  35. package/cjs/components/use-form/use-form-control/use-form-control.type.d.ts +8 -2
  36. package/cjs/components/use-form/use-form-control/use-form-control.type.d.ts.map +1 -1
  37. package/cjs/components/use-form/use-form-flow/use-form-datum.d.ts +8 -0
  38. package/cjs/components/use-form/use-form-flow/use-form-datum.d.ts.map +1 -1
  39. package/cjs/components/use-form/use-form-item/form-item-context.d.ts +1 -0
  40. package/cjs/components/use-form/use-form-item/form-item-context.d.ts.map +1 -1
  41. package/cjs/components/use-form/use-form-item/form-item-context.js +2 -1
  42. package/cjs/components/use-form/use-form-item/index.d.ts +1 -0
  43. package/cjs/components/use-form/use-form-item/index.d.ts.map +1 -1
  44. package/cjs/components/use-form/use-form-item/index.js +7 -0
  45. package/cjs/components/use-form/use-form-item/use-form-item.d.ts +1 -1
  46. package/cjs/components/use-form/use-form-schema/form-schema-builder.d.ts +50 -0
  47. package/cjs/components/use-form/use-form-schema/form-schema-builder.d.ts.map +1 -0
  48. package/cjs/components/use-form/use-form-schema/form-schema-builder.js +377 -0
  49. package/cjs/components/use-form/use-form-schema/index.d.ts +3 -0
  50. package/cjs/components/use-form/use-form-schema/index.d.ts.map +1 -0
  51. package/cjs/components/use-form/use-form-schema/index.js +13 -0
  52. package/cjs/components/use-form/use-form.d.ts +4 -0
  53. package/cjs/components/use-form/use-form.d.ts.map +1 -1
  54. package/cjs/components/use-form/use-form.js +19 -9
  55. package/cjs/components/use-form/use-form.type.d.ts +46 -39
  56. package/cjs/components/use-form/use-form.type.d.ts.map +1 -1
  57. package/cjs/components/use-input/use-input-number.d.ts.map +1 -1
  58. package/cjs/components/use-input/use-input-number.js +3 -1
  59. package/cjs/components/use-input/use-input-number.type.d.ts +1 -1
  60. package/cjs/components/use-input/use-input-number.type.d.ts.map +1 -1
  61. package/cjs/components/use-input/use-input.d.ts.map +1 -1
  62. package/cjs/components/use-input/use-input.js +4 -1
  63. package/cjs/components/use-pagination/use-pagination.d.ts.map +1 -1
  64. package/cjs/components/use-pagination/use-pagination.js +2 -1
  65. package/cjs/components/use-popup/use-popup.d.ts.map +1 -1
  66. package/cjs/components/use-popup/use-popup.js +12 -24
  67. package/cjs/components/use-select/use-select.type.d.ts +27 -18
  68. package/cjs/components/use-select/use-select.type.d.ts.map +1 -1
  69. package/cjs/components/use-table/use-table-virtual.d.ts +6 -1
  70. package/cjs/components/use-table/use-table-virtual.d.ts.map +1 -1
  71. package/cjs/components/use-table/use-table-virtual.js +5 -4
  72. package/cjs/components/use-table/use-table.type.d.ts +70 -92
  73. package/cjs/components/use-table/use-table.type.d.ts.map +1 -1
  74. package/cjs/components/use-tree/use-tree-node.d.ts +7 -1
  75. package/cjs/components/use-tree/use-tree-node.d.ts.map +1 -1
  76. package/cjs/components/use-tree/use-tree-node.js +19 -1
  77. package/cjs/components/use-tree/use-tree.d.ts.map +1 -1
  78. package/cjs/components/use-tree/use-tree.js +26 -19
  79. package/cjs/components/use-tree/use-tree.type.d.ts +7 -1
  80. package/cjs/components/use-tree/use-tree.type.d.ts.map +1 -1
  81. package/cjs/utils/dom/document.d.ts +4 -0
  82. package/cjs/utils/dom/document.d.ts.map +1 -1
  83. package/cjs/utils/dom/document.js +19 -2
  84. package/cjs/utils/dom/element.d.ts +1 -0
  85. package/cjs/utils/dom/element.d.ts.map +1 -1
  86. package/cjs/utils/dom/element.js +5 -1
  87. package/cjs/utils/highlight.d.ts.map +1 -1
  88. package/cjs/utils/highlight.js +24 -11
  89. package/cjs/utils/lazyload.d.ts.map +1 -1
  90. package/cjs/utils/lazyload.js +33 -1
  91. package/cjs/utils/object.d.ts +6 -0
  92. package/cjs/utils/object.d.ts.map +1 -1
  93. package/cjs/utils/object.js +21 -1
  94. package/esm/common/use-filter/use-filter.d.ts.map +1 -1
  95. package/esm/common/use-filter/use-filter.js +4 -1
  96. package/esm/common/use-input-able/use-Input-able.d.ts.map +1 -1
  97. package/esm/common/use-input-able/use-Input-able.js +7 -8
  98. package/esm/common/use-position-style/check-border.d.ts +1 -0
  99. package/esm/common/use-position-style/check-border.d.ts.map +1 -1
  100. package/esm/common/use-position-style/check-border.js +2 -2
  101. package/esm/common/use-position-style/index.d.ts.map +1 -1
  102. package/esm/common/use-position-style/index.js +11 -5
  103. package/esm/components/use-check/use-check.d.ts.map +1 -1
  104. package/esm/components/use-check/use-check.js +10 -2
  105. package/esm/components/use-datepicker/use-datepicker-format.d.ts.map +1 -1
  106. package/esm/components/use-datepicker/use-datepicker-format.js +1 -0
  107. package/esm/components/use-datepicker/use-time.d.ts +10 -8
  108. package/esm/components/use-datepicker/use-time.d.ts.map +1 -1
  109. package/esm/components/use-datepicker/use-time.js +19 -5
  110. package/esm/components/use-datepicker/use-time.type.d.ts +5 -1
  111. package/esm/components/use-datepicker/use-time.type.d.ts.map +1 -1
  112. package/esm/components/use-datepicker/util.d.ts.map +1 -1
  113. package/esm/components/use-datepicker/util.js +10 -1
  114. package/esm/components/use-form/Provider.d.ts.map +1 -1
  115. package/esm/components/use-form/Provider.js +7 -2
  116. package/esm/components/use-form/form-schema-context.d.ts +6 -0
  117. package/esm/components/use-form/form-schema-context.d.ts.map +1 -0
  118. package/esm/components/use-form/form-schema-context.js +8 -0
  119. package/esm/components/use-form/index.d.ts +2 -0
  120. package/esm/components/use-form/index.d.ts.map +1 -1
  121. package/esm/components/use-form/index.js +3 -1
  122. package/esm/components/use-form/use-form-context.d.ts.map +1 -1
  123. package/esm/components/use-form/use-form-context.js +11 -5
  124. package/esm/components/use-form/use-form-context.type.d.ts +6 -0
  125. package/esm/components/use-form/use-form-context.type.d.ts.map +1 -1
  126. package/esm/components/use-form/use-form-control/use-form-control.d.ts.map +1 -1
  127. package/esm/components/use-form/use-form-control/use-form-control.js +34 -4
  128. package/esm/components/use-form/use-form-control/use-form-control.type.d.ts +8 -2
  129. package/esm/components/use-form/use-form-control/use-form-control.type.d.ts.map +1 -1
  130. package/esm/components/use-form/use-form-flow/use-form-datum.d.ts +8 -0
  131. package/esm/components/use-form/use-form-flow/use-form-datum.d.ts.map +1 -1
  132. package/esm/components/use-form/use-form-item/form-item-context.d.ts +1 -0
  133. package/esm/components/use-form/use-form-item/form-item-context.d.ts.map +1 -1
  134. package/esm/components/use-form/use-form-item/form-item-context.js +2 -1
  135. package/esm/components/use-form/use-form-item/index.d.ts +1 -0
  136. package/esm/components/use-form/use-form-item/index.d.ts.map +1 -1
  137. package/esm/components/use-form/use-form-item/index.js +2 -1
  138. package/esm/components/use-form/use-form-item/use-form-item.d.ts +1 -1
  139. package/esm/components/use-form/use-form-schema/form-schema-builder.d.ts +50 -0
  140. package/esm/components/use-form/use-form-schema/form-schema-builder.d.ts.map +1 -0
  141. package/esm/components/use-form/use-form-schema/form-schema-builder.js +371 -0
  142. package/esm/components/use-form/use-form-schema/index.d.ts +3 -0
  143. package/esm/components/use-form/use-form-schema/index.d.ts.map +1 -0
  144. package/esm/components/use-form/use-form-schema/index.js +2 -0
  145. package/esm/components/use-form/use-form.d.ts +4 -0
  146. package/esm/components/use-form/use-form.d.ts.map +1 -1
  147. package/esm/components/use-form/use-form.js +19 -9
  148. package/esm/components/use-form/use-form.type.d.ts +46 -39
  149. package/esm/components/use-form/use-form.type.d.ts.map +1 -1
  150. package/esm/components/use-input/use-input-number.d.ts.map +1 -1
  151. package/esm/components/use-input/use-input-number.js +3 -1
  152. package/esm/components/use-input/use-input-number.type.d.ts +1 -1
  153. package/esm/components/use-input/use-input-number.type.d.ts.map +1 -1
  154. package/esm/components/use-input/use-input.d.ts.map +1 -1
  155. package/esm/components/use-input/use-input.js +4 -1
  156. package/esm/components/use-pagination/use-pagination.d.ts.map +1 -1
  157. package/esm/components/use-pagination/use-pagination.js +2 -1
  158. package/esm/components/use-popup/use-popup.d.ts.map +1 -1
  159. package/esm/components/use-popup/use-popup.js +12 -24
  160. package/esm/components/use-select/use-select.type.d.ts +27 -18
  161. package/esm/components/use-select/use-select.type.d.ts.map +1 -1
  162. package/esm/components/use-table/use-table-virtual.d.ts +6 -1
  163. package/esm/components/use-table/use-table-virtual.d.ts.map +1 -1
  164. package/esm/components/use-table/use-table-virtual.js +5 -4
  165. package/esm/components/use-table/use-table.type.d.ts +70 -92
  166. package/esm/components/use-table/use-table.type.d.ts.map +1 -1
  167. package/esm/components/use-tree/use-tree-node.d.ts +7 -1
  168. package/esm/components/use-tree/use-tree-node.d.ts.map +1 -1
  169. package/esm/components/use-tree/use-tree-node.js +19 -1
  170. package/esm/components/use-tree/use-tree.d.ts.map +1 -1
  171. package/esm/components/use-tree/use-tree.js +26 -19
  172. package/esm/components/use-tree/use-tree.type.d.ts +7 -1
  173. package/esm/components/use-tree/use-tree.type.d.ts.map +1 -1
  174. package/esm/utils/dom/document.d.ts +4 -0
  175. package/esm/utils/dom/document.d.ts.map +1 -1
  176. package/esm/utils/dom/document.js +18 -1
  177. package/esm/utils/dom/element.d.ts +1 -0
  178. package/esm/utils/dom/element.d.ts.map +1 -1
  179. package/esm/utils/dom/element.js +4 -0
  180. package/esm/utils/highlight.d.ts.map +1 -1
  181. package/esm/utils/highlight.js +24 -10
  182. package/esm/utils/lazyload.d.ts.map +1 -1
  183. package/esm/utils/lazyload.js +33 -1
  184. package/esm/utils/object.d.ts +6 -0
  185. package/esm/utils/object.d.ts.map +1 -1
  186. package/esm/utils/object.js +20 -0
  187. 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,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":"AAiCA,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;;;;;;;;;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,6 +14,7 @@ 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__&&@@';
18
19
  var SUBMIT_TIMEOUT = 10;
19
20
  import { current, produce } from "../../utils/immer";
@@ -62,7 +63,8 @@ var useForm = function useForm(props) {
62
63
  resetTime: 0,
63
64
  mounted: false,
64
65
  unmounted: false,
65
- removeLock: false
66
+ removeLock: false,
67
+ schema: props.name ? new SchemaBuilder(props.name) : null
66
68
  }),
67
69
  context = _React$useRef.current;
68
70
  var getValue = usePersistFn(function (name) {
@@ -227,7 +229,7 @@ var useForm = function useForm(props) {
227
229
  var _props$onChange;
228
230
  var newValue = typeof change === 'function' ? produce(context.value, change) : change;
229
231
  context.value = newValue;
230
- (_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);
231
233
  });
232
234
  var scrollToField = usePersistFn(function (name) {
233
235
  var _document;
@@ -281,6 +283,9 @@ var useForm = function useForm(props) {
281
283
  context.removeArr.forEach(function (n) {
282
284
  deepRemove(v, n);
283
285
  context.removeArr.delete(n);
286
+ if (context.errors[n]) {
287
+ delete context.errors[n];
288
+ }
284
289
  });
285
290
  });
286
291
  };
@@ -330,6 +335,10 @@ var useForm = function useForm(props) {
330
335
  Object.keys(context.defaultValues).forEach(function (df) {
331
336
  var latestDefaultValue = getValue(df);
332
337
  if (latestDefaultValue === undefined) {
338
+ // todo: Form组件传了clearToUndefined时,加入这部分判断?
339
+ // if(context.value.hasOwnProperty(df) && clearToUndefined){
340
+ // return;
341
+ // }
333
342
  setValue(_defineProperty({}, df, context.defaultValues[df]), {
334
343
  validate: false
335
344
  });
@@ -568,7 +577,11 @@ var useForm = function useForm(props) {
568
577
  validateFieldset: validateFieldset,
569
578
  insertError: insertError,
570
579
  spliceError: spliceError,
571
- 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
+ }
572
585
  });
573
586
  var formConfig = React.useMemo(function () {
574
587
  return {
@@ -606,11 +619,6 @@ var useForm = function useForm(props) {
606
619
  // 默认值更新
607
620
  React.useEffect(function () {
608
621
  context.removeLock = false;
609
- // 内部 onChange 改的 value, 不需要更新
610
- if (props.value === context.value) {
611
- if (!isControl) update();
612
- return;
613
- }
614
622
  if (initValidate && !context.resetTime) {
615
623
  var keys = Object.keys(context.validateMap).filter(function (key) {
616
624
  var oldValue = deepGet(preValue || emptyObj, key);
@@ -620,6 +628,7 @@ var useForm = function useForm(props) {
620
628
  validateFields(keys).catch(function () {});
621
629
  }
622
630
  update();
631
+ if (!isControl) return;
623
632
  // 默认值上位时会提前触发外部的onChange, 导致外部的多次setFormValue不能合并后生效的问题(ReactDOM.render方式渲染)
624
633
  setTimeout(updateDefaultValue);
625
634
  context.resetTime = 0;
@@ -641,7 +650,8 @@ var useForm = function useForm(props) {
641
650
  ProviderProps: {
642
651
  formValue: formValue,
643
652
  formConfig: formConfig,
644
- formFunc: formFunc
653
+ formFunc: formFunc,
654
+ formSchema: context.schema
645
655
  },
646
656
  formFunc: formFunc
647
657
  };