From 10f329cebff54c10bb84135eece0a606f6ec450d Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Sun, 8 Jan 2023 11:18:15 +0400 Subject: [PATCH] Move CommandAbstract to TS --- src/canvas/index.ts | 2 +- ...{CommandAbstract.js => CommandAbstract.ts} | 53 +++++++++++-------- src/commands/view/SelectPosition.js | 4 +- 3 files changed, 34 insertions(+), 25 deletions(-) rename src/commands/view/{CommandAbstract.js => CommandAbstract.ts} (72%) diff --git a/src/canvas/index.ts b/src/canvas/index.ts index 810544787..6eebed08a 100644 --- a/src/canvas/index.ts +++ b/src/canvas/index.ts @@ -176,7 +176,7 @@ export default class CanvasModule extends Module { * @returns {HTMLElement} * @private */ - getToolsEl(compView: any) { + getToolsEl(compView?: any) { return this._getLocalEl(this.getCanvasView().toolsEl, compView, 'getToolsEl'); } diff --git a/src/commands/view/CommandAbstract.js b/src/commands/view/CommandAbstract.ts similarity index 72% rename from src/commands/view/CommandAbstract.js rename to src/commands/view/CommandAbstract.ts index 759c6f7da..046eda5f7 100644 --- a/src/commands/view/CommandAbstract.js +++ b/src/commands/view/CommandAbstract.ts @@ -1,22 +1,31 @@ +import CanvasModule from '../../canvas'; import { Model } from '../../common'; +import Editor from '../../editor'; +import EditorModel from '../../editor/model/Editor'; export default class CommandAbstract extends Model { - /** - * Initialize method that can't be removed - * @param {Object} o Options - * @private - * */ - initialize(o) { + config: any; + em: EditorModel; + pfx: string; + ppfx: string; + hoverClass: string; + badgeClass: string; + plhClass: string; + freezClass: string; + canvas: CanvasModule; + + constructor(o: any) { + super(0); this.config = o || {}; - this.editorModel = this.em = this.config.em || {}; - this.pfx = this.config.stylePrefix; + this.em = this.config.em || {}; + const pfx = this.config.stylePrefix; + this.pfx = pfx; this.ppfx = this.config.pStylePrefix; - this.hoverClass = this.pfx + 'hover'; - this.badgeClass = this.pfx + 'badge'; - this.plhClass = this.pfx + 'placeholder'; - this.freezClass = this.ppfx + 'freezed'; - - this.canvas = this.em.get && this.em.get('Canvas'); + this.hoverClass = `${pfx}hover`; + this.badgeClass = `${pfx}badge`; + this.plhClass = `${pfx}placeholder`; + this.freezClass = `${this.ppfx}freezed`; + this.canvas = this.em.Canvas; this.init(this.config); } @@ -25,7 +34,7 @@ export default class CommandAbstract extends Model { * @param {[type]} e [description] * @return {[type]} [description] */ - onFrameScroll(e) {} + onFrameScroll(e: any) {} /** * Returns canval element @@ -56,7 +65,7 @@ export default class CommandAbstract extends Model { * @param {HTMLElement} el * @return {Object} */ - offset(el) { + offset(el: HTMLElement) { var rect = el.getBoundingClientRect(); return { top: rect.top + el.ownerDocument.body.scrollTop, @@ -69,7 +78,7 @@ export default class CommandAbstract extends Model { * @param {Object} o Options * @private * */ - init(o) {} + init(o: any) {} /** * Method that run command @@ -77,7 +86,7 @@ export default class CommandAbstract extends Model { * @param {Object} [options={}] Options * @private * */ - callRun(editor, options = {}) { + callRun(editor: Editor, options: any = {}) { const id = this.id; editor.trigger(`run:${id}:before`, options); @@ -99,7 +108,7 @@ export default class CommandAbstract extends Model { * @param {Object} [options={}] Options * @private * */ - callStop(editor, options = {}) { + callStop(editor: Editor, options: any = {}) { const id = this.id; const sender = options.sender || editor; editor.trigger(`stop:${id}:before`, options); @@ -112,7 +121,7 @@ export default class CommandAbstract extends Model { /** * Stop current command */ - stopCommand(opts) { + stopCommand(opts: any) { this.em.get('Commands').stop(this.id, opts); } @@ -122,7 +131,7 @@ export default class CommandAbstract extends Model { * @param {Object} sender Button sender * @private * */ - run(em, sender) {} + run(em: Editor, sender: any, options: any) {} /** * Method that stop command @@ -130,5 +139,5 @@ export default class CommandAbstract extends Model { * @param {Object} sender Button sender * @private * */ - stop(em, sender) {} + stop(em: Editor, sender: any, options: any) {} } diff --git a/src/commands/view/SelectPosition.js b/src/commands/view/SelectPosition.js index e39fd5bf7..8a03666e4 100644 --- a/src/commands/view/SelectPosition.js +++ b/src/commands/view/SelectPosition.js @@ -9,7 +9,7 @@ export default { * */ startSelectPosition(trg, doc, opts = {}) { this.isPointed = false; - var utils = this.editorModel.get('Utils'); + var utils = this.em.get('Utils'); const container = trg.ownerDocument.body; if (utils && !this.sorter) @@ -23,7 +23,7 @@ export default { document: doc, wmargin: 1, nested: 1, - em: this.editorModel, + em: this.em, canvasRelative: 1, scale: () => this.em.getZoomDecimal(), });