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

2 lines
1.9 KiB
JavaScript
Raw Normal View History

/*! This file is auto-generated */
!function(){"use strict";var t={d:function(e,o){for(var n in o)t.o(o,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:o[n]})},o:function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r:function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},e={};t.r(e),t.d(e,{actions:function(){return u},state:function(){return s}});var o=window.wp.interactivity;const n=new Map,r=t=>{const e=new URL(t,window.location);return e.pathname+e.search},i=t=>{const e={},n=`data-${o.directivePrefix}-router-region`;t.querySelectorAll(`[${n}]`).forEach((t=>{const r=t.getAttribute(n);e[r]=(0,o.toVdom)(t)}));const r=t.querySelector("title")?.innerText;return{regions:e,title:r}},a=t=>{const e=`data-${o.directivePrefix}-router-region`;document.querySelectorAll(`[${e}]`).forEach((n=>{const r=n.getAttribute(e),i=(0,o.getRegionRootFragment)(n);(0,o.render)(t.regions[r],i)})),t.title&&(document.title=t.title)};let c="";window.addEventListener("popstate",(async()=>{const t=r(window.location),e=n.has(t)&&await n.get(t);e?a(e):window.location.reload()})),n.set(r(window.location),Promise.resolve(i(document)));const{state:s,actions:u}=(0,o.store)("core/router",{actions:{*navigate(t,e={}){const o=r(t);c=t,u.prefetch(o,e);const i=new Promise((t=>{var o;return setTimeout(t,null!==(o=e.timeout)&&void 0!==o?o:1e4)})),s=yield Promise.race([n.get(o),i]);c===t&&(s?(a(s),window.history[e.replace?"replaceState":"pushState"]({},"",t)):(window.location.assign(t),yield new Promise((()=>{}))))},prefetch(t,e={}){t=r(t),!e.force&&n.has(t)||n.set(t,(async(t,{html:e})=>{try{if(!e){const o=await window.fetch(t);if(200!==o.status)return!1;e=await o.text()}const o=(new window.DOMParser).parseFromString(e,"text/html");return i(o)}catch(t){return!1}})(t,e))}}});(window.wp=window.wp||{}).interactivityRouter=e}();