Skip to content

Commit

Permalink
fix: change how aboveNodes/belowNodes are applied
Browse files Browse the repository at this point in the history
  • Loading branch information
yf-yang committed Jan 25, 2025
1 parent e71cbcc commit b012dc1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
5 changes: 5 additions & 0 deletions .changeset/eight-melons-perform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@udecode/plate-core': patch
---

change `aboveNodes` and `belowNodes` to React component instead of direct function call"
12 changes: 6 additions & 6 deletions packages/core/src/lib/static/pluginRenderElementStatic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ export const pluginRenderElementStatic = (
}) as any;

belowNodes.forEach((withHOC) => {
const hoc = withHOC({ ...nodeProps, key } as any);
const HOC = withHOC({ ...nodeProps, key } as any);

if (hoc) {
children = hoc({ ...nodeProps, children } as any);
if (HOC) {
children = <HOC {...nodeProps}>{children}</HOC>;
}
});

Expand All @@ -59,10 +59,10 @@ export const pluginRenderElementStatic = (
);

aboveNodes.forEach((withHOC) => {
const hoc = withHOC({ ...nodeProps, key } as any);
const HOC = withHOC({ ...nodeProps, key } as any);

if (hoc) {
component = hoc({ ...nodeProps, children: component } as any);
if (HOC) {
component = <HOC {...nodeProps}>{component}</HOC>;
}
});

Expand Down
12 changes: 6 additions & 6 deletions packages/core/src/react/utils/pluginRenderElement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,20 @@ function ElementContent({
let children = _children;

belowNodes.forEach((withHOC) => {
const hoc = withHOC({ ...nodeProps, key } as any);
const HOC = withHOC({ ...nodeProps, key } as any);

if (hoc) {
children = hoc({ ...nodeProps, children } as any);
if (HOC) {
children = <HOC {...nodeProps}>{children}</HOC>;
}
});

let component: React.ReactNode = <Element {...nodeProps}>{children}</Element>;

aboveNodes.forEach((withHOC) => {
const hoc = withHOC({ ...nodeProps, key } as any);
const HOC = withHOC({ ...nodeProps, key } as any);

if (hoc) {
component = hoc({ ...nodeProps, children: component } as any);
if (HOC) {
component = <HOC {...nodeProps}>{component}</HOC>;
}
});

Expand Down

0 comments on commit b012dc1

Please sign in to comment.