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

@wordpress/dom

Package Overview
Dependencies
Maintainers
21
Versions
192
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.18.0 to 3.0.0

build-module/dom/is-rtl.js

17

build-module/data-transfer.js

@@ -9,12 +9,11 @@ /**

export function getFilesFromDataTransfer(dataTransfer) {
var files = Array.from(dataTransfer.files);
Array.from(dataTransfer.items).forEach(function (item) {
var file = item.getAsFile();
const files = Array.from(dataTransfer.files);
Array.from(dataTransfer.items).forEach(item => {
const file = item.getAsFile();
if (file && !files.find(function (_ref) {
var name = _ref.name,
type = _ref.type,
size = _ref.size;
return name === file.name && type === file.type && size === file.size;
})) {
if (file && !files.find(({
name,
type,
size
}) => name === file.name && type === file.type && size === file.size)) {
files.push(file);

@@ -21,0 +20,0 @@ }

@@ -22,3 +22,3 @@ /**

var point = doc.caretPositionFromPoint(x, y); // If x or y are negative, outside viewport, or there is no text entry node.
const point = doc.caretPositionFromPoint(x, y); // If x or y are negative, outside viewport, or there is no text entry node.
// https://developer.mozilla.org/en-US/docs/Web/API/Document/caretRangeFromPoint

@@ -30,3 +30,3 @@

var range = doc.createRange();
const range = doc.createRange();
range.setStart(point.offsetNode, point.offset);

@@ -33,0 +33,0 @@ range.collapse(true);

@@ -42,8 +42,8 @@ /**

export default function cleanNodeList(nodeList, doc, schema, inline) {
Array.from(nodeList).forEach(function (
Array.from(nodeList).forEach(
/** @type {Node & { nextElementSibling?: unknown }} */
node) {
node => {
var _schema$tag$isMatch, _schema$tag;
var tag = node.nodeName.toLowerCase(); // It's a valid child, if the tag exists in the schema without an isMatch
const tag = node.nodeName.toLowerCase(); // It's a valid child, if the tag exists in the schema without an isMatch
// function, or with an isMatch function that matches the node.

@@ -53,14 +53,11 @@

if (isElement(node)) {
var _schema$tag2 = schema[tag],
_schema$tag2$attribut = _schema$tag2.attributes,
attributes = _schema$tag2$attribut === void 0 ? [] : _schema$tag2$attribut,
_schema$tag2$classes = _schema$tag2.classes,
classes = _schema$tag2$classes === void 0 ? [] : _schema$tag2$classes,
children = _schema$tag2.children,
_schema$tag2$require = _schema$tag2.require,
require = _schema$tag2$require === void 0 ? [] : _schema$tag2$require,
allowEmpty = _schema$tag2.allowEmpty; // If the node is empty and it's supposed to have children,
const {
attributes = [],
classes = [],
children,
require = [],
allowEmpty
} = schema[tag]; // If the node is empty and it's supposed to have children,
// remove the node.
if (children && !allowEmpty && isEmpty(node)) {

@@ -73,5 +70,5 @@ remove(node);

// Strip invalid attributes.
Array.from(node.attributes).forEach(function (_ref) {
var name = _ref.name;
Array.from(node.attributes).forEach(({
name
}) => {
if (name !== 'class' && !includes(attributes, name)) {

@@ -85,15 +82,13 @@ node.removeAttribute(name);

if (node.classList && node.classList.length) {
var mattchers = classes.map(function (item) {
const mattchers = classes.map(item => {
if (typeof item === 'string') {
return function (
/** @type {string} */
className) {
return className === item;
};
return (
/** @type {string} */
className => className === item
);
} else if (item instanceof RegExp) {
return function (
/** @type {string} */
className) {
return item.test(className);
};
return (
/** @type {string} */
className => item.test(className)
);
}

@@ -103,6 +98,4 @@

});
Array.from(node.classList).forEach(function (name) {
if (!mattchers.some(function (isMatch) {
return isMatch(name);
})) {
Array.from(node.classList).forEach(name => {
if (!mattchers.some(isMatch => isMatch(name))) {
node.classList.remove(name);

@@ -136,5 +129,3 @@ }

if (Array.from(node.childNodes).some(function (child) {
return !isPhrasingContent(child);
})) {
if (Array.from(node.childNodes).some(child => !isPhrasingContent(child))) {
unwrap(node);

@@ -141,0 +132,0 @@ }

@@ -15,5 +15,5 @@ /**

export default function computeCaretRect(win) {
var selection = win.getSelection();
const selection = win.getSelection();
assertIsDefined(selection, 'selection');
var range = selection.rangeCount ? selection.getRangeAt(0) : null;
const range = selection.rangeCount ? selection.getRangeAt(0) : null;

@@ -20,0 +20,0 @@ if (!range) {

@@ -19,7 +19,7 @@ /**

assertIsDefined(doc.defaultView, 'doc.defaultView');
var selection = doc.defaultView.getSelection();
const selection = doc.defaultView.getSelection();
assertIsDefined(selection, 'selection');
var range = selection.rangeCount ? selection.getRangeAt(0) : null;
const range = selection.rangeCount ? selection.getRangeAt(0) : null;
return !!range && !range.collapsed;
}
//# sourceMappingURL=document-has-text-selection.js.map

@@ -20,3 +20,3 @@ /**

// an element node, so find the closest element node.
var closestElement;
let closestElement;

@@ -23,0 +23,0 @@ while (closestElement =

@@ -1,3 +0,1 @@

import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
/**

@@ -11,3 +9,3 @@ * Gets the height of the range without ignoring zero width rectangles, which

export default function getRangeHeight(range) {
var rects = Array.from(range.getClientRects());
const rects = Array.from(range.getClientRects());

@@ -18,12 +16,10 @@ if (!rects.length) {

var highestTop = Math.min.apply(Math, _toConsumableArray(rects.map(function (_ref) {
var top = _ref.top;
return top;
})));
var lowestBottom = Math.max.apply(Math, _toConsumableArray(rects.map(function (_ref2) {
var bottom = _ref2.bottom;
return bottom;
})));
const highestTop = Math.min(...rects.map(({
top
}) => top));
const lowestBottom = Math.max(...rects.map(({
bottom
}) => bottom));
return lowestBottom - highestTop;
}
//# sourceMappingURL=get-range-height.js.map

@@ -18,13 +18,56 @@ /**

if (!range.collapsed) {
return range.getBoundingClientRect();
const rects = Array.from(range.getClientRects()); // If there's just a single rect, return it.
if (rects.length === 1) {
return rects[0];
} // Ignore tiny selection at the edge of a range.
const filteredRects = rects.filter(({
width
}) => width > 1); // If it's full of tiny selections, return browser default.
if (filteredRects.length === 0) {
return range.getBoundingClientRect();
}
if (filteredRects.length === 1) {
return filteredRects[0];
}
let {
top: furthestTop,
bottom: furthestBottom,
left: furthestLeft,
right: furthestRight
} = filteredRects[0];
for (const {
top,
bottom,
left,
right
} of filteredRects) {
if (top < furthestTop) furthestTop = top;
if (bottom > furthestBottom) furthestBottom = bottom;
if (left < furthestLeft) furthestLeft = left;
if (right > furthestRight) furthestRight = right;
}
return new window.DOMRect(furthestLeft, furthestTop, furthestRight - furthestLeft, furthestBottom - furthestTop);
}
var _range = range,
startContainer = _range.startContainer;
var ownerDocument = startContainer.ownerDocument; // Correct invalid "BR" ranges. The cannot contain any children.
const {
startContainer
} = range;
const {
ownerDocument
} = startContainer; // Correct invalid "BR" ranges. The cannot contain any children.
if (startContainer.nodeName === 'BR') {
var parentNode = startContainer.parentNode;
const {
parentNode
} = startContainer;
assertIsDefined(parentNode, 'parentNode');
var index =
const index =
/** @type {Node[]} */

@@ -38,3 +81,3 @@ Array.from(parentNode.childNodes).indexOf(startContainer);

var rect = range.getClientRects()[0]; // If the collapsed range starts (and therefore ends) at an element node,
let rect = range.getClientRects()[0]; // If the collapsed range starts (and therefore ends) at an element node,
// `getClientRects` can be empty in some browsers. This can be resolved

@@ -47,3 +90,3 @@ // by adding a temporary text node with zero-width space to the range.

assertIsDefined(ownerDocument, 'ownerDocument');
var padNode = ownerDocument.createTextNode("\u200B"); // Do not modify the live range.
const padNode = ownerDocument.createTextNode('\u200b'); // Do not modify the live range.

@@ -50,0 +93,0 @@ range = range.cloneRange();

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

// ...except when overflow is defined to be hidden or visible
var _getComputedStyle = getComputedStyle(node),
overflowY = _getComputedStyle.overflowY;
const {
overflowY
} = getComputedStyle(node);

@@ -25,0 +26,0 @@ if (/(auto|scroll)/.test(overflowY)) {

@@ -20,10 +20,8 @@ /**

export default function hiddenCaretRangeFromPoint(doc, x, y, container) {
var originalZIndex = container.style.zIndex;
var originalPosition = container.style.position;
const originalZIndex = container.style.zIndex;
const originalPosition = container.style.position;
const {
position = 'static'
} = getComputedStyle(container); // A z-index only works if the element position is not static.
var _getComputedStyle = getComputedStyle(container),
_getComputedStyle$pos = _getComputedStyle.position,
position = _getComputedStyle$pos === void 0 ? 'static' : _getComputedStyle$pos; // A z-index only works if the element position is not static.
if (position === 'static') {

@@ -34,3 +32,3 @@ container.style.position = 'relative';

container.style.zIndex = '10000';
var range = caretRangeFromPoint(doc, x, y);
const range = caretRangeFromPoint(doc, x, y);
container.style.zIndex = originalZIndex;

@@ -37,0 +35,0 @@ container.style.position = originalPosition;

@@ -24,2 +24,3 @@ export { default as computeCaretRect } from './compute-caret-rect';

export { default as removeInvalidHTML } from './remove-invalid-html';
export { default as isRTL } from './is-rtl';
//# sourceMappingURL=index.js.map

@@ -26,6 +26,8 @@ /**

try {
var selectionStart =
const {
selectionStart,
selectionEnd
} =
/** @type {HTMLInputElement | HTMLTextAreaElement} */
element.selectionStart,
selectionEnd = element.selectionEnd;
element;
return selectionStart !== null && selectionStart !== selectionEnd;

@@ -32,0 +34,0 @@ } catch (error) {

/**
* Internal dependencies
*/
import getComputedStyle from './get-computed-style';
import isRTL from './is-rtl';
import getRangeHeight from './get-range-height';

@@ -23,5 +23,3 @@ import getRectangleFromRange from './get-rectangle-from-range';

export default function isEdge(container, isReverse) {
var onlyVertical = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
export default function isEdge(container, isReverse, onlyVertical = false) {
if (isInputOrTextArea(container)) {

@@ -45,6 +43,10 @@ if (container.selectionStart !== container.selectionEnd) {

var ownerDocument = container.ownerDocument;
var defaultView = ownerDocument.defaultView;
const {
ownerDocument
} = container;
const {
defaultView
} = ownerDocument;
assertIsDefined(defaultView, 'defaultView');
var selection = defaultView.getSelection();
const selection = defaultView.getSelection();

@@ -55,6 +57,6 @@ if (!selection || !selection.rangeCount) {

var range = selection.getRangeAt(0);
var collapsedRange = range.cloneRange();
var isForward = isSelectionForward(selection);
var isCollapsed = selection.isCollapsed; // Collapse in direction of selection.
const range = selection.getRangeAt(0);
const collapsedRange = range.cloneRange();
const isForward = isSelectionForward(selection);
const isCollapsed = selection.isCollapsed; // Collapse in direction of selection.

@@ -65,4 +67,4 @@ if (!isCollapsed) {

var collapsedRangeRect = getRectangleFromRange(collapsedRange);
var rangeRect = getRectangleFromRange(range);
const collapsedRangeRect = getRectangleFromRange(collapsedRange);
const rangeRect = getRectangleFromRange(range);

@@ -76,3 +78,3 @@ if (!collapsedRangeRect || !rangeRect) {

var rangeHeight = getRangeHeight(range);
const rangeHeight = getRangeHeight(range);

@@ -84,7 +86,4 @@ if (!isCollapsed && rangeHeight && rangeHeight > collapsedRangeRect.height && isForward === isReverse) {

var _getComputedStyle = getComputedStyle(container),
direction = _getComputedStyle.direction;
var isReverseDir = direction === 'rtl' ? !isReverse : isReverse;
var containerRect = container.getBoundingClientRect(); // To check if a selection is at the edge, we insert a test selection at the
const isReverseDir = isRTL(container) ? !isReverse : isReverse;
const containerRect = container.getBoundingClientRect(); // To check if a selection is at the edge, we insert a test selection at the
// edge of the container and check if the selections have the same vertical

@@ -100,5 +99,5 @@ // or horizontal position. If they do, the selection is at the edge.

var x = isReverseDir ? containerRect.left + 1 : containerRect.right - 1;
var y = isReverse ? containerRect.top + 1 : containerRect.bottom - 1;
var testRange = hiddenCaretRangeFromPoint(ownerDocument, x, y,
const x = isReverseDir ? containerRect.left + 1 : containerRect.right - 1;
const y = isReverse ? containerRect.top + 1 : containerRect.bottom - 1;
const testRange = hiddenCaretRangeFromPoint(ownerDocument, x, y,
/** @type {HTMLElement} */

@@ -111,3 +110,3 @@ container);

var testRect = getRectangleFromRange(testRange);
const testRect = getRectangleFromRange(testRange);

@@ -118,11 +117,11 @@ if (!testRect) {

var verticalSide = isReverse ? 'top' : 'bottom';
var horizontalSide = isReverseDir ? 'left' : 'right';
var verticalDiff = testRect[verticalSide] - rangeRect[verticalSide];
var horizontalDiff = testRect[horizontalSide] - collapsedRangeRect[horizontalSide]; // Allow the position to be 1px off.
const verticalSide = isReverse ? 'top' : 'bottom';
const horizontalSide = isReverseDir ? 'left' : 'right';
const verticalDiff = testRect[verticalSide] - rangeRect[verticalSide];
const horizontalDiff = testRect[horizontalSide] - collapsedRangeRect[horizontalSide]; // Allow the position to be 1px off.
var hasVerticalDiff = Math.abs(verticalDiff) <= 1;
var hasHorizontalDiff = Math.abs(horizontalDiff) <= 1;
const hasVerticalDiff = Math.abs(verticalDiff) <= 1;
const hasHorizontalDiff = Math.abs(horizontalDiff) <= 1;
return onlyVertical ? hasVerticalDiff : hasVerticalDiff && hasHorizontalDiff;
}
//# sourceMappingURL=is-edge.js.map

@@ -24,8 +24,12 @@ /**

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

@@ -36,6 +40,8 @@ if (!range) {

var startContainer = range.startContainer,
endContainer = range.endContainer,
startOffset = range.startOffset,
endOffset = range.endOffset;
const {
startContainer,
endContainer,
startOffset,
endOffset
} = range;

@@ -46,5 +52,5 @@ if (startContainer === element && endContainer === element && startOffset === 0 && endOffset === element.childNodes.length) {

var lastChild = element.lastChild;
const lastChild = element.lastChild;
assertIsDefined(lastChild, 'lastChild');
var lastChildContentLength = lastChild.nodeType === lastChild.TEXT_NODE ?
const lastChildContentLength = lastChild.nodeType === lastChild.TEXT_NODE ?
/** @type {Text} */

@@ -51,0 +57,0 @@ lastChild.data.length : lastChild.childNodes.length;

@@ -17,9 +17,11 @@ /**

export default function isSelectionForward(selection) {
var anchorNode = selection.anchorNode,
focusNode = selection.focusNode,
anchorOffset = selection.anchorOffset,
focusOffset = selection.focusOffset;
const {
anchorNode,
focusNode,
anchorOffset,
focusOffset
} = selection;
assertIsDefined(anchorNode, 'anchorNode');
assertIsDefined(focusNode, 'focusNode');
var position = anchorNode.compareDocumentPosition(focusNode); // Disable reason: `Node#compareDocumentPosition` returns a bitmask value,
const position = anchorNode.compareDocumentPosition(focusNode); // Disable reason: `Node#compareDocumentPosition` returns a bitmask value,
// so bitwise operators are intended.

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

@@ -19,3 +19,3 @@ /**

/* eslint-enable jsdoc/valid-types */
var nonTextInputs = ['button', 'checkbox', 'hidden', 'file', 'radio', 'image', 'range', 'reset', 'submit', 'number'];
const nonTextInputs = ['button', 'checkbox', 'hidden', 'file', 'radio', 'image', 'range', 'reset', 'submit', 'number'];
return isHTMLInputElement(node) && node.type && !nonTextInputs.includes(node.type) || node.nodeName === 'TEXTAREA' ||

@@ -22,0 +22,0 @@ /** @type {HTMLElement} */

@@ -11,2 +11,3 @@ /**

import isInputOrTextArea from './is-input-or-text-area';
import isRTL from './is-rtl';
/**

@@ -20,5 +21,3 @@ * Places the caret at start or end of a given element.

export default function placeCaretAtHorizontalEdge(container, isReverse) {
var mayUseScroll = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
export default function placeCaretAtHorizontalEdge(container, isReverse, mayUseScroll = false) {
if (!container) {

@@ -51,9 +50,13 @@ return;

var ownerDocument = container.ownerDocument;
var containerRect = container.getBoundingClientRect(); // When placing at the end (isReverse), find the closest range to the bottom
const {
ownerDocument
} = container; // In the case of RTL scripts, the horizontal edge is at the opposite side.
const isReverseDir = isRTL(container) ? !isReverse : isReverse;
const containerRect = container.getBoundingClientRect(); // When placing at the end (isReverse), find the closest range to the bottom
// right corner. When placing at the start, to the top left corner.
var x = isReverse ? containerRect.right - 1 : containerRect.left + 1;
var y = isReverse ? containerRect.bottom - 1 : containerRect.top + 1;
var range = hiddenCaretRangeFromPoint(ownerDocument, x, y, container); // If no range range can be created or it is outside the container, the
const x = isReverse ? containerRect.right - 1 : containerRect.left + 1;
const y = isReverseDir ? containerRect.bottom - 1 : containerRect.top + 1;
const range = hiddenCaretRangeFromPoint(ownerDocument, x, y, container); // If no range range can be created or it is outside the container, the
// element may be out of view.

@@ -73,5 +76,7 @@

var defaultView = ownerDocument.defaultView;
const {
defaultView
} = ownerDocument;
assertIsDefined(defaultView, 'defaultView');
var selection = defaultView.getSelection();
const selection = defaultView.getSelection();
assertIsDefined(selection, 'selection');

@@ -78,0 +83,0 @@ selection.removeAllRanges();

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

export default function placeCaretAtVerticalEdge(container, isReverse, rect) {
var mayUseScroll = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
export default function placeCaretAtVerticalEdge(container, isReverse, rect, mayUseScroll = true) {
if (!container) {

@@ -35,9 +33,13 @@ return;

var buffer = rect.height / 2;
var editableRect = container.getBoundingClientRect();
var x = rect.left;
var y = isReverse ? editableRect.bottom - buffer : editableRect.top + buffer;
var ownerDocument = container.ownerDocument;
var defaultView = ownerDocument.defaultView;
var range = hiddenCaretRangeFromPoint(ownerDocument, x, y, container);
const buffer = rect.height / 2;
const editableRect = container.getBoundingClientRect();
const x = rect.left;
const y = isReverse ? editableRect.bottom - buffer : editableRect.top + buffer;
const {
ownerDocument
} = container;
const {
defaultView
} = ownerDocument;
const range = hiddenCaretRangeFromPoint(ownerDocument, x, y, container);

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

assertIsDefined(defaultView, 'defaultView');
var selection = defaultView.getSelection();
const selection = defaultView.getSelection();
assertIsDefined(selection, 'selection');

@@ -61,0 +63,0 @@ selection.removeAllRanges();

@@ -16,3 +16,3 @@ /**

export default function removeInvalidHTML(HTML, schema, inline) {
var doc = document.implementation.createHTMLDocument('');
const doc = document.implementation.createHTMLDocument('');
doc.body.innerHTML = HTML;

@@ -19,0 +19,0 @@ cleanNodeList(doc.body.childNodes, doc, schema, inline);

@@ -15,3 +15,3 @@ /**

export default function replaceTag(node, tagName) {
var newNode = node.ownerDocument.createElement(tagName);
const newNode = node.ownerDocument.createElement(tagName);

@@ -18,0 +18,0 @@ while (node.firstChild) {

@@ -9,5 +9,5 @@ /**

export default function stripHTML(html) {
var document = new window.DOMParser().parseFromString(html, 'text/html');
const document = new window.DOMParser().parseFromString(html, 'text/html');
return document.body.textContent || '';
}
//# sourceMappingURL=strip-html.js.map

@@ -14,3 +14,3 @@ /**

export default function unwrap(node) {
var parent = node.parentNode;
const parent = node.parentNode;
assertIsDefined(parent, 'node.parentNode');

@@ -17,0 +17,0 @@

@@ -19,3 +19,3 @@ /**

*/
var SELECTOR = ['[tabindex]', 'a[href]', 'button:not([disabled])', 'input:not([type="hidden"]):not([disabled])', 'select:not([disabled])', 'textarea:not([disabled])', 'iframe', 'object', 'embed', 'area[href]', '[contenteditable]:not([contenteditable=false])'].join(',');
const SELECTOR = ['[tabindex]', 'a[href]', 'button:not([disabled])', 'input:not([type="hidden"]):not([disabled])', 'select:not([disabled])', 'textarea:not([disabled])', 'iframe', 'object', 'embed', 'area[href]', '[contenteditable]:not([contenteditable=false])'].join(',');
/**

@@ -59,3 +59,3 @@ * Returns true if the specified element is visible (i.e. neither display: none

/** @type {HTMLMapElement | null} */
var map = element.closest('map[name]');
const map = element.closest('map[name]');

@@ -68,3 +68,3 @@ if (!map) {

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

@@ -87,4 +87,4 @@ }

/* eslint-enable jsdoc/no-undefined-types */
var elements = context.querySelectorAll(SELECTOR);
return Array.from(elements).filter(function (element) {
const elements = context.querySelectorAll(SELECTOR);
return Array.from(elements).filter(element => {
if (!isVisible(element) || skipFocus(element)) {

@@ -94,3 +94,5 @@ return false;

var nodeName = element.nodeName;
const {
nodeName
} = element;

@@ -97,0 +99,0 @@ if ('AREA' === nodeName) {

@@ -11,5 +11,5 @@ /**

export var focus = {
focusable: focusable,
tabbable: tabbable
export const focus = {
focusable,
tabbable
};

@@ -16,0 +16,0 @@ export * from './dom';

@@ -1,7 +0,1 @@

import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
/**

@@ -35,3 +29,3 @@ * External dependencies

var textContentSchema = {
const textContentSchema = {
strong: {},

@@ -89,3 +83,3 @@ em: {},

without(Object.keys(textContentSchema), '#text', 'br').forEach(function (tag) {
without(Object.keys(textContentSchema), '#text', 'br').forEach(tag => {
textContentSchema[tag].children = omit(textContentSchema, tag);

@@ -101,3 +95,3 @@ });

var embeddedContentSchema = {
const embeddedContentSchema = {
audio: {

@@ -128,3 +122,5 @@ attributes: ['src', 'preload', 'autoplay', 'mediagroup', 'loop', 'muted']

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

@@ -141,3 +137,2 @@ * Get schema of possible paths for phrasing content.

export function getPhrasingContentSchema(context) {

@@ -148,3 +143,3 @@ if (context !== 'paste') {

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

@@ -158,3 +153,3 @@ // visible to the user when pasted, so strip the attributes.

}
}), ['u', // Used to mark misspelling. Shouldn't be pasted.
}, ['u', // Used to mark misspelling. Shouldn't be pasted.
'abbr', // Invisible.

@@ -179,3 +174,3 @@ 'data', // Invisible.

export function isPhrasingContent(node) {
var tag = node.nodeName.toLowerCase();
const tag = node.nodeName.toLowerCase();
return getPhrasingContentSchema().hasOwnProperty(tag) || tag === 'span';

@@ -189,5 +184,5 @@ }

export function isTextContent(node) {
var tag = node.nodeName.toLowerCase();
const tag = node.nodeName.toLowerCase();
return textContentSchema.hasOwnProperty(tag) || tag === 'span';
}
//# sourceMappingURL=phrasing-content.js.map

@@ -24,3 +24,3 @@ /**

function getTabIndex(element) {
var tabIndex = element.getAttribute('tabindex');
const tabIndex = element.getAttribute('tabindex');
return tabIndex === null ? 0 : parseInt(tabIndex, 10);

@@ -53,3 +53,3 @@ }

/** @type {Record<string, MaybeHTMLInputElement>} */
var CHOSEN_RADIO_BY_NAME = {};
const CHOSEN_RADIO_BY_NAME = {};
return function collapseRadioGroup(

@@ -60,6 +60,8 @@ /** @type {MaybeHTMLInputElement[]} */

element) {
var nodeName = element.nodeName,
type = element.type,
checked = element.checked,
name = element.name; // For all non-radio tabbables, construct to array by concatenating.
const {
nodeName,
type,
checked,
name
} = element; // For all non-radio tabbables, construct to array by concatenating.

@@ -70,5 +72,5 @@ if (nodeName !== 'INPUT' || type !== 'radio' || !name) {

var hasChosen = CHOSEN_RADIO_BY_NAME.hasOwnProperty(name); // Omit by skipping concatenation if the radio element is not chosen.
const hasChosen = CHOSEN_RADIO_BY_NAME.hasOwnProperty(name); // Omit by skipping concatenation if the radio element is not chosen.
var isChosen = checked || !hasChosen;
const isChosen = checked || !hasChosen;

@@ -83,3 +85,3 @@ if (!isChosen) {

if (hasChosen) {
var hadChosenElement = CHOSEN_RADIO_BY_NAME[name];
const hadChosenElement = CHOSEN_RADIO_BY_NAME[name];
result = without(result, hadChosenElement);

@@ -107,4 +109,4 @@ }

return {
element: element,
index: index
element,
index
};

@@ -138,4 +140,4 @@ }

function compareObjectTabbables(a, b) {
var aTabIndex = getTabIndex(a.element);
var bTabIndex = getTabIndex(b.element);
const aTabIndex = getTabIndex(a.element);
const bTabIndex = getTabIndex(b.element);

@@ -177,4 +179,4 @@ if (aTabIndex === bTabIndex) {

export function findPrevious(element) {
var focusables = findFocusable(element.ownerDocument.body);
var index = focusables.indexOf(element); // Remove all focusables after and including `element`.
const focusables = findFocusable(element.ownerDocument.body);
const index = focusables.indexOf(element); // Remove all focusables after and including `element`.

@@ -192,10 +194,8 @@ focusables.length = index;

export function findNext(element) {
var focusables = findFocusable(element.ownerDocument.body);
var index = focusables.indexOf(element); // Remove all focusables before and inside `element`.
const focusables = findFocusable(element.ownerDocument.body);
const index = focusables.indexOf(element); // Remove all focusables before and inside `element`.
var remaining = focusables.slice(index + 1).filter(function (node) {
return !element.contains(node);
});
const remaining = focusables.slice(index + 1).filter(node => !element.contains(node));
return first(filterTabbable(remaining));
}
//# sourceMappingURL=tabbable.js.map
export function assertIsDefined(val, name) {
if (process.env.NODE_ENV !== 'production' && (val === undefined || val === null)) {
throw new Error("Expected '".concat(name, "' to be defined, but received ").concat(val));
throw new Error(`Expected '${name}' to be defined, but received ${val}`);
}
}
//# sourceMappingURL=assert-is-defined.js.map

@@ -24,2 +24,3 @@ export { default as computeCaretRect } from "./compute-caret-rect";

export { default as removeInvalidHTML } from "./remove-invalid-html";
export { default as isRTL } from "./is-rtl";
//# sourceMappingURL=index.d.ts.map

@@ -16,12 +16,11 @@ "use strict";

function getFilesFromDataTransfer(dataTransfer) {
var files = Array.from(dataTransfer.files);
Array.from(dataTransfer.items).forEach(function (item) {
var file = item.getAsFile();
const files = Array.from(dataTransfer.files);
Array.from(dataTransfer.items).forEach(item => {
const file = item.getAsFile();
if (file && !files.find(function (_ref) {
var name = _ref.name,
type = _ref.type,
size = _ref.size;
return name === file.name && type === file.type && size === file.size;
})) {
if (file && !files.find(({
name,
type,
size
}) => name === file.name && type === file.type && size === file.size)) {
files.push(file);

@@ -28,0 +27,0 @@ }

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

var point = doc.caretPositionFromPoint(x, y); // If x or y are negative, outside viewport, or there is no text entry node.
const point = doc.caretPositionFromPoint(x, y); // If x or y are negative, outside viewport, or there is no text entry node.
// https://developer.mozilla.org/en-US/docs/Web/API/Document/caretRangeFromPoint

@@ -37,3 +37,3 @@

var range = doc.createRange();
const range = doc.createRange();
range.setStart(point.offsetNode, point.offset);

@@ -40,0 +40,0 @@ range.collapse(true);

@@ -58,8 +58,8 @@ "use strict";

function cleanNodeList(nodeList, doc, schema, inline) {
Array.from(nodeList).forEach(function (
Array.from(nodeList).forEach(
/** @type {Node & { nextElementSibling?: unknown }} */
node) {
node => {
var _schema$tag$isMatch, _schema$tag;
var tag = node.nodeName.toLowerCase(); // It's a valid child, if the tag exists in the schema without an isMatch
const tag = node.nodeName.toLowerCase(); // It's a valid child, if the tag exists in the schema without an isMatch
// function, or with an isMatch function that matches the node.

@@ -69,14 +69,11 @@

if ((0, _isElement.default)(node)) {
var _schema$tag2 = schema[tag],
_schema$tag2$attribut = _schema$tag2.attributes,
attributes = _schema$tag2$attribut === void 0 ? [] : _schema$tag2$attribut,
_schema$tag2$classes = _schema$tag2.classes,
classes = _schema$tag2$classes === void 0 ? [] : _schema$tag2$classes,
children = _schema$tag2.children,
_schema$tag2$require = _schema$tag2.require,
require = _schema$tag2$require === void 0 ? [] : _schema$tag2$require,
allowEmpty = _schema$tag2.allowEmpty; // If the node is empty and it's supposed to have children,
const {
attributes = [],
classes = [],
children,
require = [],
allowEmpty
} = schema[tag]; // If the node is empty and it's supposed to have children,
// remove the node.
if (children && !allowEmpty && (0, _isEmpty.default)(node)) {

@@ -89,5 +86,5 @@ (0, _remove.default)(node);

// Strip invalid attributes.
Array.from(node.attributes).forEach(function (_ref) {
var name = _ref.name;
Array.from(node.attributes).forEach(({
name
}) => {
if (name !== 'class' && !(0, _lodash.includes)(attributes, name)) {

@@ -101,15 +98,13 @@ node.removeAttribute(name);

if (node.classList && node.classList.length) {
var mattchers = classes.map(function (item) {
const mattchers = classes.map(item => {
if (typeof item === 'string') {
return function (
/** @type {string} */
className) {
return className === item;
};
return (
/** @type {string} */
className => className === item
);
} else if (item instanceof RegExp) {
return function (
/** @type {string} */
className) {
return item.test(className);
};
return (
/** @type {string} */
className => item.test(className)
);
}

@@ -119,6 +114,4 @@

});
Array.from(node.classList).forEach(function (name) {
if (!mattchers.some(function (isMatch) {
return isMatch(name);
})) {
Array.from(node.classList).forEach(name => {
if (!mattchers.some(isMatch => isMatch(name))) {
node.classList.remove(name);

@@ -152,5 +145,3 @@ }

if (Array.from(node.childNodes).some(function (child) {
return !(0, _phrasingContent.isPhrasingContent)(child);
})) {
if (Array.from(node.childNodes).some(child => !(0, _phrasingContent.isPhrasingContent)(child))) {
(0, _unwrap.default)(node);

@@ -157,0 +148,0 @@ }

@@ -26,5 +26,5 @@ "use strict";

function computeCaretRect(win) {
var selection = win.getSelection();
const selection = win.getSelection();
(0, _assertIsDefined.assertIsDefined)(selection, 'selection');
var range = selection.rangeCount ? selection.getRangeAt(0) : null;
const range = selection.rangeCount ? selection.getRangeAt(0) : null;

@@ -31,0 +31,0 @@ if (!range) {

@@ -27,7 +27,7 @@ "use strict";

(0, _assertIsDefined.assertIsDefined)(doc.defaultView, 'doc.defaultView');
var selection = doc.defaultView.getSelection();
const selection = doc.defaultView.getSelection();
(0, _assertIsDefined.assertIsDefined)(selection, 'selection');
var range = selection.rangeCount ? selection.getRangeAt(0) : null;
const range = selection.rangeCount ? selection.getRangeAt(0) : null;
return !!range && !range.collapsed;
}
//# sourceMappingURL=document-has-text-selection.js.map

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

// an element node, so find the closest element node.
var closestElement;
let closestElement;

@@ -33,0 +33,0 @@ while (closestElement =

"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {

@@ -10,4 +8,2 @@ value: true

var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
/**

@@ -21,3 +17,3 @@ * Gets the height of the range without ignoring zero width rectangles, which

function getRangeHeight(range) {
var rects = Array.from(range.getClientRects());
const rects = Array.from(range.getClientRects());

@@ -28,12 +24,10 @@ if (!rects.length) {

var highestTop = Math.min.apply(Math, (0, _toConsumableArray2.default)(rects.map(function (_ref) {
var top = _ref.top;
return top;
})));
var lowestBottom = Math.max.apply(Math, (0, _toConsumableArray2.default)(rects.map(function (_ref2) {
var bottom = _ref2.bottom;
return bottom;
})));
const highestTop = Math.min(...rects.map(({
top
}) => top));
const lowestBottom = Math.max(...rects.map(({
bottom
}) => bottom));
return lowestBottom - highestTop;
}
//# sourceMappingURL=get-range-height.js.map

@@ -26,13 +26,56 @@ "use strict";

if (!range.collapsed) {
return range.getBoundingClientRect();
const rects = Array.from(range.getClientRects()); // If there's just a single rect, return it.
if (rects.length === 1) {
return rects[0];
} // Ignore tiny selection at the edge of a range.
const filteredRects = rects.filter(({
width
}) => width > 1); // If it's full of tiny selections, return browser default.
if (filteredRects.length === 0) {
return range.getBoundingClientRect();
}
if (filteredRects.length === 1) {
return filteredRects[0];
}
let {
top: furthestTop,
bottom: furthestBottom,
left: furthestLeft,
right: furthestRight
} = filteredRects[0];
for (const {
top,
bottom,
left,
right
} of filteredRects) {
if (top < furthestTop) furthestTop = top;
if (bottom > furthestBottom) furthestBottom = bottom;
if (left < furthestLeft) furthestLeft = left;
if (right > furthestRight) furthestRight = right;
}
return new window.DOMRect(furthestLeft, furthestTop, furthestRight - furthestLeft, furthestBottom - furthestTop);
}
var _range = range,
startContainer = _range.startContainer;
var ownerDocument = startContainer.ownerDocument; // Correct invalid "BR" ranges. The cannot contain any children.
const {
startContainer
} = range;
const {
ownerDocument
} = startContainer; // Correct invalid "BR" ranges. The cannot contain any children.
if (startContainer.nodeName === 'BR') {
var parentNode = startContainer.parentNode;
const {
parentNode
} = startContainer;
(0, _assertIsDefined.assertIsDefined)(parentNode, 'parentNode');
var index =
const index =
/** @type {Node[]} */

@@ -46,3 +89,3 @@ Array.from(parentNode.childNodes).indexOf(startContainer);

var rect = range.getClientRects()[0]; // If the collapsed range starts (and therefore ends) at an element node,
let rect = range.getClientRects()[0]; // If the collapsed range starts (and therefore ends) at an element node,
// `getClientRects` can be empty in some browsers. This can be resolved

@@ -55,3 +98,3 @@ // by adding a temporary text node with zero-width space to the range.

(0, _assertIsDefined.assertIsDefined)(ownerDocument, 'ownerDocument');
var padNode = ownerDocument.createTextNode("\u200B"); // Do not modify the live range.
const padNode = ownerDocument.createTextNode('\u200b'); // Do not modify the live range.

@@ -58,0 +101,0 @@ range = range.cloneRange();

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

var _getComputedStyle2 = _interopRequireDefault(require("./get-computed-style"));
var _getComputedStyle = _interopRequireDefault(require("./get-computed-style"));

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

// ...except when overflow is defined to be hidden or visible
var _getComputedStyle = (0, _getComputedStyle2.default)(node),
overflowY = _getComputedStyle.overflowY;
const {
overflowY
} = (0, _getComputedStyle.default)(node);

@@ -36,0 +37,0 @@ if (/(auto|scroll)/.test(overflowY)) {

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

var _getComputedStyle2 = _interopRequireDefault(require("./get-computed-style"));
var _getComputedStyle = _interopRequireDefault(require("./get-computed-style"));

@@ -32,10 +32,8 @@ /**

function hiddenCaretRangeFromPoint(doc, x, y, container) {
var originalZIndex = container.style.zIndex;
var originalPosition = container.style.position;
const originalZIndex = container.style.zIndex;
const originalPosition = container.style.position;
const {
position = 'static'
} = (0, _getComputedStyle.default)(container); // A z-index only works if the element position is not static.
var _getComputedStyle = (0, _getComputedStyle2.default)(container),
_getComputedStyle$pos = _getComputedStyle.position,
position = _getComputedStyle$pos === void 0 ? 'static' : _getComputedStyle$pos; // A z-index only works if the element position is not static.
if (position === 'static') {

@@ -46,3 +44,3 @@ container.style.position = 'relative';

container.style.zIndex = '10000';
var range = (0, _caretRangeFromPoint.default)(doc, x, y);
const range = (0, _caretRangeFromPoint.default)(doc, x, y);
container.style.zIndex = originalZIndex;

@@ -49,0 +47,0 @@ container.style.position = originalPosition;

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

enumerable: true,
get: function get() {
get: function () {
return _computeCaretRect.default;

@@ -17,3 +17,3 @@ }

enumerable: true,
get: function get() {
get: function () {
return _documentHasTextSelection.default;

@@ -24,3 +24,3 @@ }

enumerable: true,
get: function get() {
get: function () {
return _documentHasUncollapsedSelection.default;

@@ -31,3 +31,3 @@ }

enumerable: true,
get: function get() {
get: function () {
return _documentHasSelection.default;

@@ -38,3 +38,3 @@ }

enumerable: true,
get: function get() {
get: function () {
return _getRectangleFromRange.default;

@@ -45,3 +45,3 @@ }

enumerable: true,
get: function get() {
get: function () {
return _getScrollContainer.default;

@@ -52,3 +52,3 @@ }

enumerable: true,
get: function get() {
get: function () {
return _getOffsetParent.default;

@@ -59,3 +59,3 @@ }

enumerable: true,
get: function get() {
get: function () {
return _isEntirelySelected.default;

@@ -66,3 +66,3 @@ }

enumerable: true,
get: function get() {
get: function () {
return _isHorizontalEdge.default;

@@ -73,3 +73,3 @@ }

enumerable: true,
get: function get() {
get: function () {
return _isNumberInput.default;

@@ -80,3 +80,3 @@ }

enumerable: true,
get: function get() {
get: function () {
return _isTextField.default;

@@ -87,3 +87,3 @@ }

enumerable: true,
get: function get() {
get: function () {
return _isVerticalEdge.default;

@@ -94,3 +94,3 @@ }

enumerable: true,
get: function get() {
get: function () {
return _placeCaretAtHorizontalEdge.default;

@@ -101,3 +101,3 @@ }

enumerable: true,
get: function get() {
get: function () {
return _placeCaretAtVerticalEdge.default;

@@ -108,3 +108,3 @@ }

enumerable: true,
get: function get() {
get: function () {
return _replace.default;

@@ -115,3 +115,3 @@ }

enumerable: true,
get: function get() {
get: function () {
return _remove.default;

@@ -122,3 +122,3 @@ }

enumerable: true,
get: function get() {
get: function () {
return _insertAfter.default;

@@ -129,3 +129,3 @@ }

enumerable: true,
get: function get() {
get: function () {
return _unwrap.default;

@@ -136,3 +136,3 @@ }

enumerable: true,
get: function get() {
get: function () {
return _replaceTag.default;

@@ -143,3 +143,3 @@ }

enumerable: true,
get: function get() {
get: function () {
return _wrap.default;

@@ -150,3 +150,3 @@ }

enumerable: true,
get: function get() {
get: function () {
return _stripHtml.default;

@@ -157,3 +157,3 @@ }

enumerable: true,
get: function get() {
get: function () {
return _isEmpty.default;

@@ -164,6 +164,12 @@ }

enumerable: true,
get: function get() {
get: function () {
return _removeInvalidHtml.default;
}
});
Object.defineProperty(exports, "isRTL", {
enumerable: true,
get: function () {
return _isRtl.default;
}
});

@@ -215,2 +221,4 @@ var _computeCaretRect = _interopRequireDefault(require("./compute-caret-rect"));

var _removeInvalidHtml = _interopRequireDefault(require("./remove-invalid-html"));
var _isRtl = _interopRequireDefault(require("./is-rtl"));
//# sourceMappingURL=index.js.map

@@ -37,6 +37,8 @@ "use strict";

try {
var selectionStart =
const {
selectionStart,
selectionEnd
} =
/** @type {HTMLInputElement | HTMLTextAreaElement} */
element.selectionStart,
selectionEnd = element.selectionEnd;
element;
return selectionStart !== null && selectionStart !== selectionEnd;

@@ -43,0 +45,0 @@ } catch (error) {

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

var _getComputedStyle2 = _interopRequireDefault(require("./get-computed-style"));
var _isRtl = _interopRequireDefault(require("./is-rtl"));

@@ -40,5 +40,3 @@ var _getRangeHeight = _interopRequireDefault(require("./get-range-height"));

*/
function isEdge(container, isReverse) {
var onlyVertical = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
function isEdge(container, isReverse, onlyVertical = false) {
if ((0, _isInputOrTextArea.default)(container)) {

@@ -62,6 +60,10 @@ if (container.selectionStart !== container.selectionEnd) {

var ownerDocument = container.ownerDocument;
var defaultView = ownerDocument.defaultView;
const {
ownerDocument
} = container;
const {
defaultView
} = ownerDocument;
(0, _assertIsDefined.assertIsDefined)(defaultView, 'defaultView');
var selection = defaultView.getSelection();
const selection = defaultView.getSelection();

@@ -72,6 +74,6 @@ if (!selection || !selection.rangeCount) {

var range = selection.getRangeAt(0);
var collapsedRange = range.cloneRange();
var isForward = (0, _isSelectionForward.default)(selection);
var isCollapsed = selection.isCollapsed; // Collapse in direction of selection.
const range = selection.getRangeAt(0);
const collapsedRange = range.cloneRange();
const isForward = (0, _isSelectionForward.default)(selection);
const isCollapsed = selection.isCollapsed; // Collapse in direction of selection.

@@ -82,4 +84,4 @@ if (!isCollapsed) {

var collapsedRangeRect = (0, _getRectangleFromRange.default)(collapsedRange);
var rangeRect = (0, _getRectangleFromRange.default)(range);
const collapsedRangeRect = (0, _getRectangleFromRange.default)(collapsedRange);
const rangeRect = (0, _getRectangleFromRange.default)(range);

@@ -93,3 +95,3 @@ if (!collapsedRangeRect || !rangeRect) {

var rangeHeight = (0, _getRangeHeight.default)(range);
const rangeHeight = (0, _getRangeHeight.default)(range);

@@ -101,7 +103,4 @@ if (!isCollapsed && rangeHeight && rangeHeight > collapsedRangeRect.height && isForward === isReverse) {

var _getComputedStyle = (0, _getComputedStyle2.default)(container),
direction = _getComputedStyle.direction;
var isReverseDir = direction === 'rtl' ? !isReverse : isReverse;
var containerRect = container.getBoundingClientRect(); // To check if a selection is at the edge, we insert a test selection at the
const isReverseDir = (0, _isRtl.default)(container) ? !isReverse : isReverse;
const containerRect = container.getBoundingClientRect(); // To check if a selection is at the edge, we insert a test selection at the
// edge of the container and check if the selections have the same vertical

@@ -117,5 +116,5 @@ // or horizontal position. If they do, the selection is at the edge.

var x = isReverseDir ? containerRect.left + 1 : containerRect.right - 1;
var y = isReverse ? containerRect.top + 1 : containerRect.bottom - 1;
var testRange = (0, _hiddenCaretRangeFromPoint.default)(ownerDocument, x, y,
const x = isReverseDir ? containerRect.left + 1 : containerRect.right - 1;
const y = isReverse ? containerRect.top + 1 : containerRect.bottom - 1;
const testRange = (0, _hiddenCaretRangeFromPoint.default)(ownerDocument, x, y,
/** @type {HTMLElement} */

@@ -128,3 +127,3 @@ container);

var testRect = (0, _getRectangleFromRange.default)(testRange);
const testRect = (0, _getRectangleFromRange.default)(testRange);

@@ -135,11 +134,11 @@ if (!testRect) {

var verticalSide = isReverse ? 'top' : 'bottom';
var horizontalSide = isReverseDir ? 'left' : 'right';
var verticalDiff = testRect[verticalSide] - rangeRect[verticalSide];
var horizontalDiff = testRect[horizontalSide] - collapsedRangeRect[horizontalSide]; // Allow the position to be 1px off.
const verticalSide = isReverse ? 'top' : 'bottom';
const horizontalSide = isReverseDir ? 'left' : 'right';
const verticalDiff = testRect[verticalSide] - rangeRect[verticalSide];
const horizontalDiff = testRect[horizontalSide] - collapsedRangeRect[horizontalSide]; // Allow the position to be 1px off.
var hasVerticalDiff = Math.abs(verticalDiff) <= 1;
var hasHorizontalDiff = Math.abs(horizontalDiff) <= 1;
const hasVerticalDiff = Math.abs(verticalDiff) <= 1;
const hasHorizontalDiff = Math.abs(horizontalDiff) <= 1;
return onlyVertical ? hasVerticalDiff : hasVerticalDiff && hasHorizontalDiff;
}
//# sourceMappingURL=is-edge.js.map

@@ -35,8 +35,12 @@ "use strict";

var ownerDocument = element.ownerDocument;
var defaultView = ownerDocument.defaultView;
const {
ownerDocument
} = element;
const {
defaultView
} = ownerDocument;
(0, _assertIsDefined.assertIsDefined)(defaultView, 'defaultView');
var selection = defaultView.getSelection();
const selection = defaultView.getSelection();
(0, _assertIsDefined.assertIsDefined)(selection, 'selection');
var range = selection.rangeCount ? selection.getRangeAt(0) : null;
const range = selection.rangeCount ? selection.getRangeAt(0) : null;

@@ -47,6 +51,8 @@ if (!range) {

var startContainer = range.startContainer,
endContainer = range.endContainer,
startOffset = range.startOffset,
endOffset = range.endOffset;
const {
startContainer,
endContainer,
startOffset,
endOffset
} = range;

@@ -57,5 +63,5 @@ if (startContainer === element && endContainer === element && startOffset === 0 && endOffset === element.childNodes.length) {

var lastChild = element.lastChild;
const lastChild = element.lastChild;
(0, _assertIsDefined.assertIsDefined)(lastChild, 'lastChild');
var lastChildContentLength = lastChild.nodeType === lastChild.TEXT_NODE ?
const lastChildContentLength = lastChild.nodeType === lastChild.TEXT_NODE ?
/** @type {Text} */

@@ -62,0 +68,0 @@ lastChild.data.length : lastChild.childNodes.length;

@@ -25,9 +25,11 @@ "use strict";

function isSelectionForward(selection) {
var anchorNode = selection.anchorNode,
focusNode = selection.focusNode,
anchorOffset = selection.anchorOffset,
focusOffset = selection.focusOffset;
const {
anchorNode,
focusNode,
anchorOffset,
focusOffset
} = selection;
(0, _assertIsDefined.assertIsDefined)(anchorNode, 'anchorNode');
(0, _assertIsDefined.assertIsDefined)(focusNode, 'focusNode');
var position = anchorNode.compareDocumentPosition(focusNode); // Disable reason: `Node#compareDocumentPosition` returns a bitmask value,
const position = anchorNode.compareDocumentPosition(focusNode); // Disable reason: `Node#compareDocumentPosition` returns a bitmask value,
// so bitwise operators are intended.

@@ -34,0 +36,0 @@

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

/* eslint-enable jsdoc/valid-types */
var nonTextInputs = ['button', 'checkbox', 'hidden', 'file', 'radio', 'image', 'range', 'reset', 'submit', 'number'];
const nonTextInputs = ['button', 'checkbox', 'hidden', 'file', 'radio', 'image', 'range', 'reset', 'submit', 'number'];
return (0, _isHtmlInputElement.default)(node) && node.type && !nonTextInputs.includes(node.type) || node.nodeName === 'TEXTAREA' ||

@@ -32,0 +32,0 @@ /** @type {HTMLElement} */

@@ -16,2 +16,4 @@ "use strict";

var _isRtl = _interopRequireDefault(require("./is-rtl"));
/**

@@ -32,5 +34,3 @@ * Internal dependencies

*/
function placeCaretAtHorizontalEdge(container, isReverse) {
var mayUseScroll = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
function placeCaretAtHorizontalEdge(container, isReverse, mayUseScroll = false) {
if (!container) {

@@ -63,9 +63,13 @@ return;

var ownerDocument = container.ownerDocument;
var containerRect = container.getBoundingClientRect(); // When placing at the end (isReverse), find the closest range to the bottom
const {
ownerDocument
} = container; // In the case of RTL scripts, the horizontal edge is at the opposite side.
const isReverseDir = (0, _isRtl.default)(container) ? !isReverse : isReverse;
const containerRect = container.getBoundingClientRect(); // When placing at the end (isReverse), find the closest range to the bottom
// right corner. When placing at the start, to the top left corner.
var x = isReverse ? containerRect.right - 1 : containerRect.left + 1;
var y = isReverse ? containerRect.bottom - 1 : containerRect.top + 1;
var range = (0, _hiddenCaretRangeFromPoint.default)(ownerDocument, x, y, container); // If no range range can be created or it is outside the container, the
const x = isReverse ? containerRect.right - 1 : containerRect.left + 1;
const y = isReverseDir ? containerRect.bottom - 1 : containerRect.top + 1;
const range = (0, _hiddenCaretRangeFromPoint.default)(ownerDocument, x, y, container); // If no range range can be created or it is outside the container, the
// element may be out of view.

@@ -85,5 +89,7 @@

var defaultView = ownerDocument.defaultView;
const {
defaultView
} = ownerDocument;
(0, _assertIsDefined.assertIsDefined)(defaultView, 'defaultView');
var selection = defaultView.getSelection();
const selection = defaultView.getSelection();
(0, _assertIsDefined.assertIsDefined)(selection, 'selection');

@@ -90,0 +96,0 @@ selection.removeAllRanges();

@@ -28,5 +28,3 @@ "use strict";

*/
function placeCaretAtVerticalEdge(container, isReverse, rect) {
var mayUseScroll = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;
function placeCaretAtVerticalEdge(container, isReverse, rect, mayUseScroll = true) {
if (!container) {

@@ -47,9 +45,13 @@ return;

var buffer = rect.height / 2;
var editableRect = container.getBoundingClientRect();
var x = rect.left;
var y = isReverse ? editableRect.bottom - buffer : editableRect.top + buffer;
var ownerDocument = container.ownerDocument;
var defaultView = ownerDocument.defaultView;
var range = (0, _hiddenCaretRangeFromPoint.default)(ownerDocument, x, y, container);
const buffer = rect.height / 2;
const editableRect = container.getBoundingClientRect();
const x = rect.left;
const y = isReverse ? editableRect.bottom - buffer : editableRect.top + buffer;
const {
ownerDocument
} = container;
const {
defaultView
} = ownerDocument;
const range = (0, _hiddenCaretRangeFromPoint.default)(ownerDocument, x, y, container);

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

(0, _assertIsDefined.assertIsDefined)(defaultView, 'defaultView');
var selection = defaultView.getSelection();
const selection = defaultView.getSelection();
(0, _assertIsDefined.assertIsDefined)(selection, 'selection');

@@ -73,0 +75,0 @@ selection.removeAllRanges();

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

function removeInvalidHTML(HTML, schema, inline) {
var doc = document.implementation.createHTMLDocument('');
const doc = document.implementation.createHTMLDocument('');
doc.body.innerHTML = HTML;

@@ -29,0 +29,0 @@ (0, _cleanNodeList.default)(doc.body.childNodes, doc, schema, inline);

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

function replaceTag(node, tagName) {
var newNode = node.ownerDocument.createElement(tagName);
const newNode = node.ownerDocument.createElement(tagName);

@@ -26,0 +26,0 @@ while (node.firstChild) {

@@ -16,5 +16,5 @@ "use strict";

function stripHTML(html) {
var document = new window.DOMParser().parseFromString(html, 'text/html');
const document = new window.DOMParser().parseFromString(html, 'text/html');
return document.body.textContent || '';
}
//# sourceMappingURL=strip-html.js.map

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

function unwrap(node) {
var parent = node.parentNode;
const parent = node.parentNode;
(0, _assertIsDefined.assertIsDefined)(parent, 'node.parentNode');

@@ -25,0 +25,0 @@

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

*/
var SELECTOR = ['[tabindex]', 'a[href]', 'button:not([disabled])', 'input:not([type="hidden"]):not([disabled])', 'select:not([disabled])', 'textarea:not([disabled])', 'iframe', 'object', 'embed', 'area[href]', '[contenteditable]:not([contenteditable=false])'].join(',');
const SELECTOR = ['[tabindex]', 'a[href]', 'button:not([disabled])', 'input:not([type="hidden"]):not([disabled])', 'select:not([disabled])', 'textarea:not([disabled])', 'iframe', 'object', 'embed', 'area[href]', '[contenteditable]:not([contenteditable=false])'].join(',');
/**

@@ -66,3 +66,3 @@ * Returns true if the specified element is visible (i.e. neither display: none

/** @type {HTMLMapElement | null} */
var map = element.closest('map[name]');
const map = element.closest('map[name]');

@@ -75,3 +75,3 @@ if (!map) {

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

@@ -94,4 +94,4 @@ }

/* eslint-enable jsdoc/no-undefined-types */
var elements = context.querySelectorAll(SELECTOR);
return Array.from(elements).filter(function (element) {
const elements = context.querySelectorAll(SELECTOR);
return Array.from(elements).filter(element => {
if (!isVisible(element) || skipFocus(element)) {

@@ -101,3 +101,5 @@ return false;

var nodeName = element.nodeName;
const {
nodeName
} = element;

@@ -104,0 +106,0 @@ if ('AREA' === nodeName) {

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

enumerable: true,
get: function get() {
get: function () {
return _dom[key];

@@ -40,3 +40,3 @@ }

enumerable: true,
get: function get() {
get: function () {
return _phrasingContent[key];

@@ -55,3 +55,3 @@ }

enumerable: true,
get: function get() {
get: function () {
return _dataTransfer[key];

@@ -70,7 +70,7 @@ }

*/
var focus = {
focusable: focusable,
tabbable: tabbable
const focus = {
focusable,
tabbable
};
exports.focus = focus;
//# sourceMappingURL=index.js.map
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {

@@ -12,10 +10,8 @@ value: true

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _lodash = require("lodash");
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
/**
* External dependencies
*/
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
/**

@@ -44,3 +40,3 @@ * All phrasing content elements.

*/
var textContentSchema = {
const textContentSchema = {
strong: {},

@@ -98,3 +94,3 @@ em: {},

(0, _lodash.without)(Object.keys(textContentSchema), '#text', 'br').forEach(function (tag) {
(0, _lodash.without)(Object.keys(textContentSchema), '#text', 'br').forEach(tag => {
textContentSchema[tag].children = (0, _lodash.omit)(textContentSchema, tag);

@@ -110,3 +106,3 @@ });

var embeddedContentSchema = {
const embeddedContentSchema = {
audio: {

@@ -137,3 +133,5 @@ attributes: ['src', 'preload', 'autoplay', 'mediagroup', 'loop', 'muted']

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

@@ -150,3 +148,2 @@ * Get schema of possible paths for phrasing content.

function getPhrasingContentSchema(context) {

@@ -157,3 +154,3 @@ if (context !== 'paste') {

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

@@ -167,3 +164,3 @@ // visible to the user when pasted, so strip the attributes.

}
}), ['u', // Used to mark misspelling. Shouldn't be pasted.
}, ['u', // Used to mark misspelling. Shouldn't be pasted.
'abbr', // Invisible.

@@ -189,3 +186,3 @@ 'data', // Invisible.

function isPhrasingContent(node) {
var tag = node.nodeName.toLowerCase();
const tag = node.nodeName.toLowerCase();
return getPhrasingContentSchema().hasOwnProperty(tag) || tag === 'span';

@@ -200,5 +197,5 @@ }

function isTextContent(node) {
var tag = node.nodeName.toLowerCase();
const tag = node.nodeName.toLowerCase();
return textContentSchema.hasOwnProperty(tag) || tag === 'span';
}
//# sourceMappingURL=phrasing-content.js.map

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

function getTabIndex(element) {
var tabIndex = element.getAttribute('tabindex');
const tabIndex = element.getAttribute('tabindex');
return tabIndex === null ? 0 : parseInt(tabIndex, 10);

@@ -66,3 +66,3 @@ }

/** @type {Record<string, MaybeHTMLInputElement>} */
var CHOSEN_RADIO_BY_NAME = {};
const CHOSEN_RADIO_BY_NAME = {};
return function collapseRadioGroup(

@@ -73,6 +73,8 @@ /** @type {MaybeHTMLInputElement[]} */

element) {
var nodeName = element.nodeName,
type = element.type,
checked = element.checked,
name = element.name; // For all non-radio tabbables, construct to array by concatenating.
const {
nodeName,
type,
checked,
name
} = element; // For all non-radio tabbables, construct to array by concatenating.

@@ -83,5 +85,5 @@ if (nodeName !== 'INPUT' || type !== 'radio' || !name) {

var hasChosen = CHOSEN_RADIO_BY_NAME.hasOwnProperty(name); // Omit by skipping concatenation if the radio element is not chosen.
const hasChosen = CHOSEN_RADIO_BY_NAME.hasOwnProperty(name); // Omit by skipping concatenation if the radio element is not chosen.
var isChosen = checked || !hasChosen;
const isChosen = checked || !hasChosen;

@@ -96,3 +98,3 @@ if (!isChosen) {

if (hasChosen) {
var hadChosenElement = CHOSEN_RADIO_BY_NAME[name];
const hadChosenElement = CHOSEN_RADIO_BY_NAME[name];
result = (0, _lodash.without)(result, hadChosenElement);

@@ -120,4 +122,4 @@ }

return {
element: element,
index: index
element,
index
};

@@ -151,4 +153,4 @@ }

function compareObjectTabbables(a, b) {
var aTabIndex = getTabIndex(a.element);
var bTabIndex = getTabIndex(b.element);
const aTabIndex = getTabIndex(a.element);
const bTabIndex = getTabIndex(b.element);

@@ -191,4 +193,4 @@ if (aTabIndex === bTabIndex) {

function findPrevious(element) {
var focusables = (0, _focusable.find)(element.ownerDocument.body);
var index = focusables.indexOf(element); // Remove all focusables after and including `element`.
const focusables = (0, _focusable.find)(element.ownerDocument.body);
const index = focusables.indexOf(element); // Remove all focusables after and including `element`.

@@ -207,10 +209,8 @@ focusables.length = index;

function findNext(element) {
var focusables = (0, _focusable.find)(element.ownerDocument.body);
var index = focusables.indexOf(element); // Remove all focusables before and inside `element`.
const focusables = (0, _focusable.find)(element.ownerDocument.body);
const index = focusables.indexOf(element); // Remove all focusables before and inside `element`.
var remaining = focusables.slice(index + 1).filter(function (node) {
return !element.contains(node);
});
const remaining = focusables.slice(index + 1).filter(node => !element.contains(node));
return (0, _lodash.first)(filterTabbable(remaining));
}
//# sourceMappingURL=tabbable.js.map

@@ -10,5 +10,5 @@ "use strict";

if (process.env.NODE_ENV !== 'production' && (val === undefined || val === null)) {
throw new Error("Expected '".concat(name, "' to be defined, but received ").concat(val));
throw new Error(`Expected '${name}' to be defined, but received ${val}`);
}
}
//# sourceMappingURL=assert-is-defined.js.map

@@ -5,2 +5,9 @@ <!-- Learn how to maintain this file at https://github.com/WordPress/gutenberg/tree/HEAD/packages#maintaining-changelogs. -->

## 3.0.0 (2021-05-14)
### Breaking Changes
- Drop support for Internet Explorer 11 ([#31110](https://github.com/WordPress/gutenberg/pull/31110)). Learn more at https://make.wordpress.org/core/2021/04/22/ie-11-support-phase-out-plan/.
- Increase the minimum Node.js version to v12 matching Long Term Support releases ([#31270](https://github.com/WordPress/gutenberg/pull/31270)). Learn more at https://nodejs.org/en/about/releases/.
## 2.18.0 (2021-04-29)

@@ -10,3 +17,3 @@

- Export type definitions
- Export type definitions.

@@ -13,0 +20,0 @@ ## 2.17.0 (2021-03-17)

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

@@ -22,2 +22,5 @@ "author": "The WordPress Contributors",

},
"engines": {
"node": ">=12"
},
"main": "build/index.js",

@@ -30,3 +33,3 @@ "module": "build-module/index.js",

"@babel/runtime": "^7.13.10",
"lodash": "^4.17.19"
"lodash": "^4.17.21"
},

@@ -36,3 +39,3 @@ "publishConfig": {

},
"gitHead": "4abe97cdbdf5e12bfc95b68c74cd0baa6583fc65"
"gitHead": "0c80fbada8b86cd8e4b4892460caa3a5d0e5f583"
}

@@ -229,2 +229,14 @@ # DOM

<a name="isRTL" href="#isRTL">#</a> **isRTL**
Whether the element's text direction is right-to-left.
_Parameters_
- _element_ `Element`: The element to check.
_Returns_
- `boolean`: True if rtl, false if ltr.
<a name="isTextContent" href="#isTextContent">#</a> **isTextContent**

@@ -231,0 +243,0 @@

@@ -18,3 +18,41 @@ /**

if ( ! range.collapsed ) {
return range.getBoundingClientRect();
const rects = Array.from( range.getClientRects() );
// If there's just a single rect, return it.
if ( rects.length === 1 ) {
return rects[ 0 ];
}
// Ignore tiny selection at the edge of a range.
const filteredRects = rects.filter( ( { width } ) => width > 1 );
// If it's full of tiny selections, return browser default.
if ( filteredRects.length === 0 ) {
return range.getBoundingClientRect();
}
if ( filteredRects.length === 1 ) {
return filteredRects[ 0 ];
}
let {
top: furthestTop,
bottom: furthestBottom,
left: furthestLeft,
right: furthestRight,
} = filteredRects[ 0 ];
for ( const { top, bottom, left, right } of filteredRects ) {
if ( top < furthestTop ) furthestTop = top;
if ( bottom > furthestBottom ) furthestBottom = bottom;
if ( left < furthestLeft ) furthestLeft = left;
if ( right > furthestRight ) furthestRight = right;
}
return new window.DOMRect(
furthestLeft,
furthestTop,
furthestRight - furthestLeft,
furthestBottom - furthestTop
);
}

@@ -21,0 +59,0 @@

@@ -24,1 +24,2 @@ export { default as computeCaretRect } from './compute-caret-rect';

export { default as removeInvalidHTML } from './remove-invalid-html';
export { default as isRTL } from './is-rtl';
/**
* Internal dependencies
*/
import getComputedStyle from './get-computed-style';
import isRTL from './is-rtl';
import getRangeHeight from './get-range-height';

@@ -81,5 +81,3 @@ import getRectangleFromRange from './get-rectangle-from-range';

// In the case of RTL scripts, the horizontal edge is at the opposite side.
const { direction } = getComputedStyle( container );
const isReverseDir = direction === 'rtl' ? ! isReverse : isReverse;
const isReverseDir = isRTL( container ) ? ! isReverse : isReverse;
const containerRect = container.getBoundingClientRect();

@@ -86,0 +84,0 @@

@@ -11,2 +11,3 @@ /**

import isInputOrTextArea from './is-input-or-text-area';
import isRTL from './is-rtl';

@@ -53,2 +54,4 @@ /**

const { ownerDocument } = container;
// In the case of RTL scripts, the horizontal edge is at the opposite side.
const isReverseDir = isRTL( container ) ? ! isReverse : isReverse;
const containerRect = container.getBoundingClientRect();

@@ -58,3 +61,3 @@ // When placing at the end (isReverse), find the closest range to the bottom

const x = isReverse ? containerRect.right - 1 : containerRect.left + 1;
const y = isReverse ? containerRect.bottom - 1 : containerRect.top + 1;
const y = isReverseDir ? containerRect.bottom - 1 : containerRect.top + 1;
const range = hiddenCaretRangeFromPoint( ownerDocument, x, y, container );

@@ -61,0 +64,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

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

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

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

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

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

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