Add ability to provide additional props to editable objects and get the sheet ref from the component
This commit is contained in:
parent
81578f7925
commit
2794e0df26
1 changed files with 20 additions and 3 deletions
|
@ -40,6 +40,8 @@ const editable = <
|
||||||
type Props = Omit<ComponentProps<T>, 'visible'> & {
|
type Props = Omit<ComponentProps<T>, 'visible'> & {
|
||||||
uniqueName: string
|
uniqueName: string
|
||||||
visible?: boolean | 'editor'
|
visible?: boolean | 'editor'
|
||||||
|
additionalProps?: $FixMe
|
||||||
|
objRef?: $FixMe
|
||||||
} & (T extends 'primitive'
|
} & (T extends 'primitive'
|
||||||
? {
|
? {
|
||||||
editableType: U
|
editableType: U
|
||||||
|
@ -48,7 +50,17 @@ const editable = <
|
||||||
RefAttributes<Elements[U]>
|
RefAttributes<Elements[U]>
|
||||||
|
|
||||||
return forwardRef(
|
return forwardRef(
|
||||||
({uniqueName, visible, editableType, ...props}: Props, ref) => {
|
(
|
||||||
|
{
|
||||||
|
uniqueName,
|
||||||
|
visible,
|
||||||
|
editableType,
|
||||||
|
additionalProps,
|
||||||
|
objRef,
|
||||||
|
...props
|
||||||
|
}: Props,
|
||||||
|
ref,
|
||||||
|
) => {
|
||||||
const objectRef = useRef<Elements[U]>()
|
const objectRef = useRef<Elements[U]>()
|
||||||
|
|
||||||
const sheet = useCurrentSheet()
|
const sheet = useCurrentSheet()
|
||||||
|
@ -61,14 +73,19 @@ const editable = <
|
||||||
|
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
if (!sheet) return
|
if (!sheet) return
|
||||||
const sheetObject = sheet.object(uniqueName, baseSheetObjectType)
|
const sheetObject = sheet.object(uniqueName, {
|
||||||
|
...baseSheetObjectType,
|
||||||
|
...additionalProps,
|
||||||
|
})
|
||||||
allRegisteredObjects.add(sheetObject)
|
allRegisteredObjects.add(sheetObject)
|
||||||
setSheetObject(sheetObject)
|
setSheetObject(sheetObject)
|
||||||
|
|
||||||
|
if (objRef) objRef!.current = sheetObject
|
||||||
|
|
||||||
useEditorStore
|
useEditorStore
|
||||||
.getState()
|
.getState()
|
||||||
.setSheetObject(uniqueName, sheetObject as $FixMe)
|
.setSheetObject(uniqueName, sheetObject as $FixMe)
|
||||||
}, [sheet, uniqueName])
|
}, [sheet, uniqueName, additionalProps])
|
||||||
|
|
||||||
const transformDeps: string[] = []
|
const transformDeps: string[] = []
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue