Skip to content

Commit

Permalink
fix(types): improves quality of typescript definitions (#8218)
Browse files Browse the repository at this point in the history
* feat(types): improves quality of typescript definitions

* fix: reverts back access modifier for controlText_

* empty commit to force retest

* fix(doc): add missing keyboard event type

---------

Co-authored-by: mister-ben <[email protected]>
  • Loading branch information
gjanblaszczyk and mister-ben authored Sep 27, 2023
1 parent 9267c46 commit 781eb43
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 11 deletions.
21 changes: 19 additions & 2 deletions src/js/big-play-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class BigPlayButton extends Button {
* This gets called when a `BigPlayButton` "clicked". See {@link ClickableComponent}
* for more detailed information on what a click can be.
*
* @param {KeyboardEvent} event
* @param {KeyboardEvent|MouseEvent|TouchEvent} event
* The `keydown`, `tap`, or `click` event that caused this function to be
* called.
*
Expand All @@ -47,7 +47,7 @@ class BigPlayButton extends Button {
const playPromise = this.player_.play();

// exit early if clicked via the mouse
if (this.mouseused_ && event.clientX && event.clientY) {
if (this.mouseused_ && 'clientX' in event && 'clientY' in event) {
silencePromise(playPromise);

if (this.player_.tech(true)) {
Expand All @@ -74,12 +74,29 @@ class BigPlayButton extends Button {
}
}

/**
* Event handler that is called when a `BigPlayButton` receives a
* `keydown` event.
*
* @param {KeyboardEvent} event
* The `keydown` event that caused this function to be called.
*
* @listens keydown
*/
handleKeyDown(event) {
this.mouseused_ = false;

super.handleKeyDown(event);
}

/**
* Handle `mousedown` events on the `BigPlayButton`.
*
* @param {MouseEvent} event
* `mousedown` or `touchstart` event that triggered this function
*
* @listens mousedown
*/
handleMouseDown(event) {
this.mouseused_ = true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/js/button.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ class Button extends ClickableComponent {
* This gets called when a `Button` has focus and `keydown` is triggered via a key
* press.
*
* @param {Event} event
* @param {KeyboardEvent} event
* The event that caused this function to get called.
*
* @listens keydown
Expand Down
2 changes: 1 addition & 1 deletion src/js/clickable-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ class ClickableComponent extends Component {
*
* By default, if the key is Space or Enter, it will trigger a `click` event.
*
* @param {Event} event
* @param {KeyboardEvent} event
* The `keydown` event that caused this function to be called.
*
* @listens keydown
Expand Down
2 changes: 1 addition & 1 deletion src/js/close-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class CloseButton extends Button {
*
* By default, if the key is Esc, it will trigger a `click` event.
*
* @param {Event} event
* @param {KeyboardEvent} event
* The `keydown` event that caused this function to be called.
*
* @listens keydown
Expand Down
4 changes: 2 additions & 2 deletions src/js/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -1324,7 +1324,7 @@ class Component {
* delegates to `handleKeyDown`. This means anyone calling `handleKeyPress`
* will not see their method calls stop working.
*
* @param {Event} event
* @param {KeyboardEvent} event
* The event that caused this function to be called.
*/
handleKeyPress(event) {
Expand All @@ -1336,7 +1336,7 @@ class Component {
* support toggling the controls through a tap on the video. They get enabled
* because every sub-component would have extra overhead otherwise.
*
* @private
* @protected
* @fires Component#tap
* @listens Component#touchstart
* @listens Component#touchmove
Expand Down
2 changes: 1 addition & 1 deletion src/js/menu/menu-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class MenuItem extends ClickableComponent {
* Ignore keys which are used by the menu, but pass any other ones up. See
* {@link ClickableComponent#handleKeyDown} for instances where this is called.
*
* @param {Event} event
* @param {KeyboardEvent} event
* The `keydown` event that caused this function to be called.
*
* @listens keydown
Expand Down
2 changes: 1 addition & 1 deletion src/js/menu/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ class Menu extends Component {
/**
* Handle a `keydown` event on this menu. This listener is added in the constructor.
*
* @param {Event} event
* @param {KeyboardEvent} event
* A `keydown` event that happened on the menu.
*
* @listens keydown
Expand Down
2 changes: 1 addition & 1 deletion src/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -3164,7 +3164,7 @@ class Player extends Component {
* This allows player-wide hotkeys (either as defined below, or optionally
* by an external function).
*
* @param {Event} event
* @param {KeyboardEvent} event
* The `keydown` event that caused this function to be called.
*
* @listens keydown
Expand Down
2 changes: 1 addition & 1 deletion src/js/utils/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ function _cleanUpEvents(elem, type) {
* @param {Element|Object} elem
* Element or object to bind listeners to
*
* @param {string} type
* @param {string[]} types
* Type of event to bind to.
*
* @param {Function} callback
Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"include": ["src/js/**/*"],
"compilerOptions": {
"allowJs": true,
"allowSyntheticDefaultImports": true,
"declaration": true,
"emitDeclarationOnly": true,
"outDir": "dist/types",
Expand Down

0 comments on commit 781eb43

Please sign in to comment.