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