From fbd14cc9ec53b30dd62945ff276a878975f0001f Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Fri, 8 Jul 2022 15:55:03 +0200 Subject: [PATCH] Update Layers doc --- docs/modules/Layers.md | 317 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 301 insertions(+), 16 deletions(-) diff --git a/docs/modules/Layers.md b/docs/modules/Layers.md index 2f8f88164..27ba79740 100644 --- a/docs/modules/Layers.md +++ b/docs/modules/Layers.md @@ -17,7 +17,7 @@ This guide is referring to GrapesJS v0.19.4 or higher ## Configuration -To change the default configurations you have to pass the `layerManager` property with the main configuration object. +To change the default configurations you have to pass the `layerManager` option with the main configuration object. ```js const editor = grapesjs.init({ @@ -28,6 +28,9 @@ const editor = grapesjs.init({ }); ``` +You can check here the full list of available configuration options: [Layer Manager Config](https://github.com/artf/grapesjs/blob/master/src/navigator/config/config.ts) + + Layers are a direct representation of your components, therefore they will only be available once your components are loaded in the editor (eg. you might load your project data from a remote endpoint). In your configuration, you're able to change the global behavior of layers (eg. make all the layers not sortable) and also decide which component layer should be used as a root. @@ -47,8 +50,6 @@ const editor = grapesjs.init({ The configurations are mainly targeting the default UI provided by GrapesJS core, in case you need more control over the tree of your layers, you can read more in the [Customization](#customization) section below. -You can check here the full list of available configuration options: [Layer Manager Config](https://github.com/artf/grapesjs/blob/master/src/navigator/config/config.ts) - ## Programmatic usage @@ -61,32 +62,319 @@ If you need to manage layers programmatically you can use its [APIs][Layers API] ## Customization -The default UI can handle most of the common tasks but in case you need a more advanced logic/elements, that requires a replace of the default UI. +By using the [Layers API][Layers API] you're able to replace the default UI with your own implementation. -All you have to do is to indicate the editor your intent to use a custom UI and then subscribe to the `selector:custom` event that will trigger on any necessary update of the UI. +All you have to do is to indicate to the editor your intent to use a custom UI and then subscribe to a few events that allow you to properly update your UI. ```js const editor = grapesjs.init({ // ... - selectorManager: { + layerManager: { custom: true, // ... }, }); -editor.on('selector:custom', props => { +// Use this event to append your UI in the default container provided by GrapesJS. +// You can skip this event if you don't rely on the core panels and decide to +// place the UI in some other place. +editor.on('layer:custom', (props) => { // props.container (HTMLElement) - The default element where you can append your UI - - // Here you would put the logic to render/update your UI. }); -``` -In the example below we'll replicate most of the default functionality by using solely the Selector Manager API. - - +// Triggered when the root layer is changed. +editor.on('layer:root', (root) => { + // Update the root of your UI +}); +// Triggered when a component is updated, this allows you to update specific layers. +editor.on('layer:component', (component) => { + // Update the specific layer of your UI +}); +``` +In the example below we'll replicate most of the default functionality with our own implementation. + + + + + ## Events @@ -94,8 +382,5 @@ In the example below we'll replicate most of the default functionality by using For a complete list of available events, you can check it [here](/api/layer_manager.html#available-events). -[Selector]: -[Style Manager]: [Components]: -[Getting Started]: [Layers API]: