cogsbox-state 0.5.434 → 0.5.435
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 +13 -21
- package/dist/CogsState.jsx +1149 -1042
- package/dist/CogsState.jsx.map +1 -1
- package/dist/Functions.jsx +17 -18
- package/dist/Functions.jsx.map +1 -1
- package/dist/store.js +8 -6
- package/dist/store.js.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +411 -47
- package/src/store.ts +14 -5
package/dist/CogsState.jsx
CHANGED
|
@@ -1,393 +1,443 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as
|
|
3
|
-
import { memo as Re, useState as
|
|
2
|
+
import { jsx as re, Fragment as ke } from "react/jsx-runtime";
|
|
3
|
+
import { memo as Re, useState as X, useRef as G, useCallback as ce, useEffect as Q, useLayoutEffect as de, useMemo as ge, createElement as le, startTransition as je } from "react";
|
|
4
4
|
import { createRoot as Ce } from "react-dom/client";
|
|
5
|
-
import { transformStateFunc as Fe, isFunction as
|
|
6
|
-
import { ValidationWrapper as
|
|
7
|
-
import
|
|
8
|
-
import { v4 as
|
|
9
|
-
import "
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
function me(e, s) {
|
|
15
|
-
const p = t.getState().getInitialOptions, g = t.getState().setInitialStateOptions, v = p(e) || {};
|
|
5
|
+
import { transformStateFunc as Fe, isFunction as ee, isArray as Te, getDifferences as Pe, isDeepEqual as se } from "./utility.js";
|
|
6
|
+
import { ValidationWrapper as be } from "./Functions.jsx";
|
|
7
|
+
import Oe from "superjson";
|
|
8
|
+
import { v4 as te } from "uuid";
|
|
9
|
+
import { getGlobalStore as t, formRefStore as pe } from "./store.js";
|
|
10
|
+
import { useCogsConfig as _e } from "./CogsStateClient.jsx";
|
|
11
|
+
import { useInView as Le } from "react-intersection-observer";
|
|
12
|
+
function he(e, i) {
|
|
13
|
+
const f = t.getState().getInitialOptions, g = t.getState().setInitialStateOptions, h = f(e) || {};
|
|
16
14
|
g(e, {
|
|
17
|
-
...
|
|
18
|
-
...
|
|
15
|
+
...h,
|
|
16
|
+
...i
|
|
19
17
|
});
|
|
20
18
|
}
|
|
21
|
-
function
|
|
19
|
+
function Ee({
|
|
22
20
|
stateKey: e,
|
|
23
|
-
options:
|
|
24
|
-
initialOptionsPart:
|
|
21
|
+
options: i,
|
|
22
|
+
initialOptionsPart: f
|
|
25
23
|
}) {
|
|
26
|
-
const g =
|
|
27
|
-
let
|
|
28
|
-
if (
|
|
29
|
-
for (const
|
|
30
|
-
|
|
31
|
-
|
|
24
|
+
const g = ae(e) || {}, h = f[e] || {}, p = t.getState().setInitialStateOptions, M = { ...h, ...g };
|
|
25
|
+
let l = !1;
|
|
26
|
+
if (i)
|
|
27
|
+
for (const u in i)
|
|
28
|
+
M.hasOwnProperty(u) ? (u == "localStorage" && i[u] && M[u].key !== i[u]?.key && (l = !0, M[u] = i[u]), u == "defaultState" && i[u] && M[u] !== i[u] && !se(M[u], i[u]) && (l = !0, M[u] = i[u])) : (l = !0, M[u] = i[u]);
|
|
29
|
+
l && p(e, M);
|
|
32
30
|
}
|
|
33
|
-
function
|
|
34
|
-
return { initialState: e, formElements:
|
|
31
|
+
function it(e, { formElements: i, validation: f }) {
|
|
32
|
+
return { initialState: e, formElements: i, validation: f };
|
|
35
33
|
}
|
|
36
|
-
const
|
|
37
|
-
let
|
|
38
|
-
const [g,
|
|
39
|
-
Object.keys(g).forEach((
|
|
40
|
-
let
|
|
41
|
-
const
|
|
42
|
-
...
|
|
34
|
+
const ct = (e, i) => {
|
|
35
|
+
let f = e;
|
|
36
|
+
const [g, h] = Fe(f);
|
|
37
|
+
Object.keys(g).forEach((l) => {
|
|
38
|
+
let u = h[l] || {};
|
|
39
|
+
const A = {
|
|
40
|
+
...u
|
|
43
41
|
};
|
|
44
|
-
if (
|
|
45
|
-
...
|
|
46
|
-
...
|
|
47
|
-
}),
|
|
48
|
-
...
|
|
49
|
-
...
|
|
50
|
-
},
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
...
|
|
54
|
-
...
|
|
55
|
-
}) : t.getState().setInitialStateOptions(
|
|
42
|
+
if (i?.formElements && (A.formElements = {
|
|
43
|
+
...i.formElements,
|
|
44
|
+
...u.formElements || {}
|
|
45
|
+
}), i?.validation && (A.validation = {
|
|
46
|
+
...i.validation,
|
|
47
|
+
...u.validation || {}
|
|
48
|
+
}, i.validation.key && !u.validation?.key && (A.validation.key = `${i.validation.key}.${l}`)), Object.keys(A).length > 0) {
|
|
49
|
+
const b = ae(l);
|
|
50
|
+
b ? t.getState().setInitialStateOptions(l, {
|
|
51
|
+
...b,
|
|
52
|
+
...A
|
|
53
|
+
}) : t.getState().setInitialStateOptions(l, A);
|
|
56
54
|
}
|
|
57
|
-
}), Object.keys(g).forEach((
|
|
58
|
-
t.getState().initializeShadowState(
|
|
55
|
+
}), Object.keys(g).forEach((l) => {
|
|
56
|
+
t.getState().initializeShadowState(l, g[l]);
|
|
59
57
|
});
|
|
60
|
-
const
|
|
61
|
-
const [
|
|
62
|
-
|
|
63
|
-
stateKey:
|
|
64
|
-
options:
|
|
65
|
-
initialOptionsPart:
|
|
58
|
+
const p = (l, u) => {
|
|
59
|
+
const [A] = X(u?.componentId ?? te());
|
|
60
|
+
Ee({
|
|
61
|
+
stateKey: l,
|
|
62
|
+
options: u,
|
|
63
|
+
initialOptionsPart: h
|
|
66
64
|
});
|
|
67
|
-
const
|
|
65
|
+
const b = t.getState().getShadowValue(l) || g[l], o = u?.modifyState ? u.modifyState(b) : b;
|
|
68
66
|
return Be(o, {
|
|
69
|
-
stateKey:
|
|
70
|
-
syncUpdate:
|
|
71
|
-
componentId:
|
|
72
|
-
localStorage:
|
|
73
|
-
middleware:
|
|
74
|
-
reactiveType:
|
|
75
|
-
reactiveDeps:
|
|
76
|
-
defaultState:
|
|
77
|
-
dependencies:
|
|
78
|
-
serverState:
|
|
67
|
+
stateKey: l,
|
|
68
|
+
syncUpdate: u?.syncUpdate,
|
|
69
|
+
componentId: A,
|
|
70
|
+
localStorage: u?.localStorage,
|
|
71
|
+
middleware: u?.middleware,
|
|
72
|
+
reactiveType: u?.reactiveType,
|
|
73
|
+
reactiveDeps: u?.reactiveDeps,
|
|
74
|
+
defaultState: u?.defaultState,
|
|
75
|
+
dependencies: u?.dependencies,
|
|
76
|
+
serverState: u?.serverState
|
|
79
77
|
});
|
|
80
78
|
};
|
|
81
|
-
function
|
|
82
|
-
|
|
79
|
+
function M(l, u) {
|
|
80
|
+
Ee({ stateKey: l, options: u, initialOptionsPart: h }), u.localStorage && xe(l, u), ie(l);
|
|
83
81
|
}
|
|
84
|
-
return { useCogsState:
|
|
82
|
+
return { useCogsState: p, setCogsOptions: M };
|
|
85
83
|
}, {
|
|
86
|
-
getInitialOptions:
|
|
84
|
+
getInitialOptions: ae,
|
|
87
85
|
getValidationErrors: Ne,
|
|
88
86
|
setStateLog: We,
|
|
89
|
-
updateInitialStateGlobal:
|
|
90
|
-
addValidationError:
|
|
87
|
+
updateInitialStateGlobal: $e,
|
|
88
|
+
addValidationError: ve,
|
|
91
89
|
removeValidationError: ne
|
|
92
|
-
} = t.getState(), He = (e,
|
|
93
|
-
|
|
90
|
+
} = t.getState(), He = (e, i, f, g, h) => {
|
|
91
|
+
f?.log && console.log(
|
|
94
92
|
"saving to localstorage",
|
|
95
|
-
|
|
96
|
-
|
|
93
|
+
i,
|
|
94
|
+
f.localStorage?.key,
|
|
97
95
|
g
|
|
98
96
|
);
|
|
99
|
-
const
|
|
100
|
-
if (
|
|
101
|
-
const
|
|
102
|
-
let
|
|
97
|
+
const p = ee(f?.localStorage?.key) ? f.localStorage?.key(e) : f?.localStorage?.key;
|
|
98
|
+
if (p && g) {
|
|
99
|
+
const M = `${g}-${i}-${p}`;
|
|
100
|
+
let l;
|
|
103
101
|
try {
|
|
104
|
-
|
|
102
|
+
l = Se(M)?.lastSyncedWithServer;
|
|
105
103
|
} catch {
|
|
106
104
|
}
|
|
107
|
-
const
|
|
105
|
+
const u = t.getState().getShadowMetadata(i, []), A = {
|
|
108
106
|
state: e,
|
|
109
107
|
lastUpdated: Date.now(),
|
|
110
|
-
lastSyncedWithServer:
|
|
111
|
-
stateSource:
|
|
112
|
-
baseServerState:
|
|
113
|
-
},
|
|
108
|
+
lastSyncedWithServer: l,
|
|
109
|
+
stateSource: u?.stateSource,
|
|
110
|
+
baseServerState: u?.baseServerState
|
|
111
|
+
}, b = Oe.serialize(A);
|
|
114
112
|
window.localStorage.setItem(
|
|
115
|
-
|
|
116
|
-
JSON.stringify(
|
|
113
|
+
M,
|
|
114
|
+
JSON.stringify(b.json)
|
|
117
115
|
);
|
|
118
116
|
}
|
|
119
|
-
},
|
|
117
|
+
}, Se = (e) => {
|
|
120
118
|
if (!e) return null;
|
|
121
119
|
try {
|
|
122
|
-
const
|
|
123
|
-
return
|
|
124
|
-
} catch (
|
|
125
|
-
return console.error("Error loading from localStorage:",
|
|
120
|
+
const i = window.localStorage.getItem(e);
|
|
121
|
+
return i ? JSON.parse(i) : null;
|
|
122
|
+
} catch (i) {
|
|
123
|
+
return console.error("Error loading from localStorage:", i), null;
|
|
126
124
|
}
|
|
127
|
-
}, xe = (e,
|
|
128
|
-
const
|
|
129
|
-
if (
|
|
130
|
-
const
|
|
131
|
-
`${g}-${e}-${
|
|
125
|
+
}, xe = (e, i) => {
|
|
126
|
+
const f = t.getState().getShadowValue(e), { sessionId: g } = _e(), h = ee(i?.localStorage?.key) ? i.localStorage.key(f) : i?.localStorage?.key;
|
|
127
|
+
if (h && g) {
|
|
128
|
+
const p = Se(
|
|
129
|
+
`${g}-${e}-${h}`
|
|
132
130
|
);
|
|
133
|
-
if (
|
|
134
|
-
return
|
|
131
|
+
if (p && p.lastUpdated > (p.lastSyncedWithServer || 0))
|
|
132
|
+
return ie(e), !0;
|
|
135
133
|
}
|
|
136
134
|
return !1;
|
|
137
|
-
},
|
|
138
|
-
const
|
|
139
|
-
if (!
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
(g ? Array.isArray(g.reactiveType) ? g.reactiveType : [g.reactiveType || "component"] : null)?.includes("none") ||
|
|
135
|
+
}, ie = (e) => {
|
|
136
|
+
const i = t.getState().getShadowMetadata(e, []);
|
|
137
|
+
if (!i) return;
|
|
138
|
+
const f = /* @__PURE__ */ new Set();
|
|
139
|
+
i?.components?.forEach((g) => {
|
|
140
|
+
(g ? Array.isArray(g.reactiveType) ? g.reactiveType : [g.reactiveType || "component"] : null)?.includes("none") || f.add(() => g.forceUpdate());
|
|
143
141
|
}), queueMicrotask(() => {
|
|
144
|
-
|
|
142
|
+
f.forEach((g) => g());
|
|
145
143
|
});
|
|
146
|
-
},
|
|
147
|
-
const
|
|
148
|
-
if (
|
|
149
|
-
const g = `${e}////${
|
|
150
|
-
if ((
|
|
144
|
+
}, lt = (e, i) => {
|
|
145
|
+
const f = t.getState().getShadowMetadata(e, []);
|
|
146
|
+
if (f) {
|
|
147
|
+
const g = `${e}////${i}`, h = f?.components?.get(g);
|
|
148
|
+
if ((h ? Array.isArray(h.reactiveType) ? h.reactiveType : [h.reactiveType || "component"] : null)?.includes("none"))
|
|
151
149
|
return;
|
|
152
|
-
|
|
150
|
+
h && h.forceUpdate();
|
|
153
151
|
}
|
|
154
152
|
};
|
|
153
|
+
function we(e, i, f, g) {
|
|
154
|
+
const h = t.getState(), p = h.getShadowMetadata(e, i);
|
|
155
|
+
if (h.setShadowMetadata(e, i, {
|
|
156
|
+
...p,
|
|
157
|
+
isDirty: !1,
|
|
158
|
+
stateSource: "server",
|
|
159
|
+
lastServerSync: g || Date.now()
|
|
160
|
+
}), Array.isArray(f)) {
|
|
161
|
+
const M = h.getShadowMetadata(e, i);
|
|
162
|
+
M?.arrayKeys && M.arrayKeys.forEach((l, u) => {
|
|
163
|
+
const A = l.split(".").slice(1), b = f[u];
|
|
164
|
+
b !== void 0 && we(
|
|
165
|
+
e,
|
|
166
|
+
A,
|
|
167
|
+
b,
|
|
168
|
+
g
|
|
169
|
+
);
|
|
170
|
+
});
|
|
171
|
+
} else f && typeof f == "object" && f.constructor === Object && Object.keys(f).forEach((M) => {
|
|
172
|
+
const l = [...i, M], u = f[M];
|
|
173
|
+
we(e, l, u, g);
|
|
174
|
+
});
|
|
175
|
+
}
|
|
155
176
|
function Be(e, {
|
|
156
|
-
stateKey:
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
formElements: v,
|
|
177
|
+
stateKey: i,
|
|
178
|
+
localStorage: f,
|
|
179
|
+
formElements: g,
|
|
160
180
|
reactiveDeps: h,
|
|
161
|
-
reactiveType:
|
|
162
|
-
componentId:
|
|
181
|
+
reactiveType: p,
|
|
182
|
+
componentId: M,
|
|
163
183
|
defaultState: l,
|
|
164
|
-
syncUpdate:
|
|
165
|
-
dependencies:
|
|
166
|
-
serverState:
|
|
184
|
+
syncUpdate: u,
|
|
185
|
+
dependencies: A,
|
|
186
|
+
serverState: b
|
|
167
187
|
} = {}) {
|
|
168
|
-
const [
|
|
169
|
-
let
|
|
170
|
-
const [c] =
|
|
188
|
+
const [o, S] = X({}), { sessionId: T } = _e();
|
|
189
|
+
let W = !i;
|
|
190
|
+
const [c] = X(i ?? te()), x = t.getState().stateLog[c], Y = G(/* @__PURE__ */ new Set()), J = G(M ?? te()), U = G(
|
|
171
191
|
null
|
|
172
192
|
);
|
|
173
|
-
|
|
174
|
-
if (
|
|
175
|
-
const
|
|
176
|
-
t.getState().setSyncInfo(
|
|
177
|
-
timeStamp:
|
|
178
|
-
userId:
|
|
193
|
+
U.current = ae(c) ?? null, Q(() => {
|
|
194
|
+
if (u && u.stateKey === c && u.path?.[0]) {
|
|
195
|
+
const n = `${u.stateKey}:${u.path.join(".")}`;
|
|
196
|
+
t.getState().setSyncInfo(n, {
|
|
197
|
+
timeStamp: u.timeStamp,
|
|
198
|
+
userId: u.userId
|
|
179
199
|
});
|
|
180
200
|
}
|
|
181
|
-
}, [
|
|
182
|
-
const
|
|
183
|
-
(
|
|
184
|
-
const
|
|
185
|
-
if (
|
|
201
|
+
}, [u]);
|
|
202
|
+
const v = ce(
|
|
203
|
+
(n) => {
|
|
204
|
+
const a = n ? { ...ae(c), ...n } : ae(c), d = a?.defaultState || l || e;
|
|
205
|
+
if (a?.serverState?.status === "success" && a?.serverState?.data !== void 0)
|
|
186
206
|
return {
|
|
187
|
-
value:
|
|
207
|
+
value: a.serverState.data,
|
|
188
208
|
source: "server",
|
|
189
|
-
timestamp:
|
|
209
|
+
timestamp: a.serverState.timestamp || Date.now()
|
|
190
210
|
};
|
|
191
|
-
if (
|
|
192
|
-
const
|
|
193
|
-
`${
|
|
211
|
+
if (a?.localStorage?.key && T) {
|
|
212
|
+
const m = ee(a.localStorage.key) ? a.localStorage.key(d) : a.localStorage.key, P = Se(
|
|
213
|
+
`${T}-${c}-${m}`
|
|
194
214
|
);
|
|
195
|
-
if (
|
|
215
|
+
if (P && P.lastUpdated > (a?.serverState?.timestamp || 0))
|
|
196
216
|
return {
|
|
197
|
-
value:
|
|
217
|
+
value: P.state,
|
|
198
218
|
source: "localStorage",
|
|
199
|
-
timestamp:
|
|
219
|
+
timestamp: P.lastUpdated
|
|
200
220
|
};
|
|
201
221
|
}
|
|
202
222
|
return {
|
|
203
|
-
value:
|
|
223
|
+
value: d || e,
|
|
204
224
|
source: "default",
|
|
205
225
|
timestamp: Date.now()
|
|
206
226
|
};
|
|
207
227
|
},
|
|
208
|
-
[c, l, e,
|
|
228
|
+
[c, l, e, T]
|
|
209
229
|
);
|
|
210
|
-
|
|
211
|
-
t.getState().setServerStateUpdate(c,
|
|
212
|
-
}, [
|
|
213
|
-
if (
|
|
214
|
-
const
|
|
215
|
-
if (
|
|
216
|
-
|
|
217
|
-
const
|
|
218
|
-
if (
|
|
219
|
-
const
|
|
220
|
-
|
|
221
|
-
),
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
230
|
+
Q(() => {
|
|
231
|
+
t.getState().setServerStateUpdate(c, b);
|
|
232
|
+
}, [b, c]), Q(() => t.getState().subscribeToPath(c, (r) => {
|
|
233
|
+
if (r?.type === "SERVER_STATE_UPDATE") {
|
|
234
|
+
const a = r.serverState;
|
|
235
|
+
if (a?.status === "success" && a.data !== void 0) {
|
|
236
|
+
he(c, { serverState: a });
|
|
237
|
+
const w = typeof a.merge == "object" ? a.merge : a.merge === !0 ? {} : null, m = t.getState().getShadowValue(c), P = a.data;
|
|
238
|
+
if (w && Array.isArray(m) && Array.isArray(P)) {
|
|
239
|
+
const D = w.key || "id", j = new Set(
|
|
240
|
+
m.map((O) => O[D])
|
|
241
|
+
), F = P.filter((O) => !j.has(O[D]));
|
|
242
|
+
F.length > 0 && F.forEach((O) => {
|
|
243
|
+
t.getState().insertShadowArrayElement(c, [], O);
|
|
244
|
+
const L = t.getState().getShadowMetadata(c, []);
|
|
245
|
+
if (L?.arrayKeys) {
|
|
246
|
+
const N = L.arrayKeys[L.arrayKeys.length - 1];
|
|
247
|
+
if (N) {
|
|
248
|
+
const B = N.split(".").slice(1);
|
|
249
|
+
t.getState().setShadowMetadata(c, B, {
|
|
250
|
+
isDirty: !1,
|
|
251
|
+
stateSource: "server",
|
|
252
|
+
lastServerSync: a.timestamp || Date.now()
|
|
253
|
+
});
|
|
254
|
+
const V = t.getState().getShadowValue(N);
|
|
255
|
+
V && typeof V == "object" && !Array.isArray(V) && Object.keys(V).forEach((E) => {
|
|
256
|
+
const $ = [...B, E];
|
|
257
|
+
t.getState().setShadowMetadata(c, $, {
|
|
258
|
+
isDirty: !1,
|
|
259
|
+
stateSource: "server",
|
|
260
|
+
lastServerSync: a.timestamp || Date.now()
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
});
|
|
228
266
|
} else
|
|
229
|
-
t.getState().initializeShadowState(c,
|
|
230
|
-
|
|
267
|
+
t.getState().initializeShadowState(c, P), we(
|
|
268
|
+
c,
|
|
269
|
+
[],
|
|
270
|
+
P,
|
|
271
|
+
a.timestamp
|
|
272
|
+
);
|
|
273
|
+
const R = t.getState().getShadowMetadata(c, []);
|
|
231
274
|
t.getState().setShadowMetadata(c, [], {
|
|
232
|
-
...
|
|
275
|
+
...R,
|
|
233
276
|
stateSource: "server",
|
|
234
|
-
lastServerSync:
|
|
277
|
+
lastServerSync: a.timestamp || Date.now(),
|
|
235
278
|
isDirty: !1
|
|
236
279
|
});
|
|
237
280
|
}
|
|
238
281
|
}
|
|
239
|
-
}), [c,
|
|
240
|
-
const
|
|
241
|
-
if (
|
|
282
|
+
}), [c, v]), Q(() => {
|
|
283
|
+
const n = t.getState().getShadowMetadata(c, []);
|
|
284
|
+
if (n && n.stateSource)
|
|
242
285
|
return;
|
|
243
|
-
const
|
|
244
|
-
if (
|
|
245
|
-
const
|
|
246
|
-
|
|
247
|
-
defaultState:
|
|
286
|
+
const r = ae(c);
|
|
287
|
+
if (r?.defaultState !== void 0 || l !== void 0) {
|
|
288
|
+
const a = r?.defaultState || l;
|
|
289
|
+
r?.defaultState || he(c, {
|
|
290
|
+
defaultState: a
|
|
248
291
|
});
|
|
249
|
-
const { value:
|
|
250
|
-
t.getState().initializeShadowState(c,
|
|
251
|
-
stateSource:
|
|
252
|
-
lastServerSync:
|
|
292
|
+
const { value: d, source: w, timestamp: m } = v();
|
|
293
|
+
t.getState().initializeShadowState(c, d), t.getState().setShadowMetadata(c, [], {
|
|
294
|
+
stateSource: w,
|
|
295
|
+
lastServerSync: w === "server" ? m : void 0,
|
|
253
296
|
isDirty: !1,
|
|
254
|
-
baseServerState:
|
|
255
|
-
}),
|
|
297
|
+
baseServerState: w === "server" ? d : void 0
|
|
298
|
+
}), ie(c);
|
|
256
299
|
}
|
|
257
|
-
}, [c, ...
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
formElements: v,
|
|
300
|
+
}, [c, ...A || []]), de(() => {
|
|
301
|
+
W && he(c, {
|
|
302
|
+
formElements: g,
|
|
261
303
|
defaultState: l,
|
|
262
|
-
localStorage:
|
|
263
|
-
middleware:
|
|
304
|
+
localStorage: f,
|
|
305
|
+
middleware: U.current?.middleware
|
|
264
306
|
});
|
|
265
|
-
const
|
|
266
|
-
return
|
|
267
|
-
forceUpdate: () =>
|
|
268
|
-
reactiveType:
|
|
307
|
+
const n = `${c}////${J.current}`, r = t.getState().getShadowMetadata(c, []), a = r?.components || /* @__PURE__ */ new Map();
|
|
308
|
+
return a.set(n, {
|
|
309
|
+
forceUpdate: () => S({}),
|
|
310
|
+
reactiveType: p ?? ["component", "deps"],
|
|
269
311
|
paths: /* @__PURE__ */ new Set(),
|
|
270
312
|
depsFunction: h || void 0,
|
|
271
313
|
deps: h ? h(t.getState().getShadowValue(c)) : [],
|
|
272
314
|
prevDeps: h ? h(t.getState().getShadowValue(c)) : []
|
|
273
315
|
}), t.getState().setShadowMetadata(c, [], {
|
|
274
|
-
...
|
|
275
|
-
components:
|
|
276
|
-
}),
|
|
277
|
-
const
|
|
278
|
-
|
|
279
|
-
const
|
|
280
|
-
|
|
281
|
-
}),
|
|
316
|
+
...r,
|
|
317
|
+
components: a
|
|
318
|
+
}), S({}), () => {
|
|
319
|
+
const d = t.getState().getShadowMetadata(c, []), w = d?.components?.get(n);
|
|
320
|
+
w?.paths && w.paths.forEach((m) => {
|
|
321
|
+
const R = m.split(".").slice(1), D = t.getState().getShadowMetadata(c, R);
|
|
322
|
+
D?.pathComponents && D.pathComponents.size === 0 && (delete D.pathComponents, t.getState().setShadowMetadata(c, R, D));
|
|
323
|
+
}), d?.components && t.getState().setShadowMetadata(c, [], d);
|
|
282
324
|
};
|
|
283
325
|
}, []);
|
|
284
|
-
const
|
|
285
|
-
const
|
|
286
|
-
if (Array.isArray(
|
|
287
|
-
const
|
|
288
|
-
|
|
326
|
+
const K = G(null), oe = (n, r, a, d) => {
|
|
327
|
+
const w = [c, ...r].join(".");
|
|
328
|
+
if (Array.isArray(r)) {
|
|
329
|
+
const V = `${c}-${r.join(".")}`;
|
|
330
|
+
Y.current.add(V);
|
|
289
331
|
}
|
|
290
|
-
const
|
|
332
|
+
const m = t.getState(), P = m.getShadowMetadata(c, r), R = m.getShadowValue(w), D = a.updateType === "insert" && ee(n) ? n({ state: R, uuid: te() }) : ee(n) ? n(R) : n, F = {
|
|
291
333
|
timeStamp: Date.now(),
|
|
292
334
|
stateKey: c,
|
|
293
|
-
path:
|
|
294
|
-
updateType:
|
|
335
|
+
path: r,
|
|
336
|
+
updateType: a.updateType,
|
|
295
337
|
status: "new",
|
|
296
|
-
oldValue:
|
|
297
|
-
newValue:
|
|
338
|
+
oldValue: R,
|
|
339
|
+
newValue: D
|
|
298
340
|
};
|
|
299
|
-
switch (
|
|
341
|
+
switch (a.updateType) {
|
|
300
342
|
case "insert": {
|
|
301
|
-
|
|
343
|
+
m.insertShadowArrayElement(c, r, F.newValue), m.markAsDirty(c, r, { bubble: !0 });
|
|
344
|
+
const V = m.getShadowMetadata(c, r);
|
|
345
|
+
if (V?.arrayKeys) {
|
|
346
|
+
const E = V.arrayKeys[V.arrayKeys.length - 1];
|
|
347
|
+
if (E) {
|
|
348
|
+
const $ = E.split(".").slice(1);
|
|
349
|
+
m.markAsDirty(c, $, { bubble: !1 });
|
|
350
|
+
}
|
|
351
|
+
}
|
|
302
352
|
break;
|
|
303
353
|
}
|
|
304
354
|
case "cut": {
|
|
305
|
-
const
|
|
306
|
-
|
|
355
|
+
const V = r.slice(0, -1);
|
|
356
|
+
m.removeShadowArrayElement(c, r), m.markAsDirty(c, V, { bubble: !0 });
|
|
307
357
|
break;
|
|
308
358
|
}
|
|
309
359
|
case "update": {
|
|
310
|
-
|
|
360
|
+
m.updateShadowAtPath(c, r, F.newValue), m.markAsDirty(c, r, { bubble: !0 });
|
|
311
361
|
break;
|
|
312
362
|
}
|
|
313
363
|
}
|
|
314
|
-
if (
|
|
315
|
-
const
|
|
316
|
-
|
|
317
|
-
const y = document.querySelector(`[data-parent-id="${
|
|
364
|
+
if (console.log("sdadasdasd", K.current, F), K.current && K.current.connected && K.current.updateState({ operation: F }), P?.signals && P.signals.length > 0) {
|
|
365
|
+
const V = a.updateType === "cut" ? null : D;
|
|
366
|
+
P.signals.forEach(({ parentId: E, position: $, effect: I }) => {
|
|
367
|
+
const y = document.querySelector(`[data-parent-id="${E}"]`);
|
|
318
368
|
if (y) {
|
|
319
|
-
const
|
|
320
|
-
if (
|
|
321
|
-
let C =
|
|
322
|
-
if (
|
|
369
|
+
const k = Array.from(y.childNodes);
|
|
370
|
+
if (k[$]) {
|
|
371
|
+
let C = V;
|
|
372
|
+
if (I && V !== null)
|
|
323
373
|
try {
|
|
324
374
|
C = new Function(
|
|
325
375
|
"state",
|
|
326
|
-
`return (${
|
|
327
|
-
)(
|
|
328
|
-
} catch (
|
|
329
|
-
console.error("Error evaluating effect function:",
|
|
376
|
+
`return (${I})(state)`
|
|
377
|
+
)(V);
|
|
378
|
+
} catch (_) {
|
|
379
|
+
console.error("Error evaluating effect function:", _);
|
|
330
380
|
}
|
|
331
|
-
C != null && typeof C == "object" && (C = JSON.stringify(C)),
|
|
381
|
+
C != null && typeof C == "object" && (C = JSON.stringify(C)), k[$].textContent = String(C ?? "");
|
|
332
382
|
}
|
|
333
383
|
}
|
|
334
384
|
});
|
|
335
385
|
}
|
|
336
|
-
if (
|
|
337
|
-
const
|
|
338
|
-
[c, ...
|
|
386
|
+
if (a.updateType === "insert" && P?.mapWrappers && P.mapWrappers.length > 0) {
|
|
387
|
+
const V = m.getShadowMetadata(c, r)?.arrayKeys || [], E = V[V.length - 1], $ = m.getShadowValue(E), I = m.getShadowValue(
|
|
388
|
+
[c, ...r].join(".")
|
|
339
389
|
);
|
|
340
|
-
if (!
|
|
341
|
-
|
|
342
|
-
let
|
|
390
|
+
if (!E || $ === void 0) return;
|
|
391
|
+
P.mapWrappers.forEach((y) => {
|
|
392
|
+
let k = !0, C = -1;
|
|
343
393
|
if (y.meta?.transforms && y.meta.transforms.length > 0) {
|
|
344
|
-
for (const
|
|
345
|
-
if (
|
|
346
|
-
|
|
394
|
+
for (const _ of y.meta.transforms)
|
|
395
|
+
if (_.type === "filter" && !_.fn($, -1)) {
|
|
396
|
+
k = !1;
|
|
347
397
|
break;
|
|
348
398
|
}
|
|
349
|
-
if (
|
|
350
|
-
const
|
|
399
|
+
if (k) {
|
|
400
|
+
const _ = Ie(
|
|
351
401
|
c,
|
|
352
|
-
|
|
402
|
+
r,
|
|
353
403
|
y.meta.transforms
|
|
354
|
-
),
|
|
355
|
-
(
|
|
404
|
+
), q = y.meta.transforms.find(
|
|
405
|
+
(H) => H.type === "sort"
|
|
356
406
|
);
|
|
357
|
-
if (
|
|
358
|
-
const
|
|
407
|
+
if (q) {
|
|
408
|
+
const H = _.map((z) => ({
|
|
359
409
|
key: z,
|
|
360
|
-
value:
|
|
410
|
+
value: m.getShadowValue(z)
|
|
361
411
|
}));
|
|
362
|
-
|
|
363
|
-
(z) => z.key ===
|
|
412
|
+
H.push({ key: E, value: $ }), H.sort((z, Z) => q.fn(z.value, Z.value)), C = H.findIndex(
|
|
413
|
+
(z) => z.key === E
|
|
364
414
|
);
|
|
365
415
|
} else
|
|
366
|
-
C =
|
|
416
|
+
C = _.length;
|
|
367
417
|
}
|
|
368
418
|
} else
|
|
369
|
-
|
|
370
|
-
if (
|
|
371
|
-
const
|
|
372
|
-
|
|
373
|
-
const
|
|
374
|
-
C >= 0 && C <
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
) : y.containerRef.appendChild(
|
|
378
|
-
const
|
|
419
|
+
k = !0, C = V.length - 1;
|
|
420
|
+
if (k && y.containerRef && y.containerRef.isConnected) {
|
|
421
|
+
const _ = document.createElement("div");
|
|
422
|
+
_.setAttribute("data-item-path", E);
|
|
423
|
+
const q = Array.from(y.containerRef.children);
|
|
424
|
+
C >= 0 && C < q.length ? y.containerRef.insertBefore(
|
|
425
|
+
_,
|
|
426
|
+
q[C]
|
|
427
|
+
) : y.containerRef.appendChild(_);
|
|
428
|
+
const H = Ce(_), z = te(), Z = E.split(".").slice(1), ue = y.rebuildStateShape({
|
|
379
429
|
path: y.path,
|
|
380
|
-
currentState:
|
|
430
|
+
currentState: I,
|
|
381
431
|
componentId: y.componentId,
|
|
382
432
|
meta: y.meta
|
|
383
433
|
});
|
|
384
|
-
|
|
385
|
-
le(
|
|
434
|
+
H.render(
|
|
435
|
+
le(Me, {
|
|
386
436
|
stateKey: c,
|
|
387
437
|
itemComponentId: z,
|
|
388
|
-
itemPath:
|
|
438
|
+
itemPath: Z,
|
|
389
439
|
localIndex: C,
|
|
390
|
-
arraySetter:
|
|
440
|
+
arraySetter: ue,
|
|
391
441
|
rebuildStateShape: y.rebuildStateShape,
|
|
392
442
|
renderFn: y.mapFn
|
|
393
443
|
})
|
|
@@ -395,451 +445,453 @@ function Be(e, {
|
|
|
395
445
|
}
|
|
396
446
|
});
|
|
397
447
|
}
|
|
398
|
-
if (
|
|
399
|
-
const
|
|
400
|
-
|
|
401
|
-
if (
|
|
402
|
-
const
|
|
403
|
-
`[data-item-path="${
|
|
448
|
+
if (a.updateType === "cut") {
|
|
449
|
+
const V = r.slice(0, -1), E = m.getShadowMetadata(c, V);
|
|
450
|
+
E?.mapWrappers && E.mapWrappers.length > 0 && E.mapWrappers.forEach(($) => {
|
|
451
|
+
if ($.containerRef && $.containerRef.isConnected) {
|
|
452
|
+
const I = $.containerRef.querySelector(
|
|
453
|
+
`[data-item-path="${w}"]`
|
|
404
454
|
);
|
|
405
|
-
|
|
455
|
+
I && I.remove();
|
|
406
456
|
}
|
|
407
457
|
});
|
|
408
458
|
}
|
|
409
|
-
|
|
410
|
-
(
|
|
459
|
+
a.updateType === "update" && (d || U.current?.validation?.key) && r && ne(
|
|
460
|
+
(d || U.current?.validation?.key) + "." + r.join(".")
|
|
411
461
|
);
|
|
412
|
-
const
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
),
|
|
416
|
-
|
|
417
|
-
).filter((
|
|
418
|
-
let
|
|
419
|
-
const
|
|
420
|
-
if (
|
|
421
|
-
let y =
|
|
422
|
-
ne(
|
|
462
|
+
const O = r.slice(0, r.length - 1);
|
|
463
|
+
a.updateType === "cut" && U.current?.validation?.key && ne(
|
|
464
|
+
U.current?.validation?.key + "." + O.join(".")
|
|
465
|
+
), a.updateType === "insert" && U.current?.validation?.key && Ne(
|
|
466
|
+
U.current?.validation?.key + "." + O.join(".")
|
|
467
|
+
).filter((E) => {
|
|
468
|
+
let $ = E?.split(".").length;
|
|
469
|
+
const I = "";
|
|
470
|
+
if (E == O.join(".") && $ == O.length - 1) {
|
|
471
|
+
let y = E + "." + O;
|
|
472
|
+
ne(E), ve(y, I);
|
|
423
473
|
}
|
|
424
474
|
});
|
|
425
|
-
const
|
|
426
|
-
if (!
|
|
427
|
-
return
|
|
428
|
-
if (
|
|
429
|
-
|
|
430
|
-
if (
|
|
475
|
+
const L = m.getShadowValue(c), N = m.getShadowMetadata(c, []), B = /* @__PURE__ */ new Set();
|
|
476
|
+
if (!N?.components)
|
|
477
|
+
return L;
|
|
478
|
+
if (a.updateType === "update")
|
|
479
|
+
P?.pathComponents && P.pathComponents.forEach((V) => {
|
|
480
|
+
if (B.has(V))
|
|
431
481
|
return;
|
|
432
|
-
const
|
|
433
|
-
|
|
434
|
-
}),
|
|
435
|
-
const
|
|
436
|
-
y?.pathComponents && y.pathComponents.forEach((
|
|
437
|
-
if (
|
|
482
|
+
const E = N.components?.get(V);
|
|
483
|
+
E && ((Array.isArray(E.reactiveType) ? E.reactiveType : [E.reactiveType || "component"]).includes("none") || (E.forceUpdate(), B.add(V)));
|
|
484
|
+
}), D && typeof D == "object" && !Te(D) && R && typeof R == "object" && !Te(R) && Pe(D, R).forEach((E) => {
|
|
485
|
+
const $ = E.split("."), I = [...r, ...$], y = m.getShadowMetadata(c, I);
|
|
486
|
+
y?.pathComponents && y.pathComponents.forEach((k) => {
|
|
487
|
+
if (B.has(k))
|
|
438
488
|
return;
|
|
439
|
-
const C =
|
|
440
|
-
C && ((Array.isArray(C.reactiveType) ? C.reactiveType : [C.reactiveType || "component"]).includes("none") || (C.forceUpdate(),
|
|
489
|
+
const C = N.components?.get(k);
|
|
490
|
+
C && ((Array.isArray(C.reactiveType) ? C.reactiveType : [C.reactiveType || "component"]).includes("none") || (C.forceUpdate(), B.add(k)));
|
|
441
491
|
});
|
|
442
492
|
});
|
|
443
|
-
else if (
|
|
444
|
-
const
|
|
445
|
-
if (
|
|
446
|
-
const
|
|
447
|
-
|
|
448
|
-
const
|
|
493
|
+
else if (a.updateType === "insert" || a.updateType === "cut") {
|
|
494
|
+
const V = a.updateType === "insert" ? r : r.slice(0, -1), E = m.getShadowMetadata(c, V);
|
|
495
|
+
if (E?.signals && E.signals.length > 0) {
|
|
496
|
+
const $ = [c, ...V].join("."), I = m.getShadowValue($);
|
|
497
|
+
E.signals.forEach(({ parentId: y, position: k, effect: C }) => {
|
|
498
|
+
const _ = document.querySelector(
|
|
449
499
|
`[data-parent-id="${y}"]`
|
|
450
500
|
);
|
|
451
|
-
if (
|
|
452
|
-
const
|
|
453
|
-
if (
|
|
454
|
-
let
|
|
501
|
+
if (_) {
|
|
502
|
+
const q = Array.from(_.childNodes);
|
|
503
|
+
if (q[k]) {
|
|
504
|
+
let H = I;
|
|
455
505
|
if (C)
|
|
456
506
|
try {
|
|
457
|
-
|
|
507
|
+
H = new Function(
|
|
458
508
|
"state",
|
|
459
509
|
`return (${C})(state)`
|
|
460
|
-
)(
|
|
510
|
+
)(I);
|
|
461
511
|
} catch (z) {
|
|
462
|
-
console.error("Error evaluating effect function:", z),
|
|
512
|
+
console.error("Error evaluating effect function:", z), H = I;
|
|
463
513
|
}
|
|
464
|
-
|
|
514
|
+
H != null && typeof H == "object" && (H = JSON.stringify(H)), q[k].textContent = String(H ?? "");
|
|
465
515
|
}
|
|
466
516
|
}
|
|
467
517
|
});
|
|
468
518
|
}
|
|
469
|
-
|
|
470
|
-
if (!
|
|
471
|
-
const
|
|
472
|
-
|
|
519
|
+
E?.pathComponents && E.pathComponents.forEach(($) => {
|
|
520
|
+
if (!B.has($)) {
|
|
521
|
+
const I = N.components?.get($);
|
|
522
|
+
I && (I.forceUpdate(), B.add($));
|
|
473
523
|
}
|
|
474
524
|
});
|
|
475
525
|
}
|
|
476
|
-
return
|
|
477
|
-
if (
|
|
526
|
+
return N.components.forEach((V, E) => {
|
|
527
|
+
if (B.has(E))
|
|
478
528
|
return;
|
|
479
|
-
const
|
|
480
|
-
if (
|
|
481
|
-
|
|
529
|
+
const $ = Array.isArray(V.reactiveType) ? V.reactiveType : [V.reactiveType || "component"];
|
|
530
|
+
if ($.includes("all")) {
|
|
531
|
+
V.forceUpdate(), B.add(E);
|
|
482
532
|
return;
|
|
483
533
|
}
|
|
484
|
-
if (
|
|
485
|
-
const
|
|
486
|
-
let
|
|
487
|
-
y === !0 ?
|
|
534
|
+
if ($.includes("deps") && V.depsFunction) {
|
|
535
|
+
const I = m.getShadowValue(c), y = V.depsFunction(I);
|
|
536
|
+
let k = !1;
|
|
537
|
+
y === !0 ? k = !0 : Array.isArray(y) && (se(V.prevDeps, y) || (V.prevDeps = y, k = !0)), k && (V.forceUpdate(), B.add(E));
|
|
488
538
|
}
|
|
489
|
-
}),
|
|
490
|
-
const
|
|
491
|
-
return
|
|
492
|
-
const y = `${
|
|
493
|
-
|
|
494
|
-
}), Array.from(
|
|
539
|
+
}), B.clear(), We(c, (V) => {
|
|
540
|
+
const E = [...V ?? [], F], $ = /* @__PURE__ */ new Map();
|
|
541
|
+
return E.forEach((I) => {
|
|
542
|
+
const y = `${I.stateKey}:${JSON.stringify(I.path)}`, k = $.get(y);
|
|
543
|
+
k ? (k.timeStamp = Math.max(k.timeStamp, I.timeStamp), k.newValue = I.newValue, k.oldValue = k.oldValue ?? I.oldValue, k.updateType = I.updateType) : $.set(y, { ...I });
|
|
544
|
+
}), Array.from($.values());
|
|
495
545
|
}), He(
|
|
496
|
-
|
|
546
|
+
D,
|
|
497
547
|
c,
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
),
|
|
501
|
-
updateLog:
|
|
502
|
-
update:
|
|
503
|
-
}),
|
|
548
|
+
U.current,
|
|
549
|
+
T
|
|
550
|
+
), U.current?.middleware && U.current.middleware({
|
|
551
|
+
updateLog: x,
|
|
552
|
+
update: F
|
|
553
|
+
}), L;
|
|
504
554
|
};
|
|
505
|
-
|
|
555
|
+
t.getState().initialStateGlobal[c] || $e(c, e);
|
|
556
|
+
const fe = ge(() => De(
|
|
506
557
|
c,
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
), [c,
|
|
558
|
+
oe,
|
|
559
|
+
J.current,
|
|
560
|
+
T
|
|
561
|
+
), [c, T]), s = U.current?.cogsSync;
|
|
562
|
+
return s && (K.current = s(fe)), fe;
|
|
511
563
|
}
|
|
512
564
|
function qe(e) {
|
|
513
565
|
return !e || e.length === 0 ? "" : e.map(
|
|
514
|
-
(
|
|
566
|
+
(i) => (
|
|
515
567
|
// Safely stringify dependencies. An empty array becomes '[]'.
|
|
516
|
-
`${
|
|
568
|
+
`${i.type}${JSON.stringify(i.dependencies || [])}`
|
|
517
569
|
)
|
|
518
570
|
).join("");
|
|
519
571
|
}
|
|
520
|
-
const
|
|
521
|
-
let g = t.getState().getShadowMetadata(e,
|
|
522
|
-
if (!
|
|
572
|
+
const Ie = (e, i, f) => {
|
|
573
|
+
let g = t.getState().getShadowMetadata(e, i)?.arrayKeys || [];
|
|
574
|
+
if (!f || f.length === 0)
|
|
523
575
|
return g;
|
|
524
|
-
let
|
|
525
|
-
key:
|
|
526
|
-
value: t.getState().getShadowValue(
|
|
576
|
+
let h = g.map((p) => ({
|
|
577
|
+
key: p,
|
|
578
|
+
value: t.getState().getShadowValue(p)
|
|
527
579
|
}));
|
|
528
|
-
for (const
|
|
529
|
-
|
|
530
|
-
({ value:
|
|
531
|
-
) :
|
|
532
|
-
return
|
|
533
|
-
},
|
|
534
|
-
const g = `${e}////${
|
|
535
|
-
if (!
|
|
580
|
+
for (const p of f)
|
|
581
|
+
p.type === "filter" ? h = h.filter(
|
|
582
|
+
({ value: M }, l) => p.fn(M, l)
|
|
583
|
+
) : p.type === "sort" && h.sort((M, l) => p.fn(M.value, l.value));
|
|
584
|
+
return h.map(({ key: p }) => p);
|
|
585
|
+
}, Ve = (e, i, f) => {
|
|
586
|
+
const g = `${e}////${i}`, p = t.getState().getShadowMetadata(e, [])?.components?.get(g);
|
|
587
|
+
if (!p || p.reactiveType == "none" || !(Array.isArray(p.reactiveType) ? p.reactiveType : [p.reactiveType]).includes("component"))
|
|
536
588
|
return;
|
|
537
|
-
const
|
|
538
|
-
|
|
539
|
-
const
|
|
540
|
-
|
|
541
|
-
...
|
|
542
|
-
pathComponents:
|
|
589
|
+
const M = [e, ...f].join(".");
|
|
590
|
+
p.paths.add(M);
|
|
591
|
+
const l = t.getState().getShadowMetadata(e, f) || {}, u = l.pathComponents || /* @__PURE__ */ new Set();
|
|
592
|
+
u.add(g), t.getState().setShadowMetadata(e, f, {
|
|
593
|
+
...l,
|
|
594
|
+
pathComponents: u
|
|
543
595
|
});
|
|
544
|
-
},
|
|
545
|
-
const g = t.getState(),
|
|
546
|
-
|
|
547
|
-
(Array.isArray(
|
|
548
|
-
}), g.getShadowMetadata(e, [...
|
|
549
|
-
|
|
596
|
+
}, ye = (e, i, f) => {
|
|
597
|
+
const g = t.getState(), h = g.getShadowMetadata(e, []), p = /* @__PURE__ */ new Set();
|
|
598
|
+
h?.components && h.components.forEach((l, u) => {
|
|
599
|
+
(Array.isArray(l.reactiveType) ? l.reactiveType : [l.reactiveType || "component"]).includes("all") && (l.forceUpdate(), p.add(u));
|
|
600
|
+
}), g.getShadowMetadata(e, [...i, "getSelected"])?.pathComponents?.forEach((l) => {
|
|
601
|
+
h?.components?.get(l)?.forceUpdate();
|
|
550
602
|
});
|
|
551
|
-
const
|
|
552
|
-
for (let
|
|
553
|
-
const
|
|
603
|
+
const M = g.getShadowMetadata(e, i);
|
|
604
|
+
for (let l of M?.arrayKeys || []) {
|
|
605
|
+
const u = l + ".selected", A = g.getShadowMetadata(
|
|
554
606
|
e,
|
|
555
|
-
|
|
607
|
+
u.split(".").slice(1)
|
|
556
608
|
);
|
|
557
|
-
|
|
558
|
-
|
|
609
|
+
l == f && A?.pathComponents?.forEach((b) => {
|
|
610
|
+
h?.components?.get(b)?.forceUpdate();
|
|
559
611
|
});
|
|
560
612
|
}
|
|
561
613
|
};
|
|
562
|
-
function
|
|
563
|
-
const
|
|
564
|
-
let
|
|
565
|
-
const
|
|
566
|
-
const o =
|
|
567
|
-
for (const [S] of
|
|
568
|
-
(S === o || S.startsWith(o + ".")) &&
|
|
569
|
-
|
|
614
|
+
function De(e, i, f, g) {
|
|
615
|
+
const h = /* @__PURE__ */ new Map();
|
|
616
|
+
let p = 0;
|
|
617
|
+
const M = (b) => {
|
|
618
|
+
const o = b.join(".");
|
|
619
|
+
for (const [S] of h)
|
|
620
|
+
(S === o || S.startsWith(o + ".")) && h.delete(S);
|
|
621
|
+
p++;
|
|
570
622
|
};
|
|
571
|
-
function
|
|
572
|
-
currentState:
|
|
623
|
+
function l({
|
|
624
|
+
currentState: b,
|
|
573
625
|
path: o = [],
|
|
574
626
|
meta: S,
|
|
575
|
-
componentId:
|
|
627
|
+
componentId: T
|
|
576
628
|
}) {
|
|
577
|
-
const
|
|
578
|
-
|
|
579
|
-
const
|
|
629
|
+
const W = o.map(String).join("."), c = [e, ...o].join(".");
|
|
630
|
+
b = t.getState().getShadowValue(c, S?.validIds);
|
|
631
|
+
const x = function() {
|
|
580
632
|
return t().getShadowValue(e, o);
|
|
581
|
-
},
|
|
582
|
-
apply(
|
|
633
|
+
}, Y = {
|
|
634
|
+
apply(U, v, K) {
|
|
583
635
|
},
|
|
584
|
-
get(
|
|
585
|
-
if (
|
|
586
|
-
return
|
|
587
|
-
if (Object.getOwnPropertyNames(
|
|
588
|
-
return
|
|
589
|
-
if (
|
|
636
|
+
get(U, v) {
|
|
637
|
+
if (v === "_rebuildStateShape")
|
|
638
|
+
return l;
|
|
639
|
+
if (Object.getOwnPropertyNames(u).includes(v) && o.length === 0)
|
|
640
|
+
return u[v];
|
|
641
|
+
if (v === "getDifferences")
|
|
590
642
|
return () => {
|
|
591
|
-
const
|
|
643
|
+
const s = t.getState().getShadowMetadata(e, []), n = t.getState().getShadowValue(e);
|
|
592
644
|
let r;
|
|
593
|
-
return
|
|
645
|
+
return s?.stateSource === "server" && s.baseServerState ? r = s.baseServerState : r = t.getState().initialStateGlobal[e], Pe(n, r);
|
|
594
646
|
};
|
|
595
|
-
if (
|
|
647
|
+
if (v === "sync" && o.length === 0)
|
|
596
648
|
return async function() {
|
|
597
|
-
const
|
|
649
|
+
const s = t.getState().getInitialOptions(e), n = s?.sync;
|
|
598
650
|
if (!n)
|
|
599
651
|
return console.error(`No mutation defined for state key "${e}"`), { success: !1, error: "No mutation defined" };
|
|
600
|
-
const r = t.getState().getShadowValue(e, []),
|
|
652
|
+
const r = t.getState().getShadowValue(e, []), a = s?.validation?.key;
|
|
601
653
|
try {
|
|
602
|
-
const
|
|
603
|
-
if (
|
|
604
|
-
const
|
|
605
|
-
t.getState().addValidationError(
|
|
606
|
-
}),
|
|
607
|
-
const
|
|
654
|
+
const d = await n.action(r);
|
|
655
|
+
if (d && !d.success && d.errors && a && (t.getState().removeValidationError(a), d.errors.forEach((w) => {
|
|
656
|
+
const m = [a, ...w.path].join(".");
|
|
657
|
+
t.getState().addValidationError(m, w.message);
|
|
658
|
+
}), ie(e)), d?.success) {
|
|
659
|
+
const w = t.getState().getShadowMetadata(e, []);
|
|
608
660
|
t.getState().setShadowMetadata(e, [], {
|
|
609
|
-
...
|
|
661
|
+
...w,
|
|
610
662
|
isDirty: !1,
|
|
611
663
|
lastServerSync: Date.now(),
|
|
612
664
|
stateSource: "server",
|
|
613
665
|
baseServerState: r
|
|
614
666
|
// Update base server state
|
|
615
|
-
}), n.onSuccess && n.onSuccess(
|
|
616
|
-
} else !
|
|
617
|
-
return
|
|
618
|
-
} catch (
|
|
619
|
-
return n.onError && n.onError(
|
|
667
|
+
}), n.onSuccess && n.onSuccess(d.data);
|
|
668
|
+
} else !d?.success && n.onError && n.onError(d.error);
|
|
669
|
+
return d;
|
|
670
|
+
} catch (d) {
|
|
671
|
+
return n.onError && n.onError(d), { success: !1, error: d };
|
|
620
672
|
}
|
|
621
673
|
};
|
|
622
|
-
if (
|
|
623
|
-
const
|
|
624
|
-
const n = t.getState().getShadowMetadata(e,
|
|
625
|
-
return n?.
|
|
674
|
+
if (v === "_status" || v === "getStatus") {
|
|
675
|
+
const s = () => {
|
|
676
|
+
const n = t.getState().getShadowMetadata(e, o), r = t.getState().getShadowValue(c);
|
|
677
|
+
return n?.isDirty === !0 ? "dirty" : n?.isDirty === !1 || n?.stateSource === "server" ? "synced" : n?.stateSource === "localStorage" ? "restored" : n?.stateSource === "default" ? "fresh" : t.getState().getShadowMetadata(e, [])?.stateSource === "server" && !n?.isDirty ? "synced" : r !== void 0 && !n ? "fresh" : "unknown";
|
|
626
678
|
};
|
|
627
|
-
return
|
|
679
|
+
return v === "_status" ? s() : s;
|
|
628
680
|
}
|
|
629
|
-
if (
|
|
681
|
+
if (v === "removeStorage")
|
|
630
682
|
return () => {
|
|
631
|
-
const
|
|
632
|
-
|
|
683
|
+
const s = t.getState().initialStateGlobal[e], n = ae(e), r = ee(n?.localStorage?.key) ? n.localStorage.key(s) : n?.localStorage?.key, a = `${g}-${e}-${r}`;
|
|
684
|
+
a && localStorage.removeItem(a);
|
|
633
685
|
};
|
|
634
|
-
if (
|
|
686
|
+
if (v === "showValidationErrors")
|
|
635
687
|
return () => {
|
|
636
|
-
const
|
|
637
|
-
if (!
|
|
638
|
-
return t.getState().getValidationErrors(
|
|
688
|
+
const s = t.getState().getInitialOptions(e)?.validation;
|
|
689
|
+
if (!s?.key) throw new Error("Validation key not found");
|
|
690
|
+
return t.getState().getValidationErrors(s.key + "." + o.join("."));
|
|
639
691
|
};
|
|
640
|
-
if (Array.isArray(
|
|
641
|
-
if (
|
|
692
|
+
if (Array.isArray(b)) {
|
|
693
|
+
if (v === "getSelected")
|
|
642
694
|
return () => {
|
|
643
|
-
const
|
|
644
|
-
|
|
695
|
+
const s = e + "." + o.join(".");
|
|
696
|
+
Ve(e, T, [
|
|
645
697
|
...o,
|
|
646
698
|
"getSelected"
|
|
647
699
|
]);
|
|
648
700
|
const n = t.getState().selectedIndicesMap;
|
|
649
|
-
if (!n || !n.has(
|
|
701
|
+
if (!n || !n.has(s))
|
|
650
702
|
return;
|
|
651
|
-
const r = n.get(
|
|
703
|
+
const r = n.get(s);
|
|
652
704
|
if (S?.validIds && !S.validIds.includes(r))
|
|
653
705
|
return;
|
|
654
|
-
const
|
|
655
|
-
if (
|
|
656
|
-
return
|
|
657
|
-
currentState:
|
|
706
|
+
const a = t.getState().getShadowValue(r);
|
|
707
|
+
if (a)
|
|
708
|
+
return l({
|
|
709
|
+
currentState: a,
|
|
658
710
|
path: r.split(".").slice(1),
|
|
659
|
-
componentId:
|
|
711
|
+
componentId: T
|
|
660
712
|
});
|
|
661
713
|
};
|
|
662
|
-
if (
|
|
714
|
+
if (v === "getSelectedIndex")
|
|
663
715
|
return () => t.getState().getSelectedIndex(
|
|
664
716
|
e + "." + o.join("."),
|
|
665
717
|
S?.validIds
|
|
666
718
|
);
|
|
667
|
-
if (
|
|
668
|
-
return
|
|
719
|
+
if (v === "clearSelected")
|
|
720
|
+
return ye(e, o), () => {
|
|
669
721
|
t.getState().clearSelectedIndex({
|
|
670
722
|
arrayKey: e + "." + o.join(".")
|
|
671
723
|
});
|
|
672
724
|
};
|
|
673
|
-
if (
|
|
674
|
-
return (
|
|
725
|
+
if (v === "useVirtualView")
|
|
726
|
+
return (s) => {
|
|
675
727
|
const {
|
|
676
728
|
itemHeight: n = 50,
|
|
677
729
|
overscan: r = 6,
|
|
678
|
-
stickToBottom:
|
|
679
|
-
scrollStickTolerance:
|
|
680
|
-
} =
|
|
730
|
+
stickToBottom: a = !1,
|
|
731
|
+
scrollStickTolerance: d = 75
|
|
732
|
+
} = s, w = G(null), [m, P] = X({
|
|
681
733
|
startIndex: 0,
|
|
682
734
|
endIndex: 10
|
|
683
|
-
}), [
|
|
735
|
+
}), [R, D] = X({}), j = G(!0), F = G({
|
|
684
736
|
isUserScrolling: !1,
|
|
685
737
|
lastScrollTop: 0,
|
|
686
738
|
scrollUpCount: 0,
|
|
687
739
|
isNearBottom: !0
|
|
688
|
-
}),
|
|
740
|
+
}), O = G(
|
|
689
741
|
/* @__PURE__ */ new Map()
|
|
690
742
|
);
|
|
691
|
-
|
|
692
|
-
if (!
|
|
743
|
+
de(() => {
|
|
744
|
+
if (!a || !w.current || F.current.isUserScrolling)
|
|
693
745
|
return;
|
|
694
|
-
const
|
|
695
|
-
|
|
696
|
-
top:
|
|
697
|
-
behavior:
|
|
746
|
+
const I = w.current;
|
|
747
|
+
I.scrollTo({
|
|
748
|
+
top: I.scrollHeight,
|
|
749
|
+
behavior: j.current ? "instant" : "smooth"
|
|
698
750
|
});
|
|
699
|
-
}, [
|
|
700
|
-
const
|
|
701
|
-
let
|
|
702
|
-
const
|
|
703
|
-
return (t.getState().getShadowMetadata(e, o)?.arrayKeys || []).forEach((
|
|
704
|
-
const
|
|
705
|
-
|
|
706
|
-
height:
|
|
707
|
-
offset:
|
|
708
|
-
}),
|
|
709
|
-
}),
|
|
710
|
-
}, [
|
|
711
|
-
|
|
712
|
-
if (
|
|
713
|
-
const
|
|
714
|
-
if (
|
|
715
|
-
const
|
|
716
|
-
|
|
717
|
-
),
|
|
751
|
+
}, [R, a]);
|
|
752
|
+
const L = t.getState().getShadowMetadata(e, o)?.arrayKeys || [], { totalHeight: N, itemOffsets: B } = ge(() => {
|
|
753
|
+
let I = 0;
|
|
754
|
+
const y = /* @__PURE__ */ new Map();
|
|
755
|
+
return (t.getState().getShadowMetadata(e, o)?.arrayKeys || []).forEach((C) => {
|
|
756
|
+
const _ = C.split(".").slice(1), q = t.getState().getShadowMetadata(e, _)?.virtualizer?.itemHeight || n;
|
|
757
|
+
y.set(C, {
|
|
758
|
+
height: q,
|
|
759
|
+
offset: I
|
|
760
|
+
}), I += q;
|
|
761
|
+
}), O.current = y, { totalHeight: I, itemOffsets: y };
|
|
762
|
+
}, [L.length, n]);
|
|
763
|
+
de(() => {
|
|
764
|
+
if (a && L.length > 0 && w.current && !F.current.isUserScrolling && j.current) {
|
|
765
|
+
const I = w.current, y = () => {
|
|
766
|
+
if (I.clientHeight > 0) {
|
|
767
|
+
const k = Math.ceil(
|
|
768
|
+
I.clientHeight / n
|
|
769
|
+
), C = L.length - 1, _ = Math.max(
|
|
718
770
|
0,
|
|
719
|
-
|
|
771
|
+
C - k - r
|
|
720
772
|
);
|
|
721
|
-
P({ startIndex:
|
|
722
|
-
|
|
773
|
+
P({ startIndex: _, endIndex: C }), requestAnimationFrame(() => {
|
|
774
|
+
E("instant"), j.current = !1;
|
|
723
775
|
});
|
|
724
776
|
} else
|
|
725
|
-
requestAnimationFrame(
|
|
777
|
+
requestAnimationFrame(y);
|
|
726
778
|
};
|
|
727
|
-
|
|
779
|
+
y();
|
|
728
780
|
}
|
|
729
|
-
}, [
|
|
730
|
-
const
|
|
731
|
-
const
|
|
732
|
-
if (!
|
|
733
|
-
const
|
|
734
|
-
|
|
735
|
-
let
|
|
736
|
-
for (let
|
|
737
|
-
const
|
|
738
|
-
if (
|
|
739
|
-
|
|
781
|
+
}, [L.length, a, n, r]);
|
|
782
|
+
const V = ce(() => {
|
|
783
|
+
const I = w.current;
|
|
784
|
+
if (!I) return;
|
|
785
|
+
const y = I.scrollTop, { scrollHeight: k, clientHeight: C } = I, _ = F.current, q = k - (y + C), H = _.isNearBottom;
|
|
786
|
+
_.isNearBottom = q <= d, y < _.lastScrollTop ? (_.scrollUpCount++, _.scrollUpCount > 3 && H && (_.isUserScrolling = !0, console.log("User scrolled away from bottom"))) : _.isNearBottom && (_.isUserScrolling = !1, _.scrollUpCount = 0), _.lastScrollTop = y;
|
|
787
|
+
let z = 0;
|
|
788
|
+
for (let Z = 0; Z < L.length; Z++) {
|
|
789
|
+
const ue = L[Z], me = O.current.get(ue);
|
|
790
|
+
if (me && me.offset + me.height > y) {
|
|
791
|
+
z = Z;
|
|
740
792
|
break;
|
|
741
793
|
}
|
|
742
794
|
}
|
|
743
|
-
if (
|
|
744
|
-
const
|
|
795
|
+
if (z !== m.startIndex) {
|
|
796
|
+
const Z = Math.ceil(C / n);
|
|
745
797
|
P({
|
|
746
|
-
startIndex: Math.max(0,
|
|
798
|
+
startIndex: Math.max(0, z - r),
|
|
747
799
|
endIndex: Math.min(
|
|
748
|
-
|
|
749
|
-
|
|
800
|
+
L.length - 1,
|
|
801
|
+
z + Z + r
|
|
750
802
|
)
|
|
751
803
|
});
|
|
752
804
|
}
|
|
753
805
|
}, [
|
|
754
|
-
|
|
755
|
-
|
|
806
|
+
L.length,
|
|
807
|
+
m.startIndex,
|
|
756
808
|
n,
|
|
757
809
|
r,
|
|
758
|
-
|
|
810
|
+
d
|
|
759
811
|
]);
|
|
760
|
-
|
|
761
|
-
const
|
|
762
|
-
if (!(!
|
|
763
|
-
return
|
|
812
|
+
Q(() => {
|
|
813
|
+
const I = w.current;
|
|
814
|
+
if (!(!I || !a))
|
|
815
|
+
return I.addEventListener("scroll", V, {
|
|
764
816
|
passive: !0
|
|
765
817
|
}), () => {
|
|
766
|
-
|
|
818
|
+
I.removeEventListener("scroll", V);
|
|
767
819
|
};
|
|
768
|
-
}, [
|
|
769
|
-
const
|
|
770
|
-
(
|
|
771
|
-
const
|
|
772
|
-
if (!
|
|
773
|
-
|
|
774
|
-
const
|
|
775
|
-
const
|
|
776
|
-
if (
|
|
777
|
-
const
|
|
778
|
-
|
|
779
|
-
top:
|
|
780
|
-
behavior:
|
|
820
|
+
}, [V, a]);
|
|
821
|
+
const E = ce(
|
|
822
|
+
(I = "smooth") => {
|
|
823
|
+
const y = w.current;
|
|
824
|
+
if (!y) return;
|
|
825
|
+
F.current.isUserScrolling = !1, F.current.isNearBottom = !0, F.current.scrollUpCount = 0;
|
|
826
|
+
const k = () => {
|
|
827
|
+
const C = (_ = 0) => {
|
|
828
|
+
if (_ > 5) return;
|
|
829
|
+
const q = y.scrollHeight, H = y.scrollTop, z = y.clientHeight;
|
|
830
|
+
H + z >= q - 1 || (y.scrollTo({
|
|
831
|
+
top: q,
|
|
832
|
+
behavior: I
|
|
781
833
|
}), setTimeout(() => {
|
|
782
|
-
const
|
|
783
|
-
(
|
|
834
|
+
const Z = y.scrollHeight, ue = y.scrollTop;
|
|
835
|
+
(Z !== q || ue + z < Z - 1) && C(_ + 1);
|
|
784
836
|
}, 50));
|
|
785
837
|
};
|
|
786
|
-
|
|
838
|
+
C();
|
|
787
839
|
};
|
|
788
|
-
"requestIdleCallback" in window ? requestIdleCallback(
|
|
789
|
-
requestAnimationFrame(
|
|
840
|
+
"requestIdleCallback" in window ? requestIdleCallback(k, { timeout: 100 }) : requestAnimationFrame(() => {
|
|
841
|
+
requestAnimationFrame(k);
|
|
790
842
|
});
|
|
791
843
|
},
|
|
792
844
|
[]
|
|
793
845
|
);
|
|
794
|
-
return
|
|
795
|
-
if (!
|
|
796
|
-
const
|
|
797
|
-
let
|
|
798
|
-
const
|
|
799
|
-
clearTimeout(
|
|
800
|
-
!
|
|
801
|
-
|
|
846
|
+
return Q(() => {
|
|
847
|
+
if (!a || !w.current) return;
|
|
848
|
+
const I = w.current, y = F.current;
|
|
849
|
+
let k;
|
|
850
|
+
const C = () => {
|
|
851
|
+
clearTimeout(k), k = setTimeout(() => {
|
|
852
|
+
!y.isUserScrolling && y.isNearBottom && E(
|
|
853
|
+
j.current ? "instant" : "smooth"
|
|
802
854
|
);
|
|
803
855
|
}, 100);
|
|
804
|
-
},
|
|
805
|
-
|
|
856
|
+
}, _ = new MutationObserver(() => {
|
|
857
|
+
y.isUserScrolling || C();
|
|
806
858
|
});
|
|
807
|
-
|
|
859
|
+
_.observe(I, {
|
|
808
860
|
childList: !0,
|
|
809
861
|
subtree: !0,
|
|
810
862
|
attributes: !0,
|
|
811
863
|
attributeFilter: ["style", "class"]
|
|
812
864
|
// More specific than just 'height'
|
|
813
865
|
});
|
|
814
|
-
const
|
|
815
|
-
|
|
866
|
+
const q = (H) => {
|
|
867
|
+
H.target instanceof HTMLImageElement && !y.isUserScrolling && C();
|
|
816
868
|
};
|
|
817
|
-
return
|
|
818
|
-
|
|
819
|
-
}, 0) :
|
|
820
|
-
clearTimeout(
|
|
869
|
+
return I.addEventListener("load", q, !0), j.current ? setTimeout(() => {
|
|
870
|
+
E("instant");
|
|
871
|
+
}, 0) : C(), () => {
|
|
872
|
+
clearTimeout(k), _.disconnect(), I.removeEventListener("load", q, !0);
|
|
821
873
|
};
|
|
822
|
-
}, [
|
|
823
|
-
virtualState:
|
|
824
|
-
const
|
|
874
|
+
}, [a, L.length, E]), {
|
|
875
|
+
virtualState: ge(() => {
|
|
876
|
+
const I = t.getState(), y = I.getShadowValue(
|
|
825
877
|
[e, ...o].join(".")
|
|
826
|
-
),
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
),
|
|
830
|
-
|
|
831
|
-
|
|
878
|
+
), k = I.getShadowMetadata(e, o)?.arrayKeys || [], C = y.slice(
|
|
879
|
+
m.startIndex,
|
|
880
|
+
m.endIndex + 1
|
|
881
|
+
), _ = k.slice(
|
|
882
|
+
m.startIndex,
|
|
883
|
+
m.endIndex + 1
|
|
832
884
|
);
|
|
833
|
-
return
|
|
834
|
-
currentState:
|
|
885
|
+
return l({
|
|
886
|
+
currentState: C,
|
|
835
887
|
path: o,
|
|
836
|
-
componentId:
|
|
837
|
-
meta: { ...S, validIds:
|
|
888
|
+
componentId: T,
|
|
889
|
+
meta: { ...S, validIds: _ }
|
|
838
890
|
});
|
|
839
|
-
}, [
|
|
891
|
+
}, [m.startIndex, m.endIndex, L.length]),
|
|
840
892
|
virtualizerProps: {
|
|
841
893
|
outer: {
|
|
842
|
-
ref:
|
|
894
|
+
ref: w,
|
|
843
895
|
style: {
|
|
844
896
|
overflowY: "auto",
|
|
845
897
|
height: "100%",
|
|
@@ -848,855 +900,910 @@ function Pe(e, s, p, g) {
|
|
|
848
900
|
},
|
|
849
901
|
inner: {
|
|
850
902
|
style: {
|
|
851
|
-
height: `${
|
|
903
|
+
height: `${N}px`,
|
|
852
904
|
position: "relative"
|
|
853
905
|
}
|
|
854
906
|
},
|
|
855
907
|
list: {
|
|
856
908
|
style: {
|
|
857
|
-
transform: `translateY(${
|
|
858
|
-
|
|
909
|
+
transform: `translateY(${O.current.get(
|
|
910
|
+
L[m.startIndex]
|
|
859
911
|
)?.offset || 0}px)`
|
|
860
912
|
}
|
|
861
913
|
}
|
|
862
914
|
},
|
|
863
|
-
scrollToBottom:
|
|
864
|
-
scrollToIndex: (
|
|
865
|
-
if (
|
|
866
|
-
const
|
|
867
|
-
|
|
915
|
+
scrollToBottom: E,
|
|
916
|
+
scrollToIndex: (I, y = "smooth") => {
|
|
917
|
+
if (w.current && L[I]) {
|
|
918
|
+
const k = O.current.get(L[I])?.offset || 0;
|
|
919
|
+
w.current.scrollTo({ top: k, behavior: y });
|
|
868
920
|
}
|
|
869
921
|
}
|
|
870
922
|
};
|
|
871
923
|
};
|
|
872
|
-
if (
|
|
873
|
-
return (
|
|
874
|
-
const [n, r] =
|
|
924
|
+
if (v === "stateMap")
|
|
925
|
+
return (s) => {
|
|
926
|
+
const [n, r] = X(
|
|
875
927
|
S?.validIds ?? t.getState().getShadowMetadata(e, o)?.arrayKeys
|
|
876
|
-
),
|
|
928
|
+
), a = t.getState().getShadowValue(c, S?.validIds);
|
|
877
929
|
if (!n)
|
|
878
930
|
throw new Error("No array keys found for mapping");
|
|
879
|
-
const
|
|
880
|
-
currentState:
|
|
931
|
+
const d = l({
|
|
932
|
+
currentState: a,
|
|
881
933
|
path: o,
|
|
882
|
-
componentId:
|
|
934
|
+
componentId: T,
|
|
883
935
|
meta: S
|
|
884
936
|
});
|
|
885
|
-
return
|
|
886
|
-
const P = n[
|
|
887
|
-
currentState:
|
|
937
|
+
return a.map((w, m) => {
|
|
938
|
+
const P = n[m]?.split(".").slice(1), R = l({
|
|
939
|
+
currentState: w,
|
|
888
940
|
path: P,
|
|
889
|
-
componentId:
|
|
941
|
+
componentId: T,
|
|
890
942
|
meta: S
|
|
891
943
|
});
|
|
892
|
-
return
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
944
|
+
return s(
|
|
945
|
+
R,
|
|
946
|
+
m,
|
|
947
|
+
d
|
|
896
948
|
);
|
|
897
949
|
});
|
|
898
950
|
};
|
|
899
|
-
if (
|
|
900
|
-
return (
|
|
951
|
+
if (v === "$stateMap")
|
|
952
|
+
return (s) => le(Ge, {
|
|
901
953
|
proxy: {
|
|
902
954
|
_stateKey: e,
|
|
903
955
|
_path: o,
|
|
904
|
-
_mapFn:
|
|
956
|
+
_mapFn: s,
|
|
905
957
|
_meta: S
|
|
906
958
|
},
|
|
907
|
-
rebuildStateShape:
|
|
959
|
+
rebuildStateShape: l
|
|
908
960
|
});
|
|
909
|
-
if (
|
|
910
|
-
return (
|
|
961
|
+
if (v === "stateFind")
|
|
962
|
+
return (s) => {
|
|
963
|
+
const n = S?.validIds ?? t.getState().getShadowMetadata(e, o)?.arrayKeys;
|
|
964
|
+
if (n)
|
|
965
|
+
for (let r = 0; r < n.length; r++) {
|
|
966
|
+
const a = n[r];
|
|
967
|
+
if (!a) continue;
|
|
968
|
+
const d = t.getState().getShadowValue(a);
|
|
969
|
+
if (s(d, r)) {
|
|
970
|
+
const w = a.split(".").slice(1);
|
|
971
|
+
return l({
|
|
972
|
+
currentState: d,
|
|
973
|
+
path: w,
|
|
974
|
+
componentId: T,
|
|
975
|
+
meta: S
|
|
976
|
+
// Pass along meta for potential further chaining
|
|
977
|
+
});
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
};
|
|
981
|
+
if (v === "stateFilter")
|
|
982
|
+
return (s) => {
|
|
911
983
|
const n = S?.validIds ?? t.getState().getShadowMetadata(e, o)?.arrayKeys;
|
|
912
984
|
if (!n)
|
|
913
985
|
throw new Error("No array keys found for filtering.");
|
|
914
|
-
const r = [],
|
|
915
|
-
(
|
|
986
|
+
const r = [], a = b.filter(
|
|
987
|
+
(d, w) => s(d, w) ? (r.push(n[w]), !0) : !1
|
|
916
988
|
);
|
|
917
|
-
return
|
|
918
|
-
currentState:
|
|
989
|
+
return l({
|
|
990
|
+
currentState: a,
|
|
919
991
|
path: o,
|
|
920
|
-
componentId:
|
|
992
|
+
componentId: T,
|
|
921
993
|
meta: {
|
|
922
994
|
validIds: r,
|
|
923
995
|
transforms: [
|
|
924
996
|
...S?.transforms || [],
|
|
925
997
|
{
|
|
926
998
|
type: "filter",
|
|
927
|
-
fn:
|
|
999
|
+
fn: s
|
|
928
1000
|
}
|
|
929
1001
|
]
|
|
930
1002
|
}
|
|
931
1003
|
});
|
|
932
1004
|
};
|
|
933
|
-
if (
|
|
934
|
-
return (
|
|
1005
|
+
if (v === "stateSort")
|
|
1006
|
+
return (s) => {
|
|
935
1007
|
const n = S?.validIds ?? t.getState().getShadowMetadata(e, o)?.arrayKeys;
|
|
936
1008
|
if (!n)
|
|
937
1009
|
throw new Error("No array keys found for sorting");
|
|
938
|
-
const r =
|
|
939
|
-
item:
|
|
940
|
-
key: n[
|
|
1010
|
+
const r = b.map((a, d) => ({
|
|
1011
|
+
item: a,
|
|
1012
|
+
key: n[d]
|
|
941
1013
|
}));
|
|
942
|
-
return r.sort((
|
|
943
|
-
currentState: r.map((
|
|
1014
|
+
return r.sort((a, d) => s(a.item, d.item)).filter(Boolean), l({
|
|
1015
|
+
currentState: r.map((a) => a.item),
|
|
944
1016
|
path: o,
|
|
945
|
-
componentId:
|
|
1017
|
+
componentId: T,
|
|
946
1018
|
meta: {
|
|
947
|
-
validIds: r.map((
|
|
1019
|
+
validIds: r.map((a) => a.key),
|
|
948
1020
|
transforms: [
|
|
949
1021
|
...S?.transforms || [],
|
|
950
|
-
{ type: "sort", fn:
|
|
1022
|
+
{ type: "sort", fn: s }
|
|
951
1023
|
]
|
|
952
1024
|
}
|
|
953
1025
|
});
|
|
954
1026
|
};
|
|
955
|
-
if (
|
|
956
|
-
return function(
|
|
1027
|
+
if (v === "stream")
|
|
1028
|
+
return function(s = {}) {
|
|
957
1029
|
const {
|
|
958
1030
|
bufferSize: n = 100,
|
|
959
1031
|
flushInterval: r = 100,
|
|
960
|
-
bufferStrategy:
|
|
961
|
-
store:
|
|
962
|
-
onFlush:
|
|
963
|
-
} =
|
|
964
|
-
let
|
|
965
|
-
const
|
|
1032
|
+
bufferStrategy: a = "accumulate",
|
|
1033
|
+
store: d,
|
|
1034
|
+
onFlush: w
|
|
1035
|
+
} = s;
|
|
1036
|
+
let m = [], P = !1, R = null;
|
|
1037
|
+
const D = (N) => {
|
|
966
1038
|
if (!P) {
|
|
967
|
-
if (
|
|
968
|
-
|
|
969
|
-
else if (
|
|
1039
|
+
if (a === "sliding" && m.length >= n)
|
|
1040
|
+
m.shift();
|
|
1041
|
+
else if (a === "dropping" && m.length >= n)
|
|
970
1042
|
return;
|
|
971
|
-
|
|
1043
|
+
m.push(N), m.length >= n && j();
|
|
972
1044
|
}
|
|
973
|
-
},
|
|
974
|
-
if (
|
|
975
|
-
const
|
|
976
|
-
if (
|
|
977
|
-
const
|
|
978
|
-
|
|
979
|
-
|
|
1045
|
+
}, j = () => {
|
|
1046
|
+
if (m.length === 0) return;
|
|
1047
|
+
const N = [...m];
|
|
1048
|
+
if (m = [], d) {
|
|
1049
|
+
const B = d(N);
|
|
1050
|
+
B !== void 0 && (Array.isArray(B) ? B : [B]).forEach((E) => {
|
|
1051
|
+
i(E, o, {
|
|
980
1052
|
updateType: "insert"
|
|
981
1053
|
});
|
|
982
1054
|
});
|
|
983
1055
|
} else
|
|
984
|
-
|
|
985
|
-
|
|
1056
|
+
N.forEach((B) => {
|
|
1057
|
+
i(B, o, {
|
|
986
1058
|
updateType: "insert"
|
|
987
1059
|
});
|
|
988
1060
|
});
|
|
989
|
-
|
|
1061
|
+
w?.(N);
|
|
990
1062
|
};
|
|
991
|
-
r > 0 && (
|
|
992
|
-
const
|
|
993
|
-
return
|
|
994
|
-
...
|
|
995
|
-
streams:
|
|
1063
|
+
r > 0 && (R = setInterval(j, r));
|
|
1064
|
+
const F = te(), O = t.getState().getShadowMetadata(e, o) || {}, L = O.streams || /* @__PURE__ */ new Map();
|
|
1065
|
+
return L.set(F, { buffer: m, flushTimer: R }), t.getState().setShadowMetadata(e, o, {
|
|
1066
|
+
...O,
|
|
1067
|
+
streams: L
|
|
996
1068
|
}), {
|
|
997
|
-
write: (
|
|
998
|
-
writeMany: (
|
|
999
|
-
flush: () =>
|
|
1069
|
+
write: (N) => D(N),
|
|
1070
|
+
writeMany: (N) => N.forEach(D),
|
|
1071
|
+
flush: () => j(),
|
|
1000
1072
|
pause: () => {
|
|
1001
1073
|
P = !0;
|
|
1002
1074
|
},
|
|
1003
1075
|
resume: () => {
|
|
1004
|
-
P = !1,
|
|
1076
|
+
P = !1, m.length > 0 && j();
|
|
1005
1077
|
},
|
|
1006
1078
|
close: () => {
|
|
1007
|
-
|
|
1008
|
-
const
|
|
1009
|
-
|
|
1079
|
+
j(), R && clearInterval(R);
|
|
1080
|
+
const N = t.getState().getShadowMetadata(e, o);
|
|
1081
|
+
N?.streams && N.streams.delete(F);
|
|
1010
1082
|
}
|
|
1011
1083
|
};
|
|
1012
1084
|
};
|
|
1013
|
-
if (
|
|
1014
|
-
return (
|
|
1015
|
-
const r =
|
|
1016
|
-
const
|
|
1017
|
-
let
|
|
1018
|
-
|
|
1085
|
+
if (v === "stateList")
|
|
1086
|
+
return (s) => /* @__PURE__ */ re(() => {
|
|
1087
|
+
const r = G(/* @__PURE__ */ new Map()), a = S?.transforms && S.transforms.length > 0 ? `${T}-${qe(S.transforms)}` : `${T}-base`, [d, w] = X({}), { validIds: m, arrayValues: P } = ge(() => {
|
|
1088
|
+
const D = t.getState().getShadowMetadata(e, o)?.transformCaches?.get(a);
|
|
1089
|
+
let j;
|
|
1090
|
+
D && D.validIds ? j = D.validIds : (j = Ie(
|
|
1019
1091
|
e,
|
|
1020
1092
|
o,
|
|
1021
1093
|
S?.transforms
|
|
1022
|
-
), t.getState().setTransformCache(e, o,
|
|
1023
|
-
validIds:
|
|
1094
|
+
), t.getState().setTransformCache(e, o, a, {
|
|
1095
|
+
validIds: j,
|
|
1024
1096
|
computedAt: Date.now(),
|
|
1025
1097
|
transforms: S?.transforms || []
|
|
1026
1098
|
}));
|
|
1027
|
-
const
|
|
1099
|
+
const F = t.getState().getShadowValue(c, j);
|
|
1028
1100
|
return {
|
|
1029
|
-
validIds:
|
|
1030
|
-
arrayValues:
|
|
1101
|
+
validIds: j,
|
|
1102
|
+
arrayValues: F || []
|
|
1031
1103
|
};
|
|
1032
|
-
}, [
|
|
1033
|
-
if (
|
|
1034
|
-
const
|
|
1035
|
-
if (
|
|
1104
|
+
}, [a, d]);
|
|
1105
|
+
if (console.log("freshValues", m, P), Q(() => {
|
|
1106
|
+
const D = t.getState().subscribeToPath(c, (j) => {
|
|
1107
|
+
if (j.type === "GET_SELECTED")
|
|
1036
1108
|
return;
|
|
1037
|
-
const
|
|
1038
|
-
if (
|
|
1039
|
-
for (const
|
|
1040
|
-
|
|
1041
|
-
|
|
1109
|
+
const O = t.getState().getShadowMetadata(e, o)?.transformCaches;
|
|
1110
|
+
if (O)
|
|
1111
|
+
for (const L of O.keys())
|
|
1112
|
+
L.startsWith(T) && O.delete(L);
|
|
1113
|
+
(j.type === "INSERT" || j.type === "REMOVE" || j.type === "CLEAR_SELECTION") && (console.log("sssssssssssssssssssssssssssss", j), w({}));
|
|
1042
1114
|
});
|
|
1043
1115
|
return () => {
|
|
1044
|
-
|
|
1116
|
+
D();
|
|
1045
1117
|
};
|
|
1046
|
-
}, [
|
|
1118
|
+
}, [T, c]), !Array.isArray(P))
|
|
1047
1119
|
return null;
|
|
1048
|
-
const
|
|
1120
|
+
const R = l({
|
|
1049
1121
|
currentState: P,
|
|
1050
1122
|
path: o,
|
|
1051
|
-
componentId:
|
|
1123
|
+
componentId: T,
|
|
1052
1124
|
meta: {
|
|
1053
1125
|
...S,
|
|
1054
|
-
validIds:
|
|
1126
|
+
validIds: m
|
|
1055
1127
|
}
|
|
1056
1128
|
});
|
|
1057
|
-
return /* @__PURE__ */
|
|
1058
|
-
const
|
|
1059
|
-
if (!
|
|
1129
|
+
return console.log("sssssssssssssssssssssssssssss", R), /* @__PURE__ */ re(ke, { children: P.map((D, j) => {
|
|
1130
|
+
const F = m[j];
|
|
1131
|
+
if (!F)
|
|
1060
1132
|
return null;
|
|
1061
|
-
let
|
|
1062
|
-
|
|
1063
|
-
const
|
|
1064
|
-
return le(
|
|
1065
|
-
key:
|
|
1133
|
+
let O = r.current.get(F);
|
|
1134
|
+
O || (O = te(), r.current.set(F, O));
|
|
1135
|
+
const L = F.split(".").slice(1);
|
|
1136
|
+
return le(Me, {
|
|
1137
|
+
key: F,
|
|
1066
1138
|
stateKey: e,
|
|
1067
|
-
itemComponentId:
|
|
1068
|
-
itemPath:
|
|
1069
|
-
localIndex:
|
|
1070
|
-
arraySetter:
|
|
1071
|
-
rebuildStateShape:
|
|
1072
|
-
renderFn:
|
|
1139
|
+
itemComponentId: O,
|
|
1140
|
+
itemPath: L,
|
|
1141
|
+
localIndex: j,
|
|
1142
|
+
arraySetter: R,
|
|
1143
|
+
rebuildStateShape: l,
|
|
1144
|
+
renderFn: s
|
|
1073
1145
|
});
|
|
1074
1146
|
}) });
|
|
1075
1147
|
}, {});
|
|
1076
|
-
if (
|
|
1077
|
-
return (
|
|
1078
|
-
const n =
|
|
1079
|
-
|
|
1148
|
+
if (v === "stateFlattenOn")
|
|
1149
|
+
return (s) => {
|
|
1150
|
+
const n = b;
|
|
1151
|
+
h.clear(), p++;
|
|
1080
1152
|
const r = n.flatMap(
|
|
1081
|
-
(
|
|
1153
|
+
(a) => a[s] ?? []
|
|
1082
1154
|
);
|
|
1083
|
-
return
|
|
1155
|
+
return l({
|
|
1084
1156
|
currentState: r,
|
|
1085
|
-
path: [...o, "[*]",
|
|
1086
|
-
componentId:
|
|
1157
|
+
path: [...o, "[*]", s],
|
|
1158
|
+
componentId: T,
|
|
1087
1159
|
meta: S
|
|
1088
1160
|
});
|
|
1089
1161
|
};
|
|
1090
|
-
if (
|
|
1091
|
-
return (
|
|
1162
|
+
if (v === "index")
|
|
1163
|
+
return (s) => {
|
|
1092
1164
|
const r = t.getState().getShadowMetadata(e, o)?.arrayKeys?.filter(
|
|
1093
|
-
(
|
|
1094
|
-
)?.[
|
|
1165
|
+
(w) => !S?.validIds || S?.validIds && S?.validIds?.includes(w)
|
|
1166
|
+
)?.[s];
|
|
1095
1167
|
if (!r) return;
|
|
1096
|
-
const
|
|
1097
|
-
return
|
|
1098
|
-
currentState:
|
|
1168
|
+
const a = t.getState().getShadowValue(r, S?.validIds);
|
|
1169
|
+
return l({
|
|
1170
|
+
currentState: a,
|
|
1099
1171
|
path: r.split(".").slice(1),
|
|
1100
|
-
componentId:
|
|
1172
|
+
componentId: T,
|
|
1101
1173
|
meta: S
|
|
1102
1174
|
});
|
|
1103
1175
|
};
|
|
1104
|
-
if (
|
|
1176
|
+
if (v === "last")
|
|
1105
1177
|
return () => {
|
|
1106
|
-
const
|
|
1107
|
-
if (
|
|
1108
|
-
const n =
|
|
1109
|
-
return
|
|
1178
|
+
const s = t.getState().getShadowValue(e, o);
|
|
1179
|
+
if (s.length === 0) return;
|
|
1180
|
+
const n = s.length - 1, r = s[n], a = [...o, n.toString()];
|
|
1181
|
+
return l({
|
|
1110
1182
|
currentState: r,
|
|
1111
|
-
path:
|
|
1112
|
-
componentId:
|
|
1183
|
+
path: a,
|
|
1184
|
+
componentId: T,
|
|
1113
1185
|
meta: S
|
|
1114
1186
|
});
|
|
1115
1187
|
};
|
|
1116
|
-
if (
|
|
1117
|
-
return (
|
|
1188
|
+
if (v === "insert")
|
|
1189
|
+
return (s, n) => (i(s, o, { updateType: "insert" }), l({
|
|
1118
1190
|
currentState: t.getState().getShadowValue(e, o),
|
|
1119
1191
|
path: o,
|
|
1120
|
-
componentId:
|
|
1192
|
+
componentId: T,
|
|
1121
1193
|
meta: S
|
|
1122
1194
|
}));
|
|
1123
|
-
if (
|
|
1124
|
-
return (
|
|
1125
|
-
const
|
|
1126
|
-
let
|
|
1127
|
-
if (!
|
|
1128
|
-
const
|
|
1129
|
-
(
|
|
1130
|
-
) :
|
|
1131
|
-
return
|
|
1195
|
+
if (v === "uniqueInsert")
|
|
1196
|
+
return (s, n, r) => {
|
|
1197
|
+
const a = t.getState().getShadowValue(e, o), d = ee(s) ? s(a) : s;
|
|
1198
|
+
let w = null;
|
|
1199
|
+
if (!a.some((P) => {
|
|
1200
|
+
const R = n ? n.every(
|
|
1201
|
+
(D) => se(P[D], d[D])
|
|
1202
|
+
) : se(P, d);
|
|
1203
|
+
return R && (w = P), R;
|
|
1132
1204
|
}))
|
|
1133
|
-
|
|
1134
|
-
else if (r &&
|
|
1135
|
-
const P = r(
|
|
1136
|
-
(
|
|
1205
|
+
M(o), i(d, o, { updateType: "insert" });
|
|
1206
|
+
else if (r && w) {
|
|
1207
|
+
const P = r(w), R = a.map(
|
|
1208
|
+
(D) => se(D, w) ? P : D
|
|
1137
1209
|
);
|
|
1138
|
-
|
|
1210
|
+
M(o), i(R, o, {
|
|
1139
1211
|
updateType: "update"
|
|
1140
1212
|
});
|
|
1141
1213
|
}
|
|
1142
1214
|
};
|
|
1143
|
-
if (
|
|
1144
|
-
return (
|
|
1215
|
+
if (v === "cut")
|
|
1216
|
+
return (s, n) => {
|
|
1145
1217
|
const r = S?.validIds ?? t.getState().getShadowMetadata(e, o)?.arrayKeys;
|
|
1146
1218
|
if (!r || r.length === 0) return;
|
|
1147
|
-
const
|
|
1148
|
-
if (!
|
|
1149
|
-
const
|
|
1150
|
-
|
|
1219
|
+
const a = s == -1 ? r.length - 1 : s !== void 0 ? s : r.length - 1, d = r[a];
|
|
1220
|
+
if (!d) return;
|
|
1221
|
+
const w = d.split(".").slice(1);
|
|
1222
|
+
i(b, w, {
|
|
1151
1223
|
updateType: "cut"
|
|
1152
1224
|
});
|
|
1153
1225
|
};
|
|
1154
|
-
if (
|
|
1226
|
+
if (v === "cutSelected")
|
|
1155
1227
|
return () => {
|
|
1156
1228
|
t.getState().getShadowMetadata(e, o)?.arrayKeys;
|
|
1157
|
-
const
|
|
1229
|
+
const s = Ie(
|
|
1158
1230
|
e,
|
|
1159
1231
|
o,
|
|
1160
1232
|
S?.transforms
|
|
1161
1233
|
);
|
|
1162
|
-
if (console.log("validKeys",
|
|
1163
|
-
const n = t.getState().selectedIndicesMap.get(
|
|
1164
|
-
let r =
|
|
1165
|
-
(
|
|
1234
|
+
if (console.log("validKeys", s), !s || s.length === 0) return;
|
|
1235
|
+
const n = t.getState().selectedIndicesMap.get(c);
|
|
1236
|
+
let r = s.findIndex(
|
|
1237
|
+
(d) => d === n
|
|
1166
1238
|
);
|
|
1167
1239
|
console.log("indexToCut", r);
|
|
1168
|
-
const
|
|
1169
|
-
console.log("pathForCut",
|
|
1240
|
+
const a = s[r == -1 ? s.length - 1 : r]?.split(".").slice(1);
|
|
1241
|
+
console.log("pathForCut", a), i(b, a, {
|
|
1170
1242
|
updateType: "cut"
|
|
1171
1243
|
});
|
|
1172
1244
|
};
|
|
1173
|
-
if (
|
|
1174
|
-
return (
|
|
1245
|
+
if (v === "cutByValue")
|
|
1246
|
+
return (s) => {
|
|
1175
1247
|
const n = t.getState().getShadowMetadata(e, o), r = S?.validIds ?? n?.arrayKeys;
|
|
1176
1248
|
if (!r) return;
|
|
1177
|
-
let
|
|
1178
|
-
for (const
|
|
1179
|
-
if (t.getState().getShadowValue(
|
|
1180
|
-
|
|
1249
|
+
let a = null;
|
|
1250
|
+
for (const d of r)
|
|
1251
|
+
if (t.getState().getShadowValue(d) === s) {
|
|
1252
|
+
a = d;
|
|
1181
1253
|
break;
|
|
1182
1254
|
}
|
|
1183
|
-
if (
|
|
1184
|
-
const
|
|
1185
|
-
|
|
1255
|
+
if (a) {
|
|
1256
|
+
const d = a.split(".").slice(1);
|
|
1257
|
+
i(null, d, { updateType: "cut" });
|
|
1186
1258
|
}
|
|
1187
1259
|
};
|
|
1188
|
-
if (
|
|
1189
|
-
return (
|
|
1260
|
+
if (v === "toggleByValue")
|
|
1261
|
+
return (s) => {
|
|
1190
1262
|
const n = t.getState().getShadowMetadata(e, o), r = S?.validIds ?? n?.arrayKeys;
|
|
1191
1263
|
if (!r) return;
|
|
1192
|
-
let
|
|
1193
|
-
for (const
|
|
1194
|
-
const
|
|
1195
|
-
if (console.log("itemValue sdasdasdasd",
|
|
1196
|
-
|
|
1264
|
+
let a = null;
|
|
1265
|
+
for (const d of r) {
|
|
1266
|
+
const w = t.getState().getShadowValue(d);
|
|
1267
|
+
if (console.log("itemValue sdasdasdasd", w), w === s) {
|
|
1268
|
+
a = d;
|
|
1197
1269
|
break;
|
|
1198
1270
|
}
|
|
1199
1271
|
}
|
|
1200
|
-
if (console.log("itemValue keyToCut",
|
|
1201
|
-
const
|
|
1202
|
-
console.log("itemValue keyToCut",
|
|
1272
|
+
if (console.log("itemValue keyToCut", a), a) {
|
|
1273
|
+
const d = a.split(".").slice(1);
|
|
1274
|
+
console.log("itemValue keyToCut", a), i(s, d, {
|
|
1203
1275
|
updateType: "cut"
|
|
1204
1276
|
});
|
|
1205
1277
|
} else
|
|
1206
|
-
s
|
|
1278
|
+
i(s, o, { updateType: "insert" });
|
|
1207
1279
|
};
|
|
1208
|
-
if (
|
|
1209
|
-
return (
|
|
1280
|
+
if (v === "findWith")
|
|
1281
|
+
return (s, n) => {
|
|
1210
1282
|
const r = t.getState().getShadowMetadata(e, o)?.arrayKeys;
|
|
1211
1283
|
if (!r)
|
|
1212
1284
|
throw new Error("No array keys found for sorting");
|
|
1213
|
-
let
|
|
1214
|
-
for (const
|
|
1215
|
-
let
|
|
1216
|
-
if (
|
|
1217
|
-
|
|
1285
|
+
let a = null, d = [];
|
|
1286
|
+
for (const w of r) {
|
|
1287
|
+
let m = t.getState().getShadowValue(w, S?.validIds);
|
|
1288
|
+
if (m && m[s] === n) {
|
|
1289
|
+
a = m, d = w.split(".").slice(1);
|
|
1218
1290
|
break;
|
|
1219
1291
|
}
|
|
1220
1292
|
}
|
|
1221
|
-
return
|
|
1222
|
-
currentState:
|
|
1223
|
-
path:
|
|
1224
|
-
componentId:
|
|
1293
|
+
return l({
|
|
1294
|
+
currentState: a,
|
|
1295
|
+
path: d,
|
|
1296
|
+
componentId: T,
|
|
1225
1297
|
meta: S
|
|
1226
1298
|
});
|
|
1227
1299
|
};
|
|
1228
1300
|
}
|
|
1229
|
-
if (
|
|
1230
|
-
let
|
|
1301
|
+
if (v === "cut") {
|
|
1302
|
+
let s = t.getState().getShadowValue(o.join("."));
|
|
1231
1303
|
return () => {
|
|
1232
|
-
s
|
|
1304
|
+
i(s, o, { updateType: "cut" });
|
|
1233
1305
|
};
|
|
1234
1306
|
}
|
|
1235
|
-
if (
|
|
1236
|
-
return () => (
|
|
1237
|
-
if (
|
|
1238
|
-
return (
|
|
1307
|
+
if (v === "get")
|
|
1308
|
+
return () => (Ve(e, T, o), t.getState().getShadowValue(c, S?.validIds));
|
|
1309
|
+
if (v === "$derive")
|
|
1310
|
+
return (s) => Ae({
|
|
1239
1311
|
_stateKey: e,
|
|
1240
1312
|
_path: o,
|
|
1241
|
-
_effect:
|
|
1313
|
+
_effect: s.toString(),
|
|
1242
1314
|
_meta: S
|
|
1243
1315
|
});
|
|
1244
|
-
if (
|
|
1245
|
-
return () =>
|
|
1246
|
-
if (
|
|
1247
|
-
const
|
|
1248
|
-
return t.getState().getSyncInfo(
|
|
1316
|
+
if (v === "$get")
|
|
1317
|
+
return () => Ae({ _stateKey: e, _path: o, _meta: S });
|
|
1318
|
+
if (v === "lastSynced") {
|
|
1319
|
+
const s = `${e}:${o.join(".")}`;
|
|
1320
|
+
return t.getState().getSyncInfo(s);
|
|
1249
1321
|
}
|
|
1250
|
-
if (
|
|
1251
|
-
return (
|
|
1252
|
-
if (
|
|
1253
|
-
const
|
|
1254
|
-
if (
|
|
1255
|
-
t.getState().getShadowValue(
|
|
1322
|
+
if (v == "getLocalStorage")
|
|
1323
|
+
return (s) => Se(g + "-" + e + "-" + s);
|
|
1324
|
+
if (v === "isSelected") {
|
|
1325
|
+
const s = [e, ...o].slice(0, -1);
|
|
1326
|
+
if (ye(e, o, void 0), Array.isArray(
|
|
1327
|
+
t.getState().getShadowValue(s.join("."), S?.validIds)
|
|
1256
1328
|
)) {
|
|
1257
1329
|
o[o.length - 1];
|
|
1258
|
-
const n =
|
|
1259
|
-
return r ===
|
|
1330
|
+
const n = s.join("."), r = t.getState().selectedIndicesMap.get(n), a = e + "." + o.join(".");
|
|
1331
|
+
return r === a;
|
|
1260
1332
|
}
|
|
1261
1333
|
return;
|
|
1262
1334
|
}
|
|
1263
|
-
if (
|
|
1264
|
-
return (
|
|
1265
|
-
const n = o.slice(0, -1), r = e + "." + n.join("."),
|
|
1266
|
-
|
|
1335
|
+
if (v === "setSelected")
|
|
1336
|
+
return (s) => {
|
|
1337
|
+
const n = o.slice(0, -1), r = e + "." + n.join("."), a = e + "." + o.join(".");
|
|
1338
|
+
ye(e, n, void 0), t.getState().selectedIndicesMap.get(r), s && t.getState().setSelectedIndex(r, a);
|
|
1267
1339
|
};
|
|
1268
|
-
if (
|
|
1340
|
+
if (v === "toggleSelected")
|
|
1269
1341
|
return () => {
|
|
1270
|
-
const
|
|
1342
|
+
const s = o.slice(0, -1), n = e + "." + s.join("."), r = e + "." + o.join(".");
|
|
1271
1343
|
t.getState().selectedIndicesMap.get(n) === r ? t.getState().clearSelectedIndex({ arrayKey: n }) : t.getState().setSelectedIndex(n, r);
|
|
1272
1344
|
};
|
|
1273
|
-
if (
|
|
1274
|
-
return
|
|
1345
|
+
if (v === "_componentId")
|
|
1346
|
+
return T;
|
|
1275
1347
|
if (o.length == 0) {
|
|
1276
|
-
if (
|
|
1277
|
-
return (
|
|
1348
|
+
if (v === "addValidation")
|
|
1349
|
+
return (s) => {
|
|
1278
1350
|
const n = t.getState().getInitialOptions(e)?.validation;
|
|
1279
1351
|
if (!n?.key) throw new Error("Validation key not found");
|
|
1280
|
-
ne(n.key),
|
|
1281
|
-
const
|
|
1282
|
-
|
|
1283
|
-
}),
|
|
1352
|
+
ne(n.key), s.forEach((r) => {
|
|
1353
|
+
const a = [n.key, ...r.path].join(".");
|
|
1354
|
+
ve(a, r.message);
|
|
1355
|
+
}), ie(e);
|
|
1284
1356
|
};
|
|
1285
|
-
if (
|
|
1286
|
-
return (
|
|
1287
|
-
const n = t.getState().
|
|
1288
|
-
|
|
1357
|
+
if (v === "applyJsonPatch")
|
|
1358
|
+
return (s) => {
|
|
1359
|
+
const n = t.getState(), r = (a) => !a || a === "/" ? [] : a.split("/").slice(1).map((d) => d.replace(/~1/g, "/").replace(/~0/g, "~"));
|
|
1360
|
+
for (const a of s) {
|
|
1361
|
+
const d = r(a.path);
|
|
1362
|
+
switch (a.op) {
|
|
1363
|
+
case "add":
|
|
1364
|
+
case "replace": {
|
|
1365
|
+
const { value: w } = a;
|
|
1366
|
+
n.updateShadowAtPath(e, d, w), n.markAsDirty(e, d, { bubble: !0 });
|
|
1367
|
+
break;
|
|
1368
|
+
}
|
|
1369
|
+
case "remove": {
|
|
1370
|
+
n.removeShadowArrayElement(e, d);
|
|
1371
|
+
const w = d.slice(0, -1);
|
|
1372
|
+
n.markAsDirty(e, w, { bubble: !0 });
|
|
1373
|
+
break;
|
|
1374
|
+
}
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1289
1377
|
};
|
|
1290
|
-
if (
|
|
1378
|
+
if (v === "validateZodSchema")
|
|
1291
1379
|
return () => {
|
|
1292
|
-
const
|
|
1293
|
-
if (!
|
|
1380
|
+
const s = t.getState().getInitialOptions(e)?.validation;
|
|
1381
|
+
if (!s?.zodSchema || !s?.key)
|
|
1294
1382
|
throw new Error("Zod schema or validation key not found");
|
|
1295
|
-
ne(
|
|
1296
|
-
const n = t.getState().getShadowValue(e), r =
|
|
1297
|
-
return r.success ? !0 : (r.error.errors.forEach((
|
|
1298
|
-
const
|
|
1299
|
-
|
|
1300
|
-
}),
|
|
1383
|
+
ne(s.key);
|
|
1384
|
+
const n = t.getState().getShadowValue(e), r = s.zodSchema.safeParse(n);
|
|
1385
|
+
return r.success ? !0 : (r.error.errors.forEach((a) => {
|
|
1386
|
+
const d = [s.key, ...a.path].join(".");
|
|
1387
|
+
ve(d, a.message);
|
|
1388
|
+
}), ie(e), !1);
|
|
1301
1389
|
};
|
|
1302
|
-
if (
|
|
1390
|
+
if (v === "getComponents")
|
|
1303
1391
|
return () => t.getState().getShadowMetadata(e, [])?.components;
|
|
1304
|
-
if (
|
|
1305
|
-
return () =>
|
|
1392
|
+
if (v === "getAllFormRefs")
|
|
1393
|
+
return () => pe.getState().getFormRefsByStateKey(e);
|
|
1306
1394
|
}
|
|
1307
|
-
if (
|
|
1308
|
-
return () =>
|
|
1309
|
-
if (
|
|
1395
|
+
if (v === "getFormRef")
|
|
1396
|
+
return () => pe.getState().getFormRef(e + "." + o.join("."));
|
|
1397
|
+
if (v === "validationWrapper")
|
|
1310
1398
|
return ({
|
|
1311
|
-
children:
|
|
1399
|
+
children: s,
|
|
1312
1400
|
hideMessage: n
|
|
1313
|
-
}) => /* @__PURE__ */
|
|
1314
|
-
|
|
1401
|
+
}) => /* @__PURE__ */ re(
|
|
1402
|
+
be,
|
|
1315
1403
|
{
|
|
1316
1404
|
formOpts: n ? { validation: { message: "" } } : void 0,
|
|
1317
1405
|
path: o,
|
|
1318
1406
|
stateKey: e,
|
|
1319
|
-
children:
|
|
1407
|
+
children: s
|
|
1320
1408
|
}
|
|
1321
1409
|
);
|
|
1322
|
-
if (
|
|
1323
|
-
if (
|
|
1324
|
-
if (
|
|
1325
|
-
return (
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1410
|
+
if (v === "_stateKey") return e;
|
|
1411
|
+
if (v === "_path") return o;
|
|
1412
|
+
if (v === "update")
|
|
1413
|
+
return (s) => (i(s, o, { updateType: "update" }), {
|
|
1414
|
+
/**
|
|
1415
|
+
* Marks this specific item, which was just updated, as 'synced' (not dirty).
|
|
1416
|
+
*/
|
|
1417
|
+
synced: () => {
|
|
1418
|
+
const n = t.getState().getShadowMetadata(e, o);
|
|
1419
|
+
t.getState().setShadowMetadata(e, o, {
|
|
1420
|
+
...n,
|
|
1421
|
+
isDirty: !1,
|
|
1422
|
+
// EXPLICITLY set to false, not just undefined
|
|
1423
|
+
stateSource: "server",
|
|
1424
|
+
// Mark as coming from server
|
|
1425
|
+
lastServerSync: Date.now()
|
|
1426
|
+
// Add timestamp
|
|
1427
|
+
});
|
|
1428
|
+
const r = [e, ...o].join(".");
|
|
1429
|
+
t.getState().notifyPathSubscribers(r, {
|
|
1430
|
+
type: "SYNC_STATUS_CHANGE",
|
|
1431
|
+
isDirty: !1
|
|
1432
|
+
});
|
|
1433
|
+
}
|
|
1434
|
+
});
|
|
1435
|
+
if (v === "toggle") {
|
|
1436
|
+
const s = t.getState().getShadowValue([e, ...o].join("."));
|
|
1437
|
+
if (console.log("currentValueAtPath", s), typeof b != "boolean")
|
|
1331
1438
|
throw new Error("toggle() can only be used on boolean values");
|
|
1332
1439
|
return () => {
|
|
1333
|
-
|
|
1440
|
+
i(!s, o, {
|
|
1334
1441
|
updateType: "update"
|
|
1335
1442
|
});
|
|
1336
1443
|
};
|
|
1337
1444
|
}
|
|
1338
|
-
if (
|
|
1339
|
-
return (
|
|
1340
|
-
|
|
1445
|
+
if (v === "formElement")
|
|
1446
|
+
return (s, n) => /* @__PURE__ */ re(
|
|
1447
|
+
be,
|
|
1341
1448
|
{
|
|
1342
1449
|
formOpts: n,
|
|
1343
1450
|
path: o,
|
|
1344
1451
|
stateKey: e,
|
|
1345
|
-
children: /* @__PURE__ */
|
|
1452
|
+
children: /* @__PURE__ */ re(
|
|
1346
1453
|
Ze,
|
|
1347
1454
|
{
|
|
1348
1455
|
stateKey: e,
|
|
1349
1456
|
path: o,
|
|
1350
|
-
rebuildStateShape:
|
|
1351
|
-
setState:
|
|
1457
|
+
rebuildStateShape: l,
|
|
1458
|
+
setState: i,
|
|
1352
1459
|
formOpts: n,
|
|
1353
|
-
renderFn:
|
|
1460
|
+
renderFn: s
|
|
1354
1461
|
}
|
|
1355
1462
|
)
|
|
1356
1463
|
}
|
|
1357
1464
|
);
|
|
1358
|
-
const
|
|
1359
|
-
return
|
|
1360
|
-
currentState:
|
|
1361
|
-
path:
|
|
1362
|
-
componentId:
|
|
1465
|
+
const oe = [...o, v], fe = t.getState().getShadowValue(e, oe);
|
|
1466
|
+
return l({
|
|
1467
|
+
currentState: fe,
|
|
1468
|
+
path: oe,
|
|
1469
|
+
componentId: T,
|
|
1363
1470
|
meta: S
|
|
1364
1471
|
});
|
|
1365
1472
|
}
|
|
1366
|
-
},
|
|
1367
|
-
return
|
|
1368
|
-
proxy:
|
|
1369
|
-
stateVersion:
|
|
1370
|
-
}),
|
|
1473
|
+
}, J = new Proxy(x, Y);
|
|
1474
|
+
return h.set(W, {
|
|
1475
|
+
proxy: J,
|
|
1476
|
+
stateVersion: p
|
|
1477
|
+
}), J;
|
|
1371
1478
|
}
|
|
1372
|
-
const
|
|
1373
|
-
removeValidation: (
|
|
1374
|
-
|
|
1479
|
+
const u = {
|
|
1480
|
+
removeValidation: (b) => {
|
|
1481
|
+
b?.validationKey && ne(b.validationKey);
|
|
1375
1482
|
},
|
|
1376
|
-
revertToInitialState: (
|
|
1483
|
+
revertToInitialState: (b) => {
|
|
1377
1484
|
const o = t.getState().getInitialOptions(e)?.validation;
|
|
1378
|
-
o?.key && ne(o.key),
|
|
1485
|
+
o?.key && ne(o.key), b?.validationKey && ne(b.validationKey);
|
|
1379
1486
|
const S = t.getState().getShadowMetadata(e, []);
|
|
1380
1487
|
S?.stateSource === "server" && S.baseServerState ? S.baseServerState : t.getState().initialStateGlobal[e];
|
|
1381
|
-
const
|
|
1382
|
-
t.getState().clearSelectedIndexesForState(e),
|
|
1383
|
-
currentState:
|
|
1488
|
+
const T = t.getState().initialStateGlobal[e];
|
|
1489
|
+
t.getState().clearSelectedIndexesForState(e), h.clear(), p++, t.getState().initializeShadowState(e, T), l({
|
|
1490
|
+
currentState: T,
|
|
1384
1491
|
path: [],
|
|
1385
|
-
componentId:
|
|
1492
|
+
componentId: f
|
|
1386
1493
|
});
|
|
1387
|
-
const
|
|
1388
|
-
|
|
1389
|
-
const
|
|
1390
|
-
return
|
|
1391
|
-
|
|
1392
|
-
}),
|
|
1494
|
+
const W = ae(e), c = ee(W?.localStorage?.key) ? W?.localStorage?.key(T) : W?.localStorage?.key, x = `${g}-${e}-${c}`;
|
|
1495
|
+
x && localStorage.removeItem(x);
|
|
1496
|
+
const Y = t.getState().getShadowMetadata(e, []);
|
|
1497
|
+
return Y && Y?.components?.forEach((J) => {
|
|
1498
|
+
J.forceUpdate();
|
|
1499
|
+
}), T;
|
|
1393
1500
|
},
|
|
1394
|
-
updateInitialState: (
|
|
1395
|
-
|
|
1396
|
-
const o =
|
|
1501
|
+
updateInitialState: (b) => {
|
|
1502
|
+
h.clear(), p++;
|
|
1503
|
+
const o = De(
|
|
1397
1504
|
e,
|
|
1398
|
-
|
|
1399
|
-
|
|
1505
|
+
i,
|
|
1506
|
+
f,
|
|
1400
1507
|
g
|
|
1401
|
-
), S = t.getState().initialStateGlobal[e],
|
|
1402
|
-
return localStorage.getItem(
|
|
1403
|
-
|
|
1404
|
-
const
|
|
1405
|
-
|
|
1406
|
-
|
|
1508
|
+
), S = t.getState().initialStateGlobal[e], T = ae(e), W = ee(T?.localStorage?.key) ? T?.localStorage?.key(S) : T?.localStorage?.key, c = `${g}-${e}-${W}`;
|
|
1509
|
+
return localStorage.getItem(c) && localStorage.removeItem(c), je(() => {
|
|
1510
|
+
$e(e, b), t.getState().initializeShadowState(e, b);
|
|
1511
|
+
const x = t.getState().getShadowMetadata(e, []);
|
|
1512
|
+
x && x?.components?.forEach((Y) => {
|
|
1513
|
+
Y.forceUpdate();
|
|
1407
1514
|
});
|
|
1408
1515
|
}), {
|
|
1409
|
-
fetchId: (
|
|
1516
|
+
fetchId: (x) => o.get()[x]
|
|
1410
1517
|
};
|
|
1411
1518
|
}
|
|
1412
1519
|
};
|
|
1413
|
-
return
|
|
1520
|
+
return l({
|
|
1414
1521
|
currentState: t.getState().getShadowValue(e, []),
|
|
1415
|
-
componentId:
|
|
1522
|
+
componentId: f,
|
|
1416
1523
|
path: []
|
|
1417
1524
|
});
|
|
1418
1525
|
}
|
|
1419
|
-
function
|
|
1420
|
-
return le(
|
|
1526
|
+
function Ae(e) {
|
|
1527
|
+
return le(ze, { proxy: e });
|
|
1421
1528
|
}
|
|
1422
|
-
function
|
|
1529
|
+
function Ge({
|
|
1423
1530
|
proxy: e,
|
|
1424
|
-
rebuildStateShape:
|
|
1531
|
+
rebuildStateShape: i
|
|
1425
1532
|
}) {
|
|
1426
|
-
const
|
|
1427
|
-
|
|
1428
|
-
const
|
|
1429
|
-
if (!
|
|
1430
|
-
const
|
|
1431
|
-
const
|
|
1432
|
-
|
|
1533
|
+
const f = G(null), g = G(`map-${crypto.randomUUID()}`), h = G(!1), p = G(/* @__PURE__ */ new Map());
|
|
1534
|
+
Q(() => {
|
|
1535
|
+
const l = f.current;
|
|
1536
|
+
if (!l || h.current) return;
|
|
1537
|
+
const u = setTimeout(() => {
|
|
1538
|
+
const A = t.getState().getShadowMetadata(e._stateKey, e._path) || {}, b = A.mapWrappers || [];
|
|
1539
|
+
b.push({
|
|
1433
1540
|
instanceId: g.current,
|
|
1434
1541
|
mapFn: e._mapFn,
|
|
1435
|
-
containerRef:
|
|
1436
|
-
rebuildStateShape:
|
|
1542
|
+
containerRef: l,
|
|
1543
|
+
rebuildStateShape: i,
|
|
1437
1544
|
path: e._path,
|
|
1438
1545
|
componentId: g.current,
|
|
1439
1546
|
meta: e._meta
|
|
1440
1547
|
}), t.getState().setShadowMetadata(e._stateKey, e._path, {
|
|
1441
|
-
...
|
|
1442
|
-
mapWrappers:
|
|
1443
|
-
}),
|
|
1548
|
+
...A,
|
|
1549
|
+
mapWrappers: b
|
|
1550
|
+
}), h.current = !0, M();
|
|
1444
1551
|
}, 0);
|
|
1445
1552
|
return () => {
|
|
1446
|
-
if (clearTimeout(
|
|
1447
|
-
const
|
|
1448
|
-
|
|
1449
|
-
(
|
|
1450
|
-
), t.getState().setShadowMetadata(e._stateKey, e._path,
|
|
1553
|
+
if (clearTimeout(u), g.current) {
|
|
1554
|
+
const A = t.getState().getShadowMetadata(e._stateKey, e._path) || {};
|
|
1555
|
+
A.mapWrappers && (A.mapWrappers = A.mapWrappers.filter(
|
|
1556
|
+
(b) => b.instanceId !== g.current
|
|
1557
|
+
), t.getState().setShadowMetadata(e._stateKey, e._path, A));
|
|
1451
1558
|
}
|
|
1452
|
-
|
|
1559
|
+
p.current.forEach((A) => A.unmount());
|
|
1453
1560
|
};
|
|
1454
1561
|
}, []);
|
|
1455
|
-
const
|
|
1456
|
-
const
|
|
1457
|
-
if (!
|
|
1458
|
-
const
|
|
1562
|
+
const M = () => {
|
|
1563
|
+
const l = f.current;
|
|
1564
|
+
if (!l) return;
|
|
1565
|
+
const u = t.getState().getShadowValue(
|
|
1459
1566
|
[e._stateKey, ...e._path].join("."),
|
|
1460
1567
|
e._meta?.validIds
|
|
1461
1568
|
);
|
|
1462
|
-
if (!Array.isArray(
|
|
1463
|
-
const
|
|
1464
|
-
currentState:
|
|
1569
|
+
if (!Array.isArray(u)) return;
|
|
1570
|
+
const A = e._meta?.validIds ?? t.getState().getShadowMetadata(e._stateKey, e._path)?.arrayKeys ?? [], b = i({
|
|
1571
|
+
currentState: u,
|
|
1465
1572
|
path: e._path,
|
|
1466
1573
|
componentId: g.current,
|
|
1467
1574
|
meta: e._meta
|
|
1468
1575
|
});
|
|
1469
|
-
|
|
1470
|
-
const
|
|
1471
|
-
if (!
|
|
1472
|
-
const
|
|
1473
|
-
|
|
1474
|
-
const
|
|
1475
|
-
|
|
1476
|
-
const
|
|
1477
|
-
|
|
1478
|
-
le(
|
|
1576
|
+
u.forEach((o, S) => {
|
|
1577
|
+
const T = A[S];
|
|
1578
|
+
if (!T) return;
|
|
1579
|
+
const W = te(), c = document.createElement("div");
|
|
1580
|
+
c.setAttribute("data-item-path", T), l.appendChild(c);
|
|
1581
|
+
const x = Ce(c);
|
|
1582
|
+
p.current.set(T, x);
|
|
1583
|
+
const Y = T.split(".").slice(1);
|
|
1584
|
+
x.render(
|
|
1585
|
+
le(Me, {
|
|
1479
1586
|
stateKey: e._stateKey,
|
|
1480
|
-
itemComponentId:
|
|
1481
|
-
itemPath:
|
|
1587
|
+
itemComponentId: W,
|
|
1588
|
+
itemPath: Y,
|
|
1482
1589
|
localIndex: S,
|
|
1483
|
-
arraySetter:
|
|
1484
|
-
rebuildStateShape:
|
|
1590
|
+
arraySetter: b,
|
|
1591
|
+
rebuildStateShape: i,
|
|
1485
1592
|
renderFn: e._mapFn
|
|
1486
1593
|
})
|
|
1487
1594
|
);
|
|
1488
1595
|
});
|
|
1489
1596
|
};
|
|
1490
|
-
return /* @__PURE__ */
|
|
1597
|
+
return /* @__PURE__ */ re("div", { ref: f, "data-map-container": g.current });
|
|
1491
1598
|
}
|
|
1492
|
-
function
|
|
1599
|
+
function ze({
|
|
1493
1600
|
proxy: e
|
|
1494
1601
|
}) {
|
|
1495
|
-
const
|
|
1602
|
+
const i = G(null), f = G(null), g = G(!1), h = `${e._stateKey}-${e._path.join(".")}`, p = t.getState().getShadowValue(
|
|
1496
1603
|
[e._stateKey, ...e._path].join("."),
|
|
1497
1604
|
e._meta?.validIds
|
|
1498
1605
|
);
|
|
1499
|
-
return
|
|
1500
|
-
const
|
|
1501
|
-
if (!
|
|
1502
|
-
const
|
|
1503
|
-
if (!
|
|
1504
|
-
console.warn("Parent element not found for signal",
|
|
1606
|
+
return Q(() => {
|
|
1607
|
+
const M = i.current;
|
|
1608
|
+
if (!M || g.current) return;
|
|
1609
|
+
const l = setTimeout(() => {
|
|
1610
|
+
if (!M.parentElement) {
|
|
1611
|
+
console.warn("Parent element not found for signal", h);
|
|
1505
1612
|
return;
|
|
1506
1613
|
}
|
|
1507
|
-
const
|
|
1508
|
-
let o =
|
|
1509
|
-
o || (o = `parent-${crypto.randomUUID()}`,
|
|
1510
|
-
const S = t.getState().getShadowMetadata(e._stateKey, e._path) || {},
|
|
1511
|
-
|
|
1512
|
-
instanceId:
|
|
1614
|
+
const u = M.parentElement, b = Array.from(u.childNodes).indexOf(M);
|
|
1615
|
+
let o = u.getAttribute("data-parent-id");
|
|
1616
|
+
o || (o = `parent-${crypto.randomUUID()}`, u.setAttribute("data-parent-id", o)), f.current = `instance-${crypto.randomUUID()}`;
|
|
1617
|
+
const S = t.getState().getShadowMetadata(e._stateKey, e._path) || {}, T = S.signals || [];
|
|
1618
|
+
T.push({
|
|
1619
|
+
instanceId: f.current,
|
|
1513
1620
|
parentId: o,
|
|
1514
|
-
position:
|
|
1621
|
+
position: b,
|
|
1515
1622
|
effect: e._effect
|
|
1516
1623
|
}), t.getState().setShadowMetadata(e._stateKey, e._path, {
|
|
1517
1624
|
...S,
|
|
1518
|
-
signals:
|
|
1625
|
+
signals: T
|
|
1519
1626
|
});
|
|
1520
|
-
let
|
|
1627
|
+
let W = p;
|
|
1521
1628
|
if (e._effect)
|
|
1522
1629
|
try {
|
|
1523
|
-
|
|
1630
|
+
W = new Function(
|
|
1524
1631
|
"state",
|
|
1525
1632
|
`return (${e._effect})(state)`
|
|
1526
|
-
)(
|
|
1527
|
-
} catch (
|
|
1528
|
-
console.error("Error evaluating effect function:",
|
|
1633
|
+
)(p);
|
|
1634
|
+
} catch (x) {
|
|
1635
|
+
console.error("Error evaluating effect function:", x);
|
|
1529
1636
|
}
|
|
1530
|
-
|
|
1531
|
-
const
|
|
1532
|
-
|
|
1637
|
+
W !== null && typeof W == "object" && (W = JSON.stringify(W));
|
|
1638
|
+
const c = document.createTextNode(String(W ?? ""));
|
|
1639
|
+
M.replaceWith(c), g.current = !0;
|
|
1533
1640
|
}, 0);
|
|
1534
1641
|
return () => {
|
|
1535
|
-
if (clearTimeout(
|
|
1536
|
-
const
|
|
1537
|
-
|
|
1538
|
-
(
|
|
1539
|
-
), t.getState().setShadowMetadata(e._stateKey, e._path,
|
|
1642
|
+
if (clearTimeout(l), f.current) {
|
|
1643
|
+
const u = t.getState().getShadowMetadata(e._stateKey, e._path) || {};
|
|
1644
|
+
u.signals && (u.signals = u.signals.filter(
|
|
1645
|
+
(A) => A.instanceId !== f.current
|
|
1646
|
+
), t.getState().setShadowMetadata(e._stateKey, e._path, u));
|
|
1540
1647
|
}
|
|
1541
1648
|
};
|
|
1542
1649
|
}, []), le("span", {
|
|
1543
|
-
ref:
|
|
1650
|
+
ref: i,
|
|
1544
1651
|
style: { display: "contents" },
|
|
1545
|
-
"data-signal-id":
|
|
1652
|
+
"data-signal-id": h
|
|
1546
1653
|
});
|
|
1547
1654
|
}
|
|
1548
|
-
const
|
|
1655
|
+
const Me = Re(
|
|
1549
1656
|
Ye,
|
|
1550
|
-
(e,
|
|
1657
|
+
(e, i) => e.itemPath.join(".") === i.itemPath.join(".") && e.stateKey === i.stateKey && e.itemComponentId === i.itemComponentId && e.localIndex === i.localIndex
|
|
1551
1658
|
), Je = (e) => {
|
|
1552
|
-
const [
|
|
1553
|
-
return
|
|
1659
|
+
const [i, f] = X(!1);
|
|
1660
|
+
return de(() => {
|
|
1554
1661
|
if (!e.current) {
|
|
1555
|
-
|
|
1662
|
+
f(!0);
|
|
1556
1663
|
return;
|
|
1557
1664
|
}
|
|
1558
1665
|
const g = Array.from(e.current.querySelectorAll("img"));
|
|
1559
1666
|
if (g.length === 0) {
|
|
1560
|
-
|
|
1667
|
+
f(!0);
|
|
1561
1668
|
return;
|
|
1562
1669
|
}
|
|
1563
|
-
let
|
|
1564
|
-
const
|
|
1565
|
-
|
|
1670
|
+
let h = 0;
|
|
1671
|
+
const p = () => {
|
|
1672
|
+
h++, h === g.length && f(!0);
|
|
1566
1673
|
};
|
|
1567
|
-
return g.forEach((
|
|
1568
|
-
|
|
1674
|
+
return g.forEach((M) => {
|
|
1675
|
+
M.complete ? p() : (M.addEventListener("load", p), M.addEventListener("error", p));
|
|
1569
1676
|
}), () => {
|
|
1570
|
-
g.forEach((
|
|
1571
|
-
|
|
1677
|
+
g.forEach((M) => {
|
|
1678
|
+
M.removeEventListener("load", p), M.removeEventListener("error", p);
|
|
1572
1679
|
});
|
|
1573
1680
|
};
|
|
1574
|
-
}, [e.current]),
|
|
1681
|
+
}, [e.current]), i;
|
|
1575
1682
|
};
|
|
1576
1683
|
function Ye({
|
|
1577
1684
|
stateKey: e,
|
|
1578
|
-
itemComponentId:
|
|
1579
|
-
itemPath:
|
|
1685
|
+
itemComponentId: i,
|
|
1686
|
+
itemPath: f,
|
|
1580
1687
|
localIndex: g,
|
|
1581
|
-
arraySetter:
|
|
1582
|
-
rebuildStateShape:
|
|
1583
|
-
renderFn:
|
|
1688
|
+
arraySetter: h,
|
|
1689
|
+
rebuildStateShape: p,
|
|
1690
|
+
renderFn: M
|
|
1584
1691
|
}) {
|
|
1585
|
-
const [,
|
|
1586
|
-
Ue(e,
|
|
1587
|
-
const
|
|
1588
|
-
(
|
|
1589
|
-
|
|
1692
|
+
const [, l] = X({}), { ref: u, inView: A } = Le(), b = G(null), o = Je(b), S = G(!1), T = [e, ...f].join(".");
|
|
1693
|
+
Ue(e, i, l);
|
|
1694
|
+
const W = ce(
|
|
1695
|
+
(U) => {
|
|
1696
|
+
b.current = U, u(U);
|
|
1590
1697
|
},
|
|
1591
|
-
[
|
|
1698
|
+
[u]
|
|
1592
1699
|
);
|
|
1593
|
-
|
|
1594
|
-
t.getState().subscribeToPath(
|
|
1595
|
-
|
|
1700
|
+
Q(() => {
|
|
1701
|
+
t.getState().subscribeToPath(T, (U) => {
|
|
1702
|
+
l({});
|
|
1596
1703
|
});
|
|
1597
|
-
}, []),
|
|
1598
|
-
if (!
|
|
1704
|
+
}, []), Q(() => {
|
|
1705
|
+
if (!A || !o || S.current)
|
|
1599
1706
|
return;
|
|
1600
|
-
const
|
|
1601
|
-
if (
|
|
1707
|
+
const U = b.current;
|
|
1708
|
+
if (U && U.offsetHeight > 0) {
|
|
1602
1709
|
S.current = !0;
|
|
1603
|
-
const
|
|
1604
|
-
t.getState().setShadowMetadata(e,
|
|
1710
|
+
const v = U.offsetHeight;
|
|
1711
|
+
t.getState().setShadowMetadata(e, f, {
|
|
1605
1712
|
virtualizer: {
|
|
1606
|
-
itemHeight:
|
|
1607
|
-
domRef:
|
|
1713
|
+
itemHeight: v,
|
|
1714
|
+
domRef: U
|
|
1608
1715
|
}
|
|
1609
1716
|
});
|
|
1610
|
-
const
|
|
1611
|
-
t.getState().notifyPathSubscribers(
|
|
1717
|
+
const K = f.slice(0, -1), oe = [e, ...K].join(".");
|
|
1718
|
+
t.getState().notifyPathSubscribers(oe, {
|
|
1612
1719
|
type: "ITEMHEIGHT",
|
|
1613
|
-
itemKey:
|
|
1614
|
-
ref:
|
|
1720
|
+
itemKey: f.join("."),
|
|
1721
|
+
ref: b.current
|
|
1615
1722
|
});
|
|
1616
1723
|
}
|
|
1617
|
-
}, [
|
|
1618
|
-
const
|
|
1619
|
-
if (
|
|
1724
|
+
}, [A, o, e, f]);
|
|
1725
|
+
const c = [e, ...f].join("."), x = t.getState().getShadowValue(c);
|
|
1726
|
+
if (x === void 0)
|
|
1620
1727
|
return null;
|
|
1621
|
-
const
|
|
1622
|
-
currentState:
|
|
1623
|
-
path:
|
|
1624
|
-
componentId:
|
|
1625
|
-
}),
|
|
1626
|
-
return /* @__PURE__ */
|
|
1728
|
+
const Y = p({
|
|
1729
|
+
currentState: x,
|
|
1730
|
+
path: f,
|
|
1731
|
+
componentId: i
|
|
1732
|
+
}), J = M(Y, g, h);
|
|
1733
|
+
return /* @__PURE__ */ re("div", { ref: W, children: J });
|
|
1627
1734
|
}
|
|
1628
1735
|
function Ze({
|
|
1629
1736
|
stateKey: e,
|
|
1630
|
-
path:
|
|
1631
|
-
rebuildStateShape:
|
|
1737
|
+
path: i,
|
|
1738
|
+
rebuildStateShape: f,
|
|
1632
1739
|
renderFn: g,
|
|
1633
|
-
formOpts:
|
|
1634
|
-
setState:
|
|
1740
|
+
formOpts: h,
|
|
1741
|
+
setState: p
|
|
1635
1742
|
}) {
|
|
1636
|
-
const [
|
|
1637
|
-
Ue(e,
|
|
1638
|
-
const
|
|
1639
|
-
|
|
1640
|
-
!S.current && !
|
|
1641
|
-
}, [
|
|
1642
|
-
const
|
|
1643
|
-
|
|
1743
|
+
const [M] = X(() => te()), [, l] = X({}), u = [e, ...i].join(".");
|
|
1744
|
+
Ue(e, M, l);
|
|
1745
|
+
const A = t.getState().getShadowValue(u), [b, o] = X(A), S = G(!1), T = G(null);
|
|
1746
|
+
Q(() => {
|
|
1747
|
+
!S.current && !se(A, b) && o(A);
|
|
1748
|
+
}, [A]), Q(() => {
|
|
1749
|
+
const J = t.getState().subscribeToPath(u, (U) => {
|
|
1750
|
+
l({});
|
|
1644
1751
|
});
|
|
1645
1752
|
return () => {
|
|
1646
|
-
|
|
1753
|
+
J(), T.current && (clearTimeout(T.current), S.current = !1);
|
|
1647
1754
|
};
|
|
1648
1755
|
}, []);
|
|
1649
|
-
const
|
|
1650
|
-
(
|
|
1651
|
-
o(
|
|
1652
|
-
const
|
|
1653
|
-
|
|
1654
|
-
S.current = !1,
|
|
1655
|
-
},
|
|
1756
|
+
const W = ce(
|
|
1757
|
+
(J) => {
|
|
1758
|
+
o(J), S.current = !0, T.current && clearTimeout(T.current);
|
|
1759
|
+
const U = h?.debounceTime ?? 200;
|
|
1760
|
+
T.current = setTimeout(() => {
|
|
1761
|
+
S.current = !1, p(J, i, { updateType: "update" });
|
|
1762
|
+
}, U);
|
|
1656
1763
|
},
|
|
1657
|
-
[
|
|
1658
|
-
),
|
|
1659
|
-
|
|
1660
|
-
}, [
|
|
1661
|
-
currentState:
|
|
1662
|
-
path:
|
|
1663
|
-
componentId:
|
|
1664
|
-
}),
|
|
1665
|
-
get(
|
|
1666
|
-
return
|
|
1667
|
-
value:
|
|
1668
|
-
onChange: (
|
|
1669
|
-
|
|
1764
|
+
[p, i, h?.debounceTime]
|
|
1765
|
+
), c = ce(() => {
|
|
1766
|
+
T.current && (clearTimeout(T.current), S.current = !1, p(b, i, { updateType: "update" }));
|
|
1767
|
+
}, [p, i, b]), x = f({
|
|
1768
|
+
currentState: A,
|
|
1769
|
+
path: i,
|
|
1770
|
+
componentId: M
|
|
1771
|
+
}), Y = new Proxy(x, {
|
|
1772
|
+
get(J, U) {
|
|
1773
|
+
return U === "inputProps" ? {
|
|
1774
|
+
value: b ?? "",
|
|
1775
|
+
onChange: (v) => {
|
|
1776
|
+
W(v.target.value);
|
|
1670
1777
|
},
|
|
1671
|
-
onBlur:
|
|
1672
|
-
ref:
|
|
1673
|
-
} :
|
|
1778
|
+
onBlur: c,
|
|
1779
|
+
ref: pe.getState().getFormRef(e + "." + i.join("."))
|
|
1780
|
+
} : J[U];
|
|
1674
1781
|
}
|
|
1675
1782
|
});
|
|
1676
|
-
return /* @__PURE__ */
|
|
1783
|
+
return /* @__PURE__ */ re(ke, { children: g(Y) });
|
|
1677
1784
|
}
|
|
1678
|
-
function Ue(e,
|
|
1679
|
-
const g = `${e}////${
|
|
1680
|
-
|
|
1681
|
-
const
|
|
1682
|
-
return
|
|
1683
|
-
forceUpdate: () =>
|
|
1785
|
+
function Ue(e, i, f) {
|
|
1786
|
+
const g = `${e}////${i}`;
|
|
1787
|
+
de(() => {
|
|
1788
|
+
const h = t.getState().getShadowMetadata(e, []), p = h?.components || /* @__PURE__ */ new Map();
|
|
1789
|
+
return p.set(g, {
|
|
1790
|
+
forceUpdate: () => f({}),
|
|
1684
1791
|
paths: /* @__PURE__ */ new Set(),
|
|
1685
1792
|
reactiveType: ["component"]
|
|
1686
1793
|
}), t.getState().setShadowMetadata(e, [], {
|
|
1687
|
-
...
|
|
1688
|
-
components:
|
|
1794
|
+
...h,
|
|
1795
|
+
components: p
|
|
1689
1796
|
}), () => {
|
|
1690
|
-
const
|
|
1691
|
-
|
|
1797
|
+
const M = t.getState().getShadowMetadata(e, []);
|
|
1798
|
+
M?.components && M.components.delete(g);
|
|
1692
1799
|
};
|
|
1693
1800
|
}, [e, g]);
|
|
1694
1801
|
}
|
|
1695
1802
|
export {
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1803
|
+
Ae as $cogsSignal,
|
|
1804
|
+
it as addStateOptions,
|
|
1805
|
+
ct as createCogsState,
|
|
1806
|
+
lt as notifyComponent,
|
|
1700
1807
|
Be as useCogsStateFn
|
|
1701
1808
|
};
|
|
1702
1809
|
//# sourceMappingURL=CogsState.jsx.map
|