-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpane-container-element.js
44 lines (39 loc) · 1.11 KB
/
pane-container-element.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const { CompositeDisposable } = require('event-kit');
class PaneContainerElement extends HTMLElement {
createdCallback() {
this.subscriptions = new CompositeDisposable();
this.classList.add('panes');
}
initialize(model, { views }) {
this.model = model;
this.views = views;
if (this.views == null) {
throw new Error(
'Must pass a views parameter when initializing PaneContainerElements'
);
}
this.subscriptions.add(this.model.observeRoot(this.rootChanged.bind(this)));
return this;
}
rootChanged(root) {
const focusedElement = this.hasFocus() ? document.activeElement : null;
if (this.firstChild != null) {
this.firstChild.remove();
}
if (root != null) {
const view = this.views.getView(root);
this.appendChild(view);
if (focusedElement != null) {
focusedElement.focus();
}
}
}
hasFocus() {
return (
this === document.activeElement || this.contains(document.activeElement)
);
}
}
module.exports = document.registerElement('atom-pane-container', {
prototype: PaneContainerElement.prototype
});