cogsbox-state 0.5.366 → 0.5.368
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.jsx +692 -712
- package/dist/CogsState.jsx.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +72 -125
package/dist/CogsState.jsx
CHANGED
|
@@ -1,63 +1,63 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as
|
|
3
|
-
import { useState as
|
|
4
|
-
import { transformStateFunc as
|
|
5
|
-
import { pushFunc as
|
|
6
|
-
import
|
|
7
|
-
import { v4 as
|
|
2
|
+
import { jsx as Tt } from "react/jsx-runtime";
|
|
3
|
+
import { useState as Q, useRef as tt, useEffect as st, useLayoutEffect as ft, useMemo as wt, createElement as it, useSyncExternalStore as Rt, startTransition as Ut, useCallback as $t } from "react";
|
|
4
|
+
import { transformStateFunc as jt, isDeepEqual as B, isFunction as K, getNestedValue as q, getDifferences as Et, debounce as Dt } from "./utility.js";
|
|
5
|
+
import { pushFunc as pt, updateFn as at, cutFunc as gt, ValidationWrapper as Ft, FormControlComponent as Gt } from "./Functions.jsx";
|
|
6
|
+
import Wt from "superjson";
|
|
7
|
+
import { v4 as At } from "uuid";
|
|
8
8
|
import "zod";
|
|
9
|
-
import { getGlobalStore as
|
|
10
|
-
import { useCogsConfig as
|
|
11
|
-
import { applyPatch as
|
|
12
|
-
import
|
|
13
|
-
function
|
|
14
|
-
const m =
|
|
15
|
-
g(
|
|
16
|
-
...
|
|
9
|
+
import { getGlobalStore as o, formRefStore as Ot } from "./store.js";
|
|
10
|
+
import { useCogsConfig as xt } from "./CogsStateClient.jsx";
|
|
11
|
+
import { applyPatch as Bt } from "fast-json-patch";
|
|
12
|
+
import Ht from "react-use-measure";
|
|
13
|
+
function bt(t, i) {
|
|
14
|
+
const m = o.getState().getInitialOptions, g = o.getState().setInitialStateOptions, I = m(t) || {};
|
|
15
|
+
g(t, {
|
|
16
|
+
...I,
|
|
17
17
|
...i
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
|
-
function
|
|
21
|
-
stateKey:
|
|
20
|
+
function kt({
|
|
21
|
+
stateKey: t,
|
|
22
22
|
options: i,
|
|
23
23
|
initialOptionsPart: m
|
|
24
24
|
}) {
|
|
25
|
-
const g =
|
|
26
|
-
let
|
|
25
|
+
const g = rt(t) || {}, I = m[t] || {}, $ = o.getState().setInitialStateOptions, p = { ...I, ...g };
|
|
26
|
+
let y = !1;
|
|
27
27
|
if (i)
|
|
28
28
|
for (const a in i)
|
|
29
|
-
|
|
30
|
-
!
|
|
31
|
-
|
|
29
|
+
p.hasOwnProperty(a) ? (a == "localStorage" && i[a] && p[a].key !== i[a]?.key && (y = !0, p[a] = i[a]), a == "initialState" && i[a] && p[a] !== i[a] && // Different references
|
|
30
|
+
!B(p[a], i[a]) && (y = !0, p[a] = i[a])) : (y = !0, p[a] = i[a]);
|
|
31
|
+
y && $(t, p);
|
|
32
32
|
}
|
|
33
|
-
function
|
|
34
|
-
return { initialState:
|
|
33
|
+
function fe(t, { formElements: i, validation: m }) {
|
|
34
|
+
return { initialState: t, formElements: i, validation: m };
|
|
35
35
|
}
|
|
36
|
-
const
|
|
37
|
-
let m =
|
|
38
|
-
const [g,
|
|
39
|
-
(Object.keys(
|
|
40
|
-
|
|
36
|
+
const Se = (t, i) => {
|
|
37
|
+
let m = t;
|
|
38
|
+
const [g, I] = jt(m);
|
|
39
|
+
(Object.keys(I).length > 0 || i && Object.keys(i).length > 0) && Object.keys(I).forEach((y) => {
|
|
40
|
+
I[y] = I[y] || {}, I[y].formElements = {
|
|
41
41
|
...i?.formElements,
|
|
42
42
|
// Global defaults first
|
|
43
43
|
...i?.validation,
|
|
44
|
-
...
|
|
44
|
+
...I[y].formElements || {}
|
|
45
45
|
// State-specific overrides
|
|
46
|
-
},
|
|
47
|
-
}),
|
|
48
|
-
const
|
|
49
|
-
const [
|
|
50
|
-
|
|
51
|
-
stateKey:
|
|
46
|
+
}, rt(y) || o.getState().setInitialStateOptions(y, I[y]);
|
|
47
|
+
}), o.getState().setInitialStates(g), o.getState().setCreatedState(g);
|
|
48
|
+
const $ = (y, a) => {
|
|
49
|
+
const [v] = Q(a?.componentId ?? At());
|
|
50
|
+
kt({
|
|
51
|
+
stateKey: y,
|
|
52
52
|
options: a,
|
|
53
|
-
initialOptionsPart:
|
|
53
|
+
initialOptionsPart: I
|
|
54
54
|
});
|
|
55
|
-
const n =
|
|
55
|
+
const n = o.getState().cogsStateStore[y] || g[y], S = a?.modifyState ? a.modifyState(n) : n, [F, L] = Qt(
|
|
56
56
|
S,
|
|
57
57
|
{
|
|
58
|
-
stateKey:
|
|
58
|
+
stateKey: y,
|
|
59
59
|
syncUpdate: a?.syncUpdate,
|
|
60
|
-
componentId:
|
|
60
|
+
componentId: v,
|
|
61
61
|
localStorage: a?.localStorage,
|
|
62
62
|
middleware: a?.middleware,
|
|
63
63
|
enabledSync: a?.enabledSync,
|
|
@@ -68,80 +68,80 @@ const gt = (e, i) => {
|
|
|
68
68
|
serverState: a?.serverState
|
|
69
69
|
}
|
|
70
70
|
);
|
|
71
|
-
return
|
|
71
|
+
return L;
|
|
72
72
|
};
|
|
73
|
-
function
|
|
74
|
-
|
|
73
|
+
function p(y, a) {
|
|
74
|
+
kt({ stateKey: y, options: a, initialOptionsPart: I }), a.localStorage && Zt(y, a), vt(y);
|
|
75
75
|
}
|
|
76
|
-
return { useCogsState:
|
|
76
|
+
return { useCogsState: $, setCogsOptions: p };
|
|
77
77
|
}, {
|
|
78
|
-
setUpdaterState:
|
|
79
|
-
setState:
|
|
80
|
-
getInitialOptions:
|
|
81
|
-
getKeyState:
|
|
82
|
-
getValidationErrors:
|
|
83
|
-
setStateLog:
|
|
84
|
-
updateInitialStateGlobal:
|
|
85
|
-
addValidationError:
|
|
86
|
-
removeValidationError:
|
|
87
|
-
setServerSyncActions:
|
|
88
|
-
} =
|
|
78
|
+
setUpdaterState: St,
|
|
79
|
+
setState: nt,
|
|
80
|
+
getInitialOptions: rt,
|
|
81
|
+
getKeyState: Pt,
|
|
82
|
+
getValidationErrors: zt,
|
|
83
|
+
setStateLog: qt,
|
|
84
|
+
updateInitialStateGlobal: Nt,
|
|
85
|
+
addValidationError: Jt,
|
|
86
|
+
removeValidationError: X,
|
|
87
|
+
setServerSyncActions: Yt
|
|
88
|
+
} = o.getState(), _t = (t, i, m, g, I) => {
|
|
89
89
|
m?.log && console.log(
|
|
90
90
|
"saving to localstorage",
|
|
91
91
|
i,
|
|
92
92
|
m.localStorage?.key,
|
|
93
93
|
g
|
|
94
94
|
);
|
|
95
|
-
const
|
|
96
|
-
if (
|
|
97
|
-
const
|
|
98
|
-
let
|
|
95
|
+
const $ = K(m?.localStorage?.key) ? m.localStorage?.key(t) : m?.localStorage?.key;
|
|
96
|
+
if ($ && g) {
|
|
97
|
+
const p = `${g}-${i}-${$}`;
|
|
98
|
+
let y;
|
|
99
99
|
try {
|
|
100
|
-
|
|
100
|
+
y = ht(p)?.lastSyncedWithServer;
|
|
101
101
|
} catch {
|
|
102
102
|
}
|
|
103
103
|
const a = {
|
|
104
|
-
state:
|
|
104
|
+
state: t,
|
|
105
105
|
lastUpdated: Date.now(),
|
|
106
|
-
lastSyncedWithServer:
|
|
107
|
-
},
|
|
106
|
+
lastSyncedWithServer: I ?? y
|
|
107
|
+
}, v = Wt.serialize(a);
|
|
108
108
|
window.localStorage.setItem(
|
|
109
|
-
|
|
110
|
-
JSON.stringify(
|
|
109
|
+
p,
|
|
110
|
+
JSON.stringify(v.json)
|
|
111
111
|
);
|
|
112
112
|
}
|
|
113
|
-
},
|
|
114
|
-
if (!
|
|
113
|
+
}, ht = (t) => {
|
|
114
|
+
if (!t) return null;
|
|
115
115
|
try {
|
|
116
|
-
const i = window.localStorage.getItem(
|
|
116
|
+
const i = window.localStorage.getItem(t);
|
|
117
117
|
return i ? JSON.parse(i) : null;
|
|
118
118
|
} catch (i) {
|
|
119
119
|
return console.error("Error loading from localStorage:", i), null;
|
|
120
120
|
}
|
|
121
|
-
},
|
|
122
|
-
const m =
|
|
123
|
-
if (
|
|
124
|
-
const
|
|
125
|
-
`${g}-${
|
|
121
|
+
}, Zt = (t, i) => {
|
|
122
|
+
const m = o.getState().cogsStateStore[t], { sessionId: g } = xt(), I = K(i?.localStorage?.key) ? i.localStorage.key(m) : i?.localStorage?.key;
|
|
123
|
+
if (I && g) {
|
|
124
|
+
const $ = ht(
|
|
125
|
+
`${g}-${t}-${I}`
|
|
126
126
|
);
|
|
127
|
-
if (
|
|
128
|
-
return
|
|
127
|
+
if ($ && $.lastUpdated > ($.lastSyncedWithServer || 0))
|
|
128
|
+
return nt(t, $.state), vt(t), !0;
|
|
129
129
|
}
|
|
130
130
|
return !1;
|
|
131
|
-
},
|
|
132
|
-
const
|
|
131
|
+
}, Mt = (t, i, m, g, I, $) => {
|
|
132
|
+
const p = {
|
|
133
133
|
initialState: i,
|
|
134
|
-
updaterState:
|
|
135
|
-
|
|
134
|
+
updaterState: mt(
|
|
135
|
+
t,
|
|
136
136
|
g,
|
|
137
|
-
|
|
138
|
-
|
|
137
|
+
I,
|
|
138
|
+
$
|
|
139
139
|
),
|
|
140
140
|
state: m
|
|
141
141
|
};
|
|
142
|
-
|
|
143
|
-
},
|
|
144
|
-
const i =
|
|
142
|
+
Nt(t, p.initialState), St(t, p.updaterState), nt(t, p.state);
|
|
143
|
+
}, vt = (t) => {
|
|
144
|
+
const i = o.getState().stateComponents.get(t);
|
|
145
145
|
if (!i) return;
|
|
146
146
|
const m = /* @__PURE__ */ new Set();
|
|
147
147
|
i.components.forEach((g) => {
|
|
@@ -149,30 +149,30 @@ const gt = (e, i) => {
|
|
|
149
149
|
}), queueMicrotask(() => {
|
|
150
150
|
m.forEach((g) => g());
|
|
151
151
|
});
|
|
152
|
-
},
|
|
153
|
-
const m =
|
|
152
|
+
}, me = (t, i) => {
|
|
153
|
+
const m = o.getState().stateComponents.get(t);
|
|
154
154
|
if (m) {
|
|
155
|
-
const g = `${
|
|
156
|
-
if ((
|
|
155
|
+
const g = `${t}////${i}`, I = m.components.get(g);
|
|
156
|
+
if ((I ? Array.isArray(I.reactiveType) ? I.reactiveType : [I.reactiveType || "component"] : null)?.includes("none"))
|
|
157
157
|
return;
|
|
158
|
-
|
|
158
|
+
I && I.forceUpdate();
|
|
159
159
|
}
|
|
160
|
-
},
|
|
161
|
-
switch (
|
|
160
|
+
}, Xt = (t, i, m, g) => {
|
|
161
|
+
switch (t) {
|
|
162
162
|
case "update":
|
|
163
163
|
return {
|
|
164
|
-
oldValue:
|
|
165
|
-
newValue:
|
|
164
|
+
oldValue: q(i, g),
|
|
165
|
+
newValue: q(m, g)
|
|
166
166
|
};
|
|
167
167
|
case "insert":
|
|
168
168
|
return {
|
|
169
169
|
oldValue: null,
|
|
170
170
|
// or undefined
|
|
171
|
-
newValue:
|
|
171
|
+
newValue: q(m, g)
|
|
172
172
|
};
|
|
173
173
|
case "cut":
|
|
174
174
|
return {
|
|
175
|
-
oldValue:
|
|
175
|
+
oldValue: q(i, g),
|
|
176
176
|
newValue: null
|
|
177
177
|
// or undefined
|
|
178
178
|
};
|
|
@@ -180,327 +180,327 @@ const gt = (e, i) => {
|
|
|
180
180
|
return { oldValue: null, newValue: null };
|
|
181
181
|
}
|
|
182
182
|
};
|
|
183
|
-
function
|
|
183
|
+
function Qt(t, {
|
|
184
184
|
stateKey: i,
|
|
185
185
|
serverSync: m,
|
|
186
186
|
localStorage: g,
|
|
187
|
-
formElements:
|
|
188
|
-
reactiveDeps:
|
|
189
|
-
reactiveType:
|
|
190
|
-
componentId:
|
|
187
|
+
formElements: I,
|
|
188
|
+
reactiveDeps: $,
|
|
189
|
+
reactiveType: p,
|
|
190
|
+
componentId: y,
|
|
191
191
|
initialState: a,
|
|
192
|
-
syncUpdate:
|
|
192
|
+
syncUpdate: v,
|
|
193
193
|
dependencies: n,
|
|
194
194
|
serverState: S
|
|
195
195
|
} = {}) {
|
|
196
|
-
const [
|
|
197
|
-
let
|
|
198
|
-
const [
|
|
196
|
+
const [F, L] = Q({}), { sessionId: R } = xt();
|
|
197
|
+
let G = !i;
|
|
198
|
+
const [h] = Q(i ?? At()), l = o.getState().stateLog[h], ct = tt(/* @__PURE__ */ new Set()), et = tt(y ?? At()), x = tt(
|
|
199
199
|
null
|
|
200
200
|
);
|
|
201
|
-
|
|
202
|
-
if (
|
|
203
|
-
|
|
204
|
-
...
|
|
205
|
-
[
|
|
201
|
+
x.current = rt(h) ?? null, st(() => {
|
|
202
|
+
if (v && v.stateKey === h && v.path?.[0]) {
|
|
203
|
+
nt(h, (r) => ({
|
|
204
|
+
...r,
|
|
205
|
+
[v.path[0]]: v.newValue
|
|
206
206
|
}));
|
|
207
|
-
const
|
|
208
|
-
|
|
209
|
-
timeStamp:
|
|
210
|
-
userId:
|
|
207
|
+
const e = `${v.stateKey}:${v.path.join(".")}`;
|
|
208
|
+
o.getState().setSyncInfo(e, {
|
|
209
|
+
timeStamp: v.timeStamp,
|
|
210
|
+
userId: v.userId
|
|
211
211
|
});
|
|
212
212
|
}
|
|
213
|
-
}, [
|
|
213
|
+
}, [v]), st(() => {
|
|
214
214
|
if (a) {
|
|
215
|
-
|
|
215
|
+
bt(h, {
|
|
216
216
|
initialState: a
|
|
217
217
|
});
|
|
218
|
-
const
|
|
219
|
-
if (!(c && !
|
|
218
|
+
const e = x.current, s = e?.serverState?.id !== void 0 && e?.serverState?.status === "success" && e?.serverState?.data, c = o.getState().initialStateGlobal[h];
|
|
219
|
+
if (!(c && !B(c, a) || !c) && !s)
|
|
220
220
|
return;
|
|
221
221
|
let u = null;
|
|
222
|
-
const
|
|
223
|
-
|
|
224
|
-
let
|
|
225
|
-
const
|
|
226
|
-
s &&
|
|
227
|
-
|
|
222
|
+
const T = K(e?.localStorage?.key) ? e?.localStorage?.key(a) : e?.localStorage?.key;
|
|
223
|
+
T && R && (u = ht(`${R}-${h}-${T}`));
|
|
224
|
+
let w = a, A = !1;
|
|
225
|
+
const O = s ? Date.now() : 0, b = u?.lastUpdated || 0, V = u?.lastSyncedWithServer || 0;
|
|
226
|
+
s && O > b ? (w = e.serverState.data, A = !0) : u && b > V && (w = u.state, e?.localStorage?.onChange && e?.localStorage?.onChange(w)), o.getState().initializeShadowState(h, a), Mt(
|
|
227
|
+
h,
|
|
228
228
|
a,
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
),
|
|
229
|
+
w,
|
|
230
|
+
ot,
|
|
231
|
+
et.current,
|
|
232
|
+
R
|
|
233
|
+
), A && T && R && _t(w, h, e, R, Date.now()), vt(h), (Array.isArray(p) ? p : [p || "component"]).includes("none") || L({});
|
|
234
234
|
}
|
|
235
235
|
}, [
|
|
236
236
|
a,
|
|
237
237
|
S?.status,
|
|
238
238
|
S?.data,
|
|
239
239
|
...n || []
|
|
240
|
-
]),
|
|
241
|
-
|
|
240
|
+
]), ft(() => {
|
|
241
|
+
G && bt(h, {
|
|
242
242
|
serverSync: m,
|
|
243
|
-
formElements:
|
|
243
|
+
formElements: I,
|
|
244
244
|
initialState: a,
|
|
245
245
|
localStorage: g,
|
|
246
|
-
middleware:
|
|
246
|
+
middleware: x.current?.middleware
|
|
247
247
|
});
|
|
248
|
-
const
|
|
248
|
+
const e = `${h}////${et.current}`, r = o.getState().stateComponents.get(h) || {
|
|
249
249
|
components: /* @__PURE__ */ new Map()
|
|
250
250
|
};
|
|
251
|
-
return
|
|
252
|
-
forceUpdate: () =>
|
|
251
|
+
return r.components.set(e, {
|
|
252
|
+
forceUpdate: () => L({}),
|
|
253
253
|
paths: /* @__PURE__ */ new Set(),
|
|
254
254
|
deps: [],
|
|
255
|
-
depsFunction:
|
|
256
|
-
reactiveType:
|
|
257
|
-
}),
|
|
258
|
-
|
|
255
|
+
depsFunction: $ || void 0,
|
|
256
|
+
reactiveType: p ?? ["component", "deps"]
|
|
257
|
+
}), o.getState().stateComponents.set(h, r), L({}), () => {
|
|
258
|
+
r && (r.components.delete(e), r.components.size === 0 && o.getState().stateComponents.delete(h));
|
|
259
259
|
};
|
|
260
260
|
}, []);
|
|
261
|
-
const
|
|
262
|
-
if (Array.isArray(
|
|
263
|
-
const u = `${
|
|
264
|
-
|
|
261
|
+
const ot = (e, r, s, c) => {
|
|
262
|
+
if (Array.isArray(r)) {
|
|
263
|
+
const u = `${h}-${r.join(".")}`;
|
|
264
|
+
ct.current.add(u);
|
|
265
265
|
}
|
|
266
|
-
const f =
|
|
267
|
-
|
|
268
|
-
const
|
|
269
|
-
if (
|
|
270
|
-
let
|
|
271
|
-
if ((!
|
|
272
|
-
const
|
|
273
|
-
if (Array.isArray(
|
|
274
|
-
|
|
275
|
-
const
|
|
276
|
-
|
|
266
|
+
const f = o.getState();
|
|
267
|
+
nt(h, (u) => {
|
|
268
|
+
const T = K(e) ? e(u) : e, w = `${h}-${r.join(".")}`;
|
|
269
|
+
if (w) {
|
|
270
|
+
let k = !1, E = f.signalDomElements.get(w);
|
|
271
|
+
if ((!E || E.size === 0) && (s.updateType === "insert" || s.updateType === "cut")) {
|
|
272
|
+
const P = r.slice(0, -1), _ = q(T, P);
|
|
273
|
+
if (Array.isArray(_)) {
|
|
274
|
+
k = !0;
|
|
275
|
+
const C = `${h}-${P.join(".")}`;
|
|
276
|
+
E = f.signalDomElements.get(C);
|
|
277
277
|
}
|
|
278
278
|
}
|
|
279
|
-
if (
|
|
280
|
-
const
|
|
281
|
-
|
|
282
|
-
const
|
|
283
|
-
`[data-parent-id="${
|
|
279
|
+
if (E) {
|
|
280
|
+
const P = k ? q(T, r.slice(0, -1)) : q(T, r);
|
|
281
|
+
E.forEach(({ parentId: _, position: C, effect: U }) => {
|
|
282
|
+
const M = document.querySelector(
|
|
283
|
+
`[data-parent-id="${_}"]`
|
|
284
284
|
);
|
|
285
|
-
if (
|
|
286
|
-
const
|
|
287
|
-
if (
|
|
288
|
-
const
|
|
289
|
-
|
|
285
|
+
if (M) {
|
|
286
|
+
const W = Array.from(M.childNodes);
|
|
287
|
+
if (W[C]) {
|
|
288
|
+
const N = U ? new Function("state", `return (${U})(state)`)(P) : P;
|
|
289
|
+
W[C].textContent = String(N);
|
|
290
290
|
}
|
|
291
291
|
}
|
|
292
292
|
});
|
|
293
293
|
}
|
|
294
294
|
}
|
|
295
|
-
console.log("shadowState", f.shadowStateStore), s.updateType === "update" && (c ||
|
|
296
|
-
(c ||
|
|
295
|
+
console.log("shadowState", f.shadowStateStore), s.updateType === "update" && (c || x.current?.validation?.key) && r && X(
|
|
296
|
+
(c || x.current?.validation?.key) + "." + r.join(".")
|
|
297
297
|
);
|
|
298
|
-
const
|
|
299
|
-
s.updateType === "cut" &&
|
|
300
|
-
|
|
301
|
-
), s.updateType === "insert" &&
|
|
302
|
-
|
|
303
|
-
).filter(([
|
|
304
|
-
let
|
|
305
|
-
if (
|
|
306
|
-
let
|
|
307
|
-
|
|
298
|
+
const A = r.slice(0, r.length - 1);
|
|
299
|
+
s.updateType === "cut" && x.current?.validation?.key && X(
|
|
300
|
+
x.current?.validation?.key + "." + A.join(".")
|
|
301
|
+
), s.updateType === "insert" && x.current?.validation?.key && zt(
|
|
302
|
+
x.current?.validation?.key + "." + A.join(".")
|
|
303
|
+
).filter(([E, P]) => {
|
|
304
|
+
let _ = E?.split(".").length;
|
|
305
|
+
if (E == A.join(".") && _ == A.length - 1) {
|
|
306
|
+
let C = E + "." + A;
|
|
307
|
+
X(E), Jt(C, P);
|
|
308
308
|
}
|
|
309
309
|
});
|
|
310
|
-
const
|
|
311
|
-
if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>",
|
|
312
|
-
const
|
|
310
|
+
const O = f.stateComponents.get(h);
|
|
311
|
+
if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", O), O) {
|
|
312
|
+
const k = Et(u, T), E = new Set(k), P = s.updateType === "update" ? r.join(".") : r.slice(0, -1).join(".") || "";
|
|
313
313
|
for (const [
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
] of
|
|
317
|
-
let
|
|
318
|
-
const
|
|
319
|
-
if (console.log("component",
|
|
320
|
-
if (
|
|
321
|
-
|
|
314
|
+
_,
|
|
315
|
+
C
|
|
316
|
+
] of O.components.entries()) {
|
|
317
|
+
let U = !1;
|
|
318
|
+
const M = Array.isArray(C.reactiveType) ? C.reactiveType : [C.reactiveType || "component"];
|
|
319
|
+
if (console.log("component", C), !M.includes("none")) {
|
|
320
|
+
if (M.includes("all")) {
|
|
321
|
+
C.forceUpdate();
|
|
322
322
|
continue;
|
|
323
323
|
}
|
|
324
|
-
if (
|
|
325
|
-
for (const
|
|
326
|
-
let
|
|
324
|
+
if (M.includes("component") && ((C.paths.has(P) || C.paths.has("")) && (U = !0), !U))
|
|
325
|
+
for (const W of E) {
|
|
326
|
+
let N = W;
|
|
327
327
|
for (; ; ) {
|
|
328
|
-
if (
|
|
329
|
-
|
|
328
|
+
if (C.paths.has(N)) {
|
|
329
|
+
U = !0;
|
|
330
330
|
break;
|
|
331
331
|
}
|
|
332
|
-
const
|
|
333
|
-
if (
|
|
334
|
-
const H =
|
|
332
|
+
const j = N.lastIndexOf(".");
|
|
333
|
+
if (j !== -1) {
|
|
334
|
+
const H = N.substring(
|
|
335
335
|
0,
|
|
336
|
-
|
|
336
|
+
j
|
|
337
337
|
);
|
|
338
338
|
if (!isNaN(
|
|
339
|
-
Number(
|
|
340
|
-
) &&
|
|
341
|
-
|
|
339
|
+
Number(N.substring(j + 1))
|
|
340
|
+
) && C.paths.has(H)) {
|
|
341
|
+
U = !0;
|
|
342
342
|
break;
|
|
343
343
|
}
|
|
344
|
-
|
|
344
|
+
N = H;
|
|
345
345
|
} else
|
|
346
|
-
|
|
347
|
-
if (
|
|
346
|
+
N = "";
|
|
347
|
+
if (N === "")
|
|
348
348
|
break;
|
|
349
349
|
}
|
|
350
|
-
if (
|
|
350
|
+
if (U) break;
|
|
351
351
|
}
|
|
352
|
-
if (!
|
|
353
|
-
const
|
|
354
|
-
let
|
|
355
|
-
typeof
|
|
352
|
+
if (!U && M.includes("deps") && C.depsFunction) {
|
|
353
|
+
const W = C.depsFunction(T);
|
|
354
|
+
let N = !1;
|
|
355
|
+
typeof W == "boolean" ? W && (N = !0) : B(C.deps, W) || (C.deps = W, N = !0), N && (U = !0);
|
|
356
356
|
}
|
|
357
|
-
|
|
357
|
+
U && C.forceUpdate();
|
|
358
358
|
}
|
|
359
359
|
}
|
|
360
360
|
}
|
|
361
|
-
const
|
|
362
|
-
|
|
363
|
-
const
|
|
364
|
-
return
|
|
361
|
+
const b = Date.now();
|
|
362
|
+
r = r.map((k, E) => {
|
|
363
|
+
const P = r.slice(0, -1), _ = q(T, P);
|
|
364
|
+
return E === r.length - 1 && ["insert", "cut"].includes(s.updateType) ? (_.length - 1).toString() : k;
|
|
365
365
|
});
|
|
366
|
-
const { oldValue:
|
|
366
|
+
const { oldValue: V, newValue: D } = Xt(
|
|
367
367
|
s.updateType,
|
|
368
368
|
u,
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
),
|
|
372
|
-
timeStamp:
|
|
373
|
-
stateKey:
|
|
374
|
-
path:
|
|
369
|
+
T,
|
|
370
|
+
r
|
|
371
|
+
), J = {
|
|
372
|
+
timeStamp: b,
|
|
373
|
+
stateKey: h,
|
|
374
|
+
path: r,
|
|
375
375
|
updateType: s.updateType,
|
|
376
376
|
status: "new",
|
|
377
|
-
oldValue:
|
|
377
|
+
oldValue: V,
|
|
378
378
|
newValue: D
|
|
379
379
|
};
|
|
380
380
|
switch (s.updateType) {
|
|
381
381
|
case "update":
|
|
382
|
-
f.updateShadowAtPath(
|
|
382
|
+
f.updateShadowAtPath(h, r, T);
|
|
383
383
|
break;
|
|
384
384
|
case "insert":
|
|
385
|
-
const
|
|
386
|
-
f.insertShadowArrayElement(
|
|
385
|
+
const k = r.slice(0, -1);
|
|
386
|
+
f.insertShadowArrayElement(h, k, D);
|
|
387
387
|
break;
|
|
388
388
|
case "cut":
|
|
389
|
-
const
|
|
390
|
-
f.removeShadowArrayElement(
|
|
389
|
+
const E = r.slice(0, -1), P = parseInt(r[r.length - 1]);
|
|
390
|
+
f.removeShadowArrayElement(h, E, P);
|
|
391
391
|
break;
|
|
392
392
|
}
|
|
393
|
-
if (
|
|
394
|
-
const
|
|
395
|
-
const
|
|
396
|
-
return
|
|
393
|
+
if (qt(h, (k) => {
|
|
394
|
+
const P = [...k ?? [], J].reduce((_, C) => {
|
|
395
|
+
const U = `${C.stateKey}:${JSON.stringify(C.path)}`, M = _.get(U);
|
|
396
|
+
return M ? (M.timeStamp = Math.max(M.timeStamp, C.timeStamp), M.newValue = C.newValue, M.oldValue = M.oldValue ?? C.oldValue, M.updateType = C.updateType) : _.set(U, { ...C }), _;
|
|
397
397
|
}, /* @__PURE__ */ new Map());
|
|
398
|
-
return Array.from(
|
|
399
|
-
}),
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
),
|
|
398
|
+
return Array.from(P.values());
|
|
399
|
+
}), _t(
|
|
400
|
+
T,
|
|
401
|
+
h,
|
|
402
|
+
x.current,
|
|
403
|
+
R
|
|
404
|
+
), x.current?.middleware && x.current.middleware({
|
|
405
405
|
updateLog: l,
|
|
406
|
-
update:
|
|
407
|
-
}),
|
|
408
|
-
const
|
|
409
|
-
|
|
410
|
-
syncKey: typeof
|
|
411
|
-
rollBackState:
|
|
412
|
-
actionTimeStamp: Date.now() + (
|
|
406
|
+
update: J
|
|
407
|
+
}), x.current?.serverSync) {
|
|
408
|
+
const k = f.serverState[h], E = x.current?.serverSync;
|
|
409
|
+
Yt(h, {
|
|
410
|
+
syncKey: typeof E.syncKey == "string" ? E.syncKey : E.syncKey({ state: T }),
|
|
411
|
+
rollBackState: k,
|
|
412
|
+
actionTimeStamp: Date.now() + (E.debounce ?? 3e3),
|
|
413
413
|
status: "waiting"
|
|
414
414
|
});
|
|
415
415
|
}
|
|
416
|
-
return
|
|
416
|
+
return T;
|
|
417
417
|
});
|
|
418
418
|
};
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
419
|
+
o.getState().updaterState[h] || (St(
|
|
420
|
+
h,
|
|
421
|
+
mt(
|
|
422
|
+
h,
|
|
423
|
+
ot,
|
|
424
|
+
et.current,
|
|
425
|
+
R
|
|
426
426
|
)
|
|
427
|
-
),
|
|
428
|
-
const d =
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
), [
|
|
434
|
-
return [
|
|
427
|
+
), o.getState().cogsStateStore[h] || nt(h, t), o.getState().initialStateGlobal[h] || Nt(h, t));
|
|
428
|
+
const d = wt(() => mt(
|
|
429
|
+
h,
|
|
430
|
+
ot,
|
|
431
|
+
et.current,
|
|
432
|
+
R
|
|
433
|
+
), [h, R]);
|
|
434
|
+
return [Pt(h), d];
|
|
435
435
|
}
|
|
436
|
-
function
|
|
437
|
-
const
|
|
438
|
-
let
|
|
439
|
-
const
|
|
440
|
-
const n =
|
|
441
|
-
for (const [S] of
|
|
442
|
-
(S === n || S.startsWith(n + ".")) &&
|
|
443
|
-
|
|
444
|
-
},
|
|
445
|
-
removeValidation: (
|
|
446
|
-
|
|
436
|
+
function mt(t, i, m, g) {
|
|
437
|
+
const I = /* @__PURE__ */ new Map();
|
|
438
|
+
let $ = 0;
|
|
439
|
+
const p = (v) => {
|
|
440
|
+
const n = v.join(".");
|
|
441
|
+
for (const [S] of I)
|
|
442
|
+
(S === n || S.startsWith(n + ".")) && I.delete(S);
|
|
443
|
+
$++;
|
|
444
|
+
}, y = {
|
|
445
|
+
removeValidation: (v) => {
|
|
446
|
+
v?.validationKey && X(v.validationKey);
|
|
447
447
|
},
|
|
448
|
-
revertToInitialState: (
|
|
449
|
-
const n =
|
|
450
|
-
n?.key &&
|
|
451
|
-
const S =
|
|
452
|
-
|
|
453
|
-
const
|
|
454
|
-
|
|
455
|
-
const
|
|
456
|
-
return
|
|
448
|
+
revertToInitialState: (v) => {
|
|
449
|
+
const n = o.getState().getInitialOptions(t)?.validation;
|
|
450
|
+
n?.key && X(n?.key), v?.validationKey && X(v.validationKey);
|
|
451
|
+
const S = o.getState().initialStateGlobal[t];
|
|
452
|
+
o.getState().clearSelectedIndexesForState(t), I.clear(), $++;
|
|
453
|
+
const F = a(S, []), L = rt(t), R = K(L?.localStorage?.key) ? L?.localStorage?.key(S) : L?.localStorage?.key, G = `${g}-${t}-${R}`;
|
|
454
|
+
G && localStorage.removeItem(G), St(t, F), nt(t, S);
|
|
455
|
+
const h = o.getState().stateComponents.get(t);
|
|
456
|
+
return h && h.components.forEach((l) => {
|
|
457
457
|
l.forceUpdate();
|
|
458
458
|
}), S;
|
|
459
459
|
},
|
|
460
|
-
updateInitialState: (
|
|
461
|
-
|
|
462
|
-
const n =
|
|
463
|
-
|
|
460
|
+
updateInitialState: (v) => {
|
|
461
|
+
I.clear(), $++;
|
|
462
|
+
const n = mt(
|
|
463
|
+
t,
|
|
464
464
|
i,
|
|
465
465
|
m,
|
|
466
466
|
g
|
|
467
|
-
), S =
|
|
468
|
-
return localStorage.getItem(
|
|
469
|
-
|
|
470
|
-
const
|
|
471
|
-
|
|
472
|
-
|
|
467
|
+
), S = o.getState().initialStateGlobal[t], F = rt(t), L = K(F?.localStorage?.key) ? F?.localStorage?.key(S) : F?.localStorage?.key, R = `${g}-${t}-${L}`;
|
|
468
|
+
return localStorage.getItem(R) && localStorage.removeItem(R), Ut(() => {
|
|
469
|
+
Nt(t, v), o.getState().initializeShadowState(t, v), St(t, n), nt(t, v);
|
|
470
|
+
const G = o.getState().stateComponents.get(t);
|
|
471
|
+
G && G.components.forEach((h) => {
|
|
472
|
+
h.forceUpdate();
|
|
473
473
|
});
|
|
474
474
|
}), {
|
|
475
|
-
fetchId: (
|
|
475
|
+
fetchId: (G) => n.get()[G]
|
|
476
476
|
};
|
|
477
477
|
},
|
|
478
|
-
_initialState:
|
|
479
|
-
_serverState:
|
|
480
|
-
_isLoading:
|
|
478
|
+
_initialState: o.getState().initialStateGlobal[t],
|
|
479
|
+
_serverState: o.getState().serverState[t],
|
|
480
|
+
_isLoading: o.getState().isLoadingGlobal[t],
|
|
481
481
|
_isServerSynced: () => {
|
|
482
|
-
const
|
|
483
|
-
return !!(
|
|
482
|
+
const v = o.getState().serverState[t];
|
|
483
|
+
return !!(v && B(v, Pt(t)));
|
|
484
484
|
}
|
|
485
485
|
};
|
|
486
|
-
function a(
|
|
487
|
-
const
|
|
488
|
-
|
|
489
|
-
const
|
|
490
|
-
return
|
|
486
|
+
function a(v, n = [], S) {
|
|
487
|
+
const F = n.map(String).join(".");
|
|
488
|
+
I.get(F);
|
|
489
|
+
const L = function() {
|
|
490
|
+
return o().getNestedState(t, n);
|
|
491
491
|
};
|
|
492
|
-
Object.keys(
|
|
493
|
-
|
|
492
|
+
Object.keys(y).forEach((h) => {
|
|
493
|
+
L[h] = y[h];
|
|
494
494
|
});
|
|
495
|
-
const
|
|
496
|
-
apply(
|
|
495
|
+
const R = {
|
|
496
|
+
apply(h, l, ct) {
|
|
497
497
|
return console.log(
|
|
498
|
-
`PROXY APPLY TRAP HIT: stateKey=${
|
|
499
|
-
), console.trace("Apply trap stack trace"),
|
|
498
|
+
`PROXY APPLY TRAP HIT: stateKey=${t}, path=${n.join(".")}`
|
|
499
|
+
), console.trace("Apply trap stack trace"), o().getNestedState(t, n);
|
|
500
500
|
},
|
|
501
|
-
get(
|
|
502
|
-
S?.validIndices && !Array.isArray(
|
|
503
|
-
const
|
|
501
|
+
get(h, l) {
|
|
502
|
+
S?.validIndices && !Array.isArray(v) && (S = { ...S, validIndices: void 0 });
|
|
503
|
+
const ct = /* @__PURE__ */ new Set([
|
|
504
504
|
"insert",
|
|
505
505
|
"cut",
|
|
506
506
|
"cutByValue",
|
|
@@ -523,259 +523,239 @@ function Se(e, i, m, g) {
|
|
|
523
523
|
"_stateKey",
|
|
524
524
|
"getComponents"
|
|
525
525
|
]);
|
|
526
|
-
if (l !== "then" && !l.startsWith("$") && l !== "stateMapNoRender" && !
|
|
527
|
-
const d = `${
|
|
528
|
-
if (
|
|
529
|
-
const
|
|
530
|
-
if (
|
|
526
|
+
if (l !== "then" && !l.startsWith("$") && l !== "stateMapNoRender" && !ct.has(l)) {
|
|
527
|
+
const d = `${t}////${m}`, e = o.getState().stateComponents.get(t);
|
|
528
|
+
if (e) {
|
|
529
|
+
const r = e.components.get(d);
|
|
530
|
+
if (r && !r.paths.has("")) {
|
|
531
531
|
const s = n.join(".");
|
|
532
532
|
let c = !0;
|
|
533
|
-
for (const f of
|
|
533
|
+
for (const f of r.paths)
|
|
534
534
|
if (s.startsWith(f) && (s === f || s[f.length] === ".")) {
|
|
535
535
|
c = !1;
|
|
536
536
|
break;
|
|
537
537
|
}
|
|
538
|
-
c &&
|
|
538
|
+
c && r.paths.add(s);
|
|
539
539
|
}
|
|
540
540
|
}
|
|
541
541
|
}
|
|
542
542
|
if (l === "getDifferences")
|
|
543
|
-
return () =>
|
|
544
|
-
|
|
545
|
-
|
|
543
|
+
return () => Et(
|
|
544
|
+
o.getState().cogsStateStore[t],
|
|
545
|
+
o.getState().initialStateGlobal[t]
|
|
546
546
|
);
|
|
547
547
|
if (l === "sync" && n.length === 0)
|
|
548
548
|
return async function() {
|
|
549
|
-
const d =
|
|
550
|
-
if (!
|
|
551
|
-
return console.error(`No mutation defined for state key "${
|
|
552
|
-
const
|
|
549
|
+
const d = o.getState().getInitialOptions(t), e = d?.sync;
|
|
550
|
+
if (!e)
|
|
551
|
+
return console.error(`No mutation defined for state key "${t}"`), { success: !1, error: "No mutation defined" };
|
|
552
|
+
const r = o.getState().getNestedState(t, []), s = d?.validation?.key;
|
|
553
553
|
try {
|
|
554
|
-
const c = await
|
|
554
|
+
const c = await e.action(r);
|
|
555
555
|
if (c && !c.success && c.errors && s) {
|
|
556
|
-
|
|
557
|
-
const
|
|
558
|
-
|
|
556
|
+
o.getState().removeValidationError(s), c.errors.forEach((u) => {
|
|
557
|
+
const T = [s, ...u.path].join(".");
|
|
558
|
+
o.getState().addValidationError(T, u.message);
|
|
559
559
|
});
|
|
560
|
-
const f =
|
|
560
|
+
const f = o.getState().stateComponents.get(t);
|
|
561
561
|
f && f.components.forEach((u) => {
|
|
562
562
|
u.forceUpdate();
|
|
563
563
|
});
|
|
564
564
|
}
|
|
565
|
-
return c?.success &&
|
|
565
|
+
return c?.success && e.onSuccess ? e.onSuccess(c.data) : !c?.success && e.onError && e.onError(c.error), c;
|
|
566
566
|
} catch (c) {
|
|
567
|
-
return
|
|
567
|
+
return e.onError && e.onError(c), { success: !1, error: c };
|
|
568
568
|
}
|
|
569
569
|
};
|
|
570
570
|
if (l === "_status") {
|
|
571
|
-
const d =
|
|
572
|
-
return
|
|
571
|
+
const d = o.getState().getNestedState(t, n), e = o.getState().initialStateGlobal[t], r = q(e, n);
|
|
572
|
+
return B(d, r) ? "fresh" : "stale";
|
|
573
573
|
}
|
|
574
574
|
if (l === "getStatus")
|
|
575
575
|
return function() {
|
|
576
|
-
const d =
|
|
577
|
-
|
|
576
|
+
const d = o().getNestedState(
|
|
577
|
+
t,
|
|
578
578
|
n
|
|
579
|
-
),
|
|
580
|
-
return
|
|
579
|
+
), e = o.getState().initialStateGlobal[t], r = q(e, n);
|
|
580
|
+
return B(d, r) ? "fresh" : "stale";
|
|
581
581
|
};
|
|
582
582
|
if (l === "removeStorage")
|
|
583
583
|
return () => {
|
|
584
|
-
const d =
|
|
584
|
+
const d = o.getState().initialStateGlobal[t], e = rt(t), r = K(e?.localStorage?.key) ? e?.localStorage?.key(d) : e?.localStorage?.key, s = `${g}-${t}-${r}`;
|
|
585
585
|
s && localStorage.removeItem(s);
|
|
586
586
|
};
|
|
587
587
|
if (l === "showValidationErrors")
|
|
588
588
|
return () => {
|
|
589
|
-
const d =
|
|
589
|
+
const d = o.getState().getInitialOptions(t)?.validation;
|
|
590
590
|
if (!d?.key)
|
|
591
591
|
throw new Error("Validation key not found");
|
|
592
|
-
return
|
|
592
|
+
return o.getState().getValidationErrors(d.key + "." + n.join("."));
|
|
593
593
|
};
|
|
594
|
-
if (Array.isArray(
|
|
595
|
-
const d = () => S?.validIndices ?
|
|
596
|
-
item:
|
|
594
|
+
if (Array.isArray(v)) {
|
|
595
|
+
const d = () => S?.validIndices ? v.map((r, s) => ({
|
|
596
|
+
item: r,
|
|
597
597
|
originalIndex: S.validIndices[s]
|
|
598
|
-
})) :
|
|
599
|
-
item:
|
|
598
|
+
})) : o.getState().getNestedState(t, n).map((r, s) => ({
|
|
599
|
+
item: r,
|
|
600
600
|
originalIndex: s
|
|
601
601
|
}));
|
|
602
602
|
if (l === "getSelected")
|
|
603
603
|
return () => {
|
|
604
|
-
const
|
|
605
|
-
if (
|
|
604
|
+
const e = o.getState().getSelectedIndex(t, n.join("."));
|
|
605
|
+
if (e !== void 0)
|
|
606
606
|
return a(
|
|
607
|
-
|
|
608
|
-
[...n,
|
|
607
|
+
v[e],
|
|
608
|
+
[...n, e.toString()],
|
|
609
609
|
S
|
|
610
610
|
);
|
|
611
611
|
};
|
|
612
612
|
if (l === "clearSelected")
|
|
613
613
|
return () => {
|
|
614
|
-
|
|
614
|
+
o.getState().clearSelectedIndex({ stateKey: t, path: n });
|
|
615
615
|
};
|
|
616
616
|
if (l === "getSelectedIndex")
|
|
617
|
-
return () =>
|
|
617
|
+
return () => o.getState().getSelectedIndex(t, n.join(".")) ?? -1;
|
|
618
618
|
if (l === "useVirtualView")
|
|
619
|
-
return (
|
|
619
|
+
return (e) => {
|
|
620
620
|
const {
|
|
621
|
-
itemHeight:
|
|
621
|
+
itemHeight: r = 50,
|
|
622
622
|
overscan: s = 6,
|
|
623
623
|
stickToBottom: c = !1,
|
|
624
624
|
dependencies: f = []
|
|
625
|
-
} =
|
|
625
|
+
} = e, u = tt(null), [T, w] = Q({
|
|
626
626
|
startIndex: 0,
|
|
627
627
|
endIndex: 10
|
|
628
|
-
}), [
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
}), [
|
|
632
|
-
const
|
|
633
|
-
|
|
628
|
+
}), [A, O] = Q("IDLE"), b = tt(0), V = tt(f), [D, J] = Q(0);
|
|
629
|
+
st(() => o.getState().subscribeToShadowState(t, () => {
|
|
630
|
+
J((j) => j + 1);
|
|
631
|
+
}), [t]);
|
|
632
|
+
const k = o().getNestedState(
|
|
633
|
+
t,
|
|
634
634
|
n
|
|
635
|
-
),
|
|
636
|
-
const
|
|
637
|
-
let
|
|
635
|
+
), E = k.length, { totalHeight: P, positions: _ } = wt(() => {
|
|
636
|
+
const N = o.getState().getShadowMetadata(t, n) || [];
|
|
637
|
+
let j = 0;
|
|
638
638
|
const H = [];
|
|
639
|
-
for (let
|
|
640
|
-
H[
|
|
641
|
-
const
|
|
642
|
-
|
|
639
|
+
for (let z = 0; z < E; z++) {
|
|
640
|
+
H[z] = j;
|
|
641
|
+
const Y = N[z]?.virtualizer?.itemHeight;
|
|
642
|
+
j += Y || r;
|
|
643
643
|
}
|
|
644
|
-
return { totalHeight:
|
|
644
|
+
return { totalHeight: j, positions: H };
|
|
645
645
|
}, [
|
|
646
|
-
|
|
647
|
-
|
|
646
|
+
E,
|
|
647
|
+
t,
|
|
648
648
|
n.join("."),
|
|
649
|
-
|
|
649
|
+
r,
|
|
650
650
|
D
|
|
651
|
-
]),
|
|
652
|
-
const
|
|
653
|
-
{ length:
|
|
654
|
-
(
|
|
655
|
-
),
|
|
656
|
-
return a(
|
|
651
|
+
]), C = wt(() => {
|
|
652
|
+
const N = Math.max(0, T.startIndex), j = Math.min(E, T.endIndex), H = Array.from(
|
|
653
|
+
{ length: j - N },
|
|
654
|
+
(Y, Z) => N + Z
|
|
655
|
+
), z = H.map((Y) => k[Y]);
|
|
656
|
+
return a(z, n, {
|
|
657
657
|
...S,
|
|
658
658
|
validIndices: H
|
|
659
659
|
});
|
|
660
|
-
}, [
|
|
661
|
-
|
|
662
|
-
const
|
|
660
|
+
}, [T.startIndex, T.endIndex, k, E]);
|
|
661
|
+
ft(() => {
|
|
662
|
+
const N = u.current;
|
|
663
|
+
if (!N) return;
|
|
664
|
+
const j = !B(
|
|
663
665
|
f,
|
|
664
|
-
|
|
665
|
-
),
|
|
666
|
-
if (
|
|
666
|
+
V.current
|
|
667
|
+
), H = E > b.current;
|
|
668
|
+
if (j) {
|
|
667
669
|
console.log(
|
|
668
|
-
"
|
|
669
|
-
),
|
|
670
|
+
"EVENT: Chat changed. Resetting state and scrolling."
|
|
671
|
+
), O("SCROLLING_TO_BOTTOM");
|
|
670
672
|
return;
|
|
671
673
|
}
|
|
672
|
-
|
|
673
|
-
"STATE_TRANSITION: New items arrived while locked. -> GETTING_ARRAY_HEIGHTS"
|
|
674
|
-
), C("GETTING_ARRAY_HEIGHTS")), $.current = y, k.current = f;
|
|
675
|
-
}, [y, ...f]), ie(() => {
|
|
676
|
-
const E = u.current;
|
|
677
|
-
if (!E) return;
|
|
678
|
-
let b, H;
|
|
679
|
-
if (w === "WAITING_FOR_ARRAY" && y > 0 && c)
|
|
674
|
+
if (H && A === "IDLE" && N.scrollHeight - N.scrollTop - N.clientHeight < r && c) {
|
|
680
675
|
console.log(
|
|
681
|
-
"
|
|
682
|
-
),
|
|
683
|
-
|
|
676
|
+
"EVENT: New message arrived while at bottom. -> SCROLLING_TO_BOTTOM"
|
|
677
|
+
), O("SCROLLING_TO_BOTTOM");
|
|
678
|
+
return;
|
|
679
|
+
}
|
|
680
|
+
let z;
|
|
681
|
+
if (A === "SCROLLING_TO_BOTTOM") {
|
|
682
|
+
const Z = b.current === 0 || j, lt = Z ? "auto" : "smooth";
|
|
684
683
|
console.log(
|
|
685
|
-
|
|
686
|
-
),
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
}),
|
|
690
|
-
const F = y - 1;
|
|
691
|
-
((r.getState().getShadowMetadata(e, n) || [])[F]?.virtualizer?.itemHeight || 0) > 0 && (clearInterval(b), console.log(
|
|
692
|
-
"ACTION: Measurement success. -> MOVING_TO_BOTTOM"
|
|
693
|
-
), C("MOVING_TO_BOTTOM"));
|
|
694
|
-
}, 100);
|
|
695
|
-
else if (w === "MOVING_TO_BOTTOM") {
|
|
696
|
-
console.log("ACTION: MOVING_TO_BOTTOM. Executing scroll.");
|
|
697
|
-
const F = $.current === 0 ? "auto" : "smooth";
|
|
698
|
-
E.scrollTo({
|
|
699
|
-
top: E.scrollHeight,
|
|
700
|
-
behavior: F
|
|
701
|
-
}), H = setTimeout(
|
|
684
|
+
`ACTION: Scrolling to bottom. Behavior: ${lt}`
|
|
685
|
+
), N.scrollTo({
|
|
686
|
+
top: N.scrollHeight,
|
|
687
|
+
behavior: lt
|
|
688
|
+
}), z = setTimeout(
|
|
702
689
|
() => {
|
|
703
|
-
console.log(
|
|
704
|
-
"ACTION: Scroll finished. -> LOCKED_AT_BOTTOM"
|
|
705
|
-
), C("LOCKED_AT_BOTTOM");
|
|
690
|
+
console.log("ACTION: Scroll finished. -> IDLE"), O("IDLE");
|
|
706
691
|
},
|
|
707
|
-
|
|
692
|
+
Z ? 50 : 500
|
|
708
693
|
);
|
|
709
694
|
}
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
!(E.scrollHeight - E.scrollTop - E.clientHeight < 1) && (w === "LOCKED_AT_BOTTOM" || w === "MOVING_TO_BOTTOM") && (console.log(
|
|
718
|
-
"USER_ACTION: Scrolled up. -> IDLE_NOT_AT_BOTTOM"
|
|
719
|
-
), C("IDLE_NOT_AT_BOTTOM"));
|
|
720
|
-
const { scrollTop: F, clientHeight: ee } = E;
|
|
721
|
-
let ne = 0, de = y - 1;
|
|
722
|
-
for (; ne <= de; ) {
|
|
723
|
-
const he = Math.floor((ne + de) / 2);
|
|
724
|
-
R[he] < F ? ne = he + 1 : de = he - 1;
|
|
695
|
+
const Y = () => {
|
|
696
|
+
A === "SCROLLING_TO_BOTTOM" && (console.log("USER ACTION: Interrupted scroll. -> IDLE"), O("IDLE"));
|
|
697
|
+
const { scrollTop: Z, clientHeight: lt } = N;
|
|
698
|
+
let It = 0, dt = E - 1;
|
|
699
|
+
for (; It <= dt; ) {
|
|
700
|
+
const yt = Math.floor((It + dt) / 2);
|
|
701
|
+
_[yt] < Z ? It = yt + 1 : dt = yt - 1;
|
|
725
702
|
}
|
|
726
|
-
const
|
|
727
|
-
let
|
|
728
|
-
const
|
|
729
|
-
for (;
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
startIndex:
|
|
733
|
-
endIndex: Math.min(
|
|
703
|
+
const Ct = Math.max(0, dt - s);
|
|
704
|
+
let ut = Ct;
|
|
705
|
+
const Lt = Z + lt;
|
|
706
|
+
for (; ut < E && _[ut] < Lt; )
|
|
707
|
+
ut++;
|
|
708
|
+
w({
|
|
709
|
+
startIndex: Ct,
|
|
710
|
+
endIndex: Math.min(E, ut + s)
|
|
734
711
|
});
|
|
735
712
|
};
|
|
736
|
-
return
|
|
713
|
+
return N.addEventListener("scroll", Y, {
|
|
737
714
|
passive: !0
|
|
738
|
-
}), ()
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
715
|
+
}), A === "IDLE" && Y(), b.current = E, V.current = f, () => {
|
|
716
|
+
N.removeEventListener("scroll", Y), z && clearTimeout(z);
|
|
717
|
+
};
|
|
718
|
+
}, [E, _, A, ...f]);
|
|
719
|
+
const U = $t(() => {
|
|
720
|
+
console.log(
|
|
721
|
+
"USER ACTION: Clicked scroll button -> SCROLLING_TO_BOTTOM"
|
|
722
|
+
), O("SCROLLING_TO_BOTTOM");
|
|
723
|
+
}, []), M = $t(
|
|
724
|
+
(N, j = "smooth") => {
|
|
725
|
+
u.current && _[N] !== void 0 && (O("IDLE"), u.current.scrollTo({
|
|
726
|
+
top: _[N],
|
|
727
|
+
behavior: j
|
|
728
|
+
}));
|
|
749
729
|
},
|
|
750
|
-
[
|
|
751
|
-
),
|
|
730
|
+
[_]
|
|
731
|
+
), W = {
|
|
752
732
|
outer: {
|
|
753
733
|
ref: u,
|
|
754
734
|
style: { overflowY: "auto", height: "100%" }
|
|
755
735
|
},
|
|
756
736
|
inner: {
|
|
757
737
|
style: {
|
|
758
|
-
height: `${
|
|
738
|
+
height: `${P}px`,
|
|
759
739
|
position: "relative"
|
|
760
740
|
}
|
|
761
741
|
},
|
|
762
742
|
list: {
|
|
763
743
|
style: {
|
|
764
|
-
transform: `translateY(${
|
|
744
|
+
transform: `translateY(${_[T.startIndex] || 0}px)`
|
|
765
745
|
}
|
|
766
746
|
}
|
|
767
747
|
};
|
|
768
748
|
return {
|
|
769
|
-
virtualState:
|
|
770
|
-
virtualizerProps:
|
|
771
|
-
scrollToBottom:
|
|
772
|
-
scrollToIndex:
|
|
749
|
+
virtualState: C,
|
|
750
|
+
virtualizerProps: W,
|
|
751
|
+
scrollToBottom: U,
|
|
752
|
+
scrollToIndex: M
|
|
773
753
|
};
|
|
774
754
|
};
|
|
775
755
|
if (l === "stateSort")
|
|
776
|
-
return (
|
|
756
|
+
return (e) => {
|
|
777
757
|
const s = [...d()].sort(
|
|
778
|
-
(u,
|
|
758
|
+
(u, T) => e(u.item, T.item)
|
|
779
759
|
), c = s.map(({ item: u }) => u), f = {
|
|
780
760
|
...S,
|
|
781
761
|
validIndices: s.map(
|
|
@@ -785,9 +765,9 @@ function Se(e, i, m, g) {
|
|
|
785
765
|
return a(c, n, f);
|
|
786
766
|
};
|
|
787
767
|
if (l === "stateFilter")
|
|
788
|
-
return (
|
|
768
|
+
return (e) => {
|
|
789
769
|
const s = d().filter(
|
|
790
|
-
({ item: u },
|
|
770
|
+
({ item: u }, T) => e(u, T)
|
|
791
771
|
), c = s.map(({ item: u }) => u), f = {
|
|
792
772
|
...S,
|
|
793
773
|
validIndices: s.map(
|
|
@@ -797,73 +777,73 @@ function Se(e, i, m, g) {
|
|
|
797
777
|
return a(c, n, f);
|
|
798
778
|
};
|
|
799
779
|
if (l === "stateMap")
|
|
800
|
-
return (
|
|
801
|
-
const
|
|
802
|
-
return Array.isArray(
|
|
803
|
-
const u =
|
|
804
|
-
return
|
|
780
|
+
return (e) => {
|
|
781
|
+
const r = o.getState().getNestedState(t, n);
|
|
782
|
+
return Array.isArray(r) ? (S?.validIndices || Array.from({ length: r.length }, (c, f) => f)).map((c, f) => {
|
|
783
|
+
const u = r[c], T = [...n, c.toString()], w = a(u, T, S);
|
|
784
|
+
return e(u, w, {
|
|
805
785
|
register: () => {
|
|
806
|
-
const [,
|
|
807
|
-
|
|
808
|
-
const
|
|
786
|
+
const [, O] = Q({}), b = `${m}-${n.join(".")}-${c}`;
|
|
787
|
+
ft(() => {
|
|
788
|
+
const V = `${t}////${b}`, D = o.getState().stateComponents.get(t) || {
|
|
809
789
|
components: /* @__PURE__ */ new Map()
|
|
810
790
|
};
|
|
811
|
-
return D.components.set(
|
|
812
|
-
forceUpdate: () =>
|
|
813
|
-
paths: /* @__PURE__ */ new Set([
|
|
814
|
-
}),
|
|
815
|
-
const
|
|
816
|
-
|
|
791
|
+
return D.components.set(V, {
|
|
792
|
+
forceUpdate: () => O({}),
|
|
793
|
+
paths: /* @__PURE__ */ new Set([T.join(".")])
|
|
794
|
+
}), o.getState().stateComponents.set(t, D), () => {
|
|
795
|
+
const J = o.getState().stateComponents.get(t);
|
|
796
|
+
J && J.components.delete(V);
|
|
817
797
|
};
|
|
818
|
-
}, [
|
|
798
|
+
}, [t, b]);
|
|
819
799
|
},
|
|
820
800
|
index: f,
|
|
821
801
|
originalIndex: c
|
|
822
802
|
});
|
|
823
803
|
}) : (console.warn(
|
|
824
804
|
`stateMap called on a non-array value at path: ${n.join(".")}. The current value is:`,
|
|
825
|
-
|
|
805
|
+
r
|
|
826
806
|
), null);
|
|
827
807
|
};
|
|
828
808
|
if (l === "stateMapNoRender")
|
|
829
|
-
return (
|
|
809
|
+
return (e) => v.map((s, c) => {
|
|
830
810
|
let f;
|
|
831
811
|
S?.validIndices && S.validIndices[c] !== void 0 ? f = S.validIndices[c] : f = c;
|
|
832
|
-
const u = [...n, f.toString()],
|
|
833
|
-
return
|
|
812
|
+
const u = [...n, f.toString()], T = a(s, u, S);
|
|
813
|
+
return e(
|
|
834
814
|
s,
|
|
835
|
-
|
|
815
|
+
T,
|
|
836
816
|
c,
|
|
837
|
-
|
|
838
|
-
a(
|
|
817
|
+
v,
|
|
818
|
+
a(v, n, S)
|
|
839
819
|
);
|
|
840
820
|
});
|
|
841
821
|
if (l === "$stateMap")
|
|
842
|
-
return (
|
|
822
|
+
return (e) => it(Kt, {
|
|
843
823
|
proxy: {
|
|
844
|
-
_stateKey:
|
|
824
|
+
_stateKey: t,
|
|
845
825
|
_path: n,
|
|
846
|
-
_mapFn:
|
|
826
|
+
_mapFn: e
|
|
847
827
|
// Pass the actual function, not string
|
|
848
828
|
},
|
|
849
829
|
rebuildStateShape: a
|
|
850
830
|
});
|
|
851
831
|
if (l === "stateList")
|
|
852
|
-
return (
|
|
853
|
-
const
|
|
854
|
-
return Array.isArray(
|
|
855
|
-
const u =
|
|
856
|
-
return
|
|
832
|
+
return (e) => {
|
|
833
|
+
const r = o.getState().getNestedState(t, n);
|
|
834
|
+
return Array.isArray(r) ? (S?.validIndices || Array.from({ length: r.length }, (c, f) => f)).map((c, f) => {
|
|
835
|
+
const u = r[c], T = [...n, c.toString()], w = a(u, T, S), A = `${m}-${n.join(".")}-${c}`;
|
|
836
|
+
return it(ee, {
|
|
857
837
|
key: c,
|
|
858
|
-
stateKey:
|
|
859
|
-
itemComponentId:
|
|
860
|
-
itemPath:
|
|
861
|
-
children:
|
|
838
|
+
stateKey: t,
|
|
839
|
+
itemComponentId: A,
|
|
840
|
+
itemPath: T,
|
|
841
|
+
children: e(
|
|
862
842
|
u,
|
|
863
|
-
|
|
843
|
+
w,
|
|
864
844
|
f,
|
|
865
|
-
|
|
866
|
-
a(
|
|
845
|
+
r,
|
|
846
|
+
a(r, n, S)
|
|
867
847
|
)
|
|
868
848
|
});
|
|
869
849
|
}) : (console.warn(
|
|
@@ -871,420 +851,420 @@ function Se(e, i, m, g) {
|
|
|
871
851
|
), null);
|
|
872
852
|
};
|
|
873
853
|
if (l === "stateFlattenOn")
|
|
874
|
-
return (
|
|
875
|
-
const
|
|
876
|
-
|
|
877
|
-
const s =
|
|
878
|
-
(c) => c[
|
|
854
|
+
return (e) => {
|
|
855
|
+
const r = v;
|
|
856
|
+
I.clear(), $++;
|
|
857
|
+
const s = r.flatMap(
|
|
858
|
+
(c) => c[e] ?? []
|
|
879
859
|
);
|
|
880
860
|
return a(
|
|
881
861
|
s,
|
|
882
|
-
[...n, "[*]",
|
|
862
|
+
[...n, "[*]", e],
|
|
883
863
|
S
|
|
884
864
|
);
|
|
885
865
|
};
|
|
886
866
|
if (l === "index")
|
|
887
|
-
return (
|
|
888
|
-
const
|
|
889
|
-
return a(
|
|
867
|
+
return (e) => {
|
|
868
|
+
const r = v[e];
|
|
869
|
+
return a(r, [...n, e.toString()]);
|
|
890
870
|
};
|
|
891
871
|
if (l === "last")
|
|
892
872
|
return () => {
|
|
893
|
-
const
|
|
894
|
-
if (
|
|
895
|
-
const
|
|
873
|
+
const e = o.getState().getNestedState(t, n);
|
|
874
|
+
if (e.length === 0) return;
|
|
875
|
+
const r = e.length - 1, s = e[r], c = [...n, r.toString()];
|
|
896
876
|
return a(s, c);
|
|
897
877
|
};
|
|
898
878
|
if (l === "insert")
|
|
899
|
-
return (
|
|
900
|
-
|
|
879
|
+
return (e) => (p(n), pt(i, e, n, t), a(
|
|
880
|
+
o.getState().getNestedState(t, n),
|
|
901
881
|
n
|
|
902
882
|
));
|
|
903
883
|
if (l === "uniqueInsert")
|
|
904
|
-
return (
|
|
905
|
-
const c =
|
|
884
|
+
return (e, r, s) => {
|
|
885
|
+
const c = o.getState().getNestedState(t, n), f = K(e) ? e(c) : e;
|
|
906
886
|
let u = null;
|
|
907
|
-
if (!c.some((
|
|
908
|
-
if (
|
|
909
|
-
const
|
|
910
|
-
(
|
|
887
|
+
if (!c.some((w) => {
|
|
888
|
+
if (r) {
|
|
889
|
+
const O = r.every(
|
|
890
|
+
(b) => B(w[b], f[b])
|
|
911
891
|
);
|
|
912
|
-
return
|
|
892
|
+
return O && (u = w), O;
|
|
913
893
|
}
|
|
914
|
-
const
|
|
915
|
-
return
|
|
894
|
+
const A = B(w, f);
|
|
895
|
+
return A && (u = w), A;
|
|
916
896
|
}))
|
|
917
|
-
|
|
897
|
+
p(n), pt(i, f, n, t);
|
|
918
898
|
else if (s && u) {
|
|
919
|
-
const
|
|
920
|
-
(
|
|
899
|
+
const w = s(u), A = c.map(
|
|
900
|
+
(O) => B(O, u) ? w : O
|
|
921
901
|
);
|
|
922
|
-
|
|
902
|
+
p(n), at(i, A, n);
|
|
923
903
|
}
|
|
924
904
|
};
|
|
925
905
|
if (l === "cut")
|
|
926
|
-
return (
|
|
927
|
-
if (!
|
|
928
|
-
return
|
|
929
|
-
|
|
906
|
+
return (e, r) => {
|
|
907
|
+
if (!r?.waitForSync)
|
|
908
|
+
return p(n), gt(i, n, t, e), a(
|
|
909
|
+
o.getState().getNestedState(t, n),
|
|
930
910
|
n
|
|
931
911
|
);
|
|
932
912
|
};
|
|
933
913
|
if (l === "cutByValue")
|
|
934
|
-
return (
|
|
935
|
-
for (let
|
|
936
|
-
|
|
914
|
+
return (e) => {
|
|
915
|
+
for (let r = 0; r < v.length; r++)
|
|
916
|
+
v[r] === e && gt(i, n, t, r);
|
|
937
917
|
};
|
|
938
918
|
if (l === "toggleByValue")
|
|
939
|
-
return (
|
|
940
|
-
const
|
|
941
|
-
|
|
919
|
+
return (e) => {
|
|
920
|
+
const r = v.findIndex((s) => s === e);
|
|
921
|
+
r > -1 ? gt(i, n, t, r) : pt(i, e, n, t);
|
|
942
922
|
};
|
|
943
923
|
if (l === "stateFind")
|
|
944
|
-
return (
|
|
924
|
+
return (e) => {
|
|
945
925
|
const s = d().find(
|
|
946
|
-
({ item: f }, u) =>
|
|
926
|
+
({ item: f }, u) => e(f, u)
|
|
947
927
|
);
|
|
948
928
|
if (!s) return;
|
|
949
929
|
const c = [...n, s.originalIndex.toString()];
|
|
950
930
|
return a(s.item, c, S);
|
|
951
931
|
};
|
|
952
932
|
if (l === "findWith")
|
|
953
|
-
return (
|
|
933
|
+
return (e, r) => {
|
|
954
934
|
const c = d().find(
|
|
955
|
-
({ item: u }) => u[
|
|
935
|
+
({ item: u }) => u[e] === r
|
|
956
936
|
);
|
|
957
937
|
if (!c) return;
|
|
958
938
|
const f = [...n, c.originalIndex.toString()];
|
|
959
939
|
return a(c.item, f, S);
|
|
960
940
|
};
|
|
961
941
|
}
|
|
962
|
-
const
|
|
963
|
-
if (!isNaN(Number(
|
|
964
|
-
const d = n.slice(0, -1),
|
|
965
|
-
if (Array.isArray(
|
|
966
|
-
return () =>
|
|
942
|
+
const et = n[n.length - 1];
|
|
943
|
+
if (!isNaN(Number(et))) {
|
|
944
|
+
const d = n.slice(0, -1), e = o.getState().getNestedState(t, d);
|
|
945
|
+
if (Array.isArray(e) && l === "cut")
|
|
946
|
+
return () => gt(
|
|
967
947
|
i,
|
|
968
948
|
d,
|
|
969
|
-
|
|
970
|
-
Number(
|
|
949
|
+
t,
|
|
950
|
+
Number(et)
|
|
971
951
|
);
|
|
972
952
|
}
|
|
973
953
|
if (l === "get")
|
|
974
954
|
return () => {
|
|
975
|
-
if (S?.validIndices && Array.isArray(
|
|
976
|
-
const d =
|
|
977
|
-
return S.validIndices.map((
|
|
955
|
+
if (S?.validIndices && Array.isArray(v)) {
|
|
956
|
+
const d = o.getState().getNestedState(t, n);
|
|
957
|
+
return S.validIndices.map((e) => d[e]);
|
|
978
958
|
}
|
|
979
|
-
return
|
|
959
|
+
return o.getState().getNestedState(t, n);
|
|
980
960
|
};
|
|
981
961
|
if (l === "$derive")
|
|
982
|
-
return (d) =>
|
|
983
|
-
_stateKey:
|
|
962
|
+
return (d) => Vt({
|
|
963
|
+
_stateKey: t,
|
|
984
964
|
_path: n,
|
|
985
965
|
_effect: d.toString()
|
|
986
966
|
});
|
|
987
967
|
if (l === "$get")
|
|
988
|
-
return () =>
|
|
989
|
-
_stateKey:
|
|
968
|
+
return () => Vt({
|
|
969
|
+
_stateKey: t,
|
|
990
970
|
_path: n
|
|
991
971
|
});
|
|
992
972
|
if (l === "lastSynced") {
|
|
993
|
-
const d = `${
|
|
994
|
-
return
|
|
973
|
+
const d = `${t}:${n.join(".")}`;
|
|
974
|
+
return o.getState().getSyncInfo(d);
|
|
995
975
|
}
|
|
996
976
|
if (l == "getLocalStorage")
|
|
997
|
-
return (d) =>
|
|
977
|
+
return (d) => ht(g + "-" + t + "-" + d);
|
|
998
978
|
if (l === "_selected") {
|
|
999
|
-
const d = n.slice(0, -1),
|
|
1000
|
-
return Array.isArray(
|
|
979
|
+
const d = n.slice(0, -1), e = d.join("."), r = o.getState().getNestedState(t, d);
|
|
980
|
+
return Array.isArray(r) ? Number(n[n.length - 1]) === o.getState().getSelectedIndex(t, e) : void 0;
|
|
1001
981
|
}
|
|
1002
982
|
if (l === "setSelected")
|
|
1003
983
|
return (d) => {
|
|
1004
|
-
const
|
|
1005
|
-
d ?
|
|
1006
|
-
const c =
|
|
1007
|
-
|
|
984
|
+
const e = n.slice(0, -1), r = Number(n[n.length - 1]), s = e.join(".");
|
|
985
|
+
d ? o.getState().setSelectedIndex(t, s, r) : o.getState().setSelectedIndex(t, s, void 0);
|
|
986
|
+
const c = o.getState().getNestedState(t, [...e]);
|
|
987
|
+
at(i, c, e), p(e);
|
|
1008
988
|
};
|
|
1009
989
|
if (l === "toggleSelected")
|
|
1010
990
|
return () => {
|
|
1011
|
-
const d = n.slice(0, -1),
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
s ===
|
|
991
|
+
const d = n.slice(0, -1), e = Number(n[n.length - 1]), r = d.join("."), s = o.getState().getSelectedIndex(t, r);
|
|
992
|
+
o.getState().setSelectedIndex(
|
|
993
|
+
t,
|
|
994
|
+
r,
|
|
995
|
+
s === e ? void 0 : e
|
|
1016
996
|
);
|
|
1017
|
-
const c =
|
|
1018
|
-
|
|
997
|
+
const c = o.getState().getNestedState(t, [...d]);
|
|
998
|
+
at(i, c, d), p(d);
|
|
1019
999
|
};
|
|
1020
1000
|
if (n.length == 0) {
|
|
1021
1001
|
if (l === "applyJsonPatch")
|
|
1022
1002
|
return (d) => {
|
|
1023
|
-
const
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1003
|
+
const e = o.getState().cogsStateStore[t], s = Bt(e, d).newDocument;
|
|
1004
|
+
Mt(
|
|
1005
|
+
t,
|
|
1006
|
+
o.getState().initialStateGlobal[t],
|
|
1027
1007
|
s,
|
|
1028
1008
|
i,
|
|
1029
1009
|
m,
|
|
1030
1010
|
g
|
|
1031
1011
|
);
|
|
1032
|
-
const c =
|
|
1012
|
+
const c = o.getState().stateComponents.get(t);
|
|
1033
1013
|
if (c) {
|
|
1034
|
-
const f =
|
|
1014
|
+
const f = Et(e, s), u = new Set(f);
|
|
1035
1015
|
for (const [
|
|
1036
|
-
|
|
1037
|
-
|
|
1016
|
+
T,
|
|
1017
|
+
w
|
|
1038
1018
|
] of c.components.entries()) {
|
|
1039
|
-
let
|
|
1040
|
-
const
|
|
1041
|
-
if (!
|
|
1042
|
-
if (
|
|
1043
|
-
|
|
1019
|
+
let A = !1;
|
|
1020
|
+
const O = Array.isArray(w.reactiveType) ? w.reactiveType : [w.reactiveType || "component"];
|
|
1021
|
+
if (!O.includes("none")) {
|
|
1022
|
+
if (O.includes("all")) {
|
|
1023
|
+
w.forceUpdate();
|
|
1044
1024
|
continue;
|
|
1045
1025
|
}
|
|
1046
|
-
if (
|
|
1047
|
-
for (const
|
|
1048
|
-
if (
|
|
1049
|
-
|
|
1026
|
+
if (O.includes("component") && (w.paths.has("") && (A = !0), !A))
|
|
1027
|
+
for (const b of u) {
|
|
1028
|
+
if (w.paths.has(b)) {
|
|
1029
|
+
A = !0;
|
|
1050
1030
|
break;
|
|
1051
1031
|
}
|
|
1052
|
-
let
|
|
1053
|
-
for (;
|
|
1054
|
-
const D =
|
|
1055
|
-
if (
|
|
1056
|
-
|
|
1032
|
+
let V = b.lastIndexOf(".");
|
|
1033
|
+
for (; V !== -1; ) {
|
|
1034
|
+
const D = b.substring(0, V);
|
|
1035
|
+
if (w.paths.has(D)) {
|
|
1036
|
+
A = !0;
|
|
1057
1037
|
break;
|
|
1058
1038
|
}
|
|
1059
|
-
const
|
|
1060
|
-
|
|
1039
|
+
const J = b.substring(
|
|
1040
|
+
V + 1
|
|
1061
1041
|
);
|
|
1062
|
-
if (!isNaN(Number(
|
|
1063
|
-
const
|
|
1064
|
-
if (
|
|
1065
|
-
const
|
|
1042
|
+
if (!isNaN(Number(J))) {
|
|
1043
|
+
const k = D.lastIndexOf(".");
|
|
1044
|
+
if (k !== -1) {
|
|
1045
|
+
const E = D.substring(
|
|
1066
1046
|
0,
|
|
1067
|
-
|
|
1047
|
+
k
|
|
1068
1048
|
);
|
|
1069
|
-
if (
|
|
1070
|
-
|
|
1049
|
+
if (w.paths.has(E)) {
|
|
1050
|
+
A = !0;
|
|
1071
1051
|
break;
|
|
1072
1052
|
}
|
|
1073
1053
|
}
|
|
1074
1054
|
}
|
|
1075
|
-
|
|
1055
|
+
V = D.lastIndexOf(".");
|
|
1076
1056
|
}
|
|
1077
|
-
if (
|
|
1057
|
+
if (A) break;
|
|
1078
1058
|
}
|
|
1079
|
-
if (!
|
|
1080
|
-
const
|
|
1081
|
-
let
|
|
1082
|
-
typeof
|
|
1059
|
+
if (!A && O.includes("deps") && w.depsFunction) {
|
|
1060
|
+
const b = w.depsFunction(s);
|
|
1061
|
+
let V = !1;
|
|
1062
|
+
typeof b == "boolean" ? b && (V = !0) : B(w.deps, b) || (w.deps = b, V = !0), V && (A = !0);
|
|
1083
1063
|
}
|
|
1084
|
-
|
|
1064
|
+
A && w.forceUpdate();
|
|
1085
1065
|
}
|
|
1086
1066
|
}
|
|
1087
1067
|
}
|
|
1088
1068
|
};
|
|
1089
1069
|
if (l === "validateZodSchema")
|
|
1090
1070
|
return () => {
|
|
1091
|
-
const d =
|
|
1071
|
+
const d = o.getState().getInitialOptions(t)?.validation, e = o.getState().addValidationError;
|
|
1092
1072
|
if (!d?.zodSchema)
|
|
1093
1073
|
throw new Error("Zod schema not found");
|
|
1094
1074
|
if (!d?.key)
|
|
1095
1075
|
throw new Error("Validation key not found");
|
|
1096
|
-
|
|
1097
|
-
const
|
|
1076
|
+
X(d.key);
|
|
1077
|
+
const r = o.getState().cogsStateStore[t];
|
|
1098
1078
|
try {
|
|
1099
|
-
const s =
|
|
1079
|
+
const s = o.getState().getValidationErrors(d.key);
|
|
1100
1080
|
s && s.length > 0 && s.forEach(([f]) => {
|
|
1101
|
-
f && f.startsWith(d.key) &&
|
|
1081
|
+
f && f.startsWith(d.key) && X(f);
|
|
1102
1082
|
});
|
|
1103
|
-
const c = d.zodSchema.safeParse(
|
|
1083
|
+
const c = d.zodSchema.safeParse(r);
|
|
1104
1084
|
return c.success ? !0 : (c.error.errors.forEach((u) => {
|
|
1105
|
-
const
|
|
1106
|
-
|
|
1107
|
-
}),
|
|
1085
|
+
const T = u.path, w = u.message, A = [d.key, ...T].join(".");
|
|
1086
|
+
e(A, w);
|
|
1087
|
+
}), vt(t), !1);
|
|
1108
1088
|
} catch (s) {
|
|
1109
1089
|
return console.error("Zod schema validation failed", s), !1;
|
|
1110
1090
|
}
|
|
1111
1091
|
};
|
|
1112
1092
|
if (l === "_componentId") return m;
|
|
1113
1093
|
if (l === "getComponents")
|
|
1114
|
-
return () =>
|
|
1094
|
+
return () => o().stateComponents.get(t);
|
|
1115
1095
|
if (l === "getAllFormRefs")
|
|
1116
|
-
return () =>
|
|
1096
|
+
return () => Ot.getState().getFormRefsByStateKey(t);
|
|
1117
1097
|
if (l === "_initialState")
|
|
1118
|
-
return
|
|
1098
|
+
return o.getState().initialStateGlobal[t];
|
|
1119
1099
|
if (l === "_serverState")
|
|
1120
|
-
return
|
|
1100
|
+
return o.getState().serverState[t];
|
|
1121
1101
|
if (l === "_isLoading")
|
|
1122
|
-
return
|
|
1102
|
+
return o.getState().isLoadingGlobal[t];
|
|
1123
1103
|
if (l === "revertToInitialState")
|
|
1124
|
-
return
|
|
1125
|
-
if (l === "updateInitialState") return
|
|
1126
|
-
if (l === "removeValidation") return
|
|
1104
|
+
return y.revertToInitialState;
|
|
1105
|
+
if (l === "updateInitialState") return y.updateInitialState;
|
|
1106
|
+
if (l === "removeValidation") return y.removeValidation;
|
|
1127
1107
|
}
|
|
1128
1108
|
if (l === "getFormRef")
|
|
1129
|
-
return () =>
|
|
1109
|
+
return () => Ot.getState().getFormRef(t + "." + n.join("."));
|
|
1130
1110
|
if (l === "validationWrapper")
|
|
1131
1111
|
return ({
|
|
1132
1112
|
children: d,
|
|
1133
|
-
hideMessage:
|
|
1134
|
-
}) => /* @__PURE__ */
|
|
1135
|
-
|
|
1113
|
+
hideMessage: e
|
|
1114
|
+
}) => /* @__PURE__ */ Tt(
|
|
1115
|
+
Ft,
|
|
1136
1116
|
{
|
|
1137
|
-
formOpts:
|
|
1117
|
+
formOpts: e ? { validation: { message: "" } } : void 0,
|
|
1138
1118
|
path: n,
|
|
1139
|
-
validationKey:
|
|
1140
|
-
stateKey:
|
|
1119
|
+
validationKey: o.getState().getInitialOptions(t)?.validation?.key || "",
|
|
1120
|
+
stateKey: t,
|
|
1141
1121
|
validIndices: S?.validIndices,
|
|
1142
1122
|
children: d
|
|
1143
1123
|
}
|
|
1144
1124
|
);
|
|
1145
|
-
if (l === "_stateKey") return
|
|
1125
|
+
if (l === "_stateKey") return t;
|
|
1146
1126
|
if (l === "_path") return n;
|
|
1147
|
-
if (l === "_isServerSynced") return
|
|
1127
|
+
if (l === "_isServerSynced") return y._isServerSynced;
|
|
1148
1128
|
if (l === "update")
|
|
1149
|
-
return (d,
|
|
1150
|
-
if (
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
const
|
|
1154
|
-
|
|
1155
|
-
},
|
|
1129
|
+
return (d, e) => {
|
|
1130
|
+
if (e?.debounce)
|
|
1131
|
+
Dt(() => {
|
|
1132
|
+
at(i, d, n, "");
|
|
1133
|
+
const r = o.getState().getNestedState(t, n);
|
|
1134
|
+
e?.afterUpdate && e.afterUpdate(r);
|
|
1135
|
+
}, e.debounce);
|
|
1156
1136
|
else {
|
|
1157
|
-
|
|
1158
|
-
const
|
|
1159
|
-
|
|
1137
|
+
at(i, d, n, "");
|
|
1138
|
+
const r = o.getState().getNestedState(t, n);
|
|
1139
|
+
e?.afterUpdate && e.afterUpdate(r);
|
|
1160
1140
|
}
|
|
1161
|
-
|
|
1141
|
+
p(n);
|
|
1162
1142
|
};
|
|
1163
1143
|
if (l === "formElement")
|
|
1164
|
-
return (d,
|
|
1165
|
-
|
|
1144
|
+
return (d, e) => /* @__PURE__ */ Tt(
|
|
1145
|
+
Gt,
|
|
1166
1146
|
{
|
|
1167
1147
|
setState: i,
|
|
1168
|
-
stateKey:
|
|
1148
|
+
stateKey: t,
|
|
1169
1149
|
path: n,
|
|
1170
1150
|
child: d,
|
|
1171
|
-
formOpts:
|
|
1151
|
+
formOpts: e
|
|
1172
1152
|
}
|
|
1173
1153
|
);
|
|
1174
|
-
const
|
|
1175
|
-
return a(
|
|
1154
|
+
const x = [...n, l], ot = o.getState().getNestedState(t, x);
|
|
1155
|
+
return a(ot, x, S);
|
|
1176
1156
|
}
|
|
1177
|
-
},
|
|
1178
|
-
return
|
|
1179
|
-
proxy:
|
|
1180
|
-
stateVersion:
|
|
1181
|
-
}),
|
|
1157
|
+
}, G = new Proxy(L, R);
|
|
1158
|
+
return I.set(F, {
|
|
1159
|
+
proxy: G,
|
|
1160
|
+
stateVersion: $
|
|
1161
|
+
}), G;
|
|
1182
1162
|
}
|
|
1183
1163
|
return a(
|
|
1184
|
-
|
|
1164
|
+
o.getState().getNestedState(t, [])
|
|
1185
1165
|
);
|
|
1186
1166
|
}
|
|
1187
|
-
function
|
|
1188
|
-
return
|
|
1167
|
+
function Vt(t) {
|
|
1168
|
+
return it(te, { proxy: t });
|
|
1189
1169
|
}
|
|
1190
|
-
function
|
|
1191
|
-
proxy:
|
|
1170
|
+
function Kt({
|
|
1171
|
+
proxy: t,
|
|
1192
1172
|
rebuildStateShape: i
|
|
1193
1173
|
}) {
|
|
1194
|
-
const m =
|
|
1174
|
+
const m = o().getNestedState(t._stateKey, t._path);
|
|
1195
1175
|
return Array.isArray(m) ? i(
|
|
1196
1176
|
m,
|
|
1197
|
-
|
|
1177
|
+
t._path
|
|
1198
1178
|
).stateMapNoRender(
|
|
1199
|
-
(
|
|
1179
|
+
(I, $, p, y, a) => t._mapFn(I, $, p, y, a)
|
|
1200
1180
|
) : null;
|
|
1201
1181
|
}
|
|
1202
|
-
function
|
|
1203
|
-
proxy:
|
|
1182
|
+
function te({
|
|
1183
|
+
proxy: t
|
|
1204
1184
|
}) {
|
|
1205
|
-
const i =
|
|
1206
|
-
return
|
|
1185
|
+
const i = tt(null), m = `${t._stateKey}-${t._path.join(".")}`;
|
|
1186
|
+
return st(() => {
|
|
1207
1187
|
const g = i.current;
|
|
1208
1188
|
if (!g || !g.parentElement) return;
|
|
1209
|
-
const
|
|
1210
|
-
let
|
|
1211
|
-
|
|
1212
|
-
const
|
|
1189
|
+
const I = g.parentElement, p = Array.from(I.childNodes).indexOf(g);
|
|
1190
|
+
let y = I.getAttribute("data-parent-id");
|
|
1191
|
+
y || (y = `parent-${crypto.randomUUID()}`, I.setAttribute("data-parent-id", y));
|
|
1192
|
+
const v = {
|
|
1213
1193
|
instanceId: `instance-${crypto.randomUUID()}`,
|
|
1214
|
-
parentId:
|
|
1215
|
-
position:
|
|
1216
|
-
effect:
|
|
1194
|
+
parentId: y,
|
|
1195
|
+
position: p,
|
|
1196
|
+
effect: t._effect
|
|
1217
1197
|
};
|
|
1218
|
-
|
|
1219
|
-
const n =
|
|
1198
|
+
o.getState().addSignalElement(m, v);
|
|
1199
|
+
const n = o.getState().getNestedState(t._stateKey, t._path);
|
|
1220
1200
|
let S;
|
|
1221
|
-
if (
|
|
1201
|
+
if (t._effect)
|
|
1222
1202
|
try {
|
|
1223
1203
|
S = new Function(
|
|
1224
1204
|
"state",
|
|
1225
|
-
`return (${
|
|
1205
|
+
`return (${t._effect})(state)`
|
|
1226
1206
|
)(n);
|
|
1227
|
-
} catch (
|
|
1228
|
-
console.error("Error evaluating effect function during mount:",
|
|
1207
|
+
} catch (L) {
|
|
1208
|
+
console.error("Error evaluating effect function during mount:", L), S = n;
|
|
1229
1209
|
}
|
|
1230
1210
|
else
|
|
1231
1211
|
S = n;
|
|
1232
1212
|
S !== null && typeof S == "object" && (S = JSON.stringify(S));
|
|
1233
|
-
const
|
|
1234
|
-
g.replaceWith(
|
|
1235
|
-
}, [
|
|
1213
|
+
const F = document.createTextNode(String(S));
|
|
1214
|
+
g.replaceWith(F);
|
|
1215
|
+
}, [t._stateKey, t._path.join("."), t._effect]), it("span", {
|
|
1236
1216
|
ref: i,
|
|
1237
1217
|
style: { display: "none" },
|
|
1238
1218
|
"data-signal-id": m
|
|
1239
1219
|
});
|
|
1240
1220
|
}
|
|
1241
|
-
function
|
|
1242
|
-
const i =
|
|
1221
|
+
function he(t) {
|
|
1222
|
+
const i = Rt(
|
|
1243
1223
|
(m) => {
|
|
1244
|
-
const g =
|
|
1224
|
+
const g = o.getState().stateComponents.get(t._stateKey) || {
|
|
1245
1225
|
components: /* @__PURE__ */ new Map()
|
|
1246
1226
|
};
|
|
1247
|
-
return g.components.set(
|
|
1227
|
+
return g.components.set(t._stateKey, {
|
|
1248
1228
|
forceUpdate: m,
|
|
1249
|
-
paths: /* @__PURE__ */ new Set([
|
|
1250
|
-
}), () => g.components.delete(
|
|
1229
|
+
paths: /* @__PURE__ */ new Set([t._path.join(".")])
|
|
1230
|
+
}), () => g.components.delete(t._stateKey);
|
|
1251
1231
|
},
|
|
1252
|
-
() =>
|
|
1232
|
+
() => o.getState().getNestedState(t._stateKey, t._path)
|
|
1253
1233
|
);
|
|
1254
|
-
return
|
|
1234
|
+
return it("text", {}, String(i));
|
|
1255
1235
|
}
|
|
1256
|
-
function
|
|
1257
|
-
stateKey:
|
|
1236
|
+
function ee({
|
|
1237
|
+
stateKey: t,
|
|
1258
1238
|
itemComponentId: i,
|
|
1259
1239
|
itemPath: m,
|
|
1260
1240
|
children: g
|
|
1261
1241
|
}) {
|
|
1262
|
-
const [,
|
|
1263
|
-
return
|
|
1264
|
-
|
|
1242
|
+
const [, I] = Q({}), [$, p] = Ht(), y = tt(null);
|
|
1243
|
+
return st(() => {
|
|
1244
|
+
p.height > 0 && p.height !== y.current && (y.current = p.height, o.getState().setShadowMetadata(t, m, {
|
|
1265
1245
|
virtualizer: {
|
|
1266
|
-
itemHeight:
|
|
1246
|
+
itemHeight: p.height
|
|
1267
1247
|
}
|
|
1268
1248
|
}));
|
|
1269
|
-
}, [
|
|
1270
|
-
const a = `${
|
|
1249
|
+
}, [p.height, t, m]), ft(() => {
|
|
1250
|
+
const a = `${t}////${i}`, v = o.getState().stateComponents.get(t) || {
|
|
1271
1251
|
components: /* @__PURE__ */ new Map()
|
|
1272
1252
|
};
|
|
1273
|
-
return
|
|
1274
|
-
forceUpdate: () =>
|
|
1253
|
+
return v.components.set(a, {
|
|
1254
|
+
forceUpdate: () => I({}),
|
|
1275
1255
|
paths: /* @__PURE__ */ new Set([m.join(".")])
|
|
1276
|
-
}),
|
|
1277
|
-
const n =
|
|
1256
|
+
}), o.getState().stateComponents.set(t, v), () => {
|
|
1257
|
+
const n = o.getState().stateComponents.get(t);
|
|
1278
1258
|
n && n.components.delete(a);
|
|
1279
1259
|
};
|
|
1280
|
-
}, [
|
|
1260
|
+
}, [t, i, m.join(".")]), /* @__PURE__ */ Tt("div", { ref: $, children: g });
|
|
1281
1261
|
}
|
|
1282
1262
|
export {
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1263
|
+
Vt as $cogsSignal,
|
|
1264
|
+
he as $cogsSignalStore,
|
|
1265
|
+
fe as addStateOptions,
|
|
1266
|
+
Se as createCogsState,
|
|
1267
|
+
me as notifyComponent,
|
|
1268
|
+
Qt as useCogsStateFn
|
|
1289
1269
|
};
|
|
1290
1270
|
//# sourceMappingURL=CogsState.jsx.map
|