@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 +134 -134
- package/dist/form-model-DhW2HZOB.js +323 -0
- package/dist/index.js +47 -47
- package/dist/state/form-model.d.ts +14 -0
- package/dist/state/index.d.ts +2 -1
- package/dist/state/types.d.ts +39 -11
- package/dist/state.js +18 -18
- package/dist/validation.js +1 -1
- package/docs/llms/19-reading-values.md +30 -1
- package/docs/llms/20-compute-vs-watch.md +9 -0
- package/llms.txt +104 -5
- package/package.json +1 -1
- package/dist/derived-registry-CluZCQ7U.js +0 -16
- package/dist/form-model-DYCzGGKF.js +0 -286
package/dist/behaviors.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { effect as
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { e as
|
|
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
|
|
20
|
+
function I(e) {
|
|
21
21
|
return {
|
|
22
|
-
__run(
|
|
23
|
-
const o = { cleanups: [], model:
|
|
22
|
+
__run(t, n) {
|
|
23
|
+
const o = { cleanups: [], model: t, form: n }, r = p;
|
|
24
24
|
p = o;
|
|
25
25
|
try {
|
|
26
|
-
e({ model:
|
|
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(
|
|
37
|
+
s(j(e));
|
|
38
38
|
}
|
|
39
|
-
function
|
|
40
|
-
|
|
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
|
|
45
|
-
for (const
|
|
46
|
-
const o = e[
|
|
47
|
-
n
|
|
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
|
|
49
|
+
return t;
|
|
50
50
|
}
|
|
51
|
-
function W(e,
|
|
52
|
-
for (const
|
|
53
|
-
const o = e[
|
|
54
|
-
m(o) ? o.value =
|
|
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
|
|
57
|
+
function R(e) {
|
|
58
58
|
if (!e) return;
|
|
59
|
-
const { form:
|
|
60
|
-
return
|
|
59
|
+
const { form: t } = y();
|
|
60
|
+
return t.getFieldByPath(e);
|
|
61
61
|
}
|
|
62
|
-
function
|
|
62
|
+
function S(e) {
|
|
63
63
|
return new Proxy(
|
|
64
64
|
{},
|
|
65
65
|
{
|
|
66
|
-
get: (
|
|
67
|
-
if (
|
|
68
|
-
if (typeof
|
|
69
|
-
const o = e[
|
|
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 :
|
|
71
|
+
return m(o) ? o.value : S(o);
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
);
|
|
75
75
|
}
|
|
76
|
-
function
|
|
77
|
-
return (
|
|
76
|
+
function V(e) {
|
|
77
|
+
return (t) => {
|
|
78
78
|
try {
|
|
79
|
-
|
|
80
|
-
} catch (
|
|
81
|
-
if (
|
|
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
|
|
87
|
+
throw n;
|
|
88
88
|
}
|
|
89
89
|
};
|
|
90
90
|
}
|
|
91
|
-
function
|
|
92
|
-
|
|
93
|
-
const o =
|
|
91
|
+
function X(e, t, n) {
|
|
92
|
+
$(e), s(() => k(e));
|
|
93
|
+
const o = V(e);
|
|
94
94
|
h(() => {
|
|
95
|
-
if (
|
|
96
|
-
const r =
|
|
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
|
|
103
|
-
|
|
104
|
-
const r =
|
|
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 =
|
|
109
|
-
|
|
110
|
-
|
|
108
|
+
const i = n(...c);
|
|
109
|
+
t.peek() !== i && r(() => {
|
|
110
|
+
t.value = i;
|
|
111
111
|
});
|
|
112
112
|
});
|
|
113
113
|
}
|
|
114
|
-
function
|
|
115
|
-
if (m(e) && m(
|
|
116
|
-
s(
|
|
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 =
|
|
119
|
+
const o = e, r = t;
|
|
120
120
|
h(() => {
|
|
121
121
|
const c = E(o);
|
|
122
|
-
|
|
122
|
+
n?.when && !n.when() || g(() => W(r, c));
|
|
123
123
|
});
|
|
124
124
|
}
|
|
125
|
-
function
|
|
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
|
-
|
|
130
|
+
x(() => t(c, { signal: i }));
|
|
131
131
|
};
|
|
132
|
-
if (!
|
|
133
|
-
s(F(e, r, { 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),
|
|
139
|
+
c && clearTimeout(c), c = setTimeout(() => r(f), n.debounce);
|
|
140
140
|
},
|
|
141
|
-
{ 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
|
|
149
|
+
function z(e, t, n) {
|
|
150
150
|
for (const o of B(e))
|
|
151
|
-
m(o) ? s(
|
|
151
|
+
m(o) ? s(T(o, t, n)) : L(o, t, n);
|
|
152
152
|
}
|
|
153
|
-
function
|
|
154
|
-
|
|
153
|
+
function ee(e, t, n) {
|
|
154
|
+
z(e, () => !t(), n);
|
|
155
155
|
}
|
|
156
|
-
function
|
|
157
|
-
const o =
|
|
156
|
+
function L(e, t, n) {
|
|
157
|
+
const o = R(e.__path);
|
|
158
158
|
o && h(() => {
|
|
159
|
-
const r =
|
|
160
|
-
|
|
161
|
-
r ? o.enable() : (o.disable(),
|
|
159
|
+
const r = t();
|
|
160
|
+
g(() => {
|
|
161
|
+
r ? o.enable() : (o.disable(), n?.resetOnDisable && o.reset());
|
|
162
162
|
});
|
|
163
163
|
});
|
|
164
164
|
}
|
|
165
|
-
function
|
|
166
|
-
s(
|
|
165
|
+
function ne(e, t) {
|
|
166
|
+
s(O(e, t));
|
|
167
167
|
}
|
|
168
|
-
function te(e,
|
|
169
|
-
s(
|
|
168
|
+
function te(e, t, n) {
|
|
169
|
+
s(A(e, t, n));
|
|
170
170
|
}
|
|
171
|
-
function
|
|
172
|
-
s(D(e,
|
|
171
|
+
function oe(e, t, n) {
|
|
172
|
+
s(D(e, t, n));
|
|
173
173
|
}
|
|
174
|
-
function
|
|
175
|
-
s(
|
|
174
|
+
function re(e, t) {
|
|
175
|
+
s(G(e, t));
|
|
176
176
|
}
|
|
177
|
-
function
|
|
178
|
-
return
|
|
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(
|
|
185
|
-
if (!(typeof
|
|
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
|
-
|
|
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,
|
|
196
|
-
const { model:
|
|
195
|
+
function H(e, t) {
|
|
196
|
+
const { model: n, form: o } = y(), r = e.__path;
|
|
197
197
|
if (!r) return;
|
|
198
|
-
const c =
|
|
198
|
+
const c = _(n, r);
|
|
199
199
|
if (!c) return;
|
|
200
200
|
const i = o.getFieldByPath(
|
|
201
201
|
r
|
|
202
|
-
), f = i?.length,
|
|
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
|
|
206
|
-
const l = c.at(
|
|
207
|
-
if (l != null && (w.add(l), !
|
|
208
|
-
const b = i?.at?.(
|
|
209
|
-
|
|
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 [
|
|
213
|
-
w.has(
|
|
212
|
+
for (const [u, l] of a)
|
|
213
|
+
w.has(u) || (l(), a.delete(u));
|
|
214
214
|
}), s(() => {
|
|
215
|
-
for (const d of
|
|
216
|
-
|
|
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
|
|
222
|
-
if (typeof
|
|
223
|
-
const
|
|
224
|
-
for (let o = 0; 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
|
|
227
|
+
for (const n of Object.keys(e)) v(e[n]);
|
|
228
228
|
}
|
|
229
|
-
function
|
|
230
|
-
const { model:
|
|
229
|
+
function ce(e, t) {
|
|
230
|
+
const { model: n } = y(), o = e.__path;
|
|
231
231
|
if (!o) return;
|
|
232
|
-
const r =
|
|
232
|
+
const r = _(n, o);
|
|
233
233
|
r && H(
|
|
234
234
|
e,
|
|
235
|
-
|
|
236
|
-
|
|
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
|
|
240
|
-
if (
|
|
241
|
-
const d =
|
|
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
|
|
250
|
-
const { model:
|
|
249
|
+
function ie(e, t) {
|
|
250
|
+
const { model: n } = y(), o = e.__path;
|
|
251
251
|
if (!o) return;
|
|
252
|
-
const r =
|
|
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 =
|
|
259
|
-
let
|
|
258
|
+
const f = t(r.toArray());
|
|
259
|
+
let a = !1;
|
|
260
260
|
for (const { index: d, patch: w } of f) {
|
|
261
|
-
const
|
|
262
|
-
if (
|
|
261
|
+
const u = r.at(d);
|
|
262
|
+
if (u)
|
|
263
263
|
for (const [l, b] of Object.entries(w))
|
|
264
|
-
|
|
264
|
+
u[l] !== b && (u[l] = b, a = !0);
|
|
265
265
|
}
|
|
266
|
-
if (i =
|
|
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
|
|
274
|
-
const { form:
|
|
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 =
|
|
279
|
-
s(
|
|
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
|
-
|
|
284
|
-
|
|
283
|
+
ie as aggregateInto,
|
|
284
|
+
fe as apply,
|
|
285
285
|
H as applyEach,
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
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
|
-
|
|
294
|
-
|
|
293
|
+
z as enableWhen,
|
|
294
|
+
ce as exclusiveFlag,
|
|
295
295
|
y as getScope,
|
|
296
|
-
|
|
296
|
+
q as onChange,
|
|
297
297
|
s as onDispose,
|
|
298
298
|
te as resetWhen,
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
299
|
+
re as revalidateWhen,
|
|
300
|
+
oe as syncFields,
|
|
301
|
+
ne as transformValue
|
|
302
302
|
};
|