cogsbox-state 0.5.180 → 0.5.183
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 +333 -334
- package/dist/CogsState.jsx.map +1 -1
- package/dist/TRPCValidationLink.js +1 -1
- package/dist/store.js +1 -1
- package/dist/useValidateZodPath.js +9 -8
- package/dist/useValidateZodPath.js.map +1 -1
- package/package.json +4 -3
- package/src/CogsState.tsx +2444 -0
- package/src/CogsStateClient.tsx +25 -0
- package/src/Functions.tsx +409 -0
- package/src/TRPCValidationLink.ts +70 -0
- package/src/index.ts +4 -0
- package/src/store.ts +616 -0
- package/src/useValidateZodPath.ts +231 -0
- package/src/utility.ts +423 -0
- package/dist/node_modules/@trpc/server/dist/observable/observable.js +0 -38
- package/dist/node_modules/@trpc/server/dist/observable/observable.js.map +0 -1
- package/dist/node_modules/copy-anything/dist/index.js +0 -27
- package/dist/node_modules/copy-anything/dist/index.js.map +0 -1
- package/dist/node_modules/is-what/dist/index.js +0 -18
- package/dist/node_modules/is-what/dist/index.js.map +0 -1
- package/dist/node_modules/superjson/dist/accessDeep.js +0 -92
- package/dist/node_modules/superjson/dist/accessDeep.js.map +0 -1
- package/dist/node_modules/superjson/dist/class-registry.js +0 -16
- package/dist/node_modules/superjson/dist/class-registry.js.map +0 -1
- package/dist/node_modules/superjson/dist/custom-transformer-registry.js +0 -19
- package/dist/node_modules/superjson/dist/custom-transformer-registry.js.map +0 -1
- package/dist/node_modules/superjson/dist/double-indexed-kv.js +0 -21
- package/dist/node_modules/superjson/dist/double-indexed-kv.js.map +0 -1
- package/dist/node_modules/superjson/dist/index.js +0 -75
- package/dist/node_modules/superjson/dist/index.js.map +0 -1
- package/dist/node_modules/superjson/dist/is.js +0 -24
- package/dist/node_modules/superjson/dist/is.js.map +0 -1
- package/dist/node_modules/superjson/dist/pathstringifier.js +0 -24
- package/dist/node_modules/superjson/dist/pathstringifier.js.map +0 -1
- package/dist/node_modules/superjson/dist/plainer.js +0 -102
- package/dist/node_modules/superjson/dist/plainer.js.map +0 -1
- package/dist/node_modules/superjson/dist/registry.js +0 -22
- package/dist/node_modules/superjson/dist/registry.js.map +0 -1
- package/dist/node_modules/superjson/dist/transformer.js +0 -140
- package/dist/node_modules/superjson/dist/transformer.js.map +0 -1
- package/dist/node_modules/superjson/dist/util.js +0 -39
- package/dist/node_modules/superjson/dist/util.js.map +0 -1
- package/dist/node_modules/uuid/dist/esm-browser/native.js +0 -7
- package/dist/node_modules/uuid/dist/esm-browser/native.js.map +0 -1
- package/dist/node_modules/uuid/dist/esm-browser/rng.js +0 -11
- package/dist/node_modules/uuid/dist/esm-browser/rng.js.map +0 -1
- package/dist/node_modules/uuid/dist/esm-browser/stringify.js +0 -10
- package/dist/node_modules/uuid/dist/esm-browser/stringify.js.map +0 -1
- package/dist/node_modules/uuid/dist/esm-browser/v4.js +0 -14
- package/dist/node_modules/uuid/dist/esm-browser/v4.js.map +0 -1
- package/dist/node_modules/zustand/esm/react.js +0 -20
- package/dist/node_modules/zustand/esm/react.js.map +0 -1
- package/dist/node_modules/zustand/esm/vanilla.js +0 -15
- package/dist/node_modules/zustand/esm/vanilla.js.map +0 -1
package/dist/CogsState.jsx
CHANGED
|
@@ -1,61 +1,61 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsx as me } from "react/jsx-runtime";
|
|
3
|
-
import { useState as de, useRef as Q, useEffect as ue, useLayoutEffect as
|
|
4
|
-
import { transformStateFunc as
|
|
5
|
-
import { pushFunc as ce, updateFn as Z, cutFunc as X, ValidationWrapper as
|
|
6
|
-
import be from "
|
|
3
|
+
import { useState as de, useRef as Q, useEffect as ue, useLayoutEffect as Ne, useMemo as he, createElement as te, useSyncExternalStore as ke, startTransition as Ve } from "react";
|
|
4
|
+
import { transformStateFunc as Ae, isDeepEqual as G, isFunction as L, getNestedValue as D, getDifferences as _e, debounce as xe } from "./utility.js";
|
|
5
|
+
import { pushFunc as ce, updateFn as Z, cutFunc as X, ValidationWrapper as Te, FormControlComponent as Ce } from "./Functions.jsx";
|
|
6
|
+
import be from "superjson";
|
|
7
|
+
import { v4 as ge } from "uuid";
|
|
7
8
|
import "zod";
|
|
8
9
|
import { getGlobalStore as a, formRefStore as ye } from "./store.js";
|
|
9
10
|
import { useCogsConfig as $e } from "./CogsStateClient.jsx";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const m = a.getState().getInitialOptions, d = a.getState().setInitialStateOptions, u = m(e) || {};
|
|
11
|
+
function ve(e, c) {
|
|
12
|
+
const S = a.getState().getInitialOptions, d = a.getState().setInitialStateOptions, u = S(e) || {};
|
|
13
13
|
d(e, {
|
|
14
14
|
...u,
|
|
15
|
-
...
|
|
15
|
+
...c
|
|
16
16
|
});
|
|
17
17
|
}
|
|
18
18
|
function Ie({
|
|
19
19
|
stateKey: e,
|
|
20
|
-
options:
|
|
21
|
-
initialOptionsPart:
|
|
20
|
+
options: c,
|
|
21
|
+
initialOptionsPart: S
|
|
22
22
|
}) {
|
|
23
|
-
const d = z(e) || {}, u =
|
|
24
|
-
let
|
|
25
|
-
if (
|
|
26
|
-
for (const l in
|
|
27
|
-
E.hasOwnProperty(l) ? (l == "localStorage" &&
|
|
28
|
-
!
|
|
29
|
-
|
|
23
|
+
const d = z(e) || {}, u = S[e] || {}, I = a.getState().setInitialStateOptions, E = { ...u, ...d };
|
|
24
|
+
let f = !1;
|
|
25
|
+
if (c)
|
|
26
|
+
for (const l in c)
|
|
27
|
+
E.hasOwnProperty(l) ? (l == "localStorage" && c[l] && E[l].key !== c[l]?.key && (f = !0, E[l] = c[l]), l == "initialState" && c[l] && E[l] !== c[l] && // Different references
|
|
28
|
+
!G(E[l], c[l]) && (f = !0, E[l] = c[l])) : (f = !0, E[l] = c[l]);
|
|
29
|
+
f && I(e, E);
|
|
30
30
|
}
|
|
31
|
-
function Xe(e, { formElements:
|
|
32
|
-
return { initialState: e, formElements:
|
|
31
|
+
function Xe(e, { formElements: c, validation: S }) {
|
|
32
|
+
return { initialState: e, formElements: c, validation: S };
|
|
33
33
|
}
|
|
34
|
-
const Qe = (e,
|
|
35
|
-
let
|
|
36
|
-
const [d, u] =
|
|
37
|
-
(Object.keys(u).length > 0 ||
|
|
38
|
-
u[
|
|
39
|
-
...
|
|
34
|
+
const Qe = (e, c) => {
|
|
35
|
+
let S = e;
|
|
36
|
+
const [d, u] = Ae(S);
|
|
37
|
+
(Object.keys(u).length > 0 || c && Object.keys(c).length > 0) && Object.keys(u).forEach((f) => {
|
|
38
|
+
u[f] = u[f] || {}, u[f].formElements = {
|
|
39
|
+
...c?.formElements,
|
|
40
40
|
// Global defaults first
|
|
41
|
-
...
|
|
42
|
-
...u[
|
|
41
|
+
...c?.validation,
|
|
42
|
+
...u[f].formElements || {}
|
|
43
43
|
// State-specific overrides
|
|
44
|
-
}, z(
|
|
44
|
+
}, z(f) || a.getState().setInitialStateOptions(f, u[f]);
|
|
45
45
|
}), a.getState().setInitialStates(d), a.getState().setCreatedState(d);
|
|
46
|
-
const I = (
|
|
47
|
-
const [
|
|
46
|
+
const I = (f, l) => {
|
|
47
|
+
const [m] = de(l?.componentId ?? ge());
|
|
48
48
|
Ie({
|
|
49
|
-
stateKey:
|
|
49
|
+
stateKey: f,
|
|
50
50
|
options: l,
|
|
51
51
|
initialOptionsPart: u
|
|
52
52
|
});
|
|
53
|
-
const t = a.getState().cogsStateStore[
|
|
53
|
+
const t = a.getState().cogsStateStore[f] || d[f], v = l?.modifyState ? l.modifyState(t) : t, [A, b] = Me(
|
|
54
54
|
v,
|
|
55
55
|
{
|
|
56
|
-
stateKey:
|
|
56
|
+
stateKey: f,
|
|
57
57
|
syncUpdate: l?.syncUpdate,
|
|
58
|
-
componentId:
|
|
58
|
+
componentId: m,
|
|
59
59
|
localStorage: l?.localStorage,
|
|
60
60
|
middleware: l?.middleware,
|
|
61
61
|
enabledSync: l?.enabledSync,
|
|
@@ -68,56 +68,56 @@ const Qe = (e, s) => {
|
|
|
68
68
|
);
|
|
69
69
|
return b;
|
|
70
70
|
};
|
|
71
|
-
function E(
|
|
72
|
-
Ie({ stateKey:
|
|
71
|
+
function E(f, l) {
|
|
72
|
+
Ie({ stateKey: f, options: l, initialOptionsPart: u }), l.localStorage && Re(f, l), re(f);
|
|
73
73
|
}
|
|
74
74
|
return { useCogsState: I, setCogsOptions: E };
|
|
75
75
|
}, {
|
|
76
76
|
setUpdaterState: K,
|
|
77
77
|
setState: q,
|
|
78
78
|
getInitialOptions: z,
|
|
79
|
-
getKeyState:
|
|
79
|
+
getKeyState: we,
|
|
80
80
|
getValidationErrors: Pe,
|
|
81
|
-
setStateLog:
|
|
81
|
+
setStateLog: je,
|
|
82
82
|
updateInitialStateGlobal: fe,
|
|
83
83
|
addValidationError: Fe,
|
|
84
|
-
removeValidationError:
|
|
85
|
-
setServerSyncActions:
|
|
86
|
-
} = a.getState(), Ee = (e,
|
|
87
|
-
|
|
84
|
+
removeValidationError: p,
|
|
85
|
+
setServerSyncActions: Oe
|
|
86
|
+
} = a.getState(), Ee = (e, c, S, d, u) => {
|
|
87
|
+
S?.log && console.log(
|
|
88
88
|
"saving to localstorage",
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
c,
|
|
90
|
+
S.localStorage?.key,
|
|
91
91
|
d
|
|
92
92
|
);
|
|
93
|
-
const I = L(
|
|
93
|
+
const I = L(S?.localStorage?.key) ? S.localStorage?.key(e) : S?.localStorage?.key;
|
|
94
94
|
if (I && d) {
|
|
95
|
-
const E = `${d}-${
|
|
96
|
-
let
|
|
95
|
+
const E = `${d}-${c}-${I}`;
|
|
96
|
+
let f;
|
|
97
97
|
try {
|
|
98
|
-
|
|
98
|
+
f = ne(E)?.lastSyncedWithServer;
|
|
99
99
|
} catch {
|
|
100
100
|
}
|
|
101
101
|
const l = {
|
|
102
102
|
state: e,
|
|
103
103
|
lastUpdated: Date.now(),
|
|
104
|
-
lastSyncedWithServer: u ??
|
|
105
|
-
},
|
|
104
|
+
lastSyncedWithServer: u ?? f
|
|
105
|
+
}, m = be.serialize(l);
|
|
106
106
|
window.localStorage.setItem(
|
|
107
107
|
E,
|
|
108
|
-
JSON.stringify(
|
|
108
|
+
JSON.stringify(m.json)
|
|
109
109
|
);
|
|
110
110
|
}
|
|
111
111
|
}, ne = (e) => {
|
|
112
112
|
if (!e) return null;
|
|
113
113
|
try {
|
|
114
|
-
const
|
|
115
|
-
return
|
|
116
|
-
} catch (
|
|
117
|
-
return console.error("Error loading from localStorage:",
|
|
114
|
+
const c = window.localStorage.getItem(e);
|
|
115
|
+
return c ? JSON.parse(c) : null;
|
|
116
|
+
} catch (c) {
|
|
117
|
+
return console.error("Error loading from localStorage:", c), null;
|
|
118
118
|
}
|
|
119
|
-
}, Re = (e,
|
|
120
|
-
const
|
|
119
|
+
}, Re = (e, c) => {
|
|
120
|
+
const S = a.getState().cogsStateStore[e], { sessionId: d } = $e(), u = L(c?.localStorage?.key) ? c.localStorage.key(S) : c?.localStorage?.key;
|
|
121
121
|
if (u && d) {
|
|
122
122
|
const I = ne(
|
|
123
123
|
`${d}-${e}-${u}`
|
|
@@ -126,51 +126,51 @@ const Qe = (e, s) => {
|
|
|
126
126
|
return q(e, I.state), re(e), !0;
|
|
127
127
|
}
|
|
128
128
|
return !1;
|
|
129
|
-
}, Ue = (e,
|
|
129
|
+
}, Ue = (e, c, S, d, u, I) => {
|
|
130
130
|
const E = {
|
|
131
|
-
initialState:
|
|
131
|
+
initialState: c,
|
|
132
132
|
updaterState: ee(
|
|
133
133
|
e,
|
|
134
134
|
d,
|
|
135
135
|
u,
|
|
136
136
|
I
|
|
137
137
|
),
|
|
138
|
-
state:
|
|
138
|
+
state: S
|
|
139
139
|
};
|
|
140
140
|
fe(e, E.initialState), K(e, E.updaterState), q(e, E.state);
|
|
141
141
|
}, re = (e) => {
|
|
142
|
-
const
|
|
143
|
-
if (!
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
(d ? Array.isArray(d.reactiveType) ? d.reactiveType : [d.reactiveType || "component"] : null)?.includes("none") ||
|
|
142
|
+
const c = a.getState().stateComponents.get(e);
|
|
143
|
+
if (!c) return;
|
|
144
|
+
const S = /* @__PURE__ */ new Set();
|
|
145
|
+
c.components.forEach((d) => {
|
|
146
|
+
(d ? Array.isArray(d.reactiveType) ? d.reactiveType : [d.reactiveType || "component"] : null)?.includes("none") || S.add(() => d.forceUpdate());
|
|
147
147
|
}), queueMicrotask(() => {
|
|
148
|
-
|
|
148
|
+
S.forEach((d) => d());
|
|
149
149
|
});
|
|
150
|
-
}, Ke = (e,
|
|
151
|
-
const
|
|
152
|
-
if (
|
|
153
|
-
const d = `${e}////${
|
|
150
|
+
}, Ke = (e, c) => {
|
|
151
|
+
const S = a.getState().stateComponents.get(e);
|
|
152
|
+
if (S) {
|
|
153
|
+
const d = `${e}////${c}`, u = S.components.get(d);
|
|
154
154
|
if ((u ? Array.isArray(u.reactiveType) ? u.reactiveType : [u.reactiveType || "component"] : null)?.includes("none"))
|
|
155
155
|
return;
|
|
156
156
|
u && u.forceUpdate();
|
|
157
157
|
}
|
|
158
|
-
},
|
|
158
|
+
}, De = (e, c, S, d) => {
|
|
159
159
|
switch (e) {
|
|
160
160
|
case "update":
|
|
161
161
|
return {
|
|
162
|
-
oldValue:
|
|
163
|
-
newValue:
|
|
162
|
+
oldValue: D(c, d),
|
|
163
|
+
newValue: D(S, d)
|
|
164
164
|
};
|
|
165
165
|
case "insert":
|
|
166
166
|
return {
|
|
167
167
|
oldValue: null,
|
|
168
168
|
// or undefined
|
|
169
|
-
newValue:
|
|
169
|
+
newValue: D(S, d)
|
|
170
170
|
};
|
|
171
171
|
case "cut":
|
|
172
172
|
return {
|
|
173
|
-
oldValue:
|
|
173
|
+
oldValue: D(c, d),
|
|
174
174
|
newValue: null
|
|
175
175
|
// or undefined
|
|
176
176
|
};
|
|
@@ -178,23 +178,23 @@ const Qe = (e, s) => {
|
|
|
178
178
|
return { oldValue: null, newValue: null };
|
|
179
179
|
}
|
|
180
180
|
};
|
|
181
|
-
function
|
|
182
|
-
stateKey:
|
|
183
|
-
serverSync:
|
|
181
|
+
function Me(e, {
|
|
182
|
+
stateKey: c,
|
|
183
|
+
serverSync: S,
|
|
184
184
|
localStorage: d,
|
|
185
185
|
formElements: u,
|
|
186
186
|
middleware: I,
|
|
187
187
|
reactiveDeps: E,
|
|
188
|
-
reactiveType:
|
|
188
|
+
reactiveType: f,
|
|
189
189
|
componentId: l,
|
|
190
|
-
initialState:
|
|
190
|
+
initialState: m,
|
|
191
191
|
syncUpdate: t,
|
|
192
192
|
dependencies: v,
|
|
193
|
-
serverState:
|
|
193
|
+
serverState: A
|
|
194
194
|
} = {}) {
|
|
195
|
-
const [b,
|
|
196
|
-
let R = !
|
|
197
|
-
const [r] = de(
|
|
195
|
+
const [b, O] = de({}), { sessionId: N } = $e();
|
|
196
|
+
let R = !c;
|
|
197
|
+
const [r] = de(c ?? ge()), B = a.getState().stateLog[r], H = Q(/* @__PURE__ */ new Set()), W = Q(l ?? ge()), n = Q(
|
|
198
198
|
null
|
|
199
199
|
);
|
|
200
200
|
n.current = z(r) ?? null, ue(() => {
|
|
@@ -203,174 +203,174 @@ function De(e, {
|
|
|
203
203
|
...i,
|
|
204
204
|
[t.path[0]]: t.newValue
|
|
205
205
|
}));
|
|
206
|
-
const
|
|
207
|
-
a.getState().setSyncInfo(
|
|
206
|
+
const s = `${t.stateKey}:${t.path.join(".")}`;
|
|
207
|
+
a.getState().setSyncInfo(s, {
|
|
208
208
|
timeStamp: t.timeStamp,
|
|
209
209
|
userId: t.userId
|
|
210
210
|
});
|
|
211
211
|
}
|
|
212
212
|
}, [t]), ue(() => {
|
|
213
|
-
if (
|
|
213
|
+
if (m) {
|
|
214
214
|
ve(r, {
|
|
215
|
-
initialState:
|
|
215
|
+
initialState: m
|
|
216
216
|
});
|
|
217
|
-
const
|
|
218
|
-
if (!(
|
|
217
|
+
const s = n.current, y = s?.serverState?.id !== void 0 && s?.serverState?.status === "success" && s?.serverState?.data, k = a.getState().initialStateGlobal[r];
|
|
218
|
+
if (!(k && !G(k, m) || !k) && !y)
|
|
219
219
|
return;
|
|
220
220
|
let $ = null;
|
|
221
|
-
const
|
|
222
|
-
|
|
223
|
-
let
|
|
221
|
+
const x = L(s?.localStorage?.key) ? s?.localStorage?.key(m) : s?.localStorage?.key;
|
|
222
|
+
x && N && ($ = ne(`${N}-${r}-${x}`));
|
|
223
|
+
let T = m, J = !1;
|
|
224
224
|
const ae = y ? Date.now() : 0, Y = $?.lastUpdated || 0, oe = $?.lastSyncedWithServer || 0;
|
|
225
|
-
y && ae > Y ? (
|
|
225
|
+
y && ae > Y ? (T = s.serverState.data, J = !0) : $ && Y > oe && (T = $.state, s?.localStorage?.onChange && s?.localStorage?.onChange(T)), Ue(
|
|
226
226
|
r,
|
|
227
|
-
|
|
228
|
-
|
|
227
|
+
m,
|
|
228
|
+
T,
|
|
229
229
|
o,
|
|
230
230
|
W.current,
|
|
231
|
-
|
|
232
|
-
),
|
|
231
|
+
N
|
|
232
|
+
), J && x && N && Ee(T, r, s, N, Date.now()), re(r), (Array.isArray(f) ? f : [f || "component"]).includes("none") || O({});
|
|
233
233
|
}
|
|
234
234
|
}, [
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
235
|
+
m,
|
|
236
|
+
A?.status,
|
|
237
|
+
A?.data,
|
|
238
238
|
...v || []
|
|
239
|
-
]),
|
|
239
|
+
]), Ne(() => {
|
|
240
240
|
R && ve(r, {
|
|
241
|
-
serverSync:
|
|
241
|
+
serverSync: S,
|
|
242
242
|
formElements: u,
|
|
243
|
-
initialState:
|
|
243
|
+
initialState: m,
|
|
244
244
|
localStorage: d,
|
|
245
245
|
middleware: I
|
|
246
246
|
});
|
|
247
|
-
const
|
|
247
|
+
const s = `${r}////${W.current}`, i = a.getState().stateComponents.get(r) || {
|
|
248
248
|
components: /* @__PURE__ */ new Map()
|
|
249
249
|
};
|
|
250
|
-
return i.components.set(
|
|
251
|
-
forceUpdate: () =>
|
|
250
|
+
return i.components.set(s, {
|
|
251
|
+
forceUpdate: () => O({}),
|
|
252
252
|
paths: /* @__PURE__ */ new Set(),
|
|
253
253
|
deps: [],
|
|
254
254
|
depsFunction: E || void 0,
|
|
255
|
-
reactiveType:
|
|
256
|
-
}), a.getState().stateComponents.set(r, i),
|
|
255
|
+
reactiveType: f ?? ["component", "deps"]
|
|
256
|
+
}), a.getState().stateComponents.set(r, i), O({}), () => {
|
|
257
257
|
const y = `${r}////${W.current}`;
|
|
258
258
|
i && (i.components.delete(y), i.components.size === 0 && a.getState().stateComponents.delete(r));
|
|
259
259
|
};
|
|
260
260
|
}, []);
|
|
261
|
-
const o = (
|
|
261
|
+
const o = (s, i, y, k) => {
|
|
262
262
|
if (Array.isArray(i)) {
|
|
263
|
-
const
|
|
264
|
-
H.current.add(
|
|
263
|
+
const h = `${r}-${i.join(".")}`;
|
|
264
|
+
H.current.add(h);
|
|
265
265
|
}
|
|
266
|
-
q(r, (
|
|
267
|
-
const $ = L(
|
|
268
|
-
if (
|
|
269
|
-
let U = !1,
|
|
270
|
-
if ((!
|
|
271
|
-
const P = i.slice(0, -1), F =
|
|
266
|
+
q(r, (h) => {
|
|
267
|
+
const $ = L(s) ? s(h) : s, x = `${r}-${i.join(".")}`;
|
|
268
|
+
if (x) {
|
|
269
|
+
let U = !1, w = a.getState().signalDomElements.get(x);
|
|
270
|
+
if ((!w || w.size === 0) && (y.updateType === "insert" || y.updateType === "cut")) {
|
|
271
|
+
const P = i.slice(0, -1), F = D($, P);
|
|
272
272
|
if (Array.isArray(F)) {
|
|
273
273
|
U = !0;
|
|
274
274
|
const _ = `${r}-${P.join(".")}`;
|
|
275
|
-
|
|
275
|
+
w = a.getState().signalDomElements.get(_);
|
|
276
276
|
}
|
|
277
277
|
}
|
|
278
|
-
if (
|
|
279
|
-
const P = U ?
|
|
280
|
-
|
|
281
|
-
const
|
|
278
|
+
if (w) {
|
|
279
|
+
const P = U ? D($, i.slice(0, -1)) : D($, i);
|
|
280
|
+
w.forEach(({ parentId: F, position: _, effect: C }) => {
|
|
281
|
+
const V = document.querySelector(
|
|
282
282
|
`[data-parent-id="${F}"]`
|
|
283
283
|
);
|
|
284
|
-
if (
|
|
285
|
-
const
|
|
286
|
-
if (
|
|
287
|
-
const
|
|
288
|
-
|
|
284
|
+
if (V) {
|
|
285
|
+
const M = Array.from(V.childNodes);
|
|
286
|
+
if (M[_]) {
|
|
287
|
+
const j = C ? new Function("state", `return (${C})(state)`)(P) : P;
|
|
288
|
+
M[_].textContent = String(j);
|
|
289
289
|
}
|
|
290
290
|
}
|
|
291
291
|
});
|
|
292
292
|
}
|
|
293
293
|
}
|
|
294
|
-
y.updateType === "update" && (
|
|
295
|
-
(
|
|
294
|
+
y.updateType === "update" && (k || n.current?.validation?.key) && i && p(
|
|
295
|
+
(k || n.current?.validation?.key) + "." + i.join(".")
|
|
296
296
|
);
|
|
297
|
-
const
|
|
298
|
-
y.updateType === "cut" && n.current?.validation?.key &&
|
|
299
|
-
n.current?.validation?.key + "." +
|
|
297
|
+
const T = i.slice(0, i.length - 1);
|
|
298
|
+
y.updateType === "cut" && n.current?.validation?.key && p(
|
|
299
|
+
n.current?.validation?.key + "." + T.join(".")
|
|
300
300
|
), y.updateType === "insert" && n.current?.validation?.key && Pe(
|
|
301
|
-
n.current?.validation?.key + "." +
|
|
302
|
-
).filter(([
|
|
303
|
-
let F =
|
|
304
|
-
if (
|
|
305
|
-
let _ =
|
|
306
|
-
|
|
301
|
+
n.current?.validation?.key + "." + T.join(".")
|
|
302
|
+
).filter(([w, P]) => {
|
|
303
|
+
let F = w?.split(".").length;
|
|
304
|
+
if (w == T.join(".") && F == T.length - 1) {
|
|
305
|
+
let _ = w + "." + T;
|
|
306
|
+
p(w), Fe(_, P);
|
|
307
307
|
}
|
|
308
308
|
});
|
|
309
|
-
const
|
|
310
|
-
if (
|
|
311
|
-
const U = _e(
|
|
309
|
+
const J = a.getState().stateComponents.get(r);
|
|
310
|
+
if (J) {
|
|
311
|
+
const U = _e(h, $), w = new Set(U), P = y.updateType === "update" ? i.join(".") : i.slice(0, -1).join(".") || "";
|
|
312
312
|
for (const [
|
|
313
313
|
F,
|
|
314
314
|
_
|
|
315
|
-
] of
|
|
315
|
+
] of J.components.entries()) {
|
|
316
316
|
let C = !1;
|
|
317
|
-
const
|
|
318
|
-
if (!
|
|
319
|
-
if (
|
|
317
|
+
const V = Array.isArray(_.reactiveType) ? _.reactiveType : [_.reactiveType || "component"];
|
|
318
|
+
if (!V.includes("none")) {
|
|
319
|
+
if (V.includes("all")) {
|
|
320
320
|
_.forceUpdate();
|
|
321
321
|
continue;
|
|
322
322
|
}
|
|
323
|
-
if (
|
|
324
|
-
for (const
|
|
325
|
-
let
|
|
323
|
+
if (V.includes("component") && ((_.paths.has(P) || _.paths.has("")) && (C = !0), !C))
|
|
324
|
+
for (const M of w) {
|
|
325
|
+
let j = M;
|
|
326
326
|
for (; ; ) {
|
|
327
|
-
if (_.paths.has(
|
|
327
|
+
if (_.paths.has(j)) {
|
|
328
328
|
C = !0;
|
|
329
329
|
break;
|
|
330
330
|
}
|
|
331
|
-
const se =
|
|
331
|
+
const se = j.lastIndexOf(".");
|
|
332
332
|
if (se !== -1) {
|
|
333
|
-
const Se =
|
|
333
|
+
const Se = j.substring(
|
|
334
334
|
0,
|
|
335
335
|
se
|
|
336
336
|
);
|
|
337
337
|
if (!isNaN(
|
|
338
|
-
Number(
|
|
338
|
+
Number(j.substring(se + 1))
|
|
339
339
|
) && _.paths.has(Se)) {
|
|
340
340
|
C = !0;
|
|
341
341
|
break;
|
|
342
342
|
}
|
|
343
|
-
|
|
343
|
+
j = Se;
|
|
344
344
|
} else
|
|
345
|
-
|
|
346
|
-
if (
|
|
345
|
+
j = "";
|
|
346
|
+
if (j === "")
|
|
347
347
|
break;
|
|
348
348
|
}
|
|
349
349
|
if (C) break;
|
|
350
350
|
}
|
|
351
|
-
if (!C &&
|
|
352
|
-
const
|
|
353
|
-
let
|
|
354
|
-
typeof
|
|
351
|
+
if (!C && V.includes("deps") && _.depsFunction) {
|
|
352
|
+
const M = _.depsFunction($);
|
|
353
|
+
let j = !1;
|
|
354
|
+
typeof M == "boolean" ? M && (j = !0) : G(_.deps, M) || (_.deps = M, j = !0), j && (C = !0);
|
|
355
355
|
}
|
|
356
356
|
C && _.forceUpdate();
|
|
357
357
|
}
|
|
358
358
|
}
|
|
359
359
|
}
|
|
360
360
|
const ae = Date.now();
|
|
361
|
-
i = i.map((U,
|
|
362
|
-
const P = i.slice(0, -1), F =
|
|
363
|
-
return
|
|
361
|
+
i = i.map((U, w) => {
|
|
362
|
+
const P = i.slice(0, -1), F = D($, P);
|
|
363
|
+
return w === i.length - 1 && ["insert", "cut"].includes(y.updateType) ? (F.length - 1).toString() : U;
|
|
364
364
|
}), console.log(
|
|
365
365
|
"mmmmmmmmmmmmmmmmm22222222222222",
|
|
366
366
|
y.updateType,
|
|
367
|
-
|
|
367
|
+
h,
|
|
368
368
|
$,
|
|
369
369
|
i
|
|
370
370
|
);
|
|
371
|
-
const { oldValue: Y, newValue: oe } =
|
|
371
|
+
const { oldValue: Y, newValue: oe } = De(
|
|
372
372
|
y.updateType,
|
|
373
|
-
|
|
373
|
+
h,
|
|
374
374
|
$,
|
|
375
375
|
i
|
|
376
376
|
), ie = {
|
|
@@ -382,26 +382,26 @@ function De(e, {
|
|
|
382
382
|
oldValue: Y,
|
|
383
383
|
newValue: oe
|
|
384
384
|
};
|
|
385
|
-
if (
|
|
385
|
+
if (je(r, (U) => {
|
|
386
386
|
const P = [...U ?? [], ie].reduce((F, _) => {
|
|
387
|
-
const C = `${_.stateKey}:${JSON.stringify(_.path)}`,
|
|
388
|
-
return
|
|
387
|
+
const C = `${_.stateKey}:${JSON.stringify(_.path)}`, V = F.get(C);
|
|
388
|
+
return V ? (V.timeStamp = Math.max(V.timeStamp, _.timeStamp), V.newValue = _.newValue, V.oldValue = V.oldValue ?? _.oldValue, V.updateType = _.updateType) : F.set(C, { ..._ }), F;
|
|
389
389
|
}, /* @__PURE__ */ new Map());
|
|
390
390
|
return Array.from(P.values());
|
|
391
391
|
}), Ee(
|
|
392
392
|
$,
|
|
393
393
|
r,
|
|
394
394
|
n.current,
|
|
395
|
-
|
|
395
|
+
N
|
|
396
396
|
), I && I({
|
|
397
|
-
updateLog:
|
|
397
|
+
updateLog: B,
|
|
398
398
|
update: ie
|
|
399
399
|
}), n.current?.serverSync) {
|
|
400
|
-
const U = a.getState().serverState[r],
|
|
401
|
-
|
|
402
|
-
syncKey: typeof
|
|
400
|
+
const U = a.getState().serverState[r], w = n.current?.serverSync;
|
|
401
|
+
Oe(r, {
|
|
402
|
+
syncKey: typeof w.syncKey == "string" ? w.syncKey : w.syncKey({ state: $ }),
|
|
403
403
|
rollBackState: U,
|
|
404
|
-
actionTimeStamp: Date.now() + (
|
|
404
|
+
actionTimeStamp: Date.now() + (w.debounce ?? 3e3),
|
|
405
405
|
status: "waiting"
|
|
406
406
|
});
|
|
407
407
|
}
|
|
@@ -414,88 +414,88 @@ function De(e, {
|
|
|
414
414
|
r,
|
|
415
415
|
o,
|
|
416
416
|
W.current,
|
|
417
|
-
|
|
417
|
+
N
|
|
418
418
|
)
|
|
419
419
|
), a.getState().cogsStateStore[r] || q(r, e), a.getState().initialStateGlobal[r] || fe(r, e));
|
|
420
|
-
const g =
|
|
420
|
+
const g = he(() => ee(
|
|
421
421
|
r,
|
|
422
422
|
o,
|
|
423
423
|
W.current,
|
|
424
|
-
|
|
424
|
+
N
|
|
425
425
|
), [r]);
|
|
426
|
-
return [
|
|
426
|
+
return [we(r), g];
|
|
427
427
|
}
|
|
428
|
-
function ee(e,
|
|
428
|
+
function ee(e, c, S, d) {
|
|
429
429
|
const u = /* @__PURE__ */ new Map();
|
|
430
430
|
let I = 0;
|
|
431
|
-
const E = (
|
|
432
|
-
const t =
|
|
431
|
+
const E = (m) => {
|
|
432
|
+
const t = m.join(".");
|
|
433
433
|
for (const [v] of u)
|
|
434
434
|
(v === t || v.startsWith(t + ".")) && u.delete(v);
|
|
435
435
|
I++;
|
|
436
|
-
},
|
|
437
|
-
removeValidation: (
|
|
438
|
-
|
|
436
|
+
}, f = {
|
|
437
|
+
removeValidation: (m) => {
|
|
438
|
+
m?.validationKey && p(m.validationKey);
|
|
439
439
|
},
|
|
440
|
-
revertToInitialState: (
|
|
440
|
+
revertToInitialState: (m) => {
|
|
441
441
|
const t = a.getState().getInitialOptions(e)?.validation;
|
|
442
|
-
t?.key &&
|
|
442
|
+
t?.key && p(t?.key), m?.validationKey && p(m.validationKey);
|
|
443
443
|
const v = a.getState().initialStateGlobal[e];
|
|
444
444
|
a.getState().clearSelectedIndexesForState(e), u.clear(), I++;
|
|
445
|
-
const
|
|
446
|
-
|
|
445
|
+
const A = l(v, []), b = z(e), O = L(b?.localStorage?.key) ? b?.localStorage?.key(v) : b?.localStorage?.key, N = `${d}-${e}-${O}`;
|
|
446
|
+
N && localStorage.removeItem(N), K(e, A), q(e, v);
|
|
447
447
|
const R = a.getState().stateComponents.get(e);
|
|
448
448
|
return R && R.components.forEach((r) => {
|
|
449
449
|
r.forceUpdate();
|
|
450
450
|
}), v;
|
|
451
451
|
},
|
|
452
|
-
updateInitialState: (
|
|
452
|
+
updateInitialState: (m) => {
|
|
453
453
|
u.clear(), I++;
|
|
454
454
|
const t = ee(
|
|
455
455
|
e,
|
|
456
|
-
|
|
457
|
-
|
|
456
|
+
c,
|
|
457
|
+
S,
|
|
458
458
|
d
|
|
459
|
-
), v = a.getState().initialStateGlobal[e],
|
|
460
|
-
return console.log("removing storage",
|
|
461
|
-
fe(e,
|
|
462
|
-
const
|
|
463
|
-
|
|
459
|
+
), v = a.getState().initialStateGlobal[e], A = z(e), b = L(A?.localStorage?.key) ? A?.localStorage?.key(v) : A?.localStorage?.key, O = `${d}-${e}-${b}`;
|
|
460
|
+
return console.log("removing storage", O), localStorage.getItem(O) && localStorage.removeItem(O), Ve(() => {
|
|
461
|
+
fe(e, m), K(e, t), q(e, m);
|
|
462
|
+
const N = a.getState().stateComponents.get(e);
|
|
463
|
+
N && N.components.forEach((R) => {
|
|
464
464
|
R.forceUpdate();
|
|
465
465
|
});
|
|
466
466
|
}), {
|
|
467
|
-
fetchId: (
|
|
467
|
+
fetchId: (N) => t.get()[N]
|
|
468
468
|
};
|
|
469
469
|
},
|
|
470
470
|
_initialState: a.getState().initialStateGlobal[e],
|
|
471
471
|
_serverState: a.getState().serverState[e],
|
|
472
472
|
_isLoading: a.getState().isLoadingGlobal[e],
|
|
473
473
|
_isServerSynced: () => {
|
|
474
|
-
const
|
|
475
|
-
return !!(
|
|
474
|
+
const m = a.getState().serverState[e];
|
|
475
|
+
return !!(m && G(m, we(e)));
|
|
476
476
|
}
|
|
477
477
|
};
|
|
478
|
-
function l(
|
|
479
|
-
const
|
|
480
|
-
u.get(
|
|
478
|
+
function l(m, t = [], v) {
|
|
479
|
+
const A = t.map(String).join(".");
|
|
480
|
+
u.get(A);
|
|
481
481
|
const b = function() {
|
|
482
482
|
return a().getNestedState(e, t);
|
|
483
483
|
};
|
|
484
|
-
Object.keys(
|
|
485
|
-
b[R] =
|
|
484
|
+
Object.keys(f).forEach((R) => {
|
|
485
|
+
b[R] = f[R];
|
|
486
486
|
});
|
|
487
|
-
const
|
|
488
|
-
apply(R, r,
|
|
487
|
+
const O = {
|
|
488
|
+
apply(R, r, B) {
|
|
489
489
|
return console.log(
|
|
490
490
|
`PROXY APPLY TRAP HIT: stateKey=${e}, path=${t.join(".")}`
|
|
491
491
|
), console.trace("Apply trap stack trace"), a().getNestedState(e, t);
|
|
492
492
|
},
|
|
493
493
|
get(R, r) {
|
|
494
494
|
if (r !== "then" && !r.startsWith("$") && r !== "stateMapNoRender") {
|
|
495
|
-
const n = t.join("."), o = `${e}////${
|
|
495
|
+
const n = t.join("."), o = `${e}////${S}`, g = a.getState().stateComponents.get(e);
|
|
496
496
|
if (g) {
|
|
497
|
-
const
|
|
498
|
-
|
|
497
|
+
const s = g.components.get(o);
|
|
498
|
+
s && (t.length > 0 || r === "get") && s.paths.add(n);
|
|
499
499
|
}
|
|
500
500
|
}
|
|
501
501
|
if (r === "getDifferences")
|
|
@@ -508,17 +508,17 @@ function ee(e, s, m, d) {
|
|
|
508
508
|
const n = a.getState().getInitialOptions(e), o = n?.sync;
|
|
509
509
|
if (!o)
|
|
510
510
|
return console.error(`No mutation defined for state key "${e}"`), { success: !1, error: "No mutation defined" };
|
|
511
|
-
const g = a.getState().getNestedState(e, []),
|
|
511
|
+
const g = a.getState().getNestedState(e, []), s = n?.validation?.key;
|
|
512
512
|
try {
|
|
513
513
|
const i = await o.action(g);
|
|
514
|
-
if (i && !i.success && i.errors &&
|
|
515
|
-
a.getState().removeValidationError(
|
|
516
|
-
const
|
|
517
|
-
a.getState().addValidationError(
|
|
514
|
+
if (i && !i.success && i.errors && s) {
|
|
515
|
+
a.getState().removeValidationError(s), i.errors.forEach((k) => {
|
|
516
|
+
const h = [s, ...k.path].join(".");
|
|
517
|
+
a.getState().addValidationError(h, k.message);
|
|
518
518
|
});
|
|
519
519
|
const y = a.getState().stateComponents.get(e);
|
|
520
|
-
y && y.components.forEach((
|
|
521
|
-
|
|
520
|
+
y && y.components.forEach((k) => {
|
|
521
|
+
k.forceUpdate();
|
|
522
522
|
});
|
|
523
523
|
}
|
|
524
524
|
return i?.success && o.onSuccess ? o.onSuccess(i.data) : !i?.success && o.onError && o.onError(i.error), i;
|
|
@@ -527,21 +527,21 @@ function ee(e, s, m, d) {
|
|
|
527
527
|
}
|
|
528
528
|
};
|
|
529
529
|
if (r === "_status") {
|
|
530
|
-
const n = a.getState().getNestedState(e, t), o = a.getState().initialStateGlobal[e], g =
|
|
531
|
-
return
|
|
530
|
+
const n = a.getState().getNestedState(e, t), o = a.getState().initialStateGlobal[e], g = D(o, t);
|
|
531
|
+
return G(n, g) ? "fresh" : "stale";
|
|
532
532
|
}
|
|
533
533
|
if (r === "getStatus")
|
|
534
534
|
return function() {
|
|
535
535
|
const n = a().getNestedState(
|
|
536
536
|
e,
|
|
537
537
|
t
|
|
538
|
-
), o = a.getState().initialStateGlobal[e], g =
|
|
539
|
-
return
|
|
538
|
+
), o = a.getState().initialStateGlobal[e], g = D(o, t);
|
|
539
|
+
return G(n, g) ? "fresh" : "stale";
|
|
540
540
|
};
|
|
541
541
|
if (r === "removeStorage")
|
|
542
542
|
return () => {
|
|
543
|
-
const n = a.getState().initialStateGlobal[e], o = z(e), g = L(o?.localStorage?.key) ? o?.localStorage?.key(n) : o?.localStorage?.key,
|
|
544
|
-
console.log("removing storage",
|
|
543
|
+
const n = a.getState().initialStateGlobal[e], o = z(e), g = L(o?.localStorage?.key) ? o?.localStorage?.key(n) : o?.localStorage?.key, s = `${d}-${e}-${g}`;
|
|
544
|
+
console.log("removing storage", s), s && localStorage.removeItem(s);
|
|
545
545
|
};
|
|
546
546
|
if (r === "showValidationErrors")
|
|
547
547
|
return () => {
|
|
@@ -550,13 +550,13 @@ function ee(e, s, m, d) {
|
|
|
550
550
|
throw new Error("Validation key not found");
|
|
551
551
|
return a.getState().getValidationErrors(n.key + "." + t.join("."));
|
|
552
552
|
};
|
|
553
|
-
if (Array.isArray(
|
|
553
|
+
if (Array.isArray(m)) {
|
|
554
554
|
if (r === "getSelected")
|
|
555
555
|
return () => {
|
|
556
556
|
const n = a.getState().getSelectedIndex(e, t.join("."));
|
|
557
557
|
if (n !== void 0)
|
|
558
558
|
return l(
|
|
559
|
-
|
|
559
|
+
m[n],
|
|
560
560
|
[...t, n.toString()],
|
|
561
561
|
v
|
|
562
562
|
);
|
|
@@ -569,13 +569,13 @@ function ee(e, s, m, d) {
|
|
|
569
569
|
return () => a.getState().getSelectedIndex(e, t.join(".")) ?? -1;
|
|
570
570
|
if (r === "stateSort")
|
|
571
571
|
return (n) => {
|
|
572
|
-
const
|
|
572
|
+
const s = [...a.getState().getNestedState(e, t).map((i, y) => ({
|
|
573
573
|
...i,
|
|
574
574
|
__origIndex: y.toString()
|
|
575
575
|
}))].sort(n);
|
|
576
|
-
return u.clear(), I++, l(
|
|
576
|
+
return u.clear(), I++, l(s, t, {
|
|
577
577
|
filtered: [...v?.filtered || [], t],
|
|
578
|
-
validIndices:
|
|
578
|
+
validIndices: s.map(
|
|
579
579
|
(i) => parseInt(i.__origIndex)
|
|
580
580
|
)
|
|
581
581
|
});
|
|
@@ -583,25 +583,25 @@ function ee(e, s, m, d) {
|
|
|
583
583
|
if (r === "stateMap" || r === "stateMapNoRender")
|
|
584
584
|
return (n) => {
|
|
585
585
|
const o = v?.filtered?.some(
|
|
586
|
-
(
|
|
587
|
-
), g = o ?
|
|
588
|
-
return r !== "stateMapNoRender" && (u.clear(), I++), g.map((
|
|
589
|
-
const y = o &&
|
|
590
|
-
|
|
586
|
+
(s) => s.join(".") === t.join(".")
|
|
587
|
+
), g = o ? m : a.getState().getNestedState(e, t);
|
|
588
|
+
return r !== "stateMapNoRender" && (u.clear(), I++), g.map((s, i) => {
|
|
589
|
+
const y = o && s.__origIndex ? s.__origIndex : i, k = l(
|
|
590
|
+
s,
|
|
591
591
|
[...t, y.toString()],
|
|
592
592
|
v
|
|
593
593
|
);
|
|
594
594
|
return n(
|
|
595
|
-
|
|
596
|
-
|
|
595
|
+
s,
|
|
596
|
+
k,
|
|
597
597
|
i,
|
|
598
|
-
|
|
599
|
-
l(
|
|
598
|
+
m,
|
|
599
|
+
l(m, t, v)
|
|
600
600
|
);
|
|
601
601
|
});
|
|
602
602
|
};
|
|
603
603
|
if (r === "$stateMap")
|
|
604
|
-
return (n) => te(
|
|
604
|
+
return (n) => te(Ge, {
|
|
605
605
|
proxy: {
|
|
606
606
|
_stateKey: e,
|
|
607
607
|
_path: t,
|
|
@@ -614,113 +614,112 @@ function ee(e, s, m, d) {
|
|
|
614
614
|
return (n) => {
|
|
615
615
|
const g = v?.filtered?.some(
|
|
616
616
|
(i) => i.join(".") === t.join(".")
|
|
617
|
-
) ?
|
|
617
|
+
) ? m : a.getState().getNestedState(e, t);
|
|
618
618
|
u.clear(), I++;
|
|
619
|
-
const
|
|
619
|
+
const s = g.flatMap(
|
|
620
620
|
(i, y) => i[n] ?? []
|
|
621
621
|
);
|
|
622
622
|
return l(
|
|
623
|
-
|
|
623
|
+
s,
|
|
624
624
|
[...t, "[*]", n],
|
|
625
625
|
v
|
|
626
626
|
);
|
|
627
627
|
};
|
|
628
628
|
if (r === "findWith")
|
|
629
629
|
return (n, o) => {
|
|
630
|
-
const g =
|
|
630
|
+
const g = m.findIndex((y) => y[n] === o);
|
|
631
631
|
if (g === -1) return;
|
|
632
|
-
const
|
|
633
|
-
return u.clear(), I++, l(
|
|
632
|
+
const s = m[g], i = [...t, g.toString()];
|
|
633
|
+
return u.clear(), I++, l(s, i);
|
|
634
634
|
};
|
|
635
635
|
if (r === "index")
|
|
636
636
|
return (n) => {
|
|
637
|
-
const o =
|
|
637
|
+
const o = m[n];
|
|
638
638
|
return l(o, [...t, n.toString()]);
|
|
639
639
|
};
|
|
640
640
|
if (r === "last")
|
|
641
641
|
return () => {
|
|
642
642
|
const n = a.getState().getNestedState(e, t);
|
|
643
643
|
if (n.length === 0) return;
|
|
644
|
-
const o = n.length - 1, g = n[o],
|
|
645
|
-
return l(g,
|
|
644
|
+
const o = n.length - 1, g = n[o], s = [...t, o.toString()];
|
|
645
|
+
return l(g, s);
|
|
646
646
|
};
|
|
647
647
|
if (r === "insert")
|
|
648
|
-
return (n) => (E(t), ce(
|
|
648
|
+
return (n) => (E(t), ce(c, n, t, e), l(
|
|
649
649
|
a.getState().getNestedState(e, t),
|
|
650
650
|
t
|
|
651
651
|
));
|
|
652
652
|
if (r === "uniqueInsert")
|
|
653
653
|
return (n, o, g) => {
|
|
654
|
-
const
|
|
654
|
+
const s = a.getState().getNestedState(e, t), i = L(n) ? n(s) : n;
|
|
655
655
|
let y = null;
|
|
656
|
-
if (!
|
|
656
|
+
if (!s.some((h) => {
|
|
657
657
|
if (o) {
|
|
658
|
-
const
|
|
659
|
-
(
|
|
658
|
+
const x = o.every(
|
|
659
|
+
(T) => G(h[T], i[T])
|
|
660
660
|
);
|
|
661
|
-
return
|
|
661
|
+
return x && (y = h), x;
|
|
662
662
|
}
|
|
663
|
-
const $ =
|
|
664
|
-
return $ && (y =
|
|
663
|
+
const $ = G(h, i);
|
|
664
|
+
return $ && (y = h), $;
|
|
665
665
|
}))
|
|
666
|
-
E(t), ce(
|
|
666
|
+
E(t), ce(c, i, t, e);
|
|
667
667
|
else if (g && y) {
|
|
668
|
-
const
|
|
669
|
-
(
|
|
668
|
+
const h = g(y), $ = s.map(
|
|
669
|
+
(x) => G(x, y) ? h : x
|
|
670
670
|
);
|
|
671
|
-
E(t), Z(
|
|
671
|
+
E(t), Z(c, $, t);
|
|
672
672
|
}
|
|
673
673
|
};
|
|
674
674
|
if (r === "cut")
|
|
675
675
|
return (n, o) => {
|
|
676
676
|
if (!o?.waitForSync)
|
|
677
|
-
return E(t), X(
|
|
677
|
+
return E(t), X(c, t, e, n), l(
|
|
678
678
|
a.getState().getNestedState(e, t),
|
|
679
679
|
t
|
|
680
680
|
);
|
|
681
681
|
};
|
|
682
682
|
if (r === "cutByValue")
|
|
683
683
|
return (n) => {
|
|
684
|
-
for (let o = 0; o <
|
|
685
|
-
|
|
684
|
+
for (let o = 0; o < m.length; o++)
|
|
685
|
+
m[o] === n && X(c, t, e, o);
|
|
686
686
|
};
|
|
687
687
|
if (r === "toggleByValue")
|
|
688
688
|
return (n) => {
|
|
689
|
-
const o =
|
|
690
|
-
o > -1 ? X(
|
|
689
|
+
const o = m.findIndex((g) => g === n);
|
|
690
|
+
o > -1 ? X(c, t, e, o) : ce(c, n, t, e);
|
|
691
691
|
};
|
|
692
692
|
if (r === "stateFind")
|
|
693
693
|
return (n) => {
|
|
694
|
-
const o =
|
|
695
|
-
if (
|
|
694
|
+
const o = a.getState().getNestedState(e, t), g = o.findIndex(n);
|
|
695
|
+
if (g === -1)
|
|
696
696
|
return;
|
|
697
|
-
const
|
|
698
|
-
return l(
|
|
697
|
+
const s = o[g], i = [...t, g.toString()];
|
|
698
|
+
return l(s, i);
|
|
699
699
|
};
|
|
700
700
|
if (r === "stateFilter")
|
|
701
701
|
return (n) => {
|
|
702
|
-
const
|
|
703
|
-
...i
|
|
704
|
-
|
|
705
|
-
})
|
|
706
|
-
|
|
707
|
-
n(o[i], i) && (g.push(i), c.push(o[i]));
|
|
708
|
-
return u.clear(), I++, l(c, t, {
|
|
702
|
+
const g = a.getState().getNestedState(e, t).filter((s, i) => {
|
|
703
|
+
const y = { ...s, __origIndex: i.toString() };
|
|
704
|
+
return n(y, i);
|
|
705
|
+
});
|
|
706
|
+
return u.clear(), I++, l(g, t, {
|
|
709
707
|
filtered: [...v?.filtered || [], t],
|
|
710
|
-
validIndices: g
|
|
711
|
-
|
|
708
|
+
validIndices: g.map(
|
|
709
|
+
(s) => parseInt(s.__origIndex)
|
|
710
|
+
)
|
|
712
711
|
});
|
|
713
712
|
};
|
|
714
713
|
}
|
|
715
|
-
const
|
|
716
|
-
if (!isNaN(Number(
|
|
714
|
+
const B = t[t.length - 1];
|
|
715
|
+
if (!isNaN(Number(B))) {
|
|
717
716
|
const n = t.slice(0, -1), o = a.getState().getNestedState(e, n);
|
|
718
717
|
if (Array.isArray(o) && r === "cut")
|
|
719
718
|
return () => X(
|
|
720
|
-
|
|
719
|
+
c,
|
|
721
720
|
n,
|
|
722
721
|
e,
|
|
723
|
-
Number(
|
|
722
|
+
Number(B)
|
|
724
723
|
);
|
|
725
724
|
}
|
|
726
725
|
if (r === "get")
|
|
@@ -754,21 +753,21 @@ function ee(e, s, m, d) {
|
|
|
754
753
|
}
|
|
755
754
|
if (r === "setSelected")
|
|
756
755
|
return (n) => {
|
|
757
|
-
const o = t.slice(0, -1), g = Number(t[t.length - 1]),
|
|
758
|
-
n ? a.getState().setSelectedIndex(e,
|
|
756
|
+
const o = t.slice(0, -1), g = Number(t[t.length - 1]), s = o.join(".");
|
|
757
|
+
n ? a.getState().setSelectedIndex(e, s, g) : a.getState().setSelectedIndex(e, s, void 0);
|
|
759
758
|
const i = a.getState().getNestedState(e, [...o]);
|
|
760
|
-
Z(
|
|
759
|
+
Z(c, i, o), E(o);
|
|
761
760
|
};
|
|
762
761
|
if (r === "toggleSelected")
|
|
763
762
|
return () => {
|
|
764
|
-
const n = t.slice(0, -1), o = Number(t[t.length - 1]), g = n.join("."),
|
|
763
|
+
const n = t.slice(0, -1), o = Number(t[t.length - 1]), g = n.join("."), s = a.getState().getSelectedIndex(e, g);
|
|
765
764
|
a.getState().setSelectedIndex(
|
|
766
765
|
e,
|
|
767
766
|
g,
|
|
768
|
-
|
|
767
|
+
s === o ? void 0 : o
|
|
769
768
|
);
|
|
770
769
|
const i = a.getState().getNestedState(e, [...n]);
|
|
771
|
-
Z(
|
|
770
|
+
Z(c, i, n), E(n);
|
|
772
771
|
};
|
|
773
772
|
if (t.length == 0) {
|
|
774
773
|
if (r === "validateZodSchema")
|
|
@@ -778,23 +777,23 @@ function ee(e, s, m, d) {
|
|
|
778
777
|
throw new Error("Zod schema not found");
|
|
779
778
|
if (!n?.key)
|
|
780
779
|
throw new Error("Validation key not found");
|
|
781
|
-
|
|
780
|
+
p(n.key);
|
|
782
781
|
const g = a.getState().cogsStateStore[e];
|
|
783
782
|
try {
|
|
784
|
-
const
|
|
785
|
-
|
|
786
|
-
y && y.startsWith(n.key) &&
|
|
783
|
+
const s = a.getState().getValidationErrors(n.key);
|
|
784
|
+
s && s.length > 0 && s.forEach(([y]) => {
|
|
785
|
+
y && y.startsWith(n.key) && p(y);
|
|
787
786
|
});
|
|
788
787
|
const i = n.zodSchema.safeParse(g);
|
|
789
|
-
return i.success ? !0 : (i.error.errors.forEach((
|
|
790
|
-
const
|
|
791
|
-
o(
|
|
788
|
+
return i.success ? !0 : (i.error.errors.forEach((k) => {
|
|
789
|
+
const h = k.path, $ = k.message, x = [n.key, ...h].join(".");
|
|
790
|
+
o(x, $);
|
|
792
791
|
}), re(e), !1);
|
|
793
|
-
} catch (
|
|
794
|
-
return console.error("Zod schema validation failed",
|
|
792
|
+
} catch (s) {
|
|
793
|
+
return console.error("Zod schema validation failed", s), !1;
|
|
795
794
|
}
|
|
796
795
|
};
|
|
797
|
-
if (r === "_componentId") return
|
|
796
|
+
if (r === "_componentId") return S;
|
|
798
797
|
if (r === "getComponents")
|
|
799
798
|
return () => a().stateComponents.get(e);
|
|
800
799
|
if (r === "getAllFormRefs")
|
|
@@ -806,9 +805,9 @@ function ee(e, s, m, d) {
|
|
|
806
805
|
if (r === "_isLoading")
|
|
807
806
|
return a.getState().isLoadingGlobal[e];
|
|
808
807
|
if (r === "revertToInitialState")
|
|
809
|
-
return
|
|
810
|
-
if (r === "updateInitialState") return
|
|
811
|
-
if (r === "removeValidation") return
|
|
808
|
+
return f.revertToInitialState;
|
|
809
|
+
if (r === "updateInitialState") return f.updateInitialState;
|
|
810
|
+
if (r === "removeValidation") return f.removeValidation;
|
|
812
811
|
}
|
|
813
812
|
if (r === "getFormRef")
|
|
814
813
|
return () => ye.getState().getFormRef(e + "." + t.join("."));
|
|
@@ -817,7 +816,7 @@ function ee(e, s, m, d) {
|
|
|
817
816
|
children: n,
|
|
818
817
|
hideMessage: o
|
|
819
818
|
}) => /* @__PURE__ */ me(
|
|
820
|
-
|
|
819
|
+
Te,
|
|
821
820
|
{
|
|
822
821
|
formOpts: o ? { validation: { message: "" } } : void 0,
|
|
823
822
|
path: t,
|
|
@@ -829,17 +828,17 @@ function ee(e, s, m, d) {
|
|
|
829
828
|
);
|
|
830
829
|
if (r === "_stateKey") return e;
|
|
831
830
|
if (r === "_path") return t;
|
|
832
|
-
if (r === "_isServerSynced") return
|
|
831
|
+
if (r === "_isServerSynced") return f._isServerSynced;
|
|
833
832
|
if (r === "update")
|
|
834
833
|
return (n, o) => {
|
|
835
834
|
if (o?.debounce)
|
|
836
|
-
|
|
837
|
-
Z(
|
|
835
|
+
xe(() => {
|
|
836
|
+
Z(c, n, t, "");
|
|
838
837
|
const g = a.getState().getNestedState(e, t);
|
|
839
838
|
o?.afterUpdate && o.afterUpdate(g);
|
|
840
839
|
}, o.debounce);
|
|
841
840
|
else {
|
|
842
|
-
Z(
|
|
841
|
+
Z(c, n, t, "");
|
|
843
842
|
const g = a.getState().getNestedState(e, t);
|
|
844
843
|
o?.afterUpdate && o.afterUpdate(g);
|
|
845
844
|
}
|
|
@@ -849,7 +848,7 @@ function ee(e, s, m, d) {
|
|
|
849
848
|
return (n, o) => /* @__PURE__ */ me(
|
|
850
849
|
Ce,
|
|
851
850
|
{
|
|
852
|
-
setState:
|
|
851
|
+
setState: c,
|
|
853
852
|
stateKey: e,
|
|
854
853
|
path: t,
|
|
855
854
|
child: n,
|
|
@@ -859,48 +858,48 @@ function ee(e, s, m, d) {
|
|
|
859
858
|
const H = [...t, r], W = a.getState().getNestedState(e, H);
|
|
860
859
|
return l(W, H, v);
|
|
861
860
|
}
|
|
862
|
-
},
|
|
863
|
-
return u.set(
|
|
864
|
-
proxy:
|
|
861
|
+
}, N = new Proxy(b, O);
|
|
862
|
+
return u.set(A, {
|
|
863
|
+
proxy: N,
|
|
865
864
|
stateVersion: I
|
|
866
|
-
}),
|
|
865
|
+
}), N;
|
|
867
866
|
}
|
|
868
867
|
return l(
|
|
869
868
|
a.getState().getNestedState(e, [])
|
|
870
869
|
);
|
|
871
870
|
}
|
|
872
871
|
function le(e) {
|
|
873
|
-
return te(
|
|
872
|
+
return te(pe, { proxy: e });
|
|
874
873
|
}
|
|
875
|
-
function
|
|
874
|
+
function Ge({
|
|
876
875
|
proxy: e,
|
|
877
|
-
rebuildStateShape:
|
|
876
|
+
rebuildStateShape: c
|
|
878
877
|
}) {
|
|
879
|
-
const
|
|
880
|
-
return Array.isArray(
|
|
881
|
-
|
|
878
|
+
const S = a().getNestedState(e._stateKey, e._path);
|
|
879
|
+
return Array.isArray(S) ? c(
|
|
880
|
+
S,
|
|
882
881
|
e._path
|
|
883
882
|
).stateMapNoRender(
|
|
884
|
-
(u, I, E,
|
|
883
|
+
(u, I, E, f, l) => e._mapFn(u, I, E, f, l)
|
|
885
884
|
) : null;
|
|
886
885
|
}
|
|
887
|
-
function
|
|
886
|
+
function pe({
|
|
888
887
|
proxy: e
|
|
889
888
|
}) {
|
|
890
|
-
const
|
|
889
|
+
const c = Q(null), S = `${e._stateKey}-${e._path.join(".")}`;
|
|
891
890
|
return ue(() => {
|
|
892
|
-
const d =
|
|
891
|
+
const d = c.current;
|
|
893
892
|
if (!d || !d.parentElement) return;
|
|
894
893
|
const u = d.parentElement, E = Array.from(u.childNodes).indexOf(d);
|
|
895
|
-
let
|
|
896
|
-
|
|
897
|
-
const
|
|
894
|
+
let f = u.getAttribute("data-parent-id");
|
|
895
|
+
f || (f = `parent-${crypto.randomUUID()}`, u.setAttribute("data-parent-id", f));
|
|
896
|
+
const m = {
|
|
898
897
|
instanceId: `instance-${crypto.randomUUID()}`,
|
|
899
|
-
parentId:
|
|
898
|
+
parentId: f,
|
|
900
899
|
position: E,
|
|
901
900
|
effect: e._effect
|
|
902
901
|
};
|
|
903
|
-
a.getState().addSignalElement(
|
|
902
|
+
a.getState().addSignalElement(S, m);
|
|
904
903
|
const t = a.getState().getNestedState(e._stateKey, e._path);
|
|
905
904
|
let v;
|
|
906
905
|
if (e._effect)
|
|
@@ -915,28 +914,28 @@ function Ge({
|
|
|
915
914
|
else
|
|
916
915
|
v = t;
|
|
917
916
|
v !== null && typeof v == "object" && (v = JSON.stringify(v));
|
|
918
|
-
const
|
|
919
|
-
d.replaceWith(
|
|
917
|
+
const A = document.createTextNode(String(v));
|
|
918
|
+
d.replaceWith(A);
|
|
920
919
|
}, [e._stateKey, e._path.join("."), e._effect]), te("span", {
|
|
921
|
-
ref:
|
|
920
|
+
ref: c,
|
|
922
921
|
style: { display: "none" },
|
|
923
|
-
"data-signal-id":
|
|
922
|
+
"data-signal-id": S
|
|
924
923
|
});
|
|
925
924
|
}
|
|
926
925
|
function et(e) {
|
|
927
|
-
const
|
|
928
|
-
(
|
|
926
|
+
const c = ke(
|
|
927
|
+
(S) => {
|
|
929
928
|
const d = a.getState().stateComponents.get(e._stateKey) || {
|
|
930
929
|
components: /* @__PURE__ */ new Map()
|
|
931
930
|
};
|
|
932
931
|
return d.components.set(e._stateKey, {
|
|
933
|
-
forceUpdate:
|
|
932
|
+
forceUpdate: S,
|
|
934
933
|
paths: /* @__PURE__ */ new Set([e._path.join(".")])
|
|
935
934
|
}), () => d.components.delete(e._stateKey);
|
|
936
935
|
},
|
|
937
936
|
() => a.getState().getNestedState(e._stateKey, e._path)
|
|
938
937
|
);
|
|
939
|
-
return te("text", {}, String(
|
|
938
|
+
return te("text", {}, String(c));
|
|
940
939
|
}
|
|
941
940
|
export {
|
|
942
941
|
le as $cogsSignal,
|
|
@@ -944,6 +943,6 @@ export {
|
|
|
944
943
|
Xe as addStateOptions,
|
|
945
944
|
Qe as createCogsState,
|
|
946
945
|
Ke as notifyComponent,
|
|
947
|
-
|
|
946
|
+
Me as useCogsStateFn
|
|
948
947
|
};
|
|
949
948
|
//# sourceMappingURL=CogsState.jsx.map
|