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