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