Skip to content

Commit

Permalink
Rename onCopy/Paste -> onCellCopy/Paste
Browse files Browse the repository at this point in the history
  • Loading branch information
amanmahajan7 committed Dec 12, 2024
1 parent 3288bf3 commit 2eab97f
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 29 deletions.
34 changes: 17 additions & 17 deletions src/DataGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ import type {
CalculatedColumn,
CellClickArgs,
CellClipboardEvent,
CellCopyPasteEvent,
CellKeyboardEvent,
CellKeyDownArgs,
CellMouseEvent,
CellNavigationMode,
CellSelectArgs,
Column,
ColumnOrColumnGroup,
CopyPasteEvent,
Direction,
FillEvent,
Maybe,
Expand Down Expand Up @@ -161,12 +161,6 @@ export interface DataGridProps<R, SR = unknown, K extends Key = Key> extends Sha
onSortColumnsChange?: Maybe<(sortColumns: SortColumn[]) => void>;
defaultColumnOptions?: Maybe<DefaultColumnOptions<NoInfer<R>, NoInfer<SR>>>;
onFill?: Maybe<(event: FillEvent<NoInfer<R>>) => NoInfer<R>>;
onCopy?: Maybe<
(args: CopyPasteEvent<NoInfer<R>, NoInfer<SR>>, event: CellClipboardEvent) => void
>;
onPaste?: Maybe<
(args: CopyPasteEvent<NoInfer<R>, NoInfer<SR>>, event: CellClipboardEvent) => NoInfer<R>
>;

/**
* Event props
Expand All @@ -186,6 +180,12 @@ export interface DataGridProps<R, SR = unknown, K extends Key = Key> extends Sha
onCellKeyDown?: Maybe<
(args: CellKeyDownArgs<NoInfer<R>, NoInfer<SR>>, event: CellKeyboardEvent) => void
>;
onCellCopy?: Maybe<
(args: CellCopyPasteEvent<NoInfer<R>, NoInfer<SR>>, event: CellClipboardEvent) => void
>;
onCellPaste?: Maybe<
(args: CellCopyPasteEvent<NoInfer<R>, NoInfer<SR>>, event: CellClipboardEvent) => NoInfer<R>
>;
/** Function called whenever cell selection is changed */
onSelectedCellChange?: Maybe<(args: CellSelectArgs<NoInfer<R>, NoInfer<SR>>) => void>;
/** Called when the grid is scrolled */
Expand Down Expand Up @@ -251,8 +251,8 @@ function DataGrid<R, SR, K extends Key>(
onColumnResize,
onColumnsReorder,
onFill,
onCopy,
onPaste,
onCellCopy,
onCellPaste,
// Toggles and modes
enableVirtualization: rawEnableVirtualization,
// Miscellaneous
Expand Down Expand Up @@ -647,20 +647,20 @@ function DataGrid<R, SR, K extends Key>(
updateRow(columns[selectedPosition.idx], selectedPosition.rowIdx, selectedPosition.row);
}

function handleCopy(event: CellClipboardEvent) {
function handleCellCopy(event: CellClipboardEvent) {
if (!selectedCellIsWithinViewportBounds) return;
const { idx, rowIdx } = selectedPosition;
onCopy?.({ row: rows[rowIdx], column: columns[idx] }, event);
onCellCopy?.({ row: rows[rowIdx], column: columns[idx] }, event);
}

function handlePaste(event: CellClipboardEvent) {
if (!onPaste || !onRowsChange || !isCellEditable(selectedPosition)) {
function handleCellPaste(event: CellClipboardEvent) {
if (!onCellPaste || !onRowsChange || !isCellEditable(selectedPosition)) {
return;
}

const { idx, rowIdx } = selectedPosition;
const column = columns[idx];
const updatedRow = onPaste({ row: rows[rowIdx], column }, event);
const updatedRow = onCellPaste({ row: rows[rowIdx], column }, event);
updateRow(column, rowIdx, updatedRow);
}

Expand All @@ -679,7 +679,7 @@ function DataGrid<R, SR, K extends Key>(
return;
}

if (isCellEditable(selectedPosition) && isDefaultCellInput(event, onPaste != null)) {
if (isCellEditable(selectedPosition) && isDefaultCellInput(event, onCellPaste != null)) {
setSelectedPosition(({ idx, rowIdx }) => ({
idx,
rowIdx,
Expand Down Expand Up @@ -1083,8 +1083,8 @@ function DataGrid<R, SR, K extends Key>(
ref={gridRef}
onScroll={handleScroll}
onKeyDown={handleKeyDown}
onCopy={handleCopy}
onPaste={handlePaste}
onCopy={handleCellCopy}
onPaste={handleCellPaste}
data-testid={testId}
>
<DataGridDefaultRenderersProvider value={defaultGridComponents}>
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export type {
SelectHeaderRowEvent,
SelectRowEvent,
FillEvent,
CopyPasteEvent,
CellCopyPasteEvent,
SortDirection,
SortColumn,
ColSpanArgs,
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ export interface FillEvent<TRow> {
targetRow: TRow;
}

export interface CopyPasteEvent<TRow, TSummaryRow = unknown> {
export interface CellCopyPasteEvent<TRow, TSummaryRow = unknown> {
row: TRow;
column: CalculatedColumn<TRow, TSummaryRow>;
}
Expand Down
4 changes: 2 additions & 2 deletions test/browser/TreeDataGrid.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function TestGrid({ groupBy }: { groupBy: string[] }) {
(): ReadonlySet<unknown> => new Set<unknown>([])
);

function onPaste(event: PasteEvent<Row>) {
function onCellPaste(event: PasteEvent<Row>) {
return {
...event.targetRow,
[event.targetColumnKey]: event.sourceRow[event.sourceColumnKey as keyof Row]
Expand All @@ -120,7 +120,7 @@ function TestGrid({ groupBy }: { groupBy: string[] }) {
expandedGroupIds={expandedGroupIds}
onExpandedGroupIdsChange={setExpandedGroupIds}
onRowsChange={setRows}
onPaste={onPaste}
onCellPaste={onCellPaste}
/>
);
}
Expand Down
4 changes: 2 additions & 2 deletions test/browser/copyPaste.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ function CopyPasteTest({
rows={rows}
bottomSummaryRows={bottomSummaryRows}
onRowsChange={setRows}
onPaste={onPasteCallback ? onPaste : undefined}
onCopy={onCopyCallback ? onCopySpy : undefined}
onCellPaste={onPasteCallback ? onPaste : undefined}
onCellCopy={onCopyCallback ? onCopySpy : undefined}
/>
);
}
Expand Down
12 changes: 6 additions & 6 deletions website/routes/AllFeatures.lazy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { css } from '@linaria/core';
import clsx from 'clsx';

import DataGrid, { SelectColumn, textEditor } from '../../src';
import type { CalculatedColumn, Column, CopyPasteEvent, FillEvent } from '../../src';
import type { CalculatedColumn, CellCopyPasteEvent, Column, FillEvent } from '../../src';
import { textEditorClassname } from '../../src/editors/textEditor';
import { useDirection } from '../directionContext';

Expand Down Expand Up @@ -182,7 +182,7 @@ function AllFeatures() {
return { ...targetRow, [columnKey]: sourceRow[columnKey as keyof Row] };
}

function handlePaste({ row, column }: CopyPasteEvent<Row>): Row {
function handleCellPaste({ row, column }: CellCopyPasteEvent<Row>): Row {
if (!copiedCell) {
return row;
}
Expand All @@ -205,8 +205,8 @@ function AllFeatures() {
return { ...row, [targetColumnKey]: sourceRow[sourceColumnKey as keyof Row] };
}

function handleCopy(
{ row, column }: CopyPasteEvent<Row>,
function handleCellCopy(
{ row, column }: CellCopyPasteEvent<Row>,
event: React.ClipboardEvent<HTMLDivElement>
): void {
// copy highlighted text only
Expand Down Expand Up @@ -241,8 +241,8 @@ function AllFeatures() {
rowKeyGetter={rowKeyGetter}
onRowsChange={setRows}
onFill={handleFill}
onCopy={handleCopy}
onPaste={handlePaste}
onCellCopy={handleCellCopy}
onCellPaste={handleCellPaste}
rowHeight={30}
selectedRows={selectedRows}
isRowSelectionDisabled={(row) => row.id === 'id_2'}
Expand Down

0 comments on commit 2eab97f

Please sign in to comment.