diff --git a/docs/api.mjs b/docs/api.mjs index 6ad7b70e2..d68d9c18f 100644 --- a/docs/api.mjs +++ b/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; diff --git a/docs/api/assets.md b/docs/api/assets.md index 637d1fef3..37a235080 100644 --- a/docs/api/assets.md +++ b/docs/api/assets.md @@ -85,6 +85,8 @@ editor.on('asset:custom', ({ container, assets, ... }) => { ... }); editor.on('asset', ({ event, model, ... }) => { ... }); ``` +* AssetsEventCallback + ## Methods * [open][2] diff --git a/docs/api/canvas.md b/docs/api/canvas.md index c82ef3a82..cb48c5756 100644 --- a/docs/api/canvas.md +++ b/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 diff --git a/docs/api/commands.md b/docs/api/commands.md index 20491ad7c..32ee5cbb3 100644 --- a/docs/api/commands.md +++ b/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] diff --git a/docs/api/datasources.md b/docs/api/datasources.md index 108caa2e3..ae853a24b 100644 --- a/docs/api/datasources.md +++ b/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]>** + ## 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>?}?** 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 diff --git a/docs/api/device_manager.md b/docs/api/device_manager.md index 4a6f6e914..47c2c2a0e 100644 --- a/docs/api/device_manager.md +++ b/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. diff --git a/docs/api/layer_manager.md b/docs/api/layer_manager.md index 8ae97605e..ea5f42fc1 100644 --- a/docs/api/layer_manager.md +++ b/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] diff --git a/docs/api/rich_text_editor.md b/docs/api/rich_text_editor.md index d002ad9fd..870a075bc 100644 --- a/docs/api/rich_text_editor.md +++ b/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] diff --git a/docs/api/selector_manager.md b/docs/api/selector_manager.md index 9d5630ba6..6ad1fc8ed 100644 --- a/docs/api/selector_manager.md +++ b/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]