index.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var vue = require('vue');
  4. var shared = require('@vue/shared');
  5. require('../../utils/index.js');
  6. var core = require('@vueuse/core');
  7. var globalNode = require('../../utils/vue/global-node.js');
  8. const useTeleport = (contentRenderer, appendToBody) => {
  9. const isTeleportVisible = vue.ref(false);
  10. if (!core.isClient) {
  11. return {
  12. isTeleportVisible,
  13. showTeleport: shared.NOOP,
  14. hideTeleport: shared.NOOP,
  15. renderTeleport: shared.NOOP
  16. };
  17. }
  18. let $el = null;
  19. const showTeleport = () => {
  20. isTeleportVisible.value = true;
  21. if ($el !== null)
  22. return;
  23. $el = globalNode.createGlobalNode();
  24. };
  25. const hideTeleport = () => {
  26. isTeleportVisible.value = false;
  27. if ($el !== null) {
  28. globalNode.removeGlobalNode($el);
  29. $el = null;
  30. }
  31. };
  32. const renderTeleport = () => {
  33. return appendToBody.value !== true ? contentRenderer() : isTeleportVisible.value ? [vue.h(vue.Teleport, { to: $el }, contentRenderer())] : void 0;
  34. };
  35. vue.onUnmounted(hideTeleport);
  36. return {
  37. isTeleportVisible,
  38. showTeleport,
  39. hideTeleport,
  40. renderTeleport
  41. };
  42. };
  43. exports.useTeleport = useTeleport;
  44. //# sourceMappingURL=index.js.map