Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert editable text changes #10540

Merged
merged 6 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/social-glasses-begin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@gradio/dataframe": minor
"gradio": minor
---

feat:Revert editable text changes
24 changes: 2 additions & 22 deletions js/dataframe/shared/Table.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,7 @@
header_edit = false;

selected_cells = handle_selection([row, col], selected_cells, event);
parent.focus();

if (selected_cells.length === 1 && editable) {
editing = [row, col];
Expand Down Expand Up @@ -999,7 +1000,6 @@
<td
tabindex={show_row_numbers && j === 0 ? -1 : 0}
on:touchstart={(event) => {
if (!editable) return;
const touch = event.touches[0];
const mouseEvent = new MouseEvent("click", {
clientX: touch.clientX,
Expand All @@ -1011,17 +1011,12 @@
handle_cell_click(mouseEvent, index, j);
}}
on:mousedown={(event) => {
if (!editable) return;
event.preventDefault();
event.stopPropagation();
}}
on:click={(event) => {
if (!editable) return;
handle_cell_click(event, index, j);
}}
on:click={(event) => handle_cell_click(event, index, j)}
style:width="var(--cell-width-{j})"
style={styling?.[index]?.[j] || ""}
class:not-editable={!editable}
class={is_cell_selected([index, j], selected_cells)}
class:menu-active={active_cell_menu &&
active_cell_menu.row === index &&
Expand Down Expand Up @@ -1437,19 +1432,4 @@
.cell-selected.no-top.no-bottom.no-left.no-right {
box-shadow: none;
}

.not-editable {
user-select: text;
cursor: text;
}

.not-editable .cell-wrap {
pointer-events: none;
}

.not-editable :global(.editable-cell) {
pointer-events: auto;
user-select: text;
cursor: text;
}
</style>
26 changes: 1 addition & 25 deletions js/dataframe/shared/utils/table_utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import {
make_cell_id,
make_header_id,
process_data,
make_headers,
get_data_at
make_headers
} from "./table_utils";

describe("table_utils", () => {
Expand Down Expand Up @@ -112,27 +111,4 @@ describe("table_utils", () => {
).toBe(true);
});
});

describe("get_data_at", () => {
const test_data = [
[
{ id: "1", value: "A" },
{ id: "2", value: "B" }
],
[
{ id: "3", value: "C" },
{ id: "4", value: "D" }
]
];

test("gets data at valid indices", () => {
expect(get_data_at(test_data, 0, 0)).toBe("A");
expect(get_data_at(test_data, 1, 1)).toBe("D");
});

test("returns undefined for invalid indices", () => {
expect(get_data_at(test_data, 2, 0)).toBeUndefined();
expect(get_data_at(test_data, 0, 2)).toBeUndefined();
});
});
});
35 changes: 24 additions & 11 deletions js/dataframe/shared/utils/table_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,6 @@ export function make_headers(
});
}

export function get_data_at(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this isnt being used so I've also removed this

data: TableData,
row: number,
col: number
): string | number | undefined {
return data?.[row]?.[col]?.value;
}

export function get_max(data: TableData): TableCell[] {
if (!data || !data.length) return [];
return data[0];
Expand All @@ -129,10 +121,31 @@ export async function copy_table_data(
data: TableData,
selected_cells: [number, number][]
): Promise<void> {
const selected_data = selected_cells.map(
([row, col]) => data[row][col].value
const csv = selected_cells.reduce(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changes tsv copy to csv

(acc: { [key: string]: { [key: string]: string } }, [row, col]) => {
acc[row] = acc[row] || {};
const value = String(data[row][col].value);
acc[row][col] =
value.includes(",") || value.includes('"') || value.includes("\n")
? `"${value.replace(/"/g, '""')}"`
: value;
return acc;
},
{}
);
await navigator.clipboard.writeText(selected_data.join("\t"));

const rows = Object.keys(csv).sort((a, b) => +a - +b);
const cols = Object.keys(csv[rows[0]]).sort((a, b) => +a - +b);
const text = rows
.map((r) => cols.map((c) => csv[r][c] || "").join(","))
.join("\n");

try {
await navigator.clipboard.writeText(text);
} catch (err) {
console.error("Copy failed:", err);
throw new Error("Failed to copy to clipboard: " + (err as Error).message);
}
}

export function handle_file_upload(
Expand Down
Loading