mirror of
https://github.com/wavetermdev/waveterm.git
synced 2024-12-21 16:38:23 +01:00
debounce resize handler, fix useEffect() in term.tsx
This commit is contained in:
parent
2f2ff8a1cb
commit
cf85ad0980
@ -23,7 +23,6 @@ const Block = ({ blockId, onClose }: BlockProps) => {
|
|||||||
let blockElem: JSX.Element = null;
|
let blockElem: JSX.Element = null;
|
||||||
const [blockData, blockDataLoading] = WOS.useWaveObjectValue<Block>(WOS.makeORef("block", blockId));
|
const [blockData, blockDataLoading] = WOS.useWaveObjectValue<Block>(WOS.makeORef("block", blockId));
|
||||||
if (!blockId || !blockData) return null;
|
if (!blockId || !blockData) return null;
|
||||||
console.log("blockData: ", blockData);
|
|
||||||
if (blockDataLoading) {
|
if (blockDataLoading) {
|
||||||
blockElem = <CenteredDiv>Loading...</CenteredDiv>;
|
blockElem = <CenteredDiv>Loading...</CenteredDiv>;
|
||||||
} else if (blockData.view === "term") {
|
} else if (blockData.view === "term") {
|
||||||
@ -38,7 +37,9 @@ const Block = ({ blockId, onClose }: BlockProps) => {
|
|||||||
return (
|
return (
|
||||||
<div className="block" ref={blockRef}>
|
<div className="block" ref={blockRef}>
|
||||||
<div key="header" className="block-header">
|
<div key="header" className="block-header">
|
||||||
<div className="block-header-text text-fixed">Block [{blockId.substring(0, 8)}]</div>
|
<div className="block-header-text text-fixed">
|
||||||
|
Block [{blockId.substring(0, 8)}] {blockData.view}
|
||||||
|
</div>
|
||||||
<div className="flex-spacer" />
|
<div className="flex-spacer" />
|
||||||
<div className="close-button" onClick={onClose}>
|
<div className="close-button" onClick={onClose}>
|
||||||
<i className="fa fa-solid fa-xmark-large" />
|
<i className="fa fa-solid fa-xmark-large" />
|
||||||
|
@ -8,6 +8,7 @@ import { FitAddon } from "@xterm/addon-fit";
|
|||||||
import type { ITheme } from "@xterm/xterm";
|
import type { ITheme } from "@xterm/xterm";
|
||||||
import { Terminal } from "@xterm/xterm";
|
import { Terminal } from "@xterm/xterm";
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
|
import { debounce } from "throttle-debounce";
|
||||||
|
|
||||||
import "./view.less";
|
import "./view.less";
|
||||||
import "/public/xterm.css";
|
import "/public/xterm.css";
|
||||||
@ -40,6 +41,16 @@ function getThemeFromCSSVars(el: Element): ITheme {
|
|||||||
return theme;
|
return theme;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function handleResize(fitAddon: FitAddon, blockId: string, term: Terminal) {
|
||||||
|
const oldRows = term.rows;
|
||||||
|
const oldCols = term.cols;
|
||||||
|
fitAddon.fit();
|
||||||
|
if (oldRows !== term.rows || oldCols !== term.cols) {
|
||||||
|
const resizeCommand = { command: "controller:input", termsize: { rows: term.rows, cols: term.cols } };
|
||||||
|
BlockService.SendCommand(blockId, resizeCommand);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type InitialLoadDataType = {
|
type InitialLoadDataType = {
|
||||||
loaded: boolean;
|
loaded: boolean;
|
||||||
heldData: Uint8Array[];
|
heldData: Uint8Array[];
|
||||||
@ -78,16 +89,9 @@ const TerminalView = ({ blockId }: { blockId: string }) => {
|
|||||||
BlockService.SendCommand(blockId, inputCmd);
|
BlockService.SendCommand(blockId, inputCmd);
|
||||||
});
|
});
|
||||||
// resize observer
|
// resize observer
|
||||||
|
const handleResize_debounced = debounce(50, handleResize);
|
||||||
const rszObs = new ResizeObserver(() => {
|
const rszObs = new ResizeObserver(() => {
|
||||||
const oldRows = term.rows;
|
handleResize_debounced(fitAddon, blockId, term);
|
||||||
const oldCols = term.cols;
|
|
||||||
fitAddon.fit();
|
|
||||||
if (oldRows !== term.rows || oldCols !== term.cols) {
|
|
||||||
BlockService.SendCommand(blockId, {
|
|
||||||
command: "controller:input",
|
|
||||||
termsize: { rows: term.rows, cols: term.cols },
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
rszObs.observe(connectElemRef.current);
|
rszObs.observe(connectElemRef.current);
|
||||||
|
|
||||||
@ -108,7 +112,7 @@ const TerminalView = ({ blockId }: { blockId: string }) => {
|
|||||||
rszObs.disconnect();
|
rszObs.disconnect();
|
||||||
blockSubject.release();
|
blockSubject.release();
|
||||||
};
|
};
|
||||||
}, [connectElemRef.current]);
|
}, []);
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (!termRef.current) {
|
if (!termRef.current) {
|
||||||
@ -141,7 +145,7 @@ const TerminalView = ({ blockId }: { blockId: string }) => {
|
|||||||
initialLoadRef.current.heldData = [];
|
initialLoadRef.current.heldData = [];
|
||||||
console.log(`terminal loaded file ${loadedBytes} bytes, ${Date.now() - startTs}ms`);
|
console.log(`terminal loaded file ${loadedBytes} bytes, ${Date.now() - startTs}ms`);
|
||||||
});
|
});
|
||||||
}, [termRef.current]);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="view-term">
|
<div className="view-term">
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
flex-grow: 1;
|
flex-grow: 1;
|
||||||
min-height: 0;
|
min-height: 0;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
line-height: 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +41,6 @@ export const TileLayout = <T,>({ layoutTreeStateAtom, className, renderContent,
|
|||||||
(id: string, ref: RefObject<HTMLDivElement>) => {
|
(id: string, ref: RefObject<HTMLDivElement>) => {
|
||||||
setNodeRefs((prev) => {
|
setNodeRefs((prev) => {
|
||||||
prev.set(id, ref);
|
prev.set(id, ref);
|
||||||
console.log("setRef", id, ref, prev);
|
|
||||||
return prev;
|
return prev;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@ -53,7 +52,6 @@ export const TileLayout = <T,>({ layoutTreeStateAtom, className, renderContent,
|
|||||||
if (nodeRefs.has(id)) {
|
if (nodeRefs.has(id)) {
|
||||||
setNodeRefs((prev) => {
|
setNodeRefs((prev) => {
|
||||||
prev.delete(id);
|
prev.delete(id);
|
||||||
console.log("deleteRef", id, prev);
|
|
||||||
return prev;
|
return prev;
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -239,7 +237,6 @@ const TileNode = <T,>({ layoutNode, renderContent, transform, onLeafClose }: Til
|
|||||||
|
|
||||||
// Register the tile item as a draggable component
|
// Register the tile item as a draggable component
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
console.log("set drag", layoutNode);
|
|
||||||
drag(tileNodeRef);
|
drag(tileNodeRef);
|
||||||
dragPreview(tileNodeRef);
|
dragPreview(tileNodeRef);
|
||||||
}, [tileNodeRef]);
|
}, [tileNodeRef]);
|
||||||
|
@ -66,7 +66,7 @@
|
|||||||
flex: 1 1 auto;
|
flex: 1 1 auto;
|
||||||
max-height: 100%;
|
max-height: 100%;
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
margin: 5px;
|
/* margin: 5px; */
|
||||||
}
|
}
|
||||||
|
|
||||||
.tile-leaf {
|
.tile-leaf {
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
"@storybook/test": "^8.1.4",
|
"@storybook/test": "^8.1.4",
|
||||||
"@types/node": "^20.12.12",
|
"@types/node": "^20.12.12",
|
||||||
"@types/react": "^18.3.2",
|
"@types/react": "^18.3.2",
|
||||||
|
"@types/throttle-debounce": "^5",
|
||||||
"@types/uuid": "^9.0.8",
|
"@types/uuid": "^9.0.8",
|
||||||
"@vitejs/plugin-react": "^4.3.0",
|
"@vitejs/plugin-react": "^4.3.0",
|
||||||
"@vitest/coverage-istanbul": "^1.6.0",
|
"@vitest/coverage-istanbul": "^1.6.0",
|
||||||
@ -65,6 +66,7 @@
|
|||||||
"react-markdown": "^9.0.1",
|
"react-markdown": "^9.0.1",
|
||||||
"remark-gfm": "^4.0.0",
|
"remark-gfm": "^4.0.0",
|
||||||
"rxjs": "^7.8.1",
|
"rxjs": "^7.8.1",
|
||||||
|
"throttle-debounce": "^5.0.0",
|
||||||
"uuid": "^9.0.1"
|
"uuid": "^9.0.1"
|
||||||
},
|
},
|
||||||
"packageManager": "yarn@4.2.1"
|
"packageManager": "yarn@4.2.1"
|
||||||
|
@ -5,11 +5,11 @@
|
|||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>Wails App</title>
|
<title>Wails App</title>
|
||||||
<link rel="stylesheet" href="/public/fontawesome/css/fontawesome.min.css" />
|
<link rel="stylesheet" href="/fontawesome/css/fontawesome.min.css" />
|
||||||
<link rel="stylesheet" href="/public/fontawesome/css/brands.min.css" />
|
<link rel="stylesheet" href="/fontawesome/css/brands.min.css" />
|
||||||
<link rel="stylesheet" href="/public/fontawesome/css/solid.min.css" />
|
<link rel="stylesheet" href="/fontawesome/css/solid.min.css" />
|
||||||
<link rel="stylesheet" href="/public/fontawesome/css/sharp-solid.min.css" />
|
<link rel="stylesheet" href="/fontawesome/css/sharp-solid.min.css" />
|
||||||
<link rel="stylesheet" href="/public/fontawesome/css/sharp-regular.min.css" />
|
<link rel="stylesheet" href="/fontawesome/css/sharp-regular.min.css" />
|
||||||
<script type="module" src="/frontend/wave.ts"></script>
|
<script type="module" src="/frontend/wave.ts"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
16
yarn.lock
16
yarn.lock
@ -3728,6 +3728,13 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
|
"@types/throttle-debounce@npm:^5":
|
||||||
|
version: 5.0.2
|
||||||
|
resolution: "@types/throttle-debounce@npm:5.0.2"
|
||||||
|
checksum: 10c0/526084a7b83edd5c008f193a80c1f6851421d44921e874032d63a598047e17c1a5c97fe99a9dbf806e3d0b49a40d8c4171541a32ea1911d45b5216ddf129d51a
|
||||||
|
languageName: node
|
||||||
|
linkType: hard
|
||||||
|
|
||||||
"@types/unist@npm:*, @types/unist@npm:^3.0.0":
|
"@types/unist@npm:*, @types/unist@npm:^3.0.0":
|
||||||
version: 3.0.2
|
version: 3.0.2
|
||||||
resolution: "@types/unist@npm:3.0.2"
|
resolution: "@types/unist@npm:3.0.2"
|
||||||
@ -11069,6 +11076,7 @@ __metadata:
|
|||||||
"@tanstack/react-table": "npm:^8.17.3"
|
"@tanstack/react-table": "npm:^8.17.3"
|
||||||
"@types/node": "npm:^20.12.12"
|
"@types/node": "npm:^20.12.12"
|
||||||
"@types/react": "npm:^18.3.2"
|
"@types/react": "npm:^18.3.2"
|
||||||
|
"@types/throttle-debounce": "npm:^5"
|
||||||
"@types/uuid": "npm:^9.0.8"
|
"@types/uuid": "npm:^9.0.8"
|
||||||
"@vitejs/plugin-react": "npm:^4.3.0"
|
"@vitejs/plugin-react": "npm:^4.3.0"
|
||||||
"@vitest/coverage-istanbul": "npm:^1.6.0"
|
"@vitest/coverage-istanbul": "npm:^1.6.0"
|
||||||
@ -11094,6 +11102,7 @@ __metadata:
|
|||||||
remark-gfm: "npm:^4.0.0"
|
remark-gfm: "npm:^4.0.0"
|
||||||
rxjs: "npm:^7.8.1"
|
rxjs: "npm:^7.8.1"
|
||||||
storybook: "npm:^8.1.4"
|
storybook: "npm:^8.1.4"
|
||||||
|
throttle-debounce: "npm:^5.0.0"
|
||||||
ts-node: "npm:^10.9.2"
|
ts-node: "npm:^10.9.2"
|
||||||
tslib: "npm:^2.6.2"
|
tslib: "npm:^2.6.2"
|
||||||
typescript: "npm:^5.4.5"
|
typescript: "npm:^5.4.5"
|
||||||
@ -11106,6 +11115,13 @@ __metadata:
|
|||||||
languageName: unknown
|
languageName: unknown
|
||||||
linkType: soft
|
linkType: soft
|
||||||
|
|
||||||
|
"throttle-debounce@npm:^5.0.0":
|
||||||
|
version: 5.0.0
|
||||||
|
resolution: "throttle-debounce@npm:5.0.0"
|
||||||
|
checksum: 10c0/666d5b73bfa7340c5186b244416ce965cd276e4bc91a12453ff6eddcc62f02a19c6f532305601d90c809dd5acbd45dd6eea5eb43e0a879a0b3d66d0886a4d8d2
|
||||||
|
languageName: node
|
||||||
|
linkType: hard
|
||||||
|
|
||||||
"through2@npm:^2.0.3":
|
"through2@npm:^2.0.3":
|
||||||
version: 2.0.5
|
version: 2.0.5
|
||||||
resolution: "through2@npm:2.0.5"
|
resolution: "through2@npm:2.0.5"
|
||||||
|
Loading…
Reference in New Issue
Block a user