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