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