cogsbox-state 0.5.488 → 0.5.489
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/README.md +4 -4
- package/dist/CogsState.d.ts +1 -1
- package/dist/CogsState.d.ts.map +1 -1
- package/dist/CogsState.js +401 -399
- package/dist/CogsState.js.map +1 -1
- package/dist/plugins.d.ts +2 -2
- package/dist/plugins.d.ts.map +1 -1
- package/dist/plugins.js.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +86 -83
- package/src/plugins.ts +15 -8
package/dist/CogsState.js
CHANGED
|
@@ -14,7 +14,7 @@ const {
|
|
|
14
14
|
updateInitialStateGlobal: Ve,
|
|
15
15
|
getShadowMetadata: E,
|
|
16
16
|
setShadowMetadata: B,
|
|
17
|
-
getShadowValue:
|
|
17
|
+
getShadowValue: _,
|
|
18
18
|
initializeShadowState: K,
|
|
19
19
|
initializeAndMergeShadowState: Re,
|
|
20
20
|
updateShadowAtPath: Le,
|
|
@@ -44,9 +44,9 @@ function z(e, a, l) {
|
|
|
44
44
|
function le(e, a, l) {
|
|
45
45
|
for (let s = 0; s < e.length; s++)
|
|
46
46
|
if (l(e[s], s)) {
|
|
47
|
-
const
|
|
48
|
-
if (
|
|
49
|
-
return { key:
|
|
47
|
+
const S = a[s];
|
|
48
|
+
if (S)
|
|
49
|
+
return { key: S, index: s, value: e[s] };
|
|
50
50
|
}
|
|
51
51
|
return null;
|
|
52
52
|
}
|
|
@@ -62,20 +62,20 @@ function fe({
|
|
|
62
62
|
options: a,
|
|
63
63
|
initialOptionsPart: l
|
|
64
64
|
}) {
|
|
65
|
-
const s = U(e) || {},
|
|
66
|
-
let u = { ...
|
|
65
|
+
const s = U(e) || {}, S = l[e] || {};
|
|
66
|
+
let u = { ...S, ...s }, h = !1;
|
|
67
67
|
if (a) {
|
|
68
|
-
const
|
|
68
|
+
const y = (t, o) => {
|
|
69
69
|
for (const d in o)
|
|
70
|
-
o.hasOwnProperty(d) && (o[d] instanceof Object && !Array.isArray(o[d]) && t[d] instanceof Object ? X(t[d], o[d]) || (
|
|
70
|
+
o.hasOwnProperty(d) && (o[d] instanceof Object && !Array.isArray(o[d]) && t[d] instanceof Object ? X(t[d], o[d]) || (y(t[d], o[d]), h = !0) : t[d] !== o[d] && (t[d] = o[d], h = !0));
|
|
71
71
|
return t;
|
|
72
72
|
};
|
|
73
|
-
u =
|
|
73
|
+
u = y(u, a);
|
|
74
74
|
}
|
|
75
|
-
if (u.validation && (a?.validation?.hasOwnProperty("onBlur") || s?.validation?.hasOwnProperty("onBlur") ||
|
|
75
|
+
if (u.validation && (a?.validation?.hasOwnProperty("onBlur") || s?.validation?.hasOwnProperty("onBlur") || S?.validation?.hasOwnProperty("onBlur") || (u.validation.onBlur = "error", h = !0)), h) {
|
|
76
76
|
ye(e, u);
|
|
77
|
-
const
|
|
78
|
-
(
|
|
77
|
+
const y = u.validation?.zodSchemaV4, t = u.validation?.zodSchemaV3;
|
|
78
|
+
(y !== s?.validation?.zodSchemaV4 || t !== s?.validation?.zodSchemaV3) && (y || t) && (y ? H(e, y, "zod4") : t && H(e, t, "zod3"), N(e));
|
|
79
79
|
}
|
|
80
80
|
return u;
|
|
81
81
|
}
|
|
@@ -85,8 +85,8 @@ const bt = (e, a) => {
|
|
|
85
85
|
if (a?.plugins)
|
|
86
86
|
for (const o of a.plugins)
|
|
87
87
|
typeof o.initialState == "function" && Object.assign(l, o.initialState());
|
|
88
|
-
const s = { ...l, ...e }, [
|
|
89
|
-
Object.keys(
|
|
88
|
+
const s = { ...l, ...e }, [S, u] = ke(s);
|
|
89
|
+
Object.keys(S).forEach((o) => {
|
|
90
90
|
let d = {};
|
|
91
91
|
a?.formElements && (d.formElements = a.formElements), d.validation = {
|
|
92
92
|
onBlur: "error",
|
|
@@ -101,8 +101,8 @@ const bt = (e, a) => {
|
|
|
101
101
|
}
|
|
102
102
|
} : d;
|
|
103
103
|
Object.keys(b).length > 0 && ye(o, b);
|
|
104
|
-
}), Object.keys(
|
|
105
|
-
K(o,
|
|
104
|
+
}), Object.keys(S).forEach((o) => {
|
|
105
|
+
K(o, S[o]);
|
|
106
106
|
});
|
|
107
107
|
const h = (o, d) => {
|
|
108
108
|
const [$] = ne(d?.componentId ?? ae()), b = fe({
|
|
@@ -111,7 +111,7 @@ const bt = (e, a) => {
|
|
|
111
111
|
initialOptionsPart: u
|
|
112
112
|
}), P = x(b);
|
|
113
113
|
P.current = b;
|
|
114
|
-
const v =
|
|
114
|
+
const v = _(o, []) || S[o], O = ct(v, {
|
|
115
115
|
stateKey: o,
|
|
116
116
|
syncUpdate: d?.syncUpdate,
|
|
117
117
|
componentId: $,
|
|
@@ -125,14 +125,14 @@ const bt = (e, a) => {
|
|
|
125
125
|
});
|
|
126
126
|
return re(() => {
|
|
127
127
|
d && L.getState().setPluginOptionsForState(o, d);
|
|
128
|
-
}, [o, d]), re(() => (L.getState().registerStateHandler(o,
|
|
128
|
+
}, [o, d]), re(() => (L.getState().registerStateHandler(o, O), () => {
|
|
129
129
|
L.getState().unregisterStateHandler(o);
|
|
130
|
-
}), [o,
|
|
130
|
+
}), [o, O]), re(() => {
|
|
131
131
|
const D = U(o)?.validation;
|
|
132
132
|
D?.zodSchemaV4 ? H(o, D.zodSchemaV4, "zod4") : D?.zodSchemaV3 && H(o, D.zodSchemaV3, "zod3");
|
|
133
|
-
}),
|
|
133
|
+
}), O;
|
|
134
134
|
};
|
|
135
|
-
function
|
|
135
|
+
function y(o, d) {
|
|
136
136
|
if (fe({ stateKey: o, options: d, initialOptionsPart: u }), d.localStorage && Xe(o, d), d.formElements) {
|
|
137
137
|
const b = L.getState().registeredPlugins.map((P) => d.formElements.hasOwnProperty(P.name) ? {
|
|
138
138
|
...P,
|
|
@@ -143,16 +143,16 @@ const bt = (e, a) => {
|
|
|
143
143
|
N(o);
|
|
144
144
|
}
|
|
145
145
|
function t(o) {
|
|
146
|
-
Object.keys(
|
|
147
|
-
|
|
146
|
+
Object.keys(S).forEach(($) => {
|
|
147
|
+
y($, o);
|
|
148
148
|
});
|
|
149
149
|
}
|
|
150
150
|
return {
|
|
151
151
|
useCogsState: h,
|
|
152
|
-
setCogsOptionsByKey:
|
|
152
|
+
setCogsOptionsByKey: y,
|
|
153
153
|
setCogsOptions: t
|
|
154
154
|
};
|
|
155
|
-
}, Ze = (e, a, l, s,
|
|
155
|
+
}, Ze = (e, a, l, s, S) => {
|
|
156
156
|
l?.log && console.log(
|
|
157
157
|
"saving to localstorage",
|
|
158
158
|
a,
|
|
@@ -162,15 +162,15 @@ const bt = (e, a) => {
|
|
|
162
162
|
const u = W(l?.localStorage?.key) ? l.localStorage?.key(e) : l?.localStorage?.key;
|
|
163
163
|
if (u && s) {
|
|
164
164
|
const h = `${s}-${a}-${u}`;
|
|
165
|
-
let
|
|
165
|
+
let y;
|
|
166
166
|
try {
|
|
167
|
-
|
|
167
|
+
y = ce(h)?.lastSyncedWithServer;
|
|
168
168
|
} catch {
|
|
169
169
|
}
|
|
170
170
|
const t = E(a, []), o = {
|
|
171
171
|
state: e,
|
|
172
172
|
lastUpdated: Date.now(),
|
|
173
|
-
lastSyncedWithServer:
|
|
173
|
+
lastSyncedWithServer: y,
|
|
174
174
|
stateSource: t?.stateSource,
|
|
175
175
|
baseServerState: t?.baseServerState
|
|
176
176
|
}, d = Fe.serialize(o);
|
|
@@ -195,10 +195,10 @@ const bt = (e, a) => {
|
|
|
195
195
|
console.error("Error removing from localStorage:", a);
|
|
196
196
|
}
|
|
197
197
|
}, Xe = (e, a) => {
|
|
198
|
-
const l =
|
|
199
|
-
if (
|
|
198
|
+
const l = _(e, []), { sessionId: s } = Me(), S = W(a?.localStorage?.key) ? a.localStorage.key(l) : a?.localStorage?.key;
|
|
199
|
+
if (S && s) {
|
|
200
200
|
const u = ce(
|
|
201
|
-
`${s}-${e}-${
|
|
201
|
+
`${s}-${e}-${S}`
|
|
202
202
|
);
|
|
203
203
|
if (u && u.lastUpdated > (u.lastSyncedWithServer || 0))
|
|
204
204
|
return N(e), !0;
|
|
@@ -215,16 +215,16 @@ const bt = (e, a) => {
|
|
|
215
215
|
});
|
|
216
216
|
};
|
|
217
217
|
function oe(e, a, l, s) {
|
|
218
|
-
const
|
|
218
|
+
const S = E(e, a);
|
|
219
219
|
if (B(e, a, {
|
|
220
|
-
...
|
|
220
|
+
...S,
|
|
221
221
|
isDirty: !1,
|
|
222
222
|
stateSource: "server",
|
|
223
223
|
lastServerSync: s || Date.now()
|
|
224
224
|
}), Array.isArray(l)) {
|
|
225
225
|
const u = E(e, a);
|
|
226
|
-
u?.arrayKeys && u.arrayKeys.forEach((h,
|
|
227
|
-
const t = [...a, h], o = l[
|
|
226
|
+
u?.arrayKeys && u.arrayKeys.forEach((h, y) => {
|
|
227
|
+
const t = [...a, h], o = l[y];
|
|
228
228
|
o !== void 0 && oe(
|
|
229
229
|
e,
|
|
230
230
|
t,
|
|
@@ -233,8 +233,8 @@ function oe(e, a, l, s) {
|
|
|
233
233
|
);
|
|
234
234
|
});
|
|
235
235
|
} else l && typeof l == "object" && l.constructor === Object && Object.keys(l).forEach((u) => {
|
|
236
|
-
const h = [...a, u],
|
|
237
|
-
oe(e, h,
|
|
236
|
+
const h = [...a, u], y = l[u];
|
|
237
|
+
oe(e, h, y, s);
|
|
238
238
|
});
|
|
239
239
|
}
|
|
240
240
|
let se = [], ge = !1;
|
|
@@ -244,68 +244,68 @@ function Ke() {
|
|
|
244
244
|
}));
|
|
245
245
|
}
|
|
246
246
|
function et(e, a) {
|
|
247
|
-
e?.signals?.length && e.signals.forEach(({ parentId: l, position: s, effect:
|
|
247
|
+
e?.signals?.length && e.signals.forEach(({ parentId: l, position: s, effect: S }) => {
|
|
248
248
|
const u = document.querySelector(`[data-parent-id="${l}"]`);
|
|
249
249
|
if (!u) return;
|
|
250
250
|
const h = Array.from(u.childNodes);
|
|
251
251
|
if (!h[s]) return;
|
|
252
|
-
let
|
|
253
|
-
if (
|
|
252
|
+
let y = a;
|
|
253
|
+
if (S && a !== null)
|
|
254
254
|
try {
|
|
255
|
-
|
|
255
|
+
y = new Function("state", `return (${S})(state)`)(
|
|
256
256
|
a
|
|
257
257
|
);
|
|
258
258
|
} catch (t) {
|
|
259
259
|
console.error("Error evaluating effect function:", t);
|
|
260
260
|
}
|
|
261
|
-
|
|
261
|
+
y !== null && typeof y == "object" && (y = JSON.stringify(y)), h[s].textContent = String(y ?? "");
|
|
262
262
|
});
|
|
263
263
|
}
|
|
264
264
|
function tt(e, a, l) {
|
|
265
265
|
const s = E(e, []);
|
|
266
266
|
if (!s?.components)
|
|
267
267
|
return /* @__PURE__ */ new Set();
|
|
268
|
-
const
|
|
268
|
+
const S = /* @__PURE__ */ new Set();
|
|
269
269
|
if (l.type === "update") {
|
|
270
270
|
let u = [...a];
|
|
271
271
|
for (; ; ) {
|
|
272
272
|
const h = E(e, u);
|
|
273
|
-
if (h?.pathComponents && h.pathComponents.forEach((
|
|
274
|
-
const t = s.components?.get(
|
|
275
|
-
t && ((Array.isArray(t.reactiveType) ? t.reactiveType : [t.reactiveType || "component"]).includes("none") ||
|
|
273
|
+
if (h?.pathComponents && h.pathComponents.forEach((y) => {
|
|
274
|
+
const t = s.components?.get(y);
|
|
275
|
+
t && ((Array.isArray(t.reactiveType) ? t.reactiveType : [t.reactiveType || "component"]).includes("none") || S.add(t));
|
|
276
276
|
}), u.length === 0) break;
|
|
277
277
|
u.pop();
|
|
278
278
|
}
|
|
279
|
-
l.newValue && typeof l.newValue == "object" && !Ce(l.newValue) && _e(l.newValue, l.oldValue).forEach((
|
|
280
|
-
const t =
|
|
279
|
+
l.newValue && typeof l.newValue == "object" && !Ce(l.newValue) && _e(l.newValue, l.oldValue).forEach((y) => {
|
|
280
|
+
const t = y.split("."), o = [...a, ...t], d = E(e, o);
|
|
281
281
|
d?.pathComponents && d.pathComponents.forEach(($) => {
|
|
282
282
|
const b = s.components?.get($);
|
|
283
|
-
b && ((Array.isArray(b.reactiveType) ? b.reactiveType : [b.reactiveType || "component"]).includes("none") ||
|
|
283
|
+
b && ((Array.isArray(b.reactiveType) ? b.reactiveType : [b.reactiveType || "component"]).includes("none") || S.add(b));
|
|
284
284
|
});
|
|
285
285
|
});
|
|
286
286
|
} else if (l.type === "insert" || l.type === "cut" || l.type === "insert_many") {
|
|
287
287
|
let h = [...l.type === "insert" ? a : a.slice(0, -1)];
|
|
288
288
|
for (; ; ) {
|
|
289
|
-
const
|
|
290
|
-
if (
|
|
289
|
+
const y = E(e, h);
|
|
290
|
+
if (y?.pathComponents && y.pathComponents.forEach((t) => {
|
|
291
291
|
const o = s.components?.get(t);
|
|
292
|
-
o &&
|
|
292
|
+
o && S.add(o);
|
|
293
293
|
}), h.length === 0) break;
|
|
294
294
|
h.pop();
|
|
295
295
|
}
|
|
296
296
|
}
|
|
297
|
-
return
|
|
297
|
+
return S;
|
|
298
298
|
}
|
|
299
299
|
function rt(e, a, l) {
|
|
300
|
-
const s = M.getState().getShadowValue(e, a),
|
|
301
|
-
if (X(s,
|
|
300
|
+
const s = M.getState().getShadowValue(e, a), S = W(l) ? l(s) : l;
|
|
301
|
+
if (X(s, S))
|
|
302
302
|
return null;
|
|
303
|
-
Le(e, a,
|
|
303
|
+
Le(e, a, S), ie(e, a, { bubble: !0 });
|
|
304
304
|
const u = E(e, a);
|
|
305
305
|
return {
|
|
306
306
|
type: "update",
|
|
307
307
|
oldValue: s,
|
|
308
|
-
newValue:
|
|
308
|
+
newValue: S,
|
|
309
309
|
shadowMeta: u
|
|
310
310
|
};
|
|
311
311
|
}
|
|
@@ -319,10 +319,10 @@ function nt(e, a, l) {
|
|
|
319
319
|
path: a
|
|
320
320
|
};
|
|
321
321
|
}
|
|
322
|
-
function at(e, a, l, s,
|
|
322
|
+
function at(e, a, l, s, S) {
|
|
323
323
|
let u;
|
|
324
324
|
if (W(l)) {
|
|
325
|
-
const { value: o } =
|
|
325
|
+
const { value: o } = j(e, a);
|
|
326
326
|
u = l({ state: o });
|
|
327
327
|
} else
|
|
328
328
|
u = l;
|
|
@@ -331,22 +331,22 @@ function at(e, a, l, s, f) {
|
|
|
331
331
|
a,
|
|
332
332
|
u,
|
|
333
333
|
s,
|
|
334
|
-
|
|
334
|
+
S
|
|
335
335
|
);
|
|
336
336
|
ie(e, a, { bubble: !0 });
|
|
337
|
-
const
|
|
337
|
+
const y = E(e, a);
|
|
338
338
|
let t;
|
|
339
|
-
return
|
|
339
|
+
return y?.arrayKeys && s !== void 0 && s > 0 && (t = y.arrayKeys[s - 1]), {
|
|
340
340
|
type: "insert",
|
|
341
341
|
newValue: u,
|
|
342
|
-
shadowMeta:
|
|
342
|
+
shadowMeta: y,
|
|
343
343
|
path: a,
|
|
344
344
|
itemId: h,
|
|
345
345
|
insertAfterId: t
|
|
346
346
|
};
|
|
347
347
|
}
|
|
348
348
|
function ot(e, a) {
|
|
349
|
-
const l = a.slice(0, -1), s =
|
|
349
|
+
const l = a.slice(0, -1), s = _(e, a);
|
|
350
350
|
return Be(e, a), ie(e, l, { bubble: !0 }), { type: "cut", oldValue: s, parentPath: l };
|
|
351
351
|
}
|
|
352
352
|
function st() {
|
|
@@ -356,90 +356,90 @@ function st() {
|
|
|
356
356
|
l.push(s);
|
|
357
357
|
continue;
|
|
358
358
|
}
|
|
359
|
-
const
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
).forEach((
|
|
365
|
-
e.add(
|
|
359
|
+
const S = s, u = S.type === "cut" ? null : S.newValue;
|
|
360
|
+
S.shadowMeta?.signals?.length > 0 && a.push({ shadowMeta: S.shadowMeta, displayValue: u }), tt(
|
|
361
|
+
S.stateKey,
|
|
362
|
+
S.path,
|
|
363
|
+
S
|
|
364
|
+
).forEach((y) => {
|
|
365
|
+
e.add(y);
|
|
366
366
|
});
|
|
367
367
|
}
|
|
368
|
-
l.length > 0 && xe(l), a.forEach(({ shadowMeta: s, displayValue:
|
|
369
|
-
et(s,
|
|
368
|
+
l.length > 0 && xe(l), a.forEach(({ shadowMeta: s, displayValue: S }) => {
|
|
369
|
+
et(s, S);
|
|
370
370
|
}), e.forEach((s) => {
|
|
371
371
|
s.forceUpdate();
|
|
372
372
|
}), se = [], ge = !1;
|
|
373
373
|
}
|
|
374
374
|
function it(e, a, l) {
|
|
375
|
-
return (
|
|
376
|
-
s(e, u,
|
|
375
|
+
return (S, u, h) => {
|
|
376
|
+
s(e, u, S, h);
|
|
377
377
|
};
|
|
378
|
-
function s(
|
|
378
|
+
function s(S, u, h, y) {
|
|
379
379
|
let t;
|
|
380
|
-
switch (
|
|
380
|
+
switch (y.updateType) {
|
|
381
381
|
case "update":
|
|
382
|
-
t = rt(
|
|
382
|
+
t = rt(S, u, h);
|
|
383
383
|
break;
|
|
384
384
|
case "insert":
|
|
385
385
|
t = at(
|
|
386
|
-
|
|
386
|
+
S,
|
|
387
387
|
u,
|
|
388
388
|
h,
|
|
389
|
-
|
|
390
|
-
|
|
389
|
+
y.index,
|
|
390
|
+
y.itemId
|
|
391
391
|
);
|
|
392
392
|
break;
|
|
393
393
|
case "insert_many":
|
|
394
|
-
t = nt(
|
|
394
|
+
t = nt(S, u, h);
|
|
395
395
|
break;
|
|
396
396
|
case "cut":
|
|
397
|
-
t = ot(
|
|
397
|
+
t = ot(S, u);
|
|
398
398
|
break;
|
|
399
399
|
}
|
|
400
400
|
if (t === null)
|
|
401
401
|
return;
|
|
402
|
-
t.stateKey =
|
|
402
|
+
t.stateKey = S, t.path = u, se.push(t), Ke();
|
|
403
403
|
const o = {
|
|
404
404
|
timeStamp: Date.now(),
|
|
405
|
-
stateKey:
|
|
405
|
+
stateKey: S,
|
|
406
406
|
path: u,
|
|
407
|
-
updateType:
|
|
407
|
+
updateType: y.updateType,
|
|
408
408
|
status: "new",
|
|
409
409
|
oldValue: t.oldValue,
|
|
410
410
|
newValue: t.newValue ?? null,
|
|
411
411
|
itemId: t.itemId,
|
|
412
412
|
insertAfterId: t.insertAfterId,
|
|
413
|
-
metaData:
|
|
413
|
+
metaData: y.metaData
|
|
414
414
|
};
|
|
415
415
|
se.push(o), t.newValue !== void 0 && Ze(
|
|
416
416
|
t.newValue,
|
|
417
|
-
|
|
417
|
+
S,
|
|
418
418
|
l.current,
|
|
419
419
|
a
|
|
420
|
-
), l.current?.middleware && l.current.middleware({ update: o }), ze(o,
|
|
420
|
+
), l.current?.middleware && l.current.middleware({ update: o }), ze(o, y.validationTrigger || "programmatic"), Ye(o);
|
|
421
421
|
}
|
|
422
422
|
}
|
|
423
423
|
function ct(e, {
|
|
424
424
|
stateKey: a,
|
|
425
425
|
localStorage: l,
|
|
426
426
|
formElements: s,
|
|
427
|
-
reactiveDeps:
|
|
427
|
+
reactiveDeps: S,
|
|
428
428
|
reactiveType: u,
|
|
429
429
|
componentId: h,
|
|
430
|
-
defaultState:
|
|
430
|
+
defaultState: y,
|
|
431
431
|
dependencies: t,
|
|
432
432
|
serverState: o
|
|
433
433
|
} = {}) {
|
|
434
434
|
const [d, $] = ne({}), { sessionId: b } = Me();
|
|
435
435
|
let P = !a;
|
|
436
|
-
const [v] = ne(a ?? ae()),
|
|
436
|
+
const [v] = ne(a ?? ae()), O = x(h ?? ae()), D = x(
|
|
437
437
|
null
|
|
438
438
|
);
|
|
439
439
|
D.current = U(v) ?? null;
|
|
440
440
|
const J = Ie(
|
|
441
441
|
(k) => {
|
|
442
|
-
const r = k ? { ...U(v), ...k } : U(v), n = r?.defaultState ||
|
|
442
|
+
const r = k ? { ...U(v), ...k } : U(v), n = r?.defaultState || y || e;
|
|
443
443
|
if (r?.serverState?.status === "success" && r?.serverState?.data !== void 0)
|
|
444
444
|
return {
|
|
445
445
|
value: r.serverState.data,
|
|
@@ -447,14 +447,14 @@ function ct(e, {
|
|
|
447
447
|
timestamp: r.serverState.timestamp || Date.now()
|
|
448
448
|
};
|
|
449
449
|
if (r?.localStorage?.key && b) {
|
|
450
|
-
const
|
|
451
|
-
`${b}-${v}-${
|
|
450
|
+
const f = W(r.localStorage.key) ? r.localStorage.key(n) : r.localStorage.key, c = ce(
|
|
451
|
+
`${b}-${v}-${f}`
|
|
452
452
|
);
|
|
453
|
-
if (
|
|
453
|
+
if (c && c.lastUpdated > (r?.serverState?.timestamp || 0))
|
|
454
454
|
return {
|
|
455
|
-
value:
|
|
455
|
+
value: c.state,
|
|
456
456
|
source: "localStorage",
|
|
457
|
-
timestamp:
|
|
457
|
+
timestamp: c.lastUpdated
|
|
458
458
|
};
|
|
459
459
|
}
|
|
460
460
|
return {
|
|
@@ -463,7 +463,7 @@ function ct(e, {
|
|
|
463
463
|
timestamp: Date.now()
|
|
464
464
|
};
|
|
465
465
|
},
|
|
466
|
-
[v,
|
|
466
|
+
[v, y, e, b]
|
|
467
467
|
);
|
|
468
468
|
Z(() => {
|
|
469
469
|
o && o.status === "success" && o.data !== void 0 && me(v, o);
|
|
@@ -473,22 +473,22 @@ function ct(e, {
|
|
|
473
473
|
if (r?.status !== "success" || r.data === void 0)
|
|
474
474
|
return;
|
|
475
475
|
ue(v, { serverState: r });
|
|
476
|
-
const n = typeof r.merge == "object" ? r.merge : r.merge === !0 ? { strategy: "append", key: "id" } : null,
|
|
477
|
-
if (n && n.strategy === "append" && "key" in n && Array.isArray(
|
|
478
|
-
const
|
|
479
|
-
if (!
|
|
476
|
+
const n = typeof r.merge == "object" ? r.merge : r.merge === !0 ? { strategy: "append", key: "id" } : null, i = _(v, []), f = r.data;
|
|
477
|
+
if (n && n.strategy === "append" && "key" in n && Array.isArray(i) && Array.isArray(f)) {
|
|
478
|
+
const c = n.key;
|
|
479
|
+
if (!c) {
|
|
480
480
|
console.error(
|
|
481
481
|
"CogsState: Merge strategy 'append' requires a 'key' field."
|
|
482
482
|
);
|
|
483
483
|
return;
|
|
484
484
|
}
|
|
485
|
-
const
|
|
486
|
-
|
|
487
|
-
), w =
|
|
488
|
-
(A) => !
|
|
485
|
+
const m = new Set(
|
|
486
|
+
i.map((A) => A[c])
|
|
487
|
+
), w = f.filter(
|
|
488
|
+
(A) => !m.has(A[c])
|
|
489
489
|
);
|
|
490
490
|
w.length > 0 && be(v, [], w);
|
|
491
|
-
const p =
|
|
491
|
+
const p = _(v, []);
|
|
492
492
|
oe(
|
|
493
493
|
v,
|
|
494
494
|
[],
|
|
@@ -496,10 +496,10 @@ function ct(e, {
|
|
|
496
496
|
r.timestamp || Date.now()
|
|
497
497
|
);
|
|
498
498
|
} else
|
|
499
|
-
K(v,
|
|
499
|
+
K(v, f), oe(
|
|
500
500
|
v,
|
|
501
501
|
[],
|
|
502
|
-
|
|
502
|
+
f,
|
|
503
503
|
r.timestamp || Date.now()
|
|
504
504
|
);
|
|
505
505
|
N(v);
|
|
@@ -514,44 +514,44 @@ function ct(e, {
|
|
|
514
514
|
if (B(v, [], {
|
|
515
515
|
...k,
|
|
516
516
|
features: r
|
|
517
|
-
}), C?.defaultState !== void 0 ||
|
|
518
|
-
const
|
|
517
|
+
}), C?.defaultState !== void 0 || y !== void 0) {
|
|
518
|
+
const m = C?.defaultState || y;
|
|
519
519
|
C?.defaultState || ue(v, {
|
|
520
|
-
defaultState:
|
|
520
|
+
defaultState: m
|
|
521
521
|
});
|
|
522
522
|
}
|
|
523
|
-
const { value: n, source:
|
|
523
|
+
const { value: n, source: i, timestamp: f } = J();
|
|
524
524
|
K(v, n);
|
|
525
|
-
const
|
|
526
|
-
|
|
527
|
-
stateSource:
|
|
528
|
-
lastServerSync:
|
|
529
|
-
isDirty:
|
|
530
|
-
baseServerState:
|
|
531
|
-
}),
|
|
525
|
+
const c = U(v)?.validation;
|
|
526
|
+
c?.zodSchemaV4 ? H(v, c.zodSchemaV4, "zod4") : c?.zodSchemaV3 && H(v, c.zodSchemaV3, "zod3"), B(v, [], {
|
|
527
|
+
stateSource: i,
|
|
528
|
+
lastServerSync: i === "server" ? f : void 0,
|
|
529
|
+
isDirty: i === "server" ? !1 : void 0,
|
|
530
|
+
baseServerState: i === "server" ? n : void 0
|
|
531
|
+
}), i === "server" && o && me(v, o), N(v);
|
|
532
532
|
}, [v, ...t || []]), re(() => {
|
|
533
533
|
P && ue(v, {
|
|
534
534
|
formElements: s,
|
|
535
|
-
defaultState:
|
|
535
|
+
defaultState: y,
|
|
536
536
|
localStorage: l,
|
|
537
537
|
middleware: D.current?.middleware
|
|
538
538
|
});
|
|
539
|
-
const k = `${v}////${
|
|
539
|
+
const k = `${v}////${O.current}`, C = E(v, []), r = C?.components || /* @__PURE__ */ new Map();
|
|
540
540
|
return r.set(k, {
|
|
541
541
|
forceUpdate: () => $({}),
|
|
542
542
|
reactiveType: u ?? ["component"],
|
|
543
543
|
paths: /* @__PURE__ */ new Set(),
|
|
544
|
-
depsFunction:
|
|
545
|
-
deps:
|
|
546
|
-
prevDeps:
|
|
544
|
+
depsFunction: S || void 0,
|
|
545
|
+
deps: S ? S(_(v, [])) : [],
|
|
546
|
+
prevDeps: S ? S(_(v, [])) : []
|
|
547
547
|
}), B(v, [], {
|
|
548
548
|
...C,
|
|
549
549
|
components: r
|
|
550
550
|
}), $({}), () => {
|
|
551
|
-
const n = E(v, []),
|
|
552
|
-
|
|
553
|
-
const
|
|
554
|
-
w?.pathComponents && w.pathComponents.size === 0 && (delete w.pathComponents, M.getState().setShadowMetadata(v,
|
|
551
|
+
const n = E(v, []), i = n?.components?.get(k);
|
|
552
|
+
i?.paths && i.paths.forEach((f) => {
|
|
553
|
+
const m = f.split(".").slice(1), w = M.getState().getShadowMetadata(v, m);
|
|
554
|
+
w?.pathComponents && w.pathComponents.size === 0 && (delete w.pathComponents, M.getState().setShadowMetadata(v, m, w));
|
|
555
555
|
}), n?.components && B(v, [], n);
|
|
556
556
|
};
|
|
557
557
|
}, []);
|
|
@@ -563,24 +563,24 @@ function ct(e, {
|
|
|
563
563
|
return M.getState().initialStateGlobal[v] || Ve(v, e), pe(() => Te(
|
|
564
564
|
v,
|
|
565
565
|
q,
|
|
566
|
-
|
|
566
|
+
O.current,
|
|
567
567
|
b
|
|
568
568
|
), [v, b]);
|
|
569
569
|
}
|
|
570
570
|
const lt = (e, a, l) => {
|
|
571
571
|
let s = E(e, a)?.arrayKeys || [];
|
|
572
|
-
const
|
|
573
|
-
if (!
|
|
572
|
+
const S = l?.transforms;
|
|
573
|
+
if (!S || S.length === 0)
|
|
574
574
|
return s;
|
|
575
|
-
for (const u of
|
|
575
|
+
for (const u of S)
|
|
576
576
|
if (u.type === "filter") {
|
|
577
577
|
const h = [];
|
|
578
|
-
s.forEach((
|
|
579
|
-
const o =
|
|
580
|
-
u.fn(o, t) && h.push(
|
|
578
|
+
s.forEach((y, t) => {
|
|
579
|
+
const o = _(e, [...a, y]);
|
|
580
|
+
u.fn(o, t) && h.push(y);
|
|
581
581
|
}), s = h;
|
|
582
|
-
} else u.type === "sort" && s.sort((h,
|
|
583
|
-
const t =
|
|
582
|
+
} else u.type === "sort" && s.sort((h, y) => {
|
|
583
|
+
const t = _(e, [...a, h]), o = _(e, [...a, y]);
|
|
584
584
|
return u.fn(t, o);
|
|
585
585
|
});
|
|
586
586
|
return s;
|
|
@@ -588,9 +588,9 @@ const lt = (e, a, l) => {
|
|
|
588
588
|
const s = `${e}////${a}`, u = E(e, [])?.components?.get(s);
|
|
589
589
|
!u || u.reactiveType === "none" || !(Array.isArray(u.reactiveType) ? u.reactiveType : [u.reactiveType]).includes("component") || Ge(e, l, s);
|
|
590
590
|
}, Y = (e, a, l) => {
|
|
591
|
-
const s = E(e, []),
|
|
592
|
-
s?.components && s.components.forEach((h,
|
|
593
|
-
(Array.isArray(h.reactiveType) ? h.reactiveType : [h.reactiveType || "component"]).includes("all") && (h.forceUpdate(),
|
|
591
|
+
const s = E(e, []), S = /* @__PURE__ */ new Set();
|
|
592
|
+
s?.components && s.components.forEach((h, y) => {
|
|
593
|
+
(Array.isArray(h.reactiveType) ? h.reactiveType : [h.reactiveType || "component"]).includes("all") && (h.forceUpdate(), S.add(y));
|
|
594
594
|
}), E(e, [
|
|
595
595
|
...a,
|
|
596
596
|
"getSelected"
|
|
@@ -599,21 +599,21 @@ const lt = (e, a, l) => {
|
|
|
599
599
|
});
|
|
600
600
|
const u = E(e, a);
|
|
601
601
|
for (let h of u?.arrayKeys || []) {
|
|
602
|
-
const
|
|
602
|
+
const y = h + ".selected", t = E(e, y.split(".").slice(1));
|
|
603
603
|
h == l && t?.pathComponents?.forEach((o) => {
|
|
604
604
|
s?.components?.get(o)?.forceUpdate();
|
|
605
605
|
});
|
|
606
606
|
}
|
|
607
607
|
};
|
|
608
|
-
function
|
|
609
|
-
const s = E(e, a),
|
|
608
|
+
function j(e, a, l) {
|
|
609
|
+
const s = E(e, a), S = a.length > 0 ? a.join(".") : "root", u = l?.arrayViews?.[S];
|
|
610
610
|
if (Array.isArray(u) && u.length === 0)
|
|
611
611
|
return {
|
|
612
612
|
shadowMeta: s,
|
|
613
613
|
value: [],
|
|
614
614
|
arrayKeys: s?.arrayKeys
|
|
615
615
|
};
|
|
616
|
-
const h =
|
|
616
|
+
const h = _(e, a, u);
|
|
617
617
|
return {
|
|
618
618
|
shadowMeta: s,
|
|
619
619
|
value: h,
|
|
@@ -630,8 +630,8 @@ function Ee(e, a) {
|
|
|
630
630
|
const l = M.getState().getShadowMetadata(e, a);
|
|
631
631
|
if (!l?.clientActivityState?.elements) return [];
|
|
632
632
|
const s = [];
|
|
633
|
-
return l.clientActivityState.elements.forEach((
|
|
634
|
-
|
|
633
|
+
return l.clientActivityState.elements.forEach((S) => {
|
|
634
|
+
S.domRef?.current && s.push(S.domRef);
|
|
635
635
|
}), s;
|
|
636
636
|
}
|
|
637
637
|
function $e(e, a) {
|
|
@@ -647,23 +647,23 @@ function ft(e, a, l) {
|
|
|
647
647
|
});
|
|
648
648
|
}
|
|
649
649
|
function Te(e, a, l, s) {
|
|
650
|
-
const
|
|
650
|
+
const S = /* @__PURE__ */ new Map();
|
|
651
651
|
function u({
|
|
652
652
|
path: t = [],
|
|
653
653
|
meta: o,
|
|
654
654
|
componentId: d
|
|
655
655
|
}) {
|
|
656
656
|
if (E(e, t)?.isRaw)
|
|
657
|
-
return
|
|
657
|
+
return _(e, t);
|
|
658
658
|
const b = o ? JSON.stringify(o.arrayViews || o.transforms) : "", P = t.join(".") + ":" + d + ":" + b;
|
|
659
|
-
if (
|
|
660
|
-
return
|
|
661
|
-
const v = [e, ...t].join("."),
|
|
659
|
+
if (S.has(P))
|
|
660
|
+
return S.get(P);
|
|
661
|
+
const v = [e, ...t].join("."), O = () => {
|
|
662
662
|
}, D = {
|
|
663
663
|
apply(q, g, k) {
|
|
664
664
|
if (k.length === 0) {
|
|
665
665
|
const r = t.length > 0 ? t.join(".") : "root", n = o?.arrayViews?.[r];
|
|
666
|
-
return te(e, d, t),
|
|
666
|
+
return te(e, d, t), _(e, t, n);
|
|
667
667
|
}
|
|
668
668
|
const C = k[0];
|
|
669
669
|
return a(C, t, { updateType: "update" }), !0;
|
|
@@ -674,7 +674,7 @@ function Te(e, a, l, s) {
|
|
|
674
674
|
if (g === Symbol.toStringTag)
|
|
675
675
|
return "CogsState";
|
|
676
676
|
if (g === Symbol.iterator) {
|
|
677
|
-
const { value: r } =
|
|
677
|
+
const { value: r } = j(e, t, o);
|
|
678
678
|
return Array.isArray(r) ? function* () {
|
|
679
679
|
for (let n = 0; n < r.length; n++)
|
|
680
680
|
yield r[n];
|
|
@@ -687,66 +687,68 @@ function Te(e, a, l, s) {
|
|
|
687
687
|
if (t.length === 0 && g in h)
|
|
688
688
|
return h[g];
|
|
689
689
|
if (typeof g == "string" && !g.startsWith("$")) {
|
|
690
|
-
const { value: r } =
|
|
690
|
+
const { value: r } = j(e, t, o);
|
|
691
691
|
if (r !== null && typeof r == "object" && !Array.isArray(r) && Object.prototype.hasOwnProperty.call(r, g)) {
|
|
692
|
-
const
|
|
692
|
+
const f = [...t, g];
|
|
693
693
|
return u({
|
|
694
|
-
path:
|
|
694
|
+
path: f,
|
|
695
695
|
componentId: d,
|
|
696
696
|
meta: o
|
|
697
697
|
});
|
|
698
698
|
}
|
|
699
|
-
const
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
699
|
+
const i = [...t, g];
|
|
700
|
+
return u({
|
|
701
|
+
path: i,
|
|
702
|
+
componentId: d,
|
|
703
|
+
meta: o
|
|
704
|
+
});
|
|
705
|
+
}
|
|
706
|
+
if (typeof g == "string" && g.startsWith("$")) {
|
|
707
|
+
const r = g.slice(1), { value: n } = j(e, t, o), i = L.getState().registeredPlugins;
|
|
708
|
+
for (const f of i) {
|
|
709
|
+
const c = f.chainMethods?.[r];
|
|
710
|
+
if (c && ut(t, c.pathPattern) && dt(n, c.target))
|
|
711
|
+
return (...m) => {
|
|
712
|
+
const w = L.getState(), p = w.pluginOptions.get(e)?.get(f.name), A = w.getHookResult(e, f.name);
|
|
713
|
+
return c.handler(
|
|
706
714
|
{
|
|
707
715
|
stateKey: e,
|
|
708
716
|
path: t,
|
|
709
|
-
pluginName:
|
|
710
|
-
options:
|
|
711
|
-
hookData:
|
|
712
|
-
$get: () =>
|
|
717
|
+
pluginName: f.name,
|
|
718
|
+
options: p,
|
|
719
|
+
hookData: A,
|
|
720
|
+
$get: () => j(e, t, o).value,
|
|
713
721
|
$update: (V) => (a(V, t, {
|
|
714
722
|
updateType: "update"
|
|
715
723
|
}), {
|
|
716
724
|
synced: () => {
|
|
717
|
-
const
|
|
725
|
+
const T = M.getState().getShadowMetadata(e, t);
|
|
718
726
|
B(e, t, {
|
|
719
|
-
...
|
|
727
|
+
...T,
|
|
720
728
|
isDirty: !1,
|
|
721
729
|
stateSource: "server",
|
|
722
730
|
lastServerSync: Date.now()
|
|
723
731
|
});
|
|
724
732
|
}
|
|
725
733
|
}),
|
|
726
|
-
$applyOperation: (V,
|
|
734
|
+
$applyOperation: (V, T) => {
|
|
727
735
|
a(V.newValue, V.path, {
|
|
728
736
|
updateType: V.updateType,
|
|
729
737
|
itemId: V.itemId,
|
|
730
|
-
metaData:
|
|
738
|
+
metaData: T
|
|
731
739
|
});
|
|
732
740
|
},
|
|
733
|
-
getFieldMetaData: () => he(e, t)?.get(
|
|
734
|
-
setFieldMetaData: (V) => ve(e, t,
|
|
735
|
-
removeFieldMetaData: () => we(e, t,
|
|
741
|
+
getFieldMetaData: () => he(e, t)?.get(f.name),
|
|
742
|
+
setFieldMetaData: (V) => ve(e, t, f.name, V),
|
|
743
|
+
removeFieldMetaData: () => we(e, t, f.name),
|
|
736
744
|
getFieldRefs: () => Ee(e, t),
|
|
737
745
|
getFieldElements: () => $e(e, t),
|
|
738
746
|
setFieldDisabled: (V) => ft(e, t, V)
|
|
739
747
|
},
|
|
740
|
-
...
|
|
748
|
+
...m
|
|
741
749
|
);
|
|
742
750
|
};
|
|
743
751
|
}
|
|
744
|
-
const S = [...t, g];
|
|
745
|
-
return u({
|
|
746
|
-
path: S,
|
|
747
|
-
componentId: d,
|
|
748
|
-
meta: o
|
|
749
|
-
});
|
|
750
752
|
}
|
|
751
753
|
if (g === "$_rebuildStateShape")
|
|
752
754
|
return u;
|
|
@@ -755,36 +757,36 @@ function Te(e, a, l, s) {
|
|
|
755
757
|
const r = M.getState().getInitialOptions(e), n = r?.sync;
|
|
756
758
|
if (!n)
|
|
757
759
|
return console.error(`No mutation defined for state key "${e}"`), { success: !1, error: "No mutation defined" };
|
|
758
|
-
const
|
|
760
|
+
const i = M.getState().getShadowValue(e, []), f = r?.validation?.key;
|
|
759
761
|
try {
|
|
760
|
-
const
|
|
761
|
-
if (
|
|
762
|
-
const
|
|
762
|
+
const c = await n.action(i);
|
|
763
|
+
if (c && !c.success && c.errors, c?.success) {
|
|
764
|
+
const m = M.getState().getShadowMetadata(e, []);
|
|
763
765
|
B(e, [], {
|
|
764
|
-
...
|
|
766
|
+
...m,
|
|
765
767
|
isDirty: !1,
|
|
766
768
|
lastServerSync: Date.now(),
|
|
767
769
|
stateSource: "server",
|
|
768
|
-
baseServerState:
|
|
770
|
+
baseServerState: i
|
|
769
771
|
// Update base server state
|
|
770
|
-
}), n.onSuccess && n.onSuccess(
|
|
771
|
-
} else !
|
|
772
|
-
return
|
|
773
|
-
} catch (
|
|
774
|
-
return n.onError && n.onError(
|
|
772
|
+
}), n.onSuccess && n.onSuccess(c.data);
|
|
773
|
+
} else !c?.success && n.onError && n.onError(c.error);
|
|
774
|
+
return c;
|
|
775
|
+
} catch (c) {
|
|
776
|
+
return n.onError && n.onError(c), { success: !1, error: c };
|
|
775
777
|
}
|
|
776
778
|
};
|
|
777
779
|
if (g === "$_status" || g === "$getStatus") {
|
|
778
780
|
const r = () => {
|
|
779
|
-
const { shadowMeta: n, value:
|
|
780
|
-
return n?.isDirty === !0 ? "dirty" : n?.stateSource === "server" || n?.isDirty === !1 ? "synced" : n?.stateSource === "localStorage" ? "restored" : n?.stateSource === "default" ||
|
|
781
|
+
const { shadowMeta: n, value: i } = j(e, t, o);
|
|
782
|
+
return n?.isDirty === !0 ? "dirty" : n?.stateSource === "server" || n?.isDirty === !1 ? "synced" : n?.stateSource === "localStorage" ? "restored" : n?.stateSource === "default" || i !== void 0 ? "fresh" : "unknown";
|
|
781
783
|
};
|
|
782
784
|
return g === "$_status" ? r() : r;
|
|
783
785
|
}
|
|
784
786
|
if (g === "$removeStorage")
|
|
785
787
|
return () => {
|
|
786
|
-
const r = M.getState().initialStateGlobal[e], n = U(e),
|
|
787
|
-
de(
|
|
788
|
+
const r = M.getState().initialStateGlobal[e], n = U(e), i = W(n?.localStorage?.key) ? n.localStorage.key(r) : n?.localStorage?.key, f = s && i ? `${s}-${e}-${i}` : void 0;
|
|
789
|
+
de(f);
|
|
788
790
|
};
|
|
789
791
|
if (g === "$setRaw")
|
|
790
792
|
return (r) => {
|
|
@@ -796,17 +798,17 @@ function Te(e, a, l, s) {
|
|
|
796
798
|
const n = M.getState();
|
|
797
799
|
if (r) {
|
|
798
800
|
const w = r.map((p) => {
|
|
799
|
-
const A = [...t, p],
|
|
800
|
-
if (!
|
|
801
|
+
const A = [...t, p], V = n.getShadowValue(e, A), T = n.getShadowMetadata(e, A) || {}, F = T.typeInfo?.schema;
|
|
802
|
+
if (!F)
|
|
801
803
|
return {
|
|
802
804
|
key: p,
|
|
803
805
|
path: A,
|
|
804
806
|
success: !0,
|
|
805
|
-
data:
|
|
807
|
+
data: V
|
|
806
808
|
};
|
|
807
|
-
const I =
|
|
809
|
+
const I = F.safeParse(V), R = I.error?.issues || I.error?.errors || [];
|
|
808
810
|
return n.setShadowMetadata(e, A, {
|
|
809
|
-
...
|
|
811
|
+
...T,
|
|
810
812
|
validation: {
|
|
811
813
|
status: I.success ? "VALID" : "INVALID",
|
|
812
814
|
errors: I.success ? [] : [
|
|
@@ -818,7 +820,7 @@ function Te(e, a, l, s) {
|
|
|
818
820
|
}
|
|
819
821
|
],
|
|
820
822
|
lastValidated: Date.now(),
|
|
821
|
-
validatedValue:
|
|
823
|
+
validatedValue: V
|
|
822
824
|
}
|
|
823
825
|
}), n.notifyPathSubscribers([e, ...A].join("."), {
|
|
824
826
|
type: "VALIDATION_UPDATE"
|
|
@@ -835,11 +837,11 @@ function Te(e, a, l, s) {
|
|
|
835
837
|
results: w
|
|
836
838
|
};
|
|
837
839
|
}
|
|
838
|
-
const { value:
|
|
839
|
-
if (!
|
|
840
|
-
return { success: !0, data:
|
|
841
|
-
const
|
|
842
|
-
if (
|
|
840
|
+
const { value: i } = j(e, t, o), f = n.getInitialOptions(e), c = f?.validation?.zodSchemaV4 || f?.validation?.zodSchemaV3;
|
|
841
|
+
if (!c)
|
|
842
|
+
return { success: !0, data: i };
|
|
843
|
+
const m = c.safeParse(i);
|
|
844
|
+
if (m.success) {
|
|
843
845
|
const w = n.getShadowMetadata(e, t) || {};
|
|
844
846
|
n.setShadowMetadata(e, t, {
|
|
845
847
|
...w,
|
|
@@ -850,10 +852,10 @@ function Te(e, a, l, s) {
|
|
|
850
852
|
}
|
|
851
853
|
});
|
|
852
854
|
} else
|
|
853
|
-
(
|
|
854
|
-
const A = [...t, ...p.path.map(String)],
|
|
855
|
+
(m.error?.issues || m.error?.errors || []).forEach((p) => {
|
|
856
|
+
const A = [...t, ...p.path.map(String)], V = n.getShadowMetadata(e, A) || {};
|
|
855
857
|
n.setShadowMetadata(e, A, {
|
|
856
|
-
...
|
|
858
|
+
...V,
|
|
857
859
|
validation: {
|
|
858
860
|
status: "INVALID",
|
|
859
861
|
errors: [
|
|
@@ -869,38 +871,38 @@ function Te(e, a, l, s) {
|
|
|
869
871
|
}
|
|
870
872
|
});
|
|
871
873
|
});
|
|
872
|
-
return N(e),
|
|
874
|
+
return N(e), m;
|
|
873
875
|
};
|
|
874
876
|
if (g === "$showValidationErrors")
|
|
875
877
|
return () => {
|
|
876
|
-
const { shadowMeta: r } =
|
|
878
|
+
const { shadowMeta: r } = j(e, t, o);
|
|
877
879
|
return r?.validation?.status === "INVALID" && r.validation.errors.length > 0 ? r.validation.errors.filter((n) => n.severity === "error").map((n) => n.message) : [];
|
|
878
880
|
};
|
|
879
881
|
if (g === "$validationErrors")
|
|
880
882
|
return (r) => {
|
|
881
|
-
const n = M.getState(),
|
|
882
|
-
const
|
|
883
|
-
...
|
|
884
|
-
path:
|
|
885
|
-
})), p = w.filter((
|
|
886
|
-
(
|
|
887
|
-
),
|
|
883
|
+
const n = M.getState(), i = (c) => {
|
|
884
|
+
const m = n.getShadowMetadata(e, c)?.validation, w = (m?.errors || []).map((T) => ({
|
|
885
|
+
...T,
|
|
886
|
+
path: c
|
|
887
|
+
})), p = w.filter((T) => T.severity === "error"), A = w.filter(
|
|
888
|
+
(T) => T.severity === "warning"
|
|
889
|
+
), V = p.length > 0 ? "error" : A.length > 0 ? "warning" : void 0;
|
|
888
890
|
return {
|
|
889
|
-
status:
|
|
890
|
-
severity:
|
|
891
|
+
status: m?.status || "NOT_VALIDATED",
|
|
892
|
+
severity: V,
|
|
891
893
|
hasErrors: p.length > 0,
|
|
892
894
|
hasWarnings: A.length > 0,
|
|
893
895
|
message: p[0]?.message || A[0]?.message || "",
|
|
894
|
-
errors: p.map((
|
|
895
|
-
warnings: A.map((
|
|
896
|
+
errors: p.map((T) => T.message),
|
|
897
|
+
warnings: A.map((T) => T.message),
|
|
896
898
|
allErrors: w,
|
|
897
|
-
path:
|
|
898
|
-
getData: () => n.getShadowValue(e,
|
|
899
|
+
path: c,
|
|
900
|
+
getData: () => n.getShadowValue(e, c)
|
|
899
901
|
};
|
|
900
902
|
};
|
|
901
903
|
return (r ?? Object.keys(n.getShadowNode(e, t) ?? {}).filter(
|
|
902
|
-
(
|
|
903
|
-
)).map((
|
|
904
|
+
(c) => c !== "_meta"
|
|
905
|
+
)).map((c) => i([...t, c]));
|
|
904
906
|
};
|
|
905
907
|
if (g === "$getSelected")
|
|
906
908
|
return () => {
|
|
@@ -912,8 +914,8 @@ function Te(e, a, l, s) {
|
|
|
912
914
|
const n = M.getState().selectedIndicesMap.get(r);
|
|
913
915
|
if (!n)
|
|
914
916
|
return;
|
|
915
|
-
const
|
|
916
|
-
if (!(
|
|
917
|
+
const i = t.join("."), f = o?.arrayViews?.[i], c = n.split(".").pop();
|
|
918
|
+
if (!(f && !f.includes(c) || _(
|
|
917
919
|
e,
|
|
918
920
|
n.split(".").slice(1)
|
|
919
921
|
) === void 0))
|
|
@@ -930,11 +932,11 @@ function Te(e, a, l, s) {
|
|
|
930
932
|
const n = M.getState().selectedIndicesMap.get(r);
|
|
931
933
|
if (!n)
|
|
932
934
|
return -1;
|
|
933
|
-
const { keys:
|
|
934
|
-
if (!
|
|
935
|
+
const { keys: i } = z(e, t, o);
|
|
936
|
+
if (!i)
|
|
935
937
|
return -1;
|
|
936
|
-
const
|
|
937
|
-
return
|
|
938
|
+
const f = n.split(".").pop();
|
|
939
|
+
return i.indexOf(f);
|
|
938
940
|
};
|
|
939
941
|
if (g === "$clearSelected")
|
|
940
942
|
return Y(e, t), () => {
|
|
@@ -944,20 +946,20 @@ function Te(e, a, l, s) {
|
|
|
944
946
|
};
|
|
945
947
|
if (g === "$map")
|
|
946
948
|
return (r) => {
|
|
947
|
-
const { value: n, keys:
|
|
949
|
+
const { value: n, keys: i } = z(
|
|
948
950
|
e,
|
|
949
951
|
t,
|
|
950
952
|
o
|
|
951
953
|
);
|
|
952
|
-
if (te(e, d, t), !
|
|
954
|
+
if (te(e, d, t), !i || !Array.isArray(n))
|
|
953
955
|
return [];
|
|
954
|
-
const
|
|
956
|
+
const f = u({
|
|
955
957
|
path: t,
|
|
956
958
|
componentId: d,
|
|
957
959
|
meta: o
|
|
958
960
|
});
|
|
959
|
-
return n.map((
|
|
960
|
-
const w =
|
|
961
|
+
return n.map((c, m) => {
|
|
962
|
+
const w = i[m];
|
|
961
963
|
if (!w) return;
|
|
962
964
|
const p = [...t, w], A = u({
|
|
963
965
|
path: p,
|
|
@@ -965,23 +967,23 @@ function Te(e, a, l, s) {
|
|
|
965
967
|
componentId: d,
|
|
966
968
|
meta: o
|
|
967
969
|
});
|
|
968
|
-
return r(A,
|
|
970
|
+
return r(A, m, f);
|
|
969
971
|
});
|
|
970
972
|
};
|
|
971
973
|
if (g === "$filter")
|
|
972
974
|
return (r) => {
|
|
973
|
-
const n = t.length > 0 ? t.join(".") : "root", { keys:
|
|
975
|
+
const n = t.length > 0 ? t.join(".") : "root", { keys: i, value: f } = z(
|
|
974
976
|
e,
|
|
975
977
|
t,
|
|
976
978
|
o
|
|
977
979
|
);
|
|
978
|
-
if (!Array.isArray(
|
|
980
|
+
if (!Array.isArray(f))
|
|
979
981
|
throw new Error("filter can only be used on arrays");
|
|
980
|
-
const
|
|
981
|
-
return
|
|
982
|
-
if (r(
|
|
983
|
-
const p =
|
|
984
|
-
p &&
|
|
982
|
+
const c = [];
|
|
983
|
+
return f.forEach((m, w) => {
|
|
984
|
+
if (r(m, w)) {
|
|
985
|
+
const p = i[w];
|
|
986
|
+
p && c.push(p);
|
|
985
987
|
}
|
|
986
988
|
}), u({
|
|
987
989
|
path: t,
|
|
@@ -990,7 +992,7 @@ function Te(e, a, l, s) {
|
|
|
990
992
|
...o,
|
|
991
993
|
arrayViews: {
|
|
992
994
|
...o?.arrayViews || {},
|
|
993
|
-
[n]:
|
|
995
|
+
[n]: c
|
|
994
996
|
},
|
|
995
997
|
transforms: [
|
|
996
998
|
...o?.transforms || [],
|
|
@@ -1001,19 +1003,19 @@ function Te(e, a, l, s) {
|
|
|
1001
1003
|
};
|
|
1002
1004
|
if (g === "$sort")
|
|
1003
1005
|
return (r) => {
|
|
1004
|
-
const n = t.length > 0 ? t.join(".") : "root", { value:
|
|
1006
|
+
const n = t.length > 0 ? t.join(".") : "root", { value: i, keys: f } = z(
|
|
1005
1007
|
e,
|
|
1006
1008
|
t,
|
|
1007
1009
|
o
|
|
1008
1010
|
);
|
|
1009
|
-
if (!Array.isArray(
|
|
1011
|
+
if (!Array.isArray(i) || !f)
|
|
1010
1012
|
throw new Error("No array keys found for sorting");
|
|
1011
|
-
const
|
|
1013
|
+
const c = i.map((w, p) => ({
|
|
1012
1014
|
item: w,
|
|
1013
|
-
key:
|
|
1015
|
+
key: f[p]
|
|
1014
1016
|
}));
|
|
1015
|
-
|
|
1016
|
-
const
|
|
1017
|
+
c.sort((w, p) => r(w.item, p.item));
|
|
1018
|
+
const m = c.map((w) => w.key);
|
|
1017
1019
|
return u({
|
|
1018
1020
|
path: t,
|
|
1019
1021
|
componentId: d,
|
|
@@ -1021,7 +1023,7 @@ function Te(e, a, l, s) {
|
|
|
1021
1023
|
...o,
|
|
1022
1024
|
arrayViews: {
|
|
1023
1025
|
...o?.arrayViews || {},
|
|
1024
|
-
[n]:
|
|
1026
|
+
[n]: m
|
|
1025
1027
|
},
|
|
1026
1028
|
transforms: [
|
|
1027
1029
|
...o?.transforms || [],
|
|
@@ -1032,43 +1034,43 @@ function Te(e, a, l, s) {
|
|
|
1032
1034
|
};
|
|
1033
1035
|
if (g === "$list")
|
|
1034
1036
|
return (r) => /* @__PURE__ */ Q(() => {
|
|
1035
|
-
const
|
|
1037
|
+
const i = x(/* @__PURE__ */ new Map()), [f, c] = ne({}), m = t.length > 0 ? t.join(".") : "root", w = lt(e, t, o), p = pe(() => ({
|
|
1036
1038
|
...o,
|
|
1037
1039
|
arrayViews: {
|
|
1038
1040
|
...o?.arrayViews || {},
|
|
1039
|
-
[
|
|
1041
|
+
[m]: w
|
|
1040
1042
|
}
|
|
1041
|
-
}), [o,
|
|
1043
|
+
}), [o, m, w]), { value: A } = z(
|
|
1042
1044
|
e,
|
|
1043
1045
|
t,
|
|
1044
1046
|
p
|
|
1045
1047
|
);
|
|
1046
1048
|
if (Z(() => {
|
|
1047
|
-
const
|
|
1049
|
+
const F = M.getState().subscribeToPath(v, (I) => {
|
|
1048
1050
|
if (I.type === "GET_SELECTED")
|
|
1049
1051
|
return;
|
|
1050
1052
|
const G = M.getState().getShadowMetadata(e, t)?.transformCaches;
|
|
1051
1053
|
if (G)
|
|
1052
1054
|
for (const ee of G.keys())
|
|
1053
1055
|
ee.startsWith(d) && G.delete(ee);
|
|
1054
|
-
(I.type === "INSERT" || I.type === "INSERT_MANY" || I.type === "REMOVE" || I.type === "CLEAR_SELECTION" || I.type === "SERVER_STATE_UPDATE" && !o?.serverStateIsUpStream) &&
|
|
1056
|
+
(I.type === "INSERT" || I.type === "INSERT_MANY" || I.type === "REMOVE" || I.type === "CLEAR_SELECTION" || I.type === "SERVER_STATE_UPDATE" && !o?.serverStateIsUpStream) && c({});
|
|
1055
1057
|
});
|
|
1056
1058
|
return () => {
|
|
1057
|
-
|
|
1059
|
+
F();
|
|
1058
1060
|
};
|
|
1059
1061
|
}, [d, v]), !Array.isArray(A))
|
|
1060
1062
|
return null;
|
|
1061
|
-
const
|
|
1063
|
+
const V = u({
|
|
1062
1064
|
path: t,
|
|
1063
1065
|
componentId: d,
|
|
1064
1066
|
meta: p
|
|
1065
1067
|
// Use updated meta here
|
|
1066
|
-
}),
|
|
1068
|
+
}), T = A.map((F, I) => {
|
|
1067
1069
|
const R = w[I];
|
|
1068
1070
|
if (!R)
|
|
1069
1071
|
return null;
|
|
1070
|
-
let G =
|
|
1071
|
-
G || (G = ae(),
|
|
1072
|
+
let G = i.current.get(R);
|
|
1073
|
+
G || (G = ae(), i.current.set(R, G));
|
|
1072
1074
|
const ee = [...t, R];
|
|
1073
1075
|
return Se(Ue, {
|
|
1074
1076
|
key: R,
|
|
@@ -1076,17 +1078,17 @@ function Te(e, a, l, s) {
|
|
|
1076
1078
|
itemComponentId: G,
|
|
1077
1079
|
itemPath: ee,
|
|
1078
1080
|
localIndex: I,
|
|
1079
|
-
arraySetter:
|
|
1081
|
+
arraySetter: V,
|
|
1080
1082
|
rebuildStateShape: u,
|
|
1081
1083
|
renderFn: r
|
|
1082
1084
|
});
|
|
1083
1085
|
});
|
|
1084
|
-
return /* @__PURE__ */ Q(Pe, { children:
|
|
1086
|
+
return /* @__PURE__ */ Q(Pe, { children: T });
|
|
1085
1087
|
}, {});
|
|
1086
1088
|
if (g === "$stateFlattenOn")
|
|
1087
1089
|
return (r) => {
|
|
1088
|
-
const n = t.length > 0 ? t.join(".") : "root",
|
|
1089
|
-
return Array.isArray(
|
|
1090
|
+
const n = t.length > 0 ? t.join(".") : "root", i = o?.arrayViews?.[n], f = M.getState().getShadowValue(e, t, i);
|
|
1091
|
+
return Array.isArray(f) ? u({
|
|
1090
1092
|
path: [...t, "[*]", r],
|
|
1091
1093
|
componentId: d,
|
|
1092
1094
|
meta: o
|
|
@@ -1094,21 +1096,21 @@ function Te(e, a, l, s) {
|
|
|
1094
1096
|
};
|
|
1095
1097
|
if (g === "$index")
|
|
1096
1098
|
return (r) => {
|
|
1097
|
-
const n = t.length > 0 ? t.join(".") : "root",
|
|
1098
|
-
if (
|
|
1099
|
-
const
|
|
1100
|
-
return
|
|
1101
|
-
path: [...t,
|
|
1099
|
+
const n = t.length > 0 ? t.join(".") : "root", i = o?.arrayViews?.[n];
|
|
1100
|
+
if (i) {
|
|
1101
|
+
const m = i[r];
|
|
1102
|
+
return m ? u({
|
|
1103
|
+
path: [...t, m],
|
|
1102
1104
|
componentId: d,
|
|
1103
1105
|
meta: o
|
|
1104
1106
|
}) : void 0;
|
|
1105
1107
|
}
|
|
1106
|
-
const
|
|
1107
|
-
if (!
|
|
1108
|
-
const
|
|
1109
|
-
if (
|
|
1108
|
+
const f = E(e, t);
|
|
1109
|
+
if (!f?.arrayKeys) return;
|
|
1110
|
+
const c = f.arrayKeys[r];
|
|
1111
|
+
if (c)
|
|
1110
1112
|
return u({
|
|
1111
|
-
path: [...t,
|
|
1113
|
+
path: [...t, c],
|
|
1112
1114
|
componentId: d,
|
|
1113
1115
|
meta: o
|
|
1114
1116
|
});
|
|
@@ -1121,9 +1123,9 @@ function Te(e, a, l, s) {
|
|
|
1121
1123
|
const n = r[r.length - 1];
|
|
1122
1124
|
if (!n)
|
|
1123
1125
|
return;
|
|
1124
|
-
const
|
|
1126
|
+
const i = [...t, n];
|
|
1125
1127
|
return u({
|
|
1126
|
-
path:
|
|
1128
|
+
path: i,
|
|
1127
1129
|
componentId: d,
|
|
1128
1130
|
meta: o
|
|
1129
1131
|
});
|
|
@@ -1142,23 +1144,23 @@ function Te(e, a, l, s) {
|
|
|
1142
1144
|
});
|
|
1143
1145
|
};
|
|
1144
1146
|
if (g === "$uniqueInsert")
|
|
1145
|
-
return (r, n,
|
|
1146
|
-
const { value:
|
|
1147
|
+
return (r, n, i) => {
|
|
1148
|
+
const { value: f } = j(
|
|
1147
1149
|
e,
|
|
1148
1150
|
t,
|
|
1149
1151
|
o
|
|
1150
|
-
),
|
|
1151
|
-
let
|
|
1152
|
-
if (!
|
|
1152
|
+
), c = W(r) ? r(f) : r;
|
|
1153
|
+
let m = null;
|
|
1154
|
+
if (!f.some((p) => {
|
|
1153
1155
|
const A = n ? n.every(
|
|
1154
|
-
(
|
|
1155
|
-
) : X(p,
|
|
1156
|
-
return A && (
|
|
1156
|
+
(V) => X(p[V], c[V])
|
|
1157
|
+
) : X(p, c);
|
|
1158
|
+
return A && (m = p), A;
|
|
1157
1159
|
}))
|
|
1158
|
-
a(
|
|
1159
|
-
else if (
|
|
1160
|
-
const p =
|
|
1161
|
-
(
|
|
1160
|
+
a(c, t, { updateType: "insert" });
|
|
1161
|
+
else if (i && m) {
|
|
1162
|
+
const p = i(m), A = f.map(
|
|
1163
|
+
(V) => X(V, m) ? p : V
|
|
1162
1164
|
);
|
|
1163
1165
|
a(A, t, {
|
|
1164
1166
|
updateType: "update"
|
|
@@ -1167,11 +1169,11 @@ function Te(e, a, l, s) {
|
|
|
1167
1169
|
};
|
|
1168
1170
|
if (g === "$cut")
|
|
1169
1171
|
return (r, n) => {
|
|
1170
|
-
const
|
|
1171
|
-
if (!
|
|
1172
|
+
const i = E(e, t);
|
|
1173
|
+
if (!i?.arrayKeys || i.arrayKeys.length === 0)
|
|
1172
1174
|
return;
|
|
1173
|
-
const
|
|
1174
|
-
|
|
1175
|
+
const f = r === -1 ? i.arrayKeys.length - 1 : r !== void 0 ? r : i.arrayKeys.length - 1, c = i.arrayKeys[f];
|
|
1176
|
+
c && a(null, [...t, c], {
|
|
1175
1177
|
updateType: "cut"
|
|
1176
1178
|
});
|
|
1177
1179
|
};
|
|
@@ -1180,16 +1182,16 @@ function Te(e, a, l, s) {
|
|
|
1180
1182
|
const r = [e, ...t].join("."), { keys: n } = z(e, t, o);
|
|
1181
1183
|
if (!n || n.length === 0)
|
|
1182
1184
|
return;
|
|
1183
|
-
const
|
|
1184
|
-
if (!
|
|
1185
|
+
const i = M.getState().selectedIndicesMap.get(r);
|
|
1186
|
+
if (!i)
|
|
1185
1187
|
return;
|
|
1186
|
-
const
|
|
1187
|
-
if (!n.includes(
|
|
1188
|
+
const f = i.split(".").pop();
|
|
1189
|
+
if (!n.includes(f))
|
|
1188
1190
|
return;
|
|
1189
|
-
const
|
|
1191
|
+
const c = i.split(".").slice(1);
|
|
1190
1192
|
M.getState().clearSelectedIndex({ arrayKey: r });
|
|
1191
|
-
const
|
|
1192
|
-
Y(e,
|
|
1193
|
+
const m = c.slice(0, -1);
|
|
1194
|
+
Y(e, m), a(null, c, {
|
|
1193
1195
|
updateType: "cut"
|
|
1194
1196
|
});
|
|
1195
1197
|
};
|
|
@@ -1197,12 +1199,12 @@ function Te(e, a, l, s) {
|
|
|
1197
1199
|
return (r) => {
|
|
1198
1200
|
const {
|
|
1199
1201
|
isArray: n,
|
|
1200
|
-
value:
|
|
1201
|
-
keys:
|
|
1202
|
+
value: i,
|
|
1203
|
+
keys: f
|
|
1202
1204
|
} = z(e, t, o);
|
|
1203
1205
|
if (!n) return;
|
|
1204
|
-
const
|
|
1205
|
-
|
|
1206
|
+
const c = le(i, f, (m) => m === r);
|
|
1207
|
+
c && a(null, [...t, c.key], {
|
|
1206
1208
|
updateType: "cut"
|
|
1207
1209
|
});
|
|
1208
1210
|
};
|
|
@@ -1210,14 +1212,14 @@ function Te(e, a, l, s) {
|
|
|
1210
1212
|
return (r) => {
|
|
1211
1213
|
const {
|
|
1212
1214
|
isArray: n,
|
|
1213
|
-
value:
|
|
1214
|
-
keys:
|
|
1215
|
+
value: i,
|
|
1216
|
+
keys: f
|
|
1215
1217
|
} = z(e, t, o);
|
|
1216
1218
|
if (!n) return;
|
|
1217
|
-
const
|
|
1218
|
-
if (
|
|
1219
|
-
const
|
|
1220
|
-
a(null,
|
|
1219
|
+
const c = le(i, f, (m) => m === r);
|
|
1220
|
+
if (c) {
|
|
1221
|
+
const m = [...t, c.key];
|
|
1222
|
+
a(null, m, {
|
|
1221
1223
|
updateType: "cut"
|
|
1222
1224
|
});
|
|
1223
1225
|
} else
|
|
@@ -1225,22 +1227,22 @@ function Te(e, a, l, s) {
|
|
|
1225
1227
|
};
|
|
1226
1228
|
if (g === "$findWith")
|
|
1227
1229
|
return (r, n) => {
|
|
1228
|
-
const { isArray:
|
|
1229
|
-
if (!
|
|
1230
|
+
const { isArray: i, value: f, keys: c } = z(e, t, o);
|
|
1231
|
+
if (!i)
|
|
1230
1232
|
throw new Error("findWith can only be used on arrays");
|
|
1231
|
-
const
|
|
1232
|
-
|
|
1233
|
-
|
|
1233
|
+
const m = le(
|
|
1234
|
+
f,
|
|
1235
|
+
c,
|
|
1234
1236
|
(w) => w?.[r] === n
|
|
1235
1237
|
);
|
|
1236
|
-
return
|
|
1237
|
-
path: [...t,
|
|
1238
|
+
return m ? u({
|
|
1239
|
+
path: [...t, m.key],
|
|
1238
1240
|
componentId: d,
|
|
1239
1241
|
meta: o
|
|
1240
1242
|
}) : null;
|
|
1241
1243
|
};
|
|
1242
1244
|
if (g === "$cutThis") {
|
|
1243
|
-
const { value: r } =
|
|
1245
|
+
const { value: r } = j(e, t, o), n = t.slice(0, -1);
|
|
1244
1246
|
return Y(e, n), () => {
|
|
1245
1247
|
a(r, t, { updateType: "cut" });
|
|
1246
1248
|
};
|
|
@@ -1248,7 +1250,7 @@ function Te(e, a, l, s) {
|
|
|
1248
1250
|
if (g === "$get")
|
|
1249
1251
|
return () => {
|
|
1250
1252
|
te(e, d, t);
|
|
1251
|
-
const { value: r } =
|
|
1253
|
+
const { value: r } = j(e, t, o);
|
|
1252
1254
|
return r;
|
|
1253
1255
|
};
|
|
1254
1256
|
if (g === "$$derive")
|
|
@@ -1269,44 +1271,44 @@ function Te(e, a, l, s) {
|
|
|
1269
1271
|
if (g === "$isSelected") {
|
|
1270
1272
|
const r = t.slice(0, -1);
|
|
1271
1273
|
if (E(e, r)?.arrayKeys) {
|
|
1272
|
-
const
|
|
1273
|
-
return
|
|
1274
|
+
const i = e + "." + r.join("."), f = M.getState().selectedIndicesMap.get(i), c = e + "." + t.join(".");
|
|
1275
|
+
return f === c;
|
|
1274
1276
|
}
|
|
1275
1277
|
return;
|
|
1276
1278
|
}
|
|
1277
1279
|
if (g === "$setSelected")
|
|
1278
1280
|
return (r) => {
|
|
1279
|
-
const n = t.slice(0, -1),
|
|
1280
|
-
Y(e, n, void 0), M.getState().selectedIndicesMap.get(
|
|
1281
|
+
const n = t.slice(0, -1), i = e + "." + n.join("."), f = e + "." + t.join(".");
|
|
1282
|
+
Y(e, n, void 0), M.getState().selectedIndicesMap.get(i), r && M.getState().setSelectedIndex(i, f);
|
|
1281
1283
|
};
|
|
1282
1284
|
if (g === "$toggleSelected")
|
|
1283
1285
|
return () => {
|
|
1284
|
-
const r = t.slice(0, -1), n = e + "." + r.join("."),
|
|
1285
|
-
M.getState().selectedIndicesMap.get(n) ===
|
|
1286
|
+
const r = t.slice(0, -1), n = e + "." + r.join("."), i = e + "." + t.join(".");
|
|
1287
|
+
M.getState().selectedIndicesMap.get(n) === i ? M.getState().clearSelectedIndex({ arrayKey: n }) : M.getState().setSelectedIndex(n, i), Y(e, r);
|
|
1286
1288
|
};
|
|
1287
1289
|
if (g === "$clearValidation")
|
|
1288
1290
|
return (r) => {
|
|
1289
|
-
const n = r ? [...t, ...r] : t,
|
|
1290
|
-
if (console.log("startNode ",
|
|
1291
|
-
const
|
|
1292
|
-
for (console.log("stack ",
|
|
1293
|
-
const [
|
|
1294
|
-
if (console.log("while (stack.length ",
|
|
1295
|
-
if (
|
|
1296
|
-
|
|
1291
|
+
const n = r ? [...t, ...r] : t, i = M.getState(), f = i.getShadowNode(e, n);
|
|
1292
|
+
if (console.log("startNode ", f), !f) return;
|
|
1293
|
+
const c = [[f, n]];
|
|
1294
|
+
for (console.log("stack ", c); c.length > 0; ) {
|
|
1295
|
+
const [m, w] = c.pop();
|
|
1296
|
+
if (console.log("while (stack.length ", m, w), !m || typeof m != "object") continue;
|
|
1297
|
+
if (m._meta?.validation) {
|
|
1298
|
+
m._meta.validation = {
|
|
1297
1299
|
status: "NOT_VALIDATED",
|
|
1298
1300
|
errors: [],
|
|
1299
1301
|
lastValidated: Date.now(),
|
|
1300
1302
|
validatedValue: void 0
|
|
1301
1303
|
};
|
|
1302
1304
|
const A = [e, ...w].join(".");
|
|
1303
|
-
|
|
1305
|
+
i.notifyPathSubscribers(A, {
|
|
1304
1306
|
type: "VALIDATION_CLEAR"
|
|
1305
1307
|
});
|
|
1306
1308
|
}
|
|
1307
|
-
const p = Object.keys(
|
|
1309
|
+
const p = Object.keys(m);
|
|
1308
1310
|
for (const A of p)
|
|
1309
|
-
A !== "_meta" &&
|
|
1311
|
+
A !== "_meta" && c.push([m[A], [...w, A]]);
|
|
1310
1312
|
}
|
|
1311
1313
|
N(e);
|
|
1312
1314
|
};
|
|
@@ -1318,8 +1320,8 @@ function Te(e, a, l, s) {
|
|
|
1318
1320
|
fe({ stateKey: e, options: r, initialOptionsPart: {} });
|
|
1319
1321
|
};
|
|
1320
1322
|
if (g === "$_applyUpdate")
|
|
1321
|
-
return (r, n,
|
|
1322
|
-
a(r, n, { updateType:
|
|
1323
|
+
return (r, n, i = "update") => {
|
|
1324
|
+
a(r, n, { updateType: i });
|
|
1323
1325
|
};
|
|
1324
1326
|
if (g === "$_getEffectiveSetState")
|
|
1325
1327
|
return a;
|
|
@@ -1331,26 +1333,26 @@ function Te(e, a, l, s) {
|
|
|
1331
1333
|
return (r) => we(e, t, r);
|
|
1332
1334
|
if (g === "$addZodValidation")
|
|
1333
1335
|
return (r, n) => {
|
|
1334
|
-
const
|
|
1335
|
-
r.forEach((
|
|
1336
|
-
const
|
|
1337
|
-
|
|
1338
|
-
...
|
|
1336
|
+
const i = M.getState();
|
|
1337
|
+
r.forEach((f) => {
|
|
1338
|
+
const c = f.path.map(String), m = i.getShadowMetadata(e, c) || {};
|
|
1339
|
+
i.setShadowMetadata(e, c, {
|
|
1340
|
+
...m,
|
|
1339
1341
|
validation: {
|
|
1340
1342
|
status: "INVALID",
|
|
1341
1343
|
errors: [
|
|
1342
1344
|
{
|
|
1343
1345
|
source: n || "client",
|
|
1344
|
-
message:
|
|
1346
|
+
message: f.message,
|
|
1345
1347
|
severity: "error",
|
|
1346
|
-
code:
|
|
1348
|
+
code: f.code
|
|
1347
1349
|
}
|
|
1348
1350
|
],
|
|
1349
1351
|
lastValidated: Date.now(),
|
|
1350
1352
|
validatedValue: void 0
|
|
1351
1353
|
}
|
|
1352
|
-
}),
|
|
1353
|
-
[e, ...
|
|
1354
|
+
}), i.notifyPathSubscribers(
|
|
1355
|
+
[e, ...c].join("."),
|
|
1354
1356
|
{ type: "VALIDATION_UPDATE" }
|
|
1355
1357
|
);
|
|
1356
1358
|
}), N(e);
|
|
@@ -1358,10 +1360,10 @@ function Te(e, a, l, s) {
|
|
|
1358
1360
|
if (g === "$clearZodValidationPaths")
|
|
1359
1361
|
return (r) => {
|
|
1360
1362
|
const n = M.getState();
|
|
1361
|
-
r.forEach((
|
|
1362
|
-
const
|
|
1363
|
-
|
|
1364
|
-
...
|
|
1363
|
+
r.forEach((i) => {
|
|
1364
|
+
const f = n.getShadowMetadata(e, i) || {};
|
|
1365
|
+
f.validation && (n.setShadowMetadata(e, i, {
|
|
1366
|
+
...f,
|
|
1365
1367
|
validation: {
|
|
1366
1368
|
status: "NOT_VALIDATED",
|
|
1367
1369
|
errors: [],
|
|
@@ -1369,53 +1371,53 @@ function Te(e, a, l, s) {
|
|
|
1369
1371
|
validatedValue: void 0
|
|
1370
1372
|
}
|
|
1371
1373
|
}), n.notifyPathSubscribers(
|
|
1372
|
-
[e, ...
|
|
1374
|
+
[e, ...i].join("."),
|
|
1373
1375
|
{ type: "VALIDATION_CLEAR" }
|
|
1374
1376
|
));
|
|
1375
1377
|
}), N(e);
|
|
1376
1378
|
};
|
|
1377
1379
|
if (g === "$applyOperation")
|
|
1378
1380
|
return (r, n) => {
|
|
1379
|
-
let
|
|
1381
|
+
let i;
|
|
1380
1382
|
if (r.insertAfterId && r.updateType === "insert") {
|
|
1381
|
-
const
|
|
1382
|
-
if (
|
|
1383
|
-
const
|
|
1383
|
+
const f = E(e, r.path);
|
|
1384
|
+
if (f?.arrayKeys) {
|
|
1385
|
+
const c = f.arrayKeys.indexOf(
|
|
1384
1386
|
r.insertAfterId
|
|
1385
1387
|
);
|
|
1386
|
-
|
|
1388
|
+
c !== -1 && (i = c + 1);
|
|
1387
1389
|
}
|
|
1388
1390
|
}
|
|
1389
1391
|
a(r.newValue, r.path, {
|
|
1390
1392
|
updateType: r.updateType,
|
|
1391
1393
|
itemId: r.itemId,
|
|
1392
|
-
index:
|
|
1394
|
+
index: i,
|
|
1393
1395
|
// Pass the calculated index
|
|
1394
1396
|
metaData: n
|
|
1395
1397
|
});
|
|
1396
1398
|
};
|
|
1397
1399
|
if (g === "$applyJsonPatch")
|
|
1398
1400
|
return (r) => {
|
|
1399
|
-
const n = M.getState(),
|
|
1400
|
-
if (!
|
|
1401
|
-
const
|
|
1402
|
-
for (const
|
|
1403
|
-
const w =
|
|
1404
|
-
switch (
|
|
1401
|
+
const n = M.getState(), i = n.getShadowMetadata(e, []);
|
|
1402
|
+
if (!i?.components) return;
|
|
1403
|
+
const f = (m) => !m || m === "/" ? [] : m.split("/").slice(1).map((w) => w.replace(/~1/g, "/").replace(/~0/g, "~")), c = /* @__PURE__ */ new Set();
|
|
1404
|
+
for (const m of r) {
|
|
1405
|
+
const w = f(m.path);
|
|
1406
|
+
switch (m.op) {
|
|
1405
1407
|
case "add":
|
|
1406
1408
|
case "replace": {
|
|
1407
|
-
const { value: p } =
|
|
1409
|
+
const { value: p } = m;
|
|
1408
1410
|
n.updateShadowAtPath(e, w, p), n.markAsDirty(e, w, { bubble: !0 });
|
|
1409
1411
|
let A = [...w];
|
|
1410
1412
|
for (; ; ) {
|
|
1411
|
-
const
|
|
1413
|
+
const V = n.getShadowMetadata(
|
|
1412
1414
|
e,
|
|
1413
1415
|
A
|
|
1414
1416
|
);
|
|
1415
|
-
if (
|
|
1416
|
-
if (!
|
|
1417
|
-
const
|
|
1418
|
-
|
|
1417
|
+
if (V?.pathComponents && V.pathComponents.forEach((T) => {
|
|
1418
|
+
if (!c.has(T)) {
|
|
1419
|
+
const F = i.components?.get(T);
|
|
1420
|
+
F && (F.forceUpdate(), c.add(T));
|
|
1419
1421
|
}
|
|
1420
1422
|
}), A.length === 0) break;
|
|
1421
1423
|
A.pop();
|
|
@@ -1427,14 +1429,14 @@ function Te(e, a, l, s) {
|
|
|
1427
1429
|
n.removeShadowArrayElement(e, w), n.markAsDirty(e, p, { bubble: !0 });
|
|
1428
1430
|
let A = [...p];
|
|
1429
1431
|
for (; ; ) {
|
|
1430
|
-
const
|
|
1432
|
+
const V = n.getShadowMetadata(
|
|
1431
1433
|
e,
|
|
1432
1434
|
A
|
|
1433
1435
|
);
|
|
1434
|
-
if (
|
|
1435
|
-
if (!
|
|
1436
|
-
const
|
|
1437
|
-
|
|
1436
|
+
if (V?.pathComponents && V.pathComponents.forEach((T) => {
|
|
1437
|
+
if (!c.has(T)) {
|
|
1438
|
+
const F = i.components?.get(T);
|
|
1439
|
+
F && (F.forceUpdate(), c.add(T));
|
|
1438
1440
|
}
|
|
1439
1441
|
}), A.length === 0) break;
|
|
1440
1442
|
A.pop();
|
|
@@ -1472,15 +1474,15 @@ function Te(e, a, l, s) {
|
|
|
1472
1474
|
stateSource: "server",
|
|
1473
1475
|
lastServerSync: Date.now()
|
|
1474
1476
|
});
|
|
1475
|
-
const
|
|
1476
|
-
Qe(
|
|
1477
|
+
const i = [e, ...t].join(".");
|
|
1478
|
+
Qe(i, {
|
|
1477
1479
|
type: "SYNC_STATUS_CHANGE",
|
|
1478
1480
|
isDirty: !1
|
|
1479
1481
|
});
|
|
1480
1482
|
}
|
|
1481
1483
|
});
|
|
1482
1484
|
if (g === "$toggle") {
|
|
1483
|
-
const { value: r } =
|
|
1485
|
+
const { value: r } = j(
|
|
1484
1486
|
e,
|
|
1485
1487
|
t,
|
|
1486
1488
|
o
|
|
@@ -1495,8 +1497,8 @@ function Te(e, a, l, s) {
|
|
|
1495
1497
|
}
|
|
1496
1498
|
if (g === "$isolate")
|
|
1497
1499
|
return (r, n) => {
|
|
1498
|
-
const
|
|
1499
|
-
if (!
|
|
1500
|
+
const i = Array.isArray(r), f = i ? r : void 0, c = i ? n : r;
|
|
1501
|
+
if (!c || typeof c != "function")
|
|
1500
1502
|
throw new Error(
|
|
1501
1503
|
"CogsState: $isolate requires a render function."
|
|
1502
1504
|
);
|
|
@@ -1505,9 +1507,9 @@ function Te(e, a, l, s) {
|
|
|
1505
1507
|
{
|
|
1506
1508
|
stateKey: e,
|
|
1507
1509
|
path: t,
|
|
1508
|
-
dependencies:
|
|
1510
|
+
dependencies: f,
|
|
1509
1511
|
rebuildStateShape: u,
|
|
1510
|
-
renderFn:
|
|
1512
|
+
renderFn: c
|
|
1511
1513
|
}
|
|
1512
1514
|
);
|
|
1513
1515
|
};
|
|
@@ -1530,8 +1532,8 @@ function Te(e, a, l, s) {
|
|
|
1530
1532
|
meta: o
|
|
1531
1533
|
});
|
|
1532
1534
|
}
|
|
1533
|
-
}, J = new Proxy(
|
|
1534
|
-
return
|
|
1535
|
+
}, J = new Proxy(O, D);
|
|
1536
|
+
return S.set(P, J), J;
|
|
1535
1537
|
}
|
|
1536
1538
|
const h = {
|
|
1537
1539
|
$revertToInitialState: (t) => {
|
|
@@ -1557,8 +1559,8 @@ function Te(e, a, l, s) {
|
|
|
1557
1559
|
return de(P), De(() => {
|
|
1558
1560
|
Ve(e, t), K(e, t);
|
|
1559
1561
|
const v = M.getState().getShadowMetadata(e, []);
|
|
1560
|
-
v && v?.components?.forEach((
|
|
1561
|
-
|
|
1562
|
+
v && v?.components?.forEach((O) => {
|
|
1563
|
+
O.forceUpdate();
|
|
1562
1564
|
});
|
|
1563
1565
|
}), {
|
|
1564
1566
|
fetchId: (v) => o.$get()[v]
|
|
@@ -1576,35 +1578,35 @@ function Ae(e) {
|
|
|
1576
1578
|
function gt({
|
|
1577
1579
|
proxy: e
|
|
1578
1580
|
}) {
|
|
1579
|
-
const a = x(null), l = x(null), s = x(!1),
|
|
1581
|
+
const a = x(null), l = x(null), s = x(!1), S = `${e._stateKey}-${e._path.join(".")}`, u = e._path.length > 0 ? e._path.join(".") : "root", h = e._meta?.arrayViews?.[u], y = _(e._stateKey, e._path, h);
|
|
1580
1582
|
return Z(() => {
|
|
1581
1583
|
const t = a.current;
|
|
1582
1584
|
if (!t || s.current) return;
|
|
1583
1585
|
const o = setTimeout(() => {
|
|
1584
1586
|
if (!t.parentElement) {
|
|
1585
|
-
console.warn("Parent element not found for signal",
|
|
1587
|
+
console.warn("Parent element not found for signal", S);
|
|
1586
1588
|
return;
|
|
1587
1589
|
}
|
|
1588
1590
|
const d = t.parentElement, b = Array.from(d.childNodes).indexOf(t);
|
|
1589
1591
|
let P = d.getAttribute("data-parent-id");
|
|
1590
1592
|
P || (P = `parent-${crypto.randomUUID()}`, d.setAttribute("data-parent-id", P)), l.current = `instance-${crypto.randomUUID()}`;
|
|
1591
|
-
const v = M.getState().getShadowMetadata(e._stateKey, e._path) || {},
|
|
1592
|
-
|
|
1593
|
+
const v = M.getState().getShadowMetadata(e._stateKey, e._path) || {}, O = v.signals || [];
|
|
1594
|
+
O.push({
|
|
1593
1595
|
instanceId: l.current,
|
|
1594
1596
|
parentId: P,
|
|
1595
1597
|
position: b,
|
|
1596
1598
|
effect: e._effect
|
|
1597
1599
|
}), M.getState().setShadowMetadata(e._stateKey, e._path, {
|
|
1598
1600
|
...v,
|
|
1599
|
-
signals:
|
|
1601
|
+
signals: O
|
|
1600
1602
|
});
|
|
1601
|
-
let D =
|
|
1603
|
+
let D = y;
|
|
1602
1604
|
if (e._effect)
|
|
1603
1605
|
try {
|
|
1604
1606
|
D = new Function(
|
|
1605
1607
|
"state",
|
|
1606
1608
|
`return (${e._effect})(state)`
|
|
1607
|
-
)(
|
|
1609
|
+
)(y);
|
|
1608
1610
|
} catch (q) {
|
|
1609
1611
|
console.error("Error evaluating effect function:", q);
|
|
1610
1612
|
}
|
|
@@ -1623,7 +1625,7 @@ function gt({
|
|
|
1623
1625
|
}, []), Se("span", {
|
|
1624
1626
|
ref: a,
|
|
1625
1627
|
style: { display: "contents" },
|
|
1626
|
-
"data-signal-id":
|
|
1628
|
+
"data-signal-id": S
|
|
1627
1629
|
});
|
|
1628
1630
|
}
|
|
1629
1631
|
export {
|