cogsbox-state 0.5.483 → 0.5.484
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.map +1 -1
- package/dist/CogsState.js +360 -363
- package/dist/CogsState.js.map +1 -1
- package/dist/Components.d.ts.map +1 -1
- package/dist/Components.js +202 -201
- 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/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 +31 -27
- package/src/Components.tsx +13 -6
- package/src/PluginRunner.tsx +2 -1
- package/src/store.ts +24 -7
package/dist/CogsState.js
CHANGED
|
@@ -1,128 +1,120 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as Q, Fragment as
|
|
3
|
-
import { pluginStore as
|
|
4
|
-
import { useState as
|
|
5
|
-
import { transformStateFunc as De, isFunction as
|
|
6
|
-
import { ValidationWrapper as Oe, IsolatedComponentWrapper as je, FormElementWrapper as
|
|
2
|
+
import { jsx as Q, Fragment as Te } from "react/jsx-runtime";
|
|
3
|
+
import { pluginStore as z } from "./pluginStore.js";
|
|
4
|
+
import { useState as ne, useRef as q, useCallback as ke, useEffect as Z, useLayoutEffect as re, useMemo as Ae, createElement as Se, startTransition as Ie } from "react";
|
|
5
|
+
import { transformStateFunc as De, isFunction as R, isDeepEqual as X, isArray as Ce, getDifferences as _e } from "./utility.js";
|
|
6
|
+
import { ValidationWrapper as Oe, IsolatedComponentWrapper as je, FormElementWrapper as Ue, MemoizedCogsItemWrapper as Ne } 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:
|
|
13
|
+
getInitialOptions: j,
|
|
14
|
+
updateInitialStateGlobal: be,
|
|
15
15
|
getShadowMetadata: $,
|
|
16
16
|
setShadowMetadata: L,
|
|
17
|
-
getShadowValue:
|
|
18
|
-
initializeShadowState:
|
|
19
|
-
initializeAndMergeShadowState:
|
|
17
|
+
getShadowValue: C,
|
|
18
|
+
initializeShadowState: K,
|
|
19
|
+
initializeAndMergeShadowState: Re,
|
|
20
20
|
updateShadowAtPath: Le,
|
|
21
21
|
insertShadowArrayElement: We,
|
|
22
|
-
insertManyShadowArrayElements:
|
|
22
|
+
insertManyShadowArrayElements: $e,
|
|
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:
|
|
36
|
-
} = p.getState(), { notifyUpdate: Ye } =
|
|
37
|
-
function N(e, n,
|
|
33
|
+
getPluginMetaDataMap: he,
|
|
34
|
+
setPluginMetaData: ve,
|
|
35
|
+
removePluginMetaData: we
|
|
36
|
+
} = p.getState(), { notifyUpdate: Ye } = z.getState();
|
|
37
|
+
function N(e, n, c) {
|
|
38
38
|
const i = $(e, n);
|
|
39
39
|
if (!!!i?.arrayKeys)
|
|
40
40
|
return { isArray: !1, value: p.getState().getShadowValue(e, n), keys: [] };
|
|
41
|
-
const
|
|
41
|
+
const l = n.length > 0 ? n.join(".") : "root", m = c?.arrayViews?.[l] ?? i.arrayKeys;
|
|
42
42
|
return Array.isArray(m) && m.length === 0 ? { isArray: !0, value: [], keys: [] } : { isArray: !0, value: p.getState().getShadowValue(e, n, m), keys: m ?? [] };
|
|
43
43
|
}
|
|
44
|
-
function
|
|
44
|
+
function le(e, n, c) {
|
|
45
45
|
for (let i = 0; i < e.length; i++)
|
|
46
|
-
if (
|
|
46
|
+
if (c(e[i], i)) {
|
|
47
47
|
const f = n[i];
|
|
48
48
|
if (f)
|
|
49
49
|
return { key: f, index: i, value: e[i] };
|
|
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
|
-
initialOptionsPart:
|
|
63
|
+
initialOptionsPart: c
|
|
64
64
|
}) {
|
|
65
|
-
const i =
|
|
66
|
-
let
|
|
65
|
+
const i = j(e) || {}, f = c[e] || {};
|
|
66
|
+
let l = { ...f, ...i }, m = !1;
|
|
67
67
|
if (n) {
|
|
68
68
|
const y = (t, a) => {
|
|
69
69
|
for (const d in a)
|
|
70
|
-
a.hasOwnProperty(d) && (a[d] instanceof Object && !Array.isArray(a[d]) && t[d] instanceof Object ?
|
|
70
|
+
a.hasOwnProperty(d) && (a[d] instanceof Object && !Array.isArray(a[d]) && t[d] instanceof Object ? X(t[d], a[d]) || (y(t[d], a[d]), m = !0) : t[d] !== a[d] && (t[d] = a[d], m = !0));
|
|
71
71
|
return t;
|
|
72
72
|
};
|
|
73
|
-
|
|
73
|
+
l = y(l, 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 (l.validation && (n?.validation?.hasOwnProperty("onBlur") || i?.validation?.hasOwnProperty("onBlur") || f?.validation?.hasOwnProperty("onBlur") || (l.validation.onBlur = "error", m = !0)), m) {
|
|
76
|
+
ye(e, l);
|
|
77
|
+
const y = l.validation?.zodSchemaV4, t = l.validation?.zodSchemaV3;
|
|
78
|
+
(y !== i?.validation?.zodSchemaV4 || t !== i?.validation?.zodSchemaV3) && (y || t) && (y ? H(e, y, "zod4") : t && H(e, t, "zod3"), W(e));
|
|
87
79
|
}
|
|
88
|
-
return
|
|
80
|
+
return l;
|
|
89
81
|
}
|
|
90
82
|
const $t = (e, n) => {
|
|
91
|
-
n?.plugins &&
|
|
92
|
-
const
|
|
83
|
+
n?.plugins && z.getState().setRegisteredPlugins(n.plugins);
|
|
84
|
+
const c = {};
|
|
93
85
|
if (n?.plugins)
|
|
94
86
|
for (const a of n.plugins)
|
|
95
|
-
typeof a.initialState == "function" && Object.assign(
|
|
96
|
-
const i = { ...
|
|
87
|
+
typeof a.initialState == "function" && Object.assign(c, a.initialState());
|
|
88
|
+
const i = { ...c, ...e }, [f, l] = De(i);
|
|
97
89
|
Object.keys(f).forEach((a) => {
|
|
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
|
|
104
|
-
...
|
|
95
|
+
const V = j(a), b = V ? {
|
|
96
|
+
...V,
|
|
105
97
|
formElements: n?.formElements,
|
|
106
98
|
validation: {
|
|
107
|
-
...
|
|
99
|
+
...V.validation,
|
|
108
100
|
...d.validation
|
|
109
101
|
}
|
|
110
102
|
} : d;
|
|
111
|
-
Object.keys(b).length > 0 &&
|
|
103
|
+
Object.keys(b).length > 0 && ye(a, b);
|
|
112
104
|
}), Object.keys(f).forEach((a) => {
|
|
113
|
-
|
|
105
|
+
K(a, f[a]);
|
|
114
106
|
});
|
|
115
107
|
const m = (a, d) => {
|
|
116
|
-
const [
|
|
108
|
+
const [V] = ne(d?.componentId ?? ae()), b = fe({
|
|
117
109
|
stateKey: a,
|
|
118
110
|
options: d,
|
|
119
|
-
initialOptionsPart:
|
|
120
|
-
}),
|
|
121
|
-
|
|
122
|
-
const v =
|
|
111
|
+
initialOptionsPart: l
|
|
112
|
+
}), E = q(b);
|
|
113
|
+
E.current = b;
|
|
114
|
+
const v = C(a, []) || f[a], _ = ct(v, {
|
|
123
115
|
stateKey: a,
|
|
124
116
|
syncUpdate: d?.syncUpdate,
|
|
125
|
-
componentId:
|
|
117
|
+
componentId: V,
|
|
126
118
|
localStorage: d?.localStorage,
|
|
127
119
|
middleware: d?.middleware,
|
|
128
120
|
reactiveType: d?.reactiveType,
|
|
@@ -131,25 +123,28 @@ const $t = (e, n) => {
|
|
|
131
123
|
dependencies: d?.dependencies,
|
|
132
124
|
serverState: d?.serverState
|
|
133
125
|
});
|
|
134
|
-
return
|
|
135
|
-
d &&
|
|
136
|
-
}, [a, d]),
|
|
137
|
-
|
|
138
|
-
}), [a,
|
|
126
|
+
return re(() => {
|
|
127
|
+
d && z.getState().setPluginOptionsForState(a, d);
|
|
128
|
+
}, [a, d]), re(() => (z.getState().registerStateHandler(a, _), () => {
|
|
129
|
+
z.getState().unregisterStateHandler(a);
|
|
130
|
+
}), [a, _]), re(() => {
|
|
131
|
+
const T = j(a)?.validation;
|
|
132
|
+
T?.zodSchemaV4 ? H(a, T.zodSchemaV4, "zod4") : T?.zodSchemaV3 && H(a, T.zodSchemaV3, "zod3");
|
|
133
|
+
}), _;
|
|
139
134
|
};
|
|
140
135
|
function y(a, d) {
|
|
141
|
-
if (
|
|
142
|
-
const b =
|
|
143
|
-
...
|
|
144
|
-
formWrapper: d.formElements[
|
|
145
|
-
} :
|
|
146
|
-
|
|
136
|
+
if (fe({ stateKey: a, options: d, initialOptionsPart: l }), d.localStorage && Xe(a, d), d.formElements) {
|
|
137
|
+
const b = z.getState().registeredPlugins.map((E) => d.formElements.hasOwnProperty(E.name) ? {
|
|
138
|
+
...E,
|
|
139
|
+
formWrapper: d.formElements[E.name]
|
|
140
|
+
} : E);
|
|
141
|
+
z.getState().setRegisteredPlugins(b);
|
|
147
142
|
}
|
|
148
143
|
W(a);
|
|
149
144
|
}
|
|
150
145
|
function t(a) {
|
|
151
|
-
Object.keys(f).forEach((
|
|
152
|
-
y(
|
|
146
|
+
Object.keys(f).forEach((V) => {
|
|
147
|
+
y(V, a);
|
|
153
148
|
});
|
|
154
149
|
}
|
|
155
150
|
return {
|
|
@@ -157,19 +152,19 @@ const $t = (e, n) => {
|
|
|
157
152
|
setCogsOptionsByKey: y,
|
|
158
153
|
setCogsOptions: t
|
|
159
154
|
};
|
|
160
|
-
}, Ze = (e, n,
|
|
161
|
-
|
|
155
|
+
}, Ze = (e, n, c, i, f) => {
|
|
156
|
+
c?.log && console.log(
|
|
162
157
|
"saving to localstorage",
|
|
163
158
|
n,
|
|
164
|
-
|
|
159
|
+
c.localStorage?.key,
|
|
165
160
|
i
|
|
166
161
|
);
|
|
167
|
-
const
|
|
168
|
-
if (
|
|
169
|
-
const m = `${i}-${n}-${
|
|
162
|
+
const l = R(c?.localStorage?.key) ? c.localStorage?.key(e) : c?.localStorage?.key;
|
|
163
|
+
if (l && i) {
|
|
164
|
+
const m = `${i}-${n}-${l}`;
|
|
170
165
|
let y;
|
|
171
166
|
try {
|
|
172
|
-
y =
|
|
167
|
+
y = ce(m)?.lastSyncedWithServer;
|
|
173
168
|
} catch {
|
|
174
169
|
}
|
|
175
170
|
const t = $(n, []), a = {
|
|
@@ -184,7 +179,7 @@ const $t = (e, n) => {
|
|
|
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,59 +195,59 @@ const $t = (e, n) => {
|
|
|
200
195
|
console.error("Error removing from localStorage:", n);
|
|
201
196
|
}
|
|
202
197
|
}, Xe = (e, n) => {
|
|
203
|
-
const
|
|
198
|
+
const c = C(e, []), { sessionId: i } = Me(), f = R(n?.localStorage?.key) ? n.localStorage.key(c) : n?.localStorage?.key;
|
|
204
199
|
if (f && i) {
|
|
205
|
-
const
|
|
200
|
+
const l = ce(
|
|
206
201
|
`${i}-${e}-${f}`
|
|
207
202
|
);
|
|
208
|
-
if (
|
|
203
|
+
if (l && l.lastUpdated > (l.lastSyncedWithServer || 0))
|
|
209
204
|
return W(e), !0;
|
|
210
205
|
}
|
|
211
206
|
return !1;
|
|
212
207
|
}, W = (e) => {
|
|
213
208
|
const n = $(e, []);
|
|
214
209
|
if (!n) return;
|
|
215
|
-
const
|
|
210
|
+
const c = /* @__PURE__ */ new Set();
|
|
216
211
|
n?.components?.forEach((i) => {
|
|
217
|
-
(i ? Array.isArray(i.reactiveType) ? i.reactiveType : [i.reactiveType || "component"] : null)?.includes("none") ||
|
|
212
|
+
(i ? Array.isArray(i.reactiveType) ? i.reactiveType : [i.reactiveType || "component"] : null)?.includes("none") || c.add(() => i.forceUpdate());
|
|
218
213
|
}), queueMicrotask(() => {
|
|
219
|
-
|
|
214
|
+
c.forEach((i) => i());
|
|
220
215
|
});
|
|
221
216
|
};
|
|
222
|
-
function
|
|
217
|
+
function oe(e, n, c, i) {
|
|
223
218
|
const f = $(e, n);
|
|
224
219
|
if (L(e, n, {
|
|
225
220
|
...f,
|
|
226
221
|
isDirty: !1,
|
|
227
222
|
stateSource: "server",
|
|
228
223
|
lastServerSync: i || Date.now()
|
|
229
|
-
}), Array.isArray(
|
|
230
|
-
const
|
|
231
|
-
|
|
232
|
-
const t = [...n, m], a =
|
|
233
|
-
a !== void 0 &&
|
|
224
|
+
}), Array.isArray(c)) {
|
|
225
|
+
const l = $(e, n);
|
|
226
|
+
l?.arrayKeys && l.arrayKeys.forEach((m, y) => {
|
|
227
|
+
const t = [...n, m], a = c[y];
|
|
228
|
+
a !== void 0 && oe(
|
|
234
229
|
e,
|
|
235
230
|
t,
|
|
236
231
|
a,
|
|
237
232
|
i
|
|
238
233
|
);
|
|
239
234
|
});
|
|
240
|
-
} else
|
|
241
|
-
const m = [...n,
|
|
242
|
-
|
|
235
|
+
} else c && typeof c == "object" && c.constructor === Object && Object.keys(c).forEach((l) => {
|
|
236
|
+
const m = [...n, l], y = c[l];
|
|
237
|
+
oe(e, m, 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
|
-
e?.signals?.length && e.signals.forEach(({ parentId:
|
|
253
|
-
const
|
|
254
|
-
if (!
|
|
255
|
-
const m = Array.from(
|
|
247
|
+
e?.signals?.length && e.signals.forEach(({ parentId: c, position: i, effect: f }) => {
|
|
248
|
+
const l = document.querySelector(`[data-parent-id="${c}"]`);
|
|
249
|
+
if (!l) return;
|
|
250
|
+
const m = Array.from(l.childNodes);
|
|
256
251
|
if (!m[i]) return;
|
|
257
252
|
let y = n;
|
|
258
253
|
if (f && n !== null)
|
|
@@ -266,30 +261,30 @@ function et(e, n) {
|
|
|
266
261
|
y !== null && typeof y == "object" && (y = JSON.stringify(y)), m[i].textContent = String(y ?? "");
|
|
267
262
|
});
|
|
268
263
|
}
|
|
269
|
-
function tt(e, n,
|
|
264
|
+
function tt(e, n, c) {
|
|
270
265
|
const i = $(e, []);
|
|
271
266
|
if (!i?.components)
|
|
272
267
|
return /* @__PURE__ */ new Set();
|
|
273
268
|
const f = /* @__PURE__ */ new Set();
|
|
274
|
-
if (
|
|
275
|
-
let
|
|
269
|
+
if (c.type === "update") {
|
|
270
|
+
let l = [...n];
|
|
276
271
|
for (; ; ) {
|
|
277
|
-
const m = $(e,
|
|
272
|
+
const m = $(e, l);
|
|
278
273
|
if (m?.pathComponents && m.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
|
+
}), l.length === 0) break;
|
|
277
|
+
l.pop();
|
|
283
278
|
}
|
|
284
|
-
|
|
279
|
+
c.newValue && typeof c.newValue == "object" && !Ce(c.newValue) && _e(c.newValue, c.oldValue).forEach((y) => {
|
|
285
280
|
const t = y.split("."), a = [...n, ...t], d = $(e, a);
|
|
286
|
-
d?.pathComponents && d.pathComponents.forEach((
|
|
287
|
-
const b = i.components?.get(
|
|
281
|
+
d?.pathComponents && d.pathComponents.forEach((V) => {
|
|
282
|
+
const b = i.components?.get(V);
|
|
288
283
|
b && ((Array.isArray(b.reactiveType) ? b.reactiveType : [b.reactiveType || "component"]).includes("none") || f.add(b));
|
|
289
284
|
});
|
|
290
285
|
});
|
|
291
|
-
} else if (
|
|
292
|
-
let m = [...
|
|
286
|
+
} else if (c.type === "insert" || c.type === "cut" || c.type === "insert_many") {
|
|
287
|
+
let m = [...c.type === "insert" ? n : n.slice(0, -1)];
|
|
293
288
|
for (; ; ) {
|
|
294
289
|
const y = $(e, m);
|
|
295
290
|
if (y?.pathComponents && y.pathComponents.forEach((t) => {
|
|
@@ -301,49 +296,49 @@ function tt(e, n, l) {
|
|
|
301
296
|
}
|
|
302
297
|
return f;
|
|
303
298
|
}
|
|
304
|
-
function rt(e, n,
|
|
305
|
-
const i = p.getState().getShadowValue(e, n), f =
|
|
306
|
-
if (
|
|
299
|
+
function rt(e, n, c) {
|
|
300
|
+
const i = p.getState().getShadowValue(e, n), f = R(c) ? c(i) : c;
|
|
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 l = $(e, n);
|
|
310
305
|
return {
|
|
311
306
|
type: "update",
|
|
312
307
|
oldValue: i,
|
|
313
308
|
newValue: f,
|
|
314
|
-
shadowMeta:
|
|
309
|
+
shadowMeta: l
|
|
315
310
|
};
|
|
316
311
|
}
|
|
317
|
-
function nt(e, n,
|
|
318
|
-
|
|
312
|
+
function nt(e, n, c) {
|
|
313
|
+
$e(e, n, c), se(e, n, { bubble: !0 });
|
|
319
314
|
const i = $(e, n);
|
|
320
315
|
return {
|
|
321
316
|
type: "insert_many",
|
|
322
|
-
count:
|
|
317
|
+
count: c.length,
|
|
323
318
|
shadowMeta: i,
|
|
324
319
|
path: n
|
|
325
320
|
};
|
|
326
321
|
}
|
|
327
|
-
function at(e, n,
|
|
328
|
-
let
|
|
329
|
-
if (
|
|
330
|
-
const { value: a } =
|
|
331
|
-
|
|
322
|
+
function at(e, n, c, i, f) {
|
|
323
|
+
let l;
|
|
324
|
+
if (R(c)) {
|
|
325
|
+
const { value: a } = U(e, n);
|
|
326
|
+
l = c({ state: a });
|
|
332
327
|
} else
|
|
333
|
-
|
|
328
|
+
l = c;
|
|
334
329
|
const m = We(
|
|
335
330
|
e,
|
|
336
331
|
n,
|
|
337
|
-
|
|
332
|
+
l,
|
|
338
333
|
i,
|
|
339
334
|
f
|
|
340
335
|
);
|
|
341
|
-
|
|
336
|
+
se(e, n, { bubble: !0 });
|
|
342
337
|
const y = $(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: l,
|
|
347
342
|
shadowMeta: y,
|
|
348
343
|
path: n,
|
|
349
344
|
itemId: m,
|
|
@@ -351,18 +346,18 @@ function at(e, n, l, i, f) {
|
|
|
351
346
|
};
|
|
352
347
|
}
|
|
353
348
|
function ot(e, n) {
|
|
354
|
-
const
|
|
355
|
-
return Be(e, n),
|
|
349
|
+
const c = n.slice(0, -1), i = C(e, n);
|
|
350
|
+
return Be(e, n), se(e, c, { bubble: !0 }), { type: "cut", oldValue: i, parentPath: c };
|
|
356
351
|
}
|
|
357
352
|
function it() {
|
|
358
|
-
const e = /* @__PURE__ */ new Set(), n = [],
|
|
359
|
-
for (const i of
|
|
353
|
+
const e = /* @__PURE__ */ new Set(), n = [], c = [];
|
|
354
|
+
for (const i of ie) {
|
|
360
355
|
if (i.status && i.updateType) {
|
|
361
|
-
|
|
356
|
+
c.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, l = f.type === "cut" ? null : f.newValue;
|
|
360
|
+
f.shadowMeta?.signals?.length > 0 && n.push({ shadowMeta: f.shadowMeta, displayValue: l }), tt(
|
|
366
361
|
f.stateKey,
|
|
367
362
|
f.path,
|
|
368
363
|
f
|
|
@@ -370,45 +365,45 @@ function it() {
|
|
|
370
365
|
e.add(y);
|
|
371
366
|
});
|
|
372
367
|
}
|
|
373
|
-
|
|
368
|
+
c.length > 0 && xe(c), n.forEach(({ shadowMeta: i, displayValue: f }) => {
|
|
374
369
|
et(i, f);
|
|
375
370
|
}), e.forEach((i) => {
|
|
376
371
|
i.forceUpdate();
|
|
377
|
-
}),
|
|
372
|
+
}), ie = [], ge = !1;
|
|
378
373
|
}
|
|
379
|
-
function st(e, n,
|
|
380
|
-
return (f,
|
|
381
|
-
i(e,
|
|
374
|
+
function st(e, n, c) {
|
|
375
|
+
return (f, l, m) => {
|
|
376
|
+
i(e, l, f, m);
|
|
382
377
|
};
|
|
383
|
-
function i(f,
|
|
378
|
+
function i(f, l, m, y) {
|
|
384
379
|
let t;
|
|
385
380
|
switch (y.updateType) {
|
|
386
381
|
case "update":
|
|
387
|
-
t = rt(f,
|
|
382
|
+
t = rt(f, l, m);
|
|
388
383
|
break;
|
|
389
384
|
case "insert":
|
|
390
385
|
t = at(
|
|
391
386
|
f,
|
|
392
|
-
|
|
387
|
+
l,
|
|
393
388
|
m,
|
|
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, l, m);
|
|
400
395
|
break;
|
|
401
396
|
case "cut":
|
|
402
|
-
t = ot(f,
|
|
397
|
+
t = ot(f, l);
|
|
403
398
|
break;
|
|
404
399
|
}
|
|
405
400
|
if (t === null)
|
|
406
401
|
return;
|
|
407
|
-
t.stateKey = f, t.path =
|
|
402
|
+
t.stateKey = f, t.path = l, ie.push(t), Ke();
|
|
408
403
|
const a = {
|
|
409
404
|
timeStamp: Date.now(),
|
|
410
405
|
stateKey: f,
|
|
411
|
-
path:
|
|
406
|
+
path: l,
|
|
412
407
|
updateType: y.updateType,
|
|
413
408
|
status: "new",
|
|
414
409
|
oldValue: t.oldValue,
|
|
@@ -417,34 +412,34 @@ function st(e, n, l) {
|
|
|
417
412
|
insertAfterId: t.insertAfterId,
|
|
418
413
|
metaData: y.metaData
|
|
419
414
|
};
|
|
420
|
-
|
|
415
|
+
ie.push(a), t.newValue !== void 0 && Ze(
|
|
421
416
|
t.newValue,
|
|
422
417
|
f,
|
|
423
|
-
|
|
418
|
+
c.current,
|
|
424
419
|
n
|
|
425
|
-
),
|
|
420
|
+
), c.current?.middleware && c.current.middleware({ update: a }), ze(a, y.validationTrigger || "programmatic"), Ye(a);
|
|
426
421
|
}
|
|
427
422
|
}
|
|
428
423
|
function ct(e, {
|
|
429
424
|
stateKey: n,
|
|
430
|
-
localStorage:
|
|
425
|
+
localStorage: c,
|
|
431
426
|
formElements: i,
|
|
432
427
|
reactiveDeps: f,
|
|
433
|
-
reactiveType:
|
|
428
|
+
reactiveType: l,
|
|
434
429
|
componentId: m,
|
|
435
430
|
defaultState: y,
|
|
436
431
|
dependencies: t,
|
|
437
432
|
serverState: a
|
|
438
433
|
} = {}) {
|
|
439
|
-
const [d,
|
|
440
|
-
let
|
|
441
|
-
const [v] =
|
|
434
|
+
const [d, V] = ne({}), { sessionId: b } = Me();
|
|
435
|
+
let E = !n;
|
|
436
|
+
const [v] = ne(n ?? ae()), _ = q(m ?? ae()), T = q(
|
|
442
437
|
null
|
|
443
438
|
);
|
|
444
|
-
|
|
445
|
-
const
|
|
446
|
-
(
|
|
447
|
-
const r =
|
|
439
|
+
T.current = j(v) ?? null;
|
|
440
|
+
const x = ke(
|
|
441
|
+
(k) => {
|
|
442
|
+
const r = k ? { ...j(v), ...k } : j(v), o = 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,7 +447,7 @@ 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 = R(r.localStorage.key) ? r.localStorage.key(o) : r.localStorage.key, u = ce(
|
|
456
451
|
`${b}-${v}-${S}`
|
|
457
452
|
);
|
|
458
453
|
if (u && u.lastUpdated > (r?.serverState?.timestamp || 0))
|
|
@@ -470,15 +465,15 @@ function ct(e, {
|
|
|
470
465
|
},
|
|
471
466
|
[v, y, e, b]
|
|
472
467
|
);
|
|
473
|
-
|
|
474
|
-
a && a.status === "success" && a.data !== void 0 &&
|
|
475
|
-
}, [a, v]),
|
|
476
|
-
if (
|
|
477
|
-
const r =
|
|
468
|
+
Z(() => {
|
|
469
|
+
a && a.status === "success" && a.data !== void 0 && me(v, a);
|
|
470
|
+
}, [a, v]), Z(() => p.getState().subscribeToPath(v, (I) => {
|
|
471
|
+
if (I?.type === "SERVER_STATE_UPDATE") {
|
|
472
|
+
const r = I.serverState;
|
|
478
473
|
if (r?.status !== "success" || r.data === void 0)
|
|
479
474
|
return;
|
|
480
|
-
|
|
481
|
-
const o = typeof r.merge == "object" ? r.merge : r.merge === !0 ? { strategy: "append", key: "id" } : null, s =
|
|
475
|
+
ue(v, { serverState: r });
|
|
476
|
+
const o = typeof r.merge == "object" ? r.merge : r.merge === !0 ? { strategy: "append", key: "id" } : null, s = C(v, []), S = r.data;
|
|
482
477
|
if (o && o.strategy === "append" && "key" in o && Array.isArray(s) && Array.isArray(S)) {
|
|
483
478
|
const u = o.key;
|
|
484
479
|
if (!u) {
|
|
@@ -492,16 +487,16 @@ function ct(e, {
|
|
|
492
487
|
), w = S.filter(
|
|
493
488
|
(M) => !h.has(M[u])
|
|
494
489
|
);
|
|
495
|
-
w.length > 0 &&
|
|
496
|
-
const A =
|
|
497
|
-
|
|
490
|
+
w.length > 0 && $e(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,
|
|
@@ -509,49 +504,51 @@ function ct(e, {
|
|
|
509
504
|
);
|
|
510
505
|
W(v);
|
|
511
506
|
}
|
|
512
|
-
}), [v]),
|
|
513
|
-
const
|
|
514
|
-
if (
|
|
507
|
+
}), [v]), Z(() => {
|
|
508
|
+
const k = p.getState().getShadowMetadata(v, []);
|
|
509
|
+
if (k && k.stateSource)
|
|
515
510
|
return;
|
|
516
|
-
const
|
|
517
|
-
localStorageEnabled: !!
|
|
511
|
+
const I = j(v), r = {
|
|
512
|
+
localStorageEnabled: !!I?.localStorage?.key
|
|
518
513
|
};
|
|
519
514
|
if (L(v, [], {
|
|
520
|
-
...
|
|
515
|
+
...k,
|
|
521
516
|
features: r
|
|
522
|
-
}),
|
|
523
|
-
const
|
|
524
|
-
|
|
525
|
-
defaultState:
|
|
517
|
+
}), I?.defaultState !== void 0 || y !== void 0) {
|
|
518
|
+
const h = I?.defaultState || y;
|
|
519
|
+
I?.defaultState || ue(v, {
|
|
520
|
+
defaultState: h
|
|
526
521
|
});
|
|
527
522
|
}
|
|
528
|
-
const { value: o, source: s, timestamp: S } =
|
|
529
|
-
|
|
523
|
+
const { value: o, source: s, timestamp: S } = x();
|
|
524
|
+
K(v, o);
|
|
525
|
+
const u = j(v)?.validation;
|
|
526
|
+
u?.zodSchemaV4 ? H(v, u.zodSchemaV4, "zod4") : u?.zodSchemaV3 && H(v, u.zodSchemaV3, "zod3"), L(v, [], {
|
|
530
527
|
stateSource: s,
|
|
531
528
|
lastServerSync: s === "server" ? S : void 0,
|
|
532
529
|
isDirty: s === "server" ? !1 : void 0,
|
|
533
530
|
baseServerState: s === "server" ? o : void 0
|
|
534
|
-
}), s === "server" && a &&
|
|
535
|
-
}, [v, ...t || []]),
|
|
536
|
-
|
|
531
|
+
}), s === "server" && a && me(v, a), W(v);
|
|
532
|
+
}, [v, ...t || []]), re(() => {
|
|
533
|
+
E && ue(v, {
|
|
537
534
|
formElements: i,
|
|
538
535
|
defaultState: y,
|
|
539
|
-
localStorage:
|
|
540
|
-
middleware:
|
|
536
|
+
localStorage: c,
|
|
537
|
+
middleware: T.current?.middleware
|
|
541
538
|
});
|
|
542
|
-
const
|
|
543
|
-
return r.set(
|
|
544
|
-
forceUpdate: () =>
|
|
545
|
-
reactiveType:
|
|
539
|
+
const k = `${v}////${_.current}`, I = $(v, []), r = I?.components || /* @__PURE__ */ new Map();
|
|
540
|
+
return r.set(k, {
|
|
541
|
+
forceUpdate: () => V({}),
|
|
542
|
+
reactiveType: l ?? ["component"],
|
|
546
543
|
paths: /* @__PURE__ */ new Set(),
|
|
547
544
|
depsFunction: f || void 0,
|
|
548
|
-
deps: f ? f(
|
|
549
|
-
prevDeps: f ? f(
|
|
545
|
+
deps: f ? f(C(v, [])) : [],
|
|
546
|
+
prevDeps: f ? f(C(v, [])) : []
|
|
550
547
|
}), L(v, [], {
|
|
551
|
-
...
|
|
548
|
+
...I,
|
|
552
549
|
components: r
|
|
553
|
-
}),
|
|
554
|
-
const o = $(v, []), s = o?.components?.get(
|
|
550
|
+
}), V({}), () => {
|
|
551
|
+
const o = $(v, []), s = o?.components?.get(k);
|
|
555
552
|
s?.paths && s.paths.forEach((S) => {
|
|
556
553
|
const h = S.split(".").slice(1), w = p.getState().getShadowMetadata(v, h);
|
|
557
554
|
w?.pathComponents && w.pathComponents.size === 0 && (delete w.pathComponents, p.getState().setShadowMetadata(v, h, w));
|
|
@@ -561,36 +558,36 @@ function ct(e, {
|
|
|
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
|
-
const lt = (e, n,
|
|
570
|
+
const lt = (e, n, c) => {
|
|
574
571
|
let i = $(e, n)?.arrayKeys || [];
|
|
575
|
-
const f =
|
|
572
|
+
const f = c?.transforms;
|
|
576
573
|
if (!f || f.length === 0)
|
|
577
574
|
return i;
|
|
578
|
-
for (const
|
|
579
|
-
if (
|
|
575
|
+
for (const l of f)
|
|
576
|
+
if (l.type === "filter") {
|
|
580
577
|
const m = [];
|
|
581
578
|
i.forEach((y, t) => {
|
|
582
|
-
const a =
|
|
583
|
-
|
|
579
|
+
const a = C(e, [...n, y]);
|
|
580
|
+
l.fn(a, t) && m.push(y);
|
|
584
581
|
}), i = m;
|
|
585
|
-
} else
|
|
586
|
-
const t =
|
|
587
|
-
return
|
|
582
|
+
} else l.type === "sort" && i.sort((m, y) => {
|
|
583
|
+
const t = C(e, [...n, m]), a = C(e, [...n, y]);
|
|
584
|
+
return l.fn(t, a);
|
|
588
585
|
});
|
|
589
586
|
return i;
|
|
590
|
-
},
|
|
591
|
-
const i = `${e}////${n}`,
|
|
592
|
-
!
|
|
593
|
-
}, Y = (e, n,
|
|
587
|
+
}, te = (e, n, c) => {
|
|
588
|
+
const i = `${e}////${n}`, l = $(e, [])?.components?.get(i);
|
|
589
|
+
!l || l.reactiveType === "none" || !(Array.isArray(l.reactiveType) ? l.reactiveType : [l.reactiveType]).includes("component") || Ge(e, c, i);
|
|
590
|
+
}, Y = (e, n, c) => {
|
|
594
591
|
const i = $(e, []), f = /* @__PURE__ */ new Set();
|
|
595
592
|
i?.components && i.components.forEach((m, y) => {
|
|
596
593
|
(Array.isArray(m.reactiveType) ? m.reactiveType : [m.reactiveType || "component"]).includes("all") && (m.forceUpdate(), f.add(y));
|
|
@@ -600,23 +597,23 @@ const lt = (e, n, l) => {
|
|
|
600
597
|
])?.pathComponents?.forEach((m) => {
|
|
601
598
|
i?.components?.get(m)?.forceUpdate();
|
|
602
599
|
});
|
|
603
|
-
const
|
|
604
|
-
for (let m of
|
|
600
|
+
const l = $(e, n);
|
|
601
|
+
for (let m of l?.arrayKeys || []) {
|
|
605
602
|
const y = m + ".selected", t = $(e, y.split(".").slice(1));
|
|
606
|
-
m ==
|
|
603
|
+
m == c && t?.pathComponents?.forEach((a) => {
|
|
607
604
|
i?.components?.get(a)?.forceUpdate();
|
|
608
605
|
});
|
|
609
606
|
}
|
|
610
607
|
};
|
|
611
|
-
function
|
|
612
|
-
const i = $(e, n), f = n.length > 0 ? n.join(".") : "root",
|
|
613
|
-
if (Array.isArray(
|
|
608
|
+
function U(e, n, c) {
|
|
609
|
+
const i = $(e, n), f = n.length > 0 ? n.join(".") : "root", l = c?.arrayViews?.[f];
|
|
610
|
+
if (Array.isArray(l) && l.length === 0)
|
|
614
611
|
return {
|
|
615
612
|
shadowMeta: i,
|
|
616
613
|
value: [],
|
|
617
614
|
arrayKeys: i?.arrayKeys
|
|
618
615
|
};
|
|
619
|
-
const m =
|
|
616
|
+
const m = C(e, n, l);
|
|
620
617
|
return {
|
|
621
618
|
shadowMeta: i,
|
|
622
619
|
value: m,
|
|
@@ -624,95 +621,95 @@ function j(e, n, l) {
|
|
|
624
621
|
};
|
|
625
622
|
}
|
|
626
623
|
function ut(e, n) {
|
|
627
|
-
return n ? e.length !== n.length ? !1 : n.every((
|
|
624
|
+
return n ? e.length !== n.length ? !1 : n.every((c, i) => c === "*" || c === e[i]) : !0;
|
|
628
625
|
}
|
|
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
|
|
633
|
-
const
|
|
634
|
-
if (!
|
|
629
|
+
function Ve(e, n) {
|
|
630
|
+
const c = p.getState().getShadowMetadata(e, n);
|
|
631
|
+
if (!c?.clientActivityState?.elements) return [];
|
|
635
632
|
const i = [];
|
|
636
|
-
return
|
|
633
|
+
return c.clientActivityState.elements.forEach((f) => {
|
|
637
634
|
f.domRef?.current && i.push(f.domRef);
|
|
638
635
|
}), i;
|
|
639
636
|
}
|
|
640
637
|
function Ee(e, n) {
|
|
641
|
-
return
|
|
638
|
+
return Ve(e, n).map((i) => i.current).filter(Boolean);
|
|
642
639
|
}
|
|
643
|
-
function ft(e, n,
|
|
640
|
+
function ft(e, n, c) {
|
|
644
641
|
Ee(e, n).forEach((i) => {
|
|
645
642
|
if ("disabled" in i) {
|
|
646
|
-
i.disabled =
|
|
643
|
+
i.disabled = c;
|
|
647
644
|
return;
|
|
648
645
|
}
|
|
649
|
-
i.style.pointerEvents =
|
|
646
|
+
i.style.pointerEvents = c ? "none" : "", i.setAttribute("aria-disabled", String(c));
|
|
650
647
|
});
|
|
651
648
|
}
|
|
652
|
-
function
|
|
649
|
+
function Pe(e, n, c, i) {
|
|
653
650
|
const f = /* @__PURE__ */ new Map();
|
|
654
|
-
function
|
|
651
|
+
function l({
|
|
655
652
|
path: t = [],
|
|
656
653
|
meta: a,
|
|
657
654
|
componentId: d
|
|
658
655
|
}) {
|
|
659
656
|
if ($(e, t)?.isRaw)
|
|
660
|
-
return
|
|
661
|
-
const b = a ? JSON.stringify(a.arrayViews || a.transforms) : "",
|
|
662
|
-
if (f.has(
|
|
663
|
-
return f.get(
|
|
664
|
-
const v = [e, ...t].join("."),
|
|
665
|
-
},
|
|
666
|
-
apply(G, g,
|
|
667
|
-
if (
|
|
657
|
+
return C(e, t);
|
|
658
|
+
const b = a ? JSON.stringify(a.arrayViews || a.transforms) : "", E = t.join(".") + ":" + d + ":" + b;
|
|
659
|
+
if (f.has(E))
|
|
660
|
+
return f.get(E);
|
|
661
|
+
const v = [e, ...t].join("."), _ = () => {
|
|
662
|
+
}, T = {
|
|
663
|
+
apply(G, g, k) {
|
|
664
|
+
if (k.length === 0) {
|
|
668
665
|
const r = t.length > 0 ? t.join(".") : "root", o = a?.arrayViews?.[r];
|
|
669
|
-
return
|
|
666
|
+
return te(e, d, t), C(e, t, o);
|
|
670
667
|
}
|
|
671
|
-
const
|
|
672
|
-
return n(
|
|
668
|
+
const I = k[0];
|
|
669
|
+
return n(I, t, { updateType: "update" }), !0;
|
|
673
670
|
},
|
|
674
|
-
get(G, g,
|
|
671
|
+
get(G, g, k) {
|
|
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 } = U(e, t, a);
|
|
681
678
|
return Array.isArray(r) ? function* () {
|
|
682
679
|
for (let o = 0; o < r.length; o++)
|
|
683
680
|
yield r[o];
|
|
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, k);
|
|
688
685
|
if (typeof g != "string")
|
|
689
686
|
return Reflect.get(G, g);
|
|
690
687
|
if (t.length === 0 && g in m)
|
|
691
688
|
return m[g];
|
|
692
689
|
if (typeof g == "string" && !g.startsWith("$")) {
|
|
693
|
-
const { value: r } =
|
|
690
|
+
const { value: r } = U(e, t, a);
|
|
694
691
|
if (r !== null && typeof r == "object" && !Array.isArray(r) && Object.prototype.hasOwnProperty.call(r, g)) {
|
|
695
692
|
const u = [...t, g];
|
|
696
|
-
return
|
|
693
|
+
return l({
|
|
697
694
|
path: u,
|
|
698
695
|
componentId: d,
|
|
699
696
|
meta: a
|
|
700
697
|
});
|
|
701
698
|
}
|
|
702
|
-
const s =
|
|
699
|
+
const s = z.getState().registeredPlugins;
|
|
703
700
|
for (const u of s) {
|
|
704
701
|
const h = u.chainMethods?.[g];
|
|
705
702
|
if (h && ut(t, h.pathPattern) && dt(r, h.target))
|
|
706
703
|
return (...w) => {
|
|
707
|
-
const A =
|
|
704
|
+
const A = z.getState(), M = A.pluginOptions.get(e)?.get(u.name), D = A.getHookResult(e, u.name);
|
|
708
705
|
return h.handler(
|
|
709
706
|
{
|
|
710
707
|
stateKey: e,
|
|
711
708
|
path: t,
|
|
712
709
|
pluginName: u.name,
|
|
713
710
|
options: M,
|
|
714
|
-
hookData:
|
|
715
|
-
$get: () =>
|
|
711
|
+
hookData: D,
|
|
712
|
+
$get: () => U(e, t, a).value,
|
|
716
713
|
$update: (P) => (n(P, t, {
|
|
717
714
|
updateType: "update"
|
|
718
715
|
}), {
|
|
@@ -733,10 +730,10 @@ function Ve(e, n, l, i) {
|
|
|
733
730
|
metaData: O
|
|
734
731
|
});
|
|
735
732
|
},
|
|
736
|
-
getFieldMetaData: () =>
|
|
737
|
-
setFieldMetaData: (P) =>
|
|
738
|
-
removeFieldMetaData: () =>
|
|
739
|
-
getFieldRefs: () =>
|
|
733
|
+
getFieldMetaData: () => he(e, t)?.get(u.name),
|
|
734
|
+
setFieldMetaData: (P) => ve(e, t, u.name, P),
|
|
735
|
+
removeFieldMetaData: () => we(e, t, u.name),
|
|
736
|
+
getFieldRefs: () => Ve(e, t),
|
|
740
737
|
getFieldElements: () => Ee(e, t),
|
|
741
738
|
setFieldDisabled: (P) => ft(e, t, P)
|
|
742
739
|
},
|
|
@@ -745,14 +742,14 @@ function Ve(e, n, l, i) {
|
|
|
745
742
|
};
|
|
746
743
|
}
|
|
747
744
|
const S = [...t, g];
|
|
748
|
-
return
|
|
745
|
+
return l({
|
|
749
746
|
path: S,
|
|
750
747
|
componentId: d,
|
|
751
748
|
meta: a
|
|
752
749
|
});
|
|
753
750
|
}
|
|
754
751
|
if (g === "$_rebuildStateShape")
|
|
755
|
-
return
|
|
752
|
+
return l;
|
|
756
753
|
if (g === "$sync" && t.length === 0)
|
|
757
754
|
return async function() {
|
|
758
755
|
const r = p.getState().getInitialOptions(e), o = r?.sync;
|
|
@@ -779,15 +776,15 @@ function Ve(e, n, l, i) {
|
|
|
779
776
|
};
|
|
780
777
|
if (g === "$_status" || g === "$getStatus") {
|
|
781
778
|
const r = () => {
|
|
782
|
-
const { shadowMeta: o, value: s } =
|
|
779
|
+
const { shadowMeta: o, value: s } = U(e, t, a);
|
|
783
780
|
return o?.isDirty === !0 ? "dirty" : o?.stateSource === "server" || o?.isDirty === !1 ? "synced" : o?.stateSource === "localStorage" ? "restored" : o?.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], o =
|
|
790
|
-
|
|
786
|
+
const r = p.getState().initialStateGlobal[e], o = j(e), s = R(o?.localStorage?.key) ? o.localStorage.key(r) : o?.localStorage?.key, S = i && s ? `${i}-${e}-${s}` : void 0;
|
|
787
|
+
de(S);
|
|
791
788
|
};
|
|
792
789
|
if (g === "$setRaw")
|
|
793
790
|
return (r) => {
|
|
@@ -796,7 +793,7 @@ function Ve(e, n, l, i) {
|
|
|
796
793
|
};
|
|
797
794
|
if (g === "$validate")
|
|
798
795
|
return () => {
|
|
799
|
-
const r = p.getState(), { value: o } =
|
|
796
|
+
const r = p.getState(), { value: o } = U(e, t, a), s = r.getInitialOptions(e), S = s?.validation?.zodSchemaV4 || s?.validation?.zodSchemaV3;
|
|
800
797
|
if (!S)
|
|
801
798
|
return { success: !0, data: o };
|
|
802
799
|
const u = S.safeParse(o);
|
|
@@ -834,13 +831,13 @@ function Ve(e, n, l, i) {
|
|
|
834
831
|
};
|
|
835
832
|
if (g === "$showValidationErrors")
|
|
836
833
|
return () => {
|
|
837
|
-
const { shadowMeta: r } =
|
|
834
|
+
const { shadowMeta: r } = U(e, t, a);
|
|
838
835
|
return r?.validation?.status === "INVALID" && r.validation.errors.length > 0 ? r.validation.errors.filter((o) => o.severity === "error").map((o) => o.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
|
]);
|
|
@@ -848,11 +845,11 @@ function Ve(e, n, l, i) {
|
|
|
848
845
|
if (!o)
|
|
849
846
|
return;
|
|
850
847
|
const s = t.join("."), S = a?.arrayViews?.[s], u = o.split(".").pop();
|
|
851
|
-
if (!(S && !S.includes(u) ||
|
|
848
|
+
if (!(S && !S.includes(u) || C(
|
|
852
849
|
e,
|
|
853
850
|
o.split(".").slice(1)
|
|
854
851
|
) === void 0))
|
|
855
|
-
return
|
|
852
|
+
return l({
|
|
856
853
|
path: o.split(".").slice(1),
|
|
857
854
|
componentId: d,
|
|
858
855
|
meta: a
|
|
@@ -884,9 +881,9 @@ function Ve(e, n, l, i) {
|
|
|
884
881
|
t,
|
|
885
882
|
a
|
|
886
883
|
);
|
|
887
|
-
if (
|
|
884
|
+
if (te(e, d, t), !s || !Array.isArray(o))
|
|
888
885
|
return [];
|
|
889
|
-
const S =
|
|
886
|
+
const S = l({
|
|
890
887
|
path: t,
|
|
891
888
|
componentId: d,
|
|
892
889
|
meta: a
|
|
@@ -894,7 +891,7 @@ function Ve(e, n, l, i) {
|
|
|
894
891
|
return o.map((u, h) => {
|
|
895
892
|
const w = s[h];
|
|
896
893
|
if (!w) return;
|
|
897
|
-
const A = [...t, w], M =
|
|
894
|
+
const A = [...t, w], M = l({
|
|
898
895
|
path: A,
|
|
899
896
|
// This now correctly points to the item in the shadow store.
|
|
900
897
|
componentId: d,
|
|
@@ -918,7 +915,7 @@ function Ve(e, n, l, i) {
|
|
|
918
915
|
const A = s[w];
|
|
919
916
|
A && u.push(A);
|
|
920
917
|
}
|
|
921
|
-
}),
|
|
918
|
+
}), l({
|
|
922
919
|
path: t,
|
|
923
920
|
componentId: d,
|
|
924
921
|
meta: {
|
|
@@ -949,7 +946,7 @@ function Ve(e, n, l, i) {
|
|
|
949
946
|
}));
|
|
950
947
|
u.sort((w, A) => r(w.item, A.item));
|
|
951
948
|
const h = u.map((w) => w.key);
|
|
952
|
-
return
|
|
949
|
+
return l({
|
|
953
950
|
path: t,
|
|
954
951
|
componentId: d,
|
|
955
952
|
meta: {
|
|
@@ -967,7 +964,7 @@ 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, u] =
|
|
967
|
+
const s = q(/* @__PURE__ */ new Map()), [S, u] = ne({}), h = t.length > 0 ? t.join(".") : "root", w = lt(e, t, a), A = Ae(() => ({
|
|
971
968
|
...a,
|
|
972
969
|
arrayViews: {
|
|
973
970
|
...a?.arrayViews || {},
|
|
@@ -978,14 +975,14 @@ function Ve(e, n, l, i) {
|
|
|
978
975
|
t,
|
|
979
976
|
A
|
|
980
977
|
);
|
|
981
|
-
if (
|
|
978
|
+
if (Z(() => {
|
|
982
979
|
const O = p.getState().subscribeToPath(v, (F) => {
|
|
983
980
|
if (F.type === "GET_SELECTED")
|
|
984
981
|
return;
|
|
985
982
|
const B = p.getState().getShadowMetadata(e, t)?.transformCaches;
|
|
986
983
|
if (B)
|
|
987
|
-
for (const
|
|
988
|
-
|
|
984
|
+
for (const ee of B.keys())
|
|
985
|
+
ee.startsWith(d) && B.delete(ee);
|
|
989
986
|
(F.type === "INSERT" || F.type === "INSERT_MANY" || F.type === "REMOVE" || F.type === "CLEAR_SELECTION" || F.type === "SERVER_STATE_UPDATE" && !a?.serverStateIsUpStream) && u({});
|
|
990
987
|
});
|
|
991
988
|
return () => {
|
|
@@ -993,35 +990,35 @@ function Ve(e, n, l, i) {
|
|
|
993
990
|
};
|
|
994
991
|
}, [d, v]), !Array.isArray(M))
|
|
995
992
|
return null;
|
|
996
|
-
const
|
|
993
|
+
const D = l({
|
|
997
994
|
path: t,
|
|
998
995
|
componentId: d,
|
|
999
996
|
meta: A
|
|
1000
997
|
// Use updated meta here
|
|
1001
998
|
}), P = M.map((O, F) => {
|
|
1002
|
-
const
|
|
1003
|
-
if (!
|
|
999
|
+
const J = w[F];
|
|
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(Ne, {
|
|
1006
|
+
key: J,
|
|
1010
1007
|
stateKey: e,
|
|
1011
1008
|
itemComponentId: B,
|
|
1012
|
-
itemPath:
|
|
1009
|
+
itemPath: ee,
|
|
1013
1010
|
localIndex: F,
|
|
1014
|
-
arraySetter:
|
|
1015
|
-
rebuildStateShape:
|
|
1011
|
+
arraySetter: D,
|
|
1012
|
+
rebuildStateShape: l,
|
|
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
1020
|
const o = t.length > 0 ? t.join(".") : "root", s = a?.arrayViews?.[o], S = p.getState().getShadowValue(e, t, s);
|
|
1024
|
-
return Array.isArray(S) ?
|
|
1021
|
+
return Array.isArray(S) ? l({
|
|
1025
1022
|
path: [...t, "[*]", r],
|
|
1026
1023
|
componentId: d,
|
|
1027
1024
|
meta: a
|
|
@@ -1032,7 +1029,7 @@ function Ve(e, n, l, i) {
|
|
|
1032
1029
|
const o = t.length > 0 ? t.join(".") : "root", s = a?.arrayViews?.[o];
|
|
1033
1030
|
if (s) {
|
|
1034
1031
|
const h = s[r];
|
|
1035
|
-
return h ?
|
|
1032
|
+
return h ? l({
|
|
1036
1033
|
path: [...t, h],
|
|
1037
1034
|
componentId: d,
|
|
1038
1035
|
meta: a
|
|
@@ -1042,7 +1039,7 @@ function Ve(e, n, l, i) {
|
|
|
1042
1039
|
if (!S?.arrayKeys) return;
|
|
1043
1040
|
const u = S.arrayKeys[r];
|
|
1044
1041
|
if (u)
|
|
1045
|
-
return
|
|
1042
|
+
return l({
|
|
1046
1043
|
path: [...t, u],
|
|
1047
1044
|
componentId: d,
|
|
1048
1045
|
meta: a
|
|
@@ -1057,7 +1054,7 @@ function Ve(e, n, l, i) {
|
|
|
1057
1054
|
if (!o)
|
|
1058
1055
|
return;
|
|
1059
1056
|
const s = [...t, o];
|
|
1060
|
-
return
|
|
1057
|
+
return l({
|
|
1061
1058
|
path: s,
|
|
1062
1059
|
componentId: d,
|
|
1063
1060
|
meta: a
|
|
@@ -1078,22 +1075,22 @@ function Ve(e, n, l, i) {
|
|
|
1078
1075
|
};
|
|
1079
1076
|
if (g === "$uniqueInsert")
|
|
1080
1077
|
return (r, o, s) => {
|
|
1081
|
-
const { value: S } =
|
|
1078
|
+
const { value: S } = U(
|
|
1082
1079
|
e,
|
|
1083
1080
|
t,
|
|
1084
1081
|
a
|
|
1085
|
-
), u =
|
|
1082
|
+
), u = R(r) ? r(S) : r;
|
|
1086
1083
|
let h = null;
|
|
1087
1084
|
if (!S.some((A) => {
|
|
1088
1085
|
const M = o ? o.every(
|
|
1089
|
-
(
|
|
1090
|
-
) :
|
|
1086
|
+
(D) => X(A[D], u[D])
|
|
1087
|
+
) : X(A, u);
|
|
1091
1088
|
return M && (h = A), M;
|
|
1092
1089
|
}))
|
|
1093
1090
|
n(u, t, { updateType: "insert" });
|
|
1094
1091
|
else if (s && h) {
|
|
1095
1092
|
const A = s(h), M = S.map(
|
|
1096
|
-
(
|
|
1093
|
+
(D) => X(D, h) ? A : D
|
|
1097
1094
|
);
|
|
1098
1095
|
n(M, t, {
|
|
1099
1096
|
updateType: "update"
|
|
@@ -1136,7 +1133,7 @@ function Ve(e, n, l, i) {
|
|
|
1136
1133
|
keys: S
|
|
1137
1134
|
} = N(e, t, a);
|
|
1138
1135
|
if (!o) return;
|
|
1139
|
-
const u =
|
|
1136
|
+
const u = le(s, S, (h) => h === r);
|
|
1140
1137
|
u && n(null, [...t, u.key], {
|
|
1141
1138
|
updateType: "cut"
|
|
1142
1139
|
});
|
|
@@ -1149,7 +1146,7 @@ function Ve(e, n, l, i) {
|
|
|
1149
1146
|
keys: S
|
|
1150
1147
|
} = N(e, t, a);
|
|
1151
1148
|
if (!o) return;
|
|
1152
|
-
const u =
|
|
1149
|
+
const u = le(s, S, (h) => h === r);
|
|
1153
1150
|
if (u) {
|
|
1154
1151
|
const h = [...t, u.key];
|
|
1155
1152
|
n(null, h, {
|
|
@@ -1163,44 +1160,44 @@ function Ve(e, n, l, i) {
|
|
|
1163
1160
|
const { isArray: s, value: S, keys: u } = N(e, t, a);
|
|
1164
1161
|
if (!s)
|
|
1165
1162
|
throw new Error("findWith can only be used on arrays");
|
|
1166
|
-
const h =
|
|
1163
|
+
const h = le(
|
|
1167
1164
|
S,
|
|
1168
1165
|
u,
|
|
1169
1166
|
(w) => w?.[r] === o
|
|
1170
1167
|
);
|
|
1171
|
-
return h ?
|
|
1168
|
+
return h ? l({
|
|
1172
1169
|
path: [...t, h.key],
|
|
1173
1170
|
componentId: d,
|
|
1174
1171
|
meta: a
|
|
1175
1172
|
}) : null;
|
|
1176
1173
|
};
|
|
1177
1174
|
if (g === "$cutThis") {
|
|
1178
|
-
const { value: r } =
|
|
1175
|
+
const { value: r } = U(e, t, a), o = t.slice(0, -1);
|
|
1179
1176
|
return Y(e, o), () => {
|
|
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 } = U(e, t, a);
|
|
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
1191
|
_meta: a
|
|
1195
1192
|
});
|
|
1196
1193
|
if (g === "$$get")
|
|
1197
|
-
return () =>
|
|
1194
|
+
return () => pe({ _stateKey: e, _path: t, _meta: a });
|
|
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
1203
|
if ($(e, r)?.arrayKeys) {
|
|
@@ -1250,7 +1247,7 @@ function Ve(e, n, l, i) {
|
|
|
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
1253
|
return (r, o, s = "update") => {
|
|
@@ -1259,11 +1256,11 @@ function Ve(e, n, l, i) {
|
|
|
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, o) =>
|
|
1261
|
+
return (r, o) => ve(e, t, r, o);
|
|
1265
1262
|
if (g === "$removePluginMetaData")
|
|
1266
|
-
return (r) =>
|
|
1263
|
+
return (r) => we(e, t, r);
|
|
1267
1264
|
if (g === "$addZodValidation")
|
|
1268
1265
|
return (r, o) => {
|
|
1269
1266
|
r.forEach((s) => {
|
|
@@ -1320,11 +1317,11 @@ function Ve(e, n, l, i) {
|
|
|
1320
1317
|
o.updateShadowAtPath(e, w, A), o.markAsDirty(e, w, { bubble: !0 });
|
|
1321
1318
|
let M = [...w];
|
|
1322
1319
|
for (; ; ) {
|
|
1323
|
-
const
|
|
1320
|
+
const D = o.getShadowMetadata(
|
|
1324
1321
|
e,
|
|
1325
1322
|
M
|
|
1326
1323
|
);
|
|
1327
|
-
if (
|
|
1324
|
+
if (D?.pathComponents && D.pathComponents.forEach((P) => {
|
|
1328
1325
|
if (!u.has(P)) {
|
|
1329
1326
|
const O = s.components?.get(P);
|
|
1330
1327
|
O && (O.forceUpdate(), u.add(P));
|
|
@@ -1339,11 +1336,11 @@ function Ve(e, n, l, i) {
|
|
|
1339
1336
|
o.removeShadowArrayElement(e, w), o.markAsDirty(e, A, { bubble: !0 });
|
|
1340
1337
|
let M = [...A];
|
|
1341
1338
|
for (; ; ) {
|
|
1342
|
-
const
|
|
1339
|
+
const D = o.getShadowMetadata(
|
|
1343
1340
|
e,
|
|
1344
1341
|
M
|
|
1345
1342
|
);
|
|
1346
|
-
if (
|
|
1343
|
+
if (D?.pathComponents && D.pathComponents.forEach((P) => {
|
|
1347
1344
|
if (!u.has(P)) {
|
|
1348
1345
|
const O = s.components?.get(P);
|
|
1349
1346
|
O && (O.forceUpdate(), u.add(P));
|
|
@@ -1392,7 +1389,7 @@ function Ve(e, n, l, i) {
|
|
|
1392
1389
|
}
|
|
1393
1390
|
});
|
|
1394
1391
|
if (g === "$toggle") {
|
|
1395
|
-
const { value: r } =
|
|
1392
|
+
const { value: r } = U(
|
|
1396
1393
|
e,
|
|
1397
1394
|
t,
|
|
1398
1395
|
a
|
|
@@ -1418,78 +1415,78 @@ function Ve(e, n, l, i) {
|
|
|
1418
1415
|
stateKey: e,
|
|
1419
1416
|
path: t,
|
|
1420
1417
|
dependencies: S,
|
|
1421
|
-
rebuildStateShape:
|
|
1418
|
+
rebuildStateShape: l,
|
|
1422
1419
|
renderFn: u
|
|
1423
1420
|
}
|
|
1424
1421
|
);
|
|
1425
1422
|
};
|
|
1426
1423
|
if (g === "$formElement")
|
|
1427
1424
|
return (r, o) => /* @__PURE__ */ Q(
|
|
1428
|
-
|
|
1425
|
+
Ue,
|
|
1429
1426
|
{
|
|
1430
1427
|
stateKey: e,
|
|
1431
1428
|
path: t,
|
|
1432
|
-
rebuildStateShape:
|
|
1429
|
+
rebuildStateShape: l,
|
|
1433
1430
|
setState: n,
|
|
1434
1431
|
formOpts: o,
|
|
1435
1432
|
renderFn: r
|
|
1436
1433
|
}
|
|
1437
1434
|
);
|
|
1438
|
-
const
|
|
1439
|
-
return
|
|
1440
|
-
path:
|
|
1435
|
+
const I = [...t, g];
|
|
1436
|
+
return l({
|
|
1437
|
+
path: I,
|
|
1441
1438
|
componentId: d,
|
|
1442
1439
|
meta: a
|
|
1443
1440
|
});
|
|
1444
1441
|
}
|
|
1445
|
-
},
|
|
1446
|
-
return f.set(
|
|
1442
|
+
}, x = new Proxy(_, T);
|
|
1443
|
+
return f.set(E, x), x;
|
|
1447
1444
|
}
|
|
1448
1445
|
const m = {
|
|
1449
1446
|
$revertToInitialState: (t) => {
|
|
1450
1447
|
const a = p.getState().getShadowMetadata(e, []);
|
|
1451
1448
|
let d;
|
|
1452
|
-
a?.stateSource === "server" && a.baseServerState ? d = a.baseServerState : d = p.getState().initialStateGlobal[e], qe(e),
|
|
1449
|
+
a?.stateSource === "server" && a.baseServerState ? d = a.baseServerState : d = p.getState().initialStateGlobal[e], qe(e), K(e, d), l({
|
|
1453
1450
|
path: [],
|
|
1454
|
-
componentId:
|
|
1451
|
+
componentId: c
|
|
1455
1452
|
});
|
|
1456
|
-
const
|
|
1457
|
-
return
|
|
1453
|
+
const V = j(e), b = R(V?.localStorage?.key) ? V?.localStorage?.key(d) : V?.localStorage?.key, E = i && b ? `${i}-${e}-${b}` : void 0;
|
|
1454
|
+
return de(E), W(e), d;
|
|
1458
1455
|
},
|
|
1459
1456
|
$initializeAndMergeShadowState: (t) => {
|
|
1460
|
-
|
|
1457
|
+
Re(e, t), W(e);
|
|
1461
1458
|
},
|
|
1462
1459
|
$updateInitialState: (t) => {
|
|
1463
|
-
const a =
|
|
1460
|
+
const a = Pe(
|
|
1464
1461
|
e,
|
|
1465
1462
|
n,
|
|
1466
|
-
|
|
1463
|
+
c,
|
|
1467
1464
|
i
|
|
1468
|
-
), d = p.getState().initialStateGlobal[e],
|
|
1469
|
-
return
|
|
1470
|
-
|
|
1465
|
+
), d = p.getState().initialStateGlobal[e], V = j(e), b = R(V?.localStorage?.key) ? V?.localStorage?.key(d) : V?.localStorage?.key, E = i && b ? `${i}-${e}-${b}` : void 0;
|
|
1466
|
+
return de(E), Ie(() => {
|
|
1467
|
+
be(e, t), K(e, t);
|
|
1471
1468
|
const v = p.getState().getShadowMetadata(e, []);
|
|
1472
|
-
v && v?.components?.forEach((
|
|
1473
|
-
|
|
1469
|
+
v && v?.components?.forEach((_) => {
|
|
1470
|
+
_.forceUpdate();
|
|
1474
1471
|
});
|
|
1475
1472
|
}), {
|
|
1476
1473
|
fetchId: (v) => a.$get()[v]
|
|
1477
1474
|
};
|
|
1478
1475
|
}
|
|
1479
1476
|
};
|
|
1480
|
-
return
|
|
1481
|
-
componentId:
|
|
1477
|
+
return l({
|
|
1478
|
+
componentId: c,
|
|
1482
1479
|
path: []
|
|
1483
1480
|
});
|
|
1484
1481
|
}
|
|
1485
|
-
function
|
|
1486
|
-
return
|
|
1482
|
+
function pe(e) {
|
|
1483
|
+
return Se(gt, { proxy: e });
|
|
1487
1484
|
}
|
|
1488
1485
|
function gt({
|
|
1489
1486
|
proxy: e
|
|
1490
1487
|
}) {
|
|
1491
|
-
const n = q(null),
|
|
1492
|
-
return
|
|
1488
|
+
const n = q(null), c = q(null), i = q(!1), f = `${e._stateKey}-${e._path.join(".")}`, l = e._path.length > 0 ? e._path.join(".") : "root", m = e._meta?.arrayViews?.[l], y = C(e._stateKey, e._path, m);
|
|
1489
|
+
return Z(() => {
|
|
1493
1490
|
const t = n.current;
|
|
1494
1491
|
if (!t || i.current) return;
|
|
1495
1492
|
const a = setTimeout(() => {
|
|
@@ -1498,48 +1495,48 @@ function gt({
|
|
|
1498
1495
|
return;
|
|
1499
1496
|
}
|
|
1500
1497
|
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
|
-
|
|
1505
|
-
instanceId:
|
|
1506
|
-
parentId:
|
|
1498
|
+
let E = d.getAttribute("data-parent-id");
|
|
1499
|
+
E || (E = `parent-${crypto.randomUUID()}`, d.setAttribute("data-parent-id", E)), c.current = `instance-${crypto.randomUUID()}`;
|
|
1500
|
+
const v = p.getState().getShadowMetadata(e._stateKey, e._path) || {}, _ = v.signals || [];
|
|
1501
|
+
_.push({
|
|
1502
|
+
instanceId: c.current,
|
|
1503
|
+
parentId: E,
|
|
1507
1504
|
position: b,
|
|
1508
1505
|
effect: e._effect
|
|
1509
1506
|
}), p.getState().setShadowMetadata(e._stateKey, e._path, {
|
|
1510
1507
|
...v,
|
|
1511
|
-
signals:
|
|
1508
|
+
signals: _
|
|
1512
1509
|
});
|
|
1513
|
-
let
|
|
1510
|
+
let T = y;
|
|
1514
1511
|
if (e._effect)
|
|
1515
1512
|
try {
|
|
1516
|
-
|
|
1513
|
+
T = new Function(
|
|
1517
1514
|
"state",
|
|
1518
1515
|
`return (${e._effect})(state)`
|
|
1519
1516
|
)(y);
|
|
1520
1517
|
} catch (G) {
|
|
1521
1518
|
console.error("Error evaluating effect function:", G);
|
|
1522
1519
|
}
|
|
1523
|
-
|
|
1524
|
-
const
|
|
1525
|
-
t.replaceWith(
|
|
1520
|
+
T !== null && typeof T == "object" && (T = JSON.stringify(T));
|
|
1521
|
+
const x = document.createTextNode(String(T ?? ""));
|
|
1522
|
+
t.replaceWith(x), i.current = !0;
|
|
1526
1523
|
}, 0);
|
|
1527
1524
|
return () => {
|
|
1528
|
-
if (clearTimeout(a),
|
|
1525
|
+
if (clearTimeout(a), c.current) {
|
|
1529
1526
|
const d = p.getState().getShadowMetadata(e._stateKey, e._path) || {};
|
|
1530
1527
|
d.signals && (d.signals = d.signals.filter(
|
|
1531
|
-
(
|
|
1528
|
+
(V) => V.instanceId !== c.current
|
|
1532
1529
|
), p.getState().setShadowMetadata(e._stateKey, e._path, d));
|
|
1533
1530
|
}
|
|
1534
1531
|
};
|
|
1535
|
-
}, []),
|
|
1532
|
+
}, []), Se("span", {
|
|
1536
1533
|
ref: n,
|
|
1537
1534
|
style: { display: "contents" },
|
|
1538
1535
|
"data-signal-id": f
|
|
1539
1536
|
});
|
|
1540
1537
|
}
|
|
1541
1538
|
export {
|
|
1542
|
-
|
|
1539
|
+
pe as $cogsSignal,
|
|
1543
1540
|
$t as createCogsState,
|
|
1544
1541
|
ct as useCogsStateFn
|
|
1545
1542
|
};
|