mirror of
https://github.com/element-plus/element-plus.git
synced 2024-12-27 03:01:14 +08:00
913aaafabb
* feat(hooks) add use-teleport hook - Add teleport hook for teleported components - Add teleport hooks hepler methods - Add coresponding testing cases * - add use teleport to the exporting entry
35 lines
649 B
TypeScript
35 lines
649 B
TypeScript
import isServer from './isServer'
|
|
|
|
const globalNodes = []
|
|
let target = isServer ? void 0 : document.body
|
|
|
|
export function createGlobalNode(id?: string) {
|
|
const el = document.createElement('div')
|
|
|
|
if (id !== void 0) {
|
|
el.id = id
|
|
}
|
|
|
|
target.appendChild(el)
|
|
globalNodes.push(el)
|
|
|
|
return el
|
|
}
|
|
|
|
export function removeGlobalNode(el: HTMLElement) {
|
|
globalNodes.splice(globalNodes.indexOf(el), 1)
|
|
el.remove()
|
|
}
|
|
|
|
export function changeGlobalNodesTarget(el: HTMLElement) {
|
|
if (el !== target) {
|
|
target = el
|
|
|
|
globalNodes.forEach(el => {
|
|
if (el.contains(target) === false) {
|
|
target.appendChild(el)
|
|
}
|
|
})
|
|
}
|
|
}
|