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