@wordpress/interactivity-router 1.0.1 → 1.1.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 +6 -0
- package/build/index.js +116 -39
- package/build/index.js.map +1 -1
- package/build-module/index.js +112 -36
- package/build-module/index.js.map +1 -1
- package/build-types/index.d.ts +19 -15
- package/build-types/index.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/index.js +112 -40
- package/tsconfig.tsbuildinfo +1 -1
package/CHANGELOG.md
CHANGED
package/build/index.js
CHANGED
|
@@ -9,12 +9,20 @@ var _interactivity = require("@wordpress/interactivity");
|
|
|
9
9
|
* WordPress dependencies
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
+
const {
|
|
13
|
+
directivePrefix,
|
|
14
|
+
getRegionRootFragment,
|
|
15
|
+
initialVdom,
|
|
16
|
+
toVdom,
|
|
17
|
+
render
|
|
18
|
+
} = (0, _interactivity.privateApis)('I acknowledge that using private APIs means my theme or plugin will inevitably break in the next version of WordPress.');
|
|
19
|
+
|
|
12
20
|
// The cache of visited and prefetched pages.
|
|
13
21
|
const pages = new Map();
|
|
14
22
|
|
|
15
23
|
// Helper to remove domain and hash from the URL. We are only interesting in
|
|
16
24
|
// caching the path and the query.
|
|
17
|
-
const
|
|
25
|
+
const getPagePath = url => {
|
|
18
26
|
const u = new URL(url, window.location);
|
|
19
27
|
return u.pathname + u.search;
|
|
20
28
|
};
|
|
@@ -38,12 +46,14 @@ const fetchPage = async (url, {
|
|
|
38
46
|
|
|
39
47
|
// Return an object with VDOM trees of those HTML regions marked with a
|
|
40
48
|
// `router-region` directive.
|
|
41
|
-
const regionsToVdom = dom
|
|
49
|
+
const regionsToVdom = (dom, {
|
|
50
|
+
vdom
|
|
51
|
+
} = {}) => {
|
|
42
52
|
const regions = {};
|
|
43
|
-
const attrName = `data-${
|
|
53
|
+
const attrName = `data-${directivePrefix}-router-region`;
|
|
44
54
|
dom.querySelectorAll(`[${attrName}]`).forEach(region => {
|
|
45
55
|
const id = region.getAttribute(attrName);
|
|
46
|
-
regions[id] = (
|
|
56
|
+
regions[id] = vdom?.has(region) ? vdom.get(region) : toVdom(region);
|
|
47
57
|
});
|
|
48
58
|
const title = dom.querySelector('title')?.innerText;
|
|
49
59
|
return {
|
|
@@ -54,38 +64,65 @@ const regionsToVdom = dom => {
|
|
|
54
64
|
|
|
55
65
|
// Render all interactive regions contained in the given page.
|
|
56
66
|
const renderRegions = page => {
|
|
57
|
-
const attrName = `data-${
|
|
67
|
+
const attrName = `data-${directivePrefix}-router-region`;
|
|
58
68
|
document.querySelectorAll(`[${attrName}]`).forEach(region => {
|
|
59
69
|
const id = region.getAttribute(attrName);
|
|
60
|
-
const fragment =
|
|
61
|
-
|
|
70
|
+
const fragment = getRegionRootFragment(region);
|
|
71
|
+
render(page.regions[id], fragment);
|
|
62
72
|
});
|
|
63
73
|
if (page.title) {
|
|
64
74
|
document.title = page.title;
|
|
65
75
|
}
|
|
66
76
|
};
|
|
67
77
|
|
|
68
|
-
|
|
69
|
-
|
|
78
|
+
/**
|
|
79
|
+
* Load the given page forcing a full page reload.
|
|
80
|
+
*
|
|
81
|
+
* The function returns a promise that won't resolve, useful to prevent any
|
|
82
|
+
* potential feedback indicating that the navigation has finished while the new
|
|
83
|
+
* page is being loaded.
|
|
84
|
+
*
|
|
85
|
+
* @param {string} href The page href.
|
|
86
|
+
* @return {Promise} Promise that never resolves.
|
|
87
|
+
*/
|
|
88
|
+
const forcePageReload = href => {
|
|
89
|
+
window.location.assign(href);
|
|
90
|
+
return new Promise(() => {});
|
|
91
|
+
};
|
|
70
92
|
|
|
71
93
|
// Listen to the back and forward buttons and restore the page if it's in the
|
|
72
94
|
// cache.
|
|
73
95
|
window.addEventListener('popstate', async () => {
|
|
74
|
-
const
|
|
75
|
-
const page = pages.has(
|
|
96
|
+
const pagePath = getPagePath(window.location); // Remove hash.
|
|
97
|
+
const page = pages.has(pagePath) && (await pages.get(pagePath));
|
|
76
98
|
if (page) {
|
|
77
99
|
renderRegions(page);
|
|
100
|
+
// Update the URL in the state.
|
|
101
|
+
state.url = window.location.href;
|
|
78
102
|
} else {
|
|
79
103
|
window.location.reload();
|
|
80
104
|
}
|
|
81
105
|
});
|
|
82
106
|
|
|
83
|
-
// Cache the
|
|
84
|
-
pages.set(
|
|
107
|
+
// Cache the initial page using the intially parsed vDOM.
|
|
108
|
+
pages.set(getPagePath(window.location), Promise.resolve(regionsToVdom(document, {
|
|
109
|
+
vdom: initialVdom
|
|
110
|
+
})));
|
|
111
|
+
|
|
112
|
+
// Variable to store the current navigation.
|
|
113
|
+
let navigatingTo = '';
|
|
85
114
|
const {
|
|
86
115
|
state,
|
|
87
116
|
actions
|
|
88
117
|
} = (0, _interactivity.store)('core/router', {
|
|
118
|
+
state: {
|
|
119
|
+
url: window.location.href,
|
|
120
|
+
navigation: {
|
|
121
|
+
hasStarted: false,
|
|
122
|
+
hasFinished: false,
|
|
123
|
+
texts: {}
|
|
124
|
+
}
|
|
125
|
+
},
|
|
89
126
|
actions: {
|
|
90
127
|
/**
|
|
91
128
|
* Navigates to the specified page.
|
|
@@ -94,34 +131,55 @@ const {
|
|
|
94
131
|
* needed, and updates any interactive regions whose contents have
|
|
95
132
|
* changed. It also creates a new entry in the browser session history.
|
|
96
133
|
*
|
|
97
|
-
* @param {string} href
|
|
98
|
-
* @param {Object} [options]
|
|
99
|
-
* @param {boolean} [options.force]
|
|
100
|
-
*
|
|
101
|
-
* @param {
|
|
102
|
-
*
|
|
103
|
-
* @param {boolean} [options.
|
|
104
|
-
*
|
|
105
|
-
* history.
|
|
106
|
-
* @param {number} [options.timeout] Time until the navigation is
|
|
107
|
-
* aborted, in milliseconds. Default
|
|
108
|
-
* is 10000.
|
|
134
|
+
* @param {string} href The page href.
|
|
135
|
+
* @param {Object} [options] Options object.
|
|
136
|
+
* @param {boolean} [options.force] If true, it forces re-fetching the URL.
|
|
137
|
+
* @param {string} [options.html] HTML string to be used instead of fetching the requested URL.
|
|
138
|
+
* @param {boolean} [options.replace] If true, it replaces the current entry in the browser session history.
|
|
139
|
+
* @param {number} [options.timeout] Time until the navigation is aborted, in milliseconds. Default is 10000.
|
|
140
|
+
* @param {boolean} [options.loadingAnimation] Whether an animation should be shown while navigating. Default to `true`.
|
|
141
|
+
* @param {boolean} [options.screenReaderAnnouncement] Whether a message for screen readers should be announced while navigating. Default to `true`.
|
|
109
142
|
*
|
|
110
|
-
* @return {Promise} Promise that resolves once the navigation is
|
|
111
|
-
* completed or aborted.
|
|
143
|
+
* @return {Promise} Promise that resolves once the navigation is completed or aborted.
|
|
112
144
|
*/
|
|
113
145
|
*navigate(href, options = {}) {
|
|
114
|
-
const
|
|
146
|
+
const {
|
|
147
|
+
clientNavigationDisabled
|
|
148
|
+
} = (0, _interactivity.getConfig)();
|
|
149
|
+
if (clientNavigationDisabled) {
|
|
150
|
+
yield forcePageReload(href);
|
|
151
|
+
}
|
|
152
|
+
const pagePath = getPagePath(href);
|
|
153
|
+
const {
|
|
154
|
+
navigation
|
|
155
|
+
} = state;
|
|
156
|
+
const {
|
|
157
|
+
loadingAnimation = true,
|
|
158
|
+
screenReaderAnnouncement = true,
|
|
159
|
+
timeout = 10000
|
|
160
|
+
} = options;
|
|
115
161
|
navigatingTo = href;
|
|
116
|
-
actions.prefetch(
|
|
162
|
+
actions.prefetch(pagePath, options);
|
|
117
163
|
|
|
118
164
|
// Create a promise that resolves when the specified timeout ends.
|
|
119
165
|
// The timeout value is 10 seconds by default.
|
|
120
|
-
const timeoutPromise = new Promise(resolve =>
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
166
|
+
const timeoutPromise = new Promise(resolve => setTimeout(resolve, timeout));
|
|
167
|
+
|
|
168
|
+
// Don't update the navigation status immediately, wait 400 ms.
|
|
169
|
+
const loadingTimeout = setTimeout(() => {
|
|
170
|
+
if (navigatingTo !== href) return;
|
|
171
|
+
if (loadingAnimation) {
|
|
172
|
+
navigation.hasStarted = true;
|
|
173
|
+
navigation.hasFinished = false;
|
|
174
|
+
}
|
|
175
|
+
if (screenReaderAnnouncement) {
|
|
176
|
+
navigation.message = navigation.texts.loading;
|
|
177
|
+
}
|
|
178
|
+
}, 400);
|
|
179
|
+
const page = yield Promise.race([pages.get(pagePath), timeoutPromise]);
|
|
180
|
+
|
|
181
|
+
// Dismiss loading message if it hasn't been added yet.
|
|
182
|
+
clearTimeout(loadingTimeout);
|
|
125
183
|
|
|
126
184
|
// Once the page is fetched, the destination URL could have changed
|
|
127
185
|
// (e.g., by clicking another link in the meantime). If so, bail
|
|
@@ -130,9 +188,24 @@ const {
|
|
|
130
188
|
if (page) {
|
|
131
189
|
renderRegions(page);
|
|
132
190
|
window.history[options.replace ? 'replaceState' : 'pushState']({}, '', href);
|
|
191
|
+
|
|
192
|
+
// Update the URL in the state.
|
|
193
|
+
state.url = href;
|
|
194
|
+
|
|
195
|
+
// Update the navigation status once the the new page rendering
|
|
196
|
+
// has been completed.
|
|
197
|
+
if (loadingAnimation) {
|
|
198
|
+
navigation.hasStarted = false;
|
|
199
|
+
navigation.hasFinished = true;
|
|
200
|
+
}
|
|
201
|
+
if (screenReaderAnnouncement) {
|
|
202
|
+
// Announce that the page has been loaded. If the message is the
|
|
203
|
+
// same, we use a no-break space similar to the @wordpress/a11y
|
|
204
|
+
// package: https://github.com/WordPress/gutenberg/blob/c395242b8e6ee20f8b06c199e4fc2920d7018af1/packages/a11y/src/filter-message.js#L20-L26
|
|
205
|
+
navigation.message = navigation.texts.loaded + (navigation.message === navigation.texts.loaded ? '\u00A0' : '');
|
|
206
|
+
}
|
|
133
207
|
} else {
|
|
134
|
-
|
|
135
|
-
yield new Promise(() => {});
|
|
208
|
+
yield forcePageReload(href);
|
|
136
209
|
}
|
|
137
210
|
},
|
|
138
211
|
/**
|
|
@@ -148,9 +221,13 @@ const {
|
|
|
148
221
|
* fetching the requested URL.
|
|
149
222
|
*/
|
|
150
223
|
prefetch(url, options = {}) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
224
|
+
const {
|
|
225
|
+
clientNavigationDisabled
|
|
226
|
+
} = (0, _interactivity.getConfig)();
|
|
227
|
+
if (clientNavigationDisabled) return;
|
|
228
|
+
const pagePath = getPagePath(url);
|
|
229
|
+
if (options.force || !pages.has(pagePath)) {
|
|
230
|
+
pages.set(pagePath, fetchPage(pagePath, options));
|
|
154
231
|
}
|
|
155
232
|
}
|
|
156
233
|
}
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_interactivity","require","pages","Map","cleanUrl","url","u","URL","window","location","pathname","search","fetchPage","html","res","fetch","status","text","dom","DOMParser","parseFromString","regionsToVdom","e","regions","attrName","directivePrefix","querySelectorAll","forEach","region","id","getAttribute","toVdom","title","querySelector","innerText","renderRegions","page","document","fragment","getRegionRootFragment","render","navigatingTo","addEventListener","has","get","reload","set","Promise","resolve","state","actions","store","navigate","href","options","prefetch","timeoutPromise","_options$timeout","setTimeout","timeout","race","history","replace","assign","force","exports"],"sources":["@wordpress/interactivity-router/src/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\trender,\n\tdirectivePrefix,\n\ttoVdom,\n\tgetRegionRootFragment,\n\tstore,\n} from '@wordpress/interactivity';\n\n// The cache of visited and prefetched pages.\nconst pages = new Map();\n\n// Helper to remove domain and hash from the URL. We are only interesting in\n// caching the path and the query.\nconst cleanUrl = ( url ) => {\n\tconst u = new URL( url, window.location );\n\treturn u.pathname + u.search;\n};\n\n// Fetch a new page and convert it to a static virtual DOM.\nconst fetchPage = async ( url, { html } ) => {\n\ttry {\n\t\tif ( ! html ) {\n\t\t\tconst res = await window.fetch( url );\n\t\t\tif ( res.status !== 200 ) return false;\n\t\t\thtml = await res.text();\n\t\t}\n\t\tconst dom = new window.DOMParser().parseFromString( html, 'text/html' );\n\t\treturn regionsToVdom( dom );\n\t} catch ( e ) {\n\t\treturn false;\n\t}\n};\n\n// Return an object with VDOM trees of those HTML regions marked with a\n// `router-region` directive.\nconst regionsToVdom = ( dom ) => {\n\tconst regions = {};\n\tconst attrName = `data-${ directivePrefix }-router-region`;\n\tdom.querySelectorAll( `[${ attrName }]` ).forEach( ( region ) => {\n\t\tconst id = region.getAttribute( attrName );\n\t\tregions[ id ] = toVdom( region );\n\t} );\n\tconst title = dom.querySelector( 'title' )?.innerText;\n\treturn { regions, title };\n};\n\n// Render all interactive regions contained in the given page.\nconst renderRegions = ( page ) => {\n\tconst attrName = `data-${ directivePrefix }-router-region`;\n\tdocument.querySelectorAll( `[${ attrName }]` ).forEach( ( region ) => {\n\t\tconst id = region.getAttribute( attrName );\n\t\tconst fragment = getRegionRootFragment( region );\n\t\trender( page.regions[ id ], fragment );\n\t} );\n\tif ( page.title ) {\n\t\tdocument.title = page.title;\n\t}\n};\n\n// Variable to store the current navigation.\nlet navigatingTo = '';\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 url = cleanUrl( window.location ); // Remove hash.\n\tconst page = pages.has( url ) && ( await pages.get( url ) );\n\tif ( page ) {\n\t\trenderRegions( page );\n\t} else {\n\t\twindow.location.reload();\n\t}\n} );\n\n// Cache the current regions.\npages.set(\n\tcleanUrl( window.location ),\n\tPromise.resolve( regionsToVdom( document ) )\n);\n\nexport const { state, actions } = store( 'core/router', {\n\tactions: {\n\t\t/**\n\t\t * Navigates to the specified page.\n\t\t *\n\t\t * This function normalizes the passed href, fetchs the page HTML if\n\t\t * needed, and updates any interactive regions whose contents have\n\t\t * changed. It also creates a new entry in the browser session history.\n\t\t *\n\t\t * @param {string} href The page href.\n\t\t * @param {Object} [options] Options object.\n\t\t * @param {boolean} [options.force] If true, it forces re-fetching the\n\t\t * URL.\n\t\t * @param {string} [options.html] HTML string to be used instead of\n\t\t * fetching the requested URL.\n\t\t * @param {boolean} [options.replace] If true, it replaces the current\n\t\t * entry in the browser session\n\t\t * history.\n\t\t * @param {number} [options.timeout] Time until the navigation is\n\t\t * aborted, in milliseconds. Default\n\t\t * is 10000.\n\t\t *\n\t\t * @return {Promise} Promise that resolves once the navigation is\n\t\t * completed or aborted.\n\t\t */\n\t\t*navigate( href, options = {} ) {\n\t\t\tconst url = cleanUrl( href );\n\t\t\tnavigatingTo = href;\n\t\t\tactions.prefetch( url, options );\n\n\t\t\t// Create a promise that resolves when the specified timeout ends.\n\t\t\t// The timeout value is 10 seconds by default.\n\t\t\tconst timeoutPromise = new Promise( ( resolve ) =>\n\t\t\t\tsetTimeout( resolve, options.timeout ?? 10000 )\n\t\t\t);\n\n\t\t\tconst page = yield Promise.race( [\n\t\t\t\tpages.get( url ),\n\t\t\t\ttimeoutPromise,\n\t\t\t] );\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 ) return;\n\n\t\t\tif ( page ) {\n\t\t\t\trenderRegions( page );\n\t\t\t\twindow.history[\n\t\t\t\t\toptions.replace ? 'replaceState' : 'pushState'\n\t\t\t\t]( {}, '', href );\n\t\t\t} else {\n\t\t\t\twindow.location.assign( href );\n\t\t\t\tyield new Promise( () => {} );\n\t\t\t}\n\t\t},\n\n\t\t/**\n\t\t * Prefetchs the page with the passed URL.\n\t\t *\n\t\t * The function normalizes the URL and stores internally the fetch\n\t\t * promise, to avoid triggering a second fetch for an ongoing request.\n\t\t *\n\t\t * @param {string} url The page URL.\n\t\t * @param {Object} [options] Options object.\n\t\t * @param {boolean} [options.force] Force fetching the URL again.\n\t\t * @param {string} [options.html] HTML string to be used instead of\n\t\t * fetching the requested URL.\n\t\t */\n\t\tprefetch( url, options = {} ) {\n\t\t\turl = cleanUrl( url );\n\t\t\tif ( options.force || ! pages.has( url ) ) {\n\t\t\t\tpages.set( url, fetchPage( url, options ) );\n\t\t\t}\n\t\t},\n\t},\n} );\n"],"mappings":";;;;;;AAGA,IAAAA,cAAA,G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;AACA;AACA;AACA;AACA;IACEQ,QAAQA,CAAElD,GAAG,EAAEiD,OAAO,GAAG,CAAC,CAAC,EAAG;MAC7BjD,GAAG,GAAGD,QAAQ,CAAEC,GAAI,CAAC;MACrB,IAAKiD,OAAO,CAACU,KAAK,IAAI,CAAE9D,KAAK,CAACyC,GAAG,CAAEtC,GAAI,CAAC,EAAG;QAC1CH,KAAK,CAAC4C,GAAG,CAAEzC,GAAG,EAAEO,SAAS,CAAEP,GAAG,EAAEiD,OAAQ,CAAE,CAAC;MAC5C;IACD;EACD;AACD,CAAE,CAAC;AAACW,OAAA,CAAAf,OAAA,GAAAA,OAAA;AAAAe,OAAA,CAAAhB,KAAA,GAAAA,KAAA"}
|
|
1
|
+
{"version":3,"names":["_interactivity","require","directivePrefix","getRegionRootFragment","initialVdom","toVdom","render","privateApis","pages","Map","getPagePath","url","u","URL","window","location","pathname","search","fetchPage","html","res","fetch","status","text","dom","DOMParser","parseFromString","regionsToVdom","e","vdom","regions","attrName","querySelectorAll","forEach","region","id","getAttribute","has","get","title","querySelector","innerText","renderRegions","page","document","fragment","forcePageReload","href","assign","Promise","addEventListener","pagePath","state","reload","set","resolve","navigatingTo","actions","store","navigation","hasStarted","hasFinished","texts","navigate","options","clientNavigationDisabled","getConfig","loadingAnimation","screenReaderAnnouncement","timeout","prefetch","timeoutPromise","setTimeout","loadingTimeout","message","loading","race","clearTimeout","history","replace","loaded","force","exports"],"sources":["@wordpress/interactivity-router/src/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { store, privateApis, getConfig } from '@wordpress/interactivity';\n\nconst { directivePrefix, getRegionRootFragment, initialVdom, toVdom, render } =\n\tprivateApis(\n\t\t'I acknowledge that using private APIs means my theme or plugin will inevitably break in the next version of WordPress.'\n\t);\n\n// The cache of visited and prefetched pages.\nconst pages = new Map();\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 ) => {\n\tconst u = new URL( url, window.location );\n\treturn u.pathname + u.search;\n};\n\n// Fetch a new page and convert it to a static virtual DOM.\nconst fetchPage = async ( url, { html } ) => {\n\ttry {\n\t\tif ( ! html ) {\n\t\t\tconst res = await window.fetch( url );\n\t\t\tif ( res.status !== 200 ) return false;\n\t\t\thtml = await res.text();\n\t\t}\n\t\tconst dom = new window.DOMParser().parseFromString( html, 'text/html' );\n\t\treturn regionsToVdom( dom );\n\t} catch ( e ) {\n\t\treturn false;\n\t}\n};\n\n// Return an object with VDOM trees of those HTML regions marked with a\n// `router-region` directive.\nconst regionsToVdom = ( dom, { vdom } = {} ) => {\n\tconst regions = {};\n\tconst attrName = `data-${ directivePrefix }-router-region`;\n\tdom.querySelectorAll( `[${ attrName }]` ).forEach( ( region ) => {\n\t\tconst id = region.getAttribute( attrName );\n\t\tregions[ id ] = vdom?.has( region )\n\t\t\t? vdom.get( region )\n\t\t\t: toVdom( region );\n\t} );\n\tconst title = dom.querySelector( 'title' )?.innerText;\n\treturn { regions, title };\n};\n\n// Render all interactive regions contained in the given page.\nconst renderRegions = ( page ) => {\n\tconst attrName = `data-${ directivePrefix }-router-region`;\n\tdocument.querySelectorAll( `[${ attrName }]` ).forEach( ( region ) => {\n\t\tconst id = region.getAttribute( attrName );\n\t\tconst fragment = getRegionRootFragment( region );\n\t\trender( page.regions[ id ], fragment );\n\t} );\n\tif ( page.title ) {\n\t\tdocument.title = page.title;\n\t}\n};\n\n/**\n * Load the given page forcing a full page reload.\n *\n * The function returns a promise that won't resolve, useful to prevent any\n * potential feedback indicating that the navigation has finished while the new\n * page is being loaded.\n *\n * @param {string} href The page href.\n * @return {Promise} Promise that never resolves.\n */\nconst forcePageReload = ( href ) => {\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 ); // Remove hash.\n\tconst page = pages.has( pagePath ) && ( await pages.get( pagePath ) );\n\tif ( page ) {\n\t\trenderRegions( page );\n\t\t// Update the URL in the state.\n\t\tstate.url = window.location.href;\n\t} else {\n\t\twindow.location.reload();\n\t}\n} );\n\n// Cache the initial page using the intially parsed vDOM.\npages.set(\n\tgetPagePath( window.location ),\n\tPromise.resolve( regionsToVdom( document, { vdom: initialVdom } ) )\n);\n\n// Variable to store the current navigation.\nlet navigatingTo = '';\n\nexport const { state, actions } = store( 'core/router', {\n\tstate: {\n\t\turl: window.location.href,\n\t\tnavigation: {\n\t\t\thasStarted: false,\n\t\t\thasFinished: false,\n\t\t\ttexts: {},\n\t\t},\n\t},\n\tactions: {\n\t\t/**\n\t\t * Navigates to the specified page.\n\t\t *\n\t\t * This function normalizes the passed href, fetchs the page HTML if\n\t\t * needed, and updates any interactive regions whose contents have\n\t\t * changed. It also creates a new entry in the browser session history.\n\t\t *\n\t\t * @param {string} href The page href.\n\t\t * @param {Object} [options] Options object.\n\t\t * @param {boolean} [options.force] If true, it forces re-fetching the URL.\n\t\t * @param {string} [options.html] HTML string to be used instead of fetching the requested URL.\n\t\t * @param {boolean} [options.replace] If true, it replaces the current entry in the browser session history.\n\t\t * @param {number} [options.timeout] Time until the navigation is aborted, in milliseconds. Default is 10000.\n\t\t * @param {boolean} [options.loadingAnimation] Whether an animation should be shown while navigating. Default to `true`.\n\t\t * @param {boolean} [options.screenReaderAnnouncement] Whether a message for screen readers should be announced while navigating. Default to `true`.\n\t\t *\n\t\t * @return {Promise} Promise that resolves once the navigation is completed or aborted.\n\t\t */\n\t\t*navigate( href, options = {} ) {\n\t\t\tconst { clientNavigationDisabled } = getConfig();\n\t\t\tif ( clientNavigationDisabled ) {\n\t\t\t\tyield forcePageReload( href );\n\t\t\t}\n\n\t\t\tconst pagePath = getPagePath( href );\n\t\t\tconst { navigation } = state;\n\t\t\tconst {\n\t\t\t\tloadingAnimation = true,\n\t\t\t\tscreenReaderAnnouncement = true,\n\t\t\t\ttimeout = 10000,\n\t\t\t} = options;\n\n\t\t\tnavigatingTo = href;\n\t\t\tactions.prefetch( pagePath, options );\n\n\t\t\t// Create a promise that resolves when the specified timeout ends.\n\t\t\t// The timeout value is 10 seconds by default.\n\t\t\tconst timeoutPromise = new Promise( ( resolve ) =>\n\t\t\t\tsetTimeout( resolve, timeout )\n\t\t\t);\n\n\t\t\t// Don't update the navigation status immediately, wait 400 ms.\n\t\t\tconst loadingTimeout = setTimeout( () => {\n\t\t\t\tif ( navigatingTo !== href ) return;\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\tnavigation.message = navigation.texts.loading;\n\t\t\t\t}\n\t\t\t}, 400 );\n\n\t\t\tconst page = yield Promise.race( [\n\t\t\t\tpages.get( pagePath ),\n\t\t\t\ttimeoutPromise,\n\t\t\t] );\n\n\t\t\t// Dismiss loading message if it hasn't been added yet.\n\t\t\tclearTimeout( loadingTimeout );\n\n\t\t\t// Once the page is fetched, the destination URL could have changed\n\t\t\t// (e.g., by clicking another link in the meantime). If so, bail\n\t\t\t// out, and let the newer execution to update the HTML.\n\t\t\tif ( navigatingTo !== href ) return;\n\n\t\t\tif ( page ) {\n\t\t\t\trenderRegions( page );\n\t\t\t\twindow.history[\n\t\t\t\t\toptions.replace ? 'replaceState' : 'pushState'\n\t\t\t\t]( {}, '', href );\n\n\t\t\t\t// Update the URL in the state.\n\t\t\t\tstate.url = href;\n\n\t\t\t\t// Update the navigation status once the the new page rendering\n\t\t\t\t// has been completed.\n\t\t\t\tif ( loadingAnimation ) {\n\t\t\t\t\tnavigation.hasStarted = false;\n\t\t\t\t\tnavigation.hasFinished = true;\n\t\t\t\t}\n\n\t\t\t\tif ( screenReaderAnnouncement ) {\n\t\t\t\t\t// Announce that the page has been loaded. If the message is the\n\t\t\t\t\t// same, we use a no-break space similar to the @wordpress/a11y\n\t\t\t\t\t// package: https://github.com/WordPress/gutenberg/blob/c395242b8e6ee20f8b06c199e4fc2920d7018af1/packages/a11y/src/filter-message.js#L20-L26\n\t\t\t\t\tnavigation.message =\n\t\t\t\t\t\tnavigation.texts.loaded +\n\t\t\t\t\t\t( navigation.message === navigation.texts.loaded\n\t\t\t\t\t\t\t? '\\u00A0'\n\t\t\t\t\t\t\t: '' );\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tyield forcePageReload( href );\n\t\t\t}\n\t\t},\n\n\t\t/**\n\t\t * Prefetchs the page with the passed URL.\n\t\t *\n\t\t * The function normalizes the URL and stores internally the fetch\n\t\t * promise, to avoid triggering a second fetch for an ongoing request.\n\t\t *\n\t\t * @param {string} url The page URL.\n\t\t * @param {Object} [options] Options object.\n\t\t * @param {boolean} [options.force] Force fetching the URL again.\n\t\t * @param {string} [options.html] HTML string to be used instead of\n\t\t * fetching the requested URL.\n\t\t */\n\t\tprefetch( url, options = {} ) {\n\t\t\tconst { clientNavigationDisabled } = getConfig();\n\t\t\tif ( clientNavigationDisabled ) return;\n\n\t\t\tconst pagePath = getPagePath( url );\n\t\t\tif ( options.force || ! pages.has( pagePath ) ) {\n\t\t\t\tpages.set( pagePath, fetchPage( pagePath, options ) );\n\t\t\t}\n\t\t},\n\t},\n} );\n"],"mappings":";;;;;;AAGA,IAAAA,cAAA,GAAAC,OAAA;AAHA;AACA;AACA;;AAGA,MAAM;EAAEC,eAAe;EAAEC,qBAAqB;EAAEC,WAAW;EAAEC,MAAM;EAAEC;AAAO,CAAC,GAC5E,IAAAC,0BAAW,EACV,wHACD,CAAC;;AAEF;AACA,MAAMC,KAAK,GAAG,IAAIC,GAAG,CAAC,CAAC;;AAEvB;AACA;AACA,MAAMC,WAAW,GAAKC,GAAG,IAAM;EAC9B,MAAMC,CAAC,GAAG,IAAIC,GAAG,CAAEF,GAAG,EAAEG,MAAM,CAACC,QAAS,CAAC;EACzC,OAAOH,CAAC,CAACI,QAAQ,GAAGJ,CAAC,CAACK,MAAM;AAC7B,CAAC;;AAED;AACA,MAAMC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AEqD,OAAO,GAAG,CAAC,CAAC,EAAG;MAC7B,MAAM;QAAEC;MAAyB,CAAC,GAAG,IAAAC,wBAAS,EAAC,CAAC;MAChD,IAAKD,wBAAwB,EAAG;MAEhC,MAAMd,QAAQ,GAAGzC,WAAW,CAAEC,GAAI,CAAC;MACnC,IAAKqD,OAAO,CAACiB,KAAK,IAAI,CAAEzE,KAAK,CAAC6B,GAAG,CAAEc,QAAS,CAAC,EAAG;QAC/C3C,KAAK,CAAC8C,GAAG,CAAEH,QAAQ,EAAEjC,SAAS,CAAEiC,QAAQ,EAAEa,OAAQ,CAAE,CAAC;MACtD;IACD;EACD;AACD,CAAE,CAAC;AAACkB,OAAA,CAAAzB,OAAA,GAAAA,OAAA;AAAAyB,OAAA,CAAA9B,KAAA,GAAAA,KAAA"}
|
package/build-module/index.js
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import { store, privateApis, getConfig } from '@wordpress/interactivity';
|
|
5
|
+
const {
|
|
6
|
+
directivePrefix,
|
|
7
|
+
getRegionRootFragment,
|
|
8
|
+
initialVdom,
|
|
9
|
+
toVdom,
|
|
10
|
+
render
|
|
11
|
+
} = privateApis('I acknowledge that using private APIs means my theme or plugin will inevitably break in the next version of WordPress.');
|
|
5
12
|
|
|
6
13
|
// The cache of visited and prefetched pages.
|
|
7
14
|
const pages = new Map();
|
|
8
15
|
|
|
9
16
|
// Helper to remove domain and hash from the URL. We are only interesting in
|
|
10
17
|
// caching the path and the query.
|
|
11
|
-
const
|
|
18
|
+
const getPagePath = url => {
|
|
12
19
|
const u = new URL(url, window.location);
|
|
13
20
|
return u.pathname + u.search;
|
|
14
21
|
};
|
|
@@ -32,12 +39,14 @@ const fetchPage = async (url, {
|
|
|
32
39
|
|
|
33
40
|
// Return an object with VDOM trees of those HTML regions marked with a
|
|
34
41
|
// `router-region` directive.
|
|
35
|
-
const regionsToVdom = dom
|
|
42
|
+
const regionsToVdom = (dom, {
|
|
43
|
+
vdom
|
|
44
|
+
} = {}) => {
|
|
36
45
|
const regions = {};
|
|
37
46
|
const attrName = `data-${directivePrefix}-router-region`;
|
|
38
47
|
dom.querySelectorAll(`[${attrName}]`).forEach(region => {
|
|
39
48
|
const id = region.getAttribute(attrName);
|
|
40
|
-
regions[id] = toVdom(region);
|
|
49
|
+
regions[id] = vdom?.has(region) ? vdom.get(region) : toVdom(region);
|
|
41
50
|
});
|
|
42
51
|
const title = dom.querySelector('title')?.innerText;
|
|
43
52
|
return {
|
|
@@ -59,27 +68,54 @@ const renderRegions = page => {
|
|
|
59
68
|
}
|
|
60
69
|
};
|
|
61
70
|
|
|
62
|
-
|
|
63
|
-
|
|
71
|
+
/**
|
|
72
|
+
* Load the given page forcing a full page reload.
|
|
73
|
+
*
|
|
74
|
+
* The function returns a promise that won't resolve, useful to prevent any
|
|
75
|
+
* potential feedback indicating that the navigation has finished while the new
|
|
76
|
+
* page is being loaded.
|
|
77
|
+
*
|
|
78
|
+
* @param {string} href The page href.
|
|
79
|
+
* @return {Promise} Promise that never resolves.
|
|
80
|
+
*/
|
|
81
|
+
const forcePageReload = href => {
|
|
82
|
+
window.location.assign(href);
|
|
83
|
+
return new Promise(() => {});
|
|
84
|
+
};
|
|
64
85
|
|
|
65
86
|
// Listen to the back and forward buttons and restore the page if it's in the
|
|
66
87
|
// cache.
|
|
67
88
|
window.addEventListener('popstate', async () => {
|
|
68
|
-
const
|
|
69
|
-
const page = pages.has(
|
|
89
|
+
const pagePath = getPagePath(window.location); // Remove hash.
|
|
90
|
+
const page = pages.has(pagePath) && (await pages.get(pagePath));
|
|
70
91
|
if (page) {
|
|
71
92
|
renderRegions(page);
|
|
93
|
+
// Update the URL in the state.
|
|
94
|
+
state.url = window.location.href;
|
|
72
95
|
} else {
|
|
73
96
|
window.location.reload();
|
|
74
97
|
}
|
|
75
98
|
});
|
|
76
99
|
|
|
77
|
-
// Cache the
|
|
78
|
-
pages.set(
|
|
100
|
+
// Cache the initial page using the intially parsed vDOM.
|
|
101
|
+
pages.set(getPagePath(window.location), Promise.resolve(regionsToVdom(document, {
|
|
102
|
+
vdom: initialVdom
|
|
103
|
+
})));
|
|
104
|
+
|
|
105
|
+
// Variable to store the current navigation.
|
|
106
|
+
let navigatingTo = '';
|
|
79
107
|
export const {
|
|
80
108
|
state,
|
|
81
109
|
actions
|
|
82
110
|
} = store('core/router', {
|
|
111
|
+
state: {
|
|
112
|
+
url: window.location.href,
|
|
113
|
+
navigation: {
|
|
114
|
+
hasStarted: false,
|
|
115
|
+
hasFinished: false,
|
|
116
|
+
texts: {}
|
|
117
|
+
}
|
|
118
|
+
},
|
|
83
119
|
actions: {
|
|
84
120
|
/**
|
|
85
121
|
* Navigates to the specified page.
|
|
@@ -88,34 +124,55 @@ export const {
|
|
|
88
124
|
* needed, and updates any interactive regions whose contents have
|
|
89
125
|
* changed. It also creates a new entry in the browser session history.
|
|
90
126
|
*
|
|
91
|
-
* @param {string} href
|
|
92
|
-
* @param {Object} [options]
|
|
93
|
-
* @param {boolean} [options.force]
|
|
94
|
-
*
|
|
95
|
-
* @param {
|
|
96
|
-
*
|
|
97
|
-
* @param {boolean} [options.
|
|
98
|
-
*
|
|
99
|
-
* history.
|
|
100
|
-
* @param {number} [options.timeout] Time until the navigation is
|
|
101
|
-
* aborted, in milliseconds. Default
|
|
102
|
-
* is 10000.
|
|
127
|
+
* @param {string} href The page href.
|
|
128
|
+
* @param {Object} [options] Options object.
|
|
129
|
+
* @param {boolean} [options.force] If true, it forces re-fetching the URL.
|
|
130
|
+
* @param {string} [options.html] HTML string to be used instead of fetching the requested URL.
|
|
131
|
+
* @param {boolean} [options.replace] If true, it replaces the current entry in the browser session history.
|
|
132
|
+
* @param {number} [options.timeout] Time until the navigation is aborted, in milliseconds. Default is 10000.
|
|
133
|
+
* @param {boolean} [options.loadingAnimation] Whether an animation should be shown while navigating. Default to `true`.
|
|
134
|
+
* @param {boolean} [options.screenReaderAnnouncement] Whether a message for screen readers should be announced while navigating. Default to `true`.
|
|
103
135
|
*
|
|
104
|
-
* @return {Promise} Promise that resolves once the navigation is
|
|
105
|
-
* completed or aborted.
|
|
136
|
+
* @return {Promise} Promise that resolves once the navigation is completed or aborted.
|
|
106
137
|
*/
|
|
107
138
|
*navigate(href, options = {}) {
|
|
108
|
-
const
|
|
139
|
+
const {
|
|
140
|
+
clientNavigationDisabled
|
|
141
|
+
} = getConfig();
|
|
142
|
+
if (clientNavigationDisabled) {
|
|
143
|
+
yield forcePageReload(href);
|
|
144
|
+
}
|
|
145
|
+
const pagePath = getPagePath(href);
|
|
146
|
+
const {
|
|
147
|
+
navigation
|
|
148
|
+
} = state;
|
|
149
|
+
const {
|
|
150
|
+
loadingAnimation = true,
|
|
151
|
+
screenReaderAnnouncement = true,
|
|
152
|
+
timeout = 10000
|
|
153
|
+
} = options;
|
|
109
154
|
navigatingTo = href;
|
|
110
|
-
actions.prefetch(
|
|
155
|
+
actions.prefetch(pagePath, options);
|
|
111
156
|
|
|
112
157
|
// Create a promise that resolves when the specified timeout ends.
|
|
113
158
|
// The timeout value is 10 seconds by default.
|
|
114
|
-
const timeoutPromise = new Promise(resolve =>
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
159
|
+
const timeoutPromise = new Promise(resolve => setTimeout(resolve, timeout));
|
|
160
|
+
|
|
161
|
+
// Don't update the navigation status immediately, wait 400 ms.
|
|
162
|
+
const loadingTimeout = setTimeout(() => {
|
|
163
|
+
if (navigatingTo !== href) return;
|
|
164
|
+
if (loadingAnimation) {
|
|
165
|
+
navigation.hasStarted = true;
|
|
166
|
+
navigation.hasFinished = false;
|
|
167
|
+
}
|
|
168
|
+
if (screenReaderAnnouncement) {
|
|
169
|
+
navigation.message = navigation.texts.loading;
|
|
170
|
+
}
|
|
171
|
+
}, 400);
|
|
172
|
+
const page = yield Promise.race([pages.get(pagePath), timeoutPromise]);
|
|
173
|
+
|
|
174
|
+
// Dismiss loading message if it hasn't been added yet.
|
|
175
|
+
clearTimeout(loadingTimeout);
|
|
119
176
|
|
|
120
177
|
// Once the page is fetched, the destination URL could have changed
|
|
121
178
|
// (e.g., by clicking another link in the meantime). If so, bail
|
|
@@ -124,9 +181,24 @@ export const {
|
|
|
124
181
|
if (page) {
|
|
125
182
|
renderRegions(page);
|
|
126
183
|
window.history[options.replace ? 'replaceState' : 'pushState']({}, '', href);
|
|
184
|
+
|
|
185
|
+
// Update the URL in the state.
|
|
186
|
+
state.url = href;
|
|
187
|
+
|
|
188
|
+
// Update the navigation status once the the new page rendering
|
|
189
|
+
// has been completed.
|
|
190
|
+
if (loadingAnimation) {
|
|
191
|
+
navigation.hasStarted = false;
|
|
192
|
+
navigation.hasFinished = true;
|
|
193
|
+
}
|
|
194
|
+
if (screenReaderAnnouncement) {
|
|
195
|
+
// Announce that the page has been loaded. If the message is the
|
|
196
|
+
// same, we use a no-break space similar to the @wordpress/a11y
|
|
197
|
+
// package: https://github.com/WordPress/gutenberg/blob/c395242b8e6ee20f8b06c199e4fc2920d7018af1/packages/a11y/src/filter-message.js#L20-L26
|
|
198
|
+
navigation.message = navigation.texts.loaded + (navigation.message === navigation.texts.loaded ? '\u00A0' : '');
|
|
199
|
+
}
|
|
127
200
|
} else {
|
|
128
|
-
|
|
129
|
-
yield new Promise(() => {});
|
|
201
|
+
yield forcePageReload(href);
|
|
130
202
|
}
|
|
131
203
|
},
|
|
132
204
|
/**
|
|
@@ -142,9 +214,13 @@ export const {
|
|
|
142
214
|
* fetching the requested URL.
|
|
143
215
|
*/
|
|
144
216
|
prefetch(url, options = {}) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
217
|
+
const {
|
|
218
|
+
clientNavigationDisabled
|
|
219
|
+
} = getConfig();
|
|
220
|
+
if (clientNavigationDisabled) return;
|
|
221
|
+
const pagePath = getPagePath(url);
|
|
222
|
+
if (options.force || !pages.has(pagePath)) {
|
|
223
|
+
pages.set(pagePath, fetchPage(pagePath, options));
|
|
148
224
|
}
|
|
149
225
|
}
|
|
150
226
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["render","directivePrefix","toVdom","getRegionRootFragment","store","pages","Map","cleanUrl","url","u","URL","window","location","pathname","search","fetchPage","html","res","fetch","status","text","dom","DOMParser","parseFromString","regionsToVdom","e","regions","attrName","querySelectorAll","forEach","region","id","getAttribute","title","querySelector","innerText","renderRegions","page","document","fragment","navigatingTo","addEventListener","has","get","reload","set","Promise","resolve","state","actions","navigate","href","options","prefetch","timeoutPromise","_options$timeout","setTimeout","timeout","race","history","replace","assign","force"],"sources":["@wordpress/interactivity-router/src/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\trender,\n\tdirectivePrefix,\n\ttoVdom,\n\tgetRegionRootFragment,\n\tstore,\n} from '@wordpress/interactivity';\n\n// The cache of visited and prefetched pages.\nconst pages = new Map();\n\n// Helper to remove domain and hash from the URL. We are only interesting in\n// caching the path and the query.\nconst cleanUrl = ( url ) => {\n\tconst u = new URL( url, window.location );\n\treturn u.pathname + u.search;\n};\n\n// Fetch a new page and convert it to a static virtual DOM.\nconst fetchPage = async ( url, { html } ) => {\n\ttry {\n\t\tif ( ! html ) {\n\t\t\tconst res = await window.fetch( url );\n\t\t\tif ( res.status !== 200 ) return false;\n\t\t\thtml = await res.text();\n\t\t}\n\t\tconst dom = new window.DOMParser().parseFromString( html, 'text/html' );\n\t\treturn regionsToVdom( dom );\n\t} catch ( e ) {\n\t\treturn false;\n\t}\n};\n\n// Return an object with VDOM trees of those HTML regions marked with a\n// `router-region` directive.\nconst regionsToVdom = ( dom ) => {\n\tconst regions = {};\n\tconst attrName = `data-${ directivePrefix }-router-region`;\n\tdom.querySelectorAll( `[${ attrName }]` ).forEach( ( region ) => {\n\t\tconst id = region.getAttribute( attrName );\n\t\tregions[ id ] = toVdom( region );\n\t} );\n\tconst title = dom.querySelector( 'title' )?.innerText;\n\treturn { regions, title };\n};\n\n// Render all interactive regions contained in the given page.\nconst renderRegions = ( page ) => {\n\tconst attrName = `data-${ directivePrefix }-router-region`;\n\tdocument.querySelectorAll( `[${ attrName }]` ).forEach( ( region ) => {\n\t\tconst id = region.getAttribute( attrName );\n\t\tconst fragment = getRegionRootFragment( region );\n\t\trender( page.regions[ id ], fragment );\n\t} );\n\tif ( page.title ) {\n\t\tdocument.title = page.title;\n\t}\n};\n\n// Variable to store the current navigation.\nlet navigatingTo = '';\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 url = cleanUrl( window.location ); // Remove hash.\n\tconst page = pages.has( url ) && ( await pages.get( url ) );\n\tif ( page ) {\n\t\trenderRegions( page );\n\t} else {\n\t\twindow.location.reload();\n\t}\n} );\n\n// Cache the current regions.\npages.set(\n\tcleanUrl( window.location ),\n\tPromise.resolve( regionsToVdom( document ) )\n);\n\nexport const { state, actions } = store( 'core/router', {\n\tactions: {\n\t\t/**\n\t\t * Navigates to the specified page.\n\t\t *\n\t\t * This function normalizes the passed href, fetchs the page HTML if\n\t\t * needed, and updates any interactive regions whose contents have\n\t\t * changed. It also creates a new entry in the browser session history.\n\t\t *\n\t\t * @param {string} href The page href.\n\t\t * @param {Object} [options] Options object.\n\t\t * @param {boolean} [options.force] If true, it forces re-fetching the\n\t\t * URL.\n\t\t * @param {string} [options.html] HTML string to be used instead of\n\t\t * fetching the requested URL.\n\t\t * @param {boolean} [options.replace] If true, it replaces the current\n\t\t * entry in the browser session\n\t\t * history.\n\t\t * @param {number} [options.timeout] Time until the navigation is\n\t\t * aborted, in milliseconds. Default\n\t\t * is 10000.\n\t\t *\n\t\t * @return {Promise} Promise that resolves once the navigation is\n\t\t * completed or aborted.\n\t\t */\n\t\t*navigate( href, options = {} ) {\n\t\t\tconst url = cleanUrl( href );\n\t\t\tnavigatingTo = href;\n\t\t\tactions.prefetch( url, options );\n\n\t\t\t// Create a promise that resolves when the specified timeout ends.\n\t\t\t// The timeout value is 10 seconds by default.\n\t\t\tconst timeoutPromise = new Promise( ( resolve ) =>\n\t\t\t\tsetTimeout( resolve, options.timeout ?? 10000 )\n\t\t\t);\n\n\t\t\tconst page = yield Promise.race( [\n\t\t\t\tpages.get( url ),\n\t\t\t\ttimeoutPromise,\n\t\t\t] );\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 ) return;\n\n\t\t\tif ( page ) {\n\t\t\t\trenderRegions( page );\n\t\t\t\twindow.history[\n\t\t\t\t\toptions.replace ? 'replaceState' : 'pushState'\n\t\t\t\t]( {}, '', href );\n\t\t\t} else {\n\t\t\t\twindow.location.assign( href );\n\t\t\t\tyield new Promise( () => {} );\n\t\t\t}\n\t\t},\n\n\t\t/**\n\t\t * Prefetchs the page with the passed URL.\n\t\t *\n\t\t * The function normalizes the URL and stores internally the fetch\n\t\t * promise, to avoid triggering a second fetch for an ongoing request.\n\t\t *\n\t\t * @param {string} url The page URL.\n\t\t * @param {Object} [options] Options object.\n\t\t * @param {boolean} [options.force] Force fetching the URL again.\n\t\t * @param {string} [options.html] HTML string to be used instead of\n\t\t * fetching the requested URL.\n\t\t */\n\t\tprefetch( url, options = {} ) {\n\t\t\turl = cleanUrl( url );\n\t\t\tif ( options.force || ! pages.has( url ) ) {\n\t\t\t\tpages.set( url, fetchPage( url, options ) );\n\t\t\t}\n\t\t},\n\t},\n} );\n"],"mappings":"AAAA;AACA;AACA;AACA,SACCA,MAAM,EACNC,eAAe,EACfC,MAAM,EACNC,qBAAqB,EACrBC,KAAK,QACC,0BAA0B;;AAEjC;AACA,MAAMC,KAAK,GAAG,IAAIC,GAAG,CAAC,CAAC;;AAEvB;AACA;AACA,MAAMC,QAAQ,GAAKC,GAAG,IAAM;EAC3B,MAAMC,CAAC,GAAG,IAAIC,GAAG,CAAEF,GAAG,EAAEG,MAAM,CAACC,QAAS,C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C1CH,KAAK,CAACwC,GAAG,CAAErC,GAAG,EAAEO,SAAS,CAAEP,GAAG,EAAE4C,OAAQ,CAAE,CAAC;MAC5C;IACD;EACD;AACD,CAAE,CAAC"}
|
|
1
|
+
{"version":3,"names":["store","privateApis","getConfig","directivePrefix","getRegionRootFragment","initialVdom","toVdom","render","pages","Map","getPagePath","url","u","URL","window","location","pathname","search","fetchPage","html","res","fetch","status","text","dom","DOMParser","parseFromString","regionsToVdom","e","vdom","regions","attrName","querySelectorAll","forEach","region","id","getAttribute","has","get","title","querySelector","innerText","renderRegions","page","document","fragment","forcePageReload","href","assign","Promise","addEventListener","pagePath","state","reload","set","resolve","navigatingTo","actions","navigation","hasStarted","hasFinished","texts","navigate","options","clientNavigationDisabled","loadingAnimation","screenReaderAnnouncement","timeout","prefetch","timeoutPromise","setTimeout","loadingTimeout","message","loading","race","clearTimeout","history","replace","loaded","force"],"sources":["@wordpress/interactivity-router/src/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { store, privateApis, getConfig } from '@wordpress/interactivity';\n\nconst { directivePrefix, getRegionRootFragment, initialVdom, toVdom, render } =\n\tprivateApis(\n\t\t'I acknowledge that using private APIs means my theme or plugin will inevitably break in the next version of WordPress.'\n\t);\n\n// The cache of visited and prefetched pages.\nconst pages = new Map();\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 ) => {\n\tconst u = new URL( url, window.location );\n\treturn u.pathname + u.search;\n};\n\n// Fetch a new page and convert it to a static virtual DOM.\nconst fetchPage = async ( url, { html } ) => {\n\ttry {\n\t\tif ( ! html ) {\n\t\t\tconst res = await window.fetch( url );\n\t\t\tif ( res.status !== 200 ) return false;\n\t\t\thtml = await res.text();\n\t\t}\n\t\tconst dom = new window.DOMParser().parseFromString( html, 'text/html' );\n\t\treturn regionsToVdom( dom );\n\t} catch ( e ) {\n\t\treturn false;\n\t}\n};\n\n// Return an object with VDOM trees of those HTML regions marked with a\n// `router-region` directive.\nconst regionsToVdom = ( dom, { vdom } = {} ) => {\n\tconst regions = {};\n\tconst attrName = `data-${ directivePrefix }-router-region`;\n\tdom.querySelectorAll( `[${ attrName }]` ).forEach( ( region ) => {\n\t\tconst id = region.getAttribute( attrName );\n\t\tregions[ id ] = vdom?.has( region )\n\t\t\t? vdom.get( region )\n\t\t\t: toVdom( region );\n\t} );\n\tconst title = dom.querySelector( 'title' )?.innerText;\n\treturn { regions, title };\n};\n\n// Render all interactive regions contained in the given page.\nconst renderRegions = ( page ) => {\n\tconst attrName = `data-${ directivePrefix }-router-region`;\n\tdocument.querySelectorAll( `[${ attrName }]` ).forEach( ( region ) => {\n\t\tconst id = region.getAttribute( attrName );\n\t\tconst fragment = getRegionRootFragment( region );\n\t\trender( page.regions[ id ], fragment );\n\t} );\n\tif ( page.title ) {\n\t\tdocument.title = page.title;\n\t}\n};\n\n/**\n * Load the given page forcing a full page reload.\n *\n * The function returns a promise that won't resolve, useful to prevent any\n * potential feedback indicating that the navigation has finished while the new\n * page is being loaded.\n *\n * @param {string} href The page href.\n * @return {Promise} Promise that never resolves.\n */\nconst forcePageReload = ( href ) => {\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 ); // Remove hash.\n\tconst page = pages.has( pagePath ) && ( await pages.get( pagePath ) );\n\tif ( page ) {\n\t\trenderRegions( page );\n\t\t// Update the URL in the state.\n\t\tstate.url = window.location.href;\n\t} else {\n\t\twindow.location.reload();\n\t}\n} );\n\n// Cache the initial page using the intially parsed vDOM.\npages.set(\n\tgetPagePath( window.location ),\n\tPromise.resolve( regionsToVdom( document, { vdom: initialVdom } ) )\n);\n\n// Variable to store the current navigation.\nlet navigatingTo = '';\n\nexport const { state, actions } = store( 'core/router', {\n\tstate: {\n\t\turl: window.location.href,\n\t\tnavigation: {\n\t\t\thasStarted: false,\n\t\t\thasFinished: false,\n\t\t\ttexts: {},\n\t\t},\n\t},\n\tactions: {\n\t\t/**\n\t\t * Navigates to the specified page.\n\t\t *\n\t\t * This function normalizes the passed href, fetchs the page HTML if\n\t\t * needed, and updates any interactive regions whose contents have\n\t\t * changed. It also creates a new entry in the browser session history.\n\t\t *\n\t\t * @param {string} href The page href.\n\t\t * @param {Object} [options] Options object.\n\t\t * @param {boolean} [options.force] If true, it forces re-fetching the URL.\n\t\t * @param {string} [options.html] HTML string to be used instead of fetching the requested URL.\n\t\t * @param {boolean} [options.replace] If true, it replaces the current entry in the browser session history.\n\t\t * @param {number} [options.timeout] Time until the navigation is aborted, in milliseconds. Default is 10000.\n\t\t * @param {boolean} [options.loadingAnimation] Whether an animation should be shown while navigating. Default to `true`.\n\t\t * @param {boolean} [options.screenReaderAnnouncement] Whether a message for screen readers should be announced while navigating. Default to `true`.\n\t\t *\n\t\t * @return {Promise} Promise that resolves once the navigation is completed or aborted.\n\t\t */\n\t\t*navigate( href, options = {} ) {\n\t\t\tconst { clientNavigationDisabled } = getConfig();\n\t\t\tif ( clientNavigationDisabled ) {\n\t\t\t\tyield forcePageReload( href );\n\t\t\t}\n\n\t\t\tconst pagePath = getPagePath( href );\n\t\t\tconst { navigation } = state;\n\t\t\tconst {\n\t\t\t\tloadingAnimation = true,\n\t\t\t\tscreenReaderAnnouncement = true,\n\t\t\t\ttimeout = 10000,\n\t\t\t} = options;\n\n\t\t\tnavigatingTo = href;\n\t\t\tactions.prefetch( pagePath, options );\n\n\t\t\t// Create a promise that resolves when the specified timeout ends.\n\t\t\t// The timeout value is 10 seconds by default.\n\t\t\tconst timeoutPromise = new Promise( ( resolve ) =>\n\t\t\t\tsetTimeout( resolve, timeout )\n\t\t\t);\n\n\t\t\t// Don't update the navigation status immediately, wait 400 ms.\n\t\t\tconst loadingTimeout = setTimeout( () => {\n\t\t\t\tif ( navigatingTo !== href ) return;\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\tnavigation.message = navigation.texts.loading;\n\t\t\t\t}\n\t\t\t}, 400 );\n\n\t\t\tconst page = yield Promise.race( [\n\t\t\t\tpages.get( pagePath ),\n\t\t\t\ttimeoutPromise,\n\t\t\t] );\n\n\t\t\t// Dismiss loading message if it hasn't been added yet.\n\t\t\tclearTimeout( loadingTimeout );\n\n\t\t\t// Once the page is fetched, the destination URL could have changed\n\t\t\t// (e.g., by clicking another link in the meantime). If so, bail\n\t\t\t// out, and let the newer execution to update the HTML.\n\t\t\tif ( navigatingTo !== href ) return;\n\n\t\t\tif ( page ) {\n\t\t\t\trenderRegions( page );\n\t\t\t\twindow.history[\n\t\t\t\t\toptions.replace ? 'replaceState' : 'pushState'\n\t\t\t\t]( {}, '', href );\n\n\t\t\t\t// Update the URL in the state.\n\t\t\t\tstate.url = href;\n\n\t\t\t\t// Update the navigation status once the the new page rendering\n\t\t\t\t// has been completed.\n\t\t\t\tif ( loadingAnimation ) {\n\t\t\t\t\tnavigation.hasStarted = false;\n\t\t\t\t\tnavigation.hasFinished = true;\n\t\t\t\t}\n\n\t\t\t\tif ( screenReaderAnnouncement ) {\n\t\t\t\t\t// Announce that the page has been loaded. If the message is the\n\t\t\t\t\t// same, we use a no-break space similar to the @wordpress/a11y\n\t\t\t\t\t// package: https://github.com/WordPress/gutenberg/blob/c395242b8e6ee20f8b06c199e4fc2920d7018af1/packages/a11y/src/filter-message.js#L20-L26\n\t\t\t\t\tnavigation.message =\n\t\t\t\t\t\tnavigation.texts.loaded +\n\t\t\t\t\t\t( navigation.message === navigation.texts.loaded\n\t\t\t\t\t\t\t? '\\u00A0'\n\t\t\t\t\t\t\t: '' );\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tyield forcePageReload( href );\n\t\t\t}\n\t\t},\n\n\t\t/**\n\t\t * Prefetchs the page with the passed URL.\n\t\t *\n\t\t * The function normalizes the URL and stores internally the fetch\n\t\t * promise, to avoid triggering a second fetch for an ongoing request.\n\t\t *\n\t\t * @param {string} url The page URL.\n\t\t * @param {Object} [options] Options object.\n\t\t * @param {boolean} [options.force] Force fetching the URL again.\n\t\t * @param {string} [options.html] HTML string to be used instead of\n\t\t * fetching the requested URL.\n\t\t */\n\t\tprefetch( url, options = {} ) {\n\t\t\tconst { clientNavigationDisabled } = getConfig();\n\t\t\tif ( clientNavigationDisabled ) return;\n\n\t\t\tconst pagePath = getPagePath( url );\n\t\t\tif ( options.force || ! pages.has( pagePath ) ) {\n\t\t\t\tpages.set( pagePath, fetchPage( pagePath, options ) );\n\t\t\t}\n\t\t},\n\t},\n} );\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,KAAK,EAAEC,WAAW,EAAEC,SAAS,QAAQ,0BAA0B;AAExE,MAAM;EAAEC,eAAe;EAAEC,qBAAqB;EAAEC,WAAW;EAAEC,MAAM;EAAEC;AAAO,CAAC,GAC5EN,WAAW,CACV,wHACD,CAAC;;AAEF;AACA,MAAMO,KAAK,GAAG,IAAIC,GAAG,CAAC,CAAC;;AAEvB;AACA;AACA,MAAMC,WAAW,GAAKC,GAAG,IAAM;EAC9B,MAAMC,CAAC,GAAG,IAAIC,GAAG,CAAEF,GAAG,EAAEG,MAAM,CAACC,QAAS,CAAC;EACzC,OAAOH,CAAC,CAACI,QAAQ,GAAGJ,CAAC,CAACK,MAAM;AAC7B,CAAC;;AAED;AACA,MAAMC,SAAS,GAAG,MAAAA,CAAQP,GAAG,EAAE;EAAEQ;AAAK,CAAC,KAAM;EAC5C,IAAI;IACH,IAAK,CAAEA,IAAI,EAAG;MACb,MAAMC,GAAG,GAAG,MAAMN,MAAM,CAACO,KAAK,CAAEV,GAAI,CAAC;MACrC,IAAKS,GAAG,CAACE,MAAM,KAAK,GAAG,EAAG,OAAO,KAAK;MACtCH,IAAI,GAAG,MAAMC,GAAG,CAACG,IAAI,CAAC,CAAC;IACxB;IACA,MAAMC,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EjC,SAAS,CAAEiC,QAAQ,EAAEY,OAAQ,CAAE,CAAC;MACtD;IACD;EACD;AACD,CAAE,CAAC"}
|
package/build-types/index.d.ts
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
export
|
|
1
|
+
export namespace state {
|
|
2
|
+
let url: string;
|
|
3
|
+
namespace navigation {
|
|
4
|
+
let hasStarted: boolean;
|
|
5
|
+
let hasFinished: boolean;
|
|
6
|
+
let texts: {};
|
|
7
|
+
}
|
|
8
|
+
}
|
|
2
9
|
export namespace actions {
|
|
3
10
|
/**
|
|
4
11
|
* Navigates to the specified page.
|
|
@@ -7,27 +14,24 @@ export namespace actions {
|
|
|
7
14
|
* needed, and updates any interactive regions whose contents have
|
|
8
15
|
* changed. It also creates a new entry in the browser session history.
|
|
9
16
|
*
|
|
10
|
-
* @param {string} href
|
|
11
|
-
* @param {Object} [options]
|
|
12
|
-
* @param {boolean} [options.force]
|
|
13
|
-
*
|
|
14
|
-
* @param {
|
|
15
|
-
*
|
|
16
|
-
* @param {boolean} [options.
|
|
17
|
-
*
|
|
18
|
-
* history.
|
|
19
|
-
* @param {number} [options.timeout] Time until the navigation is
|
|
20
|
-
* aborted, in milliseconds. Default
|
|
21
|
-
* is 10000.
|
|
17
|
+
* @param {string} href The page href.
|
|
18
|
+
* @param {Object} [options] Options object.
|
|
19
|
+
* @param {boolean} [options.force] If true, it forces re-fetching the URL.
|
|
20
|
+
* @param {string} [options.html] HTML string to be used instead of fetching the requested URL.
|
|
21
|
+
* @param {boolean} [options.replace] If true, it replaces the current entry in the browser session history.
|
|
22
|
+
* @param {number} [options.timeout] Time until the navigation is aborted, in milliseconds. Default is 10000.
|
|
23
|
+
* @param {boolean} [options.loadingAnimation] Whether an animation should be shown while navigating. Default to `true`.
|
|
24
|
+
* @param {boolean} [options.screenReaderAnnouncement] Whether a message for screen readers should be announced while navigating. Default to `true`.
|
|
22
25
|
*
|
|
23
|
-
* @return {Promise} Promise that resolves once the navigation is
|
|
24
|
-
* completed or aborted.
|
|
26
|
+
* @return {Promise} Promise that resolves once the navigation is completed or aborted.
|
|
25
27
|
*/
|
|
26
28
|
function navigate(href: string, options?: {
|
|
27
29
|
force?: boolean;
|
|
28
30
|
html?: string;
|
|
29
31
|
replace?: boolean;
|
|
30
32
|
timeout?: number;
|
|
33
|
+
loadingAnimation?: boolean;
|
|
34
|
+
screenReaderAnnouncement?: boolean;
|
|
31
35
|
}): Promise<any>;
|
|
32
36
|
/**
|
|
33
37
|
* Prefetchs the page with the passed URL.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":";;;;;;;;;IA+GE;;;;;;;;;;;;;;;;;OAiBG;IACH;;;;;;;qBA8EC;IAED;;;;;;;;;;;OAWG;IACH;;;aAQC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/interactivity-router",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.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",
|
|
@@ -26,10 +26,10 @@
|
|
|
26
26
|
"react-native": "src/index",
|
|
27
27
|
"types": "build-types",
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@wordpress/interactivity": "^
|
|
29
|
+
"@wordpress/interactivity": "^5.0.0"
|
|
30
30
|
},
|
|
31
31
|
"publishConfig": {
|
|
32
32
|
"access": "public"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "eb796371e9630636a4a8837033807b0c4a06ed67"
|
|
35
35
|
}
|
package/src/index.js
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* WordPress dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
} from '@wordpress/interactivity';
|
|
4
|
+
import { store, privateApis, getConfig } from '@wordpress/interactivity';
|
|
5
|
+
|
|
6
|
+
const { directivePrefix, getRegionRootFragment, initialVdom, toVdom, render } =
|
|
7
|
+
privateApis(
|
|
8
|
+
'I acknowledge that using private APIs means my theme or plugin will inevitably break in the next version of WordPress.'
|
|
9
|
+
);
|
|
11
10
|
|
|
12
11
|
// The cache of visited and prefetched pages.
|
|
13
12
|
const pages = new Map();
|
|
14
13
|
|
|
15
14
|
// Helper to remove domain and hash from the URL. We are only interesting in
|
|
16
15
|
// caching the path and the query.
|
|
17
|
-
const
|
|
16
|
+
const getPagePath = ( url ) => {
|
|
18
17
|
const u = new URL( url, window.location );
|
|
19
18
|
return u.pathname + u.search;
|
|
20
19
|
};
|
|
@@ -36,12 +35,14 @@ const fetchPage = async ( url, { html } ) => {
|
|
|
36
35
|
|
|
37
36
|
// Return an object with VDOM trees of those HTML regions marked with a
|
|
38
37
|
// `router-region` directive.
|
|
39
|
-
const regionsToVdom = ( dom ) => {
|
|
38
|
+
const regionsToVdom = ( dom, { vdom } = {} ) => {
|
|
40
39
|
const regions = {};
|
|
41
40
|
const attrName = `data-${ directivePrefix }-router-region`;
|
|
42
41
|
dom.querySelectorAll( `[${ attrName }]` ).forEach( ( region ) => {
|
|
43
42
|
const id = region.getAttribute( attrName );
|
|
44
|
-
regions[ id ] =
|
|
43
|
+
regions[ id ] = vdom?.has( region )
|
|
44
|
+
? vdom.get( region )
|
|
45
|
+
: toVdom( region );
|
|
45
46
|
} );
|
|
46
47
|
const title = dom.querySelector( 'title' )?.innerText;
|
|
47
48
|
return { regions, title };
|
|
@@ -60,28 +61,53 @@ const renderRegions = ( page ) => {
|
|
|
60
61
|
}
|
|
61
62
|
};
|
|
62
63
|
|
|
63
|
-
|
|
64
|
-
|
|
64
|
+
/**
|
|
65
|
+
* Load the given page forcing a full page reload.
|
|
66
|
+
*
|
|
67
|
+
* The function returns a promise that won't resolve, useful to prevent any
|
|
68
|
+
* potential feedback indicating that the navigation has finished while the new
|
|
69
|
+
* page is being loaded.
|
|
70
|
+
*
|
|
71
|
+
* @param {string} href The page href.
|
|
72
|
+
* @return {Promise} Promise that never resolves.
|
|
73
|
+
*/
|
|
74
|
+
const forcePageReload = ( href ) => {
|
|
75
|
+
window.location.assign( href );
|
|
76
|
+
return new Promise( () => {} );
|
|
77
|
+
};
|
|
65
78
|
|
|
66
79
|
// Listen to the back and forward buttons and restore the page if it's in the
|
|
67
80
|
// cache.
|
|
68
81
|
window.addEventListener( 'popstate', async () => {
|
|
69
|
-
const
|
|
70
|
-
const page = pages.has(
|
|
82
|
+
const pagePath = getPagePath( window.location ); // Remove hash.
|
|
83
|
+
const page = pages.has( pagePath ) && ( await pages.get( pagePath ) );
|
|
71
84
|
if ( page ) {
|
|
72
85
|
renderRegions( page );
|
|
86
|
+
// Update the URL in the state.
|
|
87
|
+
state.url = window.location.href;
|
|
73
88
|
} else {
|
|
74
89
|
window.location.reload();
|
|
75
90
|
}
|
|
76
91
|
} );
|
|
77
92
|
|
|
78
|
-
// Cache the
|
|
93
|
+
// Cache the initial page using the intially parsed vDOM.
|
|
79
94
|
pages.set(
|
|
80
|
-
|
|
81
|
-
Promise.resolve( regionsToVdom( document ) )
|
|
95
|
+
getPagePath( window.location ),
|
|
96
|
+
Promise.resolve( regionsToVdom( document, { vdom: initialVdom } ) )
|
|
82
97
|
);
|
|
83
98
|
|
|
99
|
+
// Variable to store the current navigation.
|
|
100
|
+
let navigatingTo = '';
|
|
101
|
+
|
|
84
102
|
export const { state, actions } = store( 'core/router', {
|
|
103
|
+
state: {
|
|
104
|
+
url: window.location.href,
|
|
105
|
+
navigation: {
|
|
106
|
+
hasStarted: false,
|
|
107
|
+
hasFinished: false,
|
|
108
|
+
texts: {},
|
|
109
|
+
},
|
|
110
|
+
},
|
|
85
111
|
actions: {
|
|
86
112
|
/**
|
|
87
113
|
* Navigates to the specified page.
|
|
@@ -90,38 +116,61 @@ export const { state, actions } = store( 'core/router', {
|
|
|
90
116
|
* needed, and updates any interactive regions whose contents have
|
|
91
117
|
* changed. It also creates a new entry in the browser session history.
|
|
92
118
|
*
|
|
93
|
-
* @param {string} href
|
|
94
|
-
* @param {Object} [options]
|
|
95
|
-
* @param {boolean} [options.force]
|
|
96
|
-
*
|
|
97
|
-
* @param {
|
|
98
|
-
*
|
|
99
|
-
* @param {boolean} [options.
|
|
100
|
-
*
|
|
101
|
-
* history.
|
|
102
|
-
* @param {number} [options.timeout] Time until the navigation is
|
|
103
|
-
* aborted, in milliseconds. Default
|
|
104
|
-
* is 10000.
|
|
119
|
+
* @param {string} href The page href.
|
|
120
|
+
* @param {Object} [options] Options object.
|
|
121
|
+
* @param {boolean} [options.force] If true, it forces re-fetching the URL.
|
|
122
|
+
* @param {string} [options.html] HTML string to be used instead of fetching the requested URL.
|
|
123
|
+
* @param {boolean} [options.replace] If true, it replaces the current entry in the browser session history.
|
|
124
|
+
* @param {number} [options.timeout] Time until the navigation is aborted, in milliseconds. Default is 10000.
|
|
125
|
+
* @param {boolean} [options.loadingAnimation] Whether an animation should be shown while navigating. Default to `true`.
|
|
126
|
+
* @param {boolean} [options.screenReaderAnnouncement] Whether a message for screen readers should be announced while navigating. Default to `true`.
|
|
105
127
|
*
|
|
106
|
-
* @return {Promise} Promise that resolves once the navigation is
|
|
107
|
-
* completed or aborted.
|
|
128
|
+
* @return {Promise} Promise that resolves once the navigation is completed or aborted.
|
|
108
129
|
*/
|
|
109
130
|
*navigate( href, options = {} ) {
|
|
110
|
-
const
|
|
131
|
+
const { clientNavigationDisabled } = getConfig();
|
|
132
|
+
if ( clientNavigationDisabled ) {
|
|
133
|
+
yield forcePageReload( href );
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const pagePath = getPagePath( href );
|
|
137
|
+
const { navigation } = state;
|
|
138
|
+
const {
|
|
139
|
+
loadingAnimation = true,
|
|
140
|
+
screenReaderAnnouncement = true,
|
|
141
|
+
timeout = 10000,
|
|
142
|
+
} = options;
|
|
143
|
+
|
|
111
144
|
navigatingTo = href;
|
|
112
|
-
actions.prefetch(
|
|
145
|
+
actions.prefetch( pagePath, options );
|
|
113
146
|
|
|
114
147
|
// Create a promise that resolves when the specified timeout ends.
|
|
115
148
|
// The timeout value is 10 seconds by default.
|
|
116
149
|
const timeoutPromise = new Promise( ( resolve ) =>
|
|
117
|
-
setTimeout( resolve,
|
|
150
|
+
setTimeout( resolve, timeout )
|
|
118
151
|
);
|
|
119
152
|
|
|
153
|
+
// Don't update the navigation status immediately, wait 400 ms.
|
|
154
|
+
const loadingTimeout = setTimeout( () => {
|
|
155
|
+
if ( navigatingTo !== href ) return;
|
|
156
|
+
|
|
157
|
+
if ( loadingAnimation ) {
|
|
158
|
+
navigation.hasStarted = true;
|
|
159
|
+
navigation.hasFinished = false;
|
|
160
|
+
}
|
|
161
|
+
if ( screenReaderAnnouncement ) {
|
|
162
|
+
navigation.message = navigation.texts.loading;
|
|
163
|
+
}
|
|
164
|
+
}, 400 );
|
|
165
|
+
|
|
120
166
|
const page = yield Promise.race( [
|
|
121
|
-
pages.get(
|
|
167
|
+
pages.get( pagePath ),
|
|
122
168
|
timeoutPromise,
|
|
123
169
|
] );
|
|
124
170
|
|
|
171
|
+
// Dismiss loading message if it hasn't been added yet.
|
|
172
|
+
clearTimeout( loadingTimeout );
|
|
173
|
+
|
|
125
174
|
// Once the page is fetched, the destination URL could have changed
|
|
126
175
|
// (e.g., by clicking another link in the meantime). If so, bail
|
|
127
176
|
// out, and let the newer execution to update the HTML.
|
|
@@ -132,9 +181,29 @@ export const { state, actions } = store( 'core/router', {
|
|
|
132
181
|
window.history[
|
|
133
182
|
options.replace ? 'replaceState' : 'pushState'
|
|
134
183
|
]( {}, '', href );
|
|
184
|
+
|
|
185
|
+
// Update the URL in the state.
|
|
186
|
+
state.url = href;
|
|
187
|
+
|
|
188
|
+
// Update the navigation status once the the new page rendering
|
|
189
|
+
// has been completed.
|
|
190
|
+
if ( loadingAnimation ) {
|
|
191
|
+
navigation.hasStarted = false;
|
|
192
|
+
navigation.hasFinished = true;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if ( screenReaderAnnouncement ) {
|
|
196
|
+
// Announce that the page has been loaded. If the message is the
|
|
197
|
+
// same, we use a no-break space similar to the @wordpress/a11y
|
|
198
|
+
// package: https://github.com/WordPress/gutenberg/blob/c395242b8e6ee20f8b06c199e4fc2920d7018af1/packages/a11y/src/filter-message.js#L20-L26
|
|
199
|
+
navigation.message =
|
|
200
|
+
navigation.texts.loaded +
|
|
201
|
+
( navigation.message === navigation.texts.loaded
|
|
202
|
+
? '\u00A0'
|
|
203
|
+
: '' );
|
|
204
|
+
}
|
|
135
205
|
} else {
|
|
136
|
-
|
|
137
|
-
yield new Promise( () => {} );
|
|
206
|
+
yield forcePageReload( href );
|
|
138
207
|
}
|
|
139
208
|
},
|
|
140
209
|
|
|
@@ -151,9 +220,12 @@ export const { state, actions } = store( 'core/router', {
|
|
|
151
220
|
* fetching the requested URL.
|
|
152
221
|
*/
|
|
153
222
|
prefetch( url, options = {} ) {
|
|
154
|
-
|
|
155
|
-
if (
|
|
156
|
-
|
|
223
|
+
const { clientNavigationDisabled } = getConfig();
|
|
224
|
+
if ( clientNavigationDisabled ) return;
|
|
225
|
+
|
|
226
|
+
const pagePath = getPagePath( url );
|
|
227
|
+
if ( options.force || ! pages.has( pagePath ) ) {
|
|
228
|
+
pages.set( pagePath, fetchPage( pagePath, options ) );
|
|
157
229
|
}
|
|
158
230
|
},
|
|
159
231
|
},
|
package/tsconfig.tsbuildinfo
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"program":{"fileNames":["../../node_modules/typescript/lib/lib.es5.d.ts","../../node_modules/typescript/lib/lib.es2015.d.ts","../../node_modules/typescript/lib/lib.es2016.d.ts","../../node_modules/typescript/lib/lib.es2017.d.ts","../../node_modules/typescript/lib/lib.es2018.d.ts","../../node_modules/typescript/lib/lib.es2019.d.ts","../../node_modules/typescript/lib/lib.es2020.d.ts","../../node_modules/typescript/lib/lib.es2021.d.ts","../../node_modules/typescript/lib/lib.es2022.d.ts","../../node_modules/typescript/lib/lib.es2023.d.ts","../../node_modules/typescript/lib/lib.esnext.d.ts","../../node_modules/typescript/lib/lib.dom.d.ts","../../node_modules/typescript/lib/lib.es2015.core.d.ts","../../node_modules/typescript/lib/lib.es2015.collection.d.ts","../../node_modules/typescript/lib/lib.es2015.generator.d.ts","../../node_modules/typescript/lib/lib.es2015.iterable.d.ts","../../node_modules/typescript/lib/lib.es2015.promise.d.ts","../../node_modules/typescript/lib/lib.es2015.proxy.d.ts","../../node_modules/typescript/lib/lib.es2015.reflect.d.ts","../../node_modules/typescript/lib/lib.es2015.symbol.d.ts","../../node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../../node_modules/typescript/lib/lib.es2016.array.include.d.ts","../../node_modules/typescript/lib/lib.es2017.object.d.ts","../../node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../../node_modules/typescript/lib/lib.es2017.string.d.ts","../../node_modules/typescript/lib/lib.es2017.intl.d.ts","../../node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../../node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../../node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../../node_modules/typescript/lib/lib.es2018.intl.d.ts","../../node_modules/typescript/lib/lib.es2018.promise.d.ts","../../node_modules/typescript/lib/lib.es2018.regexp.d.ts","../../node_modules/typescript/lib/lib.es2019.array.d.ts","../../node_modules/typescript/lib/lib.es2019.object.d.ts","../../node_modules/typescript/lib/lib.es2019.string.d.ts","../../node_modules/typescript/lib/lib.es2019.symbol.d.ts","../../node_modules/typescript/lib/lib.es2019.intl.d.ts","../../node_modules/typescript/lib/lib.es2020.bigint.d.ts","../../node_modules/typescript/lib/lib.es2020.date.d.ts","../../node_modules/typescript/lib/lib.es2020.promise.d.ts","../../node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts","../../node_modules/typescript/lib/lib.es2020.string.d.ts","../../node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts","../../node_modules/typescript/lib/lib.es2020.intl.d.ts","../../node_modules/typescript/lib/lib.es2020.number.d.ts","../../node_modules/typescript/lib/lib.es2021.promise.d.ts","../../node_modules/typescript/lib/lib.es2021.string.d.ts","../../node_modules/typescript/lib/lib.es2021.weakref.d.ts","../../node_modules/typescript/lib/lib.es2021.intl.d.ts","../../node_modules/typescript/lib/lib.es2022.array.d.ts","../../node_modules/typescript/lib/lib.es2022.error.d.ts","../../node_modules/typescript/lib/lib.es2022.intl.d.ts","../../node_modules/typescript/lib/lib.es2022.object.d.ts","../../node_modules/typescript/lib/lib.es2022.sharedmemory.d.ts","../../node_modules/typescript/lib/lib.es2022.string.d.ts","../../node_modules/typescript/lib/lib.es2022.regexp.d.ts","../../node_modules/typescript/lib/lib.es2023.array.d.ts","../../node_modules/typescript/lib/lib.esnext.intl.d.ts","../../node_modules/typescript/lib/lib.decorators.d.ts","../../node_modules/typescript/lib/lib.decorators.legacy.d.ts","../interactivity/build-types/store.d.ts","../interactivity/build-types/constants.d.ts","../interactivity/build-types/vdom.d.ts","../interactivity/build-types/init.d.ts","../../node_modules/@preact/signals-core/dist/signals-core.d.ts","../interactivity/node_modules/deepsignal/dist/deepsignal.d.ts","../interactivity/node_modules/preact/src/jsx.d.ts","../interactivity/node_modules/preact/src/index.d.ts","../interactivity/build-types/hooks.d.ts","../interactivity/build-types/utils.d.ts","../interactivity/node_modules/preact/hooks/src/index.d.ts","../interactivity/build-types/index.d.ts","./src/index.js"],"fileInfos":[{"version":"f59215c5f1d886b05395ee7aca73e0ac69ddfad2843aa88530e797879d511bad","affectsGlobalScope":true},"45b7ab580deca34ae9729e97c13cfd999df04416a79116c3bfb483804f85ded4","dc48272d7c333ccf58034c0026162576b7d50ea0e69c3b9292f803fc20720fd5","27147504487dc1159369da4f4da8a26406364624fa9bc3db632f7d94a5bae2c3","5e1c4c362065a6b95ff952c0eab010f04dcd2c3494e813b493ecfd4fcb9fc0d8","68d73b4a11549f9c0b7d352d10e91e5dca8faa3322bfb77b661839c42b1ddec7","5efce4fc3c29ea84e8928f97adec086e3dc876365e0982cc8479a07954a3efd4","feecb1be483ed332fad555aff858affd90a48ab19ba7272ee084704eb7167569","5514e54f17d6d74ecefedc73c504eadffdeda79c7ea205cf9febead32d45c4bc","f4e736d6c8d69ae5b3ab0ddfcaa3dc365c3e76909d6660af5b4e979b3934ac20","eeeb3aca31fbadef8b82502484499dfd1757204799a6f5b33116201c810676ec",{"version":"3dda5344576193a4ae48b8d03f105c86f20b2f2aff0a1d1fd7935f5d68649654","affectsGlobalScope":true},{"version":"9d9885c728913c1d16e0d2831b40341d6ad9a0ceecaabc55209b306ad9c736a5","affectsGlobalScope":true},{"version":"17bea081b9c0541f39dd1ae9bc8c78bdd561879a682e60e2f25f688c0ecab248","affectsGlobalScope":true},{"version":"4443e68b35f3332f753eacc66a04ac1d2053b8b035a0e0ac1d455392b5e243b3","affectsGlobalScope":true},{"version":"ab22100fdd0d24cfc2cc59d0a00fc8cf449830d9c4030dc54390a46bd562e929","affectsGlobalScope":true},{"version":"f7bd636ae3a4623c503359ada74510c4005df5b36de7f23e1db8a5c543fd176b","affectsGlobalScope":true},{"version":"ce691fb9e5c64efb9547083e4a34091bcbe5bdb41027e310ebba8f7d96a98671","affectsGlobalScope":true},{"version":"8d697a2a929a5fcb38b7a65594020fcef05ec1630804a33748829c5ff53640d0","affectsGlobalScope":true},{"version":"0c20f4d2358eb679e4ae8a4432bdd96c857a2960fd6800b21ec4008ec59d60ea","affectsGlobalScope":true},{"version":"36ae84ccc0633f7c0787bc6108386c8b773e95d3b052d9464a99cd9b8795fbec","affectsGlobalScope":true},{"version":"82d0d8e269b9eeac02c3bd1c9e884e85d483fcb2cd168bccd6bc54df663da031","affectsGlobalScope":true},{"version":"b8deab98702588840be73d67f02412a2d45a417a3c097b2e96f7f3a42ac483d1","affectsGlobalScope":true},{"version":"4738f2420687fd85629c9efb470793bb753709c2379e5f85bc1815d875ceadcd","affectsGlobalScope":true},{"version":"2f11ff796926e0832f9ae148008138ad583bd181899ab7dd768a2666700b1893","affectsGlobalScope":true},{"version":"376d554d042fb409cb55b5cbaf0b2b4b7e669619493c5d18d5fa8bd67273f82a","affectsGlobalScope":true},{"version":"9fc46429fbe091ac5ad2608c657201eb68b6f1b8341bd6d670047d32ed0a88fa","affectsGlobalScope":true},{"version":"61c37c1de663cf4171e1192466e52c7a382afa58da01b1dc75058f032ddf0839","affectsGlobalScope":true},{"version":"c4138a3dd7cd6cf1f363ca0f905554e8d81b45844feea17786cdf1626cb8ea06","affectsGlobalScope":true},{"version":"6ff3e2452b055d8f0ec026511c6582b55d935675af67cdb67dd1dc671e8065df","affectsGlobalScope":true},{"version":"03de17b810f426a2f47396b0b99b53a82c1b60e9cba7a7edda47f9bb077882f4","affectsGlobalScope":true},{"version":"8184c6ddf48f0c98429326b428478ecc6143c27f79b79e85740f17e6feb090f1","affectsGlobalScope":true},{"version":"261c4d2cf86ac5a89ad3fb3fafed74cbb6f2f7c1d139b0540933df567d64a6ca","affectsGlobalScope":true},{"version":"6af1425e9973f4924fca986636ac19a0cf9909a7e0d9d3009c349e6244e957b6","affectsGlobalScope":true},{"version":"576711e016cf4f1804676043e6a0a5414252560eb57de9faceee34d79798c850","affectsGlobalScope":true},{"version":"89c1b1281ba7b8a96efc676b11b264de7a8374c5ea1e6617f11880a13fc56dc6","affectsGlobalScope":true},{"version":"15a630d6817718a2ddd7088c4f83e4673fde19fa992d2eae2cf51132a302a5d3","affectsGlobalScope":true},{"version":"f06948deb2a51aae25184561c9640fb66afeddb34531a9212d011792b1d19e0a","affectsGlobalScope":true},{"version":"01e0ee7e1f661acedb08b51f8a9b7d7f959e9cdb6441360f06522cc3aea1bf2e","affectsGlobalScope":true},{"version":"ac17a97f816d53d9dd79b0d235e1c0ed54a8cc6a0677e9a3d61efb480b2a3e4e","affectsGlobalScope":true},{"version":"bf14a426dbbf1022d11bd08d6b8e709a2e9d246f0c6c1032f3b2edb9a902adbe","affectsGlobalScope":true},{"version":"ec0104fee478075cb5171e5f4e3f23add8e02d845ae0165bfa3f1099241fa2aa","affectsGlobalScope":true},{"version":"2b72d528b2e2fe3c57889ca7baef5e13a56c957b946906d03767c642f386bbc3","affectsGlobalScope":true},{"version":"9cc66b0513ad41cb5f5372cca86ef83a0d37d1c1017580b7dace3ea5661836df","affectsGlobalScope":true},{"version":"368af93f74c9c932edd84c58883e736c9e3d53cec1fe24c0b0ff451f529ceab1","affectsGlobalScope":true},{"version":"709efdae0cb5df5f49376cde61daacc95cdd44ae4671da13a540da5088bf3f30","affectsGlobalScope":true},{"version":"995c005ab91a498455ea8dfb63aa9f83fa2ea793c3d8aa344be4a1678d06d399","affectsGlobalScope":true},{"version":"61ed9b6d07af959e745fb11f9593ecd743b279418cc8a99448ea3cd5f3b3eb22","affectsGlobalScope":true},{"version":"038a2f66a34ee7a9c2fbc3584c8ab43dff2995f8c68e3f566f4c300d2175e31e","affectsGlobalScope":true},{"version":"4fa6ed14e98aa80b91f61b9805c653ee82af3502dc21c9da5268d3857772ca05","affectsGlobalScope":true},{"version":"f5c92f2c27b06c1a41b88f6db8299205aee52c2a2943f7ed29bd585977f254e8","affectsGlobalScope":true},{"version":"930b0e15811f84e203d3c23508674d5ded88266df4b10abee7b31b2ac77632d2","affectsGlobalScope":true},{"version":"8444af78980e3b20b49324f4a16ba35024fef3ee069a0eb67616ea6ca821c47a","affectsGlobalScope":true},{"version":"b9ea5778ff8b50d7c04c9890170db34c26a5358cccba36844fe319f50a43a61a","affectsGlobalScope":true},{"version":"3287d9d085fbd618c3971944b65b4be57859f5415f495b33a6adc994edd2f004","affectsGlobalScope":true},{"version":"50d53ccd31f6667aff66e3d62adf948879a3a16f05d89882d1188084ee415bbc","affectsGlobalScope":true},{"version":"25de46552b782d43cb7284df22fe2a265de387cf0248b747a7a1b647d81861f6","affectsGlobalScope":true},{"version":"307c8b7ebbd7f23a92b73a4c6c0a697beca05b06b036c23a34553e5fe65e4fdc","affectsGlobalScope":true},{"version":"189c0703923150aa30673fa3de411346d727cc44a11c75d05d7cf9ef095daa22","affectsGlobalScope":true},{"version":"782dec38049b92d4e85c1585fbea5474a219c6984a35b004963b00beb1aab538","affectsGlobalScope":true},"6115a21cd7d4c5febe505788258735ef3724a23a059ba654a4224089118af21b","8f761f6b43e4dddc4ad37bb18731c43230b93ee7622eaa6de05dd8ab13312265","460cc6a2fddd9fc792a8ab6e3a8b9ac966e42116df530ca91cb1063d992aa697","590d4b7df88872c8e48fab3c125308f1cdf5afd972126e1225a0623852bd220d","a03597e01b6506c238ec0e0de7f4df46f63c29bac200a0f01ef1e9ba858d9881","7f3b868338902dfe19d96d55944f6da8414a3fbcb9e597e3b3846eeb4f788555","290ae21b816c4ed479be7a08a86d99afcc2d200028ecdcf437f1776dfc94ed68","5ff856251ae237dbc86c112d2ef1060eebda755c708a1361904abfbb6fc6ea96","24e8237a29b16509f6eed9c57dd302ddc68c1e1d2031875a084811601c1c6e86","a96a67c9f461daf8ca9f0ce8e7dc136b2e181aa8c860be1662a9ae448f2e2cbb","414c9c77766f65ad0b2f005f8cca243df26eebe8a07ee58520365c7df060d37e","60f8f0f47b5b70e31ab228326a8f791359d0f56db0d8c90530023a991c78e2ff",{"version":"0aa3e79b0fa08d987c7658684e84ff6fd7baed02caaf9e79d7d86a9a333e99ff","signature":"4657f705833f2807d7cc1193031d0c3b7ea21a45a47f1ad4cffe9abb15a8fa93"}],"root":[73],"options":{"allowSyntheticDefaultImports":true,"composite":true,"declaration":true,"declarationDir":"./build-types","declarationMap":true,"emitDeclarationOnly":true,"esModuleInterop":false,"jsx":1,"module":99,"noFallthroughCasesInSwitch":true,"noImplicitReturns":true,"noUnusedLocals":true,"noUnusedParameters":true,"rootDir":"./src","strict":false,"target":99},"fileIdsList":[[72],[68],[61,62,63,64,66,68,69,70,71],[65],[67]],"referencedMap":[[73,1],[69,2],[72,3],[66,4],[71,2],[68,5],[67,2]],"exportedModulesMap":[[69,2],[72,3],[66,4],[71,2],[68,5],[67,2]],"semanticDiagnosticsPerFile":[65,59,60,12,14,13,2,15,16,17,18,19,20,21,22,3,4,26,23,24,25,27,28,29,5,30,31,32,33,6,37,34,35,36,38,7,39,44,45,40,41,42,43,8,49,46,47,48,50,9,51,52,53,56,54,55,57,10,1,11,58,73,62,69,72,64,61,70,63,66,71,68,67],"latestChangedDtsFile":"./build-types/index.d.ts"},"version":"5.1.6"}
|
|
1
|
+
{"program":{"fileNames":["../../node_modules/typescript/lib/lib.es5.d.ts","../../node_modules/typescript/lib/lib.es2015.d.ts","../../node_modules/typescript/lib/lib.es2016.d.ts","../../node_modules/typescript/lib/lib.es2017.d.ts","../../node_modules/typescript/lib/lib.es2018.d.ts","../../node_modules/typescript/lib/lib.es2019.d.ts","../../node_modules/typescript/lib/lib.es2020.d.ts","../../node_modules/typescript/lib/lib.es2021.d.ts","../../node_modules/typescript/lib/lib.es2022.d.ts","../../node_modules/typescript/lib/lib.es2023.d.ts","../../node_modules/typescript/lib/lib.esnext.d.ts","../../node_modules/typescript/lib/lib.dom.d.ts","../../node_modules/typescript/lib/lib.es2015.core.d.ts","../../node_modules/typescript/lib/lib.es2015.collection.d.ts","../../node_modules/typescript/lib/lib.es2015.generator.d.ts","../../node_modules/typescript/lib/lib.es2015.iterable.d.ts","../../node_modules/typescript/lib/lib.es2015.promise.d.ts","../../node_modules/typescript/lib/lib.es2015.proxy.d.ts","../../node_modules/typescript/lib/lib.es2015.reflect.d.ts","../../node_modules/typescript/lib/lib.es2015.symbol.d.ts","../../node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts","../../node_modules/typescript/lib/lib.es2016.array.include.d.ts","../../node_modules/typescript/lib/lib.es2017.object.d.ts","../../node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts","../../node_modules/typescript/lib/lib.es2017.string.d.ts","../../node_modules/typescript/lib/lib.es2017.intl.d.ts","../../node_modules/typescript/lib/lib.es2017.typedarrays.d.ts","../../node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts","../../node_modules/typescript/lib/lib.es2018.asynciterable.d.ts","../../node_modules/typescript/lib/lib.es2018.intl.d.ts","../../node_modules/typescript/lib/lib.es2018.promise.d.ts","../../node_modules/typescript/lib/lib.es2018.regexp.d.ts","../../node_modules/typescript/lib/lib.es2019.array.d.ts","../../node_modules/typescript/lib/lib.es2019.object.d.ts","../../node_modules/typescript/lib/lib.es2019.string.d.ts","../../node_modules/typescript/lib/lib.es2019.symbol.d.ts","../../node_modules/typescript/lib/lib.es2019.intl.d.ts","../../node_modules/typescript/lib/lib.es2020.bigint.d.ts","../../node_modules/typescript/lib/lib.es2020.date.d.ts","../../node_modules/typescript/lib/lib.es2020.promise.d.ts","../../node_modules/typescript/lib/lib.es2020.sharedmemory.d.ts","../../node_modules/typescript/lib/lib.es2020.string.d.ts","../../node_modules/typescript/lib/lib.es2020.symbol.wellknown.d.ts","../../node_modules/typescript/lib/lib.es2020.intl.d.ts","../../node_modules/typescript/lib/lib.es2020.number.d.ts","../../node_modules/typescript/lib/lib.es2021.promise.d.ts","../../node_modules/typescript/lib/lib.es2021.string.d.ts","../../node_modules/typescript/lib/lib.es2021.weakref.d.ts","../../node_modules/typescript/lib/lib.es2021.intl.d.ts","../../node_modules/typescript/lib/lib.es2022.array.d.ts","../../node_modules/typescript/lib/lib.es2022.error.d.ts","../../node_modules/typescript/lib/lib.es2022.intl.d.ts","../../node_modules/typescript/lib/lib.es2022.object.d.ts","../../node_modules/typescript/lib/lib.es2022.sharedmemory.d.ts","../../node_modules/typescript/lib/lib.es2022.string.d.ts","../../node_modules/typescript/lib/lib.es2022.regexp.d.ts","../../node_modules/typescript/lib/lib.es2023.array.d.ts","../../node_modules/typescript/lib/lib.esnext.intl.d.ts","../../node_modules/typescript/lib/lib.decorators.d.ts","../../node_modules/typescript/lib/lib.decorators.legacy.d.ts","../interactivity/build-types/store.d.ts","../interactivity/node_modules/preact/src/jsx.d.ts","../interactivity/node_modules/preact/src/index.d.ts","../interactivity/build-types/hooks.d.ts","../interactivity/build-types/utils.d.ts","../interactivity/node_modules/preact/hooks/src/index.d.ts","../interactivity/build-types/index.d.ts","./src/index.js"],"fileInfos":[{"version":"f59215c5f1d886b05395ee7aca73e0ac69ddfad2843aa88530e797879d511bad","affectsGlobalScope":true},"45b7ab580deca34ae9729e97c13cfd999df04416a79116c3bfb483804f85ded4","dc48272d7c333ccf58034c0026162576b7d50ea0e69c3b9292f803fc20720fd5","27147504487dc1159369da4f4da8a26406364624fa9bc3db632f7d94a5bae2c3","5e1c4c362065a6b95ff952c0eab010f04dcd2c3494e813b493ecfd4fcb9fc0d8","68d73b4a11549f9c0b7d352d10e91e5dca8faa3322bfb77b661839c42b1ddec7","5efce4fc3c29ea84e8928f97adec086e3dc876365e0982cc8479a07954a3efd4","feecb1be483ed332fad555aff858affd90a48ab19ba7272ee084704eb7167569","5514e54f17d6d74ecefedc73c504eadffdeda79c7ea205cf9febead32d45c4bc","f4e736d6c8d69ae5b3ab0ddfcaa3dc365c3e76909d6660af5b4e979b3934ac20","eeeb3aca31fbadef8b82502484499dfd1757204799a6f5b33116201c810676ec",{"version":"3dda5344576193a4ae48b8d03f105c86f20b2f2aff0a1d1fd7935f5d68649654","affectsGlobalScope":true},{"version":"9d9885c728913c1d16e0d2831b40341d6ad9a0ceecaabc55209b306ad9c736a5","affectsGlobalScope":true},{"version":"17bea081b9c0541f39dd1ae9bc8c78bdd561879a682e60e2f25f688c0ecab248","affectsGlobalScope":true},{"version":"4443e68b35f3332f753eacc66a04ac1d2053b8b035a0e0ac1d455392b5e243b3","affectsGlobalScope":true},{"version":"ab22100fdd0d24cfc2cc59d0a00fc8cf449830d9c4030dc54390a46bd562e929","affectsGlobalScope":true},{"version":"f7bd636ae3a4623c503359ada74510c4005df5b36de7f23e1db8a5c543fd176b","affectsGlobalScope":true},{"version":"ce691fb9e5c64efb9547083e4a34091bcbe5bdb41027e310ebba8f7d96a98671","affectsGlobalScope":true},{"version":"8d697a2a929a5fcb38b7a65594020fcef05ec1630804a33748829c5ff53640d0","affectsGlobalScope":true},{"version":"0c20f4d2358eb679e4ae8a4432bdd96c857a2960fd6800b21ec4008ec59d60ea","affectsGlobalScope":true},{"version":"36ae84ccc0633f7c0787bc6108386c8b773e95d3b052d9464a99cd9b8795fbec","affectsGlobalScope":true},{"version":"82d0d8e269b9eeac02c3bd1c9e884e85d483fcb2cd168bccd6bc54df663da031","affectsGlobalScope":true},{"version":"b8deab98702588840be73d67f02412a2d45a417a3c097b2e96f7f3a42ac483d1","affectsGlobalScope":true},{"version":"4738f2420687fd85629c9efb470793bb753709c2379e5f85bc1815d875ceadcd","affectsGlobalScope":true},{"version":"2f11ff796926e0832f9ae148008138ad583bd181899ab7dd768a2666700b1893","affectsGlobalScope":true},{"version":"376d554d042fb409cb55b5cbaf0b2b4b7e669619493c5d18d5fa8bd67273f82a","affectsGlobalScope":true},{"version":"9fc46429fbe091ac5ad2608c657201eb68b6f1b8341bd6d670047d32ed0a88fa","affectsGlobalScope":true},{"version":"61c37c1de663cf4171e1192466e52c7a382afa58da01b1dc75058f032ddf0839","affectsGlobalScope":true},{"version":"c4138a3dd7cd6cf1f363ca0f905554e8d81b45844feea17786cdf1626cb8ea06","affectsGlobalScope":true},{"version":"6ff3e2452b055d8f0ec026511c6582b55d935675af67cdb67dd1dc671e8065df","affectsGlobalScope":true},{"version":"03de17b810f426a2f47396b0b99b53a82c1b60e9cba7a7edda47f9bb077882f4","affectsGlobalScope":true},{"version":"8184c6ddf48f0c98429326b428478ecc6143c27f79b79e85740f17e6feb090f1","affectsGlobalScope":true},{"version":"261c4d2cf86ac5a89ad3fb3fafed74cbb6f2f7c1d139b0540933df567d64a6ca","affectsGlobalScope":true},{"version":"6af1425e9973f4924fca986636ac19a0cf9909a7e0d9d3009c349e6244e957b6","affectsGlobalScope":true},{"version":"576711e016cf4f1804676043e6a0a5414252560eb57de9faceee34d79798c850","affectsGlobalScope":true},{"version":"89c1b1281ba7b8a96efc676b11b264de7a8374c5ea1e6617f11880a13fc56dc6","affectsGlobalScope":true},{"version":"15a630d6817718a2ddd7088c4f83e4673fde19fa992d2eae2cf51132a302a5d3","affectsGlobalScope":true},{"version":"f06948deb2a51aae25184561c9640fb66afeddb34531a9212d011792b1d19e0a","affectsGlobalScope":true},{"version":"01e0ee7e1f661acedb08b51f8a9b7d7f959e9cdb6441360f06522cc3aea1bf2e","affectsGlobalScope":true},{"version":"ac17a97f816d53d9dd79b0d235e1c0ed54a8cc6a0677e9a3d61efb480b2a3e4e","affectsGlobalScope":true},{"version":"bf14a426dbbf1022d11bd08d6b8e709a2e9d246f0c6c1032f3b2edb9a902adbe","affectsGlobalScope":true},{"version":"ec0104fee478075cb5171e5f4e3f23add8e02d845ae0165bfa3f1099241fa2aa","affectsGlobalScope":true},{"version":"2b72d528b2e2fe3c57889ca7baef5e13a56c957b946906d03767c642f386bbc3","affectsGlobalScope":true},{"version":"9cc66b0513ad41cb5f5372cca86ef83a0d37d1c1017580b7dace3ea5661836df","affectsGlobalScope":true},{"version":"368af93f74c9c932edd84c58883e736c9e3d53cec1fe24c0b0ff451f529ceab1","affectsGlobalScope":true},{"version":"709efdae0cb5df5f49376cde61daacc95cdd44ae4671da13a540da5088bf3f30","affectsGlobalScope":true},{"version":"995c005ab91a498455ea8dfb63aa9f83fa2ea793c3d8aa344be4a1678d06d399","affectsGlobalScope":true},{"version":"61ed9b6d07af959e745fb11f9593ecd743b279418cc8a99448ea3cd5f3b3eb22","affectsGlobalScope":true},{"version":"038a2f66a34ee7a9c2fbc3584c8ab43dff2995f8c68e3f566f4c300d2175e31e","affectsGlobalScope":true},{"version":"4fa6ed14e98aa80b91f61b9805c653ee82af3502dc21c9da5268d3857772ca05","affectsGlobalScope":true},{"version":"f5c92f2c27b06c1a41b88f6db8299205aee52c2a2943f7ed29bd585977f254e8","affectsGlobalScope":true},{"version":"930b0e15811f84e203d3c23508674d5ded88266df4b10abee7b31b2ac77632d2","affectsGlobalScope":true},{"version":"8444af78980e3b20b49324f4a16ba35024fef3ee069a0eb67616ea6ca821c47a","affectsGlobalScope":true},{"version":"b9ea5778ff8b50d7c04c9890170db34c26a5358cccba36844fe319f50a43a61a","affectsGlobalScope":true},{"version":"3287d9d085fbd618c3971944b65b4be57859f5415f495b33a6adc994edd2f004","affectsGlobalScope":true},{"version":"50d53ccd31f6667aff66e3d62adf948879a3a16f05d89882d1188084ee415bbc","affectsGlobalScope":true},{"version":"25de46552b782d43cb7284df22fe2a265de387cf0248b747a7a1b647d81861f6","affectsGlobalScope":true},{"version":"307c8b7ebbd7f23a92b73a4c6c0a697beca05b06b036c23a34553e5fe65e4fdc","affectsGlobalScope":true},{"version":"189c0703923150aa30673fa3de411346d727cc44a11c75d05d7cf9ef095daa22","affectsGlobalScope":true},{"version":"782dec38049b92d4e85c1585fbea5474a219c6984a35b004963b00beb1aab538","affectsGlobalScope":true},"9ec4f90724e0c763c2afbd7c7c2f3bed683668f204db871fab3e2597d8bd203e","290ae21b816c4ed479be7a08a86d99afcc2d200028ecdcf437f1776dfc94ed68","5ff856251ae237dbc86c112d2ef1060eebda755c708a1361904abfbb6fc6ea96","24e8237a29b16509f6eed9c57dd302ddc68c1e1d2031875a084811601c1c6e86","a96a67c9f461daf8ca9f0ce8e7dc136b2e181aa8c860be1662a9ae448f2e2cbb","414c9c77766f65ad0b2f005f8cca243df26eebe8a07ee58520365c7df060d37e","e52b70bda56de06a28c06416f83d16375020082eea0afab3e3b266ad17af6e7a",{"version":"5419e46a7392c2c5e19fb2405f6319271ec6970ccf9cd5283620567b7fff52b9","signature":"a9323b72027425cfd3602300bbf1645f8a554ea548917c6419f6ca353674f97c"}],"root":[68],"options":{"allowSyntheticDefaultImports":true,"composite":true,"declaration":true,"declarationDir":"./build-types","declarationMap":true,"emitDeclarationOnly":true,"esModuleInterop":false,"jsx":1,"module":99,"noFallthroughCasesInSwitch":true,"noImplicitReturns":true,"noUnusedLocals":true,"noUnusedParameters":true,"rootDir":"./src","strict":false,"target":99},"fileIdsList":[[67],[63],[61,64,65,66],[62]],"referencedMap":[[68,1],[64,2],[67,3],[66,2],[63,4],[62,2]],"exportedModulesMap":[[64,2],[67,3],[66,2],[63,4],[62,2]],"semanticDiagnosticsPerFile":[59,60,12,14,13,2,15,16,17,18,19,20,21,22,3,4,26,23,24,25,27,28,29,5,30,31,32,33,6,37,34,35,36,38,7,39,44,45,40,41,42,43,8,49,46,47,48,50,9,51,52,53,56,54,55,57,10,1,11,58,68,64,67,61,65,66,63,62],"latestChangedDtsFile":"./build-types/index.d.ts"},"version":"5.1.6"}
|