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