aboutsummaryrefslogtreecommitdiff
path: root/src/Utils.ts
diff options
context:
space:
mode:
authorusodhi <61431818+usodhi@users.noreply.github.com>2021-02-01 18:42:38 -0500
committerusodhi <61431818+usodhi@users.noreply.github.com>2021-02-01 18:42:38 -0500
commitb160a00f80c4855e190d75f97482b5b019e77437 (patch)
tree4fd150d45a5c49b9d5572edcb663956c0b29dd60 /src/Utils.ts
parent888fb3b3933e7aa48e9ac3abe85536328fcca336 (diff)
parent41bb365dd4f787aec2262dcb07508e0de3837e10 (diff)
more merge
Diffstat (limited to 'src/Utils.ts')
-rw-r--r--src/Utils.ts31
1 files changed, 22 insertions, 9 deletions
diff --git a/src/Utils.ts b/src/Utils.ts
index 3cf695a30..c7074c3da 100644
--- a/src/Utils.ts
+++ b/src/Utils.ts
@@ -500,9 +500,9 @@ export function addStyleSheet(styleType: string = "text/css") {
const sheets = document.head.appendChild(style);
return (sheets as any).sheet;
}
-export function addStyleSheetRule(sheet: any, selector: any, css: any) {
+export function addStyleSheetRule(sheet: any, selector: any, css: any, selectorPrefix = ".") {
const propText = typeof css === "string" ? css : Object.keys(css).map(p => p + ":" + (p === "content" ? "'" + css[p] + "'" : css[p])).join(";");
- return sheet.insertRule("." + selector + "{" + propText + "}", sheet.cssRules.length);
+ return sheet.insertRule(selectorPrefix + selector + "{" + propText + "}", sheet.cssRules.length);
}
export function removeStyleSheetRule(sheet: any, rule: number) {
if (sheet.rules.length) {
@@ -600,17 +600,32 @@ export function hasDescendantTarget(x: number, y: number, target: HTMLDivElement
return entered;
}
+export function StopEvent(e: React.PointerEvent | React.MouseEvent) {
+ e.stopPropagation();
+ e.preventDefault();
+}
+
export function setupMoveUpEvents(
target: object,
e: React.PointerEvent,
moveEvent: (e: PointerEvent, down: number[], delta: number[]) => boolean,
- upEvent: (e: PointerEvent, movement: number[]) => any,
+ upEvent: (e: PointerEvent, movement: number[], isClick: boolean) => any,
clickEvent: (e: PointerEvent, doubleTap?: boolean) => any,
stopPropagation: boolean = true,
- stopMovePropagation: boolean = true
+ stopMovePropagation: boolean = true,
+ noDoubleTapTimeout?: () => void
) {
+ const doubleTapTimeout = 300;
+ (target as any)._doubleTap = (Date.now() - (target as any)._lastTap < doubleTapTimeout);
+ (target as any)._lastTap = Date.now();
(target as any)._downX = (target as any)._lastX = e.clientX;
(target as any)._downY = (target as any)._lastY = e.clientY;
+ if (!(target as any)._doubleTime && noDoubleTapTimeout) {
+ (target as any)._doubleTime = setTimeout(() => {
+ noDoubleTapTimeout?.();
+ (target as any)._doubleTime = undefined;
+ }, doubleTapTimeout);
+ }
const _moveEvent = (e: PointerEvent): void => {
if (Math.abs(e.clientX - (target as any)._downX) > Utils.DRAG_THRESHOLD || Math.abs(e.clientY - (target as any)._downY) > Utils.DRAG_THRESHOLD) {
@@ -628,12 +643,10 @@ export function setupMoveUpEvents(
(target as any)._lastY = e.clientY;
stopMovePropagation && e.stopPropagation();
};
- (target as any)._doubleTap = false;
const _upEvent = (e: PointerEvent): void => {
- (target as any)._doubleTap = (Date.now() - (target as any)._lastTap < 300);
- (target as any)._lastTap = Date.now();
- upEvent(e, [e.clientX - (target as any)._downX, e.clientY - (target as any)._downY]);
- if (Math.abs(e.clientX - (target as any)._downX) < 4 && Math.abs(e.clientY - (target as any)._downY) < 4) {
+ const isClick = Math.abs(e.clientX - (target as any)._downX) < 4 && Math.abs(e.clientY - (target as any)._downY) < 4;
+ upEvent(e, [e.clientX - (target as any)._downX, e.clientY - (target as any)._downY], isClick);
+ if (isClick) {
if ((target as any)._doubleTime && (target as any)._doubleTap) {
clearTimeout((target as any)._doubleTime);
(target as any)._doubleTime = undefined;