react-glide-table 1.1.0 → 1.1.2

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,2067 @@
1
+ // src/components/ui/table/components/DataTable/DataTable.tsx
2
+ import { flexRender as flexRender2 } from "@tanstack/react-table";
3
+
4
+ // src/components/ui/table/components/DataTable/DataTableRow.tsx
5
+ import { flexRender } from "@tanstack/react-table";
6
+ import { useEffect as useEffect2, useRef as useRef2 } from "react";
7
+
8
+ // src/components/ui/table/constants.ts
9
+ var CELL_ALIGN_CLASS = {
10
+ left: "cell-align-left",
11
+ center: "cell-align-center",
12
+ right: "cell-align-right"
13
+ };
14
+ var ROW_HOVER_CLASS = "row-hoverable";
15
+ var ROW_HOVERED_BG_CLASS = "row-hovered";
16
+ var CELL_SELECTION_FILL_CLASS = "cell-selection-fill";
17
+ var DATA_TABLE_ROW_HEIGHT = 44;
18
+ var DATA_TABLE_VIRTUAL_OVERSCAN = 8;
19
+
20
+ // src/components/ui/table/DataTableContext.tsx
21
+ import { createContext, use } from "react";
22
+ import { jsx } from "react/jsx-runtime";
23
+ var DataTableContext = createContext(null);
24
+ function useDataTableRowContext() {
25
+ const context = use(DataTableContext);
26
+ if (!context) {
27
+ throw new Error("useDataTableRowContext must be used within a DataTableContextProvider");
28
+ }
29
+ return context;
30
+ }
31
+ function DataTableContextProvider({
32
+ value,
33
+ children
34
+ }) {
35
+ return /* @__PURE__ */ jsx(DataTableContext, { value, children });
36
+ }
37
+
38
+ // src/components/ui/table/features/cell-edit/cellEdit.ts
39
+ function getColumnAccessorKey(columnDef) {
40
+ if (columnDef.accessorKey !== void 0 && columnDef.accessorKey !== null) {
41
+ return String(columnDef.accessorKey);
42
+ }
43
+ return columnDef.id;
44
+ }
45
+ function isColumnEditable(columnDef) {
46
+ return Boolean(columnDef.meta?.editable);
47
+ }
48
+ function getColumnEditType(columnDef) {
49
+ return columnDef.meta?.editType ?? "text";
50
+ }
51
+ function parseCellEditValue(raw, editType) {
52
+ if (editType === "text") {
53
+ return { ok: true, value: raw };
54
+ }
55
+ const trimmed = raw.trim();
56
+ if (trimmed === "") {
57
+ return { ok: true, value: null };
58
+ }
59
+ const parsed = Number(trimmed);
60
+ if (Number.isNaN(parsed)) {
61
+ return { ok: false };
62
+ }
63
+ return { ok: true, value: parsed };
64
+ }
65
+ function getCellEditDraftValue(value) {
66
+ if (value === null || value === void 0) return "";
67
+ return String(value);
68
+ }
69
+ function applyCellEdit(data, rows, rowIndex, colIndex, raw) {
70
+ const cell = rows[rowIndex]?.getVisibleCells()[colIndex];
71
+ if (!cell) return null;
72
+ const columnDef = cell.column.columnDef;
73
+ if (!isColumnEditable(columnDef)) return null;
74
+ const accessorKey = getColumnAccessorKey(columnDef);
75
+ if (!accessorKey) return null;
76
+ const parsed = parseCellEditValue(raw, getColumnEditType(columnDef));
77
+ if (!parsed.ok) return null;
78
+ const newData = data.map((row) => ({ ...row }));
79
+ if (!newData[rowIndex]) return null;
80
+ newData[rowIndex][accessorKey] = parsed.value;
81
+ return newData;
82
+ }
83
+
84
+ // src/components/ui/table/features/cell-selection/cellSelection.ts
85
+ var INITIAL_DRAG_STATE = {
86
+ isSelecting: false,
87
+ isFillDragging: false,
88
+ start: null,
89
+ end: null,
90
+ fillAnchor: null,
91
+ fillEnd: null
92
+ };
93
+ function getCellSelectionBounds(start, end) {
94
+ if (!start || !end) return null;
95
+ return {
96
+ startRow: Math.min(start.row, end.row),
97
+ endRow: Math.max(start.row, end.row),
98
+ startCol: Math.min(start.col, end.col),
99
+ endCol: Math.max(start.col, end.col)
100
+ };
101
+ }
102
+ function getRowIndexInMergedCell(clientY, cellElement, rowIndex, rowSpan) {
103
+ if (rowSpan <= 1) return rowIndex;
104
+ const rect = cellElement.getBoundingClientRect();
105
+ const relativeY = clientY - rect.top;
106
+ const rowHeight = rect.height / rowSpan;
107
+ const offset = Math.min(
108
+ Math.max(Math.floor(relativeY / rowHeight), 0),
109
+ rowSpan - 1
110
+ );
111
+ return rowIndex + offset;
112
+ }
113
+ function isCellInSelection(rowIndex, colIndex, bounds, rowSpan = 1) {
114
+ if (!bounds) return false;
115
+ const cellEndRow = rowIndex + rowSpan - 1;
116
+ return cellEndRow >= bounds.startRow && rowIndex <= bounds.endRow && colIndex >= bounds.startCol && colIndex <= bounds.endCol;
117
+ }
118
+ function getActiveSelectionBounds(dragState, selectionBounds) {
119
+ if (dragState.isFillDragging && dragState.fillAnchor && dragState.fillEnd) {
120
+ return getCellSelectionBounds(dragState.fillAnchor, dragState.fillEnd);
121
+ }
122
+ return selectionBounds;
123
+ }
124
+ var SELECTION_EDGE_WIDTH_PX = 2;
125
+ var SELECTION_EDGE_COLOR = "var(--color-brand-primary)";
126
+ var CELL_SELECTION_EDGES_CLASS = "cell-selection-edges";
127
+ function getMergedCellStepEdges(rowIndex, colIndex, bounds, rowSpan, isVisuallySelectedAt) {
128
+ const cellEndRow = rowIndex + rowSpan - 1;
129
+ const span = cellEndRow - rowIndex + 1;
130
+ if (span <= 1) return [];
131
+ const edges = [];
132
+ const isNeighborSelected = (row, neighborCol) => {
133
+ if (isVisuallySelectedAt) {
134
+ return isVisuallySelectedAt(row, neighborCol);
135
+ }
136
+ return row >= bounds.startRow && row <= bounds.endRow && neighborCol >= bounds.startCol && neighborCol <= bounds.endCol;
137
+ };
138
+ const pushUnselectedRuns = (side, neighborCol, fromRow, toRowExclusive) => {
139
+ let runStart = null;
140
+ for (let row = fromRow; row < toRowExclusive; row++) {
141
+ if (!isNeighborSelected(row, neighborCol)) {
142
+ if (runStart === null) runStart = row;
143
+ continue;
144
+ }
145
+ if (runStart !== null) {
146
+ edges.push({
147
+ side,
148
+ offsetRatio: (runStart - rowIndex) / span,
149
+ heightRatio: (row - runStart) / span
150
+ });
151
+ runStart = null;
152
+ }
153
+ }
154
+ if (runStart !== null) {
155
+ edges.push({
156
+ side,
157
+ offsetRatio: (runStart - rowIndex) / span,
158
+ heightRatio: (toRowExclusive - runStart) / span
159
+ });
160
+ }
161
+ };
162
+ const collectSide = (side, neighborCol) => {
163
+ if (bounds.startRow > rowIndex) {
164
+ pushUnselectedRuns(
165
+ side,
166
+ neighborCol,
167
+ rowIndex,
168
+ Math.min(bounds.startRow, cellEndRow + 1)
169
+ );
170
+ }
171
+ if (bounds.endRow < cellEndRow) {
172
+ pushUnselectedRuns(
173
+ side,
174
+ neighborCol,
175
+ Math.max(bounds.endRow + 1, rowIndex),
176
+ cellEndRow + 1
177
+ );
178
+ }
179
+ };
180
+ if (colIndex < bounds.endCol) {
181
+ collectSide("right", colIndex + 1);
182
+ }
183
+ if (colIndex > bounds.startCol) {
184
+ collectSide("left", colIndex - 1);
185
+ }
186
+ return edges;
187
+ }
188
+ function buildPartialVerticalGradient(edge) {
189
+ const startPct = edge.offsetRatio * 100;
190
+ const endPct = (edge.offsetRatio + edge.heightRatio) * 100;
191
+ const overlapPx = SELECTION_EDGE_WIDTH_PX + 1;
192
+ const isTopProtrusion = edge.offsetRatio === 0 && edge.heightRatio < 1;
193
+ const isBottomProtrusion = edge.offsetRatio > 0;
194
+ const startStop = isBottomProtrusion ? `calc(${startPct}% - ${overlapPx}px)` : `${startPct}%`;
195
+ const endStop = isTopProtrusion ? `calc(${endPct}% + ${overlapPx}px)` : `${endPct}%`;
196
+ const xPos = edge.side === "left" ? "0" : "100%";
197
+ const layers = [
198
+ {
199
+ image: `linear-gradient(to bottom, transparent 0%, transparent ${startStop}, ${SELECTION_EDGE_COLOR} ${startStop}, ${SELECTION_EDGE_COLOR} ${endStop}, transparent ${endStop}, transparent 100%)`,
200
+ size: `${SELECTION_EDGE_WIDTH_PX}px 100%`,
201
+ position: `${xPos} 0`
202
+ }
203
+ ];
204
+ if (isTopProtrusion || isBottomProtrusion) {
205
+ const capTop = isTopProtrusion ? `calc(${endPct}% - ${SELECTION_EDGE_WIDTH_PX}px)` : `calc(${startPct}% - ${SELECTION_EDGE_WIDTH_PX}px)`;
206
+ layers.push({
207
+ image: `linear-gradient(${SELECTION_EDGE_COLOR}, ${SELECTION_EDGE_COLOR})`,
208
+ size: `${SELECTION_EDGE_WIDTH_PX}px ${SELECTION_EDGE_WIDTH_PX}px`,
209
+ position: `${xPos} ${capTop}`
210
+ });
211
+ }
212
+ return layers;
213
+ }
214
+ function getCellSelectionEdgeStyle(rowIndex, colIndex, bounds, rowSpan = 1, isVisuallySelectedAt) {
215
+ if (!isCellInSelection(rowIndex, colIndex, bounds, rowSpan) || !bounds)
216
+ return void 0;
217
+ const cellEndRow = rowIndex + rowSpan - 1;
218
+ const isTopEdge = bounds.startRow >= rowIndex && bounds.startRow <= cellEndRow;
219
+ const isBottomEdge = bounds.endRow >= rowIndex && bounds.endRow <= cellEndRow;
220
+ const isLeftEdge = colIndex === bounds.startCol;
221
+ const isRightEdge = colIndex === bounds.endCol;
222
+ const selectionContinuesBelow = cellEndRow < bounds.endRow;
223
+ const shadows = [];
224
+ if (isTopEdge) {
225
+ shadows.push(
226
+ `inset 0 ${SELECTION_EDGE_WIDTH_PX}px 0 0 ${SELECTION_EDGE_COLOR}`
227
+ );
228
+ }
229
+ if (isBottomEdge) {
230
+ shadows.push(
231
+ `inset 0 -${SELECTION_EDGE_WIDTH_PX}px 0 0 ${SELECTION_EDGE_COLOR}`
232
+ );
233
+ }
234
+ if (isLeftEdge) {
235
+ shadows.push(
236
+ `inset ${SELECTION_EDGE_WIDTH_PX}px 0 0 0 ${SELECTION_EDGE_COLOR}`
237
+ );
238
+ }
239
+ if (isRightEdge) {
240
+ shadows.push(
241
+ `inset -${SELECTION_EDGE_WIDTH_PX}px 0 0 0 ${SELECTION_EDGE_COLOR}`
242
+ );
243
+ }
244
+ const stepEdges = getMergedCellStepEdges(
245
+ rowIndex,
246
+ colIndex,
247
+ bounds,
248
+ rowSpan,
249
+ isVisuallySelectedAt
250
+ );
251
+ const gradients = [];
252
+ const sizes = [];
253
+ const positions = [];
254
+ for (const edge of stepEdges) {
255
+ for (const partial of buildPartialVerticalGradient(edge)) {
256
+ gradients.push(partial.image);
257
+ sizes.push(partial.size);
258
+ positions.push(partial.position);
259
+ }
260
+ }
261
+ if (shadows.length === 0 && gradients.length === 0 && !selectionContinuesBelow) {
262
+ return void 0;
263
+ }
264
+ const style = {};
265
+ if (shadows.length > 0) {
266
+ style["--selection-edge-shadows"] = shadows.join(", ");
267
+ }
268
+ if (gradients.length > 0) {
269
+ style["--selection-edge-gradients"] = gradients.join(", ");
270
+ style["--selection-edge-sizes"] = sizes.join(", ");
271
+ style["--selection-edge-positions"] = positions.join(", ");
272
+ }
273
+ if (selectionContinuesBelow) {
274
+ style.borderBottomColor = "var(--color-brand-surface)";
275
+ }
276
+ return style;
277
+ }
278
+ function hasCellSelectionEdges(style) {
279
+ return Boolean(
280
+ style?.["--selection-edge-shadows"] || style?.["--selection-edge-gradients"]
281
+ );
282
+ }
283
+
284
+ // src/components/ui/table/features/row-expand/row-expand.ts
285
+ import { useEffect, useMemo, useRef } from "react";
286
+
287
+ // src/core/treeDefaults.ts
288
+ var DEFAULT_TREE_ID_FIELD = "id";
289
+ var DEFAULT_TREE_PARENT_ID_FIELD = "parentId";
290
+ var DEFAULT_TREE_CHILDREN_FIELD = "children";
291
+ var DEFAULT_TREE_QTY_FIELD = "qty";
292
+
293
+ // src/components/ui/table/features/row-expand/row-expand.ts
294
+ function getFieldValue(row, key) {
295
+ return row[key];
296
+ }
297
+ function canExpandRow(row) {
298
+ const children = row.children;
299
+ const level = row.level;
300
+ return Array.isArray(children) && children.length > 0 && (level === 0 || level === void 0);
301
+ }
302
+ function toggleExpandedRowId(rowId, previous) {
303
+ const next = new Set(previous);
304
+ if (next.has(rowId)) {
305
+ next.delete(rowId);
306
+ } else {
307
+ next.add(rowId);
308
+ }
309
+ return next;
310
+ }
311
+ var useConvertTreeData = ({
312
+ data,
313
+ enabled = true,
314
+ toggleField = DEFAULT_TREE_ID_FIELD,
315
+ childField = DEFAULT_TREE_PARENT_ID_FIELD,
316
+ flattenField = DEFAULT_TREE_CHILDREN_FIELD,
317
+ qtyField = DEFAULT_TREE_QTY_FIELD,
318
+ preventExpand = false,
319
+ startIndex = 1,
320
+ expandedRows,
321
+ onExpandedRowsChange
322
+ }) => {
323
+ const onExpandedRowsChangeRef = useRef(onExpandedRowsChange);
324
+ const hasInitializedRef = useRef(false);
325
+ useEffect(() => {
326
+ onExpandedRowsChangeRef.current = onExpandedRowsChange;
327
+ }, [onExpandedRowsChange]);
328
+ useEffect(() => {
329
+ if (!data || data.length === 0) {
330
+ hasInitializedRef.current = false;
331
+ return;
332
+ }
333
+ if (!enabled || hasInitializedRef.current) return;
334
+ const ids = data.map((item) => getFieldValue(item, toggleField)).filter((value) => typeof value === "string" && value.length > 0);
335
+ onExpandedRowsChangeRef.current?.(new Set(ids));
336
+ hasInitializedRef.current = true;
337
+ }, [enabled, data, toggleField]);
338
+ const processedData = useMemo(() => {
339
+ if (!enabled || !data || data.length === 0) return [];
340
+ const flattenedData = [];
341
+ const flattenItems = (items) => {
342
+ items.forEach((item) => {
343
+ const newItem = { ...item };
344
+ const nested = newItem[flattenField];
345
+ if (Array.isArray(nested)) {
346
+ const children = nested.map(
347
+ (child) => typeof child === "object" && child !== null ? { ...child } : child
348
+ );
349
+ delete newItem[flattenField];
350
+ flattenedData.push(newItem);
351
+ children.forEach((child) => {
352
+ if (typeof child === "object" && child !== null) {
353
+ ;
354
+ child[childField] = newItem[toggleField];
355
+ }
356
+ });
357
+ flattenItems(children);
358
+ } else {
359
+ flattenedData.push(newItem);
360
+ }
361
+ });
362
+ };
363
+ flattenItems(data);
364
+ const dataWithLevels = flattenedData.map((item) => ({
365
+ ...item,
366
+ level: 0,
367
+ children: [],
368
+ processed: false
369
+ }));
370
+ const itemMap = /* @__PURE__ */ new Map();
371
+ dataWithLevels.forEach((item) => {
372
+ const key = getFieldValue(item, toggleField);
373
+ if (typeof key !== "string" || !key) return;
374
+ if (!itemMap.has(key)) {
375
+ itemMap.set(key, []);
376
+ }
377
+ itemMap.get(key)?.push(item);
378
+ });
379
+ const rootItems = [];
380
+ dataWithLevels.forEach((item) => {
381
+ if (!getFieldValue(item, childField)) {
382
+ rootItems.push(item);
383
+ item.processed = true;
384
+ }
385
+ });
386
+ dataWithLevels.forEach((item) => {
387
+ const parentKey = getFieldValue(item, childField);
388
+ if (!parentKey || item.processed) return;
389
+ const parentItems = dataWithLevels.filter(
390
+ (parent) => getFieldValue(parent, toggleField) === parentKey && !getFieldValue(parent, childField)
391
+ );
392
+ if (parentItems.length > 0) {
393
+ const parent = parentItems[0];
394
+ item.level = parent.level + 1;
395
+ parent.children.push(item);
396
+ item.processed = true;
397
+ } else {
398
+ const otherParents = itemMap.get(String(parentKey)) || [];
399
+ if (otherParents.length > 0) {
400
+ const parent = otherParents[0];
401
+ item.level = parent.level + 1;
402
+ parent.children.push(item);
403
+ item.processed = true;
404
+ } else {
405
+ rootItems.push(item);
406
+ item.processed = true;
407
+ }
408
+ }
409
+ });
410
+ return rootItems;
411
+ }, [enabled, data, toggleField, childField, flattenField]);
412
+ const flattenTree = useMemo(() => {
413
+ if (!enabled) return [];
414
+ const flatten = (nodes, result = [], level = 0) => {
415
+ nodes.forEach((node, index) => {
416
+ const currentIndex = level === 0 ? `${index + startIndex}` : `${level}-${index + 1}`;
417
+ const toggleValue = getFieldValue(node, toggleField);
418
+ const uniqueId = `${index}-${String(toggleValue ?? "")}`;
419
+ result.push({
420
+ ...node,
421
+ treeNo: currentIndex,
422
+ uniqueId,
423
+ processed: true
424
+ });
425
+ const shouldExpandChildren = node.children.length > 0 && (preventExpand || typeof toggleValue === "string" && expandedRows?.has(toggleValue));
426
+ if (shouldExpandChildren) {
427
+ flatten(node.children, result, index + startIndex);
428
+ }
429
+ });
430
+ return result;
431
+ };
432
+ const flattenedData = flatten(processedData, [], 0);
433
+ flattenedData.forEach((item) => {
434
+ if (getFieldValue(item, childField)) {
435
+ const parentItem = flattenedData.find(
436
+ (parent) => getFieldValue(parent, toggleField) === getFieldValue(item, childField)
437
+ );
438
+ const parentAmount = parentItem ? Number(getFieldValue(parentItem, qtyField) ?? 1) : 1;
439
+ item.parentCount = parentAmount || 1;
440
+ } else {
441
+ item.parentCount = 1;
442
+ }
443
+ });
444
+ return flattenedData;
445
+ }, [
446
+ enabled,
447
+ processedData,
448
+ startIndex,
449
+ toggleField,
450
+ childField,
451
+ qtyField,
452
+ preventExpand,
453
+ expandedRows
454
+ ]);
455
+ const sortedData = useMemo(() => {
456
+ if (!enabled) {
457
+ return data ?? [];
458
+ }
459
+ return [...flattenTree].sort((a, b) => {
460
+ const aParts = String(a.treeNo ?? "").split("-").map(Number);
461
+ const bParts = String(b.treeNo ?? "").split("-").map(Number);
462
+ for (let i = 0; i < Math.max(aParts.length, bParts.length); i++) {
463
+ const aVal = aParts[i] || 0;
464
+ const bVal = bParts[i] || 0;
465
+ if (aVal !== bVal) {
466
+ return aVal - bVal;
467
+ }
468
+ }
469
+ return 0;
470
+ });
471
+ }, [enabled, data, flattenTree]);
472
+ return sortedData;
473
+ };
474
+
475
+ // src/components/ui/table/features/row-span/rowSpan.ts
476
+ function getRowFieldValue(row, key) {
477
+ return row[key];
478
+ }
479
+ function computeRowSpans(data, rowSpanKey) {
480
+ if (data.length === 0) return [];
481
+ const result = [];
482
+ for (let index = 0; index < data.length; index++) {
483
+ const currentValue = getRowFieldValue(data[index], rowSpanKey);
484
+ const previousValue = index > 0 ? getRowFieldValue(data[index - 1], rowSpanKey) : void 0;
485
+ if (index > 0 && currentValue === previousValue) {
486
+ result.push({ rowSpan: 0, isFirstInGroup: false });
487
+ continue;
488
+ }
489
+ let span = 1;
490
+ for (let nextIndex = index + 1; nextIndex < data.length; nextIndex++) {
491
+ if (getRowFieldValue(data[nextIndex], rowSpanKey) === currentValue) {
492
+ span++;
493
+ } else {
494
+ break;
495
+ }
496
+ }
497
+ result.push({ rowSpan: span, isFirstInGroup: true });
498
+ }
499
+ return result;
500
+ }
501
+ function resolveRowSpanAt(rowSpans, rowIndex) {
502
+ if (!rowSpans?.[rowIndex]) {
503
+ return { startRow: rowIndex, rowSpan: 1 };
504
+ }
505
+ const current = rowSpans[rowIndex];
506
+ if (current.rowSpan > 0) {
507
+ return { startRow: rowIndex, rowSpan: current.rowSpan };
508
+ }
509
+ for (let row = rowIndex - 1; row >= 0; row--) {
510
+ const info = rowSpans[row];
511
+ if (info && info.rowSpan > 0) {
512
+ return { startRow: row, rowSpan: info.rowSpan };
513
+ }
514
+ }
515
+ return { startRow: rowIndex, rowSpan: 1 };
516
+ }
517
+ function buildColumnRowSpanMap(data, columnKeys) {
518
+ const map = /* @__PURE__ */ new Map();
519
+ for (const { columnId, rowSpanKey } of columnKeys) {
520
+ map.set(columnId, computeRowSpans(data, rowSpanKey));
521
+ }
522
+ return map;
523
+ }
524
+ function collectRowSpanColumns(columns) {
525
+ const result = [];
526
+ const visit = (defs) => {
527
+ for (const columnDef of defs) {
528
+ if ("columns" in columnDef && columnDef.columns?.length) {
529
+ visit(columnDef.columns);
530
+ continue;
531
+ }
532
+ const columnId = columnDef.id ?? ("accessorKey" in columnDef && columnDef.accessorKey ? String(columnDef.accessorKey) : void 0);
533
+ if (!columnId || !columnDef.meta?.rowSpan) continue;
534
+ result.push({
535
+ columnId,
536
+ rowSpanKey: columnDef.meta.rowSpanKey ?? columnId
537
+ });
538
+ }
539
+ };
540
+ visit(columns);
541
+ return result;
542
+ }
543
+
544
+ // src/components/ui/table/components/icons.tsx
545
+ import { jsx as jsx2, jsxs } from "react/jsx-runtime";
546
+ function ChevronDown({ className, "aria-hidden": ariaHidden = true }) {
547
+ return /* @__PURE__ */ jsx2(
548
+ "svg",
549
+ {
550
+ className,
551
+ "aria-hidden": ariaHidden,
552
+ width: "16",
553
+ height: "16",
554
+ viewBox: "0 0 24 24",
555
+ fill: "none",
556
+ stroke: "currentColor",
557
+ strokeWidth: "2",
558
+ strokeLinecap: "round",
559
+ strokeLinejoin: "round",
560
+ children: /* @__PURE__ */ jsx2("path", { d: "m6 9 6 6 6-6" })
561
+ }
562
+ );
563
+ }
564
+ function ChevronUp({ className, "aria-hidden": ariaHidden = true }) {
565
+ return /* @__PURE__ */ jsx2(
566
+ "svg",
567
+ {
568
+ className,
569
+ "aria-hidden": ariaHidden,
570
+ width: "16",
571
+ height: "16",
572
+ viewBox: "0 0 24 24",
573
+ fill: "none",
574
+ stroke: "currentColor",
575
+ strokeWidth: "2",
576
+ strokeLinecap: "round",
577
+ strokeLinejoin: "round",
578
+ children: /* @__PURE__ */ jsx2("path", { d: "m18 15-6-6-6 6" })
579
+ }
580
+ );
581
+ }
582
+ function ChevronLeft({ className, "aria-hidden": ariaHidden = true }) {
583
+ return /* @__PURE__ */ jsx2(
584
+ "svg",
585
+ {
586
+ className,
587
+ "aria-hidden": ariaHidden,
588
+ width: "16",
589
+ height: "16",
590
+ viewBox: "0 0 24 24",
591
+ fill: "none",
592
+ stroke: "currentColor",
593
+ strokeWidth: "2",
594
+ strokeLinecap: "round",
595
+ strokeLinejoin: "round",
596
+ children: /* @__PURE__ */ jsx2("path", { d: "m15 18-6-6 6-6" })
597
+ }
598
+ );
599
+ }
600
+ function ChevronRight({ className, "aria-hidden": ariaHidden = true }) {
601
+ return /* @__PURE__ */ jsx2(
602
+ "svg",
603
+ {
604
+ className,
605
+ "aria-hidden": ariaHidden,
606
+ width: "16",
607
+ height: "16",
608
+ viewBox: "0 0 24 24",
609
+ fill: "none",
610
+ stroke: "currentColor",
611
+ strokeWidth: "2",
612
+ strokeLinecap: "round",
613
+ strokeLinejoin: "round",
614
+ children: /* @__PURE__ */ jsx2("path", { d: "m9 18 6-6-6-6" })
615
+ }
616
+ );
617
+ }
618
+ function ArrowUp({ className, "aria-hidden": ariaHidden = true }) {
619
+ return /* @__PURE__ */ jsxs(
620
+ "svg",
621
+ {
622
+ className,
623
+ "aria-hidden": ariaHidden,
624
+ width: "14",
625
+ height: "14",
626
+ viewBox: "0 0 24 24",
627
+ fill: "none",
628
+ stroke: "currentColor",
629
+ strokeWidth: "2",
630
+ strokeLinecap: "round",
631
+ strokeLinejoin: "round",
632
+ children: [
633
+ /* @__PURE__ */ jsx2("path", { d: "m18 15-6-6-6 6" }),
634
+ /* @__PURE__ */ jsx2("path", { d: "M12 21V9" })
635
+ ]
636
+ }
637
+ );
638
+ }
639
+ function ArrowDown({ className, "aria-hidden": ariaHidden = true }) {
640
+ return /* @__PURE__ */ jsxs(
641
+ "svg",
642
+ {
643
+ className,
644
+ "aria-hidden": ariaHidden,
645
+ width: "14",
646
+ height: "14",
647
+ viewBox: "0 0 24 24",
648
+ fill: "none",
649
+ stroke: "currentColor",
650
+ strokeWidth: "2",
651
+ strokeLinecap: "round",
652
+ strokeLinejoin: "round",
653
+ children: [
654
+ /* @__PURE__ */ jsx2("path", { d: "m6 9 6 6 6-6" }),
655
+ /* @__PURE__ */ jsx2("path", { d: "M12 3v12" })
656
+ ]
657
+ }
658
+ );
659
+ }
660
+ function ArrowUpDown({ className, "aria-hidden": ariaHidden = true }) {
661
+ return /* @__PURE__ */ jsxs(
662
+ "svg",
663
+ {
664
+ className,
665
+ "aria-hidden": ariaHidden,
666
+ width: "14",
667
+ height: "14",
668
+ viewBox: "0 0 24 24",
669
+ fill: "none",
670
+ stroke: "currentColor",
671
+ strokeWidth: "2",
672
+ strokeLinecap: "round",
673
+ strokeLinejoin: "round",
674
+ children: [
675
+ /* @__PURE__ */ jsx2("path", { d: "m21 16-4 4-4-4" }),
676
+ /* @__PURE__ */ jsx2("path", { d: "M17 20V4" }),
677
+ /* @__PURE__ */ jsx2("path", { d: "m3 8 4-4 4 4" }),
678
+ /* @__PURE__ */ jsx2("path", { d: "M7 4v16" })
679
+ ]
680
+ }
681
+ );
682
+ }
683
+
684
+ // src/lib/cn.ts
685
+ function cn(...inputs) {
686
+ return inputs.filter(Boolean).join(" ");
687
+ }
688
+
689
+ // src/components/ui/table/components/DataTable/DataTableRow.tsx
690
+ import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
691
+ function resolveExpandCellIndex(cells, toggleField) {
692
+ if (!toggleField) return 0;
693
+ const matchedIndex = cells.findIndex(
694
+ (cell) => cell.column.id === toggleField
695
+ );
696
+ if (matchedIndex >= 0) return matchedIndex;
697
+ const noColumnIndex = cells.findIndex(
698
+ (cell) => cell.column.id === "no" || cell.column.id === "treeNo"
699
+ );
700
+ if (noColumnIndex >= 0 && noColumnIndex + 1 < cells.length) {
701
+ return noColumnIndex + 1;
702
+ }
703
+ return 0;
704
+ }
705
+ function DataTableRow({
706
+ row,
707
+ onToggleSelect,
708
+ virtualIndex,
709
+ measureElement
710
+ }) {
711
+ const { rowSpan, selection, cellSelection, cellEdit, expand } = useDataTableRowContext();
712
+ const {
713
+ enableRowSpan,
714
+ primaryRowSpanKey,
715
+ columnRowSpanMap,
716
+ hoveredRowIndex,
717
+ hoveredGroupKey,
718
+ selectedGroupKeys,
719
+ onRowHover
720
+ } = rowSpan;
721
+ const { rowSelectionMode, selectOnRowClick, onRowClick, getRowClassName } = selection;
722
+ const {
723
+ enableCellSelection,
724
+ activeSelectionBounds,
725
+ dragState,
726
+ onCellMouseDown,
727
+ onCellMouseEnter,
728
+ onFillHandleMouseDown
729
+ } = cellSelection;
730
+ const {
731
+ editingCell,
732
+ draftValue,
733
+ onDraftValueChange,
734
+ onStartEdit,
735
+ onCommitEdit,
736
+ onCancelEdit
737
+ } = cellEdit;
738
+ const {
739
+ enableExpand,
740
+ toggleField,
741
+ expandedRows,
742
+ preventExpand,
743
+ onToggleExpand,
744
+ expandRowLabel,
745
+ collapseRowLabel
746
+ } = expand;
747
+ const rowIndex = row.index;
748
+ const rowData = row.original;
749
+ const isRowHovered = hoveredRowIndex === rowIndex;
750
+ const isRowSelected = row.getIsSelected();
751
+ const rowGroupKey = primaryRowSpanKey !== void 0 && rowData[primaryRowSpanKey] !== null && rowData[primaryRowSpanKey] !== void 0 ? String(rowData[primaryRowSpanKey]) : null;
752
+ const isGroupHovered = enableRowSpan && hoveredGroupKey !== null && rowGroupKey === hoveredGroupKey;
753
+ const isGroupSelected = enableRowSpan && rowGroupKey !== null && selectedGroupKeys.has(rowGroupKey);
754
+ const visibleCells = row.getVisibleCells();
755
+ const columnIdsByIndex = visibleCells.map((cell) => cell.column.id);
756
+ const isVisuallySelectedAt = activeSelectionBounds ? (targetRow, targetCol) => {
757
+ if (targetCol < activeSelectionBounds.startCol || targetCol > activeSelectionBounds.endCol) {
758
+ return false;
759
+ }
760
+ const columnId = columnIdsByIndex[targetCol];
761
+ const { startRow, rowSpan: span } = resolveRowSpanAt(
762
+ columnId ? columnRowSpanMap.get(columnId) : void 0,
763
+ targetRow
764
+ );
765
+ return isCellInSelection(
766
+ startRow,
767
+ targetCol,
768
+ activeSelectionBounds,
769
+ span
770
+ );
771
+ } : void 0;
772
+ const expandCellIndex = enableExpand ? resolveExpandCellIndex(visibleCells, toggleField) : -1;
773
+ const canExpand = enableExpand && !preventExpand && canExpandRow(rowData);
774
+ const expandKey = toggleField && rowData[toggleField] !== null && rowData[toggleField] !== void 0 ? String(rowData[toggleField]) : null;
775
+ const isExpanded = expandKey !== null && Boolean(expandedRows?.has(expandKey));
776
+ const rowLevel = typeof rowData.level === "number" ? rowData.level : 0;
777
+ const editInputRef = useRef2(null);
778
+ const isRowEditing = editingCell?.rowIndex === rowIndex;
779
+ useEffect2(() => {
780
+ if (!isRowEditing) return;
781
+ editInputRef.current?.focus();
782
+ editInputRef.current?.select();
783
+ }, [isRowEditing, editingCell?.colIndex]);
784
+ return /* @__PURE__ */ jsx3(
785
+ "tr",
786
+ {
787
+ ref: measureElement,
788
+ "data-index": virtualIndex,
789
+ className: cn(
790
+ "DataTableRowJSX",
791
+ !enableRowSpan && ROW_HOVER_CLASS,
792
+ enableRowSpan && isRowHovered && !isRowSelected && ROW_HOVERED_BG_CLASS,
793
+ isRowSelected && "is-selected",
794
+ enableExpand && canExpand && "is-expandable",
795
+ getRowClassName?.(rowData, rowIndex)
796
+ ),
797
+ onMouseEnter: () => onRowHover(rowIndex, rowData),
798
+ onClick: () => {
799
+ if (isRowEditing) return;
800
+ onRowClick?.(rowData, rowIndex);
801
+ if (rowSelectionMode !== "none" && selectOnRowClick) {
802
+ onToggleSelect();
803
+ }
804
+ },
805
+ children: visibleCells.map((cell, cellIndex) => {
806
+ const columnId = cell.column.id;
807
+ const meta = cell.column.columnDef.meta;
808
+ const align = meta?.align ?? "center";
809
+ const cellClassName = meta?.className;
810
+ const isRowSpanColumn = Boolean(enableRowSpan && meta?.rowSpan);
811
+ const isExpandCell = cellIndex === expandCellIndex;
812
+ const editable = isColumnEditable(cell.column.columnDef);
813
+ const editType = getColumnEditType(cell.column.columnDef);
814
+ let rowSpanInfo;
815
+ if (isRowSpanColumn) {
816
+ rowSpanInfo = columnRowSpanMap.get(columnId)?.[rowIndex];
817
+ if (rowSpanInfo && rowSpanInfo.rowSpan === 0) {
818
+ return null;
819
+ }
820
+ }
821
+ const isEditing = editingCell?.rowIndex === rowIndex && editingCell?.colIndex === cellIndex;
822
+ const showCellHover = isRowSpanColumn ? isGroupHovered : isRowHovered;
823
+ const showCellSelected = isRowSpanColumn ? isGroupSelected : isRowSelected;
824
+ const cellRowSpan = rowSpanInfo?.rowSpan ?? 1;
825
+ const isMerged = cellRowSpan > 1;
826
+ const showMergedRightEdge = isMerged && (cellIndex === visibleCells.length - 1 || resolveRowSpanAt(
827
+ columnRowSpanMap.get(columnIdsByIndex[cellIndex + 1]),
828
+ rowIndex
829
+ ).rowSpan <= 1);
830
+ const isCellDragSelected = isCellInSelection(
831
+ rowIndex,
832
+ cellIndex,
833
+ activeSelectionBounds,
834
+ cellRowSpan
835
+ );
836
+ const isBottomRightCell = !isEditing && activeSelectionBounds && !dragState.isSelecting && activeSelectionBounds.endRow >= rowIndex && activeSelectionBounds.endRow <= rowIndex + cellRowSpan - 1 && cellIndex === activeSelectionBounds.endCol;
837
+ const selectionEdgeStyle = getCellSelectionEdgeStyle(
838
+ rowIndex,
839
+ cellIndex,
840
+ activeSelectionBounds,
841
+ cellRowSpan,
842
+ isVisuallySelectedAt
843
+ );
844
+ const resolveCellRowIndex = (clientY, element) => getRowIndexInMergedCell(clientY, element, rowIndex, cellRowSpan);
845
+ return /* @__PURE__ */ jsxs2(
846
+ "td",
847
+ {
848
+ rowSpan: rowSpanInfo && rowSpanInfo.rowSpan > 1 ? rowSpanInfo.rowSpan : void 0,
849
+ onMouseDown: (event) => {
850
+ if (isEditing) {
851
+ event.stopPropagation();
852
+ return;
853
+ }
854
+ if (!enableCellSelection) return;
855
+ event.preventDefault();
856
+ onCellMouseDown(
857
+ resolveCellRowIndex(event.clientY, event.currentTarget),
858
+ cellIndex
859
+ );
860
+ },
861
+ onMouseEnter: (event) => {
862
+ if (!enableCellSelection) return;
863
+ onCellMouseEnter(
864
+ resolveCellRowIndex(event.clientY, event.currentTarget),
865
+ cellIndex
866
+ );
867
+ },
868
+ onMouseMove: (event) => {
869
+ if (!enableCellSelection) return;
870
+ if (!dragState.isSelecting && !dragState.isFillDragging) return;
871
+ onCellMouseEnter(
872
+ resolveCellRowIndex(event.clientY, event.currentTarget),
873
+ cellIndex
874
+ );
875
+ },
876
+ onDoubleClick: (event) => {
877
+ if (!editable) return;
878
+ event.preventDefault();
879
+ event.stopPropagation();
880
+ onStartEdit(rowIndex, cellIndex);
881
+ },
882
+ style: selectionEdgeStyle,
883
+ className: cn(
884
+ "data-table-cell",
885
+ CELL_ALIGN_CLASS[align],
886
+ cellClassName,
887
+ isMerged && cellIndex > 0 && "is-merged",
888
+ showMergedRightEdge && "is-merged-edge-right",
889
+ enableRowSpan && showCellSelected && "is-group-selected",
890
+ enableRowSpan && showCellHover && !showCellSelected && "is-group-hovered",
891
+ isCellDragSelected && CELL_SELECTION_FILL_CLASS,
892
+ hasCellSelectionEdges(selectionEdgeStyle) && CELL_SELECTION_EDGES_CLASS,
893
+ editable && "is-editable"
894
+ ),
895
+ children: [
896
+ isEditing ? /* @__PURE__ */ jsx3(
897
+ "input",
898
+ {
899
+ ref: editInputRef,
900
+ type: editType === "number" ? "number" : "text",
901
+ defaultValue: draftValue,
902
+ className: cn("cell-edit-input", CELL_ALIGN_CLASS[align]),
903
+ onChange: (event) => onDraftValueChange(event.target.value),
904
+ onMouseDown: (event) => event.stopPropagation(),
905
+ onClick: (event) => event.stopPropagation(),
906
+ onKeyDown: (event) => {
907
+ if (event.key === "Enter") {
908
+ event.preventDefault();
909
+ onCommitEdit(event.currentTarget.value);
910
+ }
911
+ if (event.key === "Escape") {
912
+ event.preventDefault();
913
+ onCancelEdit();
914
+ }
915
+ },
916
+ onBlur: (event) => {
917
+ onCommitEdit(event.currentTarget.value);
918
+ }
919
+ }
920
+ ) : isExpandCell && enableExpand ? /* @__PURE__ */ jsxs2("div", { className: "expand-cell", children: [
921
+ /* @__PURE__ */ jsxs2("div", { className: "expand-cell-content", children: [
922
+ rowLevel > 0 && /* @__PURE__ */ jsx3("span", { className: "expand-cell-indent", children: "\xB7" }),
923
+ /* @__PURE__ */ jsx3("div", { className: "expand-cell-value", children: flexRender(cell.column.columnDef.cell, cell.getContext()) })
924
+ ] }),
925
+ canExpand && expandKey && /* @__PURE__ */ jsx3(
926
+ "button",
927
+ {
928
+ type: "button",
929
+ "aria-label": isExpanded ? collapseRowLabel : expandRowLabel,
930
+ className: "expand-toggle-button",
931
+ onClick: (event) => {
932
+ event.stopPropagation();
933
+ onToggleExpand?.(expandKey);
934
+ },
935
+ onMouseDown: (event) => event.stopPropagation(),
936
+ children: isExpanded ? /* @__PURE__ */ jsx3(ChevronUp, { className: "expand-toggle-icon" }) : /* @__PURE__ */ jsx3(ChevronDown, { className: "expand-toggle-icon" })
937
+ }
938
+ )
939
+ ] }) : flexRender(cell.column.columnDef.cell, cell.getContext()),
940
+ isBottomRightCell && /* @__PURE__ */ jsx3(
941
+ "div",
942
+ {
943
+ role: "presentation",
944
+ className: "fill-handle",
945
+ onMouseDown: (event) => {
946
+ event.stopPropagation();
947
+ event.preventDefault();
948
+ onFillHandleMouseDown(rowIndex, cellIndex);
949
+ }
950
+ }
951
+ )
952
+ ]
953
+ },
954
+ cell.id
955
+ );
956
+ })
957
+ }
958
+ );
959
+ }
960
+
961
+ // src/components/ui/table/components/DataTable/DataTableToolbar.tsx
962
+ import { Fragment, jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
963
+ function DataTableToolbar({
964
+ filteredCount,
965
+ totalCount,
966
+ summary,
967
+ selectedCount,
968
+ selectionLabel,
969
+ toolbar,
970
+ className
971
+ }) {
972
+ const displayFiltered = filteredCount ?? totalCount;
973
+ const hasCount = displayFiltered !== void 0 || totalCount !== void 0;
974
+ const hasLeftContent = hasCount || Boolean(summary);
975
+ const hasToolbar = Boolean(toolbar);
976
+ const selectionContent = selectionLabel?.(selectedCount) ?? null;
977
+ const hasSelectionContent = selectionContent !== null && selectionContent !== false && selectionContent !== void 0 && typeof selectionContent !== "boolean";
978
+ if (!hasLeftContent && !hasToolbar && !hasSelectionContent) return null;
979
+ return /* @__PURE__ */ jsxs3("div", { className: cn("DataTableToolbarJSX", className), children: [
980
+ /* @__PURE__ */ jsxs3("div", { className: "toolbar-left", children: [
981
+ hasCount && /* @__PURE__ */ jsx4("span", { className: "toolbar-count", children: displayFiltered !== void 0 && totalCount !== void 0 ? /* @__PURE__ */ jsxs3(Fragment, { children: [
982
+ /* @__PURE__ */ jsx4("span", { className: "toolbar-count-primary", children: displayFiltered }),
983
+ /* @__PURE__ */ jsxs3("span", { className: "toolbar-count-placeholder", children: [
984
+ " / ",
985
+ totalCount
986
+ ] })
987
+ ] }) : /* @__PURE__ */ jsx4("span", { className: "toolbar-count-primary", children: displayFiltered ?? totalCount }) }),
988
+ summary
989
+ ] }),
990
+ /* @__PURE__ */ jsxs3("div", { className: "toolbar-right", children: [
991
+ hasSelectionContent && (typeof selectionContent === "string" || typeof selectionContent === "number" ? /* @__PURE__ */ jsx4("span", { className: "toolbar-selection", children: selectionContent }) : selectionContent),
992
+ hasToolbar && /* @__PURE__ */ jsx4("div", { className: "toolbar-actions", children: toolbar })
993
+ ] })
994
+ ] });
995
+ }
996
+
997
+ // src/core/useGlideTable.ts
998
+ import {
999
+ getCoreRowModel,
1000
+ useReactTable
1001
+ } from "@tanstack/react-table";
1002
+ import {
1003
+ useVirtualizer
1004
+ } from "@tanstack/react-virtual";
1005
+ import {
1006
+ useCallback as useCallback3,
1007
+ useEffect as useEffect5,
1008
+ useMemo as useMemo2,
1009
+ useRef as useRef4,
1010
+ useState as useState3
1011
+ } from "react";
1012
+
1013
+ // src/components/ui/table/features/cell-edit/useCellEdit.ts
1014
+ import { useCallback, useEffect as useEffect3, useRef as useRef3, useState } from "react";
1015
+ function useCellEdit({
1016
+ data,
1017
+ rows,
1018
+ onDataChange,
1019
+ onCellChange
1020
+ }) {
1021
+ const [editingCell, setEditingCell] = useState(null);
1022
+ const [draftValue, setDraftValue] = useState("");
1023
+ const draftValueRef = useRef3(draftValue);
1024
+ const editingCellRef = useRef3(editingCell);
1025
+ useEffect3(() => {
1026
+ draftValueRef.current = draftValue;
1027
+ }, [draftValue]);
1028
+ useEffect3(() => {
1029
+ editingCellRef.current = editingCell;
1030
+ }, [editingCell]);
1031
+ const cancelEdit = useCallback(() => {
1032
+ setEditingCell(null);
1033
+ setDraftValue("");
1034
+ }, []);
1035
+ const commitEdit = useCallback(
1036
+ (raw) => {
1037
+ const current = editingCellRef.current;
1038
+ if (!current) return true;
1039
+ if (!onCellChange && !onDataChange) {
1040
+ cancelEdit();
1041
+ return true;
1042
+ }
1043
+ const row = rows[current.rowIndex];
1044
+ const cell = row?.getVisibleCells()[current.colIndex];
1045
+ if (!row || !cell) {
1046
+ cancelEdit();
1047
+ return true;
1048
+ }
1049
+ const value = raw ?? draftValueRef.current;
1050
+ if (!isColumnEditable(cell.column.columnDef)) {
1051
+ cancelEdit();
1052
+ return true;
1053
+ }
1054
+ const parsed = parseCellEditValue(value, getColumnEditType(cell.column.columnDef));
1055
+ if (!parsed.ok) return false;
1056
+ if (onCellChange) {
1057
+ onCellChange(row.id, cell.column.id, parsed.value);
1058
+ cancelEdit();
1059
+ return true;
1060
+ }
1061
+ const next = applyCellEdit(data, rows, current.rowIndex, current.colIndex, value);
1062
+ if (!next) return false;
1063
+ onDataChange?.(next);
1064
+ cancelEdit();
1065
+ return true;
1066
+ },
1067
+ [cancelEdit, data, onCellChange, onDataChange, rows]
1068
+ );
1069
+ const startEdit = useCallback(
1070
+ (rowIndex, colIndex) => {
1071
+ const cell = rows[rowIndex]?.getVisibleCells()[colIndex];
1072
+ if (!cell || !isColumnEditable(cell.column.columnDef)) return;
1073
+ const current = editingCellRef.current;
1074
+ if (current && (current.rowIndex !== rowIndex || current.colIndex !== colIndex) && !commitEdit()) {
1075
+ return;
1076
+ }
1077
+ setEditingCell({ rowIndex, colIndex });
1078
+ setDraftValue(getCellEditDraftValue(cell.getValue()));
1079
+ },
1080
+ [commitEdit, rows]
1081
+ );
1082
+ return {
1083
+ editingCell,
1084
+ draftValue,
1085
+ setDraftValue,
1086
+ startEdit,
1087
+ commitEdit,
1088
+ cancelEdit
1089
+ };
1090
+ }
1091
+
1092
+ // src/components/ui/table/features/cell-selection/useCellSelection.ts
1093
+ import { useCallback as useCallback2, useEffect as useEffect4, useState as useState2 } from "react";
1094
+
1095
+ // src/components/ui/table/features/cell-selection/fillData.ts
1096
+ function getColumnAccessorKey2(columnDef) {
1097
+ if ("accessorKey" in columnDef && columnDef.accessorKey) {
1098
+ return String(columnDef.accessorKey);
1099
+ }
1100
+ return columnDef.id;
1101
+ }
1102
+ function collectFillTargets(rows, sourceBounds, fillBounds) {
1103
+ const targets = [];
1104
+ const sourceHeight = sourceBounds.endRow - sourceBounds.startRow + 1;
1105
+ const sourceWidth = sourceBounds.endCol - sourceBounds.startCol + 1;
1106
+ for (let rowIndex = fillBounds.startRow; rowIndex <= fillBounds.endRow; rowIndex += 1) {
1107
+ for (let colIndex = fillBounds.startCol; colIndex <= fillBounds.endCol; colIndex += 1) {
1108
+ if (isCellInSelection(rowIndex, colIndex, sourceBounds)) continue;
1109
+ const offsetRow = rowIndex - sourceBounds.startRow;
1110
+ const offsetCol = colIndex - sourceBounds.startCol;
1111
+ const sourceRowIndex = sourceBounds.startRow + (offsetRow % sourceHeight + sourceHeight) % sourceHeight;
1112
+ const sourceColIndex = sourceBounds.startCol + (offsetCol % sourceWidth + sourceWidth) % sourceWidth;
1113
+ const targetRow = rows[rowIndex];
1114
+ const targetCell = targetRow?.getVisibleCells()[colIndex];
1115
+ const sourceCell = rows[sourceRowIndex]?.getVisibleCells()[sourceColIndex];
1116
+ if (!targetRow || !targetCell || !sourceCell) continue;
1117
+ const accessorKey = getColumnAccessorKey2(
1118
+ targetCell.column.columnDef
1119
+ );
1120
+ if (!accessorKey) continue;
1121
+ targets.push({
1122
+ rowIndex,
1123
+ accessorKey,
1124
+ columnId: targetCell.column.id,
1125
+ value: sourceCell.getValue(),
1126
+ rowId: targetRow.id
1127
+ });
1128
+ }
1129
+ }
1130
+ return targets;
1131
+ }
1132
+ function collectFillChanges(rows, sourceBounds, fillBounds) {
1133
+ return collectFillTargets(rows, sourceBounds, fillBounds).map(
1134
+ ({ rowId, columnId, value }) => ({ rowId, columnId, value })
1135
+ );
1136
+ }
1137
+ function applyFillData(data, rows, sourceBounds, fillBounds) {
1138
+ const newData = data.map((row) => ({ ...row }));
1139
+ const targets = collectFillTargets(rows, sourceBounds, fillBounds);
1140
+ for (const target of targets) {
1141
+ if (!newData[target.rowIndex]) continue;
1142
+ newData[target.rowIndex][target.accessorKey] = target.value;
1143
+ }
1144
+ return newData;
1145
+ }
1146
+ function hasFillExtension(sourceBounds, fillBounds) {
1147
+ if (!sourceBounds) return false;
1148
+ return fillBounds.startRow < sourceBounds.startRow || fillBounds.endRow > sourceBounds.endRow || fillBounds.startCol < sourceBounds.startCol || fillBounds.endCol > sourceBounds.endCol;
1149
+ }
1150
+
1151
+ // src/components/ui/table/features/cell-selection/useCellSelection.ts
1152
+ function useCellSelection({
1153
+ data,
1154
+ rows,
1155
+ enabled = true,
1156
+ onDataChange,
1157
+ onBatchChange
1158
+ }) {
1159
+ const [dragState, setDragState] = useState2(INITIAL_DRAG_STATE);
1160
+ const cellSelectionBounds = getCellSelectionBounds(dragState.start, dragState.end);
1161
+ const activeSelectionBounds = enabled ? getActiveSelectionBounds(dragState, cellSelectionBounds) : null;
1162
+ const handleCellMouseDown = useCallback2(
1163
+ (rowIndex, colIndex) => {
1164
+ if (!enabled) return;
1165
+ setDragState({
1166
+ isSelecting: true,
1167
+ isFillDragging: false,
1168
+ start: { row: rowIndex, col: colIndex },
1169
+ end: { row: rowIndex, col: colIndex },
1170
+ fillAnchor: null,
1171
+ fillEnd: null
1172
+ });
1173
+ },
1174
+ [enabled]
1175
+ );
1176
+ const handleCellMouseEnter = useCallback2(
1177
+ (rowIndex, colIndex) => {
1178
+ if (!enabled) return;
1179
+ setDragState((prev) => {
1180
+ if (prev.isSelecting) {
1181
+ return { ...prev, end: { row: rowIndex, col: colIndex } };
1182
+ }
1183
+ if (prev.isFillDragging) {
1184
+ return { ...prev, fillEnd: { row: rowIndex, col: colIndex } };
1185
+ }
1186
+ return prev;
1187
+ });
1188
+ },
1189
+ [enabled]
1190
+ );
1191
+ const handleFillHandleMouseDown = useCallback2(
1192
+ (rowIndex, colIndex) => {
1193
+ if (!enabled) return;
1194
+ setDragState((prev) => {
1195
+ const bounds = getCellSelectionBounds(prev.start, prev.end);
1196
+ if (!bounds) return prev;
1197
+ return {
1198
+ ...prev,
1199
+ isSelecting: false,
1200
+ isFillDragging: true,
1201
+ fillAnchor: { row: bounds.startRow, col: bounds.startCol },
1202
+ fillEnd: { row: rowIndex, col: colIndex }
1203
+ };
1204
+ });
1205
+ },
1206
+ [enabled]
1207
+ );
1208
+ useEffect4(() => {
1209
+ if (!enabled) {
1210
+ setDragState(INITIAL_DRAG_STATE);
1211
+ }
1212
+ }, [enabled]);
1213
+ useEffect4(() => {
1214
+ if (!enabled) return;
1215
+ const handleKeyDown = (e) => {
1216
+ if ((e.ctrlKey || e.metaKey) && e.key === "c" && activeSelectionBounds) {
1217
+ const { startRow, endRow, startCol, endCol } = activeSelectionBounds;
1218
+ const selectedData = rows.slice(startRow, endRow + 1).map((row) => {
1219
+ const cells = row.getVisibleCells();
1220
+ return cells.slice(startCol, endCol + 1).map((cell) => cell.getValue()).join(" ");
1221
+ }).join("\n");
1222
+ navigator.clipboard.writeText(selectedData);
1223
+ }
1224
+ };
1225
+ window.addEventListener("keydown", handleKeyDown);
1226
+ return () => window.removeEventListener("keydown", handleKeyDown);
1227
+ }, [activeSelectionBounds, enabled, rows]);
1228
+ useEffect4(() => {
1229
+ if (!enabled) return;
1230
+ const handleMouseUp = () => {
1231
+ setDragState((prev) => {
1232
+ if (prev.isFillDragging && prev.fillAnchor && prev.fillEnd) {
1233
+ const sourceBounds = getCellSelectionBounds(prev.start, prev.end);
1234
+ const newBounds = getCellSelectionBounds(prev.fillAnchor, prev.fillEnd);
1235
+ if (newBounds) {
1236
+ if (hasFillExtension(sourceBounds, newBounds) && sourceBounds) {
1237
+ if (onBatchChange) {
1238
+ const changes = collectFillChanges(rows, sourceBounds, newBounds);
1239
+ if (changes.length > 0) {
1240
+ onBatchChange(changes);
1241
+ }
1242
+ } else if (onDataChange) {
1243
+ onDataChange(applyFillData(data, rows, sourceBounds, newBounds));
1244
+ }
1245
+ }
1246
+ return {
1247
+ isSelecting: false,
1248
+ isFillDragging: false,
1249
+ start: { row: newBounds.startRow, col: newBounds.startCol },
1250
+ end: { row: newBounds.endRow, col: newBounds.endCol },
1251
+ fillAnchor: null,
1252
+ fillEnd: null
1253
+ };
1254
+ }
1255
+ }
1256
+ if (prev.isSelecting) {
1257
+ return { ...prev, isSelecting: false };
1258
+ }
1259
+ if (prev.isFillDragging) {
1260
+ return { ...prev, isFillDragging: false, fillAnchor: null, fillEnd: null };
1261
+ }
1262
+ return prev;
1263
+ });
1264
+ };
1265
+ window.addEventListener("mouseup", handleMouseUp);
1266
+ return () => window.removeEventListener("mouseup", handleMouseUp);
1267
+ }, [data, enabled, onBatchChange, onDataChange, rows]);
1268
+ return {
1269
+ dragState: enabled ? dragState : INITIAL_DRAG_STATE,
1270
+ activeSelectionBounds,
1271
+ handleCellMouseDown,
1272
+ handleCellMouseEnter,
1273
+ handleFillHandleMouseDown
1274
+ };
1275
+ }
1276
+
1277
+ // src/components/ui/table/features/row-selection/rowSelection.ts
1278
+ function resolveRowSelection(mode, controlledSelection, internalSelection) {
1279
+ if (mode === "none") return {};
1280
+ return controlledSelection ?? internalSelection;
1281
+ }
1282
+ function normalizeSingleSelection(next) {
1283
+ const selectedIds = Object.keys(next).filter((id) => next[id]);
1284
+ if (selectedIds.length <= 1) return next;
1285
+ return { [selectedIds[selectedIds.length - 1]]: true };
1286
+ }
1287
+ function applySelectionUpdater(mode, updater, previous) {
1288
+ const next = typeof updater === "function" ? updater(previous) : updater;
1289
+ return mode === "single" ? normalizeSingleSelection(next) : next;
1290
+ }
1291
+
1292
+ // src/core/labels.ts
1293
+ var DEFAULT_DATA_TABLE_LABELS = {
1294
+ empty: "No data",
1295
+ loading: "Loading...",
1296
+ selection: (selectedCount) => selectedCount > 0 ? `\u2713 ${selectedCount} selected` : null,
1297
+ expandRow: "Expand row",
1298
+ collapseRow: "Collapse row"
1299
+ };
1300
+ function resolveDataTableLabels(partial) {
1301
+ return {
1302
+ ...DEFAULT_DATA_TABLE_LABELS,
1303
+ ...partial
1304
+ };
1305
+ }
1306
+
1307
+ // src/core/useGlideTable.ts
1308
+ function useGlideTable(options) {
1309
+ const {
1310
+ data,
1311
+ columns,
1312
+ rowSelectionMode = "none",
1313
+ rowSelection: controlledRowSelection,
1314
+ onRowSelectionChange,
1315
+ selectionLabel,
1316
+ emptyText,
1317
+ loadingText,
1318
+ labels: labelsProp,
1319
+ enableRowSpan = false,
1320
+ getRowId,
1321
+ onRowClick,
1322
+ getRowClassName,
1323
+ getRowCanSelect,
1324
+ selectOnRowClick = true,
1325
+ enableCellSelection = true,
1326
+ onDataChange,
1327
+ onCellChange,
1328
+ onBatchChange,
1329
+ preserveRowSelection = false,
1330
+ toggleField,
1331
+ childField,
1332
+ flattenField,
1333
+ qtyField,
1334
+ expandedRows: controlledExpandedRows,
1335
+ onExpandedRowsChange,
1336
+ preventExpand = false,
1337
+ enableVirtualization = true,
1338
+ estimateRowHeight = DATA_TABLE_ROW_HEIGHT,
1339
+ virtualOverscan = DATA_TABLE_VIRTUAL_OVERSCAN
1340
+ } = options;
1341
+ const labels = useMemo2(() => {
1342
+ const resolved = resolveDataTableLabels(labelsProp);
1343
+ return {
1344
+ ...resolved,
1345
+ empty: labelsProp?.empty ?? emptyText ?? resolved.empty,
1346
+ loading: labelsProp?.loading ?? loadingText ?? resolved.loading,
1347
+ selection: labelsProp?.selection ?? selectionLabel ?? resolved.selection
1348
+ };
1349
+ }, [labelsProp, emptyText, loadingText, selectionLabel]);
1350
+ const enableExpand = Boolean(toggleField);
1351
+ const [internalRowSelection, setInternalRowSelection] = useState3({});
1352
+ const [internalExpandedRows, setInternalExpandedRows] = useState3(
1353
+ () => /* @__PURE__ */ new Set()
1354
+ );
1355
+ const [hoveredRowIndex, setHoveredRowIndex] = useState3(null);
1356
+ const [hoveredGroupKey, setHoveredGroupKey] = useState3(null);
1357
+ const scrollRef = useRef4(null);
1358
+ const shouldVirtualize = enableVirtualization && !enableRowSpan;
1359
+ useEffect5(() => {
1360
+ if (enableVirtualization && enableRowSpan) {
1361
+ console.warn(
1362
+ "[useGlideTable] enableRowSpan is on; virtualization is disabled to preserve cell merges."
1363
+ );
1364
+ }
1365
+ }, [enableVirtualization, enableRowSpan]);
1366
+ const rowSelection = resolveRowSelection(
1367
+ rowSelectionMode,
1368
+ controlledRowSelection,
1369
+ internalRowSelection
1370
+ );
1371
+ const expandedRows = controlledExpandedRows ?? internalExpandedRows;
1372
+ const handleExpandedRowsChange = useCallback3(
1373
+ (next) => {
1374
+ if (onExpandedRowsChange) {
1375
+ onExpandedRowsChange(next);
1376
+ return;
1377
+ }
1378
+ setInternalExpandedRows(next);
1379
+ },
1380
+ [onExpandedRowsChange]
1381
+ );
1382
+ const tableData = useConvertTreeData({
1383
+ data,
1384
+ enabled: enableExpand,
1385
+ toggleField,
1386
+ childField,
1387
+ flattenField,
1388
+ qtyField,
1389
+ expandedRows,
1390
+ onExpandedRowsChange: enableExpand ? handleExpandedRowsChange : void 0,
1391
+ preventExpand
1392
+ });
1393
+ const table = useReactTable({
1394
+ data: tableData,
1395
+ columns,
1396
+ state: {
1397
+ rowSelection: rowSelectionMode === "none" ? {} : rowSelection
1398
+ },
1399
+ enableRowSelection: rowSelectionMode === "none" ? false : getRowCanSelect ? (row) => getRowCanSelect(row.original, row.index) : true,
1400
+ enableMultiRowSelection: rowSelectionMode === "multi",
1401
+ onRowSelectionChange: (updater) => {
1402
+ if (onRowSelectionChange) {
1403
+ onRowSelectionChange(
1404
+ (previous) => applySelectionUpdater(rowSelectionMode, updater, previous)
1405
+ );
1406
+ return;
1407
+ }
1408
+ setInternalRowSelection(
1409
+ (previous) => applySelectionUpdater(rowSelectionMode, updater, previous)
1410
+ );
1411
+ },
1412
+ getCoreRowModel: getCoreRowModel(),
1413
+ getRowId: getRowId ? (originalRow, index) => getRowId(originalRow, index) : (_originalRow, index) => String(index)
1414
+ });
1415
+ const rowSpanColumnKeys = useMemo2(() => {
1416
+ if (!enableRowSpan) return [];
1417
+ return collectRowSpanColumns(columns);
1418
+ }, [enableRowSpan, columns]);
1419
+ const primaryRowSpanKey = rowSpanColumnKeys[0]?.rowSpanKey;
1420
+ const columnRowSpanMap = useMemo2(
1421
+ () => buildColumnRowSpanMap(tableData, rowSpanColumnKeys),
1422
+ [tableData, rowSpanColumnKeys]
1423
+ );
1424
+ const selectedRows = table.getSelectedRowModel().rows;
1425
+ const selectedCount = selectedRows.length;
1426
+ const rows = table.getRowModel().rows;
1427
+ const columnCount = table.getAllLeafColumns().length || 1;
1428
+ const rowVirtualizer = useVirtualizer({
1429
+ count: shouldVirtualize ? rows.length : 0,
1430
+ getScrollElement: () => scrollRef.current,
1431
+ estimateSize: () => estimateRowHeight,
1432
+ overscan: virtualOverscan
1433
+ });
1434
+ const virtualRows = rowVirtualizer.getVirtualItems();
1435
+ const totalSize = rowVirtualizer.getTotalSize();
1436
+ const paddingTop = virtualRows.length > 0 ? virtualRows[0]?.start ?? 0 : 0;
1437
+ const paddingBottom = virtualRows.length > 0 ? totalSize - (virtualRows[virtualRows.length - 1]?.end ?? 0) : 0;
1438
+ const selectedGroupKeys = useMemo2(() => {
1439
+ if (!enableRowSpan || !primaryRowSpanKey) return /* @__PURE__ */ new Set();
1440
+ const keys = /* @__PURE__ */ new Set();
1441
+ for (const selectedRow of selectedRows) {
1442
+ const value = selectedRow.original[primaryRowSpanKey];
1443
+ if (value !== null && value !== void 0) keys.add(String(value));
1444
+ }
1445
+ return keys;
1446
+ }, [enableRowSpan, primaryRowSpanKey, selectedRows]);
1447
+ const {
1448
+ dragState,
1449
+ activeSelectionBounds,
1450
+ handleCellMouseDown,
1451
+ handleCellMouseEnter,
1452
+ handleFillHandleMouseDown
1453
+ } = useCellSelection({
1454
+ data: tableData,
1455
+ rows,
1456
+ enabled: enableCellSelection,
1457
+ onDataChange,
1458
+ onBatchChange
1459
+ });
1460
+ const {
1461
+ editingCell,
1462
+ draftValue,
1463
+ setDraftValue,
1464
+ startEdit,
1465
+ commitEdit,
1466
+ cancelEdit
1467
+ } = useCellEdit({ data: tableData, rows, onDataChange, onCellChange });
1468
+ const handleCellMouseDownWithCommit = useCallback3(
1469
+ (rowIndex, colIndex) => {
1470
+ const isSameEditingCell = editingCell?.rowIndex === rowIndex && editingCell?.colIndex === colIndex;
1471
+ if (editingCell && !isSameEditingCell && !commitEdit()) {
1472
+ return;
1473
+ }
1474
+ handleCellMouseDown(rowIndex, colIndex);
1475
+ },
1476
+ [commitEdit, editingCell, handleCellMouseDown]
1477
+ );
1478
+ const clearHover = useCallback3(() => {
1479
+ setHoveredRowIndex(null);
1480
+ setHoveredGroupKey(null);
1481
+ }, []);
1482
+ const handleRowHover = useCallback3(
1483
+ (rowIndex, rowData) => {
1484
+ setHoveredRowIndex(rowIndex);
1485
+ if (!primaryRowSpanKey) {
1486
+ setHoveredGroupKey(null);
1487
+ return;
1488
+ }
1489
+ const groupValue = rowData[primaryRowSpanKey];
1490
+ setHoveredGroupKey(
1491
+ groupValue === null || groupValue === void 0 ? null : String(groupValue)
1492
+ );
1493
+ },
1494
+ [primaryRowSpanKey]
1495
+ );
1496
+ const handleToggleSelect = useCallback3(
1497
+ (row) => {
1498
+ if (!row.getCanSelect()) return;
1499
+ if (preserveRowSelection && row.getIsSelected()) {
1500
+ return;
1501
+ }
1502
+ row.toggleSelected();
1503
+ },
1504
+ [preserveRowSelection]
1505
+ );
1506
+ const handleToggleExpand = useCallback3(
1507
+ (rowKey) => {
1508
+ if (preventExpand) return;
1509
+ handleExpandedRowsChange(toggleExpandedRowId(rowKey, expandedRows));
1510
+ },
1511
+ [preventExpand, handleExpandedRowsChange, expandedRows]
1512
+ );
1513
+ const rowContextValue = useMemo2(() => {
1514
+ return {
1515
+ rowSpan: {
1516
+ enableRowSpan,
1517
+ primaryRowSpanKey,
1518
+ columnRowSpanMap,
1519
+ hoveredRowIndex,
1520
+ hoveredGroupKey,
1521
+ selectedGroupKeys,
1522
+ onRowHover: handleRowHover
1523
+ },
1524
+ selection: {
1525
+ rowSelectionMode,
1526
+ selectOnRowClick,
1527
+ onRowClick,
1528
+ getRowClassName
1529
+ },
1530
+ cellSelection: {
1531
+ enableCellSelection,
1532
+ activeSelectionBounds,
1533
+ dragState,
1534
+ onCellMouseDown: handleCellMouseDownWithCommit,
1535
+ onCellMouseEnter: handleCellMouseEnter,
1536
+ onFillHandleMouseDown: handleFillHandleMouseDown
1537
+ },
1538
+ cellEdit: {
1539
+ editingCell,
1540
+ draftValue,
1541
+ onDraftValueChange: setDraftValue,
1542
+ onStartEdit: startEdit,
1543
+ onCommitEdit: commitEdit,
1544
+ onCancelEdit: cancelEdit
1545
+ },
1546
+ expand: {
1547
+ enableExpand,
1548
+ toggleField,
1549
+ expandedRows,
1550
+ preventExpand,
1551
+ onToggleExpand: handleToggleExpand,
1552
+ expandRowLabel: labels.expandRow,
1553
+ collapseRowLabel: labels.collapseRow
1554
+ }
1555
+ };
1556
+ }, [
1557
+ enableRowSpan,
1558
+ primaryRowSpanKey,
1559
+ columnRowSpanMap,
1560
+ hoveredRowIndex,
1561
+ hoveredGroupKey,
1562
+ selectedGroupKeys,
1563
+ handleRowHover,
1564
+ rowSelectionMode,
1565
+ selectOnRowClick,
1566
+ onRowClick,
1567
+ getRowClassName,
1568
+ enableCellSelection,
1569
+ activeSelectionBounds,
1570
+ dragState,
1571
+ handleCellMouseDownWithCommit,
1572
+ handleCellMouseEnter,
1573
+ handleFillHandleMouseDown,
1574
+ editingCell,
1575
+ draftValue,
1576
+ setDraftValue,
1577
+ startEdit,
1578
+ commitEdit,
1579
+ cancelEdit,
1580
+ enableExpand,
1581
+ toggleField,
1582
+ expandedRows,
1583
+ preventExpand,
1584
+ handleToggleExpand,
1585
+ labels.expandRow,
1586
+ labels.collapseRow
1587
+ ]);
1588
+ return {
1589
+ table,
1590
+ tableData,
1591
+ rows,
1592
+ columnCount,
1593
+ selectedCount,
1594
+ labels,
1595
+ emptyText: labels.empty,
1596
+ loadingText: labels.loading,
1597
+ selectionLabel: labels.selection,
1598
+ enableCellSelection,
1599
+ shouldVirtualize,
1600
+ scrollRef,
1601
+ rowVirtualizer,
1602
+ virtualRows,
1603
+ paddingTop,
1604
+ paddingBottom,
1605
+ rowContextValue,
1606
+ handleToggleSelect,
1607
+ clearHover
1608
+ };
1609
+ }
1610
+
1611
+ // src/components/ui/table/components/DataTable/DataTable.tsx
1612
+ import { Fragment as Fragment2, jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
1613
+ function DefaultPending({
1614
+ loadingText,
1615
+ className
1616
+ }) {
1617
+ return /* @__PURE__ */ jsx5("div", { className: cn("DataTableJSX", "DataTableJSX--pending", className), children: /* @__PURE__ */ jsx5("span", { className: "data-table-loading-text", children: loadingText }) });
1618
+ }
1619
+ function DefaultEmpty({
1620
+ emptyText,
1621
+ columnCount
1622
+ }) {
1623
+ return /* @__PURE__ */ jsx5("tr", { children: /* @__PURE__ */ jsx5("td", { colSpan: columnCount, className: "data-table-empty-cell", children: emptyText }) });
1624
+ }
1625
+ function DataTable({
1626
+ isPending = false,
1627
+ summary,
1628
+ toolbar,
1629
+ filteredCount,
1630
+ totalCount,
1631
+ className,
1632
+ slots,
1633
+ ...glideOptions
1634
+ }) {
1635
+ const {
1636
+ table,
1637
+ tableData,
1638
+ rows,
1639
+ columnCount,
1640
+ selectedCount,
1641
+ emptyText,
1642
+ loadingText,
1643
+ selectionLabel,
1644
+ enableCellSelection,
1645
+ shouldVirtualize,
1646
+ scrollRef,
1647
+ rowVirtualizer,
1648
+ virtualRows,
1649
+ paddingTop,
1650
+ paddingBottom,
1651
+ rowContextValue,
1652
+ handleToggleSelect,
1653
+ clearHover
1654
+ } = useGlideTable(glideOptions);
1655
+ const ToolbarSlot = slots?.Toolbar ?? DataTableToolbar;
1656
+ const RowSlot = slots?.Row ?? DataTableRow;
1657
+ const PendingSlot = slots?.Pending ?? DefaultPending;
1658
+ const EmptySlot = slots?.Empty ?? DefaultEmpty;
1659
+ if (isPending) {
1660
+ return /* @__PURE__ */ jsx5(PendingSlot, { loadingText, className });
1661
+ }
1662
+ return /* @__PURE__ */ jsxs4(
1663
+ "div",
1664
+ {
1665
+ className: cn(
1666
+ "DataTableJSX",
1667
+ !enableCellSelection && "DataTableJSX--no-cell-selection",
1668
+ className
1669
+ ),
1670
+ children: [
1671
+ /* @__PURE__ */ jsx5(
1672
+ ToolbarSlot,
1673
+ {
1674
+ filteredCount: filteredCount ?? tableData.length,
1675
+ totalCount,
1676
+ summary,
1677
+ selectedCount,
1678
+ selectionLabel,
1679
+ toolbar
1680
+ }
1681
+ ),
1682
+ /* @__PURE__ */ jsx5("div", { ref: scrollRef, className: "data-table-scroll", children: /* @__PURE__ */ jsxs4(
1683
+ "table",
1684
+ {
1685
+ className: "data-table",
1686
+ onDragStart: enableCellSelection ? (event) => event.preventDefault() : void 0,
1687
+ children: [
1688
+ /* @__PURE__ */ jsx5("thead", { className: "data-table-head", children: table.getHeaderGroups().map((headerGroup) => /* @__PURE__ */ jsx5("tr", { className: "data-table-head-row", children: headerGroup.headers.map((header) => {
1689
+ const align = header.column.columnDef.meta?.align ?? "center";
1690
+ const headerClassName = header.column.columnDef.meta?.headerClassName;
1691
+ return /* @__PURE__ */ jsx5(
1692
+ "th",
1693
+ {
1694
+ style: { width: header.getSize() !== 150 ? header.getSize() : void 0 },
1695
+ className: cn(
1696
+ "data-table-head-cell",
1697
+ CELL_ALIGN_CLASS[align],
1698
+ headerClassName
1699
+ ),
1700
+ children: header.isPlaceholder ? null : flexRender2(header.column.columnDef.header, header.getContext())
1701
+ },
1702
+ header.id
1703
+ );
1704
+ }) }, headerGroup.id)) }),
1705
+ /* @__PURE__ */ jsx5(DataTableContextProvider, { value: rowContextValue, children: /* @__PURE__ */ jsx5("tbody", { onMouseLeave: clearHover, className: "data-table-body", children: rows.length === 0 ? /* @__PURE__ */ jsx5(EmptySlot, { emptyText, columnCount }) : shouldVirtualize ? /* @__PURE__ */ jsxs4(Fragment2, { children: [
1706
+ paddingTop > 0 && /* @__PURE__ */ jsx5("tr", { "aria-hidden": true, className: "data-table-virtual-spacer", children: /* @__PURE__ */ jsx5(
1707
+ "td",
1708
+ {
1709
+ colSpan: columnCount,
1710
+ style: { height: paddingTop },
1711
+ className: "data-table-virtual-spacer-cell"
1712
+ }
1713
+ ) }),
1714
+ virtualRows.map((virtualRow) => {
1715
+ const row = rows[virtualRow.index];
1716
+ if (!row) return null;
1717
+ return /* @__PURE__ */ jsx5(
1718
+ RowSlot,
1719
+ {
1720
+ row,
1721
+ virtualIndex: virtualRow.index,
1722
+ measureElement: rowVirtualizer.measureElement,
1723
+ onToggleSelect: () => handleToggleSelect(row)
1724
+ },
1725
+ row.id
1726
+ );
1727
+ }),
1728
+ paddingBottom > 0 && /* @__PURE__ */ jsx5("tr", { "aria-hidden": true, className: "data-table-virtual-spacer", children: /* @__PURE__ */ jsx5(
1729
+ "td",
1730
+ {
1731
+ colSpan: columnCount,
1732
+ style: { height: paddingBottom },
1733
+ className: "data-table-virtual-spacer-cell"
1734
+ }
1735
+ ) })
1736
+ ] }) : rows.map((row) => /* @__PURE__ */ jsx5(
1737
+ RowSlot,
1738
+ {
1739
+ row,
1740
+ onToggleSelect: () => handleToggleSelect(row)
1741
+ },
1742
+ row.id
1743
+ )) }) })
1744
+ ]
1745
+ }
1746
+ ) })
1747
+ ]
1748
+ }
1749
+ );
1750
+ }
1751
+
1752
+ // src/components/ui/table/components/Table/Table.tsx
1753
+ import { useCallback as useCallback4, useMemo as useMemo3, useState as useState4 } from "react";
1754
+
1755
+ // src/components/ui/table/components/Table/buildColumnDef.tsx
1756
+ import { jsx as jsx6, jsxs as jsxs5 } from "react/jsx-runtime";
1757
+ function SortableHeader({
1758
+ label,
1759
+ field,
1760
+ sort,
1761
+ onSort
1762
+ }) {
1763
+ const isActive = sort?.field === field;
1764
+ const Icon = isActive ? sort.direction === "asc" ? ArrowUp : ArrowDown : ArrowUpDown;
1765
+ return /* @__PURE__ */ jsxs5(
1766
+ "button",
1767
+ {
1768
+ type: "button",
1769
+ className: cn("SortableHeaderJSX", isActive ? "is-active" : "is-inactive"),
1770
+ onClick: () => onSort(field),
1771
+ children: [
1772
+ /* @__PURE__ */ jsx6("span", { children: label }),
1773
+ /* @__PURE__ */ jsx6(Icon, { className: "sortable-header-icon" })
1774
+ ]
1775
+ }
1776
+ );
1777
+ }
1778
+ function buildColumnDef(props, sort, onSort) {
1779
+ const {
1780
+ field,
1781
+ virtual = false,
1782
+ children,
1783
+ sortable = false,
1784
+ width,
1785
+ align,
1786
+ rowSpan,
1787
+ rowSpanKey,
1788
+ editable,
1789
+ editType,
1790
+ className,
1791
+ headerClassName,
1792
+ render
1793
+ } = props;
1794
+ return {
1795
+ id: field,
1796
+ ...!virtual ? { accessorKey: field } : {},
1797
+ size: width ?? 150,
1798
+ header: sortable ? () => /* @__PURE__ */ jsx6(SortableHeader, { label: children, field, sort, onSort }) : (
1799
+ // eslint-disable-next-line @typescript-eslint/promise-function-async
1800
+ () => children
1801
+ ),
1802
+ ...render ? {
1803
+ // eslint-disable-next-line @typescript-eslint/promise-function-async
1804
+ cell: ({ row, getValue }) => render(
1805
+ getValue(),
1806
+ row,
1807
+ row.index
1808
+ )
1809
+ } : {},
1810
+ meta: {
1811
+ align,
1812
+ rowSpan,
1813
+ rowSpanKey,
1814
+ editable,
1815
+ editType,
1816
+ className,
1817
+ headerClassName
1818
+ }
1819
+ };
1820
+ }
1821
+
1822
+ // src/components/ui/table/components/Table/parseTableChildren.ts
1823
+ import { Children } from "react";
1824
+
1825
+ // src/components/ui/table/components/Table/tableChildTypes.ts
1826
+ import { isValidElement } from "react";
1827
+ var TABLE_HEADER_DISPLAY_NAME = "Table.Header";
1828
+ var TABLE_BODY_DISPLAY_NAME = "Table.Body";
1829
+ var TABLE_COLUMN_DISPLAY_NAME = "Table.Column";
1830
+ var TABLE_PAGINATION_DISPLAY_NAME = "Table.Pagination";
1831
+ function getComponentDisplayName(type) {
1832
+ if (typeof type === "function" || typeof type === "object" && type !== null) {
1833
+ return type.displayName;
1834
+ }
1835
+ return void 0;
1836
+ }
1837
+ function isTableHeaderElement(child) {
1838
+ return isValidElement(child) && getComponentDisplayName(child.type) === TABLE_HEADER_DISPLAY_NAME;
1839
+ }
1840
+ function isTableBodyElement(child) {
1841
+ return isValidElement(child) && getComponentDisplayName(child.type) === TABLE_BODY_DISPLAY_NAME;
1842
+ }
1843
+ function isTableColumnElement(child) {
1844
+ return isValidElement(child) && getComponentDisplayName(child.type) === TABLE_COLUMN_DISPLAY_NAME;
1845
+ }
1846
+ function isTablePaginationElement(child) {
1847
+ return isValidElement(child) && getComponentDisplayName(child.type) === TABLE_PAGINATION_DISPLAY_NAME;
1848
+ }
1849
+
1850
+ // src/components/ui/table/components/Table/parseTableChildren.ts
1851
+ function parseTableChildren(children) {
1852
+ const slots = {
1853
+ header: null,
1854
+ body: null,
1855
+ pagination: null
1856
+ };
1857
+ for (const child of Children.toArray(children)) {
1858
+ if (isTableHeaderElement(child)) {
1859
+ slots.header = child;
1860
+ continue;
1861
+ }
1862
+ if (isTableBodyElement(child)) {
1863
+ slots.body = child;
1864
+ continue;
1865
+ }
1866
+ if (isTablePaginationElement(child)) {
1867
+ slots.pagination = child;
1868
+ }
1869
+ }
1870
+ return slots;
1871
+ }
1872
+ function extractColumnElements(header) {
1873
+ if (!header) return [];
1874
+ const { children } = header.props;
1875
+ return Children.toArray(children).filter(isTableColumnElement);
1876
+ }
1877
+
1878
+ // src/components/ui/table/components/Table/TableBody.tsx
1879
+ function TableBody() {
1880
+ return null;
1881
+ }
1882
+ TableBody.displayName = TABLE_BODY_DISPLAY_NAME;
1883
+
1884
+ // src/components/ui/table/components/Table/TableColumn.tsx
1885
+ function TableColumn(props) {
1886
+ void props;
1887
+ return null;
1888
+ }
1889
+ TableColumn.displayName = TABLE_COLUMN_DISPLAY_NAME;
1890
+
1891
+ // src/components/ui/table/components/Table/tableDataPipeline.ts
1892
+ function sortTableData(data, sort) {
1893
+ if (!sort) return data;
1894
+ const { field, direction } = sort;
1895
+ const multiplier = direction === "asc" ? 1 : -1;
1896
+ return [...data].sort((left, right) => {
1897
+ const leftValue = left[field];
1898
+ const rightValue = right[field];
1899
+ if ((leftValue === null || leftValue === void 0) && (rightValue === null || rightValue === void 0)) {
1900
+ return 0;
1901
+ }
1902
+ if (leftValue === null || leftValue === void 0) return 1;
1903
+ if (rightValue === null || rightValue === void 0) return -1;
1904
+ if (typeof leftValue === "number" && typeof rightValue === "number") {
1905
+ return (leftValue - rightValue) * multiplier;
1906
+ }
1907
+ return String(leftValue).localeCompare(String(rightValue), "ko") * multiplier;
1908
+ });
1909
+ }
1910
+ function paginateTableData(data, page, pageSize) {
1911
+ const safePage = Math.max(1, page);
1912
+ const start = (safePage - 1) * pageSize;
1913
+ return data.slice(start, start + pageSize);
1914
+ }
1915
+ function getTotalPages(totalCount, pageSize) {
1916
+ if (pageSize <= 0) return 1;
1917
+ return Math.max(1, Math.ceil(totalCount / pageSize));
1918
+ }
1919
+
1920
+ // src/components/ui/table/components/Table/TableHeader.tsx
1921
+ function TableHeader(props) {
1922
+ void props;
1923
+ return null;
1924
+ }
1925
+ TableHeader.displayName = TABLE_HEADER_DISPLAY_NAME;
1926
+
1927
+ // src/components/ui/table/components/Table/TablePagination.tsx
1928
+ import { jsx as jsx7, jsxs as jsxs6 } from "react/jsx-runtime";
1929
+ function TablePagination({
1930
+ page,
1931
+ pageSize = 10,
1932
+ totalCount = 0,
1933
+ onChange,
1934
+ className
1935
+ }) {
1936
+ const totalPages = getTotalPages(totalCount, pageSize);
1937
+ const safePage = Math.min(Math.max(1, page), totalPages);
1938
+ const canGoPrev = safePage > 1;
1939
+ const canGoNext = safePage < totalPages;
1940
+ return /* @__PURE__ */ jsxs6("div", { className: cn("TablePaginationJSX", className), children: [
1941
+ /* @__PURE__ */ jsx7(
1942
+ "button",
1943
+ {
1944
+ type: "button",
1945
+ className: "pagination-button",
1946
+ disabled: !canGoPrev,
1947
+ onClick: () => onChange(safePage - 1),
1948
+ "aria-label": "Previous page",
1949
+ children: /* @__PURE__ */ jsx7(ChevronLeft, { className: "pagination-button-icon" })
1950
+ }
1951
+ ),
1952
+ /* @__PURE__ */ jsxs6("span", { className: "pagination-label", children: [
1953
+ safePage,
1954
+ " / ",
1955
+ totalPages
1956
+ ] }),
1957
+ /* @__PURE__ */ jsx7(
1958
+ "button",
1959
+ {
1960
+ type: "button",
1961
+ className: "pagination-button",
1962
+ disabled: !canGoNext,
1963
+ onClick: () => onChange(safePage + 1),
1964
+ "aria-label": "Next page",
1965
+ children: /* @__PURE__ */ jsx7(ChevronRight, { className: "pagination-button-icon" })
1966
+ }
1967
+ )
1968
+ ] });
1969
+ }
1970
+ TablePagination.displayName = TABLE_PAGINATION_DISPLAY_NAME;
1971
+
1972
+ // src/components/ui/table/components/Table/Table.tsx
1973
+ import { jsx as jsx8, jsxs as jsxs7 } from "react/jsx-runtime";
1974
+ function TableRoot({
1975
+ data,
1976
+ children,
1977
+ className,
1978
+ totalCount,
1979
+ filteredCount,
1980
+ ...dataTableProps
1981
+ }) {
1982
+ const { header, pagination: paginationElement } = useMemo3(
1983
+ () => parseTableChildren(children),
1984
+ [children]
1985
+ );
1986
+ const [sort, setSort] = useState4(null);
1987
+ const handleSort = useCallback4((field) => {
1988
+ setSort((previous) => {
1989
+ if (previous?.field !== field) {
1990
+ return { field, direction: "asc" };
1991
+ }
1992
+ if (previous.direction === "asc") {
1993
+ return { field, direction: "desc" };
1994
+ }
1995
+ return null;
1996
+ });
1997
+ }, []);
1998
+ const columns = useMemo3(() => {
1999
+ return extractColumnElements(header).map(
2000
+ (columnElement) => buildColumnDef(columnElement.props, sort, handleSort)
2001
+ );
2002
+ }, [header, sort, handleSort]);
2003
+ const paginationProps = paginationElement?.props;
2004
+ const pageSize = paginationProps?.pageSize ?? 10;
2005
+ const page = paginationProps?.page ?? 1;
2006
+ const resolvedTotalCount = paginationProps?.totalCount ?? totalCount ?? data.length;
2007
+ const tableData = useMemo3(() => {
2008
+ const sortedData = sortTableData(data, sort);
2009
+ if (!paginationProps) return sortedData;
2010
+ return paginateTableData(sortedData, page, pageSize);
2011
+ }, [data, sort, paginationProps, page, pageSize]);
2012
+ if (columns.length === 0) {
2013
+ console.warn("[Table] Declare at least one Table.Column inside Table.Header.");
2014
+ }
2015
+ return /* @__PURE__ */ jsxs7("div", { className: "TableJSX", children: [
2016
+ /* @__PURE__ */ jsx8(
2017
+ DataTable,
2018
+ {
2019
+ ...dataTableProps,
2020
+ data: tableData,
2021
+ columns,
2022
+ totalCount: paginationProps ? resolvedTotalCount : totalCount,
2023
+ filteredCount: filteredCount ?? data.length,
2024
+ className: cn(className, paginationProps && "DataTableJSX--with-pagination")
2025
+ }
2026
+ ),
2027
+ paginationProps && /* @__PURE__ */ jsx8(
2028
+ TablePagination,
2029
+ {
2030
+ page,
2031
+ pageSize,
2032
+ totalCount: resolvedTotalCount,
2033
+ onChange: paginationProps.onChange,
2034
+ className: paginationProps.className
2035
+ }
2036
+ )
2037
+ ] });
2038
+ }
2039
+ function createTable() {
2040
+ function Column(props) {
2041
+ void props;
2042
+ return null;
2043
+ }
2044
+ Column.displayName = TABLE_COLUMN_DISPLAY_NAME;
2045
+ return Object.assign(
2046
+ function BoundTable(props) {
2047
+ return /* @__PURE__ */ jsx8(TableRoot, { ...props });
2048
+ },
2049
+ {
2050
+ Header: TableHeader,
2051
+ Column,
2052
+ Body: TableBody,
2053
+ Pagination: TablePagination
2054
+ }
2055
+ );
2056
+ }
2057
+ var Table = Object.assign(TableRoot, {
2058
+ Header: TableHeader,
2059
+ Column: TableColumn,
2060
+ Body: TableBody,
2061
+ Pagination: TablePagination
2062
+ });
2063
+ export {
2064
+ DataTable,
2065
+ Table,
2066
+ createTable
2067
+ };