PluginProbe
Gutenberg / 22.9.0
Gutenberg v22.9.0
23.9.1 23.9.0 23.8.0 23.7.2 23.7.1 23.7.0 23.6.1 23.6.2 23.6.0 23.5.3 23.5.2 23.5.1 23.5.0 23.4.0 23.3.2 23.3.1 23.3.0 23.2.0 23.2.1 23.2.2 23.1.1 23.1.0 23.0.1 12.6.0 7.4.0 All 402 releases
gutenberg / build / modules / block-library / query / view.js

view.js in Gutenberg 22.9.0, at build/modules/block-library/query/view.js

55 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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