build/modules/block-library/query
view.js
1.8 KB
7 months ago
view.js.map
3.1 KB
10 months ago
view.min.asset.php
253 B
7 months ago
view.min.js
966 B
9 months ago
view.min.js.map
3.3 KB
10 months ago
view.js in Gutenberg 23.2.0, at build/modules/block-library/query/view.js
| 1 | // packages/block-library/build-module/query/view.mjs |
| 2 | import { |
| 3 | store, |
| 4 | getContext, |
| 5 | getElement, |
| 6 | withSyncEvent |
| 7 | } from "@wordpress/interactivity"; |
| 8 | var isValidLink = (ref) => ref && ref instanceof window.HTMLAnchorElement && ref.href && (!ref.target || ref.target === "_self") && ref.origin === window.location.origin; |
| 9 | var isValidEvent = (event) => event.button === 0 && // Left clicks only. |
| 10 | !event.metaKey && // Open in new tab (Mac). |
| 11 | !event.ctrlKey && // Open in new tab (Windows). |
| 12 | !event.altKey && // Download. |
| 13 | !event.shiftKey && !event.defaultPrevented; |
| 14 | store( |
| 15 | "core/query", |
| 16 | { |
| 17 | actions: { |
| 18 | navigate: withSyncEvent(function* (event) { |
| 19 | const ctx = getContext(); |
| 20 | const { ref } = getElement(); |
| 21 | const queryRef = ref.closest( |
| 22 | ".wp-block-query[data-wp-router-region]" |
| 23 | ); |
| 24 | if (isValidLink(ref) && isValidEvent(event)) { |
| 25 | event.preventDefault(); |
| 26 | const { actions } = yield import("@wordpress/interactivity-router"); |
| 27 | yield actions.navigate(ref.href); |
| 28 | ctx.url = ref.href; |
| 29 | const firstAnchor = `.wp-block-post-template a[href]`; |
| 30 | queryRef.querySelector(firstAnchor)?.focus(); |
| 31 | } |
| 32 | }), |
| 33 | *prefetch() { |
| 34 | const { ref } = getElement(); |
| 35 | if (isValidLink(ref)) { |
| 36 | const { actions } = yield import("@wordpress/interactivity-router"); |
| 37 | yield actions.prefetch(ref.href); |
| 38 | } |
| 39 | } |
| 40 | }, |
| 41 | callbacks: { |
| 42 | *prefetch() { |
| 43 | const { url } = getContext(); |
| 44 | const { ref } = getElement(); |
| 45 | if (url && isValidLink(ref)) { |
| 46 | const { actions } = yield import("@wordpress/interactivity-router"); |
| 47 | yield actions.prefetch(ref.href); |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 | }, |
| 52 | { lock: true } |
| 53 | ); |
| 54 | //# sourceMappingURL=view.js.map |
| 55 |