@wordpress/interactivity-router 2.31.1-next.f56bd8138.0 → 2.32.1-next.47f435fc9.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 +4 -0
- package/build/assets/dynamic-importmap/fetch.js +32 -43
- package/build/assets/dynamic-importmap/fetch.js.map +7 -1
- package/build/assets/dynamic-importmap/index.js +43 -73
- package/build/assets/dynamic-importmap/index.js.map +7 -1
- package/build/assets/dynamic-importmap/loader.js +139 -172
- package/build/assets/dynamic-importmap/loader.js.map +7 -1
- package/build/assets/dynamic-importmap/resolver.js +99 -112
- package/build/assets/dynamic-importmap/resolver.js.map +7 -1
- package/build/assets/script-modules.js +46 -58
- package/build/assets/script-modules.js.map +7 -1
- package/build/assets/scs.js +30 -39
- package/build/assets/scs.js.map +7 -1
- package/build/assets/styles.js +81 -171
- package/build/assets/styles.js.map +7 -1
- package/build/full-page.js +43 -36
- package/build/full-page.js.map +7 -1
- package/build/index.js +180 -243
- package/build/index.js.map +7 -1
- package/build-module/assets/dynamic-importmap/fetch.js +11 -39
- package/build-module/assets/dynamic-importmap/fetch.js.map +7 -1
- package/build-module/assets/dynamic-importmap/index.js +18 -52
- package/build-module/assets/dynamic-importmap/index.js.map +7 -1
- package/build-module/assets/dynamic-importmap/loader.js +101 -165
- package/build-module/assets/dynamic-importmap/loader.js.map +7 -1
- package/build-module/assets/dynamic-importmap/resolver.js +78 -108
- package/build-module/assets/dynamic-importmap/resolver.js.map +7 -1
- package/build-module/assets/script-modules.js +25 -49
- package/build-module/assets/script-modules.js.map +7 -1
- package/build-module/assets/scs.js +9 -35
- package/build-module/assets/scs.js.map +7 -1
- package/build-module/assets/styles.js +58 -163
- package/build-module/assets/styles.js.map +7 -1
- package/build-module/full-page.js +21 -32
- package/build-module/full-page.js.map +7 -1
- package/build-module/index.js +149 -235
- package/build-module/index.js.map +7 -1
- package/build-types/index.d.ts.map +1 -1
- package/package.json +12 -4
- package/src/index.ts +106 -26
- package/tsconfig.main.tsbuildinfo +1 -1
package/build/index.js
CHANGED
|
@@ -1,79 +1,86 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
Object.
|
|
5
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var index_exports = {};
|
|
29
|
+
__export(index_exports, {
|
|
30
|
+
actions: () => actions,
|
|
31
|
+
state: () => state
|
|
6
32
|
});
|
|
7
|
-
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
12
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } /**
|
|
13
|
-
* WordPress dependencies
|
|
14
|
-
*/ /**
|
|
15
|
-
* Internal dependencies
|
|
16
|
-
*/
|
|
33
|
+
module.exports = __toCommonJS(index_exports);
|
|
34
|
+
var import_interactivity = require("@wordpress/interactivity");
|
|
35
|
+
var import_styles = require("./assets/styles");
|
|
36
|
+
var import_script_modules = require("./assets/script-modules");
|
|
17
37
|
const {
|
|
18
|
-
directivePrefix,
|
|
19
38
|
getRegionRootFragment,
|
|
20
39
|
initialVdom,
|
|
21
40
|
toVdom,
|
|
22
41
|
render,
|
|
23
42
|
parseServerData,
|
|
24
43
|
populateServerData,
|
|
25
|
-
batch
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const getPagePath = url => {
|
|
44
|
+
batch,
|
|
45
|
+
routerRegions,
|
|
46
|
+
cloneElement
|
|
47
|
+
} = (0, import_interactivity.privateApis)(
|
|
48
|
+
"I acknowledge that using private APIs means my theme or plugin will inevitably break in the next version of WordPress."
|
|
49
|
+
);
|
|
50
|
+
const regionAttr = `data-wp-router-region`;
|
|
51
|
+
const interactiveAttr = `data-wp-interactive`;
|
|
52
|
+
const regionsSelector = `[${interactiveAttr}][${regionAttr}], [${interactiveAttr}] [${interactiveAttr}][${regionAttr}]`;
|
|
53
|
+
const pages = /* @__PURE__ */ new Map();
|
|
54
|
+
const getPagePath = (url) => {
|
|
36
55
|
const u = new URL(url, window.location.href);
|
|
37
56
|
return u.pathname + u.search;
|
|
38
57
|
};
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Parses the given region's directive.
|
|
42
|
-
*
|
|
43
|
-
* @param region Region element.
|
|
44
|
-
* @return Data contained in the region directive value.
|
|
45
|
-
*/
|
|
46
|
-
const parseRegionAttribute = region => {
|
|
58
|
+
const parseRegionAttribute = (region) => {
|
|
47
59
|
const value = region.getAttribute(regionAttr);
|
|
48
60
|
try {
|
|
49
|
-
const {
|
|
50
|
-
|
|
51
|
-
attachTo
|
|
52
|
-
} = JSON.parse(value);
|
|
53
|
-
return {
|
|
54
|
-
id,
|
|
55
|
-
attachTo
|
|
56
|
-
};
|
|
61
|
+
const { id, attachTo } = JSON.parse(value);
|
|
62
|
+
return { id, attachTo };
|
|
57
63
|
} catch (e) {
|
|
58
|
-
return {
|
|
59
|
-
id: value
|
|
60
|
-
};
|
|
64
|
+
return { id: value };
|
|
61
65
|
}
|
|
62
66
|
};
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
67
|
+
const cloneRouterRegionContent = (vdom) => {
|
|
68
|
+
if (!vdom) {
|
|
69
|
+
return vdom;
|
|
70
|
+
}
|
|
71
|
+
const allPriorityLevels = vdom.props.priorityLevels;
|
|
72
|
+
const routerRegionLevel = allPriorityLevels.findIndex(
|
|
73
|
+
(level) => level.includes("router-region")
|
|
74
|
+
);
|
|
75
|
+
const priorityLevels = routerRegionLevel !== -1 ? allPriorityLevels.slice(routerRegionLevel + 1) : allPriorityLevels;
|
|
76
|
+
return priorityLevels.length > 0 ? cloneElement(vdom, {
|
|
77
|
+
...vdom.props,
|
|
78
|
+
priorityLevels
|
|
79
|
+
}) : vdom.props.element;
|
|
80
|
+
};
|
|
81
|
+
const regionsToAttachByParent = /* @__PURE__ */ new WeakMap();
|
|
82
|
+
const rootFragmentsByParent = /* @__PURE__ */ new WeakMap();
|
|
83
|
+
const fetchPage = async (url, { html }) => {
|
|
77
84
|
try {
|
|
78
85
|
if (!html) {
|
|
79
86
|
const res = await window.fetch(url);
|
|
@@ -82,56 +89,33 @@ const fetchPage = async (url, {
|
|
|
82
89
|
}
|
|
83
90
|
html = await res.text();
|
|
84
91
|
}
|
|
85
|
-
const dom = new window.DOMParser().parseFromString(html,
|
|
92
|
+
const dom = new window.DOMParser().parseFromString(html, "text/html");
|
|
86
93
|
return await preparePage(url, dom);
|
|
87
94
|
} catch (e) {
|
|
88
95
|
return false;
|
|
89
96
|
}
|
|
90
97
|
};
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
* Processes a DOM document to extract router regions and related resources.
|
|
94
|
-
*
|
|
95
|
-
* This function analyzes the provided DOM document and creates a virtual DOM
|
|
96
|
-
* representation of all HTML regions marked with a `router-region` directive.
|
|
97
|
-
* It also extracts and preloads associated styles and scripts to prepare for
|
|
98
|
-
* rendering the page.
|
|
99
|
-
*
|
|
100
|
-
* @param url The URL associated with the page, used for asset
|
|
101
|
-
* loading and caching.
|
|
102
|
-
* @param dom The DOM document to process.
|
|
103
|
-
* @param vdomParams Optional parameters for virtual DOM processing.
|
|
104
|
-
* @param vdomParams.vdom An optional existing virtual DOM cache to check for
|
|
105
|
-
* regions. If a region exists in this cache, it will be
|
|
106
|
-
* reused instead of creating a new vDOM representation.
|
|
107
|
-
* @return A Promise that resolves to a {@link Page} object
|
|
108
|
-
* containing the virtual DOM for all router regions,
|
|
109
|
-
* preloaded styles and scripts, page title, and initial
|
|
110
|
-
* server-rendered data.
|
|
111
|
-
*/
|
|
112
|
-
const preparePage = async (url, dom, {
|
|
113
|
-
vdom
|
|
114
|
-
} = {}) => {
|
|
115
|
-
// Remove all noscript elements as they're irrelevant when request is served via router.
|
|
116
|
-
// This prevents browsers from extracting styles from noscript tags.
|
|
117
|
-
dom.querySelectorAll('noscript').forEach(el => el.remove());
|
|
98
|
+
const preparePage = async (url, dom, { vdom } = {}) => {
|
|
99
|
+
dom.querySelectorAll("noscript").forEach((el) => el.remove());
|
|
118
100
|
const regions = {};
|
|
119
101
|
const regionsToAttach = {};
|
|
120
|
-
dom.querySelectorAll(regionsSelector).forEach(region => {
|
|
121
|
-
const {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}
|
|
125
|
-
|
|
102
|
+
dom.querySelectorAll(regionsSelector).forEach((region) => {
|
|
103
|
+
const { id, attachTo } = parseRegionAttribute(region);
|
|
104
|
+
if (region.parentElement.closest(`[${regionAttr}]`)) {
|
|
105
|
+
regions[id] = void 0;
|
|
106
|
+
} else {
|
|
107
|
+
regions[id] = vdom?.has(region) ? vdom.get(region) : toVdom(region);
|
|
108
|
+
}
|
|
126
109
|
if (attachTo) {
|
|
127
110
|
regionsToAttach[id] = attachTo;
|
|
128
111
|
}
|
|
129
112
|
});
|
|
130
|
-
const title = dom.querySelector(
|
|
113
|
+
const title = dom.querySelector("title")?.innerText;
|
|
131
114
|
const initialData = parseServerData(dom);
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
115
|
+
const [styles, scriptModules] = await Promise.all([
|
|
116
|
+
Promise.all((0, import_styles.preloadStyles)(dom, url)),
|
|
117
|
+
Promise.all((0, import_script_modules.preloadScriptModules)(dom))
|
|
118
|
+
]);
|
|
135
119
|
return {
|
|
136
120
|
regions,
|
|
137
121
|
regionsToAttach,
|
|
@@ -142,105 +126,87 @@ const preparePage = async (url, dom, {
|
|
|
142
126
|
url
|
|
143
127
|
};
|
|
144
128
|
};
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
* and updating the document title.
|
|
149
|
-
*
|
|
150
|
-
* @param page The {@link Page} object to render.
|
|
151
|
-
*/
|
|
152
|
-
const renderPage = page => {
|
|
153
|
-
(0, _styles.applyStyles)(page.styles);
|
|
154
|
-
|
|
155
|
-
// Clone regionsToAttach.
|
|
156
|
-
const regionsToAttach = {
|
|
157
|
-
...page.regionsToAttach
|
|
158
|
-
};
|
|
129
|
+
const renderPage = (page) => {
|
|
130
|
+
(0, import_styles.applyStyles)(page.styles);
|
|
131
|
+
const regionsToAttach = { ...page.regionsToAttach };
|
|
159
132
|
batch(() => {
|
|
160
133
|
populateServerData(page.initialData);
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
id
|
|
164
|
-
} = parseRegionAttribute(region);
|
|
165
|
-
const fragment = getRegionRootFragment(region);
|
|
166
|
-
render(page.regions[id], fragment);
|
|
167
|
-
// If this is an attached region, remove it from the list.
|
|
168
|
-
delete regionsToAttach[id];
|
|
134
|
+
routerRegions.forEach((signal) => {
|
|
135
|
+
signal.value = null;
|
|
169
136
|
});
|
|
170
|
-
|
|
171
|
-
// Render unattached regions.
|
|
137
|
+
const parentsToUpdate = /* @__PURE__ */ new Set();
|
|
172
138
|
for (const id in regionsToAttach) {
|
|
173
139
|
const parent = document.querySelector(regionsToAttach[id]);
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
const
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
// Create an element with the obtained type where the region will be
|
|
184
|
-
// rendered. The type should match the one of the root vnode.
|
|
185
|
-
const region = document.createElement(elementType);
|
|
186
|
-
parent.appendChild(region);
|
|
187
|
-
const fragment = getRegionRootFragment(region);
|
|
188
|
-
render(page.regions[id], fragment);
|
|
140
|
+
if (!regionsToAttachByParent.has(parent)) {
|
|
141
|
+
regionsToAttachByParent.set(parent, []);
|
|
142
|
+
}
|
|
143
|
+
const regions = regionsToAttachByParent.get(parent);
|
|
144
|
+
if (!regions.includes(id)) {
|
|
145
|
+
regions.push(id);
|
|
146
|
+
parentsToUpdate.add(parent);
|
|
147
|
+
}
|
|
189
148
|
}
|
|
149
|
+
for (const id in page.regions) {
|
|
150
|
+
if (routerRegions.has(id)) {
|
|
151
|
+
routerRegions.get(id).value = cloneRouterRegionContent(
|
|
152
|
+
page.regions[id]
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
parentsToUpdate.forEach((parent) => {
|
|
157
|
+
const ids = regionsToAttachByParent.get(parent);
|
|
158
|
+
const vdoms = ids.map((id) => page.regions[id]);
|
|
159
|
+
if (!rootFragmentsByParent.has(parent)) {
|
|
160
|
+
const regions = vdoms.map(({ props, type }) => {
|
|
161
|
+
const elementType = typeof type === "function" ? props.type : type;
|
|
162
|
+
const region = document.createElement(elementType);
|
|
163
|
+
parent.appendChild(region);
|
|
164
|
+
return region;
|
|
165
|
+
});
|
|
166
|
+
rootFragmentsByParent.set(
|
|
167
|
+
parent,
|
|
168
|
+
getRegionRootFragment(regions)
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
const fragment = rootFragmentsByParent.get(parent);
|
|
172
|
+
render(vdoms, fragment);
|
|
173
|
+
});
|
|
190
174
|
});
|
|
191
175
|
if (page.title) {
|
|
192
176
|
document.title = page.title;
|
|
193
177
|
}
|
|
194
178
|
};
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* Loads the given page forcing a full page reload.
|
|
198
|
-
*
|
|
199
|
-
* The function returns a promise that won't resolve, useful to prevent any
|
|
200
|
-
* potential feedback indicating that the navigation has finished while the new
|
|
201
|
-
* page is being loaded.
|
|
202
|
-
*
|
|
203
|
-
* @param href The page href.
|
|
204
|
-
* @return Promise that never resolves.
|
|
205
|
-
*/
|
|
206
|
-
const forcePageReload = href => {
|
|
179
|
+
const forcePageReload = (href) => {
|
|
207
180
|
window.location.assign(href);
|
|
208
|
-
return new Promise(() => {
|
|
181
|
+
return new Promise(() => {
|
|
182
|
+
});
|
|
209
183
|
};
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
window.addEventListener('popstate', async () => {
|
|
214
|
-
const pagePath = getPagePath(window.location.href); // Remove hash.
|
|
215
|
-
const page = pages.has(pagePath) && (await pages.get(pagePath));
|
|
184
|
+
window.addEventListener("popstate", async () => {
|
|
185
|
+
const pagePath = getPagePath(window.location.href);
|
|
186
|
+
const page = pages.has(pagePath) && await pages.get(pagePath);
|
|
216
187
|
if (page) {
|
|
217
188
|
renderPage(page);
|
|
218
|
-
// Update the URL in the state.
|
|
219
189
|
state.url = window.location.href;
|
|
220
190
|
} else {
|
|
221
191
|
window.location.reload();
|
|
222
192
|
}
|
|
223
193
|
});
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
window.
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
let navigatingTo = '';
|
|
194
|
+
window.document.querySelectorAll("script[type=module][src]").forEach(({ src }) => (0, import_script_modules.markScriptModuleAsResolved)(src));
|
|
195
|
+
pages.set(
|
|
196
|
+
getPagePath(window.location.href),
|
|
197
|
+
Promise.resolve(
|
|
198
|
+
preparePage(getPagePath(window.location.href), document, {
|
|
199
|
+
vdom: initialVdom
|
|
200
|
+
})
|
|
201
|
+
)
|
|
202
|
+
);
|
|
203
|
+
let navigatingTo = "";
|
|
235
204
|
let hasLoadedNavigationTextsData = false;
|
|
236
205
|
const navigationTexts = {
|
|
237
|
-
loading:
|
|
238
|
-
loaded:
|
|
206
|
+
loading: "Loading page, please wait.",
|
|
207
|
+
loaded: "Page Loaded."
|
|
239
208
|
};
|
|
240
|
-
const {
|
|
241
|
-
state,
|
|
242
|
-
actions
|
|
243
|
-
} = (0, _interactivity.store)('core/router', {
|
|
209
|
+
const { state, actions } = (0, import_interactivity.store)("core/router", {
|
|
244
210
|
state: {
|
|
245
211
|
url: window.location.href,
|
|
246
212
|
navigation: {
|
|
@@ -268,29 +234,22 @@ const {
|
|
|
268
234
|
* @return Promise that resolves once the navigation is completed or aborted.
|
|
269
235
|
*/
|
|
270
236
|
*navigate(href, options = {}) {
|
|
271
|
-
const {
|
|
272
|
-
clientNavigationDisabled
|
|
273
|
-
} = (0, _interactivity.getConfig)();
|
|
237
|
+
const { clientNavigationDisabled } = (0, import_interactivity.getConfig)();
|
|
274
238
|
if (clientNavigationDisabled) {
|
|
275
239
|
yield forcePageReload(href);
|
|
276
240
|
}
|
|
277
241
|
const pagePath = getPagePath(href);
|
|
278
|
-
const {
|
|
279
|
-
navigation
|
|
280
|
-
} = state;
|
|
242
|
+
const { navigation } = state;
|
|
281
243
|
const {
|
|
282
244
|
loadingAnimation = true,
|
|
283
245
|
screenReaderAnnouncement = true,
|
|
284
|
-
timeout =
|
|
246
|
+
timeout = 1e4
|
|
285
247
|
} = options;
|
|
286
248
|
navigatingTo = href;
|
|
287
249
|
actions.prefetch(pagePath, options);
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
const timeoutPromise = new Promise(resolve => setTimeout(resolve, timeout));
|
|
292
|
-
|
|
293
|
-
// Don't update the navigation status immediately, wait 400 ms.
|
|
250
|
+
const timeoutPromise = new Promise(
|
|
251
|
+
(resolve) => setTimeout(resolve, timeout)
|
|
252
|
+
);
|
|
294
253
|
const loadingTimeout = setTimeout(() => {
|
|
295
254
|
if (navigatingTo !== href) {
|
|
296
255
|
return;
|
|
@@ -300,42 +259,30 @@ const {
|
|
|
300
259
|
navigation.hasFinished = false;
|
|
301
260
|
}
|
|
302
261
|
if (screenReaderAnnouncement) {
|
|
303
|
-
a11ySpeak(
|
|
262
|
+
a11ySpeak("loading");
|
|
304
263
|
}
|
|
305
264
|
}, 400);
|
|
306
|
-
const page = yield Promise.race([
|
|
307
|
-
|
|
308
|
-
|
|
265
|
+
const page = yield Promise.race([
|
|
266
|
+
pages.get(pagePath),
|
|
267
|
+
timeoutPromise
|
|
268
|
+
]);
|
|
309
269
|
clearTimeout(loadingTimeout);
|
|
310
|
-
|
|
311
|
-
// Once the page is fetched, the destination URL could have changed
|
|
312
|
-
// (e.g., by clicking another link in the meantime). If so, bail
|
|
313
|
-
// out, and let the newer execution to update the HTML.
|
|
314
270
|
if (navigatingTo !== href) {
|
|
315
271
|
return;
|
|
316
272
|
}
|
|
317
|
-
if (page && !page.initialData?.config?.[
|
|
318
|
-
yield (0,
|
|
273
|
+
if (page && !page.initialData?.config?.["core/router"]?.clientNavigationDisabled) {
|
|
274
|
+
yield (0, import_script_modules.importScriptModules)(page.scriptModules);
|
|
319
275
|
renderPage(page);
|
|
320
|
-
window.history[options.replace ?
|
|
321
|
-
|
|
322
|
-
// Update the URL in the state.
|
|
276
|
+
window.history[options.replace ? "replaceState" : "pushState"]({}, "", href);
|
|
323
277
|
state.url = href;
|
|
324
|
-
|
|
325
|
-
// Update the navigation status once the the new page rendering
|
|
326
|
-
// has been completed.
|
|
327
278
|
if (loadingAnimation) {
|
|
328
279
|
navigation.hasStarted = false;
|
|
329
280
|
navigation.hasFinished = true;
|
|
330
281
|
}
|
|
331
282
|
if (screenReaderAnnouncement) {
|
|
332
|
-
a11ySpeak(
|
|
283
|
+
a11ySpeak("loaded");
|
|
333
284
|
}
|
|
334
|
-
|
|
335
|
-
// Scroll to the anchor if exits in the link.
|
|
336
|
-
const {
|
|
337
|
-
hash
|
|
338
|
-
} = new URL(href, window.location.href);
|
|
285
|
+
const { hash } = new URL(href, window.location.href);
|
|
339
286
|
if (hash) {
|
|
340
287
|
document.querySelector(hash)?.scrollIntoView();
|
|
341
288
|
}
|
|
@@ -357,68 +304,58 @@ const {
|
|
|
357
304
|
* @return Promise that resolves once the page has been fetched.
|
|
358
305
|
*/
|
|
359
306
|
*prefetch(url, options = {}) {
|
|
360
|
-
const {
|
|
361
|
-
clientNavigationDisabled
|
|
362
|
-
} = (0, _interactivity.getConfig)();
|
|
307
|
+
const { clientNavigationDisabled } = (0, import_interactivity.getConfig)();
|
|
363
308
|
if (clientNavigationDisabled) {
|
|
364
309
|
return;
|
|
365
310
|
}
|
|
366
311
|
const pagePath = getPagePath(url);
|
|
367
312
|
if (options.force || !pages.has(pagePath)) {
|
|
368
|
-
pages.set(
|
|
369
|
-
|
|
370
|
-
|
|
313
|
+
pages.set(
|
|
314
|
+
pagePath,
|
|
315
|
+
fetchPage(pagePath, { html: options.html })
|
|
316
|
+
);
|
|
371
317
|
}
|
|
372
318
|
yield pages.get(pagePath);
|
|
373
319
|
}
|
|
374
320
|
}
|
|
375
321
|
});
|
|
376
|
-
|
|
377
|
-
/**
|
|
378
|
-
* Announces a message to screen readers.
|
|
379
|
-
*
|
|
380
|
-
* This is a wrapper around the `@wordpress/a11y` package's `speak` function. It handles importing
|
|
381
|
-
* the package on demand and should be used instead of calling `a11y.speak` directly.
|
|
382
|
-
*
|
|
383
|
-
* @param messageKey The message to be announced by assistive technologies.
|
|
384
|
-
*/
|
|
385
|
-
exports.actions = actions;
|
|
386
|
-
exports.state = state;
|
|
387
322
|
function a11ySpeak(messageKey) {
|
|
388
323
|
if (!hasLoadedNavigationTextsData) {
|
|
389
324
|
hasLoadedNavigationTextsData = true;
|
|
390
|
-
const content = document.getElementById(
|
|
325
|
+
const content = document.getElementById(
|
|
326
|
+
"wp-script-module-data-@wordpress/interactivity-router"
|
|
327
|
+
)?.textContent;
|
|
391
328
|
if (content) {
|
|
392
329
|
try {
|
|
393
330
|
const parsed = JSON.parse(content);
|
|
394
|
-
if (typeof parsed?.i18n?.loading ===
|
|
331
|
+
if (typeof parsed?.i18n?.loading === "string") {
|
|
395
332
|
navigationTexts.loading = parsed.i18n.loading;
|
|
396
333
|
}
|
|
397
|
-
if (typeof parsed?.i18n?.loaded ===
|
|
334
|
+
if (typeof parsed?.i18n?.loaded === "string") {
|
|
398
335
|
navigationTexts.loaded = parsed.i18n.loaded;
|
|
399
336
|
}
|
|
400
|
-
} catch {
|
|
337
|
+
} catch {
|
|
338
|
+
}
|
|
401
339
|
} else {
|
|
402
|
-
// Fallback to localized strings from Interactivity API state.
|
|
403
|
-
// @todo This block is for Core < 6.7.0. Remove when support is dropped.
|
|
404
|
-
|
|
405
|
-
// @ts-expect-error
|
|
406
340
|
if (state.navigation.texts?.loading) {
|
|
407
|
-
// @ts-expect-error
|
|
408
341
|
navigationTexts.loading = state.navigation.texts.loading;
|
|
409
342
|
}
|
|
410
|
-
// @ts-expect-error
|
|
411
343
|
if (state.navigation.texts?.loaded) {
|
|
412
|
-
// @ts-expect-error
|
|
413
344
|
navigationTexts.loaded = state.navigation.texts.loaded;
|
|
414
345
|
}
|
|
415
346
|
}
|
|
416
347
|
}
|
|
417
348
|
const message = navigationTexts[messageKey];
|
|
418
|
-
|
|
419
|
-
speak
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
349
|
+
import("@wordpress/a11y").then(
|
|
350
|
+
({ speak }) => speak(message),
|
|
351
|
+
// Ignore failures to load the a11y module.
|
|
352
|
+
() => {
|
|
353
|
+
}
|
|
354
|
+
);
|
|
423
355
|
}
|
|
424
|
-
|
|
356
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
357
|
+
0 && (module.exports = {
|
|
358
|
+
actions,
|
|
359
|
+
state
|
|
360
|
+
});
|
|
361
|
+
//# sourceMappingURL=index.js.map
|