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