chore(ckeditor5): fix references: Element -> ModelElement

This commit is contained in:
Elian Doran 2025-07-12 19:40:24 +03:00
parent 6aa3b8dbd7
commit 4ae3272cdf
No known key found for this signature in database
5 changed files with 19 additions and 19 deletions

View File

@ -5,7 +5,7 @@ import { BalloonEditor, DecoupledEditor, FindAndReplaceEditing, FindCommand } fr
import "./translation_overrides.js"; import "./translation_overrides.js";
export { EditorWatchdog } from "ckeditor5"; export { EditorWatchdog } from "ckeditor5";
export { PREMIUM_PLUGINS } from "./plugins.js"; export { PREMIUM_PLUGINS } from "./plugins.js";
export type { EditorConfig, MentionFeed, MentionFeedObjectItem, Node, Position, Element, WatchdogConfig } from "ckeditor5"; export type { EditorConfig, MentionFeed, MentionFeedObjectItem, Node, Position, ModelElement, WatchdogConfig } from "ckeditor5";
export type { TemplateDefinition } from "ckeditor5-premium-features"; export type { TemplateDefinition } from "ckeditor5-premium-features";
export { default as buildExtraCommands } from "./extra_slash_commands.js"; export { default as buildExtraCommands } from "./extra_slash_commands.js";

View File

@ -2,7 +2,7 @@
* https://github.com/zadam/trilium/issues/978 * https://github.com/zadam/trilium/issues/978
*/ */
import { DocumentFragment, Element, Plugin, Position } from "ckeditor5"; import { DocumentFragment, ModelElement, Plugin, Position } from "ckeditor5";
export default class IndentBlockShortcutPlugin extends Plugin { export default class IndentBlockShortcutPlugin extends Plugin {
@ -28,7 +28,7 @@ export default class IndentBlockShortcutPlugin extends Plugin {
// in table TAB should switch cells // in table TAB should switch cells
isInTable() { isInTable() {
let el: Position | Element | DocumentFragment | null = this.editor.model.document.selection.getFirstPosition(); let el: Position | ModelElement | DocumentFragment | null = this.editor.model.document.selection.getFirstPosition();
while (el) { while (el) {
if ("name" in el && el.name === 'tableCell') { if ("name" in el && el.name === 'tableCell') {

View File

@ -2,7 +2,7 @@
* https://github.com/TriliumNext/Trilium/issues/1002 * https://github.com/TriliumNext/Trilium/issues/1002
*/ */
import { Command, DocumentSelection, Element, Node, Plugin, Range } from 'ckeditor5'; import { Command, DocumentSelection, ModelElement, Node, Plugin, Range } from 'ckeditor5';
export default class MoveBlockUpDownPlugin extends Plugin { export default class MoveBlockUpDownPlugin extends Plugin {
init() { init() {
@ -46,7 +46,7 @@ export default class MoveBlockUpDownPlugin extends Plugin {
abstract class MoveBlockUpDownCommand extends Command { abstract class MoveBlockUpDownCommand extends Command {
abstract getSibling(selectedBlock: Element): Node | null; abstract getSibling(selectedBlock: ModelElement): Node | null;
abstract get offset(): "before" | "after"; abstract get offset(): "before" | "after";
override execute() { override execute() {
@ -107,7 +107,7 @@ abstract class MoveBlockUpDownCommand extends Command {
getSelectedBlocks(selection: DocumentSelection) { getSelectedBlocks(selection: DocumentSelection) {
const blocks = [...selection.getSelectedBlocks()]; const blocks = [...selection.getSelectedBlocks()];
const resolved: Element[] = []; const resolved: ModelElement[] = [];
// Selects elements (such as Mermaid) when there are no blocks // Selects elements (such as Mermaid) when there are no blocks
if (!blocks.length) { if (!blocks.length) {
@ -118,10 +118,10 @@ abstract class MoveBlockUpDownCommand extends Command {
} }
for (const block of blocks) { for (const block of blocks) {
let el: Element = block; let el: ModelElement = block;
// Traverse up until the parent is the root ($root) or there is no parent // Traverse up until the parent is the root ($root) or there is no parent
while (el.parent && el.parent.name !== '$root') { while (el.parent && el.parent.name !== '$root') {
el = el.parent as Element; el = el.parent as ModelElement;
} }
resolved.push(el); resolved.push(el);
} }
@ -140,7 +140,7 @@ abstract class MoveBlockUpDownCommand extends Command {
class MoveBlockUpCommand extends MoveBlockUpDownCommand { class MoveBlockUpCommand extends MoveBlockUpDownCommand {
getSibling(selectedBlock: Element) { getSibling(selectedBlock: ModelElement) {
return selectedBlock.previousSibling; return selectedBlock.previousSibling;
} }
@ -153,7 +153,7 @@ class MoveBlockUpCommand extends MoveBlockUpDownCommand {
class MoveBlockDownCommand extends MoveBlockUpDownCommand { class MoveBlockDownCommand extends MoveBlockUpDownCommand {
/** @override */ /** @override */
getSibling(selectedBlock: Element) { getSibling(selectedBlock: ModelElement) {
return selectedBlock.nextSibling; return selectedBlock.nextSibling;
} }

View File

@ -1,4 +1,4 @@
import { Command, Element, LinkEditing, Plugin, toWidget, viewToModelPositionOutsideModelElement, Widget } from "ckeditor5"; import { Command, ModelElement, LinkEditing, Plugin, toWidget, viewToModelPositionOutsideModelElement, Widget } from "ckeditor5";
export default class ReferenceLink extends Plugin { export default class ReferenceLink extends Plugin {
static get requires() { static get requires() {
@ -32,7 +32,7 @@ class ReferenceLinkCommand extends Command {
override refresh() { override refresh() {
const model = this.editor.model; const model = this.editor.model;
const selection = model.document.selection; const selection = model.document.selection;
this.isEnabled = selection.focus !== null && model.schema.checkChild(selection.focus.parent as Element, 'reference'); this.isEnabled = selection.focus !== null && model.schema.checkChild(selection.focus.parent as ModelElement, 'reference');
} }
} }

View File

@ -1,4 +1,4 @@
import type { Element, Position, Writer } from "ckeditor5"; import type { ModelElement, Position, Writer } from "ckeditor5";
import type { Node, Editor } from "ckeditor5"; import type { Node, Editor } from "ckeditor5";
import { Plugin } from "ckeditor5"; import { Plugin } from "ckeditor5";
@ -77,9 +77,9 @@ export default class SyntaxHighlighting extends Plugin {
// See // See
// https://github.com/ckeditor/ckeditor5/blob/b53d2a4b49679b072f4ae781ac094e7e831cfb14/packages/ckeditor5-block-quote/src/blockquoteediting.js#L54 // https://github.com/ckeditor/ckeditor5/blob/b53d2a4b49679b072f4ae781ac094e7e831cfb14/packages/ckeditor5-block-quote/src/blockquoteediting.js#L54
const changes = document.differ.getChanges(); const changes = document.differ.getChanges();
let dirtyCodeBlocks = new Set<Element>(); let dirtyCodeBlocks = new Set<ModelElement>();
function lookForCodeBlocks(node: Element | Node) { function lookForCodeBlocks(node: ModelElement | Node) {
if (!("getChildren" in node)) { if (!("getChildren" in node)) {
return; return;
} }
@ -91,7 +91,7 @@ export default class SyntaxHighlighting extends Plugin {
if (child.is("element", "codeBlock")) { if (child.is("element", "codeBlock")) {
dirtyCodeBlocks.add(child); dirtyCodeBlocks.add(child);
} else if ((child as Element).childCount > 0) { } else if ((child as ModelElement).childCount > 0) {
lookForCodeBlocks(child); lookForCodeBlocks(child);
} }
} }
@ -100,7 +100,7 @@ export default class SyntaxHighlighting extends Plugin {
for (const change of changes) { for (const change of changes) {
dbg("change " + JSON.stringify(change)); dbg("change " + JSON.stringify(change));
if ("name" in change && change.name !== "paragraph" && change.name !== "codeBlock" && change?.position?.nodeAfter && (change.position.nodeAfter as Element).childCount > 0) { if ("name" in change && change.name !== "paragraph" && change.name !== "codeBlock" && change?.position?.nodeAfter && (change.position.nodeAfter as ModelElement).childCount > 0) {
/* /*
* We need to look for code blocks recursively, as they can be placed within a <div> due to * We need to look for code blocks recursively, as they can be placed within a <div> due to
* general HTML support or normally underneath other elements such as tables, blockquotes, etc. * general HTML support or normally underneath other elements such as tables, blockquotes, etc.
@ -115,7 +115,7 @@ export default class SyntaxHighlighting extends Plugin {
// etc (the postfixer won't get later changes for those). // etc (the postfixer won't get later changes for those).
if (codeBlock) { if (codeBlock) {
log("dirtying inserted codeBlock " + JSON.stringify(codeBlock.toJSON())); log("dirtying inserted codeBlock " + JSON.stringify(codeBlock.toJSON()));
dirtyCodeBlocks.add(codeBlock as Element); dirtyCodeBlocks.add(codeBlock as ModelElement);
} }
} else if (change.type == "remove" && change.name == "codeBlock" && change.position) { } else if (change.type == "remove" && change.name == "codeBlock" && change.position) {
// An existing codeblock was removed, do nothing. Note the // An existing codeblock was removed, do nothing. Note the
@ -149,7 +149,7 @@ export default class SyntaxHighlighting extends Plugin {
* the formatting would be stored with the note and it would need a * the formatting would be stored with the note and it would need a
* way to remove that formatting when editing back the note. * way to remove that formatting when editing back the note.
*/ */
highlightCodeBlock(codeBlock: Element, writer: Writer) { highlightCodeBlock(codeBlock: ModelElement, writer: Writer) {
log("highlighting codeblock " + JSON.stringify(codeBlock.toJSON())); log("highlighting codeblock " + JSON.stringify(codeBlock.toJSON()));
const model = codeBlock.root.document?.model; const model = codeBlock.root.document?.model;
if (!model) { if (!model) {