@tachybase/schema 0.23.40 → 0.23.47

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 (273) hide show
  1. package/lib/core/effects/index.d.ts +2 -0
  2. package/lib/core/effects/index.js +23 -0
  3. package/lib/core/effects/onFieldEffects.d.ts +27 -0
  4. package/lib/core/effects/onFieldEffects.js +158 -0
  5. package/lib/core/effects/onFormEffects.d.ts +24 -0
  6. package/lib/core/effects/onFormEffects.js +117 -0
  7. package/lib/core/global.d.js +0 -0
  8. package/lib/core/index.d.ts +4 -0
  9. package/lib/core/index.js +27 -0
  10. package/lib/core/models/ArrayField.d.ts +17 -0
  11. package/lib/core/models/ArrayField.js +145 -0
  12. package/lib/core/models/BaseField.d.ts +72 -0
  13. package/lib/core/models/BaseField.js +285 -0
  14. package/lib/core/models/Field.d.ts +70 -0
  15. package/lib/core/models/Field.js +426 -0
  16. package/lib/core/models/Form.d.ts +102 -0
  17. package/lib/core/models/Form.js +483 -0
  18. package/lib/core/models/Graph.d.ts +8 -0
  19. package/lib/core/models/Graph.js +77 -0
  20. package/lib/core/models/Heart.d.ts +16 -0
  21. package/lib/core/models/Heart.js +91 -0
  22. package/lib/core/models/LifeCycle.d.ts +14 -0
  23. package/lib/core/models/LifeCycle.js +64 -0
  24. package/lib/core/models/ObjectField.d.ts +12 -0
  25. package/lib/core/models/ObjectField.js +64 -0
  26. package/lib/core/models/Query.d.ts +18 -0
  27. package/lib/core/models/Query.js +105 -0
  28. package/lib/core/models/VoidField.d.ts +14 -0
  29. package/lib/core/models/VoidField.js +117 -0
  30. package/lib/core/models/index.d.ts +9 -0
  31. package/lib/core/models/index.js +37 -0
  32. package/lib/core/models/types.d.ts +9 -0
  33. package/lib/core/models/types.js +15 -0
  34. package/lib/core/shared/checkers.d.ts +117 -0
  35. package/lib/core/shared/checkers.js +109 -0
  36. package/lib/core/shared/constants.d.ts +48 -0
  37. package/lib/core/shared/constants.js +86 -0
  38. package/lib/core/shared/effective.d.ts +9 -0
  39. package/lib/core/shared/effective.js +91 -0
  40. package/lib/core/shared/externals.d.ts +8 -0
  41. package/lib/core/shared/externals.js +87 -0
  42. package/lib/core/shared/internals.d.ts +54 -0
  43. package/lib/core/shared/internals.js +956 -0
  44. package/lib/core/types.d.ts +275 -0
  45. package/lib/core/types.js +76 -0
  46. package/lib/grid/index.d.ts +67 -0
  47. package/lib/grid/index.js +378 -0
  48. package/lib/grid/observer.d.ts +19 -0
  49. package/lib/grid/observer.js +107 -0
  50. package/lib/index.d.ts +12 -24
  51. package/lib/index.js +27 -244
  52. package/lib/json-schema/compiler.d.ts +8 -0
  53. package/lib/json-schema/compiler.js +129 -0
  54. package/lib/json-schema/global.d.js +0 -0
  55. package/lib/json-schema/index.d.ts +2 -0
  56. package/lib/json-schema/index.js +23 -0
  57. package/lib/json-schema/patches.d.ts +5 -0
  58. package/lib/json-schema/patches.js +68 -0
  59. package/lib/json-schema/polyfills/SPECIFICATION_1_0.d.ts +2 -0
  60. package/lib/json-schema/polyfills/SPECIFICATION_1_0.js +132 -0
  61. package/lib/json-schema/polyfills/index.d.ts +1 -0
  62. package/lib/json-schema/polyfills/index.js +21 -0
  63. package/lib/json-schema/schema.d.ts +88 -0
  64. package/lib/json-schema/schema.js +231 -0
  65. package/lib/json-schema/shared.d.ts +62 -0
  66. package/lib/json-schema/shared.js +232 -0
  67. package/lib/json-schema/transformer.d.ts +4 -0
  68. package/lib/json-schema/transformer.js +238 -0
  69. package/lib/json-schema/types.d.ts +119 -0
  70. package/lib/json-schema/types.js +15 -0
  71. package/lib/path/contexts.d.ts +10 -0
  72. package/lib/path/contexts.js +49 -0
  73. package/lib/path/destructor.d.ts +15 -0
  74. package/lib/path/destructor.js +151 -0
  75. package/lib/path/index.d.ts +51 -0
  76. package/lib/path/index.js +513 -0
  77. package/lib/path/matcher.d.ts +33 -0
  78. package/lib/path/matcher.js +197 -0
  79. package/lib/path/parser.d.ts +33 -0
  80. package/lib/path/parser.js +379 -0
  81. package/lib/path/shared.d.ts +13 -0
  82. package/lib/path/shared.js +121 -0
  83. package/lib/path/tokenizer.d.ts +27 -0
  84. package/lib/path/tokenizer.js +269 -0
  85. package/lib/path/tokens.d.ts +27 -0
  86. package/lib/path/tokens.js +216 -0
  87. package/lib/path/types.d.ts +88 -0
  88. package/lib/path/types.js +63 -0
  89. package/lib/react/components/ArrayField.d.ts +6 -0
  90. package/lib/react/components/ArrayField.js +44 -0
  91. package/lib/react/components/ExpressionScope.d.ts +2 -0
  92. package/lib/react/components/ExpressionScope.js +35 -0
  93. package/lib/react/components/Field.d.ts +5 -0
  94. package/lib/react/components/Field.js +45 -0
  95. package/lib/react/components/FormConsumer.d.ts +2 -0
  96. package/lib/react/components/FormConsumer.js +36 -0
  97. package/lib/react/components/FormProvider.d.ts +2 -0
  98. package/lib/react/components/FormProvider.js +35 -0
  99. package/lib/react/components/ObjectField.d.ts +6 -0
  100. package/lib/react/components/ObjectField.js +39 -0
  101. package/lib/react/components/ReactiveField.d.ts +11 -0
  102. package/lib/react/components/ReactiveField.js +115 -0
  103. package/lib/react/components/RecordScope.d.ts +2 -0
  104. package/lib/react/components/RecordScope.js +65 -0
  105. package/lib/react/components/RecordsScope.d.ts +2 -0
  106. package/lib/react/components/RecordsScope.js +43 -0
  107. package/lib/react/components/RecursionField.d.ts +2 -0
  108. package/lib/react/components/RecursionField.js +105 -0
  109. package/lib/react/components/SchemaField.d.ts +41 -0
  110. package/lib/react/components/SchemaField.js +154 -0
  111. package/lib/react/components/VoidField.d.ts +5 -0
  112. package/lib/react/components/VoidField.js +39 -0
  113. package/lib/react/components/index.d.ts +11 -0
  114. package/lib/react/components/index.js +41 -0
  115. package/lib/react/global.d.js +0 -0
  116. package/lib/react/hooks/index.d.ts +6 -0
  117. package/lib/react/hooks/index.js +31 -0
  118. package/lib/react/hooks/useAttach.d.ts +6 -0
  119. package/lib/react/hooks/useAttach.js +35 -0
  120. package/lib/react/hooks/useExpressionScope.d.ts +1 -0
  121. package/lib/react/hooks/useExpressionScope.js +30 -0
  122. package/lib/react/hooks/useField.d.ts +2 -0
  123. package/lib/react/hooks/useField.js +32 -0
  124. package/lib/react/hooks/useFieldSchema.d.ts +2 -0
  125. package/lib/react/hooks/useFieldSchema.js +32 -0
  126. package/lib/react/hooks/useForm.d.ts +2 -0
  127. package/lib/react/hooks/useForm.js +32 -0
  128. package/lib/react/hooks/useFormEffects.d.ts +2 -0
  129. package/lib/react/hooks/useFormEffects.js +42 -0
  130. package/lib/react/hooks/useParentForm.d.ts +2 -0
  131. package/lib/react/hooks/useParentForm.js +40 -0
  132. package/lib/react/index.d.ts +5 -0
  133. package/lib/react/index.js +29 -0
  134. package/lib/react/shared/connect.d.ts +9 -0
  135. package/lib/react/shared/connect.js +118 -0
  136. package/lib/react/shared/context.d.ts +14 -0
  137. package/lib/react/shared/context.js +74 -0
  138. package/lib/react/shared/index.d.ts +2 -0
  139. package/lib/react/shared/index.js +23 -0
  140. package/lib/react/shared/render.d.ts +2 -0
  141. package/lib/react/shared/render.js +69 -0
  142. package/lib/react/types.d.ts +84 -0
  143. package/lib/react/types.js +15 -0
  144. package/lib/reactive/action.d.ts +2 -0
  145. package/lib/reactive/action.js +48 -0
  146. package/lib/reactive/annotations/box.d.ts +7 -0
  147. package/lib/reactive/annotations/box.js +76 -0
  148. package/lib/reactive/annotations/computed.d.ts +12 -0
  149. package/lib/reactive/annotations/computed.js +154 -0
  150. package/lib/reactive/annotations/index.d.ts +5 -0
  151. package/lib/reactive/annotations/index.js +29 -0
  152. package/lib/reactive/annotations/observable.d.ts +4 -0
  153. package/lib/reactive/annotations/observable.js +67 -0
  154. package/lib/reactive/annotations/ref.d.ts +6 -0
  155. package/lib/reactive/annotations/ref.js +78 -0
  156. package/lib/reactive/annotations/shallow.d.ts +2 -0
  157. package/lib/reactive/annotations/shallow.js +67 -0
  158. package/lib/reactive/array.d.ts +12 -0
  159. package/lib/reactive/array.js +83 -0
  160. package/lib/reactive/autorun.d.ts +7 -0
  161. package/lib/reactive/autorun.js +155 -0
  162. package/lib/reactive/batch.d.ts +2 -0
  163. package/lib/reactive/batch.js +40 -0
  164. package/lib/reactive/checkers.d.ts +10 -0
  165. package/lib/reactive/checkers.js +60 -0
  166. package/lib/reactive/environment.d.ts +28 -0
  167. package/lib/reactive/environment.js +76 -0
  168. package/lib/reactive/externals.d.ts +10 -0
  169. package/lib/reactive/externals.js +156 -0
  170. package/lib/reactive/global.d.js +0 -0
  171. package/lib/reactive/handlers.d.ts +4 -0
  172. package/lib/reactive/handlers.js +246 -0
  173. package/lib/reactive/index.d.ts +10 -0
  174. package/lib/reactive/index.js +39 -0
  175. package/lib/reactive/internals.d.ts +17 -0
  176. package/lib/reactive/internals.js +139 -0
  177. package/lib/reactive/model.d.ts +3 -0
  178. package/lib/reactive/model.js +68 -0
  179. package/lib/reactive/observable.d.ts +9 -0
  180. package/lib/reactive/observable.js +50 -0
  181. package/lib/reactive/observe.d.ts +2 -0
  182. package/lib/reactive/observe.js +58 -0
  183. package/lib/reactive/reaction.d.ts +21 -0
  184. package/lib/reactive/reaction.js +278 -0
  185. package/lib/reactive/tracker.d.ts +7 -0
  186. package/lib/reactive/tracker.js +63 -0
  187. package/lib/reactive/tree.d.ts +25 -0
  188. package/lib/reactive/tree.js +106 -0
  189. package/lib/reactive/types.d.ts +79 -0
  190. package/lib/reactive/types.js +21 -0
  191. package/lib/reactive/untracked.d.ts +4 -0
  192. package/lib/reactive/untracked.js +29 -0
  193. package/lib/reactive-react/hooks/index.d.ts +9 -0
  194. package/lib/reactive-react/hooks/index.js +48 -0
  195. package/lib/reactive-react/hooks/useCompatEffect.d.ts +2 -0
  196. package/lib/reactive-react/hooks/useCompatEffect.js +60 -0
  197. package/lib/reactive-react/hooks/useCompatFactory.d.ts +3 -0
  198. package/lib/reactive-react/hooks/useCompatFactory.js +74 -0
  199. package/lib/reactive-react/hooks/useDidUpdate.d.ts +1 -0
  200. package/lib/reactive-react/hooks/useDidUpdate.js +38 -0
  201. package/lib/reactive-react/hooks/useForceUpdate.d.ts +1 -0
  202. package/lib/reactive-react/hooks/useForceUpdate.js +76 -0
  203. package/lib/reactive-react/hooks/useLayoutEffect.d.ts +2 -0
  204. package/lib/reactive-react/hooks/useLayoutEffect.js +28 -0
  205. package/lib/reactive-react/hooks/useObserver.d.ts +2 -0
  206. package/lib/reactive-react/hooks/useObserver.js +43 -0
  207. package/lib/reactive-react/index.d.ts +3 -0
  208. package/lib/reactive-react/index.js +25 -0
  209. package/lib/reactive-react/observer.d.ts +8 -0
  210. package/lib/reactive-react/observer.js +64 -0
  211. package/lib/reactive-react/shared/gc.d.ts +8 -0
  212. package/lib/reactive-react/shared/gc.js +59 -0
  213. package/lib/reactive-react/shared/global.d.ts +1 -0
  214. package/lib/reactive-react/shared/global.js +50 -0
  215. package/lib/reactive-react/shared/immediate.d.ts +1 -0
  216. package/lib/reactive-react/shared/immediate.js +40 -0
  217. package/lib/reactive-react/shared/index.d.ts +2 -0
  218. package/lib/reactive-react/shared/index.js +23 -0
  219. package/lib/reactive-react/types.d.ts +14 -0
  220. package/lib/reactive-react/types.js +15 -0
  221. package/lib/shared/array.d.ts +35 -0
  222. package/lib/shared/array.js +189 -0
  223. package/lib/shared/case.d.ts +6 -0
  224. package/lib/shared/case.js +39 -0
  225. package/lib/shared/checkers.d.ts +21 -0
  226. package/lib/shared/checkers.js +77 -0
  227. package/lib/shared/clone.d.ts +2 -0
  228. package/lib/shared/clone.js +97 -0
  229. package/lib/shared/compare.d.ts +1 -0
  230. package/lib/shared/compare.js +129 -0
  231. package/lib/shared/defaults.d.ts +6 -0
  232. package/lib/shared/defaults.js +63 -0
  233. package/lib/shared/deprecate.d.ts +1 -0
  234. package/lib/shared/deprecate.js +42 -0
  235. package/lib/shared/global.d.ts +1 -0
  236. package/lib/shared/global.js +50 -0
  237. package/lib/shared/index.d.ts +16 -0
  238. package/lib/shared/index.js +51 -0
  239. package/lib/shared/instanceof.d.ts +1 -0
  240. package/lib/shared/instanceof.js +36 -0
  241. package/lib/shared/isEmpty.d.ts +3 -0
  242. package/lib/shared/isEmpty.js +94 -0
  243. package/lib/shared/merge.d.ts +12 -0
  244. package/lib/shared/merge.js +214 -0
  245. package/lib/shared/middleware.d.ts +4 -0
  246. package/lib/shared/middleware.js +41 -0
  247. package/lib/shared/path.d.ts +3 -0
  248. package/lib/shared/path.js +27 -0
  249. package/lib/shared/string.d.ts +1 -0
  250. package/lib/shared/string.js +38 -0
  251. package/lib/shared/subscribable.d.ts +11 -0
  252. package/lib/shared/subscribable.js +74 -0
  253. package/lib/shared/uid.d.ts +1 -0
  254. package/lib/shared/uid.js +35 -0
  255. package/lib/validator/formats.d.ts +16 -0
  256. package/lib/validator/formats.js +40 -0
  257. package/lib/validator/index.d.ts +4 -0
  258. package/lib/validator/index.js +27 -0
  259. package/lib/validator/locale.d.ts +219 -0
  260. package/lib/validator/locale.js +240 -0
  261. package/lib/validator/parser.d.ts +5 -0
  262. package/lib/validator/parser.js +153 -0
  263. package/lib/validator/registry.d.ts +15 -0
  264. package/lib/validator/registry.js +116 -0
  265. package/lib/validator/rules.d.ts +3 -0
  266. package/lib/validator/rules.js +154 -0
  267. package/lib/validator/template.d.ts +2 -0
  268. package/lib/validator/template.js +42 -0
  269. package/lib/validator/types.d.ts +62 -0
  270. package/lib/validator/types.js +28 -0
  271. package/lib/validator/validator.d.ts +2 -0
  272. package/lib/validator/validator.js +63 -0
  273. package/package.json +16 -10
@@ -0,0 +1,378 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var grid_exports = {};
20
+ __export(grid_exports, {
21
+ Grid: () => Grid
22
+ });
23
+ module.exports = __toCommonJS(grid_exports);
24
+ var import_reactive = require("../reactive");
25
+ var import_observer = require("./observer");
26
+ const SpanRegExp = /span\s*(\d+)/;
27
+ const isValid = /* @__PURE__ */ __name((value) => value !== void 0 && value !== null, "isValid");
28
+ const calcBreakpointIndex = /* @__PURE__ */ __name((breakpoints, width) => {
29
+ if (Array.isArray(breakpoints)) {
30
+ for (let i = 0; i < breakpoints.length; i++) {
31
+ if (width <= breakpoints[i]) {
32
+ return i;
33
+ }
34
+ }
35
+ }
36
+ return -1;
37
+ }, "calcBreakpointIndex");
38
+ const calcFactor = /* @__PURE__ */ __name((value, breakpointIndex) => {
39
+ if (Array.isArray(value)) {
40
+ if (breakpointIndex === -1) return value[0];
41
+ return value[breakpointIndex] ?? value[value.length - 1];
42
+ } else {
43
+ return value;
44
+ }
45
+ }, "calcFactor");
46
+ const parseGridNode = /* @__PURE__ */ __name((elements) => {
47
+ return Array.from(elements).reduce((buf, element, index) => {
48
+ const style = getComputedStyle(element);
49
+ const visible = !(style.display === "none");
50
+ const origin = element.getAttribute("data-grid-span");
51
+ const span = parseSpan(style.gridColumnStart) ?? 1;
52
+ const originSpan = Number(origin ?? span);
53
+ const node = {
54
+ index,
55
+ span,
56
+ visible,
57
+ originSpan,
58
+ element
59
+ };
60
+ if (!origin) {
61
+ element.setAttribute("data-grid-span", String(span));
62
+ }
63
+ return buf.concat(node);
64
+ }, []);
65
+ }, "parseGridNode");
66
+ const calcChildTotalColumns = /* @__PURE__ */ __name((nodes, shadow = false) => nodes.reduce((buf, node) => {
67
+ if (!shadow) {
68
+ if (!node.visible) return buf;
69
+ }
70
+ if (node.originSpan === -1) return buf + (node.span ?? 1);
71
+ return buf + node.span;
72
+ }, 0), "calcChildTotalColumns");
73
+ const calcChildOriginTotalColumns = /* @__PURE__ */ __name((nodes, shadow = false) => nodes.reduce((buf, node) => {
74
+ if (!shadow) {
75
+ if (!node.visible) return buf;
76
+ }
77
+ if (node.originSpan === -1) return buf + (node.span ?? 1);
78
+ return buf + node.originSpan;
79
+ }, 0), "calcChildOriginTotalColumns");
80
+ const calcSatisfyColumns = /* @__PURE__ */ __name((width, maxColumns, minColumns, maxWidth, minWidth, gap) => {
81
+ const results = [];
82
+ for (let columns = minColumns; columns <= maxColumns; columns++) {
83
+ const innerWidth = width - (columns - 1) * gap;
84
+ const columnWidth = innerWidth / columns;
85
+ if (columnWidth >= minWidth && columnWidth <= maxWidth) {
86
+ results.push(columns);
87
+ } else if (columnWidth < minWidth) {
88
+ results.push(Math.min(Math.floor(innerWidth / minWidth), maxColumns));
89
+ } else if (columnWidth > maxWidth) {
90
+ results.push(Math.min(Math.floor(innerWidth / maxWidth), maxColumns));
91
+ }
92
+ }
93
+ return Math.max(...results);
94
+ }, "calcSatisfyColumns");
95
+ const parseSpan = /* @__PURE__ */ __name((gridColumnStart) => {
96
+ var _a;
97
+ return Number(((_a = String(gridColumnStart).match(SpanRegExp)) == null ? void 0 : _a[1]) ?? 1);
98
+ }, "parseSpan");
99
+ const factor = /* @__PURE__ */ __name((value, grid) => isValid(value) ? calcFactor(value, grid.breakpoint) : value, "factor");
100
+ const resolveChildren = /* @__PURE__ */ __name((grid) => {
101
+ let walked = 0, shadowWalked = 0, rowIndex = 0, shadowRowIndex = 0;
102
+ if (!grid.ready) return;
103
+ grid.children = grid.children.map((node) => {
104
+ var _a;
105
+ const columnIndex = walked % grid.columns;
106
+ const shadowColumnIndex = shadowWalked % grid.columns;
107
+ const remainColumns = grid.columns - columnIndex;
108
+ const originSpan = node.originSpan;
109
+ const targetSpan = originSpan > grid.columns ? grid.columns : originSpan;
110
+ const span = grid.options.strictAutoFit ? targetSpan : targetSpan > remainColumns ? remainColumns : targetSpan;
111
+ const gridColumn = originSpan === -1 ? `span ${remainColumns} / -1` : `span ${span} / auto`;
112
+ if (node.element.style.gridColumn !== gridColumn) {
113
+ node.element.style.gridColumn = gridColumn;
114
+ }
115
+ if (node.visible) {
116
+ walked += span;
117
+ }
118
+ shadowWalked += span;
119
+ if (columnIndex === 0) {
120
+ rowIndex++;
121
+ }
122
+ if (shadowColumnIndex === 0) {
123
+ shadowRowIndex++;
124
+ }
125
+ node.shadowRow = shadowRowIndex;
126
+ node.shadowColumn = shadowColumnIndex + 1;
127
+ if (node.visible) {
128
+ node.row = rowIndex;
129
+ node.column = columnIndex + 1;
130
+ }
131
+ if ((_a = grid.options) == null ? void 0 : _a.shouldVisible) {
132
+ if (!grid.options.shouldVisible(node, grid)) {
133
+ if (node.visible) {
134
+ node.element.style.display = "none";
135
+ }
136
+ node.visible = false;
137
+ } else {
138
+ if (!node.visible) {
139
+ node.element.style.display = "";
140
+ }
141
+ node.visible = true;
142
+ }
143
+ }
144
+ return node;
145
+ });
146
+ }, "resolveChildren");
147
+ const nextTick = /* @__PURE__ */ __name((callback) => Promise.resolve(0).then(callback), "nextTick");
148
+ const _Grid = class _Grid {
149
+ constructor(options) {
150
+ this.width = 0;
151
+ this.height = 0;
152
+ this.children = [];
153
+ this.childTotalColumns = 0;
154
+ this.shadowChildTotalColumns = 0;
155
+ this.childOriginTotalColumns = 0;
156
+ this.shadowChildOriginTotalColumns = 0;
157
+ this.ready = false;
158
+ this.connect = /* @__PURE__ */ __name((container) => {
159
+ if (container) {
160
+ this.container = container;
161
+ const initialize = import_reactive.batch.bound(() => {
162
+ digest();
163
+ this.ready = true;
164
+ });
165
+ const digest = import_reactive.batch.bound(() => {
166
+ this.children = parseGridNode(this.container.children);
167
+ this.childTotalColumns = calcChildTotalColumns(this.children);
168
+ this.shadowChildTotalColumns = calcChildTotalColumns(this.children, true);
169
+ this.childOriginTotalColumns = calcChildOriginTotalColumns(this.children);
170
+ this.shadowChildOriginTotalColumns = calcChildOriginTotalColumns(this.children, true);
171
+ const rect = this.container.getBoundingClientRect();
172
+ if (rect.width && rect.height) {
173
+ this.width = rect.width;
174
+ this.height = rect.height;
175
+ }
176
+ resolveChildren(this);
177
+ nextTick(() => {
178
+ var _a, _b;
179
+ (_b = (_a = this.options) == null ? void 0 : _a.onDigest) == null ? void 0 : _b.call(_a, this);
180
+ });
181
+ if (!this.ready) {
182
+ nextTick(() => {
183
+ var _a, _b;
184
+ (_b = (_a = this.options) == null ? void 0 : _a.onInitialized) == null ? void 0 : _b.call(_a, this);
185
+ });
186
+ }
187
+ });
188
+ const mutationObserver = new import_observer.ChildListMutationObserver(digest);
189
+ const resizeObserver = new ResizeObserver(digest);
190
+ const dispose = (0, import_reactive.reaction)(() => ({ ...this.options }), digest);
191
+ resizeObserver.observe(this.container);
192
+ mutationObserver.observe(this.container, {
193
+ attributeFilter: ["data-grid-span"],
194
+ attributes: true
195
+ });
196
+ initialize();
197
+ return () => {
198
+ resizeObserver.unobserve(this.container);
199
+ resizeObserver.disconnect();
200
+ mutationObserver.disconnect();
201
+ dispose();
202
+ this.children = [];
203
+ };
204
+ }
205
+ return () => {
206
+ };
207
+ }, "connect");
208
+ this.options = {
209
+ breakpoints: [720, 1280, 1920],
210
+ columnGap: 8,
211
+ rowGap: 4,
212
+ minWidth: 100,
213
+ colWrap: true,
214
+ strictAutoFit: false,
215
+ ...options
216
+ };
217
+ (0, import_reactive.define)(this, {
218
+ options: import_reactive.observable.shallow,
219
+ width: import_reactive.observable.ref,
220
+ height: import_reactive.observable.ref,
221
+ ready: import_reactive.observable.ref,
222
+ children: import_reactive.observable.ref,
223
+ childOriginTotalColumns: import_reactive.observable.ref,
224
+ shadowChildOriginTotalColumns: import_reactive.observable.ref,
225
+ shadowChildTotalColumns: import_reactive.observable.ref,
226
+ childTotalColumns: import_reactive.observable.ref,
227
+ columns: import_reactive.observable.computed,
228
+ templateColumns: import_reactive.observable.computed,
229
+ gap: import_reactive.observable.computed,
230
+ maxColumns: import_reactive.observable.computed,
231
+ minColumns: import_reactive.observable.computed,
232
+ maxWidth: import_reactive.observable.computed,
233
+ minWidth: import_reactive.observable.computed,
234
+ breakpoints: import_reactive.observable.computed,
235
+ breakpoint: import_reactive.observable.computed,
236
+ rowGap: import_reactive.observable.computed,
237
+ columnGap: import_reactive.observable.computed,
238
+ colWrap: import_reactive.observable.computed
239
+ });
240
+ }
241
+ set breakpoints(breakpoints) {
242
+ this.options.breakpoints = breakpoints;
243
+ }
244
+ get breakpoints() {
245
+ return this.options.breakpoints;
246
+ }
247
+ get breakpoint() {
248
+ return calcBreakpointIndex(this.options.breakpoints, this.width);
249
+ }
250
+ set maxWidth(maxWidth) {
251
+ this.options.maxWidth = maxWidth;
252
+ }
253
+ get maxWidth() {
254
+ return factor(this.options.maxWidth, this) ?? Infinity;
255
+ }
256
+ set minWidth(minWidth) {
257
+ this.options.minWidth = minWidth;
258
+ }
259
+ get minWidth() {
260
+ return factor(this.options.minWidth, this) ?? 100;
261
+ }
262
+ set maxColumns(maxColumns) {
263
+ this.options.maxColumns = maxColumns;
264
+ }
265
+ get maxColumns() {
266
+ return factor(this.options.maxColumns, this) ?? Infinity;
267
+ }
268
+ set maxRows(maxRows) {
269
+ this.options.maxRows = maxRows;
270
+ }
271
+ get maxRows() {
272
+ return this.options.maxRows ?? Infinity;
273
+ }
274
+ set minColumns(minColumns) {
275
+ this.options.minColumns = minColumns;
276
+ }
277
+ get minColumns() {
278
+ return factor(this.options.minColumns, this) ?? 1;
279
+ }
280
+ set rowGap(rowGap) {
281
+ this.options.rowGap = rowGap;
282
+ }
283
+ get rowGap() {
284
+ return factor(this.options.rowGap, this) ?? 5;
285
+ }
286
+ set columnGap(columnGap) {
287
+ this.options.columnGap = columnGap;
288
+ }
289
+ get columnGap() {
290
+ return factor(this.options.columnGap, this) ?? 10;
291
+ }
292
+ set colWrap(colWrap) {
293
+ this.options.colWrap = colWrap;
294
+ }
295
+ get colWrap() {
296
+ return factor(this.options.colWrap, this) ?? true;
297
+ }
298
+ get columns() {
299
+ if (!this.ready) return 0;
300
+ const originTotalColumns = this.childOriginTotalColumns;
301
+ if (this.colWrap === false) {
302
+ return originTotalColumns;
303
+ }
304
+ const baseColumns = this.childSize;
305
+ const strictMaxWidthColumns = Math.round(this.width / (this.maxWidth + this.columnGap));
306
+ const looseMaxWidthColumns = Math.min(originTotalColumns, strictMaxWidthColumns);
307
+ const maxWidthColumns = this.options.strictAutoFit ? strictMaxWidthColumns : looseMaxWidthColumns;
308
+ const strictMinWidthColumns = Math.round(this.width / (this.minWidth + this.columnGap));
309
+ const looseMinWidthColumns = Math.min(originTotalColumns, strictMinWidthColumns);
310
+ const minWidthColumns = this.options.strictAutoFit ? strictMinWidthColumns : looseMinWidthColumns;
311
+ const minCalculatedColumns = Math.min(baseColumns, originTotalColumns, maxWidthColumns, minWidthColumns);
312
+ const maxCalculatedColumns = Math.max(baseColumns, originTotalColumns, maxWidthColumns, minWidthColumns);
313
+ const finalColumns = calcSatisfyColumns(
314
+ this.width,
315
+ maxCalculatedColumns,
316
+ minCalculatedColumns,
317
+ this.maxWidth,
318
+ this.minWidth,
319
+ this.columnGap
320
+ );
321
+ if (finalColumns >= this.maxColumns) {
322
+ return this.maxColumns;
323
+ }
324
+ if (finalColumns <= this.minColumns) {
325
+ return this.minColumns;
326
+ }
327
+ return finalColumns;
328
+ }
329
+ get rows() {
330
+ return Math.ceil(this.childTotalColumns / this.columns);
331
+ }
332
+ get shadowRows() {
333
+ return Math.ceil(this.shadowChildTotalColumns / this.columns);
334
+ }
335
+ get templateColumns() {
336
+ if (!this.width) return "";
337
+ if (this.maxWidth === Infinity) {
338
+ return `repeat(${this.columns},minmax(0,1fr))`;
339
+ }
340
+ if (this.options.strictAutoFit !== true) {
341
+ const columnWidth = (this.width - (this.columns - 1) * this.columnGap) / this.columns;
342
+ if (columnWidth < this.minWidth || columnWidth > this.maxWidth) {
343
+ return `repeat(${this.columns},minmax(0,1fr))`;
344
+ }
345
+ }
346
+ return `repeat(${this.columns},minmax(${this.minWidth}px,${this.maxWidth}px))`;
347
+ }
348
+ get gap() {
349
+ return `${this.rowGap}px ${this.columnGap}px`;
350
+ }
351
+ get childSize() {
352
+ return this.children.length;
353
+ }
354
+ get fullnessLastColumn() {
355
+ var _a;
356
+ return this.columns === ((_a = this.children[this.childSize - 1]) == null ? void 0 : _a.span);
357
+ }
358
+ };
359
+ __name(_Grid, "Grid");
360
+ _Grid.id = /* @__PURE__ */ __name((options = {}) => JSON.stringify(
361
+ [
362
+ "maxRows",
363
+ "maxColumns",
364
+ "minColumns",
365
+ "maxWidth",
366
+ "minWidth",
367
+ "breakpoints",
368
+ "columnGap",
369
+ "rowGap",
370
+ "colWrap",
371
+ "strictAutoFit"
372
+ ].map((key) => options[key])
373
+ ), "id");
374
+ let Grid = _Grid;
375
+ // Annotate the CommonJS export names for ESM import in node:
376
+ 0 && (module.exports = {
377
+ Grid
378
+ });
@@ -0,0 +1,19 @@
1
+ type ChildNode = {
2
+ element?: HTMLElement;
3
+ observer?: MutationObserver;
4
+ dispose?: () => void;
5
+ };
6
+ export declare class ChildListMutationObserver {
7
+ observer: MutationObserver;
8
+ callback: MutationCallback;
9
+ childList: ChildNode[];
10
+ init: MutationObserverInit;
11
+ constructor(callback: MutationCallback);
12
+ observeChildList(element: HTMLElement): void;
13
+ addObserver(element: HTMLElement): void;
14
+ removeObserver(element: HTMLElement): void;
15
+ handler: (mutations: MutationRecord[]) => void;
16
+ observe: (element: HTMLElement, init?: MutationObserverInit) => void;
17
+ disconnect: () => void;
18
+ }
19
+ export {};
@@ -0,0 +1,107 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var observer_exports = {};
20
+ __export(observer_exports, {
21
+ ChildListMutationObserver: () => ChildListMutationObserver
22
+ });
23
+ module.exports = __toCommonJS(observer_exports);
24
+ const isHTMLElement = /* @__PURE__ */ __name((node) => node.nodeType === 1, "isHTMLElement");
25
+ const _ChildListMutationObserver = class _ChildListMutationObserver {
26
+ constructor(callback) {
27
+ this.childList = [];
28
+ this.handler = /* @__PURE__ */ __name((mutations) => {
29
+ mutations.forEach((mutation) => {
30
+ if (mutation.type === "childList") {
31
+ mutation.addedNodes.forEach((node) => {
32
+ if (isHTMLElement(node)) {
33
+ this.addObserver(node);
34
+ }
35
+ });
36
+ mutation.removedNodes.forEach((node) => {
37
+ if (isHTMLElement(node)) {
38
+ this.removeObserver(node);
39
+ }
40
+ });
41
+ }
42
+ });
43
+ this.callback(mutations, this.observer);
44
+ }, "handler");
45
+ this.observe = /* @__PURE__ */ __name((element, init) => {
46
+ this.init = init;
47
+ this.observeChildList(element);
48
+ this.observer.observe(element, {
49
+ ...this.init,
50
+ subtree: false,
51
+ childList: true,
52
+ characterData: false,
53
+ characterDataOldValue: false,
54
+ attributeOldValue: false
55
+ });
56
+ }, "observe");
57
+ this.disconnect = /* @__PURE__ */ __name(() => {
58
+ this.observer.disconnect();
59
+ }, "disconnect");
60
+ this.callback = callback;
61
+ this.observer = new MutationObserver(this.handler);
62
+ }
63
+ observeChildList(element) {
64
+ Array.from(element.children).forEach((node) => {
65
+ this.addObserver(node);
66
+ });
67
+ }
68
+ addObserver(element) {
69
+ const child = this.childList.find((t) => t.element === element);
70
+ if (!child) {
71
+ const childIndex = this.childList.length;
72
+ const child2 = {
73
+ element,
74
+ observer: new MutationObserver(this.callback),
75
+ dispose: /* @__PURE__ */ __name(() => {
76
+ if (child2.observer) {
77
+ child2.observer.disconnect();
78
+ delete child2.observer;
79
+ this.childList.splice(childIndex, 1);
80
+ }
81
+ }, "dispose")
82
+ };
83
+ child2.observer.observe(child2.element, {
84
+ ...this.init,
85
+ subtree: false,
86
+ childList: false,
87
+ characterData: false,
88
+ characterDataOldValue: false,
89
+ attributeOldValue: false
90
+ });
91
+ this.childList.push(child2);
92
+ }
93
+ }
94
+ removeObserver(element) {
95
+ var _a;
96
+ const child = this.childList.find((t) => t.element === element);
97
+ if (child) {
98
+ (_a = child.dispose) == null ? void 0 : _a.call(child);
99
+ }
100
+ }
101
+ };
102
+ __name(_ChildListMutationObserver, "ChildListMutationObserver");
103
+ let ChildListMutationObserver = _ChildListMutationObserver;
104
+ // Annotate the CommonJS export names for ESM import in node:
105
+ 0 && (module.exports = {
106
+ ChildListMutationObserver
107
+ });
package/lib/index.d.ts CHANGED
@@ -1,24 +1,12 @@
1
- import { ArrayField, FormPathPattern, GeneralField, IExchangeArrayStateProps, INodePatch, ISpliceArrayStateProps } from '@formily/core';
2
- import { FormPath } from '@formily/shared';
3
- export * from '@formily/core';
4
- export type { ArrayField, Field, FormPathPattern, GeneralField, ObjectField } from '@formily/core';
5
- export * from '@formily/grid';
6
- export * from '@formily/json-schema';
7
- export { type IFieldProps, type IRecursionFieldProps, type ISchemaFieldProps, type ISchemaFieldReactFactoryOptions, type IVoidFieldProps, type JSXComponent, type SchemaReactComponents, FormConsumer, ArrayField as ArrayFieldComponent, ExpressionScope, Field as FieldComponent, FieldContext, FormContext, FormProvider, ObjectField as ObjectFieldComponent, RecursionField, SchemaComponentsContext, SchemaContext, SchemaExpressionScopeContext, SchemaOptionsContext, VoidField as VoidFieldComponent, connect, createSchemaField, mapProps, mapReadPretty, useExpressionScope, useField, useFieldSchema, useForm, useFormEffects, RecordScope, RecordsScope, useParentForm, } from '@formily/react';
8
- export * from '@formily/reactive';
9
- export * from '@formily/reactive-react';
10
- export * from '@formily/shared';
11
- export * from '@formily/validator';
12
- interface IRecycleTarget {
13
- onMount: () => void;
14
- onUnmount: () => void;
15
- }
16
- export declare const useAttach: <T extends IRecycleTarget>(target: T) => T;
17
- export declare const NumberIndexReg: RegExp;
18
- export declare const exchangeArrayState: (field: ArrayField, props: IExchangeArrayStateProps) => void;
19
- export declare const patchFieldStates: (target: Record<string, GeneralField>, patches: INodePatch<GeneralField>[]) => void;
20
- export declare const destroy: (target: Record<string, GeneralField>, address: string, forceClear?: boolean) => void;
21
- export declare const locateNode: (field: GeneralField, address: FormPathPattern) => GeneralField;
22
- export declare const buildFieldPath: (field: GeneralField) => FormPath;
23
- export declare const buildDataPath: (fields: Record<string, GeneralField>, pattern: FormPath) => FormPath;
24
- export declare const spliceArrayState: (field: ArrayField, props?: ISpliceArrayStateProps) => void;
1
+ export { buildDataPath, buildFieldPath, spliceArrayState, locateNode, destroy, patchFieldStates, exchangeArrayState, } from './core/shared/internals';
2
+ export { NumberIndexReg } from './core/shared/constants';
3
+ export { useAttach } from './react/hooks/useAttach';
4
+ export * from './core';
5
+ export type { ArrayField, Field, FormPathPattern, GeneralField, ObjectField } from './core';
6
+ export * from './grid';
7
+ export * from './json-schema';
8
+ export { type IFieldProps, type IRecursionFieldProps, type ISchemaFieldProps, type ISchemaFieldReactFactoryOptions, type IVoidFieldProps, type JSXComponent, type SchemaReactComponents, FormConsumer, ArrayField as ArrayFieldComponent, ExpressionScope, Field as FieldComponent, FieldContext, FormContext, FormProvider, ObjectField as ObjectFieldComponent, RecursionField, SchemaComponentsContext, SchemaContext, SchemaExpressionScopeContext, SchemaOptionsContext, VoidField as VoidFieldComponent, connect, createSchemaField, mapProps, mapReadPretty, useExpressionScope, useField, useFieldSchema, useForm, useFormEffects, RecordScope, RecordsScope, useParentForm, } from './react';
9
+ export * from './reactive';
10
+ export * from './reactive-react';
11
+ export * from './shared';
12
+ export * from './validator';