Skip to content

refactor(types): Type enhancements #8968

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
e93f224
wiip
mister-ben Nov 12, 2024
0d7a77d
Merge branch 'main' into type-experiment-467
mister-ben Nov 14, 2024
bebefa8
Merge branch 'main' into type-experiment-467
mister-ben Nov 15, 2024
53c6c3d
Update typescript
mister-ben Dec 6, 2024
705df44
Types overhaul
mister-ben Dec 6, 2024
9813b5c
Merge branch 'main' into type-experiment-467
mister-ben Dec 10, 2024
c6754b2
update jsdoc,tsc deps
mister-ben Dec 12, 2024
fcc47da
reorg exports
mister-ben Dec 12, 2024
c1d4bd0
list of strings for audio/video track types
mister-ben Dec 12, 2024
dd7f1ff
use standard types for TextTracks
mister-ben Dec 12, 2024
74c1316
Fix type of SourceObject, MediaObject
mister-ben Dec 12, 2024
2ea0ced
Update description to match type
mister-ben Dec 12, 2024
1b482a5
Add more to component options
mister-ben Dec 13, 2024
8d2f672
Fullscreen properties
mister-ben Dec 13, 2024
2e5fc2d
Define player options and have them importable from top level
mister-ben Jan 13, 2025
f7da0c6
fixes
mister-ben Jan 14, 2025
c884bfa
Merge branch 'main' into type-enhancements
mister-ben Jan 31, 2025
ea97ef1
Add redundant jsdoc so that tsc understands
mister-ben Jan 31, 2025
7420c3d
Merge branch 'main' into type-enhancements
mister-ben Feb 14, 2025
08eeb6e
lint
Feb 14, 2025
2798afd
support @template {typeof Component} T
mister-ben Feb 17, 2025
4e5dbb1
Update regiserComponent jsdoc
mister-ben Feb 17, 2025
88aead4
Merge branch 'main' into type-enhancements
mister-ben Mar 24, 2025
84cd78d
Merge branch 'main' into type-enhancements
mister-ben Apr 23, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions build/jsdoc-typeof-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@
*/
exports.handlers = {
jsdocCommentFound: event => {
const templateMatch = /@template {(.*)} ([A-Z])\n/.exec(event.comment || '');

if (templateMatch) {
const className = templateMatch[1];
const templateName = templateMatch[2];

event.comment = event.comment.replace(new RegExp(`{(.*\\b)(${templateName})(\\b.*)}`, 'g'), `{$1typeof ${className}$3}`);
}

// \{.*\bT\b.*\}
event.comment = (event.comment || '').replace(/\{.*typeof\s+([^\s\|]+).*\}/g, typeExpression => {
return typeExpression.replace(/typeof\s+([^\s\|\}]+)/g, (expression, className) => {
return 'Class<' + className + '>';
Expand Down
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
"humanize-duration": "^3.26.0",
"husky": "^1.3.1",
"is-ci": "^3.0.0",
"jsdoc": "^4.0.3",
"jsdoc": "^4.0.4",
"karma": "^6.4.3",
"lint-staged": "^10.5.4",
"markdown-table": "^1.1.3",
Expand Down Expand Up @@ -160,7 +160,7 @@
"shelljs": "^0.8.5",
"shx": "^0.3.2",
"sinon": "^11.1.1",
"typescript": "^5.5.2",
"typescript": "^5.7.2",
"uglify-js": "^3.19.0",
"unified": "^7.0.2",
"videojs-generate-karma-config": "^8.1.0",
Expand Down
38 changes: 21 additions & 17 deletions src/js/component.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ import {merge} from './utils/obj.js';
* @returns {void}
*/

/**
* @typedef {Object} ComponentOptions
* @property {Object[]} [children]
* @property {string} [classname]
* @property {boolean} [initChildren]
* @property {boolean} [reportTouchActivity]
* @property {string} [name]
* @property {boolean} [createEl=true]
* @property {HTMLElement} [el]
* @property {boolean} [evented]
*/

/**
* Base class for all UI Components.
* Components are UI objects which represent both a javascript object and an element
Expand All @@ -39,17 +51,9 @@ class Component {
* @param {Player} player
* The `Player` that this class should be attached to.
*
* @param {Object} [options]
* @param {ComponentOptions} [options]
* The key/value store of component options.
*
* @param {Object[]} [options.children]
* An array of children objects to initialize this component with. Children objects have
* a name property that will be used if more than one component of the same type needs to be
* added.
*
* @param {string} [options.className]
* A class or space separated list of classes to add the component
*
* @param {ReadyCallback} [ready]
* Function that gets called when the `Component` is ready.
*/
Expand Down Expand Up @@ -589,22 +593,22 @@ class Component {

return iconContainer;
}

/**
* Add a child `Component` inside the current `Component`.
*
* @param {string|Component} child
* @template {Component} T
* @param {string|T} child
* The name or instance of a child to add.
*
* @param {Object} [options={}]
* @param {ComponentOptions} [options={}]
* The key/value store of options that will get passed to children of
* the child.
*
* @param {number} [index=this.children_.length]
* The index to attempt to add a child into.
*
*
* @return {Component}
* @return {T}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renders like this in the API docs with the changes to jsdoc-typeof-plugin:
image

* The `Component` that gets added as a child. When using a string the
* `Component` will get created by this process.
*/
Expand Down Expand Up @@ -1242,7 +1246,7 @@ class Component {
* An object that contains width and height values of the `Component`s
* computed style. Uses `window.getComputedStyle`.
*
* @typedef {Object} Component~DimensionObject
* @typedef {Object} DimensionObject
*
* @property {number} width
* The width of the `Component`s computed style.
Expand All @@ -1257,7 +1261,7 @@ class Component {
*
* Uses `window.getComputedStyle`.
*
* @return {Component~DimensionObject}
* @return {DimensionObject}
* The computed dimensions of the component's element.
*/
currentDimensions() {
Expand Down Expand Up @@ -1979,10 +1983,10 @@ class Component {
* @param {string} name
* The name of the `Component` to register.
*
* @param {Component} ComponentToRegister
* @param {typeof Component} ComponentToRegister
* The `Component` class to register.
*
* @return {Component}
* @return {typeof Component}
* The `Component` that was registered.
*/
static registerComponent(name, ComponentToRegister) {
Expand Down
8 changes: 8 additions & 0 deletions src/js/fullscreen-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ import document from 'global/document';
* Store the browser-specific methods for the fullscreen API.
*
* @type {Object}
* @property {string} requestFullscreen
* @property {string} exitFullscreen
* @property {string} fullscreenElement
* @property {string} fullscreenEnabled
* @property {string} fullscreenchange
* @property {string} fullscreenerror
* @property {string} fullscreen
* @property {boolean} prefixed
* @see [Specification]{@link https://fullscreen.spec.whatwg.org}
* @see [Map Approach From Screenfull.js]{@link https://github.com/sindresorhus/screenfull.js}
*/
Expand Down
Loading
Loading