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