@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.
@@ -0,0 +1,499 @@
1
+ import { b as w, c as E, d as I, B as L } from "./registry-helpers-BRxAr6nG.js";
2
+ var $ = /* @__PURE__ */ Symbol.for("preact-signals");
3
+ function B() {
4
+ if (y > 1)
5
+ y--;
6
+ else {
7
+ for (var e, t = !1; P !== void 0; ) {
8
+ var i = P;
9
+ for (P = void 0, N++; i !== void 0; ) {
10
+ var n = i.o;
11
+ if (i.o = void 0, i.f &= -3, !(8 & i.f) && W(i)) try {
12
+ i.c();
13
+ } catch (s) {
14
+ t || (e = s, t = !0);
15
+ }
16
+ i = n;
17
+ }
18
+ }
19
+ if (N = 0, y--, t) throw e;
20
+ }
21
+ }
22
+ function rt(e) {
23
+ if (y > 0) return e();
24
+ y++;
25
+ try {
26
+ return e();
27
+ } finally {
28
+ B();
29
+ }
30
+ }
31
+ var o = void 0;
32
+ function C(e) {
33
+ var t = o;
34
+ o = void 0;
35
+ try {
36
+ return e();
37
+ } finally {
38
+ o = t;
39
+ }
40
+ }
41
+ var P = void 0, y = 0, N = 0, V = 0;
42
+ function A(e) {
43
+ if (o !== void 0) {
44
+ var t = e.n;
45
+ if (t === void 0 || t.t !== o)
46
+ return t = { i: 0, S: e, p: o.s, n: void 0, t: o, e: void 0, x: void 0, r: t }, o.s !== void 0 && (o.s.n = t), o.s = t, e.n = t, 32 & o.f && e.S(t), t;
47
+ if (t.i === -1)
48
+ return t.i = 0, t.n !== void 0 && (t.n.p = t.p, t.p !== void 0 && (t.p.n = t.n), t.p = o.s, t.n = void 0, o.s.n = t, o.s = t), t;
49
+ }
50
+ }
51
+ function d(e, t) {
52
+ this.v = e, this.i = 0, this.n = void 0, this.t = void 0, this.W = t?.watched, this.Z = t?.unwatched, this.name = t?.name;
53
+ }
54
+ d.prototype.brand = $;
55
+ d.prototype.h = function() {
56
+ return !0;
57
+ };
58
+ d.prototype.S = function(e) {
59
+ var t = this, i = this.t;
60
+ i !== e && e.e === void 0 && (e.x = i, this.t = e, i !== void 0 ? i.e = e : C(function() {
61
+ var n;
62
+ (n = t.W) == null || n.call(t);
63
+ }));
64
+ };
65
+ d.prototype.U = function(e) {
66
+ var t = this;
67
+ if (this.t !== void 0) {
68
+ var i = e.e, n = e.x;
69
+ i !== void 0 && (i.x = n, e.e = void 0), n !== void 0 && (n.e = i, e.x = void 0), e === this.t && (this.t = n, n === void 0 && C(function() {
70
+ var s;
71
+ (s = t.Z) == null || s.call(t);
72
+ }));
73
+ }
74
+ };
75
+ d.prototype.subscribe = function(e) {
76
+ var t = this;
77
+ return g(function() {
78
+ var i = t.value, n = o;
79
+ o = void 0;
80
+ try {
81
+ e(i);
82
+ } finally {
83
+ o = n;
84
+ }
85
+ }, { name: "sub" });
86
+ };
87
+ d.prototype.valueOf = function() {
88
+ return this.value;
89
+ };
90
+ d.prototype.toString = function() {
91
+ return this.value + "";
92
+ };
93
+ d.prototype.toJSON = function() {
94
+ return this.value;
95
+ };
96
+ d.prototype.peek = function() {
97
+ var e = o;
98
+ o = void 0;
99
+ try {
100
+ return this.value;
101
+ } finally {
102
+ o = e;
103
+ }
104
+ };
105
+ Object.defineProperty(d.prototype, "value", { get: function() {
106
+ var e = A(this);
107
+ return e !== void 0 && (e.i = this.i), this.v;
108
+ }, set: function(e) {
109
+ if (e !== this.v) {
110
+ if (N > 100) throw new Error("Cycle detected");
111
+ this.v = e, this.i++, V++, y++;
112
+ try {
113
+ for (var t = this.t; t !== void 0; t = t.x) t.t.N();
114
+ } finally {
115
+ B();
116
+ }
117
+ }
118
+ } });
119
+ function ot(e, t) {
120
+ return new d(e, t);
121
+ }
122
+ function W(e) {
123
+ for (var t = e.s; t !== void 0; t = t.n) if (t.S.i !== t.i || !t.S.h() || t.S.i !== t.i) return !0;
124
+ return !1;
125
+ }
126
+ function j(e) {
127
+ for (var t = e.s; t !== void 0; t = t.n) {
128
+ var i = t.S.n;
129
+ if (i !== void 0 && (t.r = i), t.S.n = t, t.i = -1, t.n === void 0) {
130
+ e.s = t;
131
+ break;
132
+ }
133
+ }
134
+ }
135
+ function k(e) {
136
+ for (var t = e.s, i = void 0; t !== void 0; ) {
137
+ var n = t.p;
138
+ t.i === -1 ? (t.S.U(t), n !== void 0 && (n.n = t.n), t.n !== void 0 && (t.n.p = n)) : i = t, t.S.n = t.r, t.r !== void 0 && (t.r = void 0), t = n;
139
+ }
140
+ e.s = i;
141
+ }
142
+ function _(e, t) {
143
+ d.call(this, void 0), this.x = e, this.s = void 0, this.g = V - 1, this.f = 4, this.W = t?.watched, this.Z = t?.unwatched, this.name = t?.name;
144
+ }
145
+ _.prototype = new d();
146
+ _.prototype.h = function() {
147
+ if (this.f &= -3, 1 & this.f) return !1;
148
+ if ((36 & this.f) == 32 || (this.f &= -5, this.g === V)) return !0;
149
+ if (this.g = V, this.f |= 1, this.i > 0 && !W(this))
150
+ return this.f &= -2, !0;
151
+ var e = o;
152
+ try {
153
+ j(this), o = this;
154
+ var t = this.x();
155
+ (16 & this.f || this.v !== t || this.i === 0) && (this.v = t, this.f &= -17, this.i++);
156
+ } catch (i) {
157
+ this.v = i, this.f |= 16, this.i++;
158
+ }
159
+ return o = e, k(this), this.f &= -2, !0;
160
+ };
161
+ _.prototype.S = function(e) {
162
+ if (this.t === void 0) {
163
+ this.f |= 36;
164
+ for (var t = this.s; t !== void 0; t = t.n) t.S.S(t);
165
+ }
166
+ d.prototype.S.call(this, e);
167
+ };
168
+ _.prototype.U = function(e) {
169
+ if (this.t !== void 0 && (d.prototype.U.call(this, e), this.t === void 0)) {
170
+ this.f &= -33;
171
+ for (var t = this.s; t !== void 0; t = t.n) t.S.U(t);
172
+ }
173
+ };
174
+ _.prototype.N = function() {
175
+ if (!(2 & this.f)) {
176
+ this.f |= 6;
177
+ for (var e = this.t; e !== void 0; e = e.x) e.t.N();
178
+ }
179
+ };
180
+ Object.defineProperty(_.prototype, "value", { get: function() {
181
+ if (1 & this.f) throw new Error("Cycle detected");
182
+ var e = A(this);
183
+ if (this.h(), e !== void 0 && (e.i = this.i), 16 & this.f) throw this.v;
184
+ return this.v;
185
+ } });
186
+ function st(e, t) {
187
+ return new _(e, t);
188
+ }
189
+ function M(e) {
190
+ var t = e.u;
191
+ if (e.u = void 0, typeof t == "function") {
192
+ y++;
193
+ var i = o;
194
+ o = void 0;
195
+ try {
196
+ t();
197
+ } catch (n) {
198
+ throw e.f &= -2, e.f |= 8, O(e), n;
199
+ } finally {
200
+ o = i, B();
201
+ }
202
+ }
203
+ }
204
+ function O(e) {
205
+ for (var t = e.s; t !== void 0; t = t.n) t.S.U(t);
206
+ e.x = void 0, e.s = void 0, M(e);
207
+ }
208
+ function z(e) {
209
+ if (o !== this) throw new Error("Out-of-order effect");
210
+ k(this), o = e, this.f &= -2, 8 & this.f && O(this), B();
211
+ }
212
+ function S(e, t) {
213
+ this.x = e, this.u = void 0, this.s = void 0, this.o = void 0, this.f = 32, this.name = t?.name;
214
+ }
215
+ S.prototype.c = function() {
216
+ var e = this.S();
217
+ try {
218
+ if (8 & this.f || this.x === void 0) return;
219
+ var t = this.x();
220
+ typeof t == "function" && (this.u = t);
221
+ } finally {
222
+ e();
223
+ }
224
+ };
225
+ S.prototype.S = function() {
226
+ if (1 & this.f) throw new Error("Cycle detected");
227
+ this.f |= 1, this.f &= -9, M(this), j(this), y++;
228
+ var e = o;
229
+ return o = this, z.bind(this, e);
230
+ };
231
+ S.prototype.N = function() {
232
+ 2 & this.f || (this.f |= 2, this.o = P, P = this);
233
+ };
234
+ S.prototype.d = function() {
235
+ this.f |= 8, 1 & this.f || O(this);
236
+ };
237
+ S.prototype.dispose = function() {
238
+ this.d();
239
+ };
240
+ function g(e, t) {
241
+ var i = new S(e, t);
242
+ try {
243
+ i.c();
244
+ } catch (s) {
245
+ throw i.d(), s;
246
+ }
247
+ var n = i.d.bind(i);
248
+ return n[Symbol.dispose] = n, n;
249
+ }
250
+ function F(e, t, i) {
251
+ const { debounce: n, immediate: s = !1 } = i || {}, f = (u, l, h) => {
252
+ const a = u.getFieldByPath(e.__path);
253
+ return a ? (s && queueMicrotask(() => {
254
+ const r = a.value.value;
255
+ t(r, l);
256
+ }), g(() => {
257
+ const r = a.value.value;
258
+ h(() => {
259
+ t(r, l);
260
+ });
261
+ })) : null;
262
+ };
263
+ w().register(f, { debounce: n });
264
+ }
265
+ function J(e, t, i) {
266
+ const { when: n, fields: s = "all", transform: f, debounce: u } = i || {};
267
+ F(
268
+ e,
269
+ (l, h) => {
270
+ if (n) {
271
+ const c = h.form.getValue();
272
+ if (!n(c)) return;
273
+ }
274
+ const a = f ? f(l) : l, r = h.form.getFieldByPath(t.__path);
275
+ if (r)
276
+ if (s === "all" || !s)
277
+ r.setValue(a, { emitEvent: !1 });
278
+ else {
279
+ const c = {};
280
+ s.forEach((v) => {
281
+ l && typeof l == "object" && (c[v] = l[v]);
282
+ }), "patchValue" in r && r.patchValue(c);
283
+ }
284
+ },
285
+ { debounce: u }
286
+ );
287
+ }
288
+ function R(e, t, i) {
289
+ const { debounce: n, resetOnDisable: s = !1 } = i || {}, f = (u, l, h) => {
290
+ const a = u.getFieldByPath(e.__path);
291
+ return a ? g(() => {
292
+ const r = u.value.value;
293
+ h(() => {
294
+ t(r) ? a.enable() : (a.disable(), s && a.reset());
295
+ });
296
+ }) : null;
297
+ };
298
+ w().register(f, { debounce: n });
299
+ }
300
+ function G(e, t, i) {
301
+ R(e, (n) => !t(n), i);
302
+ }
303
+ function H(e, t, i, n) {
304
+ const { debounce: s, condition: f } = n || {}, u = (l, h, a) => {
305
+ const r = l.getFieldByPath(t.__path);
306
+ if (!r) return null;
307
+ const c = e.map((v) => l.getFieldByPath(v.__path)).filter((v) => v !== void 0);
308
+ return c.length === 0 ? null : g(() => {
309
+ const v = c.map((b) => b.value.value);
310
+ a(() => {
311
+ if (f) {
312
+ const x = l.getValue();
313
+ if (!f(x)) return;
314
+ }
315
+ const b = {};
316
+ e.forEach((x, q) => {
317
+ const D = x.__path.split(".").pop() || x.__path;
318
+ b[D] = v[q];
319
+ });
320
+ const m = i(b);
321
+ r.value.peek() !== m && queueMicrotask(() => {
322
+ r.setValue(m, { emitEvent: !1 });
323
+ });
324
+ });
325
+ });
326
+ };
327
+ w().register(u, { debounce: s });
328
+ }
329
+ function K(e, t, i) {
330
+ const { debounce: n } = i || {}, s = (f, u, l) => {
331
+ const h = f.getFieldByPath(e.__path);
332
+ if (!h) return null;
333
+ const a = t.map((r) => f.getFieldByPath(r.__path)).filter((r) => r !== void 0);
334
+ return a.length === 0 ? null : g(() => {
335
+ a.forEach((r) => r.value.value), l(() => {
336
+ h.validate();
337
+ });
338
+ });
339
+ };
340
+ w().register(s, { debounce: n });
341
+ }
342
+ function Q(e, t, i) {
343
+ const { debounce: n, transform: s } = i || {}, f = (u, l, h) => {
344
+ const a = u.getFieldByPath(e.__path), r = u.getFieldByPath(t.__path);
345
+ if (!a || !r) return null;
346
+ let c = !1;
347
+ const v = g(() => {
348
+ const m = a.value.value;
349
+ c || h(() => {
350
+ c = !0;
351
+ const U = s ? s(m) : m;
352
+ r.setValue(U, { emitEvent: !1 }), c = !1;
353
+ });
354
+ }), b = g(() => {
355
+ const m = r.value.value;
356
+ c || h(() => {
357
+ c = !0, a.setValue(m, { emitEvent: !1 }), c = !1;
358
+ });
359
+ });
360
+ return () => {
361
+ v(), b();
362
+ };
363
+ };
364
+ w().register(f, { debounce: n });
365
+ }
366
+ function X(e, t, i) {
367
+ const { debounce: n, resetValue: s = null, onlyIfDirty: f = !1 } = i || {}, u = (l, h, a) => {
368
+ const r = l.getFieldByPath(e.__path);
369
+ return r ? g(() => {
370
+ const c = l.value.value;
371
+ a(() => {
372
+ if (t(c)) {
373
+ if (f && !r.dirty.value)
374
+ return;
375
+ r.setValue(s), r.markAsPristine(), r.markAsUntouched();
376
+ }
377
+ });
378
+ }) : null;
379
+ };
380
+ w().register(u, { debounce: n });
381
+ }
382
+ function T(e, t, i) {
383
+ const { onUserChangeOnly: n = !1, emitEvent: s = !0, debounce: f } = i || {};
384
+ F(
385
+ e,
386
+ (u, l) => {
387
+ const h = l.form.getFieldByPath(e.__path);
388
+ if (!h || n && !h.touched.value)
389
+ return;
390
+ const a = t(u);
391
+ a !== u && h.setValue(a, { emitEvent: s });
392
+ },
393
+ { debounce: f }
394
+ );
395
+ }
396
+ function p(e, t) {
397
+ return (i, n) => {
398
+ T(i, e, { ...t, ...n });
399
+ };
400
+ }
401
+ const Y = {
402
+ /** Перевести в верхний регистр */
403
+ toUpperCase: p((e) => e?.toUpperCase()),
404
+ /** Перевести в нижний регистр */
405
+ toLowerCase: p((e) => e?.toLowerCase()),
406
+ /** Удалить пробелы с краев */
407
+ trim: p((e) => e?.trim()),
408
+ /** Удалить все пробелы */
409
+ removeSpaces: p((e) => e?.replace(/\s/g, "")),
410
+ /** Оставить только цифры */
411
+ digitsOnly: p((e) => e?.replace(/\D/g, "")),
412
+ /** Округлить число */
413
+ round: p(
414
+ (e) => typeof e == "number" ? Math.round(e) : e
415
+ ),
416
+ /** Округлить до 2 знаков после запятой */
417
+ roundTo2: p(
418
+ (e) => typeof e == "number" ? Math.round(e * 100) / 100 : e
419
+ )
420
+ };
421
+ function Z(e) {
422
+ if (!e)
423
+ return E();
424
+ const t = e.__path;
425
+ return tt(t);
426
+ }
427
+ function tt(e) {
428
+ return new Proxy({}, {
429
+ get(t, i) {
430
+ return typeof i == "symbol" ? void 0 : {
431
+ __path: e ? `${e}.${i}` : i,
432
+ __key: i
433
+ };
434
+ }
435
+ });
436
+ }
437
+ function et(e, t) {
438
+ const i = (Array.isArray(e) ? e : [e]).filter(Boolean), n = Array.isArray(t) ? t : [t];
439
+ for (const s of i) {
440
+ const f = Z(s);
441
+ for (const u of n)
442
+ u(f);
443
+ }
444
+ }
445
+ function it(e, t, i) {
446
+ if (!e) return;
447
+ let n = !1;
448
+ F(
449
+ e,
450
+ (s, f) => {
451
+ if (!n && t(s)) {
452
+ const u = E();
453
+ i(u), n = !0;
454
+ }
455
+ },
456
+ { immediate: !0 }
457
+ );
458
+ }
459
+ const at = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
460
+ __proto__: null,
461
+ BehaviorContextImpl: I,
462
+ BehaviorRegistry: L,
463
+ apply: et,
464
+ applyWhen: it,
465
+ computeFrom: H,
466
+ copyFrom: J,
467
+ createFieldPath: E,
468
+ createTransformer: p,
469
+ disableWhen: G,
470
+ enableWhen: R,
471
+ resetWhen: X,
472
+ revalidateWhen: K,
473
+ syncFields: Q,
474
+ toBehaviorFieldPath: Z,
475
+ transformValue: T,
476
+ transformers: Y,
477
+ watchField: F
478
+ }, Symbol.toStringTag, { value: "Module" }));
479
+ export {
480
+ g as E,
481
+ et as a,
482
+ it as b,
483
+ J as c,
484
+ ot as d,
485
+ R as e,
486
+ G as f,
487
+ H as g,
488
+ F as h,
489
+ at as i,
490
+ K as j,
491
+ X as k,
492
+ T as l,
493
+ p as m,
494
+ Y as n,
495
+ rt as r,
496
+ Q as s,
497
+ Z as t,
498
+ st as w
499
+ };
package/dist/behaviors.js CHANGED
@@ -1,5 +1,5 @@
1
- import { a as s, b as r, h as t, e as o, c as l, m as h, i as n, g as i, f as m, k as p, r as c, s as d, t as f, l as F, n as y, j as W } from "./behaviors-BRaiR-UY.js";
2
- import { b as v, B } from "./registry-helpers-BfCZcMkO.js";
1
+ import { a as s, b as r, g as t, c as o, m as l, i as h, f as n, e as i, k as m, j as p, s as c, t as d, l as f, n as F, h as y } from "./behaviors-DzYL8kY_.js";
2
+ import { d as v, B, c as b } from "./registry-helpers-BRxAr6nG.js";
3
3
  export {
4
4
  v as BehaviorContextImpl,
5
5
  B as BehaviorRegistry,
@@ -7,16 +7,16 @@ export {
7
7
  r as applyWhen,
8
8
  t as computeFrom,
9
9
  o as copyFrom,
10
- l as createFieldPath,
11
- h as createTransformer,
12
- n as default,
13
- i as disableWhen,
14
- m as enableWhen,
15
- p as resetWhen,
16
- c as revalidateWhen,
17
- d as syncFields,
18
- f as toBehaviorFieldPath,
19
- F as transformValue,
20
- y as transformers,
21
- W as watchField
10
+ b as createFieldPath,
11
+ l as createTransformer,
12
+ h as default,
13
+ n as disableWhen,
14
+ i as enableWhen,
15
+ m as resetWhen,
16
+ p as revalidateWhen,
17
+ c as syncFields,
18
+ d as toBehaviorFieldPath,
19
+ f as transformValue,
20
+ F as transformers,
21
+ y as watchField
22
22
  };
@@ -1,20 +1,7 @@
1
1
  /**
2
2
  * Создание типизированного FieldPath для Behavior Schema
3
- * Аналогично createFieldPath из validators
4
- */
5
- import type { FieldPath } from '../types';
6
- /**
7
- * Создать типизированный путь к полям формы
8
- * Используется для декларативного описания behavior схем
9
3
  *
10
- * @example
11
- * ```typescript
12
- * const schema: BehaviorSchemaFn<MyForm> = (path) => {
13
- * // path.email, path.address.city и т.д. - типизированы
14
- * copyFrom(path.residenceAddress, path.registrationAddress, {
15
- * when: (form) => form.sameAsRegistration
16
- * });
17
- * };
18
- * ```
4
+ * @deprecated Импортируйте из '../utils/field-path' напрямую.
5
+ * Этот файл оставлен для обратной совместимости.
19
6
  */
20
- export declare function createFieldPath<T>(): FieldPath<T>;
7
+ export { createFieldPath } from '../utils/field-path';