Compare commits

...

1 Commits

Author SHA1 Message Date
Tom Moor 4811fb9f4d fix: Invisible JS error 2025-05-04 09:54:58 -04:00
+62 -19
View File
@@ -6,6 +6,30 @@ import {
selectedRect,
} from "prosemirror-tables";
/**
* Checks if the current selection is a column selection.
* @param state The editor state.
* @returns True if the selection is a column selection, false otherwise.
*/
export function isColSelection(state: EditorState): boolean {
if (state.selection instanceof CellSelection) {
return state.selection.isColSelection();
}
return false;
}
/**
* Checks if the current selection is a row selection.
* @param state The editor state.
* @returns True if the selection is a row selection, false otherwise.
*/
export function isRowSelection(state: EditorState): boolean {
if (state.selection instanceof CellSelection) {
return state.selection.isRowSelection();
}
return false;
}
export function getColumnIndex(state: EditorState): number | undefined {
if (state.selection instanceof CellSelection) {
if (state.selection.isColSelection()) {
@@ -62,13 +86,18 @@ export function getCellsInRow(index: number) {
};
}
/**
* Check if a specific column is selected in the editor.
*
* @param state The editor state
* @param index The index of the column to check
* @returns Boolean indicating if the column is selected
*/
export function isColumnSelected(index: number) {
return (state: EditorState): boolean => {
if (state.selection instanceof CellSelection) {
if (state.selection.isColSelection()) {
const rect = selectedRect(state);
return rect.left <= index && rect.right > index;
}
if (isColSelection(state)) {
const rect = selectedRect(state);
return rect.left <= index && rect.right > index;
}
return false;
@@ -106,28 +135,42 @@ export function isHeaderEnabled(
return true;
}
/**
* Check if a specific row is selected in the editor.
*
* @param state The editor state
* @param index The index of the row to check
* @returns Boolean indicating if the row is selected
*/
export function isRowSelected(index: number) {
return (state: EditorState): boolean => {
if (state.selection instanceof CellSelection) {
if (state.selection.isRowSelection()) {
const rect = selectedRect(state);
return rect.top <= index && rect.bottom > index;
}
if (isRowSelection(state)) {
const rect = selectedRect(state);
return rect.top <= index && rect.bottom > index;
}
return false;
};
}
/**
* Check if an entire table is selected in the editor.
*
* @param state The editor state
* @returns Boolean indicating if the table is selected
*/
export function isTableSelected(state: EditorState): boolean {
const rect = selectedRect(state);
if (state.selection instanceof CellSelection) {
const rect = selectedRect(state);
return (
rect.top === 0 &&
rect.left === 0 &&
rect.bottom === rect.map.height &&
rect.right === rect.map.width &&
!state.selection.empty &&
state.selection instanceof CellSelection
);
return (
rect.top === 0 &&
rect.left === 0 &&
rect.bottom === rect.map.height &&
rect.right === rect.map.width &&
!state.selection.empty
);
}
return false;
}