MCPcopy
hub / github.com/GrapesJS/grapesjs / PageManager

Class PageManager

packages/core/src/pages/index.ts:46–311  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

44const typeMain = 'main';
45
46export default class PageManager extends ItemManagerModule<PageManagerConfig, Pages> {
47 events = PagesEvents;
48 storageKey = 'pages';
49
50 get pages() {
51 return this.all;
52 }
53
54 model: ModuleModel;
55
56 getAll() {
57 // this avoids issues during the TS build (some getAll are inconsistent)
58 return [...this.all.models];
59 }
60
61 /**
62 * Get all pages
63 * @name getAll
64 * @function
65 * @returns {Array<[Page]>}
66 * @example
67 * const arrayOfPages = pageManager.getAll();
68 */
69
70 /**
71 * Initialize module
72 * @hideconstructor
73 * @param {Object} config Configurations
74 */
75 constructor(em: EditorModel) {
76 super(em, 'PageManager', new Pages([], em), PagesEvents);
77 bindAll(this, '_onPageChange');
78 const model = new ModuleModel(this, { _undo: true });
79 this.model = model;
80 this.pages.on('reset', this.__onReset, this);
81 this.pages.on('all', this.__onChange, this);
82 model.on(chnSel, this._onPageChange);
83 }
84
85 __onChange(event: string, page: Page, coll: Pages, opts?: any) {
86 const { em, events } = this;
87 const options = opts || coll;
88 em.trigger(events.all, { event, page, options });
89 }
90
91 __onReset() {
92 const firstPage = this.pages.at(0);
93 firstPage && this.select(firstPage);
94 }
95
96 onLoad() {
97 const { pages, config, em } = this;
98 const opt = { silent: true };
99 const configPages = config.pages?.map((page) => new Page(page, { em, config })) || [];
100 pages.add(configPages, opt);
101 const mainPage = !pages.length ? this.add({ type: typeMain }, opt) : this._initPage();
102 mainPage && this.select(mainPage, opt);
103 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected