2021-12-12 23:28:03 +08:00
|
|
|
import { isClient } from '@vueuse/core'
|
2021-07-03 19:04:03 +08:00
|
|
|
|
|
|
|
const globalNodes = []
|
2021-12-12 23:28:03 +08:00
|
|
|
let target = !isClient ? undefined : document.body
|
2021-07-03 19:04:03 +08:00
|
|
|
|
|
|
|
export function createGlobalNode(id?: string) {
|
|
|
|
const el = document.createElement('div')
|
|
|
|
|
2021-09-04 19:29:28 +08:00
|
|
|
if (id !== undefined) {
|
2021-07-03 19:04:03 +08:00
|
|
|
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
|
|
|
|
|
2021-09-04 19:29:28 +08:00
|
|
|
globalNodes.forEach((el) => {
|
2021-07-03 19:04:03 +08:00
|
|
|
if (el.contains(target) === false) {
|
|
|
|
target.appendChild(el)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|