cogsbox-state 0.5.476 → 0.5.479
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +92 -0
- package/dist/CogsState.d.ts +84 -74
- package/dist/CogsState.d.ts.map +1 -1
- package/dist/CogsState.js +920 -844
- package/dist/CogsState.js.map +1 -1
- package/dist/Components.d.ts.map +1 -1
- package/dist/Components.js +110 -108
- package/dist/Components.js.map +1 -1
- package/dist/PluginRunner.d.ts.map +1 -1
- package/dist/PluginRunner.js +0 -1
- package/dist/PluginRunner.js.map +1 -1
- package/dist/index.js +35 -34
- package/dist/plugins.d.ts +93 -294
- package/dist/plugins.d.ts.map +1 -1
- package/dist/plugins.js +191 -60
- package/dist/plugins.js.map +1 -1
- package/dist/store.d.ts +3 -0
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +470 -417
- package/dist/store.js.map +1 -1
- package/dist/utility.d.ts +1 -3
- package/dist/utility.d.ts.map +1 -1
- package/dist/utility.js +63 -73
- package/dist/utility.js.map +1 -1
- package/package.json +3 -3
- package/src/CogsState.tsx +405 -115
- package/src/Components.tsx +3 -1
- package/src/PluginRunner.tsx +3 -3
- package/src/plugins.ts +822 -108
- package/src/store.ts +131 -3
- package/src/utility.ts +1 -33
package/dist/CogsState.js
CHANGED
|
@@ -1,729 +1,806 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as
|
|
3
|
-
import { pluginStore as
|
|
4
|
-
import { useState as
|
|
5
|
-
import { transformStateFunc as
|
|
6
|
-
import { ValidationWrapper as
|
|
7
|
-
import
|
|
8
|
-
import { v4 as
|
|
9
|
-
import { getGlobalStore as
|
|
10
|
-
import { useCogsConfig as
|
|
11
|
-
import { runValidation as
|
|
2
|
+
import { jsx as Q, Fragment as Pe } from "react/jsx-runtime";
|
|
3
|
+
import { pluginStore as R } from "./pluginStore.js";
|
|
4
|
+
import { useState as te, useRef as q, useCallback as Te, useEffect as x, useLayoutEffect as ke, useMemo as pe, createElement as fe, startTransition as Ie } from "react";
|
|
5
|
+
import { transformStateFunc as De, isFunction as z, isDeepEqual as Z, isArray as Ce, getDifferences as _e } from "./utility.js";
|
|
6
|
+
import { ValidationWrapper as Oe, IsolatedComponentWrapper as je, FormElementWrapper as Ne, MemoizedCogsItemWrapper as Ue } from "./Components.js";
|
|
7
|
+
import Fe from "superjson";
|
|
8
|
+
import { v4 as re } from "uuid";
|
|
9
|
+
import { getGlobalStore as p, updateShadowTypeInfo as Se } from "./store.js";
|
|
10
|
+
import { useCogsConfig as Ae } from "./CogsStateClient.js";
|
|
11
|
+
import { runValidation as Re } from "./validation.js";
|
|
12
12
|
const {
|
|
13
|
-
getInitialOptions:
|
|
14
|
-
updateInitialStateGlobal:
|
|
15
|
-
getShadowMetadata:
|
|
16
|
-
setShadowMetadata:
|
|
17
|
-
getShadowValue:
|
|
18
|
-
initializeShadowState:
|
|
19
|
-
initializeAndMergeShadowState:
|
|
20
|
-
updateShadowAtPath:
|
|
21
|
-
insertShadowArrayElement:
|
|
22
|
-
insertManyShadowArrayElements:
|
|
23
|
-
removeShadowArrayElement:
|
|
24
|
-
setInitialStateOptions:
|
|
25
|
-
setServerStateUpdate:
|
|
26
|
-
markAsDirty:
|
|
27
|
-
addPathComponent:
|
|
28
|
-
clearSelectedIndexesForState:
|
|
29
|
-
addStateLog:
|
|
30
|
-
clearSelectedIndex:
|
|
31
|
-
getSyncInfo:
|
|
32
|
-
notifyPathSubscribers:
|
|
33
|
-
getPluginMetaDataMap:
|
|
34
|
-
setPluginMetaData:
|
|
35
|
-
removePluginMetaData:
|
|
36
|
-
} =
|
|
37
|
-
function
|
|
38
|
-
const
|
|
39
|
-
if (!!!
|
|
40
|
-
return { isArray: !1, value:
|
|
41
|
-
const c =
|
|
42
|
-
return Array.isArray(m) && m.length === 0 ? { isArray: !0, value: [], keys: [] } : { isArray: !0, value:
|
|
13
|
+
getInitialOptions: U,
|
|
14
|
+
updateInitialStateGlobal: Me,
|
|
15
|
+
getShadowMetadata: $,
|
|
16
|
+
setShadowMetadata: L,
|
|
17
|
+
getShadowValue: D,
|
|
18
|
+
initializeShadowState: X,
|
|
19
|
+
initializeAndMergeShadowState: ze,
|
|
20
|
+
updateShadowAtPath: Le,
|
|
21
|
+
insertShadowArrayElement: We,
|
|
22
|
+
insertManyShadowArrayElements: be,
|
|
23
|
+
removeShadowArrayElement: Be,
|
|
24
|
+
setInitialStateOptions: ge,
|
|
25
|
+
setServerStateUpdate: ye,
|
|
26
|
+
markAsDirty: oe,
|
|
27
|
+
addPathComponent: Ge,
|
|
28
|
+
clearSelectedIndexesForState: qe,
|
|
29
|
+
addStateLog: xe,
|
|
30
|
+
clearSelectedIndex: Je,
|
|
31
|
+
getSyncInfo: He,
|
|
32
|
+
notifyPathSubscribers: Qe,
|
|
33
|
+
getPluginMetaDataMap: me,
|
|
34
|
+
setPluginMetaData: he,
|
|
35
|
+
removePluginMetaData: ve
|
|
36
|
+
} = p.getState(), { notifyUpdate: Ye } = R.getState();
|
|
37
|
+
function N(e, n, l) {
|
|
38
|
+
const i = $(e, n);
|
|
39
|
+
if (!!!i?.arrayKeys)
|
|
40
|
+
return { isArray: !1, value: p.getState().getShadowValue(e, n), keys: [] };
|
|
41
|
+
const c = n.length > 0 ? n.join(".") : "root", m = l?.arrayViews?.[c] ?? i.arrayKeys;
|
|
42
|
+
return Array.isArray(m) && m.length === 0 ? { isArray: !0, value: [], keys: [] } : { isArray: !0, value: p.getState().getShadowValue(e, n, m), keys: m ?? [] };
|
|
43
43
|
}
|
|
44
|
-
function se(e,
|
|
45
|
-
for (let
|
|
46
|
-
if (l(e[
|
|
47
|
-
const
|
|
48
|
-
if (
|
|
49
|
-
return { key:
|
|
44
|
+
function se(e, n, l) {
|
|
45
|
+
for (let i = 0; i < e.length; i++)
|
|
46
|
+
if (l(e[i], i)) {
|
|
47
|
+
const f = n[i];
|
|
48
|
+
if (f)
|
|
49
|
+
return { key: f, index: i, value: e[i] };
|
|
50
50
|
}
|
|
51
51
|
return null;
|
|
52
52
|
}
|
|
53
|
-
function
|
|
54
|
-
const
|
|
55
|
-
...
|
|
56
|
-
...
|
|
53
|
+
function ce(e, n) {
|
|
54
|
+
const i = {
|
|
55
|
+
...U(e) || {},
|
|
56
|
+
...n
|
|
57
57
|
};
|
|
58
|
-
(
|
|
58
|
+
(i.validation?.zodSchemaV4 || i.validation?.zodSchemaV3) && !i.validation?.onBlur && (i.validation.onBlur = "error"), ge(e, i);
|
|
59
59
|
}
|
|
60
|
-
function
|
|
60
|
+
function ue({
|
|
61
61
|
stateKey: e,
|
|
62
|
-
options:
|
|
62
|
+
options: n,
|
|
63
63
|
initialOptionsPart: l
|
|
64
64
|
}) {
|
|
65
|
-
const
|
|
66
|
-
let c = { ...
|
|
67
|
-
if (
|
|
68
|
-
const
|
|
69
|
-
for (const
|
|
70
|
-
|
|
65
|
+
const i = U(e) || {}, f = l[e] || {};
|
|
66
|
+
let c = { ...f, ...i }, m = !1;
|
|
67
|
+
if (n) {
|
|
68
|
+
const y = (t, a) => {
|
|
69
|
+
for (const d in a)
|
|
70
|
+
a.hasOwnProperty(d) && (a[d] instanceof Object && !Array.isArray(a[d]) && t[d] instanceof Object ? Z(t[d], a[d]) || (y(t[d], a[d]), m = !0) : t[d] !== a[d] && (t[d] = a[d], m = !0));
|
|
71
71
|
return t;
|
|
72
72
|
};
|
|
73
|
-
c =
|
|
73
|
+
c = y(c, n);
|
|
74
74
|
}
|
|
75
|
-
if (c.validation && (
|
|
76
|
-
|
|
77
|
-
const
|
|
78
|
-
!
|
|
75
|
+
if (c.validation && (n?.validation?.hasOwnProperty("onBlur") || i?.validation?.hasOwnProperty("onBlur") || f?.validation?.hasOwnProperty("onBlur") || (c.validation.onBlur = "error", m = !0)), m) {
|
|
76
|
+
ge(e, c);
|
|
77
|
+
const y = i?.validation?.zodSchemaV4 || i?.validation?.zodSchemaV3, t = c.validation?.zodSchemaV4 && !i?.validation?.zodSchemaV4, a = c.validation?.zodSchemaV3 && !i?.validation?.zodSchemaV3;
|
|
78
|
+
!y && (t || a) && (t ? Se(
|
|
79
79
|
e,
|
|
80
80
|
c.validation.zodSchemaV4,
|
|
81
81
|
"zod4"
|
|
82
|
-
) :
|
|
82
|
+
) : a && Se(
|
|
83
83
|
e,
|
|
84
84
|
c.validation.zodSchemaV3,
|
|
85
85
|
"zod3"
|
|
86
|
-
),
|
|
86
|
+
), W(e));
|
|
87
87
|
}
|
|
88
88
|
return c;
|
|
89
89
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
Object.keys(l).forEach((u) => {
|
|
101
|
-
let t = s[u] || {};
|
|
102
|
-
const o = {
|
|
103
|
-
...t
|
|
104
|
-
};
|
|
105
|
-
a?.formElements && (o.formElements = {
|
|
106
|
-
...a.formElements,
|
|
107
|
-
...t.formElements || {}
|
|
108
|
-
}), o.validation = {
|
|
90
|
+
const $t = (e, n) => {
|
|
91
|
+
n?.plugins && R.getState().setRegisteredPlugins(n.plugins);
|
|
92
|
+
const l = {};
|
|
93
|
+
if (n?.plugins)
|
|
94
|
+
for (const a of n.plugins)
|
|
95
|
+
typeof a.initialState == "function" && Object.assign(l, a.initialState());
|
|
96
|
+
const i = { ...l, ...e }, [f, c] = De(i);
|
|
97
|
+
Object.keys(f).forEach((a) => {
|
|
98
|
+
let d = {};
|
|
99
|
+
n?.formElements && (d.formElements = n.formElements), d.validation = {
|
|
109
100
|
onBlur: "error",
|
|
110
|
-
...
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
...o,
|
|
116
|
-
formElements: {
|
|
117
|
-
...y.formElements,
|
|
118
|
-
...o.formElements
|
|
119
|
-
},
|
|
101
|
+
...n?.validation
|
|
102
|
+
};
|
|
103
|
+
const E = U(a), b = E ? {
|
|
104
|
+
...E,
|
|
105
|
+
formElements: n?.formElements,
|
|
120
106
|
validation: {
|
|
121
|
-
...
|
|
122
|
-
...
|
|
107
|
+
...E.validation,
|
|
108
|
+
...d.validation
|
|
123
109
|
}
|
|
124
|
-
} :
|
|
125
|
-
|
|
126
|
-
}), Object.keys(
|
|
127
|
-
|
|
110
|
+
} : d;
|
|
111
|
+
Object.keys(b).length > 0 && ge(a, b);
|
|
112
|
+
}), Object.keys(f).forEach((a) => {
|
|
113
|
+
X(a, f[a]);
|
|
128
114
|
});
|
|
129
|
-
const
|
|
130
|
-
const [
|
|
131
|
-
stateKey:
|
|
132
|
-
options:
|
|
133
|
-
initialOptionsPart:
|
|
134
|
-
}),
|
|
135
|
-
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
)
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}, [u, t]), q(() => (W.getState().stateHandlers.set(u, b), () => {
|
|
154
|
-
W.getState().stateHandlers.delete(u);
|
|
155
|
-
}), [u, b]), b;
|
|
115
|
+
const m = (a, d) => {
|
|
116
|
+
const [E] = te(d?.componentId ?? re()), b = ue({
|
|
117
|
+
stateKey: a,
|
|
118
|
+
options: d,
|
|
119
|
+
initialOptionsPart: c
|
|
120
|
+
}), V = q(b);
|
|
121
|
+
V.current = b;
|
|
122
|
+
const v = D(a, []) || f[a], C = ct(v, {
|
|
123
|
+
stateKey: a,
|
|
124
|
+
syncUpdate: d?.syncUpdate,
|
|
125
|
+
componentId: E,
|
|
126
|
+
localStorage: d?.localStorage,
|
|
127
|
+
middleware: d?.middleware,
|
|
128
|
+
reactiveType: d?.reactiveType,
|
|
129
|
+
reactiveDeps: d?.reactiveDeps,
|
|
130
|
+
defaultState: d?.defaultState,
|
|
131
|
+
dependencies: d?.dependencies,
|
|
132
|
+
serverState: d?.serverState
|
|
133
|
+
});
|
|
134
|
+
return x(() => {
|
|
135
|
+
d && R.getState().setPluginOptionsForState(a, d);
|
|
136
|
+
}, [a, d]), x(() => (R.getState().stateHandlers.set(a, C), () => {
|
|
137
|
+
R.getState().stateHandlers.delete(a);
|
|
138
|
+
}), [a, C]), C;
|
|
156
139
|
};
|
|
157
|
-
function
|
|
158
|
-
if (
|
|
159
|
-
const
|
|
160
|
-
...
|
|
161
|
-
formWrapper:
|
|
162
|
-
} :
|
|
163
|
-
|
|
140
|
+
function y(a, d) {
|
|
141
|
+
if (ue({ stateKey: a, options: d, initialOptionsPart: c }), d.localStorage && Xe(a, d), d.formElements) {
|
|
142
|
+
const b = R.getState().registeredPlugins.map((V) => d.formElements.hasOwnProperty(V.name) ? {
|
|
143
|
+
...V,
|
|
144
|
+
formWrapper: d.formElements[V.name]
|
|
145
|
+
} : V);
|
|
146
|
+
R.getState().setRegisteredPlugins(b);
|
|
164
147
|
}
|
|
165
|
-
|
|
148
|
+
W(a);
|
|
166
149
|
}
|
|
167
|
-
function
|
|
168
|
-
Object.keys(
|
|
169
|
-
|
|
150
|
+
function t(a) {
|
|
151
|
+
Object.keys(f).forEach((E) => {
|
|
152
|
+
y(E, a);
|
|
170
153
|
});
|
|
171
154
|
}
|
|
172
155
|
return {
|
|
173
|
-
useCogsState:
|
|
174
|
-
setCogsOptionsByKey:
|
|
175
|
-
setCogsOptions:
|
|
156
|
+
useCogsState: m,
|
|
157
|
+
setCogsOptionsByKey: y,
|
|
158
|
+
setCogsOptions: t
|
|
176
159
|
};
|
|
177
|
-
},
|
|
160
|
+
}, Ze = (e, n, l, i, f) => {
|
|
178
161
|
l?.log && console.log(
|
|
179
162
|
"saving to localstorage",
|
|
180
|
-
|
|
163
|
+
n,
|
|
181
164
|
l.localStorage?.key,
|
|
182
|
-
|
|
165
|
+
i
|
|
183
166
|
);
|
|
184
|
-
const c =
|
|
185
|
-
if (c &&
|
|
186
|
-
const m = `${
|
|
187
|
-
let
|
|
167
|
+
const c = z(l?.localStorage?.key) ? l.localStorage?.key(e) : l?.localStorage?.key;
|
|
168
|
+
if (c && i) {
|
|
169
|
+
const m = `${i}-${n}-${c}`;
|
|
170
|
+
let y;
|
|
188
171
|
try {
|
|
189
|
-
|
|
172
|
+
y = ie(m)?.lastSyncedWithServer;
|
|
190
173
|
} catch {
|
|
191
174
|
}
|
|
192
|
-
const t =
|
|
175
|
+
const t = $(n, []), a = {
|
|
193
176
|
state: e,
|
|
194
177
|
lastUpdated: Date.now(),
|
|
195
|
-
lastSyncedWithServer:
|
|
178
|
+
lastSyncedWithServer: y,
|
|
196
179
|
stateSource: t?.stateSource,
|
|
197
180
|
baseServerState: t?.baseServerState
|
|
198
|
-
},
|
|
181
|
+
}, d = Fe.serialize(a);
|
|
199
182
|
window.localStorage.setItem(
|
|
200
183
|
m,
|
|
201
|
-
JSON.stringify(
|
|
184
|
+
JSON.stringify(d.json)
|
|
202
185
|
);
|
|
203
186
|
}
|
|
204
|
-
},
|
|
187
|
+
}, ie = (e) => {
|
|
205
188
|
if (!e) return null;
|
|
206
189
|
try {
|
|
207
|
-
const
|
|
208
|
-
return
|
|
209
|
-
} catch (
|
|
210
|
-
return console.error("Error loading from localStorage:",
|
|
190
|
+
const n = window.localStorage.getItem(e);
|
|
191
|
+
return n ? JSON.parse(n) : null;
|
|
192
|
+
} catch (n) {
|
|
193
|
+
return console.error("Error loading from localStorage:", n), null;
|
|
211
194
|
}
|
|
212
|
-
},
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
195
|
+
}, le = (e) => {
|
|
196
|
+
if (e)
|
|
197
|
+
try {
|
|
198
|
+
typeof window < "u" && window.localStorage && window.localStorage.removeItem(e);
|
|
199
|
+
} catch (n) {
|
|
200
|
+
console.error("Error removing from localStorage:", n);
|
|
201
|
+
}
|
|
202
|
+
}, Xe = (e, n) => {
|
|
203
|
+
const l = D(e, []), { sessionId: i } = Ae(), f = z(n?.localStorage?.key) ? n.localStorage.key(l) : n?.localStorage?.key;
|
|
204
|
+
if (f && i) {
|
|
205
|
+
const c = ie(
|
|
206
|
+
`${i}-${e}-${f}`
|
|
217
207
|
);
|
|
218
208
|
if (c && c.lastUpdated > (c.lastSyncedWithServer || 0))
|
|
219
|
-
return
|
|
209
|
+
return W(e), !0;
|
|
220
210
|
}
|
|
221
211
|
return !1;
|
|
222
|
-
},
|
|
223
|
-
const
|
|
224
|
-
if (!
|
|
212
|
+
}, W = (e) => {
|
|
213
|
+
const n = $(e, []);
|
|
214
|
+
if (!n) return;
|
|
225
215
|
const l = /* @__PURE__ */ new Set();
|
|
226
|
-
|
|
227
|
-
(
|
|
216
|
+
n?.components?.forEach((i) => {
|
|
217
|
+
(i ? Array.isArray(i.reactiveType) ? i.reactiveType : [i.reactiveType || "component"] : null)?.includes("none") || l.add(() => i.forceUpdate());
|
|
228
218
|
}), queueMicrotask(() => {
|
|
229
|
-
l.forEach((
|
|
219
|
+
l.forEach((i) => i());
|
|
230
220
|
});
|
|
231
221
|
};
|
|
232
|
-
function
|
|
233
|
-
const
|
|
234
|
-
if (
|
|
235
|
-
...
|
|
222
|
+
function ne(e, n, l, i) {
|
|
223
|
+
const f = $(e, n);
|
|
224
|
+
if (L(e, n, {
|
|
225
|
+
...f,
|
|
236
226
|
isDirty: !1,
|
|
237
227
|
stateSource: "server",
|
|
238
|
-
lastServerSync:
|
|
228
|
+
lastServerSync: i || Date.now()
|
|
239
229
|
}), Array.isArray(l)) {
|
|
240
|
-
const c =
|
|
241
|
-
c?.arrayKeys && c.arrayKeys.forEach((m,
|
|
242
|
-
const t = [...
|
|
243
|
-
|
|
230
|
+
const c = $(e, n);
|
|
231
|
+
c?.arrayKeys && c.arrayKeys.forEach((m, y) => {
|
|
232
|
+
const t = [...n, m], a = l[y];
|
|
233
|
+
a !== void 0 && ne(
|
|
244
234
|
e,
|
|
245
235
|
t,
|
|
246
|
-
|
|
247
|
-
|
|
236
|
+
a,
|
|
237
|
+
i
|
|
248
238
|
);
|
|
249
239
|
});
|
|
250
240
|
} else l && typeof l == "object" && l.constructor === Object && Object.keys(l).forEach((c) => {
|
|
251
|
-
const m = [...
|
|
252
|
-
|
|
241
|
+
const m = [...n, c], y = l[c];
|
|
242
|
+
ne(e, m, y, i);
|
|
253
243
|
});
|
|
254
244
|
}
|
|
255
|
-
let
|
|
256
|
-
function
|
|
257
|
-
|
|
258
|
-
|
|
245
|
+
let ae = [], de = !1;
|
|
246
|
+
function Ke() {
|
|
247
|
+
de || (de = !0, queueMicrotask(() => {
|
|
248
|
+
it();
|
|
259
249
|
}));
|
|
260
250
|
}
|
|
261
|
-
function
|
|
262
|
-
e?.signals?.length && e.signals.forEach(({ parentId: l, position:
|
|
251
|
+
function et(e, n) {
|
|
252
|
+
e?.signals?.length && e.signals.forEach(({ parentId: l, position: i, effect: f }) => {
|
|
263
253
|
const c = document.querySelector(`[data-parent-id="${l}"]`);
|
|
264
254
|
if (!c) return;
|
|
265
255
|
const m = Array.from(c.childNodes);
|
|
266
|
-
if (!m[
|
|
267
|
-
let
|
|
268
|
-
if (
|
|
256
|
+
if (!m[i]) return;
|
|
257
|
+
let y = n;
|
|
258
|
+
if (f && n !== null)
|
|
269
259
|
try {
|
|
270
|
-
|
|
271
|
-
|
|
260
|
+
y = new Function("state", `return (${f})(state)`)(
|
|
261
|
+
n
|
|
272
262
|
);
|
|
273
263
|
} catch (t) {
|
|
274
264
|
console.error("Error evaluating effect function:", t);
|
|
275
265
|
}
|
|
276
|
-
|
|
266
|
+
y !== null && typeof y == "object" && (y = JSON.stringify(y)), m[i].textContent = String(y ?? "");
|
|
277
267
|
});
|
|
278
268
|
}
|
|
279
|
-
function
|
|
280
|
-
const
|
|
281
|
-
if (!
|
|
269
|
+
function tt(e, n, l) {
|
|
270
|
+
const i = $(e, []);
|
|
271
|
+
if (!i?.components)
|
|
282
272
|
return /* @__PURE__ */ new Set();
|
|
283
|
-
const
|
|
273
|
+
const f = /* @__PURE__ */ new Set();
|
|
284
274
|
if (l.type === "update") {
|
|
285
|
-
let c = [...
|
|
275
|
+
let c = [...n];
|
|
286
276
|
for (; ; ) {
|
|
287
|
-
const m =
|
|
288
|
-
if (m?.pathComponents && m.pathComponents.forEach((
|
|
289
|
-
const t =
|
|
290
|
-
t && ((Array.isArray(t.reactiveType) ? t.reactiveType : [t.reactiveType || "component"]).includes("none") ||
|
|
277
|
+
const m = $(e, c);
|
|
278
|
+
if (m?.pathComponents && m.pathComponents.forEach((y) => {
|
|
279
|
+
const t = i.components?.get(y);
|
|
280
|
+
t && ((Array.isArray(t.reactiveType) ? t.reactiveType : [t.reactiveType || "component"]).includes("none") || f.add(t));
|
|
291
281
|
}), c.length === 0) break;
|
|
292
282
|
c.pop();
|
|
293
283
|
}
|
|
294
|
-
l.newValue && typeof l.newValue == "object" && !
|
|
295
|
-
const t =
|
|
296
|
-
|
|
297
|
-
const
|
|
298
|
-
|
|
284
|
+
l.newValue && typeof l.newValue == "object" && !Ce(l.newValue) && _e(l.newValue, l.oldValue).forEach((y) => {
|
|
285
|
+
const t = y.split("."), a = [...n, ...t], d = $(e, a);
|
|
286
|
+
d?.pathComponents && d.pathComponents.forEach((E) => {
|
|
287
|
+
const b = i.components?.get(E);
|
|
288
|
+
b && ((Array.isArray(b.reactiveType) ? b.reactiveType : [b.reactiveType || "component"]).includes("none") || f.add(b));
|
|
299
289
|
});
|
|
300
290
|
});
|
|
301
291
|
} else if (l.type === "insert" || l.type === "cut" || l.type === "insert_many") {
|
|
302
|
-
let m = [...l.type === "insert" ?
|
|
292
|
+
let m = [...l.type === "insert" ? n : n.slice(0, -1)];
|
|
303
293
|
for (; ; ) {
|
|
304
|
-
const
|
|
305
|
-
if (
|
|
306
|
-
const
|
|
307
|
-
|
|
294
|
+
const y = $(e, m);
|
|
295
|
+
if (y?.pathComponents && y.pathComponents.forEach((t) => {
|
|
296
|
+
const a = i.components?.get(t);
|
|
297
|
+
a && f.add(a);
|
|
308
298
|
}), m.length === 0) break;
|
|
309
299
|
m.pop();
|
|
310
300
|
}
|
|
311
301
|
}
|
|
312
|
-
return
|
|
302
|
+
return f;
|
|
313
303
|
}
|
|
314
|
-
function
|
|
315
|
-
const
|
|
316
|
-
if (
|
|
304
|
+
function rt(e, n, l) {
|
|
305
|
+
const i = p.getState().getShadowValue(e, n), f = z(l) ? l(i) : l;
|
|
306
|
+
if (Z(i, f))
|
|
317
307
|
return null;
|
|
318
|
-
|
|
319
|
-
const c =
|
|
308
|
+
Le(e, n, f), oe(e, n, { bubble: !0 });
|
|
309
|
+
const c = $(e, n);
|
|
320
310
|
return {
|
|
321
311
|
type: "update",
|
|
322
|
-
oldValue:
|
|
323
|
-
newValue:
|
|
312
|
+
oldValue: i,
|
|
313
|
+
newValue: f,
|
|
324
314
|
shadowMeta: c
|
|
325
315
|
};
|
|
326
316
|
}
|
|
327
|
-
function
|
|
328
|
-
|
|
329
|
-
const
|
|
317
|
+
function nt(e, n, l) {
|
|
318
|
+
be(e, n, l), oe(e, n, { bubble: !0 });
|
|
319
|
+
const i = $(e, n);
|
|
330
320
|
return {
|
|
331
321
|
type: "insert_many",
|
|
332
322
|
count: l.length,
|
|
333
|
-
shadowMeta:
|
|
334
|
-
path:
|
|
323
|
+
shadowMeta: i,
|
|
324
|
+
path: n
|
|
335
325
|
};
|
|
336
326
|
}
|
|
337
|
-
function
|
|
327
|
+
function at(e, n, l, i, f) {
|
|
338
328
|
let c;
|
|
339
|
-
if (
|
|
340
|
-
const { value:
|
|
341
|
-
c = l({ state:
|
|
329
|
+
if (z(l)) {
|
|
330
|
+
const { value: a } = j(e, n);
|
|
331
|
+
c = l({ state: a });
|
|
342
332
|
} else
|
|
343
333
|
c = l;
|
|
344
|
-
const m =
|
|
334
|
+
const m = We(
|
|
345
335
|
e,
|
|
346
|
-
|
|
336
|
+
n,
|
|
347
337
|
c,
|
|
348
|
-
|
|
349
|
-
|
|
338
|
+
i,
|
|
339
|
+
f
|
|
350
340
|
);
|
|
351
|
-
|
|
352
|
-
const
|
|
341
|
+
oe(e, n, { bubble: !0 });
|
|
342
|
+
const y = $(e, n);
|
|
353
343
|
let t;
|
|
354
|
-
return
|
|
344
|
+
return y?.arrayKeys && i !== void 0 && i > 0 && (t = y.arrayKeys[i - 1]), {
|
|
355
345
|
type: "insert",
|
|
356
346
|
newValue: c,
|
|
357
|
-
shadowMeta:
|
|
358
|
-
path:
|
|
347
|
+
shadowMeta: y,
|
|
348
|
+
path: n,
|
|
359
349
|
itemId: m,
|
|
360
350
|
insertAfterId: t
|
|
361
351
|
};
|
|
362
352
|
}
|
|
363
|
-
function
|
|
364
|
-
const l =
|
|
365
|
-
return
|
|
353
|
+
function ot(e, n) {
|
|
354
|
+
const l = n.slice(0, -1), i = D(e, n);
|
|
355
|
+
return Be(e, n), oe(e, l, { bubble: !0 }), { type: "cut", oldValue: i, parentPath: l };
|
|
366
356
|
}
|
|
367
|
-
function
|
|
368
|
-
const e = /* @__PURE__ */ new Set(),
|
|
369
|
-
for (const
|
|
370
|
-
if (
|
|
371
|
-
l.push(
|
|
357
|
+
function it() {
|
|
358
|
+
const e = /* @__PURE__ */ new Set(), n = [], l = [];
|
|
359
|
+
for (const i of ae) {
|
|
360
|
+
if (i.status && i.updateType) {
|
|
361
|
+
l.push(i);
|
|
372
362
|
continue;
|
|
373
363
|
}
|
|
374
|
-
const
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
).forEach((
|
|
380
|
-
e.add(
|
|
364
|
+
const f = i, c = f.type === "cut" ? null : f.newValue;
|
|
365
|
+
f.shadowMeta?.signals?.length > 0 && n.push({ shadowMeta: f.shadowMeta, displayValue: c }), tt(
|
|
366
|
+
f.stateKey,
|
|
367
|
+
f.path,
|
|
368
|
+
f
|
|
369
|
+
).forEach((y) => {
|
|
370
|
+
e.add(y);
|
|
381
371
|
});
|
|
382
372
|
}
|
|
383
|
-
l.length > 0 &&
|
|
384
|
-
|
|
385
|
-
}), e.forEach((
|
|
386
|
-
|
|
387
|
-
}),
|
|
373
|
+
l.length > 0 && xe(l), n.forEach(({ shadowMeta: i, displayValue: f }) => {
|
|
374
|
+
et(i, f);
|
|
375
|
+
}), e.forEach((i) => {
|
|
376
|
+
i.forceUpdate();
|
|
377
|
+
}), ae = [], de = !1;
|
|
388
378
|
}
|
|
389
|
-
function
|
|
390
|
-
return (
|
|
391
|
-
|
|
379
|
+
function st(e, n, l) {
|
|
380
|
+
return (f, c, m) => {
|
|
381
|
+
i(e, c, f, m);
|
|
392
382
|
};
|
|
393
|
-
function
|
|
383
|
+
function i(f, c, m, y) {
|
|
394
384
|
let t;
|
|
395
|
-
switch (
|
|
385
|
+
switch (y.updateType) {
|
|
396
386
|
case "update":
|
|
397
|
-
t =
|
|
387
|
+
t = rt(f, c, m);
|
|
398
388
|
break;
|
|
399
389
|
case "insert":
|
|
400
|
-
t =
|
|
401
|
-
|
|
390
|
+
t = at(
|
|
391
|
+
f,
|
|
402
392
|
c,
|
|
403
393
|
m,
|
|
404
|
-
|
|
405
|
-
|
|
394
|
+
y.index,
|
|
395
|
+
y.itemId
|
|
406
396
|
);
|
|
407
397
|
break;
|
|
408
398
|
case "insert_many":
|
|
409
|
-
t =
|
|
399
|
+
t = nt(f, c, m);
|
|
410
400
|
break;
|
|
411
401
|
case "cut":
|
|
412
|
-
t =
|
|
402
|
+
t = ot(f, c);
|
|
413
403
|
break;
|
|
414
404
|
}
|
|
415
405
|
if (t === null)
|
|
416
406
|
return;
|
|
417
|
-
t.stateKey =
|
|
418
|
-
const
|
|
407
|
+
t.stateKey = f, t.path = c, ae.push(t), Ke();
|
|
408
|
+
const a = {
|
|
419
409
|
timeStamp: Date.now(),
|
|
420
|
-
stateKey:
|
|
410
|
+
stateKey: f,
|
|
421
411
|
path: c,
|
|
422
|
-
updateType:
|
|
412
|
+
updateType: y.updateType,
|
|
423
413
|
status: "new",
|
|
424
414
|
oldValue: t.oldValue,
|
|
425
415
|
newValue: t.newValue ?? null,
|
|
426
416
|
itemId: t.itemId,
|
|
427
417
|
insertAfterId: t.insertAfterId,
|
|
428
|
-
metaData:
|
|
418
|
+
metaData: y.metaData
|
|
429
419
|
};
|
|
430
|
-
|
|
420
|
+
ae.push(a), t.newValue !== void 0 && Ze(
|
|
431
421
|
t.newValue,
|
|
432
|
-
|
|
422
|
+
f,
|
|
433
423
|
l.current,
|
|
434
|
-
|
|
435
|
-
), l.current?.middleware && l.current.middleware({ update:
|
|
424
|
+
n
|
|
425
|
+
), l.current?.middleware && l.current.middleware({ update: a }), Re(a, y.validationTrigger || "programmatic"), Ye(a);
|
|
436
426
|
}
|
|
437
427
|
}
|
|
438
|
-
function
|
|
439
|
-
stateKey:
|
|
428
|
+
function ct(e, {
|
|
429
|
+
stateKey: n,
|
|
440
430
|
localStorage: l,
|
|
441
|
-
formElements:
|
|
442
|
-
reactiveDeps:
|
|
431
|
+
formElements: i,
|
|
432
|
+
reactiveDeps: f,
|
|
443
433
|
reactiveType: c,
|
|
444
434
|
componentId: m,
|
|
445
|
-
defaultState:
|
|
435
|
+
defaultState: y,
|
|
446
436
|
dependencies: t,
|
|
447
|
-
serverState:
|
|
437
|
+
serverState: a
|
|
448
438
|
} = {}) {
|
|
449
|
-
const [
|
|
450
|
-
let
|
|
451
|
-
const [v] =
|
|
439
|
+
const [d, E] = te({}), { sessionId: b } = Ae();
|
|
440
|
+
let V = !n;
|
|
441
|
+
const [v] = te(n ?? re()), C = q(m ?? re()), _ = q(
|
|
452
442
|
null
|
|
453
443
|
);
|
|
454
|
-
|
|
455
|
-
const
|
|
456
|
-
(
|
|
457
|
-
const
|
|
458
|
-
if (
|
|
444
|
+
_.current = U(v) ?? null;
|
|
445
|
+
const J = Te(
|
|
446
|
+
(T) => {
|
|
447
|
+
const r = T ? { ...U(v), ...T } : U(v), o = r?.defaultState || y || e;
|
|
448
|
+
if (r?.serverState?.status === "success" && r?.serverState?.data !== void 0)
|
|
459
449
|
return {
|
|
460
|
-
value:
|
|
450
|
+
value: r.serverState.data,
|
|
461
451
|
source: "server",
|
|
462
|
-
timestamp:
|
|
452
|
+
timestamp: r.serverState.timestamp || Date.now()
|
|
463
453
|
};
|
|
464
|
-
if (
|
|
465
|
-
const
|
|
466
|
-
`${
|
|
454
|
+
if (r?.localStorage?.key && b) {
|
|
455
|
+
const S = z(r.localStorage.key) ? r.localStorage.key(o) : r.localStorage.key, u = ie(
|
|
456
|
+
`${b}-${v}-${S}`
|
|
467
457
|
);
|
|
468
|
-
if (
|
|
458
|
+
if (u && u.lastUpdated > (r?.serverState?.timestamp || 0))
|
|
469
459
|
return {
|
|
470
|
-
value:
|
|
460
|
+
value: u.state,
|
|
471
461
|
source: "localStorage",
|
|
472
|
-
timestamp:
|
|
462
|
+
timestamp: u.lastUpdated
|
|
473
463
|
};
|
|
474
464
|
}
|
|
475
465
|
return {
|
|
476
|
-
value:
|
|
466
|
+
value: o || e,
|
|
477
467
|
source: "default",
|
|
478
468
|
timestamp: Date.now()
|
|
479
469
|
};
|
|
480
470
|
},
|
|
481
|
-
[v,
|
|
471
|
+
[v, y, e, b]
|
|
482
472
|
);
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
}, [
|
|
486
|
-
if (
|
|
487
|
-
const
|
|
488
|
-
if (
|
|
473
|
+
x(() => {
|
|
474
|
+
a && a.status === "success" && a.data !== void 0 && ye(v, a);
|
|
475
|
+
}, [a, v]), x(() => p.getState().subscribeToPath(v, (k) => {
|
|
476
|
+
if (k?.type === "SERVER_STATE_UPDATE") {
|
|
477
|
+
const r = k.serverState;
|
|
478
|
+
if (r?.status !== "success" || r.data === void 0)
|
|
489
479
|
return;
|
|
490
|
-
|
|
491
|
-
const
|
|
492
|
-
if (
|
|
493
|
-
const
|
|
494
|
-
if (!
|
|
480
|
+
ce(v, { serverState: r });
|
|
481
|
+
const o = typeof r.merge == "object" ? r.merge : r.merge === !0 ? { strategy: "append", key: "id" } : null, s = D(v, []), S = r.data;
|
|
482
|
+
if (o && o.strategy === "append" && "key" in o && Array.isArray(s) && Array.isArray(S)) {
|
|
483
|
+
const u = o.key;
|
|
484
|
+
if (!u) {
|
|
495
485
|
console.error(
|
|
496
486
|
"CogsState: Merge strategy 'append' requires a 'key' field."
|
|
497
487
|
);
|
|
498
488
|
return;
|
|
499
489
|
}
|
|
500
|
-
const
|
|
501
|
-
|
|
502
|
-
),
|
|
503
|
-
(
|
|
490
|
+
const h = new Set(
|
|
491
|
+
s.map((M) => M[u])
|
|
492
|
+
), w = S.filter(
|
|
493
|
+
(M) => !h.has(M[u])
|
|
504
494
|
);
|
|
505
|
-
|
|
506
|
-
const
|
|
507
|
-
|
|
495
|
+
w.length > 0 && be(v, [], w);
|
|
496
|
+
const A = D(v, []);
|
|
497
|
+
ne(
|
|
508
498
|
v,
|
|
509
499
|
[],
|
|
510
|
-
|
|
511
|
-
|
|
500
|
+
A,
|
|
501
|
+
r.timestamp || Date.now()
|
|
512
502
|
);
|
|
513
503
|
} else
|
|
514
|
-
|
|
504
|
+
X(v, S), ne(
|
|
515
505
|
v,
|
|
516
506
|
[],
|
|
517
|
-
|
|
518
|
-
|
|
507
|
+
S,
|
|
508
|
+
r.timestamp || Date.now()
|
|
519
509
|
);
|
|
520
|
-
|
|
510
|
+
W(v);
|
|
521
511
|
}
|
|
522
|
-
}), [v]),
|
|
523
|
-
const
|
|
524
|
-
if (
|
|
512
|
+
}), [v]), x(() => {
|
|
513
|
+
const T = p.getState().getShadowMetadata(v, []);
|
|
514
|
+
if (T && T.stateSource)
|
|
525
515
|
return;
|
|
526
|
-
const
|
|
527
|
-
localStorageEnabled: !!
|
|
516
|
+
const k = U(v), r = {
|
|
517
|
+
localStorageEnabled: !!k?.localStorage?.key
|
|
528
518
|
};
|
|
529
|
-
if (
|
|
530
|
-
...
|
|
531
|
-
features:
|
|
532
|
-
}),
|
|
533
|
-
const
|
|
534
|
-
|
|
535
|
-
defaultState:
|
|
519
|
+
if (L(v, [], {
|
|
520
|
+
...T,
|
|
521
|
+
features: r
|
|
522
|
+
}), k?.defaultState !== void 0 || y !== void 0) {
|
|
523
|
+
const u = k?.defaultState || y;
|
|
524
|
+
k?.defaultState || ce(v, {
|
|
525
|
+
defaultState: u
|
|
536
526
|
});
|
|
537
527
|
}
|
|
538
|
-
const { value:
|
|
539
|
-
|
|
540
|
-
stateSource:
|
|
541
|
-
lastServerSync:
|
|
542
|
-
isDirty:
|
|
543
|
-
baseServerState:
|
|
544
|
-
}),
|
|
545
|
-
}, [v, ...t || []]),
|
|
546
|
-
|
|
547
|
-
formElements:
|
|
548
|
-
defaultState:
|
|
528
|
+
const { value: o, source: s, timestamp: S } = J();
|
|
529
|
+
X(v, o), L(v, [], {
|
|
530
|
+
stateSource: s,
|
|
531
|
+
lastServerSync: s === "server" ? S : void 0,
|
|
532
|
+
isDirty: s === "server" ? !1 : void 0,
|
|
533
|
+
baseServerState: s === "server" ? o : void 0
|
|
534
|
+
}), s === "server" && a && ye(v, a), W(v);
|
|
535
|
+
}, [v, ...t || []]), ke(() => {
|
|
536
|
+
V && ce(v, {
|
|
537
|
+
formElements: i,
|
|
538
|
+
defaultState: y,
|
|
549
539
|
localStorage: l,
|
|
550
|
-
middleware:
|
|
540
|
+
middleware: _.current?.middleware
|
|
551
541
|
});
|
|
552
|
-
const
|
|
553
|
-
return
|
|
554
|
-
forceUpdate: () =>
|
|
542
|
+
const T = `${v}////${C.current}`, k = $(v, []), r = k?.components || /* @__PURE__ */ new Map();
|
|
543
|
+
return r.set(T, {
|
|
544
|
+
forceUpdate: () => E({}),
|
|
555
545
|
reactiveType: c ?? ["component"],
|
|
556
546
|
paths: /* @__PURE__ */ new Set(),
|
|
557
|
-
depsFunction:
|
|
558
|
-
deps:
|
|
559
|
-
prevDeps:
|
|
560
|
-
}),
|
|
561
|
-
...
|
|
562
|
-
components:
|
|
563
|
-
}),
|
|
564
|
-
const
|
|
565
|
-
|
|
566
|
-
const
|
|
567
|
-
|
|
568
|
-
}),
|
|
547
|
+
depsFunction: f || void 0,
|
|
548
|
+
deps: f ? f(D(v, [])) : [],
|
|
549
|
+
prevDeps: f ? f(D(v, [])) : []
|
|
550
|
+
}), L(v, [], {
|
|
551
|
+
...k,
|
|
552
|
+
components: r
|
|
553
|
+
}), E({}), () => {
|
|
554
|
+
const o = $(v, []), s = o?.components?.get(T);
|
|
555
|
+
s?.paths && s.paths.forEach((S) => {
|
|
556
|
+
const h = S.split(".").slice(1), w = p.getState().getShadowMetadata(v, h);
|
|
557
|
+
w?.pathComponents && w.pathComponents.size === 0 && (delete w.pathComponents, p.getState().setShadowMetadata(v, h, w));
|
|
558
|
+
}), o?.components && L(v, [], o);
|
|
569
559
|
};
|
|
570
560
|
}, []);
|
|
571
|
-
const
|
|
561
|
+
const G = st(
|
|
572
562
|
v,
|
|
573
|
-
|
|
574
|
-
|
|
563
|
+
b,
|
|
564
|
+
_
|
|
575
565
|
);
|
|
576
|
-
return
|
|
566
|
+
return p.getState().initialStateGlobal[v] || Me(v, e), pe(() => Ve(
|
|
577
567
|
v,
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
), [v,
|
|
568
|
+
G,
|
|
569
|
+
C.current,
|
|
570
|
+
b
|
|
571
|
+
), [v, b]);
|
|
582
572
|
}
|
|
583
|
-
const
|
|
584
|
-
let
|
|
585
|
-
const
|
|
586
|
-
if (!
|
|
587
|
-
return
|
|
588
|
-
for (const c of
|
|
573
|
+
const lt = (e, n, l) => {
|
|
574
|
+
let i = $(e, n)?.arrayKeys || [];
|
|
575
|
+
const f = l?.transforms;
|
|
576
|
+
if (!f || f.length === 0)
|
|
577
|
+
return i;
|
|
578
|
+
for (const c of f)
|
|
589
579
|
if (c.type === "filter") {
|
|
590
580
|
const m = [];
|
|
591
|
-
|
|
592
|
-
const
|
|
593
|
-
c.fn(
|
|
594
|
-
}),
|
|
595
|
-
} else c.type === "sort" &&
|
|
596
|
-
const t =
|
|
597
|
-
return c.fn(t,
|
|
581
|
+
i.forEach((y, t) => {
|
|
582
|
+
const a = D(e, [...n, y]);
|
|
583
|
+
c.fn(a, t) && m.push(y);
|
|
584
|
+
}), i = m;
|
|
585
|
+
} else c.type === "sort" && i.sort((m, y) => {
|
|
586
|
+
const t = D(e, [...n, m]), a = D(e, [...n, y]);
|
|
587
|
+
return c.fn(t, a);
|
|
598
588
|
});
|
|
599
|
-
return
|
|
600
|
-
},
|
|
601
|
-
const
|
|
602
|
-
!c || c.reactiveType === "none" || !(Array.isArray(c.reactiveType) ? c.reactiveType : [c.reactiveType]).includes("component") ||
|
|
603
|
-
},
|
|
604
|
-
const
|
|
605
|
-
|
|
606
|
-
(Array.isArray(m.reactiveType) ? m.reactiveType : [m.reactiveType || "component"]).includes("all") && (m.forceUpdate(),
|
|
607
|
-
}),
|
|
608
|
-
...
|
|
589
|
+
return i;
|
|
590
|
+
}, ee = (e, n, l) => {
|
|
591
|
+
const i = `${e}////${n}`, c = $(e, [])?.components?.get(i);
|
|
592
|
+
!c || c.reactiveType === "none" || !(Array.isArray(c.reactiveType) ? c.reactiveType : [c.reactiveType]).includes("component") || Ge(e, l, i);
|
|
593
|
+
}, Y = (e, n, l) => {
|
|
594
|
+
const i = $(e, []), f = /* @__PURE__ */ new Set();
|
|
595
|
+
i?.components && i.components.forEach((m, y) => {
|
|
596
|
+
(Array.isArray(m.reactiveType) ? m.reactiveType : [m.reactiveType || "component"]).includes("all") && (m.forceUpdate(), f.add(y));
|
|
597
|
+
}), $(e, [
|
|
598
|
+
...n,
|
|
609
599
|
"getSelected"
|
|
610
600
|
])?.pathComponents?.forEach((m) => {
|
|
611
|
-
|
|
601
|
+
i?.components?.get(m)?.forceUpdate();
|
|
612
602
|
});
|
|
613
|
-
const c =
|
|
603
|
+
const c = $(e, n);
|
|
614
604
|
for (let m of c?.arrayKeys || []) {
|
|
615
|
-
const
|
|
616
|
-
m == l && t?.pathComponents?.forEach((
|
|
617
|
-
|
|
605
|
+
const y = m + ".selected", t = $(e, y.split(".").slice(1));
|
|
606
|
+
m == l && t?.pathComponents?.forEach((a) => {
|
|
607
|
+
i?.components?.get(a)?.forceUpdate();
|
|
618
608
|
});
|
|
619
609
|
}
|
|
620
610
|
};
|
|
621
|
-
function
|
|
622
|
-
const
|
|
611
|
+
function j(e, n, l) {
|
|
612
|
+
const i = $(e, n), f = n.length > 0 ? n.join(".") : "root", c = l?.arrayViews?.[f];
|
|
623
613
|
if (Array.isArray(c) && c.length === 0)
|
|
624
614
|
return {
|
|
625
|
-
shadowMeta:
|
|
615
|
+
shadowMeta: i,
|
|
626
616
|
value: [],
|
|
627
|
-
arrayKeys:
|
|
617
|
+
arrayKeys: i?.arrayKeys
|
|
628
618
|
};
|
|
629
|
-
const m =
|
|
619
|
+
const m = D(e, n, c);
|
|
630
620
|
return {
|
|
631
|
-
shadowMeta:
|
|
621
|
+
shadowMeta: i,
|
|
632
622
|
value: m,
|
|
633
|
-
arrayKeys:
|
|
623
|
+
arrayKeys: i?.arrayKeys
|
|
634
624
|
};
|
|
635
625
|
}
|
|
636
|
-
function
|
|
637
|
-
|
|
626
|
+
function ut(e, n) {
|
|
627
|
+
return n ? e.length !== n.length ? !1 : n.every((l, i) => l === "*" || l === e[i]) : !0;
|
|
628
|
+
}
|
|
629
|
+
function dt(e, n) {
|
|
630
|
+
return n === "any" ? !0 : n === "array" ? Array.isArray(e) : n === "boolean" ? typeof e == "boolean" : n === "object" ? e !== null && typeof e == "object" && !Array.isArray(e) : n === "primitive" ? e === null || typeof e != "object" && !Array.isArray(e) : !1;
|
|
631
|
+
}
|
|
632
|
+
function $e(e, n) {
|
|
633
|
+
const l = p.getState().getShadowMetadata(e, n);
|
|
634
|
+
if (!l?.clientActivityState?.elements) return [];
|
|
635
|
+
const i = [];
|
|
636
|
+
return l.clientActivityState.elements.forEach((f) => {
|
|
637
|
+
f.domRef?.current && i.push(f.domRef);
|
|
638
|
+
}), i;
|
|
639
|
+
}
|
|
640
|
+
function Ee(e, n) {
|
|
641
|
+
return $e(e, n).map((i) => i.current).filter(Boolean);
|
|
642
|
+
}
|
|
643
|
+
function ft(e, n, l) {
|
|
644
|
+
Ee(e, n).forEach((i) => {
|
|
645
|
+
if ("disabled" in i) {
|
|
646
|
+
i.disabled = l;
|
|
647
|
+
return;
|
|
648
|
+
}
|
|
649
|
+
i.style.pointerEvents = l ? "none" : "", i.setAttribute("aria-disabled", String(l));
|
|
650
|
+
});
|
|
651
|
+
}
|
|
652
|
+
function Ve(e, n, l, i) {
|
|
653
|
+
const f = /* @__PURE__ */ new Map();
|
|
638
654
|
function c({
|
|
639
655
|
path: t = [],
|
|
640
|
-
meta:
|
|
641
|
-
componentId:
|
|
656
|
+
meta: a,
|
|
657
|
+
componentId: d
|
|
642
658
|
}) {
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
659
|
+
if ($(e, t)?.isRaw)
|
|
660
|
+
return D(e, t);
|
|
661
|
+
const b = a ? JSON.stringify(a.arrayViews || a.transforms) : "", V = t.join(".") + ":" + d + ":" + b;
|
|
662
|
+
if (f.has(V))
|
|
663
|
+
return f.get(V);
|
|
664
|
+
const v = [e, ...t].join("."), C = () => {
|
|
647
665
|
}, _ = {
|
|
648
|
-
apply(
|
|
649
|
-
if (
|
|
650
|
-
const r = t.length > 0 ? t.join(".") : "root",
|
|
651
|
-
return
|
|
666
|
+
apply(G, g, T) {
|
|
667
|
+
if (T.length === 0) {
|
|
668
|
+
const r = t.length > 0 ? t.join(".") : "root", o = a?.arrayViews?.[r];
|
|
669
|
+
return ee(e, d, t), D(e, t, o);
|
|
652
670
|
}
|
|
653
|
-
const
|
|
654
|
-
return
|
|
671
|
+
const k = T[0];
|
|
672
|
+
return n(k, t, { updateType: "update" }), !0;
|
|
655
673
|
},
|
|
656
|
-
get(
|
|
657
|
-
if (
|
|
674
|
+
get(G, g, T) {
|
|
675
|
+
if (g === Symbol.toPrimitive)
|
|
658
676
|
return (r) => r === "number" ? NaN : r === "string" ? `[CogsState: ${t.join(".") || "root"}]` : null;
|
|
659
|
-
if (
|
|
677
|
+
if (g === Symbol.toStringTag)
|
|
660
678
|
return "CogsState";
|
|
661
|
-
if (
|
|
662
|
-
const { value: r } =
|
|
679
|
+
if (g === Symbol.iterator) {
|
|
680
|
+
const { value: r } = j(e, t, a);
|
|
663
681
|
return Array.isArray(r) ? function* () {
|
|
664
|
-
for (let
|
|
665
|
-
yield r[
|
|
682
|
+
for (let o = 0; o < r.length; o++)
|
|
683
|
+
yield r[o];
|
|
666
684
|
} : void 0;
|
|
667
685
|
}
|
|
668
|
-
if (
|
|
669
|
-
return Reflect.get(
|
|
670
|
-
if (typeof
|
|
671
|
-
return Reflect.get(
|
|
672
|
-
if (t.length === 0 &&
|
|
673
|
-
return m[
|
|
674
|
-
if (typeof
|
|
675
|
-
const r =
|
|
686
|
+
if (g === "call" || g === "apply" || g === "bind")
|
|
687
|
+
return Reflect.get(G, g, T);
|
|
688
|
+
if (typeof g != "string")
|
|
689
|
+
return Reflect.get(G, g);
|
|
690
|
+
if (t.length === 0 && g in m)
|
|
691
|
+
return m[g];
|
|
692
|
+
if (typeof g == "string" && !g.startsWith("$")) {
|
|
693
|
+
const { value: r } = j(e, t, a);
|
|
694
|
+
if (r !== null && typeof r == "object" && !Array.isArray(r) && Object.prototype.hasOwnProperty.call(r, g)) {
|
|
695
|
+
const u = [...t, g];
|
|
696
|
+
return c({
|
|
697
|
+
path: u,
|
|
698
|
+
componentId: d,
|
|
699
|
+
meta: a
|
|
700
|
+
});
|
|
701
|
+
}
|
|
702
|
+
const s = R.getState().registeredPlugins;
|
|
703
|
+
for (const u of s) {
|
|
704
|
+
const h = u.chainMethods?.[g];
|
|
705
|
+
if (h && ut(t, h.pathPattern) && dt(r, h.target))
|
|
706
|
+
return (...w) => {
|
|
707
|
+
const A = R.getState(), M = A.pluginOptions.get(e)?.get(u.name), I = A.getHookResult(e, u.name);
|
|
708
|
+
return h.handler(
|
|
709
|
+
{
|
|
710
|
+
stateKey: e,
|
|
711
|
+
path: t,
|
|
712
|
+
pluginName: u.name,
|
|
713
|
+
options: M,
|
|
714
|
+
hookData: I,
|
|
715
|
+
$get: () => j(e, t, a).value,
|
|
716
|
+
$update: (P) => (n(P, t, {
|
|
717
|
+
updateType: "update"
|
|
718
|
+
}), {
|
|
719
|
+
synced: () => {
|
|
720
|
+
const O = p.getState().getShadowMetadata(e, t);
|
|
721
|
+
L(e, t, {
|
|
722
|
+
...O,
|
|
723
|
+
isDirty: !1,
|
|
724
|
+
stateSource: "server",
|
|
725
|
+
lastServerSync: Date.now()
|
|
726
|
+
});
|
|
727
|
+
}
|
|
728
|
+
}),
|
|
729
|
+
$applyOperation: (P, O) => {
|
|
730
|
+
n(P.newValue, P.path, {
|
|
731
|
+
updateType: P.updateType,
|
|
732
|
+
itemId: P.itemId,
|
|
733
|
+
metaData: O
|
|
734
|
+
});
|
|
735
|
+
},
|
|
736
|
+
getFieldMetaData: () => me(e, t)?.get(u.name),
|
|
737
|
+
setFieldMetaData: (P) => he(e, t, u.name, P),
|
|
738
|
+
removeFieldMetaData: () => ve(e, t, u.name),
|
|
739
|
+
getFieldRefs: () => $e(e, t),
|
|
740
|
+
getFieldElements: () => Ee(e, t),
|
|
741
|
+
setFieldDisabled: (P) => ft(e, t, P)
|
|
742
|
+
},
|
|
743
|
+
...w
|
|
744
|
+
);
|
|
745
|
+
};
|
|
746
|
+
}
|
|
747
|
+
const S = [...t, g];
|
|
676
748
|
return c({
|
|
677
|
-
path:
|
|
678
|
-
componentId:
|
|
679
|
-
meta:
|
|
749
|
+
path: S,
|
|
750
|
+
componentId: d,
|
|
751
|
+
meta: a
|
|
680
752
|
});
|
|
681
753
|
}
|
|
682
|
-
if (
|
|
754
|
+
if (g === "$_rebuildStateShape")
|
|
683
755
|
return c;
|
|
684
|
-
if (
|
|
756
|
+
if (g === "$sync" && t.length === 0)
|
|
685
757
|
return async function() {
|
|
686
|
-
const r =
|
|
687
|
-
if (!
|
|
758
|
+
const r = p.getState().getInitialOptions(e), o = r?.sync;
|
|
759
|
+
if (!o)
|
|
688
760
|
return console.error(`No mutation defined for state key "${e}"`), { success: !1, error: "No mutation defined" };
|
|
689
|
-
const
|
|
761
|
+
const s = p.getState().getShadowValue(e, []), S = r?.validation?.key;
|
|
690
762
|
try {
|
|
691
|
-
const
|
|
692
|
-
if (
|
|
693
|
-
const h =
|
|
694
|
-
|
|
763
|
+
const u = await o.action(s);
|
|
764
|
+
if (u && !u.success && u.errors, u?.success) {
|
|
765
|
+
const h = p.getState().getShadowMetadata(e, []);
|
|
766
|
+
L(e, [], {
|
|
695
767
|
...h,
|
|
696
768
|
isDirty: !1,
|
|
697
769
|
lastServerSync: Date.now(),
|
|
698
770
|
stateSource: "server",
|
|
699
|
-
baseServerState:
|
|
771
|
+
baseServerState: s
|
|
700
772
|
// Update base server state
|
|
701
|
-
}),
|
|
702
|
-
} else !
|
|
703
|
-
return
|
|
704
|
-
} catch (
|
|
705
|
-
return
|
|
773
|
+
}), o.onSuccess && o.onSuccess(u.data);
|
|
774
|
+
} else !u?.success && o.onError && o.onError(u.error);
|
|
775
|
+
return u;
|
|
776
|
+
} catch (u) {
|
|
777
|
+
return o.onError && o.onError(u), { success: !1, error: u };
|
|
706
778
|
}
|
|
707
779
|
};
|
|
708
|
-
if (
|
|
780
|
+
if (g === "$_status" || g === "$getStatus") {
|
|
709
781
|
const r = () => {
|
|
710
|
-
const { shadowMeta:
|
|
711
|
-
return
|
|
782
|
+
const { shadowMeta: o, value: s } = j(e, t, a);
|
|
783
|
+
return o?.isDirty === !0 ? "dirty" : o?.stateSource === "server" || o?.isDirty === !1 ? "synced" : o?.stateSource === "localStorage" ? "restored" : o?.stateSource === "default" || s !== void 0 ? "fresh" : "unknown";
|
|
712
784
|
};
|
|
713
|
-
return
|
|
785
|
+
return g === "$_status" ? r() : r;
|
|
714
786
|
}
|
|
715
|
-
if (
|
|
787
|
+
if (g === "$removeStorage")
|
|
716
788
|
return () => {
|
|
717
|
-
const r =
|
|
718
|
-
|
|
789
|
+
const r = p.getState().initialStateGlobal[e], o = U(e), s = z(o?.localStorage?.key) ? o.localStorage.key(r) : o?.localStorage?.key, S = i && s ? `${i}-${e}-${s}` : void 0;
|
|
790
|
+
le(S);
|
|
791
|
+
};
|
|
792
|
+
if (g === "$setRaw")
|
|
793
|
+
return (r) => {
|
|
794
|
+
const o = $(e, t) || {};
|
|
795
|
+
L(e, t, { ...o, isRaw: !0 }), n(r, t, { updateType: "update" });
|
|
719
796
|
};
|
|
720
|
-
if (
|
|
797
|
+
if (g === "$validate")
|
|
721
798
|
return () => {
|
|
722
|
-
const r =
|
|
799
|
+
const r = p.getState(), { value: o } = j(e, t, a), s = r.getInitialOptions(e), S = s?.validation?.zodSchemaV4 || s?.validation?.zodSchemaV3;
|
|
723
800
|
if (!S)
|
|
724
|
-
return { success: !0, data:
|
|
725
|
-
const
|
|
726
|
-
if (
|
|
801
|
+
return { success: !0, data: o };
|
|
802
|
+
const u = S.safeParse(o);
|
|
803
|
+
if (u.success) {
|
|
727
804
|
const h = r.getShadowMetadata(e, t) || {};
|
|
728
805
|
r.setShadowMetadata(e, t, {
|
|
729
806
|
...h,
|
|
@@ -734,18 +811,18 @@ function we(e, a, l, s) {
|
|
|
734
811
|
}
|
|
735
812
|
});
|
|
736
813
|
} else
|
|
737
|
-
(
|
|
738
|
-
const A = [...t, ...
|
|
814
|
+
(u.error?.issues || u.error?.errors || []).forEach((w) => {
|
|
815
|
+
const A = [...t, ...w.path.map(String)], M = r.getShadowMetadata(e, A) || {};
|
|
739
816
|
r.setShadowMetadata(e, A, {
|
|
740
|
-
|
|
817
|
+
...M,
|
|
741
818
|
validation: {
|
|
742
819
|
status: "INVALID",
|
|
743
820
|
errors: [
|
|
744
821
|
{
|
|
745
822
|
source: "client",
|
|
746
|
-
message:
|
|
823
|
+
message: w.message,
|
|
747
824
|
severity: "error",
|
|
748
|
-
code:
|
|
825
|
+
code: w.code
|
|
749
826
|
}
|
|
750
827
|
],
|
|
751
828
|
lastValidated: Date.now(),
|
|
@@ -753,403 +830,403 @@ function we(e, a, l, s) {
|
|
|
753
830
|
}
|
|
754
831
|
});
|
|
755
832
|
});
|
|
756
|
-
return
|
|
833
|
+
return W(e), u;
|
|
757
834
|
};
|
|
758
|
-
if (
|
|
835
|
+
if (g === "$showValidationErrors")
|
|
759
836
|
return () => {
|
|
760
|
-
const { shadowMeta: r } =
|
|
761
|
-
return r?.validation?.status === "INVALID" && r.validation.errors.length > 0 ? r.validation.errors.filter((
|
|
837
|
+
const { shadowMeta: r } = j(e, t, a);
|
|
838
|
+
return r?.validation?.status === "INVALID" && r.validation.errors.length > 0 ? r.validation.errors.filter((o) => o.severity === "error").map((o) => o.message) : [];
|
|
762
839
|
};
|
|
763
|
-
if (
|
|
840
|
+
if (g === "$getSelected")
|
|
764
841
|
return () => {
|
|
765
842
|
const r = [e, ...t].join(".");
|
|
766
|
-
|
|
843
|
+
ee(e, d, [
|
|
767
844
|
...t,
|
|
768
845
|
"getSelected"
|
|
769
846
|
]);
|
|
770
|
-
const
|
|
771
|
-
if (!
|
|
847
|
+
const o = p.getState().selectedIndicesMap.get(r);
|
|
848
|
+
if (!o)
|
|
772
849
|
return;
|
|
773
|
-
const
|
|
774
|
-
if (!(S && !S.includes(
|
|
850
|
+
const s = t.join("."), S = a?.arrayViews?.[s], u = o.split(".").pop();
|
|
851
|
+
if (!(S && !S.includes(u) || D(
|
|
775
852
|
e,
|
|
776
|
-
|
|
853
|
+
o.split(".").slice(1)
|
|
777
854
|
) === void 0))
|
|
778
855
|
return c({
|
|
779
|
-
path:
|
|
780
|
-
componentId:
|
|
781
|
-
meta:
|
|
856
|
+
path: o.split(".").slice(1),
|
|
857
|
+
componentId: d,
|
|
858
|
+
meta: a
|
|
782
859
|
});
|
|
783
860
|
};
|
|
784
|
-
if (
|
|
861
|
+
if (g === "$getSelectedIndex")
|
|
785
862
|
return () => {
|
|
786
863
|
const r = e + "." + t.join(".");
|
|
787
864
|
t.join(".");
|
|
788
|
-
const
|
|
789
|
-
if (!
|
|
865
|
+
const o = p.getState().selectedIndicesMap.get(r);
|
|
866
|
+
if (!o)
|
|
790
867
|
return -1;
|
|
791
|
-
const { keys:
|
|
792
|
-
if (!
|
|
868
|
+
const { keys: s } = N(e, t, a);
|
|
869
|
+
if (!s)
|
|
793
870
|
return -1;
|
|
794
|
-
const S =
|
|
795
|
-
return
|
|
871
|
+
const S = o.split(".").pop();
|
|
872
|
+
return s.indexOf(S);
|
|
796
873
|
};
|
|
797
|
-
if (
|
|
798
|
-
return
|
|
799
|
-
|
|
874
|
+
if (g === "$clearSelected")
|
|
875
|
+
return Y(e, t), () => {
|
|
876
|
+
Je({
|
|
800
877
|
arrayKey: e + "." + t.join(".")
|
|
801
878
|
});
|
|
802
879
|
};
|
|
803
|
-
if (
|
|
880
|
+
if (g === "$map")
|
|
804
881
|
return (r) => {
|
|
805
|
-
const { value:
|
|
882
|
+
const { value: o, keys: s } = N(
|
|
806
883
|
e,
|
|
807
884
|
t,
|
|
808
|
-
|
|
885
|
+
a
|
|
809
886
|
);
|
|
810
|
-
if (
|
|
887
|
+
if (ee(e, d, t), !s || !Array.isArray(o))
|
|
811
888
|
return [];
|
|
812
889
|
const S = c({
|
|
813
890
|
path: t,
|
|
814
|
-
componentId:
|
|
815
|
-
meta:
|
|
891
|
+
componentId: d,
|
|
892
|
+
meta: a
|
|
816
893
|
});
|
|
817
|
-
return
|
|
818
|
-
const
|
|
819
|
-
if (!
|
|
820
|
-
const A = [...t,
|
|
894
|
+
return o.map((u, h) => {
|
|
895
|
+
const w = s[h];
|
|
896
|
+
if (!w) return;
|
|
897
|
+
const A = [...t, w], M = c({
|
|
821
898
|
path: A,
|
|
822
899
|
// This now correctly points to the item in the shadow store.
|
|
823
|
-
componentId:
|
|
824
|
-
meta:
|
|
900
|
+
componentId: d,
|
|
901
|
+
meta: a
|
|
825
902
|
});
|
|
826
|
-
return r(
|
|
903
|
+
return r(M, h, S);
|
|
827
904
|
});
|
|
828
905
|
};
|
|
829
|
-
if (
|
|
906
|
+
if (g === "$filter")
|
|
830
907
|
return (r) => {
|
|
831
|
-
const
|
|
908
|
+
const o = t.length > 0 ? t.join(".") : "root", { keys: s, value: S } = N(
|
|
832
909
|
e,
|
|
833
910
|
t,
|
|
834
|
-
|
|
911
|
+
a
|
|
835
912
|
);
|
|
836
913
|
if (!Array.isArray(S))
|
|
837
914
|
throw new Error("filter can only be used on arrays");
|
|
838
|
-
const
|
|
839
|
-
return S.forEach((h,
|
|
840
|
-
if (r(h,
|
|
841
|
-
const A =
|
|
842
|
-
A &&
|
|
915
|
+
const u = [];
|
|
916
|
+
return S.forEach((h, w) => {
|
|
917
|
+
if (r(h, w)) {
|
|
918
|
+
const A = s[w];
|
|
919
|
+
A && u.push(A);
|
|
843
920
|
}
|
|
844
921
|
}), c({
|
|
845
922
|
path: t,
|
|
846
|
-
componentId:
|
|
923
|
+
componentId: d,
|
|
847
924
|
meta: {
|
|
848
|
-
...
|
|
925
|
+
...a,
|
|
849
926
|
arrayViews: {
|
|
850
|
-
...
|
|
851
|
-
[
|
|
927
|
+
...a?.arrayViews || {},
|
|
928
|
+
[o]: u
|
|
852
929
|
},
|
|
853
930
|
transforms: [
|
|
854
|
-
...
|
|
931
|
+
...a?.transforms || [],
|
|
855
932
|
{ type: "filter", fn: r, path: t }
|
|
856
933
|
]
|
|
857
934
|
}
|
|
858
935
|
});
|
|
859
936
|
};
|
|
860
|
-
if (
|
|
937
|
+
if (g === "$sort")
|
|
861
938
|
return (r) => {
|
|
862
|
-
const
|
|
939
|
+
const o = t.length > 0 ? t.join(".") : "root", { value: s, keys: S } = N(
|
|
863
940
|
e,
|
|
864
941
|
t,
|
|
865
|
-
|
|
942
|
+
a
|
|
866
943
|
);
|
|
867
|
-
if (!Array.isArray(
|
|
944
|
+
if (!Array.isArray(s) || !S)
|
|
868
945
|
throw new Error("No array keys found for sorting");
|
|
869
|
-
const
|
|
870
|
-
item:
|
|
946
|
+
const u = s.map((w, A) => ({
|
|
947
|
+
item: w,
|
|
871
948
|
key: S[A]
|
|
872
949
|
}));
|
|
873
|
-
|
|
874
|
-
const h =
|
|
950
|
+
u.sort((w, A) => r(w.item, A.item));
|
|
951
|
+
const h = u.map((w) => w.key);
|
|
875
952
|
return c({
|
|
876
953
|
path: t,
|
|
877
|
-
componentId:
|
|
954
|
+
componentId: d,
|
|
878
955
|
meta: {
|
|
879
|
-
...
|
|
956
|
+
...a,
|
|
880
957
|
arrayViews: {
|
|
881
|
-
...
|
|
882
|
-
[
|
|
958
|
+
...a?.arrayViews || {},
|
|
959
|
+
[o]: h
|
|
883
960
|
},
|
|
884
961
|
transforms: [
|
|
885
|
-
...
|
|
962
|
+
...a?.transforms || [],
|
|
886
963
|
{ type: "sort", fn: r, path: t }
|
|
887
964
|
]
|
|
888
965
|
}
|
|
889
966
|
});
|
|
890
967
|
};
|
|
891
|
-
if (
|
|
892
|
-
return (r) => /* @__PURE__ */
|
|
893
|
-
const
|
|
894
|
-
...
|
|
968
|
+
if (g === "$list")
|
|
969
|
+
return (r) => /* @__PURE__ */ Q(() => {
|
|
970
|
+
const s = q(/* @__PURE__ */ new Map()), [S, u] = te({}), h = t.length > 0 ? t.join(".") : "root", w = lt(e, t, a), A = pe(() => ({
|
|
971
|
+
...a,
|
|
895
972
|
arrayViews: {
|
|
896
|
-
...
|
|
897
|
-
[h]:
|
|
973
|
+
...a?.arrayViews || {},
|
|
974
|
+
[h]: w
|
|
898
975
|
}
|
|
899
|
-
}), [
|
|
976
|
+
}), [a, h, w]), { value: M } = N(
|
|
900
977
|
e,
|
|
901
978
|
t,
|
|
902
979
|
A
|
|
903
980
|
);
|
|
904
|
-
if (
|
|
905
|
-
const
|
|
906
|
-
if (
|
|
981
|
+
if (x(() => {
|
|
982
|
+
const O = p.getState().subscribeToPath(v, (F) => {
|
|
983
|
+
if (F.type === "GET_SELECTED")
|
|
907
984
|
return;
|
|
908
|
-
const
|
|
909
|
-
if (
|
|
910
|
-
for (const
|
|
911
|
-
|
|
912
|
-
(
|
|
985
|
+
const B = p.getState().getShadowMetadata(e, t)?.transformCaches;
|
|
986
|
+
if (B)
|
|
987
|
+
for (const K of B.keys())
|
|
988
|
+
K.startsWith(d) && B.delete(K);
|
|
989
|
+
(F.type === "INSERT" || F.type === "INSERT_MANY" || F.type === "REMOVE" || F.type === "CLEAR_SELECTION" || F.type === "SERVER_STATE_UPDATE" && !a?.serverStateIsUpStream) && u({});
|
|
913
990
|
});
|
|
914
991
|
return () => {
|
|
915
|
-
|
|
992
|
+
O();
|
|
916
993
|
};
|
|
917
|
-
}, [
|
|
994
|
+
}, [d, v]), !Array.isArray(M))
|
|
918
995
|
return null;
|
|
919
|
-
const
|
|
996
|
+
const I = c({
|
|
920
997
|
path: t,
|
|
921
|
-
componentId:
|
|
998
|
+
componentId: d,
|
|
922
999
|
meta: A
|
|
923
1000
|
// Use updated meta here
|
|
924
|
-
}),
|
|
925
|
-
const
|
|
926
|
-
if (!
|
|
1001
|
+
}), P = M.map((O, F) => {
|
|
1002
|
+
const H = w[F];
|
|
1003
|
+
if (!H)
|
|
927
1004
|
return null;
|
|
928
|
-
let
|
|
929
|
-
|
|
930
|
-
const
|
|
931
|
-
return
|
|
932
|
-
key:
|
|
1005
|
+
let B = s.current.get(H);
|
|
1006
|
+
B || (B = re(), s.current.set(H, B));
|
|
1007
|
+
const K = [...t, H];
|
|
1008
|
+
return fe(Ue, {
|
|
1009
|
+
key: H,
|
|
933
1010
|
stateKey: e,
|
|
934
|
-
itemComponentId:
|
|
935
|
-
itemPath:
|
|
936
|
-
localIndex:
|
|
937
|
-
arraySetter:
|
|
1011
|
+
itemComponentId: B,
|
|
1012
|
+
itemPath: K,
|
|
1013
|
+
localIndex: F,
|
|
1014
|
+
arraySetter: I,
|
|
938
1015
|
rebuildStateShape: c,
|
|
939
1016
|
renderFn: r
|
|
940
1017
|
});
|
|
941
1018
|
});
|
|
942
|
-
return /* @__PURE__ */
|
|
1019
|
+
return /* @__PURE__ */ Q(Pe, { children: P });
|
|
943
1020
|
}, {});
|
|
944
|
-
if (
|
|
1021
|
+
if (g === "$stateFlattenOn")
|
|
945
1022
|
return (r) => {
|
|
946
|
-
const
|
|
1023
|
+
const o = t.length > 0 ? t.join(".") : "root", s = a?.arrayViews?.[o], S = p.getState().getShadowValue(e, t, s);
|
|
947
1024
|
return Array.isArray(S) ? c({
|
|
948
1025
|
path: [...t, "[*]", r],
|
|
949
|
-
componentId:
|
|
950
|
-
meta:
|
|
1026
|
+
componentId: d,
|
|
1027
|
+
meta: a
|
|
951
1028
|
}) : [];
|
|
952
1029
|
};
|
|
953
|
-
if (
|
|
1030
|
+
if (g === "$index")
|
|
954
1031
|
return (r) => {
|
|
955
|
-
const
|
|
956
|
-
if (
|
|
957
|
-
const h =
|
|
1032
|
+
const o = t.length > 0 ? t.join(".") : "root", s = a?.arrayViews?.[o];
|
|
1033
|
+
if (s) {
|
|
1034
|
+
const h = s[r];
|
|
958
1035
|
return h ? c({
|
|
959
1036
|
path: [...t, h],
|
|
960
|
-
componentId:
|
|
961
|
-
meta:
|
|
1037
|
+
componentId: d,
|
|
1038
|
+
meta: a
|
|
962
1039
|
}) : void 0;
|
|
963
1040
|
}
|
|
964
|
-
const S =
|
|
1041
|
+
const S = $(e, t);
|
|
965
1042
|
if (!S?.arrayKeys) return;
|
|
966
|
-
const
|
|
967
|
-
if (
|
|
1043
|
+
const u = S.arrayKeys[r];
|
|
1044
|
+
if (u)
|
|
968
1045
|
return c({
|
|
969
|
-
path: [...t,
|
|
970
|
-
componentId:
|
|
971
|
-
meta:
|
|
1046
|
+
path: [...t, u],
|
|
1047
|
+
componentId: d,
|
|
1048
|
+
meta: a
|
|
972
1049
|
});
|
|
973
1050
|
};
|
|
974
|
-
if (
|
|
1051
|
+
if (g === "$last")
|
|
975
1052
|
return () => {
|
|
976
|
-
const { keys: r } =
|
|
1053
|
+
const { keys: r } = N(e, t, a);
|
|
977
1054
|
if (!r || r.length === 0)
|
|
978
1055
|
return;
|
|
979
|
-
const
|
|
980
|
-
if (!
|
|
1056
|
+
const o = r[r.length - 1];
|
|
1057
|
+
if (!o)
|
|
981
1058
|
return;
|
|
982
|
-
const
|
|
1059
|
+
const s = [...t, o];
|
|
983
1060
|
return c({
|
|
984
|
-
path:
|
|
985
|
-
componentId:
|
|
986
|
-
meta:
|
|
1061
|
+
path: s,
|
|
1062
|
+
componentId: d,
|
|
1063
|
+
meta: a
|
|
987
1064
|
});
|
|
988
1065
|
};
|
|
989
|
-
if (
|
|
990
|
-
return (r,
|
|
991
|
-
|
|
1066
|
+
if (g === "$insert")
|
|
1067
|
+
return (r, o) => {
|
|
1068
|
+
n(r, t, {
|
|
992
1069
|
updateType: "insert",
|
|
993
|
-
index:
|
|
1070
|
+
index: o
|
|
994
1071
|
});
|
|
995
1072
|
};
|
|
996
|
-
if (
|
|
1073
|
+
if (g === "$insertMany")
|
|
997
1074
|
return (r) => {
|
|
998
|
-
|
|
1075
|
+
n(r, t, {
|
|
999
1076
|
updateType: "insert_many"
|
|
1000
1077
|
});
|
|
1001
1078
|
};
|
|
1002
|
-
if (
|
|
1003
|
-
return (r,
|
|
1004
|
-
const { value: S } =
|
|
1079
|
+
if (g === "$uniqueInsert")
|
|
1080
|
+
return (r, o, s) => {
|
|
1081
|
+
const { value: S } = j(
|
|
1005
1082
|
e,
|
|
1006
1083
|
t,
|
|
1007
|
-
|
|
1008
|
-
),
|
|
1084
|
+
a
|
|
1085
|
+
), u = z(r) ? r(S) : r;
|
|
1009
1086
|
let h = null;
|
|
1010
1087
|
if (!S.some((A) => {
|
|
1011
|
-
const
|
|
1012
|
-
(
|
|
1013
|
-
) :
|
|
1014
|
-
return
|
|
1088
|
+
const M = o ? o.every(
|
|
1089
|
+
(I) => Z(A[I], u[I])
|
|
1090
|
+
) : Z(A, u);
|
|
1091
|
+
return M && (h = A), M;
|
|
1015
1092
|
}))
|
|
1016
|
-
|
|
1017
|
-
else if (
|
|
1018
|
-
const A =
|
|
1019
|
-
(
|
|
1093
|
+
n(u, t, { updateType: "insert" });
|
|
1094
|
+
else if (s && h) {
|
|
1095
|
+
const A = s(h), M = S.map(
|
|
1096
|
+
(I) => Z(I, h) ? A : I
|
|
1020
1097
|
);
|
|
1021
|
-
|
|
1098
|
+
n(M, t, {
|
|
1022
1099
|
updateType: "update"
|
|
1023
1100
|
});
|
|
1024
1101
|
}
|
|
1025
1102
|
};
|
|
1026
|
-
if (
|
|
1027
|
-
return (r,
|
|
1028
|
-
const
|
|
1029
|
-
if (!
|
|
1103
|
+
if (g === "$cut")
|
|
1104
|
+
return (r, o) => {
|
|
1105
|
+
const s = $(e, t);
|
|
1106
|
+
if (!s?.arrayKeys || s.arrayKeys.length === 0)
|
|
1030
1107
|
return;
|
|
1031
|
-
const S = r === -1 ?
|
|
1032
|
-
|
|
1108
|
+
const S = r === -1 ? s.arrayKeys.length - 1 : r !== void 0 ? r : s.arrayKeys.length - 1, u = s.arrayKeys[S];
|
|
1109
|
+
u && n(null, [...t, u], {
|
|
1033
1110
|
updateType: "cut"
|
|
1034
1111
|
});
|
|
1035
1112
|
};
|
|
1036
|
-
if (
|
|
1113
|
+
if (g === "$cutSelected")
|
|
1037
1114
|
return () => {
|
|
1038
|
-
const r = [e, ...t].join("."), { keys:
|
|
1039
|
-
if (!
|
|
1115
|
+
const r = [e, ...t].join("."), { keys: o } = N(e, t, a);
|
|
1116
|
+
if (!o || o.length === 0)
|
|
1040
1117
|
return;
|
|
1041
|
-
const
|
|
1042
|
-
if (!
|
|
1118
|
+
const s = p.getState().selectedIndicesMap.get(r);
|
|
1119
|
+
if (!s)
|
|
1043
1120
|
return;
|
|
1044
|
-
const S =
|
|
1045
|
-
if (!
|
|
1121
|
+
const S = s.split(".").pop();
|
|
1122
|
+
if (!o.includes(S))
|
|
1046
1123
|
return;
|
|
1047
|
-
const
|
|
1048
|
-
|
|
1049
|
-
const h =
|
|
1050
|
-
|
|
1124
|
+
const u = s.split(".").slice(1);
|
|
1125
|
+
p.getState().clearSelectedIndex({ arrayKey: r });
|
|
1126
|
+
const h = u.slice(0, -1);
|
|
1127
|
+
Y(e, h), n(null, u, {
|
|
1051
1128
|
updateType: "cut"
|
|
1052
1129
|
});
|
|
1053
1130
|
};
|
|
1054
|
-
if (
|
|
1131
|
+
if (g === "$cutByValue")
|
|
1055
1132
|
return (r) => {
|
|
1056
1133
|
const {
|
|
1057
|
-
isArray:
|
|
1058
|
-
value:
|
|
1134
|
+
isArray: o,
|
|
1135
|
+
value: s,
|
|
1059
1136
|
keys: S
|
|
1060
|
-
} =
|
|
1061
|
-
if (!
|
|
1062
|
-
const
|
|
1063
|
-
|
|
1137
|
+
} = N(e, t, a);
|
|
1138
|
+
if (!o) return;
|
|
1139
|
+
const u = se(s, S, (h) => h === r);
|
|
1140
|
+
u && n(null, [...t, u.key], {
|
|
1064
1141
|
updateType: "cut"
|
|
1065
1142
|
});
|
|
1066
1143
|
};
|
|
1067
|
-
if (
|
|
1144
|
+
if (g === "$toggleByValue")
|
|
1068
1145
|
return (r) => {
|
|
1069
1146
|
const {
|
|
1070
|
-
isArray:
|
|
1071
|
-
value:
|
|
1147
|
+
isArray: o,
|
|
1148
|
+
value: s,
|
|
1072
1149
|
keys: S
|
|
1073
|
-
} =
|
|
1074
|
-
if (!
|
|
1075
|
-
const
|
|
1076
|
-
if (
|
|
1077
|
-
const h = [...t,
|
|
1078
|
-
|
|
1150
|
+
} = N(e, t, a);
|
|
1151
|
+
if (!o) return;
|
|
1152
|
+
const u = se(s, S, (h) => h === r);
|
|
1153
|
+
if (u) {
|
|
1154
|
+
const h = [...t, u.key];
|
|
1155
|
+
n(null, h, {
|
|
1079
1156
|
updateType: "cut"
|
|
1080
1157
|
});
|
|
1081
1158
|
} else
|
|
1082
|
-
|
|
1159
|
+
n(r, t, { updateType: "insert" });
|
|
1083
1160
|
};
|
|
1084
|
-
if (
|
|
1085
|
-
return (r,
|
|
1086
|
-
const { isArray:
|
|
1087
|
-
if (!
|
|
1161
|
+
if (g === "$findWith")
|
|
1162
|
+
return (r, o) => {
|
|
1163
|
+
const { isArray: s, value: S, keys: u } = N(e, t, a);
|
|
1164
|
+
if (!s)
|
|
1088
1165
|
throw new Error("findWith can only be used on arrays");
|
|
1089
1166
|
const h = se(
|
|
1090
1167
|
S,
|
|
1091
|
-
|
|
1092
|
-
(
|
|
1168
|
+
u,
|
|
1169
|
+
(w) => w?.[r] === o
|
|
1093
1170
|
);
|
|
1094
1171
|
return h ? c({
|
|
1095
1172
|
path: [...t, h.key],
|
|
1096
|
-
componentId:
|
|
1097
|
-
meta:
|
|
1173
|
+
componentId: d,
|
|
1174
|
+
meta: a
|
|
1098
1175
|
}) : null;
|
|
1099
1176
|
};
|
|
1100
|
-
if (
|
|
1101
|
-
const { value: r } =
|
|
1102
|
-
return
|
|
1103
|
-
|
|
1177
|
+
if (g === "$cutThis") {
|
|
1178
|
+
const { value: r } = j(e, t, a), o = t.slice(0, -1);
|
|
1179
|
+
return Y(e, o), () => {
|
|
1180
|
+
n(r, t, { updateType: "cut" });
|
|
1104
1181
|
};
|
|
1105
1182
|
}
|
|
1106
|
-
if (
|
|
1183
|
+
if (g === "$get")
|
|
1107
1184
|
return () => {
|
|
1108
|
-
|
|
1109
|
-
const { value: r } =
|
|
1185
|
+
ee(e, d, t);
|
|
1186
|
+
const { value: r } = j(e, t, a);
|
|
1110
1187
|
return r;
|
|
1111
1188
|
};
|
|
1112
|
-
if (
|
|
1113
|
-
return (r) =>
|
|
1189
|
+
if (g === "$$derive")
|
|
1190
|
+
return (r) => we({
|
|
1114
1191
|
_stateKey: e,
|
|
1115
1192
|
_path: t,
|
|
1116
1193
|
_effect: r.toString(),
|
|
1117
|
-
_meta:
|
|
1194
|
+
_meta: a
|
|
1118
1195
|
});
|
|
1119
|
-
if (
|
|
1120
|
-
return () =>
|
|
1121
|
-
if (
|
|
1196
|
+
if (g === "$$get")
|
|
1197
|
+
return () => we({ _stateKey: e, _path: t, _meta: a });
|
|
1198
|
+
if (g === "$lastSynced") {
|
|
1122
1199
|
const r = `${e}:${t.join(".")}`;
|
|
1123
|
-
return
|
|
1200
|
+
return He(r);
|
|
1124
1201
|
}
|
|
1125
|
-
if (
|
|
1126
|
-
return (r) =>
|
|
1127
|
-
if (
|
|
1202
|
+
if (g == "getLocalStorage")
|
|
1203
|
+
return (r) => ie(i + "-" + e + "-" + r);
|
|
1204
|
+
if (g === "$isSelected") {
|
|
1128
1205
|
const r = t.slice(0, -1);
|
|
1129
|
-
if (
|
|
1130
|
-
const
|
|
1131
|
-
return S ===
|
|
1206
|
+
if ($(e, r)?.arrayKeys) {
|
|
1207
|
+
const s = e + "." + r.join("."), S = p.getState().selectedIndicesMap.get(s), u = e + "." + t.join(".");
|
|
1208
|
+
return S === u;
|
|
1132
1209
|
}
|
|
1133
1210
|
return;
|
|
1134
1211
|
}
|
|
1135
|
-
if (
|
|
1212
|
+
if (g === "$setSelected")
|
|
1136
1213
|
return (r) => {
|
|
1137
|
-
const
|
|
1138
|
-
|
|
1214
|
+
const o = t.slice(0, -1), s = e + "." + o.join("."), S = e + "." + t.join(".");
|
|
1215
|
+
Y(e, o, void 0), p.getState().selectedIndicesMap.get(s), r && p.getState().setSelectedIndex(s, S);
|
|
1139
1216
|
};
|
|
1140
|
-
if (
|
|
1217
|
+
if (g === "$toggleSelected")
|
|
1141
1218
|
return () => {
|
|
1142
|
-
const r = t.slice(0, -1),
|
|
1143
|
-
|
|
1219
|
+
const r = t.slice(0, -1), o = e + "." + r.join("."), s = e + "." + t.join(".");
|
|
1220
|
+
p.getState().selectedIndicesMap.get(o) === s ? p.getState().clearSelectedIndex({ arrayKey: o }) : p.getState().setSelectedIndex(o, s), Y(e, r);
|
|
1144
1221
|
};
|
|
1145
|
-
if (
|
|
1222
|
+
if (g === "$clearValidation")
|
|
1146
1223
|
return (r) => {
|
|
1147
|
-
const
|
|
1224
|
+
const o = r ? [...t, ...r] : t, s = p.getState(), S = s.getShadowNode(e, o);
|
|
1148
1225
|
if (console.log("startNode ", S), !S) return;
|
|
1149
|
-
const
|
|
1150
|
-
for (console.log("stack ",
|
|
1151
|
-
const [h,
|
|
1152
|
-
if (console.log("while (stack.length ", h,
|
|
1226
|
+
const u = [[S, o]];
|
|
1227
|
+
for (console.log("stack ", u); u.length > 0; ) {
|
|
1228
|
+
const [h, w] = u.pop();
|
|
1229
|
+
if (console.log("while (stack.length ", h, w), !h || typeof h != "object") continue;
|
|
1153
1230
|
if (h._meta?.validation) {
|
|
1154
1231
|
h._meta.validation = {
|
|
1155
1232
|
status: "NOT_VALIDATED",
|
|
@@ -1157,50 +1234,50 @@ function we(e, a, l, s) {
|
|
|
1157
1234
|
lastValidated: Date.now(),
|
|
1158
1235
|
validatedValue: void 0
|
|
1159
1236
|
};
|
|
1160
|
-
const
|
|
1161
|
-
|
|
1237
|
+
const M = [e, ...w].join(".");
|
|
1238
|
+
s.notifyPathSubscribers(M, {
|
|
1162
1239
|
type: "VALIDATION_CLEAR"
|
|
1163
1240
|
});
|
|
1164
1241
|
}
|
|
1165
1242
|
const A = Object.keys(h);
|
|
1166
|
-
for (const
|
|
1167
|
-
|
|
1243
|
+
for (const M of A)
|
|
1244
|
+
M !== "_meta" && u.push([h[M], [...w, M]]);
|
|
1168
1245
|
}
|
|
1169
|
-
|
|
1246
|
+
W(e);
|
|
1170
1247
|
};
|
|
1171
1248
|
if (t.length == 0) {
|
|
1172
|
-
if (
|
|
1173
|
-
return
|
|
1174
|
-
if (
|
|
1249
|
+
if (g === "$_componentId")
|
|
1250
|
+
return d;
|
|
1251
|
+
if (g === "$setOptions")
|
|
1175
1252
|
return (r) => {
|
|
1176
|
-
|
|
1253
|
+
ue({ stateKey: e, options: r, initialOptionsPart: {} });
|
|
1177
1254
|
};
|
|
1178
|
-
if (
|
|
1179
|
-
return (r,
|
|
1180
|
-
|
|
1255
|
+
if (g === "$_applyUpdate")
|
|
1256
|
+
return (r, o, s = "update") => {
|
|
1257
|
+
n(r, o, { updateType: s });
|
|
1181
1258
|
};
|
|
1182
|
-
if (
|
|
1183
|
-
return
|
|
1184
|
-
if (
|
|
1185
|
-
return (r) =>
|
|
1186
|
-
if (
|
|
1187
|
-
return (r,
|
|
1188
|
-
if (
|
|
1189
|
-
return (r) =>
|
|
1190
|
-
if (
|
|
1191
|
-
return (r,
|
|
1192
|
-
r.forEach((
|
|
1193
|
-
const S =
|
|
1194
|
-
|
|
1259
|
+
if (g === "$_getEffectiveSetState")
|
|
1260
|
+
return n;
|
|
1261
|
+
if (g === "$getPluginMetaData")
|
|
1262
|
+
return (r) => me(e, t)?.get(r);
|
|
1263
|
+
if (g === "$addPluginMetaData")
|
|
1264
|
+
return (r, o) => he(e, t, r, o);
|
|
1265
|
+
if (g === "$removePluginMetaData")
|
|
1266
|
+
return (r) => ve(e, t, r);
|
|
1267
|
+
if (g === "$addZodValidation")
|
|
1268
|
+
return (r, o) => {
|
|
1269
|
+
r.forEach((s) => {
|
|
1270
|
+
const S = p.getState().getShadowMetadata(e, s.path) || {};
|
|
1271
|
+
p.getState().setShadowMetadata(e, s.path, {
|
|
1195
1272
|
...S,
|
|
1196
1273
|
validation: {
|
|
1197
1274
|
status: "INVALID",
|
|
1198
1275
|
errors: [
|
|
1199
1276
|
{
|
|
1200
|
-
source:
|
|
1201
|
-
message:
|
|
1277
|
+
source: o || "client",
|
|
1278
|
+
message: s.message,
|
|
1202
1279
|
severity: "error",
|
|
1203
|
-
code:
|
|
1280
|
+
code: s.code
|
|
1204
1281
|
}
|
|
1205
1282
|
],
|
|
1206
1283
|
lastValidated: Date.now(),
|
|
@@ -1209,194 +1286,194 @@ function we(e, a, l, s) {
|
|
|
1209
1286
|
});
|
|
1210
1287
|
});
|
|
1211
1288
|
};
|
|
1212
|
-
if (
|
|
1213
|
-
return (r,
|
|
1214
|
-
let
|
|
1289
|
+
if (g === "$applyOperation")
|
|
1290
|
+
return (r, o) => {
|
|
1291
|
+
let s;
|
|
1215
1292
|
if (r.insertAfterId && r.updateType === "insert") {
|
|
1216
|
-
const S =
|
|
1293
|
+
const S = $(e, r.path);
|
|
1217
1294
|
if (S?.arrayKeys) {
|
|
1218
|
-
const
|
|
1295
|
+
const u = S.arrayKeys.indexOf(
|
|
1219
1296
|
r.insertAfterId
|
|
1220
1297
|
);
|
|
1221
|
-
|
|
1298
|
+
u !== -1 && (s = u + 1);
|
|
1222
1299
|
}
|
|
1223
1300
|
}
|
|
1224
|
-
|
|
1301
|
+
n(r.newValue, r.path, {
|
|
1225
1302
|
updateType: r.updateType,
|
|
1226
1303
|
itemId: r.itemId,
|
|
1227
|
-
index:
|
|
1304
|
+
index: s,
|
|
1228
1305
|
// Pass the calculated index
|
|
1229
|
-
metaData:
|
|
1306
|
+
metaData: o
|
|
1230
1307
|
});
|
|
1231
1308
|
};
|
|
1232
|
-
if (
|
|
1309
|
+
if (g === "$applyJsonPatch")
|
|
1233
1310
|
return (r) => {
|
|
1234
|
-
const
|
|
1235
|
-
if (!
|
|
1236
|
-
const S = (h) => !h || h === "/" ? [] : h.split("/").slice(1).map((
|
|
1311
|
+
const o = p.getState(), s = o.getShadowMetadata(e, []);
|
|
1312
|
+
if (!s?.components) return;
|
|
1313
|
+
const S = (h) => !h || h === "/" ? [] : h.split("/").slice(1).map((w) => w.replace(/~1/g, "/").replace(/~0/g, "~")), u = /* @__PURE__ */ new Set();
|
|
1237
1314
|
for (const h of r) {
|
|
1238
|
-
const
|
|
1315
|
+
const w = S(h.path);
|
|
1239
1316
|
switch (h.op) {
|
|
1240
1317
|
case "add":
|
|
1241
1318
|
case "replace": {
|
|
1242
1319
|
const { value: A } = h;
|
|
1243
|
-
|
|
1244
|
-
let
|
|
1320
|
+
o.updateShadowAtPath(e, w, A), o.markAsDirty(e, w, { bubble: !0 });
|
|
1321
|
+
let M = [...w];
|
|
1245
1322
|
for (; ; ) {
|
|
1246
|
-
const
|
|
1323
|
+
const I = o.getShadowMetadata(
|
|
1247
1324
|
e,
|
|
1248
|
-
|
|
1325
|
+
M
|
|
1249
1326
|
);
|
|
1250
|
-
if (
|
|
1251
|
-
if (!
|
|
1252
|
-
const
|
|
1253
|
-
|
|
1327
|
+
if (I?.pathComponents && I.pathComponents.forEach((P) => {
|
|
1328
|
+
if (!u.has(P)) {
|
|
1329
|
+
const O = s.components?.get(P);
|
|
1330
|
+
O && (O.forceUpdate(), u.add(P));
|
|
1254
1331
|
}
|
|
1255
|
-
}),
|
|
1256
|
-
|
|
1332
|
+
}), M.length === 0) break;
|
|
1333
|
+
M.pop();
|
|
1257
1334
|
}
|
|
1258
1335
|
break;
|
|
1259
1336
|
}
|
|
1260
1337
|
case "remove": {
|
|
1261
|
-
const A =
|
|
1262
|
-
|
|
1263
|
-
let
|
|
1338
|
+
const A = w.slice(0, -1);
|
|
1339
|
+
o.removeShadowArrayElement(e, w), o.markAsDirty(e, A, { bubble: !0 });
|
|
1340
|
+
let M = [...A];
|
|
1264
1341
|
for (; ; ) {
|
|
1265
|
-
const
|
|
1342
|
+
const I = o.getShadowMetadata(
|
|
1266
1343
|
e,
|
|
1267
|
-
|
|
1344
|
+
M
|
|
1268
1345
|
);
|
|
1269
|
-
if (
|
|
1270
|
-
if (!
|
|
1271
|
-
const
|
|
1272
|
-
|
|
1346
|
+
if (I?.pathComponents && I.pathComponents.forEach((P) => {
|
|
1347
|
+
if (!u.has(P)) {
|
|
1348
|
+
const O = s.components?.get(P);
|
|
1349
|
+
O && (O.forceUpdate(), u.add(P));
|
|
1273
1350
|
}
|
|
1274
|
-
}),
|
|
1275
|
-
|
|
1351
|
+
}), M.length === 0) break;
|
|
1352
|
+
M.pop();
|
|
1276
1353
|
}
|
|
1277
1354
|
break;
|
|
1278
1355
|
}
|
|
1279
1356
|
}
|
|
1280
1357
|
}
|
|
1281
1358
|
};
|
|
1282
|
-
if (
|
|
1283
|
-
return () =>
|
|
1359
|
+
if (g === "$getComponents")
|
|
1360
|
+
return () => $(e, [])?.components;
|
|
1284
1361
|
}
|
|
1285
|
-
if (
|
|
1362
|
+
if (g === "$validationWrapper")
|
|
1286
1363
|
return ({
|
|
1287
1364
|
children: r,
|
|
1288
|
-
hideMessage:
|
|
1289
|
-
}) => /* @__PURE__ */
|
|
1290
|
-
|
|
1365
|
+
hideMessage: o
|
|
1366
|
+
}) => /* @__PURE__ */ Q(
|
|
1367
|
+
Oe,
|
|
1291
1368
|
{
|
|
1292
|
-
formOpts:
|
|
1369
|
+
formOpts: o ? { validation: { message: "" } } : void 0,
|
|
1293
1370
|
path: t,
|
|
1294
1371
|
stateKey: e,
|
|
1295
1372
|
children: r
|
|
1296
1373
|
}
|
|
1297
1374
|
);
|
|
1298
|
-
if (
|
|
1299
|
-
if (
|
|
1300
|
-
if (
|
|
1301
|
-
return (r) => (
|
|
1375
|
+
if (g === "$_stateKey") return e;
|
|
1376
|
+
if (g === "$_path") return t;
|
|
1377
|
+
if (g === "$update")
|
|
1378
|
+
return (r) => (n(r, t, { updateType: "update" }), {
|
|
1302
1379
|
synced: () => {
|
|
1303
|
-
const
|
|
1304
|
-
|
|
1305
|
-
...
|
|
1380
|
+
const o = p.getState().getShadowMetadata(e, t);
|
|
1381
|
+
L(e, t, {
|
|
1382
|
+
...o,
|
|
1306
1383
|
isDirty: !1,
|
|
1307
1384
|
stateSource: "server",
|
|
1308
1385
|
lastServerSync: Date.now()
|
|
1309
1386
|
});
|
|
1310
|
-
const
|
|
1311
|
-
|
|
1387
|
+
const s = [e, ...t].join(".");
|
|
1388
|
+
Qe(s, {
|
|
1312
1389
|
type: "SYNC_STATUS_CHANGE",
|
|
1313
1390
|
isDirty: !1
|
|
1314
1391
|
});
|
|
1315
1392
|
}
|
|
1316
1393
|
});
|
|
1317
|
-
if (
|
|
1318
|
-
const { value: r } =
|
|
1394
|
+
if (g === "$toggle") {
|
|
1395
|
+
const { value: r } = j(
|
|
1319
1396
|
e,
|
|
1320
1397
|
t,
|
|
1321
|
-
|
|
1398
|
+
a
|
|
1322
1399
|
);
|
|
1323
1400
|
if (typeof r != "boolean")
|
|
1324
1401
|
throw new Error("toggle() can only be used on boolean values");
|
|
1325
1402
|
return () => {
|
|
1326
|
-
|
|
1403
|
+
n(!r, t, {
|
|
1327
1404
|
updateType: "update"
|
|
1328
1405
|
});
|
|
1329
1406
|
};
|
|
1330
1407
|
}
|
|
1331
|
-
if (
|
|
1332
|
-
return (r,
|
|
1333
|
-
const
|
|
1334
|
-
if (!
|
|
1408
|
+
if (g === "$isolate")
|
|
1409
|
+
return (r, o) => {
|
|
1410
|
+
const s = Array.isArray(r), S = s ? r : void 0, u = s ? o : r;
|
|
1411
|
+
if (!u || typeof u != "function")
|
|
1335
1412
|
throw new Error(
|
|
1336
1413
|
"CogsState: $isolate requires a render function."
|
|
1337
1414
|
);
|
|
1338
|
-
return /* @__PURE__ */
|
|
1339
|
-
|
|
1415
|
+
return /* @__PURE__ */ Q(
|
|
1416
|
+
je,
|
|
1340
1417
|
{
|
|
1341
1418
|
stateKey: e,
|
|
1342
1419
|
path: t,
|
|
1343
1420
|
dependencies: S,
|
|
1344
1421
|
rebuildStateShape: c,
|
|
1345
|
-
renderFn:
|
|
1422
|
+
renderFn: u
|
|
1346
1423
|
}
|
|
1347
1424
|
);
|
|
1348
1425
|
};
|
|
1349
|
-
if (
|
|
1350
|
-
return (r,
|
|
1351
|
-
|
|
1426
|
+
if (g === "$formElement")
|
|
1427
|
+
return (r, o) => /* @__PURE__ */ Q(
|
|
1428
|
+
Ne,
|
|
1352
1429
|
{
|
|
1353
1430
|
stateKey: e,
|
|
1354
1431
|
path: t,
|
|
1355
1432
|
rebuildStateShape: c,
|
|
1356
|
-
setState:
|
|
1357
|
-
formOpts:
|
|
1433
|
+
setState: n,
|
|
1434
|
+
formOpts: o,
|
|
1358
1435
|
renderFn: r
|
|
1359
1436
|
}
|
|
1360
1437
|
);
|
|
1361
|
-
const
|
|
1438
|
+
const k = [...t, g];
|
|
1362
1439
|
return c({
|
|
1363
|
-
path:
|
|
1364
|
-
componentId:
|
|
1365
|
-
meta:
|
|
1440
|
+
path: k,
|
|
1441
|
+
componentId: d,
|
|
1442
|
+
meta: a
|
|
1366
1443
|
});
|
|
1367
1444
|
}
|
|
1368
|
-
},
|
|
1369
|
-
return
|
|
1445
|
+
}, J = new Proxy(C, _);
|
|
1446
|
+
return f.set(V, J), J;
|
|
1370
1447
|
}
|
|
1371
1448
|
const m = {
|
|
1372
1449
|
$revertToInitialState: (t) => {
|
|
1373
|
-
const
|
|
1374
|
-
let
|
|
1375
|
-
|
|
1450
|
+
const a = p.getState().getShadowMetadata(e, []);
|
|
1451
|
+
let d;
|
|
1452
|
+
a?.stateSource === "server" && a.baseServerState ? d = a.baseServerState : d = p.getState().initialStateGlobal[e], qe(e), X(e, d), c({
|
|
1376
1453
|
path: [],
|
|
1377
1454
|
componentId: l
|
|
1378
1455
|
});
|
|
1379
|
-
const
|
|
1380
|
-
return
|
|
1456
|
+
const E = U(e), b = z(E?.localStorage?.key) ? E?.localStorage?.key(d) : E?.localStorage?.key, V = i && b ? `${i}-${e}-${b}` : void 0;
|
|
1457
|
+
return le(V), W(e), d;
|
|
1381
1458
|
},
|
|
1382
1459
|
$initializeAndMergeShadowState: (t) => {
|
|
1383
|
-
|
|
1460
|
+
ze(e, t), W(e);
|
|
1384
1461
|
},
|
|
1385
1462
|
$updateInitialState: (t) => {
|
|
1386
|
-
const
|
|
1463
|
+
const a = Ve(
|
|
1387
1464
|
e,
|
|
1388
|
-
|
|
1465
|
+
n,
|
|
1389
1466
|
l,
|
|
1390
|
-
|
|
1391
|
-
),
|
|
1392
|
-
return
|
|
1393
|
-
|
|
1394
|
-
const v =
|
|
1395
|
-
v && v?.components?.forEach((
|
|
1396
|
-
|
|
1467
|
+
i
|
|
1468
|
+
), d = p.getState().initialStateGlobal[e], E = U(e), b = z(E?.localStorage?.key) ? E?.localStorage?.key(d) : E?.localStorage?.key, V = i && b ? `${i}-${e}-${b}` : void 0;
|
|
1469
|
+
return le(V), Ie(() => {
|
|
1470
|
+
Me(e, t), X(e, t);
|
|
1471
|
+
const v = p.getState().getShadowMetadata(e, []);
|
|
1472
|
+
v && v?.components?.forEach((C) => {
|
|
1473
|
+
C.forceUpdate();
|
|
1397
1474
|
});
|
|
1398
1475
|
}), {
|
|
1399
|
-
fetchId: (v) =>
|
|
1476
|
+
fetchId: (v) => a.$get()[v]
|
|
1400
1477
|
};
|
|
1401
1478
|
}
|
|
1402
1479
|
};
|
|
@@ -1405,66 +1482,65 @@ function we(e, a, l, s) {
|
|
|
1405
1482
|
path: []
|
|
1406
1483
|
});
|
|
1407
1484
|
}
|
|
1408
|
-
function
|
|
1409
|
-
return
|
|
1485
|
+
function we(e) {
|
|
1486
|
+
return fe(gt, { proxy: e });
|
|
1410
1487
|
}
|
|
1411
|
-
function
|
|
1488
|
+
function gt({
|
|
1412
1489
|
proxy: e
|
|
1413
1490
|
}) {
|
|
1414
|
-
const
|
|
1415
|
-
return
|
|
1416
|
-
const t =
|
|
1417
|
-
if (!t ||
|
|
1418
|
-
const
|
|
1491
|
+
const n = q(null), l = q(null), i = q(!1), f = `${e._stateKey}-${e._path.join(".")}`, c = e._path.length > 0 ? e._path.join(".") : "root", m = e._meta?.arrayViews?.[c], y = D(e._stateKey, e._path, m);
|
|
1492
|
+
return x(() => {
|
|
1493
|
+
const t = n.current;
|
|
1494
|
+
if (!t || i.current) return;
|
|
1495
|
+
const a = setTimeout(() => {
|
|
1419
1496
|
if (!t.parentElement) {
|
|
1420
|
-
console.warn("Parent element not found for signal",
|
|
1497
|
+
console.warn("Parent element not found for signal", f);
|
|
1421
1498
|
return;
|
|
1422
1499
|
}
|
|
1423
|
-
const
|
|
1424
|
-
let
|
|
1425
|
-
|
|
1426
|
-
const v =
|
|
1427
|
-
|
|
1500
|
+
const d = t.parentElement, b = Array.from(d.childNodes).indexOf(t);
|
|
1501
|
+
let V = d.getAttribute("data-parent-id");
|
|
1502
|
+
V || (V = `parent-${crypto.randomUUID()}`, d.setAttribute("data-parent-id", V)), l.current = `instance-${crypto.randomUUID()}`;
|
|
1503
|
+
const v = p.getState().getShadowMetadata(e._stateKey, e._path) || {}, C = v.signals || [];
|
|
1504
|
+
C.push({
|
|
1428
1505
|
instanceId: l.current,
|
|
1429
|
-
parentId:
|
|
1430
|
-
position:
|
|
1506
|
+
parentId: V,
|
|
1507
|
+
position: b,
|
|
1431
1508
|
effect: e._effect
|
|
1432
|
-
}),
|
|
1509
|
+
}), p.getState().setShadowMetadata(e._stateKey, e._path, {
|
|
1433
1510
|
...v,
|
|
1434
|
-
signals:
|
|
1511
|
+
signals: C
|
|
1435
1512
|
});
|
|
1436
|
-
let
|
|
1513
|
+
let _ = y;
|
|
1437
1514
|
if (e._effect)
|
|
1438
1515
|
try {
|
|
1439
|
-
|
|
1516
|
+
_ = new Function(
|
|
1440
1517
|
"state",
|
|
1441
1518
|
`return (${e._effect})(state)`
|
|
1442
|
-
)(
|
|
1443
|
-
} catch (
|
|
1444
|
-
console.error("Error evaluating effect function:",
|
|
1519
|
+
)(y);
|
|
1520
|
+
} catch (G) {
|
|
1521
|
+
console.error("Error evaluating effect function:", G);
|
|
1445
1522
|
}
|
|
1446
|
-
|
|
1447
|
-
const
|
|
1448
|
-
t.replaceWith(
|
|
1523
|
+
_ !== null && typeof _ == "object" && (_ = JSON.stringify(_));
|
|
1524
|
+
const J = document.createTextNode(String(_ ?? ""));
|
|
1525
|
+
t.replaceWith(J), i.current = !0;
|
|
1449
1526
|
}, 0);
|
|
1450
1527
|
return () => {
|
|
1451
|
-
if (clearTimeout(
|
|
1452
|
-
const
|
|
1453
|
-
|
|
1454
|
-
(
|
|
1455
|
-
),
|
|
1528
|
+
if (clearTimeout(a), l.current) {
|
|
1529
|
+
const d = p.getState().getShadowMetadata(e._stateKey, e._path) || {};
|
|
1530
|
+
d.signals && (d.signals = d.signals.filter(
|
|
1531
|
+
(E) => E.instanceId !== l.current
|
|
1532
|
+
), p.getState().setShadowMetadata(e._stateKey, e._path, d));
|
|
1456
1533
|
}
|
|
1457
1534
|
};
|
|
1458
|
-
}, []),
|
|
1459
|
-
ref:
|
|
1535
|
+
}, []), fe("span", {
|
|
1536
|
+
ref: n,
|
|
1460
1537
|
style: { display: "contents" },
|
|
1461
|
-
"data-signal-id":
|
|
1538
|
+
"data-signal-id": f
|
|
1462
1539
|
});
|
|
1463
1540
|
}
|
|
1464
1541
|
export {
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
at as useCogsStateFn
|
|
1542
|
+
we as $cogsSignal,
|
|
1543
|
+
$t as createCogsState,
|
|
1544
|
+
ct as useCogsStateFn
|
|
1469
1545
|
};
|
|
1470
1546
|
//# sourceMappingURL=CogsState.js.map
|