From de40c3dfc780d1d581eb8e8ed9c87a1b95dd7f42 Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Wed, 23 Aug 2023 20:07:05 +0400 Subject: [PATCH] Up api docs --- docs/api/component.md | 2 +- docs/api/components.md | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/docs/api/component.md b/docs/api/component.md index cb8328ab7..44800f854 100644 --- a/docs/api/component.md +++ b/docs/api/component.md @@ -725,7 +725,7 @@ This works only if the component is already rendered ### Parameters -* `frame` **Frame** Specific frame from which taking the element (optional, default `undefined`) +* `frame` **Frame** Specific frame from which taking the element Returns **[HTMLElement][11]** diff --git a/docs/api/components.md b/docs/api/components.md index cb7fa6250..d6d154a94 100644 --- a/docs/api/components.md +++ b/docs/api/components.md @@ -201,6 +201,36 @@ Return the array of all types Returns **[Array][11]** +## canMove + +Check if a component can be moved inside another one. + +### Parameters + +* `target` **[Component]** The target component is the one that is supposed to receive the source one. +* `source` **([Component] | [String][12])** The source can be another component, a component definition or an HTML string. +* `index` **[Number][17]?** Index position, if not specified, the check will be performed against appending the source to the target. + +### Examples + +```javascript +const rootComponent = editor.getWrapper(); +const someComponent = editor.getSelected(); + +// Check with two components +editor.Components.canMove(rootComponent, someComponent); + +// Check with component definition +editor.Components.canMove(rootComponent, { tagName: 'a', draggable: false }); + +// Check with HTML string +editor.Components.canMove(rootComponent, '
...
'); +``` + +Returns **[Object][10]** Object containing the `result` (Boolean), `source`, `target` (as Components), and a `reason` (Number) with these meanings:* `0` - Invalid source. This is a default value and should be ignored in case the `result` is true. +* `1` - Source doesn't accept target as destination. +* `2` - Target doesn't accept source. + [1]: https://github.com/GrapesJS/grapesjs/blob/master/src/dom_components/config/config.ts [2]: #getwrapper @@ -232,3 +262,5 @@ Returns **[Array][11]** [15]: https://grapesjs.com/docs/modules/Components.html#define-new-component [16]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/undefined + +[17]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number