-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make hit system relative. move unselect out of core Calendar
- Loading branch information
Showing
8 changed files
with
181 additions
and
216 deletions.
There are no files selected for viewing
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,70 @@ | ||
import Calendar, { DateSelectionApi } from '../Calendar' | ||
import PointerDragging from '../dnd/PointerDragging' | ||
import { PointerDragEvent } from './pointer' | ||
import { elementClosest } from '../util/dom-manip' | ||
import EventDragging from './EventDragging' | ||
|
||
export default class UnselectAuto { | ||
|
||
calendar: Calendar | ||
documentPointer: PointerDragging // for unfocusing | ||
isRecentPointerDateSelect = false // wish we could use a selector to detect date selection, but uses hit system | ||
|
||
constructor(calendar: Calendar) { | ||
this.calendar = calendar | ||
|
||
let documentPointer = this.documentPointer = new PointerDragging(document) | ||
documentPointer.shouldIgnoreMove = true | ||
documentPointer.shouldWatchScroll = false | ||
documentPointer.emitter.on('pointerup', this.onDocumentPointerUp) | ||
|
||
/* | ||
TODO: better way to know about whether there was a selection with the pointer | ||
*/ | ||
calendar.on('select', this.onSelect) | ||
} | ||
|
||
destroy() { | ||
this.calendar.off('select', this.onSelect) | ||
this.documentPointer.destroy() | ||
} | ||
|
||
onSelect = (selectInfo: DateSelectionApi) => { | ||
if (selectInfo.jsEvent) { | ||
this.isRecentPointerDateSelect = true | ||
} | ||
} | ||
|
||
onDocumentPointerUp = (pev: PointerDragEvent) => { | ||
let { calendar, documentPointer } = this | ||
let { state } = calendar | ||
|
||
// touch-scrolling should never unfocus any type of selection | ||
if (!documentPointer.wasTouchScroll) { | ||
|
||
if ( | ||
state.dateSelection && // an existing date selection? | ||
!this.isRecentPointerDateSelect // a new pointer-initiated date selection since last onDocumentPointerUp? | ||
) { | ||
let unselectAuto = calendar.viewOpt('unselectAuto') | ||
let unselectCancel = calendar.viewOpt('unselectCancel') | ||
|
||
if (unselectAuto && (!unselectAuto || !elementClosest(documentPointer.downEl, unselectCancel))) { | ||
calendar.unselect(pev) | ||
} | ||
} | ||
|
||
if ( | ||
state.eventSelection && // an existing event selected? | ||
!elementClosest(documentPointer.downEl, EventDragging.SELECTOR) // interaction DIDN'T start on an event | ||
) { | ||
calendar.dispatch({ type: 'UNSELECT_EVENT' }) | ||
} | ||
|
||
} | ||
|
||
this.isRecentPointerDateSelect = false | ||
} | ||
|
||
} | ||
|
Oops, something went wrong.