cleanup
This commit is contained in:
parent
4e13b0e07b
commit
4a0800a5df
5 changed files with 4 additions and 49 deletions
|
@ -14,11 +14,6 @@ import { useTLTheme, TLContext, TLContextType } from '../../hooks'
|
||||||
|
|
||||||
export interface RendererProps<T extends TLShape, M extends Record<string, unknown>>
|
export interface RendererProps<T extends TLShape, M extends Record<string, unknown>>
|
||||||
extends Partial<TLCallbacks> {
|
extends Partial<TLCallbacks> {
|
||||||
/**
|
|
||||||
* An id representing the current document. Changing the id will
|
|
||||||
* update the context and trigger a re-render.
|
|
||||||
*/
|
|
||||||
id?: string
|
|
||||||
/**
|
/**
|
||||||
* An object containing instances of your shape classes.
|
* An object containing instances of your shape classes.
|
||||||
*/
|
*/
|
||||||
|
@ -57,8 +52,6 @@ export interface RendererProps<T extends TLShape, M extends Record<string, unkno
|
||||||
* An object of custom options that should be passed to rendered shapes.
|
* An object of custom options that should be passed to rendered shapes.
|
||||||
*/
|
*/
|
||||||
meta?: M
|
meta?: M
|
||||||
// Temp
|
|
||||||
onTest?: () => void
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -70,7 +63,6 @@ export interface RendererProps<T extends TLShape, M extends Record<string, unkno
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
export function Renderer<T extends TLShape, M extends Record<string, unknown>>({
|
export function Renderer<T extends TLShape, M extends Record<string, unknown>>({
|
||||||
id,
|
|
||||||
shapeUtils,
|
shapeUtils,
|
||||||
page,
|
page,
|
||||||
pageState,
|
pageState,
|
||||||
|
@ -90,31 +82,13 @@ export function Renderer<T extends TLShape, M extends Record<string, unknown>>({
|
||||||
rPageState.current = pageState
|
rPageState.current = pageState
|
||||||
}, [pageState])
|
}, [pageState])
|
||||||
|
|
||||||
const rId = React.useRef(id)
|
const [context] = React.useState<TLContextType>(() => ({
|
||||||
|
|
||||||
const [context, setContext] = React.useState<TLContextType>(() => ({
|
|
||||||
id,
|
|
||||||
callbacks: rest,
|
callbacks: rest,
|
||||||
shapeUtils,
|
shapeUtils,
|
||||||
rScreenBounds,
|
rScreenBounds,
|
||||||
rPageState,
|
rPageState,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
React.useEffect(() => {
|
|
||||||
if (id !== rId.current) {
|
|
||||||
rest.onTest?.()
|
|
||||||
setContext({
|
|
||||||
id,
|
|
||||||
callbacks: rest,
|
|
||||||
shapeUtils,
|
|
||||||
rScreenBounds,
|
|
||||||
rPageState,
|
|
||||||
})
|
|
||||||
|
|
||||||
rId.current = id
|
|
||||||
}
|
|
||||||
}, [id])
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TLContext.Provider value={context}>
|
<TLContext.Provider value={context}>
|
||||||
<Canvas
|
<Canvas
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
import * as React from 'react'
|
import * as React from 'react'
|
||||||
import Controlled from './controlled'
|
|
||||||
import Basic from './basic'
|
|
||||||
import NewId from './newId'
|
import NewId from './newId'
|
||||||
|
|
||||||
export default function App(): JSX.Element {
|
export default function App(): JSX.Element {
|
||||||
|
|
|
@ -69,23 +69,16 @@ export function TLDraw({ id, document, currentPageId, onMount, onChange }: TLDra
|
||||||
return (
|
return (
|
||||||
<TLDrawContext.Provider value={context}>
|
<TLDrawContext.Provider value={context}>
|
||||||
<IdProvider>
|
<IdProvider>
|
||||||
<InnerTldraw
|
<InnerTldraw key={sId || 'tldraw'} currentPageId={currentPageId} document={document} />
|
||||||
key={sId || 'tldraw'}
|
|
||||||
id={sId}
|
|
||||||
currentPageId={currentPageId}
|
|
||||||
document={document}
|
|
||||||
/>
|
|
||||||
</IdProvider>
|
</IdProvider>
|
||||||
</TLDrawContext.Provider>
|
</TLDrawContext.Provider>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function InnerTldraw({
|
function InnerTldraw({
|
||||||
id,
|
|
||||||
currentPageId,
|
currentPageId,
|
||||||
document,
|
document,
|
||||||
}: {
|
}: {
|
||||||
id?: string
|
|
||||||
currentPageId?: string
|
currentPageId?: string
|
||||||
document?: TLDrawDocument
|
document?: TLDrawDocument
|
||||||
}) {
|
}) {
|
||||||
|
@ -150,16 +143,10 @@ function InnerTldraw({
|
||||||
tlstate.changePage(currentPageId)
|
tlstate.changePage(currentPageId)
|
||||||
}, [currentPageId, tlstate])
|
}, [currentPageId, tlstate])
|
||||||
|
|
||||||
React.useEffect(() => {
|
|
||||||
'Id Changed!'
|
|
||||||
console.log(id, tlstate.id)
|
|
||||||
}, [id])
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Layout>
|
<Layout>
|
||||||
<ContextMenu>
|
<ContextMenu>
|
||||||
<Renderer
|
<Renderer
|
||||||
id={id}
|
|
||||||
page={page}
|
page={page}
|
||||||
pageState={pageState}
|
pageState={pageState}
|
||||||
shapeUtils={tldrawShapeUtils}
|
shapeUtils={tldrawShapeUtils}
|
||||||
|
|
|
@ -32,15 +32,11 @@ export const ToolsPanel = React.memo((): JSX.Element => {
|
||||||
|
|
||||||
const isDebugMode = useSelector(isDebugModeSelector)
|
const isDebugMode = useSelector(isDebugModeSelector)
|
||||||
|
|
||||||
console.log(activeTool)
|
|
||||||
|
|
||||||
const selectSelectTool = React.useCallback(() => {
|
const selectSelectTool = React.useCallback(() => {
|
||||||
console.log(tlstate.id)
|
|
||||||
tlstate.selectTool('select')
|
tlstate.selectTool('select')
|
||||||
}, [tlstate])
|
}, [tlstate])
|
||||||
|
|
||||||
const selectDrawTool = React.useCallback(() => {
|
const selectDrawTool = React.useCallback(() => {
|
||||||
console.log(tlstate.id)
|
|
||||||
tlstate.selectTool(TLDrawShapeType.Draw)
|
tlstate.selectTool(TLDrawShapeType.Draw)
|
||||||
}, [tlstate])
|
}, [tlstate])
|
||||||
|
|
||||||
|
|
|
@ -447,9 +447,9 @@ describe('TLDrawState', () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('when the document prop changes', () => {
|
describe('when the document prop changes', () => {
|
||||||
it.todo('updates the document if the new id is the same as the old one')
|
|
||||||
|
|
||||||
it.todo('replaces the document if the ids are different')
|
it.todo('replaces the document if the ids are different')
|
||||||
|
|
||||||
|
it.todo('updates the document if the new id is the same as the old one')
|
||||||
})
|
})
|
||||||
/*
|
/*
|
||||||
We want to be able to use the `document` property to update the
|
We want to be able to use the `document` property to update the
|
||||||
|
|
Loading…
Reference in a new issue