-
Notifications
You must be signed in to change notification settings - Fork 81
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 #251 from idrawjs/dev-v0.4
feat: add dragger and optimize renderer
- Loading branch information
Showing
38 changed files
with
571 additions
and
284 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
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,53 @@ | ||
import type { BoardMiddleware, CoreEvent, Point } from '@idraw/types'; | ||
|
||
const key = 'DRAG'; | ||
const keyPrevPoint = Symbol(`${key}_prevPoint`); | ||
|
||
type DraggerSharedStorage = { | ||
[keyPrevPoint]: Point | null; | ||
}; | ||
|
||
export const MiddlewareDragger: BoardMiddleware<DraggerSharedStorage, CoreEvent> = (opts) => { | ||
const { eventHub, sharer, viewer } = opts; | ||
let isDragging = false; | ||
|
||
return { | ||
hover() { | ||
if (isDragging === true) { | ||
return; | ||
} | ||
eventHub.trigger('cursor', { | ||
type: 'drag-default' | ||
}); | ||
}, | ||
|
||
pointStart(e) { | ||
const { point } = e; | ||
sharer.setSharedStorage(keyPrevPoint, point); | ||
isDragging = true; | ||
eventHub.trigger('cursor', { | ||
type: 'drag-active' | ||
}); | ||
}, | ||
|
||
pointMove(e) { | ||
const { point } = e; | ||
const prevPoint = sharer.getSharedStorage(keyPrevPoint); | ||
if (point && prevPoint) { | ||
const moveX = point.x - prevPoint.x; | ||
const moveY = point.y - prevPoint.y; | ||
viewer.scroll({ moveX, moveY }); | ||
viewer.drawFrame(); | ||
} | ||
sharer.setSharedStorage(keyPrevPoint, point); | ||
}, | ||
|
||
pointEnd() { | ||
isDragging = false; | ||
sharer.setSharedStorage(keyPrevPoint, null); | ||
eventHub.trigger('cursor', { | ||
type: 'drag-default' | ||
}); | ||
} | ||
}; | ||
}; |
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
Oops, something went wrong.