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