aboutsummaryrefslogtreecommitdiff
path: root/ext/js/dom/panel-element.js
diff options
context:
space:
mode:
authorDarius Jahandarie <djahandarie@gmail.com>2023-12-06 03:53:16 +0000
committerGitHub <noreply@github.com>2023-12-06 03:53:16 +0000
commitbd5bc1a5db29903bc098995cd9262c4576bf76af (patch)
treec9214189e0214480fcf6539ad1c6327aef6cbd1c /ext/js/dom/panel-element.js
parentfd6bba8a2a869eaf2b2c1fa49001f933fce3c618 (diff)
parent23e6fb76319c9ed7c9bcdc3efba39bc5dd38f288 (diff)
Merge pull request #339 from toasted-nutbread/type-annotations
Type annotations
Diffstat (limited to 'ext/js/dom/panel-element.js')
-rw-r--r--ext/js/dom/panel-element.js34
1 files changed, 34 insertions, 0 deletions
diff --git a/ext/js/dom/panel-element.js b/ext/js/dom/panel-element.js
index 9b056920..748c3a36 100644
--- a/ext/js/dom/panel-element.js
+++ b/ext/js/dom/panel-element.js
@@ -18,25 +18,45 @@
import {EventDispatcher} from '../core.js';
+/**
+ * @augments EventDispatcher<import('panel-element').EventType>
+ */
export class PanelElement extends EventDispatcher {
+ /**
+ * @param {import('panel-element').ConstructorDetails} details
+ */
constructor({node, closingAnimationDuration}) {
super();
+ /** @type {HTMLElement} */
this._node = node;
+ /** @type {number} */
this._closingAnimationDuration = closingAnimationDuration;
+ /** @type {string} */
this._hiddenAnimatingClass = 'hidden-animating';
+ /** @type {?MutationObserver} */
this._mutationObserver = null;
+ /** @type {boolean} */
this._visible = false;
+ /** @type {?import('core').Timeout} */
this._closeTimer = null;
}
+ /** @type {HTMLElement} */
get node() {
return this._node;
}
+ /**
+ * @returns {boolean}
+ */
isVisible() {
return !this._node.hidden;
}
+ /**
+ * @param {boolean} value
+ * @param {boolean} [animate]
+ */
setVisible(value, animate=true) {
value = !!value;
if (this.isVisible() === value) { return; }
@@ -63,6 +83,11 @@ export class PanelElement extends EventDispatcher {
}
}
+ /**
+ * @param {import('panel-element').EventType} eventName
+ * @param {(details: import('core').SafeAny) => void} callback
+ * @returns {void}
+ */
on(eventName, callback) {
if (eventName === 'visibilityChanged') {
if (this._mutationObserver === null) {
@@ -78,6 +103,11 @@ export class PanelElement extends EventDispatcher {
return super.on(eventName, callback);
}
+ /**
+ * @param {import('panel-element').EventType} eventName
+ * @param {(details: import('core').SafeAny) => void} callback
+ * @returns {boolean}
+ */
off(eventName, callback) {
const result = super.off(eventName, callback);
if (eventName === 'visibilityChanged' && !this.hasListeners(eventName)) {
@@ -91,6 +121,7 @@ export class PanelElement extends EventDispatcher {
// Private
+ /** */
_onMutation() {
const visible = this.isVisible();
if (this._visible === visible) { return; }
@@ -98,6 +129,9 @@ export class PanelElement extends EventDispatcher {
this.trigger('visibilityChanged', {visible});
}
+ /**
+ * @param {boolean} reopening
+ */
_completeClose(reopening) {
this._closeTimer = null;
this._node.classList.remove(this._hiddenAnimatingClass);