diff --git a/docs/api.js b/docs/api.js index 13d080299..6fa9290bb 100644 --- a/docs/api.js +++ b/docs/api.js @@ -40,6 +40,7 @@ async function generateDocs () { .then(output => { const res = output .replace(/\*\*\\\[/g, '**[') + .replace(/\*\*\(\\\[/g, '**([') .replace(/<\\\[/g, '<[') .replace(/\| \\\[/g, '| [') .replace('**Extends Model**', ''); diff --git a/docs/api/device_manager.md b/docs/api/device_manager.md index 175af4a37..713d90c30 100644 --- a/docs/api/device_manager.md +++ b/docs/api/device_manager.md @@ -30,7 +30,10 @@ const deviceManager = editor.Devices; * [add][2] * [get][3] -* [getAll][4] +* [getDevices][4] +* [remove][5] +* [select][6] +* [getSelected][7] [Device]: device.html @@ -40,7 +43,7 @@ Add new device ### Parameters -* `props` **[Object][5]** Device properties +* `props` **[Object][8]** Device properties * `options` (optional, default `{}`) ### Examples @@ -65,11 +68,11 @@ Returns **[Device]** Added device ## get -Return device by name +Return device by ID ### Parameters -* `name` **[String][6]** Name of the device +* `id` **[String][9]** ID of the device ### Examples @@ -79,7 +82,27 @@ console.log(JSON.stringify(device)); // {name: 'Tablet', width: '900px'} ``` -Returns **[Device]** +Returns **([Device] | null)** + +## remove + +Remove device + +### Parameters + +* `device` **([String][9] | [Device])** Device or device id +* `opts` (optional, default `{}`) + +### Examples + +```javascript +const removed = deviceManager.remove('device-id'); +// or by passing the Device +const device = deviceManager.get('device-id'); +deviceManager.remove(device); +``` + +Returns **[Device]** Removed device ## getDevices @@ -93,7 +116,37 @@ console.log(JSON.stringify(devices)); // [{name: 'Desktop', width: ''}, ...] ``` -Returns **[Array][7]<[Device]>** +Returns **[Array][10]<[Device]>** + +## select + +Change the selected device. This will update the frame in the canvas + +### Parameters + +* `device` **([String][9] | [Device])** Device or device id +* `opts` (optional, default `{}`) + +### Examples + +```javascript +deviceManager.select('some-id'); +// or by passing the page +const device = deviceManager.get('some-id'); +deviceManager.select(device); +``` + +## getSelected + +Get the selected device + +### Examples + +```javascript +const selected = deviceManager.getSelected(); +``` + +Returns **[Device]** [1]: https://github.com/artf/grapesjs/blob/master/src/device_manager/config/config.js @@ -101,10 +154,16 @@ Returns **[Array][7]<[Device]>** [3]: #get -[4]: #getAll +[4]: #getdevices + +[5]: #remove + +[6]: #select + +[7]: #getselected -[5]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object +[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object -[6]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String +[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String -[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array +[10]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array diff --git a/docs/api/editor.md b/docs/api/editor.md index ac9501ab3..a772c059d 100644 --- a/docs/api/editor.md +++ b/docs/api/editor.md @@ -751,7 +751,7 @@ Returns **[String][5]** [1]: https://github.com/artf/grapesjs/blob/master/src/editor/config/config.js -[2]: /api/devices.html +[2]: /api/device_manager.html [3]: /api/parser.html diff --git a/src/editor/index.js b/src/editor/index.js index 8f2af9103..28bc4ef8a 100644 --- a/src/editor/index.js +++ b/src/editor/index.js @@ -97,7 +97,7 @@ * * `run` - Triggered on run of any command. The id and the result are passed as arguments to the callback * * `stop` - Triggered on stop of any command. The id and the result are passed as arguments to the callback * ### Devices - * Check the [Devices](/api/devices.html) module. + * Check the [Devices](/api/device_manager.html) module. * ### Parser * Check the [Parser](/api/parser.html) module. * ### Pages