@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.
@@ -1,4 +1,64 @@
1
- class h {
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 f {
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 a {
147
+ class o {
88
148
  /**
89
149
  * Global stack активных реестров
90
150
  * Используется для изоляции форм друг от друга
91
151
  */
92
- static registryStack = new h();
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 a.registryStack.getCurrent();
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 f();
121
- return this.contextStack.push(t), a.registryStack.push(this), 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
- a.registryStack.verify(this, "ValidationRegistry"), this.validators = e.getValidators(), this.applyValidators(t, this.validators), this.applyArrayItemValidators(t, this.validators);
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
- a.registryStack.verify(this, "ValidationRegistry");
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, i) {
157
- const r = this.getCurrentContext();
158
- if (!r)
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
- r.addValidator({
220
+ s.addValidator({
161
221
  fieldPath: t,
162
222
  type: "sync",
163
223
  validator: e,
164
- options: i
224
+ options: r
165
225
  });
166
226
  }
167
227
  /**
168
228
  * Зарегистрировать асинхронный валидатор
169
229
  */
170
- registerAsync(t, e, i) {
171
- const r = this.getCurrentContext();
172
- if (!r)
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
- r.addValidator({
234
+ s.addValidator({
175
235
  fieldPath: t,
176
236
  type: "async",
177
237
  validator: e,
178
- options: i
238
+ options: r
179
239
  });
180
240
  }
181
241
  /**
182
242
  * Зарегистрировать tree валидатор
183
243
  */
184
244
  registerTree(t, e) {
185
- const i = this.getCurrentContext();
186
- if (!i)
245
+ const r = this.getCurrentContext();
246
+ if (!r)
187
247
  throw new Error("Validators can only be registered inside a validation schema function");
188
- i.addValidator({
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 i = this.getCurrentContext();
200
- if (!i)
259
+ const r = this.getCurrentContext();
260
+ if (!r)
201
261
  throw new Error("Conditions can only be used inside a validation schema function");
202
- i.enterCondition(t, e);
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 i = this.getCurrentContext();
224
- if (!i)
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
- i.addValidator({
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 i = /* @__PURE__ */ new Map();
250
- for (const r of e) {
251
- if (r.type === "tree" || r.type === "array-items")
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 n = i.get(r.fieldPath) || [];
254
- n.push(r), i.set(r.fieldPath, n);
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 i = e.filter((r) => r.type === "array-items");
263
- if (i.length !== 0)
264
- for (const r of i) {
265
- const n = t[r.fieldPath.split(".")[0]];
266
- if (n && "applyValidationSchema" in n) {
267
- const s = r.validator;
268
- n.applyValidationSchema(s);
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 p {
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 i = typeof t == "string" ? t : t.toString(), r = this._form.getFieldByPath(i);
294
- r && r.setValue(e, { emitEvent: !1 });
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 h();
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 p(t), i = [];
366
- for (const n of this.registrations) {
367
- const s = this.createEffect(n, t, e);
368
- s && i.push(s);
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 r = () => {
371
- i.forEach((n) => n());
430
+ const s = () => {
431
+ r.forEach((a) => a());
372
432
  };
373
433
  return {
374
434
  count: this.registrations.length,
375
- cleanup: r
435
+ cleanup: s
376
436
  };
377
437
  }
378
438
  /**
379
439
  * Создать effect подписку для behavior
380
440
  * @private
381
441
  */
382
- createEffect(t, e, i) {
383
- const { handler: r, debounce: n = 0 } = t;
384
- let s = null;
385
- const g = (l) => {
386
- n > 0 ? (s && clearTimeout(s), s = setTimeout(l, n)) : l();
387
- }, u = () => {
388
- s && (clearTimeout(s), s = null);
389
- }, d = r(e, i, g);
390
- return d ? () => {
391
- u(), d && d();
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 y() {
396
- const o = a.getCurrent();
397
- return o || {
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 x() {
413
- const o = c.getCurrent();
414
- return o || {
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
- h as R,
422
- a as V,
423
- x as a,
424
- p as b,
425
- y as g
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
  };