Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@wordpress/dom

Package Overview
Dependencies
Maintainers
16
Versions
193
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@wordpress/dom - npm Package Compare versions

Comparing version 2.14.0 to 2.15.0

96

build-module/dom.js

@@ -10,14 +10,6 @@ /**

import { isPhrasingContent } from './phrasing-content';
/**
* Browser dependencies
*/
var _window = window,
DOMParser = _window.DOMParser,
getComputedStyle = _window.getComputedStyle;
var _window$Node = window.Node,
TEXT_NODE = _window$Node.TEXT_NODE,
ELEMENT_NODE = _window$Node.ELEMENT_NODE,
DOCUMENT_POSITION_PRECEDING = _window$Node.DOCUMENT_POSITION_PRECEDING,
DOCUMENT_POSITION_FOLLOWING = _window$Node.DOCUMENT_POSITION_FOLLOWING;
function getComputedStyle(node) {
return node.ownerDocument.defaultView.getComputedStyle(node);
}
/**

@@ -34,2 +26,3 @@ * Returns true if the given selection object is in the forward direction, or

function isSelectionForward(selection) {

@@ -47,7 +40,7 @@ var anchorNode = selection.anchorNode,

if (position & DOCUMENT_POSITION_PRECEDING) {
if (position & anchorNode.DOCUMENT_POSITION_PRECEDING) {
return false;
}
if (position & DOCUMENT_POSITION_FOLLOWING) {
if (position & anchorNode.DOCUMENT_POSITION_FOLLOWING) {
return true;

@@ -97,3 +90,5 @@ }

var selection = window.getSelection();
var ownerDocument = container.ownerDocument;
var defaultView = ownerDocument.defaultView;
var selection = defaultView.getSelection();

@@ -119,3 +114,3 @@ if (!selection.rangeCount) {

var computedStyle = window.getComputedStyle(container);
var computedStyle = getComputedStyle(container);
var lineHeight = parseInt(computedStyle.lineHeight, 10) || 0; // Only consider the multiline selection at the edge if the direction is

@@ -156,3 +151,3 @@ // towards the edge.

var y = isReverse ? containerRect.top + buffer : containerRect.bottom - buffer;
var testRange = hiddenCaretRangeFromPoint(document, x, y, container);
var testRange = hiddenCaretRangeFromPoint(ownerDocument, x, y, container);

@@ -210,3 +205,4 @@ if (!testRange) {

var _range = range,
startContainer = _range.startContainer; // Correct invalid "BR" ranges. The cannot contain any children.
startContainer = _range.startContainer;
var ownerDocument = startContainer.ownerDocument; // Correct invalid "BR" ranges. The cannot contain any children.

@@ -216,3 +212,3 @@ if (startContainer.nodeName === 'BR') {

var index = Array.from(parentNode.childNodes).indexOf(startContainer);
range = document.createRange();
range = ownerDocument.createRange();
range.setStart(parentNode, index);

@@ -229,3 +225,3 @@ range.setEnd(parentNode, index);

if (!rect) {
var padNode = document.createTextNode("\u200B"); // Do not modify the live range.
var padNode = ownerDocument.createTextNode("\u200B"); // Do not modify the live range.

@@ -243,7 +239,9 @@ range = range.cloneRange();

*
* @param {Window} win The window of the selection.
*
* @return {?DOMRect} The rectangle.
*/
export function computeCaretRect() {
var selection = window.getSelection();
export function computeCaretRect(win) {
var selection = win.getSelection();
var range = selection.rangeCount ? selection.getRangeAt(0) : null;

@@ -299,4 +297,6 @@

var selection = window.getSelection();
var range = document.createRange();
var ownerDocument = container.ownerDocument;
var defaultView = ownerDocument.defaultView;
var selection = defaultView.getSelection();
var range = ownerDocument.createRange();
range.selectNodeContents(rangeTarget);

@@ -313,5 +313,5 @@ range.collapse(!isReverse);

*
* @param {Document} doc The document of the range.
* @param {number} x Horizontal position within the current viewport.
* @param {number} y Vertical position within the current viewport.
* @param {Document} doc The document of the range.
* @param {number} x Horizontal position within the current viewport.
* @param {number} y Vertical position within the current viewport.
*

@@ -399,3 +399,5 @@ * @return {?Range} The best range for the given point.

var y = isReverse ? editableRect.bottom - buffer : editableRect.top + buffer;
var range = hiddenCaretRangeFromPoint(document, x, y, container);
var ownerDocument = container.ownerDocument;
var defaultView = ownerDocument.defaultView;
var range = hiddenCaretRangeFromPoint(ownerDocument, x, y, container);

@@ -415,3 +417,3 @@ if (!range || !container.contains(range.startContainer)) {

var selection = window.getSelection();
var selection = defaultView.getSelection();
selection.removeAllRanges();

@@ -464,7 +466,9 @@ selection.addRange(range);

*
* @param {Document} doc The document to check.
*
* @return {boolean} True if there is selection, false if not.
*/
export function documentHasTextSelection() {
var selection = window.getSelection();
export function documentHasTextSelection(doc) {
var selection = doc.defaultView.getSelection();
var range = selection.rangeCount ? selection.getRangeAt(0) : null;

@@ -513,2 +517,4 @@ return range && !range.collapsed;

*
* @param {Document} doc The document to check.
*
* @return {boolean} Whether there is any sort of "selection" in the document.

@@ -518,4 +524,4 @@ */

export function documentHasUncollapsedSelection() {
return documentHasTextSelection() || inputFieldHasUncollapsedSelection(document.activeElement);
export function documentHasUncollapsedSelection(doc) {
return documentHasTextSelection(doc) || inputFieldHasUncollapsedSelection(doc.activeElement);
}

@@ -526,7 +532,9 @@ /**

*
* @param {Document} doc The document to check.
*
* @return {boolean} True if there is selection, false if not.
*/
export function documentHasSelection() {
return isTextField(document.activeElement) || isNumberInput(document.activeElement) || documentHasTextSelection();
export function documentHasSelection(doc) {
return isTextField(doc.activeElement) || isNumberInput(doc.activeElement) || documentHasTextSelection(doc);
}

@@ -551,3 +559,5 @@ /**

var selection = window.getSelection();
var ownerDocument = element.ownerDocument;
var defaultView = ownerDocument.defaultView;
var selection = defaultView.getSelection();
var range = selection.rangeCount ? selection.getRangeAt(0) : null;

@@ -569,3 +579,3 @@

var lastChild = element.lastChild;
var lastChildContentLength = lastChild.nodeType === TEXT_NODE ? lastChild.data.length : lastChild.childNodes.length;
var lastChildContentLength = lastChild.nodeType === lastChild.TEXT_NODE ? lastChild.data.length : lastChild.childNodes.length;
return startContainer === element.firstChild && endContainer === element.lastChild && startOffset === 0 && endOffset === lastChildContentLength;

@@ -589,4 +599,4 @@ }

// ...except when overflow is defined to be hidden or visible
var _window$getComputedSt = window.getComputedStyle(node),
overflowY = _window$getComputedSt.overflowY;
var _getComputedStyle = getComputedStyle(node),
overflowY = _getComputedStyle.overflowY;

@@ -619,3 +629,3 @@ if (/(auto|scroll)/.test(overflowY)) {

while (closestElement = node.parentNode) {
if (closestElement.nodeType === ELEMENT_NODE) {
if (closestElement.nodeType === closestElement.ELEMENT_NODE) {
break;

@@ -727,3 +737,3 @@ }

export function __unstableStripHTML(html) {
var document = new DOMParser().parseFromString(html, 'text/html');
var document = new window.DOMParser().parseFromString(html, 'text/html');
return document.body.textContent || '';

@@ -747,3 +757,3 @@ }

if (schema.hasOwnProperty(tag) && (!schema[tag].isMatch || schema[tag].isMatch(node))) {
if (node.nodeType === ELEMENT_NODE) {
if (node.nodeType === node.ELEMENT_NODE) {
var _schema$tag = schema[tag],

@@ -869,7 +879,7 @@ _schema$tag$attribute = _schema$tag.attributes,

return Array.from(element.childNodes).every(function (node) {
if (node.nodeType === TEXT_NODE) {
if (node.nodeType === node.TEXT_NODE) {
return !node.nodeValue.trim();
}
if (node.nodeType === ELEMENT_NODE) {
if (node.nodeType === node.ELEMENT_NODE) {
if (node.nodeName === 'BR') {

@@ -876,0 +886,0 @@ return true;

@@ -63,3 +63,3 @@ /**

var img = document.querySelector('img[usemap="#' + map.name + '"]');
var img = element.ownerDocument.querySelector('img[usemap="#' + map.name + '"]');
return !!img && isVisible(img);

@@ -66,0 +66,0 @@ }

@@ -111,3 +111,3 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";

var phrasingContentSchema = _objectSpread({}, textContentSchema, {}, embeddedContentSchema);
var phrasingContentSchema = _objectSpread(_objectSpread({}, textContentSchema), embeddedContentSchema);
/**

@@ -130,3 +130,3 @@ * Get schema of possible paths for phrasing content.

return omit(_objectSpread({}, phrasingContentSchema, {
return omit(_objectSpread(_objectSpread({}, phrasingContentSchema), {}, {
// We shouldn't paste potentially sensitive information which is not

@@ -133,0 +133,0 @@ // visible to the user when pasted, so strip the attributes.

@@ -157,5 +157,4 @@ /**

export function findPrevious() {
var element = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document.activeElement;
var focusables = findFocusable(document.body);
export function findPrevious(element) {
var focusables = findFocusable(element.ownerDocument.body);
var index = focusables.indexOf(element); // Remove all focusables after and including `element`.

@@ -173,5 +172,4 @@

export function findNext() {
var element = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document.activeElement;
var focusables = findFocusable(document.body);
export function findNext(element) {
var focusables = findFocusable(element.ownerDocument.body);
var index = focusables.indexOf(element); // Remove all focusables before and inside `element`.

@@ -178,0 +176,0 @@

@@ -41,15 +41,6 @@ "use strict";

*/
function getComputedStyle(node) {
return node.ownerDocument.defaultView.getComputedStyle(node);
}
/**
* Browser dependencies
*/
var _window = window,
DOMParser = _window.DOMParser,
getComputedStyle = _window.getComputedStyle;
var _window$Node = window.Node,
TEXT_NODE = _window$Node.TEXT_NODE,
ELEMENT_NODE = _window$Node.ELEMENT_NODE,
DOCUMENT_POSITION_PRECEDING = _window$Node.DOCUMENT_POSITION_PRECEDING,
DOCUMENT_POSITION_FOLLOWING = _window$Node.DOCUMENT_POSITION_FOLLOWING;
/**
* Returns true if the given selection object is in the forward direction, or

@@ -65,2 +56,3 @@ * false otherwise.

function isSelectionForward(selection) {

@@ -78,7 +70,7 @@ var anchorNode = selection.anchorNode,

if (position & DOCUMENT_POSITION_PRECEDING) {
if (position & anchorNode.DOCUMENT_POSITION_PRECEDING) {
return false;
}
if (position & DOCUMENT_POSITION_FOLLOWING) {
if (position & anchorNode.DOCUMENT_POSITION_FOLLOWING) {
return true;

@@ -128,3 +120,5 @@ }

var selection = window.getSelection();
var ownerDocument = container.ownerDocument;
var defaultView = ownerDocument.defaultView;
var selection = defaultView.getSelection();

@@ -150,3 +144,3 @@ if (!selection.rangeCount) {

var computedStyle = window.getComputedStyle(container);
var computedStyle = getComputedStyle(container);
var lineHeight = parseInt(computedStyle.lineHeight, 10) || 0; // Only consider the multiline selection at the edge if the direction is

@@ -187,3 +181,3 @@ // towards the edge.

var y = isReverse ? containerRect.top + buffer : containerRect.bottom - buffer;
var testRange = hiddenCaretRangeFromPoint(document, x, y, container);
var testRange = hiddenCaretRangeFromPoint(ownerDocument, x, y, container);

@@ -243,3 +237,4 @@ if (!testRange) {

var _range = range,
startContainer = _range.startContainer; // Correct invalid "BR" ranges. The cannot contain any children.
startContainer = _range.startContainer;
var ownerDocument = startContainer.ownerDocument; // Correct invalid "BR" ranges. The cannot contain any children.

@@ -249,3 +244,3 @@ if (startContainer.nodeName === 'BR') {

var index = Array.from(parentNode.childNodes).indexOf(startContainer);
range = document.createRange();
range = ownerDocument.createRange();
range.setStart(parentNode, index);

@@ -262,3 +257,3 @@ range.setEnd(parentNode, index);

if (!rect) {
var padNode = document.createTextNode("\u200B"); // Do not modify the live range.
var padNode = ownerDocument.createTextNode("\u200B"); // Do not modify the live range.

@@ -276,2 +271,4 @@ range = range.cloneRange();

*
* @param {Window} win The window of the selection.
*
* @return {?DOMRect} The rectangle.

@@ -281,4 +278,4 @@ */

function computeCaretRect() {
var selection = window.getSelection();
function computeCaretRect(win) {
var selection = win.getSelection();
var range = selection.rangeCount ? selection.getRangeAt(0) : null;

@@ -335,4 +332,6 @@

var selection = window.getSelection();
var range = document.createRange();
var ownerDocument = container.ownerDocument;
var defaultView = ownerDocument.defaultView;
var selection = defaultView.getSelection();
var range = ownerDocument.createRange();
range.selectNodeContents(rangeTarget);

@@ -349,5 +348,5 @@ range.collapse(!isReverse);

*
* @param {Document} doc The document of the range.
* @param {number} x Horizontal position within the current viewport.
* @param {number} y Vertical position within the current viewport.
* @param {Document} doc The document of the range.
* @param {number} x Horizontal position within the current viewport.
* @param {number} y Vertical position within the current viewport.
*

@@ -436,3 +435,5 @@ * @return {?Range} The best range for the given point.

var y = isReverse ? editableRect.bottom - buffer : editableRect.top + buffer;
var range = hiddenCaretRangeFromPoint(document, x, y, container);
var ownerDocument = container.ownerDocument;
var defaultView = ownerDocument.defaultView;
var range = hiddenCaretRangeFromPoint(ownerDocument, x, y, container);

@@ -452,3 +453,3 @@ if (!range || !container.contains(range.startContainer)) {

var selection = window.getSelection();
var selection = defaultView.getSelection();
selection.removeAllRanges();

@@ -503,2 +504,4 @@ selection.addRange(range);

*
* @param {Document} doc The document to check.
*
* @return {boolean} True if there is selection, false if not.

@@ -508,4 +511,4 @@ */

function documentHasTextSelection() {
var selection = window.getSelection();
function documentHasTextSelection(doc) {
var selection = doc.defaultView.getSelection();
var range = selection.rangeCount ? selection.getRangeAt(0) : null;

@@ -555,2 +558,4 @@ return range && !range.collapsed;

*
* @param {Document} doc The document to check.
*
* @return {boolean} Whether there is any sort of "selection" in the document.

@@ -560,4 +565,4 @@ */

function documentHasUncollapsedSelection() {
return documentHasTextSelection() || inputFieldHasUncollapsedSelection(document.activeElement);
function documentHasUncollapsedSelection(doc) {
return documentHasTextSelection(doc) || inputFieldHasUncollapsedSelection(doc.activeElement);
}

@@ -568,2 +573,4 @@ /**

*
* @param {Document} doc The document to check.
*
* @return {boolean} True if there is selection, false if not.

@@ -573,4 +580,4 @@ */

function documentHasSelection() {
return isTextField(document.activeElement) || isNumberInput(document.activeElement) || documentHasTextSelection();
function documentHasSelection(doc) {
return isTextField(doc.activeElement) || isNumberInput(doc.activeElement) || documentHasTextSelection(doc);
}

@@ -596,3 +603,5 @@ /**

var selection = window.getSelection();
var ownerDocument = element.ownerDocument;
var defaultView = ownerDocument.defaultView;
var selection = defaultView.getSelection();
var range = selection.rangeCount ? selection.getRangeAt(0) : null;

@@ -614,3 +623,3 @@

var lastChild = element.lastChild;
var lastChildContentLength = lastChild.nodeType === TEXT_NODE ? lastChild.data.length : lastChild.childNodes.length;
var lastChildContentLength = lastChild.nodeType === lastChild.TEXT_NODE ? lastChild.data.length : lastChild.childNodes.length;
return startContainer === element.firstChild && endContainer === element.lastChild && startOffset === 0 && endOffset === lastChildContentLength;

@@ -635,4 +644,4 @@ }

// ...except when overflow is defined to be hidden or visible
var _window$getComputedSt = window.getComputedStyle(node),
overflowY = _window$getComputedSt.overflowY;
var _getComputedStyle = getComputedStyle(node),
overflowY = _getComputedStyle.overflowY;

@@ -666,3 +675,3 @@ if (/(auto|scroll)/.test(overflowY)) {

while (closestElement = node.parentNode) {
if (closestElement.nodeType === ELEMENT_NODE) {
if (closestElement.nodeType === closestElement.ELEMENT_NODE) {
break;

@@ -781,3 +790,3 @@ }

function __unstableStripHTML(html) {
var document = new DOMParser().parseFromString(html, 'text/html');
var document = new window.DOMParser().parseFromString(html, 'text/html');
return document.body.textContent || '';

@@ -802,3 +811,3 @@ }

if (schema.hasOwnProperty(tag) && (!schema[tag].isMatch || schema[tag].isMatch(node))) {
if (node.nodeType === ELEMENT_NODE) {
if (node.nodeType === node.ELEMENT_NODE) {
var _schema$tag = schema[tag],

@@ -924,7 +933,7 @@ _schema$tag$attribute = _schema$tag.attributes,

return Array.from(element.childNodes).every(function (node) {
if (node.nodeType === TEXT_NODE) {
if (node.nodeType === node.TEXT_NODE) {
return !node.nodeValue.trim();
}
if (node.nodeType === ELEMENT_NODE) {
if (node.nodeType === node.ELEMENT_NODE) {
if (node.nodeName === 'BR') {

@@ -931,0 +940,0 @@ return true;

@@ -70,3 +70,3 @@ "use strict";

var img = document.querySelector('img[usemap="#' + map.name + '"]');
var img = element.ownerDocument.querySelector('img[usemap="#' + map.name + '"]');
return !!img && isVisible(img);

@@ -73,0 +73,0 @@ }

@@ -119,3 +119,3 @@ "use strict";

var phrasingContentSchema = _objectSpread({}, textContentSchema, {}, embeddedContentSchema);
var phrasingContentSchema = _objectSpread(_objectSpread({}, textContentSchema), embeddedContentSchema);
/**

@@ -138,3 +138,3 @@ * Get schema of possible paths for phrasing content.

return (0, _lodash.omit)(_objectSpread({}, phrasingContentSchema, {
return (0, _lodash.omit)(_objectSpread(_objectSpread({}, phrasingContentSchema), {}, {
// We shouldn't paste potentially sensitive information which is not

@@ -141,0 +141,0 @@ // visible to the user when pasted, so strip the attributes.

@@ -171,5 +171,4 @@ "use strict";

function findPrevious() {
var element = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document.activeElement;
var focusables = (0, _focusable.find)(document.body);
function findPrevious(element) {
var focusables = (0, _focusable.find)(element.ownerDocument.body);
var index = focusables.indexOf(element); // Remove all focusables after and including `element`.

@@ -188,5 +187,4 @@

function findNext() {
var element = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document.activeElement;
var focusables = (0, _focusable.find)(document.body);
function findNext(element) {
var focusables = (0, _focusable.find)(element.ownerDocument.body);
var index = focusables.indexOf(element); // Remove all focusables before and inside `element`.

@@ -193,0 +191,0 @@

{
"name": "@wordpress/dom",
"version": "2.14.0",
"version": "2.15.0",
"description": "DOM utilities module for WordPress.",

@@ -27,3 +27,3 @@ "author": "The WordPress Contributors",

"dependencies": {
"@babel/runtime": "^7.9.2",
"@babel/runtime": "^7.11.2",
"lodash": "^4.17.19"

@@ -34,3 +34,3 @@ },

},
"gitHead": "07baf5a12007d31bbd4ee22113b07952f7eacc26"
"gitHead": "cbcd167ffb9b67f87a79df71d95aa48dc4db1a64"
}

@@ -21,2 +21,6 @@ # DOM

_Parameters_
- _win_ `Window`: The window of the selection.
_Returns_

@@ -31,2 +35,6 @@

_Parameters_
- _doc_ `Document`: The document to check.
_Returns_

@@ -44,2 +52,6 @@

_Parameters_
- _doc_ `Document`: The document to check.
_Returns_

@@ -55,2 +67,6 @@

_Parameters_
- _doc_ `Document`: The document to check.
_Returns_

@@ -57,0 +73,0 @@

@@ -11,14 +11,6 @@ /**

/**
* Browser dependencies
*/
function getComputedStyle( node ) {
return node.ownerDocument.defaultView.getComputedStyle( node );
}
const { DOMParser, getComputedStyle } = window;
const {
TEXT_NODE,
ELEMENT_NODE,
DOCUMENT_POSITION_PRECEDING,
DOCUMENT_POSITION_FOLLOWING,
} = window.Node;
/**

@@ -44,7 +36,7 @@ * Returns true if the given selection object is in the forward direction, or

// end of selection occurs) is after the anchor node, it is forward.
if ( position & DOCUMENT_POSITION_PRECEDING ) {
if ( position & anchorNode.DOCUMENT_POSITION_PRECEDING ) {
return false;
}
if ( position & DOCUMENT_POSITION_FOLLOWING ) {
if ( position & anchorNode.DOCUMENT_POSITION_FOLLOWING ) {
return true;

@@ -92,4 +84,7 @@ }

const selection = window.getSelection();
const { ownerDocument } = container;
const { defaultView } = ownerDocument;
const selection = defaultView.getSelection();
if ( ! selection.rangeCount ) {

@@ -115,3 +110,3 @@ return false;

const computedStyle = window.getComputedStyle( container );
const computedStyle = getComputedStyle( container );
const lineHeight = parseInt( computedStyle.lineHeight, 10 ) || 0;

@@ -167,3 +162,8 @@

: containerRect.bottom - buffer;
const testRange = hiddenCaretRangeFromPoint( document, x, y, container );
const testRange = hiddenCaretRangeFromPoint(
ownerDocument,
x,
y,
container
);

@@ -221,2 +221,3 @@ if ( ! testRange ) {

const { startContainer } = range;
const { ownerDocument } = startContainer;

@@ -230,3 +231,3 @@ // Correct invalid "BR" ranges. The cannot contain any children.

range = document.createRange();
range = ownerDocument.createRange();
range.setStart( parentNode, index );

@@ -244,3 +245,3 @@ range.setEnd( parentNode, index );

if ( ! rect ) {
const padNode = document.createTextNode( '\u200b' );
const padNode = ownerDocument.createTextNode( '\u200b' );
// Do not modify the live range.

@@ -259,6 +260,8 @@ range = range.cloneRange();

*
* @param {Window} win The window of the selection.
*
* @return {?DOMRect} The rectangle.
*/
export function computeCaretRect() {
const selection = window.getSelection();
export function computeCaretRect( win ) {
const selection = win.getSelection();
const range = selection.rangeCount ? selection.getRangeAt( 0 ) : null;

@@ -313,4 +316,6 @@

const selection = window.getSelection();
const range = document.createRange();
const { ownerDocument } = container;
const { defaultView } = ownerDocument;
const selection = defaultView.getSelection();
const range = ownerDocument.createRange();

@@ -330,5 +335,5 @@ range.selectNodeContents( rangeTarget );

*
* @param {Document} doc The document of the range.
* @param {number} x Horizontal position within the current viewport.
* @param {number} y Vertical position within the current viewport.
* @param {Document} doc The document of the range.
* @param {number} x Horizontal position within the current viewport.
* @param {number} y Vertical position within the current viewport.
*

@@ -426,3 +431,5 @@ * @return {?Range} The best range for the given point.

const range = hiddenCaretRangeFromPoint( document, x, y, container );
const { ownerDocument } = container;
const { defaultView } = ownerDocument;
const range = hiddenCaretRangeFromPoint( ownerDocument, x, y, container );

@@ -447,3 +454,3 @@ if ( ! range || ! container.contains( range.startContainer ) ) {

const selection = window.getSelection();
const selection = defaultView.getSelection();
selection.removeAllRanges();

@@ -510,6 +517,8 @@ selection.addRange( range );

*
* @param {Document} doc The document to check.
*
* @return {boolean} True if there is selection, false if not.
*/
export function documentHasTextSelection() {
const selection = window.getSelection();
export function documentHasTextSelection( doc ) {
const selection = doc.defaultView.getSelection();
const range = selection.rangeCount ? selection.getRangeAt( 0 ) : null;

@@ -558,8 +567,10 @@ return range && ! range.collapsed;

*
* @param {Document} doc The document to check.
*
* @return {boolean} Whether there is any sort of "selection" in the document.
*/
export function documentHasUncollapsedSelection() {
export function documentHasUncollapsedSelection( doc ) {
return (
documentHasTextSelection() ||
inputFieldHasUncollapsedSelection( document.activeElement )
documentHasTextSelection( doc ) ||
inputFieldHasUncollapsedSelection( doc.activeElement )
);

@@ -572,9 +583,11 @@ }

*
* @param {Document} doc The document to check.
*
* @return {boolean} True if there is selection, false if not.
*/
export function documentHasSelection() {
export function documentHasSelection( doc ) {
return (
isTextField( document.activeElement ) ||
isNumberInput( document.activeElement ) ||
documentHasTextSelection()
isTextField( doc.activeElement ) ||
isNumberInput( doc.activeElement ) ||
documentHasTextSelection( doc )
);

@@ -603,3 +616,5 @@ }

const selection = window.getSelection();
const { ownerDocument } = element;
const { defaultView } = ownerDocument;
const selection = defaultView.getSelection();
const range = selection.rangeCount ? selection.getRangeAt( 0 ) : null;

@@ -624,3 +639,3 @@

const lastChildContentLength =
lastChild.nodeType === TEXT_NODE
lastChild.nodeType === lastChild.TEXT_NODE
? lastChild.data.length

@@ -652,3 +667,3 @@ : lastChild.childNodes.length;

// ...except when overflow is defined to be hidden or visible
const { overflowY } = window.getComputedStyle( node );
const { overflowY } = getComputedStyle( node );
if ( /(auto|scroll)/.test( overflowY ) ) {

@@ -679,3 +694,3 @@ return node;

while ( ( closestElement = node.parentNode ) ) {
if ( closestElement.nodeType === ELEMENT_NODE ) {
if ( closestElement.nodeType === closestElement.ELEMENT_NODE ) {
break;

@@ -788,3 +803,6 @@ }

export function __unstableStripHTML( html ) {
const document = new DOMParser().parseFromString( html, 'text/html' );
const document = new window.DOMParser().parseFromString(
html,
'text/html'
);
return document.body.textContent || '';

@@ -812,3 +830,3 @@ }

) {
if ( node.nodeType === ELEMENT_NODE ) {
if ( node.nodeType === node.ELEMENT_NODE ) {
const {

@@ -961,7 +979,7 @@ attributes = [],

return Array.from( element.childNodes ).every( ( node ) => {
if ( node.nodeType === TEXT_NODE ) {
if ( node.nodeType === node.TEXT_NODE ) {
return ! node.nodeValue.trim();
}
if ( node.nodeType === ELEMENT_NODE ) {
if ( node.nodeType === node.ELEMENT_NODE ) {
if ( node.nodeName === 'BR' ) {

@@ -968,0 +986,0 @@ return true;

@@ -80,3 +80,5 @@ /**

const img = document.querySelector( 'img[usemap="#' + map.name + '"]' );
const img = element.ownerDocument.querySelector(
'img[usemap="#' + map.name + '"]'
);
return !! img && isVisible( img );

@@ -83,0 +85,0 @@ }

@@ -154,4 +154,4 @@ /**

*/
export function findPrevious( element = document.activeElement ) {
const focusables = findFocusable( document.body );
export function findPrevious( element ) {
const focusables = findFocusable( element.ownerDocument.body );
const index = focusables.indexOf( element );

@@ -171,4 +171,4 @@

*/
export function findNext( element = document.activeElement ) {
const focusables = findFocusable( document.body );
export function findNext( element ) {
const focusables = findFocusable( element.ownerDocument.body );
const index = focusables.indexOf( element );

@@ -175,0 +175,0 @@

@@ -25,3 +25,3 @@ /**

node &&
node.nodeType === window.Node.ELEMENT_NODE
node.nodeType === node.ELEMENT_NODE
);

@@ -28,0 +28,0 @@

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

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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc