2021-07-03 19:04:03 +08:00
|
|
|
import isServer from './isServer'
|
|
|
|
|
|
|
|
const globalNodes = []
|
2021-09-04 19:29:28 +08:00
|
|
|
let target = isServer ? 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)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|