@longzai-intelligence-cli/tui 0.0.5
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 +131 -0
- package/dist/index.js +1 -0
- package/dist/rolldown-runtime-BqT_7tdF.js +1 -0
- package/package.json +46 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import "./rolldown-runtime-BqT_7tdF.js";
|
|
2
|
+
import { render } from "ink";
|
|
3
|
+
import { FC, ReactElement, ReactNode } from "react";
|
|
4
|
+
//#region src/render-app.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* ink 渲染实例类型
|
|
7
|
+
*
|
|
8
|
+
* 暴露给消费方,用于等待渲染就绪与卸载
|
|
9
|
+
*/
|
|
10
|
+
type RenderInstance = ReturnType<typeof render>;
|
|
11
|
+
/**
|
|
12
|
+
* 渲染 TUI 应用
|
|
13
|
+
*
|
|
14
|
+
* 使用 ink 的 render 函数将 React 元素渲染到终端,
|
|
15
|
+
* 返回 ink 渲染实例以支持后续卸载与等待退出操作。
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```tsx
|
|
19
|
+
* import { renderApp } from '@longzai-intelligence-cli/tui';
|
|
20
|
+
* import { DataTable } from '@longzai-intelligence-cli/tui';
|
|
21
|
+
*
|
|
22
|
+
* const instance = renderApp(<DataTable columns={...} rows={...} />);
|
|
23
|
+
* instance.unmount();
|
|
24
|
+
* ```;
|
|
25
|
+
*
|
|
26
|
+
* @param element - 要渲染的 React 元素
|
|
27
|
+
* @returns ink 渲染实例
|
|
28
|
+
*/
|
|
29
|
+
declare function renderApp(element: ReactElement): RenderInstance;
|
|
30
|
+
//#endregion
|
|
31
|
+
//#region src/components/data-table.d.ts
|
|
32
|
+
/** 文本对齐方式 */
|
|
33
|
+
type Align = 'left' | 'right';
|
|
34
|
+
/** ink Text 支持的颜色字面量 */
|
|
35
|
+
type TextColor = 'black' | 'red' | 'green' | 'yellow' | 'blue' | 'magenta' | 'cyan' | 'white' | 'gray' | 'grayBright' | 'redBright' | 'greenBright' | 'yellowBright' | 'blueBright' | 'magentaBright' | 'cyanBright' | 'whiteBright';
|
|
36
|
+
/** 单元格取值方式:字段名或格式化器函数 */
|
|
37
|
+
type CellAccessor<T> = keyof T | ((row: T) => string);
|
|
38
|
+
/**
|
|
39
|
+
* 列定义
|
|
40
|
+
*
|
|
41
|
+
* @typeParam T - 行数据类型
|
|
42
|
+
*/
|
|
43
|
+
type Column<T> = {
|
|
44
|
+
/** 列标题(表头显示文本) */
|
|
45
|
+
header: string;
|
|
46
|
+
/** 列宽(字符数,用于 Box width) */
|
|
47
|
+
width: number;
|
|
48
|
+
/** 单元格取值:行字段名或自定义格式化器 */
|
|
49
|
+
cell: CellAccessor<T>;
|
|
50
|
+
/** 文本对齐,默认 left */
|
|
51
|
+
align?: Align;
|
|
52
|
+
/** 数据行文本颜色,默认不染色 */
|
|
53
|
+
color?: TextColor;
|
|
54
|
+
};
|
|
55
|
+
/** DataTable 组件属性 */
|
|
56
|
+
type DataTableProps<T> = {
|
|
57
|
+
/** 列定义列表 */
|
|
58
|
+
columns: Array<Column<T>>;
|
|
59
|
+
/** 行数据列表 */
|
|
60
|
+
rows: T[];
|
|
61
|
+
/** 表格标题(显示在表头上方) */
|
|
62
|
+
title?: string;
|
|
63
|
+
/** 总记录数(用于标题展示,通常在分页时传入) */
|
|
64
|
+
total?: number;
|
|
65
|
+
/** 空态提示文本,默认"暂无数据" */
|
|
66
|
+
emptyText?: string;
|
|
67
|
+
/** 行 key 提取器,默认使用行索引字符串 */
|
|
68
|
+
rowKey?: (row: T, index: number) => string;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* 泛型数据表格组件
|
|
72
|
+
*
|
|
73
|
+
* 渲染表格头部与各行数据,空列表时显示空态提示。
|
|
74
|
+
* 因 React FC 不支持泛型参数透传,采用泛型函数组件形式;
|
|
75
|
+
* 消费方可通过 JSX `<DataTable columns={...} rows={...} />` 或 `createElement(DataTable, {...})` 使用。
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```tsx
|
|
79
|
+
* import { DataTable, type Column } from '@longzai-intelligence-cli/tui';
|
|
80
|
+
*
|
|
81
|
+
* type Repo = { name: string; stars: number };
|
|
82
|
+
* const columns: Column<Repo>[] = [
|
|
83
|
+
* { header: '名称', width: 30, cell: 'name', color: 'blue' },
|
|
84
|
+
* { header: 'Stars', width: 10, cell: (r) => String(r.stars), align: 'right' },
|
|
85
|
+
* ];
|
|
86
|
+
*
|
|
87
|
+
* <DataTable title="仓库列表" total={repos.length} columns={columns} rows={repos} />
|
|
88
|
+
* ```;
|
|
89
|
+
*
|
|
90
|
+
* @typeParam T - 行数据类型
|
|
91
|
+
*/
|
|
92
|
+
declare function DataTable<T>(props: DataTableProps<T>): ReactElement;
|
|
93
|
+
//#endregion
|
|
94
|
+
//#region src/components/info-panel.d.ts
|
|
95
|
+
/** InfoPanel 组件属性 */
|
|
96
|
+
type InfoPanelProps = {
|
|
97
|
+
/** 面板标题(显示在顶部) */
|
|
98
|
+
title: string;
|
|
99
|
+
/** 面板内容 */
|
|
100
|
+
children: ReactNode;
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* 信息面板组件
|
|
104
|
+
*
|
|
105
|
+
* 以青色粗体标题 + 内容区形式渲染
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```tsx
|
|
109
|
+
* <InfoPanel title="统计概览">
|
|
110
|
+
* <Text>仓库总数:{stats.totalRepos}</Text>
|
|
111
|
+
* </InfoPanel>
|
|
112
|
+
* ```;
|
|
113
|
+
*/
|
|
114
|
+
declare const InfoPanel: FC<InfoPanelProps>;
|
|
115
|
+
//#endregion
|
|
116
|
+
//#region src/components/empty-state.d.ts
|
|
117
|
+
/** 空态提示组件属性 */
|
|
118
|
+
type EmptyStateProps = {
|
|
119
|
+
/** 提示文本(默认"暂无数据") */
|
|
120
|
+
text?: string;
|
|
121
|
+
};
|
|
122
|
+
/**
|
|
123
|
+
* 空态提示组件
|
|
124
|
+
*
|
|
125
|
+
* 以暗色文本居中展示空态提示
|
|
126
|
+
*
|
|
127
|
+
* @param props - 组件属性
|
|
128
|
+
*/
|
|
129
|
+
declare const EmptyState: FC<EmptyStateProps>;
|
|
130
|
+
//#endregion
|
|
131
|
+
export { type Column, DataTable, type DataTableProps, EmptyState, InfoPanel, type RenderInstance, renderApp };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./rolldown-runtime-BqT_7tdF.js";import{Box as e,Text as t,render as n}from"ink";import{jsx as r,jsxs as i}from"react/jsx-runtime";function a(e){return n(e)}const o=({text:n=`暂无数据`})=>r(e,{padding:1,children:r(t,{dimColor:!0,children:n})});function s(e,t){if(typeof t==`function`)return t(e);let n=e[t];return n==null?`-`:String(n)}function c(n){let{columns:a,rows:c,title:l,total:u,emptyText:d=`暂无数据`,rowKey:f}=n;if(c.length===0)return r(o,{text:d});let p=a.reduce((e,t)=>e+t.width,0);return i(e,{flexDirection:`column`,padding:1,children:[l!==void 0&&i(t,{color:`cyan`,bold:!0,children:[l,u===void 0?``:`(共 ${u} 条)`]}),i(e,{marginTop:l===void 0?0:1,flexDirection:`column`,children:[r(e,{children:a.map(n=>r(e,{width:n.width,children:r(t,{bold:!0,color:`gray`,children:n.header})},n.header))}),r(t,{dimColor:!0,children:`─`.repeat(p)}),c.map((n,i)=>r(e,{children:a.map(i=>{let a=s(n,i.cell);return r(e,{width:i.width,children:i.color===void 0?r(t,{children:a}):r(t,{color:i.color,children:a})},i.header)})},f?.(n,i)??String(i)))]})]})}const l=({title:n,children:a})=>i(e,{flexDirection:`column`,padding:1,children:[r(t,{color:`cyan`,bold:!0,children:n}),r(e,{marginTop:1,flexDirection:`column`,children:a})]});export{c as DataTable,o as EmptyState,l as InfoPanel,a as renderApp};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"node:module";export{};
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@longzai-intelligence-cli/tui",
|
|
3
|
+
"version": "0.0.5",
|
|
4
|
+
"private": false,
|
|
5
|
+
"keywords": [
|
|
6
|
+
"cli",
|
|
7
|
+
"ink",
|
|
8
|
+
"preset",
|
|
9
|
+
"react",
|
|
10
|
+
"tui"
|
|
11
|
+
],
|
|
12
|
+
"license": "UNLICENSED",
|
|
13
|
+
"files": [
|
|
14
|
+
"dist"
|
|
15
|
+
],
|
|
16
|
+
"type": "module",
|
|
17
|
+
"main": "./dist/index.js",
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"exports": {
|
|
20
|
+
".": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"import": "./dist/index.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "lzi-builder",
|
|
27
|
+
"build:prod": "NODE_ENV=production lzi-builder",
|
|
28
|
+
"prepublishOnly": "bun run build:prod",
|
|
29
|
+
"typecheck": "bun run typecheck:app && bun run typecheck:node && bun run typecheck:test",
|
|
30
|
+
"typecheck:app": "tsgo --noEmit -p tsconfig/app.json",
|
|
31
|
+
"typecheck:node": "tsgo --noEmit -p tsconfig/node.json",
|
|
32
|
+
"typecheck:test": "tsgo --noEmit -p tsconfig/test.json",
|
|
33
|
+
"lint": "oxlint && oxfmt --check",
|
|
34
|
+
"lint:fix": "oxlint --fix && oxfmt",
|
|
35
|
+
"test": "bun test",
|
|
36
|
+
"test:watch": "bun test --watch",
|
|
37
|
+
"test:coverage": "bun test --coverage",
|
|
38
|
+
"clean": "lzi-dev-cli clean"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@longzai-intelligence-cli/core": "0.0.5",
|
|
42
|
+
"ink": "^5.0.1",
|
|
43
|
+
"react": "^19.2.6"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {}
|
|
46
|
+
}
|