cogsbox-state 0.5.474 → 0.5.475-canary.1
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 +11 -11
- package/dist/CogsState.d.ts +26 -17
- package/dist/CogsState.d.ts.map +1 -1
- package/dist/CogsState.jsx +383 -380
- package/dist/CogsState.jsx.map +1 -1
- package/dist/Components.d.ts.map +1 -1
- package/dist/Components.jsx +231 -225
- package/dist/Components.jsx.map +1 -1
- package/dist/PluginRunner.d.ts.map +1 -1
- package/dist/PluginRunner.jsx +82 -67
- package/dist/PluginRunner.jsx.map +1 -1
- package/dist/index.js +17 -16
- package/dist/plugins.d.ts +98 -980
- package/dist/plugins.d.ts.map +1 -1
- package/dist/plugins.js +48 -36
- package/dist/plugins.js.map +1 -1
- package/dist/store.js +168 -169
- package/dist/store.js.map +1 -1
- package/package.json +4 -3
- package/src/CogsState.tsx +234 -551
- package/src/Components.tsx +43 -34
- package/src/PluginRunner.tsx +24 -6
- package/src/plugins.ts +93 -127
- package/src/store.ts +1 -1
package/dist/store.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { create as A } from "zustand";
|
|
2
|
-
function
|
|
2
|
+
function O(u, o = "zod4") {
|
|
3
3
|
if (!u) return null;
|
|
4
|
-
let e = u, t = !1,
|
|
4
|
+
let e = u, t = !1, a = !1, n, s = !1;
|
|
5
5
|
for (let l = 0; l < 20; l++) {
|
|
6
6
|
const f = e?.def || e?._def;
|
|
7
7
|
if (!f) break;
|
|
@@ -13,7 +13,7 @@ function I(u, a = "zod4") {
|
|
|
13
13
|
} else
|
|
14
14
|
break;
|
|
15
15
|
if (p === "ZodOptional" || p === "optional")
|
|
16
|
-
|
|
16
|
+
a = !0;
|
|
17
17
|
else if (p === "ZodNullable" || p === "nullable")
|
|
18
18
|
t = !0;
|
|
19
19
|
else if (p === "ZodDefault" || p === "default")
|
|
@@ -29,45 +29,45 @@ function I(u, a = "zod4") {
|
|
|
29
29
|
return c === "ZodNumber" || c === "number" ? {
|
|
30
30
|
type: "number",
|
|
31
31
|
schema: u,
|
|
32
|
-
source:
|
|
32
|
+
source: o,
|
|
33
33
|
default: s ? n : 0,
|
|
34
34
|
nullable: t,
|
|
35
|
-
optional:
|
|
35
|
+
optional: a
|
|
36
36
|
} : c === "ZodString" || c === "string" ? {
|
|
37
37
|
type: "string",
|
|
38
38
|
schema: u,
|
|
39
|
-
source:
|
|
39
|
+
source: o,
|
|
40
40
|
default: s ? n : "",
|
|
41
41
|
nullable: t,
|
|
42
|
-
optional:
|
|
42
|
+
optional: a
|
|
43
43
|
} : c === "ZodBoolean" || c === "boolean" ? {
|
|
44
44
|
type: "boolean",
|
|
45
45
|
schema: u,
|
|
46
|
-
source:
|
|
46
|
+
source: o,
|
|
47
47
|
default: s ? n : !1,
|
|
48
48
|
nullable: t,
|
|
49
|
-
optional:
|
|
49
|
+
optional: a
|
|
50
50
|
} : c === "ZodArray" || c === "array" ? {
|
|
51
51
|
type: "array",
|
|
52
52
|
schema: u,
|
|
53
|
-
source:
|
|
53
|
+
source: o,
|
|
54
54
|
default: s ? n : [],
|
|
55
55
|
nullable: t,
|
|
56
|
-
optional:
|
|
56
|
+
optional: a
|
|
57
57
|
} : c === "ZodObject" || c === "object" ? {
|
|
58
58
|
type: "object",
|
|
59
59
|
schema: u,
|
|
60
|
-
source:
|
|
60
|
+
source: o,
|
|
61
61
|
default: s ? n : {},
|
|
62
62
|
nullable: t,
|
|
63
|
-
optional:
|
|
63
|
+
optional: a
|
|
64
64
|
} : c === "ZodDate" || c === "date" ? {
|
|
65
65
|
type: "date",
|
|
66
66
|
schema: u,
|
|
67
|
-
source:
|
|
67
|
+
source: o,
|
|
68
68
|
default: s ? n : /* @__PURE__ */ new Date(),
|
|
69
69
|
nullable: t,
|
|
70
|
-
optional:
|
|
70
|
+
optional: a
|
|
71
71
|
} : null;
|
|
72
72
|
}
|
|
73
73
|
function E(u) {
|
|
@@ -87,103 +87,103 @@ function E(u) {
|
|
|
87
87
|
default: void 0,
|
|
88
88
|
optional: !0
|
|
89
89
|
};
|
|
90
|
-
const
|
|
91
|
-
return
|
|
90
|
+
const o = typeof u;
|
|
91
|
+
return o === "number" ? { type: "number", schema: null, source: "runtime", default: u } : o === "string" ? { type: "string", schema: null, source: "runtime", default: u } : o === "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 } : o === "object" ? { type: "object", schema: null, source: "runtime", default: {} } : { type: "unknown", schema: null, source: "runtime", default: u };
|
|
92
92
|
}
|
|
93
|
-
function _(u,
|
|
94
|
-
if (
|
|
95
|
-
const t = { _meta: { value:
|
|
96
|
-
return t._meta.typeInfo =
|
|
93
|
+
function _(u, o, e) {
|
|
94
|
+
if (o == null || typeof o != "object") {
|
|
95
|
+
const t = { _meta: { value: o } };
|
|
96
|
+
return t._meta.typeInfo = I(o, e), t;
|
|
97
97
|
}
|
|
98
|
-
if (Array.isArray(
|
|
98
|
+
if (Array.isArray(o)) {
|
|
99
99
|
const t = { _meta: { arrayKeys: [] } };
|
|
100
|
-
return t._meta.typeInfo =
|
|
101
|
-
const s =
|
|
100
|
+
return t._meta.typeInfo = I(o, e), o.forEach((a, n) => {
|
|
101
|
+
const s = M(), r = e ? {
|
|
102
102
|
...e,
|
|
103
103
|
path: [...e.path, n.toString()]
|
|
104
104
|
} : void 0;
|
|
105
|
-
t[s] = _(u,
|
|
105
|
+
t[s] = _(u, a, r), t._meta.arrayKeys.push(s);
|
|
106
106
|
}), t;
|
|
107
107
|
}
|
|
108
|
-
if (
|
|
108
|
+
if (o.constructor === Object) {
|
|
109
109
|
const t = { _meta: {} };
|
|
110
|
-
t._meta.typeInfo =
|
|
111
|
-
for (const
|
|
112
|
-
if (Object.prototype.hasOwnProperty.call(
|
|
110
|
+
t._meta.typeInfo = I(o, e);
|
|
111
|
+
for (const a in o)
|
|
112
|
+
if (Object.prototype.hasOwnProperty.call(o, a)) {
|
|
113
113
|
const n = e ? {
|
|
114
114
|
...e,
|
|
115
|
-
path: [...e.path,
|
|
115
|
+
path: [...e.path, a]
|
|
116
116
|
} : void 0;
|
|
117
|
-
t[
|
|
117
|
+
t[a] = _(u, o[a], n);
|
|
118
118
|
}
|
|
119
119
|
return t;
|
|
120
120
|
}
|
|
121
121
|
return {
|
|
122
122
|
_meta: {
|
|
123
|
-
value:
|
|
124
|
-
typeInfo: E(
|
|
123
|
+
value: o,
|
|
124
|
+
typeInfo: E(o)
|
|
125
125
|
}
|
|
126
126
|
};
|
|
127
127
|
}
|
|
128
|
-
function
|
|
129
|
-
if (
|
|
128
|
+
function I(u, o) {
|
|
129
|
+
if (o) {
|
|
130
130
|
let e = null;
|
|
131
|
-
if (
|
|
132
|
-
const t =
|
|
133
|
-
t && (e =
|
|
131
|
+
if (o.schemas.zodV4) {
|
|
132
|
+
const t = o.path.length === 0 ? o.schemas.zodV4 : j(o.schemas.zodV4, o.path);
|
|
133
|
+
t && (e = O(t, "zod4"));
|
|
134
134
|
}
|
|
135
|
-
if (!e &&
|
|
136
|
-
const t =
|
|
137
|
-
t && (e =
|
|
135
|
+
if (!e && o.schemas.zodV3) {
|
|
136
|
+
const t = o.path.length === 0 ? o.schemas.zodV3 : j(o.schemas.zodV3, o.path);
|
|
137
|
+
t && (e = O(t, "zod3"));
|
|
138
138
|
}
|
|
139
|
-
if (!e &&
|
|
139
|
+
if (!e && o.schemas.sync?.[o.stateKey] && (e = E(u), e.source = "sync"), e) return e;
|
|
140
140
|
}
|
|
141
141
|
return E(u);
|
|
142
142
|
}
|
|
143
|
-
function N(u,
|
|
143
|
+
function N(u, o, e) {
|
|
144
144
|
const t = h.get(u) || h.get(`[${u}`);
|
|
145
145
|
if (!t) return;
|
|
146
|
-
function
|
|
146
|
+
function a(n, s) {
|
|
147
147
|
if (!n || typeof n != "object") return;
|
|
148
|
-
const r = j(
|
|
148
|
+
const r = j(o, s);
|
|
149
149
|
if (r) {
|
|
150
|
-
const i =
|
|
150
|
+
const i = O(r, e);
|
|
151
151
|
i && (n._meta || (n._meta = {}), n._meta.typeInfo = {
|
|
152
152
|
...i,
|
|
153
153
|
schema: r
|
|
154
154
|
});
|
|
155
155
|
}
|
|
156
156
|
n._meta?.arrayKeys ? n._meta.arrayKeys.forEach((i) => {
|
|
157
|
-
n[i] &&
|
|
157
|
+
n[i] && a(n[i], [...s, "0"]);
|
|
158
158
|
}) : n._meta?.hasOwnProperty("value") || Object.keys(n).forEach((i) => {
|
|
159
|
-
i !== "_meta" &&
|
|
159
|
+
i !== "_meta" && a(n[i], [...s, i]);
|
|
160
160
|
});
|
|
161
161
|
}
|
|
162
|
-
|
|
162
|
+
a(t, []);
|
|
163
163
|
}
|
|
164
164
|
function z(u) {
|
|
165
|
-
let
|
|
166
|
-
for (;
|
|
167
|
-
const e =
|
|
165
|
+
let o = u;
|
|
166
|
+
for (; o; ) {
|
|
167
|
+
const e = o.def || o._def, t = e?.typeName || e?.type || o._type;
|
|
168
168
|
if (t === "ZodOptional" || t === "optional" || t === "ZodNullable" || t === "nullable" || t === "ZodDefault" || t === "default" || t === "ZodEffects" || t === "effects")
|
|
169
|
-
|
|
169
|
+
o = e.innerType || e.schema || o._inner || o.unwrap?.();
|
|
170
170
|
else
|
|
171
171
|
break;
|
|
172
172
|
}
|
|
173
|
-
return
|
|
173
|
+
return o;
|
|
174
174
|
}
|
|
175
|
-
function j(u,
|
|
175
|
+
function j(u, o) {
|
|
176
176
|
if (!u) return null;
|
|
177
|
-
if (
|
|
177
|
+
if (o.length === 0) return u;
|
|
178
178
|
let e = u;
|
|
179
|
-
for (const t of
|
|
180
|
-
const
|
|
181
|
-
if (!
|
|
182
|
-
const n =
|
|
179
|
+
for (const t of o) {
|
|
180
|
+
const a = z(e);
|
|
181
|
+
if (!a) return null;
|
|
182
|
+
const n = a.def || a._def, s = n?.typeName || n?.type || a._type;
|
|
183
183
|
if (s === "ZodObject" || s === "object")
|
|
184
|
-
e = (n?.shape ||
|
|
184
|
+
e = (n?.shape || a.shape || a._shape)?.[t];
|
|
185
185
|
else if (s === "ZodArray" || s === "array")
|
|
186
|
-
e =
|
|
186
|
+
e = a.element || n?.type;
|
|
187
187
|
else
|
|
188
188
|
return null;
|
|
189
189
|
if (!e)
|
|
@@ -194,26 +194,26 @@ function j(u, a) {
|
|
|
194
194
|
const h = /* @__PURE__ */ new Map();
|
|
195
195
|
let D = 0;
|
|
196
196
|
const V = Date.now().toString(36);
|
|
197
|
-
function
|
|
197
|
+
function M(u) {
|
|
198
198
|
return `id:local_${V}_${(D++).toString(36)}`;
|
|
199
199
|
}
|
|
200
|
-
const $ = A((u,
|
|
201
|
-
getPluginMetaDataMap: (e, t) =>
|
|
202
|
-
setPluginMetaData: (e, t,
|
|
203
|
-
const s =
|
|
204
|
-
r.set(
|
|
200
|
+
const $ = A((u, o) => ({
|
|
201
|
+
getPluginMetaDataMap: (e, t) => o().getShadowMetadata(e, t)?.pluginMetaData,
|
|
202
|
+
setPluginMetaData: (e, t, a, n) => {
|
|
203
|
+
const s = o().getShadowMetadata(e, t) || {}, r = new Map(s.pluginMetaData || []), i = r.get(a) || {};
|
|
204
|
+
r.set(a, { ...i, ...n }), o().setShadowMetadata(e, t, { ...s, pluginMetaData: r }), o().notifyPathSubscribers([e, ...t].join("."), {
|
|
205
205
|
type: "METADATA_UPDATE"
|
|
206
206
|
});
|
|
207
207
|
},
|
|
208
|
-
removePluginMetaData: (e, t,
|
|
209
|
-
const n =
|
|
208
|
+
removePluginMetaData: (e, t, a) => {
|
|
209
|
+
const n = o().getShadowMetadata(e, t);
|
|
210
210
|
if (!n?.pluginMetaData) return;
|
|
211
211
|
const s = new Map(n.pluginMetaData);
|
|
212
|
-
s.delete(
|
|
212
|
+
s.delete(a), o().setShadowMetadata(e, t, { ...n, pluginMetaData: s });
|
|
213
213
|
},
|
|
214
|
-
setTransformCache: (e, t,
|
|
215
|
-
const s =
|
|
216
|
-
s.transformCaches || (s.transformCaches = /* @__PURE__ */ new Map()), s.transformCaches.set(
|
|
214
|
+
setTransformCache: (e, t, a, n) => {
|
|
215
|
+
const s = o().getShadowMetadata(e, t) || {};
|
|
216
|
+
s.transformCaches || (s.transformCaches = /* @__PURE__ */ new Map()), s.transformCaches.set(a, n), o().setShadowMetadata(e, t, {
|
|
217
217
|
transformCaches: s.transformCaches
|
|
218
218
|
});
|
|
219
219
|
},
|
|
@@ -257,24 +257,24 @@ const $ = A((u, a) => ({
|
|
|
257
257
|
}
|
|
258
258
|
}
|
|
259
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 =
|
|
260
|
+
const c = o().getInitialOptions(e);
|
|
261
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
262
|
},
|
|
263
263
|
initializeShadowState: (e, t) => {
|
|
264
|
-
const
|
|
264
|
+
const a = h.get(e) || h.get(`[${e}`);
|
|
265
265
|
let n = {};
|
|
266
|
-
if (
|
|
266
|
+
if (a?._meta) {
|
|
267
267
|
const {
|
|
268
268
|
components: f,
|
|
269
269
|
features: p,
|
|
270
270
|
lastServerSync: y,
|
|
271
271
|
stateSource: m,
|
|
272
272
|
baseServerState: d
|
|
273
|
-
} =
|
|
273
|
+
} = a._meta;
|
|
274
274
|
f && (n.components = f), p && (n.features = p), y && (n.lastServerSync = y), m && (n.stateSource = m), d && (n.baseServerState = d);
|
|
275
275
|
}
|
|
276
276
|
h.delete(e), h.delete(`[${e}`);
|
|
277
|
-
const s =
|
|
277
|
+
const s = o().getInitialOptions(e), r = o().getInitialOptions("__syncSchemas"), i = {
|
|
278
278
|
stateKey: e,
|
|
279
279
|
path: [],
|
|
280
280
|
schemas: {
|
|
@@ -288,29 +288,29 @@ const $ = A((u, a) => ({
|
|
|
288
288
|
h.set(l, c);
|
|
289
289
|
},
|
|
290
290
|
getShadowNode: (e, t) => {
|
|
291
|
-
let
|
|
292
|
-
if (
|
|
293
|
-
if (t.length === 0) return
|
|
291
|
+
let a = h.get(e) || h.get(`[${e}`);
|
|
292
|
+
if (a) {
|
|
293
|
+
if (t.length === 0) return a;
|
|
294
294
|
for (const n of t)
|
|
295
|
-
if (typeof
|
|
296
|
-
return
|
|
295
|
+
if (typeof a != "object" || a === null || (a = a[n], a === void 0)) return;
|
|
296
|
+
return a;
|
|
297
297
|
}
|
|
298
298
|
},
|
|
299
|
-
getShadowMetadata: (e, t) =>
|
|
300
|
-
setShadowMetadata: (e, t,
|
|
299
|
+
getShadowMetadata: (e, t) => o().getShadowNode(e, t)?._meta,
|
|
300
|
+
setShadowMetadata: (e, t, a) => {
|
|
301
301
|
const n = h.has(`[${e}`) ? `[${e}` : e;
|
|
302
302
|
let s = h.get(n);
|
|
303
303
|
if (!s) {
|
|
304
|
-
s = { _meta:
|
|
304
|
+
s = { _meta: a }, h.set(n, s);
|
|
305
305
|
return;
|
|
306
306
|
}
|
|
307
307
|
let r = s;
|
|
308
308
|
for (const i of t)
|
|
309
309
|
r[i] || (r[i] = {}), r = r[i];
|
|
310
|
-
r._meta || (r._meta = {}), Object.assign(r._meta,
|
|
310
|
+
r._meta || (r._meta = {}), Object.assign(r._meta, a);
|
|
311
311
|
},
|
|
312
|
-
getShadowValue: (e, t,
|
|
313
|
-
const n =
|
|
312
|
+
getShadowValue: (e, t, a) => {
|
|
313
|
+
const n = o().getShadowNode(e, t);
|
|
314
314
|
if (!n)
|
|
315
315
|
return;
|
|
316
316
|
const s = {}, r = [
|
|
@@ -323,7 +323,7 @@ const $ = A((u, a) => ({
|
|
|
323
323
|
continue;
|
|
324
324
|
}
|
|
325
325
|
if (i._meta?.arrayKeys) {
|
|
326
|
-
const y =
|
|
326
|
+
const y = a || i._meta.arrayKeys, m = [];
|
|
327
327
|
c[l] = m;
|
|
328
328
|
for (let d = y.length - 1; d >= 0; d--) {
|
|
329
329
|
const S = y[d];
|
|
@@ -339,7 +339,7 @@ const $ = A((u, a) => ({
|
|
|
339
339
|
}
|
|
340
340
|
return s.final;
|
|
341
341
|
},
|
|
342
|
-
updateShadowAtPath: (e, t,
|
|
342
|
+
updateShadowAtPath: (e, t, a) => {
|
|
343
343
|
const n = h.has(`[${e}`) ? `[${e}` : e;
|
|
344
344
|
let s = h.get(n);
|
|
345
345
|
if (!s) return;
|
|
@@ -367,7 +367,7 @@ const $ = A((u, a) => ({
|
|
|
367
367
|
w
|
|
368
368
|
]), S.push(w);
|
|
369
369
|
} else {
|
|
370
|
-
const w =
|
|
370
|
+
const w = M(), K = o().getInitialOptions(e), v = {
|
|
371
371
|
stateKey: e,
|
|
372
372
|
path: [...p, "0"],
|
|
373
373
|
// Use '0' for array element schema lookup
|
|
@@ -398,7 +398,7 @@ const $ = A((u, a) => ({
|
|
|
398
398
|
m
|
|
399
399
|
]);
|
|
400
400
|
else {
|
|
401
|
-
const S =
|
|
401
|
+
const S = o().getInitialOptions(e), b = {
|
|
402
402
|
stateKey: e,
|
|
403
403
|
path: [...p, m],
|
|
404
404
|
schemas: {
|
|
@@ -412,12 +412,12 @@ const $ = A((u, a) => ({
|
|
|
412
412
|
for (const m in l)
|
|
413
413
|
m === "_meta" || !Object.prototype.hasOwnProperty.call(l, m) || y.has(m) || delete l[m];
|
|
414
414
|
}
|
|
415
|
-
i ? c(i,
|
|
415
|
+
i ? c(i, a, t) : r[t[t.length - 1]] = _(e, a), o().notifyPathSubscribers([e, ...t].join("."), {
|
|
416
416
|
type: "UPDATE",
|
|
417
|
-
newValue:
|
|
417
|
+
newValue: a
|
|
418
418
|
});
|
|
419
419
|
},
|
|
420
|
-
addItemsToArrayNode: (e, t,
|
|
420
|
+
addItemsToArrayNode: (e, t, a) => {
|
|
421
421
|
const n = h.has(`[${e}`) ? `[${e}` : e;
|
|
422
422
|
let s = h.get(n);
|
|
423
423
|
if (!s) {
|
|
@@ -427,31 +427,30 @@ const $ = A((u, a) => ({
|
|
|
427
427
|
let r = s;
|
|
428
428
|
for (const i of t)
|
|
429
429
|
r[i] || (r[i] = {}), r = r[i];
|
|
430
|
-
Object.assign(r,
|
|
430
|
+
Object.assign(r, a);
|
|
431
431
|
},
|
|
432
|
-
insertShadowArrayElement: (e, t,
|
|
433
|
-
const r =
|
|
432
|
+
insertShadowArrayElement: (e, t, a, n, s) => {
|
|
433
|
+
const r = o().getShadowNode(e, t);
|
|
434
434
|
if (!r?._meta?.arrayKeys)
|
|
435
435
|
throw new Error(
|
|
436
436
|
`Array not found at path: ${[e, ...t].join(".")}`
|
|
437
437
|
);
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
r[i] = _(e, o);
|
|
438
|
+
const i = s || `${M()}`;
|
|
439
|
+
r[i] = _(e, a);
|
|
441
440
|
const c = r._meta.arrayKeys, l = n !== void 0 && n >= 0 && n <= c.length ? n : c.length;
|
|
442
441
|
l >= c.length ? c.push(i) : c.splice(l, 0, i);
|
|
443
442
|
const f = [e, ...t].join(".");
|
|
444
|
-
return
|
|
443
|
+
return o().notifyPathSubscribers(f, {
|
|
445
444
|
type: "INSERT",
|
|
446
445
|
path: f,
|
|
447
446
|
itemKey: `${f}.${i}`,
|
|
448
447
|
index: l
|
|
449
448
|
}), i;
|
|
450
449
|
},
|
|
451
|
-
insertManyShadowArrayElements: (e, t,
|
|
452
|
-
if (!
|
|
450
|
+
insertManyShadowArrayElements: (e, t, a, n) => {
|
|
451
|
+
if (!a || a.length === 0)
|
|
453
452
|
return;
|
|
454
|
-
const s =
|
|
453
|
+
const s = o().getShadowNode(e, t);
|
|
455
454
|
if (!s?._meta?.arrayKeys) {
|
|
456
455
|
console.error(
|
|
457
456
|
`Array not found at path: ${[e, ...t].join(".")}`
|
|
@@ -459,69 +458,69 @@ const $ = A((u, a) => ({
|
|
|
459
458
|
return;
|
|
460
459
|
}
|
|
461
460
|
const r = [];
|
|
462
|
-
|
|
463
|
-
const p = `${
|
|
461
|
+
a.forEach((f) => {
|
|
462
|
+
const p = `${M()}`;
|
|
464
463
|
r.push(p), s[p] = _(e, f);
|
|
465
464
|
});
|
|
466
465
|
const i = s._meta.arrayKeys, c = n !== void 0 && n >= 0 && n <= i.length ? n : i.length;
|
|
467
466
|
c >= i.length ? i.push(...r) : i.splice(c, 0, ...r);
|
|
468
467
|
const l = [e, ...t].join(".");
|
|
469
|
-
|
|
468
|
+
o().notifyPathSubscribers(l, {
|
|
470
469
|
type: "INSERT_MANY",
|
|
471
470
|
path: l,
|
|
472
|
-
count:
|
|
471
|
+
count: a.length,
|
|
473
472
|
index: c
|
|
474
473
|
});
|
|
475
474
|
},
|
|
476
475
|
removeShadowArrayElement: (e, t) => {
|
|
477
476
|
if (t.length === 0) return;
|
|
478
|
-
const
|
|
477
|
+
const a = t.slice(0, -1), n = t[t.length - 1];
|
|
479
478
|
if (!n?.startsWith("id:")) return;
|
|
480
|
-
const s =
|
|
479
|
+
const s = o().getShadowNode(e, a);
|
|
481
480
|
if (!s?._meta?.arrayKeys) return;
|
|
482
481
|
const r = s._meta.arrayKeys, i = r.indexOf(n);
|
|
483
482
|
if (i === -1) return;
|
|
484
483
|
i === r.length - 1 ? r.pop() : i === 0 ? r.shift() : r.splice(i, 1), delete s[n];
|
|
485
|
-
const c = [e, ...
|
|
486
|
-
|
|
484
|
+
const c = [e, ...a].join(".");
|
|
485
|
+
o().notifyPathSubscribers(c, {
|
|
487
486
|
type: "REMOVE",
|
|
488
487
|
path: c,
|
|
489
488
|
itemKey: `${c}.${n}`
|
|
490
489
|
});
|
|
491
490
|
},
|
|
492
|
-
registerComponent: (e, t,
|
|
493
|
-
const n =
|
|
494
|
-
s.set(t,
|
|
491
|
+
registerComponent: (e, t, a) => {
|
|
492
|
+
const n = o().getShadowMetadata(e, []) || {}, s = new Map(n.components);
|
|
493
|
+
s.set(t, a), o().setShadowMetadata(e, [], { components: s });
|
|
495
494
|
},
|
|
496
495
|
unregisterComponent: (e, t) => {
|
|
497
|
-
const
|
|
498
|
-
if (!
|
|
499
|
-
const n = new Map(
|
|
500
|
-
n.delete(t) &&
|
|
496
|
+
const a = o().getShadowMetadata(e, []);
|
|
497
|
+
if (!a?.components) return;
|
|
498
|
+
const n = new Map(a.components);
|
|
499
|
+
n.delete(t) && o().setShadowMetadata(e, [], { components: n });
|
|
501
500
|
},
|
|
502
|
-
addPathComponent: (e, t,
|
|
503
|
-
const n =
|
|
504
|
-
s.add(
|
|
501
|
+
addPathComponent: (e, t, a) => {
|
|
502
|
+
const n = o().getShadowMetadata(e, t) || {}, s = new Set(n.pathComponents);
|
|
503
|
+
s.add(a), o().setShadowMetadata(e, t, {
|
|
505
504
|
pathComponents: s
|
|
506
505
|
});
|
|
507
|
-
const r =
|
|
506
|
+
const r = o().getShadowMetadata(e, []);
|
|
508
507
|
if (r?.components) {
|
|
509
|
-
const i = r.components.get(
|
|
508
|
+
const i = r.components.get(a);
|
|
510
509
|
if (i) {
|
|
511
510
|
const c = [e, ...t].join("."), l = new Set(i.paths);
|
|
512
511
|
l.add(c);
|
|
513
512
|
const f = { ...i, paths: l }, p = new Map(r.components);
|
|
514
|
-
p.set(
|
|
513
|
+
p.set(a, f), o().setShadowMetadata(e, [], { components: p });
|
|
515
514
|
}
|
|
516
515
|
}
|
|
517
516
|
},
|
|
518
|
-
markAsDirty: (e, t,
|
|
519
|
-
let n =
|
|
517
|
+
markAsDirty: (e, t, a = { bubble: !0 }) => {
|
|
518
|
+
let n = o().getShadowNode(e, []);
|
|
520
519
|
if (!n) return;
|
|
521
520
|
let s = n;
|
|
522
521
|
for (const i of t)
|
|
523
522
|
if (s = s[i], !s) return;
|
|
524
|
-
if (s._meta || (s._meta = {}), s._meta.isDirty = !0, !
|
|
523
|
+
if (s._meta || (s._meta = {}), s._meta.isDirty = !0, !a.bubble) return;
|
|
525
524
|
let r = n;
|
|
526
525
|
for (let i = 0; i < t.length; i++) {
|
|
527
526
|
if (r._meta?.isDirty)
|
|
@@ -532,69 +531,69 @@ const $ = A((u, a) => ({
|
|
|
532
531
|
// Keep these in Zustand as they need React reactivity
|
|
533
532
|
serverStateUpdates: /* @__PURE__ */ new Map(),
|
|
534
533
|
setServerStateUpdate: (e, t) => {
|
|
535
|
-
u((
|
|
536
|
-
serverStateUpdates: new Map(
|
|
534
|
+
u((a) => ({
|
|
535
|
+
serverStateUpdates: new Map(a.serverStateUpdates).set(
|
|
537
536
|
e,
|
|
538
537
|
t
|
|
539
538
|
)
|
|
540
|
-
})),
|
|
539
|
+
})), o().notifyPathSubscribers(e, {
|
|
541
540
|
type: "SERVER_STATE_UPDATE",
|
|
542
541
|
serverState: t
|
|
543
542
|
});
|
|
544
543
|
},
|
|
545
544
|
pathSubscribers: /* @__PURE__ */ new Map(),
|
|
546
545
|
subscribeToPath: (e, t) => {
|
|
547
|
-
const
|
|
548
|
-
return n.add(t),
|
|
549
|
-
const s =
|
|
550
|
-
s && (s.delete(t), s.size === 0 &&
|
|
546
|
+
const a = o().pathSubscribers, n = a.get(e) || /* @__PURE__ */ new Set();
|
|
547
|
+
return n.add(t), a.set(e, n), () => {
|
|
548
|
+
const s = o().pathSubscribers.get(e);
|
|
549
|
+
s && (s.delete(t), s.size === 0 && o().pathSubscribers.delete(e));
|
|
551
550
|
};
|
|
552
551
|
},
|
|
553
552
|
notifyPathSubscribers: (e, t) => {
|
|
554
|
-
const n =
|
|
553
|
+
const n = o().pathSubscribers.get(e);
|
|
555
554
|
n && n.forEach((s) => s(t));
|
|
556
555
|
},
|
|
557
556
|
selectedIndicesMap: /* @__PURE__ */ new Map(),
|
|
558
557
|
getSelectedIndex: (e, t) => {
|
|
559
|
-
const
|
|
560
|
-
if (!
|
|
561
|
-
const n =
|
|
558
|
+
const a = o().selectedIndicesMap.get(e);
|
|
559
|
+
if (!a) return -1;
|
|
560
|
+
const n = o().getShadowMetadata(
|
|
562
561
|
e.split(".")[0],
|
|
563
562
|
e.split(".").slice(1)
|
|
564
563
|
), s = t || n?.arrayKeys;
|
|
565
|
-
return s ? s.indexOf(
|
|
564
|
+
return s ? s.indexOf(a) : -1;
|
|
566
565
|
},
|
|
567
566
|
setSelectedIndex: (e, t) => {
|
|
568
|
-
u((
|
|
569
|
-
const n = new Map(
|
|
570
|
-
return t === void 0 ? n.delete(e) : (n.has(e) &&
|
|
567
|
+
u((a) => {
|
|
568
|
+
const n = new Map(a.selectedIndicesMap);
|
|
569
|
+
return t === void 0 ? n.delete(e) : (n.has(e) && o().notifyPathSubscribers(n.get(e), {
|
|
571
570
|
type: "THIS_UNSELECTED"
|
|
572
|
-
}), n.set(e, t),
|
|
573
|
-
...
|
|
571
|
+
}), n.set(e, t), o().notifyPathSubscribers(t, { type: "THIS_SELECTED" })), o().notifyPathSubscribers(e, { type: "GET_SELECTED" }), {
|
|
572
|
+
...a,
|
|
574
573
|
selectedIndicesMap: n
|
|
575
574
|
};
|
|
576
575
|
});
|
|
577
576
|
},
|
|
578
577
|
clearSelectedIndex: ({ arrayKey: e }) => {
|
|
579
578
|
u((t) => {
|
|
580
|
-
const
|
|
581
|
-
return n &&
|
|
579
|
+
const a = new Map(t.selectedIndicesMap), n = a.get(e);
|
|
580
|
+
return n && o().notifyPathSubscribers(n, {
|
|
582
581
|
type: "CLEAR_SELECTION"
|
|
583
|
-
}),
|
|
582
|
+
}), a.delete(e), o().notifyPathSubscribers(e, {
|
|
584
583
|
type: "CLEAR_SELECTION"
|
|
585
584
|
}), {
|
|
586
585
|
...t,
|
|
587
|
-
selectedIndicesMap:
|
|
586
|
+
selectedIndicesMap: a
|
|
588
587
|
};
|
|
589
588
|
});
|
|
590
589
|
},
|
|
591
590
|
clearSelectedIndexesForState: (e) => {
|
|
592
591
|
u((t) => {
|
|
593
|
-
const
|
|
592
|
+
const a = new Map(t.selectedIndicesMap);
|
|
594
593
|
let n = !1;
|
|
595
|
-
for (const s of
|
|
596
|
-
(s === e || s.startsWith(e + ".")) && (
|
|
597
|
-
return n ? { selectedIndicesMap:
|
|
594
|
+
for (const s of a.keys())
|
|
595
|
+
(s === e || s.startsWith(e + ".")) && (a.delete(s), n = !0);
|
|
596
|
+
return n ? { selectedIndicesMap: a } : {};
|
|
598
597
|
});
|
|
599
598
|
},
|
|
600
599
|
initialStateOptions: {},
|
|
@@ -602,41 +601,41 @@ const $ = A((u, a) => ({
|
|
|
602
601
|
initialStateGlobal: {},
|
|
603
602
|
addStateLog: (e) => {
|
|
604
603
|
!e || e.length === 0 || u((t) => {
|
|
605
|
-
const
|
|
604
|
+
const a = new Map(t.stateLog), n = /* @__PURE__ */ new Map();
|
|
606
605
|
for (const s of e) {
|
|
607
606
|
const r = n.get(s.stateKey) || [];
|
|
608
607
|
r.push(s), n.set(s.stateKey, r);
|
|
609
608
|
}
|
|
610
609
|
for (const [s, r] of n.entries()) {
|
|
611
|
-
const i = new Map(
|
|
610
|
+
const i = new Map(a.get(s));
|
|
612
611
|
for (const c of r)
|
|
613
612
|
i.set(JSON.stringify(c.path), { ...c });
|
|
614
|
-
|
|
613
|
+
a.set(s, i);
|
|
615
614
|
}
|
|
616
|
-
return { stateLog:
|
|
615
|
+
return { stateLog: a };
|
|
617
616
|
});
|
|
618
617
|
},
|
|
619
|
-
getInitialOptions: (e) =>
|
|
618
|
+
getInitialOptions: (e) => o().initialStateOptions[e],
|
|
620
619
|
setInitialStateOptions: (e, t) => {
|
|
621
|
-
u((
|
|
622
|
-
initialStateOptions: { ...
|
|
620
|
+
u((a) => ({
|
|
621
|
+
initialStateOptions: { ...a.initialStateOptions, [e]: t }
|
|
623
622
|
}));
|
|
624
623
|
},
|
|
625
624
|
updateInitialStateGlobal: (e, t) => {
|
|
626
|
-
u((
|
|
627
|
-
initialStateGlobal: { ...
|
|
625
|
+
u((a) => ({
|
|
626
|
+
initialStateGlobal: { ...a.initialStateGlobal, [e]: t }
|
|
628
627
|
}));
|
|
629
628
|
},
|
|
630
629
|
syncInfoStore: /* @__PURE__ */ new Map(),
|
|
631
|
-
setSyncInfo: (e, t) => u((
|
|
632
|
-
const n = new Map(
|
|
630
|
+
setSyncInfo: (e, t) => u((a) => {
|
|
631
|
+
const n = new Map(a.syncInfoStore);
|
|
633
632
|
return n.set(e, t), { syncInfoStore: n };
|
|
634
633
|
}),
|
|
635
|
-
getSyncInfo: (e) =>
|
|
634
|
+
getSyncInfo: (e) => o().syncInfoStore.get(e) || null
|
|
636
635
|
}));
|
|
637
636
|
export {
|
|
638
637
|
_ as buildShadowNode,
|
|
639
|
-
|
|
638
|
+
M as generateId,
|
|
640
639
|
$ as getGlobalStore,
|
|
641
640
|
h as shadowStateStore,
|
|
642
641
|
N as updateShadowTypeInfo
|