mirror of
https://github.com/zadam/trilium.git
synced 2025-11-04 20:36:13 +01:00
chore(ckeditor5): fix references: Element -> ModelElement
This commit is contained in:
@@ -5,7 +5,7 @@ import { BalloonEditor, DecoupledEditor, FindAndReplaceEditing, FindCommand } fr
|
||||
import "./translation_overrides.js";
|
||||
export { EditorWatchdog } from "ckeditor5";
|
||||
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 { default as buildExtraCommands } from "./extra_slash_commands.js";
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* 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 {
|
||||
|
||||
@@ -28,7 +28,7 @@ export default class IndentBlockShortcutPlugin extends Plugin {
|
||||
|
||||
// in table TAB should switch cells
|
||||
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) {
|
||||
if ("name" in el && el.name === 'tableCell') {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* 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 {
|
||||
|
||||
init() {
|
||||
@@ -46,7 +46,7 @@ export default class MoveBlockUpDownPlugin extends Plugin {
|
||||
|
||||
abstract class MoveBlockUpDownCommand extends Command {
|
||||
|
||||
abstract getSibling(selectedBlock: Element): Node | null;
|
||||
abstract getSibling(selectedBlock: ModelElement): Node | null;
|
||||
abstract get offset(): "before" | "after";
|
||||
|
||||
override execute() {
|
||||
@@ -107,7 +107,7 @@ abstract class MoveBlockUpDownCommand extends Command {
|
||||
|
||||
getSelectedBlocks(selection: DocumentSelection) {
|
||||
const blocks = [...selection.getSelectedBlocks()];
|
||||
const resolved: Element[] = [];
|
||||
const resolved: ModelElement[] = [];
|
||||
|
||||
// Selects elements (such as Mermaid) when there are no blocks
|
||||
if (!blocks.length) {
|
||||
@@ -118,10 +118,10 @@ abstract class MoveBlockUpDownCommand extends Command {
|
||||
}
|
||||
|
||||
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
|
||||
while (el.parent && el.parent.name !== '$root') {
|
||||
el = el.parent as Element;
|
||||
el = el.parent as ModelElement;
|
||||
}
|
||||
resolved.push(el);
|
||||
}
|
||||
@@ -140,7 +140,7 @@ abstract class MoveBlockUpDownCommand extends Command {
|
||||
|
||||
class MoveBlockUpCommand extends MoveBlockUpDownCommand {
|
||||
|
||||
getSibling(selectedBlock: Element) {
|
||||
getSibling(selectedBlock: ModelElement) {
|
||||
return selectedBlock.previousSibling;
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ class MoveBlockUpCommand extends MoveBlockUpDownCommand {
|
||||
class MoveBlockDownCommand extends MoveBlockUpDownCommand {
|
||||
|
||||
/** @override */
|
||||
getSibling(selectedBlock: Element) {
|
||||
getSibling(selectedBlock: ModelElement) {
|
||||
return selectedBlock.nextSibling;
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
static get requires() {
|
||||
@@ -32,7 +32,7 @@ class ReferenceLinkCommand extends Command {
|
||||
override refresh() {
|
||||
const model = this.editor.model;
|
||||
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');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 { Plugin } from "ckeditor5";
|
||||
|
||||
@@ -77,9 +77,9 @@ export default class SyntaxHighlighting extends Plugin {
|
||||
// See
|
||||
// https://github.com/ckeditor/ckeditor5/blob/b53d2a4b49679b072f4ae781ac094e7e831cfb14/packages/ckeditor5-block-quote/src/blockquoteediting.js#L54
|
||||
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)) {
|
||||
return;
|
||||
}
|
||||
@@ -91,7 +91,7 @@ export default class SyntaxHighlighting extends Plugin {
|
||||
|
||||
if (child.is("element", "codeBlock")) {
|
||||
dirtyCodeBlocks.add(child);
|
||||
} else if ((child as Element).childCount > 0) {
|
||||
} else if ((child as ModelElement).childCount > 0) {
|
||||
lookForCodeBlocks(child);
|
||||
}
|
||||
}
|
||||
@@ -100,7 +100,7 @@ export default class SyntaxHighlighting extends Plugin {
|
||||
for (const change of changes) {
|
||||
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
|
||||
* 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).
|
||||
if (codeBlock) {
|
||||
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) {
|
||||
// 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
|
||||
* 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()));
|
||||
const model = codeBlock.root.document?.model;
|
||||
if (!model) {
|
||||
|
||||
Reference in New Issue
Block a user