@reformer/core 11.0.0-beta.1 → 11.0.0-beta.2

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.
package/dist/behaviors.js CHANGED
@@ -1,7 +1,7 @@
1
- import { effect as O } from "@preact/signals-core";
2
- import { d as $, a as S, w as F, t as A, r as C, s as D, b as M } from "./behaviors-value-C7dSEhCc.js";
3
- import { m as k, u as x } from "./derived-registry-CluZCQ7U.js";
4
- import { e as G } from "./behaviors-node-DGEFMTQu.js";
1
+ import { effect as j } from "@preact/signals-core";
2
+ import { m as $, u as k, i as C } from "./form-model-DhW2HZOB.js";
3
+ import { d as x, a as M, w as F, t as O, r as A, s as D, b as G } from "./behaviors-value-C7dSEhCc.js";
4
+ import { e as T } from "./behaviors-node-DGEFMTQu.js";
5
5
  let p = null;
6
6
  function P(e) {
7
7
  if (!p)
@@ -17,13 +17,13 @@ function y() {
17
17
  const e = P("getScope");
18
18
  return { model: e.model, form: e.form };
19
19
  }
20
- function T(e) {
20
+ function I(e) {
21
21
  return {
22
- __run(n, t) {
23
- const o = { cleanups: [], model: n, form: t }, r = p;
22
+ __run(t, n) {
23
+ const o = { cleanups: [], model: t, form: n }, r = p;
24
24
  p = o;
25
25
  try {
26
- e({ model: n, form: t });
26
+ e({ model: t, form: n });
27
27
  } finally {
28
28
  p = r;
29
29
  }
@@ -34,111 +34,111 @@ function T(e) {
34
34
  };
35
35
  }
36
36
  function h(e) {
37
- s(O(e));
37
+ s(j(e));
38
38
  }
39
- function _(e) {
40
- $(e);
39
+ function g(e) {
40
+ x(e);
41
41
  }
42
- const m = (e) => typeof e == "object" && e !== null && typeof e.peek == "function", B = (e) => Array.isArray(e) ? e : [e];
42
+ const m = (e) => typeof e == "object" && e !== null && typeof e.peek == "function" && !C(e), B = (e) => Array.isArray(e) ? e : [e];
43
43
  function E(e) {
44
- const n = {};
45
- for (const t of Object.keys(e)) {
46
- const o = e[t];
47
- n[t] = m(o) ? o.value : E(o);
44
+ const t = {};
45
+ for (const n of Object.keys(e)) {
46
+ const o = e[n];
47
+ t[n] = m(o) ? o.value : E(o);
48
48
  }
49
- return n;
49
+ return t;
50
50
  }
51
- function W(e, n) {
52
- for (const t of Object.keys(e)) {
53
- const o = e[t];
54
- m(o) ? o.value = n?.[t] : W(o, n?.[t] ?? {});
51
+ function W(e, t) {
52
+ for (const n of Object.keys(e)) {
53
+ const o = e[n];
54
+ m(o) ? o.value = t?.[n] : W(o, t?.[n] ?? {});
55
55
  }
56
56
  }
57
- function I(e) {
57
+ function R(e) {
58
58
  if (!e) return;
59
- const { form: n } = y();
60
- return n.getFieldByPath(e);
59
+ const { form: t } = y();
60
+ return t.getFieldByPath(e);
61
61
  }
62
- function V(e) {
62
+ function S(e) {
63
63
  return new Proxy(
64
64
  {},
65
65
  {
66
- get: (n, t) => {
67
- if (t === "$") return e;
68
- if (typeof t != "string") return;
69
- const o = e[t];
66
+ get: (t, n) => {
67
+ if (n === "$") return e;
68
+ if (typeof n != "string") return;
69
+ const o = e[n];
70
70
  if (o != null)
71
- return m(o) ? o.value : V(o);
71
+ return m(o) ? o.value : S(o);
72
72
  }
73
73
  }
74
74
  );
75
75
  }
76
- function j(e) {
77
- return (n) => {
76
+ function V(e) {
77
+ return (t) => {
78
78
  try {
79
- n();
80
- } catch (t) {
81
- if (t instanceof Error && /cycle detected/i.test(t.message)) {
79
+ t();
80
+ } catch (n) {
81
+ if (n instanceof Error && /cycle detected/i.test(n.message)) {
82
82
  const o = e.__path ?? "?";
83
83
  throw new Error(
84
84
  `[@reformer/core/behaviors] compute("${o}"): расходящийся цикл пересчёта — взаимные compute/computeFrom без стабилизации. Проверьте зависимости или добавьте стабилизирующее условие (when) / разорвите цикл через peek.`
85
85
  );
86
86
  }
87
- throw t;
87
+ throw n;
88
88
  }
89
89
  };
90
90
  }
91
- function U(e, n, t) {
92
- k(e), s(() => x(e));
93
- const o = j(e);
91
+ function X(e, t, n) {
92
+ $(e), s(() => k(e));
93
+ const o = V(e);
94
94
  h(() => {
95
- if (t?.when && !t.when()) return;
96
- const r = n();
95
+ if (n?.when && !n.when()) return;
96
+ const r = t();
97
97
  e.peek() !== r && o(() => {
98
98
  e.value = r;
99
99
  });
100
100
  });
101
101
  }
102
- function X(e, n, t, o) {
103
- k(n), s(() => x(n));
104
- const r = j(n);
102
+ function Y(e, t, n, o) {
103
+ $(t), s(() => k(t));
104
+ const r = V(t);
105
105
  h(() => {
106
106
  const c = e.map((f) => f.value);
107
107
  if (o?.when && !o.when(...c)) return;
108
- const i = t(...c);
109
- n.peek() !== i && r(() => {
110
- n.value = i;
108
+ const i = n(...c);
109
+ t.peek() !== i && r(() => {
110
+ t.value = i;
111
111
  });
112
112
  });
113
113
  }
114
- function Y(e, n, t) {
115
- if (m(e) && m(n)) {
116
- s(S(e, n, t));
114
+ function Z(e, t, n) {
115
+ if (m(e) && m(t)) {
116
+ s(M(e, t, n));
117
117
  return;
118
118
  }
119
- const o = e, r = n;
119
+ const o = e, r = t;
120
120
  h(() => {
121
121
  const c = E(o);
122
- t?.when && !t.when() || _(() => W(r, c));
122
+ n?.when && !n.when() || g(() => W(r, c));
123
123
  });
124
124
  }
125
- function R(e, n, t) {
125
+ function q(e, t, n) {
126
126
  let o;
127
127
  const r = (c) => {
128
128
  o?.abort(), o = new AbortController();
129
129
  const { signal: i } = o;
130
- $(() => n(c, { signal: i }));
130
+ x(() => t(c, { signal: i }));
131
131
  };
132
- if (!t?.debounce)
133
- s(F(e, r, { immediate: t?.immediate }));
132
+ if (!n?.debounce)
133
+ s(F(e, r, { immediate: n?.immediate }));
134
134
  else {
135
135
  let c;
136
136
  const i = F(
137
137
  e,
138
138
  (f) => {
139
- c && clearTimeout(c), c = setTimeout(() => r(f), t.debounce);
139
+ c && clearTimeout(c), c = setTimeout(() => r(f), n.debounce);
140
140
  },
141
- { immediate: t?.immediate }
141
+ { immediate: n?.immediate }
142
142
  );
143
143
  s(() => {
144
144
  c && clearTimeout(c), i();
@@ -146,99 +146,99 @@ function R(e, n, t) {
146
146
  }
147
147
  s(() => o?.abort());
148
148
  }
149
- function q(e, n, t) {
149
+ function z(e, t, n) {
150
150
  for (const o of B(e))
151
- m(o) ? s(G(o, n, t)) : z(o, n, t);
151
+ m(o) ? s(T(o, t, n)) : L(o, t, n);
152
152
  }
153
- function Z(e, n, t) {
154
- q(e, () => !n(), t);
153
+ function ee(e, t, n) {
154
+ z(e, () => !t(), n);
155
155
  }
156
- function z(e, n, t) {
157
- const o = I(e.__path);
156
+ function L(e, t, n) {
157
+ const o = R(e.__path);
158
158
  o && h(() => {
159
- const r = n();
160
- _(() => {
161
- r ? o.enable() : (o.disable(), t?.resetOnDisable && o.reset());
159
+ const r = t();
160
+ g(() => {
161
+ r ? o.enable() : (o.disable(), n?.resetOnDisable && o.reset());
162
162
  });
163
163
  });
164
164
  }
165
- function ee(e, n) {
166
- s(A(e, n));
165
+ function ne(e, t) {
166
+ s(O(e, t));
167
167
  }
168
- function te(e, n, t) {
169
- s(C(e, n, t));
168
+ function te(e, t, n) {
169
+ s(A(e, t, n));
170
170
  }
171
- function ne(e, n, t) {
172
- s(D(e, n, t));
171
+ function oe(e, t, n) {
172
+ s(D(e, t, n));
173
173
  }
174
- function oe(e, n) {
175
- s(M(e, n));
174
+ function re(e, t) {
175
+ s(G(e, t));
176
176
  }
177
- function g(e, n) {
178
- return n.split(".").reduce((t, o) => t?.[o], e);
177
+ function _(e, t) {
178
+ return t.split(".").reduce((n, o) => n?.[o], e);
179
179
  }
180
180
  function N(e) {
181
181
  return new Proxy(
182
182
  {},
183
183
  {
184
- get(n, t) {
185
- if (!(typeof t == "symbol" || t === "then"))
184
+ get(t, n) {
185
+ if (!(typeof n == "symbol" || n === "then"))
186
186
  throw new Error(
187
187
  `[@reformer/core/behaviors] applyEach: форма строки массива "${e}" недоступна (form.${String(
188
- t
188
+ n
189
189
  )}) — массив не материализован в схеме формы. Per-row node-операции (enableWhen/updateComponentProps/reset) требуют узла { array, item } в схеме; value-операции (row.$.*: compute/copyFrom/transformValue) работают и без материализации.`
190
190
  );
191
191
  }
192
192
  }
193
193
  );
194
194
  }
195
- function H(e, n) {
196
- const { model: t, form: o } = y(), r = e.__path;
195
+ function H(e, t) {
196
+ const { model: n, form: o } = y(), r = e.__path;
197
197
  if (!r) return;
198
- const c = g(t, r);
198
+ const c = _(n, r);
199
199
  if (!c) return;
200
200
  const i = o.getFieldByPath(
201
201
  r
202
- ), f = i?.length, u = /* @__PURE__ */ new Map();
202
+ ), f = i?.length, a = /* @__PURE__ */ new Map();
203
203
  h(() => {
204
204
  const d = f ? f.value : c.length, w = /* @__PURE__ */ new Set();
205
- for (let a = 0; a < d; a++) {
206
- const l = c.at(a);
207
- if (l != null && (w.add(l), !u.has(l))) {
208
- const b = i?.at?.(a) ?? N(r);
209
- u.set(l, n.__run(l, b));
205
+ for (let u = 0; u < d; u++) {
206
+ const l = c.at(u);
207
+ if (l != null && (w.add(l), !a.has(l))) {
208
+ const b = i?.at?.(u) ?? N(r);
209
+ a.set(l, t.__run(l, b));
210
210
  }
211
211
  }
212
- for (const [a, l] of u)
213
- w.has(a) || (l(), u.delete(a));
212
+ for (const [u, l] of a)
213
+ w.has(u) || (l(), a.delete(u));
214
214
  }), s(() => {
215
- for (const d of u.values()) d();
216
- u.clear();
215
+ for (const d of a.values()) d();
216
+ a.clear();
217
217
  });
218
218
  }
219
219
  function v(e) {
220
220
  if (e == null || typeof e != "object") return;
221
- const n = e;
222
- if (typeof n.at == "function" && typeof n.length == "number") {
223
- const t = n.length;
224
- for (let o = 0; o < t; o++) v(n.at(o));
221
+ const t = e;
222
+ if (typeof t.at == "function" && typeof t.length == "number") {
223
+ const n = t.length;
224
+ for (let o = 0; o < n; o++) v(t.at(o));
225
225
  return;
226
226
  }
227
- for (const t of Object.keys(e)) v(e[t]);
227
+ for (const n of Object.keys(e)) v(e[n]);
228
228
  }
229
- function re(e, n) {
230
- const { model: t } = y(), o = e.__path;
229
+ function ce(e, t) {
230
+ const { model: n } = y(), o = e.__path;
231
231
  if (!o) return;
232
- const r = g(t, o);
232
+ const r = _(n, o);
233
233
  r && H(
234
234
  e,
235
- T(({ model: c }) => {
236
- R(n(c), (i) => {
235
+ I(({ model: c }) => {
236
+ q(t(c), (i) => {
237
237
  if (i)
238
238
  for (let f = 0; f < r.length; f++) {
239
- const u = r.at(f);
240
- if (u && u !== c) {
241
- const d = n(u);
239
+ const a = r.at(f);
240
+ if (a && a !== c) {
241
+ const d = t(a);
242
242
  d.peek() && (d.value = !1);
243
243
  }
244
244
  }
@@ -246,57 +246,57 @@ function re(e, n) {
246
246
  })
247
247
  );
248
248
  }
249
- function ce(e, n) {
250
- const { model: t } = y(), o = e.__path;
249
+ function ie(e, t) {
250
+ const { model: n } = y(), o = e.__path;
251
251
  if (!o) return;
252
- const r = g(t, o);
252
+ const r = _(n, o);
253
253
  if (!r) return;
254
254
  let c = !1, i = 0;
255
255
  h(() => {
256
- v(r), !c && (c = !0, _(() => {
256
+ v(r), !c && (c = !0, g(() => {
257
257
  c = !1;
258
- const f = n(r.toArray());
259
- let u = !1;
258
+ const f = t(r.toArray());
259
+ let a = !1;
260
260
  for (const { index: d, patch: w } of f) {
261
- const a = r.at(d);
262
- if (a)
261
+ const u = r.at(d);
262
+ if (u)
263
263
  for (const [l, b] of Object.entries(w))
264
- a[l] !== b && (a[l] = b, u = !0);
264
+ u[l] !== b && (u[l] = b, a = !0);
265
265
  }
266
- if (i = u ? i + 1 : 0, i > 50)
266
+ if (i = a ? i + 1 : 0, i > 50)
267
267
  throw i = 0, new Error(
268
268
  `[@reformer/core/behaviors] aggregateInto("${o}"): запись не сходится (>50 проходов) — derive должна быть идемпотентной на фикспоинте.`
269
269
  );
270
270
  }));
271
271
  });
272
272
  }
273
- function ie(e, n) {
274
- const { form: t } = y();
273
+ function fe(e, t) {
274
+ const { form: n } = y();
275
275
  for (const o of B(e)) {
276
276
  const r = o, c = r.__path;
277
277
  if (!c) continue;
278
- const i = t ? t.getFieldByPath(c) : void 0, f = i ? i.getProxy?.() ?? i : void 0;
279
- s(n.__run(V(r), f));
278
+ const i = n ? n.getFieldByPath(c) : void 0, f = i ? i.getProxy?.() ?? i : void 0;
279
+ s(t.__run(S(r), f));
280
280
  }
281
281
  }
282
282
  export {
283
- ce as aggregateInto,
284
- ie as apply,
283
+ ie as aggregateInto,
284
+ fe as apply,
285
285
  H as applyEach,
286
- U as compute,
287
- X as computeFrom,
288
- Y as copyFrom,
289
- _ as defer,
290
- T as defineFormBehavior,
291
- Z as disableWhen,
286
+ X as compute,
287
+ Y as computeFrom,
288
+ Z as copyFrom,
289
+ g as defer,
290
+ I as defineFormBehavior,
291
+ ee as disableWhen,
292
292
  h as effect,
293
- q as enableWhen,
294
- re as exclusiveFlag,
293
+ z as enableWhen,
294
+ ce as exclusiveFlag,
295
295
  y as getScope,
296
- R as onChange,
296
+ q as onChange,
297
297
  s as onDispose,
298
298
  te as resetWhen,
299
- oe as revalidateWhen,
300
- ne as syncFields,
301
- ee as transformValue
299
+ re as revalidateWhen,
300
+ oe as syncFields,
301
+ ne as transformValue
302
302
  };