@industry-theme/xterm-terminal-panel 0.5.33 → 0.5.35
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/index.js +41 -90
- package/dist/src/panels/TerminalPanel.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -35,7 +35,7 @@ import {
|
|
|
35
35
|
// package.json
|
|
36
36
|
var package_default = {
|
|
37
37
|
name: "@industry-theme/xterm-terminal-panel",
|
|
38
|
-
version: "0.5.
|
|
38
|
+
version: "0.5.35",
|
|
39
39
|
description: "Industry-themed xterm.js terminal components with panel framework integration",
|
|
40
40
|
type: "module",
|
|
41
41
|
main: "dist/index.js",
|
|
@@ -1756,68 +1756,29 @@ var TerminalPanel = ({
|
|
|
1756
1756
|
const [sessionId, setSessionId] = useState3(null);
|
|
1757
1757
|
const [error, setError] = useState3(null);
|
|
1758
1758
|
const [isInitializing, setIsInitializing] = useState3(true);
|
|
1759
|
-
const [usingMessagePort, setUsingMessagePort] = useState3(false);
|
|
1760
1759
|
const [scrollPosition, setScrollPosition] = useState3({
|
|
1761
1760
|
isAtTop: false,
|
|
1762
1761
|
isAtBottom: true,
|
|
1763
1762
|
isScrollLocked: false
|
|
1764
1763
|
});
|
|
1765
1764
|
const terminalRef = useRef2(null);
|
|
1766
|
-
const dataPortRef = useRef2(null);
|
|
1767
1765
|
const isScrollLockedRef = useRef2(scrollPosition.isScrollLocked);
|
|
1768
1766
|
const terminalDirectory = getTerminalDirectory(context2, terminalScope);
|
|
1769
1767
|
const pendingSessionIdRef = useRef2(null);
|
|
1770
|
-
const pendingPortEventsRef = useRef2([]);
|
|
1771
1768
|
useEffect3(() => {
|
|
1772
1769
|
let mounted = true;
|
|
1773
|
-
let unsubscribePortReady = null;
|
|
1774
|
-
const adoptPort = (port) => {
|
|
1775
|
-
dataPortRef.current = port;
|
|
1776
|
-
if (typeof port.start === "function") {
|
|
1777
|
-
port.start();
|
|
1778
|
-
}
|
|
1779
|
-
if (mounted) {
|
|
1780
|
-
setUsingMessagePort(true);
|
|
1781
|
-
}
|
|
1782
|
-
};
|
|
1783
1770
|
const initTerminal = async () => {
|
|
1784
1771
|
try {
|
|
1785
1772
|
if (!actions.createTerminalSession) {
|
|
1786
1773
|
throw new Error("Terminal actions not available. Host must provide createTerminalSession action.");
|
|
1787
1774
|
}
|
|
1788
|
-
if (!actions.onTerminalPortReady) {
|
|
1789
|
-
throw new Error("MessagePort support not available. Host must provide onTerminalPortReady action.");
|
|
1790
|
-
}
|
|
1791
|
-
unsubscribePortReady = actions.onTerminalPortReady((data, port) => {
|
|
1792
|
-
if (pendingSessionIdRef.current === null) {
|
|
1793
|
-
pendingPortEventsRef.current.push({ data, port });
|
|
1794
|
-
return;
|
|
1795
|
-
}
|
|
1796
|
-
if (data.sessionId === pendingSessionIdRef.current || data.sessionId === sessionId) {
|
|
1797
|
-
adoptPort(port);
|
|
1798
|
-
}
|
|
1799
|
-
});
|
|
1800
1775
|
const id = await actions.createTerminalSession({
|
|
1801
1776
|
cwd: terminalDirectory || undefined
|
|
1802
1777
|
});
|
|
1803
1778
|
pendingSessionIdRef.current = id;
|
|
1804
|
-
const buffered = pendingPortEventsRef.current;
|
|
1805
|
-
pendingPortEventsRef.current = [];
|
|
1806
|
-
for (const evt of buffered) {
|
|
1807
|
-
if (evt.data.sessionId === id && !dataPortRef.current) {
|
|
1808
|
-
adoptPort(evt.port);
|
|
1809
|
-
}
|
|
1810
|
-
}
|
|
1811
1779
|
if (actions.claimTerminalOwnership) {
|
|
1812
1780
|
await actions.claimTerminalOwnership(id);
|
|
1813
1781
|
}
|
|
1814
|
-
if (!dataPortRef.current && actions.requestTerminalDataPort) {
|
|
1815
|
-
try {
|
|
1816
|
-
await actions.requestTerminalDataPort(id);
|
|
1817
|
-
} catch (portErr) {
|
|
1818
|
-
console.warn("[TerminalPanel] requestTerminalDataPort failed:", portErr);
|
|
1819
|
-
}
|
|
1820
|
-
}
|
|
1821
1782
|
if (mounted) {
|
|
1822
1783
|
setSessionId(id);
|
|
1823
1784
|
setIsInitializing(false);
|
|
@@ -1832,73 +1793,48 @@ var TerminalPanel = ({
|
|
|
1832
1793
|
initTerminal();
|
|
1833
1794
|
return () => {
|
|
1834
1795
|
mounted = false;
|
|
1835
|
-
if (unsubscribePortReady) {
|
|
1836
|
-
unsubscribePortReady();
|
|
1837
|
-
}
|
|
1838
1796
|
if (pendingSessionIdRef.current && actions.destroyTerminalSession) {
|
|
1839
1797
|
actions.destroyTerminalSession(pendingSessionIdRef.current);
|
|
1840
1798
|
}
|
|
1841
|
-
if (dataPortRef.current) {
|
|
1842
|
-
if (typeof dataPortRef.current.close === "function") {
|
|
1843
|
-
dataPortRef.current.close();
|
|
1844
|
-
}
|
|
1845
|
-
dataPortRef.current = null;
|
|
1846
|
-
}
|
|
1847
1799
|
};
|
|
1848
1800
|
}, []);
|
|
1849
1801
|
useEffect3(() => {
|
|
1850
|
-
if (usingMessagePort)
|
|
1851
|
-
return;
|
|
1852
1802
|
if (!sessionId)
|
|
1853
1803
|
return;
|
|
1854
|
-
|
|
1855
|
-
|
|
1856
|
-
console.error("[TerminalPanel] MessagePort not received after timeout - terminal data will not be displayed");
|
|
1857
|
-
setError("MessagePort not available. Terminal data streaming requires MessagePort support from the host.");
|
|
1858
|
-
}
|
|
1859
|
-
}, 5000);
|
|
1860
|
-
return () => clearTimeout(timeout);
|
|
1861
|
-
}, [sessionId, usingMessagePort]);
|
|
1862
|
-
useEffect3(() => {
|
|
1863
|
-
if (!usingMessagePort || !dataPortRef.current) {
|
|
1804
|
+
if (!actions.onTerminalData) {
|
|
1805
|
+
setError("Host does not provide onTerminalData. Terminal data cannot be displayed.");
|
|
1864
1806
|
return;
|
|
1865
1807
|
}
|
|
1866
|
-
const port = dataPortRef.current;
|
|
1867
|
-
let lastWriteTime = 0;
|
|
1868
1808
|
let cursorMovedToHome = false;
|
|
1809
|
+
let lastWriteTime = 0;
|
|
1869
1810
|
let autoScrollTimeout = null;
|
|
1870
|
-
const
|
|
1871
|
-
if (
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
lastWriteTime = Date.now();
|
|
1876
|
-
}
|
|
1877
|
-
terminalRef.current.write(data);
|
|
1878
|
-
if (cursorMovedToHome && isScrollLockedRef.current) {
|
|
1879
|
-
if (autoScrollTimeout) {
|
|
1880
|
-
clearTimeout(autoScrollTimeout);
|
|
1881
|
-
}
|
|
1882
|
-
autoScrollTimeout = setTimeout(() => {
|
|
1883
|
-
const now = Date.now();
|
|
1884
|
-
const timeSinceLastWrite = now - lastWriteTime;
|
|
1885
|
-
if (timeSinceLastWrite >= 100 && cursorMovedToHome && terminalRef.current) {
|
|
1886
|
-
terminalRef.current.write("\x1B[9999;1H");
|
|
1887
|
-
cursorMovedToHome = false;
|
|
1888
|
-
}
|
|
1889
|
-
}, 100);
|
|
1890
|
-
}
|
|
1811
|
+
const unsubscribe = actions.onTerminalData(sessionId, (data) => {
|
|
1812
|
+
if (!terminalRef.current)
|
|
1813
|
+
return;
|
|
1814
|
+
if (data.includes("\x1B[H")) {
|
|
1815
|
+
cursorMovedToHome = true;
|
|
1891
1816
|
lastWriteTime = Date.now();
|
|
1892
1817
|
}
|
|
1893
|
-
|
|
1894
|
-
|
|
1818
|
+
terminalRef.current.write(data);
|
|
1819
|
+
if (cursorMovedToHome && isScrollLockedRef.current) {
|
|
1820
|
+
if (autoScrollTimeout)
|
|
1821
|
+
clearTimeout(autoScrollTimeout);
|
|
1822
|
+
autoScrollTimeout = setTimeout(() => {
|
|
1823
|
+
const timeSinceLastWrite = Date.now() - lastWriteTime;
|
|
1824
|
+
if (timeSinceLastWrite >= 100 && cursorMovedToHome && terminalRef.current) {
|
|
1825
|
+
terminalRef.current.write("\x1B[9999;1H");
|
|
1826
|
+
cursorMovedToHome = false;
|
|
1827
|
+
}
|
|
1828
|
+
}, 100);
|
|
1829
|
+
}
|
|
1830
|
+
lastWriteTime = Date.now();
|
|
1831
|
+
});
|
|
1895
1832
|
return () => {
|
|
1896
|
-
|
|
1897
|
-
if (autoScrollTimeout) {
|
|
1833
|
+
if (autoScrollTimeout)
|
|
1898
1834
|
clearTimeout(autoScrollTimeout);
|
|
1899
|
-
|
|
1835
|
+
unsubscribe();
|
|
1900
1836
|
};
|
|
1901
|
-
}, [
|
|
1837
|
+
}, [sessionId, actions.onTerminalData]);
|
|
1902
1838
|
const handleTerminalData = useCallback4((data) => {
|
|
1903
1839
|
if (sessionId && actions.writeToTerminal) {
|
|
1904
1840
|
actions.writeToTerminal(sessionId, data);
|
|
@@ -1920,6 +1856,21 @@ var TerminalPanel = ({
|
|
|
1920
1856
|
useEffect3(() => {
|
|
1921
1857
|
hasNotifiedPtyRef.current = false;
|
|
1922
1858
|
}, [sessionId]);
|
|
1859
|
+
useEffect3(() => {
|
|
1860
|
+
if (!sessionId || !actions.resizeTerminal)
|
|
1861
|
+
return;
|
|
1862
|
+
if (hasNotifiedPtyRef.current)
|
|
1863
|
+
return;
|
|
1864
|
+
const term = terminalRef.current?.getTerminal();
|
|
1865
|
+
if (!term || !term.cols || !term.rows)
|
|
1866
|
+
return;
|
|
1867
|
+
actions.resizeTerminal(sessionId, term.cols, term.rows);
|
|
1868
|
+
hasNotifiedPtyRef.current = true;
|
|
1869
|
+
if (actions.writeToTerminal) {
|
|
1870
|
+
const writeFn = actions.writeToTerminal;
|
|
1871
|
+
setTimeout(() => writeFn(sessionId, "\f"), 50);
|
|
1872
|
+
}
|
|
1873
|
+
}, [sessionId, actions.resizeTerminal, actions.writeToTerminal]);
|
|
1923
1874
|
const handleScrollPositionChange = useCallback4((position) => {
|
|
1924
1875
|
setScrollPosition(position);
|
|
1925
1876
|
isScrollLockedRef.current = position.isScrollLocked;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TerminalPanel.d.ts","sourceRoot":"","sources":["../../../src/panels/TerminalPanel.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,kBAAkB,
|
|
1
|
+
{"version":3,"file":"TerminalPanel.d.ts","sourceRoot":"","sources":["../../../src/panels/TerminalPanel.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AA+BzD,eAAO,MAAM,aAAa,EAAE,KAAK,CAAC,EAAE,CAAC,kBAAkB,CA2XtD,CAAC"}
|
package/package.json
CHANGED