@reformer/core 11.0.0-beta.7 → 11.0.0-beta.8

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.
Files changed (56) hide show
  1. package/README.md +7 -3
  2. package/dist/behaviors.js +211 -174
  3. package/dist/create-model-BBRHhHwK.js +30 -0
  4. package/dist/form/behaviors/collections.d.ts +14 -1
  5. package/dist/form/behaviors/context.d.ts +18 -2
  6. package/dist/form/behaviors/index.d.ts +3 -1
  7. package/dist/form/behaviors/internals.d.ts +0 -1
  8. package/dist/form/behaviors/schema-operators.d.ts +76 -0
  9. package/dist/form/behaviors/types.d.ts +15 -3
  10. package/dist/form/create-core-form.d.ts +5 -3
  11. package/dist/form/create-form.d.ts +28 -53
  12. package/dist/form/form-bundle.d.ts +136 -0
  13. package/dist/form/index.d.ts +6 -1
  14. package/dist/form/nodes/field-node.d.ts +2 -2
  15. package/dist/form/nodes/group-node.d.ts +1 -1
  16. package/dist/form/nodes/model-array-node.d.ts +10 -5
  17. package/dist/form/schema-controller.d.ts +137 -0
  18. package/dist/form/schema-subtree.d.ts +28 -0
  19. package/dist/form/signal-node-registry.d.ts +22 -16
  20. package/dist/form/types/deep-schema.d.ts +2 -2
  21. package/dist/form/types/form-proxy.d.ts +1 -1
  22. package/dist/form/types/schema-node.d.ts +37 -12
  23. package/dist/form/validation/context.d.ts +6 -1
  24. package/dist/form/validation/index.d.ts +1 -1
  25. package/dist/form/validation/operators.d.ts +70 -8
  26. package/dist/form/validation/types.d.ts +2 -1
  27. package/dist/index.js +345 -254
  28. package/dist/model/index.d.ts +5 -0
  29. package/dist/model/model-nodes.d.ts +67 -4
  30. package/dist/model/model-signals-proxy.d.ts +8 -1
  31. package/dist/model/model-value-proxy.d.ts +76 -0
  32. package/dist/model/types.d.ts +7 -4
  33. package/dist/model-value-proxy-caTmAiUd.js +419 -0
  34. package/dist/model.js +19 -17
  35. package/dist/node-BeV_lV5i.js +100 -0
  36. package/dist/platforms/react/form-bundle-context.d.ts +27 -0
  37. package/dist/platforms/react/index.d.ts +1 -0
  38. package/dist/strategy-DgzELWno.js +204 -0
  39. package/dist/validation.js +7 -6
  40. package/docs/llms/03-api-signatures.md +4 -4
  41. package/docs/llms/09-formschema.md +5 -5
  42. package/docs/llms/10-arrays.md +23 -4
  43. package/docs/llms/16-ui-components.md +2 -2
  44. package/docs/llms/18-conditional-fields.md +1 -1
  45. package/docs/llms/21-array-operations.md +26 -0
  46. package/docs/llms/28-submit-and-reset.md +3 -3
  47. package/docs/llms/29-async-preload.md +4 -4
  48. package/docs/llms/33-validation-strategy.md +2 -2
  49. package/docs/llms/35-unified-contract.md +246 -0
  50. package/llms-index.json +1 -1
  51. package/llms.txt +1148 -122
  52. package/package.json +1 -1
  53. package/dist/create-model-B8U-COv-.js +0 -103
  54. package/dist/model-signals-proxy-2vqS243J.js +0 -250
  55. package/dist/node-DGEFMTQu.js +0 -18
  56. package/dist/strategy-BXS_gBfz.js +0 -170
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reformer/core",
3
- "version": "11.0.0-beta.7",
3
+ "version": "11.0.0-beta.8",
4
4
  "description": "Reactive form state management library for React with signals-based architecture",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -1,103 +0,0 @@
1
- import { s as p, r as g, c as u, G as v } from "./model-signals-proxy-2vqS243J.js";
2
- function r(t) {
3
- if (t)
4
- return t.kind === "group" ? d(t) : t.kind === "array" ? w(t) : t.read();
5
- }
6
- function w(t) {
7
- const i = {
8
- get length() {
9
- return t.items.value.length;
10
- },
11
- push: (e) => t.push(e),
12
- insertAt: (e, n) => t.insertAt(e, n),
13
- removeAt: (e) => t.removeAt(e),
14
- move: (e, n) => t.move(e, n),
15
- swap: (e, n) => t.swap(e, n),
16
- clear: () => t.clear(),
17
- at: (e) => r(t.items.value[e]),
18
- map: (e) => t.items.value.map((n, s) => e(r(n), s)),
19
- forEach: (e) => t.items.value.forEach((n, s) => e(r(n), s)),
20
- toArray: () => t.peek(),
21
- [Symbol.iterator]: function* () {
22
- const e = t.items.value;
23
- for (let n = 0; n < e.length; n++) yield r(e[n]);
24
- }
25
- };
26
- return new Proxy(i, {
27
- get: (e, n, s) => n === "__path" ? t.path : typeof n == "string" && u(n) ? r(t.items.value[Number(n)]) : Reflect.get(e, n, s),
28
- has: (e, n) => typeof n == "string" && u(n) ? Number(n) < t.items.value.length : Reflect.has(e, n)
29
- });
30
- }
31
- const h = /* @__PURE__ */ new Set([
32
- "$",
33
- "get",
34
- "set",
35
- "patch",
36
- "isDirty",
37
- "reset",
38
- "captureInitial",
39
- "signalAt"
40
- ]), m = /* @__PURE__ */ new WeakMap(), o = /* @__PURE__ */ new WeakMap();
41
- function d(t) {
42
- const i = m.get(t);
43
- if (i) return i;
44
- const e = {
45
- $: p(t),
46
- get: () => t.peek(),
47
- set: (s) => t.set(s),
48
- patch: (s) => t.set(s),
49
- isDirty: () => t.dirty(),
50
- reset: () => t.resetToInitial(),
51
- captureInitial: () => t.captureInitial(),
52
- signalAt: (s) => g(t, s)
53
- }, n = new Proxy(
54
- {},
55
- {
56
- get: (s, a) => {
57
- if (a === "__path") return t.path;
58
- if (typeof a != "string") return;
59
- const c = t.children.get(a);
60
- if (c) return r(c);
61
- if (h.has(a)) return e[a];
62
- },
63
- set: (s, a, c) => {
64
- if (typeof a != "string") return !1;
65
- const f = t.children.get(a);
66
- return f ? (f.set(c), !0) : !1;
67
- },
68
- has: (s, a) => typeof a == "string" && (t.children.has(a) || h.has(a)),
69
- ownKeys: () => [...t.children.keys()],
70
- getOwnPropertyDescriptor: (s, a) => typeof a == "string" && t.children.has(a) ? { enumerable: !0, configurable: !0 } : void 0
71
- }
72
- );
73
- return m.set(t, n), o.set(n, t), n;
74
- }
75
- function l(t, i, e) {
76
- if (t.kind === "leaf") {
77
- i(t.signal);
78
- return;
79
- }
80
- if (t.kind === "group") {
81
- for (const n of t.children.values()) l(n, i, e);
82
- return;
83
- }
84
- e && i(p(t));
85
- for (const n of t.items.value) l(n, i, e);
86
- }
87
- function x(t, i) {
88
- const e = o.get(t);
89
- e && l(e, i, !1);
90
- }
91
- function y(t, i) {
92
- const e = o.get(t);
93
- e && l(e, i, !0);
94
- }
95
- function A(t) {
96
- const i = new v(t, "");
97
- return d(i);
98
- }
99
- export {
100
- y as a,
101
- A as c,
102
- x as e
103
- };
@@ -1,250 +0,0 @@
1
- import { batch as y, signal as v, Signal as A, computed as w } from "@preact/signals-core";
2
- const u = /* @__PURE__ */ new WeakMap();
3
- function R(t) {
4
- u.set(t, (u.get(t) ?? 0) + 1);
5
- }
6
- function D(t) {
7
- const e = u.get(t);
8
- e !== void 0 && (e <= 1 ? u.delete(t) : u.set(t, e - 1));
9
- }
10
- function _(t) {
11
- return u.has(t);
12
- }
13
- const h = (t) => !(t === null || typeof t != "object" || Array.isArray(t) || t instanceof Date || typeof Blob < "u" && t instanceof Blob || typeof File < "u" && t instanceof File), o = (t, e) => t === "" ? String(e) : `${t}.${e}`, S = (t) => /^\d+$/.test(t), l = (t) => {
14
- if (Array.isArray(t)) return t.map(l);
15
- if (h(t)) {
16
- const e = {};
17
- for (const r of Object.keys(t)) e[r] = l(t[r]);
18
- return e;
19
- }
20
- return t;
21
- }, d = (t, e) => {
22
- if (t === e) return !0;
23
- if (Array.isArray(t) && Array.isArray(e))
24
- return t.length !== e.length ? !1 : t.every((r, i) => d(r, e[i]));
25
- if (h(t) && h(e)) {
26
- const r = Object.keys(t), i = Object.keys(e);
27
- return r.length !== i.length ? !1 : r.every((s) => d(t[s], e[s]));
28
- }
29
- return !1;
30
- };
31
- class j {
32
- constructor(e, r) {
33
- this.path = r;
34
- const i = v(e);
35
- i.__path = r, this.signal = i, this.initial = l(e);
36
- }
37
- kind = "leaf";
38
- signal;
39
- initial;
40
- rebase(e) {
41
- this.path = e, this.signal.__path = e;
42
- }
43
- /** Реактивное чтение (внутри effect/computed создаёт зависимость). */
44
- read() {
45
- return this.signal.value;
46
- }
47
- /** Нереактивный снимок. */
48
- peek() {
49
- return this.signal.peek();
50
- }
51
- set(e) {
52
- this.signal.value = e;
53
- }
54
- resetToInitial() {
55
- this.signal.value = l(this.initial);
56
- }
57
- captureInitial() {
58
- this.initial = l(this.signal.peek());
59
- }
60
- dirty() {
61
- return !d(this.signal.peek(), this.initial);
62
- }
63
- }
64
- class $ {
65
- constructor(e, r) {
66
- this.path = r;
67
- for (const i of Object.keys(e))
68
- this.children.set(i, c(e[i], o(r, i)));
69
- }
70
- kind = "group";
71
- children = /* @__PURE__ */ new Map();
72
- rebase(e) {
73
- this.path = e;
74
- for (const [r, i] of this.children) i.rebase(o(e, r));
75
- }
76
- /** Реактивное чтение поддерева (внутри effect/computed подписывает на все листья группы). */
77
- read() {
78
- const e = {};
79
- for (const [r, i] of this.children) e[r] = i.read();
80
- return e;
81
- }
82
- peek() {
83
- const e = {};
84
- for (const [r, i] of this.children) e[r] = i.peek();
85
- return e;
86
- }
87
- set(e) {
88
- if (e == null || typeof e != "object") return;
89
- const r = e;
90
- y(() => {
91
- for (const [i, s] of this.children)
92
- i in r && (s.kind === "leaf" && _(s.signal) || s.set(r[i]));
93
- });
94
- }
95
- resetToInitial() {
96
- y(() => {
97
- for (const e of this.children.values()) e.resetToInitial();
98
- });
99
- }
100
- captureInitial() {
101
- for (const e of this.children.values()) e.captureInitial();
102
- }
103
- dirty() {
104
- for (const e of this.children.values()) if (e.dirty()) return !0;
105
- return !1;
106
- }
107
- }
108
- class x {
109
- constructor(e, r) {
110
- this.path = r, this.items = v(e.map((i, s) => c(i, o(r, s)))), this.initial = l(e);
111
- }
112
- kind = "array";
113
- items;
114
- initial;
115
- rebase(e) {
116
- this.path = e, this.items.peek().forEach((r, i) => r.rebase(o(e, i)));
117
- }
118
- reindex() {
119
- this.items.peek().forEach((e, r) => e.rebase(o(this.path, r)));
120
- }
121
- push(e) {
122
- const r = this.items.peek();
123
- this.items.value = [...r, c(e, o(this.path, r.length))];
124
- }
125
- insertAt(e, r) {
126
- const i = [...this.items.peek()];
127
- i.splice(e, 0, c(r, o(this.path, e))), this.items.value = i, this.reindex();
128
- }
129
- removeAt(e) {
130
- const r = [...this.items.peek()];
131
- r.splice(e, 1), this.items.value = r, this.reindex();
132
- }
133
- move(e, r) {
134
- const i = [...this.items.peek()], [s] = i.splice(e, 1);
135
- s && i.splice(r, 0, s), this.items.value = i, this.reindex();
136
- }
137
- swap(e, r) {
138
- const i = [...this.items.peek()];
139
- e < 0 || r < 0 || e >= i.length || r >= i.length || e === r || ([i[e], i[r]] = [i[r], i[e]], this.items.value = i, this.reindex());
140
- }
141
- clear() {
142
- this.items.value = [];
143
- }
144
- /**
145
- * Реактивное чтение массива. Читаем `items.value` (а не `.peek()`) — внутри effect/computed это
146
- * подписка на СОСТАВ массива, поэтому push/removeAt/move ретригерят наравне с правкой элемента.
147
- */
148
- read() {
149
- return this.items.value.map((e) => e.read());
150
- }
151
- peek() {
152
- return this.items.peek().map((e) => e.peek());
153
- }
154
- set(e) {
155
- const r = Array.isArray(e) ? e : [];
156
- this.items.value = r.map((i, s) => c(i, o(this.path, s)));
157
- }
158
- resetToInitial() {
159
- this.set(l(this.initial));
160
- }
161
- captureInitial() {
162
- this.initial = l(this.peek());
163
- }
164
- dirty() {
165
- return !d(this.peek(), this.initial);
166
- }
167
- }
168
- function c(t, e) {
169
- return Array.isArray(t) ? new x(t, e) : h(t) ? new $(t, e) : new j(t, e);
170
- }
171
- const k = /* @__PURE__ */ new WeakMap();
172
- function I(t) {
173
- const e = w(() => t.read());
174
- return {
175
- get value() {
176
- return e.value;
177
- },
178
- peek: () => e.peek(),
179
- subscribe: (r) => e.subscribe(r),
180
- valueOf: () => e.value,
181
- toString: () => String(e.value),
182
- toJSON: () => e.value,
183
- brand: e.brand
184
- };
185
- }
186
- function b(t) {
187
- if (t.kind === "leaf") return t.signal;
188
- const e = k.get(t);
189
- if (e) return e;
190
- const r = I(t), i = t.kind === "group", s = (a) => i ? t.children.get(a) : S(a) ? t.items.value[Number(a)] : void 0, g = i ? {} : {
191
- get length() {
192
- return t.items.value.length;
193
- }
194
- }, m = new Proxy(g, {
195
- get: (a, n, p) => {
196
- if (n === "__path") return t.path;
197
- if (n === "__kind") return t.kind;
198
- if (typeof n != "string") return Reflect.get(r, n, r);
199
- const f = s(n);
200
- return f ? b(f) : !i && Reflect.has(a, n) ? Reflect.get(a, n, p) : Reflect.get(r, n, r);
201
- },
202
- set: (a, n, p) => {
203
- if (!i && n === "value")
204
- return t.set(p), !0;
205
- const f = t.path === "" ? "model.$" : `model.$.${t.path}`;
206
- throw new TypeError(
207
- `[@reformer/core] ${f}: запись в «${String(n)}» ` + (i ? "узла-группы невозможна — группа читается целиком, а пишется по полям (model.$.<поле>.value) либо через model.patch(...)" : "узла-массива невозможна — массив заменяется целиком через .value, а элемент правится своим сигналом (model.$.<массив>[i].value)")
208
- );
209
- },
210
- has: (a, n) => typeof n == "string" && (s(n) !== void 0 || !i && Reflect.has(a, n)),
211
- ownKeys: () => i ? [...t.children.keys()] : Reflect.ownKeys(g),
212
- getOwnPropertyDescriptor: (a, n) => typeof n == "string" && s(n) ? { enumerable: !0, configurable: !0 } : i ? void 0 : Reflect.getOwnPropertyDescriptor(a, n)
213
- });
214
- return k.set(t, m), m;
215
- }
216
- function P(t) {
217
- if (t == null || typeof t != "object") return !1;
218
- const e = t.__kind;
219
- return e === "group" || e === "array";
220
- }
221
- function O(t) {
222
- return t == null || typeof t != "object" ? !1 : t.__kind === "array";
223
- }
224
- function M(t) {
225
- return t instanceof A || O(t);
226
- }
227
- function T(t, e) {
228
- if (!e) return;
229
- let r = t;
230
- for (const i of e.split(".")) {
231
- if (!r) return;
232
- if (r.kind === "group") r = r.children.get(i);
233
- else if (r.kind === "array") r = r.items.peek()[Number(i)];
234
- else return;
235
- }
236
- if (r)
237
- return r.kind === "leaf" ? r.signal : r.kind === "array" ? b(r) : void 0;
238
- }
239
- export {
240
- $ as G,
241
- M as a,
242
- _ as b,
243
- S as c,
244
- O as d,
245
- P as i,
246
- R as m,
247
- T as r,
248
- b as s,
249
- D as u
250
- };
@@ -1,18 +0,0 @@
1
- import { effect as i } from "@preact/signals-core";
2
- import { g as s } from "./signal-node-registry-tiwel-TV.js";
3
- import { d as f } from "./behaviors-value-C7dSEhCc.js";
4
- function a(n, r, t) {
5
- return i(() => {
6
- const o = r(), e = s(n);
7
- e && f(() => {
8
- o ? e.enable() : (e.disable(), t?.resetOnDisable && e.reset());
9
- });
10
- });
11
- }
12
- function b(n, r, t) {
13
- return a(n, () => !r(), t);
14
- }
15
- export {
16
- b as d,
17
- a as e
18
- };
@@ -1,170 +0,0 @@
1
- import { signal as A, effect as M } from "@preact/signals-core";
2
- import { a as W } from "./create-model-B8U-COv-.js";
3
- import { g as v } from "./signal-node-registry-tiwel-TV.js";
4
- let g = null;
5
- function E(e, n) {
6
- const t = g;
7
- g = e;
8
- try {
9
- return n();
10
- } finally {
11
- g = t;
12
- }
13
- }
14
- function u(e) {
15
- if (!g)
16
- throw new Error(
17
- `[@reformer/core/validation] "${e}" вызван вне схемы валидации — операторы валидации можно вызывать только внутри прогона validateModel(...) (напрямую или через apply/each).`
18
- );
19
- return g;
20
- }
21
- function m(e, n) {
22
- let t = e.errors.get(n);
23
- return t || e.errors.set(n, t = []), t;
24
- }
25
- const b = (e) => e.whenStack.every((n) => n());
26
- function D(e, n) {
27
- const t = u("validate"), r = m(t, e);
28
- if (!b(t)) return;
29
- const o = e.peek();
30
- for (const a of n) {
31
- const i = a(o, t.model, t.model);
32
- i && r.push(i);
33
- }
34
- }
35
- function N(e, n) {
36
- const t = u("validateAsync"), r = m(t, e);
37
- if (!b(t)) return;
38
- const o = e.peek(), a = t.signal;
39
- for (const i of n)
40
- t.pending.push(
41
- i(o, { signal: a }).then(
42
- (s) => {
43
- s && !a.aborted && r.push(s);
44
- },
45
- () => {
46
- }
47
- )
48
- );
49
- }
50
- function R(e, n) {
51
- const t = u("validateWhen");
52
- t.whenStack.push(e);
53
- try {
54
- n();
55
- } finally {
56
- t.whenStack.pop();
57
- }
58
- }
59
- function _(e, n) {
60
- const t = u("cross"), r = m(t, e);
61
- if (!b(t)) return;
62
- const o = n(t.model.get());
63
- o && r.push(o);
64
- }
65
- function $(e, n) {
66
- u("each");
67
- const t = e.length;
68
- for (let r = 0; r < t; r++) n(e.at(r));
69
- }
70
- function j(...e) {
71
- const t = u("apply").model;
72
- for (const r of e) r({ model: t });
73
- }
74
- function z(e) {
75
- return e;
76
- }
77
- const x = /* @__PURE__ */ new WeakMap();
78
- function P(e, n) {
79
- let t = x.get(e);
80
- t || x.set(e, t = /* @__PURE__ */ new WeakMap());
81
- let r = t.get(n);
82
- return r || t.set(n, r = { fields: /* @__PURE__ */ new Set(), ac: null }), r;
83
- }
84
- const T = (e) => {
85
- for (const n of e.values()) for (const t of n) if (t.severity !== "warning") return !0;
86
- return !1;
87
- };
88
- function V(e) {
89
- return e.aborted ? Promise.resolve() : new Promise((n) => {
90
- e.addEventListener("abort", () => n(), { once: !0 });
91
- });
92
- }
93
- async function C(e, n, t) {
94
- const r = P(e, n);
95
- r.ac?.abort();
96
- const o = new AbortController();
97
- r.ac = o;
98
- const a = {
99
- model: e,
100
- errors: /* @__PURE__ */ new Map(),
101
- pending: [],
102
- whenStack: [],
103
- signal: o.signal
104
- };
105
- if (E(a, () => n({ model: e })), a.pending.length && await Promise.race([Promise.all(a.pending), V(o.signal)]), o.signal.aborted) return !1;
106
- const i = new Set(a.errors.keys());
107
- for (const s of r.fields) i.has(s) || v(s)?.setErrors([]);
108
- for (const s of i) v(s)?.setErrors(a.errors.get(s) ?? []);
109
- if (t?.touch) for (const s of i) v(s)?.markAsTouched();
110
- return r.fields = i, !T(a.errors);
111
- }
112
- function G(e, n, t = {}) {
113
- const { strategy: r = "submit", debounce: o = 0, liveAfterSubmit: a = "change" } = t, i = A(!1);
114
- let s = 0, y = !1, f, c;
115
- const w = async (l) => {
116
- s++, i.value = !0;
117
- try {
118
- return await C(e, n, { touch: l });
119
- } finally {
120
- --s === 0 && (i.value = !1);
121
- }
122
- }, p = () => {
123
- w(!1);
124
- }, F = () => {
125
- if (!o) {
126
- p();
127
- return;
128
- }
129
- c && clearTimeout(c), c = setTimeout(p, o);
130
- }, k = (l, d) => {
131
- let S = !0;
132
- return M(() => {
133
- if (W(e, l), S) {
134
- S = !1;
135
- return;
136
- }
137
- r === "afterFirstSubmit" && !y || d();
138
- });
139
- }, h = {
140
- async validate() {
141
- return y = !0, w(!0);
142
- },
143
- start() {
144
- if (f) return () => h.dispose();
145
- const l = r === "afterFirstSubmit" ? a : r;
146
- return l === "change" ? f = k((d) => void d.value, F) : l === "blur" && (f = k((d) => void v(d)?.touched.value, p)), () => h.dispose();
147
- },
148
- dispose() {
149
- c && (clearTimeout(c), c = void 0), f?.(), f = void 0;
150
- },
151
- get isValidating() {
152
- return i.value;
153
- },
154
- get validating() {
155
- return i;
156
- }
157
- };
158
- return h;
159
- }
160
- export {
161
- N as a,
162
- R as b,
163
- _ as c,
164
- j as d,
165
- $ as e,
166
- z as f,
167
- C as g,
168
- G as h,
169
- D as v
170
- };