-
Notifications
You must be signed in to change notification settings - Fork 548
dbeaver/pro#9659 add dnd scroll container #4476
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
81 changes: 81 additions & 0 deletions
81
webapp/packages/core-ui/src/DragAndDrop/DNDScrollContainer.tsx
This file contains hidden or 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,81 @@ | ||
| /* | ||
| * CloudBeaver - Cloud Database Manager | ||
| * Copyright (C) 2020-2026 DBeaver Corp and others | ||
| * | ||
| * Licensed under the Apache License, Version 2.0. | ||
| * you may not use this file except in compliance with the License. | ||
| */ | ||
|
|
||
| import { forwardRef, useEffect, useRef } from 'react'; | ||
| import { observer } from 'mobx-react-lite'; | ||
|
|
||
| import { useMergeRefs, useMouse } from '@cloudbeaver/core-blocks'; | ||
|
|
||
| const EDGE = 60; | ||
| const MAX_SPEED = 12; | ||
|
|
||
| export interface IDNDScrollContainerProps { | ||
| isDragging: boolean; | ||
| className?: string; | ||
| children: React.ReactNode; | ||
| } | ||
|
|
||
| export const DNDScrollContainer = observer( | ||
| forwardRef<HTMLDivElement, IDNDScrollContainerProps>(function DNDScrollContainer({ isDragging, className, children }, externalRef) { | ||
| const innerRef = useRef<HTMLDivElement>(null); | ||
| const speedRef = useRef(0); | ||
| const rafRef = useRef<number>(null); | ||
|
|
||
| const mouse = useMouse<HTMLDivElement>(); | ||
|
|
||
| const el = innerRef.current; | ||
|
|
||
| if (isDragging && el && mouse.state.position) { | ||
| const y = mouse.state.position.y; | ||
| const h = el.getBoundingClientRect().height; | ||
|
|
||
| if (y < EDGE) { | ||
| speedRef.current = -MAX_SPEED * Math.min((EDGE - y) / EDGE, 1); | ||
| } else if (y > h - EDGE) { | ||
| speedRef.current = MAX_SPEED * Math.min((y - (h - EDGE)) / EDGE, 1); | ||
| } else { | ||
| speedRef.current = 0; | ||
| } | ||
| } else { | ||
| speedRef.current = 0; | ||
| } | ||
|
|
||
| useEffect(() => { | ||
| if (!isDragging) { | ||
| return; | ||
| } | ||
|
|
||
| // rAF loop for smooth scrolling | ||
| const loop = () => { | ||
| const node = innerRef.current; | ||
|
|
||
| if (node && speedRef.current !== 0) { | ||
| node.scrollTop += speedRef.current; | ||
| } | ||
|
|
||
| rafRef.current = requestAnimationFrame(loop); | ||
| }; | ||
|
|
||
| rafRef.current = requestAnimationFrame(loop); | ||
|
|
||
| return () => { | ||
| if (rafRef.current) { | ||
| cancelAnimationFrame(rafRef.current); | ||
| } | ||
| }; | ||
| }, [isDragging]); | ||
|
|
||
| const ref = useMergeRefs(innerRef, mouse.reference, externalRef); | ||
|
|
||
| return ( | ||
| <div ref={ref} className={className}> | ||
| {children} | ||
| </div> | ||
| ); | ||
| }), | ||
| ); |
11 changes: 11 additions & 0 deletions
11
webapp/packages/core-ui/src/DragAndDrop/DNDScrollContainerLoader.ts
This file contains hidden or 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,11 @@ | ||
| /* | ||
| * CloudBeaver - Cloud Database Manager | ||
| * Copyright (C) 2020-2026 DBeaver Corp and others | ||
| * | ||
| * Licensed under the Apache License, Version 2.0. | ||
| * you may not use this file except in compliance with the License. | ||
| */ | ||
|
|
||
| import { importLazyComponent } from '@cloudbeaver/core-blocks'; | ||
|
|
||
| export const DNDScrollContainer = importLazyComponent(() => import('./DNDScrollContainer.js').then(m => m.DNDScrollContainer)); |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The best solution here is to invent something tricky with html/css so it triggers scroll. Cause it already works fine, but this zone is too small
I can see why you want JS to handle that. But feel like there is a native html/css solution, it's just tricky to find
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't find any native solution. Everyone mentions that the native solution has a very small scrollable area. If you know of any solutions, feel free to suggest them.