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