WordPress/wp-includes/js/dist/interactivity-router.min.js

2 lines
2.5 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*! This file is auto-generated */
import*as e from"@wordpress/interactivity";var t={d:(e,o)=>{for(var i in o)t.o(o,i)&&!t.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:o[i]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},o={};t.d(o,{N:()=>p,S:()=>h});const i=(e=>{var o={};return t.d(o,e),o})({getConfig:()=>e.getConfig,privateApis:()=>e.privateApis,store:()=>e.store}),{directivePrefix:n,getRegionRootFragment:r,initialVdom:a,toVdom:s,render:c}=(0,i.privateApis)("I acknowledge that using private APIs means my theme or plugin will inevitably break in the next version of WordPress."),d=new Map,l=e=>{const t=new URL(e,window.location);return t.pathname+t.search},g=(e,{vdom:t}={})=>{const o={},i=`data-${n}-router-region`;e.querySelectorAll(`[${i}]`).forEach((e=>{const n=e.getAttribute(i);o[n]=t?.has(e)?t.get(e):s(e)}));const r=e.querySelector("title")?.innerText;return{regions:o,title:r}},w=e=>{const t=`data-${n}-router-region`;document.querySelectorAll(`[${t}]`).forEach((o=>{const i=o.getAttribute(t),n=r(o);c(e.regions[i],n)})),e.title&&(document.title=e.title)},m=e=>(window.location.assign(e),new Promise((()=>{})));window.addEventListener("popstate",(async()=>{const e=l(window.location),t=d.has(e)&&await d.get(e);t?(w(t),h.url=window.location.href):window.location.reload()})),d.set(l(window.location),Promise.resolve(g(document,{vdom:a})));let u="";const{state:h,actions:p}=(0,i.store)("core/router",{state:{url:window.location.href,navigation:{hasStarted:!1,hasFinished:!1,texts:{}}},actions:{*navigate(e,t={}){const{clientNavigationDisabled:o}=(0,i.getConfig)();o&&(yield m(e));const n=l(e),{navigation:r}=h,{loadingAnimation:a=!0,screenReaderAnnouncement:s=!0,timeout:c=1e4}=t;u=e,p.prefetch(n,t);const g=new Promise((e=>setTimeout(e,c))),v=setTimeout((()=>{u===e&&(a&&(r.hasStarted=!0,r.hasFinished=!1),s&&(r.message=r.texts.loading))}),400),f=yield Promise.race([d.get(n),g]);clearTimeout(v),u===e&&(f?(w(f),window.history[t.replace?"replaceState":"pushState"]({},"",e),h.url=e,a&&(r.hasStarted=!1,r.hasFinished=!0),s&&(r.message=r.texts.loaded+(r.message===r.texts.loaded?" ":""))):yield m(e))},prefetch(e,t={}){const{clientNavigationDisabled:o}=(0,i.getConfig)();if(o)return;const n=l(e);!t.force&&d.has(n)||d.set(n,(async(e,{html:t})=>{try{if(!t){const o=await window.fetch(e);if(200!==o.status)return!1;t=await o.text()}const o=(new window.DOMParser).parseFromString(t,"text/html");return g(o)}catch(e){return!1}})(n,t))}}});var v=o.N,f=o.S;export{v as actions,f as state};