cogsbox-state 0.5.488 → 0.5.490
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 +4 -4
- package/dist/CogsState.d.ts +2 -50
- package/dist/CogsState.d.ts.map +1 -1
- package/dist/CogsState.js +886 -1002
- package/dist/CogsState.js.map +1 -1
- package/dist/plugins.d.ts +4 -2
- package/dist/plugins.d.ts.map +1 -1
- package/dist/plugins.js.map +1 -1
- package/dist/store.d.ts +1 -20
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +180 -218
- package/dist/store.js.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +267 -594
- package/src/plugins.ts +23 -14
- package/src/store.ts +2 -96
package/dist/store.js
CHANGED
|
@@ -1,79 +1,79 @@
|
|
|
1
|
-
import { create as
|
|
1
|
+
import { create as z } from "zustand";
|
|
2
2
|
function A(f, o = "zod4") {
|
|
3
3
|
if (!f) return null;
|
|
4
|
-
let t = f, e = !1, n = !1, a,
|
|
4
|
+
let t = f, e = !1, n = !1, a, i = !1;
|
|
5
5
|
for (let l = 0; l < 20; l++) {
|
|
6
6
|
const d = t?.def || t?._def;
|
|
7
7
|
if (!d) break;
|
|
8
|
-
const
|
|
9
|
-
if (
|
|
8
|
+
const m = d.typeName || d.type || t._type;
|
|
9
|
+
if (m === "ZodUnion" || m === "union")
|
|
10
10
|
if (d.options && d.options.length > 0) {
|
|
11
11
|
t = d.options.find((c) => {
|
|
12
|
-
const
|
|
13
|
-
return
|
|
12
|
+
const y = c?.def || c?._def, h = y?.typeName || y?.type || c?._type;
|
|
13
|
+
return h !== "ZodNull" && h !== "null" && h !== "ZodUndefined" && h !== "undefined";
|
|
14
14
|
}) ?? d.options[0];
|
|
15
15
|
continue;
|
|
16
16
|
} else
|
|
17
17
|
break;
|
|
18
|
-
if (
|
|
18
|
+
if (m === "ZodOptional" || m === "optional")
|
|
19
19
|
n = !0;
|
|
20
|
-
else if (
|
|
20
|
+
else if (m === "ZodNullable" || m === "nullable")
|
|
21
21
|
e = !0;
|
|
22
|
-
else if (
|
|
23
|
-
|
|
24
|
-
else if (
|
|
22
|
+
else if (m === "ZodDefault" || m === "default")
|
|
23
|
+
i = !0, a = typeof d.defaultValue == "function" ? d.defaultValue() : d.defaultValue;
|
|
24
|
+
else if (m !== "ZodEffects" && m !== "effects")
|
|
25
25
|
break;
|
|
26
26
|
const b = d.innerType || d.schema || t._inner;
|
|
27
27
|
if (!b || b === t)
|
|
28
28
|
break;
|
|
29
29
|
t = b;
|
|
30
30
|
}
|
|
31
|
-
const
|
|
31
|
+
const s = t, r = s?.def || s?._def, u = r?.typeName || r?.type || s?._type;
|
|
32
32
|
return u === "ZodNumber" || u === "number" ? {
|
|
33
33
|
type: "number",
|
|
34
34
|
schema: f,
|
|
35
35
|
source: o,
|
|
36
|
-
default:
|
|
36
|
+
default: i ? a : 0,
|
|
37
37
|
nullable: e,
|
|
38
38
|
optional: n
|
|
39
39
|
} : u === "ZodString" || u === "string" ? {
|
|
40
40
|
type: "string",
|
|
41
41
|
schema: f,
|
|
42
42
|
source: o,
|
|
43
|
-
default:
|
|
43
|
+
default: i ? a : "",
|
|
44
44
|
nullable: e,
|
|
45
45
|
optional: n
|
|
46
46
|
} : u === "ZodBoolean" || u === "boolean" ? {
|
|
47
47
|
type: "boolean",
|
|
48
48
|
schema: f,
|
|
49
49
|
source: o,
|
|
50
|
-
default:
|
|
50
|
+
default: i ? a : !1,
|
|
51
51
|
nullable: e,
|
|
52
52
|
optional: n
|
|
53
53
|
} : u === "ZodArray" || u === "array" ? {
|
|
54
54
|
type: "array",
|
|
55
55
|
schema: f,
|
|
56
56
|
source: o,
|
|
57
|
-
default:
|
|
57
|
+
default: i ? a : [],
|
|
58
58
|
nullable: e,
|
|
59
59
|
optional: n
|
|
60
60
|
} : u === "ZodObject" || u === "object" ? {
|
|
61
61
|
type: "object",
|
|
62
62
|
schema: f,
|
|
63
63
|
source: o,
|
|
64
|
-
default:
|
|
64
|
+
default: i ? a : {},
|
|
65
65
|
nullable: e,
|
|
66
66
|
optional: n
|
|
67
67
|
} : u === "ZodDate" || u === "date" ? {
|
|
68
68
|
type: "date",
|
|
69
69
|
schema: f,
|
|
70
70
|
source: o,
|
|
71
|
-
default:
|
|
71
|
+
default: i ? a : /* @__PURE__ */ new Date(),
|
|
72
72
|
nullable: e,
|
|
73
73
|
optional: n
|
|
74
74
|
} : null;
|
|
75
75
|
}
|
|
76
|
-
function
|
|
76
|
+
function j(f) {
|
|
77
77
|
if (f === null)
|
|
78
78
|
return {
|
|
79
79
|
type: "unknown",
|
|
@@ -96,21 +96,21 @@ function O(f) {
|
|
|
96
96
|
function g(f, o, t) {
|
|
97
97
|
if (o == null || typeof o != "object") {
|
|
98
98
|
const e = { _meta: { value: o } };
|
|
99
|
-
return e._meta.typeInfo =
|
|
99
|
+
return e._meta.typeInfo = O(o, t), e;
|
|
100
100
|
}
|
|
101
101
|
if (Array.isArray(o)) {
|
|
102
102
|
const e = { _meta: { arrayKeys: [] } };
|
|
103
|
-
return e._meta.typeInfo =
|
|
104
|
-
const
|
|
103
|
+
return e._meta.typeInfo = O(o, t), o.forEach((n, a) => {
|
|
104
|
+
const i = I(), s = t ? {
|
|
105
105
|
...t,
|
|
106
106
|
path: [...t.path, a.toString()]
|
|
107
107
|
} : void 0;
|
|
108
|
-
e[
|
|
108
|
+
e[i] = g(f, n, s), e._meta.arrayKeys.push(i);
|
|
109
109
|
}), e;
|
|
110
110
|
}
|
|
111
111
|
if (o.constructor === Object) {
|
|
112
112
|
const e = { _meta: {} };
|
|
113
|
-
e._meta.typeInfo =
|
|
113
|
+
e._meta.typeInfo = O(o, t);
|
|
114
114
|
for (const n in o)
|
|
115
115
|
if (Object.prototype.hasOwnProperty.call(o, n)) {
|
|
116
116
|
const a = t ? {
|
|
@@ -124,47 +124,47 @@ function g(f, o, t) {
|
|
|
124
124
|
return {
|
|
125
125
|
_meta: {
|
|
126
126
|
value: o,
|
|
127
|
-
typeInfo:
|
|
127
|
+
typeInfo: j(o)
|
|
128
128
|
}
|
|
129
129
|
};
|
|
130
130
|
}
|
|
131
|
-
function
|
|
131
|
+
function O(f, o) {
|
|
132
132
|
if (o) {
|
|
133
133
|
let t = null;
|
|
134
134
|
if (o.schemas.zodV4) {
|
|
135
|
-
const e = o.path.length === 0 ? o.schemas.zodV4 :
|
|
135
|
+
const e = o.path.length === 0 ? o.schemas.zodV4 : v(o.schemas.zodV4, o.path);
|
|
136
136
|
e && (t = A(e, "zod4"));
|
|
137
137
|
}
|
|
138
138
|
if (!t && o.schemas.zodV3) {
|
|
139
|
-
const e = o.path.length === 0 ? o.schemas.zodV3 :
|
|
139
|
+
const e = o.path.length === 0 ? o.schemas.zodV3 : v(o.schemas.zodV3, o.path);
|
|
140
140
|
e && (t = A(e, "zod3"));
|
|
141
141
|
}
|
|
142
|
-
if (!t && o.schemas.sync?.[o.stateKey] && (t =
|
|
142
|
+
if (!t && o.schemas.sync?.[o.stateKey] && (t = j(f), t.source = "sync"), t) return t;
|
|
143
143
|
}
|
|
144
|
-
return
|
|
144
|
+
return j(f);
|
|
145
145
|
}
|
|
146
146
|
function w(f, o, t) {
|
|
147
147
|
const e = S.get(f) || S.get(`[${f}`);
|
|
148
148
|
if (!e) return;
|
|
149
|
-
function n(a,
|
|
149
|
+
function n(a, i) {
|
|
150
150
|
if (!a || typeof a != "object") return;
|
|
151
|
-
const
|
|
152
|
-
if (
|
|
153
|
-
const r = A(
|
|
151
|
+
const s = v(o, i);
|
|
152
|
+
if (s) {
|
|
153
|
+
const r = A(s, t);
|
|
154
154
|
r && (a._meta || (a._meta = {}), a._meta.typeInfo = {
|
|
155
155
|
...r,
|
|
156
|
-
schema:
|
|
156
|
+
schema: s
|
|
157
157
|
});
|
|
158
158
|
}
|
|
159
159
|
a._meta?.arrayKeys ? a._meta.arrayKeys.forEach((r) => {
|
|
160
|
-
a[r] && n(a[r], [...
|
|
160
|
+
a[r] && n(a[r], [...i, "0"]);
|
|
161
161
|
}) : a._meta?.hasOwnProperty("value") || Object.keys(a).forEach((r) => {
|
|
162
|
-
r !== "_meta" && n(a[r], [...
|
|
162
|
+
r !== "_meta" && n(a[r], [...i, r]);
|
|
163
163
|
});
|
|
164
164
|
}
|
|
165
165
|
n(e, []);
|
|
166
166
|
}
|
|
167
|
-
function
|
|
167
|
+
function N(f) {
|
|
168
168
|
let o = f;
|
|
169
169
|
for (; o; ) {
|
|
170
170
|
const t = o.def || o._def, e = t?.typeName || t?.type || o._type;
|
|
@@ -175,18 +175,18 @@ function z(f) {
|
|
|
175
175
|
}
|
|
176
176
|
return o;
|
|
177
177
|
}
|
|
178
|
-
function
|
|
178
|
+
function v(f, o) {
|
|
179
179
|
if (!f) return null;
|
|
180
180
|
if (o.length === 0) return f;
|
|
181
181
|
let t = f;
|
|
182
182
|
for (const e of o) {
|
|
183
|
-
const n =
|
|
183
|
+
const n = N(t);
|
|
184
184
|
if (!n) return null;
|
|
185
|
-
const a = n.def || n._def,
|
|
186
|
-
if (
|
|
187
|
-
const
|
|
188
|
-
t = (typeof
|
|
189
|
-
} else if (
|
|
185
|
+
const a = n.def || n._def, i = a?.typeName || a?.type || n._type;
|
|
186
|
+
if (i === "ZodObject" || i === "object") {
|
|
187
|
+
const s = a?.shape ?? n.shape ?? n._shape;
|
|
188
|
+
t = (typeof s == "function" ? s() : s)?.[e];
|
|
189
|
+
} else if (i === "ZodArray" || i === "array")
|
|
190
190
|
t = n.element || a?.type;
|
|
191
191
|
else
|
|
192
192
|
return null;
|
|
@@ -201,82 +201,79 @@ const V = Date.now().toString(36);
|
|
|
201
201
|
function I(f) {
|
|
202
202
|
return `id:local_${V}_${(K++).toString(36)}`;
|
|
203
203
|
}
|
|
204
|
-
const C =
|
|
204
|
+
const C = z((f, o) => ({
|
|
205
205
|
getPluginMetaDataMap: (t, e) => o().getShadowMetadata(t, e)?.pluginMetaData,
|
|
206
206
|
setPluginMetaData: (t, e, n, a) => {
|
|
207
|
-
const
|
|
208
|
-
|
|
207
|
+
const i = o().getShadowMetadata(t, e) || {}, s = new Map(i.pluginMetaData || []), r = s.get(n) || {};
|
|
208
|
+
s.set(n, { ...r, ...a }), o().setShadowMetadata(t, e, { ...i, pluginMetaData: s }), o().notifyPathSubscribers([t, ...e].join("."), {
|
|
209
209
|
type: "METADATA_UPDATE"
|
|
210
210
|
});
|
|
211
211
|
},
|
|
212
212
|
removePluginMetaData: (t, e, n) => {
|
|
213
213
|
const a = o().getShadowMetadata(t, e);
|
|
214
214
|
if (!a?.pluginMetaData) return;
|
|
215
|
-
const
|
|
216
|
-
|
|
215
|
+
const i = new Map(a.pluginMetaData);
|
|
216
|
+
i.delete(n), o().setShadowMetadata(t, e, { ...a, pluginMetaData: i });
|
|
217
217
|
},
|
|
218
218
|
setTransformCache: (t, e, n, a) => {
|
|
219
|
-
const
|
|
220
|
-
|
|
221
|
-
transformCaches:
|
|
219
|
+
const i = o().getShadowMetadata(t, e) || {};
|
|
220
|
+
i.transformCaches || (i.transformCaches = /* @__PURE__ */ new Map()), i.transformCaches.set(n, a), o().setShadowMetadata(t, e, {
|
|
221
|
+
transformCaches: i.transformCaches
|
|
222
222
|
});
|
|
223
223
|
},
|
|
224
224
|
// Replace your entire `initializeAndMergeShadowState` function with this one.
|
|
225
225
|
initializeAndMergeShadowState: (t, e) => {
|
|
226
|
-
const a = e?._meta?.arrayKeys !== void 0 ? `[${t}` : t,
|
|
227
|
-
let
|
|
228
|
-
if (
|
|
226
|
+
const a = e?._meta?.arrayKeys !== void 0 ? `[${t}` : t, i = S.get(a) || S.get(t) || S.get(`[${t}`);
|
|
227
|
+
let s = {};
|
|
228
|
+
if (i?._meta) {
|
|
229
229
|
const {
|
|
230
230
|
components: d,
|
|
231
|
-
features:
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
validation: _
|
|
238
|
-
} = s._meta;
|
|
239
|
-
d && (i.components = d), y && (i.features = y), b && (i.lastServerSync = b), p && (i.stateSource = p), c && (i.baseServerState = c), h && (i.pathComponents = h), m && (i.signals = m), _ && (i.validation = _);
|
|
231
|
+
features: m,
|
|
232
|
+
pathComponents: b,
|
|
233
|
+
signals: p,
|
|
234
|
+
validation: c
|
|
235
|
+
} = i._meta;
|
|
236
|
+
d && (s.components = d), m && (s.features = m), b && (s.pathComponents = b), p && (s.signals = p), c && (s.validation = c);
|
|
240
237
|
}
|
|
241
|
-
function r(d,
|
|
242
|
-
if (
|
|
243
|
-
const c = d._meta || {},
|
|
244
|
-
c.typeInfo?.schema && !
|
|
238
|
+
function r(d, m) {
|
|
239
|
+
if (m._meta || d._meta) {
|
|
240
|
+
const c = d._meta || {}, y = m._meta || {}, h = { ...c, ...y };
|
|
241
|
+
c.typeInfo?.schema && !y.typeInfo?.schema && (h.typeInfo = c.typeInfo), c.validation && !y.validation && (h.validation = c.validation), c.components && (h.components = c.components), c.clientActivityState && !y.clientActivityState && (h.clientActivityState = c.clientActivityState), c.pluginMetaData && !y.pluginMetaData && (h.pluginMetaData = c.pluginMetaData), d._meta = h;
|
|
245
242
|
}
|
|
246
|
-
if (
|
|
243
|
+
if (m._meta?.hasOwnProperty("value")) {
|
|
247
244
|
for (const c in d)
|
|
248
245
|
c !== "_meta" && delete d[c];
|
|
249
246
|
return;
|
|
250
247
|
}
|
|
251
248
|
const b = new Set(
|
|
252
|
-
Object.keys(
|
|
249
|
+
Object.keys(m).filter((c) => c !== "_meta")
|
|
253
250
|
), p = new Set(
|
|
254
251
|
Object.keys(d).filter((c) => c !== "_meta")
|
|
255
252
|
);
|
|
256
253
|
for (const c of p)
|
|
257
254
|
b.has(c) || delete d[c];
|
|
258
255
|
for (const c of b) {
|
|
259
|
-
const
|
|
260
|
-
|
|
256
|
+
const y = m[c], h = d[c];
|
|
257
|
+
h && typeof h == "object" && y && typeof y == "object" ? r(h, y) : d[c] = y;
|
|
261
258
|
}
|
|
262
259
|
}
|
|
263
|
-
|
|
260
|
+
i ? (r(i, e), i._meta || (i._meta = {}), Object.assign(i._meta, s), S.set(a, i)) : (s && Object.keys(s).length > 0 && (e._meta || (e._meta = {}), Object.assign(e._meta, s)), S.set(a, e));
|
|
264
261
|
const u = o().getInitialOptions(t);
|
|
265
262
|
(u?.validation?.zodSchemaV4 || u?.validation?.zodSchemaV3) && (u.validation?.zodSchemaV4 ? w(t, u.validation.zodSchemaV4, "zod4") : u.validation?.zodSchemaV3 && w(t, u.validation.zodSchemaV3, "zod3")), a === t ? S.delete(`[${t}`) : S.delete(t);
|
|
266
263
|
},
|
|
267
264
|
initializeShadowState: (t, e) => {
|
|
268
265
|
const n = S.get(t) || S.get(`[${t}`);
|
|
269
266
|
let a = {};
|
|
270
|
-
const
|
|
267
|
+
const i = /* @__PURE__ */ new Map();
|
|
271
268
|
if (n) {
|
|
272
|
-
const p = (c,
|
|
269
|
+
const p = (c, y) => {
|
|
273
270
|
if (!(!c || typeof c != "object")) {
|
|
274
|
-
(c._meta?.clientActivityState || c._meta?.pluginMetaData) &&
|
|
271
|
+
(c._meta?.clientActivityState || c._meta?.pluginMetaData) && i.set(y.join("\0"), {
|
|
275
272
|
clientActivityState: c._meta.clientActivityState,
|
|
276
273
|
pluginMetaData: c._meta.pluginMetaData
|
|
277
274
|
});
|
|
278
|
-
for (const
|
|
279
|
-
|
|
275
|
+
for (const h in c)
|
|
276
|
+
h !== "_meta" && p(c[h], [...y, h]);
|
|
280
277
|
}
|
|
281
278
|
};
|
|
282
279
|
p(n, []);
|
|
@@ -284,34 +281,31 @@ const C = N((f, o) => ({
|
|
|
284
281
|
if (n?._meta) {
|
|
285
282
|
const {
|
|
286
283
|
components: p,
|
|
287
|
-
features: c
|
|
288
|
-
lastServerSync: h,
|
|
289
|
-
stateSource: m,
|
|
290
|
-
baseServerState: _
|
|
284
|
+
features: c
|
|
291
285
|
} = n._meta;
|
|
292
|
-
p && (a.components = p), c && (a.features = c)
|
|
286
|
+
p && (a.components = p), c && (a.features = c);
|
|
293
287
|
}
|
|
294
288
|
S.delete(t), S.delete(`[${t}`);
|
|
295
|
-
const
|
|
289
|
+
const s = o().getInitialOptions(t), r = o().getInitialOptions("__syncSchemas"), u = {
|
|
296
290
|
stateKey: t,
|
|
297
291
|
path: [],
|
|
298
292
|
schemas: {
|
|
299
293
|
sync: r,
|
|
300
|
-
zodV4:
|
|
301
|
-
zodV3:
|
|
294
|
+
zodV4: s?.validation?.zodSchemaV4,
|
|
295
|
+
zodV3: s?.validation?.zodSchemaV3
|
|
302
296
|
}
|
|
303
297
|
}, l = g(t, e, u);
|
|
304
298
|
l._meta || (l._meta = {}), Object.assign(l._meta, a);
|
|
305
299
|
const d = (p, c) => {
|
|
306
300
|
if (!p || typeof p != "object") return;
|
|
307
|
-
const
|
|
308
|
-
|
|
301
|
+
const y = c.join("\0"), h = i.get(y);
|
|
302
|
+
h && (p._meta || (p._meta = {}), h.clientActivityState && (p._meta.clientActivityState = h.clientActivityState), h.pluginMetaData && (p._meta.pluginMetaData = h.pluginMetaData));
|
|
309
303
|
for (const _ in p)
|
|
310
304
|
_ !== "_meta" && d(p[_], [...c, _]);
|
|
311
305
|
};
|
|
312
306
|
d(l, []);
|
|
313
|
-
const
|
|
314
|
-
S.set(
|
|
307
|
+
const m = Array.isArray(e) ? `[${t}` : t;
|
|
308
|
+
S.set(m, l);
|
|
315
309
|
const b = o().getInitialOptions(t);
|
|
316
310
|
b?.validation?.zodSchemaV4 ? w(t, b.validation.zodSchemaV4, "zod4") : b?.validation?.zodSchemaV3 && w(t, b.validation.zodSchemaV3, "zod3");
|
|
317
311
|
},
|
|
@@ -327,25 +321,25 @@ const C = N((f, o) => ({
|
|
|
327
321
|
getShadowMetadata: (t, e) => o().getShadowNode(t, e)?._meta,
|
|
328
322
|
setShadowMetadata: (t, e, n) => {
|
|
329
323
|
const a = S.has(`[${t}`) ? `[${t}` : t;
|
|
330
|
-
let
|
|
331
|
-
if (!
|
|
332
|
-
|
|
324
|
+
let i = S.get(a);
|
|
325
|
+
if (!i) {
|
|
326
|
+
i = { _meta: n }, S.set(a, i);
|
|
333
327
|
return;
|
|
334
328
|
}
|
|
335
|
-
let
|
|
329
|
+
let s = i;
|
|
336
330
|
for (const r of e)
|
|
337
|
-
|
|
338
|
-
|
|
331
|
+
s[r] || (s[r] = {}), s = s[r];
|
|
332
|
+
s._meta || (s._meta = {}), Object.assign(s._meta, n);
|
|
339
333
|
},
|
|
340
334
|
getShadowValue: (t, e, n) => {
|
|
341
335
|
const a = o().getShadowNode(t, e);
|
|
342
336
|
if (!a)
|
|
343
337
|
return;
|
|
344
|
-
const
|
|
345
|
-
[a,
|
|
338
|
+
const i = {}, s = [
|
|
339
|
+
[a, i, "final"]
|
|
346
340
|
];
|
|
347
|
-
for (;
|
|
348
|
-
const [r, u, l] =
|
|
341
|
+
for (; s.length > 0; ) {
|
|
342
|
+
const [r, u, l] = s.pop();
|
|
349
343
|
if (r._meta?.hasOwnProperty("value")) {
|
|
350
344
|
u[l] = r._meta.value;
|
|
351
345
|
continue;
|
|
@@ -354,28 +348,28 @@ const C = N((f, o) => ({
|
|
|
354
348
|
const b = n || r._meta.arrayKeys, p = [];
|
|
355
349
|
u[l] = p;
|
|
356
350
|
for (let c = b.length - 1; c >= 0; c--) {
|
|
357
|
-
const
|
|
358
|
-
r[
|
|
351
|
+
const y = b[c];
|
|
352
|
+
r[y] && s.push([r[y], p, c]);
|
|
359
353
|
}
|
|
360
354
|
continue;
|
|
361
355
|
}
|
|
362
356
|
const d = {};
|
|
363
357
|
u[l] = d;
|
|
364
|
-
const
|
|
365
|
-
for (const b of
|
|
366
|
-
b !== "_meta" &&
|
|
358
|
+
const m = Object.keys(r);
|
|
359
|
+
for (const b of m)
|
|
360
|
+
b !== "_meta" && s.push([r[b], d, b]);
|
|
367
361
|
}
|
|
368
|
-
return
|
|
362
|
+
return i.final;
|
|
369
363
|
},
|
|
370
364
|
updateShadowAtPath: (t, e, n) => {
|
|
371
365
|
const a = S.has(`[${t}`) ? `[${t}` : t;
|
|
372
|
-
let
|
|
373
|
-
if (!
|
|
374
|
-
let
|
|
366
|
+
let i = S.get(a);
|
|
367
|
+
if (!i) return;
|
|
368
|
+
let s = i;
|
|
375
369
|
for (let l = 0; l < e.length - 1; l++)
|
|
376
|
-
|
|
377
|
-
const r = e.length === 0 ?
|
|
378
|
-
function u(l, d,
|
|
370
|
+
s[e[l]] || (s[e[l]] = {}), s = s[e[l]];
|
|
371
|
+
const r = e.length === 0 ? s : s[e[e.length - 1]];
|
|
372
|
+
function u(l, d, m) {
|
|
379
373
|
if (typeof d != "object" || d === null || d instanceof Date) {
|
|
380
374
|
const p = l._meta || {};
|
|
381
375
|
for (const c in l)
|
|
@@ -385,35 +379,35 @@ const C = N((f, o) => ({
|
|
|
385
379
|
}
|
|
386
380
|
if (Array.isArray(d)) {
|
|
387
381
|
l._meta || (l._meta = {}), l._meta.arrayKeys || (l._meta.arrayKeys = []);
|
|
388
|
-
const p = l._meta.arrayKeys, c = d,
|
|
389
|
-
for (let
|
|
390
|
-
const _ = c[
|
|
391
|
-
if (
|
|
392
|
-
const M = p[
|
|
382
|
+
const p = l._meta.arrayKeys, c = d, y = [];
|
|
383
|
+
for (let h = 0; h < c.length; h++) {
|
|
384
|
+
const _ = c[h];
|
|
385
|
+
if (h < p.length) {
|
|
386
|
+
const M = p[h];
|
|
393
387
|
u(l[M], _, [
|
|
394
|
-
...
|
|
388
|
+
...m,
|
|
395
389
|
M
|
|
396
|
-
]),
|
|
390
|
+
]), y.push(M);
|
|
397
391
|
} else {
|
|
398
|
-
const M = I(),
|
|
392
|
+
const M = I(), E = o().getInitialOptions(t), D = {
|
|
399
393
|
stateKey: t,
|
|
400
|
-
path: [...
|
|
394
|
+
path: [...m, "0"],
|
|
401
395
|
// Use '0' for array element schema lookup
|
|
402
396
|
schemas: {
|
|
403
|
-
zodV4:
|
|
404
|
-
zodV3:
|
|
397
|
+
zodV4: E?.validation?.zodSchemaV4,
|
|
398
|
+
zodV3: E?.validation?.zodSchemaV3
|
|
405
399
|
}
|
|
406
400
|
};
|
|
407
401
|
l[M] = g(
|
|
408
402
|
t,
|
|
409
403
|
_,
|
|
410
|
-
|
|
411
|
-
),
|
|
404
|
+
D
|
|
405
|
+
), y.push(M);
|
|
412
406
|
}
|
|
413
407
|
}
|
|
414
408
|
p.length > c.length && p.slice(c.length).forEach((_) => {
|
|
415
409
|
delete l[_];
|
|
416
|
-
}), l._meta.arrayKeys =
|
|
410
|
+
}), l._meta.arrayKeys = y;
|
|
417
411
|
return;
|
|
418
412
|
}
|
|
419
413
|
const b = new Set(Object.keys(d));
|
|
@@ -422,50 +416,50 @@ const C = N((f, o) => ({
|
|
|
422
416
|
const c = d[p];
|
|
423
417
|
if (l[p])
|
|
424
418
|
u(l[p], c, [
|
|
425
|
-
...
|
|
419
|
+
...m,
|
|
426
420
|
p
|
|
427
421
|
]);
|
|
428
422
|
else {
|
|
429
|
-
const
|
|
423
|
+
const y = o().getInitialOptions(t), h = {
|
|
430
424
|
stateKey: t,
|
|
431
|
-
path: [...
|
|
425
|
+
path: [...m, p],
|
|
432
426
|
schemas: {
|
|
433
|
-
zodV4:
|
|
434
|
-
zodV3:
|
|
427
|
+
zodV4: y?.validation?.zodSchemaV4,
|
|
428
|
+
zodV3: y?.validation?.zodSchemaV3
|
|
435
429
|
}
|
|
436
430
|
};
|
|
437
|
-
l[p] = g(t, c,
|
|
431
|
+
l[p] = g(t, c, h);
|
|
438
432
|
}
|
|
439
433
|
}
|
|
440
434
|
for (const p in l)
|
|
441
435
|
p === "_meta" || !Object.prototype.hasOwnProperty.call(l, p) || b.has(p) || delete l[p];
|
|
442
436
|
}
|
|
443
|
-
r ? u(r, n, e) :
|
|
437
|
+
r ? u(r, n, e) : s[e[e.length - 1]] = g(t, n), o().notifyPathSubscribers([t, ...e].join("."), {
|
|
444
438
|
type: "UPDATE",
|
|
445
439
|
newValue: n
|
|
446
440
|
});
|
|
447
441
|
},
|
|
448
442
|
addItemsToArrayNode: (t, e, n) => {
|
|
449
443
|
const a = S.has(`[${t}`) ? `[${t}` : t;
|
|
450
|
-
let
|
|
451
|
-
if (!
|
|
444
|
+
let i = S.get(a);
|
|
445
|
+
if (!i) {
|
|
452
446
|
console.error("Root not found for state key:", t);
|
|
453
447
|
return;
|
|
454
448
|
}
|
|
455
|
-
let
|
|
449
|
+
let s = i;
|
|
456
450
|
for (const r of e)
|
|
457
|
-
|
|
458
|
-
Object.assign(
|
|
451
|
+
s[r] || (s[r] = {}), s = s[r];
|
|
452
|
+
Object.assign(s, n);
|
|
459
453
|
},
|
|
460
|
-
insertShadowArrayElement: (t, e, n, a,
|
|
461
|
-
const
|
|
462
|
-
if (!
|
|
454
|
+
insertShadowArrayElement: (t, e, n, a, i) => {
|
|
455
|
+
const s = o().getShadowNode(t, e);
|
|
456
|
+
if (!s?._meta?.arrayKeys)
|
|
463
457
|
throw new Error(
|
|
464
458
|
`Array not found at path: ${[t, ...e].join(".")}`
|
|
465
459
|
);
|
|
466
|
-
const r =
|
|
467
|
-
|
|
468
|
-
const u =
|
|
460
|
+
const r = i || `${I()}`;
|
|
461
|
+
s[r] = g(t, n);
|
|
462
|
+
const u = s._meta.arrayKeys, l = a !== void 0 && a >= 0 && a <= u.length ? a : u.length;
|
|
469
463
|
l >= u.length ? u.push(r) : u.splice(l, 0, r);
|
|
470
464
|
const d = [t, ...e].join(".");
|
|
471
465
|
return o().notifyPathSubscribers(d, {
|
|
@@ -478,20 +472,20 @@ const C = N((f, o) => ({
|
|
|
478
472
|
insertManyShadowArrayElements: (t, e, n, a) => {
|
|
479
473
|
if (!n || n.length === 0)
|
|
480
474
|
return;
|
|
481
|
-
const
|
|
482
|
-
if (!
|
|
475
|
+
const i = o().getShadowNode(t, e);
|
|
476
|
+
if (!i?._meta?.arrayKeys) {
|
|
483
477
|
console.error(
|
|
484
478
|
`Array not found at path: ${[t, ...e].join(".")}`
|
|
485
479
|
);
|
|
486
480
|
return;
|
|
487
481
|
}
|
|
488
|
-
const
|
|
482
|
+
const s = [];
|
|
489
483
|
n.forEach((d) => {
|
|
490
|
-
const
|
|
491
|
-
|
|
484
|
+
const m = `${I()}`;
|
|
485
|
+
s.push(m), i[m] = g(t, d);
|
|
492
486
|
});
|
|
493
|
-
const r =
|
|
494
|
-
u >= r.length ? r.push(...
|
|
487
|
+
const r = i._meta.arrayKeys, u = a !== void 0 && a >= 0 && a <= r.length ? a : r.length;
|
|
488
|
+
u >= r.length ? r.push(...s) : r.splice(u, 0, ...s);
|
|
495
489
|
const l = [t, ...e].join(".");
|
|
496
490
|
o().notifyPathSubscribers(l, {
|
|
497
491
|
type: "INSERT_MANY",
|
|
@@ -504,11 +498,11 @@ const C = N((f, o) => ({
|
|
|
504
498
|
if (e.length === 0) return;
|
|
505
499
|
const n = e.slice(0, -1), a = e[e.length - 1];
|
|
506
500
|
if (!a?.startsWith("id:")) return;
|
|
507
|
-
const
|
|
508
|
-
if (!
|
|
509
|
-
const
|
|
501
|
+
const i = o().getShadowNode(t, n);
|
|
502
|
+
if (!i?._meta?.arrayKeys) return;
|
|
503
|
+
const s = i._meta.arrayKeys, r = s.indexOf(a);
|
|
510
504
|
if (r === -1) return;
|
|
511
|
-
r ===
|
|
505
|
+
r === s.length - 1 ? s.pop() : r === 0 ? s.shift() : s.splice(r, 1), delete i[a];
|
|
512
506
|
const u = [t, ...n].join(".");
|
|
513
507
|
o().notifyPathSubscribers(u, {
|
|
514
508
|
type: "REMOVE",
|
|
@@ -517,8 +511,8 @@ const C = N((f, o) => ({
|
|
|
517
511
|
});
|
|
518
512
|
},
|
|
519
513
|
registerComponent: (t, e, n) => {
|
|
520
|
-
const a = o().getShadowMetadata(t, []) || {},
|
|
521
|
-
|
|
514
|
+
const a = o().getShadowMetadata(t, []) || {}, i = new Map(a.components);
|
|
515
|
+
i.set(e, n), o().setShadowMetadata(t, [], { components: i });
|
|
522
516
|
},
|
|
523
517
|
unregisterComponent: (t, e) => {
|
|
524
518
|
const n = o().getShadowMetadata(t, []);
|
|
@@ -527,59 +521,32 @@ const C = N((f, o) => ({
|
|
|
527
521
|
a.delete(e) && o().setShadowMetadata(t, [], { components: a });
|
|
528
522
|
},
|
|
529
523
|
addPathComponent: (t, e, n) => {
|
|
530
|
-
const a = o().getShadowMetadata(t, e) || {},
|
|
531
|
-
|
|
532
|
-
pathComponents:
|
|
524
|
+
const a = o().getShadowMetadata(t, e) || {}, i = new Set(a.pathComponents);
|
|
525
|
+
i.add(n), o().setShadowMetadata(t, e, {
|
|
526
|
+
pathComponents: i
|
|
533
527
|
});
|
|
534
|
-
const
|
|
535
|
-
if (
|
|
536
|
-
const r =
|
|
528
|
+
const s = o().getShadowMetadata(t, []);
|
|
529
|
+
if (s?.components) {
|
|
530
|
+
const r = s.components.get(n);
|
|
537
531
|
if (r) {
|
|
538
532
|
const u = [t, ...e].join("."), l = new Set(r.paths);
|
|
539
533
|
l.add(u);
|
|
540
|
-
const d = { ...r, paths: l },
|
|
541
|
-
|
|
534
|
+
const d = { ...r, paths: l }, m = new Map(s.components);
|
|
535
|
+
m.set(n, d), o().setShadowMetadata(t, [], { components: m });
|
|
542
536
|
}
|
|
543
537
|
}
|
|
544
538
|
},
|
|
545
|
-
markAsDirty: (t, e, n = { bubble: !0 }) => {
|
|
546
|
-
let a = o().getShadowNode(t, []);
|
|
547
|
-
if (!a) return;
|
|
548
|
-
let s = a;
|
|
549
|
-
for (const r of e)
|
|
550
|
-
if (s = s[r], !s) return;
|
|
551
|
-
if (s._meta || (s._meta = {}), s._meta.isDirty = !0, !n.bubble) return;
|
|
552
|
-
let i = a;
|
|
553
|
-
for (let r = 0; r < e.length; r++) {
|
|
554
|
-
if (i._meta?.isDirty)
|
|
555
|
-
return;
|
|
556
|
-
i._meta || (i._meta = {}), i._meta.isDirty = !0, i = i[e[r]];
|
|
557
|
-
}
|
|
558
|
-
},
|
|
559
|
-
// Keep these in Zustand as they need React reactivity
|
|
560
|
-
serverStateUpdates: /* @__PURE__ */ new Map(),
|
|
561
|
-
setServerStateUpdate: (t, e) => {
|
|
562
|
-
f((n) => ({
|
|
563
|
-
serverStateUpdates: new Map(n.serverStateUpdates).set(
|
|
564
|
-
t,
|
|
565
|
-
e
|
|
566
|
-
)
|
|
567
|
-
})), o().notifyPathSubscribers(t, {
|
|
568
|
-
type: "SERVER_STATE_UPDATE",
|
|
569
|
-
serverState: e
|
|
570
|
-
});
|
|
571
|
-
},
|
|
572
539
|
pathSubscribers: /* @__PURE__ */ new Map(),
|
|
573
540
|
subscribeToPath: (t, e) => {
|
|
574
541
|
const n = o().pathSubscribers, a = n.get(t) || /* @__PURE__ */ new Set();
|
|
575
542
|
return a.add(e), n.set(t, a), () => {
|
|
576
|
-
const
|
|
577
|
-
|
|
543
|
+
const i = o().pathSubscribers.get(t);
|
|
544
|
+
i && (i.delete(e), i.size === 0 && o().pathSubscribers.delete(t));
|
|
578
545
|
};
|
|
579
546
|
},
|
|
580
547
|
notifyPathSubscribers: (t, e) => {
|
|
581
548
|
const a = o().pathSubscribers.get(t);
|
|
582
|
-
a && a.forEach((
|
|
549
|
+
a && a.forEach((i) => i(e));
|
|
583
550
|
},
|
|
584
551
|
selectedIndicesMap: /* @__PURE__ */ new Map(),
|
|
585
552
|
getSelectedIndex: (t, e) => {
|
|
@@ -588,8 +555,8 @@ const C = N((f, o) => ({
|
|
|
588
555
|
const a = o().getShadowMetadata(
|
|
589
556
|
t.split(".")[0],
|
|
590
557
|
t.split(".").slice(1)
|
|
591
|
-
),
|
|
592
|
-
return
|
|
558
|
+
), i = e || a?.arrayKeys;
|
|
559
|
+
return i ? i.indexOf(n) : -1;
|
|
593
560
|
},
|
|
594
561
|
setSelectedIndex: (t, e) => {
|
|
595
562
|
f((n) => {
|
|
@@ -619,8 +586,8 @@ const C = N((f, o) => ({
|
|
|
619
586
|
f((e) => {
|
|
620
587
|
const n = new Map(e.selectedIndicesMap);
|
|
621
588
|
let a = !1;
|
|
622
|
-
for (const
|
|
623
|
-
(
|
|
589
|
+
for (const i of n.keys())
|
|
590
|
+
(i === t || i.startsWith(t + ".")) && (n.delete(i), a = !0);
|
|
624
591
|
return a ? { selectedIndicesMap: n } : {};
|
|
625
592
|
});
|
|
626
593
|
},
|
|
@@ -630,15 +597,15 @@ const C = N((f, o) => ({
|
|
|
630
597
|
addStateLog: (t) => {
|
|
631
598
|
!t || t.length === 0 || f((e) => {
|
|
632
599
|
const n = new Map(e.stateLog), a = /* @__PURE__ */ new Map();
|
|
633
|
-
for (const
|
|
634
|
-
const
|
|
635
|
-
|
|
600
|
+
for (const i of t) {
|
|
601
|
+
const s = a.get(i.stateKey) || [];
|
|
602
|
+
s.push(i), a.set(i.stateKey, s);
|
|
636
603
|
}
|
|
637
|
-
for (const [
|
|
638
|
-
const r = new Map(n.get(
|
|
639
|
-
for (const u of
|
|
604
|
+
for (const [i, s] of a.entries()) {
|
|
605
|
+
const r = new Map(n.get(i));
|
|
606
|
+
for (const u of s)
|
|
640
607
|
r.set(JSON.stringify(u.path), { ...u });
|
|
641
|
-
n.set(
|
|
608
|
+
n.set(i, r);
|
|
642
609
|
}
|
|
643
610
|
return { stateLog: n };
|
|
644
611
|
});
|
|
@@ -653,13 +620,8 @@ const C = N((f, o) => ({
|
|
|
653
620
|
f((n) => ({
|
|
654
621
|
initialStateGlobal: { ...n.initialStateGlobal, [t]: e }
|
|
655
622
|
}));
|
|
656
|
-
}
|
|
657
|
-
|
|
658
|
-
setSyncInfo: (t, e) => f((n) => {
|
|
659
|
-
const a = new Map(n.syncInfoStore);
|
|
660
|
-
return a.set(t, e), { syncInfoStore: a };
|
|
661
|
-
}),
|
|
662
|
-
getSyncInfo: (t) => o().syncInfoStore.get(t) || null
|
|
623
|
+
}
|
|
624
|
+
// Removed: syncInfo is now owned by Shape Plugin
|
|
663
625
|
}));
|
|
664
626
|
function P(f) {
|
|
665
627
|
const o = [], t = S.get(f) || S.get(`[${f}`);
|
|
@@ -675,14 +637,14 @@ function P(f) {
|
|
|
675
637
|
};
|
|
676
638
|
return e(t), o;
|
|
677
639
|
}
|
|
678
|
-
function
|
|
640
|
+
function Z(f, o) {
|
|
679
641
|
const t = S.get(f) || S.get(`[${f}`);
|
|
680
642
|
if (!t) return;
|
|
681
643
|
const e = (n) => {
|
|
682
644
|
if (!(!n || typeof n != "object")) {
|
|
683
645
|
n._meta?.clientActivityState?.elements && n._meta.clientActivityState.elements.forEach((a) => {
|
|
684
|
-
const
|
|
685
|
-
|
|
646
|
+
const i = a.domRef?.current;
|
|
647
|
+
i && ("disabled" in i ? i.disabled = o : (i.style.pointerEvents = o ? "none" : "", i.setAttribute("aria-disabled", String(o))));
|
|
686
648
|
});
|
|
687
649
|
for (const a in n)
|
|
688
650
|
a !== "_meta" && e(n[a]);
|
|
@@ -695,7 +657,7 @@ export {
|
|
|
695
657
|
I as generateId,
|
|
696
658
|
P as getAllFieldElements,
|
|
697
659
|
C as getGlobalStore,
|
|
698
|
-
|
|
660
|
+
Z as setAllFieldsDisabled,
|
|
699
661
|
S as shadowStateStore,
|
|
700
662
|
w as updateShadowTypeInfo
|
|
701
663
|
};
|