@wordpress/dom 4.32.0 → 4.32.1-next.b8c8708f3.0
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/build/data-transfer.js +30 -18
- package/build/data-transfer.js.map +7 -1
- package/build/dom/caret-range-from-point.js +22 -25
- package/build/dom/caret-range-from-point.js.map +7 -1
- package/build/dom/clean-node-list.js +122 -129
- package/build/dom/clean-node-list.js.map +7 -1
- package/build/dom/compute-caret-rect.js +36 -21
- package/build/dom/compute-caret-rect.js.map +7 -1
- package/build/dom/document-has-selection.js +36 -22
- package/build/dom/document-has-selection.js.map +7 -1
- package/build/dom/document-has-text-selection.js +25 -23
- package/build/dom/document-has-text-selection.js.map +7 -1
- package/build/dom/document-has-uncollapsed-selection.js +35 -22
- package/build/dom/document-has-uncollapsed-selection.js.map +7 -1
- package/build/dom/get-computed-style.js +27 -17
- package/build/dom/get-computed-style.js.map +7 -1
- package/build/dom/get-offset-parent.js +43 -32
- package/build/dom/get-offset-parent.js.map +7 -1
- package/build/dom/get-range-height.js +24 -18
- package/build/dom/get-range-height.js.map +7 -1
- package/build/dom/get-rectangle-from-range.js +47 -68
- package/build/dom/get-rectangle-from-range.js.map +7 -1
- package/build/dom/get-scroll-container.js +44 -37
- package/build/dom/get-scroll-container.js.map +7 -1
- package/build/dom/hidden-caret-range-from-point.js +39 -33
- package/build/dom/hidden-caret-range-from-point.js.map +7 -1
- package/build/dom/index.js +116 -195
- package/build/dom/index.js.map +7 -1
- package/build/dom/input-field-has-uncollapsed-selection.js +40 -42
- package/build/dom/input-field-has-uncollapsed-selection.js.map +7 -1
- package/build/dom/insert-after.js +24 -19
- package/build/dom/insert-after.js.map +7 -1
- package/build/dom/is-edge.js +57 -67
- package/build/dom/is-edge.js.map +7 -1
- package/build/dom/is-element.js +22 -11
- package/build/dom/is-element.js.map +7 -1
- package/build/dom/is-empty.js +27 -17
- package/build/dom/is-empty.js.map +7 -1
- package/build/dom/is-entirely-selected.js +46 -50
- package/build/dom/is-entirely-selected.js.map +7 -1
- package/build/dom/is-form-element.js +36 -24
- package/build/dom/is-form-element.js.map +7 -1
- package/build/dom/is-horizontal-edge.js +34 -20
- package/build/dom/is-horizontal-edge.js.map +7 -1
- package/build/dom/is-html-input-element.js +23 -12
- package/build/dom/is-html-input-element.js.map +7 -1
- package/build/dom/is-input-or-text-area.js +23 -12
- package/build/dom/is-input-or-text-area.js.map +7 -1
- package/build/dom/is-number-input.js +38 -29
- package/build/dom/is-number-input.js.map +7 -1
- package/build/dom/is-rtl.js +34 -19
- package/build/dom/is-rtl.js.map +7 -1
- package/build/dom/is-selection-forward.js +26 -40
- package/build/dom/is-selection-forward.js.map +7 -1
- package/build/dom/is-text-field.js +49 -24
- package/build/dom/is-text-field.js.map +7 -1
- package/build/dom/is-vertical-edge.js +34 -20
- package/build/dom/is-vertical-edge.js.map +7 -1
- package/build/dom/place-caret-at-edge.js +52 -55
- package/build/dom/place-caret-at-edge.js.map +7 -1
- package/build/dom/place-caret-at-horizontal-edge.js +34 -18
- package/build/dom/place-caret-at-horizontal-edge.js.map +7 -1
- package/build/dom/place-caret-at-vertical-edge.js +34 -19
- package/build/dom/place-caret-at-vertical-edge.js.map +7 -1
- package/build/dom/remove-invalid-html.js +35 -22
- package/build/dom/remove-invalid-html.js.map +7 -1
- package/build/dom/remove.js +24 -17
- package/build/dom/remove.js.map +7 -1
- package/build/dom/replace-tag.js +24 -19
- package/build/dom/replace-tag.js.map +7 -1
- package/build/dom/replace.js +38 -23
- package/build/dom/replace.js.map +7 -1
- package/build/dom/safe-html.js +39 -28
- package/build/dom/safe-html.js.map +7 -1
- package/build/dom/scroll-if-no-range.js +26 -18
- package/build/dom/scroll-if-no-range.js.map +7 -1
- package/build/dom/strip-html.js +36 -23
- package/build/dom/strip-html.js.map +7 -1
- package/build/dom/unwrap.js +24 -18
- package/build/dom/unwrap.js.map +7 -1
- package/build/dom/wrap.js +24 -17
- package/build/dom/wrap.js.map +7 -1
- package/build/focusable.js +52 -85
- package/build/focusable.js.map +7 -1
- package/build/index.js +44 -58
- package/build/index.js.map +7 -1
- package/build/phrasing-content.js +88 -128
- package/build/phrasing-content.js.map +7 -1
- package/build/tabbable.js +52 -137
- package/build/tabbable.js.map +7 -1
- package/build/utils/assert-is-defined.js +30 -7
- package/build/utils/assert-is-defined.js.map +7 -1
- package/build-module/data-transfer.js +9 -15
- package/build-module/data-transfer.js.map +7 -1
- package/build-module/dom/caret-range-from-point.js +5 -22
- package/build-module/dom/caret-range-from-point.js.map +7 -1
- package/build-module/dom/clean-node-list.js +94 -123
- package/build-module/dom/clean-node-list.js.map +7 -1
- package/build-module/dom/compute-caret-rect.js +8 -16
- package/build-module/dom/compute-caret-rect.js.map +7 -1
- package/build-module/dom/document-has-selection.js +8 -17
- package/build-module/dom/document-has-selection.js.map +7 -1
- package/build-module/dom/document-has-text-selection.js +8 -20
- package/build-module/dom/document-has-text-selection.js.map +7 -1
- package/build-module/dom/document-has-uncollapsed-selection.js +7 -17
- package/build-module/dom/document-has-uncollapsed-selection.js.map +7 -1
- package/build-module/dom/get-computed-style.js +10 -14
- package/build-module/dom/get-computed-style.js.map +7 -1
- package/build-module/dom/get-offset-parent.js +16 -28
- package/build-module/dom/get-offset-parent.js.map +7 -1
- package/build-module/dom/get-range-height.js +7 -15
- package/build-module/dom/get-range-height.js.map +7 -1
- package/build-module/dom/get-rectangle-from-range.js +30 -65
- package/build-module/dom/get-rectangle-from-range.js.map +7 -1
- package/build-module/dom/get-scroll-container.js +16 -32
- package/build-module/dom/get-scroll-container.js.map +7 -1
- package/build-module/dom/hidden-caret-range-from-point.js +11 -28
- package/build-module/dom/hidden-caret-range-from-point.js.map +7 -1
- package/build-module/dom/index.js +57 -28
- package/build-module/dom/index.js.map +7 -1
- package/build-module/dom/input-field-has-uncollapsed-selection.js +12 -37
- package/build-module/dom/input-field-has-uncollapsed-selection.js.map +7 -1
- package/build-module/dom/insert-after.js +7 -16
- package/build-module/dom/insert-after.js.map +7 -1
- package/build-module/dom/is-edge.js +24 -57
- package/build-module/dom/is-edge.js.map +7 -1
- package/build-module/dom/is-element.js +5 -8
- package/build-module/dom/is-element.js.map +7 -1
- package/build-module/dom/is-empty.js +10 -14
- package/build-module/dom/is-empty.js.map +7 -1
- package/build-module/dom/is-entirely-selected.js +18 -45
- package/build-module/dom/is-entirely-selected.js.map +7 -1
- package/build-module/dom/is-form-element.js +8 -19
- package/build-module/dom/is-form-element.js.map +7 -1
- package/build-module/dom/is-horizontal-edge.js +6 -15
- package/build-module/dom/is-horizontal-edge.js.map +7 -1
- package/build-module/dom/is-html-input-element.js +6 -9
- package/build-module/dom/is-html-input-element.js.map +7 -1
- package/build-module/dom/is-input-or-text-area.js +6 -9
- package/build-module/dom/is-input-or-text-area.js.map +7 -1
- package/build-module/dom/is-number-input.js +11 -25
- package/build-module/dom/is-number-input.js.map +7 -1
- package/build-module/dom/is-rtl.js +7 -15
- package/build-module/dom/is-rtl.js.map +7 -1
- package/build-module/dom/is-selection-forward.js +9 -37
- package/build-module/dom/is-selection-forward.js.map +7 -1
- package/build-module/dom/is-text-field.js +22 -20
- package/build-module/dom/is-text-field.js.map +7 -1
- package/build-module/dom/is-vertical-edge.js +6 -15
- package/build-module/dom/is-vertical-edge.js.map +7 -1
- package/build-module/dom/place-caret-at-edge.js +22 -48
- package/build-module/dom/place-caret-at-edge.js.map +7 -1
- package/build-module/dom/place-caret-at-horizontal-edge.js +7 -14
- package/build-module/dom/place-caret-at-horizontal-edge.js.map +7 -1
- package/build-module/dom/place-caret-at-vertical-edge.js +6 -14
- package/build-module/dom/place-caret-at-vertical-edge.js.map +7 -1
- package/build-module/dom/remove-invalid-html.js +7 -17
- package/build-module/dom/remove-invalid-html.js.map +7 -1
- package/build-module/dom/remove.js +7 -14
- package/build-module/dom/remove.js.map +7 -1
- package/build-module/dom/replace-tag.js +7 -16
- package/build-module/dom/replace-tag.js.map +7 -1
- package/build-module/dom/replace.js +9 -17
- package/build-module/dom/replace.js.map +7 -1
- package/build-module/dom/safe-html.js +11 -23
- package/build-module/dom/safe-html.js.map +7 -1
- package/build-module/dom/scroll-if-no-range.js +5 -15
- package/build-module/dom/scroll-if-no-range.js.map +7 -1
- package/build-module/dom/strip-html.js +8 -18
- package/build-module/dom/strip-html.js.map +7 -1
- package/build-module/dom/unwrap.js +7 -15
- package/build-module/dom/unwrap.js.map +7 -1
- package/build-module/dom/wrap.js +7 -14
- package/build-module/dom/wrap.js.map +7 -1
- package/build-module/focusable.js +30 -81
- package/build-module/focusable.js.map +7 -1
- package/build-module/index.js +9 -17
- package/build-module/index.js.map +7 -1
- package/build-module/phrasing-content.js +67 -125
- package/build-module/phrasing-content.js.map +7 -1
- package/build-module/tabbable.js +30 -133
- package/build-module/tabbable.js.map +7 -1
- package/build-module/utils/assert-is-defined.js +9 -4
- package/build-module/utils/assert-is-defined.js.map +7 -1
- package/package.json +11 -4
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/phrasing-content.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * All phrasing content elements.\n *\n * @see https://www.w3.org/TR/2011/WD-html5-20110525/content-models.html#phrasing-content-0\n */\n\n/**\n * @typedef {Record<string,SemanticElementDefinition>} ContentSchema\n */\n\n/**\n * @typedef SemanticElementDefinition\n * @property {string[]} [attributes] Content attributes\n * @property {ContentSchema} [children] Content attributes\n */\n\n/**\n * All text-level semantic elements.\n *\n * @see https://html.spec.whatwg.org/multipage/text-level-semantics.html\n *\n * @type {ContentSchema}\n */\nconst textContentSchema = {\n\tstrong: {},\n\tem: {},\n\ts: {},\n\tdel: {},\n\tins: {},\n\ta: { attributes: [ 'href', 'target', 'rel', 'id' ] },\n\tcode: {},\n\tabbr: { attributes: [ 'title' ] },\n\tsub: {},\n\tsup: {},\n\tbr: {},\n\tsmall: {},\n\t// To do: fix blockquote.\n\t// cite: {},\n\tq: { attributes: [ 'cite' ] },\n\tdfn: { attributes: [ 'title' ] },\n\tdata: { attributes: [ 'value' ] },\n\ttime: { attributes: [ 'datetime' ] },\n\tvar: {},\n\tsamp: {},\n\tkbd: {},\n\ti: {},\n\tb: {},\n\tu: {},\n\tmark: {},\n\truby: {},\n\trt: {},\n\trp: {},\n\tbdi: { attributes: [ 'dir' ] },\n\tbdo: { attributes: [ 'dir' ] },\n\twbr: {},\n\t'#text': {},\n};\n\n// Recursion is needed.\n// Possible: strong > em > strong.\n// Impossible: strong > strong.\nconst excludedElements = [ '#text', 'br' ];\nObject.keys( textContentSchema )\n\t.filter( ( element ) => ! excludedElements.includes( element ) )\n\t.forEach( ( tag ) => {\n\t\tconst { [ tag ]: removedTag, ...restSchema } = textContentSchema;\n\t\ttextContentSchema[ tag ].children = restSchema;\n\t} );\n\n/**\n * Embedded content elements.\n *\n * @see https://www.w3.org/TR/2011/WD-html5-20110525/content-models.html#embedded-content-0\n *\n * @type {ContentSchema}\n */\nconst embeddedContentSchema = {\n\taudio: {\n\t\tattributes: [\n\t\t\t'src',\n\t\t\t'preload',\n\t\t\t'autoplay',\n\t\t\t'mediagroup',\n\t\t\t'loop',\n\t\t\t'muted',\n\t\t],\n\t},\n\tcanvas: { attributes: [ 'width', 'height' ] },\n\tembed: { attributes: [ 'src', 'type', 'width', 'height' ] },\n\timg: {\n\t\tattributes: [\n\t\t\t'alt',\n\t\t\t'src',\n\t\t\t'srcset',\n\t\t\t'usemap',\n\t\t\t'ismap',\n\t\t\t'width',\n\t\t\t'height',\n\t\t],\n\t},\n\tobject: {\n\t\tattributes: [\n\t\t\t'data',\n\t\t\t'type',\n\t\t\t'name',\n\t\t\t'usemap',\n\t\t\t'form',\n\t\t\t'width',\n\t\t\t'height',\n\t\t],\n\t},\n\tvideo: {\n\t\tattributes: [\n\t\t\t'src',\n\t\t\t'poster',\n\t\t\t'preload',\n\t\t\t'playsinline',\n\t\t\t'autoplay',\n\t\t\t'mediagroup',\n\t\t\t'loop',\n\t\t\t'muted',\n\t\t\t'controls',\n\t\t\t'width',\n\t\t\t'height',\n\t\t],\n\t},\n};\n\n/**\n * Phrasing content elements.\n *\n * @see https://www.w3.org/TR/2011/WD-html5-20110525/content-models.html#phrasing-content-0\n */\nconst phrasingContentSchema = {\n\t...textContentSchema,\n\t...embeddedContentSchema,\n};\n\n/**\n * Get schema of possible paths for phrasing content.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories#Phrasing_content\n *\n * @param {string} [context] Set to \"paste\" to exclude invisible elements and\n * sensitive data.\n *\n * @return {Partial<ContentSchema>} Schema.\n */\nexport function getPhrasingContentSchema( context ) {\n\tif ( context !== 'paste' ) {\n\t\treturn phrasingContentSchema;\n\t}\n\n\t/**\n\t * @type {Partial<ContentSchema>}\n\t */\n\tconst {\n\t\tu, // Used to mark misspelling. Shouldn't be pasted.\n\t\tabbr, // Invisible.\n\t\tdata, // Invisible.\n\t\ttime, // Invisible.\n\t\twbr, // Invisible.\n\t\tbdi, // Invisible.\n\t\tbdo, // Invisible.\n\t\t...remainingContentSchema\n\t} = {\n\t\t...phrasingContentSchema,\n\t\t// We shouldn't paste potentially sensitive information which is not\n\t\t// visible to the user when pasted, so strip the attributes.\n\t\tins: { children: phrasingContentSchema.ins.children },\n\t\tdel: { children: phrasingContentSchema.del.children },\n\t};\n\n\treturn remainingContentSchema;\n}\n\n/**\n * Find out whether or not the given node is phrasing content.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories#Phrasing_content\n *\n * @param {Node} node The node to test.\n *\n * @return {boolean} True if phrasing content, false if not.\n */\nexport function isPhrasingContent( node ) {\n\tconst tag = node.nodeName.toLowerCase();\n\treturn getPhrasingContentSchema().hasOwnProperty( tag ) || tag === 'span';\n}\n\n/**\n * @param {Node} node\n * @return {boolean} Node is text content\n */\nexport function isTextContent( node ) {\n\tconst tag = node.nodeName.toLowerCase();\n\treturn textContentSchema.hasOwnProperty( tag ) || tag === 'span';\n}\n"],
|
|
5
|
+
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C,SAAO,yBAAyB,EAAE,eAAgB,GAAI,KAAK,QAAQ;AACpE;AAMO,SAAS,cAAe,MAAO;AACrC,QAAM,MAAM,KAAK,SAAS,YAAY;AACtC,SAAO,kBAAkB,eAAgB,GAAI,KAAK,QAAQ;AAC3D;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/build-module/tabbable.js
CHANGED
|
@@ -1,121 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
* Internal dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { find as findFocusable } from './focusable';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Returns the tab index of the given element. In contrast with the tabIndex
|
|
8
|
-
* property, this normalizes the default (0) to avoid browser inconsistencies,
|
|
9
|
-
* operating under the assumption that this function is only ever called with a
|
|
10
|
-
* focusable node.
|
|
11
|
-
*
|
|
12
|
-
* @see https://bugzilla.mozilla.org/show_bug.cgi?id=1190261
|
|
13
|
-
*
|
|
14
|
-
* @param {Element} element Element from which to retrieve.
|
|
15
|
-
*
|
|
16
|
-
* @return {number} Tab index of element (default 0).
|
|
17
|
-
*/
|
|
1
|
+
import { find as findFocusable } from "./focusable";
|
|
18
2
|
function getTabIndex(element) {
|
|
19
|
-
const tabIndex = element.getAttribute(
|
|
3
|
+
const tabIndex = element.getAttribute("tabindex");
|
|
20
4
|
return tabIndex === null ? 0 : parseInt(tabIndex, 10);
|
|
21
5
|
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Returns true if the specified element is tabbable, or false otherwise.
|
|
25
|
-
*
|
|
26
|
-
* @param {Element} element Element to test.
|
|
27
|
-
*
|
|
28
|
-
* @return {boolean} Whether element is tabbable.
|
|
29
|
-
*/
|
|
30
|
-
export function isTabbableIndex(element) {
|
|
6
|
+
function isTabbableIndex(element) {
|
|
31
7
|
return getTabIndex(element) !== -1;
|
|
32
8
|
}
|
|
33
|
-
|
|
34
|
-
/** @typedef {HTMLElement & { type?: string, checked?: boolean, name?: string }} MaybeHTMLInputElement */
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Returns a stateful reducer function which constructs a filtered array of
|
|
38
|
-
* tabbable elements, where at most one radio input is selected for a given
|
|
39
|
-
* name, giving priority to checked input, falling back to the first
|
|
40
|
-
* encountered.
|
|
41
|
-
*
|
|
42
|
-
* @return {(acc: MaybeHTMLInputElement[], el: MaybeHTMLInputElement) => MaybeHTMLInputElement[]} Radio group collapse reducer.
|
|
43
|
-
*/
|
|
44
9
|
function createStatefulCollapseRadioGroup() {
|
|
45
|
-
/** @type {Record<string, MaybeHTMLInputElement>} */
|
|
46
10
|
const CHOSEN_RADIO_BY_NAME = {};
|
|
47
|
-
return function collapseRadioGroup(
|
|
48
|
-
const {
|
|
49
|
-
|
|
50
|
-
type,
|
|
51
|
-
checked,
|
|
52
|
-
name
|
|
53
|
-
} = element;
|
|
54
|
-
|
|
55
|
-
// For all non-radio tabbables, construct to array by concatenating.
|
|
56
|
-
if (nodeName !== 'INPUT' || type !== 'radio' || !name) {
|
|
11
|
+
return function collapseRadioGroup(result, element) {
|
|
12
|
+
const { nodeName, type, checked, name } = element;
|
|
13
|
+
if (nodeName !== "INPUT" || type !== "radio" || !name) {
|
|
57
14
|
return result.concat(element);
|
|
58
15
|
}
|
|
59
16
|
const hasChosen = CHOSEN_RADIO_BY_NAME.hasOwnProperty(name);
|
|
60
|
-
|
|
61
|
-
// Omit by skipping concatenation if the radio element is not chosen.
|
|
62
17
|
const isChosen = checked || !hasChosen;
|
|
63
18
|
if (!isChosen) {
|
|
64
19
|
return result;
|
|
65
20
|
}
|
|
66
|
-
|
|
67
|
-
// At this point, if there had been a chosen element, the current
|
|
68
|
-
// element is checked and should take priority. Retroactively remove
|
|
69
|
-
// the element which had previously been considered the chosen one.
|
|
70
21
|
if (hasChosen) {
|
|
71
22
|
const hadChosenElement = CHOSEN_RADIO_BY_NAME[name];
|
|
72
|
-
result = result.filter(e => e !== hadChosenElement);
|
|
23
|
+
result = result.filter((e) => e !== hadChosenElement);
|
|
73
24
|
}
|
|
74
25
|
CHOSEN_RADIO_BY_NAME[name] = element;
|
|
75
26
|
return result.concat(element);
|
|
76
27
|
};
|
|
77
28
|
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* An array map callback, returning an object with the element value and its
|
|
81
|
-
* array index location as properties. This is used to emulate a proper stable
|
|
82
|
-
* sort where equal tabIndex should be left in order of their occurrence in the
|
|
83
|
-
* document.
|
|
84
|
-
*
|
|
85
|
-
* @param {HTMLElement} element Element.
|
|
86
|
-
* @param {number} index Array index of element.
|
|
87
|
-
*
|
|
88
|
-
* @return {{ element: HTMLElement, index: number }} Mapped object with element, index.
|
|
89
|
-
*/
|
|
90
29
|
function mapElementToObjectTabbable(element, index) {
|
|
91
|
-
return {
|
|
92
|
-
element,
|
|
93
|
-
index
|
|
94
|
-
};
|
|
30
|
+
return { element, index };
|
|
95
31
|
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* An array map callback, returning an element of the given mapped object's
|
|
99
|
-
* element value.
|
|
100
|
-
*
|
|
101
|
-
* @param {{ element: HTMLElement }} object Mapped object with element.
|
|
102
|
-
*
|
|
103
|
-
* @return {HTMLElement} Mapped object element.
|
|
104
|
-
*/
|
|
105
32
|
function mapObjectTabbableToElement(object) {
|
|
106
33
|
return object.element;
|
|
107
34
|
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* A sort comparator function used in comparing two objects of mapped elements.
|
|
111
|
-
*
|
|
112
|
-
* @see mapElementToObjectTabbable
|
|
113
|
-
*
|
|
114
|
-
* @param {{ element: HTMLElement, index: number }} a First object to compare.
|
|
115
|
-
* @param {{ element: HTMLElement, index: number }} b Second object to compare.
|
|
116
|
-
*
|
|
117
|
-
* @return {number} Comparator result.
|
|
118
|
-
*/
|
|
119
35
|
function compareObjectTabbables(a, b) {
|
|
120
36
|
const aTabIndex = getTabIndex(a.element);
|
|
121
37
|
const bTabIndex = getTabIndex(b.element);
|
|
@@ -124,51 +40,32 @@ function compareObjectTabbables(a, b) {
|
|
|
124
40
|
}
|
|
125
41
|
return aTabIndex - bTabIndex;
|
|
126
42
|
}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* Givin focusable elements, filters out tabbable element.
|
|
130
|
-
*
|
|
131
|
-
* @param {HTMLElement[]} focusables Focusable elements to filter.
|
|
132
|
-
*
|
|
133
|
-
* @return {HTMLElement[]} Tabbable elements.
|
|
134
|
-
*/
|
|
135
43
|
function filterTabbable(focusables) {
|
|
136
44
|
return focusables.filter(isTabbableIndex).map(mapElementToObjectTabbable).sort(compareObjectTabbables).map(mapObjectTabbableToElement).reduce(createStatefulCollapseRadioGroup(), []);
|
|
137
45
|
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* @param {Element} context
|
|
141
|
-
* @return {HTMLElement[]} Tabbable elements within the context.
|
|
142
|
-
*/
|
|
143
|
-
export function find(context) {
|
|
46
|
+
function find(context) {
|
|
144
47
|
return filterTabbable(findFocusable(context));
|
|
145
48
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
* @return {HTMLElement|undefined} Preceding tabbable element.
|
|
154
|
-
*/
|
|
155
|
-
export function findPrevious(element) {
|
|
156
|
-
return filterTabbable(findFocusable(element.ownerDocument.body)).reverse().find(focusable =>
|
|
157
|
-
// eslint-disable-next-line no-bitwise
|
|
158
|
-
element.compareDocumentPosition(focusable) & element.DOCUMENT_POSITION_PRECEDING);
|
|
49
|
+
function findPrevious(element) {
|
|
50
|
+
return filterTabbable(findFocusable(element.ownerDocument.body)).reverse().find(
|
|
51
|
+
(focusable) => (
|
|
52
|
+
// eslint-disable-next-line no-bitwise
|
|
53
|
+
element.compareDocumentPosition(focusable) & element.DOCUMENT_POSITION_PRECEDING
|
|
54
|
+
)
|
|
55
|
+
);
|
|
159
56
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
* @return {HTMLElement|undefined} Next tabbable element.
|
|
168
|
-
*/
|
|
169
|
-
export function findNext(element) {
|
|
170
|
-
return filterTabbable(findFocusable(element.ownerDocument.body)).find(focusable =>
|
|
171
|
-
// eslint-disable-next-line no-bitwise
|
|
172
|
-
element.compareDocumentPosition(focusable) & element.DOCUMENT_POSITION_FOLLOWING);
|
|
57
|
+
function findNext(element) {
|
|
58
|
+
return filterTabbable(findFocusable(element.ownerDocument.body)).find(
|
|
59
|
+
(focusable) => (
|
|
60
|
+
// eslint-disable-next-line no-bitwise
|
|
61
|
+
element.compareDocumentPosition(focusable) & element.DOCUMENT_POSITION_FOLLOWING
|
|
62
|
+
)
|
|
63
|
+
);
|
|
173
64
|
}
|
|
174
|
-
|
|
65
|
+
export {
|
|
66
|
+
find,
|
|
67
|
+
findNext,
|
|
68
|
+
findPrevious,
|
|
69
|
+
isTabbableIndex
|
|
70
|
+
};
|
|
71
|
+
//# sourceMappingURL=tabbable.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/tabbable.js"],
|
|
4
|
+
"sourcesContent": ["/**\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 {HTMLElement & { 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 = result.filter( ( e ) => e !== 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 {HTMLElement} element Element.\n * @param {number} index Array index of element.\n *\n * @return {{ element: HTMLElement, 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: HTMLElement }} object Mapped object with element.\n *\n * @return {HTMLElement} 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: HTMLElement, index: number }} a First object to compare.\n * @param {{ element: HTMLElement, 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 {HTMLElement[]} focusables Focusable elements to filter.\n *\n * @return {HTMLElement[]} 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 {HTMLElement[]} 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 *\n * @return {HTMLElement|undefined} Preceding tabbable element.\n */\nexport function findPrevious( element ) {\n\treturn filterTabbable( findFocusable( element.ownerDocument.body ) )\n\t\t.reverse()\n\t\t.find(\n\t\t\t( focusable ) =>\n\t\t\t\t// eslint-disable-next-line no-bitwise\n\t\t\t\telement.compareDocumentPosition( focusable ) &\n\t\t\t\telement.DOCUMENT_POSITION_PRECEDING\n\t\t);\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 *\n * @return {HTMLElement|undefined} Next tabbable element.\n */\nexport function findNext( element ) {\n\treturn filterTabbable( findFocusable( element.ownerDocument.body ) ).find(\n\t\t( focusable ) =>\n\t\t\t// eslint-disable-next-line no-bitwise\n\t\t\telement.compareDocumentPosition( focusable ) &\n\t\t\telement.DOCUMENT_POSITION_FOLLOWING\n\t);\n}\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,QAAQ,qBAAqB;AActC,SAAS,YAAa,SAAU;AAC/B,QAAM,WAAW,QAAQ,aAAc,UAAW;AAClD,SAAO,aAAa,OAAO,IAAI,SAAU,UAAU,EAAG;AACvD;AASO,SAAS,gBAAiB,SAAU;AAC1C,SAAO,YAAa,OAAQ,MAAM;AACnC;AAYA,SAAS,mCAAmC;AAE3C,QAAM,uBAAuB,CAAC;AAE9B,SAAO,SAAS,mBACwB,QACF,SACpC;AACD,UAAM,EAAE,UAAU,MAAM,SAAS,KAAK,IAAI;AAG1C,QAAK,aAAa,WAAW,SAAS,WAAW,CAAE,MAAO;AACzD,aAAO,OAAO,OAAQ,OAAQ;AAAA,IAC/B;AAEA,UAAM,YAAY,qBAAqB,eAAgB,IAAK;AAG5D,UAAM,WAAW,WAAW,CAAE;AAC9B,QAAK,CAAE,UAAW;AACjB,aAAO;AAAA,IACR;AAKA,QAAK,WAAY;AAChB,YAAM,mBAAmB,qBAAsB,IAAK;AACpD,eAAS,OAAO,OAAQ,CAAE,MAAO,MAAM,gBAAiB;AAAA,IACzD;AAEA,yBAAsB,IAAK,IAAI;AAE/B,WAAO,OAAO,OAAQ,OAAQ;AAAA,EAC/B;AACD;AAaA,SAAS,2BAA4B,SAAS,OAAQ;AACrD,SAAO,EAAE,SAAS,MAAM;AACzB;AAUA,SAAS,2BAA4B,QAAS;AAC7C,SAAO,OAAO;AACf;AAYA,SAAS,uBAAwB,GAAG,GAAI;AACvC,QAAM,YAAY,YAAa,EAAE,OAAQ;AACzC,QAAM,YAAY,YAAa,EAAE,OAAQ;AAEzC,MAAK,cAAc,WAAY;AAC9B,WAAO,EAAE,QAAQ,EAAE;AAAA,EACpB;AAEA,SAAO,YAAY;AACpB;AASA,SAAS,eAAgB,YAAa;AACrC,SAAO,WACL,OAAQ,eAAgB,EACxB,IAAK,0BAA2B,EAChC,KAAM,sBAAuB,EAC7B,IAAK,0BAA2B,EAChC,OAAQ,iCAAiC,GAAG,CAAC,CAAE;AAClD;AAMO,SAAS,KAAM,SAAU;AAC/B,SAAO,eAAgB,cAAe,OAAQ,CAAE;AACjD;AAUO,SAAS,aAAc,SAAU;AACvC,SAAO,eAAgB,cAAe,QAAQ,cAAc,IAAK,CAAE,EACjE,QAAQ,EACR;AAAA,IACA,CAAE;AAAA;AAAA,MAED,QAAQ,wBAAyB,SAAU,IAC3C,QAAQ;AAAA;AAAA,EACV;AACF;AAUO,SAAS,SAAU,SAAU;AACnC,SAAO,eAAgB,cAAe,QAAQ,cAAc,IAAK,CAAE,EAAE;AAAA,IACpE,CAAE;AAAA;AAAA,MAED,QAAQ,wBAAyB,SAAU,IAC3C,QAAQ;AAAA;AAAA,EACV;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
if (process.env.NODE_ENV !==
|
|
3
|
-
throw new Error(
|
|
1
|
+
function assertIsDefined(val, name) {
|
|
2
|
+
if (process.env.NODE_ENV !== "production" && (val === void 0 || val === null)) {
|
|
3
|
+
throw new Error(
|
|
4
|
+
`Expected '${name}' to be defined, but received ${val}`
|
|
5
|
+
);
|
|
4
6
|
}
|
|
5
7
|
}
|
|
6
|
-
|
|
8
|
+
export {
|
|
9
|
+
assertIsDefined
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=assert-is-defined.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/utils/assert-is-defined.ts"],
|
|
4
|
+
"sourcesContent": ["export function assertIsDefined< T >(\n\tval: T,\n\tname: string\n): asserts val is NonNullable< T > {\n\tif (\n\t\tprocess.env.NODE_ENV !== 'production' &&\n\t\t( val === undefined || val === null )\n\t) {\n\t\tthrow new Error(\n\t\t\t`Expected '${ name }' to be defined, but received ${ val }`\n\t\t);\n\t}\n}\n"],
|
|
5
|
+
"mappings": "AAAO,SAAS,gBACf,KACA,MACkC;AAClC,MACC,QAAQ,IAAI,aAAa,iBACvB,QAAQ,UAAa,QAAQ,OAC9B;AACD,UAAM,IAAI;AAAA,MACT,aAAc,IAAK,iCAAkC,GAAI;AAAA,IAC1D;AAAA,EACD;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/dom",
|
|
3
|
-
"version": "4.32.0",
|
|
3
|
+
"version": "4.32.1-next.b8c8708f3.0",
|
|
4
4
|
"description": "DOM utilities module for WordPress.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -25,16 +25,23 @@
|
|
|
25
25
|
},
|
|
26
26
|
"main": "build/index.js",
|
|
27
27
|
"module": "build-module/index.js",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./build-types/index.d.ts",
|
|
31
|
+
"import": "./build-module/index.js",
|
|
32
|
+
"require": "./build/index.js"
|
|
33
|
+
},
|
|
34
|
+
"./package.json": "./package.json"
|
|
35
|
+
},
|
|
28
36
|
"react-native": "src/index",
|
|
29
37
|
"wpScript": true,
|
|
30
38
|
"types": "build-types",
|
|
31
39
|
"sideEffects": false,
|
|
32
40
|
"dependencies": {
|
|
33
|
-
"@
|
|
34
|
-
"@wordpress/deprecated": "^4.32.0"
|
|
41
|
+
"@wordpress/deprecated": "^4.32.1-next.b8c8708f3.0"
|
|
35
42
|
},
|
|
36
43
|
"publishConfig": {
|
|
37
44
|
"access": "public"
|
|
38
45
|
},
|
|
39
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "67cfd7e661931aeb0d06bec894599d287a4f8d0f"
|
|
40
47
|
}
|