- Docs(imagelib): JSDocs for extension

This commit is contained in:
Brett Zamir
2020-01-04 16:45:18 +08:00
parent 77eb85e91c
commit d7d6b87255

View File

@@ -75,8 +75,38 @@ export default {
let transferStopped = false;
let preview, submit;
// Receive `postMessage` data
window.addEventListener('message', async function ({origin, data: response}) { // eslint-disable-line no-shadow
/**
* @typedef {PlainObject} ImageLibMessage
* @property {"imagelib"} namespace Required to distinguish from any other messages of app.
* @property {string} href Set to same value as previous `ImageLibMetaMessage` `id`.
* @property {string} data The response (as an SVG string or URL)
*/
/**
* @typedef {PlainObject} ImageLibMetaMessage
* @property {"imagelib"} namespace Required to distinguish from any other messages of app.
* @property {string} name If the subsequent response is an SVG string or if `preview_url`
* is present, will be used as the title for the preview image. When an
* SVG string is present, will default to the first `<title>`'s contents or
* "(SVG #<Length of response>)" if none is present. Otherwise, if `preview_url`
* is present, will default to the empty string.
* @property {string} id Identifier (the expected `href` for a subsequent response message);
* used for ensuring the subsequent response can be tied to this `ImageLibMetaMessage` object.
* @property {string} [preview_url] Used to set an image source along with the
* name/title. If the subsequent response is an SVG string and there is no `preview_url`,
* the default will just be to show the name/title. If the response is not an SVG
* string, the default will be to show that response (i.e., the URL).
* @property {string} entry Set automatically with div holding retrieving message (until ready to delete)
* @todo Should use a separate Map instead of `entry`
*/
/**
* @param {PlainObject} cfg
* @param {string} cfg.origin
* @param {ImageLibMetaMessage|ImageLibMessage|string} cfg.data String is deprecated when parsed to JSON `ImageLibMessage`
* @returns {void}
*/
async function onMessage ({origin, data: response}) { // eslint-disable-line no-shadow
if (!response || !['string', 'object'].includes(typeof response)) {
// Do nothing
return;
@@ -283,7 +313,10 @@ export default {
break;
}
}
}, true);
}
// Receive `postMessage` data
window.addEventListener('message', onMessage, true);
/**
* @param {boolean} show