[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/js/dist/script-modules/block-library/query/ -> view.js (source)

   1  // packages/block-library/build-module/query/view.js
   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  );


Generated : Wed Apr 15 08:20:10 2026 Cross-referenced by PHPXref