UNPKG

@wordpress/block-library

Version:
42 lines (41 loc) • 1.78 kB
"use strict"; Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } }); let _wordpress_interactivity = require("@wordpress/interactivity"); // packages/block-library/src/query/view.js const isValidLink = (ref) => ref && ref instanceof window.HTMLAnchorElement && ref.href && (!ref.target || ref.target === "_self") && ref.origin === window.location.origin; const isValidEvent = (event) => event.button === 0 && !event.metaKey && !event.ctrlKey && !event.altKey && !event.shiftKey && !event.defaultPrevented; (0, _wordpress_interactivity.store)("core/query", { actions: { navigate: (0, _wordpress_interactivity.withSyncEvent)(function* (event) { const ctx = (0, _wordpress_interactivity.getContext)(); const { ref } = (0, _wordpress_interactivity.getElement)(); const queryRef = ref.closest(".wp-block-query[data-wp-router-region]"); if (isValidLink(ref) && isValidEvent(event)) { event.preventDefault(); const { actions } = yield import("@wordpress/interactivity-router"); yield actions.navigate(ref.href); ctx.url = ref.href; queryRef.querySelector(`.wp-block-post-template a[href]`)?.focus(); } }), *prefetch() { const { ref } = (0, _wordpress_interactivity.getElement)(); if (isValidLink(ref)) { const { actions } = yield import("@wordpress/interactivity-router"); yield actions.prefetch(ref.href); } } }, callbacks: { *prefetch() { const { url } = (0, _wordpress_interactivity.getContext)(); const { ref } = (0, _wordpress_interactivity.getElement)(); if (url && isValidLink(ref)) { const { actions } = yield import("@wordpress/interactivity-router"); yield actions.prefetch(ref.href); } } } }, { lock: true }); //# sourceMappingURL=view.cjs.map