react-state-custom 1.0.19 → 1.0.21

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/index.es.js CHANGED
@@ -1,25 +1,25 @@
1
- import { useRef as D, useMemo as d, useEffect as b, useState as S, useCallback as O, Fragment as R } from "react";
2
- import { jsx as g, Fragment as T } from "react/jsx-runtime";
3
- function w(t, e) {
4
- let r = null, s = function(...u) {
5
- r && clearTimeout(r), r = setTimeout(() => {
6
- t(...u);
1
+ import { useRef as w, useMemo as g, useEffect as f, useState as v, useCallback as $, Fragment as F, createElement as G } from "react";
2
+ import { jsx as o, Fragment as O, jsxs as m } from "react/jsx-runtime";
3
+ function C(t, e) {
4
+ let n = null, a = function(...r) {
5
+ n && clearTimeout(n), n = setTimeout(() => {
6
+ t(...r);
7
7
  }, e);
8
8
  };
9
- return s.cancel = () => clearTimeout(r), s;
9
+ return a.cancel = () => clearTimeout(n), a;
10
10
  }
11
- function V(t) {
12
- const e = /* @__PURE__ */ new Map();
13
- return function(...r) {
14
- const s = JSON.stringify(r);
15
- if (e.has(s))
16
- return e.get(s);
17
- const u = t(...r);
18
- return e.set(s, u), u;
11
+ function J(t) {
12
+ const e = /* @__PURE__ */ new Map(), n = function(...a) {
13
+ const r = JSON.stringify(a);
14
+ if (e.has(r))
15
+ return e.get(r);
16
+ const s = t(...a);
17
+ return e.set(r, s), s;
19
18
  };
19
+ return n.cache = e, n;
20
20
  }
21
- const v = () => Math.random().toString().slice(2), j = (t) => {
22
- const { current: { computedHash: e } } = D({
21
+ const V = () => Math.random().toString().slice(2), H = (t) => {
22
+ const { current: { computedHash: e } } = w({
23
23
  /**
24
24
  * Getter for the computed hash function.
25
25
  *
@@ -28,21 +28,21 @@ const v = () => Math.random().toString().slice(2), j = (t) => {
28
28
  * - Updates the hash if any difference is detected.
29
29
  */
30
30
  get computedHash() {
31
- let r = [], s = v();
32
- return (u) => {
33
- let n = !1;
34
- return n = n || !u != !r, n = n || u?.length != r?.length, n = n || u.some((a, c) => a != r[c]), r = u, n && (s = v()), s;
31
+ let n = [], a = V();
32
+ return (r) => {
33
+ let s = !1;
34
+ return s = s || !r != !n, s = s || r?.length != n?.length, s = s || r.some((c, l) => c != n[l]), n = r, s && (a = V()), a;
35
35
  };
36
36
  }
37
37
  });
38
38
  return e(t);
39
39
  };
40
- class G extends Event {
41
- constructor(e, r) {
42
- super(e), this.event = e, this.value = r;
40
+ class L extends Event {
41
+ constructor(e, n) {
42
+ super(e), this.event = e, this.value = n;
43
43
  }
44
44
  }
45
- class H extends EventTarget {
45
+ class W extends EventTarget {
46
46
  /**
47
47
  * Create a new Context instance.
48
48
  * @param name - The name of the context (for debugging).
@@ -64,8 +64,8 @@ class H extends EventTarget {
64
64
  * @param key - The key to update.
65
65
  * @param value - The new value.
66
66
  */
67
- publish(e, r) {
68
- r != this.data[e] && (this.data[e] = r, this.dispatchEvent(new G(String(e), r)));
67
+ publish(e, n) {
68
+ n != this.data[e] && (this.data[e] = n, this.dispatchEvent(new L(String(e), n)));
69
69
  }
70
70
  /**
71
71
  * Subscribe to changes for a specific key in the context.
@@ -73,193 +73,193 @@ class H extends EventTarget {
73
73
  * @param _listener - Callback invoked with the new value.
74
74
  * @returns Unsubscribe function.
75
75
  */
76
- subscribe(e, r) {
77
- const s = ({ event: u, value: n }) => {
78
- r(n);
76
+ subscribe(e, n) {
77
+ const a = ({ event: r, value: s }) => {
78
+ n(s);
79
79
  };
80
- return this.addEventListener(String(e), s), e in this.data && r(this.data[e]), () => (this.removeEventListener(String(e), s), void 0);
80
+ return this.addEventListener(String(e), a), e in this.data && n(this.data[e]), () => (this.removeEventListener(String(e), a), void 0);
81
81
  }
82
82
  }
83
- const A = V((t) => new H(t)), p = (t = "noname") => d(() => A(t), [t]), N = (t, ...e) => {
84
- const r = new Error("[ctx] useRegistryChecker failed " + JSON.stringify({ names: e, ctx: t?.name ?? "undefined" }));
85
- b(
83
+ const y = J((t) => new W(t)), E = (t = "noname") => g(() => y(t), [t]), A = (t, ...e) => {
84
+ const n = new Error("[ctx] useRegistryChecker failed " + JSON.stringify({ names: e, ctx: t?.name ?? "undefined" }));
85
+ f(
86
86
  () => {
87
87
  if (t)
88
- return e.some((s) => t.registry.has(s)) && console.error(r), e.forEach((s) => t.registry.add(s)), () => {
89
- e.forEach((s) => t.registry.delete(s));
88
+ return e.some((a) => t.registry.has(a)) && console.error(n), e.forEach((a) => t.registry.add(a)), () => {
89
+ e.forEach((a) => t.registry.delete(a));
90
90
  };
91
91
  },
92
92
  [t, e.length]
93
93
  );
94
- }, x = (t, e, r) => {
95
- b(() => {
96
- t && t.data[e] != r && t.publish(e, r);
97
- }, [e, r, t]), N(t, e);
98
- }, W = (t, e, r = 0) => {
99
- const [{ value: s }, u] = S(() => ({ value: t?.data?.[e] }));
100
- return b(() => {
94
+ }, ne = (t, e, n) => {
95
+ f(() => {
96
+ t && t.data[e] != n && t.publish(e, n);
97
+ }, [e, n, t]), A(t, e);
98
+ }, K = (t, e, n = 0) => {
99
+ const [{ value: a }, r] = v(() => ({ value: t?.data?.[e] }));
100
+ return f(() => {
101
101
  if (t) {
102
- let n = r == 0 ? (c) => u({ value: c }) : w((c) => u({ value: c }), r), a = t.subscribe(e, n);
103
- return s != t.data[e] && u({ value: t.data[e] }), () => {
104
- a();
102
+ let s = n == 0 ? (l) => r({ value: l }) : C((l) => r({ value: l }), n), c = t.subscribe(e, s);
103
+ return a != t.data[e] && r({ value: t.data[e] }), () => {
104
+ c();
105
105
  };
106
106
  }
107
107
  }, [e, t]), t?.data[e];
108
- }, z = (t, e, r) => {
109
- const [, s] = S(0), u = d(
110
- () => r(t?.data[e]),
111
- [r, t?.data[e]]
108
+ }, ae = (t, e, n) => {
109
+ const [, a] = v(0), r = g(
110
+ () => n(t?.data[e]),
111
+ [n, t?.data[e]]
112
112
  );
113
- return b(() => {
113
+ return f(() => {
114
114
  if (t) {
115
- let n = u, a = () => {
116
- let o = r(t.data[e]);
117
- o != n && (n = o, s((l) => l + 1));
118
- }, c = t.subscribe(e, a);
119
- return a(), () => c();
115
+ let s = r, c = () => {
116
+ let i = n(t.data[e]);
117
+ i != s && (s = i, a((u) => u + 1));
118
+ }, l = t.subscribe(e, c);
119
+ return c(), () => l();
120
120
  }
121
- }, [e, t]), u;
122
- }, M = (t, ...e) => {
123
- b(() => {
121
+ }, [e, t]), r;
122
+ }, k = (t, ...e) => {
123
+ f(() => {
124
124
  if (t)
125
- for (let [r, s] of e)
126
- t.data[r] != s && t.publish(r, s);
127
- }, [t, j(e.flat())]), N(t, ...e.map((r) => r[0]));
128
- }, K = (t, ...e) => {
129
- const [, r] = S(0), s = e.map((u) => t?.data?.[u]);
130
- return b(() => {
125
+ for (let [n, a] of e)
126
+ t.data[n] != a && t.publish(n, a);
127
+ }, [t, H(e.flat())]), A(t, ...e.map((n) => n[0]));
128
+ }, re = (t, ...e) => {
129
+ const [, n] = v(0), a = e.map((r) => t?.data?.[r]);
130
+ return f(() => {
131
131
  if (t) {
132
- let u = s;
133
- const n = w(() => {
134
- let o = e.map((l) => t?.data?.[l]);
135
- e.some((l, i) => u[i] != o[i]) && (u = o, r((l) => l + 1));
132
+ let r = a;
133
+ const s = C(() => {
134
+ let i = e.map((u) => t?.data?.[u]);
135
+ e.some((u, d) => r[d] != i[d]) && (r = i, n((u) => u + 1));
136
136
  }, 1);
137
- let a = e.map((o) => t.subscribe(o, n)), c = setTimeout(n, 1);
137
+ let c = e.map((i) => t.subscribe(i, s)), l = setTimeout(s, 1);
138
138
  return () => {
139
- clearTimeout(c), n.cancel(), a.forEach((o) => o());
139
+ clearTimeout(l), s.cancel(), c.forEach((i) => i());
140
140
  };
141
141
  }
142
- }, [t, ...e]), Object.fromEntries(e.map((u, n) => [u, s[n]]));
143
- }, P = (t, e = 50, ...r) => {
144
- const [, s] = S(0), u = r.map((n) => t?.data?.[n]);
145
- return b(() => {
142
+ }, [t, ...e]), Object.fromEntries(e.map((r, s) => [r, a[s]]));
143
+ }, se = (t, e = 50, ...n) => {
144
+ const [, a] = v(0), r = n.map((s) => t?.data?.[s]);
145
+ return f(() => {
146
146
  if (t) {
147
- let n = u;
148
- const a = w(() => {
149
- let l = r.map((i) => t?.data?.[i]);
150
- r.some((i, m) => n[m] != l[m]) && (n = l, s((i) => i + 1));
147
+ let s = r;
148
+ const c = C(() => {
149
+ let u = n.map((d) => t?.data?.[d]);
150
+ n.some((d, p) => s[p] != u[p]) && (s = u, a((d) => d + 1));
151
151
  }, e);
152
- let c = r.map((l) => t.subscribe(l, a)), o = setTimeout(a, 1);
152
+ let l = n.map((u) => t.subscribe(u, c)), i = setTimeout(c, 1);
153
153
  return () => {
154
- clearTimeout(o), a.cancel(), c.forEach((l) => l());
154
+ clearTimeout(i), c.cancel(), l.forEach((u) => u());
155
155
  };
156
156
  }
157
- }, [t, ...r]), u;
158
- }, Q = (t, e) => {
159
- const r = (n) => [
157
+ }, [t, ...n]), r;
158
+ }, ce = (t, e) => {
159
+ const n = (s) => [
160
160
  t,
161
- ...Object.entries(n ?? {}).sort((a, c) => a[0].localeCompare(c[0])).flat()
161
+ ...Object.entries(s ?? {}).sort((c, l) => c[0].localeCompare(l[0])).flat()
162
162
  ].join("-");
163
- let s = /* @__PURE__ */ new Set();
164
- const u = (n) => {
165
- const a = e(n), c = r(n), o = p(c), l = d(() => new Error().stack, []);
166
- return M(
167
- o,
168
- ...Object.entries(a)
169
- ), b(() => {
170
- if (s.has(c)) {
171
- const i = new Error("RootContext " + c + " are mounted more than once");
172
- throw i.stack = l, i;
163
+ let a = /* @__PURE__ */ new Set();
164
+ const r = (s) => {
165
+ const c = e(s), l = n(s), i = E(l), u = g(() => new Error().stack, []);
166
+ return k(
167
+ i,
168
+ ...Object.entries(c)
169
+ ), f(() => {
170
+ if (a.has(l)) {
171
+ const d = new Error("RootContext " + l + " are mounted more than once");
172
+ throw d.stack = u, d;
173
173
  }
174
- return s.add(c), () => {
175
- s.delete(c);
174
+ return a.add(l), () => {
175
+ a.delete(l);
176
176
  };
177
- }), /* @__PURE__ */ g(T, {});
177
+ }), /* @__PURE__ */ o(O, {});
178
178
  };
179
- return u.displayName = `State[${e?.name ?? "??"}]`, {
180
- resolveCtxName: r,
181
- Root: u,
179
+ return r.displayName = `State[${e?.name ?? "??"}]`, {
180
+ resolveCtxName: n,
181
+ Root: r,
182
182
  /**
183
183
  * Strict consumer: throws if the corresponding Root for these props isn't mounted.
184
184
  * Use in development/tests to fail fast when wiring is incorrect.
185
185
  */
186
- useCtxStateStrict: (n) => {
187
- const a = r(n), c = d(() => new Error().stack, []);
188
- return b(() => {
189
- if (!s.has(a)) {
190
- const o = new Error("RootContext [" + a + "] is not mounted");
191
- throw o.stack = c, o;
186
+ useCtxStateStrict: (s) => {
187
+ const c = n(s), l = g(() => new Error().stack, []);
188
+ return f(() => {
189
+ if (!a.has(c)) {
190
+ const i = new Error("RootContext [" + c + "] is not mounted");
191
+ throw i.stack = l, i;
192
192
  }
193
- }, [a]), p(a);
193
+ }, [c]), E(c);
194
194
  },
195
195
  /**
196
196
  * Lenient consumer: schedules a console.error if the Root isn't mounted instead of throwing.
197
197
  * Useful in production to avoid hard crashes while still surfacing misconfiguration.
198
198
  */
199
- useCtxState: (n) => {
200
- const a = r(n), c = d(() => new Error().stack, []);
201
- return b(() => {
202
- if (!s.has(a)) {
203
- const o = new Error("RootContext [" + a + "] is not mounted");
204
- o.stack = c;
205
- let l = setTimeout(() => console.error(o), 1e3);
206
- return () => clearTimeout(l);
199
+ useCtxState: (s) => {
200
+ const c = n(s), l = g(() => new Error().stack, []);
201
+ return f(() => {
202
+ if (!a.has(c)) {
203
+ const i = new Error("RootContext [" + c + "] is not mounted");
204
+ i.stack = l;
205
+ let u = setTimeout(() => console.error(i), 1e3);
206
+ return () => clearTimeout(u);
207
207
  }
208
- }, [s.has(a)]), p(a);
208
+ }, [a.has(c)]), E(c);
209
209
  }
210
210
  };
211
- }, F = /* @__PURE__ */ function() {
211
+ }, _ = /* @__PURE__ */ function() {
212
212
  const t = /* @__PURE__ */ new WeakMap();
213
213
  return (e) => {
214
- let r = t.get(e);
215
- return r || t.set(e, r = (e?.name ?? "") + Math.random().toString()), r;
214
+ let n = t.get(e);
215
+ return n || t.set(e, n = (e?.name ?? "") + Math.random().toString()), n;
216
216
  };
217
- }(), J = (t) => [
218
- ...Object.entries(t ?? {}).sort((e, r) => e[0].localeCompare(r[0])).flat()
219
- ].join("-"), U = ({ Wrapper: t = R }) => {
220
- const e = p("auto-ctx"), [r, s] = S({}), u = O(
221
- (n, a) => {
222
- const c = F(n), o = J(a);
223
- return s(({
224
- [c]: {
225
- Component: l = n,
217
+ }(), I = (t) => [
218
+ ...Object.entries(t ?? {}).sort((e, n) => e[0].localeCompare(n[0])).flat()
219
+ ].join("-"), le = ({ Wrapper: t = F }) => {
220
+ const e = E("auto-ctx"), [n, a] = v({}), r = $(
221
+ (s, c) => {
222
+ const l = _(s), i = I(c);
223
+ return a(({
224
+ [l]: {
225
+ Component: u = s,
226
226
  subState: {
227
- [o]: i = { params: a, counter: 0 },
228
- ...m
227
+ [i]: d = { params: c, counter: 0 },
228
+ ...p
229
229
  } = {}
230
230
  } = {},
231
- ...h
231
+ ...b
232
232
  }) => ({
233
- ...h,
234
- [c]: {
235
- Component: l,
233
+ ...b,
234
+ [l]: {
235
+ Component: u,
236
236
  subState: {
237
- ...m,
238
- [o]: {
239
- ...i,
240
- counter: i.counter + 1
237
+ ...p,
238
+ [i]: {
239
+ ...d,
240
+ counter: d.counter + 1
241
241
  }
242
242
  }
243
243
  }
244
- })), () => s(({
245
- [c]: {
246
- Component: l = n,
244
+ })), () => a(({
245
+ [l]: {
246
+ Component: u = s,
247
247
  subState: {
248
- [o]: i = { params: a, counter: 0 },
249
- ...m
248
+ [i]: d = { params: c, counter: 0 },
249
+ ...p
250
250
  } = {}
251
251
  } = {},
252
- ...h
252
+ ...b
253
253
  }) => ({
254
- ...h,
255
- [c]: {
256
- Component: l,
254
+ ...b,
255
+ [l]: {
256
+ Component: u,
257
257
  subState: {
258
- ...m,
259
- ...i.counter > 1 ? {
260
- [o]: {
261
- ...i,
262
- counter: i.counter - 1
258
+ ...p,
259
+ ...d.counter > 1 ? {
260
+ [i]: {
261
+ ...d,
262
+ counter: d.counter - 1
263
263
  }
264
264
  } : {}
265
265
  }
@@ -268,74 +268,312 @@ const A = V((t) => new H(t)), p = (t = "noname") => d(() => A(t), [t]), N = (t,
268
268
  },
269
269
  []
270
270
  );
271
- return M(
271
+ return k(
272
272
  e,
273
- ["subscribe", u],
274
- ["state", r]
275
- ), /* @__PURE__ */ g(T, { children: Object.entries(r).flatMap(
276
- ([n, { Component: a, subState: c }]) => Object.entries(c).map(([o, { counter: l, params: i }]) => ({ key: n + o, Component: a, params: i, counter: l })).filter((o) => o.counter > 0).map(({ key: o, params: l, Component: i }) => /* @__PURE__ */ g(t, { children: /* @__PURE__ */ g(i, { ...l }) }, o))
273
+ ["subscribe", r],
274
+ ["state", n]
275
+ ), /* @__PURE__ */ o(O, { children: Object.entries(n).flatMap(
276
+ ([s, { Component: c, subState: l }]) => Object.entries(l).map(([i, { counter: u, params: d }]) => ({ key: s + i, Component: c, params: d, counter: u })).filter((i) => i.counter > 0).map(({ key: i, params: u, Component: d }) => /* @__PURE__ */ o(t, { children: /* @__PURE__ */ o(d, { ...u }) }, i))
277
277
  ) });
278
- }, X = ({ Root: t, useCtxState: e, useCtxStateStrict: r, resolveCtxName: s }, u = 0) => ({
279
- useCtxState: (n) => {
280
- const a = s(n), c = W(p("auto-ctx"), "subscribe");
281
- return b(() => {
282
- if (u == 0)
283
- return c?.(t, n);
278
+ }, ie = ({ Root: t, useCtxState: e, useCtxStateStrict: n, resolveCtxName: a }, r = 0) => ({
279
+ useCtxState: (s) => {
280
+ const c = a(s), l = K(E("auto-ctx"), "subscribe");
281
+ return f(() => {
282
+ if (r == 0)
283
+ return l?.(t, s);
284
284
  {
285
- let o = c?.(t, n);
286
- return () => setTimeout(o, u);
285
+ let i = l?.(t, s);
286
+ return () => setTimeout(i, r);
287
287
  }
288
- }, [c, a]), p(a);
288
+ }, [l, c]), E(c);
289
289
  }
290
- }), q = (t) => {
291
- const [, e] = S(0), { proxy: r, finalGetter: s, openGetter: u, clean: n } = d(
290
+ }), oe = (t) => {
291
+ const [, e] = v(0), { proxy: n, finalGetter: a, openGetter: r, clean: s } = g(
292
292
  () => {
293
- const a = /* @__PURE__ */ new Set(), c = {}, o = /* @__PURE__ */ new Map(), l = new Proxy(
293
+ const c = /* @__PURE__ */ new Set(), l = {}, i = /* @__PURE__ */ new Map(), u = new Proxy(
294
294
  t?.data,
295
295
  {
296
- get(f, C) {
297
- if (i)
298
- return a.add(C), c[C] = f[C];
296
+ get(h, S) {
297
+ if (d)
298
+ return c.add(S), l[S] = h[S];
299
299
  throw new Error("now allow here");
300
300
  }
301
301
  }
302
302
  );
303
- let i = !0, m = w(() => {
304
- [...a.values()].some((f) => c[f] != t?.data?.[f]) && e((f) => f + 1);
305
- }, 0), h = () => {
306
- i = !0, a.clear();
307
- }, E = () => {
308
- i = !1, [...a.values()].filter((f) => !o.has(f)).forEach((f) => {
309
- o.set(f, t?.subscribe(f, m));
310
- }), [...o.keys()].filter((f) => !a.has(f)).forEach((f) => {
311
- o.get(f)?.(), o.delete(f);
303
+ let d = !0, p = C(() => {
304
+ [...c.values()].some((h) => l[h] != t?.data?.[h]) && e((h) => h + 1);
305
+ }, 0), b = () => {
306
+ d = !0, c.clear();
307
+ }, j = () => {
308
+ d = !1, [...c.values()].filter((h) => !i.has(h)).forEach((h) => {
309
+ i.set(h, t?.subscribe(h, p));
310
+ }), [...i.keys()].filter((h) => !c.has(h)).forEach((h) => {
311
+ i.get(h)?.(), i.delete(h);
312
312
  });
313
313
  };
314
- return { proxy: l, finalGetter: E, openGetter: h, clean: () => {
315
- h(), E(), e((f) => f + 1);
314
+ return { proxy: u, finalGetter: j, openGetter: b, clean: () => {
315
+ b(), j(), e((h) => h + 1);
316
316
  } };
317
317
  },
318
318
  [t]
319
319
  );
320
- return u(), setTimeout(s, 0), b(
321
- () => () => n(),
322
- [n]
323
- ), r;
320
+ return r(), setTimeout(a, 0), f(
321
+ () => () => s(),
322
+ [s]
323
+ ), n;
324
+ }, q = y.cache, z = ({}) => {
325
+ const [t, e] = v("");
326
+ return /* @__PURE__ */ m("div", { className: "main-panel", children: [
327
+ /* @__PURE__ */ o("div", { className: "state-list", children: [...q.keys()].map((n) => JSON.parse(n)?.[0]).filter((n) => n != "auto-ctx").map((n) => /* @__PURE__ */ o(
328
+ "div",
329
+ {
330
+ className: "state-key",
331
+ "data-active": n == t,
332
+ onClick: () => e(n),
333
+ children: n
334
+ }
335
+ )) }),
336
+ /* @__PURE__ */ o("div", { className: "state-view", children: /* @__PURE__ */ o(B, { dataKey: t }, t) })
337
+ ] });
338
+ }, B = ({ dataKey: t }) => {
339
+ const e = y(t), [n, a] = v({ ...e?.data });
340
+ return f(() => {
341
+ let r = { ...n }, s = setInterval(() => {
342
+ let c = !1;
343
+ for (let l in e?.data)
344
+ e?.data?.[l] != r[l] && (r[l] = e?.data?.[l], c = !0);
345
+ c && a({ ...r });
346
+ }, 200);
347
+ return () => clearInterval(s);
348
+ }, [e]), /* @__PURE__ */ o(
349
+ Z,
350
+ {
351
+ value: n,
352
+ name: "ROOT",
353
+ expandLevel: 1,
354
+ style: {}
355
+ }
356
+ );
357
+ }, x = (t, e = 10) => Object.fromEntries(
358
+ new Array(Math.ceil((t.length + 1) / e)).fill(0).map(
359
+ (n, a, r) => new Array(a == r.length - 1 ? t.length % e : e).fill(0).map((s, c) => a * e + c)
360
+ ).filter((n) => n.length).map((n) => [`${n.at(0)}..${n.at(-1)}`, Object.fromEntries(
361
+ n.map((a) => [a, t[a]])
362
+ )])
363
+ ), P = (t, e = 10) => {
364
+ const n = Object.keys(t);
365
+ return Object.fromEntries(
366
+ Array(Math.ceil((n.length + 1) / e)).fill(0).map(
367
+ (a, r, s) => new Array(r == s.length - 1 ? n.length % e : e).fill(0).map((c, l) => r * e + l)
368
+ ).filter((a) => a.length).map((a) => a.map((r) => n.at(r))).map(
369
+ (a) => [
370
+ `${a.at(0)?.slice(0, 15)}...${a.at(-1)?.slice(0, 15)}`,
371
+ Object.fromEntries(a.map((r) => [r, t[r]]))
372
+ ]
373
+ )
374
+ );
375
+ }, T = ({ path: t, expandLevel: e, expandRoot: n, setExpandRoot: a }) => {
376
+ const r = t?.join("%") ?? "", s = typeof e == "boolean" ? e : typeof e == "number" && e > 0, c = g(
377
+ () => n?.[r] ?? s,
378
+ [n?.[r], r]
379
+ ), l = $(
380
+ (i) => a((u) => ({ ...u, [r]: i })),
381
+ [n, r]
382
+ );
383
+ return { isExpand: c, setExpand: l };
384
+ }, N = ({ value: t, deepCompare: e = !1, ...n }) => {
385
+ const a = w(void 0), r = w(t);
386
+ return f(() => {
387
+ if (a.current && (e && t && r.current ? Object.keys(t).length != Object.keys(r.current).length || Object.keys(t).some((c) => t[c] != r.current[c]) : t != r.current)) {
388
+ r.current = t, a.current.classList.add("jv-updated");
389
+ let c = requestAnimationFrame(() => a.current?.classList.remove("jv-updated"));
390
+ return () => cancelAnimationFrame(c);
391
+ }
392
+ }, [t, e, a]), /* @__PURE__ */ o("div", { ...n, ref: a });
393
+ }, Q = (t) => {
394
+ const {
395
+ currentField: e,
396
+ value: n,
397
+ path: a = [],
398
+ name: r,
399
+ expandRoot: s,
400
+ setExpandRoot: c,
401
+ expandLevel: l,
402
+ isGrouped: i
403
+ } = t, u = n instanceof Array, { isExpand: d, setExpand: p } = T(t), b = typeof l == "number" ? l - 1 : l, j = Object.entries(n).length > 10, D = g(
404
+ () => j ? n instanceof Array ? x(n, 10) : P(n, 10) : n,
405
+ [n, j, x]
406
+ );
407
+ return d ? /* @__PURE__ */ m(N, { className: "jv-field jv-field-obj", value: n, deepCompare: i, children: [
408
+ e && /* @__PURE__ */ o("div", { children: /* @__PURE__ */ m("div", { onClick: () => p(!1), children: [
409
+ /* @__PURE__ */ o("span", { className: "jv-name", children: e }),
410
+ /* @__PURE__ */ o("span", { children: ":" }),
411
+ /* @__PURE__ */ o("span", { children: "[-]" }),
412
+ /* @__PURE__ */ m("span", { className: "jv-type", children: [
413
+ Object.keys(n).length,
414
+ " items "
415
+ ] }),
416
+ /* @__PURE__ */ m("span", { children: [
417
+ " ",
418
+ u ? "[" : "{",
419
+ " "
420
+ ] })
421
+ ] }) }),
422
+ /* @__PURE__ */ o("div", { className: "jv-value", children: Object.entries(D).map(([h, S], R) => /* @__PURE__ */ G(
423
+ M,
424
+ {
425
+ name: r,
426
+ expandRoot: s,
427
+ setExpandRoot: c,
428
+ expandLevel: b,
429
+ value: S,
430
+ isGrouped: j,
431
+ key: [...a, j ? R : h].join("%"),
432
+ path: [...a, h]
433
+ }
434
+ )) }),
435
+ e && /* @__PURE__ */ o("div", { children: /* @__PURE__ */ m("span", { children: [
436
+ " ",
437
+ u ? "]" : "}",
438
+ " "
439
+ ] }) })
440
+ ] }) : /* @__PURE__ */ o(N, { className: "jv-field jv-field-obj", value: n, deepCompare: i, children: /* @__PURE__ */ o("div", { children: /* @__PURE__ */ m("div", { onClick: () => p(!0), children: [
441
+ /* @__PURE__ */ o("span", { className: "jv-name", children: e }),
442
+ e && /* @__PURE__ */ o("span", { children: ":" }),
443
+ e && /* @__PURE__ */ o("span", { children: "[+]" }),
444
+ /* @__PURE__ */ m("span", { className: "jv-type", children: [
445
+ Object.keys(n).length,
446
+ " items "
447
+ ] }),
448
+ /* @__PURE__ */ m("span", { children: [
449
+ " ",
450
+ u ? "[" : "{",
451
+ " "
452
+ ] }),
453
+ /* @__PURE__ */ o("span", { children: " ... " }),
454
+ /* @__PURE__ */ m("span", { children: [
455
+ " ",
456
+ u ? "]" : "}",
457
+ " "
458
+ ] })
459
+ ] }) }) });
460
+ }, U = (t) => {
461
+ const { currentType: e, currentField: n, value: a } = t, { isExpand: r, setExpand: s } = T(t), c = String(a).length > 50, l = c && !r ? `${String(a).slice(0, 15)}...${String(a).slice(-15, -1)}` : String(a);
462
+ return /* @__PURE__ */ m(
463
+ N,
464
+ {
465
+ value: t.value,
466
+ className: `jv-field jv-field-${e} ${c ? "jv-cursor" : ""}`,
467
+ onClick: () => s(!r),
468
+ children: [
469
+ /* @__PURE__ */ o("span", { className: "jv-name", children: n }),
470
+ /* @__PURE__ */ o("span", { children: ":" }),
471
+ /* @__PURE__ */ m("span", { className: "jv-type", children: [
472
+ e,
473
+ ", lng=",
474
+ a?.length
475
+ ] }),
476
+ /* @__PURE__ */ m("span", { className: "jv-value", children: [
477
+ '"',
478
+ l,
479
+ '"'
480
+ ] }),
481
+ /* @__PURE__ */ o("span", { children: "," })
482
+ ]
483
+ }
484
+ );
485
+ }, X = (t) => {
486
+ const { currentType: e, currentField: n, value: a } = t, { isExpand: r, setExpand: s } = T(t), c = String(a).length > 50, l = c && !r ? `${String(a).slice(0, 15)}...${String(a).slice(-15, -1)}` : String(a);
487
+ return /* @__PURE__ */ m(
488
+ N,
489
+ {
490
+ value: t.value,
491
+ className: `jv-field jv-field-${e} ${c ? "jv-cursor" : ""}`,
492
+ onClick: () => s(!r),
493
+ children: [
494
+ /* @__PURE__ */ o("span", { className: "jv-name", children: n }),
495
+ /* @__PURE__ */ o("span", { children: ":" }),
496
+ /* @__PURE__ */ o("span", { className: "jv-type", children: e }),
497
+ /* @__PURE__ */ m("span", { className: "jv-value", children: [
498
+ '"',
499
+ l,
500
+ '"'
501
+ ] }),
502
+ /* @__PURE__ */ o("span", { children: "," })
503
+ ]
504
+ }
505
+ );
506
+ }, Y = (t) => {
507
+ const { currentType: e, currentField: n, value: a } = t;
508
+ return /* @__PURE__ */ m(
509
+ N,
510
+ {
511
+ value: t.value,
512
+ className: `jv-field jv-field-${e}`,
513
+ children: [
514
+ /* @__PURE__ */ o("span", { className: "jv-name", children: n }),
515
+ /* @__PURE__ */ o("span", { children: ":" }),
516
+ /* @__PURE__ */ o("span", { className: "jv-type", children: e }),
517
+ /* @__PURE__ */ o("span", { className: "jv-value", children: String(a) }),
518
+ /* @__PURE__ */ o("span", { children: "," })
519
+ ]
520
+ }
521
+ );
522
+ }, M = (t) => {
523
+ const { value: e, path: n = [], name: a } = t, r = n.at(-1) ?? a ?? void 0, s = typeof e;
524
+ switch (s) {
525
+ case "object":
526
+ return /* @__PURE__ */ o(Q, { ...t, currentField: r, currentType: s });
527
+ case "string":
528
+ return /* @__PURE__ */ o(U, { ...t, currentField: r, currentType: s });
529
+ case "function":
530
+ return /* @__PURE__ */ o(X, { ...t, currentField: r, currentType: s });
531
+ case "number":
532
+ case "boolean":
533
+ case "bigint":
534
+ case "symbol":
535
+ case "undefined":
536
+ default:
537
+ return /* @__PURE__ */ o(Y, { ...t, currentField: r, currentType: s });
538
+ }
539
+ }, Z = ({ value: t, name: e, style: n, expandLevel: a = !1 }) => {
540
+ const [r, s] = v({});
541
+ return /* @__PURE__ */ o("div", { className: "jv-root", style: n, children: /* @__PURE__ */ o(
542
+ M,
543
+ {
544
+ path: [],
545
+ name: e,
546
+ value: t,
547
+ expandRoot: r,
548
+ setExpandRoot: s,
549
+ expandLevel: a
550
+ }
551
+ ) });
552
+ }, ue = ({ toggleButton: t = "[x]", ...e }) => {
553
+ const [n, a] = v(!1);
554
+ return /* @__PURE__ */ m(O, { children: [
555
+ /* @__PURE__ */ o("button", { className: "react-state-dev-btn", "data-active": n, onClick: () => a(!0), ...e, children: e?.children ?? "Toggle Dev Tool" }),
556
+ /* @__PURE__ */ m("div", { className: "react-state-dev-container", "data-active": n, children: [
557
+ /* @__PURE__ */ o("button", { className: "close-btn", onClick: () => a(!1), children: "[x]" }),
558
+ /* @__PURE__ */ o(z, {})
559
+ ] })
560
+ ] });
324
561
  };
325
562
  export {
326
- U as AutoRootCtx,
327
- H as Context,
328
- X as createAutoCtx,
329
- Q as createRootCtx,
330
- A as getContext,
331
- j as useArrayHash,
332
- p as useDataContext,
333
- x as useDataSource,
334
- M as useDataSourceMultiple,
335
- W as useDataSubscribe,
336
- K as useDataSubscribeMultiple,
337
- P as useDataSubscribeMultipleWithDebounce,
338
- z as useDataSubscribeWithTransform,
339
- q as useQuickSubscribe
563
+ le as AutoRootCtx,
564
+ W as Context,
565
+ ue as DevToolContainer,
566
+ ie as createAutoCtx,
567
+ ce as createRootCtx,
568
+ y as getContext,
569
+ H as useArrayHash,
570
+ E as useDataContext,
571
+ ne as useDataSource,
572
+ k as useDataSourceMultiple,
573
+ K as useDataSubscribe,
574
+ re as useDataSubscribeMultiple,
575
+ se as useDataSubscribeMultipleWithDebounce,
576
+ ae as useDataSubscribeWithTransform,
577
+ oe as useQuickSubscribe
340
578
  };
341
579
  //# sourceMappingURL=index.es.js.map