mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-12-23 23:02:08 +03:00
Lexical: Added better selection display for collapisble blocks
This commit is contained in:
@@ -20,6 +20,7 @@ import {modals} from "./ui/defaults/modals";
|
||||
import {CodeBlockDecorator} from "./ui/decorators/code-block";
|
||||
import {DiagramDecorator} from "./ui/decorators/diagram";
|
||||
import {registerMouseHandling} from "./services/mouse-handling";
|
||||
import {registerSelectionHandling} from "./services/selection-handling";
|
||||
|
||||
const theme = {
|
||||
text: {
|
||||
@@ -53,6 +54,7 @@ export function createPageEditorInstance(container: HTMLElement, htmlContent: st
|
||||
registerShortcuts(context),
|
||||
registerKeyboardHandling(context),
|
||||
registerMouseHandling(context),
|
||||
registerSelectionHandling(context),
|
||||
registerTableResizer(editor, context.scrollDOM),
|
||||
registerTableSelectionHandler(editor),
|
||||
registerTaskListHandler(editor, context.editorDOM),
|
||||
|
||||
49
resources/js/wysiwyg/services/selection-handling.ts
Normal file
49
resources/js/wysiwyg/services/selection-handling.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import {EditorUiContext} from "../ui/framework/core";
|
||||
import {
|
||||
$getSelection,
|
||||
COMMAND_PRIORITY_LOW,
|
||||
SELECTION_CHANGE_COMMAND
|
||||
} from "lexical";
|
||||
import {$isDetailsNode} from "@lexical/rich-text/LexicalDetailsNode";
|
||||
|
||||
|
||||
const trackedDomNodes = new Set<HTMLElement>();
|
||||
|
||||
/**
|
||||
* Set a selection indicator on nodes which require it.
|
||||
* @param context
|
||||
*/
|
||||
function setSelectionIndicator(context: EditorUiContext): boolean {
|
||||
|
||||
for (const domNode of trackedDomNodes) {
|
||||
domNode.classList.remove('selected');
|
||||
trackedDomNodes.delete(domNode);
|
||||
}
|
||||
|
||||
const selection = $getSelection();
|
||||
const nodes = selection?.getNodes() || [];
|
||||
|
||||
if (nodes.length === 1) {
|
||||
if ($isDetailsNode(nodes[0])) {
|
||||
const domEl = context.editor.getElementByKey(nodes[0].getKey());
|
||||
if (domEl) {
|
||||
domEl.classList.add('selected');
|
||||
trackedDomNodes.add(domEl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
export function registerSelectionHandling(context: EditorUiContext): () => void {
|
||||
const unregisterSelectionChange = context.editor.registerCommand(SELECTION_CHANGE_COMMAND, (): boolean => {
|
||||
setSelectionIndicator(context);
|
||||
return false;
|
||||
}, COMMAND_PRIORITY_LOW);
|
||||
|
||||
|
||||
return () => {
|
||||
unregisterSelectionChange();
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user