@sheinx/hooks 3.8.0-beta.9 → 3.8.1-beta.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 (173) 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/index.d.ts.map +1 -1
  4. package/cjs/common/use-position-style/index.js +11 -8
  5. package/cjs/components/use-check/use-check.d.ts.map +1 -1
  6. package/cjs/components/use-check/use-check.js +10 -2
  7. package/cjs/components/use-datepicker/use-datepicker-format.d.ts.map +1 -1
  8. package/cjs/components/use-datepicker/use-datepicker-format.js +1 -0
  9. package/cjs/components/use-datepicker/use-time.d.ts +10 -8
  10. package/cjs/components/use-datepicker/use-time.d.ts.map +1 -1
  11. package/cjs/components/use-datepicker/use-time.js +19 -5
  12. package/cjs/components/use-datepicker/use-time.type.d.ts +5 -1
  13. package/cjs/components/use-datepicker/use-time.type.d.ts.map +1 -1
  14. package/cjs/components/use-datepicker/util.d.ts.map +1 -1
  15. package/cjs/components/use-datepicker/util.js +10 -1
  16. package/cjs/components/use-form/Provider.d.ts.map +1 -1
  17. package/cjs/components/use-form/Provider.js +7 -2
  18. package/cjs/components/use-form/form-schema-context.d.ts +6 -0
  19. package/cjs/components/use-form/form-schema-context.d.ts.map +1 -0
  20. package/cjs/components/use-form/form-schema-context.js +16 -0
  21. package/cjs/components/use-form/index.d.ts +2 -0
  22. package/cjs/components/use-form/index.d.ts.map +1 -1
  23. package/cjs/components/use-form/index.js +21 -1
  24. package/cjs/components/use-form/use-form-context.type.d.ts +6 -0
  25. package/cjs/components/use-form/use-form-context.type.d.ts.map +1 -1
  26. package/cjs/components/use-form/use-form-control/use-form-control.d.ts.map +1 -1
  27. package/cjs/components/use-form/use-form-control/use-form-control.js +34 -4
  28. package/cjs/components/use-form/use-form-control/use-form-control.type.d.ts +8 -2
  29. package/cjs/components/use-form/use-form-control/use-form-control.type.d.ts.map +1 -1
  30. package/cjs/components/use-form/use-form-flow/use-form-datum.d.ts +8 -0
  31. package/cjs/components/use-form/use-form-flow/use-form-datum.d.ts.map +1 -1
  32. package/cjs/components/use-form/use-form-item/form-item-context.d.ts +1 -0
  33. package/cjs/components/use-form/use-form-item/form-item-context.d.ts.map +1 -1
  34. package/cjs/components/use-form/use-form-item/form-item-context.js +2 -1
  35. package/cjs/components/use-form/use-form-item/index.d.ts +1 -0
  36. package/cjs/components/use-form/use-form-item/index.d.ts.map +1 -1
  37. package/cjs/components/use-form/use-form-item/index.js +7 -0
  38. package/cjs/components/use-form/use-form-item/use-form-item.d.ts +1 -1
  39. package/cjs/components/use-form/use-form-schema/form-schema-builder.d.ts +50 -0
  40. package/cjs/components/use-form/use-form-schema/form-schema-builder.d.ts.map +1 -0
  41. package/cjs/components/use-form/use-form-schema/form-schema-builder.js +377 -0
  42. package/cjs/components/use-form/use-form-schema/index.d.ts +3 -0
  43. package/cjs/components/use-form/use-form-schema/index.d.ts.map +1 -0
  44. package/cjs/components/use-form/use-form-schema/index.js +13 -0
  45. package/cjs/components/use-form/use-form.d.ts +4 -0
  46. package/cjs/components/use-form/use-form.d.ts.map +1 -1
  47. package/cjs/components/use-form/use-form.js +19 -9
  48. package/cjs/components/use-form/use-form.type.d.ts +46 -39
  49. package/cjs/components/use-form/use-form.type.d.ts.map +1 -1
  50. package/cjs/components/use-input/use-input-number.d.ts.map +1 -1
  51. package/cjs/components/use-input/use-input-number.js +3 -1
  52. package/cjs/components/use-input/use-input-number.type.d.ts +1 -1
  53. package/cjs/components/use-input/use-input-number.type.d.ts.map +1 -1
  54. package/cjs/components/use-input/use-input.d.ts.map +1 -1
  55. package/cjs/components/use-input/use-input.js +4 -1
  56. package/cjs/components/use-pagination/use-pagination.d.ts.map +1 -1
  57. package/cjs/components/use-pagination/use-pagination.js +2 -1
  58. package/cjs/components/use-popup/use-popup.d.ts.map +1 -1
  59. package/cjs/components/use-popup/use-popup.js +12 -24
  60. package/cjs/components/use-select/use-select.type.d.ts +27 -18
  61. package/cjs/components/use-select/use-select.type.d.ts.map +1 -1
  62. package/cjs/components/use-table/use-table-virtual.d.ts +6 -1
  63. package/cjs/components/use-table/use-table-virtual.d.ts.map +1 -1
  64. package/cjs/components/use-table/use-table-virtual.js +5 -4
  65. package/cjs/components/use-table/use-table.type.d.ts +70 -92
  66. package/cjs/components/use-table/use-table.type.d.ts.map +1 -1
  67. package/cjs/components/use-tree/use-tree-node.d.ts +7 -1
  68. package/cjs/components/use-tree/use-tree-node.d.ts.map +1 -1
  69. package/cjs/components/use-tree/use-tree-node.js +19 -1
  70. package/cjs/components/use-tree/use-tree.d.ts.map +1 -1
  71. package/cjs/components/use-tree/use-tree.js +26 -19
  72. package/cjs/components/use-tree/use-tree.type.d.ts +7 -1
  73. package/cjs/components/use-tree/use-tree.type.d.ts.map +1 -1
  74. package/cjs/utils/dom/document.d.ts +4 -0
  75. package/cjs/utils/dom/document.d.ts.map +1 -1
  76. package/cjs/utils/dom/document.js +19 -2
  77. package/cjs/utils/dom/element.d.ts +1 -0
  78. package/cjs/utils/dom/element.d.ts.map +1 -1
  79. package/cjs/utils/dom/element.js +5 -1
  80. package/cjs/utils/highlight.d.ts.map +1 -1
  81. package/cjs/utils/highlight.js +24 -11
  82. package/cjs/utils/lazyload.d.ts.map +1 -1
  83. package/cjs/utils/lazyload.js +33 -1
  84. package/cjs/utils/object.d.ts +6 -0
  85. package/cjs/utils/object.d.ts.map +1 -1
  86. package/cjs/utils/object.js +21 -1
  87. package/esm/common/use-filter/use-filter.d.ts.map +1 -1
  88. package/esm/common/use-filter/use-filter.js +4 -1
  89. package/esm/common/use-position-style/index.d.ts.map +1 -1
  90. package/esm/common/use-position-style/index.js +12 -9
  91. package/esm/components/use-check/use-check.d.ts.map +1 -1
  92. package/esm/components/use-check/use-check.js +10 -2
  93. package/esm/components/use-datepicker/use-datepicker-format.d.ts.map +1 -1
  94. package/esm/components/use-datepicker/use-datepicker-format.js +1 -0
  95. package/esm/components/use-datepicker/use-time.d.ts +10 -8
  96. package/esm/components/use-datepicker/use-time.d.ts.map +1 -1
  97. package/esm/components/use-datepicker/use-time.js +19 -5
  98. package/esm/components/use-datepicker/use-time.type.d.ts +5 -1
  99. package/esm/components/use-datepicker/use-time.type.d.ts.map +1 -1
  100. package/esm/components/use-datepicker/util.d.ts.map +1 -1
  101. package/esm/components/use-datepicker/util.js +10 -1
  102. package/esm/components/use-form/Provider.d.ts.map +1 -1
  103. package/esm/components/use-form/Provider.js +7 -2
  104. package/esm/components/use-form/form-schema-context.d.ts +6 -0
  105. package/esm/components/use-form/form-schema-context.d.ts.map +1 -0
  106. package/esm/components/use-form/form-schema-context.js +8 -0
  107. package/esm/components/use-form/index.d.ts +2 -0
  108. package/esm/components/use-form/index.d.ts.map +1 -1
  109. package/esm/components/use-form/index.js +3 -1
  110. package/esm/components/use-form/use-form-context.type.d.ts +6 -0
  111. package/esm/components/use-form/use-form-context.type.d.ts.map +1 -1
  112. package/esm/components/use-form/use-form-control/use-form-control.d.ts.map +1 -1
  113. package/esm/components/use-form/use-form-control/use-form-control.js +34 -4
  114. package/esm/components/use-form/use-form-control/use-form-control.type.d.ts +8 -2
  115. package/esm/components/use-form/use-form-control/use-form-control.type.d.ts.map +1 -1
  116. package/esm/components/use-form/use-form-flow/use-form-datum.d.ts +8 -0
  117. package/esm/components/use-form/use-form-flow/use-form-datum.d.ts.map +1 -1
  118. package/esm/components/use-form/use-form-item/form-item-context.d.ts +1 -0
  119. package/esm/components/use-form/use-form-item/form-item-context.d.ts.map +1 -1
  120. package/esm/components/use-form/use-form-item/form-item-context.js +2 -1
  121. package/esm/components/use-form/use-form-item/index.d.ts +1 -0
  122. package/esm/components/use-form/use-form-item/index.d.ts.map +1 -1
  123. package/esm/components/use-form/use-form-item/index.js +2 -1
  124. package/esm/components/use-form/use-form-item/use-form-item.d.ts +1 -1
  125. package/esm/components/use-form/use-form-schema/form-schema-builder.d.ts +50 -0
  126. package/esm/components/use-form/use-form-schema/form-schema-builder.d.ts.map +1 -0
  127. package/esm/components/use-form/use-form-schema/form-schema-builder.js +371 -0
  128. package/esm/components/use-form/use-form-schema/index.d.ts +3 -0
  129. package/esm/components/use-form/use-form-schema/index.d.ts.map +1 -0
  130. package/esm/components/use-form/use-form-schema/index.js +2 -0
  131. package/esm/components/use-form/use-form.d.ts +4 -0
  132. package/esm/components/use-form/use-form.d.ts.map +1 -1
  133. package/esm/components/use-form/use-form.js +19 -9
  134. package/esm/components/use-form/use-form.type.d.ts +46 -39
  135. package/esm/components/use-form/use-form.type.d.ts.map +1 -1
  136. package/esm/components/use-input/use-input-number.d.ts.map +1 -1
  137. package/esm/components/use-input/use-input-number.js +3 -1
  138. package/esm/components/use-input/use-input-number.type.d.ts +1 -1
  139. package/esm/components/use-input/use-input-number.type.d.ts.map +1 -1
  140. package/esm/components/use-input/use-input.d.ts.map +1 -1
  141. package/esm/components/use-input/use-input.js +4 -1
  142. package/esm/components/use-pagination/use-pagination.d.ts.map +1 -1
  143. package/esm/components/use-pagination/use-pagination.js +2 -1
  144. package/esm/components/use-popup/use-popup.d.ts.map +1 -1
  145. package/esm/components/use-popup/use-popup.js +12 -24
  146. package/esm/components/use-select/use-select.type.d.ts +27 -18
  147. package/esm/components/use-select/use-select.type.d.ts.map +1 -1
  148. package/esm/components/use-table/use-table-virtual.d.ts +6 -1
  149. package/esm/components/use-table/use-table-virtual.d.ts.map +1 -1
  150. package/esm/components/use-table/use-table-virtual.js +5 -4
  151. package/esm/components/use-table/use-table.type.d.ts +70 -92
  152. package/esm/components/use-table/use-table.type.d.ts.map +1 -1
  153. package/esm/components/use-tree/use-tree-node.d.ts +7 -1
  154. package/esm/components/use-tree/use-tree-node.d.ts.map +1 -1
  155. package/esm/components/use-tree/use-tree-node.js +19 -1
  156. package/esm/components/use-tree/use-tree.d.ts.map +1 -1
  157. package/esm/components/use-tree/use-tree.js +26 -19
  158. package/esm/components/use-tree/use-tree.type.d.ts +7 -1
  159. package/esm/components/use-tree/use-tree.type.d.ts.map +1 -1
  160. package/esm/utils/dom/document.d.ts +4 -0
  161. package/esm/utils/dom/document.d.ts.map +1 -1
  162. package/esm/utils/dom/document.js +18 -1
  163. package/esm/utils/dom/element.d.ts +1 -0
  164. package/esm/utils/dom/element.d.ts.map +1 -1
  165. package/esm/utils/dom/element.js +4 -0
  166. package/esm/utils/highlight.d.ts.map +1 -1
  167. package/esm/utils/highlight.js +24 -10
  168. package/esm/utils/lazyload.d.ts.map +1 -1
  169. package/esm/utils/lazyload.js +33 -1
  170. package/esm/utils/object.d.ts +6 -0
  171. package/esm/utils/object.d.ts.map +1 -1
  172. package/esm/utils/object.js +20 -0
  173. package/package.json +3 -3
@@ -0,0 +1,50 @@
1
+ interface SchemaMeta {
2
+ type?: string;
3
+ required?: boolean;
4
+ title?: string;
5
+ format?: string;
6
+ items?: any;
7
+ enum?: any[] | {
8
+ anyOf?: any[];
9
+ oneOf?: any[];
10
+ };
11
+ description?: string;
12
+ [key: string]: any;
13
+ }
14
+ export interface SchemaProperty {
15
+ type?: string;
16
+ properties?: Record<string, SchemaProperty>;
17
+ items?: SchemaProperty;
18
+ required?: string[];
19
+ title?: string;
20
+ description?: string;
21
+ format?: string;
22
+ enum?: any;
23
+ [key: string]: any;
24
+ }
25
+ export declare class SchemaBuilder {
26
+ private schema;
27
+ constructor(formName: string);
28
+ updateSchema({ path, meta }: {
29
+ path: string;
30
+ meta: SchemaMeta;
31
+ }): void;
32
+ /**
33
+ * 根据组件信息构建 schema meta
34
+ */
35
+ buildSchemaFromComponent(params: {
36
+ componentElement: any;
37
+ rules?: any[];
38
+ label?: string;
39
+ finalFieldId?: string;
40
+ separator?: string;
41
+ }): SchemaMeta;
42
+ parsePath(path?: string): string[] | null;
43
+ mergeSchema(currentSchema: SchemaProperty, pathSegments: string[], meta: SchemaMeta): void;
44
+ handleArraySegment(currentSchema: SchemaProperty, remainingSegments: string[], meta: SchemaMeta): void;
45
+ handleObjectProperty(currentSchema: SchemaProperty, propertyName: string, remainingSegments: string[], meta: SchemaMeta): void;
46
+ handleRequired(parentSchema: SchemaProperty, propertyName: string, isRequired: boolean): void;
47
+ getFormSchema(): SchemaProperty;
48
+ }
49
+ export {};
50
+ //# sourceMappingURL=form-schema-builder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"form-schema-builder.d.ts","sourceRoot":"","sources":["form-schema-builder.ts"],"names":[],"mappings":"AAAA,UAAU,UAAU;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,IAAI,CAAC,EAAE,GAAG,EAAE,GAAG;QAAE,KAAK,CAAC,EAAE,GAAG,EAAE,CAAC;QAAC,KAAK,CAAC,EAAE,GAAG,EAAE,CAAA;KAAE,CAAC;IAChD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,MAAM,WAAW,cAAc;IAC7B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAC5C,KAAK,CAAC,EAAE,cAAc,CAAC;IACvB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB;AAED,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAiB;gBACnB,QAAQ,EAAE,MAAM;IAQ5B,YAAY,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,UAAU,CAAA;KAAE,GAAG,IAAI;IAMtE;;OAEG;IACH,wBAAwB,CAAC,MAAM,EAAE;QAC/B,gBAAgB,EAAE,GAAG,CAAC;QACtB,KAAK,CAAC,EAAE,GAAG,EAAE,CAAC;QACd,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,SAAS,CAAC,EAAE,MAAM,CAAC;KACpB,GAAG,UAAU;IAuLd,SAAS,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,IAAI;IAuCzC,WAAW,CAAC,aAAa,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,UAAU,GAAG,IAAI;IAkB1F,kBAAkB,CAAC,aAAa,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,UAAU,GAAG,IAAI;IAatG,oBAAoB,CAAC,aAAa,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,UAAU,GAAG,IAAI;IA0B9H,cAAc,CAAC,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,OAAO,GAAG,IAAI;IAwB7F,aAAa,IAAI,cAAc;CAGhC"}
@@ -0,0 +1,377 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.SchemaBuilder = void 0;
7
+ var _excluded = ["required"];
8
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
9
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
10
+ function _toArray(arr) { return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest(); }
11
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
12
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
13
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
14
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
15
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
16
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
17
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
18
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
19
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
20
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
21
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
22
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
23
+ var SchemaBuilder = exports.SchemaBuilder = /*#__PURE__*/function () {
24
+ function SchemaBuilder(formName) {
25
+ _classCallCheck(this, SchemaBuilder);
26
+ _defineProperty(this, "schema", void 0);
27
+ this.schema = {
28
+ type: 'object',
29
+ title: formName,
30
+ properties: {}
31
+ };
32
+ }
33
+ _createClass(SchemaBuilder, [{
34
+ key: "updateSchema",
35
+ value: function updateSchema(_ref) {
36
+ var path = _ref.path,
37
+ meta = _ref.meta;
38
+ var pathSegments = this.parsePath(path);
39
+ if (!pathSegments) return;
40
+ this.mergeSchema(this.schema, pathSegments, meta);
41
+ }
42
+
43
+ /**
44
+ * 根据组件信息构建 schema meta
45
+ */
46
+ }, {
47
+ key: "buildSchemaFromComponent",
48
+ value: function buildSchemaFromComponent(params) {
49
+ var _componentElement$pro;
50
+ var componentElement = params.componentElement,
51
+ rules = params.rules,
52
+ label = params.label,
53
+ finalFieldId = params.finalFieldId,
54
+ separator = params.separator;
55
+ var fieldSchemaInfo = {
56
+ title: label
57
+ };
58
+ var data = componentElement.props.data;
59
+ var isRequired = rules === null || rules === void 0 ? void 0 : rules.some(function (rule) {
60
+ return rule.required;
61
+ });
62
+ fieldSchemaInfo.required = isRequired;
63
+ fieldSchemaInfo.description = '';
64
+ if (rules !== null && rules !== void 0 && rules.length) {
65
+ var messageRules = rules.filter(function (rule) {
66
+ return typeof rule.message === 'string';
67
+ });
68
+ if (messageRules.length) {
69
+ fieldSchemaInfo.description += "rules: ".concat(messageRules.map(function (rule) {
70
+ return rule.message;
71
+ }).join(', '), ";");
72
+ }
73
+ }
74
+ var itemType;
75
+ if (typeof componentElement.type === 'function') {
76
+ var componentName = componentElement.type.displayName || componentElement.type.name;
77
+ var format = componentElement.props.format || componentElement.props.keygen;
78
+ switch (componentName) {
79
+ case 'ShineoutInput':
80
+ case 'ShineoutEditableArea':
81
+ fieldSchemaInfo.type = 'string';
82
+ break;
83
+ case 'ShineoutInputNumber':
84
+ fieldSchemaInfo.type = 'number';
85
+ break;
86
+ case 'ShineoutInputPassword':
87
+ fieldSchemaInfo.type = 'string';
88
+ break;
89
+ case 'ShineoutTextarea':
90
+ fieldSchemaInfo.type = 'string';
91
+ break;
92
+ case 'ShineoutCascader':
93
+ case 'ShineoutSelect':
94
+ case 'ShineoutTreeSelect':
95
+ {
96
+ if (typeof componentElement.props.keygen !== 'boolean') {
97
+ if (typeof format === 'string') {
98
+ var _data$;
99
+ itemType = _typeof(data === null || data === void 0 ? void 0 : data[0]) === 'object' ? _typeof(data === null || data === void 0 || (_data$ = data[0]) === null || _data$ === void 0 ? void 0 : _data$[format]) : _typeof(data === null || data === void 0 ? void 0 : data[0]);
100
+ } else if (typeof format === 'function') {
101
+ itemType = _typeof(format(data === null || data === void 0 ? void 0 : data[0]));
102
+ } else {
103
+ itemType = _typeof(data === null || data === void 0 ? void 0 : data[0]);
104
+ }
105
+ } else {
106
+ itemType = _typeof(data === null || data === void 0 ? void 0 : data[0]);
107
+ }
108
+ if (componentElement.props.multiple) {
109
+ fieldSchemaInfo.type = 'array';
110
+ if (itemType !== 'undefined') {
111
+ fieldSchemaInfo.items = {
112
+ type: itemType
113
+ };
114
+ }
115
+ } else {
116
+ if (itemType !== 'undefined') {
117
+ fieldSchemaInfo.type = itemType;
118
+ }
119
+ }
120
+ if (itemType === 'object') {
121
+ // 对于对象类型,使用 oneOf 而不是 enum
122
+ if (componentElement.props.multiple) {
123
+ fieldSchemaInfo.items.oneOf = componentElement.props.data.map(function (item) {
124
+ return {
125
+ const: item,
126
+ title: (item === null || item === void 0 ? void 0 : item.title) || JSON.stringify(item)
127
+ };
128
+ });
129
+ } else {
130
+ fieldSchemaInfo.oneOf = componentElement.props.data.map(function (item) {
131
+ return {
132
+ const: item,
133
+ title: (item === null || item === void 0 ? void 0 : item.title) || JSON.stringify(item)
134
+ };
135
+ });
136
+ }
137
+ } else {
138
+ fieldSchemaInfo.enum = componentElement.props.data.map(function (item) {
139
+ return (item === null || item === void 0 ? void 0 : item[format]) || item;
140
+ });
141
+ }
142
+ break;
143
+ }
144
+ case 'ShineoutDatePicker':
145
+ if (componentElement.props.range) {
146
+ if (finalFieldId !== null && finalFieldId !== void 0 && finalFieldId.includes(separator || '')) {
147
+ fieldSchemaInfo.type = 'string';
148
+ fieldSchemaInfo.format = 'date';
149
+ } else {
150
+ fieldSchemaInfo.type = 'array';
151
+ fieldSchemaInfo.items = {
152
+ type: 'string',
153
+ format: 'date'
154
+ };
155
+ }
156
+ } else {
157
+ fieldSchemaInfo.type = 'string';
158
+ fieldSchemaInfo.format = 'date';
159
+ }
160
+ 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 || '', " ");
161
+ break;
162
+ case 'ShineoutCheckbox':
163
+ case 'ShineoutCheckboxGroup':
164
+ {
165
+ if (typeof componentElement.props.keygen !== 'boolean') {
166
+ if (typeof format === 'string') {
167
+ var _data$2;
168
+ 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]);
169
+ } else if (typeof format === 'function') {
170
+ itemType = _typeof(format(data === null || data === void 0 ? void 0 : data[0]));
171
+ } else {
172
+ itemType = _typeof(data === null || data === void 0 ? void 0 : data[0]);
173
+ }
174
+ } else {
175
+ itemType = _typeof(data === null || data === void 0 ? void 0 : data[0]);
176
+ }
177
+ fieldSchemaInfo.type = 'array';
178
+ fieldSchemaInfo.items = {
179
+ type: itemType
180
+ };
181
+
182
+ // ShineoutCheckboxGroup 有 data 时(多选的)
183
+ if (itemType === 'object') {
184
+ fieldSchemaInfo.items.oneOf = componentElement.props.data.map(function (item) {
185
+ return {
186
+ const: item,
187
+ title: (item === null || item === void 0 ? void 0 : item.title) || JSON.stringify(item)
188
+ };
189
+ });
190
+ } else {
191
+ fieldSchemaInfo.items.enum = componentElement.props.data.map(function (item) {
192
+ return (item === null || item === void 0 ? void 0 : item[format]) || item;
193
+ });
194
+ }
195
+ break;
196
+ }
197
+ case 'ShineoutRadio':
198
+ case 'ShineoutRadioGroup':
199
+ {
200
+ if (typeof componentElement.props.keygen !== 'boolean') {
201
+ if (typeof format === 'string') {
202
+ var _data$3;
203
+ 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]);
204
+ } else if (typeof format === 'function') {
205
+ itemType = _typeof(format(data === null || data === void 0 ? void 0 : data[0]));
206
+ } else {
207
+ itemType = _typeof(data === null || data === void 0 ? void 0 : data[0]);
208
+ }
209
+ } else {
210
+ itemType = _typeof(data === null || data === void 0 ? void 0 : data[0]);
211
+ }
212
+ fieldSchemaInfo.type = itemType;
213
+
214
+ // ShineoutRadioGroup 有 data 时(单选的)
215
+ if (itemType === 'object') {
216
+ fieldSchemaInfo.oneOf = componentElement.props.data.map(function (item) {
217
+ return {
218
+ const: item,
219
+ title: (item === null || item === void 0 ? void 0 : item.title) || JSON.stringify(item)
220
+ };
221
+ });
222
+ } else {
223
+ fieldSchemaInfo.enum = componentElement.props.data.map(function (item) {
224
+ return (item === null || item === void 0 ? void 0 : item[format]) || item;
225
+ });
226
+ }
227
+ break;
228
+ }
229
+ case 'ShineoutSwitch':
230
+ fieldSchemaInfo.type = 'boolean';
231
+ break;
232
+ case 'ShineoutSlider':
233
+ case 'ShineoutRate':
234
+ fieldSchemaInfo.type = 'number';
235
+ break;
236
+ default:
237
+ if (Array.isArray(componentElement.props.value) && componentElement.props.value.length === 0) {
238
+ fieldSchemaInfo.type = 'array';
239
+ fieldSchemaInfo.items = {
240
+ type: 'string'
241
+ };
242
+ } else {
243
+ fieldSchemaInfo.type = _typeof(componentElement.props.value);
244
+ }
245
+ break;
246
+ }
247
+ }
248
+ return fieldSchemaInfo;
249
+ }
250
+
251
+ // 解析路径字符串,如 'a[0].b1' -> ['a', '[0]', 'b1']
252
+ }, {
253
+ key: "parsePath",
254
+ value: function parsePath(path) {
255
+ if (!path) return null;
256
+ var segments = [];
257
+ var current = '';
258
+ var inBracket = false;
259
+ for (var i = 0; i < path.length; i++) {
260
+ var char = path[i];
261
+ if (char === '[') {
262
+ if (current) {
263
+ segments.push(current);
264
+ current = '';
265
+ }
266
+ current = '[';
267
+ inBracket = true;
268
+ } else if (char === ']') {
269
+ current += ']';
270
+ segments.push(current);
271
+ current = '';
272
+ inBracket = false;
273
+ } else if (char === '.' && !inBracket) {
274
+ if (current) {
275
+ segments.push(current);
276
+ current = '';
277
+ }
278
+ } else {
279
+ current += char;
280
+ }
281
+ }
282
+ if (current) {
283
+ segments.push(current);
284
+ }
285
+ return segments;
286
+ }
287
+
288
+ // 递归合并 schema
289
+ }, {
290
+ key: "mergeSchema",
291
+ value: function mergeSchema(currentSchema, pathSegments, meta) {
292
+ if (pathSegments.length === 0) {
293
+ // 到达叶子节点,应用元数据
294
+ Object.assign(currentSchema, meta);
295
+ return;
296
+ }
297
+ var _pathSegments = _toArray(pathSegments),
298
+ currentSegment = _pathSegments[0],
299
+ remainingSegments = _pathSegments.slice(1);
300
+ if (currentSegment.startsWith('[') && currentSegment.endsWith(']')) {
301
+ // 处理数组索引,如 [0]
302
+ this.handleArraySegment(currentSchema, remainingSegments, meta);
303
+ } else {
304
+ // 处理对象属性
305
+ this.handleObjectProperty(currentSchema, currentSegment, remainingSegments, meta);
306
+ }
307
+ }
308
+ }, {
309
+ key: "handleArraySegment",
310
+ value: function handleArraySegment(currentSchema, remainingSegments, meta) {
311
+ // 当前节点应该是数组类型
312
+ if (!currentSchema.items) {
313
+ currentSchema.type = 'array';
314
+ currentSchema.items = {
315
+ type: 'object',
316
+ properties: {}
317
+ };
318
+ }
319
+ this.mergeSchema(currentSchema.items, remainingSegments, meta);
320
+ }
321
+ }, {
322
+ key: "handleObjectProperty",
323
+ value: function handleObjectProperty(currentSchema, propertyName, remainingSegments, meta) {
324
+ // 确保当前节点有 properties
325
+ if (!currentSchema.properties) {
326
+ currentSchema.properties = {};
327
+ }
328
+
329
+ // 如果属性不存在,创建它
330
+ if (!currentSchema.properties[propertyName]) {
331
+ currentSchema.properties[propertyName] = remainingSegments.length > 0 ? {
332
+ type: 'object'
333
+ } : {};
334
+ }
335
+ if (remainingSegments.length === 0) {
336
+ // 叶子节点,应用元数据并处理 required
337
+ var required = meta.required,
338
+ restMeta = _objectWithoutProperties(meta, _excluded);
339
+ Object.assign(currentSchema.properties[propertyName], restMeta);
340
+ if (typeof required === 'boolean') {
341
+ this.handleRequired(currentSchema, propertyName, required);
342
+ }
343
+ } else {
344
+ // 继续递归
345
+ this.mergeSchema(currentSchema.properties[propertyName], remainingSegments, meta);
346
+ }
347
+ }
348
+ }, {
349
+ key: "handleRequired",
350
+ value: function handleRequired(parentSchema, propertyName, isRequired) {
351
+ // 如果required是布尔值,转换为数组形式
352
+ if (typeof parentSchema.required === 'boolean') {
353
+ return;
354
+ }
355
+ if (!parentSchema.required) {
356
+ parentSchema.required = [];
357
+ }
358
+ var requiredIndex = parentSchema.required.indexOf(propertyName);
359
+ if (isRequired && requiredIndex === -1) {
360
+ parentSchema.required.push(propertyName);
361
+ } else if (!isRequired && requiredIndex !== -1) {
362
+ parentSchema.required.splice(requiredIndex, 1);
363
+ }
364
+
365
+ // 如果 required 数组为空,删除它
366
+ if (parentSchema.required.length === 0) {
367
+ delete parentSchema.required;
368
+ }
369
+ }
370
+ }, {
371
+ key: "getFormSchema",
372
+ value: function getFormSchema() {
373
+ return this.schema;
374
+ }
375
+ }]);
376
+ return SchemaBuilder;
377
+ }();
@@ -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,13 @@
1
+ "use strict";
2
+ "use client";
3
+
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ Object.defineProperty(exports, "SchemaBuilder", {
8
+ enumerable: true,
9
+ get: function get() {
10
+ return _formSchemaBuilder.SchemaBuilder;
11
+ }
12
+ });
13
+ var _formSchemaBuilder = require("./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"}
@@ -11,6 +11,7 @@ var _usePersistFn = _interopRequireDefault(require("../../common/use-persist-fn"
11
11
  var _attribute = require("../../utils/attribute");
12
12
  var _flat = require("../../utils/flat");
13
13
  var _useDefaultValue = require("../../common/use-default-value");
14
+ var _formSchemaBuilder = require("./use-form-schema/form-schema-builder");
14
15
  var _immer = require("../../utils/immer");
15
16
  var _utils = require("../../utils");
16
17
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -71,7 +72,8 @@ var useForm = function useForm(props) {
71
72
  resetTime: 0,
72
73
  mounted: false,
73
74
  unmounted: false,
74
- removeLock: false
75
+ removeLock: false,
76
+ schema: props.name ? new _formSchemaBuilder.SchemaBuilder(props.name) : null
75
77
  }),
76
78
  context = _React$useRef.current;
77
79
  var getValue = (0, _usePersistFn.default)(function (name) {
@@ -236,7 +238,7 @@ var useForm = function useForm(props) {
236
238
  var _props$onChange;
237
239
  var newValue = typeof change === 'function' ? (0, _immer.produce)(context.value, change) : change;
238
240
  context.value = newValue;
239
- (_props$onChange = props.onChange) === null || _props$onChange === void 0 || _props$onChange.call(props, context.value);
241
+ (_props$onChange = props.onChange) === null || _props$onChange === void 0 || _props$onChange.call(props, newValue);
240
242
  });
241
243
  var scrollToField = (0, _usePersistFn.default)(function (name) {
242
244
  var _document;
@@ -290,6 +292,9 @@ var useForm = function useForm(props) {
290
292
  context.removeArr.forEach(function (n) {
291
293
  (0, _utils.deepRemove)(v, n);
292
294
  context.removeArr.delete(n);
295
+ if (context.errors[n]) {
296
+ delete context.errors[n];
297
+ }
293
298
  });
294
299
  });
295
300
  };
@@ -339,6 +344,10 @@ var useForm = function useForm(props) {
339
344
  Object.keys(context.defaultValues).forEach(function (df) {
340
345
  var latestDefaultValue = getValue(df);
341
346
  if (latestDefaultValue === undefined) {
347
+ // todo: Form组件传了clearToUndefined时,加入这部分判断?
348
+ // if(context.value.hasOwnProperty(df) && clearToUndefined){
349
+ // return;
350
+ // }
342
351
  setValue(_defineProperty({}, df, context.defaultValues[df]), {
343
352
  validate: false
344
353
  });
@@ -577,7 +586,11 @@ var useForm = function useForm(props) {
577
586
  validateFieldset: validateFieldset,
578
587
  insertError: insertError,
579
588
  spliceError: spliceError,
580
- scrollToField: scrollToField
589
+ scrollToField: scrollToField,
590
+ getFormSchema: function getFormSchema() {
591
+ var _context$schema;
592
+ return (_context$schema = context.schema) === null || _context$schema === void 0 ? void 0 : _context$schema.getFormSchema();
593
+ }
581
594
  });
582
595
  var formConfig = React.useMemo(function () {
583
596
  return {
@@ -615,11 +628,6 @@ var useForm = function useForm(props) {
615
628
  // 默认值更新
616
629
  React.useEffect(function () {
617
630
  context.removeLock = false;
618
- // 内部 onChange 改的 value, 不需要更新
619
- if (props.value === context.value) {
620
- if (!isControl) update();
621
- return;
622
- }
623
631
  if (initValidate && !context.resetTime) {
624
632
  var keys = Object.keys(context.validateMap).filter(function (key) {
625
633
  var oldValue = (0, _utils.deepGet)(preValue || emptyObj, key);
@@ -629,6 +637,7 @@ var useForm = function useForm(props) {
629
637
  validateFields(keys).catch(function () {});
630
638
  }
631
639
  update();
640
+ if (!isControl) return;
632
641
  // 默认值上位时会提前触发外部的onChange, 导致外部的多次setFormValue不能合并后生效的问题(ReactDOM.render方式渲染)
633
642
  setTimeout(updateDefaultValue);
634
643
  context.resetTime = 0;
@@ -650,7 +659,8 @@ var useForm = function useForm(props) {
650
659
  ProviderProps: {
651
660
  formValue: formValue,
652
661
  formConfig: formConfig,
653
- formFunc: formFunc
662
+ formFunc: formFunc,
663
+ formSchema: context.schema
654
664
  },
655
665
  formFunc: formFunc
656
666
  };