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