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