@hrnec06/react_utils 1.7.0 → 1.7.1
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/README.md +1 -0
- package/package.json +2 -2
- package/src/components/Debugger/parser/DebugParser.tsx +3 -7
- package/src/components/Debugger/parser/DebugTerminal.tsx +26 -9
- package/src/components/Debugger/parser/ValueArray.tsx +21 -12
- package/src/components/Debugger/parser/ValueObject.tsx +21 -13
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
A source only React Library for private use.
|
package/package.json
CHANGED
|
@@ -20,7 +20,7 @@ import useDebounce from "../../../hooks/useDebounce";
|
|
|
20
20
|
import { useCTXMListener } from "../../ContextMenu/ContextMenuCtx";
|
|
21
21
|
|
|
22
22
|
export interface ParseValueRef {
|
|
23
|
-
copyValue
|
|
23
|
+
copyValue?: string,
|
|
24
24
|
name?: string,
|
|
25
25
|
menu?: CTXM.ContextMenuSection,
|
|
26
26
|
}
|
|
@@ -116,13 +116,9 @@ export function DebugCTXMProvider({
|
|
|
116
116
|
return path.join('.');
|
|
117
117
|
}, [path]);
|
|
118
118
|
|
|
119
|
-
const handleCopy = ref === null
|
|
119
|
+
const handleCopy = (ref === null || ref.copyValue === undefined)
|
|
120
120
|
? undefined
|
|
121
|
-
: () =>
|
|
122
|
-
if (!ref) return;
|
|
123
|
-
|
|
124
|
-
navigator.clipboard.writeText(ref.copyValue);
|
|
125
|
-
};
|
|
121
|
+
: () => navigator.clipboard.writeText(ref.copyValue!);
|
|
126
122
|
|
|
127
123
|
return (
|
|
128
124
|
<ContextMenu
|
|
@@ -35,17 +35,34 @@ const DebugTerminal = forwardRef<ParseValueRef, DebugTerminalProps>(({
|
|
|
35
35
|
}, ref) => {
|
|
36
36
|
const [showing, setShowing] = useState(!!defaultExpanded);
|
|
37
37
|
|
|
38
|
-
useImperativeHandle(ref, () =>
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
useImperativeHandle(ref, () => {
|
|
39
|
+
const logToString = (log: LogItem) => {
|
|
40
|
+
let value: string;
|
|
41
|
+
|
|
42
|
+
try
|
|
43
|
+
{
|
|
44
|
+
value = JSON.stringify(log.value);
|
|
45
|
+
}
|
|
46
|
+
catch (error)
|
|
42
47
|
{
|
|
43
|
-
|
|
44
|
-
label: "Clear",
|
|
45
|
-
onClick: () => terminal.clear(),
|
|
48
|
+
value = `Error parsing value (${typeof log.value})`;
|
|
46
49
|
}
|
|
47
|
-
|
|
48
|
-
|
|
50
|
+
|
|
51
|
+
return `${log.role === LogRole.Input ? '> ' : `${LogType[log.type]}: `}${value}`;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
name: `Terminal ${terminal.name}`,
|
|
56
|
+
copyValue: terminal.getLog().reduce((prev, curr) => prev + logToString(curr) + "\n", ""),
|
|
57
|
+
menu: [
|
|
58
|
+
{
|
|
59
|
+
id: "terminal-clear",
|
|
60
|
+
label: "Clear",
|
|
61
|
+
onClick: () => terminal.clear(),
|
|
62
|
+
}
|
|
63
|
+
]
|
|
64
|
+
};
|
|
65
|
+
}, [terminal.getLog()]);
|
|
49
66
|
|
|
50
67
|
const handleToggle = (value: boolean) => {
|
|
51
68
|
setShowing(value);
|
|
@@ -3,6 +3,7 @@ import useDebugger from "../DebuggerContext";
|
|
|
3
3
|
import { Char_Bracket, Char_Comma, Chevron_Toggle } from "../DebuggerSymbols";
|
|
4
4
|
import ParseValueSimple from "./DebugParserSimple";
|
|
5
5
|
import ParseValue, { ParseValueRef } from "./DebugParser";
|
|
6
|
+
import { Optional } from "@hrnec06/util";
|
|
6
7
|
|
|
7
8
|
interface ValueArrayProps {
|
|
8
9
|
value: unknown[],
|
|
@@ -18,19 +19,27 @@ const ValueArray = forwardRef<ParseValueRef, ValueArrayProps>(({
|
|
|
18
19
|
|
|
19
20
|
const [expanded, setExpanded] = useState(defaultExpanded);
|
|
20
21
|
|
|
21
|
-
useImperativeHandle(ref, () =>
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
22
|
+
useImperativeHandle(ref, () => {
|
|
23
|
+
let copyValue: Optional<string> = undefined;
|
|
24
|
+
try
|
|
25
|
+
{
|
|
26
|
+
copyValue = JSON.stringify(value);
|
|
27
|
+
} catch {}
|
|
28
|
+
|
|
29
|
+
return {
|
|
30
|
+
name: `Array (${value.length})`,
|
|
31
|
+
copyValue: copyValue,
|
|
32
|
+
menu: [
|
|
33
|
+
{
|
|
34
|
+
id: "open-toggle",
|
|
35
|
+
label: expanded ? "Collapse" : "Expand",
|
|
36
|
+
onClick: () => {
|
|
37
|
+
setExpanded(!expanded);
|
|
38
|
+
}
|
|
30
39
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
40
|
+
]
|
|
41
|
+
};
|
|
42
|
+
}, [value, expanded]);
|
|
34
43
|
|
|
35
44
|
const children = useMemo(() => {
|
|
36
45
|
const children: React.ReactNode[] = [];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, { forwardRef, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
2
2
|
import useDebugger from "../DebuggerContext";
|
|
3
|
-
import { entries, keys, Nullable } from "@hrnec06/util";
|
|
3
|
+
import { entries, keys, Nullable, Optional } from "@hrnec06/util";
|
|
4
4
|
import { Char_Bracket, Char_Colon, Char_Comma, Chevron_Toggle } from "../DebuggerSymbols";
|
|
5
5
|
import ParseValue, { DebugCTXMProvider, ParseValueRef } from "./DebugParser";
|
|
6
6
|
import useSyncRef from "../../../hooks/useSyncRef";
|
|
@@ -22,19 +22,27 @@ const ValueObject = forwardRef<ParseValueRef, ValueObjectProps>(({
|
|
|
22
22
|
|
|
23
23
|
const objectEntries = entries(value);
|
|
24
24
|
|
|
25
|
-
useImperativeHandle(ref, () =>
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
25
|
+
useImperativeHandle(ref, () => {
|
|
26
|
+
let copyValue: Optional<string> = undefined;
|
|
27
|
+
try
|
|
28
|
+
{
|
|
29
|
+
copyValue = JSON.stringify(value);
|
|
30
|
+
} catch {}
|
|
31
|
+
|
|
32
|
+
return {
|
|
33
|
+
name: `Object {${objectEntries.length}}`,
|
|
34
|
+
copyValue: copyValue,
|
|
35
|
+
menu: [
|
|
36
|
+
{
|
|
37
|
+
id: "open-toggle",
|
|
38
|
+
label: expanded ? "Collapse" : "Expand",
|
|
39
|
+
onClick: () => {
|
|
40
|
+
setExpanded(!expanded);
|
|
41
|
+
}
|
|
34
42
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
43
|
+
]
|
|
44
|
+
};
|
|
45
|
+
}, [value, expanded]);
|
|
38
46
|
|
|
39
47
|
const collapsedPreview = useMemo(() => {
|
|
40
48
|
const children: React.ReactNode[] = [];
|