Browse Source

Fix API docs generation

type-event-callbacks
Artur Arseniev 1 month ago
parent
commit
698acd97b6
  1. 19
      docs/api.mjs
  2. 2
      docs/api/assets.md
  3. 16
      docs/api/canvas.md
  4. 4
      docs/api/commands.md
  5. 21
      docs/api/datasources.md
  6. 8
      docs/api/device_manager.md
  7. 6
      docs/api/layer_manager.md
  8. 2
      docs/api/rich_text_editor.md
  9. 2
      docs/api/selector_manager.md

19
docs/api.mjs

@ -15,13 +15,28 @@ const REPLACE_EVENTS = '{REPLACE\\_EVENTS}';
const log = (...args) => console.log(...args);
const hasTemplateLiteralType = (value) => {
if (!value || typeof value !== 'object') return false;
if (value.type === 'TemplateLiteralType') return true;
return Object.values(value).some((item) =>
Array.isArray(item) ? item.some((nested) => hasTemplateLiteralType(nested)) : hasTemplateLiteralType(item),
);
};
const sanitizeUnsupportedTypes = (comments = []) =>
comments.map((comment) =>
comment.kind === 'typedef' && hasTemplateLiteralType(comment.type)
? { ...comment, type: { type: 'NameExpression', name: 'string' } }
: comment,
);
const getEventsMdFromTypes = async (filePath) => {
const dirname = filePath.replace(basename(filePath), '');
const typesFilePath = `${dirname}types.ts`;
if (existsSync(typesFilePath)) {
const resTypes = await build([typesFilePath], { shallow: true }).then((cm) =>
formats.md(cm /*{ markdownToc: true }*/),
formats.md(sanitizeUnsupportedTypes(cm) /*{ markdownToc: true }*/),
);
const indexFrom = resTypes.indexOf(START_EVENTS) + START_EVENTS.length;
const indexTo = resTypes.indexOf(END_EVENTS);
@ -31,10 +46,12 @@ const getEventsMdFromTypes = async (filePath) => {
.replace(/\n### Examples\n/gi, '')
.replace(/\n## types\n/gi, '')
.replace(/## /gi, '* ')
.replace(/^\* [A-Za-z][A-Za-z0-9]*Event\s*$/gm, '')
.replace(/\\`/gi, '`')
.replace(/##/gi, '')
.replace(/\\\[/gi, '[')
.replace(/\]\\\(/gi, '](')
.replace(/\n{3,}/g, '\n\n')
.trim();
return result;

2
docs/api/assets.md

@ -85,6 +85,8 @@ editor.on('asset:custom', ({ container, assets, ... }) => { ... });
editor.on('asset', ({ event, model, ... }) => { ... });
```
* AssetsEventCallback
## Methods
* [open][2]

16
docs/api/canvas.md

@ -24,11 +24,11 @@ canvas.setCoords(...);
```
## Available Events
* `canvas:dragenter` Something is dragged inside the canvas, `DataTransfer` instance passed as an argument.
* `canvas:dragenter` Something is dragged inside the canvas. `DataTransfer` instance and dragged content are passed as arguments.
* `canvas:dragover` Something is dragging on the canvas, `DataTransfer` instance passed as an argument.
* `canvas:dragover` Something is dragging on the canvas. Triggering event is passed as an argument.
* `canvas:dragend` When a drag operation is ended, `DataTransfer` instance passed as an argument.
* `canvas:dragend` When a drag operation is ended, triggering event is passed as an argument.
* `canvas:dragdata` On any dataTransfer parse, `DataTransfer` instance and the `result` are passed as arguments. By changing `result.content` you're able to customize what is dropped.
@ -98,6 +98,16 @@ editor.on('canvas:refresh', (canvasRefreshOptions) => {
});
```
* `canvas:update` Canvas was updated.
* `canvas:tools:update` Canvas tools were updated.
* `canvas:move:start` Canvas move started.
* `canvas:move` Canvas is moving.
* `canvas:move:end` Canvas move ended.
* `canvas:frame:load` Frame loaded in canvas. The event is triggered right after iframe's `onload`.
```javascript

4
docs/api/commands.md

@ -16,7 +16,7 @@ Once the editor is instantiated you can use its API and listen to its events. Be
```js
// Listen to events
editor.on('run', () => { ... });
editor.on('command:run', () => { ... });
// Use the API
const commands = editor.Commands;
@ -91,6 +91,8 @@ editor.on('command:call', ({ id, result, options, type }) => {
editor.on('command:call:my-command', ({ result, options, type }) => { ... });
```
* CommandEventOptions
## Methods
* [add][2]

21
docs/api/datasources.md

@ -113,6 +113,18 @@ const ds = dsm.get('my_data_source_id');
Returns **[DataSource]** Data source.
## getAll
Return all data sources.
### Examples
```javascript
const ds = dsm.getAll();
```
Returns **[Array][8]<[DataSource]>**&#x20;
## getValue
Get value from data sources by path.
@ -121,6 +133,7 @@ Get value from data sources by path.
* `path` **[String][7]** Path to value.
* `defValue` **any** Default value if the path is not found.
* `opts` **{context: Record<[string][7], any>?}?**&#x20;
Returns **any** const value = dsm.getValue('ds\_id.record\_id.propName', 'defaultValue');
@ -139,7 +152,7 @@ Set value in data sources by path.
dsm.setValue('ds_id.record_id.propName', 'new value');
```
Returns **[Boolean][8]** Returns true if the value was set successfully
Returns **[Boolean][9]** Returns true if the value was set successfully
## remove
@ -183,7 +196,7 @@ data record, and optional property path.
Store data sources to a JSON object.
Returns **[Array][9]** Stored data sources.
Returns **[Array][8]** Stored data sources.
## load
@ -209,6 +222,6 @@ Returns **[Object][6]** Loaded data sources.
[7]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String
[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean
[8]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array
[9]: https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Boolean

8
docs/api/device_manager.md

@ -31,16 +31,16 @@ editor.on('device:add', (device) => { ... });
editor.on('device:remove', (device) => { ... });
```
* `device:select` A new device is selected. The `Device` is passed as an argument.
* `device:select` A new device is selected. Current and previous `Device` are passed as arguments.
```javascript
editor.on('device:select', (device) => { ... });
editor.on('device:select', (newDevice, prevDevice) => { ... });
```
* `device:update` Device updated. The `Device` and the object containing changes are passed as arguments.
* `device:update` Device updated. The `Device`, changed properties, and update options are passed as arguments.
```javascript
editor.on('device:update', (device) => { ... });
editor.on('device:update', (device, changes, options) => { ... });
```
* `device` Catch-all event for all the events mentioned above.

6
docs/api/layer_manager.md

@ -38,6 +38,12 @@ editor.on('layer:component', (component, opts) => { ... });
editor.on('layer:custom', ({ container, root }) => { ... });
```
* `layer:render` Component layer rendered. Object with component and rendered layer element is passed as an argument.
```javascript
editor.on('layer:render', ({ component, el }) => { ... });
```
## Methods
* [setRoot][1]

2
docs/api/rich_text_editor.md

@ -40,6 +40,8 @@ editor.on('rte:disable', (view, rte) => { ... });
editor.on('rte:custom', ({ enabled, container, actions }) => { ... });
```
* RichTextEditorEventCallback
## Methods
* [add][3]

2
docs/api/selector_manager.md

@ -84,8 +84,6 @@ editor.on('selector:custom', ({ states, selected, container }) => { ... });
editor.on('selector', ({ event, selector, changes, ... }) => { ... });
```
* SelectorStringObject
## Methods
* [getConfig][2]

Loading…
Cancel
Save