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