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

This commit is contained in:
Elian Doran 2025-07-12 19:24:39 +03:00
parent b4f2be332b
commit 70eece1429
No known key found for this signature in database
5 changed files with 12 additions and 12 deletions

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, Item, Node, Plugin, toWidget, UpcastConversionApi, UpcastConversionData, ViewElement, ViewText, ViewUIElement } from 'ckeditor5';
// Time in milliseconds. // Time in milliseconds.
const DEBOUNCE_TIME = 300; const DEBOUNCE_TIME = 300;
@ -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 ) {
@ -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' ),
@ -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;
} }

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();