@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.
- package/CHANGELOG.md +19 -0
- package/README.md +22 -0
- package/build/assets/dynamic-importmap/fetch.js +60 -0
- package/build/assets/dynamic-importmap/fetch.js.map +1 -0
- package/build/assets/dynamic-importmap/index.js +91 -0
- package/build/assets/dynamic-importmap/index.js.map +1 -0
- package/build/assets/dynamic-importmap/loader.js +286 -0
- package/build/assets/dynamic-importmap/loader.js.map +1 -0
- package/build/assets/dynamic-importmap/resolver.js +220 -0
- package/build/assets/dynamic-importmap/resolver.js.map +1 -0
- package/build/assets/script-modules.js +64 -0
- package/build/assets/script-modules.js.map +1 -0
- package/build/assets/scs.js +62 -0
- package/build/assets/scs.js.map +1 -0
- package/build/assets/styles.js +246 -0
- package/build/assets/styles.js.map +1 -0
- package/build/full-page.js +43 -0
- package/build/full-page.js.map +1 -0
- package/build/index.js +141 -112
- package/build/index.js.map +1 -1
- package/build-module/assets/dynamic-importmap/fetch.js +54 -0
- package/build-module/assets/dynamic-importmap/fetch.js.map +1 -0
- package/build-module/assets/dynamic-importmap/index.js +72 -0
- package/build-module/assets/dynamic-importmap/index.js.map +1 -0
- package/build-module/assets/dynamic-importmap/loader.js +279 -0
- package/build-module/assets/dynamic-importmap/loader.js.map +1 -0
- package/build-module/assets/dynamic-importmap/resolver.js +213 -0
- package/build-module/assets/dynamic-importmap/resolver.js.map +1 -0
- package/build-module/assets/script-modules.js +55 -0
- package/build-module/assets/script-modules.js.map +1 -0
- package/build-module/assets/scs.js +56 -0
- package/build-module/assets/scs.js.map +1 -0
- package/build-module/assets/styles.js +235 -0
- package/build-module/assets/styles.js.map +1 -0
- package/build-module/full-page.js +39 -0
- package/build-module/full-page.js.map +1 -0
- package/build-module/index.js +138 -107
- package/build-module/index.js.map +1 -1
- package/build-types/assets/dynamic-importmap/fetch.d.ts +30 -0
- package/build-types/assets/dynamic-importmap/fetch.d.ts.map +1 -0
- package/build-types/assets/dynamic-importmap/index.d.ts +42 -0
- package/build-types/assets/dynamic-importmap/index.d.ts.map +1 -0
- package/build-types/assets/dynamic-importmap/loader.d.ts +68 -0
- package/build-types/assets/dynamic-importmap/loader.d.ts.map +1 -0
- package/build-types/assets/dynamic-importmap/resolver.d.ts +35 -0
- package/build-types/assets/dynamic-importmap/resolver.d.ts.map +1 -0
- package/build-types/assets/script-modules.d.ts +26 -0
- package/build-types/assets/script-modules.d.ts.map +1 -0
- package/build-types/assets/scs.d.ts +24 -0
- package/build-types/assets/scs.d.ts.map +1 -0
- package/build-types/assets/styles.d.ts +69 -0
- package/build-types/assets/styles.d.ts.map +1 -0
- package/build-types/full-page.d.ts +3 -0
- package/build-types/full-page.d.ts.map +1 -0
- package/build-types/index.d.ts +4 -5
- package/build-types/index.d.ts.map +1 -1
- package/package.json +9 -5
- package/src/assets/dynamic-importmap/fetch.ts +58 -0
- package/src/assets/dynamic-importmap/index.ts +87 -0
- package/src/assets/dynamic-importmap/loader.ts +366 -0
- package/src/assets/dynamic-importmap/resolver.ts +292 -0
- package/src/assets/script-modules.ts +69 -0
- package/src/assets/scs.ts +61 -0
- package/src/assets/styles.ts +272 -0
- package/src/assets/test/scs.test.ts +367 -0
- package/src/assets/test/styles.test.ts +758 -0
- package/src/full-page.ts +53 -0
- package/src/index.ts +160 -135
- package/tsconfig.full-page.json +12 -0
- package/tsconfig.full-page.tsbuildinfo +1 -0
- package/tsconfig.json +9 -4
- package/tsconfig.main.json +21 -0
- package/tsconfig.main.tsbuildinfo +1 -0
- package/build/head.js +0 -113
- package/build/head.js.map +0 -1
- package/build-module/head.js +0 -103
- package/build-module/head.js.map +0 -1
- package/build-types/head.d.ts +0 -24
- package/build-types/head.d.ts.map +0 -1
- package/src/head.ts +0 -126
- package/tsconfig.tsbuildinfo +0 -1
package/build-module/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
/* wp:polyfill */
|
|
2
2
|
/**
|
|
3
3
|
* WordPress dependencies
|
|
4
4
|
*/
|
|
@@ -7,7 +7,8 @@ import { store, privateApis, getConfig } from '@wordpress/interactivity';
|
|
|
7
7
|
/**
|
|
8
8
|
* Internal dependencies
|
|
9
9
|
*/
|
|
10
|
-
import {
|
|
10
|
+
import { preloadStyles, applyStyles } from './assets/styles';
|
|
11
|
+
import { preloadScriptModules, importScriptModules, markScriptModuleAsResolved } from './assets/script-modules';
|
|
11
12
|
const {
|
|
12
13
|
directivePrefix,
|
|
13
14
|
getRegionRootFragment,
|
|
@@ -18,9 +19,9 @@ const {
|
|
|
18
19
|
populateServerData,
|
|
19
20
|
batch
|
|
20
21
|
} = privateApis('I acknowledge that using private APIs means my theme or plugin will inevitably break in the next version of WordPress.');
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
|
|
22
|
+
const regionAttr = `data-${directivePrefix}-router-region`;
|
|
23
|
+
const interactiveAttr = `data-${directivePrefix}-interactive`;
|
|
24
|
+
const regionsSelector = `[${interactiveAttr}][${regionAttr}]:not([${interactiveAttr}] [${interactiveAttr}])`;
|
|
24
25
|
// The cache of visited and prefetched pages, stylesheets and scripts.
|
|
25
26
|
const pages = new Map();
|
|
26
27
|
|
|
@@ -31,7 +32,40 @@ const getPagePath = url => {
|
|
|
31
32
|
return u.pathname + u.search;
|
|
32
33
|
};
|
|
33
34
|
|
|
34
|
-
|
|
35
|
+
/**
|
|
36
|
+
* Parses the given region's directive.
|
|
37
|
+
*
|
|
38
|
+
* @param region Region element.
|
|
39
|
+
* @return Data contained in the region directive value.
|
|
40
|
+
*/
|
|
41
|
+
const parseRegionAttribute = region => {
|
|
42
|
+
const value = region.getAttribute(regionAttr);
|
|
43
|
+
try {
|
|
44
|
+
const {
|
|
45
|
+
id,
|
|
46
|
+
attachTo
|
|
47
|
+
} = JSON.parse(value);
|
|
48
|
+
return {
|
|
49
|
+
id,
|
|
50
|
+
attachTo
|
|
51
|
+
};
|
|
52
|
+
} catch (e) {
|
|
53
|
+
return {
|
|
54
|
+
id: value
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Fetches and prepares a page from a given URL.
|
|
61
|
+
*
|
|
62
|
+
* @param url The URL of the page to fetch.
|
|
63
|
+
* @param options Options for the fetch operation.
|
|
64
|
+
* @param options.html Optional HTML content. If provided, the function will use
|
|
65
|
+
* this instead of fetching from the URL.
|
|
66
|
+
* @return A Promise that resolves to the prepared page, or false if
|
|
67
|
+
* there was an error during fetching or preparation.
|
|
68
|
+
*/
|
|
35
69
|
const fetchPage = async (url, {
|
|
36
70
|
html
|
|
37
71
|
}) => {
|
|
@@ -44,75 +78,115 @@ const fetchPage = async (url, {
|
|
|
44
78
|
html = await res.text();
|
|
45
79
|
}
|
|
46
80
|
const dom = new window.DOMParser().parseFromString(html, 'text/html');
|
|
47
|
-
return
|
|
81
|
+
return await preparePage(url, dom);
|
|
48
82
|
} catch (e) {
|
|
49
83
|
return false;
|
|
50
84
|
}
|
|
51
85
|
};
|
|
52
86
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
87
|
+
/**
|
|
88
|
+
* Processes a DOM document to extract router regions and related resources.
|
|
89
|
+
*
|
|
90
|
+
* This function analyzes the provided DOM document and creates a virtual DOM
|
|
91
|
+
* representation of all HTML regions marked with a `router-region` directive.
|
|
92
|
+
* It also extracts and preloads associated styles and scripts to prepare for
|
|
93
|
+
* rendering the page.
|
|
94
|
+
*
|
|
95
|
+
* @param url The URL associated with the page, used for asset
|
|
96
|
+
* loading and caching.
|
|
97
|
+
* @param dom The DOM document to process.
|
|
98
|
+
* @param vdomParams Optional parameters for virtual DOM processing.
|
|
99
|
+
* @param vdomParams.vdom An optional existing virtual DOM cache to check for
|
|
100
|
+
* regions. If a region exists in this cache, it will be
|
|
101
|
+
* reused instead of creating a new vDOM representation.
|
|
102
|
+
* @return A Promise that resolves to a {@link Page} object
|
|
103
|
+
* containing the virtual DOM for all router regions,
|
|
104
|
+
* preloaded styles and scripts, page title, and initial
|
|
105
|
+
* server-rendered data.
|
|
106
|
+
*/
|
|
107
|
+
const preparePage = async (url, dom, {
|
|
56
108
|
vdom
|
|
57
109
|
} = {}) => {
|
|
58
|
-
const regions = {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
110
|
+
const regions = {};
|
|
111
|
+
const regionsToAttach = {};
|
|
112
|
+
dom.querySelectorAll(regionsSelector).forEach(region => {
|
|
113
|
+
const {
|
|
114
|
+
id,
|
|
115
|
+
attachTo
|
|
116
|
+
} = parseRegionAttribute(region);
|
|
117
|
+
regions[id] = vdom?.has(region) ? vdom.get(region) : toVdom(region);
|
|
118
|
+
if (attachTo) {
|
|
119
|
+
regionsToAttach[id] = attachTo;
|
|
66
120
|
}
|
|
67
|
-
}
|
|
68
|
-
if (navigationMode === 'regionBased') {
|
|
69
|
-
const attrName = `data-${directivePrefix}-router-region`;
|
|
70
|
-
dom.querySelectorAll(`[${attrName}]`).forEach(region => {
|
|
71
|
-
const id = region.getAttribute(attrName);
|
|
72
|
-
regions[id] = vdom?.has(region) ? vdom.get(region) : toVdom(region);
|
|
73
|
-
});
|
|
74
|
-
}
|
|
121
|
+
});
|
|
75
122
|
const title = dom.querySelector('title')?.innerText;
|
|
76
123
|
const initialData = parseServerData(dom);
|
|
124
|
+
|
|
125
|
+
// Wait for styles and modules to be ready.
|
|
126
|
+
const [styles, scriptModules] = await Promise.all([Promise.all(preloadStyles(dom, url)), Promise.all(preloadScriptModules(dom))]);
|
|
77
127
|
return {
|
|
78
128
|
regions,
|
|
79
|
-
|
|
129
|
+
regionsToAttach,
|
|
130
|
+
styles,
|
|
131
|
+
scriptModules,
|
|
80
132
|
title,
|
|
81
|
-
initialData
|
|
133
|
+
initialData,
|
|
134
|
+
url
|
|
82
135
|
};
|
|
83
136
|
};
|
|
84
137
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
138
|
+
/**
|
|
139
|
+
* Renders a page by applying styles, populating server data, rendering regions,
|
|
140
|
+
* and updating the document title.
|
|
141
|
+
*
|
|
142
|
+
* @param page The {@link Page} object to render.
|
|
143
|
+
*/
|
|
144
|
+
const renderPage = page => {
|
|
145
|
+
applyStyles(page.styles);
|
|
146
|
+
|
|
147
|
+
// Clone regionsToAttach.
|
|
148
|
+
const regionsToAttach = {
|
|
149
|
+
...page.regionsToAttach
|
|
150
|
+
};
|
|
151
|
+
batch(() => {
|
|
152
|
+
populateServerData(page.initialData);
|
|
153
|
+
document.querySelectorAll(regionsSelector).forEach(region => {
|
|
154
|
+
const {
|
|
155
|
+
id
|
|
156
|
+
} = parseRegionAttribute(region);
|
|
157
|
+
const fragment = getRegionRootFragment(region);
|
|
158
|
+
render(page.regions[id], fragment);
|
|
159
|
+
// If this is an attached region, remove it from the list.
|
|
160
|
+
delete regionsToAttach[id];
|
|
107
161
|
});
|
|
108
|
-
|
|
162
|
+
|
|
163
|
+
// Render unattached regions.
|
|
164
|
+
for (const id in regionsToAttach) {
|
|
165
|
+
const parent = document.querySelector(regionsToAttach[id]);
|
|
166
|
+
|
|
167
|
+
// Get the type from the vnode. If wrapped with Directives, get the
|
|
168
|
+
// original type from `props.type`.
|
|
169
|
+
const {
|
|
170
|
+
props,
|
|
171
|
+
type
|
|
172
|
+
} = page.regions[id];
|
|
173
|
+
const elementType = typeof type === 'function' ? props.type : type;
|
|
174
|
+
|
|
175
|
+
// Create an element with the obtained type where the region will be
|
|
176
|
+
// rendered. The type should match the one of the root vnode.
|
|
177
|
+
const region = document.createElement(elementType);
|
|
178
|
+
parent.appendChild(region);
|
|
179
|
+
const fragment = getRegionRootFragment(region);
|
|
180
|
+
render(page.regions[id], fragment);
|
|
181
|
+
}
|
|
182
|
+
});
|
|
109
183
|
if (page.title) {
|
|
110
184
|
document.title = page.title;
|
|
111
185
|
}
|
|
112
186
|
};
|
|
113
187
|
|
|
114
188
|
/**
|
|
115
|
-
*
|
|
189
|
+
* Loads the given page forcing a full page reload.
|
|
116
190
|
*
|
|
117
191
|
* The function returns a promise that won't resolve, useful to prevent any
|
|
118
192
|
* potential feedback indicating that the navigation has finished while the new
|
|
@@ -132,7 +206,7 @@ window.addEventListener('popstate', async () => {
|
|
|
132
206
|
const pagePath = getPagePath(window.location.href); // Remove hash.
|
|
133
207
|
const page = pages.has(pagePath) && (await pages.get(pagePath));
|
|
134
208
|
if (page) {
|
|
135
|
-
|
|
209
|
+
renderPage(page);
|
|
136
210
|
// Update the URL in the state.
|
|
137
211
|
state.url = window.location.href;
|
|
138
212
|
} else {
|
|
@@ -141,37 +215,13 @@ window.addEventListener('popstate', async () => {
|
|
|
141
215
|
});
|
|
142
216
|
|
|
143
217
|
// Initialize the router and cache the initial page using the initial vDOM.
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
// Cache the scripts. Has to be called before fetching the assets.
|
|
149
|
-
[].map.call(document.querySelectorAll('script[type="module"][src]'), script => {
|
|
150
|
-
headElements.set(script.getAttribute('src'), {
|
|
151
|
-
tag: script
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
await fetchHeadAssets(document);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
pages.set(getPagePath(window.location.href), Promise.resolve(regionsToVdom(document, {
|
|
218
|
+
window.document.querySelectorAll('script[type=module][src]').forEach(({
|
|
219
|
+
src
|
|
220
|
+
}) => markScriptModuleAsResolved(src));
|
|
221
|
+
pages.set(getPagePath(window.location.href), Promise.resolve(preparePage(getPagePath(window.location.href), document, {
|
|
158
222
|
vdom: initialVdom
|
|
159
223
|
})));
|
|
160
224
|
|
|
161
|
-
// Check if the link is valid for client-side navigation.
|
|
162
|
-
const isValidLink = ref => ref && ref instanceof window.HTMLAnchorElement && ref.href && (!ref.target || ref.target === '_self') && ref.origin === window.location.origin && !ref.pathname.startsWith('/wp-admin') && !ref.pathname.startsWith('/wp-login.php') && !ref.getAttribute('href').startsWith('#') && !new URL(ref.href).searchParams.has('_wpnonce');
|
|
163
|
-
|
|
164
|
-
// Check if the event is valid for client-side navigation.
|
|
165
|
-
const isValidEvent = event => event && event.button === 0 &&
|
|
166
|
-
// Left clicks only.
|
|
167
|
-
!event.metaKey &&
|
|
168
|
-
// Open in new tab (Mac).
|
|
169
|
-
!event.ctrlKey &&
|
|
170
|
-
// Open in new tab (Windows).
|
|
171
|
-
!event.altKey &&
|
|
172
|
-
// Download.
|
|
173
|
-
!event.shiftKey && !event.defaultPrevented;
|
|
174
|
-
|
|
175
225
|
// Variable to store the current navigation.
|
|
176
226
|
let navigatingTo = '';
|
|
177
227
|
let hasLoadedNavigationTextsData = false;
|
|
@@ -257,7 +307,8 @@ export const {
|
|
|
257
307
|
return;
|
|
258
308
|
}
|
|
259
309
|
if (page && !page.initialData?.config?.['core/router']?.clientNavigationDisabled) {
|
|
260
|
-
yield
|
|
310
|
+
yield importScriptModules(page.scriptModules);
|
|
311
|
+
renderPage(page);
|
|
261
312
|
window.history[options.replace ? 'replaceState' : 'pushState']({}, '', href);
|
|
262
313
|
|
|
263
314
|
// Update the URL in the state.
|
|
@@ -294,8 +345,10 @@ export const {
|
|
|
294
345
|
* @param [options] Options object.
|
|
295
346
|
* @param [options.force] Force fetching the URL again.
|
|
296
347
|
* @param [options.html] HTML string to be used instead of fetching the requested URL.
|
|
348
|
+
*
|
|
349
|
+
* @return Promise that resolves once the page has been fetched.
|
|
297
350
|
*/
|
|
298
|
-
prefetch(url, options = {}) {
|
|
351
|
+
*prefetch(url, options = {}) {
|
|
299
352
|
const {
|
|
300
353
|
clientNavigationDisabled
|
|
301
354
|
} = getConfig();
|
|
@@ -308,6 +361,7 @@ export const {
|
|
|
308
361
|
html: options.html
|
|
309
362
|
}));
|
|
310
363
|
}
|
|
364
|
+
yield pages.get(pagePath);
|
|
311
365
|
}
|
|
312
366
|
}
|
|
313
367
|
});
|
|
@@ -316,7 +370,7 @@ export const {
|
|
|
316
370
|
* Announces a message to screen readers.
|
|
317
371
|
*
|
|
318
372
|
* This is a wrapper around the `@wordpress/a11y` package's `speak` function. It handles importing
|
|
319
|
-
* the package on demand and should be used instead of calling `
|
|
373
|
+
* the package on demand and should be used instead of calling `a11y.speak` directly.
|
|
320
374
|
*
|
|
321
375
|
* @param messageKey The message to be announced by assistive technologies.
|
|
322
376
|
*/
|
|
@@ -357,27 +411,4 @@ function a11ySpeak(messageKey) {
|
|
|
357
411
|
// Ignore failures to load the a11y module.
|
|
358
412
|
() => {});
|
|
359
413
|
}
|
|
360
|
-
|
|
361
|
-
// Add click and prefetch to all links.
|
|
362
|
-
if (globalThis.IS_GUTENBERG_PLUGIN) {
|
|
363
|
-
if (navigationMode === 'fullPage') {
|
|
364
|
-
// Navigate on click.
|
|
365
|
-
document.addEventListener('click', function (event) {
|
|
366
|
-
const ref = event.target.closest('a');
|
|
367
|
-
if (isValidLink(ref) && isValidEvent(event)) {
|
|
368
|
-
event.preventDefault();
|
|
369
|
-
actions.navigate(ref.href);
|
|
370
|
-
}
|
|
371
|
-
}, true);
|
|
372
|
-
// Prefetch on hover.
|
|
373
|
-
document.addEventListener('mouseenter', function (event) {
|
|
374
|
-
if (event.target?.nodeName === 'A') {
|
|
375
|
-
const ref = event.target.closest('a');
|
|
376
|
-
if (isValidLink(ref) && isValidEvent(event)) {
|
|
377
|
-
actions.prefetch(ref.href);
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
}, true);
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
414
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["store","privateApis","getConfig","fetchHeadAssets","updateHead","headElements","directivePrefix","getRegionRootFragment","initialVdom","toVdom","render","parseServerData","populateServerData","batch","navigationMode","_getConfig$navigation","pages","Map","getPagePath","url","u","URL","window","location","href","pathname","search","fetchPage","html","res","fetch","status","text","dom","DOMParser","parseFromString","regionsToVdom","e","vdom","regions","body","undefined","head","globalThis","IS_GUTENBERG_PLUGIN","get","document","attrName","querySelectorAll","forEach","region","id","getAttribute","has","title","querySelector","innerText","initialData","renderRegions","page","fragment","forcePageReload","assign","Promise","addEventListener","pagePath","state","reload","map","call","script","set","tag","resolve","isValidLink","ref","HTMLAnchorElement","target","origin","startsWith","searchParams","isValidEvent","event","button","metaKey","ctrlKey","altKey","shiftKey","defaultPrevented","navigatingTo","hasLoadedNavigationTextsData","navigationTexts","loading","loaded","actions","navigation","hasStarted","hasFinished","navigate","options","clientNavigationDisabled","loadingAnimation","screenReaderAnnouncement","timeout","prefetch","timeoutPromise","setTimeout","loadingTimeout","a11ySpeak","race","clearTimeout","config","history","replace","hash","scrollIntoView","force","messageKey","content","getElementById","textContent","parsed","JSON","parse","i18n","texts","message","then","speak","closest","preventDefault","nodeName"],"sources":["@wordpress/interactivity-router/src/index.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { store, privateApis, getConfig } from '@wordpress/interactivity';\n\n/**\n * Internal dependencies\n */\nimport { fetchHeadAssets, updateHead, headElements } from './head';\n\nconst {\n\tdirectivePrefix,\n\tgetRegionRootFragment,\n\tinitialVdom,\n\ttoVdom,\n\trender,\n\tparseServerData,\n\tpopulateServerData,\n\tbatch,\n} = privateApis(\n\t'I acknowledge that using private APIs means my theme or plugin will inevitably break in the next version of WordPress.'\n);\n\ninterface NavigateOptions {\n\tforce?: boolean;\n\thtml?: string;\n\treplace?: boolean;\n\ttimeout?: number;\n\tloadingAnimation?: boolean;\n\tscreenReaderAnnouncement?: boolean;\n}\n\ninterface PrefetchOptions {\n\tforce?: boolean;\n\thtml?: string;\n}\n\ninterface VdomParams {\n\tvdom?: typeof initialVdom;\n}\n\ninterface Page {\n\tregions: Record< string, any >;\n\thead: HTMLHeadElement[];\n\ttitle: string;\n\tinitialData: any;\n}\n\ntype RegionsToVdom = ( dom: Document, params?: VdomParams ) => Promise< Page >;\n\n// Check if the navigation mode is full page or region based.\nconst navigationMode: 'regionBased' | 'fullPage' =\n\tgetConfig( 'core/router' ).navigationMode ?? 'regionBased';\n\n// The cache of visited and prefetched pages, stylesheets and scripts.\nconst pages = new Map< string, Promise< Page | false > >();\n\n// Helper to remove domain and hash from the URL. We are only interesting in\n// caching the path and the query.\nconst getPagePath = ( url: string ) => {\n\tconst u = new URL( url, window.location.href );\n\treturn u.pathname + u.search;\n};\n\n// Fetch a new page and convert it to a static virtual DOM.\nconst fetchPage = async ( url: string, { html }: { html: string } ) => {\n\ttry {\n\t\tif ( ! html ) {\n\t\t\tconst res = await window.fetch( url );\n\t\t\tif ( res.status !== 200 ) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\thtml = await res.text();\n\t\t}\n\t\tconst dom = new window.DOMParser().parseFromString( html, 'text/html' );\n\t\treturn regionsToVdom( dom );\n\t} catch ( e ) {\n\t\treturn false;\n\t}\n};\n\n// Return an object with VDOM trees of those HTML regions marked with a\n// `router-region` directive.\nconst regionsToVdom: RegionsToVdom = async ( dom, { vdom } = {} ) => {\n\tconst regions = { body: undefined };\n\tlet head: HTMLElement[];\n\tif ( globalThis.IS_GUTENBERG_PLUGIN ) {\n\t\tif ( navigationMode === 'fullPage' ) {\n\t\t\thead = await fetchHeadAssets( dom );\n\t\t\tregions.body = vdom\n\t\t\t\t? vdom.get( document.body )\n\t\t\t\t: toVdom( dom.body );\n\t\t}\n\t}\n\tif ( navigationMode === 'regionBased' ) {\n\t\tconst attrName = `data-${ directivePrefix }-router-region`;\n\t\tdom.querySelectorAll( `[${ attrName }]` ).forEach( ( region ) => {\n\t\t\tconst id = region.getAttribute( attrName );\n\t\t\tregions[ id ] = vdom?.has( region )\n\t\t\t\t? vdom.get( region )\n\t\t\t\t: toVdom( region );\n\t\t} );\n\t}\n\tconst title = dom.querySelector( 'title' )?.innerText;\n\tconst initialData = parseServerData( dom );\n\treturn { regions, head, title, initialData };\n};\n\n// Render all interactive regions contained in the given page.\nconst renderRegions = async ( page: Page ) => {\n\tif ( globalThis.IS_GUTENBERG_PLUGIN ) {\n\t\tif ( navigationMode === 'fullPage' ) {\n\t\t\t// Once this code is tested and more mature, the head should be updated for region based navigation as well.\n\t\t\tawait updateHead( page.head );\n\t\t\tconst fragment = getRegionRootFragment( document.body );\n\t\t\tbatch( () => {\n\t\t\t\tpopulateServerData( page.initialData );\n\t\t\t\trender( page.regions.body, fragment );\n\t\t\t} );\n\t\t}\n\t}\n\tif ( navigationMode === 'regionBased' ) {\n\t\tconst attrName = `data-${ directivePrefix }-router-region`;\n\t\tbatch( () => {\n\t\t\tpopulateServerData( page.initialData );\n\t\t\tdocument\n\t\t\t\t.querySelectorAll( `[${ attrName }]` )\n\t\t\t\t.forEach( ( region ) => {\n\t\t\t\t\tconst id = region.getAttribute( attrName );\n\t\t\t\t\tconst fragment = getRegionRootFragment( region );\n\t\t\t\t\trender( page.regions[ id ], fragment );\n\t\t\t\t} );\n\t\t} );\n\t}\n\tif ( page.title ) {\n\t\tdocument.title = page.title;\n\t}\n};\n\n/**\n * Load the given page forcing a full page reload.\n *\n * The function returns a promise that won't resolve, useful to prevent any\n * potential feedback indicating that the navigation has finished while the new\n * page is being loaded.\n *\n * @param href The page href.\n * @return Promise that never resolves.\n */\nconst forcePageReload = ( href: string ) => {\n\twindow.location.assign( href );\n\treturn new Promise( () => {} );\n};\n\n// Listen to the back and forward buttons and restore the page if it's in the\n// cache.\nwindow.addEventListener( 'popstate', async () => {\n\tconst pagePath = getPagePath( window.location.href ); // Remove hash.\n\tconst page = pages.has( pagePath ) && ( await pages.get( pagePath ) );\n\tif ( page ) {\n\t\tawait renderRegions( page );\n\t\t// Update the URL in the state.\n\t\tstate.url = window.location.href;\n\t} else {\n\t\twindow.location.reload();\n\t}\n} );\n\n// Initialize the router and cache the initial page using the initial vDOM.\n// Once this code is tested and more mature, the head should be updated for\n// region based navigation as well.\nif ( globalThis.IS_GUTENBERG_PLUGIN ) {\n\tif ( navigationMode === 'fullPage' ) {\n\t\t// Cache the scripts. Has to be called before fetching the assets.\n\t\t[].map.call(\n\t\t\tdocument.querySelectorAll( 'script[type=\"module\"][src]' ),\n\t\t\t( script ) => {\n\t\t\t\theadElements.set( script.getAttribute( 'src' ), {\n\t\t\t\t\ttag: script,\n\t\t\t\t} );\n\t\t\t}\n\t\t);\n\t\tawait fetchHeadAssets( document );\n\t}\n}\npages.set(\n\tgetPagePath( window.location.href ),\n\tPromise.resolve( regionsToVdom( document, { vdom: initialVdom } ) )\n);\n\n// Check if the link is valid for client-side navigation.\nconst isValidLink = ( ref: HTMLAnchorElement ) =>\n\tref &&\n\tref instanceof window.HTMLAnchorElement &&\n\tref.href &&\n\t( ! ref.target || ref.target === '_self' ) &&\n\tref.origin === window.location.origin &&\n\t! ref.pathname.startsWith( '/wp-admin' ) &&\n\t! ref.pathname.startsWith( '/wp-login.php' ) &&\n\t! ref.getAttribute( 'href' ).startsWith( '#' ) &&\n\t! new URL( ref.href ).searchParams.has( '_wpnonce' );\n\n// Check if the event is valid for client-side navigation.\nconst isValidEvent = ( event: MouseEvent ) =>\n\tevent &&\n\tevent.button === 0 && // Left clicks only.\n\t! event.metaKey && // Open in new tab (Mac).\n\t! event.ctrlKey && // Open in new tab (Windows).\n\t! event.altKey && // Download.\n\t! event.shiftKey &&\n\t! event.defaultPrevented;\n\n// Variable to store the current navigation.\nlet navigatingTo = '';\n\nlet hasLoadedNavigationTextsData = false;\nconst navigationTexts = {\n\tloading: 'Loading page, please wait.',\n\tloaded: 'Page Loaded.',\n};\n\ninterface Store {\n\tstate: {\n\t\turl: string;\n\t\tnavigation: {\n\t\t\thasStarted: boolean;\n\t\t\thasFinished: boolean;\n\t\t};\n\t};\n\tactions: {\n\t\tnavigate: ( href: string, options?: NavigateOptions ) => void;\n\t\tprefetch: ( url: string, options?: PrefetchOptions ) => void;\n\t};\n}\n\nexport const { state, actions } = store< Store >( 'core/router', {\n\tstate: {\n\t\turl: window.location.href,\n\t\tnavigation: {\n\t\t\thasStarted: false,\n\t\t\thasFinished: false,\n\t\t},\n\t},\n\tactions: {\n\t\t/**\n\t\t * Navigates to the specified page.\n\t\t *\n\t\t * This function normalizes the passed href, fetches the page HTML if\n\t\t * needed, and updates any interactive regions whose contents have\n\t\t * changed. It also creates a new entry in the browser session history.\n\t\t *\n\t\t * @param href The page href.\n\t\t * @param [options] Options object.\n\t\t * @param [options.force] If true, it forces re-fetching the URL.\n\t\t * @param [options.html] HTML string to be used instead of fetching the requested URL.\n\t\t * @param [options.replace] If true, it replaces the current entry in the browser session history.\n\t\t * @param [options.timeout] Time until the navigation is aborted, in milliseconds. Default is 10000.\n\t\t * @param [options.loadingAnimation] Whether an animation should be shown while navigating. Default to `true`.\n\t\t * @param [options.screenReaderAnnouncement] Whether a message for screen readers should be announced while navigating. Default to `true`.\n\t\t *\n\t\t * @return Promise that resolves once the navigation is completed or aborted.\n\t\t */\n\t\t*navigate( href: string, options: NavigateOptions = {} ) {\n\t\t\tconst { clientNavigationDisabled } = getConfig();\n\t\t\tif ( clientNavigationDisabled ) {\n\t\t\t\tyield forcePageReload( href );\n\t\t\t}\n\n\t\t\tconst pagePath = getPagePath( href );\n\t\t\tconst { navigation } = state;\n\t\t\tconst {\n\t\t\t\tloadingAnimation = true,\n\t\t\t\tscreenReaderAnnouncement = true,\n\t\t\t\ttimeout = 10000,\n\t\t\t} = options;\n\n\t\t\tnavigatingTo = href;\n\t\t\tactions.prefetch( pagePath, options );\n\n\t\t\t// Create a promise that resolves when the specified timeout ends.\n\t\t\t// The timeout value is 10 seconds by default.\n\t\t\tconst timeoutPromise = new Promise< void >( ( resolve ) =>\n\t\t\t\tsetTimeout( resolve, timeout )\n\t\t\t);\n\n\t\t\t// Don't update the navigation status immediately, wait 400 ms.\n\t\t\tconst loadingTimeout = setTimeout( () => {\n\t\t\t\tif ( navigatingTo !== href ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif ( loadingAnimation ) {\n\t\t\t\t\tnavigation.hasStarted = true;\n\t\t\t\t\tnavigation.hasFinished = false;\n\t\t\t\t}\n\t\t\t\tif ( screenReaderAnnouncement ) {\n\t\t\t\t\ta11ySpeak( 'loading' );\n\t\t\t\t}\n\t\t\t}, 400 );\n\n\t\t\tconst page = yield Promise.race( [\n\t\t\t\tpages.get( pagePath ),\n\t\t\t\ttimeoutPromise,\n\t\t\t] );\n\n\t\t\t// Dismiss loading message if it hasn't been added yet.\n\t\t\tclearTimeout( loadingTimeout );\n\n\t\t\t// Once the page is fetched, the destination URL could have changed\n\t\t\t// (e.g., by clicking another link in the meantime). If so, bail\n\t\t\t// out, and let the newer execution to update the HTML.\n\t\t\tif ( navigatingTo !== href ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\tpage &&\n\t\t\t\t! page.initialData?.config?.[ 'core/router' ]\n\t\t\t\t\t?.clientNavigationDisabled\n\t\t\t) {\n\t\t\t\tyield renderRegions( page );\n\t\t\t\twindow.history[\n\t\t\t\t\toptions.replace ? 'replaceState' : 'pushState'\n\t\t\t\t]( {}, '', href );\n\n\t\t\t\t// Update the URL in the state.\n\t\t\t\tstate.url = href;\n\n\t\t\t\t// Update the navigation status once the the new page rendering\n\t\t\t\t// has been completed.\n\t\t\t\tif ( loadingAnimation ) {\n\t\t\t\t\tnavigation.hasStarted = false;\n\t\t\t\t\tnavigation.hasFinished = true;\n\t\t\t\t}\n\n\t\t\t\tif ( screenReaderAnnouncement ) {\n\t\t\t\t\ta11ySpeak( 'loaded' );\n\t\t\t\t}\n\n\t\t\t\t// Scroll to the anchor if exits in the link.\n\t\t\t\tconst { hash } = new URL( href, window.location.href );\n\t\t\t\tif ( hash ) {\n\t\t\t\t\tdocument.querySelector( hash )?.scrollIntoView();\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tyield forcePageReload( href );\n\t\t\t}\n\t\t},\n\n\t\t/**\n\t\t * Prefetches the page with the passed URL.\n\t\t *\n\t\t * The function normalizes the URL and stores internally the fetch\n\t\t * promise, to avoid triggering a second fetch for an ongoing request.\n\t\t *\n\t\t * @param url The page URL.\n\t\t * @param [options] Options object.\n\t\t * @param [options.force] Force fetching the URL again.\n\t\t * @param [options.html] HTML string to be used instead of fetching the requested URL.\n\t\t */\n\t\tprefetch( url: string, options: PrefetchOptions = {} ) {\n\t\t\tconst { clientNavigationDisabled } = getConfig();\n\t\t\tif ( clientNavigationDisabled ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst pagePath = getPagePath( url );\n\t\t\tif ( options.force || ! pages.has( pagePath ) ) {\n\t\t\t\tpages.set(\n\t\t\t\t\tpagePath,\n\t\t\t\t\tfetchPage( pagePath, { html: options.html } )\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\t},\n} );\n\n/**\n * Announces a message to screen readers.\n *\n * This is a wrapper around the `@wordpress/a11y` package's `speak` function. It handles importing\n * the package on demand and should be used instead of calling `ally.speak` direacly.\n *\n * @param messageKey The message to be announced by assistive technologies.\n */\nfunction a11ySpeak( messageKey: keyof typeof navigationTexts ) {\n\tif ( ! hasLoadedNavigationTextsData ) {\n\t\thasLoadedNavigationTextsData = true;\n\t\tconst content = document.getElementById(\n\t\t\t'wp-script-module-data-@wordpress/interactivity-router'\n\t\t)?.textContent;\n\t\tif ( content ) {\n\t\t\ttry {\n\t\t\t\tconst parsed = JSON.parse( content );\n\t\t\t\tif ( typeof parsed?.i18n?.loading === 'string' ) {\n\t\t\t\t\tnavigationTexts.loading = parsed.i18n.loading;\n\t\t\t\t}\n\t\t\t\tif ( typeof parsed?.i18n?.loaded === 'string' ) {\n\t\t\t\t\tnavigationTexts.loaded = parsed.i18n.loaded;\n\t\t\t\t}\n\t\t\t} catch {}\n\t\t} else {\n\t\t\t// Fallback to localized strings from Interactivity API state.\n\t\t\t// @todo This block is for Core < 6.7.0. Remove when support is dropped.\n\n\t\t\t// @ts-expect-error\n\t\t\tif ( state.navigation.texts?.loading ) {\n\t\t\t\t// @ts-expect-error\n\t\t\t\tnavigationTexts.loading = state.navigation.texts.loading;\n\t\t\t}\n\t\t\t// @ts-expect-error\n\t\t\tif ( state.navigation.texts?.loaded ) {\n\t\t\t\t// @ts-expect-error\n\t\t\t\tnavigationTexts.loaded = state.navigation.texts.loaded;\n\t\t\t}\n\t\t}\n\t}\n\n\tconst message = navigationTexts[ messageKey ];\n\n\timport( '@wordpress/a11y' ).then(\n\t\t( { speak } ) => speak( message ),\n\t\t// Ignore failures to load the a11y module.\n\t\t() => {}\n\t);\n}\n\n// Add click and prefetch to all links.\nif ( globalThis.IS_GUTENBERG_PLUGIN ) {\n\tif ( navigationMode === 'fullPage' ) {\n\t\t// Navigate on click.\n\t\tdocument.addEventListener(\n\t\t\t'click',\n\t\t\tfunction ( event ) {\n\t\t\t\tconst ref = ( event.target as Element ).closest( 'a' );\n\t\t\t\tif ( isValidLink( ref ) && isValidEvent( event ) ) {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\tactions.navigate( ref.href );\n\t\t\t\t}\n\t\t\t},\n\t\t\ttrue\n\t\t);\n\t\t// Prefetch on hover.\n\t\tdocument.addEventListener(\n\t\t\t'mouseenter',\n\t\t\tfunction ( event ) {\n\t\t\t\tif ( ( event.target as Element )?.nodeName === 'A' ) {\n\t\t\t\t\tconst ref = ( event.target as Element ).closest( 'a' );\n\t\t\t\t\tif ( isValidLink( ref ) && isValidEvent( event ) ) {\n\t\t\t\t\t\tactions.prefetch( ref.href );\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t\ttrue\n\t\t);\n\t}\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,KAAK,EAAEC,WAAW,EAAEC,SAAS,QAAQ,0BAA0B;;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;IACpC;IACAgC,QAAQ,CAACkB,gBAAgB,CACxB,OAAO,EACP,UAAWkB,KAAK,EAAG;MAClB,MAAMP,GAAG,GAAKO,KAAK,CAACL,MAAM,CAAcoD,OAAO,CAAE,GAAI,CAAC;MACtD,IAAKvD,WAAW,CAAEC,GAAI,CAAC,IAAIM,YAAY,CAAEC,KAAM,CAAC,EAAG;QAClDA,KAAK,CAACgD,cAAc,CAAC,CAAC;QACtBpC,OAAO,CAACI,QAAQ,CAAEvB,GAAG,CAACnD,IAAK,CAAC;MAC7B;IACD,CAAC,EACD,IACD,CAAC;IACD;IACAsB,QAAQ,CAACkB,gBAAgB,CACxB,YAAY,EACZ,UAAWkB,KAAK,EAAG;MAClB,IAAOA,KAAK,CAACL,MAAM,EAAesD,QAAQ,KAAK,GAAG,EAAG;QACpD,MAAMxD,GAAG,GAAKO,KAAK,CAACL,MAAM,CAAcoD,OAAO,CAAE,GAAI,CAAC;QACtD,IAAKvD,WAAW,CAAEC,GAAI,CAAC,IAAIM,YAAY,CAAEC,KAAM,CAAC,EAAG;UAClDY,OAAO,CAACU,QAAQ,CAAE7B,GAAG,CAACnD,IAAK,CAAC;QAC7B;MACD;IACD,CAAC,EACD,IACD,CAAC;EACF;AACD","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["store","privateApis","getConfig","preloadStyles","applyStyles","preloadScriptModules","importScriptModules","markScriptModuleAsResolved","directivePrefix","getRegionRootFragment","initialVdom","toVdom","render","parseServerData","populateServerData","batch","regionAttr","interactiveAttr","regionsSelector","pages","Map","getPagePath","url","u","URL","window","location","href","pathname","search","parseRegionAttribute","region","value","getAttribute","id","attachTo","JSON","parse","e","fetchPage","html","res","fetch","status","text","dom","DOMParser","parseFromString","preparePage","vdom","regions","regionsToAttach","querySelectorAll","forEach","has","get","title","querySelector","innerText","initialData","styles","scriptModules","Promise","all","renderPage","page","document","fragment","parent","props","type","elementType","createElement","appendChild","forcePageReload","assign","addEventListener","pagePath","state","reload","src","set","resolve","navigatingTo","hasLoadedNavigationTextsData","navigationTexts","loading","loaded","actions","navigation","hasStarted","hasFinished","navigate","options","clientNavigationDisabled","loadingAnimation","screenReaderAnnouncement","timeout","prefetch","timeoutPromise","setTimeout","loadingTimeout","a11ySpeak","race","clearTimeout","config","history","replace","hash","scrollIntoView","force","messageKey","content","getElementById","textContent","parsed","i18n","texts","message","then","speak"],"sources":["@wordpress/interactivity-router/src/index.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { store, privateApis, getConfig } from '@wordpress/interactivity';\n\n/**\n * Internal dependencies\n */\nimport { preloadStyles, applyStyles, type StyleElement } from './assets/styles';\nimport {\n\tpreloadScriptModules,\n\timportScriptModules,\n\tmarkScriptModuleAsResolved,\n\ttype ScriptModuleLoad,\n} from './assets/script-modules';\n\nconst {\n\tdirectivePrefix,\n\tgetRegionRootFragment,\n\tinitialVdom,\n\ttoVdom,\n\trender,\n\tparseServerData,\n\tpopulateServerData,\n\tbatch,\n} = privateApis(\n\t'I acknowledge that using private APIs means my theme or plugin will inevitably break in the next version of WordPress.'\n);\n\nconst regionAttr = `data-${ directivePrefix }-router-region`;\nconst interactiveAttr = `data-${ directivePrefix }-interactive`;\nconst regionsSelector = `[${ interactiveAttr }][${ regionAttr }]:not([${ interactiveAttr }] [${ interactiveAttr }])`;\n\nexport interface NavigateOptions {\n\tforce?: boolean;\n\thtml?: string;\n\treplace?: boolean;\n\ttimeout?: number;\n\tloadingAnimation?: boolean;\n\tscreenReaderAnnouncement?: boolean;\n}\n\nexport interface PrefetchOptions {\n\tforce?: boolean;\n\thtml?: string;\n}\n\ninterface VdomParams {\n\tvdom?: typeof initialVdom;\n}\n\ninterface Page {\n\turl: string;\n\tregions: Record< string, any >;\n\tregionsToAttach: Record< string, string >;\n\tstyles: StyleElement[];\n\tscriptModules: ScriptModuleLoad[];\n\ttitle: string;\n\tinitialData: any;\n}\n\ntype PreparePage = (\n\turl: string,\n\tdom: Document,\n\tparams?: VdomParams\n) => Promise< Page >;\n\n// The cache of visited and prefetched pages, stylesheets and scripts.\nconst pages = new Map< string, Promise< Page | false > >();\n\n// Helper to remove domain and hash from the URL. We are only interesting in\n// caching the path and the query.\nconst getPagePath = ( url: string ) => {\n\tconst u = new URL( url, window.location.href );\n\treturn u.pathname + u.search;\n};\n\n/**\n * Parses the given region's directive.\n *\n * @param region Region element.\n * @return Data contained in the region directive value.\n */\nconst parseRegionAttribute = ( region: Element ) => {\n\tconst value = region.getAttribute( regionAttr );\n\ttry {\n\t\tconst { id, attachTo } = JSON.parse( value );\n\t\treturn { id, attachTo };\n\t} catch ( e ) {\n\t\treturn { id: value };\n\t}\n};\n\n/**\n * Fetches and prepares a page from a given URL.\n *\n * @param url The URL of the page to fetch.\n * @param options Options for the fetch operation.\n * @param options.html Optional HTML content. If provided, the function will use\n * this instead of fetching from the URL.\n * @return A Promise that resolves to the prepared page, or false if\n * there was an error during fetching or preparation.\n */\nconst fetchPage = async ( url: string, { html }: { html: string } ) => {\n\ttry {\n\t\tif ( ! html ) {\n\t\t\tconst res = await window.fetch( url );\n\t\t\tif ( res.status !== 200 ) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\thtml = await res.text();\n\t\t}\n\t\tconst dom = new window.DOMParser().parseFromString( html, 'text/html' );\n\t\treturn await preparePage( url, dom );\n\t} catch ( e ) {\n\t\treturn false;\n\t}\n};\n\n/**\n * Processes a DOM document to extract router regions and related resources.\n *\n * This function analyzes the provided DOM document and creates a virtual DOM\n * representation of all HTML regions marked with a `router-region` directive.\n * It also extracts and preloads associated styles and scripts to prepare for\n * rendering the page.\n *\n * @param url The URL associated with the page, used for asset\n * loading and caching.\n * @param dom The DOM document to process.\n * @param vdomParams Optional parameters for virtual DOM processing.\n * @param vdomParams.vdom An optional existing virtual DOM cache to check for\n * regions. If a region exists in this cache, it will be\n * reused instead of creating a new vDOM representation.\n * @return A Promise that resolves to a {@link Page} object\n * containing the virtual DOM for all router regions,\n * preloaded styles and scripts, page title, and initial\n * server-rendered data.\n */\nconst preparePage: PreparePage = async ( url, dom, { vdom } = {} ) => {\n\tconst regions = {};\n\tconst regionsToAttach = {};\n\tdom.querySelectorAll( regionsSelector ).forEach( ( region ) => {\n\t\tconst { id, attachTo } = parseRegionAttribute( region );\n\t\tregions[ id ] = vdom?.has( region )\n\t\t\t? vdom.get( region )\n\t\t\t: toVdom( region );\n\t\tif ( attachTo ) {\n\t\t\tregionsToAttach[ id ] = attachTo;\n\t\t}\n\t} );\n\n\tconst title = dom.querySelector( 'title' )?.innerText;\n\tconst initialData = parseServerData( dom );\n\n\t// Wait for styles and modules to be ready.\n\tconst [ styles, scriptModules ] = await Promise.all( [\n\t\tPromise.all( preloadStyles( dom, url ) ),\n\t\tPromise.all( preloadScriptModules( dom ) ),\n\t] );\n\n\treturn {\n\t\tregions,\n\t\tregionsToAttach,\n\t\tstyles,\n\t\tscriptModules,\n\t\ttitle,\n\t\tinitialData,\n\t\turl,\n\t};\n};\n\n/**\n * Renders a page by applying styles, populating server data, rendering regions,\n * and updating the document title.\n *\n * @param page The {@link Page} object to render.\n */\nconst renderPage = ( page: Page ) => {\n\tapplyStyles( page.styles );\n\n\t// Clone regionsToAttach.\n\tconst regionsToAttach = { ...page.regionsToAttach };\n\n\tbatch( () => {\n\t\tpopulateServerData( page.initialData );\n\t\tdocument.querySelectorAll( regionsSelector ).forEach( ( region ) => {\n\t\t\tconst { id } = parseRegionAttribute( region );\n\t\t\tconst fragment = getRegionRootFragment( region );\n\t\t\trender( page.regions[ id ], fragment );\n\t\t\t// If this is an attached region, remove it from the list.\n\t\t\tdelete regionsToAttach[ id ];\n\t\t} );\n\n\t\t// Render unattached regions.\n\t\tfor ( const id in regionsToAttach ) {\n\t\t\tconst parent = document.querySelector( regionsToAttach[ id ] );\n\n\t\t\t// Get the type from the vnode. If wrapped with Directives, get the\n\t\t\t// original type from `props.type`.\n\t\t\tconst { props, type } = page.regions[ id ];\n\t\t\tconst elementType = typeof type === 'function' ? props.type : type;\n\n\t\t\t// Create an element with the obtained type where the region will be\n\t\t\t// rendered. The type should match the one of the root vnode.\n\t\t\tconst region = document.createElement( elementType );\n\t\t\tparent.appendChild( region );\n\n\t\t\tconst fragment = getRegionRootFragment( region );\n\t\t\trender( page.regions[ id ], fragment );\n\t\t}\n\t} );\n\n\tif ( page.title ) {\n\t\tdocument.title = page.title;\n\t}\n};\n\n/**\n * Loads the given page forcing a full page reload.\n *\n * The function returns a promise that won't resolve, useful to prevent any\n * potential feedback indicating that the navigation has finished while the new\n * page is being loaded.\n *\n * @param href The page href.\n * @return Promise that never resolves.\n */\nconst forcePageReload = ( href: string ) => {\n\twindow.location.assign( href );\n\treturn new Promise( () => {} );\n};\n\n// Listen to the back and forward buttons and restore the page if it's in the\n// cache.\nwindow.addEventListener( 'popstate', async () => {\n\tconst pagePath = getPagePath( window.location.href ); // Remove hash.\n\tconst page = pages.has( pagePath ) && ( await pages.get( pagePath ) );\n\tif ( page ) {\n\t\trenderPage( page );\n\t\t// Update the URL in the state.\n\t\tstate.url = window.location.href;\n\t} else {\n\t\twindow.location.reload();\n\t}\n} );\n\n// Initialize the router and cache the initial page using the initial vDOM.\nwindow.document\n\t.querySelectorAll< HTMLScriptElement >( 'script[type=module][src]' )\n\t.forEach( ( { src } ) => markScriptModuleAsResolved( src ) );\npages.set(\n\tgetPagePath( window.location.href ),\n\tPromise.resolve(\n\t\tpreparePage( getPagePath( window.location.href ), document, {\n\t\t\tvdom: initialVdom,\n\t\t} )\n\t)\n);\n\n// Variable to store the current navigation.\nlet navigatingTo = '';\n\nlet hasLoadedNavigationTextsData = false;\nconst navigationTexts = {\n\tloading: 'Loading page, please wait.',\n\tloaded: 'Page Loaded.',\n};\n\ninterface Store {\n\tstate: {\n\t\turl: string;\n\t\tnavigation: {\n\t\t\thasStarted: boolean;\n\t\t\thasFinished: boolean;\n\t\t};\n\t};\n\tactions: {\n\t\tnavigate: (\n\t\t\thref: string,\n\t\t\toptions?: NavigateOptions\n\t\t) => Promise< void >;\n\t\tprefetch: ( url: string, options?: PrefetchOptions ) => Promise< void >;\n\t};\n}\n\nexport const { state, actions } = store< Store >( 'core/router', {\n\tstate: {\n\t\turl: window.location.href,\n\t\tnavigation: {\n\t\t\thasStarted: false,\n\t\t\thasFinished: false,\n\t\t},\n\t},\n\tactions: {\n\t\t/**\n\t\t * Navigates to the specified page.\n\t\t *\n\t\t * This function normalizes the passed href, fetches the page HTML if\n\t\t * needed, and updates any interactive regions whose contents have\n\t\t * changed. It also creates a new entry in the browser session history.\n\t\t *\n\t\t * @param href The page href.\n\t\t * @param [options] Options object.\n\t\t * @param [options.force] If true, it forces re-fetching the URL.\n\t\t * @param [options.html] HTML string to be used instead of fetching the requested URL.\n\t\t * @param [options.replace] If true, it replaces the current entry in the browser session history.\n\t\t * @param [options.timeout] Time until the navigation is aborted, in milliseconds. Default is 10000.\n\t\t * @param [options.loadingAnimation] Whether an animation should be shown while navigating. Default to `true`.\n\t\t * @param [options.screenReaderAnnouncement] Whether a message for screen readers should be announced while navigating. Default to `true`.\n\t\t *\n\t\t * @return Promise that resolves once the navigation is completed or aborted.\n\t\t */\n\t\t*navigate( href: string, options: NavigateOptions = {} ) {\n\t\t\tconst { clientNavigationDisabled } = getConfig();\n\t\t\tif ( clientNavigationDisabled ) {\n\t\t\t\tyield forcePageReload( href );\n\t\t\t}\n\n\t\t\tconst pagePath = getPagePath( href );\n\t\t\tconst { navigation } = state;\n\t\t\tconst {\n\t\t\t\tloadingAnimation = true,\n\t\t\t\tscreenReaderAnnouncement = true,\n\t\t\t\ttimeout = 10000,\n\t\t\t} = options;\n\n\t\t\tnavigatingTo = href;\n\t\t\tactions.prefetch( pagePath, options );\n\n\t\t\t// Create a promise that resolves when the specified timeout ends.\n\t\t\t// The timeout value is 10 seconds by default.\n\t\t\tconst timeoutPromise = new Promise< void >( ( resolve ) =>\n\t\t\t\tsetTimeout( resolve, timeout )\n\t\t\t);\n\n\t\t\t// Don't update the navigation status immediately, wait 400 ms.\n\t\t\tconst loadingTimeout = setTimeout( () => {\n\t\t\t\tif ( navigatingTo !== href ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif ( loadingAnimation ) {\n\t\t\t\t\tnavigation.hasStarted = true;\n\t\t\t\t\tnavigation.hasFinished = false;\n\t\t\t\t}\n\t\t\t\tif ( screenReaderAnnouncement ) {\n\t\t\t\t\ta11ySpeak( 'loading' );\n\t\t\t\t}\n\t\t\t}, 400 );\n\n\t\t\tconst page = yield Promise.race( [\n\t\t\t\tpages.get( pagePath ),\n\t\t\t\ttimeoutPromise,\n\t\t\t] );\n\n\t\t\t// Dismiss loading message if it hasn't been added yet.\n\t\t\tclearTimeout( loadingTimeout );\n\n\t\t\t// Once the page is fetched, the destination URL could have changed\n\t\t\t// (e.g., by clicking another link in the meantime). If so, bail\n\t\t\t// out, and let the newer execution to update the HTML.\n\t\t\tif ( navigatingTo !== href ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\tpage &&\n\t\t\t\t! page.initialData?.config?.[ 'core/router' ]\n\t\t\t\t\t?.clientNavigationDisabled\n\t\t\t) {\n\t\t\t\tyield importScriptModules( page.scriptModules );\n\t\t\t\trenderPage( page );\n\t\t\t\twindow.history[\n\t\t\t\t\toptions.replace ? 'replaceState' : 'pushState'\n\t\t\t\t]( {}, '', href );\n\n\t\t\t\t// Update the URL in the state.\n\t\t\t\tstate.url = href;\n\n\t\t\t\t// Update the navigation status once the the new page rendering\n\t\t\t\t// has been completed.\n\t\t\t\tif ( loadingAnimation ) {\n\t\t\t\t\tnavigation.hasStarted = false;\n\t\t\t\t\tnavigation.hasFinished = true;\n\t\t\t\t}\n\n\t\t\t\tif ( screenReaderAnnouncement ) {\n\t\t\t\t\ta11ySpeak( 'loaded' );\n\t\t\t\t}\n\n\t\t\t\t// Scroll to the anchor if exits in the link.\n\t\t\t\tconst { hash } = new URL( href, window.location.href );\n\t\t\t\tif ( hash ) {\n\t\t\t\t\tdocument.querySelector( hash )?.scrollIntoView();\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tyield forcePageReload( href );\n\t\t\t}\n\t\t},\n\n\t\t/**\n\t\t * Prefetches the page with the passed URL.\n\t\t *\n\t\t * The function normalizes the URL and stores internally the fetch\n\t\t * promise, to avoid triggering a second fetch for an ongoing request.\n\t\t *\n\t\t * @param url The page URL.\n\t\t * @param [options] Options object.\n\t\t * @param [options.force] Force fetching the URL again.\n\t\t * @param [options.html] HTML string to be used instead of fetching the requested URL.\n\t\t *\n\t\t * @return Promise that resolves once the page has been fetched.\n\t\t */\n\t\t*prefetch( url: string, options: PrefetchOptions = {} ) {\n\t\t\tconst { clientNavigationDisabled } = getConfig();\n\t\t\tif ( clientNavigationDisabled ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst pagePath = getPagePath( url );\n\t\t\tif ( options.force || ! pages.has( pagePath ) ) {\n\t\t\t\tpages.set(\n\t\t\t\t\tpagePath,\n\t\t\t\t\tfetchPage( pagePath, { html: options.html } )\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tyield pages.get( pagePath );\n\t\t},\n\t},\n} );\n\n/**\n * Announces a message to screen readers.\n *\n * This is a wrapper around the `@wordpress/a11y` package's `speak` function. It handles importing\n * the package on demand and should be used instead of calling `a11y.speak` directly.\n *\n * @param messageKey The message to be announced by assistive technologies.\n */\nfunction a11ySpeak( messageKey: keyof typeof navigationTexts ) {\n\tif ( ! hasLoadedNavigationTextsData ) {\n\t\thasLoadedNavigationTextsData = true;\n\t\tconst content = document.getElementById(\n\t\t\t'wp-script-module-data-@wordpress/interactivity-router'\n\t\t)?.textContent;\n\t\tif ( content ) {\n\t\t\ttry {\n\t\t\t\tconst parsed = JSON.parse( content );\n\t\t\t\tif ( typeof parsed?.i18n?.loading === 'string' ) {\n\t\t\t\t\tnavigationTexts.loading = parsed.i18n.loading;\n\t\t\t\t}\n\t\t\t\tif ( typeof parsed?.i18n?.loaded === 'string' ) {\n\t\t\t\t\tnavigationTexts.loaded = parsed.i18n.loaded;\n\t\t\t\t}\n\t\t\t} catch {}\n\t\t} else {\n\t\t\t// Fallback to localized strings from Interactivity API state.\n\t\t\t// @todo This block is for Core < 6.7.0. Remove when support is dropped.\n\n\t\t\t// @ts-expect-error\n\t\t\tif ( state.navigation.texts?.loading ) {\n\t\t\t\t// @ts-expect-error\n\t\t\t\tnavigationTexts.loading = state.navigation.texts.loading;\n\t\t\t}\n\t\t\t// @ts-expect-error\n\t\t\tif ( state.navigation.texts?.loaded ) {\n\t\t\t\t// @ts-expect-error\n\t\t\t\tnavigationTexts.loaded = state.navigation.texts.loaded;\n\t\t\t}\n\t\t}\n\t}\n\n\tconst message = navigationTexts[ messageKey ];\n\n\timport( '@wordpress/a11y' ).then(\n\t\t( { speak } ) => speak( message ),\n\t\t// Ignore failures to load the a11y module.\n\t\t() => {}\n\t);\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,KAAK,EAAEC,WAAW,EAAEC,SAAS,QAAQ,0BAA0B;;AAExE;AACA;AACA;AACA,SAASC,aAAa,EAAEC,WAAW,QAA2B,iBAAiB;AAC/E,SACCC,oBAAoB,EACpBC,mBAAmB,EACnBC,0BAA0B,QAEpB,yBAAyB;AAEhC,MAAM;EACLC,eAAe;EACfC,qBAAqB;EACrBC,WAAW;EACXC,MAAM;EACNC,MAAM;EACNC,eAAe;EACfC,kBAAkB;EAClBC;AACD,CAAC,GAAGd,WAAW,CACd,wHACD,CAAC;AAED,MAAMe,UAAU,GAAG,QAASR,eAAe,gBAAiB;AAC5D,MAAMS,eAAe,GAAG,QAAST,eAAe,cAAe;AAC/D,MAAMU,eAAe,GAAG,IAAKD,eAAe,KAAOD,UAAU,UAAYC,eAAe,MAAQA,eAAe,IAAK;AAoCpH;AACA,MAAME,KAAK,GAAG,IAAIC,GAAG,CAAoC,CAAC;;AAE1D;AACA;AACA,MAAMC,WAAW,GAAKC,GAAW,IAAM;EACtC,MAAMC,CAAC,GAAG,IAAIC,GAAG,CAAEF,GAAG,EAAEG,MAAM,CA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ACA,IAAKT,KAAK,CAACW,UAAU,CAAC4B,KAAK,EAAE/B,OAAO,EAAG;QACtC;QACAD,eAAe,CAACC,OAAO,GAAGR,KAAK,CAACW,UAAU,CAAC4B,KAAK,CAAC/B,OAAO;MACzD;MACA;MACA,IAAKR,KAAK,CAACW,UAAU,CAAC4B,KAAK,EAAE9B,MAAM,EAAG;QACrC;QACAF,eAAe,CAACE,MAAM,GAAGT,KAAK,CAACW,UAAU,CAAC4B,KAAK,CAAC9B,MAAM;MACvD;IACD;EACD;EAEA,MAAM+B,OAAO,GAAGjC,eAAe,CAAE0B,UAAU,CAAE;EAE7C,MAAM,CAAE,iBAAkB,CAAC,CAACQ,IAAI,CAC/B,CAAE;IAAEC;EAAM,CAAC,KAAMA,KAAK,CAAEF,OAAQ,CAAC;EACjC;EACA,MAAM,CAAC,CACR,CAAC;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
* Internal dependencies
|
|
17
|
+
*/
|
|
18
|
+
import { type ModuleLoad } from './loader';
|
|
19
|
+
/**
|
|
20
|
+
* Fetches the passed module URL and return the corresponding `ModuleLoad`
|
|
21
|
+
* instance. If the passed URL does not point to a JS file, the function
|
|
22
|
+
* throws and error.
|
|
23
|
+
*
|
|
24
|
+
* @param url Module URL.
|
|
25
|
+
* @param fetchOpts Fetch init options.
|
|
26
|
+
* @param parent Parent module URL referencing this URL (if any).
|
|
27
|
+
* @return Promise with a `ModuleLoad` instance.
|
|
28
|
+
*/
|
|
29
|
+
export declare function fetchModule(url: string, fetchOpts: RequestInit, parent: string): Promise<ModuleLoad>;
|
|
30
|
+
//# sourceMappingURL=fetch.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch.d.ts","sourceRoot":"","sources":["../../../src/assets/dynamic-importmap/fetch.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH;;GAEG;AACH,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,UAAU,CAAC;AAQ3C;;;;;;;;;GASG;AACH,wBAAsB,WAAW,CAChC,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,WAAW,EACtB,MAAM,EAAE,MAAM,GACZ,OAAO,CAAE,UAAU,CAAE,CAiBvB"}
|
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
type ImportMap = {
|
|
16
|
+
imports?: Record<string, string>;
|
|
17
|
+
scopes?: Record<string, Record<string, string>>;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Imports the module with the passed ID.
|
|
21
|
+
*
|
|
22
|
+
* The module is resolved against the internal dynamic import map,
|
|
23
|
+
* extended with the passed import map.
|
|
24
|
+
*
|
|
25
|
+
* @param id Module ID.
|
|
26
|
+
* @param importMapIn Import map.
|
|
27
|
+
* @return Resolved module.
|
|
28
|
+
*/
|
|
29
|
+
export declare function importWithMap<Module = unknown>(id: string, importMapIn: ImportMap): Promise<Module>;
|
|
30
|
+
/**
|
|
31
|
+
* Preloads the module with the passed ID along with its dependencies.
|
|
32
|
+
*
|
|
33
|
+
* The module is resolved against the internal dynamic import map,
|
|
34
|
+
* extended with the passed import map.
|
|
35
|
+
*
|
|
36
|
+
* @param id Module ID.
|
|
37
|
+
* @param importMapIn Import map.
|
|
38
|
+
* @return Resolved `ModuleLoad` instance.
|
|
39
|
+
*/
|
|
40
|
+
export declare function preloadWithMap(id: string, importMapIn: ImportMap): Promise<import("./loader").ModuleLoad>;
|
|
41
|
+
export { initialImportMap, importPreloadedModule, type ModuleLoad, } from './loader';
|
|
42
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/assets/dynamic-importmap/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAQH,KAAK,SAAS,GAAG;IAChB,OAAO,CAAC,EAAE,MAAM,CAAE,MAAM,EAAE,MAAM,CAAE,CAAC;IACnC,MAAM,CAAC,EAAE,MAAM,CAAE,MAAM,EAAE,MAAM,CAAE,MAAM,EAAE,MAAM,CAAE,CAAE,CAAC;CACpD,CAAC;AAsBF;;;;;;;;;GASG;AACH,wBAAsB,aAAa,CAAE,MAAM,GAAG,OAAO,EACpD,EAAE,EAAE,MAAM,EACV,WAAW,EAAE,SAAS,mBAItB;AAED;;;;;;;;;GASG;AACH,wBAAsB,cAAc,CAAE,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,0CAMvE;AAED,OAAO,EACN,gBAAgB,EAChB,qBAAqB,EACrB,KAAK,UAAU,GACf,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,68 @@
|
|
|
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
|
+
* External dependencies
|
|
17
|
+
*/
|
|
18
|
+
import * as lexer from 'es-module-lexer';
|
|
19
|
+
export interface ModuleLoad {
|
|
20
|
+
url?: string;
|
|
21
|
+
responseUrl?: string;
|
|
22
|
+
fetchPromise?: Promise<ModuleLoad>;
|
|
23
|
+
source?: string;
|
|
24
|
+
linkPromise?: Promise<void>;
|
|
25
|
+
analysis?: ReturnType<typeof lexer.parse>;
|
|
26
|
+
deps?: ModuleLoad[];
|
|
27
|
+
blobUrl?: string;
|
|
28
|
+
shellUrl?: string;
|
|
29
|
+
}
|
|
30
|
+
export declare const initPromise: Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Data from the initial page's import map.
|
|
33
|
+
*
|
|
34
|
+
* Pages containing any of the imports present on the original page
|
|
35
|
+
* in their import maps should ignore them, as those imports would
|
|
36
|
+
* be handled natively.
|
|
37
|
+
*/
|
|
38
|
+
export declare const initialImportMap: any;
|
|
39
|
+
export declare const registry: {};
|
|
40
|
+
/**
|
|
41
|
+
* Resolves the passed module URL and fetches the corresponding module
|
|
42
|
+
* and their dependencies, returning a `ModuleLoad` object once all
|
|
43
|
+
* of them have been fetched.
|
|
44
|
+
*
|
|
45
|
+
* @param url Module URL.
|
|
46
|
+
* @param fetchOpts Fetch options.
|
|
47
|
+
* @return A promise with a `ModuleLoad` instance.
|
|
48
|
+
*/
|
|
49
|
+
export declare function preloadModule(url: string, fetchOpts?: RequestInit): Promise<ModuleLoad>;
|
|
50
|
+
/**
|
|
51
|
+
* Imports the module represented by the passed `ModuleLoad` instance.
|
|
52
|
+
*
|
|
53
|
+
* @param load The `ModuleLoad` instance representing the module.
|
|
54
|
+
* @return A promise with the imported module.
|
|
55
|
+
*/
|
|
56
|
+
export declare function importPreloadedModule<Module = unknown>(load: ModuleLoad): Promise<Module>;
|
|
57
|
+
/**
|
|
58
|
+
* Imports the module represented by the passed module URL.
|
|
59
|
+
*
|
|
60
|
+
* The module URL and all its dependencies are resolved using the
|
|
61
|
+
* current status of the internal dynamic import map.
|
|
62
|
+
*
|
|
63
|
+
* @param url Module URL.
|
|
64
|
+
* @param fetchOpts Fetch options.
|
|
65
|
+
* @return A promise with the imported module.
|
|
66
|
+
*/
|
|
67
|
+
export declare function topLevelLoad<Module = unknown>(url: string, fetchOpts?: RequestInit): Promise<Module>;
|
|
68
|
+
//# sourceMappingURL=loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../../src/assets/dynamic-importmap/loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH;;GAEG;AACH,OAAO,KAAK,KAAK,MAAM,iBAAiB,CAAC;AAQzC,MAAM,WAAW,UAAU;IAC1B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,OAAO,CAAE,UAAU,CAAE,CAAC;IACrC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,OAAO,CAAE,IAAI,CAAE,CAAC;IAC9B,QAAQ,CAAC,EAAE,UAAU,CAAE,OAAO,KAAK,CAAC,KAAK,CAAE,CAAC;IAC5C,IAAI,CAAC,EAAE,UAAU,EAAE,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,eAAO,MAAM,WAAW,eAAa,CAAC;AAUtC;;;;;;GAMG;AACH,eAAO,MAAM,gBAAgB,KAEC,CAAC;AAK/B,eAAO,MAAM,QAAQ,IAAK,CAAC;AAuP3B;;;;;;;;GAQG;AACH,wBAAsB,aAAa,CAClC,GAAG,EAAE,MAAM,EACX,SAAS,CAAC,EAAE,WAAW,GACrB,OAAO,CAAE,UAAU,CAAE,CASvB;AAED;;;;;GAKG;AACH,wBAAsB,qBAAqB,CAAE,MAAM,GAAG,OAAO,EAC5D,IAAI,EAAE,UAAU,GACd,OAAO,CAAE,MAAM,CAAE,CAOnB;AAED;;;;;;;;;GASG;AACH,wBAAsB,YAAY,CAAE,MAAM,GAAG,OAAO,EACnD,GAAG,EAAE,MAAM,EACX,SAAS,CAAC,EAAE,WAAW,GACrB,OAAO,CAAE,MAAM,CAAE,CAGnB"}
|