lynote-ui 0.0.9 → 0.0.11

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.
@@ -1,10 +1,13 @@
1
- import * as React from "react";
2
- declare function Table({ className, ...props }: React.ComponentProps<"table">): import("react/jsx-runtime").JSX.Element;
3
- declare function TableHeader({ className, ...props }: React.ComponentProps<"thead">): import("react/jsx-runtime").JSX.Element;
4
- declare function TableBody({ className, ...props }: React.ComponentProps<"tbody">): import("react/jsx-runtime").JSX.Element;
5
- declare function TableFooter({ className, ...props }: React.ComponentProps<"tfoot">): import("react/jsx-runtime").JSX.Element;
6
- declare function TableRow({ className, ...props }: React.ComponentProps<"tr">): import("react/jsx-runtime").JSX.Element;
7
- declare function TableHead({ className, ...props }: React.ComponentProps<"th">): import("react/jsx-runtime").JSX.Element;
8
- declare function TableCell({ className, ...props }: React.ComponentProps<"td">): import("react/jsx-runtime").JSX.Element;
9
- declare function TableCaption({ className, ...props }: React.ComponentProps<"caption">): import("react/jsx-runtime").JSX.Element;
10
- export { Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow, };
1
+ export * from './components/base-table';
2
+ export { DataTable, type DataTableHandle } from './components/data-table';
3
+ export { DataTableColumnHeader } from './components/data-table-column-header';
4
+ export { DataTablePagination } from './components/data-table-pagination';
5
+ export { DataTableToolbar } from './components/data-table-toolbar';
6
+ export { DataTableViewOptions } from './components/data-table-view-options';
7
+ export { DataTableVirtualBody } from './components/data-table-virtual-body';
8
+ export { RowDragHandle, RowDragHandleContext, type RowDragHandleContextValue, } from './components/row-drag-handle';
9
+ export { RowExpandToggle } from './components/row-expand-toggle';
10
+ export { useDataTable, useScrollShadow } from './hooks/use-data-table';
11
+ export type { AnyColumn, CellMergeMeta, ColSpanContext, DataTableColumn, DataTableFeatures, DataTablePropsType, DataTableState, DataTableStateHandlers, DataTableVirtualOptions, RowOrderChangeInfo, RowSpanContext, ScrollShadowState, } from './type';
12
+ export { computeCellSpans, getColumnPinningClassName, getCommonPinningStyles, panelIdFor, } from './utils';
13
+ export type { CellSpan, CellSpanMap } from './utils';
@@ -1,79 +1,25 @@
1
- "use client";
2
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const require_chunk = require("../chunk-8l464Juk.js");
4
- const require_utils = require("../utils-DrngEK1K.js");
5
- let react_jsx_runtime = require("react/jsx-runtime");
6
- let react = require("react");
7
- react = require_chunk.__toESM(react);
8
- //#region src/table/index.tsx
9
- function Table({ className, ...props }) {
10
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
11
- "data-slot": "table-container",
12
- className: "relative w-full overflow-x-auto",
13
- children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("table", {
14
- "data-slot": "table",
15
- className: require_utils.cn("w-full caption-bottom text-sm", className),
16
- ...props
17
- })
18
- });
19
- }
20
- function TableHeader({ className, ...props }) {
21
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("thead", {
22
- "data-slot": "table-header",
23
- className: require_utils.cn("[&_tr]:border-b", className),
24
- ...props
25
- });
26
- }
27
- function TableBody({ className, ...props }) {
28
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("tbody", {
29
- "data-slot": "table-body",
30
- className: require_utils.cn("[&_tr:last-child]:border-0", className),
31
- ...props
32
- });
33
- }
34
- function TableFooter({ className, ...props }) {
35
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("tfoot", {
36
- "data-slot": "table-footer",
37
- className: require_utils.cn("bg-muted/50 border-t font-medium [&>tr]:last:border-b-0", className),
38
- ...props
39
- });
40
- }
41
- function TableRow({ className, ...props }) {
42
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("tr", {
43
- "data-slot": "table-row",
44
- className: require_utils.cn("hover:bg-muted/50 data-[state=selected]:bg-muted border-b transition-colors", className),
45
- ...props
46
- });
47
- }
48
- function TableHead({ className, ...props }) {
49
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("th", {
50
- "data-slot": "table-head",
51
- className: require_utils.cn("text-foreground h-10 whitespace-nowrap px-2 text-left align-middle font-medium [&:has([role=checkbox])]:pr-0", className),
52
- ...props
53
- });
54
- }
55
- function TableCell({ className, ...props }) {
56
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("td", {
57
- "data-slot": "table-cell",
58
- className: require_utils.cn("whitespace-nowrap p-2 align-middle [&:has([role=checkbox])]:pr-0", className),
59
- ...props
60
- });
61
- }
62
- function TableCaption({ className, ...props }) {
63
- return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("caption", {
64
- "data-slot": "table-caption",
65
- className: require_utils.cn("text-muted-foreground mt-4 text-sm", className),
66
- ...props
67
- });
68
- }
69
- //#endregion
70
- exports.Table = Table;
71
- exports.TableBody = TableBody;
72
- exports.TableCaption = TableCaption;
73
- exports.TableCell = TableCell;
74
- exports.TableFooter = TableFooter;
75
- exports.TableHead = TableHead;
76
- exports.TableHeader = TableHeader;
77
- exports.TableRow = TableRow;
78
-
79
- //# sourceMappingURL=index.js.map
2
+ const require_table = require("../table-FocfdaF7.js");
3
+ exports.DataTable = require_table.DataTable;
4
+ exports.DataTableColumnHeader = require_table.DataTableColumnHeader;
5
+ exports.DataTablePagination = require_table.DataTablePagination;
6
+ exports.DataTableToolbar = require_table.DataTableToolbar;
7
+ exports.DataTableViewOptions = require_table.DataTableViewOptions;
8
+ exports.DataTableVirtualBody = require_table.DataTableVirtualBody;
9
+ exports.RowDragHandle = require_table.RowDragHandle;
10
+ exports.RowDragHandleContext = require_table.RowDragHandleContext;
11
+ exports.RowExpandToggle = require_table.RowExpandToggle;
12
+ exports.Table = require_table.Table;
13
+ exports.TableBody = require_table.TableBody;
14
+ exports.TableCaption = require_table.TableCaption;
15
+ exports.TableCell = require_table.TableCell;
16
+ exports.TableFooter = require_table.TableFooter;
17
+ exports.TableHead = require_table.TableHead;
18
+ exports.TableHeader = require_table.TableHeader;
19
+ exports.TableRow = require_table.TableRow;
20
+ exports.computeCellSpans = require_table.computeCellSpans;
21
+ exports.getColumnPinningClassName = require_table.getColumnPinningClassName;
22
+ exports.getCommonPinningStyles = require_table.getCommonPinningStyles;
23
+ exports.panelIdFor = require_table.panelIdFor;
24
+ exports.useDataTable = require_table.useDataTable;
25
+ exports.useScrollShadow = require_table.useScrollShadow;
@@ -1,69 +1,2 @@
1
- "use client";
2
- import { t as cn } from "../utils-Bg4z4cXr.mjs";
3
- import { jsx } from "react/jsx-runtime";
4
- import "react";
5
- //#region src/table/index.tsx
6
- function Table({ className, ...props }) {
7
- return /* @__PURE__ */ jsx("div", {
8
- "data-slot": "table-container",
9
- className: "relative w-full overflow-x-auto",
10
- children: /* @__PURE__ */ jsx("table", {
11
- "data-slot": "table",
12
- className: cn("w-full caption-bottom text-sm", className),
13
- ...props
14
- })
15
- });
16
- }
17
- function TableHeader({ className, ...props }) {
18
- return /* @__PURE__ */ jsx("thead", {
19
- "data-slot": "table-header",
20
- className: cn("[&_tr]:border-b", className),
21
- ...props
22
- });
23
- }
24
- function TableBody({ className, ...props }) {
25
- return /* @__PURE__ */ jsx("tbody", {
26
- "data-slot": "table-body",
27
- className: cn("[&_tr:last-child]:border-0", className),
28
- ...props
29
- });
30
- }
31
- function TableFooter({ className, ...props }) {
32
- return /* @__PURE__ */ jsx("tfoot", {
33
- "data-slot": "table-footer",
34
- className: cn("bg-muted/50 border-t font-medium [&>tr]:last:border-b-0", className),
35
- ...props
36
- });
37
- }
38
- function TableRow({ className, ...props }) {
39
- return /* @__PURE__ */ jsx("tr", {
40
- "data-slot": "table-row",
41
- className: cn("hover:bg-muted/50 data-[state=selected]:bg-muted border-b transition-colors", className),
42
- ...props
43
- });
44
- }
45
- function TableHead({ className, ...props }) {
46
- return /* @__PURE__ */ jsx("th", {
47
- "data-slot": "table-head",
48
- className: cn("text-foreground h-10 whitespace-nowrap px-2 text-left align-middle font-medium [&:has([role=checkbox])]:pr-0", className),
49
- ...props
50
- });
51
- }
52
- function TableCell({ className, ...props }) {
53
- return /* @__PURE__ */ jsx("td", {
54
- "data-slot": "table-cell",
55
- className: cn("whitespace-nowrap p-2 align-middle [&:has([role=checkbox])]:pr-0", className),
56
- ...props
57
- });
58
- }
59
- function TableCaption({ className, ...props }) {
60
- return /* @__PURE__ */ jsx("caption", {
61
- "data-slot": "table-caption",
62
- className: cn("text-muted-foreground mt-4 text-sm", className),
63
- ...props
64
- });
65
- }
66
- //#endregion
67
- export { Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow };
68
-
69
- //# sourceMappingURL=index.mjs.map
1
+ import { C as TableRow, S as TableHeader, _ as TableBody, a as RowDragHandle, b as TableFooter, c as DataTablePagination, d as getColumnPinningClassName, f as getCommonPinningStyles, g as Table, h as useScrollShadow, i as DataTable, l as DataTableColumnHeader, m as useDataTable, n as DataTableToolbar, o as RowDragHandleContext, p as panelIdFor, r as DataTableViewOptions, s as DataTableVirtualBody, t as RowExpandToggle, u as computeCellSpans, v as TableCaption, x as TableHead, y as TableCell } from "../table-BA2BijtZ.mjs";
2
+ export { DataTable, DataTableColumnHeader, DataTablePagination, DataTableToolbar, DataTableViewOptions, DataTableVirtualBody, RowDragHandle, RowDragHandleContext, RowExpandToggle, Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow, computeCellSpans, getColumnPinningClassName, getCommonPinningStyles, panelIdFor, useDataTable, useScrollShadow };
@@ -0,0 +1,198 @@
1
+ import { Column, ColumnDef, ColumnFiltersState, ColumnOrderState, ColumnPinningState, ExpandedState, PaginationState, Row, RowData, RowSelectionState, SortingState, TableOptions, Table as TanstackTable, VisibilityState } from '@tanstack/react-table';
2
+ import { ReactNode } from 'react';
3
+ /** 行合并回调上下文 */
4
+ export type RowSpanContext<TData> = {
5
+ row: Row<TData>;
6
+ rows: Row<TData>[];
7
+ rowIndex: number;
8
+ value: unknown;
9
+ };
10
+ /** 列合并回调上下文 */
11
+ export type ColSpanContext<TData> = {
12
+ row: Row<TData>;
13
+ rows: Row<TData>[];
14
+ rowIndex: number;
15
+ column: Column<TData, unknown>;
16
+ };
17
+ /**
18
+ * 通过 `column.meta` 在 DataTable 中描述单元格合并行为
19
+ *
20
+ * - `rowSpan: true`(等同 `"auto"`):自动合并连续相同值
21
+ * - `rowSpan: (ctx) => number`:返回 rowSpan,`0` 表示该格不渲染
22
+ * - `rowSpanParent`:仅当父字段同时相同才允许合并(如 city 在同 region 下才合并)
23
+ * - `colSpan: (ctx) => number`:返回 colSpan,`0` 表示该格不渲染
24
+ */
25
+ export type CellMergeMeta<TData = RowData> = {
26
+ rowSpan?: true | "auto" | ((ctx: RowSpanContext<TData>) => number);
27
+ rowSpanParent?: string;
28
+ colSpan?: (ctx: ColSpanContext<TData>) => number;
29
+ };
30
+ declare module "@tanstack/react-table" {
31
+ interface ColumnMeta<TData extends RowData, TValue> extends CellMergeMeta<TData> {
32
+ }
33
+ }
34
+ /**
35
+ * 表格容器横向滚动阴影状态
36
+ */
37
+ export type ScrollShadowState = {
38
+ left: boolean;
39
+ right: boolean;
40
+ };
41
+ /**
42
+ * 列配置,扩展 TanStack ColumnDef
43
+ */
44
+ export type DataTableColumn<TData, TValue = unknown> = ColumnDef<TData, TValue>;
45
+ /**
46
+ * 受控状态,所有字段均可选
47
+ */
48
+ export type DataTableState = {
49
+ sorting?: SortingState;
50
+ columnFilters?: ColumnFiltersState;
51
+ columnVisibility?: VisibilityState;
52
+ columnOrder?: ColumnOrderState;
53
+ columnPinning?: ColumnPinningState;
54
+ rowSelection?: RowSelectionState;
55
+ pagination?: PaginationState;
56
+ globalFilter?: string;
57
+ expanded?: ExpandedState;
58
+ };
59
+ /**
60
+ * 状态变更回调集合
61
+ */
62
+ export type DataTableStateHandlers = {
63
+ onSortingChange?: (state: SortingState) => void;
64
+ onColumnFiltersChange?: (state: ColumnFiltersState) => void;
65
+ onColumnVisibilityChange?: (state: VisibilityState) => void;
66
+ onColumnOrderChange?: (state: ColumnOrderState) => void;
67
+ onColumnPinningChange?: (state: ColumnPinningState) => void;
68
+ onRowSelectionChange?: (state: RowSelectionState) => void;
69
+ onPaginationChange?: (state: PaginationState) => void;
70
+ onGlobalFilterChange?: (state: string) => void;
71
+ onExpandedChange?: (state: ExpandedState) => void;
72
+ };
73
+ /**
74
+ * 各能力开关 + 初始值
75
+ */
76
+ export type DataTableFeatures = {
77
+ /** 是否启用排序,默认 true */
78
+ sorting?: boolean;
79
+ /** 是否启用多列同时排序,默认 false */
80
+ multiSort?: boolean;
81
+ /** 是否启用列筛选,默认 true */
82
+ filtering?: boolean;
83
+ /** 是否启用全局搜索,默认 false */
84
+ globalFilter?: boolean;
85
+ /** 是否启用分页,默认 true */
86
+ pagination?: boolean;
87
+ /** 是否启用行选择(多选),默认 false */
88
+ rowSelection?: boolean;
89
+ /** 是否启用列显隐控制,默认 true */
90
+ columnVisibility?: boolean;
91
+ /** 是否启用列拖拽排序,默认 false */
92
+ columnOrdering?: boolean;
93
+ /** 是否启用列固定(冻结),默认 false */
94
+ columnPinning?: boolean;
95
+ /** 是否启用列宽调整,默认 false */
96
+ columnResizing?: boolean;
97
+ /**
98
+ * 是否启用行拖拽排序,默认 false
99
+ *
100
+ * 开启后会在最左侧自动插入一列拖拽手柄;也可手动在自己的 cell 里放 `<RowDragHandle />`。
101
+ * 需要传 `tableOptions.getRowId` 提供稳定的行标识,并在 `onRowOrderChange` 中接住新顺序。
102
+ * 与 `virtual` 不兼容
103
+ */
104
+ rowDnd?: boolean;
105
+ /**
106
+ * 是否启用行展开,默认 false
107
+ *
108
+ * 嵌套树:在 `tableOptions.getSubRows` 中返回子行,即可在 cell 里用 `<RowExpandToggle row={row} />` 展开。
109
+ * 展开面板:传 `expandedRowRender` 在每行下方渲染自定义面板。
110
+ * 开启 `virtual` 时会被自动忽略
111
+ */
112
+ expanding?: boolean;
113
+ };
114
+ /** 行拖拽完成后的回调 */
115
+ export type RowOrderChangeInfo = {
116
+ oldIndex: number;
117
+ newIndex: number;
118
+ activeId: string;
119
+ overId: string;
120
+ };
121
+ /**
122
+ * 行虚拟滚动配置
123
+ */
124
+ export type DataTableVirtualOptions = {
125
+ /** 估计的行高(px),默认 36 */
126
+ estimateRowHeight?: number;
127
+ /** 滚动容器高度,默认 480 */
128
+ maxHeight?: number | string;
129
+ /** 视口外预渲染行数,默认 10 */
130
+ overscan?: number;
131
+ };
132
+ /**
133
+ * DataTable 顶层属性
134
+ */
135
+ export type DataTablePropsType<TData, TValue = unknown> = {
136
+ /** 列定义 */
137
+ columns: DataTableColumn<TData, TValue>[];
138
+ /** 数据源 */
139
+ data: TData[];
140
+ /** 加载状态,显示占位条 */
141
+ loading?: boolean;
142
+ /** 受控状态 */
143
+ state?: DataTableState;
144
+ /** 初始状态(非受控) */
145
+ initialState?: DataTableState;
146
+ /** 状态变更回调 */
147
+ onStateChange?: DataTableStateHandlers;
148
+ /** 功能开关 */
149
+ features?: DataTableFeatures;
150
+ /**
151
+ * 工具栏渲染函数,接收 table 实例;不传则不渲染工具栏
152
+ *
153
+ * 搜索 / 视图设置等控件请在此函数中用 `DataTableToolbar` / `DataTableViewOptions` 自由组合
154
+ */
155
+ renderToolbar?: (table: TanstackTable<TData>) => ReactNode;
156
+ /** 自定义分页区域 */
157
+ renderPagination?: (table: TanstackTable<TData>) => ReactNode;
158
+ /** 空状态文本或节点 */
159
+ empty?: ReactNode;
160
+ /** 每页可选数量,默认 [10, 20, 30, 50, 100] */
161
+ pageSizeOptions?: number[];
162
+ /** 外层 className */
163
+ className?: string;
164
+ /** 表格容器 className */
165
+ tableClassName?: string;
166
+ /** 是否显示纵向边框(单元格分隔线),默认 `false` */
167
+ bordered?: boolean;
168
+ /** 行点击回调 */
169
+ onRowClick?: (row: TData) => void;
170
+ /** 行拖拽完成后回调,接收重排后的完整数据 */
171
+ onRowOrderChange?: (nextData: TData[], info: RowOrderChangeInfo) => void;
172
+ /**
173
+ * 自定义展开面板渲染;返回任意节点会在该行下方渲染一行,跨满所有列
174
+ *
175
+ * - 需要将 `features.expanding` 设为 true 才会生效
176
+ * - 未自定义 `tableOptions.getRowCanExpand` 时会自动注入 `() => true`,所有行均可展开
177
+ * - 开启 `virtual` 时会被自动忽略
178
+ */
179
+ expandedRowRender?: (row: Row<TData>) => ReactNode;
180
+ /**
181
+ * 行 DnD 拖拽手柄安放方式,默认 `"auto"` 自动在最左侧追加一列
182
+ *
183
+ * 设为 `"manual"` 则不追加,需要用户在自己的列里放 `<RowDragHandle />`
184
+ */
185
+ rowDndHandle?: "auto" | "manual";
186
+ /** 透传至底层 useReactTable 的额外配置(服务端模式 / meta 等) */
187
+ tableOptions?: Partial<TableOptions<TData>>;
188
+ /**
189
+ * 行虚拟滚动:`true` 启用默认配置;传对象自定义
190
+ *
191
+ * 开启后会自动关闭分页;列固定与多级表头暂不兼容
192
+ */
193
+ virtual?: boolean | DataTableVirtualOptions;
194
+ };
195
+ /**
196
+ * 列固定 / 拖拽辅助类型
197
+ */
198
+ export type AnyColumn<TData> = Column<TData, unknown>;
@@ -0,0 +1,31 @@
1
+ import { Row } from '@tanstack/react-table';
2
+ import { CSSProperties } from 'react';
3
+ import { AnyColumn, ScrollShadowState } from './type';
4
+ /**
5
+ * 展开面板 row 的 DOM id 协议
6
+ *
7
+ * `DataTable` 渲染面板 row 时把这个 id 设到 `<tr id>` 上,
8
+ * `RowExpandToggle` 把它写进按钮的 `aria-controls`,二者必须保持一致
9
+ */
10
+ export declare const panelIdFor: (rowId: string) => string;
11
+ /**
12
+ * 计算固定列(sticky)需要的样式
13
+ */
14
+ export declare function getCommonPinningStyles<TData>(column: AnyColumn<TData>): CSSProperties;
15
+ /**
16
+ * 计算固定列阴影 className
17
+ */
18
+ export declare function getColumnPinningClassName<TData>(column: AnyColumn<TData>, scrollShadow: ScrollShadowState): string;
19
+ /** 单元格合并跨度 */
20
+ export type CellSpan = {
21
+ rowSpan: number;
22
+ colSpan: number;
23
+ };
24
+ /** 内部存储:每行每列对应的跨度 */
25
+ export type CellSpanMap = Map<number, Map<string, CellSpan>>;
26
+ /**
27
+ * 根据每列 `meta.rowSpan` / `meta.colSpan` 计算每行每列的合并跨度
28
+ *
29
+ * `0` 表示该单元格不应渲染(被合并掉了)
30
+ */
31
+ export declare function computeCellSpans<TData>(rows: Row<TData>[], columns: AnyColumn<TData>[]): CellSpanMap;