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