Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions packages/core/src/components/ComponentBuilder/ComponentBuilder.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import React, { ComponentType, Fragment, ReactElement } from "react";
import React, {
ComponentType,
Fragment,
ReactElement,
Ref,
forwardRef,
} from "react";
import { findComponentDefinitionById } from "../../compiler/findComponentDefinition";
import {
isSchemaPropComponent,
Expand Down Expand Up @@ -319,7 +325,10 @@ export type InternalNoCodeComponentProps = NoCodeComponentProps & {
};
};

function ComponentBuilder(props: ComponentBuilderProps): ReactElement | null {
const ComponentBuilder = forwardRef(function ComponentBuilder(
props: ComponentBuilderProps,
ref: Ref<unknown>
): ReactElement | null {
const { compiled, passedProps, path, components, ...restProps } = props;

const allPassedProps: Record<string, any> = {
Expand Down Expand Up @@ -431,7 +440,7 @@ function ComponentBuilder(props: ComponentBuilderProps): ReactElement | null {
});

// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { ref, __isSelected, ...restPassedProps } = allPassedProps || {};
const { __isSelected, ...restPassedProps } = allPassedProps || {};

const runtime = {
stitches: meta.stitches,
Expand Down Expand Up @@ -459,8 +468,8 @@ function ComponentBuilder(props: ComponentBuilderProps): ReactElement | null {
__easyblocks: easyblocksProp,
};

return <Component {...componentProps} />;
}
return <Component {...componentProps} ref={ref} />;
});

function getComponent(
componentDefinition: InternalComponentDefinition,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ import {
ComponentBuilder,
ComponentBuilderProps,
} from "@easyblocks/core/_internals";
import React from "react";
import React, { Ref, forwardRef } from "react";
import { BlocksControls } from "./BlockControls";

type EditableComponentBuilderProps = ComponentBuilderProps & {
index: number;
length: number;
};

function EditableComponentBuilder(props: EditableComponentBuilderProps) {
const EditableComponentBuilder = forwardRef(function EditableComponentBuilder(
props: EditableComponentBuilderProps,
ref: Ref<unknown>
) {
const { path, compiled, index, length, components, ...restPassedProps } =
props;

Expand All @@ -30,11 +33,12 @@ function EditableComponentBuilder(props: EditableComponentBuilderProps) {
path={path}
passedProps={restPassedProps}
components={components}
ref={ref}
/>
</BlocksControls>
);

return content;
}
});

export default EditableComponentBuilder;