版博士V2.0程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

87 строки
2.6 KiB

  1. 'use strict';
  2. var core = require('@vueuse/core');
  3. var vueDemi = require('vue-demi');
  4. var focusTrap = require('focus-trap');
  5. var __defProp = Object.defineProperty;
  6. var __defProps = Object.defineProperties;
  7. var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
  8. var __getOwnPropSymbols = Object.getOwnPropertySymbols;
  9. var __hasOwnProp = Object.prototype.hasOwnProperty;
  10. var __propIsEnum = Object.prototype.propertyIsEnumerable;
  11. var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
  12. var __spreadValues = (a, b) => {
  13. for (var prop in b || (b = {}))
  14. if (__hasOwnProp.call(b, prop))
  15. __defNormalProp(a, prop, b[prop]);
  16. if (__getOwnPropSymbols)
  17. for (var prop of __getOwnPropSymbols(b)) {
  18. if (__propIsEnum.call(b, prop))
  19. __defNormalProp(a, prop, b[prop]);
  20. }
  21. return a;
  22. };
  23. var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
  24. var __objRest = (source, exclude) => {
  25. var target = {};
  26. for (var prop in source)
  27. if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
  28. target[prop] = source[prop];
  29. if (source != null && __getOwnPropSymbols)
  30. for (var prop of __getOwnPropSymbols(source)) {
  31. if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
  32. target[prop] = source[prop];
  33. }
  34. return target;
  35. };
  36. function useFocusTrap(target, options = {}) {
  37. let trap;
  38. const _a = options, { immediate } = _a, focusTrapOptions = __objRest(_a, ["immediate"]);
  39. const hasFocus = vueDemi.ref(false);
  40. const isPaused = vueDemi.ref(false);
  41. const activate = (opts) => trap && trap.activate(opts);
  42. const deactivate = (opts) => trap && trap.deactivate(opts);
  43. const pause = () => {
  44. if (trap) {
  45. trap.pause();
  46. isPaused.value = true;
  47. }
  48. };
  49. const unpause = () => {
  50. if (trap) {
  51. trap.unpause();
  52. isPaused.value = false;
  53. }
  54. };
  55. vueDemi.watch(() => core.unrefElement(target), (el) => {
  56. if (!el)
  57. return;
  58. trap = focusTrap.createFocusTrap(el, __spreadProps(__spreadValues({}, focusTrapOptions), {
  59. onActivate() {
  60. hasFocus.value = true;
  61. if (options.onActivate)
  62. options.onActivate();
  63. },
  64. onDeactivate() {
  65. hasFocus.value = false;
  66. if (options.onDeactivate)
  67. options.onDeactivate();
  68. }
  69. }));
  70. if (immediate)
  71. activate();
  72. }, { flush: "post" });
  73. core.tryOnScopeDispose(() => deactivate());
  74. return {
  75. hasFocus,
  76. isPaused,
  77. activate,
  78. deactivate,
  79. pause,
  80. unpause
  81. };
  82. }
  83. exports.useFocusTrap = useFocusTrap;