cogsbox-state 0.5.488 → 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/README.md +4 -4
- package/dist/CogsState.d.ts +2 -50
- package/dist/CogsState.d.ts.map +1 -1
- package/dist/CogsState.js +886 -1002
- package/dist/CogsState.js.map +1 -1
- package/dist/plugins.d.ts +4 -2
- 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 +267 -594
- package/src/plugins.ts +23 -14
- package/src/store.ts +2 -96
package/dist/CogsState.js
CHANGED
|
@@ -1,150 +1,145 @@
|
|
|
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:
|
|
13
|
+
getInitialOptions: _,
|
|
14
|
+
updateInitialStateGlobal: pe,
|
|
15
|
+
getShadowMetadata: $,
|
|
16
|
+
setShadowMetadata: ee,
|
|
17
17
|
getShadowValue: O,
|
|
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 ?? [] };
|
|
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 f = a
|
|
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];
|
|
48
45
|
if (f)
|
|
49
|
-
return { key: f, index:
|
|
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 (
|
|
62
|
+
const a = _(e) || {}, f = c[e] || {};
|
|
63
|
+
let l = { ...f, ...a }, h = !1;
|
|
64
|
+
if (r) {
|
|
68
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 m =
|
|
78
|
-
(m !==
|
|
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
|
|
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);
|
|
89
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(
|
|
100
|
+
Object.keys(E).length > 0 && fe(o, E);
|
|
104
101
|
}), Object.keys(f).forEach((o) => {
|
|
105
|
-
|
|
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
130
|
function m(o, d) {
|
|
136
|
-
if (
|
|
137
|
-
const
|
|
138
|
-
...
|
|
139
|
-
formWrapper: d.formElements[
|
|
140
|
-
} :
|
|
141
|
-
|
|
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(f).forEach((
|
|
147
|
-
m(
|
|
141
|
+
Object.keys(f).forEach((P) => {
|
|
142
|
+
m(P, o);
|
|
148
143
|
});
|
|
149
144
|
}
|
|
150
145
|
return {
|
|
@@ -152,143 +147,119 @@ const bt = (e, a) => {
|
|
|
152
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 = `${
|
|
157
|
+
const l = W(c?.localStorage?.key) ? c.localStorage?.key(e) : c?.localStorage?.key;
|
|
158
|
+
if (l && a) {
|
|
159
|
+
const h = `${a}-${r}-${l}`;
|
|
165
160
|
let m;
|
|
166
161
|
try {
|
|
167
|
-
m =
|
|
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: m
|
|
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 (f &&
|
|
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, m) => {
|
|
227
|
-
const t = [...a, h], o = l[m];
|
|
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], m = l[u];
|
|
237
|
-
oe(e, h, m, 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 m =
|
|
253
|
-
if (f &&
|
|
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
226
|
m = new Function("state", `return (${f})(state)`)(
|
|
256
|
-
|
|
227
|
+
r
|
|
257
228
|
);
|
|
258
229
|
} catch (t) {
|
|
259
230
|
console.error("Error evaluating effect function:", t);
|
|
260
231
|
}
|
|
261
|
-
m !== null && typeof m == "object" && (m = JSON.stringify(m)), h[
|
|
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
239
|
const f = /* @__PURE__ */ new Set();
|
|
269
|
-
if (
|
|
270
|
-
let
|
|
240
|
+
if (c.type === "update") {
|
|
241
|
+
let l = [...r];
|
|
271
242
|
for (; ; ) {
|
|
272
|
-
const h =
|
|
243
|
+
const h = $(e, l);
|
|
273
244
|
if (h?.pathComponents && h.pathComponents.forEach((m) => {
|
|
274
|
-
const t =
|
|
245
|
+
const t = a.components?.get(m);
|
|
275
246
|
t && ((Array.isArray(t.reactiveType) ? t.reactiveType : [t.reactiveType || "component"]).includes("none") || f.add(t));
|
|
276
|
-
}),
|
|
277
|
-
|
|
247
|
+
}), l.length === 0) break;
|
|
248
|
+
l.pop();
|
|
278
249
|
}
|
|
279
|
-
|
|
280
|
-
const t = m.split("."), o = [...
|
|
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 m =
|
|
260
|
+
const m = $(e, h);
|
|
290
261
|
if (m?.pathComponents && m.pathComponents.forEach((t) => {
|
|
291
|
-
const o =
|
|
262
|
+
const o = a.components?.get(t);
|
|
292
263
|
o && f.add(o);
|
|
293
264
|
}), h.length === 0) break;
|
|
294
265
|
h.pop();
|
|
@@ -296,68 +267,66 @@ function tt(e, a, l) {
|
|
|
296
267
|
}
|
|
297
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:
|
|
278
|
+
oldValue: a,
|
|
308
279
|
newValue: f,
|
|
309
|
-
shadowMeta:
|
|
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
|
-
u,
|
|
333
|
-
s,
|
|
334
305
|
f
|
|
335
|
-
);
|
|
336
|
-
ie(e, a, { bubble: !0 });
|
|
337
|
-
const m = E(e, a);
|
|
306
|
+
), m = $(e, r);
|
|
338
307
|
let t;
|
|
339
|
-
return m?.arrayKeys &&
|
|
308
|
+
return m?.arrayKeys && a !== void 0 && a > 0 && (t = m.arrayKeys[a - 1]), {
|
|
340
309
|
type: "insert",
|
|
341
|
-
newValue:
|
|
310
|
+
newValue: l,
|
|
342
311
|
shadowMeta: m,
|
|
343
|
-
path:
|
|
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 f =
|
|
360
|
-
f.shadowMeta?.signals?.length > 0 &&
|
|
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(
|
|
361
330
|
f.stateKey,
|
|
362
331
|
f.path,
|
|
363
332
|
f
|
|
@@ -365,45 +334,45 @@ function st() {
|
|
|
365
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 (f,
|
|
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
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 =
|
|
354
|
+
t = et(
|
|
386
355
|
f,
|
|
387
|
-
|
|
356
|
+
l,
|
|
388
357
|
h,
|
|
389
358
|
m.index,
|
|
390
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 = f, t.path =
|
|
371
|
+
t.stateKey = f, t.path = l, ae.push(t), Qe();
|
|
403
372
|
const o = {
|
|
404
373
|
timeStamp: Date.now(),
|
|
405
374
|
stateKey: f,
|
|
406
|
-
path:
|
|
375
|
+
path: l,
|
|
407
376
|
updateType: m.updateType,
|
|
408
377
|
status: "new",
|
|
409
378
|
oldValue: t.oldValue,
|
|
@@ -412,49 +381,42 @@ function it(e, a, l) {
|
|
|
412
381
|
insertAfterId: t.insertAfterId,
|
|
413
382
|
metaData: m.metaData
|
|
414
383
|
};
|
|
415
|
-
|
|
384
|
+
ae.push(o), t.newValue !== void 0 && Je(
|
|
416
385
|
t.newValue,
|
|
417
386
|
f,
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
),
|
|
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:
|
|
392
|
+
function at(e, {
|
|
393
|
+
stateKey: r,
|
|
394
|
+
localStorage: c,
|
|
395
|
+
formElements: a,
|
|
427
396
|
reactiveDeps: f,
|
|
428
|
-
reactiveType:
|
|
397
|
+
reactiveType: l,
|
|
429
398
|
componentId: h,
|
|
430
399
|
defaultState: m,
|
|
431
|
-
dependencies: t
|
|
432
|
-
serverState: o
|
|
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 S = W(r.localStorage.key) ? r.localStorage.key(n) : r.localStorage.key, i = ce(
|
|
451
|
-
`${b}-${v}-${S}`
|
|
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,386 +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, 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
|
-
console.error(
|
|
481
|
-
"CogsState: Merge strategy 'append' requires a 'key' field."
|
|
482
|
-
);
|
|
483
|
-
return;
|
|
484
|
-
}
|
|
485
|
-
const y = new Set(
|
|
486
|
-
c.map((A) => A[i])
|
|
487
|
-
), w = S.filter(
|
|
488
|
-
(A) => !y.has(A[i])
|
|
489
|
-
);
|
|
490
|
-
w.length > 0 && be(v, [], w);
|
|
491
|
-
const p = O(v, []);
|
|
492
|
-
oe(
|
|
493
|
-
v,
|
|
494
|
-
[],
|
|
495
|
-
p,
|
|
496
|
-
r.timestamp || Date.now()
|
|
497
|
-
);
|
|
498
|
-
} else
|
|
499
|
-
K(v, S), oe(
|
|
500
|
-
v,
|
|
501
|
-
[],
|
|
502
|
-
S,
|
|
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: y
|
|
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
|
-
baseServerState: c === "server" ? n : void 0
|
|
531
|
-
}), c === "server" && o && me(v, o), N(v);
|
|
532
|
-
}, [v, ...t || []]), re(() => {
|
|
533
|
-
P && ue(v, {
|
|
534
|
-
formElements: s,
|
|
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,
|
|
535
449
|
defaultState: m,
|
|
536
|
-
localStorage:
|
|
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
458
|
depsFunction: f || void 0,
|
|
545
|
-
deps: f ? f(O(
|
|
546
|
-
prevDeps: f ? f(O(
|
|
547
|
-
}),
|
|
548
|
-
...
|
|
549
|
-
components:
|
|
550
|
-
}),
|
|
551
|
-
const n =
|
|
552
|
-
|
|
553
|
-
const
|
|
554
|
-
|
|
555
|
-
}), n?.components &&
|
|
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 f =
|
|
484
|
+
const ot = (e, r, c) => {
|
|
485
|
+
let a = $(e, r)?.arrayKeys || [];
|
|
486
|
+
const f = c?.transforms;
|
|
573
487
|
if (!f || f.length === 0)
|
|
574
|
-
return
|
|
575
|
-
for (const
|
|
576
|
-
if (
|
|
488
|
+
return a;
|
|
489
|
+
for (const l of f)
|
|
490
|
+
if (l.type === "filter") {
|
|
577
491
|
const h = [];
|
|
578
|
-
|
|
579
|
-
const o = O(e, [...
|
|
580
|
-
|
|
581
|
-
}),
|
|
582
|
-
} else
|
|
583
|
-
const t = O(e, [...
|
|
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
|
-
|
|
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) => {
|
|
593
507
|
(Array.isArray(h.reactiveType) ? h.reactiveType : [h.reactiveType || "component"]).includes("all") && (h.forceUpdate(), f.add(m));
|
|
594
|
-
}),
|
|
595
|
-
...
|
|
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 m = h + ".selected", t =
|
|
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 = O(e,
|
|
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
|
-
f.domRef?.current &&
|
|
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));
|
|
647
561
|
});
|
|
648
562
|
}
|
|
649
|
-
function
|
|
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();
|
|
573
|
+
});
|
|
574
|
+
}
|
|
575
|
+
function Pe(e, r, c, a) {
|
|
650
576
|
const f = /* @__PURE__ */ new Map();
|
|
651
|
-
function
|
|
577
|
+
function l({
|
|
652
578
|
path: t = [],
|
|
653
579
|
meta: o,
|
|
654
580
|
componentId: d
|
|
655
581
|
}) {
|
|
656
|
-
if (
|
|
582
|
+
if ($(e, t)?.isRaw)
|
|
657
583
|
return O(e, t);
|
|
658
|
-
const
|
|
659
|
-
if (f.has(
|
|
660
|
-
return f.get(
|
|
661
|
-
const
|
|
662
|
-
},
|
|
663
|
-
apply(
|
|
664
|
-
if (
|
|
665
|
-
const
|
|
666
|
-
return
|
|
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
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
625
|
+
const s = [...t, u];
|
|
626
|
+
return l({
|
|
627
|
+
path: s,
|
|
628
|
+
componentId: d,
|
|
629
|
+
meta: o
|
|
630
|
+
});
|
|
631
|
+
}
|
|
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(
|
|
706
640
|
{
|
|
707
641
|
stateKey: e,
|
|
708
642
|
path: t,
|
|
709
|
-
pluginName:
|
|
643
|
+
pluginName: g.name,
|
|
710
644
|
options: A,
|
|
711
|
-
hookData:
|
|
712
|
-
$get: () =>
|
|
713
|
-
$update: (
|
|
645
|
+
hookData: p,
|
|
646
|
+
$get: () => N(e, t, o).value,
|
|
647
|
+
$update: (M) => (r(M, t, {
|
|
714
648
|
updateType: "update"
|
|
715
649
|
}), {
|
|
716
|
-
|
|
717
|
-
const _ = M.getState().getShadowMetadata(e, t);
|
|
718
|
-
B(e, t, {
|
|
719
|
-
..._,
|
|
720
|
-
isDirty: !1,
|
|
721
|
-
stateSource: "server",
|
|
722
|
-
lastServerSync: Date.now()
|
|
723
|
-
});
|
|
650
|
+
syned: () => {
|
|
724
651
|
}
|
|
725
652
|
}),
|
|
726
|
-
$applyOperation: (
|
|
727
|
-
|
|
728
|
-
updateType:
|
|
729
|
-
itemId:
|
|
730
|
-
metaData:
|
|
653
|
+
$applyOperation: (M, T) => {
|
|
654
|
+
r(M.newValue, M.path, {
|
|
655
|
+
updateType: M.updateType,
|
|
656
|
+
itemId: M.itemId,
|
|
657
|
+
metaData: T
|
|
731
658
|
});
|
|
732
659
|
},
|
|
733
|
-
getFieldMetaData: () =>
|
|
734
|
-
setFieldMetaData: (
|
|
735
|
-
removeFieldMetaData: () =>
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
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)
|
|
739
677
|
},
|
|
740
|
-
...
|
|
678
|
+
...y
|
|
741
679
|
);
|
|
742
680
|
};
|
|
743
681
|
}
|
|
744
|
-
const S = [...t, g];
|
|
745
|
-
return u({
|
|
746
|
-
path: S,
|
|
747
|
-
componentId: d,
|
|
748
|
-
meta: o
|
|
749
|
-
});
|
|
750
|
-
}
|
|
751
|
-
if (g === "$_rebuildStateShape")
|
|
752
|
-
return u;
|
|
753
|
-
if (g === "$sync" && t.length === 0)
|
|
754
|
-
return async function() {
|
|
755
|
-
const r = M.getState().getInitialOptions(e), n = r?.sync;
|
|
756
|
-
if (!n)
|
|
757
|
-
return console.error(`No mutation defined for state key "${e}"`), { success: !1, error: "No mutation defined" };
|
|
758
|
-
const c = M.getState().getShadowValue(e, []), S = r?.validation?.key;
|
|
759
|
-
try {
|
|
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
|
-
isDirty: !1,
|
|
766
|
-
lastServerSync: Date.now(),
|
|
767
|
-
stateSource: "server",
|
|
768
|
-
baseServerState: c
|
|
769
|
-
// Update base server state
|
|
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
|
-
}
|
|
776
|
-
};
|
|
777
|
-
if (g === "$_status" || g === "$getStatus") {
|
|
778
|
-
const r = () => {
|
|
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
|
-
};
|
|
782
|
-
return g === "$_status" ? r() : r;
|
|
783
682
|
}
|
|
784
|
-
if (
|
|
683
|
+
if (u === "$_rebuildStateShape")
|
|
684
|
+
return l;
|
|
685
|
+
if (u === "$removeStorage")
|
|
785
686
|
return () => {
|
|
786
|
-
const
|
|
787
|
-
|
|
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);
|
|
788
689
|
};
|
|
789
|
-
if (
|
|
790
|
-
return (
|
|
791
|
-
const
|
|
792
|
-
|
|
690
|
+
if (u === "$setRaw")
|
|
691
|
+
return (n) => {
|
|
692
|
+
const i = $(e, t) || {};
|
|
693
|
+
ee(e, t, { ...i, isRaw: !0 }), r(n, t, { updateType: "update" });
|
|
793
694
|
};
|
|
794
|
-
if (
|
|
795
|
-
return (
|
|
796
|
-
const
|
|
797
|
-
if (
|
|
798
|
-
const
|
|
799
|
-
const
|
|
800
|
-
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)
|
|
801
702
|
return {
|
|
802
|
-
key:
|
|
803
|
-
path:
|
|
703
|
+
key: A,
|
|
704
|
+
path: p,
|
|
804
705
|
success: !0,
|
|
805
|
-
data:
|
|
706
|
+
data: M
|
|
806
707
|
};
|
|
807
|
-
const I =
|
|
808
|
-
return
|
|
809
|
-
...
|
|
708
|
+
const I = j.safeParse(M), L = I.error?.issues || I.error?.errors || [];
|
|
709
|
+
return i.setShadowMetadata(e, p, {
|
|
710
|
+
...T,
|
|
810
711
|
validation: {
|
|
811
712
|
status: I.success ? "VALID" : "INVALID",
|
|
812
713
|
errors: I.success ? [] : [
|
|
813
714
|
{
|
|
814
715
|
source: "client",
|
|
815
|
-
message:
|
|
716
|
+
message: L[0]?.message || "Invalid value",
|
|
816
717
|
severity: "error",
|
|
817
|
-
code:
|
|
718
|
+
code: L[0]?.code
|
|
818
719
|
}
|
|
819
720
|
],
|
|
820
721
|
lastValidated: Date.now(),
|
|
821
|
-
validatedValue:
|
|
722
|
+
validatedValue: M
|
|
822
723
|
}
|
|
823
|
-
}),
|
|
724
|
+
}), i.notifyPathSubscribers([e, ...p].join("."), {
|
|
824
725
|
type: "VALIDATION_UPDATE"
|
|
825
726
|
}), {
|
|
826
|
-
key:
|
|
827
|
-
path:
|
|
727
|
+
key: A,
|
|
728
|
+
path: p,
|
|
828
729
|
success: I.success,
|
|
829
730
|
data: I.success ? I.data : void 0,
|
|
830
731
|
error: I.success ? void 0 : I.error
|
|
831
732
|
};
|
|
832
733
|
});
|
|
833
|
-
return
|
|
834
|
-
success:
|
|
835
|
-
results:
|
|
734
|
+
return F(e), {
|
|
735
|
+
success: v.every((A) => A.success),
|
|
736
|
+
results: v
|
|
836
737
|
};
|
|
837
738
|
}
|
|
838
|
-
const { value:
|
|
839
|
-
if (!
|
|
840
|
-
return { success: !0, data:
|
|
841
|
-
const y =
|
|
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);
|
|
842
743
|
if (y.success) {
|
|
843
|
-
const
|
|
844
|
-
|
|
845
|
-
...
|
|
744
|
+
const v = i.getShadowMetadata(e, t) || {};
|
|
745
|
+
i.setShadowMetadata(e, t, {
|
|
746
|
+
...v,
|
|
846
747
|
validation: {
|
|
847
748
|
status: "VALID",
|
|
848
749
|
errors: [],
|
|
@@ -850,448 +751,444 @@ function Te(e, a, l, s) {
|
|
|
850
751
|
}
|
|
851
752
|
});
|
|
852
753
|
} else
|
|
853
|
-
(y.error?.issues || y.error?.errors || []).forEach((
|
|
854
|
-
const
|
|
855
|
-
|
|
856
|
-
...
|
|
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,
|
|
857
758
|
validation: {
|
|
858
759
|
status: "INVALID",
|
|
859
760
|
errors: [
|
|
860
761
|
{
|
|
861
762
|
source: "client",
|
|
862
|
-
message:
|
|
763
|
+
message: A.message,
|
|
863
764
|
severity: "error",
|
|
864
|
-
code:
|
|
765
|
+
code: A.code
|
|
865
766
|
}
|
|
866
767
|
],
|
|
867
768
|
lastValidated: Date.now(),
|
|
868
|
-
validatedValue:
|
|
769
|
+
validatedValue: i.getShadowValue(e, p)
|
|
869
770
|
}
|
|
870
771
|
});
|
|
871
772
|
});
|
|
872
|
-
return
|
|
773
|
+
return F(e), y;
|
|
873
774
|
};
|
|
874
|
-
if (
|
|
775
|
+
if (u === "$showValidationErrors")
|
|
875
776
|
return () => {
|
|
876
|
-
const { shadowMeta:
|
|
877
|
-
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) : [];
|
|
878
779
|
};
|
|
879
|
-
if (
|
|
880
|
-
return (
|
|
881
|
-
const
|
|
882
|
-
const y =
|
|
883
|
-
...
|
|
884
|
-
path:
|
|
885
|
-
})),
|
|
886
|
-
(
|
|
887
|
-
),
|
|
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) => ({
|
|
784
|
+
...T,
|
|
785
|
+
path: S
|
|
786
|
+
})), A = v.filter((T) => T.severity === "error"), p = v.filter(
|
|
787
|
+
(T) => T.severity === "warning"
|
|
788
|
+
), M = A.length > 0 ? "error" : p.length > 0 ? "warning" : void 0;
|
|
888
789
|
return {
|
|
889
790
|
status: y?.status || "NOT_VALIDATED",
|
|
890
|
-
severity:
|
|
891
|
-
hasErrors:
|
|
892
|
-
hasWarnings:
|
|
893
|
-
message:
|
|
894
|
-
errors:
|
|
895
|
-
warnings:
|
|
896
|
-
allErrors:
|
|
897
|
-
path:
|
|
898
|
-
getData: () =>
|
|
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)
|
|
899
800
|
};
|
|
900
801
|
};
|
|
901
|
-
return (
|
|
902
|
-
(
|
|
903
|
-
)).map((
|
|
802
|
+
return (n ?? Object.keys(i.getShadowNode(e, t) ?? {}).filter(
|
|
803
|
+
(S) => S !== "_meta"
|
|
804
|
+
)).map((S) => s([...t, S]));
|
|
904
805
|
};
|
|
905
|
-
if (
|
|
806
|
+
if (u === "$getSelected")
|
|
906
807
|
return () => {
|
|
907
|
-
const
|
|
908
|
-
|
|
808
|
+
const n = [e, ...t].join(".");
|
|
809
|
+
Q(e, d, [
|
|
909
810
|
...t,
|
|
910
811
|
"getSelected"
|
|
911
812
|
]);
|
|
912
|
-
const
|
|
913
|
-
if (!
|
|
813
|
+
const i = V.getState().selectedIndicesMap.get(n);
|
|
814
|
+
if (!i)
|
|
914
815
|
return;
|
|
915
|
-
const
|
|
916
|
-
if (!(
|
|
816
|
+
const s = t.join("."), g = o?.arrayViews?.[s], S = i.split(".").pop();
|
|
817
|
+
if (!(g && !g.includes(S) || O(
|
|
917
818
|
e,
|
|
918
|
-
|
|
819
|
+
i.split(".").slice(1)
|
|
919
820
|
) === void 0))
|
|
920
|
-
return
|
|
921
|
-
path:
|
|
821
|
+
return l({
|
|
822
|
+
path: i.split(".").slice(1),
|
|
922
823
|
componentId: d,
|
|
923
824
|
meta: o
|
|
924
825
|
});
|
|
925
826
|
};
|
|
926
|
-
if (
|
|
827
|
+
if (u === "$getSelectedIndex")
|
|
927
828
|
return () => {
|
|
928
|
-
const
|
|
829
|
+
const n = e + "." + t.join(".");
|
|
929
830
|
t.join(".");
|
|
930
|
-
const
|
|
931
|
-
if (!
|
|
831
|
+
const i = V.getState().selectedIndicesMap.get(n);
|
|
832
|
+
if (!i)
|
|
932
833
|
return -1;
|
|
933
|
-
const { keys:
|
|
934
|
-
if (!
|
|
834
|
+
const { keys: s } = U(e, t, o);
|
|
835
|
+
if (!s)
|
|
935
836
|
return -1;
|
|
936
|
-
const
|
|
937
|
-
return
|
|
837
|
+
const g = i.split(".").pop();
|
|
838
|
+
return s.indexOf(g);
|
|
938
839
|
};
|
|
939
|
-
if (
|
|
940
|
-
return
|
|
941
|
-
|
|
840
|
+
if (u === "$clearSelected")
|
|
841
|
+
return Z(e, t), () => {
|
|
842
|
+
qe({
|
|
942
843
|
arrayKey: e + "." + t.join(".")
|
|
943
844
|
});
|
|
944
845
|
};
|
|
945
|
-
if (
|
|
946
|
-
return (
|
|
947
|
-
const { value:
|
|
846
|
+
if (u === "$map")
|
|
847
|
+
return (n) => {
|
|
848
|
+
const { value: i, keys: s } = U(
|
|
948
849
|
e,
|
|
949
850
|
t,
|
|
950
851
|
o
|
|
951
852
|
);
|
|
952
|
-
if (
|
|
853
|
+
if (Q(e, d, t), !s || !Array.isArray(i))
|
|
953
854
|
return [];
|
|
954
|
-
const
|
|
855
|
+
const g = l({
|
|
955
856
|
path: t,
|
|
956
857
|
componentId: d,
|
|
957
858
|
meta: o
|
|
958
859
|
});
|
|
959
|
-
return
|
|
960
|
-
const
|
|
961
|
-
if (!
|
|
962
|
-
const
|
|
963
|
-
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,
|
|
964
865
|
// This now correctly points to the item in the shadow store.
|
|
965
866
|
componentId: d,
|
|
966
867
|
meta: o
|
|
967
868
|
});
|
|
968
|
-
return
|
|
869
|
+
return n(p, y, g);
|
|
969
870
|
});
|
|
970
871
|
};
|
|
971
|
-
if (
|
|
972
|
-
return (
|
|
973
|
-
const
|
|
872
|
+
if (u === "$filter")
|
|
873
|
+
return (n) => {
|
|
874
|
+
const i = t.length > 0 ? t.join(".") : "root", { keys: s, value: g } = U(
|
|
974
875
|
e,
|
|
975
876
|
t,
|
|
976
877
|
o
|
|
977
878
|
);
|
|
978
|
-
if (!Array.isArray(
|
|
879
|
+
if (!Array.isArray(g))
|
|
979
880
|
throw new Error("filter can only be used on arrays");
|
|
980
|
-
const
|
|
981
|
-
return
|
|
982
|
-
if (
|
|
983
|
-
const
|
|
984
|
-
|
|
881
|
+
const S = [];
|
|
882
|
+
return g.forEach((y, v) => {
|
|
883
|
+
if (n(y, v)) {
|
|
884
|
+
const A = s[v];
|
|
885
|
+
A && S.push(A);
|
|
985
886
|
}
|
|
986
|
-
}),
|
|
887
|
+
}), l({
|
|
987
888
|
path: t,
|
|
988
889
|
componentId: d,
|
|
989
890
|
meta: {
|
|
990
891
|
...o,
|
|
991
892
|
arrayViews: {
|
|
992
893
|
...o?.arrayViews || {},
|
|
993
|
-
[
|
|
894
|
+
[i]: S
|
|
994
895
|
},
|
|
995
896
|
transforms: [
|
|
996
897
|
...o?.transforms || [],
|
|
997
|
-
{ type: "filter", fn:
|
|
898
|
+
{ type: "filter", fn: n, path: t }
|
|
998
899
|
]
|
|
999
900
|
}
|
|
1000
901
|
});
|
|
1001
902
|
};
|
|
1002
|
-
if (
|
|
1003
|
-
return (
|
|
1004
|
-
const
|
|
903
|
+
if (u === "$sort")
|
|
904
|
+
return (n) => {
|
|
905
|
+
const i = t.length > 0 ? t.join(".") : "root", { value: s, keys: g } = U(
|
|
1005
906
|
e,
|
|
1006
907
|
t,
|
|
1007
908
|
o
|
|
1008
909
|
);
|
|
1009
|
-
if (!Array.isArray(
|
|
910
|
+
if (!Array.isArray(s) || !g)
|
|
1010
911
|
throw new Error("No array keys found for sorting");
|
|
1011
|
-
const
|
|
1012
|
-
item:
|
|
1013
|
-
key:
|
|
912
|
+
const S = s.map((v, A) => ({
|
|
913
|
+
item: v,
|
|
914
|
+
key: g[A]
|
|
1014
915
|
}));
|
|
1015
|
-
|
|
1016
|
-
const y =
|
|
1017
|
-
return
|
|
916
|
+
S.sort((v, A) => n(v.item, A.item));
|
|
917
|
+
const y = S.map((v) => v.key);
|
|
918
|
+
return l({
|
|
1018
919
|
path: t,
|
|
1019
920
|
componentId: d,
|
|
1020
921
|
meta: {
|
|
1021
922
|
...o,
|
|
1022
923
|
arrayViews: {
|
|
1023
924
|
...o?.arrayViews || {},
|
|
1024
|
-
[
|
|
925
|
+
[i]: y
|
|
1025
926
|
},
|
|
1026
927
|
transforms: [
|
|
1027
928
|
...o?.transforms || [],
|
|
1028
|
-
{ type: "sort", fn:
|
|
929
|
+
{ type: "sort", fn: n, path: t }
|
|
1029
930
|
]
|
|
1030
931
|
}
|
|
1031
932
|
});
|
|
1032
933
|
};
|
|
1033
|
-
if (
|
|
1034
|
-
return (
|
|
1035
|
-
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(() => ({
|
|
1036
937
|
...o,
|
|
1037
938
|
arrayViews: {
|
|
1038
939
|
...o?.arrayViews || {},
|
|
1039
|
-
[y]:
|
|
940
|
+
[y]: v
|
|
1040
941
|
}
|
|
1041
|
-
}), [o, y,
|
|
942
|
+
}), [o, y, v]), { value: p } = U(
|
|
1042
943
|
e,
|
|
1043
944
|
t,
|
|
1044
|
-
|
|
945
|
+
A
|
|
1045
946
|
);
|
|
1046
|
-
if (
|
|
1047
|
-
const
|
|
947
|
+
if (ue(() => {
|
|
948
|
+
const j = V.getState().subscribeToPath(b, (I) => {
|
|
1048
949
|
if (I.type === "GET_SELECTED")
|
|
1049
950
|
return;
|
|
1050
|
-
const
|
|
1051
|
-
if (
|
|
1052
|
-
for (const
|
|
1053
|
-
|
|
1054
|
-
(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({});
|
|
1055
956
|
});
|
|
1056
957
|
return () => {
|
|
1057
|
-
|
|
958
|
+
j();
|
|
1058
959
|
};
|
|
1059
|
-
}, [d,
|
|
960
|
+
}, [d, b]), !Array.isArray(p))
|
|
1060
961
|
return null;
|
|
1061
|
-
const
|
|
962
|
+
const M = l({
|
|
1062
963
|
path: t,
|
|
1063
964
|
componentId: d,
|
|
1064
|
-
meta:
|
|
965
|
+
meta: A
|
|
1065
966
|
// Use updated meta here
|
|
1066
|
-
}),
|
|
1067
|
-
const
|
|
1068
|
-
if (!
|
|
967
|
+
}), T = p.map((j, I) => {
|
|
968
|
+
const L = v[I];
|
|
969
|
+
if (!L)
|
|
1069
970
|
return null;
|
|
1070
|
-
let
|
|
1071
|
-
|
|
1072
|
-
const
|
|
1073
|
-
return
|
|
1074
|
-
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,
|
|
1075
976
|
stateKey: e,
|
|
1076
|
-
itemComponentId:
|
|
1077
|
-
itemPath:
|
|
977
|
+
itemComponentId: B,
|
|
978
|
+
itemPath: X,
|
|
1078
979
|
localIndex: I,
|
|
1079
|
-
arraySetter:
|
|
1080
|
-
rebuildStateShape:
|
|
1081
|
-
renderFn:
|
|
980
|
+
arraySetter: M,
|
|
981
|
+
rebuildStateShape: l,
|
|
982
|
+
renderFn: n
|
|
1082
983
|
});
|
|
1083
984
|
});
|
|
1084
|
-
return /* @__PURE__ */
|
|
985
|
+
return /* @__PURE__ */ H($e, { children: T });
|
|
1085
986
|
}, {});
|
|
1086
|
-
if (
|
|
1087
|
-
return (
|
|
1088
|
-
const
|
|
1089
|
-
return Array.isArray(
|
|
1090
|
-
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],
|
|
1091
992
|
componentId: d,
|
|
1092
993
|
meta: o
|
|
1093
994
|
}) : [];
|
|
1094
995
|
};
|
|
1095
|
-
if (
|
|
1096
|
-
return (
|
|
1097
|
-
const
|
|
1098
|
-
if (
|
|
1099
|
-
const y =
|
|
1100
|
-
return y ?
|
|
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({
|
|
1101
1002
|
path: [...t, y],
|
|
1102
1003
|
componentId: d,
|
|
1103
1004
|
meta: o
|
|
1104
1005
|
}) : void 0;
|
|
1105
1006
|
}
|
|
1106
|
-
const
|
|
1107
|
-
if (!
|
|
1108
|
-
const
|
|
1109
|
-
if (
|
|
1110
|
-
return
|
|
1111
|
-
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],
|
|
1112
1013
|
componentId: d,
|
|
1113
1014
|
meta: o
|
|
1114
1015
|
});
|
|
1115
1016
|
};
|
|
1116
|
-
if (
|
|
1017
|
+
if (u === "$last")
|
|
1117
1018
|
return () => {
|
|
1118
|
-
const { keys:
|
|
1119
|
-
if (!
|
|
1019
|
+
const { keys: n } = U(e, t, o);
|
|
1020
|
+
if (!n || n.length === 0)
|
|
1120
1021
|
return;
|
|
1121
|
-
const
|
|
1122
|
-
if (!
|
|
1022
|
+
const i = n[n.length - 1];
|
|
1023
|
+
if (!i)
|
|
1123
1024
|
return;
|
|
1124
|
-
const
|
|
1125
|
-
return
|
|
1126
|
-
path:
|
|
1025
|
+
const s = [...t, i];
|
|
1026
|
+
return l({
|
|
1027
|
+
path: s,
|
|
1127
1028
|
componentId: d,
|
|
1128
1029
|
meta: o
|
|
1129
1030
|
});
|
|
1130
1031
|
};
|
|
1131
|
-
if (
|
|
1132
|
-
return (
|
|
1133
|
-
|
|
1032
|
+
if (u === "$insert")
|
|
1033
|
+
return (n, i) => {
|
|
1034
|
+
r(n, t, {
|
|
1134
1035
|
updateType: "insert",
|
|
1135
|
-
index:
|
|
1036
|
+
index: i
|
|
1136
1037
|
});
|
|
1137
1038
|
};
|
|
1138
|
-
if (
|
|
1139
|
-
return (
|
|
1140
|
-
|
|
1039
|
+
if (u === "$insertMany")
|
|
1040
|
+
return (n) => {
|
|
1041
|
+
r(n, t, {
|
|
1141
1042
|
updateType: "insert_many"
|
|
1142
1043
|
});
|
|
1143
1044
|
};
|
|
1144
|
-
if (
|
|
1145
|
-
return (
|
|
1146
|
-
const { value:
|
|
1045
|
+
if (u === "$uniqueInsert")
|
|
1046
|
+
return (n, i, s) => {
|
|
1047
|
+
const { value: g } = N(
|
|
1147
1048
|
e,
|
|
1148
1049
|
t,
|
|
1149
1050
|
o
|
|
1150
|
-
),
|
|
1051
|
+
), S = W(n) ? n(g) : n;
|
|
1151
1052
|
let y = null;
|
|
1152
|
-
if (!
|
|
1153
|
-
const
|
|
1154
|
-
(
|
|
1155
|
-
) :
|
|
1156
|
-
return
|
|
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;
|
|
1157
1058
|
}))
|
|
1158
|
-
|
|
1159
|
-
else if (
|
|
1160
|
-
const
|
|
1161
|
-
(
|
|
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
|
|
1162
1063
|
);
|
|
1163
|
-
|
|
1064
|
+
r(p, t, {
|
|
1164
1065
|
updateType: "update"
|
|
1165
1066
|
});
|
|
1166
1067
|
}
|
|
1167
1068
|
};
|
|
1168
|
-
if (
|
|
1169
|
-
return (
|
|
1170
|
-
const
|
|
1171
|
-
if (!
|
|
1069
|
+
if (u === "$cut")
|
|
1070
|
+
return (n, i) => {
|
|
1071
|
+
const s = $(e, t);
|
|
1072
|
+
if (!s?.arrayKeys || s.arrayKeys.length === 0)
|
|
1172
1073
|
return;
|
|
1173
|
-
const
|
|
1174
|
-
|
|
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], {
|
|
1175
1076
|
updateType: "cut"
|
|
1176
1077
|
});
|
|
1177
1078
|
};
|
|
1178
|
-
if (
|
|
1079
|
+
if (u === "$cutSelected")
|
|
1179
1080
|
return () => {
|
|
1180
|
-
const
|
|
1181
|
-
if (!
|
|
1081
|
+
const n = [e, ...t].join("."), { keys: i } = U(e, t, o);
|
|
1082
|
+
if (!i || i.length === 0)
|
|
1182
1083
|
return;
|
|
1183
|
-
const
|
|
1184
|
-
if (!
|
|
1084
|
+
const s = V.getState().selectedIndicesMap.get(n);
|
|
1085
|
+
if (!s)
|
|
1185
1086
|
return;
|
|
1186
|
-
const
|
|
1187
|
-
if (!
|
|
1087
|
+
const g = s.split(".").pop();
|
|
1088
|
+
if (!i.includes(g))
|
|
1188
1089
|
return;
|
|
1189
|
-
const
|
|
1190
|
-
|
|
1191
|
-
const y =
|
|
1192
|
-
|
|
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, {
|
|
1193
1094
|
updateType: "cut"
|
|
1194
1095
|
});
|
|
1195
1096
|
};
|
|
1196
|
-
if (
|
|
1197
|
-
return (
|
|
1097
|
+
if (u === "$cutByValue")
|
|
1098
|
+
return (n) => {
|
|
1198
1099
|
const {
|
|
1199
|
-
isArray:
|
|
1200
|
-
value:
|
|
1201
|
-
keys:
|
|
1202
|
-
} =
|
|
1203
|
-
if (!
|
|
1204
|
-
const
|
|
1205
|
-
|
|
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], {
|
|
1206
1107
|
updateType: "cut"
|
|
1207
1108
|
});
|
|
1208
1109
|
};
|
|
1209
|
-
if (
|
|
1210
|
-
return (
|
|
1110
|
+
if (u === "$toggleByValue")
|
|
1111
|
+
return (n) => {
|
|
1211
1112
|
const {
|
|
1212
|
-
isArray:
|
|
1213
|
-
value:
|
|
1214
|
-
keys:
|
|
1215
|
-
} =
|
|
1216
|
-
if (!
|
|
1217
|
-
const
|
|
1218
|
-
if (
|
|
1219
|
-
const y = [...t,
|
|
1220
|
-
|
|
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, {
|
|
1221
1122
|
updateType: "cut"
|
|
1222
1123
|
});
|
|
1223
1124
|
} else
|
|
1224
|
-
|
|
1125
|
+
r(n, t, { updateType: "insert" });
|
|
1225
1126
|
};
|
|
1226
|
-
if (
|
|
1227
|
-
return (
|
|
1228
|
-
const { isArray:
|
|
1229
|
-
if (!
|
|
1127
|
+
if (u === "$findWith")
|
|
1128
|
+
return (n, i) => {
|
|
1129
|
+
const { isArray: s, value: g, keys: S } = U(e, t, o);
|
|
1130
|
+
if (!s)
|
|
1230
1131
|
throw new Error("findWith can only be used on arrays");
|
|
1231
|
-
const y =
|
|
1132
|
+
const y = ie(
|
|
1133
|
+
g,
|
|
1232
1134
|
S,
|
|
1233
|
-
i
|
|
1234
|
-
(w) => w?.[r] === n
|
|
1135
|
+
(v) => v?.[n] === i
|
|
1235
1136
|
);
|
|
1236
|
-
return y ?
|
|
1137
|
+
return y ? l({
|
|
1237
1138
|
path: [...t, y.key],
|
|
1238
1139
|
componentId: d,
|
|
1239
1140
|
meta: o
|
|
1240
1141
|
}) : null;
|
|
1241
1142
|
};
|
|
1242
|
-
if (
|
|
1243
|
-
const { value:
|
|
1244
|
-
return
|
|
1245
|
-
|
|
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" });
|
|
1246
1147
|
};
|
|
1247
1148
|
}
|
|
1248
|
-
if (
|
|
1149
|
+
if (u === "$get")
|
|
1249
1150
|
return () => {
|
|
1250
|
-
|
|
1251
|
-
const { value:
|
|
1252
|
-
return
|
|
1151
|
+
Q(e, d, t);
|
|
1152
|
+
const { value: n } = N(e, t, o);
|
|
1153
|
+
return n;
|
|
1253
1154
|
};
|
|
1254
|
-
if (
|
|
1255
|
-
return (
|
|
1155
|
+
if (u === "$$derive")
|
|
1156
|
+
return (n) => he({
|
|
1256
1157
|
_stateKey: e,
|
|
1257
1158
|
_path: t,
|
|
1258
|
-
_effect:
|
|
1159
|
+
_effect: n.toString(),
|
|
1259
1160
|
_meta: o
|
|
1260
1161
|
});
|
|
1261
|
-
if (
|
|
1262
|
-
return () =>
|
|
1263
|
-
if (
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
const r = t.slice(0, -1);
|
|
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;
|
|
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;
|
|
1274
1171
|
}
|
|
1275
1172
|
return;
|
|
1276
1173
|
}
|
|
1277
|
-
if (
|
|
1278
|
-
return (
|
|
1279
|
-
const
|
|
1280
|
-
|
|
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);
|
|
1281
1178
|
};
|
|
1282
|
-
if (
|
|
1179
|
+
if (u === "$toggleSelected")
|
|
1283
1180
|
return () => {
|
|
1284
|
-
const
|
|
1285
|
-
|
|
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);
|
|
1286
1183
|
};
|
|
1287
|
-
if (
|
|
1288
|
-
return (
|
|
1289
|
-
const
|
|
1290
|
-
if (console.log("startNode ",
|
|
1291
|
-
const
|
|
1292
|
-
for (console.log("stack ",
|
|
1293
|
-
const [y,
|
|
1294
|
-
if (console.log("while (stack.length ", y,
|
|
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;
|
|
1295
1192
|
if (y._meta?.validation) {
|
|
1296
1193
|
y._meta.validation = {
|
|
1297
1194
|
status: "NOT_VALIDATED",
|
|
@@ -1299,336 +1196,323 @@ function Te(e, a, l, s) {
|
|
|
1299
1196
|
lastValidated: Date.now(),
|
|
1300
1197
|
validatedValue: void 0
|
|
1301
1198
|
};
|
|
1302
|
-
const
|
|
1303
|
-
|
|
1199
|
+
const p = [e, ...v].join(".");
|
|
1200
|
+
s.notifyPathSubscribers(p, {
|
|
1304
1201
|
type: "VALIDATION_CLEAR"
|
|
1305
1202
|
});
|
|
1306
1203
|
}
|
|
1307
|
-
const
|
|
1308
|
-
for (const
|
|
1309
|
-
|
|
1204
|
+
const A = Object.keys(y);
|
|
1205
|
+
for (const p of A)
|
|
1206
|
+
p !== "_meta" && S.push([y[p], [...v, p]]);
|
|
1310
1207
|
}
|
|
1311
|
-
|
|
1208
|
+
F(e);
|
|
1312
1209
|
};
|
|
1313
1210
|
if (t.length == 0) {
|
|
1314
|
-
if (
|
|
1211
|
+
if (u === "$_componentId")
|
|
1315
1212
|
return d;
|
|
1316
|
-
if (
|
|
1317
|
-
return (
|
|
1318
|
-
|
|
1213
|
+
if (u === "$setOptions")
|
|
1214
|
+
return (n) => {
|
|
1215
|
+
ce({ stateKey: e, options: n, initialOptionsPart: {} });
|
|
1319
1216
|
};
|
|
1320
|
-
if (
|
|
1321
|
-
return (
|
|
1322
|
-
|
|
1217
|
+
if (u === "$_applyUpdate")
|
|
1218
|
+
return (n, i, s = "update") => {
|
|
1219
|
+
r(n, i, { updateType: s });
|
|
1323
1220
|
};
|
|
1324
|
-
if (
|
|
1325
|
-
return
|
|
1326
|
-
if (
|
|
1327
|
-
return (
|
|
1328
|
-
if (
|
|
1329
|
-
return (
|
|
1330
|
-
if (
|
|
1331
|
-
return (
|
|
1332
|
-
if (
|
|
1333
|
-
return (
|
|
1334
|
-
const
|
|
1335
|
-
|
|
1336
|
-
const
|
|
1337
|
-
|
|
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, {
|
|
1338
1235
|
...y,
|
|
1339
1236
|
validation: {
|
|
1340
1237
|
status: "INVALID",
|
|
1341
1238
|
errors: [
|
|
1342
1239
|
{
|
|
1343
|
-
source:
|
|
1344
|
-
message:
|
|
1240
|
+
source: i || "client",
|
|
1241
|
+
message: g.message,
|
|
1345
1242
|
severity: "error",
|
|
1346
|
-
code:
|
|
1243
|
+
code: g.code
|
|
1347
1244
|
}
|
|
1348
1245
|
],
|
|
1349
1246
|
lastValidated: Date.now(),
|
|
1350
1247
|
validatedValue: void 0
|
|
1351
1248
|
}
|
|
1352
|
-
}),
|
|
1353
|
-
[e, ...
|
|
1249
|
+
}), s.notifyPathSubscribers(
|
|
1250
|
+
[e, ...S].join("."),
|
|
1354
1251
|
{ type: "VALIDATION_UPDATE" }
|
|
1355
1252
|
);
|
|
1356
|
-
}),
|
|
1253
|
+
}), F(e);
|
|
1357
1254
|
};
|
|
1358
|
-
if (
|
|
1359
|
-
return (
|
|
1360
|
-
const
|
|
1361
|
-
|
|
1362
|
-
const
|
|
1363
|
-
|
|
1364
|
-
...
|
|
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,
|
|
1365
1262
|
validation: {
|
|
1366
1263
|
status: "NOT_VALIDATED",
|
|
1367
1264
|
errors: [],
|
|
1368
1265
|
lastValidated: Date.now(),
|
|
1369
1266
|
validatedValue: void 0
|
|
1370
1267
|
}
|
|
1371
|
-
}),
|
|
1372
|
-
[e, ...
|
|
1268
|
+
}), i.notifyPathSubscribers(
|
|
1269
|
+
[e, ...s].join("."),
|
|
1373
1270
|
{ type: "VALIDATION_CLEAR" }
|
|
1374
1271
|
));
|
|
1375
|
-
}),
|
|
1272
|
+
}), F(e);
|
|
1376
1273
|
};
|
|
1377
|
-
if (
|
|
1378
|
-
return (
|
|
1379
|
-
let
|
|
1380
|
-
if (
|
|
1381
|
-
const
|
|
1382
|
-
if (
|
|
1383
|
-
const
|
|
1384
|
-
|
|
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
|
|
1385
1282
|
);
|
|
1386
|
-
|
|
1283
|
+
S !== -1 && (s = S + 1);
|
|
1387
1284
|
}
|
|
1388
1285
|
}
|
|
1389
|
-
|
|
1390
|
-
updateType:
|
|
1391
|
-
itemId:
|
|
1392
|
-
index:
|
|
1286
|
+
r(n.newValue, n.path, {
|
|
1287
|
+
updateType: n.updateType,
|
|
1288
|
+
itemId: n.itemId,
|
|
1289
|
+
index: s,
|
|
1393
1290
|
// Pass the calculated index
|
|
1394
|
-
metaData:
|
|
1291
|
+
metaData: i
|
|
1395
1292
|
});
|
|
1396
1293
|
};
|
|
1397
|
-
if (
|
|
1398
|
-
return (
|
|
1399
|
-
const
|
|
1400
|
-
if (!
|
|
1401
|
-
const
|
|
1402
|
-
for (const y of
|
|
1403
|
-
const
|
|
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);
|
|
1404
1301
|
switch (y.op) {
|
|
1405
1302
|
case "add":
|
|
1406
1303
|
case "replace": {
|
|
1407
|
-
const { value:
|
|
1408
|
-
|
|
1409
|
-
let
|
|
1304
|
+
const { value: A } = y;
|
|
1305
|
+
i.updateShadowAtPath(e, v, A);
|
|
1306
|
+
let p = [...v];
|
|
1410
1307
|
for (; ; ) {
|
|
1411
|
-
const
|
|
1308
|
+
const M = i.getShadowMetadata(
|
|
1412
1309
|
e,
|
|
1413
|
-
|
|
1310
|
+
p
|
|
1414
1311
|
);
|
|
1415
|
-
if (
|
|
1416
|
-
if (!
|
|
1417
|
-
const
|
|
1418
|
-
|
|
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));
|
|
1419
1316
|
}
|
|
1420
|
-
}),
|
|
1421
|
-
|
|
1317
|
+
}), p.length === 0) break;
|
|
1318
|
+
p.pop();
|
|
1422
1319
|
}
|
|
1423
1320
|
break;
|
|
1424
1321
|
}
|
|
1425
1322
|
case "remove": {
|
|
1426
|
-
const
|
|
1427
|
-
|
|
1428
|
-
let
|
|
1323
|
+
const A = v.slice(0, -1);
|
|
1324
|
+
i.removeShadowArrayElement(e, v);
|
|
1325
|
+
let p = [...A];
|
|
1429
1326
|
for (; ; ) {
|
|
1430
|
-
const
|
|
1327
|
+
const M = i.getShadowMetadata(
|
|
1431
1328
|
e,
|
|
1432
|
-
|
|
1329
|
+
p
|
|
1433
1330
|
);
|
|
1434
|
-
if (
|
|
1435
|
-
if (!
|
|
1436
|
-
const
|
|
1437
|
-
|
|
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));
|
|
1438
1335
|
}
|
|
1439
|
-
}),
|
|
1440
|
-
|
|
1336
|
+
}), p.length === 0) break;
|
|
1337
|
+
p.pop();
|
|
1441
1338
|
}
|
|
1442
1339
|
break;
|
|
1443
1340
|
}
|
|
1444
1341
|
}
|
|
1445
1342
|
}
|
|
1446
1343
|
};
|
|
1447
|
-
if (
|
|
1448
|
-
return () =>
|
|
1344
|
+
if (u === "$getComponents")
|
|
1345
|
+
return () => $(e, [])?.components;
|
|
1449
1346
|
}
|
|
1450
|
-
if (
|
|
1347
|
+
if (u === "$validationWrapper")
|
|
1451
1348
|
return ({
|
|
1452
|
-
children:
|
|
1453
|
-
hideMessage:
|
|
1454
|
-
}) => /* @__PURE__ */
|
|
1455
|
-
|
|
1349
|
+
children: n,
|
|
1350
|
+
hideMessage: i
|
|
1351
|
+
}) => /* @__PURE__ */ H(
|
|
1352
|
+
De,
|
|
1456
1353
|
{
|
|
1457
|
-
formOpts:
|
|
1354
|
+
formOpts: i ? { validation: { message: "" } } : void 0,
|
|
1458
1355
|
path: t,
|
|
1459
1356
|
stateKey: e,
|
|
1460
|
-
children:
|
|
1357
|
+
children: n
|
|
1461
1358
|
}
|
|
1462
1359
|
);
|
|
1463
|
-
if (
|
|
1464
|
-
if (
|
|
1465
|
-
if (
|
|
1466
|
-
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" }), {
|
|
1467
1364
|
synced: () => {
|
|
1468
|
-
const n = M.getState().getShadowMetadata(e, t);
|
|
1469
|
-
B(e, t, {
|
|
1470
|
-
...n,
|
|
1471
|
-
isDirty: !1,
|
|
1472
|
-
stateSource: "server",
|
|
1473
|
-
lastServerSync: Date.now()
|
|
1474
|
-
});
|
|
1475
|
-
const c = [e, ...t].join(".");
|
|
1476
|
-
Qe(c, {
|
|
1477
|
-
type: "SYNC_STATUS_CHANGE",
|
|
1478
|
-
isDirty: !1
|
|
1479
|
-
});
|
|
1480
1365
|
}
|
|
1481
1366
|
});
|
|
1482
|
-
if (
|
|
1483
|
-
const { value:
|
|
1367
|
+
if (u === "$toggle") {
|
|
1368
|
+
const { value: n } = N(
|
|
1484
1369
|
e,
|
|
1485
1370
|
t,
|
|
1486
1371
|
o
|
|
1487
1372
|
);
|
|
1488
|
-
if (typeof
|
|
1373
|
+
if (typeof n != "boolean")
|
|
1489
1374
|
throw new Error("toggle() can only be used on boolean values");
|
|
1490
1375
|
return () => {
|
|
1491
|
-
|
|
1376
|
+
r(!n, t, {
|
|
1492
1377
|
updateType: "update"
|
|
1493
1378
|
});
|
|
1494
1379
|
};
|
|
1495
1380
|
}
|
|
1496
|
-
if (
|
|
1497
|
-
return (
|
|
1498
|
-
const
|
|
1499
|
-
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")
|
|
1500
1385
|
throw new Error(
|
|
1501
1386
|
"CogsState: $isolate requires a render function."
|
|
1502
1387
|
);
|
|
1503
|
-
return /* @__PURE__ */
|
|
1504
|
-
|
|
1388
|
+
return /* @__PURE__ */ H(
|
|
1389
|
+
Ce,
|
|
1505
1390
|
{
|
|
1506
1391
|
stateKey: e,
|
|
1507
1392
|
path: t,
|
|
1508
|
-
dependencies:
|
|
1509
|
-
rebuildStateShape:
|
|
1510
|
-
renderFn:
|
|
1393
|
+
dependencies: g,
|
|
1394
|
+
rebuildStateShape: l,
|
|
1395
|
+
renderFn: S
|
|
1511
1396
|
}
|
|
1512
1397
|
);
|
|
1513
1398
|
};
|
|
1514
|
-
if (
|
|
1515
|
-
return (
|
|
1516
|
-
|
|
1399
|
+
if (u === "$formElement")
|
|
1400
|
+
return (n, i) => /* @__PURE__ */ H(
|
|
1401
|
+
Oe,
|
|
1517
1402
|
{
|
|
1518
1403
|
stateKey: e,
|
|
1519
1404
|
path: t,
|
|
1520
|
-
rebuildStateShape:
|
|
1521
|
-
setState:
|
|
1522
|
-
formOpts:
|
|
1523
|
-
renderFn:
|
|
1405
|
+
rebuildStateShape: l,
|
|
1406
|
+
setState: r,
|
|
1407
|
+
formOpts: i,
|
|
1408
|
+
renderFn: n
|
|
1524
1409
|
}
|
|
1525
1410
|
);
|
|
1526
|
-
const C = [...t,
|
|
1527
|
-
return
|
|
1411
|
+
const C = [...t, u];
|
|
1412
|
+
return l({
|
|
1528
1413
|
path: C,
|
|
1529
1414
|
componentId: d,
|
|
1530
1415
|
meta: o
|
|
1531
1416
|
});
|
|
1532
1417
|
}
|
|
1533
|
-
},
|
|
1534
|
-
return f.set(
|
|
1418
|
+
}, q = new Proxy(D, k);
|
|
1419
|
+
return f.set(w, q), q;
|
|
1535
1420
|
}
|
|
1536
1421
|
const h = {
|
|
1537
1422
|
$revertToInitialState: (t) => {
|
|
1538
|
-
const o =
|
|
1539
|
-
|
|
1540
|
-
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({
|
|
1541
1425
|
path: [],
|
|
1542
|
-
componentId:
|
|
1426
|
+
componentId: c
|
|
1543
1427
|
});
|
|
1544
|
-
const
|
|
1545
|
-
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;
|
|
1546
1430
|
},
|
|
1547
1431
|
$initializeAndMergeShadowState: (t) => {
|
|
1548
|
-
|
|
1432
|
+
Fe(e, t), F(e);
|
|
1549
1433
|
},
|
|
1550
1434
|
$updateInitialState: (t) => {
|
|
1551
|
-
const o =
|
|
1435
|
+
const o = Pe(
|
|
1552
1436
|
e,
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
), d =
|
|
1557
|
-
return
|
|
1558
|
-
|
|
1559
|
-
const
|
|
1560
|
-
|
|
1561
|
-
|
|
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();
|
|
1562
1446
|
});
|
|
1563
1447
|
}), {
|
|
1564
|
-
fetchId: (
|
|
1448
|
+
fetchId: (b) => o.$get()[b]
|
|
1565
1449
|
};
|
|
1566
1450
|
}
|
|
1567
1451
|
};
|
|
1568
|
-
return
|
|
1569
|
-
componentId:
|
|
1452
|
+
return l({
|
|
1453
|
+
componentId: c,
|
|
1570
1454
|
path: []
|
|
1571
1455
|
});
|
|
1572
1456
|
}
|
|
1573
|
-
function
|
|
1574
|
-
return
|
|
1457
|
+
function he(e) {
|
|
1458
|
+
return de(ut, { proxy: e });
|
|
1575
1459
|
}
|
|
1576
|
-
function
|
|
1460
|
+
function ut({
|
|
1577
1461
|
proxy: e
|
|
1578
1462
|
}) {
|
|
1579
|
-
const
|
|
1580
|
-
return
|
|
1581
|
-
const t =
|
|
1582
|
-
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;
|
|
1583
1467
|
const o = setTimeout(() => {
|
|
1584
1468
|
if (!t.parentElement) {
|
|
1585
1469
|
console.warn("Parent element not found for signal", f);
|
|
1586
1470
|
return;
|
|
1587
1471
|
}
|
|
1588
|
-
const d = t.parentElement,
|
|
1589
|
-
let
|
|
1590
|
-
|
|
1591
|
-
const
|
|
1592
|
-
|
|
1593
|
-
instanceId:
|
|
1594
|
-
parentId:
|
|
1595
|
-
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,
|
|
1596
1480
|
effect: e._effect
|
|
1597
|
-
}),
|
|
1598
|
-
...
|
|
1599
|
-
signals:
|
|
1481
|
+
}), V.getState().setShadowMetadata(e._stateKey, e._path, {
|
|
1482
|
+
...b,
|
|
1483
|
+
signals: D
|
|
1600
1484
|
});
|
|
1601
|
-
let
|
|
1485
|
+
let k = m;
|
|
1602
1486
|
if (e._effect)
|
|
1603
1487
|
try {
|
|
1604
|
-
|
|
1488
|
+
k = new Function(
|
|
1605
1489
|
"state",
|
|
1606
1490
|
`return (${e._effect})(state)`
|
|
1607
1491
|
)(m);
|
|
1608
|
-
} catch (
|
|
1609
|
-
console.error("Error evaluating effect function:",
|
|
1492
|
+
} catch (x) {
|
|
1493
|
+
console.error("Error evaluating effect function:", x);
|
|
1610
1494
|
}
|
|
1611
|
-
|
|
1612
|
-
const
|
|
1613
|
-
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;
|
|
1614
1498
|
}, 0);
|
|
1615
1499
|
return () => {
|
|
1616
|
-
if (clearTimeout(o),
|
|
1617
|
-
const d =
|
|
1500
|
+
if (clearTimeout(o), c.current) {
|
|
1501
|
+
const d = V.getState().getShadowMetadata(e._stateKey, e._path) || {};
|
|
1618
1502
|
d.signals && (d.signals = d.signals.filter(
|
|
1619
|
-
(
|
|
1620
|
-
),
|
|
1503
|
+
(P) => P.instanceId !== c.current
|
|
1504
|
+
), V.getState().setShadowMetadata(e._stateKey, e._path, d));
|
|
1621
1505
|
}
|
|
1622
1506
|
};
|
|
1623
|
-
}, []),
|
|
1624
|
-
ref:
|
|
1507
|
+
}, []), de("span", {
|
|
1508
|
+
ref: r,
|
|
1625
1509
|
style: { display: "contents" },
|
|
1626
1510
|
"data-signal-id": f
|
|
1627
1511
|
});
|
|
1628
1512
|
}
|
|
1629
1513
|
export {
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1514
|
+
he as $cogsSignal,
|
|
1515
|
+
Mt as createCogsState,
|
|
1516
|
+
at as useCogsStateFn
|
|
1633
1517
|
};
|
|
1634
1518
|
//# sourceMappingURL=CogsState.js.map
|