mirror of
https://github.com/zadam/trilium.git
synced 2025-10-20 15:19:01 +02:00
fix(deps): update ckeditor monorepo (major) (#6283)
This commit is contained in:
commit
e7f02fe22b
@ -58,7 +58,7 @@
|
||||
"vanilla-js-wheel-zoom": "9.0.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@ckeditor/ckeditor5-inspector": "4.1.0",
|
||||
"@ckeditor/ckeditor5-inspector": "5.0.0",
|
||||
"@types/bootstrap": "5.2.10",
|
||||
"@types/jquery": "3.5.32",
|
||||
"@types/leaflet": "1.9.20",
|
||||
|
@ -81,8 +81,8 @@ body {
|
||||
|
||||
/* -- Overrides the default colors used by the ckeditor5-image package. --------------------- */
|
||||
|
||||
--ck-color-image-caption-background: var(--main-background-color);
|
||||
--ck-color-image-caption-text: var(--main-text-color);
|
||||
--ck-content-color-image-caption-background: var(--main-background-color);
|
||||
--ck-content-color-image-caption-text: var(--main-text-color);
|
||||
|
||||
/* -- Overrides the default colors used by the ckeditor5-widget package. -------------------- */
|
||||
|
||||
|
@ -4,7 +4,7 @@ import noteAutocompleteService, { type Suggestion } from "../../services/note_au
|
||||
import server from "../../services/server.js";
|
||||
import contextMenuService from "../../menus/context_menu.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 attributeRenderer from "../../services/attribute_renderer.js";
|
||||
import noteCreateService from "../../services/note_create.js";
|
||||
@ -417,15 +417,15 @@ export default class AttributeEditorWidget extends NoteContextAwareWidget implem
|
||||
this.$editor.tooltip("show");
|
||||
}
|
||||
|
||||
getClickIndex(pos: Position) {
|
||||
getClickIndex(pos: ModelPosition) {
|
||||
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) {
|
||||
curNode = curNode.previousSibling;
|
||||
|
||||
if ((curNode as Element).name === "reference") {
|
||||
if ((curNode as ModelElement).name === "reference") {
|
||||
clickIndex += (curNode.getAttribute("notePath") as string).length + 1;
|
||||
} else if ("data" in curNode) {
|
||||
clickIndex += (curNode.data as string).length;
|
||||
|
@ -39,7 +39,7 @@
|
||||
"@typescript-eslint/parser": "^8.0.0",
|
||||
"@vitest/browser": "^3.0.5",
|
||||
"@vitest/coverage-istanbul": "^3.0.5",
|
||||
"ckeditor5": "45.2.1",
|
||||
"ckeditor5": "46.0.0",
|
||||
"eslint": "^9.0.0",
|
||||
"eslint-config-ckeditor5": ">=9.1.0",
|
||||
"http-server": "^14.1.0",
|
||||
@ -53,7 +53,7 @@
|
||||
"webdriverio": "^9.0.7"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"ckeditor5": "45.2.1"
|
||||
"ckeditor5": "46.0.0"
|
||||
},
|
||||
"author": "Elian Doran <contact@eliandoran.me>",
|
||||
"license": "GPL-2.0-or-later",
|
||||
|
@ -8,7 +8,7 @@
|
||||
*/
|
||||
|
||||
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.
|
||||
@ -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
|
||||
* 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.
|
||||
getRangesOfBlockGroups( writer, blocks ).reverse().forEach( groupRange => {
|
||||
if ( groupRange.start.isAtStart && groupRange.end.isAtEnd ) {
|
||||
writer.unwrap( groupRange.start.parent as Element );
|
||||
writer.unwrap( groupRange.start.parent as ModelElement );
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// 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 ) {
|
||||
const positionBefore = writer.createPositionBefore( groupRange.start.parent as Element );
|
||||
const positionBefore = writer.createPositionBefore( groupRange.start.parent as ModelElement );
|
||||
|
||||
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.
|
||||
|
||||
const positionAfter = writer.createPositionAfter( groupRange.end.parent as Element );
|
||||
const positionAfter = writer.createPositionAfter( groupRange.end.parent as ModelElement );
|
||||
|
||||
writer.move( groupRange, positionAfter );
|
||||
} );
|
||||
@ -189,9 +189,9 @@ export default class AdmonitionCommand extends Command {
|
||||
/**
|
||||
* 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;
|
||||
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.
|
||||
getRangesOfBlockGroups( writer, blocks ).reverse().forEach( groupRange => {
|
||||
@ -205,7 +205,7 @@ export default class AdmonitionCommand extends Command {
|
||||
writer.wrap( groupRange, quote );
|
||||
} else if (quote.is("element")) {
|
||||
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;
|
||||
}
|
||||
|
||||
@ -239,7 +239,7 @@ function findQuote( elementOrPosition: Element | Position ): Element | DocumentF
|
||||
* blocks: [ a, b, d, f, g, h ]
|
||||
* 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 i = 0;
|
||||
const ranges = [];
|
||||
@ -266,9 +266,9 @@ function getRangesOfBlockGroups( writer: Writer, blocks: Array<Element> ): Array
|
||||
/**
|
||||
* 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().
|
||||
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 );
|
||||
|
||||
return isBQAllowed && isBlockAllowedInBQ;
|
||||
|
@ -40,7 +40,7 @@
|
||||
"@typescript-eslint/parser": "^8.0.0",
|
||||
"@vitest/browser": "^3.0.5",
|
||||
"@vitest/coverage-istanbul": "^3.0.5",
|
||||
"ckeditor5": "45.2.1",
|
||||
"ckeditor5": "46.0.0",
|
||||
"eslint": "^9.0.0",
|
||||
"eslint-config-ckeditor5": ">=9.1.0",
|
||||
"http-server": "^14.1.0",
|
||||
@ -54,7 +54,7 @@
|
||||
"webdriverio": "^9.0.7"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"ckeditor5": "45.2.1"
|
||||
"ckeditor5": "46.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "node ./scripts/build-dist.mjs",
|
||||
|
@ -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 { modelQueryElement, modelQueryElementsAll } from '../utils.js';
|
||||
@ -68,13 +68,13 @@ const regexMatchCallback = (
|
||||
* Footnotes only get inserted if the matching range is an integer between 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 );
|
||||
if ( !command || !command.isEnabled ) {
|
||||
return;
|
||||
}
|
||||
const text = [ ...ranges[ 0 ].getItems() ][ 0 ];
|
||||
if ( !( text instanceof TextProxy || text instanceof Text ) ) {
|
||||
if ( !( text instanceof ModelTextProxy || text instanceof ModelText ) ) {
|
||||
return false;
|
||||
}
|
||||
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]`.
|
||||
*/
|
||||
export const addFootnoteAutoformatting = ( editor: Editor, rootElement: Element ): void => {
|
||||
export const addFootnoteAutoformatting = ( editor: Editor, rootElement: ModelElement ): void => {
|
||||
if ( editor.plugins.has( 'Autoformat' ) ) {
|
||||
const autoformatPluginInstance = editor.plugins.get( 'Autoformat' ) as Autoformat;
|
||||
inlineAutoformatEditing(
|
||||
editor,
|
||||
autoformatPluginInstance,
|
||||
text => regexMatchCallback( editor, text ),
|
||||
( _, ranges: Array<Range> ) => formatCallback( ranges, editor, rootElement )
|
||||
( _, ranges: Array<ModelRange> ) => formatCallback( ranges, editor, rootElement )
|
||||
);
|
||||
}
|
||||
};
|
||||
|
@ -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 { viewQueryElement } from '../utils.js';
|
||||
@ -232,7 +232,7 @@ export const defineConverters = ( editor: Editor ): void => {
|
||||
* for both data and editing downcasts.
|
||||
*/
|
||||
function createFootnoteBackLinkViewElement(
|
||||
modelElement: Element,
|
||||
modelElement: ModelElement,
|
||||
conversionApi: DowncastConversionApi
|
||||
): ViewContainerElement {
|
||||
const viewWriter = conversionApi.writer;
|
||||
@ -264,7 +264,7 @@ function createFootnoteBackLinkViewElement(
|
||||
* data downcast and editing downcast conversions.
|
||||
*/
|
||||
function createFootnoteReferenceViewElement(
|
||||
modelElement: Element,
|
||||
modelElement: ModelElement,
|
||||
conversionApi: DowncastConversionApi
|
||||
): ViewContainerElement {
|
||||
const viewWriter = conversionApi.writer;
|
||||
@ -301,7 +301,7 @@ function createFootnoteReferenceViewElement(
|
||||
* data downcast and editing downcast conversions.
|
||||
*/
|
||||
function createFootnoteItemViewElement(
|
||||
modelElement: Element,
|
||||
modelElement: ModelElement,
|
||||
conversionApi: DowncastConversionApi
|
||||
): ViewContainerElement {
|
||||
const viewWriter = conversionApi.writer;
|
||||
@ -330,7 +330,7 @@ function createFootnoteItemViewElement(
|
||||
*/
|
||||
function updateFootnoteReferenceView(
|
||||
data: {
|
||||
item: Element;
|
||||
item: ModelElement;
|
||||
attributeOldValue: string;
|
||||
attributeNewValue: string;
|
||||
},
|
||||
@ -339,7 +339,7 @@ function updateFootnoteReferenceView(
|
||||
) {
|
||||
const { item, attributeNewValue: newIndex } = data;
|
||||
if (
|
||||
!( item instanceof Element ) ||
|
||||
!( item instanceof ModelElement ) ||
|
||||
!conversionApi.consumable.consume( item, `attribute:${ ATTRIBUTES.footnoteIndex }:${ ELEMENTS.footnoteReference }` )
|
||||
) {
|
||||
return;
|
||||
|
@ -11,7 +11,7 @@ import { defineSchema } from './schema.js';
|
||||
import { ATTRIBUTES, COMMANDS, ELEMENTS } from '../constants.js';
|
||||
import InsertFootnoteCommand from '../insert-footnote-command.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 {
|
||||
|
||||
@ -26,7 +26,7 @@ export default class FootnoteEditing extends Plugin {
|
||||
/**
|
||||
* The root element of the document.
|
||||
*/
|
||||
public get rootElement(): RootElement {
|
||||
public get rootElement(): ModelRootElement {
|
||||
const rootElement = this.editor.model.document.getRoot();
|
||||
if ( !rootElement ) {
|
||||
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 ) {
|
||||
const { attributeNewValue: newFootnoteIndex } = diffItem;
|
||||
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 ) {
|
||||
return;
|
||||
}
|
||||
@ -143,7 +143,7 @@ export default class FootnoteEditing extends Plugin {
|
||||
* batch these changes with the ones that instantiated them,
|
||||
* 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 );
|
||||
modelWriter.appendElement( 'paragraph', footnoteContent );
|
||||
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
|
||||
* 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,
|
||||
// and renumber subsequent footnotes.
|
||||
if ( !this.editor ) {
|
||||
@ -185,7 +185,7 @@ export default class FootnoteEditing extends Plugin {
|
||||
// immediately deletes the footnote. This deliberately sets the new selection position
|
||||
// to avoid that.
|
||||
const neighborFootnote = index === 0 ? footnoteSection.getChild( index ) : footnoteSection.getChild( ( index ?? 0 ) - 1 );
|
||||
if ( !( neighborFootnote instanceof Element ) ) {
|
||||
if ( !( neighborFootnote instanceof ModelElement ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -212,7 +212,7 @@ export default class FootnoteEditing extends Plugin {
|
||||
* 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.
|
||||
*/
|
||||
private _removeReferences( modelWriter: Writer, footnoteId: string | undefined = undefined ) {
|
||||
private _removeReferences( modelWriter: ModelWriter, footnoteId: string | undefined = undefined ) {
|
||||
const removeList: Array<any> = [];
|
||||
if ( !this.rootElement ) {
|
||||
throw new Error( 'Document has no root element.' );
|
||||
|
@ -1,5 +1,5 @@
|
||||
// eslint-disable-next-line no-restricted-imports
|
||||
import { Schema } from 'ckeditor5';
|
||||
import { ModelSchema } from 'ckeditor5';
|
||||
import { ATTRIBUTES, ELEMENTS } from '../constants.js';
|
||||
|
||||
/**
|
||||
@ -7,7 +7,7 @@ import { ATTRIBUTES, ELEMENTS } from '../constants.js';
|
||||
* See here for the meanings of each rule:
|
||||
* 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.
|
||||
*/
|
||||
|
@ -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 { 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.
|
||||
*/
|
||||
private _getFootnoteSection( writer: Writer, rootElement: RootElement ): Element {
|
||||
private _getFootnoteSection( writer: ModelWriter, rootElement: ModelRootElement ): ModelElement {
|
||||
const footnoteSection = modelQueryElement( this.editor, rootElement, element =>
|
||||
element.is( 'element', ELEMENTS.footnoteSection )
|
||||
);
|
||||
|
@ -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
|
||||
// polymorphism without full typescript is just incredibly finicky.
|
||||
@ -11,14 +11,14 @@ import { type Editor, Element, Text, TextProxy, ViewElement } from 'ckeditor5';
|
||||
*/
|
||||
export const modelQueryElementsAll = (
|
||||
editor: Editor,
|
||||
rootElement: Element,
|
||||
predicate: ( item: Element ) => boolean = _ => true
|
||||
): Array<Element> => {
|
||||
rootElement: ModelElement,
|
||||
predicate: ( item: ModelElement ) => boolean = _ => true
|
||||
): Array<ModelElement> => {
|
||||
const range = editor.model.createRangeIn( rootElement );
|
||||
const output: Array<Element> = [];
|
||||
const output: Array<ModelElement> = [];
|
||||
|
||||
for ( const item of range.getItems() ) {
|
||||
if ( !( item instanceof Element ) ) {
|
||||
if ( !( item instanceof ModelElement ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -35,14 +35,14 @@ export const modelQueryElementsAll = (
|
||||
*/
|
||||
export const modelQueryTextAll = (
|
||||
editor: Editor,
|
||||
rootElement: Element,
|
||||
predicate: ( item: Text | TextProxy ) => boolean = _ => true
|
||||
): Array<Text | TextProxy> => {
|
||||
rootElement: ModelElement,
|
||||
predicate: ( item: ModelText | ModelTextProxy ) => boolean = _ => true
|
||||
): Array<ModelText | ModelTextProxy> => {
|
||||
const range = editor.model.createRangeIn( rootElement );
|
||||
const output: Array<Text | TextProxy> = [];
|
||||
const output: Array<ModelText | ModelTextProxy> = [];
|
||||
|
||||
for ( const item of range.getItems() ) {
|
||||
if ( !( item instanceof Text || item instanceof TextProxy ) ) {
|
||||
if ( !( item instanceof ModelText || item instanceof ModelTextProxy ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -59,13 +59,13 @@ export const modelQueryTextAll = (
|
||||
*/
|
||||
export const modelQueryElement = (
|
||||
editor: Editor,
|
||||
rootElement: Element,
|
||||
predicate: ( item: Element ) => boolean = _ => true
|
||||
): Element | null => {
|
||||
rootElement: ModelElement,
|
||||
predicate: ( item: ModelElement ) => boolean = _ => true
|
||||
): ModelElement | null => {
|
||||
const range = editor.model.createRangeIn( rootElement );
|
||||
|
||||
for ( const item of range.getItems() ) {
|
||||
if ( !( item instanceof Element ) ) {
|
||||
if ( !( item instanceof ModelElement ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -82,13 +82,13 @@ export const modelQueryElement = (
|
||||
*/
|
||||
export const modelQueryText = (
|
||||
editor: Editor,
|
||||
rootElement: Element,
|
||||
predicate: ( item: Text | TextProxy ) => boolean = _ => true
|
||||
): Text | TextProxy | null => {
|
||||
rootElement: ModelElement,
|
||||
predicate: ( item: ModelText | ModelTextProxy ) => boolean = _ => true
|
||||
): ModelText | ModelTextProxy | null => {
|
||||
const range = editor.model.createRangeIn( rootElement );
|
||||
|
||||
for ( const item of range.getItems() ) {
|
||||
if ( !( item instanceof Text || item instanceof TextProxy ) ) {
|
||||
if ( !( item instanceof ModelText || item instanceof ModelTextProxy ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@
|
||||
"@typescript-eslint/parser": "^8.0.0",
|
||||
"@vitest/browser": "^3.0.5",
|
||||
"@vitest/coverage-istanbul": "^3.0.5",
|
||||
"ckeditor5": "45.2.1",
|
||||
"ckeditor5": "46.0.0",
|
||||
"eslint": "^9.0.0",
|
||||
"eslint-config-ckeditor5": ">=9.1.0",
|
||||
"http-server": "^14.1.0",
|
||||
@ -56,7 +56,7 @@
|
||||
"webdriverio": "^9.0.7"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"ckeditor5": "45.2.1"
|
||||
"ckeditor5": "46.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "node ./scripts/build-dist.mjs",
|
||||
|
@ -43,7 +43,7 @@
|
||||
"@typescript-eslint/parser": "^8.0.0",
|
||||
"@vitest/browser": "^3.0.5",
|
||||
"@vitest/coverage-istanbul": "^3.0.5",
|
||||
"ckeditor5": "45.2.1",
|
||||
"ckeditor5": "46.0.0",
|
||||
"eslint": "^9.0.0",
|
||||
"eslint-config-ckeditor5": ">=9.1.0",
|
||||
"http-server": "^14.1.0",
|
||||
@ -57,7 +57,7 @@
|
||||
"webdriverio": "^9.0.7"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"ckeditor5": "45.2.1"
|
||||
"ckeditor5": "46.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "node ./scripts/build-dist.mjs",
|
||||
@ -90,6 +90,6 @@
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"@ckeditor/ckeditor5-icons": "45.2.1"
|
||||
"@ckeditor/ckeditor5-icons": "46.0.0"
|
||||
}
|
||||
}
|
||||
|
@ -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';
|
||||
|
||||
export default class AutoMath extends Plugin {
|
||||
@ -11,7 +11,7 @@ export default class AutoMath extends Plugin {
|
||||
}
|
||||
|
||||
private _timeoutId: null | number;
|
||||
private _positionToInsert: null | LivePosition;
|
||||
private _positionToInsert: null | ModelLivePosition;
|
||||
|
||||
constructor( editor: Editor ) {
|
||||
super( editor );
|
||||
@ -31,10 +31,10 @@ export default class AutoMath extends Plugin {
|
||||
return;
|
||||
}
|
||||
|
||||
const leftLivePosition = LivePosition.fromPosition( firstRange.start );
|
||||
const leftLivePosition = ModelLivePosition.fromPosition( firstRange.start );
|
||||
leftLivePosition.stickiness = 'toPrevious';
|
||||
|
||||
const rightLivePosition = LivePosition.fromPosition( firstRange.end );
|
||||
const rightLivePosition = ModelLivePosition.fromPosition( firstRange.end );
|
||||
rightLivePosition.stickiness = 'toNext';
|
||||
|
||||
modelDocument.once( 'change:data', () => {
|
||||
@ -63,15 +63,15 @@ export default class AutoMath extends Plugin {
|
||||
}
|
||||
|
||||
private _mathBetweenPositions(
|
||||
leftPosition: LivePosition,
|
||||
rightPosition: LivePosition
|
||||
leftPosition: ModelLivePosition,
|
||||
rightPosition: ModelLivePosition
|
||||
) {
|
||||
const editor = this.editor;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
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 } );
|
||||
|
||||
let text = '';
|
||||
@ -97,7 +97,7 @@ export default class AutoMath extends Plugin {
|
||||
return;
|
||||
}
|
||||
|
||||
this._positionToInsert = LivePosition.fromPosition( leftPosition );
|
||||
this._positionToInsert = ModelLivePosition.fromPosition( leftPosition );
|
||||
|
||||
// With timeout user can undo conversation if want use plain text
|
||||
this._timeoutId = window.setTimeout( () => {
|
||||
@ -106,7 +106,7 @@ export default class AutoMath extends Plugin {
|
||||
|
||||
writer.remove( equationRange );
|
||||
|
||||
let insertPosition: LivePosition | null;
|
||||
let insertPosition: ModelLivePosition | null;
|
||||
|
||||
// Check if position where the math element should be inserted is still valid.
|
||||
if ( this._positionToInsert?.root.rootName !== '$graveyard' ) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
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';
|
||||
|
||||
export default class MathEditing extends Plugin {
|
||||
@ -211,8 +211,8 @@ export default class MathEditing extends Plugin {
|
||||
|
||||
// Create view for editor
|
||||
function createMathtexEditingView(
|
||||
modelItem: Element,
|
||||
writer: DowncastWriter
|
||||
modelItem: ModelElement,
|
||||
writer: ViewDowncastWriter
|
||||
) {
|
||||
const equation = String( modelItem.getAttribute( 'equation' ) );
|
||||
const display = !!modelItem.getAttribute( 'display' );
|
||||
@ -261,8 +261,8 @@ export default class MathEditing extends Plugin {
|
||||
|
||||
// Create view for data
|
||||
function createMathtexView(
|
||||
modelItem: Element,
|
||||
{ writer }: { writer: DowncastWriter }
|
||||
modelItem: ModelElement,
|
||||
{ writer }: { writer: ViewDowncastWriter }
|
||||
) {
|
||||
const equation = modelItem.getAttribute( 'equation' );
|
||||
if ( typeof equation != 'string' ) {
|
||||
|
@ -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 type { KatexOptions, MathJax2, MathJax3 } from './typings-external.js';
|
||||
|
||||
export function getSelectedMathModelWidget(
|
||||
selection: DocumentSelection
|
||||
): null | CKElement {
|
||||
selection: ModelDocumentSelection
|
||||
): null | ModelElement {
|
||||
const selectedElement = selection.getSelectedElement();
|
||||
|
||||
if (
|
||||
|
@ -42,7 +42,7 @@
|
||||
"@typescript-eslint/parser": "^8.0.0",
|
||||
"@vitest/browser": "^3.0.5",
|
||||
"@vitest/coverage-istanbul": "^3.0.5",
|
||||
"ckeditor5": "45.2.1",
|
||||
"ckeditor5": "46.0.0",
|
||||
"eslint": "^9.0.0",
|
||||
"eslint-config-ckeditor5": ">=9.1.0",
|
||||
"http-server": "^14.1.0",
|
||||
@ -56,7 +56,7 @@
|
||||
"webdriverio": "^9.0.7"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"ckeditor5": "45.2.1"
|
||||
"ckeditor5": "46.0.0"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "node ./scripts/build-dist.mjs",
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { checkIsOn } from '../utils.js';
|
||||
import { Command, Element } from 'ckeditor5';
|
||||
import { Command, ModelElement } from 'ckeditor5';
|
||||
|
||||
/**
|
||||
* The mermaid preview command.
|
||||
@ -27,7 +27,7 @@ export default class MermaidPreviewCommand extends Command {
|
||||
const editor = this.editor;
|
||||
const model = editor.model;
|
||||
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) {
|
||||
model.change( writer => {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { checkIsOn } from '../utils.js';
|
||||
import { Command, Element } from 'ckeditor5';
|
||||
import { Command, ModelElement } from 'ckeditor5';
|
||||
|
||||
/**
|
||||
* The mermaid source view command.
|
||||
@ -29,7 +29,7 @@ export default class MermaidSourceViewCommand extends Command {
|
||||
const editor = this.editor;
|
||||
const model = editor.model;
|
||||
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 => {
|
||||
if ( mermaidItem.getAttribute( 'displayMode' ) !== 'source' ) {
|
||||
|
@ -3,7 +3,7 @@
|
||||
*/
|
||||
|
||||
import { checkIsOn } from '../utils.js';
|
||||
import { Command, Element } from 'ckeditor5';
|
||||
import { Command, ModelElement } from 'ckeditor5';
|
||||
|
||||
/**
|
||||
* The mermaid split view command.
|
||||
@ -31,7 +31,7 @@ export default class MermaidSplitViewCommand extends Command {
|
||||
const editor = this.editor;
|
||||
const model = editor.model;
|
||||
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 => {
|
||||
if ( mermaidItem.getAttribute( 'displayMode' ) !== 'split' ) {
|
||||
|
@ -8,7 +8,7 @@ import MermaidPreviewCommand from './commands/mermaidPreviewCommand.js';
|
||||
import MermaidSourceViewCommand from './commands/mermaidSourceViewCommand.js';
|
||||
import MermaidSplitViewCommand from './commands/mermaidSplitViewCommand.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.
|
||||
const DEBOUNCE_TIME = 300;
|
||||
@ -95,7 +95,7 @@ export default class MermaidEditing extends Plugin {
|
||||
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
|
||||
// multiple markdown converters that we have seen are using only `language-mermaid` class and not `mermaid` alone.
|
||||
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( pre, 'end' ) as any, code );
|
||||
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 ) {
|
||||
@ -122,7 +122,7 @@ export default class MermaidEditing extends Plugin {
|
||||
return;
|
||||
}
|
||||
|
||||
const targetViewPosition = mapper.toViewPosition( model.createPositionBefore( data.item as Item ) );
|
||||
const targetViewPosition = mapper.toViewPosition( model.createPositionBefore( data.item as ModelItem ) );
|
||||
|
||||
const wrapperAttributes = {
|
||||
class: [ 'ck-mermaid__wrapper' ]
|
||||
@ -144,7 +144,7 @@ export default class MermaidEditing extends Plugin {
|
||||
|
||||
writer.insert( targetViewPosition, wrapper );
|
||||
|
||||
mapper.bindElements( data.item as Element, wrapper );
|
||||
mapper.bindElements( data.item as ModelElement, wrapper );
|
||||
|
||||
return toWidget( wrapper, writer, {
|
||||
label: t( 'Mermaid widget' ),
|
||||
@ -158,7 +158,7 @@ export default class MermaidEditing extends Plugin {
|
||||
|
||||
const debouncedListener = debounce( event => {
|
||||
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 );
|
||||
|
||||
@ -171,7 +171,7 @@ export default class MermaidEditing extends Plugin {
|
||||
|
||||
// Move the selection onto the mermaid widget if it's currently not selected.
|
||||
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 );
|
||||
|
||||
@ -200,7 +200,7 @@ export default class MermaidEditing extends Plugin {
|
||||
const domConverter = this.editor.editing.view.domConverter;
|
||||
|
||||
if ( newSource ) {
|
||||
const mermaidView = conversionApi.mapper.toViewElement( data.item as Element );
|
||||
const mermaidView = conversionApi.mapper.toViewElement( data.item as ModelElement );
|
||||
if (!mermaidView) {
|
||||
return;
|
||||
}
|
||||
@ -208,7 +208,7 @@ export default class MermaidEditing extends Plugin {
|
||||
for ( const _child of mermaidView.getChildren() ) {
|
||||
const child = _child as ViewElement;
|
||||
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;
|
||||
|
||||
if ( domEditingTextarea.value != newSource ) {
|
||||
|
@ -7,7 +7,7 @@ import previewModeIcon from '../theme/icons/preview-mode.svg';
|
||||
import splitModeIcon from '../theme/icons/split-mode.svg';
|
||||
import sourceModeIcon from '../theme/icons/source-mode.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';
|
||||
|
||||
/* global window, document */
|
||||
@ -69,7 +69,7 @@ export default class MermaidUI extends Plugin {
|
||||
|
||||
// Execute the command when the button is clicked.
|
||||
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 );
|
||||
|
||||
view.scrollToTheSelection();
|
||||
|
@ -35,8 +35,8 @@
|
||||
"@triliumnext/ckeditor5-keyboard-marker": "workspace:*",
|
||||
"@triliumnext/ckeditor5-math": "workspace:*",
|
||||
"@triliumnext/ckeditor5-mermaid": "workspace:*",
|
||||
"ckeditor5": "45.2.1",
|
||||
"ckeditor5-premium-features": "45.2.1"
|
||||
"ckeditor5": "46.0.0",
|
||||
"ckeditor5-premium-features": "46.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jquery": "3.5.32"
|
||||
|
@ -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, ModelNode, ModelPosition, ModelElement, WatchdogConfig } from "ckeditor5";
|
||||
export type { TemplateDefinition } from "ckeditor5-premium-features";
|
||||
export { default as buildExtraCommands } from "./extra_slash_commands.js";
|
||||
|
||||
|
@ -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 {
|
||||
file: File[];
|
||||
@ -34,7 +34,7 @@ export default class FileUploadCommand extends Command {
|
||||
/**
|
||||
* 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 );
|
||||
|
||||
// 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 );
|
||||
}
|
||||
|
||||
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 );
|
||||
model.insertContent( placeholder, model.document.selection );
|
||||
writer.insertText( ' ', placeholder, 'after' );
|
||||
|
@ -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';
|
||||
|
||||
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 ) => {
|
||||
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 => {
|
||||
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 model = editor.model;
|
||||
const t = editor.locale.t;
|
||||
@ -195,7 +195,7 @@ export default class FileUploadEditing extends Plugin {
|
||||
|
||||
function fetchLocalFile( link: ViewItem ) {
|
||||
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( href )
|
||||
@ -250,7 +250,7 @@ export function isHtmlIncluded( dataTransfer: DataTransfer ) {
|
||||
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 ) )
|
||||
.filter( value => value.item.hasAttribute( 'href' ) )
|
||||
.map( value => value.item );
|
||||
|
@ -2,7 +2,7 @@
|
||||
* 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 {
|
||||
|
||||
@ -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: ModelPosition | ModelElement | ModelDocumentFragment | null = this.editor.model.document.selection.getFirstPosition();
|
||||
|
||||
while (el) {
|
||||
if ("name" in el && el.name === 'tableCell') {
|
||||
|
@ -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):
|
||||
@ -31,7 +31,7 @@ interface MentionOpts {
|
||||
};
|
||||
marker: string;
|
||||
text?: string;
|
||||
range?: Range;
|
||||
range?: ModelRange;
|
||||
}
|
||||
|
||||
interface MentionAttribute {
|
||||
@ -48,7 +48,7 @@ class CustomMentionCommand extends Command {
|
||||
const {document} = model;
|
||||
const {selection} = document;
|
||||
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('~')) {
|
||||
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;
|
||||
|
||||
model.change(writer => {
|
||||
|
@ -2,7 +2,7 @@
|
||||
* 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 {
|
||||
|
||||
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): ModelNode | null;
|
||||
abstract get offset(): "before" | "after";
|
||||
|
||||
override execute() {
|
||||
@ -81,7 +81,7 @@ abstract class MoveBlockUpDownCommand extends Command {
|
||||
}
|
||||
|
||||
// Restore selection
|
||||
let range: Range;
|
||||
let range: ModelRange;
|
||||
const maxStart = firstBlock.maxOffset ?? startOffset;
|
||||
const maxEnd = lastBlock.maxOffset ?? endOffset;
|
||||
// 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 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,10 +1,10 @@
|
||||
import type { Element, Position, Writer } from "ckeditor5";
|
||||
import type { Node, Editor } from "ckeditor5";
|
||||
import type { ModelElement, ModelPosition, ModelWriter } from "ckeditor5";
|
||||
import type { ModelNode, Editor } from "ckeditor5";
|
||||
import { Plugin } from "ckeditor5";
|
||||
|
||||
interface SpanStackEntry {
|
||||
className: string;
|
||||
posStart: Position;
|
||||
posStart: ModelPosition;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -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 | ModelNode) {
|
||||
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: ModelWriter) {
|
||||
log("highlighting codeblock " + JSON.stringify(codeBlock.toJSON()));
|
||||
const model = codeBlock.root.document?.model;
|
||||
if (!model) {
|
||||
@ -242,7 +242,7 @@ export default class SyntaxHighlighting extends Plugin {
|
||||
let spanStack: SpanStackEntry[] = [];
|
||||
let iChild = -1;
|
||||
let childText = "";
|
||||
let child: Node | null = null;
|
||||
let child: ModelNode | null = null;
|
||||
let iChildText = 0;
|
||||
|
||||
while (iHtml < html.length) {
|
||||
|
3784
pnpm-lock.yaml
generated
3784
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user