diff --git a/src/Scrollbar.tsx b/src/Scrollbar.tsx index 2dd62a0..533f466 100644 --- a/src/Scrollbar.tsx +++ b/src/Scrollbar.tsx @@ -1,28 +1,28 @@ -import { cnb } from "cnbuilder"; -import * as React from "react"; -import { DraggableData } from "react-draggable"; -import { zoomLevel } from "zoom-level"; -import Emittr from "./Emittr"; -import Loop from "./Loop"; -import ScrollbarThumb, { ScrollbarThumbProps } from "./ScrollbarThumb"; +import { cnb } from 'cnbuilder'; +import * as React from 'react'; +import { DraggableData } from 'react-draggable'; +import { zoomLevel } from 'zoom-level'; +import Emittr from './Emittr'; +import Loop from './Loop'; +import ScrollbarThumb, { ScrollbarThumbProps } from './ScrollbarThumb'; import ScrollbarTrack, { ScrollbarTrackClickParameters, - ScrollbarTrackProps -} from "./ScrollbarTrack"; -import defaultStyle from "./style"; + ScrollbarTrackProps, +} from './ScrollbarTrack'; +import defaultStyle from './style'; import { AXIS_DIRECTION, ElementPropsWithElementRefAndRenderer, ScrollState, - TRACK_CLICK_BEHAVIOR -} from "./types"; -import * as util from "./util"; -import { isBrowser, renderDivWithRenderer } from "./util"; + TRACK_CLICK_BEHAVIOR, +} from './types'; +import * as util from './util'; +import { isBrowser, renderDivWithRenderer } from './util'; let pageZoomLevel: number = isBrowser ? zoomLevel() : 1; if (isBrowser) { window.addEventListener( - "resize", + 'resize', () => { pageZoomLevel = zoomLevel(); }, @@ -85,11 +85,11 @@ export type ScrollbarProps = ElementPropsWithElementRefAndRenderer & { scrollerProps?: ElementPropsWithElementRefAndRenderer; contentProps?: ElementPropsWithElementRefAndRenderer; - trackXProps?: Pick>; - trackYProps?: Pick>; + trackXProps?: Pick>; + trackYProps?: Pick>; - thumbXProps?: Pick>; - thumbYProps?: Pick>; + thumbXProps?: Pick>; + thumbYProps?: Pick>; onUpdate?: (scrollValues: ScrollState, prevScrollState: ScrollState) => void; onScroll?: (scrollValues: ScrollState, prevScrollState: ScrollState) => void; @@ -106,7 +106,7 @@ export type ScrollbarState = { export type ScrollbarContextValue = { parentScrollbar: Scrollbar | null }; export const ScrollbarContext: React.Context = React.createContext({ - parentScrollbar: null + parentScrollbar: null, } as ScrollbarContextValue); export default class Scrollbar extends React.Component { @@ -131,7 +131,7 @@ export default class Scrollbar extends React.Component ) : ( children - ) + ), } as ElementPropsWithElementRefAndRenderer; const scrollerProps = { ...propsScrollerProps, - key: "ScrollbarsCustom-Scroller", - className: cnb("ScrollbarsCustom-Scroller", propsScrollerProps!.className), + key: 'ScrollbarsCustom-Scroller', + className: cnb('ScrollbarsCustom-Scroller', propsScrollerProps!.className), style: styles.scroller, children: renderDivWithRenderer(contentProps, this.elementRefContent), - onScroll: this.handleScrollerScroll + onScroll: this.handleScrollerScroll, } as ElementPropsWithElementRefAndRenderer; const wrapperProps = { ...propsWrapperProps, - key: "ScrollbarsCustom-Wrapper", - className: cnb("ScrollbarsCustom-Wrapper", propsWrapperProps!.className), + key: 'ScrollbarsCustom-Wrapper', + className: cnb('ScrollbarsCustom-Wrapper', propsWrapperProps!.className), style: styles.wrapper, - children: renderDivWithRenderer(scrollerProps, this.elementRefScroller) + children: renderDivWithRenderer(scrollerProps, this.elementRefScroller), } as ElementPropsWithElementRefAndRenderer; holderChildren.push(renderDivWithRenderer(wrapperProps, this.elementRefWrapper)); @@ -942,24 +942,24 @@ export default class Scrollbar extends React.Component; @@ -972,24 +972,24 @@ export default class Scrollbar extends React.Component; @@ -1002,14 +1002,14 @@ export default class Scrollbar extends React.Component { if (!this._scrollDetectionTO) { - this.eventEmitter.emit("scrollStart", this.getScrollState()); + this.eventEmitter.emit('scrollStart', this.getScrollState()); } else if (isBrowser) { window.clearTimeout(this._scrollDetectionTO); } this._scrollDetectionTO = isBrowser - ? window.setTimeout( - this._scrollDetectionCallback, - this.props.scrollDetectionThreshold || 0 - ) + ? window.setTimeout(this._scrollDetectionCallback, this.props.scrollDetectionThreshold || 0) : null; }; private _scrollDetectionCallback = () => { this._scrollDetectionTO = null; - this.eventEmitter.emit("scrollStop", this.getScrollState()); + this.eventEmitter.emit('scrollStop', this.getScrollState()); }; } diff --git a/src/ScrollbarThumb.tsx b/src/ScrollbarThumb.tsx index d5d1233..84c32bf 100644 --- a/src/ScrollbarThumb.tsx +++ b/src/ScrollbarThumb.tsx @@ -2,7 +2,7 @@ import { cnb } from 'cnbuilder'; import * as React from 'react'; import { DraggableCore, DraggableData, DraggableEvent } from 'react-draggable'; import { AXIS_DIRECTION, ElementPropsWithElementRefAndRenderer } from './types'; -import { isBrowser, isFun, isUndef, renderDivWithRenderer } from "./util"; +import { isBrowser, isFun, isUndef, renderDivWithRenderer } from './util'; export type DragCallbackData = Pick>; @@ -19,26 +19,26 @@ export type ScrollbarThumbProps = ElementPropsWithElementRefAndRenderer & { export default class ScrollbarThumb extends React.Component { private static selectStartReplacer = () => false; - public lastDragData: DragCallbackData = { - x: 0, - y: 0, - deltaX: 0, - deltaY: 0, - lastX: 0, - lastY: 0, - }; - public element: HTMLDivElement | null = null; + public initialOffsetX = 0; + + public initialOffsetY = 0; + private prevUserSelect: string; private prevOnSelectStart: ((ev: Event) => boolean) | null; private elementRefHack = React.createRef(); - public initialOffsetX = 0; - - public initialOffsetY = 0; + public lastDragData: DragCallbackData = { + x: 0, + y: 0, + deltaX: 0, + deltaY: 0, + lastX: 0, + lastY: 0, + }; public componentDidMount(): void { if (!this.element) { diff --git a/testbench/webpack.config.js b/testbench/webpack.config.js index aa9f7ab..4235737 100644 --- a/testbench/webpack.config.js +++ b/testbench/webpack.config.js @@ -1,4 +1,4 @@ -const path = require('path'); +const path = require('node:path'); // eslint-disable-next-line import/no-unresolved const HtmlWebpackPlugin = require('html-webpack-plugin'); // eslint-disable-next-line import/no-unresolved