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