@wordpress/interactivity-router 2.24.0 → 2.26.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +22 -0
  3. package/build/assets/dynamic-importmap/fetch.js +60 -0
  4. package/build/assets/dynamic-importmap/fetch.js.map +1 -0
  5. package/build/assets/dynamic-importmap/index.js +91 -0
  6. package/build/assets/dynamic-importmap/index.js.map +1 -0
  7. package/build/assets/dynamic-importmap/loader.js +286 -0
  8. package/build/assets/dynamic-importmap/loader.js.map +1 -0
  9. package/build/assets/dynamic-importmap/resolver.js +220 -0
  10. package/build/assets/dynamic-importmap/resolver.js.map +1 -0
  11. package/build/assets/script-modules.js +64 -0
  12. package/build/assets/script-modules.js.map +1 -0
  13. package/build/assets/scs.js +62 -0
  14. package/build/assets/scs.js.map +1 -0
  15. package/build/assets/styles.js +246 -0
  16. package/build/assets/styles.js.map +1 -0
  17. package/build/full-page.js +43 -0
  18. package/build/full-page.js.map +1 -0
  19. package/build/index.js +141 -112
  20. package/build/index.js.map +1 -1
  21. package/build-module/assets/dynamic-importmap/fetch.js +54 -0
  22. package/build-module/assets/dynamic-importmap/fetch.js.map +1 -0
  23. package/build-module/assets/dynamic-importmap/index.js +72 -0
  24. package/build-module/assets/dynamic-importmap/index.js.map +1 -0
  25. package/build-module/assets/dynamic-importmap/loader.js +279 -0
  26. package/build-module/assets/dynamic-importmap/loader.js.map +1 -0
  27. package/build-module/assets/dynamic-importmap/resolver.js +213 -0
  28. package/build-module/assets/dynamic-importmap/resolver.js.map +1 -0
  29. package/build-module/assets/script-modules.js +55 -0
  30. package/build-module/assets/script-modules.js.map +1 -0
  31. package/build-module/assets/scs.js +56 -0
  32. package/build-module/assets/scs.js.map +1 -0
  33. package/build-module/assets/styles.js +235 -0
  34. package/build-module/assets/styles.js.map +1 -0
  35. package/build-module/full-page.js +39 -0
  36. package/build-module/full-page.js.map +1 -0
  37. package/build-module/index.js +138 -107
  38. package/build-module/index.js.map +1 -1
  39. package/build-types/assets/dynamic-importmap/fetch.d.ts +30 -0
  40. package/build-types/assets/dynamic-importmap/fetch.d.ts.map +1 -0
  41. package/build-types/assets/dynamic-importmap/index.d.ts +42 -0
  42. package/build-types/assets/dynamic-importmap/index.d.ts.map +1 -0
  43. package/build-types/assets/dynamic-importmap/loader.d.ts +68 -0
  44. package/build-types/assets/dynamic-importmap/loader.d.ts.map +1 -0
  45. package/build-types/assets/dynamic-importmap/resolver.d.ts +35 -0
  46. package/build-types/assets/dynamic-importmap/resolver.d.ts.map +1 -0
  47. package/build-types/assets/script-modules.d.ts +26 -0
  48. package/build-types/assets/script-modules.d.ts.map +1 -0
  49. package/build-types/assets/scs.d.ts +24 -0
  50. package/build-types/assets/scs.d.ts.map +1 -0
  51. package/build-types/assets/styles.d.ts +69 -0
  52. package/build-types/assets/styles.d.ts.map +1 -0
  53. package/build-types/full-page.d.ts +3 -0
  54. package/build-types/full-page.d.ts.map +1 -0
  55. package/build-types/index.d.ts +4 -5
  56. package/build-types/index.d.ts.map +1 -1
  57. package/package.json +9 -5
  58. package/src/assets/dynamic-importmap/fetch.ts +58 -0
  59. package/src/assets/dynamic-importmap/index.ts +87 -0
  60. package/src/assets/dynamic-importmap/loader.ts +366 -0
  61. package/src/assets/dynamic-importmap/resolver.ts +292 -0
  62. package/src/assets/script-modules.ts +69 -0
  63. package/src/assets/scs.ts +61 -0
  64. package/src/assets/styles.ts +272 -0
  65. package/src/assets/test/scs.test.ts +367 -0
  66. package/src/assets/test/styles.test.ts +758 -0
  67. package/src/full-page.ts +53 -0
  68. package/src/index.ts +160 -135
  69. package/tsconfig.full-page.json +12 -0
  70. package/tsconfig.full-page.tsbuildinfo +1 -0
  71. package/tsconfig.json +9 -4
  72. package/tsconfig.main.json +21 -0
  73. package/tsconfig.main.tsbuildinfo +1 -0
  74. package/build/head.js +0 -113
  75. package/build/head.js.map +0 -1
  76. package/build-module/head.js +0 -103
  77. package/build-module/head.js.map +0 -1
  78. package/build-types/head.d.ts +0 -24
  79. package/build-types/head.d.ts.map +0 -1
  80. package/src/head.ts +0 -126
  81. package/tsconfig.tsbuildinfo +0 -1
@@ -0,0 +1,35 @@
1
+ /**
2
+ * This code is derived from the following projects:
3
+ *
4
+ * 1. dynamic-importmap (https://github.com/keller-mark/dynamic-importmap)
5
+ * 2. es-module-shims (https://github.com/guybedford/es-module-shims)
6
+ *
7
+ * The original implementation was created by Guy Bedford in es-module-shims,
8
+ * then adapted by Mark Keller in dynamic-importmap, and further modified
9
+ * for use in this project.
10
+ *
11
+ * Both projects are licensed under the MIT license.
12
+ *
13
+ * MIT License: https://opensource.org/licenses/MIT
14
+ */
15
+ /**
16
+ * Extends the internal dynamic import map with the passed one.
17
+ *
18
+ * @param importMapIn Import map.
19
+ * @param importMapIn.imports Imports declaration.
20
+ * @param importMapIn.scopes Scopes declaration.
21
+ */
22
+ export declare function addImportMap(importMapIn: {
23
+ imports?: Record<string, string>;
24
+ scopes?: Record<string, any>;
25
+ }): void;
26
+ /**
27
+ * Resolves the URL of the passed module ID against the current internal
28
+ * dynamic import map.
29
+ *
30
+ * @param id Module ID.
31
+ * @param parentUrl Parent URL, in case the module ID is relative.
32
+ * @return Resolved module URL.
33
+ */
34
+ export declare function resolve(id: string, parentUrl: string): string;
35
+ //# sourceMappingURL=resolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolver.d.ts","sourceRoot":"","sources":["../../../src/assets/dynamic-importmap/resolver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAyPH;;;;;;GAMG;AACH,wBAAgB,YAAY,CAAE,WAAW,EAAE;IAC1C,OAAO,CAAC,EAAE,MAAM,CAAE,MAAM,EAAE,MAAM,CAAE,CAAC;IACnC,MAAM,CAAC,EAAE,MAAM,CAAE,MAAM,EAAE,GAAG,CAAE,CAAC;CAC/B,QAMA;AAED;;;;;;;GAOG;AACH,wBAAgB,OAAO,CAAE,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAI,MAAM,CAG/D"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ import { type ModuleLoad } from './dynamic-importmap';
5
+ /**
6
+ * Marks the specified module as natively resolved.
7
+ * @param url Script module URL.
8
+ */
9
+ export declare const markScriptModuleAsResolved: (url: string) => void;
10
+ /**
11
+ * Resolves and fetches modules present in the passed document, using the
12
+ * document's import map to resolve them.
13
+ *
14
+ * @param doc Document containing the modules to preload.
15
+ * @return Array of promises that resolve to a `ScriptModuleLoad` instance.
16
+ */
17
+ export declare const preloadScriptModules: (doc: Document) => Promise<ModuleLoad>[];
18
+ /**
19
+ * Imports modules respresented by the passed `ScriptModuleLoad` instances.
20
+ *
21
+ * @param modules Array of `MoudleLoad` instances.
22
+ * @return Promise that resolves once all modules are imported.
23
+ */
24
+ export declare const importScriptModules: (modules: ScriptModuleLoad[]) => Promise<unknown[]>;
25
+ export type ScriptModuleLoad = ModuleLoad;
26
+ //# sourceMappingURL=script-modules.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"script-modules.d.ts","sourceRoot":"","sources":["../../src/assets/script-modules.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAIN,KAAK,UAAU,EACf,MAAM,qBAAqB,CAAC;AAQ7B;;;GAGG;AACH,eAAO,MAAM,0BAA0B,QAAU,MAAM,SAEtD,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,QAAU,QAAQ,0BA0BlD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,YAAc,gBAAgB,EAAE,uBACE,CAAC;AAEnE,MAAM,MAAM,gBAAgB,GAAG,UAAU,CAAC"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Calculates the Shortest Common Supersequence (SCS) of two sequences.
3
+ *
4
+ * A supersequence is a sequence that contains both input sequences as subsequences.
5
+ * The shortest common supersequence is the shortest possible such sequence.
6
+ *
7
+ * This implementation uses dynamic programming with a time complexity of O(mn)
8
+ * and space complexity of O(mn), where m and n are the lengths of sequences X and Y.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * const seq1 = [1, 3, 5];
13
+ * const seq2 = [2, 3, 4];
14
+ * const scs = shortestCommonSupersequence(seq1, seq2); // [1, 2, 3, 4, 5]
15
+ * ```
16
+ *
17
+ * @param X The first sequence.
18
+ * @param Y The second sequence.
19
+ * @param isEqual Optional equality function to compare elements.
20
+ * Defaults to strict equality (===).
21
+ * @return The shortest common supersequence of X and Y.
22
+ */
23
+ export declare function shortestCommonSupersequence<E = unknown>(X: E[], Y: E[], isEqual?: (a: E, b: E) => boolean): E[];
24
+ //# sourceMappingURL=scs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scs.d.ts","sourceRoot":"","sources":["../../src/assets/scs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,2BAA2B,CAAE,CAAC,GAAG,OAAO,EACvD,CAAC,EAAE,CAAC,EAAE,EACN,CAAC,EAAE,CAAC,EAAE,EACN,OAAO,OAAQ,CAAC,KAAK,CAAC,YAAa,OAmCnC"}
@@ -0,0 +1,69 @@
1
+ export type StyleElement = HTMLLinkElement | HTMLStyleElement;
2
+ /**
3
+ * Normalizes the passed style or link element, reverting the changes
4
+ * made by {@link prepareStylePromise|`prepareStylePromise`} to the
5
+ * `data-original-media` and `media`.
6
+ *
7
+ * @example
8
+ * The following elements should be normalized to the same element:
9
+ * ```html
10
+ * <link rel="stylesheet" src="./assets/styles.css">
11
+ * <link rel="stylesheet" src="./assets/styles.css" media="all">
12
+ * <link rel="stylesheet" src="./assets/styles.css" media="preload">
13
+ * <link rel="stylesheet" src="./assets/styles.css" media="preload" data-original-media="all">
14
+ * ```
15
+ *
16
+ * @param element `<style>` or `<link>` element.
17
+ * @return Normalized node.
18
+ */
19
+ export declare const normalizeMedia: (element: StyleElement) => StyleElement;
20
+ /**
21
+ * Adds the minimum style elements from Y around those in X using a
22
+ * shortest common supersequence algorithm, returning a list of
23
+ * promises for all the elements in Y.
24
+ *
25
+ * If X is empty, it appends all elements in Y to the passed parent
26
+ * element or to `document.head` instead.
27
+ *
28
+ * The returned promises resolve once the corresponding style element
29
+ * is loaded and ready. Those elements that are also in X return a
30
+ * cached promise.
31
+ *
32
+ * The algorithm ensures that the final style elements present in the
33
+ * document (or the passed `parent` element) are in the correct order
34
+ * and they are included in either X or Y.
35
+ *
36
+ * @param X Base list of style elements.
37
+ * @param Y List of style elements.
38
+ * @param parent Optional parent element to append to the new style elements.
39
+ * @return List of promises that resolve once the elements in Y are ready.
40
+ */
41
+ export declare function updateStylesWithSCS(X: StyleElement[], Y: StyleElement[], parent?: Element): any[];
42
+ /**
43
+ * Prepares all style elements contained in the passed document.
44
+ *
45
+ * This function calls {@link updateStylesWithSCS|`updateStylesWithSCS`}
46
+ * to insert only the minimum amount of style elements into the DOM, so
47
+ * those present in the passed document end up in the DOM while the order
48
+ * is respected.
49
+ *
50
+ * New appended style elements contain a `media=preload` attribute to
51
+ * make them effectively disabled until they are applied with the
52
+ * {@link applyStyles|`applyStyles`} function.
53
+ *
54
+ * @param doc Document instance.
55
+ * @param url URL for the passed document.
56
+ * @return A list of promises for each style element in the passed document.
57
+ */
58
+ export declare const preloadStyles: (doc: Document, url: string) => Promise<StyleElement>[];
59
+ /**
60
+ * Traverses all style elements in the DOM, enabling only those included
61
+ * in the passed list and disabling the others.
62
+ *
63
+ * If the style element has the `data-original-media` attribute, the
64
+ * original `media` value is restored.
65
+ *
66
+ * @param styles List of style elements to apply.
67
+ */
68
+ export declare const applyStyles: (styles: StyleElement[]) => void;
69
+ //# sourceMappingURL=styles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../src/assets/styles.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,YAAY,GAAG,eAAe,GAAG,gBAAgB,CAAC;AAa9D;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,cAAc,YAAc,YAAY,KAAI,YAYxD,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,mBAAmB,CAClC,CAAC,EAAE,YAAY,EAAE,EACjB,CAAC,EAAE,YAAY,EAAE,EACjB,MAAM,GAAE,OAA8B,SAqDtC;AAiFD;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,aAAa,QACpB,QAAQ,OACR,MAAM,KACT,OAAO,CAAE,YAAY,CAAE,EAoBzB,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,WAAW,WAAa,YAAY,EAAE,SAclD,CAAC"}
@@ -0,0 +1,3 @@
1
+ declare const isValidLink: (ref: HTMLAnchorElement) => boolean;
2
+ declare const isValidEvent: (event: MouseEvent) => boolean;
3
+ //# sourceMappingURL=full-page.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"full-page.d.ts","sourceRoot":"","sources":["../src/full-page.ts"],"names":[],"mappings":"AACA,QAAA,MAAM,WAAW,QAAU,iBAAiB,YASS,CAAC;AAGtD,QAAA,MAAM,YAAY,UAAY,UAAU,YAOf,CAAC"}
@@ -1,4 +1,4 @@
1
- interface NavigateOptions {
1
+ export interface NavigateOptions {
2
2
  force?: boolean;
3
3
  html?: string;
4
4
  replace?: boolean;
@@ -6,7 +6,7 @@ interface NavigateOptions {
6
6
  loadingAnimation?: boolean;
7
7
  screenReaderAnnouncement?: boolean;
8
8
  }
9
- interface PrefetchOptions {
9
+ export interface PrefetchOptions {
10
10
  force?: boolean;
11
11
  html?: string;
12
12
  }
@@ -17,8 +17,7 @@ export declare const state: {
17
17
  hasFinished: boolean;
18
18
  };
19
19
  }, actions: {
20
- navigate: (href: string, options?: NavigateOptions) => void;
21
- prefetch: (url: string, options?: PrefetchOptions) => void;
20
+ navigate: (href: string, options?: NavigateOptions) => Promise<void>;
21
+ prefetch: (url: string, options?: PrefetchOptions) => Promise<void>;
22
22
  };
23
- export {};
24
23
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAuBA,UAAU,eAAe;IACxB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,wBAAwB,CAAC,EAAE,OAAO,CAAC;CACnC;AAED,UAAU,eAAe;IACxB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;CACd;AAwMD,eAAO,MAAQ,KAAK;SAZb,MAAM;;oBAEE,OAAO;qBACN,OAAO;;GASD,OAAO;cALjB,CAAE,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,KAAM,IAAI;cACnD,CAAE,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,KAAM,IAAI;CAgJ3D,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAiCA,MAAM,WAAW,eAAe;IAC/B,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,wBAAwB,CAAC,EAAE,OAAO,CAAC;CACnC;AAED,MAAM,WAAW,eAAe;IAC/B,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;CACd;AAiPD,eAAO,MAAQ,KAAK;SAfb,MAAM;;oBAEE,OAAO;qBACN,OAAO;;GAYD,OAAO;cARjB,CACT,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,eAAe,KACrB,OAAO,CAAE,IAAI,CAAE;cACV,CAAE,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,eAAe,KAAM,OAAO,CAAE,IAAI,CAAE;CAqJtE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/interactivity-router",
3
- "version": "2.24.0",
3
+ "version": "2.26.0",
4
4
  "description": "Package that exposes state and actions from the `core/router` store, part of the Interactivity API.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -25,14 +25,18 @@
25
25
  "main": "build/index.js",
26
26
  "module": "build-module/index.js",
27
27
  "react-native": "src/index",
28
- "wpScriptModuleExports": "./build-module/index.js",
28
+ "wpScriptModuleExports": {
29
+ ".": "./build-module/index.js",
30
+ "./full-page": "./build-module/full-page.js"
31
+ },
29
32
  "types": "build-types",
30
33
  "dependencies": {
31
- "@wordpress/a11y": "^4.24.0",
32
- "@wordpress/interactivity": "^6.24.0"
34
+ "@wordpress/a11y": "^4.26.0",
35
+ "@wordpress/interactivity": "^6.26.0",
36
+ "es-module-lexer": "^1.5.4"
33
37
  },
34
38
  "publishConfig": {
35
39
  "access": "public"
36
40
  },
37
- "gitHead": "9c03d1458cae76792ae15e67b421205836bf4393"
41
+ "gitHead": "35e26942820d8237771af0c58e45b4303f0497f1"
38
42
  }
@@ -0,0 +1,58 @@
1
+ /**
2
+ * This code is derived from the following projects:
3
+ *
4
+ * 1. dynamic-importmap (https://github.com/keller-mark/dynamic-importmap)
5
+ * 2. es-module-shims (https://github.com/guybedford/es-module-shims)
6
+ *
7
+ * The original implementation was created by Guy Bedford in es-module-shims,
8
+ * then adapted by Mark Keller in dynamic-importmap, and further modified
9
+ * for use in this project.
10
+ *
11
+ * Both projects are licensed under the MIT license.
12
+ *
13
+ * MIT License: https://opensource.org/licenses/MIT
14
+ */
15
+
16
+ /**
17
+ * Internal dependencies
18
+ */
19
+ import { type ModuleLoad } from './loader';
20
+
21
+ const fetching = ( url: string, parent?: string ) => {
22
+ return ` fetching ${ url }${ parent ? ` from ${ parent }` : '' }`;
23
+ };
24
+
25
+ const jsContentType = /^(text|application)\/(x-)?javascript(;|$)/;
26
+
27
+ /**
28
+ * Fetches the passed module URL and return the corresponding `ModuleLoad`
29
+ * instance. If the passed URL does not point to a JS file, the function
30
+ * throws and error.
31
+ *
32
+ * @param url Module URL.
33
+ * @param fetchOpts Fetch init options.
34
+ * @param parent Parent module URL referencing this URL (if any).
35
+ * @return Promise with a `ModuleLoad` instance.
36
+ */
37
+ export async function fetchModule(
38
+ url: string,
39
+ fetchOpts: RequestInit,
40
+ parent: string
41
+ ): Promise< ModuleLoad > {
42
+ let res: Response;
43
+ try {
44
+ res = await fetch( url, fetchOpts );
45
+ } catch ( e ) {
46
+ throw Error( `Network error${ fetching( url, parent ) }.` );
47
+ }
48
+ if ( ! res.ok ) {
49
+ throw Error( `Error ${ res.status }${ fetching( url, parent ) }.` );
50
+ }
51
+ const contentType = res.headers.get( 'content-type' );
52
+ if ( ! jsContentType.test( contentType ) ) {
53
+ throw Error(
54
+ `Bad Content-Type "${ contentType }"${ fetching( url, parent ) }.`
55
+ );
56
+ }
57
+ return { responseUrl: res.url, source: await res.text() };
58
+ }
@@ -0,0 +1,87 @@
1
+ /**
2
+ * This code is derived from the following projects:
3
+ *
4
+ * 1. dynamic-importmap (https://github.com/keller-mark/dynamic-importmap)
5
+ * 2. es-module-shims (https://github.com/guybedford/es-module-shims)
6
+ *
7
+ * The original implementation was created by Guy Bedford in es-module-shims,
8
+ * then adapted by Mark Keller in dynamic-importmap, and further modified
9
+ * for use in this project.
10
+ *
11
+ * Both projects are licensed under the MIT license.
12
+ *
13
+ * MIT License: https://opensource.org/licenses/MIT
14
+ */
15
+
16
+ /**
17
+ * Internal dependencies
18
+ */
19
+ import { addImportMap, resolve } from './resolver';
20
+ import { initPromise, topLevelLoad, preloadModule } from './loader';
21
+
22
+ type ImportMap = {
23
+ imports?: Record< string, string >;
24
+ scopes?: Record< string, Record< string, string > >;
25
+ };
26
+
27
+ // TODO: check if this baseURI should change per document, and so
28
+ // it need to be passed as a parameter to methods like `importWithMap`
29
+ // and `preloadWithMap`.
30
+ const baseUrl = document.baseURI;
31
+ const pageBaseUrl = baseUrl;
32
+
33
+ Object.defineProperty( self, 'wpInteractivityRouterImport', {
34
+ value: importShim,
35
+ writable: false,
36
+ enumerable: false,
37
+ configurable: false,
38
+ } );
39
+
40
+ async function importShim< Module = unknown >( id: string ) {
41
+ await initPromise;
42
+ return topLevelLoad< Module >( resolve( id, pageBaseUrl ), {
43
+ credentials: 'same-origin',
44
+ } );
45
+ }
46
+
47
+ /**
48
+ * Imports the module with the passed ID.
49
+ *
50
+ * The module is resolved against the internal dynamic import map,
51
+ * extended with the passed import map.
52
+ *
53
+ * @param id Module ID.
54
+ * @param importMapIn Import map.
55
+ * @return Resolved module.
56
+ */
57
+ export async function importWithMap< Module = unknown >(
58
+ id: string,
59
+ importMapIn: ImportMap
60
+ ) {
61
+ addImportMap( importMapIn );
62
+ return importShim< Module >( id );
63
+ }
64
+
65
+ /**
66
+ * Preloads the module with the passed ID along with its dependencies.
67
+ *
68
+ * The module is resolved against the internal dynamic import map,
69
+ * extended with the passed import map.
70
+ *
71
+ * @param id Module ID.
72
+ * @param importMapIn Import map.
73
+ * @return Resolved `ModuleLoad` instance.
74
+ */
75
+ export async function preloadWithMap( id: string, importMapIn: ImportMap ) {
76
+ addImportMap( importMapIn );
77
+ await initPromise;
78
+ return preloadModule( resolve( id, pageBaseUrl ), {
79
+ credentials: 'same-origin',
80
+ } );
81
+ }
82
+
83
+ export {
84
+ initialImportMap,
85
+ importPreloadedModule,
86
+ type ModuleLoad,
87
+ } from './loader';