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