PluginProbe
Gutenberg / 17.2.4
Gutenberg v17.2.4
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 / interactivity / query.js

query.js in Gutenberg 17.2.4, at build/interactivity/query.js

111 lines 4.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import * as __WEBPACK_EXTERNAL_MODULE__wordpress_interactivity_8e89b257__ from "@wordpress/interactivity";
2 /******/ // The require scope
3 /******/ var __webpack_require__ = {};
4 /******/
5 /************************************************************************/
6 /******/ /* webpack/runtime/define property getters */
7 /******/ !function() {
8 /******/ // define getter functions for harmony exports
9 /******/ __webpack_require__.d = function(exports, definition) {
10 /******/ for(var key in definition) {
11 /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
12 /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
13 /******/ }
14 /******/ }
15 /******/ };
16 /******/ }();
17 /******/
18 /******/ /* webpack/runtime/hasOwnProperty shorthand */
19 /******/ !function() {
20 /******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
21 /******/ }();
22 /******/
23 /************************************************************************/
24 var __webpack_exports__ = {};
25
26 ;// CONCATENATED MODULE: external "@wordpress/interactivity"
27 var x = y => { var x = {}; __webpack_require__.d(x, y); return x; }
28 var y = x => () => x
29 var interactivity_namespaceObject = x({ ["getContext"]: () => __WEBPACK_EXTERNAL_MODULE__wordpress_interactivity_8e89b257__.getContext, ["getElement"]: () => __WEBPACK_EXTERNAL_MODULE__wordpress_interactivity_8e89b257__.getElement, ["navigate"]: () => __WEBPACK_EXTERNAL_MODULE__wordpress_interactivity_8e89b257__.navigate, ["prefetch"]: () => __WEBPACK_EXTERNAL_MODULE__wordpress_interactivity_8e89b257__.prefetch, ["store"]: () => __WEBPACK_EXTERNAL_MODULE__wordpress_interactivity_8e89b257__.store });
30 ;// CONCATENATED MODULE: ./packages/block-library/src/query/view.js
31 /**
32 * WordPress dependencies
33 */
34
35 const isValidLink = ref => ref && ref instanceof window.HTMLAnchorElement && ref.href && (!ref.target || ref.target === '_self') && ref.origin === window.location.origin;
36 const isValidEvent = event => event.button === 0 &&
37 // Left clicks only.
38 !event.metaKey &&
39 // Open in new tab (Mac).
40 !event.ctrlKey &&
41 // Open in new tab (Windows).
42 !event.altKey &&
43 // Download.
44 !event.shiftKey && !event.defaultPrevented;
45 (0,interactivity_namespaceObject.store)('core/query', {
46 state: {
47 get startAnimation() {
48 return (0,interactivity_namespaceObject.getContext)().animation === 'start';
49 },
50 get finishAnimation() {
51 return (0,interactivity_namespaceObject.getContext)().animation === 'finish';
52 }
53 },
54 actions: {
55 *navigate(event) {
56 const ctx = (0,interactivity_namespaceObject.getContext)();
57 const {
58 ref
59 } = (0,interactivity_namespaceObject.getElement)();
60 const isDisabled = ref.closest('[data-wp-navigation-id]')?.dataset.wpNavigationDisabled;
61 if (isValidLink(ref) && isValidEvent(event) && !isDisabled) {
62 event.preventDefault();
63 const id = ref.closest('[data-wp-navigation-id]').dataset.wpNavigationId;
64
65 // Don't announce the navigation immediately, wait 400 ms.
66 const timeout = setTimeout(() => {
67 ctx.message = ctx.loadingText;
68 ctx.animation = 'start';
69 }, 400);
70 yield (0,interactivity_namespaceObject.navigate)(ref.href);
71
72 // Dismiss loading message if it hasn't been added yet.
73 clearTimeout(timeout);
74
75 // Announce that the page has been loaded. If the message is the
76 // same, we use a no-break space similar to the @wordpress/a11y
77 // package: https://github.com/WordPress/gutenberg/blob/c395242b8e6ee20f8b06c199e4fc2920d7018af1/packages/a11y/src/filter-message.js#L20-L26
78 ctx.message = ctx.loadedText + (ctx.message === ctx.loadedText ? '\u00A0' : '');
79 ctx.animation = 'finish';
80 ctx.url = ref.href;
81
82 // Focus the first anchor of the Query block.
83 const firstAnchor = `[data-wp-navigation-id=${id}] .wp-block-post-template a[href]`;
84 document.querySelector(firstAnchor)?.focus();
85 }
86 },
87 *prefetch() {
88 const {
89 ref
90 } = (0,interactivity_namespaceObject.getElement)();
91 const isDisabled = ref.closest('[data-wp-navigation-id]')?.dataset.wpNavigationDisabled;
92 if (isValidLink(ref) && !isDisabled) {
93 yield (0,interactivity_namespaceObject.prefetch)(ref.href);
94 }
95 }
96 },
97 callbacks: {
98 *prefetch() {
99 const {
100 url
101 } = (0,interactivity_namespaceObject.getContext)();
102 const {
103 ref
104 } = (0,interactivity_namespaceObject.getElement)();
105 if (url && isValidLink(ref)) {
106 yield (0,interactivity_namespaceObject.prefetch)(ref.href);
107 }
108 }
109 }
110 });
111