@mdxui/terminal 2.0.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 +571 -0
- package/dist/ansi-css-Sk5mWtdK.d.ts +119 -0
- package/dist/ansi-css-V6JIHGsM.d.ts +119 -0
- package/dist/ansi-css-_3eSEU9d.d.ts +119 -0
- package/dist/chunk-3EFDH7PK.js +5235 -0
- package/dist/chunk-3RG5ZIWI.js +10 -0
- package/dist/chunk-3X5IR6WE.js +884 -0
- package/dist/chunk-4FV5ZDCE.js +5236 -0
- package/dist/chunk-4OVMSF2J.js +243 -0
- package/dist/chunk-63FEETIS.js +4048 -0
- package/dist/chunk-B43KP7XJ.js +884 -0
- package/dist/chunk-BMTJXWUV.js +655 -0
- package/dist/chunk-C3SVH4N7.js +882 -0
- package/dist/chunk-EVWR7Y47.js +874 -0
- package/dist/chunk-F6A5VWUC.js +1285 -0
- package/dist/chunk-FD7KW7GE.js +882 -0
- package/dist/chunk-GBQ6UD6I.js +655 -0
- package/dist/chunk-GMDD3M6U.js +5227 -0
- package/dist/chunk-JBHRXOXM.js +1058 -0
- package/dist/chunk-JFOO3EYO.js +1182 -0
- package/dist/chunk-JQ5H3WXL.js +1291 -0
- package/dist/chunk-JQD5NASE.js +234 -0
- package/dist/chunk-KRHJP5R7.js +592 -0
- package/dist/chunk-KWF6WVJE.js +962 -0
- package/dist/chunk-LHYQVN3H.js +1038 -0
- package/dist/chunk-M3TLQLGC.js +1032 -0
- package/dist/chunk-MVW4Q5OP.js +240 -0
- package/dist/chunk-NXCZSWLU.js +1294 -0
- package/dist/chunk-O25TNRO6.js +607 -0
- package/dist/chunk-PNECDA2I.js +884 -0
- package/dist/chunk-QIHWRLJR.js +962 -0
- package/dist/chunk-QW5YMQ7K.js +882 -0
- package/dist/chunk-R5U7XKVJ.js +16 -0
- package/dist/chunk-RP2MVQLR.js +962 -0
- package/dist/chunk-TP6RXGXA.js +1087 -0
- package/dist/chunk-TQQSTITZ.js +655 -0
- package/dist/chunk-X24GWXQV.js +1281 -0
- package/dist/components/index.d.ts +802 -0
- package/dist/components/index.js +149 -0
- package/dist/data/index.d.ts +2554 -0
- package/dist/data/index.js +51 -0
- package/dist/forms/index.d.ts +1596 -0
- package/dist/forms/index.js +464 -0
- package/dist/index-CQRFZntR.d.ts +867 -0
- package/dist/index.d.ts +579 -0
- package/dist/index.js +786 -0
- package/dist/interactive-D0JkWosD.d.ts +217 -0
- package/dist/keyboard/index.d.ts +2 -0
- package/dist/keyboard/index.js +43 -0
- package/dist/renderers/index.d.ts +546 -0
- package/dist/renderers/index.js +2157 -0
- package/dist/storybook/index.d.ts +396 -0
- package/dist/storybook/index.js +641 -0
- package/dist/theme/index.d.ts +1339 -0
- package/dist/theme/index.js +123 -0
- package/dist/types-Bxu5PAgA.d.ts +710 -0
- package/dist/types-CIlop5Ji.d.ts +701 -0
- package/dist/types-Ca8p_p5X.d.ts +710 -0
- package/package.json +90 -0
- package/src/__tests__/components/data/card.test.ts +458 -0
- package/src/__tests__/components/data/list.test.ts +473 -0
- package/src/__tests__/components/data/metrics.test.ts +541 -0
- package/src/__tests__/components/data/table.test.ts +448 -0
- package/src/__tests__/components/input/field.test.ts +555 -0
- package/src/__tests__/components/input/form.test.ts +870 -0
- package/src/__tests__/components/input/search.test.ts +1238 -0
- package/src/__tests__/components/input/select.test.ts +658 -0
- package/src/__tests__/components/navigation/breadcrumb.test.ts +923 -0
- package/src/__tests__/components/navigation/command-palette.test.ts +1095 -0
- package/src/__tests__/components/navigation/sidebar.test.ts +1018 -0
- package/src/__tests__/components/navigation/tabs.test.ts +995 -0
- package/src/__tests__/components.test.tsx +1197 -0
- package/src/__tests__/core/compiler.test.ts +986 -0
- package/src/__tests__/core/parser.test.ts +785 -0
- package/src/__tests__/core/tier-switcher.test.ts +1103 -0
- package/src/__tests__/core/types.test.ts +1398 -0
- package/src/__tests__/data/collections.test.ts +1337 -0
- package/src/__tests__/data/db.test.ts +1265 -0
- package/src/__tests__/data/reactive.test.ts +1010 -0
- package/src/__tests__/data/sync.test.ts +1614 -0
- package/src/__tests__/errors.test.ts +660 -0
- package/src/__tests__/forms/integration.test.ts +444 -0
- package/src/__tests__/integration.test.ts +905 -0
- package/src/__tests__/keyboard.test.ts +1791 -0
- package/src/__tests__/renderer.test.ts +489 -0
- package/src/__tests__/renderers/ansi-css.test.ts +948 -0
- package/src/__tests__/renderers/ansi.test.ts +1366 -0
- package/src/__tests__/renderers/ascii.test.ts +1360 -0
- package/src/__tests__/renderers/interactive.test.ts +2353 -0
- package/src/__tests__/renderers/markdown.test.ts +1483 -0
- package/src/__tests__/renderers/text.test.ts +1369 -0
- package/src/__tests__/renderers/unicode.test.ts +1307 -0
- package/src/__tests__/theme.test.ts +639 -0
- package/src/__tests__/utils/assertions.ts +685 -0
- package/src/__tests__/utils/index.ts +115 -0
- package/src/__tests__/utils/test-renderer.ts +381 -0
- package/src/__tests__/utils/utils.test.ts +560 -0
- package/src/components/containers/card.ts +56 -0
- package/src/components/containers/dialog.ts +53 -0
- package/src/components/containers/index.ts +9 -0
- package/src/components/containers/panel.ts +59 -0
- package/src/components/feedback/badge.ts +40 -0
- package/src/components/feedback/index.ts +8 -0
- package/src/components/feedback/spinner.ts +23 -0
- package/src/components/helpers.ts +81 -0
- package/src/components/index.ts +153 -0
- package/src/components/layout/breadcrumb.ts +31 -0
- package/src/components/layout/index.ts +10 -0
- package/src/components/layout/list.ts +29 -0
- package/src/components/layout/sidebar.ts +79 -0
- package/src/components/layout/table.ts +62 -0
- package/src/components/primitives/box.ts +95 -0
- package/src/components/primitives/button.ts +54 -0
- package/src/components/primitives/index.ts +11 -0
- package/src/components/primitives/input.ts +88 -0
- package/src/components/primitives/select.ts +97 -0
- package/src/components/primitives/text.ts +60 -0
- package/src/components/render.ts +155 -0
- package/src/components/templates/app.ts +43 -0
- package/src/components/templates/index.ts +8 -0
- package/src/components/templates/site.ts +54 -0
- package/src/components/types.ts +777 -0
- package/src/core/compiler.ts +718 -0
- package/src/core/parser.ts +127 -0
- package/src/core/tier-switcher.ts +607 -0
- package/src/core/types.ts +672 -0
- package/src/data/collection.ts +316 -0
- package/src/data/collections.ts +50 -0
- package/src/data/context.tsx +174 -0
- package/src/data/db.ts +127 -0
- package/src/data/hooks.ts +532 -0
- package/src/data/index.ts +138 -0
- package/src/data/reactive.ts +1225 -0
- package/src/data/saas-collections.ts +375 -0
- package/src/data/sync.ts +1213 -0
- package/src/data/types.ts +660 -0
- package/src/forms/converters.ts +512 -0
- package/src/forms/index.ts +133 -0
- package/src/forms/schemas.ts +403 -0
- package/src/forms/types.ts +476 -0
- package/src/index.ts +542 -0
- package/src/keyboard/focus.ts +748 -0
- package/src/keyboard/index.ts +96 -0
- package/src/keyboard/integration.ts +371 -0
- package/src/keyboard/manager.ts +377 -0
- package/src/keyboard/presets.ts +90 -0
- package/src/renderers/ansi-css.ts +576 -0
- package/src/renderers/ansi.ts +802 -0
- package/src/renderers/ascii.ts +680 -0
- package/src/renderers/breadcrumb.ts +480 -0
- package/src/renderers/command-palette.ts +802 -0
- package/src/renderers/components/field.ts +210 -0
- package/src/renderers/components/form.ts +327 -0
- package/src/renderers/components/index.ts +21 -0
- package/src/renderers/components/search.ts +449 -0
- package/src/renderers/components/select.ts +222 -0
- package/src/renderers/index.ts +101 -0
- package/src/renderers/interactive/component-handlers.ts +622 -0
- package/src/renderers/interactive/cursor-manager.ts +147 -0
- package/src/renderers/interactive/focus-manager.ts +279 -0
- package/src/renderers/interactive/index.ts +661 -0
- package/src/renderers/interactive/input-handler.ts +164 -0
- package/src/renderers/interactive/keyboard-handler.ts +212 -0
- package/src/renderers/interactive/mouse-handler.ts +167 -0
- package/src/renderers/interactive/state-manager.ts +109 -0
- package/src/renderers/interactive/types.ts +338 -0
- package/src/renderers/interactive-string.ts +299 -0
- package/src/renderers/interactive.ts +59 -0
- package/src/renderers/markdown.ts +950 -0
- package/src/renderers/sidebar.ts +549 -0
- package/src/renderers/tabs.ts +682 -0
- package/src/renderers/text.ts +791 -0
- package/src/renderers/unicode.ts +917 -0
- package/src/renderers/utils.ts +942 -0
- package/src/router/adapters.ts +383 -0
- package/src/router/types.ts +140 -0
- package/src/router/utils.ts +452 -0
- package/src/schemas.ts +205 -0
- package/src/storybook/index.ts +91 -0
- package/src/storybook/interactive-decorator.tsx +659 -0
- package/src/storybook/keyboard-simulator.ts +501 -0
- package/src/theme/ansi-codes.ts +80 -0
- package/src/theme/box-drawing.ts +132 -0
- package/src/theme/color-convert.ts +254 -0
- package/src/theme/color-support.ts +321 -0
- package/src/theme/index.ts +134 -0
- package/src/theme/strip-ansi.ts +50 -0
- package/src/theme/tailwind-map.ts +469 -0
- package/src/theme/text-styles.ts +206 -0
- package/src/theme/theme-system.ts +568 -0
- package/src/types.ts +103 -0
|
@@ -0,0 +1,592 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ANSI,
|
|
3
|
+
boxChars
|
|
4
|
+
} from "./chunk-JBHRXOXM.js";
|
|
5
|
+
|
|
6
|
+
// src/components/index.ts
|
|
7
|
+
import React, { Children, isValidElement } from "react";
|
|
8
|
+
var colorMap = {
|
|
9
|
+
// Basic colors
|
|
10
|
+
black: "\x1B[30m",
|
|
11
|
+
red: "\x1B[31m",
|
|
12
|
+
green: "\x1B[32m",
|
|
13
|
+
yellow: "\x1B[33m",
|
|
14
|
+
blue: "\x1B[34m",
|
|
15
|
+
magenta: "\x1B[35m",
|
|
16
|
+
cyan: "\x1B[36m",
|
|
17
|
+
white: "\x1B[37m",
|
|
18
|
+
// Semantic colors
|
|
19
|
+
error: "\x1B[31m",
|
|
20
|
+
success: "\x1B[32m",
|
|
21
|
+
warning: "\x1B[33m",
|
|
22
|
+
info: "\x1B[34m",
|
|
23
|
+
primary: "\x1B[36m",
|
|
24
|
+
secondary: "\x1B[34m",
|
|
25
|
+
muted: "\x1B[90m"
|
|
26
|
+
};
|
|
27
|
+
var bgColorMap = {
|
|
28
|
+
black: "\x1B[40m",
|
|
29
|
+
red: "\x1B[41m",
|
|
30
|
+
green: "\x1B[42m",
|
|
31
|
+
yellow: "\x1B[43m",
|
|
32
|
+
blue: "\x1B[44m",
|
|
33
|
+
magenta: "\x1B[45m",
|
|
34
|
+
cyan: "\x1B[46m",
|
|
35
|
+
white: "\x1B[47m"
|
|
36
|
+
};
|
|
37
|
+
function getColorCode(color) {
|
|
38
|
+
return colorMap[color] || colorMap.white;
|
|
39
|
+
}
|
|
40
|
+
function getBgColorCode(color) {
|
|
41
|
+
return bgColorMap[color] || "";
|
|
42
|
+
}
|
|
43
|
+
function extractChildren(children) {
|
|
44
|
+
if (typeof children === "string") return children;
|
|
45
|
+
if (typeof children === "number") return String(children);
|
|
46
|
+
if (Array.isArray(children)) {
|
|
47
|
+
return children.map(extractChildren).join("");
|
|
48
|
+
}
|
|
49
|
+
if (isValidElement(children)) {
|
|
50
|
+
const props = children.props;
|
|
51
|
+
return extractChildren(props.children);
|
|
52
|
+
}
|
|
53
|
+
return "";
|
|
54
|
+
}
|
|
55
|
+
function renderElement(element, context) {
|
|
56
|
+
const props = element.props;
|
|
57
|
+
const type = element.type;
|
|
58
|
+
if (typeof type === "function") {
|
|
59
|
+
const result = type(props);
|
|
60
|
+
return renderElement(result, context);
|
|
61
|
+
}
|
|
62
|
+
switch (type) {
|
|
63
|
+
case "box":
|
|
64
|
+
return renderBox(props, context);
|
|
65
|
+
case "text":
|
|
66
|
+
return renderText(props, context);
|
|
67
|
+
case "table":
|
|
68
|
+
return renderTable(props, context);
|
|
69
|
+
case "input":
|
|
70
|
+
return renderInput(props, context);
|
|
71
|
+
case "select":
|
|
72
|
+
return renderSelect(props, context);
|
|
73
|
+
case "sidebar":
|
|
74
|
+
return renderSidebar(props, context);
|
|
75
|
+
case "sidebar-item":
|
|
76
|
+
return renderSidebarItem(props, context);
|
|
77
|
+
case "breadcrumb":
|
|
78
|
+
return renderBreadcrumb(props, context);
|
|
79
|
+
case "badge":
|
|
80
|
+
return renderBadge(props, context);
|
|
81
|
+
case "dialog":
|
|
82
|
+
return renderDialog(props, context);
|
|
83
|
+
case "spinner":
|
|
84
|
+
return renderSpinner(props, context);
|
|
85
|
+
case "button":
|
|
86
|
+
return renderButton(props, context);
|
|
87
|
+
case "panel":
|
|
88
|
+
return renderPanel(props, context);
|
|
89
|
+
case "list":
|
|
90
|
+
return renderList(props, context);
|
|
91
|
+
case "card":
|
|
92
|
+
return renderCard(props, context);
|
|
93
|
+
default:
|
|
94
|
+
const childText = extractChildren(props.children);
|
|
95
|
+
return childText ? [childText] : [];
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
function renderComponent(element) {
|
|
99
|
+
const context = { width: 80 };
|
|
100
|
+
return renderElement(element, context);
|
|
101
|
+
}
|
|
102
|
+
function renderBox(props, context) {
|
|
103
|
+
const { children, border = "none", padding = 0, width, height, bg } = props;
|
|
104
|
+
const boxWidth = typeof width === "number" ? width : context.width;
|
|
105
|
+
const boxHeight = typeof height === "number" ? height : void 0;
|
|
106
|
+
let childLines = [];
|
|
107
|
+
if (children) {
|
|
108
|
+
if (isValidElement(children)) {
|
|
109
|
+
childLines = renderElement(children, { ...context, width: boxWidth - (border !== "none" ? 2 : 0) - padding * 2, parentWidth: boxWidth });
|
|
110
|
+
} else {
|
|
111
|
+
const text = extractChildren(children);
|
|
112
|
+
if (text) childLines = [text];
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
if (padding > 0) {
|
|
116
|
+
childLines = childLines.map((line) => " ".repeat(padding) + line + " ".repeat(padding));
|
|
117
|
+
}
|
|
118
|
+
const contentWidth = border !== "none" ? boxWidth - 2 : boxWidth;
|
|
119
|
+
if (border === "none") {
|
|
120
|
+
let result = childLines.length > 0 ? childLines : [""];
|
|
121
|
+
if (boxHeight) {
|
|
122
|
+
while (result.length < boxHeight) {
|
|
123
|
+
result.push("");
|
|
124
|
+
}
|
|
125
|
+
result = result.slice(0, boxHeight);
|
|
126
|
+
}
|
|
127
|
+
if (bg) {
|
|
128
|
+
const bgCode = getBgColorCode(bg);
|
|
129
|
+
result = result.map((line) => bgCode + line.padEnd(boxWidth) + ANSI.reset);
|
|
130
|
+
}
|
|
131
|
+
return result;
|
|
132
|
+
}
|
|
133
|
+
const chars = boxChars[border] || boxChars.single;
|
|
134
|
+
const lines = [];
|
|
135
|
+
lines.push(chars.topLeft + chars.horizontal.repeat(contentWidth) + chars.topRight);
|
|
136
|
+
const targetHeight = boxHeight ? boxHeight - 2 : childLines.length;
|
|
137
|
+
for (let i = 0; i < targetHeight; i++) {
|
|
138
|
+
const content = i < childLines.length ? childLines[i] : "";
|
|
139
|
+
const stripped = content.replace(/\x1b\[[\d;]*m/g, "");
|
|
140
|
+
const paddedContent = content + " ".repeat(Math.max(0, contentWidth - stripped.length));
|
|
141
|
+
lines.push(chars.vertical + paddedContent + chars.vertical);
|
|
142
|
+
}
|
|
143
|
+
lines.push(chars.bottomLeft + chars.horizontal.repeat(contentWidth) + chars.bottomRight);
|
|
144
|
+
if (bg) {
|
|
145
|
+
const bgCode = getBgColorCode(bg);
|
|
146
|
+
return lines.map((line) => bgCode + line + ANSI.reset);
|
|
147
|
+
}
|
|
148
|
+
return lines;
|
|
149
|
+
}
|
|
150
|
+
function Box(props) {
|
|
151
|
+
return React.createElement("box", props);
|
|
152
|
+
}
|
|
153
|
+
function renderText(props, context) {
|
|
154
|
+
const { children, bold, italic, underline, dim, color, backgroundColor, wrap } = props;
|
|
155
|
+
let text = extractChildren(children);
|
|
156
|
+
const codes = [];
|
|
157
|
+
if (bold) codes.push(ANSI.bold);
|
|
158
|
+
if (italic) codes.push(ANSI.italic);
|
|
159
|
+
if (underline) codes.push(ANSI.underline);
|
|
160
|
+
if (dim) codes.push(ANSI.dim);
|
|
161
|
+
if (color) codes.push(getColorCode(color));
|
|
162
|
+
if (backgroundColor) codes.push(getBgColorCode(backgroundColor));
|
|
163
|
+
const maxWidth = context.parentWidth || context.width;
|
|
164
|
+
if (wrap === "truncate" && text.length > maxWidth) {
|
|
165
|
+
text = text.slice(0, maxWidth - 1) + "\u2026";
|
|
166
|
+
} else if (wrap === "wrap" && text.length > maxWidth) {
|
|
167
|
+
const lines = [];
|
|
168
|
+
let remaining = text;
|
|
169
|
+
while (remaining.length > 0) {
|
|
170
|
+
if (remaining.length <= maxWidth) {
|
|
171
|
+
lines.push(remaining);
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
let breakPoint = maxWidth;
|
|
175
|
+
const lastSpace = remaining.lastIndexOf(" ", maxWidth);
|
|
176
|
+
if (lastSpace > 0) breakPoint = lastSpace;
|
|
177
|
+
lines.push(remaining.slice(0, breakPoint));
|
|
178
|
+
remaining = remaining.slice(breakPoint).trim();
|
|
179
|
+
}
|
|
180
|
+
return lines.map((line) => codes.join("") + line + ANSI.reset);
|
|
181
|
+
}
|
|
182
|
+
if (codes.length > 0) {
|
|
183
|
+
return [codes.join("") + text + ANSI.reset];
|
|
184
|
+
}
|
|
185
|
+
return [text];
|
|
186
|
+
}
|
|
187
|
+
function Text(props) {
|
|
188
|
+
return React.createElement("text", props);
|
|
189
|
+
}
|
|
190
|
+
function renderTable(props, _context) {
|
|
191
|
+
const { data, columns, selectedIndex } = props;
|
|
192
|
+
const lines = [];
|
|
193
|
+
const colWidths = columns.map((col, idx) => {
|
|
194
|
+
if (col.width) return col.width;
|
|
195
|
+
let maxWidth = col.header.length;
|
|
196
|
+
for (const row of data) {
|
|
197
|
+
const value = String(row[col.key] ?? "");
|
|
198
|
+
maxWidth = Math.max(maxWidth, value.length);
|
|
199
|
+
}
|
|
200
|
+
return maxWidth + 2;
|
|
201
|
+
});
|
|
202
|
+
const headerParts = columns.map((col, idx) => {
|
|
203
|
+
const width = colWidths[idx];
|
|
204
|
+
return col.header.padEnd(width);
|
|
205
|
+
});
|
|
206
|
+
lines.push("\u2502" + headerParts.join("\u2502") + "\u2502");
|
|
207
|
+
const separatorParts = colWidths.map((w) => "\u2500".repeat(w));
|
|
208
|
+
lines.push("\u251C" + separatorParts.join("\u253C") + "\u2524");
|
|
209
|
+
data.forEach((row, rowIndex) => {
|
|
210
|
+
const rowParts = columns.map((col, idx) => {
|
|
211
|
+
const value = String(row[col.key] ?? "");
|
|
212
|
+
const width = colWidths[idx];
|
|
213
|
+
if (col.align === "right") {
|
|
214
|
+
return value.padStart(width);
|
|
215
|
+
}
|
|
216
|
+
return value.padEnd(width);
|
|
217
|
+
});
|
|
218
|
+
let rowLine = "\u2502" + rowParts.join("\u2502") + "\u2502";
|
|
219
|
+
if (selectedIndex === rowIndex) {
|
|
220
|
+
rowLine = "\x1B[44m" + rowLine + ANSI.reset;
|
|
221
|
+
}
|
|
222
|
+
lines.push(rowLine);
|
|
223
|
+
});
|
|
224
|
+
return lines;
|
|
225
|
+
}
|
|
226
|
+
function Table(props) {
|
|
227
|
+
return React.createElement("table", props);
|
|
228
|
+
}
|
|
229
|
+
function renderInput(props, _context) {
|
|
230
|
+
const { value = "", placeholder, label, disabled, focused, type } = props;
|
|
231
|
+
const lines = [];
|
|
232
|
+
if (label) {
|
|
233
|
+
lines.push(label);
|
|
234
|
+
}
|
|
235
|
+
let displayValue;
|
|
236
|
+
if (type === "password" && value) {
|
|
237
|
+
displayValue = "*".repeat(value.length);
|
|
238
|
+
} else if (value) {
|
|
239
|
+
displayValue = value;
|
|
240
|
+
} else if (placeholder) {
|
|
241
|
+
displayValue = ANSI.dim + placeholder + ANSI.reset;
|
|
242
|
+
} else {
|
|
243
|
+
displayValue = "";
|
|
244
|
+
}
|
|
245
|
+
let inputLine = displayValue;
|
|
246
|
+
if (focused) {
|
|
247
|
+
inputLine = ANSI.cyan + displayValue + "\u2588" + ANSI.reset;
|
|
248
|
+
}
|
|
249
|
+
if (disabled) {
|
|
250
|
+
inputLine = ANSI.dim + displayValue + ANSI.reset;
|
|
251
|
+
}
|
|
252
|
+
lines.push(inputLine);
|
|
253
|
+
return lines;
|
|
254
|
+
}
|
|
255
|
+
function Input(props) {
|
|
256
|
+
return React.createElement("input", props);
|
|
257
|
+
}
|
|
258
|
+
function renderSelect(props, _context) {
|
|
259
|
+
const { options, value, label, focused, highlightedIndex } = props;
|
|
260
|
+
const lines = [];
|
|
261
|
+
if (label) {
|
|
262
|
+
lines.push(label);
|
|
263
|
+
}
|
|
264
|
+
const selected = options.find((opt) => opt.value === value);
|
|
265
|
+
if (focused) {
|
|
266
|
+
options.forEach((opt, idx) => {
|
|
267
|
+
let optLine = opt.label;
|
|
268
|
+
if (idx === highlightedIndex || opt.value === value) {
|
|
269
|
+
optLine = "\x1B[44m" + opt.label + ANSI.reset;
|
|
270
|
+
}
|
|
271
|
+
lines.push(optLine);
|
|
272
|
+
});
|
|
273
|
+
} else {
|
|
274
|
+
const selectedLabel = selected ? selected.label : "";
|
|
275
|
+
lines.push(selectedLabel + " \u25BC");
|
|
276
|
+
}
|
|
277
|
+
return lines;
|
|
278
|
+
}
|
|
279
|
+
function Select(props) {
|
|
280
|
+
return React.createElement("select", props);
|
|
281
|
+
}
|
|
282
|
+
function renderSidebar(props, context) {
|
|
283
|
+
const { children, width = 20, collapsed } = props;
|
|
284
|
+
const lines = [];
|
|
285
|
+
const childArray = Children.toArray(children);
|
|
286
|
+
for (const child of childArray) {
|
|
287
|
+
if (isValidElement(child)) {
|
|
288
|
+
const childProps = child.props;
|
|
289
|
+
const modifiedProps = { ...childProps, _collapsed: collapsed };
|
|
290
|
+
const childLines = renderSidebarItem(modifiedProps, { ...context, width });
|
|
291
|
+
lines.push(...childLines);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
return lines.map((line) => {
|
|
295
|
+
const stripped = line.replace(/\x1b\[[\d;]*m/g, "");
|
|
296
|
+
if (stripped.length > width) {
|
|
297
|
+
return line.slice(0, width);
|
|
298
|
+
}
|
|
299
|
+
return line;
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
function Sidebar(props) {
|
|
303
|
+
return React.createElement("sidebar", props);
|
|
304
|
+
}
|
|
305
|
+
function renderSidebarItem(props, _context) {
|
|
306
|
+
const { label, icon, active, _collapsed } = props;
|
|
307
|
+
if (_collapsed) {
|
|
308
|
+
return [icon || ""];
|
|
309
|
+
}
|
|
310
|
+
let line = "";
|
|
311
|
+
if (active) {
|
|
312
|
+
line = "\u25B6 ";
|
|
313
|
+
}
|
|
314
|
+
if (icon) {
|
|
315
|
+
line += icon + " ";
|
|
316
|
+
}
|
|
317
|
+
line += label;
|
|
318
|
+
if (active) {
|
|
319
|
+
line = "\x1B[44m" + line + ANSI.reset;
|
|
320
|
+
}
|
|
321
|
+
return [line];
|
|
322
|
+
}
|
|
323
|
+
function SidebarItem(props) {
|
|
324
|
+
return React.createElement("sidebar-item", props);
|
|
325
|
+
}
|
|
326
|
+
function renderBreadcrumb(props, _context) {
|
|
327
|
+
const { items, separator = "/" } = props;
|
|
328
|
+
const parts = [];
|
|
329
|
+
items.forEach((item, idx) => {
|
|
330
|
+
const isLast = idx === items.length - 1;
|
|
331
|
+
if (isLast) {
|
|
332
|
+
parts.push(ANSI.bold + item.label + ANSI.reset);
|
|
333
|
+
} else {
|
|
334
|
+
parts.push(ANSI.dim + item.label + ANSI.reset);
|
|
335
|
+
}
|
|
336
|
+
});
|
|
337
|
+
return [parts.join(` ${separator} `)];
|
|
338
|
+
}
|
|
339
|
+
function Breadcrumb(props) {
|
|
340
|
+
return React.createElement("breadcrumb", props);
|
|
341
|
+
}
|
|
342
|
+
function renderBadge(props, _context) {
|
|
343
|
+
const { children, variant = "default" } = props;
|
|
344
|
+
const text = extractChildren(children);
|
|
345
|
+
let color;
|
|
346
|
+
switch (variant) {
|
|
347
|
+
case "success":
|
|
348
|
+
color = "\x1B[32m";
|
|
349
|
+
break;
|
|
350
|
+
case "warning":
|
|
351
|
+
color = "\x1B[33m";
|
|
352
|
+
break;
|
|
353
|
+
case "error":
|
|
354
|
+
color = "\x1B[31m";
|
|
355
|
+
break;
|
|
356
|
+
case "info":
|
|
357
|
+
color = "\x1B[34m";
|
|
358
|
+
break;
|
|
359
|
+
default:
|
|
360
|
+
color = ANSI.dim;
|
|
361
|
+
}
|
|
362
|
+
return [color + "[" + text + "]" + ANSI.reset];
|
|
363
|
+
}
|
|
364
|
+
function Badge(props) {
|
|
365
|
+
return React.createElement("badge", props);
|
|
366
|
+
}
|
|
367
|
+
function renderDialog(props, context) {
|
|
368
|
+
const { open, title, children } = props;
|
|
369
|
+
if (!open) {
|
|
370
|
+
return [""];
|
|
371
|
+
}
|
|
372
|
+
const dialogWidth = 40;
|
|
373
|
+
const padding = Math.floor((context.width - dialogWidth) / 2);
|
|
374
|
+
const paddingStr = " ".repeat(Math.max(0, padding));
|
|
375
|
+
const lines = [];
|
|
376
|
+
const chars = boxChars.single;
|
|
377
|
+
lines.push(paddingStr + ANSI.cyan + chars.topLeft + chars.horizontal.repeat(dialogWidth - 2) + chars.topRight + ANSI.reset);
|
|
378
|
+
if (title) {
|
|
379
|
+
const titlePadded = (" " + title).padEnd(dialogWidth - 2);
|
|
380
|
+
lines.push(paddingStr + ANSI.cyan + chars.vertical + ANSI.reset + ANSI.bold + titlePadded + ANSI.reset + ANSI.cyan + chars.vertical + ANSI.reset);
|
|
381
|
+
lines.push(paddingStr + ANSI.cyan + chars.teeLeft + chars.horizontal.repeat(dialogWidth - 2) + chars.teeRight + ANSI.reset);
|
|
382
|
+
}
|
|
383
|
+
const content = extractChildren(children);
|
|
384
|
+
const contentLines = content.split("\n");
|
|
385
|
+
for (const contentLine of contentLines) {
|
|
386
|
+
const paddedContent = (" " + contentLine).padEnd(dialogWidth - 2);
|
|
387
|
+
lines.push(paddingStr + ANSI.cyan + chars.vertical + ANSI.reset + paddedContent + ANSI.cyan + chars.vertical + ANSI.reset);
|
|
388
|
+
}
|
|
389
|
+
lines.push(paddingStr + ANSI.cyan + chars.bottomLeft + chars.horizontal.repeat(dialogWidth - 2) + chars.bottomRight + ANSI.reset);
|
|
390
|
+
return lines;
|
|
391
|
+
}
|
|
392
|
+
function Dialog(props) {
|
|
393
|
+
return React.createElement("dialog", props);
|
|
394
|
+
}
|
|
395
|
+
var spinnerFrames = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
|
|
396
|
+
function renderSpinner(props, _context) {
|
|
397
|
+
const { label } = props;
|
|
398
|
+
const frame = spinnerFrames[0];
|
|
399
|
+
const text = label ? `${frame} ${label}` : frame;
|
|
400
|
+
return [ANSI.cyan + text + ANSI.reset];
|
|
401
|
+
}
|
|
402
|
+
function Spinner(props) {
|
|
403
|
+
return React.createElement("spinner", props);
|
|
404
|
+
}
|
|
405
|
+
function renderButton(props, _context) {
|
|
406
|
+
const { children, hotkey, disabled, focused, variant = "primary" } = props;
|
|
407
|
+
const text = extractChildren(children);
|
|
408
|
+
let style = "";
|
|
409
|
+
let bgColor = "";
|
|
410
|
+
switch (variant) {
|
|
411
|
+
case "primary":
|
|
412
|
+
bgColor = "\x1B[44m";
|
|
413
|
+
style = ANSI.bold;
|
|
414
|
+
break;
|
|
415
|
+
case "secondary":
|
|
416
|
+
bgColor = "\x1B[100m";
|
|
417
|
+
break;
|
|
418
|
+
case "destructive":
|
|
419
|
+
bgColor = "\x1B[41m";
|
|
420
|
+
style = ANSI.bold;
|
|
421
|
+
break;
|
|
422
|
+
}
|
|
423
|
+
let buttonText = ` ${text} `;
|
|
424
|
+
if (hotkey) {
|
|
425
|
+
buttonText += `[${hotkey}]`;
|
|
426
|
+
}
|
|
427
|
+
if (disabled) {
|
|
428
|
+
return [ANSI.dim + `[ ${text} ]` + ANSI.reset];
|
|
429
|
+
}
|
|
430
|
+
if (focused) {
|
|
431
|
+
return [bgColor + style + "\x1B[37m" + buttonText + ANSI.reset];
|
|
432
|
+
}
|
|
433
|
+
return [bgColor + style + buttonText + ANSI.reset];
|
|
434
|
+
}
|
|
435
|
+
function Button(props) {
|
|
436
|
+
return React.createElement("button", props);
|
|
437
|
+
}
|
|
438
|
+
function renderPanel(props, context) {
|
|
439
|
+
const { children, title, border = "single", collapsed, padding = 0 } = props;
|
|
440
|
+
if (collapsed) {
|
|
441
|
+
return [ANSI.dim + "\u25B6 " + ANSI.reset + ANSI.bold + (title || "Panel") + ANSI.reset];
|
|
442
|
+
}
|
|
443
|
+
const lines = [];
|
|
444
|
+
const chars = border === "double" ? boxChars.double : border === "rounded" ? boxChars.rounded : boxChars.single;
|
|
445
|
+
const panelWidth = context.width;
|
|
446
|
+
if (title && border !== "none") {
|
|
447
|
+
const titleText = ` ${title} `;
|
|
448
|
+
const remainingWidth = panelWidth - titleText.length - 2;
|
|
449
|
+
const leftBorder = Math.floor(remainingWidth / 2);
|
|
450
|
+
const rightBorder = remainingWidth - leftBorder;
|
|
451
|
+
lines.push(chars.topLeft + chars.horizontal.repeat(leftBorder) + ANSI.bold + titleText + ANSI.reset + chars.horizontal.repeat(rightBorder) + chars.topRight);
|
|
452
|
+
} else if (border !== "none") {
|
|
453
|
+
lines.push(chars.topLeft + chars.horizontal.repeat(panelWidth - 2) + chars.topRight);
|
|
454
|
+
}
|
|
455
|
+
const content = extractChildren(children);
|
|
456
|
+
const contentLines = content.split("\n");
|
|
457
|
+
const paddingStr = " ".repeat(padding);
|
|
458
|
+
for (const line of contentLines) {
|
|
459
|
+
if (border !== "none") {
|
|
460
|
+
lines.push(chars.vertical + paddingStr + line.padEnd(panelWidth - 2 - padding * 2) + paddingStr + chars.vertical);
|
|
461
|
+
} else {
|
|
462
|
+
lines.push(paddingStr + line);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
if (border !== "none") {
|
|
466
|
+
lines.push(chars.bottomLeft + chars.horizontal.repeat(panelWidth - 2) + chars.bottomRight);
|
|
467
|
+
}
|
|
468
|
+
return lines;
|
|
469
|
+
}
|
|
470
|
+
function Panel(props) {
|
|
471
|
+
return React.createElement("panel", props);
|
|
472
|
+
}
|
|
473
|
+
function renderList(props, _context) {
|
|
474
|
+
const { items, selectedIndex, bullet = "\u2022", numbered = false } = props;
|
|
475
|
+
return items.map((item, idx) => {
|
|
476
|
+
const text = typeof item === "string" ? item : extractChildren(item);
|
|
477
|
+
const prefix = numbered ? `${idx + 1}. ` : `${bullet} `;
|
|
478
|
+
const isSelected = selectedIndex === idx;
|
|
479
|
+
if (isSelected) {
|
|
480
|
+
return ANSI.cyan + "\x1B[44m" + prefix + text + ANSI.reset;
|
|
481
|
+
}
|
|
482
|
+
return prefix + text;
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
function List(props) {
|
|
486
|
+
return React.createElement("list", props);
|
|
487
|
+
}
|
|
488
|
+
function renderCard(props, context) {
|
|
489
|
+
const { children, title, border = "single" } = props;
|
|
490
|
+
const lines = [];
|
|
491
|
+
const chars = border === "double" ? boxChars.double : boxChars.single;
|
|
492
|
+
const cardWidth = Math.min(context.width, 60);
|
|
493
|
+
if (border !== "none") {
|
|
494
|
+
lines.push(chars.topLeft + chars.horizontal.repeat(cardWidth - 2) + chars.topRight);
|
|
495
|
+
}
|
|
496
|
+
if (title) {
|
|
497
|
+
const titleLine = " " + ANSI.bold + title + ANSI.reset;
|
|
498
|
+
if (border !== "none") {
|
|
499
|
+
lines.push(chars.vertical + titleLine.padEnd(cardWidth - 2 + ANSI.bold.length + ANSI.reset.length) + chars.vertical);
|
|
500
|
+
lines.push(chars.teeLeft + chars.horizontal.repeat(cardWidth - 2) + chars.teeRight);
|
|
501
|
+
} else {
|
|
502
|
+
lines.push(ANSI.bold + title + ANSI.reset);
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
const content = extractChildren(children);
|
|
506
|
+
const contentLines = content.split("\n");
|
|
507
|
+
for (const line of contentLines) {
|
|
508
|
+
if (border !== "none") {
|
|
509
|
+
lines.push(chars.vertical + " " + line.padEnd(cardWidth - 4) + " " + chars.vertical);
|
|
510
|
+
} else {
|
|
511
|
+
lines.push(line);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
if (border !== "none") {
|
|
515
|
+
lines.push(chars.bottomLeft + chars.horizontal.repeat(cardWidth - 2) + chars.bottomRight);
|
|
516
|
+
}
|
|
517
|
+
return lines;
|
|
518
|
+
}
|
|
519
|
+
function Card(props) {
|
|
520
|
+
return React.createElement("card", props);
|
|
521
|
+
}
|
|
522
|
+
function Site(props) {
|
|
523
|
+
return React.createElement("site", props);
|
|
524
|
+
}
|
|
525
|
+
function Header(props) {
|
|
526
|
+
return React.createElement("header", props);
|
|
527
|
+
}
|
|
528
|
+
function Footer(props) {
|
|
529
|
+
return React.createElement("footer", props);
|
|
530
|
+
}
|
|
531
|
+
function Hero(props) {
|
|
532
|
+
return React.createElement("hero", props);
|
|
533
|
+
}
|
|
534
|
+
function Features(props) {
|
|
535
|
+
return React.createElement("features", props);
|
|
536
|
+
}
|
|
537
|
+
function Pricing(props) {
|
|
538
|
+
return React.createElement("pricing", props);
|
|
539
|
+
}
|
|
540
|
+
function FAQ(props) {
|
|
541
|
+
return React.createElement("faq", props);
|
|
542
|
+
}
|
|
543
|
+
function LandingPage(props) {
|
|
544
|
+
return React.createElement("landing-page", props);
|
|
545
|
+
}
|
|
546
|
+
function Page(props) {
|
|
547
|
+
return React.createElement("page", props);
|
|
548
|
+
}
|
|
549
|
+
function App(props) {
|
|
550
|
+
return React.createElement("app", props);
|
|
551
|
+
}
|
|
552
|
+
function Shell(props) {
|
|
553
|
+
return React.createElement("shell", props);
|
|
554
|
+
}
|
|
555
|
+
function Dashboard(props) {
|
|
556
|
+
return React.createElement("dashboard", props);
|
|
557
|
+
}
|
|
558
|
+
function Settings(props) {
|
|
559
|
+
return React.createElement("settings", props);
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
export {
|
|
563
|
+
renderComponent,
|
|
564
|
+
Box,
|
|
565
|
+
Text,
|
|
566
|
+
Table,
|
|
567
|
+
Input,
|
|
568
|
+
Select,
|
|
569
|
+
Sidebar,
|
|
570
|
+
SidebarItem,
|
|
571
|
+
Breadcrumb,
|
|
572
|
+
Badge,
|
|
573
|
+
Dialog,
|
|
574
|
+
Spinner,
|
|
575
|
+
Button,
|
|
576
|
+
Panel,
|
|
577
|
+
List,
|
|
578
|
+
Card,
|
|
579
|
+
Site,
|
|
580
|
+
Header,
|
|
581
|
+
Footer,
|
|
582
|
+
Hero,
|
|
583
|
+
Features,
|
|
584
|
+
Pricing,
|
|
585
|
+
FAQ,
|
|
586
|
+
LandingPage,
|
|
587
|
+
Page,
|
|
588
|
+
App,
|
|
589
|
+
Shell,
|
|
590
|
+
Dashboard,
|
|
591
|
+
Settings
|
|
592
|
+
};
|