@tooee/layout 0.12.0 → 0.14.0
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 +46 -0
- package/dist/app-layout.d.ts +3 -1
- package/dist/app-layout.d.ts.map +1 -1
- package/dist/app-layout.js +1 -3
- package/dist/app-layout.js.map +1 -1
- package/dist/app-layout.public-contract.typecheck.d.ts.map +1 -1
- package/dist/cell-text.d.ts +11 -0
- package/dist/cell-text.d.ts.map +1 -0
- package/dist/cell-text.js +55 -0
- package/dist/cell-text.js.map +1 -0
- package/dist/close-button.d.ts.map +1 -1
- package/dist/close-button.js.map +1 -1
- package/dist/fit-status-bar.d.ts +78 -0
- package/dist/fit-status-bar.d.ts.map +1 -0
- package/dist/fit-status-bar.js +182 -0
- package/dist/fit-status-bar.js.map +1 -0
- package/dist/fit-title-bar.d.ts +13 -0
- package/dist/fit-title-bar.d.ts.map +1 -0
- package/dist/fit-title-bar.js +20 -0
- package/dist/fit-title-bar.js.map +1 -0
- package/dist/index.d.ts +7 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/overlay-panel.d.ts.map +1 -1
- package/dist/overlay-panel.js.map +1 -1
- package/dist/react-content.d.ts.map +1 -1
- package/dist/react-content.js.map +1 -1
- package/dist/status-bar.d.ts +13 -8
- package/dist/status-bar.d.ts.map +1 -1
- package/dist/status-bar.js +30 -5
- package/dist/status-bar.js.map +1 -1
- package/dist/title-bar.d.ts +7 -1
- package/dist/title-bar.d.ts.map +1 -1
- package/dist/title-bar.js +17 -4
- package/dist/title-bar.js.map +1 -1
- package/package.json +6 -6
- package/src/app-layout.public-contract.typecheck.ts +6 -0
- package/src/app-layout.tsx +9 -5
- package/src/cell-text.ts +79 -0
- package/src/close-button.tsx +1 -0
- package/src/fit-status-bar.ts +307 -0
- package/src/fit-title-bar.ts +36 -0
- package/src/index.ts +34 -1
- package/src/overlay-panel.tsx +3 -0
- package/src/react-content.ts +2 -0
- package/src/status-bar.tsx +72 -15
- package/src/title-bar.tsx +28 -6
package/src/index.ts
CHANGED
|
@@ -1,10 +1,43 @@
|
|
|
1
1
|
export { AppLayout } from "./app-layout.js";
|
|
2
|
+
|
|
2
3
|
export type { AppLayoutProps, AppLayoutScroll } from "./app-layout.js";
|
|
4
|
+
|
|
3
5
|
export { CloseButton } from "./close-button.js";
|
|
6
|
+
|
|
4
7
|
export { OverlayPanel } from "./overlay-panel.js";
|
|
8
|
+
|
|
5
9
|
export type { OverlayPanelProps, PanelInset, PanelInsetValue } from "./overlay-panel.js";
|
|
10
|
+
|
|
6
11
|
export { decodeReactContent } from "./react-content.js";
|
|
12
|
+
|
|
7
13
|
export type { DecodedReactContent } from "./react-content.js";
|
|
14
|
+
|
|
15
|
+
export { truncateCells } from "./cell-text.js";
|
|
16
|
+
|
|
17
|
+
export type { TruncateMode } from "./cell-text.js";
|
|
18
|
+
|
|
19
|
+
export {
|
|
20
|
+
fitStatusBar,
|
|
21
|
+
STATUS_BAR_GAP,
|
|
22
|
+
STATUS_BAR_HIDDEN_MARKER,
|
|
23
|
+
StatusPriority,
|
|
24
|
+
} from "./fit-status-bar.js";
|
|
25
|
+
|
|
26
|
+
export type {
|
|
27
|
+
FitStatusBarOptions,
|
|
28
|
+
PlacedStatusItem,
|
|
29
|
+
StatusBarAlign,
|
|
30
|
+
StatusBarItem,
|
|
31
|
+
StatusBarLayout,
|
|
32
|
+
StatusBarTruncate,
|
|
33
|
+
} from "./fit-status-bar.js";
|
|
34
|
+
|
|
35
|
+
export { fitTitleBar } from "./fit-title-bar.js";
|
|
36
|
+
|
|
37
|
+
export type { TitleBarText } from "./fit-title-bar.js";
|
|
38
|
+
|
|
8
39
|
export { StatusBar } from "./status-bar.js";
|
|
9
|
-
|
|
40
|
+
|
|
41
|
+
export type { StatusBarProps } from "./status-bar.js";
|
|
42
|
+
|
|
10
43
|
export { TitleBar } from "./title-bar.js";
|
package/src/overlay-panel.tsx
CHANGED
|
@@ -42,6 +42,7 @@ const renderThemedContent = function renderThemedContent(
|
|
|
42
42
|
if (content.kind === "empty") {
|
|
43
43
|
return null;
|
|
44
44
|
}
|
|
45
|
+
|
|
45
46
|
return content.kind === "string" ? <text content={content.value} fg={color} /> : content.value;
|
|
46
47
|
};
|
|
47
48
|
|
|
@@ -52,9 +53,11 @@ const renderPrompt = function renderPrompt(
|
|
|
52
53
|
if (prompt.kind === "empty") {
|
|
53
54
|
return null;
|
|
54
55
|
}
|
|
56
|
+
|
|
55
57
|
if (prompt.kind === "node") {
|
|
56
58
|
return prompt.value;
|
|
57
59
|
}
|
|
60
|
+
|
|
58
61
|
return (
|
|
59
62
|
<box paddingLeft={1} paddingRight={1}>
|
|
60
63
|
<text fg={textColor}>
|
package/src/react-content.ts
CHANGED
|
@@ -23,9 +23,11 @@ export const decodeReactContent = function decodeReactContent(
|
|
|
23
23
|
if (content === null || content === undefined) {
|
|
24
24
|
return { kind: "empty" };
|
|
25
25
|
}
|
|
26
|
+
|
|
26
27
|
// oxlint-disable-next-line anti-slop/no-runtime-typeof -- ReactNode boundary distinguishes themed primitive text from nodes rendered by React
|
|
27
28
|
if (typeof content === "string") {
|
|
28
29
|
return { kind: "string", value: content };
|
|
29
30
|
}
|
|
31
|
+
|
|
30
32
|
return { kind: "node", value: content };
|
|
31
33
|
};
|
package/src/status-bar.tsx
CHANGED
|
@@ -1,35 +1,92 @@
|
|
|
1
|
+
import { useTerminalDimensions } from "@opentui/react";
|
|
1
2
|
import { useTheme } from "@tooee/themes";
|
|
2
3
|
import type { ReactNode } from "react";
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
import { fitStatusBar, STATUS_BAR_GAP } from "./fit-status-bar.js";
|
|
6
|
+
import type { PlacedStatusItem, StatusBarItem } from "./fit-status-bar.js";
|
|
7
|
+
|
|
8
|
+
export type { StatusBarItem } from "./fit-status-bar.js";
|
|
9
|
+
|
|
10
|
+
const PADDING_X = 1;
|
|
11
|
+
|
|
12
|
+
export interface StatusBarProps {
|
|
13
|
+
items: readonly StatusBarItem[];
|
|
14
|
+
/** Bar width in cells. Defaults to the terminal width. */
|
|
15
|
+
width?: number;
|
|
16
|
+
/** Glyph that shows when items hide. `false` turns it off. Default `"⋯"`. */
|
|
17
|
+
hiddenMarker?: string | false;
|
|
6
18
|
}
|
|
7
19
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
20
|
+
interface StatusTextProps {
|
|
21
|
+
item: PlacedStatusItem;
|
|
22
|
+
first: boolean;
|
|
11
23
|
}
|
|
12
24
|
|
|
13
|
-
|
|
25
|
+
const StatusText = function StatusText({ item, first }: StatusTextProps): ReactNode {
|
|
14
26
|
const { theme } = useTheme();
|
|
27
|
+
const gap = item.label !== "" && item.value !== "" ? " " : "";
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<text wrapMode="none" style={{ flexShrink: 0, marginLeft: first ? 0 : STATUS_BAR_GAP }}>
|
|
31
|
+
<span fg={theme.textMuted}>{item.label}</span>
|
|
32
|
+
{gap}
|
|
33
|
+
<span fg={theme.text}>{item.value}</span>
|
|
34
|
+
</text>
|
|
35
|
+
);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* One-row status bar. Items that do not fit use their compact form, shorten,
|
|
40
|
+
* or hide, lowest priority first. The bar never wraps.
|
|
41
|
+
*/
|
|
42
|
+
export const StatusBar = function StatusBar({
|
|
43
|
+
items,
|
|
44
|
+
width,
|
|
45
|
+
hiddenMarker,
|
|
46
|
+
}: StatusBarProps): ReactNode {
|
|
47
|
+
const { theme } = useTheme();
|
|
48
|
+
const terminal = useTerminalDimensions();
|
|
49
|
+
const inner = Math.max(0, (width ?? terminal.width) - PADDING_X * 2);
|
|
50
|
+
const layout = fitStatusBar(items, inner, { hiddenMarker });
|
|
51
|
+
|
|
15
52
|
return (
|
|
16
53
|
<box
|
|
17
54
|
style={{
|
|
18
55
|
backgroundColor: theme.backgroundPanel,
|
|
19
56
|
flexDirection: "row",
|
|
20
57
|
flexShrink: 0,
|
|
58
|
+
height: 1,
|
|
59
|
+
overflow: "hidden",
|
|
21
60
|
padding: 0,
|
|
22
|
-
paddingLeft:
|
|
23
|
-
paddingRight:
|
|
61
|
+
paddingLeft: PADDING_X,
|
|
62
|
+
paddingRight: PADDING_X,
|
|
63
|
+
width,
|
|
24
64
|
}}
|
|
25
65
|
>
|
|
26
|
-
{
|
|
27
|
-
<
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
66
|
+
{layout.start.map((item, index): ReactNode => (
|
|
67
|
+
<StatusText key={item.key} item={item} first={index === 0} />
|
|
68
|
+
))}
|
|
69
|
+
{layout.marker !== null && (
|
|
70
|
+
<text
|
|
71
|
+
wrapMode="none"
|
|
72
|
+
content={layout.marker}
|
|
73
|
+
style={{
|
|
74
|
+
fg: theme.textMuted,
|
|
75
|
+
flexShrink: 0,
|
|
76
|
+
marginLeft: layout.start.length > 0 ? STATUS_BAR_GAP : 0,
|
|
77
|
+
}}
|
|
78
|
+
/>
|
|
79
|
+
)}
|
|
80
|
+
{layout.end.length > 0 && (
|
|
81
|
+
<box
|
|
82
|
+
style={{
|
|
83
|
+
flexGrow: 1,
|
|
84
|
+
minWidth: layout.start.length > 0 || layout.marker !== null ? STATUS_BAR_GAP : 0,
|
|
85
|
+
}}
|
|
86
|
+
/>
|
|
87
|
+
)}
|
|
88
|
+
{layout.end.map((item, index): ReactNode => (
|
|
89
|
+
<StatusText key={item.key} item={item} first={index === 0} />
|
|
33
90
|
))}
|
|
34
91
|
</box>
|
|
35
92
|
);
|
package/src/title-bar.tsx
CHANGED
|
@@ -1,27 +1,49 @@
|
|
|
1
|
+
import { useTerminalDimensions } from "@opentui/react";
|
|
1
2
|
import { useTheme } from "@tooee/themes";
|
|
2
3
|
import type { ReactNode } from "react";
|
|
3
4
|
|
|
5
|
+
import { fitTitleBar, TITLE_BAR_SEPARATOR } from "./fit-title-bar.js";
|
|
6
|
+
|
|
7
|
+
const PADDING_X = 1;
|
|
8
|
+
|
|
4
9
|
interface TitleBarProps {
|
|
5
10
|
title: string;
|
|
6
11
|
subtitle?: string;
|
|
12
|
+
/** Bar width in cells. Defaults to the terminal width. */
|
|
13
|
+
width?: number;
|
|
7
14
|
}
|
|
8
15
|
|
|
9
|
-
|
|
16
|
+
/**
|
|
17
|
+
* One-row title bar. When the bar is narrow, the subtitle shortens, then
|
|
18
|
+
* hides, then the title shortens. The bar never wraps.
|
|
19
|
+
*/
|
|
20
|
+
export const TitleBar = function TitleBar({ title, subtitle, width }: TitleBarProps): ReactNode {
|
|
10
21
|
const { theme } = useTheme();
|
|
22
|
+
const terminal = useTerminalDimensions();
|
|
23
|
+
const inner = Math.max(0, (width ?? terminal.width) - PADDING_X * 2);
|
|
24
|
+
const fitted = fitTitleBar(title, subtitle, inner);
|
|
25
|
+
|
|
11
26
|
return (
|
|
12
27
|
<box
|
|
13
28
|
style={{
|
|
14
29
|
backgroundColor: theme.backgroundPanel,
|
|
15
30
|
flexDirection: "row",
|
|
16
31
|
flexShrink: 0,
|
|
32
|
+
height: 1,
|
|
33
|
+
overflow: "hidden",
|
|
17
34
|
padding: 0,
|
|
18
|
-
paddingLeft:
|
|
19
|
-
paddingRight:
|
|
35
|
+
paddingLeft: PADDING_X,
|
|
36
|
+
paddingRight: PADDING_X,
|
|
37
|
+
width,
|
|
20
38
|
}}
|
|
21
39
|
>
|
|
22
|
-
<text content={title} style={{ fg: theme.primary }} />
|
|
23
|
-
{
|
|
24
|
-
<text
|
|
40
|
+
<text wrapMode="none" content={fitted.title} style={{ fg: theme.primary, flexShrink: 0 }} />
|
|
41
|
+
{fitted.subtitle !== "" && (
|
|
42
|
+
<text
|
|
43
|
+
wrapMode="none"
|
|
44
|
+
content={`${TITLE_BAR_SEPARATOR}${fitted.subtitle}`}
|
|
45
|
+
style={{ fg: theme.textMuted, flexShrink: 0 }}
|
|
46
|
+
/>
|
|
25
47
|
)}
|
|
26
48
|
</box>
|
|
27
49
|
);
|