Browse Source

Fixes types

main
Steve Ruiz 4 years ago
parent
commit
edc29dfbcf

+ 2
- 2
packages/core/src/renderer/components/canvas.tsx View File

2
 import { ErrorBoundary } from 'react-error-boundary'
2
 import { ErrorBoundary } from 'react-error-boundary'
3
 import { useZoomEvents, useSafariFocusOutFix, useCanvasEvents, useCameraCss } from '../hooks'
3
 import { useZoomEvents, useSafariFocusOutFix, useCanvasEvents, useCameraCss } from '../hooks'
4
 import { ErrorFallback } from './error-fallback'
4
 import { ErrorFallback } from './error-fallback'
5
-import type { TLPage, TLPageState, TLShape } from '../../types'
5
+import type { TLBinding, TLPage, TLPageState, TLShape } from '../../types'
6
 
6
 
7
 import { Brush } from './brush'
7
 import { Brush } from './brush'
8
 import { Defs } from './defs'
8
 import { Defs } from './defs'
14
 }
14
 }
15
 
15
 
16
 interface CanvasProps<T extends TLShape> {
16
 interface CanvasProps<T extends TLShape> {
17
-  page: TLPage<T>
17
+  page: TLPage<T, TLBinding>
18
   pageState: TLPageState
18
   pageState: TLPageState
19
   hideBounds?: boolean
19
   hideBounds?: boolean
20
   hideHandles?: boolean
20
   hideHandles?: boolean

+ 2
- 2
packages/core/src/renderer/components/page.tsx View File

1
 import * as React from 'react'
1
 import * as React from 'react'
2
 import { useShapeTree } from '../hooks/useShapeTree'
2
 import { useShapeTree } from '../hooks/useShapeTree'
3
-import type { IShapeTreeNode, TLPage, TLPageState, TLShape } from '../../types'
3
+import type { IShapeTreeNode, TLBinding, TLPage, TLPageState, TLShape } from '../../types'
4
 import { Shape as ShapeComponent } from './shape'
4
 import { Shape as ShapeComponent } from './shape'
5
 import { useHandles, useRenderOnResize, useTLContext } from '../hooks'
5
 import { useHandles, useRenderOnResize, useTLContext } from '../hooks'
6
 import { Bounds } from './bounds'
6
 import { Bounds } from './bounds'
9
 import { Handles } from './handles'
9
 import { Handles } from './handles'
10
 
10
 
11
 interface PageProps<T extends TLShape> {
11
 interface PageProps<T extends TLShape> {
12
-  page: TLPage<T>
12
+  page: TLPage<T, TLBinding>
13
   pageState: TLPageState
13
   pageState: TLPageState
14
   hideBounds: boolean
14
   hideBounds: boolean
15
   hideHandles: boolean
15
   hideHandles: boolean

+ 2
- 5
packages/core/src/renderer/hooks/useHandles.ts View File

1
-import type { TLPage, TLPageState, TLShape } from '../../types'
1
+import type { TLBinding, TLPage, TLPageState, TLShape } from '../../types'
2
 
2
 
3
-export function useHandles<T extends TLShape>(
4
-  page: TLPage<T>,
5
-  pageState: TLPageState
6
-) {
3
+export function useHandles<T extends TLShape>(page: TLPage<T, TLBinding>, pageState: TLPageState) {
7
   const { selectedIds } = pageState
4
   const { selectedIds } = pageState
8
 
5
 
9
   let shapeWithHandles: TLShape | undefined = undefined
6
   let shapeWithHandles: TLShape | undefined = undefined

+ 6
- 24
packages/core/src/renderer/hooks/useSelection.tsx View File

1
-import type {
2
-  TLPage,
3
-  TLPageState,
4
-  TLShape,
5
-  TLBounds,
6
-  TLShapeUtils,
7
-} from '../../types'
1
+import type { TLPage, TLPageState, TLShape, TLBounds, TLShapeUtils, TLBinding } from '../../types'
8
 import Utils from '../../utils'
2
 import Utils from '../../utils'
9
 import { useTLContext } from '../hooks/useTLContext'
3
 import { useTLContext } from '../hooks/useTLContext'
10
 
4
 
11
-function canvasToScreen(
12
-  point: number[],
13
-  camera: TLPageState['camera']
14
-): number[] {
15
-  return [
16
-    (point[0] + camera.point[0]) * camera.zoom,
17
-    (point[1] + camera.point[1]) * camera.zoom,
18
-  ]
5
+function canvasToScreen(point: number[], camera: TLPageState['camera']): number[] {
6
+  return [(point[0] + camera.point[0]) * camera.zoom, (point[1] + camera.point[1]) * camera.zoom]
19
 }
7
 }
20
 
8
 
21
 export function useSelection<T extends TLShape>(
9
 export function useSelection<T extends TLShape>(
22
-  page: TLPage<T>,
10
+  page: TLPage<T, TLBinding>,
23
   pageState: TLPageState,
11
   pageState: TLPageState,
24
   shapeUtils: TLShapeUtils<T>
12
   shapeUtils: TLShapeUtils<T>
25
 ) {
13
 ) {
59
   }
47
   }
60
 
48
 
61
   if (bounds) {
49
   if (bounds) {
62
-    const [minX, minY] = canvasToScreen(
63
-      [bounds.minX, bounds.minY],
64
-      pageState.camera
65
-    )
66
-    const [maxX, maxY] = canvasToScreen(
67
-      [bounds.maxX, bounds.maxY],
68
-      pageState.camera
69
-    )
50
+    const [minX, minY] = canvasToScreen([bounds.minX, bounds.minY], pageState.camera)
51
+    const [maxX, maxY] = canvasToScreen([bounds.maxX, bounds.maxY], pageState.camera)
70
 
52
 
71
     rScreenBounds.current = {
53
     rScreenBounds.current = {
72
       minX,
54
       minX,

+ 5
- 7
packages/core/src/renderer/hooks/useShapeTree.tsx View File

6
   TLShape,
6
   TLShape,
7
   TLShapeUtils,
7
   TLShapeUtils,
8
   TLCallbacks,
8
   TLCallbacks,
9
+  TLBinding,
9
 } from '../../types'
10
 } from '../../types'
10
 import Utils, { Vec } from '../../utils'
11
 import Utils, { Vec } from '../../utils'
11
 
12
 
12
 function addToShapeTree<T extends TLShape>(
13
 function addToShapeTree<T extends TLShape>(
13
   shape: TLShape,
14
   shape: TLShape,
14
   branch: IShapeTreeNode[],
15
   branch: IShapeTreeNode[],
15
-  shapes: TLPage<T>['shapes'],
16
+  shapes: TLPage<T, TLBinding>['shapes'],
16
   selectedIds: string[],
17
   selectedIds: string[],
17
   info: {
18
   info: {
18
     bindingId?: string
19
     bindingId?: string
46
 }
47
 }
47
 
48
 
48
 export function useShapeTree<T extends TLShape>(
49
 export function useShapeTree<T extends TLShape>(
49
-  page: TLPage<T>,
50
+  page: TLPage<T, TLBinding>,
50
   pageState: TLPageState,
51
   pageState: TLPageState,
51
   shapeUtils: TLShapeUtils<T>,
52
   shapeUtils: TLShapeUtils<T>,
52
   onChange?: TLCallbacks['onChange']
53
   onChange?: TLCallbacks['onChange']
87
 
88
 
88
     return (
89
     return (
89
       // TODO: Some shapes should always render (lines, rays)
90
       // TODO: Some shapes should always render (lines, rays)
90
-      Utils.boundsContain(viewport, shapeBounds) ||
91
-      Utils.boundsCollide(viewport, shapeBounds)
91
+      Utils.boundsContain(viewport, shapeBounds) || Utils.boundsCollide(viewport, shapeBounds)
92
     )
92
     )
93
   })
93
   })
94
 
94
 
105
 
105
 
106
   shapesToRender
106
   shapesToRender
107
     .sort((a, b) => a.childIndex - b.childIndex)
107
     .sort((a, b) => a.childIndex - b.childIndex)
108
-    .forEach((shape) =>
109
-      addToShapeTree(shape, tree, page.shapes, selectedIds, pageState)
110
-    )
108
+    .forEach((shape) => addToShapeTree(shape, tree, page.shapes, selectedIds, pageState))
111
 
109
 
112
   return tree
110
   return tree
113
 }
111
 }

+ 2
- 1
packages/core/src/renderer/renderer.tsx View File

8
   TLShapeUtils,
8
   TLShapeUtils,
9
   TLTheme,
9
   TLTheme,
10
   TLBounds,
10
   TLBounds,
11
+  TLBinding,
11
 } from '../types'
12
 } from '../types'
12
 import { Canvas } from './components/canvas'
13
 import { Canvas } from './components/canvas'
13
 import { useTLTheme } from './hooks/useStyle'
14
 import { useTLTheme } from './hooks/useStyle'
17
   extends Partial<TLSettings>,
18
   extends Partial<TLSettings>,
18
     Partial<TLCallbacks> {
19
     Partial<TLCallbacks> {
19
   shapeUtils: TLShapeUtils<T>
20
   shapeUtils: TLShapeUtils<T>
20
-  page: TLPage<T>
21
+  page: TLPage<T, TLBinding>
21
   pageState: TLPageState
22
   pageState: TLPageState
22
   theme?: Partial<TLTheme>
23
   theme?: Partial<TLTheme>
23
   hideBounds?: boolean
24
   hideBounds?: boolean

+ 2
- 2
packages/core/src/types.tsx View File

1
 /* --------------------- Primary -------------------- */
1
 /* --------------------- Primary -------------------- */
2
 
2
 
3
-export interface TLPage<T extends TLShape> {
3
+export interface TLPage<T extends TLShape, B extends TLBinding> {
4
   id: string
4
   id: string
5
   name?: string
5
   name?: string
6
   childIndex?: number
6
   childIndex?: number
7
   shapes: Record<string, T>
7
   shapes: Record<string, T>
8
-  bindings: Record<string, TLBinding>
8
+  bindings: Record<string, B>
9
   backgroundColor?: string
9
   backgroundColor?: string
10
 }
10
 }
11
 
11
 

+ 4
- 1
packages/tldraw/tsconfig.json View File

7
     "jsx": "preserve",
7
     "jsx": "preserve",
8
     "lib": ["dom", "esnext"],
8
     "lib": ["dom", "esnext"],
9
     "module": "esnext",
9
     "module": "esnext",
10
-    "outDir": "./dist/types"
10
+    "outDir": "./dist/types",
11
+    "paths": {
12
+      "@tldraw/core": ["packages/core/dist"]
13
+    }
11
   }
14
   }
12
 }
15
 }

Loading…
Cancel
Save