cogsbox-state 0.5.466 → 0.5.468
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/dist/CogsState.d.ts.map +1 -1
- package/dist/CogsState.jsx +382 -388
- package/dist/CogsState.jsx.map +1 -1
- package/dist/Components.d.ts.map +1 -1
- package/dist/Components.jsx +24 -23
- package/dist/Components.jsx.map +1 -1
- package/dist/store.d.ts +0 -1
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +264 -268
- package/dist/store.js.map +1 -1
- package/package.json +1 -1
- package/src/CogsState.tsx +8 -16
- package/src/Components.tsx +1 -0
- package/src/store.ts +199 -164
package/dist/store.js
CHANGED
|
@@ -1,359 +1,355 @@
|
|
|
1
|
-
import { create as
|
|
1
|
+
import { create as w } from "zustand";
|
|
2
2
|
import { ulid as y } from "ulid";
|
|
3
|
-
const
|
|
3
|
+
const _ = w((l, a) => ({
|
|
4
4
|
formRefs: /* @__PURE__ */ new Map(),
|
|
5
|
-
registerFormRef: (
|
|
6
|
-
const
|
|
7
|
-
return
|
|
5
|
+
registerFormRef: (e, t) => l((o) => {
|
|
6
|
+
const n = new Map(o.formRefs);
|
|
7
|
+
return n.set(e, t), { formRefs: n };
|
|
8
8
|
}),
|
|
9
|
-
getFormRef: (
|
|
10
|
-
removeFormRef: (
|
|
11
|
-
const
|
|
12
|
-
return
|
|
9
|
+
getFormRef: (e) => a().formRefs.get(e),
|
|
10
|
+
removeFormRef: (e) => l((t) => {
|
|
11
|
+
const o = new Map(t.formRefs);
|
|
12
|
+
return o.delete(e), { formRefs: o };
|
|
13
13
|
}),
|
|
14
|
-
getFormRefsByStateKey: (
|
|
15
|
-
const
|
|
16
|
-
return
|
|
17
|
-
(
|
|
18
|
-
}),
|
|
14
|
+
getFormRefsByStateKey: (e) => {
|
|
15
|
+
const t = a().formRefs, o = e + ".", n = /* @__PURE__ */ new Map();
|
|
16
|
+
return t.forEach((s, r) => {
|
|
17
|
+
(r.startsWith(o) || r === e) && n.set(r, s);
|
|
18
|
+
}), n;
|
|
19
19
|
}
|
|
20
20
|
}));
|
|
21
|
-
function
|
|
22
|
-
if (
|
|
23
|
-
return { value:
|
|
24
|
-
if (Array.isArray(
|
|
25
|
-
const
|
|
26
|
-
return
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
}),
|
|
21
|
+
function m(l) {
|
|
22
|
+
if (l === null || typeof l != "object")
|
|
23
|
+
return { value: l };
|
|
24
|
+
if (Array.isArray(l)) {
|
|
25
|
+
const a = { _meta: { arrayKeys: [] } }, e = [];
|
|
26
|
+
return l.forEach((t) => {
|
|
27
|
+
const o = `id:${y()}`;
|
|
28
|
+
a[o] = m(t), e.push(o);
|
|
29
|
+
}), a._meta.arrayKeys = e, a;
|
|
30
30
|
}
|
|
31
|
-
if (
|
|
32
|
-
const
|
|
33
|
-
for (const
|
|
34
|
-
Object.prototype.hasOwnProperty.call(
|
|
35
|
-
return
|
|
31
|
+
if (l.constructor === Object) {
|
|
32
|
+
const a = { _meta: {} };
|
|
33
|
+
for (const e in l)
|
|
34
|
+
Object.prototype.hasOwnProperty.call(l, e) && (a[e] = m(l[e]));
|
|
35
|
+
return a;
|
|
36
36
|
}
|
|
37
|
-
return { value:
|
|
37
|
+
return { value: l };
|
|
38
38
|
}
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
setTransformCache: (t,
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
transformCaches:
|
|
39
|
+
const p = /* @__PURE__ */ new Map(), E = w((l, a) => ({
|
|
40
|
+
// Remove shadowStateStore from Zustand state
|
|
41
|
+
setTransformCache: (e, t, o, n) => {
|
|
42
|
+
const s = a().getShadowMetadata(e, t) || {};
|
|
43
|
+
s.transformCaches || (s.transformCaches = /* @__PURE__ */ new Map()), s.transformCaches.set(o, n), a().setShadowMetadata(e, t, {
|
|
44
|
+
transformCaches: s.transformCaches
|
|
45
45
|
});
|
|
46
46
|
},
|
|
47
|
-
initializeShadowState: (
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
return o.set(p, d), { shadowStateStore: o };
|
|
66
|
-
});
|
|
47
|
+
initializeShadowState: (e, t) => {
|
|
48
|
+
const o = p.get(e) || p.get(`[${e}`);
|
|
49
|
+
let n = {};
|
|
50
|
+
if (o?._meta) {
|
|
51
|
+
const {
|
|
52
|
+
components: i,
|
|
53
|
+
features: f,
|
|
54
|
+
lastServerSync: c,
|
|
55
|
+
stateSource: d,
|
|
56
|
+
baseServerState: u
|
|
57
|
+
} = o._meta;
|
|
58
|
+
i && (n.components = i), f && (n.features = f), c && (n.lastServerSync = c), d && (n.stateSource = d), u && (n.baseServerState = u);
|
|
59
|
+
}
|
|
60
|
+
p.delete(e), p.delete(`[${e}`);
|
|
61
|
+
const s = m(t);
|
|
62
|
+
s._meta || (s._meta = {}), Object.assign(s._meta, n);
|
|
63
|
+
const r = Array.isArray(t) ? `[${e}` : e;
|
|
64
|
+
p.set(r, s);
|
|
67
65
|
},
|
|
68
|
-
getShadowNode: (
|
|
69
|
-
|
|
70
|
-
let o = n.get(t) || n.get(`[${t}`);
|
|
66
|
+
getShadowNode: (e, t) => {
|
|
67
|
+
let o = p.get(e) || p.get(`[${e}`);
|
|
71
68
|
if (o) {
|
|
72
|
-
if (
|
|
73
|
-
for (const
|
|
74
|
-
if (typeof o != "object" || o === null || (o = o[
|
|
69
|
+
if (t.length === 0) return o;
|
|
70
|
+
for (const n of t)
|
|
71
|
+
if (typeof o != "object" || o === null || (o = o[n], o === void 0)) return;
|
|
75
72
|
return o;
|
|
76
73
|
}
|
|
77
74
|
},
|
|
78
|
-
getShadowMetadata: (
|
|
79
|
-
setShadowMetadata: (
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
return c._meta = { ...c._meta || {}, ...n }, { shadowStateStore: r };
|
|
92
|
-
});
|
|
75
|
+
getShadowMetadata: (e, t) => a().getShadowNode(e, t)?._meta,
|
|
76
|
+
setShadowMetadata: (e, t, o) => {
|
|
77
|
+
const n = p.has(`[${e}`) ? `[${e}` : e;
|
|
78
|
+
let s = p.get(n);
|
|
79
|
+
if (!s) {
|
|
80
|
+
s = { _meta: o }, p.set(n, s);
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
let r = s;
|
|
84
|
+
for (const i of t)
|
|
85
|
+
r[i] || (r[i] = {}), r = r[i];
|
|
86
|
+
r._meta || (r._meta = {}), Object.assign(r._meta, o);
|
|
93
87
|
},
|
|
94
|
-
getShadowValue: (t,
|
|
95
|
-
const
|
|
96
|
-
if (
|
|
97
|
-
const
|
|
98
|
-
if (Object.prototype.hasOwnProperty.call(
|
|
99
|
-
return
|
|
100
|
-
if (
|
|
101
|
-
return (
|
|
102
|
-
(
|
|
88
|
+
getShadowValue: (e, t, o, n) => {
|
|
89
|
+
const s = a().getShadowNode(e, t);
|
|
90
|
+
if (s == null) return;
|
|
91
|
+
const r = Object.keys(s);
|
|
92
|
+
if (Object.prototype.hasOwnProperty.call(s, "value") && r.every((d) => d === "value" || d === "_meta"))
|
|
93
|
+
return s.value;
|
|
94
|
+
if (s._meta && Object.prototype.hasOwnProperty.call(s._meta, "arrayKeys"))
|
|
95
|
+
return (o !== void 0 && o.length > 0 ? o : s._meta.arrayKeys).map(
|
|
96
|
+
(u) => a().getShadowValue(e, [...t, u])
|
|
103
97
|
);
|
|
104
98
|
const c = {};
|
|
105
|
-
for (const
|
|
106
|
-
|
|
99
|
+
for (const d of r)
|
|
100
|
+
d !== "_meta" && !d.startsWith("id:") && (c[d] = a().getShadowValue(e, [...t, d]));
|
|
107
101
|
return c;
|
|
108
102
|
},
|
|
109
|
-
updateShadowAtPath: (
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
r
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
const i = e.length === 0 ? c : c[e[e.length - 1]];
|
|
120
|
-
if (!i)
|
|
121
|
-
return c[e[e.length - 1]] = w(n), { shadowStateStore: r };
|
|
122
|
-
function S(l, u) {
|
|
123
|
-
if (typeof u != "object" || u === null || Array.isArray(u)) {
|
|
124
|
-
const h = l._meta, m = w(u);
|
|
125
|
-
h && (m._meta = { ...h, ...m._meta || {} }), Object.keys(l).forEach((g) => delete l[g]), Object.assign(l, m);
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
const b = new Set(Object.keys(u));
|
|
129
|
-
for (const h of b) {
|
|
130
|
-
const m = u[h];
|
|
131
|
-
l[h] ? S(l[h], m) : l[h] = w(m);
|
|
132
|
-
}
|
|
133
|
-
for (const h in l)
|
|
134
|
-
h === "_meta" || !Object.prototype.hasOwnProperty.call(l, h) || b.has(h) || delete l[h];
|
|
135
|
-
}
|
|
136
|
-
return S(i, n), s().notifyPathSubscribers([t, ...e].join("."), {
|
|
103
|
+
updateShadowAtPath: (e, t, o) => {
|
|
104
|
+
const n = p.has(`[${e}`) ? `[${e}` : e;
|
|
105
|
+
let s = p.get(n);
|
|
106
|
+
if (!s) return;
|
|
107
|
+
let r = s;
|
|
108
|
+
for (let c = 0; c < t.length - 1; c++)
|
|
109
|
+
r[t[c]] || (r[t[c]] = {}), r = r[t[c]];
|
|
110
|
+
const i = t.length === 0 ? r : r[t[t.length - 1]];
|
|
111
|
+
if (!i) {
|
|
112
|
+
r[t[t.length - 1]] = m(o), a().notifyPathSubscribers([e, ...t].join("."), {
|
|
137
113
|
type: "UPDATE",
|
|
138
|
-
newValue:
|
|
139
|
-
})
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
114
|
+
newValue: o
|
|
115
|
+
});
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
function f(c, d) {
|
|
119
|
+
if (typeof d != "object" || d === null || Array.isArray(d)) {
|
|
120
|
+
const S = c._meta;
|
|
121
|
+
for (const b in c)
|
|
122
|
+
b !== "_meta" && delete c[b];
|
|
123
|
+
const h = m(d);
|
|
124
|
+
Object.assign(c, h), S && (c._meta = { ...S, ...c._meta || {} });
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
const u = new Set(Object.keys(d));
|
|
128
|
+
for (const S of u) {
|
|
129
|
+
const h = d[S];
|
|
130
|
+
c[S] ? f(c[S], h) : c[S] = m(h);
|
|
154
131
|
}
|
|
155
|
-
|
|
132
|
+
for (const S in c)
|
|
133
|
+
S === "_meta" || !Object.prototype.hasOwnProperty.call(c, S) || u.has(S) || delete c[S];
|
|
134
|
+
}
|
|
135
|
+
f(i, o), a().notifyPathSubscribers([e, ...t].join("."), {
|
|
136
|
+
type: "UPDATE",
|
|
137
|
+
newValue: o
|
|
156
138
|
});
|
|
157
139
|
},
|
|
158
|
-
|
|
159
|
-
const
|
|
160
|
-
|
|
140
|
+
addItemsToArrayNode: (e, t, o, n) => {
|
|
141
|
+
const s = p.has(`[${e}`) ? `[${e}` : e;
|
|
142
|
+
let r = p.get(s);
|
|
143
|
+
if (!r) {
|
|
144
|
+
console.error("Root not found for state key:", e);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
let i = r;
|
|
148
|
+
for (const f of t)
|
|
149
|
+
i[f] || (i[f] = {}), i = i[f];
|
|
150
|
+
Object.assign(i, o), i._meta || (i._meta = {}), i._meta.arrayKeys = n;
|
|
151
|
+
},
|
|
152
|
+
insertShadowArrayElement: (e, t, o, n) => {
|
|
153
|
+
const s = a().getShadowNode(e, t);
|
|
154
|
+
if (!s?._meta?.arrayKeys) {
|
|
161
155
|
console.error(
|
|
162
|
-
`Array not found at path: ${[
|
|
156
|
+
`Array not found at path: ${[e, ...t].join(".")}`
|
|
163
157
|
);
|
|
164
158
|
return;
|
|
165
159
|
}
|
|
166
|
-
const
|
|
167
|
-
c.splice(
|
|
168
|
-
const
|
|
169
|
-
|
|
160
|
+
const r = `id:${y()}`, i = { [r]: m(o) }, f = s._meta.arrayKeys, c = n !== void 0 && n >= 0 && n <= f.length ? n : f.length;
|
|
161
|
+
c >= f.length ? f.push(r) : f.splice(c, 0, r), a().addItemsToArrayNode(e, t, i, f);
|
|
162
|
+
const d = [e, ...t].join(".");
|
|
163
|
+
a().notifyPathSubscribers(d, {
|
|
170
164
|
type: "INSERT",
|
|
171
|
-
path:
|
|
172
|
-
itemKey: `${
|
|
173
|
-
index:
|
|
165
|
+
path: d,
|
|
166
|
+
itemKey: `${d}.${r}`,
|
|
167
|
+
index: c
|
|
174
168
|
});
|
|
175
169
|
},
|
|
176
|
-
insertManyShadowArrayElements: (t,
|
|
177
|
-
if (!
|
|
170
|
+
insertManyShadowArrayElements: (e, t, o, n) => {
|
|
171
|
+
if (!o || o.length === 0)
|
|
178
172
|
return;
|
|
179
|
-
const
|
|
180
|
-
if (!
|
|
173
|
+
const s = a().getShadowNode(e, t);
|
|
174
|
+
if (!s?._meta?.arrayKeys) {
|
|
181
175
|
console.error(
|
|
182
|
-
`Array not found at path: ${[
|
|
176
|
+
`Array not found at path: ${[e, ...t].join(".")}`
|
|
183
177
|
);
|
|
184
178
|
return;
|
|
185
179
|
}
|
|
186
|
-
const
|
|
187
|
-
|
|
188
|
-
const
|
|
189
|
-
|
|
180
|
+
const r = {}, i = [];
|
|
181
|
+
o.forEach((u) => {
|
|
182
|
+
const S = `id:${y()}`;
|
|
183
|
+
i.push(S), r[S] = m(u);
|
|
190
184
|
});
|
|
191
|
-
const
|
|
192
|
-
c.splice(
|
|
193
|
-
const
|
|
194
|
-
|
|
185
|
+
const f = s._meta.arrayKeys, c = n !== void 0 && n >= 0 && n <= f.length ? n : f.length;
|
|
186
|
+
c >= f.length ? f.push(...i) : f.splice(c, 0, ...i), a().addItemsToArrayNode(e, t, r, f);
|
|
187
|
+
const d = [e, ...t].join(".");
|
|
188
|
+
a().notifyPathSubscribers(d, {
|
|
195
189
|
type: "INSERT_MANY",
|
|
196
|
-
path:
|
|
197
|
-
count:
|
|
198
|
-
index:
|
|
190
|
+
path: d,
|
|
191
|
+
count: o.length,
|
|
192
|
+
index: c
|
|
199
193
|
});
|
|
200
194
|
},
|
|
201
|
-
removeShadowArrayElement: (
|
|
202
|
-
if (
|
|
203
|
-
const
|
|
204
|
-
if (!
|
|
205
|
-
const
|
|
206
|
-
if (!
|
|
207
|
-
const
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
195
|
+
removeShadowArrayElement: (e, t) => {
|
|
196
|
+
if (t.length === 0) return;
|
|
197
|
+
const o = t.slice(0, -1), n = t[t.length - 1];
|
|
198
|
+
if (!n?.startsWith("id:")) return;
|
|
199
|
+
const s = a().getShadowNode(e, o);
|
|
200
|
+
if (!s?._meta?.arrayKeys) return;
|
|
201
|
+
const r = s._meta.arrayKeys, i = r.indexOf(n);
|
|
202
|
+
if (i === -1) return;
|
|
203
|
+
i === r.length - 1 ? r.pop() : i === 0 ? r.shift() : r.splice(i, 1), delete s[n];
|
|
204
|
+
const f = [e, ...o].join(".");
|
|
205
|
+
a().notifyPathSubscribers(f, {
|
|
211
206
|
type: "REMOVE",
|
|
212
|
-
path:
|
|
213
|
-
itemKey: `${
|
|
207
|
+
path: f,
|
|
208
|
+
itemKey: `${f}.${n}`
|
|
214
209
|
});
|
|
215
210
|
},
|
|
216
|
-
|
|
217
|
-
const
|
|
218
|
-
|
|
219
|
-
|
|
211
|
+
registerComponent: (e, t, o) => {
|
|
212
|
+
const n = a().getShadowMetadata(e, []) || {}, s = new Map(n.components);
|
|
213
|
+
s.set(t, o), a().setShadowMetadata(e, [], { components: s });
|
|
214
|
+
},
|
|
215
|
+
unregisterComponent: (e, t) => {
|
|
216
|
+
const o = a().getShadowMetadata(e, []);
|
|
217
|
+
if (!o?.components) return;
|
|
218
|
+
const n = new Map(o.components);
|
|
219
|
+
n.delete(t) && a().setShadowMetadata(e, [], { components: n });
|
|
220
|
+
},
|
|
221
|
+
addPathComponent: (e, t, o) => {
|
|
222
|
+
const n = a().getShadowMetadata(e, t) || {}, s = new Set(n.pathComponents);
|
|
223
|
+
s.add(o), a().setShadowMetadata(e, t, {
|
|
224
|
+
pathComponents: s
|
|
220
225
|
});
|
|
221
|
-
const
|
|
222
|
-
if (
|
|
223
|
-
const
|
|
224
|
-
if (
|
|
225
|
-
const
|
|
226
|
-
c.add(
|
|
227
|
-
const
|
|
228
|
-
|
|
226
|
+
const r = a().getShadowMetadata(e, []);
|
|
227
|
+
if (r?.components) {
|
|
228
|
+
const i = r.components.get(o);
|
|
229
|
+
if (i) {
|
|
230
|
+
const f = [e, ...t].join("."), c = new Set(i.paths);
|
|
231
|
+
c.add(f);
|
|
232
|
+
const d = { ...i, paths: c }, u = new Map(r.components);
|
|
233
|
+
u.set(o, d), a().setShadowMetadata(e, [], { components: u });
|
|
229
234
|
}
|
|
230
235
|
}
|
|
231
236
|
},
|
|
232
|
-
|
|
233
|
-
const
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
const n = s().getShadowMetadata(t, []);
|
|
238
|
-
if (!n?.components) return;
|
|
239
|
-
const o = new Map(n.components);
|
|
240
|
-
o.delete(e) && s().setShadowMetadata(t, [], { components: o });
|
|
241
|
-
},
|
|
242
|
-
markAsDirty: (t, e, n = { bubble: !0 }) => {
|
|
243
|
-
const o = (r) => s().getShadowNode(t, r)?._meta?.isDirty ? !0 : (s().setShadowMetadata(t, r, { isDirty: !0 }), !1);
|
|
244
|
-
if (o(e), n.bubble) {
|
|
245
|
-
let r = [...e];
|
|
246
|
-
for (; r.length > 0 && (r.pop(), !o(r)); )
|
|
237
|
+
markAsDirty: (e, t, o = { bubble: !0 }) => {
|
|
238
|
+
const n = (s) => a().getShadowNode(e, s)?._meta?.isDirty ? !0 : (a().setShadowMetadata(e, s, { isDirty: !0 }), !1);
|
|
239
|
+
if (n(t), o.bubble) {
|
|
240
|
+
let s = [...t];
|
|
241
|
+
for (; s.length > 0 && (s.pop(), !n(s)); )
|
|
247
242
|
;
|
|
248
243
|
}
|
|
249
244
|
},
|
|
245
|
+
// Keep these in Zustand as they need React reactivity
|
|
250
246
|
serverStateUpdates: /* @__PURE__ */ new Map(),
|
|
251
|
-
setServerStateUpdate: (
|
|
252
|
-
|
|
253
|
-
serverStateUpdates: new Map(
|
|
254
|
-
|
|
255
|
-
|
|
247
|
+
setServerStateUpdate: (e, t) => {
|
|
248
|
+
l((o) => ({
|
|
249
|
+
serverStateUpdates: new Map(o.serverStateUpdates).set(
|
|
250
|
+
e,
|
|
251
|
+
t
|
|
256
252
|
)
|
|
257
|
-
})),
|
|
253
|
+
})), a().notifyPathSubscribers(e, {
|
|
258
254
|
type: "SERVER_STATE_UPDATE",
|
|
259
|
-
serverState:
|
|
255
|
+
serverState: t
|
|
260
256
|
});
|
|
261
257
|
},
|
|
262
258
|
pathSubscribers: /* @__PURE__ */ new Map(),
|
|
263
|
-
subscribeToPath: (
|
|
264
|
-
const
|
|
265
|
-
return
|
|
266
|
-
const
|
|
267
|
-
|
|
259
|
+
subscribeToPath: (e, t) => {
|
|
260
|
+
const o = a().pathSubscribers, n = o.get(e) || /* @__PURE__ */ new Set();
|
|
261
|
+
return n.add(t), o.set(e, n), () => {
|
|
262
|
+
const s = a().pathSubscribers.get(e);
|
|
263
|
+
s && (s.delete(t), s.size === 0 && a().pathSubscribers.delete(e));
|
|
268
264
|
};
|
|
269
265
|
},
|
|
270
|
-
notifyPathSubscribers: (
|
|
271
|
-
const
|
|
272
|
-
|
|
266
|
+
notifyPathSubscribers: (e, t) => {
|
|
267
|
+
const n = a().pathSubscribers.get(e);
|
|
268
|
+
n && n.forEach((s) => s(t));
|
|
273
269
|
},
|
|
274
270
|
selectedIndicesMap: /* @__PURE__ */ new Map(),
|
|
275
|
-
getSelectedIndex: (
|
|
276
|
-
const
|
|
277
|
-
if (!
|
|
278
|
-
const
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
),
|
|
282
|
-
return
|
|
271
|
+
getSelectedIndex: (e, t) => {
|
|
272
|
+
const o = a().selectedIndicesMap.get(e);
|
|
273
|
+
if (!o) return -1;
|
|
274
|
+
const n = a().getShadowMetadata(
|
|
275
|
+
e.split(".")[0],
|
|
276
|
+
e.split(".").slice(1)
|
|
277
|
+
), s = t || n?.arrayKeys;
|
|
278
|
+
return s ? s.indexOf(o) : -1;
|
|
283
279
|
},
|
|
284
|
-
setSelectedIndex: (
|
|
285
|
-
|
|
286
|
-
const
|
|
287
|
-
return
|
|
280
|
+
setSelectedIndex: (e, t) => {
|
|
281
|
+
l((o) => {
|
|
282
|
+
const n = new Map(o.selectedIndicesMap);
|
|
283
|
+
return t === void 0 ? n.delete(e) : (n.has(e) && a().notifyPathSubscribers(n.get(e), {
|
|
288
284
|
type: "THIS_UNSELECTED"
|
|
289
|
-
}),
|
|
290
|
-
...
|
|
291
|
-
selectedIndicesMap:
|
|
285
|
+
}), n.set(e, t), a().notifyPathSubscribers(t, { type: "THIS_SELECTED" })), a().notifyPathSubscribers(e, { type: "GET_SELECTED" }), {
|
|
286
|
+
...o,
|
|
287
|
+
selectedIndicesMap: n
|
|
292
288
|
};
|
|
293
289
|
});
|
|
294
290
|
},
|
|
295
|
-
clearSelectedIndex: ({ arrayKey:
|
|
296
|
-
|
|
297
|
-
const
|
|
298
|
-
return
|
|
291
|
+
clearSelectedIndex: ({ arrayKey: e }) => {
|
|
292
|
+
l((t) => {
|
|
293
|
+
const o = new Map(t.selectedIndicesMap), n = o.get(e);
|
|
294
|
+
return n && a().notifyPathSubscribers(n, {
|
|
299
295
|
type: "CLEAR_SELECTION"
|
|
300
|
-
}),
|
|
296
|
+
}), o.delete(e), a().notifyPathSubscribers(e, {
|
|
301
297
|
type: "CLEAR_SELECTION"
|
|
302
298
|
}), {
|
|
303
|
-
...
|
|
304
|
-
selectedIndicesMap:
|
|
299
|
+
...t,
|
|
300
|
+
selectedIndicesMap: o
|
|
305
301
|
};
|
|
306
302
|
});
|
|
307
303
|
},
|
|
308
|
-
clearSelectedIndexesForState: (
|
|
309
|
-
|
|
310
|
-
const
|
|
311
|
-
let
|
|
312
|
-
for (const
|
|
313
|
-
(
|
|
314
|
-
return
|
|
304
|
+
clearSelectedIndexesForState: (e) => {
|
|
305
|
+
l((t) => {
|
|
306
|
+
const o = new Map(t.selectedIndicesMap);
|
|
307
|
+
let n = !1;
|
|
308
|
+
for (const s of o.keys())
|
|
309
|
+
(s === e || s.startsWith(e + ".")) && (o.delete(s), n = !0);
|
|
310
|
+
return n ? { selectedIndicesMap: o } : {};
|
|
315
311
|
});
|
|
316
312
|
},
|
|
317
313
|
initialStateOptions: {},
|
|
318
314
|
stateLog: /* @__PURE__ */ new Map(),
|
|
319
315
|
initialStateGlobal: {},
|
|
320
|
-
addStateLog: (
|
|
321
|
-
!
|
|
322
|
-
const
|
|
323
|
-
for (const
|
|
324
|
-
const
|
|
325
|
-
|
|
316
|
+
addStateLog: (e) => {
|
|
317
|
+
!e || e.length === 0 || l((t) => {
|
|
318
|
+
const o = new Map(t.stateLog), n = /* @__PURE__ */ new Map();
|
|
319
|
+
for (const s of e) {
|
|
320
|
+
const r = n.get(s.stateKey) || [];
|
|
321
|
+
r.push(s), n.set(s.stateKey, r);
|
|
326
322
|
}
|
|
327
|
-
for (const [
|
|
328
|
-
const
|
|
329
|
-
for (const
|
|
330
|
-
|
|
331
|
-
|
|
323
|
+
for (const [s, r] of n.entries()) {
|
|
324
|
+
const i = new Map(o.get(s));
|
|
325
|
+
for (const f of r)
|
|
326
|
+
i.set(JSON.stringify(f.path), { ...f });
|
|
327
|
+
o.set(s, i);
|
|
332
328
|
}
|
|
333
|
-
return { stateLog:
|
|
329
|
+
return { stateLog: o };
|
|
334
330
|
});
|
|
335
331
|
},
|
|
336
|
-
getInitialOptions: (
|
|
337
|
-
setInitialStateOptions: (
|
|
338
|
-
|
|
339
|
-
initialStateOptions: { ...
|
|
332
|
+
getInitialOptions: (e) => a().initialStateOptions[e],
|
|
333
|
+
setInitialStateOptions: (e, t) => {
|
|
334
|
+
l((o) => ({
|
|
335
|
+
initialStateOptions: { ...o.initialStateOptions, [e]: t }
|
|
340
336
|
}));
|
|
341
337
|
},
|
|
342
|
-
updateInitialStateGlobal: (
|
|
343
|
-
|
|
344
|
-
initialStateGlobal: { ...
|
|
338
|
+
updateInitialStateGlobal: (e, t) => {
|
|
339
|
+
l((o) => ({
|
|
340
|
+
initialStateGlobal: { ...o.initialStateGlobal, [e]: t }
|
|
345
341
|
}));
|
|
346
342
|
},
|
|
347
343
|
syncInfoStore: /* @__PURE__ */ new Map(),
|
|
348
|
-
setSyncInfo: (
|
|
349
|
-
const
|
|
350
|
-
return
|
|
344
|
+
setSyncInfo: (e, t) => l((o) => {
|
|
345
|
+
const n = new Map(o.syncInfoStore);
|
|
346
|
+
return n.set(e, t), { syncInfoStore: n };
|
|
351
347
|
}),
|
|
352
|
-
getSyncInfo: (
|
|
348
|
+
getSyncInfo: (e) => a().syncInfoStore.get(e) || null
|
|
353
349
|
}));
|
|
354
350
|
export {
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
351
|
+
m as buildShadowNode,
|
|
352
|
+
_ as formRefStore,
|
|
353
|
+
E as getGlobalStore
|
|
358
354
|
};
|
|
359
355
|
//# sourceMappingURL=store.js.map
|