cogsbox-state 0.5.466 → 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 +382 -388
- 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/dist/store.d.ts +0 -1
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +264 -268
- package/dist/store.js.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +8 -16
- package/src/Components.tsx +1 -0
- package/src/store.ts +199 -164
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 we, useLayoutEffect as ce, useMemo 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
|
-
import { ValidationWrapper as
|
|
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,
|
|
@@ -20,11 +20,11 @@ const {
|
|
|
20
20
|
insertManyShadowArrayElements: qe,
|
|
21
21
|
removeShadowArrayElement: Be,
|
|
22
22
|
getSelectedIndex: Tt,
|
|
23
|
-
setInitialStateOptions:
|
|
23
|
+
setInitialStateOptions: le,
|
|
24
24
|
setServerStateUpdate: We,
|
|
25
|
-
markAsDirty:
|
|
26
|
-
registerComponent:
|
|
27
|
-
unregisterComponent:
|
|
25
|
+
markAsDirty: ue,
|
|
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) {
|
|
@@ -42,7 +42,7 @@ function B(e, r, l) {
|
|
|
42
42
|
const s = r.length > 0 ? r.join(".") : "root", c = l?.arrayViews?.[s] ?? a.arrayKeys;
|
|
43
43
|
return Array.isArray(c) && c.length === 0 ? { isArray: !0, value: [], keys: [] } : { isArray: !0, value: T.getState().getShadowValue(e, r, c), keys: c ?? [] };
|
|
44
44
|
}
|
|
45
|
-
function
|
|
45
|
+
function he(e, r, l) {
|
|
46
46
|
for (let a = 0; a < e.length; a++)
|
|
47
47
|
if (l(e[a], a)) {
|
|
48
48
|
const S = r[a];
|
|
@@ -51,14 +51,14 @@ function ve(e, r, l) {
|
|
|
51
51
|
}
|
|
52
52
|
return null;
|
|
53
53
|
}
|
|
54
|
-
function
|
|
54
|
+
function ve(e, r) {
|
|
55
55
|
const l = G(e) || {};
|
|
56
|
-
|
|
56
|
+
le(e, {
|
|
57
57
|
...l,
|
|
58
58
|
...r
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
|
-
function
|
|
61
|
+
function Ae({
|
|
62
62
|
stateKey: e,
|
|
63
63
|
options: r,
|
|
64
64
|
initialOptionsPart: l
|
|
@@ -68,67 +68,67 @@ function Me({
|
|
|
68
68
|
if (r)
|
|
69
69
|
for (const i in r)
|
|
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
|
-
s.syncOptions && (!r || !r.hasOwnProperty("syncOptions")) && (c = !0), c &&
|
|
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
|
-
u ?
|
|
95
|
+
u ? le(i, {
|
|
96
96
|
...u,
|
|
97
97
|
...t
|
|
98
|
-
}) :
|
|
98
|
+
}) : le(i, t);
|
|
99
99
|
}
|
|
100
100
|
}), Object.keys(a).forEach((i) => {
|
|
101
101
|
oe(i, a[i]);
|
|
102
|
-
})
|
|
103
|
-
const s = (i,
|
|
104
|
-
const [t] = K(
|
|
105
|
-
|
|
102
|
+
});
|
|
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];
|
|
@@ -154,22 +154,22 @@ const Ke = (e, r, l, a, S) => {
|
|
|
154
154
|
const c = `${a}-${r}-${s}`;
|
|
155
155
|
let i;
|
|
156
156
|
try {
|
|
157
|
-
i =
|
|
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,
|
|
169
169
|
JSON.stringify(u.json)
|
|
170
170
|
);
|
|
171
171
|
}
|
|
172
|
-
},
|
|
172
|
+
}, Se = (e) => {
|
|
173
173
|
if (!e) return null;
|
|
174
174
|
try {
|
|
175
175
|
const r = window.localStorage.getItem(e);
|
|
@@ -180,14 +180,14 @@ const Ke = (e, r, l, a, S) => {
|
|
|
180
180
|
}, et = (e, r) => {
|
|
181
181
|
const l = R(e, []), { sessionId: a } = Ve(), S = z(r?.localStorage?.key) ? r.localStorage.key(l) : r?.localStorage?.key;
|
|
182
182
|
if (S && a) {
|
|
183
|
-
const s =
|
|
183
|
+
const s = Se(
|
|
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();
|
|
@@ -207,10 +207,10 @@ function fe(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
|
|
210
|
+
const d = [...r, c], t = l[i];
|
|
211
211
|
t !== void 0 && fe(
|
|
212
212
|
e,
|
|
213
|
-
|
|
213
|
+
d,
|
|
214
214
|
t,
|
|
215
215
|
a
|
|
216
216
|
);
|
|
@@ -220,13 +220,13 @@ function fe(e, r, l, a) {
|
|
|
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
|
}
|
|
227
227
|
function rt(e, r, l) {
|
|
228
228
|
const a = T.getState().getShadowValue(e, r), S = z(l) ? l(a) : l;
|
|
229
|
-
Re(e, r, S),
|
|
229
|
+
Re(e, r, S), ue(e, r, { bubble: !0 });
|
|
230
230
|
const s = V(e, r);
|
|
231
231
|
return {
|
|
232
232
|
type: "update",
|
|
@@ -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;
|
|
@@ -301,24 +301,24 @@ function ot(e, r, l) {
|
|
|
301
301
|
a = l({ state: s, uuid: X() });
|
|
302
302
|
} else
|
|
303
303
|
a = l;
|
|
304
|
-
Le(e, r, a),
|
|
304
|
+
Le(e, r, a), ue(e, r, { bubble: !0 });
|
|
305
305
|
const S = V(e, r);
|
|
306
306
|
if (S?.arrayKeys) {
|
|
307
307
|
const s = S.arrayKeys[S.arrayKeys.length - 1];
|
|
308
308
|
if (s) {
|
|
309
309
|
const c = s.split(".").slice(1);
|
|
310
|
-
|
|
310
|
+
ue(e, c, { bubble: !1 });
|
|
311
311
|
}
|
|
312
312
|
}
|
|
313
313
|
return { type: "insert", newValue: a, shadowMeta: S };
|
|
314
314
|
}
|
|
315
315
|
function st(e, r) {
|
|
316
316
|
const l = r.slice(0, -1), a = R(e, r);
|
|
317
|
-
return Be(e, r),
|
|
317
|
+
return Be(e, r), ue(e, l, { bubble: !0 }), { type: "cut", oldValue: a, parentPath: l };
|
|
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
|
-
}, [
|
|
402
|
+
}, [d]);
|
|
403
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
|
-
|
|
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((
|
|
451
|
-
),
|
|
452
|
-
(
|
|
450
|
+
_.map((N) => N[I])
|
|
451
|
+
), M = A.filter(
|
|
452
|
+
(N) => !D.has(N[I])
|
|
453
453
|
);
|
|
454
|
-
|
|
455
|
-
const k = R(
|
|
454
|
+
M.length > 0 && qe(p, [], M);
|
|
455
|
+
const k = R(p, []);
|
|
456
456
|
fe(
|
|
457
|
-
|
|
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 ||
|
|
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 &&
|
|
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,70 +748,70 @@ 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
|
-
const C = [e, ...t].join("."), P = T.getState().subscribeToPath(C, (
|
|
774
|
-
|
|
773
|
+
const C = [e, ...t].join("."), P = T.getState().subscribeToPath(C, (j) => {
|
|
774
|
+
j.type !== "GET_SELECTED" && j.type;
|
|
775
775
|
});
|
|
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
|
-
const
|
|
783
|
+
const j = Math.ceil(
|
|
784
784
|
C.clientHeight / n
|
|
785
|
-
), q =
|
|
785
|
+
), q = M.length - 1, $ = Math.max(
|
|
786
786
|
0,
|
|
787
|
-
q -
|
|
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
|
|
802
|
+
const N = L(M);
|
|
803
803
|
ce(() => {
|
|
804
|
-
|
|
805
|
-
}, [
|
|
804
|
+
N.current = M;
|
|
805
|
+
}, [M]);
|
|
806
806
|
const se = we(() => {
|
|
807
807
|
const C = g.current;
|
|
808
808
|
if (!C) return;
|
|
809
|
-
const P = C.scrollTop, { scrollHeight:
|
|
810
|
-
$.isNearBottom = re <= h, P < $.lastScrollTop ? ($.scrollUpCount++, $.scrollUpCount > 3 &&
|
|
809
|
+
const P = C.scrollTop, { scrollHeight: j, clientHeight: q } = C, $ = I.current, re = j - (P + q), ge = $.isNearBottom;
|
|
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
|
|
814
|
-
if (
|
|
812
|
+
for (let H = 0; H < M.length; H++) {
|
|
813
|
+
const ye = M[H], me = D.current.get(ye);
|
|
814
|
+
if (me && me.offset + me.height > P) {
|
|
815
815
|
Z = H;
|
|
816
816
|
break;
|
|
817
817
|
}
|
|
@@ -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(() => {
|
|
@@ -851,35 +851,35 @@ function Pe(e, r, l, a) {
|
|
|
851
851
|
(C = "smooth") => {
|
|
852
852
|
const P = g.current;
|
|
853
853
|
if (!P) return;
|
|
854
|
-
|
|
855
|
-
const
|
|
854
|
+
I.current.isUserScrolling = !1, I.current.isNearBottom = !0, I.current.scrollUpCount = 0;
|
|
855
|
+
const j = () => {
|
|
856
856
|
const q = ($ = 0) => {
|
|
857
857
|
if ($ > 5) return;
|
|
858
|
-
const re = P.scrollHeight,
|
|
859
|
-
|
|
858
|
+
const re = P.scrollHeight, ge = P.scrollTop, Z = P.clientHeight;
|
|
859
|
+
ge + Z >= re - 1 || (P.scrollTo({
|
|
860
860
|
top: re,
|
|
861
861
|
behavior: C
|
|
862
862
|
}), setTimeout(() => {
|
|
863
|
-
const H = P.scrollHeight,
|
|
864
|
-
(H !== re ||
|
|
863
|
+
const H = P.scrollHeight, ye = P.scrollTop;
|
|
864
|
+
(H !== re || ye + Z < H - 1) && q($ + 1);
|
|
865
865
|
}, 50));
|
|
866
866
|
};
|
|
867
867
|
q();
|
|
868
868
|
};
|
|
869
|
-
"requestIdleCallback" in window ? requestIdleCallback(
|
|
870
|
-
requestAnimationFrame(
|
|
869
|
+
"requestIdleCallback" in window ? requestIdleCallback(j, { timeout: 100 }) : requestAnimationFrame(() => {
|
|
870
|
+
requestAnimationFrame(j);
|
|
871
871
|
});
|
|
872
872
|
},
|
|
873
873
|
[]
|
|
874
874
|
);
|
|
875
875
|
return W(() => {
|
|
876
876
|
if (!v || !g.current) return;
|
|
877
|
-
const C = g.current, P =
|
|
878
|
-
let
|
|
877
|
+
const C = g.current, P = I.current;
|
|
878
|
+
let j;
|
|
879
879
|
const q = () => {
|
|
880
|
-
clearTimeout(
|
|
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
|
-
clearTimeout(
|
|
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,48 +924,48 @@ 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
|
|
935
|
-
g.current.scrollTo({ top:
|
|
933
|
+
if (g.current && M[C]) {
|
|
934
|
+
const j = D.current.get(M[C])?.offset || 0;
|
|
935
|
+
g.current.scrollTo({ top: j, behavior: P });
|
|
936
936
|
}
|
|
937
937
|
}
|
|
938
938
|
};
|
|
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,136 +1029,130 @@ 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) {
|
|
1050
|
-
const
|
|
1051
|
-
|
|
1050
|
+
const N = h(k);
|
|
1051
|
+
N !== void 0 && (Array.isArray(N) ? N : [N]).forEach((Y) => {
|
|
1052
1052
|
r(Y, t, {
|
|
1053
1053
|
updateType: "insert"
|
|
1054
1054
|
});
|
|
1055
1055
|
});
|
|
1056
1056
|
} else
|
|
1057
|
-
k.forEach((
|
|
1058
|
-
r(
|
|
1057
|
+
k.forEach((N) => {
|
|
1058
|
+
r(N, t, {
|
|
1059
1059
|
updateType: "insert"
|
|
1060
1060
|
});
|
|
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
|
|
1089
|
-
e,
|
|
1090
|
-
t.join("."),
|
|
1091
|
-
// Only recalculate if the underlying array keys or transforms change
|
|
1092
|
-
V(e, t)?.arrayKeys,
|
|
1093
|
-
u?.transforms
|
|
1094
|
-
]), p = le(() => ({
|
|
1088
|
+
const f = L(/* @__PURE__ */ new Map()), [v, h] = K({}), g = t.length > 0 ? t.join(".") : "root", y = ut(e, t, u), w = pe(() => ({
|
|
1095
1089
|
...u,
|
|
1096
1090
|
arrayViews: {
|
|
1097
1091
|
...u?.arrayViews || {},
|
|
1098
1092
|
[g]: y
|
|
1099
1093
|
}
|
|
1100
|
-
}), [u, g, y]), { value:
|
|
1094
|
+
}), [u, g, y]), { value: E } = B(
|
|
1101
1095
|
e,
|
|
1102
1096
|
t,
|
|
1103
|
-
|
|
1097
|
+
w
|
|
1104
1098
|
);
|
|
1105
1099
|
if (W(() => {
|
|
1106
|
-
const
|
|
1100
|
+
const I = T.getState().subscribeToPath(F, (D) => {
|
|
1107
1101
|
if (D.type === "GET_SELECTED")
|
|
1108
1102
|
return;
|
|
1109
1103
|
const k = T.getState().getShadowMetadata(e, t)?.transformCaches;
|
|
1110
1104
|
if (k)
|
|
1111
|
-
for (const
|
|
1112
|
-
|
|
1105
|
+
for (const N of k.keys())
|
|
1106
|
+
N.startsWith(b) && k.delete(N);
|
|
1113
1107
|
(D.type === "INSERT" || D.type === "INSERT_MANY" || D.type === "REMOVE" || D.type === "CLEAR_SELECTION" || D.type === "SERVER_STATE_UPDATE" && !u?.serverStateIsUpStream) && h({});
|
|
1114
1108
|
});
|
|
1115
1109
|
return () => {
|
|
1116
|
-
|
|
1110
|
+
I();
|
|
1117
1111
|
};
|
|
1118
|
-
}, [
|
|
1112
|
+
}, [b, F]), !Array.isArray(E))
|
|
1119
1113
|
return null;
|
|
1120
1114
|
const _ = c({
|
|
1121
1115
|
path: t,
|
|
1122
|
-
componentId:
|
|
1123
|
-
meta:
|
|
1116
|
+
componentId: b,
|
|
1117
|
+
meta: w
|
|
1124
1118
|
// Use updated meta here
|
|
1125
|
-
}),
|
|
1126
|
-
const
|
|
1127
|
-
if (!
|
|
1119
|
+
}), A = E.map((I, D) => {
|
|
1120
|
+
const M = y[D];
|
|
1121
|
+
if (!M)
|
|
1128
1122
|
return null;
|
|
1129
|
-
let k =
|
|
1130
|
-
k || (k = X(),
|
|
1131
|
-
const
|
|
1132
|
-
return
|
|
1133
|
-
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,
|
|
1134
1128
|
stateKey: e,
|
|
1135
1129
|
itemComponentId: k,
|
|
1136
|
-
itemPath:
|
|
1130
|
+
itemPath: N,
|
|
1137
1131
|
localIndex: D,
|
|
1138
1132
|
arraySetter: _,
|
|
1139
1133
|
rebuildStateShape: c,
|
|
1140
1134
|
renderFn: o
|
|
1141
1135
|
});
|
|
1142
1136
|
});
|
|
1143
|
-
return /* @__PURE__ */ ie(Ce, { children:
|
|
1137
|
+
return /* @__PURE__ */ ie(Ce, { children: A });
|
|
1144
1138
|
}, {});
|
|
1145
1139
|
if (m === "stateFlattenOn")
|
|
1146
1140
|
return (o) => {
|
|
1147
|
-
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);
|
|
1148
1142
|
return Array.isArray(v) ? c({
|
|
1149
1143
|
path: [...t, "[*]", o],
|
|
1150
|
-
componentId:
|
|
1144
|
+
componentId: b,
|
|
1151
1145
|
meta: u
|
|
1152
1146
|
}) : [];
|
|
1153
1147
|
};
|
|
1154
1148
|
if (m === "index")
|
|
1155
1149
|
return (o) => {
|
|
1156
|
-
const n = t.length > 0 ? t.join(".") : "root",
|
|
1157
|
-
if (
|
|
1158
|
-
const g =
|
|
1150
|
+
const n = t.length > 0 ? t.join(".") : "root", f = u?.arrayViews?.[n];
|
|
1151
|
+
if (f) {
|
|
1152
|
+
const g = f[o];
|
|
1159
1153
|
return g ? c({
|
|
1160
1154
|
path: [...t, g],
|
|
1161
|
-
componentId:
|
|
1155
|
+
componentId: b,
|
|
1162
1156
|
meta: u
|
|
1163
1157
|
}) : void 0;
|
|
1164
1158
|
}
|
|
@@ -1168,7 +1162,7 @@ function Pe(e, r, l, a) {
|
|
|
1168
1162
|
if (h)
|
|
1169
1163
|
return c({
|
|
1170
1164
|
path: [...t, h],
|
|
1171
|
-
componentId:
|
|
1165
|
+
componentId: b,
|
|
1172
1166
|
meta: u
|
|
1173
1167
|
});
|
|
1174
1168
|
};
|
|
@@ -1180,10 +1174,10 @@ function Pe(e, r, l, a) {
|
|
|
1180
1174
|
const n = o[o.length - 1];
|
|
1181
1175
|
if (!n)
|
|
1182
1176
|
return;
|
|
1183
|
-
const
|
|
1177
|
+
const f = [...t, n];
|
|
1184
1178
|
return c({
|
|
1185
|
-
path:
|
|
1186
|
-
componentId:
|
|
1179
|
+
path: f,
|
|
1180
|
+
componentId: b,
|
|
1187
1181
|
meta: u
|
|
1188
1182
|
});
|
|
1189
1183
|
};
|
|
@@ -1192,35 +1186,35 @@ function Pe(e, r, l, a) {
|
|
|
1192
1186
|
r(o, t, { updateType: "insert" });
|
|
1193
1187
|
};
|
|
1194
1188
|
if (m === "uniqueInsert")
|
|
1195
|
-
return (o, n,
|
|
1189
|
+
return (o, n, f) => {
|
|
1196
1190
|
const { value: v } = Q(
|
|
1197
1191
|
e,
|
|
1198
1192
|
t,
|
|
1199
1193
|
u
|
|
1200
1194
|
), h = z(o) ? o(v) : o;
|
|
1201
1195
|
let g = null;
|
|
1202
|
-
if (!v.some((
|
|
1203
|
-
const
|
|
1204
|
-
(_) => ae(
|
|
1205
|
-
) : ae(
|
|
1206
|
-
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;
|
|
1207
1201
|
}))
|
|
1208
1202
|
r(h, t, { updateType: "insert" });
|
|
1209
|
-
else if (
|
|
1210
|
-
const
|
|
1211
|
-
(_) => ae(_, g) ?
|
|
1203
|
+
else if (f && g) {
|
|
1204
|
+
const w = f(g), E = v.map(
|
|
1205
|
+
(_) => ae(_, g) ? w : _
|
|
1212
1206
|
);
|
|
1213
|
-
r(
|
|
1207
|
+
r(E, t, {
|
|
1214
1208
|
updateType: "update"
|
|
1215
1209
|
});
|
|
1216
1210
|
}
|
|
1217
1211
|
};
|
|
1218
1212
|
if (m === "cut")
|
|
1219
1213
|
return (o, n) => {
|
|
1220
|
-
const
|
|
1221
|
-
if (!
|
|
1214
|
+
const f = V(e, t);
|
|
1215
|
+
if (!f?.arrayKeys || f.arrayKeys.length === 0)
|
|
1222
1216
|
return;
|
|
1223
|
-
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];
|
|
1224
1218
|
h && r(null, [...t, h], {
|
|
1225
1219
|
updateType: "cut"
|
|
1226
1220
|
});
|
|
@@ -1230,13 +1224,13 @@ function Pe(e, r, l, a) {
|
|
|
1230
1224
|
const o = [e, ...t].join("."), { keys: n } = B(e, t, u);
|
|
1231
1225
|
if (!n || n.length === 0)
|
|
1232
1226
|
return;
|
|
1233
|
-
const
|
|
1234
|
-
if (!
|
|
1227
|
+
const f = T.getState().selectedIndicesMap.get(o);
|
|
1228
|
+
if (!f)
|
|
1235
1229
|
return;
|
|
1236
|
-
const v =
|
|
1230
|
+
const v = f.split(".").pop();
|
|
1237
1231
|
if (!n.includes(v))
|
|
1238
1232
|
return;
|
|
1239
|
-
const h =
|
|
1233
|
+
const h = f.split(".").slice(1);
|
|
1240
1234
|
T.getState().clearSelectedIndex({ arrayKey: o });
|
|
1241
1235
|
const g = h.slice(0, -1);
|
|
1242
1236
|
ne(e, g), r(null, h, {
|
|
@@ -1247,11 +1241,11 @@ function Pe(e, r, l, a) {
|
|
|
1247
1241
|
return (o) => {
|
|
1248
1242
|
const {
|
|
1249
1243
|
isArray: n,
|
|
1250
|
-
value:
|
|
1244
|
+
value: f,
|
|
1251
1245
|
keys: v
|
|
1252
1246
|
} = B(e, t, u);
|
|
1253
1247
|
if (!n) return;
|
|
1254
|
-
const h =
|
|
1248
|
+
const h = he(f, v, (g) => g === o);
|
|
1255
1249
|
h && r(null, [...t, h.key], {
|
|
1256
1250
|
updateType: "cut"
|
|
1257
1251
|
});
|
|
@@ -1260,11 +1254,11 @@ function Pe(e, r, l, a) {
|
|
|
1260
1254
|
return (o) => {
|
|
1261
1255
|
const {
|
|
1262
1256
|
isArray: n,
|
|
1263
|
-
value:
|
|
1257
|
+
value: f,
|
|
1264
1258
|
keys: v
|
|
1265
1259
|
} = B(e, t, u);
|
|
1266
1260
|
if (!n) return;
|
|
1267
|
-
const h =
|
|
1261
|
+
const h = he(f, v, (g) => g === o);
|
|
1268
1262
|
if (h) {
|
|
1269
1263
|
const g = [...t, h.key];
|
|
1270
1264
|
r(null, g, {
|
|
@@ -1275,21 +1269,21 @@ function Pe(e, r, l, a) {
|
|
|
1275
1269
|
};
|
|
1276
1270
|
if (m === "findWith")
|
|
1277
1271
|
return (o, n) => {
|
|
1278
|
-
const { isArray:
|
|
1279
|
-
if (!
|
|
1272
|
+
const { isArray: f, value: v, keys: h } = B(e, t, u);
|
|
1273
|
+
if (!f)
|
|
1280
1274
|
throw new Error("findWith can only be used on arrays");
|
|
1281
|
-
const g =
|
|
1275
|
+
const g = he(
|
|
1282
1276
|
v,
|
|
1283
1277
|
h,
|
|
1284
1278
|
(y) => y?.[o] === n
|
|
1285
1279
|
);
|
|
1286
1280
|
return c(g ? {
|
|
1287
1281
|
path: [...t, g.key],
|
|
1288
|
-
componentId:
|
|
1282
|
+
componentId: b,
|
|
1289
1283
|
meta: u
|
|
1290
1284
|
} : {
|
|
1291
1285
|
path: [...t, `not_found_${X()}`],
|
|
1292
|
-
componentId:
|
|
1286
|
+
componentId: b,
|
|
1293
1287
|
meta: u
|
|
1294
1288
|
});
|
|
1295
1289
|
};
|
|
@@ -1301,7 +1295,7 @@ function Pe(e, r, l, a) {
|
|
|
1301
1295
|
}
|
|
1302
1296
|
if (m === "get")
|
|
1303
1297
|
return () => {
|
|
1304
|
-
|
|
1298
|
+
Ie(e, b, t);
|
|
1305
1299
|
const { value: o } = Q(e, t, u);
|
|
1306
1300
|
return o;
|
|
1307
1301
|
};
|
|
@@ -1319,34 +1313,34 @@ function Pe(e, r, l, a) {
|
|
|
1319
1313
|
return Ye(o);
|
|
1320
1314
|
}
|
|
1321
1315
|
if (m == "getLocalStorage")
|
|
1322
|
-
return (o) =>
|
|
1316
|
+
return (o) => Se(a + "-" + e + "-" + o);
|
|
1323
1317
|
if (m === "isSelected") {
|
|
1324
1318
|
const o = t.slice(0, -1);
|
|
1325
1319
|
if (V(e, o)?.arrayKeys) {
|
|
1326
|
-
const
|
|
1320
|
+
const f = e + "." + o.join("."), v = T.getState().selectedIndicesMap.get(f), h = e + "." + t.join(".");
|
|
1327
1321
|
return v === h;
|
|
1328
1322
|
}
|
|
1329
1323
|
return;
|
|
1330
1324
|
}
|
|
1331
1325
|
if (m === "setSelected")
|
|
1332
1326
|
return (o) => {
|
|
1333
|
-
const n = t.slice(0, -1),
|
|
1334
|
-
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);
|
|
1335
1329
|
};
|
|
1336
1330
|
if (m === "toggleSelected")
|
|
1337
1331
|
return () => {
|
|
1338
|
-
const o = t.slice(0, -1), n = e + "." + o.join("."),
|
|
1339
|
-
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);
|
|
1340
1334
|
};
|
|
1341
1335
|
if (m === "_componentId")
|
|
1342
|
-
return
|
|
1336
|
+
return b;
|
|
1343
1337
|
if (t.length == 0) {
|
|
1344
1338
|
if (m === "addZodValidation")
|
|
1345
1339
|
return (o) => {
|
|
1346
1340
|
o.forEach((n) => {
|
|
1347
|
-
const
|
|
1341
|
+
const f = T.getState().getShadowMetadata(e, n.path) || {};
|
|
1348
1342
|
T.getState().setShadowMetadata(e, n.path, {
|
|
1349
|
-
...
|
|
1343
|
+
...f,
|
|
1350
1344
|
validation: {
|
|
1351
1345
|
status: "INVALID",
|
|
1352
1346
|
errors: [
|
|
@@ -1379,48 +1373,48 @@ function Pe(e, r, l, a) {
|
|
|
1379
1373
|
};
|
|
1380
1374
|
if (m === "applyJsonPatch")
|
|
1381
1375
|
return (o) => {
|
|
1382
|
-
const n = T.getState(),
|
|
1383
|
-
if (!
|
|
1376
|
+
const n = T.getState(), f = n.getShadowMetadata(e, []);
|
|
1377
|
+
if (!f?.components) return;
|
|
1384
1378
|
const v = (g) => !g || g === "/" ? [] : g.split("/").slice(1).map((y) => y.replace(/~1/g, "/").replace(/~0/g, "~")), h = /* @__PURE__ */ new Set();
|
|
1385
1379
|
for (const g of o) {
|
|
1386
1380
|
const y = v(g.path);
|
|
1387
1381
|
switch (g.op) {
|
|
1388
1382
|
case "add":
|
|
1389
1383
|
case "replace": {
|
|
1390
|
-
const { value:
|
|
1391
|
-
n.updateShadowAtPath(e, y,
|
|
1392
|
-
let
|
|
1384
|
+
const { value: w } = g;
|
|
1385
|
+
n.updateShadowAtPath(e, y, w), n.markAsDirty(e, y, { bubble: !0 });
|
|
1386
|
+
let E = [...y];
|
|
1393
1387
|
for (; ; ) {
|
|
1394
1388
|
const _ = n.getShadowMetadata(
|
|
1395
1389
|
e,
|
|
1396
|
-
|
|
1390
|
+
E
|
|
1397
1391
|
);
|
|
1398
|
-
if (_?.pathComponents && _.pathComponents.forEach((
|
|
1399
|
-
if (!h.has(
|
|
1400
|
-
const
|
|
1401
|
-
|
|
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));
|
|
1402
1396
|
}
|
|
1403
|
-
}),
|
|
1404
|
-
|
|
1397
|
+
}), E.length === 0) break;
|
|
1398
|
+
E.pop();
|
|
1405
1399
|
}
|
|
1406
1400
|
break;
|
|
1407
1401
|
}
|
|
1408
1402
|
case "remove": {
|
|
1409
|
-
const
|
|
1410
|
-
n.removeShadowArrayElement(e, y), n.markAsDirty(e,
|
|
1411
|
-
let
|
|
1403
|
+
const w = y.slice(0, -1);
|
|
1404
|
+
n.removeShadowArrayElement(e, y), n.markAsDirty(e, w, { bubble: !0 });
|
|
1405
|
+
let E = [...w];
|
|
1412
1406
|
for (; ; ) {
|
|
1413
1407
|
const _ = n.getShadowMetadata(
|
|
1414
1408
|
e,
|
|
1415
|
-
|
|
1409
|
+
E
|
|
1416
1410
|
);
|
|
1417
|
-
if (_?.pathComponents && _.pathComponents.forEach((
|
|
1418
|
-
if (!h.has(
|
|
1419
|
-
const
|
|
1420
|
-
|
|
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));
|
|
1421
1415
|
}
|
|
1422
|
-
}),
|
|
1423
|
-
|
|
1416
|
+
}), E.length === 0) break;
|
|
1417
|
+
E.pop();
|
|
1424
1418
|
}
|
|
1425
1419
|
break;
|
|
1426
1420
|
}
|
|
@@ -1430,16 +1424,16 @@ function Pe(e, r, l, a) {
|
|
|
1430
1424
|
if (m === "getComponents")
|
|
1431
1425
|
return () => V(e, [])?.components;
|
|
1432
1426
|
if (m === "getAllFormRefs")
|
|
1433
|
-
return () =>
|
|
1427
|
+
return () => Me.getState().getFormRefsByStateKey(e);
|
|
1434
1428
|
}
|
|
1435
1429
|
if (m === "getFormRef")
|
|
1436
|
-
return () =>
|
|
1430
|
+
return () => Me.getState().getFormRef(e + "." + t.join("."));
|
|
1437
1431
|
if (m === "validationWrapper")
|
|
1438
1432
|
return ({
|
|
1439
1433
|
children: o,
|
|
1440
1434
|
hideMessage: n
|
|
1441
1435
|
}) => /* @__PURE__ */ ie(
|
|
1442
|
-
|
|
1436
|
+
Ne,
|
|
1443
1437
|
{
|
|
1444
1438
|
formOpts: n ? { validation: { message: "" } } : void 0,
|
|
1445
1439
|
path: t,
|
|
@@ -1450,7 +1444,7 @@ function Pe(e, r, l, a) {
|
|
|
1450
1444
|
if (m === "_stateKey") return e;
|
|
1451
1445
|
if (m === "_path") return t;
|
|
1452
1446
|
if (m === "update")
|
|
1453
|
-
return (o) => (
|
|
1447
|
+
return (o) => (r(o, t, { updateType: "update" }), {
|
|
1454
1448
|
synced: () => {
|
|
1455
1449
|
const n = T.getState().getShadowMetadata(e, t);
|
|
1456
1450
|
J(e, t, {
|
|
@@ -1459,8 +1453,8 @@ function Pe(e, r, l, a) {
|
|
|
1459
1453
|
stateSource: "server",
|
|
1460
1454
|
lastServerSync: Date.now()
|
|
1461
1455
|
});
|
|
1462
|
-
const
|
|
1463
|
-
Qe(
|
|
1456
|
+
const f = [e, ...t].join(".");
|
|
1457
|
+
Qe(f, {
|
|
1464
1458
|
type: "SYNC_STATUS_CHANGE",
|
|
1465
1459
|
isDirty: !1
|
|
1466
1460
|
});
|
|
@@ -1495,28 +1489,28 @@ function Pe(e, r, l, a) {
|
|
|
1495
1489
|
const te = [...t, m];
|
|
1496
1490
|
return T.getState().getShadowValue(e, te), c({
|
|
1497
1491
|
path: te,
|
|
1498
|
-
componentId:
|
|
1492
|
+
componentId: b,
|
|
1499
1493
|
meta: u
|
|
1500
1494
|
});
|
|
1501
1495
|
}
|
|
1502
|
-
},
|
|
1503
|
-
return S.set(O,
|
|
1496
|
+
}, p = new Proxy({}, x);
|
|
1497
|
+
return S.set(O, p), p;
|
|
1504
1498
|
}
|
|
1505
1499
|
const i = {
|
|
1506
1500
|
revertToInitialState: (t) => {
|
|
1507
1501
|
const u = T.getState().getShadowMetadata(e, []);
|
|
1508
1502
|
u?.stateSource === "server" && u.baseServerState ? u.baseServerState : T.getState().initialStateGlobal[e];
|
|
1509
|
-
const
|
|
1510
|
-
He(e), oe(e,
|
|
1503
|
+
const b = T.getState().initialStateGlobal[e];
|
|
1504
|
+
He(e), oe(e, b), c({
|
|
1511
1505
|
path: [],
|
|
1512
1506
|
componentId: l
|
|
1513
1507
|
});
|
|
1514
|
-
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}`;
|
|
1515
1509
|
F && localStorage.removeItem(F);
|
|
1516
1510
|
const x = T.getState().getShadowMetadata(e, []);
|
|
1517
|
-
return x && x?.components?.forEach((
|
|
1518
|
-
|
|
1519
|
-
}),
|
|
1511
|
+
return x && x?.components?.forEach((p) => {
|
|
1512
|
+
p.forceUpdate();
|
|
1513
|
+
}), b;
|
|
1520
1514
|
},
|
|
1521
1515
|
updateInitialState: (t) => {
|
|
1522
1516
|
const u = Pe(
|
|
@@ -1524,12 +1518,12 @@ function Pe(e, r, l, a) {
|
|
|
1524
1518
|
r,
|
|
1525
1519
|
l,
|
|
1526
1520
|
a
|
|
1527
|
-
),
|
|
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}`;
|
|
1528
1522
|
return localStorage.getItem(F) && localStorage.removeItem(F), De(() => {
|
|
1529
1523
|
ke(e, t), oe(e, t);
|
|
1530
1524
|
const x = T.getState().getShadowMetadata(e, []);
|
|
1531
|
-
x && x?.components?.forEach((
|
|
1532
|
-
|
|
1525
|
+
x && x?.components?.forEach((p) => {
|
|
1526
|
+
p.forceUpdate();
|
|
1533
1527
|
});
|
|
1534
1528
|
}), {
|
|
1535
1529
|
fetchId: (x) => u.get()[x]
|
|
@@ -1542,21 +1536,21 @@ function Pe(e, r, l, a) {
|
|
|
1542
1536
|
});
|
|
1543
1537
|
}
|
|
1544
1538
|
function _e(e) {
|
|
1545
|
-
return
|
|
1539
|
+
return be(ft, { proxy: e });
|
|
1546
1540
|
}
|
|
1547
|
-
function
|
|
1541
|
+
function ft({
|
|
1548
1542
|
proxy: e
|
|
1549
1543
|
}) {
|
|
1550
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);
|
|
1551
1545
|
return W(() => {
|
|
1552
|
-
const
|
|
1553
|
-
if (!
|
|
1546
|
+
const d = r.current;
|
|
1547
|
+
if (!d || a.current) return;
|
|
1554
1548
|
const t = setTimeout(() => {
|
|
1555
|
-
if (!
|
|
1549
|
+
if (!d.parentElement) {
|
|
1556
1550
|
console.warn("Parent element not found for signal", S);
|
|
1557
1551
|
return;
|
|
1558
1552
|
}
|
|
1559
|
-
const u =
|
|
1553
|
+
const u = d.parentElement, U = Array.from(u.childNodes).indexOf(d);
|
|
1560
1554
|
let O = u.getAttribute("data-parent-id");
|
|
1561
1555
|
O || (O = `parent-${crypto.randomUUID()}`, u.setAttribute("data-parent-id", O)), l.current = `instance-${crypto.randomUUID()}`;
|
|
1562
1556
|
const F = T.getState().getShadowMetadata(e._stateKey, e._path) || {}, x = F.signals || [];
|
|
@@ -1569,29 +1563,29 @@ function dt({
|
|
|
1569
1563
|
...F,
|
|
1570
1564
|
signals: x
|
|
1571
1565
|
});
|
|
1572
|
-
let
|
|
1566
|
+
let p = i;
|
|
1573
1567
|
if (e._effect)
|
|
1574
1568
|
try {
|
|
1575
|
-
|
|
1569
|
+
p = new Function(
|
|
1576
1570
|
"state",
|
|
1577
1571
|
`return (${e._effect})(state)`
|
|
1578
1572
|
)(i);
|
|
1579
1573
|
} catch (m) {
|
|
1580
1574
|
console.error("Error evaluating effect function:", m);
|
|
1581
1575
|
}
|
|
1582
|
-
|
|
1583
|
-
const ee = document.createTextNode(String(
|
|
1584
|
-
|
|
1576
|
+
p !== null && typeof p == "object" && (p = JSON.stringify(p));
|
|
1577
|
+
const ee = document.createTextNode(String(p ?? ""));
|
|
1578
|
+
d.replaceWith(ee), a.current = !0;
|
|
1585
1579
|
}, 0);
|
|
1586
1580
|
return () => {
|
|
1587
1581
|
if (clearTimeout(t), l.current) {
|
|
1588
1582
|
const u = T.getState().getShadowMetadata(e._stateKey, e._path) || {};
|
|
1589
1583
|
u.signals && (u.signals = u.signals.filter(
|
|
1590
|
-
(
|
|
1584
|
+
(b) => b.instanceId !== l.current
|
|
1591
1585
|
), T.getState().setShadowMetadata(e._stateKey, e._path, u));
|
|
1592
1586
|
}
|
|
1593
1587
|
};
|
|
1594
|
-
}, []),
|
|
1588
|
+
}, []), be("span", {
|
|
1595
1589
|
ref: r,
|
|
1596
1590
|
style: { display: "contents" },
|
|
1597
1591
|
"data-signal-id": S
|
|
@@ -1599,9 +1593,9 @@ function dt({
|
|
|
1599
1593
|
}
|
|
1600
1594
|
export {
|
|
1601
1595
|
_e as $cogsSignal,
|
|
1602
|
-
|
|
1596
|
+
At as addStateOptions,
|
|
1603
1597
|
Xe as createCogsState,
|
|
1604
|
-
|
|
1598
|
+
It as createCogsStateFromSync,
|
|
1605
1599
|
lt as useCogsStateFn
|
|
1606
1600
|
};
|
|
1607
1601
|
//# sourceMappingURL=CogsState.jsx.map
|