react-glide-table 0.0.1 → 1.0.1

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.cjs ADDED
@@ -0,0 +1,1691 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ DataTable: () => DataTable,
24
+ Table: () => Table,
25
+ createTable: () => createTable
26
+ });
27
+ module.exports = __toCommonJS(index_exports);
28
+
29
+ // src/components/ui/table/components/DataTable/DataTable.tsx
30
+ var import_react_table2 = require("@tanstack/react-table");
31
+ var import_react_virtual = require("@tanstack/react-virtual");
32
+ var import_react6 = require("react");
33
+
34
+ // src/components/ui/table/components/DataTable/DataTableRow.tsx
35
+ var import_react_table = require("@tanstack/react-table");
36
+ var import_react3 = require("react");
37
+
38
+ // src/components/ui/table/constants.ts
39
+ var CELL_ALIGN_CLASS = {
40
+ left: "cell-align-left",
41
+ center: "cell-align-center",
42
+ right: "cell-align-right"
43
+ };
44
+ var ROW_HOVER_CLASS = "row-hoverable";
45
+ var ROW_HOVERED_BG_CLASS = "row-hovered";
46
+ var CELL_SELECTION_FILL_CLASS = "cell-selection-fill";
47
+ var DATA_TABLE_ROW_HEIGHT = 44;
48
+ var DATA_TABLE_VIRTUAL_OVERSCAN = 8;
49
+
50
+ // src/components/ui/table/DataTableContext.tsx
51
+ var import_react = require("react");
52
+ var import_jsx_runtime = require("react/jsx-runtime");
53
+ var DataTableContext = (0, import_react.createContext)(null);
54
+ function useDataTableRowContext() {
55
+ const context = (0, import_react.use)(DataTableContext);
56
+ if (!context) {
57
+ throw new Error("useDataTableRowContext must be used within a DataTableContextProvider");
58
+ }
59
+ return context;
60
+ }
61
+ function DataTableContextProvider({
62
+ value,
63
+ children
64
+ }) {
65
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DataTableContext, { value, children });
66
+ }
67
+
68
+ // src/components/ui/table/features/cell-edit/cellEdit.ts
69
+ function getColumnAccessorKey(columnDef) {
70
+ if (columnDef.accessorKey !== void 0 && columnDef.accessorKey !== null) {
71
+ return String(columnDef.accessorKey);
72
+ }
73
+ return columnDef.id;
74
+ }
75
+ function isColumnEditable(columnDef) {
76
+ return Boolean(columnDef.meta?.editable);
77
+ }
78
+ function getColumnEditType(columnDef) {
79
+ return columnDef.meta?.editType ?? "text";
80
+ }
81
+ function parseCellEditValue(raw, editType) {
82
+ if (editType === "text") {
83
+ return { ok: true, value: raw };
84
+ }
85
+ const trimmed = raw.trim();
86
+ if (trimmed === "") {
87
+ return { ok: true, value: null };
88
+ }
89
+ const parsed = Number(trimmed);
90
+ if (Number.isNaN(parsed)) {
91
+ return { ok: false };
92
+ }
93
+ return { ok: true, value: parsed };
94
+ }
95
+ function getCellEditDraftValue(value) {
96
+ if (value === null || value === void 0) return "";
97
+ return String(value);
98
+ }
99
+ function applyCellEdit(data, rows, rowIndex, colIndex, raw) {
100
+ const cell = rows[rowIndex]?.getVisibleCells()[colIndex];
101
+ if (!cell) return null;
102
+ const columnDef = cell.column.columnDef;
103
+ if (!isColumnEditable(columnDef)) return null;
104
+ const accessorKey = getColumnAccessorKey(columnDef);
105
+ if (!accessorKey) return null;
106
+ const parsed = parseCellEditValue(raw, getColumnEditType(columnDef));
107
+ if (!parsed.ok) return null;
108
+ const newData = data.map((row) => ({ ...row }));
109
+ if (!newData[rowIndex]) return null;
110
+ newData[rowIndex][accessorKey] = parsed.value;
111
+ return newData;
112
+ }
113
+
114
+ // src/components/ui/table/features/cell-selection/cellSelection.ts
115
+ var INITIAL_DRAG_STATE = {
116
+ isSelecting: false,
117
+ isFillDragging: false,
118
+ start: null,
119
+ end: null,
120
+ fillAnchor: null,
121
+ fillEnd: null
122
+ };
123
+ function getCellSelectionBounds(start, end) {
124
+ if (!start || !end) return null;
125
+ return {
126
+ startRow: Math.min(start.row, end.row),
127
+ endRow: Math.max(start.row, end.row),
128
+ startCol: Math.min(start.col, end.col),
129
+ endCol: Math.max(start.col, end.col)
130
+ };
131
+ }
132
+ function getRowIndexInMergedCell(clientY, cellElement, rowIndex, rowSpan) {
133
+ if (rowSpan <= 1) return rowIndex;
134
+ const rect = cellElement.getBoundingClientRect();
135
+ const relativeY = clientY - rect.top;
136
+ const rowHeight = rect.height / rowSpan;
137
+ const offset = Math.min(Math.max(Math.floor(relativeY / rowHeight), 0), rowSpan - 1);
138
+ return rowIndex + offset;
139
+ }
140
+ function isCellInSelection(rowIndex, colIndex, bounds, rowSpan = 1) {
141
+ if (!bounds) return false;
142
+ const cellEndRow = rowIndex + rowSpan - 1;
143
+ return cellEndRow >= bounds.startRow && rowIndex <= bounds.endRow && colIndex >= bounds.startCol && colIndex <= bounds.endCol;
144
+ }
145
+ function getActiveSelectionBounds(dragState, selectionBounds) {
146
+ if (dragState.isFillDragging && dragState.fillAnchor && dragState.fillEnd) {
147
+ return getCellSelectionBounds(dragState.fillAnchor, dragState.fillEnd);
148
+ }
149
+ return selectionBounds;
150
+ }
151
+ var SELECTION_EDGE_WIDTH_PX = 2;
152
+ var SELECTION_EDGE_COLOR = "var(--color-brand-primary)";
153
+ function getCellSelectionEdgeStyle(rowIndex, colIndex, bounds, rowSpan = 1) {
154
+ if (!isCellInSelection(rowIndex, colIndex, bounds, rowSpan) || !bounds) return void 0;
155
+ const cellEndRow = rowIndex + rowSpan - 1;
156
+ const isTopEdge = bounds.startRow >= rowIndex && bounds.startRow <= cellEndRow;
157
+ const isBottomEdge = bounds.endRow >= rowIndex && bounds.endRow <= cellEndRow;
158
+ const isLeftEdge = colIndex === bounds.startCol;
159
+ const isRightEdge = colIndex === bounds.endCol;
160
+ const shadows = [];
161
+ if (isTopEdge) {
162
+ shadows.push(`inset 0 ${SELECTION_EDGE_WIDTH_PX}px 0 0 ${SELECTION_EDGE_COLOR}`);
163
+ }
164
+ if (isBottomEdge) {
165
+ shadows.push(`inset 0 -${SELECTION_EDGE_WIDTH_PX}px 0 0 ${SELECTION_EDGE_COLOR}`);
166
+ }
167
+ if (isLeftEdge) {
168
+ shadows.push(`inset ${SELECTION_EDGE_WIDTH_PX}px 0 0 0 ${SELECTION_EDGE_COLOR}`);
169
+ }
170
+ if (isRightEdge) {
171
+ shadows.push(`inset -${SELECTION_EDGE_WIDTH_PX}px 0 0 0 ${SELECTION_EDGE_COLOR}`);
172
+ }
173
+ return shadows.length > 0 ? { boxShadow: shadows.join(", ") } : void 0;
174
+ }
175
+
176
+ // src/components/ui/table/features/row-expand/row-expand.ts
177
+ var import_react2 = require("react");
178
+ function getFieldValue(row, key) {
179
+ return row[key];
180
+ }
181
+ function canExpandRow(row) {
182
+ const children = row.children;
183
+ const level = row.level;
184
+ return Array.isArray(children) && children.length > 0 && (level === 0 || level === void 0);
185
+ }
186
+ function toggleExpandedRowId(rowId, previous) {
187
+ const next = new Set(previous);
188
+ if (next.has(rowId)) {
189
+ next.delete(rowId);
190
+ } else {
191
+ next.add(rowId);
192
+ }
193
+ return next;
194
+ }
195
+ var useConvertTreeData = ({
196
+ data,
197
+ enabled = true,
198
+ toggleField = "materialCode",
199
+ childField = "assemblyCode",
200
+ flattenField = "assemblyMaterials",
201
+ preventExpand = false,
202
+ startIndex = 1,
203
+ expandedRows,
204
+ onExpandedRowsChange
205
+ }) => {
206
+ const onExpandedRowsChangeRef = (0, import_react2.useRef)(onExpandedRowsChange);
207
+ const hasInitializedRef = (0, import_react2.useRef)(false);
208
+ (0, import_react2.useEffect)(() => {
209
+ onExpandedRowsChangeRef.current = onExpandedRowsChange;
210
+ }, [onExpandedRowsChange]);
211
+ (0, import_react2.useEffect)(() => {
212
+ if (!data || data.length === 0) {
213
+ hasInitializedRef.current = false;
214
+ return;
215
+ }
216
+ if (!enabled || hasInitializedRef.current) return;
217
+ const ids = data.map((item) => getFieldValue(item, toggleField)).filter((value) => typeof value === "string" && value.length > 0);
218
+ onExpandedRowsChangeRef.current?.(new Set(ids));
219
+ hasInitializedRef.current = true;
220
+ }, [enabled, data, toggleField]);
221
+ const processedData = (0, import_react2.useMemo)(() => {
222
+ if (!enabled || !data || data.length === 0) return [];
223
+ const flattenedData = [];
224
+ const flattenItems = (items) => {
225
+ items.forEach((item) => {
226
+ const newItem = { ...item };
227
+ const nested = newItem[flattenField];
228
+ if (Array.isArray(nested)) {
229
+ const children = nested.map(
230
+ (child) => typeof child === "object" && child !== null ? { ...child } : child
231
+ );
232
+ delete newItem[flattenField];
233
+ flattenedData.push(newItem);
234
+ children.forEach((child) => {
235
+ if (typeof child === "object" && child !== null) {
236
+ ;
237
+ child[childField] = newItem[toggleField];
238
+ }
239
+ });
240
+ flattenItems(children);
241
+ } else {
242
+ flattenedData.push(newItem);
243
+ }
244
+ });
245
+ };
246
+ flattenItems(data);
247
+ const dataWithLevels = flattenedData.map((item) => ({
248
+ ...item,
249
+ level: 0,
250
+ children: [],
251
+ processed: false
252
+ }));
253
+ const itemMap = /* @__PURE__ */ new Map();
254
+ dataWithLevels.forEach((item) => {
255
+ const key = getFieldValue(item, toggleField);
256
+ if (typeof key !== "string" || !key) return;
257
+ if (!itemMap.has(key)) {
258
+ itemMap.set(key, []);
259
+ }
260
+ itemMap.get(key)?.push(item);
261
+ });
262
+ const rootItems = [];
263
+ dataWithLevels.forEach((item) => {
264
+ if (!getFieldValue(item, childField)) {
265
+ rootItems.push(item);
266
+ item.processed = true;
267
+ }
268
+ });
269
+ dataWithLevels.forEach((item) => {
270
+ const parentKey = getFieldValue(item, childField);
271
+ if (!parentKey || item.processed) return;
272
+ const parentItems = dataWithLevels.filter(
273
+ (parent) => getFieldValue(parent, toggleField) === parentKey && !getFieldValue(parent, childField)
274
+ );
275
+ if (parentItems.length > 0) {
276
+ const parent = parentItems[0];
277
+ item.level = parent.level + 1;
278
+ parent.children.push(item);
279
+ item.processed = true;
280
+ } else {
281
+ const otherParents = itemMap.get(String(parentKey)) || [];
282
+ if (otherParents.length > 0) {
283
+ const parent = otherParents[0];
284
+ item.level = parent.level + 1;
285
+ parent.children.push(item);
286
+ item.processed = true;
287
+ } else {
288
+ rootItems.push(item);
289
+ item.processed = true;
290
+ }
291
+ }
292
+ });
293
+ return rootItems;
294
+ }, [enabled, data, toggleField, childField, flattenField]);
295
+ const flattenTree = (0, import_react2.useMemo)(() => {
296
+ if (!enabled) return [];
297
+ const flatten = (nodes, result = [], level = 0) => {
298
+ nodes.forEach((node, index) => {
299
+ const currentIndex = level === 0 ? `${index + startIndex}` : `${level}-${index + 1}`;
300
+ const toggleValue = getFieldValue(node, toggleField);
301
+ const uniqueId = `${index}-${String(toggleValue ?? "")}`;
302
+ result.push({
303
+ ...node,
304
+ treeNo: currentIndex,
305
+ uniqueId,
306
+ processed: true
307
+ });
308
+ const shouldExpandChildren = node.children.length > 0 && (preventExpand || typeof toggleValue === "string" && expandedRows?.has(toggleValue));
309
+ if (shouldExpandChildren) {
310
+ flatten(node.children, result, index + startIndex);
311
+ }
312
+ });
313
+ return result;
314
+ };
315
+ const flattenedData = flatten(processedData, [], 0);
316
+ flattenedData.forEach((item) => {
317
+ if (getFieldValue(item, childField)) {
318
+ const parentItem = flattenedData.find(
319
+ (parent) => getFieldValue(parent, toggleField) === getFieldValue(item, childField)
320
+ );
321
+ const parentAmount = parentItem ? Number(getFieldValue(parentItem, "amount") ?? 1) : 1;
322
+ item.parentCount = parentAmount || 1;
323
+ } else {
324
+ item.parentCount = 1;
325
+ }
326
+ });
327
+ return flattenedData;
328
+ }, [enabled, processedData, startIndex, toggleField, childField, preventExpand, expandedRows]);
329
+ const sortedData = (0, import_react2.useMemo)(() => {
330
+ if (!enabled) {
331
+ return data ?? [];
332
+ }
333
+ return [...flattenTree].sort((a, b) => {
334
+ const aParts = String(a.treeNo ?? "").split("-").map(Number);
335
+ const bParts = String(b.treeNo ?? "").split("-").map(Number);
336
+ for (let i = 0; i < Math.max(aParts.length, bParts.length); i++) {
337
+ const aVal = aParts[i] || 0;
338
+ const bVal = bParts[i] || 0;
339
+ if (aVal !== bVal) {
340
+ return aVal - bVal;
341
+ }
342
+ }
343
+ return 0;
344
+ });
345
+ }, [enabled, data, flattenTree]);
346
+ return sortedData;
347
+ };
348
+
349
+ // src/components/ui/table/components/icons.tsx
350
+ var import_jsx_runtime2 = require("react/jsx-runtime");
351
+ function ChevronDown({ className, "aria-hidden": ariaHidden = true }) {
352
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
353
+ "svg",
354
+ {
355
+ className,
356
+ "aria-hidden": ariaHidden,
357
+ width: "16",
358
+ height: "16",
359
+ viewBox: "0 0 24 24",
360
+ fill: "none",
361
+ stroke: "currentColor",
362
+ strokeWidth: "2",
363
+ strokeLinecap: "round",
364
+ strokeLinejoin: "round",
365
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "m6 9 6 6 6-6" })
366
+ }
367
+ );
368
+ }
369
+ function ChevronUp({ className, "aria-hidden": ariaHidden = true }) {
370
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
371
+ "svg",
372
+ {
373
+ className,
374
+ "aria-hidden": ariaHidden,
375
+ width: "16",
376
+ height: "16",
377
+ viewBox: "0 0 24 24",
378
+ fill: "none",
379
+ stroke: "currentColor",
380
+ strokeWidth: "2",
381
+ strokeLinecap: "round",
382
+ strokeLinejoin: "round",
383
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "m18 15-6-6-6 6" })
384
+ }
385
+ );
386
+ }
387
+ function ChevronLeft({ className, "aria-hidden": ariaHidden = true }) {
388
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
389
+ "svg",
390
+ {
391
+ className,
392
+ "aria-hidden": ariaHidden,
393
+ width: "16",
394
+ height: "16",
395
+ viewBox: "0 0 24 24",
396
+ fill: "none",
397
+ stroke: "currentColor",
398
+ strokeWidth: "2",
399
+ strokeLinecap: "round",
400
+ strokeLinejoin: "round",
401
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "m15 18-6-6 6-6" })
402
+ }
403
+ );
404
+ }
405
+ function ChevronRight({ className, "aria-hidden": ariaHidden = true }) {
406
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
407
+ "svg",
408
+ {
409
+ className,
410
+ "aria-hidden": ariaHidden,
411
+ width: "16",
412
+ height: "16",
413
+ viewBox: "0 0 24 24",
414
+ fill: "none",
415
+ stroke: "currentColor",
416
+ strokeWidth: "2",
417
+ strokeLinecap: "round",
418
+ strokeLinejoin: "round",
419
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "m9 18 6-6-6-6" })
420
+ }
421
+ );
422
+ }
423
+ function ArrowUp({ className, "aria-hidden": ariaHidden = true }) {
424
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
425
+ "svg",
426
+ {
427
+ className,
428
+ "aria-hidden": ariaHidden,
429
+ width: "14",
430
+ height: "14",
431
+ viewBox: "0 0 24 24",
432
+ fill: "none",
433
+ stroke: "currentColor",
434
+ strokeWidth: "2",
435
+ strokeLinecap: "round",
436
+ strokeLinejoin: "round",
437
+ children: [
438
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "m18 15-6-6-6 6" }),
439
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M12 21V9" })
440
+ ]
441
+ }
442
+ );
443
+ }
444
+ function ArrowDown({ className, "aria-hidden": ariaHidden = true }) {
445
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
446
+ "svg",
447
+ {
448
+ className,
449
+ "aria-hidden": ariaHidden,
450
+ width: "14",
451
+ height: "14",
452
+ viewBox: "0 0 24 24",
453
+ fill: "none",
454
+ stroke: "currentColor",
455
+ strokeWidth: "2",
456
+ strokeLinecap: "round",
457
+ strokeLinejoin: "round",
458
+ children: [
459
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "m6 9 6 6 6-6" }),
460
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M12 3v12" })
461
+ ]
462
+ }
463
+ );
464
+ }
465
+ function ArrowUpDown({ className, "aria-hidden": ariaHidden = true }) {
466
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
467
+ "svg",
468
+ {
469
+ className,
470
+ "aria-hidden": ariaHidden,
471
+ width: "14",
472
+ height: "14",
473
+ viewBox: "0 0 24 24",
474
+ fill: "none",
475
+ stroke: "currentColor",
476
+ strokeWidth: "2",
477
+ strokeLinecap: "round",
478
+ strokeLinejoin: "round",
479
+ children: [
480
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "m21 16-4 4-4-4" }),
481
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M17 20V4" }),
482
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "m3 8 4-4 4 4" }),
483
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: "M7 4v16" })
484
+ ]
485
+ }
486
+ );
487
+ }
488
+
489
+ // src/lib/cn.ts
490
+ function cn(...inputs) {
491
+ return inputs.filter(Boolean).join(" ");
492
+ }
493
+
494
+ // src/components/ui/table/components/DataTable/DataTableRow.tsx
495
+ var import_jsx_runtime3 = require("react/jsx-runtime");
496
+ function resolveExpandCellIndex(cells, toggleField) {
497
+ if (!toggleField) return 0;
498
+ const matchedIndex = cells.findIndex(
499
+ (cell) => cell.column.id === toggleField
500
+ );
501
+ if (matchedIndex >= 0) return matchedIndex;
502
+ const noColumnIndex = cells.findIndex(
503
+ (cell) => cell.column.id === "no" || cell.column.id === "treeNo"
504
+ );
505
+ if (noColumnIndex >= 0 && noColumnIndex + 1 < cells.length) {
506
+ return noColumnIndex + 1;
507
+ }
508
+ return 0;
509
+ }
510
+ function DataTableRow({
511
+ row,
512
+ onToggleSelect,
513
+ virtualIndex,
514
+ measureElement
515
+ }) {
516
+ const { rowSpan, selection, cellSelection, cellEdit, expand } = useDataTableRowContext();
517
+ const {
518
+ enableRowSpan,
519
+ primaryRowSpanKey,
520
+ columnRowSpanMap,
521
+ hoveredRowIndex,
522
+ hoveredGroupKey,
523
+ selectedGroupKeys,
524
+ onRowHover
525
+ } = rowSpan;
526
+ const { rowSelectionMode, selectOnRowClick, onRowClick, getRowClassName } = selection;
527
+ const {
528
+ activeSelectionBounds,
529
+ dragState,
530
+ onCellMouseDown,
531
+ onCellMouseEnter,
532
+ onFillHandleMouseDown
533
+ } = cellSelection;
534
+ const {
535
+ editingCell,
536
+ draftValue,
537
+ onDraftValueChange,
538
+ onStartEdit,
539
+ onCommitEdit,
540
+ onCancelEdit
541
+ } = cellEdit;
542
+ const {
543
+ enableExpand,
544
+ toggleField,
545
+ expandedRows,
546
+ preventExpand,
547
+ onToggleExpand
548
+ } = expand;
549
+ const rowIndex = row.index;
550
+ const rowData = row.original;
551
+ const isRowHovered = hoveredRowIndex === rowIndex;
552
+ const isRowSelected = row.getIsSelected();
553
+ const rowGroupKey = primaryRowSpanKey !== void 0 && rowData[primaryRowSpanKey] !== null && rowData[primaryRowSpanKey] !== void 0 ? String(rowData[primaryRowSpanKey]) : null;
554
+ const isGroupHovered = enableRowSpan && hoveredGroupKey !== null && rowGroupKey === hoveredGroupKey;
555
+ const isGroupSelected = enableRowSpan && rowGroupKey !== null && selectedGroupKeys.has(rowGroupKey);
556
+ const visibleCells = row.getVisibleCells();
557
+ const expandCellIndex = enableExpand ? resolveExpandCellIndex(visibleCells, toggleField) : -1;
558
+ const canExpand = enableExpand && !preventExpand && canExpandRow(rowData);
559
+ const expandKey = toggleField && rowData[toggleField] !== null && rowData[toggleField] !== void 0 ? String(rowData[toggleField]) : null;
560
+ const isExpanded = expandKey !== null && Boolean(expandedRows?.has(expandKey));
561
+ const rowLevel = typeof rowData.level === "number" ? rowData.level : 0;
562
+ const editInputRef = (0, import_react3.useRef)(null);
563
+ const isRowEditing = editingCell?.rowIndex === rowIndex;
564
+ (0, import_react3.useEffect)(() => {
565
+ if (!isRowEditing) return;
566
+ editInputRef.current?.focus();
567
+ editInputRef.current?.select();
568
+ }, [isRowEditing, editingCell?.colIndex]);
569
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
570
+ "tr",
571
+ {
572
+ ref: measureElement,
573
+ "data-index": virtualIndex,
574
+ className: cn(
575
+ "DataTableRowJSX",
576
+ !enableRowSpan && ROW_HOVER_CLASS,
577
+ enableRowSpan && isRowHovered && !isRowSelected && ROW_HOVERED_BG_CLASS,
578
+ isRowSelected && "is-selected",
579
+ enableExpand && canExpand && "is-expandable",
580
+ getRowClassName?.(rowData, rowIndex)
581
+ ),
582
+ onMouseEnter: () => onRowHover(rowIndex, rowData),
583
+ onClick: () => {
584
+ if (isRowEditing) return;
585
+ onRowClick?.(rowData, rowIndex);
586
+ if (rowSelectionMode !== "none" && selectOnRowClick) {
587
+ onToggleSelect();
588
+ }
589
+ },
590
+ children: visibleCells.map((cell, cellIndex) => {
591
+ const columnId = cell.column.id;
592
+ const meta = cell.column.columnDef.meta;
593
+ const align = meta?.align ?? "center";
594
+ const cellClassName = meta?.className;
595
+ const isRowSpanColumn = Boolean(enableRowSpan && meta?.rowSpan);
596
+ const isExpandCell = cellIndex === expandCellIndex;
597
+ const editable = isColumnEditable(cell.column.columnDef);
598
+ const editType = getColumnEditType(cell.column.columnDef);
599
+ let rowSpanInfo;
600
+ if (isRowSpanColumn) {
601
+ rowSpanInfo = columnRowSpanMap.get(columnId)?.[rowIndex];
602
+ if (rowSpanInfo && rowSpanInfo.rowSpan === 0) {
603
+ return null;
604
+ }
605
+ }
606
+ const isEditing = editingCell?.rowIndex === rowIndex && editingCell?.colIndex === cellIndex;
607
+ const showCellHover = isRowSpanColumn ? isGroupHovered : isRowHovered;
608
+ const showCellSelected = isRowSpanColumn ? isGroupSelected : isRowSelected;
609
+ const cellRowSpan = rowSpanInfo?.rowSpan ?? 1;
610
+ const isCellDragSelected = isCellInSelection(
611
+ rowIndex,
612
+ cellIndex,
613
+ activeSelectionBounds,
614
+ cellRowSpan
615
+ );
616
+ const isBottomRightCell = !isEditing && activeSelectionBounds && !dragState.isSelecting && activeSelectionBounds.endRow >= rowIndex && activeSelectionBounds.endRow <= rowIndex + cellRowSpan - 1 && cellIndex === activeSelectionBounds.endCol;
617
+ const resolveCellRowIndex = (clientY, element) => getRowIndexInMergedCell(clientY, element, rowIndex, cellRowSpan);
618
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
619
+ "td",
620
+ {
621
+ rowSpan: rowSpanInfo && rowSpanInfo.rowSpan > 1 ? rowSpanInfo.rowSpan : void 0,
622
+ onMouseDown: (event) => {
623
+ if (isEditing) {
624
+ event.stopPropagation();
625
+ return;
626
+ }
627
+ event.preventDefault();
628
+ onCellMouseDown(
629
+ resolveCellRowIndex(event.clientY, event.currentTarget),
630
+ cellIndex
631
+ );
632
+ },
633
+ onMouseEnter: (event) => onCellMouseEnter(
634
+ resolveCellRowIndex(event.clientY, event.currentTarget),
635
+ cellIndex
636
+ ),
637
+ onMouseMove: (event) => {
638
+ if (!dragState.isSelecting && !dragState.isFillDragging) return;
639
+ onCellMouseEnter(
640
+ resolveCellRowIndex(event.clientY, event.currentTarget),
641
+ cellIndex
642
+ );
643
+ },
644
+ onDoubleClick: (event) => {
645
+ if (!editable) return;
646
+ event.preventDefault();
647
+ event.stopPropagation();
648
+ onStartEdit(rowIndex, cellIndex);
649
+ },
650
+ style: getCellSelectionEdgeStyle(
651
+ rowIndex,
652
+ cellIndex,
653
+ activeSelectionBounds,
654
+ cellRowSpan
655
+ ),
656
+ className: cn(
657
+ "data-table-cell",
658
+ CELL_ALIGN_CLASS[align],
659
+ cellClassName,
660
+ enableRowSpan && showCellSelected && "is-group-selected",
661
+ enableRowSpan && showCellHover && !showCellSelected && "is-group-hovered",
662
+ isCellDragSelected && CELL_SELECTION_FILL_CLASS,
663
+ editable && "is-editable"
664
+ ),
665
+ children: [
666
+ isEditing ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
667
+ "input",
668
+ {
669
+ ref: editInputRef,
670
+ type: editType === "number" ? "number" : "text",
671
+ defaultValue: draftValue,
672
+ className: cn("cell-edit-input", CELL_ALIGN_CLASS[align]),
673
+ onChange: (event) => onDraftValueChange(event.target.value),
674
+ onMouseDown: (event) => event.stopPropagation(),
675
+ onClick: (event) => event.stopPropagation(),
676
+ onKeyDown: (event) => {
677
+ if (event.key === "Enter") {
678
+ event.preventDefault();
679
+ onCommitEdit(event.currentTarget.value);
680
+ }
681
+ if (event.key === "Escape") {
682
+ event.preventDefault();
683
+ onCancelEdit();
684
+ }
685
+ },
686
+ onBlur: (event) => {
687
+ onCommitEdit(event.currentTarget.value);
688
+ }
689
+ }
690
+ ) : isExpandCell && enableExpand ? /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "expand-cell", children: [
691
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "expand-cell-content", children: [
692
+ rowLevel > 0 && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "expand-cell-indent", children: "\xB7" }),
693
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "expand-cell-value", children: (0, import_react_table.flexRender)(cell.column.columnDef.cell, cell.getContext()) })
694
+ ] }),
695
+ canExpand && expandKey && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
696
+ "button",
697
+ {
698
+ type: "button",
699
+ "aria-label": isExpanded ? "\uD589 \uC811\uAE30" : "\uD589 \uD3BC\uCE58\uAE30",
700
+ className: "expand-toggle-button",
701
+ onClick: (event) => {
702
+ event.stopPropagation();
703
+ onToggleExpand?.(expandKey);
704
+ },
705
+ onMouseDown: (event) => event.stopPropagation(),
706
+ children: isExpanded ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ChevronUp, { className: "expand-toggle-icon" }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ChevronDown, { className: "expand-toggle-icon" })
707
+ }
708
+ )
709
+ ] }) : (0, import_react_table.flexRender)(cell.column.columnDef.cell, cell.getContext()),
710
+ isBottomRightCell && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
711
+ "div",
712
+ {
713
+ role: "presentation",
714
+ className: "fill-handle",
715
+ onMouseDown: (event) => {
716
+ event.stopPropagation();
717
+ event.preventDefault();
718
+ onFillHandleMouseDown(rowIndex, cellIndex);
719
+ }
720
+ }
721
+ )
722
+ ]
723
+ },
724
+ cell.id
725
+ );
726
+ })
727
+ }
728
+ );
729
+ }
730
+
731
+ // src/components/ui/table/components/DataTable/DataTableToolbar.tsx
732
+ var import_jsx_runtime4 = require("react/jsx-runtime");
733
+ function DefaultSelectionLabel({ selectedCount }) {
734
+ if (selectedCount <= 0) return null;
735
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "toolbar-selection", children: [
736
+ "\u2713 ",
737
+ selectedCount,
738
+ "\uAC1C \uC120\uD0DD\uB428"
739
+ ] });
740
+ }
741
+ function DataTableToolbar({
742
+ filteredCount,
743
+ totalCount,
744
+ summary,
745
+ selectedCount,
746
+ selectionLabel,
747
+ toolbar,
748
+ className
749
+ }) {
750
+ const displayFiltered = filteredCount ?? totalCount;
751
+ const hasCount = displayFiltered !== void 0 || totalCount !== void 0;
752
+ const hasLeftContent = hasCount || Boolean(summary);
753
+ const hasToolbar = Boolean(toolbar);
754
+ const selectionContent = selectionLabel ? selectionLabel(selectedCount) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(DefaultSelectionLabel, { selectedCount });
755
+ const hasSelectionContent = selectionContent !== null && selectionContent !== false;
756
+ if (!hasLeftContent && !hasToolbar && !hasSelectionContent) return null;
757
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: cn("DataTableToolbarJSX", className), children: [
758
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "toolbar-left", children: [
759
+ hasCount && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "toolbar-count", children: displayFiltered !== void 0 && totalCount !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
760
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "toolbar-count-primary", children: displayFiltered }),
761
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "toolbar-count-placeholder", children: [
762
+ " / ",
763
+ totalCount
764
+ ] })
765
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "toolbar-count-primary", children: displayFiltered ?? totalCount }) }),
766
+ summary
767
+ ] }),
768
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "toolbar-right", children: [
769
+ selectionContent,
770
+ hasToolbar && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "toolbar-actions", children: toolbar })
771
+ ] })
772
+ ] });
773
+ }
774
+
775
+ // src/components/ui/table/features/cell-edit/useCellEdit.ts
776
+ var import_react4 = require("react");
777
+ function useCellEdit({
778
+ data,
779
+ rows,
780
+ onDataChange
781
+ }) {
782
+ const [editingCell, setEditingCell] = (0, import_react4.useState)(null);
783
+ const [draftValue, setDraftValue] = (0, import_react4.useState)("");
784
+ const draftValueRef = (0, import_react4.useRef)(draftValue);
785
+ const editingCellRef = (0, import_react4.useRef)(editingCell);
786
+ (0, import_react4.useEffect)(() => {
787
+ draftValueRef.current = draftValue;
788
+ }, [draftValue]);
789
+ (0, import_react4.useEffect)(() => {
790
+ editingCellRef.current = editingCell;
791
+ }, [editingCell]);
792
+ const cancelEdit = (0, import_react4.useCallback)(() => {
793
+ setEditingCell(null);
794
+ setDraftValue("");
795
+ }, []);
796
+ const commitEdit = (0, import_react4.useCallback)(
797
+ (raw) => {
798
+ const current = editingCellRef.current;
799
+ if (!current) return true;
800
+ if (!onDataChange) {
801
+ cancelEdit();
802
+ return true;
803
+ }
804
+ const value = raw ?? draftValueRef.current;
805
+ const next = applyCellEdit(data, rows, current.rowIndex, current.colIndex, value);
806
+ if (!next) return false;
807
+ onDataChange(next);
808
+ cancelEdit();
809
+ return true;
810
+ },
811
+ [cancelEdit, data, onDataChange, rows]
812
+ );
813
+ const startEdit = (0, import_react4.useCallback)(
814
+ (rowIndex, colIndex) => {
815
+ const cell = rows[rowIndex]?.getVisibleCells()[colIndex];
816
+ if (!cell || !isColumnEditable(cell.column.columnDef)) return;
817
+ const current = editingCellRef.current;
818
+ if (current && (current.rowIndex !== rowIndex || current.colIndex !== colIndex) && !commitEdit()) {
819
+ return;
820
+ }
821
+ setEditingCell({ rowIndex, colIndex });
822
+ setDraftValue(getCellEditDraftValue(cell.getValue()));
823
+ },
824
+ [commitEdit, rows]
825
+ );
826
+ return {
827
+ editingCell,
828
+ draftValue,
829
+ setDraftValue,
830
+ startEdit,
831
+ commitEdit,
832
+ cancelEdit
833
+ };
834
+ }
835
+
836
+ // src/components/ui/table/features/cell-selection/useCellSelection.ts
837
+ var import_react5 = require("react");
838
+
839
+ // src/components/ui/table/features/cell-selection/fillData.ts
840
+ function getColumnAccessorKey2(columnDef) {
841
+ if ("accessorKey" in columnDef && columnDef.accessorKey) {
842
+ return String(columnDef.accessorKey);
843
+ }
844
+ return columnDef.id;
845
+ }
846
+ function applyFillData(data, rows, sourceBounds, fillBounds) {
847
+ const newData = data.map((row) => ({ ...row }));
848
+ const sourceHeight = sourceBounds.endRow - sourceBounds.startRow + 1;
849
+ const sourceWidth = sourceBounds.endCol - sourceBounds.startCol + 1;
850
+ for (let rowIndex = fillBounds.startRow; rowIndex <= fillBounds.endRow; rowIndex += 1) {
851
+ for (let colIndex = fillBounds.startCol; colIndex <= fillBounds.endCol; colIndex += 1) {
852
+ if (isCellInSelection(rowIndex, colIndex, sourceBounds)) continue;
853
+ const offsetRow = rowIndex - sourceBounds.startRow;
854
+ const offsetCol = colIndex - sourceBounds.startCol;
855
+ const sourceRowIndex = sourceBounds.startRow + (offsetRow % sourceHeight + sourceHeight) % sourceHeight;
856
+ const sourceColIndex = sourceBounds.startCol + (offsetCol % sourceWidth + sourceWidth) % sourceWidth;
857
+ const targetCell = rows[rowIndex]?.getVisibleCells()[colIndex];
858
+ const sourceCell = rows[sourceRowIndex]?.getVisibleCells()[sourceColIndex];
859
+ if (!targetCell || !sourceCell) continue;
860
+ const accessorKey = getColumnAccessorKey2(
861
+ targetCell.column.columnDef
862
+ );
863
+ if (!accessorKey) continue;
864
+ newData[rowIndex][accessorKey] = sourceCell.getValue();
865
+ }
866
+ }
867
+ return newData;
868
+ }
869
+ function hasFillExtension(sourceBounds, fillBounds) {
870
+ if (!sourceBounds) return false;
871
+ return fillBounds.startRow < sourceBounds.startRow || fillBounds.endRow > sourceBounds.endRow || fillBounds.startCol < sourceBounds.startCol || fillBounds.endCol > sourceBounds.endCol;
872
+ }
873
+
874
+ // src/components/ui/table/features/cell-selection/useCellSelection.ts
875
+ function useCellSelection({
876
+ data,
877
+ rows,
878
+ onDataChange
879
+ }) {
880
+ const [dragState, setDragState] = (0, import_react5.useState)(INITIAL_DRAG_STATE);
881
+ const cellSelectionBounds = getCellSelectionBounds(dragState.start, dragState.end);
882
+ const activeSelectionBounds = getActiveSelectionBounds(dragState, cellSelectionBounds);
883
+ const handleCellMouseDown = (0, import_react5.useCallback)((rowIndex, colIndex) => {
884
+ setDragState({
885
+ isSelecting: true,
886
+ isFillDragging: false,
887
+ start: { row: rowIndex, col: colIndex },
888
+ end: { row: rowIndex, col: colIndex },
889
+ fillAnchor: null,
890
+ fillEnd: null
891
+ });
892
+ }, []);
893
+ const handleCellMouseEnter = (0, import_react5.useCallback)((rowIndex, colIndex) => {
894
+ setDragState((prev) => {
895
+ if (prev.isSelecting) {
896
+ return { ...prev, end: { row: rowIndex, col: colIndex } };
897
+ }
898
+ if (prev.isFillDragging) {
899
+ return { ...prev, fillEnd: { row: rowIndex, col: colIndex } };
900
+ }
901
+ return prev;
902
+ });
903
+ }, []);
904
+ const handleFillHandleMouseDown = (0, import_react5.useCallback)((rowIndex, colIndex) => {
905
+ setDragState((prev) => {
906
+ const bounds = getCellSelectionBounds(prev.start, prev.end);
907
+ if (!bounds) return prev;
908
+ return {
909
+ ...prev,
910
+ isSelecting: false,
911
+ isFillDragging: true,
912
+ fillAnchor: { row: bounds.startRow, col: bounds.startCol },
913
+ fillEnd: { row: rowIndex, col: colIndex }
914
+ };
915
+ });
916
+ }, []);
917
+ (0, import_react5.useEffect)(() => {
918
+ const handleKeyDown = (e) => {
919
+ if ((e.ctrlKey || e.metaKey) && e.key === "c" && activeSelectionBounds) {
920
+ const { startRow, endRow, startCol, endCol } = activeSelectionBounds;
921
+ const selectedData = rows.slice(startRow, endRow + 1).map((row) => {
922
+ const cells = row.getVisibleCells();
923
+ return cells.slice(startCol, endCol + 1).map((cell) => cell.getValue()).join(" ");
924
+ }).join("\n");
925
+ navigator.clipboard.writeText(selectedData);
926
+ }
927
+ };
928
+ window.addEventListener("keydown", handleKeyDown);
929
+ return () => window.removeEventListener("keydown", handleKeyDown);
930
+ }, [activeSelectionBounds, rows]);
931
+ (0, import_react5.useEffect)(() => {
932
+ const handleMouseUp = () => {
933
+ setDragState((prev) => {
934
+ if (prev.isFillDragging && prev.fillAnchor && prev.fillEnd) {
935
+ const sourceBounds = getCellSelectionBounds(prev.start, prev.end);
936
+ const newBounds = getCellSelectionBounds(prev.fillAnchor, prev.fillEnd);
937
+ if (newBounds) {
938
+ if (hasFillExtension(sourceBounds, newBounds) && sourceBounds && onDataChange) {
939
+ onDataChange(applyFillData(data, rows, sourceBounds, newBounds));
940
+ }
941
+ return {
942
+ isSelecting: false,
943
+ isFillDragging: false,
944
+ start: { row: newBounds.startRow, col: newBounds.startCol },
945
+ end: { row: newBounds.endRow, col: newBounds.endCol },
946
+ fillAnchor: null,
947
+ fillEnd: null
948
+ };
949
+ }
950
+ }
951
+ if (prev.isSelecting) {
952
+ return { ...prev, isSelecting: false };
953
+ }
954
+ if (prev.isFillDragging) {
955
+ return { ...prev, isFillDragging: false, fillAnchor: null, fillEnd: null };
956
+ }
957
+ return prev;
958
+ });
959
+ };
960
+ window.addEventListener("mouseup", handleMouseUp);
961
+ return () => window.removeEventListener("mouseup", handleMouseUp);
962
+ }, [data, onDataChange, rows]);
963
+ return {
964
+ dragState,
965
+ activeSelectionBounds,
966
+ handleCellMouseDown,
967
+ handleCellMouseEnter,
968
+ handleFillHandleMouseDown
969
+ };
970
+ }
971
+
972
+ // src/components/ui/table/features/row-selection/rowSelection.ts
973
+ function resolveRowSelection(mode, controlledSelection, internalSelection) {
974
+ if (mode === "none") return {};
975
+ return controlledSelection ?? internalSelection;
976
+ }
977
+ function normalizeSingleSelection(next) {
978
+ const selectedIds = Object.keys(next).filter((id) => next[id]);
979
+ if (selectedIds.length <= 1) return next;
980
+ return { [selectedIds[selectedIds.length - 1]]: true };
981
+ }
982
+ function applySelectionUpdater(mode, updater, previous) {
983
+ const next = typeof updater === "function" ? updater(previous) : updater;
984
+ return mode === "single" ? normalizeSingleSelection(next) : next;
985
+ }
986
+
987
+ // src/components/ui/table/features/row-span/rowSpan.ts
988
+ function getRowFieldValue(row, key) {
989
+ return row[key];
990
+ }
991
+ function computeRowSpans(data, rowSpanKey) {
992
+ if (data.length === 0) return [];
993
+ const result = [];
994
+ for (let index = 0; index < data.length; index++) {
995
+ const currentValue = getRowFieldValue(data[index], rowSpanKey);
996
+ const previousValue = index > 0 ? getRowFieldValue(data[index - 1], rowSpanKey) : void 0;
997
+ if (index > 0 && currentValue === previousValue) {
998
+ result.push({ rowSpan: 0, isFirstInGroup: false });
999
+ continue;
1000
+ }
1001
+ let span = 1;
1002
+ for (let nextIndex = index + 1; nextIndex < data.length; nextIndex++) {
1003
+ if (getRowFieldValue(data[nextIndex], rowSpanKey) === currentValue) {
1004
+ span++;
1005
+ } else {
1006
+ break;
1007
+ }
1008
+ }
1009
+ result.push({ rowSpan: span, isFirstInGroup: true });
1010
+ }
1011
+ return result;
1012
+ }
1013
+ function buildColumnRowSpanMap(data, columnKeys) {
1014
+ const map = /* @__PURE__ */ new Map();
1015
+ for (const { columnId, rowSpanKey } of columnKeys) {
1016
+ map.set(columnId, computeRowSpans(data, rowSpanKey));
1017
+ }
1018
+ return map;
1019
+ }
1020
+ function collectRowSpanColumns(columns) {
1021
+ const result = [];
1022
+ const visit = (defs) => {
1023
+ for (const columnDef of defs) {
1024
+ if ("columns" in columnDef && columnDef.columns?.length) {
1025
+ visit(columnDef.columns);
1026
+ continue;
1027
+ }
1028
+ const columnId = columnDef.id ?? ("accessorKey" in columnDef && columnDef.accessorKey ? String(columnDef.accessorKey) : void 0);
1029
+ if (!columnId || !columnDef.meta?.rowSpan) continue;
1030
+ result.push({
1031
+ columnId,
1032
+ rowSpanKey: columnDef.meta.rowSpanKey ?? columnId
1033
+ });
1034
+ }
1035
+ };
1036
+ visit(columns);
1037
+ return result;
1038
+ }
1039
+
1040
+ // src/components/ui/table/components/DataTable/DataTable.tsx
1041
+ var import_jsx_runtime5 = require("react/jsx-runtime");
1042
+ function DataTable({
1043
+ data,
1044
+ columns,
1045
+ rowSelectionMode = "none",
1046
+ rowSelection: controlledRowSelection,
1047
+ onRowSelectionChange,
1048
+ totalCount,
1049
+ filteredCount,
1050
+ summary,
1051
+ toolbar,
1052
+ selectionLabel,
1053
+ isPending = false,
1054
+ emptyText = "\uB370\uC774\uD130\uAC00 \uC5C6\uC2B5\uB2C8\uB2E4.",
1055
+ enableRowSpan = false,
1056
+ getRowId,
1057
+ onRowClick,
1058
+ getRowClassName,
1059
+ getRowCanSelect,
1060
+ selectOnRowClick = true,
1061
+ onDataChange,
1062
+ className,
1063
+ preserveRowSelection = false,
1064
+ toggleField,
1065
+ childField,
1066
+ flattenField,
1067
+ expandedRows: controlledExpandedRows,
1068
+ onExpandedRowsChange,
1069
+ preventExpand = false,
1070
+ enableVirtualization = true,
1071
+ estimateRowHeight = DATA_TABLE_ROW_HEIGHT,
1072
+ virtualOverscan = DATA_TABLE_VIRTUAL_OVERSCAN
1073
+ }) {
1074
+ const enableExpand = Boolean(toggleField);
1075
+ const [internalRowSelection, setInternalRowSelection] = (0, import_react6.useState)({});
1076
+ const [internalExpandedRows, setInternalExpandedRows] = (0, import_react6.useState)(() => /* @__PURE__ */ new Set());
1077
+ const [hoveredRowIndex, setHoveredRowIndex] = (0, import_react6.useState)(null);
1078
+ const [hoveredGroupKey, setHoveredGroupKey] = (0, import_react6.useState)(null);
1079
+ const scrollRef = (0, import_react6.useRef)(null);
1080
+ const shouldVirtualize = enableVirtualization && !enableRowSpan;
1081
+ (0, import_react6.useEffect)(() => {
1082
+ if (enableVirtualization && enableRowSpan) {
1083
+ console.warn(
1084
+ "[DataTable] enableRowSpan\uC774 \uCF1C\uC838 \uC788\uC73C\uBA74 \uC140 \uBCD1\uD569 \uC720\uC9C0\uB97C \uC704\uD574 \uAC00\uC0C1\uD654\uB97C \uBE44\uD65C\uC131\uD654\uD569\uB2C8\uB2E4."
1085
+ );
1086
+ }
1087
+ }, [enableVirtualization, enableRowSpan]);
1088
+ const rowSelection = resolveRowSelection(
1089
+ rowSelectionMode,
1090
+ controlledRowSelection,
1091
+ internalRowSelection
1092
+ );
1093
+ const expandedRows = controlledExpandedRows ?? internalExpandedRows;
1094
+ const handleExpandedRowsChange = (0, import_react6.useCallback)(
1095
+ (next) => {
1096
+ if (onExpandedRowsChange) {
1097
+ onExpandedRowsChange(next);
1098
+ return;
1099
+ }
1100
+ setInternalExpandedRows(next);
1101
+ },
1102
+ [onExpandedRowsChange]
1103
+ );
1104
+ const tableData = useConvertTreeData({
1105
+ data,
1106
+ enabled: enableExpand,
1107
+ toggleField,
1108
+ childField,
1109
+ flattenField,
1110
+ expandedRows,
1111
+ onExpandedRowsChange: enableExpand ? handleExpandedRowsChange : void 0,
1112
+ preventExpand
1113
+ });
1114
+ const table = (0, import_react_table2.useReactTable)({
1115
+ data: tableData,
1116
+ columns,
1117
+ state: {
1118
+ rowSelection: rowSelectionMode === "none" ? {} : rowSelection
1119
+ },
1120
+ enableRowSelection: rowSelectionMode === "none" ? false : getRowCanSelect ? (row) => getRowCanSelect(row.original, row.index) : true,
1121
+ enableMultiRowSelection: rowSelectionMode === "multi",
1122
+ onRowSelectionChange: (updater) => {
1123
+ if (onRowSelectionChange) {
1124
+ onRowSelectionChange(
1125
+ (previous) => applySelectionUpdater(rowSelectionMode, updater, previous)
1126
+ );
1127
+ return;
1128
+ }
1129
+ setInternalRowSelection(
1130
+ (previous) => applySelectionUpdater(rowSelectionMode, updater, previous)
1131
+ );
1132
+ },
1133
+ getCoreRowModel: (0, import_react_table2.getCoreRowModel)(),
1134
+ getRowId: getRowId ? (originalRow, index) => getRowId(originalRow, index) : (_originalRow, index) => String(index)
1135
+ });
1136
+ const rowSpanColumnKeys = (0, import_react6.useMemo)(() => {
1137
+ if (!enableRowSpan) return [];
1138
+ return collectRowSpanColumns(columns);
1139
+ }, [enableRowSpan, columns]);
1140
+ const primaryRowSpanKey = rowSpanColumnKeys[0]?.rowSpanKey;
1141
+ const columnRowSpanMap = (0, import_react6.useMemo)(
1142
+ () => buildColumnRowSpanMap(tableData, rowSpanColumnKeys),
1143
+ [tableData, rowSpanColumnKeys]
1144
+ );
1145
+ const selectedRows = table.getSelectedRowModel().rows;
1146
+ const selectedCount = selectedRows.length;
1147
+ const rows = table.getRowModel().rows;
1148
+ const columnCount = table.getAllLeafColumns().length || 1;
1149
+ const rowVirtualizer = (0, import_react_virtual.useVirtualizer)({
1150
+ count: shouldVirtualize ? rows.length : 0,
1151
+ getScrollElement: () => scrollRef.current,
1152
+ estimateSize: () => estimateRowHeight,
1153
+ overscan: virtualOverscan
1154
+ });
1155
+ const virtualRows = rowVirtualizer.getVirtualItems();
1156
+ const totalSize = rowVirtualizer.getTotalSize();
1157
+ const paddingTop = virtualRows.length > 0 ? virtualRows[0]?.start ?? 0 : 0;
1158
+ const paddingBottom = virtualRows.length > 0 ? totalSize - (virtualRows[virtualRows.length - 1]?.end ?? 0) : 0;
1159
+ const selectedGroupKeys = (0, import_react6.useMemo)(() => {
1160
+ if (!enableRowSpan || !primaryRowSpanKey) return /* @__PURE__ */ new Set();
1161
+ const keys = /* @__PURE__ */ new Set();
1162
+ for (const selectedRow of selectedRows) {
1163
+ const value = selectedRow.original[primaryRowSpanKey];
1164
+ if (value !== null && value !== void 0) keys.add(String(value));
1165
+ }
1166
+ return keys;
1167
+ }, [enableRowSpan, primaryRowSpanKey, selectedRows]);
1168
+ const {
1169
+ dragState,
1170
+ activeSelectionBounds,
1171
+ handleCellMouseDown,
1172
+ handleCellMouseEnter,
1173
+ handleFillHandleMouseDown
1174
+ } = useCellSelection({ data: tableData, rows, onDataChange });
1175
+ const { editingCell, draftValue, setDraftValue, startEdit, commitEdit, cancelEdit } = useCellEdit(
1176
+ { data: tableData, rows, onDataChange }
1177
+ );
1178
+ const handleCellMouseDownWithCommit = (0, import_react6.useCallback)(
1179
+ (rowIndex, colIndex) => {
1180
+ const isSameEditingCell = editingCell?.rowIndex === rowIndex && editingCell?.colIndex === colIndex;
1181
+ if (editingCell && !isSameEditingCell && !commitEdit()) {
1182
+ return;
1183
+ }
1184
+ handleCellMouseDown(rowIndex, colIndex);
1185
+ },
1186
+ [commitEdit, editingCell, handleCellMouseDown]
1187
+ );
1188
+ const clearHover = () => {
1189
+ setHoveredRowIndex(null);
1190
+ setHoveredGroupKey(null);
1191
+ };
1192
+ const handleRowHover = (0, import_react6.useCallback)(
1193
+ (rowIndex, rowData) => {
1194
+ setHoveredRowIndex(rowIndex);
1195
+ if (!primaryRowSpanKey) {
1196
+ setHoveredGroupKey(null);
1197
+ return;
1198
+ }
1199
+ const groupValue = rowData[primaryRowSpanKey];
1200
+ setHoveredGroupKey(
1201
+ groupValue === null || groupValue === void 0 ? null : String(groupValue)
1202
+ );
1203
+ },
1204
+ [primaryRowSpanKey]
1205
+ );
1206
+ const handleToggleSelect = (0, import_react6.useCallback)(
1207
+ (row) => {
1208
+ if (!row.getCanSelect()) return;
1209
+ if (preserveRowSelection && row.getIsSelected()) {
1210
+ return;
1211
+ }
1212
+ row.toggleSelected();
1213
+ },
1214
+ [preserveRowSelection]
1215
+ );
1216
+ const handleToggleExpand = (0, import_react6.useCallback)(
1217
+ (rowKey) => {
1218
+ if (preventExpand) return;
1219
+ handleExpandedRowsChange(toggleExpandedRowId(rowKey, expandedRows));
1220
+ },
1221
+ [preventExpand, handleExpandedRowsChange, expandedRows]
1222
+ );
1223
+ const rowContextValue = (0, import_react6.useMemo)(() => {
1224
+ return {
1225
+ rowSpan: {
1226
+ enableRowSpan,
1227
+ primaryRowSpanKey,
1228
+ columnRowSpanMap,
1229
+ hoveredRowIndex,
1230
+ hoveredGroupKey,
1231
+ selectedGroupKeys,
1232
+ onRowHover: handleRowHover
1233
+ },
1234
+ selection: {
1235
+ rowSelectionMode,
1236
+ selectOnRowClick,
1237
+ onRowClick,
1238
+ getRowClassName
1239
+ },
1240
+ cellSelection: {
1241
+ activeSelectionBounds,
1242
+ dragState,
1243
+ onCellMouseDown: handleCellMouseDownWithCommit,
1244
+ onCellMouseEnter: handleCellMouseEnter,
1245
+ onFillHandleMouseDown: handleFillHandleMouseDown
1246
+ },
1247
+ cellEdit: {
1248
+ editingCell,
1249
+ draftValue,
1250
+ onDraftValueChange: setDraftValue,
1251
+ onStartEdit: startEdit,
1252
+ onCommitEdit: commitEdit,
1253
+ onCancelEdit: cancelEdit
1254
+ },
1255
+ expand: {
1256
+ enableExpand,
1257
+ toggleField,
1258
+ expandedRows,
1259
+ preventExpand,
1260
+ onToggleExpand: handleToggleExpand
1261
+ }
1262
+ };
1263
+ }, [
1264
+ enableRowSpan,
1265
+ primaryRowSpanKey,
1266
+ columnRowSpanMap,
1267
+ hoveredRowIndex,
1268
+ hoveredGroupKey,
1269
+ selectedGroupKeys,
1270
+ handleRowHover,
1271
+ rowSelectionMode,
1272
+ selectOnRowClick,
1273
+ onRowClick,
1274
+ getRowClassName,
1275
+ activeSelectionBounds,
1276
+ dragState,
1277
+ handleCellMouseDownWithCommit,
1278
+ handleCellMouseEnter,
1279
+ handleFillHandleMouseDown,
1280
+ editingCell,
1281
+ draftValue,
1282
+ setDraftValue,
1283
+ startEdit,
1284
+ commitEdit,
1285
+ cancelEdit,
1286
+ enableExpand,
1287
+ toggleField,
1288
+ expandedRows,
1289
+ preventExpand,
1290
+ handleToggleExpand
1291
+ ]);
1292
+ if (isPending) {
1293
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: cn("DataTableJSX", "DataTableJSX--pending", className), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "data-table-loading-text", children: "\uB85C\uB529 \uC911..." }) });
1294
+ }
1295
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: cn("DataTableJSX", className), children: [
1296
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1297
+ DataTableToolbar,
1298
+ {
1299
+ filteredCount: filteredCount ?? tableData.length,
1300
+ totalCount,
1301
+ summary,
1302
+ selectedCount,
1303
+ selectionLabel,
1304
+ toolbar
1305
+ }
1306
+ ),
1307
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { ref: scrollRef, className: "data-table-scroll", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1308
+ "table",
1309
+ {
1310
+ className: "data-table",
1311
+ onDragStart: (event) => event.preventDefault(),
1312
+ children: [
1313
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("thead", { className: "data-table-head", children: table.getHeaderGroups().map((headerGroup) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("tr", { className: "data-table-head-row", children: headerGroup.headers.map((header) => {
1314
+ const align = header.column.columnDef.meta?.align ?? "center";
1315
+ const headerClassName = header.column.columnDef.meta?.headerClassName;
1316
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1317
+ "th",
1318
+ {
1319
+ style: { width: header.getSize() !== 150 ? header.getSize() : void 0 },
1320
+ className: cn(
1321
+ "data-table-head-cell",
1322
+ CELL_ALIGN_CLASS[align],
1323
+ headerClassName
1324
+ ),
1325
+ children: header.isPlaceholder ? null : (0, import_react_table2.flexRender)(header.column.columnDef.header, header.getContext())
1326
+ },
1327
+ header.id
1328
+ );
1329
+ }) }, headerGroup.id)) }),
1330
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(DataTableContextProvider, { value: rowContextValue, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("tbody", { onMouseLeave: clearHover, className: "data-table-body", children: rows.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("tr", { children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("td", { colSpan: columnCount, className: "data-table-empty-cell", children: emptyText }) }) : shouldVirtualize ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
1331
+ paddingTop > 0 && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("tr", { "aria-hidden": true, className: "data-table-virtual-spacer", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1332
+ "td",
1333
+ {
1334
+ colSpan: columnCount,
1335
+ style: { height: paddingTop },
1336
+ className: "data-table-virtual-spacer-cell"
1337
+ }
1338
+ ) }),
1339
+ virtualRows.map((virtualRow) => {
1340
+ const row = rows[virtualRow.index];
1341
+ if (!row) return null;
1342
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1343
+ DataTableRow,
1344
+ {
1345
+ row,
1346
+ virtualIndex: virtualRow.index,
1347
+ measureElement: rowVirtualizer.measureElement,
1348
+ onToggleSelect: () => handleToggleSelect(row)
1349
+ },
1350
+ row.id
1351
+ );
1352
+ }),
1353
+ paddingBottom > 0 && /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("tr", { "aria-hidden": true, className: "data-table-virtual-spacer", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1354
+ "td",
1355
+ {
1356
+ colSpan: columnCount,
1357
+ style: { height: paddingBottom },
1358
+ className: "data-table-virtual-spacer-cell"
1359
+ }
1360
+ ) })
1361
+ ] }) : rows.map((row) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1362
+ DataTableRow,
1363
+ {
1364
+ row,
1365
+ onToggleSelect: () => handleToggleSelect(row)
1366
+ },
1367
+ row.id
1368
+ )) }) })
1369
+ ]
1370
+ }
1371
+ ) })
1372
+ ] });
1373
+ }
1374
+
1375
+ // src/components/ui/table/components/Table/Table.tsx
1376
+ var import_react9 = require("react");
1377
+
1378
+ // src/components/ui/table/components/Table/buildColumnDef.tsx
1379
+ var import_jsx_runtime6 = require("react/jsx-runtime");
1380
+ function SortableHeader({
1381
+ label,
1382
+ field,
1383
+ sort,
1384
+ onSort
1385
+ }) {
1386
+ const isActive = sort?.field === field;
1387
+ const Icon = isActive ? sort.direction === "asc" ? ArrowUp : ArrowDown : ArrowUpDown;
1388
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
1389
+ "button",
1390
+ {
1391
+ type: "button",
1392
+ className: cn("SortableHeaderJSX", isActive ? "is-active" : "is-inactive"),
1393
+ onClick: () => onSort(field),
1394
+ children: [
1395
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: label }),
1396
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Icon, { className: "sortable-header-icon" })
1397
+ ]
1398
+ }
1399
+ );
1400
+ }
1401
+ function buildColumnDef(props, sort, onSort) {
1402
+ const {
1403
+ field,
1404
+ virtual = false,
1405
+ children,
1406
+ sortable = false,
1407
+ width,
1408
+ align,
1409
+ rowSpan,
1410
+ rowSpanKey,
1411
+ editable,
1412
+ editType,
1413
+ className,
1414
+ headerClassName,
1415
+ render
1416
+ } = props;
1417
+ return {
1418
+ id: field,
1419
+ ...!virtual ? { accessorKey: field } : {},
1420
+ size: width ?? 150,
1421
+ header: sortable ? () => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(SortableHeader, { label: children, field, sort, onSort }) : (
1422
+ // eslint-disable-next-line @typescript-eslint/promise-function-async
1423
+ () => children
1424
+ ),
1425
+ ...render ? {
1426
+ // eslint-disable-next-line @typescript-eslint/promise-function-async
1427
+ cell: ({ row, getValue }) => render(
1428
+ getValue(),
1429
+ row,
1430
+ row.index
1431
+ )
1432
+ } : {},
1433
+ meta: {
1434
+ align,
1435
+ rowSpan,
1436
+ rowSpanKey,
1437
+ editable,
1438
+ editType,
1439
+ className,
1440
+ headerClassName
1441
+ }
1442
+ };
1443
+ }
1444
+
1445
+ // src/components/ui/table/components/Table/parseTableChildren.ts
1446
+ var import_react8 = require("react");
1447
+
1448
+ // src/components/ui/table/components/Table/tableChildTypes.ts
1449
+ var import_react7 = require("react");
1450
+ var TABLE_HEADER_DISPLAY_NAME = "Table.Header";
1451
+ var TABLE_BODY_DISPLAY_NAME = "Table.Body";
1452
+ var TABLE_COLUMN_DISPLAY_NAME = "Table.Column";
1453
+ var TABLE_PAGINATION_DISPLAY_NAME = "Table.Pagination";
1454
+ function getComponentDisplayName(type) {
1455
+ if (typeof type === "function" || typeof type === "object" && type !== null) {
1456
+ return type.displayName;
1457
+ }
1458
+ return void 0;
1459
+ }
1460
+ function isTableHeaderElement(child) {
1461
+ return (0, import_react7.isValidElement)(child) && getComponentDisplayName(child.type) === TABLE_HEADER_DISPLAY_NAME;
1462
+ }
1463
+ function isTableBodyElement(child) {
1464
+ return (0, import_react7.isValidElement)(child) && getComponentDisplayName(child.type) === TABLE_BODY_DISPLAY_NAME;
1465
+ }
1466
+ function isTableColumnElement(child) {
1467
+ return (0, import_react7.isValidElement)(child) && getComponentDisplayName(child.type) === TABLE_COLUMN_DISPLAY_NAME;
1468
+ }
1469
+ function isTablePaginationElement(child) {
1470
+ return (0, import_react7.isValidElement)(child) && getComponentDisplayName(child.type) === TABLE_PAGINATION_DISPLAY_NAME;
1471
+ }
1472
+
1473
+ // src/components/ui/table/components/Table/parseTableChildren.ts
1474
+ function parseTableChildren(children) {
1475
+ const slots = {
1476
+ header: null,
1477
+ body: null,
1478
+ pagination: null
1479
+ };
1480
+ for (const child of import_react8.Children.toArray(children)) {
1481
+ if (isTableHeaderElement(child)) {
1482
+ slots.header = child;
1483
+ continue;
1484
+ }
1485
+ if (isTableBodyElement(child)) {
1486
+ slots.body = child;
1487
+ continue;
1488
+ }
1489
+ if (isTablePaginationElement(child)) {
1490
+ slots.pagination = child;
1491
+ }
1492
+ }
1493
+ return slots;
1494
+ }
1495
+ function extractColumnElements(header) {
1496
+ if (!header) return [];
1497
+ const { children } = header.props;
1498
+ return import_react8.Children.toArray(children).filter(isTableColumnElement);
1499
+ }
1500
+
1501
+ // src/components/ui/table/components/Table/TableBody.tsx
1502
+ function TableBody() {
1503
+ return null;
1504
+ }
1505
+ TableBody.displayName = TABLE_BODY_DISPLAY_NAME;
1506
+
1507
+ // src/components/ui/table/components/Table/TableColumn.tsx
1508
+ function TableColumn(props) {
1509
+ void props;
1510
+ return null;
1511
+ }
1512
+ TableColumn.displayName = TABLE_COLUMN_DISPLAY_NAME;
1513
+
1514
+ // src/components/ui/table/components/Table/tableDataPipeline.ts
1515
+ function sortTableData(data, sort) {
1516
+ if (!sort) return data;
1517
+ const { field, direction } = sort;
1518
+ const multiplier = direction === "asc" ? 1 : -1;
1519
+ return [...data].sort((left, right) => {
1520
+ const leftValue = left[field];
1521
+ const rightValue = right[field];
1522
+ if ((leftValue === null || leftValue === void 0) && (rightValue === null || rightValue === void 0)) {
1523
+ return 0;
1524
+ }
1525
+ if (leftValue === null || leftValue === void 0) return 1;
1526
+ if (rightValue === null || rightValue === void 0) return -1;
1527
+ if (typeof leftValue === "number" && typeof rightValue === "number") {
1528
+ return (leftValue - rightValue) * multiplier;
1529
+ }
1530
+ return String(leftValue).localeCompare(String(rightValue), "ko") * multiplier;
1531
+ });
1532
+ }
1533
+ function paginateTableData(data, page, pageSize) {
1534
+ const safePage = Math.max(1, page);
1535
+ const start = (safePage - 1) * pageSize;
1536
+ return data.slice(start, start + pageSize);
1537
+ }
1538
+ function getTotalPages(totalCount, pageSize) {
1539
+ if (pageSize <= 0) return 1;
1540
+ return Math.max(1, Math.ceil(totalCount / pageSize));
1541
+ }
1542
+
1543
+ // src/components/ui/table/components/Table/TableHeader.tsx
1544
+ function TableHeader(props) {
1545
+ void props;
1546
+ return null;
1547
+ }
1548
+ TableHeader.displayName = TABLE_HEADER_DISPLAY_NAME;
1549
+
1550
+ // src/components/ui/table/components/Table/TablePagination.tsx
1551
+ var import_jsx_runtime7 = require("react/jsx-runtime");
1552
+ function TablePagination({
1553
+ page,
1554
+ pageSize = 10,
1555
+ totalCount = 0,
1556
+ onChange,
1557
+ className
1558
+ }) {
1559
+ const totalPages = getTotalPages(totalCount, pageSize);
1560
+ const safePage = Math.min(Math.max(1, page), totalPages);
1561
+ const canGoPrev = safePage > 1;
1562
+ const canGoNext = safePage < totalPages;
1563
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: cn("TablePaginationJSX", className), children: [
1564
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1565
+ "button",
1566
+ {
1567
+ type: "button",
1568
+ className: "pagination-button",
1569
+ disabled: !canGoPrev,
1570
+ onClick: () => onChange(safePage - 1),
1571
+ "aria-label": "\uC774\uC804 \uD398\uC774\uC9C0",
1572
+ children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ChevronLeft, { className: "pagination-button-icon" })
1573
+ }
1574
+ ),
1575
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("span", { className: "pagination-label", children: [
1576
+ safePage,
1577
+ " / ",
1578
+ totalPages
1579
+ ] }),
1580
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1581
+ "button",
1582
+ {
1583
+ type: "button",
1584
+ className: "pagination-button",
1585
+ disabled: !canGoNext,
1586
+ onClick: () => onChange(safePage + 1),
1587
+ "aria-label": "\uB2E4\uC74C \uD398\uC774\uC9C0",
1588
+ children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ChevronRight, { className: "pagination-button-icon" })
1589
+ }
1590
+ )
1591
+ ] });
1592
+ }
1593
+ TablePagination.displayName = TABLE_PAGINATION_DISPLAY_NAME;
1594
+
1595
+ // src/components/ui/table/components/Table/Table.tsx
1596
+ var import_jsx_runtime8 = require("react/jsx-runtime");
1597
+ function TableRoot({
1598
+ data,
1599
+ children,
1600
+ className,
1601
+ totalCount,
1602
+ filteredCount,
1603
+ ...dataTableProps
1604
+ }) {
1605
+ const { header, pagination: paginationElement } = (0, import_react9.useMemo)(
1606
+ () => parseTableChildren(children),
1607
+ [children]
1608
+ );
1609
+ const [sort, setSort] = (0, import_react9.useState)(null);
1610
+ const handleSort = (0, import_react9.useCallback)((field) => {
1611
+ setSort((previous) => {
1612
+ if (previous?.field !== field) {
1613
+ return { field, direction: "asc" };
1614
+ }
1615
+ if (previous.direction === "asc") {
1616
+ return { field, direction: "desc" };
1617
+ }
1618
+ return null;
1619
+ });
1620
+ }, []);
1621
+ const columns = (0, import_react9.useMemo)(() => {
1622
+ return extractColumnElements(header).map(
1623
+ (columnElement) => buildColumnDef(columnElement.props, sort, handleSort)
1624
+ );
1625
+ }, [header, sort, handleSort]);
1626
+ const paginationProps = paginationElement?.props;
1627
+ const pageSize = paginationProps?.pageSize ?? 10;
1628
+ const page = paginationProps?.page ?? 1;
1629
+ const resolvedTotalCount = paginationProps?.totalCount ?? totalCount ?? data.length;
1630
+ const tableData = (0, import_react9.useMemo)(() => {
1631
+ const sortedData = sortTableData(data, sort);
1632
+ if (!paginationProps) return sortedData;
1633
+ return paginateTableData(sortedData, page, pageSize);
1634
+ }, [data, sort, paginationProps, page, pageSize]);
1635
+ if (columns.length === 0) {
1636
+ console.warn("[Table] Table.Header \uC548\uC5D0 Table.Column\uC744 \uD558\uB098 \uC774\uC0C1 \uC120\uC5B8\uD574 \uC8FC\uC138\uC694.");
1637
+ }
1638
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "TableJSX", children: [
1639
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1640
+ DataTable,
1641
+ {
1642
+ ...dataTableProps,
1643
+ data: tableData,
1644
+ columns,
1645
+ totalCount: paginationProps ? resolvedTotalCount : totalCount,
1646
+ filteredCount: filteredCount ?? data.length,
1647
+ className: cn(className, paginationProps && "DataTableJSX--with-pagination")
1648
+ }
1649
+ ),
1650
+ paginationProps && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1651
+ TablePagination,
1652
+ {
1653
+ page,
1654
+ pageSize,
1655
+ totalCount: resolvedTotalCount,
1656
+ onChange: paginationProps.onChange,
1657
+ className: paginationProps.className
1658
+ }
1659
+ )
1660
+ ] });
1661
+ }
1662
+ function createTable() {
1663
+ function Column(props) {
1664
+ void props;
1665
+ return null;
1666
+ }
1667
+ Column.displayName = TABLE_COLUMN_DISPLAY_NAME;
1668
+ return Object.assign(
1669
+ function BoundTable(props) {
1670
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(TableRoot, { ...props });
1671
+ },
1672
+ {
1673
+ Header: TableHeader,
1674
+ Column,
1675
+ Body: TableBody,
1676
+ Pagination: TablePagination
1677
+ }
1678
+ );
1679
+ }
1680
+ var Table = Object.assign(TableRoot, {
1681
+ Header: TableHeader,
1682
+ Column: TableColumn,
1683
+ Body: TableBody,
1684
+ Pagination: TablePagination
1685
+ });
1686
+ // Annotate the CommonJS export names for ESM import in node:
1687
+ 0 && (module.exports = {
1688
+ DataTable,
1689
+ Table,
1690
+ createTable
1691
+ });