Relax editable TS types to allow creating editable versions of all the JSX.IntrinsicElements elements. (#237)

Enable custom editable components through relaxed typescript types
This commit is contained in:
Andrew Prifer 2022-06-28 18:11:28 +02:00 committed by GitHub
parent 2d3466ebfe
commit a3d9892841
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 2 deletions

View file

@ -0,0 +1,33 @@
import {editable as e, SheetProvider} from '@theatre/r3f'
import {getProject} from '@theatre/core'
import React from 'react'
import {Canvas} from '@react-three/fiber'
const EditablePoints = e('points', 'mesh')
function App() {
return (
<div
style={{
height: '100vh',
}}
>
<Canvas
dpr={[1.5, 2]}
linear
gl={{preserveDrawingBuffer: true}}
frameloop="demand"
>
<SheetProvider sheet={getProject('Space').sheet('Scene')}>
<ambientLight intensity={0.75} />
<EditablePoints uniqueName="points">
<torusKnotGeometry args={[1, 0.3, 128, 64]} />
<meshNormalMaterial />
</EditablePoints>
</SheetProvider>
</Canvas>
</div>
)
}
export default App

View file

@ -0,0 +1,10 @@
import React from 'react'
import ReactDOM from 'react-dom'
import App from './App'
import studio from '@theatre/studio'
import extension from '@theatre/r3f/dist/extension'
studio.extend(extension)
studio.initialize()
ReactDOM.render(<App />, document.getElementById('root'))

View file

@ -14,8 +14,8 @@ const createEditable = <Keys extends keyof JSX.IntrinsicElements>(
config: EditableFactoryConfig,
) => {
const editable = <
T extends ComponentType<any> | Keys | 'primitive',
U extends T extends Keys ? T : Keys,
T extends ComponentType<any> | keyof JSX.IntrinsicElements | 'primitive',
U extends Keys,
>(
Component: T,
type: T extends 'primitive' ? null : U,