| 16 | } |
| 17 | |
| 18 | export class NoteDragging { |
| 19 | readonly page: Page; |
| 20 | |
| 21 | react: UnwrapRef<IDraggingReact>; |
| 22 | |
| 23 | initialRegionId?: string; |
| 24 | finalRegionId?: string; |
| 25 | |
| 26 | initialPointerPos: Vec2 = new Vec2(); |
| 27 | originalNotePositions: Record<string, Vec2> = {}; |
| 28 | |
| 29 | private _cancelPointerEvents?: () => void; |
| 30 | |
| 31 | constructor(input: { page: Page }) { |
| 32 | this.page = input.page; |
| 33 | |
| 34 | this.react = refProp<IDraggingReact>(this, 'react', { |
| 35 | active: false, |
| 36 | }); |
| 37 | } |
| 38 | |
| 39 | start(params: { note: PageNote; event: PointerEvent }) { |
| 40 | if (this.page.react.readOnly) { |
| 41 | return; |
| 42 | } |
| 43 | |
| 44 | // Prevent dragging unmovable notes |
| 45 | |
| 46 | if ( |
| 47 | this.page.activeElem.react.value?.type === 'note' && |
| 48 | !this.page.activeElem.react.value.react.collab.movable |
| 49 | ) { |
| 50 | if (params.event.pointerType !== 'mouse') { |
| 51 | this.page.panning.start(params.event); |
| 52 | } |
| 53 | |
| 54 | return; |
| 55 | } |
| 56 | |
| 57 | this.react = { active: false }; |
| 58 | |
| 59 | this.initialPointerPos = this.page.pos.eventToClient(params.event); |
| 60 | |
| 61 | this._cancelPointerEvents = listenPointerEvents(params.event, { |
| 62 | dragStartDistance: 5, |
| 63 | |
| 64 | dragStart: () => this._dragStart(params), |
| 65 | dragUpdate: this._dragUpdate, |
| 66 | dragEnd: this._dragFinish, |
| 67 | }); |
| 68 | } |
| 69 | |
| 70 | private _dragStart = async (params: { |
| 71 | note: PageNote; |
| 72 | event: PointerEvent; |
| 73 | }) => { |
| 74 | this.initialRegionId = this.page.activeRegion.react.value.id; |
| 75 | this.finalRegionId = this.page.id; |
nothing calls this directly
no test coverage detected