[big chore] restore core to monorepo (#287)
* move core into repo, apps into apps folder, update tests * Update scripts for build:core * improve scripts * remove noise from www * Update .gitignore * Fix focus bug * add ci test script * Update main.yml
This commit is contained in:
parent
878ca710b7
commit
e6a3e5c3ea
389 changed files with 12980 additions and 95 deletions
64
examples/tldraw-example/src/api-control.tsx
Normal file
64
examples/tldraw-example/src/api-control.tsx
Normal file
|
@ -0,0 +1,64 @@
|
|||
/* eslint-disable @typescript-eslint/no-non-null-assertion */
|
||||
import * as React from 'react'
|
||||
import { ColorStyle, Tldraw, TDShapeType, TldrawApp } from '@tldraw/tldraw'
|
||||
|
||||
export default function Imperative(): JSX.Element {
|
||||
const rTldrawApp = React.useRef<TldrawApp>()
|
||||
|
||||
const handleMount = React.useCallback((app: TldrawApp) => {
|
||||
rTldrawApp.current = app
|
||||
|
||||
app.createShapes(
|
||||
{
|
||||
id: 'rect1',
|
||||
type: TDShapeType.Rectangle,
|
||||
name: 'Rectangle',
|
||||
childIndex: 1,
|
||||
point: [0, 0],
|
||||
size: [100, 100],
|
||||
},
|
||||
{
|
||||
id: 'rect2',
|
||||
name: 'Rectangle',
|
||||
type: TDShapeType.Rectangle,
|
||||
point: [200, 200],
|
||||
size: [100, 100],
|
||||
}
|
||||
)
|
||||
}, [])
|
||||
|
||||
React.useEffect(() => {
|
||||
let i = 0
|
||||
const interval = setInterval(() => {
|
||||
const app = rTldrawApp.current!
|
||||
const rect1 = app.getShape('rect1')
|
||||
|
||||
if (!rect1) {
|
||||
app.createShapes({
|
||||
id: 'rect1',
|
||||
type: TDShapeType.Rectangle,
|
||||
name: 'Rectangle',
|
||||
childIndex: 1,
|
||||
point: [0, 0],
|
||||
size: [100, 100],
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
const color = i % 2 ? ColorStyle.Red : ColorStyle.Blue
|
||||
|
||||
app.patchShapes({
|
||||
id: 'rect1',
|
||||
style: {
|
||||
...rect1.style,
|
||||
color,
|
||||
},
|
||||
})
|
||||
|
||||
i++
|
||||
}, 1000)
|
||||
return () => clearInterval(interval)
|
||||
}, [])
|
||||
|
||||
return <Tldraw onMount={handleMount} />
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue