UNPKG

@wordpress/interactivity-router

Version:

Package that exposes state and actions from the `core/router` store, part of the Interactivity API.

91 lines (86 loc) 2.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "importPreloadedModule", { enumerable: true, get: function () { return _loader.importPreloadedModule; } }); exports.importWithMap = importWithMap; Object.defineProperty(exports, "initialImportMap", { enumerable: true, get: function () { return _loader.initialImportMap; } }); exports.preloadWithMap = preloadWithMap; var _resolver = require("./resolver"); var _loader = require("./loader"); /** * This code is derived from the following projects: * * 1. dynamic-importmap (https://github.com/keller-mark/dynamic-importmap) * 2. es-module-shims (https://github.com/guybedford/es-module-shims) * * The original implementation was created by Guy Bedford in es-module-shims, * then adapted by Mark Keller in dynamic-importmap, and further modified * for use in this project. * * Both projects are licensed under the MIT license. * * MIT License: https://opensource.org/licenses/MIT */ /** * Internal dependencies */ // TODO: check if this baseURI should change per document, and so // it need to be passed as a parameter to methods like `importWithMap` // and `preloadWithMap`. const baseUrl = document.baseURI; const pageBaseUrl = baseUrl; Object.defineProperty(self, 'wpInteractivityRouterImport', { value: importShim, writable: false, enumerable: false, configurable: false }); async function importShim(id) { await _loader.initPromise; return (0, _loader.topLevelLoad)((0, _resolver.resolve)(id, pageBaseUrl), { credentials: 'same-origin' }); } /** * Imports the module with the passed ID. * * The module is resolved against the internal dynamic import map, * extended with the passed import map. * * @param id Module ID. * @param importMapIn Import map. * @return Resolved module. */ async function importWithMap(id, importMapIn) { (0, _resolver.addImportMap)(importMapIn); return importShim(id); } /** * Preloads the module with the passed ID along with its dependencies. * * The module is resolved against the internal dynamic import map, * extended with the passed import map. * * @param id Module ID. * @param importMapIn Import map. * @return Resolved `ModuleLoad` instance. */ async function preloadWithMap(id, importMapIn) { (0, _resolver.addImportMap)(importMapIn); await _loader.initPromise; return (0, _loader.preloadModule)((0, _resolver.resolve)(id, pageBaseUrl), { credentials: 'same-origin' }); } //# sourceMappingURL=index.js.map