Skip to content

Instantly share code, notes, and snippets.

@rayrayzayzay
Created May 24, 2023 01:05
Show Gist options
  • Save rayrayzayzay/738dbcc21765c789f3da8ff1cd815377 to your computer and use it in GitHub Desktop.
Save rayrayzayzay/738dbcc21765c789f3da8ff1cd815377 to your computer and use it in GitHub Desktop.
let mode: "idle" | "dragging" = "idle"
const dragHandler: InteractionHandler = {
onDragStart(gesture, app) {
if (intersection(gesture.elementsUnderCursor, app.selectedElements).size) {
mode = "dragging";
}
},
onPointerMove(gesture) {
// ignore pointer-moves when we haven't started dragging
if (mode !== "dragging") return;
const delta = sub(gesture.current.point, gesture.start.point);
transformSelectedElements(delta)
// prevents other pointermove handlers acting (not important for this case)
gesture.wasHandled();
},
onDragEnd() {
mode = "idle";
},
};
const selectionHandler: InteractionHandler = {
onClick(gesture) {
addElementToSelectionSet(gesture.topElement);
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment