Normalize theatre keys in r3f (#317)
Also remove a stray console log and make makeStoreKey make more sense.
This commit is contained in:
parent
54ed4c3c41
commit
29e036638b
4 changed files with 21 additions and 33 deletions
|
@ -22,7 +22,7 @@ export function useSelected(): undefined | string {
|
||||||
if (!item) {
|
if (!item) {
|
||||||
set(undefined)
|
set(undefined)
|
||||||
} else {
|
} else {
|
||||||
set(makeStoreKey(item.sheet, item.address.objectKey))
|
set(makeStoreKey(item.address))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setFromStudio(studio.selection)
|
setFromStudio(studio.selection)
|
||||||
|
@ -41,6 +41,6 @@ export function getSelected(): undefined | string {
|
||||||
if (!item) {
|
if (!item) {
|
||||||
return undefined
|
return undefined
|
||||||
} else {
|
} else {
|
||||||
return makeStoreKey(item.sheet, item.address.objectKey)
|
return makeStoreKey(item.address)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,7 @@
|
||||||
import type {ComponentProps, ComponentType, Ref, RefAttributes} from 'react'
|
import type {ComponentProps, ComponentType, Ref, RefAttributes} from 'react'
|
||||||
import React, {
|
import React, {forwardRef, useEffect, useLayoutEffect, useRef} from 'react'
|
||||||
forwardRef,
|
|
||||||
useEffect,
|
|
||||||
useLayoutEffect,
|
|
||||||
useRef,
|
|
||||||
useState,
|
|
||||||
} from 'react'
|
|
||||||
import {allRegisteredObjects, editorStore} from './store'
|
import {allRegisteredObjects, editorStore} from './store'
|
||||||
import mergeRefs from 'react-merge-refs'
|
import mergeRefs from 'react-merge-refs'
|
||||||
import type {ISheetObject} from '@theatre/core'
|
|
||||||
import useInvalidate from './useInvalidate'
|
import useInvalidate from './useInvalidate'
|
||||||
import {useCurrentSheet} from './SheetProvider'
|
import {useCurrentSheet} from './SheetProvider'
|
||||||
import defaultEditableFactoryConfig from './defaultEditableFactoryConfig'
|
import defaultEditableFactoryConfig from './defaultEditableFactoryConfig'
|
||||||
|
@ -56,11 +49,21 @@ const createEditable = <Keys extends keyof JSX.IntrinsicElements>(
|
||||||
|
|
||||||
const sheet = useCurrentSheet()!
|
const sheet = useCurrentSheet()!
|
||||||
|
|
||||||
const storeKey = makeStoreKey(sheet, theatreKey)
|
const sheetObject = sheet.object(
|
||||||
|
theatreKey,
|
||||||
|
Object.assign(
|
||||||
|
{
|
||||||
|
...additionalProps,
|
||||||
|
},
|
||||||
|
// @ts-ignore
|
||||||
|
...Object.values(config[actualType].props).map(
|
||||||
|
// @ts-ignore
|
||||||
|
(value) => value.type,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
const [sheetObject, setSheetObject] = useState<
|
const storeKey = makeStoreKey(sheetObject.address)
|
||||||
undefined | ISheetObject<$FixMe>
|
|
||||||
>(undefined)
|
|
||||||
|
|
||||||
const invalidate = useInvalidate()
|
const invalidate = useInvalidate()
|
||||||
|
|
||||||
|
@ -99,21 +102,8 @@ Then you can use it in your JSX like any other editable component. Note the make
|
||||||
// create sheet object and add editable to store
|
// create sheet object and add editable to store
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
if (!sheet) return
|
if (!sheet) return
|
||||||
const sheetObject = sheet.object(
|
|
||||||
theatreKey,
|
|
||||||
Object.assign(
|
|
||||||
{
|
|
||||||
...additionalProps,
|
|
||||||
},
|
|
||||||
// @ts-ignore
|
|
||||||
...Object.values(config[actualType].props).map(
|
|
||||||
// @ts-ignore
|
|
||||||
(value) => value.type,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
allRegisteredObjects.add(sheetObject)
|
allRegisteredObjects.add(sheetObject)
|
||||||
setSheetObject(sheetObject)
|
|
||||||
|
|
||||||
if (objRef)
|
if (objRef)
|
||||||
typeof objRef === 'function'
|
typeof objRef === 'function'
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import {editorStore} from './store'
|
import {editorStore} from './store'
|
||||||
import type {ISheet} from '@theatre/core'
|
import type {ISheetObject} from '@theatre/core'
|
||||||
|
|
||||||
export const refreshSnapshot = editorStore.getState().createSnapshot
|
export const refreshSnapshot = editorStore.getState().createSnapshot
|
||||||
|
|
||||||
export const makeStoreKey = (sheet: ISheet, name: string) =>
|
export const makeStoreKey = (sheetObjectAddress: ISheetObject['address']) =>
|
||||||
`${sheet.address.sheetId}:${sheet.address.sheetInstanceId}:${name}`
|
`${sheetObjectAddress.sheetId}:${sheetObjectAddress.sheetInstanceId}:${sheetObjectAddress.objectKey}`
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import type {} from '@theatre/core/projects/store/types/SheetState_Historic'
|
|
||||||
import type {
|
import type {
|
||||||
PropTypeConfig,
|
PropTypeConfig,
|
||||||
PropTypeConfig_AllSimples,
|
PropTypeConfig_AllSimples,
|
||||||
|
@ -359,6 +358,5 @@ export const calculateSequenceEditorTree = (
|
||||||
topSoFar += row.nodeHeight
|
topSoFar += row.nodeHeight
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log('tree :)', tree)
|
|
||||||
return tree
|
return tree
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue