Skip to content

Commit

Permalink
Describe built-in canvas spots
Browse files Browse the repository at this point in the history
  • Loading branch information
artf committed Aug 29, 2023
1 parent c93b843 commit bae08d7
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 1 deletion.
Binary file added docs/.vuepress/public/canvas-spot-hover.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/.vuepress/public/canvas-spot-resize.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/.vuepress/public/canvas-spot-select.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/.vuepress/public/canvas-spot-target.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
99 changes: 98 additions & 1 deletion docs/modules/Canvas.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ title: Canvas
This guide is referring to GrapesJS v0.21.5 or higher
:::

[[toc]]


## Configuration

Expand All @@ -28,4 +30,99 @@ const editor = grapesjs.init({
Check the full list of available options here: [Canvas Config](https://github.com/GrapesJS/grapesjs/blob/master/src/canvas/config/config.ts)


## Canvas Spots
## Canvas Spots

Canvas spots are elements drawn on top of the canvas. They can be used to represent anything you might need but the most common use case of canvas spots is rendering information and managing components rendered in the canvas.

In order to get a better understanding of canvas spots let's see their built-in types usage.

### Built-in spot types

#### Select type

<img :src="$withBase('/canvas-spot-select.jpg')" class="img-ctr" style="max-height: 100px">

The `select` type is responsable for showing selected components and rendering the available toolbar items of the last selected component.

::: tip
Get the toolbar items from the component.
```js
const toolbarItems = editor.getSelected().toolbar;
```
:::

#### Resize type

<img :src="$withBase('/canvas-spot-resize.jpg')" class="img-ctr" style="max-height: 200px">

The `resize` type allows resizing of a component, based on the component's resizable options.

::: tip
Get the component resizable options.
```js
const resizable = editor.getSelected().resizable;
```
:::

#### Target type

<img :src="$withBase('/canvas-spot-target.jpg')" class="img-ctr" style="max-height: 200px">

The `target` type is used to highlight the component, like during the drag & drop, to show where the component will be placed.

::: warning
The default green position indicator is not part of the spot but you can easily customize it via CSS.
```css
.gjs-placeholder.horizontal {
border-color: transparent red;
}
.gjs-placeholder.vertical {
border-color: red transparent;
}
.gjs-placeholder-int {
background-color: red;
}
```
:::

#### Hover type

<img :src="$withBase('/canvas-spot-hover.jpg')" class="img-ctr" style="max-height: 200px">

The `hover` is used to highlight the hovered component and show the component name.

::: tip
Get the component name.
```js
const name = editor.getSelected().getName();
```
:::

#### Spacing type

The `spacing` type is used to show component offsets like paddings and margins (visible on the `hover` type image above).





### Disable built-in types

```js
canvas: {
customSpots: {
select: true,
hover: true,
spacing: true,
target: true,
// resize: true,
},
},
```




## Events

For a complete list of available events, you can check it [here](/api/canvas.html#available-events).
4 changes: 4 additions & 0 deletions src/dom_components/model/Component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,10 @@ export default class Component extends StyleableModel<ComponentProperties> {
return this.get('toolbar') || [];
}

get resizable() {
return this.get('resizable')!;
}

/**
* Hook method, called once the model is created
*/
Expand Down

0 comments on commit bae08d7

Please sign in to comment.