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