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/.github/copilot-instructions.md +42 -0
- package/dist/DevTool.d.ts +4 -0
- package/dist/DevToolState.d.ts +11 -0
- package/dist/Test.d.ts +1 -0
- package/dist/dev.d.ts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.es.js +440 -202
- 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 -0
- package/dist/state-utils/ctx.d.ts +3 -1
- package/dist/state-utils/utils.d.ts +3 -1
- package/index.html +14 -0
- package/package.json +4 -2
- package/src/DevTool.css +192 -0
- package/src/DevTool.tsx +19 -0
- package/src/DevToolState.tsx +316 -0
- package/src/Test.tsx +90 -0
- package/src/dev.tsx +14 -0
- package/src/index.ts +1 -1
- package/src/state-utils/utils.ts +9 -4
- package/vite.config.dev.ts +11 -0
- package/.yarnrc.yml +0 -1
package/dist/index.es.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { useRef as
|
|
2
|
-
import { jsx as
|
|
3
|
-
function
|
|
4
|
-
let
|
|
5
|
-
|
|
6
|
-
t(...
|
|
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
|
|
9
|
+
return a.cancel = () => clearTimeout(n), a;
|
|
10
10
|
}
|
|
11
|
-
function
|
|
12
|
-
const e = /* @__PURE__ */ new Map()
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
|
22
|
-
const { current: { computedHash: e } } =
|
|
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
|
|
32
|
-
return (
|
|
33
|
-
let
|
|
34
|
-
return
|
|
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
|
|
41
|
-
constructor(e,
|
|
42
|
-
super(e), this.event = e, this.value =
|
|
40
|
+
class L extends Event {
|
|
41
|
+
constructor(e, n) {
|
|
42
|
+
super(e), this.event = e, this.value = n;
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
-
class
|
|
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,
|
|
68
|
-
|
|
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,
|
|
77
|
-
const
|
|
78
|
-
|
|
76
|
+
subscribe(e, n) {
|
|
77
|
+
const a = ({ event: r, value: s }) => {
|
|
78
|
+
n(s);
|
|
79
79
|
};
|
|
80
|
-
return this.addEventListener(String(e),
|
|
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
|
|
84
|
-
const
|
|
85
|
-
|
|
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((
|
|
89
|
-
e.forEach((
|
|
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
|
-
},
|
|
95
|
-
|
|
96
|
-
t && t.data[e] !=
|
|
97
|
-
}, [e,
|
|
98
|
-
},
|
|
99
|
-
const [{ value:
|
|
100
|
-
return
|
|
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
|
|
103
|
-
return
|
|
104
|
-
|
|
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
|
-
},
|
|
109
|
-
const [,
|
|
110
|
-
() =>
|
|
111
|
-
[
|
|
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
|
|
113
|
+
return f(() => {
|
|
114
114
|
if (t) {
|
|
115
|
-
let
|
|
116
|
-
let
|
|
117
|
-
|
|
118
|
-
},
|
|
119
|
-
return
|
|
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]),
|
|
122
|
-
},
|
|
123
|
-
|
|
121
|
+
}, [e, t]), r;
|
|
122
|
+
}, k = (t, ...e) => {
|
|
123
|
+
f(() => {
|
|
124
124
|
if (t)
|
|
125
|
-
for (let [
|
|
126
|
-
t.data[
|
|
127
|
-
}, [t,
|
|
128
|
-
},
|
|
129
|
-
const [,
|
|
130
|
-
return
|
|
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
|
|
133
|
-
const
|
|
134
|
-
let
|
|
135
|
-
e.some((
|
|
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
|
|
137
|
+
let c = e.map((i) => t.subscribe(i, s)), l = setTimeout(s, 1);
|
|
138
138
|
return () => {
|
|
139
|
-
clearTimeout(
|
|
139
|
+
clearTimeout(l), s.cancel(), c.forEach((i) => i());
|
|
140
140
|
};
|
|
141
141
|
}
|
|
142
|
-
}, [t, ...e]), Object.fromEntries(e.map((
|
|
143
|
-
},
|
|
144
|
-
const [,
|
|
145
|
-
return
|
|
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
|
|
148
|
-
const
|
|
149
|
-
let
|
|
150
|
-
|
|
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
|
|
152
|
+
let l = n.map((u) => t.subscribe(u, c)), i = setTimeout(c, 1);
|
|
153
153
|
return () => {
|
|
154
|
-
clearTimeout(
|
|
154
|
+
clearTimeout(i), c.cancel(), l.forEach((u) => u());
|
|
155
155
|
};
|
|
156
156
|
}
|
|
157
|
-
}, [t, ...
|
|
158
|
-
},
|
|
159
|
-
const
|
|
157
|
+
}, [t, ...n]), r;
|
|
158
|
+
}, ce = (t, e) => {
|
|
159
|
+
const n = (s) => [
|
|
160
160
|
t,
|
|
161
|
-
...Object.entries(
|
|
161
|
+
...Object.entries(s ?? {}).sort((c, l) => c[0].localeCompare(l[0])).flat()
|
|
162
162
|
].join("-");
|
|
163
|
-
let
|
|
164
|
-
const
|
|
165
|
-
const
|
|
166
|
-
return
|
|
167
|
-
|
|
168
|
-
...Object.entries(
|
|
169
|
-
),
|
|
170
|
-
if (
|
|
171
|
-
const
|
|
172
|
-
throw
|
|
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
|
|
175
|
-
|
|
174
|
+
return a.add(l), () => {
|
|
175
|
+
a.delete(l);
|
|
176
176
|
};
|
|
177
|
-
}), /* @__PURE__ */
|
|
177
|
+
}), /* @__PURE__ */ o(O, {});
|
|
178
178
|
};
|
|
179
|
-
return
|
|
180
|
-
resolveCtxName:
|
|
181
|
-
Root:
|
|
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: (
|
|
187
|
-
const
|
|
188
|
-
return
|
|
189
|
-
if (!
|
|
190
|
-
const
|
|
191
|
-
throw
|
|
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
|
-
}, [
|
|
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: (
|
|
200
|
-
const
|
|
201
|
-
return
|
|
202
|
-
if (!
|
|
203
|
-
const
|
|
204
|
-
|
|
205
|
-
let
|
|
206
|
-
return () => clearTimeout(
|
|
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
|
-
}, [
|
|
208
|
+
}, [a.has(c)]), E(c);
|
|
209
209
|
}
|
|
210
210
|
};
|
|
211
|
-
},
|
|
211
|
+
}, _ = /* @__PURE__ */ function() {
|
|
212
212
|
const t = /* @__PURE__ */ new WeakMap();
|
|
213
213
|
return (e) => {
|
|
214
|
-
let
|
|
215
|
-
return
|
|
214
|
+
let n = t.get(e);
|
|
215
|
+
return n || t.set(e, n = (e?.name ?? "") + Math.random().toString()), n;
|
|
216
216
|
};
|
|
217
|
-
}(),
|
|
218
|
-
...Object.entries(t ?? {}).sort((e,
|
|
219
|
-
].join("-"),
|
|
220
|
-
const e =
|
|
221
|
-
(
|
|
222
|
-
const
|
|
223
|
-
return
|
|
224
|
-
[
|
|
225
|
-
Component:
|
|
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
|
-
[
|
|
228
|
-
...
|
|
227
|
+
[i]: d = { params: c, counter: 0 },
|
|
228
|
+
...p
|
|
229
229
|
} = {}
|
|
230
230
|
} = {},
|
|
231
|
-
...
|
|
231
|
+
...b
|
|
232
232
|
}) => ({
|
|
233
|
-
...
|
|
234
|
-
[
|
|
235
|
-
Component:
|
|
233
|
+
...b,
|
|
234
|
+
[l]: {
|
|
235
|
+
Component: u,
|
|
236
236
|
subState: {
|
|
237
|
-
...
|
|
238
|
-
[
|
|
239
|
-
...
|
|
240
|
-
counter:
|
|
237
|
+
...p,
|
|
238
|
+
[i]: {
|
|
239
|
+
...d,
|
|
240
|
+
counter: d.counter + 1
|
|
241
241
|
}
|
|
242
242
|
}
|
|
243
243
|
}
|
|
244
|
-
})), () =>
|
|
245
|
-
[
|
|
246
|
-
Component:
|
|
244
|
+
})), () => a(({
|
|
245
|
+
[l]: {
|
|
246
|
+
Component: u = s,
|
|
247
247
|
subState: {
|
|
248
|
-
[
|
|
249
|
-
...
|
|
248
|
+
[i]: d = { params: c, counter: 0 },
|
|
249
|
+
...p
|
|
250
250
|
} = {}
|
|
251
251
|
} = {},
|
|
252
|
-
...
|
|
252
|
+
...b
|
|
253
253
|
}) => ({
|
|
254
|
-
...
|
|
255
|
-
[
|
|
256
|
-
Component:
|
|
254
|
+
...b,
|
|
255
|
+
[l]: {
|
|
256
|
+
Component: u,
|
|
257
257
|
subState: {
|
|
258
|
-
...
|
|
259
|
-
...
|
|
260
|
-
[
|
|
261
|
-
...
|
|
262
|
-
counter:
|
|
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
|
|
271
|
+
return k(
|
|
272
272
|
e,
|
|
273
|
-
["subscribe",
|
|
274
|
-
["state",
|
|
275
|
-
), /* @__PURE__ */
|
|
276
|
-
([
|
|
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
|
-
},
|
|
279
|
-
useCtxState: (
|
|
280
|
-
const
|
|
281
|
-
return
|
|
282
|
-
if (
|
|
283
|
-
return
|
|
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
|
|
286
|
-
return () => setTimeout(
|
|
285
|
+
let i = l?.(t, s);
|
|
286
|
+
return () => setTimeout(i, r);
|
|
287
287
|
}
|
|
288
|
-
}, [
|
|
288
|
+
}, [l, c]), E(c);
|
|
289
289
|
}
|
|
290
|
-
}),
|
|
291
|
-
const [, e] =
|
|
290
|
+
}), oe = (t) => {
|
|
291
|
+
const [, e] = v(0), { proxy: n, finalGetter: a, openGetter: r, clean: s } = g(
|
|
292
292
|
() => {
|
|
293
|
-
const
|
|
293
|
+
const c = /* @__PURE__ */ new Set(), l = {}, i = /* @__PURE__ */ new Map(), u = new Proxy(
|
|
294
294
|
t?.data,
|
|
295
295
|
{
|
|
296
|
-
get(
|
|
297
|
-
if (
|
|
298
|
-
return
|
|
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
|
|
304
|
-
[...
|
|
305
|
-
}, 0),
|
|
306
|
-
|
|
307
|
-
},
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
}), [...
|
|
311
|
-
|
|
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:
|
|
315
|
-
|
|
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
|
|
321
|
-
() => () =>
|
|
322
|
-
[
|
|
323
|
-
),
|
|
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
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
K as
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
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
|