mirror of
https://github.com/outline/outline.git
synced 2026-12-02 01:34:47 +03:00
fix: Invisible JS error
This commit is contained in:
1 file changed
+62
-19
@@ -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;
|
||||
}
|
||||
Reference in new issue
Block a user