react-glide-table 1.1.5 → 1.1.6

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/core.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { C as CellEditType, a as DataTableClassNames, R as RowSelectionMode, c as DataTableProps, b as DataTableLabels } from './types-BfthylVR.cjs';
2
- export { D as DEFAULT_DATA_TABLE_LABELS, r as resolveDataTableLabels } from './types-BfthylVR.cjs';
1
+ import { C as CellEditType, a as DataTableClassNames, R as RowSelectionMode, d as DataTableProps, c as DataTableLabels, b as DataTableCopyActions, P as PasteMode, f as RowsPastePayload } from './types-DOLnknDe.cjs';
2
+ export { D as DEFAULT_DATA_TABLE_LABELS, r as resolveDataTableLabels } from './types-DOLnknDe.cjs';
3
3
  import { Row, ColumnDef, Table, Updater, RowSelectionState } from '@tanstack/react-table';
4
4
  export { ColumnDef, RowSelectionState } from '@tanstack/react-table';
5
5
  import { Virtualizer, VirtualItem } from '@tanstack/react-virtual';
@@ -133,10 +133,10 @@ type DataTableRowContextValue = {
133
133
  rowSpan: {
134
134
  enableRowSpan: boolean;
135
135
  primaryRowSpanKey?: string;
136
+ primaryRowSpanColumnId?: string;
136
137
  columnRowSpanMap: ColumnRowSpanMap;
137
138
  hoveredRowIndex: number | null;
138
- hoveredGroupKey: string | null;
139
- selectedGroupKeys: Set<string>;
139
+ selectedRowIndices: Set<number>;
140
140
  onRowHover: (rowIndex: number, rowData: RowData) => void;
141
141
  };
142
142
  selection: {
@@ -193,6 +193,7 @@ type UseGlideTableResult<T extends Record<string, unknown>> = {
193
193
  rowContextValue: DataTableRowContextValue;
194
194
  handleToggleSelect: (row: Row<T>) => void;
195
195
  clearHover: () => void;
196
+ copySelection: DataTableCopyActions["copySelection"];
196
197
  };
197
198
  declare function useGlideTable<T extends Record<string, unknown>>(options: UseGlideTableOptions<T>): UseGlideTableResult<T>;
198
199
 
@@ -211,25 +212,73 @@ declare function useCellEdit<T extends Record<string, unknown>>({ data, rows, on
211
212
  cancelEdit: () => void;
212
213
  };
213
214
 
215
+ type ParsedClipboardTSV = {
216
+ values: string[][];
217
+ /**
218
+ * Relative tree depth per row when the TSV looks like subtree-copy indentation
219
+ * (first row unindented, at least one later row with leading empty cells).
220
+ * Otherwise all zeros — leading blanks are preserved as real cell values.
221
+ */
222
+ depths: number[];
223
+ };
224
+ /** Parse Excel/Sheets-style TSV from the clipboard. Trailing newlines are ignored. */
225
+ declare function parseClipboardTSV(text: string): string[][];
226
+ /**
227
+ * Parse TSV and recover relative tree depth from leading tabs
228
+ * (encoded by subtree copy as leading empty cells).
229
+ */
230
+ declare function parseClipboardTSVWithDepths(text: string): ParsedClipboardTSV;
231
+ /** Resolve visible column ids starting at `startCol` for `width` columns. */
232
+ declare function resolvePasteColumnIds<T extends Record<string, unknown>>(rows: Row<T>[], startCol: number, width: number): string[];
233
+ declare function buildRowsPastePayload<T extends Record<string, unknown>>(rows: Row<T>[], startRow: number, startCol: number, text: string, mode: PasteMode, endRow?: number): RowsPastePayload | null;
234
+ declare function isEditablePasteTarget(target: EventTarget | null): boolean;
235
+
236
+ type CopySelectionOptions = {
237
+ /** When true, collapsed tree descendants are included. Defaults to false. */
238
+ includeDescendants?: boolean;
239
+ };
214
240
  type UseCellSelectionOptions<T extends Record<string, unknown>> = {
215
241
  data: T[];
216
242
  rows: Row<T>[];
217
243
  enabled?: boolean;
244
+ /** Enables Ctrl/Cmd+Shift+C subtree copy. Defaults to true when tree expand is enabled. */
245
+ enableSubtreeCopy?: boolean;
246
+ /** Enables Ctrl/Cmd+Shift+V insert paste. Defaults to true. */
247
+ enableInsertPaste?: boolean;
218
248
  onDataChange?: (data: T[]) => void;
219
249
  onBatchChange?: (changes: Array<{
220
250
  rowId: string;
221
251
  columnId: string;
222
252
  value: unknown;
223
253
  }>) => void;
254
+ onRowsPaste?: (payload: RowsPastePayload) => void;
224
255
  };
225
- declare function useCellSelection<T extends Record<string, unknown>>({ data, rows, enabled, onDataChange, onBatchChange, }: UseCellSelectionOptions<T>): {
256
+ declare function useCellSelection<T extends Record<string, unknown>>({ data, rows, enabled, enableSubtreeCopy, enableInsertPaste, onDataChange, onBatchChange, onRowsPaste, }: UseCellSelectionOptions<T>): {
226
257
  dragState: DragState;
227
258
  activeSelectionBounds: CellSelectionBounds | null;
228
259
  handleCellMouseDown: (rowIndex: number, colIndex: number) => void;
229
260
  handleCellMouseEnter: (rowIndex: number, colIndex: number) => void;
230
261
  handleFillHandleMouseDown: (rowIndex: number, colIndex: number) => void;
262
+ copySelection: (options?: CopySelectionOptions) => Promise<boolean>;
231
263
  };
232
264
 
265
+ type CopySelectionMode = "visible" | "subtree";
266
+ type CopyRowEntry<T extends Record<string, unknown>> = {
267
+ row: T;
268
+ /** Tree depth relative to the table root (0 = top-level). */
269
+ depth: number;
270
+ };
271
+ declare function flattenSubtreeRows<T extends Record<string, unknown>>(row: T): T[];
272
+ /**
273
+ * Collects copy rows with tree depth so paste can rebuild parent/child nesting.
274
+ * Descendant depth is derived from the walk, not only from `level`.
275
+ */
276
+ declare function collectCopyRowEntries<T extends Record<string, unknown>>(visibleRows: Row<T>[], bounds: CellSelectionBounds, mode?: CopySelectionMode): CopyRowEntry<T>[];
277
+ declare function collectCopyRows<T extends Record<string, unknown>>(visibleRows: Row<T>[], bounds: CellSelectionBounds, mode?: CopySelectionMode): T[];
278
+ declare function serializeCopyRowsToTSV<T extends Record<string, unknown>>(copyRows: T[], visibleRows: Row<T>[], bounds: CellSelectionBounds, depths?: number[]): string;
279
+ declare function serializeSelectionToTSV<T extends Record<string, unknown>>(visibleRows: Row<T>[], bounds: CellSelectionBounds, mode?: CopySelectionMode): string;
280
+ declare function writeSelectionToClipboard<T extends Record<string, unknown>>(visibleRows: Row<T>[], bounds: CellSelectionBounds, mode?: CopySelectionMode): Promise<boolean>;
281
+
233
282
  type CellChange = {
234
283
  rowId: string;
235
284
  columnId: string;
@@ -268,10 +317,14 @@ declare function toggleExpandedRowId(rowId: string, previous: Set<string>): Set<
268
317
  /**
269
318
  * Builds a tree from flat/nested data, then returns only rows visible under expandedRows.
270
319
  * When enabled=false, returns data as-is.
320
+ *
321
+ * Flat rows attach to the nearest *preceding* parent with a matching toggle key
322
+ * (so duplicate keys after paste stay under the pasted parent). Parents must appear
323
+ * before their children; a child whose parent is later in the array becomes a root.
271
324
  */
272
325
  declare const useConvertTreeData: <T extends Record<string, unknown>>({ data, enabled, toggleField, childField, flattenField, qtyField, preventExpand, startIndex, expandedRows, onExpandedRowsChange, }: UseConvertTreeDataParams<T>) => T[];
273
326
 
274
327
  declare function resolveRowSelection(mode: RowSelectionMode, controlledSelection: RowSelectionState | undefined, internalSelection: RowSelectionState): RowSelectionState;
275
328
  declare function applySelectionUpdater(mode: RowSelectionMode, updater: Updater<RowSelectionState>, previous: RowSelectionState): RowSelectionState;
276
329
 
277
- export { CELL_SELECTION_EDGES_CLASS, type CellSelectionBounds, type ColumnRowSpanMap, DEFAULT_TREE_CHILDREN_FIELD, DEFAULT_TREE_ID_FIELD, DEFAULT_TREE_PARENT_ID_FIELD, DEFAULT_TREE_QTY_FIELD, DataTableLabels, DataTableProps, type DragState, type EditingCell, RowSelectionMode, type RowSpanInfo, type TreeRow, type UseConvertTreeDataParams, type UseGlideTableOptions, type UseGlideTableResult, applyCellEdit, applyFillData, applySelectionUpdater, buildColumnRowSpanMap, canExpandRow, collectFillChanges, collectRowSpanColumns, getCellEditDraftValue, getCellSelectionEdgeStyle, getColumnEditType, getRowIndexInMergedCell, hasCellSelectionEdges, isCellInSelection, isColumnEditable, measureMergedSpanRowHeights, parseCellEditValue, resolveRowSelection, resolveRowSpanAt, rowRangeToHeightRatios, toggleExpandedRowId, useCellEdit, useCellSelection, useConvertTreeData, useGlideTable };
330
+ export { CELL_SELECTION_EDGES_CLASS, type CellSelectionBounds, type ColumnRowSpanMap, type CopyRowEntry, type CopySelectionMode, DEFAULT_TREE_CHILDREN_FIELD, DEFAULT_TREE_ID_FIELD, DEFAULT_TREE_PARENT_ID_FIELD, DEFAULT_TREE_QTY_FIELD, DataTableCopyActions, DataTableLabels, DataTableProps, type DragState, type EditingCell, PasteMode, RowSelectionMode, type RowSpanInfo, RowsPastePayload, type TreeRow, type UseConvertTreeDataParams, type UseGlideTableOptions, type UseGlideTableResult, applyCellEdit, applyFillData, applySelectionUpdater, buildColumnRowSpanMap, buildRowsPastePayload, canExpandRow, collectCopyRowEntries, collectCopyRows, collectFillChanges, collectRowSpanColumns, flattenSubtreeRows, getCellEditDraftValue, getCellSelectionEdgeStyle, getColumnEditType, getRowIndexInMergedCell, hasCellSelectionEdges, isCellInSelection, isColumnEditable, isEditablePasteTarget, measureMergedSpanRowHeights, parseCellEditValue, parseClipboardTSV, parseClipboardTSVWithDepths, resolvePasteColumnIds, resolveRowSelection, resolveRowSpanAt, rowRangeToHeightRatios, serializeCopyRowsToTSV, serializeSelectionToTSV, toggleExpandedRowId, useCellEdit, useCellSelection, useConvertTreeData, useGlideTable, writeSelectionToClipboard };
package/dist/core.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { C as CellEditType, a as DataTableClassNames, R as RowSelectionMode, c as DataTableProps, b as DataTableLabels } from './types-BfthylVR.js';
2
- export { D as DEFAULT_DATA_TABLE_LABELS, r as resolveDataTableLabels } from './types-BfthylVR.js';
1
+ import { C as CellEditType, a as DataTableClassNames, R as RowSelectionMode, d as DataTableProps, c as DataTableLabels, b as DataTableCopyActions, P as PasteMode, f as RowsPastePayload } from './types-DOLnknDe.js';
2
+ export { D as DEFAULT_DATA_TABLE_LABELS, r as resolveDataTableLabels } from './types-DOLnknDe.js';
3
3
  import { Row, ColumnDef, Table, Updater, RowSelectionState } from '@tanstack/react-table';
4
4
  export { ColumnDef, RowSelectionState } from '@tanstack/react-table';
5
5
  import { Virtualizer, VirtualItem } from '@tanstack/react-virtual';
@@ -133,10 +133,10 @@ type DataTableRowContextValue = {
133
133
  rowSpan: {
134
134
  enableRowSpan: boolean;
135
135
  primaryRowSpanKey?: string;
136
+ primaryRowSpanColumnId?: string;
136
137
  columnRowSpanMap: ColumnRowSpanMap;
137
138
  hoveredRowIndex: number | null;
138
- hoveredGroupKey: string | null;
139
- selectedGroupKeys: Set<string>;
139
+ selectedRowIndices: Set<number>;
140
140
  onRowHover: (rowIndex: number, rowData: RowData) => void;
141
141
  };
142
142
  selection: {
@@ -193,6 +193,7 @@ type UseGlideTableResult<T extends Record<string, unknown>> = {
193
193
  rowContextValue: DataTableRowContextValue;
194
194
  handleToggleSelect: (row: Row<T>) => void;
195
195
  clearHover: () => void;
196
+ copySelection: DataTableCopyActions["copySelection"];
196
197
  };
197
198
  declare function useGlideTable<T extends Record<string, unknown>>(options: UseGlideTableOptions<T>): UseGlideTableResult<T>;
198
199
 
@@ -211,25 +212,73 @@ declare function useCellEdit<T extends Record<string, unknown>>({ data, rows, on
211
212
  cancelEdit: () => void;
212
213
  };
213
214
 
215
+ type ParsedClipboardTSV = {
216
+ values: string[][];
217
+ /**
218
+ * Relative tree depth per row when the TSV looks like subtree-copy indentation
219
+ * (first row unindented, at least one later row with leading empty cells).
220
+ * Otherwise all zeros — leading blanks are preserved as real cell values.
221
+ */
222
+ depths: number[];
223
+ };
224
+ /** Parse Excel/Sheets-style TSV from the clipboard. Trailing newlines are ignored. */
225
+ declare function parseClipboardTSV(text: string): string[][];
226
+ /**
227
+ * Parse TSV and recover relative tree depth from leading tabs
228
+ * (encoded by subtree copy as leading empty cells).
229
+ */
230
+ declare function parseClipboardTSVWithDepths(text: string): ParsedClipboardTSV;
231
+ /** Resolve visible column ids starting at `startCol` for `width` columns. */
232
+ declare function resolvePasteColumnIds<T extends Record<string, unknown>>(rows: Row<T>[], startCol: number, width: number): string[];
233
+ declare function buildRowsPastePayload<T extends Record<string, unknown>>(rows: Row<T>[], startRow: number, startCol: number, text: string, mode: PasteMode, endRow?: number): RowsPastePayload | null;
234
+ declare function isEditablePasteTarget(target: EventTarget | null): boolean;
235
+
236
+ type CopySelectionOptions = {
237
+ /** When true, collapsed tree descendants are included. Defaults to false. */
238
+ includeDescendants?: boolean;
239
+ };
214
240
  type UseCellSelectionOptions<T extends Record<string, unknown>> = {
215
241
  data: T[];
216
242
  rows: Row<T>[];
217
243
  enabled?: boolean;
244
+ /** Enables Ctrl/Cmd+Shift+C subtree copy. Defaults to true when tree expand is enabled. */
245
+ enableSubtreeCopy?: boolean;
246
+ /** Enables Ctrl/Cmd+Shift+V insert paste. Defaults to true. */
247
+ enableInsertPaste?: boolean;
218
248
  onDataChange?: (data: T[]) => void;
219
249
  onBatchChange?: (changes: Array<{
220
250
  rowId: string;
221
251
  columnId: string;
222
252
  value: unknown;
223
253
  }>) => void;
254
+ onRowsPaste?: (payload: RowsPastePayload) => void;
224
255
  };
225
- declare function useCellSelection<T extends Record<string, unknown>>({ data, rows, enabled, onDataChange, onBatchChange, }: UseCellSelectionOptions<T>): {
256
+ declare function useCellSelection<T extends Record<string, unknown>>({ data, rows, enabled, enableSubtreeCopy, enableInsertPaste, onDataChange, onBatchChange, onRowsPaste, }: UseCellSelectionOptions<T>): {
226
257
  dragState: DragState;
227
258
  activeSelectionBounds: CellSelectionBounds | null;
228
259
  handleCellMouseDown: (rowIndex: number, colIndex: number) => void;
229
260
  handleCellMouseEnter: (rowIndex: number, colIndex: number) => void;
230
261
  handleFillHandleMouseDown: (rowIndex: number, colIndex: number) => void;
262
+ copySelection: (options?: CopySelectionOptions) => Promise<boolean>;
231
263
  };
232
264
 
265
+ type CopySelectionMode = "visible" | "subtree";
266
+ type CopyRowEntry<T extends Record<string, unknown>> = {
267
+ row: T;
268
+ /** Tree depth relative to the table root (0 = top-level). */
269
+ depth: number;
270
+ };
271
+ declare function flattenSubtreeRows<T extends Record<string, unknown>>(row: T): T[];
272
+ /**
273
+ * Collects copy rows with tree depth so paste can rebuild parent/child nesting.
274
+ * Descendant depth is derived from the walk, not only from `level`.
275
+ */
276
+ declare function collectCopyRowEntries<T extends Record<string, unknown>>(visibleRows: Row<T>[], bounds: CellSelectionBounds, mode?: CopySelectionMode): CopyRowEntry<T>[];
277
+ declare function collectCopyRows<T extends Record<string, unknown>>(visibleRows: Row<T>[], bounds: CellSelectionBounds, mode?: CopySelectionMode): T[];
278
+ declare function serializeCopyRowsToTSV<T extends Record<string, unknown>>(copyRows: T[], visibleRows: Row<T>[], bounds: CellSelectionBounds, depths?: number[]): string;
279
+ declare function serializeSelectionToTSV<T extends Record<string, unknown>>(visibleRows: Row<T>[], bounds: CellSelectionBounds, mode?: CopySelectionMode): string;
280
+ declare function writeSelectionToClipboard<T extends Record<string, unknown>>(visibleRows: Row<T>[], bounds: CellSelectionBounds, mode?: CopySelectionMode): Promise<boolean>;
281
+
233
282
  type CellChange = {
234
283
  rowId: string;
235
284
  columnId: string;
@@ -268,10 +317,14 @@ declare function toggleExpandedRowId(rowId: string, previous: Set<string>): Set<
268
317
  /**
269
318
  * Builds a tree from flat/nested data, then returns only rows visible under expandedRows.
270
319
  * When enabled=false, returns data as-is.
320
+ *
321
+ * Flat rows attach to the nearest *preceding* parent with a matching toggle key
322
+ * (so duplicate keys after paste stay under the pasted parent). Parents must appear
323
+ * before their children; a child whose parent is later in the array becomes a root.
271
324
  */
272
325
  declare const useConvertTreeData: <T extends Record<string, unknown>>({ data, enabled, toggleField, childField, flattenField, qtyField, preventExpand, startIndex, expandedRows, onExpandedRowsChange, }: UseConvertTreeDataParams<T>) => T[];
273
326
 
274
327
  declare function resolveRowSelection(mode: RowSelectionMode, controlledSelection: RowSelectionState | undefined, internalSelection: RowSelectionState): RowSelectionState;
275
328
  declare function applySelectionUpdater(mode: RowSelectionMode, updater: Updater<RowSelectionState>, previous: RowSelectionState): RowSelectionState;
276
329
 
277
- export { CELL_SELECTION_EDGES_CLASS, type CellSelectionBounds, type ColumnRowSpanMap, DEFAULT_TREE_CHILDREN_FIELD, DEFAULT_TREE_ID_FIELD, DEFAULT_TREE_PARENT_ID_FIELD, DEFAULT_TREE_QTY_FIELD, DataTableLabels, DataTableProps, type DragState, type EditingCell, RowSelectionMode, type RowSpanInfo, type TreeRow, type UseConvertTreeDataParams, type UseGlideTableOptions, type UseGlideTableResult, applyCellEdit, applyFillData, applySelectionUpdater, buildColumnRowSpanMap, canExpandRow, collectFillChanges, collectRowSpanColumns, getCellEditDraftValue, getCellSelectionEdgeStyle, getColumnEditType, getRowIndexInMergedCell, hasCellSelectionEdges, isCellInSelection, isColumnEditable, measureMergedSpanRowHeights, parseCellEditValue, resolveRowSelection, resolveRowSpanAt, rowRangeToHeightRatios, toggleExpandedRowId, useCellEdit, useCellSelection, useConvertTreeData, useGlideTable };
330
+ export { CELL_SELECTION_EDGES_CLASS, type CellSelectionBounds, type ColumnRowSpanMap, type CopyRowEntry, type CopySelectionMode, DEFAULT_TREE_CHILDREN_FIELD, DEFAULT_TREE_ID_FIELD, DEFAULT_TREE_PARENT_ID_FIELD, DEFAULT_TREE_QTY_FIELD, DataTableCopyActions, DataTableLabels, DataTableProps, type DragState, type EditingCell, PasteMode, RowSelectionMode, type RowSpanInfo, RowsPastePayload, type TreeRow, type UseConvertTreeDataParams, type UseGlideTableOptions, type UseGlideTableResult, applyCellEdit, applyFillData, applySelectionUpdater, buildColumnRowSpanMap, buildRowsPastePayload, canExpandRow, collectCopyRowEntries, collectCopyRows, collectFillChanges, collectRowSpanColumns, flattenSubtreeRows, getCellEditDraftValue, getCellSelectionEdgeStyle, getColumnEditType, getRowIndexInMergedCell, hasCellSelectionEdges, isCellInSelection, isColumnEditable, isEditablePasteTarget, measureMergedSpanRowHeights, parseCellEditValue, parseClipboardTSV, parseClipboardTSVWithDepths, resolvePasteColumnIds, resolveRowSelection, resolveRowSpanAt, rowRangeToHeightRatios, serializeCopyRowsToTSV, serializeSelectionToTSV, toggleExpandedRowId, useCellEdit, useCellSelection, useConvertTreeData, useGlideTable, writeSelectionToClipboard };