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/store.js CHANGED
@@ -1,359 +1,355 @@
1
- import { create as M } from "zustand";
1
+ import { create as w } from "zustand";
2
2
  import { ulid as y } from "ulid";
3
- const I = M((f, s) => ({
3
+ const _ = w((l, a) => ({
4
4
  formRefs: /* @__PURE__ */ new Map(),
5
- registerFormRef: (t, e) => f((n) => {
6
- const o = new Map(n.formRefs);
7
- return o.set(t, e), { formRefs: o };
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: (t) => s().formRefs.get(t),
10
- removeFormRef: (t) => f((e) => {
11
- const n = new Map(e.formRefs);
12
- return n.delete(t), { formRefs: n };
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: (t) => {
15
- const e = s().formRefs, n = t + ".", o = /* @__PURE__ */ new Map();
16
- return e.forEach((r, a) => {
17
- (a.startsWith(n) || a === t) && o.set(a, r);
18
- }), o;
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 w(f) {
22
- if (f === null || typeof f != "object")
23
- return { value: f };
24
- if (Array.isArray(f)) {
25
- const s = { _meta: { arrayKeys: [] } }, t = [];
26
- return f.forEach((e) => {
27
- const n = `id:${y()}`;
28
- s[n] = w(e), t.push(n);
29
- }), s._meta.arrayKeys = t, s;
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 (f.constructor === Object) {
32
- const s = { _meta: {} };
33
- for (const t in f)
34
- Object.prototype.hasOwnProperty.call(f, t) && (s[t] = w(f[t]));
35
- return s;
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: f };
37
+ return { value: l };
38
38
  }
39
- const N = M((f, s) => ({
40
- shadowStateStore: /* @__PURE__ */ new Map(),
41
- setTransformCache: (t, e, n, o) => {
42
- const r = s().getShadowMetadata(t, e) || {};
43
- r.transformCaches || (r.transformCaches = /* @__PURE__ */ new Map()), r.transformCaches.set(n, o), s().setShadowMetadata(t, e, {
44
- transformCaches: r.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: (t, e) => {
48
- f((n) => {
49
- const o = new Map(n.shadowStateStore), r = o.get(t) || o.get(`[${t}`);
50
- let a = {};
51
- if (r?._meta) {
52
- const {
53
- components: c,
54
- features: i,
55
- lastServerSync: S,
56
- stateSource: l,
57
- baseServerState: u
58
- } = r._meta;
59
- c && (a.components = c), i && (a.features = i), S && (a.lastServerSync = S), l && (a.stateSource = l), u && (a.baseServerState = u);
60
- }
61
- o.delete(t), o.delete(`[${t}`);
62
- const d = w(e);
63
- d._meta || (d._meta = {}), Object.assign(d._meta, a);
64
- const p = Array.isArray(e) ? `[${t}` : t;
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: (t, e) => {
69
- const n = s().shadowStateStore;
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 (e.length === 0) return o;
73
- for (const r of e)
74
- if (typeof o != "object" || o === null || (o = o[r], o === void 0)) return;
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: (t, e) => s().getShadowNode(t, e)?._meta,
79
- setShadowMetadata: (t, e, n) => {
80
- f((o) => {
81
- const r = new Map(o.shadowStateStore), a = r.has(`[${t}`) ? `[${t}` : t;
82
- let d = r.get(a);
83
- d || (d = {}, r.set(a, d));
84
- const p = { ...d };
85
- r.set(a, p);
86
- let c = p;
87
- for (const i of e) {
88
- const S = c[i] || {};
89
- c[i] = { ...S }, c = c[i];
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, e, n, o) => {
95
- const r = s().getShadowNode(t, e);
96
- if (r == null) return;
97
- const a = Object.keys(r);
98
- if (Object.prototype.hasOwnProperty.call(r, "value") && a.every((i) => i === "value" || i === "_meta"))
99
- return r.value;
100
- if (r._meta && Object.prototype.hasOwnProperty.call(r._meta, "arrayKeys"))
101
- return (n !== void 0 && n.length > 0 ? n : r._meta.arrayKeys).map(
102
- (S) => s().getShadowValue(t, [...e, S])
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 i of a)
106
- i !== "_meta" && !i.startsWith("id:") && (c[i] = s().getShadowValue(t, [...e, i]));
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: (t, e, n) => {
110
- f((o) => {
111
- const r = new Map(o.shadowStateStore), a = r.has(`[${t}`) ? `[${t}` : t;
112
- let d = r.get(a);
113
- if (!d) return o;
114
- const p = { ...d };
115
- r.set(a, p);
116
- let c = p;
117
- for (let l = 0; l < e.length - 1; l++)
118
- c[e[l]] = { ...c[e[l]] || {} }, c = c[e[l]];
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: n
139
- }), { shadowStateStore: r };
140
- });
141
- },
142
- addItemsToArrayNode: (t, e, n, o) => {
143
- f((r) => {
144
- const a = new Map(r.shadowStateStore), d = a.has(`[${t}`) ? `[${t}` : t;
145
- let p = a.get(d);
146
- if (!p)
147
- return console.error("Root not found for state key:", t), r;
148
- const c = { ...p };
149
- a.set(d, c);
150
- let i = c;
151
- for (const S of e) {
152
- const l = i[S] || {};
153
- i[S] = { ...l }, i = i[S];
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
- return Object.assign(i, n), i._meta = { ...i._meta || {}, arrayKeys: o }, { shadowStateStore: a };
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
- insertShadowArrayElement: (t, e, n, o) => {
159
- const r = s().getShadowNode(t, e);
160
- if (!r?._meta?.arrayKeys) {
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: ${[t, ...e].join(".")}`
156
+ `Array not found at path: ${[e, ...t].join(".")}`
163
157
  );
164
158
  return;
165
159
  }
166
- const a = `id:${y()}`, d = { [a]: w(n) }, c = [...r._meta.arrayKeys], i = o !== void 0 && o >= 0 && o <= c.length ? o : c.length;
167
- c.splice(i, 0, a), s().addItemsToArrayNode(t, e, d, c);
168
- const S = [t, ...e].join(".");
169
- s().notifyPathSubscribers(S, {
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: S,
172
- itemKey: `${S}.${a}`,
173
- index: i
165
+ path: d,
166
+ itemKey: `${d}.${r}`,
167
+ index: c
174
168
  });
175
169
  },
176
- insertManyShadowArrayElements: (t, e, n, o) => {
177
- if (!n || n.length === 0)
170
+ insertManyShadowArrayElements: (e, t, o, n) => {
171
+ if (!o || o.length === 0)
178
172
  return;
179
- const r = s().getShadowNode(t, e);
180
- if (!r?._meta?.arrayKeys) {
173
+ const s = a().getShadowNode(e, t);
174
+ if (!s?._meta?.arrayKeys) {
181
175
  console.error(
182
- `Array not found at path: ${[t, ...e].join(".")}`
176
+ `Array not found at path: ${[e, ...t].join(".")}`
183
177
  );
184
178
  return;
185
179
  }
186
- const a = {}, d = [];
187
- n.forEach((l) => {
188
- const u = `id:${y()}`;
189
- d.push(u), a[u] = w(l);
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 c = [...r._meta.arrayKeys], i = o !== void 0 && o >= 0 && o <= c.length ? o : c.length;
192
- c.splice(i, 0, ...d), s().addItemsToArrayNode(t, e, a, c);
193
- const S = [t, ...e].join(".");
194
- s().notifyPathSubscribers(S, {
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: S,
197
- count: n.length,
198
- index: i
190
+ path: d,
191
+ count: o.length,
192
+ index: c
199
193
  });
200
194
  },
201
- removeShadowArrayElement: (t, e) => {
202
- if (e.length === 0) return;
203
- const n = e.slice(0, -1), o = e[e.length - 1];
204
- if (!o?.startsWith("id:")) return;
205
- const r = s().getShadowNode(t, n);
206
- if (!r?._meta?.arrayKeys) return;
207
- const a = r._meta.arrayKeys.filter((p) => p !== o);
208
- delete r[o], s().setShadowMetadata(t, n, { arrayKeys: a });
209
- const d = [t, ...n].join(".");
210
- s().notifyPathSubscribers(d, {
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: d,
213
- itemKey: `${d}.${o}`
207
+ path: f,
208
+ itemKey: `${f}.${n}`
214
209
  });
215
210
  },
216
- addPathComponent: (t, e, n) => {
217
- const o = s().getShadowMetadata(t, e) || {}, r = new Set(o.pathComponents);
218
- r.add(n), s().setShadowMetadata(t, e, {
219
- pathComponents: r
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 a = s().getShadowMetadata(t, []);
222
- if (a?.components) {
223
- const d = a.components.get(n);
224
- if (d) {
225
- const p = [t, ...e].join("."), c = new Set(d.paths);
226
- c.add(p);
227
- const i = { ...d, paths: c }, S = new Map(a.components);
228
- S.set(n, i), s().setShadowMetadata(t, [], { components: S });
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
- registerComponent: (t, e, n) => {
233
- const o = s().getShadowMetadata(t, []) || {}, r = new Map(o.components);
234
- r.set(e, n), s().setShadowMetadata(t, [], { components: r });
235
- },
236
- unregisterComponent: (t, e) => {
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: (t, e) => {
252
- f((n) => ({
253
- serverStateUpdates: new Map(n.serverStateUpdates).set(
254
- t,
255
- e
247
+ setServerStateUpdate: (e, t) => {
248
+ l((o) => ({
249
+ serverStateUpdates: new Map(o.serverStateUpdates).set(
250
+ e,
251
+ t
256
252
  )
257
- })), s().notifyPathSubscribers(t, {
253
+ })), a().notifyPathSubscribers(e, {
258
254
  type: "SERVER_STATE_UPDATE",
259
- serverState: e
255
+ serverState: t
260
256
  });
261
257
  },
262
258
  pathSubscribers: /* @__PURE__ */ new Map(),
263
- subscribeToPath: (t, e) => {
264
- const n = s().pathSubscribers, o = n.get(t) || /* @__PURE__ */ new Set();
265
- return o.add(e), n.set(t, o), () => {
266
- const r = s().pathSubscribers.get(t);
267
- r && (r.delete(e), r.size === 0 && s().pathSubscribers.delete(t));
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: (t, e) => {
271
- const o = s().pathSubscribers.get(t);
272
- o && o.forEach((r) => r(e));
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: (t, e) => {
276
- const n = s().selectedIndicesMap.get(t);
277
- if (!n) return -1;
278
- const o = s().getShadowMetadata(
279
- t.split(".")[0],
280
- t.split(".").slice(1)
281
- ), r = e || o?.arrayKeys;
282
- return r ? r.indexOf(n) : -1;
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: (t, e) => {
285
- f((n) => {
286
- const o = new Map(n.selectedIndicesMap);
287
- return e === void 0 ? o.delete(t) : (o.has(t) && s().notifyPathSubscribers(o.get(t), {
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
- }), o.set(t, e), s().notifyPathSubscribers(e, { type: "THIS_SELECTED" })), s().notifyPathSubscribers(t, { type: "GET_SELECTED" }), {
290
- ...n,
291
- selectedIndicesMap: o
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: t }) => {
296
- f((e) => {
297
- const n = new Map(e.selectedIndicesMap), o = n.get(t);
298
- return o && s().notifyPathSubscribers(o, {
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
- }), n.delete(t), s().notifyPathSubscribers(t, {
296
+ }), o.delete(e), a().notifyPathSubscribers(e, {
301
297
  type: "CLEAR_SELECTION"
302
298
  }), {
303
- ...e,
304
- selectedIndicesMap: n
299
+ ...t,
300
+ selectedIndicesMap: o
305
301
  };
306
302
  });
307
303
  },
308
- clearSelectedIndexesForState: (t) => {
309
- f((e) => {
310
- const n = new Map(e.selectedIndicesMap);
311
- let o = !1;
312
- for (const r of n.keys())
313
- (r === t || r.startsWith(t + ".")) && (n.delete(r), o = !0);
314
- return o ? { selectedIndicesMap: n } : {};
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: (t) => {
321
- !t || t.length === 0 || f((e) => {
322
- const n = new Map(e.stateLog), o = /* @__PURE__ */ new Map();
323
- for (const r of t) {
324
- const a = o.get(r.stateKey) || [];
325
- a.push(r), o.set(r.stateKey, a);
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 [r, a] of o.entries()) {
328
- const d = new Map(n.get(r));
329
- for (const p of a)
330
- d.set(JSON.stringify(p.path), { ...p });
331
- n.set(r, d);
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: n };
329
+ return { stateLog: o };
334
330
  });
335
331
  },
336
- getInitialOptions: (t) => s().initialStateOptions[t],
337
- setInitialStateOptions: (t, e) => {
338
- f((n) => ({
339
- initialStateOptions: { ...n.initialStateOptions, [t]: e }
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: (t, e) => {
343
- f((n) => ({
344
- initialStateGlobal: { ...n.initialStateGlobal, [t]: e }
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: (t, e) => f((n) => {
349
- const o = new Map(n.syncInfoStore);
350
- return o.set(t, e), { syncInfoStore: o };
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: (t) => s().syncInfoStore.get(t) || null
348
+ getSyncInfo: (e) => a().syncInfoStore.get(e) || null
353
349
  }));
354
350
  export {
355
- w as buildShadowNode,
356
- I as formRefStore,
357
- N as getGlobalStore
351
+ m as buildShadowNode,
352
+ _ as formRefStore,
353
+ E as getGlobalStore
358
354
  };
359
355
  //# sourceMappingURL=store.js.map