Skip to content

Commit

Permalink
remove isInteractive for a system with settings
Browse files Browse the repository at this point in the history
  • Loading branch information
arshaw committed Jan 27, 2019
1 parent 8367466 commit 70c8f71
Show file tree
Hide file tree
Showing 16 changed files with 154 additions and 99 deletions.
33 changes: 17 additions & 16 deletions src/core/Calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import DateComponent from './component/DateComponent'
import { PointerDragEvent } from './interactions/pointer'
import EventClicking from './interactions/EventClicking'
import EventHovering from './interactions/EventHovering'
import { componentHash } from './common/browser-context'
import { InteractionSettingsInput, parseInteractionSettings, Interaction, interactionSettingsStore } from './interactions/interaction'
import DateClicking from './interactions/DateClicking'
import DateSelecting from './interactions/DateSelecting'
import EventDragging from './interactions/EventDragging'
Expand Down Expand Up @@ -89,7 +89,7 @@ export default class Calendar {
defaultAllDayEventDuration: Duration
defaultTimedEventDuration: Duration

componentListeners: { [componentUid: string]: { destroy: () => void }[] } = {}
interactionsStore: { [componentUid: string]: Interaction[] } = {}

removeNavLinkListener: any
documentPointer: PointerDragging // for unfocusing
Expand Down Expand Up @@ -852,29 +852,30 @@ export default class Calendar {
// -----------------------------------------------------------------------------------------------------------------


registerComponent(component: DateComponent<any>) {
componentHash[component.uid] = component
registerInteractiveComponent(component: DateComponent<any>, settingsInput: InteractionSettingsInput) {
let settings = parseInteractionSettings(component, settingsInput)

this.componentListeners[component.uid] = [
new EventClicking(component),
new EventHovering(component),
new EventDragging(component),
new EventResizing(component),
new DateClicking(component),
new DateSelecting(component)
this.interactionsStore[component.uid] = [
new EventClicking(settings),
new EventHovering(settings),
new EventDragging(settings),
new EventResizing(settings),
new DateClicking(settings),
new DateSelecting(settings)
]

interactionSettingsStore[component.uid] = settings
}


unregisterComponent(component: DateComponent<any>) {
let { componentListeners } = this
unregisterInteractiveComponent(component: DateComponent<any>) {

for (let listener of componentListeners[component.uid]) {
for (let listener of this.interactionsStore[component.uid]) {
listener.destroy()
}

delete componentListeners[component.uid]
delete componentHash[component.uid]
delete this.interactionsStore[component.uid]
delete interactionSettingsStore[component.uid]
}


Expand Down
3 changes: 0 additions & 3 deletions src/core/common/browser-context.ts

This file was deleted.

12 changes: 0 additions & 12 deletions src/core/component/DateComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ PURPOSES:
export default class DateComponent<PropsType> extends Component<PropsType> {

// self-config, overridable by subclasses. must set on prototype
isInteractable: boolean
useEventCenter: boolean // for dragging geometry
fgSegSelector: string // lets eventRender produce elements without fc-event class
bgSegSelector: string
// IN SCHEDULER: allowAcrossResources
Expand All @@ -62,20 +60,12 @@ export default class DateComponent<PropsType> extends Component<PropsType> {
super(context, isView)

this.el = el

if (this.isInteractable) {
context.calendar.registerComponent(this)
}
}

destroy() {
super.destroy()

removeElement(this.el)

if (this.isInteractable) {
this.calendar.unregisterComponent(this)
}
}


Expand Down Expand Up @@ -282,7 +272,5 @@ export default class DateComponent<PropsType> extends Component<PropsType> {

}

DateComponent.prototype.isInteractable = false
DateComponent.prototype.useEventCenter = true
DateComponent.prototype.fgSegSelector = '.fc-event-container > *'
DateComponent.prototype.bgSegSelector = '.fc-bgevent:not(.fc-nonbusiness)'
4 changes: 2 additions & 2 deletions src/core/interactions-external/ExternalElementDragging.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import ElementDragging from '../dnd/ElementDragging'
import { Hit } from '../interactions/hit'
import HitDragging from '../interactions/HitDragging'
import { componentHash } from '../common/browser-context'
import { interactionSettingsStore } from '../interactions/interaction'
import { PointerDragEvent } from '../interactions/pointer'
import { parseEventDef, createEventInstance, EventTuple } from '../structs/event'
import { createEmptyEventStore, eventTupleToStore } from '../structs/event-store'
Expand Down Expand Up @@ -41,7 +41,7 @@ export default class ExternalElementDragging {

constructor(dragging: ElementDragging, suppliedDragMeta?: DragMetaGenerator) {

let hitDragging = this.hitDragging = new HitDragging(dragging, componentHash)
let hitDragging = this.hitDragging = new HitDragging(dragging, interactionSettingsStore)
hitDragging.requireInitial = false // will start outside of a component
hitDragging.emitter.on('dragstart', this.handleDragStart)
hitDragging.emitter.on('hitupdate', this.handleHitUpdate)
Expand Down
12 changes: 6 additions & 6 deletions src/core/interactions/DateClicking.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import DateComponent from '../component/DateComponent'
import FeaturefulElementDragging from '../dnd/FeaturefulElementDragging'
import HitDragging, { isHitsEqual } from './HitDragging'
import { PointerDragEvent } from '../interactions/pointer'
import { Interaction, InteractionSettings, interactionSettingsToStore } from './interaction'

/*
Monitors when the user clicks on a specific date/time of a component.
A pointerdown+pointerup on the same "hit" constitutes a click.
*/
export default class DateClicking {
export default class DateClicking extends Interaction {

component: DateComponent<any>
dragging: FeaturefulElementDragging
hitDragging: HitDragging

constructor(component: DateComponent<any>) {
this.component = component
constructor(settings: InteractionSettings) {
super(settings)
let { component } = settings

// we DO want to watch pointer moves because otherwise finalHit won't get populated
this.dragging = new FeaturefulElementDragging(component.el)
this.dragging.autoScroller.isEnabled = false

let hitDragging = this.hitDragging = new HitDragging(this.dragging, component)
let hitDragging = this.hitDragging = new HitDragging(this.dragging, interactionSettingsToStore(settings))
hitDragging.emitter.on('pointerdown', this.handlePointerDown)
hitDragging.emitter.on('dragend', this.handleDragEnd)
}
Expand Down
11 changes: 6 additions & 5 deletions src/core/interactions/DateSelecting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,28 @@ import { PointerDragEvent } from '../interactions/pointer'
import FeaturefulElementDragging from '../dnd/FeaturefulElementDragging'
import { __assign } from 'tslib'
import { dateSelectionJoinTransformer } from './date-selecting'
import { Interaction, InteractionSettings, interactionSettingsToStore } from './interaction'

/*
Tracks when the user selects a portion of time of a component,
constituted by a drag over date cells, with a possible delay at the beginning of the drag.
*/
export default class DateSelecting {
export default class DateSelecting extends Interaction {

component: DateComponent<any>
dragging: FeaturefulElementDragging
hitDragging: HitDragging
dragSelection: DateSpan | null = null

constructor(component: DateComponent<any>) {
this.component = component
constructor(settings: InteractionSettings) {
super(settings)
let { component } = settings

let dragging = this.dragging = new FeaturefulElementDragging(component.el)
dragging.touchScrollAllowed = false
dragging.minDistance = component.opt('selectMinDistance') || 0
dragging.autoScroller.isEnabled = component.opt('dragScroll')

let hitDragging = this.hitDragging = new HitDragging(this.dragging, component)
let hitDragging = this.hitDragging = new HitDragging(this.dragging, interactionSettingsToStore(settings))
hitDragging.emitter.on('pointerdown', this.handlePointerDown)
hitDragging.emitter.on('dragstart', this.handleDragStart)
hitDragging.emitter.on('hitupdate', this.handleHitUpdate)
Expand Down
12 changes: 5 additions & 7 deletions src/core/interactions/EventClicking.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import DateComponent from '../component/DateComponent'
import { listenBySelector } from '../util/dom-event'
import EventApi from '../api/EventApi'
import { elementClosest } from '../util/dom-manip'
import { getElSeg } from '../component/event-rendering'
import { Interaction, InteractionSettings } from './interaction'

/*
Detects when the user clicks on an event within a DateComponent
*/
export default class EventClicking {
export default class EventClicking extends Interaction {

component: DateComponent<any>
destroy: () => void

constructor(component: DateComponent<any>) {
this.component = component
constructor(settings: InteractionSettings) {
super(settings)
let { component } = settings

this.destroy = listenBySelector(
component.el,
Expand Down
14 changes: 7 additions & 7 deletions src/core/interactions/EventDragging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { PointerDragEvent } from '../interactions/pointer'
import { Hit } from './hit'
import HitDragging, { isHitsEqual } from './HitDragging'
import { EventMutation, applyMutationToEventStore } from '../structs/event-mutation'
import { componentHash } from '../common/browser-context'
import { startOfDay } from '../datelib/marker'
import { elementClosest } from '../util/dom-manip'
import FeaturefulElementDragging from '../dnd/FeaturefulElementDragging'
Expand All @@ -17,12 +16,12 @@ import { __assign } from 'tslib'
import { ExternalDropApi } from '../interactions-external/ExternalElementDragging'
import View from '../View'
import { eventDragMutationMassager } from './event-dragging'
import { Interaction, InteractionSettings, interactionSettingsStore } from './interaction'

export default class EventDragging { // TODO: rename to EventSelectingAndDragging
export default class EventDragging extends Interaction { // TODO: rename to EventSelectingAndDragging

static SELECTOR = '.fc-draggable, .fc-resizable' // TODO: test this in IE11

component: DateComponent<any>
dragging: FeaturefulElementDragging
hitDragging: HitDragging

Expand All @@ -35,16 +34,17 @@ export default class EventDragging { // TODO: rename to EventSelectingAndDraggin
validMutation: EventMutation | null = null
mutatedRelevantEvents: EventStore | null = null

constructor(component: DateComponent<any>) {
this.component = component
constructor(settings: InteractionSettings) {
super(settings)
let { component } = this

let dragging = this.dragging = new FeaturefulElementDragging(component.el)
dragging.pointer.selector = EventDragging.SELECTOR
dragging.touchScrollAllowed = false
dragging.autoScroller.isEnabled = component.opt('dragScroll')

let hitDragging = this.hitDragging = new HitDragging(this.dragging, componentHash)
hitDragging.useSubjectCenter = component.useEventCenter
let hitDragging = this.hitDragging = new HitDragging(this.dragging, interactionSettingsStore)
hitDragging.useSubjectCenter = settings.useEventCenter
hitDragging.emitter.on('pointerdown', this.handlePointerDown)
hitDragging.emitter.on('dragstart', this.handleDragStart)
hitDragging.emitter.on('hitupdate', this.handleHitUpdate)
Expand Down
10 changes: 5 additions & 5 deletions src/core/interactions/EventHovering.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import DateComponent from '../component/DateComponent'
import { listenToHoverBySelector } from '../util/dom-event'
import EventApi from '../api/EventApi'
import { getElSeg } from '../component/event-rendering'
import { Interaction, InteractionSettings } from './interaction'

/*
Triggers events and adds/removes core classNames when the user's pointer
enters/leaves event-elements of a component.
*/
export default class EventHovering {
export default class EventHovering extends Interaction {

component: DateComponent<any>
removeHoverListeners: () => void
currentSegEl: HTMLElement

constructor(component: DateComponent<any>) {
this.component = component
constructor(settings: InteractionSettings) {
super(settings)
let { component } = settings

this.removeHoverListeners = listenToHoverBySelector(
component.el,
Expand Down
13 changes: 7 additions & 6 deletions src/core/interactions/EventResizing.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { default as DateComponent, Seg } from '../component/DateComponent'
import { Seg } from '../component/DateComponent'
import { Hit } from './hit'
import HitDragging, { isHitsEqual } from './HitDragging'
import { EventMutation, applyMutationToEventStore } from '../structs/event-mutation'
Expand All @@ -14,10 +14,10 @@ import { createDuration } from '../datelib/duration'
import { EventInteractionState } from './event-interaction-state'
import { __assign } from 'tslib'
import { EventResizeJoinTransforms } from './event-resizing'
import { Interaction, InteractionSettings, interactionSettingsToStore } from './interaction'

export default class EventDragging {
export default class EventDragging extends Interaction {

component: DateComponent<any>
dragging: FeaturefulElementDragging
hitDragging: HitDragging

Expand All @@ -28,15 +28,16 @@ export default class EventDragging {
validMutation: EventMutation | null = null
mutatedRelevantEvents: EventStore | null = null

constructor(component: DateComponent<any>) {
this.component = component
constructor(settings: InteractionSettings) {
super(settings)
let { component } = settings

let dragging = this.dragging = new FeaturefulElementDragging(component.el)
dragging.pointer.selector = '.fc-resizer'
dragging.touchScrollAllowed = false
dragging.autoScroller.isEnabled = component.opt('dragScroll')

let hitDragging = this.hitDragging = new HitDragging(this.dragging, component)
let hitDragging = this.hitDragging = new HitDragging(this.dragging, interactionSettingsToStore(settings))
hitDragging.emitter.on('pointerdown', this.handlePointerDown)
hitDragging.emitter.on('dragstart', this.handleDragStart)
hitDragging.emitter.on('hitupdate', this.handleHitUpdate)
Expand Down

0 comments on commit 70c8f71

Please sign in to comment.