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