cogsbox-state 0.5.475-canary.6 → 0.5.475-canary.9
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/dist/CogsState.d.ts +5 -2
- package/dist/CogsState.d.ts.map +1 -1
- package/dist/CogsState.jsx +537 -525
- package/dist/CogsState.jsx.map +1 -1
- package/dist/Components.d.ts +5 -6
- package/dist/Components.d.ts.map +1 -1
- package/dist/Components.jsx +171 -164
- package/dist/Components.jsx.map +1 -1
- package/package.json +2 -2
- package/src/CogsState.tsx +53 -21
- package/src/Components.tsx +1 -0
package/dist/CogsState.jsx
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as
|
|
3
|
-
import { pluginStore as
|
|
4
|
-
import { useState as ee, useRef as
|
|
5
|
-
import { transformStateFunc as Ve, isFunction as R, isDeepEqual as
|
|
6
|
-
import { ValidationWrapper as
|
|
2
|
+
import { jsx as Q, Fragment as Me } from "react/jsx-runtime";
|
|
3
|
+
import { pluginStore as q } from "./pluginStore.js";
|
|
4
|
+
import { useState as ee, useRef as x, useCallback as Ae, useEffect as J, useLayoutEffect as $e, useMemo as ye, createElement as ue, startTransition as Ee } from "react";
|
|
5
|
+
import { transformStateFunc as Ve, isFunction as R, isDeepEqual as Z, isArray as Te, getDifferences as be } from "./utility.js";
|
|
6
|
+
import { ValidationWrapper as Ie, IsolatedComponentWrapper as Pe, FormElementWrapper as ke, MemoizedCogsItemWrapper as De } from "./Components.jsx";
|
|
7
7
|
import Ce from "superjson";
|
|
8
8
|
import { v4 as X } from "uuid";
|
|
9
9
|
import { getGlobalStore as p, updateShadowTypeInfo as fe } from "./store.js";
|
|
@@ -12,13 +12,13 @@ import { runValidation as _e } from "./validation.js";
|
|
|
12
12
|
const {
|
|
13
13
|
getInitialOptions: N,
|
|
14
14
|
updateInitialStateGlobal: he,
|
|
15
|
-
getShadowMetadata:
|
|
16
|
-
setShadowMetadata:
|
|
15
|
+
getShadowMetadata: E,
|
|
16
|
+
setShadowMetadata: B,
|
|
17
17
|
getShadowValue: D,
|
|
18
18
|
initializeShadowState: K,
|
|
19
19
|
initializeAndMergeShadowState: Oe,
|
|
20
|
-
updateShadowAtPath:
|
|
21
|
-
insertShadowArrayElement:
|
|
20
|
+
updateShadowAtPath: je,
|
|
21
|
+
insertShadowArrayElement: Ue,
|
|
22
22
|
insertManyShadowArrayElements: ve,
|
|
23
23
|
removeShadowArrayElement: Ne,
|
|
24
24
|
setInitialStateOptions: de,
|
|
@@ -27,28 +27,26 @@ const {
|
|
|
27
27
|
addPathComponent: Fe,
|
|
28
28
|
clearSelectedIndexesForState: ze,
|
|
29
29
|
addStateLog: Re,
|
|
30
|
-
setSyncInfo: wt,
|
|
31
30
|
clearSelectedIndex: Le,
|
|
32
31
|
getSyncInfo: We,
|
|
33
32
|
notifyPathSubscribers: Be,
|
|
34
33
|
getPluginMetaDataMap: Ge,
|
|
35
|
-
setPluginMetaData:
|
|
36
|
-
removePluginMetaData:
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const s = A(e, a);
|
|
34
|
+
setPluginMetaData: qe,
|
|
35
|
+
removePluginMetaData: xe
|
|
36
|
+
} = p.getState(), { notifyUpdate: Je } = q.getState();
|
|
37
|
+
function U(e, a, l) {
|
|
38
|
+
const s = E(e, a);
|
|
41
39
|
if (!!!s?.arrayKeys)
|
|
42
40
|
return { isArray: !1, value: p.getState().getShadowValue(e, a), keys: [] };
|
|
43
|
-
const
|
|
44
|
-
return Array.isArray(
|
|
41
|
+
const c = a.length > 0 ? a.join(".") : "root", h = l?.arrayViews?.[c] ?? s.arrayKeys;
|
|
42
|
+
return Array.isArray(h) && h.length === 0 ? { isArray: !0, value: [], keys: [] } : { isArray: !0, value: p.getState().getShadowValue(e, a, h), keys: h ?? [] };
|
|
45
43
|
}
|
|
46
44
|
function oe(e, a, l) {
|
|
47
45
|
for (let s = 0; s < e.length; s++)
|
|
48
46
|
if (l(e[s], s)) {
|
|
49
|
-
const
|
|
50
|
-
if (
|
|
51
|
-
return { key:
|
|
47
|
+
const S = a[s];
|
|
48
|
+
if (S)
|
|
49
|
+
return { key: S, index: s, value: e[s] };
|
|
52
50
|
}
|
|
53
51
|
return null;
|
|
54
52
|
}
|
|
@@ -64,40 +62,40 @@ function ce({
|
|
|
64
62
|
options: a,
|
|
65
63
|
initialOptionsPart: l
|
|
66
64
|
}) {
|
|
67
|
-
const s = N(e) || {},
|
|
68
|
-
let
|
|
65
|
+
const s = N(e) || {}, S = l[e] || {};
|
|
66
|
+
let c = { ...S, ...s }, h = !1;
|
|
69
67
|
if (a) {
|
|
70
68
|
const u = (t, o) => {
|
|
71
69
|
for (const y in o)
|
|
72
|
-
o.hasOwnProperty(y) && (o[y] instanceof Object && !Array.isArray(o[y]) && t[y] instanceof Object ?
|
|
70
|
+
o.hasOwnProperty(y) && (o[y] instanceof Object && !Array.isArray(o[y]) && t[y] instanceof Object ? Z(t[y], o[y]) || (u(t[y], o[y]), h = !0) : t[y] !== o[y] && (t[y] = o[y], h = !0));
|
|
73
71
|
return t;
|
|
74
72
|
};
|
|
75
|
-
|
|
73
|
+
c = u(c, a);
|
|
76
74
|
}
|
|
77
|
-
if (
|
|
78
|
-
de(e,
|
|
79
|
-
const u = s?.validation?.zodSchemaV4 || s?.validation?.zodSchemaV3, t =
|
|
75
|
+
if (c.validation && (a?.validation?.hasOwnProperty("onBlur") || s?.validation?.hasOwnProperty("onBlur") || S?.validation?.hasOwnProperty("onBlur") || (c.validation.onBlur = "error", h = !0)), h) {
|
|
76
|
+
de(e, c);
|
|
77
|
+
const u = s?.validation?.zodSchemaV4 || s?.validation?.zodSchemaV3, t = c.validation?.zodSchemaV4 && !s?.validation?.zodSchemaV4, o = c.validation?.zodSchemaV3 && !s?.validation?.zodSchemaV3;
|
|
80
78
|
!u && (t || o) && (t ? fe(
|
|
81
79
|
e,
|
|
82
|
-
|
|
80
|
+
c.validation.zodSchemaV4,
|
|
83
81
|
"zod4"
|
|
84
82
|
) : o && fe(
|
|
85
83
|
e,
|
|
86
|
-
|
|
84
|
+
c.validation.zodSchemaV3,
|
|
87
85
|
"zod3"
|
|
88
|
-
),
|
|
86
|
+
), L(e));
|
|
89
87
|
}
|
|
90
|
-
return
|
|
88
|
+
return c;
|
|
91
89
|
}
|
|
92
|
-
function
|
|
90
|
+
function wt(e, a) {
|
|
93
91
|
return {
|
|
94
92
|
...a,
|
|
95
93
|
initialState: e,
|
|
96
94
|
_addStateOptions: !0
|
|
97
95
|
};
|
|
98
96
|
}
|
|
99
|
-
const
|
|
100
|
-
a?.plugins &&
|
|
97
|
+
const pt = (e, a) => {
|
|
98
|
+
a?.plugins && q.getState().setRegisteredPlugins(a.plugins);
|
|
101
99
|
const [l, s] = Ve(e);
|
|
102
100
|
Object.keys(l).forEach((u) => {
|
|
103
101
|
let t = s[u] || {};
|
|
@@ -128,14 +126,14 @@ const Mt = (e, a) => {
|
|
|
128
126
|
}), Object.keys(l).forEach((u) => {
|
|
129
127
|
K(u, l[u]);
|
|
130
128
|
});
|
|
131
|
-
const
|
|
129
|
+
const S = (u, t) => {
|
|
132
130
|
const [o] = ee(t?.componentId ?? X()), y = ce({
|
|
133
131
|
stateKey: u,
|
|
134
132
|
options: t,
|
|
135
133
|
initialOptionsPart: s
|
|
136
|
-
}), $ =
|
|
134
|
+
}), $ = x(y);
|
|
137
135
|
$.current = y;
|
|
138
|
-
const V = D(u, []) || l[u],
|
|
136
|
+
const V = D(u, []) || l[u], b = ot(
|
|
139
137
|
V,
|
|
140
138
|
{
|
|
141
139
|
stateKey: u,
|
|
@@ -151,47 +149,47 @@ const Mt = (e, a) => {
|
|
|
151
149
|
}
|
|
152
150
|
);
|
|
153
151
|
return J(() => {
|
|
154
|
-
t &&
|
|
155
|
-
}, [u, t]), J(() => (
|
|
156
|
-
|
|
157
|
-
}), [u,
|
|
152
|
+
t && q.getState().setPluginOptionsForState(u, t);
|
|
153
|
+
}, [u, t]), J(() => (q.getState().stateHandlers.set(u, b), () => {
|
|
154
|
+
q.getState().stateHandlers.delete(u);
|
|
155
|
+
}), [u, b]), b;
|
|
158
156
|
};
|
|
159
|
-
function
|
|
160
|
-
if (ce({ stateKey: u, options: t, initialOptionsPart: s }), t.localStorage &&
|
|
161
|
-
const y =
|
|
157
|
+
function c(u, t) {
|
|
158
|
+
if (ce({ stateKey: u, options: t, initialOptionsPart: s }), t.localStorage && Qe(u, t), t.formElements) {
|
|
159
|
+
const y = q.getState().registeredPlugins.map(($) => t.formElements.hasOwnProperty($.name) ? {
|
|
162
160
|
...$,
|
|
163
161
|
formWrapper: t.formElements[$.name]
|
|
164
162
|
} : $);
|
|
165
|
-
|
|
163
|
+
q.getState().setRegisteredPlugins(y);
|
|
166
164
|
}
|
|
167
|
-
|
|
165
|
+
L(u);
|
|
168
166
|
}
|
|
169
|
-
function
|
|
167
|
+
function h(u) {
|
|
170
168
|
Object.keys(l).forEach((o) => {
|
|
171
|
-
|
|
169
|
+
c(o, u);
|
|
172
170
|
});
|
|
173
171
|
}
|
|
174
172
|
return {
|
|
175
|
-
useCogsState:
|
|
176
|
-
setCogsOptionsByKey:
|
|
177
|
-
setCogsOptions:
|
|
173
|
+
useCogsState: S,
|
|
174
|
+
setCogsOptionsByKey: c,
|
|
175
|
+
setCogsOptions: h
|
|
178
176
|
};
|
|
179
|
-
}, He = (e, a, l, s,
|
|
177
|
+
}, He = (e, a, l, s, S) => {
|
|
180
178
|
l?.log && console.log(
|
|
181
179
|
"saving to localstorage",
|
|
182
180
|
a,
|
|
183
181
|
l.localStorage?.key,
|
|
184
182
|
s
|
|
185
183
|
);
|
|
186
|
-
const
|
|
187
|
-
if (
|
|
188
|
-
const
|
|
184
|
+
const c = R(l?.localStorage?.key) ? l.localStorage?.key(e) : l?.localStorage?.key;
|
|
185
|
+
if (c && s) {
|
|
186
|
+
const h = `${s}-${a}-${c}`;
|
|
189
187
|
let u;
|
|
190
188
|
try {
|
|
191
|
-
u = ae(
|
|
189
|
+
u = ae(h)?.lastSyncedWithServer;
|
|
192
190
|
} catch {
|
|
193
191
|
}
|
|
194
|
-
const t =
|
|
192
|
+
const t = E(a, []), o = {
|
|
195
193
|
state: e,
|
|
196
194
|
lastUpdated: Date.now(),
|
|
197
195
|
lastSyncedWithServer: u,
|
|
@@ -199,7 +197,7 @@ const Mt = (e, a) => {
|
|
|
199
197
|
baseServerState: t?.baseServerState
|
|
200
198
|
}, y = Ce.serialize(o);
|
|
201
199
|
window.localStorage.setItem(
|
|
202
|
-
|
|
200
|
+
h,
|
|
203
201
|
JSON.stringify(y.json)
|
|
204
202
|
);
|
|
205
203
|
}
|
|
@@ -211,18 +209,18 @@ const Mt = (e, a) => {
|
|
|
211
209
|
} catch (a) {
|
|
212
210
|
return console.error("Error loading from localStorage:", a), null;
|
|
213
211
|
}
|
|
214
|
-
},
|
|
215
|
-
const l = D(e, []), { sessionId: s } = me(),
|
|
216
|
-
if (
|
|
217
|
-
const
|
|
218
|
-
`${s}-${e}-${
|
|
212
|
+
}, Qe = (e, a) => {
|
|
213
|
+
const l = D(e, []), { sessionId: s } = me(), S = R(a?.localStorage?.key) ? a.localStorage.key(l) : a?.localStorage?.key;
|
|
214
|
+
if (S && s) {
|
|
215
|
+
const c = ae(
|
|
216
|
+
`${s}-${e}-${S}`
|
|
219
217
|
);
|
|
220
|
-
if (
|
|
221
|
-
return
|
|
218
|
+
if (c && c.lastUpdated > (c.lastSyncedWithServer || 0))
|
|
219
|
+
return L(e), !0;
|
|
222
220
|
}
|
|
223
221
|
return !1;
|
|
224
|
-
},
|
|
225
|
-
const a =
|
|
222
|
+
}, L = (e) => {
|
|
223
|
+
const a = E(e, []);
|
|
226
224
|
if (!a) return;
|
|
227
225
|
const l = /* @__PURE__ */ new Set();
|
|
228
226
|
a?.components?.forEach((s) => {
|
|
@@ -232,16 +230,16 @@ const Mt = (e, a) => {
|
|
|
232
230
|
});
|
|
233
231
|
};
|
|
234
232
|
function te(e, a, l, s) {
|
|
235
|
-
const
|
|
236
|
-
if (
|
|
237
|
-
...
|
|
233
|
+
const S = E(e, a);
|
|
234
|
+
if (B(e, a, {
|
|
235
|
+
...S,
|
|
238
236
|
isDirty: !1,
|
|
239
237
|
stateSource: "server",
|
|
240
238
|
lastServerSync: s || Date.now()
|
|
241
239
|
}), Array.isArray(l)) {
|
|
242
|
-
const
|
|
243
|
-
|
|
244
|
-
const t = [...a,
|
|
240
|
+
const c = E(e, a);
|
|
241
|
+
c?.arrayKeys && c.arrayKeys.forEach((h, u) => {
|
|
242
|
+
const t = [...a, h], o = l[u];
|
|
245
243
|
o !== void 0 && te(
|
|
246
244
|
e,
|
|
247
245
|
t,
|
|
@@ -249,86 +247,86 @@ function te(e, a, l, s) {
|
|
|
249
247
|
s
|
|
250
248
|
);
|
|
251
249
|
});
|
|
252
|
-
} else l && typeof l == "object" && l.constructor === Object && Object.keys(l).forEach((
|
|
253
|
-
const
|
|
254
|
-
te(e,
|
|
250
|
+
} else l && typeof l == "object" && l.constructor === Object && Object.keys(l).forEach((c) => {
|
|
251
|
+
const h = [...a, c], u = l[c];
|
|
252
|
+
te(e, h, u, s);
|
|
255
253
|
});
|
|
256
254
|
}
|
|
257
255
|
let re = [], le = !1;
|
|
258
|
-
function
|
|
259
|
-
le || (le = !0,
|
|
260
|
-
|
|
256
|
+
function Ye() {
|
|
257
|
+
le || (le = !0, queueMicrotask(() => {
|
|
258
|
+
nt();
|
|
261
259
|
}));
|
|
262
260
|
}
|
|
263
|
-
function
|
|
264
|
-
e?.signals?.length && e.signals.forEach(({ parentId: l, position: s, effect:
|
|
265
|
-
const
|
|
266
|
-
if (!
|
|
267
|
-
const
|
|
268
|
-
if (!
|
|
261
|
+
function Ze(e, a) {
|
|
262
|
+
e?.signals?.length && e.signals.forEach(({ parentId: l, position: s, effect: S }) => {
|
|
263
|
+
const c = document.querySelector(`[data-parent-id="${l}"]`);
|
|
264
|
+
if (!c) return;
|
|
265
|
+
const h = Array.from(c.childNodes);
|
|
266
|
+
if (!h[s]) return;
|
|
269
267
|
let u = a;
|
|
270
|
-
if (
|
|
268
|
+
if (S && a !== null)
|
|
271
269
|
try {
|
|
272
|
-
u = new Function("state", `return (${
|
|
270
|
+
u = new Function("state", `return (${S})(state)`)(
|
|
273
271
|
a
|
|
274
272
|
);
|
|
275
273
|
} catch (t) {
|
|
276
274
|
console.error("Error evaluating effect function:", t);
|
|
277
275
|
}
|
|
278
|
-
u !== null && typeof u == "object" && (u = JSON.stringify(u)),
|
|
276
|
+
u !== null && typeof u == "object" && (u = JSON.stringify(u)), h[s].textContent = String(u ?? "");
|
|
279
277
|
});
|
|
280
278
|
}
|
|
281
279
|
function Xe(e, a, l) {
|
|
282
|
-
const s =
|
|
280
|
+
const s = E(e, []);
|
|
283
281
|
if (!s?.components)
|
|
284
282
|
return /* @__PURE__ */ new Set();
|
|
285
|
-
const
|
|
283
|
+
const S = /* @__PURE__ */ new Set();
|
|
286
284
|
if (l.type === "update") {
|
|
287
|
-
let
|
|
285
|
+
let c = [...a];
|
|
288
286
|
for (; ; ) {
|
|
289
|
-
const
|
|
290
|
-
if (
|
|
287
|
+
const h = E(e, c);
|
|
288
|
+
if (h?.pathComponents && h.pathComponents.forEach((u) => {
|
|
291
289
|
const t = s.components?.get(u);
|
|
292
|
-
t && ((Array.isArray(t.reactiveType) ? t.reactiveType : [t.reactiveType || "component"]).includes("none") ||
|
|
293
|
-
}),
|
|
294
|
-
|
|
290
|
+
t && ((Array.isArray(t.reactiveType) ? t.reactiveType : [t.reactiveType || "component"]).includes("none") || S.add(t));
|
|
291
|
+
}), c.length === 0) break;
|
|
292
|
+
c.pop();
|
|
295
293
|
}
|
|
296
|
-
l.newValue && typeof l.newValue == "object" && !Te(l.newValue) &&
|
|
297
|
-
const t = u.split("."), o = [...a, ...t], y =
|
|
294
|
+
l.newValue && typeof l.newValue == "object" && !Te(l.newValue) && be(l.newValue, l.oldValue).forEach((u) => {
|
|
295
|
+
const t = u.split("."), o = [...a, ...t], y = E(e, o);
|
|
298
296
|
y?.pathComponents && y.pathComponents.forEach(($) => {
|
|
299
297
|
const V = s.components?.get($);
|
|
300
|
-
V && ((Array.isArray(V.reactiveType) ? V.reactiveType : [V.reactiveType || "component"]).includes("none") ||
|
|
298
|
+
V && ((Array.isArray(V.reactiveType) ? V.reactiveType : [V.reactiveType || "component"]).includes("none") || S.add(V));
|
|
301
299
|
});
|
|
302
300
|
});
|
|
303
301
|
} else if (l.type === "insert" || l.type === "cut" || l.type === "insert_many") {
|
|
304
|
-
let
|
|
302
|
+
let h = [...l.type === "insert" ? a : a.slice(0, -1)];
|
|
305
303
|
for (; ; ) {
|
|
306
|
-
const u =
|
|
304
|
+
const u = E(e, h);
|
|
307
305
|
if (u?.pathComponents && u.pathComponents.forEach((t) => {
|
|
308
306
|
const o = s.components?.get(t);
|
|
309
|
-
o &&
|
|
310
|
-
}),
|
|
311
|
-
|
|
307
|
+
o && S.add(o);
|
|
308
|
+
}), h.length === 0) break;
|
|
309
|
+
h.pop();
|
|
312
310
|
}
|
|
313
311
|
}
|
|
314
|
-
return
|
|
312
|
+
return S;
|
|
315
313
|
}
|
|
316
314
|
function Ke(e, a, l) {
|
|
317
|
-
const s = p.getState().getShadowValue(e, a),
|
|
318
|
-
if (
|
|
315
|
+
const s = p.getState().getShadowValue(e, a), S = R(l) ? l(s) : l;
|
|
316
|
+
if (Z(s, S))
|
|
319
317
|
return null;
|
|
320
|
-
|
|
321
|
-
const
|
|
318
|
+
je(e, a, S), ne(e, a, { bubble: !0 });
|
|
319
|
+
const c = E(e, a);
|
|
322
320
|
return {
|
|
323
321
|
type: "update",
|
|
324
322
|
oldValue: s,
|
|
325
|
-
newValue:
|
|
326
|
-
shadowMeta:
|
|
323
|
+
newValue: S,
|
|
324
|
+
shadowMeta: c
|
|
327
325
|
};
|
|
328
326
|
}
|
|
329
327
|
function et(e, a, l) {
|
|
330
328
|
ve(e, a, l), ne(e, a, { bubble: !0 });
|
|
331
|
-
const s =
|
|
329
|
+
const s = E(e, a);
|
|
332
330
|
return {
|
|
333
331
|
type: "insert_many",
|
|
334
332
|
count: l.length,
|
|
@@ -336,29 +334,29 @@ function et(e, a, l) {
|
|
|
336
334
|
path: a
|
|
337
335
|
};
|
|
338
336
|
}
|
|
339
|
-
function tt(e, a, l, s,
|
|
340
|
-
let
|
|
337
|
+
function tt(e, a, l, s, S) {
|
|
338
|
+
let c;
|
|
341
339
|
if (R(l)) {
|
|
342
340
|
const { value: o } = W(e, a);
|
|
343
|
-
|
|
341
|
+
c = l({ state: o });
|
|
344
342
|
} else
|
|
345
|
-
|
|
346
|
-
const
|
|
343
|
+
c = l;
|
|
344
|
+
const h = Ue(
|
|
347
345
|
e,
|
|
348
346
|
a,
|
|
349
|
-
|
|
347
|
+
c,
|
|
350
348
|
s,
|
|
351
|
-
|
|
349
|
+
S
|
|
352
350
|
);
|
|
353
351
|
ne(e, a, { bubble: !0 });
|
|
354
|
-
const u =
|
|
352
|
+
const u = E(e, a);
|
|
355
353
|
let t;
|
|
356
354
|
return u?.arrayKeys && s !== void 0 && s > 0 && (t = u.arrayKeys[s - 1]), {
|
|
357
355
|
type: "insert",
|
|
358
|
-
newValue:
|
|
356
|
+
newValue: c,
|
|
359
357
|
shadowMeta: u,
|
|
360
358
|
path: a,
|
|
361
|
-
itemId:
|
|
359
|
+
itemId: h,
|
|
362
360
|
insertAfterId: t
|
|
363
361
|
};
|
|
364
362
|
}
|
|
@@ -373,54 +371,54 @@ function nt() {
|
|
|
373
371
|
l.push(s);
|
|
374
372
|
continue;
|
|
375
373
|
}
|
|
376
|
-
const
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
374
|
+
const S = s, c = S.type === "cut" ? null : S.newValue;
|
|
375
|
+
S.shadowMeta?.signals?.length > 0 && a.push({ shadowMeta: S.shadowMeta, displayValue: c }), Xe(
|
|
376
|
+
S.stateKey,
|
|
377
|
+
S.path,
|
|
378
|
+
S
|
|
381
379
|
).forEach((u) => {
|
|
382
380
|
e.add(u);
|
|
383
381
|
});
|
|
384
382
|
}
|
|
385
|
-
l.length > 0 && Re(l), a.forEach(({ shadowMeta: s, displayValue:
|
|
386
|
-
|
|
383
|
+
l.length > 0 && Re(l), a.forEach(({ shadowMeta: s, displayValue: S }) => {
|
|
384
|
+
Ze(s, S);
|
|
387
385
|
}), e.forEach((s) => {
|
|
388
386
|
s.forceUpdate();
|
|
389
387
|
}), re = [], le = !1;
|
|
390
388
|
}
|
|
391
389
|
function at(e, a, l) {
|
|
392
|
-
return (
|
|
393
|
-
s(e,
|
|
390
|
+
return (S, c, h) => {
|
|
391
|
+
s(e, c, S, h);
|
|
394
392
|
};
|
|
395
|
-
function s(
|
|
393
|
+
function s(S, c, h, u) {
|
|
396
394
|
let t;
|
|
397
395
|
switch (u.updateType) {
|
|
398
396
|
case "update":
|
|
399
|
-
t = Ke(
|
|
397
|
+
t = Ke(S, c, h);
|
|
400
398
|
break;
|
|
401
399
|
case "insert":
|
|
402
400
|
t = tt(
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
401
|
+
S,
|
|
402
|
+
c,
|
|
403
|
+
h,
|
|
406
404
|
u.index,
|
|
407
405
|
u.itemId
|
|
408
406
|
);
|
|
409
407
|
break;
|
|
410
408
|
case "insert_many":
|
|
411
|
-
t = et(
|
|
409
|
+
t = et(S, c, h);
|
|
412
410
|
break;
|
|
413
411
|
case "cut":
|
|
414
|
-
t = rt(
|
|
412
|
+
t = rt(S, c);
|
|
415
413
|
break;
|
|
416
414
|
}
|
|
417
415
|
if (t === null)
|
|
418
416
|
return;
|
|
419
|
-
t.stateKey =
|
|
417
|
+
t.stateKey = S, t.path = c, re.push(t), Ye();
|
|
420
418
|
const o = {
|
|
421
419
|
timeStamp: Date.now(),
|
|
422
|
-
stateKey:
|
|
423
|
-
path:
|
|
420
|
+
stateKey: S,
|
|
421
|
+
path: c,
|
|
424
422
|
updateType: u.updateType,
|
|
425
423
|
status: "new",
|
|
426
424
|
oldValue: t.oldValue,
|
|
@@ -431,7 +429,7 @@ function at(e, a, l) {
|
|
|
431
429
|
};
|
|
432
430
|
re.push(o), t.newValue !== void 0 && He(
|
|
433
431
|
t.newValue,
|
|
434
|
-
|
|
432
|
+
S,
|
|
435
433
|
l.current,
|
|
436
434
|
a
|
|
437
435
|
), l.current?.middleware && l.current.middleware({ update: o }), _e(o, u.validationTrigger || "programmatic"), Je(o);
|
|
@@ -441,22 +439,22 @@ function ot(e, {
|
|
|
441
439
|
stateKey: a,
|
|
442
440
|
localStorage: l,
|
|
443
441
|
formElements: s,
|
|
444
|
-
reactiveDeps:
|
|
445
|
-
reactiveType:
|
|
446
|
-
componentId:
|
|
442
|
+
reactiveDeps: S,
|
|
443
|
+
reactiveType: c,
|
|
444
|
+
componentId: h,
|
|
447
445
|
defaultState: u,
|
|
448
446
|
dependencies: t,
|
|
449
447
|
serverState: o
|
|
450
448
|
} = {}) {
|
|
451
449
|
const [y, $] = ee({}), { sessionId: V } = me();
|
|
452
|
-
let
|
|
453
|
-
const [v] = ee(a ?? X()), F =
|
|
450
|
+
let b = !a;
|
|
451
|
+
const [v] = ee(a ?? X()), F = x(h ?? X()), C = x(
|
|
454
452
|
null
|
|
455
453
|
);
|
|
456
454
|
C.current = N(v) ?? null;
|
|
457
455
|
const G = Ae(
|
|
458
456
|
(P) => {
|
|
459
|
-
const n = P ? { ...N(v), ...P } : N(v),
|
|
457
|
+
const n = P ? { ...N(v), ...P } : N(v), i = n?.defaultState || u || e;
|
|
460
458
|
if (n?.serverState?.status === "success" && n?.serverState?.data !== void 0)
|
|
461
459
|
return {
|
|
462
460
|
value: n.serverState.data,
|
|
@@ -464,18 +462,18 @@ function ot(e, {
|
|
|
464
462
|
timestamp: n.serverState.timestamp || Date.now()
|
|
465
463
|
};
|
|
466
464
|
if (n?.localStorage?.key && V) {
|
|
467
|
-
const d = R(n.localStorage.key) ? n.localStorage.key(
|
|
465
|
+
const d = R(n.localStorage.key) ? n.localStorage.key(i) : n.localStorage.key, m = ae(
|
|
468
466
|
`${V}-${v}-${d}`
|
|
469
467
|
);
|
|
470
|
-
if (
|
|
468
|
+
if (m && m.lastUpdated > (n?.serverState?.timestamp || 0))
|
|
471
469
|
return {
|
|
472
|
-
value:
|
|
470
|
+
value: m.state,
|
|
473
471
|
source: "localStorage",
|
|
474
|
-
timestamp:
|
|
472
|
+
timestamp: m.lastUpdated
|
|
475
473
|
};
|
|
476
474
|
}
|
|
477
475
|
return {
|
|
478
|
-
value:
|
|
476
|
+
value: i || e,
|
|
479
477
|
source: "default",
|
|
480
478
|
timestamp: Date.now()
|
|
481
479
|
};
|
|
@@ -490,26 +488,26 @@ function ot(e, {
|
|
|
490
488
|
if (n?.status !== "success" || n.data === void 0)
|
|
491
489
|
return;
|
|
492
490
|
se(v, { serverState: n });
|
|
493
|
-
const
|
|
494
|
-
if (
|
|
495
|
-
const
|
|
496
|
-
if (!
|
|
491
|
+
const i = typeof n.merge == "object" ? n.merge : n.merge === !0 ? { strategy: "append", key: "id" } : null, f = D(v, []), d = n.data;
|
|
492
|
+
if (i && i.strategy === "append" && "key" in i && Array.isArray(f) && Array.isArray(d)) {
|
|
493
|
+
const m = i.key;
|
|
494
|
+
if (!m) {
|
|
497
495
|
console.error(
|
|
498
496
|
"CogsState: Merge strategy 'append' requires a 'key' field."
|
|
499
497
|
);
|
|
500
498
|
return;
|
|
501
499
|
}
|
|
502
500
|
const w = new Set(
|
|
503
|
-
|
|
501
|
+
f.map((I) => I[m])
|
|
504
502
|
), M = d.filter(
|
|
505
|
-
(
|
|
503
|
+
(I) => !w.has(I[m])
|
|
506
504
|
);
|
|
507
505
|
M.length > 0 && ve(v, [], M);
|
|
508
|
-
const
|
|
506
|
+
const A = D(v, []);
|
|
509
507
|
te(
|
|
510
508
|
v,
|
|
511
509
|
[],
|
|
512
|
-
|
|
510
|
+
A,
|
|
513
511
|
n.timestamp || Date.now()
|
|
514
512
|
);
|
|
515
513
|
} else
|
|
@@ -519,7 +517,7 @@ function ot(e, {
|
|
|
519
517
|
d,
|
|
520
518
|
n.timestamp || Date.now()
|
|
521
519
|
);
|
|
522
|
-
|
|
520
|
+
L(v);
|
|
523
521
|
}
|
|
524
522
|
}), [v]), J(() => {
|
|
525
523
|
const P = p.getState().getShadowMetadata(v, []);
|
|
@@ -528,126 +526,126 @@ function ot(e, {
|
|
|
528
526
|
const r = N(v), n = {
|
|
529
527
|
localStorageEnabled: !!r?.localStorage?.key
|
|
530
528
|
};
|
|
531
|
-
if (
|
|
529
|
+
if (B(v, [], {
|
|
532
530
|
...P,
|
|
533
531
|
features: n
|
|
534
532
|
}), r?.defaultState !== void 0 || u !== void 0) {
|
|
535
|
-
const
|
|
533
|
+
const m = r?.defaultState || u;
|
|
536
534
|
r?.defaultState || se(v, {
|
|
537
|
-
defaultState:
|
|
535
|
+
defaultState: m
|
|
538
536
|
});
|
|
539
537
|
}
|
|
540
|
-
const { value:
|
|
541
|
-
K(v,
|
|
542
|
-
stateSource:
|
|
543
|
-
lastServerSync:
|
|
544
|
-
isDirty:
|
|
545
|
-
baseServerState:
|
|
546
|
-
}),
|
|
538
|
+
const { value: i, source: f, timestamp: d } = G();
|
|
539
|
+
K(v, i), B(v, [], {
|
|
540
|
+
stateSource: f,
|
|
541
|
+
lastServerSync: f === "server" ? d : void 0,
|
|
542
|
+
isDirty: f === "server" ? !1 : void 0,
|
|
543
|
+
baseServerState: f === "server" ? i : void 0
|
|
544
|
+
}), f === "server" && o && ge(v, o), L(v);
|
|
547
545
|
}, [v, ...t || []]), $e(() => {
|
|
548
|
-
|
|
546
|
+
b && se(v, {
|
|
549
547
|
formElements: s,
|
|
550
548
|
defaultState: u,
|
|
551
549
|
localStorage: l,
|
|
552
550
|
middleware: C.current?.middleware
|
|
553
551
|
});
|
|
554
|
-
const P = `${v}////${F.current}`, r =
|
|
552
|
+
const P = `${v}////${F.current}`, r = E(v, []), n = r?.components || /* @__PURE__ */ new Map();
|
|
555
553
|
return n.set(P, {
|
|
556
554
|
forceUpdate: () => $({}),
|
|
557
|
-
reactiveType:
|
|
555
|
+
reactiveType: c ?? ["component"],
|
|
558
556
|
paths: /* @__PURE__ */ new Set(),
|
|
559
|
-
depsFunction:
|
|
560
|
-
deps:
|
|
561
|
-
prevDeps:
|
|
562
|
-
}),
|
|
557
|
+
depsFunction: S || void 0,
|
|
558
|
+
deps: S ? S(D(v, [])) : [],
|
|
559
|
+
prevDeps: S ? S(D(v, [])) : []
|
|
560
|
+
}), B(v, [], {
|
|
563
561
|
...r,
|
|
564
562
|
components: n
|
|
565
563
|
}), $({}), () => {
|
|
566
|
-
const
|
|
567
|
-
|
|
564
|
+
const i = E(v, []), f = i?.components?.get(P);
|
|
565
|
+
f?.paths && f.paths.forEach((d) => {
|
|
568
566
|
const w = d.split(".").slice(1), M = p.getState().getShadowMetadata(v, w);
|
|
569
567
|
M?.pathComponents && M.pathComponents.size === 0 && (delete M.pathComponents, p.getState().setShadowMetadata(v, w, M));
|
|
570
|
-
}),
|
|
568
|
+
}), i?.components && B(v, [], i);
|
|
571
569
|
};
|
|
572
570
|
}, []);
|
|
573
|
-
const
|
|
571
|
+
const g = at(
|
|
574
572
|
v,
|
|
575
573
|
V,
|
|
576
574
|
C
|
|
577
575
|
);
|
|
578
576
|
return p.getState().initialStateGlobal[v] || he(v, e), ye(() => we(
|
|
579
577
|
v,
|
|
580
|
-
|
|
578
|
+
g,
|
|
581
579
|
F.current,
|
|
582
580
|
V
|
|
583
581
|
), [v, V]);
|
|
584
582
|
}
|
|
585
583
|
const st = (e, a, l) => {
|
|
586
|
-
let s =
|
|
587
|
-
const
|
|
588
|
-
if (!
|
|
584
|
+
let s = E(e, a)?.arrayKeys || [];
|
|
585
|
+
const S = l?.transforms;
|
|
586
|
+
if (!S || S.length === 0)
|
|
589
587
|
return s;
|
|
590
|
-
for (const
|
|
591
|
-
if (
|
|
592
|
-
const
|
|
588
|
+
for (const c of S)
|
|
589
|
+
if (c.type === "filter") {
|
|
590
|
+
const h = [];
|
|
593
591
|
s.forEach((u, t) => {
|
|
594
592
|
const o = D(e, [...a, u]);
|
|
595
|
-
|
|
596
|
-
}), s =
|
|
597
|
-
} else
|
|
598
|
-
const t = D(e, [...a,
|
|
599
|
-
return
|
|
593
|
+
c.fn(o, t) && h.push(u);
|
|
594
|
+
}), s = h;
|
|
595
|
+
} else c.type === "sort" && s.sort((h, u) => {
|
|
596
|
+
const t = D(e, [...a, h]), o = D(e, [...a, u]);
|
|
597
|
+
return c.fn(t, o);
|
|
600
598
|
});
|
|
601
599
|
return s;
|
|
602
600
|
}, ie = (e, a, l) => {
|
|
603
|
-
const s = `${e}////${a}`,
|
|
604
|
-
!
|
|
605
|
-
},
|
|
606
|
-
const s =
|
|
607
|
-
s?.components && s.components.forEach((
|
|
608
|
-
(Array.isArray(
|
|
609
|
-
}),
|
|
601
|
+
const s = `${e}////${a}`, c = E(e, [])?.components?.get(s);
|
|
602
|
+
!c || c.reactiveType === "none" || !(Array.isArray(c.reactiveType) ? c.reactiveType : [c.reactiveType]).includes("component") || Fe(e, l, s);
|
|
603
|
+
}, Y = (e, a, l) => {
|
|
604
|
+
const s = E(e, []), S = /* @__PURE__ */ new Set();
|
|
605
|
+
s?.components && s.components.forEach((h, u) => {
|
|
606
|
+
(Array.isArray(h.reactiveType) ? h.reactiveType : [h.reactiveType || "component"]).includes("all") && (h.forceUpdate(), S.add(u));
|
|
607
|
+
}), E(e, [
|
|
610
608
|
...a,
|
|
611
609
|
"getSelected"
|
|
612
|
-
])?.pathComponents?.forEach((
|
|
613
|
-
s?.components?.get(
|
|
610
|
+
])?.pathComponents?.forEach((h) => {
|
|
611
|
+
s?.components?.get(h)?.forceUpdate();
|
|
614
612
|
});
|
|
615
|
-
const
|
|
616
|
-
for (let
|
|
617
|
-
const u =
|
|
618
|
-
|
|
613
|
+
const c = E(e, a);
|
|
614
|
+
for (let h of c?.arrayKeys || []) {
|
|
615
|
+
const u = h + ".selected", t = E(e, u.split(".").slice(1));
|
|
616
|
+
h == l && t?.pathComponents?.forEach((o) => {
|
|
619
617
|
s?.components?.get(o)?.forceUpdate();
|
|
620
618
|
});
|
|
621
619
|
}
|
|
622
620
|
};
|
|
623
621
|
function W(e, a, l) {
|
|
624
|
-
const s =
|
|
625
|
-
if (Array.isArray(
|
|
622
|
+
const s = E(e, a), S = a.length > 0 ? a.join(".") : "root", c = l?.arrayViews?.[S];
|
|
623
|
+
if (Array.isArray(c) && c.length === 0)
|
|
626
624
|
return {
|
|
627
625
|
shadowMeta: s,
|
|
628
626
|
value: [],
|
|
629
627
|
arrayKeys: s?.arrayKeys
|
|
630
628
|
};
|
|
631
|
-
const
|
|
629
|
+
const h = D(e, a, c);
|
|
632
630
|
return {
|
|
633
631
|
shadowMeta: s,
|
|
634
|
-
value:
|
|
632
|
+
value: h,
|
|
635
633
|
arrayKeys: s?.arrayKeys
|
|
636
634
|
};
|
|
637
635
|
}
|
|
638
636
|
function we(e, a, l, s) {
|
|
639
|
-
const
|
|
640
|
-
function
|
|
637
|
+
const S = /* @__PURE__ */ new Map();
|
|
638
|
+
function c({
|
|
641
639
|
path: t = [],
|
|
642
640
|
meta: o,
|
|
643
641
|
componentId: y
|
|
644
642
|
}) {
|
|
645
643
|
const $ = o ? JSON.stringify(o.arrayViews || o.transforms) : "", V = t.join(".") + ":" + y + ":" + $;
|
|
646
|
-
if (
|
|
647
|
-
return
|
|
648
|
-
const
|
|
644
|
+
if (S.has(V))
|
|
645
|
+
return S.get(V);
|
|
646
|
+
const b = [e, ...t].join("."), v = () => {
|
|
649
647
|
}, F = {
|
|
650
|
-
apply(G,
|
|
648
|
+
apply(G, g, H) {
|
|
651
649
|
if (H.length === 0) {
|
|
652
650
|
const r = t.length > 0 ? t.join(".") : "root", n = o?.arrayViews?.[r];
|
|
653
651
|
return D(e, t, n);
|
|
@@ -655,39 +653,39 @@ function we(e, a, l, s) {
|
|
|
655
653
|
const P = H[0];
|
|
656
654
|
return a(P, t, { updateType: "update" }), !0;
|
|
657
655
|
},
|
|
658
|
-
get(G,
|
|
659
|
-
if (
|
|
660
|
-
return Reflect.get(G,
|
|
661
|
-
if (typeof
|
|
662
|
-
return Reflect.get(G,
|
|
663
|
-
if (t.length === 0 &&
|
|
664
|
-
return
|
|
665
|
-
if (typeof
|
|
666
|
-
const r = [...t,
|
|
667
|
-
return
|
|
656
|
+
get(G, g, H) {
|
|
657
|
+
if (g === "call" || g === "apply" || g === "bind")
|
|
658
|
+
return Reflect.get(G, g, H);
|
|
659
|
+
if (typeof g != "string")
|
|
660
|
+
return Reflect.get(G, g);
|
|
661
|
+
if (t.length === 0 && g in h)
|
|
662
|
+
return h[g];
|
|
663
|
+
if (typeof g == "string" && !g.startsWith("$")) {
|
|
664
|
+
const r = [...t, g];
|
|
665
|
+
return c({
|
|
668
666
|
path: r,
|
|
669
667
|
componentId: y,
|
|
670
668
|
meta: o
|
|
671
669
|
});
|
|
672
670
|
}
|
|
673
|
-
if (
|
|
674
|
-
return
|
|
675
|
-
if (
|
|
671
|
+
if (g === "$_rebuildStateShape")
|
|
672
|
+
return c;
|
|
673
|
+
if (g === "$sync" && t.length === 0)
|
|
676
674
|
return async function() {
|
|
677
675
|
const r = p.getState().getInitialOptions(e), n = r?.sync;
|
|
678
676
|
if (!n)
|
|
679
677
|
return console.error(`No mutation defined for state key "${e}"`), { success: !1, error: "No mutation defined" };
|
|
680
|
-
const
|
|
678
|
+
const i = p.getState().getShadowValue(e, []), f = r?.validation?.key;
|
|
681
679
|
try {
|
|
682
|
-
const d = await n.action(
|
|
680
|
+
const d = await n.action(i);
|
|
683
681
|
if (d && !d.success && d.errors, d?.success) {
|
|
684
|
-
const
|
|
685
|
-
|
|
686
|
-
...
|
|
682
|
+
const m = p.getState().getShadowMetadata(e, []);
|
|
683
|
+
B(e, [], {
|
|
684
|
+
...m,
|
|
687
685
|
isDirty: !1,
|
|
688
686
|
lastServerSync: Date.now(),
|
|
689
687
|
stateSource: "server",
|
|
690
|
-
baseServerState:
|
|
688
|
+
baseServerState: i
|
|
691
689
|
// Update base server state
|
|
692
690
|
}), n.onSuccess && n.onSuccess(d.data);
|
|
693
691
|
} else !d?.success && n.onError && n.onError(d.error);
|
|
@@ -696,28 +694,28 @@ function we(e, a, l, s) {
|
|
|
696
694
|
return n.onError && n.onError(d), { success: !1, error: d };
|
|
697
695
|
}
|
|
698
696
|
};
|
|
699
|
-
if (
|
|
697
|
+
if (g === "$_status" || g === "$getStatus") {
|
|
700
698
|
const r = () => {
|
|
701
|
-
const { shadowMeta: n, value:
|
|
702
|
-
return n?.isDirty === !0 ? "dirty" : n?.stateSource === "server" || n?.isDirty === !1 ? "synced" : n?.stateSource === "localStorage" ? "restored" : n?.stateSource === "default" ||
|
|
699
|
+
const { shadowMeta: n, value: i } = W(e, t, o);
|
|
700
|
+
return n?.isDirty === !0 ? "dirty" : n?.stateSource === "server" || n?.isDirty === !1 ? "synced" : n?.stateSource === "localStorage" ? "restored" : n?.stateSource === "default" || i !== void 0 ? "fresh" : "unknown";
|
|
703
701
|
};
|
|
704
|
-
return
|
|
702
|
+
return g === "$_status" ? r() : r;
|
|
705
703
|
}
|
|
706
|
-
if (
|
|
704
|
+
if (g === "$removeStorage")
|
|
707
705
|
return () => {
|
|
708
|
-
const r = p.getState().initialStateGlobal[e], n = N(e),
|
|
709
|
-
|
|
706
|
+
const r = p.getState().initialStateGlobal[e], n = N(e), i = R(n?.localStorage?.key) ? n.localStorage.key(r) : n?.localStorage?.key, f = `${s}-${e}-${i}`;
|
|
707
|
+
f && localStorage.removeItem(f);
|
|
710
708
|
};
|
|
711
|
-
if (
|
|
709
|
+
if (g === "$validate")
|
|
712
710
|
return () => {
|
|
713
|
-
const r = p.getState(), { value: n } = W(e, t, o),
|
|
714
|
-
if (!
|
|
711
|
+
const r = p.getState(), { value: n } = W(e, t, o), i = r.getInitialOptions(e), f = i?.validation?.zodSchemaV4 || i?.validation?.zodSchemaV3;
|
|
712
|
+
if (!f)
|
|
715
713
|
return { success: !0, data: n };
|
|
716
|
-
const d =
|
|
714
|
+
const d = f.safeParse(n);
|
|
717
715
|
if (d.success) {
|
|
718
|
-
const
|
|
716
|
+
const m = r.getShadowMetadata(e, t) || {};
|
|
719
717
|
r.setShadowMetadata(e, t, {
|
|
720
|
-
...
|
|
718
|
+
...m,
|
|
721
719
|
validation: {
|
|
722
720
|
status: "VALID",
|
|
723
721
|
errors: [],
|
|
@@ -726,9 +724,9 @@ function we(e, a, l, s) {
|
|
|
726
724
|
});
|
|
727
725
|
} else
|
|
728
726
|
(d.error?.issues || d.error?.errors || []).forEach((w) => {
|
|
729
|
-
const M = [...t, ...w.path.map(String)],
|
|
727
|
+
const M = [...t, ...w.path.map(String)], A = r.getShadowMetadata(e, M) || {};
|
|
730
728
|
r.setShadowMetadata(e, M, {
|
|
731
|
-
...
|
|
729
|
+
...A,
|
|
732
730
|
validation: {
|
|
733
731
|
status: "INVALID",
|
|
734
732
|
errors: [
|
|
@@ -744,14 +742,14 @@ function we(e, a, l, s) {
|
|
|
744
742
|
}
|
|
745
743
|
});
|
|
746
744
|
});
|
|
747
|
-
return
|
|
745
|
+
return L(e), d;
|
|
748
746
|
};
|
|
749
|
-
if (
|
|
747
|
+
if (g === "$showValidationErrors")
|
|
750
748
|
return () => {
|
|
751
749
|
const { shadowMeta: r } = W(e, t, o);
|
|
752
750
|
return r?.validation?.status === "INVALID" && r.validation.errors.length > 0 ? r.validation.errors.filter((n) => n.severity === "error").map((n) => n.message) : [];
|
|
753
751
|
};
|
|
754
|
-
if (
|
|
752
|
+
if (g === "$getSelected")
|
|
755
753
|
return () => {
|
|
756
754
|
const r = [e, ...t].join(".");
|
|
757
755
|
ie(e, y, [
|
|
@@ -761,78 +759,78 @@ function we(e, a, l, s) {
|
|
|
761
759
|
const n = p.getState().selectedIndicesMap.get(r);
|
|
762
760
|
if (!n)
|
|
763
761
|
return;
|
|
764
|
-
const
|
|
765
|
-
if (!(
|
|
762
|
+
const i = t.join("."), f = o?.arrayViews?.[i], d = n.split(".").pop();
|
|
763
|
+
if (!(f && !f.includes(d) || D(
|
|
766
764
|
e,
|
|
767
765
|
n.split(".").slice(1)
|
|
768
766
|
) === void 0))
|
|
769
|
-
return
|
|
767
|
+
return c({
|
|
770
768
|
path: n.split(".").slice(1),
|
|
771
769
|
componentId: y,
|
|
772
770
|
meta: o
|
|
773
771
|
});
|
|
774
772
|
};
|
|
775
|
-
if (
|
|
773
|
+
if (g === "$getSelectedIndex")
|
|
776
774
|
return () => {
|
|
777
775
|
const r = e + "." + t.join(".");
|
|
778
776
|
t.join(".");
|
|
779
777
|
const n = p.getState().selectedIndicesMap.get(r);
|
|
780
778
|
if (!n)
|
|
781
779
|
return -1;
|
|
782
|
-
const { keys:
|
|
783
|
-
if (!
|
|
780
|
+
const { keys: i } = U(e, t, o);
|
|
781
|
+
if (!i)
|
|
784
782
|
return -1;
|
|
785
|
-
const
|
|
786
|
-
return
|
|
783
|
+
const f = n.split(".").pop();
|
|
784
|
+
return i.indexOf(f);
|
|
787
785
|
};
|
|
788
|
-
if (
|
|
789
|
-
return
|
|
786
|
+
if (g === "$clearSelected")
|
|
787
|
+
return Y(e, t), () => {
|
|
790
788
|
Le({
|
|
791
789
|
arrayKey: e + "." + t.join(".")
|
|
792
790
|
});
|
|
793
791
|
};
|
|
794
|
-
if (
|
|
792
|
+
if (g === "$map")
|
|
795
793
|
return (r) => {
|
|
796
|
-
const { value: n, keys:
|
|
794
|
+
const { value: n, keys: i } = U(
|
|
797
795
|
e,
|
|
798
796
|
t,
|
|
799
797
|
o
|
|
800
798
|
);
|
|
801
|
-
if (ie(e, y, t), !
|
|
799
|
+
if (ie(e, y, t), !i || !Array.isArray(n))
|
|
802
800
|
return [];
|
|
803
|
-
const
|
|
801
|
+
const f = c({
|
|
804
802
|
path: t,
|
|
805
803
|
componentId: y,
|
|
806
804
|
meta: o
|
|
807
805
|
});
|
|
808
|
-
return n.map((d,
|
|
809
|
-
const w =
|
|
806
|
+
return n.map((d, m) => {
|
|
807
|
+
const w = i[m];
|
|
810
808
|
if (!w) return;
|
|
811
|
-
const M = [...t, w],
|
|
809
|
+
const M = [...t, w], A = c({
|
|
812
810
|
path: M,
|
|
813
811
|
// This now correctly points to the item in the shadow store.
|
|
814
812
|
componentId: y,
|
|
815
813
|
meta: o
|
|
816
814
|
});
|
|
817
|
-
return r(
|
|
815
|
+
return r(A, m, f);
|
|
818
816
|
});
|
|
819
817
|
};
|
|
820
|
-
if (
|
|
818
|
+
if (g === "$filter")
|
|
821
819
|
return (r) => {
|
|
822
|
-
const n = t.length > 0 ? t.join(".") : "root", { keys:
|
|
820
|
+
const n = t.length > 0 ? t.join(".") : "root", { keys: i, value: f } = U(
|
|
823
821
|
e,
|
|
824
822
|
t,
|
|
825
823
|
o
|
|
826
824
|
);
|
|
827
|
-
if (!Array.isArray(
|
|
825
|
+
if (!Array.isArray(f))
|
|
828
826
|
throw new Error("filter can only be used on arrays");
|
|
829
827
|
const d = [];
|
|
830
|
-
return
|
|
831
|
-
if (r(
|
|
832
|
-
const M =
|
|
828
|
+
return f.forEach((m, w) => {
|
|
829
|
+
if (r(m, w)) {
|
|
830
|
+
const M = i[w];
|
|
833
831
|
M && d.push(M);
|
|
834
832
|
}
|
|
835
|
-
}),
|
|
833
|
+
}), c({
|
|
836
834
|
path: t,
|
|
837
835
|
componentId: y,
|
|
838
836
|
meta: {
|
|
@@ -848,29 +846,29 @@ function we(e, a, l, s) {
|
|
|
848
846
|
}
|
|
849
847
|
});
|
|
850
848
|
};
|
|
851
|
-
if (
|
|
849
|
+
if (g === "$sort")
|
|
852
850
|
return (r) => {
|
|
853
|
-
const n = t.length > 0 ? t.join(".") : "root", { value:
|
|
851
|
+
const n = t.length > 0 ? t.join(".") : "root", { value: i, keys: f } = U(
|
|
854
852
|
e,
|
|
855
853
|
t,
|
|
856
854
|
o
|
|
857
855
|
);
|
|
858
|
-
if (!Array.isArray(
|
|
856
|
+
if (!Array.isArray(i) || !f)
|
|
859
857
|
throw new Error("No array keys found for sorting");
|
|
860
|
-
const d =
|
|
858
|
+
const d = i.map((w, M) => ({
|
|
861
859
|
item: w,
|
|
862
|
-
key:
|
|
860
|
+
key: f[M]
|
|
863
861
|
}));
|
|
864
862
|
d.sort((w, M) => r(w.item, M.item));
|
|
865
|
-
const
|
|
866
|
-
return
|
|
863
|
+
const m = d.map((w) => w.key);
|
|
864
|
+
return c({
|
|
867
865
|
path: t,
|
|
868
866
|
componentId: y,
|
|
869
867
|
meta: {
|
|
870
868
|
...o,
|
|
871
869
|
arrayViews: {
|
|
872
870
|
...o?.arrayViews || {},
|
|
873
|
-
[n]:
|
|
871
|
+
[n]: m
|
|
874
872
|
},
|
|
875
873
|
transforms: [
|
|
876
874
|
...o?.transforms || [],
|
|
@@ -879,21 +877,21 @@ function we(e, a, l, s) {
|
|
|
879
877
|
}
|
|
880
878
|
});
|
|
881
879
|
};
|
|
882
|
-
if (
|
|
880
|
+
if (g === "$stream")
|
|
883
881
|
return function(r = {}) {
|
|
884
882
|
const {
|
|
885
883
|
bufferSize: n = 100,
|
|
886
|
-
flushInterval:
|
|
887
|
-
bufferStrategy:
|
|
884
|
+
flushInterval: i = 100,
|
|
885
|
+
bufferStrategy: f = "accumulate",
|
|
888
886
|
store: d,
|
|
889
|
-
onFlush:
|
|
887
|
+
onFlush: m
|
|
890
888
|
} = r;
|
|
891
|
-
let w = [], M = !1,
|
|
892
|
-
const
|
|
889
|
+
let w = [], M = !1, A = null;
|
|
890
|
+
const I = (T) => {
|
|
893
891
|
if (!M) {
|
|
894
|
-
if (
|
|
892
|
+
if (f === "sliding" && w.length >= n)
|
|
895
893
|
w.shift();
|
|
896
|
-
else if (
|
|
894
|
+
else if (f === "dropping" && w.length >= n)
|
|
897
895
|
return;
|
|
898
896
|
w.push(T), w.length >= n && k();
|
|
899
897
|
}
|
|
@@ -901,28 +899,28 @@ function we(e, a, l, s) {
|
|
|
901
899
|
if (w.length === 0) return;
|
|
902
900
|
const T = [...w];
|
|
903
901
|
if (w = [], d) {
|
|
904
|
-
const
|
|
905
|
-
|
|
902
|
+
const j = d(T);
|
|
903
|
+
j !== void 0 && (Array.isArray(j) ? j : [j]).forEach((pe) => {
|
|
906
904
|
a(pe, t, {
|
|
907
905
|
updateType: "insert"
|
|
908
906
|
});
|
|
909
907
|
});
|
|
910
908
|
} else
|
|
911
|
-
T.forEach((
|
|
912
|
-
a(
|
|
909
|
+
T.forEach((j) => {
|
|
910
|
+
a(j, t, {
|
|
913
911
|
updateType: "insert"
|
|
914
912
|
});
|
|
915
913
|
});
|
|
916
|
-
|
|
914
|
+
m?.(T);
|
|
917
915
|
};
|
|
918
|
-
|
|
919
|
-
const O = X(), _ =
|
|
920
|
-
return z.set(O, { buffer: w, flushTimer:
|
|
916
|
+
i > 0 && (A = setInterval(k, i));
|
|
917
|
+
const O = X(), _ = E(e, t) || {}, z = _.streams || /* @__PURE__ */ new Map();
|
|
918
|
+
return z.set(O, { buffer: w, flushTimer: A }), B(e, t, {
|
|
921
919
|
..._,
|
|
922
920
|
streams: z
|
|
923
921
|
}), {
|
|
924
|
-
write: (T) =>
|
|
925
|
-
writeMany: (T) => T.forEach(
|
|
922
|
+
write: (T) => I(T),
|
|
923
|
+
writeMany: (T) => T.forEach(I),
|
|
926
924
|
flush: () => k(),
|
|
927
925
|
pause: () => {
|
|
928
926
|
M = !0;
|
|
@@ -931,301 +929,325 @@ function we(e, a, l, s) {
|
|
|
931
929
|
M = !1, w.length > 0 && k();
|
|
932
930
|
},
|
|
933
931
|
close: () => {
|
|
934
|
-
k(),
|
|
932
|
+
k(), A && clearInterval(A);
|
|
935
933
|
const T = p.getState().getShadowMetadata(e, t);
|
|
936
934
|
T?.streams && T.streams.delete(O);
|
|
937
935
|
}
|
|
938
936
|
};
|
|
939
937
|
};
|
|
940
|
-
if (
|
|
941
|
-
return (r) => /* @__PURE__ */
|
|
942
|
-
const
|
|
938
|
+
if (g === "$list")
|
|
939
|
+
return (r) => /* @__PURE__ */ Q(() => {
|
|
940
|
+
const i = x(/* @__PURE__ */ new Map()), [f, d] = ee({}), m = t.length > 0 ? t.join(".") : "root", w = st(e, t, o), M = ye(() => ({
|
|
943
941
|
...o,
|
|
944
942
|
arrayViews: {
|
|
945
943
|
...o?.arrayViews || {},
|
|
946
|
-
[
|
|
944
|
+
[m]: w
|
|
947
945
|
}
|
|
948
|
-
}), [o,
|
|
946
|
+
}), [o, m, w]), { value: A } = U(
|
|
949
947
|
e,
|
|
950
948
|
t,
|
|
951
949
|
M
|
|
952
950
|
);
|
|
953
951
|
if (J(() => {
|
|
954
|
-
const O = p.getState().subscribeToPath(
|
|
952
|
+
const O = p.getState().subscribeToPath(b, (_) => {
|
|
955
953
|
if (_.type === "GET_SELECTED")
|
|
956
954
|
return;
|
|
957
955
|
const T = p.getState().getShadowMetadata(e, t)?.transformCaches;
|
|
958
956
|
if (T)
|
|
959
|
-
for (const
|
|
960
|
-
|
|
957
|
+
for (const j of T.keys())
|
|
958
|
+
j.startsWith(y) && T.delete(j);
|
|
961
959
|
(_.type === "INSERT" || _.type === "INSERT_MANY" || _.type === "REMOVE" || _.type === "CLEAR_SELECTION" || _.type === "SERVER_STATE_UPDATE" && !o?.serverStateIsUpStream) && d({});
|
|
962
960
|
});
|
|
963
961
|
return () => {
|
|
964
962
|
O();
|
|
965
963
|
};
|
|
966
|
-
}, [y,
|
|
964
|
+
}, [y, b]), !Array.isArray(A))
|
|
967
965
|
return null;
|
|
968
|
-
const
|
|
966
|
+
const I = c({
|
|
969
967
|
path: t,
|
|
970
968
|
componentId: y,
|
|
971
969
|
meta: M
|
|
972
970
|
// Use updated meta here
|
|
973
|
-
}), k =
|
|
971
|
+
}), k = A.map((O, _) => {
|
|
974
972
|
const z = w[_];
|
|
975
973
|
if (!z)
|
|
976
974
|
return null;
|
|
977
|
-
let T =
|
|
978
|
-
T || (T = X(),
|
|
979
|
-
const
|
|
975
|
+
let T = i.current.get(z);
|
|
976
|
+
T || (T = X(), i.current.set(z, T));
|
|
977
|
+
const j = [...t, z];
|
|
980
978
|
return ue(De, {
|
|
981
979
|
key: z,
|
|
982
980
|
stateKey: e,
|
|
983
981
|
itemComponentId: T,
|
|
984
|
-
itemPath:
|
|
982
|
+
itemPath: j,
|
|
985
983
|
localIndex: _,
|
|
986
|
-
arraySetter:
|
|
987
|
-
rebuildStateShape:
|
|
984
|
+
arraySetter: I,
|
|
985
|
+
rebuildStateShape: c,
|
|
988
986
|
renderFn: r
|
|
989
987
|
});
|
|
990
988
|
});
|
|
991
|
-
return /* @__PURE__ */
|
|
989
|
+
return /* @__PURE__ */ Q(Me, { children: k });
|
|
992
990
|
}, {});
|
|
993
|
-
if (
|
|
991
|
+
if (g === "$stateFlattenOn")
|
|
994
992
|
return (r) => {
|
|
995
|
-
const n = t.length > 0 ? t.join(".") : "root",
|
|
996
|
-
return Array.isArray(
|
|
993
|
+
const n = t.length > 0 ? t.join(".") : "root", i = o?.arrayViews?.[n], f = p.getState().getShadowValue(e, t, i);
|
|
994
|
+
return Array.isArray(f) ? c({
|
|
997
995
|
path: [...t, "[*]", r],
|
|
998
996
|
componentId: y,
|
|
999
997
|
meta: o
|
|
1000
998
|
}) : [];
|
|
1001
999
|
};
|
|
1002
|
-
if (
|
|
1000
|
+
if (g === "$index")
|
|
1003
1001
|
return (r) => {
|
|
1004
|
-
const n = t.length > 0 ? t.join(".") : "root",
|
|
1005
|
-
if (
|
|
1006
|
-
const
|
|
1007
|
-
return
|
|
1008
|
-
path: [...t,
|
|
1002
|
+
const n = t.length > 0 ? t.join(".") : "root", i = o?.arrayViews?.[n];
|
|
1003
|
+
if (i) {
|
|
1004
|
+
const m = i[r];
|
|
1005
|
+
return m ? c({
|
|
1006
|
+
path: [...t, m],
|
|
1009
1007
|
componentId: y,
|
|
1010
1008
|
meta: o
|
|
1011
1009
|
}) : void 0;
|
|
1012
1010
|
}
|
|
1013
|
-
const
|
|
1014
|
-
if (!
|
|
1015
|
-
const d =
|
|
1011
|
+
const f = E(e, t);
|
|
1012
|
+
if (!f?.arrayKeys) return;
|
|
1013
|
+
const d = f.arrayKeys[r];
|
|
1016
1014
|
if (d)
|
|
1017
|
-
return
|
|
1015
|
+
return c({
|
|
1018
1016
|
path: [...t, d],
|
|
1019
1017
|
componentId: y,
|
|
1020
1018
|
meta: o
|
|
1021
1019
|
});
|
|
1022
1020
|
};
|
|
1023
|
-
if (
|
|
1021
|
+
if (g === "$last")
|
|
1024
1022
|
return () => {
|
|
1025
|
-
const { keys: r } =
|
|
1023
|
+
const { keys: r } = U(e, t, o);
|
|
1026
1024
|
if (!r || r.length === 0)
|
|
1027
1025
|
return;
|
|
1028
1026
|
const n = r[r.length - 1];
|
|
1029
1027
|
if (!n)
|
|
1030
1028
|
return;
|
|
1031
|
-
const
|
|
1032
|
-
return
|
|
1033
|
-
path:
|
|
1029
|
+
const i = [...t, n];
|
|
1030
|
+
return c({
|
|
1031
|
+
path: i,
|
|
1034
1032
|
componentId: y,
|
|
1035
1033
|
meta: o
|
|
1036
1034
|
});
|
|
1037
1035
|
};
|
|
1038
|
-
if (
|
|
1036
|
+
if (g === "$insert")
|
|
1039
1037
|
return (r, n) => {
|
|
1040
1038
|
a(r, t, {
|
|
1041
1039
|
updateType: "insert",
|
|
1042
1040
|
index: n
|
|
1043
1041
|
});
|
|
1044
1042
|
};
|
|
1045
|
-
if (
|
|
1043
|
+
if (g === "$insertMany")
|
|
1046
1044
|
return (r) => {
|
|
1047
1045
|
a(r, t, {
|
|
1048
1046
|
updateType: "insert_many"
|
|
1049
1047
|
});
|
|
1050
1048
|
};
|
|
1051
|
-
if (
|
|
1052
|
-
return (r, n,
|
|
1053
|
-
const { value:
|
|
1049
|
+
if (g === "$uniqueInsert")
|
|
1050
|
+
return (r, n, i) => {
|
|
1051
|
+
const { value: f } = W(
|
|
1054
1052
|
e,
|
|
1055
1053
|
t,
|
|
1056
1054
|
o
|
|
1057
|
-
), d = R(r) ? r(
|
|
1058
|
-
let
|
|
1059
|
-
if (!
|
|
1060
|
-
const
|
|
1061
|
-
(
|
|
1062
|
-
) :
|
|
1063
|
-
return
|
|
1055
|
+
), d = R(r) ? r(f) : r;
|
|
1056
|
+
let m = null;
|
|
1057
|
+
if (!f.some((M) => {
|
|
1058
|
+
const A = n ? n.every(
|
|
1059
|
+
(I) => Z(M[I], d[I])
|
|
1060
|
+
) : Z(M, d);
|
|
1061
|
+
return A && (m = M), A;
|
|
1064
1062
|
}))
|
|
1065
1063
|
a(d, t, { updateType: "insert" });
|
|
1066
|
-
else if (
|
|
1067
|
-
const M =
|
|
1068
|
-
(
|
|
1064
|
+
else if (i && m) {
|
|
1065
|
+
const M = i(m), A = f.map(
|
|
1066
|
+
(I) => Z(I, m) ? M : I
|
|
1069
1067
|
);
|
|
1070
|
-
a(
|
|
1068
|
+
a(A, t, {
|
|
1071
1069
|
updateType: "update"
|
|
1072
1070
|
});
|
|
1073
1071
|
}
|
|
1074
1072
|
};
|
|
1075
|
-
if (
|
|
1073
|
+
if (g === "$cut")
|
|
1076
1074
|
return (r, n) => {
|
|
1077
|
-
const
|
|
1078
|
-
if (
|
|
1075
|
+
const i = E(e, t);
|
|
1076
|
+
if (!i?.arrayKeys || i.arrayKeys.length === 0)
|
|
1079
1077
|
return;
|
|
1080
|
-
const
|
|
1081
|
-
|
|
1082
|
-
const d = c.arrayKeys[S];
|
|
1083
|
-
d && (console.log("idToCut ->>>>>>>>>>>>>>>>", d), a(null, [...t, d], {
|
|
1078
|
+
const f = r === -1 ? i.arrayKeys.length - 1 : r !== void 0 ? r : i.arrayKeys.length - 1, d = i.arrayKeys[f];
|
|
1079
|
+
d && a(null, [...t, d], {
|
|
1084
1080
|
updateType: "cut"
|
|
1085
|
-
})
|
|
1081
|
+
});
|
|
1086
1082
|
};
|
|
1087
|
-
if (
|
|
1083
|
+
if (g === "$cutSelected")
|
|
1088
1084
|
return () => {
|
|
1089
|
-
const r = [e, ...t].join("."), { keys: n } =
|
|
1085
|
+
const r = [e, ...t].join("."), { keys: n } = U(e, t, o);
|
|
1090
1086
|
if (!n || n.length === 0)
|
|
1091
1087
|
return;
|
|
1092
|
-
const
|
|
1093
|
-
if (!
|
|
1088
|
+
const i = p.getState().selectedIndicesMap.get(r);
|
|
1089
|
+
if (!i)
|
|
1094
1090
|
return;
|
|
1095
|
-
const
|
|
1096
|
-
if (!n.includes(
|
|
1091
|
+
const f = i.split(".").pop();
|
|
1092
|
+
if (!n.includes(f))
|
|
1097
1093
|
return;
|
|
1098
|
-
const d =
|
|
1094
|
+
const d = i.split(".").slice(1);
|
|
1099
1095
|
p.getState().clearSelectedIndex({ arrayKey: r });
|
|
1100
|
-
const
|
|
1101
|
-
|
|
1096
|
+
const m = d.slice(0, -1);
|
|
1097
|
+
Y(e, m), a(null, d, {
|
|
1102
1098
|
updateType: "cut"
|
|
1103
1099
|
});
|
|
1104
1100
|
};
|
|
1105
|
-
if (
|
|
1101
|
+
if (g === "$cutByValue")
|
|
1106
1102
|
return (r) => {
|
|
1107
1103
|
const {
|
|
1108
1104
|
isArray: n,
|
|
1109
|
-
value:
|
|
1110
|
-
keys:
|
|
1111
|
-
} =
|
|
1105
|
+
value: i,
|
|
1106
|
+
keys: f
|
|
1107
|
+
} = U(e, t, o);
|
|
1112
1108
|
if (!n) return;
|
|
1113
|
-
const d = oe(
|
|
1109
|
+
const d = oe(i, f, (m) => m === r);
|
|
1114
1110
|
d && a(null, [...t, d.key], {
|
|
1115
1111
|
updateType: "cut"
|
|
1116
1112
|
});
|
|
1117
1113
|
};
|
|
1118
|
-
if (
|
|
1114
|
+
if (g === "$toggleByValue")
|
|
1119
1115
|
return (r) => {
|
|
1120
1116
|
const {
|
|
1121
1117
|
isArray: n,
|
|
1122
|
-
value:
|
|
1123
|
-
keys:
|
|
1124
|
-
} =
|
|
1118
|
+
value: i,
|
|
1119
|
+
keys: f
|
|
1120
|
+
} = U(e, t, o);
|
|
1125
1121
|
if (!n) return;
|
|
1126
|
-
const d = oe(
|
|
1122
|
+
const d = oe(i, f, (m) => m === r);
|
|
1127
1123
|
if (d) {
|
|
1128
|
-
const
|
|
1129
|
-
a(null,
|
|
1124
|
+
const m = [...t, d.key];
|
|
1125
|
+
a(null, m, {
|
|
1130
1126
|
updateType: "cut"
|
|
1131
1127
|
});
|
|
1132
1128
|
} else
|
|
1133
1129
|
a(r, t, { updateType: "insert" });
|
|
1134
1130
|
};
|
|
1135
|
-
if (
|
|
1131
|
+
if (g === "$findWith")
|
|
1136
1132
|
return (r, n) => {
|
|
1137
|
-
const { isArray:
|
|
1138
|
-
if (!
|
|
1133
|
+
const { isArray: i, value: f, keys: d } = U(e, t, o);
|
|
1134
|
+
if (!i)
|
|
1139
1135
|
throw new Error("findWith can only be used on arrays");
|
|
1140
|
-
const
|
|
1141
|
-
|
|
1136
|
+
const m = oe(
|
|
1137
|
+
f,
|
|
1142
1138
|
d,
|
|
1143
1139
|
(w) => w?.[r] === n
|
|
1144
1140
|
);
|
|
1145
|
-
return
|
|
1146
|
-
path: [...t,
|
|
1141
|
+
return m ? c({
|
|
1142
|
+
path: [...t, m.key],
|
|
1147
1143
|
componentId: y,
|
|
1148
1144
|
meta: o
|
|
1149
1145
|
}) : null;
|
|
1150
1146
|
};
|
|
1151
|
-
if (
|
|
1147
|
+
if (g === "$cutThis") {
|
|
1152
1148
|
const { value: r } = W(e, t, o), n = t.slice(0, -1);
|
|
1153
|
-
return
|
|
1149
|
+
return Y(e, n), () => {
|
|
1154
1150
|
a(r, t, { updateType: "cut" });
|
|
1155
1151
|
};
|
|
1156
1152
|
}
|
|
1157
|
-
if (
|
|
1153
|
+
if (g === "$get")
|
|
1158
1154
|
return () => {
|
|
1159
1155
|
ie(e, y, t);
|
|
1160
1156
|
const { value: r } = W(e, t, o);
|
|
1161
1157
|
return r;
|
|
1162
1158
|
};
|
|
1163
|
-
if (
|
|
1159
|
+
if (g === "$$derive")
|
|
1164
1160
|
return (r) => Se({
|
|
1165
1161
|
_stateKey: e,
|
|
1166
1162
|
_path: t,
|
|
1167
1163
|
_effect: r.toString(),
|
|
1168
1164
|
_meta: o
|
|
1169
1165
|
});
|
|
1170
|
-
if (
|
|
1166
|
+
if (g === "$$get")
|
|
1171
1167
|
return () => Se({ _stateKey: e, _path: t, _meta: o });
|
|
1172
|
-
if (
|
|
1168
|
+
if (g === "$lastSynced") {
|
|
1173
1169
|
const r = `${e}:${t.join(".")}`;
|
|
1174
1170
|
return We(r);
|
|
1175
1171
|
}
|
|
1176
|
-
if (
|
|
1172
|
+
if (g == "getLocalStorage")
|
|
1177
1173
|
return (r) => ae(s + "-" + e + "-" + r);
|
|
1178
|
-
if (
|
|
1174
|
+
if (g === "$isSelected") {
|
|
1179
1175
|
const r = t.slice(0, -1);
|
|
1180
|
-
if (
|
|
1181
|
-
const
|
|
1182
|
-
return
|
|
1176
|
+
if (E(e, r)?.arrayKeys) {
|
|
1177
|
+
const i = e + "." + r.join("."), f = p.getState().selectedIndicesMap.get(i), d = e + "." + t.join(".");
|
|
1178
|
+
return f === d;
|
|
1183
1179
|
}
|
|
1184
1180
|
return;
|
|
1185
1181
|
}
|
|
1186
|
-
if (
|
|
1182
|
+
if (g === "$setSelected")
|
|
1187
1183
|
return (r) => {
|
|
1188
|
-
const n = t.slice(0, -1),
|
|
1189
|
-
|
|
1184
|
+
const n = t.slice(0, -1), i = e + "." + n.join("."), f = e + "." + t.join(".");
|
|
1185
|
+
Y(e, n, void 0), p.getState().selectedIndicesMap.get(i), r && p.getState().setSelectedIndex(i, f);
|
|
1190
1186
|
};
|
|
1191
|
-
if (
|
|
1187
|
+
if (g === "$toggleSelected")
|
|
1192
1188
|
return () => {
|
|
1193
|
-
const r = t.slice(0, -1), n = e + "." + r.join("."),
|
|
1194
|
-
p.getState().selectedIndicesMap.get(n) ===
|
|
1189
|
+
const r = t.slice(0, -1), n = e + "." + r.join("."), i = e + "." + t.join(".");
|
|
1190
|
+
p.getState().selectedIndicesMap.get(n) === i ? p.getState().clearSelectedIndex({ arrayKey: n }) : p.getState().setSelectedIndex(n, i), Y(e, r);
|
|
1191
|
+
};
|
|
1192
|
+
if (g === "$clearValidation")
|
|
1193
|
+
return (r) => {
|
|
1194
|
+
const n = r ? [...t, ...r] : t, i = p.getState(), f = i.getShadowNode(e, n);
|
|
1195
|
+
if (console.log("startNode ", f), !f) return;
|
|
1196
|
+
const d = [[f, n]];
|
|
1197
|
+
for (console.log("stack ", d); d.length > 0; ) {
|
|
1198
|
+
const [m, w] = d.pop();
|
|
1199
|
+
if (console.log("while (stack.length ", m, w), !m || typeof m != "object") continue;
|
|
1200
|
+
if (m._meta?.validation) {
|
|
1201
|
+
m._meta.validation = {
|
|
1202
|
+
status: "NOT_VALIDATED",
|
|
1203
|
+
errors: [],
|
|
1204
|
+
lastValidated: Date.now(),
|
|
1205
|
+
validatedValue: void 0
|
|
1206
|
+
};
|
|
1207
|
+
const A = [e, ...w].join(".");
|
|
1208
|
+
i.notifyPathSubscribers(A, {
|
|
1209
|
+
type: "VALIDATION_CLEAR"
|
|
1210
|
+
});
|
|
1211
|
+
}
|
|
1212
|
+
const M = Object.keys(m);
|
|
1213
|
+
for (const A of M)
|
|
1214
|
+
A !== "_meta" && d.push([m[A], [...w, A]]);
|
|
1215
|
+
}
|
|
1216
|
+
L(e);
|
|
1195
1217
|
};
|
|
1196
|
-
if (f === "$_componentId")
|
|
1197
|
-
return y;
|
|
1198
1218
|
if (t.length == 0) {
|
|
1199
|
-
if (
|
|
1219
|
+
if (g === "$_componentId")
|
|
1220
|
+
return y;
|
|
1221
|
+
if (g === "$setOptions")
|
|
1200
1222
|
return (r) => {
|
|
1201
1223
|
ce({ stateKey: e, options: r, initialOptionsPart: {} });
|
|
1202
1224
|
};
|
|
1203
|
-
if (
|
|
1204
|
-
return (r, n,
|
|
1205
|
-
a(r, n, { updateType:
|
|
1225
|
+
if (g === "$_applyUpdate")
|
|
1226
|
+
return (r, n, i = "update") => {
|
|
1227
|
+
a(r, n, { updateType: i });
|
|
1206
1228
|
};
|
|
1207
|
-
if (
|
|
1229
|
+
if (g === "$_getEffectiveSetState")
|
|
1208
1230
|
return a;
|
|
1209
|
-
if (
|
|
1231
|
+
if (g === "$getPluginMetaData")
|
|
1210
1232
|
return (r) => Ge(e, t)?.get(r);
|
|
1211
|
-
if (
|
|
1212
|
-
return
|
|
1213
|
-
if (
|
|
1214
|
-
return (r) =>
|
|
1215
|
-
if (
|
|
1233
|
+
if (g === "$addPluginMetaData")
|
|
1234
|
+
return (r, n) => qe(e, t, r, n);
|
|
1235
|
+
if (g === "$removePluginMetaData")
|
|
1236
|
+
return (r) => xe(e, t, r);
|
|
1237
|
+
if (g === "$addZodValidation")
|
|
1216
1238
|
return (r, n) => {
|
|
1217
|
-
r.forEach((
|
|
1218
|
-
const
|
|
1219
|
-
p.getState().setShadowMetadata(e,
|
|
1220
|
-
...
|
|
1239
|
+
r.forEach((i) => {
|
|
1240
|
+
const f = p.getState().getShadowMetadata(e, i.path) || {};
|
|
1241
|
+
p.getState().setShadowMetadata(e, i.path, {
|
|
1242
|
+
...f,
|
|
1221
1243
|
validation: {
|
|
1222
1244
|
status: "INVALID",
|
|
1223
1245
|
errors: [
|
|
1224
1246
|
{
|
|
1225
1247
|
source: n || "client",
|
|
1226
|
-
message:
|
|
1248
|
+
message: i.message,
|
|
1227
1249
|
severity: "error",
|
|
1228
|
-
code:
|
|
1250
|
+
code: i.code
|
|
1229
1251
|
}
|
|
1230
1252
|
],
|
|
1231
1253
|
lastValidated: Date.now(),
|
|
@@ -1234,103 +1256,85 @@ function we(e, a, l, s) {
|
|
|
1234
1256
|
});
|
|
1235
1257
|
});
|
|
1236
1258
|
};
|
|
1237
|
-
if (
|
|
1238
|
-
return (r) => {
|
|
1239
|
-
if (!r)
|
|
1240
|
-
throw new Error("clearZodValidation requires a path");
|
|
1241
|
-
const n = A(e, r) || {};
|
|
1242
|
-
L(e, r, {
|
|
1243
|
-
...n,
|
|
1244
|
-
validation: {
|
|
1245
|
-
status: "NOT_VALIDATED",
|
|
1246
|
-
errors: [],
|
|
1247
|
-
lastValidated: Date.now()
|
|
1248
|
-
}
|
|
1249
|
-
});
|
|
1250
|
-
};
|
|
1251
|
-
if (f === "$applyOperation")
|
|
1259
|
+
if (g === "$applyOperation")
|
|
1252
1260
|
return (r, n) => {
|
|
1253
|
-
|
|
1254
|
-
"getGlobalStore",
|
|
1255
|
-
p.getState().getShadowMetadata(e, r.path)
|
|
1256
|
-
);
|
|
1257
|
-
let c;
|
|
1261
|
+
let i;
|
|
1258
1262
|
if (r.insertAfterId && r.updateType === "insert") {
|
|
1259
|
-
const
|
|
1260
|
-
if (
|
|
1261
|
-
const d =
|
|
1263
|
+
const f = E(e, r.path);
|
|
1264
|
+
if (f?.arrayKeys) {
|
|
1265
|
+
const d = f.arrayKeys.indexOf(
|
|
1262
1266
|
r.insertAfterId
|
|
1263
1267
|
);
|
|
1264
|
-
d !== -1 && (
|
|
1268
|
+
d !== -1 && (i = d + 1);
|
|
1265
1269
|
}
|
|
1266
1270
|
}
|
|
1267
1271
|
a(r.newValue, r.path, {
|
|
1268
1272
|
updateType: r.updateType,
|
|
1269
1273
|
itemId: r.itemId,
|
|
1270
|
-
index:
|
|
1274
|
+
index: i,
|
|
1271
1275
|
// Pass the calculated index
|
|
1272
1276
|
metaData: n
|
|
1273
1277
|
});
|
|
1274
1278
|
};
|
|
1275
|
-
if (
|
|
1279
|
+
if (g === "$applyJsonPatch")
|
|
1276
1280
|
return (r) => {
|
|
1277
|
-
const n = p.getState(),
|
|
1278
|
-
if (!
|
|
1279
|
-
const
|
|
1280
|
-
for (const
|
|
1281
|
-
const w =
|
|
1282
|
-
switch (
|
|
1281
|
+
const n = p.getState(), i = n.getShadowMetadata(e, []);
|
|
1282
|
+
if (!i?.components) return;
|
|
1283
|
+
const f = (m) => !m || m === "/" ? [] : m.split("/").slice(1).map((w) => w.replace(/~1/g, "/").replace(/~0/g, "~")), d = /* @__PURE__ */ new Set();
|
|
1284
|
+
for (const m of r) {
|
|
1285
|
+
const w = f(m.path);
|
|
1286
|
+
switch (m.op) {
|
|
1283
1287
|
case "add":
|
|
1284
1288
|
case "replace": {
|
|
1285
|
-
const { value: M } =
|
|
1289
|
+
const { value: M } = m;
|
|
1286
1290
|
n.updateShadowAtPath(e, w, M), n.markAsDirty(e, w, { bubble: !0 });
|
|
1287
|
-
let
|
|
1291
|
+
let A = [...w];
|
|
1288
1292
|
for (; ; ) {
|
|
1289
|
-
const
|
|
1293
|
+
const I = n.getShadowMetadata(
|
|
1290
1294
|
e,
|
|
1291
|
-
|
|
1295
|
+
A
|
|
1292
1296
|
);
|
|
1293
|
-
if (
|
|
1297
|
+
if (I?.pathComponents && I.pathComponents.forEach((k) => {
|
|
1294
1298
|
if (!d.has(k)) {
|
|
1295
|
-
const O =
|
|
1299
|
+
const O = i.components?.get(k);
|
|
1296
1300
|
O && (O.forceUpdate(), d.add(k));
|
|
1297
1301
|
}
|
|
1298
|
-
}),
|
|
1299
|
-
|
|
1302
|
+
}), A.length === 0) break;
|
|
1303
|
+
A.pop();
|
|
1300
1304
|
}
|
|
1301
1305
|
break;
|
|
1302
1306
|
}
|
|
1303
1307
|
case "remove": {
|
|
1304
1308
|
const M = w.slice(0, -1);
|
|
1305
1309
|
n.removeShadowArrayElement(e, w), n.markAsDirty(e, M, { bubble: !0 });
|
|
1306
|
-
let
|
|
1310
|
+
let A = [...M];
|
|
1307
1311
|
for (; ; ) {
|
|
1308
|
-
const
|
|
1312
|
+
const I = n.getShadowMetadata(
|
|
1309
1313
|
e,
|
|
1310
|
-
|
|
1314
|
+
A
|
|
1311
1315
|
);
|
|
1312
|
-
if (
|
|
1316
|
+
if (I?.pathComponents && I.pathComponents.forEach((k) => {
|
|
1313
1317
|
if (!d.has(k)) {
|
|
1314
|
-
const O =
|
|
1318
|
+
const O = i.components?.get(k);
|
|
1315
1319
|
O && (O.forceUpdate(), d.add(k));
|
|
1316
1320
|
}
|
|
1317
|
-
}),
|
|
1318
|
-
|
|
1321
|
+
}), A.length === 0) break;
|
|
1322
|
+
A.pop();
|
|
1319
1323
|
}
|
|
1320
1324
|
break;
|
|
1321
1325
|
}
|
|
1322
1326
|
}
|
|
1323
1327
|
}
|
|
1324
1328
|
};
|
|
1325
|
-
if (
|
|
1326
|
-
return () =>
|
|
1329
|
+
if (g === "$getComponents")
|
|
1330
|
+
return () => E(e, [])?.components;
|
|
1327
1331
|
}
|
|
1328
|
-
if (
|
|
1332
|
+
if (g === "$validationWrapper")
|
|
1329
1333
|
return ({
|
|
1330
1334
|
children: r,
|
|
1331
1335
|
hideMessage: n
|
|
1332
|
-
}) => /* @__PURE__ */
|
|
1333
|
-
|
|
1336
|
+
}) => /* @__PURE__ */ Q(
|
|
1337
|
+
Ie,
|
|
1334
1338
|
{
|
|
1335
1339
|
formOpts: n ? { validation: { message: "" } } : void 0,
|
|
1336
1340
|
path: t,
|
|
@@ -1338,26 +1342,26 @@ function we(e, a, l, s) {
|
|
|
1338
1342
|
children: r
|
|
1339
1343
|
}
|
|
1340
1344
|
);
|
|
1341
|
-
if (
|
|
1342
|
-
if (
|
|
1343
|
-
if (
|
|
1345
|
+
if (g === "$_stateKey") return e;
|
|
1346
|
+
if (g === "$_path") return t;
|
|
1347
|
+
if (g === "$update")
|
|
1344
1348
|
return (r) => (a(r, t, { updateType: "update" }), {
|
|
1345
1349
|
synced: () => {
|
|
1346
1350
|
const n = p.getState().getShadowMetadata(e, t);
|
|
1347
|
-
|
|
1351
|
+
B(e, t, {
|
|
1348
1352
|
...n,
|
|
1349
1353
|
isDirty: !1,
|
|
1350
1354
|
stateSource: "server",
|
|
1351
1355
|
lastServerSync: Date.now()
|
|
1352
1356
|
});
|
|
1353
|
-
const
|
|
1354
|
-
Be(
|
|
1357
|
+
const i = [e, ...t].join(".");
|
|
1358
|
+
Be(i, {
|
|
1355
1359
|
type: "SYNC_STATUS_CHANGE",
|
|
1356
1360
|
isDirty: !1
|
|
1357
1361
|
});
|
|
1358
1362
|
}
|
|
1359
1363
|
});
|
|
1360
|
-
if (
|
|
1364
|
+
if (g === "$toggle") {
|
|
1361
1365
|
const { value: r } = W(
|
|
1362
1366
|
e,
|
|
1363
1367
|
t,
|
|
@@ -1371,51 +1375,59 @@ function we(e, a, l, s) {
|
|
|
1371
1375
|
});
|
|
1372
1376
|
};
|
|
1373
1377
|
}
|
|
1374
|
-
if (
|
|
1375
|
-
return (r) =>
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
|
|
1378
|
+
if (g === "$isolate")
|
|
1379
|
+
return (r, n) => {
|
|
1380
|
+
const i = Array.isArray(r), f = i ? r : void 0, d = i ? n : r;
|
|
1381
|
+
if (!d || typeof d != "function")
|
|
1382
|
+
throw new Error(
|
|
1383
|
+
"CogsState: $isolate requires a render function."
|
|
1384
|
+
);
|
|
1385
|
+
return /* @__PURE__ */ Q(
|
|
1386
|
+
Pe,
|
|
1387
|
+
{
|
|
1388
|
+
stateKey: e,
|
|
1389
|
+
path: t,
|
|
1390
|
+
dependencies: f,
|
|
1391
|
+
rebuildStateShape: c,
|
|
1392
|
+
renderFn: d
|
|
1393
|
+
}
|
|
1394
|
+
);
|
|
1395
|
+
};
|
|
1396
|
+
if (g === "$formElement")
|
|
1397
|
+
return (r, n) => /* @__PURE__ */ Q(
|
|
1386
1398
|
ke,
|
|
1387
1399
|
{
|
|
1388
1400
|
stateKey: e,
|
|
1389
1401
|
path: t,
|
|
1390
|
-
rebuildStateShape:
|
|
1402
|
+
rebuildStateShape: c,
|
|
1391
1403
|
setState: a,
|
|
1392
1404
|
formOpts: n,
|
|
1393
1405
|
renderFn: r
|
|
1394
1406
|
}
|
|
1395
1407
|
);
|
|
1396
|
-
const P = [...t,
|
|
1397
|
-
return
|
|
1408
|
+
const P = [...t, g];
|
|
1409
|
+
return c({
|
|
1398
1410
|
path: P,
|
|
1399
1411
|
componentId: y,
|
|
1400
1412
|
meta: o
|
|
1401
1413
|
});
|
|
1402
1414
|
}
|
|
1403
1415
|
}, C = new Proxy(v, F);
|
|
1404
|
-
return
|
|
1416
|
+
return S.set(V, C), C;
|
|
1405
1417
|
}
|
|
1406
|
-
const
|
|
1418
|
+
const h = {
|
|
1407
1419
|
$revertToInitialState: (t) => {
|
|
1408
1420
|
const o = p.getState().getShadowMetadata(e, []);
|
|
1409
1421
|
let y;
|
|
1410
|
-
o?.stateSource === "server" && o.baseServerState ? y = o.baseServerState : y = p.getState().initialStateGlobal[e], ze(e), K(e, y),
|
|
1422
|
+
o?.stateSource === "server" && o.baseServerState ? y = o.baseServerState : y = p.getState().initialStateGlobal[e], ze(e), K(e, y), c({
|
|
1411
1423
|
path: [],
|
|
1412
1424
|
componentId: l
|
|
1413
1425
|
});
|
|
1414
|
-
const $ = N(e), V = R($?.localStorage?.key) ? $?.localStorage?.key(y) : $?.localStorage?.key,
|
|
1415
|
-
return
|
|
1426
|
+
const $ = N(e), V = R($?.localStorage?.key) ? $?.localStorage?.key(y) : $?.localStorage?.key, b = `${s}-${e}-${V}`;
|
|
1427
|
+
return b && localStorage.removeItem(b), L(e), y;
|
|
1416
1428
|
},
|
|
1417
1429
|
$initializeAndMergeShadowState: (t) => {
|
|
1418
|
-
Oe(e, t),
|
|
1430
|
+
Oe(e, t), L(e);
|
|
1419
1431
|
},
|
|
1420
1432
|
$updateInitialState: (t) => {
|
|
1421
1433
|
const o = we(
|
|
@@ -1423,8 +1435,8 @@ function we(e, a, l, s) {
|
|
|
1423
1435
|
a,
|
|
1424
1436
|
l,
|
|
1425
1437
|
s
|
|
1426
|
-
), y = p.getState().initialStateGlobal[e], $ = N(e), V = R($?.localStorage?.key) ? $?.localStorage?.key(y) : $?.localStorage?.key,
|
|
1427
|
-
return localStorage.getItem(
|
|
1438
|
+
), y = p.getState().initialStateGlobal[e], $ = N(e), V = R($?.localStorage?.key) ? $?.localStorage?.key(y) : $?.localStorage?.key, b = `${s}-${e}-${V}`;
|
|
1439
|
+
return localStorage.getItem(b) && localStorage.removeItem(b), Ee(() => {
|
|
1428
1440
|
he(e, t), K(e, t);
|
|
1429
1441
|
const v = p.getState().getShadowMetadata(e, []);
|
|
1430
1442
|
v && v?.components?.forEach((F) => {
|
|
@@ -1435,7 +1447,7 @@ function we(e, a, l, s) {
|
|
|
1435
1447
|
};
|
|
1436
1448
|
}
|
|
1437
1449
|
};
|
|
1438
|
-
return
|
|
1450
|
+
return c({
|
|
1439
1451
|
componentId: l,
|
|
1440
1452
|
path: []
|
|
1441
1453
|
});
|
|
@@ -1446,22 +1458,22 @@ function Se(e) {
|
|
|
1446
1458
|
function it({
|
|
1447
1459
|
proxy: e
|
|
1448
1460
|
}) {
|
|
1449
|
-
const a =
|
|
1461
|
+
const a = x(null), l = x(null), s = x(!1), S = `${e._stateKey}-${e._path.join(".")}`, c = e._path.length > 0 ? e._path.join(".") : "root", h = e._meta?.arrayViews?.[c], u = D(e._stateKey, e._path, h);
|
|
1450
1462
|
return J(() => {
|
|
1451
1463
|
const t = a.current;
|
|
1452
1464
|
if (!t || s.current) return;
|
|
1453
1465
|
const o = setTimeout(() => {
|
|
1454
1466
|
if (!t.parentElement) {
|
|
1455
|
-
console.warn("Parent element not found for signal",
|
|
1467
|
+
console.warn("Parent element not found for signal", S);
|
|
1456
1468
|
return;
|
|
1457
1469
|
}
|
|
1458
1470
|
const y = t.parentElement, V = Array.from(y.childNodes).indexOf(t);
|
|
1459
|
-
let
|
|
1460
|
-
|
|
1471
|
+
let b = y.getAttribute("data-parent-id");
|
|
1472
|
+
b || (b = `parent-${crypto.randomUUID()}`, y.setAttribute("data-parent-id", b)), l.current = `instance-${crypto.randomUUID()}`;
|
|
1461
1473
|
const v = p.getState().getShadowMetadata(e._stateKey, e._path) || {}, F = v.signals || [];
|
|
1462
1474
|
F.push({
|
|
1463
1475
|
instanceId: l.current,
|
|
1464
|
-
parentId:
|
|
1476
|
+
parentId: b,
|
|
1465
1477
|
position: V,
|
|
1466
1478
|
effect: e._effect
|
|
1467
1479
|
}), p.getState().setShadowMetadata(e._stateKey, e._path, {
|
|
@@ -1475,8 +1487,8 @@ function it({
|
|
|
1475
1487
|
"state",
|
|
1476
1488
|
`return (${e._effect})(state)`
|
|
1477
1489
|
)(u);
|
|
1478
|
-
} catch (
|
|
1479
|
-
console.error("Error evaluating effect function:",
|
|
1490
|
+
} catch (g) {
|
|
1491
|
+
console.error("Error evaluating effect function:", g);
|
|
1480
1492
|
}
|
|
1481
1493
|
C !== null && typeof C == "object" && (C = JSON.stringify(C));
|
|
1482
1494
|
const G = document.createTextNode(String(C ?? ""));
|
|
@@ -1493,13 +1505,13 @@ function it({
|
|
|
1493
1505
|
}, []), ue("span", {
|
|
1494
1506
|
ref: a,
|
|
1495
1507
|
style: { display: "contents" },
|
|
1496
|
-
"data-signal-id":
|
|
1508
|
+
"data-signal-id": S
|
|
1497
1509
|
});
|
|
1498
1510
|
}
|
|
1499
1511
|
export {
|
|
1500
1512
|
Se as $cogsSignal,
|
|
1501
|
-
|
|
1502
|
-
|
|
1513
|
+
wt as addStateOptions,
|
|
1514
|
+
pt as createCogsState,
|
|
1503
1515
|
ot as useCogsStateFn
|
|
1504
1516
|
};
|
|
1505
1517
|
//# sourceMappingURL=CogsState.jsx.map
|