summaryrefslogtreecommitdiffstats
path: root/wp-includes/js/dist/router.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-09-19 04:51:18 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-09-19 04:51:18 +0000
commit0e41b5d52fdc6af6442816b5f465c9db9f84e126 (patch)
treee139a90049b158d4eed892d1662ee7f5c358fa31 /wp-includes/js/dist/router.js
parentAdding upstream version 6.5.5+dfsg1. (diff)
downloadwordpress-upstream.tar.xz
wordpress-upstream.zip
Adding upstream version 6.6.1+dfsg1.upstream/6.6.1+dfsg1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'wp-includes/js/dist/router.js')
-rw-r--r--wp-includes/js/dist/router.js84
1 files changed, 52 insertions, 32 deletions
diff --git a/wp-includes/js/dist/router.js b/wp-includes/js/dist/router.js
index 6e482fa..631591a 100644
--- a/wp-includes/js/dist/router.js
+++ b/wp-includes/js/dist/router.js
@@ -42,8 +42,6 @@ __webpack_require__.d(__webpack_exports__, {
privateApis: () => (/* reexport */ privateApis)
});
-;// CONCATENATED MODULE: external "React"
-const external_React_namespaceObject = window["React"];
;// CONCATENATED MODULE: external ["wp","element"]
const external_wp_element_namespaceObject = window["wp"]["element"];
;// CONCATENATED MODULE: ./node_modules/@babel/runtime/helpers/esm/extends.js
@@ -866,24 +864,57 @@ const external_wp_url_namespaceObject = window["wp"]["url"];
const history_history = createBrowserHistory();
const originalHistoryPush = history_history.push;
const originalHistoryReplace = history_history.replace;
+
+// Preserve the `wp_theme_preview` query parameter when navigating
+// around the Site Editor.
+// TODO: move this hack out of the router into Site Editor code.
+function preserveThemePreview(params) {
+ if (params.hasOwnProperty('wp_theme_preview')) {
+ return params;
+ }
+ const currentSearch = new URLSearchParams(history_history.location.search);
+ const currentThemePreview = currentSearch.get('wp_theme_preview');
+ if (currentThemePreview === null) {
+ return params;
+ }
+ return {
+ ...params,
+ wp_theme_preview: currentThemePreview
+ };
+}
function push(params, state) {
- const currentArgs = (0,external_wp_url_namespaceObject.getQueryArgs)(window.location.href);
- const currentUrlWithoutArgs = (0,external_wp_url_namespaceObject.removeQueryArgs)(window.location.href, ...Object.keys(currentArgs));
- const newUrl = (0,external_wp_url_namespaceObject.addQueryArgs)(currentUrlWithoutArgs, params);
- return originalHistoryPush.call(history_history, newUrl, state);
+ const search = (0,external_wp_url_namespaceObject.buildQueryString)(preserveThemePreview(params));
+ return originalHistoryPush.call(history_history, {
+ search
+ }, state);
}
function replace(params, state) {
- const currentArgs = (0,external_wp_url_namespaceObject.getQueryArgs)(window.location.href);
- const currentUrlWithoutArgs = (0,external_wp_url_namespaceObject.removeQueryArgs)(window.location.href, ...Object.keys(currentArgs));
- const newUrl = (0,external_wp_url_namespaceObject.addQueryArgs)(currentUrlWithoutArgs, params);
- return originalHistoryReplace.call(history_history, newUrl, state);
+ const search = (0,external_wp_url_namespaceObject.buildQueryString)(preserveThemePreview(params));
+ return originalHistoryReplace.call(history_history, {
+ search
+ }, state);
+}
+const locationMemo = new WeakMap();
+function getLocationWithParams() {
+ const location = history_history.location;
+ let locationWithParams = locationMemo.get(location);
+ if (!locationWithParams) {
+ locationWithParams = {
+ ...location,
+ params: Object.fromEntries(new URLSearchParams(location.search))
+ };
+ locationMemo.set(location, locationWithParams);
+ }
+ return locationWithParams;
}
history_history.push = push;
history_history.replace = replace;
+history_history.getLocationWithParams = getLocationWithParams;
/* harmony default export */ const build_module_history = (history_history);
+;// CONCATENATED MODULE: external "ReactJSXRuntime"
+const external_ReactJSXRuntime_namespaceObject = window["ReactJSXRuntime"];
;// CONCATENATED MODULE: ./node_modules/@wordpress/router/build-module/router.js
-
/**
* WordPress dependencies
*/
@@ -893,6 +924,7 @@ history_history.replace = replace;
* Internal dependencies
*/
+
const RoutesContext = (0,external_wp_element_namespaceObject.createContext)();
const HistoryContext = (0,external_wp_element_namespaceObject.createContext)();
function useLocation() {
@@ -901,29 +933,17 @@ function useLocation() {
function useHistory() {
return (0,external_wp_element_namespaceObject.useContext)(HistoryContext);
}
-function getLocationWithParams(location) {
- const searchParams = new URLSearchParams(location.search);
- return {
- ...location,
- params: Object.fromEntries(searchParams.entries())
- };
-}
function RouterProvider({
children
}) {
- const [location, setLocation] = (0,external_wp_element_namespaceObject.useState)(() => getLocationWithParams(build_module_history.location));
- (0,external_wp_element_namespaceObject.useEffect)(() => {
- return build_module_history.listen(({
- location: updatedLocation
- }) => {
- setLocation(getLocationWithParams(updatedLocation));
- });
- }, []);
- return (0,external_React_namespaceObject.createElement)(HistoryContext.Provider, {
- value: build_module_history
- }, (0,external_React_namespaceObject.createElement)(RoutesContext.Provider, {
- value: location
- }, children));
+ const location = (0,external_wp_element_namespaceObject.useSyncExternalStore)(build_module_history.listen, build_module_history.getLocationWithParams, build_module_history.getLocationWithParams);
+ return /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(HistoryContext.Provider, {
+ value: build_module_history,
+ children: /*#__PURE__*/(0,external_ReactJSXRuntime_namespaceObject.jsx)(RoutesContext.Provider, {
+ value: location,
+ children: children
+ })
+ });
}
;// CONCATENATED MODULE: external ["wp","privateApis"]
@@ -936,7 +956,7 @@ const external_wp_privateApis_namespaceObject = window["wp"]["privateApis"];
const {
lock,
unlock
-} = (0,external_wp_privateApis_namespaceObject.__dangerousOptInToUnstableAPIsOnlyForCoreModules)('I know using unstable features means my theme or plugin will inevitably break in the next version of WordPress.', '@wordpress/router');
+} = (0,external_wp_privateApis_namespaceObject.__dangerousOptInToUnstableAPIsOnlyForCoreModules)('I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.', '@wordpress/router');
;// CONCATENATED MODULE: ./node_modules/@wordpress/router/build-module/private-apis.js
/**