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