react-state-custom 1.0.23 → 1.0.24

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