@wordpress/dom 3.38.0 → 3.40.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/CHANGELOG.md +4 -0
- package/README.md +2 -2
- package/build/data-transfer.js +0 -2
- package/build/data-transfer.js.map +1 -1
- package/build/dom/caret-range-from-point.js +3 -5
- package/build/dom/caret-range-from-point.js.map +1 -1
- package/build/dom/clean-node-list.js +25 -42
- package/build/dom/clean-node-list.js.map +1 -1
- package/build/dom/compute-caret-rect.js +0 -6
- package/build/dom/compute-caret-rect.js.map +1 -1
- package/build/dom/document-has-selection.js +0 -5
- package/build/dom/document-has-selection.js.map +1 -1
- package/build/dom/document-has-text-selection.js +0 -2
- package/build/dom/document-has-text-selection.js.map +1 -1
- package/build/dom/document-has-uncollapsed-selection.js +0 -4
- package/build/dom/document-has-uncollapsed-selection.js.map +1 -1
- package/build/dom/get-computed-style.js +0 -3
- package/build/dom/get-computed-style.js.map +1 -1
- package/build/dom/get-offset-parent.js +8 -19
- package/build/dom/get-offset-parent.js.map +1 -1
- package/build/dom/get-range-height.js +0 -3
- package/build/dom/get-range-height.js.map +1 -1
- package/build/dom/get-rectangle-from-range.js +15 -22
- package/build/dom/get-rectangle-from-range.js.map +1 -1
- package/build/dom/get-scroll-container.js +3 -13
- package/build/dom/get-scroll-container.js.map +1 -1
- package/build/dom/hidden-caret-range-from-point.js +2 -6
- package/build/dom/hidden-caret-range-from-point.js.map +1 -1
- package/build/dom/index.js +0 -27
- package/build/dom/index.js.map +1 -1
- package/build/dom/input-field-has-uncollapsed-selection.js +8 -12
- package/build/dom/input-field-has-uncollapsed-selection.js.map +1 -1
- package/build/dom/insert-after.js +0 -2
- package/build/dom/insert-after.js.map +1 -1
- package/build/dom/is-edge.js +18 -40
- package/build/dom/is-edge.js.map +1 -1
- package/build/dom/is-element.js +0 -2
- package/build/dom/is-element.js.map +1 -1
- package/build/dom/is-empty.js +1 -7
- package/build/dom/is-empty.js.map +1 -1
- package/build/dom/is-entirely-selected.js +2 -18
- package/build/dom/is-entirely-selected.js.map +1 -1
- package/build/dom/is-form-element.js +0 -4
- package/build/dom/is-form-element.js.map +1 -1
- package/build/dom/is-horizontal-edge.js +2 -5
- package/build/dom/is-horizontal-edge.js.map +1 -1
- package/build/dom/is-html-input-element.js +0 -2
- package/build/dom/is-html-input-element.js.map +1 -1
- package/build/dom/is-input-or-text-area.js +0 -2
- package/build/dom/is-input-or-text-area.js.map +1 -1
- package/build/dom/is-number-input.js +0 -6
- package/build/dom/is-number-input.js.map +1 -1
- package/build/dom/is-rtl.js +0 -3
- package/build/dom/is-rtl.js.map +1 -1
- package/build/dom/is-selection-forward.js +6 -10
- package/build/dom/is-selection-forward.js.map +1 -1
- package/build/dom/is-text-field.js +1 -7
- package/build/dom/is-text-field.js.map +1 -1
- package/build/dom/is-vertical-edge.js +2 -5
- package/build/dom/is-vertical-edge.js.map +1 -1
- package/build/dom/place-caret-at-edge.js +8 -31
- package/build/dom/place-caret-at-edge.js.map +1 -1
- package/build/dom/place-caret-at-horizontal-edge.js +0 -3
- package/build/dom/place-caret-at-horizontal-edge.js.map +1 -1
- package/build/dom/place-caret-at-vertical-edge.js +0 -3
- package/build/dom/place-caret-at-vertical-edge.js.map +1 -1
- package/build/dom/remove-invalid-html.js +0 -3
- package/build/dom/remove-invalid-html.js.map +1 -1
- package/build/dom/remove.js +0 -2
- package/build/dom/remove.js.map +1 -1
- package/build/dom/replace-tag.js +0 -4
- package/build/dom/replace-tag.js.map +1 -1
- package/build/dom/replace.js +0 -5
- package/build/dom/replace.js.map +1 -1
- package/build/dom/safe-html.js +0 -8
- package/build/dom/safe-html.js.map +1 -1
- package/build/dom/scroll-if-no-range.js +31 -0
- package/build/dom/scroll-if-no-range.js.map +1 -0
- package/build/dom/strip-html.js +0 -3
- package/build/dom/strip-html.js.map +1 -1
- package/build/dom/unwrap.js +0 -4
- package/build/dom/unwrap.js.map +1 -1
- package/build/dom/wrap.js +0 -2
- package/build/dom/wrap.js.map +1 -1
- package/build/focusable.js +5 -18
- package/build/focusable.js.map +1 -1
- package/build/index.js +0 -11
- package/build/index.js.map +1 -1
- package/build/phrasing-content.js +13 -14
- package/build/phrasing-content.js.map +1 -1
- package/build/tabbable.js +21 -37
- package/build/tabbable.js.map +1 -1
- package/build/utils/assert-is-defined.js +0 -1
- package/build/utils/assert-is-defined.js.map +1 -1
- package/build-module/data-transfer.js +0 -1
- package/build-module/data-transfer.js.map +1 -1
- package/build-module/dom/caret-range-from-point.js +3 -4
- package/build-module/dom/caret-range-from-point.js.map +1 -1
- package/build-module/dom/clean-node-list.js +24 -35
- package/build-module/dom/clean-node-list.js.map +1 -1
- package/build-module/dom/compute-caret-rect.js +1 -3
- package/build-module/dom/compute-caret-rect.js.map +1 -1
- package/build-module/dom/document-has-selection.js +1 -1
- package/build-module/dom/document-has-selection.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 +1 -1
- package/build-module/dom/document-has-uncollapsed-selection.js.map +1 -1
- package/build-module/dom/get-computed-style.js +1 -2
- package/build-module/dom/get-computed-style.js.map +1 -1
- package/build-module/dom/get-offset-parent.js +9 -17
- package/build-module/dom/get-offset-parent.js.map +1 -1
- package/build-module/dom/get-range-height.js +0 -2
- package/build-module/dom/get-range-height.js.map +1 -1
- package/build-module/dom/get-rectangle-from-range.js +16 -21
- package/build-module/dom/get-rectangle-from-range.js.map +1 -1
- package/build-module/dom/get-scroll-container.js +4 -11
- package/build-module/dom/get-scroll-container.js.map +1 -1
- package/build-module/dom/hidden-caret-range-from-point.js +3 -3
- package/build-module/dom/hidden-caret-range-from-point.js.map +1 -1
- package/build-module/dom/index.js.map +1 -1
- package/build-module/dom/input-field-has-uncollapsed-selection.js +9 -9
- package/build-module/dom/input-field-has-uncollapsed-selection.js.map +1 -1
- package/build-module/dom/insert-after.js +1 -1
- package/build-module/dom/insert-after.js.map +1 -1
- package/build-module/dom/is-edge.js +19 -32
- package/build-module/dom/is-edge.js.map +1 -1
- package/build-module/dom/is-element.js +0 -1
- package/build-module/dom/is-element.js.map +1 -1
- package/build-module/dom/is-empty.js +1 -6
- package/build-module/dom/is-empty.js.map +1 -1
- package/build-module/dom/is-entirely-selected.js +3 -14
- package/build-module/dom/is-entirely-selected.js.map +1 -1
- package/build-module/dom/is-form-element.js +1 -2
- package/build-module/dom/is-form-element.js.map +1 -1
- package/build-module/dom/is-horizontal-edge.js +3 -3
- package/build-module/dom/is-horizontal-edge.js.map +1 -1
- package/build-module/dom/is-html-input-element.js +0 -1
- package/build-module/dom/is-html-input-element.js.map +1 -1
- package/build-module/dom/is-input-or-text-area.js +0 -1
- package/build-module/dom/is-input-or-text-area.js.map +1 -1
- package/build-module/dom/is-number-input.js +2 -4
- package/build-module/dom/is-number-input.js.map +1 -1
- package/build-module/dom/is-rtl.js +1 -1
- package/build-module/dom/is-rtl.js.map +1 -1
- package/build-module/dom/is-selection-forward.js +7 -9
- package/build-module/dom/is-selection-forward.js.map +1 -1
- package/build-module/dom/is-text-field.js +2 -5
- package/build-module/dom/is-text-field.js.map +1 -1
- package/build-module/dom/is-vertical-edge.js +3 -3
- package/build-module/dom/is-vertical-edge.js.map +1 -1
- package/build-module/dom/place-caret-at-edge.js +9 -26
- package/build-module/dom/place-caret-at-edge.js.map +1 -1
- package/build-module/dom/place-caret-at-horizontal-edge.js +1 -1
- package/build-module/dom/place-caret-at-horizontal-edge.js.map +1 -1
- package/build-module/dom/place-caret-at-vertical-edge.js +1 -1
- package/build-module/dom/place-caret-at-vertical-edge.js.map +1 -1
- package/build-module/dom/remove-invalid-html.js +1 -1
- package/build-module/dom/remove-invalid-html.js.map +1 -1
- package/build-module/dom/remove.js +1 -1
- package/build-module/dom/remove.js.map +1 -1
- package/build-module/dom/replace-tag.js +1 -3
- package/build-module/dom/replace-tag.js.map +1 -1
- package/build-module/dom/replace.js +1 -1
- package/build-module/dom/replace.js.map +1 -1
- package/build-module/dom/safe-html.js +1 -6
- package/build-module/dom/safe-html.js.map +1 -1
- package/build-module/dom/scroll-if-no-range.js +25 -0
- package/build-module/dom/scroll-if-no-range.js.map +1 -0
- package/build-module/dom/strip-html.js +1 -1
- package/build-module/dom/strip-html.js.map +1 -1
- package/build-module/dom/unwrap.js +1 -3
- package/build-module/dom/unwrap.js.map +1 -1
- package/build-module/dom/wrap.js +1 -1
- package/build-module/dom/wrap.js.map +1 -1
- package/build-module/focusable.js +5 -17
- package/build-module/focusable.js.map +1 -1
- package/build-module/index.js +1 -1
- package/build-module/index.js.map +1 -1
- package/build-module/phrasing-content.js +13 -11
- package/build-module/phrasing-content.js.map +1 -1
- package/build-module/tabbable.js +22 -33
- package/build-module/tabbable.js.map +1 -1
- package/build-module/utils/assert-is-defined.js.map +1 -1
- package/build-types/dom/is-edge.d.ts +4 -4
- package/build-types/dom/is-edge.d.ts.map +1 -1
- package/build-types/dom/is-horizontal-edge.d.ts +3 -3
- package/build-types/dom/is-horizontal-edge.d.ts.map +1 -1
- package/build-types/dom/is-vertical-edge.d.ts +3 -3
- package/build-types/dom/is-vertical-edge.d.ts.map +1 -1
- package/build-types/dom/place-caret-at-edge.d.ts.map +1 -1
- package/build-types/dom/scroll-if-no-range.d.ts +12 -0
- package/build-types/dom/scroll-if-no-range.d.ts.map +1 -0
- package/build-types/index.d.ts +2 -2
- package/build-types/index.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/dom/is-edge.js +6 -8
- package/src/dom/is-horizontal-edge.js +2 -2
- package/src/dom/is-vertical-edge.js +2 -2
- package/src/dom/place-caret-at-edge.js +5 -19
- package/src/dom/scroll-if-no-range.js +34 -0
- package/tsconfig.tsbuildinfo +1 -1
@@ -5,6 +5,8 @@ import hiddenCaretRangeFromPoint from './hidden-caret-range-from-point';
|
|
5
5
|
import { assertIsDefined } from '../utils/assert-is-defined';
|
6
6
|
import isInputOrTextArea from './is-input-or-text-area';
|
7
7
|
import isRTL from './is-rtl';
|
8
|
+
import { scrollIfNoRange } from './scroll-if-no-range';
|
9
|
+
|
8
10
|
/**
|
9
11
|
* Gets the range to place.
|
10
12
|
*
|
@@ -14,18 +16,17 @@ import isRTL from './is-rtl';
|
|
14
16
|
*
|
15
17
|
* @return {Range|null} The range to place.
|
16
18
|
*/
|
17
|
-
|
18
19
|
function getRange(container, isReverse, x) {
|
19
20
|
const {
|
20
21
|
ownerDocument
|
21
|
-
} = container;
|
22
|
-
|
22
|
+
} = container;
|
23
|
+
// In the case of RTL scripts, the horizontal edge is at the opposite side.
|
23
24
|
const isReverseDir = isRTL(container) ? !isReverse : isReverse;
|
24
|
-
const containerRect = container.getBoundingClientRect();
|
25
|
+
const containerRect = container.getBoundingClientRect();
|
26
|
+
// When placing at the end (isReverse), find the closest range to the bottom
|
25
27
|
// right corner. When placing at the start, to the top left corner.
|
26
28
|
// Ensure x is defined and within the container's boundaries. When it's
|
27
29
|
// exactly at the boundary, it's not considered within the boundaries.
|
28
|
-
|
29
30
|
if (x === undefined) {
|
30
31
|
x = isReverse ? containerRect.right - 1 : containerRect.left + 1;
|
31
32
|
} else if (x <= containerRect.left) {
|
@@ -33,10 +34,10 @@ function getRange(container, isReverse, x) {
|
|
33
34
|
} else if (x >= containerRect.right) {
|
34
35
|
x = containerRect.right - 1;
|
35
36
|
}
|
36
|
-
|
37
37
|
const y = isReverseDir ? containerRect.bottom - 1 : containerRect.top + 1;
|
38
38
|
return hiddenCaretRangeFromPoint(ownerDocument, x, y, container);
|
39
39
|
}
|
40
|
+
|
40
41
|
/**
|
41
42
|
* Places the caret at start or end of a given element.
|
42
43
|
*
|
@@ -44,21 +45,16 @@ function getRange(container, isReverse, x) {
|
|
44
45
|
* @param {boolean} isReverse True for end, false for start.
|
45
46
|
* @param {number|undefined} x X coordinate to vertically position.
|
46
47
|
*/
|
47
|
-
|
48
|
-
|
49
48
|
export default function placeCaretAtEdge(container, isReverse, x) {
|
50
49
|
if (!container) {
|
51
50
|
return;
|
52
51
|
}
|
53
|
-
|
54
52
|
container.focus();
|
55
|
-
|
56
53
|
if (isInputOrTextArea(container)) {
|
57
54
|
// The element may not support selection setting.
|
58
55
|
if (typeof container.selectionStart !== 'number') {
|
59
56
|
return;
|
60
57
|
}
|
61
|
-
|
62
58
|
if (isReverse) {
|
63
59
|
container.selectionStart = container.value.length;
|
64
60
|
container.selectionEnd = container.value.length;
|
@@ -66,26 +62,13 @@ export default function placeCaretAtEdge(container, isReverse, x) {
|
|
66
62
|
container.selectionStart = 0;
|
67
63
|
container.selectionEnd = 0;
|
68
64
|
}
|
69
|
-
|
70
65
|
return;
|
71
66
|
}
|
72
|
-
|
73
67
|
if (!container.isContentEditable) {
|
74
68
|
return;
|
75
69
|
}
|
76
|
-
|
77
|
-
|
78
|
-
// element may be out of view.
|
79
|
-
|
80
|
-
if (!range || !range.startContainer || !container.contains(range.startContainer)) {
|
81
|
-
container.scrollIntoView(isReverse);
|
82
|
-
range = range = getRange(container, isReverse, x);
|
83
|
-
|
84
|
-
if (!range || !range.startContainer || !container.contains(range.startContainer)) {
|
85
|
-
return;
|
86
|
-
}
|
87
|
-
}
|
88
|
-
|
70
|
+
const range = scrollIfNoRange(container, isReverse, () => getRange(container, isReverse, x));
|
71
|
+
if (!range) return;
|
89
72
|
const {
|
90
73
|
ownerDocument
|
91
74
|
} = container;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"names":["hiddenCaretRangeFromPoint","assertIsDefined","isInputOrTextArea","isRTL","scrollIfNoRange","getRange","container","isReverse","x","ownerDocument","isReverseDir","containerRect","getBoundingClientRect","undefined","right","left","y","bottom","top","placeCaretAtEdge","focus","selectionStart","value","length","selectionEnd","isContentEditable","range","defaultView","selection","getSelection","removeAllRanges","addRange"],"sources":["@wordpress/dom/src/dom/place-caret-at-edge.js"],"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';\nimport { scrollIfNoRange } from './scroll-if-no-range';\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\t// Ensure x is defined and within the container's boundaries. When it's\n\t// exactly at the boundary, it's not considered within the boundaries.\n\tif ( x === undefined ) {\n\t\tx = isReverse ? containerRect.right - 1 : containerRect.left + 1;\n\t} else if ( x <= containerRect.left ) {\n\t\tx = containerRect.left + 1;\n\t} else if ( x >= containerRect.right ) {\n\t\tx = containerRect.right - 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\tconst range = scrollIfNoRange( container, isReverse, () =>\n\t\tgetRange( container, isReverse, x )\n\t);\n\n\tif ( ! range ) return;\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"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,yBAAyB,MAAM,iCAAiC;AACvE,SAASC,eAAe,QAAQ,4BAA4B;AAC5D,OAAOC,iBAAiB,MAAM,yBAAyB;AACvD,OAAOC,KAAK,MAAM,UAAU;AAC5B,SAASC,eAAe,QAAQ,sBAAsB;;AAEtD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,QAAQA,CAAEC,SAAS,EAAEC,SAAS,EAAEC,CAAC,EAAG;EAC5C,MAAM;IAAEC;EAAc,CAAC,GAAGH,SAAS;EACnC;EACA,MAAMI,YAAY,GAAGP,KAAK,CAAEG,SAAU,CAAC,GAAG,CAAEC,SAAS,GAAGA,SAAS;EACjE,MAAMI,aAAa,GAAGL,SAAS,CAACM,qBAAqB,CAAC,CAAC;EACvD;EACA;EACA;EACA;EACA,IAAKJ,CAAC,KAAKK,SAAS,EAAG;IACtBL,CAAC,GAAGD,SAAS,GAAGI,aAAa,CAACG,KAAK,GAAG,CAAC,GAAGH,aAAa,CAACI,IAAI,GAAG,CAAC;EACjE,CAAC,MAAM,IAAKP,CAAC,IAAIG,aAAa,CAACI,IAAI,EAAG;IACrCP,CAAC,GAAGG,aAAa,CAACI,IAAI,GAAG,CAAC;EAC3B,CAAC,MAAM,IAAKP,CAAC,IAAIG,aAAa,CAACG,KAAK,EAAG;IACtCN,CAAC,GAAGG,aAAa,CAACG,KAAK,GAAG,CAAC;EAC5B;EACA,MAAME,CAAC,GAAGN,YAAY,GAAGC,aAAa,CAACM,MAAM,GAAG,CAAC,GAAGN,aAAa,CAACO,GAAG,GAAG,CAAC;EACzE,OAAOlB,yBAAyB,CAAES,aAAa,EAAED,CAAC,EAAEQ,CAAC,EAAEV,SAAU,CAAC;AACnE;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASa,gBAAgBA,CAAEb,SAAS,EAAEC,SAAS,EAAEC,CAAC,EAAG;EACnE,IAAK,CAAEF,SAAS,EAAG;IAClB;EACD;EAEAA,SAAS,CAACc,KAAK,CAAC,CAAC;EAEjB,IAAKlB,iBAAiB,CAAEI,SAAU,CAAC,EAAG;IACrC;IACA,IAAK,OAAOA,SAAS,CAACe,cAAc,KAAK,QAAQ,EAAG;MACnD;IACD;IAEA,IAAKd,SAAS,EAAG;MAChBD,SAAS,CAACe,cAAc,GAAGf,SAAS,CAACgB,KAAK,CAACC,MAAM;MACjDjB,SAAS,CAACkB,YAAY,GAAGlB,SAAS,CAACgB,KAAK,CAACC,MAAM;IAChD,CAAC,MAAM;MACNjB,SAAS,CAACe,cAAc,GAAG,CAAC;MAC5Bf,SAAS,CAACkB,YAAY,GAAG,CAAC;IAC3B;IAEA;EACD;EAEA,IAAK,CAAElB,SAAS,CAACmB,iBAAiB,EAAG;IACpC;EACD;EAEA,MAAMC,KAAK,GAAGtB,eAAe,CAAEE,SAAS,EAAEC,SAAS,EAAE,MACpDF,QAAQ,CAAEC,SAAS,EAAEC,SAAS,EAAEC,CAAE,CACnC,CAAC;EAED,IAAK,CAAEkB,KAAK,EAAG;EAEf,MAAM;IAAEjB;EAAc,CAAC,GAAGH,SAAS;EACnC,MAAM;IAAEqB;EAAY,CAAC,GAAGlB,aAAa;EACrCR,eAAe,CAAE0B,WAAW,EAAE,aAAc,CAAC;EAC7C,MAAMC,SAAS,GAAGD,WAAW,CAACE,YAAY,CAAC,CAAC;EAC5C5B,eAAe,CAAE2B,SAAS,EAAE,WAAY,CAAC;EACzCA,SAAS,CAACE,eAAe,CAAC,CAAC;EAC3BF,SAAS,CAACG,QAAQ,CAAEL,KAAM,CAAC;AAC5B"}
|
@@ -2,13 +2,13 @@
|
|
2
2
|
* Internal dependencies
|
3
3
|
*/
|
4
4
|
import placeCaretAtEdge from './place-caret-at-edge';
|
5
|
+
|
5
6
|
/**
|
6
7
|
* Places the caret at start or end of a given element.
|
7
8
|
*
|
8
9
|
* @param {HTMLElement} container Focusable element.
|
9
10
|
* @param {boolean} isReverse True for end, false for start.
|
10
11
|
*/
|
11
|
-
|
12
12
|
export default function placeCaretAtHorizontalEdge(container, isReverse) {
|
13
13
|
return placeCaretAtEdge(container, isReverse, undefined);
|
14
14
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"names":["placeCaretAtEdge","placeCaretAtHorizontalEdge","container","isReverse","undefined"],"sources":["@wordpress/dom/src/dom/place-caret-at-horizontal-edge.js"],"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"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,gBAAgB,MAAM,uBAAuB;;AAEpD;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,0BAA0BA,CAAEC,SAAS,EAAEC,SAAS,EAAG;EAC1E,OAAOH,gBAAgB,CAAEE,SAAS,EAAEC,SAAS,EAAEC,SAAU,CAAC;AAC3D"}
|
@@ -2,6 +2,7 @@
|
|
2
2
|
* Internal dependencies
|
3
3
|
*/
|
4
4
|
import placeCaretAtEdge from './place-caret-at-edge';
|
5
|
+
|
5
6
|
/**
|
6
7
|
* Places the caret at the top or bottom of a given element.
|
7
8
|
*
|
@@ -9,7 +10,6 @@ import placeCaretAtEdge from './place-caret-at-edge';
|
|
9
10
|
* @param {boolean} isReverse True for bottom, false for top.
|
10
11
|
* @param {DOMRect} [rect] The rectangle to position the caret with.
|
11
12
|
*/
|
12
|
-
|
13
13
|
export default function placeCaretAtVerticalEdge(container, isReverse, rect) {
|
14
14
|
return placeCaretAtEdge(container, isReverse, rect?.left);
|
15
15
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"names":["placeCaretAtEdge","placeCaretAtVerticalEdge","container","isReverse","rect","left"],"sources":["@wordpress/dom/src/dom/place-caret-at-vertical-edge.js"],"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"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,gBAAgB,MAAM,uBAAuB;;AAEpD;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,wBAAwBA,CAAEC,SAAS,EAAEC,SAAS,EAAEC,IAAI,EAAG;EAC9E,OAAOJ,gBAAgB,CAAEE,SAAS,EAAEC,SAAS,EAAEC,IAAI,EAAEC,IAAK,CAAC;AAC5D"}
|
@@ -2,6 +2,7 @@
|
|
2
2
|
* Internal dependencies
|
3
3
|
*/
|
4
4
|
import cleanNodeList from './clean-node-list';
|
5
|
+
|
5
6
|
/**
|
6
7
|
* Given a schema, unwraps or removes nodes, attributes and classes on HTML.
|
7
8
|
*
|
@@ -11,7 +12,6 @@ import cleanNodeList from './clean-node-list';
|
|
11
12
|
*
|
12
13
|
* @return {string} The cleaned up HTML.
|
13
14
|
*/
|
14
|
-
|
15
15
|
export default function removeInvalidHTML(HTML, schema, inline) {
|
16
16
|
const doc = document.implementation.createHTMLDocument('');
|
17
17
|
doc.body.innerHTML = HTML;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"names":["cleanNodeList","removeInvalidHTML","HTML","schema","inline","doc","document","implementation","createHTMLDocument","body","innerHTML","childNodes"],"sources":["@wordpress/dom/src/dom/remove-invalid-html.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport cleanNodeList from './clean-node-list';\n\n/**\n * Given a schema, unwraps or removes nodes, attributes and classes on HTML.\n *\n * @param {string} HTML The HTML to clean up.\n * @param {import('./clean-node-list').Schema} schema Schema for the HTML.\n * @param {boolean} inline Whether to clean for inline mode.\n *\n * @return {string} The cleaned up HTML.\n */\nexport default function removeInvalidHTML( HTML, schema, inline ) {\n\tconst doc = document.implementation.createHTMLDocument( '' );\n\n\tdoc.body.innerHTML = HTML;\n\n\tcleanNodeList( doc.body.childNodes, doc, schema, inline );\n\n\treturn doc.body.innerHTML;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,aAAa,MAAM,mBAAmB;;AAE7C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,iBAAiBA,CAAEC,IAAI,EAAEC,MAAM,EAAEC,MAAM,EAAG;EACjE,MAAMC,GAAG,GAAGC,QAAQ,CAACC,cAAc,CAACC,kBAAkB,CAAE,EAAG,CAAC;EAE5DH,GAAG,CAACI,IAAI,CAACC,SAAS,GAAGR,IAAI;EAEzBF,aAAa,CAAEK,GAAG,CAACI,IAAI,CAACE,UAAU,EAAEN,GAAG,EAAEF,MAAM,EAAEC,MAAO,CAAC;EAEzD,OAAOC,GAAG,CAACI,IAAI,CAACC,SAAS;AAC1B"}
|
@@ -2,13 +2,13 @@
|
|
2
2
|
* Internal dependencies
|
3
3
|
*/
|
4
4
|
import { assertIsDefined } from '../utils/assert-is-defined';
|
5
|
+
|
5
6
|
/**
|
6
7
|
* Given a DOM node, removes it from the DOM.
|
7
8
|
*
|
8
9
|
* @param {Node} node Node to be removed.
|
9
10
|
* @return {void}
|
10
11
|
*/
|
11
|
-
|
12
12
|
export default function remove(node) {
|
13
13
|
assertIsDefined(node.parentNode, 'node.parentNode');
|
14
14
|
node.parentNode.removeChild(node);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"names":["assertIsDefined","remove","node","parentNode","removeChild"],"sources":["@wordpress/dom/src/dom/remove.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { assertIsDefined } from '../utils/assert-is-defined';\n\n/**\n * Given a DOM node, removes it from the DOM.\n *\n * @param {Node} node Node to be removed.\n * @return {void}\n */\nexport default function remove( node ) {\n\tassertIsDefined( node.parentNode, 'node.parentNode' );\n\tnode.parentNode.removeChild( node );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,eAAe,QAAQ,4BAA4B;;AAE5D;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,MAAMA,CAAEC,IAAI,EAAG;EACtCF,eAAe,CAAEE,IAAI,CAACC,UAAU,EAAE,iBAAkB,CAAC;EACrDD,IAAI,CAACC,UAAU,CAACC,WAAW,CAAEF,IAAK,CAAC;AACpC"}
|
@@ -2,6 +2,7 @@
|
|
2
2
|
* Internal dependencies
|
3
3
|
*/
|
4
4
|
import { assertIsDefined } from '../utils/assert-is-defined';
|
5
|
+
|
5
6
|
/**
|
6
7
|
* Replaces the given node with a new node with the given tag name.
|
7
8
|
*
|
@@ -10,14 +11,11 @@ import { assertIsDefined } from '../utils/assert-is-defined';
|
|
10
11
|
*
|
11
12
|
* @return {Element} The new node.
|
12
13
|
*/
|
13
|
-
|
14
14
|
export default function replaceTag(node, tagName) {
|
15
15
|
const newNode = node.ownerDocument.createElement(tagName);
|
16
|
-
|
17
16
|
while (node.firstChild) {
|
18
17
|
newNode.appendChild(node.firstChild);
|
19
18
|
}
|
20
|
-
|
21
19
|
assertIsDefined(node.parentNode, 'node.parentNode');
|
22
20
|
node.parentNode.replaceChild(newNode, node);
|
23
21
|
return newNode;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"names":["assertIsDefined","replaceTag","node","tagName","newNode","ownerDocument","createElement","firstChild","appendChild","parentNode","replaceChild"],"sources":["@wordpress/dom/src/dom/replace-tag.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { assertIsDefined } from '../utils/assert-is-defined';\n\n/**\n * Replaces the given node with a new node with the given tag name.\n *\n * @param {Element} node The node to replace\n * @param {string} tagName The new tag name.\n *\n * @return {Element} The new node.\n */\nexport default function replaceTag( node, tagName ) {\n\tconst newNode = node.ownerDocument.createElement( tagName );\n\n\twhile ( node.firstChild ) {\n\t\tnewNode.appendChild( node.firstChild );\n\t}\n\n\tassertIsDefined( node.parentNode, 'node.parentNode' );\n\tnode.parentNode.replaceChild( newNode, node );\n\n\treturn newNode;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,eAAe,QAAQ,4BAA4B;;AAE5D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,UAAUA,CAAEC,IAAI,EAAEC,OAAO,EAAG;EACnD,MAAMC,OAAO,GAAGF,IAAI,CAACG,aAAa,CAACC,aAAa,CAAEH,OAAQ,CAAC;EAE3D,OAAQD,IAAI,CAACK,UAAU,EAAG;IACzBH,OAAO,CAACI,WAAW,CAAEN,IAAI,CAACK,UAAW,CAAC;EACvC;EAEAP,eAAe,CAAEE,IAAI,CAACO,UAAU,EAAE,iBAAkB,CAAC;EACrDP,IAAI,CAACO,UAAU,CAACC,YAAY,CAAEN,OAAO,EAAEF,IAAK,CAAC;EAE7C,OAAOE,OAAO;AACf"}
|
@@ -4,6 +4,7 @@
|
|
4
4
|
import { assertIsDefined } from '../utils/assert-is-defined';
|
5
5
|
import insertAfter from './insert-after';
|
6
6
|
import remove from './remove';
|
7
|
+
|
7
8
|
/**
|
8
9
|
* Given two DOM nodes, replaces the former with the latter in the DOM.
|
9
10
|
*
|
@@ -11,7 +12,6 @@ import remove from './remove';
|
|
11
12
|
* @param {Element} newNode Node to be inserted in its place.
|
12
13
|
* @return {void}
|
13
14
|
*/
|
14
|
-
|
15
15
|
export default function replace(processedNode, newNode) {
|
16
16
|
assertIsDefined(processedNode.parentNode, 'processedNode.parentNode');
|
17
17
|
insertAfter(newNode, processedNode.parentNode);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"names":["assertIsDefined","insertAfter","remove","replace","processedNode","newNode","parentNode"],"sources":["@wordpress/dom/src/dom/replace.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { assertIsDefined } from '../utils/assert-is-defined';\nimport insertAfter from './insert-after';\nimport remove from './remove';\n\n/**\n * Given two DOM nodes, replaces the former with the latter in the DOM.\n *\n * @param {Element} processedNode Node to be removed.\n * @param {Element} newNode Node to be inserted in its place.\n * @return {void}\n */\nexport default function replace( processedNode, newNode ) {\n\tassertIsDefined( processedNode.parentNode, 'processedNode.parentNode' );\n\tinsertAfter( newNode, processedNode.parentNode );\n\tremove( processedNode );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,eAAe,QAAQ,4BAA4B;AAC5D,OAAOC,WAAW,MAAM,gBAAgB;AACxC,OAAOC,MAAM,MAAM,UAAU;;AAE7B;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,OAAOA,CAAEC,aAAa,EAAEC,OAAO,EAAG;EACzDL,eAAe,CAAEI,aAAa,CAACE,UAAU,EAAE,0BAA2B,CAAC;EACvEL,WAAW,CAAEI,OAAO,EAAED,aAAa,CAACE,UAAW,CAAC;EAChDJ,MAAM,CAAEE,aAAc,CAAC;AACxB"}
|
@@ -2,6 +2,7 @@
|
|
2
2
|
* Internal dependencies
|
3
3
|
*/
|
4
4
|
import remove from './remove';
|
5
|
+
|
5
6
|
/**
|
6
7
|
* Strips scripts and on* attributes from HTML.
|
7
8
|
*
|
@@ -9,7 +10,6 @@ import remove from './remove';
|
|
9
10
|
*
|
10
11
|
* @return {string} The sanitized HTML.
|
11
12
|
*/
|
12
|
-
|
13
13
|
export default function safeHTML(html) {
|
14
14
|
const {
|
15
15
|
body
|
@@ -17,27 +17,22 @@ export default function safeHTML(html) {
|
|
17
17
|
body.innerHTML = html;
|
18
18
|
const elements = body.getElementsByTagName('*');
|
19
19
|
let elementIndex = elements.length;
|
20
|
-
|
21
20
|
while (elementIndex--) {
|
22
21
|
const element = elements[elementIndex];
|
23
|
-
|
24
22
|
if (element.tagName === 'SCRIPT') {
|
25
23
|
remove(element);
|
26
24
|
} else {
|
27
25
|
let attributeIndex = element.attributes.length;
|
28
|
-
|
29
26
|
while (attributeIndex--) {
|
30
27
|
const {
|
31
28
|
name: key
|
32
29
|
} = element.attributes[attributeIndex];
|
33
|
-
|
34
30
|
if (key.startsWith('on')) {
|
35
31
|
element.removeAttribute(key);
|
36
32
|
}
|
37
33
|
}
|
38
34
|
}
|
39
35
|
}
|
40
|
-
|
41
36
|
return body.innerHTML;
|
42
37
|
}
|
43
38
|
//# sourceMappingURL=safe-html.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"names":["remove","safeHTML","html","body","document","implementation","createHTMLDocument","innerHTML","elements","getElementsByTagName","elementIndex","length","element","tagName","attributeIndex","attributes","name","key","startsWith","removeAttribute"],"sources":["@wordpress/dom/src/dom/safe-html.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport remove from './remove';\n\n/**\n * Strips scripts and on* attributes from HTML.\n *\n * @param {string} html HTML to sanitize.\n *\n * @return {string} The sanitized HTML.\n */\nexport default function safeHTML( html ) {\n\tconst { body } = document.implementation.createHTMLDocument( '' );\n\tbody.innerHTML = html;\n\tconst elements = body.getElementsByTagName( '*' );\n\tlet elementIndex = elements.length;\n\n\twhile ( elementIndex-- ) {\n\t\tconst element = elements[ elementIndex ];\n\n\t\tif ( element.tagName === 'SCRIPT' ) {\n\t\t\tremove( element );\n\t\t} else {\n\t\t\tlet attributeIndex = element.attributes.length;\n\n\t\t\twhile ( attributeIndex-- ) {\n\t\t\t\tconst { name: key } = element.attributes[ attributeIndex ];\n\n\t\t\t\tif ( key.startsWith( 'on' ) ) {\n\t\t\t\t\telement.removeAttribute( key );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn body.innerHTML;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,MAAM,MAAM,UAAU;;AAE7B;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,QAAQA,CAAEC,IAAI,EAAG;EACxC,MAAM;IAAEC;EAAK,CAAC,GAAGC,QAAQ,CAACC,cAAc,CAACC,kBAAkB,CAAE,EAAG,CAAC;EACjEH,IAAI,CAACI,SAAS,GAAGL,IAAI;EACrB,MAAMM,QAAQ,GAAGL,IAAI,CAACM,oBAAoB,CAAE,GAAI,CAAC;EACjD,IAAIC,YAAY,GAAGF,QAAQ,CAACG,MAAM;EAElC,OAAQD,YAAY,EAAE,EAAG;IACxB,MAAME,OAAO,GAAGJ,QAAQ,CAAEE,YAAY,CAAE;IAExC,IAAKE,OAAO,CAACC,OAAO,KAAK,QAAQ,EAAG;MACnCb,MAAM,CAAEY,OAAQ,CAAC;IAClB,CAAC,MAAM;MACN,IAAIE,cAAc,GAAGF,OAAO,CAACG,UAAU,CAACJ,MAAM;MAE9C,OAAQG,cAAc,EAAE,EAAG;QAC1B,MAAM;UAAEE,IAAI,EAAEC;QAAI,CAAC,GAAGL,OAAO,CAACG,UAAU,CAAED,cAAc,CAAE;QAE1D,IAAKG,GAAG,CAACC,UAAU,CAAE,IAAK,CAAC,EAAG;UAC7BN,OAAO,CAACO,eAAe,CAAEF,GAAI,CAAC;QAC/B;MACD;IACD;EACD;EAEA,OAAOd,IAAI,CAACI,SAAS;AACtB"}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
/**
|
2
|
+
* If no range range can be created or it is outside the container, the element
|
3
|
+
* may be out of view, so scroll it into view and try again.
|
4
|
+
*
|
5
|
+
* @param {HTMLElement} container The container to scroll.
|
6
|
+
* @param {boolean} alignToTop True to align to top, false to bottom.
|
7
|
+
* @param {Function} callback The callback to create the range.
|
8
|
+
*
|
9
|
+
* @return {?Range} The range returned by the callback.
|
10
|
+
*/
|
11
|
+
export function scrollIfNoRange(container, alignToTop, callback) {
|
12
|
+
let range = callback();
|
13
|
+
|
14
|
+
// If no range range can be created or it is outside the container, the
|
15
|
+
// element may be out of view.
|
16
|
+
if (!range || !range.startContainer || !container.contains(range.startContainer)) {
|
17
|
+
container.scrollIntoView(alignToTop);
|
18
|
+
range = callback();
|
19
|
+
if (!range || !range.startContainer || !container.contains(range.startContainer)) {
|
20
|
+
return null;
|
21
|
+
}
|
22
|
+
}
|
23
|
+
return range;
|
24
|
+
}
|
25
|
+
//# sourceMappingURL=scroll-if-no-range.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["scrollIfNoRange","container","alignToTop","callback","range","startContainer","contains","scrollIntoView"],"sources":["@wordpress/dom/src/dom/scroll-if-no-range.js"],"sourcesContent":["/**\n * If no range range can be created or it is outside the container, the element\n * may be out of view, so scroll it into view and try again.\n *\n * @param {HTMLElement} container The container to scroll.\n * @param {boolean} alignToTop True to align to top, false to bottom.\n * @param {Function} callback The callback to create the range.\n *\n * @return {?Range} The range returned by the callback.\n */\nexport function scrollIfNoRange( container, alignToTop, callback ) {\n\tlet range = callback();\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( alignToTop );\n\t\trange = callback();\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 null;\n\t\t}\n\t}\n\n\treturn range;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,eAAeA,CAAEC,SAAS,EAAEC,UAAU,EAAEC,QAAQ,EAAG;EAClE,IAAIC,KAAK,GAAGD,QAAQ,CAAC,CAAC;;EAEtB;EACA;EACA,IACC,CAAEC,KAAK,IACP,CAAEA,KAAK,CAACC,cAAc,IACtB,CAAEJ,SAAS,CAACK,QAAQ,CAAEF,KAAK,CAACC,cAAe,CAAC,EAC3C;IACDJ,SAAS,CAACM,cAAc,CAAEL,UAAW,CAAC;IACtCE,KAAK,GAAGD,QAAQ,CAAC,CAAC;IAElB,IACC,CAAEC,KAAK,IACP,CAAEA,KAAK,CAACC,cAAc,IACtB,CAAEJ,SAAS,CAACK,QAAQ,CAAEF,KAAK,CAACC,cAAe,CAAC,EAC3C;MACD,OAAO,IAAI;IACZ;EACD;EAEA,OAAOD,KAAK;AACb"}
|
@@ -2,6 +2,7 @@
|
|
2
2
|
* Internal dependencies
|
3
3
|
*/
|
4
4
|
import safeHTML from './safe-html';
|
5
|
+
|
5
6
|
/**
|
6
7
|
* Removes any HTML tags from the provided string.
|
7
8
|
*
|
@@ -9,7 +10,6 @@ import safeHTML from './safe-html';
|
|
9
10
|
*
|
10
11
|
* @return {string} The text content with any html removed.
|
11
12
|
*/
|
12
|
-
|
13
13
|
export default function stripHTML(html) {
|
14
14
|
// Remove any script tags or on* attributes otherwise their *contents* will be left
|
15
15
|
// in place following removal of HTML tags.
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"names":["safeHTML","stripHTML","html","doc","document","implementation","createHTMLDocument","body","innerHTML","textContent"],"sources":["@wordpress/dom/src/dom/strip-html.js"],"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"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,QAAQ,MAAM,aAAa;;AAElC;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,SAASA,CAAEC,IAAI,EAAG;EACzC;EACA;EACAA,IAAI,GAAGF,QAAQ,CAAEE,IAAK,CAAC;EAEvB,MAAMC,GAAG,GAAGC,QAAQ,CAACC,cAAc,CAACC,kBAAkB,CAAE,EAAG,CAAC;EAC5DH,GAAG,CAACI,IAAI,CAACC,SAAS,GAAGN,IAAI;EACzB,OAAOC,GAAG,CAACI,IAAI,CAACE,WAAW,IAAI,EAAE;AAClC"}
|
@@ -2,6 +2,7 @@
|
|
2
2
|
* Internal dependencies
|
3
3
|
*/
|
4
4
|
import { assertIsDefined } from '../utils/assert-is-defined';
|
5
|
+
|
5
6
|
/**
|
6
7
|
* Unwrap the given node. This means any child nodes are moved to the parent.
|
7
8
|
*
|
@@ -9,15 +10,12 @@ import { assertIsDefined } from '../utils/assert-is-defined';
|
|
9
10
|
*
|
10
11
|
* @return {void}
|
11
12
|
*/
|
12
|
-
|
13
13
|
export default function unwrap(node) {
|
14
14
|
const parent = node.parentNode;
|
15
15
|
assertIsDefined(parent, 'node.parentNode');
|
16
|
-
|
17
16
|
while (node.firstChild) {
|
18
17
|
parent.insertBefore(node.firstChild, node);
|
19
18
|
}
|
20
|
-
|
21
19
|
parent.removeChild(node);
|
22
20
|
}
|
23
21
|
//# sourceMappingURL=unwrap.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"names":["assertIsDefined","unwrap","node","parent","parentNode","firstChild","insertBefore","removeChild"],"sources":["@wordpress/dom/src/dom/unwrap.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { assertIsDefined } from '../utils/assert-is-defined';\n\n/**\n * Unwrap the given node. This means any child nodes are moved to the parent.\n *\n * @param {Node} node The node to unwrap.\n *\n * @return {void}\n */\nexport default function unwrap( node ) {\n\tconst parent = node.parentNode;\n\n\tassertIsDefined( parent, 'node.parentNode' );\n\n\twhile ( node.firstChild ) {\n\t\tparent.insertBefore( node.firstChild, node );\n\t}\n\n\tparent.removeChild( node );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,eAAe,QAAQ,4BAA4B;;AAE5D;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,MAAMA,CAAEC,IAAI,EAAG;EACtC,MAAMC,MAAM,GAAGD,IAAI,CAACE,UAAU;EAE9BJ,eAAe,CAAEG,MAAM,EAAE,iBAAkB,CAAC;EAE5C,OAAQD,IAAI,CAACG,UAAU,EAAG;IACzBF,MAAM,CAACG,YAAY,CAAEJ,IAAI,CAACG,UAAU,EAAEH,IAAK,CAAC;EAC7C;EAEAC,MAAM,CAACI,WAAW,CAAEL,IAAK,CAAC;AAC3B"}
|
package/build-module/dom/wrap.js
CHANGED
@@ -2,13 +2,13 @@
|
|
2
2
|
* Internal dependencies
|
3
3
|
*/
|
4
4
|
import { assertIsDefined } from '../utils/assert-is-defined';
|
5
|
+
|
5
6
|
/**
|
6
7
|
* Wraps the given node with a new node with the given tag name.
|
7
8
|
*
|
8
9
|
* @param {Element} newNode The node to insert.
|
9
10
|
* @param {Element} referenceNode The node to wrap.
|
10
11
|
*/
|
11
|
-
|
12
12
|
export default function wrap(newNode, referenceNode) {
|
13
13
|
assertIsDefined(referenceNode.parentNode, 'referenceNode.parentNode');
|
14
14
|
referenceNode.parentNode.insertBefore(newNode, referenceNode);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"names":["assertIsDefined","wrap","newNode","referenceNode","parentNode","insertBefore","appendChild"],"sources":["@wordpress/dom/src/dom/wrap.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { assertIsDefined } from '../utils/assert-is-defined';\n\n/**\n * Wraps the given node with a new node with the given tag name.\n *\n * @param {Element} newNode The node to insert.\n * @param {Element} referenceNode The node to wrap.\n */\nexport default function wrap( newNode, referenceNode ) {\n\tassertIsDefined( referenceNode.parentNode, 'referenceNode.parentNode' );\n\treferenceNode.parentNode.insertBefore( newNode, referenceNode );\n\tnewNode.appendChild( referenceNode );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,eAAe,QAAQ,4BAA4B;;AAE5D;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,IAAIA,CAAEC,OAAO,EAAEC,aAAa,EAAG;EACtDH,eAAe,CAAEG,aAAa,CAACC,UAAU,EAAE,0BAA2B,CAAC;EACvED,aAAa,CAACC,UAAU,CAACC,YAAY,CAAEH,OAAO,EAAEC,aAAc,CAAC;EAC/DD,OAAO,CAACI,WAAW,CAAEH,aAAc,CAAC;AACrC"}
|
@@ -31,6 +31,7 @@
|
|
31
31
|
function buildSelector(sequential) {
|
32
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(',');
|
33
33
|
}
|
34
|
+
|
34
35
|
/**
|
35
36
|
* Returns true if the specified element is visible (i.e. neither display: none
|
36
37
|
* nor visibility: hidden).
|
@@ -39,11 +40,10 @@ function buildSelector(sequential) {
|
|
39
40
|
*
|
40
41
|
* @return {boolean} Whether element is visible.
|
41
42
|
*/
|
42
|
-
|
43
|
-
|
44
43
|
function isVisible(element) {
|
45
44
|
return element.offsetWidth > 0 || element.offsetHeight > 0 || element.getClientRects().length > 0;
|
46
45
|
}
|
46
|
+
|
47
47
|
/**
|
48
48
|
* Returns true if the specified area element is a valid focusable element, or
|
49
49
|
* false otherwise. Area is only focusable if within a map where a named map
|
@@ -53,21 +53,18 @@ function isVisible(element) {
|
|
53
53
|
*
|
54
54
|
* @return {boolean} Whether area element is valid for focus.
|
55
55
|
*/
|
56
|
-
|
57
|
-
|
58
56
|
function isValidFocusableArea(element) {
|
59
57
|
/** @type {HTMLMapElement | null} */
|
60
58
|
const map = element.closest('map[name]');
|
61
|
-
|
62
59
|
if (!map) {
|
63
60
|
return false;
|
64
61
|
}
|
65
|
-
/** @type {HTMLImageElement | null} */
|
66
|
-
|
67
62
|
|
63
|
+
/** @type {HTMLImageElement | null} */
|
68
64
|
const img = element.ownerDocument.querySelector('img[usemap="#' + map.name + '"]');
|
69
65
|
return !!img && isVisible(img);
|
70
66
|
}
|
67
|
+
|
71
68
|
/**
|
72
69
|
* Returns all focusable elements within a given context.
|
73
70
|
*
|
@@ -82,32 +79,23 @@ function isValidFocusableArea(element) {
|
|
82
79
|
*
|
83
80
|
* @return {HTMLElement[]} Focusable elements.
|
84
81
|
*/
|
85
|
-
|
86
|
-
|
87
82
|
export function find(context, {
|
88
83
|
sequential = false
|
89
84
|
} = {}) {
|
90
85
|
/* eslint-disable jsdoc/no-undefined-types */
|
91
|
-
|
92
86
|
/** @type {NodeListOf<HTMLElement>} */
|
93
|
-
|
94
87
|
/* eslint-enable jsdoc/no-undefined-types */
|
95
88
|
const elements = context.querySelectorAll(buildSelector(sequential));
|
96
89
|
return Array.from(elements).filter(element => {
|
97
90
|
if (!isVisible(element)) {
|
98
91
|
return false;
|
99
92
|
}
|
100
|
-
|
101
93
|
const {
|
102
94
|
nodeName
|
103
95
|
} = element;
|
104
|
-
|
105
96
|
if ('AREA' === nodeName) {
|
106
|
-
return isValidFocusableArea(
|
107
|
-
/** @type {HTMLAreaElement} */
|
108
|
-
element);
|
97
|
+
return isValidFocusableArea( /** @type {HTMLAreaElement} */element);
|
109
98
|
}
|
110
|
-
|
111
99
|
return true;
|
112
100
|
});
|
113
101
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"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"],"sources":["@wordpress/dom/src/focusable.js"],"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 {HTMLElement[]} 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"],"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,aAAaA,CAAEC,UAAU,EAAG;EACpC,OAAO,CACNA,UAAU,GAAG,iCAAiC,GAAG,YAAY,EAC7D,SAAS,EACT,wBAAwB,EACxB,4CAA4C,EAC5C,wBAAwB,EACxB,0BAA0B,EAC1B,6BAA6B,EAC7B,QAAQ,EACR,OAAO,EACP,YAAY,EACZ,gDAAgD,CAChD,CAACC,IAAI,CAAE,GAAI,CAAC;AACd;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,SAASA,CAAEC,OAAO,EAAG;EAC7B,OACCA,OAAO,CAACC,WAAW,GAAG,CAAC,IACvBD,OAAO,CAACE,YAAY,GAAG,CAAC,IACxBF,OAAO,CAACG,cAAc,CAAC,CAAC,CAACC,MAAM,GAAG,CAAC;AAErC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,oBAAoBA,CAAEL,OAAO,EAAG;EACxC;EACA,MAAMM,GAAG,GAAGN,OAAO,CAACO,OAAO,CAAE,WAAY,CAAC;EAC1C,IAAK,CAAED,GAAG,EAAG;IACZ,OAAO,KAAK;EACb;;EAEA;EACA,MAAME,GAAG,GAAGR,OAAO,CAACS,aAAa,CAACC,aAAa,CAC9C,eAAe,GAAGJ,GAAG,CAACK,IAAI,GAAG,IAC9B,CAAC;EACD,OAAO,CAAC,CAAEH,GAAG,IAAIT,SAAS,CAAES,GAAI,CAAC;AAClC;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASI,IAAIA,CAAEC,OAAO,EAAE;EAAEhB,UAAU,GAAG;AAAM,CAAC,GAAG,CAAC,CAAC,EAAG;EAC5D;EACA;EACA;EACA,MAAMiB,QAAQ,GAAGD,OAAO,CAACE,gBAAgB,CAAEnB,aAAa,CAAEC,UAAW,CAAE,CAAC;EAExE,OAAOmB,KAAK,CAACC,IAAI,CAAEH,QAAS,CAAC,CAACI,MAAM,CAAIlB,OAAO,IAAM;IACpD,IAAK,CAAED,SAAS,CAAEC,OAAQ,CAAC,EAAG;MAC7B,OAAO,KAAK;IACb;IAEA,MAAM;MAAEmB;IAAS,CAAC,GAAGnB,OAAO;IAC5B,IAAK,MAAM,KAAKmB,QAAQ,EAAG;MAC1B,OAAOd,oBAAoB,EAC1B,8BAAiCL,OAClC,CAAC;IACF;IAEA,OAAO,IAAI;EACZ,CAAE,CAAC;AACJ"}
|
package/build-module/index.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"names":["focusable","tabbable","focus"],"sources":["@wordpress/dom/src/index.js"],"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"],"mappings":"AAAA;AACA;AACA;AACA,OAAO,KAAKA,SAAS,MAAM,aAAa;AACxC,OAAO,KAAKC,QAAQ,MAAM,YAAY;;AAEtC;AACA;AACA;AACA;AACA,OAAO,MAAMC,KAAK,GAAG;EAAEF,SAAS;EAAEC;AAAS,CAAC;AAE5C,cAAc,OAAO;AACrB,cAAc,oBAAoB;AAClC,cAAc,iBAAiB"}
|