mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-07-30 04:23:11 +03:00
Lexical: Added table column cut/copy/paste support
This commit is contained in:
@ -29,9 +29,15 @@ import {
|
||||
} from "../../../utils/tables";
|
||||
import {$isCustomTableRowNode} from "../../../nodes/custom-table-row";
|
||||
import {
|
||||
$copySelectedColumnsToClipboard,
|
||||
$copySelectedRowsToClipboard,
|
||||
$cutSelectedColumnsToClipboard,
|
||||
$cutSelectedRowsToClipboard,
|
||||
$pasteClipboardRowsBefore, $pasteRowsAfter, isRowClipboardEmpty
|
||||
$pasteClipboardRowsBefore,
|
||||
$pasteClipboardRowsAfter,
|
||||
isColumnClipboardEmpty,
|
||||
isRowClipboardEmpty,
|
||||
$pasteClipboardColumnsBefore, $pasteClipboardColumnsAfter
|
||||
} from "../../../utils/table-copy-paste";
|
||||
|
||||
const neverActive = (): boolean => false;
|
||||
@ -180,7 +186,7 @@ export const cutRow: EditorButtonDefinition = {
|
||||
try {
|
||||
$cutSelectedRowsToClipboard();
|
||||
} catch (e: any) {
|
||||
context.error(e.toString());
|
||||
context.error(e);
|
||||
}
|
||||
});
|
||||
},
|
||||
@ -196,7 +202,7 @@ export const copyRow: EditorButtonDefinition = {
|
||||
try {
|
||||
$copySelectedRowsToClipboard();
|
||||
} catch (e: any) {
|
||||
context.error(e.toString());
|
||||
context.error(e);
|
||||
}
|
||||
});
|
||||
},
|
||||
@ -212,7 +218,7 @@ export const pasteRowBefore: EditorButtonDefinition = {
|
||||
try {
|
||||
$pasteClipboardRowsBefore(context.editor);
|
||||
} catch (e: any) {
|
||||
context.error(e.toString());
|
||||
context.error(e);
|
||||
}
|
||||
});
|
||||
},
|
||||
@ -226,9 +232,9 @@ export const pasteRowAfter: EditorButtonDefinition = {
|
||||
action(context: EditorUiContext) {
|
||||
context.editor.update(() => {
|
||||
try {
|
||||
$pasteRowsAfter(context.editor);
|
||||
$pasteClipboardRowsAfter(context.editor);
|
||||
} catch (e: any) {
|
||||
context.error(e.toString());
|
||||
context.error(e);
|
||||
}
|
||||
});
|
||||
},
|
||||
@ -240,8 +246,12 @@ export const cutColumn: EditorButtonDefinition = {
|
||||
label: 'Cut column',
|
||||
format: 'long',
|
||||
action(context: EditorUiContext) {
|
||||
context.editor.getEditorState().read(() => {
|
||||
// TODO
|
||||
context.editor.update(() => {
|
||||
try {
|
||||
$cutSelectedColumnsToClipboard();
|
||||
} catch (e: any) {
|
||||
context.error(e);
|
||||
}
|
||||
});
|
||||
},
|
||||
isActive: neverActive,
|
||||
@ -253,7 +263,11 @@ export const copyColumn: EditorButtonDefinition = {
|
||||
format: 'long',
|
||||
action(context: EditorUiContext) {
|
||||
context.editor.getEditorState().read(() => {
|
||||
// TODO
|
||||
try {
|
||||
$copySelectedColumnsToClipboard();
|
||||
} catch (e: any) {
|
||||
context.error(e);
|
||||
}
|
||||
});
|
||||
},
|
||||
isActive: neverActive,
|
||||
@ -264,24 +278,32 @@ export const pasteColumnBefore: EditorButtonDefinition = {
|
||||
label: 'Paste column before',
|
||||
format: 'long',
|
||||
action(context: EditorUiContext) {
|
||||
context.editor.getEditorState().read(() => {
|
||||
// TODO
|
||||
context.editor.update(() => {
|
||||
try {
|
||||
$pasteClipboardColumnsBefore(context.editor);
|
||||
} catch (e: any) {
|
||||
context.error(e);
|
||||
}
|
||||
});
|
||||
},
|
||||
isActive: neverActive,
|
||||
isDisabled: cellNotSelected,
|
||||
isDisabled: (selection) => cellNotSelected(selection) || isColumnClipboardEmpty(),
|
||||
};
|
||||
|
||||
export const pasteColumnAfter: EditorButtonDefinition = {
|
||||
label: 'Paste column after',
|
||||
format: 'long',
|
||||
action(context: EditorUiContext) {
|
||||
context.editor.getEditorState().read(() => {
|
||||
// TODO
|
||||
context.editor.update(() => {
|
||||
try {
|
||||
$pasteClipboardColumnsAfter(context.editor);
|
||||
} catch (e: any) {
|
||||
context.error(e);
|
||||
}
|
||||
});
|
||||
},
|
||||
isActive: neverActive,
|
||||
isDisabled: cellNotSelected,
|
||||
isDisabled: (selection) => cellNotSelected(selection) || isColumnClipboardEmpty(),
|
||||
};
|
||||
|
||||
export const insertColumnBefore: EditorButtonDefinition = {
|
||||
|
@ -14,7 +14,7 @@ export type EditorUiContext = {
|
||||
containerDOM: HTMLElement; // DOM element which contains all editor elements
|
||||
scrollDOM: HTMLElement; // DOM element which is the main content scroll container
|
||||
translate: (text: string) => string; // Translate function
|
||||
error: (text: string) => void; // Error reporting function
|
||||
error: (text: string|Error) => void; // Error reporting function
|
||||
manager: EditorUIManager; // UI Manager instance for this editor
|
||||
options: Record<string, any>; // General user options which may be used by sub elements
|
||||
};
|
||||
|
@ -21,8 +21,9 @@ export function buildEditorUI(container: HTMLElement, element: HTMLElement, scro
|
||||
scrollDOM: scrollContainer,
|
||||
manager,
|
||||
translate: (text: string): string => text, // TODO - Implement
|
||||
error(error: string): void {
|
||||
window.$events.error(error); // TODO - Translate
|
||||
error(error: string|Error): void {
|
||||
const message = error instanceof Error ? error.message : error;
|
||||
window.$events.error(message); // TODO - Translate
|
||||
},
|
||||
options,
|
||||
};
|
||||
|
Reference in New Issue
Block a user