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.

1 line
2.5 KiB

{"version":3,"file":"index.js","sources":["../../../../../packages/hooks/use-teleport/index.ts"],"sourcesContent":["import { Teleport, h, onUnmounted, ref } from 'vue'\nimport {\n NOOP,\n createGlobalNode,\n isClient,\n removeGlobalNode,\n} from '@element-plus/utils'\n\nimport type { Ref, VNode } from 'vue'\n\nexport const useTeleport = (\n contentRenderer: () => VNode,\n appendToBody: Ref<boolean>\n) => {\n const isTeleportVisible = ref(false)\n\n if (!isClient) {\n return {\n isTeleportVisible,\n showTeleport: NOOP,\n hideTeleport: NOOP,\n renderTeleport: NOOP,\n }\n }\n\n let $el: HTMLElement | null = null\n\n const showTeleport = () => {\n isTeleportVisible.value = true\n // this allows the delayed showing strategy since the the content itself could be enterable\n // e.g. el-popper\n if ($el !== null) return\n\n $el = createGlobalNode()\n }\n\n const hideTeleport = () => {\n isTeleportVisible.value = false\n if ($el !== null) {\n removeGlobalNode($el)\n $el = null\n }\n }\n\n const renderTeleport = () => {\n return appendToBody.value !== true\n ? contentRenderer()\n : isTeleportVisible.value\n ? [h(Teleport, { to: $el }, contentRenderer())]\n : undefined\n }\n\n onUnmounted(hideTeleport)\n\n return {\n isTeleportVisible,\n showTeleport,\n hideTeleport,\n renderTeleport,\n }\n}\n"],"names":["ref","isClient","NOOP","createGlobalNode","removeGlobalNode","h","Teleport","onUnmounted"],"mappings":";;;;;;;;;;AAOY,MAAC,WAAW,GAAG,CAAC,eAAe,EAAE,YAAY,KAAK;AAC9D,EAAE,MAAM,iBAAiB,GAAGA,OAAG,CAAC,KAAK,CAAC,CAAC;AACvC,EAAE,IAAI,CAACC,aAAQ,EAAE;AACjB,IAAI,OAAO;AACX,MAAM,iBAAiB;AACvB,MAAM,YAAY,EAAEC,WAAI;AACxB,MAAM,YAAY,EAAEA,WAAI;AACxB,MAAM,cAAc,EAAEA,WAAI;AAC1B,KAAK,CAAC;AACN,GAAG;AACH,EAAE,IAA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