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