@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
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["@wordpress/dom/src/dom/place-caret-at-edge.js"],"names":["getRange","container","isReverse","x","ownerDocument","isReverseDir","containerRect","getBoundingClientRect","undefined","right","left","y","bottom","top","placeCaretAtEdge","focus","selectionStart","value","length","selectionEnd","isContentEditable","range","startContainer","contains","scrollIntoView","defaultView","selection","getSelection","removeAllRanges","addRange"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AANA;AACA;AACA;;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,QAAT,CAAmBC,SAAnB,EAA8BC,SAA9B,EAAyCC,CAAzC,EAA6C;AAC5C,QAAM;AAAEC,IAAAA;AAAF,MAAoBH,SAA1B,CAD4C,CAE5C;;AACA,QAAMI,YAAY,GAAG,oBAAOJ,SAAP,IAAqB,CAAEC,SAAvB,GAAmCA,SAAxD;AACA,QAAMI,aAAa,GAAGL,SAAS,CAACM,qBAAV,EAAtB,CAJ4C,CAK5C;AACA;;AACA,MAAKJ,CAAC,KAAKK,SAAX,EAAuB;AACtBL,IAAAA,CAAC,GAAGD,SAAS,GAAGI,aAAa,CAACG,KAAd,GAAsB,CAAzB,GAA6BH,aAAa,CAACI,IAAd,GAAqB,CAA/D;AACA;;AACD,QAAMC,CAAC,GAAGN,YAAY,GAAGC,aAAa,CAACM,MAAd,GAAuB,CAA1B,GAA8BN,aAAa,CAACO,GAAd,GAAoB,CAAxE;AACA,SAAO,wCAA2BT,aAA3B,EAA0CD,CAA1C,EAA6CQ,CAA7C,EAAgDV,SAAhD,CAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACe,SAASa,gBAAT,CAA2Bb,SAA3B,EAAsCC,SAAtC,EAAiDC,CAAjD,EAAqD;AACnE,MAAK,CAAEF,SAAP,EAAmB;AAClB;AACA;;AAEDA,EAAAA,SAAS,CAACc,KAAV;;AAEA,MAAK,gCAAmBd,SAAnB,CAAL,EAAsC;AACrC;AACA,QAAK,OAAOA,SAAS,CAACe,cAAjB,KAAoC,QAAzC,EAAoD;AACnD;AACA;;AAED,QAAKd,SAAL,EAAiB;AAChBD,MAAAA,SAAS,CAACe,cAAV,GAA2Bf,SAAS,CAACgB,KAAV,CAAgBC,MAA3C;AACAjB,MAAAA,SAAS,CAACkB,YAAV,GAAyBlB,SAAS,CAACgB,KAAV,CAAgBC,MAAzC;AACA,KAHD,MAGO;AACNjB,MAAAA,SAAS,CAACe,cAAV,GAA2B,CAA3B;AACAf,MAAAA,SAAS,CAACkB,YAAV,GAAyB,CAAzB;AACA;;AAED;AACA;;AAED,MAAK,CAAElB,SAAS,CAACmB,iBAAjB,EAAqC;AACpC;AACA;;AAED,MAAIC,KAAK,GAAGrB,QAAQ,CAAEC,SAAF,EAAaC,SAAb,EAAwBC,CAAxB,CAApB,CA5BmE,CA8BnE;AACA;;AACA,MACC,CAAEkB,KAAF,IACA,CAAEA,KAAK,CAACC,cADR,IAEA,CAAErB,SAAS,CAACsB,QAAV,CAAoBF,KAAK,CAACC,cAA1B,CAHH,EAIE;AACDrB,IAAAA,SAAS,CAACuB,cAAV,CAA0BtB,SAA1B;AACAmB,IAAAA,KAAK,GAAGA,KAAK,GAAGrB,QAAQ,CAAEC,SAAF,EAAaC,SAAb,EAAwBC,CAAxB,CAAxB;;AAEA,QACC,CAAEkB,KAAF,IACA,CAAEA,KAAK,CAACC,cADR,IAEA,CAAErB,SAAS,CAACsB,QAAV,CAAoBF,KAAK,CAACC,cAA1B,CAHH,EAIE;AACD;AACA;AACD;;AAED,QAAM;AAAElB,IAAAA;AAAF,MAAoBH,SAA1B;AACA,QAAM;AAAEwB,IAAAA;AAAF,MAAkBrB,aAAxB;AACA,wCAAiBqB,WAAjB,EAA8B,aAA9B;AACA,QAAMC,SAAS,GAAGD,WAAW,CAACE,YAAZ,EAAlB;AACA,wCAAiBD,SAAjB,EAA4B,WAA5B;AACAA,EAAAA,SAAS,CAACE,eAAV;AACAF,EAAAA,SAAS,CAACG,QAAV,CAAoBR,KAApB;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport hiddenCaretRangeFromPoint from './hidden-caret-range-from-point';\nimport { assertIsDefined } from '../utils/assert-is-defined';\nimport isInputOrTextArea from './is-input-or-text-area';\nimport isRTL from './is-rtl';\n\n/**\n * Gets the range to place.\n *\n * @param {HTMLElement} container Focusable element.\n * @param {boolean} isReverse True for end, false for start.\n * @param {number|undefined} x X coordinate to vertically position.\n *\n * @return {Range|null} The range to place.\n */\nfunction getRange( container, isReverse, x ) {\n\tconst { ownerDocument } = container;\n\t// In the case of RTL scripts, the horizontal edge is at the opposite side.\n\tconst isReverseDir = isRTL( container ) ? ! isReverse : isReverse;\n\tconst containerRect = container.getBoundingClientRect();\n\t// When placing at the end (isReverse), find the closest range to the bottom\n\t// right corner. When placing at the start, to the top left corner.\n\tif ( x === undefined ) {\n\t\tx = isReverse ? containerRect.right - 1 : containerRect.left + 1;\n\t}\n\tconst y = isReverseDir ? containerRect.bottom - 1 : containerRect.top + 1;\n\treturn hiddenCaretRangeFromPoint( ownerDocument, x, y, container );\n}\n\n/**\n * Places the caret at start or end of a given element.\n *\n * @param {HTMLElement} container Focusable element.\n * @param {boolean} isReverse True for end, false for start.\n * @param {number|undefined} x X coordinate to vertically position.\n */\nexport default function placeCaretAtEdge( container, isReverse, x ) {\n\tif ( ! container ) {\n\t\treturn;\n\t}\n\n\tcontainer.focus();\n\n\tif ( isInputOrTextArea( container ) ) {\n\t\t// The element may not support selection setting.\n\t\tif ( typeof container.selectionStart !== 'number' ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( isReverse ) {\n\t\t\tcontainer.selectionStart = container.value.length;\n\t\t\tcontainer.selectionEnd = container.value.length;\n\t\t} else {\n\t\t\tcontainer.selectionStart = 0;\n\t\t\tcontainer.selectionEnd = 0;\n\t\t}\n\n\t\treturn;\n\t}\n\n\tif ( ! container.isContentEditable ) {\n\t\treturn;\n\t}\n\n\tlet range = getRange( container, isReverse, x );\n\n\t// If no range range can be created or it is outside the container, the\n\t// element may be out of view.\n\tif (\n\t\t! range ||\n\t\t! range.startContainer ||\n\t\t! container.contains( range.startContainer )\n\t) {\n\t\tcontainer.scrollIntoView( isReverse );\n\t\trange = range = getRange( container, isReverse, x );\n\n\t\tif (\n\t\t\t! range ||\n\t\t\t! range.startContainer ||\n\t\t\t! container.contains( range.startContainer )\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t}\n\n\tconst { ownerDocument } = container;\n\tconst { defaultView } = ownerDocument;\n\tassertIsDefined( defaultView, 'defaultView' );\n\tconst selection = defaultView.getSelection();\n\tassertIsDefined( selection, 'selection' );\n\tselection.removeAllRanges();\n\tselection.addRange( range );\n}\n"]}
|
@@ -7,101 +7,19 @@ Object.defineProperty(exports, "__esModule", {
|
|
7
7
|
});
|
8
8
|
exports.default = placeCaretAtHorizontalEdge;
|
9
9
|
|
10
|
-
var
|
11
|
-
|
12
|
-
var _hiddenCaretRangeFromPoint = _interopRequireDefault(require("./hidden-caret-range-from-point"));
|
13
|
-
|
14
|
-
var _isInputOrTextArea = _interopRequireDefault(require("./is-input-or-text-area"));
|
15
|
-
|
16
|
-
var _isRtl = _interopRequireDefault(require("./is-rtl"));
|
17
|
-
|
18
|
-
/**
|
19
|
-
* Internal dependencies
|
20
|
-
*/
|
10
|
+
var _placeCaretAtEdge = _interopRequireDefault(require("./place-caret-at-edge"));
|
21
11
|
|
22
12
|
/**
|
23
13
|
* Internal dependencies
|
24
14
|
*/
|
25
15
|
|
26
|
-
/**
|
27
|
-
* Gets the range to place.
|
28
|
-
*
|
29
|
-
* @param {HTMLElement} container Focusable element.
|
30
|
-
* @param {boolean} isReverse True for end, false for start.
|
31
|
-
*
|
32
|
-
* @return {Range|null} The range to place.
|
33
|
-
*/
|
34
|
-
function getRange(container, isReverse) {
|
35
|
-
const {
|
36
|
-
ownerDocument
|
37
|
-
} = container; // In the case of RTL scripts, the horizontal edge is at the opposite side.
|
38
|
-
|
39
|
-
const isReverseDir = (0, _isRtl.default)(container) ? !isReverse : isReverse;
|
40
|
-
const containerRect = container.getBoundingClientRect(); // When placing at the end (isReverse), find the closest range to the bottom
|
41
|
-
// right corner. When placing at the start, to the top left corner.
|
42
|
-
|
43
|
-
const x = isReverse ? containerRect.right - 1 : containerRect.left + 1;
|
44
|
-
const y = isReverseDir ? containerRect.bottom - 1 : containerRect.top + 1;
|
45
|
-
return (0, _hiddenCaretRangeFromPoint.default)(ownerDocument, x, y, container);
|
46
|
-
}
|
47
16
|
/**
|
48
17
|
* Places the caret at start or end of a given element.
|
49
18
|
*
|
50
19
|
* @param {HTMLElement} container Focusable element.
|
51
20
|
* @param {boolean} isReverse True for end, false for start.
|
52
21
|
*/
|
53
|
-
|
54
|
-
|
55
22
|
function placeCaretAtHorizontalEdge(container, isReverse) {
|
56
|
-
|
57
|
-
return;
|
58
|
-
}
|
59
|
-
|
60
|
-
container.focus();
|
61
|
-
|
62
|
-
if ((0, _isInputOrTextArea.default)(container)) {
|
63
|
-
// The element may not support selection setting.
|
64
|
-
if (typeof container.selectionStart !== 'number') {
|
65
|
-
return;
|
66
|
-
}
|
67
|
-
|
68
|
-
if (isReverse) {
|
69
|
-
container.selectionStart = container.value.length;
|
70
|
-
container.selectionEnd = container.value.length;
|
71
|
-
} else {
|
72
|
-
container.selectionStart = 0;
|
73
|
-
container.selectionEnd = 0;
|
74
|
-
}
|
75
|
-
|
76
|
-
return;
|
77
|
-
}
|
78
|
-
|
79
|
-
if (!container.isContentEditable) {
|
80
|
-
return;
|
81
|
-
}
|
82
|
-
|
83
|
-
let range = getRange(container, isReverse); // If no range range can be created or it is outside the container, the
|
84
|
-
// element may be out of view.
|
85
|
-
|
86
|
-
if (!range || !range.startContainer || !container.contains(range.startContainer)) {
|
87
|
-
container.scrollIntoView(isReverse);
|
88
|
-
range = getRange(container, isReverse);
|
89
|
-
|
90
|
-
if (!range || !range.startContainer || !container.contains(range.startContainer)) {
|
91
|
-
return;
|
92
|
-
}
|
93
|
-
}
|
94
|
-
|
95
|
-
const {
|
96
|
-
ownerDocument
|
97
|
-
} = container;
|
98
|
-
const {
|
99
|
-
defaultView
|
100
|
-
} = ownerDocument;
|
101
|
-
(0, _assertIsDefined.assertIsDefined)(defaultView, 'defaultView');
|
102
|
-
const selection = defaultView.getSelection();
|
103
|
-
(0, _assertIsDefined.assertIsDefined)(selection, 'selection');
|
104
|
-
selection.removeAllRanges();
|
105
|
-
selection.addRange(range);
|
23
|
+
return (0, _placeCaretAtEdge.default)(container, isReverse, undefined);
|
106
24
|
}
|
107
25
|
//# sourceMappingURL=place-caret-at-horizontal-edge.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["@wordpress/dom/src/dom/place-caret-at-horizontal-edge.js"],"names":["
|
1
|
+
{"version":3,"sources":["@wordpress/dom/src/dom/place-caret-at-horizontal-edge.js"],"names":["placeCaretAtHorizontalEdge","container","isReverse","undefined"],"mappings":";;;;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,0BAAT,CAAqCC,SAArC,EAAgDC,SAAhD,EAA4D;AAC1E,SAAO,+BAAkBD,SAAlB,EAA6BC,SAA7B,EAAwCC,SAAxC,CAAP;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport placeCaretAtEdge from './place-caret-at-edge';\n\n/**\n * Places the caret at start or end of a given element.\n *\n * @param {HTMLElement} container Focusable element.\n * @param {boolean} isReverse True for end, false for start.\n */\nexport default function placeCaretAtHorizontalEdge( container, isReverse ) {\n\treturn placeCaretAtEdge( container, isReverse, undefined );\n}\n"]}
|
@@ -7,11 +7,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
7
7
|
});
|
8
8
|
exports.default = placeCaretAtVerticalEdge;
|
9
9
|
|
10
|
-
var
|
11
|
-
|
12
|
-
var _hiddenCaretRangeFromPoint = _interopRequireDefault(require("./hidden-caret-range-from-point"));
|
13
|
-
|
14
|
-
var _assertIsDefined = require("../utils/assert-is-defined");
|
10
|
+
var _placeCaretAtEdge = _interopRequireDefault(require("./place-caret-at-edge"));
|
15
11
|
|
16
12
|
/**
|
17
13
|
* Internal dependencies
|
@@ -20,57 +16,11 @@ var _assertIsDefined = require("../utils/assert-is-defined");
|
|
20
16
|
/**
|
21
17
|
* Places the caret at the top or bottom of a given element.
|
22
18
|
*
|
23
|
-
* @param {HTMLElement} container
|
24
|
-
* @param {boolean} isReverse
|
25
|
-
* @param {DOMRect} [rect]
|
26
|
-
* @param {boolean} [mayUseScroll=true] True to allow scrolling, false to disallow.
|
19
|
+
* @param {HTMLElement} container Focusable element.
|
20
|
+
* @param {boolean} isReverse True for bottom, false for top.
|
21
|
+
* @param {DOMRect} [rect] The rectangle to position the caret with.
|
27
22
|
*/
|
28
|
-
function placeCaretAtVerticalEdge(container, isReverse, rect
|
29
|
-
|
30
|
-
return;
|
31
|
-
}
|
32
|
-
|
33
|
-
if (!rect || !container.isContentEditable) {
|
34
|
-
(0, _placeCaretAtHorizontalEdge.default)(container, isReverse);
|
35
|
-
return;
|
36
|
-
}
|
37
|
-
|
38
|
-
container.focus(); // Offset by a buffer half the height of the caret rect. This is needed
|
39
|
-
// because caretRangeFromPoint may default to the end of the selection if
|
40
|
-
// offset is too close to the edge. It's unclear how to precisely calculate
|
41
|
-
// this threshold; it may be the padded area of some combination of line
|
42
|
-
// height, caret height, and font size. The buffer offset is effectively
|
43
|
-
// equivalent to a point at half the height of a line of text.
|
44
|
-
|
45
|
-
const buffer = rect.height / 2;
|
46
|
-
const editableRect = container.getBoundingClientRect();
|
47
|
-
const x = rect.left;
|
48
|
-
const y = isReverse ? editableRect.bottom - buffer : editableRect.top + buffer;
|
49
|
-
const {
|
50
|
-
ownerDocument
|
51
|
-
} = container;
|
52
|
-
const {
|
53
|
-
defaultView
|
54
|
-
} = ownerDocument;
|
55
|
-
const range = (0, _hiddenCaretRangeFromPoint.default)(ownerDocument, x, y, container);
|
56
|
-
|
57
|
-
if (!range || !container.contains(range.startContainer)) {
|
58
|
-
if (mayUseScroll && (!range || !range.startContainer || !range.startContainer.contains(container))) {
|
59
|
-
// Might be out of view.
|
60
|
-
// Easier than attempting to calculate manually.
|
61
|
-
container.scrollIntoView(isReverse);
|
62
|
-
placeCaretAtVerticalEdge(container, isReverse, rect, false);
|
63
|
-
return;
|
64
|
-
}
|
65
|
-
|
66
|
-
(0, _placeCaretAtHorizontalEdge.default)(container, isReverse);
|
67
|
-
return;
|
68
|
-
}
|
69
|
-
|
70
|
-
(0, _assertIsDefined.assertIsDefined)(defaultView, 'defaultView');
|
71
|
-
const selection = defaultView.getSelection();
|
72
|
-
(0, _assertIsDefined.assertIsDefined)(selection, 'selection');
|
73
|
-
selection.removeAllRanges();
|
74
|
-
selection.addRange(range);
|
23
|
+
function placeCaretAtVerticalEdge(container, isReverse, rect) {
|
24
|
+
return (0, _placeCaretAtEdge.default)(container, isReverse, rect === null || rect === void 0 ? void 0 : rect.left);
|
75
25
|
}
|
76
26
|
//# sourceMappingURL=place-caret-at-vertical-edge.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["@wordpress/dom/src/dom/place-caret-at-vertical-edge.js"],"names":["placeCaretAtVerticalEdge","container","isReverse","rect","
|
1
|
+
{"version":3,"sources":["@wordpress/dom/src/dom/place-caret-at-vertical-edge.js"],"names":["placeCaretAtVerticalEdge","container","isReverse","rect","left"],"mappings":";;;;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,wBAAT,CAAmCC,SAAnC,EAA8CC,SAA9C,EAAyDC,IAAzD,EAAgE;AAC9E,SAAO,+BAAkBF,SAAlB,EAA6BC,SAA7B,EAAwCC,IAAxC,aAAwCA,IAAxC,uBAAwCA,IAAI,CAAEC,IAA9C,CAAP;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport placeCaretAtEdge from './place-caret-at-edge';\n\n/**\n * Places the caret at the top or bottom of a given element.\n *\n * @param {HTMLElement} container Focusable element.\n * @param {boolean} isReverse True for bottom, false for top.\n * @param {DOMRect} [rect] The rectangle to position the caret with.\n */\nexport default function placeCaretAtVerticalEdge( container, isReverse, rect ) {\n\treturn placeCaretAtEdge( container, isReverse, rect?.left );\n}\n"]}
|
package/build/dom/strip-html.js
CHANGED
@@ -1,10 +1,18 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
+
|
3
5
|
Object.defineProperty(exports, "__esModule", {
|
4
6
|
value: true
|
5
7
|
});
|
6
8
|
exports.default = stripHTML;
|
7
9
|
|
10
|
+
var _safeHtml = _interopRequireDefault(require("./safe-html"));
|
11
|
+
|
12
|
+
/**
|
13
|
+
* Internal dependencies
|
14
|
+
*/
|
15
|
+
|
8
16
|
/**
|
9
17
|
* Removes any HTML tags from the provided string.
|
10
18
|
*
|
@@ -13,7 +21,11 @@ exports.default = stripHTML;
|
|
13
21
|
* @return {string} The text content with any html removed.
|
14
22
|
*/
|
15
23
|
function stripHTML(html) {
|
16
|
-
|
17
|
-
|
24
|
+
// Remove any script tags or on* attributes otherwise their *contents* will be left
|
25
|
+
// in place following removal of HTML tags.
|
26
|
+
html = (0, _safeHtml.default)(html);
|
27
|
+
const doc = document.implementation.createHTMLDocument('');
|
28
|
+
doc.body.innerHTML = html;
|
29
|
+
return doc.body.textContent || '';
|
18
30
|
}
|
19
31
|
//# sourceMappingURL=strip-html.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["@wordpress/dom/src/dom/strip-html.js"],"names":["stripHTML","html","
|
1
|
+
{"version":3,"sources":["@wordpress/dom/src/dom/strip-html.js"],"names":["stripHTML","html","doc","document","implementation","createHTMLDocument","body","innerHTML","textContent"],"mappings":";;;;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,SAAT,CAAoBC,IAApB,EAA2B;AACzC;AACA;AACAA,EAAAA,IAAI,GAAG,uBAAUA,IAAV,CAAP;AAEA,QAAMC,GAAG,GAAGC,QAAQ,CAACC,cAAT,CAAwBC,kBAAxB,CAA4C,EAA5C,CAAZ;AACAH,EAAAA,GAAG,CAACI,IAAJ,CAASC,SAAT,GAAqBN,IAArB;AACA,SAAOC,GAAG,CAACI,IAAJ,CAASE,WAAT,IAAwB,EAA/B;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport safeHTML from './safe-html';\n\n/**\n * Removes any HTML tags from the provided string.\n *\n * @param {string} html The string containing html.\n *\n * @return {string} The text content with any html removed.\n */\nexport default function stripHTML( html ) {\n\t// Remove any script tags or on* attributes otherwise their *contents* will be left\n\t// in place following removal of HTML tags.\n\thtml = safeHTML( html );\n\n\tconst doc = document.implementation.createHTMLDocument( '' );\n\tdoc.body.innerHTML = html;\n\treturn doc.body.textContent || '';\n}\n"]}
|
package/build/focusable.js
CHANGED
@@ -23,31 +23,33 @@ exports.find = find;
|
|
23
23
|
* AREA elements associated with an IMG:
|
24
24
|
* - https://w3c.github.io/html/editing.html#data-model
|
25
25
|
*/
|
26
|
-
|
26
|
+
|
27
27
|
/**
|
28
|
-
* Returns
|
29
|
-
* nor visibility: hidden).
|
28
|
+
* Returns a CSS selector used to query for focusable elements.
|
30
29
|
*
|
31
|
-
* @param {
|
30
|
+
* @param {boolean} sequential If set, only query elements that are sequentially
|
31
|
+
* focusable. Non-interactive elements with a
|
32
|
+
* negative `tabindex` are focusable but not
|
33
|
+
* sequentially focusable.
|
34
|
+
* https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute
|
32
35
|
*
|
33
|
-
* @return {
|
36
|
+
* @return {string} CSS selector.
|
34
37
|
*/
|
35
|
-
|
36
|
-
|
37
|
-
return element.offsetWidth > 0 || element.offsetHeight > 0 || element.getClientRects().length > 0;
|
38
|
+
function buildSelector(sequential) {
|
39
|
+
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(',');
|
38
40
|
}
|
39
41
|
/**
|
40
|
-
* Returns true if the specified element
|
41
|
-
*
|
42
|
+
* Returns true if the specified element is visible (i.e. neither display: none
|
43
|
+
* nor visibility: hidden).
|
42
44
|
*
|
43
|
-
* @param {
|
45
|
+
* @param {HTMLElement} element DOM element to test.
|
44
46
|
*
|
45
|
-
* @return {boolean} Whether element
|
47
|
+
* @return {boolean} Whether element is visible.
|
46
48
|
*/
|
47
49
|
|
48
50
|
|
49
|
-
function
|
50
|
-
return element.
|
51
|
+
function isVisible(element) {
|
52
|
+
return element.offsetWidth > 0 || element.offsetHeight > 0 || element.getClientRects().length > 0;
|
51
53
|
}
|
52
54
|
/**
|
53
55
|
* Returns true if the specified area element is a valid focusable element, or
|
@@ -76,21 +78,32 @@ function isValidFocusableArea(element) {
|
|
76
78
|
/**
|
77
79
|
* Returns all focusable elements within a given context.
|
78
80
|
*
|
79
|
-
* @param {Element} context
|
81
|
+
* @param {Element} context Element in which to search.
|
82
|
+
* @param {Object} [options]
|
83
|
+
* @param {boolean} [options.sequential] If set, only return elements that are
|
84
|
+
* sequentially focusable.
|
85
|
+
* Non-interactive elements with a
|
86
|
+
* negative `tabindex` are focusable but
|
87
|
+
* not sequentially focusable.
|
88
|
+
* https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute
|
80
89
|
*
|
81
90
|
* @return {Element[]} Focusable elements.
|
82
91
|
*/
|
83
92
|
|
84
93
|
|
85
94
|
function find(context) {
|
95
|
+
let {
|
96
|
+
sequential = false
|
97
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
98
|
+
|
86
99
|
/* eslint-disable jsdoc/no-undefined-types */
|
87
100
|
|
88
101
|
/** @type {NodeListOf<HTMLElement>} */
|
89
102
|
|
90
103
|
/* eslint-enable jsdoc/no-undefined-types */
|
91
|
-
const elements = context.querySelectorAll(
|
104
|
+
const elements = context.querySelectorAll(buildSelector(sequential));
|
92
105
|
return Array.from(elements).filter(element => {
|
93
|
-
if (!isVisible(element)
|
106
|
+
if (!isVisible(element)) {
|
94
107
|
return false;
|
95
108
|
}
|
96
109
|
|
package/build/focusable.js.map
CHANGED
@@ -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;;;AACO,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/index.js
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
|
4
|
-
|
5
3
|
Object.defineProperty(exports, "__esModule", {
|
6
4
|
value: true
|
7
5
|
});
|
@@ -56,6 +54,10 @@ Object.keys(_dataTransfer).forEach(function (key) {
|
|
56
54
|
});
|
57
55
|
});
|
58
56
|
|
57
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
58
|
+
|
59
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
60
|
+
|
59
61
|
/**
|
60
62
|
* Internal dependencies
|
61
63
|
*/
|
package/build/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["@wordpress/dom/src/index.js"],"names":["focus","focusable","tabbable"],"mappings":"
|
1
|
+
{"version":3,"sources":["@wordpress/dom/src/index.js"],"names":["focus","focusable","tabbable"],"mappings":";;;;;;;;;;AAGA;;AACA;;AAQA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;;;;AAdA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACO,MAAMA,KAAK,GAAG;AAAEC,EAAAA,SAAF;AAAaC,EAAAA;AAAb,CAAd","sourcesContent":["/**\n * Internal dependencies\n */\nimport * as focusable from './focusable';\nimport * as tabbable from './tabbable';\n\n/**\n * Object grouping `focusable` and `tabbable` utils\n * under the keys with the same name.\n */\nexport const focus = { focusable, tabbable };\n\nexport * from './dom';\nexport * from './phrasing-content';\nexport * from './data-transfer';\n"]}
|
package/build/tabbable.js
CHANGED
@@ -3,10 +3,10 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.isTabbableIndex = isTabbableIndex;
|
7
6
|
exports.find = find;
|
8
|
-
exports.findPrevious = findPrevious;
|
9
7
|
exports.findNext = findNext;
|
8
|
+
exports.findPrevious = findPrevious;
|
9
|
+
exports.isTabbableIndex = isTabbableIndex;
|
10
10
|
|
11
11
|
var _lodash = require("lodash");
|
12
12
|
|
@@ -199,9 +199,9 @@ function findPrevious(element) {
|
|
199
199
|
|
200
200
|
function findNext(element) {
|
201
201
|
const focusables = (0, _focusable.find)(element.ownerDocument.body);
|
202
|
-
const index = focusables.indexOf(element); // Remove all focusables before and
|
202
|
+
const index = focusables.indexOf(element); // Remove all focusables before and including `element`.
|
203
203
|
|
204
|
-
const remaining = focusables.slice(index + 1)
|
204
|
+
const remaining = focusables.slice(index + 1);
|
205
205
|
return (0, _lodash.first)(filterTabbable(remaining));
|
206
206
|
}
|
207
207
|
//# sourceMappingURL=tabbable.js.map
|
package/build/tabbable.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["@wordpress/dom/src/tabbable.js"],"names":["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","find","context","findPrevious","ownerDocument","body","indexOf","length","findNext","remaining","slice"
|
1
|
+
{"version":3,"sources":["@wordpress/dom/src/tabbable.js"],"names":["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","find","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"]}
|
@@ -10,11 +10,14 @@ export function getFilesFromDataTransfer(dataTransfer) {
|
|
10
10
|
Array.from(dataTransfer.items).forEach(item => {
|
11
11
|
const file = item.getAsFile();
|
12
12
|
|
13
|
-
if (file && !files.find(
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
if (file && !files.find(_ref => {
|
14
|
+
let {
|
15
|
+
name,
|
16
|
+
type,
|
17
|
+
size
|
18
|
+
} = _ref;
|
19
|
+
return name === file.name && type === file.type && size === file.size;
|
20
|
+
})) {
|
18
21
|
files.push(file);
|
19
22
|
}
|
20
23
|
});
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["@wordpress/dom/src/data-transfer.js"],"names":["getFilesFromDataTransfer","dataTransfer","files","Array","from","items","forEach","item","file","getAsFile","find","name","type","size","push"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,wBAAT,CAAmCC,YAAnC,EAAkD;AACxD,QAAMC,KAAK,GAAGC,KAAK,CAACC,IAAN,CAAYH,YAAY,CAACC,KAAzB,CAAd;AAEAC,EAAAA,KAAK,CAACC,IAAN,CAAYH,YAAY,CAACI,KAAzB,EAAiCC,OAAjC,CAA4CC,IAAF,IAAY;AACrD,UAAMC,IAAI,GAAGD,IAAI,CAACE,SAAL,EAAb;;AAEA,QACCD,IAAI,IACJ,CAAEN,KAAK,CAACQ,IAAN,CACD,
|
1
|
+
{"version":3,"sources":["@wordpress/dom/src/data-transfer.js"],"names":["getFilesFromDataTransfer","dataTransfer","files","Array","from","items","forEach","item","file","getAsFile","find","name","type","size","push"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,wBAAT,CAAmCC,YAAnC,EAAkD;AACxD,QAAMC,KAAK,GAAGC,KAAK,CAACC,IAAN,CAAYH,YAAY,CAACC,KAAzB,CAAd;AAEAC,EAAAA,KAAK,CAACC,IAAN,CAAYH,YAAY,CAACI,KAAzB,EAAiCC,OAAjC,CAA4CC,IAAF,IAAY;AACrD,UAAMC,IAAI,GAAGD,IAAI,CAACE,SAAL,EAAb;;AAEA,QACCD,IAAI,IACJ,CAAEN,KAAK,CAACQ,IAAN,CACD;AAAA,UAAE;AAAEC,QAAAA,IAAF;AAAQC,QAAAA,IAAR;AAAcC,QAAAA;AAAd,OAAF;AAAA,aACCF,IAAI,KAAKH,IAAI,CAACG,IAAd,IACAC,IAAI,KAAKJ,IAAI,CAACI,IADd,IAEAC,IAAI,KAAKL,IAAI,CAACK,IAHf;AAAA,KADC,CAFH,EAQE;AACDX,MAAAA,KAAK,CAACY,IAAN,CAAYN,IAAZ;AACA;AACD,GAdD;AAgBA,SAAON,KAAP;AACA","sourcesContent":["/**\n * Gets all files from a DataTransfer object.\n *\n * @param {DataTransfer} dataTransfer DataTransfer object to inspect.\n *\n * @return {File[]} An array containing all files.\n */\nexport function getFilesFromDataTransfer( dataTransfer ) {\n\tconst files = Array.from( dataTransfer.files );\n\n\tArray.from( dataTransfer.items ).forEach( ( item ) => {\n\t\tconst file = item.getAsFile();\n\n\t\tif (\n\t\t\tfile &&\n\t\t\t! files.find(\n\t\t\t\t( { name, type, size } ) =>\n\t\t\t\t\tname === file.name &&\n\t\t\t\t\ttype === file.type &&\n\t\t\t\t\tsize === file.size\n\t\t\t)\n\t\t) {\n\t\t\tfiles.push( file );\n\t\t}\n\t} );\n\n\treturn files;\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
|
*/
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["@wordpress/dom/src/dom/caret-range-from-point.js"],"names":["caretRangeFromPoint","doc","x","y","caretPositionFromPoint","point","range","createRange","setStart","offsetNode","offset","collapse"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASA,mBAAT,CAA8BC,GAA9B,EAAmCC,CAAnC,EAAsCC,CAAtC,EAA0C;AACxD,MAAKF,GAAG,CAACD,mBAAT,EAA+B;AAC9B,WAAOC,GAAG,CAACD,mBAAJ,CAAyBE,CAAzB,EAA4BC,CAA5B,CAAP;AACA;;AAED,MAAK,CAAEF,GAAG,CAACG,sBAAX,EAAoC;AACnC,WAAO,IAAP;AACA;;AAED,QAAMC,KAAK,GAAGJ,GAAG,CAACG,sBAAJ,CAA4BF,CAA5B,EAA+BC,CAA/B,CAAd,CATwD,CAWxD;AACA;;AACA,MAAK,CAAEE,KAAP,EAAe;AACd,WAAO,IAAP;AACA;;AAED,QAAMC,KAAK,GAAGL,GAAG,CAACM,WAAJ,EAAd;AAEAD,EAAAA,KAAK,CAACE,QAAN,CAAgBH,KAAK,CAACI,UAAtB,EAAkCJ,KAAK,CAACK,MAAxC;AACAJ,EAAAA,KAAK,CAACK,QAAN,CAAgB,IAAhB;AAEA,SAAOL,KAAP;AACA;AAED;AACA;AACA;AACA","sourcesContent":["/**\n * Polyfill.\n * Get a collapsed range for a given point.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Document/caretRangeFromPoint\n *\n * @param {DocumentMaybeWithCaretPositionFromPoint} doc The document of the range.\n * @param {number}
|
1
|
+
{"version":3,"sources":["@wordpress/dom/src/dom/caret-range-from-point.js"],"names":["caretRangeFromPoint","doc","x","y","caretPositionFromPoint","point","range","createRange","setStart","offsetNode","offset","collapse"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASA,mBAAT,CAA8BC,GAA9B,EAAmCC,CAAnC,EAAsCC,CAAtC,EAA0C;AACxD,MAAKF,GAAG,CAACD,mBAAT,EAA+B;AAC9B,WAAOC,GAAG,CAACD,mBAAJ,CAAyBE,CAAzB,EAA4BC,CAA5B,CAAP;AACA;;AAED,MAAK,CAAEF,GAAG,CAACG,sBAAX,EAAoC;AACnC,WAAO,IAAP;AACA;;AAED,QAAMC,KAAK,GAAGJ,GAAG,CAACG,sBAAJ,CAA4BF,CAA5B,EAA+BC,CAA/B,CAAd,CATwD,CAWxD;AACA;;AACA,MAAK,CAAEE,KAAP,EAAe;AACd,WAAO,IAAP;AACA;;AAED,QAAMC,KAAK,GAAGL,GAAG,CAACM,WAAJ,EAAd;AAEAD,EAAAA,KAAK,CAACE,QAAN,CAAgBH,KAAK,CAACI,UAAtB,EAAkCJ,KAAK,CAACK,MAAxC;AACAJ,EAAAA,KAAK,CAACK,QAAN,CAAgB,IAAhB;AAEA,SAAOL,KAAP;AACA;AAED;AACA;AACA;AACA","sourcesContent":["/**\n * Polyfill.\n * Get a collapsed range for a given point.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Document/caretRangeFromPoint\n *\n * @param {DocumentMaybeWithCaretPositionFromPoint} doc The document of the range.\n * @param {number} x Horizontal position within the current viewport.\n * @param {number} y Vertical position within the current viewport.\n *\n * @return {Range | null} The best range for the given point.\n */\nexport default function caretRangeFromPoint( doc, x, y ) {\n\tif ( doc.caretRangeFromPoint ) {\n\t\treturn doc.caretRangeFromPoint( x, y );\n\t}\n\n\tif ( ! doc.caretPositionFromPoint ) {\n\t\treturn null;\n\t}\n\n\tconst point = doc.caretPositionFromPoint( x, y );\n\n\t// If x or y are negative, outside viewport, or there is no text entry node.\n\t// https://developer.mozilla.org/en-US/docs/Web/API/Document/caretRangeFromPoint\n\tif ( ! point ) {\n\t\treturn null;\n\t}\n\n\tconst range = doc.createRange();\n\n\trange.setStart( point.offsetNode, point.offset );\n\trange.collapse( true );\n\n\treturn range;\n}\n\n/**\n * @typedef {{caretPositionFromPoint?: (x: number, y: number)=> CaretPosition | null} & Document } DocumentMaybeWithCaretPositionFromPoint\n * @typedef {{ readonly offset: number; readonly offsetNode: Node; getClientRect(): DOMRect | null; }} CaretPosition\n */\n"]}
|
@@ -39,9 +39,9 @@ import isElement from './is-element';
|
|
39
39
|
*/
|
40
40
|
|
41
41
|
export default function cleanNodeList(nodeList, doc, schema, inline) {
|
42
|
-
Array.from(nodeList).forEach(
|
42
|
+
Array.from(nodeList).forEach((
|
43
43
|
/** @type {Node & { nextElementSibling?: unknown }} */
|
44
|
-
node => {
|
44
|
+
node) => {
|
45
45
|
var _schema$tag$isMatch, _schema$tag;
|
46
46
|
|
47
47
|
const tag = node.nodeName.toLowerCase(); // It's a valid child, if the tag exists in the schema without an isMatch
|
@@ -65,9 +65,11 @@ export default function cleanNodeList(nodeList, doc, schema, inline) {
|
|
65
65
|
|
66
66
|
if (node.hasAttributes()) {
|
67
67
|
// Strip invalid attributes.
|
68
|
-
Array.from(node.attributes).forEach(
|
69
|
-
|
70
|
-
|
68
|
+
Array.from(node.attributes).forEach(_ref => {
|
69
|
+
let {
|
70
|
+
name
|
71
|
+
} = _ref;
|
72
|
+
|
71
73
|
if (name !== 'class' && !includes(attributes, name)) {
|
72
74
|
node.removeAttribute(name);
|
73
75
|
}
|
@@ -79,14 +81,12 @@ export default function cleanNodeList(nodeList, doc, schema, inline) {
|
|
79
81
|
const mattchers = classes.map(item => {
|
80
82
|
if (typeof item === 'string') {
|
81
83
|
return (
|
82
|
-
|
83
|
-
|
84
|
-
);
|
84
|
+
/** @type {string} */
|
85
|
+
className) => className === item;
|
85
86
|
} else if (item instanceof RegExp) {
|
86
87
|
return (
|
87
|
-
|
88
|
-
|
89
|
-
);
|
88
|
+
/** @type {string} */
|
89
|
+
className) => item.test(className);
|
90
90
|
}
|
91
91
|
|
92
92
|
return noop;
|