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