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