@wordpress/dom
Advanced tools
Comparing version 3.1.1 to 3.1.2
@@ -52,7 +52,32 @@ /** | ||
assertIsDefined(lastChild, 'lastChild'); | ||
const lastChildContentLength = lastChild.nodeType === lastChild.TEXT_NODE ? | ||
const endContainerContentLength = endContainer.nodeType === endContainer.TEXT_NODE ? | ||
/** @type {Text} */ | ||
lastChild.data.length : lastChild.childNodes.length; | ||
return startContainer === element.firstChild && endContainer === element.lastChild && startOffset === 0 && endOffset === lastChildContentLength; | ||
endContainer.data.length : endContainer.childNodes.length; | ||
return isDeepChild(startContainer, element, 'firstChild') && isDeepChild(endContainer, element, 'lastChild') && startOffset === 0 && endOffset === endContainerContentLength; | ||
} | ||
/** | ||
* Check whether the contents of the element have been entirely selected. | ||
* Returns true if there is no possibility of selection. | ||
* | ||
* @param {HTMLElement|Node} query The element to check. | ||
* @param {HTMLElement} container The container that we suspect "query" may be a first or last child of. | ||
* @param {"firstChild"|"lastChild"} propName "firstChild" or "lastChild" | ||
* | ||
* @return {boolean} True if query is a deep first/last child of container, false otherwise. | ||
*/ | ||
function isDeepChild(query, container, propName) { | ||
/** @type {HTMLElement | ChildNode | null} */ | ||
let candidate = container; | ||
do { | ||
if (query === candidate) { | ||
return true; | ||
} | ||
candidate = candidate[propName]; | ||
} while (candidate); | ||
return false; | ||
} | ||
//# sourceMappingURL=is-entirely-selected.js.map |
@@ -63,7 +63,33 @@ "use strict"; | ||
(0, _assertIsDefined.assertIsDefined)(lastChild, 'lastChild'); | ||
const lastChildContentLength = lastChild.nodeType === lastChild.TEXT_NODE ? | ||
const endContainerContentLength = endContainer.nodeType === endContainer.TEXT_NODE ? | ||
/** @type {Text} */ | ||
lastChild.data.length : lastChild.childNodes.length; | ||
return startContainer === element.firstChild && endContainer === element.lastChild && startOffset === 0 && endOffset === lastChildContentLength; | ||
endContainer.data.length : endContainer.childNodes.length; | ||
return isDeepChild(startContainer, element, 'firstChild') && isDeepChild(endContainer, element, 'lastChild') && startOffset === 0 && endOffset === endContainerContentLength; | ||
} | ||
/** | ||
* Check whether the contents of the element have been entirely selected. | ||
* Returns true if there is no possibility of selection. | ||
* | ||
* @param {HTMLElement|Node} query The element to check. | ||
* @param {HTMLElement} container The container that we suspect "query" may be a first or last child of. | ||
* @param {"firstChild"|"lastChild"} propName "firstChild" or "lastChild" | ||
* | ||
* @return {boolean} True if query is a deep first/last child of container, false otherwise. | ||
*/ | ||
function isDeepChild(query, container, propName) { | ||
/** @type {HTMLElement | ChildNode | null} */ | ||
let candidate = container; | ||
do { | ||
if (query === candidate) { | ||
return true; | ||
} | ||
candidate = candidate[propName]; | ||
} while (candidate); | ||
return false; | ||
} | ||
//# sourceMappingURL=is-entirely-selected.js.map |
{ | ||
"name": "@wordpress/dom", | ||
"version": "3.1.1", | ||
"version": "3.1.2", | ||
"description": "DOM utilities module for WordPress.", | ||
@@ -37,3 +37,3 @@ "author": "The WordPress Contributors", | ||
}, | ||
"gitHead": "954d6776be2ee80b5975e4ced6a3d481d8a89354" | ||
"gitHead": "a39d5605fcea63a9e02a9ae9d3f3d4f1685df14e" | ||
} |
@@ -51,13 +51,35 @@ /** | ||
assertIsDefined( lastChild, 'lastChild' ); | ||
const lastChildContentLength = | ||
lastChild.nodeType === lastChild.TEXT_NODE | ||
? /** @type {Text} */ ( lastChild ).data.length | ||
: lastChild.childNodes.length; | ||
const endContainerContentLength = | ||
endContainer.nodeType === endContainer.TEXT_NODE | ||
? /** @type {Text} */ ( endContainer ).data.length | ||
: endContainer.childNodes.length; | ||
return ( | ||
startContainer === element.firstChild && | ||
endContainer === element.lastChild && | ||
isDeepChild( startContainer, element, 'firstChild' ) && | ||
isDeepChild( endContainer, element, 'lastChild' ) && | ||
startOffset === 0 && | ||
endOffset === lastChildContentLength | ||
endOffset === endContainerContentLength | ||
); | ||
} | ||
/** | ||
* Check whether the contents of the element have been entirely selected. | ||
* Returns true if there is no possibility of selection. | ||
* | ||
* @param {HTMLElement|Node} query The element to check. | ||
* @param {HTMLElement} container The container that we suspect "query" may be a first or last child of. | ||
* @param {"firstChild"|"lastChild"} propName "firstChild" or "lastChild" | ||
* | ||
* @return {boolean} True if query is a deep first/last child of container, false otherwise. | ||
*/ | ||
function isDeepChild( query, container, propName ) { | ||
/** @type {HTMLElement | ChildNode | null} */ | ||
let candidate = container; | ||
do { | ||
if ( query === candidate ) { | ||
return true; | ||
} | ||
candidate = candidate[ propName ]; | ||
} while ( candidate ); | ||
return false; | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
550467
6405