8000 fix(editor): fix captureDOM for <slot> elements · uimix-editor/uimix@1584b9d · GitHub
[go: up one dir, main page]

Skip to content

Commit 1584b9d

Browse files
committed
fix(editor): fix captureDOM for <slot> elements
1 parent bbe4e55 commit 1584b9d

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

packages/editor/src/util/CaptureDOM.ts

Lines changed: 16 additions & 5 deletions
< 8000 /div>
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,26 @@ function getRenderableAST(node: Node): hast.Element | hast.Text | undefined {
9595
}
9696
attributes.style = styleLines.join("");
9797

98-
const childNodes = element.shadowRoot
99-
? element.shadowRoot.childNodes
100-
: element.tagName === "SLOT"
101-
? (element as HTMLSlotElement).assignedNodes()
102-
: element.childNodes;
98+
const childNodes = getActualChildNodes(element);
10399

104100
const children = compact(Array.from(childNodes).map(getRenderableAST));
105101
const isSVG = element.namespaceURI === "http://www.w3.org/2000/svg";
106102

107103
return (isSVG ? s : h)(element.tagName.toLowerCase(), attributes, children);
108104
}
109105
}
106+
107+
function getActualChildNodes(element: Element): Node[] {
108+
if (element.shadowRoot) {
109+
return [...element.shadowRoot.childNodes];
110+
}
111+
112+
if (element.tagName === "SLOT") {
113+
const assignedNodes = (element as HTMLSlotElement).assignedNodes();
114+
if (assignedNodes.length) {
115+
return assignedNodes;
116+
}
117+
}
118+
119+
return [...element.childNodes];
120+
}

0 commit comments

Comments
 (0)
0