Browse Source

Add PageManagerConfig

pull/4746/head
Artur Arseniev 4 years ago
parent
commit
309ede9f22
  1. 5
      src/editor/config/config.ts
  2. 37
      src/pages/index.ts

5
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.

37
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<Config, Pages> {
export default class PageManager extends ItemManagerModule<PageManagerConfig, Pages> {
storageKey = 'pages';
get pages() {
@ -105,7 +106,7 @@ export default class PageManager extends ItemManagerModule<Config, Pages> {
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<Config, Pages> {
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<Config, Pages> {
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<Config, Pages> {
* 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<Config, Pages> {
*/
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<Config, Pages> {
*/
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<Config, Pages> {
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() {

Loading…
Cancel
Save