@wordpress/dom 3.2.3 → 3.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -4
- package/build/data-transfer.js +8 -5
- package/build/data-transfer.js.map +1 -1
- package/build/dom/caret-range-from-point.js +2 -2
- package/build/dom/caret-range-from-point.js.map +1 -1
- package/build/dom/clean-node-list.js +11 -11
- package/build/dom/clean-node-list.js.map +1 -1
- package/build/dom/document-has-text-selection.js +1 -1
- package/build/dom/document-has-text-selection.js.map +1 -1
- package/build/dom/document-has-uncollapsed-selection.js +2 -2
- package/build/dom/document-has-uncollapsed-selection.js.map +1 -1
- package/build/dom/get-range-height.js +12 -6
- package/build/dom/get-range-height.js.map +1 -1
- package/build/dom/get-rectangle-from-range.js +6 -3
- package/build/dom/get-rectangle-from-range.js.map +1 -1
- package/build/dom/index.js +38 -38
- package/build/dom/is-edge.js +4 -2
- package/build/dom/is-edge.js.map +1 -1
- package/build/dom/place-caret-at-edge.js +108 -0
- package/build/dom/place-caret-at-edge.js.map +1 -0
- package/build/dom/place-caret-at-horizontal-edge.js +2 -84
- package/build/dom/place-caret-at-horizontal-edge.js.map +1 -1
- package/build/dom/place-caret-at-vertical-edge.js +6 -56
- package/build/dom/place-caret-at-vertical-edge.js.map +1 -1
- package/build/dom/strip-html.js +14 -2
- package/build/dom/strip-html.js.map +1 -1
- package/build/focusable.js +30 -17
- package/build/focusable.js.map +1 -1
- package/build/index.js +4 -2
- package/build/index.js.map +1 -1
- package/build/tabbable.js +4 -4
- package/build/tabbable.js.map +1 -1
- package/build-module/data-transfer.js +8 -5
- package/build-module/data-transfer.js.map +1 -1
- package/build-module/dom/caret-range-from-point.js +2 -2
- package/build-module/dom/caret-range-from-point.js.map +1 -1
- package/build-module/dom/clean-node-list.js +11 -11
- package/build-module/dom/clean-node-list.js.map +1 -1
- package/build-module/dom/document-has-text-selection.js +1 -1
- package/build-module/dom/document-has-text-selection.js.map +1 -1
- package/build-module/dom/document-has-uncollapsed-selection.js +2 -2
- package/build-module/dom/document-has-uncollapsed-selection.js.map +1 -1
- package/build-module/dom/get-range-height.js +12 -6
- package/build-module/dom/get-range-height.js.map +1 -1
- package/build-module/dom/get-rectangle-from-range.js +6 -3
- package/build-module/dom/get-rectangle-from-range.js.map +1 -1
- package/build-module/dom/is-edge.js +4 -2
- package/build-module/dom/is-edge.js.map +1 -1
- package/build-module/dom/place-caret-at-edge.js +95 -0
- package/build-module/dom/place-caret-at-edge.js.map +1 -0
- package/build-module/dom/place-caret-at-horizontal-edge.js +2 -81
- package/build-module/dom/place-caret-at-horizontal-edge.js.map +1 -1
- package/build-module/dom/place-caret-at-vertical-edge.js +6 -54
- package/build-module/dom/place-caret-at-vertical-edge.js.map +1 -1
- package/build-module/dom/strip-html.js +11 -2
- package/build-module/dom/strip-html.js.map +1 -1
- package/build-module/focusable.js +30 -17
- package/build-module/focusable.js.map +1 -1
- package/build-module/tabbable.js +2 -2
- package/build-module/tabbable.js.map +1 -1
- package/build-types/dom/caret-range-from-point.d.ts +2 -2
- package/build-types/dom/clean-node-list.d.ts +2 -2
- package/build-types/dom/document-has-text-selection.d.ts +1 -1
- package/build-types/dom/document-has-uncollapsed-selection.d.ts +2 -2
- package/build-types/dom/is-edge.d.ts.map +1 -1
- package/build-types/dom/place-caret-at-edge.d.ts +9 -0
- package/build-types/dom/place-caret-at-edge.d.ts.map +1 -0
- package/build-types/dom/place-caret-at-horizontal-edge.d.ts.map +1 -1
- package/build-types/dom/place-caret-at-vertical-edge.d.ts +4 -5
- package/build-types/dom/place-caret-at-vertical-edge.d.ts.map +1 -1
- package/build-types/dom/strip-html.d.ts.map +1 -1
- package/build-types/focusable.d.ts +11 -2
- package/build-types/focusable.d.ts.map +1 -1
- package/build-types/tabbable.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/dom/caret-range-from-point.js +2 -2
- package/src/dom/document-has-text-selection.js +1 -1
- package/src/dom/document-has-uncollapsed-selection.js +2 -2
- package/src/dom/is-edge.js +4 -1
- package/src/dom/place-caret-at-edge.js +95 -0
- package/src/dom/place-caret-at-horizontal-edge.js +2 -83
- package/src/dom/place-caret-at-vertical-edge.js +6 -64
- package/src/dom/strip-html.js +12 -5
- package/src/dom/test/strip-html.js +64 -0
- package/src/focusable.js +37 -32
- package/src/tabbable.js +2 -4
- package/src/test/dom.js +8 -15
- package/tsconfig.tsbuildinfo +1 -1
@@ -16,31 +16,33 @@
|
|
16
16
|
* AREA elements associated with an IMG:
|
17
17
|
* - https://w3c.github.io/html/editing.html#data-model
|
18
18
|
*/
|
19
|
-
|
19
|
+
|
20
20
|
/**
|
21
|
-
* Returns
|
22
|
-
* nor visibility: hidden).
|
21
|
+
* Returns a CSS selector used to query for focusable elements.
|
23
22
|
*
|
24
|
-
* @param {
|
23
|
+
* @param {boolean} sequential If set, only query elements that are sequentially
|
24
|
+
* focusable. Non-interactive elements with a
|
25
|
+
* negative `tabindex` are focusable but not
|
26
|
+
* sequentially focusable.
|
27
|
+
* https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute
|
25
28
|
*
|
26
|
-
* @return {
|
29
|
+
* @return {string} CSS selector.
|
27
30
|
*/
|
28
|
-
|
29
|
-
|
30
|
-
return element.offsetWidth > 0 || element.offsetHeight > 0 || element.getClientRects().length > 0;
|
31
|
+
function buildSelector(sequential) {
|
32
|
+
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(',');
|
31
33
|
}
|
32
34
|
/**
|
33
|
-
* Returns true if the specified element
|
34
|
-
*
|
35
|
+
* Returns true if the specified element is visible (i.e. neither display: none
|
36
|
+
* nor visibility: hidden).
|
35
37
|
*
|
36
|
-
* @param {
|
38
|
+
* @param {HTMLElement} element DOM element to test.
|
37
39
|
*
|
38
|
-
* @return {boolean} Whether element
|
40
|
+
* @return {boolean} Whether element is visible.
|
39
41
|
*/
|
40
42
|
|
41
43
|
|
42
|
-
function
|
43
|
-
return element.
|
44
|
+
function isVisible(element) {
|
45
|
+
return element.offsetWidth > 0 || element.offsetHeight > 0 || element.getClientRects().length > 0;
|
44
46
|
}
|
45
47
|
/**
|
46
48
|
* Returns true if the specified area element is a valid focusable element, or
|
@@ -69,21 +71,32 @@ function isValidFocusableArea(element) {
|
|
69
71
|
/**
|
70
72
|
* Returns all focusable elements within a given context.
|
71
73
|
*
|
72
|
-
* @param {Element} context
|
74
|
+
* @param {Element} context Element in which to search.
|
75
|
+
* @param {Object} [options]
|
76
|
+
* @param {boolean} [options.sequential] If set, only return elements that are
|
77
|
+
* sequentially focusable.
|
78
|
+
* Non-interactive elements with a
|
79
|
+
* negative `tabindex` are focusable but
|
80
|
+
* not sequentially focusable.
|
81
|
+
* https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute
|
73
82
|
*
|
74
83
|
* @return {Element[]} Focusable elements.
|
75
84
|
*/
|
76
85
|
|
77
86
|
|
78
87
|
export function find(context) {
|
88
|
+
let {
|
89
|
+
sequential = false
|
90
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
91
|
+
|
79
92
|
/* eslint-disable jsdoc/no-undefined-types */
|
80
93
|
|
81
94
|
/** @type {NodeListOf<HTMLElement>} */
|
82
95
|
|
83
96
|
/* eslint-enable jsdoc/no-undefined-types */
|
84
|
-
const elements = context.querySelectorAll(
|
97
|
+
const elements = context.querySelectorAll(buildSelector(sequential));
|
85
98
|
return Array.from(elements).filter(element => {
|
86
|
-
if (!isVisible(element)
|
99
|
+
if (!isVisible(element)) {
|
87
100
|
return false;
|
88
101
|
}
|
89
102
|
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["@wordpress/dom/src/focusable.js"],"names":["
|
1
|
+
{"version":3,"sources":["@wordpress/dom/src/focusable.js"],"names":["buildSelector","sequential","join","isVisible","element","offsetWidth","offsetHeight","getClientRects","length","isValidFocusableArea","map","closest","img","ownerDocument","querySelector","name","find","context","elements","querySelectorAll","Array","from","filter","nodeName"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,aAAT,CAAwBC,UAAxB,EAAqC;AACpC,SAAO,CACNA,UAAU,GAAG,iCAAH,GAAuC,YAD3C,EAEN,SAFM,EAGN,wBAHM,EAIN,4CAJM,EAKN,wBALM,EAMN,0BANM,EAON,6BAPM,EAQN,QARM,EASN,OATM,EAUN,YAVM,EAWN,gDAXM,EAYLC,IAZK,CAYC,GAZD,CAAP;AAaA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASC,SAAT,CAAoBC,OAApB,EAA8B;AAC7B,SACCA,OAAO,CAACC,WAAR,GAAsB,CAAtB,IACAD,OAAO,CAACE,YAAR,GAAuB,CADvB,IAEAF,OAAO,CAACG,cAAR,GAAyBC,MAAzB,GAAkC,CAHnC;AAKA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASC,oBAAT,CAA+BL,OAA/B,EAAyC;AACxC;AACA,QAAMM,GAAG,GAAGN,OAAO,CAACO,OAAR,CAAiB,WAAjB,CAAZ;;AACA,MAAK,CAAED,GAAP,EAAa;AACZ,WAAO,KAAP;AACA;AAED;;;AACA,QAAME,GAAG,GAAGR,OAAO,CAACS,aAAR,CAAsBC,aAAtB,CACX,kBAAkBJ,GAAG,CAACK,IAAtB,GAA6B,IADlB,CAAZ;AAGA,SAAO,CAAC,CAAEH,GAAH,IAAUT,SAAS,CAAES,GAAF,CAA1B;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,OAAO,SAASI,IAAT,CAAeC,OAAf,EAAsD;AAAA,MAA9B;AAAEhB,IAAAA,UAAU,GAAG;AAAf,GAA8B,uEAAL,EAAK;;AAC5D;;AACA;;AACA;AACA,QAAMiB,QAAQ,GAAGD,OAAO,CAACE,gBAAR,CAA0BnB,aAAa,CAAEC,UAAF,CAAvC,CAAjB;AAEA,SAAOmB,KAAK,CAACC,IAAN,CAAYH,QAAZ,EAAuBI,MAAvB,CAAiClB,OAAF,IAAe;AACpD,QAAK,CAAED,SAAS,CAAEC,OAAF,CAAhB,EAA8B;AAC7B,aAAO,KAAP;AACA;;AAED,UAAM;AAAEmB,MAAAA;AAAF,QAAenB,OAArB;;AACA,QAAK,WAAWmB,QAAhB,EAA2B;AAC1B,aAAOd,oBAAoB;AAC1B;AAAiCL,MAAAA,OADP,CAA3B;AAGA;;AAED,WAAO,IAAP;AACA,GAbM,CAAP;AAcA","sourcesContent":["/**\n * References:\n *\n * Focusable:\n * - https://www.w3.org/TR/html5/editing.html#focus-management\n *\n * Sequential focus navigation:\n * - https://www.w3.org/TR/html5/editing.html#sequential-focus-navigation-and-the-tabindex-attribute\n *\n * Disabled elements:\n * - https://www.w3.org/TR/html5/disabled-elements.html#disabled-elements\n *\n * getClientRects algorithm (requiring layout box):\n * - https://www.w3.org/TR/cssom-view-1/#extension-to-the-element-interface\n *\n * AREA elements associated with an IMG:\n * - https://w3c.github.io/html/editing.html#data-model\n */\n\n/**\n * Returns a CSS selector used to query for focusable elements.\n *\n * @param {boolean} sequential If set, only query elements that are sequentially\n * focusable. Non-interactive elements with a\n * negative `tabindex` are focusable but not\n * sequentially focusable.\n * https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute\n *\n * @return {string} CSS selector.\n */\nfunction buildSelector( sequential ) {\n\treturn [\n\t\tsequential ? '[tabindex]:not([tabindex^=\"-\"])' : '[tabindex]',\n\t\t'a[href]',\n\t\t'button:not([disabled])',\n\t\t'input:not([type=\"hidden\"]):not([disabled])',\n\t\t'select:not([disabled])',\n\t\t'textarea:not([disabled])',\n\t\t'iframe:not([tabindex^=\"-\"])',\n\t\t'object',\n\t\t'embed',\n\t\t'area[href]',\n\t\t'[contenteditable]:not([contenteditable=false])',\n\t].join( ',' );\n}\n\n/**\n * Returns true if the specified element is visible (i.e. neither display: none\n * nor visibility: hidden).\n *\n * @param {HTMLElement} element DOM element to test.\n *\n * @return {boolean} Whether element is visible.\n */\nfunction isVisible( element ) {\n\treturn (\n\t\telement.offsetWidth > 0 ||\n\t\telement.offsetHeight > 0 ||\n\t\telement.getClientRects().length > 0\n\t);\n}\n\n/**\n * Returns true if the specified area element is a valid focusable element, or\n * false otherwise. Area is only focusable if within a map where a named map\n * referenced by an image somewhere in the document.\n *\n * @param {HTMLAreaElement} element DOM area element to test.\n *\n * @return {boolean} Whether area element is valid for focus.\n */\nfunction isValidFocusableArea( element ) {\n\t/** @type {HTMLMapElement | null} */\n\tconst map = element.closest( 'map[name]' );\n\tif ( ! map ) {\n\t\treturn false;\n\t}\n\n\t/** @type {HTMLImageElement | null} */\n\tconst img = element.ownerDocument.querySelector(\n\t\t'img[usemap=\"#' + map.name + '\"]'\n\t);\n\treturn !! img && isVisible( img );\n}\n\n/**\n * Returns all focusable elements within a given context.\n *\n * @param {Element} context Element in which to search.\n * @param {Object} [options]\n * @param {boolean} [options.sequential] If set, only return elements that are\n * sequentially focusable.\n * Non-interactive elements with a\n * negative `tabindex` are focusable but\n * not sequentially focusable.\n * https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute\n *\n * @return {Element[]} Focusable elements.\n */\nexport function find( context, { sequential = false } = {} ) {\n\t/* eslint-disable jsdoc/no-undefined-types */\n\t/** @type {NodeListOf<HTMLElement>} */\n\t/* eslint-enable jsdoc/no-undefined-types */\n\tconst elements = context.querySelectorAll( buildSelector( sequential ) );\n\n\treturn Array.from( elements ).filter( ( element ) => {\n\t\tif ( ! isVisible( element ) ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst { nodeName } = element;\n\t\tif ( 'AREA' === nodeName ) {\n\t\t\treturn isValidFocusableArea(\n\t\t\t\t/** @type {HTMLAreaElement} */ ( element )\n\t\t\t);\n\t\t}\n\n\t\treturn true;\n\t} );\n}\n"]}
|
package/build-module/tabbable.js
CHANGED
@@ -184,9 +184,9 @@ export function findPrevious(element) {
|
|
184
184
|
|
185
185
|
export function findNext(element) {
|
186
186
|
const focusables = findFocusable(element.ownerDocument.body);
|
187
|
-
const index = focusables.indexOf(element); // Remove all focusables before and
|
187
|
+
const index = focusables.indexOf(element); // Remove all focusables before and including `element`.
|
188
188
|
|
189
|
-
const remaining = focusables.slice(index + 1)
|
189
|
+
const remaining = focusables.slice(index + 1);
|
190
190
|
return first(filterTabbable(remaining));
|
191
191
|
}
|
192
192
|
//# sourceMappingURL=tabbable.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["@wordpress/dom/src/tabbable.js"],"names":["without","first","last","find","findFocusable","getTabIndex","element","tabIndex","getAttribute","parseInt","isTabbableIndex","createStatefulCollapseRadioGroup","CHOSEN_RADIO_BY_NAME","collapseRadioGroup","result","nodeName","type","checked","name","concat","hasChosen","hasOwnProperty","isChosen","hadChosenElement","mapElementToObjectTabbable","index","mapObjectTabbableToElement","object","compareObjectTabbables","a","b","aTabIndex","bTabIndex","filterTabbable","focusables","filter","map","sort","reduce","context","findPrevious","ownerDocument","body","indexOf","length","findNext","remaining","slice"
|
1
|
+
{"version":3,"sources":["@wordpress/dom/src/tabbable.js"],"names":["without","first","last","find","findFocusable","getTabIndex","element","tabIndex","getAttribute","parseInt","isTabbableIndex","createStatefulCollapseRadioGroup","CHOSEN_RADIO_BY_NAME","collapseRadioGroup","result","nodeName","type","checked","name","concat","hasChosen","hasOwnProperty","isChosen","hadChosenElement","mapElementToObjectTabbable","index","mapObjectTabbableToElement","object","compareObjectTabbables","a","b","aTabIndex","bTabIndex","filterTabbable","focusables","filter","map","sort","reduce","context","findPrevious","ownerDocument","body","indexOf","length","findNext","remaining","slice"],"mappings":"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","sourcesContent":["/**\n * External dependencies\n */\nimport { without, first, last } from 'lodash';\n\n/**\n * Internal dependencies\n */\nimport { find as findFocusable } from './focusable';\n\n/**\n * Returns the tab index of the given element. In contrast with the tabIndex\n * property, this normalizes the default (0) to avoid browser inconsistencies,\n * operating under the assumption that this function is only ever called with a\n * focusable node.\n *\n * @see https://bugzilla.mozilla.org/show_bug.cgi?id=1190261\n *\n * @param {Element} element Element from which to retrieve.\n *\n * @return {number} Tab index of element (default 0).\n */\nfunction getTabIndex( element ) {\n\tconst tabIndex = element.getAttribute( 'tabindex' );\n\treturn tabIndex === null ? 0 : parseInt( tabIndex, 10 );\n}\n\n/**\n * Returns true if the specified element is tabbable, or false otherwise.\n *\n * @param {Element} element Element to test.\n *\n * @return {boolean} Whether element is tabbable.\n */\nexport function isTabbableIndex( element ) {\n\treturn getTabIndex( element ) !== -1;\n}\n\n/** @typedef {Element & { type?: string, checked?: boolean, name?: string }} MaybeHTMLInputElement */\n\n/**\n * Returns a stateful reducer function which constructs a filtered array of\n * tabbable elements, where at most one radio input is selected for a given\n * name, giving priority to checked input, falling back to the first\n * encountered.\n *\n * @return {(acc: MaybeHTMLInputElement[], el: MaybeHTMLInputElement) => MaybeHTMLInputElement[]} Radio group collapse reducer.\n */\nfunction createStatefulCollapseRadioGroup() {\n\t/** @type {Record<string, MaybeHTMLInputElement>} */\n\tconst CHOSEN_RADIO_BY_NAME = {};\n\n\treturn function collapseRadioGroup(\n\t\t/** @type {MaybeHTMLInputElement[]} */ result,\n\t\t/** @type {MaybeHTMLInputElement} */ element\n\t) {\n\t\tconst { nodeName, type, checked, name } = element;\n\n\t\t// For all non-radio tabbables, construct to array by concatenating.\n\t\tif ( nodeName !== 'INPUT' || type !== 'radio' || ! name ) {\n\t\t\treturn result.concat( element );\n\t\t}\n\n\t\tconst hasChosen = CHOSEN_RADIO_BY_NAME.hasOwnProperty( name );\n\n\t\t// Omit by skipping concatenation if the radio element is not chosen.\n\t\tconst isChosen = checked || ! hasChosen;\n\t\tif ( ! isChosen ) {\n\t\t\treturn result;\n\t\t}\n\n\t\t// At this point, if there had been a chosen element, the current\n\t\t// element is checked and should take priority. Retroactively remove\n\t\t// the element which had previously been considered the chosen one.\n\t\tif ( hasChosen ) {\n\t\t\tconst hadChosenElement = CHOSEN_RADIO_BY_NAME[ name ];\n\t\t\tresult = without( result, hadChosenElement );\n\t\t}\n\n\t\tCHOSEN_RADIO_BY_NAME[ name ] = element;\n\n\t\treturn result.concat( element );\n\t};\n}\n\n/**\n * An array map callback, returning an object with the element value and its\n * array index location as properties. This is used to emulate a proper stable\n * sort where equal tabIndex should be left in order of their occurrence in the\n * document.\n *\n * @param {Element} element Element.\n * @param {number} index Array index of element.\n *\n * @return {{ element: Element, index: number }} Mapped object with element, index.\n */\nfunction mapElementToObjectTabbable( element, index ) {\n\treturn { element, index };\n}\n\n/**\n * An array map callback, returning an element of the given mapped object's\n * element value.\n *\n * @param {{ element: Element }} object Mapped object with element.\n *\n * @return {Element} Mapped object element.\n */\nfunction mapObjectTabbableToElement( object ) {\n\treturn object.element;\n}\n\n/**\n * A sort comparator function used in comparing two objects of mapped elements.\n *\n * @see mapElementToObjectTabbable\n *\n * @param {{ element: Element, index: number }} a First object to compare.\n * @param {{ element: Element, index: number }} b Second object to compare.\n *\n * @return {number} Comparator result.\n */\nfunction compareObjectTabbables( a, b ) {\n\tconst aTabIndex = getTabIndex( a.element );\n\tconst bTabIndex = getTabIndex( b.element );\n\n\tif ( aTabIndex === bTabIndex ) {\n\t\treturn a.index - b.index;\n\t}\n\n\treturn aTabIndex - bTabIndex;\n}\n\n/**\n * Givin focusable elements, filters out tabbable element.\n *\n * @param {Element[]} focusables Focusable elements to filter.\n *\n * @return {Element[]} Tabbable elements.\n */\nfunction filterTabbable( focusables ) {\n\treturn focusables\n\t\t.filter( isTabbableIndex )\n\t\t.map( mapElementToObjectTabbable )\n\t\t.sort( compareObjectTabbables )\n\t\t.map( mapObjectTabbableToElement )\n\t\t.reduce( createStatefulCollapseRadioGroup(), [] );\n}\n\n/**\n * @param {Element} context\n * @return {Element[]} Tabbable elements within the context.\n */\nexport function find( context ) {\n\treturn filterTabbable( findFocusable( context ) );\n}\n\n/**\n * Given a focusable element, find the preceding tabbable element.\n *\n * @param {Element} element The focusable element before which to look. Defaults\n * to the active element.\n */\nexport function findPrevious( element ) {\n\tconst focusables = findFocusable( element.ownerDocument.body );\n\tconst index = focusables.indexOf( element );\n\n\t// Remove all focusables after and including `element`.\n\tfocusables.length = index;\n\n\treturn last( filterTabbable( focusables ) );\n}\n\n/**\n * Given a focusable element, find the next tabbable element.\n *\n * @param {Element} element The focusable element after which to look. Defaults\n * to the active element.\n */\nexport function findNext( element ) {\n\tconst focusables = findFocusable( element.ownerDocument.body );\n\tconst index = focusables.indexOf( element );\n\n\t// Remove all focusables before and including `element`.\n\tconst remaining = focusables.slice( index + 1 );\n\n\treturn first( filterTabbable( remaining ) );\n}\n"]}
|
@@ -5,8 +5,8 @@
|
|
5
5
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/Document/caretRangeFromPoint
|
6
6
|
*
|
7
7
|
* @param {DocumentMaybeWithCaretPositionFromPoint} doc The document of the range.
|
8
|
-
* @param {number}
|
9
|
-
* @param {number}
|
8
|
+
* @param {number} x Horizontal position within the current viewport.
|
9
|
+
* @param {number} y Vertical position within the current viewport.
|
10
10
|
*
|
11
11
|
* @return {Range | null} The best range for the given point.
|
12
12
|
*/
|
@@ -30,9 +30,9 @@ export type SchemaItem = {
|
|
30
30
|
/**
|
31
31
|
* Child schemas.
|
32
32
|
*/
|
33
|
-
children?: {
|
33
|
+
children?: "*" | {
|
34
34
|
[tag: string]: SchemaItem;
|
35
|
-
} |
|
35
|
+
} | undefined;
|
36
36
|
/**
|
37
37
|
* Selectors to test required children against. Leave empty or undefined if there are no requirements.
|
38
38
|
*/
|
@@ -1,6 +1,6 @@
|
|
1
1
|
/**
|
2
2
|
* Check whether the current document has selected text. This applies to ranges
|
3
|
-
* of text in the document, and not selection inside
|
3
|
+
* of text in the document, and not selection inside `<input>` and `<textarea>`
|
4
4
|
* elements.
|
5
5
|
*
|
6
6
|
* See: https://developer.mozilla.org/en-US/docs/Web/API/Window/getSelection#Related_objects.
|
@@ -1,7 +1,7 @@
|
|
1
1
|
/**
|
2
2
|
* Check whether the current document has any sort of selection. This includes
|
3
|
-
* ranges of text across elements and any selection inside
|
4
|
-
*
|
3
|
+
* ranges of text across elements and any selection inside `<input>` and
|
4
|
+
* `<textarea>` elements.
|
5
5
|
*
|
6
6
|
* @param {Document} doc The document to check.
|
7
7
|
*
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"is-edge.d.ts","sourceRoot":"","sources":["../../src/dom/is-edge.js"],"names":[],"mappings":"AAWA;;;;;;;;;;GAUG;AACH,0CANW,OAAO,aACP,OAAO,uCAGN,OAAO,
|
1
|
+
{"version":3,"file":"is-edge.d.ts","sourceRoot":"","sources":["../../src/dom/is-edge.js"],"names":[],"mappings":"AAWA;;;;;;;;;;GAUG;AACH,0CANW,OAAO,aACP,OAAO,uCAGN,OAAO,CA4GlB"}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
/**
|
2
|
+
* Places the caret at start or end of a given element.
|
3
|
+
*
|
4
|
+
* @param {HTMLElement} container Focusable element.
|
5
|
+
* @param {boolean} isReverse True for end, false for start.
|
6
|
+
* @param {number|undefined} x X coordinate to vertically position.
|
7
|
+
*/
|
8
|
+
export default function placeCaretAtEdge(container: HTMLElement, isReverse: boolean, x: number | undefined): void;
|
9
|
+
//# sourceMappingURL=place-caret-at-edge.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"place-caret-at-edge.d.ts","sourceRoot":"","sources":["../../src/dom/place-caret-at-edge.js"],"names":[],"mappings":"AA+BA;;;;;;GAMG;AACH,oDAJW,WAAW,aACX,OAAO,KACP,MAAM,GAAC,SAAS,QA0D1B"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"place-caret-at-horizontal-edge.d.ts","sourceRoot":"","sources":["../../src/dom/place-caret-at-horizontal-edge.js"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"place-caret-at-horizontal-edge.d.ts","sourceRoot":"","sources":["../../src/dom/place-caret-at-horizontal-edge.js"],"names":[],"mappings":"AAKA;;;;;GAKG;AACH,8DAHW,WAAW,aACX,OAAO,QAIjB"}
|
@@ -1,10 +1,9 @@
|
|
1
1
|
/**
|
2
2
|
* Places the caret at the top or bottom of a given element.
|
3
3
|
*
|
4
|
-
* @param {HTMLElement} container
|
5
|
-
* @param {boolean} isReverse
|
6
|
-
* @param {DOMRect} [rect]
|
7
|
-
* @param {boolean} [mayUseScroll=true] True to allow scrolling, false to disallow.
|
4
|
+
* @param {HTMLElement} container Focusable element.
|
5
|
+
* @param {boolean} isReverse True for bottom, false for top.
|
6
|
+
* @param {DOMRect} [rect] The rectangle to position the caret with.
|
8
7
|
*/
|
9
|
-
export default function placeCaretAtVerticalEdge(container: HTMLElement, isReverse: boolean, rect?: DOMRect | undefined
|
8
|
+
export default function placeCaretAtVerticalEdge(container: HTMLElement, isReverse: boolean, rect?: DOMRect | undefined): void;
|
10
9
|
//# sourceMappingURL=place-caret-at-vertical-edge.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"place-caret-at-vertical-edge.d.ts","sourceRoot":"","sources":["../../src/dom/place-caret-at-vertical-edge.js"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"place-caret-at-vertical-edge.d.ts","sourceRoot":"","sources":["../../src/dom/place-caret-at-vertical-edge.js"],"names":[],"mappings":"AAKA;;;;;;GAMG;AACH,4DAJW,WAAW,aACX,OAAO,oCAKjB"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"strip-html.d.ts","sourceRoot":"","sources":["../../src/dom/strip-html.js"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"strip-html.d.ts","sourceRoot":"","sources":["../../src/dom/strip-html.js"],"names":[],"mappings":"AAKA;;;;;;GAMG;AACH,wCAJW,MAAM,GAEL,MAAM,CAUjB"}
|
@@ -1,9 +1,18 @@
|
|
1
1
|
/**
|
2
2
|
* Returns all focusable elements within a given context.
|
3
3
|
*
|
4
|
-
* @param {Element} context
|
4
|
+
* @param {Element} context Element in which to search.
|
5
|
+
* @param {Object} [options]
|
6
|
+
* @param {boolean} [options.sequential] If set, only return elements that are
|
7
|
+
* sequentially focusable.
|
8
|
+
* Non-interactive elements with a
|
9
|
+
* negative `tabindex` are focusable but
|
10
|
+
* not sequentially focusable.
|
11
|
+
* https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute
|
5
12
|
*
|
6
13
|
* @return {Element[]} Focusable elements.
|
7
14
|
*/
|
8
|
-
export function find(context: Element
|
15
|
+
export function find(context: Element, { sequential }?: {
|
16
|
+
sequential?: boolean | undefined;
|
17
|
+
} | undefined): Element[];
|
9
18
|
//# sourceMappingURL=focusable.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"focusable.d.ts","sourceRoot":"","sources":["../src/focusable.js"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"focusable.d.ts","sourceRoot":"","sources":["../src/focusable.js"],"names":[],"mappings":"AAqFA;;;;;;;;;;;;;GAaG;AACH,8BAXW,OAAO;;gBASN,OAAO,EAAE,CAsBpB"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"tabbable.d.ts","sourceRoot":"","sources":["../src/tabbable.js"],"names":[],"mappings":"AA2BA;;;;;;GAMG;AACH,yCAJW,OAAO,GAEN,OAAO,CAIlB;AAiHD;;;GAGG;AACH,8BAHW,OAAO,GACN,OAAO,EAAE,CAIpB;AAED;;;;;GAKG;AACH,sCAHW,OAAO,uBAWjB;AAED;;;;;GAKG;AACH,kCAHW,OAAO,
|
1
|
+
{"version":3,"file":"tabbable.d.ts","sourceRoot":"","sources":["../src/tabbable.js"],"names":[],"mappings":"AA2BA;;;;;;GAMG;AACH,yCAJW,OAAO,GAEN,OAAO,CAIlB;AAiHD;;;GAGG;AACH,8BAHW,OAAO,GACN,OAAO,EAAE,CAIpB;AAED;;;;;GAKG;AACH,sCAHW,OAAO,uBAWjB;AAED;;;;;GAKG;AACH,kCAHW,OAAO,uBAWjB;oCArJa,OAAO,GAAG;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@wordpress/dom",
|
3
|
-
"version": "3.2.
|
3
|
+
"version": "3.2.7",
|
4
4
|
"description": "DOM utilities module for WordPress.",
|
5
5
|
"author": "The WordPress Contributors",
|
6
6
|
"license": "GPL-2.0-or-later",
|
@@ -28,11 +28,11 @@
|
|
28
28
|
"types": "build-types",
|
29
29
|
"sideEffects": false,
|
30
30
|
"dependencies": {
|
31
|
-
"@babel/runtime": "^7.
|
31
|
+
"@babel/runtime": "^7.16.0",
|
32
32
|
"lodash": "^4.17.21"
|
33
33
|
},
|
34
34
|
"publishConfig": {
|
35
35
|
"access": "public"
|
36
36
|
},
|
37
|
-
"gitHead": "
|
37
|
+
"gitHead": "9a1dd3474d937468e4cf9caf9886ad61ef0a8f50"
|
38
38
|
}
|
@@ -5,8 +5,8 @@
|
|
5
5
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/Document/caretRangeFromPoint
|
6
6
|
*
|
7
7
|
* @param {DocumentMaybeWithCaretPositionFromPoint} doc The document of the range.
|
8
|
-
* @param {number}
|
9
|
-
* @param {number}
|
8
|
+
* @param {number} x Horizontal position within the current viewport.
|
9
|
+
* @param {number} y Vertical position within the current viewport.
|
10
10
|
*
|
11
11
|
* @return {Range | null} The best range for the given point.
|
12
12
|
*/
|
@@ -5,7 +5,7 @@ import { assertIsDefined } from '../utils/assert-is-defined';
|
|
5
5
|
|
6
6
|
/**
|
7
7
|
* Check whether the current document has selected text. This applies to ranges
|
8
|
-
* of text in the document, and not selection inside
|
8
|
+
* of text in the document, and not selection inside `<input>` and `<textarea>`
|
9
9
|
* elements.
|
10
10
|
*
|
11
11
|
* See: https://developer.mozilla.org/en-US/docs/Web/API/Window/getSelection#Related_objects.
|
@@ -6,8 +6,8 @@ import inputFieldHasUncollapsedSelection from './input-field-has-uncollapsed-sel
|
|
6
6
|
|
7
7
|
/**
|
8
8
|
* Check whether the current document has any sort of selection. This includes
|
9
|
-
* ranges of text across elements and any selection inside
|
10
|
-
*
|
9
|
+
* ranges of text across elements and any selection inside `<input>` and
|
10
|
+
* `<textarea>` elements.
|
11
11
|
*
|
12
12
|
* @param {Document} doc The document to check.
|
13
13
|
*
|
package/src/dom/is-edge.js
CHANGED
@@ -21,7 +21,10 @@ import isInputOrTextArea from './is-input-or-text-area';
|
|
21
21
|
* @return {boolean} True if at the edge, false if not.
|
22
22
|
*/
|
23
23
|
export default function isEdge( container, isReverse, onlyVertical = false ) {
|
24
|
-
if (
|
24
|
+
if (
|
25
|
+
isInputOrTextArea( container ) &&
|
26
|
+
typeof container.selectionStart === 'number'
|
27
|
+
) {
|
25
28
|
if ( container.selectionStart !== container.selectionEnd ) {
|
26
29
|
return false;
|
27
30
|
}
|
@@ -0,0 +1,95 @@
|
|
1
|
+
/**
|
2
|
+
* Internal dependencies
|
3
|
+
*/
|
4
|
+
import hiddenCaretRangeFromPoint from './hidden-caret-range-from-point';
|
5
|
+
import { assertIsDefined } from '../utils/assert-is-defined';
|
6
|
+
import isInputOrTextArea from './is-input-or-text-area';
|
7
|
+
import isRTL from './is-rtl';
|
8
|
+
|
9
|
+
/**
|
10
|
+
* Gets the range to place.
|
11
|
+
*
|
12
|
+
* @param {HTMLElement} container Focusable element.
|
13
|
+
* @param {boolean} isReverse True for end, false for start.
|
14
|
+
* @param {number|undefined} x X coordinate to vertically position.
|
15
|
+
*
|
16
|
+
* @return {Range|null} The range to place.
|
17
|
+
*/
|
18
|
+
function getRange( container, isReverse, x ) {
|
19
|
+
const { ownerDocument } = container;
|
20
|
+
// In the case of RTL scripts, the horizontal edge is at the opposite side.
|
21
|
+
const isReverseDir = isRTL( container ) ? ! isReverse : isReverse;
|
22
|
+
const containerRect = container.getBoundingClientRect();
|
23
|
+
// When placing at the end (isReverse), find the closest range to the bottom
|
24
|
+
// right corner. When placing at the start, to the top left corner.
|
25
|
+
if ( x === undefined ) {
|
26
|
+
x = isReverse ? containerRect.right - 1 : containerRect.left + 1;
|
27
|
+
}
|
28
|
+
const y = isReverseDir ? containerRect.bottom - 1 : containerRect.top + 1;
|
29
|
+
return hiddenCaretRangeFromPoint( ownerDocument, x, y, container );
|
30
|
+
}
|
31
|
+
|
32
|
+
/**
|
33
|
+
* Places the caret at start or end of a given element.
|
34
|
+
*
|
35
|
+
* @param {HTMLElement} container Focusable element.
|
36
|
+
* @param {boolean} isReverse True for end, false for start.
|
37
|
+
* @param {number|undefined} x X coordinate to vertically position.
|
38
|
+
*/
|
39
|
+
export default function placeCaretAtEdge( container, isReverse, x ) {
|
40
|
+
if ( ! container ) {
|
41
|
+
return;
|
42
|
+
}
|
43
|
+
|
44
|
+
container.focus();
|
45
|
+
|
46
|
+
if ( isInputOrTextArea( container ) ) {
|
47
|
+
// The element may not support selection setting.
|
48
|
+
if ( typeof container.selectionStart !== 'number' ) {
|
49
|
+
return;
|
50
|
+
}
|
51
|
+
|
52
|
+
if ( isReverse ) {
|
53
|
+
container.selectionStart = container.value.length;
|
54
|
+
container.selectionEnd = container.value.length;
|
55
|
+
} else {
|
56
|
+
container.selectionStart = 0;
|
57
|
+
container.selectionEnd = 0;
|
58
|
+
}
|
59
|
+
|
60
|
+
return;
|
61
|
+
}
|
62
|
+
|
63
|
+
if ( ! container.isContentEditable ) {
|
64
|
+
return;
|
65
|
+
}
|
66
|
+
|
67
|
+
let range = getRange( container, isReverse, x );
|
68
|
+
|
69
|
+
// If no range range can be created or it is outside the container, the
|
70
|
+
// element may be out of view.
|
71
|
+
if (
|
72
|
+
! range ||
|
73
|
+
! range.startContainer ||
|
74
|
+
! container.contains( range.startContainer )
|
75
|
+
) {
|
76
|
+
container.scrollIntoView( isReverse );
|
77
|
+
range = range = getRange( container, isReverse, x );
|
78
|
+
|
79
|
+
if (
|
80
|
+
! range ||
|
81
|
+
! range.startContainer ||
|
82
|
+
! container.contains( range.startContainer )
|
83
|
+
) {
|
84
|
+
return;
|
85
|
+
}
|
86
|
+
}
|
87
|
+
|
88
|
+
const { ownerDocument } = container;
|
89
|
+
const { defaultView } = ownerDocument;
|
90
|
+
assertIsDefined( defaultView, 'defaultView' );
|
91
|
+
const selection = defaultView.getSelection();
|
92
|
+
assertIsDefined( selection, 'selection' );
|
93
|
+
selection.removeAllRanges();
|
94
|
+
selection.addRange( range );
|
95
|
+
}
|
@@ -1,34 +1,7 @@
|
|
1
1
|
/**
|
2
2
|
* Internal dependencies
|
3
3
|
*/
|
4
|
-
import
|
5
|
-
|
6
|
-
/**
|
7
|
-
* Internal dependencies
|
8
|
-
*/
|
9
|
-
import hiddenCaretRangeFromPoint from './hidden-caret-range-from-point';
|
10
|
-
import isInputOrTextArea from './is-input-or-text-area';
|
11
|
-
import isRTL from './is-rtl';
|
12
|
-
|
13
|
-
/**
|
14
|
-
* Gets the range to place.
|
15
|
-
*
|
16
|
-
* @param {HTMLElement} container Focusable element.
|
17
|
-
* @param {boolean} isReverse True for end, false for start.
|
18
|
-
*
|
19
|
-
* @return {Range|null} The range to place.
|
20
|
-
*/
|
21
|
-
function getRange( container, isReverse ) {
|
22
|
-
const { ownerDocument } = container;
|
23
|
-
// In the case of RTL scripts, the horizontal edge is at the opposite side.
|
24
|
-
const isReverseDir = isRTL( container ) ? ! isReverse : isReverse;
|
25
|
-
const containerRect = container.getBoundingClientRect();
|
26
|
-
// When placing at the end (isReverse), find the closest range to the bottom
|
27
|
-
// right corner. When placing at the start, to the top left corner.
|
28
|
-
const x = isReverse ? containerRect.right - 1 : containerRect.left + 1;
|
29
|
-
const y = isReverseDir ? containerRect.bottom - 1 : containerRect.top + 1;
|
30
|
-
return hiddenCaretRangeFromPoint( ownerDocument, x, y, container );
|
31
|
-
}
|
4
|
+
import placeCaretAtEdge from './place-caret-at-edge';
|
32
5
|
|
33
6
|
/**
|
34
7
|
* Places the caret at start or end of a given element.
|
@@ -37,59 +10,5 @@ function getRange( container, isReverse ) {
|
|
37
10
|
* @param {boolean} isReverse True for end, false for start.
|
38
11
|
*/
|
39
12
|
export default function placeCaretAtHorizontalEdge( container, isReverse ) {
|
40
|
-
|
41
|
-
return;
|
42
|
-
}
|
43
|
-
|
44
|
-
container.focus();
|
45
|
-
|
46
|
-
if ( isInputOrTextArea( container ) ) {
|
47
|
-
// The element may not support selection setting.
|
48
|
-
if ( typeof container.selectionStart !== 'number' ) {
|
49
|
-
return;
|
50
|
-
}
|
51
|
-
|
52
|
-
if ( isReverse ) {
|
53
|
-
container.selectionStart = container.value.length;
|
54
|
-
container.selectionEnd = container.value.length;
|
55
|
-
} else {
|
56
|
-
container.selectionStart = 0;
|
57
|
-
container.selectionEnd = 0;
|
58
|
-
}
|
59
|
-
|
60
|
-
return;
|
61
|
-
}
|
62
|
-
|
63
|
-
if ( ! container.isContentEditable ) {
|
64
|
-
return;
|
65
|
-
}
|
66
|
-
|
67
|
-
let range = getRange( container, isReverse );
|
68
|
-
|
69
|
-
// If no range range can be created or it is outside the container, the
|
70
|
-
// element may be out of view.
|
71
|
-
if (
|
72
|
-
! range ||
|
73
|
-
! range.startContainer ||
|
74
|
-
! container.contains( range.startContainer )
|
75
|
-
) {
|
76
|
-
container.scrollIntoView( isReverse );
|
77
|
-
range = getRange( container, isReverse );
|
78
|
-
|
79
|
-
if (
|
80
|
-
! range ||
|
81
|
-
! range.startContainer ||
|
82
|
-
! container.contains( range.startContainer )
|
83
|
-
) {
|
84
|
-
return;
|
85
|
-
}
|
86
|
-
}
|
87
|
-
|
88
|
-
const { ownerDocument } = container;
|
89
|
-
const { defaultView } = ownerDocument;
|
90
|
-
assertIsDefined( defaultView, 'defaultView' );
|
91
|
-
const selection = defaultView.getSelection();
|
92
|
-
assertIsDefined( selection, 'selection' );
|
93
|
-
selection.removeAllRanges();
|
94
|
-
selection.addRange( range );
|
13
|
+
return placeCaretAtEdge( container, isReverse, undefined );
|
95
14
|
}
|