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