## Pages
You can customize the initial state of the module from the editor initialization
```js
const editor = grapesjs.init({
....
pageManager: {
pages: [
{
id: 'page-id',
styles: `.my-class { color: red }`, // or a JSON of styles
component: '
My element
', // or a JSON of components
}
]
},
})
```
Once the editor is instantiated you can use its API. Before using these methods you should get the module from the instance
```js
const pageManager = editor.Pages;
```
## Available Events
* `page:add` Added new page. The page is passed as an argument to the callback.
```javascript
editor.on('page:add', (page) => { ... });
```
* `page:remove` Page removed. The page is passed as an argument to the callback.
```javascript
editor.on('page:remove', (page) => { ... });
```
* `page:select` New page selected. The newly selected page and the previous one, are passed as arguments to the callback.
```javascript
editor.on('page:select', (page, previousPage) => { ... });
```
* `page:update` Page updated. The updated page and the object containing changes are passed as arguments to the callback.
```javascript
editor.on('page:update', (page, changes) => { ... });
```
* `page` Catch-all event for all the events mentioned above. An object containing all the available data about the triggered event is passed as an argument to the callback.
```javascript
editor.on('page', ({ event, model, ... }) => { ... });
```
[Page]: page.html
[Component]: component.html
## getAll
Get all pages
### Examples
```javascript
const arrayOfPages = pageManager.getAll();
```
Returns **[Array][1]<[Page]>**
## add
Add new page
### Parameters
* `props` **[Object][2]** Page properties
* `opts` **[Object][2]?** Options (optional, default `{}`)
### Examples
```javascript
const newPage = pageManager.add({
id: 'new-page-id', // without an explicit ID, a random one will be created
styles: `.my-class { color: red }`, // or a JSON of styles
component: 'My element
', // or a JSON of components
});
```
Returns **[Page]**
## remove
Remove page
### Parameters
* `page` **([String][3] | [Page])** Page or page id
* `opts` **any** (optional, default `{}`)
### Examples
```javascript
const removedPage = pageManager.remove('page-id');
// or by passing the page
const somePage = pageManager.get('page-id');
pageManager.remove(somePage);
```
Returns **[Page]** Removed Page
## get
Get page by id
### Parameters
* `id` **[String][3]** Page id
### Examples
```javascript
const somePage = pageManager.get('page-id');
```
Returns **[Page]**
## getMain
Get main page (the first one available)
### Examples
```javascript
const mainPage = pageManager.getMain();
```
Returns **[Page]**
## getAllWrappers
Get wrapper components (aka body) from all pages and frames.
### Examples
```javascript
const wrappers = pageManager.getAllWrappers();
// Get all `image` components from the project
const allImages = wrappers.map(wrp => wrp.findType('image')).flat();
```
Returns **[Array][1]<[Component]>**
## select
Change the selected page. This will switch the page rendered in canvas
### Parameters
* `page` **([String][3] | [Page])** Page or page id
* `opts` **SetOptions** (optional, default `{}`)
### Examples
```javascript
pageManager.select('page-id');
// or by passing the page
const somePage = pageManager.get('page-id');
pageManager.select(somePage);
```
Returns **this**
## getSelected
Get the selected page
### Examples
```javascript
const selectedPage = pageManager.getSelected();
```
Returns **[Page]**
[1]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String