[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

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

   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  /******/ (() => {
   8  /******/     // define getter functions for harmony exports
   9  /******/     __webpack_require__.d = (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  /******/ (() => {
  20  /******/     __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
  21  /******/ })();
  22  /******/ 
  23  /************************************************************************/
  24  var __webpack_exports__ = {};
  25  
  26  ;// external "@wordpress/interactivity"
  27  var x = (y) => {
  28      var x = {}; __webpack_require__.d(x, y); return x
  29  } 
  30  var y = (x) => (() => (x))
  31  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) });
  32  ;// ./node_modules/@wordpress/block-library/build-module/search/view.js
  33  /**
  34   * WordPress dependencies
  35   */
  36  
  37  const {
  38    actions
  39  } = (0,interactivity_namespaceObject.store)('core/search', {
  40    state: {
  41      get ariaLabel() {
  42        const {
  43          isSearchInputVisible,
  44          ariaLabelCollapsed,
  45          ariaLabelExpanded
  46        } = (0,interactivity_namespaceObject.getContext)();
  47        return isSearchInputVisible ? ariaLabelExpanded : ariaLabelCollapsed;
  48      },
  49      get ariaControls() {
  50        const {
  51          isSearchInputVisible,
  52          inputId
  53        } = (0,interactivity_namespaceObject.getContext)();
  54        return isSearchInputVisible ? null : inputId;
  55      },
  56      get type() {
  57        const {
  58          isSearchInputVisible
  59        } = (0,interactivity_namespaceObject.getContext)();
  60        return isSearchInputVisible ? 'submit' : 'button';
  61      },
  62      get tabindex() {
  63        const {
  64          isSearchInputVisible
  65        } = (0,interactivity_namespaceObject.getContext)();
  66        return isSearchInputVisible ? '0' : '-1';
  67      }
  68    },
  69    actions: {
  70      openSearchInput(event) {
  71        const ctx = (0,interactivity_namespaceObject.getContext)();
  72        const {
  73          ref
  74        } = (0,interactivity_namespaceObject.getElement)();
  75        if (!ctx.isSearchInputVisible) {
  76          event.preventDefault();
  77          ctx.isSearchInputVisible = true;
  78          ref.parentElement.querySelector('input').focus();
  79        }
  80      },
  81      closeSearchInput() {
  82        const ctx = (0,interactivity_namespaceObject.getContext)();
  83        ctx.isSearchInputVisible = false;
  84      },
  85      handleSearchKeydown(event) {
  86        const {
  87          ref
  88        } = (0,interactivity_namespaceObject.getElement)();
  89        // If Escape close the menu.
  90        if (event?.key === 'Escape') {
  91          actions.closeSearchInput();
  92          ref.querySelector('button').focus();
  93        }
  94      },
  95      handleSearchFocusout(event) {
  96        const {
  97          ref
  98        } = (0,interactivity_namespaceObject.getElement)();
  99        // If focus is outside search form, and in the document, close menu
 100        // event.target === The element losing focus
 101        // event.relatedTarget === The element receiving focus (if any)
 102        // When focusout is outside the document,
 103        // `window.document.activeElement` doesn't change.
 104        if (!ref.contains(event.relatedTarget) && event.target !== window.document.activeElement) {
 105          actions.closeSearchInput();
 106        }
 107      }
 108    }
 109  }, {
 110    lock: true
 111  });
 112  


Generated : Sun Dec 22 08:20:01 2024 Cross-referenced by PHPXref