1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-12-19 10:42:29 +03:00

Esbuild & Mentions: Updated interaction stability and build system

- Updated esbuild system to be module, and fixed build command.
- Reverted module use in package.json by default as this impacted test
  runs/files.
- Updated mention user select:
  - To look better in dark mode.
  - To not remove text after on select.
  - To properly revert/restore focus on enter or cancel.
This commit is contained in:
Dan Brown
2025-12-17 21:11:01 +00:00
parent 3d9aba7b1f
commit 90fc02c57f
7 changed files with 38 additions and 13 deletions

View File

@@ -151,8 +151,6 @@ export function createCommentEditorInstance(container: HTMLElement, htmlContent:
theme: theme,
});
// TODO - Dedupe this with the basic editor instance
// Changed elements: namespace, registerMentions, toolbar, public event usage, mentioned decorator
const context: EditorUiContext = buildEditorUI(container, editor, options);
editor.setRootElement(context.editorDOM);

View File

@@ -6,6 +6,7 @@ import {KEY_AT_COMMAND} from "lexical/LexicalCommands";
import {$createMentionNode, $isMentionNode, MentionNode} from "@lexical/link/LexicalMentionNode";
import {EditorUiContext} from "../ui/framework/core";
import {MentionDecorator} from "../ui/decorators/MentionDecorator";
import {$selectSingleNode} from "../utils/selection";
function enterUserSelectMode(context: EditorUiContext, selection: RangeSelection) {
@@ -25,10 +26,13 @@ function enterUserSelectMode(context: EditorUiContext, selection: RangeSelection
}
const split = textNode.splitText(offset);
const newNode = split[atStart ? 0 : 1];
const priorTextNode = split[0];
const afterTextNode = split[atStart ? 0 : 1];
const mention = $createMentionNode(0, '', '');
newNode.replace(mention);
priorTextNode.insertAfter(mention);
afterTextNode.spliceText(0, 1, '', false);
$selectSingleNode(mention);
requestAnimationFrame(() => {
const mentionDecorator = context.manager.getDecoratorByNodeKey(mention.getKey());

View File

@@ -170,14 +170,24 @@ export class MentionDecorator extends EditorDecorator {
this.dropdownContainer?.remove();
this.abortController = null;
this.dropdownContainer = null;
this.context.manager.focus();
}
revertMention() {
this.hideSelection();
this.context.editor.update(() => {
const text = $createTextNode('@');
const before = this.getNode().getPreviousSibling();
this.getNode().replace(text);
text.selectEnd();
requestAnimationFrame(() => {
this.context.editor.update(() => {
if (text.isAttached()) {
text.selectEnd();
} else if (before?.isAttached()) {
before?.selectEnd();
}
});
});
});
}

View File

@@ -206,6 +206,14 @@ export class EditorUIManager {
}
}
/**
* Set the UI focus to the editor.
*/
focus(): void {
this.getContext().editorDOM.focus();
this.getContext().editor.focus();
}
protected updateContextToolbars(update: EditorUiStateUpdate): void {
for (let i = this.activeContextToolbars.length - 1; i >= 0; i--) {
const toolbar = this.activeContextToolbars[i];