diff --git a/src/style_manager/view/SectorView.ts b/src/style_manager/view/SectorView.ts index 5191ada27..7f71203a9 100644 --- a/src/style_manager/view/SectorView.ts +++ b/src/style_manager/view/SectorView.ts @@ -4,18 +4,18 @@ import html from '../../utils/html'; import Sector from '../model/Sector'; import PropertiesView from './PropertiesView'; -type Config = { +export type SectorViewConfig = { em: EditorModel; stylePrefix?: string; + pStylePrefix?: string; }; export default class SectorView extends View { em: EditorModel; - config: Config; + config: SectorViewConfig; pfx: string; - constructor(o: { config: Config }) { - // @ts-ignore + constructor(o: { config: SectorViewConfig; model?: Sector }) { super(o); const config = o.config || {}; const { model } = this; diff --git a/src/style_manager/view/SectorsView.js b/src/style_manager/view/SectorsView.ts similarity index 52% rename from src/style_manager/view/SectorsView.js rename to src/style_manager/view/SectorsView.ts index 7bbf91590..21a9d3145 100644 --- a/src/style_manager/view/SectorsView.js +++ b/src/style_manager/view/SectorsView.ts @@ -1,29 +1,42 @@ import { View } from '../../common'; import { appendAtIndex } from '../../utils/dom'; -import SectorView from './SectorView'; +import Sector from '../model/Sector'; +import SectorView, { SectorViewConfig } from './SectorView'; export default class SectorsView extends View { - initialize(o = {}) { - const { module, config = {} } = o; + pfx: string; + ppfx: string; + config: SectorViewConfig; + module: any; + + constructor(o: { module?: any; config?: SectorViewConfig } = {}) { + // @ts-ignore + super(o); + const { module, config } = o; const coll = this.collection; - this.pfx = config.stylePrefix || ''; - this.ppfx = config.pStylePrefix || ''; - this.config = config; - this.module = module; + this.pfx = config?.stylePrefix || ''; + this.ppfx = config?.pStylePrefix || ''; + this.config = config!; + this.module = module!; this.listenTo(coll, 'add', this.addTo); this.listenTo(coll, 'reset', this.render); } remove() { - View.prototype.remove.apply(this, arguments); - ['config', 'module', 'em'].forEach(i => (this[i] = {})); + View.prototype.remove.apply(this, arguments as any); + ['config', 'module', 'em'].forEach( + i => + // @ts-ignore + (this[i] = {}) + ); + return this; } - addTo(model, c, opts = {}) { + addTo(model: Sector, c: any, opts = {}) { this.addToCollection(model, null, opts); } - addToCollection(model, fragmentEl, opts = {}) { + addToCollection(model: Sector, fragmentEl: DocumentFragment | null, opts: { at?: number } = {}) { const { config, el } = this; const appendTo = fragmentEl || el; const rendered = new SectorView({ model, config }).render().el; diff --git a/src/utils/dom.ts b/src/utils/dom.ts index 8a3c4e15d..b67a75950 100644 --- a/src/utils/dom.ts +++ b/src/utils/dom.ts @@ -40,7 +40,7 @@ export const replaceWith = (oldEl: HTMLElement, newEl: HTMLElement) => { oldEl.parentNode?.replaceChild(newEl, oldEl); }; -export const appendAtIndex = (parent: HTMLElement, child: ChildHTML, index?: number) => { +export const appendAtIndex = (parent: HTMLElement | DocumentFragment, child: ChildHTML, index?: number) => { const { childNodes } = parent; const total = childNodes.length; const at = isUndefined(index) ? total : index;