Skip to content

Commit

Permalink
dom: Add types to miscellaneous files (#30774)
Browse files Browse the repository at this point in the history
  • Loading branch information
sarayourfriend authored Apr 14, 2021
1 parent 6eeb0dd commit dd4cc1b
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 7 deletions.
4 changes: 2 additions & 2 deletions packages/dom/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,11 +138,11 @@ Given a DOM node, finds the closest scrollable container node.
_Parameters_
- _node_ `Element`: Node from which to start.
- _node_ `Element | null`: Node from which to start.
_Returns_
- `?Element`: Scrollable container node, if found.
- `Element | undefined`: Scrollable container node, if found.
<a name="insertAfter" href="#insertAfter">#</a> **insertAfter**
Expand Down
8 changes: 4 additions & 4 deletions packages/dom/src/dom/get-scroll-container.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import getComputedStyle from './get-computed-style';
/**
* Given a DOM node, finds the closest scrollable container node.
*
* @param {Element} node Node from which to start.
* @param {Element | null} node Node from which to start.
*
* @return {?Element} Scrollable container node, if found.
* @return {Element | undefined} Scrollable container node, if found.
*/
export default function getScrollContainer( node ) {
if ( ! node ) {
return;
return undefined;
}

// Scrollable if scrollable height exceeds displayed...
Expand All @@ -25,5 +25,5 @@ export default function getScrollContainer( node ) {
}

// Continue traversing
return getScrollContainer( node.parentNode );
return getScrollContainer( /** @type {Element} */ ( node.parentNode ) );
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ export default function inputFieldHasUncollapsedSelection( element ) {
return false;
}
try {
const { selectionStart, selectionEnd } = element;
const {
selectionStart,
selectionEnd,
} = /** @type {HTMLInputElement | HTMLTextAreaElement} */ ( element );

return selectionStart !== null && selectionStart !== selectionEnd;
} catch ( error ) {
Expand Down
6 changes: 6 additions & 0 deletions packages/dom/src/dom/replace-tag.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
/**
* Internal dependencies
*/
import { assertIsDefined } from '../utils/assert-is-defined';

/**
* Replaces the given node with a new node with the given tag name.
*
Expand All @@ -13,6 +18,7 @@ export default function replaceTag( node, tagName ) {
newNode.appendChild( node.firstChild );
}

assertIsDefined( node.parentNode, 'node.parentNode' );
node.parentNode.replaceChild( newNode, node );

return newNode;
Expand Down
2 changes: 2 additions & 0 deletions packages/dom/src/dom/replace.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/**
* Internal dependencies
*/
import { assertIsDefined } from '../utils/assert-is-defined';
import insertAfter from './insert-after';
import remove from './remove';

Expand All @@ -12,6 +13,7 @@ import remove from './remove';
* @return {void}
*/
export default function replace( processedNode, newNode ) {
assertIsDefined( processedNode.parentNode, 'processedNode.parentNode' );
insertAfter( newNode, processedNode.parentNode );
remove( processedNode );
}
6 changes: 6 additions & 0 deletions packages/dom/src/dom/wrap.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
/**
* Internal dependencies
*/
import { assertIsDefined } from '../utils/assert-is-defined';

/**
* Wraps the given node with a new node with the given tag name.
*
* @param {Element} newNode The node to insert.
* @param {Element} referenceNode The node to wrap.
*/
export default function wrap( newNode, referenceNode ) {
assertIsDefined( referenceNode.parentNode, 'referenceNode.parentNode' );
referenceNode.parentNode.insertBefore( newNode, referenceNode );
newNode.appendChild( referenceNode );
}
6 changes: 6 additions & 0 deletions packages/dom/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
"src/dom/get-computed-style.js",
"src/dom/get-range-height.js",
"src/dom/get-rectangle-from-range.js",
"src/dom/get-scroll-container.js",
"src/dom/hidden-caret-range-from-point.js",
"src/dom/input-field-has-uncollapsed-selection.js",
"src/dom/is-edge.js",
"src/dom/is-empty.js",
"src/dom/is-element.js",
Expand All @@ -24,13 +26,17 @@
"src/dom/is-number-input.js",
"src/dom/is-text-field.js",
"src/dom/is-selection-forward.js",
"src/dom/is-vertical-edge.js",
"src/dom/insert-after.js",
"src/dom/remove-invalid-html.js",
"src/dom/place-caret-at-horizontal-edge.js",
"src/dom/place-caret-at-vertical-edge.js",
"src/dom/remove.js",
"src/dom/strip-html.js",
"src/dom/replace-tag.js",
"src/dom/replace.js",
"src/dom/unwrap.js",
"src/dom/wrap.js",
"src/utils/**/*",
"src/focusable.js",
"src/phrasing-content.js",
Expand Down

0 comments on commit dd4cc1b

Please sign in to comment.