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