Skip to content
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

[WIP] Type enhancements #8968

Draft
wants to merge 18 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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