[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

title

Body

[close]

/wp-includes/js/dist/script-modules/block-library/accordion/ -> 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), ["store"]: () => (__WEBPACK_EXTERNAL_MODULE__wordpress_interactivity_8e89b257__.store), ["withSyncEvent"]: () => (__WEBPACK_EXTERNAL_MODULE__wordpress_interactivity_8e89b257__.withSyncEvent) });
  32  ;// ./node_modules/@wordpress/block-library/build-module/accordion/view.js
  33  
  34  (0,interactivity_namespaceObject.store)("core/accordion", {
  35    state: {
  36      get isOpen() {
  37        const { id, accordionItems } = (0,interactivity_namespaceObject.getContext)();
  38        const accordionItem = accordionItems.find(
  39          (item) => item.id === id
  40        );
  41        return accordionItem ? accordionItem.isOpen : false;
  42      }
  43    },
  44    actions: {
  45      toggle: () => {
  46        const context = (0,interactivity_namespaceObject.getContext)();
  47        const { id, autoclose, accordionItems } = context;
  48        const accordionItem = accordionItems.find(
  49          (item) => item.id === id
  50        );
  51        if (autoclose) {
  52          accordionItems.forEach((item) => {
  53            item.isOpen = item.id === id ? !accordionItem.isOpen : false;
  54          });
  55        } else {
  56          accordionItem.isOpen = !accordionItem.isOpen;
  57        }
  58      },
  59      handleKeyDown: (0,interactivity_namespaceObject.withSyncEvent)((event) => {
  60        if (event.key !== "ArrowUp" && event.key !== "ArrowDown" && event.key !== "Home" && event.key !== "End") {
  61          return;
  62        }
  63        event.preventDefault();
  64        const context = (0,interactivity_namespaceObject.getContext)();
  65        const { id, accordionItems } = context;
  66        const currentIndex = accordionItems.findIndex(
  67          (item) => item.id === id
  68        );
  69        let nextIndex;
  70        switch (event.key) {
  71          case "ArrowUp":
  72            nextIndex = Math.max(0, currentIndex - 1);
  73            break;
  74          case "ArrowDown":
  75            nextIndex = Math.min(
  76              currentIndex + 1,
  77              accordionItems.length - 1
  78            );
  79            break;
  80          case "Home":
  81            nextIndex = 0;
  82            break;
  83          case "End":
  84            nextIndex = accordionItems.length - 1;
  85            break;
  86        }
  87        const nextId = accordionItems[nextIndex].id;
  88        const nextButton = document.getElementById(nextId);
  89        if (nextButton) {
  90          nextButton.focus();
  91        }
  92      })
  93    },
  94    callbacks: {
  95      initAccordionItems: () => {
  96        const context = (0,interactivity_namespaceObject.getContext)();
  97        const { id, openByDefault } = context;
  98        context.accordionItems.push({
  99          id,
 100          isOpen: openByDefault
 101        });
 102      }
 103    }
 104  });
 105  


Generated : Thu Oct 23 08:20:05 2025 Cross-referenced by PHPXref