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