From 5d42b942baaaf7bfb3d27d6bd533cc347445e35c Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sun, 4 May 2025 22:16:32 +0300 Subject: [PATCH] chore(ckeditor5-math): integrate source code --- _regroup/ckeditor5-math/src/augmentation.ts | 37 ----------------- _regroup/ckeditor5-math/src/index.ts | 8 ---- _regroup/ckeditor5-math/src/math.ts | 16 -------- _regroup/ckeditor5-math/typings/svg.d.ts | 4 -- packages/ckeditor5-math/src/augmentation.ts | 30 +++++++++++++- .../ckeditor5-math/src/autoformatmath.ts | 10 ++--- .../ckeditor5-math/src/automath.ts | 12 ++---- packages/ckeditor5-math/src/index.ts | 2 + packages/ckeditor5-math/src/math.ts | 41 ++++--------------- .../ckeditor5-math/src/mathcommand.ts | 4 +- .../ckeditor5-math/src/mathediting.ts | 13 ++---- .../ckeditor5-math/src/mathui.ts | 17 +++----- .../ckeditor5-math/src/typings-external.ts | 0 .../ckeditor5-math/src/ui/mainformview.ts | 22 ++-------- .../ckeditor5-math/src/ui/mathview.ts | 7 ++-- .../ckeditor5-math/src/utils.ts | 11 ++--- .../ckeditor5-math/theme/icons/ckeditor.svg | 1 - .../ckeditor5-math/theme/icons/math.svg | 0 .../ckeditor5-math/theme/mathform.css | 0 19 files changed, 67 insertions(+), 168 deletions(-) delete mode 100644 _regroup/ckeditor5-math/src/augmentation.ts delete mode 100644 _regroup/ckeditor5-math/src/index.ts delete mode 100644 _regroup/ckeditor5-math/src/math.ts delete mode 100644 _regroup/ckeditor5-math/typings/svg.d.ts rename {_regroup => packages}/ckeditor5-math/src/autoformatmath.ts (82%) rename {_regroup => packages}/ckeditor5-math/src/automath.ts (90%) rename {_regroup => packages}/ckeditor5-math/src/mathcommand.ts (94%) rename {_regroup => packages}/ckeditor5-math/src/mathediting.ts (95%) rename {_regroup => packages}/ckeditor5-math/src/mathui.ts (94%) rename {_regroup => packages}/ckeditor5-math/src/typings-external.ts (100%) rename {_regroup => packages}/ckeditor5-math/src/ui/mainformview.ts (92%) rename {_regroup => packages}/ckeditor5-math/src/ui/mathview.ts (88%) rename {_regroup => packages}/ckeditor5-math/src/utils.ts (96%) delete mode 100644 packages/ckeditor5-math/theme/icons/ckeditor.svg rename {_regroup => packages}/ckeditor5-math/theme/icons/math.svg (100%) rename {_regroup => packages}/ckeditor5-math/theme/mathform.css (100%) diff --git a/_regroup/ckeditor5-math/src/augmentation.ts b/_regroup/ckeditor5-math/src/augmentation.ts deleted file mode 100644 index cc32187ec..000000000 --- a/_regroup/ckeditor5-math/src/augmentation.ts +++ /dev/null @@ -1,37 +0,0 @@ -import Math from './math'; -import MathCommand from './mathcommand'; -import MathEditing from './mathediting'; -import MathUI from './mathui'; -import type { KatexOptions } from './typings-external'; - -declare module '@ckeditor/ckeditor5-core' { - - interface PluginsMap { - [ Math.pluginName ]: Math; - [ MathEditing.pluginName ]: MathEditing; - [ MathUI.pluginName ]: MathUI; - } - - interface CommandsMap { - math: MathCommand; - } - - interface EditorConfig { - math?: { - engine?: - | 'mathjax' - | 'katex' - | ( ( equation: string, element: HTMLElement, display: boolean ) => void ) - | undefined; - lazyLoad?: undefined | ( () => Promise ); - outputType?: 'script' | 'span' | undefined; - className?: string | undefined; - forceOutputType?: boolean | undefined; - enablePreview?: boolean | undefined; - previewClassName?: Array | undefined; - popupClassName?: Array | undefined; - katexRenderOptions?: Partial | undefined; - }; - } -} - diff --git a/_regroup/ckeditor5-math/src/index.ts b/_regroup/ckeditor5-math/src/index.ts deleted file mode 100644 index 39dc1a626..000000000 --- a/_regroup/ckeditor5-math/src/index.ts +++ /dev/null @@ -1,8 +0,0 @@ -/** - * @module math - */ - -export { default as Math } from './math'; -export { default as AutoformatMath } from './autoformatmath'; - -import "./augmentation.js"; diff --git a/_regroup/ckeditor5-math/src/math.ts b/_regroup/ckeditor5-math/src/math.ts deleted file mode 100644 index cfd390fb7..000000000 --- a/_regroup/ckeditor5-math/src/math.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { Plugin } from 'ckeditor5/src/core'; -import { Widget } from 'ckeditor5/src/widget'; - -import MathUI from './mathui'; -import MathEditing from './mathediting'; -import AutoMath from './automath'; - -export default class Math extends Plugin { - public static get requires() { - return [ MathEditing, MathUI, AutoMath, Widget ] as const; - } - - public static get pluginName() { - return 'Math' as const; - } -} diff --git a/_regroup/ckeditor5-math/typings/svg.d.ts b/_regroup/ckeditor5-math/typings/svg.d.ts deleted file mode 100644 index 465793830..000000000 --- a/_regroup/ckeditor5-math/typings/svg.d.ts +++ /dev/null @@ -1,4 +0,0 @@ -declare module '*.svg' { - const src: string; - export default src; -} diff --git a/packages/ckeditor5-math/src/augmentation.ts b/packages/ckeditor5-math/src/augmentation.ts index 17e30041a..855e42133 100644 --- a/packages/ckeditor5-math/src/augmentation.ts +++ b/packages/ckeditor5-math/src/augmentation.ts @@ -1,7 +1,35 @@ -import type { Math } from './index.js'; +import type Math from './math.js'; +import MathCommand from './mathcommand.js'; +import MathEditing from './mathediting.js'; +import MathUI from './mathui.js'; +import { KatexOptions } from './typings-external.js'; declare module 'ckeditor5' { interface PluginsMap { [ Math.pluginName ]: Math; + [ MathEditing.pluginName ]: MathEditing; + [ MathUI.pluginName ]: MathUI; + } + + interface CommandsMap { + math: MathCommand; + } + + interface EditorConfig { + math?: { + engine?: + | 'mathjax' + | 'katex' + | ( ( equation: string, element: HTMLElement, display: boolean ) => void ) + | undefined; + lazyLoad?: undefined | ( () => Promise ); + outputType?: 'script' | 'span' | undefined; + className?: string | undefined; + forceOutputType?: boolean | undefined; + enablePreview?: boolean | undefined; + previewClassName?: Array | undefined; + popupClassName?: Array | undefined; + katexRenderOptions?: Partial | undefined; + }; } } diff --git a/_regroup/ckeditor5-math/src/autoformatmath.ts b/packages/ckeditor5-math/src/autoformatmath.ts similarity index 82% rename from _regroup/ckeditor5-math/src/autoformatmath.ts rename to packages/ckeditor5-math/src/autoformatmath.ts index 3aa7697c4..7ae767928 100644 --- a/_regroup/ckeditor5-math/src/autoformatmath.ts +++ b/packages/ckeditor5-math/src/autoformatmath.ts @@ -1,10 +1,8 @@ -import { Plugin } from 'ckeditor5/src/core'; -import { global, logWarning } from 'ckeditor5/src/utils'; +import { Plugin, logWarning, blockAutoformatEditing } from 'ckeditor5'; // eslint-disable-next-line ckeditor5-rules/allow-imports-only-from-main-package-entry-point -import blockAutoformatEditing from '@ckeditor/ckeditor5-autoformat/src/blockautoformatediting'; -import Math from './math'; -import MathCommand from './mathcommand'; -import MathUI from './mathui'; +import Math from './math.js'; +import MathCommand from './mathcommand.js'; +import MathUI from './mathui.js'; export default class AutoformatMath extends Plugin { public static get requires() { diff --git a/_regroup/ckeditor5-math/src/automath.ts b/packages/ckeditor5-math/src/automath.ts similarity index 90% rename from _regroup/ckeditor5-math/src/automath.ts rename to packages/ckeditor5-math/src/automath.ts index e8eb5e9c1..bf16eacae 100644 --- a/_regroup/ckeditor5-math/src/automath.ts +++ b/packages/ckeditor5-math/src/automath.ts @@ -1,9 +1,5 @@ -import { Clipboard } from 'ckeditor5/src/clipboard'; -import { Plugin, type Editor } from 'ckeditor5/src/core'; -import { LivePosition, LiveRange } from 'ckeditor5/src/engine'; -import { Undo } from 'ckeditor5/src/undo'; -import { global } from 'ckeditor5/src/utils'; -import { extractDelimiters, hasDelimiters, delimitersCounts } from './utils'; +import { Clipboard, Plugin, type Editor, LivePosition, LiveRange, Undo } from 'ckeditor5'; +import { extractDelimiters, hasDelimiters, delimitersCounts } from './utils.js'; export default class AutoMath extends Plugin { public static get requires() { @@ -73,7 +69,7 @@ export default class AutoMath extends Plugin { const editor = this.editor; // 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 walker = equationRange.getWalker( { ignoreElementEnd: true } ); @@ -119,7 +115,7 @@ export default class AutoMath extends Plugin { editor.model.change( innerWriter => { const params = Object.assign( extractDelimiters( text ), { - type: mathConfig.outputType + type: mathConfig?.outputType } ); const mathElement = innerWriter.createElement( params.display ? 'mathtex-display' : 'mathtex-inline', params ); diff --git a/packages/ckeditor5-math/src/index.ts b/packages/ckeditor5-math/src/index.ts index 2ce863797..788de3f8a 100644 --- a/packages/ckeditor5-math/src/index.ts +++ b/packages/ckeditor5-math/src/index.ts @@ -1,7 +1,9 @@ import ckeditor from './../theme/icons/ckeditor.svg'; import './augmentation.js'; +import "../theme/mathform.css"; export { default as Math } from './math.js'; +export { default as AutoformatMath } from './autoformatmath.js'; export const icons = { ckeditor diff --git a/packages/ckeditor5-math/src/math.ts b/packages/ckeditor5-math/src/math.ts index 1be018aad..fd9debb65 100644 --- a/packages/ckeditor5-math/src/math.ts +++ b/packages/ckeditor5-math/src/math.ts @@ -1,39 +1,14 @@ -import { Plugin, ButtonView } from 'ckeditor5'; - -import ckeditor5Icon from '../theme/icons/ckeditor.svg'; +import { Plugin, Widget } from 'ckeditor5'; +import MathEditing from './mathediting.js'; +import MathUI from './mathui.js'; +import AutoMath from './automath.js'; export default class Math extends Plugin { + public static get requires() { + return [ MathEditing, MathUI, AutoMath, Widget ] as const; + } + public static get pluginName() { return 'Math' as const; } - - public init(): void { - const editor = this.editor; - const t = editor.t; - const model = editor.model; - - // Register the "math" button, so it can be displayed in the toolbar. - editor.ui.componentFactory.add( 'math', locale => { - const view = new ButtonView( locale ); - - view.set( { - label: t( 'Math' ), - icon: ckeditor5Icon, - tooltip: true - } ); - - // Insert a text into the editor after clicking the button. - this.listenTo( view, 'execute', () => { - model.change( writer => { - const textNode = writer.createText( 'Hello CKEditor 5!' ); - - model.insertContent( textNode ); - } ); - - editor.editing.view.focus(); - } ); - - return view; - } ); - } } diff --git a/_regroup/ckeditor5-math/src/mathcommand.ts b/packages/ckeditor5-math/src/mathcommand.ts similarity index 94% rename from _regroup/ckeditor5-math/src/mathcommand.ts rename to packages/ckeditor5-math/src/mathcommand.ts index 5a8dbbe9f..63671f437 100644 --- a/_regroup/ckeditor5-math/src/mathcommand.ts +++ b/packages/ckeditor5-math/src/mathcommand.ts @@ -1,5 +1,5 @@ -import { Command } from 'ckeditor5/src/core'; -import { getSelectedMathModelWidget } from './utils'; +import { Command } from 'ckeditor5'; +import { getSelectedMathModelWidget } from './utils.js'; export default class MathCommand extends Command { public override value: string | null = null; diff --git a/_regroup/ckeditor5-math/src/mathediting.ts b/packages/ckeditor5-math/src/mathediting.ts similarity index 95% rename from _regroup/ckeditor5-math/src/mathediting.ts rename to packages/ckeditor5-math/src/mathediting.ts index 83a87e1ab..bfd08ed37 100644 --- a/_regroup/ckeditor5-math/src/mathediting.ts +++ b/packages/ckeditor5-math/src/mathediting.ts @@ -1,13 +1,6 @@ -import MathCommand from './mathcommand'; -import { type Editor, Plugin } from 'ckeditor5/src/core'; -import { - toWidget, - Widget, - viewToModelPositionOutsideModelElement -} from 'ckeditor5/src/widget'; -import { renderEquation, extractDelimiters } from './utils'; -import type { DowncastWriter, Element } from 'ckeditor5/src/engine'; -import { CKEditorError, uid } from 'ckeditor5/src/utils'; +import MathCommand from './mathcommand.js'; +import { type Editor, Plugin, toWidget, Widget, viewToModelPositionOutsideModelElement, type DowncastWriter, type Element, CKEditorError, uid } from 'ckeditor5'; +import { renderEquation, extractDelimiters } from './utils.js'; export default class MathEditing extends Plugin { public static get requires() { diff --git a/_regroup/ckeditor5-math/src/mathui.ts b/packages/ckeditor5-math/src/mathui.ts similarity index 94% rename from _regroup/ckeditor5-math/src/mathui.ts rename to packages/ckeditor5-math/src/mathui.ts index 7cc76f990..f3c86af49 100644 --- a/_regroup/ckeditor5-math/src/mathui.ts +++ b/packages/ckeditor5-math/src/mathui.ts @@ -1,16 +1,9 @@ -import MathEditing from './mathediting'; -import MainFormView from './ui/mainformview'; +import MathEditing from './mathediting.js'; +import MainFormView from './ui/mainformview.js'; import mathIcon from '../theme/icons/math.svg'; -import { Plugin } from 'ckeditor5/src/core'; -import { ClickObserver } from 'ckeditor5/src/engine'; -import { - ButtonView, - ContextualBalloon, - clickOutsideHandler -} from 'ckeditor5/src/ui'; -import { CKEditorError, global, uid } from 'ckeditor5/src/utils'; -import { getBalloonPositionData } from './utils'; -import MathCommand from './mathcommand'; +import { Plugin, ClickObserver, ButtonView, ContextualBalloon, clickOutsideHandler, CKEditorError, uid } from 'ckeditor5'; +import { getBalloonPositionData } from './utils.js'; +import MathCommand from './mathcommand.js'; const mathKeystroke = 'Ctrl+M'; diff --git a/_regroup/ckeditor5-math/src/typings-external.ts b/packages/ckeditor5-math/src/typings-external.ts similarity index 100% rename from _regroup/ckeditor5-math/src/typings-external.ts rename to packages/ckeditor5-math/src/typings-external.ts diff --git a/_regroup/ckeditor5-math/src/ui/mainformview.ts b/packages/ckeditor5-math/src/ui/mainformview.ts similarity index 92% rename from _regroup/ckeditor5-math/src/ui/mainformview.ts rename to packages/ckeditor5-math/src/ui/mainformview.ts index 0f302727f..c9cd168c8 100644 --- a/_regroup/ckeditor5-math/src/ui/mainformview.ts +++ b/packages/ckeditor5-math/src/ui/mainformview.ts @@ -1,22 +1,8 @@ -import { icons } from 'ckeditor5/src/core'; -import { - ButtonView, - createLabeledInputText, - FocusCycler, - LabelView, - LabeledFieldView, - submitHandler, - SwitchButtonView, - View, - ViewCollection, - type InputTextView, - type FocusableView -} from 'ckeditor5/src/ui'; -import { Locale, FocusTracker, KeystrokeHandler } from 'ckeditor5/src/utils'; -import { extractDelimiters, hasDelimiters } from '../utils'; -import MathView from './mathview'; +import { icons, ButtonView, createLabeledInputText, FocusCycler, LabelView, LabeledFieldView, submitHandler, SwitchButtonView, View, ViewCollection, type InputTextView, type FocusableView, Locale, FocusTracker, KeystrokeHandler } from 'ckeditor5'; +import { extractDelimiters, hasDelimiters } from '../utils.js'; +import MathView from './mathview.js'; import '../../theme/mathform.css'; -import type { KatexOptions } from '../typings-external'; +import type { KatexOptions } from '../typings-external.js'; const { check: checkIcon, cancel: cancelIcon } = icons; diff --git a/_regroup/ckeditor5-math/src/ui/mathview.ts b/packages/ckeditor5-math/src/ui/mathview.ts similarity index 88% rename from _regroup/ckeditor5-math/src/ui/mathview.ts rename to packages/ckeditor5-math/src/ui/mathview.ts index ab36bea88..541227e43 100644 --- a/_regroup/ckeditor5-math/src/ui/mathview.ts +++ b/packages/ckeditor5-math/src/ui/mathview.ts @@ -1,7 +1,6 @@ -import { View } from 'ckeditor5/src/ui'; -import type { KatexOptions } from '../typings-external'; -import { renderEquation } from '../utils'; -import type { Locale } from 'ckeditor5/src/utils'; +import { View, type Locale } from 'ckeditor5'; +import type { KatexOptions } from '../typings-external.js'; +import { renderEquation } from '../utils.js'; export default class MathView extends View { public declare value: string; diff --git a/_regroup/ckeditor5-math/src/utils.ts b/packages/ckeditor5-math/src/utils.ts similarity index 96% rename from _regroup/ckeditor5-math/src/utils.ts rename to packages/ckeditor5-math/src/utils.ts index 79be614e3..3a29d3fc2 100644 --- a/_regroup/ckeditor5-math/src/utils.ts +++ b/packages/ckeditor5-math/src/utils.ts @@ -1,11 +1,6 @@ -import type { Editor } from 'ckeditor5/src/core'; -import type { - Element as CKElement, - DocumentSelection -} from 'ckeditor5/src/engine'; -import { BalloonPanelView } from 'ckeditor5/src/ui'; -import { CKEditorError, type PositioningFunction } from 'ckeditor5/src/utils'; -import type { KatexOptions, MathJax2, MathJax3 } from './typings-external'; +import type { Editor, Element as CKElement, DocumentSelection, PositioningFunction } from 'ckeditor5'; +import { BalloonPanelView, CKEditorError } from 'ckeditor5'; +import type { KatexOptions, MathJax2, MathJax3 } from './typings-external.js'; export function getSelectedMathModelWidget( selection: DocumentSelection diff --git a/packages/ckeditor5-math/theme/icons/ckeditor.svg b/packages/ckeditor5-math/theme/icons/ckeditor.svg deleted file mode 100644 index 25436f4b8..000000000 --- a/packages/ckeditor5-math/theme/icons/ckeditor.svg +++ /dev/null @@ -1 +0,0 @@ - diff --git a/_regroup/ckeditor5-math/theme/icons/math.svg b/packages/ckeditor5-math/theme/icons/math.svg similarity index 100% rename from _regroup/ckeditor5-math/theme/icons/math.svg rename to packages/ckeditor5-math/theme/icons/math.svg diff --git a/_regroup/ckeditor5-math/theme/mathform.css b/packages/ckeditor5-math/theme/mathform.css similarity index 100% rename from _regroup/ckeditor5-math/theme/mathform.css rename to packages/ckeditor5-math/theme/mathform.css