Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
client/text editor: enable block drag grip also for the fixed formatting toolbar layout
Adorian Dorand82b48658fcb
diff --git a/apps/client/src/widgets/type_widgets/text/config.spec.ts b/apps/client/src/widgets/type_widgets/text/config.spec.tsindex 7793e16d1b..a5e312c5f3 100644--- a/apps/client/src/widgets/type_widgets/text/config.spec.ts+++ b/apps/client/src/widgets/type_widgets/text/config.spec.ts@@ -617,4 +617,17 @@ describe("CK config - disabled plugins", () => {expect(enabled.removePlugins).not.toContain("TriliumEmojiMention");expect(enabled.removePlugins).not.toContain("TriliumSlashCommands");});++ it("removes the block drag handle in the mobile layout", async () => {+ const originalDevice = window.glob.device;+ try {+ window.glob.device = "desktop";+ expect((await buildConfig(baseOpts())).removePlugins).not.toContain("BlockDragHandle");++ window.glob.device = "mobile";+ expect((await buildConfig(baseOpts())).removePlugins).toContain("BlockDragHandle");+ } finally {+ window.glob.device = originalDevice;+ }+ });});diff --git a/apps/client/src/widgets/type_widgets/text/config.ts b/apps/client/src/widgets/type_widgets/text/config.tsindex 1dbd6d8ef4..d3be8278df 100644--- a/apps/client/src/widgets/type_widgets/text/config.ts+++ b/apps/client/src/widgets/type_widgets/text/config.ts@@ -12,7 +12,7 @@ import options from "../../../services/options.js";import { sanitizeNoteContentHtml } from "../../../services/sanitize_content.js";import { ensureMimeTypesForHighlighting, isSyntaxHighlightEnabled } from "../../../services/syntax_highlight.js";import { getTaskStateDefinitions, openCustomTaskStateConfig } from "../../../services/task_states.js";-import { isMac, openInAppHelpFromUrl } from "../../../services/utils.js";+import { isMac, isMobile, openInAppHelpFromUrl } from "../../../services/utils.js";import { resolveContentLanguage } from "../../../utils/formatters.js";import SAMPLE_DIAGRAMS from "../mermaid/sample_diagrams.js";import buildAiAssistantStream, { type AiNoteLocationProvider, buildAiAssistantQuickActions } from "./ai_assistant_stream.js";@@ -463,5 +463,10 @@ function getDisabledPlugins() {disabledPlugins.push("TriliumSlashCommands");}+ // The mobile layout leaves no margin beside the blocks for the drag handle.+ if (isMobile()) {+ disabledPlugins.push("BlockDragHandle");+ }+return disabledPlugins;}diff --git a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Text/Formatting toolbar.html b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Text/Formatting toolbar.htmlindex 30a81fa5ce..371427ae87 100644--- a/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Text/Formatting toolbar.html+++ b/apps/server/src/assets/doc_notes/en/User Guide/User Guide/Note Types/Text/Formatting toolbar.html@@ -15,6 +15,9 @@</p><p>Clicking this popup will reveal the formatting options that are specificto the entire paragraph, such as setting a heading, lists, tables, etc.</p>+<p>The dots are also a drag handle: drag them to move the paragraph, all+ the selected paragraphs, or a selected element such as an image, a table+ or an included note to another place in the note.</p><p><img src="3_Formatting toolbar_image.png"></p>@@ -30,6 +33,11 @@useful if a lot of formatting is needed.</p><p>All the options are combined into a single toolbar that will appear aspart of the <a href="#root/_help_BlN9DFI679QC">Ribbon</a>.</p>+<p>The sequence of dots to the left of the current paragraph is still shown,+ but only as a drag handle: drag it to move the paragraph, all the selected+ paragraphs, or a selected element such as an image, a table or an included+ note to another place in the note. Clicking it does not open a popup. The+ drag handle is not shown in the mobile layout.</p><p><img src="2_Formatting toolbar_image.png"></p>diff --git a/docs/User Guide/User Guide/Note Types/Text/Formatting toolbar.md b/docs/User Guide/User Guide/Note Types/Text/Formatting toolbar.mdindex db316b8889..412957e752 100644--- a/docs/User Guide/User Guide/Note Types/Text/Formatting toolbar.md+++ b/docs/User Guide/User Guide/Note Types/Text/Formatting toolbar.md@@ -14,6 +14,8 @@ The first popup is the block-level popup. This will appear to the left of the cuClicking this popup will reveal the formatting options that are specific to the entire paragraph, such as setting a heading, lists, tables, etc.+The dots are also a drag handle: drag them to move the paragraph, all the selected paragraphs, or a selected element such as an image, a table or an included note to another place in the note.+### Inline popup@@ -30,6 +32,8 @@ The fixed formatting offers a more traditional editing paradigm, usually usefulAll the options are combined into a single toolbar that will appear as part of the [Ribbon](../../Basic%20Concepts%20and%20Features/UI%20Elements/Ribbon.md).+The sequence of dots to the left of the current paragraph is still shown, but only as a drag handle: drag it to move the paragraph, all the selected paragraphs, or a selected element such as an image, a table or an included note to another place in the note. Clicking it does not open a popup. The drag handle is not shown in the mobile layout.+By default, if the toolbar does not fit on the screen, the rest of the options will be grouped into a single option at the end. It is possible to display items on multiple lines by checking the corresponding option in the _Formatting toolbar_ section.\ No newline at end of filediff --git a/packages/ckeditor5/src/index.spec.ts b/packages/ckeditor5/src/index.spec.tsindex 624780f184..0431a99fbe 100644--- a/packages/ckeditor5/src/index.spec.ts+++ b/packages/ckeditor5/src/index.spec.ts@@ -4,7 +4,7 @@ import { describe, expect, it } from "vitest";// everything, which is exactly what we want to exercise.import "./index.js";import { AttributeEditor, ClassicEditor, PopupEditor } from "./index.js";-import { CORE_PLUGINS, COMMON_PLUGINS, POPUP_EDITOR_PLUGINS } from "./plugins.js";+import { CLASSIC_EDITOR_PLUGINS, COMMON_PLUGINS, CORE_PLUGINS, POPUP_EDITOR_PLUGINS } from "./plugins.js";describe("index (aggregate entry point)", () => {it("sets the CKEditor distribution marker on the window object", () => {@@ -15,8 +15,8 @@ describe("index (aggregate entry point)", () => {expect(AttributeEditor.builtinPlugins).toBe(CORE_PLUGINS);});- it("ClassicEditor.builtinPlugins returns COMMON_PLUGINS", () => {- expect(ClassicEditor.builtinPlugins).toBe(COMMON_PLUGINS);+ it("ClassicEditor.builtinPlugins returns CLASSIC_EDITOR_PLUGINS", () => {+ expect(ClassicEditor.builtinPlugins).toBe(CLASSIC_EDITOR_PLUGINS);});it("PopupEditor.builtinPlugins returns POPUP_EDITOR_PLUGINS", () => {@@ -37,11 +37,10 @@ describe("index (aggregate entry point)", () => {}});- it("PopupEditor.builtinPlugins is a superset of ClassicEditor.builtinPlugins", () => {- const commonPlugins = ClassicEditor.builtinPlugins;- const popupPlugins = PopupEditor.builtinPlugins;- for (const plugin of commonPlugins) {- expect(popupPlugins).toContain(plugin);+ it("ClassicEditor and PopupEditor both build on COMMON_PLUGINS", () => {+ for (const plugin of COMMON_PLUGINS) {+ expect(ClassicEditor.builtinPlugins).toContain(plugin);+ expect(PopupEditor.builtinPlugins).toContain(plugin);}});});diff --git a/packages/ckeditor5/src/index.ts b/packages/ckeditor5/src/index.tsindex 7776bbd901..1e2d89fe55 100644--- a/packages/ckeditor5/src/index.ts+++ b/packages/ckeditor5/src/index.ts@@ -7,7 +7,7 @@ import "./theme/code_block_toolbar.css";import "./theme/link_embed_form.css";import type { ClipboardImageEmbedConfig } from "./plugins/clipboard_image_embed.js";import type { PasteTarget } from "./plugins/cuttonote.js";-import { COMMON_PLUGINS, CORE_PLUGINS, POPUP_EDITOR_PLUGINS } from "./plugins.js";+import { CLASSIC_EDITOR_PLUGINS, CORE_PLUGINS, POPUP_EDITOR_PLUGINS } from "./plugins.js";import { BalloonEditor, DecoupledEditor, FindAndReplaceEditing, FindCommand } from "ckeditor5";export { default as EditorWatchdog } from "./custom_watchdog";export { CHAT_INPUT_PLUGINS, MEMO_PLUGINS } from "./plugins.js";@@ -70,7 +70,7 @@ export class AttributeEditor extends BalloonEditor {*/export class ClassicEditor extends DecoupledEditor {static override get builtinPlugins() {- return COMMON_PLUGINS;+ return CLASSIC_EDITOR_PLUGINS;}}diff --git a/packages/ckeditor5/src/plugins.spec.ts b/packages/ckeditor5/src/plugins.spec.tsindex b44547abe1..2bd1d5580f 100644--- a/packages/ckeditor5/src/plugins.spec.ts+++ b/packages/ckeditor5/src/plugins.spec.ts@@ -4,9 +4,10 @@ import { describe, expect, it } from "vitest";import { createTestEditor } from "../test/editor-kit.js";import { AttributeEditor } from "./index.js";import Admonition from "./plugins/admonition/admonition.js";+import BlockDragHandle from "./plugins/block_drag_handle.js";import ItalicAsEmPlugin from "./plugins/italic_as_em.js";import StrikethroughAsDel from "./plugins/strikethrough_as_del.js";-import { CHAT_INPUT_PLUGINS, COMMON_PLUGINS, CORE_PLUGINS, MEMO_PLUGINS, POPUP_EDITOR_PLUGINS } from "./plugins.js";+import { CHAT_INPUT_PLUGINS, CLASSIC_EDITOR_PLUGINS, COMMON_PLUGINS, CORE_PLUGINS, MEMO_PLUGINS, POPUP_EDITOR_PLUGINS } from "./plugins.js";import CutToNotePlugin from "./plugins/cuttonote.js";import Uploadfileplugin from "./plugins/file_upload/uploadfileplugin.js";import FindInLinkWidgets from "./plugins/find_in_link_widgets.js";@@ -93,6 +94,12 @@ describe("plugin lists", () => {expect(COMMON_PLUGINS).not.toContain(BlockToolbar);});+ it("CLASSIC_EDITOR_PLUGINS adds BlockDragHandle on top of COMMON_PLUGINS", () => {+ expect(CLASSIC_EDITOR_PLUGINS).toContain(BlockDragHandle);+ expect(CLASSIC_EDITOR_PLUGINS).not.toContain(BlockToolbar);+ expect(POPUP_EDITOR_PLUGINS).not.toContain(BlockDragHandle);+ });+// Each of these replaced a premium plugin, which is why `ckeditor5-premium-features` is no// longer a dependency at all. Dropping one of the registrations silently would put the editor// back to missing the feature outright, so pin them here.diff --git a/packages/ckeditor5/src/plugins.ts b/packages/ckeditor5/src/plugins.tsindex 7b9f7ba621..c99bdbf912 100644--- a/packages/ckeditor5/src/plugins.ts+++ b/packages/ckeditor5/src/plugins.ts@@ -68,6 +68,7 @@ import TableSort from "./plugins/table_sort.js";import TableInsertUI from "./plugins/table_insert/table_insert_ui.js";import TableToolbarDropdowns from "./plugins/table_toolbar_dropdowns.js";import ToolbarGroupMenu from "./plugins/toolbar_group_menu.js";+import BlockDragHandle from "./plugins/block_drag_handle.js";/*** Plugins that are specific to Trilium and not part of the CKEditor 5 core, included in both text editors but not in the attribute editor.@@ -272,6 +273,15 @@ export const COMMON_PLUGINS: typeof Plugin[] = [...EXTERNAL_PLUGINS];+/**+ * The set of plugins specific to the fixed toolbar mode. `BlockDragHandle` gives it the block drag+ * handle that the popup editor gets from `BlockToolbar`.+ */+export const CLASSIC_EDITOR_PLUGINS: typeof Plugin[] = [+ ...COMMON_PLUGINS,+ BlockDragHandle,+];+/*** The set of plugins specific to the popup editor (floating toolbar mode), and not the fixed toolbar mode.*/diff --git a/packages/ckeditor5/src/plugins/block_drag_handle.spec.ts b/packages/ckeditor5/src/plugins/block_drag_handle.spec.tsnew file mode 100644index 0000000000..03c4e92235--- /dev/null+++ b/packages/ckeditor5/src/plugins/block_drag_handle.spec.ts@@ -0,0 +1,115 @@+import {+ _getModelData as getModelData, _setModelData as setModelData, type ClassicEditor, Essentials,+ Paragraph+} from "ckeditor5";+import editorStylesheetUrl from "ckeditor5/ckeditor5.css?url";+import { beforeAll, describe, expect, it } from "vitest";++import { createTestEditor } from "../../test/editor-kit.js";+import BlockDragHandle from "./block_drag_handle.js";++describe("BlockDragHandle", () => {+ beforeAll(() => new Promise<void>((resolve, reject) => {+ const link = document.createElement("link");+ link.rel = "stylesheet";+ link.href = editorStylesheetUrl;+ link.onload = () => resolve();+ link.onerror = () => reject(new Error("the editor stylesheet did not load"));+ document.head.appendChild(link);+ }));++ it("shows the handle beside the focused block, hidden when read-only or blurred", async () => {+ const { editor, button } = await createEditor(+ "<paragraph>one</paragraph><paragraph>tw[]o</paragraph>"+ );+ const buttonView = editor.plugins.get(BlockDragHandle).buttonView;+ expect(buttonView?.isVisible).toBe(true);+ expect(button.getAttribute("draggable")).toBe("true");++ const buttonRect = button.getBoundingClientRect();+ const buttonCenter = buttonRect.top + buttonRect.height / 2;+ const editableRect = getEditable(editor).getBoundingClientRect();+ const secondBlockRect = getBlock(editor, 1).getBoundingClientRect();+ expect(buttonRect.right).toBeCloseTo(editableRect.left, 0);+ expect(buttonCenter).toBeGreaterThan(secondBlockRect.top);+ expect(buttonCenter).toBeLessThan(secondBlockRect.bottom);++ button.focus();+ button.click();+ expect(document.activeElement).toBe(getEditable(editor));++ editor.enableReadOnlyMode("spec");+ expect(buttonView?.isVisible).toBe(false);+ editor.disableReadOnlyMode("spec");+ expect(buttonView?.isVisible).toBe(true);++ getEditable(editor).blur();+ await expect.poll(() => buttonView?.isVisible).toBe(false);+ });++ it("drags the selected block to where it is dropped", async () => {+ const { editor, button } = await createEditor(+ "<paragraph>fi[]rst</paragraph><paragraph>second</paragraph>"+ + "<paragraph>third</paragraph>"+ );+ // A constructed `DataTransfer` ignores `effectAllowed` writes, so every drop is a copy.+ const dataTransfer = new DataTransfer();+ Object.defineProperty(dataTransfer, "effectAllowed", { value: "none", writable: true });+ const editableRect = getEditable(editor).getBoundingClientRect();+ const lastBlockRect = getBlock(editor, 2).getBoundingClientRect();+ const dropPoint = {+ clientX: editableRect.left - 50,+ clientY: lastBlockRect.bottom - 2+ };++ button.dispatchEvent(new DragEvent("dragstart", { bubbles: true, dataTransfer }));+ expect(getModelData(editor.model)).toBe(+ "<paragraph>[first]</paragraph><paragraph>second</paragraph>"+ + "<paragraph>third</paragraph>"+ );++ const dropInit = { bubbles: true, dataTransfer, ...dropPoint };+ document.dispatchEvent(new DragEvent("dragover", dropInit));+ document.dispatchEvent(new DragEvent("drop", dropInit));+ button.dispatchEvent(new DragEvent("dragend", { bubbles: true, dataTransfer }));++ expect(editor.getData()).toBe("<p>second</p><p>third</p><p>first</p>");+ });+});++async function createEditor(modelData: string) {+ const editor = await createTestEditor([Essentials, Paragraph, BlockDragHandle]);+ const editorElement = editor.ui.view.element;+ if (editorElement) {+ editorElement.style.margin = "0 100px";+ }+ setModelData(editor.model, modelData);+ editor.editing.view.focus();+ await expect.poll(() => editor.ui.focusTracker.isFocused).toBe(true);+ editor.ui.update();++ const button = editor.plugins.get(BlockDragHandle).buttonView?.element;+ if (!button) {+ throw new Error("The drag handle is not rendered.");+ }++ return { editor, button };+}++function getEditable(editor: ClassicEditor) {+ const editable = editor.ui.getEditableElement();+ if (!editable) {+ throw new Error("The editor has no editable.");+ }++ return editable;+}++function getBlock(editor: ClassicEditor, index: number) {+ const block = getEditable(editor).children.item(index);+ if (!block) {+ throw new Error(`The editor has no block ${index}.`);+ }++ return block;+}diff --git a/packages/ckeditor5/src/plugins/block_drag_handle.ts b/packages/ckeditor5/src/plugins/block_drag_handle.tsnew file mode 100644index 0000000000..6b1aaf9406--- /dev/null+++ b/packages/ckeditor5/src/plugins/block_drag_handle.ts@@ -0,0 +1,230 @@+import {+ BlockButtonView, ClipboardObserver, DomEmitterMixin, DragDrop, env, IconDragIndicator, Plugin,+ Rect+} from "ckeditor5";++/**+ * The drag handle of `BlockToolbar` without the toolbar, for the fixed-toolbar editor: a grip+ * beside the block at the selection that drags the selected blocks to another place in the note.+ * The drag follows `DragDropBlockToolbar`, which only works with `BlockToolbar` itself.+ */+export default class BlockDragHandle extends Plugin {++ buttonView?: BlockButtonView;+ private isDragging = false;+ private isUpdateScheduled = false;+ private readonly domEmitter = new (DomEmitterMixin())();++ static get pluginName() {+ return "BlockDragHandle" as const;+ }++ static get requires() {+ return [ DragDrop ] as const;+ }++ init() {+ // `DragDrop` is disabled on Android.+ if (env.isAndroid) {+ return;+ }++ const editor = this.editor;+ const buttonView = new BlockButtonView(editor.locale);+ buttonView.set({+ label: editor.t("Drag to move"),+ icon: IconDragIndicator,+ tooltip: true,+ isToggleable: false+ });+ buttonView.on("execute", () => editor.editing.view.focus());+ editor.ui.view.body.add(buttonView);+ this.buttonView = buttonView;++ const element = buttonView.element;+ if (!element) {+ return;+ }+ element.setAttribute("draggable", "true");++ this.listenTo(editor.ui, "update", () => this.update());+ this.listenTo(editor, "change:isReadOnly", () => this.update(), { priority: "low" });+ this.listenTo(editor.ui.focusTracker, "change:isFocused", () => this.update());++ this.domEmitter.listenTo(window, "resize", () => this.scheduleUpdate());+ this.domEmitter.listenTo(document, "scroll", () => this.scheduleUpdate(), {+ useCapture: true,+ usePassive: true+ });++ this.domEmitter.listenTo(element, "dragstart", (_evt, domEvent: DragEvent) => {+ this.startDrag(domEvent);+ });+ this.domEmitter.listenTo(document, "dragover", (_evt, domEvent: DragEvent) => {+ this.forwardDrag(domEvent);+ });+ this.domEmitter.listenTo(document, "drop", (_evt, domEvent: DragEvent) => {+ this.forwardDrag(domEvent);+ });+ this.domEmitter.listenTo(document, "dragend", () => {+ this.isDragging = false;+ this.update();+ }, { useCapture: true });+ }++ override destroy() {+ this.domEmitter.stopListening();+ this.buttonView?.destroy();+ super.destroy();+ }++ private scheduleUpdate() {+ if (this.isUpdateScheduled) {+ return;+ }++ this.isUpdateScheduled = true;+ requestAnimationFrame(() => {+ this.isUpdateScheduled = false;+ this.update();+ });+ }++ /** Shows the handle beside the first selected block, or hides it. */+ private update() {+ const buttonView = this.buttonView;+ if (!buttonView?.element || this.isDragging) {+ return;+ }++ const target = this.getTarget();+ if (!target) {+ buttonView.isVisible = false;+ return;+ }++ // The button must be visible before it can be measured.+ buttonView.isVisible = true;+ const buttonRect = this.placeButton(buttonView, buttonView.element, target);++ // Hide the handle when its block scrolls out of the visible part of the editable.+ const visibleRect = new Rect(target.domEditable).getVisible();+ const buttonCenter = buttonRect.top + buttonRect.height / 2;+ buttonView.isVisible = !!visibleRect+ && buttonCenter >= visibleRect.top+ && buttonCenter <= visibleRect.bottom;+ }++ private getTarget(): BlockTarget | null {+ const editor = this.editor;+ const selection = editor.model.document.selection;+ const isEditable = !editor.isReadOnly && editor.model.canEditAt(selection);+ if (!editor.ui.focusTracker.isFocused || !isEditable) {+ return null;+ }++ const block = Array.from(selection.getSelectedBlocks()).at(0);+ const viewBlock = block && editor.editing.mapper.toViewElement(block);+ const domBlock = viewBlock && editor.editing.view.domConverter.mapViewToDom(viewBlock);+ const rootName = selection.getFirstRange()?.root.rootName;+ const domEditable = rootName && editor.ui.getEditableElement(rootName);+ if (!(domBlock instanceof HTMLElement) || !domEditable) {+ return null;+ }++ return { domBlock, domEditable };+ }++ /**+ * Places the handle outside the editable, level with the first line of the block.+ * Same geometry as `BlockToolbar`. Returns the handle's rectangle in the viewport.+ */+ private placeButton(+ buttonView: BlockButtonView,+ buttonElement: HTMLElement,+ target: BlockTarget+ ) {+ const { domBlock, domEditable } = target;+ const styles = window.getComputedStyle(domBlock);+ const paddingTop = parseInt(styles.paddingTop, 10);+ const lineHeight = parseInt(styles.lineHeight, 10) || parseInt(styles.fontSize, 10) * 1.2;+ const editableRect = new Rect(domEditable);+ const buttonRect = new Rect(buttonElement);++ const left = this.editor.locale.uiLanguageDirection === "ltr"+ ? editableRect.left - buttonRect.width+ : editableRect.right;+ const top = new Rect(domBlock).top + paddingTop + (lineHeight - buttonRect.height) / 2;+ buttonRect.moveTo(left, top);++ const absoluteRect = buttonRect.toAbsoluteRect();+ buttonView.top = absoluteRect.top;+ buttonView.left = absoluteRect.left;++ return buttonRect;+ }++ /** Selects the whole selected blocks and starts a drag of them in the editing view. */+ private startDrag(domEvent: DragEvent) {+ const editor = this.editor;+ const model = editor.model;+ const blocks = Array.from(model.document.selection.getSelectedBlocks());+ const firstBlock = blocks.at(0);+ const lastBlock = blocks.at(-1);+ if (editor.isReadOnly || !firstBlock || !lastBlock) {+ domEvent.preventDefault();+ return;+ }++ const range = model.createRange(+ model.createPositionBefore(firstBlock),+ model.createPositionAfter(lastBlock)+ );+ model.change((writer) => writer.setSelection(range));++ this.isDragging = true;+ editor.editing.view.focus();+ editor.editing.view.getObserver(ClipboardObserver)?.onDomEvent(domEvent);+ }++ /**+ * Passes a `dragover` or `drop` to the editing view, 100px into the content from the pointer,+ * so the pointer can stay in the margin beside the blocks.+ */+ private forwardDrag(domEvent: DragEvent) {+ if (!this.isDragging) {+ return;+ }++ const isLtr = this.editor.locale.contentLanguageDirection === "ltr";+ const clientX = domEvent.clientX + (isLtr ? 100 : -100);+ const clientY = domEvent.clientY;+ const target = document.elementFromPoint(clientX, clientY);+ const domEditable = this.editor.ui.getEditableElement();+ if (!target || !domEditable?.contains(target)) {+ return;+ }++ const forwardedEvent = {+ type: domEvent.type,+ dataTransfer: domEvent.dataTransfer,+ target,+ clientX,+ clientY,+ preventDefault: () => domEvent.preventDefault(),+ stopPropagation: () => domEvent.stopPropagation()+ } as unknown as DragEvent;+ this.editor.editing.view.getObserver(ClipboardObserver)?.onDomEvent(forwardedEvent);+ }+}++interface BlockTarget {+ domBlock: HTMLElement;+ domEditable: HTMLElement;+}++declare module "ckeditor5" {+ interface PluginsMap {+ [BlockDragHandle.pluginName]: BlockDragHandle;+ }+}diff --git a/packages/ckeditor5/src/plugins/content_embed/content_embed.spec.ts b/packages/ckeditor5/src/plugins/content_embed/content_embed.spec.tsindex 5f9c3c9550..9bd1316404 100644--- a/packages/ckeditor5/src/plugins/content_embed/content_embed.spec.ts+++ b/packages/ckeditor5/src/plugins/content_embed/content_embed.spec.ts@@ -62,10 +62,17 @@ describe("ContentEmbed", () => {const schema = editor.model.schema;expect(schema.isRegistered("contentEmbed")).toBe(true);expect(schema.isObject("contentEmbed")).toBe(true);+ expect(schema.isBlock("contentEmbed")).toBe(true);expect(schema.checkAttribute(["$root", "contentEmbed"], "noteId")).toBe(true);expect(schema.checkAttribute(["$root", "contentEmbed"], "boxSize")).toBe(true);});+ it("is one of the selected blocks when selected", () => {+ setModelData(editor.model, "[<contentEmbed noteId=\"n1\"></contentEmbed>]");+ const blocks = Array.from(editor.model.document.selection.getSelectedBlocks());+ expect(blocks.map((block) => block.name)).toStrictEqual([ "contentEmbed" ]);+ });+// -----------------------------------------------------------------------// UI button// -----------------------------------------------------------------------diff --git a/packages/ckeditor5/src/plugins/content_embed/content_embed.ts b/packages/ckeditor5/src/plugins/content_embed/content_embed.tsindex 186273410e..558110c0af 100644--- a/packages/ckeditor5/src/plugins/content_embed/content_embed.ts+++ b/packages/ckeditor5/src/plugins/content_embed/content_embed.ts@@ -396,6 +396,7 @@ class ContentEmbedEditing extends Plugin {schema.register( 'contentEmbed', {// Behaves like a self-contained object (e.g. an image).isObject: true,+ isBlock: true,// An embed shows either a note or an attachment. An embed that// `FileUploadEditing` is uploading carries the upload attributes instead of its id.diff --git a/packages/ckeditor5/src/plugins/link_embed/link_embed_editing.spec.ts b/packages/ckeditor5/src/plugins/link_embed/link_embed_editing.spec.tsindex 9bc5edbb4e..1df1d641ad 100644--- a/packages/ckeditor5/src/plugins/link_embed/link_embed_editing.spec.ts+++ b/packages/ckeditor5/src/plugins/link_embed/link_embed_editing.spec.ts@@ -21,11 +21,18 @@ describe("LinkEmbedEditing", () => {const schema = editor.model.schema;expect(schema.isRegistered("linkEmbed")).toBe(true);expect(schema.isObject("linkEmbed")).toBe(true);+ expect(schema.isBlock("linkEmbed")).toBe(true);expect(schema.isRegistered("linkMention")).toBe(true);expect(schema.isInline("linkMention")).toBe(true);expect(schema.isObject("linkMention")).toBe(true);});+ it("makes a selected linkEmbed one of the selected blocks", () => {+ setModelData(editor.model, '[<linkEmbed url="https://e.co/" embedType="web"></linkEmbed>]');+ const blocks = Array.from(editor.model.document.selection.getSelectedBlocks());+ expect(blocks.map((block) => block.name)).toStrictEqual([ "linkEmbed" ]);+ });+it("upcasts a <section.link-embed> with all data attributes into a linkEmbed", () => {editor.setData('<section class="link-embed" data-url="https://e.com/" data-embed-type="web"' +diff --git a/packages/ckeditor5/src/plugins/link_embed/link_embed_editing.ts b/packages/ckeditor5/src/plugins/link_embed/link_embed_editing.tsindex 5f8bd39147..2ba86b656f 100644--- a/packages/ckeditor5/src/plugins/link_embed/link_embed_editing.ts+++ b/packages/ckeditor5/src/plugins/link_embed/link_embed_editing.ts@@ -45,6 +45,7 @@ export default class LinkEmbedEditing extends Plugin {schema.register('linkEmbed', {isObject: true,+ isBlock: true,allowAttributes: ['url', 'embedType', 'title', 'description', 'favicon', 'siteName', 'image'],allowWhere: '$block'});diff --git a/packages/ckeditor5/src/plugins/mermaid/mermaid_editing.spec.ts b/packages/ckeditor5/src/plugins/mermaid/mermaid_editing.spec.tsindex e552c0e52a..03b28f9810 100644--- a/packages/ckeditor5/src/plugins/mermaid/mermaid_editing.spec.ts+++ b/packages/ckeditor5/src/plugins/mermaid/mermaid_editing.spec.ts@@ -35,6 +35,14 @@ describe( 'MermaidEditing', () => {return editor.destroy();} );+ it( 'makes a selected mermaid one of the selected blocks', () => {+ expect( model.schema.isBlock( 'mermaid' ) ).to.equal( true );++ setModelData( model, '[<mermaid displayMode="split" source="flowchart TB"></mermaid>]' );+ const blocks = Array.from( model.document.selection.getSelectedBlocks() );+ expect( blocks.map( block => block.name ) ).to.deep.equal( [ 'mermaid' ] );+ } );+describe( 'conversion', () => {describe( 'upcast', () => {it( 'works correctly', () => {diff --git a/packages/ckeditor5/src/plugins/mermaid/mermaid_editing.ts b/packages/ckeditor5/src/plugins/mermaid/mermaid_editing.tsindex 047e02f71b..f8b06720f9 100644--- a/packages/ckeditor5/src/plugins/mermaid/mermaid_editing.ts+++ b/packages/ckeditor5/src/plugins/mermaid/mermaid_editing.ts@@ -73,7 +73,8 @@ export default class MermaidEditing extends Plugin {this.editor.model.schema.register( 'mermaid', {allowAttributes: [ 'displayMode', 'source' ],allowWhere: '$block',- isObject: true+ isObject: true,+ isBlock: true} );}