-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #205 from germanocaumo/tldraw
feat(whiteboard): add tldraw support
- Loading branch information
Showing
15 changed files
with
28,202 additions
and
11,963 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import React from 'react'; | ||
import { useCurrentIndex } from 'components/utils/hooks'; | ||
import storage from 'utils/data/storage'; | ||
import './index.scss'; | ||
|
||
const getCursor = (index, size, pageState) => { | ||
const inactive = { | ||
x: -1, | ||
y: -1, | ||
} | ||
|
||
if (index === -1) return inactive; | ||
|
||
const currentData = storage.cursor[index]; | ||
if (currentData.x === -1 && currentData.y === -1) return inactive; | ||
|
||
let _x = null; | ||
let _y = null; | ||
|
||
_x = (currentData.x + pageState?.camera?.point[0]) * pageState?.camera?.zoom; | ||
_y = (currentData.y + pageState?.camera?.point[1]) * pageState?.camera?.zoom; | ||
|
||
if (_x > size.width || _y > size.height ) return inactive; | ||
|
||
return { | ||
x: _x, | ||
y: _y | ||
}; | ||
}; | ||
|
||
const Cursor = ({ tldrawAPI, size }) => { | ||
const currentIndex = useCurrentIndex(storage.cursor); | ||
const { x, y } = getCursor(currentIndex, size, tldrawAPI?.getPageState()); | ||
|
||
if (x === -1 || y === -1) return null; | ||
|
||
return ( | ||
<div | ||
style={{ | ||
zIndex: 2, | ||
position: "absolute", | ||
left: x - 5.0, | ||
top: y - 5.0, | ||
width: 10, | ||
height: 10, | ||
borderRadius: "50%", | ||
background: "#C70039", | ||
pointerEvents: "none", | ||
}} | ||
/> | ||
); | ||
}; | ||
|
||
export default Cursor; |
Oops, something went wrong.