diff --git a/src/editor/config/config.ts b/src/editor/config/config.ts index b48a900fd..54178694a 100644 --- a/src/editor/config/config.ts +++ b/src/editor/config/config.ts @@ -7,6 +7,7 @@ import { DeviceManagerConfig } from '../../device_manager/config/config'; import { I18nConfig } from '../../i18n/config'; import { ModalConfig } from '../../modal_dialog/config/config'; import { LayerManagerConfig } from '../../navigator/config/config'; +import { PageManagerConfig } from '../../pages'; import { PanelsConfig } from '../../panels/config/config'; import { ParserConfig } from '../../parser/config/config'; import { RichTextEditorConfig } from '../../rich_text_editor/config/config'; @@ -371,7 +372,6 @@ export interface EditorConfig { */ styleManager?: AnyObject; - // TODO /** * Configurations for Block Manager. */ @@ -383,11 +383,10 @@ export interface EditorConfig { */ traitManager?: AnyObject; - // TODO /** * Configurations for Page Manager. */ - pageManager?: AnyObject; + pageManager?: PageManagerConfig; /** * Configurations for Layer Manager. diff --git a/src/pages/index.ts b/src/pages/index.ts index 3f5ac1b45..326911fc0 100644 --- a/src/pages/index.ts +++ b/src/pages/index.ts @@ -74,10 +74,11 @@ const events = { removeBefore: evPageRemoveBefore, }; -interface Config extends ModuleConfig { +export interface PageManagerConfig extends ModuleConfig { pages?: string[]; } -export default class PageManager extends ItemManagerModule { + +export default class PageManager extends ItemManagerModule { storageKey = 'pages'; get pages() { @@ -105,7 +106,7 @@ export default class PageManager extends ItemManagerModule { bindAll(this, '_onPageChange'); const model = new Model({ _undo: true } as any); this.model = model; - this.pages.on('reset', (coll) => coll.at(0) && this.select(coll.at(0))); + this.pages.on('reset', coll => coll.at(0) && this.select(coll.at(0))); this.pages.on('all', this.__onChange, this); model.on(chnSel, this._onPageChange); @@ -120,15 +121,8 @@ export default class PageManager extends ItemManagerModule { onLoad() { const { pages } = this; const opt = { silent: true }; - pages.add( - this.config.pages?.map( - (page) => new Page(page, { em: this.em, config: this.config }) - ) || [], - opt - ); - const mainPage = !pages.length - ? this.add({ type: typeMain }, opt) - : this.getMain(); + pages.add(this.config.pages?.map(page => new Page(page, { em: this.em, config: this.config })) || [], opt); + const mainPage = !pages.length ? this.add({ type: typeMain }, opt) : this.getMain(); mainPage && this.select(mainPage, opt); } @@ -167,10 +161,7 @@ export default class PageManager extends ItemManagerModule { const { em } = this; props.id = props.id || this._createId(); const add = () => { - const page = this.pages.add( - new Page(props, { em: this.em, config: this.config }), - opts - ); + const page = this.pages.add(new Page(props, { em: this.em, config: this.config }), opts); opts.select && this.select(page); return page; }; @@ -207,7 +198,7 @@ export default class PageManager extends ItemManagerModule { * const somePage = pageManager.get('page-id'); */ get(id: string) { - return this.pages.filter((p) => p.get(p.idAttribute) === id)[0]; + return this.pages.filter(p => p.get(p.idAttribute) === id)[0]; } /** @@ -218,7 +209,7 @@ export default class PageManager extends ItemManagerModule { */ getMain() { const { pages } = this; - return pages.filter((p) => p.get('type') === typeMain)[0] || pages.at(0); + return pages.filter(p => p.get('type') === typeMain)[0] || pages.at(0); } /** @@ -231,13 +222,7 @@ export default class PageManager extends ItemManagerModule { */ getAllWrappers() { const pages = this.getAll(); - return unique( - flatten( - pages.map((page) => - page.getAllFrames().map((frame) => frame.getComponent()) - ) - ) - ); + return unique(flatten(pages.map(page => page.getAllFrames().map(frame => frame.getComponent())))); } /** @@ -274,7 +259,7 @@ export default class PageManager extends ItemManagerModule { this.model.stopListening(); this.model.clear({ silent: true }); //@ts-ignore - ['selected', 'model'].map((i) => (this[i] = 0)); + ['selected', 'model'].map(i => (this[i] = 0)); } store() {