wp/wp-includes/js/dist/script-modules/block-library/query/view.js
changeset 22 8c2e4d02f4ef
equal deleted inserted replaced
21:48c4eec2b7e6 22:8c2e4d02f4ef
       
     1 import * as __WEBPACK_EXTERNAL_MODULE__wordpress_interactivity_8e89b257__ from "@wordpress/interactivity";
       
     2 /******/ var __webpack_modules__ = ({
       
     3 
       
     4 /***/ 438:
       
     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 
       
    58 ;// external "@wordpress/interactivity"
       
    59 var x = (y) => {
       
    60 	var x = {}; __webpack_require__.d(x, y); return x
       
    61 } 
       
    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), ["withSyncEvent"]: () => (__WEBPACK_EXTERNAL_MODULE__wordpress_interactivity_8e89b257__.withSyncEvent) });
       
    64 ;// ./node_modules/@wordpress/block-library/build-module/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   actions: {
       
    81     navigate: (0,interactivity_namespaceObject.withSyncEvent)(function* (event) {
       
    82       const ctx = (0,interactivity_namespaceObject.getContext)();
       
    83       const {
       
    84         ref
       
    85       } = (0,interactivity_namespaceObject.getElement)();
       
    86       const queryRef = ref.closest('.wp-block-query[data-wp-router-region]');
       
    87       if (isValidLink(ref) && isValidEvent(event)) {
       
    88         event.preventDefault();
       
    89         const {
       
    90           actions
       
    91         } = yield Promise.resolve(/* import() */).then(__webpack_require__.bind(__webpack_require__, 438));
       
    92         yield actions.navigate(ref.href);
       
    93         ctx.url = ref.href;
       
    94 
       
    95         // Focus the first anchor of the Query block.
       
    96         const firstAnchor = `.wp-block-post-template a[href]`;
       
    97         queryRef.querySelector(firstAnchor)?.focus();
       
    98       }
       
    99     }),
       
   100     *prefetch() {
       
   101       const {
       
   102         ref
       
   103       } = (0,interactivity_namespaceObject.getElement)();
       
   104       if (isValidLink(ref)) {
       
   105         const {
       
   106           actions
       
   107         } = yield Promise.resolve(/* import() */).then(__webpack_require__.bind(__webpack_require__, 438));
       
   108         yield actions.prefetch(ref.href);
       
   109       }
       
   110     }
       
   111   },
       
   112   callbacks: {
       
   113     *prefetch() {
       
   114       const {
       
   115         url
       
   116       } = (0,interactivity_namespaceObject.getContext)();
       
   117       const {
       
   118         ref
       
   119       } = (0,interactivity_namespaceObject.getElement)();
       
   120       if (url && isValidLink(ref)) {
       
   121         const {
       
   122           actions
       
   123         } = yield Promise.resolve(/* import() */).then(__webpack_require__.bind(__webpack_require__, 438));
       
   124         yield actions.prefetch(ref.href);
       
   125       }
       
   126     }
       
   127   }
       
   128 }, {
       
   129   lock: true
       
   130 });
       
   131