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