Skip to content

Commit 4cc45f1

Browse files
authored
Fix resizing and mode switching in DockPanel (#411)
* Fix charset in examples * Fix resizing in Dockpanel * Clean up event types * Add empty DockLayout test and more UTF-8 * Add test for DockPanel#handles() that would have failed before this PR * Fix mode switching in `DockLayout` * Only use yield* when there is no predicate
1 parent 942ab86 commit 4cc45f1

File tree

9 files changed

+43
-33
lines changed

9 files changed

+43
-33
lines changed

examples/example-accordionpanel/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<!DOCTYPE html>
77
<html>
88
<head>
9+
<meta charset="UTF-8">
910
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
1011
<script type="text/javascript" src="build/bundle.example.js"></script>
1112
</head>

examples/example-datagrid/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<!DOCTYPE html>
77
<html>
88
<head>
9+
<meta charset="UTF-8">
910
<script type="text/javascript" src="build/bundle.example.js"></script>
1011
</head>
1112
<body>

examples/example-dockpanel-amd/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<html>
88

99
<head>
10+
<meta charset="UTF-8">
1011
<title>example-dockpanel-iife</title>
1112

1213
<link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">

examples/example-dockpanel-iife/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<html>
88

99
<head>
10+
<meta charset="UTF-8">
1011
<title>example-dockpanel-iife</title>
1112

1213
<link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">

examples/example-dockpanel/index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<!DOCTYPE html>
77
<html>
88
<head>
9+
<meta charset="UTF-8">
910
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
1011
<script type="text/javascript" src="build/bundle.example.js"></script>
1112
</head>

packages/widgets/src/docklayout.ts

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,8 @@ export class DockLayout extends Layout {
145145
* #### Notes
146146
* This iterator includes the generated tab bars.
147147
*/
148-
*[Symbol.iterator](): IterableIterator<Widget> {
149-
if (this._root) {
150-
yield* this._root.iterAllWidgets();
151-
}
148+
[Symbol.iterator](): IterableIterator<Widget> {
149+
return this._root ? this._root.iterAllWidgets() : Private.empty;
152150
}
153151

154152
/**
@@ -159,10 +157,8 @@ export class DockLayout extends Layout {
159157
* #### Notes
160158
* This iterator does not include the generated tab bars.
161159
*/
162-
*widgets(): IterableIterator<Widget> {
163-
if (this._root) {
164-
yield* this._root.iterUserWidgets();
165-
}
160+
widgets(): IterableIterator<Widget> {
161+
return this._root ? this._root.iterUserWidgets() : Private.empty;
166162
}
167163

168164
/**
@@ -174,10 +170,8 @@ export class DockLayout extends Layout {
174170
* This iterator yields the widgets corresponding to the current tab
175171
* of each tab bar in the layout.
176172
*/
177-
*selectedWidgets(): IterableIterator<Widget> {
178-
if (this._root) {
179-
yield* this._root.iterSelectedWidgets();
180-
}
173+
selectedWidgets(): IterableIterator<Widget> {
174+
return this._root ? this._root.iterSelectedWidgets() : Private.empty;
181175
}
182176

183177
/**
@@ -188,21 +182,17 @@ export class DockLayout extends Layout {
188182
* #### Notes
189183
* This iterator does not include the user widgets.
190184
*/
191-
*tabBars(): IterableIterator<TabBar<Widget>> {
192-
if (this._root) {
193-
yield* this._root.iterTabBars();
194-
}
185+
tabBars(): IterableIterator<TabBar<Widget>> {
186+
return this._root ? this._root.iterTabBars() : Private.empty;
195187
}
196188

197189
/**
198190
* Create an iterator over the handles in the layout.
199191
*
200192
* @returns A new iterator over the handles in the layout.
201193
*/
202-
*handles(): IterableIterator<HTMLDivElement> {
203-
if (this._root) {
204-
yield* this._root.iterHandles();
205-
}
194+
handles(): IterableIterator<HTMLDivElement> {
195+
return this._root ? this._root.iterHandles() : Private.empty;
206196
}
207197

208198
/**
@@ -1434,6 +1424,11 @@ export namespace DockLayout {
14341424
* The namespace for the module implementation details.
14351425
*/
14361426
namespace Private {
1427+
/**
1428+
* An empty iterator.
1429+
*/
1430+
export const empty = [][Symbol.iterator]();
1431+
14371432
/**
14381433
* A fraction used for sizing root panels; ~= `1 / golden_ratio`.
14391434
*/
@@ -1840,6 +1835,7 @@ namespace Private {
18401835
* Create an iterator for the handles in the layout tree.
18411836
*/
18421837
*iterHandles(): IterableIterator<HTMLDivElement> {
1838+
yield* this.handles;
18431839
for (const child of this.children) {
18441840
yield* child.iterHandles();
18451841
}

packages/widgets/src/dockpanel.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -446,13 +446,13 @@ export class DockPanel extends Widget {
446446
this._evtDrop(event as Drag.Event);
447447
break;
448448
case 'pointerdown':
449-
this._evtPointerDown(event as MouseEvent);
449+
this._evtPointerDown(event as PointerEvent);
450450
break;
451451
case 'pointermove':
452-
this._evtPointerMove(event as MouseEvent);
452+
this._evtPointerMove(event as PointerEvent);
453453
break;
454454
case 'pointerup':
455-
this._evtPointerUp(event as MouseEvent);
455+
this._evtPointerUp(event as PointerEvent);
456456
break;
457457
case 'keydown':
458458
this._evtKeyDown(event as KeyboardEvent);
@@ -685,7 +685,7 @@ export class DockPanel extends Widget {
685685
/**
686686
* Handle the `'pointerdown'` event for the dock panel.
687687
*/
688-
private _evtPointerDown(event: MouseEvent): void {
688+
private _evtPointerDown(event: PointerEvent): void {
689689
// Do nothing if the left mouse button is not pressed.
690690
if (event.button !== 0) {
691691
return;
@@ -723,7 +723,7 @@ export class DockPanel extends Widget {
723723
/**
724724
* Handle the `'pointermove'` event for the dock panel.
725725
*/
726-
private _evtPointerMove(event: MouseEvent): void {
726+
private _evtPointerMove(event: PointerEvent): void {
727727
// Bail early if no drag is in progress.
728728
if (!this._pressData) {
729729
return;
@@ -746,7 +746,7 @@ export class DockPanel extends Widget {
746746
/**
747747
* Handle the `'pointerup'` event for the dock panel.
748748
*/
749-
private _evtPointerUp(event: MouseEvent): void {
749+
private _evtPointerUp(event: PointerEvent): void {
750750
// Do nothing if the left mouse button is not released.
751751
if (event.button !== 0) {
752752
return;
Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
// Copyright (c) Jupyter Development Team.
22
// Distributed under the terms of the Modified BSD License.
3-
/*-----------------------------------------------------------------------------
4-
| Copyright (c) 2014-2017, PhosphorJS Contributors
5-
|
6-
| Distributed under the terms of the BSD 3-Clause License.
7-
|
8-
| The full license is in the file LICENSE, distributed with this software.
9-
|----------------------------------------------------------------------------*/
3+
4+
describe('@lumino/widgets', () => {
5+
describe('DockLayout', () => {
6+
it.skip('should have some tests');
7+
});
8+
});

packages/widgets/tests/src/dockpanel.spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,16 @@ describe('@lumino/widgets', () => {
5757
});
5858
});
5959

60+
describe('#handles()', () => {
61+
it('should return the handles within the dock panel', () => {
62+
let dock = new DockPanel();
63+
dock.addWidget(new Widget());
64+
dock.addWidget(new Widget(), { mode: 'split-bottom' });
65+
expect(Array.from(dock.handles())).to.have.lengthOf(2); // one is hidden
66+
dock.dispose();
67+
});
68+
});
69+
6070
describe('hiddenMode', () => {
6171
let panel: DockPanel;
6272
let widgets: Widget[] = [];

0 commit comments

Comments
 (0)