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:
parent
2d3466ebfe
commit
a3d9892841
3 changed files with 45 additions and 2 deletions
|
@ -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
|
|
@ -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'))
|
|
@ -14,8 +14,8 @@ const createEditable = <Keys extends keyof JSX.IntrinsicElements>(
|
||||||
config: EditableFactoryConfig,
|
config: EditableFactoryConfig,
|
||||||
) => {
|
) => {
|
||||||
const editable = <
|
const editable = <
|
||||||
T extends ComponentType<any> | Keys | 'primitive',
|
T extends ComponentType<any> | keyof JSX.IntrinsicElements | 'primitive',
|
||||||
U extends T extends Keys ? T : Keys,
|
U extends Keys,
|
||||||
>(
|
>(
|
||||||
Component: T,
|
Component: T,
|
||||||
type: T extends 'primitive' ? null : U,
|
type: T extends 'primitive' ? null : U,
|
||||||
|
|
Loading…
Reference in a new issue