@reformer/core 10.2.0 → 11.0.0-beta.10

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 (285) hide show
  1. package/README.md +90 -68
  2. package/dist/behaviors-value-D05z3my6.js +109 -0
  3. package/dist/behaviors.d.ts +1 -1
  4. package/dist/behaviors.js +376 -211
  5. package/dist/create-model-DPSG3I0O.js +30 -0
  6. package/dist/date-utils-90-qZbse.js +43 -0
  7. package/dist/en-HP8XEych.js +44 -0
  8. package/dist/form/aggregate-signals.d.ts +21 -63
  9. package/dist/form/behaviors/collections.d.ts +84 -0
  10. package/dist/form/behaviors/context.d.ts +56 -0
  11. package/dist/form/behaviors/index.d.ts +30 -0
  12. package/dist/form/behaviors/internals.d.ts +41 -0
  13. package/dist/form/{behaviors-node.d.ts → behaviors/node.d.ts} +28 -5
  14. package/dist/form/behaviors/operators.d.ts +59 -0
  15. package/dist/form/behaviors/schema-operators.d.ts +83 -0
  16. package/dist/form/behaviors/types.d.ts +37 -0
  17. package/dist/form/create-form.d.ts +59 -70
  18. package/dist/form/flow/flow.d.ts +87 -0
  19. package/dist/form/form-bundle.d.ts +153 -0
  20. package/dist/form/form-level.d.ts +121 -0
  21. package/dist/form/form-proxy-builder.d.ts +6 -22
  22. package/dist/form/index.d.ts +23 -27
  23. package/dist/form/nodes/form-array-node.d.ts +100 -0
  24. package/dist/form/nodes/form-control-node.d.ts +73 -0
  25. package/dist/form/nodes/form-group-node.d.ts +66 -0
  26. package/dist/form/nodes/node-kind.d.ts +29 -0
  27. package/dist/form/nodes/state/availability.d.ts +6 -0
  28. package/dist/form/nodes/state/component.d.ts +6 -0
  29. package/dist/form/nodes/state/index.d.ts +12 -0
  30. package/dist/form/nodes/state/interaction.d.ts +13 -0
  31. package/dist/form/nodes/state/issues.d.ts +9 -0
  32. package/dist/form/nodes/state/pending.d.ts +6 -0
  33. package/dist/form/schema/compile.d.ts +59 -0
  34. package/dist/form/schema/compiled.d.ts +143 -0
  35. package/dist/form/schema/row-key.d.ts +11 -0
  36. package/dist/form/schema-controller.d.ts +159 -0
  37. package/dist/form/schema-subtree.d.ts +28 -0
  38. package/dist/form/signal-node-registry.d.ts +27 -22
  39. package/dist/form/submission.d.ts +93 -0
  40. package/dist/form/type-guards.d.ts +14 -73
  41. package/dist/form/types/contracts.d.ts +21 -91
  42. package/dist/form/types/field-config.d.ts +27 -0
  43. package/dist/form/types/index.d.ts +5 -91
  44. package/dist/form/types/nodes.d.ts +159 -0
  45. package/dist/form/types/schema-node.d.ts +148 -50
  46. package/dist/form/types/validation-schema.d.ts +24 -41
  47. package/dist/form/validation/context.d.ts +67 -0
  48. package/dist/form/validation/index.d.ts +24 -28
  49. package/dist/form/validation/operators.d.ts +101 -0
  50. package/dist/form/validation/run.d.ts +120 -0
  51. package/dist/form/validation/strategy.d.ts +89 -0
  52. package/dist/form/validation/types.d.ts +83 -0
  53. package/dist/form/validators/date-utils.d.ts +42 -0
  54. package/dist/form/validators/email.d.ts +23 -0
  55. package/dist/form/{validation/validators → validators}/file-type.d.ts +10 -10
  56. package/dist/form/{validation/validators → validators}/file-utils.d.ts +3 -2
  57. package/dist/form/validators/future-date.d.ts +23 -0
  58. package/dist/form/{validation/validators → validators}/index.d.ts +7 -4
  59. package/dist/form/validators/integer.d.ts +22 -0
  60. package/dist/form/validators/is-date.d.ts +24 -0
  61. package/dist/form/validators/is-number.d.ts +25 -0
  62. package/dist/form/validators/max-age.d.ts +28 -0
  63. package/dist/form/validators/max-date.d.ts +25 -0
  64. package/dist/form/{validation/validators → validators}/max-file-size.d.ts +10 -10
  65. package/dist/form/validators/max-files.d.ts +26 -0
  66. package/dist/form/validators/max-length.d.ts +33 -0
  67. package/dist/form/validators/max-total-file-size.d.ts +26 -0
  68. package/dist/form/validators/max.d.ts +26 -0
  69. package/dist/form/validators/min-age.d.ts +27 -0
  70. package/dist/form/validators/min-date.d.ts +25 -0
  71. package/dist/form/{validation/validators → validators}/min-file-size.d.ts +10 -10
  72. package/dist/form/validators/min-files.d.ts +27 -0
  73. package/dist/form/validators/min-length.d.ts +33 -0
  74. package/dist/form/validators/min.d.ts +26 -0
  75. package/dist/form/validators/multiple-of.d.ts +25 -0
  76. package/dist/form/validators/non-negative.d.ts +22 -0
  77. package/dist/form/validators/non-zero.d.ts +22 -0
  78. package/dist/form/validators/past-date.d.ts +23 -0
  79. package/dist/form/validators/pattern.d.ts +26 -0
  80. package/dist/form/{validation/validators → validators}/phone.d.ts +11 -11
  81. package/dist/form/validators/required.d.ts +29 -0
  82. package/dist/form/validators/url.d.ts +45 -0
  83. package/dist/form/validators/validation-issue.d.ts +8 -0
  84. package/dist/i18n/descriptor.d.ts +54 -0
  85. package/dist/i18n/en.json.d.ts +49 -0
  86. package/dist/i18n/loader.d.ts +71 -0
  87. package/dist/i18n/locale-store.d.ts +46 -0
  88. package/dist/i18n/locale.d.ts +90 -0
  89. package/dist/i18n/message-format.d.ts +136 -0
  90. package/dist/i18n/resolve-localized.d.ts +17 -0
  91. package/dist/i18n/ru.json.d.ts +49 -0
  92. package/dist/i18n/translator.d.ts +61 -0
  93. package/dist/i18n/validation-message.d.ts +53 -0
  94. package/dist/i18n.d.ts +26 -0
  95. package/dist/i18n.js +86 -0
  96. package/dist/index.d.ts +18 -6
  97. package/dist/index.js +932 -2779
  98. package/dist/loader-BWkigpVe.js +52 -0
  99. package/dist/locale/en.d.ts +2 -0
  100. package/dist/locale/en.js +5 -0
  101. package/dist/locale/en.json +45 -0
  102. package/dist/locale/index.d.ts +18 -0
  103. package/dist/locale/ru.d.ts +2 -0
  104. package/dist/locale/ru.js +44 -0
  105. package/dist/locale/ru.json +45 -0
  106. package/dist/locale-CG54AU2Q.js +219 -0
  107. package/dist/locale.d.ts +2 -0
  108. package/dist/locale.js +9 -0
  109. package/dist/{state → model}/behaviors-value.d.ts +24 -6
  110. package/dist/{state/form-model.d.ts → model/create-model.d.ts} +18 -4
  111. package/dist/{state → model}/derived-registry.d.ts +1 -1
  112. package/dist/model/index.d.ts +42 -0
  113. package/dist/model/model-nodes.d.ts +190 -0
  114. package/dist/model/model-signals-proxy.d.ts +63 -0
  115. package/dist/model/model-value-proxy.d.ts +84 -0
  116. package/dist/{state → model}/safe-effect.d.ts +50 -2
  117. package/dist/model/types.d.ts +239 -0
  118. package/dist/model.d.ts +2 -0
  119. package/dist/model.js +27 -0
  120. package/dist/node-kind-C-r6ZMdo.js +15 -0
  121. package/dist/platforms/react/field-binding/field-adapter.d.ts +87 -0
  122. package/dist/platforms/react/field-binding/field-handle.d.ts +53 -0
  123. package/dist/platforms/react/form-bundle-context.d.ts +27 -0
  124. package/dist/{form → platforms/react}/hooks/types.d.ts +60 -38
  125. package/dist/platforms/react/hooks/use-form-bundle.d.ts +41 -0
  126. package/dist/platforms/react/hooks/use-form-flow.d.ts +40 -0
  127. package/dist/{form → platforms/react}/hooks/use-form-validation.d.ts +13 -7
  128. package/dist/{form → platforms/react}/hooks/useArrayLength.d.ts +6 -6
  129. package/dist/{form → platforms/react}/hooks/useFormControl.d.ts +7 -9
  130. package/dist/{form → platforms/react}/hooks/useFormControlValue.d.ts +18 -18
  131. package/dist/{form → platforms/react}/hooks/useSignalSubscription.d.ts +9 -1
  132. package/dist/platforms/react/i18n/context.d.ts +18 -0
  133. package/dist/platforms/react/i18n/hooks.d.ts +65 -0
  134. package/dist/platforms/react/i18n/provider.d.ts +59 -0
  135. package/dist/platforms/react/index.d.ts +30 -0
  136. package/dist/react.d.ts +22 -0
  137. package/dist/react.js +505 -0
  138. package/dist/runtime-token.d.ts +22 -0
  139. package/dist/safe-effect-BazLOv1g.js +669 -0
  140. package/dist/schema-controller-CpiO2JoK.js +143 -0
  141. package/dist/signals.d.ts +15 -9
  142. package/dist/signals.js +11 -6
  143. package/dist/strategy-DzvnsWLh.js +375 -0
  144. package/dist/type-guards-D-N_5Ddh.js +19 -0
  145. package/dist/validation-issue-B9mjI8jz.js +7 -0
  146. package/dist/validation-message-Ced9MGxs.js +194 -0
  147. package/dist/validation.d.ts +1 -1
  148. package/dist/validation.js +11 -165
  149. package/dist/validators/email.d.ts +1 -1
  150. package/dist/validators/email.js +5 -8
  151. package/dist/validators/future-date.d.ts +1 -1
  152. package/dist/validators/future-date.js +10 -13
  153. package/dist/validators/integer.d.ts +1 -1
  154. package/dist/validators/integer.js +4 -7
  155. package/dist/validators/is-date.d.ts +1 -1
  156. package/dist/validators/is-date.js +5 -8
  157. package/dist/validators/is-number.d.ts +1 -1
  158. package/dist/validators/is-number.js +4 -7
  159. package/dist/validators/max-age.d.ts +1 -1
  160. package/dist/validators/max-age.js +8 -12
  161. package/dist/validators/max-date.d.ts +1 -1
  162. package/dist/validators/max-date.js +10 -13
  163. package/dist/validators/max-length.d.ts +1 -1
  164. package/dist/validators/max-length.js +7 -10
  165. package/dist/validators/max.d.ts +1 -1
  166. package/dist/validators/max.js +4 -7
  167. package/dist/validators/min-age.d.ts +1 -1
  168. package/dist/validators/min-age.js +10 -11
  169. package/dist/validators/min-date.d.ts +1 -1
  170. package/dist/validators/min-date.js +8 -11
  171. package/dist/validators/min-length.d.ts +1 -1
  172. package/dist/validators/min-length.js +4 -7
  173. package/dist/validators/min.d.ts +1 -1
  174. package/dist/validators/min.js +4 -7
  175. package/dist/validators/multiple-of.d.ts +1 -1
  176. package/dist/validators/multiple-of.js +11 -10
  177. package/dist/validators/non-negative.d.ts +1 -1
  178. package/dist/validators/non-negative.js +2 -5
  179. package/dist/validators/non-zero.d.ts +1 -1
  180. package/dist/validators/non-zero.js +4 -7
  181. package/dist/validators/past-date.d.ts +1 -1
  182. package/dist/validators/past-date.js +10 -13
  183. package/dist/validators/pattern.d.ts +1 -1
  184. package/dist/validators/pattern.js +5 -8
  185. package/dist/validators/phone.d.ts +1 -1
  186. package/dist/validators/phone.js +10 -11
  187. package/dist/validators/required.d.ts +1 -1
  188. package/dist/validators/required.js +4 -7
  189. package/dist/validators/url.d.ts +1 -1
  190. package/dist/validators/url.js +48 -17
  191. package/dist/validators.d.ts +1 -5
  192. package/dist/validators.js +98 -154
  193. package/docs/llms/01-api-reference.md +89 -0
  194. package/docs/llms/02-quick-start.md +181 -0
  195. package/docs/llms/03-api-signatures.md +494 -0
  196. package/docs/llms/04-common-patterns.md +204 -0
  197. package/docs/llms/05-common-mistakes.md +192 -0
  198. package/docs/llms/06-troubleshooting.md +16 -0
  199. package/docs/llms/07-complete-import.md +130 -0
  200. package/docs/llms/08-form-types.md +54 -0
  201. package/docs/llms/09-formschema.md +191 -0
  202. package/docs/llms/10-arrays.md +241 -0
  203. package/docs/llms/11-async-watchfield.md +53 -0
  204. package/docs/llms/12-array-cleanup.md +31 -0
  205. package/docs/llms/13-multi-step.md +162 -0
  206. package/docs/llms/14-extended-mistakes.md +101 -0
  207. package/docs/llms/15-project-structure.md +279 -0
  208. package/docs/llms/16-ui-components.md +229 -0
  209. package/docs/llms/17-nonexistent-api.md +278 -0
  210. package/docs/llms/18-conditional-fields.md +222 -0
  211. package/docs/llms/19-reading-values.md +100 -0
  212. package/docs/llms/20-compute-vs-watch.md +153 -0
  213. package/docs/llms/21-array-operations.md +163 -0
  214. package/docs/llms/22-cycle-detection.md +86 -0
  215. package/docs/llms/23-copy-from.md +141 -0
  216. package/docs/llms/24-sync-fields.md +115 -0
  217. package/docs/llms/25-reset-when.md +122 -0
  218. package/docs/llms/26-transform-value.md +136 -0
  219. package/docs/llms/27-revalidate-when.md +133 -0
  220. package/docs/llms/28-submit-and-reset.md +409 -0
  221. package/docs/llms/29-async-preload.md +203 -0
  222. package/docs/llms/30-type-safety-recipes.md +213 -0
  223. package/docs/llms/31-async-validator-debounce.md +178 -0
  224. package/docs/llms/32-async-options-loading.md +108 -0
  225. package/docs/llms/33-validation-strategy.md +305 -0
  226. package/docs/llms/34-i18n.md +298 -0
  227. package/docs/llms/35-unified-contract.md +309 -0
  228. package/docs/llms/36-issue-messages.md +284 -0
  229. package/docs/llms/37-compiled-schema.md +332 -0
  230. package/docs/llms/38-form-flow.md +396 -0
  231. package/llms-index.json +1 -0
  232. package/llms.txt +10014 -3826
  233. package/package.json +77 -15
  234. package/dist/behaviors-node-DGEFMTQu.js +0 -18
  235. package/dist/behaviors-value-C7dSEhCc.js +0 -134
  236. package/dist/date-utils-dTT_x_Be.js +0 -31
  237. package/dist/derived-registry-CluZCQ7U.js +0 -16
  238. package/dist/form/behaviors.d.ts +0 -133
  239. package/dist/form/error-handler.d.ts +0 -166
  240. package/dist/form/factories/index.d.ts +0 -6
  241. package/dist/form/factories/node-factory.d.ts +0 -188
  242. package/dist/form/form-submitter.d.ts +0 -125
  243. package/dist/form/nodes/array-node.d.ts +0 -360
  244. package/dist/form/nodes/field-node.d.ts +0 -294
  245. package/dist/form/nodes/form-node.d.ts +0 -340
  246. package/dist/form/nodes/group-node.d.ts +0 -288
  247. package/dist/form/nodes/model-array-node.d.ts +0 -121
  248. package/dist/form/status-machine.d.ts +0 -153
  249. package/dist/form/types/deep-schema.d.ts +0 -116
  250. package/dist/form/types/form-proxy.d.ts +0 -141
  251. package/dist/form/unique-id.d.ts +0 -53
  252. package/dist/form/validation/validators/date-utils.d.ts +0 -30
  253. package/dist/form/validation/validators/email.d.ts +0 -23
  254. package/dist/form/validation/validators/future-date.d.ts +0 -23
  255. package/dist/form/validation/validators/integer.d.ts +0 -22
  256. package/dist/form/validation/validators/is-date.d.ts +0 -23
  257. package/dist/form/validation/validators/is-number.d.ts +0 -24
  258. package/dist/form/validation/validators/max-age.d.ts +0 -25
  259. package/dist/form/validation/validators/max-date.d.ts +0 -25
  260. package/dist/form/validation/validators/max-files.d.ts +0 -26
  261. package/dist/form/validation/validators/max-length.d.ts +0 -27
  262. package/dist/form/validation/validators/max-total-file-size.d.ts +0 -26
  263. package/dist/form/validation/validators/max.d.ts +0 -25
  264. package/dist/form/validation/validators/min-age.d.ts +0 -25
  265. package/dist/form/validation/validators/min-date.d.ts +0 -25
  266. package/dist/form/validation/validators/min-files.d.ts +0 -26
  267. package/dist/form/validation/validators/min-length.d.ts +0 -27
  268. package/dist/form/validation/validators/min.d.ts +0 -25
  269. package/dist/form/validation/validators/multiple-of.d.ts +0 -24
  270. package/dist/form/validation/validators/non-negative.d.ts +0 -22
  271. package/dist/form/validation/validators/non-zero.d.ts +0 -22
  272. package/dist/form/validation/validators/past-date.d.ts +0 -23
  273. package/dist/form/validation/validators/pattern.d.ts +0 -33
  274. package/dist/form/validation/validators/required.d.ts +0 -32
  275. package/dist/form/validation/validators/url.d.ts +0 -43
  276. package/dist/form/validation-schema.d.ts +0 -106
  277. package/dist/form/validation-strategy.d.ts +0 -55
  278. package/dist/form/validators.d.ts +0 -6
  279. package/dist/form-model-DYCzGGKF.js +0 -286
  280. package/dist/state/index.d.ts +0 -31
  281. package/dist/state/subscription-manager.d.ts +0 -180
  282. package/dist/state/types.d.ts +0 -144
  283. package/dist/state.d.ts +0 -2
  284. package/dist/state.js +0 -21
  285. package/dist/subscription-manager-705bls97.js +0 -171
@@ -0,0 +1,669 @@
1
+ import { isSignal as B } from "./signals.js";
2
+ import { batch as D, signal as W, computed as J } from "@preact/signals-core";
3
+ const h = /* @__PURE__ */ new WeakMap();
4
+ function ce(e) {
5
+ h.set(e, (h.get(e) ?? 0) + 1);
6
+ }
7
+ function le(e) {
8
+ const t = h.get(e);
9
+ t !== void 0 && (t <= 1 ? h.delete(e) : h.set(e, t - 1));
10
+ }
11
+ function O(e) {
12
+ return h.has(e);
13
+ }
14
+ const f = (e) => !(e === null || typeof e != "object" || Array.isArray(e) || e instanceof Date || typeof Blob < "u" && e instanceof Blob || typeof File < "u" && e instanceof File), d = (e, t) => e === "" ? String(t) : `${e}.${t}`, p = (e) => /^\d+$/.test(e), l = (e) => {
15
+ if (e instanceof Date) return new Date(e.getTime());
16
+ if (Array.isArray(e)) return e.map(l);
17
+ if (f(e)) {
18
+ const t = {};
19
+ for (const r of Object.keys(e)) t[r] = l(e[r]);
20
+ return t;
21
+ }
22
+ return e;
23
+ }, A = (e, t) => {
24
+ if (e === t || Number.isNaN(e) && Number.isNaN(t)) return !0;
25
+ if (e instanceof Date && t instanceof Date) return Object.is(e.getTime(), t.getTime());
26
+ if (Array.isArray(e) && Array.isArray(t))
27
+ return e.length !== t.length ? !1 : e.every((r, n) => A(r, t[n]));
28
+ if (f(e) && f(t)) {
29
+ const r = Object.keys(e), n = Object.keys(t);
30
+ return r.length !== n.length ? !1 : r.every((i) => A(e[i], t[i]));
31
+ }
32
+ return !1;
33
+ }, R = Symbol.for("@reformer/core:arrayBlank"), M = (e) => Array.isArray(e) ? e[R] : void 0, Q = (e, t) => f(e) ? e[t] : void 0;
34
+ function C(e, t) {
35
+ if (!f(e) || !f(t)) return t;
36
+ const r = { ...e };
37
+ for (const [n, i] of Object.entries(t))
38
+ r[n] = i === void 0 ? e[n] : C(e[n], i);
39
+ return r;
40
+ }
41
+ function fe(e, t = []) {
42
+ const r = [...t];
43
+ return Object.defineProperty(r, R, { value: e }), r;
44
+ }
45
+ const q = /* @__PURE__ */ new WeakMap();
46
+ function X(e) {
47
+ return q.get(e);
48
+ }
49
+ class Y {
50
+ constructor(t, r) {
51
+ this.path = r;
52
+ const n = W(t);
53
+ n.__path = r, this.signal = n, this.initial = l(t), q.set(this.signal, this);
54
+ }
55
+ kind = "leaf";
56
+ signal;
57
+ initial;
58
+ rebase(t) {
59
+ this.path = t, this.signal.__path = t;
60
+ }
61
+ /** Реактивное чтение (внутри effect/computed создаёт зависимость). */
62
+ read() {
63
+ return this.signal.value;
64
+ }
65
+ /** Нереактивный снимок. */
66
+ peek() {
67
+ return this.signal.peek();
68
+ }
69
+ set(t) {
70
+ this.signal.value = t;
71
+ }
72
+ /**
73
+ * Вернуть значение к снимку. Производное поле (цель `compute`, поле сервера с `markDerived`)
74
+ * сброс не пишет — как `set` и `patch`: значением владеет поведение, а снимок такого поля снят
75
+ * до первого расчёта, и `compute` пересчитал бы его только при смене источников.
76
+ */
77
+ resetToInitial() {
78
+ O(this.signal) || (this.signal.value = l(this.initial));
79
+ }
80
+ captureInitial() {
81
+ this.initial = l(this.signal.peek());
82
+ }
83
+ /** Значение точки отсчёта — копия: правка полученного снимок не трогает. */
84
+ reference() {
85
+ return l(this.initial);
86
+ }
87
+ dirty() {
88
+ return this.differsFrom(this.initial);
89
+ }
90
+ /**
91
+ * Отличается ли значение от снимка. Производное поле отличием не считается: его пишет поведение,
92
+ * а не пользователь — иначе форма без единой правки была бы «изменённой».
93
+ */
94
+ differsFrom(t) {
95
+ return !O(this.signal) && !A(this.signal.peek(), t);
96
+ }
97
+ }
98
+ class U {
99
+ /**
100
+ * @param shape Образец той же группы из шаблона родительского массива: из него вложенные
101
+ * массивы берут шаблоны, если значение пришло обычными данными (см. {@link ModelArrayNode}).
102
+ */
103
+ constructor(t, r, n) {
104
+ this.path = r;
105
+ for (const i of Object.keys(t)) {
106
+ const s = n && (() => Q(n(), i));
107
+ this.children.set(i, x(t[i], d(r, i), s));
108
+ }
109
+ }
110
+ kind = "group";
111
+ children = /* @__PURE__ */ new Map();
112
+ rebase(t) {
113
+ this.path = t;
114
+ for (const [r, n] of this.children) n.rebase(d(t, r));
115
+ }
116
+ /** Реактивное чтение поддерева (внутри effect/computed подписывает на все листья группы). */
117
+ read() {
118
+ const t = {};
119
+ for (const [r, n] of this.children) t[r] = n.read();
120
+ return t;
121
+ }
122
+ peek() {
123
+ const t = {};
124
+ for (const [r, n] of this.children) t[r] = n.peek();
125
+ return t;
126
+ }
127
+ /**
128
+ * Полная установка: значение ожидается целиком. Ключи, которых в нём нет, остаются прежними —
129
+ * как у {@link patch}, — но в dev о них сообщает предупреждение: неполный объект в `set` — почти
130
+ * всегда ошибка вызывающего кода, а не намерение.
131
+ */
132
+ set(t) {
133
+ const r = [];
134
+ if (this.write(t, r), r.length > 0 && process.env.NODE_ENV !== "production") {
135
+ const n = this.path === "" ? "model" : `model.${this.path}`, i = t == null || typeof t != "object" ? "значение не объект — группа осталась прежней" : `в значении нет ключей ${r.map((s) => `«${s}»`).join(", ")} — эти поля остались прежними`;
136
+ console.warn(
137
+ `[@reformer/core] ${n}.set(...): ${i}. \`set\` ожидает объект целиком; для частичного обновления есть \`patch\`.`
138
+ );
139
+ }
140
+ }
141
+ /**
142
+ * Частичное обновление: записываются только переданные ключи. Вложенная группа сливается так
143
+ * же, массив заменяется целиком.
144
+ */
145
+ patch(t) {
146
+ this.write(t, void 0, !0);
147
+ }
148
+ /**
149
+ * Запись значения по ключам группы. Лишние ключи значения игнорируются, производные поля не
150
+ * затираются.
151
+ *
152
+ * @param missing - Куда складывать пути ключей, для которых значение не пришло. Передаётся при
153
+ * полной установке ({@link set}); при частичной ({@link patch}) — `undefined`.
154
+ * @param partial - Частичное обновление: ключ со значением `undefined` — «не трогать», как в
155
+ * частичном значении элемента массива (`DeepPartial` допускает `{ ключ: undefined }`).
156
+ */
157
+ write(t, r, n = !1) {
158
+ if (t == null || typeof t != "object") {
159
+ r?.push(this.path);
160
+ return;
161
+ }
162
+ const i = t;
163
+ D(() => {
164
+ for (const [s, a] of this.children)
165
+ if (!(a.kind === "leaf" && O(a.signal))) {
166
+ if (!(s in i)) {
167
+ r?.push(d(this.path, s));
168
+ continue;
169
+ }
170
+ n && i[s] === void 0 || (a.kind === "group" ? a.write(i[s], r, n) : a.set(i[s]));
171
+ }
172
+ });
173
+ }
174
+ resetToInitial() {
175
+ D(() => {
176
+ for (const t of this.children.values()) t.resetToInitial();
177
+ });
178
+ }
179
+ captureInitial() {
180
+ for (const t of this.children.values()) t.captureInitial();
181
+ }
182
+ dirty() {
183
+ for (const t of this.children.values()) if (t.dirty()) return !0;
184
+ return !1;
185
+ }
186
+ /** Отличается ли группа от снимка её значения (строка массива сверяется со снимком массива). */
187
+ differsFrom(t) {
188
+ if (!f(t)) return !0;
189
+ for (const [r, n] of this.children) if (n.differsFrom(t[r])) return !0;
190
+ return !1;
191
+ }
192
+ }
193
+ class Z {
194
+ /** @param shape Образец того же массива из шаблона родителя (см. {@link ModelGroupNode}). */
195
+ constructor(t, r, n) {
196
+ this.path = r, this.shape = n, this.blank = M(t), this.items = W(t.map((i, s) => this.build(i, s))), this.initial = l(t);
197
+ }
198
+ kind = "array";
199
+ items;
200
+ initial;
201
+ // Шаблон нового элемента (`arrayOf`). Принадлежит узлу, а не значению: `set`/`reset` заменяют
202
+ // элементы, узел остаётся — и шаблон с ним.
203
+ blank;
204
+ // Запасной шаблон — от того, кто строит модель извне (сборка формы передаёт `initialValue`).
205
+ fallback;
206
+ // Образец элемента — один вызов шаблона. Нужен только ради вложенных шаблонов: элемент из
207
+ // обычных данных (`set` с сервера, `push(значение)`) метку `arrayOf` на своих массивах не несёт.
208
+ sample;
209
+ /** Шаблон по старшинству: свой (`arrayOf`) → из шаблона родителя → запасной извне. */
210
+ template() {
211
+ return this.blank ??= M(this.shape?.()), this.blank ?? this.fallback;
212
+ }
213
+ // Образец читается лениво — лишний вызов шаблона случается, только когда вложенному массиву
214
+ // элемента из обычных данных понадобился свой шаблон.
215
+ itemShape = () => {
216
+ if (!this.sample) {
217
+ const t = this.template();
218
+ if (!t) return;
219
+ this.sample = { value: t() };
220
+ }
221
+ return this.sample.value;
222
+ };
223
+ build(t, r) {
224
+ return x(t, d(this.path, r), this.itemShape);
225
+ }
226
+ /**
227
+ * Значение нового элемента: из шаблона; переданный объект накладывается поверх шаблона —
228
+ * недостающие ключи берутся из шаблона, поэтому `push({ type: 'house' })` даёт полный элемент.
229
+ */
230
+ fresh(t) {
231
+ const r = this.template();
232
+ if (t !== void 0) return r ? C(r(), t) : t;
233
+ if (!r)
234
+ throw new Error(
235
+ `[@reformer/core] ${this.path || "массив"}: добавление элемента без значения, а шаблона у массива нет. Объявите его в модели — \`arrayOf(() => ({ … }))\` — либо передайте значение: \`push(значение)\`.`
236
+ );
237
+ return r();
238
+ }
239
+ /** Запасной шаблон извне (сборка формы передаёт `initialValue`): шаблон модели главнее. */
240
+ provideBlank(t) {
241
+ this.fallback ??= t;
242
+ }
243
+ rebase(t) {
244
+ this.path = t, this.items.peek().forEach((r, n) => r.rebase(d(t, n)));
245
+ }
246
+ reindex() {
247
+ this.items.peek().forEach((t, r) => t.rebase(d(this.path, r)));
248
+ }
249
+ /**
250
+ * Индекс за концом массива — ошибка, а не «в конец»: `splice` молча сдвигал бы элемент на
251
+ * другой индекс, и вызывающий код получал бы путь, которого не просил.
252
+ */
253
+ beyondEnd(t, r, n) {
254
+ const i = this.path === "" ? "model" : `model.${this.path}`, s = this.items.peek().length;
255
+ return new RangeError(
256
+ `[@reformer/core] ${i}.${t}: индекс ${r} за концом массива (длина ${s}, наибольший допустимый — ${n}).` + (t.startsWith("insertAt") ? " Добавить в конец — push(…) или insertAt(length, …)." : "")
257
+ );
258
+ }
259
+ push(t) {
260
+ const r = this.items.peek();
261
+ this.items.value = [...r, this.build(this.fresh(t), r.length)];
262
+ }
263
+ insertAt(t, r) {
264
+ if (!Number.isInteger(t) || t < 0) return;
265
+ const n = [...this.items.peek()];
266
+ if (t > n.length) throw this.beyondEnd(`insertAt(${t})`, t, n.length);
267
+ n.splice(t, 0, this.build(this.fresh(r), t)), this.items.value = n, this.reindex();
268
+ }
269
+ removeAt(t) {
270
+ const r = [...this.items.peek()];
271
+ !Number.isInteger(t) || t < 0 || t >= r.length || (r.splice(t, 1), this.items.value = r, this.reindex());
272
+ }
273
+ move(t, r) {
274
+ const n = [...this.items.peek()];
275
+ if (!Number.isInteger(t) || !Number.isInteger(r) || t < 0 || r < 0) return;
276
+ const i = n.length - 1;
277
+ if (t > i) throw this.beyondEnd(`move(${t}, ${r})`, t, i);
278
+ if (r > i) throw this.beyondEnd(`move(${t}, ${r})`, r, i);
279
+ if (t === r) return;
280
+ const [s] = n.splice(t, 1);
281
+ s && n.splice(r, 0, s), this.items.value = n, this.reindex();
282
+ }
283
+ swap(t, r) {
284
+ const n = [...this.items.peek()];
285
+ t < 0 || r < 0 || t >= n.length || r >= n.length || t === r || ([n[t], n[r]] = [n[r], n[t]], this.items.value = n, this.reindex());
286
+ }
287
+ clear() {
288
+ this.items.value = [];
289
+ }
290
+ /**
291
+ * Реактивное чтение массива. Читаем `items.value` (а не `.peek()`) — внутри effect/computed это
292
+ * подписка на СОСТАВ массива, поэтому push/removeAt/move ретригерят наравне с правкой элемента.
293
+ */
294
+ read() {
295
+ return this.items.value.map((t) => t.read());
296
+ }
297
+ peek() {
298
+ return this.items.peek().map((t) => t.peek());
299
+ }
300
+ set(t) {
301
+ const r = Array.isArray(t) ? t : [];
302
+ this.items.value = r.map((n, i) => this.build(n, i));
303
+ }
304
+ resetToInitial() {
305
+ this.set(l(this.initial));
306
+ }
307
+ captureInitial() {
308
+ this.initial = l(this.peek());
309
+ }
310
+ /** Элементы точки отсчёта — копия: правка полученного снимок не трогает. */
311
+ reference() {
312
+ return l(this.initial);
313
+ }
314
+ dirty() {
315
+ return this.differsFrom(this.initial);
316
+ }
317
+ /**
318
+ * Отличается ли массив от снимка: другая длина либо отличается элемент. Сверка идёт по узлам, а
319
+ * не по значению целиком — производные поля строк (цели `compute` поведения строки) не в счёт.
320
+ */
321
+ differsFrom(t) {
322
+ const r = this.items.peek();
323
+ return !Array.isArray(t) || t.length !== r.length ? !0 : r.some((n, i) => n.differsFrom(t[i]));
324
+ }
325
+ }
326
+ function x(e, t, r) {
327
+ return Array.isArray(e) ? new Z(e, t, r) : f(e) ? new U(e, t, r) : new Y(e, t);
328
+ }
329
+ const ee = (e) => typeof e == "function" ? e : () => l(e), I = /* @__PURE__ */ new WeakMap(), K = /* @__PURE__ */ new WeakMap();
330
+ function te(e) {
331
+ const t = J(
332
+ () => process.env.NODE_ENV === "production" ? e.read() : E(e.read(), e)
333
+ );
334
+ return {
335
+ get value() {
336
+ return t.value;
337
+ },
338
+ peek: () => t.peek(),
339
+ subscribe: (r) => t.subscribe(r),
340
+ valueOf: () => t.value,
341
+ toString: () => String(t.value),
342
+ toJSON: () => t.value,
343
+ brand: t.brand
344
+ };
345
+ }
346
+ function E(e, t) {
347
+ if (t.kind === "leaf" || e === null || typeof e != "object") return e;
348
+ const r = e;
349
+ if (t.kind === "group")
350
+ for (const [n, i] of t.children) E(r[n], i);
351
+ else
352
+ t.items.peek().forEach((n, i) => E(r[i], n));
353
+ return Object.freeze(e);
354
+ }
355
+ function g(e) {
356
+ if (e.kind === "leaf") return e.signal;
357
+ const t = I.get(e);
358
+ if (t) return t;
359
+ const r = te(e), n = e.kind === "group", i = (c) => n ? e.children.get(c) : p(c) ? e.items.value[Number(c)] : void 0, s = n ? {} : Object.defineProperty({}, "length", {
360
+ get: () => e.items.value.length,
361
+ enumerable: !1,
362
+ configurable: !0
363
+ }), a = new Proxy(s, {
364
+ get: (c, o, w) => {
365
+ if (o === "__path") return e.path;
366
+ if (o === "__kind") return e.kind;
367
+ if (typeof o != "string") return Reflect.get(r, o, r);
368
+ const y = i(o);
369
+ return y ? g(y) : !n && Object.prototype.hasOwnProperty.call(c, o) ? Reflect.get(c, o, w) : Reflect.get(r, o, r);
370
+ },
371
+ set: (c, o, w) => {
372
+ if (!n && o === "value")
373
+ return e.set(w), !0;
374
+ const y = e.path === "" ? "model.$" : `model.$.${e.path}`;
375
+ throw new TypeError(
376
+ `[@reformer/core] ${y}: запись в «${String(o)}» ` + (n ? "узла-группы невозможна — группа читается целиком, а пишется по полям (model.$.<поле>.value) либо через model.patch(...)" : "узла-массива невозможна — массив заменяется целиком через .value, а элемент правится своим сигналом (model.$.<массив>[i].value)")
377
+ );
378
+ },
379
+ has: (c, o) => typeof o == "string" && (i(o) !== void 0 || !n && Object.prototype.hasOwnProperty.call(c, o)),
380
+ ownKeys: () => n ? [...e.children.keys()] : [...e.items.value.keys()].map(String).concat("length"),
381
+ getOwnPropertyDescriptor: (c, o) => typeof o == "string" && i(o) ? { enumerable: !0, configurable: !0 } : n ? void 0 : Reflect.getOwnPropertyDescriptor(c, o)
382
+ });
383
+ return I.set(e, a), K.set(a, e), a;
384
+ }
385
+ function L(e) {
386
+ if (!(e == null || typeof e != "object"))
387
+ return K.get(e);
388
+ }
389
+ function S(e) {
390
+ if (e == null || typeof e != "object") return !1;
391
+ const t = e.__kind;
392
+ return t === "group" || t === "array";
393
+ }
394
+ function b(e) {
395
+ return e == null || typeof e != "object" ? !1 : e.__kind === "array";
396
+ }
397
+ function ue(e) {
398
+ return b(e) || B(e) && !S(e);
399
+ }
400
+ function re(e, t) {
401
+ if (!t) return;
402
+ let r = e;
403
+ for (const n of t.split(".")) {
404
+ if (!r) return;
405
+ if (r.kind === "group") r = r.children.get(n);
406
+ else if (r.kind === "array") r = r.items.peek()[Number(n)];
407
+ else return;
408
+ }
409
+ if (r)
410
+ return r.kind === "leaf" ? r.signal : r.kind === "array" ? g(r) : void 0;
411
+ }
412
+ function u(e) {
413
+ if (e)
414
+ return e.kind === "group" ? z(e) : e.kind === "array" ? V(e) : e.read();
415
+ }
416
+ const P = /* @__PURE__ */ new WeakMap(), k = /* @__PURE__ */ new WeakMap();
417
+ function V(e) {
418
+ const t = P.get(e);
419
+ if (t) return t;
420
+ const r = {
421
+ get length() {
422
+ return e.items.value.length;
423
+ },
424
+ push: (i) => e.push(i),
425
+ insertAt: (i, s) => e.insertAt(i, s),
426
+ removeAt: (i) => e.removeAt(i),
427
+ move: (i, s) => e.move(i, s),
428
+ swap: (i, s) => e.swap(i, s),
429
+ clear: () => e.clear(),
430
+ at: (i) => u(e.items.value[i]),
431
+ map: (i) => e.items.value.map((s, a) => i(u(s), a)),
432
+ forEach: (i) => e.items.value.forEach((s, a) => i(u(s), a)),
433
+ toArray: () => e.peek(),
434
+ toJSON: () => e.peek(),
435
+ [Symbol.iterator]: function* () {
436
+ const i = e.items.value;
437
+ for (let s = 0; s < i.length; s++) yield u(i[s]);
438
+ }
439
+ }, n = new Proxy(r, {
440
+ get: (i, s, a) => s === "__path" ? e.path : typeof s == "string" && p(s) ? u(e.items.value[Number(s)]) : Reflect.get(i, s, a),
441
+ has: (i, s) => typeof s == "string" && p(s) ? Number(s) < e.items.value.length : Reflect.has(i, s),
442
+ // Перечисляются данные, как у массива: индексы и неперечислимый `length`, а не методы API.
443
+ ownKeys: () => [...e.items.value.keys()].map(String).concat("length"),
444
+ getOwnPropertyDescriptor: (i, s) => {
445
+ if (s === "length")
446
+ return { ...Reflect.getOwnPropertyDescriptor(i, s), enumerable: !1 };
447
+ if (typeof s == "string" && p(s) && Number(s) < e.items.value.length)
448
+ return {
449
+ enumerable: !0,
450
+ configurable: !0,
451
+ writable: !0,
452
+ value: u(e.items.value[Number(s)])
453
+ };
454
+ },
455
+ set: (i, s, a) => {
456
+ const c = e.path === "" ? "model" : `model.${e.path}`;
457
+ if (typeof s == "string" && p(s)) {
458
+ const o = e.items.peek()[Number(s)];
459
+ if (o)
460
+ return o.set(a), !0;
461
+ throw new TypeError(
462
+ `[@reformer/core] ${c}[${s}]: элемента нет — добавляйте через push(…) / insertAt(…).`
463
+ );
464
+ }
465
+ throw new TypeError(
466
+ `[@reformer/core] ${c}: запись в «${String(s)}» невозможна — элементы пишутся по индексу или через push / insertAt / removeAt / move / swap / clear.`
467
+ );
468
+ }
469
+ });
470
+ return P.set(e, n), k.set(n, e), n;
471
+ }
472
+ const $ = /* @__PURE__ */ new Set([
473
+ "$",
474
+ "get",
475
+ "set",
476
+ "patch",
477
+ "isDirty",
478
+ "reset",
479
+ "captureInitial",
480
+ "signalAt"
481
+ ]), ne = () => "[object Object]", F = /* @__PURE__ */ new WeakMap(), N = /* @__PURE__ */ new WeakMap();
482
+ function z(e) {
483
+ const t = F.get(e);
484
+ if (t) return t;
485
+ const r = {
486
+ $: g(e),
487
+ get: () => e.peek(),
488
+ set: (i) => e.set(i),
489
+ patch: (i) => e.patch(i),
490
+ isDirty: () => e.dirty(),
491
+ reset: () => e.resetToInitial(),
492
+ captureInitial: () => e.captureInitial(),
493
+ signalAt: (i) => re(e, i)
494
+ }, n = new Proxy(
495
+ {},
496
+ {
497
+ get: (i, s) => {
498
+ if (s === "__path") return e.path;
499
+ if (typeof s != "string") return;
500
+ const a = e.children.get(s);
501
+ if (a) return u(a);
502
+ if ($.has(s)) return r[s];
503
+ if (s === "toString") return ne;
504
+ },
505
+ set: (i, s, a) => {
506
+ const c = typeof s == "string" ? e.children.get(s) : void 0;
507
+ if (c)
508
+ return c.set(a), !0;
509
+ const o = e.path === "" ? "model" : `model.${e.path}`;
510
+ throw new TypeError(
511
+ `[@reformer/core] ${o}: поля «${String(s)}» в модели нет — запись невозможна. Состав полей задаёт начальное значение модели` + (typeof s == "string" && $.has(s) ? `; «${s}» — метод API модели.` : ".")
512
+ );
513
+ },
514
+ has: (i, s) => typeof s == "string" && (e.children.has(s) || $.has(s)),
515
+ ownKeys: () => [...e.children.keys()],
516
+ getOwnPropertyDescriptor: (i, s) => typeof s == "string" && e.children.has(s) ? { enumerable: !0, configurable: !0 } : void 0
517
+ }
518
+ );
519
+ return F.set(e, n), N.set(n, e), n;
520
+ }
521
+ function he(e) {
522
+ const t = L(e);
523
+ if (!t) {
524
+ const r = e?.__path, n = typeof r == "string" && r !== "" ? ` «${r}»` : "";
525
+ throw new TypeError(
526
+ B(e) && !S(e) ? `[@reformer/core] modelOf: ручка${n} — лист, у него нет под-модели. Группа или массив, созданные из начального null, в модели тоже лист: задайте начальное значение объектом или массивом.` : "[@reformer/core] modelOf: ожидалась ручка группы или массива из дерева model.$ (например, model.$.address или model.$.items)."
527
+ );
528
+ }
529
+ return t.kind === "group" ? z(t) : V(t);
530
+ }
531
+ function G(e) {
532
+ if (e == null || typeof e != "object") return;
533
+ const t = k.get(e);
534
+ if (t) return g(t);
535
+ const r = N.get(e);
536
+ return r ? g(r) : void 0;
537
+ }
538
+ function de(e) {
539
+ if (b(e)) return e;
540
+ const t = G(e);
541
+ return b(t) ? t : void 0;
542
+ }
543
+ function pe(e) {
544
+ const t = S(e) ? e : G(e);
545
+ return t !== void 0 && !b(t) ? t : void 0;
546
+ }
547
+ function me(e, t) {
548
+ const r = L(e);
549
+ r?.kind === "array" && r.provideBlank(ee(t));
550
+ }
551
+ function ge(e) {
552
+ if (typeof e != "object" || e === null) return;
553
+ const t = k.get(e);
554
+ if (t !== void 0) return { value: t.reference() };
555
+ const r = X(e);
556
+ return r === void 0 ? void 0 : { value: r.reference() };
557
+ }
558
+ function ye(e) {
559
+ return e == null || typeof e != "object" ? !1 : k.has(e) || N.has(e);
560
+ }
561
+ const H = "runOutsideEffect";
562
+ function T(e, t) {
563
+ process.env.NODE_ENV !== "production" && console.error(`[${t}]`, e);
564
+ }
565
+ function ie(e) {
566
+ return typeof e == "object" && e !== null && typeof e.then == "function";
567
+ }
568
+ function _(e, t) {
569
+ try {
570
+ const r = e();
571
+ ie(r) && r.then(void 0, (n) => T(n, t));
572
+ } catch (r) {
573
+ T(r, t);
574
+ }
575
+ }
576
+ function be(e) {
577
+ return (...t) => {
578
+ j(() => e(...t));
579
+ };
580
+ }
581
+ function j(e) {
582
+ if (m !== null) {
583
+ const r = { fn: e, cancelled: !1 };
584
+ return m.push(r), () => {
585
+ r.cancelled = !0;
586
+ };
587
+ }
588
+ let t = !1;
589
+ return v++, queueMicrotask(() => {
590
+ v--, !t && _(e, H);
591
+ }), () => {
592
+ t = !0;
593
+ };
594
+ }
595
+ let v = 0, m = null;
596
+ const se = 1e3;
597
+ function ve(e) {
598
+ if (m !== null) return e();
599
+ const t = [];
600
+ m = t;
601
+ let r = 0;
602
+ try {
603
+ const n = e();
604
+ for (; r < t.length && r < se; ) {
605
+ const i = t[r++];
606
+ i.cancelled || _(i.fn, H);
607
+ }
608
+ return n;
609
+ } finally {
610
+ m = null;
611
+ for (const n of t.slice(r))
612
+ n.cancelled || j(() => n.cancelled ? void 0 : n.fn());
613
+ }
614
+ }
615
+ function ke() {
616
+ if (v !== 0)
617
+ return new Promise((e) => {
618
+ const t = () => {
619
+ v > 0 ? queueMicrotask(t) : e();
620
+ };
621
+ queueMicrotask(t);
622
+ });
623
+ }
624
+ function we() {
625
+ const e = /* @__PURE__ */ new Set();
626
+ return {
627
+ schedule(t) {
628
+ const r = j(() => {
629
+ e.delete(r), t();
630
+ });
631
+ e.add(r);
632
+ },
633
+ cancelAll() {
634
+ e.forEach((t) => t()), e.clear();
635
+ }
636
+ };
637
+ }
638
+ function $e(e, t) {
639
+ return () => {
640
+ t(() => _(e, "safeDebouncedCallback"));
641
+ };
642
+ }
643
+ export {
644
+ U as M,
645
+ fe as a,
646
+ ue as b,
647
+ ce as c,
648
+ O as d,
649
+ $e as e,
650
+ ke as f,
651
+ A as g,
652
+ we as h,
653
+ S as i,
654
+ z as j,
655
+ N as k,
656
+ g as l,
657
+ he as m,
658
+ pe as n,
659
+ de as o,
660
+ b as p,
661
+ ge as q,
662
+ j as r,
663
+ be as s,
664
+ L as t,
665
+ le as u,
666
+ ye as v,
667
+ me as w,
668
+ ve as x
669
+ };