Skip to content

Latest commit

 

History

History
217 lines (128 loc) · 3.87 KB

layer_manager.md

File metadata and controls

217 lines (128 loc) · 3.87 KB

Layers

You can customize the initial state of the module from the editor initialization

const editor = grapesjs.init({
 // ...
 layerManager: {
   // ...
 },
})

Once the editor is instantiated you can use its API. Before using these methods you should get the module from the instance

const layers = editor.Layers;

Available Events

  • layer:root - Root layer changed. The new root component is passed as an argument to the callback.
  • layer:component - Component layer is updated. The updated component is passed as an argument to the callback.

Methods

setRoot

Update the root layer with another component.

Parameters

Examples

const component = editor.getSelected();
layers.setRoot(component);

Returns Component

getRoot

Get the current root layer.

Examples

const layerRoot = layers.getRoot();

Returns Component

getComponents

Get valid layer child components (eg. excludes non layerable components).

Parameters

  • component Component Component from which you want to get child components

Examples

const component = editor.getSelected();
const components = layers.getComponents(component);
console.log(components);

Returns Array<Component>

setOpen

Update the layer open state of the component.

Parameters

isOpen

Check the layer open state of the component.

Parameters

Returns Boolean

setVisible

Update the layer visibility state of the component.

Parameters

isVisible

Check the layer visibility state of the component.

Parameters

Returns Boolean

setLocked

Update the layer locked state of the component.

Parameters

isLocked

Check the layer locked state of the component.

Parameters

Returns Boolean

setName

Update the layer name of the component.

Parameters

getName

Get the layer name of the component.

Parameters

Returns String Component layer name

getLayerData

Get layer data from a component.

Parameters

  • component Component Component from which you want to read layer data.

Examples

const component = editor.getSelected();
const layerData = layers.getLayerData(component);
console.log(layerData);

Returns Object Object containing the layer data.