Skip to content

Commit

Permalink
Improve scroll tracking and cleanup types
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Sep 14, 2024
1 parent bbde4ca commit 6fd7899
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 18 deletions.
2 changes: 1 addition & 1 deletion panel/models/button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class ButtonView extends BkButtonView {
visible,
})
}
let timer: number
let timer: ReturnType<typeof setTimeout> | undefined
this.el.addEventListener("mouseenter", () => {
timer = setTimeout(() => toggle(true), this.model.tooltip_delay)
})
Expand Down
2 changes: 1 addition & 1 deletion panel/models/checkbox_button_group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class CheckboxButtonGroupView extends bkCheckboxButtonGroupView {
visible,
})
}
let timer: number
let timer: ReturnType<typeof setTimeout> | undefined
this.el.addEventListener("mouseenter", () => {
timer = setTimeout(() => toggle(true), this.model.tooltip_delay)
})
Expand Down
3 changes: 1 addition & 2 deletions panel/models/html.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export function run_scripts(node: Element): void {
}

function throttle(func: Function, limit: number): any {
let lastFunc: number
let lastFunc: ReturnType<typeof setTimeout> | undefined
let lastRan: number

return function(...args: any) {
Expand All @@ -85,7 +85,6 @@ function throttle(func: Function, limit: number): any {
lastRan = Date.now()
} else {
clearTimeout(lastFunc)

lastFunc = setTimeout(function() {
if ((Date.now() - lastRan) >= limit) {
func.apply(context, args)
Expand Down
2 changes: 1 addition & 1 deletion panel/models/icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class ClickableIconView extends ControlView {
visible,
})
}
let timer: number
let timer: ReturnType<typeof setTimeout> | undefined
this.el.addEventListener("mouseenter", () => {
timer = setTimeout(() => toggle_tooltip(true), this.model.tooltip_delay)
})
Expand Down
2 changes: 1 addition & 1 deletion panel/models/radio_button_group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ export class RadioButtonGroupView extends bkRadioButtonGroupView {
visible,
})
}
let timer: number
let timer: ReturnType<typeof setTimeout> | undefined
this.el.addEventListener("mouseenter", () => {
timer = setTimeout(() => toggle(true), this.model.tooltip_delay)
})
Expand Down
26 changes: 14 additions & 12 deletions panel/models/tabulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,6 @@ export class DataTabulatorView extends HTMLBoxView {
_debounced_redraw: any = null
_restore_scroll: boolean | "horizontal" | "vertical" = false
_updating_scroll: boolean = false
_scroll_timeout: number | null = null
_is_scrolling: boolean = false

override connect_signals(): void {
Expand Down Expand Up @@ -595,17 +594,7 @@ export class DataTabulatorView extends HTMLBoxView {
return `${cell.getColumn().getField()}: ${cell.getValue()}`
})
this.tabulator.on("scrollVertical", debounce(() => {
if (isNumber(this._scroll_timeout)) {
clearTimeout(this._scroll_timeout)
}
this.record_scroll()
this.setStyles()
this._scroll_timeout = setTimeout(() => {
this._is_scrolling = true
}, 100)
}, 50, false))
this.tabulator.on("scrollHorizontal", debounce(() => {
this.record_scroll()
}, 50, false))

// Sync state with model
Expand Down Expand Up @@ -659,10 +648,23 @@ export class DataTabulatorView extends HTMLBoxView {
this.renderChildren()
this.setStyles()

// Track scrolling position and active scroll
const holder = this.shadow_el.querySelector(".tabulator-tableholder")
let scroll_timeout: ReturnType<typeof setTimeout> | undefined
if (holder) {
holder.addEventListener('scroll', () => {
this.record_scroll()
this._is_scrolling = true
clearTimeout(scroll_timeout)
scroll_timeout = setTimeout(() => {
this._is_scrolling = false
}, 200)
})
}

if (this.model.pagination) {
if (this.model.page_size == null) {
const table = this.shadow_el.querySelector(".tabulator-table")
const holder = this.shadow_el.querySelector(".tabulator-tableholder")
if (table != null && holder != null) {
const table_height = holder.clientHeight
let height = 0
Expand Down

0 comments on commit 6fd7899

Please sign in to comment.