Skip to content

Commit

Permalink
interaction lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
arshaw committed Nov 10, 2020
1 parent 36c22d0 commit c5d182a
Show file tree
Hide file tree
Showing 23 changed files with 188 additions and 240 deletions.
16 changes: 16 additions & 0 deletions packages/interaction/src/ElementScrollGeomCache.ts
@@ -0,0 +1,16 @@
import { computeInnerRect, ElementScrollController } from '@fullcalendar/common'
import { ScrollGeomCache } from './ScrollGeomCache'

export class ElementScrollGeomCache extends ScrollGeomCache {
constructor(el: HTMLElement, doesListening: boolean) {
super(new ElementScrollController(el), doesListening)
}

getEventTarget(): EventTarget {
return (this.scrollController as ElementScrollController).el
}

computeClientRect() {
return computeInnerRect((this.scrollController as ElementScrollController).el)
}
}
12 changes: 5 additions & 7 deletions packages/interaction/src/OffsetTracker.ts
@@ -1,8 +1,8 @@
import {
getClippingParents, computeRect,
pointInsideRect, Rect
pointInsideRect, Rect,
} from '@fullcalendar/common'
import { ElementScrollGeomCache } from './scroll-geom-cache'
import { ElementScrollGeomCache } from './ElementScrollGeomCache'

/*
When this class is instantiated, it records the offset of an element (relative to the document topleft),
Expand All @@ -13,17 +13,16 @@ Also keeps track of all scrolling/overflow:hidden containers that are parents of
and an determine if a given point is inside the combined clipping rectangle.
*/
export class OffsetTracker { // ElementOffsetTracker

scrollCaches: ElementScrollGeomCache[]
origRect: Rect

constructor(el: HTMLElement) {
this.origRect = computeRect(el)

// will work fine for divs that have overflow:hidden
this.scrollCaches = getClippingParents(el).map(function(el) {
return new ElementScrollGeomCache(el, true) // listen=true
})
this.scrollCaches = getClippingParents(el).map(
(scrollEl) => new ElementScrollGeomCache(scrollEl, true), // listen=true
)
}

destroy() {
Expand Down Expand Up @@ -66,7 +65,6 @@ export class OffsetTracker { // ElementOffsetTracker

return true
}

}

// certain clipping containers should never constrain interactions, like <html> and <body>
Expand Down
@@ -1,7 +1,4 @@
import {
Rect, computeInnerRect,
ScrollController, ElementScrollController, WindowScrollController
} from '@fullcalendar/common'
import { Rect, ScrollController } from '@fullcalendar/common'

/*
Is a cache for a given element's scroll information (all the info that ScrollController stores)
Expand All @@ -12,7 +9,6 @@ The cache can be in one of two modes:
- doesListening:true - watch for scrolling and update the cache
*/
export abstract class ScrollGeomCache extends ScrollController {

clientRect: Rect
origScrollTop: number
origScrollLeft: number
Expand Down Expand Up @@ -108,48 +104,4 @@ export abstract class ScrollGeomCache extends ScrollController {

handleScrollChange() {
}

}

export class ElementScrollGeomCache extends ScrollGeomCache {

constructor(el: HTMLElement, doesListening: boolean) {
super(new ElementScrollController(el), doesListening)
}

getEventTarget(): EventTarget {
return (this.scrollController as ElementScrollController).el
}

computeClientRect() {
return computeInnerRect((this.scrollController as ElementScrollController).el)
}

}

export class WindowScrollGeomCache extends ScrollGeomCache {

constructor(doesListening: boolean) {
super(new WindowScrollController(), doesListening)
}

getEventTarget(): EventTarget {
return window
}

computeClientRect(): Rect {
return {
left: this.scrollLeft,
right: this.scrollLeft + this.clientWidth,
top: this.scrollTop,
bottom: this.scrollTop + this.clientHeight
}
}

// the window is the only scroll object that changes it's rectangle relative
// to the document's topleft as it scrolls
handleScrollChange() {
this.clientRect = this.computeClientRect()
}

}
27 changes: 27 additions & 0 deletions packages/interaction/src/WindowScrollGeomCache.ts
@@ -0,0 +1,27 @@
import { Rect, WindowScrollController } from '@fullcalendar/common'
import { ScrollGeomCache } from './ScrollGeomCache'

export class WindowScrollGeomCache extends ScrollGeomCache {
constructor(doesListening: boolean) {
super(new WindowScrollController(), doesListening)
}

getEventTarget(): EventTarget {
return window
}

computeClientRect(): Rect {
return {
left: this.scrollLeft,
right: this.scrollLeft + this.clientWidth,
top: this.scrollTop,
bottom: this.scrollTop + this.clientHeight,
}
}

// the window is the only scroll object that changes it's rectangle relative
// to the document's topleft as it scrolls
handleScrollChange() {
this.clientRect = this.computeClientRect()
}
}
1 change: 0 additions & 1 deletion packages/interaction/src/api-type-deps.ts
@@ -1,4 +1,3 @@

// TODO: rename file to public-types.ts

export { DateClickArg } from './interactions/DateClicking'
Expand Down
17 changes: 7 additions & 10 deletions packages/interaction/src/dnd/AutoScroller.ts
@@ -1,4 +1,6 @@
import { ScrollGeomCache, ElementScrollGeomCache, WindowScrollGeomCache } from '../scroll-geom-cache'
import { ScrollGeomCache } from '../ScrollGeomCache'
import { ElementScrollGeomCache } from '../ElementScrollGeomCache'
import { WindowScrollGeomCache } from '../WindowScrollGeomCache'

interface Edge {
scrollCache: ScrollGeomCache
Expand All @@ -18,10 +20,9 @@ approaches the edge.
The caller must call start + handleMove + stop.
*/
export class AutoScroller {

// options that can be set by caller
isEnabled: boolean = true
scrollQuery: (Window | string)[] = [ window, '.fc-scroller' ]
scrollQuery: (Window | string)[] = [window, '.fc-scroller']
edgeThreshold: number = 50 // pixels
maxVelocity: number = 300 // pixels per second

Expand Down Expand Up @@ -102,7 +103,7 @@ export class AutoScroller {
if (this.isAnimating) { // wasn't cancelled between animation calls
let edge = this.computeBestEdge(
this.pointerScreenX! + window.pageXOffset,
this.pointerScreenY! + window.pageYOffset
this.pointerScreenY! + window.pageYOffset,
)

if (edge) {
Expand All @@ -120,12 +121,11 @@ export class AutoScroller {
let { edgeThreshold } = this
let invDistance = edgeThreshold - edge.distance
let velocity = // the closer to the edge, the faster we scroll
(invDistance * invDistance) / (edgeThreshold * edgeThreshold) * // quadratic
((invDistance * invDistance) / (edgeThreshold * edgeThreshold)) * // quadratic
this.maxVelocity * seconds
let sign = 1

switch (edge.name) {

case 'left':
sign = -1
// falls through
Expand Down Expand Up @@ -156,7 +156,6 @@ export class AutoScroller {

// completely within the rect?
if (leftDist >= 0 && rightDist >= 0 && topDist >= 0 && bottomDist >= 0) {

if (
topDist <= edgeThreshold && this.everMovedUp && scrollCache.canScrollUp() &&
(!bestSide || bestSide.distance > topDist)
Expand Down Expand Up @@ -194,9 +193,8 @@ export class AutoScroller {
return this.queryScrollEls().map((el) => {
if (el === window) {
return new WindowScrollGeomCache(false) // false = don't listen to user-generated scrolls
} else {
return new ElementScrollGeomCache(el, false) // false = don't listen to user-generated scrolls
}
return new ElementScrollGeomCache(el, false) // false = don't listen to user-generated scrolls
})
}

Expand All @@ -213,5 +211,4 @@ export class AutoScroller {

return els
}

}
20 changes: 8 additions & 12 deletions packages/interaction/src/dnd/ElementMirror.ts
Expand Up @@ -6,7 +6,6 @@ The moving element is a clone of some other element.
Must call start + handleMove + stop.
*/
export class ElementMirror {

isVisible: boolean = false // must be explicitly enabled
origScreenX?: number
origScreenY?: number
Expand Down Expand Up @@ -48,14 +47,12 @@ export class ElementMirror {
this.isVisible = bool // needs to happen before updateElPosition
this.updateElPosition() // because was not updating the position while invisible
}
} else {
if (this.isVisible) {
if (this.mirrorEl) {
this.mirrorEl.style.display = 'none'
}

this.isVisible = bool
} else if (this.isVisible) {
if (this.mirrorEl) {
this.mirrorEl.style.display = 'none'
}

this.isVisible = bool
}
}

Expand Down Expand Up @@ -89,7 +86,7 @@ export class ElementMirror {

applyStyle(mirrorEl, {
left: finalSourceElRect.left,
top: finalSourceElRect.top
top: finalSourceElRect.top,
})

whenTransitionDone(mirrorEl, () => {
Expand All @@ -111,7 +108,7 @@ export class ElementMirror {
if (this.sourceEl && this.isVisible) {
applyStyle(this.getMirrorEl(), {
left: this.sourceElRect!.left + this.deltaX!,
top: this.sourceElRect!.top + this.deltaY!
top: this.sourceElRect!.top + this.deltaY!,
})
}
}
Expand All @@ -138,13 +135,12 @@ export class ElementMirror {
height: sourceElRect.bottom - sourceElRect.top, // explicit width in case there was a 'bottom' value
right: 'auto', // erase and set width instead
bottom: 'auto', // erase and set height instead
margin: 0
margin: 0,
})

this.parentNode.appendChild(mirrorEl)
}

return mirrorEl
}

}
17 changes: 9 additions & 8 deletions packages/interaction/src/dnd/FeaturefulElementDragging.ts
@@ -1,4 +1,11 @@
import { PointerDragEvent, preventSelection, allowSelection, preventContextMenu, allowContextMenu, ElementDragging } from '@fullcalendar/common'
import {
PointerDragEvent,
preventSelection,
allowSelection,
preventContextMenu,
allowContextMenu,
ElementDragging,
} from '@fullcalendar/common'
import { PointerDragging } from './PointerDragging'
import { ElementMirror } from './ElementMirror'
import { AutoScroller } from './AutoScroller'
Expand All @@ -10,7 +17,6 @@ Monitors dragging on an element. Has a number of high-level features:
- a mirror element that follows the pointer
*/
export class FeaturefulElementDragging extends ElementDragging {

pointer: PointerDragging
mirror: ElementMirror
autoScroller: AutoScroller
Expand All @@ -28,7 +34,6 @@ export class FeaturefulElementDragging extends ElementDragging {
isDistanceSurpassed: boolean = false
delayTimeoutId: number | null = null


constructor(containerEl: HTMLElement, selector?: string) {
super(containerEl)

Expand All @@ -55,7 +60,6 @@ export class FeaturefulElementDragging extends ElementDragging {

onPointerDown = (ev: PointerDragEvent) => {
if (!this.isDragging) { // so new drag doesn't happen while revert animation is going

this.isInteracting = true
this.isDelayEnded = false
this.isDistanceSurpassed = false
Expand Down Expand Up @@ -92,7 +96,6 @@ export class FeaturefulElementDragging extends ElementDragging {

onPointerMove = (ev: PointerDragEvent) => {
if (this.isInteracting) {

this.emitter.trigger('pointermove', ev)

if (!this.isDistanceSurpassed) {
Expand All @@ -107,7 +110,6 @@ export class FeaturefulElementDragging extends ElementDragging {
}

if (this.isDragging) {

// a real pointer move? (not one simulated by scrolling)
if (ev.origEvent.type !== 'scroll') {
this.mirror.handleMove(ev.pageX, ev.pageY)
Expand Down Expand Up @@ -182,7 +184,7 @@ export class FeaturefulElementDragging extends ElementDragging {
// that come from the document to fire beforehand. much more convenient this way.
this.mirror.stop(
this.mirrorNeedsRevert,
this.stopDrag.bind(this, ev) // bound with args
this.stopDrag.bind(this, ev), // bound with args
)
}

Expand All @@ -208,5 +210,4 @@ export class FeaturefulElementDragging extends ElementDragging {
setAutoScrollEnabled(bool: boolean) {
this.autoScroller.isEnabled = bool
}

}

0 comments on commit c5d182a

Please sign in to comment.