@wordpress/interactivity-router 2.8.5 → 2.10.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 CHANGED
@@ -2,6 +2,20 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 2.10.0 (2024-10-16)
6
+
7
+ ### Enhancements
8
+
9
+ - Improvements to the experimental full-page navigation ([#64067](https://github.com/WordPress/gutenberg/pull/64067)):
10
+ - Remove the `src` attributes from prefetched script tags.
11
+ - Use `.textContent` instead of `.innerText` to set `<script>` contents.
12
+ - Use [`populateServerData()`](https://github.com/WordPress/gutenberg/blob/9671329c386d2b743f14ef314823fbf915366ebd/packages/interactivity/src/store.ts#L269) with state from the server.
13
+ - Wait for the `load` event of the script element before evaluating it.
14
+ - Make `renderRegions()` an async function.
15
+ - Only prefetch **module** scripts, never prefetch regular scripts. That's because regular scripts (without `async` or `defer` attributes) found in the head are blocking and must be executed in order. When prefetching there is no guarantee that the scripts will execute in the order they are prefetched. Module scripts can be executed in any order.
16
+
17
+ ## 2.9.0 (2024-10-03)
18
+
5
19
  ## 2.8.0 (2024-09-19)
6
20
 
7
21
  ## 2.7.0 (2024-09-05)
package/README.md CHANGED
@@ -1,21 +1,32 @@
1
- # Interactivity Router
1
+ # `@wordpress/interactivity-router`
2
2
 
3
- > **Note**
4
- > This package is a extension of the API shared at [Proposal: The Interactivity API – A better developer experience in building interactive blocks](https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/). As part of an [Open Source project](https://developer.wordpress.org/block-editor/getting-started/faq/#the-gutenberg-project) we encourage participation in helping shape this API and the [discussions in GitHub](https://github.com/WordPress/gutenberg/discussions/categories/interactivity-api) is the best place to engage.
3
+ The package `@wordpress/interactivity-router` enables loading content from other pages without a full page reload. Currently, the only supported mode is "region-based". Full "client-side navigation" is still in experimental phase.
5
4
 
6
- This package defines an Interactivity API store with the `core/router` namespace, exposing state and actions like `navigate` and `prefetch` to handle client-side navigations.
5
+ The package defines an Interactivity API store with the `core/router` namespace, exposing state and 2 actions: `navigate` and `prefetch` to handle client-side navigation.
6
+
7
+ The `@wordpress/interactivity-router` package was [introduced in WordPress Core in v6.5](https://make.wordpress.org/core/2024/02/19/merge-announcement-interactivity-api/). This means this package is already bundled in Core in any version of WordPress higher than v6.5.
8
+
9
+ <div class="callout callout-info">
10
+ Check the <a href="https://developer.wordpress.org/block-editor/reference-guides/interactivity-api/">Interactivity API Reference docs in the Block Editor handbook</a> to learn more about the Interactivity API.
11
+ </div>
7
12
 
8
13
  ## Usage
9
14
 
10
- The package is intended to be imported dynamically in the `view.js` files of interactive blocks.
15
+ The package is intended to be imported dynamically in the `view.js` files of interactive blocks. This is done in in order to reduce the JS bundle size on the initial page load.
11
16
 
12
17
  ```js
18
+ /* view.js */
19
+
13
20
  import { store } from '@wordpress/interactivity';
14
21
 
15
- store( 'myblock', {
22
+ // This is how you would typically use the navigate() action in your block.
23
+ store( 'my-namespace/myblock', {
16
24
  actions: {
17
- *navigate( e ) {
25
+ *goToPage( e ) {
18
26
  e.preventDefault();
27
+
28
+ // We import the package dynamically to reduce the initial JS bundle size.
29
+ // Async actions are defined as generators so the import() must be called with `yield`.
19
30
  const { actions } = yield import(
20
31
  '@wordpress/interactivity-router'
21
32
  );
@@ -25,52 +36,116 @@ store( 'myblock', {
25
36
  } );
26
37
  ```
27
38
 
28
- ## Frequently Asked Questions
39
+ Now, you can call `actions.navigate()` in your block's `view.js` file to navigate to a different page or e.g. pass it to a `data-wp-on--click` attribute.
40
+
41
+ When loaded, this package [adds the following state and actions](https://github.com/WordPress/gutenberg/blob/ed7d78652526270b63976d7a970dba46a2bfcbb0/packages/interactivity-router/src/index.ts#L212) to the `core/router` store:
42
+
43
+ ```js
44
+ const { state, actions } = store( 'core/router', {
45
+ state: {
46
+ url: window.location.href,
47
+ navigation: {
48
+ hasStarted: false,
49
+ hasFinished: false,
50
+ texts: {
51
+ loading: '',
52
+ loaded: '',
53
+ },
54
+ message: '',
55
+ },
56
+ },
57
+ actions: {
58
+ *navigate(href, options) {...},
59
+ prefetch(url, options) {...},
60
+ }
61
+ })
62
+ ```
63
+
64
+ <div class="callout callout-tip">
65
+ The core "Query Loop" block is <a href="https://github.com/WordPress/gutenberg/blob/cd701e94ceffea7ef2f423274a2f77025bcfa1a6/packages/block-library/src/query/view.js#L35">using this package</a> to provide the <a href="https://github.com/WordPress/gutenberg/blob/cd701e94ceffea7ef2f423274a2f77025bcfa1a6/packages/block-library/src/query/index.php#L33">region-based navigation</a>.
66
+ </div>
67
+
68
+ ### Directives
69
+
70
+ #### `data-wp-router-region`
71
+
72
+ It defines a region that is updated on navigation. It requires a unique ID as the value and can only be used in root interactive elements, i.e., elements with `data-wp-interactive` that are not nested inside other elements with `data-wp-interactive`.
73
+
74
+ Example:
75
+
76
+ ```html
77
+ <div data-wp-interactive="myblock" data-wp-router-region="main-list">
78
+ <ul>
79
+ <li><a href="/post-1">Post 1</a></li>
80
+ <li><a href="/post-2">Post 2</a></li>
81
+ <li><a href="/post-3">Post 3</a></li>
82
+ </ul>
83
+ <a data-wp-on--click="actions.navigate" href="/page/2">
84
+ </div>
85
+ ```
86
+
87
+ ### Actions
88
+
89
+ #### `navigate`
90
+
91
+ Navigates to the specified page.
29
92
 
30
- At this point, some of the questions you have about the Interactivity API may be:
93
+ This function normalizes the passed `href`, fetches the page HTML if needed, and updates any interactive regions whose contents have changed in the new page. It also creates a new entry in the browser session history.
31
94
 
32
- ### What is this?
95
+ **Params**
33
96
 
34
- This is the base of a new standard to create interactive blocks. Read [the proposal](https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/) to learn more about this.
97
+ ```js
98
+ navigate( href: string, options: NavigateOptions = {} )
99
+ ```
35
100
 
36
- ### Can I use it?
101
+ - `href`: The page `href`.
102
+ - `options`: Options object.
103
+ - `force`: If `true`, it forces re-fetching the URL. `navigate()` always caches the page, so if the page has been navigated to before, it will be used. Default is `false`.
104
+ - `html`: HTML string to be used instead of fetching the requested URL.
105
+ - `replace`: If `true`, it replaces the current entry in the browser session history. Default is `false`.
106
+ - `timeout`: Time until the navigation is aborted, in milliseconds. Default is `10000`.
107
+ - `loadingAnimation`: Whether an animation should be shown while navigating. Default to `true`.
108
+ - `screenReaderAnnouncement`: Whether a message for screen readers should be announced while navigating. Default to `true`.
37
109
 
38
- You can test it, but it's still very experimental.
110
+ #### `prefetch`
39
111
 
40
- ### How do I get started?
112
+ Prefetches the page for the passed URL. The page is cached and can be used for navigation.
41
113
 
42
- The best place to start with the Interactivity API is this [**Getting started guide**](https://github.com/WordPress/gutenberg/blob/trunk/packages/interactivity/docs/1-getting-started.md). There you'll will find a very quick start guide and the current requirements of the Interactivity API.
114
+ The function normalizes the URL and stores internally the fetch promise, to avoid triggering a second fetch for an ongoing request.
43
115
 
44
- ### Where can I ask questions?
116
+ **Params**
45
117
 
46
- The [“Interactivity API” category](https://github.com/WordPress/gutenberg/discussions/categories/interactivity-api) in Gutenberg repo discussions is the best place to ask questions about the Interactivity API.
118
+ ```js
119
+ prefetch( url: string, options: PrefetchOptions = {} )
120
+ ```
47
121
 
48
- ### Where can I share my feedback about the API?
122
+ - `url`: The page `url`.
123
+ - `options`: Options object.
49
124
 
50
- The [“Interactivity API” category](https://github.com/WordPress/gutenberg/discussions/categories/interactivity-api) in Gutenberg repo discussions is also the best place to share your feedback about the Interactivity API.
125
+ - `force`: If `true`, forces fetching the URL again.
126
+ - `html`: HTML string to be used instead of fetching the requested URL.
127
+
128
+ ### State
129
+
130
+ `state.url` is a reactive property synchronized with the current URL.
131
+ Properties under `state.navigation` are meant for loading bar animations.
51
132
 
52
133
  ## Installation
53
134
 
54
135
  Install the module:
55
136
 
56
137
  ```bash
57
- npm install @wordpress/interactivity --save
138
+ npm install @wordpress/interactivity-router --save
58
139
  ```
59
140
 
60
- _This package assumes that your code will run in an **ES2015+** environment. If you're using an environment that has limited or no support for such language features and APIs, you should include [the polyfill shipped in `@wordpress/babel-preset-default`](https://github.com/WordPress/gutenberg/tree/HEAD/packages/babel-preset-default#polyfill) in your code._
61
-
62
- ## Docs & Examples
141
+ This step is only required if you use the Interactivity API outside WordPress.
63
142
 
64
- **[Interactivity API Documentation](https://github.com/WordPress/gutenberg/tree/trunk/packages/interactivity/docs)** is the best place to learn about this proposal. Although it's still in progress, some key pages are already available:
143
+ Within WordPress, the package is already bundled in Core. To ensure it's enqueued, add `@wordpress/interactivity-router` to the dependency array of the script module. This process is often done automatically with tools like [`wp-scripts`](https://developer.wordpress.org/block-editor/getting-started/devenv/get-started-with-wp-scripts/).
65
144
 
66
- - **[Getting Started Guide](https://github.com/WordPress/gutenberg/blob/trunk/packages/interactivity/docs/1-getting-started.md)**: Follow this Getting Started guide to learn how to scaffold a new project and create your first interactive blocks.
67
- - **[API Reference](https://github.com/WordPress/gutenberg/blob/trunk/packages/interactivity/docs/2-api-reference.md)**: Check this page for technical detailed explanations and examples of the directives and the store.
145
+ Furthermore, this package assumes your code will run in an **ES2015+** environment. If you're using an environment with limited or no support for such language features and APIs, you should include the polyfill shipped in [`@wordpress/babel-preset-default`](https://github.com/WordPress/gutenberg/tree/HEAD/packages/babel-preset-default#polyfill) in your code.
68
146
 
69
- Here you have some more resources to learn/read more about the Interactivity API:
147
+ ## License
70
148
 
71
- - **[Interactivity API Discussions](https://github.com/WordPress/gutenberg/discussions/52882)**
72
- - [Proposal: The Interactivity API – A better developer experience in building interactive blocks](https://make.wordpress.org/core/2023/03/30/proposal-the-interactivity-api-a-better-developer-experience-in-building-interactive-blocks/)
73
- - Developer Hours sessions ([Americas](https://www.youtube.com/watch?v=RXNoyP2ZiS8&t=664s) & [APAC/EMEA](https://www.youtube.com/watch?v=6ghbrhyAcvA))
74
- - [wpmovies.dev](http://wpmovies.dev/) demo and its [wp-movies-demo](https://github.com/WordPress/wp-movies-demo) repo
149
+ Interactivity API proposal, as part of Gutenberg and the WordPress project is free software, and is released under the terms of the GNU General Public License version 2 or (at your option) any later version. See [LICENSE.md](https://github.com/WordPress/gutenberg/blob/trunk/LICENSE.md) for complete license.
75
150
 
76
- <br /><br /><p align="center"><img src="https://s.w.org/style/images/codeispoetry.png?1" alt="Code is Poetry." /></p>
151
+ <br/><br/><p align="center"><img src="https://s.w.org/style/images/codeispoetry.png?1" alt="Code is Poetry." /></p>
package/build/head.js CHANGED
@@ -3,7 +3,14 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.updateHead = exports.fetchHeadAssets = void 0;
6
+ exports.updateHead = exports.headElements = exports.fetchHeadAssets = void 0;
7
+ 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); }
8
+ 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; }
9
+ /**
10
+ * The cache of prefetched stylesheets and scripts.
11
+ */
12
+ const headElements = exports.headElements = new Map();
13
+
7
14
  /**
8
15
  * Helper to update only the necessary tags in the head.
9
16
  *
@@ -33,6 +40,11 @@ const updateHead = async newHead => {
33
40
  toRemove.push(child);
34
41
  }
35
42
  }
43
+ await Promise.all([...headElements.entries()].filter(([, {
44
+ tag
45
+ }]) => tag.nodeName === 'SCRIPT').map(async ([url]) => {
46
+ await (specifier => new Promise(r => r(`${specifier}`)).then(s => _interopRequireWildcard(require(s))))(/* webpackIgnore: true */url);
47
+ }));
36
48
 
37
49
  // Prepare new assets.
38
50
  const toAppend = [...newHeadMap.values()];
@@ -46,58 +58,55 @@ const updateHead = async newHead => {
46
58
  * Fetches and processes head assets (stylesheets and scripts) from a specified document.
47
59
  *
48
60
  * @async
49
- * @param doc The document from which to fetch head assets. It should support standard DOM querying methods.
50
- * @param headElements A map of head elements to modify tracking the URLs of already processed assets to avoid duplicates.
51
- * @param headElements.tag
52
- * @param headElements.text
61
+ * @param doc The document from which to fetch head assets. It should support standard DOM querying methods.
53
62
  *
54
63
  * @return Returns an array of HTML elements representing the head assets.
55
64
  */
56
65
  exports.updateHead = updateHead;
57
- const fetchHeadAssets = async (doc, headElements) => {
66
+ const fetchHeadAssets = async doc => {
58
67
  const headTags = [];
59
- const assets = [{
60
- tagName: 'style',
61
- selector: 'link[rel=stylesheet]',
62
- attribute: 'href'
63
- }, {
64
- tagName: 'script',
65
- selector: 'script[src]',
66
- attribute: 'src'
67
- }];
68
- for (const asset of assets) {
69
- const {
70
- tagName,
71
- selector,
72
- attribute
73
- } = asset;
74
- const tags = doc.querySelectorAll(selector);
75
68
 
76
- // Use Promise.all to wait for fetch to complete
77
- await Promise.all(Array.from(tags).map(async tag => {
78
- const attributeValue = tag.getAttribute(attribute);
79
- if (!headElements.has(attributeValue)) {
80
- try {
81
- const response = await fetch(attributeValue);
82
- const text = await response.text();
83
- headElements.set(attributeValue, {
84
- tag,
85
- text
86
- });
87
- } catch (e) {
88
- // eslint-disable-next-line no-console
89
- console.error(e);
90
- }
91
- }
92
- const headElement = headElements.get(attributeValue);
93
- const element = doc.createElement(tagName);
94
- element.innerText = headElement.text;
95
- for (const attr of headElement.tag.attributes) {
96
- element.setAttribute(attr.name, attr.value);
69
+ // We only want to fetch module scripts because regular scripts (without
70
+ // `async` or `defer` attributes) can depend on the execution of other scripts.
71
+ // Scripts found in the head are blocking and must be executed in order.
72
+ const scripts = doc.querySelectorAll('script[type="module"][src]');
73
+ scripts.forEach(script => {
74
+ const src = script.getAttribute('src');
75
+ if (!headElements.has(src)) {
76
+ // add the <link> elements to prefetch the module scripts
77
+ const link = doc.createElement('link');
78
+ link.rel = 'modulepreload';
79
+ link.href = src;
80
+ document.head.append(link);
81
+ headElements.set(src, {
82
+ tag: script
83
+ });
84
+ }
85
+ });
86
+ const stylesheets = doc.querySelectorAll('link[rel=stylesheet]');
87
+ await Promise.all(Array.from(stylesheets).map(async tag => {
88
+ const href = tag.getAttribute('href');
89
+ if (!href) {
90
+ return;
91
+ }
92
+ if (!headElements.has(href)) {
93
+ try {
94
+ const response = await fetch(href);
95
+ const text = await response.text();
96
+ headElements.set(href, {
97
+ tag,
98
+ text
99
+ });
100
+ } catch (e) {
101
+ // eslint-disable-next-line no-console
102
+ console.error(e);
97
103
  }
98
- headTags.push(element);
99
- }));
100
- }
104
+ }
105
+ const headElement = headElements.get(href);
106
+ const styleElement = doc.createElement('style');
107
+ styleElement.textContent = headElement.text;
108
+ headTags.push(styleElement);
109
+ }));
101
110
  return [doc.querySelector('title'), ...doc.querySelectorAll('style'), ...headTags];
102
111
  };
103
112
  exports.fetchHeadAssets = fetchHeadAssets;
package/build/head.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["updateHead","newHead","getTagId","tag","id","outerHTML","newHeadMap","Map","child","set","toRemove","document","head","children","nodeName","push","has","delete","toAppend","values","forEach","n","remove","append","exports","fetchHeadAssets","doc","headElements","headTags","assets","tagName","selector","attribute","asset","tags","querySelectorAll","Promise","all","Array","from","map","attributeValue","getAttribute","response","fetch","text","e","console","error","headElement","get","element","createElement","innerText","attr","attributes","setAttribute","name","value","querySelector"],"sources":["@wordpress/interactivity-router/src/head.ts"],"sourcesContent":["/**\n * Helper to update only the necessary tags in the head.\n *\n * @async\n * @param newHead The head elements of the new page.\n */\nexport const updateHead = async ( newHead: HTMLHeadElement[] ) => {\n\t// Helper to get the tag id store in the cache.\n\tconst getTagId = ( tag: Element ) => tag.id || tag.outerHTML;\n\n\t// Map incoming head tags by their content.\n\tconst newHeadMap = new Map< string, Element >();\n\tfor ( const child of newHead ) {\n\t\tnewHeadMap.set( getTagId( child ), child );\n\t}\n\n\tconst toRemove: Element[] = [];\n\n\t// Detect nodes that should be added or removed.\n\tfor ( const child of document.head.children ) {\n\t\tconst id = getTagId( child );\n\t\t// Always remove styles and links as they might change.\n\t\tif ( child.nodeName === 'LINK' || child.nodeName === 'STYLE' ) {\n\t\t\ttoRemove.push( child );\n\t\t} else if ( newHeadMap.has( id ) ) {\n\t\t\tnewHeadMap.delete( id );\n\t\t} else if ( child.nodeName !== 'SCRIPT' && child.nodeName !== 'META' ) {\n\t\t\ttoRemove.push( child );\n\t\t}\n\t}\n\n\t// Prepare new assets.\n\tconst toAppend = [ ...newHeadMap.values() ];\n\n\t// Apply the changes.\n\ttoRemove.forEach( ( n ) => n.remove() );\n\tdocument.head.append( ...toAppend );\n};\n\n/**\n * Fetches and processes head assets (stylesheets and scripts) from a specified document.\n *\n * @async\n * @param doc The document from which to fetch head assets. It should support standard DOM querying methods.\n * @param headElements A map of head elements to modify tracking the URLs of already processed assets to avoid duplicates.\n * @param headElements.tag\n * @param headElements.text\n *\n * @return Returns an array of HTML elements representing the head assets.\n */\nexport const fetchHeadAssets = async (\n\tdoc: Document,\n\theadElements: Map< string, { tag: HTMLElement; text: string } >\n): Promise< HTMLElement[] > => {\n\tconst headTags = [];\n\tconst assets = [\n\t\t{\n\t\t\ttagName: 'style',\n\t\t\tselector: 'link[rel=stylesheet]',\n\t\t\tattribute: 'href',\n\t\t},\n\t\t{ tagName: 'script', selector: 'script[src]', attribute: 'src' },\n\t];\n\tfor ( const asset of assets ) {\n\t\tconst { tagName, selector, attribute } = asset;\n\t\tconst tags = doc.querySelectorAll<\n\t\t\tHTMLScriptElement | HTMLStyleElement\n\t\t>( selector );\n\n\t\t// Use Promise.all to wait for fetch to complete\n\t\tawait Promise.all(\n\t\t\tArray.from( tags ).map( async ( tag ) => {\n\t\t\t\tconst attributeValue = tag.getAttribute( attribute );\n\t\t\t\tif ( ! headElements.has( attributeValue ) ) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tconst response = await fetch( attributeValue );\n\t\t\t\t\t\tconst text = await response.text();\n\t\t\t\t\t\theadElements.set( attributeValue, {\n\t\t\t\t\t\t\ttag,\n\t\t\t\t\t\t\ttext,\n\t\t\t\t\t\t} );\n\t\t\t\t\t} catch ( e ) {\n\t\t\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\t\t\tconsole.error( e );\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst headElement = headElements.get( attributeValue );\n\t\t\t\tconst element = doc.createElement( tagName );\n\t\t\t\telement.innerText = headElement.text;\n\t\t\t\tfor ( const attr of headElement.tag.attributes ) {\n\t\t\t\t\telement.setAttribute( attr.name, attr.value );\n\t\t\t\t}\n\t\t\t\theadTags.push( element );\n\t\t\t} )\n\t\t);\n\t}\n\n\treturn [\n\t\tdoc.querySelector( 'title' ),\n\t\t...doc.querySelectorAll( 'style' ),\n\t\t...headTags,\n\t];\n};\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,UAAU,GAAG,MAAQC,OAA0B,IAAM;EACjE;EACA,MAAMC,QAAQ,GAAKC,GAAY,IAAMA,GAAG,CAACC,EAAE,IAAID,GAAG,CAACE,SAAS;;EAE5D;EACA,MAAMC,UAAU,GAAG,IAAIC,GAAG,CAAoB,CAAC;EAC/C,KAAM,MAAMC,KAAK,IAAIP,OAAO,EAAG;IAC9BK,UAAU,CAACG,GAAG,CAAEP,QAAQ,CAAEM,KAAM,CAAC,EAAEA,KAAM,CAAC;EAC3C;EAEA,MAAME,QAAmB,GAAG,EAAE;;EAE9B;EACA,KAAM,MAAMF,KAAK,IAAIG,QAAQ,CAACC,IAAI,CAACC,QAAQ,EAAG;IAC7C,MAAMT,EAAE,GAAGF,QAAQ,CAAEM,KAAM,CAAC;IAC5B;IACA,IAAKA,KAAK,CAACM,QAAQ,KAAK,MAAM,IAAIN,KAAK,CAACM,QAAQ,KAAK,OAAO,EAAG;MAC9DJ,QAAQ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AACM,GAAG,CAAE,MAAQrC,GAAG,IAAM;MACxC,MAAMsC,cAAc,GAAGtC,GAAG,CAACuC,YAAY,CAAEV,SAAU,CAAC;MACpD,IAAK,CAAEL,YAAY,CAACX,GAAG,CAAEyB,cAAe,CAAC,EAAG;QAC3C,IAAI;UACH,MAAME,QAAQ,GAAG,MAAMC,KAAK,CAAEH,cAAe,CAAC;UAC9C,MAAMI,IAAI,GAAG,MAAMF,QAAQ,CAACE,IAAI,CAAC,CAAC;UAClClB,YAAY,CAAClB,GAAG,CAAEgC,cAAc,EAAE;YACjCtC,GAAG;YACH0C;UACD,CAAE,CAAC;QACJ,CAAC,CAAC,OAAQC,CAAC,EAAG;UACb;UACAC,OAAO,CAACC,KAAK,CAAEF,CAAE,CAAC;QACnB;MACD;MAEA,MAAMG,WAAW,GAAGtB,YAAY,CAACuB,GAAG,CAAET,cAAe,CAAC;MACtD,MAAMU,OAAO,GAAGzB,GAAG,CAAC0B,aAAa,CAAEtB,OAAQ,CAAC;MAC5CqB,OAAO,CAACE,SAAS,GAAGJ,WAAW,CAACJ,IAAI;MACpC,KAAM,MAAMS,IAAI,IAAIL,WAAW,CAAC9C,GAAG,CAACoD,UAAU,EAAG;QAChDJ,OAAO,CAACK,YAAY,CAAEF,IAAI,CAACG,IAAI,EAAEH,IAAI,CAACI,KAAM,CAAC;MAC9C;MACA9B,QAAQ,CAACb,IAAI,CAAEoC,OAAQ,CAAC;IACzB,CAAE,CACH,CAAC;EACF;EAEA,OAAO,CACNzB,GAAG,CAACiC,aAAa,CAAE,OAAQ,CAAC,EAC5B,GAAGjC,GAAG,CAACS,gBAAgB,CAAE,OAAQ,CAAC,EAClC,GAAGP,QAAQ,CACX;AACF,CAAC;AAACJ,OAAA,CAAAC,eAAA,GAAAA,eAAA","ignoreList":[]}
1
+ {"version":3,"names":["headElements","exports","Map","updateHead","newHead","getTagId","tag","id","outerHTML","newHeadMap","child","set","toRemove","document","head","children","nodeName","push","has","delete","Promise","all","entries","filter","map","url","specifier","r","then","s","_interopRequireWildcard","require","toAppend","values","forEach","n","remove","append","fetchHeadAssets","doc","headTags","scripts","querySelectorAll","script","src","getAttribute","link","createElement","rel","href","stylesheets","Array","from","response","fetch","text","e","console","error","headElement","get","styleElement","textContent","querySelector"],"sources":["@wordpress/interactivity-router/src/head.ts"],"sourcesContent":["/**\n * The cache of prefetched stylesheets and scripts.\n */\nexport const headElements = new Map<\n\tstring,\n\t{ tag: HTMLElement; text?: string }\n>();\n\n/**\n * Helper to update only the necessary tags in the head.\n *\n * @async\n * @param newHead The head elements of the new page.\n */\nexport const updateHead = async ( newHead: HTMLHeadElement[] ) => {\n\t// Helper to get the tag id store in the cache.\n\tconst getTagId = ( tag: Element ) => tag.id || tag.outerHTML;\n\n\t// Map incoming head tags by their content.\n\tconst newHeadMap = new Map< string, Element >();\n\tfor ( const child of newHead ) {\n\t\tnewHeadMap.set( getTagId( child ), child );\n\t}\n\n\tconst toRemove: Element[] = [];\n\n\t// Detect nodes that should be added or removed.\n\tfor ( const child of document.head.children ) {\n\t\tconst id = getTagId( child );\n\t\t// Always remove styles and links as they might change.\n\t\tif ( child.nodeName === 'LINK' || child.nodeName === 'STYLE' ) {\n\t\t\ttoRemove.push( child );\n\t\t} else if ( newHeadMap.has( id ) ) {\n\t\t\tnewHeadMap.delete( id );\n\t\t} else if ( child.nodeName !== 'SCRIPT' && child.nodeName !== 'META' ) {\n\t\t\ttoRemove.push( child );\n\t\t}\n\t}\n\n\tawait Promise.all(\n\t\t[ ...headElements.entries() ]\n\t\t\t.filter( ( [ , { tag } ] ) => tag.nodeName === 'SCRIPT' )\n\t\t\t.map( async ( [ url ] ) => {\n\t\t\t\tawait import( /* webpackIgnore: true */ url );\n\t\t\t} )\n\t);\n\n\t// Prepare new assets.\n\tconst toAppend = [ ...newHeadMap.values() ];\n\n\t// Apply the changes.\n\ttoRemove.forEach( ( n ) => n.remove() );\n\tdocument.head.append( ...toAppend );\n};\n\n/**\n * Fetches and processes head assets (stylesheets and scripts) from a specified document.\n *\n * @async\n * @param doc The document from which to fetch head assets. It should support standard DOM querying methods.\n *\n * @return Returns an array of HTML elements representing the head assets.\n */\nexport const fetchHeadAssets = async (\n\tdoc: Document\n): Promise< HTMLElement[] > => {\n\tconst headTags = [];\n\n\t// We only want to fetch module scripts because regular scripts (without\n\t// `async` or `defer` attributes) can depend on the execution of other scripts.\n\t// Scripts found in the head are blocking and must be executed in order.\n\tconst scripts = doc.querySelectorAll< HTMLScriptElement >(\n\t\t'script[type=\"module\"][src]'\n\t);\n\n\tscripts.forEach( ( script ) => {\n\t\tconst src = script.getAttribute( 'src' );\n\t\tif ( ! headElements.has( src ) ) {\n\t\t\t// add the <link> elements to prefetch the module scripts\n\t\t\tconst link = doc.createElement( 'link' );\n\t\t\tlink.rel = 'modulepreload';\n\t\t\tlink.href = src;\n\t\t\tdocument.head.append( link );\n\t\t\theadElements.set( src, { tag: script } );\n\t\t}\n\t} );\n\n\tconst stylesheets = doc.querySelectorAll< HTMLLinkElement >(\n\t\t'link[rel=stylesheet]'\n\t);\n\n\tawait Promise.all(\n\t\tArray.from( stylesheets ).map( async ( tag ) => {\n\t\t\tconst href = tag.getAttribute( 'href' );\n\t\t\tif ( ! href ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( ! headElements.has( href ) ) {\n\t\t\t\ttry {\n\t\t\t\t\tconst response = await fetch( href );\n\t\t\t\t\tconst text = await response.text();\n\t\t\t\t\theadElements.set( href, {\n\t\t\t\t\t\ttag,\n\t\t\t\t\t\ttext,\n\t\t\t\t\t} );\n\t\t\t\t} catch ( e ) {\n\t\t\t\t\t// eslint-disable-next-line no-console\n\t\t\t\t\tconsole.error( e );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst headElement = headElements.get( href );\n\t\t\tconst styleElement = doc.createElement( 'style' );\n\t\t\tstyleElement.textContent = headElement.text;\n\n\t\t\theadTags.push( styleElement );\n\t\t} )\n\t);\n\n\treturn [\n\t\tdoc.querySelector( 'title'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@ const navigationMode = (_getConfig$navigation = (0, _interactivity.getConfig)('c
30
30
 
31
31
  // The cache of visited and prefetched pages, stylesheets and scripts.
32
32
  const pages = new Map();
33
- const headElements = new Map();
34
33
 
35
34
  // Helper to remove domain and hash from the URL. We are only interesting in
36
35
  // caching the path and the query.
@@ -69,7 +68,7 @@ const regionsToVdom = async (dom, {
69
68
  let head;
70
69
  if (globalThis.IS_GUTENBERG_PLUGIN) {
71
70
  if (navigationMode === 'fullPage') {
72
- head = await (0, _head.fetchHeadAssets)(dom, headElements);
71
+ head = await (0, _head.fetchHeadAssets)(dom);
73
72
  regions.body = vdom ? vdom.get(document.body) : toVdom(dom.body);
74
73
  }
75
74
  }
@@ -91,29 +90,32 @@ const regionsToVdom = async (dom, {
91
90
  };
92
91
 
93
92
  // Render all interactive regions contained in the given page.
94
- const renderRegions = page => {
95
- batch(() => {
96
- if (globalThis.IS_GUTENBERG_PLUGIN) {
97
- if (navigationMode === 'fullPage') {
98
- // Once this code is tested and more mature, the head should be updated for region based navigation as well.
99
- (0, _head.updateHead)(page.head);
100
- const fragment = getRegionRootFragment(document.body);
93
+ const renderRegions = async page => {
94
+ if (globalThis.IS_GUTENBERG_PLUGIN) {
95
+ if (navigationMode === 'fullPage') {
96
+ // Once this code is tested and more mature, the head should be updated for region based navigation as well.
97
+ await (0, _head.updateHead)(page.head);
98
+ const fragment = getRegionRootFragment(document.body);
99
+ batch(() => {
100
+ populateServerData(page.initialData);
101
101
  render(page.regions.body, fragment);
102
- }
102
+ });
103
103
  }
104
- if (navigationMode === 'regionBased') {
104
+ }
105
+ if (navigationMode === 'regionBased') {
106
+ const attrName = `data-${directivePrefix}-router-region`;
107
+ batch(() => {
105
108
  populateServerData(page.initialData);
106
- const attrName = `data-${directivePrefix}-router-region`;
107
109
  document.querySelectorAll(`[${attrName}]`).forEach(region => {
108
110
  const id = region.getAttribute(attrName);
109
111
  const fragment = getRegionRootFragment(region);
110
112
  render(page.regions[id], fragment);
111
113
  });
112
- }
113
- if (page.title) {
114
- document.title = page.title;
115
- }
116
- });
114
+ });
115
+ }
116
+ if (page.title) {
117
+ document.title = page.title;
118
+ }
117
119
  };
118
120
 
119
121
  /**
@@ -137,7 +139,7 @@ window.addEventListener('popstate', async () => {
137
139
  const pagePath = getPagePath(window.location.href); // Remove hash.
138
140
  const page = pages.has(pagePath) && (await pages.get(pagePath));
139
141
  if (page) {
140
- renderRegions(page);
142
+ await renderRegions(page);
141
143
  // Update the URL in the state.
142
144
  state.url = window.location.href;
143
145
  } else {
@@ -151,13 +153,12 @@ window.addEventListener('popstate', async () => {
151
153
  if (globalThis.IS_GUTENBERG_PLUGIN) {
152
154
  if (navigationMode === 'fullPage') {
153
155
  // Cache the scripts. Has to be called before fetching the assets.
154
- [].map.call(document.querySelectorAll('script[src]'), script => {
155
- headElements.set(script.getAttribute('src'), {
156
- tag: script,
157
- text: script.textContent
156
+ [].map.call(document.querySelectorAll('script[type="module"][src]'), script => {
157
+ _head.headElements.set(script.getAttribute('src'), {
158
+ tag: script
158
159
  });
159
160
  });
160
- await (0, _head.fetchHeadAssets)(document, headElements);
161
+ await (0, _head.fetchHeadAssets)(document);
161
162
  }
162
163
  }
163
164
  pages.set(getPagePath(window.location.href), Promise.resolve(regionsToVdom(document, {
@@ -1 +1 @@
1
- {"version":3,"names":["_interactivity","require","_head","_getConfig$navigation","_getRequireWildcardCache","e","WeakMap","r","t","_interopRequireWildcard","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","directivePrefix","getRegionRootFragment","initialVdom","toVdom","render","parseServerData","populateServerData","batch","privateApis","navigationMode","getConfig","pages","Map","headElements","getPagePath","url","URL","window","location","href","pathname","search","fetchPage","html","res","fetch","status","text","dom","DOMParser","parseFromString","regionsToVdom","vdom","regions","body","undefined","head","globalThis","IS_GUTENBERG_PLUGIN","fetchHeadAssets","document","attrName","querySelectorAll","forEach","region","id","getAttribute","title","querySelector","innerText","initialData","renderRegions","page","updateHead","fragment","forcePageReload","assign","Promise","addEventListener","pagePath","state","reload","map","script","tag","textContent","resolve","isValidLink","ref","HTMLAnchorElement","target","origin","startsWith","searchParams","isValidEvent","event","button","metaKey","ctrlKey","altKey","shiftKey","defaultPrevented","navigatingTo","hasLoadedNavigationTextsData","navigationTexts","loading","loaded","actions","store","navigation","hasStarted","hasFinished","navigate","options","clientNavigationDisabled","loadingAnimation","screenReaderAnnouncement","timeout","prefetch","timeoutPromise","setTimeout","loadingTimeout","a11ySpeak","race","clearTimeout","config","history","replace","hash","scrollIntoView","force","exports","messageKey","content","getElementById","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 } 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 > >();\nconst headElements = new Map< string, { tag: HTMLElement; text: string } >();\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, headElements );\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 = ( page: Page ) => {\n\tbatch( () => {\n\t\tif ( globalThis.IS_GUTENBERG_PLUGIN ) {\n\t\t\tif ( navigationMode === 'fullPage' ) {\n\t\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\t\tupdateHead( page.head );\n\t\t\t\tconst fragment = getRegionRootFragment( document.body );\n\t\t\t\trender( page.regions.body, fragment );\n\t\t\t}\n\t\t}\n\t\tif ( navigationMode === 'regionBased' ) {\n\t\t\tpopulateServerData( page.initialData );\n\t\t\tconst attrName = `data-${ directivePrefix }-router-region`;\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\tif ( page.title ) {\n\t\t\tdocument.title = page.title;\n\t\t}\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\trenderRegions( 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( document.querySelectorAll( 'script[src]' ), ( script ) => {\n\t\t\theadElements.set( script.getAttribute( 'src' ), {\n\t\t\t\ttag: script,\n\t\t\t\ttext: script.textContent,\n\t\t\t} );\n\t\t} );\n\t\tawait fetchHeadAssets( document, headElements );\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, fetchs 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 * Prefetchs 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":";;;;;;AAGA,IAAAA,cAAA,GAAAC,OAAA;AAKA,IAAAC,KAAA,GAAAD,OAAA;AAAqD,IAAAE,qBAAA;AARrD;AACA;AACA;AAGA;AACA;AACA;AAFA,SAAAC,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAI,wBAAAJ,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,eAAAA,CAA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D,IAAK,CAAC;MAC7B;IACD,CAAC,EACD,IACD,CAAC;IACD;IACAqB,QAAQ,CAACkB,gBAAgB,CACxB,YAAY,EACZ,UAAWiB,KAAK,EAAG;MAClB,IAAOA,KAAK,CAACL,MAAM,EAAeuD,QAAQ,KAAK,GAAG,EAAG;QACpD,MAAMzD,GAAG,GAAKO,KAAK,CAACL,MAAM,CAAcqD,OAAO,CAAE,GAAI,CAAC;QACtD,IAAKxD,WAAW,CAAEC,GAAI,CAAC,IAAIM,YAAY,CAAEC,KAAM,CAAC,EAAG;UAClDY,OAAO,CAACW,QAAQ,CAAE9B,GAAG,CAACjD,IAAK,CAAC;QAC7B;MACD;IACD,CAAC,EACD,IACD,CAAC;EACF;AACD","ignoreList":[]}
1
+ {"version":3,"names":["_interactivity","require","_head","_getConfig$navigation","_getRequireWildcardCache","e","WeakMap","r","t","_interopRequireWildcard","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","directivePrefix","getRegionRootFragment","initialVdom","toVdom","render","parseServerData","populateServerData","batch","privateApis","navigationMode","getConfig","pages","Map","getPagePath","url","URL","window","location","href","pathname","search","fetchPage","html","res","fetch","status","text","dom","DOMParser","parseFromString","regionsToVdom","vdom","regions","body","undefined","head","globalThis","IS_GUTENBERG_PLUGIN","fetchHeadAssets","document","attrName","querySelectorAll","forEach","region","id","getAttribute","title","querySelector","innerText","initialData","renderRegions","page","updateHead","fragment","forcePageReload","assign","Promise","addEventListener","pagePath","state","reload","map","script","headElements","tag","resolve","isValidLink","ref","HTMLAnchorElement","target","origin","startsWith","searchParams","isValidEvent","event","button","metaKey","ctrlKey","altKey","shiftKey","defaultPrevented","navigatingTo","hasLoadedNavigationTextsData","navigationTexts","loading","loaded","actions","store","navigation","hasStarted","hasFinished","navigate","options","clientNavigationDisabled","loadingAnimation","screenReaderAnnouncement","timeout","prefetch","timeoutPromise","setTimeout","loadingTimeout","a11ySpeak","race","clearTimeout","config","history","replace","hash","scrollIntoView","force","exports","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, fetchs 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 * Prefetchs 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":";;;;;;AAGA,IAAAA,cAAA,GAAAC,OAAA;AAKA,IAAAC,KAAA,GAAAD,OAAA;AAAmE,IAAAE,qBAAA;AARnE;AACA;AACA;AAGA;AACA;AACA;AAFA,SAAAC,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,GAAAD,CAAA,KAAAF,CAAA;AAAA,SAAAI,wBAAAJ,CAAA,EAAAE,CAAA,SAAAA,CAAA,IAAAF,CAAA,IAAAA,CAAA,CAAAK,UAAA,SAAAL,CAAA,eAAAA,CAAA,uBAAAA,CAAA,yBAAAA,CAAA,WAAAM,OAAA,EAAAN,CAAA,QAAAG,CAAA,GAAAJ,wBAAA,CAAAG,CAAA,OAAAC,CAAA,IAAAA,CAAA,CAAAI,GAAA,CAAAP,CAAA,UAAAG,CAAA,CAAAK,GAAA,CAAAR,CAAA,OAAAS,CAAA,KAAAC,SAAA,UAAAC,CAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,CAAA,IAAAf,CAA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