index.mjs 778 B

12345678910111213141516171819202122232425
  1. import { EVENT_CODE } from "../../constants/aria.mjs";
  2. import { getEventCode } from "../../utils/dom/event.mjs";
  3. import { isClient, useEventListener } from "@vueuse/core";
  4. import { watch } from "vue";
  5. //#region ../../packages/hooks/use-modal/index.ts
  6. const modalStack = [];
  7. const closeModal = (e) => {
  8. if (modalStack.length === 0) return;
  9. if (getEventCode(e) === EVENT_CODE.esc) {
  10. e.stopPropagation();
  11. modalStack[modalStack.length - 1].handleClose();
  12. }
  13. };
  14. const useModal = (instance, visibleRef) => {
  15. watch(visibleRef, (val) => {
  16. if (val) modalStack.push(instance);
  17. else modalStack.splice(modalStack.indexOf(instance), 1);
  18. });
  19. };
  20. if (isClient) useEventListener(document, "keydown", closeModal);
  21. //#endregion
  22. export { useModal };
  23. //# sourceMappingURL=index.mjs.map