@tooee/layout 0.16.2 → 0.16.4
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/overlay-panel.d.ts +2 -7
- package/dist/overlay-panel.d.ts.map +1 -1
- package/dist/overlay-panel.js +6 -2
- package/dist/overlay-panel.js.map +1 -1
- package/dist/panel-inset.d.ts +37 -0
- package/dist/panel-inset.d.ts.map +1 -0
- package/dist/panel-inset.js +58 -0
- package/dist/panel-inset.js.map +1 -0
- package/package.json +10 -10
- package/src/overlay-panel.tsx +13 -14
- package/src/panel-inset.ts +105 -0
package/dist/overlay-panel.d.ts
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
import type { MouseEvent } from "@opentui/core";
|
|
2
2
|
import type { ReactNode } from "react";
|
|
3
|
-
|
|
4
|
-
export
|
|
5
|
-
left?: PanelInsetValue;
|
|
6
|
-
right?: PanelInsetValue;
|
|
7
|
-
top?: PanelInsetValue;
|
|
8
|
-
bottom?: PanelInsetValue;
|
|
9
|
-
}
|
|
3
|
+
import type { PanelInset } from "./panel-inset.js";
|
|
4
|
+
export type { PanelInset, PanelInsetValue } from "./panel-inset.js";
|
|
10
5
|
export interface OverlayPanelProps {
|
|
11
6
|
/** Title bar content. Primitive text uses the active accent color. */
|
|
12
7
|
title?: ReactNode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"overlay-panel.d.ts","sourceRoot":"","sources":["../src/overlay-panel.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"overlay-panel.d.ts","sourceRoot":"","sources":["../src/overlay-panel.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAiB,UAAU,EAAE,MAAM,eAAe,CAAC;AAG/D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAIvC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAInD,YAAY,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAEpE,MAAM,WAAW,iBAAiB;IAChC,sEAAsE;IACtE,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,yDAAyD;IACzD,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB,QAAQ,EAAE,SAAS,CAAC;IACpB,uDAAuD;IACvD,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB,qCAAqC;IACrC,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,iDAAiD;IACjD,WAAW,CAAC,EAAE,SAAS,CAAC;IACxB,iFAAiF;IACjF,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB,qCAAqC;IACrC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,yCAAyC;IACzC,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,UAAU,KAAK,IAAI,CAAC;CAC3C;AAkCD,uDAAuD;AACvD,eAAO,MAAM,YAAY,0FAUtB,iBAAiB,KAAG,SAmEtB,CAAC"}
|
package/dist/overlay-panel.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "@opentui/react/jsx-runtime";
|
|
2
2
|
import { useTheme } from "@tooee/themes";
|
|
3
|
+
import { useRef } from "react";
|
|
3
4
|
import { CloseButton } from "./close-button.js";
|
|
5
|
+
import { resolvePanelInset, useContainerSize } from "./panel-inset.js";
|
|
4
6
|
import { decodeReactContent } from "./react-content.js";
|
|
5
7
|
const renderThemedContent = function renderThemedContent(content, color) {
|
|
6
8
|
if (content.kind === "empty") {
|
|
@@ -15,7 +17,7 @@ const renderPrompt = function renderPrompt(prompt, textColor) {
|
|
|
15
17
|
if (prompt.kind === "node") {
|
|
16
18
|
return prompt.value;
|
|
17
19
|
}
|
|
18
|
-
return (_jsx("box", { paddingLeft: 1, paddingRight: 1, children: _jsx("text", { fg: textColor, children: _jsx("strong", { children: prompt.value }) }) }));
|
|
20
|
+
return (_jsx("box", { paddingLeft: 1, paddingRight: 1, flexShrink: 0, children: _jsx("text", { fg: textColor, children: _jsx("strong", { children: prompt.value }) }) }));
|
|
19
21
|
};
|
|
20
22
|
/** Shared bordered chrome for modal overlay panels. */
|
|
21
23
|
export const OverlayPanel = function OverlayPanel({ title, prompt, children, footer, hints, statusRight, inset, onClose, onMouseDown, }) {
|
|
@@ -25,6 +27,8 @@ export const OverlayPanel = function OverlayPanel({ title, prompt, children, foo
|
|
|
25
27
|
const decodedFooter = decodeReactContent(footer);
|
|
26
28
|
const decodedHints = decodeReactContent(hints);
|
|
27
29
|
const decodedStatus = decodeReactContent(statusRight);
|
|
28
|
-
|
|
30
|
+
const panelRef = useRef(null);
|
|
31
|
+
const edges = resolvePanelInset(inset, useContainerSize(panelRef));
|
|
32
|
+
return (_jsxs("box", { ref: panelRef, position: "absolute", left: edges.left, right: edges.right, top: edges.top, bottom: edges.bottom, flexDirection: "column", backgroundColor: theme.backgroundPanel, border: true, borderColor: theme.borderActive, onMouseDown: onMouseDown, children: [decodedTitle.kind !== "empty" && (_jsxs("box", { flexDirection: "row", height: 1, paddingLeft: 1, paddingRight: 1, backgroundColor: theme.backgroundElement, children: [decodedTitle.kind === "string" ? (_jsx("text", { content: decodedTitle.value, fg: theme.accent, style: { flexGrow: 1 } })) : (_jsx("box", { flexDirection: "row", style: { flexGrow: 1 }, children: decodedTitle.value })), onClose && _jsx(CloseButton, { onClose: onClose })] })), renderPrompt(decodedPrompt, theme.text), children, decodedFooter.kind !== "empty" && (_jsx("box", { height: 1, paddingLeft: 1, paddingRight: 1, children: decodedFooter.value })), _jsxs("box", { flexDirection: "row", height: 1, paddingLeft: 1, paddingRight: 1, backgroundColor: theme.backgroundElement, children: [_jsx("box", { flexDirection: "row", style: { flexGrow: 1 }, children: renderThemedContent(decodedHints, theme.textMuted) }), renderThemedContent(decodedStatus, theme.textMuted)] })] }));
|
|
29
33
|
};
|
|
30
34
|
//# sourceMappingURL=overlay-panel.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"overlay-panel.js","sourceRoot":"","sources":["../src/overlay-panel.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"overlay-panel.js","sourceRoot":"","sources":["../src/overlay-panel.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAG/B,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAyBxD,MAAM,mBAAmB,GAAG,SAAS,mBAAmB,CACtD,OAA4B,EAC5B,KAAa;IAEb,IAAI,OAAO,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;QAC7B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,OAAO,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,eAAM,OAAO,EAAE,OAAO,CAAC,KAAK,EAAE,EAAE,EAAE,KAAK,GAAI,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC;AACjG,CAAC,CAAC;AAEF,MAAM,YAAY,GAAG,SAAS,YAAY,CACxC,MAA2B,EAC3B,SAAiB;IAEjB,IAAI,MAAM,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;QAC5B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAI,MAAM,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;QAC3B,OAAO,MAAM,CAAC,KAAK,CAAC;IACtB,CAAC;IAED,OAAO,CACL,cAAK,WAAW,EAAE,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,YACjD,eAAM,EAAE,EAAE,SAAS,YACjB,2BAAS,MAAM,CAAC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BAAiB,aAEvC,YAAY,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,CAChC,eAAM,OAAO,EAAE,YAAY,CAAC,KAAK,EAAE,EAAE,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,GAAI,CAChF,CAAC,CAAC,CAAC,CACF,cAAK,aAAa,EAAC,KAAK,EAAC,KAAK,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,YAC5C,YAAY,CAAC,KAAK,GACf,CACP,EACA,OAAO,IAAI,KAAC,WAAW,IAAC,OAAO,EAAE,OAAO,GAAI,IACzC,CACP,EAEA,YAAY,CAAC,aAAa,EAAE,KAAK,CAAC,IAAI,CAAC,EAEvC,QAAQ,EAER,aAAa,CAAC,IAAI,KAAK,OAAO,IAAI,CACjC,cAAK,MAAM,EAAE,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE,YAAY,EAAE,CAAC,YAC5C,aAAa,CAAC,KAAK,GAChB,CACP,EAED,eACE,aAAa,EAAC,KAAK,EACnB,MAAM,EAAE,CAAC,EACT,WAAW,EAAE,CAAC,EACd,YAAY,EAAE,CAAC,EACf,eAAe,EAAE,KAAK,CAAC,iBAAiB,aAExC,cAAK,aAAa,EAAC,KAAK,EAAC,KAAK,EAAE,EAAE,QAAQ,EAAE,CAAC,EAAE,YAC5C,mBAAmB,CAAC,YAAY,EAAE,KAAK,CAAC,SAAS,CAAC,GAC/C,EACL,mBAAmB,CAAC,aAAa,EAAE,KAAK,CAAC,SAAS,CAAC,IAChD,IACF,CACP,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { Renderable } from "@opentui/core";
|
|
2
|
+
import type { RefObject } from "react";
|
|
3
|
+
export type PanelInsetValue = number | "auto" | `${number}%`;
|
|
4
|
+
export interface PanelInset {
|
|
5
|
+
left?: PanelInsetValue;
|
|
6
|
+
right?: PanelInsetValue;
|
|
7
|
+
top?: PanelInsetValue;
|
|
8
|
+
bottom?: PanelInsetValue;
|
|
9
|
+
}
|
|
10
|
+
export interface ResolvedPanelInset {
|
|
11
|
+
left: PanelInsetValue;
|
|
12
|
+
right: PanelInsetValue;
|
|
13
|
+
top: PanelInsetValue;
|
|
14
|
+
bottom: PanelInsetValue;
|
|
15
|
+
}
|
|
16
|
+
export interface PanelContainerSize {
|
|
17
|
+
width: number;
|
|
18
|
+
height: number;
|
|
19
|
+
}
|
|
20
|
+
export declare const DEFAULT_PANEL_INSET = "20%";
|
|
21
|
+
/**
|
|
22
|
+
* Resolve percentage insets to whole terminal cells.
|
|
23
|
+
*
|
|
24
|
+
* Percent insets give the panel fractional geometry. OpenTUI 0.6 rounds each
|
|
25
|
+
* child's position inside that fractional box on its own, so the last rows can
|
|
26
|
+
* land on the bottom border and editors can paint below it. Whole-cell insets
|
|
27
|
+
* keep every row of the panel on the grid. Without a container size the
|
|
28
|
+
* percentages pass through unchanged.
|
|
29
|
+
*/
|
|
30
|
+
export declare const resolvePanelInset: (inset: PanelInset | undefined, container?: PanelContainerSize) => ResolvedPanelInset;
|
|
31
|
+
/**
|
|
32
|
+
* Track the size of the renderable that contains `ref`. The size is read in a
|
|
33
|
+
* layout effect, so a container that already has layout gives whole-cell
|
|
34
|
+
* insets on the first painted frame, and it updates on every container resize.
|
|
35
|
+
*/
|
|
36
|
+
export declare const useContainerSize: (ref: RefObject<Renderable | null>) => PanelContainerSize | undefined;
|
|
37
|
+
//# sourceMappingURL=panel-inset.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"panel-inset.d.ts","sourceRoot":"","sources":["../src/panel-inset.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC;AAE7D,MAAM,WAAW,UAAU;IACzB,IAAI,CAAC,EAAE,eAAe,CAAC;IACvB,KAAK,CAAC,EAAE,eAAe,CAAC;IACxB,GAAG,CAAC,EAAE,eAAe,CAAC;IACtB,MAAM,CAAC,EAAE,eAAe,CAAC;CAC1B;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,eAAe,CAAC;IACtB,KAAK,EAAE,eAAe,CAAC;IACvB,GAAG,EAAE,eAAe,CAAC;IACrB,MAAM,EAAE,eAAe,CAAC;CACzB;AAED,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,eAAO,MAAM,mBAAmB,QAAQ,CAAC;AAkBzC;;;;;;;;GAQG;AACH,eAAO,MAAM,iBAAiB,UACrB,UAAU,GAAG,SAAS,cACjB,kBAAkB,KAC7B,kBAOF,CAAC;AAMF;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,QACtB,SAAS,CAAC,UAAU,GAAG,IAAI,CAAC,KAChC,kBAAkB,GAAG,SA6BvB,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { useLayoutEffect, useState } from "react";
|
|
2
|
+
export const DEFAULT_PANEL_INSET = "20%";
|
|
3
|
+
const PERCENT_PATTERN = /^(?<percent>-?\d+(?:\.\d+)?)%$/u;
|
|
4
|
+
const resolveEdge = function resolveEdge(value, extent) {
|
|
5
|
+
const edge = value ?? DEFAULT_PANEL_INSET;
|
|
6
|
+
const percent = PERCENT_PATTERN.exec(String(edge))?.groups?.percent;
|
|
7
|
+
if (percent === undefined || extent === undefined) {
|
|
8
|
+
return edge;
|
|
9
|
+
}
|
|
10
|
+
return Math.round((Number(percent) / 100) * extent);
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Resolve percentage insets to whole terminal cells.
|
|
14
|
+
*
|
|
15
|
+
* Percent insets give the panel fractional geometry. OpenTUI 0.6 rounds each
|
|
16
|
+
* child's position inside that fractional box on its own, so the last rows can
|
|
17
|
+
* land on the bottom border and editors can paint below it. Whole-cell insets
|
|
18
|
+
* keep every row of the panel on the grid. Without a container size the
|
|
19
|
+
* percentages pass through unchanged.
|
|
20
|
+
*/
|
|
21
|
+
export const resolvePanelInset = function resolvePanelInset(inset, container) {
|
|
22
|
+
return {
|
|
23
|
+
bottom: resolveEdge(inset?.bottom, container?.height),
|
|
24
|
+
left: resolveEdge(inset?.left, container?.width),
|
|
25
|
+
right: resolveEdge(inset?.right, container?.width),
|
|
26
|
+
top: resolveEdge(inset?.top, container?.height),
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
const readSize = function readSize(node) {
|
|
30
|
+
return node.width > 0 && node.height > 0 ? { height: node.height, width: node.width } : undefined;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* Track the size of the renderable that contains `ref`. The size is read in a
|
|
34
|
+
* layout effect, so a container that already has layout gives whole-cell
|
|
35
|
+
* insets on the first painted frame, and it updates on every container resize.
|
|
36
|
+
*/
|
|
37
|
+
export const useContainerSize = function useContainerSize(ref) {
|
|
38
|
+
const [size, setSize] = useState();
|
|
39
|
+
useLayoutEffect(() => {
|
|
40
|
+
const parent = ref.current?.parent;
|
|
41
|
+
if (!parent) {
|
|
42
|
+
return () => {
|
|
43
|
+
// Without a parent there is no resize listener to remove.
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
const sync = () => {
|
|
47
|
+
const next = readSize(parent);
|
|
48
|
+
setSize((prev) => prev?.width === next?.width && prev?.height === next?.height ? prev : next);
|
|
49
|
+
};
|
|
50
|
+
sync();
|
|
51
|
+
parent.on("resize", sync);
|
|
52
|
+
return () => {
|
|
53
|
+
parent.off("resize", sync);
|
|
54
|
+
};
|
|
55
|
+
}, [ref]);
|
|
56
|
+
return size;
|
|
57
|
+
};
|
|
58
|
+
//# sourceMappingURL=panel-inset.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"panel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|
"description": "Standard app chrome (title bar, status bar) for Tooee",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"cli",
|
|
@@ -38,23 +38,23 @@
|
|
|
38
38
|
"typecheck": "tsc --noEmit"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@tooee/commands": "0.16.
|
|
42
|
-
"@tooee/overlays": "0.16.
|
|
43
|
-
"@tooee/search": "0.16.
|
|
44
|
-
"@tooee/themes": "0.16.
|
|
45
|
-
"@tooee/toasts": "0.16.
|
|
41
|
+
"@tooee/commands": "0.16.4",
|
|
42
|
+
"@tooee/overlays": "0.16.4",
|
|
43
|
+
"@tooee/search": "0.16.4",
|
|
44
|
+
"@tooee/themes": "0.16.4",
|
|
45
|
+
"@tooee/toasts": "0.16.4"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@opentui/core": "^0.
|
|
49
|
-
"@opentui/react": "^0.
|
|
48
|
+
"@opentui/core": "^0.8.3",
|
|
49
|
+
"@opentui/react": "^0.8.3",
|
|
50
50
|
"@tooee/test-support": "0.7.3",
|
|
51
51
|
"@types/bun": "^1.4.2",
|
|
52
52
|
"@types/react": "^19.3.0",
|
|
53
53
|
"typescript": "^7.0.2"
|
|
54
54
|
},
|
|
55
55
|
"peerDependencies": {
|
|
56
|
-
"@opentui/core": "^0.
|
|
57
|
-
"@opentui/react": "^0.
|
|
56
|
+
"@opentui/core": "^0.8.3",
|
|
57
|
+
"@opentui/react": "^0.8.3",
|
|
58
58
|
"react": "^18.0.0 || ^19.0.0"
|
|
59
59
|
}
|
|
60
60
|
}
|
package/src/overlay-panel.tsx
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
|
-
import type { MouseEvent } from "@opentui/core";
|
|
1
|
+
import type { BoxRenderable, MouseEvent } from "@opentui/core";
|
|
2
2
|
import { useTheme } from "@tooee/themes";
|
|
3
|
+
import { useRef } from "react";
|
|
3
4
|
import type { ReactNode } from "react";
|
|
4
5
|
|
|
5
6
|
import { CloseButton } from "./close-button.js";
|
|
7
|
+
import { resolvePanelInset, useContainerSize } from "./panel-inset.js";
|
|
8
|
+
import type { PanelInset } from "./panel-inset.js";
|
|
6
9
|
import { decodeReactContent } from "./react-content.js";
|
|
7
10
|
import type { DecodedReactContent } from "./react-content.js";
|
|
8
11
|
|
|
9
|
-
export type PanelInsetValue
|
|
10
|
-
|
|
11
|
-
export interface PanelInset {
|
|
12
|
-
left?: PanelInsetValue;
|
|
13
|
-
right?: PanelInsetValue;
|
|
14
|
-
top?: PanelInsetValue;
|
|
15
|
-
bottom?: PanelInsetValue;
|
|
16
|
-
}
|
|
12
|
+
export type { PanelInset, PanelInsetValue } from "./panel-inset.js";
|
|
17
13
|
|
|
18
14
|
export interface OverlayPanelProps {
|
|
19
15
|
/** Title bar content. Primitive text uses the active accent color. */
|
|
@@ -59,7 +55,7 @@ const renderPrompt = function renderPrompt(
|
|
|
59
55
|
}
|
|
60
56
|
|
|
61
57
|
return (
|
|
62
|
-
<box paddingLeft={1} paddingRight={1}>
|
|
58
|
+
<box paddingLeft={1} paddingRight={1} flexShrink={0}>
|
|
63
59
|
<text fg={textColor}>
|
|
64
60
|
<strong>{prompt.value}</strong>
|
|
65
61
|
</text>
|
|
@@ -85,14 +81,17 @@ export const OverlayPanel = function OverlayPanel({
|
|
|
85
81
|
const decodedFooter = decodeReactContent(footer);
|
|
86
82
|
const decodedHints = decodeReactContent(hints);
|
|
87
83
|
const decodedStatus = decodeReactContent(statusRight);
|
|
84
|
+
const panelRef = useRef<BoxRenderable>(null);
|
|
85
|
+
const edges = resolvePanelInset(inset, useContainerSize(panelRef));
|
|
88
86
|
|
|
89
87
|
return (
|
|
90
88
|
<box
|
|
89
|
+
ref={panelRef}
|
|
91
90
|
position="absolute"
|
|
92
|
-
left={
|
|
93
|
-
right={
|
|
94
|
-
top={
|
|
95
|
-
bottom={
|
|
91
|
+
left={edges.left}
|
|
92
|
+
right={edges.right}
|
|
93
|
+
top={edges.top}
|
|
94
|
+
bottom={edges.bottom}
|
|
96
95
|
flexDirection="column"
|
|
97
96
|
backgroundColor={theme.backgroundPanel}
|
|
98
97
|
border
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { Renderable } from "@opentui/core";
|
|
2
|
+
import { useLayoutEffect, useState } from "react";
|
|
3
|
+
import type { RefObject } from "react";
|
|
4
|
+
|
|
5
|
+
export type PanelInsetValue = number | "auto" | `${number}%`;
|
|
6
|
+
|
|
7
|
+
export interface PanelInset {
|
|
8
|
+
left?: PanelInsetValue;
|
|
9
|
+
right?: PanelInsetValue;
|
|
10
|
+
top?: PanelInsetValue;
|
|
11
|
+
bottom?: PanelInsetValue;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface ResolvedPanelInset {
|
|
15
|
+
left: PanelInsetValue;
|
|
16
|
+
right: PanelInsetValue;
|
|
17
|
+
top: PanelInsetValue;
|
|
18
|
+
bottom: PanelInsetValue;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface PanelContainerSize {
|
|
22
|
+
width: number;
|
|
23
|
+
height: number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export const DEFAULT_PANEL_INSET = "20%";
|
|
27
|
+
|
|
28
|
+
const PERCENT_PATTERN = /^(?<percent>-?\d+(?:\.\d+)?)%$/u;
|
|
29
|
+
|
|
30
|
+
const resolveEdge = function resolveEdge(
|
|
31
|
+
value: PanelInsetValue | undefined,
|
|
32
|
+
extent: number | undefined
|
|
33
|
+
): PanelInsetValue {
|
|
34
|
+
const edge = value ?? DEFAULT_PANEL_INSET;
|
|
35
|
+
const percent = PERCENT_PATTERN.exec(String(edge))?.groups?.percent;
|
|
36
|
+
|
|
37
|
+
if (percent === undefined || extent === undefined) {
|
|
38
|
+
return edge;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return Math.round((Number(percent) / 100) * extent);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Resolve percentage insets to whole terminal cells.
|
|
46
|
+
*
|
|
47
|
+
* Percent insets give the panel fractional geometry. OpenTUI 0.6 rounds each
|
|
48
|
+
* child's position inside that fractional box on its own, so the last rows can
|
|
49
|
+
* land on the bottom border and editors can paint below it. Whole-cell insets
|
|
50
|
+
* keep every row of the panel on the grid. Without a container size the
|
|
51
|
+
* percentages pass through unchanged.
|
|
52
|
+
*/
|
|
53
|
+
export const resolvePanelInset = function resolvePanelInset(
|
|
54
|
+
inset: PanelInset | undefined,
|
|
55
|
+
container?: PanelContainerSize
|
|
56
|
+
): ResolvedPanelInset {
|
|
57
|
+
return {
|
|
58
|
+
bottom: resolveEdge(inset?.bottom, container?.height),
|
|
59
|
+
left: resolveEdge(inset?.left, container?.width),
|
|
60
|
+
right: resolveEdge(inset?.right, container?.width),
|
|
61
|
+
top: resolveEdge(inset?.top, container?.height),
|
|
62
|
+
};
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const readSize = function readSize(node: Renderable): PanelContainerSize | undefined {
|
|
66
|
+
return node.width > 0 && node.height > 0 ? { height: node.height, width: node.width } : undefined;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Track the size of the renderable that contains `ref`. The size is read in a
|
|
71
|
+
* layout effect, so a container that already has layout gives whole-cell
|
|
72
|
+
* insets on the first painted frame, and it updates on every container resize.
|
|
73
|
+
*/
|
|
74
|
+
export const useContainerSize = function useContainerSize(
|
|
75
|
+
ref: RefObject<Renderable | null>
|
|
76
|
+
): PanelContainerSize | undefined {
|
|
77
|
+
const [size, setSize] = useState<PanelContainerSize>();
|
|
78
|
+
|
|
79
|
+
useLayoutEffect(() => {
|
|
80
|
+
const parent = ref.current?.parent;
|
|
81
|
+
|
|
82
|
+
if (!parent) {
|
|
83
|
+
return () => {
|
|
84
|
+
// Without a parent there is no resize listener to remove.
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const sync = () => {
|
|
89
|
+
const next = readSize(parent);
|
|
90
|
+
|
|
91
|
+
setSize((prev) =>
|
|
92
|
+
prev?.width === next?.width && prev?.height === next?.height ? prev : next
|
|
93
|
+
);
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
sync();
|
|
97
|
+
parent.on("resize", sync);
|
|
98
|
+
|
|
99
|
+
return () => {
|
|
100
|
+
parent.off("resize", sync);
|
|
101
|
+
};
|
|
102
|
+
}, [ref]);
|
|
103
|
+
|
|
104
|
+
return size;
|
|
105
|
+
};
|