@reformer/core 1.1.0-beta.8 → 2.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-DzYL8kY_.js +499 -0
- package/dist/behaviors.js +14 -14
- package/dist/core/behavior/create-field-path.d.ts +3 -16
- package/dist/core/nodes/group-node.d.ts +14 -193
- package/dist/core/utils/field-path.d.ts +48 -0
- package/dist/core/utils/index.d.ts +1 -0
- package/dist/core/validation/field-path.d.ts +3 -39
- package/dist/core/validation/validation-context.d.ts +23 -0
- package/dist/hooks/types.d.ts +328 -0
- package/dist/hooks/useFormControl.d.ts +13 -37
- package/dist/hooks/useFormControlValue.d.ts +167 -0
- package/dist/hooks/useSignalSubscription.d.ts +17 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +492 -986
- package/dist/{registry-helpers-BfCZcMkO.js → registry-helpers-BRxAr6nG.js} +136 -72
- package/dist/{validators-DjXtDVoE.js → validators-gXoHPdqM.js} +194 -231
- package/dist/validators.js +25 -25
- package/llms.txt +317 -172
- package/package.json +8 -4
- package/dist/behaviors-BRaiR-UY.js +0 -528
- package/dist/core/behavior/behavior-applicator.d.ts +0 -71
- package/dist/core/nodes/group-node/field-registry.d.ts +0 -191
- package/dist/core/nodes/group-node/index.d.ts +0 -11
- package/dist/core/nodes/group-node/proxy-builder.d.ts +0 -71
- package/dist/core/nodes/group-node/state-manager.d.ts +0 -184
|
@@ -1,4 +1,64 @@
|
|
|
1
|
-
|
|
1
|
+
function k() {
|
|
2
|
+
return h("");
|
|
3
|
+
}
|
|
4
|
+
function h(i) {
|
|
5
|
+
return new Proxy({}, {
|
|
6
|
+
get(t, e) {
|
|
7
|
+
if (typeof e == "symbol")
|
|
8
|
+
return;
|
|
9
|
+
if (e === "__path" || e === "__fieldPath")
|
|
10
|
+
return i || e;
|
|
11
|
+
if (e === "__key") {
|
|
12
|
+
const a = i.split(".");
|
|
13
|
+
return a[a.length - 1] || e;
|
|
14
|
+
}
|
|
15
|
+
if (e === "then" || e === "catch" || e === "finally" || e === "constructor" || e === "toString" || e === "valueOf" || e === "toJSON")
|
|
16
|
+
return;
|
|
17
|
+
const r = i ? `${i}.${e}` : e, s = {
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
19
|
+
__key: e,
|
|
20
|
+
__path: r,
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
22
|
+
__formType: void 0,
|
|
23
|
+
__fieldType: void 0
|
|
24
|
+
};
|
|
25
|
+
return new Proxy(s, {
|
|
26
|
+
get(a, n) {
|
|
27
|
+
if (typeof n != "symbol") {
|
|
28
|
+
if (n === "__path" || n === "__fieldPath") return r;
|
|
29
|
+
if (n === "__key") return e;
|
|
30
|
+
if (n !== "__formType" && n !== "__fieldType" && !(n === "then" || n === "catch" || n === "finally" || n === "constructor" || n === "toString" || n === "valueOf" || n === "toJSON"))
|
|
31
|
+
return h(`${r}.${n}`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
function y(i) {
|
|
39
|
+
if (typeof i == "string")
|
|
40
|
+
return i;
|
|
41
|
+
if (i && typeof i == "object") {
|
|
42
|
+
const t = i.__path;
|
|
43
|
+
if (typeof t == "string")
|
|
44
|
+
return t;
|
|
45
|
+
}
|
|
46
|
+
throw new Error("Invalid field path node: " + JSON.stringify(i));
|
|
47
|
+
}
|
|
48
|
+
function C(i) {
|
|
49
|
+
const t = y(i);
|
|
50
|
+
return h(t);
|
|
51
|
+
}
|
|
52
|
+
function S(i) {
|
|
53
|
+
if (i && typeof i == "object" && "__key" in i)
|
|
54
|
+
return i.__key;
|
|
55
|
+
if (typeof i == "string") {
|
|
56
|
+
const t = i.split(".");
|
|
57
|
+
return t[t.length - 1];
|
|
58
|
+
}
|
|
59
|
+
throw new Error("Invalid field path node");
|
|
60
|
+
}
|
|
61
|
+
class d {
|
|
2
62
|
stack = [];
|
|
3
63
|
/**
|
|
4
64
|
* Добавить элемент в стек
|
|
@@ -52,7 +112,7 @@ class h {
|
|
|
52
112
|
this.stack = [];
|
|
53
113
|
}
|
|
54
114
|
}
|
|
55
|
-
class
|
|
115
|
+
class x {
|
|
56
116
|
validators = [];
|
|
57
117
|
conditionStack = [];
|
|
58
118
|
/**
|
|
@@ -84,12 +144,12 @@ class f {
|
|
|
84
144
|
return this.validators;
|
|
85
145
|
}
|
|
86
146
|
}
|
|
87
|
-
class
|
|
147
|
+
class o {
|
|
88
148
|
/**
|
|
89
149
|
* Global stack активных реестров
|
|
90
150
|
* Используется для изоляции форм друг от друга
|
|
91
151
|
*/
|
|
92
|
-
static registryStack = new
|
|
152
|
+
static registryStack = new d();
|
|
93
153
|
contextStack = [];
|
|
94
154
|
validators = [];
|
|
95
155
|
/**
|
|
@@ -109,7 +169,7 @@ class a {
|
|
|
109
169
|
* ```
|
|
110
170
|
*/
|
|
111
171
|
static getCurrent() {
|
|
112
|
-
return
|
|
172
|
+
return o.registryStack.getCurrent();
|
|
113
173
|
}
|
|
114
174
|
/**
|
|
115
175
|
* Начать регистрацию валидаторов для формы
|
|
@@ -117,8 +177,8 @@ class a {
|
|
|
117
177
|
* Помещает this в global stack для изоляции форм
|
|
118
178
|
*/
|
|
119
179
|
beginRegistration() {
|
|
120
|
-
const t = new
|
|
121
|
-
return this.contextStack.push(t),
|
|
180
|
+
const t = new x();
|
|
181
|
+
return this.contextStack.push(t), o.registryStack.push(this), t;
|
|
122
182
|
}
|
|
123
183
|
/**
|
|
124
184
|
* Завершить регистрацию и применить валидаторы к GroupNode
|
|
@@ -131,7 +191,7 @@ class a {
|
|
|
131
191
|
const e = this.contextStack.pop();
|
|
132
192
|
if (!e)
|
|
133
193
|
throw new Error("No active registration context");
|
|
134
|
-
|
|
194
|
+
o.registryStack.verify(this, "ValidationRegistry"), this.validators = e.getValidators(), this.applyValidators(t, this.validators), this.applyArrayItemValidators(t, this.validators);
|
|
135
195
|
}
|
|
136
196
|
/**
|
|
137
197
|
* Отменить регистрацию без применения валидаторов
|
|
@@ -142,7 +202,7 @@ class a {
|
|
|
142
202
|
cancelRegistration() {
|
|
143
203
|
if (!this.contextStack.pop())
|
|
144
204
|
throw new Error("No active registration context to cancel");
|
|
145
|
-
|
|
205
|
+
o.registryStack.verify(this, "ValidationRegistry");
|
|
146
206
|
}
|
|
147
207
|
/**
|
|
148
208
|
* Получить текущий контекст регистрации
|
|
@@ -153,39 +213,39 @@ class a {
|
|
|
153
213
|
/**
|
|
154
214
|
* Зарегистрировать синхронный валидатор
|
|
155
215
|
*/
|
|
156
|
-
registerSync(t, e,
|
|
157
|
-
const
|
|
158
|
-
if (!
|
|
216
|
+
registerSync(t, e, r) {
|
|
217
|
+
const s = this.getCurrentContext();
|
|
218
|
+
if (!s)
|
|
159
219
|
throw new Error("Validators can only be registered inside a validation schema function");
|
|
160
|
-
|
|
220
|
+
s.addValidator({
|
|
161
221
|
fieldPath: t,
|
|
162
222
|
type: "sync",
|
|
163
223
|
validator: e,
|
|
164
|
-
options:
|
|
224
|
+
options: r
|
|
165
225
|
});
|
|
166
226
|
}
|
|
167
227
|
/**
|
|
168
228
|
* Зарегистрировать асинхронный валидатор
|
|
169
229
|
*/
|
|
170
|
-
registerAsync(t, e,
|
|
171
|
-
const
|
|
172
|
-
if (!
|
|
230
|
+
registerAsync(t, e, r) {
|
|
231
|
+
const s = this.getCurrentContext();
|
|
232
|
+
if (!s)
|
|
173
233
|
throw new Error("Validators can only be registered inside a validation schema function");
|
|
174
|
-
|
|
234
|
+
s.addValidator({
|
|
175
235
|
fieldPath: t,
|
|
176
236
|
type: "async",
|
|
177
237
|
validator: e,
|
|
178
|
-
options:
|
|
238
|
+
options: r
|
|
179
239
|
});
|
|
180
240
|
}
|
|
181
241
|
/**
|
|
182
242
|
* Зарегистрировать tree валидатор
|
|
183
243
|
*/
|
|
184
244
|
registerTree(t, e) {
|
|
185
|
-
const
|
|
186
|
-
if (!
|
|
245
|
+
const r = this.getCurrentContext();
|
|
246
|
+
if (!r)
|
|
187
247
|
throw new Error("Validators can only be registered inside a validation schema function");
|
|
188
|
-
|
|
248
|
+
r.addValidator({
|
|
189
249
|
fieldPath: e?.targetField || "__tree__",
|
|
190
250
|
type: "tree",
|
|
191
251
|
validator: t,
|
|
@@ -196,10 +256,10 @@ class a {
|
|
|
196
256
|
* Войти в условный блок
|
|
197
257
|
*/
|
|
198
258
|
enterCondition(t, e) {
|
|
199
|
-
const
|
|
200
|
-
if (!
|
|
259
|
+
const r = this.getCurrentContext();
|
|
260
|
+
if (!r)
|
|
201
261
|
throw new Error("Conditions can only be used inside a validation schema function");
|
|
202
|
-
|
|
262
|
+
r.enterCondition(t, e);
|
|
203
263
|
}
|
|
204
264
|
/**
|
|
205
265
|
* Выйти из условного блока
|
|
@@ -220,12 +280,12 @@ class a {
|
|
|
220
280
|
* @param itemSchemaFn - Validation schema для элемента массива
|
|
221
281
|
*/
|
|
222
282
|
registerArrayItemValidation(t, e) {
|
|
223
|
-
const
|
|
224
|
-
if (!
|
|
283
|
+
const r = this.getCurrentContext();
|
|
284
|
+
if (!r)
|
|
225
285
|
throw new Error(
|
|
226
286
|
"Array item validators can only be registered inside a validation schema function"
|
|
227
287
|
);
|
|
228
|
-
|
|
288
|
+
r.addValidator({
|
|
229
289
|
fieldPath: t,
|
|
230
290
|
type: "array-items",
|
|
231
291
|
validator: e,
|
|
@@ -246,12 +306,12 @@ class a {
|
|
|
246
306
|
* @private
|
|
247
307
|
*/
|
|
248
308
|
applyValidators(t, e) {
|
|
249
|
-
const
|
|
250
|
-
for (const
|
|
251
|
-
if (
|
|
309
|
+
const r = /* @__PURE__ */ new Map();
|
|
310
|
+
for (const s of e) {
|
|
311
|
+
if (s.type === "tree" || s.type === "array-items")
|
|
252
312
|
continue;
|
|
253
|
-
const
|
|
254
|
-
|
|
313
|
+
const a = r.get(s.fieldPath) || [];
|
|
314
|
+
a.push(s), r.set(s.fieldPath, a);
|
|
255
315
|
}
|
|
256
316
|
}
|
|
257
317
|
/**
|
|
@@ -259,18 +319,18 @@ class a {
|
|
|
259
319
|
* @private
|
|
260
320
|
*/
|
|
261
321
|
applyArrayItemValidators(t, e) {
|
|
262
|
-
const
|
|
263
|
-
if (
|
|
264
|
-
for (const
|
|
265
|
-
const
|
|
266
|
-
if (
|
|
267
|
-
const
|
|
268
|
-
|
|
322
|
+
const r = e.filter((s) => s.type === "array-items");
|
|
323
|
+
if (r.length !== 0)
|
|
324
|
+
for (const s of r) {
|
|
325
|
+
const a = t[s.fieldPath.split(".")[0]];
|
|
326
|
+
if (a && "applyValidationSchema" in a) {
|
|
327
|
+
const n = s.validator;
|
|
328
|
+
a.applyValidationSchema(n);
|
|
269
329
|
}
|
|
270
330
|
}
|
|
271
331
|
}
|
|
272
332
|
}
|
|
273
|
-
class
|
|
333
|
+
class v {
|
|
274
334
|
/**
|
|
275
335
|
* Форма с типизированным Proxy-доступом к полям
|
|
276
336
|
*/
|
|
@@ -290,8 +350,8 @@ class p {
|
|
|
290
350
|
* @param value - Новое значение
|
|
291
351
|
*/
|
|
292
352
|
setFieldValue(t, e) {
|
|
293
|
-
const
|
|
294
|
-
|
|
353
|
+
const r = typeof t == "string" ? t : t.toString(), s = this._form.getFieldByPath(r);
|
|
354
|
+
s && s.setValue(e, { emitEvent: !1 });
|
|
295
355
|
}
|
|
296
356
|
}
|
|
297
357
|
class c {
|
|
@@ -299,7 +359,7 @@ class c {
|
|
|
299
359
|
* Stack активных контекстов регистрации
|
|
300
360
|
* Используется для изоляции форм друг от друга
|
|
301
361
|
*/
|
|
302
|
-
static contextStack = new
|
|
362
|
+
static contextStack = new d();
|
|
303
363
|
registrations = [];
|
|
304
364
|
isRegistering = !1;
|
|
305
365
|
/**
|
|
@@ -362,39 +422,39 @@ class c {
|
|
|
362
422
|
*/
|
|
363
423
|
endRegistration(t) {
|
|
364
424
|
this.isRegistering = !1, c.contextStack.verify(this, "BehaviorRegistry");
|
|
365
|
-
const e = new
|
|
366
|
-
for (const
|
|
367
|
-
const
|
|
368
|
-
|
|
425
|
+
const e = new v(t), r = [];
|
|
426
|
+
for (const a of this.registrations) {
|
|
427
|
+
const n = this.createEffect(a, t, e);
|
|
428
|
+
n && r.push(n);
|
|
369
429
|
}
|
|
370
|
-
const
|
|
371
|
-
|
|
430
|
+
const s = () => {
|
|
431
|
+
r.forEach((a) => a());
|
|
372
432
|
};
|
|
373
433
|
return {
|
|
374
434
|
count: this.registrations.length,
|
|
375
|
-
cleanup:
|
|
435
|
+
cleanup: s
|
|
376
436
|
};
|
|
377
437
|
}
|
|
378
438
|
/**
|
|
379
439
|
* Создать effect подписку для behavior
|
|
380
440
|
* @private
|
|
381
441
|
*/
|
|
382
|
-
createEffect(t, e,
|
|
383
|
-
const { handler:
|
|
384
|
-
let
|
|
385
|
-
const
|
|
386
|
-
|
|
387
|
-
},
|
|
388
|
-
|
|
389
|
-
},
|
|
390
|
-
return
|
|
391
|
-
|
|
442
|
+
createEffect(t, e, r) {
|
|
443
|
+
const { handler: s, debounce: a = 0 } = t;
|
|
444
|
+
let n = null;
|
|
445
|
+
const f = (u) => {
|
|
446
|
+
a > 0 ? (n && clearTimeout(n), n = setTimeout(u, a)) : u();
|
|
447
|
+
}, g = () => {
|
|
448
|
+
n && (clearTimeout(n), n = null);
|
|
449
|
+
}, l = s(e, r, f);
|
|
450
|
+
return l ? () => {
|
|
451
|
+
g(), l && l();
|
|
392
452
|
} : null;
|
|
393
453
|
}
|
|
394
454
|
}
|
|
395
|
-
function
|
|
396
|
-
const
|
|
397
|
-
return
|
|
455
|
+
function _() {
|
|
456
|
+
const i = o.getCurrent();
|
|
457
|
+
return i || {
|
|
398
458
|
registerSync: () => {
|
|
399
459
|
},
|
|
400
460
|
registerAsync: () => {
|
|
@@ -409,18 +469,22 @@ function y() {
|
|
|
409
469
|
}
|
|
410
470
|
};
|
|
411
471
|
}
|
|
412
|
-
function
|
|
413
|
-
const
|
|
414
|
-
return
|
|
472
|
+
function m() {
|
|
473
|
+
const i = c.getCurrent();
|
|
474
|
+
return i || {
|
|
415
475
|
register: () => {
|
|
416
476
|
}
|
|
417
477
|
};
|
|
418
478
|
}
|
|
419
479
|
export {
|
|
420
480
|
c as B,
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
481
|
+
d as R,
|
|
482
|
+
o as V,
|
|
483
|
+
S as a,
|
|
484
|
+
m as b,
|
|
485
|
+
k as c,
|
|
486
|
+
v as d,
|
|
487
|
+
y as e,
|
|
488
|
+
_ as g,
|
|
489
|
+
C as t
|
|
426
490
|
};
|