@kud/ink-ui 0.8.0 → 0.9.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/dist/index.d.ts +34 -2
- package/dist/index.js +55 -6
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React from 'react';
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
2
|
|
|
3
3
|
type BannerProps = {
|
|
4
4
|
title: string;
|
|
@@ -54,6 +54,38 @@ type LoadingScreenProps = {
|
|
|
54
54
|
};
|
|
55
55
|
declare const LoadingScreen: ({ label }: LoadingScreenProps) => React.JSX.Element;
|
|
56
56
|
|
|
57
|
+
type ScreenProps = {
|
|
58
|
+
children: ReactNode;
|
|
59
|
+
/**
|
|
60
|
+
* Enter the terminal's alternate buffer so the app owns the whole screen and
|
|
61
|
+
* the previous scrollback is restored on exit. Defaults to true. Set false to
|
|
62
|
+
* render full-height inline instead.
|
|
63
|
+
*/
|
|
64
|
+
altScreen?: boolean;
|
|
65
|
+
};
|
|
66
|
+
declare const Screen: ({ children, altScreen }: ScreenProps) => React.JSX.Element;
|
|
67
|
+
|
|
68
|
+
type PanelProps = {
|
|
69
|
+
/** Optional title shown in the panel's header row. */
|
|
70
|
+
title?: string;
|
|
71
|
+
/** Accent colour for the border + title when focused. Defaults to the info token. */
|
|
72
|
+
color?: string;
|
|
73
|
+
/** When true the border brightens to `color` and the title gains a ● marker. */
|
|
74
|
+
focused?: boolean;
|
|
75
|
+
width?: number;
|
|
76
|
+
height?: number;
|
|
77
|
+
flexGrow?: number;
|
|
78
|
+
children: ReactNode;
|
|
79
|
+
};
|
|
80
|
+
declare const Panel: ({ title, color, focused, width, height, flexGrow, children, }: PanelProps) => React.JSX.Element;
|
|
81
|
+
|
|
82
|
+
type ColumnsProps = {
|
|
83
|
+
/** Horizontal gap between columns (character cells). Defaults to 1. */
|
|
84
|
+
gap?: number;
|
|
85
|
+
children: ReactNode;
|
|
86
|
+
};
|
|
87
|
+
declare const Columns: ({ gap, children }: ColumnsProps) => React.JSX.Element;
|
|
88
|
+
|
|
57
89
|
type SelectableRowProps = {
|
|
58
90
|
active?: boolean;
|
|
59
91
|
marker?: string;
|
|
@@ -248,4 +280,4 @@ declare const spacing: {
|
|
|
248
280
|
};
|
|
249
281
|
type Spacing = (typeof spacing)[keyof typeof spacing];
|
|
250
282
|
|
|
251
|
-
export { Alert, Badge, type BadgeVariant, Banner, type Color, type Column, ConfirmInput, EmailInput, FooterHints, Header, type Hint, type IconMode, KeyValue, LoadingScreen, MultiSelect, type NotifyOptions, OrderedList, PasswordInput, ProgressBar, ScrollView, Select, type SelectOption, SelectableRow, type Spacing, type Span, Spinner, StatusMessage, type StatusVariant, type StyledLine, Switch, type SwitchValue, type TabItem, Table, Tabs, TextInput, Toast, Toggle, UnorderedList, colors, getIconMode, notify, setIconMode, spacing };
|
|
283
|
+
export { Alert, Badge, type BadgeVariant, Banner, type Color, type Column, Columns, ConfirmInput, EmailInput, FooterHints, Header, type Hint, type IconMode, KeyValue, LoadingScreen, MultiSelect, type NotifyOptions, OrderedList, Panel, PasswordInput, ProgressBar, Screen, ScrollView, Select, type SelectOption, SelectableRow, type Spacing, type Span, Spinner, StatusMessage, type StatusVariant, type StyledLine, Switch, type SwitchValue, type TabItem, Table, Tabs, TextInput, Toast, Toggle, UnorderedList, colors, getIconMode, notify, setIconMode, spacing };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Box, Text, useInput, measureElement } from 'ink';
|
|
1
|
+
import { Box, Text, useStdout, useInput, measureElement } from 'ink';
|
|
2
2
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
|
-
import
|
|
3
|
+
import React9, { createContext, useContext, useState, useEffect, useRef, useLayoutEffect } from 'react';
|
|
4
4
|
import cliSpinners from 'cli-spinners';
|
|
5
5
|
import { glyphs } from '@kud/glyphs';
|
|
6
6
|
import { spawn } from 'child_process';
|
|
@@ -73,6 +73,55 @@ var KeyValue = ({ label, value, labelWidth = 12 }) => /* @__PURE__ */ jsxs(Box,
|
|
|
73
73
|
isTextValue(value) ? /* @__PURE__ */ jsx(Text, { children: value }) : value
|
|
74
74
|
] });
|
|
75
75
|
var LoadingScreen = ({ label }) => /* @__PURE__ */ jsx(Box, { padding: 1, children: /* @__PURE__ */ jsx(Spinner, { label }) });
|
|
76
|
+
var ENTER_ALT = "\x1B[?1049h";
|
|
77
|
+
var LEAVE_ALT = "\x1B[?1049l";
|
|
78
|
+
var Screen = ({ children, altScreen = true }) => {
|
|
79
|
+
const { stdout } = useStdout();
|
|
80
|
+
const [size, setSize] = useState({
|
|
81
|
+
columns: stdout.columns || 80,
|
|
82
|
+
rows: stdout.rows || 24
|
|
83
|
+
});
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
const restore = () => {
|
|
86
|
+
if (altScreen) stdout.write(LEAVE_ALT);
|
|
87
|
+
};
|
|
88
|
+
if (altScreen) stdout.write(ENTER_ALT);
|
|
89
|
+
const onResize = () => setSize({ columns: stdout.columns || 80, rows: stdout.rows || 24 });
|
|
90
|
+
stdout.on("resize", onResize);
|
|
91
|
+
process.on("exit", restore);
|
|
92
|
+
return () => {
|
|
93
|
+
stdout.off("resize", onResize);
|
|
94
|
+
process.off("exit", restore);
|
|
95
|
+
restore();
|
|
96
|
+
};
|
|
97
|
+
}, [stdout, altScreen]);
|
|
98
|
+
return /* @__PURE__ */ jsx(Box, { width: size.columns, height: size.rows, flexDirection: "column", children });
|
|
99
|
+
};
|
|
100
|
+
var Panel = ({
|
|
101
|
+
title,
|
|
102
|
+
color = colors.info,
|
|
103
|
+
focused = false,
|
|
104
|
+
width,
|
|
105
|
+
height,
|
|
106
|
+
flexGrow,
|
|
107
|
+
children
|
|
108
|
+
}) => /* @__PURE__ */ jsxs(
|
|
109
|
+
Box,
|
|
110
|
+
{
|
|
111
|
+
flexDirection: "column",
|
|
112
|
+
width,
|
|
113
|
+
height,
|
|
114
|
+
flexGrow,
|
|
115
|
+
borderStyle: "round",
|
|
116
|
+
borderColor: focused ? color : colors.muted,
|
|
117
|
+
overflow: "hidden",
|
|
118
|
+
children: [
|
|
119
|
+
title && /* @__PURE__ */ jsx(Text, { color: focused ? color : colors.muted, bold: true, children: focused ? `${title} \u25CF` : title }),
|
|
120
|
+
children
|
|
121
|
+
]
|
|
122
|
+
}
|
|
123
|
+
);
|
|
124
|
+
var Columns = ({ gap = 1, children }) => /* @__PURE__ */ jsx(Box, { flexDirection: "row", gap, flexGrow: 1, children });
|
|
76
125
|
var isTextValue2 = (value) => typeof value === "string" || typeof value === "number";
|
|
77
126
|
var SelectableRow = ({
|
|
78
127
|
active = false,
|
|
@@ -423,10 +472,10 @@ var OrderedListItem = ({ children, _index = 1 }) => /* @__PURE__ */ jsxs(Box, {
|
|
|
423
472
|
] });
|
|
424
473
|
var OrderedListRoot = ({ children }) => {
|
|
425
474
|
let n = 0;
|
|
426
|
-
const numbered =
|
|
427
|
-
if (
|
|
475
|
+
const numbered = React9.Children.map(children, (child) => {
|
|
476
|
+
if (React9.isValidElement(child) && child.type === OrderedListItem) {
|
|
428
477
|
n += 1;
|
|
429
|
-
return
|
|
478
|
+
return React9.cloneElement(child, {
|
|
430
479
|
_index: n
|
|
431
480
|
});
|
|
432
481
|
}
|
|
@@ -667,4 +716,4 @@ var notify = (message, options = {}) => {
|
|
|
667
716
|
child.unref();
|
|
668
717
|
};
|
|
669
718
|
|
|
670
|
-
export { Alert, Badge, Banner, ConfirmInput, EmailInput, FooterHints, Header, KeyValue, LoadingScreen, MultiSelect, OrderedList, PasswordInput, ProgressBar, ScrollView, Select, SelectableRow, Spinner, StatusMessage, Switch, Table, Tabs, TextInput, Toast, Toggle, UnorderedList, colors, getIconMode, notify, setIconMode, spacing };
|
|
719
|
+
export { Alert, Badge, Banner, Columns, ConfirmInput, EmailInput, FooterHints, Header, KeyValue, LoadingScreen, MultiSelect, OrderedList, Panel, PasswordInput, ProgressBar, Screen, ScrollView, Select, SelectableRow, Spinner, StatusMessage, Switch, Table, Tabs, TextInput, Toast, Toggle, UnorderedList, colors, getIconMode, notify, setIconMode, spacing };
|