index.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var vue = require('vue');
  4. require('../../utils/index.js');
  5. var index = require('../use-namespace/index.js');
  6. var index$1 = require('../use-id/index.js');
  7. var core = require('@vueuse/core');
  8. let cachedContainer;
  9. const usePopperContainerId = () => {
  10. const namespace = index.useGetDerivedNamespace();
  11. const idInjection = index$1.useIdInjection();
  12. const id = vue.computed(() => {
  13. return `${namespace.value}-popper-container-${idInjection.prefix}`;
  14. });
  15. const selector = vue.computed(() => `#${id.value}`);
  16. return {
  17. id,
  18. selector
  19. };
  20. };
  21. const createContainer = (id) => {
  22. const container = document.createElement("div");
  23. container.id = id;
  24. document.body.appendChild(container);
  25. return container;
  26. };
  27. const usePopperContainer = () => {
  28. const { id, selector } = usePopperContainerId();
  29. vue.onBeforeMount(() => {
  30. if (!core.isClient)
  31. return;
  32. if (process.env.NODE_ENV === "test" || !cachedContainer && !document.body.querySelector(selector.value)) {
  33. cachedContainer = createContainer(id.value);
  34. }
  35. });
  36. return {
  37. id,
  38. selector
  39. };
  40. };
  41. exports.usePopperContainer = usePopperContainer;
  42. exports.usePopperContainerId = usePopperContainerId;
  43. //# sourceMappingURL=index.js.map