@reformer/core 11.0.0-beta.1 → 11.0.0-beta.3

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,323 @@
1
+ import { batch as k, signal as _, computed as O } from "@preact/signals-core";
2
+ const h = /* @__PURE__ */ new WeakMap();
3
+ function F(e) {
4
+ h.set(e, (h.get(e) ?? 0) + 1);
5
+ }
6
+ function K(e) {
7
+ const t = h.get(e);
8
+ t !== void 0 && (t <= 1 ? h.delete(e) : h.set(e, t - 1));
9
+ }
10
+ function P(e) {
11
+ return h.has(e);
12
+ }
13
+ const p = (e) => !(e === null || typeof e != "object" || Array.isArray(e) || e instanceof Date || typeof Blob < "u" && e instanceof Blob || typeof File < "u" && e instanceof File), c = (e, t) => e === "" ? String(t) : `${e}.${t}`, m = (e) => /^\d+$/.test(e), l = (e) => {
14
+ if (Array.isArray(e)) return e.map(l);
15
+ if (p(e)) {
16
+ const t = {};
17
+ for (const i of Object.keys(e)) t[i] = l(e[i]);
18
+ return t;
19
+ }
20
+ return e;
21
+ }, g = (e, t) => {
22
+ if (e === t) return !0;
23
+ if (Array.isArray(e) && Array.isArray(t))
24
+ return e.length !== t.length ? !1 : e.every((i, r) => g(i, t[r]));
25
+ if (p(e) && p(t)) {
26
+ const i = Object.keys(e), r = Object.keys(t);
27
+ return i.length !== r.length ? !1 : i.every((n) => g(e[n], t[n]));
28
+ }
29
+ return !1;
30
+ };
31
+ class j {
32
+ constructor(t, i) {
33
+ this.path = i;
34
+ const r = _(t);
35
+ r.__path = i, this.signal = r, this.initial = l(t);
36
+ }
37
+ kind = "leaf";
38
+ signal;
39
+ initial;
40
+ rebase(t) {
41
+ this.path = t, this.signal.__path = t;
42
+ }
43
+ /** Реактивное чтение (внутри effect/computed создаёт зависимость). */
44
+ read() {
45
+ return this.signal.value;
46
+ }
47
+ /** Нереактивный снимок. */
48
+ peek() {
49
+ return this.signal.peek();
50
+ }
51
+ set(t) {
52
+ this.signal.value = t;
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 !g(this.signal.peek(), this.initial);
62
+ }
63
+ }
64
+ class x {
65
+ constructor(t, i) {
66
+ this.path = i;
67
+ for (const r of Object.keys(t))
68
+ this.children.set(r, d(t[r], c(i, r)));
69
+ }
70
+ kind = "group";
71
+ children = /* @__PURE__ */ new Map();
72
+ rebase(t) {
73
+ this.path = t;
74
+ for (const [i, r] of this.children) r.rebase(c(t, i));
75
+ }
76
+ /** Реактивное чтение поддерева (внутри effect/computed подписывает на все листья группы). */
77
+ read() {
78
+ const t = {};
79
+ for (const [i, r] of this.children) t[i] = r.read();
80
+ return t;
81
+ }
82
+ peek() {
83
+ const t = {};
84
+ for (const [i, r] of this.children) t[i] = r.peek();
85
+ return t;
86
+ }
87
+ set(t) {
88
+ if (t == null || typeof t != "object") return;
89
+ const i = t;
90
+ k(() => {
91
+ for (const [r, n] of this.children)
92
+ r in i && (n.kind === "leaf" && P(n.signal) || n.set(i[r]));
93
+ });
94
+ }
95
+ resetToInitial() {
96
+ k(() => {
97
+ for (const t of this.children.values()) t.resetToInitial();
98
+ });
99
+ }
100
+ captureInitial() {
101
+ for (const t of this.children.values()) t.captureInitial();
102
+ }
103
+ dirty() {
104
+ for (const t of this.children.values()) if (t.dirty()) return !0;
105
+ return !1;
106
+ }
107
+ }
108
+ class N {
109
+ constructor(t, i) {
110
+ this.path = i, this.items = _(t.map((r, n) => d(r, c(i, n)))), this.initial = l(t);
111
+ }
112
+ kind = "array";
113
+ items;
114
+ initial;
115
+ rebase(t) {
116
+ this.path = t, this.items.peek().forEach((i, r) => i.rebase(c(t, r)));
117
+ }
118
+ reindex() {
119
+ this.items.peek().forEach((t, i) => t.rebase(c(this.path, i)));
120
+ }
121
+ push(t) {
122
+ const i = this.items.peek();
123
+ this.items.value = [...i, d(t, c(this.path, i.length))];
124
+ }
125
+ insertAt(t, i) {
126
+ const r = [...this.items.peek()];
127
+ r.splice(t, 0, d(i, c(this.path, t))), this.items.value = r, this.reindex();
128
+ }
129
+ removeAt(t) {
130
+ const i = [...this.items.peek()];
131
+ i.splice(t, 1), this.items.value = i, this.reindex();
132
+ }
133
+ move(t, i) {
134
+ const r = [...this.items.peek()], [n] = r.splice(t, 1);
135
+ n && r.splice(i, 0, n), this.items.value = r, this.reindex();
136
+ }
137
+ swap(t, i) {
138
+ const r = [...this.items.peek()];
139
+ t < 0 || i < 0 || t >= r.length || i >= r.length || t === i || ([r[t], r[i]] = [r[i], r[t]], this.items.value = r, 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((t) => t.read());
150
+ }
151
+ peek() {
152
+ return this.items.peek().map((t) => t.peek());
153
+ }
154
+ set(t) {
155
+ const i = Array.isArray(t) ? t : [];
156
+ this.items.value = i.map((r, n) => d(r, c(this.path, n)));
157
+ }
158
+ resetToInitial() {
159
+ this.set(l(this.initial));
160
+ }
161
+ captureInitial() {
162
+ this.initial = l(this.peek());
163
+ }
164
+ dirty() {
165
+ return !g(this.peek(), this.initial);
166
+ }
167
+ }
168
+ function d(e, t) {
169
+ return Array.isArray(e) ? new N(e, t) : p(e) ? new x(e, t) : new j(e, t);
170
+ }
171
+ function f(e) {
172
+ if (e)
173
+ return e.kind === "group" ? S(e) : e.kind === "array" ? E(e) : e.read();
174
+ }
175
+ function E(e) {
176
+ const t = {
177
+ get length() {
178
+ return e.items.value.length;
179
+ },
180
+ push: (i) => e.push(i),
181
+ insertAt: (i, r) => e.insertAt(i, r),
182
+ removeAt: (i) => e.removeAt(i),
183
+ move: (i, r) => e.move(i, r),
184
+ swap: (i, r) => e.swap(i, r),
185
+ clear: () => e.clear(),
186
+ at: (i) => f(e.items.value[i]),
187
+ map: (i) => e.items.value.map((r, n) => i(f(r), n)),
188
+ forEach: (i) => e.items.value.forEach((r, n) => i(f(r), n)),
189
+ toArray: () => e.peek(),
190
+ [Symbol.iterator]: function* () {
191
+ const i = e.items.value;
192
+ for (let r = 0; r < i.length; r++) yield f(i[r]);
193
+ }
194
+ };
195
+ return new Proxy(t, {
196
+ get: (i, r, n) => r === "__path" ? e.path : typeof r == "string" && m(r) ? f(e.items.value[Number(r)]) : Reflect.get(i, r, n),
197
+ has: (i, r) => typeof r == "string" && m(r) ? Number(r) < e.items.value.length : Reflect.has(i, r)
198
+ });
199
+ }
200
+ const A = /* @__PURE__ */ new WeakMap();
201
+ function M(e) {
202
+ const t = O(() => e.read());
203
+ return {
204
+ get value() {
205
+ return t.value;
206
+ },
207
+ peek: () => t.peek(),
208
+ subscribe: (i) => t.subscribe(i),
209
+ valueOf: () => t.value,
210
+ toString: () => String(t.value),
211
+ toJSON: () => t.value,
212
+ brand: t.brand
213
+ };
214
+ }
215
+ function I(e) {
216
+ if (e.kind === "leaf") return e.signal;
217
+ const t = A.get(e);
218
+ if (t) return t;
219
+ const i = M(e), r = e.kind === "group", n = (o) => r ? e.children.get(o) : m(o) ? e.items.value[Number(o)] : void 0, s = r ? {} : {
220
+ get length() {
221
+ return e.items.value.length;
222
+ }
223
+ }, u = new Proxy(s, {
224
+ get: (o, a, D) => {
225
+ if (a === "__path") return e.path;
226
+ if (a === "__kind") return e.kind;
227
+ if (typeof a != "string") return Reflect.get(i, a, i);
228
+ const v = n(a);
229
+ return v ? I(v) : !r && Reflect.has(o, a) ? Reflect.get(o, a, D) : Reflect.get(i, a, i);
230
+ },
231
+ has: (o, a) => typeof a == "string" && (n(a) !== void 0 || !r && Reflect.has(o, a)),
232
+ ownKeys: () => r ? [...e.children.keys()] : Reflect.ownKeys(s),
233
+ getOwnPropertyDescriptor: (o, a) => typeof a == "string" && n(a) ? { enumerable: !0, configurable: !0 } : r ? void 0 : Reflect.getOwnPropertyDescriptor(o, a)
234
+ });
235
+ return A.set(e, u), u;
236
+ }
237
+ function W(e) {
238
+ if (e == null || typeof e != "object") return !1;
239
+ const t = e.__kind;
240
+ return t === "group" || t === "array";
241
+ }
242
+ function T(e, t) {
243
+ if (!t) return;
244
+ let i = e;
245
+ for (const r of t.split(".")) {
246
+ if (!i) return;
247
+ if (i.kind === "group") i = i.children.get(r);
248
+ else if (i.kind === "array") i = i.items.peek()[Number(r)];
249
+ else return;
250
+ }
251
+ return i && i.kind === "leaf" ? i.signal : void 0;
252
+ }
253
+ const b = /* @__PURE__ */ new Set([
254
+ "$",
255
+ "get",
256
+ "set",
257
+ "patch",
258
+ "isDirty",
259
+ "reset",
260
+ "captureInitial",
261
+ "signalAt"
262
+ ]), w = /* @__PURE__ */ new WeakMap(), R = /* @__PURE__ */ new WeakMap();
263
+ function S(e) {
264
+ const t = w.get(e);
265
+ if (t) return t;
266
+ const i = {
267
+ $: I(e),
268
+ get: () => e.peek(),
269
+ set: (n) => e.set(n),
270
+ patch: (n) => e.set(n),
271
+ isDirty: () => e.dirty(),
272
+ reset: () => e.resetToInitial(),
273
+ captureInitial: () => e.captureInitial(),
274
+ signalAt: (n) => T(e, n)
275
+ }, r = new Proxy(
276
+ {},
277
+ {
278
+ get: (n, s) => {
279
+ if (s === "__path") return e.path;
280
+ if (typeof s != "string") return;
281
+ const u = e.children.get(s);
282
+ if (u) return f(u);
283
+ if (b.has(s)) return i[s];
284
+ },
285
+ set: (n, s, u) => {
286
+ if (typeof s != "string") return !1;
287
+ const o = e.children.get(s);
288
+ return o ? (o.set(u), !0) : !1;
289
+ },
290
+ has: (n, s) => typeof s == "string" && (e.children.has(s) || b.has(s)),
291
+ ownKeys: () => [...e.children.keys()],
292
+ getOwnPropertyDescriptor: (n, s) => typeof s == "string" && e.children.has(s) ? { enumerable: !0, configurable: !0 } : void 0
293
+ }
294
+ );
295
+ return w.set(e, r), R.set(r, e), r;
296
+ }
297
+ function y(e, t) {
298
+ if (e.kind === "leaf") {
299
+ t(e.signal);
300
+ return;
301
+ }
302
+ if (e.kind === "group") {
303
+ for (const i of e.children.values()) y(i, t);
304
+ return;
305
+ }
306
+ for (const i of e.items.value) y(i, t);
307
+ }
308
+ function B(e, t) {
309
+ const i = R.get(e);
310
+ i && y(i, t);
311
+ }
312
+ function C(e) {
313
+ const t = new x(e, "");
314
+ return S(t);
315
+ }
316
+ export {
317
+ P as a,
318
+ C as c,
319
+ B as e,
320
+ W as i,
321
+ F as m,
322
+ K as u
323
+ };