@wordpress/dom
Advanced tools
Comparing version 2.17.2 to 2.18.0
@@ -17,4 +17,4 @@ /** | ||
export default function documentHasSelection(doc) { | ||
return isTextField(doc.activeElement) || isNumberInput(doc.activeElement) || documentHasTextSelection(doc); | ||
return !!doc.activeElement && (isTextField(doc.activeElement) || isNumberInput(doc.activeElement) || documentHasTextSelection(doc)); | ||
} | ||
//# sourceMappingURL=document-has-selection.js.map |
/** | ||
* Internal dependencies | ||
*/ | ||
import { assertIsDefined } from '../utils/assert-is-defined'; | ||
/** | ||
* Check whether the current document has selected text. This applies to ranges | ||
@@ -12,7 +16,10 @@ * of text in the document, and not selection inside <input> and <textarea> | ||
*/ | ||
export default function documentHasTextSelection(doc) { | ||
assertIsDefined(doc.defaultView, 'doc.defaultView'); | ||
var selection = doc.defaultView.getSelection(); | ||
assertIsDefined(selection, 'selection'); | ||
var range = selection.rangeCount ? selection.getRangeAt(0) : null; | ||
return range && !range.collapsed; | ||
return !!range && !range.collapsed; | ||
} | ||
//# sourceMappingURL=document-has-text-selection.js.map |
@@ -17,4 +17,4 @@ /** | ||
export default function documentHasUncollapsedSelection(doc) { | ||
return documentHasTextSelection(doc) || inputFieldHasUncollapsedSelection(doc.activeElement); | ||
return documentHasTextSelection(doc) || !!doc.activeElement && inputFieldHasUncollapsedSelection(doc.activeElement); | ||
} | ||
//# sourceMappingURL=document-has-uncollapsed-selection.js.map |
@@ -1,4 +0,17 @@ | ||
export default function getComputedStyle(node) { | ||
return node.ownerDocument.defaultView.getComputedStyle(node); | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { assertIsDefined } from '../utils/assert-is-defined'; | ||
/* eslint-disable jsdoc/valid-types */ | ||
/** | ||
* @param {Element} element | ||
* @return {ReturnType<Window['getComputedStyle']>} The computed style for the element. | ||
*/ | ||
export default function getComputedStyle(element) { | ||
/* eslint-enable jsdoc/valid-types */ | ||
assertIsDefined(element.ownerDocument.defaultView, 'element.ownerDocument.defaultView'); | ||
return element.ownerDocument.defaultView.getComputedStyle(element); | ||
} | ||
//# sourceMappingURL=get-computed-style.js.map |
@@ -14,3 +14,3 @@ /** | ||
* | ||
* @return {?Node} Offset parent. | ||
* @return {Node | null} Offset parent. | ||
*/ | ||
@@ -23,3 +23,5 @@ | ||
while (closestElement = node.parentNode) { | ||
while (closestElement = | ||
/** @type {Node} */ | ||
node.parentNode) { | ||
if (closestElement.nodeType === closestElement.ELEMENT_NODE) { | ||
@@ -36,8 +38,14 @@ break; | ||
if (getComputedStyle(closestElement).position !== 'static') { | ||
if (getComputedStyle( | ||
/** @type {Element} */ | ||
closestElement).position !== 'static') { | ||
return closestElement; | ||
} | ||
} // offsetParent is undocumented/draft | ||
return closestElement.offsetParent; | ||
return ( | ||
/** @type {Node & { offsetParent: Node }} */ | ||
closestElement.offsetParent | ||
); | ||
} | ||
//# sourceMappingURL=get-offset-parent.js.map |
@@ -8,2 +8,3 @@ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray"; | ||
* @param {Range} range The range to check. | ||
* @return {number | undefined} Height of the range or undefined if the range has no client rectangles. | ||
*/ | ||
@@ -10,0 +11,0 @@ export default function getRangeHeight(range) { |
@@ -8,5 +8,5 @@ /** | ||
* | ||
* @param {Element} node Node from which to start. | ||
* @param {Element | null} node Node from which to start. | ||
* | ||
* @return {?Element} Scrollable container node, if found. | ||
* @return {Element | undefined} Scrollable container node, if found. | ||
*/ | ||
@@ -16,3 +16,3 @@ | ||
if (!node) { | ||
return; | ||
return undefined; | ||
} // Scrollable if scrollable height exceeds displayed... | ||
@@ -32,4 +32,6 @@ | ||
return getScrollContainer(node.parentNode); | ||
return getScrollContainer( | ||
/** @type {Element} */ | ||
node.parentNode); | ||
} | ||
//# sourceMappingURL=get-scroll-container.js.map |
@@ -14,3 +14,3 @@ /** |
* @param {number} y Vertical position within the current viewport. |
* @param {Element} container Container in which the range is expected to be found. |
* @param {HTMLElement} container Container in which the range is expected to be found. |
* |
@@ -17,0 +17,0 @@ * @return {?Range} The best range for the given point. |
@@ -15,3 +15,3 @@ /** | ||
* | ||
* @param {HTMLElement} element The HTML element. | ||
* @param {Element} element The HTML element. | ||
* | ||
@@ -27,3 +27,5 @@ * @return {boolean} Whether the input/textareaa element has some "selection". | ||
try { | ||
var selectionStart = element.selectionStart, | ||
var selectionStart = | ||
/** @type {HTMLInputElement | HTMLTextAreaElement} */ | ||
element.selectionStart, | ||
selectionEnd = element.selectionEnd; | ||
@@ -30,0 +32,0 @@ return selectionStart !== null && selectionStart !== selectionEnd; |
/** | ||
* External dependencies | ||
*/ | ||
import { includes } from 'lodash'; | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import getComputedStyle from './get-computed-style'; | ||
@@ -14,2 +9,4 @@ import getRangeHeight from './get-range-height'; | ||
import hiddenCaretRangeFromPoint from './hidden-caret-range-from-point'; | ||
import { assertIsDefined } from '../utils/assert-is-defined'; | ||
import isInputOrTextArea from './is-input-or-text-area'; | ||
/** | ||
@@ -20,5 +17,5 @@ * Check whether the selection is at the edge of the container. Checks for | ||
* | ||
* @param {Element} container Focusable element. | ||
* @param {boolean} isReverse Set to true to check left, false to check right. | ||
* @param {boolean} onlyVertical Set to true to check only vertical position. | ||
* @param {Element} container Focusable element. | ||
* @param {boolean} isReverse Set to true to check left, false to check right. | ||
* @param {boolean} [onlyVertical=false] Set to true to check only vertical position. | ||
* | ||
@@ -28,4 +25,6 @@ * @return {boolean} True if at the edge, false if not. | ||
export default function isEdge(container, isReverse, onlyVertical) { | ||
if (includes(['INPUT', 'TEXTAREA'], container.tagName)) { | ||
export default function isEdge(container, isReverse) { | ||
var onlyVertical = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; | ||
if (isInputOrTextArea(container)) { | ||
if (container.selectionStart !== container.selectionEnd) { | ||
@@ -42,3 +41,5 @@ return false; | ||
if (!container.isContentEditable) { | ||
if (! | ||
/** @type {HTMLElement} */ | ||
container.isContentEditable) { | ||
return true; | ||
@@ -49,5 +50,6 @@ } | ||
var defaultView = ownerDocument.defaultView; | ||
assertIsDefined(defaultView, 'defaultView'); | ||
var selection = defaultView.getSelection(); | ||
if (!selection.rangeCount) { | ||
if (!selection || !selection.rangeCount) { | ||
return false; | ||
@@ -75,3 +77,5 @@ } | ||
if (!isCollapsed && getRangeHeight(range) > collapsedRangeRect.height && isForward === isReverse) { | ||
var rangeHeight = getRangeHeight(range); | ||
if (!isCollapsed && rangeHeight && rangeHeight > collapsedRangeRect.height && isForward === isReverse) { | ||
return false; | ||
@@ -98,3 +102,5 @@ } // In the case of RTL scripts, the horizontal edge is at the opposite side. | ||
var y = isReverse ? containerRect.top + 1 : containerRect.bottom - 1; | ||
var testRange = hiddenCaretRangeFromPoint(ownerDocument, x, y, container); | ||
var testRange = hiddenCaretRangeFromPoint(ownerDocument, x, y, | ||
/** @type {HTMLElement} */ | ||
container); | ||
@@ -101,0 +107,0 @@ if (!testRange) { |
/** | ||
* External dependencies | ||
* Internal dependencies | ||
*/ | ||
import { includes } from 'lodash'; | ||
import { assertIsDefined } from '../utils/assert-is-defined'; | ||
import isInputOrTextArea from './is-input-or-text-area'; | ||
/** | ||
@@ -9,3 +10,3 @@ * Check whether the contents of the element have been entirely selected. | ||
* | ||
* @param {Element} element The element to check. | ||
* @param {HTMLElement} element The element to check. | ||
* | ||
@@ -16,3 +17,3 @@ * @return {boolean} True if entirely selected, false if not. | ||
export default function isEntirelySelected(element) { | ||
if (includes(['INPUT', 'TEXTAREA'], element.nodeName)) { | ||
if (isInputOrTextArea(element)) { | ||
return element.selectionStart === 0 && element.value.length === element.selectionEnd; | ||
@@ -27,3 +28,5 @@ } | ||
var defaultView = ownerDocument.defaultView; | ||
assertIsDefined(defaultView, 'defaultView'); | ||
var selection = defaultView.getSelection(); | ||
assertIsDefined(selection, 'selection'); | ||
var range = selection.rangeCount ? selection.getRangeAt(0) : null; | ||
@@ -45,5 +48,8 @@ | ||
var lastChild = element.lastChild; | ||
var lastChildContentLength = lastChild.nodeType === lastChild.TEXT_NODE ? lastChild.data.length : lastChild.childNodes.length; | ||
assertIsDefined(lastChild, 'lastChild'); | ||
var lastChildContentLength = lastChild.nodeType === lastChild.TEXT_NODE ? | ||
/** @type {Text} */ | ||
lastChild.data.length : lastChild.childNodes.length; | ||
return startContainer === element.firstChild && endContainer === element.lastChild && startOffset === 0 && endOffset === lastChildContentLength; | ||
} | ||
//# sourceMappingURL=is-entirely-selected.js.map |
/** | ||
* Internal dependencies | ||
*/ | ||
import isHTMLInputElement from './is-html-input-element'; | ||
/* eslint-disable jsdoc/valid-types */ | ||
/** | ||
* Check whether the given element is an input field of type number | ||
* and has a valueAsNumber | ||
* | ||
* @param {HTMLElement} element The HTML element. | ||
* @param {Node} node The HTML node. | ||
* | ||
* @return {boolean} True if the element is input and holds a number. | ||
* @return {node is HTMLInputElement} True if the node is input and holds a number. | ||
*/ | ||
export default function isNumberInput(element) { | ||
var nodeName = element.nodeName, | ||
type = element.type, | ||
valueAsNumber = element.valueAsNumber; | ||
return nodeName === 'INPUT' && type === 'number' && !!valueAsNumber; | ||
export default function isNumberInput(node) { | ||
/* eslint-enable jsdoc/valid-types */ | ||
return isHTMLInputElement(node) && node.type === 'number' && !!node.valueAsNumber; | ||
} | ||
//# sourceMappingURL=is-number-input.js.map |
/** | ||
* Internal dependencies | ||
*/ | ||
import { assertIsDefined } from '../utils/assert-is-defined'; | ||
/** | ||
* Returns true if the given selection object is in the forward direction, or | ||
@@ -11,2 +15,3 @@ * false otherwise. | ||
*/ | ||
export default function isSelectionForward(selection) { | ||
@@ -17,2 +22,4 @@ var anchorNode = selection.anchorNode, | ||
focusOffset = selection.focusOffset; | ||
assertIsDefined(anchorNode, 'anchorNode'); | ||
assertIsDefined(focusNode, 'focusNode'); | ||
var position = anchorNode.compareDocumentPosition(focusNode); // Disable reason: `Node#compareDocumentPosition` returns a bitmask value, | ||
@@ -19,0 +26,0 @@ // so bitwise operators are intended. |
/** | ||
* Internal dependencies | ||
*/ | ||
import isHTMLInputElement from './is-html-input-element'; | ||
/* eslint-disable jsdoc/valid-types */ | ||
/** | ||
* Check whether the given element is a text field, where text field is defined | ||
@@ -7,12 +13,13 @@ * by the ability to select within the input, or that it is contenteditable. | ||
* | ||
* @param {HTMLElement} element The HTML element. | ||
* | ||
* @return {boolean} True if the element is an text field, false if not. | ||
* @param {Node} node The HTML element. | ||
* @return {element is HTMLElement} True if the element is an text field, false if not. | ||
*/ | ||
export default function isTextField(element) { | ||
var nodeName = element.nodeName, | ||
contentEditable = element.contentEditable; | ||
export default function isTextField(node) { | ||
/* eslint-enable jsdoc/valid-types */ | ||
var nonTextInputs = ['button', 'checkbox', 'hidden', 'file', 'radio', 'image', 'range', 'reset', 'submit', 'number']; | ||
return nodeName === 'INPUT' && !nonTextInputs.includes(element.type) || nodeName === 'TEXTAREA' || contentEditable === 'true'; | ||
return isHTMLInputElement(node) && node.type && !nonTextInputs.includes(node.type) || node.nodeName === 'TEXTAREA' || | ||
/** @type {HTMLElement} */ | ||
node.contentEditable === 'true'; | ||
} | ||
//# sourceMappingURL=is-text-field.js.map |
/** | ||
* External dependencies | ||
* Internal dependencies | ||
*/ | ||
import { includes } from 'lodash'; | ||
import { assertIsDefined } from '../utils/assert-is-defined'; | ||
/** | ||
@@ -10,11 +10,14 @@ * Internal dependencies | ||
import hiddenCaretRangeFromPoint from './hidden-caret-range-from-point'; | ||
import isInputOrTextArea from './is-input-or-text-area'; | ||
/** | ||
* Places the caret at start or end of a given element. | ||
* | ||
* @param {Element} container Focusable element. | ||
* @param {HTMLElement} container Focusable element. | ||
* @param {boolean} isReverse True for end, false for start. | ||
* @param {boolean} mayUseScroll Whether to allow scrolling. | ||
* @param {boolean} [mayUseScroll=false] Whether to allow scrolling. | ||
*/ | ||
export default function placeCaretAtHorizontalEdge(container, isReverse, mayUseScroll) { | ||
export default function placeCaretAtHorizontalEdge(container, isReverse) { | ||
var mayUseScroll = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; | ||
if (!container) { | ||
@@ -26,3 +29,3 @@ return; | ||
if (includes(['INPUT', 'TEXTAREA'], container.tagName)) { | ||
if (isInputOrTextArea(container)) { | ||
// The element may not support selection setting. | ||
@@ -70,3 +73,5 @@ if (typeof container.selectionStart !== 'number') { | ||
var defaultView = ownerDocument.defaultView; | ||
assertIsDefined(defaultView, 'defaultView'); | ||
var selection = defaultView.getSelection(); | ||
assertIsDefined(selection, 'selection'); | ||
selection.removeAllRanges(); | ||
@@ -73,0 +78,0 @@ selection.addRange(range); |
@@ -6,6 +6,7 @@ /** | ||
import hiddenCaretRangeFromPoint from './hidden-caret-range-from-point'; | ||
import { assertIsDefined } from '../utils/assert-is-defined'; | ||
/** | ||
* Places the caret at the top or bottom of a given element. | ||
* | ||
* @param {Element} container Focusable element. | ||
* @param {HTMLElement} container Focusable element. | ||
* @param {boolean} isReverse True for bottom, false for top. | ||
@@ -55,3 +56,5 @@ * @param {DOMRect} [rect] The rectangle to position the caret with. | ||
assertIsDefined(defaultView, 'defaultView'); | ||
var selection = defaultView.getSelection(); | ||
assertIsDefined(selection, 'selection'); | ||
selection.removeAllRanges(); | ||
@@ -58,0 +61,0 @@ selection.addRange(range); |
@@ -9,4 +9,4 @@ /** | ||
* @param {string} HTML The HTML to clean up. | ||
* @param {Object} schema Schema for the HTML. | ||
* @param {Object} inline Whether to clean for inline mode. | ||
* @param {import('./clean-node-list').Schema} schema Schema for the HTML. | ||
* @param {boolean} inline Whether to clean for inline mode. | ||
* | ||
@@ -13,0 +13,0 @@ * @return {string} The cleaned up HTML. |
/** | ||
* Internal dependencies | ||
*/ | ||
import { assertIsDefined } from '../utils/assert-is-defined'; | ||
/** | ||
* Replaces the given node with a new node with the given tag name. | ||
@@ -9,2 +13,3 @@ * | ||
*/ | ||
export default function replaceTag(node, tagName) { | ||
@@ -17,2 +22,3 @@ var newNode = node.ownerDocument.createElement(tagName); | ||
assertIsDefined(node.parentNode, 'node.parentNode'); | ||
node.parentNode.replaceChild(newNode, node); | ||
@@ -19,0 +25,0 @@ return newNode; |
/** | ||
* Internal dependencies | ||
*/ | ||
import { assertIsDefined } from '../utils/assert-is-defined'; | ||
import insertAfter from './insert-after'; | ||
@@ -15,2 +16,3 @@ import remove from './remove'; | ||
export default function replace(processedNode, newNode) { | ||
assertIsDefined(processedNode.parentNode, 'processedNode.parentNode'); | ||
insertAfter(newNode, processedNode.parentNode); | ||
@@ -17,0 +19,0 @@ remove(processedNode); |
/** | ||
* Internal dependencies | ||
*/ | ||
import { assertIsDefined } from '../utils/assert-is-defined'; | ||
/** | ||
* Wraps the given node with a new node with the given tag name. | ||
@@ -7,3 +11,5 @@ * | ||
*/ | ||
export default function wrap(newNode, referenceNode) { | ||
assertIsDefined(referenceNode.parentNode, 'referenceNode.parentNode'); | ||
referenceNode.parentNode.insertBefore(newNode, referenceNode); | ||
@@ -10,0 +16,0 @@ newNode.appendChild(referenceNode); |
export function assertIsDefined(val, name) { | ||
if (val === undefined || val === null) { | ||
if (process.env.NODE_ENV !== 'production' && (val === undefined || val === null)) { | ||
throw new Error("Expected '".concat(name, "' to be defined, but received ").concat(val)); | ||
@@ -4,0 +4,0 @@ } |
@@ -29,4 +29,4 @@ "use strict"; | ||
function documentHasSelection(doc) { | ||
return (0, _isTextField.default)(doc.activeElement) || (0, _isNumberInput.default)(doc.activeElement) || (0, _documentHasTextSelection.default)(doc); | ||
return !!doc.activeElement && ((0, _isTextField.default)(doc.activeElement) || (0, _isNumberInput.default)(doc.activeElement) || (0, _documentHasTextSelection.default)(doc)); | ||
} | ||
//# sourceMappingURL=document-has-selection.js.map |
@@ -8,3 +8,9 @@ "use strict"; | ||
var _assertIsDefined = require("../utils/assert-is-defined"); | ||
/** | ||
* Internal dependencies | ||
*/ | ||
/** | ||
* Check whether the current document has selected text. This applies to ranges | ||
@@ -21,6 +27,8 @@ * of text in the document, and not selection inside <input> and <textarea> | ||
function documentHasTextSelection(doc) { | ||
(0, _assertIsDefined.assertIsDefined)(doc.defaultView, 'doc.defaultView'); | ||
var selection = doc.defaultView.getSelection(); | ||
(0, _assertIsDefined.assertIsDefined)(selection, 'selection'); | ||
var range = selection.rangeCount ? selection.getRangeAt(0) : null; | ||
return range && !range.collapsed; | ||
return !!range && !range.collapsed; | ||
} | ||
//# sourceMappingURL=document-has-text-selection.js.map |
@@ -28,4 +28,4 @@ "use strict"; | ||
function documentHasUncollapsedSelection(doc) { | ||
return (0, _documentHasTextSelection.default)(doc) || (0, _inputFieldHasUncollapsedSelection.default)(doc.activeElement); | ||
return (0, _documentHasTextSelection.default)(doc) || !!doc.activeElement && (0, _inputFieldHasUncollapsedSelection.default)(doc.activeElement); | ||
} | ||
//# sourceMappingURL=document-has-uncollapsed-selection.js.map |
@@ -8,5 +8,19 @@ "use strict"; | ||
function getComputedStyle(node) { | ||
return node.ownerDocument.defaultView.getComputedStyle(node); | ||
var _assertIsDefined = require("../utils/assert-is-defined"); | ||
/** | ||
* Internal dependencies | ||
*/ | ||
/* eslint-disable jsdoc/valid-types */ | ||
/** | ||
* @param {Element} element | ||
* @return {ReturnType<Window['getComputedStyle']>} The computed style for the element. | ||
*/ | ||
function getComputedStyle(element) { | ||
/* eslint-enable jsdoc/valid-types */ | ||
(0, _assertIsDefined.assertIsDefined)(element.ownerDocument.defaultView, 'element.ownerDocument.defaultView'); | ||
return element.ownerDocument.defaultView.getComputedStyle(element); | ||
} | ||
//# sourceMappingURL=get-computed-style.js.map |
@@ -25,3 +25,3 @@ "use strict"; | ||
* | ||
* @return {?Node} Offset parent. | ||
* @return {Node | null} Offset parent. | ||
*/ | ||
@@ -33,3 +33,5 @@ function getOffsetParent(node) { | ||
while (closestElement = node.parentNode) { | ||
while (closestElement = | ||
/** @type {Node} */ | ||
node.parentNode) { | ||
if (closestElement.nodeType === closestElement.ELEMENT_NODE) { | ||
@@ -46,8 +48,14 @@ break; | ||
if ((0, _getComputedStyle.default)(closestElement).position !== 'static') { | ||
if ((0, _getComputedStyle.default)( | ||
/** @type {Element} */ | ||
closestElement).position !== 'static') { | ||
return closestElement; | ||
} | ||
} // offsetParent is undocumented/draft | ||
return closestElement.offsetParent; | ||
return ( | ||
/** @type {Node & { offsetParent: Node }} */ | ||
closestElement.offsetParent | ||
); | ||
} | ||
//# sourceMappingURL=get-offset-parent.js.map |
@@ -17,2 +17,3 @@ "use strict"; | ||
* @param {Range} range The range to check. | ||
* @return {number | undefined} Height of the range or undefined if the range has no client rectangles. | ||
*/ | ||
@@ -19,0 +20,0 @@ function getRangeHeight(range) { |
@@ -19,9 +19,9 @@ "use strict"; | ||
* | ||
* @param {Element} node Node from which to start. | ||
* @param {Element | null} node Node from which to start. | ||
* | ||
* @return {?Element} Scrollable container node, if found. | ||
* @return {Element | undefined} Scrollable container node, if found. | ||
*/ | ||
function getScrollContainer(node) { | ||
if (!node) { | ||
return; | ||
return undefined; | ||
} // Scrollable if scrollable height exceeds displayed... | ||
@@ -41,4 +41,6 @@ | ||
return getScrollContainer(node.parentNode); | ||
return getScrollContainer( | ||
/** @type {Element} */ | ||
node.parentNode); | ||
} | ||
//# sourceMappingURL=get-scroll-container.js.map |
@@ -26,3 +26,3 @@ "use strict"; |
* @param {number} y Vertical position within the current viewport. |
* @param {Element} container Container in which the range is expected to be found. |
* @param {HTMLElement} container Container in which the range is expected to be found. |
* |
@@ -29,0 +29,0 @@ * @return {?Range} The best range for the given point. |
@@ -27,3 +27,3 @@ "use strict"; | ||
* | ||
* @param {HTMLElement} element The HTML element. | ||
* @param {Element} element The HTML element. | ||
* | ||
@@ -38,3 +38,5 @@ * @return {boolean} Whether the input/textareaa element has some "selection". | ||
try { | ||
var selectionStart = element.selectionStart, | ||
var selectionStart = | ||
/** @type {HTMLInputElement | HTMLTextAreaElement} */ | ||
element.selectionStart, | ||
selectionEnd = element.selectionEnd; | ||
@@ -41,0 +43,0 @@ return selectionStart !== null && selectionStart !== selectionEnd; |
@@ -10,4 +10,2 @@ "use strict"; | ||
var _lodash = require("lodash"); | ||
var _getComputedStyle2 = _interopRequireDefault(require("./get-computed-style")); | ||
@@ -23,6 +21,6 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
var _assertIsDefined = require("../utils/assert-is-defined"); | ||
var _isInputOrTextArea = _interopRequireDefault(require("./is-input-or-text-area")); | ||
/** | ||
@@ -37,10 +35,12 @@ * Internal dependencies | ||
* | ||
* @param {Element} container Focusable element. | ||
* @param {boolean} isReverse Set to true to check left, false to check right. | ||
* @param {boolean} onlyVertical Set to true to check only vertical position. | ||
* @param {Element} container Focusable element. | ||
* @param {boolean} isReverse Set to true to check left, false to check right. | ||
* @param {boolean} [onlyVertical=false] Set to true to check only vertical position. | ||
* | ||
* @return {boolean} True if at the edge, false if not. | ||
*/ | ||
function isEdge(container, isReverse, onlyVertical) { | ||
if ((0, _lodash.includes)(['INPUT', 'TEXTAREA'], container.tagName)) { | ||
function isEdge(container, isReverse) { | ||
var onlyVertical = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; | ||
if ((0, _isInputOrTextArea.default)(container)) { | ||
if (container.selectionStart !== container.selectionEnd) { | ||
@@ -57,3 +57,5 @@ return false; | ||
if (!container.isContentEditable) { | ||
if (! | ||
/** @type {HTMLElement} */ | ||
container.isContentEditable) { | ||
return true; | ||
@@ -64,5 +66,6 @@ } | ||
var defaultView = ownerDocument.defaultView; | ||
(0, _assertIsDefined.assertIsDefined)(defaultView, 'defaultView'); | ||
var selection = defaultView.getSelection(); | ||
if (!selection.rangeCount) { | ||
if (!selection || !selection.rangeCount) { | ||
return false; | ||
@@ -90,3 +93,5 @@ } | ||
if (!isCollapsed && (0, _getRangeHeight.default)(range) > collapsedRangeRect.height && isForward === isReverse) { | ||
var rangeHeight = (0, _getRangeHeight.default)(range); | ||
if (!isCollapsed && rangeHeight && rangeHeight > collapsedRangeRect.height && isForward === isReverse) { | ||
return false; | ||
@@ -113,3 +118,5 @@ } // In the case of RTL scripts, the horizontal edge is at the opposite side. | ||
var y = isReverse ? containerRect.top + 1 : containerRect.bottom - 1; | ||
var testRange = (0, _hiddenCaretRangeFromPoint.default)(ownerDocument, x, y, container); | ||
var testRange = (0, _hiddenCaretRangeFromPoint.default)(ownerDocument, x, y, | ||
/** @type {HTMLElement} */ | ||
container); | ||
@@ -116,0 +123,0 @@ if (!testRange) { |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -8,6 +10,8 @@ value: true | ||
var _lodash = require("lodash"); | ||
var _assertIsDefined = require("../utils/assert-is-defined"); | ||
var _isInputOrTextArea = _interopRequireDefault(require("./is-input-or-text-area")); | ||
/** | ||
* External dependencies | ||
* Internal dependencies | ||
*/ | ||
@@ -19,3 +23,3 @@ | ||
* | ||
* @param {Element} element The element to check. | ||
* @param {HTMLElement} element The element to check. | ||
* | ||
@@ -25,3 +29,3 @@ * @return {boolean} True if entirely selected, false if not. | ||
function isEntirelySelected(element) { | ||
if ((0, _lodash.includes)(['INPUT', 'TEXTAREA'], element.nodeName)) { | ||
if ((0, _isInputOrTextArea.default)(element)) { | ||
return element.selectionStart === 0 && element.value.length === element.selectionEnd; | ||
@@ -36,3 +40,5 @@ } | ||
var defaultView = ownerDocument.defaultView; | ||
(0, _assertIsDefined.assertIsDefined)(defaultView, 'defaultView'); | ||
var selection = defaultView.getSelection(); | ||
(0, _assertIsDefined.assertIsDefined)(selection, 'selection'); | ||
var range = selection.rangeCount ? selection.getRangeAt(0) : null; | ||
@@ -54,5 +60,8 @@ | ||
var lastChild = element.lastChild; | ||
var lastChildContentLength = lastChild.nodeType === lastChild.TEXT_NODE ? lastChild.data.length : lastChild.childNodes.length; | ||
(0, _assertIsDefined.assertIsDefined)(lastChild, 'lastChild'); | ||
var lastChildContentLength = lastChild.nodeType === lastChild.TEXT_NODE ? | ||
/** @type {Text} */ | ||
lastChild.data.length : lastChild.childNodes.length; | ||
return startContainer === element.firstChild && endContainer === element.lastChild && startOffset === 0 && endOffset === lastChildContentLength; | ||
} | ||
//# sourceMappingURL=is-entirely-selected.js.map |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -8,16 +10,22 @@ value: true | ||
var _isHtmlInputElement = _interopRequireDefault(require("./is-html-input-element")); | ||
/** | ||
* Internal dependencies | ||
*/ | ||
/* eslint-disable jsdoc/valid-types */ | ||
/** | ||
* Check whether the given element is an input field of type number | ||
* and has a valueAsNumber | ||
* | ||
* @param {HTMLElement} element The HTML element. | ||
* @param {Node} node The HTML node. | ||
* | ||
* @return {boolean} True if the element is input and holds a number. | ||
* @return {node is HTMLInputElement} True if the node is input and holds a number. | ||
*/ | ||
function isNumberInput(element) { | ||
var nodeName = element.nodeName, | ||
type = element.type, | ||
valueAsNumber = element.valueAsNumber; | ||
return nodeName === 'INPUT' && type === 'number' && !!valueAsNumber; | ||
function isNumberInput(node) { | ||
/* eslint-enable jsdoc/valid-types */ | ||
return (0, _isHtmlInputElement.default)(node) && node.type === 'number' && !!node.valueAsNumber; | ||
} | ||
//# sourceMappingURL=is-number-input.js.map |
@@ -8,3 +8,9 @@ "use strict"; | ||
var _assertIsDefined = require("../utils/assert-is-defined"); | ||
/** | ||
* Internal dependencies | ||
*/ | ||
/** | ||
* Returns true if the given selection object is in the forward direction, or | ||
@@ -24,2 +30,4 @@ * false otherwise. | ||
focusOffset = selection.focusOffset; | ||
(0, _assertIsDefined.assertIsDefined)(anchorNode, 'anchorNode'); | ||
(0, _assertIsDefined.assertIsDefined)(focusNode, 'focusNode'); | ||
var position = anchorNode.compareDocumentPosition(focusNode); // Disable reason: `Node#compareDocumentPosition` returns a bitmask value, | ||
@@ -26,0 +34,0 @@ // so bitwise operators are intended. |
"use strict"; | ||
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); | ||
Object.defineProperty(exports, "__esModule", { | ||
@@ -8,3 +10,11 @@ value: true | ||
var _isHtmlInputElement = _interopRequireDefault(require("./is-html-input-element")); | ||
/** | ||
* Internal dependencies | ||
*/ | ||
/* eslint-disable jsdoc/valid-types */ | ||
/** | ||
* Check whether the given element is a text field, where text field is defined | ||
@@ -15,12 +25,12 @@ * by the ability to select within the input, or that it is contenteditable. | ||
* | ||
* @param {HTMLElement} element The HTML element. | ||
* | ||
* @return {boolean} True if the element is an text field, false if not. | ||
* @param {Node} node The HTML element. | ||
* @return {element is HTMLElement} True if the element is an text field, false if not. | ||
*/ | ||
function isTextField(element) { | ||
var nodeName = element.nodeName, | ||
contentEditable = element.contentEditable; | ||
function isTextField(node) { | ||
/* eslint-enable jsdoc/valid-types */ | ||
var nonTextInputs = ['button', 'checkbox', 'hidden', 'file', 'radio', 'image', 'range', 'reset', 'submit', 'number']; | ||
return nodeName === 'INPUT' && !nonTextInputs.includes(element.type) || nodeName === 'TEXTAREA' || contentEditable === 'true'; | ||
return (0, _isHtmlInputElement.default)(node) && node.type && !nonTextInputs.includes(node.type) || node.nodeName === 'TEXTAREA' || | ||
/** @type {HTMLElement} */ | ||
node.contentEditable === 'true'; | ||
} | ||
//# sourceMappingURL=is-text-field.js.map |
@@ -10,8 +10,10 @@ "use strict"; | ||
var _lodash = require("lodash"); | ||
var _assertIsDefined = require("../utils/assert-is-defined"); | ||
var _hiddenCaretRangeFromPoint = _interopRequireDefault(require("./hidden-caret-range-from-point")); | ||
var _isInputOrTextArea = _interopRequireDefault(require("./is-input-or-text-area")); | ||
/** | ||
* External dependencies | ||
* Internal dependencies | ||
*/ | ||
@@ -26,7 +28,9 @@ | ||
* | ||
* @param {Element} container Focusable element. | ||
* @param {HTMLElement} container Focusable element. | ||
* @param {boolean} isReverse True for end, false for start. | ||
* @param {boolean} mayUseScroll Whether to allow scrolling. | ||
* @param {boolean} [mayUseScroll=false] Whether to allow scrolling. | ||
*/ | ||
function placeCaretAtHorizontalEdge(container, isReverse, mayUseScroll) { | ||
function placeCaretAtHorizontalEdge(container, isReverse) { | ||
var mayUseScroll = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; | ||
if (!container) { | ||
@@ -38,3 +42,3 @@ return; | ||
if ((0, _lodash.includes)(['INPUT', 'TEXTAREA'], container.tagName)) { | ||
if ((0, _isInputOrTextArea.default)(container)) { | ||
// The element may not support selection setting. | ||
@@ -82,3 +86,5 @@ if (typeof container.selectionStart !== 'number') { | ||
var defaultView = ownerDocument.defaultView; | ||
(0, _assertIsDefined.assertIsDefined)(defaultView, 'defaultView'); | ||
var selection = defaultView.getSelection(); | ||
(0, _assertIsDefined.assertIsDefined)(selection, 'selection'); | ||
selection.removeAllRanges(); | ||
@@ -85,0 +91,0 @@ selection.addRange(range); |
@@ -14,2 +14,4 @@ "use strict"; | ||
var _assertIsDefined = require("../utils/assert-is-defined"); | ||
/** | ||
@@ -22,3 +24,3 @@ * Internal dependencies | ||
* | ||
* @param {Element} container Focusable element. | ||
* @param {HTMLElement} container Focusable element. | ||
* @param {boolean} isReverse True for bottom, false for top. | ||
@@ -67,3 +69,5 @@ * @param {DOMRect} [rect] The rectangle to position the caret with. | ||
(0, _assertIsDefined.assertIsDefined)(defaultView, 'defaultView'); | ||
var selection = defaultView.getSelection(); | ||
(0, _assertIsDefined.assertIsDefined)(selection, 'selection'); | ||
selection.removeAllRanges(); | ||
@@ -70,0 +74,0 @@ selection.addRange(range); |
@@ -20,4 +20,4 @@ "use strict"; | ||
* @param {string} HTML The HTML to clean up. | ||
* @param {Object} schema Schema for the HTML. | ||
* @param {Object} inline Whether to clean for inline mode. | ||
* @param {import('./clean-node-list').Schema} schema Schema for the HTML. | ||
* @param {boolean} inline Whether to clean for inline mode. | ||
* | ||
@@ -24,0 +24,0 @@ * @return {string} The cleaned up HTML. |
@@ -8,3 +8,9 @@ "use strict"; | ||
var _assertIsDefined = require("../utils/assert-is-defined"); | ||
/** | ||
* Internal dependencies | ||
*/ | ||
/** | ||
* Replaces the given node with a new node with the given tag name. | ||
@@ -24,2 +30,3 @@ * | ||
(0, _assertIsDefined.assertIsDefined)(node.parentNode, 'node.parentNode'); | ||
node.parentNode.replaceChild(newNode, node); | ||
@@ -26,0 +33,0 @@ return newNode; |
@@ -10,2 +10,4 @@ "use strict"; | ||
var _assertIsDefined = require("../utils/assert-is-defined"); | ||
var _insertAfter = _interopRequireDefault(require("./insert-after")); | ||
@@ -27,2 +29,3 @@ | ||
function replace(processedNode, newNode) { | ||
(0, _assertIsDefined.assertIsDefined)(processedNode.parentNode, 'processedNode.parentNode'); | ||
(0, _insertAfter.default)(newNode, processedNode.parentNode); | ||
@@ -29,0 +32,0 @@ (0, _remove.default)(processedNode); |
@@ -8,3 +8,9 @@ "use strict"; | ||
var _assertIsDefined = require("../utils/assert-is-defined"); | ||
/** | ||
* Internal dependencies | ||
*/ | ||
/** | ||
* Wraps the given node with a new node with the given tag name. | ||
@@ -16,2 +22,3 @@ * | ||
function wrap(newNode, referenceNode) { | ||
(0, _assertIsDefined.assertIsDefined)(referenceNode.parentNode, 'referenceNode.parentNode'); | ||
referenceNode.parentNode.insertBefore(newNode, referenceNode); | ||
@@ -18,0 +25,0 @@ newNode.appendChild(referenceNode); |
@@ -9,3 +9,3 @@ "use strict"; | ||
function assertIsDefined(val, name) { | ||
if (val === undefined || val === null) { | ||
if (process.env.NODE_ENV !== 'production' && (val === undefined || val === null)) { | ||
throw new Error("Expected '".concat(name, "' to be defined, but received ").concat(val)); | ||
@@ -12,0 +12,0 @@ } |
@@ -5,2 +5,8 @@ <!-- Learn how to maintain this file at https://github.com/WordPress/gutenberg/tree/HEAD/packages#maintaining-changelogs. --> | ||
## 2.18.0 (2021-04-29) | ||
### New Feature | ||
- Export type definitions | ||
## 2.17.0 (2021-03-17) | ||
@@ -12,3 +18,3 @@ | ||
- Add `documentHasUncollapsedSelection` to inquire about ranges of selected text in the document, including the separately managed selections inside <input> and <textarea> elements. | ||
- Add `documentHasUncollapsedSelection` to inquire about ranges of selected text in the document, including the separately managed selections inside <input> and <textarea> elements. | ||
@@ -19,3 +25,3 @@ ## 2.10.0 (2020-05-28) | ||
- Add `documentHasTextSelection` to inquire specifically about ranges of selected text, in addition to the existing `documentHasSelection`. | ||
- Add `documentHasTextSelection` to inquire specifically about ranges of selected text, in addition to the existing `documentHasSelection`. | ||
@@ -26,4 +32,4 @@ ## 2.1.0 (2019-03-06) | ||
- Update `isHorizontalEdge` to account for empty text nodes. | ||
- `tabbables.find` considers at most a single radio input for a given name. The checked input is given priority, falling back to the first in the tabindex-sorted set if there is no checked input. | ||
- Update `isHorizontalEdge` to account for empty text nodes. | ||
- `tabbables.find` considers at most a single radio input for a given name. The checked input is given priority, falling back to the first in the tabindex-sorted set if there is no checked input. | ||
@@ -46,2 +52,2 @@ ## 2.0.8 (2019-01-03) | ||
- Change how required built-ins are polyfilled with Babel 7 ([#9171](https://github.com/WordPress/gutenberg/pull/9171)). If you're using an environment that has limited or no support for ES2015+ such as lower versions of IE then using [core-js](https://github.com/zloirock/core-js) or [@babel/polyfill](https://babeljs.io/docs/en/next/babel-polyfill) will add support for these methods. | ||
- Change how required built-ins are polyfilled with Babel 7 ([#9171](https://github.com/WordPress/gutenberg/pull/9171)). If you're using an environment that has limited or no support for ES2015+ such as lower versions of IE then using [core-js](https://github.com/zloirock/core-js) or [@babel/polyfill](https://babeljs.io/docs/en/next/babel-polyfill) will add support for these methods. |
426
LICENSE.md
@@ -1,19 +0,23 @@ | ||
### WordPress - Web publishing software | ||
## Gutenberg | ||
Copyright 2011-2021 by the contributors | ||
Copyright 2016-2021 by the contributors | ||
This program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 2 of the License, or | ||
(at your option) any later version. | ||
**License for Contributions (on and after April 15, 2021)** | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
All code contributed to the Gutenberg project is dual-licensed, | ||
and released under both of the following licenses: | ||
You should have received a copy of the GNU General Public License | ||
along with this program; if not, write to the Free Software | ||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
the GNU General Public License as published by the Free Software Foundation; | ||
either version 2 of the License or (at your option) any later version (the “GPL”) | ||
and the Mozilla Public License, Version 2.0 (the “MPL”). | ||
**Project License** | ||
The Gutenberg project license is not affected by the License for Contributions (as | ||
discussed in the [Dual License section](#dual-license) below). The Gutenberg project | ||
continues to be free software; you can redistribute it and/or modify it | ||
under the terms of the GNU General Public License as published by the Free | ||
Software Foundation; either version 2 of the License or (at your option) any | ||
later version (the “GPL”). | ||
This program incorporates work covered by the following copyright and | ||
@@ -38,4 +42,45 @@ permission notices: | ||
### Dual License | ||
**We are currently in the process of changing Gutenberg’s software license from | ||
GPL to a dual license: GPL and MPL.** | ||
**This process involves two independent steps (1) obtaining permission for dual | ||
licensing from contributors of already contributed Gutenberg code and (2) | ||
dual licensing of all contributions to Gutenberg that are made on or after | ||
April 15, 2021.** | ||
**For part (1): We’re reaching out to everyone who has contributed code, prior | ||
to April 15, 2021, and asking that they agree to dual license their | ||
contribution to the project. We expect this process to be completed by | ||
mid-year, 2021.** | ||
**For part (2): We have changed the license for contributed code to this | ||
repository to make clear that all contributions on or after April 15, 2021 | ||
will be made under the dual-license.** | ||
**When we have received all necessary rights and permissions to dual license | ||
the pre-April 15, 2021 code of the Gutenberg project (Part 1 above), you will | ||
have the option to use and distribute all of the Gutenberg project under | ||
either the GPL or MPL license. At this time we will change the “Project | ||
License” to the following:** | ||
The Gutenberg project is free software; you can redistribute it and/or modify | ||
it under the terms of either of the following licenses: | ||
1. the GNU General Public License as published by the Free Software Foundation; | ||
either version 2 of the License or (at your option) any later version (the | ||
“GPL”) OR | ||
2. the Mozilla Public License Version 2.0 (the “MPL”). | ||
--- | ||
## Full Text of Referenced Licenses | ||
1. [GNU General Public License, Version 2](#gnu-general-public-license-version-2) | ||
2. [Mozilla Public License, Version 2.0](#mozilla-public-license-version-20) | ||
## GNU General Public License, Version 2 | ||
### GNU GENERAL PUBLIC LICENSE | ||
@@ -139,7 +184,5 @@ | ||
**a)** You must cause the modified files to carry prominent notices | ||
stating that you changed the files and the date of any change. | ||
**b)** You must cause any work that you distribute or publish, that in | ||
@@ -150,3 +193,2 @@ whole or in part contains or is derived from the Program or any part | ||
**c)** If the modified program normally reads commands interactively | ||
@@ -188,3 +230,2 @@ when run, you must cause it, when started running for such interactive | ||
**a)** Accompany it with the complete corresponding machine-readable | ||
@@ -194,3 +235,2 @@ source code, which must be distributed under the terms of Sections 1 | ||
**b)** Accompany it with a written offer, valid for at least three | ||
@@ -203,3 +243,2 @@ years, to give any third party, for a charge no more than your cost of | ||
**c)** Accompany it with the information you received as to the offer | ||
@@ -407,1 +446,350 @@ to distribute corresponding source code. (This alternative is allowed | ||
License. | ||
--- | ||
## Mozilla Public License, Version 2.0 | ||
### 1. Definitions | ||
**1.1. “Contributor”** | ||
means each individual or legal entity that creates, contributes to | ||
the creation of, or owns Covered Software. | ||
**1.2. “Contributor Version”** | ||
means the combination of the Contributions of others (if any) used | ||
by a Contributor and that particular Contributor's Contribution. | ||
**1.3. “Contribution”** | ||
means Covered Software of a particular Contributor. | ||
**1.4. “Covered Software”** | ||
means Source Code Form to which the initial Contributor has attached | ||
the notice in Exhibit A, the Executable Form of such Source Code | ||
Form, and Modifications of such Source Code Form, in each case | ||
including portions thereof. | ||
**1.5. “Incompatible With Secondary Licenses”** | ||
means | ||
- **(a)** that the initial Contributor has attached the notice described | ||
in Exhibit B to the Covered Software; or | ||
- **(b)** that the Covered Software was made available under the terms of | ||
version 1.1 or earlier of the License, but not also under the | ||
terms of a Secondary License. | ||
**1.6. “Executable Form”** | ||
means any form of the work other than Source Code Form. | ||
**1.7. “Larger Work”** | ||
means a work that combines Covered Software with other material, in | ||
a separate file or files, that is not Covered Software. | ||
**1.8. “License”** | ||
means this document. | ||
**1.9. “Licensable”** | ||
means having the right to grant, to the maximum extent possible, | ||
whether at the time of the initial grant or subsequently, any and | ||
all of the rights conveyed by this License. | ||
**1.10. “Modifications”** | ||
means any of the following: | ||
- **(a)** any file in Source Code Form that results from an addition to, | ||
deletion from, or modification of the contents of Covered | ||
Software; or | ||
- **(b)** any new file in Source Code Form that contains any Covered | ||
Software. | ||
**1.11. “Patent Claims” of a Contributor** | ||
means any patent claim(s), including without limitation, method, | ||
process, and apparatus claims, in any patent Licensable by such | ||
Contributor that would be infringed, but for the grant of the | ||
License, by the making, using, selling, offering for sale, having | ||
made, import, or transfer of either its Contributions or its | ||
Contributor Version. | ||
**1.12. “Secondary License”** | ||
means either the GNU General Public License, Version 2.0, the GNU | ||
Lesser General Public License, Version 2.1, the GNU Affero General | ||
Public License, Version 3.0, or any later versions of those | ||
licenses. | ||
**1.13. “Source Code Form”** | ||
means the form of the work preferred for making modifications. | ||
**1.14. “You” (or “Your”)** | ||
means an individual or a legal entity exercising rights under this | ||
License. For legal entities, “You” includes any entity that | ||
controls, is controlled by, or is under common control with You. For | ||
purposes of this definition, “control” means **(a)** the power, direct | ||
or indirect, to cause the direction or management of such entity, | ||
whether by contract or otherwise, or **(b)** ownership of more than | ||
fifty percent (50%) of the outstanding shares or beneficial | ||
ownership of such entity. | ||
### 2. License Grants and Conditions | ||
#### 2.1. Grants | ||
Each Contributor hereby grants You a world-wide, royalty-free, | ||
non-exclusive license: | ||
- **(a)** under intellectual property rights (other than patent or trademark) | ||
Licensable by such Contributor to use, reproduce, make available, | ||
modify, display, perform, distribute, and otherwise exploit its | ||
Contributions, either on an unmodified basis, with Modifications, or | ||
as part of a Larger Work; and | ||
- **(b)** under Patent Claims of such Contributor to make, use, sell, offer | ||
for sale, have made, import, and otherwise transfer either its | ||
Contributions or its Contributor Version. | ||
#### 2.2. Effective Date | ||
The licenses granted in Section 2.1 with respect to any Contribution | ||
become effective for each Contribution on the date the Contributor first | ||
distributes such Contribution. | ||
#### 2.3. Limitations on Grant Scope | ||
The licenses granted in this Section 2 are the only rights granted under | ||
this License. No additional rights or licenses will be implied from the | ||
distribution or licensing of Covered Software under this License. | ||
Notwithstanding Section 2.1(b) above, no patent license is granted by a | ||
Contributor: | ||
- **(a)** for any code that a Contributor has removed from Covered Software; | ||
or | ||
- **(b)** for infringements caused by: **(i)** Your and any other third party's | ||
modifications of Covered Software, or **(ii)** the combination of its | ||
Contributions with other software (except as part of its Contributor | ||
Version); or | ||
- **(c)** under Patent Claims infringed by Covered Software in the absence of | ||
its Contributions. | ||
This License does not grant any rights in the trademarks, service marks, | ||
or logos of any Contributor (except as may be necessary to comply with | ||
the notice requirements in Section 3.4). | ||
#### 2.4. Subsequent Licenses | ||
No Contributor makes additional grants as a result of Your choice to | ||
distribute the Covered Software under a subsequent version of this | ||
License (see Section 10.2) or under the terms of a Secondary License (if | ||
permitted under the terms of Section 3.3). | ||
#### 2.5. Representation | ||
Each Contributor represents that the Contributor believes its | ||
Contributions are its original creation(s) or it has sufficient rights | ||
to grant the rights to its Contributions conveyed by this License. | ||
#### 2.6. Fair Use | ||
This License is not intended to limit any rights You have under | ||
applicable copyright doctrines of fair use, fair dealing, or other | ||
equivalents. | ||
#### 2.7. Conditions | ||
Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted | ||
in Section 2.1. | ||
### 3. Responsibilities | ||
#### 3.1. Distribution of Source Form | ||
All distribution of Covered Software in Source Code Form, including any | ||
Modifications that You create or to which You contribute, must be under | ||
the terms of this License. You must inform recipients that the Source | ||
Code Form of the Covered Software is governed by the terms of this | ||
License, and how they can obtain a copy of this License. You may not | ||
attempt to alter or restrict the recipients' rights in the Source Code | ||
Form. | ||
#### 3.2. Distribution of Executable Form | ||
If You distribute Covered Software in Executable Form then: | ||
- **(a)** such Covered Software must also be made available in Source Code | ||
Form, as described in Section 3.1, and You must inform recipients of | ||
the Executable Form how they can obtain a copy of such Source Code | ||
Form by reasonable means in a timely manner, at a charge no more | ||
than the cost of distribution to the recipient; and | ||
- **(b)** You may distribute such Executable Form under the terms of this | ||
License, or sublicense it under different terms, provided that the | ||
license for the Executable Form does not attempt to limit or alter | ||
the recipients' rights in the Source Code Form under this License. | ||
#### 3.3. Distribution of a Larger Work | ||
You may create and distribute a Larger Work under terms of Your choice, | ||
provided that You also comply with the requirements of this License for | ||
the Covered Software. If the Larger Work is a combination of Covered | ||
Software with a work governed by one or more Secondary Licenses, and the | ||
Covered Software is not Incompatible With Secondary Licenses, this | ||
License permits You to additionally distribute such Covered Software | ||
under the terms of such Secondary License(s), so that the recipient of | ||
the Larger Work may, at their option, further distribute the Covered | ||
Software under the terms of either this License or such Secondary | ||
License(s). | ||
#### 3.4. Notices | ||
You may not remove or alter the substance of any license notices | ||
(including copyright notices, patent notices, disclaimers of warranty, | ||
or limitations of liability) contained within the Source Code Form of | ||
the Covered Software, except that You may alter any license notices to | ||
the extent required to remedy known factual inaccuracies. | ||
#### 3.5. Application of Additional Terms | ||
You may choose to offer, and to charge a fee for, warranty, support, | ||
indemnity or liability obligations to one or more recipients of Covered | ||
Software. However, You may do so only on Your own behalf, and not on | ||
behalf of any Contributor. You must make it absolutely clear that any | ||
such warranty, support, indemnity, or liability obligation is offered by | ||
You alone, and You hereby agree to indemnify every Contributor for any | ||
liability incurred by such Contributor as a result of warranty, support, | ||
indemnity or liability terms You offer. You may include additional | ||
disclaimers of warranty and limitations of liability specific to any | ||
jurisdiction. | ||
### 4. Inability to Comply Due to Statute or Regulation | ||
If it is impossible for You to comply with any of the terms of this | ||
License with respect to some or all of the Covered Software due to | ||
statute, judicial order, or regulation then You must: **(a)** comply with | ||
the terms of this License to the maximum extent possible; and **(b)** | ||
describe the limitations and the code they affect. Such description must | ||
be placed in a text file included with all distributions of the Covered | ||
Software under this License. Except to the extent prohibited by statute | ||
or regulation, such description must be sufficiently detailed for a | ||
recipient of ordinary skill to be able to understand it. | ||
### 5. Termination | ||
**5.1.** The rights granted under this License will terminate automatically | ||
if You fail to comply with any of its terms. However, if You become | ||
compliant, then the rights granted under this License from a particular | ||
Contributor are reinstated **(a)** provisionally, unless and until such | ||
Contributor explicitly and finally terminates Your grants, and **(b)** on an | ||
ongoing basis, if such Contributor fails to notify You of the | ||
non-compliance by some reasonable means prior to 60 days after You have | ||
come back into compliance. Moreover, Your grants from a particular | ||
Contributor are reinstated on an ongoing basis if such Contributor | ||
notifies You of the non-compliance by some reasonable means, this is the | ||
first time You have received notice of non-compliance with this License | ||
from such Contributor, and You become compliant prior to 30 days after | ||
Your receipt of the notice. | ||
**5.2.** If You initiate litigation against any entity by asserting a patent | ||
infringement claim (excluding declaratory judgment actions, | ||
counter-claims, and cross-claims) alleging that a Contributor Version | ||
directly or indirectly infringes any patent, then the rights granted to | ||
You by any and all Contributors for the Covered Software under Section | ||
2.1 of this License shall terminate. | ||
**5.3.** In the event of termination under Sections 5.1 or 5.2 above, all | ||
end user license agreements (excluding distributors and resellers) which | ||
have been validly granted by You or Your distributors under this License | ||
prior to termination shall survive termination. | ||
### 6. Disclaimer of Warranty | ||
> Covered Software is provided under this License on an “as is” | ||
> basis, without warranty of any kind, either expressed, implied, or | ||
> statutory, including, without limitation, warranties that the | ||
> Covered Software is free of defects, merchantable, fit for a | ||
> particular purpose or non-infringing. The entire risk as to the | ||
> quality and performance of the Covered Software is with You. | ||
> Should any Covered Software prove defective in any respect, You | ||
> (not any Contributor) assume the cost of any necessary servicing, | ||
> repair, or correction. This disclaimer of warranty constitutes an | ||
> essential part of this License. No use of any Covered Software is | ||
> authorized under this License except under this disclaimer. | ||
### 7. Limitation of Liability | ||
> Under no circumstances and under no legal theory, whether tort | ||
> (including negligence), contract, or otherwise, shall any | ||
> Contributor, or anyone who distributes Covered Software as | ||
> permitted above, be liable to You for any direct, indirect, | ||
> special, incidental, or consequential damages of any character | ||
> including, without limitation, damages for lost profits, loss of | ||
> goodwill, work stoppage, computer failure or malfunction, or any | ||
> and all other commercial damages or losses, even if such party | ||
> shall have been informed of the possibility of such damages. This | ||
> limitation of liability shall not apply to liability for death or | ||
> personal injury resulting from such party's negligence to the | ||
> extent applicable law prohibits such limitation. Some | ||
> jurisdictions do not allow the exclusion or limitation of | ||
> incidental or consequential damages, so this exclusion and | ||
> limitation may not apply to You. | ||
### 8. Litigation | ||
Any litigation relating to this License may be brought only in the | ||
courts of a jurisdiction where the defendant maintains its principal | ||
place of business and such litigation shall be governed by laws of that | ||
jurisdiction, without reference to its conflict-of-law provisions. | ||
Nothing in this Section shall prevent a party's ability to bring | ||
cross-claims or counter-claims. | ||
### 9. Miscellaneous | ||
This License represents the complete agreement concerning the subject | ||
matter hereof. If any provision of this License is held to be | ||
unenforceable, such provision shall be reformed only to the extent | ||
necessary to make it enforceable. Any law or regulation which provides | ||
that the language of a contract shall be construed against the drafter | ||
shall not be used to construe this License against a Contributor. | ||
### 10. Versions of the License | ||
#### 10.1. New Versions | ||
Mozilla Foundation is the license steward. Except as provided in Section | ||
10.3, no one other than the license steward has the right to modify or | ||
publish new versions of this License. Each version will be given a | ||
distinguishing version number. | ||
#### 10.2. Effect of New Versions | ||
You may distribute the Covered Software under the terms of the version | ||
of the License under which You originally received the Covered Software, | ||
or under the terms of any subsequent version published by the license | ||
steward. | ||
#### 10.3. Modified Versions | ||
If you create software not governed by this License, and you want to | ||
create a new license for such software, you may create and use a | ||
modified version of this License if you rename the license and remove | ||
any references to the name of the license steward (except to note that | ||
such modified license differs from this License). | ||
#### 10.4. Distributing Source Code Form that is Incompatible With Secondary Licenses | ||
If You choose to distribute Source Code Form that is Incompatible With | ||
Secondary Licenses under the terms of this version of the License, the | ||
notice described in Exhibit B of this License must be attached. | ||
## Exhibit A - Source Code Form License Notice | ||
This Source Code Form is subject to the terms of the Mozilla Public | ||
License, v. 2.0. If a copy of the MPL was not distributed with this | ||
file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
If it is not possible or desirable to put the notice in a particular | ||
file, then You may include the notice in a location (such as a LICENSE | ||
file in a relevant directory) where a recipient would be likely to look | ||
for such a notice. | ||
You may add additional accurate notices of copyright ownership. | ||
## Exhibit B - “Incompatible With Secondary Licenses” Notice | ||
This Source Code Form is "Incompatible With Secondary Licenses", as | ||
defined by the Mozilla Public License, v. 2.0. |
{ | ||
"name": "@wordpress/dom", | ||
"version": "2.17.2", | ||
"version": "2.18.0", | ||
"description": "DOM utilities module for WordPress.", | ||
@@ -25,2 +25,3 @@ "author": "The WordPress Contributors", | ||
"react-native": "src/index", | ||
"types": "build-types", | ||
"sideEffects": false, | ||
@@ -34,3 +35,3 @@ "dependencies": { | ||
}, | ||
"gitHead": "a71b0769184b8b1cf0c86f3c99d452ef7491b096" | ||
"gitHead": "4abe97cdbdf5e12bfc95b68c74cd0baa6583fc65" | ||
} |
@@ -105,3 +105,3 @@ # DOM | ||
- `?Node`: Offset parent. | ||
- `Node | null`: Offset parent. | ||
@@ -142,7 +142,7 @@ <a name="getPhrasingContentSchema" href="#getPhrasingContentSchema">#</a> **getPhrasingContentSchema** | ||
- _node_ `Element`: Node from which to start. | ||
- _node_ `Element | null`: Node from which to start. | ||
_Returns_ | ||
- `?Element`: Scrollable container node, if found. | ||
- `Element | undefined`: Scrollable container node, if found. | ||
@@ -183,3 +183,3 @@ <a name="insertAfter" href="#insertAfter">#</a> **insertAfter** | ||
- _element_ `Element`: The element to check. | ||
- _element_ `HTMLElement`: The element to check. | ||
@@ -210,7 +210,7 @@ _Returns_ | ||
- _element_ `HTMLElement`: The HTML element. | ||
- _node_ `Node`: The HTML node. | ||
_Returns_ | ||
- `boolean`: True if the element is input and holds a number. | ||
- `node is HTMLInputElement`: True if the node is input and holds a number. | ||
@@ -252,7 +252,7 @@ <a name="isPhrasingContent" href="#isPhrasingContent">#</a> **isPhrasingContent** | ||
- _element_ `HTMLElement`: The HTML element. | ||
- _node_ `Node`: The HTML element. | ||
_Returns_ | ||
- `boolean`: True if the element is an text field, false if not. | ||
- `element is HTMLElement`: True if the element is an text field, false if not. | ||
@@ -278,5 +278,5 @@ <a name="isVerticalEdge" href="#isVerticalEdge">#</a> **isVerticalEdge** | ||
- _container_ `Element`: Focusable element. | ||
- _container_ `HTMLElement`: Focusable element. | ||
- _isReverse_ `boolean`: True for end, false for start. | ||
- _mayUseScroll_ `boolean`: Whether to allow scrolling. | ||
- _mayUseScroll_ `[boolean]`: Whether to allow scrolling. | ||
@@ -289,3 +289,3 @@ <a name="placeCaretAtVerticalEdge" href="#placeCaretAtVerticalEdge">#</a> **placeCaretAtVerticalEdge** | ||
- _container_ `Element`: Focusable element. | ||
- _container_ `HTMLElement`: Focusable element. | ||
- _isReverse_ `boolean`: True for bottom, false for top. | ||
@@ -314,4 +314,4 @@ - _rect_ `[DOMRect]`: The rectangle to position the caret with. | ||
- _HTML_ `string`: The HTML to clean up. | ||
- _schema_ `Object`: Schema for the HTML. | ||
- _inline_ `Object`: Whether to clean for inline mode. | ||
- _schema_ `import('./clean-node-list').Schema`: Schema for the HTML. | ||
- _inline_ `boolean`: Whether to clean for inline mode. | ||
@@ -318,0 +318,0 @@ _Returns_ |
@@ -18,6 +18,7 @@ /** | ||
return ( | ||
isTextField( doc.activeElement ) || | ||
isNumberInput( doc.activeElement ) || | ||
documentHasTextSelection( doc ) | ||
!! doc.activeElement && | ||
( isTextField( doc.activeElement ) || | ||
isNumberInput( doc.activeElement ) || | ||
documentHasTextSelection( doc ) ) | ||
); | ||
} |
/** | ||
* Internal dependencies | ||
*/ | ||
import { assertIsDefined } from '../utils/assert-is-defined'; | ||
/** | ||
* Check whether the current document has selected text. This applies to ranges | ||
@@ -13,5 +18,7 @@ * of text in the document, and not selection inside <input> and <textarea> | ||
export default function documentHasTextSelection( doc ) { | ||
assertIsDefined( doc.defaultView, 'doc.defaultView' ); | ||
const selection = doc.defaultView.getSelection(); | ||
assertIsDefined( selection, 'selection' ); | ||
const range = selection.rangeCount ? selection.getRangeAt( 0 ) : null; | ||
return range && ! range.collapsed; | ||
return !! range && ! range.collapsed; | ||
} |
@@ -19,4 +19,5 @@ /** | ||
documentHasTextSelection( doc ) || | ||
inputFieldHasUncollapsedSelection( doc.activeElement ) | ||
( !! doc.activeElement && | ||
inputFieldHasUncollapsedSelection( doc.activeElement ) ) | ||
); | ||
} |
@@ -1,3 +0,18 @@ | ||
export default function getComputedStyle( node ) { | ||
return node.ownerDocument.defaultView.getComputedStyle( node ); | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { assertIsDefined } from '../utils/assert-is-defined'; | ||
/* eslint-disable jsdoc/valid-types */ | ||
/** | ||
* @param {Element} element | ||
* @return {ReturnType<Window['getComputedStyle']>} The computed style for the element. | ||
*/ | ||
export default function getComputedStyle( element ) { | ||
/* eslint-enable jsdoc/valid-types */ | ||
assertIsDefined( | ||
element.ownerDocument.defaultView, | ||
'element.ownerDocument.defaultView' | ||
); | ||
return element.ownerDocument.defaultView.getComputedStyle( element ); | ||
} |
@@ -15,3 +15,3 @@ /** | ||
* | ||
* @return {?Node} Offset parent. | ||
* @return {Node | null} Offset parent. | ||
*/ | ||
@@ -22,3 +22,3 @@ export default function getOffsetParent( node ) { | ||
let closestElement; | ||
while ( ( closestElement = node.parentNode ) ) { | ||
while ( ( closestElement = /** @type {Node} */ ( node.parentNode ) ) ) { | ||
if ( closestElement.nodeType === closestElement.ELEMENT_NODE ) { | ||
@@ -35,7 +35,12 @@ break; | ||
// does not otherwise consider the node itself. | ||
if ( getComputedStyle( closestElement ).position !== 'static' ) { | ||
if ( | ||
getComputedStyle( /** @type {Element} */ ( closestElement ) ) | ||
.position !== 'static' | ||
) { | ||
return closestElement; | ||
} | ||
return closestElement.offsetParent; | ||
// offsetParent is undocumented/draft | ||
return /** @type {Node & { offsetParent: Node }} */ ( closestElement ) | ||
.offsetParent; | ||
} |
@@ -6,2 +6,3 @@ /** | ||
* @param {Range} range The range to check. | ||
* @return {number | undefined} Height of the range or undefined if the range has no client rectangles. | ||
*/ | ||
@@ -8,0 +9,0 @@ export default function getRangeHeight( range ) { |
@@ -9,9 +9,9 @@ /** | ||
* | ||
* @param {Element} node Node from which to start. | ||
* @param {Element | null} node Node from which to start. | ||
* | ||
* @return {?Element} Scrollable container node, if found. | ||
* @return {Element | undefined} Scrollable container node, if found. | ||
*/ | ||
export default function getScrollContainer( node ) { | ||
if ( ! node ) { | ||
return; | ||
return undefined; | ||
} | ||
@@ -29,3 +29,3 @@ | ||
// Continue traversing | ||
return getScrollContainer( node.parentNode ); | ||
return getScrollContainer( /** @type {Element} */ ( node.parentNode ) ); | ||
} |
@@ -15,3 +15,3 @@ /** |
* @param {number} y Vertical position within the current viewport. |
* @param {Element} container Container in which the range is expected to be found. |
* @param {HTMLElement} container Container in which the range is expected to be found. |
* |
@@ -18,0 +18,0 @@ * @return {?Range} The best range for the given point. |
@@ -16,3 +16,3 @@ /** | ||
* | ||
* @param {HTMLElement} element The HTML element. | ||
* @param {Element} element The HTML element. | ||
* | ||
@@ -26,3 +26,6 @@ * @return {boolean} Whether the input/textareaa element has some "selection". | ||
try { | ||
const { selectionStart, selectionEnd } = element; | ||
const { | ||
selectionStart, | ||
selectionEnd, | ||
} = /** @type {HTMLInputElement | HTMLTextAreaElement} */ ( element ); | ||
@@ -29,0 +32,0 @@ return selectionStart !== null && selectionStart !== selectionEnd; |
/** | ||
* External dependencies | ||
*/ | ||
import { includes } from 'lodash'; | ||
/** | ||
* Internal dependencies | ||
@@ -14,2 +9,4 @@ */ | ||
import hiddenCaretRangeFromPoint from './hidden-caret-range-from-point'; | ||
import { assertIsDefined } from '../utils/assert-is-defined'; | ||
import isInputOrTextArea from './is-input-or-text-area'; | ||
@@ -21,10 +18,10 @@ /** | ||
* | ||
* @param {Element} container Focusable element. | ||
* @param {boolean} isReverse Set to true to check left, false to check right. | ||
* @param {boolean} onlyVertical Set to true to check only vertical position. | ||
* @param {Element} container Focusable element. | ||
* @param {boolean} isReverse Set to true to check left, false to check right. | ||
* @param {boolean} [onlyVertical=false] Set to true to check only vertical position. | ||
* | ||
* @return {boolean} True if at the edge, false if not. | ||
*/ | ||
export default function isEdge( container, isReverse, onlyVertical ) { | ||
if ( includes( [ 'INPUT', 'TEXTAREA' ], container.tagName ) ) { | ||
export default function isEdge( container, isReverse, onlyVertical = false ) { | ||
if ( isInputOrTextArea( container ) ) { | ||
if ( container.selectionStart !== container.selectionEnd ) { | ||
@@ -41,3 +38,3 @@ return false; | ||
if ( ! container.isContentEditable ) { | ||
if ( ! (/** @type {HTMLElement} */ ( container ).isContentEditable) ) { | ||
return true; | ||
@@ -49,5 +46,6 @@ } | ||
assertIsDefined( defaultView, 'defaultView' ); | ||
const selection = defaultView.getSelection(); | ||
if ( ! selection.rangeCount ) { | ||
if ( ! selection || ! selection.rangeCount ) { | ||
return false; | ||
@@ -76,5 +74,7 @@ } | ||
// collapsed selection. | ||
const rangeHeight = getRangeHeight( range ); | ||
if ( | ||
! isCollapsed && | ||
getRangeHeight( range ) > collapsedRangeRect.height && | ||
rangeHeight && | ||
rangeHeight > collapsedRangeRect.height && | ||
isForward === isReverse | ||
@@ -107,3 +107,3 @@ ) { | ||
y, | ||
container | ||
/** @type {HTMLElement} */ ( container ) | ||
); | ||
@@ -110,0 +110,0 @@ |
/** | ||
* External dependencies | ||
* Internal dependencies | ||
*/ | ||
import { includes } from 'lodash'; | ||
import { assertIsDefined } from '../utils/assert-is-defined'; | ||
import isInputOrTextArea from './is-input-or-text-area'; | ||
@@ -10,3 +11,3 @@ /** | ||
* | ||
* @param {Element} element The element to check. | ||
* @param {HTMLElement} element The element to check. | ||
* | ||
@@ -16,3 +17,3 @@ * @return {boolean} True if entirely selected, false if not. | ||
export default function isEntirelySelected( element ) { | ||
if ( includes( [ 'INPUT', 'TEXTAREA' ], element.nodeName ) ) { | ||
if ( isInputOrTextArea( element ) ) { | ||
return ( | ||
@@ -30,3 +31,5 @@ element.selectionStart === 0 && | ||
const { defaultView } = ownerDocument; | ||
assertIsDefined( defaultView, 'defaultView' ); | ||
const selection = defaultView.getSelection(); | ||
assertIsDefined( selection, 'selection' ); | ||
const range = selection.rangeCount ? selection.getRangeAt( 0 ) : null; | ||
@@ -50,5 +53,6 @@ | ||
const lastChild = element.lastChild; | ||
assertIsDefined( lastChild, 'lastChild' ); | ||
const lastChildContentLength = | ||
lastChild.nodeType === lastChild.TEXT_NODE | ||
? lastChild.data.length | ||
? /** @type {Text} */ ( lastChild ).data.length | ||
: lastChild.childNodes.length; | ||
@@ -55,0 +59,0 @@ |
/** | ||
* Internal dependencies | ||
*/ | ||
import isHTMLInputElement from './is-html-input-element'; | ||
/* eslint-disable jsdoc/valid-types */ | ||
/** | ||
* Check whether the given element is an input field of type number | ||
* and has a valueAsNumber | ||
* | ||
* @param {HTMLElement} element The HTML element. | ||
* @param {Node} node The HTML node. | ||
* | ||
* @return {boolean} True if the element is input and holds a number. | ||
* @return {node is HTMLInputElement} True if the node is input and holds a number. | ||
*/ | ||
export default function isNumberInput( element ) { | ||
const { nodeName, type, valueAsNumber } = element; | ||
return nodeName === 'INPUT' && type === 'number' && !! valueAsNumber; | ||
export default function isNumberInput( node ) { | ||
/* eslint-enable jsdoc/valid-types */ | ||
return ( | ||
isHTMLInputElement( node ) && | ||
node.type === 'number' && | ||
!! node.valueAsNumber | ||
); | ||
} |
/** | ||
* Internal dependencies | ||
*/ | ||
import { assertIsDefined } from '../utils/assert-is-defined'; | ||
/** | ||
* Returns true if the given selection object is in the forward direction, or | ||
@@ -14,2 +19,4 @@ * false otherwise. | ||
assertIsDefined( anchorNode, 'anchorNode' ); | ||
assertIsDefined( focusNode, 'focusNode' ); | ||
const position = anchorNode.compareDocumentPosition( focusNode ); | ||
@@ -16,0 +23,0 @@ |
/** | ||
* Internal dependencies | ||
*/ | ||
import isHTMLInputElement from './is-html-input-element'; | ||
/* eslint-disable jsdoc/valid-types */ | ||
/** | ||
* Check whether the given element is a text field, where text field is defined | ||
@@ -7,8 +13,7 @@ * by the ability to select within the input, or that it is contenteditable. | ||
* | ||
* @param {HTMLElement} element The HTML element. | ||
* | ||
* @return {boolean} True if the element is an text field, false if not. | ||
* @param {Node} node The HTML element. | ||
* @return {element is HTMLElement} True if the element is an text field, false if not. | ||
*/ | ||
export default function isTextField( element ) { | ||
const { nodeName, contentEditable } = element; | ||
export default function isTextField( node ) { | ||
/* eslint-enable jsdoc/valid-types */ | ||
const nonTextInputs = [ | ||
@@ -27,6 +32,8 @@ 'button', | ||
return ( | ||
( nodeName === 'INPUT' && ! nonTextInputs.includes( element.type ) ) || | ||
nodeName === 'TEXTAREA' || | ||
contentEditable === 'true' | ||
( isHTMLInputElement( node ) && | ||
node.type && | ||
! nonTextInputs.includes( node.type ) ) || | ||
node.nodeName === 'TEXTAREA' || | ||
/** @type {HTMLElement} */ ( node ).contentEditable === 'true' | ||
); | ||
} |
/** | ||
* External dependencies | ||
* Internal dependencies | ||
*/ | ||
import { includes } from 'lodash'; | ||
import { assertIsDefined } from '../utils/assert-is-defined'; | ||
@@ -10,2 +10,3 @@ /** | ||
import hiddenCaretRangeFromPoint from './hidden-caret-range-from-point'; | ||
import isInputOrTextArea from './is-input-or-text-area'; | ||
@@ -15,5 +16,5 @@ /** | ||
* | ||
* @param {Element} container Focusable element. | ||
* @param {HTMLElement} container Focusable element. | ||
* @param {boolean} isReverse True for end, false for start. | ||
* @param {boolean} mayUseScroll Whether to allow scrolling. | ||
* @param {boolean} [mayUseScroll=false] Whether to allow scrolling. | ||
*/ | ||
@@ -23,3 +24,3 @@ export default function placeCaretAtHorizontalEdge( | ||
isReverse, | ||
mayUseScroll | ||
mayUseScroll = false | ||
) { | ||
@@ -32,3 +33,3 @@ if ( ! container ) { | ||
if ( includes( [ 'INPUT', 'TEXTAREA' ], container.tagName ) ) { | ||
if ( isInputOrTextArea( container ) ) { | ||
// The element may not support selection setting. | ||
@@ -81,5 +82,7 @@ if ( typeof container.selectionStart !== 'number' ) { | ||
const { defaultView } = ownerDocument; | ||
assertIsDefined( defaultView, 'defaultView' ); | ||
const selection = defaultView.getSelection(); | ||
assertIsDefined( selection, 'selection' ); | ||
selection.removeAllRanges(); | ||
selection.addRange( range ); | ||
} |
@@ -6,2 +6,3 @@ /** | ||
import hiddenCaretRangeFromPoint from './hidden-caret-range-from-point'; | ||
import { assertIsDefined } from '../utils/assert-is-defined'; | ||
@@ -11,3 +12,3 @@ /** | ||
* | ||
* @param {Element} container Focusable element. | ||
* @param {HTMLElement} container Focusable element. | ||
* @param {boolean} isReverse True for bottom, false for top. | ||
@@ -67,3 +68,5 @@ * @param {DOMRect} [rect] The rectangle to position the caret with. | ||
assertIsDefined( defaultView, 'defaultView' ); | ||
const selection = defaultView.getSelection(); | ||
assertIsDefined( selection, 'selection' ); | ||
selection.removeAllRanges(); | ||
@@ -70,0 +73,0 @@ selection.addRange( range ); |
@@ -10,4 +10,4 @@ /** | ||
* @param {string} HTML The HTML to clean up. | ||
* @param {Object} schema Schema for the HTML. | ||
* @param {Object} inline Whether to clean for inline mode. | ||
* @param {import('./clean-node-list').Schema} schema Schema for the HTML. | ||
* @param {boolean} inline Whether to clean for inline mode. | ||
* | ||
@@ -14,0 +14,0 @@ * @return {string} The cleaned up HTML. |
/** | ||
* Internal dependencies | ||
*/ | ||
import { assertIsDefined } from '../utils/assert-is-defined'; | ||
/** | ||
* Replaces the given node with a new node with the given tag name. | ||
@@ -16,2 +21,3 @@ * | ||
assertIsDefined( node.parentNode, 'node.parentNode' ); | ||
node.parentNode.replaceChild( newNode, node ); | ||
@@ -18,0 +24,0 @@ |
/** | ||
* Internal dependencies | ||
*/ | ||
import { assertIsDefined } from '../utils/assert-is-defined'; | ||
import insertAfter from './insert-after'; | ||
@@ -15,4 +16,5 @@ import remove from './remove'; | ||
export default function replace( processedNode, newNode ) { | ||
assertIsDefined( processedNode.parentNode, 'processedNode.parentNode' ); | ||
insertAfter( newNode, processedNode.parentNode ); | ||
remove( processedNode ); | ||
} |
/** | ||
* Internal dependencies | ||
*/ | ||
import { assertIsDefined } from '../utils/assert-is-defined'; | ||
/** | ||
* Wraps the given node with a new node with the given tag name. | ||
@@ -8,4 +13,5 @@ * | ||
export default function wrap( newNode, referenceNode ) { | ||
assertIsDefined( referenceNode.parentNode, 'referenceNode.parentNode' ); | ||
referenceNode.parentNode.insertBefore( newNode, referenceNode ); | ||
newNode.appendChild( referenceNode ); | ||
} |
@@ -5,3 +5,6 @@ export function assertIsDefined< T >( | ||
): asserts val is NonNullable< T > { | ||
if ( val === undefined || val === null ) { | ||
if ( | ||
process.env.NODE_ENV !== 'production' && | ||
( val === undefined || val === null ) | ||
) { | ||
throw new Error( | ||
@@ -8,0 +11,0 @@ `Expected '${ name }' to be defined, but received ${ val }` |
@@ -5,20 +5,8 @@ { | ||
"rootDir": "src", | ||
"declarationDir": "build-types" | ||
"declarationDir": "build-types", | ||
"types": [ "gutenberg-env" ] | ||
}, | ||
"include": [ | ||
"src/data-transfer.js", | ||
"src/dom/caret-range-from-point.js", | ||
"src/dom/clean-node-list.js", | ||
"src/dom/compute-caret-rect.js", | ||
"src/dom/get-rectangle-from-range.js", | ||
"src/dom/is-empty.js", | ||
"src/dom/is-element.js", | ||
"src/dom/insert-after.js", | ||
"src/dom/remove.js", | ||
"src/dom/unwrap.js", | ||
"src/utils/**/*", | ||
"src/focusable.js", | ||
"src/phrasing-content.js", | ||
"src/tabbable.js", | ||
"src/**/*" | ||
] | ||
} |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Copyleft License
License(Experimental) Copyleft license information was found.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
Non-permissive License
License(Experimental) A license not known to be considered permissive was found.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Copyleft License
License(Experimental) Copyleft license information was found.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
Non-permissive License
License(Experimental) A license not known to be considered permissive was found.
Found 1 instance in 1 package
539164
298
6137