@kopexa/data-grid 0.0.0-canary-20250921225330

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.
@@ -0,0 +1,39 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { DataGridVariants } from '@kopexa/theme';
3
+ import { RowData, Table, Row } from '@tanstack/react-table';
4
+ import { ReactNode } from 'react';
5
+
6
+ declare module "@tanstack/react-table" {
7
+ interface ColumnMeta<TData extends RowData, TValue> {
8
+ headerTitle?: string;
9
+ headerClassName?: string;
10
+ cellClassName?: string;
11
+ skeleton?: ReactNode;
12
+ expandedContent?: (row: TData) => ReactNode;
13
+ }
14
+ }
15
+ type BaseProps<TData extends object> = {
16
+ table: Table<TData>;
17
+ emptyMessage?: string;
18
+ isLoading?: boolean;
19
+ pageSize?: number;
20
+ };
21
+ type DataGridProps<TData extends object> = BaseProps<TData> & DataGridVariants & {
22
+ children?: ReactNode;
23
+ };
24
+ declare function DataGrid<TData extends object>(props: DataGridProps<TData>): react_jsx_runtime.JSX.Element;
25
+ declare function DataGridContainer({ children, className, }: {
26
+ children: ReactNode;
27
+ className?: string;
28
+ border?: boolean;
29
+ }): react_jsx_runtime.JSX.Element;
30
+ declare function DataGridTable<TData>(): react_jsx_runtime.JSX.Element;
31
+ declare function DataGridTableRowSelectAll({ size, }: {
32
+ size?: "sm" | "md" | "lg";
33
+ }): react_jsx_runtime.JSX.Element;
34
+ declare function DataGridTableRowSelect<TData>({ row, size, }: {
35
+ row: Row<TData>;
36
+ size?: "sm" | "md" | "lg";
37
+ }): react_jsx_runtime.JSX.Element;
38
+
39
+ export { DataGrid, DataGridContainer, type DataGridProps, DataGridTable, DataGridTableRowSelect, DataGridTableRowSelectAll };
@@ -0,0 +1,420 @@
1
+ "use client";
2
+ "use strict";
3
+ "use client";
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21
+
22
+ // src/data-grid.tsx
23
+ var data_grid_exports = {};
24
+ __export(data_grid_exports, {
25
+ DataGrid: () => DataGrid,
26
+ DataGridContainer: () => DataGridContainer,
27
+ DataGridTable: () => DataGridTable,
28
+ DataGridTableRowSelect: () => DataGridTableRowSelect,
29
+ DataGridTableRowSelectAll: () => DataGridTableRowSelectAll
30
+ });
31
+ module.exports = __toCommonJS(data_grid_exports);
32
+ var import_checkbox = require("@kopexa/checkbox");
33
+ var import_react_utils = require("@kopexa/react-utils");
34
+ var import_shared_utils = require("@kopexa/shared-utils");
35
+ var import_theme = require("@kopexa/theme");
36
+ var import_react_table = require("@tanstack/react-table");
37
+ var import_react = require("react");
38
+ var import_jsx_runtime = require("react/jsx-runtime");
39
+ var [DataGridProvider, useDataGridContext] = (
40
+ // biome-ignore lint/suspicious/noExplicitAny: no idea.
41
+ (0, import_react_utils.createContext)()
42
+ );
43
+ function DataGrid(props) {
44
+ const {
45
+ children,
46
+ table,
47
+ columnsResizable = import_theme.datagrid.defaultVariants.columnsResizable,
48
+ columnsDraggable,
49
+ columnsPinnable,
50
+ stripped,
51
+ border = import_theme.datagrid.defaultVariants.border,
52
+ rowBorder = import_theme.datagrid.defaultVariants.rowBorder,
53
+ dense = import_theme.datagrid.defaultVariants.dense,
54
+ rowRounded = import_theme.datagrid.defaultVariants.rowRounded,
55
+ headerBackground = import_theme.datagrid.defaultVariants.headerBackground,
56
+ width = import_theme.datagrid.defaultVariants.width,
57
+ loadingMode,
58
+ emptyMessage,
59
+ isLoading = false,
60
+ pageSize = 20,
61
+ cellBorder,
62
+ ...rest
63
+ } = props;
64
+ const styles = (0, import_theme.datagrid)({
65
+ border,
66
+ columnsResizable,
67
+ columnsDraggable,
68
+ columnsPinnable,
69
+ headerBackground,
70
+ stripped,
71
+ rowBorder,
72
+ loadingMode,
73
+ cellBorder,
74
+ rowRounded,
75
+ width,
76
+ dense
77
+ });
78
+ if (!table) {
79
+ throw new Error('DataGrid requires a "table" prop');
80
+ }
81
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
82
+ DataGridProvider,
83
+ {
84
+ value: {
85
+ table,
86
+ styles,
87
+ columnsResizable,
88
+ columnsDraggable,
89
+ columnsPinnable,
90
+ stripped,
91
+ rowBorder,
92
+ loadingMode,
93
+ emptyMessage,
94
+ isLoading,
95
+ pageSize
96
+ },
97
+ ...rest,
98
+ children
99
+ }
100
+ );
101
+ }
102
+ function DataGridContainer({
103
+ children,
104
+ className
105
+ }) {
106
+ const { styles } = useDataGridContext();
107
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { "data-slot": "data-grid", className: (0, import_shared_utils.cn)(styles.container({ className })), children });
108
+ }
109
+ function DataGridTableHead({
110
+ children,
111
+ className,
112
+ ...restProps
113
+ }) {
114
+ const { styles } = useDataGridContext();
115
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("thead", { className: styles.head({ className }), ...restProps, children });
116
+ }
117
+ function DataGridTableHeadRow({
118
+ children,
119
+ headerGroup,
120
+ className,
121
+ ...restProps
122
+ }) {
123
+ const { styles } = useDataGridContext();
124
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
125
+ "tr",
126
+ {
127
+ className: styles.headerRow({ className }),
128
+ ...restProps,
129
+ children
130
+ },
131
+ headerGroup.id
132
+ );
133
+ }
134
+ function DataGridTableBase({
135
+ children,
136
+ className,
137
+ ...restProps
138
+ }) {
139
+ const { styles } = useDataGridContext();
140
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
141
+ "table",
142
+ {
143
+ "data-slot": "data-grid-table",
144
+ className: styles.table({ className }),
145
+ ...restProps,
146
+ children
147
+ }
148
+ );
149
+ }
150
+ function DataGridTableHeadRowCell({
151
+ children,
152
+ header,
153
+ dndRef
154
+ }) {
155
+ var _a;
156
+ const { styles } = useDataGridContext();
157
+ const { column } = header;
158
+ const isPinned = column.getIsPinned();
159
+ const isLastLeftPinned = isPinned === "left" && column.getIsLastColumn("left");
160
+ const isFirstRightPinned = isPinned === "right" && column.getIsFirstColumn("right");
161
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
162
+ "th",
163
+ {
164
+ ref: dndRef,
165
+ style: {
166
+ "--size": `${header.getSize()}px`
167
+ },
168
+ "data-pinned": isPinned || void 0,
169
+ "data-last-col": isLastLeftPinned ? "left" : isFirstRightPinned ? "right" : void 0,
170
+ className: (0, import_shared_utils.cn)(
171
+ styles.headerRowCell(),
172
+ (_a = header.column.columnDef.meta) == null ? void 0 : _a.headerClassName
173
+ ),
174
+ children
175
+ },
176
+ header.id
177
+ );
178
+ }
179
+ function DataGridTableRowSpacer() {
180
+ const { styles } = useDataGridContext();
181
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("tbody", { "aria-hidden": "true", className: styles.rowSpacer() });
182
+ }
183
+ function DataGridTableHeadRowCellResize({
184
+ header
185
+ }) {
186
+ const { column } = header;
187
+ const { styles } = useDataGridContext();
188
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
189
+ "div",
190
+ {
191
+ ...{
192
+ onDoubleClick: () => column.resetSize(),
193
+ onMouseDown: header.getResizeHandler(),
194
+ onTouchStart: header.getResizeHandler(),
195
+ className: styles.headRowCellResize()
196
+ }
197
+ }
198
+ );
199
+ }
200
+ function DataGridTableBody({
201
+ children,
202
+ className,
203
+ ...restProps
204
+ }) {
205
+ const { styles } = useDataGridContext();
206
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("tbody", { className: (0, import_shared_utils.cn)(styles.body({ className })), ...restProps, children });
207
+ }
208
+ function DataGridTableEmpty() {
209
+ const { styles, table, emptyMessage } = useDataGridContext();
210
+ const totalColumns = table.getAllColumns().length;
211
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("tr", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", { colSpan: totalColumns, className: styles.empty(), children: emptyMessage || "No data available." }) });
212
+ }
213
+ function DataGridTableBodyRowSkeleton({ children }) {
214
+ const { table, styles } = useDataGridContext();
215
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
216
+ "tr",
217
+ {
218
+ className: (0, import_shared_utils.cn)(
219
+ styles.bodyRowSkeleton,
220
+ // props.onRowClick && 'cursor-pointer',
221
+ table.options.enableRowSelection && "[&_>:first-child]:relative"
222
+ ),
223
+ children
224
+ }
225
+ );
226
+ }
227
+ function DataGridTableBodyRowCell({
228
+ children,
229
+ cell,
230
+ dndRef,
231
+ dndStyle
232
+ }) {
233
+ var _a;
234
+ const { styles, columnsResizable, columnsDraggable, columnsPinnable } = useDataGridContext();
235
+ const { column } = cell;
236
+ const isPinned = column.getIsPinned();
237
+ const isLastLeftPinned = isPinned === "left" && column.getIsLastColumn("left");
238
+ const isFirstRightPinned = isPinned === "right" && column.getIsFirstColumn("right");
239
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
240
+ "td",
241
+ {
242
+ ref: dndRef,
243
+ ...columnsDraggable && !isPinned ? { cell } : {},
244
+ style: {
245
+ ...columnsPinnable && column.getCanPin() && getPinningStyles(column),
246
+ ...dndStyle ? dndStyle : null
247
+ },
248
+ "data-pinned": isPinned || void 0,
249
+ "data-last-col": isLastLeftPinned ? "left" : isFirstRightPinned ? "right" : void 0,
250
+ className: (0, import_shared_utils.cn)(
251
+ styles.bodyRowCell(),
252
+ columnsResizable && column.getCanResize() && "truncate",
253
+ (_a = cell.column.columnDef.meta) == null ? void 0 : _a.cellClassName,
254
+ columnsPinnable && column.getCanPin() && '[&[data-pinned=left][data-last-col=left]]:border-e! [&[data-pinned=right][data-last-col=right]]:border-s! [&[data-pinned][data-last-col]]:border-border data-pinned:bg-background/90 data-pinned:backdrop-blur-xs"'
255
+ // column.getIndex() === 0 || column.getIndex() === row.getVisibleCells().length - 1
256
+ // ? props.tableClassNames?.edgeCell
257
+ // : '',
258
+ ),
259
+ children
260
+ },
261
+ cell.id
262
+ );
263
+ }
264
+ function DataGridTableBodyRowSkeletonCell({
265
+ children,
266
+ column
267
+ }) {
268
+ var _a;
269
+ const { styles, columnsResizable, columnsPinnable } = useDataGridContext();
270
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
271
+ "td",
272
+ {
273
+ className: (0, import_shared_utils.cn)(
274
+ styles.bodyRowSkeletonCell(),
275
+ columnsResizable && column.getCanResize() && "truncate",
276
+ (_a = column.columnDef.meta) == null ? void 0 : _a.cellClassName,
277
+ columnsPinnable && column.getCanPin() && '[&[data-pinned=left][data-last-col=left]]:border-e! [&[data-pinned=right][data-last-col=right]]:border-s! [&[data-pinned][data-last-col]]:border-border data-pinned:bg-background/90 data-pinned:backdrop-blur-xs"'
278
+ // column.getIndex() === 0 || column.getIndex() === table.getVisibleFlatColumns().length - 1
279
+ // ? props.tableClassNames?.edgeCell
280
+ // : '',
281
+ ),
282
+ children
283
+ }
284
+ );
285
+ }
286
+ function DataGridTableBodyRow({
287
+ children,
288
+ row,
289
+ dndRef,
290
+ dndStyle
291
+ }) {
292
+ const { styles, table } = useDataGridContext();
293
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
294
+ "tr",
295
+ {
296
+ ref: dndRef,
297
+ style: { ...dndStyle ? dndStyle : null },
298
+ "data-state": table.options.enableRowSelection && row.getIsSelected() ? "selected" : void 0,
299
+ className: (0, import_shared_utils.cn)(
300
+ styles.bodyRow(),
301
+ //props.onRowClick && 'cursor-pointer',
302
+ table.options.enableRowSelection && "[&_>:first-child]:relative"
303
+ ),
304
+ children
305
+ }
306
+ );
307
+ }
308
+ function DataGridTableBodyRowExpanded({ row }) {
309
+ var _a, _b, _c;
310
+ const { table, styles } = useDataGridContext();
311
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("tr", { className: styles.bodyRowExpanded(), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("td", { colSpan: row.getVisibleCells().length, children: (_c = (_b = (_a = table.getAllColumns().find((column) => {
312
+ var _a2;
313
+ return (_a2 = column.columnDef.meta) == null ? void 0 : _a2.expandedContent;
314
+ })) == null ? void 0 : _a.columnDef.meta) == null ? void 0 : _b.expandedContent) == null ? void 0 : _c.call(_b, row.original) }) });
315
+ }
316
+ function DataGridTable() {
317
+ const {
318
+ table,
319
+ columnsResizable,
320
+ stripped,
321
+ rowBorder,
322
+ loadingMode,
323
+ isLoading,
324
+ pageSize
325
+ } = useDataGridContext();
326
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DataGridTableBase, { children: [
327
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DataGridTableHead, { children: table.getHeaderGroups().map((headerGroup) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DataGridTableHeadRow, { headerGroup, children: headerGroup.headers.map((header) => {
328
+ const { column } = header;
329
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DataGridTableHeadRowCell, { header, children: [
330
+ header.isPlaceholder ? null : (0, import_react_table.flexRender)(
331
+ header.column.columnDef.header,
332
+ header.getContext()
333
+ ),
334
+ columnsResizable && column.getCanResize() && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DataGridTableHeadRowCellResize, { header })
335
+ ] }, column.id);
336
+ }) }, headerGroup.id)) }),
337
+ (stripped || !rowBorder) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DataGridTableRowSpacer, {}),
338
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DataGridTableBody, { children: loadingMode === "skeleton" && isLoading && pageSize ? Array.from({ length: pageSize }).map((_, rowIndex) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DataGridTableBodyRowSkeleton, { children: table.getVisibleFlatColumns().map((column, colIndex) => {
339
+ var _a;
340
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
341
+ DataGridTableBodyRowSkeletonCell,
342
+ {
343
+ column,
344
+ children: (_a = column.columnDef.meta) == null ? void 0 : _a.skeleton
345
+ },
346
+ colIndex.toString()
347
+ );
348
+ }) }, rowIndex.toString())) : table.getRowModel().rows.length ? table.getRowModel().rows.map((row) => {
349
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_react.Fragment, { children: [
350
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DataGridTableBodyRow, { row, children: row.getVisibleCells().map((cell) => {
351
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DataGridTableBodyRowCell, { cell, children: (0, import_react_table.flexRender)(
352
+ cell.column.columnDef.cell,
353
+ cell.getContext()
354
+ ) }, cell.id);
355
+ }) }, row.id),
356
+ row.getIsExpanded() && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DataGridTableBodyRowExpanded, { row })
357
+ ] }, row.id);
358
+ }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DataGridTableEmpty, {}) })
359
+ ] });
360
+ }
361
+ function getPinningStyles(column) {
362
+ const isPinned = column.getIsPinned();
363
+ return {
364
+ left: isPinned === "left" ? `${column.getStart("left")}px` : void 0,
365
+ right: isPinned === "right" ? `${column.getAfter("right")}px` : void 0,
366
+ position: isPinned ? "sticky" : "relative",
367
+ width: column.getSize(),
368
+ zIndex: isPinned ? 1 : 0
369
+ };
370
+ }
371
+ function DataGridTableRowSelectAll({
372
+ size
373
+ }) {
374
+ const { table, isLoading } = useDataGridContext();
375
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
376
+ import_checkbox.Checkbox,
377
+ {
378
+ checked: table.getIsAllPageRowsSelected() || table.getIsSomePageRowsSelected() && "indeterminate",
379
+ disabled: isLoading || table.getRowModel().rows.length === 0,
380
+ onCheckedChange: (value) => table.toggleAllPageRowsSelected(!!value),
381
+ "aria-label": "Select all",
382
+ size,
383
+ className: "align-[inherit]"
384
+ }
385
+ );
386
+ }
387
+ function DataGridTableRowSelect({
388
+ row,
389
+ size
390
+ }) {
391
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
392
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
393
+ "div",
394
+ {
395
+ className: (0, import_shared_utils.cn)(
396
+ "hidden absolute top-0 bottom-0 start-0 w-[2px] bg-primary",
397
+ row.getIsSelected() && "block"
398
+ )
399
+ }
400
+ ),
401
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
402
+ import_checkbox.Checkbox,
403
+ {
404
+ checked: row.getIsSelected(),
405
+ onCheckedChange: (value) => row.toggleSelected(!!value),
406
+ "aria-label": "Select row",
407
+ size: size != null ? size : "sm",
408
+ className: "align-[inherit]"
409
+ }
410
+ )
411
+ ] });
412
+ }
413
+ // Annotate the CommonJS export names for ESM import in node:
414
+ 0 && (module.exports = {
415
+ DataGrid,
416
+ DataGridContainer,
417
+ DataGridTable,
418
+ DataGridTableRowSelect,
419
+ DataGridTableRowSelectAll
420
+ });
@@ -0,0 +1,16 @@
1
+ "use client";
2
+ "use client";
3
+ import {
4
+ DataGrid,
5
+ DataGridContainer,
6
+ DataGridTable,
7
+ DataGridTableRowSelect,
8
+ DataGridTableRowSelectAll
9
+ } from "./chunk-XYG65G3U.mjs";
10
+ export {
11
+ DataGrid,
12
+ DataGridContainer,
13
+ DataGridTable,
14
+ DataGridTableRowSelect,
15
+ DataGridTableRowSelectAll
16
+ };
@@ -0,0 +1,15 @@
1
+ import { DataGrid as DataGrid$1, DataGridContainer, DataGridTable, DataGridTableRowSelectAll, DataGridTableRowSelect } from './data-grid.mjs';
2
+ export { DataGridProps } from './data-grid.mjs';
3
+ import 'react/jsx-runtime';
4
+ import '@kopexa/theme';
5
+ import '@tanstack/react-table';
6
+ import 'react';
7
+
8
+ declare const DataGrid: typeof DataGrid$1 & {
9
+ Container: typeof DataGridContainer;
10
+ Table: typeof DataGridTable;
11
+ SelectAll: typeof DataGridTableRowSelectAll;
12
+ RowSelect: typeof DataGridTableRowSelect;
13
+ };
14
+
15
+ export { DataGrid };
@@ -0,0 +1,15 @@
1
+ import { DataGrid as DataGrid$1, DataGridContainer, DataGridTable, DataGridTableRowSelectAll, DataGridTableRowSelect } from './data-grid.js';
2
+ export { DataGridProps } from './data-grid.js';
3
+ import 'react/jsx-runtime';
4
+ import '@kopexa/theme';
5
+ import '@tanstack/react-table';
6
+ import 'react';
7
+
8
+ declare const DataGrid: typeof DataGrid$1 & {
9
+ Container: typeof DataGridContainer;
10
+ Table: typeof DataGridTable;
11
+ SelectAll: typeof DataGridTableRowSelectAll;
12
+ RowSelect: typeof DataGridTableRowSelect;
13
+ };
14
+
15
+ export { DataGrid };