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

2 lines
2.9 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,i)=>{for(var o in i)t.o(i,o)&&!t.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:i[o]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t)},i={};t.d(i,{o:()=>x,w:()=>b});const o=(e=>{var i={};return t.d(i,e),i})({getConfig:()=>e.getConfig,privateApis:()=>e.privateApis,store:()=>e.store});var n;const{directivePrefix:a,getRegionRootFragment:r,initialVdom:s,toVdom:c,render:l,parseInitialData:d,populateInitialData:g,batch:w}=(0,o.privateApis)("I acknowledge that using private APIs means my theme or plugin will inevitably break in the next version of WordPress."),u=null!==(n=(0,o.getConfig)("core/router").navigationMode)&&void 0!==n?n:"regionBased",h=new Map,m=(new Map,e=>{const t=new URL(e,window.location);return t.pathname+t.search}),p=async(e,{vdom:t}={})=>{const i={};if("regionBased"===u){const o=`data-${a}-router-region`;e.querySelectorAll(`[${o}]`).forEach((e=>{const n=e.getAttribute(o);i[n]=t?.has(e)?t.get(e):c(e)}))}const o=e.querySelector("title")?.innerText,n=d(e);return{regions:i,head:undefined,title:o,initialData:n}},f=e=>{w((()=>{if("regionBased"===u){g(e.initialData);const t=`data-${a}-router-region`;document.querySelectorAll(`[${t}]`).forEach((i=>{const o=i.getAttribute(t),n=r(i);l(e.regions[o],n)}))}e.title&&(document.title=e.title)}))},v=e=>(window.location.assign(e),new Promise((()=>{})));window.addEventListener("popstate",(async()=>{const e=m(window.location),t=h.has(e)&&await h.get(e);t?(f(t),b.url=window.location.href):window.location.reload()})),h.set(m(window.location),Promise.resolve(p(document,{vdom:s})));let y="";const{state:b,actions:x}=(0,o.store)("core/router",{state:{url:window.location.href,navigation:{hasStarted:!1,hasFinished:!1,texts:{}}},actions:{*navigate(e,t={}){const{clientNavigationDisabled:i}=(0,o.getConfig)();i&&(yield v(e));const n=m(e),{navigation:a}=b,{loadingAnimation:r=!0,screenReaderAnnouncement:s=!0,timeout:c=1e4}=t;y=e,x.prefetch(n,t);const l=new Promise((e=>setTimeout(e,c))),d=setTimeout((()=>{y===e&&(r&&(a.hasStarted=!0,a.hasFinished=!1),s&&(a.message=a.texts.loading))}),400),g=yield Promise.race([h.get(n),l]);if(clearTimeout(d),y===e)if(g&&!g.initialData?.config?.["core/router"]?.clientNavigationDisabled){yield f(g),window.history[t.replace?"replaceState":"pushState"]({},"",e),b.url=e,r&&(a.hasStarted=!1,a.hasFinished=!0),s&&(a.message=a.texts.loaded+(a.message===a.texts.loaded?" ":""));const{hash:i}=new URL(e,window.location);i&&document.querySelector(i)?.scrollIntoView()}else yield v(e)},prefetch(e,t={}){const{clientNavigationDisabled:i}=(0,o.getConfig)();if(i)return;const n=m(e);!t.force&&h.has(n)||h.set(n,(async(e,{html:t})=>{try{if(!t){const i=await window.fetch(e);if(200!==i.status)return!1;t=await i.text()}const i=(new window.DOMParser).parseFromString(t,"text/html");return p(i)}catch(e){return!1}})(n,t))}}});var A=i.o,P=i.w;export{A as actions,P as state};