diff -r 34716fd837a4 -r be944660c56a wp/wp-includes/js/dist/dom.js --- a/wp/wp-includes/js/dist/dom.js Tue Dec 15 15:52:01 2020 +0100 +++ b/wp/wp-includes/js/dist/dom.js Wed Sep 21 18:19:35 2022 +0200 @@ -82,19 +82,12 @@ /******/ /******/ /******/ // Load entry module and return exports -/******/ return __webpack_require__(__webpack_require__.s = 462); +/******/ return __webpack_require__(__webpack_require__.s = "2sUP"); /******/ }) /************************************************************************/ /******/ ({ -/***/ 2: -/***/ (function(module, exports) { - -(function() { module.exports = this["lodash"]; }()); - -/***/ }), - -/***/ 462: +/***/ "2sUP": /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; @@ -103,27 +96,35 @@ // EXPORTS __webpack_require__.d(__webpack_exports__, "focus", function() { return /* binding */ build_module_focus; }); -__webpack_require__.d(__webpack_exports__, "isHorizontalEdge", function() { return /* reexport */ isHorizontalEdge; }); -__webpack_require__.d(__webpack_exports__, "isVerticalEdge", function() { return /* reexport */ isVerticalEdge; }); -__webpack_require__.d(__webpack_exports__, "getRectangleFromRange", function() { return /* reexport */ getRectangleFromRange; }); __webpack_require__.d(__webpack_exports__, "computeCaretRect", function() { return /* reexport */ computeCaretRect; }); -__webpack_require__.d(__webpack_exports__, "placeCaretAtHorizontalEdge", function() { return /* reexport */ placeCaretAtHorizontalEdge; }); -__webpack_require__.d(__webpack_exports__, "placeCaretAtVerticalEdge", function() { return /* reexport */ placeCaretAtVerticalEdge; }); -__webpack_require__.d(__webpack_exports__, "isTextField", function() { return /* reexport */ isTextField; }); -__webpack_require__.d(__webpack_exports__, "isNumberInput", function() { return /* reexport */ isNumberInput; }); __webpack_require__.d(__webpack_exports__, "documentHasTextSelection", function() { return /* reexport */ documentHasTextSelection; }); __webpack_require__.d(__webpack_exports__, "documentHasUncollapsedSelection", function() { return /* reexport */ documentHasUncollapsedSelection; }); __webpack_require__.d(__webpack_exports__, "documentHasSelection", function() { return /* reexport */ documentHasSelection; }); -__webpack_require__.d(__webpack_exports__, "isEntirelySelected", function() { return /* reexport */ isEntirelySelected; }); +__webpack_require__.d(__webpack_exports__, "getRectangleFromRange", function() { return /* reexport */ getRectangleFromRange; }); __webpack_require__.d(__webpack_exports__, "getScrollContainer", function() { return /* reexport */ getScrollContainer; }); __webpack_require__.d(__webpack_exports__, "getOffsetParent", function() { return /* reexport */ getOffsetParent; }); +__webpack_require__.d(__webpack_exports__, "isEntirelySelected", function() { return /* reexport */ isEntirelySelected; }); +__webpack_require__.d(__webpack_exports__, "isHorizontalEdge", function() { return /* reexport */ isHorizontalEdge; }); +__webpack_require__.d(__webpack_exports__, "isNumberInput", function() { return /* reexport */ isNumberInput; }); +__webpack_require__.d(__webpack_exports__, "isTextField", function() { return /* reexport */ isTextField; }); +__webpack_require__.d(__webpack_exports__, "isVerticalEdge", function() { return /* reexport */ isVerticalEdge; }); +__webpack_require__.d(__webpack_exports__, "placeCaretAtHorizontalEdge", function() { return /* reexport */ placeCaretAtHorizontalEdge; }); +__webpack_require__.d(__webpack_exports__, "placeCaretAtVerticalEdge", function() { return /* reexport */ placeCaretAtVerticalEdge; }); __webpack_require__.d(__webpack_exports__, "replace", function() { return /* reexport */ replace; }); __webpack_require__.d(__webpack_exports__, "remove", function() { return /* reexport */ remove; }); __webpack_require__.d(__webpack_exports__, "insertAfter", function() { return /* reexport */ insertAfter; }); __webpack_require__.d(__webpack_exports__, "unwrap", function() { return /* reexport */ unwrap; }); __webpack_require__.d(__webpack_exports__, "replaceTag", function() { return /* reexport */ replaceTag; }); __webpack_require__.d(__webpack_exports__, "wrap", function() { return /* reexport */ wrap; }); -__webpack_require__.d(__webpack_exports__, "__unstableStripHTML", function() { return /* reexport */ __unstableStripHTML; }); +__webpack_require__.d(__webpack_exports__, "__unstableStripHTML", function() { return /* reexport */ stripHTML; }); +__webpack_require__.d(__webpack_exports__, "isEmpty", function() { return /* reexport */ isEmpty; }); +__webpack_require__.d(__webpack_exports__, "removeInvalidHTML", function() { return /* reexport */ removeInvalidHTML; }); +__webpack_require__.d(__webpack_exports__, "isRTL", function() { return /* reexport */ isRTL; }); +__webpack_require__.d(__webpack_exports__, "safeHTML", function() { return /* reexport */ safeHTML; }); +__webpack_require__.d(__webpack_exports__, "getPhrasingContentSchema", function() { return /* reexport */ getPhrasingContentSchema; }); +__webpack_require__.d(__webpack_exports__, "isPhrasingContent", function() { return /* reexport */ isPhrasingContent; }); +__webpack_require__.d(__webpack_exports__, "isTextContent", function() { return /* reexport */ isTextContent; }); +__webpack_require__.d(__webpack_exports__, "getFilesFromDataTransfer", function() { return /* reexport */ getFilesFromDataTransfer; }); // NAMESPACE OBJECT: ./node_modules/@wordpress/dom/build-module/focusable.js var focusable_namespaceObject = {}; @@ -157,12 +158,12 @@ * AREA elements associated with an IMG: * - https://w3c.github.io/html/editing.html#data-model */ -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(','); /** * Returns true if the specified element is visible (i.e. neither display: none * nor visibility: hidden). * - * @param {Element} element DOM element to test. + * @param {HTMLElement} element DOM element to test. * * @return {boolean} Whether element is visible. */ @@ -188,20 +189,23 @@ * false otherwise. Area is only focusable if within a map where a named map * referenced by an image somewhere in the document. * - * @param {Element} element DOM area element to test. + * @param {HTMLAreaElement} element DOM area element to test. * * @return {boolean} Whether area element is valid for focus. */ function isValidFocusableArea(element) { - var map = element.closest('map[name]'); + /** @type {HTMLMapElement | null} */ + const map = element.closest('map[name]'); if (!map) { return false; } + /** @type {HTMLImageElement | null} */ - var img = document.querySelector('img[usemap="#' + map.name + '"]'); + + const img = element.ownerDocument.querySelector('img[usemap="#' + map.name + '"]'); return !!img && isVisible(img); } /** @@ -214,24 +218,33 @@ function find(context) { - var elements = context.querySelectorAll(SELECTOR); - return Array.from(elements).filter(function (element) { + /* eslint-disable jsdoc/no-undefined-types */ + + /** @type {NodeListOf} */ + + /* eslint-enable jsdoc/no-undefined-types */ + const elements = context.querySelectorAll(SELECTOR); + return Array.from(elements).filter(element => { if (!isVisible(element) || skipFocus(element)) { return false; } - var nodeName = element.nodeName; + const { + nodeName + } = element; if ('AREA' === nodeName) { - return isValidFocusableArea(element); + return isValidFocusableArea( + /** @type {HTMLAreaElement} */ + element); } return true; }); } -// EXTERNAL MODULE: external {"this":"lodash"} -var external_this_lodash_ = __webpack_require__(2); +// EXTERNAL MODULE: external "lodash" +var external_lodash_ = __webpack_require__("YLtl"); // CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/tabbable.js /** @@ -253,11 +266,11 @@ * * @param {Element} element Element from which to retrieve. * - * @return {?number} Tab index of element (default 0). + * @return {number} Tab index of element (default 0). */ function getTabIndex(element) { - var tabIndex = element.getAttribute('tabindex'); + const tabIndex = element.getAttribute('tabindex'); return tabIndex === null ? 0 : parseInt(tabIndex, 10); } /** @@ -272,30 +285,39 @@ function isTabbableIndex(element) { return getTabIndex(element) !== -1; } +/** @typedef {Element & { type?: string, checked?: boolean, name?: string }} MaybeHTMLInputElement */ + /** * Returns a stateful reducer function which constructs a filtered array of * tabbable elements, where at most one radio input is selected for a given * name, giving priority to checked input, falling back to the first * encountered. * - * @return {Function} Radio group collapse reducer. + * @return {(acc: MaybeHTMLInputElement[], el: MaybeHTMLInputElement) => MaybeHTMLInputElement[]} Radio group collapse reducer. */ function createStatefulCollapseRadioGroup() { - var CHOSEN_RADIO_BY_NAME = {}; - return function collapseRadioGroup(result, element) { - var nodeName = element.nodeName, - type = element.type, - checked = element.checked, - name = element.name; // For all non-radio tabbables, construct to array by concatenating. + /** @type {Record} */ + const CHOSEN_RADIO_BY_NAME = {}; + return function collapseRadioGroup( + /** @type {MaybeHTMLInputElement[]} */ + result, + /** @type {MaybeHTMLInputElement} */ + element) { + const { + nodeName, + type, + checked, + name + } = element; // For all non-radio tabbables, construct to array by concatenating. if (nodeName !== 'INPUT' || type !== 'radio' || !name) { return result.concat(element); } - 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; if (!isChosen) { return result; @@ -305,8 +327,8 @@ if (hasChosen) { - var hadChosenElement = CHOSEN_RADIO_BY_NAME[name]; - result = Object(external_this_lodash_["without"])(result, hadChosenElement); + const hadChosenElement = CHOSEN_RADIO_BY_NAME[name]; + result = Object(external_lodash_["without"])(result, hadChosenElement); } CHOSEN_RADIO_BY_NAME[name] = element; @@ -322,21 +344,21 @@ * @param {Element} element Element. * @param {number} index Array index of element. * - * @return {Object} Mapped object with element, index. + * @return {{ element: Element, index: number }} Mapped object with element, index. */ function mapElementToObjectTabbable(element, index) { return { - element: element, - index: index + element, + index }; } /** * An array map callback, returning an element of the given mapped object's * element value. * - * @param {Object} object Mapped object with index. + * @param {{ element: Element }} object Mapped object with element. * * @return {Element} Mapped object element. */ @@ -350,16 +372,16 @@ * * @see mapElementToObjectTabbable * - * @param {Object} a First object to compare. - * @param {Object} b Second object to compare. + * @param {{ element: Element, index: number }} a First object to compare. + * @param {{ element: Element, index: number }} b Second object to compare. * * @return {number} Comparator result. */ function compareObjectTabbables(a, b) { - var aTabIndex = getTabIndex(a.element); - var bTabIndex = getTabIndex(b.element); + const aTabIndex = getTabIndex(a.element); + const bTabIndex = getTabIndex(b.element); if (aTabIndex === bTabIndex) { return a.index - b.index; @@ -370,15 +392,20 @@ /** * Givin focusable elements, filters out tabbable element. * - * @param {Array} focusables Focusable elements to filter. + * @param {Element[]} focusables Focusable elements to filter. * - * @return {Array} Tabbable elements. + * @return {Element[]} Tabbable elements. */ function filterTabbable(focusables) { return focusables.filter(isTabbableIndex).map(mapElementToObjectTabbable).sort(compareObjectTabbables).map(mapObjectTabbableToElement).reduce(createStatefulCollapseRadioGroup(), []); } +/** + * @param {Element} context + * @return {Element[]} Tabbable elements within the context. + */ + function tabbable_find(context) { return filterTabbable(find(context)); @@ -390,13 +417,12 @@ * to the active element. */ -function findPrevious() { - var element = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document.activeElement; - var focusables = find(document.body); - var index = focusables.indexOf(element); // Remove all focusables after and including `element`. +function findPrevious(element) { + const focusables = find(element.ownerDocument.body); + const index = focusables.indexOf(element); // Remove all focusables after and including `element`. focusables.length = index; - return Object(external_this_lodash_["last"])(filterTabbable(focusables)); + return Object(external_lodash_["last"])(filterTabbable(focusables)); } /** * Given a focusable element, find the next tabbable element. @@ -405,34 +431,558 @@ * to the active element. */ -function findNext() { - var element = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document.activeElement; - var focusables = find(document.body); - var index = focusables.indexOf(element); // Remove all focusables before and inside `element`. +function findNext(element) { + const focusables = 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); - }); - return Object(external_this_lodash_["first"])(filterTabbable(remaining)); + const remaining = focusables.slice(index + 1).filter(node => !element.contains(node)); + return Object(external_lodash_["first"])(filterTabbable(remaining)); +} + +// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/utils/assert-is-defined.js +function assertIsDefined(val, name) { + if (false) {} } -// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom.js +// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/get-rectangle-from-range.js +/** + * Internal dependencies + */ + /** - * External dependencies + * Get the rectangle of a given Range. + * + * @param {Range} range The range. + * + * @return {DOMRect} The rectangle. + */ + +function getRectangleFromRange(range) { + // For uncollapsed ranges, get the rectangle that bounds the contents of the + // range; this a rectangle enclosing the union of the bounding rectangles + // for all the elements in the range. + if (!range.collapsed) { + 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); + } + + const { + startContainer + } = range; + const { + ownerDocument + } = startContainer; // Correct invalid "BR" ranges. The cannot contain any children. + + if (startContainer.nodeName === 'BR') { + const { + parentNode + } = startContainer; + assertIsDefined(parentNode, 'parentNode'); + const index = + /** @type {Node[]} */ + Array.from(parentNode.childNodes).indexOf(startContainer); + assertIsDefined(ownerDocument, 'ownerDocument'); + range = ownerDocument.createRange(); + range.setStart(parentNode, index); + range.setEnd(parentNode, index); + } + + 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 + // by adding a temporary text node with zero-width space to the range. + // + // See: https://stackoverflow.com/a/6847328/995445 + + if (!rect) { + assertIsDefined(ownerDocument, 'ownerDocument'); + const padNode = ownerDocument.createTextNode('\u200b'); // Do not modify the live range. + + range = range.cloneRange(); + range.insertNode(padNode); + rect = range.getClientRects()[0]; + assertIsDefined(padNode.parentNode, 'padNode.parentNode'); + padNode.parentNode.removeChild(padNode); + } + + return rect; +} + +// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/compute-caret-rect.js +/** + * Internal dependencies + */ + + +/** + * Get the rectangle for the selection in a container. + * + * @param {Window} win The window of the selection. + * + * @return {DOMRect | null} The rectangle. + */ + +function computeCaretRect(win) { + const selection = win.getSelection(); + assertIsDefined(selection, 'selection'); + const range = selection.rangeCount ? selection.getRangeAt(0) : null; + + if (!range) { + return null; + } + + return getRectangleFromRange(range); +} + +// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/document-has-text-selection.js +/** + * Internal dependencies */ /** - * Browser dependencies + * Check whether the current document has selected text. This applies to ranges + * of text in the document, and not selection inside and