|
|
|
@ -682,12 +682,15 @@ export function htmlToSpan(html: string) {
@@ -682,12 +682,15 @@ export function htmlToSpan(html: string) {
|
|
|
|
|
|
|
|
|
|
export function replaceContent(elem: HTMLElement, node: string | Node) { |
|
|
|
|
// * children.length doesn't count text nodes
|
|
|
|
|
if(elem.children.length) { |
|
|
|
|
elem.firstChild.replaceWith(node); |
|
|
|
|
} else if(!elem.firstChild) { |
|
|
|
|
elem.append(node); |
|
|
|
|
const firstChild = elem.firstChild; |
|
|
|
|
if(firstChild) { |
|
|
|
|
if(elem.lastChild === firstChild) { |
|
|
|
|
firstChild.replaceWith(node); |
|
|
|
|
} else { |
|
|
|
|
elem.textContent = ''; |
|
|
|
|
elem.append(node); |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
elem.textContent = ''; |
|
|
|
|
elem.append(node); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|