fix(deps): update ckeditor monorepo (major) (#6283)

This commit is contained in:
Elian Doran
2025-07-12 22:03:15 +03:00
committed by GitHub
33 changed files with 2276 additions and 1794 deletions

View File

@@ -58,7 +58,7 @@
"vanilla-js-wheel-zoom": "9.0.4" "vanilla-js-wheel-zoom": "9.0.4"
}, },
"devDependencies": { "devDependencies": {
"@ckeditor/ckeditor5-inspector": "4.1.0", "@ckeditor/ckeditor5-inspector": "5.0.0",
"@types/bootstrap": "5.2.10", "@types/bootstrap": "5.2.10",
"@types/jquery": "3.5.32", "@types/jquery": "3.5.32",
"@types/leaflet": "1.9.20", "@types/leaflet": "1.9.20",

View File

@@ -81,8 +81,8 @@ body {
/* -- Overrides the default colors used by the ckeditor5-image package. --------------------- */ /* -- Overrides the default colors used by the ckeditor5-image package. --------------------- */
--ck-color-image-caption-background: var(--main-background-color); --ck-content-color-image-caption-background: var(--main-background-color);
--ck-color-image-caption-text: var(--main-text-color); --ck-content-color-image-caption-text: var(--main-text-color);
/* -- Overrides the default colors used by the ckeditor5-widget package. -------------------- */ /* -- Overrides the default colors used by the ckeditor5-widget package. -------------------- */

View File

@@ -4,7 +4,7 @@ import noteAutocompleteService, { type Suggestion } from "../../services/note_au
import server from "../../services/server.js"; import server from "../../services/server.js";
import contextMenuService from "../../menus/context_menu.js"; import contextMenuService from "../../menus/context_menu.js";
import attributeParser, { type Attribute } from "../../services/attribute_parser.js"; import attributeParser, { type Attribute } from "../../services/attribute_parser.js";
import { AttributeEditor, type EditorConfig, type Element, type MentionFeed, type Node, type Position } from "@triliumnext/ckeditor5"; import { AttributeEditor, type EditorConfig, type ModelElement, type MentionFeed, type ModelNode, type ModelPosition } from "@triliumnext/ckeditor5";
import froca from "../../services/froca.js"; import froca from "../../services/froca.js";
import attributeRenderer from "../../services/attribute_renderer.js"; import attributeRenderer from "../../services/attribute_renderer.js";
import noteCreateService from "../../services/note_create.js"; import noteCreateService from "../../services/note_create.js";
@@ -417,15 +417,15 @@ export default class AttributeEditorWidget extends NoteContextAwareWidget implem
this.$editor.tooltip("show"); this.$editor.tooltip("show");
} }
getClickIndex(pos: Position) { getClickIndex(pos: ModelPosition) {
let clickIndex = pos.offset - (pos.textNode?.startOffset ?? 0); let clickIndex = pos.offset - (pos.textNode?.startOffset ?? 0);
let curNode: Node | Text | Element | null = pos.textNode; let curNode: ModelNode | Text | ModelElement | null = pos.textNode;
while (curNode?.previousSibling) { while (curNode?.previousSibling) {
curNode = curNode.previousSibling; curNode = curNode.previousSibling;
if ((curNode as Element).name === "reference") { if ((curNode as ModelElement).name === "reference") {
clickIndex += (curNode.getAttribute("notePath") as string).length + 1; clickIndex += (curNode.getAttribute("notePath") as string).length + 1;
} else if ("data" in curNode) { } else if ("data" in curNode) {
clickIndex += (curNode.data as string).length; clickIndex += (curNode.data as string).length;

View File

@@ -39,7 +39,7 @@
"@typescript-eslint/parser": "^8.0.0", "@typescript-eslint/parser": "^8.0.0",
"@vitest/browser": "^3.0.5", "@vitest/browser": "^3.0.5",
"@vitest/coverage-istanbul": "^3.0.5", "@vitest/coverage-istanbul": "^3.0.5",
"ckeditor5": "45.2.1", "ckeditor5": "46.0.0",
"eslint": "^9.0.0", "eslint": "^9.0.0",
"eslint-config-ckeditor5": ">=9.1.0", "eslint-config-ckeditor5": ">=9.1.0",
"http-server": "^14.1.0", "http-server": "^14.1.0",
@@ -53,7 +53,7 @@
"webdriverio": "^9.0.7" "webdriverio": "^9.0.7"
}, },
"peerDependencies": { "peerDependencies": {
"ckeditor5": "45.2.1" "ckeditor5": "46.0.0"
}, },
"author": "Elian Doran <contact@eliandoran.me>", "author": "Elian Doran <contact@eliandoran.me>",
"license": "GPL-2.0-or-later", "license": "GPL-2.0-or-later",

View File

@@ -8,7 +8,7 @@
*/ */
import { Command, first } from 'ckeditor5'; import { Command, first } from 'ckeditor5';
import type { DocumentFragment, Element, Position, Range, Schema, Writer } from 'ckeditor5'; import type { ModelElement, ModelPosition, ModelRange, ModelSchema, ModelWriter, ModelDocumentFragment } from 'ckeditor5';
/** /**
* The block quote command plugin. * The block quote command plugin.
@@ -154,18 +154,18 @@ export default class AdmonitionCommand extends Command {
* start it or end it, then the quote will be split (if needed) and the blocks * start it or end it, then the quote will be split (if needed) and the blocks
* will be moved out of it, so other quoted blocks remained quoted. * will be moved out of it, so other quoted blocks remained quoted.
*/ */
private _removeQuote( writer: Writer, blocks: Array<Element> ): void { private _removeQuote( writer: ModelWriter, blocks: Array<ModelElement> ): void {
// Unquote all groups of block. Iterate in the reverse order to not break following ranges. // Unquote all groups of block. Iterate in the reverse order to not break following ranges.
getRangesOfBlockGroups( writer, blocks ).reverse().forEach( groupRange => { getRangesOfBlockGroups( writer, blocks ).reverse().forEach( groupRange => {
if ( groupRange.start.isAtStart && groupRange.end.isAtEnd ) { if ( groupRange.start.isAtStart && groupRange.end.isAtEnd ) {
writer.unwrap( groupRange.start.parent as Element ); writer.unwrap( groupRange.start.parent as ModelElement );
return; return;
} }
// The group of blocks are at the beginning of an <bQ> so let's move them left (out of the <bQ>). // The group of blocks are at the beginning of an <bQ> so let's move them left (out of the <bQ>).
if ( groupRange.start.isAtStart ) { if ( groupRange.start.isAtStart ) {
const positionBefore = writer.createPositionBefore( groupRange.start.parent as Element ); const positionBefore = writer.createPositionBefore( groupRange.start.parent as ModelElement );
writer.move( groupRange, positionBefore ); writer.move( groupRange, positionBefore );
@@ -180,7 +180,7 @@ export default class AdmonitionCommand extends Command {
// Now we are sure that groupRange.end.isAtEnd is true, so let's move the blocks right. // Now we are sure that groupRange.end.isAtEnd is true, so let's move the blocks right.
const positionAfter = writer.createPositionAfter( groupRange.end.parent as Element ); const positionAfter = writer.createPositionAfter( groupRange.end.parent as ModelElement );
writer.move( groupRange, positionAfter ); writer.move( groupRange, positionAfter );
} ); } );
@@ -189,9 +189,9 @@ export default class AdmonitionCommand extends Command {
/** /**
* Applies the quote to given blocks. * Applies the quote to given blocks.
*/ */
private _applyQuote( writer: Writer, blocks: Array<Element>, type?: AdmonitionType): void { private _applyQuote( writer: ModelWriter, blocks: Array<ModelElement>, type?: AdmonitionType): void {
this._lastType = type; this._lastType = type;
const quotesToMerge: Array<Element | DocumentFragment> = []; const quotesToMerge: Array<ModelElement | ModelDocumentFragment> = [];
// Quote all groups of block. Iterate in the reverse order to not break following ranges. // Quote all groups of block. Iterate in the reverse order to not break following ranges.
getRangesOfBlockGroups( writer, blocks ).reverse().forEach( groupRange => { getRangesOfBlockGroups( writer, blocks ).reverse().forEach( groupRange => {
@@ -205,7 +205,7 @@ export default class AdmonitionCommand extends Command {
writer.wrap( groupRange, quote ); writer.wrap( groupRange, quote );
} else if (quote.is("element")) { } else if (quote.is("element")) {
this.editor.model.change((writer) => { this.editor.model.change((writer) => {
writer.setAttribute(ADMONITION_TYPE_ATTRIBUTE, type, quote as Element); writer.setAttribute(ADMONITION_TYPE_ATTRIBUTE, type, quote as ModelElement);
}); });
} }
@@ -228,7 +228,7 @@ export default class AdmonitionCommand extends Command {
} }
} }
function findQuote( elementOrPosition: Element | Position ): Element | DocumentFragment | null { function findQuote( elementOrPosition: ModelElement | ModelPosition ): ModelElement | ModelDocumentFragment | null {
return elementOrPosition.parent!.name == 'aside' ? elementOrPosition.parent : null; return elementOrPosition.parent!.name == 'aside' ? elementOrPosition.parent : null;
} }
@@ -239,7 +239,7 @@ function findQuote( elementOrPosition: Element | Position ): Element | DocumentF
* blocks: [ a, b, d, f, g, h ] * blocks: [ a, b, d, f, g, h ]
* output ranges: [ab]c[d]e[fgh] * output ranges: [ab]c[d]e[fgh]
*/ */
function getRangesOfBlockGroups( writer: Writer, blocks: Array<Element> ): Array<Range> { function getRangesOfBlockGroups( writer: ModelWriter, blocks: Array<ModelElement> ): Array<ModelRange> {
let startPosition; let startPosition;
let i = 0; let i = 0;
const ranges = []; const ranges = [];
@@ -266,9 +266,9 @@ function getRangesOfBlockGroups( writer: Writer, blocks: Array<Element> ): Array
/** /**
* Checks whether <bQ> can wrap the block. * Checks whether <bQ> can wrap the block.
*/ */
function checkCanBeQuoted( schema: Schema, block: Element ): boolean { function checkCanBeQuoted( schema: ModelSchema, block: ModelElement ): boolean {
// TMP will be replaced with schema.checkWrap(). // TMP will be replaced with schema.checkWrap().
const isBQAllowed = schema.checkChild( block.parent as Element, 'aside' ); const isBQAllowed = schema.checkChild( block.parent as ModelElement, 'aside' );
const isBlockAllowedInBQ = schema.checkChild( [ '$root', 'aside' ], block ); const isBlockAllowedInBQ = schema.checkChild( [ '$root', 'aside' ], block );
return isBQAllowed && isBlockAllowedInBQ; return isBQAllowed && isBlockAllowedInBQ;

View File

@@ -40,7 +40,7 @@
"@typescript-eslint/parser": "^8.0.0", "@typescript-eslint/parser": "^8.0.0",
"@vitest/browser": "^3.0.5", "@vitest/browser": "^3.0.5",
"@vitest/coverage-istanbul": "^3.0.5", "@vitest/coverage-istanbul": "^3.0.5",
"ckeditor5": "45.2.1", "ckeditor5": "46.0.0",
"eslint": "^9.0.0", "eslint": "^9.0.0",
"eslint-config-ckeditor5": ">=9.1.0", "eslint-config-ckeditor5": ">=9.1.0",
"http-server": "^14.1.0", "http-server": "^14.1.0",
@@ -54,7 +54,7 @@
"webdriverio": "^9.0.7" "webdriverio": "^9.0.7"
}, },
"peerDependencies": { "peerDependencies": {
"ckeditor5": "45.2.1" "ckeditor5": "46.0.0"
}, },
"scripts": { "scripts": {
"build": "node ./scripts/build-dist.mjs", "build": "node ./scripts/build-dist.mjs",

View File

@@ -1,4 +1,4 @@
import { type Editor, Text, TextProxy, type Element, type Range, type Autoformat, inlineAutoformatEditing } from 'ckeditor5'; import { type Editor, ModelText, ModelTextProxy, type ModelElement, type ModelRange, type Autoformat, inlineAutoformatEditing } from 'ckeditor5';
import { COMMANDS, ELEMENTS } from '../constants.js'; import { COMMANDS, ELEMENTS } from '../constants.js';
import { modelQueryElement, modelQueryElementsAll } from '../utils.js'; import { modelQueryElement, modelQueryElementsAll } from '../utils.js';
@@ -68,13 +68,13 @@ const regexMatchCallback = (
* Footnotes only get inserted if the matching range is an integer between 1 * Footnotes only get inserted if the matching range is an integer between 1
* and the number of existing footnotes + 1. * and the number of existing footnotes + 1.
*/ */
const formatCallback = ( ranges: Array<Range>, editor: Editor, rootElement: Element ): boolean | undefined => { const formatCallback = ( ranges: Array<ModelRange>, editor: Editor, rootElement: ModelElement ): boolean | undefined => {
const command = editor.commands.get( COMMANDS.insertFootnote ); const command = editor.commands.get( COMMANDS.insertFootnote );
if ( !command || !command.isEnabled ) { if ( !command || !command.isEnabled ) {
return; return;
} }
const text = [ ...ranges[ 0 ].getItems() ][ 0 ]; const text = [ ...ranges[ 0 ].getItems() ][ 0 ];
if ( !( text instanceof TextProxy || text instanceof Text ) ) { if ( !( text instanceof ModelTextProxy || text instanceof ModelText ) ) {
return false; return false;
} }
const match = text.data.match( /[0-9]+/ ); const match = text.data.match( /[0-9]+/ );
@@ -108,14 +108,14 @@ const formatCallback = ( ranges: Array<Range>, editor: Editor, rootElement: Elem
/** /**
* Adds functionality to support creating footnotes using markdown syntax, e.g. `[^1]`. * Adds functionality to support creating footnotes using markdown syntax, e.g. `[^1]`.
*/ */
export const addFootnoteAutoformatting = ( editor: Editor, rootElement: Element ): void => { export const addFootnoteAutoformatting = ( editor: Editor, rootElement: ModelElement ): void => {
if ( editor.plugins.has( 'Autoformat' ) ) { if ( editor.plugins.has( 'Autoformat' ) ) {
const autoformatPluginInstance = editor.plugins.get( 'Autoformat' ) as Autoformat; const autoformatPluginInstance = editor.plugins.get( 'Autoformat' ) as Autoformat;
inlineAutoformatEditing( inlineAutoformatEditing(
editor, editor,
autoformatPluginInstance, autoformatPluginInstance,
text => regexMatchCallback( editor, text ), text => regexMatchCallback( editor, text ),
( _, ranges: Array<Range> ) => formatCallback( ranges, editor, rootElement ) ( _, ranges: Array<ModelRange> ) => formatCallback( ranges, editor, rootElement )
); );
} }
}; };

View File

@@ -1,4 +1,4 @@
import { type Editor, type DowncastConversionApi, type ViewContainerElement, Element, toWidget, toWidgetEditable } from 'ckeditor5'; import { type Editor, type DowncastConversionApi, type ViewContainerElement, ModelElement, toWidget, toWidgetEditable } from 'ckeditor5';
import { ATTRIBUTES, CLASSES, ELEMENTS } from '../constants.js'; import { ATTRIBUTES, CLASSES, ELEMENTS } from '../constants.js';
import { viewQueryElement } from '../utils.js'; import { viewQueryElement } from '../utils.js';
@@ -232,7 +232,7 @@ export const defineConverters = ( editor: Editor ): void => {
* for both data and editing downcasts. * for both data and editing downcasts.
*/ */
function createFootnoteBackLinkViewElement( function createFootnoteBackLinkViewElement(
modelElement: Element, modelElement: ModelElement,
conversionApi: DowncastConversionApi conversionApi: DowncastConversionApi
): ViewContainerElement { ): ViewContainerElement {
const viewWriter = conversionApi.writer; const viewWriter = conversionApi.writer;
@@ -264,7 +264,7 @@ function createFootnoteBackLinkViewElement(
* data downcast and editing downcast conversions. * data downcast and editing downcast conversions.
*/ */
function createFootnoteReferenceViewElement( function createFootnoteReferenceViewElement(
modelElement: Element, modelElement: ModelElement,
conversionApi: DowncastConversionApi conversionApi: DowncastConversionApi
): ViewContainerElement { ): ViewContainerElement {
const viewWriter = conversionApi.writer; const viewWriter = conversionApi.writer;
@@ -301,7 +301,7 @@ function createFootnoteReferenceViewElement(
* data downcast and editing downcast conversions. * data downcast and editing downcast conversions.
*/ */
function createFootnoteItemViewElement( function createFootnoteItemViewElement(
modelElement: Element, modelElement: ModelElement,
conversionApi: DowncastConversionApi conversionApi: DowncastConversionApi
): ViewContainerElement { ): ViewContainerElement {
const viewWriter = conversionApi.writer; const viewWriter = conversionApi.writer;
@@ -330,7 +330,7 @@ function createFootnoteItemViewElement(
*/ */
function updateFootnoteReferenceView( function updateFootnoteReferenceView(
data: { data: {
item: Element; item: ModelElement;
attributeOldValue: string; attributeOldValue: string;
attributeNewValue: string; attributeNewValue: string;
}, },
@@ -339,7 +339,7 @@ function updateFootnoteReferenceView(
) { ) {
const { item, attributeNewValue: newIndex } = data; const { item, attributeNewValue: newIndex } = data;
if ( if (
!( item instanceof Element ) || !( item instanceof ModelElement ) ||
!conversionApi.consumable.consume( item, `attribute:${ ATTRIBUTES.footnoteIndex }:${ ELEMENTS.footnoteReference }` ) !conversionApi.consumable.consume( item, `attribute:${ ATTRIBUTES.footnoteIndex }:${ ELEMENTS.footnoteReference }` )
) { ) {
return; return;

View File

@@ -11,7 +11,7 @@ import { defineSchema } from './schema.js';
import { ATTRIBUTES, COMMANDS, ELEMENTS } from '../constants.js'; import { ATTRIBUTES, COMMANDS, ELEMENTS } from '../constants.js';
import InsertFootnoteCommand from '../insert-footnote-command.js'; import InsertFootnoteCommand from '../insert-footnote-command.js';
import { modelQueryElement, modelQueryElementsAll } from '../utils.js'; import { modelQueryElement, modelQueryElementsAll } from '../utils.js';
import { Autoformat, Batch, Element, Plugin, RootElement, viewToModelPositionOutsideModelElement, Widget, Writer } from 'ckeditor5'; import { Autoformat, Batch, ModelElement, Plugin, ModelRootElement, viewToModelPositionOutsideModelElement, Widget, ModelWriter } from 'ckeditor5';
export default class FootnoteEditing extends Plugin { export default class FootnoteEditing extends Plugin {
@@ -26,7 +26,7 @@ export default class FootnoteEditing extends Plugin {
/** /**
* The root element of the document. * The root element of the document.
*/ */
public get rootElement(): RootElement { public get rootElement(): ModelRootElement {
const rootElement = this.editor.model.document.getRoot(); const rootElement = this.editor.model.document.getRoot();
if ( !rootElement ) { if ( !rootElement ) {
throw new Error( 'Document has no rootElement element.' ); throw new Error( 'Document has no rootElement element.' );
@@ -56,7 +56,7 @@ export default class FootnoteEditing extends Plugin {
if ( diffItem.type === 'attribute' && diffItem.attributeKey === ATTRIBUTES.footnoteIndex ) { if ( diffItem.type === 'attribute' && diffItem.attributeKey === ATTRIBUTES.footnoteIndex ) {
const { attributeNewValue: newFootnoteIndex } = diffItem; const { attributeNewValue: newFootnoteIndex } = diffItem;
const footnote = [ ...diffItem.range.getItems() ].find( item => item.is( 'element', ELEMENTS.footnoteItem ) ); const footnote = [ ...diffItem.range.getItems() ].find( item => item.is( 'element', ELEMENTS.footnoteItem ) );
const footnoteId = footnote instanceof Element && footnote.getAttribute( ATTRIBUTES.footnoteId ); const footnoteId = footnote instanceof ModelElement && footnote.getAttribute( ATTRIBUTES.footnoteId );
if ( !footnoteId ) { if ( !footnoteId ) {
return; return;
} }
@@ -143,7 +143,7 @@ export default class FootnoteEditing extends Plugin {
* batch these changes with the ones that instantiated them, * batch these changes with the ones that instantiated them,
* such that the set can be undone with a single action. * such that the set can be undone with a single action.
*/ */
private _clearContents( modelWriter: Writer, footnoteContent: Element ) { private _clearContents( modelWriter: ModelWriter, footnoteContent: ModelElement ) {
const contents = modelWriter.createRangeIn( footnoteContent ); const contents = modelWriter.createRangeIn( footnoteContent );
modelWriter.appendElement( 'paragraph', footnoteContent ); modelWriter.appendElement( 'paragraph', footnoteContent );
modelWriter.remove( contents ); modelWriter.remove( contents );
@@ -155,7 +155,7 @@ export default class FootnoteEditing extends Plugin {
* which triggers the `updateReferenceIds` method. modelWriter is passed in to batch these changes with * which triggers the `updateReferenceIds` method. modelWriter is passed in to batch these changes with
* the ones that instantiated them, such that the set can be undone with a single action. * the ones that instantiated them, such that the set can be undone with a single action.
*/ */
private _removeFootnote( modelWriter: Writer, footnote: Element ) { private _removeFootnote( modelWriter: ModelWriter, footnote: ModelElement ) {
// delete the current footnote and its references, // delete the current footnote and its references,
// and renumber subsequent footnotes. // and renumber subsequent footnotes.
if ( !this.editor ) { if ( !this.editor ) {
@@ -185,7 +185,7 @@ export default class FootnoteEditing extends Plugin {
// immediately deletes the footnote. This deliberately sets the new selection position // immediately deletes the footnote. This deliberately sets the new selection position
// to avoid that. // to avoid that.
const neighborFootnote = index === 0 ? footnoteSection.getChild( index ) : footnoteSection.getChild( ( index ?? 0 ) - 1 ); const neighborFootnote = index === 0 ? footnoteSection.getChild( index ) : footnoteSection.getChild( ( index ?? 0 ) - 1 );
if ( !( neighborFootnote instanceof Element ) ) { if ( !( neighborFootnote instanceof ModelElement ) ) {
return; return;
} }
@@ -212,7 +212,7 @@ export default class FootnoteEditing extends Plugin {
* all references are deleted. modelWriter is passed in to batch these changes with * all references are deleted. modelWriter is passed in to batch these changes with
* the ones that instantiated them, such that the set can be undone with a single action. * the ones that instantiated them, such that the set can be undone with a single action.
*/ */
private _removeReferences( modelWriter: Writer, footnoteId: string | undefined = undefined ) { private _removeReferences( modelWriter: ModelWriter, footnoteId: string | undefined = undefined ) {
const removeList: Array<any> = []; const removeList: Array<any> = [];
if ( !this.rootElement ) { if ( !this.rootElement ) {
throw new Error( 'Document has no root element.' ); throw new Error( 'Document has no root element.' );

View File

@@ -1,5 +1,5 @@
// eslint-disable-next-line no-restricted-imports // eslint-disable-next-line no-restricted-imports
import { Schema } from 'ckeditor5'; import { ModelSchema } from 'ckeditor5';
import { ATTRIBUTES, ELEMENTS } from '../constants.js'; import { ATTRIBUTES, ELEMENTS } from '../constants.js';
/** /**
@@ -7,7 +7,7 @@ import { ATTRIBUTES, ELEMENTS } from '../constants.js';
* See here for the meanings of each rule: * See here for the meanings of each rule:
* https://ckeditor.com/docs/ckeditor5/latest/api/module_engine_model_schema-SchemaItemDefinition.html#member-isObject * https://ckeditor.com/docs/ckeditor5/latest/api/module_engine_model_schema-SchemaItemDefinition.html#member-isObject
*/ */
export const defineSchema = ( schema: Schema ): void => { export const defineSchema = ( schema: ModelSchema ): void => {
/** /**
* Footnote section at the footer of the document. * Footnote section at the footer of the document.
*/ */

View File

@@ -1,4 +1,4 @@
import { Command, type Element, type RootElement, type Writer } from "ckeditor5"; import { Command, type ModelElement, type ModelRootElement, type ModelWriter } from "ckeditor5";
import { ATTRIBUTES, ELEMENTS } from './constants.js'; import { ATTRIBUTES, ELEMENTS } from './constants.js';
import { modelQueryElement } from './utils.js'; import { modelQueryElement } from './utils.js';
@@ -82,7 +82,7 @@ export default class InsertFootnoteCommand extends Command {
/** /**
* Returns the footnote section if it exists, or creates on if it doesn't. * Returns the footnote section if it exists, or creates on if it doesn't.
*/ */
private _getFootnoteSection( writer: Writer, rootElement: RootElement ): Element { private _getFootnoteSection( writer: ModelWriter, rootElement: ModelRootElement ): ModelElement {
const footnoteSection = modelQueryElement( this.editor, rootElement, element => const footnoteSection = modelQueryElement( this.editor, rootElement, element =>
element.is( 'element', ELEMENTS.footnoteSection ) element.is( 'element', ELEMENTS.footnoteSection )
); );

View File

@@ -1,4 +1,4 @@
import { type Editor, Element, Text, TextProxy, ViewElement } from 'ckeditor5'; import { type Editor, ModelElement, ModelText, ModelTextProxy, ViewElement } from 'ckeditor5';
// There's ample DRY violation in this file; type checking // There's ample DRY violation in this file; type checking
// polymorphism without full typescript is just incredibly finicky. // polymorphism without full typescript is just incredibly finicky.
@@ -11,14 +11,14 @@ import { type Editor, Element, Text, TextProxy, ViewElement } from 'ckeditor5';
*/ */
export const modelQueryElementsAll = ( export const modelQueryElementsAll = (
editor: Editor, editor: Editor,
rootElement: Element, rootElement: ModelElement,
predicate: ( item: Element ) => boolean = _ => true predicate: ( item: ModelElement ) => boolean = _ => true
): Array<Element> => { ): Array<ModelElement> => {
const range = editor.model.createRangeIn( rootElement ); const range = editor.model.createRangeIn( rootElement );
const output: Array<Element> = []; const output: Array<ModelElement> = [];
for ( const item of range.getItems() ) { for ( const item of range.getItems() ) {
if ( !( item instanceof Element ) ) { if ( !( item instanceof ModelElement ) ) {
continue; continue;
} }
@@ -35,14 +35,14 @@ export const modelQueryElementsAll = (
*/ */
export const modelQueryTextAll = ( export const modelQueryTextAll = (
editor: Editor, editor: Editor,
rootElement: Element, rootElement: ModelElement,
predicate: ( item: Text | TextProxy ) => boolean = _ => true predicate: ( item: ModelText | ModelTextProxy ) => boolean = _ => true
): Array<Text | TextProxy> => { ): Array<ModelText | ModelTextProxy> => {
const range = editor.model.createRangeIn( rootElement ); const range = editor.model.createRangeIn( rootElement );
const output: Array<Text | TextProxy> = []; const output: Array<ModelText | ModelTextProxy> = [];
for ( const item of range.getItems() ) { for ( const item of range.getItems() ) {
if ( !( item instanceof Text || item instanceof TextProxy ) ) { if ( !( item instanceof ModelText || item instanceof ModelTextProxy ) ) {
continue; continue;
} }
@@ -59,13 +59,13 @@ export const modelQueryTextAll = (
*/ */
export const modelQueryElement = ( export const modelQueryElement = (
editor: Editor, editor: Editor,
rootElement: Element, rootElement: ModelElement,
predicate: ( item: Element ) => boolean = _ => true predicate: ( item: ModelElement ) => boolean = _ => true
): Element | null => { ): ModelElement | null => {
const range = editor.model.createRangeIn( rootElement ); const range = editor.model.createRangeIn( rootElement );
for ( const item of range.getItems() ) { for ( const item of range.getItems() ) {
if ( !( item instanceof Element ) ) { if ( !( item instanceof ModelElement ) ) {
continue; continue;
} }
@@ -82,13 +82,13 @@ export const modelQueryElement = (
*/ */
export const modelQueryText = ( export const modelQueryText = (
editor: Editor, editor: Editor,
rootElement: Element, rootElement: ModelElement,
predicate: ( item: Text | TextProxy ) => boolean = _ => true predicate: ( item: ModelText | ModelTextProxy ) => boolean = _ => true
): Text | TextProxy | null => { ): ModelText | ModelTextProxy | null => {
const range = editor.model.createRangeIn( rootElement ); const range = editor.model.createRangeIn( rootElement );
for ( const item of range.getItems() ) { for ( const item of range.getItems() ) {
if ( !( item instanceof Text || item instanceof TextProxy ) ) { if ( !( item instanceof ModelText || item instanceof ModelTextProxy ) ) {
continue; continue;
} }

View File

@@ -42,7 +42,7 @@
"@typescript-eslint/parser": "^8.0.0", "@typescript-eslint/parser": "^8.0.0",
"@vitest/browser": "^3.0.5", "@vitest/browser": "^3.0.5",
"@vitest/coverage-istanbul": "^3.0.5", "@vitest/coverage-istanbul": "^3.0.5",
"ckeditor5": "45.2.1", "ckeditor5": "46.0.0",
"eslint": "^9.0.0", "eslint": "^9.0.0",
"eslint-config-ckeditor5": ">=9.1.0", "eslint-config-ckeditor5": ">=9.1.0",
"http-server": "^14.1.0", "http-server": "^14.1.0",
@@ -56,7 +56,7 @@
"webdriverio": "^9.0.7" "webdriverio": "^9.0.7"
}, },
"peerDependencies": { "peerDependencies": {
"ckeditor5": "45.2.1" "ckeditor5": "46.0.0"
}, },
"scripts": { "scripts": {
"build": "node ./scripts/build-dist.mjs", "build": "node ./scripts/build-dist.mjs",

View File

@@ -43,7 +43,7 @@
"@typescript-eslint/parser": "^8.0.0", "@typescript-eslint/parser": "^8.0.0",
"@vitest/browser": "^3.0.5", "@vitest/browser": "^3.0.5",
"@vitest/coverage-istanbul": "^3.0.5", "@vitest/coverage-istanbul": "^3.0.5",
"ckeditor5": "45.2.1", "ckeditor5": "46.0.0",
"eslint": "^9.0.0", "eslint": "^9.0.0",
"eslint-config-ckeditor5": ">=9.1.0", "eslint-config-ckeditor5": ">=9.1.0",
"http-server": "^14.1.0", "http-server": "^14.1.0",
@@ -57,7 +57,7 @@
"webdriverio": "^9.0.7" "webdriverio": "^9.0.7"
}, },
"peerDependencies": { "peerDependencies": {
"ckeditor5": "45.2.1" "ckeditor5": "46.0.0"
}, },
"scripts": { "scripts": {
"build": "node ./scripts/build-dist.mjs", "build": "node ./scripts/build-dist.mjs",
@@ -90,6 +90,6 @@
} }
}, },
"dependencies": { "dependencies": {
"@ckeditor/ckeditor5-icons": "45.2.1" "@ckeditor/ckeditor5-icons": "46.0.0"
} }
} }

View File

@@ -1,4 +1,4 @@
import { Clipboard, Plugin, type Editor, LivePosition, LiveRange, Undo } from 'ckeditor5'; import { Clipboard, Plugin, type Editor, ModelLivePosition, ModelLiveRange, Undo } from 'ckeditor5';
import { extractDelimiters, hasDelimiters, delimitersCounts } from './utils.js'; import { extractDelimiters, hasDelimiters, delimitersCounts } from './utils.js';
export default class AutoMath extends Plugin { export default class AutoMath extends Plugin {
@@ -11,7 +11,7 @@ export default class AutoMath extends Plugin {
} }
private _timeoutId: null | number; private _timeoutId: null | number;
private _positionToInsert: null | LivePosition; private _positionToInsert: null | ModelLivePosition;
constructor( editor: Editor ) { constructor( editor: Editor ) {
super( editor ); super( editor );
@@ -31,10 +31,10 @@ export default class AutoMath extends Plugin {
return; return;
} }
const leftLivePosition = LivePosition.fromPosition( firstRange.start ); const leftLivePosition = ModelLivePosition.fromPosition( firstRange.start );
leftLivePosition.stickiness = 'toPrevious'; leftLivePosition.stickiness = 'toPrevious';
const rightLivePosition = LivePosition.fromPosition( firstRange.end ); const rightLivePosition = ModelLivePosition.fromPosition( firstRange.end );
rightLivePosition.stickiness = 'toNext'; rightLivePosition.stickiness = 'toNext';
modelDocument.once( 'change:data', () => { modelDocument.once( 'change:data', () => {
@@ -63,15 +63,15 @@ export default class AutoMath extends Plugin {
} }
private _mathBetweenPositions( private _mathBetweenPositions(
leftPosition: LivePosition, leftPosition: ModelLivePosition,
rightPosition: LivePosition rightPosition: ModelLivePosition
) { ) {
const editor = this.editor; const editor = this.editor;
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const mathConfig = this.editor.config.get( 'math' ); const mathConfig = this.editor.config.get( 'math' );
const equationRange = new LiveRange( leftPosition, rightPosition ); const equationRange = new ModelLiveRange( leftPosition, rightPosition );
const walker = equationRange.getWalker( { ignoreElementEnd: true } ); const walker = equationRange.getWalker( { ignoreElementEnd: true } );
let text = ''; let text = '';
@@ -97,7 +97,7 @@ export default class AutoMath extends Plugin {
return; return;
} }
this._positionToInsert = LivePosition.fromPosition( leftPosition ); this._positionToInsert = ModelLivePosition.fromPosition( leftPosition );
// With timeout user can undo conversation if want use plain text // With timeout user can undo conversation if want use plain text
this._timeoutId = window.setTimeout( () => { this._timeoutId = window.setTimeout( () => {
@@ -106,7 +106,7 @@ export default class AutoMath extends Plugin {
writer.remove( equationRange ); writer.remove( equationRange );
let insertPosition: LivePosition | null; let insertPosition: ModelLivePosition | null;
// Check if position where the math element should be inserted is still valid. // Check if position where the math element should be inserted is still valid.
if ( this._positionToInsert?.root.rootName !== '$graveyard' ) { if ( this._positionToInsert?.root.rootName !== '$graveyard' ) {

View File

@@ -1,5 +1,5 @@
import MathCommand from './mathcommand.js'; import MathCommand from './mathcommand.js';
import { type Editor, Plugin, toWidget, Widget, viewToModelPositionOutsideModelElement, type DowncastWriter, type Element, CKEditorError, uid } from 'ckeditor5'; import { type Editor, Plugin, toWidget, Widget, viewToModelPositionOutsideModelElement, type ViewDowncastWriter, type ModelElement, CKEditorError, uid } from 'ckeditor5';
import { renderEquation, extractDelimiters } from './utils.js'; import { renderEquation, extractDelimiters } from './utils.js';
export default class MathEditing extends Plugin { export default class MathEditing extends Plugin {
@@ -211,8 +211,8 @@ export default class MathEditing extends Plugin {
// Create view for editor // Create view for editor
function createMathtexEditingView( function createMathtexEditingView(
modelItem: Element, modelItem: ModelElement,
writer: DowncastWriter writer: ViewDowncastWriter
) { ) {
const equation = String( modelItem.getAttribute( 'equation' ) ); const equation = String( modelItem.getAttribute( 'equation' ) );
const display = !!modelItem.getAttribute( 'display' ); const display = !!modelItem.getAttribute( 'display' );
@@ -261,8 +261,8 @@ export default class MathEditing extends Plugin {
// Create view for data // Create view for data
function createMathtexView( function createMathtexView(
modelItem: Element, modelItem: ModelElement,
{ writer }: { writer: DowncastWriter } { writer }: { writer: ViewDowncastWriter }
) { ) {
const equation = modelItem.getAttribute( 'equation' ); const equation = modelItem.getAttribute( 'equation' );
if ( typeof equation != 'string' ) { if ( typeof equation != 'string' ) {

View File

@@ -1,10 +1,10 @@
import type { Editor, Element as CKElement, DocumentSelection, PositioningFunction } from 'ckeditor5'; import type { Editor, ModelElement, ModelDocumentSelection, PositioningFunction } from 'ckeditor5';
import { BalloonPanelView, CKEditorError } from 'ckeditor5'; import { BalloonPanelView, CKEditorError } from 'ckeditor5';
import type { KatexOptions, MathJax2, MathJax3 } from './typings-external.js'; import type { KatexOptions, MathJax2, MathJax3 } from './typings-external.js';
export function getSelectedMathModelWidget( export function getSelectedMathModelWidget(
selection: DocumentSelection selection: ModelDocumentSelection
): null | CKElement { ): null | ModelElement {
const selectedElement = selection.getSelectedElement(); const selectedElement = selection.getSelectedElement();
if ( if (

View File

@@ -42,7 +42,7 @@
"@typescript-eslint/parser": "^8.0.0", "@typescript-eslint/parser": "^8.0.0",
"@vitest/browser": "^3.0.5", "@vitest/browser": "^3.0.5",
"@vitest/coverage-istanbul": "^3.0.5", "@vitest/coverage-istanbul": "^3.0.5",
"ckeditor5": "45.2.1", "ckeditor5": "46.0.0",
"eslint": "^9.0.0", "eslint": "^9.0.0",
"eslint-config-ckeditor5": ">=9.1.0", "eslint-config-ckeditor5": ">=9.1.0",
"http-server": "^14.1.0", "http-server": "^14.1.0",
@@ -56,7 +56,7 @@
"webdriverio": "^9.0.7" "webdriverio": "^9.0.7"
}, },
"peerDependencies": { "peerDependencies": {
"ckeditor5": "45.2.1" "ckeditor5": "46.0.0"
}, },
"scripts": { "scripts": {
"build": "node ./scripts/build-dist.mjs", "build": "node ./scripts/build-dist.mjs",

View File

@@ -1,5 +1,5 @@
import { checkIsOn } from '../utils.js'; import { checkIsOn } from '../utils.js';
import { Command, Element } from 'ckeditor5'; import { Command, ModelElement } from 'ckeditor5';
/** /**
* The mermaid preview command. * The mermaid preview command.
@@ -27,7 +27,7 @@ export default class MermaidPreviewCommand extends Command {
const editor = this.editor; const editor = this.editor;
const model = editor.model; const model = editor.model;
const documentSelection = this.editor.model.document.selection; const documentSelection = this.editor.model.document.selection;
const mermaidItem = (documentSelection.getSelectedElement() || documentSelection.getLastPosition()?.parent) as Element; const mermaidItem = (documentSelection.getSelectedElement() || documentSelection.getLastPosition()?.parent) as ModelElement;
if (mermaidItem) { if (mermaidItem) {
model.change( writer => { model.change( writer => {

View File

@@ -1,5 +1,5 @@
import { checkIsOn } from '../utils.js'; import { checkIsOn } from '../utils.js';
import { Command, Element } from 'ckeditor5'; import { Command, ModelElement } from 'ckeditor5';
/** /**
* The mermaid source view command. * The mermaid source view command.
@@ -29,7 +29,7 @@ export default class MermaidSourceViewCommand extends Command {
const editor = this.editor; const editor = this.editor;
const model = editor.model; const model = editor.model;
const documentSelection = this.editor.model.document.selection; const documentSelection = this.editor.model.document.selection;
const mermaidItem = (documentSelection.getSelectedElement() || documentSelection.getLastPosition()?.parent) as Element; const mermaidItem = (documentSelection.getSelectedElement() || documentSelection.getLastPosition()?.parent) as ModelElement;
model.change( writer => { model.change( writer => {
if ( mermaidItem.getAttribute( 'displayMode' ) !== 'source' ) { if ( mermaidItem.getAttribute( 'displayMode' ) !== 'source' ) {

View File

@@ -3,7 +3,7 @@
*/ */
import { checkIsOn } from '../utils.js'; import { checkIsOn } from '../utils.js';
import { Command, Element } from 'ckeditor5'; import { Command, ModelElement } from 'ckeditor5';
/** /**
* The mermaid split view command. * The mermaid split view command.
@@ -31,7 +31,7 @@ export default class MermaidSplitViewCommand extends Command {
const editor = this.editor; const editor = this.editor;
const model = editor.model; const model = editor.model;
const documentSelection = this.editor.model.document.selection; const documentSelection = this.editor.model.document.selection;
const mermaidItem = (documentSelection.getSelectedElement() || documentSelection.getLastPosition()?.parent) as Element; const mermaidItem = (documentSelection.getSelectedElement() || documentSelection.getLastPosition()?.parent) as ModelElement;
model.change( writer => { model.change( writer => {
if ( mermaidItem.getAttribute( 'displayMode' ) !== 'split' ) { if ( mermaidItem.getAttribute( 'displayMode' ) !== 'split' ) {

View File

@@ -8,7 +8,7 @@ import MermaidPreviewCommand from './commands/mermaidPreviewCommand.js';
import MermaidSourceViewCommand from './commands/mermaidSourceViewCommand.js'; import MermaidSourceViewCommand from './commands/mermaidSourceViewCommand.js';
import MermaidSplitViewCommand from './commands/mermaidSplitViewCommand.js'; import MermaidSplitViewCommand from './commands/mermaidSplitViewCommand.js';
import InsertMermaidCommand from './commands/insertMermaidCommand.js'; import InsertMermaidCommand from './commands/insertMermaidCommand.js';
import { DowncastAttributeEvent, DowncastConversionApi, EditorConfig, Element, EventInfo, Item, Node, Plugin, toWidget, UpcastConversionApi, UpcastConversionData, ViewElement, ViewText, ViewUIElement } from 'ckeditor5'; import { DowncastAttributeEvent, DowncastConversionApi, EditorConfig, ModelElement, EventInfo, ModelItem, ModelNode, Plugin, toWidget, UpcastConversionApi, UpcastConversionData, ViewElement, ViewText, ViewUIElement } from 'ckeditor5';
// Time in milliseconds. // Time in milliseconds.
const DEBOUNCE_TIME = 300; const DEBOUNCE_TIME = 300;
@@ -95,7 +95,7 @@ export default class MermaidEditing extends Plugin {
return; return;
} }
const targetViewPosition = mapper.toViewPosition( model.createPositionBefore( data.item as Item ) ); const targetViewPosition = mapper.toViewPosition( model.createPositionBefore( data.item as ModelItem ) );
// For downcast we're using only language-mermaid class. We don't set class to `mermaid language-mermaid` as // For downcast we're using only language-mermaid class. We don't set class to `mermaid language-mermaid` as
// multiple markdown converters that we have seen are using only `language-mermaid` class and not `mermaid` alone. // multiple markdown converters that we have seen are using only `language-mermaid` class and not `mermaid` alone.
const code = writer.createContainerElement( 'code', { const code = writer.createContainerElement( 'code', {
@@ -109,7 +109,7 @@ export default class MermaidEditing extends Plugin {
writer.insert( model.createPositionAt( code, 'end' ) as any, sourceTextNode ); writer.insert( model.createPositionAt( code, 'end' ) as any, sourceTextNode );
writer.insert( model.createPositionAt( pre, 'end' ) as any, code ); writer.insert( model.createPositionAt( pre, 'end' ) as any, code );
writer.insert( targetViewPosition, pre ); writer.insert( targetViewPosition, pre );
mapper.bindElements( data.item as Element, code as ViewElement ); mapper.bindElements( data.item as ModelElement, code as ViewElement );
} }
_mermaidDowncast( evt: EventInfo, data: DowncastConversionData, conversionApi: DowncastConversionApi ) { _mermaidDowncast( evt: EventInfo, data: DowncastConversionData, conversionApi: DowncastConversionApi ) {
@@ -122,7 +122,7 @@ export default class MermaidEditing extends Plugin {
return; return;
} }
const targetViewPosition = mapper.toViewPosition( model.createPositionBefore( data.item as Item ) ); const targetViewPosition = mapper.toViewPosition( model.createPositionBefore( data.item as ModelItem ) );
const wrapperAttributes = { const wrapperAttributes = {
class: [ 'ck-mermaid__wrapper' ] class: [ 'ck-mermaid__wrapper' ]
@@ -144,7 +144,7 @@ export default class MermaidEditing extends Plugin {
writer.insert( targetViewPosition, wrapper ); writer.insert( targetViewPosition, wrapper );
mapper.bindElements( data.item as Element, wrapper ); mapper.bindElements( data.item as ModelElement, wrapper );
return toWidget( wrapper, writer, { return toWidget( wrapper, writer, {
label: t( 'Mermaid widget' ), label: t( 'Mermaid widget' ),
@@ -158,7 +158,7 @@ export default class MermaidEditing extends Plugin {
const debouncedListener = debounce( event => { const debouncedListener = debounce( event => {
editor.model.change( writer => { editor.model.change( writer => {
writer.setAttribute( 'source', event.target.value, data.item as Node ); writer.setAttribute( 'source', event.target.value, data.item as ModelNode );
} ); } );
}, DEBOUNCE_TIME ); }, DEBOUNCE_TIME );
@@ -171,7 +171,7 @@ export default class MermaidEditing extends Plugin {
// Move the selection onto the mermaid widget if it's currently not selected. // Move the selection onto the mermaid widget if it's currently not selected.
if ( selectedElement !== data.item ) { if ( selectedElement !== data.item ) {
model.change( writer => writer.setSelection( data.item as Node, 'on' ) ); model.change( writer => writer.setSelection( data.item as ModelNode, 'on' ) );
} }
}, true ); }, true );
@@ -200,7 +200,7 @@ export default class MermaidEditing extends Plugin {
const domConverter = this.editor.editing.view.domConverter; const domConverter = this.editor.editing.view.domConverter;
if ( newSource ) { if ( newSource ) {
const mermaidView = conversionApi.mapper.toViewElement( data.item as Element ); const mermaidView = conversionApi.mapper.toViewElement( data.item as ModelElement );
if (!mermaidView) { if (!mermaidView) {
return; return;
} }
@@ -208,7 +208,7 @@ export default class MermaidEditing extends Plugin {
for ( const _child of mermaidView.getChildren() ) { for ( const _child of mermaidView.getChildren() ) {
const child = _child as ViewElement; const child = _child as ViewElement;
if ( child.name === 'textarea' && child.hasClass( 'ck-mermaid__editing-view' ) ) { if ( child.name === 'textarea' && child.hasClass( 'ck-mermaid__editing-view' ) ) {
// Text & HTMLElement & Node & DocumentFragment // Text & HTMLElement & ModelNode & DocumentFragment
const domEditingTextarea = domConverter.viewToDom(child) as HTMLElement as HTMLInputElement; const domEditingTextarea = domConverter.viewToDom(child) as HTMLElement as HTMLInputElement;
if ( domEditingTextarea.value != newSource ) { if ( domEditingTextarea.value != newSource ) {

View File

@@ -7,7 +7,7 @@ import previewModeIcon from '../theme/icons/preview-mode.svg';
import splitModeIcon from '../theme/icons/split-mode.svg'; import splitModeIcon from '../theme/icons/split-mode.svg';
import sourceModeIcon from '../theme/icons/source-mode.svg'; import sourceModeIcon from '../theme/icons/source-mode.svg';
import infoIcon from '../theme/icons/info.svg'; import infoIcon from '../theme/icons/info.svg';
import { ButtonView, Editor, Element, Locale, Observable, Plugin } from 'ckeditor5'; import { ButtonView, Editor, ModelElement, Locale, Observable, Plugin } from 'ckeditor5';
import InsertMermaidCommand from './commands/insertMermaidCommand.js'; import InsertMermaidCommand from './commands/insertMermaidCommand.js';
/* global window, document */ /* global window, document */
@@ -69,7 +69,7 @@ export default class MermaidUI extends Plugin {
// Execute the command when the button is clicked. // Execute the command when the button is clicked.
command.listenTo( buttonView, 'execute', () => { command.listenTo( buttonView, 'execute', () => {
const mermaidItem = editor.execute( 'insertMermaidCommand' ) as Element; const mermaidItem = editor.execute( 'insertMermaidCommand' ) as ModelElement;
const mermaidItemViewElement = editor.editing.mapper.toViewElement( mermaidItem ); const mermaidItemViewElement = editor.editing.mapper.toViewElement( mermaidItem );
view.scrollToTheSelection(); view.scrollToTheSelection();

View File

@@ -35,8 +35,8 @@
"@triliumnext/ckeditor5-keyboard-marker": "workspace:*", "@triliumnext/ckeditor5-keyboard-marker": "workspace:*",
"@triliumnext/ckeditor5-math": "workspace:*", "@triliumnext/ckeditor5-math": "workspace:*",
"@triliumnext/ckeditor5-mermaid": "workspace:*", "@triliumnext/ckeditor5-mermaid": "workspace:*",
"ckeditor5": "45.2.1", "ckeditor5": "46.0.0",
"ckeditor5-premium-features": "45.2.1" "ckeditor5-premium-features": "46.0.0"
}, },
"devDependencies": { "devDependencies": {
"@types/jquery": "3.5.32" "@types/jquery": "3.5.32"

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, ModelNode, ModelPosition, 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

@@ -1,4 +1,4 @@
import { Command, FileRepository, Model, type NodeAttributes, type Writer } from "ckeditor5"; import { Command, FileRepository, Model, type ModelNodeAttributes, type ModelWriter } from "ckeditor5";
interface FileUploadOpts { interface FileUploadOpts {
file: File[]; file: File[];
@@ -34,7 +34,7 @@ export default class FileUploadCommand extends Command {
/** /**
* Handles uploading single file. * Handles uploading single file.
*/ */
function uploadFile( writer: Writer, model: Model, fileRepository: FileRepository, file: File ) { function uploadFile( writer: ModelWriter, model: Model, fileRepository: FileRepository, file: File ) {
const loader = fileRepository.createLoader( file ); const loader = fileRepository.createLoader( file );
// Do not throw when upload adapter is not set. FileRepository will log an error anyway. // Do not throw when upload adapter is not set. FileRepository will log an error anyway.
@@ -45,7 +45,7 @@ function uploadFile( writer: Writer, model: Model, fileRepository: FileRepositor
insertFileLink( writer, model, { href: '', uploadId: loader.id }, file ); insertFileLink( writer, model, { href: '', uploadId: loader.id }, file );
} }
function insertFileLink( writer: Writer, model: Model, attributes: NodeAttributes = {}, file: File ) { function insertFileLink( writer: ModelWriter, model: Model, attributes: ModelNodeAttributes = {}, file: File ) {
const placeholder = writer.createElement( 'reference', attributes ); const placeholder = writer.createElement( 'reference', attributes );
model.insertContent( placeholder, model.document.selection ); model.insertContent( placeholder, model.document.selection );
writer.insertText( ' ', placeholder, 'after' ); writer.insertText( ' ', placeholder, 'after' );

View File

@@ -1,4 +1,4 @@
import { Clipboard, FileRepository, Notification, Plugin, UpcastWriter, ViewElement, type Editor, type FileLoader, type Item, type Node, type ViewItem, type ViewRange } from 'ckeditor5'; import { Clipboard, FileRepository, Notification, Plugin, UpcastWriter, ViewElement, type Editor, type FileLoader, type ModelItem, type ModelNode, type ViewItem, type ViewRange } from 'ckeditor5';
import FileUploadCommand from './fileuploadcommand'; import FileUploadCommand from './fileuploadcommand';
export default class FileUploadEditing extends Plugin { export default class FileUploadEditing extends Plugin {
@@ -58,7 +58,7 @@ export default class FileUploadEditing extends Plugin {
this.listenTo( editor.plugins.get( Clipboard ), 'inputTransformation', ( evt, data ) => { this.listenTo( editor.plugins.get( Clipboard ), 'inputTransformation', ( evt, data ) => {
const fetchableFiles = Array.from( editor.editing.view.createRangeIn( data.content ) ) const fetchableFiles = Array.from( editor.editing.view.createRangeIn( data.content ) )
.filter( value => isLocalFile( value.item ) && !(value.item as unknown as Node).getAttribute( 'uploadProcessed' ) ) .filter( value => isLocalFile( value.item ) && !(value.item as unknown as ModelNode).getAttribute( 'uploadProcessed' ) )
.map( value => { .map( value => {
return { promise: fetchLocalFile( value.item ), fileElement: value as unknown as ViewElement }; return { promise: fetchLocalFile( value.item ), fileElement: value as unknown as ViewElement };
} ); } );
@@ -123,7 +123,7 @@ export default class FileUploadEditing extends Plugin {
} ); } );
} }
_readAndUpload( loader: FileLoader, fileElement: Item ) { _readAndUpload( loader: FileLoader, fileElement: ModelItem ) {
const editor = this.editor; const editor = this.editor;
const model = editor.model; const model = editor.model;
const t = editor.locale.t; const t = editor.locale.t;
@@ -195,7 +195,7 @@ export default class FileUploadEditing extends Plugin {
function fetchLocalFile( link: ViewItem ) { function fetchLocalFile( link: ViewItem ) {
return new Promise<File>( ( resolve, reject ) => { return new Promise<File>( ( resolve, reject ) => {
const href = (link as unknown as Node).getAttribute( 'href' ) as string; const href = (link as unknown as ModelNode).getAttribute( 'href' ) as string;
// Fetch works asynchronously and so does not block the browser UI when processing data. // Fetch works asynchronously and so does not block the browser UI when processing data.
fetch( href ) fetch( href )
@@ -250,7 +250,7 @@ export function isHtmlIncluded( dataTransfer: DataTransfer ) {
return Array.from( dataTransfer.types ).includes( 'text/html' ) && dataTransfer.getData( 'text/html' ) !== ''; return Array.from( dataTransfer.types ).includes( 'text/html' ) && dataTransfer.getData( 'text/html' ) !== '';
} }
function getFileLinksFromChangeItem( editor: Editor, item: Item ) { function getFileLinksFromChangeItem( editor: Editor, item: ModelItem ) {
return Array.from( editor.model.createRangeOn( item ) ) return Array.from( editor.model.createRangeOn( item ) )
.filter( value => value.item.hasAttribute( 'href' ) ) .filter( value => value.item.hasAttribute( 'href' ) )
.map( value => value.item ); .map( value => value.item );

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 { ModelDocumentFragment, ModelElement, Plugin, ModelPosition } 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: ModelPosition | ModelElement | ModelDocumentFragment | 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

@@ -1,4 +1,4 @@
import { Command, Mention, Plugin, Range, type Selectable } from "ckeditor5"; import { Command, Mention, Plugin, ModelRange, type ModelSelectable } from "ckeditor5";
/** /**
* Overrides the actions taken by the Mentions plugin (triggered by `@` in the text editor, or `~` & `#` in the attribute editor): * Overrides the actions taken by the Mentions plugin (triggered by `@` in the text editor, or `~` & `#` in the attribute editor):
@@ -31,7 +31,7 @@ interface MentionOpts {
}; };
marker: string; marker: string;
text?: string; text?: string;
range?: Range; range?: ModelRange;
} }
interface MentionAttribute { interface MentionAttribute {
@@ -48,7 +48,7 @@ class CustomMentionCommand extends Command {
const {document} = model; const {document} = model;
const {selection} = document; const {selection} = document;
const mention = options.mention as unknown as MentionAttribute; const mention = options.mention as unknown as MentionAttribute;
const range = (options.range || selection.getFirstRange()) as Selectable; const range = (options.range || selection.getFirstRange()) as ModelSelectable;
if (mention.id.startsWith('#') || mention.id.startsWith('~')) { if (mention.id.startsWith('#') || mention.id.startsWith('~')) {
model.change(writer => { model.change(writer => {
@@ -69,7 +69,7 @@ class CustomMentionCommand extends Command {
} }
} }
insertReference(range: Selectable, notePath: string) { insertReference(range: ModelSelectable, notePath: string) {
const {model} = this.editor; const {model} = this.editor;
model.change(writer => { model.change(writer => {

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, ModelDocumentSelection, ModelElement, ModelNode, Plugin, ModelRange } 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): ModelNode | null;
abstract get offset(): "before" | "after"; abstract get offset(): "before" | "after";
override execute() { override execute() {
@@ -81,7 +81,7 @@ abstract class MoveBlockUpDownCommand extends Command {
} }
// Restore selection // Restore selection
let range: Range; let range: ModelRange;
const maxStart = firstBlock.maxOffset ?? startOffset; const maxStart = firstBlock.maxOffset ?? startOffset;
const maxEnd = lastBlock.maxOffset ?? endOffset; const maxEnd = lastBlock.maxOffset ?? endOffset;
// If original offsets valid within bounds, restore partial selection // If original offsets valid within bounds, restore partial selection
@@ -105,9 +105,9 @@ abstract class MoveBlockUpDownCommand extends Command {
}); });
} }
getSelectedBlocks(selection: DocumentSelection) { getSelectedBlocks(selection: ModelDocumentSelection) {
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,10 +1,10 @@
import type { Element, Position, Writer } from "ckeditor5"; import type { ModelElement, ModelPosition, ModelWriter } from "ckeditor5";
import type { Node, Editor } from "ckeditor5"; import type { ModelNode, Editor } from "ckeditor5";
import { Plugin } from "ckeditor5"; import { Plugin } from "ckeditor5";
interface SpanStackEntry { interface SpanStackEntry {
className: string; className: string;
posStart: Position; posStart: ModelPosition;
} }
/* /*
@@ -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 | ModelNode) {
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: ModelWriter) {
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) {
@@ -242,7 +242,7 @@ export default class SyntaxHighlighting extends Plugin {
let spanStack: SpanStackEntry[] = []; let spanStack: SpanStackEntry[] = [];
let iChild = -1; let iChild = -1;
let childText = ""; let childText = "";
let child: Node | null = null; let child: ModelNode | null = null;
let iChildText = 0; let iChildText = 0;
while (iHtml < html.length) { while (iHtml < html.length) {

3784
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff