2024-01-31 13:59:56 +01:00
|
|
|
/******/ (() => { // webpackBootstrap
|
2022-04-11 14:04:30 +02:00
|
|
|
/******/ "use strict";
|
|
|
|
/******/ // The require scope
|
|
|
|
/******/ var __webpack_require__ = {};
|
|
|
|
/******/
|
|
|
|
/************************************************************************/
|
2022-09-20 17:43:29 +02:00
|
|
|
/******/ /* webpack/runtime/compat get default export */
|
2024-01-31 13:59:56 +01:00
|
|
|
/******/ (() => {
|
2022-09-20 17:43:29 +02:00
|
|
|
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
2024-01-31 13:59:56 +01:00
|
|
|
/******/ __webpack_require__.n = (module) => {
|
2022-09-20 17:43:29 +02:00
|
|
|
/******/ var getter = module && module.__esModule ?
|
2024-01-31 13:59:56 +01:00
|
|
|
/******/ () => (module['default']) :
|
|
|
|
/******/ () => (module);
|
2022-09-20 17:43:29 +02:00
|
|
|
/******/ __webpack_require__.d(getter, { a: getter });
|
|
|
|
/******/ return getter;
|
|
|
|
/******/ };
|
2024-01-31 13:59:56 +01:00
|
|
|
/******/ })();
|
2022-09-20 17:43:29 +02:00
|
|
|
/******/
|
2022-04-11 14:04:30 +02:00
|
|
|
/******/ /* webpack/runtime/define property getters */
|
2024-01-31 13:59:56 +01:00
|
|
|
/******/ (() => {
|
2022-04-11 14:04:30 +02:00
|
|
|
/******/ // define getter functions for harmony exports
|
2024-01-31 13:59:56 +01:00
|
|
|
/******/ __webpack_require__.d = (exports, definition) => {
|
2022-04-11 14:04:30 +02:00
|
|
|
/******/ for(var key in definition) {
|
|
|
|
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
|
|
|
|
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
|
|
|
|
/******/ }
|
|
|
|
/******/ }
|
|
|
|
/******/ };
|
2024-01-31 13:59:56 +01:00
|
|
|
/******/ })();
|
2022-04-11 14:04:30 +02:00
|
|
|
/******/
|
|
|
|
/******/ /* webpack/runtime/hasOwnProperty shorthand */
|
2024-01-31 13:59:56 +01:00
|
|
|
/******/ (() => {
|
|
|
|
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
|
|
|
|
/******/ })();
|
2022-04-11 14:04:30 +02:00
|
|
|
/******/
|
|
|
|
/******/ /* webpack/runtime/make namespace object */
|
2024-01-31 13:59:56 +01:00
|
|
|
/******/ (() => {
|
2022-04-11 14:04:30 +02:00
|
|
|
/******/ // define __esModule on exports
|
2024-01-31 13:59:56 +01:00
|
|
|
/******/ __webpack_require__.r = (exports) => {
|
2022-04-11 14:04:30 +02:00
|
|
|
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
|
|
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
|
|
/******/ }
|
|
|
|
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
2018-12-14 05:41:57 +01:00
|
|
|
/******/ };
|
2024-01-31 13:59:56 +01:00
|
|
|
/******/ })();
|
2022-04-11 14:04:30 +02:00
|
|
|
/******/
|
2018-12-14 05:41:57 +01:00
|
|
|
/************************************************************************/
|
2022-04-11 14:04:30 +02:00
|
|
|
var __webpack_exports__ = {};
|
2020-06-29 13:50:29 +02:00
|
|
|
// ESM COMPAT FLAG
|
2018-12-14 05:41:57 +01:00
|
|
|
__webpack_require__.r(__webpack_exports__);
|
2020-06-29 13:50:29 +02:00
|
|
|
|
|
|
|
// EXPORTS
|
2022-04-11 14:04:30 +02:00
|
|
|
__webpack_require__.d(__webpack_exports__, {
|
2024-01-31 13:59:56 +01:00
|
|
|
__unstableStripHTML: () => (/* reexport */ stripHTML),
|
|
|
|
computeCaretRect: () => (/* reexport */ computeCaretRect),
|
|
|
|
documentHasSelection: () => (/* reexport */ documentHasSelection),
|
|
|
|
documentHasTextSelection: () => (/* reexport */ documentHasTextSelection),
|
|
|
|
documentHasUncollapsedSelection: () => (/* reexport */ documentHasUncollapsedSelection),
|
|
|
|
focus: () => (/* binding */ build_module_focus),
|
|
|
|
getFilesFromDataTransfer: () => (/* reexport */ getFilesFromDataTransfer),
|
|
|
|
getOffsetParent: () => (/* reexport */ getOffsetParent),
|
|
|
|
getPhrasingContentSchema: () => (/* reexport */ getPhrasingContentSchema),
|
|
|
|
getRectangleFromRange: () => (/* reexport */ getRectangleFromRange),
|
|
|
|
getScrollContainer: () => (/* reexport */ getScrollContainer),
|
|
|
|
insertAfter: () => (/* reexport */ insertAfter),
|
|
|
|
isEmpty: () => (/* reexport */ isEmpty),
|
|
|
|
isEntirelySelected: () => (/* reexport */ isEntirelySelected),
|
|
|
|
isFormElement: () => (/* reexport */ isFormElement),
|
|
|
|
isHorizontalEdge: () => (/* reexport */ isHorizontalEdge),
|
|
|
|
isNumberInput: () => (/* reexport */ isNumberInput),
|
|
|
|
isPhrasingContent: () => (/* reexport */ isPhrasingContent),
|
|
|
|
isRTL: () => (/* reexport */ isRTL),
|
|
|
|
isTextContent: () => (/* reexport */ isTextContent),
|
|
|
|
isTextField: () => (/* reexport */ isTextField),
|
|
|
|
isVerticalEdge: () => (/* reexport */ isVerticalEdge),
|
|
|
|
placeCaretAtHorizontalEdge: () => (/* reexport */ placeCaretAtHorizontalEdge),
|
|
|
|
placeCaretAtVerticalEdge: () => (/* reexport */ placeCaretAtVerticalEdge),
|
|
|
|
remove: () => (/* reexport */ remove),
|
|
|
|
removeInvalidHTML: () => (/* reexport */ removeInvalidHTML),
|
|
|
|
replace: () => (/* reexport */ replace),
|
|
|
|
replaceTag: () => (/* reexport */ replaceTag),
|
|
|
|
safeHTML: () => (/* reexport */ safeHTML),
|
|
|
|
unwrap: () => (/* reexport */ unwrap),
|
|
|
|
wrap: () => (/* reexport */ wrap)
|
2022-04-11 14:04:30 +02:00
|
|
|
});
|
2020-06-29 13:50:29 +02:00
|
|
|
|
|
|
|
// NAMESPACE OBJECT: ./node_modules/@wordpress/dom/build-module/focusable.js
|
2018-12-18 04:14:52 +01:00
|
|
|
var focusable_namespaceObject = {};
|
|
|
|
__webpack_require__.r(focusable_namespaceObject);
|
2022-04-11 14:04:30 +02:00
|
|
|
__webpack_require__.d(focusable_namespaceObject, {
|
2024-01-31 13:59:56 +01:00
|
|
|
find: () => (find)
|
2022-04-11 14:04:30 +02:00
|
|
|
});
|
2020-06-29 13:50:29 +02:00
|
|
|
|
|
|
|
// NAMESPACE OBJECT: ./node_modules/@wordpress/dom/build-module/tabbable.js
|
2018-12-18 04:14:52 +01:00
|
|
|
var tabbable_namespaceObject = {};
|
|
|
|
__webpack_require__.r(tabbable_namespaceObject);
|
2022-04-11 14:04:30 +02:00
|
|
|
__webpack_require__.d(tabbable_namespaceObject, {
|
2024-01-31 13:59:56 +01:00
|
|
|
find: () => (tabbable_find),
|
|
|
|
findNext: () => (findNext),
|
|
|
|
findPrevious: () => (findPrevious),
|
|
|
|
isTabbableIndex: () => (isTabbableIndex)
|
2022-04-11 14:04:30 +02:00
|
|
|
});
|
2018-12-18 04:14:52 +01:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/focusable.js
|
2018-12-18 04:14:52 +01:00
|
|
|
/**
|
|
|
|
* References:
|
|
|
|
*
|
|
|
|
* Focusable:
|
|
|
|
* - https://www.w3.org/TR/html5/editing.html#focus-management
|
|
|
|
*
|
|
|
|
* Sequential focus navigation:
|
|
|
|
* - https://www.w3.org/TR/html5/editing.html#sequential-focus-navigation-and-the-tabindex-attribute
|
|
|
|
*
|
|
|
|
* Disabled elements:
|
|
|
|
* - https://www.w3.org/TR/html5/disabled-elements.html#disabled-elements
|
|
|
|
*
|
|
|
|
* getClientRects algorithm (requiring layout box):
|
|
|
|
* - https://www.w3.org/TR/cssom-view-1/#extension-to-the-element-interface
|
|
|
|
*
|
|
|
|
* AREA elements associated with an IMG:
|
|
|
|
* - https://w3c.github.io/html/editing.html#data-model
|
|
|
|
*/
|
2021-11-08 15:29:21 +01:00
|
|
|
|
2018-12-18 04:14:52 +01:00
|
|
|
/**
|
2021-11-08 15:29:21 +01:00
|
|
|
* Returns a CSS selector used to query for focusable elements.
|
2018-12-18 04:14:52 +01:00
|
|
|
*
|
2021-11-08 15:29:21 +01:00
|
|
|
* @param {boolean} sequential If set, only query elements that are sequentially
|
|
|
|
* focusable. Non-interactive elements with a
|
|
|
|
* negative `tabindex` are focusable but not
|
|
|
|
* sequentially focusable.
|
|
|
|
* https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute
|
2018-12-18 04:14:52 +01:00
|
|
|
*
|
2021-11-08 15:29:21 +01:00
|
|
|
* @return {string} CSS selector.
|
2018-12-18 04:14:52 +01:00
|
|
|
*/
|
2021-11-08 15:29:21 +01:00
|
|
|
function buildSelector(sequential) {
|
|
|
|
return [sequential ? '[tabindex]:not([tabindex^="-"])' : '[tabindex]', 'a[href]', 'button:not([disabled])', 'input:not([type="hidden"]):not([disabled])', 'select:not([disabled])', 'textarea:not([disabled])', 'iframe:not([tabindex^="-"])', 'object', 'embed', 'area[href]', '[contenteditable]:not([contenteditable=false])'].join(',');
|
2018-12-14 05:41:57 +01:00
|
|
|
}
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2020-07-07 16:43:35 +02:00
|
|
|
/**
|
2021-11-08 15:29:21 +01:00
|
|
|
* Returns true if the specified element is visible (i.e. neither display: none
|
|
|
|
* nor visibility: hidden).
|
2020-07-07 16:43:35 +02:00
|
|
|
*
|
2021-11-08 15:29:21 +01:00
|
|
|
* @param {HTMLElement} element DOM element to test.
|
2020-07-07 16:43:35 +02:00
|
|
|
*
|
2021-11-08 15:29:21 +01:00
|
|
|
* @return {boolean} Whether element is visible.
|
2020-07-07 16:43:35 +02:00
|
|
|
*/
|
2021-11-08 15:29:21 +01:00
|
|
|
function isVisible(element) {
|
|
|
|
return element.offsetWidth > 0 || element.offsetHeight > 0 || element.getClientRects().length > 0;
|
2020-07-07 16:43:35 +02:00
|
|
|
}
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2018-12-18 04:14:52 +01:00
|
|
|
/**
|
|
|
|
* Returns true if the specified area element is a valid focusable element, or
|
|
|
|
* false otherwise. Area is only focusable if within a map where a named map
|
|
|
|
* referenced by an image somewhere in the document.
|
|
|
|
*
|
2021-04-15 17:19:43 +02:00
|
|
|
* @param {HTMLAreaElement} element DOM area element to test.
|
2018-12-18 04:14:52 +01:00
|
|
|
*
|
|
|
|
* @return {boolean} Whether area element is valid for focus.
|
|
|
|
*/
|
|
|
|
function isValidFocusableArea(element) {
|
2021-04-15 17:19:43 +02:00
|
|
|
/** @type {HTMLMapElement | null} */
|
2021-05-19 17:09:27 +02:00
|
|
|
const map = element.closest('map[name]');
|
2018-12-18 04:14:52 +01:00
|
|
|
if (!map) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
/** @type {HTMLImageElement | null} */
|
2021-05-19 17:09:27 +02:00
|
|
|
const img = element.ownerDocument.querySelector('img[usemap="#' + map.name + '"]');
|
2018-12-18 04:14:52 +01:00
|
|
|
return !!img && isVisible(img);
|
|
|
|
}
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2018-12-18 04:14:52 +01:00
|
|
|
/**
|
|
|
|
* Returns all focusable elements within a given context.
|
|
|
|
*
|
2021-11-08 15:29:21 +01:00
|
|
|
* @param {Element} context Element in which to search.
|
2023-06-27 16:24:19 +02:00
|
|
|
* @param {Object} options
|
2021-11-08 15:29:21 +01:00
|
|
|
* @param {boolean} [options.sequential] If set, only return elements that are
|
|
|
|
* sequentially focusable.
|
|
|
|
* Non-interactive elements with a
|
|
|
|
* negative `tabindex` are focusable but
|
|
|
|
* not sequentially focusable.
|
|
|
|
* https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute
|
2018-12-18 04:14:52 +01:00
|
|
|
*
|
2023-06-27 16:24:19 +02:00
|
|
|
* @return {HTMLElement[]} Focusable elements.
|
2018-12-18 04:14:52 +01:00
|
|
|
*/
|
2023-06-27 16:24:19 +02:00
|
|
|
function find(context, {
|
|
|
|
sequential = false
|
|
|
|
} = {}) {
|
2021-04-15 17:19:43 +02:00
|
|
|
/* eslint-disable jsdoc/no-undefined-types */
|
|
|
|
/** @type {NodeListOf<HTMLElement>} */
|
|
|
|
/* eslint-enable jsdoc/no-undefined-types */
|
2021-11-08 15:29:21 +01:00
|
|
|
const elements = context.querySelectorAll(buildSelector(sequential));
|
2021-05-19 17:09:27 +02:00
|
|
|
return Array.from(elements).filter(element => {
|
2021-11-08 15:29:21 +01:00
|
|
|
if (!isVisible(element)) {
|
2018-12-18 04:14:52 +01:00
|
|
|
return false;
|
|
|
|
}
|
2021-05-19 17:09:27 +02:00
|
|
|
const {
|
|
|
|
nodeName
|
|
|
|
} = element;
|
2018-12-18 04:14:52 +01:00
|
|
|
if ('AREA' === nodeName) {
|
2023-09-26 16:23:26 +02:00
|
|
|
return isValidFocusableArea( /** @type {HTMLAreaElement} */element);
|
2018-12-18 04:14:52 +01:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
2018-12-14 05:41:57 +01:00
|
|
|
}
|
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/tabbable.js
|
2018-12-18 04:14:52 +01:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2018-12-14 05:41:57 +01:00
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2018-12-18 04:14:52 +01:00
|
|
|
/**
|
|
|
|
* Returns the tab index of the given element. In contrast with the tabIndex
|
|
|
|
* property, this normalizes the default (0) to avoid browser inconsistencies,
|
|
|
|
* operating under the assumption that this function is only ever called with a
|
|
|
|
* focusable node.
|
|
|
|
*
|
|
|
|
* @see https://bugzilla.mozilla.org/show_bug.cgi?id=1190261
|
|
|
|
*
|
|
|
|
* @param {Element} element Element from which to retrieve.
|
|
|
|
*
|
2021-04-15 17:19:43 +02:00
|
|
|
* @return {number} Tab index of element (default 0).
|
2018-12-18 04:14:52 +01:00
|
|
|
*/
|
|
|
|
function getTabIndex(element) {
|
2021-05-19 17:09:27 +02:00
|
|
|
const tabIndex = element.getAttribute('tabindex');
|
2018-12-18 04:14:52 +01:00
|
|
|
return tabIndex === null ? 0 : parseInt(tabIndex, 10);
|
|
|
|
}
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2018-12-18 04:14:52 +01:00
|
|
|
/**
|
|
|
|
* Returns true if the specified element is tabbable, or false otherwise.
|
|
|
|
*
|
|
|
|
* @param {Element} element Element to test.
|
|
|
|
*
|
|
|
|
* @return {boolean} Whether element is tabbable.
|
|
|
|
*/
|
|
|
|
function isTabbableIndex(element) {
|
|
|
|
return getTabIndex(element) !== -1;
|
|
|
|
}
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2021-04-15 17:19:43 +02:00
|
|
|
/** @typedef {Element & { type?: string, checked?: boolean, name?: string }} MaybeHTMLInputElement */
|
|
|
|
|
2019-03-21 13:48:00 +01:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
2021-04-15 17:19:43 +02:00
|
|
|
* @return {(acc: MaybeHTMLInputElement[], el: MaybeHTMLInputElement) => MaybeHTMLInputElement[]} Radio group collapse reducer.
|
2019-03-21 13:48:00 +01:00
|
|
|
*/
|
|
|
|
function createStatefulCollapseRadioGroup() {
|
2021-04-15 17:19:43 +02:00
|
|
|
/** @type {Record<string, MaybeHTMLInputElement>} */
|
2021-05-19 17:09:27 +02:00
|
|
|
const CHOSEN_RADIO_BY_NAME = {};
|
2023-09-26 16:23:26 +02:00
|
|
|
return function collapseRadioGroup( /** @type {MaybeHTMLInputElement[]} */result, /** @type {MaybeHTMLInputElement} */element) {
|
2021-05-19 17:09:27 +02:00
|
|
|
const {
|
|
|
|
nodeName,
|
|
|
|
type,
|
|
|
|
checked,
|
|
|
|
name
|
2023-09-26 16:23:26 +02:00
|
|
|
} = element;
|
2019-03-21 13:48:00 +01:00
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
// For all non-radio tabbables, construct to array by concatenating.
|
2019-03-21 13:48:00 +01:00
|
|
|
if (nodeName !== 'INPUT' || type !== 'radio' || !name) {
|
|
|
|
return result.concat(element);
|
|
|
|
}
|
2023-09-26 16:23:26 +02:00
|
|
|
const hasChosen = CHOSEN_RADIO_BY_NAME.hasOwnProperty(name);
|
2019-03-21 13:48:00 +01:00
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
// Omit by skipping concatenation if the radio element is not chosen.
|
2021-05-19 17:09:27 +02:00
|
|
|
const isChosen = checked || !hasChosen;
|
2019-03-21 13:48:00 +01:00
|
|
|
if (!isChosen) {
|
|
|
|
return result;
|
2023-09-26 16:23:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// At this point, if there had been a chosen element, the current
|
2019-03-21 13:48:00 +01:00
|
|
|
// element is checked and should take priority. Retroactively remove
|
|
|
|
// the element which had previously been considered the chosen one.
|
|
|
|
if (hasChosen) {
|
2021-05-19 17:09:27 +02:00
|
|
|
const hadChosenElement = CHOSEN_RADIO_BY_NAME[name];
|
2022-09-20 17:43:29 +02:00
|
|
|
result = result.filter(e => e !== hadChosenElement);
|
2019-03-21 13:48:00 +01:00
|
|
|
}
|
|
|
|
CHOSEN_RADIO_BY_NAME[name] = element;
|
|
|
|
return result.concat(element);
|
|
|
|
};
|
|
|
|
}
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2018-12-18 04:14:52 +01:00
|
|
|
/**
|
|
|
|
* An array map callback, returning an object with the element value and its
|
|
|
|
* array index location as properties. This is used to emulate a proper stable
|
|
|
|
* sort where equal tabIndex should be left in order of their occurrence in the
|
|
|
|
* document.
|
|
|
|
*
|
|
|
|
* @param {Element} element Element.
|
|
|
|
* @param {number} index Array index of element.
|
|
|
|
*
|
2021-04-15 17:19:43 +02:00
|
|
|
* @return {{ element: Element, index: number }} Mapped object with element, index.
|
2018-12-18 04:14:52 +01:00
|
|
|
*/
|
|
|
|
function mapElementToObjectTabbable(element, index) {
|
|
|
|
return {
|
2021-05-19 17:09:27 +02:00
|
|
|
element,
|
|
|
|
index
|
2018-12-18 04:14:52 +01:00
|
|
|
};
|
|
|
|
}
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2018-12-18 04:14:52 +01:00
|
|
|
/**
|
|
|
|
* An array map callback, returning an element of the given mapped object's
|
|
|
|
* element value.
|
|
|
|
*
|
2021-04-15 17:19:43 +02:00
|
|
|
* @param {{ element: Element }} object Mapped object with element.
|
2018-12-18 04:14:52 +01:00
|
|
|
*
|
|
|
|
* @return {Element} Mapped object element.
|
|
|
|
*/
|
|
|
|
function mapObjectTabbableToElement(object) {
|
|
|
|
return object.element;
|
|
|
|
}
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2018-12-18 04:14:52 +01:00
|
|
|
/**
|
|
|
|
* A sort comparator function used in comparing two objects of mapped elements.
|
|
|
|
*
|
|
|
|
* @see mapElementToObjectTabbable
|
|
|
|
*
|
2021-04-15 17:19:43 +02:00
|
|
|
* @param {{ element: Element, index: number }} a First object to compare.
|
|
|
|
* @param {{ element: Element, index: number }} b Second object to compare.
|
2018-12-18 04:14:52 +01:00
|
|
|
*
|
|
|
|
* @return {number} Comparator result.
|
|
|
|
*/
|
|
|
|
function compareObjectTabbables(a, b) {
|
2021-05-19 17:09:27 +02:00
|
|
|
const aTabIndex = getTabIndex(a.element);
|
|
|
|
const bTabIndex = getTabIndex(b.element);
|
2018-12-18 04:14:52 +01:00
|
|
|
if (aTabIndex === bTabIndex) {
|
|
|
|
return a.index - b.index;
|
|
|
|
}
|
|
|
|
return aTabIndex - bTabIndex;
|
|
|
|
}
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2020-01-22 23:06:21 +01:00
|
|
|
/**
|
|
|
|
* Givin focusable elements, filters out tabbable element.
|
|
|
|
*
|
2021-04-15 17:19:43 +02:00
|
|
|
* @param {Element[]} focusables Focusable elements to filter.
|
2020-01-22 23:06:21 +01:00
|
|
|
*
|
2021-04-15 17:19:43 +02:00
|
|
|
* @return {Element[]} Tabbable elements.
|
2020-01-22 23:06:21 +01:00
|
|
|
*/
|
|
|
|
function filterTabbable(focusables) {
|
|
|
|
return focusables.filter(isTabbableIndex).map(mapElementToObjectTabbable).sort(compareObjectTabbables).map(mapObjectTabbableToElement).reduce(createStatefulCollapseRadioGroup(), []);
|
|
|
|
}
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2021-04-15 17:19:43 +02:00
|
|
|
/**
|
|
|
|
* @param {Element} context
|
|
|
|
* @return {Element[]} Tabbable elements within the context.
|
|
|
|
*/
|
2018-12-18 04:14:52 +01:00
|
|
|
function tabbable_find(context) {
|
2020-01-22 23:06:21 +01:00
|
|
|
return filterTabbable(find(context));
|
|
|
|
}
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2020-01-22 23:06:21 +01:00
|
|
|
/**
|
|
|
|
* Given a focusable element, find the preceding tabbable element.
|
|
|
|
*
|
|
|
|
* @param {Element} element The focusable element before which to look. Defaults
|
|
|
|
* to the active element.
|
2022-04-12 17:12:47 +02:00
|
|
|
*
|
|
|
|
* @return {Element|undefined} Preceding tabbable element.
|
2020-01-22 23:06:21 +01:00
|
|
|
*/
|
2020-10-13 15:10:30 +02:00
|
|
|
function findPrevious(element) {
|
2023-02-07 08:04:52 +01:00
|
|
|
return filterTabbable(find(element.ownerDocument.body)).reverse().find(focusable => {
|
2023-09-26 16:23:26 +02:00
|
|
|
return (
|
|
|
|
// eslint-disable-next-line no-bitwise
|
2023-02-07 08:04:52 +01:00
|
|
|
element.compareDocumentPosition(focusable) & element.DOCUMENT_POSITION_PRECEDING
|
|
|
|
);
|
|
|
|
});
|
2020-01-22 23:06:21 +01:00
|
|
|
}
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2020-01-22 23:06:21 +01:00
|
|
|
/**
|
|
|
|
* Given a focusable element, find the next tabbable element.
|
|
|
|
*
|
|
|
|
* @param {Element} element The focusable element after which to look. Defaults
|
|
|
|
* to the active element.
|
2022-09-20 17:43:29 +02:00
|
|
|
*
|
|
|
|
* @return {Element|undefined} Next tabbable element.
|
2020-01-22 23:06:21 +01:00
|
|
|
*/
|
2020-10-13 15:10:30 +02:00
|
|
|
function findNext(element) {
|
2023-02-07 08:04:52 +01:00
|
|
|
return filterTabbable(find(element.ownerDocument.body)).find(focusable => {
|
2023-09-26 16:23:26 +02:00
|
|
|
return (
|
|
|
|
// eslint-disable-next-line no-bitwise
|
2023-02-07 08:04:52 +01:00
|
|
|
element.compareDocumentPosition(focusable) & element.DOCUMENT_POSITION_FOLLOWING
|
|
|
|
);
|
|
|
|
});
|
2018-12-18 04:14:52 +01:00
|
|
|
}
|
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/utils/assert-is-defined.js
|
2021-04-15 17:19:43 +02:00
|
|
|
function assertIsDefined(val, name) {
|
2021-05-07 13:48:27 +02:00
|
|
|
if (false) {}
|
2021-04-15 17:19:43 +02:00
|
|
|
}
|
2020-10-13 15:10:30 +02:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/get-rectangle-from-range.js
|
2020-10-13 15:10:30 +02:00
|
|
|
/**
|
2021-04-15 17:19:43 +02:00
|
|
|
* Internal dependencies
|
2020-10-13 15:10:30 +02:00
|
|
|
*/
|
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2020-10-13 15:10:30 +02:00
|
|
|
/**
|
2022-09-20 17:43:29 +02:00
|
|
|
* Get the rectangle of a given Range. Returns `null` if no suitable rectangle
|
|
|
|
* can be found.
|
2020-10-13 15:10:30 +02:00
|
|
|
*
|
2021-04-15 17:19:43 +02:00
|
|
|
* @param {Range} range The range.
|
2020-10-13 15:10:30 +02:00
|
|
|
*
|
2022-09-20 17:43:29 +02:00
|
|
|
* @return {DOMRect?} The rectangle.
|
2020-10-13 15:10:30 +02:00
|
|
|
*/
|
2021-04-15 17:19:43 +02:00
|
|
|
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) {
|
2023-09-26 16:23:26 +02:00
|
|
|
const rects = Array.from(range.getClientRects());
|
2021-05-19 17:09:27 +02:00
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
// If there's just a single rect, return it.
|
2021-05-19 17:09:27 +02:00
|
|
|
if (rects.length === 1) {
|
|
|
|
return rects[0];
|
2023-09-26 16:23:26 +02:00
|
|
|
}
|
2021-05-19 17:09:27 +02:00
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
// Ignore tiny selection at the edge of a range.
|
2023-06-27 16:24:19 +02:00
|
|
|
const filteredRects = rects.filter(({
|
|
|
|
width
|
2023-09-26 16:23:26 +02:00
|
|
|
}) => width > 1);
|
2021-05-19 17:09:27 +02:00
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
// If it's full of tiny selections, return browser default.
|
2021-05-19 17:09:27 +02:00
|
|
|
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);
|
2021-04-15 17:19:43 +02:00
|
|
|
}
|
2021-05-19 17:09:27 +02:00
|
|
|
const {
|
|
|
|
startContainer
|
|
|
|
} = range;
|
|
|
|
const {
|
|
|
|
ownerDocument
|
2023-09-26 16:23:26 +02:00
|
|
|
} = startContainer;
|
2020-10-13 15:10:30 +02:00
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
// Correct invalid "BR" ranges. The cannot contain any children.
|
2021-04-15 17:19:43 +02:00
|
|
|
if (startContainer.nodeName === 'BR') {
|
2021-05-19 17:09:27 +02:00
|
|
|
const {
|
|
|
|
parentNode
|
|
|
|
} = startContainer;
|
2021-04-15 17:19:43 +02:00
|
|
|
assertIsDefined(parentNode, 'parentNode');
|
2023-09-26 16:23:26 +02:00
|
|
|
const index = /** @type {Node[]} */Array.from(parentNode.childNodes).indexOf(startContainer);
|
2021-04-15 17:19:43 +02:00
|
|
|
assertIsDefined(ownerDocument, 'ownerDocument');
|
|
|
|
range = ownerDocument.createRange();
|
|
|
|
range.setStart(parentNode, index);
|
|
|
|
range.setEnd(parentNode, index);
|
2020-10-13 15:10:30 +02:00
|
|
|
}
|
2023-09-26 16:23:26 +02:00
|
|
|
const rects = range.getClientRects();
|
2021-04-15 17:19:43 +02:00
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
// If we have multiple rectangles for a collapsed range, there's no way to
|
2022-09-20 17:43:29 +02:00
|
|
|
// know which it is, so don't return anything.
|
|
|
|
if (rects.length > 1) {
|
|
|
|
return null;
|
|
|
|
}
|
2023-09-26 16:23:26 +02:00
|
|
|
let rect = rects[0];
|
2022-09-20 17:43:29 +02:00
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
// If the collapsed range starts (and therefore ends) at an element node,
|
2021-04-15 17:19:43 +02:00
|
|
|
// `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
|
2023-06-27 16:24:19 +02:00
|
|
|
if (!rect || rect.height === 0) {
|
2021-04-15 17:19:43 +02:00
|
|
|
assertIsDefined(ownerDocument, 'ownerDocument');
|
2023-09-26 16:23:26 +02:00
|
|
|
const padNode = ownerDocument.createTextNode('\u200b');
|
|
|
|
// Do not modify the live range.
|
2021-04-15 17:19:43 +02:00
|
|
|
range = range.cloneRange();
|
|
|
|
range.insertNode(padNode);
|
|
|
|
rect = range.getClientRects()[0];
|
|
|
|
assertIsDefined(padNode.parentNode, 'padNode.parentNode');
|
|
|
|
padNode.parentNode.removeChild(padNode);
|
|
|
|
}
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/compute-caret-rect.js
|
2020-10-13 15:10:30 +02:00
|
|
|
/**
|
2021-04-15 17:19:43 +02:00
|
|
|
* Internal dependencies
|
2020-10-13 15:10:30 +02:00
|
|
|
*/
|
|
|
|
|
2021-04-15 17:19:43 +02:00
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2020-10-13 15:10:30 +02:00
|
|
|
/**
|
2021-04-15 17:19:43 +02:00
|
|
|
* Get the rectangle for the selection in a container.
|
2020-10-13 15:10:30 +02:00
|
|
|
*
|
2021-04-15 17:19:43 +02:00
|
|
|
* @param {Window} win The window of the selection.
|
2020-10-13 15:10:30 +02:00
|
|
|
*
|
2021-04-15 17:19:43 +02:00
|
|
|
* @return {DOMRect | null} The rectangle.
|
2020-10-13 15:10:30 +02:00
|
|
|
*/
|
2021-04-15 17:19:43 +02:00
|
|
|
function computeCaretRect(win) {
|
2021-05-19 17:09:27 +02:00
|
|
|
const selection = win.getSelection();
|
2021-04-15 17:19:43 +02:00
|
|
|
assertIsDefined(selection, 'selection');
|
2021-05-19 17:09:27 +02:00
|
|
|
const range = selection.rangeCount ? selection.getRangeAt(0) : null;
|
2021-04-15 17:19:43 +02:00
|
|
|
if (!range) {
|
|
|
|
return null;
|
2020-10-13 15:10:30 +02:00
|
|
|
}
|
2021-04-15 17:19:43 +02:00
|
|
|
return getRectangleFromRange(range);
|
2020-10-13 15:10:30 +02:00
|
|
|
}
|
2021-04-15 17:19:43 +02:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/document-has-text-selection.js
|
2021-05-07 13:48:27 +02:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2020-10-13 15:10:30 +02:00
|
|
|
/**
|
2021-04-15 17:19:43 +02:00
|
|
|
* Check whether the current document has selected text. This applies to ranges
|
2021-11-08 15:29:21 +01:00
|
|
|
* of text in the document, and not selection inside `<input>` and `<textarea>`
|
2021-04-15 17:19:43 +02:00
|
|
|
* elements.
|
2020-10-13 15:10:30 +02:00
|
|
|
*
|
2021-04-15 17:19:43 +02:00
|
|
|
* See: https://developer.mozilla.org/en-US/docs/Web/API/Window/getSelection#Related_objects.
|
2020-10-13 15:10:30 +02:00
|
|
|
*
|
2021-04-15 17:19:43 +02:00
|
|
|
* @param {Document} doc The document to check.
|
2020-10-13 15:10:30 +02:00
|
|
|
*
|
2021-04-15 17:19:43 +02:00
|
|
|
* @return {boolean} True if there is selection, false if not.
|
2020-10-13 15:10:30 +02:00
|
|
|
*/
|
2021-04-15 17:19:43 +02:00
|
|
|
function documentHasTextSelection(doc) {
|
2021-05-07 13:48:27 +02:00
|
|
|
assertIsDefined(doc.defaultView, 'doc.defaultView');
|
2021-05-19 17:09:27 +02:00
|
|
|
const selection = doc.defaultView.getSelection();
|
2021-05-07 13:48:27 +02:00
|
|
|
assertIsDefined(selection, 'selection');
|
2021-05-19 17:09:27 +02:00
|
|
|
const range = selection.rangeCount ? selection.getRangeAt(0) : null;
|
2021-05-07 13:48:27 +02:00
|
|
|
return !!range && !range.collapsed;
|
|
|
|
}
|
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/is-html-input-element.js
|
2021-05-07 13:48:27 +02:00
|
|
|
/* eslint-disable jsdoc/valid-types */
|
|
|
|
/**
|
|
|
|
* @param {Node} node
|
|
|
|
* @return {node is HTMLInputElement} Whether the node is an HTMLInputElement.
|
|
|
|
*/
|
|
|
|
function isHTMLInputElement(node) {
|
|
|
|
/* eslint-enable jsdoc/valid-types */
|
2023-06-27 16:24:19 +02:00
|
|
|
return node?.nodeName === 'INPUT';
|
2020-10-13 15:10:30 +02:00
|
|
|
}
|
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/is-text-field.js
|
2021-05-07 13:48:27 +02:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
/* eslint-disable jsdoc/valid-types */
|
2021-04-15 17:19:43 +02:00
|
|
|
/**
|
|
|
|
* Check whether the given element is a text field, where text field is defined
|
|
|
|
* by the ability to select within the input, or that it is contenteditable.
|
|
|
|
*
|
|
|
|
* See: https://html.spec.whatwg.org/#textFieldSelection
|
|
|
|
*
|
2021-05-07 13:48:27 +02:00
|
|
|
* @param {Node} node The HTML element.
|
2021-05-21 12:14:23 +02:00
|
|
|
* @return {node is HTMLElement} True if the element is an text field, false if not.
|
2021-04-15 17:19:43 +02:00
|
|
|
*/
|
2021-05-07 13:48:27 +02:00
|
|
|
function isTextField(node) {
|
|
|
|
/* eslint-enable jsdoc/valid-types */
|
2022-09-20 17:43:29 +02:00
|
|
|
const nonTextInputs = ['button', 'checkbox', 'hidden', 'file', 'radio', 'image', 'range', 'reset', 'submit', 'number', 'email', 'time'];
|
2023-09-26 16:23:26 +02:00
|
|
|
return isHTMLInputElement(node) && node.type && !nonTextInputs.includes(node.type) || node.nodeName === 'TEXTAREA' || /** @type {HTMLElement} */node.contentEditable === 'true';
|
2021-04-15 17:19:43 +02:00
|
|
|
}
|
2021-01-28 03:04:13 +01:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/input-field-has-uncollapsed-selection.js
|
2018-12-14 05:41:57 +01:00
|
|
|
/**
|
2020-10-13 15:10:30 +02:00
|
|
|
* Internal dependencies
|
2018-12-14 05:41:57 +01:00
|
|
|
*/
|
|
|
|
|
2020-10-13 15:10:30 +02:00
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2021-04-15 17:19:43 +02:00
|
|
|
/**
|
2022-09-20 17:43:29 +02:00
|
|
|
* Check whether the given input field or textarea contains a (uncollapsed)
|
|
|
|
* selection of text.
|
2021-04-15 17:19:43 +02:00
|
|
|
*
|
2022-09-20 17:43:29 +02:00
|
|
|
* CAVEAT: Only specific text-based HTML inputs support the selection APIs
|
|
|
|
* needed to determine whether they have a collapsed or uncollapsed selection.
|
|
|
|
* This function defaults to returning `true` when the selection cannot be
|
|
|
|
* inspected, such as with `<input type="time">`. The rationale is that this
|
|
|
|
* should cause the block editor to defer to the browser's native selection
|
|
|
|
* handling (e.g. copying and pasting), thereby reducing friction for the user.
|
2021-04-15 17:19:43 +02:00
|
|
|
*
|
2022-09-20 17:43:29 +02:00
|
|
|
* See: https://html.spec.whatwg.org/multipage/input.html#do-not-apply
|
2021-04-15 17:19:43 +02:00
|
|
|
*
|
2021-05-07 13:48:27 +02:00
|
|
|
* @param {Element} element The HTML element.
|
2021-04-15 17:19:43 +02:00
|
|
|
*
|
|
|
|
* @return {boolean} Whether the input/textareaa element has some "selection".
|
|
|
|
*/
|
|
|
|
function inputFieldHasUncollapsedSelection(element) {
|
2022-09-20 17:43:29 +02:00
|
|
|
if (!isHTMLInputElement(element) && !isTextField(element)) {
|
2021-04-15 17:19:43 +02:00
|
|
|
return false;
|
2023-09-26 16:23:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Safari throws a type error when trying to get `selectionStart` and
|
2022-09-20 17:43:29 +02:00
|
|
|
// `selectionEnd` on non-text <input> elements, so a try/catch construct is
|
|
|
|
// necessary.
|
2021-04-15 17:19:43 +02:00
|
|
|
try {
|
2021-05-19 17:09:27 +02:00
|
|
|
const {
|
|
|
|
selectionStart,
|
|
|
|
selectionEnd
|
2023-09-26 16:23:26 +02:00
|
|
|
} = /** @type {HTMLInputElement | HTMLTextAreaElement} */element;
|
|
|
|
return (
|
|
|
|
// `null` means the input type doesn't implement selection, thus we
|
2022-09-20 17:43:29 +02:00
|
|
|
// cannot determine whether the selection is collapsed, so we
|
|
|
|
// default to true.
|
2023-09-26 16:23:26 +02:00
|
|
|
selectionStart === null ||
|
|
|
|
// when not null, compare the two points
|
2022-09-20 17:43:29 +02:00
|
|
|
selectionStart !== selectionEnd
|
|
|
|
);
|
2021-04-15 17:19:43 +02:00
|
|
|
} catch (error) {
|
2022-09-20 17:43:29 +02:00
|
|
|
// This is Safari's way of saying that the input type doesn't implement
|
|
|
|
// selection, so we default to true.
|
|
|
|
return true;
|
2021-04-15 17:19:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/document-has-uncollapsed-selection.js
|
2021-04-15 17:19:43 +02:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2021-04-15 17:19:43 +02:00
|
|
|
/**
|
2022-09-20 17:43:29 +02:00
|
|
|
* Check whether the current document has any sort of (uncollapsed) selection.
|
|
|
|
* This includes ranges of text across elements and any selection inside
|
|
|
|
* textual `<input>` and `<textarea>` elements.
|
2021-04-15 17:19:43 +02:00
|
|
|
*
|
|
|
|
* @param {Document} doc The document to check.
|
|
|
|
*
|
2022-09-20 17:43:29 +02:00
|
|
|
* @return {boolean} Whether there is any recognizable text selection in the document.
|
2021-04-15 17:19:43 +02:00
|
|
|
*/
|
|
|
|
function documentHasUncollapsedSelection(doc) {
|
2021-05-07 13:48:27 +02:00
|
|
|
return documentHasTextSelection(doc) || !!doc.activeElement && inputFieldHasUncollapsedSelection(doc.activeElement);
|
2021-04-15 17:19:43 +02:00
|
|
|
}
|
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/document-has-selection.js
|
2021-04-15 17:19:43 +02:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2021-04-15 17:19:43 +02:00
|
|
|
/**
|
2022-09-20 17:43:29 +02:00
|
|
|
* Check whether the current document has a selection. This includes focus in
|
|
|
|
* input fields, textareas, and general rich-text selection.
|
2021-04-15 17:19:43 +02:00
|
|
|
*
|
|
|
|
* @param {Document} doc The document to check.
|
|
|
|
*
|
|
|
|
* @return {boolean} True if there is selection, false if not.
|
|
|
|
*/
|
|
|
|
function documentHasSelection(doc) {
|
2022-09-20 17:43:29 +02:00
|
|
|
return !!doc.activeElement && (isHTMLInputElement(doc.activeElement) || isTextField(doc.activeElement) || documentHasTextSelection(doc));
|
2021-04-15 17:19:43 +02:00
|
|
|
}
|
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/get-computed-style.js
|
2021-05-07 13:48:27 +02:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
/* eslint-disable jsdoc/valid-types */
|
2021-05-07 13:48:27 +02:00
|
|
|
/**
|
|
|
|
* @param {Element} element
|
|
|
|
* @return {ReturnType<Window['getComputedStyle']>} The computed style for the element.
|
|
|
|
*/
|
|
|
|
function getComputedStyle(element) {
|
|
|
|
/* eslint-enable jsdoc/valid-types */
|
|
|
|
assertIsDefined(element.ownerDocument.defaultView, 'element.ownerDocument.defaultView');
|
|
|
|
return element.ownerDocument.defaultView.getComputedStyle(element);
|
2021-04-15 17:19:43 +02:00
|
|
|
}
|
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/get-scroll-container.js
|
2021-04-15 17:19:43 +02:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2021-04-15 17:19:43 +02:00
|
|
|
/**
|
2023-06-27 16:24:19 +02:00
|
|
|
* Given a DOM node, finds the closest scrollable container node or the node
|
|
|
|
* itself, if scrollable.
|
2021-04-15 17:19:43 +02:00
|
|
|
*
|
2023-06-27 16:24:19 +02:00
|
|
|
* @param {Element | null} node Node from which to start.
|
|
|
|
* @param {?string} direction Direction of scrollable container to search for ('vertical', 'horizontal', 'all').
|
|
|
|
* Defaults to 'vertical'.
|
2021-05-07 13:48:27 +02:00
|
|
|
* @return {Element | undefined} Scrollable container node, if found.
|
2021-04-15 17:19:43 +02:00
|
|
|
*/
|
2023-06-27 16:24:19 +02:00
|
|
|
function getScrollContainer(node, direction = 'vertical') {
|
2021-04-15 17:19:43 +02:00
|
|
|
if (!node) {
|
2021-05-07 13:48:27 +02:00
|
|
|
return undefined;
|
2023-06-27 16:24:19 +02:00
|
|
|
}
|
|
|
|
if (direction === 'vertical' || direction === 'all') {
|
|
|
|
// Scrollable if scrollable height exceeds displayed...
|
|
|
|
if (node.scrollHeight > node.clientHeight) {
|
|
|
|
// ...except when overflow is defined to be hidden or visible
|
|
|
|
const {
|
|
|
|
overflowY
|
|
|
|
} = getComputedStyle(node);
|
|
|
|
if (/(auto|scroll)/.test(overflowY)) {
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (direction === 'horizontal' || direction === 'all') {
|
|
|
|
// Scrollable if scrollable width exceeds displayed...
|
|
|
|
if (node.scrollWidth > node.clientWidth) {
|
|
|
|
// ...except when overflow is defined to be hidden or visible
|
|
|
|
const {
|
|
|
|
overflowX
|
|
|
|
} = getComputedStyle(node);
|
|
|
|
if (/(auto|scroll)/.test(overflowX)) {
|
|
|
|
return node;
|
|
|
|
}
|
2021-04-15 17:19:43 +02:00
|
|
|
}
|
2022-09-20 17:43:29 +02:00
|
|
|
}
|
|
|
|
if (node.ownerDocument === node.parentNode) {
|
|
|
|
return node;
|
2023-09-26 16:23:26 +02:00
|
|
|
}
|
2021-04-15 17:19:43 +02:00
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
// Continue traversing.
|
|
|
|
return getScrollContainer( /** @type {Element} */node.parentNode, direction);
|
2021-04-15 17:19:43 +02:00
|
|
|
}
|
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/get-offset-parent.js
|
2021-04-15 17:19:43 +02:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2021-04-15 17:19:43 +02:00
|
|
|
/**
|
|
|
|
* Returns the closest positioned element, or null under any of the conditions
|
|
|
|
* of the offsetParent specification. Unlike offsetParent, this function is not
|
|
|
|
* limited to HTMLElement and accepts any Node (e.g. Node.TEXT_NODE).
|
|
|
|
*
|
|
|
|
* @see https://drafts.csswg.org/cssom-view/#dom-htmlelement-offsetparent
|
|
|
|
*
|
|
|
|
* @param {Node} node Node from which to find offset parent.
|
|
|
|
*
|
2021-05-07 13:48:27 +02:00
|
|
|
* @return {Node | null} Offset parent.
|
2021-04-15 17:19:43 +02:00
|
|
|
*/
|
|
|
|
function getOffsetParent(node) {
|
|
|
|
// Cannot retrieve computed style or offset parent only anything other than
|
|
|
|
// an element node, so find the closest element node.
|
2021-05-19 17:09:27 +02:00
|
|
|
let closestElement;
|
2023-09-26 16:23:26 +02:00
|
|
|
while (closestElement = /** @type {Node} */node.parentNode) {
|
2021-04-15 17:19:43 +02:00
|
|
|
if (closestElement.nodeType === closestElement.ELEMENT_NODE) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!closestElement) {
|
|
|
|
return null;
|
2023-09-26 16:23:26 +02:00
|
|
|
}
|
2021-04-15 17:19:43 +02:00
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
// If the closest element is already positioned, return it, as offsetParent
|
|
|
|
// does not otherwise consider the node itself.
|
|
|
|
if (getComputedStyle( /** @type {Element} */closestElement).position !== 'static') {
|
2021-04-15 17:19:43 +02:00
|
|
|
return closestElement;
|
2023-09-26 16:23:26 +02:00
|
|
|
}
|
2021-05-07 13:48:27 +02:00
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
// offsetParent is undocumented/draft.
|
2024-02-09 19:22:22 +01:00
|
|
|
return /** @type {Node & { offsetParent: Node }} */closestElement.offsetParent;
|
2021-05-07 13:48:27 +02:00
|
|
|
}
|
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/is-input-or-text-area.js
|
2021-05-07 13:48:27 +02:00
|
|
|
/* eslint-disable jsdoc/valid-types */
|
|
|
|
/**
|
|
|
|
* @param {Element} element
|
|
|
|
* @return {element is HTMLInputElement | HTMLTextAreaElement} Whether the element is an input or textarea
|
|
|
|
*/
|
|
|
|
function isInputOrTextArea(element) {
|
|
|
|
/* eslint-enable jsdoc/valid-types */
|
|
|
|
return element.tagName === 'INPUT' || element.tagName === 'TEXTAREA';
|
2021-04-15 17:19:43 +02:00
|
|
|
}
|
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/is-entirely-selected.js
|
2021-04-15 17:19:43 +02:00
|
|
|
/**
|
2021-05-07 13:48:27 +02:00
|
|
|
* Internal dependencies
|
2021-04-15 17:19:43 +02:00
|
|
|
*/
|
|
|
|
|
2021-05-07 13:48:27 +02:00
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2021-04-15 17:19:43 +02:00
|
|
|
/**
|
|
|
|
* Check whether the contents of the element have been entirely selected.
|
|
|
|
* Returns true if there is no possibility of selection.
|
|
|
|
*
|
2021-05-07 13:48:27 +02:00
|
|
|
* @param {HTMLElement} element The element to check.
|
2021-04-15 17:19:43 +02:00
|
|
|
*
|
|
|
|
* @return {boolean} True if entirely selected, false if not.
|
|
|
|
*/
|
|
|
|
function isEntirelySelected(element) {
|
2021-05-07 13:48:27 +02:00
|
|
|
if (isInputOrTextArea(element)) {
|
2021-04-15 17:19:43 +02:00
|
|
|
return element.selectionStart === 0 && element.value.length === element.selectionEnd;
|
|
|
|
}
|
|
|
|
if (!element.isContentEditable) {
|
|
|
|
return true;
|
|
|
|
}
|
2021-05-19 17:09:27 +02:00
|
|
|
const {
|
|
|
|
ownerDocument
|
|
|
|
} = element;
|
|
|
|
const {
|
|
|
|
defaultView
|
|
|
|
} = ownerDocument;
|
2021-05-07 13:48:27 +02:00
|
|
|
assertIsDefined(defaultView, 'defaultView');
|
2021-05-19 17:09:27 +02:00
|
|
|
const selection = defaultView.getSelection();
|
2021-05-07 13:48:27 +02:00
|
|
|
assertIsDefined(selection, 'selection');
|
2021-05-19 17:09:27 +02:00
|
|
|
const range = selection.rangeCount ? selection.getRangeAt(0) : null;
|
2021-04-15 17:19:43 +02:00
|
|
|
if (!range) {
|
|
|
|
return true;
|
|
|
|
}
|
2021-05-19 17:09:27 +02:00
|
|
|
const {
|
|
|
|
startContainer,
|
|
|
|
endContainer,
|
|
|
|
startOffset,
|
|
|
|
endOffset
|
|
|
|
} = range;
|
2021-04-15 17:19:43 +02:00
|
|
|
if (startContainer === element && endContainer === element && startOffset === 0 && endOffset === element.childNodes.length) {
|
|
|
|
return true;
|
|
|
|
}
|
2021-05-19 17:09:27 +02:00
|
|
|
const lastChild = element.lastChild;
|
2021-05-07 13:48:27 +02:00
|
|
|
assertIsDefined(lastChild, 'lastChild');
|
2023-09-26 16:23:26 +02:00
|
|
|
const endContainerContentLength = endContainer.nodeType === endContainer.TEXT_NODE ? /** @type {Text} */endContainer.data.length : endContainer.childNodes.length;
|
2021-07-06 16:38:40 +02:00
|
|
|
return isDeepChild(startContainer, element, 'firstChild') && isDeepChild(endContainer, element, 'lastChild') && startOffset === 0 && endOffset === endContainerContentLength;
|
|
|
|
}
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2021-07-06 16:38:40 +02:00
|
|
|
/**
|
|
|
|
* Check whether the contents of the element have been entirely selected.
|
|
|
|
* Returns true if there is no possibility of selection.
|
|
|
|
*
|
2021-11-08 15:29:21 +01:00
|
|
|
* @param {HTMLElement|Node} query The element to check.
|
|
|
|
* @param {HTMLElement} container The container that we suspect "query" may be a first or last child of.
|
|
|
|
* @param {"firstChild"|"lastChild"} propName "firstChild" or "lastChild"
|
2021-07-06 16:38:40 +02:00
|
|
|
*
|
|
|
|
* @return {boolean} True if query is a deep first/last child of container, false otherwise.
|
|
|
|
*/
|
|
|
|
function isDeepChild(query, container, propName) {
|
|
|
|
/** @type {HTMLElement | ChildNode | null} */
|
|
|
|
let candidate = container;
|
|
|
|
do {
|
|
|
|
if (query === candidate) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
candidate = candidate[propName];
|
|
|
|
} while (candidate);
|
|
|
|
return false;
|
2020-10-13 15:10:30 +02:00
|
|
|
}
|
2021-04-15 17:19:43 +02:00
|
|
|
|
2022-04-12 17:12:47 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/is-form-element.js
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2022-04-12 17:12:47 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Detects if element is a form element.
|
|
|
|
*
|
|
|
|
* @param {Element} element The element to check.
|
|
|
|
*
|
|
|
|
* @return {boolean} True if form element and false otherwise.
|
|
|
|
*/
|
|
|
|
function isFormElement(element) {
|
2022-09-20 17:43:29 +02:00
|
|
|
if (!element) {
|
|
|
|
return false;
|
|
|
|
}
|
2022-04-12 17:12:47 +02:00
|
|
|
const {
|
|
|
|
tagName
|
|
|
|
} = element;
|
|
|
|
const checkForInputTextarea = isInputOrTextArea(element);
|
|
|
|
return checkForInputTextarea || tagName === 'BUTTON' || tagName === 'SELECT';
|
|
|
|
}
|
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/is-rtl.js
|
2021-05-19 17:09:27 +02:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2021-04-15 17:19:43 +02:00
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2021-05-19 17:09:27 +02:00
|
|
|
/**
|
|
|
|
* Whether the element's text direction is right-to-left.
|
|
|
|
*
|
|
|
|
* @param {Element} element The element to check.
|
|
|
|
*
|
|
|
|
* @return {boolean} True if rtl, false if ltr.
|
|
|
|
*/
|
|
|
|
function isRTL(element) {
|
|
|
|
return getComputedStyle(element).direction === 'rtl';
|
|
|
|
}
|
2021-04-15 17:19:43 +02:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/get-range-height.js
|
2021-01-28 03:04:13 +01:00
|
|
|
/**
|
|
|
|
* Gets the height of the range without ignoring zero width rectangles, which
|
|
|
|
* some browsers ignore when creating a union.
|
|
|
|
*
|
|
|
|
* @param {Range} range The range to check.
|
2021-05-07 13:48:27 +02:00
|
|
|
* @return {number | undefined} Height of the range or undefined if the range has no client rectangles.
|
2021-01-28 03:04:13 +01:00
|
|
|
*/
|
|
|
|
function getRangeHeight(range) {
|
2021-05-19 17:09:27 +02:00
|
|
|
const rects = Array.from(range.getClientRects());
|
2021-01-28 03:04:13 +01:00
|
|
|
if (!rects.length) {
|
|
|
|
return;
|
|
|
|
}
|
2023-06-27 16:24:19 +02:00
|
|
|
const highestTop = Math.min(...rects.map(({
|
|
|
|
top
|
|
|
|
}) => top));
|
|
|
|
const lowestBottom = Math.max(...rects.map(({
|
|
|
|
bottom
|
|
|
|
}) => bottom));
|
2021-01-28 03:04:13 +01:00
|
|
|
return lowestBottom - highestTop;
|
|
|
|
}
|
2021-04-15 17:19:43 +02:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/is-selection-forward.js
|
2021-05-07 13:48:27 +02:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2018-12-14 05:41:57 +01:00
|
|
|
/**
|
|
|
|
* Returns true if the given selection object is in the forward direction, or
|
|
|
|
* false otherwise.
|
|
|
|
*
|
|
|
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/Node/compareDocumentPosition
|
|
|
|
*
|
|
|
|
* @param {Selection} selection Selection object to check.
|
|
|
|
*
|
|
|
|
* @return {boolean} Whether the selection is forward.
|
|
|
|
*/
|
|
|
|
function isSelectionForward(selection) {
|
2021-05-19 17:09:27 +02:00
|
|
|
const {
|
|
|
|
anchorNode,
|
|
|
|
focusNode,
|
|
|
|
anchorOffset,
|
|
|
|
focusOffset
|
|
|
|
} = selection;
|
2021-05-07 13:48:27 +02:00
|
|
|
assertIsDefined(anchorNode, 'anchorNode');
|
|
|
|
assertIsDefined(focusNode, 'focusNode');
|
2023-09-26 16:23:26 +02:00
|
|
|
const position = anchorNode.compareDocumentPosition(focusNode);
|
2018-12-14 05:41:57 +01:00
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
// Disable reason: `Node#compareDocumentPosition` returns a bitmask value,
|
|
|
|
// so bitwise operators are intended.
|
2018-12-14 05:41:57 +01:00
|
|
|
/* eslint-disable no-bitwise */
|
|
|
|
// Compare whether anchor node precedes focus node. If focus node (where
|
|
|
|
// end of selection occurs) is after the anchor node, it is forward.
|
2020-10-13 15:10:30 +02:00
|
|
|
if (position & anchorNode.DOCUMENT_POSITION_PRECEDING) {
|
2018-12-14 05:41:57 +01:00
|
|
|
return false;
|
|
|
|
}
|
2020-10-13 15:10:30 +02:00
|
|
|
if (position & anchorNode.DOCUMENT_POSITION_FOLLOWING) {
|
2018-12-14 05:41:57 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
/* eslint-enable no-bitwise */
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2018-12-14 05:41:57 +01:00
|
|
|
// `compareDocumentPosition` returns 0 when passed the same node, in which
|
|
|
|
// case compare offsets.
|
|
|
|
if (position === 0) {
|
|
|
|
return anchorOffset <= focusOffset;
|
2023-09-26 16:23:26 +02:00
|
|
|
}
|
2018-12-14 05:41:57 +01:00
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
// This should never be reached, but return true as default case.
|
2018-12-14 05:41:57 +01:00
|
|
|
return true;
|
|
|
|
}
|
2021-04-15 17:19:43 +02:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/caret-range-from-point.js
|
2018-12-14 05:41:57 +01:00
|
|
|
/**
|
2021-04-15 17:19:43 +02:00
|
|
|
* Polyfill.
|
|
|
|
* Get a collapsed range for a given point.
|
2018-12-14 05:41:57 +01:00
|
|
|
*
|
2021-04-15 17:19:43 +02:00
|
|
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/Document/caretRangeFromPoint
|
2018-12-14 05:41:57 +01:00
|
|
|
*
|
2021-11-08 15:29:21 +01:00
|
|
|
* @param {DocumentMaybeWithCaretPositionFromPoint} doc The document of the range.
|
|
|
|
* @param {number} x Horizontal position within the current viewport.
|
|
|
|
* @param {number} y Vertical position within the current viewport.
|
2021-04-15 17:19:43 +02:00
|
|
|
*
|
|
|
|
* @return {Range | null} The best range for the given point.
|
2018-12-14 05:41:57 +01:00
|
|
|
*/
|
2021-04-15 17:19:43 +02:00
|
|
|
function caretRangeFromPoint(doc, x, y) {
|
|
|
|
if (doc.caretRangeFromPoint) {
|
|
|
|
return doc.caretRangeFromPoint(x, y);
|
2018-12-14 05:41:57 +01:00
|
|
|
}
|
2021-04-15 17:19:43 +02:00
|
|
|
if (!doc.caretPositionFromPoint) {
|
|
|
|
return null;
|
2018-12-14 05:41:57 +01:00
|
|
|
}
|
2023-09-26 16:23:26 +02:00
|
|
|
const point = doc.caretPositionFromPoint(x, y);
|
2018-12-14 05:41:57 +01:00
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
// If x or y are negative, outside viewport, or there is no text entry node.
|
2021-04-15 17:19:43 +02:00
|
|
|
// https://developer.mozilla.org/en-US/docs/Web/API/Document/caretRangeFromPoint
|
|
|
|
if (!point) {
|
|
|
|
return null;
|
Block Editor: Update packages to bring a selection of bugfixes in.
Props iseulde, kjellr, aduth, 0mirka00, mcsf, nosolosw, gziolo, jasmussen, talldanwp, notnownikki, swissspidy, jorgefilipecosta, noisysocks.
See https://github.com/WordPress/gutenberg/pull/14796.
Fixes #46801.
Built from https://develop.svn.wordpress.org/trunk@45138
git-svn-id: http://core.svn.wordpress.org/trunk@44947 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-04-08 08:37:57 +02:00
|
|
|
}
|
2021-05-19 17:09:27 +02:00
|
|
|
const range = doc.createRange();
|
2021-04-15 17:19:43 +02:00
|
|
|
range.setStart(point.offsetNode, point.offset);
|
|
|
|
range.collapse(true);
|
|
|
|
return range;
|
|
|
|
}
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2021-11-08 15:29:21 +01:00
|
|
|
/**
|
|
|
|
* @typedef {{caretPositionFromPoint?: (x: number, y: number)=> CaretPosition | null} & Document } DocumentMaybeWithCaretPositionFromPoint
|
|
|
|
* @typedef {{ readonly offset: number; readonly offsetNode: Node; getClientRect(): DOMRect | null; }} CaretPosition
|
|
|
|
*/
|
2019-04-22 14:40:04 +02:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/hidden-caret-range-from-point.js
|
2021-04-15 17:19:43 +02:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2021-04-15 17:19:43 +02:00
|
|
|
/**
|
|
|
|
* Get a collapsed range for a given point.
|
|
|
|
* Gives the container a temporary high z-index (above any UI).
|
|
|
|
* This is preferred over getting the UI nodes and set styles there.
|
|
|
|
*
|
2021-11-08 15:29:21 +01:00
|
|
|
* @param {Document} doc The document of the range.
|
|
|
|
* @param {number} x Horizontal position within the current viewport.
|
|
|
|
* @param {number} y Vertical position within the current viewport.
|
|
|
|
* @param {HTMLElement} container Container in which the range is expected to be found.
|
2021-04-15 17:19:43 +02:00
|
|
|
*
|
|
|
|
* @return {?Range} The best range for the given point.
|
|
|
|
*/
|
|
|
|
function hiddenCaretRangeFromPoint(doc, x, y, container) {
|
2021-05-19 17:09:27 +02:00
|
|
|
const originalZIndex = container.style.zIndex;
|
|
|
|
const originalPosition = container.style.position;
|
|
|
|
const {
|
|
|
|
position = 'static'
|
2023-09-26 16:23:26 +02:00
|
|
|
} = getComputedStyle(container);
|
2021-04-15 17:19:43 +02:00
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
// A z-index only works if the element position is not static.
|
2021-04-15 17:19:43 +02:00
|
|
|
if (position === 'static') {
|
|
|
|
container.style.position = 'relative';
|
|
|
|
}
|
|
|
|
container.style.zIndex = '10000';
|
2021-05-19 17:09:27 +02:00
|
|
|
const range = caretRangeFromPoint(doc, x, y);
|
2021-04-15 17:19:43 +02:00
|
|
|
container.style.zIndex = originalZIndex;
|
|
|
|
container.style.position = originalPosition;
|
|
|
|
return range;
|
|
|
|
}
|
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/scroll-if-no-range.js
|
|
|
|
/**
|
|
|
|
* If no range range can be created or it is outside the container, the element
|
|
|
|
* may be out of view, so scroll it into view and try again.
|
|
|
|
*
|
|
|
|
* @param {HTMLElement} container The container to scroll.
|
|
|
|
* @param {boolean} alignToTop True to align to top, false to bottom.
|
|
|
|
* @param {Function} callback The callback to create the range.
|
|
|
|
*
|
|
|
|
* @return {?Range} The range returned by the callback.
|
|
|
|
*/
|
|
|
|
function scrollIfNoRange(container, alignToTop, callback) {
|
|
|
|
let range = callback();
|
|
|
|
|
|
|
|
// If no range range can be created or it is outside the container, the
|
|
|
|
// element may be out of view.
|
|
|
|
if (!range || !range.startContainer || !container.contains(range.startContainer)) {
|
|
|
|
container.scrollIntoView(alignToTop);
|
|
|
|
range = callback();
|
|
|
|
if (!range || !range.startContainer || !container.contains(range.startContainer)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return range;
|
|
|
|
}
|
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/is-edge.js
|
2021-04-15 17:19:43 +02:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-05-07 13:48:27 +02:00
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
|
|
|
|
|
2021-04-15 17:19:43 +02:00
|
|
|
/**
|
|
|
|
* Check whether the selection is at the edge of the container. Checks for
|
|
|
|
* horizontal position by default. Set `onlyVertical` to true to check only
|
|
|
|
* vertically.
|
|
|
|
*
|
2023-09-26 16:23:26 +02:00
|
|
|
* @param {HTMLElement} 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.
|
2021-04-15 17:19:43 +02:00
|
|
|
*
|
|
|
|
* @return {boolean} True if at the edge, false if not.
|
|
|
|
*/
|
2023-06-27 16:24:19 +02:00
|
|
|
function isEdge(container, isReverse, onlyVertical = false) {
|
2021-11-08 15:29:21 +01:00
|
|
|
if (isInputOrTextArea(container) && typeof container.selectionStart === 'number') {
|
2021-04-15 17:19:43 +02:00
|
|
|
if (container.selectionStart !== container.selectionEnd) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (isReverse) {
|
|
|
|
return container.selectionStart === 0;
|
|
|
|
}
|
|
|
|
return container.value.length === container.selectionStart;
|
|
|
|
}
|
2024-02-09 19:22:22 +01:00
|
|
|
if (!( /** @type {HTMLElement} */container.isContentEditable)) {
|
2021-04-15 17:19:43 +02:00
|
|
|
return true;
|
|
|
|
}
|
2021-05-19 17:09:27 +02:00
|
|
|
const {
|
|
|
|
ownerDocument
|
|
|
|
} = container;
|
|
|
|
const {
|
|
|
|
defaultView
|
|
|
|
} = ownerDocument;
|
2021-05-07 13:48:27 +02:00
|
|
|
assertIsDefined(defaultView, 'defaultView');
|
2021-05-19 17:09:27 +02:00
|
|
|
const selection = defaultView.getSelection();
|
2021-05-07 13:48:27 +02:00
|
|
|
if (!selection || !selection.rangeCount) {
|
2021-04-15 17:19:43 +02:00
|
|
|
return false;
|
|
|
|
}
|
2021-05-19 17:09:27 +02:00
|
|
|
const range = selection.getRangeAt(0);
|
|
|
|
const collapsedRange = range.cloneRange();
|
|
|
|
const isForward = isSelectionForward(selection);
|
2023-09-26 16:23:26 +02:00
|
|
|
const isCollapsed = selection.isCollapsed;
|
2021-04-15 17:19:43 +02:00
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
// Collapse in direction of selection.
|
2021-04-15 17:19:43 +02:00
|
|
|
if (!isCollapsed) {
|
2021-01-28 03:04:13 +01:00
|
|
|
collapsedRange.collapse(!isForward);
|
2019-04-22 14:40:04 +02:00
|
|
|
}
|
2021-05-19 17:09:27 +02:00
|
|
|
const collapsedRangeRect = getRectangleFromRange(collapsedRange);
|
|
|
|
const rangeRect = getRectangleFromRange(range);
|
2021-01-28 03:04:13 +01:00
|
|
|
if (!collapsedRangeRect || !rangeRect) {
|
Block Editor: Update packages to bring a selection of bugfixes in.
Props iseulde, kjellr, aduth, 0mirka00, mcsf, nosolosw, gziolo, jasmussen, talldanwp, notnownikki, swissspidy, jorgefilipecosta, noisysocks.
See https://github.com/WordPress/gutenberg/pull/14796.
Fixes #46801.
Built from https://develop.svn.wordpress.org/trunk@45138
git-svn-id: http://core.svn.wordpress.org/trunk@44947 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-04-08 08:37:57 +02:00
|
|
|
return false;
|
2023-09-26 16:23:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Only consider the multiline selection at the edge if the direction is
|
2021-01-28 03:04:13 +01:00
|
|
|
// towards the edge. The selection is multiline if it is taller than the
|
|
|
|
// collapsed selection.
|
2021-05-19 17:09:27 +02:00
|
|
|
const rangeHeight = getRangeHeight(range);
|
2021-05-07 13:48:27 +02:00
|
|
|
if (!isCollapsed && rangeHeight && rangeHeight > collapsedRangeRect.height && isForward === isReverse) {
|
2018-12-14 05:41:57 +01:00
|
|
|
return false;
|
2023-09-26 16:23:26 +02:00
|
|
|
}
|
2019-05-16 20:08:00 +02:00
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
// In the case of RTL scripts, the horizontal edge is at the opposite side.
|
2021-05-19 17:09:27 +02:00
|
|
|
const isReverseDir = isRTL(container) ? !isReverse : isReverse;
|
2023-09-26 16:23:26 +02:00
|
|
|
const containerRect = container.getBoundingClientRect();
|
|
|
|
|
|
|
|
// To check if a selection is at the edge, we insert a test selection at the
|
2021-01-28 03:04:13 +01:00
|
|
|
// edge of the container and check if the selections have the same vertical
|
|
|
|
// or horizontal position. If they do, the selection is at the edge.
|
|
|
|
// This method proves to be better than a DOM-based calculation for the
|
|
|
|
// horizontal edge, since it ignores empty textnodes and a trailing line
|
|
|
|
// break element. In other words, we need to check visual positioning, not
|
|
|
|
// DOM positioning.
|
|
|
|
// It also proves better than using the computed style for the vertical
|
|
|
|
// edge, because we cannot know the padding and line height reliably in
|
|
|
|
// pixels. `getComputedStyle` may return a value with different units.
|
2021-05-19 17:09:27 +02:00
|
|
|
const x = isReverseDir ? containerRect.left + 1 : containerRect.right - 1;
|
|
|
|
const y = isReverse ? containerRect.top + 1 : containerRect.bottom - 1;
|
2023-09-26 16:23:26 +02:00
|
|
|
const testRange = scrollIfNoRange(container, isReverse, () => hiddenCaretRangeFromPoint(ownerDocument, x, y, container));
|
Block Editor: Update packages to bring a selection of bugfixes in.
Props iseulde, kjellr, aduth, 0mirka00, mcsf, nosolosw, gziolo, jasmussen, talldanwp, notnownikki, swissspidy, jorgefilipecosta, noisysocks.
See https://github.com/WordPress/gutenberg/pull/14796.
Fixes #46801.
Built from https://develop.svn.wordpress.org/trunk@45138
git-svn-id: http://core.svn.wordpress.org/trunk@44947 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-04-08 08:37:57 +02:00
|
|
|
if (!testRange) {
|
|
|
|
return false;
|
|
|
|
}
|
2021-05-19 17:09:27 +02:00
|
|
|
const testRect = getRectangleFromRange(testRange);
|
2021-01-28 03:04:13 +01:00
|
|
|
if (!testRect) {
|
|
|
|
return false;
|
|
|
|
}
|
2021-05-19 17:09:27 +02:00
|
|
|
const verticalSide = isReverse ? 'top' : 'bottom';
|
|
|
|
const horizontalSide = isReverseDir ? 'left' : 'right';
|
|
|
|
const verticalDiff = testRect[verticalSide] - rangeRect[verticalSide];
|
2023-09-26 16:23:26 +02:00
|
|
|
const horizontalDiff = testRect[horizontalSide] - collapsedRangeRect[horizontalSide];
|
2021-01-28 03:04:13 +01:00
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
// Allow the position to be 1px off.
|
2021-05-19 17:09:27 +02:00
|
|
|
const hasVerticalDiff = Math.abs(verticalDiff) <= 1;
|
|
|
|
const hasHorizontalDiff = Math.abs(horizontalDiff) <= 1;
|
2021-01-28 03:04:13 +01:00
|
|
|
return onlyVertical ? hasVerticalDiff : hasVerticalDiff && hasHorizontalDiff;
|
Block Editor: Update packages to bring a selection of bugfixes in.
Props iseulde, kjellr, aduth, 0mirka00, mcsf, nosolosw, gziolo, jasmussen, talldanwp, notnownikki, swissspidy, jorgefilipecosta, noisysocks.
See https://github.com/WordPress/gutenberg/pull/14796.
Fixes #46801.
Built from https://develop.svn.wordpress.org/trunk@45138
git-svn-id: http://core.svn.wordpress.org/trunk@44947 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-04-08 08:37:57 +02:00
|
|
|
}
|
2021-04-15 17:19:43 +02:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/is-horizontal-edge.js
|
2021-04-15 17:19:43 +02:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
|
Block Editor: Update packages to bring a selection of bugfixes in.
Props iseulde, kjellr, aduth, 0mirka00, mcsf, nosolosw, gziolo, jasmussen, talldanwp, notnownikki, swissspidy, jorgefilipecosta, noisysocks.
See https://github.com/WordPress/gutenberg/pull/14796.
Fixes #46801.
Built from https://develop.svn.wordpress.org/trunk@45138
git-svn-id: http://core.svn.wordpress.org/trunk@44947 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-04-08 08:37:57 +02:00
|
|
|
/**
|
|
|
|
* Check whether the selection is horizontally at the edge of the container.
|
|
|
|
*
|
2023-09-26 16:23:26 +02:00
|
|
|
* @param {HTMLElement} container Focusable element.
|
|
|
|
* @param {boolean} isReverse Set to true to check left, false for right.
|
Block Editor: Update packages to bring a selection of bugfixes in.
Props iseulde, kjellr, aduth, 0mirka00, mcsf, nosolosw, gziolo, jasmussen, talldanwp, notnownikki, swissspidy, jorgefilipecosta, noisysocks.
See https://github.com/WordPress/gutenberg/pull/14796.
Fixes #46801.
Built from https://develop.svn.wordpress.org/trunk@45138
git-svn-id: http://core.svn.wordpress.org/trunk@44947 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-04-08 08:37:57 +02:00
|
|
|
*
|
|
|
|
* @return {boolean} True if at the horizontal edge, false if not.
|
|
|
|
*/
|
|
|
|
function isHorizontalEdge(container, isReverse) {
|
|
|
|
return isEdge(container, isReverse);
|
2018-12-14 05:41:57 +01:00
|
|
|
}
|
2021-04-15 17:19:43 +02:00
|
|
|
|
2022-09-20 17:43:29 +02:00
|
|
|
;// CONCATENATED MODULE: external ["wp","deprecated"]
|
2024-01-31 13:59:56 +01:00
|
|
|
const external_wp_deprecated_namespaceObject = window["wp"]["deprecated"];
|
2022-09-20 17:43:29 +02:00
|
|
|
var external_wp_deprecated_default = /*#__PURE__*/__webpack_require__.n(external_wp_deprecated_namespaceObject);
|
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/is-number-input.js
|
|
|
|
/**
|
|
|
|
* WordPress dependencies
|
|
|
|
*/
|
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2022-09-20 17:43:29 +02:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/* eslint-disable jsdoc/valid-types */
|
|
|
|
/**
|
|
|
|
* Check whether the given element is an input field of type number.
|
|
|
|
*
|
|
|
|
* @param {Node} node The HTML node.
|
|
|
|
*
|
|
|
|
* @return {node is HTMLInputElement} True if the node is number input.
|
|
|
|
*/
|
|
|
|
function isNumberInput(node) {
|
|
|
|
external_wp_deprecated_default()('wp.dom.isNumberInput', {
|
|
|
|
since: '6.1',
|
|
|
|
version: '6.5'
|
|
|
|
});
|
|
|
|
/* eslint-enable jsdoc/valid-types */
|
|
|
|
return isHTMLInputElement(node) && node.type === 'number' && !isNaN(node.valueAsNumber);
|
|
|
|
}
|
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/is-vertical-edge.js
|
2021-04-15 17:19:43 +02:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2018-12-14 05:41:57 +01:00
|
|
|
/**
|
|
|
|
* Check whether the selection is vertically at the edge of the container.
|
|
|
|
*
|
2023-09-26 16:23:26 +02:00
|
|
|
* @param {HTMLElement} container Focusable element.
|
|
|
|
* @param {boolean} isReverse Set to true to check top, false for bottom.
|
2018-12-14 05:41:57 +01:00
|
|
|
*
|
Block Editor: Update packages to bring a selection of bugfixes in.
Props iseulde, kjellr, aduth, 0mirka00, mcsf, nosolosw, gziolo, jasmussen, talldanwp, notnownikki, swissspidy, jorgefilipecosta, noisysocks.
See https://github.com/WordPress/gutenberg/pull/14796.
Fixes #46801.
Built from https://develop.svn.wordpress.org/trunk@45138
git-svn-id: http://core.svn.wordpress.org/trunk@44947 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-04-08 08:37:57 +02:00
|
|
|
* @return {boolean} True if at the vertical edge, false if not.
|
2018-12-14 05:41:57 +01:00
|
|
|
*/
|
|
|
|
function isVerticalEdge(container, isReverse) {
|
Block Editor: Update packages to bring a selection of bugfixes in.
Props iseulde, kjellr, aduth, 0mirka00, mcsf, nosolosw, gziolo, jasmussen, talldanwp, notnownikki, swissspidy, jorgefilipecosta, noisysocks.
See https://github.com/WordPress/gutenberg/pull/14796.
Fixes #46801.
Built from https://develop.svn.wordpress.org/trunk@45138
git-svn-id: http://core.svn.wordpress.org/trunk@44947 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2019-04-08 08:37:57 +02:00
|
|
|
return isEdge(container, isReverse, true);
|
2018-12-14 05:41:57 +01:00
|
|
|
}
|
2021-04-15 17:19:43 +02:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/place-caret-at-edge.js
|
2018-12-14 05:41:57 +01:00
|
|
|
/**
|
2021-04-15 17:19:43 +02:00
|
|
|
* Internal dependencies
|
2018-12-14 05:41:57 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2021-05-07 13:48:27 +02:00
|
|
|
|
2021-05-19 17:09:27 +02:00
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
|
|
|
|
|
2021-05-21 12:14:23 +02:00
|
|
|
/**
|
|
|
|
* Gets the range to place.
|
|
|
|
*
|
2021-11-08 15:29:21 +01:00
|
|
|
* @param {HTMLElement} container Focusable element.
|
|
|
|
* @param {boolean} isReverse True for end, false for start.
|
|
|
|
* @param {number|undefined} x X coordinate to vertically position.
|
2021-05-21 12:14:23 +02:00
|
|
|
*
|
|
|
|
* @return {Range|null} The range to place.
|
|
|
|
*/
|
2021-11-08 15:29:21 +01:00
|
|
|
function getRange(container, isReverse, x) {
|
2021-05-21 12:14:23 +02:00
|
|
|
const {
|
|
|
|
ownerDocument
|
2023-09-26 16:23:26 +02:00
|
|
|
} = container;
|
|
|
|
// In the case of RTL scripts, the horizontal edge is at the opposite side.
|
2021-05-21 12:14:23 +02:00
|
|
|
const isReverseDir = isRTL(container) ? !isReverse : isReverse;
|
2023-09-26 16:23:26 +02:00
|
|
|
const containerRect = container.getBoundingClientRect();
|
|
|
|
// When placing at the end (isReverse), find the closest range to the bottom
|
2021-05-21 12:14:23 +02:00
|
|
|
// right corner. When placing at the start, to the top left corner.
|
2022-09-20 17:43:29 +02:00
|
|
|
// Ensure x is defined and within the container's boundaries. When it's
|
|
|
|
// exactly at the boundary, it's not considered within the boundaries.
|
2021-11-08 15:29:21 +01:00
|
|
|
if (x === undefined) {
|
|
|
|
x = isReverse ? containerRect.right - 1 : containerRect.left + 1;
|
2022-09-20 17:43:29 +02:00
|
|
|
} else if (x <= containerRect.left) {
|
|
|
|
x = containerRect.left + 1;
|
|
|
|
} else if (x >= containerRect.right) {
|
|
|
|
x = containerRect.right - 1;
|
2021-11-08 15:29:21 +01:00
|
|
|
}
|
2021-05-21 12:14:23 +02:00
|
|
|
const y = isReverseDir ? containerRect.bottom - 1 : containerRect.top + 1;
|
|
|
|
return hiddenCaretRangeFromPoint(ownerDocument, x, y, container);
|
|
|
|
}
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2018-12-14 05:41:57 +01:00
|
|
|
/**
|
|
|
|
* Places the caret at start or end of a given element.
|
|
|
|
*
|
2021-11-08 15:29:21 +01:00
|
|
|
* @param {HTMLElement} container Focusable element.
|
|
|
|
* @param {boolean} isReverse True for end, false for start.
|
|
|
|
* @param {number|undefined} x X coordinate to vertically position.
|
2018-12-14 05:41:57 +01:00
|
|
|
*/
|
2021-11-08 15:29:21 +01:00
|
|
|
function placeCaretAtEdge(container, isReverse, x) {
|
2018-12-14 05:41:57 +01:00
|
|
|
if (!container) {
|
|
|
|
return;
|
|
|
|
}
|
2021-04-15 17:19:43 +02:00
|
|
|
container.focus();
|
2021-05-07 13:48:27 +02:00
|
|
|
if (isInputOrTextArea(container)) {
|
2021-04-15 17:19:43 +02:00
|
|
|
// The element may not support selection setting.
|
|
|
|
if (typeof container.selectionStart !== 'number') {
|
|
|
|
return;
|
|
|
|
}
|
2018-12-14 05:41:57 +01:00
|
|
|
if (isReverse) {
|
|
|
|
container.selectionStart = container.value.length;
|
|
|
|
container.selectionEnd = container.value.length;
|
|
|
|
} else {
|
|
|
|
container.selectionStart = 0;
|
|
|
|
container.selectionEnd = 0;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!container.isContentEditable) {
|
|
|
|
return;
|
2021-04-15 17:19:43 +02:00
|
|
|
}
|
2023-09-26 16:23:26 +02:00
|
|
|
const range = scrollIfNoRange(container, isReverse, () => getRange(container, isReverse, x));
|
|
|
|
if (!range) return;
|
2021-05-21 12:14:23 +02:00
|
|
|
const {
|
|
|
|
ownerDocument
|
|
|
|
} = container;
|
2021-05-19 17:09:27 +02:00
|
|
|
const {
|
|
|
|
defaultView
|
|
|
|
} = ownerDocument;
|
2021-05-07 13:48:27 +02:00
|
|
|
assertIsDefined(defaultView, 'defaultView');
|
2021-05-19 17:09:27 +02:00
|
|
|
const selection = defaultView.getSelection();
|
2021-05-07 13:48:27 +02:00
|
|
|
assertIsDefined(selection, 'selection');
|
2018-12-14 05:41:57 +01:00
|
|
|
selection.removeAllRanges();
|
|
|
|
selection.addRange(range);
|
|
|
|
}
|
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/place-caret-at-horizontal-edge.js
|
2018-12-14 05:41:57 +01:00
|
|
|
/**
|
2021-04-15 17:19:43 +02:00
|
|
|
* Internal dependencies
|
2018-12-14 05:41:57 +01:00
|
|
|
*/
|
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2018-12-14 05:41:57 +01:00
|
|
|
/**
|
2021-11-08 15:29:21 +01:00
|
|
|
* Places the caret at start or end of a given element.
|
2018-12-14 05:41:57 +01:00
|
|
|
*
|
2021-11-08 15:29:21 +01:00
|
|
|
* @param {HTMLElement} container Focusable element.
|
|
|
|
* @param {boolean} isReverse True for end, false for start.
|
2018-12-14 05:41:57 +01:00
|
|
|
*/
|
2021-11-08 15:29:21 +01:00
|
|
|
function placeCaretAtHorizontalEdge(container, isReverse) {
|
|
|
|
return placeCaretAtEdge(container, isReverse, undefined);
|
|
|
|
}
|
2021-05-21 12:14:23 +02:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/place-caret-at-vertical-edge.js
|
2021-11-08 15:29:21 +01:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2018-12-14 05:41:57 +01:00
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2021-11-08 15:29:21 +01:00
|
|
|
/**
|
|
|
|
* Places the caret at the top or bottom of a given element.
|
|
|
|
*
|
|
|
|
* @param {HTMLElement} container Focusable element.
|
|
|
|
* @param {boolean} isReverse True for bottom, false for top.
|
|
|
|
* @param {DOMRect} [rect] The rectangle to position the caret with.
|
|
|
|
*/
|
|
|
|
function placeCaretAtVerticalEdge(container, isReverse, rect) {
|
2023-06-27 16:24:19 +02:00
|
|
|
return placeCaretAtEdge(container, isReverse, rect?.left);
|
2018-12-14 05:41:57 +01:00
|
|
|
}
|
2021-04-15 17:19:43 +02:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/insert-after.js
|
2018-12-14 05:41:57 +01:00
|
|
|
/**
|
2021-04-15 17:19:43 +02:00
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2021-04-15 17:19:43 +02:00
|
|
|
/**
|
|
|
|
* Given two DOM nodes, inserts the former in the DOM as the next sibling of
|
|
|
|
* the latter.
|
2018-12-14 05:41:57 +01:00
|
|
|
*
|
2021-04-15 17:19:43 +02:00
|
|
|
* @param {Node} newNode Node to be inserted.
|
|
|
|
* @param {Node} referenceNode Node after which to perform the insertion.
|
|
|
|
* @return {void}
|
|
|
|
*/
|
|
|
|
function insertAfter(newNode, referenceNode) {
|
|
|
|
assertIsDefined(referenceNode.parentNode, 'referenceNode.parentNode');
|
|
|
|
referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
|
|
|
|
}
|
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/remove.js
|
2021-04-15 17:19:43 +02:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2021-04-15 17:19:43 +02:00
|
|
|
/**
|
|
|
|
* Given a DOM node, removes it from the DOM.
|
2018-12-14 05:41:57 +01:00
|
|
|
*
|
2021-04-15 17:19:43 +02:00
|
|
|
* @param {Node} node Node to be removed.
|
|
|
|
* @return {void}
|
|
|
|
*/
|
|
|
|
function remove(node) {
|
|
|
|
assertIsDefined(node.parentNode, 'node.parentNode');
|
|
|
|
node.parentNode.removeChild(node);
|
|
|
|
}
|
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/replace.js
|
2021-04-15 17:19:43 +02:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2021-05-07 13:48:27 +02:00
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2021-04-15 17:19:43 +02:00
|
|
|
/**
|
|
|
|
* Given two DOM nodes, replaces the former with the latter in the DOM.
|
2018-12-14 05:41:57 +01:00
|
|
|
*
|
2021-04-15 17:19:43 +02:00
|
|
|
* @param {Element} processedNode Node to be removed.
|
|
|
|
* @param {Element} newNode Node to be inserted in its place.
|
|
|
|
* @return {void}
|
2018-12-14 05:41:57 +01:00
|
|
|
*/
|
2021-04-15 17:19:43 +02:00
|
|
|
function replace(processedNode, newNode) {
|
2021-05-07 13:48:27 +02:00
|
|
|
assertIsDefined(processedNode.parentNode, 'processedNode.parentNode');
|
2021-04-15 17:19:43 +02:00
|
|
|
insertAfter(newNode, processedNode.parentNode);
|
|
|
|
remove(processedNode);
|
2018-12-14 05:41:57 +01:00
|
|
|
}
|
2021-04-15 17:19:43 +02:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/unwrap.js
|
2018-12-14 05:41:57 +01:00
|
|
|
/**
|
2021-04-15 17:19:43 +02:00
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2021-04-15 17:19:43 +02:00
|
|
|
/**
|
|
|
|
* Unwrap the given node. This means any child nodes are moved to the parent.
|
2018-12-14 05:41:57 +01:00
|
|
|
*
|
2021-04-15 17:19:43 +02:00
|
|
|
* @param {Node} node The node to unwrap.
|
2020-06-26 15:33:47 +02:00
|
|
|
*
|
2021-04-15 17:19:43 +02:00
|
|
|
* @return {void}
|
2018-12-14 05:41:57 +01:00
|
|
|
*/
|
2021-04-15 17:19:43 +02:00
|
|
|
function unwrap(node) {
|
2021-05-19 17:09:27 +02:00
|
|
|
const parent = node.parentNode;
|
2021-04-15 17:19:43 +02:00
|
|
|
assertIsDefined(parent, 'node.parentNode');
|
|
|
|
while (node.firstChild) {
|
|
|
|
parent.insertBefore(node.firstChild, node);
|
|
|
|
}
|
|
|
|
parent.removeChild(node);
|
2020-06-26 15:33:47 +02:00
|
|
|
}
|
2021-04-15 17:19:43 +02:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/replace-tag.js
|
2021-05-07 13:48:27 +02:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2020-06-26 15:33:47 +02:00
|
|
|
/**
|
2021-04-15 17:19:43 +02:00
|
|
|
* Replaces the given node with a new node with the given tag name.
|
2020-06-26 15:33:47 +02:00
|
|
|
*
|
2021-11-08 15:29:21 +01:00
|
|
|
* @param {Element} node The node to replace
|
|
|
|
* @param {string} tagName The new tag name.
|
2020-10-13 15:10:30 +02:00
|
|
|
*
|
2021-04-15 17:19:43 +02:00
|
|
|
* @return {Element} The new node.
|
2020-06-26 15:33:47 +02:00
|
|
|
*/
|
2021-04-15 17:19:43 +02:00
|
|
|
function replaceTag(node, tagName) {
|
2021-05-19 17:09:27 +02:00
|
|
|
const newNode = node.ownerDocument.createElement(tagName);
|
2021-04-15 17:19:43 +02:00
|
|
|
while (node.firstChild) {
|
|
|
|
newNode.appendChild(node.firstChild);
|
|
|
|
}
|
2021-05-07 13:48:27 +02:00
|
|
|
assertIsDefined(node.parentNode, 'node.parentNode');
|
2021-04-15 17:19:43 +02:00
|
|
|
node.parentNode.replaceChild(newNode, node);
|
|
|
|
return newNode;
|
2018-12-14 05:41:57 +01:00
|
|
|
}
|
2021-04-15 17:19:43 +02:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/wrap.js
|
2021-05-07 13:48:27 +02:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2020-06-26 15:33:47 +02:00
|
|
|
/**
|
2021-04-15 17:19:43 +02:00
|
|
|
* Wraps the given node with a new node with the given tag name.
|
2020-06-26 15:33:47 +02:00
|
|
|
*
|
2021-04-15 17:19:43 +02:00
|
|
|
* @param {Element} newNode The node to insert.
|
|
|
|
* @param {Element} referenceNode The node to wrap.
|
|
|
|
*/
|
|
|
|
function wrap(newNode, referenceNode) {
|
2021-05-07 13:48:27 +02:00
|
|
|
assertIsDefined(referenceNode.parentNode, 'referenceNode.parentNode');
|
2021-04-15 17:19:43 +02:00
|
|
|
referenceNode.parentNode.insertBefore(newNode, referenceNode);
|
|
|
|
newNode.appendChild(referenceNode);
|
|
|
|
}
|
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/safe-html.js
|
2021-11-08 15:29:21 +01:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2021-11-08 15:29:21 +01:00
|
|
|
/**
|
|
|
|
* Strips scripts and on* attributes from HTML.
|
|
|
|
*
|
|
|
|
* @param {string} html HTML to sanitize.
|
|
|
|
*
|
|
|
|
* @return {string} The sanitized HTML.
|
|
|
|
*/
|
|
|
|
function safeHTML(html) {
|
|
|
|
const {
|
|
|
|
body
|
|
|
|
} = document.implementation.createHTMLDocument('');
|
|
|
|
body.innerHTML = html;
|
|
|
|
const elements = body.getElementsByTagName('*');
|
|
|
|
let elementIndex = elements.length;
|
|
|
|
while (elementIndex--) {
|
|
|
|
const element = elements[elementIndex];
|
|
|
|
if (element.tagName === 'SCRIPT') {
|
|
|
|
remove(element);
|
|
|
|
} else {
|
|
|
|
let attributeIndex = element.attributes.length;
|
|
|
|
while (attributeIndex--) {
|
|
|
|
const {
|
|
|
|
name: key
|
|
|
|
} = element.attributes[attributeIndex];
|
|
|
|
if (key.startsWith('on')) {
|
|
|
|
element.removeAttribute(key);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return body.innerHTML;
|
|
|
|
}
|
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/strip-html.js
|
2021-11-08 15:29:21 +01:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2021-04-15 17:19:43 +02:00
|
|
|
/**
|
|
|
|
* Removes any HTML tags from the provided string.
|
2020-06-26 15:33:47 +02:00
|
|
|
*
|
2021-04-15 17:19:43 +02:00
|
|
|
* @param {string} html The string containing html.
|
2020-06-26 15:33:47 +02:00
|
|
|
*
|
2021-04-15 17:19:43 +02:00
|
|
|
* @return {string} The text content with any html removed.
|
|
|
|
*/
|
|
|
|
function stripHTML(html) {
|
2021-11-08 15:29:21 +01:00
|
|
|
// Remove any script tags or on* attributes otherwise their *contents* will be left
|
|
|
|
// in place following removal of HTML tags.
|
|
|
|
html = safeHTML(html);
|
|
|
|
const doc = document.implementation.createHTMLDocument('');
|
|
|
|
doc.body.innerHTML = html;
|
|
|
|
return doc.body.textContent || '';
|
2021-04-15 17:19:43 +02:00
|
|
|
}
|
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/is-empty.js
|
2021-04-15 17:19:43 +02:00
|
|
|
/**
|
|
|
|
* Recursively checks if an element is empty. An element is not empty if it
|
|
|
|
* contains text or contains elements with attributes such as images.
|
2020-06-26 15:33:47 +02:00
|
|
|
*
|
2021-04-15 17:19:43 +02:00
|
|
|
* @param {Element} element The element to check.
|
|
|
|
*
|
|
|
|
* @return {boolean} Whether or not the element is empty.
|
2020-06-26 15:33:47 +02:00
|
|
|
*/
|
2021-04-15 17:19:43 +02:00
|
|
|
function isEmpty(element) {
|
|
|
|
switch (element.nodeType) {
|
|
|
|
case element.TEXT_NODE:
|
|
|
|
// We cannot use \s since it includes special spaces which we want
|
|
|
|
// to preserve.
|
|
|
|
return /^[ \f\n\r\t\v\u00a0]*$/.test(element.nodeValue || '');
|
|
|
|
case element.ELEMENT_NODE:
|
|
|
|
if (element.hasAttributes()) {
|
|
|
|
return false;
|
|
|
|
} else if (!element.hasChildNodes()) {
|
|
|
|
return true;
|
|
|
|
}
|
2024-02-09 19:22:22 +01:00
|
|
|
return /** @type {Element[]} */Array.from(element.childNodes).every(isEmpty);
|
2021-04-15 17:19:43 +02:00
|
|
|
default:
|
|
|
|
return true;
|
2020-06-26 15:33:47 +02:00
|
|
|
}
|
|
|
|
}
|
2021-04-15 17:19:43 +02:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/phrasing-content.js
|
2021-04-15 17:19:43 +02:00
|
|
|
/**
|
|
|
|
* All phrasing content elements.
|
2020-06-26 15:33:47 +02:00
|
|
|
*
|
2021-04-15 17:19:43 +02:00
|
|
|
* @see https://www.w3.org/TR/2011/WD-html5-20110525/content-models.html#phrasing-content-0
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @typedef {Record<string,SemanticElementDefinition>} ContentSchema
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @typedef SemanticElementDefinition
|
2021-11-08 15:29:21 +01:00
|
|
|
* @property {string[]} [attributes] Content attributes
|
|
|
|
* @property {ContentSchema} [children] Content attributes
|
2021-04-15 17:19:43 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* All text-level semantic elements.
|
2020-10-13 15:10:30 +02:00
|
|
|
*
|
2021-04-15 17:19:43 +02:00
|
|
|
* @see https://html.spec.whatwg.org/multipage/text-level-semantics.html
|
|
|
|
*
|
|
|
|
* @type {ContentSchema}
|
2020-06-26 15:33:47 +02:00
|
|
|
*/
|
2021-05-19 17:09:27 +02:00
|
|
|
const textContentSchema = {
|
2021-04-15 17:19:43 +02:00
|
|
|
strong: {},
|
|
|
|
em: {},
|
|
|
|
s: {},
|
|
|
|
del: {},
|
|
|
|
ins: {},
|
|
|
|
a: {
|
2021-11-08 15:29:21 +01:00
|
|
|
attributes: ['href', 'target', 'rel', 'id']
|
2021-04-15 17:19:43 +02:00
|
|
|
},
|
|
|
|
code: {},
|
|
|
|
abbr: {
|
|
|
|
attributes: ['title']
|
|
|
|
},
|
|
|
|
sub: {},
|
|
|
|
sup: {},
|
|
|
|
br: {},
|
|
|
|
small: {},
|
|
|
|
// To do: fix blockquote.
|
|
|
|
// cite: {},
|
|
|
|
q: {
|
|
|
|
attributes: ['cite']
|
|
|
|
},
|
|
|
|
dfn: {
|
|
|
|
attributes: ['title']
|
|
|
|
},
|
|
|
|
data: {
|
|
|
|
attributes: ['value']
|
|
|
|
},
|
|
|
|
time: {
|
|
|
|
attributes: ['datetime']
|
|
|
|
},
|
|
|
|
var: {},
|
|
|
|
samp: {},
|
|
|
|
kbd: {},
|
|
|
|
i: {},
|
|
|
|
b: {},
|
|
|
|
u: {},
|
|
|
|
mark: {},
|
|
|
|
ruby: {},
|
|
|
|
rt: {},
|
|
|
|
rp: {},
|
|
|
|
bdi: {
|
|
|
|
attributes: ['dir']
|
|
|
|
},
|
|
|
|
bdo: {
|
|
|
|
attributes: ['dir']
|
|
|
|
},
|
|
|
|
wbr: {},
|
|
|
|
'#text': {}
|
2023-09-26 16:23:26 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Recursion is needed.
|
2021-04-15 17:19:43 +02:00
|
|
|
// Possible: strong > em > strong.
|
|
|
|
// Impossible: strong > strong.
|
2022-09-20 17:43:29 +02:00
|
|
|
const excludedElements = ['#text', 'br'];
|
|
|
|
Object.keys(textContentSchema).filter(element => !excludedElements.includes(element)).forEach(tag => {
|
|
|
|
const {
|
|
|
|
[tag]: removedTag,
|
|
|
|
...restSchema
|
|
|
|
} = textContentSchema;
|
|
|
|
textContentSchema[tag].children = restSchema;
|
2021-04-15 17:19:43 +02:00
|
|
|
});
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2021-04-15 17:19:43 +02:00
|
|
|
/**
|
|
|
|
* Embedded content elements.
|
|
|
|
*
|
|
|
|
* @see https://www.w3.org/TR/2011/WD-html5-20110525/content-models.html#embedded-content-0
|
|
|
|
*
|
|
|
|
* @type {ContentSchema}
|
|
|
|
*/
|
2021-05-19 17:09:27 +02:00
|
|
|
const embeddedContentSchema = {
|
2021-04-15 17:19:43 +02:00
|
|
|
audio: {
|
|
|
|
attributes: ['src', 'preload', 'autoplay', 'mediagroup', 'loop', 'muted']
|
|
|
|
},
|
|
|
|
canvas: {
|
|
|
|
attributes: ['width', 'height']
|
|
|
|
},
|
|
|
|
embed: {
|
|
|
|
attributes: ['src', 'type', 'width', 'height']
|
|
|
|
},
|
|
|
|
img: {
|
|
|
|
attributes: ['alt', 'src', 'srcset', 'usemap', 'ismap', 'width', 'height']
|
|
|
|
},
|
|
|
|
object: {
|
|
|
|
attributes: ['data', 'type', 'name', 'usemap', 'form', 'width', 'height']
|
|
|
|
},
|
|
|
|
video: {
|
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
This patch, somewhat small brings a lot to WordPress.
This includes features like:
- DataViews.
- Customization tools like box shadow, background size and repeat.
- UI improvements in the site editor.
- Preferences sharing between the post and site editors.
- Unified panels and editors between post and site editors.
- Improved template mode in the post editor.
- Iterations to multiple interactive blocks.
- Preparing the blocks and UI for pattern overrides.
- and a lot more.
Props luisherranz, gziolo, isabel_brison, costdev, jonsurrell, peterwilsoncc, get_dave, antonvlasenko, desrosj.
See #60315.
Built from https://develop.svn.wordpress.org/trunk@57377
git-svn-id: http://core.svn.wordpress.org/trunk@56883 1a063a9b-81f0-0310-95a4-ce76da25c4cd
2024-01-29 22:07:12 +01:00
|
|
|
attributes: ['src', 'poster', 'preload', 'playsinline', 'autoplay', 'mediagroup', 'loop', 'muted', 'controls', 'width', 'height']
|
2021-04-15 17:19:43 +02:00
|
|
|
}
|
|
|
|
};
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2020-06-26 15:33:47 +02:00
|
|
|
/**
|
2021-04-15 17:19:43 +02:00
|
|
|
* Phrasing content elements.
|
2020-10-13 15:10:30 +02:00
|
|
|
*
|
2021-04-15 17:19:43 +02:00
|
|
|
* @see https://www.w3.org/TR/2011/WD-html5-20110525/content-models.html#phrasing-content-0
|
2020-06-26 15:33:47 +02:00
|
|
|
*/
|
2023-09-26 16:23:26 +02:00
|
|
|
const phrasingContentSchema = {
|
|
|
|
...textContentSchema,
|
2021-05-19 17:09:27 +02:00
|
|
|
...embeddedContentSchema
|
|
|
|
};
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2018-12-14 05:41:57 +01:00
|
|
|
/**
|
2021-04-15 17:19:43 +02:00
|
|
|
* Get schema of possible paths for phrasing content.
|
2018-12-14 05:41:57 +01:00
|
|
|
*
|
2021-04-15 17:19:43 +02:00
|
|
|
* @see https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories#Phrasing_content
|
2018-12-14 05:41:57 +01:00
|
|
|
*
|
2021-04-15 17:19:43 +02:00
|
|
|
* @param {string} [context] Set to "paste" to exclude invisible elements and
|
2021-11-08 15:29:21 +01:00
|
|
|
* sensitive data.
|
2018-12-14 05:41:57 +01:00
|
|
|
*
|
2021-04-15 17:19:43 +02:00
|
|
|
* @return {Partial<ContentSchema>} Schema.
|
2018-12-14 05:41:57 +01:00
|
|
|
*/
|
2021-04-15 17:19:43 +02:00
|
|
|
function getPhrasingContentSchema(context) {
|
|
|
|
if (context !== 'paste') {
|
|
|
|
return phrasingContentSchema;
|
|
|
|
}
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2022-09-20 17:43:29 +02:00
|
|
|
/**
|
|
|
|
* @type {Partial<ContentSchema>}
|
|
|
|
*/
|
|
|
|
const {
|
|
|
|
u,
|
|
|
|
// Used to mark misspelling. Shouldn't be pasted.
|
|
|
|
abbr,
|
|
|
|
// Invisible.
|
|
|
|
data,
|
|
|
|
// Invisible.
|
|
|
|
time,
|
|
|
|
// Invisible.
|
|
|
|
wbr,
|
|
|
|
// Invisible.
|
|
|
|
bdi,
|
|
|
|
// Invisible.
|
|
|
|
bdo,
|
|
|
|
// Invisible.
|
|
|
|
...remainingContentSchema
|
2023-09-26 16:23:26 +02:00
|
|
|
} = {
|
|
|
|
...phrasingContentSchema,
|
2021-04-15 17:19:43 +02:00
|
|
|
// We shouldn't paste potentially sensitive information which is not
|
|
|
|
// visible to the user when pasted, so strip the attributes.
|
|
|
|
ins: {
|
|
|
|
children: phrasingContentSchema.ins.children
|
|
|
|
},
|
|
|
|
del: {
|
|
|
|
children: phrasingContentSchema.del.children
|
2018-12-14 05:41:57 +01:00
|
|
|
}
|
2022-09-20 17:43:29 +02:00
|
|
|
};
|
|
|
|
return remainingContentSchema;
|
2018-12-14 05:41:57 +01:00
|
|
|
}
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2018-12-14 05:41:57 +01:00
|
|
|
/**
|
2021-04-15 17:19:43 +02:00
|
|
|
* Find out whether or not the given node is phrasing content.
|
2018-12-14 05:41:57 +01:00
|
|
|
*
|
2021-04-15 17:19:43 +02:00
|
|
|
* @see https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories#Phrasing_content
|
2018-12-14 05:41:57 +01:00
|
|
|
*
|
2021-04-15 17:19:43 +02:00
|
|
|
* @param {Node} node The node to test.
|
2018-12-14 05:41:57 +01:00
|
|
|
*
|
2021-04-15 17:19:43 +02:00
|
|
|
* @return {boolean} True if phrasing content, false if not.
|
2018-12-14 05:41:57 +01:00
|
|
|
*/
|
2021-04-15 17:19:43 +02:00
|
|
|
function isPhrasingContent(node) {
|
2021-05-19 17:09:27 +02:00
|
|
|
const tag = node.nodeName.toLowerCase();
|
2021-04-15 17:19:43 +02:00
|
|
|
return getPhrasingContentSchema().hasOwnProperty(tag) || tag === 'span';
|
2018-12-14 05:41:57 +01:00
|
|
|
}
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2018-12-14 05:41:57 +01:00
|
|
|
/**
|
2021-04-15 17:19:43 +02:00
|
|
|
* @param {Node} node
|
|
|
|
* @return {boolean} Node is text content
|
2018-12-14 05:41:57 +01:00
|
|
|
*/
|
2021-04-15 17:19:43 +02:00
|
|
|
function isTextContent(node) {
|
2021-05-19 17:09:27 +02:00
|
|
|
const tag = node.nodeName.toLowerCase();
|
2021-04-15 17:19:43 +02:00
|
|
|
return textContentSchema.hasOwnProperty(tag) || tag === 'span';
|
2018-12-14 05:41:57 +01:00
|
|
|
}
|
2021-04-15 17:19:43 +02:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/is-element.js
|
2021-04-15 17:19:43 +02:00
|
|
|
/* eslint-disable jsdoc/valid-types */
|
2018-12-14 05:41:57 +01:00
|
|
|
/**
|
2021-04-15 17:19:43 +02:00
|
|
|
* @param {Node | null | undefined} node
|
|
|
|
* @return {node is Element} True if node is an Element node
|
2018-12-14 05:41:57 +01:00
|
|
|
*/
|
2021-04-15 17:19:43 +02:00
|
|
|
function isElement(node) {
|
|
|
|
/* eslint-enable jsdoc/valid-types */
|
|
|
|
return !!node && node.nodeType === node.ELEMENT_NODE;
|
2018-12-14 05:41:57 +01:00
|
|
|
}
|
2021-04-15 17:19:43 +02:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/clean-node-list.js
|
2018-12-14 05:41:57 +01:00
|
|
|
/**
|
2021-04-15 17:19:43 +02:00
|
|
|
* Internal dependencies
|
2018-12-14 05:41:57 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2022-09-20 17:43:29 +02:00
|
|
|
const noop = () => {};
|
2021-04-15 17:19:43 +02:00
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
/* eslint-disable jsdoc/valid-types */
|
2020-02-06 22:03:31 +01:00
|
|
|
/**
|
2021-04-15 17:19:43 +02:00
|
|
|
* @typedef SchemaItem
|
2021-11-08 15:29:21 +01:00
|
|
|
* @property {string[]} [attributes] Attributes.
|
|
|
|
* @property {(string | RegExp)[]} [classes] Classnames or RegExp to test against.
|
|
|
|
* @property {'*' | { [tag: string]: SchemaItem }} [children] Child schemas.
|
|
|
|
* @property {string[]} [require] Selectors to test required children against. Leave empty or undefined if there are no requirements.
|
|
|
|
* @property {boolean} allowEmpty Whether to allow nodes without children.
|
|
|
|
* @property {(node: Node) => boolean} [isMatch] Function to test whether a node is a match. If left undefined any node will be assumed to match.
|
2020-02-06 22:03:31 +01:00
|
|
|
*/
|
|
|
|
|
2021-04-15 17:19:43 +02:00
|
|
|
/** @typedef {{ [tag: string]: SchemaItem }} Schema */
|
|
|
|
/* eslint-enable jsdoc/valid-types */
|
|
|
|
|
2020-10-13 15:10:30 +02:00
|
|
|
/**
|
|
|
|
* Given a schema, unwraps or removes nodes, attributes and classes on a node
|
|
|
|
* list.
|
|
|
|
*
|
|
|
|
* @param {NodeList} nodeList The nodeList to filter.
|
|
|
|
* @param {Document} doc The document of the nodeList.
|
2021-04-15 17:19:43 +02:00
|
|
|
* @param {Schema} schema An array of functions that can mutate with the provided node.
|
|
|
|
* @param {boolean} inline Whether to clean for inline mode.
|
2020-10-13 15:10:30 +02:00
|
|
|
*/
|
|
|
|
function cleanNodeList(nodeList, doc, schema, inline) {
|
2023-09-26 16:23:26 +02:00
|
|
|
Array.from(nodeList).forEach(( /** @type {Node & { nextElementSibling?: unknown }} */node) => {
|
|
|
|
const tag = node.nodeName.toLowerCase();
|
2020-10-13 15:10:30 +02:00
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
// It's a valid child, if the tag exists in the schema without an isMatch
|
|
|
|
// function, or with an isMatch function that matches the node.
|
2023-06-27 16:24:19 +02:00
|
|
|
if (schema.hasOwnProperty(tag) && (!schema[tag].isMatch || schema[tag].isMatch?.(node))) {
|
2021-04-15 17:19:43 +02:00
|
|
|
if (isElement(node)) {
|
2021-05-19 17:09:27 +02:00
|
|
|
const {
|
|
|
|
attributes = [],
|
|
|
|
classes = [],
|
|
|
|
children,
|
|
|
|
require = [],
|
|
|
|
allowEmpty
|
2023-09-26 16:23:26 +02:00
|
|
|
} = schema[tag];
|
2020-10-13 15:10:30 +02:00
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
// If the node is empty and it's supposed to have children,
|
|
|
|
// remove the node.
|
2020-10-13 15:10:30 +02:00
|
|
|
if (children && !allowEmpty && isEmpty(node)) {
|
|
|
|
remove(node);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (node.hasAttributes()) {
|
|
|
|
// Strip invalid attributes.
|
2023-06-27 16:24:19 +02:00
|
|
|
Array.from(node.attributes).forEach(({
|
|
|
|
name
|
|
|
|
}) => {
|
2022-09-20 17:43:29 +02:00
|
|
|
if (name !== 'class' && !attributes.includes(name)) {
|
2020-10-13 15:10:30 +02:00
|
|
|
node.removeAttribute(name);
|
|
|
|
}
|
2023-09-26 16:23:26 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
// Strip invalid classes.
|
2020-10-13 15:10:30 +02:00
|
|
|
// In jsdom-jscore, 'node.classList' can be undefined.
|
|
|
|
// TODO: Explore patching this in jsdom-jscore.
|
|
|
|
if (node.classList && node.classList.length) {
|
2021-05-19 17:09:27 +02:00
|
|
|
const mattchers = classes.map(item => {
|
2020-10-13 15:10:30 +02:00
|
|
|
if (typeof item === 'string') {
|
2023-09-26 16:23:26 +02:00
|
|
|
return ( /** @type {string} */className) => className === item;
|
2020-10-13 15:10:30 +02:00
|
|
|
} else if (item instanceof RegExp) {
|
2023-09-26 16:23:26 +02:00
|
|
|
return ( /** @type {string} */className) => item.test(className);
|
2020-10-13 15:10:30 +02:00
|
|
|
}
|
2022-09-20 17:43:29 +02:00
|
|
|
return noop;
|
2020-10-13 15:10:30 +02:00
|
|
|
});
|
2021-05-19 17:09:27 +02:00
|
|
|
Array.from(node.classList).forEach(name => {
|
|
|
|
if (!mattchers.some(isMatch => isMatch(name))) {
|
2020-10-13 15:10:30 +02:00
|
|
|
node.classList.remove(name);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
if (!node.classList.length) {
|
|
|
|
node.removeAttribute('class');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (node.hasChildNodes()) {
|
|
|
|
// Do not filter any content.
|
|
|
|
if (children === '*') {
|
|
|
|
return;
|
2023-09-26 16:23:26 +02:00
|
|
|
}
|
2020-10-13 15:10:30 +02:00
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
// Continue if the node is supposed to have children.
|
2020-10-13 15:10:30 +02:00
|
|
|
if (children) {
|
|
|
|
// If a parent requires certain children, but it does
|
|
|
|
// not have them, drop the parent and continue.
|
|
|
|
if (require.length && !node.querySelector(require.join(','))) {
|
|
|
|
cleanNodeList(node.childNodes, doc, schema, inline);
|
2023-09-26 16:23:26 +02:00
|
|
|
unwrap(node);
|
|
|
|
// If the node is at the top, phrasing content, and
|
2020-10-13 15:10:30 +02:00
|
|
|
// contains children that are block content, unwrap
|
|
|
|
// the node because it is invalid.
|
2021-04-15 17:19:43 +02:00
|
|
|
} else if (node.parentNode && node.parentNode.nodeName === 'BODY' && isPhrasingContent(node)) {
|
2020-10-13 15:10:30 +02:00
|
|
|
cleanNodeList(node.childNodes, doc, schema, inline);
|
2021-05-19 17:09:27 +02:00
|
|
|
if (Array.from(node.childNodes).some(child => !isPhrasingContent(child))) {
|
2020-10-13 15:10:30 +02:00
|
|
|
unwrap(node);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
cleanNodeList(node.childNodes, doc, children, inline);
|
2023-09-26 16:23:26 +02:00
|
|
|
}
|
|
|
|
// Remove children if the node is not supposed to have any.
|
2020-10-13 15:10:30 +02:00
|
|
|
} else {
|
|
|
|
while (node.firstChild) {
|
|
|
|
remove(node.firstChild);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-09-26 16:23:26 +02:00
|
|
|
}
|
|
|
|
// Invalid child. Continue with schema at the same place and unwrap.
|
2020-10-13 15:10:30 +02:00
|
|
|
} else {
|
2023-09-26 16:23:26 +02:00
|
|
|
cleanNodeList(node.childNodes, doc, schema, inline);
|
2020-10-13 15:10:30 +02:00
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
// For inline mode, insert a line break when unwrapping nodes that
|
|
|
|
// are not phrasing content.
|
2020-10-13 15:10:30 +02:00
|
|
|
if (inline && !isPhrasingContent(node) && node.nextElementSibling) {
|
|
|
|
insertAfter(doc.createElement('br'), node);
|
|
|
|
}
|
|
|
|
unwrap(node);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2021-04-15 17:19:43 +02:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/remove-invalid-html.js
|
2020-10-13 15:10:30 +02:00
|
|
|
/**
|
2021-04-15 17:19:43 +02:00
|
|
|
* Internal dependencies
|
2020-10-13 15:10:30 +02:00
|
|
|
*/
|
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2020-10-13 15:10:30 +02:00
|
|
|
/**
|
|
|
|
* Given a schema, unwraps or removes nodes, attributes and classes on HTML.
|
|
|
|
*
|
2021-11-08 15:29:21 +01:00
|
|
|
* @param {string} HTML The HTML to clean up.
|
2021-05-07 13:48:27 +02:00
|
|
|
* @param {import('./clean-node-list').Schema} schema Schema for the HTML.
|
2021-11-08 15:29:21 +01:00
|
|
|
* @param {boolean} inline Whether to clean for inline mode.
|
2020-10-13 15:10:30 +02:00
|
|
|
*
|
|
|
|
* @return {string} The cleaned up HTML.
|
|
|
|
*/
|
|
|
|
function removeInvalidHTML(HTML, schema, inline) {
|
2021-05-19 17:09:27 +02:00
|
|
|
const doc = document.implementation.createHTMLDocument('');
|
2020-10-13 15:10:30 +02:00
|
|
|
doc.body.innerHTML = HTML;
|
|
|
|
cleanNodeList(doc.body.childNodes, doc, schema, inline);
|
|
|
|
return doc.body.innerHTML;
|
|
|
|
}
|
2018-12-14 05:41:57 +01:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/dom/index.js
|
2021-04-15 17:19:43 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-01-28 03:04:13 +01:00
|
|
|
|
|
|
|
|
2021-04-15 17:19:43 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2021-05-19 17:09:27 +02:00
|
|
|
|
2021-07-14 01:58:30 +02:00
|
|
|
|
2022-04-12 17:12:47 +02:00
|
|
|
|
2021-04-15 17:19:43 +02:00
|
|
|
|
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/data-transfer.js
|
2021-01-28 03:04:13 +01:00
|
|
|
/**
|
|
|
|
* Gets all files from a DataTransfer object.
|
|
|
|
*
|
|
|
|
* @param {DataTransfer} dataTransfer DataTransfer object to inspect.
|
|
|
|
*
|
2021-04-15 17:19:43 +02:00
|
|
|
* @return {File[]} An array containing all files.
|
2021-01-28 03:04:13 +01:00
|
|
|
*/
|
|
|
|
function getFilesFromDataTransfer(dataTransfer) {
|
2021-05-19 17:09:27 +02:00
|
|
|
const files = Array.from(dataTransfer.files);
|
|
|
|
Array.from(dataTransfer.items).forEach(item => {
|
|
|
|
const file = item.getAsFile();
|
2023-06-27 16:24:19 +02:00
|
|
|
if (file && !files.find(({
|
|
|
|
name,
|
|
|
|
type,
|
|
|
|
size
|
|
|
|
}) => name === file.name && type === file.type && size === file.size)) {
|
2021-01-28 03:04:13 +01:00
|
|
|
files.push(file);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return files;
|
|
|
|
}
|
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
;// CONCATENATED MODULE: ./node_modules/@wordpress/dom/build-module/index.js
|
2018-12-14 05:41:57 +01:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2023-09-26 16:23:26 +02:00
|
|
|
|
2019-03-21 13:48:00 +01:00
|
|
|
/**
|
|
|
|
* Object grouping `focusable` and `tabbable` utils
|
|
|
|
* under the keys with the same name.
|
|
|
|
*/
|
2021-05-19 17:09:27 +02:00
|
|
|
const build_module_focus = {
|
2018-12-18 04:14:52 +01:00
|
|
|
focusable: focusable_namespaceObject,
|
|
|
|
tabbable: tabbable_namespaceObject
|
2018-12-14 05:41:57 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-10-13 15:10:30 +02:00
|
|
|
|
2022-04-11 14:04:30 +02:00
|
|
|
(window.wp = window.wp || {}).dom = __webpack_exports__;
|
|
|
|
/******/ })()
|
|
|
|
;
|