Skip to content

Commit e54b82f

Browse files
committed
Horizontal slider updates
1 parent 2588eaf commit e54b82f

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

packages/app/src/components/workbench.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export class DevtoolsWorkbench extends Element {
4444
#dragVertical = new DragController(this, {
4545
localStorageKey: 'toolbarHeight',
4646
minPosition: MIN_WORKBENCH_HEIGHT,
47+
maxPosition: (window.innerHeight * 0.7),
4748
initialPosition: window.innerHeight * .7, // initial height of browser window is 70% of window
4849
getContainerEl: () => this.getShadowRootAsync() as any as Element,
4950
direction: Direction.vertical
@@ -91,14 +92,13 @@ export class DevtoolsWorkbench extends Element {
9192
// When collapsed keep previous full behavior; when expanded no fixed height class
9293
const heightWorkbench = this.#toolbarCollapsed ? 'h-full flex-1' : ''
9394

94-
// Convert the drag position (e.g. "top: 334px") into a concrete height
9595
const styleWorkbench = this.#toolbarCollapsed ? '' : (() => {
9696
const HANDLE_HEIGHT = 10
9797
const m = this.#dragVertical.getPosition().match(/(\d+(?:\.\d+)?)px/)
9898
const raw = m ? parseFloat(m[1]) : window.innerHeight * 0.7
99-
const paneHeight = raw + HANDLE_HEIGHT
100-
const capped = Math.min(paneHeight, window.innerHeight * 0.7)
101-
return `flex:0 0 auto; flex-basis:${capped}px; height:${capped}px; max-height:70vh; min-height:0;`
99+
const capped = Math.min(raw, window.innerHeight * 0.7)
100+
const paneHeight = Math.max(MIN_WORKBENCH_HEIGHT, capped - HANDLE_HEIGHT)
101+
return `flex:0 0 ${paneHeight}px; height:${paneHeight}px; max-height:calc(70vh - ${HANDLE_HEIGHT}px); min-height:0;`
102102
})()
103103

104104
const sidebarStyle = !this.#workbenchSidebarCollapsed
@@ -137,10 +137,10 @@ export class DevtoolsWorkbench extends Element {
137137
: nothing
138138
}
139139
</section>
140+
${!this.#workbenchSidebarCollapsed ? this.#dragHorizontal.getSlider() : nothing}
140141
<section class="basis-auto text-gray-500 flex items-center justify-center flex-grow">
141142
<wdio-devtools-browser></wdio-devtools-browser>
142143
</section>
143-
${!this.#workbenchSidebarCollapsed ? this.#dragHorizontal.getSlider() : nothing}
144144
</section>
145145
${!this.#toolbarCollapsed ? this.#dragVertical.getSlider() : nothing}
146146
<wdio-devtools-tabs cacheId="activeWorkbenchTab" class="border-t-[1px] border-t-panelBorder ${this.#toolbarCollapsed ? 'hidden' : ''} flex-1 min-h-0">

packages/app/src/utils/DragController.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ interface DragControllerOptions {
1919
direction: Direction
2020
localStorageKey?: string
2121
minPosition?: number
22+
maxPosition?: number
2223
getContainerEl: AsyncGetElFn
2324
}
2425

@@ -104,11 +105,15 @@ export class DragController implements ReactiveController {
104105
return this.#host.shadowRoot!.querySelector(`button[data-draggable-id="${this.#id}"]`)
105106
}
106107

107-
#setPosition(x: number, y: number) {
108+
#setPosition(x: number, y: number) { // <<< MODIFY to clamp max
108109
if (this.#options.direction === Direction.horizontal) {
109-
this.#x = Math.max(x, this.#options.minPosition || 0)
110-
} else if (this.#options.direction === Direction.vertical) {
111-
this.#y = Math.max(y, this.#options.minPosition || 0)
110+
let nx = Math.max(x, this.#options.minPosition || 0)
111+
if (this.#options.maxPosition !== undefined) nx = Math.min(nx, this.#options.maxPosition)
112+
this.#x = nx
113+
} else {
114+
let ny = Math.max(y, this.#options.minPosition || 0)
115+
if (this.#options.maxPosition !== undefined) ny = Math.min(ny, this.#options.maxPosition)
116+
this.#y = ny
112117
}
113118
}
114119

0 commit comments

Comments
 (0)