Skip to content

Commit

Permalink
Clean up NodeView decorations a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
smoores-dev committed Aug 1, 2023
1 parent 0d035a4 commit 37a3519
Showing 1 changed file with 16 additions and 27 deletions.
43 changes: 16 additions & 27 deletions src/components/NodeView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,24 +167,7 @@ export function NodeView({
throw new Error(`Node spec for ${node.type.name} is missing toDOM`);
}

const wrapDecorations: DecorationInternal[] = [];
for (const decoration of decorations) {
if ((decoration.type as NonWidgetType).attrs.nodeName) {
wrapDecorations.push(decoration);
} else {
const {
class: className,
style: _,
...attrs
} = (decoration.type as NonWidgetType).attrs;
element = cloneElement(element, {
className,
...attrs,
});
}
}

return wrapDecorations.reduce(
return decorations.reduce(
(element, deco) => {
const {
nodeName,
Expand All @@ -193,15 +176,21 @@ export function NodeView({
...attrs
} = (deco.type as NonWidgetType).attrs;

return createElement(
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
nodeName!,
{
className,
...attrs,
},
element
);
if (nodeName) {
return createElement(
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
nodeName!,
{
className,
...attrs,
},
element
);
}
return cloneElement(element, {
className,
...attrs,
});
},

node.marks.reduce(
Expand Down

0 comments on commit 37a3519

Please sign in to comment.