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