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