cogsbox-state 0.5.485 → 0.5.487
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 +70 -7
- package/dist/CogsState.d.ts +26 -0
- package/dist/CogsState.d.ts.map +1 -1
- package/dist/CogsState.js +381 -355
- package/dist/CogsState.js.map +1 -1
- package/dist/Components.d.ts.map +1 -1
- package/dist/Components.js +173 -170
- package/dist/Components.js.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +98 -26
- package/src/Components.tsx +44 -18
package/dist/CogsState.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as Q, Fragment as
|
|
2
|
+
import { jsx as Q, Fragment as Pe } from "react/jsx-runtime";
|
|
3
3
|
import { pluginStore as R } from "./pluginStore.js";
|
|
4
4
|
import { useState as ne, useRef as q, useCallback as Ie, useEffect as Z, useLayoutEffect as re, useMemo as Ae, createElement as Se, startTransition as ke } from "react";
|
|
5
5
|
import { transformStateFunc as De, isFunction as L, isDeepEqual as X, isArray as Ce, getDifferences as _e } from "./utility.js";
|
|
@@ -11,15 +11,15 @@ import { useCogsConfig as Me } from "./CogsStateClient.js";
|
|
|
11
11
|
import { runValidation as ze } from "./validation.js";
|
|
12
12
|
const {
|
|
13
13
|
getInitialOptions: j,
|
|
14
|
-
updateInitialStateGlobal:
|
|
15
|
-
getShadowMetadata:
|
|
14
|
+
updateInitialStateGlobal: Ve,
|
|
15
|
+
getShadowMetadata: E,
|
|
16
16
|
setShadowMetadata: W,
|
|
17
17
|
getShadowValue: C,
|
|
18
18
|
initializeShadowState: K,
|
|
19
19
|
initializeAndMergeShadowState: Re,
|
|
20
20
|
updateShadowAtPath: Le,
|
|
21
21
|
insertShadowArrayElement: We,
|
|
22
|
-
insertManyShadowArrayElements:
|
|
22
|
+
insertManyShadowArrayElements: be,
|
|
23
23
|
removeShadowArrayElement: Be,
|
|
24
24
|
setInitialStateOptions: ye,
|
|
25
25
|
setServerStateUpdate: me,
|
|
@@ -35,7 +35,7 @@ const {
|
|
|
35
35
|
removePluginMetaData: we
|
|
36
36
|
} = p.getState(), { notifyUpdate: Ye } = R.getState();
|
|
37
37
|
function F(e, n, l) {
|
|
38
|
-
const i =
|
|
38
|
+
const i = E(e, n);
|
|
39
39
|
if (!!!i?.arrayKeys)
|
|
40
40
|
return { isArray: !1, value: p.getState().getShadowValue(e, n), keys: [] };
|
|
41
41
|
const u = n.length > 0 ? n.join(".") : "root", h = l?.arrayViews?.[u] ?? i.arrayKeys;
|
|
@@ -65,21 +65,21 @@ function fe({
|
|
|
65
65
|
const i = j(e) || {}, f = l[e] || {};
|
|
66
66
|
let u = { ...f, ...i }, h = !1;
|
|
67
67
|
if (n) {
|
|
68
|
-
const
|
|
68
|
+
const m = (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]) || (m(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 = m(u, n);
|
|
74
74
|
}
|
|
75
75
|
if (u.validation && (n?.validation?.hasOwnProperty("onBlur") || i?.validation?.hasOwnProperty("onBlur") || f?.validation?.hasOwnProperty("onBlur") || (u.validation.onBlur = "error", h = !0)), h) {
|
|
76
76
|
ye(e, u);
|
|
77
|
-
const
|
|
78
|
-
(
|
|
77
|
+
const m = u.validation?.zodSchemaV4, t = u.validation?.zodSchemaV3;
|
|
78
|
+
(m !== i?.validation?.zodSchemaV4 || t !== i?.validation?.zodSchemaV3) && (m || t) && (m ? H(e, m, "zod4") : t && H(e, t, "zod3"), U(e));
|
|
79
79
|
}
|
|
80
80
|
return u;
|
|
81
81
|
}
|
|
82
|
-
const
|
|
82
|
+
const bt = (e, n) => {
|
|
83
83
|
n?.plugins && R.getState().setRegisteredPlugins(n.plugins);
|
|
84
84
|
const l = {};
|
|
85
85
|
if (n?.plugins)
|
|
@@ -92,29 +92,29 @@ const Vt = (e, n) => {
|
|
|
92
92
|
onBlur: "error",
|
|
93
93
|
...n?.validation
|
|
94
94
|
};
|
|
95
|
-
const
|
|
96
|
-
|
|
95
|
+
const $ = j(o), V = $ ? {
|
|
96
|
+
...$,
|
|
97
97
|
formElements: n?.formElements,
|
|
98
98
|
validation: {
|
|
99
|
-
|
|
99
|
+
...$.validation,
|
|
100
100
|
...d.validation
|
|
101
101
|
}
|
|
102
102
|
} : d;
|
|
103
|
-
Object.keys(
|
|
103
|
+
Object.keys(V).length > 0 && ye(o, V);
|
|
104
104
|
}), Object.keys(f).forEach((o) => {
|
|
105
105
|
K(o, f[o]);
|
|
106
106
|
});
|
|
107
107
|
const h = (o, d) => {
|
|
108
|
-
const [
|
|
108
|
+
const [$] = ne(d?.componentId ?? ae()), V = fe({
|
|
109
109
|
stateKey: o,
|
|
110
110
|
options: d,
|
|
111
111
|
initialOptionsPart: u
|
|
112
|
-
}),
|
|
113
|
-
|
|
112
|
+
}), T = q(V);
|
|
113
|
+
T.current = V;
|
|
114
114
|
const v = C(o, []) || f[o], _ = ct(v, {
|
|
115
115
|
stateKey: o,
|
|
116
116
|
syncUpdate: d?.syncUpdate,
|
|
117
|
-
componentId:
|
|
117
|
+
componentId: $,
|
|
118
118
|
localStorage: d?.localStorage,
|
|
119
119
|
middleware: d?.middleware,
|
|
120
120
|
reactiveType: d?.reactiveType,
|
|
@@ -128,28 +128,28 @@ const Vt = (e, n) => {
|
|
|
128
128
|
}, [o, d]), re(() => (R.getState().registerStateHandler(o, _), () => {
|
|
129
129
|
R.getState().unregisterStateHandler(o);
|
|
130
130
|
}), [o, _]), re(() => {
|
|
131
|
-
const
|
|
132
|
-
|
|
131
|
+
const P = j(o)?.validation;
|
|
132
|
+
P?.zodSchemaV4 ? H(o, P.zodSchemaV4, "zod4") : P?.zodSchemaV3 && H(o, P.zodSchemaV3, "zod3");
|
|
133
133
|
}), _;
|
|
134
134
|
};
|
|
135
|
-
function
|
|
135
|
+
function m(o, d) {
|
|
136
136
|
if (fe({ stateKey: o, options: d, initialOptionsPart: u }), d.localStorage && Xe(o, d), d.formElements) {
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
formWrapper: d.formElements[
|
|
140
|
-
} :
|
|
141
|
-
R.getState().setRegisteredPlugins(
|
|
137
|
+
const V = R.getState().registeredPlugins.map((T) => d.formElements.hasOwnProperty(T.name) ? {
|
|
138
|
+
...T,
|
|
139
|
+
formWrapper: d.formElements[T.name]
|
|
140
|
+
} : T);
|
|
141
|
+
R.getState().setRegisteredPlugins(V);
|
|
142
142
|
}
|
|
143
143
|
U(o);
|
|
144
144
|
}
|
|
145
145
|
function t(o) {
|
|
146
|
-
Object.keys(f).forEach((
|
|
147
|
-
|
|
146
|
+
Object.keys(f).forEach(($) => {
|
|
147
|
+
m($, o);
|
|
148
148
|
});
|
|
149
149
|
}
|
|
150
150
|
return {
|
|
151
151
|
useCogsState: h,
|
|
152
|
-
setCogsOptionsByKey:
|
|
152
|
+
setCogsOptionsByKey: m,
|
|
153
153
|
setCogsOptions: t
|
|
154
154
|
};
|
|
155
155
|
}, Ze = (e, n, l, i, f) => {
|
|
@@ -162,15 +162,15 @@ const Vt = (e, n) => {
|
|
|
162
162
|
const u = L(l?.localStorage?.key) ? l.localStorage?.key(e) : l?.localStorage?.key;
|
|
163
163
|
if (u && i) {
|
|
164
164
|
const h = `${i}-${n}-${u}`;
|
|
165
|
-
let
|
|
165
|
+
let m;
|
|
166
166
|
try {
|
|
167
|
-
|
|
167
|
+
m = ce(h)?.lastSyncedWithServer;
|
|
168
168
|
} catch {
|
|
169
169
|
}
|
|
170
|
-
const t =
|
|
170
|
+
const t = E(n, []), o = {
|
|
171
171
|
state: e,
|
|
172
172
|
lastUpdated: Date.now(),
|
|
173
|
-
lastSyncedWithServer:
|
|
173
|
+
lastSyncedWithServer: m,
|
|
174
174
|
stateSource: t?.stateSource,
|
|
175
175
|
baseServerState: t?.baseServerState
|
|
176
176
|
}, d = Fe.serialize(o);
|
|
@@ -205,7 +205,7 @@ const Vt = (e, n) => {
|
|
|
205
205
|
}
|
|
206
206
|
return !1;
|
|
207
207
|
}, U = (e) => {
|
|
208
|
-
const n =
|
|
208
|
+
const n = E(e, []);
|
|
209
209
|
if (!n) return;
|
|
210
210
|
const l = /* @__PURE__ */ new Set();
|
|
211
211
|
n?.components?.forEach((i) => {
|
|
@@ -215,16 +215,16 @@ const Vt = (e, n) => {
|
|
|
215
215
|
});
|
|
216
216
|
};
|
|
217
217
|
function oe(e, n, l, i) {
|
|
218
|
-
const f =
|
|
218
|
+
const f = E(e, n);
|
|
219
219
|
if (W(e, n, {
|
|
220
220
|
...f,
|
|
221
221
|
isDirty: !1,
|
|
222
222
|
stateSource: "server",
|
|
223
223
|
lastServerSync: i || Date.now()
|
|
224
224
|
}), Array.isArray(l)) {
|
|
225
|
-
const u =
|
|
226
|
-
u?.arrayKeys && u.arrayKeys.forEach((h,
|
|
227
|
-
const t = [...n, h], o = l[
|
|
225
|
+
const u = E(e, n);
|
|
226
|
+
u?.arrayKeys && u.arrayKeys.forEach((h, m) => {
|
|
227
|
+
const t = [...n, h], o = l[m];
|
|
228
228
|
o !== void 0 && oe(
|
|
229
229
|
e,
|
|
230
230
|
t,
|
|
@@ -233,8 +233,8 @@ function oe(e, n, l, i) {
|
|
|
233
233
|
);
|
|
234
234
|
});
|
|
235
235
|
} else l && typeof l == "object" && l.constructor === Object && Object.keys(l).forEach((u) => {
|
|
236
|
-
const h = [...n, u],
|
|
237
|
-
oe(e, h,
|
|
236
|
+
const h = [...n, u], m = l[u];
|
|
237
|
+
oe(e, h, m, i);
|
|
238
238
|
});
|
|
239
239
|
}
|
|
240
240
|
let ie = [], ge = !1;
|
|
@@ -249,45 +249,45 @@ function et(e, n) {
|
|
|
249
249
|
if (!u) return;
|
|
250
250
|
const h = Array.from(u.childNodes);
|
|
251
251
|
if (!h[i]) return;
|
|
252
|
-
let
|
|
252
|
+
let m = n;
|
|
253
253
|
if (f && n !== null)
|
|
254
254
|
try {
|
|
255
|
-
|
|
255
|
+
m = new Function("state", `return (${f})(state)`)(
|
|
256
256
|
n
|
|
257
257
|
);
|
|
258
258
|
} catch (t) {
|
|
259
259
|
console.error("Error evaluating effect function:", t);
|
|
260
260
|
}
|
|
261
|
-
|
|
261
|
+
m !== null && typeof m == "object" && (m = JSON.stringify(m)), h[i].textContent = String(m ?? "");
|
|
262
262
|
});
|
|
263
263
|
}
|
|
264
264
|
function tt(e, n, l) {
|
|
265
|
-
const i =
|
|
265
|
+
const i = E(e, []);
|
|
266
266
|
if (!i?.components)
|
|
267
267
|
return /* @__PURE__ */ new Set();
|
|
268
268
|
const f = /* @__PURE__ */ new Set();
|
|
269
269
|
if (l.type === "update") {
|
|
270
270
|
let u = [...n];
|
|
271
271
|
for (; ; ) {
|
|
272
|
-
const h =
|
|
273
|
-
if (h?.pathComponents && h.pathComponents.forEach((
|
|
274
|
-
const t = i.components?.get(
|
|
272
|
+
const h = E(e, u);
|
|
273
|
+
if (h?.pathComponents && h.pathComponents.forEach((m) => {
|
|
274
|
+
const t = i.components?.get(m);
|
|
275
275
|
t && ((Array.isArray(t.reactiveType) ? t.reactiveType : [t.reactiveType || "component"]).includes("none") || f.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 =
|
|
281
|
-
d?.pathComponents && d.pathComponents.forEach((
|
|
282
|
-
const
|
|
283
|
-
|
|
279
|
+
l.newValue && typeof l.newValue == "object" && !Ce(l.newValue) && _e(l.newValue, l.oldValue).forEach((m) => {
|
|
280
|
+
const t = m.split("."), o = [...n, ...t], d = E(e, o);
|
|
281
|
+
d?.pathComponents && d.pathComponents.forEach(($) => {
|
|
282
|
+
const V = i.components?.get($);
|
|
283
|
+
V && ((Array.isArray(V.reactiveType) ? V.reactiveType : [V.reactiveType || "component"]).includes("none") || f.add(V));
|
|
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" ? n : n.slice(0, -1)];
|
|
288
288
|
for (; ; ) {
|
|
289
|
-
const
|
|
290
|
-
if (
|
|
289
|
+
const m = E(e, h);
|
|
290
|
+
if (m?.pathComponents && m.pathComponents.forEach((t) => {
|
|
291
291
|
const o = i.components?.get(t);
|
|
292
292
|
o && f.add(o);
|
|
293
293
|
}), h.length === 0) break;
|
|
@@ -301,7 +301,7 @@ function rt(e, n, l) {
|
|
|
301
301
|
if (X(i, f))
|
|
302
302
|
return null;
|
|
303
303
|
Le(e, n, f), se(e, n, { bubble: !0 });
|
|
304
|
-
const u =
|
|
304
|
+
const u = E(e, n);
|
|
305
305
|
return {
|
|
306
306
|
type: "update",
|
|
307
307
|
oldValue: i,
|
|
@@ -310,8 +310,8 @@ function rt(e, n, l) {
|
|
|
310
310
|
};
|
|
311
311
|
}
|
|
312
312
|
function nt(e, n, l) {
|
|
313
|
-
|
|
314
|
-
const i =
|
|
313
|
+
be(e, n, l), se(e, n, { bubble: !0 });
|
|
314
|
+
const i = E(e, n);
|
|
315
315
|
return {
|
|
316
316
|
type: "insert_many",
|
|
317
317
|
count: l.length,
|
|
@@ -334,12 +334,12 @@ function at(e, n, l, i, f) {
|
|
|
334
334
|
f
|
|
335
335
|
);
|
|
336
336
|
se(e, n, { bubble: !0 });
|
|
337
|
-
const
|
|
337
|
+
const m = E(e, n);
|
|
338
338
|
let t;
|
|
339
|
-
return
|
|
339
|
+
return m?.arrayKeys && i !== void 0 && i > 0 && (t = m.arrayKeys[i - 1]), {
|
|
340
340
|
type: "insert",
|
|
341
341
|
newValue: u,
|
|
342
|
-
shadowMeta:
|
|
342
|
+
shadowMeta: m,
|
|
343
343
|
path: n,
|
|
344
344
|
itemId: h,
|
|
345
345
|
insertAfterId: t
|
|
@@ -361,8 +361,8 @@ function it() {
|
|
|
361
361
|
f.stateKey,
|
|
362
362
|
f.path,
|
|
363
363
|
f
|
|
364
|
-
).forEach((
|
|
365
|
-
e.add(
|
|
364
|
+
).forEach((m) => {
|
|
365
|
+
e.add(m);
|
|
366
366
|
});
|
|
367
367
|
}
|
|
368
368
|
l.length > 0 && xe(l), n.forEach(({ shadowMeta: i, displayValue: f }) => {
|
|
@@ -375,9 +375,9 @@ function st(e, n, l) {
|
|
|
375
375
|
return (f, u, h) => {
|
|
376
376
|
i(e, u, f, h);
|
|
377
377
|
};
|
|
378
|
-
function i(f, u, h,
|
|
378
|
+
function i(f, u, h, m) {
|
|
379
379
|
let t;
|
|
380
|
-
switch (
|
|
380
|
+
switch (m.updateType) {
|
|
381
381
|
case "update":
|
|
382
382
|
t = rt(f, u, h);
|
|
383
383
|
break;
|
|
@@ -386,8 +386,8 @@ function st(e, n, l) {
|
|
|
386
386
|
f,
|
|
387
387
|
u,
|
|
388
388
|
h,
|
|
389
|
-
|
|
390
|
-
|
|
389
|
+
m.index,
|
|
390
|
+
m.itemId
|
|
391
391
|
);
|
|
392
392
|
break;
|
|
393
393
|
case "insert_many":
|
|
@@ -404,20 +404,20 @@ function st(e, n, l) {
|
|
|
404
404
|
timeStamp: Date.now(),
|
|
405
405
|
stateKey: f,
|
|
406
406
|
path: u,
|
|
407
|
-
updateType:
|
|
407
|
+
updateType: m.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: m.metaData
|
|
414
414
|
};
|
|
415
415
|
ie.push(o), t.newValue !== void 0 && Ze(
|
|
416
416
|
t.newValue,
|
|
417
417
|
f,
|
|
418
418
|
l.current,
|
|
419
419
|
n
|
|
420
|
-
), l.current?.middleware && l.current.middleware({ update: o }), ze(o,
|
|
420
|
+
), l.current?.middleware && l.current.middleware({ update: o }), ze(o, m.validationTrigger || "programmatic"), Ye(o);
|
|
421
421
|
}
|
|
422
422
|
}
|
|
423
423
|
function ct(e, {
|
|
@@ -427,34 +427,34 @@ function ct(e, {
|
|
|
427
427
|
reactiveDeps: f,
|
|
428
428
|
reactiveType: u,
|
|
429
429
|
componentId: h,
|
|
430
|
-
defaultState:
|
|
430
|
+
defaultState: m,
|
|
431
431
|
dependencies: t,
|
|
432
432
|
serverState: o
|
|
433
433
|
} = {}) {
|
|
434
|
-
const [d,
|
|
435
|
-
let
|
|
436
|
-
const [v] = ne(n ?? ae()), _ = q(h ?? ae()),
|
|
434
|
+
const [d, $] = ne({}), { sessionId: V } = Me();
|
|
435
|
+
let T = !n;
|
|
436
|
+
const [v] = ne(n ?? ae()), _ = q(h ?? ae()), P = q(
|
|
437
437
|
null
|
|
438
438
|
);
|
|
439
|
-
|
|
439
|
+
P.current = j(v) ?? null;
|
|
440
440
|
const x = Ie(
|
|
441
|
-
(
|
|
442
|
-
const r =
|
|
441
|
+
(k) => {
|
|
442
|
+
const r = k ? { ...j(v), ...k } : j(v), a = r?.defaultState || m || e;
|
|
443
443
|
if (r?.serverState?.status === "success" && r?.serverState?.data !== void 0)
|
|
444
444
|
return {
|
|
445
445
|
value: r.serverState.data,
|
|
446
446
|
source: "server",
|
|
447
447
|
timestamp: r.serverState.timestamp || Date.now()
|
|
448
448
|
};
|
|
449
|
-
if (r?.localStorage?.key &&
|
|
450
|
-
const S = L(r.localStorage.key) ? r.localStorage.key(a) : r.localStorage.key,
|
|
451
|
-
`${
|
|
449
|
+
if (r?.localStorage?.key && V) {
|
|
450
|
+
const S = L(r.localStorage.key) ? r.localStorage.key(a) : r.localStorage.key, s = ce(
|
|
451
|
+
`${V}-${v}-${S}`
|
|
452
452
|
);
|
|
453
|
-
if (
|
|
453
|
+
if (s && s.lastUpdated > (r?.serverState?.timestamp || 0))
|
|
454
454
|
return {
|
|
455
|
-
value:
|
|
455
|
+
value: s.state,
|
|
456
456
|
source: "localStorage",
|
|
457
|
-
timestamp:
|
|
457
|
+
timestamp: s.lastUpdated
|
|
458
458
|
};
|
|
459
459
|
}
|
|
460
460
|
return {
|
|
@@ -463,31 +463,31 @@ function ct(e, {
|
|
|
463
463
|
timestamp: Date.now()
|
|
464
464
|
};
|
|
465
465
|
},
|
|
466
|
-
[v,
|
|
466
|
+
[v, m, e, V]
|
|
467
467
|
);
|
|
468
468
|
Z(() => {
|
|
469
469
|
o && o.status === "success" && o.data !== void 0 && me(v, o);
|
|
470
|
-
}, [o, v]), Z(() => p.getState().subscribeToPath(v, (
|
|
471
|
-
if (
|
|
472
|
-
const r =
|
|
470
|
+
}, [o, v]), Z(() => p.getState().subscribeToPath(v, (D) => {
|
|
471
|
+
if (D?.type === "SERVER_STATE_UPDATE") {
|
|
472
|
+
const r = D.serverState;
|
|
473
473
|
if (r?.status !== "success" || r.data === void 0)
|
|
474
474
|
return;
|
|
475
475
|
ue(v, { serverState: r });
|
|
476
|
-
const a = typeof r.merge == "object" ? r.merge : r.merge === !0 ? { strategy: "append", key: "id" } : null,
|
|
477
|
-
if (a && a.strategy === "append" && "key" in a && Array.isArray(
|
|
478
|
-
const
|
|
479
|
-
if (!
|
|
476
|
+
const a = typeof r.merge == "object" ? r.merge : r.merge === !0 ? { strategy: "append", key: "id" } : null, c = C(v, []), S = r.data;
|
|
477
|
+
if (a && a.strategy === "append" && "key" in a && Array.isArray(c) && Array.isArray(S)) {
|
|
478
|
+
const s = a.key;
|
|
479
|
+
if (!s) {
|
|
480
480
|
console.error(
|
|
481
481
|
"CogsState: Merge strategy 'append' requires a 'key' field."
|
|
482
482
|
);
|
|
483
483
|
return;
|
|
484
484
|
}
|
|
485
|
-
const
|
|
486
|
-
|
|
485
|
+
const y = new Set(
|
|
486
|
+
c.map((M) => M[s])
|
|
487
487
|
), w = S.filter(
|
|
488
|
-
(M) => !
|
|
488
|
+
(M) => !y.has(M[s])
|
|
489
489
|
);
|
|
490
|
-
w.length > 0 &&
|
|
490
|
+
w.length > 0 && be(v, [], w);
|
|
491
491
|
const A = C(v, []);
|
|
492
492
|
oe(
|
|
493
493
|
v,
|
|
@@ -505,108 +505,108 @@ function ct(e, {
|
|
|
505
505
|
U(v);
|
|
506
506
|
}
|
|
507
507
|
}), [v]), Z(() => {
|
|
508
|
-
const
|
|
509
|
-
if (
|
|
508
|
+
const k = p.getState().getShadowMetadata(v, []);
|
|
509
|
+
if (k && k.stateSource)
|
|
510
510
|
return;
|
|
511
|
-
const
|
|
512
|
-
localStorageEnabled: !!
|
|
511
|
+
const D = j(v), r = {
|
|
512
|
+
localStorageEnabled: !!D?.localStorage?.key
|
|
513
513
|
};
|
|
514
514
|
if (W(v, [], {
|
|
515
|
-
...
|
|
515
|
+
...k,
|
|
516
516
|
features: r
|
|
517
|
-
}),
|
|
518
|
-
const
|
|
519
|
-
|
|
520
|
-
defaultState:
|
|
517
|
+
}), D?.defaultState !== void 0 || m !== void 0) {
|
|
518
|
+
const y = D?.defaultState || m;
|
|
519
|
+
D?.defaultState || ue(v, {
|
|
520
|
+
defaultState: y
|
|
521
521
|
});
|
|
522
522
|
}
|
|
523
|
-
const { value: a, source:
|
|
523
|
+
const { value: a, source: c, timestamp: S } = x();
|
|
524
524
|
K(v, a);
|
|
525
|
-
const
|
|
526
|
-
|
|
527
|
-
stateSource:
|
|
528
|
-
lastServerSync:
|
|
529
|
-
isDirty:
|
|
530
|
-
baseServerState:
|
|
531
|
-
}),
|
|
525
|
+
const s = j(v)?.validation;
|
|
526
|
+
s?.zodSchemaV4 ? H(v, s.zodSchemaV4, "zod4") : s?.zodSchemaV3 && H(v, s.zodSchemaV3, "zod3"), W(v, [], {
|
|
527
|
+
stateSource: c,
|
|
528
|
+
lastServerSync: c === "server" ? S : void 0,
|
|
529
|
+
isDirty: c === "server" ? !1 : void 0,
|
|
530
|
+
baseServerState: c === "server" ? a : void 0
|
|
531
|
+
}), c === "server" && o && me(v, o), U(v);
|
|
532
532
|
}, [v, ...t || []]), re(() => {
|
|
533
|
-
|
|
533
|
+
T && ue(v, {
|
|
534
534
|
formElements: i,
|
|
535
|
-
defaultState:
|
|
535
|
+
defaultState: m,
|
|
536
536
|
localStorage: l,
|
|
537
|
-
middleware:
|
|
537
|
+
middleware: P.current?.middleware
|
|
538
538
|
});
|
|
539
|
-
const
|
|
540
|
-
return r.set(
|
|
541
|
-
forceUpdate: () =>
|
|
539
|
+
const k = `${v}////${_.current}`, D = E(v, []), r = D?.components || /* @__PURE__ */ new Map();
|
|
540
|
+
return r.set(k, {
|
|
541
|
+
forceUpdate: () => $({}),
|
|
542
542
|
reactiveType: u ?? ["component"],
|
|
543
543
|
paths: /* @__PURE__ */ new Set(),
|
|
544
544
|
depsFunction: f || void 0,
|
|
545
545
|
deps: f ? f(C(v, [])) : [],
|
|
546
546
|
prevDeps: f ? f(C(v, [])) : []
|
|
547
547
|
}), W(v, [], {
|
|
548
|
-
...
|
|
548
|
+
...D,
|
|
549
549
|
components: r
|
|
550
|
-
}),
|
|
551
|
-
const a =
|
|
552
|
-
|
|
553
|
-
const
|
|
554
|
-
w?.pathComponents && w.pathComponents.size === 0 && (delete w.pathComponents, p.getState().setShadowMetadata(v,
|
|
550
|
+
}), $({}), () => {
|
|
551
|
+
const a = E(v, []), c = a?.components?.get(k);
|
|
552
|
+
c?.paths && c.paths.forEach((S) => {
|
|
553
|
+
const y = S.split(".").slice(1), w = p.getState().getShadowMetadata(v, y);
|
|
554
|
+
w?.pathComponents && w.pathComponents.size === 0 && (delete w.pathComponents, p.getState().setShadowMetadata(v, y, w));
|
|
555
555
|
}), a?.components && W(v, [], a);
|
|
556
556
|
};
|
|
557
557
|
}, []);
|
|
558
558
|
const G = st(
|
|
559
559
|
v,
|
|
560
|
-
|
|
561
|
-
|
|
560
|
+
V,
|
|
561
|
+
P
|
|
562
562
|
);
|
|
563
|
-
return p.getState().initialStateGlobal[v] ||
|
|
563
|
+
return p.getState().initialStateGlobal[v] || Ve(v, e), Ae(() => Te(
|
|
564
564
|
v,
|
|
565
565
|
G,
|
|
566
566
|
_.current,
|
|
567
|
-
|
|
568
|
-
), [v,
|
|
567
|
+
V
|
|
568
|
+
), [v, V]);
|
|
569
569
|
}
|
|
570
570
|
const lt = (e, n, l) => {
|
|
571
|
-
let i =
|
|
571
|
+
let i = E(e, n)?.arrayKeys || [];
|
|
572
572
|
const f = l?.transforms;
|
|
573
573
|
if (!f || f.length === 0)
|
|
574
574
|
return i;
|
|
575
575
|
for (const u of f)
|
|
576
576
|
if (u.type === "filter") {
|
|
577
577
|
const h = [];
|
|
578
|
-
i.forEach((
|
|
579
|
-
const o = C(e, [...n,
|
|
580
|
-
u.fn(o, t) && h.push(
|
|
578
|
+
i.forEach((m, t) => {
|
|
579
|
+
const o = C(e, [...n, m]);
|
|
580
|
+
u.fn(o, t) && h.push(m);
|
|
581
581
|
}), i = h;
|
|
582
|
-
} else u.type === "sort" && i.sort((h,
|
|
583
|
-
const t = C(e, [...n, h]), o = C(e, [...n,
|
|
582
|
+
} else u.type === "sort" && i.sort((h, m) => {
|
|
583
|
+
const t = C(e, [...n, h]), o = C(e, [...n, m]);
|
|
584
584
|
return u.fn(t, o);
|
|
585
585
|
});
|
|
586
586
|
return i;
|
|
587
587
|
}, te = (e, n, l) => {
|
|
588
|
-
const i = `${e}////${n}`, u =
|
|
588
|
+
const i = `${e}////${n}`, u = E(e, [])?.components?.get(i);
|
|
589
589
|
!u || u.reactiveType === "none" || !(Array.isArray(u.reactiveType) ? u.reactiveType : [u.reactiveType]).includes("component") || Ge(e, l, i);
|
|
590
590
|
}, Y = (e, n, l) => {
|
|
591
|
-
const i =
|
|
592
|
-
i?.components && i.components.forEach((h,
|
|
593
|
-
(Array.isArray(h.reactiveType) ? h.reactiveType : [h.reactiveType || "component"]).includes("all") && (h.forceUpdate(), f.add(
|
|
594
|
-
}),
|
|
591
|
+
const i = E(e, []), f = /* @__PURE__ */ new Set();
|
|
592
|
+
i?.components && i.components.forEach((h, m) => {
|
|
593
|
+
(Array.isArray(h.reactiveType) ? h.reactiveType : [h.reactiveType || "component"]).includes("all") && (h.forceUpdate(), f.add(m));
|
|
594
|
+
}), E(e, [
|
|
595
595
|
...n,
|
|
596
596
|
"getSelected"
|
|
597
597
|
])?.pathComponents?.forEach((h) => {
|
|
598
598
|
i?.components?.get(h)?.forceUpdate();
|
|
599
599
|
});
|
|
600
|
-
const u =
|
|
600
|
+
const u = E(e, n);
|
|
601
601
|
for (let h of u?.arrayKeys || []) {
|
|
602
|
-
const
|
|
602
|
+
const m = h + ".selected", t = E(e, m.split(".").slice(1));
|
|
603
603
|
h == l && t?.pathComponents?.forEach((o) => {
|
|
604
604
|
i?.components?.get(o)?.forceUpdate();
|
|
605
605
|
});
|
|
606
606
|
}
|
|
607
607
|
};
|
|
608
608
|
function N(e, n, l) {
|
|
609
|
-
const i =
|
|
609
|
+
const i = E(e, n), f = n.length > 0 ? n.join(".") : "root", u = l?.arrayViews?.[f];
|
|
610
610
|
if (Array.isArray(u) && u.length === 0)
|
|
611
611
|
return {
|
|
612
612
|
shadowMeta: i,
|
|
@@ -646,29 +646,29 @@ function ft(e, n, l) {
|
|
|
646
646
|
i.style.pointerEvents = l ? "none" : "", i.setAttribute("aria-disabled", String(l));
|
|
647
647
|
});
|
|
648
648
|
}
|
|
649
|
-
function
|
|
649
|
+
function Te(e, n, l, i) {
|
|
650
650
|
const f = /* @__PURE__ */ new Map();
|
|
651
651
|
function u({
|
|
652
652
|
path: t = [],
|
|
653
653
|
meta: o,
|
|
654
654
|
componentId: d
|
|
655
655
|
}) {
|
|
656
|
-
if (
|
|
656
|
+
if (E(e, t)?.isRaw)
|
|
657
657
|
return C(e, t);
|
|
658
|
-
const
|
|
659
|
-
if (f.has(
|
|
660
|
-
return f.get(
|
|
658
|
+
const V = o ? JSON.stringify(o.arrayViews || o.transforms) : "", T = t.join(".") + ":" + d + ":" + V;
|
|
659
|
+
if (f.has(T))
|
|
660
|
+
return f.get(T);
|
|
661
661
|
const v = [e, ...t].join("."), _ = () => {
|
|
662
|
-
},
|
|
663
|
-
apply(G, g,
|
|
664
|
-
if (
|
|
662
|
+
}, P = {
|
|
663
|
+
apply(G, g, k) {
|
|
664
|
+
if (k.length === 0) {
|
|
665
665
|
const r = t.length > 0 ? t.join(".") : "root", a = o?.arrayViews?.[r];
|
|
666
666
|
return te(e, d, t), C(e, t, a);
|
|
667
667
|
}
|
|
668
|
-
const
|
|
669
|
-
return n(
|
|
668
|
+
const D = k[0];
|
|
669
|
+
return n(D, t, { updateType: "update" }), !0;
|
|
670
670
|
},
|
|
671
|
-
get(G, g,
|
|
671
|
+
get(G, g, k) {
|
|
672
672
|
if (g === Symbol.toPrimitive)
|
|
673
673
|
return (r) => r === "number" ? NaN : r === "string" ? `[CogsState: ${t.join(".") || "root"}]` : null;
|
|
674
674
|
if (g === Symbol.toStringTag)
|
|
@@ -681,7 +681,7 @@ function Pe(e, n, l, i) {
|
|
|
681
681
|
} : void 0;
|
|
682
682
|
}
|
|
683
683
|
if (g === "call" || g === "apply" || g === "bind")
|
|
684
|
-
return Reflect.get(G, g,
|
|
684
|
+
return Reflect.get(G, g, k);
|
|
685
685
|
if (typeof g != "string")
|
|
686
686
|
return Reflect.get(G, g);
|
|
687
687
|
if (t.length === 0 && g in h)
|
|
@@ -689,28 +689,28 @@ function Pe(e, n, l, i) {
|
|
|
689
689
|
if (typeof g == "string" && !g.startsWith("$")) {
|
|
690
690
|
const { value: r } = N(e, t, o);
|
|
691
691
|
if (r !== null && typeof r == "object" && !Array.isArray(r) && Object.prototype.hasOwnProperty.call(r, g)) {
|
|
692
|
-
const
|
|
692
|
+
const s = [...t, g];
|
|
693
693
|
return u({
|
|
694
|
-
path:
|
|
694
|
+
path: s,
|
|
695
695
|
componentId: d,
|
|
696
696
|
meta: o
|
|
697
697
|
});
|
|
698
698
|
}
|
|
699
|
-
const
|
|
700
|
-
for (const
|
|
701
|
-
const
|
|
702
|
-
if (
|
|
699
|
+
const c = R.getState().registeredPlugins;
|
|
700
|
+
for (const s of c) {
|
|
701
|
+
const y = s.chainMethods?.[g];
|
|
702
|
+
if (y && ut(t, y.pathPattern) && dt(r, y.target))
|
|
703
703
|
return (...w) => {
|
|
704
|
-
const A = R.getState(), M = A.pluginOptions.get(e)?.get(
|
|
705
|
-
return
|
|
704
|
+
const A = R.getState(), M = A.pluginOptions.get(e)?.get(s.name), I = A.getHookResult(e, s.name);
|
|
705
|
+
return y.handler(
|
|
706
706
|
{
|
|
707
707
|
stateKey: e,
|
|
708
708
|
path: t,
|
|
709
|
-
pluginName:
|
|
709
|
+
pluginName: s.name,
|
|
710
710
|
options: M,
|
|
711
|
-
hookData:
|
|
711
|
+
hookData: I,
|
|
712
712
|
$get: () => N(e, t, o).value,
|
|
713
|
-
$update: (
|
|
713
|
+
$update: (b) => (n(b, t, {
|
|
714
714
|
updateType: "update"
|
|
715
715
|
}), {
|
|
716
716
|
synced: () => {
|
|
@@ -723,19 +723,19 @@ function Pe(e, n, l, i) {
|
|
|
723
723
|
});
|
|
724
724
|
}
|
|
725
725
|
}),
|
|
726
|
-
$applyOperation: (
|
|
727
|
-
n(
|
|
728
|
-
updateType:
|
|
729
|
-
itemId:
|
|
726
|
+
$applyOperation: (b, O) => {
|
|
727
|
+
n(b.newValue, b.path, {
|
|
728
|
+
updateType: b.updateType,
|
|
729
|
+
itemId: b.itemId,
|
|
730
730
|
metaData: O
|
|
731
731
|
});
|
|
732
732
|
},
|
|
733
|
-
getFieldMetaData: () => he(e, t)?.get(
|
|
734
|
-
setFieldMetaData: (
|
|
735
|
-
removeFieldMetaData: () => we(e, t,
|
|
733
|
+
getFieldMetaData: () => he(e, t)?.get(s.name),
|
|
734
|
+
setFieldMetaData: (b) => ve(e, t, s.name, b),
|
|
735
|
+
removeFieldMetaData: () => we(e, t, s.name),
|
|
736
736
|
getFieldRefs: () => Ee(e, t),
|
|
737
737
|
getFieldElements: () => $e(e, t),
|
|
738
|
-
setFieldDisabled: (
|
|
738
|
+
setFieldDisabled: (b) => ft(e, t, b)
|
|
739
739
|
},
|
|
740
740
|
...w
|
|
741
741
|
);
|
|
@@ -755,52 +755,52 @@ function Pe(e, n, l, i) {
|
|
|
755
755
|
const r = p.getState().getInitialOptions(e), a = r?.sync;
|
|
756
756
|
if (!a)
|
|
757
757
|
return console.error(`No mutation defined for state key "${e}"`), { success: !1, error: "No mutation defined" };
|
|
758
|
-
const
|
|
758
|
+
const c = p.getState().getShadowValue(e, []), S = r?.validation?.key;
|
|
759
759
|
try {
|
|
760
|
-
const
|
|
761
|
-
if (
|
|
762
|
-
const
|
|
760
|
+
const s = await a.action(c);
|
|
761
|
+
if (s && !s.success && s.errors, s?.success) {
|
|
762
|
+
const y = p.getState().getShadowMetadata(e, []);
|
|
763
763
|
W(e, [], {
|
|
764
|
-
...
|
|
764
|
+
...y,
|
|
765
765
|
isDirty: !1,
|
|
766
766
|
lastServerSync: Date.now(),
|
|
767
767
|
stateSource: "server",
|
|
768
|
-
baseServerState:
|
|
768
|
+
baseServerState: c
|
|
769
769
|
// Update base server state
|
|
770
|
-
}), a.onSuccess && a.onSuccess(
|
|
771
|
-
} else !
|
|
772
|
-
return
|
|
773
|
-
} catch (
|
|
774
|
-
return a.onError && a.onError(
|
|
770
|
+
}), a.onSuccess && a.onSuccess(s.data);
|
|
771
|
+
} else !s?.success && a.onError && a.onError(s.error);
|
|
772
|
+
return s;
|
|
773
|
+
} catch (s) {
|
|
774
|
+
return a.onError && a.onError(s), { success: !1, error: s };
|
|
775
775
|
}
|
|
776
776
|
};
|
|
777
777
|
if (g === "$_status" || g === "$getStatus") {
|
|
778
778
|
const r = () => {
|
|
779
|
-
const { shadowMeta: a, value:
|
|
780
|
-
return a?.isDirty === !0 ? "dirty" : a?.stateSource === "server" || a?.isDirty === !1 ? "synced" : a?.stateSource === "localStorage" ? "restored" : a?.stateSource === "default" ||
|
|
779
|
+
const { shadowMeta: a, value: c } = N(e, t, o);
|
|
780
|
+
return a?.isDirty === !0 ? "dirty" : a?.stateSource === "server" || a?.isDirty === !1 ? "synced" : a?.stateSource === "localStorage" ? "restored" : a?.stateSource === "default" || c !== void 0 ? "fresh" : "unknown";
|
|
781
781
|
};
|
|
782
782
|
return g === "$_status" ? r() : r;
|
|
783
783
|
}
|
|
784
784
|
if (g === "$removeStorage")
|
|
785
785
|
return () => {
|
|
786
|
-
const r = p.getState().initialStateGlobal[e], a = j(e),
|
|
786
|
+
const r = p.getState().initialStateGlobal[e], a = j(e), c = L(a?.localStorage?.key) ? a.localStorage.key(r) : a?.localStorage?.key, S = i && c ? `${i}-${e}-${c}` : void 0;
|
|
787
787
|
de(S);
|
|
788
788
|
};
|
|
789
789
|
if (g === "$setRaw")
|
|
790
790
|
return (r) => {
|
|
791
|
-
const a =
|
|
791
|
+
const a = E(e, t) || {};
|
|
792
792
|
W(e, t, { ...a, isRaw: !0 }), n(r, t, { updateType: "update" });
|
|
793
793
|
};
|
|
794
794
|
if (g === "$validate")
|
|
795
795
|
return () => {
|
|
796
|
-
const r = p.getState(), { value: a } = N(e, t, o),
|
|
796
|
+
const r = p.getState(), { value: a } = N(e, t, o), c = r.getInitialOptions(e), S = c?.validation?.zodSchemaV4 || c?.validation?.zodSchemaV3;
|
|
797
797
|
if (!S)
|
|
798
798
|
return { success: !0, data: a };
|
|
799
|
-
const
|
|
800
|
-
if (
|
|
801
|
-
const
|
|
799
|
+
const s = S.safeParse(a);
|
|
800
|
+
if (s.success) {
|
|
801
|
+
const y = r.getShadowMetadata(e, t) || {};
|
|
802
802
|
r.setShadowMetadata(e, t, {
|
|
803
|
-
...
|
|
803
|
+
...y,
|
|
804
804
|
validation: {
|
|
805
805
|
status: "VALID",
|
|
806
806
|
errors: [],
|
|
@@ -808,7 +808,7 @@ function Pe(e, n, l, i) {
|
|
|
808
808
|
}
|
|
809
809
|
});
|
|
810
810
|
} else
|
|
811
|
-
(
|
|
811
|
+
(s.error?.issues || s.error?.errors || []).forEach((w) => {
|
|
812
812
|
const A = [...t, ...w.path.map(String)], M = r.getShadowMetadata(e, A) || {};
|
|
813
813
|
r.setShadowMetadata(e, A, {
|
|
814
814
|
...M,
|
|
@@ -827,13 +827,39 @@ function Pe(e, n, l, i) {
|
|
|
827
827
|
}
|
|
828
828
|
});
|
|
829
829
|
});
|
|
830
|
-
return U(e),
|
|
830
|
+
return U(e), s;
|
|
831
831
|
};
|
|
832
832
|
if (g === "$showValidationErrors")
|
|
833
833
|
return () => {
|
|
834
834
|
const { shadowMeta: r } = N(e, t, o);
|
|
835
835
|
return r?.validation?.status === "INVALID" && r.validation.errors.length > 0 ? r.validation.errors.filter((a) => a.severity === "error").map((a) => a.message) : [];
|
|
836
836
|
};
|
|
837
|
+
if (g === "$validationErrors")
|
|
838
|
+
return (r) => {
|
|
839
|
+
const a = p.getState(), c = (s) => {
|
|
840
|
+
const y = a.getShadowMetadata(e, s)?.validation, w = (y?.errors || []).map((b) => ({
|
|
841
|
+
...b,
|
|
842
|
+
path: s
|
|
843
|
+
})), A = w.filter((b) => b.severity === "error"), M = w.filter(
|
|
844
|
+
(b) => b.severity === "warning"
|
|
845
|
+
), I = A.length > 0 ? "error" : M.length > 0 ? "warning" : void 0;
|
|
846
|
+
return {
|
|
847
|
+
status: y?.status || "NOT_VALIDATED",
|
|
848
|
+
severity: I,
|
|
849
|
+
hasErrors: A.length > 0,
|
|
850
|
+
hasWarnings: M.length > 0,
|
|
851
|
+
message: A[0]?.message || M[0]?.message || "",
|
|
852
|
+
errors: A.map((b) => b.message),
|
|
853
|
+
warnings: M.map((b) => b.message),
|
|
854
|
+
allErrors: w,
|
|
855
|
+
path: s,
|
|
856
|
+
getData: () => a.getShadowValue(e, s)
|
|
857
|
+
};
|
|
858
|
+
};
|
|
859
|
+
return (r ?? Object.keys(a.getShadowNode(e, t) ?? {}).filter(
|
|
860
|
+
(s) => s !== "_meta"
|
|
861
|
+
)).map((s) => c([...t, s]));
|
|
862
|
+
};
|
|
837
863
|
if (g === "$getSelected")
|
|
838
864
|
return () => {
|
|
839
865
|
const r = [e, ...t].join(".");
|
|
@@ -844,8 +870,8 @@ function Pe(e, n, l, i) {
|
|
|
844
870
|
const a = p.getState().selectedIndicesMap.get(r);
|
|
845
871
|
if (!a)
|
|
846
872
|
return;
|
|
847
|
-
const
|
|
848
|
-
if (!(S && !S.includes(
|
|
873
|
+
const c = t.join("."), S = o?.arrayViews?.[c], s = a.split(".").pop();
|
|
874
|
+
if (!(S && !S.includes(s) || C(
|
|
849
875
|
e,
|
|
850
876
|
a.split(".").slice(1)
|
|
851
877
|
) === void 0))
|
|
@@ -862,11 +888,11 @@ function Pe(e, n, l, i) {
|
|
|
862
888
|
const a = p.getState().selectedIndicesMap.get(r);
|
|
863
889
|
if (!a)
|
|
864
890
|
return -1;
|
|
865
|
-
const { keys:
|
|
866
|
-
if (!
|
|
891
|
+
const { keys: c } = F(e, t, o);
|
|
892
|
+
if (!c)
|
|
867
893
|
return -1;
|
|
868
894
|
const S = a.split(".").pop();
|
|
869
|
-
return
|
|
895
|
+
return c.indexOf(S);
|
|
870
896
|
};
|
|
871
897
|
if (g === "$clearSelected")
|
|
872
898
|
return Y(e, t), () => {
|
|
@@ -876,20 +902,20 @@ function Pe(e, n, l, i) {
|
|
|
876
902
|
};
|
|
877
903
|
if (g === "$map")
|
|
878
904
|
return (r) => {
|
|
879
|
-
const { value: a, keys:
|
|
905
|
+
const { value: a, keys: c } = F(
|
|
880
906
|
e,
|
|
881
907
|
t,
|
|
882
908
|
o
|
|
883
909
|
);
|
|
884
|
-
if (te(e, d, t), !
|
|
910
|
+
if (te(e, d, t), !c || !Array.isArray(a))
|
|
885
911
|
return [];
|
|
886
912
|
const S = u({
|
|
887
913
|
path: t,
|
|
888
914
|
componentId: d,
|
|
889
915
|
meta: o
|
|
890
916
|
});
|
|
891
|
-
return a.map((
|
|
892
|
-
const w =
|
|
917
|
+
return a.map((s, y) => {
|
|
918
|
+
const w = c[y];
|
|
893
919
|
if (!w) return;
|
|
894
920
|
const A = [...t, w], M = u({
|
|
895
921
|
path: A,
|
|
@@ -897,23 +923,23 @@ function Pe(e, n, l, i) {
|
|
|
897
923
|
componentId: d,
|
|
898
924
|
meta: o
|
|
899
925
|
});
|
|
900
|
-
return r(M,
|
|
926
|
+
return r(M, y, S);
|
|
901
927
|
});
|
|
902
928
|
};
|
|
903
929
|
if (g === "$filter")
|
|
904
930
|
return (r) => {
|
|
905
|
-
const a = t.length > 0 ? t.join(".") : "root", { keys:
|
|
931
|
+
const a = t.length > 0 ? t.join(".") : "root", { keys: c, value: S } = F(
|
|
906
932
|
e,
|
|
907
933
|
t,
|
|
908
934
|
o
|
|
909
935
|
);
|
|
910
936
|
if (!Array.isArray(S))
|
|
911
937
|
throw new Error("filter can only be used on arrays");
|
|
912
|
-
const
|
|
913
|
-
return S.forEach((
|
|
914
|
-
if (r(
|
|
915
|
-
const A =
|
|
916
|
-
A &&
|
|
938
|
+
const s = [];
|
|
939
|
+
return S.forEach((y, w) => {
|
|
940
|
+
if (r(y, w)) {
|
|
941
|
+
const A = c[w];
|
|
942
|
+
A && s.push(A);
|
|
917
943
|
}
|
|
918
944
|
}), u({
|
|
919
945
|
path: t,
|
|
@@ -922,7 +948,7 @@ function Pe(e, n, l, i) {
|
|
|
922
948
|
...o,
|
|
923
949
|
arrayViews: {
|
|
924
950
|
...o?.arrayViews || {},
|
|
925
|
-
[a]:
|
|
951
|
+
[a]: s
|
|
926
952
|
},
|
|
927
953
|
transforms: [
|
|
928
954
|
...o?.transforms || [],
|
|
@@ -933,19 +959,19 @@ function Pe(e, n, l, i) {
|
|
|
933
959
|
};
|
|
934
960
|
if (g === "$sort")
|
|
935
961
|
return (r) => {
|
|
936
|
-
const a = t.length > 0 ? t.join(".") : "root", { value:
|
|
962
|
+
const a = t.length > 0 ? t.join(".") : "root", { value: c, keys: S } = F(
|
|
937
963
|
e,
|
|
938
964
|
t,
|
|
939
965
|
o
|
|
940
966
|
);
|
|
941
|
-
if (!Array.isArray(
|
|
967
|
+
if (!Array.isArray(c) || !S)
|
|
942
968
|
throw new Error("No array keys found for sorting");
|
|
943
|
-
const
|
|
969
|
+
const s = c.map((w, A) => ({
|
|
944
970
|
item: w,
|
|
945
971
|
key: S[A]
|
|
946
972
|
}));
|
|
947
|
-
|
|
948
|
-
const
|
|
973
|
+
s.sort((w, A) => r(w.item, A.item));
|
|
974
|
+
const y = s.map((w) => w.key);
|
|
949
975
|
return u({
|
|
950
976
|
path: t,
|
|
951
977
|
componentId: d,
|
|
@@ -953,7 +979,7 @@ function Pe(e, n, l, i) {
|
|
|
953
979
|
...o,
|
|
954
980
|
arrayViews: {
|
|
955
981
|
...o?.arrayViews || {},
|
|
956
|
-
[a]:
|
|
982
|
+
[a]: y
|
|
957
983
|
},
|
|
958
984
|
transforms: [
|
|
959
985
|
...o?.transforms || [],
|
|
@@ -964,13 +990,13 @@ function Pe(e, n, l, i) {
|
|
|
964
990
|
};
|
|
965
991
|
if (g === "$list")
|
|
966
992
|
return (r) => /* @__PURE__ */ Q(() => {
|
|
967
|
-
const
|
|
993
|
+
const c = q(/* @__PURE__ */ new Map()), [S, s] = ne({}), y = t.length > 0 ? t.join(".") : "root", w = lt(e, t, o), A = Ae(() => ({
|
|
968
994
|
...o,
|
|
969
995
|
arrayViews: {
|
|
970
996
|
...o?.arrayViews || {},
|
|
971
|
-
[
|
|
997
|
+
[y]: w
|
|
972
998
|
}
|
|
973
|
-
}), [o,
|
|
999
|
+
}), [o, y, w]), { value: M } = F(
|
|
974
1000
|
e,
|
|
975
1001
|
t,
|
|
976
1002
|
A
|
|
@@ -983,24 +1009,24 @@ function Pe(e, n, l, i) {
|
|
|
983
1009
|
if (B)
|
|
984
1010
|
for (const ee of B.keys())
|
|
985
1011
|
ee.startsWith(d) && B.delete(ee);
|
|
986
|
-
(z.type === "INSERT" || z.type === "INSERT_MANY" || z.type === "REMOVE" || z.type === "CLEAR_SELECTION" || z.type === "SERVER_STATE_UPDATE" && !o?.serverStateIsUpStream) &&
|
|
1012
|
+
(z.type === "INSERT" || z.type === "INSERT_MANY" || z.type === "REMOVE" || z.type === "CLEAR_SELECTION" || z.type === "SERVER_STATE_UPDATE" && !o?.serverStateIsUpStream) && s({});
|
|
987
1013
|
});
|
|
988
1014
|
return () => {
|
|
989
1015
|
O();
|
|
990
1016
|
};
|
|
991
1017
|
}, [d, v]), !Array.isArray(M))
|
|
992
1018
|
return null;
|
|
993
|
-
const
|
|
1019
|
+
const I = u({
|
|
994
1020
|
path: t,
|
|
995
1021
|
componentId: d,
|
|
996
1022
|
meta: A
|
|
997
1023
|
// Use updated meta here
|
|
998
|
-
}),
|
|
1024
|
+
}), b = M.map((O, z) => {
|
|
999
1025
|
const J = w[z];
|
|
1000
1026
|
if (!J)
|
|
1001
1027
|
return null;
|
|
1002
|
-
let B =
|
|
1003
|
-
B || (B = ae(),
|
|
1028
|
+
let B = c.current.get(J);
|
|
1029
|
+
B || (B = ae(), c.current.set(J, B));
|
|
1004
1030
|
const ee = [...t, J];
|
|
1005
1031
|
return Se(Ue, {
|
|
1006
1032
|
key: J,
|
|
@@ -1008,16 +1034,16 @@ function Pe(e, n, l, i) {
|
|
|
1008
1034
|
itemComponentId: B,
|
|
1009
1035
|
itemPath: ee,
|
|
1010
1036
|
localIndex: z,
|
|
1011
|
-
arraySetter:
|
|
1037
|
+
arraySetter: I,
|
|
1012
1038
|
rebuildStateShape: u,
|
|
1013
1039
|
renderFn: r
|
|
1014
1040
|
});
|
|
1015
1041
|
});
|
|
1016
|
-
return /* @__PURE__ */ Q(
|
|
1042
|
+
return /* @__PURE__ */ Q(Pe, { children: b });
|
|
1017
1043
|
}, {});
|
|
1018
1044
|
if (g === "$stateFlattenOn")
|
|
1019
1045
|
return (r) => {
|
|
1020
|
-
const a = t.length > 0 ? t.join(".") : "root",
|
|
1046
|
+
const a = t.length > 0 ? t.join(".") : "root", c = o?.arrayViews?.[a], S = p.getState().getShadowValue(e, t, c);
|
|
1021
1047
|
return Array.isArray(S) ? u({
|
|
1022
1048
|
path: [...t, "[*]", r],
|
|
1023
1049
|
componentId: d,
|
|
@@ -1026,21 +1052,21 @@ function Pe(e, n, l, i) {
|
|
|
1026
1052
|
};
|
|
1027
1053
|
if (g === "$index")
|
|
1028
1054
|
return (r) => {
|
|
1029
|
-
const a = t.length > 0 ? t.join(".") : "root",
|
|
1030
|
-
if (
|
|
1031
|
-
const
|
|
1032
|
-
return
|
|
1033
|
-
path: [...t,
|
|
1055
|
+
const a = t.length > 0 ? t.join(".") : "root", c = o?.arrayViews?.[a];
|
|
1056
|
+
if (c) {
|
|
1057
|
+
const y = c[r];
|
|
1058
|
+
return y ? u({
|
|
1059
|
+
path: [...t, y],
|
|
1034
1060
|
componentId: d,
|
|
1035
1061
|
meta: o
|
|
1036
1062
|
}) : void 0;
|
|
1037
1063
|
}
|
|
1038
|
-
const S =
|
|
1064
|
+
const S = E(e, t);
|
|
1039
1065
|
if (!S?.arrayKeys) return;
|
|
1040
|
-
const
|
|
1041
|
-
if (
|
|
1066
|
+
const s = S.arrayKeys[r];
|
|
1067
|
+
if (s)
|
|
1042
1068
|
return u({
|
|
1043
|
-
path: [...t,
|
|
1069
|
+
path: [...t, s],
|
|
1044
1070
|
componentId: d,
|
|
1045
1071
|
meta: o
|
|
1046
1072
|
});
|
|
@@ -1053,9 +1079,9 @@ function Pe(e, n, l, i) {
|
|
|
1053
1079
|
const a = r[r.length - 1];
|
|
1054
1080
|
if (!a)
|
|
1055
1081
|
return;
|
|
1056
|
-
const
|
|
1082
|
+
const c = [...t, a];
|
|
1057
1083
|
return u({
|
|
1058
|
-
path:
|
|
1084
|
+
path: c,
|
|
1059
1085
|
componentId: d,
|
|
1060
1086
|
meta: o
|
|
1061
1087
|
});
|
|
@@ -1074,23 +1100,23 @@ function Pe(e, n, l, i) {
|
|
|
1074
1100
|
});
|
|
1075
1101
|
};
|
|
1076
1102
|
if (g === "$uniqueInsert")
|
|
1077
|
-
return (r, a,
|
|
1103
|
+
return (r, a, c) => {
|
|
1078
1104
|
const { value: S } = N(
|
|
1079
1105
|
e,
|
|
1080
1106
|
t,
|
|
1081
1107
|
o
|
|
1082
|
-
),
|
|
1083
|
-
let
|
|
1108
|
+
), s = L(r) ? r(S) : r;
|
|
1109
|
+
let y = null;
|
|
1084
1110
|
if (!S.some((A) => {
|
|
1085
1111
|
const M = a ? a.every(
|
|
1086
|
-
(
|
|
1087
|
-
) : X(A,
|
|
1088
|
-
return M && (
|
|
1112
|
+
(I) => X(A[I], s[I])
|
|
1113
|
+
) : X(A, s);
|
|
1114
|
+
return M && (y = A), M;
|
|
1089
1115
|
}))
|
|
1090
|
-
n(
|
|
1091
|
-
else if (
|
|
1092
|
-
const A =
|
|
1093
|
-
(
|
|
1116
|
+
n(s, t, { updateType: "insert" });
|
|
1117
|
+
else if (c && y) {
|
|
1118
|
+
const A = c(y), M = S.map(
|
|
1119
|
+
(I) => X(I, y) ? A : I
|
|
1094
1120
|
);
|
|
1095
1121
|
n(M, t, {
|
|
1096
1122
|
updateType: "update"
|
|
@@ -1099,11 +1125,11 @@ function Pe(e, n, l, i) {
|
|
|
1099
1125
|
};
|
|
1100
1126
|
if (g === "$cut")
|
|
1101
1127
|
return (r, a) => {
|
|
1102
|
-
const
|
|
1103
|
-
if (!
|
|
1128
|
+
const c = E(e, t);
|
|
1129
|
+
if (!c?.arrayKeys || c.arrayKeys.length === 0)
|
|
1104
1130
|
return;
|
|
1105
|
-
const S = r === -1 ?
|
|
1106
|
-
|
|
1131
|
+
const S = r === -1 ? c.arrayKeys.length - 1 : r !== void 0 ? r : c.arrayKeys.length - 1, s = c.arrayKeys[S];
|
|
1132
|
+
s && n(null, [...t, s], {
|
|
1107
1133
|
updateType: "cut"
|
|
1108
1134
|
});
|
|
1109
1135
|
};
|
|
@@ -1112,16 +1138,16 @@ function Pe(e, n, l, i) {
|
|
|
1112
1138
|
const r = [e, ...t].join("."), { keys: a } = F(e, t, o);
|
|
1113
1139
|
if (!a || a.length === 0)
|
|
1114
1140
|
return;
|
|
1115
|
-
const
|
|
1116
|
-
if (!
|
|
1141
|
+
const c = p.getState().selectedIndicesMap.get(r);
|
|
1142
|
+
if (!c)
|
|
1117
1143
|
return;
|
|
1118
|
-
const S =
|
|
1144
|
+
const S = c.split(".").pop();
|
|
1119
1145
|
if (!a.includes(S))
|
|
1120
1146
|
return;
|
|
1121
|
-
const
|
|
1147
|
+
const s = c.split(".").slice(1);
|
|
1122
1148
|
p.getState().clearSelectedIndex({ arrayKey: r });
|
|
1123
|
-
const
|
|
1124
|
-
Y(e,
|
|
1149
|
+
const y = s.slice(0, -1);
|
|
1150
|
+
Y(e, y), n(null, s, {
|
|
1125
1151
|
updateType: "cut"
|
|
1126
1152
|
});
|
|
1127
1153
|
};
|
|
@@ -1129,12 +1155,12 @@ function Pe(e, n, l, i) {
|
|
|
1129
1155
|
return (r) => {
|
|
1130
1156
|
const {
|
|
1131
1157
|
isArray: a,
|
|
1132
|
-
value:
|
|
1158
|
+
value: c,
|
|
1133
1159
|
keys: S
|
|
1134
1160
|
} = F(e, t, o);
|
|
1135
1161
|
if (!a) return;
|
|
1136
|
-
const
|
|
1137
|
-
|
|
1162
|
+
const s = le(c, S, (y) => y === r);
|
|
1163
|
+
s && n(null, [...t, s.key], {
|
|
1138
1164
|
updateType: "cut"
|
|
1139
1165
|
});
|
|
1140
1166
|
};
|
|
@@ -1142,14 +1168,14 @@ function Pe(e, n, l, i) {
|
|
|
1142
1168
|
return (r) => {
|
|
1143
1169
|
const {
|
|
1144
1170
|
isArray: a,
|
|
1145
|
-
value:
|
|
1171
|
+
value: c,
|
|
1146
1172
|
keys: S
|
|
1147
1173
|
} = F(e, t, o);
|
|
1148
1174
|
if (!a) return;
|
|
1149
|
-
const
|
|
1150
|
-
if (
|
|
1151
|
-
const
|
|
1152
|
-
n(null,
|
|
1175
|
+
const s = le(c, S, (y) => y === r);
|
|
1176
|
+
if (s) {
|
|
1177
|
+
const y = [...t, s.key];
|
|
1178
|
+
n(null, y, {
|
|
1153
1179
|
updateType: "cut"
|
|
1154
1180
|
});
|
|
1155
1181
|
} else
|
|
@@ -1157,16 +1183,16 @@ function Pe(e, n, l, i) {
|
|
|
1157
1183
|
};
|
|
1158
1184
|
if (g === "$findWith")
|
|
1159
1185
|
return (r, a) => {
|
|
1160
|
-
const { isArray:
|
|
1161
|
-
if (!
|
|
1186
|
+
const { isArray: c, value: S, keys: s } = F(e, t, o);
|
|
1187
|
+
if (!c)
|
|
1162
1188
|
throw new Error("findWith can only be used on arrays");
|
|
1163
|
-
const
|
|
1189
|
+
const y = le(
|
|
1164
1190
|
S,
|
|
1165
|
-
|
|
1191
|
+
s,
|
|
1166
1192
|
(w) => w?.[r] === a
|
|
1167
1193
|
);
|
|
1168
|
-
return
|
|
1169
|
-
path: [...t,
|
|
1194
|
+
return y ? u({
|
|
1195
|
+
path: [...t, y.key],
|
|
1170
1196
|
componentId: d,
|
|
1171
1197
|
meta: o
|
|
1172
1198
|
}) : null;
|
|
@@ -1200,45 +1226,45 @@ function Pe(e, n, l, i) {
|
|
|
1200
1226
|
return (r) => ce(i + "-" + e + "-" + r);
|
|
1201
1227
|
if (g === "$isSelected") {
|
|
1202
1228
|
const r = t.slice(0, -1);
|
|
1203
|
-
if (
|
|
1204
|
-
const
|
|
1205
|
-
return S ===
|
|
1229
|
+
if (E(e, r)?.arrayKeys) {
|
|
1230
|
+
const c = e + "." + r.join("."), S = p.getState().selectedIndicesMap.get(c), s = e + "." + t.join(".");
|
|
1231
|
+
return S === s;
|
|
1206
1232
|
}
|
|
1207
1233
|
return;
|
|
1208
1234
|
}
|
|
1209
1235
|
if (g === "$setSelected")
|
|
1210
1236
|
return (r) => {
|
|
1211
|
-
const a = t.slice(0, -1),
|
|
1212
|
-
Y(e, a, void 0), p.getState().selectedIndicesMap.get(
|
|
1237
|
+
const a = t.slice(0, -1), c = e + "." + a.join("."), S = e + "." + t.join(".");
|
|
1238
|
+
Y(e, a, void 0), p.getState().selectedIndicesMap.get(c), r && p.getState().setSelectedIndex(c, S);
|
|
1213
1239
|
};
|
|
1214
1240
|
if (g === "$toggleSelected")
|
|
1215
1241
|
return () => {
|
|
1216
|
-
const r = t.slice(0, -1), a = e + "." + r.join("."),
|
|
1217
|
-
p.getState().selectedIndicesMap.get(a) ===
|
|
1242
|
+
const r = t.slice(0, -1), a = e + "." + r.join("."), c = e + "." + t.join(".");
|
|
1243
|
+
p.getState().selectedIndicesMap.get(a) === c ? p.getState().clearSelectedIndex({ arrayKey: a }) : p.getState().setSelectedIndex(a, c), Y(e, r);
|
|
1218
1244
|
};
|
|
1219
1245
|
if (g === "$clearValidation")
|
|
1220
1246
|
return (r) => {
|
|
1221
|
-
const a = r ? [...t, ...r] : t,
|
|
1247
|
+
const a = r ? [...t, ...r] : t, c = p.getState(), S = c.getShadowNode(e, a);
|
|
1222
1248
|
if (console.log("startNode ", S), !S) return;
|
|
1223
|
-
const
|
|
1224
|
-
for (console.log("stack ",
|
|
1225
|
-
const [
|
|
1226
|
-
if (console.log("while (stack.length ",
|
|
1227
|
-
if (
|
|
1228
|
-
|
|
1249
|
+
const s = [[S, a]];
|
|
1250
|
+
for (console.log("stack ", s); s.length > 0; ) {
|
|
1251
|
+
const [y, w] = s.pop();
|
|
1252
|
+
if (console.log("while (stack.length ", y, w), !y || typeof y != "object") continue;
|
|
1253
|
+
if (y._meta?.validation) {
|
|
1254
|
+
y._meta.validation = {
|
|
1229
1255
|
status: "NOT_VALIDATED",
|
|
1230
1256
|
errors: [],
|
|
1231
1257
|
lastValidated: Date.now(),
|
|
1232
1258
|
validatedValue: void 0
|
|
1233
1259
|
};
|
|
1234
1260
|
const M = [e, ...w].join(".");
|
|
1235
|
-
|
|
1261
|
+
c.notifyPathSubscribers(M, {
|
|
1236
1262
|
type: "VALIDATION_CLEAR"
|
|
1237
1263
|
});
|
|
1238
1264
|
}
|
|
1239
|
-
const A = Object.keys(
|
|
1265
|
+
const A = Object.keys(y);
|
|
1240
1266
|
for (const M of A)
|
|
1241
|
-
M !== "_meta" &&
|
|
1267
|
+
M !== "_meta" && s.push([y[M], [...w, M]]);
|
|
1242
1268
|
}
|
|
1243
1269
|
U(e);
|
|
1244
1270
|
};
|
|
@@ -1250,8 +1276,8 @@ function Pe(e, n, l, i) {
|
|
|
1250
1276
|
fe({ stateKey: e, options: r, initialOptionsPart: {} });
|
|
1251
1277
|
};
|
|
1252
1278
|
if (g === "$_applyUpdate")
|
|
1253
|
-
return (r, a,
|
|
1254
|
-
n(r, a, { updateType:
|
|
1279
|
+
return (r, a, c = "update") => {
|
|
1280
|
+
n(r, a, { updateType: c });
|
|
1255
1281
|
};
|
|
1256
1282
|
if (g === "$_getEffectiveSetState")
|
|
1257
1283
|
return n;
|
|
@@ -1263,11 +1289,11 @@ function Pe(e, n, l, i) {
|
|
|
1263
1289
|
return (r) => we(e, t, r);
|
|
1264
1290
|
if (g === "$addZodValidation")
|
|
1265
1291
|
return (r, a) => {
|
|
1266
|
-
const
|
|
1292
|
+
const c = p.getState();
|
|
1267
1293
|
r.forEach((S) => {
|
|
1268
|
-
const
|
|
1269
|
-
|
|
1270
|
-
...
|
|
1294
|
+
const s = S.path.map(String), y = c.getShadowMetadata(e, s) || {};
|
|
1295
|
+
c.setShadowMetadata(e, s, {
|
|
1296
|
+
...y,
|
|
1271
1297
|
validation: {
|
|
1272
1298
|
status: "INVALID",
|
|
1273
1299
|
errors: [
|
|
@@ -1281,8 +1307,8 @@ function Pe(e, n, l, i) {
|
|
|
1281
1307
|
lastValidated: Date.now(),
|
|
1282
1308
|
validatedValue: void 0
|
|
1283
1309
|
}
|
|
1284
|
-
}),
|
|
1285
|
-
[e, ...
|
|
1310
|
+
}), c.notifyPathSubscribers(
|
|
1311
|
+
[e, ...s].join("."),
|
|
1286
1312
|
{ type: "VALIDATION_UPDATE" }
|
|
1287
1313
|
);
|
|
1288
1314
|
}), U(e);
|
|
@@ -1290,9 +1316,9 @@ function Pe(e, n, l, i) {
|
|
|
1290
1316
|
if (g === "$clearZodValidationPaths")
|
|
1291
1317
|
return (r) => {
|
|
1292
1318
|
const a = p.getState();
|
|
1293
|
-
r.forEach((
|
|
1294
|
-
const S = a.getShadowMetadata(e,
|
|
1295
|
-
S.validation && (a.setShadowMetadata(e,
|
|
1319
|
+
r.forEach((c) => {
|
|
1320
|
+
const S = a.getShadowMetadata(e, c) || {};
|
|
1321
|
+
S.validation && (a.setShadowMetadata(e, c, {
|
|
1296
1322
|
...S,
|
|
1297
1323
|
validation: {
|
|
1298
1324
|
status: "NOT_VALIDATED",
|
|
@@ -1301,53 +1327,53 @@ function Pe(e, n, l, i) {
|
|
|
1301
1327
|
validatedValue: void 0
|
|
1302
1328
|
}
|
|
1303
1329
|
}), a.notifyPathSubscribers(
|
|
1304
|
-
[e, ...
|
|
1330
|
+
[e, ...c].join("."),
|
|
1305
1331
|
{ type: "VALIDATION_CLEAR" }
|
|
1306
1332
|
));
|
|
1307
1333
|
}), U(e);
|
|
1308
1334
|
};
|
|
1309
1335
|
if (g === "$applyOperation")
|
|
1310
1336
|
return (r, a) => {
|
|
1311
|
-
let
|
|
1337
|
+
let c;
|
|
1312
1338
|
if (r.insertAfterId && r.updateType === "insert") {
|
|
1313
|
-
const S =
|
|
1339
|
+
const S = E(e, r.path);
|
|
1314
1340
|
if (S?.arrayKeys) {
|
|
1315
|
-
const
|
|
1341
|
+
const s = S.arrayKeys.indexOf(
|
|
1316
1342
|
r.insertAfterId
|
|
1317
1343
|
);
|
|
1318
|
-
|
|
1344
|
+
s !== -1 && (c = s + 1);
|
|
1319
1345
|
}
|
|
1320
1346
|
}
|
|
1321
1347
|
n(r.newValue, r.path, {
|
|
1322
1348
|
updateType: r.updateType,
|
|
1323
1349
|
itemId: r.itemId,
|
|
1324
|
-
index:
|
|
1350
|
+
index: c,
|
|
1325
1351
|
// Pass the calculated index
|
|
1326
1352
|
metaData: a
|
|
1327
1353
|
});
|
|
1328
1354
|
};
|
|
1329
1355
|
if (g === "$applyJsonPatch")
|
|
1330
1356
|
return (r) => {
|
|
1331
|
-
const a = p.getState(),
|
|
1332
|
-
if (!
|
|
1333
|
-
const S = (
|
|
1334
|
-
for (const
|
|
1335
|
-
const w = S(
|
|
1336
|
-
switch (
|
|
1357
|
+
const a = p.getState(), c = a.getShadowMetadata(e, []);
|
|
1358
|
+
if (!c?.components) return;
|
|
1359
|
+
const S = (y) => !y || y === "/" ? [] : y.split("/").slice(1).map((w) => w.replace(/~1/g, "/").replace(/~0/g, "~")), s = /* @__PURE__ */ new Set();
|
|
1360
|
+
for (const y of r) {
|
|
1361
|
+
const w = S(y.path);
|
|
1362
|
+
switch (y.op) {
|
|
1337
1363
|
case "add":
|
|
1338
1364
|
case "replace": {
|
|
1339
|
-
const { value: A } =
|
|
1365
|
+
const { value: A } = y;
|
|
1340
1366
|
a.updateShadowAtPath(e, w, A), a.markAsDirty(e, w, { bubble: !0 });
|
|
1341
1367
|
let M = [...w];
|
|
1342
1368
|
for (; ; ) {
|
|
1343
|
-
const
|
|
1369
|
+
const I = a.getShadowMetadata(
|
|
1344
1370
|
e,
|
|
1345
1371
|
M
|
|
1346
1372
|
);
|
|
1347
|
-
if (
|
|
1348
|
-
if (!
|
|
1349
|
-
const O =
|
|
1350
|
-
O && (O.forceUpdate(),
|
|
1373
|
+
if (I?.pathComponents && I.pathComponents.forEach((b) => {
|
|
1374
|
+
if (!s.has(b)) {
|
|
1375
|
+
const O = c.components?.get(b);
|
|
1376
|
+
O && (O.forceUpdate(), s.add(b));
|
|
1351
1377
|
}
|
|
1352
1378
|
}), M.length === 0) break;
|
|
1353
1379
|
M.pop();
|
|
@@ -1359,14 +1385,14 @@ function Pe(e, n, l, i) {
|
|
|
1359
1385
|
a.removeShadowArrayElement(e, w), a.markAsDirty(e, A, { bubble: !0 });
|
|
1360
1386
|
let M = [...A];
|
|
1361
1387
|
for (; ; ) {
|
|
1362
|
-
const
|
|
1388
|
+
const I = a.getShadowMetadata(
|
|
1363
1389
|
e,
|
|
1364
1390
|
M
|
|
1365
1391
|
);
|
|
1366
|
-
if (
|
|
1367
|
-
if (!
|
|
1368
|
-
const O =
|
|
1369
|
-
O && (O.forceUpdate(),
|
|
1392
|
+
if (I?.pathComponents && I.pathComponents.forEach((b) => {
|
|
1393
|
+
if (!s.has(b)) {
|
|
1394
|
+
const O = c.components?.get(b);
|
|
1395
|
+
O && (O.forceUpdate(), s.add(b));
|
|
1370
1396
|
}
|
|
1371
1397
|
}), M.length === 0) break;
|
|
1372
1398
|
M.pop();
|
|
@@ -1377,7 +1403,7 @@ function Pe(e, n, l, i) {
|
|
|
1377
1403
|
}
|
|
1378
1404
|
};
|
|
1379
1405
|
if (g === "$getComponents")
|
|
1380
|
-
return () =>
|
|
1406
|
+
return () => E(e, [])?.components;
|
|
1381
1407
|
}
|
|
1382
1408
|
if (g === "$validationWrapper")
|
|
1383
1409
|
return ({
|
|
@@ -1404,8 +1430,8 @@ function Pe(e, n, l, i) {
|
|
|
1404
1430
|
stateSource: "server",
|
|
1405
1431
|
lastServerSync: Date.now()
|
|
1406
1432
|
});
|
|
1407
|
-
const
|
|
1408
|
-
Qe(
|
|
1433
|
+
const c = [e, ...t].join(".");
|
|
1434
|
+
Qe(c, {
|
|
1409
1435
|
type: "SYNC_STATUS_CHANGE",
|
|
1410
1436
|
isDirty: !1
|
|
1411
1437
|
});
|
|
@@ -1427,8 +1453,8 @@ function Pe(e, n, l, i) {
|
|
|
1427
1453
|
}
|
|
1428
1454
|
if (g === "$isolate")
|
|
1429
1455
|
return (r, a) => {
|
|
1430
|
-
const
|
|
1431
|
-
if (!
|
|
1456
|
+
const c = Array.isArray(r), S = c ? r : void 0, s = c ? a : r;
|
|
1457
|
+
if (!s || typeof s != "function")
|
|
1432
1458
|
throw new Error(
|
|
1433
1459
|
"CogsState: $isolate requires a render function."
|
|
1434
1460
|
);
|
|
@@ -1439,7 +1465,7 @@ function Pe(e, n, l, i) {
|
|
|
1439
1465
|
path: t,
|
|
1440
1466
|
dependencies: S,
|
|
1441
1467
|
rebuildStateShape: u,
|
|
1442
|
-
renderFn:
|
|
1468
|
+
renderFn: s
|
|
1443
1469
|
}
|
|
1444
1470
|
);
|
|
1445
1471
|
};
|
|
@@ -1455,15 +1481,15 @@ function Pe(e, n, l, i) {
|
|
|
1455
1481
|
renderFn: r
|
|
1456
1482
|
}
|
|
1457
1483
|
);
|
|
1458
|
-
const
|
|
1484
|
+
const D = [...t, g];
|
|
1459
1485
|
return u({
|
|
1460
|
-
path:
|
|
1486
|
+
path: D,
|
|
1461
1487
|
componentId: d,
|
|
1462
1488
|
meta: o
|
|
1463
1489
|
});
|
|
1464
1490
|
}
|
|
1465
|
-
}, x = new Proxy(_,
|
|
1466
|
-
return f.set(
|
|
1491
|
+
}, x = new Proxy(_, P);
|
|
1492
|
+
return f.set(T, x), x;
|
|
1467
1493
|
}
|
|
1468
1494
|
const h = {
|
|
1469
1495
|
$revertToInitialState: (t) => {
|
|
@@ -1473,21 +1499,21 @@ function Pe(e, n, l, i) {
|
|
|
1473
1499
|
path: [],
|
|
1474
1500
|
componentId: l
|
|
1475
1501
|
});
|
|
1476
|
-
const
|
|
1477
|
-
return de(
|
|
1502
|
+
const $ = j(e), V = L($?.localStorage?.key) ? $?.localStorage?.key(d) : $?.localStorage?.key, T = i && V ? `${i}-${e}-${V}` : void 0;
|
|
1503
|
+
return de(T), U(e), d;
|
|
1478
1504
|
},
|
|
1479
1505
|
$initializeAndMergeShadowState: (t) => {
|
|
1480
1506
|
Re(e, t), U(e);
|
|
1481
1507
|
},
|
|
1482
1508
|
$updateInitialState: (t) => {
|
|
1483
|
-
const o =
|
|
1509
|
+
const o = Te(
|
|
1484
1510
|
e,
|
|
1485
1511
|
n,
|
|
1486
1512
|
l,
|
|
1487
1513
|
i
|
|
1488
|
-
), d = p.getState().initialStateGlobal[e],
|
|
1489
|
-
return de(
|
|
1490
|
-
|
|
1514
|
+
), d = p.getState().initialStateGlobal[e], $ = j(e), V = L($?.localStorage?.key) ? $?.localStorage?.key(d) : $?.localStorage?.key, T = i && V ? `${i}-${e}-${V}` : void 0;
|
|
1515
|
+
return de(T), ke(() => {
|
|
1516
|
+
Ve(e, t), K(e, t);
|
|
1491
1517
|
const v = p.getState().getShadowMetadata(e, []);
|
|
1492
1518
|
v && v?.components?.forEach((_) => {
|
|
1493
1519
|
_.forceUpdate();
|
|
@@ -1508,7 +1534,7 @@ function pe(e) {
|
|
|
1508
1534
|
function gt({
|
|
1509
1535
|
proxy: e
|
|
1510
1536
|
}) {
|
|
1511
|
-
const n = q(null), l = q(null), i = q(!1), f = `${e._stateKey}-${e._path.join(".")}`, u = e._path.length > 0 ? e._path.join(".") : "root", h = e._meta?.arrayViews?.[u],
|
|
1537
|
+
const n = q(null), l = q(null), i = q(!1), f = `${e._stateKey}-${e._path.join(".")}`, u = e._path.length > 0 ? e._path.join(".") : "root", h = e._meta?.arrayViews?.[u], m = C(e._stateKey, e._path, h);
|
|
1512
1538
|
return Z(() => {
|
|
1513
1539
|
const t = n.current;
|
|
1514
1540
|
if (!t || i.current) return;
|
|
@@ -1517,38 +1543,38 @@ function gt({
|
|
|
1517
1543
|
console.warn("Parent element not found for signal", f);
|
|
1518
1544
|
return;
|
|
1519
1545
|
}
|
|
1520
|
-
const d = t.parentElement,
|
|
1521
|
-
let
|
|
1522
|
-
|
|
1546
|
+
const d = t.parentElement, V = Array.from(d.childNodes).indexOf(t);
|
|
1547
|
+
let T = d.getAttribute("data-parent-id");
|
|
1548
|
+
T || (T = `parent-${crypto.randomUUID()}`, d.setAttribute("data-parent-id", T)), l.current = `instance-${crypto.randomUUID()}`;
|
|
1523
1549
|
const v = p.getState().getShadowMetadata(e._stateKey, e._path) || {}, _ = v.signals || [];
|
|
1524
1550
|
_.push({
|
|
1525
1551
|
instanceId: l.current,
|
|
1526
|
-
parentId:
|
|
1527
|
-
position:
|
|
1552
|
+
parentId: T,
|
|
1553
|
+
position: V,
|
|
1528
1554
|
effect: e._effect
|
|
1529
1555
|
}), p.getState().setShadowMetadata(e._stateKey, e._path, {
|
|
1530
1556
|
...v,
|
|
1531
1557
|
signals: _
|
|
1532
1558
|
});
|
|
1533
|
-
let
|
|
1559
|
+
let P = m;
|
|
1534
1560
|
if (e._effect)
|
|
1535
1561
|
try {
|
|
1536
|
-
|
|
1562
|
+
P = new Function(
|
|
1537
1563
|
"state",
|
|
1538
1564
|
`return (${e._effect})(state)`
|
|
1539
|
-
)(
|
|
1565
|
+
)(m);
|
|
1540
1566
|
} catch (G) {
|
|
1541
1567
|
console.error("Error evaluating effect function:", G);
|
|
1542
1568
|
}
|
|
1543
|
-
|
|
1544
|
-
const x = document.createTextNode(String(
|
|
1569
|
+
P !== null && typeof P == "object" && (P = JSON.stringify(P));
|
|
1570
|
+
const x = document.createTextNode(String(P ?? ""));
|
|
1545
1571
|
t.replaceWith(x), i.current = !0;
|
|
1546
1572
|
}, 0);
|
|
1547
1573
|
return () => {
|
|
1548
1574
|
if (clearTimeout(o), l.current) {
|
|
1549
1575
|
const d = p.getState().getShadowMetadata(e._stateKey, e._path) || {};
|
|
1550
1576
|
d.signals && (d.signals = d.signals.filter(
|
|
1551
|
-
(
|
|
1577
|
+
($) => $.instanceId !== l.current
|
|
1552
1578
|
), p.getState().setShadowMetadata(e._stateKey, e._path, d));
|
|
1553
1579
|
}
|
|
1554
1580
|
};
|
|
@@ -1560,7 +1586,7 @@ function gt({
|
|
|
1560
1586
|
}
|
|
1561
1587
|
export {
|
|
1562
1588
|
pe as $cogsSignal,
|
|
1563
|
-
|
|
1589
|
+
bt as createCogsState,
|
|
1564
1590
|
ct as useCogsStateFn
|
|
1565
1591
|
};
|
|
1566
1592
|
//# sourceMappingURL=CogsState.js.map
|