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