import type {VFC} from 'react' import React, { useEffect, useLayoutEffect, useRef, useState, Suspense, } from 'react' import {Canvas} from '@react-three/fiber' import {useEditorStore} from '../store' import {OrbitControls, Environment} from '@react-three/drei' import shallow from 'zustand/shallow' import root from 'react-shadow' import styles from '../bundle.css.txt' import UI from './UI' import ProxyManager from './ProxyManager' import { Button, Heading, Code, PortalManager, Modal, ModalHeader, ModalFooter, ModalBody, IdProvider, } from './elements' import studio from '@theatre/studio' const EditorScene = () => { const orbitControlsRef = useRef() const [ selectedHdr, useHdrAsBackground, showGrid, showAxes, helpersRoot, setOrbitControlsRef, ] = useEditorStore( (state) => [ state.selectedHdr, state.useHdrAsBackground, state.showGrid, state.showAxes, state.helpersRoot, state.setOrbitControlsRef, ], shallow, ) useEffect(() => { setOrbitControlsRef(orbitControlsRef) }, [setOrbitControlsRef]) return ( <> {selectedHdr && ( )} {showGrid && } {showAxes && } {/* @ts-ignore */} ) } const Editor: VFC = () => { const [ sceneSnapshot, editorOpen, initialState, initialEditorCamera, setEditorOpen, createSnapshot, isPersistedStateDifferentThanInitial, applyPersistedState, ] = useEditorStore( (state) => [ state.sceneSnapshot, state.editorOpen, state.initialState, state.initialEditorCamera, state.setEditorOpen, state.createSnapshot, state.isPersistedStateDifferentThanInitial, state.applyPersistedState, ], shallow, ) const [stateMismatch, setStateMismatch] = useState(false) useLayoutEffect(() => { if (initialState) { setStateMismatch(isPersistedStateDifferentThanInitial()) } else { applyPersistedState() } }, [applyPersistedState, initialState, isPersistedStateDifferentThanInitial]) return (
{sceneSnapshot ? ( <>
{ gl.setClearColor('white') }} shadowMap pixelRatio={window.devicePixelRatio} onPointerMissed={() => studio.__experimental_setSelection([]) } >
) : (
No canvas connected
Please use configure() and{' '} bind() to connect a canvas to React Three Editable.
{`import React from 'react'; import { Canvas } from '@react-three/fiber'; import { configure, editable as e } from 'react-three-editable'; const bind = configure({ localStorageNamespace: "MyProject" }); const MyComponent = () => ( );`}
For more details, please consult the{' '} documentation .
)}
{editorOpen || ( )}
Saved state found Would you like to use initial state or saved state?
) } export default Editor