|
|
@@ -14,11 +14,6 @@ import { useTLTheme, TLContext, TLContextType } from '../../hooks'
|
|
14
|
14
|
|
|
15
|
15
|
export interface RendererProps<T extends TLShape, M extends Record<string, unknown>>
|
|
16
|
16
|
extends Partial<TLCallbacks> {
|
|
17
|
|
- /**
|
|
18
|
|
- * An id representing the current document. Changing the id will
|
|
19
|
|
- * update the context and trigger a re-render.
|
|
20
|
|
- */
|
|
21
|
|
- id?: string
|
|
22
|
17
|
/**
|
|
23
|
18
|
* An object containing instances of your shape classes.
|
|
24
|
19
|
*/
|
|
|
@@ -57,8 +52,6 @@ export interface RendererProps<T extends TLShape, M extends Record<string, unkno
|
|
57
|
52
|
* An object of custom options that should be passed to rendered shapes.
|
|
58
|
53
|
*/
|
|
59
|
54
|
meta?: M
|
|
60
|
|
- // Temp
|
|
61
|
|
- onTest?: () => void
|
|
62
|
55
|
}
|
|
63
|
56
|
|
|
64
|
57
|
/**
|
|
|
@@ -70,7 +63,6 @@ export interface RendererProps<T extends TLShape, M extends Record<string, unkno
|
|
70
|
63
|
* @returns
|
|
71
|
64
|
*/
|
|
72
|
65
|
export function Renderer<T extends TLShape, M extends Record<string, unknown>>({
|
|
73
|
|
- id,
|
|
74
|
66
|
shapeUtils,
|
|
75
|
67
|
page,
|
|
76
|
68
|
pageState,
|
|
|
@@ -90,31 +82,13 @@ export function Renderer<T extends TLShape, M extends Record<string, unknown>>({
|
|
90
|
82
|
rPageState.current = pageState
|
|
91
|
83
|
}, [pageState])
|
|
92
|
84
|
|
|
93
|
|
- const rId = React.useRef(id)
|
|
94
|
|
-
|
|
95
|
|
- const [context, setContext] = React.useState<TLContextType>(() => ({
|
|
96
|
|
- id,
|
|
|
85
|
+ const [context] = React.useState<TLContextType>(() => ({
|
|
97
|
86
|
callbacks: rest,
|
|
98
|
87
|
shapeUtils,
|
|
99
|
88
|
rScreenBounds,
|
|
100
|
89
|
rPageState,
|
|
101
|
90
|
}))
|
|
102
|
91
|
|
|
103
|
|
- React.useEffect(() => {
|
|
104
|
|
- if (id !== rId.current) {
|
|
105
|
|
- rest.onTest?.()
|
|
106
|
|
- setContext({
|
|
107
|
|
- id,
|
|
108
|
|
- callbacks: rest,
|
|
109
|
|
- shapeUtils,
|
|
110
|
|
- rScreenBounds,
|
|
111
|
|
- rPageState,
|
|
112
|
|
- })
|
|
113
|
|
-
|
|
114
|
|
- rId.current = id
|
|
115
|
|
- }
|
|
116
|
|
- }, [id])
|
|
117
|
|
-
|
|
118
|
92
|
return (
|
|
119
|
93
|
<TLContext.Provider value={context}>
|
|
120
|
94
|
<Canvas
|