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