cogsbox-state 0.5.471 → 0.5.473
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 +2 -5
- package/dist/CogsState.d.ts +105 -79
- package/dist/CogsState.d.ts.map +1 -1
- package/dist/CogsState.jsx +1082 -987
- package/dist/CogsState.jsx.map +1 -1
- package/dist/Components.d.ts.map +1 -1
- package/dist/Components.jsx +293 -243
- package/dist/Components.jsx.map +1 -1
- package/dist/PluginRunner.d.ts +10 -0
- package/dist/PluginRunner.d.ts.map +1 -0
- package/dist/PluginRunner.jsx +128 -0
- package/dist/PluginRunner.jsx.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +33 -26
- package/dist/index.js.map +1 -1
- package/dist/pluginStore.d.ts +43 -0
- package/dist/pluginStore.d.ts.map +1 -0
- package/dist/pluginStore.js +52 -0
- package/dist/pluginStore.js.map +1 -0
- package/dist/plugins.d.ts +1326 -0
- package/dist/plugins.d.ts.map +1 -0
- package/dist/plugins.js +76 -0
- package/dist/plugins.js.map +1 -0
- package/dist/store.d.ts +69 -26
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +436 -152
- package/dist/store.js.map +1 -1
- package/dist/utility.d.ts +1 -1
- package/dist/utility.d.ts.map +1 -1
- package/dist/utility.js +12 -12
- package/dist/utility.js.map +1 -1
- package/dist/validation.d.ts +7 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +39 -0
- package/dist/validation.js.map +1 -0
- package/package.json +18 -13
- package/src/CogsState.tsx +719 -458
- package/src/Components.tsx +304 -180
- package/src/PluginRunner.tsx +208 -0
- package/src/index.ts +2 -0
- package/src/pluginStore.ts +159 -0
- package/src/plugins.ts +548 -0
- package/src/store.ts +881 -189
- package/src/utility.ts +31 -31
- package/src/validation.ts +84 -0
package/dist/store.js
CHANGED
|
@@ -1,74 +1,294 @@
|
|
|
1
|
-
import { create as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
import { create as A } from "zustand";
|
|
2
|
+
function I(u, a = "zod4") {
|
|
3
|
+
if (!u) return null;
|
|
4
|
+
let e = u, t = !1, o = !1, n, s = !1;
|
|
5
|
+
for (let l = 0; l < 20; l++) {
|
|
6
|
+
const f = e?.def || e?._def;
|
|
7
|
+
if (!f) break;
|
|
8
|
+
const p = f.typeName || f.type || e._type;
|
|
9
|
+
if (p === "ZodUnion" || p === "union")
|
|
10
|
+
if (f.options && f.options.length > 0) {
|
|
11
|
+
e = f.options[0];
|
|
12
|
+
continue;
|
|
13
|
+
} else
|
|
14
|
+
break;
|
|
15
|
+
if (p === "ZodOptional" || p === "optional")
|
|
16
|
+
o = !0;
|
|
17
|
+
else if (p === "ZodNullable" || p === "nullable")
|
|
18
|
+
t = !0;
|
|
19
|
+
else if (p === "ZodDefault" || p === "default")
|
|
20
|
+
s = !0, n = typeof f.defaultValue == "function" ? f.defaultValue() : f.defaultValue;
|
|
21
|
+
else if (p !== "ZodEffects" && p !== "effects")
|
|
22
|
+
break;
|
|
23
|
+
const y = f.innerType || f.schema || e._inner;
|
|
24
|
+
if (!y || y === e)
|
|
25
|
+
break;
|
|
26
|
+
e = y;
|
|
18
27
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
const r = e, i = r?.def || r?._def, c = i?.typeName || i?.type || r?._type;
|
|
29
|
+
return c === "ZodNumber" || c === "number" ? {
|
|
30
|
+
type: "number",
|
|
31
|
+
schema: u,
|
|
32
|
+
source: a,
|
|
33
|
+
default: s ? n : 0,
|
|
34
|
+
nullable: t,
|
|
35
|
+
optional: o
|
|
36
|
+
} : c === "ZodString" || c === "string" ? {
|
|
37
|
+
type: "string",
|
|
38
|
+
schema: u,
|
|
39
|
+
source: a,
|
|
40
|
+
default: s ? n : "",
|
|
41
|
+
nullable: t,
|
|
42
|
+
optional: o
|
|
43
|
+
} : c === "ZodBoolean" || c === "boolean" ? {
|
|
44
|
+
type: "boolean",
|
|
45
|
+
schema: u,
|
|
46
|
+
source: a,
|
|
47
|
+
default: s ? n : !1,
|
|
48
|
+
nullable: t,
|
|
49
|
+
optional: o
|
|
50
|
+
} : c === "ZodArray" || c === "array" ? {
|
|
51
|
+
type: "array",
|
|
52
|
+
schema: u,
|
|
53
|
+
source: a,
|
|
54
|
+
default: s ? n : [],
|
|
55
|
+
nullable: t,
|
|
56
|
+
optional: o
|
|
57
|
+
} : c === "ZodObject" || c === "object" ? {
|
|
58
|
+
type: "object",
|
|
59
|
+
schema: u,
|
|
60
|
+
source: a,
|
|
61
|
+
default: s ? n : {},
|
|
62
|
+
nullable: t,
|
|
63
|
+
optional: o
|
|
64
|
+
} : c === "ZodDate" || c === "date" ? {
|
|
65
|
+
type: "date",
|
|
66
|
+
schema: u,
|
|
67
|
+
source: a,
|
|
68
|
+
default: s ? n : /* @__PURE__ */ new Date(),
|
|
69
|
+
nullable: t,
|
|
70
|
+
optional: o
|
|
71
|
+
} : null;
|
|
72
|
+
}
|
|
73
|
+
function E(u) {
|
|
74
|
+
if (u === null)
|
|
75
|
+
return {
|
|
76
|
+
type: "unknown",
|
|
77
|
+
schema: null,
|
|
78
|
+
source: "default",
|
|
79
|
+
default: null,
|
|
80
|
+
nullable: !0
|
|
81
|
+
};
|
|
82
|
+
if (u === void 0)
|
|
83
|
+
return {
|
|
84
|
+
type: "unknown",
|
|
85
|
+
schema: null,
|
|
86
|
+
source: "default",
|
|
87
|
+
default: void 0,
|
|
88
|
+
optional: !0
|
|
89
|
+
};
|
|
90
|
+
const a = typeof u;
|
|
91
|
+
return a === "number" ? { type: "number", schema: null, source: "runtime", default: u } : a === "string" ? { type: "string", schema: null, source: "runtime", default: u } : a === "boolean" ? { type: "boolean", schema: null, source: "runtime", default: u } : Array.isArray(u) ? { type: "array", schema: null, source: "runtime", default: [] } : u instanceof Date ? { type: "date", schema: null, source: "runtime", default: u } : a === "object" ? { type: "object", schema: null, source: "runtime", default: {} } : { type: "unknown", schema: null, source: "runtime", default: u };
|
|
92
|
+
}
|
|
93
|
+
function _(u, a, e) {
|
|
94
|
+
if (a == null || typeof a != "object") {
|
|
95
|
+
const t = { _meta: { value: a } };
|
|
96
|
+
return t._meta.typeInfo = M(a, e), t;
|
|
97
|
+
}
|
|
98
|
+
if (Array.isArray(a)) {
|
|
99
|
+
const t = { _meta: { arrayKeys: [] } };
|
|
100
|
+
return t._meta.typeInfo = M(a, e), a.forEach((o, n) => {
|
|
101
|
+
const s = O(), r = e ? {
|
|
102
|
+
...e,
|
|
103
|
+
path: [...e.path, n.toString()]
|
|
104
|
+
} : void 0;
|
|
105
|
+
t[s] = _(u, o, r), t._meta.arrayKeys.push(s);
|
|
106
|
+
}), t;
|
|
29
107
|
}
|
|
30
|
-
if (
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
108
|
+
if (a.constructor === Object) {
|
|
109
|
+
const t = { _meta: {} };
|
|
110
|
+
t._meta.typeInfo = M(a, e);
|
|
111
|
+
for (const o in a)
|
|
112
|
+
if (Object.prototype.hasOwnProperty.call(a, o)) {
|
|
113
|
+
const n = e ? {
|
|
114
|
+
...e,
|
|
115
|
+
path: [...e.path, o]
|
|
116
|
+
} : void 0;
|
|
117
|
+
t[o] = _(u, a[o], n);
|
|
118
|
+
}
|
|
119
|
+
return t;
|
|
35
120
|
}
|
|
36
|
-
return {
|
|
121
|
+
return {
|
|
122
|
+
_meta: {
|
|
123
|
+
value: a,
|
|
124
|
+
typeInfo: E(a)
|
|
125
|
+
}
|
|
126
|
+
};
|
|
37
127
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
128
|
+
function M(u, a) {
|
|
129
|
+
if (a) {
|
|
130
|
+
let e = null;
|
|
131
|
+
if (a.schemas.zodV4) {
|
|
132
|
+
const t = a.path.length === 0 ? a.schemas.zodV4 : j(a.schemas.zodV4, a.path);
|
|
133
|
+
t && (e = I(t, "zod4"));
|
|
134
|
+
}
|
|
135
|
+
if (!e && a.schemas.zodV3) {
|
|
136
|
+
const t = a.path.length === 0 ? a.schemas.zodV3 : j(a.schemas.zodV3, a.path);
|
|
137
|
+
t && (e = I(t, "zod3"));
|
|
138
|
+
}
|
|
139
|
+
if (!e && a.schemas.sync?.[a.stateKey] && (e = E(u), e.source = "sync"), e) return e;
|
|
140
|
+
}
|
|
141
|
+
return E(u);
|
|
42
142
|
}
|
|
43
|
-
|
|
44
|
-
|
|
143
|
+
function N(u, a, e) {
|
|
144
|
+
const t = h.get(u) || h.get(`[${u}`);
|
|
145
|
+
if (!t) return;
|
|
146
|
+
function o(n, s) {
|
|
147
|
+
if (!n || typeof n != "object") return;
|
|
148
|
+
const r = j(a, s);
|
|
149
|
+
if (r) {
|
|
150
|
+
const i = I(r, e);
|
|
151
|
+
i && (n._meta || (n._meta = {}), n._meta.typeInfo = {
|
|
152
|
+
...i,
|
|
153
|
+
schema: r
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
n._meta?.arrayKeys ? n._meta.arrayKeys.forEach((i) => {
|
|
157
|
+
n[i] && o(n[i], [...s, "0"]);
|
|
158
|
+
}) : n._meta?.hasOwnProperty("value") || Object.keys(n).forEach((i) => {
|
|
159
|
+
i !== "_meta" && o(n[i], [...s, i]);
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
o(t, []);
|
|
163
|
+
}
|
|
164
|
+
function z(u) {
|
|
165
|
+
let a = u;
|
|
166
|
+
for (; a; ) {
|
|
167
|
+
const e = a.def || a._def, t = e?.typeName || e?.type || a._type;
|
|
168
|
+
if (t === "ZodOptional" || t === "optional" || t === "ZodNullable" || t === "nullable" || t === "ZodDefault" || t === "default" || t === "ZodEffects" || t === "effects")
|
|
169
|
+
a = e.innerType || e.schema || a._inner || a.unwrap?.();
|
|
170
|
+
else
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
return a;
|
|
174
|
+
}
|
|
175
|
+
function j(u, a) {
|
|
176
|
+
if (!u) return null;
|
|
177
|
+
if (a.length === 0) return u;
|
|
178
|
+
let e = u;
|
|
179
|
+
for (const t of a) {
|
|
180
|
+
const o = z(e);
|
|
181
|
+
if (!o) return null;
|
|
182
|
+
const n = o.def || o._def, s = n?.typeName || n?.type || o._type;
|
|
183
|
+
if (s === "ZodObject" || s === "object")
|
|
184
|
+
e = (n?.shape || o.shape || o._shape)?.[t];
|
|
185
|
+
else if (s === "ZodArray" || s === "array")
|
|
186
|
+
e = o.element || n?.type;
|
|
187
|
+
else
|
|
188
|
+
return null;
|
|
189
|
+
if (!e)
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
return e;
|
|
193
|
+
}
|
|
194
|
+
const h = /* @__PURE__ */ new Map();
|
|
195
|
+
let D = 0;
|
|
196
|
+
const V = Date.now().toString(36);
|
|
197
|
+
function O(u) {
|
|
198
|
+
return `id:local_${V}_${(D++).toString(36)}`;
|
|
199
|
+
}
|
|
200
|
+
const $ = A((u, a) => ({
|
|
201
|
+
getPluginMetaDataMap: (e, t) => a().getShadowMetadata(e, t)?.pluginMetaData,
|
|
202
|
+
setPluginMetaData: (e, t, o, n) => {
|
|
203
|
+
const s = a().getShadowMetadata(e, t) || {}, r = new Map(s.pluginMetaData || []), i = r.get(o) || {};
|
|
204
|
+
r.set(o, { ...i, ...n }), a().setShadowMetadata(e, t, { ...s, pluginMetaData: r }), a().notifyPathSubscribers([e, ...t].join("."), {
|
|
205
|
+
type: "METADATA_UPDATE"
|
|
206
|
+
});
|
|
207
|
+
},
|
|
208
|
+
removePluginMetaData: (e, t, o) => {
|
|
209
|
+
const n = a().getShadowMetadata(e, t);
|
|
210
|
+
if (!n?.pluginMetaData) return;
|
|
211
|
+
const s = new Map(n.pluginMetaData);
|
|
212
|
+
s.delete(o), a().setShadowMetadata(e, t, { ...n, pluginMetaData: s });
|
|
213
|
+
},
|
|
45
214
|
setTransformCache: (e, t, o, n) => {
|
|
46
215
|
const s = a().getShadowMetadata(e, t) || {};
|
|
47
216
|
s.transformCaches || (s.transformCaches = /* @__PURE__ */ new Map()), s.transformCaches.set(o, n), a().setShadowMetadata(e, t, {
|
|
48
217
|
transformCaches: s.transformCaches
|
|
49
218
|
});
|
|
50
219
|
},
|
|
220
|
+
// Replace your entire `initializeAndMergeShadowState` function with this one.
|
|
221
|
+
initializeAndMergeShadowState: (e, t) => {
|
|
222
|
+
const n = t?._meta?.arrayKeys !== void 0 ? `[${e}` : e, s = h.get(n) || h.get(e) || h.get(`[${e}`);
|
|
223
|
+
let r = {};
|
|
224
|
+
if (s?._meta) {
|
|
225
|
+
const {
|
|
226
|
+
components: f,
|
|
227
|
+
features: p,
|
|
228
|
+
lastServerSync: y,
|
|
229
|
+
stateSource: m,
|
|
230
|
+
baseServerState: d,
|
|
231
|
+
pathComponents: S,
|
|
232
|
+
signals: b,
|
|
233
|
+
validation: g
|
|
234
|
+
} = s._meta;
|
|
235
|
+
f && (r.components = f), p && (r.features = p), y && (r.lastServerSync = y), m && (r.stateSource = m), d && (r.baseServerState = d), S && (r.pathComponents = S), b && (r.signals = b), g && (r.validation = g);
|
|
236
|
+
}
|
|
237
|
+
function i(f, p) {
|
|
238
|
+
if (p._meta || f._meta) {
|
|
239
|
+
const d = f._meta || {}, S = p._meta || {}, b = { ...d, ...S };
|
|
240
|
+
d.typeInfo?.schema && !S.typeInfo?.schema && (b.typeInfo = d.typeInfo), d.validation && !S.validation && (b.validation = d.validation), d.components && (b.components = d.components), f._meta = b;
|
|
241
|
+
}
|
|
242
|
+
if (p._meta?.hasOwnProperty("value")) {
|
|
243
|
+
for (const d in f)
|
|
244
|
+
d !== "_meta" && delete f[d];
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
const y = new Set(
|
|
248
|
+
Object.keys(p).filter((d) => d !== "_meta")
|
|
249
|
+
), m = new Set(
|
|
250
|
+
Object.keys(f).filter((d) => d !== "_meta")
|
|
251
|
+
);
|
|
252
|
+
for (const d of m)
|
|
253
|
+
y.has(d) || delete f[d];
|
|
254
|
+
for (const d of y) {
|
|
255
|
+
const S = p[d], b = f[d];
|
|
256
|
+
b && typeof b == "object" && S && typeof S == "object" ? i(b, S) : f[d] = S;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
s ? (i(s, t), s._meta || (s._meta = {}), Object.assign(s._meta, r), h.set(n, s)) : (r && Object.keys(r).length > 0 && (t._meta || (t._meta = {}), Object.assign(t._meta, r)), h.set(n, t));
|
|
260
|
+
const c = a().getInitialOptions(e);
|
|
261
|
+
(c?.validation?.zodSchemaV4 || c?.validation?.zodSchemaV3) && (c.validation?.zodSchemaV4 ? N(e, c.validation.zodSchemaV4, "zod4") : c.validation?.zodSchemaV3 && N(e, c.validation.zodSchemaV3, "zod3")), n === e ? h.delete(`[${e}`) : h.delete(e);
|
|
262
|
+
},
|
|
51
263
|
initializeShadowState: (e, t) => {
|
|
52
|
-
const o =
|
|
264
|
+
const o = h.get(e) || h.get(`[${e}`);
|
|
53
265
|
let n = {};
|
|
54
266
|
if (o?._meta) {
|
|
55
267
|
const {
|
|
56
|
-
components:
|
|
57
|
-
features:
|
|
58
|
-
lastServerSync:
|
|
59
|
-
stateSource:
|
|
60
|
-
baseServerState:
|
|
268
|
+
components: f,
|
|
269
|
+
features: p,
|
|
270
|
+
lastServerSync: y,
|
|
271
|
+
stateSource: m,
|
|
272
|
+
baseServerState: d
|
|
61
273
|
} = o._meta;
|
|
62
|
-
|
|
274
|
+
f && (n.components = f), p && (n.features = p), y && (n.lastServerSync = y), m && (n.stateSource = m), d && (n.baseServerState = d);
|
|
63
275
|
}
|
|
64
|
-
|
|
65
|
-
const s =
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
276
|
+
h.delete(e), h.delete(`[${e}`);
|
|
277
|
+
const s = a().getInitialOptions(e), r = a().getInitialOptions("__syncSchemas"), i = {
|
|
278
|
+
stateKey: e,
|
|
279
|
+
path: [],
|
|
280
|
+
schemas: {
|
|
281
|
+
sync: r,
|
|
282
|
+
zodV4: s?.validation?.zodSchemaV4,
|
|
283
|
+
zodV3: s?.validation?.zodSchemaV3
|
|
284
|
+
}
|
|
285
|
+
}, c = _(e, t, i);
|
|
286
|
+
c._meta || (c._meta = {}), Object.assign(c._meta, n);
|
|
287
|
+
const l = Array.isArray(t) ? `[${e}` : e;
|
|
288
|
+
h.set(l, c);
|
|
69
289
|
},
|
|
70
290
|
getShadowNode: (e, t) => {
|
|
71
|
-
let o =
|
|
291
|
+
let o = h.get(e) || h.get(`[${e}`);
|
|
72
292
|
if (o) {
|
|
73
293
|
if (t.length === 0) return o;
|
|
74
294
|
for (const n of t)
|
|
@@ -78,10 +298,10 @@ const E = w((l, a) => ({
|
|
|
78
298
|
},
|
|
79
299
|
getShadowMetadata: (e, t) => a().getShadowNode(e, t)?._meta,
|
|
80
300
|
setShadowMetadata: (e, t, o) => {
|
|
81
|
-
const n =
|
|
82
|
-
let s =
|
|
301
|
+
const n = h.has(`[${e}`) ? `[${e}` : e;
|
|
302
|
+
let s = h.get(n);
|
|
83
303
|
if (!s) {
|
|
84
|
-
s = { _meta: o },
|
|
304
|
+
s = { _meta: o }, h.set(n, s);
|
|
85
305
|
return;
|
|
86
306
|
}
|
|
87
307
|
let r = s;
|
|
@@ -89,87 +309,144 @@ const E = w((l, a) => ({
|
|
|
89
309
|
r[i] || (r[i] = {}), r = r[i];
|
|
90
310
|
r._meta || (r._meta = {}), Object.assign(r._meta, o);
|
|
91
311
|
},
|
|
92
|
-
getShadowValue: (e, t, o
|
|
93
|
-
const
|
|
94
|
-
if (
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
)
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
312
|
+
getShadowValue: (e, t, o) => {
|
|
313
|
+
const n = a().getShadowNode(e, t);
|
|
314
|
+
if (!n)
|
|
315
|
+
return;
|
|
316
|
+
const s = {}, r = [
|
|
317
|
+
[n, s, "final"]
|
|
318
|
+
];
|
|
319
|
+
for (; r.length > 0; ) {
|
|
320
|
+
const [i, c, l] = r.pop();
|
|
321
|
+
if (i._meta?.hasOwnProperty("value")) {
|
|
322
|
+
c[l] = i._meta.value;
|
|
323
|
+
continue;
|
|
324
|
+
}
|
|
325
|
+
if (i._meta?.arrayKeys) {
|
|
326
|
+
const y = o || i._meta.arrayKeys, m = [];
|
|
327
|
+
c[l] = m;
|
|
328
|
+
for (let d = y.length - 1; d >= 0; d--) {
|
|
329
|
+
const S = y[d];
|
|
330
|
+
i[S] && r.push([i[S], m, d]);
|
|
331
|
+
}
|
|
332
|
+
continue;
|
|
333
|
+
}
|
|
334
|
+
const f = {};
|
|
335
|
+
c[l] = f;
|
|
336
|
+
const p = Object.keys(i);
|
|
337
|
+
for (const y of p)
|
|
338
|
+
y !== "_meta" && r.push([i[y], f, y]);
|
|
339
|
+
}
|
|
340
|
+
return s.final;
|
|
106
341
|
},
|
|
107
342
|
updateShadowAtPath: (e, t, o) => {
|
|
108
|
-
const n =
|
|
109
|
-
let s =
|
|
343
|
+
const n = h.has(`[${e}`) ? `[${e}` : e;
|
|
344
|
+
let s = h.get(n);
|
|
110
345
|
if (!s) return;
|
|
111
346
|
let r = s;
|
|
112
|
-
for (let
|
|
113
|
-
r[t[
|
|
347
|
+
for (let l = 0; l < t.length - 1; l++)
|
|
348
|
+
r[t[l]] || (r[t[l]] = {}), r = r[t[l]];
|
|
114
349
|
const i = t.length === 0 ? r : r[t[t.length - 1]];
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
if (
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
350
|
+
function c(l, f, p) {
|
|
351
|
+
if (typeof f != "object" || f === null || f instanceof Date) {
|
|
352
|
+
const m = l._meta || {};
|
|
353
|
+
for (const d in l)
|
|
354
|
+
d !== "_meta" && delete l[d];
|
|
355
|
+
l._meta = { ...m, value: f };
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
if (Array.isArray(f)) {
|
|
359
|
+
l._meta || (l._meta = {}), l._meta.arrayKeys || (l._meta.arrayKeys = []);
|
|
360
|
+
const m = l._meta.arrayKeys, d = f, S = [];
|
|
361
|
+
for (let b = 0; b < d.length; b++) {
|
|
362
|
+
const g = d[b];
|
|
363
|
+
if (b < m.length) {
|
|
364
|
+
const w = m[b];
|
|
365
|
+
c(l[w], g, [
|
|
366
|
+
...p,
|
|
367
|
+
w
|
|
368
|
+
]), S.push(w);
|
|
369
|
+
} else {
|
|
370
|
+
const w = O(), K = a().getInitialOptions(e), v = {
|
|
371
|
+
stateKey: e,
|
|
372
|
+
path: [...p, "0"],
|
|
373
|
+
// Use '0' for array element schema lookup
|
|
374
|
+
schemas: {
|
|
375
|
+
zodV4: K?.validation?.zodSchemaV4,
|
|
376
|
+
zodV3: K?.validation?.zodSchemaV3
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
l[w] = _(
|
|
380
|
+
e,
|
|
381
|
+
g,
|
|
382
|
+
v
|
|
383
|
+
), S.push(w);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
m.length > d.length && m.slice(d.length).forEach((g) => {
|
|
387
|
+
delete l[g];
|
|
388
|
+
}), l._meta.arrayKeys = S;
|
|
129
389
|
return;
|
|
130
390
|
}
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
391
|
+
const y = new Set(Object.keys(f));
|
|
392
|
+
l._meta?.hasOwnProperty("value") && delete l._meta.value;
|
|
393
|
+
for (const m of y) {
|
|
394
|
+
const d = f[m];
|
|
395
|
+
if (l[m])
|
|
396
|
+
c(l[m], d, [
|
|
397
|
+
...p,
|
|
398
|
+
m
|
|
399
|
+
]);
|
|
400
|
+
else {
|
|
401
|
+
const S = a().getInitialOptions(e), b = {
|
|
402
|
+
stateKey: e,
|
|
403
|
+
path: [...p, m],
|
|
404
|
+
schemas: {
|
|
405
|
+
zodV4: S?.validation?.zodSchemaV4,
|
|
406
|
+
zodV3: S?.validation?.zodSchemaV3
|
|
407
|
+
}
|
|
408
|
+
};
|
|
409
|
+
l[m] = _(e, d, b);
|
|
410
|
+
}
|
|
135
411
|
}
|
|
136
|
-
for (const
|
|
137
|
-
|
|
412
|
+
for (const m in l)
|
|
413
|
+
m === "_meta" || !Object.prototype.hasOwnProperty.call(l, m) || y.has(m) || delete l[m];
|
|
138
414
|
}
|
|
139
|
-
|
|
415
|
+
i ? c(i, o, t) : r[t[t.length - 1]] = _(e, o), a().notifyPathSubscribers([e, ...t].join("."), {
|
|
140
416
|
type: "UPDATE",
|
|
141
417
|
newValue: o
|
|
142
418
|
});
|
|
143
419
|
},
|
|
144
|
-
addItemsToArrayNode: (e, t, o
|
|
145
|
-
const
|
|
146
|
-
let
|
|
147
|
-
if (!
|
|
420
|
+
addItemsToArrayNode: (e, t, o) => {
|
|
421
|
+
const n = h.has(`[${e}`) ? `[${e}` : e;
|
|
422
|
+
let s = h.get(n);
|
|
423
|
+
if (!s) {
|
|
148
424
|
console.error("Root not found for state key:", e);
|
|
149
425
|
return;
|
|
150
426
|
}
|
|
151
|
-
let
|
|
152
|
-
for (const
|
|
153
|
-
i
|
|
154
|
-
Object.assign(
|
|
427
|
+
let r = s;
|
|
428
|
+
for (const i of t)
|
|
429
|
+
r[i] || (r[i] = {}), r = r[i];
|
|
430
|
+
Object.assign(r, o);
|
|
155
431
|
},
|
|
156
|
-
insertShadowArrayElement: (e, t, o, n) => {
|
|
157
|
-
const
|
|
158
|
-
if (!
|
|
159
|
-
|
|
432
|
+
insertShadowArrayElement: (e, t, o, n, s) => {
|
|
433
|
+
const r = a().getShadowNode(e, t);
|
|
434
|
+
if (!r?._meta?.arrayKeys)
|
|
435
|
+
throw new Error(
|
|
160
436
|
`Array not found at path: ${[e, ...t].join(".")}`
|
|
161
437
|
);
|
|
162
|
-
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
c
|
|
166
|
-
|
|
167
|
-
|
|
438
|
+
console.log("OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO");
|
|
439
|
+
const i = s || `${O()}`;
|
|
440
|
+
r[i] = _(e, o);
|
|
441
|
+
const c = r._meta.arrayKeys, l = n !== void 0 && n >= 0 && n <= c.length ? n : c.length;
|
|
442
|
+
l >= c.length ? c.push(i) : c.splice(l, 0, i);
|
|
443
|
+
const f = [e, ...t].join(".");
|
|
444
|
+
return a().notifyPathSubscribers(f, {
|
|
168
445
|
type: "INSERT",
|
|
169
|
-
path:
|
|
170
|
-
itemKey: `${
|
|
171
|
-
index:
|
|
172
|
-
});
|
|
446
|
+
path: f,
|
|
447
|
+
itemKey: `${f}.${i}`,
|
|
448
|
+
index: l
|
|
449
|
+
}), i;
|
|
173
450
|
},
|
|
174
451
|
insertManyShadowArrayElements: (e, t, o, n) => {
|
|
175
452
|
if (!o || o.length === 0)
|
|
@@ -181,17 +458,17 @@ const E = w((l, a) => ({
|
|
|
181
458
|
);
|
|
182
459
|
return;
|
|
183
460
|
}
|
|
184
|
-
const r =
|
|
185
|
-
o.forEach((
|
|
186
|
-
const
|
|
187
|
-
|
|
461
|
+
const r = [];
|
|
462
|
+
o.forEach((f) => {
|
|
463
|
+
const p = `${O()}`;
|
|
464
|
+
r.push(p), s[p] = _(e, f);
|
|
188
465
|
});
|
|
189
|
-
const
|
|
190
|
-
c >=
|
|
191
|
-
const
|
|
192
|
-
a().notifyPathSubscribers(
|
|
466
|
+
const i = s._meta.arrayKeys, c = n !== void 0 && n >= 0 && n <= i.length ? n : i.length;
|
|
467
|
+
c >= i.length ? i.push(...r) : i.splice(c, 0, ...r);
|
|
468
|
+
const l = [e, ...t].join(".");
|
|
469
|
+
a().notifyPathSubscribers(l, {
|
|
193
470
|
type: "INSERT_MANY",
|
|
194
|
-
path:
|
|
471
|
+
path: l,
|
|
195
472
|
count: o.length,
|
|
196
473
|
index: c
|
|
197
474
|
});
|
|
@@ -205,11 +482,11 @@ const E = w((l, a) => ({
|
|
|
205
482
|
const r = s._meta.arrayKeys, i = r.indexOf(n);
|
|
206
483
|
if (i === -1) return;
|
|
207
484
|
i === r.length - 1 ? r.pop() : i === 0 ? r.shift() : r.splice(i, 1), delete s[n];
|
|
208
|
-
const
|
|
209
|
-
a().notifyPathSubscribers(
|
|
485
|
+
const c = [e, ...o].join(".");
|
|
486
|
+
a().notifyPathSubscribers(c, {
|
|
210
487
|
type: "REMOVE",
|
|
211
|
-
path:
|
|
212
|
-
itemKey: `${
|
|
488
|
+
path: c,
|
|
489
|
+
itemKey: `${c}.${n}`
|
|
213
490
|
});
|
|
214
491
|
},
|
|
215
492
|
registerComponent: (e, t, o) => {
|
|
@@ -231,25 +508,31 @@ const E = w((l, a) => ({
|
|
|
231
508
|
if (r?.components) {
|
|
232
509
|
const i = r.components.get(o);
|
|
233
510
|
if (i) {
|
|
234
|
-
const
|
|
235
|
-
|
|
236
|
-
const
|
|
237
|
-
|
|
511
|
+
const c = [e, ...t].join("."), l = new Set(i.paths);
|
|
512
|
+
l.add(c);
|
|
513
|
+
const f = { ...i, paths: l }, p = new Map(r.components);
|
|
514
|
+
p.set(o, f), a().setShadowMetadata(e, [], { components: p });
|
|
238
515
|
}
|
|
239
516
|
}
|
|
240
517
|
},
|
|
241
518
|
markAsDirty: (e, t, o = { bubble: !0 }) => {
|
|
242
|
-
|
|
243
|
-
if (n
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
519
|
+
let n = a().getShadowNode(e, []);
|
|
520
|
+
if (!n) return;
|
|
521
|
+
let s = n;
|
|
522
|
+
for (const i of t)
|
|
523
|
+
if (s = s[i], !s) return;
|
|
524
|
+
if (s._meta || (s._meta = {}), s._meta.isDirty = !0, !o.bubble) return;
|
|
525
|
+
let r = n;
|
|
526
|
+
for (let i = 0; i < t.length; i++) {
|
|
527
|
+
if (r._meta?.isDirty)
|
|
528
|
+
return;
|
|
529
|
+
r._meta || (r._meta = {}), r._meta.isDirty = !0, r = r[t[i]];
|
|
247
530
|
}
|
|
248
531
|
},
|
|
249
532
|
// Keep these in Zustand as they need React reactivity
|
|
250
533
|
serverStateUpdates: /* @__PURE__ */ new Map(),
|
|
251
534
|
setServerStateUpdate: (e, t) => {
|
|
252
|
-
|
|
535
|
+
u((o) => ({
|
|
253
536
|
serverStateUpdates: new Map(o.serverStateUpdates).set(
|
|
254
537
|
e,
|
|
255
538
|
t
|
|
@@ -282,7 +565,7 @@ const E = w((l, a) => ({
|
|
|
282
565
|
return s ? s.indexOf(o) : -1;
|
|
283
566
|
},
|
|
284
567
|
setSelectedIndex: (e, t) => {
|
|
285
|
-
|
|
568
|
+
u((o) => {
|
|
286
569
|
const n = new Map(o.selectedIndicesMap);
|
|
287
570
|
return t === void 0 ? n.delete(e) : (n.has(e) && a().notifyPathSubscribers(n.get(e), {
|
|
288
571
|
type: "THIS_UNSELECTED"
|
|
@@ -293,7 +576,7 @@ const E = w((l, a) => ({
|
|
|
293
576
|
});
|
|
294
577
|
},
|
|
295
578
|
clearSelectedIndex: ({ arrayKey: e }) => {
|
|
296
|
-
|
|
579
|
+
u((t) => {
|
|
297
580
|
const o = new Map(t.selectedIndicesMap), n = o.get(e);
|
|
298
581
|
return n && a().notifyPathSubscribers(n, {
|
|
299
582
|
type: "CLEAR_SELECTION"
|
|
@@ -306,7 +589,7 @@ const E = w((l, a) => ({
|
|
|
306
589
|
});
|
|
307
590
|
},
|
|
308
591
|
clearSelectedIndexesForState: (e) => {
|
|
309
|
-
|
|
592
|
+
u((t) => {
|
|
310
593
|
const o = new Map(t.selectedIndicesMap);
|
|
311
594
|
let n = !1;
|
|
312
595
|
for (const s of o.keys())
|
|
@@ -318,7 +601,7 @@ const E = w((l, a) => ({
|
|
|
318
601
|
stateLog: /* @__PURE__ */ new Map(),
|
|
319
602
|
initialStateGlobal: {},
|
|
320
603
|
addStateLog: (e) => {
|
|
321
|
-
!e || e.length === 0 ||
|
|
604
|
+
!e || e.length === 0 || u((t) => {
|
|
322
605
|
const o = new Map(t.stateLog), n = /* @__PURE__ */ new Map();
|
|
323
606
|
for (const s of e) {
|
|
324
607
|
const r = n.get(s.stateKey) || [];
|
|
@@ -326,8 +609,8 @@ const E = w((l, a) => ({
|
|
|
326
609
|
}
|
|
327
610
|
for (const [s, r] of n.entries()) {
|
|
328
611
|
const i = new Map(o.get(s));
|
|
329
|
-
for (const
|
|
330
|
-
i.set(JSON.stringify(
|
|
612
|
+
for (const c of r)
|
|
613
|
+
i.set(JSON.stringify(c.path), { ...c });
|
|
331
614
|
o.set(s, i);
|
|
332
615
|
}
|
|
333
616
|
return { stateLog: o };
|
|
@@ -335,26 +618,27 @@ const E = w((l, a) => ({
|
|
|
335
618
|
},
|
|
336
619
|
getInitialOptions: (e) => a().initialStateOptions[e],
|
|
337
620
|
setInitialStateOptions: (e, t) => {
|
|
338
|
-
|
|
621
|
+
u((o) => ({
|
|
339
622
|
initialStateOptions: { ...o.initialStateOptions, [e]: t }
|
|
340
623
|
}));
|
|
341
624
|
},
|
|
342
625
|
updateInitialStateGlobal: (e, t) => {
|
|
343
|
-
|
|
626
|
+
u((o) => ({
|
|
344
627
|
initialStateGlobal: { ...o.initialStateGlobal, [e]: t }
|
|
345
628
|
}));
|
|
346
629
|
},
|
|
347
630
|
syncInfoStore: /* @__PURE__ */ new Map(),
|
|
348
|
-
setSyncInfo: (e, t) =>
|
|
631
|
+
setSyncInfo: (e, t) => u((o) => {
|
|
349
632
|
const n = new Map(o.syncInfoStore);
|
|
350
633
|
return n.set(e, t), { syncInfoStore: n };
|
|
351
634
|
}),
|
|
352
635
|
getSyncInfo: (e) => a().syncInfoStore.get(e) || null
|
|
353
636
|
}));
|
|
354
637
|
export {
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
638
|
+
_ as buildShadowNode,
|
|
639
|
+
O as generateId,
|
|
640
|
+
$ as getGlobalStore,
|
|
641
|
+
h as shadowStateStore,
|
|
642
|
+
N as updateShadowTypeInfo
|
|
359
643
|
};
|
|
360
644
|
//# sourceMappingURL=store.js.map
|