Browse Source

Move CommandAbstract to TS

ts-style-manager
Artur Arseniev 4 years ago
parent
commit
10f329cebf
  1. 2
      src/canvas/index.ts
  2. 53
      src/commands/view/CommandAbstract.ts
  3. 4
      src/commands/view/SelectPosition.js

2
src/canvas/index.ts

@ -176,7 +176,7 @@ export default class CanvasModule extends Module<CanvasConfig> {
* @returns {HTMLElement} * @returns {HTMLElement}
* @private * @private
*/ */
getToolsEl(compView: any) { getToolsEl(compView?: any) {
return this._getLocalEl(this.getCanvasView().toolsEl, compView, 'getToolsEl'); return this._getLocalEl(this.getCanvasView().toolsEl, compView, 'getToolsEl');
} }

53
src/commands/view/CommandAbstract.js → src/commands/view/CommandAbstract.ts

@ -1,22 +1,31 @@
import CanvasModule from '../../canvas';
import { Model } from '../../common'; import { Model } from '../../common';
import Editor from '../../editor';
import EditorModel from '../../editor/model/Editor';
export default class CommandAbstract extends Model { export default class CommandAbstract extends Model {
/** config: any;
* Initialize method that can't be removed em: EditorModel;
* @param {Object} o Options pfx: string;
* @private ppfx: string;
* */ hoverClass: string;
initialize(o) { badgeClass: string;
plhClass: string;
freezClass: string;
canvas: CanvasModule;
constructor(o: any) {
super(0);
this.config = o || {}; this.config = o || {};
this.editorModel = this.em = this.config.em || {}; this.em = this.config.em || {};
this.pfx = this.config.stylePrefix; const pfx = this.config.stylePrefix;
this.pfx = pfx;
this.ppfx = this.config.pStylePrefix; this.ppfx = this.config.pStylePrefix;
this.hoverClass = this.pfx + 'hover'; this.hoverClass = `${pfx}hover`;
this.badgeClass = this.pfx + 'badge'; this.badgeClass = `${pfx}badge`;
this.plhClass = this.pfx + 'placeholder'; this.plhClass = `${pfx}placeholder`;
this.freezClass = this.ppfx + 'freezed'; this.freezClass = `${this.ppfx}freezed`;
this.canvas = this.em.Canvas;
this.canvas = this.em.get && this.em.get('Canvas');
this.init(this.config); this.init(this.config);
} }
@ -25,7 +34,7 @@ export default class CommandAbstract extends Model {
* @param {[type]} e [description] * @param {[type]} e [description]
* @return {[type]} [description] * @return {[type]} [description]
*/ */
onFrameScroll(e) {} onFrameScroll(e: any) {}
/** /**
* Returns canval element * Returns canval element
@ -56,7 +65,7 @@ export default class CommandAbstract extends Model {
* @param {HTMLElement} el * @param {HTMLElement} el
* @return {Object} * @return {Object}
*/ */
offset(el) { offset(el: HTMLElement) {
var rect = el.getBoundingClientRect(); var rect = el.getBoundingClientRect();
return { return {
top: rect.top + el.ownerDocument.body.scrollTop, top: rect.top + el.ownerDocument.body.scrollTop,
@ -69,7 +78,7 @@ export default class CommandAbstract extends Model {
* @param {Object} o Options * @param {Object} o Options
* @private * @private
* */ * */
init(o) {} init(o: any) {}
/** /**
* Method that run command * Method that run command
@ -77,7 +86,7 @@ export default class CommandAbstract extends Model {
* @param {Object} [options={}] Options * @param {Object} [options={}] Options
* @private * @private
* */ * */
callRun(editor, options = {}) { callRun(editor: Editor, options: any = {}) {
const id = this.id; const id = this.id;
editor.trigger(`run:${id}:before`, options); editor.trigger(`run:${id}:before`, options);
@ -99,7 +108,7 @@ export default class CommandAbstract extends Model {
* @param {Object} [options={}] Options * @param {Object} [options={}] Options
* @private * @private
* */ * */
callStop(editor, options = {}) { callStop(editor: Editor, options: any = {}) {
const id = this.id; const id = this.id;
const sender = options.sender || editor; const sender = options.sender || editor;
editor.trigger(`stop:${id}:before`, options); editor.trigger(`stop:${id}:before`, options);
@ -112,7 +121,7 @@ export default class CommandAbstract extends Model {
/** /**
* Stop current command * Stop current command
*/ */
stopCommand(opts) { stopCommand(opts: any) {
this.em.get('Commands').stop(this.id, opts); this.em.get('Commands').stop(this.id, opts);
} }
@ -122,7 +131,7 @@ export default class CommandAbstract extends Model {
* @param {Object} sender Button sender * @param {Object} sender Button sender
* @private * @private
* */ * */
run(em, sender) {} run(em: Editor, sender: any, options: any) {}
/** /**
* Method that stop command * Method that stop command
@ -130,5 +139,5 @@ export default class CommandAbstract extends Model {
* @param {Object} sender Button sender * @param {Object} sender Button sender
* @private * @private
* */ * */
stop(em, sender) {} stop(em: Editor, sender: any, options: any) {}
} }

4
src/commands/view/SelectPosition.js

@ -9,7 +9,7 @@ export default {
* */ * */
startSelectPosition(trg, doc, opts = {}) { startSelectPosition(trg, doc, opts = {}) {
this.isPointed = false; this.isPointed = false;
var utils = this.editorModel.get('Utils'); var utils = this.em.get('Utils');
const container = trg.ownerDocument.body; const container = trg.ownerDocument.body;
if (utils && !this.sorter) if (utils && !this.sorter)
@ -23,7 +23,7 @@ export default {
document: doc, document: doc,
wmargin: 1, wmargin: 1,
nested: 1, nested: 1,
em: this.editorModel, em: this.em,
canvasRelative: 1, canvasRelative: 1,
scale: () => this.em.getZoomDecimal(), scale: () => this.em.getZoomDecimal(),
}); });

Loading…
Cancel
Save