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