-
-
Notifications
You must be signed in to change notification settings - Fork 651
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
354 additions
and
162 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,23 @@ | ||
import type {DragDropManager} from '../manager'; | ||
|
||
export abstract class Plugin< | ||
export class Plugin< | ||
T extends DragDropManager<any, any> = DragDropManager<any, any>, | ||
> { | ||
constructor(protected manager: T) { | ||
this.manager = manager; | ||
} | ||
|
||
public abstract destroy(): void; | ||
public disabled: boolean = false; | ||
|
||
public enable() { | ||
this.disabled = false; | ||
} | ||
|
||
public disable() { | ||
this.disabled = true; | ||
} | ||
|
||
public destroy() { | ||
// no-op | ||
} | ||
} |
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,24 @@ | ||
import type {Coordinates} from '@dnd-kit/geometry'; | ||
|
||
import {getScrollPosition} from './getScrollPosition'; | ||
|
||
export function canScroll(scrollableElement: Element, by?: Coordinates) { | ||
const {isTop, isBottom, isLeft, isRight, position} = | ||
getScrollPosition(scrollableElement); | ||
|
||
const {x, y} = by ?? {x: 0, y: 0}; | ||
|
||
const top = !isTop && position.current.y + y > 0; | ||
const bottom = !isBottom && position.current.y + y < position.max.y; | ||
const left = !isLeft && position.current.x + x > 0; | ||
const right = !isRight && position.current.x + x < position.max.x; | ||
|
||
return { | ||
top, | ||
bottom, | ||
left, | ||
right, | ||
x: left || right, | ||
y: top || bottom, | ||
}; | ||
} |
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 |
---|---|---|
@@ -1,35 +1,45 @@ | ||
import {isDocumentScrollingElement} from './documentScrollingElement'; | ||
import { | ||
getViewportBoundingRectangle, | ||
getBoundingRectangle, | ||
} from '../bounding-rectangle'; | ||
|
||
export function getScrollPosition(scrollingContainer: Element) { | ||
const minScroll = { | ||
x: 0, | ||
y: 0, | ||
}; | ||
const dimensions = isDocumentScrollingElement(scrollingContainer) | ||
export function getScrollPosition(scrollableElement: Element) { | ||
const rect = isDocumentScrollingElement(scrollableElement) | ||
? getViewportBoundingRectangle(scrollableElement) | ||
: getBoundingRectangle(scrollableElement); | ||
|
||
const dimensions = isDocumentScrollingElement(scrollableElement) | ||
? { | ||
height: window.innerHeight, | ||
width: window.innerWidth, | ||
} | ||
: { | ||
height: scrollingContainer.clientHeight, | ||
width: scrollingContainer.clientWidth, | ||
height: scrollableElement.clientHeight, | ||
width: scrollableElement.clientWidth, | ||
}; | ||
const maxScroll = { | ||
x: scrollingContainer.scrollWidth - dimensions.width, | ||
y: scrollingContainer.scrollHeight - dimensions.height, | ||
const position = { | ||
current: { | ||
x: scrollableElement.scrollLeft, | ||
y: scrollableElement.scrollTop, | ||
}, | ||
max: { | ||
x: scrollableElement.scrollWidth - dimensions.width, | ||
y: scrollableElement.scrollHeight - dimensions.height, | ||
}, | ||
}; | ||
|
||
const isTop = scrollingContainer.scrollTop <= minScroll.y; | ||
const isLeft = scrollingContainer.scrollLeft <= minScroll.x; | ||
const isBottom = scrollingContainer.scrollTop >= maxScroll.y; | ||
const isRight = scrollingContainer.scrollLeft >= maxScroll.x; | ||
const isTop = position.current.y <= 0; | ||
const isLeft = position.current.x <= 0; | ||
const isBottom = position.current.y >= position.max.y; | ||
const isRight = position.current.x >= position.max.x; | ||
|
||
return { | ||
rect, | ||
position, | ||
isTop, | ||
isLeft, | ||
isBottom, | ||
isRight, | ||
maxScroll, | ||
minScroll, | ||
}; | ||
} |
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export {DraggableClone, DraggablePlaceholder} from './feedback'; | ||
export {AutoScroller, ScrollManager} from './scrolling'; | ||
export {AutoScroller, Scroller, ScrollManager} from './scrolling'; |
Oops, something went wrong.