Re-do bundling, compat tests, and extension API (#174)
This commit is contained in:
parent
5ee9a2543f
commit
ec18687a98
83 changed files with 1138 additions and 886 deletions
5
compatibility-tests/.gitignore
vendored
Normal file
5
compatibility-tests/.gitignore
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
# these lock files include checksums of the @theatre/*@compat packages, which
|
||||
# would change after every edit to their source, so we better not keep them
|
||||
# in the repo
|
||||
/*/package-lock.json
|
||||
/*/yarn.lock
|
|
@ -3,7 +3,8 @@
|
|||
"private": true,
|
||||
"scripts": {
|
||||
"registry:start": "zx ./scripts/start-registry.mjs",
|
||||
"test:ci": "zx ./scripts/ci.mjs"
|
||||
"test:ci": "zx ./scripts/ci.mjs",
|
||||
"clean": "zx ./scripts/clean.mjs"
|
||||
},
|
||||
"dependencies": {
|
||||
"node-cleanup": "^2.1.2",
|
||||
|
@ -12,5 +13,6 @@
|
|||
"verdaccio-auth-memory": "^10.2.0",
|
||||
"verdaccio-memory": "^10.2.0",
|
||||
"zx": "^6.1.0"
|
||||
}
|
||||
},
|
||||
"version": "0.0.1-COMPAT.1"
|
||||
}
|
||||
|
|
3
compatibility-tests/scripts/clean.mjs
Normal file
3
compatibility-tests/scripts/clean.mjs
Normal file
|
@ -0,0 +1,3 @@
|
|||
import {clean} from './utils.mjs'
|
||||
|
||||
await clean()
|
|
@ -2,9 +2,8 @@
|
|||
* Utility functions for the compatibility tests
|
||||
*/
|
||||
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import {YAML} from 'zx'
|
||||
import {globby, YAML} from 'zx'
|
||||
import onCleanup from 'node-cleanup'
|
||||
import * as verdaccioPackage from 'verdaccio'
|
||||
|
||||
|
@ -14,6 +13,7 @@ const startVerdaccioServer = verdaccioPackage.default.default
|
|||
export const VERDACCIO_PORT = 4823
|
||||
export const VERDACCIO_HOST = `localhost`
|
||||
export const VERDACCIO_URL = `http://${VERDACCIO_HOST}:${VERDACCIO_PORT}/`
|
||||
export const PATH_TO_COMPAT_TESTS_ROOT = path.join(__dirname, '..')
|
||||
export const MONOREPO_ROOT = path.join(__dirname, '../..')
|
||||
export const PATH_TO_YARNRC = path.join(MONOREPO_ROOT, '.yarnrc.yml')
|
||||
|
||||
|
@ -259,3 +259,23 @@ export function getCompatibilityTestSetups() {
|
|||
|
||||
return setupsAbsPaths
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes ../test-*\/(node_modules|package-lock.json|yarn.lock)
|
||||
*/
|
||||
export async function clean() {
|
||||
const toDelete = await globby(
|
||||
'./test-*/(node_modules|yarn.lock|package-lock.json)',
|
||||
{
|
||||
cwd: PATH_TO_COMPAT_TESTS_ROOT,
|
||||
// node_modules et al are gitignored, but we still want to clean them
|
||||
gitignore: false,
|
||||
// include directories too
|
||||
onlyFiles: false,
|
||||
},
|
||||
)
|
||||
toDelete.forEach((fileOrDir) => {
|
||||
console.log('deleting', fileOrDir)
|
||||
fs.removeSync(path.join(PATH_TO_COMPAT_TESTS_ROOT, fileOrDir))
|
||||
})
|
||||
}
|
||||
|
|
1
compatibility-tests/test-cra-react18/README.md
Normal file
1
compatibility-tests/test-cra-react18/README.md
Normal file
|
@ -0,0 +1 @@
|
|||
Testing `@theatre/core` and `@theatre/studio` with `npm`, `create-react-app`, and `react@18`
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"name": "@theatre-build-tests/react-app",
|
||||
"name": "@compat/cra-react18",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
|
@ -15,7 +15,6 @@
|
|||
"@testing-library/user-event": "^12.1.10",
|
||||
"@theatre/core": "^0.0.1-COMPAT.1",
|
||||
"@theatre/studio": "^0.0.1-COMPAT.1",
|
||||
"@theatre/r3f": "^0.0.1-COMPAT.1",
|
||||
"react-scripts": "^5.0.1",
|
||||
"three": ">0.132.0",
|
||||
"web-vitals": "^1.0.1"
|
|
@ -2,19 +2,13 @@
|
|||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<meta name="theme-color" content="#000000" />
|
||||
<meta
|
||||
name="description"
|
||||
content="Web site created using create-react-app"
|
||||
/>
|
||||
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
|
||||
<!--
|
||||
manifest.json provides metadata used when your web app is installed on a
|
||||
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
|
||||
-->
|
||||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
|
||||
|
||||
<!--
|
||||
Notice the use of %PUBLIC_URL% in the tags above.
|
||||
It will be replaced with the URL of the `public` folder during the build.
|
6
compatibility-tests/test-cra-react18/src/App.js
Normal file
6
compatibility-tests/test-cra-react18/src/App.js
Normal file
|
@ -0,0 +1,6 @@
|
|||
import React from 'react'
|
||||
|
||||
export default function App({obj}) {
|
||||
console.log(obj)
|
||||
return <div>hi</div>
|
||||
}
|
19
compatibility-tests/test-cra-react18/src/index.js
Normal file
19
compatibility-tests/test-cra-react18/src/index.js
Normal file
|
@ -0,0 +1,19 @@
|
|||
// import ReactDOM from 'react-dom'
|
||||
|
||||
import studio from '@theatre/studio'
|
||||
import {getProject} from '@theatre/core'
|
||||
// import React from 'react'
|
||||
// import App from './App'
|
||||
|
||||
studio.initialize({usePersistentStorage: false})
|
||||
|
||||
const project = getProject('Project')
|
||||
const sheet = project.sheet('Sheet')
|
||||
const obj = sheet.object('Obj', {str: 'some string', num: 0})
|
||||
|
||||
// ReactDOM.render(
|
||||
// <React.StrictMode>
|
||||
// <App obj={obj} />
|
||||
// </React.StrictMode>,
|
||||
// document.getElementById('root'),
|
||||
// )
|
|
@ -1,16 +0,0 @@
|
|||
# Theatre.js project with `create-react-app` using the `r3f extension`
|
||||
|
||||
## Setup
|
||||
|
||||
Please refer to [this guide](../README.md#testing-the-configurations-locally).
|
||||
|
||||
## Usage
|
||||
|
||||
- start the development server:
|
||||
```sh
|
||||
yarn start
|
||||
```
|
||||
- build the project:
|
||||
```sh
|
||||
yarn build
|
||||
```
|
Binary file not shown.
Before Width: | Height: | Size: 3.8 KiB |
Binary file not shown.
Before Width: | Height: | Size: 5.2 KiB |
Binary file not shown.
Before Width: | Height: | Size: 9.4 KiB |
|
@ -1,25 +0,0 @@
|
|||
{
|
||||
"short_name": "React App",
|
||||
"name": "Create React App Sample",
|
||||
"icons": [
|
||||
{
|
||||
"src": "favicon.ico",
|
||||
"sizes": "64x64 32x32 24x24 16x16",
|
||||
"type": "image/x-icon"
|
||||
},
|
||||
{
|
||||
"src": "logo192.png",
|
||||
"type": "image/png",
|
||||
"sizes": "192x192"
|
||||
},
|
||||
{
|
||||
"src": "logo512.png",
|
||||
"type": "image/png",
|
||||
"sizes": "512x512"
|
||||
}
|
||||
],
|
||||
"start_url": ".",
|
||||
"display": "standalone",
|
||||
"theme_color": "#000000",
|
||||
"background_color": "#ffffff"
|
||||
}
|
|
@ -1,3 +0,0 @@
|
|||
# https://www.robotstxt.org/robotstxt.html
|
||||
User-agent: *
|
||||
Disallow:
|
|
@ -1,38 +0,0 @@
|
|||
.App {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.App-logo {
|
||||
height: 40vmin;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: no-preference) {
|
||||
.App-logo {
|
||||
animation: App-logo-spin infinite 20s linear;
|
||||
}
|
||||
}
|
||||
|
||||
.App-header {
|
||||
background-color: #282c34;
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: calc(10px + 2vmin);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.App-link {
|
||||
color: #61dafb;
|
||||
}
|
||||
|
||||
@keyframes App-logo-spin {
|
||||
from {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
|
@ -1,150 +0,0 @@
|
|||
import {getProject} from '@theatre/core'
|
||||
import * as THREE from 'three'
|
||||
import {useState, useEffect, useRef} from 'react'
|
||||
import {useFrame, Canvas} from '@react-three/fiber'
|
||||
import {Shadow, softShadows} from '@react-three/drei'
|
||||
import React from 'react'
|
||||
import studio from '@theatre/studio'
|
||||
import {editable as e, SheetProvider, extension} from '@theatre/r3f'
|
||||
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
studio.extend(extension)
|
||||
studio.initialize()
|
||||
}
|
||||
|
||||
// Soft shadows are expensive, comment and refresh when it's too slow
|
||||
softShadows()
|
||||
|
||||
// credit: https://codesandbox.io/s/camera-pan-nsb7f
|
||||
|
||||
function Button() {
|
||||
const vec = new THREE.Vector3()
|
||||
const light = useRef(undefined)
|
||||
const [active, setActive] = useState(false)
|
||||
const [zoom, set] = useState(true)
|
||||
useEffect(
|
||||
() => void (document.body.style.cursor = active ? 'pointer' : 'auto'),
|
||||
[active],
|
||||
)
|
||||
|
||||
useFrame((state) => {
|
||||
const step = 0.1
|
||||
const camera = state.camera
|
||||
camera.fov = THREE.MathUtils.lerp(camera.fov, zoom ? 10 : 42, step)
|
||||
camera.position.lerp(
|
||||
vec.set(zoom ? 25 : 10, zoom ? 1 : 5, zoom ? 0 : 10),
|
||||
step,
|
||||
)
|
||||
state.camera.lookAt(0, 0, 0)
|
||||
state.camera.updateProjectionMatrix()
|
||||
|
||||
light.current.position.lerp(
|
||||
vec.set(zoom ? 4 : 0, zoom ? 3 : 8, zoom ? 3 : 5),
|
||||
step,
|
||||
)
|
||||
})
|
||||
|
||||
return (
|
||||
<e.mesh
|
||||
receiveShadow
|
||||
castShadow
|
||||
onClick={() => set(!zoom)}
|
||||
onPointerOver={() => setActive(true)}
|
||||
onPointerOut={() => setActive(false)}
|
||||
uniqueName="The Button"
|
||||
>
|
||||
<sphereBufferGeometry args={[0.75, 64, 64]} />
|
||||
<meshPhysicalMaterial
|
||||
color={active ? 'purple' : '#e7b056'}
|
||||
clearcoat={1}
|
||||
clearcoatRoughness={0}
|
||||
/>
|
||||
<Shadow
|
||||
position-y={-0.79}
|
||||
rotation-x={-Math.PI / 2}
|
||||
opacity={0.6}
|
||||
scale={[0.8, 0.8, 1]}
|
||||
/>
|
||||
<directionalLight
|
||||
ref={light}
|
||||
castShadow
|
||||
intensity={1.5}
|
||||
shadow-camera-far={70}
|
||||
/>
|
||||
</e.mesh>
|
||||
)
|
||||
}
|
||||
|
||||
function Plane({color, uniqueName, ...props}) {
|
||||
return (
|
||||
<e.mesh receiveShadow castShadow {...props} uniqueName={uniqueName}>
|
||||
<boxBufferGeometry />
|
||||
<meshStandardMaterial color={color} />
|
||||
</e.mesh>
|
||||
)
|
||||
}
|
||||
|
||||
const sheet = getProject('Playground - R3F').sheet('R3F-Canvas')
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<div>
|
||||
<Canvas
|
||||
// @ts-ignore
|
||||
shadowMap
|
||||
>
|
||||
<SheetProvider sheet={sheet}>
|
||||
{/* @ts-ignore */}
|
||||
<e.perspectiveCamera makeDefault uniqueName="Camera" />
|
||||
<ambientLight intensity={0.4} />
|
||||
<e.pointLight
|
||||
position={[-10, -10, 5]}
|
||||
intensity={2}
|
||||
color="#ff20f0"
|
||||
uniqueName="Light 1"
|
||||
/>
|
||||
<e.pointLight
|
||||
position={[0, 0.5, -1]}
|
||||
distance={1}
|
||||
intensity={2}
|
||||
color="#e4be00"
|
||||
uniqueName="Light 2"
|
||||
/>
|
||||
<group position={[0, -0.9, -3]}>
|
||||
<Plane
|
||||
color="hotpink"
|
||||
rotation-x={-Math.PI / 2}
|
||||
position-z={2}
|
||||
scale={[4, 20, 0.2]}
|
||||
uniqueName="plane1"
|
||||
/>
|
||||
<Plane
|
||||
color="#e4be00"
|
||||
rotation-x={-Math.PI / 2}
|
||||
position-y={1}
|
||||
scale={[4.2, 0.2, 4]}
|
||||
uniqueName="plane2"
|
||||
/>
|
||||
<Plane
|
||||
color="#736fbd"
|
||||
rotation-x={-Math.PI / 2}
|
||||
position={[-1.7, 1, 3.5]}
|
||||
scale={[0.5, 4, 4]}
|
||||
uniqueName="plane3"
|
||||
/>
|
||||
<Plane
|
||||
color="white"
|
||||
rotation-x={-Math.PI / 2}
|
||||
position={[0, 4.5, 3]}
|
||||
scale={[2, 0.03, 4]}
|
||||
uniqueName="plane4"
|
||||
/>
|
||||
</group>
|
||||
<Button />
|
||||
</SheetProvider>
|
||||
</Canvas>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default App
|
|
@ -1,7 +0,0 @@
|
|||
import {render, screen} from '@testing-library/react'
|
||||
|
||||
test('renders learn react link', () => {
|
||||
render(<App />)
|
||||
const linkElement = screen.getByText(/learn react/i)
|
||||
expect(linkElement).toBeInTheDocument()
|
||||
})
|
|
@ -1,13 +0,0 @@
|
|||
body {
|
||||
margin: 0;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
|
||||
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
|
||||
sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
|
||||
monospace;
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
import ReactDOM from 'react-dom'
|
||||
import './index.css'
|
||||
import reportWebVitals from './reportWebVitals'
|
||||
import '@theatre/studio'
|
||||
import {getProject} from '@theatre/core'
|
||||
import React from 'react'
|
||||
import App from './App'
|
||||
|
||||
ReactDOM.render(
|
||||
<React.StrictMode>
|
||||
<App project={getProject('CRA project')} />
|
||||
</React.StrictMode>,
|
||||
document.getElementById('root'),
|
||||
)
|
||||
|
||||
// If you want to start measuring performance in your app, pass a function
|
||||
// to log results (for example: reportWebVitals(console.log))
|
||||
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
|
||||
reportWebVitals()
|
|
@ -1 +0,0 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 841.9 595.3"><g fill="#61DAFB"><path d="M666.3 296.5c0-32.5-40.7-63.3-103.1-82.4 14.4-63.6 8-114.2-20.2-130.4-6.5-3.8-14.1-5.6-22.4-5.6v22.3c4.6 0 8.3.9 11.4 2.6 13.6 7.8 19.5 37.5 14.9 75.7-1.1 9.4-2.9 19.3-5.1 29.4-19.6-4.8-41-8.5-63.5-10.9-13.5-18.5-27.5-35.3-41.6-50 32.6-30.3 63.2-46.9 84-46.9V78c-27.5 0-63.5 19.6-99.9 53.6-36.4-33.8-72.4-53.2-99.9-53.2v22.3c20.7 0 51.4 16.5 84 46.6-14 14.7-28 31.4-41.3 49.9-22.6 2.4-44 6.1-63.6 11-2.3-10-4-19.7-5.2-29-4.7-38.2 1.1-67.9 14.6-75.8 3-1.8 6.9-2.6 11.5-2.6V78.5c-8.4 0-16 1.8-22.6 5.6-28.1 16.2-34.4 66.7-19.9 130.1-62.2 19.2-102.7 49.9-102.7 82.3 0 32.5 40.7 63.3 103.1 82.4-14.4 63.6-8 114.2 20.2 130.4 6.5 3.8 14.1 5.6 22.5 5.6 27.5 0 63.5-19.6 99.9-53.6 36.4 33.8 72.4 53.2 99.9 53.2 8.4 0 16-1.8 22.6-5.6 28.1-16.2 34.4-66.7 19.9-130.1 62-19.1 102.5-49.9 102.5-82.3zm-130.2-66.7c-3.7 12.9-8.3 26.2-13.5 39.5-4.1-8-8.4-16-13.1-24-4.6-8-9.5-15.8-14.4-23.4 14.2 2.1 27.9 4.7 41 7.9zm-45.8 106.5c-7.8 13.5-15.8 26.3-24.1 38.2-14.9 1.3-30 2-45.2 2-15.1 0-30.2-.7-45-1.9-8.3-11.9-16.4-24.6-24.2-38-7.6-13.1-14.5-26.4-20.8-39.8 6.2-13.4 13.2-26.8 20.7-39.9 7.8-13.5 15.8-26.3 24.1-38.2 14.9-1.3 30-2 45.2-2 15.1 0 30.2.7 45 1.9 8.3 11.9 16.4 24.6 24.2 38 7.6 13.1 14.5 26.4 20.8 39.8-6.3 13.4-13.2 26.8-20.7 39.9zm32.3-13c5.4 13.4 10 26.8 13.8 39.8-13.1 3.2-26.9 5.9-41.2 8 4.9-7.7 9.8-15.6 14.4-23.7 4.6-8 8.9-16.1 13-24.1zM421.2 430c-9.3-9.6-18.6-20.3-27.8-32 9 .4 18.2.7 27.5.7 9.4 0 18.7-.2 27.8-.7-9 11.7-18.3 22.4-27.5 32zm-74.4-58.9c-14.2-2.1-27.9-4.7-41-7.9 3.7-12.9 8.3-26.2 13.5-39.5 4.1 8 8.4 16 13.1 24 4.7 8 9.5 15.8 14.4 23.4zM420.7 163c9.3 9.6 18.6 20.3 27.8 32-9-.4-18.2-.7-27.5-.7-9.4 0-18.7.2-27.8.7 9-11.7 18.3-22.4 27.5-32zm-74 58.9c-4.9 7.7-9.8 15.6-14.4 23.7-4.6 8-8.9 16-13 24-5.4-13.4-10-26.8-13.8-39.8 13.1-3.1 26.9-5.8 41.2-7.9zm-90.5 125.2c-35.4-15.1-58.3-34.9-58.3-50.6 0-15.7 22.9-35.6 58.3-50.6 8.6-3.7 18-7 27.7-10.1 5.7 19.6 13.2 40 22.5 60.9-9.2 20.8-16.6 41.1-22.2 60.6-9.9-3.1-19.3-6.5-28-10.2zM310 490c-13.6-7.8-19.5-37.5-14.9-75.7 1.1-9.4 2.9-19.3 5.1-29.4 19.6 4.8 41 8.5 63.5 10.9 13.5 18.5 27.5 35.3 41.6 50-32.6 30.3-63.2 46.9-84 46.9-4.5-.1-8.3-1-11.3-2.7zm237.2-76.2c4.7 38.2-1.1 67.9-14.6 75.8-3 1.8-6.9 2.6-11.5 2.6-20.7 0-51.4-16.5-84-46.6 14-14.7 28-31.4 41.3-49.9 22.6-2.4 44-6.1 63.6-11 2.3 10.1 4.1 19.8 5.2 29.1zm38.5-66.7c-8.6 3.7-18 7-27.7 10.1-5.7-19.6-13.2-40-22.5-60.9 9.2-20.8 16.6-41.1 22.2-60.6 9.9 3.1 19.3 6.5 28.1 10.2 35.4 15.1 58.3 34.9 58.3 50.6-.1 15.7-23 35.6-58.4 50.6zM320.8 78.4z"/><circle cx="420.9" cy="296.5" r="45.7"/><path d="M520.5 78.1z"/></g></svg>
|
Before Width: | Height: | Size: 2.6 KiB |
|
@ -1 +0,0 @@
|
|||
/// <reference types="react-scripts" />
|
|
@ -1,13 +0,0 @@
|
|||
const reportWebVitals = (onPerfEntry) => {
|
||||
if (onPerfEntry && onPerfEntry instanceof Function) {
|
||||
import('web-vitals').then(({getCLS, getFID, getFCP, getLCP, getTTFB}) => {
|
||||
getCLS(onPerfEntry)
|
||||
getFID(onPerfEntry)
|
||||
getFCP(onPerfEntry)
|
||||
getLCP(onPerfEntry)
|
||||
getTTFB(onPerfEntry)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export default reportWebVitals
|
|
@ -1,5 +0,0 @@
|
|||
// jest-dom adds custom jest matchers for asserting on DOM nodes.
|
||||
// allows you to do things like:
|
||||
// expect(element).toHaveTextContent(/react/i)
|
||||
// learn more: https://github.com/testing-library/jest-dom
|
||||
import '@testing-library/jest-dom'
|
|
@ -1,130 +0,0 @@
|
|||
import {useLayoutEffect, useRef} from 'react'
|
||||
|
||||
const noop = () => {}
|
||||
|
||||
function createCursorLock(cursor) {
|
||||
const el = document.createElement('div')
|
||||
el.style.cssText = `
|
||||
position: fixed;
|
||||
top: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
z-index: 9999999;`
|
||||
|
||||
el.style.cursor = cursor
|
||||
document.body.appendChild(el)
|
||||
const relinquish = () => {
|
||||
document.body.removeChild(el)
|
||||
}
|
||||
|
||||
return relinquish
|
||||
}
|
||||
|
||||
export default function useDrag(target, opts) {
|
||||
const optsRef = useRef(opts)
|
||||
optsRef.current = opts
|
||||
|
||||
const modeRef = useRef('notDragging')
|
||||
|
||||
const stateRef = useRef({dragHappened: false, startPos: {x: 0, y: 0}})
|
||||
|
||||
useLayoutEffect(() => {
|
||||
if (!target) return
|
||||
|
||||
const getDistances = (event) => {
|
||||
const {startPos} = stateRef.current
|
||||
return [event.screenX - startPos.x, event.screenY - startPos.y]
|
||||
}
|
||||
|
||||
let relinquishCursorLock = noop
|
||||
|
||||
const dragHandler = (event) => {
|
||||
if (!stateRef.current.dragHappened && optsRef.current.lockCursorTo) {
|
||||
relinquishCursorLock = createCursorLock(optsRef.current.lockCursorTo)
|
||||
}
|
||||
if (!stateRef.current.dragHappened) stateRef.current.dragHappened = true
|
||||
modeRef.current = 'dragging'
|
||||
|
||||
const deltas = getDistances(event)
|
||||
optsRef.current.onDrag(deltas[0], deltas[1], event)
|
||||
}
|
||||
|
||||
const dragEndHandler = () => {
|
||||
removeDragListeners()
|
||||
modeRef.current = 'notDragging'
|
||||
|
||||
optsRef.current.onDragEnd &&
|
||||
optsRef.current.onDragEnd(stateRef.current.dragHappened)
|
||||
relinquishCursorLock()
|
||||
relinquishCursorLock = noop
|
||||
}
|
||||
|
||||
const addDragListeners = () => {
|
||||
document.addEventListener('mousemove', dragHandler)
|
||||
document.addEventListener('mouseup', dragEndHandler)
|
||||
}
|
||||
|
||||
const removeDragListeners = () => {
|
||||
document.removeEventListener('mousemove', dragHandler)
|
||||
document.removeEventListener('mouseup', dragEndHandler)
|
||||
}
|
||||
|
||||
const preventUnwantedClick = (event) => {
|
||||
if (optsRef.current.disabled) return
|
||||
if (stateRef.current.dragHappened) {
|
||||
if (
|
||||
!optsRef.current.dontBlockMouseDown &&
|
||||
modeRef.current !== 'notDragging'
|
||||
) {
|
||||
event.stopPropagation()
|
||||
event.preventDefault()
|
||||
}
|
||||
stateRef.current.dragHappened = false
|
||||
}
|
||||
}
|
||||
|
||||
const dragStartHandler = (event) => {
|
||||
const opts = optsRef.current
|
||||
if (opts.disabled === true) return
|
||||
|
||||
if (event.button !== 0) return
|
||||
const resultOfStart = opts.onDragStart && opts.onDragStart(event)
|
||||
|
||||
if (resultOfStart === false) return
|
||||
|
||||
if (!opts.dontBlockMouseDown) {
|
||||
event.stopPropagation()
|
||||
event.preventDefault()
|
||||
}
|
||||
|
||||
modeRef.current = 'dragStartCalled'
|
||||
|
||||
const {screenX, screenY} = event
|
||||
stateRef.current.startPos = {x: screenX, y: screenY}
|
||||
stateRef.current.dragHappened = false
|
||||
|
||||
addDragListeners()
|
||||
}
|
||||
|
||||
const onMouseDown = (e) => {
|
||||
dragStartHandler(e)
|
||||
}
|
||||
|
||||
target.addEventListener('mousedown', onMouseDown)
|
||||
target.addEventListener('click', preventUnwantedClick)
|
||||
|
||||
return () => {
|
||||
removeDragListeners()
|
||||
target.removeEventListener('mousedown', onMouseDown)
|
||||
target.removeEventListener('click', preventUnwantedClick)
|
||||
relinquishCursorLock()
|
||||
|
||||
if (modeRef.current !== 'notDragging') {
|
||||
optsRef.current.onDragEnd &&
|
||||
optsRef.current.onDragEnd(modeRef.current === 'dragging')
|
||||
}
|
||||
modeRef.current = 'notDragging'
|
||||
}
|
||||
}, [target])
|
||||
}
|
31
compatibility-tests/test-next/.gitignore
vendored
Normal file
31
compatibility-tests/test-next/.gitignore
vendored
Normal file
|
@ -0,0 +1,31 @@
|
|||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
/.pnp
|
||||
.pnp.js
|
||||
|
||||
# testing
|
||||
/coverage
|
||||
|
||||
# next.js
|
||||
/.next/
|
||||
/out/
|
||||
|
||||
# production
|
||||
/build
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
|
||||
# debug
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
|
||||
# local env files
|
||||
.env.local
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
|
1
compatibility-tests/test-next/README.md
Normal file
1
compatibility-tests/test-next/README.md
Normal file
|
@ -0,0 +1 @@
|
|||
This is a starter template for [Learn Next.js](https://nextjs.org/learn).
|
15
compatibility-tests/test-next/package.json
Normal file
15
compatibility-tests/test-next/package.json
Normal file
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev",
|
||||
"build": "next build",
|
||||
"start": "next start"
|
||||
},
|
||||
"dependencies": {
|
||||
"@theatre/core": "^0.0.1-COMPAT.1",
|
||||
"@theatre/studio": "^0.0.1-COMPAT.1",
|
||||
"next": "latest",
|
||||
"react": "17.0.2",
|
||||
"react-dom": "17.0.2"
|
||||
}
|
||||
}
|
23
compatibility-tests/test-next/pages/index.js
Normal file
23
compatibility-tests/test-next/pages/index.js
Normal file
|
@ -0,0 +1,23 @@
|
|||
import Head from 'next/head'
|
||||
|
||||
// import ReactDOM from 'react-dom'
|
||||
|
||||
import studio from '@theatre/studio'
|
||||
import {getProject} from '@theatre/core'
|
||||
// import React from 'react'
|
||||
// import App from './App'
|
||||
|
||||
studio.initialize({usePersistentStorage: false})
|
||||
|
||||
const project = getProject('Project')
|
||||
const sheet = project.sheet('Sheet')
|
||||
const obj = sheet.object('Obj', {str: 'some string', num: 0})
|
||||
|
||||
function App({obj}) {
|
||||
console.log(obj)
|
||||
return <div>hi</div>
|
||||
}
|
||||
|
||||
export default function Home() {
|
||||
return <App obj={obj}>hi</App>
|
||||
}
|
BIN
compatibility-tests/test-next/public/favicon.ico
Normal file
BIN
compatibility-tests/test-next/public/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 15 KiB |
3
compatibility-tests/test-parcel1-react18/.gitignore
vendored
Normal file
3
compatibility-tests/test-parcel1-react18/.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
/.cache
|
||||
/dist
|
||||
/package-lock.json
|
13
compatibility-tests/test-parcel1-react18/index.html
Normal file
13
compatibility-tests/test-parcel1-react18/index.html
Normal file
|
@ -0,0 +1,13 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Theatre.js Example - DOM</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script src="./src/index.js"></script>
|
||||
</body>
|
||||
</html>
|
13
compatibility-tests/test-parcel1-react18/package.json
Normal file
13
compatibility-tests/test-parcel1-react18/package.json
Normal file
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"name": "@compat/parcel1-react18",
|
||||
"scripts": {
|
||||
"dev": "parcel serve ./index.html"
|
||||
},
|
||||
"dependencies": {
|
||||
"@theatre/core": "0.0.1-COMPAT.1",
|
||||
"@theatre/studio": "0.0.1-COMPAT.1",
|
||||
"parcel-bundler": "^1.12.5",
|
||||
"react": "^18.1.0",
|
||||
"react-dom": "^18.1.0"
|
||||
}
|
||||
}
|
6
compatibility-tests/test-parcel1-react18/src/App.js
Normal file
6
compatibility-tests/test-parcel1-react18/src/App.js
Normal file
|
@ -0,0 +1,6 @@
|
|||
import React from 'react'
|
||||
|
||||
export default function App({obj}) {
|
||||
console.log(obj)
|
||||
return <div>hi</div>
|
||||
}
|
19
compatibility-tests/test-parcel1-react18/src/index.js
Normal file
19
compatibility-tests/test-parcel1-react18/src/index.js
Normal file
|
@ -0,0 +1,19 @@
|
|||
// import ReactDOM from 'react-dom'
|
||||
|
||||
import studio from '@theatre/studio'
|
||||
import {getProject} from '@theatre/core'
|
||||
// import React from 'react'
|
||||
// import App from './App'
|
||||
|
||||
studio.initialize({usePersistentStorage: false})
|
||||
|
||||
const project = getProject('Project')
|
||||
const sheet = project.sheet('Sheet')
|
||||
const obj = sheet.object('Obj', {str: 'some string', num: 0})
|
||||
|
||||
// ReactDOM.render(
|
||||
// <React.StrictMode>
|
||||
// <App obj={obj} />
|
||||
// </React.StrictMode>,
|
||||
// document.getElementById('root'),
|
||||
// )
|
4
compatibility-tests/test-parcel2-react18/.gitignore
vendored
Normal file
4
compatibility-tests/test-parcel2-react18/.gitignore
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
/.parcel-cache
|
||||
/.cache
|
||||
/dist
|
||||
/package-lock.json
|
13
compatibility-tests/test-parcel2-react18/index.html
Normal file
13
compatibility-tests/test-parcel2-react18/index.html
Normal file
|
@ -0,0 +1,13 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Theatre.js Example - DOM</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="module" src="./src/index.js"></script>
|
||||
</body>
|
||||
</html>
|
13
compatibility-tests/test-parcel2-react18/package.json
Normal file
13
compatibility-tests/test-parcel2-react18/package.json
Normal file
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"name": "@compat/parcel2-react18",
|
||||
"scripts": {
|
||||
"dev": "parcel serve ./index.html"
|
||||
},
|
||||
"dependencies": {
|
||||
"@theatre/core": "0.0.1-COMPAT.1",
|
||||
"@theatre/studio": "0.0.1-COMPAT.1",
|
||||
"parcel": "^2.5.0",
|
||||
"react": "^18.1.0",
|
||||
"react-dom": "^18.1.0"
|
||||
}
|
||||
}
|
6
compatibility-tests/test-parcel2-react18/src/App.js
Normal file
6
compatibility-tests/test-parcel2-react18/src/App.js
Normal file
|
@ -0,0 +1,6 @@
|
|||
import React from 'react'
|
||||
|
||||
export default function App({obj}) {
|
||||
console.log(obj)
|
||||
return <div>hi</div>
|
||||
}
|
19
compatibility-tests/test-parcel2-react18/src/index.js
Normal file
19
compatibility-tests/test-parcel2-react18/src/index.js
Normal file
|
@ -0,0 +1,19 @@
|
|||
// import ReactDOM from 'react-dom'
|
||||
|
||||
import studio from '@theatre/studio'
|
||||
import {getProject} from '@theatre/core'
|
||||
// import React from 'react'
|
||||
// import App from './App'
|
||||
|
||||
studio.initialize({usePersistentStorage: false})
|
||||
|
||||
const project = getProject('Project')
|
||||
const sheet = project.sheet('Sheet')
|
||||
const obj = sheet.object('Obj', {str: 'some string', num: 0})
|
||||
|
||||
// ReactDOM.render(
|
||||
// <React.StrictMode>
|
||||
// <App obj={obj} />
|
||||
// </React.StrictMode>,
|
||||
// document.getElementById('root'),
|
||||
// )
|
24
compatibility-tests/test-vite-react18/.gitignore
vendored
Normal file
24
compatibility-tests/test-vite-react18/.gitignore
vendored
Normal file
|
@ -0,0 +1,24 @@
|
|||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
dist
|
||||
dist-ssr
|
||||
*.local
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
.idea
|
||||
.DS_Store
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
12
compatibility-tests/test-vite-react18/index.html
Normal file
12
compatibility-tests/test-vite-react18/index.html
Normal file
|
@ -0,0 +1,12 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Vite App</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="module" src="/src/main.tsx"></script>
|
||||
</body>
|
||||
</html>
|
23
compatibility-tests/test-vite-react18/package.json
Normal file
23
compatibility-tests/test-vite-react18/package.json
Normal file
|
@ -0,0 +1,23 @@
|
|||
{
|
||||
"name": "@compat/vite-react18",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "tsc && vite build",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"@theatre/core": "^0.0.1-COMPAT.1",
|
||||
"@theatre/studio": "^0.0.1-COMPAT.1",
|
||||
"react": "^18.0.0",
|
||||
"react-dom": "^18.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/react": "^18.0.0",
|
||||
"@types/react-dom": "^18.0.0",
|
||||
"@vitejs/plugin-react": "^1.3.0",
|
||||
"typescript": "^4.6.3",
|
||||
"vite": "^2.9.9"
|
||||
}
|
||||
}
|
6
compatibility-tests/test-vite-react18/src/App.tsx
Normal file
6
compatibility-tests/test-vite-react18/src/App.tsx
Normal file
|
@ -0,0 +1,6 @@
|
|||
import React from 'react'
|
||||
|
||||
export default function App({obj}) {
|
||||
console.log(obj)
|
||||
return <div>hi</div>
|
||||
}
|
19
compatibility-tests/test-vite-react18/src/main.tsx
Normal file
19
compatibility-tests/test-vite-react18/src/main.tsx
Normal file
|
@ -0,0 +1,19 @@
|
|||
// import ReactDOM from 'react-dom'
|
||||
|
||||
import studio from '@theatre/studio'
|
||||
import {getProject} from '@theatre/core'
|
||||
// import React from 'react'
|
||||
// import App from './App'
|
||||
|
||||
studio.initialize({usePersistentStorage: false})
|
||||
|
||||
const project = getProject('Project')
|
||||
const sheet = project.sheet('Sheet')
|
||||
const obj = sheet.object('Obj', {str: 'some string', num: 0})
|
||||
|
||||
// ReactDOM.render(
|
||||
// <React.StrictMode>
|
||||
// <App obj={obj} />
|
||||
// </React.StrictMode>,
|
||||
// document.getElementById('root'),
|
||||
// )
|
1
compatibility-tests/test-vite-react18/src/vite-env.d.ts
vendored
Normal file
1
compatibility-tests/test-vite-react18/src/vite-env.d.ts
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/// <reference types="vite/client" />
|
21
compatibility-tests/test-vite-react18/tsconfig.json
Normal file
21
compatibility-tests/test-vite-react18/tsconfig.json
Normal file
|
@ -0,0 +1,21 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"target": "ESNext",
|
||||
"useDefineForClassFields": true,
|
||||
"lib": ["DOM", "DOM.Iterable", "ESNext"],
|
||||
"allowJs": false,
|
||||
"skipLibCheck": true,
|
||||
"esModuleInterop": false,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"strict": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "Node",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"noEmit": true,
|
||||
"jsx": "react-jsx"
|
||||
},
|
||||
"include": ["src"],
|
||||
"references": [{ "path": "./tsconfig.node.json" }]
|
||||
}
|
8
compatibility-tests/test-vite-react18/tsconfig.node.json
Normal file
8
compatibility-tests/test-vite-react18/tsconfig.node.json
Normal file
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"composite": true,
|
||||
"module": "esnext",
|
||||
"moduleResolution": "node"
|
||||
},
|
||||
"include": ["vite.config.ts"]
|
||||
}
|
7
compatibility-tests/test-vite-react18/vite.config.ts
Normal file
7
compatibility-tests/test-vite-react18/vite.config.ts
Normal file
|
@ -0,0 +1,7 @@
|
|||
import {defineConfig} from 'vite'
|
||||
import react from '@vitejs/plugin-react'
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [react()],
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue