diff --git a/packages/ckeditor5-footnotes/src/footnote-editing/auto-formatting.ts b/packages/ckeditor5-footnotes/src/footnote-editing/auto-formatting.ts index 2cb586f48..a4ecee2db 100644 --- a/packages/ckeditor5-footnotes/src/footnote-editing/auto-formatting.ts +++ b/packages/ckeditor5-footnotes/src/footnote-editing/auto-formatting.ts @@ -1,4 +1,4 @@ -import { type Editor, ModelText, ModelTextProxy, type Element, type Range, type Autoformat, inlineAutoformatEditing } from 'ckeditor5'; +import { type Editor, ModelText, ModelTextProxy, type ModelElement, type Range, type Autoformat, inlineAutoformatEditing } from 'ckeditor5'; import { COMMANDS, ELEMENTS } from '../constants.js'; import { modelQueryElement, modelQueryElementsAll } from '../utils.js'; @@ -68,7 +68,7 @@ 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, editor: Editor, rootElement: Element ): boolean | undefined => { +const formatCallback = ( ranges: Array, editor: Editor, rootElement: ModelElement ): boolean | undefined => { const command = editor.commands.get( COMMANDS.insertFootnote ); if ( !command || !command.isEnabled ) { return; @@ -108,7 +108,7 @@ const formatCallback = ( ranges: Array, 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( diff --git a/packages/ckeditor5-footnotes/src/footnote-editing/converters.ts b/packages/ckeditor5-footnotes/src/footnote-editing/converters.ts index 30d2eeecd..48b6e653b 100644 --- a/packages/ckeditor5-footnotes/src/footnote-editing/converters.ts +++ b/packages/ckeditor5-footnotes/src/footnote-editing/converters.ts @@ -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; diff --git a/packages/ckeditor5-footnotes/src/footnote-editing/footnote-editing.ts b/packages/ckeditor5-footnotes/src/footnote-editing/footnote-editing.ts index 80649e59d..8d71ac4da 100644 --- a/packages/ckeditor5-footnotes/src/footnote-editing/footnote-editing.ts +++ b/packages/ckeditor5-footnotes/src/footnote-editing/footnote-editing.ts @@ -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, ModelRootElement, viewToModelPositionOutsideModelElement, Widget, Writer } from 'ckeditor5'; +import { Autoformat, Batch, ModelElement, Plugin, ModelRootElement, viewToModelPositionOutsideModelElement, Widget, Writer } from 'ckeditor5'; export default class FootnoteEditing extends Plugin { @@ -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: Writer, 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: Writer, 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; } diff --git a/packages/ckeditor5-footnotes/src/insert-footnote-command.ts b/packages/ckeditor5-footnotes/src/insert-footnote-command.ts index 850236ad8..ec7e2a619 100644 --- a/packages/ckeditor5-footnotes/src/insert-footnote-command.ts +++ b/packages/ckeditor5-footnotes/src/insert-footnote-command.ts @@ -1,4 +1,4 @@ -import { Command, type Element, type ModelRootElement, type Writer } from "ckeditor5"; +import { Command, type ModelElement, type ModelRootElement, type Writer } 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: ModelRootElement ): Element { + private _getFootnoteSection( writer: Writer, rootElement: ModelRootElement ): ModelElement { const footnoteSection = modelQueryElement( this.editor, rootElement, element => element.is( 'element', ELEMENTS.footnoteSection ) ); diff --git a/packages/ckeditor5-footnotes/src/utils.ts b/packages/ckeditor5-footnotes/src/utils.ts index 8c6b4a4c9..43dee0936 100644 --- a/packages/ckeditor5-footnotes/src/utils.ts +++ b/packages/ckeditor5-footnotes/src/utils.ts @@ -1,4 +1,4 @@ -import { type Editor, Element, ModelText, ModelTextProxy, 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, ModelText, ModelTextProxy, ViewElement } from 'ck */ export const modelQueryElementsAll = ( editor: Editor, - rootElement: Element, - predicate: ( item: Element ) => boolean = _ => true -): Array => { + rootElement: ModelElement, + predicate: ( item: ModelElement ) => boolean = _ => true +): Array => { const range = editor.model.createRangeIn( rootElement ); - const output: Array = []; + const output: Array = []; for ( const item of range.getItems() ) { - if ( !( item instanceof Element ) ) { + if ( !( item instanceof ModelElement ) ) { continue; } @@ -35,7 +35,7 @@ export const modelQueryElementsAll = ( */ export const modelQueryTextAll = ( editor: Editor, - rootElement: Element, + rootElement: ModelElement, predicate: ( item: ModelText | ModelTextProxy ) => boolean = _ => true ): Array => { const range = editor.model.createRangeIn( rootElement ); @@ -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,7 +82,7 @@ export const modelQueryElement = ( */ export const modelQueryText = ( editor: Editor, - rootElement: Element, + rootElement: ModelElement, predicate: ( item: ModelText | ModelTextProxy ) => boolean = _ => true ): ModelText | ModelTextProxy | null => { const range = editor.model.createRangeIn( rootElement );