You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
794 B

1 month ago
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var vue = require('vue');
  4. var core = require('@vueuse/core');
  5. var aria = require('../../constants/aria.js');
  6. const modalStack = [];
  7. const closeModal = (e) => {
  8. if (modalStack.length === 0)
  9. return;
  10. if (e.code === aria.EVENT_CODE.esc) {
  11. e.stopPropagation();
  12. const topModal = modalStack[modalStack.length - 1];
  13. topModal.handleClose();
  14. }
  15. };
  16. const useModal = (instance, visibleRef) => {
  17. vue.watch(visibleRef, (val) => {
  18. if (val) {
  19. modalStack.push(instance);
  20. } else {
  21. modalStack.splice(modalStack.indexOf(instance), 1);
  22. }
  23. });
  24. };
  25. if (core.isClient)
  26. core.useEventListener(document, "keydown", closeModal);
  27. exports.useModal = useModal;
  28. //# sourceMappingURL=index.js.map