-
Notifications
You must be signed in to change notification settings - Fork 27
ScrollService #344
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
Open
munkk
wants to merge
22
commits into
qgrid:master
Choose a base branch
from
munkk:ScrollServiceN
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
ScrollService #344
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
0f2713e
ScrollService
munkk 1c83c89
fix_velosity
munkk 6c734e4
fix_formatting
munkk 4496701
ref.
munkk 758ca97
ref.
munkk 35c0ae0
fix_batch
munkk 2ad0db8
add_ability_to_select_cells_whithout_mousemove
munkk 07397f9
fix_guard_null_exeption
munkk 12094ab
fix_cooment+remove_imports
munkk a8d03cb
remove_import
munkk 16281de
move_resizeF_invocation_from_body-core-comp_to_body.ctrl
munkk 64d046c
add_window_provider
munkk 039d931
remove_import
munkk 50e16a2
ref.
munkk b1793af
ref.
munkk d5c271b
ref
munkk 4b0c891
ref
munkk 8b853fa
ref
munkk 590b200
refactoring
munkk 43e4f76
refactoring
munkk a7dc051
ю
munkk e0bee6f
Interval to Timeout
munkk 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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| import { Bag } from '../dom/bag'; | ||
| import { Model } from '../infrastructure/model'; | ||
| import { Table } from '../dom/table'; | ||
|
|
||
| export declare class ScrollService { | ||
| constructor(model: Model, table: Table, bag: Bag, view: any); | ||
|
|
||
| start(): void; | ||
| stop(): void; | ||
| } | ||
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,185 @@ | ||
| import { AppError } from '../infrastructure/error'; | ||
| import { jobLine } from '../services/job.line'; | ||
| import { PathService } from '../path/path.service'; | ||
|
|
||
| export class ScrollService { | ||
| constructor(model, table, bag, view) { | ||
| this.model = model; | ||
| this.table = table; | ||
| this.bag = bag; | ||
| this.view = view; | ||
| this.job = jobLine(50); | ||
| this.startCell = null; | ||
| this.mouseEvent = null; | ||
| this.inMotion = false; | ||
| this.allowScroll = false; | ||
|
|
||
| const pathFinder = new PathService(bag.body); | ||
| model.scrollChanged.watch(e => { | ||
| const path = this.getPath(this.mouseEvent); | ||
| const td = pathFinder.cell(path); | ||
|
|
||
| if (td) { | ||
| this.navigate(td); | ||
| this.view.selection.selectRange(this.startCell, td, 'body'); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| canScroll(e) { | ||
| const rect = this.rect; | ||
| const offset = this.offset; | ||
|
|
||
| const mouseOnTopSide = e.clientY < (rect.top + offset); | ||
| const mouseOnBottomSide = e.clientY > (rect.bottom - offset); | ||
| const mouseOnLeftSide = e.clientX < (rect.left + offset); | ||
| const mouseOnRightSide = e.clientX > (rect.right - offset); | ||
|
|
||
| return mouseOnTopSide || mouseOnBottomSide || mouseOnLeftSide || mouseOnRightSide; | ||
| } | ||
|
|
||
| start(e, startCell) { | ||
| this.mouseEvent = e; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could we calculate td here? not in scrollChanged event |
||
| this.startCell = startCell; | ||
|
|
||
| const direction = this.onEdgeOf(e); | ||
| if (direction) { | ||
| this.allowScroll = true; | ||
| this.scroll(direction); | ||
| } | ||
| } | ||
|
|
||
| scroll(direction) { | ||
| const { scroll } = this.model; | ||
| const scrollState = scroll(); | ||
| const { velocity } = scrollState; | ||
| const scrolledToEnd = () => this.isScrolledToEnd(direction); | ||
|
|
||
| const timeout = () => setTimeout(() => { | ||
| if (this.allowScroll && this.canScroll(this.mouseEvent) && !scrolledToEnd()) { | ||
| this.inMotion = true; | ||
| switch (direction) { | ||
| case 'right': | ||
| case 'bottom': { | ||
| const course = direction === 'bottom' ? 'top' : 'left'; | ||
| const origin = scrollState[course]; | ||
| scroll({ [course]: origin + velocity }); | ||
| break; | ||
| } | ||
| case 'left': | ||
| case 'top': { | ||
| const course = direction === 'top' ? 'top' : 'left'; | ||
| const origin = scrollState[course]; | ||
| scroll({ [course]: origin - velocity }); | ||
| break; | ||
| } | ||
| default: { | ||
| throw new AppError('scroll.service', `doScroll: Wrong direction`); | ||
| } | ||
| } | ||
| } else { | ||
| this.inMotion = false; | ||
| return; | ||
| } | ||
|
|
||
| timeout(); | ||
|
|
||
| }, 50); | ||
|
|
||
| if(!this.inMotion) { | ||
| timeout(); | ||
| } | ||
| } | ||
|
|
||
| isScrolledToEnd(direction) { | ||
| const body = this.body; | ||
|
|
||
| switch (direction) { | ||
| case 'top': { | ||
| return body.scrollTop === 0; | ||
| } | ||
| case 'bottom': { | ||
| return body.clientHeight === body.scrollHeight - body.scrollTop; | ||
| } | ||
| case 'left': { | ||
| return body.scrollLeft === 0; | ||
| } | ||
| case 'right': { | ||
| return body.scrollLeft === body.scrollWidth - body.clientWidth; | ||
| } | ||
| default: { | ||
| throw new AppError('scroll.service', `isScrolledToEnd: Wrong direction`); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| onEdgeOf(e) { | ||
| const rect = this.rect; | ||
| const offset = this.offset; | ||
|
|
||
| if (e.clientY < (rect.top + offset) && | ||
| e.clientX > (rect.left + offset) && | ||
| e.clientX < (rect.right - offset)) { | ||
| return 'top'; | ||
| } | ||
|
|
||
| if (e.clientY > (rect.bottom - offset) && | ||
| e.clientX > (rect.left + offset) && | ||
| e.clientX < (rect.right - offset)) { | ||
| return 'bottom'; | ||
| } | ||
|
|
||
| if (e.clientX < (rect.left + offset) && | ||
| e.clientY > (rect.top + offset) && | ||
| e.clientY < (rect.bottom - offset)) { | ||
| return 'left'; | ||
| } | ||
|
|
||
| if (e.clientX > (rect.right - offset) && | ||
| e.clientY > (rect.top + offset) && | ||
| e.clientY < (rect.bottom - offset)) { | ||
| return 'right'; | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| stop() { | ||
| this.allowScroll = false; | ||
| } | ||
|
|
||
| clearInterval() { | ||
| clearInterval(this.interval); | ||
| this.interval = null; | ||
| } | ||
|
|
||
| navigate(cell) { | ||
| const { focus } = this.view.nav; | ||
| if (focus.canExecute(cell)) { | ||
| focus.execute(cell); | ||
| } | ||
| } | ||
|
|
||
| getPath(e) { | ||
| const path = []; | ||
| let element = document.elementFromPoint(e.clientX, e.clientY); | ||
| while (element) { | ||
| path.push(element); | ||
| element = element.parentElement; | ||
| } | ||
|
|
||
| return path; | ||
| } | ||
|
|
||
| get rect() { | ||
| return this.table.view.rect(this.body); | ||
| } | ||
|
|
||
| get body() { | ||
| return this.table.view.markup.body; | ||
| } | ||
|
|
||
| get offset() { | ||
| return this.model.scroll().offset; | ||
| } | ||
| } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Write unit tests |
||
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
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.
add scroll method