cogsbox-state 0.5.467 → 0.5.468
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.map +1 -1
- package/dist/CogsState.jsx +346 -346
- package/dist/CogsState.jsx.map +1 -1
- package/dist/Components.d.ts.map +1 -1
- package/dist/Components.jsx +24 -23
- package/dist/Components.jsx.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +6 -5
- package/src/Components.tsx +1 -0
package/dist/CogsState.jsx
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as ie, Fragment as Ce } from "react/jsx-runtime";
|
|
3
|
-
import { useState as K, useRef as L, useEffect as W, useCallback as
|
|
3
|
+
import { useState as K, useRef as L, useEffect as W, useCallback as we, useLayoutEffect as ce, useMemo as pe, createElement as be, startTransition as De } from "react";
|
|
4
4
|
import { transformStateFunc as Ue, isFunction as z, isDeepEqual as ae, isArray as Fe, getDifferences as $e } from "./utility.js";
|
|
5
5
|
import { ValidationWrapper as Ne, FormElementWrapper as Oe, MemoizedCogsItemWrapper as je } from "./Components.jsx";
|
|
6
6
|
import xe from "superjson";
|
|
7
7
|
import { v4 as X } from "uuid";
|
|
8
|
-
import { getGlobalStore as T, formRefStore as
|
|
8
|
+
import { getGlobalStore as T, formRefStore as Me } from "./store.js";
|
|
9
9
|
import { useCogsConfig as Ve } from "./CogsStateClient.jsx";
|
|
10
10
|
const {
|
|
11
11
|
getInitialOptions: G,
|
|
@@ -23,8 +23,8 @@ const {
|
|
|
23
23
|
setInitialStateOptions: le,
|
|
24
24
|
setServerStateUpdate: We,
|
|
25
25
|
markAsDirty: ue,
|
|
26
|
-
registerComponent:
|
|
27
|
-
unregisterComponent:
|
|
26
|
+
registerComponent: bt,
|
|
27
|
+
unregisterComponent: Et,
|
|
28
28
|
addPathComponent: Ge,
|
|
29
29
|
clearSelectedIndexesForState: He,
|
|
30
30
|
addStateLog: ze,
|
|
@@ -32,7 +32,7 @@ const {
|
|
|
32
32
|
clearSelectedIndex: Ze,
|
|
33
33
|
getSyncInfo: Ye,
|
|
34
34
|
notifyPathSubscribers: Qe,
|
|
35
|
-
subscribeToPath:
|
|
35
|
+
subscribeToPath: Mt
|
|
36
36
|
// Note: The old functions are no longer imported under their original names
|
|
37
37
|
} = T.getState();
|
|
38
38
|
function B(e, r, l) {
|
|
@@ -58,7 +58,7 @@ function ve(e, r) {
|
|
|
58
58
|
...r
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
|
-
function
|
|
61
|
+
function Ae({
|
|
62
62
|
stateKey: e,
|
|
63
63
|
options: r,
|
|
64
64
|
initialOptionsPart: l
|
|
@@ -70,26 +70,26 @@ function Me({
|
|
|
70
70
|
s.hasOwnProperty(i) ? (i == "localStorage" && r[i] && s[i].key !== r[i]?.key && (c = !0, s[i] = r[i]), i == "defaultState" && r[i] && s[i] !== r[i] && !ae(s[i], r[i]) && (c = !0, s[i] = r[i])) : (c = !0, s[i] = r[i]);
|
|
71
71
|
s.syncOptions && (!r || !r.hasOwnProperty("syncOptions")) && (c = !0), c && le(e, s);
|
|
72
72
|
}
|
|
73
|
-
function
|
|
73
|
+
function At(e, { formElements: r, validation: l }) {
|
|
74
74
|
return { initialState: e, formElements: r, validation: l };
|
|
75
75
|
}
|
|
76
76
|
const Xe = (e, r) => {
|
|
77
77
|
let l = e;
|
|
78
78
|
const [a, S] = Ue(l);
|
|
79
79
|
r?.__fromSyncSchema && r?.__syncNotifications && T.getState().setInitialStateOptions("__notifications", r.__syncNotifications), r?.__fromSyncSchema && r?.__apiParamsMap && T.getState().setInitialStateOptions("__apiParamsMap", r.__apiParamsMap), Object.keys(a).forEach((i) => {
|
|
80
|
-
let
|
|
80
|
+
let d = S[i] || {};
|
|
81
81
|
const t = {
|
|
82
|
-
...
|
|
82
|
+
...d
|
|
83
83
|
};
|
|
84
84
|
if (r?.formElements && (t.formElements = {
|
|
85
85
|
...r.formElements,
|
|
86
|
-
...
|
|
86
|
+
...d.formElements || {}
|
|
87
87
|
}), r?.validation && (t.validation = {
|
|
88
88
|
...r.validation,
|
|
89
|
-
...
|
|
90
|
-
}, r.validation.key && !
|
|
89
|
+
...d.validation || {}
|
|
90
|
+
}, r.validation.key && !d.validation?.key && (t.validation.key = `${r.validation.key}.${i}`)), r?.__syncSchemas?.[i]?.schemas?.validation && (t.validation = {
|
|
91
91
|
zodSchemaV4: r.__syncSchemas[i].schemas.validation,
|
|
92
|
-
...
|
|
92
|
+
...d.validation
|
|
93
93
|
}), Object.keys(t).length > 0) {
|
|
94
94
|
const u = G(i);
|
|
95
95
|
u ? le(i, {
|
|
@@ -100,35 +100,35 @@ const Xe = (e, r) => {
|
|
|
100
100
|
}), Object.keys(a).forEach((i) => {
|
|
101
101
|
oe(i, a[i]);
|
|
102
102
|
});
|
|
103
|
-
const s = (i,
|
|
104
|
-
const [t] = K(
|
|
105
|
-
|
|
103
|
+
const s = (i, d) => {
|
|
104
|
+
const [t] = K(d?.componentId ?? X());
|
|
105
|
+
Ae({
|
|
106
106
|
stateKey: i,
|
|
107
|
-
options:
|
|
107
|
+
options: d,
|
|
108
108
|
initialOptionsPart: S
|
|
109
109
|
});
|
|
110
|
-
const u = R(i, []) || a[i],
|
|
111
|
-
return lt(
|
|
110
|
+
const u = R(i, []) || a[i], b = d?.modifyState ? d.modifyState(u) : u;
|
|
111
|
+
return lt(b, {
|
|
112
112
|
stateKey: i,
|
|
113
|
-
syncUpdate:
|
|
113
|
+
syncUpdate: d?.syncUpdate,
|
|
114
114
|
componentId: t,
|
|
115
|
-
localStorage:
|
|
116
|
-
middleware:
|
|
117
|
-
reactiveType:
|
|
118
|
-
reactiveDeps:
|
|
119
|
-
defaultState:
|
|
120
|
-
dependencies:
|
|
121
|
-
serverState:
|
|
122
|
-
syncOptions:
|
|
115
|
+
localStorage: d?.localStorage,
|
|
116
|
+
middleware: d?.middleware,
|
|
117
|
+
reactiveType: d?.reactiveType,
|
|
118
|
+
reactiveDeps: d?.reactiveDeps,
|
|
119
|
+
defaultState: d?.defaultState,
|
|
120
|
+
dependencies: d?.dependencies,
|
|
121
|
+
serverState: d?.serverState,
|
|
122
|
+
syncOptions: d?.syncOptions,
|
|
123
123
|
__useSync: r?.__useSync
|
|
124
124
|
});
|
|
125
125
|
};
|
|
126
|
-
function c(i,
|
|
127
|
-
|
|
126
|
+
function c(i, d) {
|
|
127
|
+
Ae({ stateKey: i, options: d, initialOptionsPart: S }), d.localStorage && et(i, d), Ee(i);
|
|
128
128
|
}
|
|
129
129
|
return { useCogsState: s, setCogsOptions: c };
|
|
130
130
|
};
|
|
131
|
-
function
|
|
131
|
+
function It(e, r) {
|
|
132
132
|
const l = e.schemas, a = {}, S = {};
|
|
133
133
|
for (const s in l) {
|
|
134
134
|
const c = l[s];
|
|
@@ -157,12 +157,12 @@ const Ke = (e, r, l, a, S) => {
|
|
|
157
157
|
i = Se(c)?.lastSyncedWithServer;
|
|
158
158
|
} catch {
|
|
159
159
|
}
|
|
160
|
-
const
|
|
160
|
+
const d = V(r, []), t = {
|
|
161
161
|
state: e,
|
|
162
162
|
lastUpdated: Date.now(),
|
|
163
163
|
lastSyncedWithServer: i,
|
|
164
|
-
stateSource:
|
|
165
|
-
baseServerState:
|
|
164
|
+
stateSource: d?.stateSource,
|
|
165
|
+
baseServerState: d?.baseServerState
|
|
166
166
|
}, u = xe.serialize(t);
|
|
167
167
|
window.localStorage.setItem(
|
|
168
168
|
c,
|
|
@@ -184,10 +184,10 @@ const Ke = (e, r, l, a, S) => {
|
|
|
184
184
|
`${a}-${e}-${S}`
|
|
185
185
|
);
|
|
186
186
|
if (s && s.lastUpdated > (s.lastSyncedWithServer || 0))
|
|
187
|
-
return
|
|
187
|
+
return Ee(e), !0;
|
|
188
188
|
}
|
|
189
189
|
return !1;
|
|
190
|
-
},
|
|
190
|
+
}, Ee = (e) => {
|
|
191
191
|
const r = V(e, []);
|
|
192
192
|
if (!r) return;
|
|
193
193
|
const l = /* @__PURE__ */ new Set();
|
|
@@ -197,7 +197,7 @@ const Ke = (e, r, l, a, S) => {
|
|
|
197
197
|
l.forEach((a) => a());
|
|
198
198
|
});
|
|
199
199
|
};
|
|
200
|
-
function
|
|
200
|
+
function fe(e, r, l, a) {
|
|
201
201
|
const S = V(e, r);
|
|
202
202
|
if (J(e, r, {
|
|
203
203
|
...S,
|
|
@@ -207,20 +207,20 @@ function de(e, r, l, a) {
|
|
|
207
207
|
}), Array.isArray(l)) {
|
|
208
208
|
const s = V(e, r);
|
|
209
209
|
s?.arrayKeys && s.arrayKeys.forEach((c, i) => {
|
|
210
|
-
const
|
|
211
|
-
t !== void 0 &&
|
|
210
|
+
const d = [...r, c], t = l[i];
|
|
211
|
+
t !== void 0 && fe(
|
|
212
212
|
e,
|
|
213
|
-
|
|
213
|
+
d,
|
|
214
214
|
t,
|
|
215
215
|
a
|
|
216
216
|
);
|
|
217
217
|
});
|
|
218
218
|
} else l && typeof l == "object" && l.constructor === Object && Object.keys(l).forEach((s) => {
|
|
219
219
|
const c = [...r, s], i = l[s];
|
|
220
|
-
|
|
220
|
+
fe(e, c, i, a);
|
|
221
221
|
});
|
|
222
222
|
}
|
|
223
|
-
let
|
|
223
|
+
let de = [], Te = !1;
|
|
224
224
|
function tt() {
|
|
225
225
|
Te || (Te = !0, queueMicrotask(it));
|
|
226
226
|
}
|
|
@@ -247,8 +247,8 @@ function nt(e, r) {
|
|
|
247
247
|
i = new Function("state", `return (${S})(state)`)(
|
|
248
248
|
r
|
|
249
249
|
);
|
|
250
|
-
} catch (
|
|
251
|
-
console.error("Error evaluating effect function:",
|
|
250
|
+
} catch (d) {
|
|
251
|
+
console.error("Error evaluating effect function:", d);
|
|
252
252
|
}
|
|
253
253
|
i !== null && typeof i == "object" && (i = JSON.stringify(i)), c[a].textContent = String(i ?? "");
|
|
254
254
|
});
|
|
@@ -263,23 +263,23 @@ function at(e, r, l) {
|
|
|
263
263
|
for (; ; ) {
|
|
264
264
|
const c = V(e, s);
|
|
265
265
|
if (c?.pathComponents && c.pathComponents.forEach((i) => {
|
|
266
|
-
const
|
|
267
|
-
|
|
266
|
+
const d = a.components?.get(i);
|
|
267
|
+
d && ((Array.isArray(d.reactiveType) ? d.reactiveType : [d.reactiveType || "component"]).includes("none") || S.add(d));
|
|
268
268
|
}), s.length === 0) break;
|
|
269
269
|
s.pop();
|
|
270
270
|
}
|
|
271
271
|
l.newValue && typeof l.newValue == "object" && !Fe(l.newValue) && $e(l.newValue, l.oldValue).forEach((i) => {
|
|
272
|
-
const
|
|
273
|
-
u?.pathComponents && u.pathComponents.forEach((
|
|
274
|
-
const U = a.components?.get(
|
|
272
|
+
const d = i.split("."), t = [...r, ...d], u = V(e, t);
|
|
273
|
+
u?.pathComponents && u.pathComponents.forEach((b) => {
|
|
274
|
+
const U = a.components?.get(b);
|
|
275
275
|
U && ((Array.isArray(U.reactiveType) ? U.reactiveType : [U.reactiveType || "component"]).includes("none") || S.add(U));
|
|
276
276
|
});
|
|
277
277
|
});
|
|
278
278
|
} else if (l.type === "insert" || l.type === "cut") {
|
|
279
279
|
const s = l.type === "insert" ? r : r.slice(0, -1), c = V(e, s);
|
|
280
280
|
c?.pathComponents && c.pathComponents.forEach((i) => {
|
|
281
|
-
const
|
|
282
|
-
|
|
281
|
+
const d = a.components?.get(i);
|
|
282
|
+
d && S.add(d);
|
|
283
283
|
});
|
|
284
284
|
}
|
|
285
285
|
return a.components.forEach((s, c) => {
|
|
@@ -289,7 +289,7 @@ function at(e, r, l) {
|
|
|
289
289
|
if (i.includes("all"))
|
|
290
290
|
S.add(s);
|
|
291
291
|
else if (i.includes("deps") && s.depsFunction) {
|
|
292
|
-
const
|
|
292
|
+
const d = R(e, []), t = s.depsFunction(d);
|
|
293
293
|
(t === !0 || Array.isArray(t) && !ae(s.prevDeps, t)) && (s.prevDeps = t, S.add(s));
|
|
294
294
|
}
|
|
295
295
|
}), S;
|
|
@@ -318,7 +318,7 @@ function st(e, r) {
|
|
|
318
318
|
}
|
|
319
319
|
function it() {
|
|
320
320
|
const e = /* @__PURE__ */ new Set(), r = [], l = [];
|
|
321
|
-
for (const a of
|
|
321
|
+
for (const a of de) {
|
|
322
322
|
if (a.status && a.updateType) {
|
|
323
323
|
l.push(a);
|
|
324
324
|
continue;
|
|
@@ -336,15 +336,15 @@ function it() {
|
|
|
336
336
|
nt(a, S);
|
|
337
337
|
}), e.forEach((a) => {
|
|
338
338
|
a.forceUpdate();
|
|
339
|
-
}),
|
|
339
|
+
}), de = [], Te = !1;
|
|
340
340
|
}
|
|
341
341
|
function ct(e, r, l, a) {
|
|
342
|
-
return (s, c, i,
|
|
342
|
+
return (s, c, i, d) => {
|
|
343
343
|
S(e, c, s, i);
|
|
344
344
|
};
|
|
345
|
-
function S(s, c, i,
|
|
345
|
+
function S(s, c, i, d) {
|
|
346
346
|
let t;
|
|
347
|
-
switch (
|
|
347
|
+
switch (d.updateType) {
|
|
348
348
|
case "update":
|
|
349
349
|
t = rt(s, c, i);
|
|
350
350
|
break;
|
|
@@ -355,22 +355,22 @@ function ct(e, r, l, a) {
|
|
|
355
355
|
t = st(s, c);
|
|
356
356
|
break;
|
|
357
357
|
}
|
|
358
|
-
t.stateKey = s, t.path = c,
|
|
358
|
+
t.stateKey = s, t.path = c, de.push(t), tt();
|
|
359
359
|
const u = {
|
|
360
360
|
timeStamp: Date.now(),
|
|
361
361
|
stateKey: s,
|
|
362
362
|
path: c,
|
|
363
|
-
updateType:
|
|
363
|
+
updateType: d.updateType,
|
|
364
364
|
status: "new",
|
|
365
365
|
oldValue: t.oldValue,
|
|
366
366
|
newValue: t.newValue ?? null
|
|
367
367
|
};
|
|
368
|
-
|
|
368
|
+
de.push(u), t.newValue !== void 0 && Ke(
|
|
369
369
|
t.newValue,
|
|
370
370
|
s,
|
|
371
371
|
a.current,
|
|
372
372
|
l
|
|
373
|
-
), a.current?.middleware && a.current.middleware({ update: u }),
|
|
373
|
+
), a.current?.middleware && a.current.middleware({ update: u }), d.sync !== !1 && r.current?.connected && r.current.updateState({ operation: u });
|
|
374
374
|
}
|
|
375
375
|
}
|
|
376
376
|
function lt(e, {
|
|
@@ -381,160 +381,160 @@ function lt(e, {
|
|
|
381
381
|
reactiveType: s,
|
|
382
382
|
componentId: c,
|
|
383
383
|
defaultState: i,
|
|
384
|
-
syncUpdate:
|
|
384
|
+
syncUpdate: d,
|
|
385
385
|
dependencies: t,
|
|
386
386
|
serverState: u,
|
|
387
|
-
__useSync:
|
|
387
|
+
__useSync: b
|
|
388
388
|
} = {}) {
|
|
389
389
|
const [U, O] = K({}), { sessionId: F } = Ve();
|
|
390
390
|
let x = !r;
|
|
391
|
-
const [
|
|
391
|
+
const [p] = K(r ?? X()), ee = L(c ?? X()), m = L(
|
|
392
392
|
null
|
|
393
393
|
);
|
|
394
|
-
m.current = G(
|
|
395
|
-
if (
|
|
396
|
-
const g = `${
|
|
394
|
+
m.current = G(p) ?? null, W(() => {
|
|
395
|
+
if (d && d.stateKey === p && d.path?.[0]) {
|
|
396
|
+
const g = `${d.stateKey}:${d.path.join(".")}`;
|
|
397
397
|
Je(g, {
|
|
398
|
-
timeStamp:
|
|
399
|
-
userId:
|
|
398
|
+
timeStamp: d.timeStamp,
|
|
399
|
+
userId: d.userId
|
|
400
400
|
});
|
|
401
401
|
}
|
|
402
|
-
}, [
|
|
403
|
-
const te =
|
|
402
|
+
}, [d]);
|
|
403
|
+
const te = we(
|
|
404
404
|
(g) => {
|
|
405
|
-
const
|
|
406
|
-
if (
|
|
405
|
+
const w = g ? { ...G(p), ...g } : G(p), E = w?.defaultState || i || e;
|
|
406
|
+
if (w?.serverState?.status === "success" && w?.serverState?.data !== void 0)
|
|
407
407
|
return {
|
|
408
|
-
value:
|
|
408
|
+
value: w.serverState.data,
|
|
409
409
|
source: "server",
|
|
410
|
-
timestamp:
|
|
410
|
+
timestamp: w.serverState.timestamp || Date.now()
|
|
411
411
|
};
|
|
412
|
-
if (
|
|
413
|
-
const
|
|
414
|
-
`${F}-${
|
|
412
|
+
if (w?.localStorage?.key && F) {
|
|
413
|
+
const A = z(w.localStorage.key) ? w.localStorage.key(E) : w.localStorage.key, I = Se(
|
|
414
|
+
`${F}-${p}-${A}`
|
|
415
415
|
);
|
|
416
|
-
if (
|
|
416
|
+
if (I && I.lastUpdated > (w?.serverState?.timestamp || 0))
|
|
417
417
|
return {
|
|
418
|
-
value:
|
|
418
|
+
value: I.state,
|
|
419
419
|
source: "localStorage",
|
|
420
|
-
timestamp:
|
|
420
|
+
timestamp: I.lastUpdated
|
|
421
421
|
};
|
|
422
422
|
}
|
|
423
423
|
return {
|
|
424
|
-
value:
|
|
424
|
+
value: E || e,
|
|
425
425
|
source: "default",
|
|
426
426
|
timestamp: Date.now()
|
|
427
427
|
};
|
|
428
428
|
},
|
|
429
|
-
[
|
|
429
|
+
[p, i, e, F]
|
|
430
430
|
);
|
|
431
431
|
W(() => {
|
|
432
|
-
We(
|
|
433
|
-
}, [u,
|
|
432
|
+
We(p, u);
|
|
433
|
+
}, [u, p]), W(() => T.getState().subscribeToPath(p, (y) => {
|
|
434
434
|
if (y?.type === "SERVER_STATE_UPDATE") {
|
|
435
|
-
const
|
|
436
|
-
if (
|
|
435
|
+
const w = y.serverState;
|
|
436
|
+
if (w?.status !== "success" || w.data === void 0)
|
|
437
437
|
return;
|
|
438
|
-
ve(
|
|
439
|
-
const
|
|
440
|
-
if (
|
|
441
|
-
Array.isArray(_) && Array.isArray(
|
|
442
|
-
const
|
|
443
|
-
if (!
|
|
438
|
+
ve(p, { serverState: w });
|
|
439
|
+
const E = typeof w.merge == "object" ? w.merge : w.merge === !0 ? { strategy: "append" } : null, _ = R(p, []), A = w.data;
|
|
440
|
+
if (E && E.strategy === "append" && "key" in E && // Type guard for key
|
|
441
|
+
Array.isArray(_) && Array.isArray(A)) {
|
|
442
|
+
const I = E.key;
|
|
443
|
+
if (!I) {
|
|
444
444
|
console.error(
|
|
445
445
|
"CogsState: Merge strategy 'append' requires a 'key' field."
|
|
446
446
|
);
|
|
447
447
|
return;
|
|
448
448
|
}
|
|
449
449
|
const D = new Set(
|
|
450
|
-
_.map((N) => N[
|
|
451
|
-
),
|
|
452
|
-
(N) => !D.has(N[
|
|
450
|
+
_.map((N) => N[I])
|
|
451
|
+
), M = A.filter(
|
|
452
|
+
(N) => !D.has(N[I])
|
|
453
453
|
);
|
|
454
|
-
|
|
455
|
-
const k = R(
|
|
456
|
-
|
|
457
|
-
|
|
454
|
+
M.length > 0 && qe(p, [], M);
|
|
455
|
+
const k = R(p, []);
|
|
456
|
+
fe(
|
|
457
|
+
p,
|
|
458
458
|
[],
|
|
459
459
|
k,
|
|
460
|
-
|
|
460
|
+
w.timestamp
|
|
461
461
|
);
|
|
462
462
|
} else
|
|
463
|
-
oe(
|
|
464
|
-
|
|
463
|
+
oe(p, A), fe(
|
|
464
|
+
p,
|
|
465
465
|
[],
|
|
466
|
-
|
|
467
|
-
|
|
466
|
+
A,
|
|
467
|
+
w.timestamp
|
|
468
468
|
);
|
|
469
469
|
}
|
|
470
|
-
}), [
|
|
471
|
-
const g = T.getState().getShadowMetadata(
|
|
470
|
+
}), [p, te]), W(() => {
|
|
471
|
+
const g = T.getState().getShadowMetadata(p, []);
|
|
472
472
|
if (g && g.stateSource)
|
|
473
473
|
return;
|
|
474
|
-
const y = G(
|
|
474
|
+
const y = G(p), w = {
|
|
475
475
|
syncEnabled: !!v && !!h,
|
|
476
476
|
validationEnabled: !!(y?.validation?.zodSchemaV4 || y?.validation?.zodSchemaV3),
|
|
477
477
|
localStorageEnabled: !!y?.localStorage?.key
|
|
478
478
|
};
|
|
479
|
-
if (J(
|
|
479
|
+
if (J(p, [], {
|
|
480
480
|
...g,
|
|
481
|
-
features:
|
|
481
|
+
features: w
|
|
482
482
|
}), y?.defaultState !== void 0 || i !== void 0) {
|
|
483
|
-
const
|
|
484
|
-
y?.defaultState || ve(
|
|
485
|
-
defaultState:
|
|
483
|
+
const E = y?.defaultState || i;
|
|
484
|
+
y?.defaultState || ve(p, {
|
|
485
|
+
defaultState: E
|
|
486
486
|
});
|
|
487
|
-
const { value: _, source:
|
|
488
|
-
oe(
|
|
489
|
-
stateSource:
|
|
490
|
-
lastServerSync:
|
|
487
|
+
const { value: _, source: A, timestamp: I } = te();
|
|
488
|
+
oe(p, _), J(p, [], {
|
|
489
|
+
stateSource: A,
|
|
490
|
+
lastServerSync: A === "server" ? I : void 0,
|
|
491
491
|
isDirty: !1,
|
|
492
|
-
baseServerState:
|
|
493
|
-
}),
|
|
492
|
+
baseServerState: A === "server" ? _ : void 0
|
|
493
|
+
}), Ee(p);
|
|
494
494
|
}
|
|
495
|
-
}, [
|
|
496
|
-
x && ve(
|
|
495
|
+
}, [p, ...t || []]), ce(() => {
|
|
496
|
+
x && ve(p, {
|
|
497
497
|
formElements: a,
|
|
498
498
|
defaultState: i,
|
|
499
499
|
localStorage: l,
|
|
500
500
|
middleware: m.current?.middleware
|
|
501
501
|
});
|
|
502
|
-
const g = `${
|
|
503
|
-
return
|
|
502
|
+
const g = `${p}////${ee.current}`, y = V(p, []), w = y?.components || /* @__PURE__ */ new Map();
|
|
503
|
+
return w.set(g, {
|
|
504
504
|
forceUpdate: () => O({}),
|
|
505
505
|
reactiveType: s ?? ["component"],
|
|
506
506
|
paths: /* @__PURE__ */ new Set(),
|
|
507
507
|
depsFunction: S || void 0,
|
|
508
|
-
deps: S ? S(R(
|
|
509
|
-
prevDeps: S ? S(R(
|
|
510
|
-
}), J(
|
|
508
|
+
deps: S ? S(R(p, [])) : [],
|
|
509
|
+
prevDeps: S ? S(R(p, [])) : []
|
|
510
|
+
}), J(p, [], {
|
|
511
511
|
...y,
|
|
512
|
-
components:
|
|
512
|
+
components: w
|
|
513
513
|
}), O({}), () => {
|
|
514
|
-
const
|
|
515
|
-
_?.paths && _.paths.forEach((
|
|
516
|
-
const D =
|
|
517
|
-
|
|
518
|
-
}),
|
|
514
|
+
const E = V(p, []), _ = E?.components?.get(g);
|
|
515
|
+
_?.paths && _.paths.forEach((A) => {
|
|
516
|
+
const D = A.split(".").slice(1), M = T.getState().getShadowMetadata(p, D);
|
|
517
|
+
M?.pathComponents && M.pathComponents.size === 0 && (delete M.pathComponents, T.getState().setShadowMetadata(p, D, M));
|
|
518
|
+
}), E?.components && J(p, [], E);
|
|
519
519
|
};
|
|
520
520
|
}, []);
|
|
521
521
|
const o = L(null), n = ct(
|
|
522
|
-
|
|
522
|
+
p,
|
|
523
523
|
o,
|
|
524
524
|
F,
|
|
525
525
|
m
|
|
526
526
|
);
|
|
527
|
-
T.getState().initialStateGlobal[
|
|
528
|
-
const
|
|
529
|
-
|
|
527
|
+
T.getState().initialStateGlobal[p] || ke(p, e);
|
|
528
|
+
const f = pe(() => Pe(
|
|
529
|
+
p,
|
|
530
530
|
n,
|
|
531
531
|
ee.current,
|
|
532
532
|
F
|
|
533
|
-
), [
|
|
533
|
+
), [p, F]), v = b, h = m.current?.syncOptions;
|
|
534
534
|
return v && (o.current = v(
|
|
535
|
-
|
|
535
|
+
f,
|
|
536
536
|
h ?? {}
|
|
537
|
-
)),
|
|
537
|
+
)), f;
|
|
538
538
|
}
|
|
539
539
|
const ut = (e, r, l) => {
|
|
540
540
|
let a = V(e, r)?.arrayKeys || [];
|
|
@@ -544,16 +544,16 @@ const ut = (e, r, l) => {
|
|
|
544
544
|
for (const s of S)
|
|
545
545
|
if (s.type === "filter") {
|
|
546
546
|
const c = [];
|
|
547
|
-
a.forEach((i,
|
|
547
|
+
a.forEach((i, d) => {
|
|
548
548
|
const t = R(e, [...r, i]);
|
|
549
|
-
s.fn(t,
|
|
549
|
+
s.fn(t, d) && c.push(i);
|
|
550
550
|
}), a = c;
|
|
551
551
|
} else s.type === "sort" && a.sort((c, i) => {
|
|
552
|
-
const
|
|
553
|
-
return s.fn(
|
|
552
|
+
const d = R(e, [...r, c]), t = R(e, [...r, i]);
|
|
553
|
+
return s.fn(d, t);
|
|
554
554
|
});
|
|
555
555
|
return a;
|
|
556
|
-
},
|
|
556
|
+
}, Ie = (e, r, l) => {
|
|
557
557
|
const a = `${e}////${r}`, s = V(e, [])?.components?.get(a);
|
|
558
558
|
!s || s.reactiveType === "none" || !(Array.isArray(s.reactiveType) ? s.reactiveType : [s.reactiveType]).includes("component") || Ge(e, l, a);
|
|
559
559
|
}, ne = (e, r, l) => {
|
|
@@ -568,8 +568,8 @@ const ut = (e, r, l) => {
|
|
|
568
568
|
});
|
|
569
569
|
const s = V(e, r);
|
|
570
570
|
for (let c of s?.arrayKeys || []) {
|
|
571
|
-
const i = c + ".selected",
|
|
572
|
-
c == l &&
|
|
571
|
+
const i = c + ".selected", d = V(e, i.split(".").slice(1));
|
|
572
|
+
c == l && d?.pathComponents?.forEach((t) => {
|
|
573
573
|
a?.components?.get(t)?.forceUpdate();
|
|
574
574
|
});
|
|
575
575
|
}
|
|
@@ -644,9 +644,9 @@ function Pe(e, r, l, a) {
|
|
|
644
644
|
function c({
|
|
645
645
|
path: t = [],
|
|
646
646
|
meta: u,
|
|
647
|
-
componentId:
|
|
647
|
+
componentId: b
|
|
648
648
|
}) {
|
|
649
|
-
const U = u ? JSON.stringify(u.arrayViews || u.transforms) : "", O = t.join(".") + ":" + U;
|
|
649
|
+
const U = u ? JSON.stringify(u.arrayViews || u.transforms) : "", O = t.join(".") + ":" + b + ":" + U;
|
|
650
650
|
if (S.has(O))
|
|
651
651
|
return S.get(O);
|
|
652
652
|
const F = [e, ...t].join("."), x = {
|
|
@@ -657,7 +657,7 @@ function Pe(e, r, l, a) {
|
|
|
657
657
|
const o = [...t, m];
|
|
658
658
|
return c({
|
|
659
659
|
path: o,
|
|
660
|
-
componentId:
|
|
660
|
+
componentId: b,
|
|
661
661
|
meta: u
|
|
662
662
|
});
|
|
663
663
|
}
|
|
@@ -668,9 +668,9 @@ function Pe(e, r, l, a) {
|
|
|
668
668
|
const o = T.getState().getInitialOptions(e), n = o?.sync;
|
|
669
669
|
if (!n)
|
|
670
670
|
return console.error(`No mutation defined for state key "${e}"`), { success: !1, error: "No mutation defined" };
|
|
671
|
-
const
|
|
671
|
+
const f = T.getState().getShadowValue(e, []), v = o?.validation?.key;
|
|
672
672
|
try {
|
|
673
|
-
const h = await n.action(
|
|
673
|
+
const h = await n.action(f);
|
|
674
674
|
if (h && !h.success && h.errors, h?.success) {
|
|
675
675
|
const g = T.getState().getShadowMetadata(e, []);
|
|
676
676
|
J(e, [], {
|
|
@@ -678,7 +678,7 @@ function Pe(e, r, l, a) {
|
|
|
678
678
|
isDirty: !1,
|
|
679
679
|
lastServerSync: Date.now(),
|
|
680
680
|
stateSource: "server",
|
|
681
|
-
baseServerState:
|
|
681
|
+
baseServerState: f
|
|
682
682
|
// Update base server state
|
|
683
683
|
}), n.onSuccess && n.onSuccess(h.data);
|
|
684
684
|
} else !h?.success && n.onError && n.onError(h.error);
|
|
@@ -689,14 +689,14 @@ function Pe(e, r, l, a) {
|
|
|
689
689
|
};
|
|
690
690
|
if (m === "_status" || m === "getStatus") {
|
|
691
691
|
const o = () => {
|
|
692
|
-
const { shadowMeta: n, value:
|
|
693
|
-
return n?.isDirty === !0 ? "dirty" : n?.stateSource === "server" || n?.isDirty === !1 ? "synced" : n?.stateSource === "localStorage" ? "restored" : n?.stateSource === "default" ||
|
|
692
|
+
const { shadowMeta: n, value: f } = Q(e, t, u);
|
|
693
|
+
return n?.isDirty === !0 ? "dirty" : n?.stateSource === "server" || n?.isDirty === !1 ? "synced" : n?.stateSource === "localStorage" ? "restored" : n?.stateSource === "default" || f !== void 0 && !n ? "fresh" : "unknown";
|
|
694
694
|
};
|
|
695
695
|
return m === "_status" ? o() : o;
|
|
696
696
|
}
|
|
697
697
|
if (m === "removeStorage")
|
|
698
698
|
return () => {
|
|
699
|
-
const o = T.getState().initialStateGlobal[e], n = G(e),
|
|
699
|
+
const o = T.getState().initialStateGlobal[e], n = G(e), f = z(n?.localStorage?.key) ? n.localStorage.key(o) : n?.localStorage?.key, v = `${a}-${e}-${f}`;
|
|
700
700
|
v && localStorage.removeItem(v);
|
|
701
701
|
};
|
|
702
702
|
if (m === "showValidationErrors")
|
|
@@ -707,21 +707,21 @@ function Pe(e, r, l, a) {
|
|
|
707
707
|
if (m === "getSelected")
|
|
708
708
|
return () => {
|
|
709
709
|
const o = [e, ...t].join(".");
|
|
710
|
-
|
|
710
|
+
Ie(e, b, [
|
|
711
711
|
...t,
|
|
712
712
|
"getSelected"
|
|
713
713
|
]);
|
|
714
714
|
const n = T.getState().selectedIndicesMap.get(o);
|
|
715
715
|
if (!n)
|
|
716
716
|
return;
|
|
717
|
-
const
|
|
717
|
+
const f = t.join("."), v = u?.arrayViews?.[f], h = n.split(".").pop();
|
|
718
718
|
if (!(v && !v.includes(h) || R(
|
|
719
719
|
e,
|
|
720
720
|
n.split(".").slice(1)
|
|
721
721
|
) === void 0))
|
|
722
722
|
return c({
|
|
723
723
|
path: n.split(".").slice(1),
|
|
724
|
-
componentId:
|
|
724
|
+
componentId: b,
|
|
725
725
|
meta: u
|
|
726
726
|
});
|
|
727
727
|
};
|
|
@@ -732,11 +732,11 @@ function Pe(e, r, l, a) {
|
|
|
732
732
|
const n = T.getState().selectedIndicesMap.get(o);
|
|
733
733
|
if (!n)
|
|
734
734
|
return -1;
|
|
735
|
-
const { keys:
|
|
736
|
-
if (!
|
|
735
|
+
const { keys: f } = B(e, t, u);
|
|
736
|
+
if (!f)
|
|
737
737
|
return -1;
|
|
738
738
|
const v = n.split(".").pop();
|
|
739
|
-
return
|
|
739
|
+
return f.indexOf(v);
|
|
740
740
|
};
|
|
741
741
|
if (m === "clearSelected")
|
|
742
742
|
return ne(e, t), () => {
|
|
@@ -748,27 +748,27 @@ function Pe(e, r, l, a) {
|
|
|
748
748
|
return (o) => {
|
|
749
749
|
const {
|
|
750
750
|
itemHeight: n = 50,
|
|
751
|
-
overscan:
|
|
751
|
+
overscan: f = 6,
|
|
752
752
|
stickToBottom: v = !1,
|
|
753
753
|
scrollStickTolerance: h = 75
|
|
754
|
-
} = o, g = L(null), [y,
|
|
754
|
+
} = o, g = L(null), [y, w] = K({
|
|
755
755
|
startIndex: 0,
|
|
756
756
|
endIndex: 10
|
|
757
|
-
}), [
|
|
757
|
+
}), [E, _] = K({}), A = L(!0);
|
|
758
758
|
W(() => {
|
|
759
759
|
const C = setInterval(() => {
|
|
760
760
|
_({});
|
|
761
761
|
}, 1e3);
|
|
762
762
|
return () => clearInterval(C);
|
|
763
763
|
}, []);
|
|
764
|
-
const
|
|
764
|
+
const I = L({
|
|
765
765
|
isUserScrolling: !1,
|
|
766
766
|
lastScrollTop: 0,
|
|
767
767
|
scrollUpCount: 0,
|
|
768
768
|
isNearBottom: !0
|
|
769
769
|
}), D = L(
|
|
770
770
|
/* @__PURE__ */ new Map()
|
|
771
|
-
), { keys:
|
|
771
|
+
), { keys: M } = B(e, t, u);
|
|
772
772
|
W(() => {
|
|
773
773
|
const C = [e, ...t].join("."), P = T.getState().subscribeToPath(C, (j) => {
|
|
774
774
|
j.type !== "GET_SELECTED" && j.type;
|
|
@@ -776,41 +776,41 @@ function Pe(e, r, l, a) {
|
|
|
776
776
|
return () => {
|
|
777
777
|
P();
|
|
778
778
|
};
|
|
779
|
-
}, [
|
|
780
|
-
if (v &&
|
|
779
|
+
}, [b, e, t.join(".")]), ce(() => {
|
|
780
|
+
if (v && M.length > 0 && g.current && !I.current.isUserScrolling && A.current) {
|
|
781
781
|
const C = g.current, P = () => {
|
|
782
782
|
if (C.clientHeight > 0) {
|
|
783
783
|
const j = Math.ceil(
|
|
784
784
|
C.clientHeight / n
|
|
785
|
-
), q =
|
|
785
|
+
), q = M.length - 1, $ = Math.max(
|
|
786
786
|
0,
|
|
787
|
-
q - j -
|
|
787
|
+
q - j - f
|
|
788
788
|
);
|
|
789
|
-
|
|
790
|
-
Y("instant"),
|
|
789
|
+
w({ startIndex: $, endIndex: q }), requestAnimationFrame(() => {
|
|
790
|
+
Y("instant"), A.current = !1;
|
|
791
791
|
});
|
|
792
792
|
} else
|
|
793
793
|
requestAnimationFrame(P);
|
|
794
794
|
};
|
|
795
795
|
P();
|
|
796
796
|
}
|
|
797
|
-
}, [
|
|
797
|
+
}, [M.length, v, n, f]);
|
|
798
798
|
const k = L(y);
|
|
799
799
|
ce(() => {
|
|
800
800
|
k.current = y;
|
|
801
801
|
}, [y]);
|
|
802
|
-
const N = L(
|
|
802
|
+
const N = L(M);
|
|
803
803
|
ce(() => {
|
|
804
|
-
N.current =
|
|
805
|
-
}, [
|
|
806
|
-
const se =
|
|
804
|
+
N.current = M;
|
|
805
|
+
}, [M]);
|
|
806
|
+
const se = we(() => {
|
|
807
807
|
const C = g.current;
|
|
808
808
|
if (!C) return;
|
|
809
|
-
const P = C.scrollTop, { scrollHeight: j, clientHeight: q } = C, $ =
|
|
809
|
+
const P = C.scrollTop, { scrollHeight: j, clientHeight: q } = C, $ = I.current, re = j - (P + q), ge = $.isNearBottom;
|
|
810
810
|
$.isNearBottom = re <= h, P < $.lastScrollTop ? ($.scrollUpCount++, $.scrollUpCount > 3 && ge && ($.isUserScrolling = !0, console.log("User scrolled away from bottom"))) : $.isNearBottom && ($.isUserScrolling = !1, $.scrollUpCount = 0), $.lastScrollTop = P;
|
|
811
811
|
let Z = 0;
|
|
812
|
-
for (let H = 0; H <
|
|
813
|
-
const ye =
|
|
812
|
+
for (let H = 0; H < M.length; H++) {
|
|
813
|
+
const ye = M[H], me = D.current.get(ye);
|
|
814
814
|
if (me && me.offset + me.height > P) {
|
|
815
815
|
Z = H;
|
|
816
816
|
break;
|
|
@@ -823,19 +823,19 @@ function Pe(e, r, l, a) {
|
|
|
823
823
|
y
|
|
824
824
|
), Z !== y.startIndex && y.startIndex != 0) {
|
|
825
825
|
const H = Math.ceil(q / n);
|
|
826
|
-
|
|
827
|
-
startIndex: Math.max(0, Z -
|
|
826
|
+
w({
|
|
827
|
+
startIndex: Math.max(0, Z - f),
|
|
828
828
|
endIndex: Math.min(
|
|
829
|
-
|
|
830
|
-
Z + H +
|
|
829
|
+
M.length - 1,
|
|
830
|
+
Z + H + f
|
|
831
831
|
)
|
|
832
832
|
});
|
|
833
833
|
}
|
|
834
834
|
}, [
|
|
835
|
-
|
|
835
|
+
M.length,
|
|
836
836
|
y.startIndex,
|
|
837
837
|
n,
|
|
838
|
-
|
|
838
|
+
f,
|
|
839
839
|
h
|
|
840
840
|
]);
|
|
841
841
|
W(() => {
|
|
@@ -847,11 +847,11 @@ function Pe(e, r, l, a) {
|
|
|
847
847
|
C.removeEventListener("scroll", se);
|
|
848
848
|
};
|
|
849
849
|
}, [se, v]);
|
|
850
|
-
const Y =
|
|
850
|
+
const Y = we(
|
|
851
851
|
(C = "smooth") => {
|
|
852
852
|
const P = g.current;
|
|
853
853
|
if (!P) return;
|
|
854
|
-
|
|
854
|
+
I.current.isUserScrolling = !1, I.current.isNearBottom = !0, I.current.scrollUpCount = 0;
|
|
855
855
|
const j = () => {
|
|
856
856
|
const q = ($ = 0) => {
|
|
857
857
|
if ($ > 5) return;
|
|
@@ -874,12 +874,12 @@ function Pe(e, r, l, a) {
|
|
|
874
874
|
);
|
|
875
875
|
return W(() => {
|
|
876
876
|
if (!v || !g.current) return;
|
|
877
|
-
const C = g.current, P =
|
|
877
|
+
const C = g.current, P = I.current;
|
|
878
878
|
let j;
|
|
879
879
|
const q = () => {
|
|
880
880
|
clearTimeout(j), j = setTimeout(() => {
|
|
881
881
|
!P.isUserScrolling && P.isNearBottom && Y(
|
|
882
|
-
|
|
882
|
+
A.current ? "instant" : "smooth"
|
|
883
883
|
);
|
|
884
884
|
}, 100);
|
|
885
885
|
}, $ = new MutationObserver(() => {
|
|
@@ -890,24 +890,24 @@ function Pe(e, r, l, a) {
|
|
|
890
890
|
subtree: !0,
|
|
891
891
|
attributes: !0,
|
|
892
892
|
attributeFilter: ["style", "class"]
|
|
893
|
-
}),
|
|
893
|
+
}), A.current ? setTimeout(() => {
|
|
894
894
|
Y("instant");
|
|
895
895
|
}, 0) : q(), () => {
|
|
896
896
|
clearTimeout(j), $.disconnect();
|
|
897
897
|
};
|
|
898
|
-
}, [v,
|
|
899
|
-
virtualState:
|
|
900
|
-
const C = Array.isArray(
|
|
898
|
+
}, [v, M.length, Y]), {
|
|
899
|
+
virtualState: pe(() => {
|
|
900
|
+
const C = Array.isArray(M) ? M.slice(y.startIndex, y.endIndex + 1) : [], P = t.length > 0 ? t.join(".") : "root";
|
|
901
901
|
return c({
|
|
902
902
|
path: t,
|
|
903
|
-
componentId:
|
|
903
|
+
componentId: b,
|
|
904
904
|
meta: {
|
|
905
905
|
...u,
|
|
906
906
|
arrayViews: { [P]: C },
|
|
907
907
|
serverStateIsUpStream: !0
|
|
908
908
|
}
|
|
909
909
|
});
|
|
910
|
-
}, [y.startIndex, y.endIndex,
|
|
910
|
+
}, [y.startIndex, y.endIndex, M, u]),
|
|
911
911
|
virtualizerProps: {
|
|
912
912
|
outer: {
|
|
913
913
|
ref: g,
|
|
@@ -924,14 +924,14 @@ function Pe(e, r, l, a) {
|
|
|
924
924
|
},
|
|
925
925
|
list: {
|
|
926
926
|
style: {
|
|
927
|
-
transform: `translateY(${D.current.get(
|
|
927
|
+
transform: `translateY(${D.current.get(M[y.startIndex])?.offset || 0}px)`
|
|
928
928
|
}
|
|
929
929
|
}
|
|
930
930
|
},
|
|
931
931
|
scrollToBottom: Y,
|
|
932
932
|
scrollToIndex: (C, P = "smooth") => {
|
|
933
|
-
if (g.current &&
|
|
934
|
-
const j = D.current.get(
|
|
933
|
+
if (g.current && M[C]) {
|
|
934
|
+
const j = D.current.get(M[C])?.offset || 0;
|
|
935
935
|
g.current.scrollTo({ top: j, behavior: P });
|
|
936
936
|
}
|
|
937
937
|
}
|
|
@@ -939,33 +939,33 @@ function Pe(e, r, l, a) {
|
|
|
939
939
|
};
|
|
940
940
|
if (m === "stateMap")
|
|
941
941
|
return (o) => {
|
|
942
|
-
const { value: n, keys:
|
|
942
|
+
const { value: n, keys: f } = B(
|
|
943
943
|
e,
|
|
944
944
|
t,
|
|
945
945
|
u
|
|
946
946
|
);
|
|
947
|
-
if (!
|
|
947
|
+
if (!f || !Array.isArray(n))
|
|
948
948
|
return [];
|
|
949
949
|
const v = c({
|
|
950
950
|
path: t,
|
|
951
|
-
componentId:
|
|
951
|
+
componentId: b,
|
|
952
952
|
meta: u
|
|
953
953
|
});
|
|
954
954
|
return n.map((h, g) => {
|
|
955
|
-
const y =
|
|
955
|
+
const y = f[g];
|
|
956
956
|
if (!y) return;
|
|
957
|
-
const
|
|
958
|
-
path:
|
|
957
|
+
const w = [...t, y], E = c({
|
|
958
|
+
path: w,
|
|
959
959
|
// This now correctly points to the item in the shadow store.
|
|
960
|
-
componentId:
|
|
960
|
+
componentId: b,
|
|
961
961
|
meta: u
|
|
962
962
|
});
|
|
963
|
-
return o(
|
|
963
|
+
return o(E, g, v);
|
|
964
964
|
});
|
|
965
965
|
};
|
|
966
966
|
if (m === "stateFilter")
|
|
967
967
|
return (o) => {
|
|
968
|
-
const n = t.length > 0 ? t.join(".") : "root", { keys:
|
|
968
|
+
const n = t.length > 0 ? t.join(".") : "root", { keys: f, value: v } = B(
|
|
969
969
|
e,
|
|
970
970
|
t,
|
|
971
971
|
u
|
|
@@ -975,12 +975,12 @@ function Pe(e, r, l, a) {
|
|
|
975
975
|
const h = [];
|
|
976
976
|
return v.forEach((g, y) => {
|
|
977
977
|
if (o(g, y)) {
|
|
978
|
-
const
|
|
979
|
-
|
|
978
|
+
const w = f[y];
|
|
979
|
+
w && h.push(w);
|
|
980
980
|
}
|
|
981
981
|
}), c({
|
|
982
982
|
path: t,
|
|
983
|
-
componentId:
|
|
983
|
+
componentId: b,
|
|
984
984
|
meta: {
|
|
985
985
|
...u,
|
|
986
986
|
arrayViews: {
|
|
@@ -996,22 +996,22 @@ function Pe(e, r, l, a) {
|
|
|
996
996
|
};
|
|
997
997
|
if (m === "stateSort")
|
|
998
998
|
return (o) => {
|
|
999
|
-
const n = t.length > 0 ? t.join(".") : "root", { value:
|
|
999
|
+
const n = t.length > 0 ? t.join(".") : "root", { value: f, keys: v } = B(
|
|
1000
1000
|
e,
|
|
1001
1001
|
t,
|
|
1002
1002
|
u
|
|
1003
1003
|
);
|
|
1004
|
-
if (!Array.isArray(
|
|
1004
|
+
if (!Array.isArray(f) || !v)
|
|
1005
1005
|
throw new Error("No array keys found for sorting");
|
|
1006
|
-
const h =
|
|
1006
|
+
const h = f.map((y, w) => ({
|
|
1007
1007
|
item: y,
|
|
1008
|
-
key: v[
|
|
1008
|
+
key: v[w]
|
|
1009
1009
|
}));
|
|
1010
|
-
h.sort((y,
|
|
1010
|
+
h.sort((y, w) => o(y.item, w.item));
|
|
1011
1011
|
const g = h.map((y) => y.key);
|
|
1012
1012
|
return c({
|
|
1013
1013
|
path: t,
|
|
1014
|
-
componentId:
|
|
1014
|
+
componentId: b,
|
|
1015
1015
|
meta: {
|
|
1016
1016
|
...u,
|
|
1017
1017
|
arrayViews: {
|
|
@@ -1029,21 +1029,21 @@ function Pe(e, r, l, a) {
|
|
|
1029
1029
|
return function(o = {}) {
|
|
1030
1030
|
const {
|
|
1031
1031
|
bufferSize: n = 100,
|
|
1032
|
-
flushInterval:
|
|
1032
|
+
flushInterval: f = 100,
|
|
1033
1033
|
bufferStrategy: v = "accumulate",
|
|
1034
1034
|
store: h,
|
|
1035
1035
|
onFlush: g
|
|
1036
1036
|
} = o;
|
|
1037
|
-
let y = [],
|
|
1037
|
+
let y = [], w = !1, E = null;
|
|
1038
1038
|
const _ = (k) => {
|
|
1039
|
-
if (!
|
|
1039
|
+
if (!w) {
|
|
1040
1040
|
if (v === "sliding" && y.length >= n)
|
|
1041
1041
|
y.shift();
|
|
1042
1042
|
else if (v === "dropping" && y.length >= n)
|
|
1043
1043
|
return;
|
|
1044
|
-
y.push(k), y.length >= n &&
|
|
1044
|
+
y.push(k), y.length >= n && A();
|
|
1045
1045
|
}
|
|
1046
|
-
},
|
|
1046
|
+
}, A = () => {
|
|
1047
1047
|
if (y.length === 0) return;
|
|
1048
1048
|
const k = [...y];
|
|
1049
1049
|
if (y = [], h) {
|
|
@@ -1061,70 +1061,70 @@ function Pe(e, r, l, a) {
|
|
|
1061
1061
|
});
|
|
1062
1062
|
g?.(k);
|
|
1063
1063
|
};
|
|
1064
|
-
|
|
1065
|
-
const
|
|
1066
|
-
return
|
|
1064
|
+
f > 0 && (E = setInterval(A, f));
|
|
1065
|
+
const I = X(), D = V(e, t) || {}, M = D.streams || /* @__PURE__ */ new Map();
|
|
1066
|
+
return M.set(I, { buffer: y, flushTimer: E }), J(e, t, {
|
|
1067
1067
|
...D,
|
|
1068
|
-
streams:
|
|
1068
|
+
streams: M
|
|
1069
1069
|
}), {
|
|
1070
1070
|
write: (k) => _(k),
|
|
1071
1071
|
writeMany: (k) => k.forEach(_),
|
|
1072
|
-
flush: () =>
|
|
1072
|
+
flush: () => A(),
|
|
1073
1073
|
pause: () => {
|
|
1074
|
-
|
|
1074
|
+
w = !0;
|
|
1075
1075
|
},
|
|
1076
1076
|
resume: () => {
|
|
1077
|
-
|
|
1077
|
+
w = !1, y.length > 0 && A();
|
|
1078
1078
|
},
|
|
1079
1079
|
close: () => {
|
|
1080
|
-
|
|
1080
|
+
A(), E && clearInterval(E);
|
|
1081
1081
|
const k = T.getState().getShadowMetadata(e, t);
|
|
1082
|
-
k?.streams && k.streams.delete(
|
|
1082
|
+
k?.streams && k.streams.delete(I);
|
|
1083
1083
|
}
|
|
1084
1084
|
};
|
|
1085
1085
|
};
|
|
1086
1086
|
if (m === "stateList")
|
|
1087
1087
|
return (o) => /* @__PURE__ */ ie(() => {
|
|
1088
|
-
const
|
|
1088
|
+
const f = L(/* @__PURE__ */ new Map()), [v, h] = K({}), g = t.length > 0 ? t.join(".") : "root", y = ut(e, t, u), w = pe(() => ({
|
|
1089
1089
|
...u,
|
|
1090
1090
|
arrayViews: {
|
|
1091
1091
|
...u?.arrayViews || {},
|
|
1092
1092
|
[g]: y
|
|
1093
1093
|
}
|
|
1094
|
-
}), [u, g, y]), { value:
|
|
1094
|
+
}), [u, g, y]), { value: E } = B(
|
|
1095
1095
|
e,
|
|
1096
1096
|
t,
|
|
1097
|
-
|
|
1097
|
+
w
|
|
1098
1098
|
);
|
|
1099
1099
|
if (W(() => {
|
|
1100
|
-
const
|
|
1100
|
+
const I = T.getState().subscribeToPath(F, (D) => {
|
|
1101
1101
|
if (D.type === "GET_SELECTED")
|
|
1102
1102
|
return;
|
|
1103
1103
|
const k = T.getState().getShadowMetadata(e, t)?.transformCaches;
|
|
1104
1104
|
if (k)
|
|
1105
1105
|
for (const N of k.keys())
|
|
1106
|
-
N.startsWith(
|
|
1106
|
+
N.startsWith(b) && k.delete(N);
|
|
1107
1107
|
(D.type === "INSERT" || D.type === "INSERT_MANY" || D.type === "REMOVE" || D.type === "CLEAR_SELECTION" || D.type === "SERVER_STATE_UPDATE" && !u?.serverStateIsUpStream) && h({});
|
|
1108
1108
|
});
|
|
1109
1109
|
return () => {
|
|
1110
|
-
|
|
1110
|
+
I();
|
|
1111
1111
|
};
|
|
1112
|
-
}, [
|
|
1112
|
+
}, [b, F]), !Array.isArray(E))
|
|
1113
1113
|
return null;
|
|
1114
1114
|
const _ = c({
|
|
1115
1115
|
path: t,
|
|
1116
|
-
componentId:
|
|
1117
|
-
meta:
|
|
1116
|
+
componentId: b,
|
|
1117
|
+
meta: w
|
|
1118
1118
|
// Use updated meta here
|
|
1119
|
-
}),
|
|
1120
|
-
const
|
|
1121
|
-
if (!
|
|
1119
|
+
}), A = E.map((I, D) => {
|
|
1120
|
+
const M = y[D];
|
|
1121
|
+
if (!M)
|
|
1122
1122
|
return null;
|
|
1123
|
-
let k =
|
|
1124
|
-
k || (k = X(),
|
|
1125
|
-
const N = [...t,
|
|
1126
|
-
return
|
|
1127
|
-
key:
|
|
1123
|
+
let k = f.current.get(M);
|
|
1124
|
+
k || (k = X(), f.current.set(M, k));
|
|
1125
|
+
const N = [...t, M];
|
|
1126
|
+
return be(je, {
|
|
1127
|
+
key: M,
|
|
1128
1128
|
stateKey: e,
|
|
1129
1129
|
itemComponentId: k,
|
|
1130
1130
|
itemPath: N,
|
|
@@ -1134,25 +1134,25 @@ function Pe(e, r, l, a) {
|
|
|
1134
1134
|
renderFn: o
|
|
1135
1135
|
});
|
|
1136
1136
|
});
|
|
1137
|
-
return /* @__PURE__ */ ie(Ce, { children:
|
|
1137
|
+
return /* @__PURE__ */ ie(Ce, { children: A });
|
|
1138
1138
|
}, {});
|
|
1139
1139
|
if (m === "stateFlattenOn")
|
|
1140
1140
|
return (o) => {
|
|
1141
|
-
const n = t.length > 0 ? t.join(".") : "root",
|
|
1141
|
+
const n = t.length > 0 ? t.join(".") : "root", f = u?.arrayViews?.[n], v = T.getState().getShadowValue(e, t, f);
|
|
1142
1142
|
return Array.isArray(v) ? c({
|
|
1143
1143
|
path: [...t, "[*]", o],
|
|
1144
|
-
componentId:
|
|
1144
|
+
componentId: b,
|
|
1145
1145
|
meta: u
|
|
1146
1146
|
}) : [];
|
|
1147
1147
|
};
|
|
1148
1148
|
if (m === "index")
|
|
1149
1149
|
return (o) => {
|
|
1150
|
-
const n = t.length > 0 ? t.join(".") : "root",
|
|
1151
|
-
if (
|
|
1152
|
-
const g =
|
|
1150
|
+
const n = t.length > 0 ? t.join(".") : "root", f = u?.arrayViews?.[n];
|
|
1151
|
+
if (f) {
|
|
1152
|
+
const g = f[o];
|
|
1153
1153
|
return g ? c({
|
|
1154
1154
|
path: [...t, g],
|
|
1155
|
-
componentId:
|
|
1155
|
+
componentId: b,
|
|
1156
1156
|
meta: u
|
|
1157
1157
|
}) : void 0;
|
|
1158
1158
|
}
|
|
@@ -1162,7 +1162,7 @@ function Pe(e, r, l, a) {
|
|
|
1162
1162
|
if (h)
|
|
1163
1163
|
return c({
|
|
1164
1164
|
path: [...t, h],
|
|
1165
|
-
componentId:
|
|
1165
|
+
componentId: b,
|
|
1166
1166
|
meta: u
|
|
1167
1167
|
});
|
|
1168
1168
|
};
|
|
@@ -1174,10 +1174,10 @@ function Pe(e, r, l, a) {
|
|
|
1174
1174
|
const n = o[o.length - 1];
|
|
1175
1175
|
if (!n)
|
|
1176
1176
|
return;
|
|
1177
|
-
const
|
|
1177
|
+
const f = [...t, n];
|
|
1178
1178
|
return c({
|
|
1179
|
-
path:
|
|
1180
|
-
componentId:
|
|
1179
|
+
path: f,
|
|
1180
|
+
componentId: b,
|
|
1181
1181
|
meta: u
|
|
1182
1182
|
});
|
|
1183
1183
|
};
|
|
@@ -1186,35 +1186,35 @@ function Pe(e, r, l, a) {
|
|
|
1186
1186
|
r(o, t, { updateType: "insert" });
|
|
1187
1187
|
};
|
|
1188
1188
|
if (m === "uniqueInsert")
|
|
1189
|
-
return (o, n,
|
|
1189
|
+
return (o, n, f) => {
|
|
1190
1190
|
const { value: v } = Q(
|
|
1191
1191
|
e,
|
|
1192
1192
|
t,
|
|
1193
1193
|
u
|
|
1194
1194
|
), h = z(o) ? o(v) : o;
|
|
1195
1195
|
let g = null;
|
|
1196
|
-
if (!v.some((
|
|
1197
|
-
const
|
|
1198
|
-
(_) => ae(
|
|
1199
|
-
) : ae(
|
|
1200
|
-
return
|
|
1196
|
+
if (!v.some((w) => {
|
|
1197
|
+
const E = n ? n.every(
|
|
1198
|
+
(_) => ae(w[_], h[_])
|
|
1199
|
+
) : ae(w, h);
|
|
1200
|
+
return E && (g = w), E;
|
|
1201
1201
|
}))
|
|
1202
1202
|
r(h, t, { updateType: "insert" });
|
|
1203
|
-
else if (
|
|
1204
|
-
const
|
|
1205
|
-
(_) => ae(_, g) ?
|
|
1203
|
+
else if (f && g) {
|
|
1204
|
+
const w = f(g), E = v.map(
|
|
1205
|
+
(_) => ae(_, g) ? w : _
|
|
1206
1206
|
);
|
|
1207
|
-
r(
|
|
1207
|
+
r(E, t, {
|
|
1208
1208
|
updateType: "update"
|
|
1209
1209
|
});
|
|
1210
1210
|
}
|
|
1211
1211
|
};
|
|
1212
1212
|
if (m === "cut")
|
|
1213
1213
|
return (o, n) => {
|
|
1214
|
-
const
|
|
1215
|
-
if (!
|
|
1214
|
+
const f = V(e, t);
|
|
1215
|
+
if (!f?.arrayKeys || f.arrayKeys.length === 0)
|
|
1216
1216
|
return;
|
|
1217
|
-
const v = o === -1 ?
|
|
1217
|
+
const v = o === -1 ? f.arrayKeys.length - 1 : o !== void 0 ? o : f.arrayKeys.length - 1, h = f.arrayKeys[v];
|
|
1218
1218
|
h && r(null, [...t, h], {
|
|
1219
1219
|
updateType: "cut"
|
|
1220
1220
|
});
|
|
@@ -1224,13 +1224,13 @@ function Pe(e, r, l, a) {
|
|
|
1224
1224
|
const o = [e, ...t].join("."), { keys: n } = B(e, t, u);
|
|
1225
1225
|
if (!n || n.length === 0)
|
|
1226
1226
|
return;
|
|
1227
|
-
const
|
|
1228
|
-
if (!
|
|
1227
|
+
const f = T.getState().selectedIndicesMap.get(o);
|
|
1228
|
+
if (!f)
|
|
1229
1229
|
return;
|
|
1230
|
-
const v =
|
|
1230
|
+
const v = f.split(".").pop();
|
|
1231
1231
|
if (!n.includes(v))
|
|
1232
1232
|
return;
|
|
1233
|
-
const h =
|
|
1233
|
+
const h = f.split(".").slice(1);
|
|
1234
1234
|
T.getState().clearSelectedIndex({ arrayKey: o });
|
|
1235
1235
|
const g = h.slice(0, -1);
|
|
1236
1236
|
ne(e, g), r(null, h, {
|
|
@@ -1241,11 +1241,11 @@ function Pe(e, r, l, a) {
|
|
|
1241
1241
|
return (o) => {
|
|
1242
1242
|
const {
|
|
1243
1243
|
isArray: n,
|
|
1244
|
-
value:
|
|
1244
|
+
value: f,
|
|
1245
1245
|
keys: v
|
|
1246
1246
|
} = B(e, t, u);
|
|
1247
1247
|
if (!n) return;
|
|
1248
|
-
const h = he(
|
|
1248
|
+
const h = he(f, v, (g) => g === o);
|
|
1249
1249
|
h && r(null, [...t, h.key], {
|
|
1250
1250
|
updateType: "cut"
|
|
1251
1251
|
});
|
|
@@ -1254,11 +1254,11 @@ function Pe(e, r, l, a) {
|
|
|
1254
1254
|
return (o) => {
|
|
1255
1255
|
const {
|
|
1256
1256
|
isArray: n,
|
|
1257
|
-
value:
|
|
1257
|
+
value: f,
|
|
1258
1258
|
keys: v
|
|
1259
1259
|
} = B(e, t, u);
|
|
1260
1260
|
if (!n) return;
|
|
1261
|
-
const h = he(
|
|
1261
|
+
const h = he(f, v, (g) => g === o);
|
|
1262
1262
|
if (h) {
|
|
1263
1263
|
const g = [...t, h.key];
|
|
1264
1264
|
r(null, g, {
|
|
@@ -1269,8 +1269,8 @@ function Pe(e, r, l, a) {
|
|
|
1269
1269
|
};
|
|
1270
1270
|
if (m === "findWith")
|
|
1271
1271
|
return (o, n) => {
|
|
1272
|
-
const { isArray:
|
|
1273
|
-
if (!
|
|
1272
|
+
const { isArray: f, value: v, keys: h } = B(e, t, u);
|
|
1273
|
+
if (!f)
|
|
1274
1274
|
throw new Error("findWith can only be used on arrays");
|
|
1275
1275
|
const g = he(
|
|
1276
1276
|
v,
|
|
@@ -1279,11 +1279,11 @@ function Pe(e, r, l, a) {
|
|
|
1279
1279
|
);
|
|
1280
1280
|
return c(g ? {
|
|
1281
1281
|
path: [...t, g.key],
|
|
1282
|
-
componentId:
|
|
1282
|
+
componentId: b,
|
|
1283
1283
|
meta: u
|
|
1284
1284
|
} : {
|
|
1285
1285
|
path: [...t, `not_found_${X()}`],
|
|
1286
|
-
componentId:
|
|
1286
|
+
componentId: b,
|
|
1287
1287
|
meta: u
|
|
1288
1288
|
});
|
|
1289
1289
|
};
|
|
@@ -1295,7 +1295,7 @@ function Pe(e, r, l, a) {
|
|
|
1295
1295
|
}
|
|
1296
1296
|
if (m === "get")
|
|
1297
1297
|
return () => {
|
|
1298
|
-
|
|
1298
|
+
Ie(e, b, t);
|
|
1299
1299
|
const { value: o } = Q(e, t, u);
|
|
1300
1300
|
return o;
|
|
1301
1301
|
};
|
|
@@ -1317,30 +1317,30 @@ function Pe(e, r, l, a) {
|
|
|
1317
1317
|
if (m === "isSelected") {
|
|
1318
1318
|
const o = t.slice(0, -1);
|
|
1319
1319
|
if (V(e, o)?.arrayKeys) {
|
|
1320
|
-
const
|
|
1320
|
+
const f = e + "." + o.join("."), v = T.getState().selectedIndicesMap.get(f), h = e + "." + t.join(".");
|
|
1321
1321
|
return v === h;
|
|
1322
1322
|
}
|
|
1323
1323
|
return;
|
|
1324
1324
|
}
|
|
1325
1325
|
if (m === "setSelected")
|
|
1326
1326
|
return (o) => {
|
|
1327
|
-
const n = t.slice(0, -1),
|
|
1328
|
-
ne(e, n, void 0), T.getState().selectedIndicesMap.get(
|
|
1327
|
+
const n = t.slice(0, -1), f = e + "." + n.join("."), v = e + "." + t.join(".");
|
|
1328
|
+
ne(e, n, void 0), T.getState().selectedIndicesMap.get(f), o && T.getState().setSelectedIndex(f, v);
|
|
1329
1329
|
};
|
|
1330
1330
|
if (m === "toggleSelected")
|
|
1331
1331
|
return () => {
|
|
1332
|
-
const o = t.slice(0, -1), n = e + "." + o.join("."),
|
|
1333
|
-
T.getState().selectedIndicesMap.get(n) ===
|
|
1332
|
+
const o = t.slice(0, -1), n = e + "." + o.join("."), f = e + "." + t.join(".");
|
|
1333
|
+
T.getState().selectedIndicesMap.get(n) === f ? T.getState().clearSelectedIndex({ arrayKey: n }) : T.getState().setSelectedIndex(n, f), ne(e, o);
|
|
1334
1334
|
};
|
|
1335
1335
|
if (m === "_componentId")
|
|
1336
|
-
return
|
|
1336
|
+
return b;
|
|
1337
1337
|
if (t.length == 0) {
|
|
1338
1338
|
if (m === "addZodValidation")
|
|
1339
1339
|
return (o) => {
|
|
1340
1340
|
o.forEach((n) => {
|
|
1341
|
-
const
|
|
1341
|
+
const f = T.getState().getShadowMetadata(e, n.path) || {};
|
|
1342
1342
|
T.getState().setShadowMetadata(e, n.path, {
|
|
1343
|
-
...
|
|
1343
|
+
...f,
|
|
1344
1344
|
validation: {
|
|
1345
1345
|
status: "INVALID",
|
|
1346
1346
|
errors: [
|
|
@@ -1373,48 +1373,48 @@ function Pe(e, r, l, a) {
|
|
|
1373
1373
|
};
|
|
1374
1374
|
if (m === "applyJsonPatch")
|
|
1375
1375
|
return (o) => {
|
|
1376
|
-
const n = T.getState(),
|
|
1377
|
-
if (!
|
|
1376
|
+
const n = T.getState(), f = n.getShadowMetadata(e, []);
|
|
1377
|
+
if (!f?.components) return;
|
|
1378
1378
|
const v = (g) => !g || g === "/" ? [] : g.split("/").slice(1).map((y) => y.replace(/~1/g, "/").replace(/~0/g, "~")), h = /* @__PURE__ */ new Set();
|
|
1379
1379
|
for (const g of o) {
|
|
1380
1380
|
const y = v(g.path);
|
|
1381
1381
|
switch (g.op) {
|
|
1382
1382
|
case "add":
|
|
1383
1383
|
case "replace": {
|
|
1384
|
-
const { value:
|
|
1385
|
-
n.updateShadowAtPath(e, y,
|
|
1386
|
-
let
|
|
1384
|
+
const { value: w } = g;
|
|
1385
|
+
n.updateShadowAtPath(e, y, w), n.markAsDirty(e, y, { bubble: !0 });
|
|
1386
|
+
let E = [...y];
|
|
1387
1387
|
for (; ; ) {
|
|
1388
1388
|
const _ = n.getShadowMetadata(
|
|
1389
1389
|
e,
|
|
1390
|
-
|
|
1390
|
+
E
|
|
1391
1391
|
);
|
|
1392
|
-
if (_?.pathComponents && _.pathComponents.forEach((
|
|
1393
|
-
if (!h.has(
|
|
1394
|
-
const
|
|
1395
|
-
|
|
1392
|
+
if (_?.pathComponents && _.pathComponents.forEach((A) => {
|
|
1393
|
+
if (!h.has(A)) {
|
|
1394
|
+
const I = f.components?.get(A);
|
|
1395
|
+
I && (I.forceUpdate(), h.add(A));
|
|
1396
1396
|
}
|
|
1397
|
-
}),
|
|
1398
|
-
|
|
1397
|
+
}), E.length === 0) break;
|
|
1398
|
+
E.pop();
|
|
1399
1399
|
}
|
|
1400
1400
|
break;
|
|
1401
1401
|
}
|
|
1402
1402
|
case "remove": {
|
|
1403
|
-
const
|
|
1404
|
-
n.removeShadowArrayElement(e, y), n.markAsDirty(e,
|
|
1405
|
-
let
|
|
1403
|
+
const w = y.slice(0, -1);
|
|
1404
|
+
n.removeShadowArrayElement(e, y), n.markAsDirty(e, w, { bubble: !0 });
|
|
1405
|
+
let E = [...w];
|
|
1406
1406
|
for (; ; ) {
|
|
1407
1407
|
const _ = n.getShadowMetadata(
|
|
1408
1408
|
e,
|
|
1409
|
-
|
|
1409
|
+
E
|
|
1410
1410
|
);
|
|
1411
|
-
if (_?.pathComponents && _.pathComponents.forEach((
|
|
1412
|
-
if (!h.has(
|
|
1413
|
-
const
|
|
1414
|
-
|
|
1411
|
+
if (_?.pathComponents && _.pathComponents.forEach((A) => {
|
|
1412
|
+
if (!h.has(A)) {
|
|
1413
|
+
const I = f.components?.get(A);
|
|
1414
|
+
I && (I.forceUpdate(), h.add(A));
|
|
1415
1415
|
}
|
|
1416
|
-
}),
|
|
1417
|
-
|
|
1416
|
+
}), E.length === 0) break;
|
|
1417
|
+
E.pop();
|
|
1418
1418
|
}
|
|
1419
1419
|
break;
|
|
1420
1420
|
}
|
|
@@ -1424,10 +1424,10 @@ function Pe(e, r, l, a) {
|
|
|
1424
1424
|
if (m === "getComponents")
|
|
1425
1425
|
return () => V(e, [])?.components;
|
|
1426
1426
|
if (m === "getAllFormRefs")
|
|
1427
|
-
return () =>
|
|
1427
|
+
return () => Me.getState().getFormRefsByStateKey(e);
|
|
1428
1428
|
}
|
|
1429
1429
|
if (m === "getFormRef")
|
|
1430
|
-
return () =>
|
|
1430
|
+
return () => Me.getState().getFormRef(e + "." + t.join("."));
|
|
1431
1431
|
if (m === "validationWrapper")
|
|
1432
1432
|
return ({
|
|
1433
1433
|
children: o,
|
|
@@ -1453,8 +1453,8 @@ function Pe(e, r, l, a) {
|
|
|
1453
1453
|
stateSource: "server",
|
|
1454
1454
|
lastServerSync: Date.now()
|
|
1455
1455
|
});
|
|
1456
|
-
const
|
|
1457
|
-
Qe(
|
|
1456
|
+
const f = [e, ...t].join(".");
|
|
1457
|
+
Qe(f, {
|
|
1458
1458
|
type: "SYNC_STATUS_CHANGE",
|
|
1459
1459
|
isDirty: !1
|
|
1460
1460
|
});
|
|
@@ -1489,28 +1489,28 @@ function Pe(e, r, l, a) {
|
|
|
1489
1489
|
const te = [...t, m];
|
|
1490
1490
|
return T.getState().getShadowValue(e, te), c({
|
|
1491
1491
|
path: te,
|
|
1492
|
-
componentId:
|
|
1492
|
+
componentId: b,
|
|
1493
1493
|
meta: u
|
|
1494
1494
|
});
|
|
1495
1495
|
}
|
|
1496
|
-
},
|
|
1497
|
-
return S.set(O,
|
|
1496
|
+
}, p = new Proxy({}, x);
|
|
1497
|
+
return S.set(O, p), p;
|
|
1498
1498
|
}
|
|
1499
1499
|
const i = {
|
|
1500
1500
|
revertToInitialState: (t) => {
|
|
1501
1501
|
const u = T.getState().getShadowMetadata(e, []);
|
|
1502
1502
|
u?.stateSource === "server" && u.baseServerState ? u.baseServerState : T.getState().initialStateGlobal[e];
|
|
1503
|
-
const
|
|
1504
|
-
He(e), oe(e,
|
|
1503
|
+
const b = T.getState().initialStateGlobal[e];
|
|
1504
|
+
He(e), oe(e, b), c({
|
|
1505
1505
|
path: [],
|
|
1506
1506
|
componentId: l
|
|
1507
1507
|
});
|
|
1508
|
-
const U = G(e), O = z(U?.localStorage?.key) ? U?.localStorage?.key(
|
|
1508
|
+
const U = G(e), O = z(U?.localStorage?.key) ? U?.localStorage?.key(b) : U?.localStorage?.key, F = `${a}-${e}-${O}`;
|
|
1509
1509
|
F && localStorage.removeItem(F);
|
|
1510
1510
|
const x = T.getState().getShadowMetadata(e, []);
|
|
1511
|
-
return x && x?.components?.forEach((
|
|
1512
|
-
|
|
1513
|
-
}),
|
|
1511
|
+
return x && x?.components?.forEach((p) => {
|
|
1512
|
+
p.forceUpdate();
|
|
1513
|
+
}), b;
|
|
1514
1514
|
},
|
|
1515
1515
|
updateInitialState: (t) => {
|
|
1516
1516
|
const u = Pe(
|
|
@@ -1518,12 +1518,12 @@ function Pe(e, r, l, a) {
|
|
|
1518
1518
|
r,
|
|
1519
1519
|
l,
|
|
1520
1520
|
a
|
|
1521
|
-
),
|
|
1521
|
+
), b = T.getState().initialStateGlobal[e], U = G(e), O = z(U?.localStorage?.key) ? U?.localStorage?.key(b) : U?.localStorage?.key, F = `${a}-${e}-${O}`;
|
|
1522
1522
|
return localStorage.getItem(F) && localStorage.removeItem(F), De(() => {
|
|
1523
1523
|
ke(e, t), oe(e, t);
|
|
1524
1524
|
const x = T.getState().getShadowMetadata(e, []);
|
|
1525
|
-
x && x?.components?.forEach((
|
|
1526
|
-
|
|
1525
|
+
x && x?.components?.forEach((p) => {
|
|
1526
|
+
p.forceUpdate();
|
|
1527
1527
|
});
|
|
1528
1528
|
}), {
|
|
1529
1529
|
fetchId: (x) => u.get()[x]
|
|
@@ -1536,21 +1536,21 @@ function Pe(e, r, l, a) {
|
|
|
1536
1536
|
});
|
|
1537
1537
|
}
|
|
1538
1538
|
function _e(e) {
|
|
1539
|
-
return
|
|
1539
|
+
return be(ft, { proxy: e });
|
|
1540
1540
|
}
|
|
1541
|
-
function
|
|
1541
|
+
function ft({
|
|
1542
1542
|
proxy: e
|
|
1543
1543
|
}) {
|
|
1544
1544
|
const r = L(null), l = L(null), a = L(!1), S = `${e._stateKey}-${e._path.join(".")}`, s = e._path.length > 0 ? e._path.join(".") : "root", c = e._meta?.arrayViews?.[s], i = R(e._stateKey, e._path, c);
|
|
1545
1545
|
return W(() => {
|
|
1546
|
-
const
|
|
1547
|
-
if (!
|
|
1546
|
+
const d = r.current;
|
|
1547
|
+
if (!d || a.current) return;
|
|
1548
1548
|
const t = setTimeout(() => {
|
|
1549
|
-
if (!
|
|
1549
|
+
if (!d.parentElement) {
|
|
1550
1550
|
console.warn("Parent element not found for signal", S);
|
|
1551
1551
|
return;
|
|
1552
1552
|
}
|
|
1553
|
-
const u =
|
|
1553
|
+
const u = d.parentElement, U = Array.from(u.childNodes).indexOf(d);
|
|
1554
1554
|
let O = u.getAttribute("data-parent-id");
|
|
1555
1555
|
O || (O = `parent-${crypto.randomUUID()}`, u.setAttribute("data-parent-id", O)), l.current = `instance-${crypto.randomUUID()}`;
|
|
1556
1556
|
const F = T.getState().getShadowMetadata(e._stateKey, e._path) || {}, x = F.signals || [];
|
|
@@ -1563,29 +1563,29 @@ function dt({
|
|
|
1563
1563
|
...F,
|
|
1564
1564
|
signals: x
|
|
1565
1565
|
});
|
|
1566
|
-
let
|
|
1566
|
+
let p = i;
|
|
1567
1567
|
if (e._effect)
|
|
1568
1568
|
try {
|
|
1569
|
-
|
|
1569
|
+
p = new Function(
|
|
1570
1570
|
"state",
|
|
1571
1571
|
`return (${e._effect})(state)`
|
|
1572
1572
|
)(i);
|
|
1573
1573
|
} catch (m) {
|
|
1574
1574
|
console.error("Error evaluating effect function:", m);
|
|
1575
1575
|
}
|
|
1576
|
-
|
|
1577
|
-
const ee = document.createTextNode(String(
|
|
1578
|
-
|
|
1576
|
+
p !== null && typeof p == "object" && (p = JSON.stringify(p));
|
|
1577
|
+
const ee = document.createTextNode(String(p ?? ""));
|
|
1578
|
+
d.replaceWith(ee), a.current = !0;
|
|
1579
1579
|
}, 0);
|
|
1580
1580
|
return () => {
|
|
1581
1581
|
if (clearTimeout(t), l.current) {
|
|
1582
1582
|
const u = T.getState().getShadowMetadata(e._stateKey, e._path) || {};
|
|
1583
1583
|
u.signals && (u.signals = u.signals.filter(
|
|
1584
|
-
(
|
|
1584
|
+
(b) => b.instanceId !== l.current
|
|
1585
1585
|
), T.getState().setShadowMetadata(e._stateKey, e._path, u));
|
|
1586
1586
|
}
|
|
1587
1587
|
};
|
|
1588
|
-
}, []),
|
|
1588
|
+
}, []), be("span", {
|
|
1589
1589
|
ref: r,
|
|
1590
1590
|
style: { display: "contents" },
|
|
1591
1591
|
"data-signal-id": S
|
|
@@ -1593,9 +1593,9 @@ function dt({
|
|
|
1593
1593
|
}
|
|
1594
1594
|
export {
|
|
1595
1595
|
_e as $cogsSignal,
|
|
1596
|
-
|
|
1596
|
+
At as addStateOptions,
|
|
1597
1597
|
Xe as createCogsState,
|
|
1598
|
-
|
|
1598
|
+
It as createCogsStateFromSync,
|
|
1599
1599
|
lt as useCogsStateFn
|
|
1600
1600
|
};
|
|
1601
1601
|
//# sourceMappingURL=CogsState.jsx.map
|