From 2794e0df26c201c02b665b3ee8387ebe771fd6a5 Mon Sep 17 00:00:00 2001 From: Or Fleisher Date: Tue, 12 Oct 2021 17:14:03 -0400 Subject: [PATCH] Add ability to provide additional props to editable objects and get the sheet ref from the component --- packages/r3f/src/components/editable.tsx | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/packages/r3f/src/components/editable.tsx b/packages/r3f/src/components/editable.tsx index bff0d5e..9072d6a 100644 --- a/packages/r3f/src/components/editable.tsx +++ b/packages/r3f/src/components/editable.tsx @@ -40,6 +40,8 @@ const editable = < type Props = Omit, 'visible'> & { uniqueName: string visible?: boolean | 'editor' + additionalProps?: $FixMe + objRef?: $FixMe } & (T extends 'primitive' ? { editableType: U @@ -48,7 +50,17 @@ const editable = < RefAttributes return forwardRef( - ({uniqueName, visible, editableType, ...props}: Props, ref) => { + ( + { + uniqueName, + visible, + editableType, + additionalProps, + objRef, + ...props + }: Props, + ref, + ) => { const objectRef = useRef() const sheet = useCurrentSheet() @@ -61,14 +73,19 @@ const editable = < useLayoutEffect(() => { if (!sheet) return - const sheetObject = sheet.object(uniqueName, baseSheetObjectType) + const sheetObject = sheet.object(uniqueName, { + ...baseSheetObjectType, + ...additionalProps, + }) allRegisteredObjects.add(sheetObject) setSheetObject(sheetObject) + if (objRef) objRef!.current = sheetObject + useEditorStore .getState() .setSheetObject(uniqueName, sheetObject as $FixMe) - }, [sheet, uniqueName]) + }, [sheet, uniqueName, additionalProps]) const transformDeps: string[] = []