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