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