@wordpress/interactivity-router 2.43.0 → 2.44.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 +2 -0
- package/README.md +9 -11
- package/build/assets/dynamic-importmap/fetch.cjs +1 -1
- package/build/assets/dynamic-importmap/fetch.cjs.map +2 -2
- package/build/assets/dynamic-importmap/resolver.cjs +1 -1
- package/build/assets/dynamic-importmap/resolver.cjs.map +2 -2
- package/build/index.cjs +2 -2
- package/build/index.cjs.map +2 -2
- package/build-module/assets/dynamic-importmap/fetch.mjs +1 -1
- package/build-module/assets/dynamic-importmap/fetch.mjs.map +2 -2
- package/build-module/assets/dynamic-importmap/resolver.mjs +1 -1
- package/build-module/assets/dynamic-importmap/resolver.mjs.map +2 -2
- package/build-module/index.mjs +2 -2
- package/build-module/index.mjs.map +2 -2
- package/package.json +4 -4
- package/src/assets/dynamic-importmap/fetch.ts +1 -1
- package/src/assets/dynamic-importmap/resolver.ts +1 -1
- package/src/index.ts +2 -2
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -65,26 +65,24 @@ const { state, actions } = store( 'core/router', {
|
|
|
65
65
|
|
|
66
66
|
#### `data-wp-router-region`
|
|
67
67
|
|
|
68
|
-
|
|
69
68
|
It defines a region that is updated on navigation. It requires a unique ID as the value and must be used alongside `data-wp-interactive` to receive the proper namespace. Router regions can be placed anywhere within interactive regions, including nested interactive elements.
|
|
70
69
|
|
|
71
70
|
<div class="callout callout-warning">
|
|
72
71
|
When adding <code>data-wp-router-region</code> to a child element inside a parent with <code>data-wp-interactive</code>, always include <code>data-wp-interactive</code> on the child element as well. This is required for the router region to function correctly.
|
|
73
72
|
</div>
|
|
74
73
|
|
|
75
|
-
|
|
76
74
|
The value can be a string with the region ID, or a JSON object containing the `id` and an optional `attachTo` property.
|
|
77
75
|
|
|
78
76
|
Example:
|
|
79
77
|
|
|
80
78
|
```html
|
|
81
79
|
<div data-wp-interactive="myblock" data-wp-router-region="main-list">
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
80
|
+
<ul>
|
|
81
|
+
<li><a href="/post-1">Post 1</a></li>
|
|
82
|
+
<li><a href="/post-2">Post 2</a></li>
|
|
83
|
+
<li><a href="/post-3">Post 3</a></li>
|
|
84
|
+
</ul>
|
|
85
|
+
<a data-wp-on--click="actions.navigate" href="/page/2">Page 2</a>
|
|
88
86
|
</div>
|
|
89
87
|
```
|
|
90
88
|
|
|
@@ -101,10 +99,10 @@ Example with `attachTo`:
|
|
|
101
99
|
|
|
102
100
|
```html
|
|
103
101
|
<div
|
|
104
|
-
|
|
105
|
-
|
|
102
|
+
data-wp-interactive="myblock"
|
|
103
|
+
data-wp-router-region='{ "id": "myblock/overlay", "attachTo": "body" }'
|
|
106
104
|
>
|
|
107
|
-
|
|
105
|
+
I'm in a new region!
|
|
108
106
|
</div>
|
|
109
107
|
```
|
|
110
108
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/assets/dynamic-importmap/fetch.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * This code is derived from the following projects:\n *\n * 1. dynamic-importmap (https://github.com/keller-mark/dynamic-importmap)\n * 2. es-module-shims (https://github.com/guybedford/es-module-shims)\n *\n * The original implementation was created by Guy Bedford in es-module-shims,\n * then adapted by Mark Keller in dynamic-importmap, and further modified\n * for use in this project.\n *\n * Both projects are licensed under the MIT license.\n *\n * MIT License: https://opensource.org/licenses/MIT\n */\n\n/**\n * Internal dependencies\n */\nimport { type ModuleLoad } from './loader';\n\nconst fetching = ( url: string, parent?: string ) => {\n\treturn ` fetching ${ url }${ parent ? ` from ${ parent }` : '' }`;\n};\n\nconst jsContentType = /^(text|application)\\/(x-)?javascript(;|$)/;\n\n/**\n * Fetches the passed module URL and return the corresponding `ModuleLoad`\n * instance. If the passed URL does not point to a JS file, the function\n * throws and error.\n *\n * @param url Module URL.\n * @param fetchOpts Fetch init options.\n * @param parent Parent module URL referencing this URL (if any).\n * @return Promise with a `ModuleLoad` instance.\n */\nexport async function fetchModule(\n\turl: string,\n\tfetchOpts: RequestInit,\n\tparent: string\n): Promise< ModuleLoad > {\n\tlet res: Response;\n\ttry {\n\t\tres = await fetch( url, fetchOpts );\n\t} catch
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAoBA,IAAM,WAAW,CAAE,KAAa,WAAqB;AACpD,SAAO,aAAc,GAAI,GAAI,SAAS,SAAU,MAAO,KAAK,EAAG;AAChE;AAEA,IAAM,gBAAgB;AAYtB,eAAsB,YACrB,KACA,WACA,QACwB;AACxB,MAAI;AACJ,MAAI;AACH,UAAM,MAAM,MAAO,KAAK,SAAU;AAAA,EACnC,
|
|
4
|
+
"sourcesContent": ["/**\n * This code is derived from the following projects:\n *\n * 1. dynamic-importmap (https://github.com/keller-mark/dynamic-importmap)\n * 2. es-module-shims (https://github.com/guybedford/es-module-shims)\n *\n * The original implementation was created by Guy Bedford in es-module-shims,\n * then adapted by Mark Keller in dynamic-importmap, and further modified\n * for use in this project.\n *\n * Both projects are licensed under the MIT license.\n *\n * MIT License: https://opensource.org/licenses/MIT\n */\n\n/**\n * Internal dependencies\n */\nimport { type ModuleLoad } from './loader';\n\nconst fetching = ( url: string, parent?: string ) => {\n\treturn ` fetching ${ url }${ parent ? ` from ${ parent }` : '' }`;\n};\n\nconst jsContentType = /^(text|application)\\/(x-)?javascript(;|$)/;\n\n/**\n * Fetches the passed module URL and return the corresponding `ModuleLoad`\n * instance. If the passed URL does not point to a JS file, the function\n * throws and error.\n *\n * @param url Module URL.\n * @param fetchOpts Fetch init options.\n * @param parent Parent module URL referencing this URL (if any).\n * @return Promise with a `ModuleLoad` instance.\n */\nexport async function fetchModule(\n\turl: string,\n\tfetchOpts: RequestInit,\n\tparent: string\n): Promise< ModuleLoad > {\n\tlet res: Response;\n\ttry {\n\t\tres = await fetch( url, fetchOpts );\n\t} catch {\n\t\tthrow Error( `Network error${ fetching( url, parent ) }.` );\n\t}\n\tif ( ! res.ok ) {\n\t\tthrow Error( `Error ${ res.status }${ fetching( url, parent ) }.` );\n\t}\n\tconst contentType = res.headers.get( 'content-type' );\n\tif ( ! jsContentType.test( contentType ) ) {\n\t\tthrow Error(\n\t\t\t`Bad Content-Type \"${ contentType }\"${ fetching( url, parent ) }.`\n\t\t);\n\t}\n\treturn { responseUrl: res.url, source: await res.text() };\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAoBA,IAAM,WAAW,CAAE,KAAa,WAAqB;AACpD,SAAO,aAAc,GAAI,GAAI,SAAS,SAAU,MAAO,KAAK,EAAG;AAChE;AAEA,IAAM,gBAAgB;AAYtB,eAAsB,YACrB,KACA,WACA,QACwB;AACxB,MAAI;AACJ,MAAI;AACH,UAAM,MAAM,MAAO,KAAK,SAAU;AAAA,EACnC,QAAQ;AACP,UAAM,MAAO,gBAAiB,SAAU,KAAK,MAAO,CAAE,GAAI;AAAA,EAC3D;AACA,MAAK,CAAE,IAAI,IAAK;AACf,UAAM,MAAO,SAAU,IAAI,MAAO,GAAI,SAAU,KAAK,MAAO,CAAE,GAAI;AAAA,EACnE;AACA,QAAM,cAAc,IAAI,QAAQ,IAAK,cAAe;AACpD,MAAK,CAAE,cAAc,KAAM,WAAY,GAAI;AAC1C,UAAM;AAAA,MACL,qBAAsB,WAAY,IAAK,SAAU,KAAK,MAAO,CAAE;AAAA,IAChE;AAAA,EACD;AACA,SAAO,EAAE,aAAa,IAAI,KAAK,QAAQ,MAAM,IAAI,KAAK,EAAE;AACzD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/assets/dynamic-importmap/resolver.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * This code is derived from the following projects:\n *\n * 1. dynamic-importmap (https://github.com/keller-mark/dynamic-importmap)\n * 2. es-module-shims (https://github.com/guybedford/es-module-shims)\n *\n * The original implementation was created by Guy Bedford in es-module-shims,\n * then adapted by Mark Keller in dynamic-importmap, and further modified\n * for use in this project.\n *\n * Both projects are licensed under the MIT license.\n *\n * MIT License: https://opensource.org/licenses/MIT\n */\n\nconst backslashRegEx = /\\\\/g;\n\nfunction isURL( url: string ) {\n\tif ( url.indexOf( ':' ) === -1 ) {\n\t\treturn false;\n\t}\n\ttry {\n\t\tnew URL( url );\n\t\treturn true;\n\t} catch
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAeA,IAAM,iBAAiB;AAEvB,SAAS,MAAO,KAAc;AAC7B,MAAK,IAAI,QAAS,GAAI,MAAM,IAAK;AAChC,WAAO;AAAA,EACR;AACA,MAAI;AACH,QAAI,IAAK,GAAI;AACb,WAAO;AAAA,EACR,
|
|
4
|
+
"sourcesContent": ["/**\n * This code is derived from the following projects:\n *\n * 1. dynamic-importmap (https://github.com/keller-mark/dynamic-importmap)\n * 2. es-module-shims (https://github.com/guybedford/es-module-shims)\n *\n * The original implementation was created by Guy Bedford in es-module-shims,\n * then adapted by Mark Keller in dynamic-importmap, and further modified\n * for use in this project.\n *\n * Both projects are licensed under the MIT license.\n *\n * MIT License: https://opensource.org/licenses/MIT\n */\n\nconst backslashRegEx = /\\\\/g;\n\nfunction isURL( url: string ) {\n\tif ( url.indexOf( ':' ) === -1 ) {\n\t\treturn false;\n\t}\n\ttry {\n\t\tnew URL( url );\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nfunction resolveIfNotPlainOrUrl( relUrl, parentUrl ) {\n\tconst hIdx = parentUrl.indexOf( '#' ),\n\t\tqIdx = parentUrl.indexOf( '?' );\n\tif ( hIdx + qIdx > -2 ) {\n\t\tparentUrl = parentUrl.slice(\n\t\t\t0,\n\t\t\t// eslint-disable-next-line no-nested-ternary\n\t\t\thIdx === -1 ? qIdx : qIdx === -1 || qIdx > hIdx ? hIdx : qIdx\n\t\t);\n\t}\n\tif ( relUrl.indexOf( '\\\\' ) !== -1 ) {\n\t\trelUrl = relUrl.replace( backslashRegEx, '/' );\n\t}\n\t// protocol-relative\n\tif ( relUrl[ 0 ] === '/' && relUrl[ 1 ] === '/' ) {\n\t\treturn parentUrl.slice( 0, parentUrl.indexOf( ':' ) + 1 ) + relUrl;\n\t}\n\t// relative-url\n\telse if (\n\t\t( relUrl[ 0 ] === '.' &&\n\t\t\t( relUrl[ 1 ] === '/' ||\n\t\t\t\t( relUrl[ 1 ] === '.' &&\n\t\t\t\t\t( relUrl[ 2 ] === '/' ||\n\t\t\t\t\t\t( relUrl.length === 2 && ( relUrl += '/' ) ) ) ) ||\n\t\t\t\t( relUrl.length === 1 && ( relUrl += '/' ) ) ) ) ||\n\t\trelUrl[ 0 ] === '/'\n\t) {\n\t\tconst parentProtocol = parentUrl.slice(\n\t\t\t0,\n\t\t\tparentUrl.indexOf( ':' ) + 1\n\t\t);\n\t\t// Disabled, but these cases will give inconsistent results for deep backtracking\n\t\t//if (parentUrl[parentProtocol.length] !== '/')\n\t\t// throw new Error('Cannot resolve');\n\t\t// read pathname from parent URL\n\t\t// pathname taken to be part after leading \"/\"\n\t\tlet pathname;\n\t\tif ( parentUrl[ parentProtocol.length + 1 ] === '/' ) {\n\t\t\t// resolving to a :// so we need to read out the auth and host\n\t\t\tif ( parentProtocol !== 'file:' ) {\n\t\t\t\tpathname = parentUrl.slice( parentProtocol.length + 2 );\n\t\t\t\tpathname = pathname.slice( pathname.indexOf( '/' ) + 1 );\n\t\t\t} else {\n\t\t\t\tpathname = parentUrl.slice( 8 );\n\t\t\t}\n\t\t} else {\n\t\t\t// resolving to :/ so pathname is the /... part\n\t\t\tpathname = parentUrl.slice(\n\t\t\t\tparentProtocol.length +\n\t\t\t\t\t( parentUrl[ parentProtocol.length ] === '/' )\n\t\t\t);\n\t\t}\n\n\t\tif ( relUrl[ 0 ] === '/' ) {\n\t\t\treturn (\n\t\t\t\tparentUrl.slice( 0, parentUrl.length - pathname.length - 1 ) +\n\t\t\t\trelUrl\n\t\t\t);\n\t\t}\n\n\t\t// join together and split for removal of .. and . segments\n\t\t// looping the string instead of anything fancy for perf reasons\n\t\t// '../../../../../z' resolved to 'x/y' is just 'z'\n\t\tconst segmented =\n\t\t\tpathname.slice( 0, pathname.lastIndexOf( '/' ) + 1 ) + relUrl;\n\n\t\tconst output = [];\n\t\tlet segmentIndex = -1;\n\t\tfor ( let i = 0; i < segmented.length; i++ ) {\n\t\t\t// busy reading a segment - only terminate on '/'\n\t\t\tif ( segmentIndex !== -1 ) {\n\t\t\t\tif ( segmented[ i ] === '/' ) {\n\t\t\t\t\toutput.push( segmented.slice( segmentIndex, i + 1 ) );\n\t\t\t\t\tsegmentIndex = -1;\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// new segment - check if it is relative\n\t\t\telse if ( segmented[ i ] === '.' ) {\n\t\t\t\t// ../ segment\n\t\t\t\tif (\n\t\t\t\t\tsegmented[ i + 1 ] === '.' &&\n\t\t\t\t\t( segmented[ i + 2 ] === '/' || i + 2 === segmented.length )\n\t\t\t\t) {\n\t\t\t\t\toutput.pop();\n\t\t\t\t\ti += 2;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\t// ./ segment\n\t\t\t\telse if (\n\t\t\t\t\tsegmented[ i + 1 ] === '/' ||\n\t\t\t\t\ti + 1 === segmented.length\n\t\t\t\t) {\n\t\t\t\t\ti += 1;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// it is the start of a new segment\n\t\t\twhile ( segmented[ i ] === '/' ) {\n\t\t\t\ti++;\n\t\t\t}\n\t\t\tsegmentIndex = i;\n\t\t}\n\t\t// finish reading out the last segment\n\t\tif ( segmentIndex !== -1 ) {\n\t\t\toutput.push( segmented.slice( segmentIndex ) );\n\t\t}\n\t\treturn (\n\t\t\tparentUrl.slice( 0, parentUrl.length - pathname.length ) +\n\t\t\toutput.join( '' )\n\t\t);\n\t}\n}\n\nfunction resolveUrl( relUrl, parentUrl ) {\n\treturn (\n\t\tresolveIfNotPlainOrUrl( relUrl, parentUrl ) ||\n\t\t( isURL( relUrl )\n\t\t\t? relUrl\n\t\t\t: resolveIfNotPlainOrUrl( './' + relUrl, parentUrl ) )\n\t);\n}\n\nfunction getMatch( path, matchObj ) {\n\tif ( matchObj[ path ] ) {\n\t\treturn path;\n\t}\n\tlet sepIndex = path.length;\n\tdo {\n\t\tconst segment = path.slice( 0, sepIndex + 1 );\n\t\tif ( segment in matchObj ) {\n\t\t\treturn segment;\n\t\t}\n\t} while ( ( sepIndex = path.lastIndexOf( '/', sepIndex - 1 ) ) !== -1 );\n}\n\nfunction applyPackages( id, packages ) {\n\tconst pkgName = getMatch( id, packages );\n\tif ( pkgName ) {\n\t\tconst pkg = packages[ pkgName ];\n\t\tif ( pkg === null ) {\n\t\t\treturn;\n\t\t}\n\t\treturn pkg + id.slice( pkgName.length );\n\t}\n}\n\nfunction resolveImportMap( importMap, resolvedOrPlain, parentUrl ) {\n\tlet scopeUrl = parentUrl && getMatch( parentUrl, importMap.scopes );\n\twhile ( scopeUrl ) {\n\t\tconst packageResolution = applyPackages(\n\t\t\tresolvedOrPlain,\n\t\t\timportMap.scopes[ scopeUrl ]\n\t\t);\n\t\tif ( packageResolution ) {\n\t\t\treturn packageResolution;\n\t\t}\n\t\tscopeUrl = getMatch(\n\t\t\tscopeUrl.slice( 0, scopeUrl.lastIndexOf( '/' ) ),\n\t\t\timportMap.scopes\n\t\t);\n\t}\n\treturn (\n\t\tapplyPackages( resolvedOrPlain, importMap.imports ) ||\n\t\t( resolvedOrPlain.indexOf( ':' ) !== -1 && resolvedOrPlain )\n\t);\n}\n\nfunction resolveAndComposePackages(\n\tpackages,\n\toutPackages,\n\tbaseUrl,\n\tparentMap\n) {\n\tfor ( const p in packages ) {\n\t\tconst resolvedLhs = resolveIfNotPlainOrUrl( p, baseUrl ) || p;\n\t\tconst target = packages[ p ];\n\t\tif ( typeof target !== 'string' ) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst mapped = resolveImportMap(\n\t\t\tparentMap,\n\t\t\tresolveIfNotPlainOrUrl( target, baseUrl ) || target,\n\t\t\tbaseUrl\n\t\t);\n\t\tif ( mapped ) {\n\t\t\toutPackages[ resolvedLhs ] = mapped;\n\t\t\tcontinue;\n\t\t}\n\t\t// console.warn(\n\t\t// \t`Mapping \"${ p }\" -> \"${ packages[ p ] }\" does not resolve`\n\t\t// );\n\t}\n}\n\nfunction resolveAndComposeImportMap( json, baseUrl, parentMap ) {\n\tconst outMap = {\n\t\timports: Object.assign( {}, parentMap.imports ),\n\t\tscopes: Object.assign( {}, parentMap.scopes ),\n\t};\n\n\tif ( json.imports ) {\n\t\tresolveAndComposePackages(\n\t\t\tjson.imports,\n\t\t\toutMap.imports,\n\t\t\tbaseUrl,\n\t\t\tparentMap\n\t\t);\n\t}\n\n\tif ( json.scopes ) {\n\t\tfor ( const s in json.scopes ) {\n\t\t\tconst resolvedScope = resolveUrl( s, baseUrl );\n\t\t\tresolveAndComposePackages(\n\t\t\t\tjson.scopes[ s ],\n\t\t\t\toutMap.scopes[ resolvedScope ] ||\n\t\t\t\t\t( outMap.scopes[ resolvedScope ] = {} ),\n\t\t\t\tbaseUrl,\n\t\t\t\tparentMap\n\t\t\t);\n\t\t}\n\t}\n\n\treturn outMap;\n}\n\nlet importMap = { imports: {}, scopes: {} };\n\n// TODO: check if this baseURI should change per document, and so\n// it need to be passed as a parameter to methods like `resolve`.\nconst baseUrl = document.baseURI;\nconst pageBaseUrl = baseUrl;\n\n/**\n * Extends the internal dynamic import map with the passed one.\n *\n * @param importMapIn Import map.\n * @param importMapIn.imports Imports declaration.\n * @param importMapIn.scopes Scopes declaration.\n */\nexport function addImportMap( importMapIn: {\n\timports?: Record< string, string >;\n\tscopes?: Record< string, any >;\n} ) {\n\timportMap = resolveAndComposeImportMap(\n\t\timportMapIn,\n\t\tpageBaseUrl,\n\t\timportMap\n\t);\n}\n\n/**\n * Resolves the URL of the passed module ID against the current internal\n * dynamic import map.\n *\n * @param id Module ID.\n * @param parentUrl Parent URL, in case the module ID is relative.\n * @return Resolved module URL.\n */\nexport function resolve( id: string, parentUrl: string ): string {\n\tconst urlResolved = resolveIfNotPlainOrUrl( id, parentUrl );\n\treturn resolveImportMap( importMap, urlResolved || id, parentUrl ) || id;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAeA,IAAM,iBAAiB;AAEvB,SAAS,MAAO,KAAc;AAC7B,MAAK,IAAI,QAAS,GAAI,MAAM,IAAK;AAChC,WAAO;AAAA,EACR;AACA,MAAI;AACH,QAAI,IAAK,GAAI;AACb,WAAO;AAAA,EACR,QAAQ;AACP,WAAO;AAAA,EACR;AACD;AAEA,SAAS,uBAAwB,QAAQ,WAAY;AACpD,QAAM,OAAO,UAAU,QAAS,GAAI,GACnC,OAAO,UAAU,QAAS,GAAI;AAC/B,MAAK,OAAO,OAAO,IAAK;AACvB,gBAAY,UAAU;AAAA,MACrB;AAAA;AAAA,MAEA,SAAS,KAAK,OAAO,SAAS,MAAM,OAAO,OAAO,OAAO;AAAA,IAC1D;AAAA,EACD;AACA,MAAK,OAAO,QAAS,IAAK,MAAM,IAAK;AACpC,aAAS,OAAO,QAAS,gBAAgB,GAAI;AAAA,EAC9C;AAEA,MAAK,OAAQ,CAAE,MAAM,OAAO,OAAQ,CAAE,MAAM,KAAM;AACjD,WAAO,UAAU,MAAO,GAAG,UAAU,QAAS,GAAI,IAAI,CAAE,IAAI;AAAA,EAC7D,WAGG,OAAQ,CAAE,MAAM,QACf,OAAQ,CAAE,MAAM,OACf,OAAQ,CAAE,MAAM,QACf,OAAQ,CAAE,MA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AAc,uBAAwB,IAAI,SAAU;AAC1D,SAAO,iBAAkB,WAAW,eAAe,IAAI,SAAU,KAAK;AACvE;",
|
|
6
6
|
"names": ["importMap", "baseUrl"]
|
|
7
7
|
}
|
package/build/index.cjs
CHANGED
|
@@ -65,7 +65,7 @@ var parseRegionAttribute = (region) => {
|
|
|
65
65
|
try {
|
|
66
66
|
const { id, attachTo } = JSON.parse(value);
|
|
67
67
|
return { id, attachTo };
|
|
68
|
-
} catch
|
|
68
|
+
} catch {
|
|
69
69
|
return { id: value };
|
|
70
70
|
}
|
|
71
71
|
};
|
|
@@ -97,7 +97,7 @@ var fetchPage = async (url, { html }) => {
|
|
|
97
97
|
}
|
|
98
98
|
const dom = new window.DOMParser().parseFromString(html, "text/html");
|
|
99
99
|
return await preparePage(url, dom);
|
|
100
|
-
} catch
|
|
100
|
+
} catch {
|
|
101
101
|
return false;
|
|
102
102
|
}
|
|
103
103
|
};
|
package/build/index.cjs.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { store, privateApis, getConfig } from '@wordpress/interactivity';\n\n/**\n * Internal dependencies\n */\nimport { preloadStyles, applyStyles, type StyleElement } from './assets/styles';\nimport {\n\tpreloadScriptModules,\n\timportScriptModules,\n\tmarkScriptModuleAsResolved,\n\ttype ScriptModuleLoad,\n} from './assets/script-modules';\n\nconst {\n\tgetRegionRootFragment,\n\tinitialVdomPromise,\n\ttoVdom,\n\trender,\n\tparseServerData,\n\tpopulateServerData,\n\tbatch,\n\trouterRegions,\n\th: createElement,\n\tnavigationSignal,\n\tsessionId,\n\twarn,\n} = privateApis(\n\t'I acknowledge that using private APIs means my theme or plugin will inevitably break in the next version of WordPress.'\n);\n\nconst regionAttr = `data-wp-router-region`;\nconst interactiveAttr = `data-wp-interactive`;\nconst regionsSelector = `[${ interactiveAttr }][${ regionAttr }], [${ interactiveAttr }] [${ interactiveAttr }][${ regionAttr }]`;\n\nexport interface NavigateOptions {\n\tforce?: boolean;\n\thtml?: string;\n\treplace?: boolean;\n\ttimeout?: number;\n\tloadingAnimation?: boolean;\n\tscreenReaderAnnouncement?: boolean;\n}\n\nexport interface PrefetchOptions {\n\tforce?: boolean;\n\thtml?: string;\n}\n\ninterface VdomParams {\n\tvdom?: WeakMap< Element, any >;\n}\n\ninterface Page {\n\turl: string;\n\tregions: Record< string, any >;\n\tregionsToAttach: Record< string, string >;\n\tstyles: StyleElement[];\n\tscriptModules: ScriptModuleLoad[];\n\ttitle: string;\n\tinitialData: any;\n}\n\ntype PreparePage = (\n\turl: string,\n\tdom: Document,\n\tparams?: VdomParams\n) => Promise< Page >;\n\n// The cache of visited and prefetched pages, stylesheets and scripts.\nconst pages = new Map< string, Promise< Page | false > >();\n\n// Helper to remove domain and hash from the URL. We are only interesting in\n// caching the path and the query.\nconst getPagePath = ( url: string ) => {\n\tconst u = new URL( url, window.location.href );\n\treturn u.pathname + u.search;\n};\n\n/**\n * Parses the given region's directive.\n *\n * @param region Region element.\n * @return Data contained in the region directive value.\n */\nconst parseRegionAttribute = ( region: Element ) => {\n\tconst value = region.getAttribute( regionAttr );\n\ttry {\n\t\tconst { id, attachTo } = JSON.parse( value );\n\t\treturn { id, attachTo };\n\t} catch ( e ) {\n\t\treturn { id: value };\n\t}\n};\n\n/**\n * Clones the content of the router region vDOM passed as argument.\n *\n * The function creates a new VNode instance removing all priority levels up to\n * the one containing the router-region directive, which should have evaluated\n * in advance.\n *\n * @param vdom A router region's VNode.\n * @return The VNode for the passed router region's content.\n */\nconst cloneRouterRegionContent = ( vdom: any ) => {\n\tif ( ! vdom ) {\n\t\treturn vdom;\n\t}\n\tconst allPriorityLevels: string[][] = vdom.props.priorityLevels;\n\tconst routerRegionLevel = allPriorityLevels.findIndex( ( level ) =>\n\t\tlevel.includes( 'router-region' )\n\t);\n\tconst priorityLevels =\n\t\trouterRegionLevel !== -1\n\t\t\t? allPriorityLevels.slice( routerRegionLevel + 1 )\n\t\t\t: allPriorityLevels;\n\n\treturn priorityLevels.length > 0\n\t\t? createElement( vdom.type, {\n\t\t\t\t...vdom.props,\n\t\t\t\tpriorityLevels,\n\t\t } )\n\t\t: vdom.props.element;\n};\n\n/**\n * IDs of router regions with an `attachTo` property pointing to the same parent\n * element.\n */\nconst regionsToAttachByParent = new WeakMap< Element, string[] >();\n\n/**\n * Map of root fragments by parent element, used to render router regions with\n * the `attachTo` property. Those elements with the same parent are rendered\n * together in the corresponding root fragment.\n */\nconst rootFragmentsByParent = new WeakMap< Element, any >();\n\n/**\n * Set of router regions using the `attachTo` property that are present in the\n * initial page.\n *\n * These regions should be treated as regular regions without the `attachTo`\n * attribute as they don't need to be appended; they are already in the HTML.\n */\nconst initialRegionsToAttach = new Set< string >();\n\n/**\n * Fetches and prepares a page from a given URL.\n *\n * @param url The URL of the page to fetch.\n * @param options Options for the fetch operation.\n * @param options.html Optional HTML content. If provided, the function will use\n * this instead of fetching from the URL.\n * @return A Promise that resolves to the prepared page, or false if\n * there was an error during fetching or preparation.\n */\nconst fetchPage = async ( url: string, { html }: { html: string } ) => {\n\ttry {\n\t\tif ( ! html ) {\n\t\t\tconst res = await window.fetch( url );\n\t\t\tif ( res.status !== 200 ) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\thtml = await res.text();\n\t\t}\n\t\tconst dom = new window.DOMParser().parseFromString( html, 'text/html' );\n\t\treturn await preparePage( url, dom );\n\t} catch ( e ) {\n\t\treturn false;\n\t}\n};\n\n/**\n * Processes a DOM document to extract router regions and related resources.\n *\n * This function analyzes the provided DOM document and creates a virtual DOM\n * representation of all HTML regions marked with a `router-region` directive.\n * It also extracts and preloads associated styles and scripts to prepare for\n * rendering the page.\n *\n * @param url The URL associated with the page, used for asset\n * loading and caching.\n * @param dom The DOM document to process.\n * @param vdomParams Optional parameters for virtual DOM processing.\n * @param vdomParams.vdom An optional existing virtual DOM cache to check for\n * regions. If a region exists in this cache, it will be\n * reused instead of creating a new vDOM representation.\n * @return A Promise that resolves to a {@link Page} object\n * containing the virtual DOM for all router regions,\n * preloaded styles and scripts, page title, and initial\n * server-rendered data.\n */\nconst preparePage: PreparePage = async ( url, dom, { vdom } = {} ) => {\n\t// Remove all noscript elements as they're irrelevant when request is served via router.\n\t// This prevents browsers from extracting styles from noscript tags.\n\tdom.querySelectorAll( 'noscript' ).forEach( ( el ) => el.remove() );\n\n\tconst regions = {};\n\tconst regionsToAttach = {};\n\tdom.querySelectorAll( regionsSelector ).forEach( ( region ) => {\n\t\tconst { id, attachTo } = parseRegionAttribute( region );\n\n\t\tif ( region.parentElement.closest( `[${ regionAttr }]` ) ) {\n\t\t\tregions[ id ] = undefined;\n\t\t} else {\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\n\t\tif ( attachTo && ! initialRegionsToAttach.has( id ) ) {\n\t\t\tregionsToAttach[ id ] = attachTo;\n\t\t}\n\t} );\n\n\tconst title = dom.querySelector( 'title' )?.innerText;\n\tconst initialData = parseServerData( dom );\n\n\t// Wait for styles and modules to be ready.\n\tconst [ styles, scriptModules ] = await Promise.all( [\n\t\tPromise.all( preloadStyles( dom ) ),\n\t\tPromise.all( preloadScriptModules( dom ) ),\n\t] );\n\n\treturn {\n\t\tregions,\n\t\tregionsToAttach,\n\t\tstyles,\n\t\tscriptModules,\n\t\ttitle,\n\t\tinitialData,\n\t\turl,\n\t};\n};\n\n/**\n * Renders a page by applying styles, populating server data, rendering regions,\n * and updating the document title.\n *\n * @param page The {@link Page} object to render.\n */\nconst renderPage = ( page: Page ) => {\n\tapplyStyles( page.styles );\n\n\t// Clone regionsToAttach.\n\tconst regionsToAttach = { ...page.regionsToAttach };\n\n\tbatch( () => {\n\t\t// Updates the server data.\n\t\tpopulateServerData( page.initialData );\n\n\t\t// Triggers navigation invalidations (`getServerState` and\n\t\t// `getServerContext`).\n\t\tnavigationSignal.value += 1;\n\n\t\t// Resets all router regions before setting the actual values.\n\t\t( routerRegions as Map< string, any > ).forEach( ( signal ) => {\n\t\t\tsignal.value = null;\n\t\t} );\n\n\t\t// Inits regions with attachTo that don't exist yet.\n\t\tconst parentsToUpdate = new Set< Element >();\n\t\tfor ( const id in regionsToAttach ) {\n\t\t\tconst parent = document.querySelector( regionsToAttach[ id ] );\n\t\t\tif ( ! regionsToAttachByParent.has( parent ) ) {\n\t\t\t\tregionsToAttachByParent.set( parent, [] );\n\t\t\t}\n\t\t\tconst regions = regionsToAttachByParent.get( parent );\n\t\t\tif ( ! regions.includes( id ) ) {\n\t\t\t\tregions.push( id );\n\t\t\t\tparentsToUpdate.add( parent );\n\t\t\t}\n\t\t}\n\n\t\t// Updates all existing regions.\n\t\tfor ( const id in page.regions ) {\n\t\t\tif ( routerRegions.has( id ) ) {\n\t\t\t\trouterRegions.get( id ).value = cloneRouterRegionContent(\n\t\t\t\t\tpage.regions[ id ]\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\t// Renders regions attached to the same parent in the same fragment.\n\t\tparentsToUpdate.forEach( ( parent ) => {\n\t\t\tconst ids = regionsToAttachByParent.get( parent );\n\t\t\tconst vdoms = ids.map( ( id ) => page.regions[ id ] );\n\n\t\t\tif ( ! rootFragmentsByParent.has( parent ) ) {\n\t\t\t\tconst regions = vdoms.map( ( { props, type } ) => {\n\t\t\t\t\tconst elementType =\n\t\t\t\t\t\ttypeof type === 'function' ? props.type : type;\n\n\t\t\t\t\t// Creates an element with the obtained type where the\n\t\t\t\t\t// region will be rendered. The type should match the one of\n\t\t\t\t\t// the root vnode.\n\t\t\t\t\tconst region = document.createElement( elementType );\n\t\t\t\t\tparent.appendChild( region );\n\t\t\t\t\treturn region;\n\t\t\t\t} );\n\t\t\t\trootFragmentsByParent.set(\n\t\t\t\t\tparent,\n\t\t\t\t\tgetRegionRootFragment( regions )\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst fragment = rootFragmentsByParent.get( parent );\n\t\t\trender( vdoms, fragment );\n\t\t} );\n\t} );\n\n\tif ( page.title ) {\n\t\tdocument.title = page.title;\n\t}\n};\n\n/**\n * Loads the given page forcing a full page reload.\n *\n * The function returns a promise that won't resolve, useful to prevent any\n * potential feedback indicating that the navigation has finished while the new\n * page is being loaded.\n *\n * @param href The page href.\n * @return Promise that never resolves.\n */\nconst forcePageReload = ( href: string ) => {\n\twindow.location.assign( href );\n\treturn new Promise( () => {} );\n};\n\n// Listen to the back and forward buttons and restore the page if it's in the\n// cache.\nwindow.addEventListener( 'popstate', async () => {\n\tconst pagePath = getPagePath( window.location.href ); // Remove hash.\n\tconst page = pages.has( pagePath ) && ( await pages.get( pagePath ) );\n\tif ( page ) {\n\t\tbatch( () => {\n\t\t\tstate.url = window.location.href;\n\t\t\trenderPage( page );\n\t\t} );\n\t} else {\n\t\twindow.location.reload();\n\t}\n} );\n\n// Detect router regions with `attachTo` in the initial page. This step should\n// be done before the initial page is processed with `preparePage()` so this\n// function treats them as regular router regions.\ndocument.querySelectorAll( regionsSelector ).forEach( ( region ) => {\n\tconst { id, attachTo } = parseRegionAttribute( region );\n\tif ( attachTo ) {\n\t\tinitialRegionsToAttach.add( id );\n\t}\n} );\n\n// Initialize the router and cache the initial page using the initial vDOM.\nwindow.document\n\t.querySelectorAll< HTMLScriptElement >( 'script[type=module][src]' )\n\t.forEach( ( { src } ) => markScriptModuleAsResolved( src ) );\n\n// Await hydration completion before setting the initial page to ensure initialVdom is populated.\n( async () => {\n\tconst initialVdomMap = await initialVdomPromise;\n\tpages.set(\n\t\tgetPagePath( window.location.href ),\n\t\tPromise.resolve(\n\t\t\tpreparePage( getPagePath( window.location.href ), document, {\n\t\t\t\tvdom: initialVdomMap,\n\t\t\t} )\n\t\t)\n\t);\n} )();\n\n// Variable to store the current navigation.\nlet navigatingTo = '';\n\nlet hasLoadedNavigationTextsData = false;\nconst navigationTexts = {\n\tloading: 'Loading page, please wait.',\n\tloaded: 'Page Loaded.',\n};\n\ninterface Store {\n\tstate: {\n\t\turl: string;\n\t\tnavigation: {\n\t\t\thasStarted: boolean;\n\t\t\thasFinished: boolean;\n\t\t};\n\t};\n\tactions: {\n\t\tnavigate: (\n\t\t\thref: string,\n\t\t\toptions?: NavigateOptions\n\t\t) => Promise< void >;\n\t\tprefetch: ( url: string, options?: PrefetchOptions ) => Promise< void >;\n\t};\n}\n\nconst { state: privateState } = store(\n\t'core/router/private',\n\t{\n\t\tstate: {\n\t\t\tnavigation: {\n\t\t\t\thasStarted: false,\n\t\t\t\thasFinished: false,\n\t\t\t},\n\t\t},\n\t},\n\t{ lock: true }\n);\n\nexport const { state, actions } = store< Store >( 'core/router', {\n\tstate: {\n\t\tget navigation() {\n\t\t\tif ( globalThis.SCRIPT_DEBUG ) {\n\t\t\t\twarn(\n\t\t\t\t\t`The usage of state.navigation.{hasStarted|hasFinished} from core/router is deprecated and will stop working in WordPress 7.1.`\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn privateState.navigation;\n\t\t},\n\t},\n\tactions: {\n\t\t/**\n\t\t * Navigates to the specified page.\n\t\t *\n\t\t * This function normalizes the passed href, fetches the page HTML if\n\t\t * needed, and updates any interactive regions whose contents have\n\t\t * changed. It also creates a new entry in the browser session history.\n\t\t *\n\t\t * @param href The page href.\n\t\t * @param [options] Options object.\n\t\t * @param [options.force] If true, it forces re-fetching the URL.\n\t\t * @param [options.html] HTML string to be used instead of fetching the requested URL.\n\t\t * @param [options.replace] If true, it replaces the current entry in the browser session history.\n\t\t * @param [options.timeout] Time until the navigation is aborted, in milliseconds. Default is 10000.\n\t\t * @param [options.loadingAnimation] Whether an animation should be shown while navigating. Default to `true`.\n\t\t * @param [options.screenReaderAnnouncement] Whether a message for screen readers should be announced while navigating. Default to `true`.\n\t\t *\n\t\t * @return Promise that resolves once the navigation is completed or aborted.\n\t\t */\n\t\t*navigate( href: string, options: NavigateOptions = {} ) {\n\t\t\tconst { clientNavigationDisabled } = getConfig();\n\t\t\tif ( clientNavigationDisabled ) {\n\t\t\t\tyield forcePageReload( href );\n\t\t\t}\n\n\t\t\tconst pagePath = getPagePath( href );\n\t\t\tconst { navigation } = privateState;\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// Creates 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// Doesn'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// Dismisses loading message if it hasn't been added yet.\n\t\t\tclearTimeout( loadingTimeout );\n\n\t\t\t// Once the page is fetched, the destination URL could have changed\n\t\t\t// (e.g., by clicking another link in the meantime). If so, bail\n\t\t\t// out, and let the newer execution to update the HTML.\n\t\t\tif ( navigatingTo !== href ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\tpage &&\n\t\t\t\t! page.initialData?.config?.[ 'core/router' ]\n\t\t\t\t\t?.clientNavigationDisabled\n\t\t\t) {\n\t\t\t\tyield importScriptModules( page.scriptModules );\n\n\t\t\t\tbatch( () => {\n\t\t\t\t\t// Updates the URL in the state.\n\t\t\t\t\tstate.url = href;\n\n\t\t\t\t\t// Updates the navigation status once the the new page rendering\n\t\t\t\t\t// has been completed.\n\t\t\t\t\tif ( loadingAnimation ) {\n\t\t\t\t\t\tnavigation.hasStarted = false;\n\t\t\t\t\t\tnavigation.hasFinished = true;\n\t\t\t\t\t}\n\n\t\t\t\t\t// Renders the new page.\n\t\t\t\t\trenderPage( page );\n\t\t\t\t} );\n\n\t\t\t\twindow.history[\n\t\t\t\t\toptions.replace ? 'replaceState' : 'pushState'\n\t\t\t\t]( { wpInteractivityId: sessionId }, '', href );\n\n\t\t\t\tif ( screenReaderAnnouncement ) {\n\t\t\t\t\ta11ySpeak( 'loaded' );\n\t\t\t\t}\n\n\t\t\t\t// Scroll to the anchor if exits in the link.\n\t\t\t\tconst { hash } = new URL( href, window.location.href );\n\t\t\t\tif ( hash ) {\n\t\t\t\t\tdocument.querySelector( hash )?.scrollIntoView();\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tyield forcePageReload( href );\n\t\t\t}\n\t\t},\n\n\t\t/**\n\t\t * Prefetches the page with the passed URL.\n\t\t *\n\t\t * The function normalizes the URL and stores internally the fetch\n\t\t * promise, to avoid triggering a second fetch for an ongoing request.\n\t\t *\n\t\t * @param url The page URL.\n\t\t * @param [options] Options object.\n\t\t * @param [options.force] Force fetching the URL again.\n\t\t * @param [options.html] HTML string to be used instead of fetching the requested URL.\n\t\t *\n\t\t * @return Promise that resolves once the page has been fetched.\n\t\t */\n\t\t*prefetch( url: string, options: PrefetchOptions = {} ) {\n\t\t\tconst { clientNavigationDisabled } = getConfig();\n\t\t\tif ( clientNavigationDisabled ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst pagePath = getPagePath( url );\n\t\t\tif ( options.force || ! pages.has( pagePath ) ) {\n\t\t\t\tpages.set(\n\t\t\t\t\tpagePath,\n\t\t\t\t\tfetchPage( pagePath, { html: options.html } )\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tyield pages.get( pagePath );\n\t\t},\n\t},\n} );\n\n// Initialize the URL in the state if it hasn't been set yet in the server.\nstate.url = state.url || window.location.href;\n\n/**\n * Announces a message to screen readers.\n *\n * This is a wrapper around the `@wordpress/a11y` package's `speak` function. It handles importing\n * the package on demand and should be used instead of calling `a11y.speak` directly.\n *\n * @param messageKey The message to be announced by assistive technologies.\n */\nfunction a11ySpeak( messageKey: keyof typeof navigationTexts ) {\n\tif ( ! hasLoadedNavigationTextsData ) {\n\t\thasLoadedNavigationTextsData = true;\n\t\tconst content = document.getElementById(\n\t\t\t'wp-script-module-data-@wordpress/interactivity-router'\n\t\t)?.textContent;\n\t\tif ( content ) {\n\t\t\ttry {\n\t\t\t\tconst parsed = JSON.parse( content );\n\t\t\t\tif ( typeof parsed?.i18n?.loading === 'string' ) {\n\t\t\t\t\tnavigationTexts.loading = parsed.i18n.loading;\n\t\t\t\t}\n\t\t\t\tif ( typeof parsed?.i18n?.loaded === 'string' ) {\n\t\t\t\t\tnavigationTexts.loaded = parsed.i18n.loaded;\n\t\t\t\t}\n\t\t\t} catch {}\n\t\t} else {\n\t\t\t// Fallback to localized strings from Interactivity API state.\n\t\t\t// @todo This block is for Core < 6.7.0. Remove when support is dropped.\n\n\t\t\t// @ts-expect-error\n\t\t\tif ( state.navigation.texts?.loading ) {\n\t\t\t\t// @ts-expect-error\n\t\t\t\tnavigationTexts.loading = state.navigation.texts.loading;\n\t\t\t}\n\t\t\t// @ts-expect-error\n\t\t\tif ( state.navigation.texts?.loaded ) {\n\t\t\t\t// @ts-expect-error\n\t\t\t\tnavigationTexts.loaded = state.navigation.texts.loaded;\n\t\t\t}\n\t\t}\n\t}\n\n\tconst message = navigationTexts[ messageKey ];\n\n\timport( '@wordpress/a11y' ).then(\n\t\t( { speak } ) => speak( message ),\n\t\t// Ignore failures to load the a11y module.\n\t\t() => {}\n\t);\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,2BAA8C;AAK9C,oBAA8D;AAC9D,4BAKO;AAEP,IAAM;AAAA,EACL;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AAAA,EACH;AAAA,EACA;AAAA,EACA;AACD,QAAI;AAAA,EACH;AACD;AAEA,IAAM,aAAa;AACnB,IAAM,kBAAkB;AACxB,IAAM,kBAAkB,IAAK,eAAgB,KAAM,UAAW,OAAQ,eAAgB,MAAO,eAAgB,KAAM,UAAW;AAqC9H,IAAM,QAAQ,oBAAI,IAAuC;AAIzD,IAAM,cAAc,CAAE,QAAiB;AACtC,QAAM,IAAI,IAAI,IAAK,KAAK,OAAO,SAAS,IAAK;AAC7C,SAAO,EAAE,WAAW,EAAE;AACvB;AAQA,IAAM,uBAAuB,CAAE,WAAqB;AACnD,QAAM,QAAQ,OAAO,aAAc,UAAW;AAC9C,MAAI;AACH,UAAM,EAAE,IAAI,SAAS,IAAI,KAAK,MAAO,KAAM;AAC3C,WAAO,EAAE,IAAI,SAAS;AAAA,EACvB,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { store, privateApis, getConfig } from '@wordpress/interactivity';\n\n/**\n * Internal dependencies\n */\nimport { preloadStyles, applyStyles, type StyleElement } from './assets/styles';\nimport {\n\tpreloadScriptModules,\n\timportScriptModules,\n\tmarkScriptModuleAsResolved,\n\ttype ScriptModuleLoad,\n} from './assets/script-modules';\n\nconst {\n\tgetRegionRootFragment,\n\tinitialVdomPromise,\n\ttoVdom,\n\trender,\n\tparseServerData,\n\tpopulateServerData,\n\tbatch,\n\trouterRegions,\n\th: createElement,\n\tnavigationSignal,\n\tsessionId,\n\twarn,\n} = privateApis(\n\t'I acknowledge that using private APIs means my theme or plugin will inevitably break in the next version of WordPress.'\n);\n\nconst regionAttr = `data-wp-router-region`;\nconst interactiveAttr = `data-wp-interactive`;\nconst regionsSelector = `[${ interactiveAttr }][${ regionAttr }], [${ interactiveAttr }] [${ interactiveAttr }][${ regionAttr }]`;\n\nexport interface NavigateOptions {\n\tforce?: boolean;\n\thtml?: string;\n\treplace?: boolean;\n\ttimeout?: number;\n\tloadingAnimation?: boolean;\n\tscreenReaderAnnouncement?: boolean;\n}\n\nexport interface PrefetchOptions {\n\tforce?: boolean;\n\thtml?: string;\n}\n\ninterface VdomParams {\n\tvdom?: WeakMap< Element, any >;\n}\n\ninterface Page {\n\turl: string;\n\tregions: Record< string, any >;\n\tregionsToAttach: Record< string, string >;\n\tstyles: StyleElement[];\n\tscriptModules: ScriptModuleLoad[];\n\ttitle: string;\n\tinitialData: any;\n}\n\ntype PreparePage = (\n\turl: string,\n\tdom: Document,\n\tparams?: VdomParams\n) => Promise< Page >;\n\n// The cache of visited and prefetched pages, stylesheets and scripts.\nconst pages = new Map< string, Promise< Page | false > >();\n\n// Helper to remove domain and hash from the URL. We are only interesting in\n// caching the path and the query.\nconst getPagePath = ( url: string ) => {\n\tconst u = new URL( url, window.location.href );\n\treturn u.pathname + u.search;\n};\n\n/**\n * Parses the given region's directive.\n *\n * @param region Region element.\n * @return Data contained in the region directive value.\n */\nconst parseRegionAttribute = ( region: Element ) => {\n\tconst value = region.getAttribute( regionAttr );\n\ttry {\n\t\tconst { id, attachTo } = JSON.parse( value );\n\t\treturn { id, attachTo };\n\t} catch {\n\t\treturn { id: value };\n\t}\n};\n\n/**\n * Clones the content of the router region vDOM passed as argument.\n *\n * The function creates a new VNode instance removing all priority levels up to\n * the one containing the router-region directive, which should have evaluated\n * in advance.\n *\n * @param vdom A router region's VNode.\n * @return The VNode for the passed router region's content.\n */\nconst cloneRouterRegionContent = ( vdom: any ) => {\n\tif ( ! vdom ) {\n\t\treturn vdom;\n\t}\n\tconst allPriorityLevels: string[][] = vdom.props.priorityLevels;\n\tconst routerRegionLevel = allPriorityLevels.findIndex( ( level ) =>\n\t\tlevel.includes( 'router-region' )\n\t);\n\tconst priorityLevels =\n\t\trouterRegionLevel !== -1\n\t\t\t? allPriorityLevels.slice( routerRegionLevel + 1 )\n\t\t\t: allPriorityLevels;\n\n\treturn priorityLevels.length > 0\n\t\t? createElement( vdom.type, {\n\t\t\t\t...vdom.props,\n\t\t\t\tpriorityLevels,\n\t\t } )\n\t\t: vdom.props.element;\n};\n\n/**\n * IDs of router regions with an `attachTo` property pointing to the same parent\n * element.\n */\nconst regionsToAttachByParent = new WeakMap< Element, string[] >();\n\n/**\n * Map of root fragments by parent element, used to render router regions with\n * the `attachTo` property. Those elements with the same parent are rendered\n * together in the corresponding root fragment.\n */\nconst rootFragmentsByParent = new WeakMap< Element, any >();\n\n/**\n * Set of router regions using the `attachTo` property that are present in the\n * initial page.\n *\n * These regions should be treated as regular regions without the `attachTo`\n * attribute as they don't need to be appended; they are already in the HTML.\n */\nconst initialRegionsToAttach = new Set< string >();\n\n/**\n * Fetches and prepares a page from a given URL.\n *\n * @param url The URL of the page to fetch.\n * @param options Options for the fetch operation.\n * @param options.html Optional HTML content. If provided, the function will use\n * this instead of fetching from the URL.\n * @return A Promise that resolves to the prepared page, or false if\n * there was an error during fetching or preparation.\n */\nconst fetchPage = async ( url: string, { html }: { html: string } ) => {\n\ttry {\n\t\tif ( ! html ) {\n\t\t\tconst res = await window.fetch( url );\n\t\t\tif ( res.status !== 200 ) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\thtml = await res.text();\n\t\t}\n\t\tconst dom = new window.DOMParser().parseFromString( html, 'text/html' );\n\t\treturn await preparePage( url, dom );\n\t} catch {\n\t\treturn false;\n\t}\n};\n\n/**\n * Processes a DOM document to extract router regions and related resources.\n *\n * This function analyzes the provided DOM document and creates a virtual DOM\n * representation of all HTML regions marked with a `router-region` directive.\n * It also extracts and preloads associated styles and scripts to prepare for\n * rendering the page.\n *\n * @param url The URL associated with the page, used for asset\n * loading and caching.\n * @param dom The DOM document to process.\n * @param vdomParams Optional parameters for virtual DOM processing.\n * @param vdomParams.vdom An optional existing virtual DOM cache to check for\n * regions. If a region exists in this cache, it will be\n * reused instead of creating a new vDOM representation.\n * @return A Promise that resolves to a {@link Page} object\n * containing the virtual DOM for all router regions,\n * preloaded styles and scripts, page title, and initial\n * server-rendered data.\n */\nconst preparePage: PreparePage = async ( url, dom, { vdom } = {} ) => {\n\t// Remove all noscript elements as they're irrelevant when request is served via router.\n\t// This prevents browsers from extracting styles from noscript tags.\n\tdom.querySelectorAll( 'noscript' ).forEach( ( el ) => el.remove() );\n\n\tconst regions = {};\n\tconst regionsToAttach = {};\n\tdom.querySelectorAll( regionsSelector ).forEach( ( region ) => {\n\t\tconst { id, attachTo } = parseRegionAttribute( region );\n\n\t\tif ( region.parentElement.closest( `[${ regionAttr }]` ) ) {\n\t\t\tregions[ id ] = undefined;\n\t\t} else {\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\n\t\tif ( attachTo && ! initialRegionsToAttach.has( id ) ) {\n\t\t\tregionsToAttach[ id ] = attachTo;\n\t\t}\n\t} );\n\n\tconst title = dom.querySelector( 'title' )?.innerText;\n\tconst initialData = parseServerData( dom );\n\n\t// Wait for styles and modules to be ready.\n\tconst [ styles, scriptModules ] = await Promise.all( [\n\t\tPromise.all( preloadStyles( dom ) ),\n\t\tPromise.all( preloadScriptModules( dom ) ),\n\t] );\n\n\treturn {\n\t\tregions,\n\t\tregionsToAttach,\n\t\tstyles,\n\t\tscriptModules,\n\t\ttitle,\n\t\tinitialData,\n\t\turl,\n\t};\n};\n\n/**\n * Renders a page by applying styles, populating server data, rendering regions,\n * and updating the document title.\n *\n * @param page The {@link Page} object to render.\n */\nconst renderPage = ( page: Page ) => {\n\tapplyStyles( page.styles );\n\n\t// Clone regionsToAttach.\n\tconst regionsToAttach = { ...page.regionsToAttach };\n\n\tbatch( () => {\n\t\t// Updates the server data.\n\t\tpopulateServerData( page.initialData );\n\n\t\t// Triggers navigation invalidations (`getServerState` and\n\t\t// `getServerContext`).\n\t\tnavigationSignal.value += 1;\n\n\t\t// Resets all router regions before setting the actual values.\n\t\t( routerRegions as Map< string, any > ).forEach( ( signal ) => {\n\t\t\tsignal.value = null;\n\t\t} );\n\n\t\t// Inits regions with attachTo that don't exist yet.\n\t\tconst parentsToUpdate = new Set< Element >();\n\t\tfor ( const id in regionsToAttach ) {\n\t\t\tconst parent = document.querySelector( regionsToAttach[ id ] );\n\t\t\tif ( ! regionsToAttachByParent.has( parent ) ) {\n\t\t\t\tregionsToAttachByParent.set( parent, [] );\n\t\t\t}\n\t\t\tconst regions = regionsToAttachByParent.get( parent );\n\t\t\tif ( ! regions.includes( id ) ) {\n\t\t\t\tregions.push( id );\n\t\t\t\tparentsToUpdate.add( parent );\n\t\t\t}\n\t\t}\n\n\t\t// Updates all existing regions.\n\t\tfor ( const id in page.regions ) {\n\t\t\tif ( routerRegions.has( id ) ) {\n\t\t\t\trouterRegions.get( id ).value = cloneRouterRegionContent(\n\t\t\t\t\tpage.regions[ id ]\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\t// Renders regions attached to the same parent in the same fragment.\n\t\tparentsToUpdate.forEach( ( parent ) => {\n\t\t\tconst ids = regionsToAttachByParent.get( parent );\n\t\t\tconst vdoms = ids.map( ( id ) => page.regions[ id ] );\n\n\t\t\tif ( ! rootFragmentsByParent.has( parent ) ) {\n\t\t\t\tconst regions = vdoms.map( ( { props, type } ) => {\n\t\t\t\t\tconst elementType =\n\t\t\t\t\t\ttypeof type === 'function' ? props.type : type;\n\n\t\t\t\t\t// Creates an element with the obtained type where the\n\t\t\t\t\t// region will be rendered. The type should match the one of\n\t\t\t\t\t// the root vnode.\n\t\t\t\t\tconst region = document.createElement( elementType );\n\t\t\t\t\tparent.appendChild( region );\n\t\t\t\t\treturn region;\n\t\t\t\t} );\n\t\t\t\trootFragmentsByParent.set(\n\t\t\t\t\tparent,\n\t\t\t\t\tgetRegionRootFragment( regions )\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst fragment = rootFragmentsByParent.get( parent );\n\t\t\trender( vdoms, fragment );\n\t\t} );\n\t} );\n\n\tif ( page.title ) {\n\t\tdocument.title = page.title;\n\t}\n};\n\n/**\n * Loads the given page forcing a full page reload.\n *\n * The function returns a promise that won't resolve, useful to prevent any\n * potential feedback indicating that the navigation has finished while the new\n * page is being loaded.\n *\n * @param href The page href.\n * @return Promise that never resolves.\n */\nconst forcePageReload = ( href: string ) => {\n\twindow.location.assign( href );\n\treturn new Promise( () => {} );\n};\n\n// Listen to the back and forward buttons and restore the page if it's in the\n// cache.\nwindow.addEventListener( 'popstate', async () => {\n\tconst pagePath = getPagePath( window.location.href ); // Remove hash.\n\tconst page = pages.has( pagePath ) && ( await pages.get( pagePath ) );\n\tif ( page ) {\n\t\tbatch( () => {\n\t\t\tstate.url = window.location.href;\n\t\t\trenderPage( page );\n\t\t} );\n\t} else {\n\t\twindow.location.reload();\n\t}\n} );\n\n// Detect router regions with `attachTo` in the initial page. This step should\n// be done before the initial page is processed with `preparePage()` so this\n// function treats them as regular router regions.\ndocument.querySelectorAll( regionsSelector ).forEach( ( region ) => {\n\tconst { id, attachTo } = parseRegionAttribute( region );\n\tif ( attachTo ) {\n\t\tinitialRegionsToAttach.add( id );\n\t}\n} );\n\n// Initialize the router and cache the initial page using the initial vDOM.\nwindow.document\n\t.querySelectorAll< HTMLScriptElement >( 'script[type=module][src]' )\n\t.forEach( ( { src } ) => markScriptModuleAsResolved( src ) );\n\n// Await hydration completion before setting the initial page to ensure initialVdom is populated.\n( async () => {\n\tconst initialVdomMap = await initialVdomPromise;\n\tpages.set(\n\t\tgetPagePath( window.location.href ),\n\t\tPromise.resolve(\n\t\t\tpreparePage( getPagePath( window.location.href ), document, {\n\t\t\t\tvdom: initialVdomMap,\n\t\t\t} )\n\t\t)\n\t);\n} )();\n\n// Variable to store the current navigation.\nlet navigatingTo = '';\n\nlet hasLoadedNavigationTextsData = false;\nconst navigationTexts = {\n\tloading: 'Loading page, please wait.',\n\tloaded: 'Page Loaded.',\n};\n\ninterface Store {\n\tstate: {\n\t\turl: string;\n\t\tnavigation: {\n\t\t\thasStarted: boolean;\n\t\t\thasFinished: boolean;\n\t\t};\n\t};\n\tactions: {\n\t\tnavigate: (\n\t\t\thref: string,\n\t\t\toptions?: NavigateOptions\n\t\t) => Promise< void >;\n\t\tprefetch: ( url: string, options?: PrefetchOptions ) => Promise< void >;\n\t};\n}\n\nconst { state: privateState } = store(\n\t'core/router/private',\n\t{\n\t\tstate: {\n\t\t\tnavigation: {\n\t\t\t\thasStarted: false,\n\t\t\t\thasFinished: false,\n\t\t\t},\n\t\t},\n\t},\n\t{ lock: true }\n);\n\nexport const { state, actions } = store< Store >( 'core/router', {\n\tstate: {\n\t\tget navigation() {\n\t\t\tif ( globalThis.SCRIPT_DEBUG ) {\n\t\t\t\twarn(\n\t\t\t\t\t`The usage of state.navigation.{hasStarted|hasFinished} from core/router is deprecated and will stop working in WordPress 7.1.`\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn privateState.navigation;\n\t\t},\n\t},\n\tactions: {\n\t\t/**\n\t\t * Navigates to the specified page.\n\t\t *\n\t\t * This function normalizes the passed href, fetches the page HTML if\n\t\t * needed, and updates any interactive regions whose contents have\n\t\t * changed. It also creates a new entry in the browser session history.\n\t\t *\n\t\t * @param href The page href.\n\t\t * @param [options] Options object.\n\t\t * @param [options.force] If true, it forces re-fetching the URL.\n\t\t * @param [options.html] HTML string to be used instead of fetching the requested URL.\n\t\t * @param [options.replace] If true, it replaces the current entry in the browser session history.\n\t\t * @param [options.timeout] Time until the navigation is aborted, in milliseconds. Default is 10000.\n\t\t * @param [options.loadingAnimation] Whether an animation should be shown while navigating. Default to `true`.\n\t\t * @param [options.screenReaderAnnouncement] Whether a message for screen readers should be announced while navigating. Default to `true`.\n\t\t *\n\t\t * @return Promise that resolves once the navigation is completed or aborted.\n\t\t */\n\t\t*navigate( href: string, options: NavigateOptions = {} ) {\n\t\t\tconst { clientNavigationDisabled } = getConfig();\n\t\t\tif ( clientNavigationDisabled ) {\n\t\t\t\tyield forcePageReload( href );\n\t\t\t}\n\n\t\t\tconst pagePath = getPagePath( href );\n\t\t\tconst { navigation } = privateState;\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// Creates 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// Doesn'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// Dismisses loading message if it hasn't been added yet.\n\t\t\tclearTimeout( loadingTimeout );\n\n\t\t\t// Once the page is fetched, the destination URL could have changed\n\t\t\t// (e.g., by clicking another link in the meantime). If so, bail\n\t\t\t// out, and let the newer execution to update the HTML.\n\t\t\tif ( navigatingTo !== href ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\tpage &&\n\t\t\t\t! page.initialData?.config?.[ 'core/router' ]\n\t\t\t\t\t?.clientNavigationDisabled\n\t\t\t) {\n\t\t\t\tyield importScriptModules( page.scriptModules );\n\n\t\t\t\tbatch( () => {\n\t\t\t\t\t// Updates the URL in the state.\n\t\t\t\t\tstate.url = href;\n\n\t\t\t\t\t// Updates the navigation status once the the new page rendering\n\t\t\t\t\t// has been completed.\n\t\t\t\t\tif ( loadingAnimation ) {\n\t\t\t\t\t\tnavigation.hasStarted = false;\n\t\t\t\t\t\tnavigation.hasFinished = true;\n\t\t\t\t\t}\n\n\t\t\t\t\t// Renders the new page.\n\t\t\t\t\trenderPage( page );\n\t\t\t\t} );\n\n\t\t\t\twindow.history[\n\t\t\t\t\toptions.replace ? 'replaceState' : 'pushState'\n\t\t\t\t]( { wpInteractivityId: sessionId }, '', href );\n\n\t\t\t\tif ( screenReaderAnnouncement ) {\n\t\t\t\t\ta11ySpeak( 'loaded' );\n\t\t\t\t}\n\n\t\t\t\t// Scroll to the anchor if exits in the link.\n\t\t\t\tconst { hash } = new URL( href, window.location.href );\n\t\t\t\tif ( hash ) {\n\t\t\t\t\tdocument.querySelector( hash )?.scrollIntoView();\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tyield forcePageReload( href );\n\t\t\t}\n\t\t},\n\n\t\t/**\n\t\t * Prefetches the page with the passed URL.\n\t\t *\n\t\t * The function normalizes the URL and stores internally the fetch\n\t\t * promise, to avoid triggering a second fetch for an ongoing request.\n\t\t *\n\t\t * @param url The page URL.\n\t\t * @param [options] Options object.\n\t\t * @param [options.force] Force fetching the URL again.\n\t\t * @param [options.html] HTML string to be used instead of fetching the requested URL.\n\t\t *\n\t\t * @return Promise that resolves once the page has been fetched.\n\t\t */\n\t\t*prefetch( url: string, options: PrefetchOptions = {} ) {\n\t\t\tconst { clientNavigationDisabled } = getConfig();\n\t\t\tif ( clientNavigationDisabled ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst pagePath = getPagePath( url );\n\t\t\tif ( options.force || ! pages.has( pagePath ) ) {\n\t\t\t\tpages.set(\n\t\t\t\t\tpagePath,\n\t\t\t\t\tfetchPage( pagePath, { html: options.html } )\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tyield pages.get( pagePath );\n\t\t},\n\t},\n} );\n\n// Initialize the URL in the state if it hasn't been set yet in the server.\nstate.url = state.url || window.location.href;\n\n/**\n * Announces a message to screen readers.\n *\n * This is a wrapper around the `@wordpress/a11y` package's `speak` function. It handles importing\n * the package on demand and should be used instead of calling `a11y.speak` directly.\n *\n * @param messageKey The message to be announced by assistive technologies.\n */\nfunction a11ySpeak( messageKey: keyof typeof navigationTexts ) {\n\tif ( ! hasLoadedNavigationTextsData ) {\n\t\thasLoadedNavigationTextsData = true;\n\t\tconst content = document.getElementById(\n\t\t\t'wp-script-module-data-@wordpress/interactivity-router'\n\t\t)?.textContent;\n\t\tif ( content ) {\n\t\t\ttry {\n\t\t\t\tconst parsed = JSON.parse( content );\n\t\t\t\tif ( typeof parsed?.i18n?.loading === 'string' ) {\n\t\t\t\t\tnavigationTexts.loading = parsed.i18n.loading;\n\t\t\t\t}\n\t\t\t\tif ( typeof parsed?.i18n?.loaded === 'string' ) {\n\t\t\t\t\tnavigationTexts.loaded = parsed.i18n.loaded;\n\t\t\t\t}\n\t\t\t} catch {}\n\t\t} else {\n\t\t\t// Fallback to localized strings from Interactivity API state.\n\t\t\t// @todo This block is for Core < 6.7.0. Remove when support is dropped.\n\n\t\t\t// @ts-expect-error\n\t\t\tif ( state.navigation.texts?.loading ) {\n\t\t\t\t// @ts-expect-error\n\t\t\t\tnavigationTexts.loading = state.navigation.texts.loading;\n\t\t\t}\n\t\t\t// @ts-expect-error\n\t\t\tif ( state.navigation.texts?.loaded ) {\n\t\t\t\t// @ts-expect-error\n\t\t\t\tnavigationTexts.loaded = state.navigation.texts.loaded;\n\t\t\t}\n\t\t}\n\t}\n\n\tconst message = navigationTexts[ messageKey ];\n\n\timport( '@wordpress/a11y' ).then(\n\t\t( { speak } ) => speak( message ),\n\t\t// Ignore failures to load the a11y module.\n\t\t() => {}\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;A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,MAAM,MAAM,MAAM,OAAO,OAAO,SAAS;AAUzC,SAAS,UAAW,YAA2C;AAC9D,MAAK,CAAE,8BAA+B;AACrC,mCAA+B;AAC/B,UAAM,UAAU,SAAS;AAAA,MACxB;AAAA,IACD,GAAG;AACH,QAAK,SAAU;AACd,UAAI;AACH,cAAM,SAAS,KAAK,MAAO,OAAQ;AACnC,YAAK,OAAO,QAAQ,MAAM,YAAY,UAAW;AAChD,0BAAgB,UAAU,OAAO,KAAK;AAAA,QACvC;AACA,YAAK,OAAO,QAAQ,MAAM,WAAW,UAAW;AAC/C,0BAAgB,SAAS,OAAO,KAAK;AAAA,QACtC;AAAA,MACD,QAAQ;AAAA,MAAC;AAAA,IACV,OAAO;AAKN,UAAK,MAAM,WAAW,OAAO,SAAU;AAEtC,wBAAgB,UAAU,MAAM,WAAW,MAAM;AAAA,MAClD;AAEA,UAAK,MAAM,WAAW,OAAO,QAAS;AAErC,wBAAgB,SAAS,MAAM,WAAW,MAAM;AAAA,MACjD;AAAA,IACD;AAAA,EACD;AAEA,QAAM,UAAU,gBAAiB,UAAW;AAE5C,SAAQ,iBAAkB,EAAE;AAAA,IAC3B,CAAE,EAAE,MAAM,MAAO,MAAO,OAAQ;AAAA;AAAA,IAEhC,MAAM;AAAA,IAAC;AAAA,EACR;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/assets/dynamic-importmap/fetch.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * This code is derived from the following projects:\n *\n * 1. dynamic-importmap (https://github.com/keller-mark/dynamic-importmap)\n * 2. es-module-shims (https://github.com/guybedford/es-module-shims)\n *\n * The original implementation was created by Guy Bedford in es-module-shims,\n * then adapted by Mark Keller in dynamic-importmap, and further modified\n * for use in this project.\n *\n * Both projects are licensed under the MIT license.\n *\n * MIT License: https://opensource.org/licenses/MIT\n */\n\n/**\n * Internal dependencies\n */\nimport { type ModuleLoad } from './loader';\n\nconst fetching = ( url: string, parent?: string ) => {\n\treturn ` fetching ${ url }${ parent ? ` from ${ parent }` : '' }`;\n};\n\nconst jsContentType = /^(text|application)\\/(x-)?javascript(;|$)/;\n\n/**\n * Fetches the passed module URL and return the corresponding `ModuleLoad`\n * instance. If the passed URL does not point to a JS file, the function\n * throws and error.\n *\n * @param url Module URL.\n * @param fetchOpts Fetch init options.\n * @param parent Parent module URL referencing this URL (if any).\n * @return Promise with a `ModuleLoad` instance.\n */\nexport async function fetchModule(\n\turl: string,\n\tfetchOpts: RequestInit,\n\tparent: string\n): Promise< ModuleLoad > {\n\tlet res: Response;\n\ttry {\n\t\tres = await fetch( url, fetchOpts );\n\t} catch
|
|
5
|
-
"mappings": ";AAoBA,IAAM,WAAW,CAAE,KAAa,WAAqB;AACpD,SAAO,aAAc,GAAI,GAAI,SAAS,SAAU,MAAO,KAAK,EAAG;AAChE;AAEA,IAAM,gBAAgB;AAYtB,eAAsB,YACrB,KACA,WACA,QACwB;AACxB,MAAI;AACJ,MAAI;AACH,UAAM,MAAM,MAAO,KAAK,SAAU;AAAA,EACnC,
|
|
4
|
+
"sourcesContent": ["/**\n * This code is derived from the following projects:\n *\n * 1. dynamic-importmap (https://github.com/keller-mark/dynamic-importmap)\n * 2. es-module-shims (https://github.com/guybedford/es-module-shims)\n *\n * The original implementation was created by Guy Bedford in es-module-shims,\n * then adapted by Mark Keller in dynamic-importmap, and further modified\n * for use in this project.\n *\n * Both projects are licensed under the MIT license.\n *\n * MIT License: https://opensource.org/licenses/MIT\n */\n\n/**\n * Internal dependencies\n */\nimport { type ModuleLoad } from './loader';\n\nconst fetching = ( url: string, parent?: string ) => {\n\treturn ` fetching ${ url }${ parent ? ` from ${ parent }` : '' }`;\n};\n\nconst jsContentType = /^(text|application)\\/(x-)?javascript(;|$)/;\n\n/**\n * Fetches the passed module URL and return the corresponding `ModuleLoad`\n * instance. If the passed URL does not point to a JS file, the function\n * throws and error.\n *\n * @param url Module URL.\n * @param fetchOpts Fetch init options.\n * @param parent Parent module URL referencing this URL (if any).\n * @return Promise with a `ModuleLoad` instance.\n */\nexport async function fetchModule(\n\turl: string,\n\tfetchOpts: RequestInit,\n\tparent: string\n): Promise< ModuleLoad > {\n\tlet res: Response;\n\ttry {\n\t\tres = await fetch( url, fetchOpts );\n\t} catch {\n\t\tthrow Error( `Network error${ fetching( url, parent ) }.` );\n\t}\n\tif ( ! res.ok ) {\n\t\tthrow Error( `Error ${ res.status }${ fetching( url, parent ) }.` );\n\t}\n\tconst contentType = res.headers.get( 'content-type' );\n\tif ( ! jsContentType.test( contentType ) ) {\n\t\tthrow Error(\n\t\t\t`Bad Content-Type \"${ contentType }\"${ fetching( url, parent ) }.`\n\t\t);\n\t}\n\treturn { responseUrl: res.url, source: await res.text() };\n}\n"],
|
|
5
|
+
"mappings": ";AAoBA,IAAM,WAAW,CAAE,KAAa,WAAqB;AACpD,SAAO,aAAc,GAAI,GAAI,SAAS,SAAU,MAAO,KAAK,EAAG;AAChE;AAEA,IAAM,gBAAgB;AAYtB,eAAsB,YACrB,KACA,WACA,QACwB;AACxB,MAAI;AACJ,MAAI;AACH,UAAM,MAAM,MAAO,KAAK,SAAU;AAAA,EACnC,QAAQ;AACP,UAAM,MAAO,gBAAiB,SAAU,KAAK,MAAO,CAAE,GAAI;AAAA,EAC3D;AACA,MAAK,CAAE,IAAI,IAAK;AACf,UAAM,MAAO,SAAU,IAAI,MAAO,GAAI,SAAU,KAAK,MAAO,CAAE,GAAI;AAAA,EACnE;AACA,QAAM,cAAc,IAAI,QAAQ,IAAK,cAAe;AACpD,MAAK,CAAE,cAAc,KAAM,WAAY,GAAI;AAC1C,UAAM;AAAA,MACL,qBAAsB,WAAY,IAAK,SAAU,KAAK,MAAO,CAAE;AAAA,IAChE;AAAA,EACD;AACA,SAAO,EAAE,aAAa,IAAI,KAAK,QAAQ,MAAM,IAAI,KAAK,EAAE;AACzD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/assets/dynamic-importmap/resolver.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * This code is derived from the following projects:\n *\n * 1. dynamic-importmap (https://github.com/keller-mark/dynamic-importmap)\n * 2. es-module-shims (https://github.com/guybedford/es-module-shims)\n *\n * The original implementation was created by Guy Bedford in es-module-shims,\n * then adapted by Mark Keller in dynamic-importmap, and further modified\n * for use in this project.\n *\n * Both projects are licensed under the MIT license.\n *\n * MIT License: https://opensource.org/licenses/MIT\n */\n\nconst backslashRegEx = /\\\\/g;\n\nfunction isURL( url: string ) {\n\tif ( url.indexOf( ':' ) === -1 ) {\n\t\treturn false;\n\t}\n\ttry {\n\t\tnew URL( url );\n\t\treturn true;\n\t} catch
|
|
5
|
-
"mappings": ";AAeA,IAAM,iBAAiB;AAEvB,SAAS,MAAO,KAAc;AAC7B,MAAK,IAAI,QAAS,GAAI,MAAM,IAAK;AAChC,WAAO;AAAA,EACR;AACA,MAAI;AACH,QAAI,IAAK,GAAI;AACb,WAAO;AAAA,EACR,
|
|
4
|
+
"sourcesContent": ["/**\n * This code is derived from the following projects:\n *\n * 1. dynamic-importmap (https://github.com/keller-mark/dynamic-importmap)\n * 2. es-module-shims (https://github.com/guybedford/es-module-shims)\n *\n * The original implementation was created by Guy Bedford in es-module-shims,\n * then adapted by Mark Keller in dynamic-importmap, and further modified\n * for use in this project.\n *\n * Both projects are licensed under the MIT license.\n *\n * MIT License: https://opensource.org/licenses/MIT\n */\n\nconst backslashRegEx = /\\\\/g;\n\nfunction isURL( url: string ) {\n\tif ( url.indexOf( ':' ) === -1 ) {\n\t\treturn false;\n\t}\n\ttry {\n\t\tnew URL( url );\n\t\treturn true;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\nfunction resolveIfNotPlainOrUrl( relUrl, parentUrl ) {\n\tconst hIdx = parentUrl.indexOf( '#' ),\n\t\tqIdx = parentUrl.indexOf( '?' );\n\tif ( hIdx + qIdx > -2 ) {\n\t\tparentUrl = parentUrl.slice(\n\t\t\t0,\n\t\t\t// eslint-disable-next-line no-nested-ternary\n\t\t\thIdx === -1 ? qIdx : qIdx === -1 || qIdx > hIdx ? hIdx : qIdx\n\t\t);\n\t}\n\tif ( relUrl.indexOf( '\\\\' ) !== -1 ) {\n\t\trelUrl = relUrl.replace( backslashRegEx, '/' );\n\t}\n\t// protocol-relative\n\tif ( relUrl[ 0 ] === '/' && relUrl[ 1 ] === '/' ) {\n\t\treturn parentUrl.slice( 0, parentUrl.indexOf( ':' ) + 1 ) + relUrl;\n\t}\n\t// relative-url\n\telse if (\n\t\t( relUrl[ 0 ] === '.' &&\n\t\t\t( relUrl[ 1 ] === '/' ||\n\t\t\t\t( relUrl[ 1 ] === '.' &&\n\t\t\t\t\t( relUrl[ 2 ] === '/' ||\n\t\t\t\t\t\t( relUrl.length === 2 && ( relUrl += '/' ) ) ) ) ||\n\t\t\t\t( relUrl.length === 1 && ( relUrl += '/' ) ) ) ) ||\n\t\trelUrl[ 0 ] === '/'\n\t) {\n\t\tconst parentProtocol = parentUrl.slice(\n\t\t\t0,\n\t\t\tparentUrl.indexOf( ':' ) + 1\n\t\t);\n\t\t// Disabled, but these cases will give inconsistent results for deep backtracking\n\t\t//if (parentUrl[parentProtocol.length] !== '/')\n\t\t// throw new Error('Cannot resolve');\n\t\t// read pathname from parent URL\n\t\t// pathname taken to be part after leading \"/\"\n\t\tlet pathname;\n\t\tif ( parentUrl[ parentProtocol.length + 1 ] === '/' ) {\n\t\t\t// resolving to a :// so we need to read out the auth and host\n\t\t\tif ( parentProtocol !== 'file:' ) {\n\t\t\t\tpathname = parentUrl.slice( parentProtocol.length + 2 );\n\t\t\t\tpathname = pathname.slice( pathname.indexOf( '/' ) + 1 );\n\t\t\t} else {\n\t\t\t\tpathname = parentUrl.slice( 8 );\n\t\t\t}\n\t\t} else {\n\t\t\t// resolving to :/ so pathname is the /... part\n\t\t\tpathname = parentUrl.slice(\n\t\t\t\tparentProtocol.length +\n\t\t\t\t\t( parentUrl[ parentProtocol.length ] === '/' )\n\t\t\t);\n\t\t}\n\n\t\tif ( relUrl[ 0 ] === '/' ) {\n\t\t\treturn (\n\t\t\t\tparentUrl.slice( 0, parentUrl.length - pathname.length - 1 ) +\n\t\t\t\trelUrl\n\t\t\t);\n\t\t}\n\n\t\t// join together and split for removal of .. and . segments\n\t\t// looping the string instead of anything fancy for perf reasons\n\t\t// '../../../../../z' resolved to 'x/y' is just 'z'\n\t\tconst segmented =\n\t\t\tpathname.slice( 0, pathname.lastIndexOf( '/' ) + 1 ) + relUrl;\n\n\t\tconst output = [];\n\t\tlet segmentIndex = -1;\n\t\tfor ( let i = 0; i < segmented.length; i++ ) {\n\t\t\t// busy reading a segment - only terminate on '/'\n\t\t\tif ( segmentIndex !== -1 ) {\n\t\t\t\tif ( segmented[ i ] === '/' ) {\n\t\t\t\t\toutput.push( segmented.slice( segmentIndex, i + 1 ) );\n\t\t\t\t\tsegmentIndex = -1;\n\t\t\t\t}\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// new segment - check if it is relative\n\t\t\telse if ( segmented[ i ] === '.' ) {\n\t\t\t\t// ../ segment\n\t\t\t\tif (\n\t\t\t\t\tsegmented[ i + 1 ] === '.' &&\n\t\t\t\t\t( segmented[ i + 2 ] === '/' || i + 2 === segmented.length )\n\t\t\t\t) {\n\t\t\t\t\toutput.pop();\n\t\t\t\t\ti += 2;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\t// ./ segment\n\t\t\t\telse if (\n\t\t\t\t\tsegmented[ i + 1 ] === '/' ||\n\t\t\t\t\ti + 1 === segmented.length\n\t\t\t\t) {\n\t\t\t\t\ti += 1;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// it is the start of a new segment\n\t\t\twhile ( segmented[ i ] === '/' ) {\n\t\t\t\ti++;\n\t\t\t}\n\t\t\tsegmentIndex = i;\n\t\t}\n\t\t// finish reading out the last segment\n\t\tif ( segmentIndex !== -1 ) {\n\t\t\toutput.push( segmented.slice( segmentIndex ) );\n\t\t}\n\t\treturn (\n\t\t\tparentUrl.slice( 0, parentUrl.length - pathname.length ) +\n\t\t\toutput.join( '' )\n\t\t);\n\t}\n}\n\nfunction resolveUrl( relUrl, parentUrl ) {\n\treturn (\n\t\tresolveIfNotPlainOrUrl( relUrl, parentUrl ) ||\n\t\t( isURL( relUrl )\n\t\t\t? relUrl\n\t\t\t: resolveIfNotPlainOrUrl( './' + relUrl, parentUrl ) )\n\t);\n}\n\nfunction getMatch( path, matchObj ) {\n\tif ( matchObj[ path ] ) {\n\t\treturn path;\n\t}\n\tlet sepIndex = path.length;\n\tdo {\n\t\tconst segment = path.slice( 0, sepIndex + 1 );\n\t\tif ( segment in matchObj ) {\n\t\t\treturn segment;\n\t\t}\n\t} while ( ( sepIndex = path.lastIndexOf( '/', sepIndex - 1 ) ) !== -1 );\n}\n\nfunction applyPackages( id, packages ) {\n\tconst pkgName = getMatch( id, packages );\n\tif ( pkgName ) {\n\t\tconst pkg = packages[ pkgName ];\n\t\tif ( pkg === null ) {\n\t\t\treturn;\n\t\t}\n\t\treturn pkg + id.slice( pkgName.length );\n\t}\n}\n\nfunction resolveImportMap( importMap, resolvedOrPlain, parentUrl ) {\n\tlet scopeUrl = parentUrl && getMatch( parentUrl, importMap.scopes );\n\twhile ( scopeUrl ) {\n\t\tconst packageResolution = applyPackages(\n\t\t\tresolvedOrPlain,\n\t\t\timportMap.scopes[ scopeUrl ]\n\t\t);\n\t\tif ( packageResolution ) {\n\t\t\treturn packageResolution;\n\t\t}\n\t\tscopeUrl = getMatch(\n\t\t\tscopeUrl.slice( 0, scopeUrl.lastIndexOf( '/' ) ),\n\t\t\timportMap.scopes\n\t\t);\n\t}\n\treturn (\n\t\tapplyPackages( resolvedOrPlain, importMap.imports ) ||\n\t\t( resolvedOrPlain.indexOf( ':' ) !== -1 && resolvedOrPlain )\n\t);\n}\n\nfunction resolveAndComposePackages(\n\tpackages,\n\toutPackages,\n\tbaseUrl,\n\tparentMap\n) {\n\tfor ( const p in packages ) {\n\t\tconst resolvedLhs = resolveIfNotPlainOrUrl( p, baseUrl ) || p;\n\t\tconst target = packages[ p ];\n\t\tif ( typeof target !== 'string' ) {\n\t\t\tcontinue;\n\t\t}\n\t\tconst mapped = resolveImportMap(\n\t\t\tparentMap,\n\t\t\tresolveIfNotPlainOrUrl( target, baseUrl ) || target,\n\t\t\tbaseUrl\n\t\t);\n\t\tif ( mapped ) {\n\t\t\toutPackages[ resolvedLhs ] = mapped;\n\t\t\tcontinue;\n\t\t}\n\t\t// console.warn(\n\t\t// \t`Mapping \"${ p }\" -> \"${ packages[ p ] }\" does not resolve`\n\t\t// );\n\t}\n}\n\nfunction resolveAndComposeImportMap( json, baseUrl, parentMap ) {\n\tconst outMap = {\n\t\timports: Object.assign( {}, parentMap.imports ),\n\t\tscopes: Object.assign( {}, parentMap.scopes ),\n\t};\n\n\tif ( json.imports ) {\n\t\tresolveAndComposePackages(\n\t\t\tjson.imports,\n\t\t\toutMap.imports,\n\t\t\tbaseUrl,\n\t\t\tparentMap\n\t\t);\n\t}\n\n\tif ( json.scopes ) {\n\t\tfor ( const s in json.scopes ) {\n\t\t\tconst resolvedScope = resolveUrl( s, baseUrl );\n\t\t\tresolveAndComposePackages(\n\t\t\t\tjson.scopes[ s ],\n\t\t\t\toutMap.scopes[ resolvedScope ] ||\n\t\t\t\t\t( outMap.scopes[ resolvedScope ] = {} ),\n\t\t\t\tbaseUrl,\n\t\t\t\tparentMap\n\t\t\t);\n\t\t}\n\t}\n\n\treturn outMap;\n}\n\nlet importMap = { imports: {}, scopes: {} };\n\n// TODO: check if this baseURI should change per document, and so\n// it need to be passed as a parameter to methods like `resolve`.\nconst baseUrl = document.baseURI;\nconst pageBaseUrl = baseUrl;\n\n/**\n * Extends the internal dynamic import map with the passed one.\n *\n * @param importMapIn Import map.\n * @param importMapIn.imports Imports declaration.\n * @param importMapIn.scopes Scopes declaration.\n */\nexport function addImportMap( importMapIn: {\n\timports?: Record< string, string >;\n\tscopes?: Record< string, any >;\n} ) {\n\timportMap = resolveAndComposeImportMap(\n\t\timportMapIn,\n\t\tpageBaseUrl,\n\t\timportMap\n\t);\n}\n\n/**\n * Resolves the URL of the passed module ID against the current internal\n * dynamic import map.\n *\n * @param id Module ID.\n * @param parentUrl Parent URL, in case the module ID is relative.\n * @return Resolved module URL.\n */\nexport function resolve( id: string, parentUrl: string ): string {\n\tconst urlResolved = resolveIfNotPlainOrUrl( id, parentUrl );\n\treturn resolveImportMap( importMap, urlResolved || id, parentUrl ) || id;\n}\n"],
|
|
5
|
+
"mappings": ";AAeA,IAAM,iBAAiB;AAEvB,SAAS,MAAO,KAAc;AAC7B,MAAK,IAAI,QAAS,GAAI,MAAM,IAAK;AAChC,WAAO;AAAA,EACR;AACA,MAAI;AACH,QAAI,IAAK,GAAI;AACb,WAAO;AAAA,EACR,QAAQ;AACP,WAAO;AAAA,EACR;AACD;AAEA,SAAS,uBAAwB,QAAQ,WAAY;AACpD,QAAM,OAAO,UAAU,QAAS,GAAI,GACnC,OAAO,UAAU,QAAS,GAAI;AAC/B,MAAK,OAAO,OAAO,IAAK;AACvB,gBAAY,UAAU;AAAA,MACrB;AAAA;AAAA,MAEA,SAAS,KAAK,OAAO,SAAS,MAAM,OAAO,OAAO,OAAO;AAAA,IAC1D;AAAA,EACD;AACA,MAAK,OAAO,QAAS,IAAK,MAAM,IAAK;AACpC,aAAS,OAAO,QAAS,gBAAgB,GAAI;AAAA,EAC9C;AAEA,MAAK,OAAQ,CAAE,MAAM,OAAO,OAAQ,CAAE,MAAM,KAAM;AACjD,WAAO,UAAU,MAAO,GAAG,UAAU,QAAS,GAAI,IAAI,CAAE,IAAI;AAAA,EAC7D,WAGG,OAAQ,CAAE,MAAM,QACf,OAAQ,CAAE,MAAM,OACf,OAAQ,CAAE,MAAM,QACf,OAAQ,CA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AAM,cAAc,uBAAwB,IAAI,SAAU;AAC1D,SAAO,iBAAkB,WAAW,eAAe,IAAI,SAAU,KAAK;AACvE;",
|
|
6
6
|
"names": ["importMap", "baseUrl"]
|
|
7
7
|
}
|
package/build-module/index.mjs
CHANGED
|
@@ -35,7 +35,7 @@ var parseRegionAttribute = (region) => {
|
|
|
35
35
|
try {
|
|
36
36
|
const { id, attachTo } = JSON.parse(value);
|
|
37
37
|
return { id, attachTo };
|
|
38
|
-
} catch
|
|
38
|
+
} catch {
|
|
39
39
|
return { id: value };
|
|
40
40
|
}
|
|
41
41
|
};
|
|
@@ -67,7 +67,7 @@ var fetchPage = async (url, { html }) => {
|
|
|
67
67
|
}
|
|
68
68
|
const dom = new window.DOMParser().parseFromString(html, "text/html");
|
|
69
69
|
return await preparePage(url, dom);
|
|
70
|
-
} catch
|
|
70
|
+
} catch {
|
|
71
71
|
return false;
|
|
72
72
|
}
|
|
73
73
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { store, privateApis, getConfig } from '@wordpress/interactivity';\n\n/**\n * Internal dependencies\n */\nimport { preloadStyles, applyStyles, type StyleElement } from './assets/styles';\nimport {\n\tpreloadScriptModules,\n\timportScriptModules,\n\tmarkScriptModuleAsResolved,\n\ttype ScriptModuleLoad,\n} from './assets/script-modules';\n\nconst {\n\tgetRegionRootFragment,\n\tinitialVdomPromise,\n\ttoVdom,\n\trender,\n\tparseServerData,\n\tpopulateServerData,\n\tbatch,\n\trouterRegions,\n\th: createElement,\n\tnavigationSignal,\n\tsessionId,\n\twarn,\n} = privateApis(\n\t'I acknowledge that using private APIs means my theme or plugin will inevitably break in the next version of WordPress.'\n);\n\nconst regionAttr = `data-wp-router-region`;\nconst interactiveAttr = `data-wp-interactive`;\nconst regionsSelector = `[${ interactiveAttr }][${ regionAttr }], [${ interactiveAttr }] [${ interactiveAttr }][${ regionAttr }]`;\n\nexport interface NavigateOptions {\n\tforce?: boolean;\n\thtml?: string;\n\treplace?: boolean;\n\ttimeout?: number;\n\tloadingAnimation?: boolean;\n\tscreenReaderAnnouncement?: boolean;\n}\n\nexport interface PrefetchOptions {\n\tforce?: boolean;\n\thtml?: string;\n}\n\ninterface VdomParams {\n\tvdom?: WeakMap< Element, any >;\n}\n\ninterface Page {\n\turl: string;\n\tregions: Record< string, any >;\n\tregionsToAttach: Record< string, string >;\n\tstyles: StyleElement[];\n\tscriptModules: ScriptModuleLoad[];\n\ttitle: string;\n\tinitialData: any;\n}\n\ntype PreparePage = (\n\turl: string,\n\tdom: Document,\n\tparams?: VdomParams\n) => Promise< Page >;\n\n// The cache of visited and prefetched pages, stylesheets and scripts.\nconst pages = new Map< string, Promise< Page | false > >();\n\n// Helper to remove domain and hash from the URL. We are only interesting in\n// caching the path and the query.\nconst getPagePath = ( url: string ) => {\n\tconst u = new URL( url, window.location.href );\n\treturn u.pathname + u.search;\n};\n\n/**\n * Parses the given region's directive.\n *\n * @param region Region element.\n * @return Data contained in the region directive value.\n */\nconst parseRegionAttribute = ( region: Element ) => {\n\tconst value = region.getAttribute( regionAttr );\n\ttry {\n\t\tconst { id, attachTo } = JSON.parse( value );\n\t\treturn { id, attachTo };\n\t} catch ( e ) {\n\t\treturn { id: value };\n\t}\n};\n\n/**\n * Clones the content of the router region vDOM passed as argument.\n *\n * The function creates a new VNode instance removing all priority levels up to\n * the one containing the router-region directive, which should have evaluated\n * in advance.\n *\n * @param vdom A router region's VNode.\n * @return The VNode for the passed router region's content.\n */\nconst cloneRouterRegionContent = ( vdom: any ) => {\n\tif ( ! vdom ) {\n\t\treturn vdom;\n\t}\n\tconst allPriorityLevels: string[][] = vdom.props.priorityLevels;\n\tconst routerRegionLevel = allPriorityLevels.findIndex( ( level ) =>\n\t\tlevel.includes( 'router-region' )\n\t);\n\tconst priorityLevels =\n\t\trouterRegionLevel !== -1\n\t\t\t? allPriorityLevels.slice( routerRegionLevel + 1 )\n\t\t\t: allPriorityLevels;\n\n\treturn priorityLevels.length > 0\n\t\t? createElement( vdom.type, {\n\t\t\t\t...vdom.props,\n\t\t\t\tpriorityLevels,\n\t\t } )\n\t\t: vdom.props.element;\n};\n\n/**\n * IDs of router regions with an `attachTo` property pointing to the same parent\n * element.\n */\nconst regionsToAttachByParent = new WeakMap< Element, string[] >();\n\n/**\n * Map of root fragments by parent element, used to render router regions with\n * the `attachTo` property. Those elements with the same parent are rendered\n * together in the corresponding root fragment.\n */\nconst rootFragmentsByParent = new WeakMap< Element, any >();\n\n/**\n * Set of router regions using the `attachTo` property that are present in the\n * initial page.\n *\n * These regions should be treated as regular regions without the `attachTo`\n * attribute as they don't need to be appended; they are already in the HTML.\n */\nconst initialRegionsToAttach = new Set< string >();\n\n/**\n * Fetches and prepares a page from a given URL.\n *\n * @param url The URL of the page to fetch.\n * @param options Options for the fetch operation.\n * @param options.html Optional HTML content. If provided, the function will use\n * this instead of fetching from the URL.\n * @return A Promise that resolves to the prepared page, or false if\n * there was an error during fetching or preparation.\n */\nconst fetchPage = async ( url: string, { html }: { html: string } ) => {\n\ttry {\n\t\tif ( ! html ) {\n\t\t\tconst res = await window.fetch( url );\n\t\t\tif ( res.status !== 200 ) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\thtml = await res.text();\n\t\t}\n\t\tconst dom = new window.DOMParser().parseFromString( html, 'text/html' );\n\t\treturn await preparePage( url, dom );\n\t} catch ( e ) {\n\t\treturn false;\n\t}\n};\n\n/**\n * Processes a DOM document to extract router regions and related resources.\n *\n * This function analyzes the provided DOM document and creates a virtual DOM\n * representation of all HTML regions marked with a `router-region` directive.\n * It also extracts and preloads associated styles and scripts to prepare for\n * rendering the page.\n *\n * @param url The URL associated with the page, used for asset\n * loading and caching.\n * @param dom The DOM document to process.\n * @param vdomParams Optional parameters for virtual DOM processing.\n * @param vdomParams.vdom An optional existing virtual DOM cache to check for\n * regions. If a region exists in this cache, it will be\n * reused instead of creating a new vDOM representation.\n * @return A Promise that resolves to a {@link Page} object\n * containing the virtual DOM for all router regions,\n * preloaded styles and scripts, page title, and initial\n * server-rendered data.\n */\nconst preparePage: PreparePage = async ( url, dom, { vdom } = {} ) => {\n\t// Remove all noscript elements as they're irrelevant when request is served via router.\n\t// This prevents browsers from extracting styles from noscript tags.\n\tdom.querySelectorAll( 'noscript' ).forEach( ( el ) => el.remove() );\n\n\tconst regions = {};\n\tconst regionsToAttach = {};\n\tdom.querySelectorAll( regionsSelector ).forEach( ( region ) => {\n\t\tconst { id, attachTo } = parseRegionAttribute( region );\n\n\t\tif ( region.parentElement.closest( `[${ regionAttr }]` ) ) {\n\t\t\tregions[ id ] = undefined;\n\t\t} else {\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\n\t\tif ( attachTo && ! initialRegionsToAttach.has( id ) ) {\n\t\t\tregionsToAttach[ id ] = attachTo;\n\t\t}\n\t} );\n\n\tconst title = dom.querySelector( 'title' )?.innerText;\n\tconst initialData = parseServerData( dom );\n\n\t// Wait for styles and modules to be ready.\n\tconst [ styles, scriptModules ] = await Promise.all( [\n\t\tPromise.all( preloadStyles( dom ) ),\n\t\tPromise.all( preloadScriptModules( dom ) ),\n\t] );\n\n\treturn {\n\t\tregions,\n\t\tregionsToAttach,\n\t\tstyles,\n\t\tscriptModules,\n\t\ttitle,\n\t\tinitialData,\n\t\turl,\n\t};\n};\n\n/**\n * Renders a page by applying styles, populating server data, rendering regions,\n * and updating the document title.\n *\n * @param page The {@link Page} object to render.\n */\nconst renderPage = ( page: Page ) => {\n\tapplyStyles( page.styles );\n\n\t// Clone regionsToAttach.\n\tconst regionsToAttach = { ...page.regionsToAttach };\n\n\tbatch( () => {\n\t\t// Updates the server data.\n\t\tpopulateServerData( page.initialData );\n\n\t\t// Triggers navigation invalidations (`getServerState` and\n\t\t// `getServerContext`).\n\t\tnavigationSignal.value += 1;\n\n\t\t// Resets all router regions before setting the actual values.\n\t\t( routerRegions as Map< string, any > ).forEach( ( signal ) => {\n\t\t\tsignal.value = null;\n\t\t} );\n\n\t\t// Inits regions with attachTo that don't exist yet.\n\t\tconst parentsToUpdate = new Set< Element >();\n\t\tfor ( const id in regionsToAttach ) {\n\t\t\tconst parent = document.querySelector( regionsToAttach[ id ] );\n\t\t\tif ( ! regionsToAttachByParent.has( parent ) ) {\n\t\t\t\tregionsToAttachByParent.set( parent, [] );\n\t\t\t}\n\t\t\tconst regions = regionsToAttachByParent.get( parent );\n\t\t\tif ( ! regions.includes( id ) ) {\n\t\t\t\tregions.push( id );\n\t\t\t\tparentsToUpdate.add( parent );\n\t\t\t}\n\t\t}\n\n\t\t// Updates all existing regions.\n\t\tfor ( const id in page.regions ) {\n\t\t\tif ( routerRegions.has( id ) ) {\n\t\t\t\trouterRegions.get( id ).value = cloneRouterRegionContent(\n\t\t\t\t\tpage.regions[ id ]\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\t// Renders regions attached to the same parent in the same fragment.\n\t\tparentsToUpdate.forEach( ( parent ) => {\n\t\t\tconst ids = regionsToAttachByParent.get( parent );\n\t\t\tconst vdoms = ids.map( ( id ) => page.regions[ id ] );\n\n\t\t\tif ( ! rootFragmentsByParent.has( parent ) ) {\n\t\t\t\tconst regions = vdoms.map( ( { props, type } ) => {\n\t\t\t\t\tconst elementType =\n\t\t\t\t\t\ttypeof type === 'function' ? props.type : type;\n\n\t\t\t\t\t// Creates an element with the obtained type where the\n\t\t\t\t\t// region will be rendered. The type should match the one of\n\t\t\t\t\t// the root vnode.\n\t\t\t\t\tconst region = document.createElement( elementType );\n\t\t\t\t\tparent.appendChild( region );\n\t\t\t\t\treturn region;\n\t\t\t\t} );\n\t\t\t\trootFragmentsByParent.set(\n\t\t\t\t\tparent,\n\t\t\t\t\tgetRegionRootFragment( regions )\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst fragment = rootFragmentsByParent.get( parent );\n\t\t\trender( vdoms, fragment );\n\t\t} );\n\t} );\n\n\tif ( page.title ) {\n\t\tdocument.title = page.title;\n\t}\n};\n\n/**\n * Loads the given page forcing a full page reload.\n *\n * The function returns a promise that won't resolve, useful to prevent any\n * potential feedback indicating that the navigation has finished while the new\n * page is being loaded.\n *\n * @param href The page href.\n * @return Promise that never resolves.\n */\nconst forcePageReload = ( href: string ) => {\n\twindow.location.assign( href );\n\treturn new Promise( () => {} );\n};\n\n// Listen to the back and forward buttons and restore the page if it's in the\n// cache.\nwindow.addEventListener( 'popstate', async () => {\n\tconst pagePath = getPagePath( window.location.href ); // Remove hash.\n\tconst page = pages.has( pagePath ) && ( await pages.get( pagePath ) );\n\tif ( page ) {\n\t\tbatch( () => {\n\t\t\tstate.url = window.location.href;\n\t\t\trenderPage( page );\n\t\t} );\n\t} else {\n\t\twindow.location.reload();\n\t}\n} );\n\n// Detect router regions with `attachTo` in the initial page. This step should\n// be done before the initial page is processed with `preparePage()` so this\n// function treats them as regular router regions.\ndocument.querySelectorAll( regionsSelector ).forEach( ( region ) => {\n\tconst { id, attachTo } = parseRegionAttribute( region );\n\tif ( attachTo ) {\n\t\tinitialRegionsToAttach.add( id );\n\t}\n} );\n\n// Initialize the router and cache the initial page using the initial vDOM.\nwindow.document\n\t.querySelectorAll< HTMLScriptElement >( 'script[type=module][src]' )\n\t.forEach( ( { src } ) => markScriptModuleAsResolved( src ) );\n\n// Await hydration completion before setting the initial page to ensure initialVdom is populated.\n( async () => {\n\tconst initialVdomMap = await initialVdomPromise;\n\tpages.set(\n\t\tgetPagePath( window.location.href ),\n\t\tPromise.resolve(\n\t\t\tpreparePage( getPagePath( window.location.href ), document, {\n\t\t\t\tvdom: initialVdomMap,\n\t\t\t} )\n\t\t)\n\t);\n} )();\n\n// Variable to store the current navigation.\nlet navigatingTo = '';\n\nlet hasLoadedNavigationTextsData = false;\nconst navigationTexts = {\n\tloading: 'Loading page, please wait.',\n\tloaded: 'Page Loaded.',\n};\n\ninterface Store {\n\tstate: {\n\t\turl: string;\n\t\tnavigation: {\n\t\t\thasStarted: boolean;\n\t\t\thasFinished: boolean;\n\t\t};\n\t};\n\tactions: {\n\t\tnavigate: (\n\t\t\thref: string,\n\t\t\toptions?: NavigateOptions\n\t\t) => Promise< void >;\n\t\tprefetch: ( url: string, options?: PrefetchOptions ) => Promise< void >;\n\t};\n}\n\nconst { state: privateState } = store(\n\t'core/router/private',\n\t{\n\t\tstate: {\n\t\t\tnavigation: {\n\t\t\t\thasStarted: false,\n\t\t\t\thasFinished: false,\n\t\t\t},\n\t\t},\n\t},\n\t{ lock: true }\n);\n\nexport const { state, actions } = store< Store >( 'core/router', {\n\tstate: {\n\t\tget navigation() {\n\t\t\tif ( globalThis.SCRIPT_DEBUG ) {\n\t\t\t\twarn(\n\t\t\t\t\t`The usage of state.navigation.{hasStarted|hasFinished} from core/router is deprecated and will stop working in WordPress 7.1.`\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn privateState.navigation;\n\t\t},\n\t},\n\tactions: {\n\t\t/**\n\t\t * Navigates to the specified page.\n\t\t *\n\t\t * This function normalizes the passed href, fetches the page HTML if\n\t\t * needed, and updates any interactive regions whose contents have\n\t\t * changed. It also creates a new entry in the browser session history.\n\t\t *\n\t\t * @param href The page href.\n\t\t * @param [options] Options object.\n\t\t * @param [options.force] If true, it forces re-fetching the URL.\n\t\t * @param [options.html] HTML string to be used instead of fetching the requested URL.\n\t\t * @param [options.replace] If true, it replaces the current entry in the browser session history.\n\t\t * @param [options.timeout] Time until the navigation is aborted, in milliseconds. Default is 10000.\n\t\t * @param [options.loadingAnimation] Whether an animation should be shown while navigating. Default to `true`.\n\t\t * @param [options.screenReaderAnnouncement] Whether a message for screen readers should be announced while navigating. Default to `true`.\n\t\t *\n\t\t * @return Promise that resolves once the navigation is completed or aborted.\n\t\t */\n\t\t*navigate( href: string, options: NavigateOptions = {} ) {\n\t\t\tconst { clientNavigationDisabled } = getConfig();\n\t\t\tif ( clientNavigationDisabled ) {\n\t\t\t\tyield forcePageReload( href );\n\t\t\t}\n\n\t\t\tconst pagePath = getPagePath( href );\n\t\t\tconst { navigation } = privateState;\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// Creates 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// Doesn'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// Dismisses loading message if it hasn't been added yet.\n\t\t\tclearTimeout( loadingTimeout );\n\n\t\t\t// Once the page is fetched, the destination URL could have changed\n\t\t\t// (e.g., by clicking another link in the meantime). If so, bail\n\t\t\t// out, and let the newer execution to update the HTML.\n\t\t\tif ( navigatingTo !== href ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\tpage &&\n\t\t\t\t! page.initialData?.config?.[ 'core/router' ]\n\t\t\t\t\t?.clientNavigationDisabled\n\t\t\t) {\n\t\t\t\tyield importScriptModules( page.scriptModules );\n\n\t\t\t\tbatch( () => {\n\t\t\t\t\t// Updates the URL in the state.\n\t\t\t\t\tstate.url = href;\n\n\t\t\t\t\t// Updates the navigation status once the the new page rendering\n\t\t\t\t\t// has been completed.\n\t\t\t\t\tif ( loadingAnimation ) {\n\t\t\t\t\t\tnavigation.hasStarted = false;\n\t\t\t\t\t\tnavigation.hasFinished = true;\n\t\t\t\t\t}\n\n\t\t\t\t\t// Renders the new page.\n\t\t\t\t\trenderPage( page );\n\t\t\t\t} );\n\n\t\t\t\twindow.history[\n\t\t\t\t\toptions.replace ? 'replaceState' : 'pushState'\n\t\t\t\t]( { wpInteractivityId: sessionId }, '', href );\n\n\t\t\t\tif ( screenReaderAnnouncement ) {\n\t\t\t\t\ta11ySpeak( 'loaded' );\n\t\t\t\t}\n\n\t\t\t\t// Scroll to the anchor if exits in the link.\n\t\t\t\tconst { hash } = new URL( href, window.location.href );\n\t\t\t\tif ( hash ) {\n\t\t\t\t\tdocument.querySelector( hash )?.scrollIntoView();\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tyield forcePageReload( href );\n\t\t\t}\n\t\t},\n\n\t\t/**\n\t\t * Prefetches the page with the passed URL.\n\t\t *\n\t\t * The function normalizes the URL and stores internally the fetch\n\t\t * promise, to avoid triggering a second fetch for an ongoing request.\n\t\t *\n\t\t * @param url The page URL.\n\t\t * @param [options] Options object.\n\t\t * @param [options.force] Force fetching the URL again.\n\t\t * @param [options.html] HTML string to be used instead of fetching the requested URL.\n\t\t *\n\t\t * @return Promise that resolves once the page has been fetched.\n\t\t */\n\t\t*prefetch( url: string, options: PrefetchOptions = {} ) {\n\t\t\tconst { clientNavigationDisabled } = getConfig();\n\t\t\tif ( clientNavigationDisabled ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst pagePath = getPagePath( url );\n\t\t\tif ( options.force || ! pages.has( pagePath ) ) {\n\t\t\t\tpages.set(\n\t\t\t\t\tpagePath,\n\t\t\t\t\tfetchPage( pagePath, { html: options.html } )\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tyield pages.get( pagePath );\n\t\t},\n\t},\n} );\n\n// Initialize the URL in the state if it hasn't been set yet in the server.\nstate.url = state.url || window.location.href;\n\n/**\n * Announces a message to screen readers.\n *\n * This is a wrapper around the `@wordpress/a11y` package's `speak` function. It handles importing\n * the package on demand and should be used instead of calling `a11y.speak` directly.\n *\n * @param messageKey The message to be announced by assistive technologies.\n */\nfunction a11ySpeak( messageKey: keyof typeof navigationTexts ) {\n\tif ( ! hasLoadedNavigationTextsData ) {\n\t\thasLoadedNavigationTextsData = true;\n\t\tconst content = document.getElementById(\n\t\t\t'wp-script-module-data-@wordpress/interactivity-router'\n\t\t)?.textContent;\n\t\tif ( content ) {\n\t\t\ttry {\n\t\t\t\tconst parsed = JSON.parse( content );\n\t\t\t\tif ( typeof parsed?.i18n?.loading === 'string' ) {\n\t\t\t\t\tnavigationTexts.loading = parsed.i18n.loading;\n\t\t\t\t}\n\t\t\t\tif ( typeof parsed?.i18n?.loaded === 'string' ) {\n\t\t\t\t\tnavigationTexts.loaded = parsed.i18n.loaded;\n\t\t\t\t}\n\t\t\t} catch {}\n\t\t} else {\n\t\t\t// Fallback to localized strings from Interactivity API state.\n\t\t\t// @todo This block is for Core < 6.7.0. Remove when support is dropped.\n\n\t\t\t// @ts-expect-error\n\t\t\tif ( state.navigation.texts?.loading ) {\n\t\t\t\t// @ts-expect-error\n\t\t\t\tnavigationTexts.loading = state.navigation.texts.loading;\n\t\t\t}\n\t\t\t// @ts-expect-error\n\t\t\tif ( state.navigation.texts?.loaded ) {\n\t\t\t\t// @ts-expect-error\n\t\t\t\tnavigationTexts.loaded = state.navigation.texts.loaded;\n\t\t\t}\n\t\t}\n\t}\n\n\tconst message = navigationTexts[ messageKey ];\n\n\timport( '@wordpress/a11y' ).then(\n\t\t( { speak } ) => speak( message ),\n\t\t// Ignore failures to load the a11y module.\n\t\t() => {}\n\t);\n}\n"],
|
|
5
|
-
"mappings": ";AAGA,SAAS,OAAO,aAAa,iBAAiB;AAK9C,SAAS,eAAe,mBAAsC;AAC9D;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OAEM;AAEP,IAAM;AAAA,EACL;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AAAA,EACH;AAAA,EACA;AAAA,EACA;AACD,IAAI;AAAA,EACH;AACD;AAEA,IAAM,aAAa;AACnB,IAAM,kBAAkB;AACxB,IAAM,kBAAkB,IAAK,eAAgB,KAAM,UAAW,OAAQ,eAAgB,MAAO,eAAgB,KAAM,UAAW;AAqC9H,IAAM,QAAQ,oBAAI,IAAuC;AAIzD,IAAM,cAAc,CAAE,QAAiB;AACtC,QAAM,IAAI,IAAI,IAAK,KAAK,OAAO,SAAS,IAAK;AAC7C,SAAO,EAAE,WAAW,EAAE;AACvB;AAQA,IAAM,uBAAuB,CAAE,WAAqB;AACnD,QAAM,QAAQ,OAAO,aAAc,UAAW;AAC9C,MAAI;AACH,UAAM,EAAE,IAAI,SAAS,IAAI,KAAK,MAAO,KAAM;AAC3C,WAAO,EAAE,IAAI,SAAS;AAAA,EACvB,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { store, privateApis, getConfig } from '@wordpress/interactivity';\n\n/**\n * Internal dependencies\n */\nimport { preloadStyles, applyStyles, type StyleElement } from './assets/styles';\nimport {\n\tpreloadScriptModules,\n\timportScriptModules,\n\tmarkScriptModuleAsResolved,\n\ttype ScriptModuleLoad,\n} from './assets/script-modules';\n\nconst {\n\tgetRegionRootFragment,\n\tinitialVdomPromise,\n\ttoVdom,\n\trender,\n\tparseServerData,\n\tpopulateServerData,\n\tbatch,\n\trouterRegions,\n\th: createElement,\n\tnavigationSignal,\n\tsessionId,\n\twarn,\n} = privateApis(\n\t'I acknowledge that using private APIs means my theme or plugin will inevitably break in the next version of WordPress.'\n);\n\nconst regionAttr = `data-wp-router-region`;\nconst interactiveAttr = `data-wp-interactive`;\nconst regionsSelector = `[${ interactiveAttr }][${ regionAttr }], [${ interactiveAttr }] [${ interactiveAttr }][${ regionAttr }]`;\n\nexport interface NavigateOptions {\n\tforce?: boolean;\n\thtml?: string;\n\treplace?: boolean;\n\ttimeout?: number;\n\tloadingAnimation?: boolean;\n\tscreenReaderAnnouncement?: boolean;\n}\n\nexport interface PrefetchOptions {\n\tforce?: boolean;\n\thtml?: string;\n}\n\ninterface VdomParams {\n\tvdom?: WeakMap< Element, any >;\n}\n\ninterface Page {\n\turl: string;\n\tregions: Record< string, any >;\n\tregionsToAttach: Record< string, string >;\n\tstyles: StyleElement[];\n\tscriptModules: ScriptModuleLoad[];\n\ttitle: string;\n\tinitialData: any;\n}\n\ntype PreparePage = (\n\turl: string,\n\tdom: Document,\n\tparams?: VdomParams\n) => Promise< Page >;\n\n// The cache of visited and prefetched pages, stylesheets and scripts.\nconst pages = new Map< string, Promise< Page | false > >();\n\n// Helper to remove domain and hash from the URL. We are only interesting in\n// caching the path and the query.\nconst getPagePath = ( url: string ) => {\n\tconst u = new URL( url, window.location.href );\n\treturn u.pathname + u.search;\n};\n\n/**\n * Parses the given region's directive.\n *\n * @param region Region element.\n * @return Data contained in the region directive value.\n */\nconst parseRegionAttribute = ( region: Element ) => {\n\tconst value = region.getAttribute( regionAttr );\n\ttry {\n\t\tconst { id, attachTo } = JSON.parse( value );\n\t\treturn { id, attachTo };\n\t} catch {\n\t\treturn { id: value };\n\t}\n};\n\n/**\n * Clones the content of the router region vDOM passed as argument.\n *\n * The function creates a new VNode instance removing all priority levels up to\n * the one containing the router-region directive, which should have evaluated\n * in advance.\n *\n * @param vdom A router region's VNode.\n * @return The VNode for the passed router region's content.\n */\nconst cloneRouterRegionContent = ( vdom: any ) => {\n\tif ( ! vdom ) {\n\t\treturn vdom;\n\t}\n\tconst allPriorityLevels: string[][] = vdom.props.priorityLevels;\n\tconst routerRegionLevel = allPriorityLevels.findIndex( ( level ) =>\n\t\tlevel.includes( 'router-region' )\n\t);\n\tconst priorityLevels =\n\t\trouterRegionLevel !== -1\n\t\t\t? allPriorityLevels.slice( routerRegionLevel + 1 )\n\t\t\t: allPriorityLevels;\n\n\treturn priorityLevels.length > 0\n\t\t? createElement( vdom.type, {\n\t\t\t\t...vdom.props,\n\t\t\t\tpriorityLevels,\n\t\t } )\n\t\t: vdom.props.element;\n};\n\n/**\n * IDs of router regions with an `attachTo` property pointing to the same parent\n * element.\n */\nconst regionsToAttachByParent = new WeakMap< Element, string[] >();\n\n/**\n * Map of root fragments by parent element, used to render router regions with\n * the `attachTo` property. Those elements with the same parent are rendered\n * together in the corresponding root fragment.\n */\nconst rootFragmentsByParent = new WeakMap< Element, any >();\n\n/**\n * Set of router regions using the `attachTo` property that are present in the\n * initial page.\n *\n * These regions should be treated as regular regions without the `attachTo`\n * attribute as they don't need to be appended; they are already in the HTML.\n */\nconst initialRegionsToAttach = new Set< string >();\n\n/**\n * Fetches and prepares a page from a given URL.\n *\n * @param url The URL of the page to fetch.\n * @param options Options for the fetch operation.\n * @param options.html Optional HTML content. If provided, the function will use\n * this instead of fetching from the URL.\n * @return A Promise that resolves to the prepared page, or false if\n * there was an error during fetching or preparation.\n */\nconst fetchPage = async ( url: string, { html }: { html: string } ) => {\n\ttry {\n\t\tif ( ! html ) {\n\t\t\tconst res = await window.fetch( url );\n\t\t\tif ( res.status !== 200 ) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\thtml = await res.text();\n\t\t}\n\t\tconst dom = new window.DOMParser().parseFromString( html, 'text/html' );\n\t\treturn await preparePage( url, dom );\n\t} catch {\n\t\treturn false;\n\t}\n};\n\n/**\n * Processes a DOM document to extract router regions and related resources.\n *\n * This function analyzes the provided DOM document and creates a virtual DOM\n * representation of all HTML regions marked with a `router-region` directive.\n * It also extracts and preloads associated styles and scripts to prepare for\n * rendering the page.\n *\n * @param url The URL associated with the page, used for asset\n * loading and caching.\n * @param dom The DOM document to process.\n * @param vdomParams Optional parameters for virtual DOM processing.\n * @param vdomParams.vdom An optional existing virtual DOM cache to check for\n * regions. If a region exists in this cache, it will be\n * reused instead of creating a new vDOM representation.\n * @return A Promise that resolves to a {@link Page} object\n * containing the virtual DOM for all router regions,\n * preloaded styles and scripts, page title, and initial\n * server-rendered data.\n */\nconst preparePage: PreparePage = async ( url, dom, { vdom } = {} ) => {\n\t// Remove all noscript elements as they're irrelevant when request is served via router.\n\t// This prevents browsers from extracting styles from noscript tags.\n\tdom.querySelectorAll( 'noscript' ).forEach( ( el ) => el.remove() );\n\n\tconst regions = {};\n\tconst regionsToAttach = {};\n\tdom.querySelectorAll( regionsSelector ).forEach( ( region ) => {\n\t\tconst { id, attachTo } = parseRegionAttribute( region );\n\n\t\tif ( region.parentElement.closest( `[${ regionAttr }]` ) ) {\n\t\t\tregions[ id ] = undefined;\n\t\t} else {\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\n\t\tif ( attachTo && ! initialRegionsToAttach.has( id ) ) {\n\t\t\tregionsToAttach[ id ] = attachTo;\n\t\t}\n\t} );\n\n\tconst title = dom.querySelector( 'title' )?.innerText;\n\tconst initialData = parseServerData( dom );\n\n\t// Wait for styles and modules to be ready.\n\tconst [ styles, scriptModules ] = await Promise.all( [\n\t\tPromise.all( preloadStyles( dom ) ),\n\t\tPromise.all( preloadScriptModules( dom ) ),\n\t] );\n\n\treturn {\n\t\tregions,\n\t\tregionsToAttach,\n\t\tstyles,\n\t\tscriptModules,\n\t\ttitle,\n\t\tinitialData,\n\t\turl,\n\t};\n};\n\n/**\n * Renders a page by applying styles, populating server data, rendering regions,\n * and updating the document title.\n *\n * @param page The {@link Page} object to render.\n */\nconst renderPage = ( page: Page ) => {\n\tapplyStyles( page.styles );\n\n\t// Clone regionsToAttach.\n\tconst regionsToAttach = { ...page.regionsToAttach };\n\n\tbatch( () => {\n\t\t// Updates the server data.\n\t\tpopulateServerData( page.initialData );\n\n\t\t// Triggers navigation invalidations (`getServerState` and\n\t\t// `getServerContext`).\n\t\tnavigationSignal.value += 1;\n\n\t\t// Resets all router regions before setting the actual values.\n\t\t( routerRegions as Map< string, any > ).forEach( ( signal ) => {\n\t\t\tsignal.value = null;\n\t\t} );\n\n\t\t// Inits regions with attachTo that don't exist yet.\n\t\tconst parentsToUpdate = new Set< Element >();\n\t\tfor ( const id in regionsToAttach ) {\n\t\t\tconst parent = document.querySelector( regionsToAttach[ id ] );\n\t\t\tif ( ! regionsToAttachByParent.has( parent ) ) {\n\t\t\t\tregionsToAttachByParent.set( parent, [] );\n\t\t\t}\n\t\t\tconst regions = regionsToAttachByParent.get( parent );\n\t\t\tif ( ! regions.includes( id ) ) {\n\t\t\t\tregions.push( id );\n\t\t\t\tparentsToUpdate.add( parent );\n\t\t\t}\n\t\t}\n\n\t\t// Updates all existing regions.\n\t\tfor ( const id in page.regions ) {\n\t\t\tif ( routerRegions.has( id ) ) {\n\t\t\t\trouterRegions.get( id ).value = cloneRouterRegionContent(\n\t\t\t\t\tpage.regions[ id ]\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\t// Renders regions attached to the same parent in the same fragment.\n\t\tparentsToUpdate.forEach( ( parent ) => {\n\t\t\tconst ids = regionsToAttachByParent.get( parent );\n\t\t\tconst vdoms = ids.map( ( id ) => page.regions[ id ] );\n\n\t\t\tif ( ! rootFragmentsByParent.has( parent ) ) {\n\t\t\t\tconst regions = vdoms.map( ( { props, type } ) => {\n\t\t\t\t\tconst elementType =\n\t\t\t\t\t\ttypeof type === 'function' ? props.type : type;\n\n\t\t\t\t\t// Creates an element with the obtained type where the\n\t\t\t\t\t// region will be rendered. The type should match the one of\n\t\t\t\t\t// the root vnode.\n\t\t\t\t\tconst region = document.createElement( elementType );\n\t\t\t\t\tparent.appendChild( region );\n\t\t\t\t\treturn region;\n\t\t\t\t} );\n\t\t\t\trootFragmentsByParent.set(\n\t\t\t\t\tparent,\n\t\t\t\t\tgetRegionRootFragment( regions )\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst fragment = rootFragmentsByParent.get( parent );\n\t\t\trender( vdoms, fragment );\n\t\t} );\n\t} );\n\n\tif ( page.title ) {\n\t\tdocument.title = page.title;\n\t}\n};\n\n/**\n * Loads the given page forcing a full page reload.\n *\n * The function returns a promise that won't resolve, useful to prevent any\n * potential feedback indicating that the navigation has finished while the new\n * page is being loaded.\n *\n * @param href The page href.\n * @return Promise that never resolves.\n */\nconst forcePageReload = ( href: string ) => {\n\twindow.location.assign( href );\n\treturn new Promise( () => {} );\n};\n\n// Listen to the back and forward buttons and restore the page if it's in the\n// cache.\nwindow.addEventListener( 'popstate', async () => {\n\tconst pagePath = getPagePath( window.location.href ); // Remove hash.\n\tconst page = pages.has( pagePath ) && ( await pages.get( pagePath ) );\n\tif ( page ) {\n\t\tbatch( () => {\n\t\t\tstate.url = window.location.href;\n\t\t\trenderPage( page );\n\t\t} );\n\t} else {\n\t\twindow.location.reload();\n\t}\n} );\n\n// Detect router regions with `attachTo` in the initial page. This step should\n// be done before the initial page is processed with `preparePage()` so this\n// function treats them as regular router regions.\ndocument.querySelectorAll( regionsSelector ).forEach( ( region ) => {\n\tconst { id, attachTo } = parseRegionAttribute( region );\n\tif ( attachTo ) {\n\t\tinitialRegionsToAttach.add( id );\n\t}\n} );\n\n// Initialize the router and cache the initial page using the initial vDOM.\nwindow.document\n\t.querySelectorAll< HTMLScriptElement >( 'script[type=module][src]' )\n\t.forEach( ( { src } ) => markScriptModuleAsResolved( src ) );\n\n// Await hydration completion before setting the initial page to ensure initialVdom is populated.\n( async () => {\n\tconst initialVdomMap = await initialVdomPromise;\n\tpages.set(\n\t\tgetPagePath( window.location.href ),\n\t\tPromise.resolve(\n\t\t\tpreparePage( getPagePath( window.location.href ), document, {\n\t\t\t\tvdom: initialVdomMap,\n\t\t\t} )\n\t\t)\n\t);\n} )();\n\n// Variable to store the current navigation.\nlet navigatingTo = '';\n\nlet hasLoadedNavigationTextsData = false;\nconst navigationTexts = {\n\tloading: 'Loading page, please wait.',\n\tloaded: 'Page Loaded.',\n};\n\ninterface Store {\n\tstate: {\n\t\turl: string;\n\t\tnavigation: {\n\t\t\thasStarted: boolean;\n\t\t\thasFinished: boolean;\n\t\t};\n\t};\n\tactions: {\n\t\tnavigate: (\n\t\t\thref: string,\n\t\t\toptions?: NavigateOptions\n\t\t) => Promise< void >;\n\t\tprefetch: ( url: string, options?: PrefetchOptions ) => Promise< void >;\n\t};\n}\n\nconst { state: privateState } = store(\n\t'core/router/private',\n\t{\n\t\tstate: {\n\t\t\tnavigation: {\n\t\t\t\thasStarted: false,\n\t\t\t\thasFinished: false,\n\t\t\t},\n\t\t},\n\t},\n\t{ lock: true }\n);\n\nexport const { state, actions } = store< Store >( 'core/router', {\n\tstate: {\n\t\tget navigation() {\n\t\t\tif ( globalThis.SCRIPT_DEBUG ) {\n\t\t\t\twarn(\n\t\t\t\t\t`The usage of state.navigation.{hasStarted|hasFinished} from core/router is deprecated and will stop working in WordPress 7.1.`\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn privateState.navigation;\n\t\t},\n\t},\n\tactions: {\n\t\t/**\n\t\t * Navigates to the specified page.\n\t\t *\n\t\t * This function normalizes the passed href, fetches the page HTML if\n\t\t * needed, and updates any interactive regions whose contents have\n\t\t * changed. It also creates a new entry in the browser session history.\n\t\t *\n\t\t * @param href The page href.\n\t\t * @param [options] Options object.\n\t\t * @param [options.force] If true, it forces re-fetching the URL.\n\t\t * @param [options.html] HTML string to be used instead of fetching the requested URL.\n\t\t * @param [options.replace] If true, it replaces the current entry in the browser session history.\n\t\t * @param [options.timeout] Time until the navigation is aborted, in milliseconds. Default is 10000.\n\t\t * @param [options.loadingAnimation] Whether an animation should be shown while navigating. Default to `true`.\n\t\t * @param [options.screenReaderAnnouncement] Whether a message for screen readers should be announced while navigating. Default to `true`.\n\t\t *\n\t\t * @return Promise that resolves once the navigation is completed or aborted.\n\t\t */\n\t\t*navigate( href: string, options: NavigateOptions = {} ) {\n\t\t\tconst { clientNavigationDisabled } = getConfig();\n\t\t\tif ( clientNavigationDisabled ) {\n\t\t\t\tyield forcePageReload( href );\n\t\t\t}\n\n\t\t\tconst pagePath = getPagePath( href );\n\t\t\tconst { navigation } = privateState;\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// Creates 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// Doesn'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// Dismisses loading message if it hasn't been added yet.\n\t\t\tclearTimeout( loadingTimeout );\n\n\t\t\t// Once the page is fetched, the destination URL could have changed\n\t\t\t// (e.g., by clicking another link in the meantime). If so, bail\n\t\t\t// out, and let the newer execution to update the HTML.\n\t\t\tif ( navigatingTo !== href ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (\n\t\t\t\tpage &&\n\t\t\t\t! page.initialData?.config?.[ 'core/router' ]\n\t\t\t\t\t?.clientNavigationDisabled\n\t\t\t) {\n\t\t\t\tyield importScriptModules( page.scriptModules );\n\n\t\t\t\tbatch( () => {\n\t\t\t\t\t// Updates the URL in the state.\n\t\t\t\t\tstate.url = href;\n\n\t\t\t\t\t// Updates the navigation status once the the new page rendering\n\t\t\t\t\t// has been completed.\n\t\t\t\t\tif ( loadingAnimation ) {\n\t\t\t\t\t\tnavigation.hasStarted = false;\n\t\t\t\t\t\tnavigation.hasFinished = true;\n\t\t\t\t\t}\n\n\t\t\t\t\t// Renders the new page.\n\t\t\t\t\trenderPage( page );\n\t\t\t\t} );\n\n\t\t\t\twindow.history[\n\t\t\t\t\toptions.replace ? 'replaceState' : 'pushState'\n\t\t\t\t]( { wpInteractivityId: sessionId }, '', href );\n\n\t\t\t\tif ( screenReaderAnnouncement ) {\n\t\t\t\t\ta11ySpeak( 'loaded' );\n\t\t\t\t}\n\n\t\t\t\t// Scroll to the anchor if exits in the link.\n\t\t\t\tconst { hash } = new URL( href, window.location.href );\n\t\t\t\tif ( hash ) {\n\t\t\t\t\tdocument.querySelector( hash )?.scrollIntoView();\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tyield forcePageReload( href );\n\t\t\t}\n\t\t},\n\n\t\t/**\n\t\t * Prefetches the page with the passed URL.\n\t\t *\n\t\t * The function normalizes the URL and stores internally the fetch\n\t\t * promise, to avoid triggering a second fetch for an ongoing request.\n\t\t *\n\t\t * @param url The page URL.\n\t\t * @param [options] Options object.\n\t\t * @param [options.force] Force fetching the URL again.\n\t\t * @param [options.html] HTML string to be used instead of fetching the requested URL.\n\t\t *\n\t\t * @return Promise that resolves once the page has been fetched.\n\t\t */\n\t\t*prefetch( url: string, options: PrefetchOptions = {} ) {\n\t\t\tconst { clientNavigationDisabled } = getConfig();\n\t\t\tif ( clientNavigationDisabled ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst pagePath = getPagePath( url );\n\t\t\tif ( options.force || ! pages.has( pagePath ) ) {\n\t\t\t\tpages.set(\n\t\t\t\t\tpagePath,\n\t\t\t\t\tfetchPage( pagePath, { html: options.html } )\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tyield pages.get( pagePath );\n\t\t},\n\t},\n} );\n\n// Initialize the URL in the state if it hasn't been set yet in the server.\nstate.url = state.url || window.location.href;\n\n/**\n * Announces a message to screen readers.\n *\n * This is a wrapper around the `@wordpress/a11y` package's `speak` function. It handles importing\n * the package on demand and should be used instead of calling `a11y.speak` directly.\n *\n * @param messageKey The message to be announced by assistive technologies.\n */\nfunction a11ySpeak( messageKey: keyof typeof navigationTexts ) {\n\tif ( ! hasLoadedNavigationTextsData ) {\n\t\thasLoadedNavigationTextsData = true;\n\t\tconst content = document.getElementById(\n\t\t\t'wp-script-module-data-@wordpress/interactivity-router'\n\t\t)?.textContent;\n\t\tif ( content ) {\n\t\t\ttry {\n\t\t\t\tconst parsed = JSON.parse( content );\n\t\t\t\tif ( typeof parsed?.i18n?.loading === 'string' ) {\n\t\t\t\t\tnavigationTexts.loading = parsed.i18n.loading;\n\t\t\t\t}\n\t\t\t\tif ( typeof parsed?.i18n?.loaded === 'string' ) {\n\t\t\t\t\tnavigationTexts.loaded = parsed.i18n.loaded;\n\t\t\t\t}\n\t\t\t} catch {}\n\t\t} else {\n\t\t\t// Fallback to localized strings from Interactivity API state.\n\t\t\t// @todo This block is for Core < 6.7.0. Remove when support is dropped.\n\n\t\t\t// @ts-expect-error\n\t\t\tif ( state.navigation.texts?.loading ) {\n\t\t\t\t// @ts-expect-error\n\t\t\t\tnavigationTexts.loading = state.navigation.texts.loading;\n\t\t\t}\n\t\t\t// @ts-expect-error\n\t\t\tif ( state.navigation.texts?.loaded ) {\n\t\t\t\t// @ts-expect-error\n\t\t\t\tnavigationTexts.loaded = state.navigation.texts.loaded;\n\t\t\t}\n\t\t}\n\t}\n\n\tconst message = navigationTexts[ messageKey ];\n\n\timport( '@wordpress/a11y' ).then(\n\t\t( { speak } ) => speak( message ),\n\t\t// Ignore failures to load the a11y module.\n\t\t() => {}\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,OAAO,aAAa,iBAAiB;AAK9C,SAAS,eAAe,mBAA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OAAO,SAAS;AAUzC,SAAS,UAAW,YAA2C;AAC9D,MAAK,CAAE,8BAA+B;AACrC,mCAA+B;AAC/B,UAAM,UAAU,SAAS;AAAA,MACxB;AAAA,IACD,GAAG;AACH,QAAK,SAAU;AACd,UAAI;AACH,cAAM,SAAS,KAAK,MAAO,OAAQ;AACnC,YAAK,OAAO,QAAQ,MAAM,YAAY,UAAW;AAChD,0BAAgB,UAAU,OAAO,KAAK;AAAA,QACvC;AACA,YAAK,OAAO,QAAQ,MAAM,WAAW,UAAW;AAC/C,0BAAgB,SAAS,OAAO,KAAK;AAAA,QACtC;AAAA,MACD,QAAQ;AAAA,MAAC;AAAA,IACV,OAAO;AAKN,UAAK,MAAM,WAAW,OAAO,SAAU;AAEtC,wBAAgB,UAAU,MAAM,WAAW,MAAM;AAAA,MAClD;AAEA,UAAK,MAAM,WAAW,OAAO,QAAS;AAErC,wBAAgB,SAAS,MAAM,WAAW,MAAM;AAAA,MACjD;AAAA,IACD;AAAA,EACD;AAEA,QAAM,UAAU,gBAAiB,UAAW;AAE5C,SAAQ,iBAAkB,EAAE;AAAA,IAC3B,CAAE,EAAE,MAAM,MAAO,MAAO,OAAQ;AAAA;AAAA,IAEhC,MAAM;AAAA,IAAC;AAAA,EACR;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/interactivity-router",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.44.0",
|
|
4
4
|
"description": "Package that exposes state and actions from the `core/router` store, part of the Interactivity API.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -46,12 +46,12 @@
|
|
|
46
46
|
},
|
|
47
47
|
"types": "build-types",
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@wordpress/a11y": "^4.
|
|
50
|
-
"@wordpress/interactivity": "^6.
|
|
49
|
+
"@wordpress/a11y": "^4.44.0",
|
|
50
|
+
"@wordpress/interactivity": "^6.44.0",
|
|
51
51
|
"es-module-lexer": "^1.5.4"
|
|
52
52
|
},
|
|
53
53
|
"publishConfig": {
|
|
54
54
|
"access": "public"
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "b862d8c84121a47bbeff882f6c87e61681ce2e0d"
|
|
57
57
|
}
|
package/src/index.ts
CHANGED
|
@@ -90,7 +90,7 @@ const parseRegionAttribute = ( region: Element ) => {
|
|
|
90
90
|
try {
|
|
91
91
|
const { id, attachTo } = JSON.parse( value );
|
|
92
92
|
return { id, attachTo };
|
|
93
|
-
} catch
|
|
93
|
+
} catch {
|
|
94
94
|
return { id: value };
|
|
95
95
|
}
|
|
96
96
|
};
|
|
@@ -169,7 +169,7 @@ const fetchPage = async ( url: string, { html }: { html: string } ) => {
|
|
|
169
169
|
}
|
|
170
170
|
const dom = new window.DOMParser().parseFromString( html, 'text/html' );
|
|
171
171
|
return await preparePage( url, dom );
|
|
172
|
-
} catch
|
|
172
|
+
} catch {
|
|
173
173
|
return false;
|
|
174
174
|
}
|
|
175
175
|
};
|