forked from jd-solanki/anu
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ssr): fix ssr for overlay type components (jd-solanki#85)
- Loading branch information
1 parent
5253c6a
commit d5f2e78
Showing
9 changed files
with
163 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// 鈩癸笍 Inspired from Vuetify's useTeleport composable | ||
|
||
import type { Ref } from 'vue' | ||
import { computed, unref } from 'vue' | ||
|
||
export function useTeleport(target?: Ref<string | Element>) { | ||
const teleportTarget = computed(() => { | ||
const _target = unref(target) | ||
|
||
if (typeof window === 'undefined') | ||
return undefined | ||
|
||
const targetElement | ||
= _target === undefined | ||
? document.body | ||
: typeof _target === 'string' | ||
? document.querySelector(_target) | ||
: _target | ||
|
||
if (targetElement == null) { | ||
console.warn(`Unable to locate target ${_target}`) | ||
|
||
return undefined | ||
} | ||
|
||
if (!useTeleport.cache.has(targetElement)) { | ||
const el = document.createElement('div') | ||
el.id = 'a-teleport-target' | ||
targetElement.appendChild(el) | ||
useTeleport.cache.set(targetElement, el) | ||
} | ||
|
||
return useTeleport.cache.get(targetElement) | ||
}) | ||
|
||
return { teleportTarget } | ||
} | ||
useTeleport.cache = new WeakMap<Element, Element>() |
Oops, something went wrong.