Skip to content

Commit

Permalink
Up docs
Browse files Browse the repository at this point in the history
  • Loading branch information
artf committed Sep 17, 2023
1 parent 3107810 commit 20cce66
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 56 deletions.
3 changes: 2 additions & 1 deletion docs/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const getEventsMdFromTypes = async (filePath) => {
const dirname = filePath.replace(path.basename(filePath), '');
const typesFilePath = `${dirname}types.ts`;

if (fs.existsSync(typesFilePath) && typesFilePath.includes('canvas')) {
if (fs.existsSync(typesFilePath)) {
const resTypes = await documentation.build([typesFilePath], { shallow: true })
.then(cm => documentation.formats.md(cm, /*{ markdownToc: true }*/));
const indexFrom = resTypes.indexOf(START_EVENTS) + START_EVENTS.length;
Expand All @@ -26,6 +26,7 @@ const getEventsMdFromTypes = async (filePath) => {
.replace(/## /gi, '* ')
.replace(/\\`/gi, '`')
.replace(/##/gi, '')
.replace(/\\\[/gi, '[')
.trim();

return result
Expand Down
125 changes: 70 additions & 55 deletions docs/api/block_manager.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,59 @@ blockManager.add(...);
```

## Available Events
* `block:add` New block added to the collection. The [Block] is passed as an argument to the callback.

* `block:add` - Block added. The [Block] is passed as an argument to the callback.
* `block:remove` - Block removed. The [Block] is passed as an argument to the callback.
* `block:update` - Block updated. The [Block] and the object containing changes are passed as arguments to the callback.
* `block:drag:start` - Started dragging block, the [Block] is passed as an argument.
* `block:drag` - Dragging block, the [Block] is passed as an argument.
* `block:drag:stop` - Dragging of the block is stopped. The dropped [Component] (if dropped successfully) and the [Block] are passed as arguments.
* `block` - 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.

## Methods

* [add][2]
* [get][3]
* [getAll][4]
* [getAllVisible][5]
* [remove][6]
* [getConfig][7]
* [getCategories][8]
* [getContainer][9]
* [render][10]
```javascript
editor.on('block:add', (block) => { ... });
```

* `block:remove` Block removed from the collection. The [Block] is passed as an argument to the callback.

```javascript
editor.on('block:remove', (block) => { ... });
```

* `block:remove:before` Event triggered before Block remove.

```javascript
editor.on('block:remove:before', (block, remove, opts) => { ... });
```

* `block:update` Block updated. The [Block] and the object containing changes are passed as arguments to the callback.

```javascript
editor.on('block:update', (block, updatedProps) => { ... });
```

* `block:drag:start` Started dragging block. The [Block] is passed as an argument.

```javascript
editor.on('block:drag:start', (block) => { ... });
```

* `block:drag` The block is dragging. The [Block] is passed as an argument.

```javascript
editor.on('block:drag', (block) => { ... });
```

* `block:drag:stop` Dragging of the block is stopped. The dropped [Component] (if dropped successfully) and the [Block] are passed as arguments.

```javascript
editor.on('block:drag:stop', (component, block) => { ... });
```

* `block:custom` Event to use in case of [custom Block Manager UI]\(https://grapesjs.com/docs/modules/Blocks.html#customization).

```javascript
editor.on('block:custom', ({ container, blocks, ... }) => { ... });
```

* `block` 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('block', ({ event, model, ... }) => { ... });
```

[Block]: block.html

Expand All @@ -53,15 +86,15 @@ blockManager.add(...);

Get configuration object

Returns **[Object][11]**
Returns **[Object][2]**

## add

Add new block.

### Parameters

* `id` **[String][12]** Block ID
* `id` **[String][3]** Block ID
* `props` **[Block]** Block properties
* `opts` (optional, default `{}`)

Expand All @@ -86,7 +119,7 @@ Get the block by id.

### Parameters

* `id` **[String][12]** Block id
* `id` **[String][3]** Block id

### Examples

Expand Down Expand Up @@ -124,7 +157,7 @@ Remove block.

### Parameters

* `block` **([String][12] | [Block])** Block or block ID
* `block` **([String][3] | [Block])** Block or block ID
* `opts` (optional, default `{}`)

### Examples
Expand All @@ -143,32 +176,32 @@ Returns **[Block]** Removed block
Get all available categories.
It's possible to add categories only within blocks via 'add()' method

Returns **([Array][13] | Collection)**
Returns **([Array][4] | Collection)**

## getContainer

Return the Blocks container element

Returns **[HTMLElement][14]**
Returns **[HTMLElement][5]**

## getDragBlock

Returns currently dragging block.
Updated when the drag starts and cleared once it's done.

Returns **([Block] | [undefined][15])**
Returns **([Block] | [undefined][6])**

## render

Render blocks

### Parameters

* `blocks` **[Array][13]** Blocks to render, without the argument will render all global blocks
* `opts` **[Object][11]** Options (optional, default `{}`)
* `blocks` **[Array][4]** Blocks to render, without the argument will render all global blocks
* `opts` **[Object][2]** Options (optional, default `{}`)

* `opts.external` **[Boolean][16]?** Render blocks in a new container (HTMLElement will be returned)
* `opts.ignoreCategories` **[Boolean][16]?** Render blocks without categories
* `opts.external` **[Boolean][7]?** Render blocks in a new container (HTMLElement will be returned)
* `opts.ignoreCategories` **[Boolean][7]?** Render blocks without categories

### Examples

Expand All @@ -194,36 +227,18 @@ const newBlocksEl = blockManager.render(filtered, { external: true });
document.getElementById('some-id').appendChild(newBlocksEl);
```

Returns **[HTMLElement][14]** Rendered element
Returns **[HTMLElement][5]** Rendered element

[1]: https://github.com/GrapesJS/grapesjs/blob/master/src/block_manager/config/config.ts

[2]: #add

[3]: #get

[4]: #getall

[5]: #getallvisible

[6]: #remove

[7]: #getconfig

[8]: #getcategories

[9]: #getcontainer

[10]: #render

[11]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object
[2]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object

[12]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
[3]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String

[13]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
[4]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array

[14]: https://developer.mozilla.org/docs/Web/HTML/Element
[5]: https://developer.mozilla.org/docs/Web/HTML/Element

[15]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined
[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined

[16]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
3 changes: 3 additions & 0 deletions docs/api/editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,9 @@ Load data from the current storage.
### Parameters

* `options` **[Object][16]?** Storage options.
* `loadOptions` **[Object][16]** Load options. (optional, default `{}`)

* `loadOptions.clear` **[Boolean][17]** Clear the editor state (eg. dirty counter, undo manager, etc.). (optional, default `false`)

### Examples

Expand Down
3 changes: 3 additions & 0 deletions src/block_manager/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,6 @@ export enum BlocksEvents {
all = 'block',
}
/**{END_EVENTS}*/

// need this to avoid the TS documentation generator to break
export default BlocksEvents;

0 comments on commit 20cce66

Please sign in to comment.