Notes/packages/ckeditor5-math/src/mathcommand.ts

65 lines
1.9 KiB
TypeScript
Raw Normal View History

import { Command } from 'ckeditor5';
import { getSelectedMathModelWidget } from './utils.js';
2024-03-14 21:33:24 -03:00
export default class MathCommand extends Command {
chore: Add override for methods ERROR in ckeditor5-math/src/mathcommand.ts ./src/mathcommand.ts 5:8-13 [tsl] ERROR in ckeditor5-math/src/mathcommand.ts(5,9) TS4114: This member must have an 'override' modifier because it overrides a member in the base class 'Command'. @ ./src/autoformatmath.ts 6:0-40 24:31-42 @ ./src/index.ts 5:0-61 5:0-61 ERROR in ckeditor5-math/src/mathcommand.ts ./src/mathcommand.ts 6:8-15 [tsl] ERROR in ckeditor5-math/src/mathcommand.ts(6,9) TS4114: This member must have an 'override' modifier because it overrides a member in the base class 'Command'. @ ./src/autoformatmath.ts 6:0-40 24:31-42 @ ./src/index.ts 5:0-61 5:0-61 ERROR in ckeditor5-math/src/mathcommand.ts ./src/mathcommand.ts 48:8-15 [tsl] ERROR in ckeditor5-math/src/mathcommand.ts(48,9) TS4114: This member must have an 'override' modifier because it overrides a member in the base class 'Command'. @ ./src/autoformatmath.ts 6:0-40 24:31-42 @ ./src/index.ts 5:0-61 5:0-61 ERROR in ckeditor5-math/src/mathui.ts ./src/mathui.ts 41:8-15 [tsl] ERROR in ckeditor5-math/src/mathui.ts(41,9) TS4114: This member must have an 'override' modifier because it overrides a member in the base class 'Plugin'. @ ./src/autoformatmath.ts 7:0-30 33:50-56 @ ./src/index.ts 5:0-61 5:0-61 ERROR in ckeditor5-math/src/ui/mainformview.ts ./src/ui/mainformview.ts 40:8-14 [tsl] ERROR in ckeditor5-math/src/ui/mainformview.ts(40,9) TS4114: This member must have an 'override' modifier because it overrides a member in the base class 'View<HTMLElement>'. @ ./src/mathui.ts 2:0-45 61:29-41 @ ./src/autoformatmath.ts 7:0-30 33:50-56 @ ./src/index.ts 5:0-61 5:0-61 ERROR in ckeditor5-math/src/ui/mainformview.ts ./src/ui/mainformview.ts 130:8-14 [tsl] ERROR in ckeditor5-math/src/ui/mainformview.ts(130,9) TS4114: This member must have an 'override' modifier because it overrides a member in the base class 'View<HTMLElement>'. @ ./src/mathui.ts 2:0-45 61:29-41 @ ./src/autoformatmath.ts 7:0-30 33:50-56 @ ./src/index.ts 5:0-61 5:0-61 ERROR in ckeditor5-math/src/ui/mathview.ts ./src/ui/mathview.ts 76:8-14 [tsl] ERROR in ckeditor5-math/src/ui/mathview.ts(76,9) TS4114: This member must have an 'override' modifier because it overrides a member in the base class 'View<HTMLElement>'. @ ./src/ui/mainformview.ts 5:0-34 48:32-40 @ ./src/mathui.ts 2:0-45 61:29-41 @ ./src/autoformatmath.ts 7:0-30 33:50-56 @ ./src/index.ts 5:0-61 5:0-61 7 errors have detailed information that is not shown. Use 'stats.errorDetails: true' resp. '--stats-error-details' to show it.
2024-03-16 05:40:55 -05:00
public override value: string | null = null;
public override execute(
2024-03-14 21:33:24 -03:00
equation: string,
display?: boolean,
outputType: 'script' | 'span' = 'script',
forceOutputType?: boolean
): void {
const model = this.editor.model;
const selection = model.document.selection;
const selectedElement = selection.getSelectedElement();
model.change( writer => {
let mathtex;
if (
selectedElement &&
( selectedElement.is( 'element', 'mathtex-inline' ) ||
selectedElement.is( 'element', 'mathtex-display' ) )
) {
// Update selected element
const typeAttr = selectedElement.getAttribute( 'type' );
// Use already set type if found and is not forced
const type = forceOutputType ?
outputType :
typeAttr || outputType;
mathtex = writer.createElement(
display ? 'mathtex-display' : 'mathtex-inline',
{ equation, type, display }
);
} else {
// Create new model element
mathtex = writer.createElement(
display ? 'mathtex-display' : 'mathtex-inline',
{ equation, type: outputType, display }
);
}
model.insertContent( mathtex );
} );
}
public display = false;
chore: Add override for methods ERROR in ckeditor5-math/src/mathcommand.ts ./src/mathcommand.ts 5:8-13 [tsl] ERROR in ckeditor5-math/src/mathcommand.ts(5,9) TS4114: This member must have an 'override' modifier because it overrides a member in the base class 'Command'. @ ./src/autoformatmath.ts 6:0-40 24:31-42 @ ./src/index.ts 5:0-61 5:0-61 ERROR in ckeditor5-math/src/mathcommand.ts ./src/mathcommand.ts 6:8-15 [tsl] ERROR in ckeditor5-math/src/mathcommand.ts(6,9) TS4114: This member must have an 'override' modifier because it overrides a member in the base class 'Command'. @ ./src/autoformatmath.ts 6:0-40 24:31-42 @ ./src/index.ts 5:0-61 5:0-61 ERROR in ckeditor5-math/src/mathcommand.ts ./src/mathcommand.ts 48:8-15 [tsl] ERROR in ckeditor5-math/src/mathcommand.ts(48,9) TS4114: This member must have an 'override' modifier because it overrides a member in the base class 'Command'. @ ./src/autoformatmath.ts 6:0-40 24:31-42 @ ./src/index.ts 5:0-61 5:0-61 ERROR in ckeditor5-math/src/mathui.ts ./src/mathui.ts 41:8-15 [tsl] ERROR in ckeditor5-math/src/mathui.ts(41,9) TS4114: This member must have an 'override' modifier because it overrides a member in the base class 'Plugin'. @ ./src/autoformatmath.ts 7:0-30 33:50-56 @ ./src/index.ts 5:0-61 5:0-61 ERROR in ckeditor5-math/src/ui/mainformview.ts ./src/ui/mainformview.ts 40:8-14 [tsl] ERROR in ckeditor5-math/src/ui/mainformview.ts(40,9) TS4114: This member must have an 'override' modifier because it overrides a member in the base class 'View<HTMLElement>'. @ ./src/mathui.ts 2:0-45 61:29-41 @ ./src/autoformatmath.ts 7:0-30 33:50-56 @ ./src/index.ts 5:0-61 5:0-61 ERROR in ckeditor5-math/src/ui/mainformview.ts ./src/ui/mainformview.ts 130:8-14 [tsl] ERROR in ckeditor5-math/src/ui/mainformview.ts(130,9) TS4114: This member must have an 'override' modifier because it overrides a member in the base class 'View<HTMLElement>'. @ ./src/mathui.ts 2:0-45 61:29-41 @ ./src/autoformatmath.ts 7:0-30 33:50-56 @ ./src/index.ts 5:0-61 5:0-61 ERROR in ckeditor5-math/src/ui/mathview.ts ./src/ui/mathview.ts 76:8-14 [tsl] ERROR in ckeditor5-math/src/ui/mathview.ts(76,9) TS4114: This member must have an 'override' modifier because it overrides a member in the base class 'View<HTMLElement>'. @ ./src/ui/mainformview.ts 5:0-34 48:32-40 @ ./src/mathui.ts 2:0-45 61:29-41 @ ./src/autoformatmath.ts 7:0-30 33:50-56 @ ./src/index.ts 5:0-61 5:0-61 7 errors have detailed information that is not shown. Use 'stats.errorDetails: true' resp. '--stats-error-details' to show it.
2024-03-16 05:40:55 -05:00
public override refresh(): void {
2024-03-14 21:33:24 -03:00
const model = this.editor.model;
const selection = model.document.selection;
const selectedElement = selection.getSelectedElement();
this.isEnabled =
selectedElement === null ||
selectedElement.is( 'element', 'mathtex-inline' ) ||
selectedElement.is( 'element', 'mathtex-display' );
const selectedEquation = getSelectedMathModelWidget( selection );
const value = selectedEquation?.getAttribute( 'equation' );
this.value = typeof value === 'string' ? value : null;
const display = selectedEquation?.getAttribute( 'display' );
this.display = typeof display === 'boolean' ? display : false;
}
}