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