cogsbox-state 0.5.242 → 0.5.244
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/CogsState.jsx +703 -744
- package/dist/CogsState.jsx.map +1 -1
- package/dist/store.d.ts +0 -1
- package/dist/store.js.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +183 -196
- package/src/store.ts +0 -1
package/dist/CogsState.jsx
CHANGED
|
@@ -1,177 +1,177 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as
|
|
3
|
-
import { useState as
|
|
4
|
-
import { transformStateFunc as Ne, isDeepEqual as
|
|
5
|
-
import { pushFunc as
|
|
6
|
-
import
|
|
7
|
-
import { v4 as
|
|
2
|
+
import { jsx as Se } from "react/jsx-runtime";
|
|
3
|
+
import { useState as te, useRef as ee, useEffect as le, useLayoutEffect as pe, useMemo as ke, createElement as ae, useSyncExternalStore as Te, startTransition as Ae } from "react";
|
|
4
|
+
import { transformStateFunc as Ne, isDeepEqual as G, isFunction as J, getNestedValue as L, getDifferences as de, debounce as Ve } from "./utility.js";
|
|
5
|
+
import { pushFunc as ce, updateFn as X, cutFunc as K, ValidationWrapper as be, FormControlComponent as Ce } from "./Functions.jsx";
|
|
6
|
+
import Pe from "superjson";
|
|
7
|
+
import { v4 as ue } from "uuid";
|
|
8
8
|
import "zod";
|
|
9
|
-
import { getGlobalStore as n, formRefStore as
|
|
10
|
-
import { useCogsConfig as
|
|
11
|
-
import { applyPatch as
|
|
12
|
-
function
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
...
|
|
16
|
-
...
|
|
9
|
+
import { getGlobalStore as n, formRefStore as me } from "./store.js";
|
|
10
|
+
import { useCogsConfig as we } from "./CogsStateClient.jsx";
|
|
11
|
+
import { applyPatch as _e } from "fast-json-patch";
|
|
12
|
+
function ye(e, s) {
|
|
13
|
+
const y = n.getState().getInitialOptions, g = n.getState().setInitialStateOptions, m = y(e) || {};
|
|
14
|
+
g(e, {
|
|
15
|
+
...m,
|
|
16
|
+
...s
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
|
-
function
|
|
19
|
+
function ve({
|
|
20
20
|
stateKey: e,
|
|
21
|
-
options:
|
|
22
|
-
initialOptionsPart:
|
|
21
|
+
options: s,
|
|
22
|
+
initialOptionsPart: y
|
|
23
23
|
}) {
|
|
24
|
-
const
|
|
25
|
-
let
|
|
26
|
-
if (
|
|
27
|
-
for (const
|
|
28
|
-
|
|
29
|
-
!
|
|
30
|
-
|
|
24
|
+
const g = H(e) || {}, m = y[e] || {}, $ = n.getState().setInitialStateOptions, w = { ...m, ...g };
|
|
25
|
+
let h = !1;
|
|
26
|
+
if (s)
|
|
27
|
+
for (const i in s)
|
|
28
|
+
w.hasOwnProperty(i) ? (i == "localStorage" && s[i] && w[i].key !== s[i]?.key && (h = !0, w[i] = s[i]), i == "initialState" && s[i] && w[i] !== s[i] && // Different references
|
|
29
|
+
!G(w[i], s[i]) && (h = !0, w[i] = s[i])) : (h = !0, w[i] = s[i]);
|
|
30
|
+
h && $(e, w);
|
|
31
31
|
}
|
|
32
|
-
function
|
|
33
|
-
return { initialState: e, formElements:
|
|
32
|
+
function Qe(e, { formElements: s, validation: y }) {
|
|
33
|
+
return { initialState: e, formElements: s, validation: y };
|
|
34
34
|
}
|
|
35
|
-
const
|
|
36
|
-
let
|
|
37
|
-
const [
|
|
38
|
-
(Object.keys(
|
|
39
|
-
|
|
40
|
-
...
|
|
35
|
+
const Ke = (e, s) => {
|
|
36
|
+
let y = e;
|
|
37
|
+
const [g, m] = Ne(y);
|
|
38
|
+
(Object.keys(m).length > 0 || s && Object.keys(s).length > 0) && Object.keys(m).forEach((h) => {
|
|
39
|
+
m[h] = m[h] || {}, m[h].formElements = {
|
|
40
|
+
...s?.formElements,
|
|
41
41
|
// Global defaults first
|
|
42
|
-
...
|
|
43
|
-
...
|
|
42
|
+
...s?.validation,
|
|
43
|
+
...m[h].formElements || {}
|
|
44
44
|
// State-specific overrides
|
|
45
|
-
},
|
|
46
|
-
}), n.getState().setInitialStates(
|
|
47
|
-
const
|
|
48
|
-
const [
|
|
49
|
-
|
|
50
|
-
stateKey:
|
|
51
|
-
options:
|
|
52
|
-
initialOptionsPart:
|
|
45
|
+
}, H(h) || n.getState().setInitialStateOptions(h, m[h]);
|
|
46
|
+
}), n.getState().setInitialStates(g), n.getState().setCreatedState(g);
|
|
47
|
+
const $ = (h, i) => {
|
|
48
|
+
const [v] = te(i?.componentId ?? ue());
|
|
49
|
+
ve({
|
|
50
|
+
stateKey: h,
|
|
51
|
+
options: i,
|
|
52
|
+
initialOptionsPart: m
|
|
53
53
|
});
|
|
54
|
-
const r = n.getState().cogsStateStore[
|
|
55
|
-
|
|
54
|
+
const r = n.getState().cogsStateStore[h] || g[h], f = i?.modifyState ? i.modifyState(r) : r, [U, C] = Me(
|
|
55
|
+
f,
|
|
56
56
|
{
|
|
57
|
-
stateKey:
|
|
58
|
-
syncUpdate:
|
|
59
|
-
componentId:
|
|
60
|
-
localStorage:
|
|
61
|
-
middleware:
|
|
62
|
-
enabledSync:
|
|
63
|
-
reactiveType:
|
|
64
|
-
reactiveDeps:
|
|
65
|
-
initialState:
|
|
66
|
-
dependencies:
|
|
67
|
-
serverState:
|
|
57
|
+
stateKey: h,
|
|
58
|
+
syncUpdate: i?.syncUpdate,
|
|
59
|
+
componentId: v,
|
|
60
|
+
localStorage: i?.localStorage,
|
|
61
|
+
middleware: i?.middleware,
|
|
62
|
+
enabledSync: i?.enabledSync,
|
|
63
|
+
reactiveType: i?.reactiveType,
|
|
64
|
+
reactiveDeps: i?.reactiveDeps,
|
|
65
|
+
initialState: i?.initialState,
|
|
66
|
+
dependencies: i?.dependencies,
|
|
67
|
+
serverState: i?.serverState
|
|
68
68
|
}
|
|
69
69
|
);
|
|
70
|
-
return
|
|
70
|
+
return C;
|
|
71
71
|
};
|
|
72
|
-
function
|
|
73
|
-
|
|
72
|
+
function w(h, i) {
|
|
73
|
+
ve({ stateKey: h, options: i, initialOptionsPart: m }), i.localStorage && Re(h, i), ie(h);
|
|
74
74
|
}
|
|
75
|
-
return { useCogsState:
|
|
75
|
+
return { useCogsState: $, setCogsOptions: w };
|
|
76
76
|
}, {
|
|
77
|
-
setUpdaterState:
|
|
78
|
-
setState:
|
|
79
|
-
getInitialOptions:
|
|
80
|
-
getKeyState:
|
|
77
|
+
setUpdaterState: ne,
|
|
78
|
+
setState: Z,
|
|
79
|
+
getInitialOptions: H,
|
|
80
|
+
getKeyState: Ee,
|
|
81
81
|
getValidationErrors: xe,
|
|
82
82
|
setStateLog: Oe,
|
|
83
83
|
updateInitialStateGlobal: ge,
|
|
84
|
-
addValidationError:
|
|
85
|
-
removeValidationError:
|
|
86
|
-
setServerSyncActions:
|
|
87
|
-
} = n.getState(),
|
|
88
|
-
|
|
84
|
+
addValidationError: je,
|
|
85
|
+
removeValidationError: B,
|
|
86
|
+
setServerSyncActions: Fe
|
|
87
|
+
} = n.getState(), Ie = (e, s, y, g, m) => {
|
|
88
|
+
y?.log && console.log(
|
|
89
89
|
"saving to localstorage",
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
90
|
+
s,
|
|
91
|
+
y.localStorage?.key,
|
|
92
|
+
g
|
|
93
93
|
);
|
|
94
|
-
const
|
|
95
|
-
if (
|
|
96
|
-
const
|
|
97
|
-
let
|
|
94
|
+
const $ = J(y?.localStorage?.key) ? y.localStorage?.key(e) : y?.localStorage?.key;
|
|
95
|
+
if ($ && g) {
|
|
96
|
+
const w = `${g}-${s}-${$}`;
|
|
97
|
+
let h;
|
|
98
98
|
try {
|
|
99
|
-
|
|
99
|
+
h = oe(w)?.lastSyncedWithServer;
|
|
100
100
|
} catch {
|
|
101
101
|
}
|
|
102
|
-
const
|
|
102
|
+
const i = {
|
|
103
103
|
state: e,
|
|
104
104
|
lastUpdated: Date.now(),
|
|
105
|
-
lastSyncedWithServer:
|
|
106
|
-
},
|
|
105
|
+
lastSyncedWithServer: m ?? h
|
|
106
|
+
}, v = Pe.serialize(i);
|
|
107
107
|
window.localStorage.setItem(
|
|
108
|
-
|
|
109
|
-
JSON.stringify(
|
|
108
|
+
w,
|
|
109
|
+
JSON.stringify(v.json)
|
|
110
110
|
);
|
|
111
111
|
}
|
|
112
112
|
}, oe = (e) => {
|
|
113
113
|
if (!e) return null;
|
|
114
114
|
try {
|
|
115
|
-
const
|
|
116
|
-
return
|
|
117
|
-
} catch (
|
|
118
|
-
return console.error("Error loading from localStorage:",
|
|
115
|
+
const s = window.localStorage.getItem(e);
|
|
116
|
+
return s ? JSON.parse(s) : null;
|
|
117
|
+
} catch (s) {
|
|
118
|
+
return console.error("Error loading from localStorage:", s), null;
|
|
119
119
|
}
|
|
120
|
-
},
|
|
121
|
-
const
|
|
122
|
-
if (
|
|
123
|
-
const
|
|
124
|
-
`${
|
|
120
|
+
}, Re = (e, s) => {
|
|
121
|
+
const y = n.getState().cogsStateStore[e], { sessionId: g } = we(), m = J(s?.localStorage?.key) ? s.localStorage.key(y) : s?.localStorage?.key;
|
|
122
|
+
if (m && g) {
|
|
123
|
+
const $ = oe(
|
|
124
|
+
`${g}-${e}-${m}`
|
|
125
125
|
);
|
|
126
|
-
if (
|
|
127
|
-
return
|
|
126
|
+
if ($ && $.lastUpdated > ($.lastSyncedWithServer || 0))
|
|
127
|
+
return Z(e, $.state), ie(e), !0;
|
|
128
128
|
}
|
|
129
129
|
return !1;
|
|
130
|
-
},
|
|
131
|
-
const
|
|
132
|
-
initialState:
|
|
133
|
-
updaterState:
|
|
130
|
+
}, $e = (e, s, y, g, m, $) => {
|
|
131
|
+
const w = {
|
|
132
|
+
initialState: s,
|
|
133
|
+
updaterState: re(
|
|
134
134
|
e,
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
135
|
+
g,
|
|
136
|
+
m,
|
|
137
|
+
$
|
|
138
138
|
),
|
|
139
|
-
state:
|
|
139
|
+
state: y
|
|
140
140
|
};
|
|
141
|
-
ge(e,
|
|
142
|
-
},
|
|
143
|
-
const
|
|
144
|
-
if (!
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
(
|
|
141
|
+
ge(e, w.initialState), ne(e, w.updaterState), Z(e, w.state);
|
|
142
|
+
}, ie = (e) => {
|
|
143
|
+
const s = n.getState().stateComponents.get(e);
|
|
144
|
+
if (!s) return;
|
|
145
|
+
const y = /* @__PURE__ */ new Set();
|
|
146
|
+
s.components.forEach((g) => {
|
|
147
|
+
(g ? Array.isArray(g.reactiveType) ? g.reactiveType : [g.reactiveType || "component"] : null)?.includes("none") || y.add(() => g.forceUpdate());
|
|
148
148
|
}), queueMicrotask(() => {
|
|
149
|
-
|
|
149
|
+
y.forEach((g) => g());
|
|
150
150
|
});
|
|
151
|
-
},
|
|
152
|
-
const
|
|
153
|
-
if (
|
|
154
|
-
const
|
|
155
|
-
if ((
|
|
151
|
+
}, et = (e, s) => {
|
|
152
|
+
const y = n.getState().stateComponents.get(e);
|
|
153
|
+
if (y) {
|
|
154
|
+
const g = `${e}////${s}`, m = y.components.get(g);
|
|
155
|
+
if ((m ? Array.isArray(m.reactiveType) ? m.reactiveType : [m.reactiveType || "component"] : null)?.includes("none"))
|
|
156
156
|
return;
|
|
157
|
-
|
|
157
|
+
m && m.forceUpdate();
|
|
158
158
|
}
|
|
159
|
-
},
|
|
159
|
+
}, Ue = (e, s, y, g) => {
|
|
160
160
|
switch (e) {
|
|
161
161
|
case "update":
|
|
162
162
|
return {
|
|
163
|
-
oldValue:
|
|
164
|
-
newValue:
|
|
163
|
+
oldValue: L(s, g),
|
|
164
|
+
newValue: L(y, g)
|
|
165
165
|
};
|
|
166
166
|
case "insert":
|
|
167
167
|
return {
|
|
168
168
|
oldValue: null,
|
|
169
169
|
// or undefined
|
|
170
|
-
newValue:
|
|
170
|
+
newValue: L(y, g)
|
|
171
171
|
};
|
|
172
172
|
case "cut":
|
|
173
173
|
return {
|
|
174
|
-
oldValue:
|
|
174
|
+
oldValue: L(s, g),
|
|
175
175
|
newValue: null
|
|
176
176
|
// or undefined
|
|
177
177
|
};
|
|
@@ -179,328 +179,313 @@ const et = (e, i) => {
|
|
|
179
179
|
return { oldValue: null, newValue: null };
|
|
180
180
|
}
|
|
181
181
|
};
|
|
182
|
-
function ue(e, i, S) {
|
|
183
|
-
const l = i.split(".");
|
|
184
|
-
let c = e;
|
|
185
|
-
for (const b of l)
|
|
186
|
-
c.children.has(b) || c.children.set(b, {
|
|
187
|
-
subscribers: /* @__PURE__ */ new Set(),
|
|
188
|
-
children: /* @__PURE__ */ new Map()
|
|
189
|
-
}), c = c.children.get(b);
|
|
190
|
-
c.subscribers.add(S);
|
|
191
|
-
}
|
|
192
|
-
function Ue(e, i, S) {
|
|
193
|
-
const l = i.split(".");
|
|
194
|
-
let c = e;
|
|
195
|
-
for (const b of l)
|
|
196
|
-
if (c = c.children.get(b), !c) return;
|
|
197
|
-
c.subscribers.delete(S);
|
|
198
|
-
}
|
|
199
|
-
function he(e, i) {
|
|
200
|
-
console.log("Getting subscribers for path:", i);
|
|
201
|
-
const S = i.split("."), l = new Set(e.subscribers);
|
|
202
|
-
console.log("Root subscribers:", e.subscribers);
|
|
203
|
-
let c = e;
|
|
204
|
-
for (const b of S) {
|
|
205
|
-
if (c = c.children?.get(b), console.log(`Segment ${b} subscribers:`, c?.subscribers), !c) break;
|
|
206
|
-
c.subscribers.forEach((p) => l.add(p));
|
|
207
|
-
}
|
|
208
|
-
return console.log("Total subscribers found:", l), l;
|
|
209
|
-
}
|
|
210
182
|
function Me(e, {
|
|
211
|
-
stateKey:
|
|
212
|
-
serverSync:
|
|
213
|
-
localStorage:
|
|
214
|
-
formElements:
|
|
215
|
-
reactiveDeps:
|
|
216
|
-
reactiveType:
|
|
217
|
-
componentId:
|
|
218
|
-
initialState:
|
|
219
|
-
syncUpdate:
|
|
183
|
+
stateKey: s,
|
|
184
|
+
serverSync: y,
|
|
185
|
+
localStorage: g,
|
|
186
|
+
formElements: m,
|
|
187
|
+
reactiveDeps: $,
|
|
188
|
+
reactiveType: w,
|
|
189
|
+
componentId: h,
|
|
190
|
+
initialState: i,
|
|
191
|
+
syncUpdate: v,
|
|
220
192
|
dependencies: r,
|
|
221
|
-
serverState:
|
|
193
|
+
serverState: f
|
|
222
194
|
} = {}) {
|
|
223
|
-
const [
|
|
224
|
-
let
|
|
225
|
-
const [
|
|
195
|
+
const [U, C] = te({}), { sessionId: P } = we();
|
|
196
|
+
let M = !s;
|
|
197
|
+
const [S] = te(s ?? ue()), c = n.getState().stateLog[S], Q = ee(/* @__PURE__ */ new Set()), z = ee(h ?? ue()), V = ee(
|
|
226
198
|
null
|
|
227
199
|
);
|
|
228
|
-
|
|
229
|
-
if (
|
|
230
|
-
|
|
231
|
-
...
|
|
232
|
-
[
|
|
200
|
+
V.current = H(S) ?? null, le(() => {
|
|
201
|
+
if (v && v.stateKey === S && v.path?.[0]) {
|
|
202
|
+
Z(S, (a) => ({
|
|
203
|
+
...a,
|
|
204
|
+
[v.path[0]]: v.newValue
|
|
233
205
|
}));
|
|
234
|
-
const t = `${
|
|
206
|
+
const t = `${v.stateKey}:${v.path.join(".")}`;
|
|
235
207
|
n.getState().setSyncInfo(t, {
|
|
236
|
-
timeStamp:
|
|
237
|
-
userId:
|
|
208
|
+
timeStamp: v.timeStamp,
|
|
209
|
+
userId: v.userId
|
|
238
210
|
});
|
|
239
211
|
}
|
|
240
|
-
}, [
|
|
241
|
-
if (
|
|
242
|
-
|
|
243
|
-
initialState:
|
|
212
|
+
}, [v]), le(() => {
|
|
213
|
+
if (i) {
|
|
214
|
+
ye(S, {
|
|
215
|
+
initialState: i
|
|
244
216
|
});
|
|
245
|
-
const t =
|
|
246
|
-
if (!(
|
|
217
|
+
const t = V.current, o = t?.serverState?.id !== void 0 && t?.serverState?.status === "success" && t?.serverState?.data, l = n.getState().initialStateGlobal[S];
|
|
218
|
+
if (!(l && !G(l, i) || !l) && !o)
|
|
247
219
|
return;
|
|
248
|
-
let
|
|
249
|
-
const
|
|
250
|
-
|
|
251
|
-
let
|
|
252
|
-
const
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
),
|
|
220
|
+
let u = null;
|
|
221
|
+
const A = J(t?.localStorage?.key) ? t?.localStorage?.key(i) : t?.localStorage?.key;
|
|
222
|
+
A && P && (u = oe(`${P}-${S}-${A}`));
|
|
223
|
+
let p = i, k = !1;
|
|
224
|
+
const b = o ? Date.now() : 0, N = u?.lastUpdated || 0, _ = u?.lastSyncedWithServer || 0;
|
|
225
|
+
o && b > N ? (p = t.serverState.data, k = !0) : u && N > _ && (p = u.state, t?.localStorage?.onChange && t?.localStorage?.onChange(p)), $e(
|
|
226
|
+
S,
|
|
227
|
+
i,
|
|
228
|
+
p,
|
|
229
|
+
Y,
|
|
230
|
+
z.current,
|
|
231
|
+
P
|
|
232
|
+
), k && A && P && Ie(p, S, t, P, Date.now()), ie(S), (Array.isArray(w) ? w : [w || "component"]).includes("none") || C({});
|
|
261
233
|
}
|
|
262
234
|
}, [
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
235
|
+
i,
|
|
236
|
+
f?.status,
|
|
237
|
+
f?.data,
|
|
266
238
|
...r || []
|
|
267
|
-
]),
|
|
268
|
-
|
|
269
|
-
serverSync:
|
|
270
|
-
formElements:
|
|
271
|
-
initialState:
|
|
272
|
-
localStorage:
|
|
273
|
-
middleware:
|
|
239
|
+
]), pe(() => {
|
|
240
|
+
M && ye(S, {
|
|
241
|
+
serverSync: y,
|
|
242
|
+
formElements: m,
|
|
243
|
+
initialState: i,
|
|
244
|
+
localStorage: g,
|
|
245
|
+
middleware: V.current?.middleware
|
|
274
246
|
});
|
|
275
|
-
const t = `${
|
|
276
|
-
components: /* @__PURE__ */ new Map()
|
|
277
|
-
pathTrie: {
|
|
278
|
-
subscribers: /* @__PURE__ */ new Set(),
|
|
279
|
-
children: /* @__PURE__ */ new Map()
|
|
280
|
-
}
|
|
247
|
+
const t = `${S}////${z.current}`, a = n.getState().stateComponents.get(S) || {
|
|
248
|
+
components: /* @__PURE__ */ new Map()
|
|
281
249
|
};
|
|
282
|
-
return
|
|
283
|
-
forceUpdate: () =>
|
|
250
|
+
return a.components.set(t, {
|
|
251
|
+
forceUpdate: () => C({}),
|
|
284
252
|
paths: /* @__PURE__ */ new Set(),
|
|
285
253
|
deps: [],
|
|
286
|
-
depsFunction:
|
|
287
|
-
reactiveType:
|
|
288
|
-
}), n.getState().stateComponents.set(
|
|
289
|
-
const
|
|
290
|
-
|
|
254
|
+
depsFunction: $ || void 0,
|
|
255
|
+
reactiveType: w ?? ["component", "deps"]
|
|
256
|
+
}), n.getState().stateComponents.set(S, a), C({}), () => {
|
|
257
|
+
const o = `${S}////${z.current}`;
|
|
258
|
+
a && (a.components.delete(o), a.components.size === 0 && n.getState().stateComponents.delete(S));
|
|
291
259
|
};
|
|
292
260
|
}, []);
|
|
293
|
-
const
|
|
294
|
-
if (Array.isArray(
|
|
295
|
-
const
|
|
296
|
-
Q.current.add(
|
|
261
|
+
const Y = (t, a, o, l) => {
|
|
262
|
+
if (Array.isArray(a)) {
|
|
263
|
+
const I = `${S}-${a.join(".")}`;
|
|
264
|
+
Q.current.add(I);
|
|
297
265
|
}
|
|
298
|
-
|
|
299
|
-
const
|
|
300
|
-
if (
|
|
301
|
-
let F = !1,
|
|
302
|
-
if ((!
|
|
303
|
-
const
|
|
304
|
-
if (Array.isArray(
|
|
266
|
+
Z(S, (I) => {
|
|
267
|
+
const u = J(t) ? t(I) : t, A = `${S}-${a.join(".")}`;
|
|
268
|
+
if (A) {
|
|
269
|
+
let F = !1, T = n.getState().signalDomElements.get(A);
|
|
270
|
+
if ((!T || T.size === 0) && (o.updateType === "insert" || o.updateType === "cut")) {
|
|
271
|
+
const x = a.slice(0, -1), D = L(u, x);
|
|
272
|
+
if (Array.isArray(D)) {
|
|
305
273
|
F = !0;
|
|
306
|
-
const
|
|
307
|
-
|
|
274
|
+
const E = `${S}-${x.join(".")}`;
|
|
275
|
+
T = n.getState().signalDomElements.get(E);
|
|
308
276
|
}
|
|
309
277
|
}
|
|
310
|
-
if (
|
|
311
|
-
const
|
|
312
|
-
|
|
313
|
-
const
|
|
314
|
-
`[data-parent-id="${
|
|
278
|
+
if (T) {
|
|
279
|
+
const x = F ? L(u, a.slice(0, -1)) : L(u, a);
|
|
280
|
+
T.forEach(({ parentId: D, position: E, effect: j }) => {
|
|
281
|
+
const O = document.querySelector(
|
|
282
|
+
`[data-parent-id="${D}"]`
|
|
315
283
|
);
|
|
316
|
-
if (
|
|
317
|
-
const
|
|
318
|
-
if (
|
|
319
|
-
const
|
|
320
|
-
|
|
284
|
+
if (O) {
|
|
285
|
+
const q = Array.from(O.childNodes);
|
|
286
|
+
if (q[E]) {
|
|
287
|
+
const R = j ? new Function("state", `return (${j})(state)`)(x) : x;
|
|
288
|
+
q[E].textContent = String(R);
|
|
321
289
|
}
|
|
322
290
|
}
|
|
323
291
|
});
|
|
324
292
|
}
|
|
325
293
|
}
|
|
326
|
-
|
|
327
|
-
(
|
|
294
|
+
o.updateType === "update" && (l || V.current?.validation?.key) && a && B(
|
|
295
|
+
(l || V.current?.validation?.key) + "." + a.join(".")
|
|
328
296
|
);
|
|
329
|
-
const
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
),
|
|
333
|
-
|
|
334
|
-
).filter(([
|
|
335
|
-
let
|
|
336
|
-
if (
|
|
337
|
-
let
|
|
338
|
-
|
|
297
|
+
const p = a.slice(0, a.length - 1);
|
|
298
|
+
o.updateType === "cut" && V.current?.validation?.key && B(
|
|
299
|
+
V.current?.validation?.key + "." + p.join(".")
|
|
300
|
+
), o.updateType === "insert" && V.current?.validation?.key && xe(
|
|
301
|
+
V.current?.validation?.key + "." + p.join(".")
|
|
302
|
+
).filter(([T, x]) => {
|
|
303
|
+
let D = T?.split(".").length;
|
|
304
|
+
if (T == p.join(".") && D == p.length - 1) {
|
|
305
|
+
let E = T + "." + p;
|
|
306
|
+
B(T), je(E, x);
|
|
339
307
|
}
|
|
340
308
|
});
|
|
341
|
-
const
|
|
342
|
-
if (
|
|
343
|
-
const F =
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
).forEach((A) => E.add(A)), console.log("componentsToUpdate", E), E.forEach((A) => {
|
|
355
|
-
const V = w.components.get(A);
|
|
356
|
-
if (V) {
|
|
357
|
-
const C = Array.isArray(V.reactiveType) ? V.reactiveType : [V.reactiveType || "component"];
|
|
358
|
-
if (C.includes("none")) return;
|
|
359
|
-
if (C.includes("all")) {
|
|
360
|
-
V.forceUpdate();
|
|
361
|
-
return;
|
|
309
|
+
const k = n.getState().stateComponents.get(S);
|
|
310
|
+
if (console.log("stateEntry >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>", k), k) {
|
|
311
|
+
const F = de(I, u), T = new Set(F), x = o.updateType === "update" ? a.join(".") : a.slice(0, -1).join(".") || "";
|
|
312
|
+
for (const [
|
|
313
|
+
D,
|
|
314
|
+
E
|
|
315
|
+
] of k.components.entries()) {
|
|
316
|
+
let j = !1;
|
|
317
|
+
const O = Array.isArray(E.reactiveType) ? E.reactiveType : [E.reactiveType || "component"];
|
|
318
|
+
if (console.log("component", E), !O.includes("none")) {
|
|
319
|
+
if (O.includes("all")) {
|
|
320
|
+
E.forceUpdate();
|
|
321
|
+
continue;
|
|
362
322
|
}
|
|
363
|
-
if (
|
|
364
|
-
const
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
323
|
+
if (O.includes("component") && ((E.paths.has(x) || E.paths.has("")) && (j = !0), !j))
|
|
324
|
+
for (const q of T) {
|
|
325
|
+
let R = q;
|
|
326
|
+
for (; ; ) {
|
|
327
|
+
if (E.paths.has(R)) {
|
|
328
|
+
j = !0;
|
|
329
|
+
break;
|
|
330
|
+
}
|
|
331
|
+
const se = R.lastIndexOf(".");
|
|
332
|
+
if (se !== -1) {
|
|
333
|
+
const fe = R.substring(
|
|
334
|
+
0,
|
|
335
|
+
se
|
|
336
|
+
);
|
|
337
|
+
if (!isNaN(
|
|
338
|
+
Number(R.substring(se + 1))
|
|
339
|
+
) && E.paths.has(fe)) {
|
|
340
|
+
j = !0;
|
|
341
|
+
break;
|
|
342
|
+
}
|
|
343
|
+
R = fe;
|
|
344
|
+
} else
|
|
345
|
+
R = "";
|
|
346
|
+
if (R === "")
|
|
347
|
+
break;
|
|
348
|
+
}
|
|
349
|
+
if (j) break;
|
|
369
350
|
}
|
|
351
|
+
if (!j && O.includes("deps") && E.depsFunction) {
|
|
352
|
+
const q = E.depsFunction(u);
|
|
353
|
+
let R = !1;
|
|
354
|
+
typeof q == "boolean" ? q && (R = !0) : G(E.deps, q) || (E.deps = q, R = !0), R && (j = !0);
|
|
370
355
|
}
|
|
371
|
-
|
|
356
|
+
j && E.forceUpdate();
|
|
372
357
|
}
|
|
373
|
-
}
|
|
358
|
+
}
|
|
374
359
|
}
|
|
375
|
-
const
|
|
376
|
-
|
|
377
|
-
const
|
|
378
|
-
return
|
|
360
|
+
const b = Date.now();
|
|
361
|
+
a = a.map((F, T) => {
|
|
362
|
+
const x = a.slice(0, -1), D = L(u, x);
|
|
363
|
+
return T === a.length - 1 && ["insert", "cut"].includes(o.updateType) ? (D.length - 1).toString() : F;
|
|
379
364
|
});
|
|
380
|
-
const { oldValue:
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
),
|
|
386
|
-
timeStamp:
|
|
387
|
-
stateKey:
|
|
388
|
-
path:
|
|
389
|
-
updateType:
|
|
365
|
+
const { oldValue: N, newValue: _ } = Ue(
|
|
366
|
+
o.updateType,
|
|
367
|
+
I,
|
|
368
|
+
u,
|
|
369
|
+
a
|
|
370
|
+
), W = {
|
|
371
|
+
timeStamp: b,
|
|
372
|
+
stateKey: S,
|
|
373
|
+
path: a,
|
|
374
|
+
updateType: o.updateType,
|
|
390
375
|
status: "new",
|
|
391
|
-
oldValue:
|
|
392
|
-
newValue:
|
|
376
|
+
oldValue: N,
|
|
377
|
+
newValue: _
|
|
393
378
|
};
|
|
394
|
-
if (Oe(
|
|
395
|
-
const
|
|
396
|
-
const
|
|
397
|
-
return
|
|
379
|
+
if (Oe(S, (F) => {
|
|
380
|
+
const x = [...F ?? [], W].reduce((D, E) => {
|
|
381
|
+
const j = `${E.stateKey}:${JSON.stringify(E.path)}`, O = D.get(j);
|
|
382
|
+
return O ? (O.timeStamp = Math.max(O.timeStamp, E.timeStamp), O.newValue = E.newValue, O.oldValue = O.oldValue ?? E.oldValue, O.updateType = E.updateType) : D.set(j, { ...E }), D;
|
|
398
383
|
}, /* @__PURE__ */ new Map());
|
|
399
|
-
return Array.from(
|
|
400
|
-
}),
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
),
|
|
406
|
-
updateLog:
|
|
407
|
-
update:
|
|
408
|
-
}),
|
|
409
|
-
const F = n.getState().serverState[
|
|
410
|
-
|
|
411
|
-
syncKey: typeof
|
|
384
|
+
return Array.from(x.values());
|
|
385
|
+
}), Ie(
|
|
386
|
+
u,
|
|
387
|
+
S,
|
|
388
|
+
V.current,
|
|
389
|
+
P
|
|
390
|
+
), V.current?.middleware && V.current.middleware({
|
|
391
|
+
updateLog: c,
|
|
392
|
+
update: W
|
|
393
|
+
}), V.current?.serverSync) {
|
|
394
|
+
const F = n.getState().serverState[S], T = V.current?.serverSync;
|
|
395
|
+
Fe(S, {
|
|
396
|
+
syncKey: typeof T.syncKey == "string" ? T.syncKey : T.syncKey({ state: u }),
|
|
412
397
|
rollBackState: F,
|
|
413
|
-
actionTimeStamp: Date.now() + (
|
|
398
|
+
actionTimeStamp: Date.now() + (T.debounce ?? 3e3),
|
|
414
399
|
status: "waiting"
|
|
415
400
|
});
|
|
416
401
|
}
|
|
417
|
-
return
|
|
402
|
+
return u;
|
|
418
403
|
});
|
|
419
404
|
};
|
|
420
|
-
n.getState().updaterState[
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
405
|
+
n.getState().updaterState[S] || (ne(
|
|
406
|
+
S,
|
|
407
|
+
re(
|
|
408
|
+
S,
|
|
409
|
+
Y,
|
|
410
|
+
z.current,
|
|
411
|
+
P
|
|
427
412
|
)
|
|
428
|
-
), n.getState().cogsStateStore[
|
|
429
|
-
const
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
), [
|
|
435
|
-
return [
|
|
413
|
+
), n.getState().cogsStateStore[S] || Z(S, e), n.getState().initialStateGlobal[S] || ge(S, e));
|
|
414
|
+
const d = ke(() => re(
|
|
415
|
+
S,
|
|
416
|
+
Y,
|
|
417
|
+
z.current,
|
|
418
|
+
P
|
|
419
|
+
), [S, P]);
|
|
420
|
+
return [Ee(S), d];
|
|
436
421
|
}
|
|
437
|
-
function
|
|
438
|
-
const
|
|
439
|
-
let
|
|
440
|
-
const
|
|
441
|
-
const r =
|
|
442
|
-
for (const [
|
|
443
|
-
(
|
|
444
|
-
|
|
445
|
-
},
|
|
446
|
-
removeValidation: (
|
|
447
|
-
|
|
422
|
+
function re(e, s, y, g) {
|
|
423
|
+
const m = /* @__PURE__ */ new Map();
|
|
424
|
+
let $ = 0;
|
|
425
|
+
const w = (v) => {
|
|
426
|
+
const r = v.join(".");
|
|
427
|
+
for (const [f] of m)
|
|
428
|
+
(f === r || f.startsWith(r + ".")) && m.delete(f);
|
|
429
|
+
$++;
|
|
430
|
+
}, h = {
|
|
431
|
+
removeValidation: (v) => {
|
|
432
|
+
v?.validationKey && B(v.validationKey);
|
|
448
433
|
},
|
|
449
|
-
revertToInitialState: (
|
|
434
|
+
revertToInitialState: (v) => {
|
|
450
435
|
const r = n.getState().getInitialOptions(e)?.validation;
|
|
451
|
-
r?.key &&
|
|
452
|
-
const
|
|
453
|
-
n.getState().clearSelectedIndexesForState(e),
|
|
454
|
-
const
|
|
455
|
-
|
|
456
|
-
const
|
|
457
|
-
return
|
|
458
|
-
|
|
459
|
-
}),
|
|
436
|
+
r?.key && B(r?.key), v?.validationKey && B(v.validationKey);
|
|
437
|
+
const f = n.getState().initialStateGlobal[e];
|
|
438
|
+
n.getState().clearSelectedIndexesForState(e), m.clear(), $++;
|
|
439
|
+
const U = i(f, []), C = H(e), P = J(C?.localStorage?.key) ? C?.localStorage?.key(f) : C?.localStorage?.key, M = `${g}-${e}-${P}`;
|
|
440
|
+
M && localStorage.removeItem(M), ne(e, U), Z(e, f);
|
|
441
|
+
const S = n.getState().stateComponents.get(e);
|
|
442
|
+
return S && S.components.forEach((c) => {
|
|
443
|
+
c.forceUpdate();
|
|
444
|
+
}), f;
|
|
460
445
|
},
|
|
461
|
-
updateInitialState: (
|
|
462
|
-
|
|
463
|
-
const r =
|
|
446
|
+
updateInitialState: (v) => {
|
|
447
|
+
m.clear(), $++;
|
|
448
|
+
const r = re(
|
|
464
449
|
e,
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
),
|
|
469
|
-
return localStorage.getItem(
|
|
470
|
-
ge(e,
|
|
471
|
-
const
|
|
472
|
-
|
|
473
|
-
|
|
450
|
+
s,
|
|
451
|
+
y,
|
|
452
|
+
g
|
|
453
|
+
), f = n.getState().initialStateGlobal[e], U = H(e), C = J(U?.localStorage?.key) ? U?.localStorage?.key(f) : U?.localStorage?.key, P = `${g}-${e}-${C}`;
|
|
454
|
+
return localStorage.getItem(P) && localStorage.removeItem(P), Ae(() => {
|
|
455
|
+
ge(e, v), ne(e, r), Z(e, v);
|
|
456
|
+
const M = n.getState().stateComponents.get(e);
|
|
457
|
+
M && M.components.forEach((S) => {
|
|
458
|
+
S.forceUpdate();
|
|
474
459
|
});
|
|
475
460
|
}), {
|
|
476
|
-
fetchId: (
|
|
461
|
+
fetchId: (M) => r.get()[M]
|
|
477
462
|
};
|
|
478
463
|
},
|
|
479
464
|
_initialState: n.getState().initialStateGlobal[e],
|
|
480
465
|
_serverState: n.getState().serverState[e],
|
|
481
466
|
_isLoading: n.getState().isLoadingGlobal[e],
|
|
482
467
|
_isServerSynced: () => {
|
|
483
|
-
const
|
|
484
|
-
return !!(
|
|
468
|
+
const v = n.getState().serverState[e];
|
|
469
|
+
return !!(v && G(v, Ee(e)));
|
|
485
470
|
}
|
|
486
471
|
};
|
|
487
|
-
function
|
|
488
|
-
const
|
|
489
|
-
|
|
490
|
-
const
|
|
472
|
+
function i(v, r = [], f) {
|
|
473
|
+
const U = r.map(String).join(".");
|
|
474
|
+
m.get(U);
|
|
475
|
+
const C = function() {
|
|
491
476
|
return n().getNestedState(e, r);
|
|
492
477
|
};
|
|
493
|
-
Object.keys(
|
|
494
|
-
|
|
478
|
+
Object.keys(h).forEach((S) => {
|
|
479
|
+
C[S] = h[S];
|
|
495
480
|
});
|
|
496
|
-
const
|
|
497
|
-
apply(
|
|
481
|
+
const P = {
|
|
482
|
+
apply(S, c, Q) {
|
|
498
483
|
return console.log(
|
|
499
484
|
`PROXY APPLY TRAP HIT: stateKey=${e}, path=${r.join(".")}`
|
|
500
485
|
), console.trace("Apply trap stack trace"), n().getNestedState(e, r);
|
|
501
486
|
},
|
|
502
|
-
get(
|
|
503
|
-
|
|
487
|
+
get(S, c) {
|
|
488
|
+
f?.validIndices && !Array.isArray(v) && (f = { ...f, validIndices: void 0 });
|
|
504
489
|
const Q = /* @__PURE__ */ new Set([
|
|
505
490
|
"insert",
|
|
506
491
|
"cut",
|
|
@@ -524,586 +509,560 @@ function ne(e, i, S, l) {
|
|
|
524
509
|
"_stateKey",
|
|
525
510
|
"getComponents"
|
|
526
511
|
]);
|
|
527
|
-
if (
|
|
528
|
-
const
|
|
529
|
-
if (
|
|
530
|
-
const
|
|
531
|
-
if (
|
|
532
|
-
const
|
|
533
|
-
let
|
|
534
|
-
for (const
|
|
535
|
-
if (
|
|
536
|
-
|
|
512
|
+
if (c !== "then" && !c.startsWith("$") && c !== "stateMapNoRender" && !Q.has(c)) {
|
|
513
|
+
const d = `${e}////${y}`, t = n.getState().stateComponents.get(e);
|
|
514
|
+
if (t) {
|
|
515
|
+
const a = t.components.get(d);
|
|
516
|
+
if (a && !a.paths.has("")) {
|
|
517
|
+
const o = r.join(".");
|
|
518
|
+
let l = !0;
|
|
519
|
+
for (const I of a.paths)
|
|
520
|
+
if (o.startsWith(I) && (o === I || o[I.length] === ".")) {
|
|
521
|
+
l = !1;
|
|
537
522
|
break;
|
|
538
523
|
}
|
|
539
|
-
|
|
540
|
-
console.log(
|
|
541
|
-
"ADDING PATH:",
|
|
542
|
-
a,
|
|
543
|
-
"for component:",
|
|
544
|
-
u
|
|
545
|
-
), o.paths.add(a);
|
|
546
|
-
const v = n.getState().stateComponents.get(e);
|
|
547
|
-
v && v.pathTrie ? (console.log(
|
|
548
|
-
"ADDING TO TRIE:",
|
|
549
|
-
a,
|
|
550
|
-
u
|
|
551
|
-
), ue(
|
|
552
|
-
v.pathTrie,
|
|
553
|
-
a,
|
|
554
|
-
u
|
|
555
|
-
), console.log("TRIE AFTER ADD:", v.pathTrie)) : console.log("NO TRIE FOUND for state:", e);
|
|
556
|
-
}
|
|
524
|
+
l && a.paths.add(o);
|
|
557
525
|
}
|
|
558
526
|
}
|
|
559
527
|
}
|
|
560
|
-
if (
|
|
561
|
-
return () =>
|
|
528
|
+
if (c === "getDifferences")
|
|
529
|
+
return () => de(
|
|
562
530
|
n.getState().cogsStateStore[e],
|
|
563
531
|
n.getState().initialStateGlobal[e]
|
|
564
532
|
);
|
|
565
|
-
if (
|
|
533
|
+
if (c === "sync" && r.length === 0)
|
|
566
534
|
return async function() {
|
|
567
|
-
const
|
|
535
|
+
const d = n.getState().getInitialOptions(e), t = d?.sync;
|
|
568
536
|
if (!t)
|
|
569
537
|
return console.error(`No mutation defined for state key "${e}"`), { success: !1, error: "No mutation defined" };
|
|
570
|
-
const
|
|
538
|
+
const a = n.getState().getNestedState(e, []), o = d?.validation?.key;
|
|
571
539
|
try {
|
|
572
|
-
const
|
|
573
|
-
if (
|
|
574
|
-
n.getState().removeValidationError(
|
|
575
|
-
const
|
|
576
|
-
n.getState().addValidationError(
|
|
540
|
+
const l = await t.action(a);
|
|
541
|
+
if (l && !l.success && l.errors && o) {
|
|
542
|
+
n.getState().removeValidationError(o), l.errors.forEach((u) => {
|
|
543
|
+
const A = [o, ...u.path].join(".");
|
|
544
|
+
n.getState().addValidationError(A, u.message);
|
|
577
545
|
});
|
|
578
|
-
const
|
|
579
|
-
|
|
580
|
-
|
|
546
|
+
const I = n.getState().stateComponents.get(e);
|
|
547
|
+
I && I.components.forEach((u) => {
|
|
548
|
+
u.forceUpdate();
|
|
581
549
|
});
|
|
582
550
|
}
|
|
583
|
-
return
|
|
584
|
-
} catch (
|
|
585
|
-
return t.onError && t.onError(
|
|
551
|
+
return l?.success && t.onSuccess ? t.onSuccess(l.data) : !l?.success && t.onError && t.onError(l.error), l;
|
|
552
|
+
} catch (l) {
|
|
553
|
+
return t.onError && t.onError(l), { success: !1, error: l };
|
|
586
554
|
}
|
|
587
555
|
};
|
|
588
|
-
if (
|
|
589
|
-
const
|
|
590
|
-
return
|
|
556
|
+
if (c === "_status") {
|
|
557
|
+
const d = n.getState().getNestedState(e, r), t = n.getState().initialStateGlobal[e], a = L(t, r);
|
|
558
|
+
return G(d, a) ? "fresh" : "stale";
|
|
591
559
|
}
|
|
592
|
-
if (
|
|
560
|
+
if (c === "getStatus")
|
|
593
561
|
return function() {
|
|
594
|
-
const
|
|
562
|
+
const d = n().getNestedState(
|
|
595
563
|
e,
|
|
596
564
|
r
|
|
597
|
-
), t = n.getState().initialStateGlobal[e],
|
|
598
|
-
return
|
|
565
|
+
), t = n.getState().initialStateGlobal[e], a = L(t, r);
|
|
566
|
+
return G(d, a) ? "fresh" : "stale";
|
|
599
567
|
};
|
|
600
|
-
if (
|
|
568
|
+
if (c === "removeStorage")
|
|
601
569
|
return () => {
|
|
602
|
-
const
|
|
603
|
-
|
|
570
|
+
const d = n.getState().initialStateGlobal[e], t = H(e), a = J(t?.localStorage?.key) ? t?.localStorage?.key(d) : t?.localStorage?.key, o = `${g}-${e}-${a}`;
|
|
571
|
+
o && localStorage.removeItem(o);
|
|
604
572
|
};
|
|
605
|
-
if (
|
|
573
|
+
if (c === "showValidationErrors")
|
|
606
574
|
return () => {
|
|
607
|
-
const
|
|
608
|
-
if (!
|
|
575
|
+
const d = n.getState().getInitialOptions(e)?.validation;
|
|
576
|
+
if (!d?.key)
|
|
609
577
|
throw new Error("Validation key not found");
|
|
610
|
-
return n.getState().getValidationErrors(
|
|
578
|
+
return n.getState().getValidationErrors(d.key + "." + r.join("."));
|
|
611
579
|
};
|
|
612
|
-
if (Array.isArray(
|
|
613
|
-
const
|
|
614
|
-
item:
|
|
615
|
-
originalIndex:
|
|
616
|
-
})) : n.getState().getNestedState(e, r).map((
|
|
617
|
-
item:
|
|
618
|
-
originalIndex:
|
|
580
|
+
if (Array.isArray(v)) {
|
|
581
|
+
const d = () => f?.validIndices ? v.map((a, o) => ({
|
|
582
|
+
item: a,
|
|
583
|
+
originalIndex: f.validIndices[o]
|
|
584
|
+
})) : n.getState().getNestedState(e, r).map((a, o) => ({
|
|
585
|
+
item: a,
|
|
586
|
+
originalIndex: o
|
|
619
587
|
}));
|
|
620
|
-
if (
|
|
588
|
+
if (c === "getSelected")
|
|
621
589
|
return () => {
|
|
622
590
|
const t = n.getState().getSelectedIndex(e, r.join("."));
|
|
623
591
|
if (t !== void 0)
|
|
624
|
-
return
|
|
625
|
-
|
|
592
|
+
return i(
|
|
593
|
+
v[t],
|
|
626
594
|
[...r, t.toString()],
|
|
627
|
-
|
|
595
|
+
f
|
|
628
596
|
);
|
|
629
597
|
};
|
|
630
|
-
if (
|
|
598
|
+
if (c === "clearSelected")
|
|
631
599
|
return () => {
|
|
632
600
|
n.getState().clearSelectedIndex({ stateKey: e, path: r });
|
|
633
601
|
};
|
|
634
|
-
if (
|
|
602
|
+
if (c === "getSelectedIndex")
|
|
635
603
|
return () => n.getState().getSelectedIndex(e, r.join(".")) ?? -1;
|
|
636
|
-
if (
|
|
604
|
+
if (c === "stateSort")
|
|
637
605
|
return (t) => {
|
|
638
|
-
const
|
|
639
|
-
(
|
|
640
|
-
),
|
|
641
|
-
...
|
|
642
|
-
validIndices:
|
|
643
|
-
({ originalIndex:
|
|
606
|
+
const o = [...d()].sort(
|
|
607
|
+
(u, A) => t(u.item, A.item)
|
|
608
|
+
), l = o.map(({ item: u }) => u), I = {
|
|
609
|
+
...f,
|
|
610
|
+
validIndices: o.map(
|
|
611
|
+
({ originalIndex: u }) => u
|
|
644
612
|
)
|
|
645
613
|
};
|
|
646
|
-
return
|
|
614
|
+
return i(l, r, I);
|
|
647
615
|
};
|
|
648
|
-
if (
|
|
616
|
+
if (c === "stateFilter")
|
|
649
617
|
return (t) => {
|
|
650
|
-
const
|
|
651
|
-
({ item:
|
|
652
|
-
),
|
|
653
|
-
...
|
|
654
|
-
validIndices:
|
|
655
|
-
({ originalIndex:
|
|
618
|
+
const o = d().filter(
|
|
619
|
+
({ item: u }, A) => t(u, A)
|
|
620
|
+
), l = o.map(({ item: u }) => u), I = {
|
|
621
|
+
...f,
|
|
622
|
+
validIndices: o.map(
|
|
623
|
+
({ originalIndex: u }) => u
|
|
656
624
|
)
|
|
657
625
|
};
|
|
658
|
-
return
|
|
626
|
+
return i(l, r, I);
|
|
659
627
|
};
|
|
660
|
-
if (
|
|
628
|
+
if (c === "stateMap")
|
|
661
629
|
return (t) => {
|
|
662
|
-
const
|
|
663
|
-
return
|
|
664
|
-
let
|
|
665
|
-
|
|
666
|
-
const
|
|
667
|
-
return
|
|
668
|
-
|
|
630
|
+
const a = n.getState().getNestedState(e, r);
|
|
631
|
+
return Array.isArray(a) ? a.map((o, l) => {
|
|
632
|
+
let I;
|
|
633
|
+
f?.validIndices && f.validIndices[l] !== void 0 ? I = f.validIndices[l] : I = l;
|
|
634
|
+
const u = [...r, I.toString()], A = i(o, u, f);
|
|
635
|
+
return t(o, A, {
|
|
636
|
+
register: () => {
|
|
637
|
+
const [, k] = te({}), b = `${y}-${r.join(".")}-${I}`;
|
|
638
|
+
pe(() => {
|
|
639
|
+
const N = `${e}////${b}`, _ = n.getState().stateComponents.get(e) || {
|
|
640
|
+
components: /* @__PURE__ */ new Map()
|
|
641
|
+
};
|
|
642
|
+
return _.components.set(N, {
|
|
643
|
+
forceUpdate: () => k({}),
|
|
644
|
+
paths: /* @__PURE__ */ new Set([u.join(".")])
|
|
645
|
+
// ATOMIC: Subscribes only to this item's path.
|
|
646
|
+
}), n.getState().stateComponents.set(e, _), () => {
|
|
647
|
+
const W = n.getState().stateComponents.get(e);
|
|
648
|
+
W && W.components.delete(N);
|
|
649
|
+
};
|
|
650
|
+
}, [e, b]);
|
|
669
651
|
},
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
f.join("."),
|
|
678
|
-
w
|
|
679
|
-
)), t(
|
|
680
|
-
a,
|
|
681
|
-
$,
|
|
682
|
-
g,
|
|
683
|
-
o,
|
|
684
|
-
s(o, r, m)
|
|
685
|
-
);
|
|
686
|
-
});
|
|
652
|
+
index: l,
|
|
653
|
+
originalIndex: I
|
|
654
|
+
});
|
|
655
|
+
}) : (console.warn(
|
|
656
|
+
`stateMap called on a non-array value at path: ${r.join(".")}. The current value is:`,
|
|
657
|
+
a
|
|
658
|
+
), null);
|
|
687
659
|
};
|
|
688
|
-
if (
|
|
689
|
-
return (t) =>
|
|
690
|
-
let
|
|
691
|
-
|
|
692
|
-
const
|
|
660
|
+
if (c === "stateMapNoRender")
|
|
661
|
+
return (t) => v.map((o, l) => {
|
|
662
|
+
let I;
|
|
663
|
+
f?.validIndices && f.validIndices[l] !== void 0 ? I = f.validIndices[l] : I = l;
|
|
664
|
+
const u = [...r, I.toString()], A = i(o, u, f);
|
|
693
665
|
return t(
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
666
|
+
o,
|
|
667
|
+
A,
|
|
668
|
+
l,
|
|
669
|
+
v,
|
|
670
|
+
i(v, r, f)
|
|
699
671
|
);
|
|
700
672
|
});
|
|
701
|
-
if (
|
|
702
|
-
return (t) =>
|
|
673
|
+
if (c === "$stateMap")
|
|
674
|
+
return (t) => ae(De, {
|
|
703
675
|
proxy: {
|
|
704
676
|
_stateKey: e,
|
|
705
677
|
_path: r,
|
|
706
678
|
_mapFn: t
|
|
707
679
|
// Pass the actual function, not string
|
|
708
680
|
},
|
|
709
|
-
rebuildStateShape:
|
|
681
|
+
rebuildStateShape: i
|
|
710
682
|
});
|
|
711
|
-
if (
|
|
683
|
+
if (c === "stateFlattenOn")
|
|
712
684
|
return (t) => {
|
|
713
|
-
const
|
|
714
|
-
|
|
715
|
-
const
|
|
716
|
-
(
|
|
685
|
+
const a = v;
|
|
686
|
+
m.clear(), $++;
|
|
687
|
+
const o = a.flatMap(
|
|
688
|
+
(l) => l[t] ?? []
|
|
717
689
|
);
|
|
718
|
-
return
|
|
719
|
-
|
|
690
|
+
return i(
|
|
691
|
+
o,
|
|
720
692
|
[...r, "[*]", t],
|
|
721
|
-
|
|
693
|
+
f
|
|
722
694
|
);
|
|
723
695
|
};
|
|
724
|
-
if (
|
|
696
|
+
if (c === "index")
|
|
725
697
|
return (t) => {
|
|
726
|
-
const
|
|
727
|
-
return
|
|
698
|
+
const a = v[t];
|
|
699
|
+
return i(a, [...r, t.toString()]);
|
|
728
700
|
};
|
|
729
|
-
if (
|
|
701
|
+
if (c === "last")
|
|
730
702
|
return () => {
|
|
731
703
|
const t = n.getState().getNestedState(e, r);
|
|
732
704
|
if (t.length === 0) return;
|
|
733
|
-
const
|
|
734
|
-
return
|
|
705
|
+
const a = t.length - 1, o = t[a], l = [...r, a.toString()];
|
|
706
|
+
return i(o, l);
|
|
735
707
|
};
|
|
736
|
-
if (
|
|
737
|
-
return (t) => (
|
|
708
|
+
if (c === "insert")
|
|
709
|
+
return (t) => (w(r), ce(s, t, r, e), i(
|
|
738
710
|
n.getState().getNestedState(e, r),
|
|
739
711
|
r
|
|
740
712
|
));
|
|
741
|
-
if (
|
|
742
|
-
return (t,
|
|
743
|
-
const
|
|
744
|
-
let
|
|
745
|
-
if (!
|
|
746
|
-
if (
|
|
747
|
-
const
|
|
748
|
-
(
|
|
713
|
+
if (c === "uniqueInsert")
|
|
714
|
+
return (t, a, o) => {
|
|
715
|
+
const l = n.getState().getNestedState(e, r), I = J(t) ? t(l) : t;
|
|
716
|
+
let u = null;
|
|
717
|
+
if (!l.some((p) => {
|
|
718
|
+
if (a) {
|
|
719
|
+
const b = a.every(
|
|
720
|
+
(N) => G(p[N], I[N])
|
|
749
721
|
);
|
|
750
|
-
return
|
|
722
|
+
return b && (u = p), b;
|
|
751
723
|
}
|
|
752
|
-
const
|
|
753
|
-
return
|
|
724
|
+
const k = G(p, I);
|
|
725
|
+
return k && (u = p), k;
|
|
754
726
|
}))
|
|
755
|
-
|
|
756
|
-
else if (
|
|
757
|
-
const
|
|
758
|
-
(
|
|
727
|
+
w(r), ce(s, I, r, e);
|
|
728
|
+
else if (o && u) {
|
|
729
|
+
const p = o(u), k = l.map(
|
|
730
|
+
(b) => G(b, u) ? p : b
|
|
759
731
|
);
|
|
760
|
-
|
|
732
|
+
w(r), X(s, k, r);
|
|
761
733
|
}
|
|
762
734
|
};
|
|
763
|
-
if (
|
|
764
|
-
return (t,
|
|
765
|
-
if (!
|
|
766
|
-
return
|
|
735
|
+
if (c === "cut")
|
|
736
|
+
return (t, a) => {
|
|
737
|
+
if (!a?.waitForSync)
|
|
738
|
+
return w(r), K(s, r, e, t), i(
|
|
767
739
|
n.getState().getNestedState(e, r),
|
|
768
740
|
r
|
|
769
741
|
);
|
|
770
742
|
};
|
|
771
|
-
if (
|
|
743
|
+
if (c === "cutByValue")
|
|
772
744
|
return (t) => {
|
|
773
|
-
for (let
|
|
774
|
-
|
|
745
|
+
for (let a = 0; a < v.length; a++)
|
|
746
|
+
v[a] === t && K(s, r, e, a);
|
|
775
747
|
};
|
|
776
|
-
if (
|
|
748
|
+
if (c === "toggleByValue")
|
|
777
749
|
return (t) => {
|
|
778
|
-
const
|
|
779
|
-
|
|
750
|
+
const a = v.findIndex((o) => o === t);
|
|
751
|
+
a > -1 ? K(s, r, e, a) : ce(s, t, r, e);
|
|
780
752
|
};
|
|
781
|
-
if (
|
|
753
|
+
if (c === "stateFind")
|
|
782
754
|
return (t) => {
|
|
783
|
-
const
|
|
784
|
-
({ item:
|
|
755
|
+
const o = d().find(
|
|
756
|
+
({ item: I }, u) => t(I, u)
|
|
785
757
|
);
|
|
786
|
-
if (!
|
|
787
|
-
const
|
|
788
|
-
return
|
|
758
|
+
if (!o) return;
|
|
759
|
+
const l = [...r, o.originalIndex.toString()];
|
|
760
|
+
return i(o.item, l, f);
|
|
789
761
|
};
|
|
790
|
-
if (
|
|
791
|
-
return (t,
|
|
792
|
-
const
|
|
793
|
-
({ item:
|
|
762
|
+
if (c === "findWith")
|
|
763
|
+
return (t, a) => {
|
|
764
|
+
const l = d().find(
|
|
765
|
+
({ item: u }) => u[t] === a
|
|
794
766
|
);
|
|
795
|
-
if (!
|
|
796
|
-
const
|
|
797
|
-
return
|
|
767
|
+
if (!l) return;
|
|
768
|
+
const I = [...r, l.originalIndex.toString()];
|
|
769
|
+
return i(l.item, I, f);
|
|
798
770
|
};
|
|
799
771
|
}
|
|
800
|
-
const
|
|
801
|
-
if (!isNaN(Number(
|
|
802
|
-
const
|
|
803
|
-
if (Array.isArray(t) &&
|
|
772
|
+
const z = r[r.length - 1];
|
|
773
|
+
if (!isNaN(Number(z))) {
|
|
774
|
+
const d = r.slice(0, -1), t = n.getState().getNestedState(e, d);
|
|
775
|
+
if (Array.isArray(t) && c === "cut")
|
|
804
776
|
return () => K(
|
|
805
|
-
|
|
806
|
-
|
|
777
|
+
s,
|
|
778
|
+
d,
|
|
807
779
|
e,
|
|
808
|
-
Number(
|
|
780
|
+
Number(z)
|
|
809
781
|
);
|
|
810
782
|
}
|
|
811
|
-
if (
|
|
783
|
+
if (c === "get")
|
|
812
784
|
return () => n.getState().getNestedState(e, r);
|
|
813
|
-
if (
|
|
814
|
-
return (
|
|
785
|
+
if (c === "$derive")
|
|
786
|
+
return (d) => he({
|
|
815
787
|
_stateKey: e,
|
|
816
788
|
_path: r,
|
|
817
|
-
_effect:
|
|
789
|
+
_effect: d.toString()
|
|
818
790
|
});
|
|
819
|
-
if (
|
|
820
|
-
return () =>
|
|
791
|
+
if (c === "$get")
|
|
792
|
+
return () => he({
|
|
821
793
|
_stateKey: e,
|
|
822
794
|
_path: r
|
|
823
795
|
});
|
|
824
|
-
if (
|
|
825
|
-
const
|
|
826
|
-
return n.getState().getSyncInfo(
|
|
796
|
+
if (c === "lastSynced") {
|
|
797
|
+
const d = `${e}:${r.join(".")}`;
|
|
798
|
+
return n.getState().getSyncInfo(d);
|
|
827
799
|
}
|
|
828
|
-
if (
|
|
829
|
-
return (
|
|
830
|
-
if (
|
|
831
|
-
const
|
|
832
|
-
return Array.isArray(
|
|
800
|
+
if (c == "getLocalStorage")
|
|
801
|
+
return (d) => oe(g + "-" + e + "-" + d);
|
|
802
|
+
if (c === "_selected") {
|
|
803
|
+
const d = r.slice(0, -1), t = d.join("."), a = n.getState().getNestedState(e, d);
|
|
804
|
+
return Array.isArray(a) ? Number(r[r.length - 1]) === n.getState().getSelectedIndex(e, t) : void 0;
|
|
833
805
|
}
|
|
834
|
-
if (
|
|
835
|
-
return (
|
|
836
|
-
const t = r.slice(0, -1),
|
|
837
|
-
|
|
838
|
-
const
|
|
839
|
-
X(
|
|
806
|
+
if (c === "setSelected")
|
|
807
|
+
return (d) => {
|
|
808
|
+
const t = r.slice(0, -1), a = Number(r[r.length - 1]), o = t.join(".");
|
|
809
|
+
d ? n.getState().setSelectedIndex(e, o, a) : n.getState().setSelectedIndex(e, o, void 0);
|
|
810
|
+
const l = n.getState().getNestedState(e, [...t]);
|
|
811
|
+
X(s, l, t), w(t);
|
|
840
812
|
};
|
|
841
|
-
if (
|
|
813
|
+
if (c === "toggleSelected")
|
|
842
814
|
return () => {
|
|
843
|
-
const
|
|
815
|
+
const d = r.slice(0, -1), t = Number(r[r.length - 1]), a = d.join("."), o = n.getState().getSelectedIndex(e, a);
|
|
844
816
|
n.getState().setSelectedIndex(
|
|
845
817
|
e,
|
|
846
|
-
|
|
847
|
-
|
|
818
|
+
a,
|
|
819
|
+
o === t ? void 0 : t
|
|
848
820
|
);
|
|
849
|
-
const
|
|
850
|
-
X(
|
|
821
|
+
const l = n.getState().getNestedState(e, [...d]);
|
|
822
|
+
X(s, l, d), w(d);
|
|
851
823
|
};
|
|
852
824
|
if (r.length == 0) {
|
|
853
|
-
if (
|
|
854
|
-
return (
|
|
855
|
-
const t = n.getState().cogsStateStore[e],
|
|
856
|
-
|
|
825
|
+
if (c === "applyJsonPatch")
|
|
826
|
+
return (d) => {
|
|
827
|
+
const t = n.getState().cogsStateStore[e], o = _e(t, d).newDocument;
|
|
828
|
+
$e(
|
|
857
829
|
e,
|
|
858
830
|
n.getState().initialStateGlobal[e],
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
831
|
+
o,
|
|
832
|
+
s,
|
|
833
|
+
y,
|
|
834
|
+
g
|
|
863
835
|
);
|
|
864
|
-
const
|
|
865
|
-
if (
|
|
866
|
-
const
|
|
836
|
+
const l = n.getState().stateComponents.get(e);
|
|
837
|
+
if (l) {
|
|
838
|
+
const I = de(t, o), u = new Set(I);
|
|
867
839
|
for (const [
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
] of
|
|
871
|
-
let
|
|
872
|
-
const
|
|
873
|
-
if (!
|
|
874
|
-
if (
|
|
875
|
-
|
|
840
|
+
A,
|
|
841
|
+
p
|
|
842
|
+
] of l.components.entries()) {
|
|
843
|
+
let k = !1;
|
|
844
|
+
const b = Array.isArray(p.reactiveType) ? p.reactiveType : [p.reactiveType || "component"];
|
|
845
|
+
if (!b.includes("none")) {
|
|
846
|
+
if (b.includes("all")) {
|
|
847
|
+
p.forceUpdate();
|
|
876
848
|
continue;
|
|
877
849
|
}
|
|
878
|
-
if (
|
|
879
|
-
for (const
|
|
880
|
-
if (
|
|
881
|
-
|
|
850
|
+
if (b.includes("component") && (p.paths.has("") && (k = !0), !k))
|
|
851
|
+
for (const N of u) {
|
|
852
|
+
if (p.paths.has(N)) {
|
|
853
|
+
k = !0;
|
|
882
854
|
break;
|
|
883
855
|
}
|
|
884
|
-
let
|
|
885
|
-
for (;
|
|
886
|
-
const
|
|
887
|
-
if (
|
|
888
|
-
|
|
856
|
+
let _ = N.lastIndexOf(".");
|
|
857
|
+
for (; _ !== -1; ) {
|
|
858
|
+
const W = N.substring(0, _);
|
|
859
|
+
if (p.paths.has(W)) {
|
|
860
|
+
k = !0;
|
|
889
861
|
break;
|
|
890
862
|
}
|
|
891
|
-
const F =
|
|
892
|
-
|
|
863
|
+
const F = N.substring(
|
|
864
|
+
_ + 1
|
|
893
865
|
);
|
|
894
866
|
if (!isNaN(Number(F))) {
|
|
895
|
-
const
|
|
896
|
-
if (
|
|
897
|
-
const
|
|
867
|
+
const T = W.lastIndexOf(".");
|
|
868
|
+
if (T !== -1) {
|
|
869
|
+
const x = W.substring(
|
|
898
870
|
0,
|
|
899
|
-
|
|
871
|
+
T
|
|
900
872
|
);
|
|
901
|
-
if (
|
|
902
|
-
|
|
873
|
+
if (p.paths.has(x)) {
|
|
874
|
+
k = !0;
|
|
903
875
|
break;
|
|
904
876
|
}
|
|
905
877
|
}
|
|
906
878
|
}
|
|
907
|
-
|
|
879
|
+
_ = W.lastIndexOf(".");
|
|
908
880
|
}
|
|
909
|
-
if (
|
|
881
|
+
if (k) break;
|
|
910
882
|
}
|
|
911
|
-
if (!
|
|
912
|
-
const
|
|
913
|
-
let
|
|
914
|
-
typeof
|
|
883
|
+
if (!k && b.includes("deps") && p.depsFunction) {
|
|
884
|
+
const N = p.depsFunction(o);
|
|
885
|
+
let _ = !1;
|
|
886
|
+
typeof N == "boolean" ? N && (_ = !0) : G(p.deps, N) || (p.deps = N, _ = !0), _ && (k = !0);
|
|
915
887
|
}
|
|
916
|
-
|
|
888
|
+
k && p.forceUpdate();
|
|
917
889
|
}
|
|
918
890
|
}
|
|
919
891
|
}
|
|
920
892
|
};
|
|
921
|
-
if (
|
|
893
|
+
if (c === "validateZodSchema")
|
|
922
894
|
return () => {
|
|
923
|
-
const
|
|
924
|
-
if (!
|
|
895
|
+
const d = n.getState().getInitialOptions(e)?.validation, t = n.getState().addValidationError;
|
|
896
|
+
if (!d?.zodSchema)
|
|
925
897
|
throw new Error("Zod schema not found");
|
|
926
|
-
if (!
|
|
898
|
+
if (!d?.key)
|
|
927
899
|
throw new Error("Validation key not found");
|
|
928
|
-
|
|
929
|
-
const
|
|
900
|
+
B(d.key);
|
|
901
|
+
const a = n.getState().cogsStateStore[e];
|
|
930
902
|
try {
|
|
931
|
-
const
|
|
932
|
-
|
|
933
|
-
|
|
903
|
+
const o = n.getState().getValidationErrors(d.key);
|
|
904
|
+
o && o.length > 0 && o.forEach(([I]) => {
|
|
905
|
+
I && I.startsWith(d.key) && B(I);
|
|
934
906
|
});
|
|
935
|
-
const
|
|
936
|
-
return
|
|
937
|
-
const
|
|
938
|
-
t(
|
|
939
|
-
}),
|
|
940
|
-
} catch (
|
|
941
|
-
return console.error("Zod schema validation failed",
|
|
907
|
+
const l = d.zodSchema.safeParse(a);
|
|
908
|
+
return l.success ? !0 : (l.error.errors.forEach((u) => {
|
|
909
|
+
const A = u.path, p = u.message, k = [d.key, ...A].join(".");
|
|
910
|
+
t(k, p);
|
|
911
|
+
}), ie(e), !1);
|
|
912
|
+
} catch (o) {
|
|
913
|
+
return console.error("Zod schema validation failed", o), !1;
|
|
942
914
|
}
|
|
943
915
|
};
|
|
944
|
-
if (
|
|
945
|
-
if (
|
|
916
|
+
if (c === "_componentId") return y;
|
|
917
|
+
if (c === "getComponents")
|
|
946
918
|
return () => n().stateComponents.get(e);
|
|
947
|
-
if (
|
|
948
|
-
return () =>
|
|
949
|
-
if (
|
|
919
|
+
if (c === "getAllFormRefs")
|
|
920
|
+
return () => me.getState().getFormRefsByStateKey(e);
|
|
921
|
+
if (c === "_initialState")
|
|
950
922
|
return n.getState().initialStateGlobal[e];
|
|
951
|
-
if (
|
|
923
|
+
if (c === "_serverState")
|
|
952
924
|
return n.getState().serverState[e];
|
|
953
|
-
if (
|
|
925
|
+
if (c === "_isLoading")
|
|
954
926
|
return n.getState().isLoadingGlobal[e];
|
|
955
|
-
if (
|
|
956
|
-
return
|
|
957
|
-
if (
|
|
958
|
-
if (
|
|
927
|
+
if (c === "revertToInitialState")
|
|
928
|
+
return h.revertToInitialState;
|
|
929
|
+
if (c === "updateInitialState") return h.updateInitialState;
|
|
930
|
+
if (c === "removeValidation") return h.removeValidation;
|
|
959
931
|
}
|
|
960
|
-
if (
|
|
961
|
-
return () =>
|
|
962
|
-
if (
|
|
932
|
+
if (c === "getFormRef")
|
|
933
|
+
return () => me.getState().getFormRef(e + "." + r.join("."));
|
|
934
|
+
if (c === "validationWrapper")
|
|
963
935
|
return ({
|
|
964
|
-
children:
|
|
936
|
+
children: d,
|
|
965
937
|
hideMessage: t
|
|
966
|
-
}) => /* @__PURE__ */
|
|
967
|
-
|
|
938
|
+
}) => /* @__PURE__ */ Se(
|
|
939
|
+
be,
|
|
968
940
|
{
|
|
969
941
|
formOpts: t ? { validation: { message: "" } } : void 0,
|
|
970
942
|
path: r,
|
|
971
943
|
validationKey: n.getState().getInitialOptions(e)?.validation?.key || "",
|
|
972
944
|
stateKey: e,
|
|
973
|
-
validIndices:
|
|
974
|
-
children:
|
|
945
|
+
validIndices: f?.validIndices,
|
|
946
|
+
children: d
|
|
975
947
|
}
|
|
976
948
|
);
|
|
977
|
-
if (
|
|
978
|
-
if (
|
|
979
|
-
if (
|
|
980
|
-
if (
|
|
981
|
-
return (
|
|
949
|
+
if (c === "_stateKey") return e;
|
|
950
|
+
if (c === "_path") return r;
|
|
951
|
+
if (c === "_isServerSynced") return h._isServerSynced;
|
|
952
|
+
if (c === "update")
|
|
953
|
+
return (d, t) => {
|
|
982
954
|
if (t?.debounce)
|
|
983
955
|
Ve(() => {
|
|
984
|
-
X(
|
|
985
|
-
const
|
|
986
|
-
t?.afterUpdate && t.afterUpdate(
|
|
956
|
+
X(s, d, r, "");
|
|
957
|
+
const a = n.getState().getNestedState(e, r);
|
|
958
|
+
t?.afterUpdate && t.afterUpdate(a);
|
|
987
959
|
}, t.debounce);
|
|
988
960
|
else {
|
|
989
|
-
X(
|
|
990
|
-
const
|
|
991
|
-
t?.afterUpdate && t.afterUpdate(
|
|
961
|
+
X(s, d, r, "");
|
|
962
|
+
const a = n.getState().getNestedState(e, r);
|
|
963
|
+
t?.afterUpdate && t.afterUpdate(a);
|
|
992
964
|
}
|
|
993
|
-
|
|
965
|
+
w(r);
|
|
994
966
|
};
|
|
995
|
-
if (
|
|
996
|
-
return (
|
|
997
|
-
|
|
967
|
+
if (c === "formElement")
|
|
968
|
+
return (d, t) => /* @__PURE__ */ Se(
|
|
969
|
+
Ce,
|
|
998
970
|
{
|
|
999
|
-
setState:
|
|
971
|
+
setState: s,
|
|
1000
972
|
stateKey: e,
|
|
1001
973
|
path: r,
|
|
1002
|
-
child:
|
|
974
|
+
child: d,
|
|
1003
975
|
formOpts: t
|
|
1004
976
|
}
|
|
1005
977
|
);
|
|
1006
|
-
const
|
|
1007
|
-
return
|
|
978
|
+
const V = [...r, c], Y = n.getState().getNestedState(e, V);
|
|
979
|
+
return i(Y, V, f);
|
|
1008
980
|
}
|
|
1009
|
-
},
|
|
1010
|
-
return
|
|
1011
|
-
proxy:
|
|
1012
|
-
stateVersion:
|
|
1013
|
-
}),
|
|
981
|
+
}, M = new Proxy(C, P);
|
|
982
|
+
return m.set(U, {
|
|
983
|
+
proxy: M,
|
|
984
|
+
stateVersion: $
|
|
985
|
+
}), M;
|
|
1014
986
|
}
|
|
1015
|
-
return
|
|
987
|
+
return i(
|
|
1016
988
|
n.getState().getNestedState(e, [])
|
|
1017
989
|
);
|
|
1018
990
|
}
|
|
1019
|
-
function
|
|
1020
|
-
return
|
|
991
|
+
function he(e) {
|
|
992
|
+
return ae(We, { proxy: e });
|
|
1021
993
|
}
|
|
1022
|
-
function
|
|
994
|
+
function De({
|
|
1023
995
|
proxy: e,
|
|
1024
|
-
rebuildStateShape:
|
|
996
|
+
rebuildStateShape: s
|
|
1025
997
|
}) {
|
|
1026
|
-
const
|
|
1027
|
-
return Array.isArray(
|
|
1028
|
-
|
|
998
|
+
const y = n().getNestedState(e._stateKey, e._path);
|
|
999
|
+
return Array.isArray(y) ? s(
|
|
1000
|
+
y,
|
|
1029
1001
|
e._path
|
|
1030
1002
|
).stateMapNoRender(
|
|
1031
|
-
(
|
|
1003
|
+
(m, $, w, h, i) => e._mapFn(m, $, w, h, i)
|
|
1032
1004
|
) : null;
|
|
1033
1005
|
}
|
|
1034
1006
|
function We({
|
|
1035
1007
|
proxy: e
|
|
1036
1008
|
}) {
|
|
1037
|
-
const
|
|
1038
|
-
return
|
|
1039
|
-
const
|
|
1040
|
-
if (!
|
|
1041
|
-
const
|
|
1042
|
-
let
|
|
1043
|
-
|
|
1044
|
-
const
|
|
1009
|
+
const s = ee(null), y = `${e._stateKey}-${e._path.join(".")}`;
|
|
1010
|
+
return le(() => {
|
|
1011
|
+
const g = s.current;
|
|
1012
|
+
if (!g || !g.parentElement) return;
|
|
1013
|
+
const m = g.parentElement, w = Array.from(m.childNodes).indexOf(g);
|
|
1014
|
+
let h = m.getAttribute("data-parent-id");
|
|
1015
|
+
h || (h = `parent-${crypto.randomUUID()}`, m.setAttribute("data-parent-id", h));
|
|
1016
|
+
const v = {
|
|
1045
1017
|
instanceId: `instance-${crypto.randomUUID()}`,
|
|
1046
|
-
parentId:
|
|
1047
|
-
position:
|
|
1018
|
+
parentId: h,
|
|
1019
|
+
position: w,
|
|
1048
1020
|
effect: e._effect
|
|
1049
1021
|
};
|
|
1050
|
-
n.getState().addSignalElement(
|
|
1022
|
+
n.getState().addSignalElement(y, v);
|
|
1051
1023
|
const r = n.getState().getNestedState(e._stateKey, e._path);
|
|
1052
|
-
let
|
|
1024
|
+
let f;
|
|
1053
1025
|
if (e._effect)
|
|
1054
1026
|
try {
|
|
1055
|
-
|
|
1027
|
+
f = new Function(
|
|
1056
1028
|
"state",
|
|
1057
1029
|
`return (${e._effect})(state)`
|
|
1058
1030
|
)(r);
|
|
1059
|
-
} catch (
|
|
1060
|
-
console.error("Error evaluating effect function during mount:",
|
|
1031
|
+
} catch (C) {
|
|
1032
|
+
console.error("Error evaluating effect function during mount:", C), f = r;
|
|
1061
1033
|
}
|
|
1062
1034
|
else
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
const
|
|
1066
|
-
|
|
1067
|
-
}, [e._stateKey, e._path.join("."), e._effect]),
|
|
1068
|
-
ref:
|
|
1035
|
+
f = r;
|
|
1036
|
+
f !== null && typeof f == "object" && (f = JSON.stringify(f));
|
|
1037
|
+
const U = document.createTextNode(String(f));
|
|
1038
|
+
g.replaceWith(U);
|
|
1039
|
+
}, [e._stateKey, e._path.join("."), e._effect]), ae("span", {
|
|
1040
|
+
ref: s,
|
|
1069
1041
|
style: { display: "none" },
|
|
1070
|
-
"data-signal-id":
|
|
1042
|
+
"data-signal-id": y
|
|
1071
1043
|
});
|
|
1072
1044
|
}
|
|
1073
|
-
function
|
|
1074
|
-
const
|
|
1075
|
-
(
|
|
1076
|
-
const
|
|
1077
|
-
components: /* @__PURE__ */ new Map()
|
|
1078
|
-
pathTrie: {
|
|
1079
|
-
subscribers: /* @__PURE__ */ new Set(),
|
|
1080
|
-
children: /* @__PURE__ */ new Map()
|
|
1081
|
-
}
|
|
1082
|
-
}, c = `signal-${e._stateKey}-${Date.now()}`;
|
|
1083
|
-
return l.components.set(c, {
|
|
1084
|
-
forceUpdate: S,
|
|
1085
|
-
paths: /* @__PURE__ */ new Set([e._path.join(".")]),
|
|
1086
|
-
deps: [],
|
|
1087
|
-
depsFunction: void 0,
|
|
1088
|
-
reactiveType: ["component"]
|
|
1089
|
-
}), l.pathTrie && ue(l.pathTrie, e._path.join("."), c), n.getState().stateComponents.set(e._stateKey, l), () => {
|
|
1090
|
-
l.components.delete(c), l.pathTrie && Ue(
|
|
1091
|
-
l.pathTrie,
|
|
1092
|
-
e._path.join("."),
|
|
1093
|
-
c
|
|
1094
|
-
);
|
|
1045
|
+
function tt(e) {
|
|
1046
|
+
const s = Te(
|
|
1047
|
+
(y) => {
|
|
1048
|
+
const g = n.getState().stateComponents.get(e._stateKey) || {
|
|
1049
|
+
components: /* @__PURE__ */ new Map()
|
|
1095
1050
|
};
|
|
1051
|
+
return g.components.set(e._stateKey, {
|
|
1052
|
+
forceUpdate: y,
|
|
1053
|
+
paths: /* @__PURE__ */ new Set([e._path.join(".")])
|
|
1054
|
+
}), () => g.components.delete(e._stateKey);
|
|
1096
1055
|
},
|
|
1097
1056
|
() => n.getState().getNestedState(e._stateKey, e._path)
|
|
1098
1057
|
);
|
|
1099
|
-
return
|
|
1058
|
+
return ae("text", {}, String(s));
|
|
1100
1059
|
}
|
|
1101
1060
|
export {
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1061
|
+
he as $cogsSignal,
|
|
1062
|
+
tt as $cogsSignalStore,
|
|
1063
|
+
Qe as addStateOptions,
|
|
1064
|
+
Ke as createCogsState,
|
|
1065
|
+
et as notifyComponent,
|
|
1107
1066
|
Me as useCogsStateFn
|
|
1108
1067
|
};
|
|
1109
1068
|
//# sourceMappingURL=CogsState.jsx.map
|