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