PluginProbe
Gutenberg / 17.6.2
Gutenberg v17.6.2
24.0.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 All 403 releases
gutenberg / build / interactivity / query.js

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

168 lines 6.0 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 /******/ var __webpack_modules__ = ({
3
4 /***/ 978:
5 /***/ ((module) => {
6
7 module.exports = import("@wordpress/interactivity-router");;
8
9 /***/ })
10
11 /******/ });
12 /************************************************************************/
13 /******/ // The module cache
14 /******/ var __webpack_module_cache__ = {};
15 /******/
16 /******/ // The require function
17 /******/ function __webpack_require__(moduleId) {
18 /******/ // Check if module is in cache
19 /******/ var cachedModule = __webpack_module_cache__[moduleId];
20 /******/ if (cachedModule !== undefined) {
21 /******/ return cachedModule.exports;
22 /******/ }
23 /******/ // Create a new module (and put it into the cache)
24 /******/ var module = __webpack_module_cache__[moduleId] = {
25 /******/ // no module.id needed
26 /******/ // no module.loaded needed
27 /******/ exports: {}
28 /******/ };
29 /******/
30 /******/ // Execute the module function
31 /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
32 /******/
33 /******/ // Return the exports of the module
34 /******/ return module.exports;
35 /******/ }
36 /******/
37 /************************************************************************/
38 /******/ /* webpack/runtime/define property getters */
39 /******/ (() => {
40 /******/ // define getter functions for harmony exports
41 /******/ __webpack_require__.d = (exports, definition) => {
42 /******/ for(var key in definition) {
43 /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
44 /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
45 /******/ }
46 /******/ }
47 /******/ };
48 /******/ })();
49 /******/
50 /******/ /* webpack/runtime/hasOwnProperty shorthand */
51 /******/ (() => {
52 /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
53 /******/ })();
54 /******/
55 /************************************************************************/
56 var __webpack_exports__ = {};
57 // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
58 (() => {
59
60 ;// CONCATENATED MODULE: external "@wordpress/interactivity"
61 var x = y => { var x = {}; __webpack_require__.d(x, y); return x; }
62 var y = x => () => x
63 const interactivity_namespaceObject = x({ ["getContext"]: () => __WEBPACK_EXTERNAL_MODULE__wordpress_interactivity_8e89b257__.getContext, ["getElement"]: () => __WEBPACK_EXTERNAL_MODULE__wordpress_interactivity_8e89b257__.getElement, ["store"]: () => __WEBPACK_EXTERNAL_MODULE__wordpress_interactivity_8e89b257__.store });
64 ;// CONCATENATED MODULE: ./packages/block-library/src/query/view.js
65 /**
66 * WordPress dependencies
67 */
68
69 const isValidLink = ref => ref && ref instanceof window.HTMLAnchorElement && ref.href && (!ref.target || ref.target === '_self') && ref.origin === window.location.origin;
70 const isValidEvent = event => event.button === 0 &&
71 // Left clicks only.
72 !event.metaKey &&
73 // Open in new tab (Mac).
74 !event.ctrlKey &&
75 // Open in new tab (Windows).
76 !event.altKey &&
77 // Download.
78 !event.shiftKey && !event.defaultPrevented;
79 (0,interactivity_namespaceObject.store)('core/query', {
80 state: {
81 get startAnimation() {
82 return (0,interactivity_namespaceObject.getContext)().animation === 'start';
83 },
84 get finishAnimation() {
85 return (0,interactivity_namespaceObject.getContext)().animation === 'finish';
86 }
87 },
88 actions: {
89 *navigate(event) {
90 const ctx = (0,interactivity_namespaceObject.getContext)();
91 const {
92 ref
93 } = (0,interactivity_namespaceObject.getElement)();
94 const {
95 queryRef
96 } = ctx;
97 const isDisabled = queryRef?.dataset.wpNavigationDisabled;
98 if (isValidLink(ref) && isValidEvent(event) && !isDisabled) {
99 event.preventDefault();
100
101 // Don't announce the navigation immediately, wait 400 ms.
102 const timeout = setTimeout(() => {
103 ctx.message = ctx.loadingText;
104 ctx.animation = 'start';
105 }, 400);
106 const {
107 actions
108 } = yield Promise.resolve(/* import() */).then(__webpack_require__.bind(__webpack_require__, 978));
109 yield actions.navigate(ref.href);
110
111 // Dismiss loading message if it hasn't been added yet.
112 clearTimeout(timeout);
113
114 // Announce that the page has been loaded. If the message is the
115 // same, we use a no-break space similar to the @wordpress/a11y
116 // package: https://github.com/WordPress/gutenberg/blob/c395242b8e6ee20f8b06c199e4fc2920d7018af1/packages/a11y/src/filter-message.js#L20-L26
117 ctx.message = ctx.loadedText + (ctx.message === ctx.loadedText ? '\u00A0' : '');
118 ctx.animation = 'finish';
119 ctx.url = ref.href;
120
121 // Focus the first anchor of the Query block.
122 const firstAnchor = `.wp-block-post-template a[href]`;
123 queryRef.querySelector(firstAnchor)?.focus();
124 }
125 },
126 *prefetch() {
127 const {
128 queryRef
129 } = (0,interactivity_namespaceObject.getContext)();
130 const {
131 ref
132 } = (0,interactivity_namespaceObject.getElement)();
133 const isDisabled = queryRef?.dataset.wpNavigationDisabled;
134 if (isValidLink(ref) && !isDisabled) {
135 const {
136 actions
137 } = yield Promise.resolve(/* import() */).then(__webpack_require__.bind(__webpack_require__, 978));
138 yield actions.prefetch(ref.href);
139 }
140 }
141 },
142 callbacks: {
143 *prefetch() {
144 const {
145 url
146 } = (0,interactivity_namespaceObject.getContext)();
147 const {
148 ref
149 } = (0,interactivity_namespaceObject.getElement)();
150 if (url && isValidLink(ref)) {
151 const {
152 actions
153 } = yield Promise.resolve(/* import() */).then(__webpack_require__.bind(__webpack_require__, 978));
154 yield actions.prefetch(ref.href);
155 }
156 },
157 setQueryRef() {
158 const ctx = (0,interactivity_namespaceObject.getContext)();
159 const {
160 ref
161 } = (0,interactivity_namespaceObject.getElement)();
162 ctx.queryRef = ref;
163 }
164 }
165 });
166 })();
167
168