dockview-core 4.13.0 → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +56 -8
- package/dist/cjs/api/dockviewGroupPanelApi.d.ts +5 -0
- package/dist/cjs/api/dockviewGroupPanelApi.js +13 -1
- package/dist/cjs/api/dockviewPanelApi.js +1 -1
- package/dist/cjs/constants.js +6 -1
- package/dist/cjs/dnd/abstractDragHandler.js +3 -1
- package/dist/cjs/dnd/droptarget.js +2 -2
- package/dist/cjs/dockview/components/popupService.js +2 -0
- package/dist/cjs/dockview/components/titlebar/tabs.d.ts +5 -0
- package/dist/cjs/dockview/components/titlebar/tabs.js +31 -4
- package/dist/cjs/dockview/components/titlebar/tabsContainer.d.ts +5 -0
- package/dist/cjs/dockview/components/titlebar/tabsContainer.js +21 -0
- package/dist/cjs/dockview/deserializer.js +1 -1
- package/dist/cjs/dockview/dockviewComponent.d.ts +4 -1
- package/dist/cjs/dockview/dockviewComponent.js +93 -58
- package/dist/cjs/dockview/dockviewGroupPanel.js +16 -13
- package/dist/cjs/dockview/dockviewGroupPanelModel.d.ts +11 -1
- package/dist/cjs/dockview/dockviewGroupPanelModel.js +62 -5
- package/dist/cjs/dockview/framework.d.ts +2 -0
- package/dist/cjs/dockview/options.d.ts +3 -0
- package/dist/cjs/dockview/options.js +1 -0
- package/dist/cjs/dom.js +9 -1
- package/dist/cjs/framwork.d.ts +1 -1
- package/dist/cjs/lifecycle.d.ts +2 -1
- package/dist/cjs/lifecycle.js +6 -3
- package/dist/cjs/overlay/overlay.js +2 -1
- package/dist/cjs/scrollbar.d.ts +5 -2
- package/dist/cjs/scrollbar.js +88 -26
- package/dist/dockview-core.js +284 -77
- package/dist/dockview-core.min.js +2 -2
- package/dist/dockview-core.min.js.map +1 -1
- package/dist/dockview-core.min.noStyle.js +2 -2
- package/dist/dockview-core.min.noStyle.js.map +1 -1
- package/dist/dockview-core.noStyle.js +283 -76
- package/dist/esm/api/dockviewGroupPanelApi.d.ts +5 -0
- package/dist/esm/api/dockviewGroupPanelApi.js +14 -2
- package/dist/esm/api/dockviewPanelApi.js +1 -1
- package/dist/esm/constants.js +6 -1
- package/dist/esm/dnd/abstractDragHandler.js +3 -1
- package/dist/esm/dnd/droptarget.js +2 -2
- package/dist/esm/dockview/components/popupService.js +2 -0
- package/dist/esm/dockview/components/titlebar/tabs.d.ts +5 -0
- package/dist/esm/dockview/components/titlebar/tabs.js +28 -5
- package/dist/esm/dockview/components/titlebar/tabsContainer.d.ts +5 -0
- package/dist/esm/dockview/components/titlebar/tabsContainer.js +18 -1
- package/dist/esm/dockview/deserializer.js +1 -1
- package/dist/esm/dockview/dockviewComponent.d.ts +4 -1
- package/dist/esm/dockview/dockviewComponent.js +34 -14
- package/dist/esm/dockview/dockviewGroupPanel.js +17 -14
- package/dist/esm/dockview/dockviewGroupPanelModel.d.ts +11 -1
- package/dist/esm/dockview/dockviewGroupPanelModel.js +61 -8
- package/dist/esm/dockview/framework.d.ts +2 -0
- package/dist/esm/dockview/options.d.ts +3 -0
- package/dist/esm/dockview/options.js +1 -0
- package/dist/esm/dom.js +9 -1
- package/dist/esm/framwork.d.ts +1 -1
- package/dist/esm/lifecycle.d.ts +2 -1
- package/dist/esm/lifecycle.js +6 -3
- package/dist/esm/overlay/overlay.js +2 -1
- package/dist/esm/scrollbar.d.ts +5 -2
- package/dist/esm/scrollbar.js +85 -27
- package/dist/{dockview-core.cjs.js → package/main.cjs.js} +284 -77
- package/dist/package/main.cjs.min.js +7 -0
- package/dist/package/main.esm.min.mjs +7 -0
- package/dist/{dockview-core.esm.js → package/main.esm.mjs} +284 -77
- package/dist/styles/dockview.css +63 -7
- package/package.json +63 -53
- package/dist/dockview-core.amd.js +0 -11365
- package/dist/dockview-core.amd.js.map +0 -1
- package/dist/dockview-core.amd.min.js +0 -8
- package/dist/dockview-core.amd.min.js.map +0 -1
- package/dist/dockview-core.amd.min.noStyle.js +0 -8
- package/dist/dockview-core.amd.min.noStyle.js.map +0 -1
- package/dist/dockview-core.amd.noStyle.js +0 -11335
- package/dist/dockview-core.amd.noStyle.js.map +0 -1
- package/dist/dockview-core.cjs.js.map +0 -1
- package/dist/dockview-core.esm.js.map +0 -1
- package/dist/dockview-core.esm.min.js +0 -8
- package/dist/dockview-core.esm.min.js.map +0 -1
- package/dist/dockview-core.js.map +0 -1
- package/dist/dockview-core.noStyle.js.map +0 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { DockviewApi } from '../api/component.api';
|
|
2
2
|
import { getPanelData } from '../dnd/dataTransfer';
|
|
3
|
-
import { isAncestor, toggleClass } from '../dom';
|
|
3
|
+
import { addClasses, isAncestor, removeClasses, toggleClass } from '../dom';
|
|
4
4
|
import { addDisposableListener, DockviewEvent, Emitter, } from '../events';
|
|
5
|
-
import { DockviewWillShowOverlayLocationEvent } from './events';
|
|
6
|
-
import { CompositeDisposable } from '../lifecycle';
|
|
5
|
+
import { DockviewWillShowOverlayLocationEvent, } from './events';
|
|
6
|
+
import { CompositeDisposable, MutableDisposable, } from '../lifecycle';
|
|
7
7
|
import { ContentContainer, } from './components/panel/content';
|
|
8
8
|
import { TabsContainer, } from './components/titlebar/tabsContainer';
|
|
9
9
|
import { DockviewUnhandledDragOverEvent, } from './options';
|
|
@@ -78,6 +78,29 @@ export class DockviewGroupPanelModel extends CompositeDisposable {
|
|
|
78
78
|
}
|
|
79
79
|
return isAncestor(document.activeElement, this.contentContainer.element);
|
|
80
80
|
}
|
|
81
|
+
get headerPosition() {
|
|
82
|
+
var _a;
|
|
83
|
+
return (_a = this._headerPosition) !== null && _a !== void 0 ? _a : 'top';
|
|
84
|
+
}
|
|
85
|
+
set headerPosition(value) {
|
|
86
|
+
var _a;
|
|
87
|
+
this._headerPosition = value;
|
|
88
|
+
removeClasses(this.container, 'dv-groupview-header-top', 'dv-groupview-header-bottom', 'dv-groupview-header-left', 'dv-groupview-header-right');
|
|
89
|
+
addClasses(this.container, `dv-groupview-header-${value}`);
|
|
90
|
+
const direction = value === 'top' || value === 'bottom' ? 'horizontal' : 'vertical';
|
|
91
|
+
this.tabsContainer.direction = direction;
|
|
92
|
+
this.header.direction = direction;
|
|
93
|
+
// resize the active panel to fit the new header direction
|
|
94
|
+
// if not, the panel will overflow the tabs container
|
|
95
|
+
if ((_a = this._activePanel) === null || _a === void 0 ? void 0 : _a.layout) {
|
|
96
|
+
this._activePanel.layout(this._width, this._height);
|
|
97
|
+
}
|
|
98
|
+
if (this._leftHeaderActions ||
|
|
99
|
+
this._rightHeaderActions ||
|
|
100
|
+
this._prefixHeaderActions) {
|
|
101
|
+
this.updateHeaderActions();
|
|
102
|
+
}
|
|
103
|
+
}
|
|
81
104
|
get location() {
|
|
82
105
|
return this._location;
|
|
83
106
|
}
|
|
@@ -112,7 +135,7 @@ export class DockviewGroupPanelModel extends CompositeDisposable {
|
|
|
112
135
|
});
|
|
113
136
|
}
|
|
114
137
|
constructor(container, accessor, id, options, groupPanel) {
|
|
115
|
-
var _a;
|
|
138
|
+
var _a, _b;
|
|
116
139
|
super();
|
|
117
140
|
this.container = container;
|
|
118
141
|
this.accessor = accessor;
|
|
@@ -121,6 +144,9 @@ export class DockviewGroupPanelModel extends CompositeDisposable {
|
|
|
121
144
|
this.groupPanel = groupPanel;
|
|
122
145
|
this._isGroupActive = false;
|
|
123
146
|
this._locked = false;
|
|
147
|
+
this._rightHeaderActionsDisposable = new MutableDisposable();
|
|
148
|
+
this._leftHeaderActionsDisposable = new MutableDisposable();
|
|
149
|
+
this._prefixHeaderActionsDisposable = new MutableDisposable();
|
|
124
150
|
this._location = { type: 'grid' };
|
|
125
151
|
this.mostRecentlyUsed = [];
|
|
126
152
|
this._overwriteRenderContainer = null;
|
|
@@ -162,7 +188,9 @@ export class DockviewGroupPanelModel extends CompositeDisposable {
|
|
|
162
188
|
container.append(this.tabsContainer.element, this.contentContainer.element);
|
|
163
189
|
this.header.hidden = !!options.hideHeader;
|
|
164
190
|
this.locked = (_a = options.locked) !== null && _a !== void 0 ? _a : false;
|
|
165
|
-
this.
|
|
191
|
+
this.headerPosition =
|
|
192
|
+
(_b = options.headerPosition) !== null && _b !== void 0 ? _b : accessor.defaultHeaderPosition;
|
|
193
|
+
this.addDisposables(this._onTabDragStart, this._onGroupDragStart, this._onWillShowOverlay, this._rightHeaderActionsDisposable, this._leftHeaderActionsDisposable, this._prefixHeaderActionsDisposable, this.tabsContainer.onTabDragStart((event) => {
|
|
166
194
|
this._onTabDragStart.fire(event);
|
|
167
195
|
}), this.tabsContainer.onGroupDragStart((event) => {
|
|
168
196
|
this._onGroupDragStart.fire(event);
|
|
@@ -222,10 +250,13 @@ export class DockviewGroupPanelModel extends CompositeDisposable {
|
|
|
222
250
|
// correctly initialized
|
|
223
251
|
this.setActive(this.isActive, true);
|
|
224
252
|
this.updateContainer();
|
|
253
|
+
this.updateHeaderActions();
|
|
254
|
+
}
|
|
255
|
+
updateHeaderActions() {
|
|
225
256
|
if (this.accessor.options.createRightHeaderActionComponent) {
|
|
226
257
|
this._rightHeaderActions =
|
|
227
258
|
this.accessor.options.createRightHeaderActionComponent(this.groupPanel);
|
|
228
|
-
this.
|
|
259
|
+
this._rightHeaderActionsDisposable.value = this._rightHeaderActions;
|
|
229
260
|
this._rightHeaderActions.init({
|
|
230
261
|
containerApi: this._api,
|
|
231
262
|
api: this.groupPanel.api,
|
|
@@ -233,10 +264,15 @@ export class DockviewGroupPanelModel extends CompositeDisposable {
|
|
|
233
264
|
});
|
|
234
265
|
this.tabsContainer.setRightActionsElement(this._rightHeaderActions.element);
|
|
235
266
|
}
|
|
267
|
+
else {
|
|
268
|
+
this._rightHeaderActions = undefined;
|
|
269
|
+
this._rightHeaderActionsDisposable.dispose();
|
|
270
|
+
this.tabsContainer.setRightActionsElement(undefined);
|
|
271
|
+
}
|
|
236
272
|
if (this.accessor.options.createLeftHeaderActionComponent) {
|
|
237
273
|
this._leftHeaderActions =
|
|
238
274
|
this.accessor.options.createLeftHeaderActionComponent(this.groupPanel);
|
|
239
|
-
this.
|
|
275
|
+
this._leftHeaderActionsDisposable.value = this._leftHeaderActions;
|
|
240
276
|
this._leftHeaderActions.init({
|
|
241
277
|
containerApi: this._api,
|
|
242
278
|
api: this.groupPanel.api,
|
|
@@ -244,10 +280,16 @@ export class DockviewGroupPanelModel extends CompositeDisposable {
|
|
|
244
280
|
});
|
|
245
281
|
this.tabsContainer.setLeftActionsElement(this._leftHeaderActions.element);
|
|
246
282
|
}
|
|
283
|
+
else {
|
|
284
|
+
this._leftHeaderActions = undefined;
|
|
285
|
+
this._leftHeaderActionsDisposable.dispose();
|
|
286
|
+
this.tabsContainer.setLeftActionsElement(undefined);
|
|
287
|
+
}
|
|
247
288
|
if (this.accessor.options.createPrefixHeaderActionComponent) {
|
|
248
289
|
this._prefixHeaderActions =
|
|
249
290
|
this.accessor.options.createPrefixHeaderActionComponent(this.groupPanel);
|
|
250
|
-
this.
|
|
291
|
+
this._prefixHeaderActionsDisposable.value =
|
|
292
|
+
this._prefixHeaderActions;
|
|
251
293
|
this._prefixHeaderActions.init({
|
|
252
294
|
containerApi: this._api,
|
|
253
295
|
api: this.groupPanel.api,
|
|
@@ -255,6 +297,11 @@ export class DockviewGroupPanelModel extends CompositeDisposable {
|
|
|
255
297
|
});
|
|
256
298
|
this.tabsContainer.setPrefixActionsElement(this._prefixHeaderActions.element);
|
|
257
299
|
}
|
|
300
|
+
else {
|
|
301
|
+
this._prefixHeaderActions = undefined;
|
|
302
|
+
this._prefixHeaderActionsDisposable.dispose();
|
|
303
|
+
this.tabsContainer.setPrefixActionsElement(undefined);
|
|
304
|
+
}
|
|
258
305
|
}
|
|
259
306
|
rerender(panel) {
|
|
260
307
|
this.contentContainer.renderPanel(panel, { asActive: false });
|
|
@@ -275,6 +322,9 @@ export class DockviewGroupPanelModel extends CompositeDisposable {
|
|
|
275
322
|
if (this.header.hidden) {
|
|
276
323
|
result.hideHeader = true;
|
|
277
324
|
}
|
|
325
|
+
if (this.headerPosition !== 'top') {
|
|
326
|
+
result.headerPosition = this.headerPosition;
|
|
327
|
+
}
|
|
278
328
|
return result;
|
|
279
329
|
}
|
|
280
330
|
moveToNext(options) {
|
|
@@ -472,6 +522,9 @@ export class DockviewGroupPanelModel extends CompositeDisposable {
|
|
|
472
522
|
if (!options.skipSetActive) {
|
|
473
523
|
this.contentContainer.openPanel(panel);
|
|
474
524
|
}
|
|
525
|
+
else if (panel.api.renderer === 'always') {
|
|
526
|
+
this.contentContainer.renderPanel(panel, { asActive: false });
|
|
527
|
+
}
|
|
475
528
|
if (hasExistingPanel) {
|
|
476
529
|
// TODO - need to ensure ordering hasn't changed and if it has need to re-order this.panels
|
|
477
530
|
return;
|
|
@@ -4,6 +4,7 @@ import { DockviewPanelApi } from '../api/dockviewPanelApi';
|
|
|
4
4
|
import { PanelParameters } from '../framwork';
|
|
5
5
|
import { DockviewGroupPanel, IDockviewGroupPanel } from './dockviewGroupPanel';
|
|
6
6
|
import { IDockviewPanel } from './dockviewPanel';
|
|
7
|
+
import { DockviewHeaderPosition } from './options';
|
|
7
8
|
export interface IGroupPanelBaseProps<T extends {
|
|
8
9
|
[index: string]: any;
|
|
9
10
|
} = any> extends PanelParameters<T> {
|
|
@@ -26,6 +27,7 @@ export interface IDockviewHeaderActionsProps {
|
|
|
26
27
|
activePanel: IDockviewPanel | undefined;
|
|
27
28
|
isGroupActive: boolean;
|
|
28
29
|
group: DockviewGroupPanel;
|
|
30
|
+
headerPosition: DockviewHeaderPosition;
|
|
29
31
|
}
|
|
30
32
|
export interface IGroupHeaderProps {
|
|
31
33
|
api: DockviewGroupPanelApi;
|
|
@@ -29,6 +29,8 @@ export interface ViewFactoryData {
|
|
|
29
29
|
content: string;
|
|
30
30
|
tab?: string;
|
|
31
31
|
}
|
|
32
|
+
export type DockviewHeaderPosition = 'top' | 'bottom' | 'left' | 'right';
|
|
33
|
+
export type DockviewHeaderDirection = 'horizontal' | 'vertical';
|
|
32
34
|
export interface DockviewOptions {
|
|
33
35
|
/**
|
|
34
36
|
* Disable the auto-resizing which is controlled through a `ResizeObserver`.
|
|
@@ -44,6 +46,7 @@ export interface DockviewOptions {
|
|
|
44
46
|
};
|
|
45
47
|
popoutUrl?: string;
|
|
46
48
|
defaultRenderer?: DockviewPanelRenderer;
|
|
49
|
+
defaultHeaderPosition?: DockviewHeaderPosition;
|
|
47
50
|
debug?: boolean;
|
|
48
51
|
dndEdges?: false | DroptargetOverlayModel;
|
|
49
52
|
/**
|
package/dist/esm/dom.js
CHANGED
|
@@ -267,9 +267,9 @@ export class Classnames {
|
|
|
267
267
|
}
|
|
268
268
|
const DEBOUCE_DELAY = 100;
|
|
269
269
|
export function isChildEntirelyVisibleWithinParent(child, parent) {
|
|
270
|
-
//
|
|
271
270
|
const childPosition = getDomNodePagePosition(child);
|
|
272
271
|
const parentPosition = getDomNodePagePosition(parent);
|
|
272
|
+
// Check horizontal visibility
|
|
273
273
|
if (childPosition.left < parentPosition.left) {
|
|
274
274
|
return false;
|
|
275
275
|
}
|
|
@@ -277,6 +277,14 @@ export function isChildEntirelyVisibleWithinParent(child, parent) {
|
|
|
277
277
|
parentPosition.left + parentPosition.width) {
|
|
278
278
|
return false;
|
|
279
279
|
}
|
|
280
|
+
// Check vertical visibility
|
|
281
|
+
if (childPosition.top < parentPosition.top) {
|
|
282
|
+
return false;
|
|
283
|
+
}
|
|
284
|
+
if (childPosition.top + childPosition.height >
|
|
285
|
+
parentPosition.top + parentPosition.height) {
|
|
286
|
+
return false;
|
|
287
|
+
}
|
|
280
288
|
return true;
|
|
281
289
|
}
|
|
282
290
|
export function onDidWindowMoveEnd(window) {
|
package/dist/esm/framwork.d.ts
CHANGED
package/dist/esm/lifecycle.d.ts
CHANGED
|
@@ -10,11 +10,12 @@ export declare namespace Disposable {
|
|
|
10
10
|
function from(func: () => void): IDisposable;
|
|
11
11
|
}
|
|
12
12
|
export declare class CompositeDisposable {
|
|
13
|
-
private _disposables;
|
|
13
|
+
private readonly _disposables;
|
|
14
14
|
private _isDisposed;
|
|
15
15
|
get isDisposed(): boolean;
|
|
16
16
|
constructor(...args: IDisposable[]);
|
|
17
17
|
addDisposables(...args: IDisposable[]): void;
|
|
18
|
+
removeDisposable(disposable: IDisposable): void;
|
|
18
19
|
dispose(): void;
|
|
19
20
|
}
|
|
20
21
|
export declare class MutableDisposable implements IDisposable {
|
package/dist/esm/lifecycle.js
CHANGED
|
@@ -20,10 +20,13 @@ export class CompositeDisposable {
|
|
|
20
20
|
}
|
|
21
21
|
constructor(...args) {
|
|
22
22
|
this._isDisposed = false;
|
|
23
|
-
this._disposables = args;
|
|
23
|
+
this._disposables = new Set(args);
|
|
24
24
|
}
|
|
25
25
|
addDisposables(...args) {
|
|
26
|
-
args.forEach((arg) => this._disposables.
|
|
26
|
+
args.forEach((arg) => this._disposables.add(arg));
|
|
27
|
+
}
|
|
28
|
+
removeDisposable(disposable) {
|
|
29
|
+
this._disposables.delete(disposable);
|
|
27
30
|
}
|
|
28
31
|
dispose() {
|
|
29
32
|
if (this._isDisposed) {
|
|
@@ -31,7 +34,7 @@ export class CompositeDisposable {
|
|
|
31
34
|
}
|
|
32
35
|
this._isDisposed = true;
|
|
33
36
|
this._disposables.forEach((arg) => arg.dispose());
|
|
34
|
-
this._disposables
|
|
37
|
+
this._disposables.clear();
|
|
35
38
|
}
|
|
36
39
|
}
|
|
37
40
|
export class MutableDisposable {
|
|
@@ -20,7 +20,8 @@ class AriaLevelTracker {
|
|
|
20
20
|
update() {
|
|
21
21
|
for (let i = 0; i < this._orderedList.length; i++) {
|
|
22
22
|
this._orderedList[i].setAttribute('aria-level', `${i}`);
|
|
23
|
-
this._orderedList[i].style.zIndex =
|
|
23
|
+
this._orderedList[i].style.zIndex =
|
|
24
|
+
`calc(var(--dv-overlay-z-index, 999) + ${i * 2})`;
|
|
24
25
|
}
|
|
25
26
|
}
|
|
26
27
|
}
|
package/dist/esm/scrollbar.d.ts
CHANGED
|
@@ -2,11 +2,14 @@ import { CompositeDisposable } from './lifecycle';
|
|
|
2
2
|
export declare class Scrollbar extends CompositeDisposable {
|
|
3
3
|
private readonly scrollableElement;
|
|
4
4
|
private readonly _element;
|
|
5
|
-
private readonly
|
|
6
|
-
private
|
|
5
|
+
private readonly _scrollbar;
|
|
6
|
+
private _scrollOffset;
|
|
7
7
|
private _animationTimer;
|
|
8
|
+
private _orientation;
|
|
8
9
|
static MouseWheelSpeed: number;
|
|
9
10
|
get element(): HTMLElement;
|
|
11
|
+
get orientation(): 'horizontal' | 'vertical';
|
|
12
|
+
set orientation(value: 'horizontal' | 'vertical');
|
|
10
13
|
constructor(scrollableElement: HTMLElement);
|
|
11
14
|
private calculateScrollbarStyles;
|
|
12
15
|
}
|
package/dist/esm/scrollbar.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { toggleClass, watchElementResize } from './dom';
|
|
1
|
+
import { addClasses, removeClasses, toggleClass, watchElementResize, } from './dom';
|
|
2
2
|
import { addDisposableListener } from './events';
|
|
3
3
|
import { CompositeDisposable } from './lifecycle';
|
|
4
4
|
import { clamp } from './math';
|
|
@@ -6,30 +6,56 @@ export class Scrollbar extends CompositeDisposable {
|
|
|
6
6
|
get element() {
|
|
7
7
|
return this._element;
|
|
8
8
|
}
|
|
9
|
+
get orientation() {
|
|
10
|
+
return this._orientation;
|
|
11
|
+
}
|
|
12
|
+
set orientation(value) {
|
|
13
|
+
if (this._orientation === value) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
this._scrollOffset = 0;
|
|
17
|
+
this._orientation = value;
|
|
18
|
+
removeClasses(this._scrollbar, 'dv-scrollbar-vertical', 'dv-scrollbar-horizontal');
|
|
19
|
+
if (value === 'vertical') {
|
|
20
|
+
addClasses(this._scrollbar, 'dv-scrollbar-vertical');
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
addClasses(this._scrollbar, 'dv-scrollbar-horizontal');
|
|
24
|
+
}
|
|
25
|
+
}
|
|
9
26
|
constructor(scrollableElement) {
|
|
10
27
|
super();
|
|
11
28
|
this.scrollableElement = scrollableElement;
|
|
12
|
-
this.
|
|
29
|
+
this._scrollOffset = 0;
|
|
30
|
+
this._orientation = 'horizontal';
|
|
13
31
|
this._element = document.createElement('div');
|
|
14
32
|
this._element.className = 'dv-scrollable';
|
|
15
|
-
this.
|
|
16
|
-
this.
|
|
33
|
+
this._scrollbar = document.createElement('div');
|
|
34
|
+
this._scrollbar.className = 'dv-scrollbar dv-scrollbar-horizontal';
|
|
17
35
|
this.element.appendChild(scrollableElement);
|
|
18
|
-
this.element.appendChild(this.
|
|
36
|
+
this.element.appendChild(this._scrollbar);
|
|
19
37
|
this.addDisposables(addDisposableListener(this.element, 'wheel', (event) => {
|
|
20
|
-
this.
|
|
38
|
+
this._scrollOffset += event.deltaY * Scrollbar.MouseWheelSpeed;
|
|
21
39
|
this.calculateScrollbarStyles();
|
|
22
|
-
}), addDisposableListener(this.
|
|
40
|
+
}), addDisposableListener(this._scrollbar, 'pointerdown', (event) => {
|
|
23
41
|
event.preventDefault();
|
|
24
42
|
toggleClass(this.element, 'dv-scrollable-scrolling', true);
|
|
25
|
-
const
|
|
26
|
-
|
|
43
|
+
const originalClient = this._orientation === 'horizontal'
|
|
44
|
+
? event.clientX
|
|
45
|
+
: event.clientY;
|
|
46
|
+
const originalScrollOffset = this._scrollOffset;
|
|
27
47
|
const onPointerMove = (event) => {
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
|
|
48
|
+
const delta = this._orientation === 'horizontal'
|
|
49
|
+
? event.clientX - originalClient
|
|
50
|
+
: event.clientY - originalClient;
|
|
51
|
+
const clientSize = this._orientation === 'horizontal'
|
|
52
|
+
? this.element.clientWidth
|
|
53
|
+
: this.element.clientHeight;
|
|
54
|
+
const scrollSize = this._orientation === 'horizontal'
|
|
55
|
+
? this.scrollableElement.scrollWidth
|
|
56
|
+
: this.scrollableElement.scrollHeight;
|
|
57
|
+
const p = clientSize / scrollSize;
|
|
58
|
+
this._scrollOffset = originalScrollOffset + delta / p;
|
|
33
59
|
this.calculateScrollbarStyles();
|
|
34
60
|
};
|
|
35
61
|
const onEnd = () => {
|
|
@@ -44,7 +70,10 @@ export class Scrollbar extends CompositeDisposable {
|
|
|
44
70
|
}), addDisposableListener(this.element, 'scroll', () => {
|
|
45
71
|
this.calculateScrollbarStyles();
|
|
46
72
|
}), addDisposableListener(this.scrollableElement, 'scroll', () => {
|
|
47
|
-
this.
|
|
73
|
+
this._scrollOffset =
|
|
74
|
+
this._orientation === 'horizontal'
|
|
75
|
+
? this.scrollableElement.scrollLeft
|
|
76
|
+
: this.scrollableElement.scrollTop;
|
|
48
77
|
this.calculateScrollbarStyles();
|
|
49
78
|
}), watchElementResize(this.element, () => {
|
|
50
79
|
toggleClass(this.element, 'dv-scrollable-resizing', true);
|
|
@@ -59,21 +88,50 @@ export class Scrollbar extends CompositeDisposable {
|
|
|
59
88
|
}));
|
|
60
89
|
}
|
|
61
90
|
calculateScrollbarStyles() {
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
91
|
+
const clientSize = this._orientation === 'horizontal'
|
|
92
|
+
? this.element.clientWidth
|
|
93
|
+
: this.element.clientHeight;
|
|
94
|
+
const scrollSize = this._orientation === 'horizontal'
|
|
95
|
+
? this.scrollableElement.scrollWidth
|
|
96
|
+
: this.scrollableElement.scrollHeight;
|
|
97
|
+
const hasScrollbar = scrollSize > clientSize;
|
|
65
98
|
if (hasScrollbar) {
|
|
66
|
-
const px =
|
|
67
|
-
this.
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
99
|
+
const px = clientSize * (clientSize / scrollSize);
|
|
100
|
+
if (this._orientation === 'horizontal') {
|
|
101
|
+
this._scrollbar.style.width = `${px}px`;
|
|
102
|
+
this._scrollbar.style.height = '';
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
this._scrollbar.style.height = `${px}px`;
|
|
106
|
+
this._scrollbar.style.width = '';
|
|
107
|
+
}
|
|
108
|
+
this._scrollOffset = clamp(this._scrollOffset, 0, scrollSize - clientSize);
|
|
109
|
+
if (this._orientation === 'horizontal') {
|
|
110
|
+
this.scrollableElement.scrollLeft = this._scrollOffset;
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
this.scrollableElement.scrollTop = this._scrollOffset;
|
|
114
|
+
}
|
|
115
|
+
const percentageComplete = this._scrollOffset / (scrollSize - clientSize);
|
|
116
|
+
if (this._orientation === 'horizontal') {
|
|
117
|
+
this._scrollbar.style.left = `${(clientSize - px) * percentageComplete}px`;
|
|
118
|
+
this._scrollbar.style.top = '';
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
this._scrollbar.style.top = `${(clientSize - px) * percentageComplete}px`;
|
|
122
|
+
this._scrollbar.style.left = '';
|
|
123
|
+
}
|
|
72
124
|
}
|
|
73
125
|
else {
|
|
74
|
-
this.
|
|
75
|
-
|
|
76
|
-
|
|
126
|
+
if (this._orientation === 'horizontal') {
|
|
127
|
+
this._scrollbar.style.width = '0px';
|
|
128
|
+
this._scrollbar.style.left = '0px';
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
this._scrollbar.style.height = '0px';
|
|
132
|
+
this._scrollbar.style.top = '0px';
|
|
133
|
+
}
|
|
134
|
+
this._scrollOffset = 0;
|
|
77
135
|
}
|
|
78
136
|
}
|
|
79
137
|
}
|