cogsbox-state 0.5.5 → 0.5.7
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.d.ts +30 -13
- package/dist/CogsState.jsx +544 -480
- package/dist/CogsState.jsx.map +1 -1
- package/dist/CogsStateClient.jsx +6 -6
- package/dist/CogsStateClient.jsx.map +1 -1
- package/dist/Functions.d.ts +3 -4
- package/dist/Functions.jsx +173 -128
- package/dist/Functions.jsx.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +21 -17
- package/dist/index.js.map +1 -1
- package/dist/node_modules/zustand/esm/react.js +1 -1
- package/dist/store.d.ts +19 -9
- package/dist/store.js +77 -60
- package/dist/store.js.map +1 -1
- package/dist/useValidateZodPath.d.ts +34 -0
- package/dist/useValidateZodPath.js +60 -0
- package/dist/useValidateZodPath.js.map +1 -0
- package/dist/utility.d.ts +6 -0
- package/dist/utility.js +90 -80
- package/dist/utility.js.map +1 -1
- package/package.json +68 -64
- package/dist/_virtual/_commonjsHelpers.js +0 -7
- package/dist/_virtual/_commonjsHelpers.js.map +0 -1
- package/dist/_virtual/index.js +0 -5
- package/dist/_virtual/index.js.map +0 -1
- package/dist/_virtual/jsx-runtime.jsx +0 -5
- package/dist/_virtual/jsx-runtime.jsx.map +0 -1
- package/dist/_virtual/react-jsx-runtime.jsx +0 -5
- package/dist/_virtual/react-jsx-runtime.jsx.map +0 -1
- package/dist/_virtual/react-jsx-runtime.production.jsx +0 -5
- package/dist/_virtual/react-jsx-runtime.production.jsx.map +0 -1
- package/dist/_virtual/react.js +0 -5
- package/dist/_virtual/react.js.map +0 -1
- package/dist/_virtual/react.production.js +0 -5
- package/dist/_virtual/react.production.js.map +0 -1
- package/dist/node_modules/react/cjs/react-jsx-runtime.jsx +0 -605
- package/dist/node_modules/react/cjs/react-jsx-runtime.jsx.map +0 -1
- package/dist/node_modules/react/cjs/react-jsx-runtime.production.jsx +0 -29
- package/dist/node_modules/react/cjs/react-jsx-runtime.production.jsx.map +0 -1
- package/dist/node_modules/react/cjs/react.js +0 -1274
- package/dist/node_modules/react/cjs/react.js.map +0 -1
- package/dist/node_modules/react/cjs/react.production.js +0 -209
- package/dist/node_modules/react/cjs/react.production.js.map +0 -1
- package/dist/node_modules/react/index.js +0 -12
- package/dist/node_modules/react/index.js.map +0 -1
- package/dist/node_modules/react/jsx-runtime.jsx +0 -9
- package/dist/node_modules/react/jsx-runtime.jsx.map +0 -1
package/dist/CogsState.jsx
CHANGED
|
@@ -1,72 +1,75 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { transformStateFunc as
|
|
5
|
-
import { pushFunc as
|
|
2
|
+
import { jsx as at } from "react/jsx-runtime";
|
|
3
|
+
import { useState as Y, useRef as z, useEffect as K, useLayoutEffect as vt, useMemo as It, createElement as H, useSyncExternalStore as pt, startTransition as J } from "react";
|
|
4
|
+
import { transformStateFunc as _t, isFunction as ut, getNestedValue as D, isDeepEqual as L, debounce as Et } from "./utility.js";
|
|
5
|
+
import { pushFunc as it, updateFn as q, cutFunc as st, ValidationWrapper as wt, FormControlComponent as $t } from "./Functions.jsx";
|
|
6
6
|
import "zod";
|
|
7
|
-
import { getGlobalStore as
|
|
8
|
-
import { useCogsConfig as
|
|
9
|
-
import
|
|
10
|
-
function
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
const d = a.getState().getInitialOptions, u = a.getState().setInitialStateOptions, S = d(t) || {};
|
|
15
|
-
u(t, {
|
|
16
|
-
...S,
|
|
7
|
+
import { getGlobalStore as o, formRefStore as ct } from "./store.js";
|
|
8
|
+
import { useCogsConfig as Vt } from "./CogsStateClient.jsx";
|
|
9
|
+
import tt from "./node_modules/uuid/dist/esm-browser/v4.js";
|
|
10
|
+
function lt(t, i) {
|
|
11
|
+
const f = o.getState().getInitialOptions, S = o.getState().setInitialStateOptions, g = f(t) || {};
|
|
12
|
+
S(t, {
|
|
13
|
+
...g,
|
|
17
14
|
...i
|
|
18
15
|
});
|
|
19
16
|
}
|
|
20
|
-
function
|
|
17
|
+
function dt({
|
|
21
18
|
stateKey: t,
|
|
22
19
|
options: i,
|
|
23
|
-
initialOptionsPart:
|
|
20
|
+
initialOptionsPart: f
|
|
24
21
|
}) {
|
|
25
|
-
const
|
|
26
|
-
let
|
|
22
|
+
const S = et(t) || {}, g = f[t] || {}, I = o.getState().setInitialStateOptions, _ = { ...g, ...S };
|
|
23
|
+
let p = !1;
|
|
27
24
|
if (i)
|
|
28
|
-
for (const
|
|
29
|
-
_.hasOwnProperty(
|
|
30
|
-
|
|
25
|
+
for (const m in i)
|
|
26
|
+
_.hasOwnProperty(m) || (p = !0, _[m] = i[m]);
|
|
27
|
+
p && I(t, _);
|
|
31
28
|
}
|
|
32
|
-
const
|
|
33
|
-
let
|
|
34
|
-
const [
|
|
35
|
-
|
|
36
|
-
const I = (
|
|
37
|
-
const [
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
29
|
+
const qt = (t, i) => {
|
|
30
|
+
let f = t;
|
|
31
|
+
const [S, g] = _t(f);
|
|
32
|
+
o.getState().setInitialStates(S);
|
|
33
|
+
const I = (p, m) => {
|
|
34
|
+
const [E] = Y(m?.componentId ?? tt());
|
|
35
|
+
dt({
|
|
36
|
+
stateKey: p,
|
|
37
|
+
options: m,
|
|
38
|
+
initialOptionsPart: g
|
|
39
|
+
});
|
|
40
|
+
const l = o.getState().cogsStateStore[p] || S[p], e = m?.modifyState ? m.modifyState(l) : l, [v, h] = jt(
|
|
41
|
+
e,
|
|
41
42
|
{
|
|
42
|
-
stateKey:
|
|
43
|
-
syncUpdate:
|
|
44
|
-
componentId:
|
|
45
|
-
localStorage:
|
|
46
|
-
middleware:
|
|
47
|
-
enabledSync:
|
|
48
|
-
|
|
49
|
-
|
|
43
|
+
stateKey: p,
|
|
44
|
+
syncUpdate: m?.syncUpdate,
|
|
45
|
+
componentId: E,
|
|
46
|
+
localStorage: m?.localStorage,
|
|
47
|
+
middleware: m?.middleware,
|
|
48
|
+
enabledSync: m?.enabledSync,
|
|
49
|
+
reactiveType: m?.reactiveType,
|
|
50
|
+
reactiveDeps: m?.reactiveDeps,
|
|
51
|
+
initState: m?.initState,
|
|
52
|
+
localStorageKey: m?.localStorageKey
|
|
50
53
|
}
|
|
51
54
|
);
|
|
52
|
-
return
|
|
55
|
+
return h;
|
|
53
56
|
};
|
|
54
|
-
function _(
|
|
55
|
-
|
|
57
|
+
function _(p, m) {
|
|
58
|
+
dt({ stateKey: p, options: m, initialOptionsPart: g });
|
|
56
59
|
}
|
|
57
60
|
return { useCogsState: I, setCogsOptions: _ };
|
|
58
61
|
}, {
|
|
59
|
-
setUpdaterState:
|
|
60
|
-
setState:
|
|
61
|
-
getInitialOptions:
|
|
62
|
-
getKeyState:
|
|
63
|
-
getValidationErrors:
|
|
64
|
-
setStateLog:
|
|
65
|
-
updateInitialStateGlobal:
|
|
66
|
-
addValidationError:
|
|
67
|
-
removeValidationError:
|
|
68
|
-
setServerSyncActions:
|
|
69
|
-
} =
|
|
62
|
+
setUpdaterState: B,
|
|
63
|
+
setState: x,
|
|
64
|
+
getInitialOptions: et,
|
|
65
|
+
getKeyState: ft,
|
|
66
|
+
getValidationErrors: Nt,
|
|
67
|
+
setStateLog: ht,
|
|
68
|
+
updateInitialStateGlobal: nt,
|
|
69
|
+
addValidationError: Ct,
|
|
70
|
+
removeValidationError: R,
|
|
71
|
+
setServerSyncActions: Tt
|
|
72
|
+
} = o.getState(), gt = (t) => {
|
|
70
73
|
if (!t) return null;
|
|
71
74
|
try {
|
|
72
75
|
const i = window.localStorage.getItem(t);
|
|
@@ -74,584 +77,645 @@ const Ot = (t, i) => {
|
|
|
74
77
|
} catch (i) {
|
|
75
78
|
return console.error("Error loading from localStorage:", i), null;
|
|
76
79
|
}
|
|
77
|
-
},
|
|
78
|
-
if (
|
|
79
|
-
const
|
|
80
|
+
}, At = (t, i, f, S) => {
|
|
81
|
+
if (f.localStorageKey) {
|
|
82
|
+
const g = {
|
|
80
83
|
state: t,
|
|
81
84
|
lastUpdated: Date.now(),
|
|
82
|
-
lastSyncedWithServer:
|
|
83
|
-
baseServerState:
|
|
84
|
-
}, I =
|
|
85
|
-
window.localStorage.setItem(I, JSON.stringify(
|
|
85
|
+
lastSyncedWithServer: o.getState().serverSyncLog[i]?.[0]?.timeStamp,
|
|
86
|
+
baseServerState: o.getState().serverState[i]
|
|
87
|
+
}, I = f.initState ? `${S}-${i}-${f.localStorageKey}` : i;
|
|
88
|
+
window.localStorage.setItem(I, JSON.stringify(g));
|
|
86
89
|
}
|
|
87
|
-
},
|
|
90
|
+
}, Ft = (t, i, f, S, g, I) => {
|
|
88
91
|
const _ = {
|
|
89
92
|
initialState: i,
|
|
90
|
-
updaterState:
|
|
93
|
+
updaterState: Z(
|
|
91
94
|
t,
|
|
92
|
-
u,
|
|
93
95
|
S,
|
|
96
|
+
g,
|
|
94
97
|
I
|
|
95
98
|
),
|
|
96
|
-
state:
|
|
99
|
+
state: f
|
|
97
100
|
};
|
|
98
|
-
|
|
99
|
-
|
|
101
|
+
J(() => {
|
|
102
|
+
nt(t, _.initialState), B(t, _.updaterState), x(t, _.state);
|
|
100
103
|
});
|
|
101
|
-
},
|
|
102
|
-
const i =
|
|
104
|
+
}, Mt = (t) => {
|
|
105
|
+
const i = o.getState().stateComponents.get(t);
|
|
103
106
|
if (!i) return;
|
|
104
|
-
const
|
|
105
|
-
i.components.forEach((
|
|
106
|
-
|
|
107
|
+
const f = /* @__PURE__ */ new Set();
|
|
108
|
+
i.components.forEach((S) => {
|
|
109
|
+
f.add(() => S.forceUpdate());
|
|
107
110
|
}), queueMicrotask(() => {
|
|
108
|
-
|
|
109
|
-
|
|
111
|
+
J(() => {
|
|
112
|
+
f.forEach((S) => S());
|
|
110
113
|
});
|
|
111
114
|
});
|
|
115
|
+
}, zt = (t, i) => {
|
|
116
|
+
const f = o.getState().stateComponents.get(t);
|
|
117
|
+
if (f) {
|
|
118
|
+
const S = `${t}////${i}`, g = f.components.get(S);
|
|
119
|
+
g && g.forceUpdate();
|
|
120
|
+
}
|
|
112
121
|
};
|
|
113
|
-
function
|
|
122
|
+
function jt(t, {
|
|
114
123
|
stateKey: i,
|
|
115
|
-
serverSync:
|
|
116
|
-
zodSchema: u,
|
|
124
|
+
serverSync: f,
|
|
117
125
|
localStorage: S,
|
|
118
|
-
formElements:
|
|
119
|
-
middleware:
|
|
120
|
-
reactiveDeps:
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
126
|
+
formElements: g,
|
|
127
|
+
middleware: I,
|
|
128
|
+
reactiveDeps: _,
|
|
129
|
+
reactiveType: p,
|
|
130
|
+
componentId: m,
|
|
131
|
+
localStorageKey: E,
|
|
132
|
+
initState: l,
|
|
133
|
+
syncUpdate: e
|
|
124
134
|
} = {}) {
|
|
125
|
-
const [
|
|
126
|
-
let
|
|
127
|
-
const [
|
|
128
|
-
A.current =
|
|
129
|
-
if (
|
|
130
|
-
|
|
131
|
-
...
|
|
132
|
-
[
|
|
135
|
+
const [v, h] = Y({}), { sessionId: F } = Vt();
|
|
136
|
+
let U = !i;
|
|
137
|
+
const [d] = Y(i ?? tt()), a = o.getState().stateLog[d], G = z(/* @__PURE__ */ new Set()), b = z(m ?? tt()), A = z(null);
|
|
138
|
+
A.current = et(d), K(() => {
|
|
139
|
+
if (e && e.stateKey === d && e.path?.[0]) {
|
|
140
|
+
x(d, (r) => ({
|
|
141
|
+
...r,
|
|
142
|
+
[e.path[0]]: e.newValue
|
|
133
143
|
}));
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
timeStamp:
|
|
137
|
-
userId:
|
|
144
|
+
const c = `${e.stateKey}:${e.path.join(".")}`;
|
|
145
|
+
o.getState().setSyncInfo(c, {
|
|
146
|
+
timeStamp: e.timeStamp,
|
|
147
|
+
userId: e.userId
|
|
138
148
|
});
|
|
139
149
|
}
|
|
140
|
-
}, [
|
|
141
|
-
|
|
142
|
-
initState:
|
|
150
|
+
}, [e]), K(() => {
|
|
151
|
+
lt(d, {
|
|
152
|
+
initState: l
|
|
143
153
|
});
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
154
|
+
let c = null;
|
|
155
|
+
E && (c = gt(
|
|
156
|
+
F + "-" + d + "-" + E
|
|
157
|
+
));
|
|
158
|
+
let r = null;
|
|
159
|
+
l?.initialState && (r = l?.initialState, console.log("newState", r), c && c.lastUpdated > (c.lastSyncedWithServer || 0) && (r = c.state), Ft(
|
|
160
|
+
d,
|
|
161
|
+
l?.initialState,
|
|
162
|
+
r,
|
|
151
163
|
n,
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
zodSchema: u,
|
|
161
|
-
initState: p,
|
|
164
|
+
b.current,
|
|
165
|
+
F
|
|
166
|
+
), console.log("newState222", r), h({}));
|
|
167
|
+
}, [E, ...l?.dependencies || []]), vt(() => {
|
|
168
|
+
U && lt(d, {
|
|
169
|
+
serverSync: f,
|
|
170
|
+
formElements: g,
|
|
171
|
+
initState: l,
|
|
162
172
|
localStorage: S,
|
|
163
|
-
middleware:
|
|
173
|
+
middleware: I
|
|
164
174
|
});
|
|
165
|
-
const
|
|
175
|
+
const c = `${d}////${b.current}`, r = o.getState().stateComponents.get(d) || {
|
|
166
176
|
components: /* @__PURE__ */ new Map()
|
|
167
177
|
};
|
|
168
|
-
return
|
|
169
|
-
forceUpdate: () =>
|
|
178
|
+
return r.components.set(c, {
|
|
179
|
+
forceUpdate: () => h({}),
|
|
170
180
|
paths: /* @__PURE__ */ new Set(),
|
|
171
181
|
deps: [],
|
|
172
|
-
depsFunction:
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
182
|
+
depsFunction: _ || void 0,
|
|
183
|
+
reactiveType: p ?? ["component", "deps"]
|
|
184
|
+
}), o.getState().stateComponents.set(d, r), h({}), () => {
|
|
185
|
+
const u = `${d}////${b.current}`;
|
|
186
|
+
r && (r.components.delete(u), r.components.size === 0 && o.getState().stateComponents.delete(d));
|
|
176
187
|
};
|
|
177
188
|
}, []);
|
|
178
|
-
const
|
|
179
|
-
if (Array.isArray(
|
|
180
|
-
const
|
|
181
|
-
|
|
189
|
+
const n = (c, r, u, w) => {
|
|
190
|
+
if (Array.isArray(r)) {
|
|
191
|
+
const M = `${d}-${r.join(".")}`;
|
|
192
|
+
G.current.add(M);
|
|
182
193
|
}
|
|
183
|
-
|
|
184
|
-
const
|
|
185
|
-
if (
|
|
186
|
-
let
|
|
187
|
-
if ((!
|
|
188
|
-
const
|
|
189
|
-
if (Array.isArray(
|
|
190
|
-
|
|
191
|
-
const
|
|
192
|
-
|
|
194
|
+
x(d, (M) => {
|
|
195
|
+
const V = ut(c) ? c(M) : c, j = `${d}-${r.join(".")}`;
|
|
196
|
+
if (j) {
|
|
197
|
+
let P = !1, y = o.getState().signalDomElements.get(j);
|
|
198
|
+
if ((!y || y.size === 0) && (u.updateType === "insert" || u.updateType === "cut")) {
|
|
199
|
+
const N = r.slice(0, -1), T = D(V, N);
|
|
200
|
+
if (Array.isArray(T)) {
|
|
201
|
+
P = !0;
|
|
202
|
+
const $ = `${d}-${N.join(".")}`;
|
|
203
|
+
y = o.getState().signalDomElements.get($);
|
|
193
204
|
}
|
|
194
205
|
}
|
|
195
|
-
if (
|
|
196
|
-
const
|
|
197
|
-
|
|
198
|
-
const
|
|
199
|
-
`[data-parent-id="${
|
|
206
|
+
if (y) {
|
|
207
|
+
const N = P ? D(V, r.slice(0, -1)) : D(V, r);
|
|
208
|
+
y.forEach(({ parentId: T, position: $, effect: k }) => {
|
|
209
|
+
const O = document.querySelector(
|
|
210
|
+
`[data-parent-id="${T}"]`
|
|
200
211
|
);
|
|
201
|
-
if (
|
|
202
|
-
const
|
|
203
|
-
if (
|
|
204
|
-
const
|
|
205
|
-
|
|
206
|
-
`return (${D})(state)`
|
|
207
|
-
)(V) : V;
|
|
208
|
-
X[T].textContent = String(dt);
|
|
212
|
+
if (O) {
|
|
213
|
+
const ot = Array.from(O.childNodes);
|
|
214
|
+
if (ot[$]) {
|
|
215
|
+
const yt = k ? new Function("state", `return (${k})(state)`)(N) : N;
|
|
216
|
+
ot[$].textContent = String(yt);
|
|
209
217
|
}
|
|
210
218
|
}
|
|
211
219
|
});
|
|
212
220
|
}
|
|
213
221
|
}
|
|
214
|
-
|
|
215
|
-
(
|
|
222
|
+
u.updateType === "update" && (w || A.current?.validationKey) && r && R(
|
|
223
|
+
(w || A.current?.validationKey) + "." + r.join(".")
|
|
216
224
|
);
|
|
217
|
-
const
|
|
218
|
-
|
|
219
|
-
A.current?.validationKey + "." +
|
|
220
|
-
),
|
|
221
|
-
A.current?.validationKey + "." +
|
|
222
|
-
).filter(([
|
|
223
|
-
let
|
|
224
|
-
if (
|
|
225
|
-
let
|
|
226
|
-
|
|
225
|
+
const C = r.slice(0, r.length - 1);
|
|
226
|
+
u.updateType === "cut" && A.current?.validationKey && R(
|
|
227
|
+
A.current?.validationKey + "." + C.join(".")
|
|
228
|
+
), u.updateType === "insert" && A.current?.validationKey && Nt(
|
|
229
|
+
A.current?.validationKey + "." + C.join(".")
|
|
230
|
+
).filter(([y, N]) => {
|
|
231
|
+
let T = y?.split(".").length;
|
|
232
|
+
if (y == C.join(".") && T == C.length - 1) {
|
|
233
|
+
let $ = y + "." + C;
|
|
234
|
+
R(y), Ct($, N);
|
|
227
235
|
}
|
|
228
236
|
});
|
|
229
|
-
const
|
|
230
|
-
if (
|
|
231
|
-
for (const [
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
237
|
+
const W = D(M, r), St = D(V, r), mt = u.updateType === "update" ? r.join(".") : [...r].slice(0, -1).join("."), Q = o.getState().stateComponents.get(d);
|
|
238
|
+
if (i == "cart" && (console.log("thisKey", d), console.log("stateEntry", Q)), Q)
|
|
239
|
+
for (const [P, y] of Q.components.entries()) {
|
|
240
|
+
let N = !1;
|
|
241
|
+
const T = Array.isArray(y.reactiveType) ? y.reactiveType : [y.reactiveType || "component"];
|
|
242
|
+
if (!T.includes("none")) {
|
|
243
|
+
if (T.includes("all")) {
|
|
244
|
+
y.forceUpdate();
|
|
245
|
+
continue;
|
|
246
|
+
}
|
|
247
|
+
if (T.includes("component") && y.paths && (y.paths.has(mt) || y.paths.has("")) && (N = !0), !N && T.includes("deps") && y.depsFunction) {
|
|
248
|
+
const $ = y.depsFunction(V);
|
|
249
|
+
typeof $ == "boolean" ? $ && (N = !0) : L(y.deps, $) || (y.deps = $, N = !0);
|
|
250
|
+
}
|
|
251
|
+
N && y.forceUpdate();
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
const rt = {
|
|
243
255
|
timeStamp: Date.now(),
|
|
244
|
-
stateKey:
|
|
245
|
-
path:
|
|
246
|
-
updateType:
|
|
256
|
+
stateKey: d,
|
|
257
|
+
path: r,
|
|
258
|
+
updateType: u.updateType,
|
|
247
259
|
status: "new",
|
|
248
|
-
oldValue:
|
|
249
|
-
newValue:
|
|
260
|
+
oldValue: W,
|
|
261
|
+
newValue: St
|
|
250
262
|
};
|
|
251
|
-
if (
|
|
252
|
-
const
|
|
253
|
-
const
|
|
254
|
-
return
|
|
255
|
-
C.timeStamp,
|
|
256
|
-
T.timeStamp
|
|
257
|
-
), C.newValue = T.newValue, C.oldValue = C.oldValue ?? T.oldValue, C.updateType = T.updateType) : x.set(D, { ...T }), x;
|
|
263
|
+
if (ht(d, (P) => {
|
|
264
|
+
const N = [...P ?? [], rt].reduce((T, $) => {
|
|
265
|
+
const k = `${$.stateKey}:${JSON.stringify($.path)}`, O = T.get(k);
|
|
266
|
+
return O ? (O.timeStamp = Math.max(O.timeStamp, $.timeStamp), O.newValue = $.newValue, O.oldValue = O.oldValue ?? $.oldValue, O.updateType = $.updateType) : T.set(k, { ...$ }), T;
|
|
258
267
|
}, /* @__PURE__ */ new Map());
|
|
259
|
-
return Array.from(
|
|
260
|
-
}),
|
|
261
|
-
|
|
262
|
-
|
|
268
|
+
return Array.from(N.values());
|
|
269
|
+
}), At(
|
|
270
|
+
V,
|
|
271
|
+
d,
|
|
263
272
|
A.current,
|
|
264
|
-
|
|
265
|
-
),
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
273
|
+
F
|
|
274
|
+
), I && I({
|
|
275
|
+
updateLog: a,
|
|
276
|
+
update: rt
|
|
277
|
+
}), A.current?.serverSync) {
|
|
278
|
+
const P = o.getState().serverState[d], y = A.current?.serverSync;
|
|
279
|
+
Tt(d, {
|
|
280
|
+
syncKey: typeof y.syncKey == "string" ? y.syncKey : y.syncKey({ state: V }),
|
|
281
|
+
rollBackState: P,
|
|
282
|
+
actionTimeStamp: Date.now() + (y.debounce ?? 3e3),
|
|
271
283
|
status: "waiting"
|
|
272
284
|
});
|
|
273
285
|
}
|
|
274
|
-
return
|
|
286
|
+
return V;
|
|
275
287
|
});
|
|
276
288
|
};
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
289
|
+
o.getState().updaterState[d] || (console.log("Initializing state for", d, t), B(
|
|
290
|
+
d,
|
|
291
|
+
Z(
|
|
292
|
+
d,
|
|
293
|
+
n,
|
|
294
|
+
b.current,
|
|
295
|
+
F
|
|
284
296
|
)
|
|
285
|
-
),
|
|
286
|
-
const
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
), [
|
|
292
|
-
return [
|
|
297
|
+
), o.getState().cogsStateStore[d] || x(d, t), o.getState().initialStateGlobal[d] || nt(d, t));
|
|
298
|
+
const s = It(() => Z(
|
|
299
|
+
d,
|
|
300
|
+
n,
|
|
301
|
+
b.current,
|
|
302
|
+
F
|
|
303
|
+
), [d]);
|
|
304
|
+
return [ft(d), s];
|
|
293
305
|
}
|
|
294
|
-
function
|
|
295
|
-
const
|
|
306
|
+
function Z(t, i, f, S) {
|
|
307
|
+
const g = /* @__PURE__ */ new Map();
|
|
296
308
|
let I = 0;
|
|
297
|
-
const _ = (
|
|
298
|
-
const
|
|
299
|
-
for (const [v] of
|
|
300
|
-
(v ===
|
|
309
|
+
const _ = (l) => {
|
|
310
|
+
const e = l.join(".");
|
|
311
|
+
for (const [v] of g)
|
|
312
|
+
(v === e || v.startsWith(e + ".")) && g.delete(v);
|
|
301
313
|
I++;
|
|
302
|
-
},
|
|
303
|
-
removeValidation: (
|
|
304
|
-
|
|
314
|
+
}, p = /* @__PURE__ */ new Map(), m = {
|
|
315
|
+
removeValidation: (l) => {
|
|
316
|
+
l?.validationKey && R(l.validationKey);
|
|
305
317
|
},
|
|
306
|
-
revertToInitialState: (
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
318
|
+
revertToInitialState: (l) => {
|
|
319
|
+
const e = o.getState().getInitialOptions(t)?.validation;
|
|
320
|
+
e?.key && R(e?.key), l?.validationKey && R(l.validationKey);
|
|
321
|
+
const v = o.getState().initialStateGlobal[t];
|
|
322
|
+
g.clear(), I++;
|
|
323
|
+
const h = E(v, []);
|
|
324
|
+
J(() => {
|
|
325
|
+
B(t, h), x(t, v);
|
|
326
|
+
const F = o.getState().stateComponents.get(t);
|
|
327
|
+
F && F.components.forEach((d) => {
|
|
328
|
+
d.forceUpdate();
|
|
316
329
|
});
|
|
317
|
-
const
|
|
318
|
-
|
|
319
|
-
|
|
330
|
+
const U = et(t);
|
|
331
|
+
U?.localStorageKey && localStorage.removeItem(
|
|
332
|
+
U?.initState ? S + "-" + t + "-" + U?.localStorageKey : t
|
|
320
333
|
), localStorage.removeItem(t);
|
|
321
334
|
});
|
|
322
335
|
},
|
|
323
|
-
updateInitialState: (
|
|
324
|
-
|
|
325
|
-
const
|
|
336
|
+
updateInitialState: (l) => {
|
|
337
|
+
g.clear(), I++;
|
|
338
|
+
const e = Z(
|
|
326
339
|
t,
|
|
327
340
|
i,
|
|
328
|
-
|
|
329
|
-
|
|
341
|
+
f,
|
|
342
|
+
S
|
|
330
343
|
);
|
|
331
|
-
return
|
|
332
|
-
|
|
333
|
-
const v =
|
|
334
|
-
v && v.components.forEach((
|
|
335
|
-
|
|
344
|
+
return J(() => {
|
|
345
|
+
nt(t, l), B(t, e), x(t, l);
|
|
346
|
+
const v = o.getState().stateComponents.get(t);
|
|
347
|
+
v && v.components.forEach((h) => {
|
|
348
|
+
h.forceUpdate();
|
|
336
349
|
}), localStorage.removeItem(t);
|
|
337
350
|
}), {
|
|
338
|
-
fetchId: (v) =>
|
|
351
|
+
fetchId: (v) => e.get()[v]
|
|
339
352
|
};
|
|
340
353
|
},
|
|
341
|
-
_initialState:
|
|
342
|
-
_serverState:
|
|
343
|
-
_isLoading:
|
|
354
|
+
_initialState: o.getState().initialStateGlobal[t],
|
|
355
|
+
_serverState: o.getState().serverState[t],
|
|
356
|
+
_isLoading: o.getState().isLoadingGlobal[t],
|
|
344
357
|
_isServerSynced: () => {
|
|
345
|
-
const
|
|
346
|
-
return !!(
|
|
358
|
+
const l = o.getState().serverState[t];
|
|
359
|
+
return !!(l && L(l, ft(t)));
|
|
347
360
|
}
|
|
348
361
|
};
|
|
349
|
-
function
|
|
350
|
-
const
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
g && g.paths.add(e);
|
|
362
|
+
function E(l, e = [], v) {
|
|
363
|
+
const h = e.map(String).join(".");
|
|
364
|
+
g.get(h);
|
|
365
|
+
const F = {
|
|
366
|
+
get(d, a) {
|
|
367
|
+
if (a !== "then" && !a.startsWith("$") && a !== "stateMapNoRender") {
|
|
368
|
+
const n = e.join("."), s = `${t}////${f}`, c = o.getState().stateComponents.get(t);
|
|
369
|
+
if (c) {
|
|
370
|
+
const r = c.components.get(s);
|
|
371
|
+
r && (e.length > 0 || a === "get") && r.paths.add(n);
|
|
360
372
|
}
|
|
361
373
|
}
|
|
362
|
-
if (
|
|
363
|
-
|
|
374
|
+
if (a === "showValidationErrors")
|
|
375
|
+
return () => {
|
|
376
|
+
const n = o.getState().getInitialOptions(t)?.validation;
|
|
377
|
+
if (!n?.key)
|
|
378
|
+
throw new Error("Validation key not found");
|
|
379
|
+
return o.getState().getValidationErrors(n.key + "." + e.join("."));
|
|
380
|
+
};
|
|
381
|
+
if (Array.isArray(l)) {
|
|
382
|
+
if (a === "getSelected")
|
|
364
383
|
return () => {
|
|
365
|
-
const
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
o[e],
|
|
371
|
-
[...r, e.toString()],
|
|
384
|
+
const n = p.get(e.join("."));
|
|
385
|
+
if (n !== void 0)
|
|
386
|
+
return E(
|
|
387
|
+
l[n],
|
|
388
|
+
[...e, n.toString()],
|
|
372
389
|
v
|
|
373
390
|
);
|
|
374
391
|
};
|
|
375
|
-
if (
|
|
376
|
-
return (
|
|
377
|
-
const
|
|
378
|
-
(
|
|
379
|
-
),
|
|
380
|
-
return
|
|
381
|
-
const
|
|
382
|
-
|
|
383
|
-
[...
|
|
392
|
+
if (a === "stateMap" || a === "stateMapNoRender")
|
|
393
|
+
return (n) => {
|
|
394
|
+
const s = v?.filtered?.some(
|
|
395
|
+
(r) => r.join(".") === e.join(".")
|
|
396
|
+
), c = s ? l : o.getState().getNestedState(t, e);
|
|
397
|
+
return a !== "stateMapNoRender" && (g.clear(), I++), c.map((r, u) => {
|
|
398
|
+
const w = s && r.__origIndex ? r.__origIndex : u, M = E(
|
|
399
|
+
r,
|
|
400
|
+
[...e, w.toString()],
|
|
384
401
|
v
|
|
385
402
|
);
|
|
386
|
-
return
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
o,
|
|
393
|
-
r,
|
|
394
|
-
v
|
|
395
|
-
)
|
|
403
|
+
return n(
|
|
404
|
+
r,
|
|
405
|
+
M,
|
|
406
|
+
u,
|
|
407
|
+
l,
|
|
408
|
+
E(l, e, v)
|
|
396
409
|
);
|
|
397
410
|
});
|
|
398
411
|
};
|
|
399
|
-
if (
|
|
400
|
-
return (
|
|
412
|
+
if (a === "$stateMap")
|
|
413
|
+
return (n) => H(Ot, {
|
|
401
414
|
proxy: {
|
|
402
415
|
_stateKey: t,
|
|
403
|
-
_path:
|
|
404
|
-
_mapFn:
|
|
416
|
+
_path: e,
|
|
417
|
+
_mapFn: n
|
|
405
418
|
// Pass the actual function, not string
|
|
406
|
-
}
|
|
419
|
+
},
|
|
420
|
+
rebuildStateShape: E
|
|
407
421
|
});
|
|
408
|
-
if (
|
|
409
|
-
return (
|
|
410
|
-
const
|
|
411
|
-
(
|
|
412
|
-
) ?
|
|
413
|
-
|
|
414
|
-
const
|
|
415
|
-
(
|
|
422
|
+
if (a === "stateFlattenOn")
|
|
423
|
+
return (n) => {
|
|
424
|
+
const c = v?.filtered?.some(
|
|
425
|
+
(u) => u.join(".") === e.join(".")
|
|
426
|
+
) ? l : o.getState().getNestedState(t, e);
|
|
427
|
+
g.clear(), I++;
|
|
428
|
+
const r = c.flatMap(
|
|
429
|
+
(u, w) => u[n] ?? []
|
|
416
430
|
);
|
|
417
|
-
return
|
|
418
|
-
|
|
419
|
-
[...
|
|
431
|
+
return E(
|
|
432
|
+
r,
|
|
433
|
+
[...e, "[*]", n],
|
|
420
434
|
v
|
|
421
435
|
);
|
|
422
436
|
};
|
|
423
|
-
if (
|
|
424
|
-
return (
|
|
425
|
-
const
|
|
426
|
-
(
|
|
437
|
+
if (a === "findWith")
|
|
438
|
+
return (n, s) => {
|
|
439
|
+
const c = l.findIndex(
|
|
440
|
+
(w) => w[n] === s
|
|
427
441
|
);
|
|
428
|
-
if (
|
|
429
|
-
const
|
|
430
|
-
return
|
|
442
|
+
if (c === -1) return;
|
|
443
|
+
const r = l[c], u = [...e, c.toString()];
|
|
444
|
+
return g.clear(), I++, g.clear(), I++, E(r, u);
|
|
431
445
|
};
|
|
432
|
-
if (
|
|
433
|
-
return (
|
|
434
|
-
const
|
|
435
|
-
return
|
|
436
|
-
...r,
|
|
437
|
-
e.toString()
|
|
438
|
-
]);
|
|
446
|
+
if (a === "index")
|
|
447
|
+
return (n) => {
|
|
448
|
+
const s = l[n];
|
|
449
|
+
return E(s, [...e, n.toString()]);
|
|
439
450
|
};
|
|
440
|
-
if (
|
|
441
|
-
return (
|
|
442
|
-
|
|
443
|
-
e,
|
|
444
|
-
r,
|
|
445
|
-
t
|
|
446
|
-
), p(
|
|
447
|
-
a.getState().cogsStateStore[t],
|
|
451
|
+
if (a === "insert")
|
|
452
|
+
return (n) => (_(e), it(i, n, e, t), E(
|
|
453
|
+
o.getState().cogsStateStore[t],
|
|
448
454
|
[]
|
|
449
455
|
));
|
|
450
|
-
if (
|
|
451
|
-
return (
|
|
452
|
-
const
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
))
|
|
456
|
+
if (a === "uniqueInsert")
|
|
457
|
+
return (n, s, c) => {
|
|
458
|
+
const r = o.getState().getNestedState(t, e), u = ut(n) ? n(r) : n;
|
|
459
|
+
let w = null;
|
|
460
|
+
if (!r.some((V) => {
|
|
461
|
+
if (s) {
|
|
462
|
+
const C = s.every(
|
|
463
|
+
(W) => L(V[W], u[W])
|
|
464
|
+
);
|
|
465
|
+
return C && (w = V), C;
|
|
466
|
+
}
|
|
467
|
+
const j = L(V, u);
|
|
468
|
+
return j && (w = V), j;
|
|
469
|
+
}))
|
|
470
|
+
_(e), it(i, u, e, t);
|
|
471
|
+
else if (c && w) {
|
|
472
|
+
const V = c(w), j = r.map(
|
|
473
|
+
(C) => L(C, w) ? V : C
|
|
474
|
+
);
|
|
475
|
+
_(e), q(i, j, e);
|
|
476
|
+
}
|
|
464
477
|
};
|
|
465
|
-
if (
|
|
466
|
-
return (
|
|
467
|
-
|
|
478
|
+
if (a === "cut")
|
|
479
|
+
return (n, s) => {
|
|
480
|
+
s?.waitForSync || (_(e), st(i, e, t, n));
|
|
468
481
|
};
|
|
469
|
-
if (
|
|
470
|
-
return (
|
|
471
|
-
const
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
{
|
|
483
|
-
filtered: [...v?.filtered || [], r],
|
|
484
|
-
validIndices: l
|
|
485
|
-
// Pass through the meta
|
|
486
|
-
}
|
|
487
|
-
);
|
|
482
|
+
if (a === "stateFilter")
|
|
483
|
+
return (n) => {
|
|
484
|
+
const s = l.map((u, w) => ({
|
|
485
|
+
...u,
|
|
486
|
+
__origIndex: w.toString()
|
|
487
|
+
})), c = [], r = [];
|
|
488
|
+
for (let u = 0; u < s.length; u++)
|
|
489
|
+
n(s[u], u) && (c.push(u), r.push(s[u]));
|
|
490
|
+
return g.clear(), I++, E(r, e, {
|
|
491
|
+
filtered: [...v?.filtered || [], e],
|
|
492
|
+
validIndices: c
|
|
493
|
+
// Pass through the meta
|
|
494
|
+
});
|
|
488
495
|
};
|
|
489
496
|
}
|
|
490
|
-
const
|
|
491
|
-
if (!isNaN(Number(
|
|
492
|
-
const
|
|
493
|
-
if (Array.isArray(
|
|
494
|
-
return () =>
|
|
497
|
+
const G = e[e.length - 1];
|
|
498
|
+
if (!isNaN(Number(G))) {
|
|
499
|
+
const n = e.slice(0, -1), s = o.getState().getNestedState(t, n);
|
|
500
|
+
if (Array.isArray(s) && a === "cut")
|
|
501
|
+
return () => st(
|
|
495
502
|
i,
|
|
496
|
-
|
|
503
|
+
n,
|
|
497
504
|
t,
|
|
498
|
-
Number(
|
|
505
|
+
Number(G)
|
|
499
506
|
);
|
|
500
507
|
}
|
|
501
|
-
if (
|
|
502
|
-
return () =>
|
|
503
|
-
if (
|
|
504
|
-
return (
|
|
508
|
+
if (a === "get")
|
|
509
|
+
return () => o.getState().getNestedState(t, e);
|
|
510
|
+
if (a === "$derive")
|
|
511
|
+
return (n) => X({
|
|
505
512
|
_stateKey: t,
|
|
506
|
-
_path:
|
|
507
|
-
_effect:
|
|
513
|
+
_path: e,
|
|
514
|
+
_effect: n.toString()
|
|
508
515
|
});
|
|
509
|
-
if (
|
|
510
|
-
return () =>
|
|
516
|
+
if (a === "$derive")
|
|
517
|
+
return (n) => X({
|
|
511
518
|
_stateKey: t,
|
|
512
|
-
_path:
|
|
519
|
+
_path: e,
|
|
520
|
+
_effect: n.toString()
|
|
513
521
|
});
|
|
514
|
-
if (
|
|
515
|
-
|
|
516
|
-
|
|
522
|
+
if (a === "$get")
|
|
523
|
+
return () => X({
|
|
524
|
+
_stateKey: t,
|
|
525
|
+
_path: e
|
|
526
|
+
});
|
|
527
|
+
if (a === "lastSynced") {
|
|
528
|
+
const n = `${t}:${e.join(".")}`;
|
|
529
|
+
return o.getState().getSyncInfo(n);
|
|
517
530
|
}
|
|
518
|
-
if (
|
|
519
|
-
const
|
|
520
|
-
return Array.isArray(
|
|
531
|
+
if (a === "_selected") {
|
|
532
|
+
const n = e.slice(0, -1), s = n.join("."), c = o.getState().getNestedState(t, n);
|
|
533
|
+
return Array.isArray(c) ? Number(e[e.length - 1]) === p.get(s) : void 0;
|
|
521
534
|
}
|
|
522
|
-
if (
|
|
523
|
-
return (
|
|
524
|
-
|
|
525
|
-
)
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
const
|
|
529
|
-
|
|
530
|
-
const m = a.getState().getNestedState(t, [...n]);
|
|
531
|
-
tt(i, m, n), _(n);
|
|
535
|
+
if (a == "getLocalStorage")
|
|
536
|
+
return (n) => gt(S + "-" + t + "-" + n);
|
|
537
|
+
if (a === "setSelected")
|
|
538
|
+
return (n) => {
|
|
539
|
+
const s = e.slice(0, -1), c = Number(e[e.length - 1]), r = s.join(".");
|
|
540
|
+
n ? p.set(r, c) : p.delete(r);
|
|
541
|
+
const u = o.getState().getNestedState(t, [...s]);
|
|
542
|
+
q(i, u, s), _(s);
|
|
532
543
|
};
|
|
533
|
-
if (
|
|
534
|
-
if (
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
544
|
+
if (e.length == 0) {
|
|
545
|
+
if (a === "validateZodSchema")
|
|
546
|
+
return () => {
|
|
547
|
+
const n = o.getState().getInitialOptions(t)?.validation, s = o.getState().addValidationError;
|
|
548
|
+
if (!n?.zodSchema)
|
|
549
|
+
throw new Error("Zod schema not found");
|
|
550
|
+
if (!n?.key)
|
|
551
|
+
throw new Error("Validation key not found");
|
|
552
|
+
R(n.key);
|
|
553
|
+
const c = o.getState().cogsStateStore[t];
|
|
554
|
+
try {
|
|
555
|
+
const r = o.getState().getValidationErrors(n.key);
|
|
556
|
+
r && r.length > 0 && r.forEach(([w]) => {
|
|
557
|
+
w && w.startsWith(n.key) && R(w);
|
|
558
|
+
});
|
|
559
|
+
const u = n.zodSchema.safeParse(c);
|
|
560
|
+
return u.success ? !0 : (u.error.errors.forEach((M) => {
|
|
561
|
+
const V = M.path, j = M.message, C = [n.key, ...V].join(".");
|
|
562
|
+
s(C, j), console.log(
|
|
563
|
+
`Validation error at ${C}: ${j}`
|
|
564
|
+
);
|
|
565
|
+
}), Mt(t), !1);
|
|
566
|
+
} catch (r) {
|
|
567
|
+
return console.error("Zod schema validation failed", r), !1;
|
|
568
|
+
}
|
|
569
|
+
};
|
|
570
|
+
if (a === "_componentId") return f;
|
|
571
|
+
if (a === "getComponents")
|
|
572
|
+
return () => o().stateComponents.get(t);
|
|
573
|
+
if (a === "getAllFormRefs")
|
|
574
|
+
return () => ct.getState().getFormRefsByStateKey(t);
|
|
575
|
+
if (a === "_initialState")
|
|
576
|
+
return o.getState().initialStateGlobal[t];
|
|
577
|
+
if (a === "_serverState")
|
|
578
|
+
return o.getState().serverState[t];
|
|
579
|
+
if (a === "_isLoading")
|
|
580
|
+
return o.getState().isLoadingGlobal[t];
|
|
581
|
+
if (a === "revertToInitialState")
|
|
582
|
+
return m.revertToInitialState;
|
|
583
|
+
if (a === "updateInitialState") return m.updateInitialState;
|
|
584
|
+
if (a === "removeValidation") return m.removeValidation;
|
|
547
585
|
}
|
|
548
|
-
if (
|
|
586
|
+
if (a === "getFormRef")
|
|
587
|
+
return () => ct.getState().getFormRef(t + "." + e.join("."));
|
|
588
|
+
if (a === "validationWrapper")
|
|
549
589
|
return ({
|
|
550
|
-
children:
|
|
551
|
-
hideMessage:
|
|
552
|
-
}) => /* @__PURE__ */
|
|
553
|
-
|
|
590
|
+
children: n,
|
|
591
|
+
hideMessage: s
|
|
592
|
+
}) => /* @__PURE__ */ at(
|
|
593
|
+
wt,
|
|
554
594
|
{
|
|
555
|
-
formOpts:
|
|
556
|
-
path:
|
|
557
|
-
validationKey:
|
|
595
|
+
formOpts: s ? { validation: { message: "" } } : void 0,
|
|
596
|
+
path: e,
|
|
597
|
+
validationKey: o.getState().getInitialOptions(t)?.validation?.key || "",
|
|
558
598
|
stateKey: t,
|
|
559
599
|
validIndices: v?.validIndices,
|
|
560
|
-
children:
|
|
600
|
+
children: n
|
|
561
601
|
}
|
|
562
602
|
);
|
|
563
|
-
if (
|
|
564
|
-
if (
|
|
565
|
-
if (
|
|
566
|
-
if (
|
|
567
|
-
return (
|
|
568
|
-
|
|
603
|
+
if (a === "_stateKey") return t;
|
|
604
|
+
if (a === "_path") return e;
|
|
605
|
+
if (a === "_isServerSynced") return m._isServerSynced;
|
|
606
|
+
if (a === "update")
|
|
607
|
+
return (n, s) => {
|
|
608
|
+
if (s?.debounce)
|
|
609
|
+
Et(() => {
|
|
610
|
+
q(i, n, e, "");
|
|
611
|
+
const c = o.getState().getNestedState(t, e);
|
|
612
|
+
s?.afterUpdate && s.afterUpdate(c);
|
|
613
|
+
}, s.debounce);
|
|
614
|
+
else {
|
|
615
|
+
q(i, n, e, "");
|
|
616
|
+
const c = o.getState().getNestedState(t, e);
|
|
617
|
+
s?.afterUpdate && s.afterUpdate(c);
|
|
618
|
+
}
|
|
619
|
+
_(e);
|
|
569
620
|
};
|
|
570
|
-
if (
|
|
571
|
-
return (
|
|
572
|
-
|
|
621
|
+
if (a === "formElement")
|
|
622
|
+
return (n, s) => /* @__PURE__ */ at(
|
|
623
|
+
$t,
|
|
573
624
|
{
|
|
574
625
|
setState: i,
|
|
575
|
-
validationKey: e,
|
|
576
626
|
stateKey: t,
|
|
577
|
-
path:
|
|
627
|
+
path: e,
|
|
578
628
|
child: n,
|
|
579
|
-
formOpts:
|
|
629
|
+
formOpts: s
|
|
580
630
|
}
|
|
581
631
|
);
|
|
582
|
-
const
|
|
583
|
-
return
|
|
632
|
+
const b = [...e, a], A = o.getState().getNestedState(t, b);
|
|
633
|
+
return E(A, b, v);
|
|
584
634
|
}
|
|
585
|
-
},
|
|
586
|
-
return
|
|
587
|
-
proxy:
|
|
635
|
+
}, U = new Proxy(m, F);
|
|
636
|
+
return g.set(h, {
|
|
637
|
+
proxy: U,
|
|
588
638
|
stateVersion: I
|
|
589
|
-
}),
|
|
639
|
+
}), U;
|
|
590
640
|
}
|
|
591
|
-
return
|
|
592
|
-
|
|
641
|
+
return E(
|
|
642
|
+
o.getState().getNestedState(t, [])
|
|
593
643
|
);
|
|
594
644
|
}
|
|
595
|
-
function
|
|
596
|
-
return
|
|
645
|
+
function X(t) {
|
|
646
|
+
return H(Ut, { proxy: t });
|
|
597
647
|
}
|
|
598
|
-
function
|
|
599
|
-
proxy: t
|
|
648
|
+
function Ot({
|
|
649
|
+
proxy: t,
|
|
650
|
+
rebuildStateShape: i
|
|
600
651
|
}) {
|
|
601
|
-
const
|
|
602
|
-
return console.log("value",
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
)) : null;
|
|
652
|
+
const f = o().getNestedState(t._stateKey, t._path);
|
|
653
|
+
return console.log("value", f), Array.isArray(f) ? i(
|
|
654
|
+
f,
|
|
655
|
+
t._path
|
|
656
|
+
).stateMapNoRender(
|
|
657
|
+
(g, I, _, p, m) => t._mapFn(g, I, _, p, m)
|
|
658
|
+
) : null;
|
|
609
659
|
}
|
|
610
|
-
function
|
|
660
|
+
function Ut({
|
|
611
661
|
proxy: t
|
|
612
662
|
}) {
|
|
613
|
-
const i =
|
|
614
|
-
return
|
|
615
|
-
const
|
|
616
|
-
if (!
|
|
617
|
-
const
|
|
618
|
-
let
|
|
619
|
-
|
|
620
|
-
const
|
|
663
|
+
const i = z(null), f = `${t._stateKey}-${t._path.join(".")}`;
|
|
664
|
+
return K(() => {
|
|
665
|
+
const S = i.current;
|
|
666
|
+
if (!S || !S.parentElement) return;
|
|
667
|
+
const g = S.parentElement, _ = Array.from(g.childNodes).indexOf(S);
|
|
668
|
+
let p = g.getAttribute("data-parent-id");
|
|
669
|
+
p || (p = `parent-${crypto.randomUUID()}`, g.setAttribute("data-parent-id", p));
|
|
670
|
+
const E = {
|
|
621
671
|
instanceId: `instance-${crypto.randomUUID()}`,
|
|
622
|
-
parentId:
|
|
672
|
+
parentId: p,
|
|
623
673
|
position: _,
|
|
624
674
|
effect: t._effect
|
|
625
675
|
};
|
|
626
|
-
|
|
627
|
-
const
|
|
628
|
-
|
|
629
|
-
|
|
676
|
+
o.getState().addSignalElement(f, E);
|
|
677
|
+
const l = o.getState().getNestedState(t._stateKey, t._path);
|
|
678
|
+
let e;
|
|
679
|
+
if (t._effect)
|
|
680
|
+
try {
|
|
681
|
+
e = new Function(
|
|
682
|
+
"state",
|
|
683
|
+
`return (${t._effect})(state)`
|
|
684
|
+
)(l);
|
|
685
|
+
} catch (h) {
|
|
686
|
+
console.error("Error evaluating effect function during mount:", h), e = l;
|
|
687
|
+
}
|
|
688
|
+
else
|
|
689
|
+
e = l;
|
|
690
|
+
e !== null && typeof e == "object" && (e = JSON.stringify(e));
|
|
691
|
+
const v = document.createTextNode(String(e));
|
|
692
|
+
S.replaceWith(v);
|
|
693
|
+
}, [t._stateKey, t._path.join("."), t._effect]), H("span", {
|
|
630
694
|
ref: i,
|
|
631
695
|
style: { display: "none" },
|
|
632
|
-
"data-signal-id":
|
|
696
|
+
"data-signal-id": f
|
|
633
697
|
});
|
|
634
698
|
}
|
|
635
|
-
function
|
|
636
|
-
const i =
|
|
637
|
-
(
|
|
638
|
-
const
|
|
699
|
+
function Jt(t) {
|
|
700
|
+
const i = pt(
|
|
701
|
+
(f) => {
|
|
702
|
+
const S = o.getState().stateComponents.get(t._stateKey) || {
|
|
639
703
|
components: /* @__PURE__ */ new Map()
|
|
640
704
|
};
|
|
641
|
-
return
|
|
642
|
-
forceUpdate:
|
|
705
|
+
return S.components.set(t._stateKey, {
|
|
706
|
+
forceUpdate: f,
|
|
643
707
|
paths: /* @__PURE__ */ new Set([t._path.join(".")])
|
|
644
|
-
}), () =>
|
|
708
|
+
}), () => S.components.delete(t._stateKey);
|
|
645
709
|
},
|
|
646
|
-
() =>
|
|
710
|
+
() => o.getState().getNestedState(t._stateKey, t._path)
|
|
647
711
|
);
|
|
648
|
-
return
|
|
712
|
+
return H("text", {}, String(i));
|
|
649
713
|
}
|
|
650
714
|
export {
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
715
|
+
X as $cogsSignal,
|
|
716
|
+
Jt as $cogsSignalStore,
|
|
717
|
+
qt as createCogsState,
|
|
718
|
+
zt as notifyComponent,
|
|
719
|
+
jt as useCogsStateFn
|
|
656
720
|
};
|
|
657
721
|
//# sourceMappingURL=CogsState.jsx.map
|