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