- Linting (ESLint): Stricter rules (or switch to warning)
- Breaking internal API change: `updateGripCursor` moved to be class method of Selector rather than instance method - Breaking internal API change: `subpathIsClosed` moved to be class method of `Path` rather than instance method - Refactoring: Reuse utilities base64 encoder for SVG icons plugin - Docs (JSDoc): Fix return of the `mouseUp` (can also be an object) and `mouseDown` (may also be a boolean) of `pathActions`; other JSDoc additions/improvements
This commit is contained in:
@@ -5,12 +5,23 @@
|
||||
* @module importModule
|
||||
*/
|
||||
|
||||
/**
|
||||
* Converts a possible relative URL into an absolute one.
|
||||
* @param {string} url
|
||||
* @returns {string}
|
||||
*/
|
||||
function toAbsoluteURL (url) {
|
||||
const a = document.createElement('a');
|
||||
a.setAttribute('href', url); // <a href="hoge.html">
|
||||
return a.cloneNode(false).href; // -> "http://example.com/hoge.html"
|
||||
}
|
||||
|
||||
/**
|
||||
* Add any of the whitelisted attributes to the script tag.
|
||||
* @param {HTMLScriptElement} script
|
||||
* @param {PlainObject.<string, string>} atts
|
||||
* @returns {undefined}
|
||||
*/
|
||||
function addScriptAtts (script, atts) {
|
||||
['id', 'class', 'type'].forEach((prop) => {
|
||||
if (prop in atts) {
|
||||
@@ -27,18 +38,19 @@ function addScriptAtts (script, atts) {
|
||||
*/
|
||||
/**
|
||||
* @function module:importModule.importSetGlobalDefault
|
||||
* @param {string} url
|
||||
* @param {string|string[]} url
|
||||
* @param {module:importModule.ImportConfig} config
|
||||
* @returns {*} The return depends on the export of the targeted module.
|
||||
* @returns {Promise} The value to which it resolves depends on the export of the targeted module.
|
||||
*/
|
||||
export async function importSetGlobalDefault (url, config) {
|
||||
export function importSetGlobalDefault (url, config) {
|
||||
return importSetGlobal(url, {...config, returnDefault: true});
|
||||
}
|
||||
/**
|
||||
* @function module:importModule.importSetGlobal
|
||||
* @param {string} url
|
||||
* @param {string|string[]} url
|
||||
* @param {module:importModule.ImportConfig} config
|
||||
* @returns {ArbitraryModule|*} The return depends on the export of the targeted module.
|
||||
* @returns {Promise} The promise resolves to either an `ArbitraryModule` or
|
||||
* any other value depends on the export of the targeted module.
|
||||
*/
|
||||
export async function importSetGlobal (url, {global, returnDefault}) {
|
||||
// Todo: Replace calls to this function with `import()` when supported
|
||||
@@ -51,14 +63,21 @@ export async function importSetGlobal (url, {global, returnDefault}) {
|
||||
await importScript(url);
|
||||
return window[global];
|
||||
}
|
||||
// Addition by Brett
|
||||
/**
|
||||
*
|
||||
* @author Brett Zamir (other items are from `dynamic-import-polyfill`)
|
||||
* @param {string|string[]} url
|
||||
* @param {Object} [atts={}]
|
||||
* @returns {Promise} Resolves to `undefined` or rejects with an `Error` upon a
|
||||
* script loading error
|
||||
*/
|
||||
export function importScript (url, atts = {}) {
|
||||
if (Array.isArray(url)) {
|
||||
return Promise.all(url.map((u) => {
|
||||
return importScript(u, atts);
|
||||
}));
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
return new Promise((resolve, reject) => { // eslint-disable-line promise/avoid-new
|
||||
const script = document.createElement('script');
|
||||
const destructor = () => {
|
||||
script.onerror = null;
|
||||
@@ -82,13 +101,22 @@ export function importScript (url, atts = {}) {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string|string[]} url
|
||||
* @param {Object} [atts={}]
|
||||
* @param {PlainObject} opts
|
||||
* @param {boolean} [opts.returnDefault=false} = {}]
|
||||
* @returns {Promise} Resolves to value of loading module or rejects with
|
||||
* `Error` upon a script loading error.
|
||||
*/
|
||||
export function importModule (url, atts = {}, {returnDefault = false} = {}) {
|
||||
if (Array.isArray(url)) {
|
||||
return Promise.all(url.map((u) => {
|
||||
return importModule(u, atts);
|
||||
}));
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
return new Promise((resolve, reject) => { // eslint-disable-line promise/avoid-new
|
||||
const vector = '$importModule$' + Math.random().toString(32).slice(2);
|
||||
const script = document.createElement('script');
|
||||
const destructor = () => {
|
||||
|
||||
Reference in New Issue
Block a user