@reformer/core 11.0.0-beta.7 → 11.0.0-beta.9

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 (226) hide show
  1. package/README.md +90 -68
  2. package/dist/behaviors-value-HA_Q03hc.js +108 -0
  3. package/dist/behaviors.js +382 -217
  4. package/dist/create-model-BvcbNPgL.js +30 -0
  5. package/dist/date-utils-90-qZbse.js +43 -0
  6. package/dist/{en-CjAqn7h0.js → en-HP8XEych.js} +6 -3
  7. package/dist/form/aggregate-signals.d.ts +21 -63
  8. package/dist/form/behaviors/collections.d.ts +42 -8
  9. package/dist/form/behaviors/context.d.ts +37 -4
  10. package/dist/form/behaviors/index.d.ts +6 -4
  11. package/dist/form/behaviors/internals.d.ts +9 -3
  12. package/dist/form/behaviors/node.d.ts +25 -2
  13. package/dist/form/behaviors/operators.d.ts +17 -9
  14. package/dist/form/behaviors/schema-operators.d.ts +78 -0
  15. package/dist/form/behaviors/types.d.ts +25 -5
  16. package/dist/form/create-form.d.ts +57 -70
  17. package/dist/form/flow/flow.d.ts +87 -0
  18. package/dist/form/form-bundle.d.ts +153 -0
  19. package/dist/form/form-config-base.d.ts +46 -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 +20 -20
  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 +153 -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 +19 -92
  42. package/dist/form/types/field-config.d.ts +27 -0
  43. package/dist/form/types/index.d.ts +5 -57
  44. package/dist/form/types/nodes.d.ts +159 -0
  45. package/dist/form/types/schema-node.d.ts +147 -46
  46. package/dist/form/types/validation-schema.d.ts +23 -27
  47. package/dist/form/validation/context.d.ts +46 -6
  48. package/dist/form/validation/index.d.ts +9 -8
  49. package/dist/form/validation/operators.d.ts +71 -17
  50. package/dist/form/validation/run.d.ts +93 -18
  51. package/dist/form/validation/strategy.d.ts +41 -13
  52. package/dist/form/validation/types.d.ts +74 -19
  53. package/dist/form/validators/date-utils.d.ts +13 -1
  54. package/dist/form/validators/email.d.ts +8 -7
  55. package/dist/form/validators/file-type.d.ts +8 -7
  56. package/dist/form/validators/file-utils.d.ts +2 -1
  57. package/dist/form/validators/future-date.d.ts +8 -7
  58. package/dist/form/validators/index.d.ts +1 -1
  59. package/dist/form/validators/integer.d.ts +8 -7
  60. package/dist/form/validators/is-date.d.ts +11 -9
  61. package/dist/form/validators/is-number.d.ts +11 -9
  62. package/dist/form/validators/max-age.d.ts +13 -9
  63. package/dist/form/validators/max-date.d.ts +8 -7
  64. package/dist/form/validators/max-file-size.d.ts +8 -7
  65. package/dist/form/validators/max-files.d.ts +8 -7
  66. package/dist/form/validators/max-length.d.ts +14 -7
  67. package/dist/form/validators/max-total-file-size.d.ts +8 -7
  68. package/dist/form/validators/max.d.ts +10 -8
  69. package/dist/form/validators/min-age.d.ts +12 -9
  70. package/dist/form/validators/min-date.d.ts +8 -7
  71. package/dist/form/validators/min-file-size.d.ts +8 -7
  72. package/dist/form/validators/min-files.d.ts +11 -9
  73. package/dist/form/validators/min-length.d.ts +14 -7
  74. package/dist/form/validators/min.d.ts +10 -8
  75. package/dist/form/validators/multiple-of.d.ts +10 -8
  76. package/dist/form/validators/non-negative.d.ts +8 -7
  77. package/dist/form/validators/non-zero.d.ts +8 -7
  78. package/dist/form/validators/past-date.d.ts +8 -7
  79. package/dist/form/validators/pattern.d.ts +9 -8
  80. package/dist/form/validators/phone.d.ts +8 -7
  81. package/dist/form/validators/required.d.ts +11 -9
  82. package/dist/form/validators/url.d.ts +20 -13
  83. package/dist/form/validators/validation-issue.d.ts +8 -0
  84. package/dist/i18n/descriptor.d.ts +1 -1
  85. package/dist/i18n/en.json.d.ts +5 -1
  86. package/dist/i18n/locale-store.d.ts +7 -0
  87. package/dist/i18n/message-format.d.ts +24 -4
  88. package/dist/i18n/ru.json.d.ts +5 -1
  89. package/dist/i18n/translator.d.ts +11 -0
  90. package/dist/i18n/validation-message.d.ts +42 -7
  91. package/dist/i18n.d.ts +7 -12
  92. package/dist/i18n.js +66 -283
  93. package/dist/index.d.ts +16 -7
  94. package/dist/index.js +958 -2798
  95. package/dist/loader-BWkigpVe.js +52 -0
  96. package/dist/locale/en.js +1 -1
  97. package/dist/locale/en.json +4 -1
  98. package/dist/locale/ru.js +4 -1
  99. package/dist/locale/ru.json +4 -1
  100. package/dist/locale-CG54AU2Q.js +219 -0
  101. package/dist/locale.js +1 -1
  102. package/dist/model/behaviors-value.d.ts +24 -6
  103. package/dist/model/create-model.d.ts +2 -2
  104. package/dist/model/derived-registry.d.ts +1 -1
  105. package/dist/model/index.d.ts +16 -5
  106. package/dist/model/model-nodes.d.ts +138 -8
  107. package/dist/model/model-signals-proxy.d.ts +11 -5
  108. package/dist/model/model-value-proxy.d.ts +84 -3
  109. package/dist/model/safe-effect.d.ts +33 -1
  110. package/dist/model/types.d.ts +70 -17
  111. package/dist/model.js +21 -17
  112. package/dist/node-kind-C-r6ZMdo.js +15 -0
  113. package/dist/platforms/react/field-binding/field-adapter.d.ts +1 -1
  114. package/dist/platforms/react/field-binding/field-handle.d.ts +5 -2
  115. package/dist/platforms/react/form-bundle-context.d.ts +27 -0
  116. package/dist/platforms/react/hooks/types.d.ts +57 -38
  117. package/dist/platforms/react/hooks/use-form-bundle.d.ts +19 -4
  118. package/dist/platforms/react/hooks/use-form-flow.d.ts +40 -0
  119. package/dist/platforms/react/hooks/use-form-validation.d.ts +12 -6
  120. package/dist/platforms/react/hooks/useArrayLength.d.ts +6 -6
  121. package/dist/platforms/react/hooks/useFormControl.d.ts +7 -9
  122. package/dist/platforms/react/hooks/useFormControlValue.d.ts +18 -19
  123. package/dist/platforms/react/hooks/useSignalSubscription.d.ts +9 -1
  124. package/dist/platforms/react/i18n/context.d.ts +6 -1
  125. package/dist/platforms/react/i18n/hooks.d.ts +16 -10
  126. package/dist/platforms/react/i18n/provider.d.ts +9 -2
  127. package/dist/platforms/react/index.d.ts +7 -4
  128. package/dist/react.d.ts +22 -0
  129. package/dist/react.js +505 -0
  130. package/dist/runtime-token.d.ts +1 -2
  131. package/dist/safe-effect-BbtX3KuN.js +643 -0
  132. package/dist/schema-controller-CpiO2JoK.js +143 -0
  133. package/dist/signals.d.ts +15 -9
  134. package/dist/signals.js +11 -6
  135. package/dist/strategy-CoFSemuP.js +375 -0
  136. package/dist/type-guards-D-N_5Ddh.js +19 -0
  137. package/dist/validation-issue-B9mjI8jz.js +7 -0
  138. package/dist/validation-message-Ced9MGxs.js +194 -0
  139. package/dist/validation.js +9 -8
  140. package/dist/validators/email.js +5 -5
  141. package/dist/validators/future-date.js +8 -8
  142. package/dist/validators/integer.js +3 -3
  143. package/dist/validators/is-date.js +4 -4
  144. package/dist/validators/is-number.js +4 -4
  145. package/dist/validators/max-age.js +8 -9
  146. package/dist/validators/max-date.js +8 -8
  147. package/dist/validators/max-length.js +7 -7
  148. package/dist/validators/max.js +4 -4
  149. package/dist/validators/min-age.js +10 -8
  150. package/dist/validators/min-date.js +3 -3
  151. package/dist/validators/min-length.js +5 -5
  152. package/dist/validators/min.js +4 -4
  153. package/dist/validators/multiple-of.js +11 -7
  154. package/dist/validators/non-negative.js +3 -3
  155. package/dist/validators/non-zero.js +3 -3
  156. package/dist/validators/past-date.js +8 -8
  157. package/dist/validators/pattern.js +5 -5
  158. package/dist/validators/phone.js +11 -9
  159. package/dist/validators/required.js +2 -2
  160. package/dist/validators/url.js +48 -12
  161. package/dist/validators.js +17 -17
  162. package/docs/llms/01-api-reference.md +60 -34
  163. package/docs/llms/02-quick-start.md +111 -80
  164. package/docs/llms/03-api-signatures.md +368 -153
  165. package/docs/llms/04-common-patterns.md +58 -56
  166. package/docs/llms/05-common-mistakes.md +69 -44
  167. package/docs/llms/06-troubleshooting.md +14 -9
  168. package/docs/llms/07-complete-import.md +74 -43
  169. package/docs/llms/08-form-types.md +11 -4
  170. package/docs/llms/09-formschema.md +131 -83
  171. package/docs/llms/10-arrays.md +119 -69
  172. package/docs/llms/11-async-watchfield.md +2 -2
  173. package/docs/llms/13-multi-step.md +134 -63
  174. package/docs/llms/14-extended-mistakes.md +20 -17
  175. package/docs/llms/15-project-structure.md +221 -74
  176. package/docs/llms/16-ui-components.md +55 -42
  177. package/docs/llms/17-nonexistent-api.md +199 -32
  178. package/docs/llms/18-conditional-fields.md +66 -32
  179. package/docs/llms/19-reading-values.md +15 -3
  180. package/docs/llms/20-compute-vs-watch.md +16 -10
  181. package/docs/llms/21-array-operations.md +76 -26
  182. package/docs/llms/22-cycle-detection.md +1 -1
  183. package/docs/llms/23-copy-from.md +2 -2
  184. package/docs/llms/24-sync-fields.md +6 -5
  185. package/docs/llms/25-reset-when.md +14 -7
  186. package/docs/llms/26-transform-value.md +4 -4
  187. package/docs/llms/27-revalidate-when.md +16 -15
  188. package/docs/llms/28-submit-and-reset.md +276 -128
  189. package/docs/llms/29-async-preload.md +40 -30
  190. package/docs/llms/30-type-safety-recipes.md +105 -51
  191. package/docs/llms/31-async-validator-debounce.md +96 -53
  192. package/docs/llms/33-validation-strategy.md +178 -66
  193. package/docs/llms/34-i18n.md +69 -43
  194. package/docs/llms/35-unified-contract.md +307 -0
  195. package/docs/llms/36-issue-messages.md +284 -0
  196. package/docs/llms/37-compiled-schema.md +332 -0
  197. package/docs/llms/38-form-flow.md +397 -0
  198. package/llms-index.json +1 -1
  199. package/llms.txt +6968 -3278
  200. package/package.json +23 -4
  201. package/dist/behaviors-value-C7dSEhCc.js +0 -134
  202. package/dist/create-model-B8U-COv-.js +0 -103
  203. package/dist/date-utils-dTT_x_Be.js +0 -31
  204. package/dist/form/create-core-form.d.ts +0 -70
  205. package/dist/form/factories/index.d.ts +0 -6
  206. package/dist/form/factories/node-factory.d.ts +0 -189
  207. package/dist/form/form-submitter.d.ts +0 -121
  208. package/dist/form/nodes/array-node.d.ts +0 -276
  209. package/dist/form/nodes/field-node.d.ts +0 -297
  210. package/dist/form/nodes/form-node.d.ts +0 -326
  211. package/dist/form/nodes/group-node.d.ts +0 -284
  212. package/dist/form/nodes/model-array-node.d.ts +0 -121
  213. package/dist/form/nodes/subscription-manager.d.ts +0 -180
  214. package/dist/form/status-machine.d.ts +0 -115
  215. package/dist/form/types/deep-schema.d.ts +0 -107
  216. package/dist/form/types/form-proxy.d.ts +0 -141
  217. package/dist/form/unique-id.d.ts +0 -45
  218. package/dist/form/validation/config.d.ts +0 -73
  219. package/dist/form/validation/error-handler.d.ts +0 -166
  220. package/dist/form/validators/validation-error.d.ts +0 -8
  221. package/dist/index-BrNkQj1y.js +0 -105
  222. package/dist/loader-Dv_Hl7JC.js +0 -216
  223. package/dist/model-signals-proxy-2vqS243J.js +0 -250
  224. package/dist/node-DGEFMTQu.js +0 -18
  225. package/dist/strategy-BXS_gBfz.js +0 -170
  226. package/dist/validation-error-B-U3RsV0.js +0 -11
@@ -1,250 +0,0 @@
1
- import { batch as y, signal as v, Signal as A, computed as w } from "@preact/signals-core";
2
- const u = /* @__PURE__ */ new WeakMap();
3
- function R(t) {
4
- u.set(t, (u.get(t) ?? 0) + 1);
5
- }
6
- function D(t) {
7
- const e = u.get(t);
8
- e !== void 0 && (e <= 1 ? u.delete(t) : u.set(t, e - 1));
9
- }
10
- function _(t) {
11
- return u.has(t);
12
- }
13
- const h = (t) => !(t === null || typeof t != "object" || Array.isArray(t) || t instanceof Date || typeof Blob < "u" && t instanceof Blob || typeof File < "u" && t instanceof File), o = (t, e) => t === "" ? String(e) : `${t}.${e}`, S = (t) => /^\d+$/.test(t), l = (t) => {
14
- if (Array.isArray(t)) return t.map(l);
15
- if (h(t)) {
16
- const e = {};
17
- for (const r of Object.keys(t)) e[r] = l(t[r]);
18
- return e;
19
- }
20
- return t;
21
- }, d = (t, e) => {
22
- if (t === e) return !0;
23
- if (Array.isArray(t) && Array.isArray(e))
24
- return t.length !== e.length ? !1 : t.every((r, i) => d(r, e[i]));
25
- if (h(t) && h(e)) {
26
- const r = Object.keys(t), i = Object.keys(e);
27
- return r.length !== i.length ? !1 : r.every((s) => d(t[s], e[s]));
28
- }
29
- return !1;
30
- };
31
- class j {
32
- constructor(e, r) {
33
- this.path = r;
34
- const i = v(e);
35
- i.__path = r, this.signal = i, this.initial = l(e);
36
- }
37
- kind = "leaf";
38
- signal;
39
- initial;
40
- rebase(e) {
41
- this.path = e, this.signal.__path = e;
42
- }
43
- /** Реактивное чтение (внутри effect/computed создаёт зависимость). */
44
- read() {
45
- return this.signal.value;
46
- }
47
- /** Нереактивный снимок. */
48
- peek() {
49
- return this.signal.peek();
50
- }
51
- set(e) {
52
- this.signal.value = e;
53
- }
54
- resetToInitial() {
55
- this.signal.value = l(this.initial);
56
- }
57
- captureInitial() {
58
- this.initial = l(this.signal.peek());
59
- }
60
- dirty() {
61
- return !d(this.signal.peek(), this.initial);
62
- }
63
- }
64
- class $ {
65
- constructor(e, r) {
66
- this.path = r;
67
- for (const i of Object.keys(e))
68
- this.children.set(i, c(e[i], o(r, i)));
69
- }
70
- kind = "group";
71
- children = /* @__PURE__ */ new Map();
72
- rebase(e) {
73
- this.path = e;
74
- for (const [r, i] of this.children) i.rebase(o(e, r));
75
- }
76
- /** Реактивное чтение поддерева (внутри effect/computed подписывает на все листья группы). */
77
- read() {
78
- const e = {};
79
- for (const [r, i] of this.children) e[r] = i.read();
80
- return e;
81
- }
82
- peek() {
83
- const e = {};
84
- for (const [r, i] of this.children) e[r] = i.peek();
85
- return e;
86
- }
87
- set(e) {
88
- if (e == null || typeof e != "object") return;
89
- const r = e;
90
- y(() => {
91
- for (const [i, s] of this.children)
92
- i in r && (s.kind === "leaf" && _(s.signal) || s.set(r[i]));
93
- });
94
- }
95
- resetToInitial() {
96
- y(() => {
97
- for (const e of this.children.values()) e.resetToInitial();
98
- });
99
- }
100
- captureInitial() {
101
- for (const e of this.children.values()) e.captureInitial();
102
- }
103
- dirty() {
104
- for (const e of this.children.values()) if (e.dirty()) return !0;
105
- return !1;
106
- }
107
- }
108
- class x {
109
- constructor(e, r) {
110
- this.path = r, this.items = v(e.map((i, s) => c(i, o(r, s)))), this.initial = l(e);
111
- }
112
- kind = "array";
113
- items;
114
- initial;
115
- rebase(e) {
116
- this.path = e, this.items.peek().forEach((r, i) => r.rebase(o(e, i)));
117
- }
118
- reindex() {
119
- this.items.peek().forEach((e, r) => e.rebase(o(this.path, r)));
120
- }
121
- push(e) {
122
- const r = this.items.peek();
123
- this.items.value = [...r, c(e, o(this.path, r.length))];
124
- }
125
- insertAt(e, r) {
126
- const i = [...this.items.peek()];
127
- i.splice(e, 0, c(r, o(this.path, e))), this.items.value = i, this.reindex();
128
- }
129
- removeAt(e) {
130
- const r = [...this.items.peek()];
131
- r.splice(e, 1), this.items.value = r, this.reindex();
132
- }
133
- move(e, r) {
134
- const i = [...this.items.peek()], [s] = i.splice(e, 1);
135
- s && i.splice(r, 0, s), this.items.value = i, this.reindex();
136
- }
137
- swap(e, r) {
138
- const i = [...this.items.peek()];
139
- e < 0 || r < 0 || e >= i.length || r >= i.length || e === r || ([i[e], i[r]] = [i[r], i[e]], this.items.value = i, this.reindex());
140
- }
141
- clear() {
142
- this.items.value = [];
143
- }
144
- /**
145
- * Реактивное чтение массива. Читаем `items.value` (а не `.peek()`) — внутри effect/computed это
146
- * подписка на СОСТАВ массива, поэтому push/removeAt/move ретригерят наравне с правкой элемента.
147
- */
148
- read() {
149
- return this.items.value.map((e) => e.read());
150
- }
151
- peek() {
152
- return this.items.peek().map((e) => e.peek());
153
- }
154
- set(e) {
155
- const r = Array.isArray(e) ? e : [];
156
- this.items.value = r.map((i, s) => c(i, o(this.path, s)));
157
- }
158
- resetToInitial() {
159
- this.set(l(this.initial));
160
- }
161
- captureInitial() {
162
- this.initial = l(this.peek());
163
- }
164
- dirty() {
165
- return !d(this.peek(), this.initial);
166
- }
167
- }
168
- function c(t, e) {
169
- return Array.isArray(t) ? new x(t, e) : h(t) ? new $(t, e) : new j(t, e);
170
- }
171
- const k = /* @__PURE__ */ new WeakMap();
172
- function I(t) {
173
- const e = w(() => t.read());
174
- return {
175
- get value() {
176
- return e.value;
177
- },
178
- peek: () => e.peek(),
179
- subscribe: (r) => e.subscribe(r),
180
- valueOf: () => e.value,
181
- toString: () => String(e.value),
182
- toJSON: () => e.value,
183
- brand: e.brand
184
- };
185
- }
186
- function b(t) {
187
- if (t.kind === "leaf") return t.signal;
188
- const e = k.get(t);
189
- if (e) return e;
190
- const r = I(t), i = t.kind === "group", s = (a) => i ? t.children.get(a) : S(a) ? t.items.value[Number(a)] : void 0, g = i ? {} : {
191
- get length() {
192
- return t.items.value.length;
193
- }
194
- }, m = new Proxy(g, {
195
- get: (a, n, p) => {
196
- if (n === "__path") return t.path;
197
- if (n === "__kind") return t.kind;
198
- if (typeof n != "string") return Reflect.get(r, n, r);
199
- const f = s(n);
200
- return f ? b(f) : !i && Reflect.has(a, n) ? Reflect.get(a, n, p) : Reflect.get(r, n, r);
201
- },
202
- set: (a, n, p) => {
203
- if (!i && n === "value")
204
- return t.set(p), !0;
205
- const f = t.path === "" ? "model.$" : `model.$.${t.path}`;
206
- throw new TypeError(
207
- `[@reformer/core] ${f}: запись в «${String(n)}» ` + (i ? "узла-группы невозможна — группа читается целиком, а пишется по полям (model.$.<поле>.value) либо через model.patch(...)" : "узла-массива невозможна — массив заменяется целиком через .value, а элемент правится своим сигналом (model.$.<массив>[i].value)")
208
- );
209
- },
210
- has: (a, n) => typeof n == "string" && (s(n) !== void 0 || !i && Reflect.has(a, n)),
211
- ownKeys: () => i ? [...t.children.keys()] : Reflect.ownKeys(g),
212
- getOwnPropertyDescriptor: (a, n) => typeof n == "string" && s(n) ? { enumerable: !0, configurable: !0 } : i ? void 0 : Reflect.getOwnPropertyDescriptor(a, n)
213
- });
214
- return k.set(t, m), m;
215
- }
216
- function P(t) {
217
- if (t == null || typeof t != "object") return !1;
218
- const e = t.__kind;
219
- return e === "group" || e === "array";
220
- }
221
- function O(t) {
222
- return t == null || typeof t != "object" ? !1 : t.__kind === "array";
223
- }
224
- function M(t) {
225
- return t instanceof A || O(t);
226
- }
227
- function T(t, e) {
228
- if (!e) return;
229
- let r = t;
230
- for (const i of e.split(".")) {
231
- if (!r) return;
232
- if (r.kind === "group") r = r.children.get(i);
233
- else if (r.kind === "array") r = r.items.peek()[Number(i)];
234
- else return;
235
- }
236
- if (r)
237
- return r.kind === "leaf" ? r.signal : r.kind === "array" ? b(r) : void 0;
238
- }
239
- export {
240
- $ as G,
241
- M as a,
242
- _ as b,
243
- S as c,
244
- O as d,
245
- P as i,
246
- R as m,
247
- T as r,
248
- b as s,
249
- D as u
250
- };
@@ -1,18 +0,0 @@
1
- import { effect as i } from "@preact/signals-core";
2
- import { g as s } from "./signal-node-registry-tiwel-TV.js";
3
- import { d as f } from "./behaviors-value-C7dSEhCc.js";
4
- function a(n, r, t) {
5
- return i(() => {
6
- const o = r(), e = s(n);
7
- e && f(() => {
8
- o ? e.enable() : (e.disable(), t?.resetOnDisable && e.reset());
9
- });
10
- });
11
- }
12
- function b(n, r, t) {
13
- return a(n, () => !r(), t);
14
- }
15
- export {
16
- b as d,
17
- a as e
18
- };
@@ -1,170 +0,0 @@
1
- import { signal as A, effect as M } from "@preact/signals-core";
2
- import { a as W } from "./create-model-B8U-COv-.js";
3
- import { g as v } from "./signal-node-registry-tiwel-TV.js";
4
- let g = null;
5
- function E(e, n) {
6
- const t = g;
7
- g = e;
8
- try {
9
- return n();
10
- } finally {
11
- g = t;
12
- }
13
- }
14
- function u(e) {
15
- if (!g)
16
- throw new Error(
17
- `[@reformer/core/validation] "${e}" вызван вне схемы валидации — операторы валидации можно вызывать только внутри прогона validateModel(...) (напрямую или через apply/each).`
18
- );
19
- return g;
20
- }
21
- function m(e, n) {
22
- let t = e.errors.get(n);
23
- return t || e.errors.set(n, t = []), t;
24
- }
25
- const b = (e) => e.whenStack.every((n) => n());
26
- function D(e, n) {
27
- const t = u("validate"), r = m(t, e);
28
- if (!b(t)) return;
29
- const o = e.peek();
30
- for (const a of n) {
31
- const i = a(o, t.model, t.model);
32
- i && r.push(i);
33
- }
34
- }
35
- function N(e, n) {
36
- const t = u("validateAsync"), r = m(t, e);
37
- if (!b(t)) return;
38
- const o = e.peek(), a = t.signal;
39
- for (const i of n)
40
- t.pending.push(
41
- i(o, { signal: a }).then(
42
- (s) => {
43
- s && !a.aborted && r.push(s);
44
- },
45
- () => {
46
- }
47
- )
48
- );
49
- }
50
- function R(e, n) {
51
- const t = u("validateWhen");
52
- t.whenStack.push(e);
53
- try {
54
- n();
55
- } finally {
56
- t.whenStack.pop();
57
- }
58
- }
59
- function _(e, n) {
60
- const t = u("cross"), r = m(t, e);
61
- if (!b(t)) return;
62
- const o = n(t.model.get());
63
- o && r.push(o);
64
- }
65
- function $(e, n) {
66
- u("each");
67
- const t = e.length;
68
- for (let r = 0; r < t; r++) n(e.at(r));
69
- }
70
- function j(...e) {
71
- const t = u("apply").model;
72
- for (const r of e) r({ model: t });
73
- }
74
- function z(e) {
75
- return e;
76
- }
77
- const x = /* @__PURE__ */ new WeakMap();
78
- function P(e, n) {
79
- let t = x.get(e);
80
- t || x.set(e, t = /* @__PURE__ */ new WeakMap());
81
- let r = t.get(n);
82
- return r || t.set(n, r = { fields: /* @__PURE__ */ new Set(), ac: null }), r;
83
- }
84
- const T = (e) => {
85
- for (const n of e.values()) for (const t of n) if (t.severity !== "warning") return !0;
86
- return !1;
87
- };
88
- function V(e) {
89
- return e.aborted ? Promise.resolve() : new Promise((n) => {
90
- e.addEventListener("abort", () => n(), { once: !0 });
91
- });
92
- }
93
- async function C(e, n, t) {
94
- const r = P(e, n);
95
- r.ac?.abort();
96
- const o = new AbortController();
97
- r.ac = o;
98
- const a = {
99
- model: e,
100
- errors: /* @__PURE__ */ new Map(),
101
- pending: [],
102
- whenStack: [],
103
- signal: o.signal
104
- };
105
- if (E(a, () => n({ model: e })), a.pending.length && await Promise.race([Promise.all(a.pending), V(o.signal)]), o.signal.aborted) return !1;
106
- const i = new Set(a.errors.keys());
107
- for (const s of r.fields) i.has(s) || v(s)?.setErrors([]);
108
- for (const s of i) v(s)?.setErrors(a.errors.get(s) ?? []);
109
- if (t?.touch) for (const s of i) v(s)?.markAsTouched();
110
- return r.fields = i, !T(a.errors);
111
- }
112
- function G(e, n, t = {}) {
113
- const { strategy: r = "submit", debounce: o = 0, liveAfterSubmit: a = "change" } = t, i = A(!1);
114
- let s = 0, y = !1, f, c;
115
- const w = async (l) => {
116
- s++, i.value = !0;
117
- try {
118
- return await C(e, n, { touch: l });
119
- } finally {
120
- --s === 0 && (i.value = !1);
121
- }
122
- }, p = () => {
123
- w(!1);
124
- }, F = () => {
125
- if (!o) {
126
- p();
127
- return;
128
- }
129
- c && clearTimeout(c), c = setTimeout(p, o);
130
- }, k = (l, d) => {
131
- let S = !0;
132
- return M(() => {
133
- if (W(e, l), S) {
134
- S = !1;
135
- return;
136
- }
137
- r === "afterFirstSubmit" && !y || d();
138
- });
139
- }, h = {
140
- async validate() {
141
- return y = !0, w(!0);
142
- },
143
- start() {
144
- if (f) return () => h.dispose();
145
- const l = r === "afterFirstSubmit" ? a : r;
146
- return l === "change" ? f = k((d) => void d.value, F) : l === "blur" && (f = k((d) => void v(d)?.touched.value, p)), () => h.dispose();
147
- },
148
- dispose() {
149
- c && (clearTimeout(c), c = void 0), f?.(), f = void 0;
150
- },
151
- get isValidating() {
152
- return i.value;
153
- },
154
- get validating() {
155
- return i;
156
- }
157
- };
158
- return h;
159
- }
160
- export {
161
- N as a,
162
- R as b,
163
- _ as c,
164
- j as d,
165
- $ as e,
166
- z as f,
167
- C as g,
168
- G as h,
169
- D as v
170
- };
@@ -1,11 +0,0 @@
1
- function m(s, e, a) {
2
- const r = {
3
- code: s,
4
- message: e?.message ?? "",
5
- params: a === void 0 ? e?.params : { ...a, ...e?.params }
6
- };
7
- return e?.messageKey !== void 0 && (r.messageKey = e.messageKey), r;
8
- }
9
- export {
10
- m as v
11
- };