@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
@@ -2,6 +2,7 @@
|
|
2
2
|
* Internal dependencies
|
3
3
|
*/
|
4
4
|
import { assertIsDefined } from '../utils/assert-is-defined';
|
5
|
+
|
5
6
|
/**
|
6
7
|
* Check whether the current document has selected text. This applies to ranges
|
7
8
|
* of text in the document, and not selection inside `<input>` and `<textarea>`
|
@@ -13,7 +14,6 @@ import { assertIsDefined } from '../utils/assert-is-defined';
|
|
13
14
|
*
|
14
15
|
* @return {boolean} True if there is selection, false if not.
|
15
16
|
*/
|
16
|
-
|
17
17
|
export default function documentHasTextSelection(doc) {
|
18
18
|
assertIsDefined(doc.defaultView, 'doc.defaultView');
|
19
19
|
const selection = doc.defaultView.getSelection();
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"names":["assertIsDefined","documentHasTextSelection","doc","defaultView","selection","getSelection","range","rangeCount","getRangeAt","collapsed"],"sources":["@wordpress/dom/src/dom/document-has-text-selection.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { assertIsDefined } from '../utils/assert-is-defined';\n\n/**\n * Check whether the current document has selected text. This applies to ranges\n * of text in the document, and not selection inside `<input>` and `<textarea>`\n * elements.\n *\n * See: https://developer.mozilla.org/en-US/docs/Web/API/Window/getSelection#Related_objects.\n *\n * @param {Document} doc The document to check.\n *\n * @return {boolean} True if there is selection, false if not.\n */\nexport default function documentHasTextSelection( doc ) {\n\tassertIsDefined( doc.defaultView, 'doc.defaultView' );\n\tconst selection = doc.defaultView.getSelection();\n\tassertIsDefined( selection, 'selection' );\n\tconst range = selection.rangeCount ? selection.getRangeAt( 0 ) : null;\n\treturn !! range && ! range.collapsed;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,eAAe,QAAQ,4BAA4B;;AAE5D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,wBAAwBA,CAAEC,GAAG,EAAG;EACvDF,eAAe,CAAEE,GAAG,CAACC,WAAW,EAAE,iBAAkB,CAAC;EACrD,MAAMC,SAAS,GAAGF,GAAG,CAACC,WAAW,CAACE,YAAY,CAAC,CAAC;EAChDL,eAAe,CAAEI,SAAS,EAAE,WAAY,CAAC;EACzC,MAAME,KAAK,GAAGF,SAAS,CAACG,UAAU,GAAGH,SAAS,CAACI,UAAU,CAAE,CAAE,CAAC,GAAG,IAAI;EACrE,OAAO,CAAC,CAAEF,KAAK,IAAI,CAAEA,KAAK,CAACG,SAAS;AACrC"}
|
@@ -3,6 +3,7 @@
|
|
3
3
|
*/
|
4
4
|
import documentHasTextSelection from './document-has-text-selection';
|
5
5
|
import inputFieldHasUncollapsedSelection from './input-field-has-uncollapsed-selection';
|
6
|
+
|
6
7
|
/**
|
7
8
|
* Check whether the current document has any sort of (uncollapsed) selection.
|
8
9
|
* This includes ranges of text across elements and any selection inside
|
@@ -12,7 +13,6 @@ import inputFieldHasUncollapsedSelection from './input-field-has-uncollapsed-sel
|
|
12
13
|
*
|
13
14
|
* @return {boolean} Whether there is any recognizable text selection in the document.
|
14
15
|
*/
|
15
|
-
|
16
16
|
export default function documentHasUncollapsedSelection(doc) {
|
17
17
|
return documentHasTextSelection(doc) || !!doc.activeElement && inputFieldHasUncollapsedSelection(doc.activeElement);
|
18
18
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"names":["documentHasTextSelection","inputFieldHasUncollapsedSelection","documentHasUncollapsedSelection","doc","activeElement"],"sources":["@wordpress/dom/src/dom/document-has-uncollapsed-selection.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport documentHasTextSelection from './document-has-text-selection';\nimport inputFieldHasUncollapsedSelection from './input-field-has-uncollapsed-selection';\n\n/**\n * Check whether the current document has any sort of (uncollapsed) selection.\n * This includes ranges of text across elements and any selection inside\n * textual `<input>` and `<textarea>` elements.\n *\n * @param {Document} doc The document to check.\n *\n * @return {boolean} Whether there is any recognizable text selection in the document.\n */\nexport default function documentHasUncollapsedSelection( doc ) {\n\treturn (\n\t\tdocumentHasTextSelection( doc ) ||\n\t\t( !! doc.activeElement &&\n\t\t\tinputFieldHasUncollapsedSelection( doc.activeElement ) )\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,wBAAwB,MAAM,+BAA+B;AACpE,OAAOC,iCAAiC,MAAM,yCAAyC;;AAEvF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,+BAA+BA,CAAEC,GAAG,EAAG;EAC9D,OACCH,wBAAwB,CAAEG,GAAI,CAAC,IAC7B,CAAC,CAAEA,GAAG,CAACC,aAAa,IACrBH,iCAAiC,CAAEE,GAAG,CAACC,aAAc,CAAG;AAE3D"}
|
@@ -2,13 +2,12 @@
|
|
2
2
|
* Internal dependencies
|
3
3
|
*/
|
4
4
|
import { assertIsDefined } from '../utils/assert-is-defined';
|
5
|
-
/* eslint-disable jsdoc/valid-types */
|
6
5
|
|
6
|
+
/* eslint-disable jsdoc/valid-types */
|
7
7
|
/**
|
8
8
|
* @param {Element} element
|
9
9
|
* @return {ReturnType<Window['getComputedStyle']>} The computed style for the element.
|
10
10
|
*/
|
11
|
-
|
12
11
|
export default function getComputedStyle(element) {
|
13
12
|
/* eslint-enable jsdoc/valid-types */
|
14
13
|
assertIsDefined(element.ownerDocument.defaultView, 'element.ownerDocument.defaultView');
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"names":["assertIsDefined","getComputedStyle","element","ownerDocument","defaultView"],"sources":["@wordpress/dom/src/dom/get-computed-style.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { assertIsDefined } from '../utils/assert-is-defined';\n\n/* eslint-disable jsdoc/valid-types */\n/**\n * @param {Element} element\n * @return {ReturnType<Window['getComputedStyle']>} The computed style for the element.\n */\nexport default function getComputedStyle( element ) {\n\t/* eslint-enable jsdoc/valid-types */\n\tassertIsDefined(\n\t\telement.ownerDocument.defaultView,\n\t\t'element.ownerDocument.defaultView'\n\t);\n\treturn element.ownerDocument.defaultView.getComputedStyle( element );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,eAAe,QAAQ,4BAA4B;;AAE5D;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,gBAAgBA,CAAEC,OAAO,EAAG;EACnD;EACAF,eAAe,CACdE,OAAO,CAACC,aAAa,CAACC,WAAW,EACjC,mCACD,CAAC;EACD,OAAOF,OAAO,CAACC,aAAa,CAACC,WAAW,CAACH,gBAAgB,CAAEC,OAAQ,CAAC;AACrE"}
|
@@ -2,6 +2,7 @@
|
|
2
2
|
* Internal dependencies
|
3
3
|
*/
|
4
4
|
import getComputedStyle from './get-computed-style';
|
5
|
+
|
5
6
|
/**
|
6
7
|
* Returns the closest positioned element, or null under any of the conditions
|
7
8
|
* of the offsetParent specification. Unlike offsetParent, this function is not
|
@@ -13,36 +14,27 @@ import getComputedStyle from './get-computed-style';
|
|
13
14
|
*
|
14
15
|
* @return {Node | null} Offset parent.
|
15
16
|
*/
|
16
|
-
|
17
17
|
export default function getOffsetParent(node) {
|
18
18
|
// Cannot retrieve computed style or offset parent only anything other than
|
19
19
|
// an element node, so find the closest element node.
|
20
20
|
let closestElement;
|
21
|
-
|
22
|
-
while (closestElement =
|
23
|
-
/** @type {Node} */
|
24
|
-
node.parentNode) {
|
21
|
+
while (closestElement = /** @type {Node} */node.parentNode) {
|
25
22
|
if (closestElement.nodeType === closestElement.ELEMENT_NODE) {
|
26
23
|
break;
|
27
24
|
}
|
28
25
|
}
|
29
|
-
|
30
26
|
if (!closestElement) {
|
31
27
|
return null;
|
32
|
-
}
|
33
|
-
// does not otherwise consider the node itself.
|
34
|
-
|
28
|
+
}
|
35
29
|
|
36
|
-
|
37
|
-
|
38
|
-
closestElement).position !== 'static') {
|
30
|
+
// If the closest element is already positioned, return it, as offsetParent
|
31
|
+
// does not otherwise consider the node itself.
|
32
|
+
if (getComputedStyle( /** @type {Element} */closestElement).position !== 'static') {
|
39
33
|
return closestElement;
|
40
|
-
}
|
41
|
-
|
34
|
+
}
|
42
35
|
|
43
|
-
|
44
|
-
|
45
|
-
closestElement.offsetParent
|
36
|
+
// offsetParent is undocumented/draft.
|
37
|
+
return (/** @type {Node & { offsetParent: Node }} */closestElement.offsetParent
|
46
38
|
);
|
47
39
|
}
|
48
40
|
//# sourceMappingURL=get-offset-parent.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"names":["getComputedStyle","getOffsetParent","node","closestElement","parentNode","nodeType","ELEMENT_NODE","position","offsetParent"],"sources":["@wordpress/dom/src/dom/get-offset-parent.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport getComputedStyle from './get-computed-style';\n\n/**\n * Returns the closest positioned element, or null under any of the conditions\n * of the offsetParent specification. Unlike offsetParent, this function is not\n * limited to HTMLElement and accepts any Node (e.g. Node.TEXT_NODE).\n *\n * @see https://drafts.csswg.org/cssom-view/#dom-htmlelement-offsetparent\n *\n * @param {Node} node Node from which to find offset parent.\n *\n * @return {Node | null} Offset parent.\n */\nexport default function getOffsetParent( node ) {\n\t// Cannot retrieve computed style or offset parent only anything other than\n\t// an element node, so find the closest element node.\n\tlet closestElement;\n\twhile ( ( closestElement = /** @type {Node} */ ( node.parentNode ) ) ) {\n\t\tif ( closestElement.nodeType === closestElement.ELEMENT_NODE ) {\n\t\t\tbreak;\n\t\t}\n\t}\n\n\tif ( ! closestElement ) {\n\t\treturn null;\n\t}\n\n\t// If the closest element is already positioned, return it, as offsetParent\n\t// does not otherwise consider the node itself.\n\tif (\n\t\tgetComputedStyle( /** @type {Element} */ ( closestElement ) )\n\t\t\t.position !== 'static'\n\t) {\n\t\treturn closestElement;\n\t}\n\n\t// offsetParent is undocumented/draft.\n\treturn /** @type {Node & { offsetParent: Node }} */ ( closestElement )\n\t\t.offsetParent;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,gBAAgB,MAAM,sBAAsB;;AAEnD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,eAAeA,CAAEC,IAAI,EAAG;EAC/C;EACA;EACA,IAAIC,cAAc;EAClB,OAAUA,cAAc,GAAG,mBAAsBD,IAAI,CAACE,UAAY,EAAK;IACtE,IAAKD,cAAc,CAACE,QAAQ,KAAKF,cAAc,CAACG,YAAY,EAAG;MAC9D;IACD;EACD;EAEA,IAAK,CAAEH,cAAc,EAAG;IACvB,OAAO,IAAI;EACZ;;EAEA;EACA;EACA,IACCH,gBAAgB,EAAE,sBAAyBG,cAAiB,CAAC,CAC3DI,QAAQ,KAAK,QAAQ,EACtB;IACD,OAAOJ,cAAc;EACtB;;EAEA;EACA,OAAO,6CAA+CA,cAAc,CAClEK;EAAY;AACf"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"names":["getRangeHeight","range","rects","Array","from","getClientRects","length","highestTop","Math","min","map","top","lowestBottom","max","bottom"],"sources":["@wordpress/dom/src/dom/get-range-height.js"],"sourcesContent":["/**\n * Gets the height of the range without ignoring zero width rectangles, which\n * some browsers ignore when creating a union.\n *\n * @param {Range} range The range to check.\n * @return {number | undefined} Height of the range or undefined if the range has no client rectangles.\n */\nexport default function getRangeHeight( range ) {\n\tconst rects = Array.from( range.getClientRects() );\n\n\tif ( ! rects.length ) {\n\t\treturn;\n\t}\n\n\tconst highestTop = Math.min( ...rects.map( ( { top } ) => top ) );\n\tconst lowestBottom = Math.max( ...rects.map( ( { bottom } ) => bottom ) );\n\n\treturn lowestBottom - highestTop;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASA,cAAcA,CAAEC,KAAK,EAAG;EAC/C,MAAMC,KAAK,GAAGC,KAAK,CAACC,IAAI,CAAEH,KAAK,CAACI,cAAc,CAAC,CAAE,CAAC;EAElD,IAAK,CAAEH,KAAK,CAACI,MAAM,EAAG;IACrB;EACD;EAEA,MAAMC,UAAU,GAAGC,IAAI,CAACC,GAAG,CAAE,GAAGP,KAAK,CAACQ,GAAG,CAAE,CAAE;IAAEC;EAAI,CAAC,KAAMA,GAAI,CAAE,CAAC;EACjE,MAAMC,YAAY,GAAGJ,IAAI,CAACK,GAAG,CAAE,GAAGX,KAAK,CAACQ,GAAG,CAAE,CAAE;IAAEI;EAAO,CAAC,KAAMA,MAAO,CAAE,CAAC;EAEzE,OAAOF,YAAY,GAAGL,UAAU;AACjC"}
|
@@ -2,6 +2,7 @@
|
|
2
2
|
* Internal dependencies
|
3
3
|
*/
|
4
4
|
import { assertIsDefined } from '../utils/assert-is-defined';
|
5
|
+
|
5
6
|
/**
|
6
7
|
* Get the rectangle of a given Range. Returns `null` if no suitable rectangle
|
7
8
|
* can be found.
|
@@ -10,38 +11,36 @@ import { assertIsDefined } from '../utils/assert-is-defined';
|
|
10
11
|
*
|
11
12
|
* @return {DOMRect?} The rectangle.
|
12
13
|
*/
|
13
|
-
|
14
14
|
export default function getRectangleFromRange(range) {
|
15
15
|
// For uncollapsed ranges, get the rectangle that bounds the contents of the
|
16
16
|
// range; this a rectangle enclosing the union of the bounding rectangles
|
17
17
|
// for all the elements in the range.
|
18
18
|
if (!range.collapsed) {
|
19
|
-
const rects = Array.from(range.getClientRects());
|
19
|
+
const rects = Array.from(range.getClientRects());
|
20
20
|
|
21
|
+
// If there's just a single rect, return it.
|
21
22
|
if (rects.length === 1) {
|
22
23
|
return rects[0];
|
23
|
-
}
|
24
|
-
|
24
|
+
}
|
25
25
|
|
26
|
+
// Ignore tiny selection at the edge of a range.
|
26
27
|
const filteredRects = rects.filter(({
|
27
28
|
width
|
28
|
-
}) => width > 1);
|
29
|
+
}) => width > 1);
|
29
30
|
|
31
|
+
// If it's full of tiny selections, return browser default.
|
30
32
|
if (filteredRects.length === 0) {
|
31
33
|
return range.getBoundingClientRect();
|
32
34
|
}
|
33
|
-
|
34
35
|
if (filteredRects.length === 1) {
|
35
36
|
return filteredRects[0];
|
36
37
|
}
|
37
|
-
|
38
38
|
let {
|
39
39
|
top: furthestTop,
|
40
40
|
bottom: furthestBottom,
|
41
41
|
left: furthestLeft,
|
42
42
|
right: furthestRight
|
43
43
|
} = filteredRects[0];
|
44
|
-
|
45
44
|
for (const {
|
46
45
|
top,
|
47
46
|
bottom,
|
@@ -53,55 +52,51 @@ export default function getRectangleFromRange(range) {
|
|
53
52
|
if (left < furthestLeft) furthestLeft = left;
|
54
53
|
if (right > furthestRight) furthestRight = right;
|
55
54
|
}
|
56
|
-
|
57
55
|
return new window.DOMRect(furthestLeft, furthestTop, furthestRight - furthestLeft, furthestBottom - furthestTop);
|
58
56
|
}
|
59
|
-
|
60
57
|
const {
|
61
58
|
startContainer
|
62
59
|
} = range;
|
63
60
|
const {
|
64
61
|
ownerDocument
|
65
|
-
} = startContainer;
|
62
|
+
} = startContainer;
|
66
63
|
|
64
|
+
// Correct invalid "BR" ranges. The cannot contain any children.
|
67
65
|
if (startContainer.nodeName === 'BR') {
|
68
66
|
const {
|
69
67
|
parentNode
|
70
68
|
} = startContainer;
|
71
69
|
assertIsDefined(parentNode, 'parentNode');
|
72
|
-
const index =
|
73
|
-
/** @type {Node[]} */
|
74
|
-
Array.from(parentNode.childNodes).indexOf(startContainer);
|
70
|
+
const index = /** @type {Node[]} */Array.from(parentNode.childNodes).indexOf(startContainer);
|
75
71
|
assertIsDefined(ownerDocument, 'ownerDocument');
|
76
72
|
range = ownerDocument.createRange();
|
77
73
|
range.setStart(parentNode, index);
|
78
74
|
range.setEnd(parentNode, index);
|
79
75
|
}
|
76
|
+
const rects = range.getClientRects();
|
80
77
|
|
81
|
-
|
78
|
+
// If we have multiple rectangles for a collapsed range, there's no way to
|
82
79
|
// know which it is, so don't return anything.
|
83
|
-
|
84
80
|
if (rects.length > 1) {
|
85
81
|
return null;
|
86
82
|
}
|
83
|
+
let rect = rects[0];
|
87
84
|
|
88
|
-
|
85
|
+
// If the collapsed range starts (and therefore ends) at an element node,
|
89
86
|
// `getClientRects` can be empty in some browsers. This can be resolved
|
90
87
|
// by adding a temporary text node with zero-width space to the range.
|
91
88
|
//
|
92
89
|
// See: https://stackoverflow.com/a/6847328/995445
|
93
|
-
|
94
90
|
if (!rect || rect.height === 0) {
|
95
91
|
assertIsDefined(ownerDocument, 'ownerDocument');
|
96
|
-
const padNode = ownerDocument.createTextNode('\u200b');
|
97
|
-
|
92
|
+
const padNode = ownerDocument.createTextNode('\u200b');
|
93
|
+
// Do not modify the live range.
|
98
94
|
range = range.cloneRange();
|
99
95
|
range.insertNode(padNode);
|
100
96
|
rect = range.getClientRects()[0];
|
101
97
|
assertIsDefined(padNode.parentNode, 'padNode.parentNode');
|
102
98
|
padNode.parentNode.removeChild(padNode);
|
103
99
|
}
|
104
|
-
|
105
100
|
return rect;
|
106
101
|
}
|
107
102
|
//# sourceMappingURL=get-rectangle-from-range.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"names":["assertIsDefined","getRectangleFromRange","range","collapsed","rects","Array","from","getClientRects","length","filteredRects","filter","width","getBoundingClientRect","top","furthestTop","bottom","furthestBottom","left","furthestLeft","right","furthestRight","window","DOMRect","startContainer","ownerDocument","nodeName","parentNode","index","childNodes","indexOf","createRange","setStart","setEnd","rect","height","padNode","createTextNode","cloneRange","insertNode","removeChild"],"sources":["@wordpress/dom/src/dom/get-rectangle-from-range.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { assertIsDefined } from '../utils/assert-is-defined';\n\n/**\n * Get the rectangle of a given Range. Returns `null` if no suitable rectangle\n * can be found.\n *\n * @param {Range} range The range.\n *\n * @return {DOMRect?} The rectangle.\n */\nexport default function getRectangleFromRange( range ) {\n\t// For uncollapsed ranges, get the rectangle that bounds the contents of the\n\t// range; this a rectangle enclosing the union of the bounding rectangles\n\t// for all the elements in the range.\n\tif ( ! range.collapsed ) {\n\t\tconst rects = Array.from( range.getClientRects() );\n\n\t\t// If there's just a single rect, return it.\n\t\tif ( rects.length === 1 ) {\n\t\t\treturn rects[ 0 ];\n\t\t}\n\n\t\t// Ignore tiny selection at the edge of a range.\n\t\tconst filteredRects = rects.filter( ( { width } ) => width > 1 );\n\n\t\t// If it's full of tiny selections, return browser default.\n\t\tif ( filteredRects.length === 0 ) {\n\t\t\treturn range.getBoundingClientRect();\n\t\t}\n\n\t\tif ( filteredRects.length === 1 ) {\n\t\t\treturn filteredRects[ 0 ];\n\t\t}\n\n\t\tlet {\n\t\t\ttop: furthestTop,\n\t\t\tbottom: furthestBottom,\n\t\t\tleft: furthestLeft,\n\t\t\tright: furthestRight,\n\t\t} = filteredRects[ 0 ];\n\n\t\tfor ( const { top, bottom, left, right } of filteredRects ) {\n\t\t\tif ( top < furthestTop ) furthestTop = top;\n\t\t\tif ( bottom > furthestBottom ) furthestBottom = bottom;\n\t\t\tif ( left < furthestLeft ) furthestLeft = left;\n\t\t\tif ( right > furthestRight ) furthestRight = right;\n\t\t}\n\n\t\treturn new window.DOMRect(\n\t\t\tfurthestLeft,\n\t\t\tfurthestTop,\n\t\t\tfurthestRight - furthestLeft,\n\t\t\tfurthestBottom - furthestTop\n\t\t);\n\t}\n\n\tconst { startContainer } = range;\n\tconst { ownerDocument } = startContainer;\n\n\t// Correct invalid \"BR\" ranges. The cannot contain any children.\n\tif ( startContainer.nodeName === 'BR' ) {\n\t\tconst { parentNode } = startContainer;\n\t\tassertIsDefined( parentNode, 'parentNode' );\n\t\tconst index = /** @type {Node[]} */ (\n\t\t\tArray.from( parentNode.childNodes )\n\t\t).indexOf( startContainer );\n\n\t\tassertIsDefined( ownerDocument, 'ownerDocument' );\n\t\trange = ownerDocument.createRange();\n\t\trange.setStart( parentNode, index );\n\t\trange.setEnd( parentNode, index );\n\t}\n\n\tconst rects = range.getClientRects();\n\n\t// If we have multiple rectangles for a collapsed range, there's no way to\n\t// know which it is, so don't return anything.\n\tif ( rects.length > 1 ) {\n\t\treturn null;\n\t}\n\n\tlet rect = rects[ 0 ];\n\n\t// If the collapsed range starts (and therefore ends) at an element node,\n\t// `getClientRects` can be empty in some browsers. This can be resolved\n\t// by adding a temporary text node with zero-width space to the range.\n\t//\n\t// See: https://stackoverflow.com/a/6847328/995445\n\tif ( ! rect || rect.height === 0 ) {\n\t\tassertIsDefined( ownerDocument, 'ownerDocument' );\n\t\tconst padNode = ownerDocument.createTextNode( '\\u200b' );\n\t\t// Do not modify the live range.\n\t\trange = range.cloneRange();\n\t\trange.insertNode( padNode );\n\t\trect = range.getClientRects()[ 0 ];\n\t\tassertIsDefined( padNode.parentNode, 'padNode.parentNode' );\n\t\tpadNode.parentNode.removeChild( padNode );\n\t}\n\n\treturn rect;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,eAAe,QAAQ,4BAA4B;;AAE5D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,qBAAqBA,CAAEC,KAAK,EAAG;EACtD;EACA;EACA;EACA,IAAK,CAAEA,KAAK,CAACC,SAAS,EAAG;IACxB,MAAMC,KAAK,GAAGC,KAAK,CAACC,IAAI,CAAEJ,KAAK,CAACK,cAAc,CAAC,CAAE,CAAC;;IAElD;IACA,IAAKH,KAAK,CAACI,MAAM,KAAK,CAAC,EAAG;MACzB,OAAOJ,KAAK,CAAE,CAAC,CAAE;IAClB;;IAEA;IACA,MAAMK,aAAa,GAAGL,KAAK,CAACM,MAAM,CAAE,CAAE;MAAEC;IAAM,CAAC,KAAMA,KAAK,GAAG,CAAE,CAAC;;IAEhE;IACA,IAAKF,aAAa,CAACD,MAAM,KAAK,CAAC,EAAG;MACjC,OAAON,KAAK,CAACU,qBAAqB,CAAC,CAAC;IACrC;IAEA,IAAKH,aAAa,CAACD,MAAM,KAAK,CAAC,EAAG;MACjC,OAAOC,aAAa,CAAE,CAAC,CAAE;IAC1B;IAEA,IAAI;MACHI,GAAG,EAAEC,WAAW;MAChBC,MAAM,EAAEC,cAAc;MACtBC,IAAI,EAAEC,YAAY;MAClBC,KAAK,EAAEC;IACR,CAAC,GAAGX,aAAa,CAAE,CAAC,CAAE;IAEtB,KAAM,MAAM;MAAEI,GAAG;MAAEE,MAAM;MAAEE,IAAI;MAAEE;IAAM,CAAC,IAAIV,aAAa,EAAG;MAC3D,IAAKI,GAAG,GAAGC,WAAW,EAAGA,WAAW,GAAGD,GAAG;MAC1C,IAAKE,MAAM,GAAGC,cAAc,EAAGA,cAAc,GAAGD,MAAM;MACtD,IAAKE,IAAI,GAAGC,YAAY,EAAGA,YAAY,GAAGD,IAAI;MAC9C,IAAKE,KAAK,GAAGC,aAAa,EAAGA,aAAa,GAAGD,KAAK;IACnD;IAEA,OAAO,IAAIE,MAAM,CAACC,OAAO,CACxBJ,YAAY,EACZJ,WAAW,EACXM,aAAa,GAAGF,YAAY,EAC5BF,cAAc,GAAGF,WAClB,CAAC;EACF;EAEA,MAAM;IAAES;EAAe,CAAC,GAAGrB,KAAK;EAChC,MAAM;IAAEsB;EAAc,CAAC,GAAGD,cAAc;;EAExC;EACA,IAAKA,cAAc,CAACE,QAAQ,KAAK,IAAI,EAAG;IACvC,MAAM;MAAEC;IAAW,CAAC,GAAGH,cAAc;IACrCvB,eAAe,CAAE0B,UAAU,EAAE,YAAa,CAAC;IAC3C,MAAMC,KAAK,GAAG,qBACbtB,KAAK,CAACC,IAAI,CAAEoB,UAAU,CAACE,UAAW,CAAC,CAClCC,OAAO,CAAEN,cAAe,CAAC;IAE3BvB,eAAe,CAAEwB,aAAa,EAAE,eAAgB,CAAC;IACjDtB,KAAK,GAAGsB,aAAa,CAACM,WAAW,CAAC,CAAC;IACnC5B,KAAK,CAAC6B,QAAQ,CAAEL,UAAU,EAAEC,KAAM,CAAC;IACnCzB,KAAK,CAAC8B,MAAM,CAAEN,UAAU,EAAEC,KAAM,CAAC;EAClC;EAEA,MAAMvB,KAAK,GAAGF,KAAK,CAACK,cAAc,CAAC,CAAC;;EAEpC;EACA;EACA,IAAKH,KAAK,CAACI,MAAM,GAAG,CAAC,EAAG;IACvB,OAAO,IAAI;EACZ;EAEA,IAAIyB,IAAI,GAAG7B,KAAK,CAAE,CAAC,CAAE;;EAErB;EACA;EACA;EACA;EACA;EACA,IAAK,CAAE6B,IAAI,IAAIA,IAAI,CAACC,MAAM,KAAK,CAAC,EAAG;IAClClC,eAAe,CAAEwB,aAAa,EAAE,eAAgB,CAAC;IACjD,MAAMW,OAAO,GAAGX,aAAa,CAACY,cAAc,CAAE,QAAS,CAAC;IACxD;IACAlC,KAAK,GAAGA,KAAK,CAACmC,UAAU,CAAC,CAAC;IAC1BnC,KAAK,CAACoC,UAAU,CAAEH,OAAQ,CAAC;IAC3BF,IAAI,GAAG/B,KAAK,CAACK,cAAc,CAAC,CAAC,CAAE,CAAC,CAAE;IAClCP,eAAe,CAAEmC,OAAO,CAACT,UAAU,EAAE,oBAAqB,CAAC;IAC3DS,OAAO,CAACT,UAAU,CAACa,WAAW,CAAEJ,OAAQ,CAAC;EAC1C;EAEA,OAAOF,IAAI;AACZ"}
|
@@ -2,6 +2,7 @@
|
|
2
2
|
* Internal dependencies
|
3
3
|
*/
|
4
4
|
import getComputedStyle from './get-computed-style';
|
5
|
+
|
5
6
|
/**
|
6
7
|
* Given a DOM node, finds the closest scrollable container node or the node
|
7
8
|
* itself, if scrollable.
|
@@ -11,12 +12,10 @@ import getComputedStyle from './get-computed-style';
|
|
11
12
|
* Defaults to 'vertical'.
|
12
13
|
* @return {Element | undefined} Scrollable container node, if found.
|
13
14
|
*/
|
14
|
-
|
15
15
|
export default function getScrollContainer(node, direction = 'vertical') {
|
16
16
|
if (!node) {
|
17
17
|
return undefined;
|
18
18
|
}
|
19
|
-
|
20
19
|
if (direction === 'vertical' || direction === 'all') {
|
21
20
|
// Scrollable if scrollable height exceeds displayed...
|
22
21
|
if (node.scrollHeight > node.clientHeight) {
|
@@ -24,13 +23,11 @@ export default function getScrollContainer(node, direction = 'vertical') {
|
|
24
23
|
const {
|
25
24
|
overflowY
|
26
25
|
} = getComputedStyle(node);
|
27
|
-
|
28
26
|
if (/(auto|scroll)/.test(overflowY)) {
|
29
27
|
return node;
|
30
28
|
}
|
31
29
|
}
|
32
30
|
}
|
33
|
-
|
34
31
|
if (direction === 'horizontal' || direction === 'all') {
|
35
32
|
// Scrollable if scrollable width exceeds displayed...
|
36
33
|
if (node.scrollWidth > node.clientWidth) {
|
@@ -38,20 +35,16 @@ export default function getScrollContainer(node, direction = 'vertical') {
|
|
38
35
|
const {
|
39
36
|
overflowX
|
40
37
|
} = getComputedStyle(node);
|
41
|
-
|
42
38
|
if (/(auto|scroll)/.test(overflowX)) {
|
43
39
|
return node;
|
44
40
|
}
|
45
41
|
}
|
46
42
|
}
|
47
|
-
|
48
43
|
if (node.ownerDocument === node.parentNode) {
|
49
44
|
return node;
|
50
|
-
}
|
51
|
-
|
45
|
+
}
|
52
46
|
|
53
|
-
|
54
|
-
/** @type {Element} */
|
55
|
-
node.parentNode, direction);
|
47
|
+
// Continue traversing.
|
48
|
+
return getScrollContainer( /** @type {Element} */node.parentNode, direction);
|
56
49
|
}
|
57
50
|
//# sourceMappingURL=get-scroll-container.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"names":["getComputedStyle","getScrollContainer","node","direction","undefined","scrollHeight","clientHeight","overflowY","test","scrollWidth","clientWidth","overflowX","ownerDocument","parentNode"],"sources":["@wordpress/dom/src/dom/get-scroll-container.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport getComputedStyle from './get-computed-style';\n\n/**\n * Given a DOM node, finds the closest scrollable container node or the node\n * itself, if scrollable.\n *\n * @param {Element | null} node Node from which to start.\n * @param {?string} direction Direction of scrollable container to search for ('vertical', 'horizontal', 'all').\n * Defaults to 'vertical'.\n * @return {Element | undefined} Scrollable container node, if found.\n */\nexport default function getScrollContainer( node, direction = 'vertical' ) {\n\tif ( ! node ) {\n\t\treturn undefined;\n\t}\n\n\tif ( direction === 'vertical' || direction === 'all' ) {\n\t\t// Scrollable if scrollable height exceeds displayed...\n\t\tif ( node.scrollHeight > node.clientHeight ) {\n\t\t\t// ...except when overflow is defined to be hidden or visible\n\t\t\tconst { overflowY } = getComputedStyle( node );\n\n\t\t\tif ( /(auto|scroll)/.test( overflowY ) ) {\n\t\t\t\treturn node;\n\t\t\t}\n\t\t}\n\t}\n\n\tif ( direction === 'horizontal' || direction === 'all' ) {\n\t\t// Scrollable if scrollable width exceeds displayed...\n\t\tif ( node.scrollWidth > node.clientWidth ) {\n\t\t\t// ...except when overflow is defined to be hidden or visible\n\t\t\tconst { overflowX } = getComputedStyle( node );\n\n\t\t\tif ( /(auto|scroll)/.test( overflowX ) ) {\n\t\t\t\treturn node;\n\t\t\t}\n\t\t}\n\t}\n\n\tif ( node.ownerDocument === node.parentNode ) {\n\t\treturn node;\n\t}\n\n\t// Continue traversing.\n\treturn getScrollContainer(\n\t\t/** @type {Element} */ ( node.parentNode ),\n\t\tdirection\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,gBAAgB,MAAM,sBAAsB;;AAEnD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,kBAAkBA,CAAEC,IAAI,EAAEC,SAAS,GAAG,UAAU,EAAG;EAC1E,IAAK,CAAED,IAAI,EAAG;IACb,OAAOE,SAAS;EACjB;EAEA,IAAKD,SAAS,KAAK,UAAU,IAAIA,SAAS,KAAK,KAAK,EAAG;IACtD;IACA,IAAKD,IAAI,CAACG,YAAY,GAAGH,IAAI,CAACI,YAAY,EAAG;MAC5C;MACA,MAAM;QAAEC;MAAU,CAAC,GAAGP,gBAAgB,CAAEE,IAAK,CAAC;MAE9C,IAAK,eAAe,CAACM,IAAI,CAAED,SAAU,CAAC,EAAG;QACxC,OAAOL,IAAI;MACZ;IACD;EACD;EAEA,IAAKC,SAAS,KAAK,YAAY,IAAIA,SAAS,KAAK,KAAK,EAAG;IACxD;IACA,IAAKD,IAAI,CAACO,WAAW,GAAGP,IAAI,CAACQ,WAAW,EAAG;MAC1C;MACA,MAAM;QAAEC;MAAU,CAAC,GAAGX,gBAAgB,CAAEE,IAAK,CAAC;MAE9C,IAAK,eAAe,CAACM,IAAI,CAAEG,SAAU,CAAC,EAAG;QACxC,OAAOT,IAAI;MACZ;IACD;EACD;EAEA,IAAKA,IAAI,CAACU,aAAa,KAAKV,IAAI,CAACW,UAAU,EAAG;IAC7C,OAAOX,IAAI;EACZ;;EAEA;EACA,OAAOD,kBAAkB,EACxB,sBAAyBC,IAAI,CAACW,UAAU,EACxCV,SACD,CAAC;AACF"}
|
@@ -3,6 +3,7 @@
|
|
3
3
|
*/
|
4
4
|
import caretRangeFromPoint from './caret-range-from-point';
|
5
5
|
import getComputedStyle from './get-computed-style';
|
6
|
+
|
6
7
|
/**
|
7
8
|
* Get a collapsed range for a given point.
|
8
9
|
* Gives the container a temporary high z-index (above any UI).
|
@@ -15,18 +16,17 @@ import getComputedStyle from './get-computed-style';
|
|
15
16
|
*
|
16
17
|
* @return {?Range} The best range for the given point.
|
17
18
|
*/
|
18
|
-
|
19
19
|
export default function hiddenCaretRangeFromPoint(doc, x, y, container) {
|
20
20
|
const originalZIndex = container.style.zIndex;
|
21
21
|
const originalPosition = container.style.position;
|
22
22
|
const {
|
23
23
|
position = 'static'
|
24
|
-
} = getComputedStyle(container);
|
24
|
+
} = getComputedStyle(container);
|
25
25
|
|
26
|
+
// A z-index only works if the element position is not static.
|
26
27
|
if (position === 'static') {
|
27
28
|
container.style.position = 'relative';
|
28
29
|
}
|
29
|
-
|
30
30
|
container.style.zIndex = '10000';
|
31
31
|
const range = caretRangeFromPoint(doc, x, y);
|
32
32
|
container.style.zIndex = originalZIndex;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"names":["caretRangeFromPoint","getComputedStyle","hiddenCaretRangeFromPoint","doc","x","y","container","originalZIndex","style","zIndex","originalPosition","position","range"],"sources":["@wordpress/dom/src/dom/hidden-caret-range-from-point.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport caretRangeFromPoint from './caret-range-from-point';\nimport getComputedStyle from './get-computed-style';\n\n/**\n * Get a collapsed range for a given point.\n * Gives the container a temporary high z-index (above any UI).\n * This is preferred over getting the UI nodes and set styles there.\n *\n * @param {Document} 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 * @param {HTMLElement} container Container in which the range is expected to be found.\n *\n * @return {?Range} The best range for the given point.\n */\nexport default function hiddenCaretRangeFromPoint( doc, x, y, container ) {\n\tconst originalZIndex = container.style.zIndex;\n\tconst originalPosition = container.style.position;\n\n\tconst { position = 'static' } = getComputedStyle( container );\n\n\t// A z-index only works if the element position is not static.\n\tif ( position === 'static' ) {\n\t\tcontainer.style.position = 'relative';\n\t}\n\n\tcontainer.style.zIndex = '10000';\n\n\tconst range = caretRangeFromPoint( doc, x, y );\n\n\tcontainer.style.zIndex = originalZIndex;\n\tcontainer.style.position = originalPosition;\n\n\treturn range;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,mBAAmB,MAAM,0BAA0B;AAC1D,OAAOC,gBAAgB,MAAM,sBAAsB;;AAEnD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,yBAAyBA,CAAEC,GAAG,EAAEC,CAAC,EAAEC,CAAC,EAAEC,SAAS,EAAG;EACzE,MAAMC,cAAc,GAAGD,SAAS,CAACE,KAAK,CAACC,MAAM;EAC7C,MAAMC,gBAAgB,GAAGJ,SAAS,CAACE,KAAK,CAACG,QAAQ;EAEjD,MAAM;IAAEA,QAAQ,GAAG;EAAS,CAAC,GAAGV,gBAAgB,CAAEK,SAAU,CAAC;;EAE7D;EACA,IAAKK,QAAQ,KAAK,QAAQ,EAAG;IAC5BL,SAAS,CAACE,KAAK,CAACG,QAAQ,GAAG,UAAU;EACtC;EAEAL,SAAS,CAACE,KAAK,CAACC,MAAM,GAAG,OAAO;EAEhC,MAAMG,KAAK,GAAGZ,mBAAmB,CAAEG,GAAG,EAAEC,CAAC,EAAEC,CAAE,CAAC;EAE9CC,SAAS,CAACE,KAAK,CAACC,MAAM,GAAGF,cAAc;EACvCD,SAAS,CAACE,KAAK,CAACG,QAAQ,GAAGD,gBAAgB;EAE3C,OAAOE,KAAK;AACb"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"names":["default","computeCaretRect","documentHasTextSelection","documentHasUncollapsedSelection","documentHasSelection","getRectangleFromRange","getScrollContainer","getOffsetParent","isEntirelySelected","isFormElement","isHorizontalEdge","isNumberInput","isTextField","isVerticalEdge","placeCaretAtHorizontalEdge","placeCaretAtVerticalEdge","replace","remove","insertAfter","unwrap","replaceTag","wrap","__unstableStripHTML","isEmpty","removeInvalidHTML","isRTL","safeHTML"],"sources":["@wordpress/dom/src/dom/index.js"],"sourcesContent":["export { default as computeCaretRect } from './compute-caret-rect';\nexport { default as documentHasTextSelection } from './document-has-text-selection';\nexport { default as documentHasUncollapsedSelection } from './document-has-uncollapsed-selection';\nexport { default as documentHasSelection } from './document-has-selection';\nexport { default as getRectangleFromRange } from './get-rectangle-from-range';\nexport { default as getScrollContainer } from './get-scroll-container';\nexport { default as getOffsetParent } from './get-offset-parent';\nexport { default as isEntirelySelected } from './is-entirely-selected';\nexport { default as isFormElement } from './is-form-element';\nexport { default as isHorizontalEdge } from './is-horizontal-edge';\nexport { default as isNumberInput } from './is-number-input';\nexport { default as isTextField } from './is-text-field';\nexport { default as isVerticalEdge } from './is-vertical-edge';\nexport { default as placeCaretAtHorizontalEdge } from './place-caret-at-horizontal-edge';\nexport { default as placeCaretAtVerticalEdge } from './place-caret-at-vertical-edge';\nexport { default as replace } from './replace';\nexport { default as remove } from './remove';\nexport { default as insertAfter } from './insert-after';\nexport { default as unwrap } from './unwrap';\nexport { default as replaceTag } from './replace-tag';\nexport { default as wrap } from './wrap';\nexport { default as __unstableStripHTML } from './strip-html';\nexport { default as isEmpty } from './is-empty';\nexport { default as removeInvalidHTML } from './remove-invalid-html';\nexport { default as isRTL } from './is-rtl';\nexport { default as safeHTML } from './safe-html';\n"],"mappings":"AAAA,SAASA,OAAO,IAAIC,gBAAgB,QAAQ,sBAAsB;AAClE,SAASD,OAAO,IAAIE,wBAAwB,QAAQ,+BAA+B;AACnF,SAASF,OAAO,IAAIG,+BAA+B,QAAQ,sCAAsC;AACjG,SAASH,OAAO,IAAII,oBAAoB,QAAQ,0BAA0B;AAC1E,SAASJ,OAAO,IAAIK,qBAAqB,QAAQ,4BAA4B;AAC7E,SAASL,OAAO,IAAIM,kBAAkB,QAAQ,wBAAwB;AACtE,SAASN,OAAO,IAAIO,eAAe,QAAQ,qBAAqB;AAChE,SAASP,OAAO,IAAIQ,kBAAkB,QAAQ,wBAAwB;AACtE,SAASR,OAAO,IAAIS,aAAa,QAAQ,mBAAmB;AAC5D,SAAST,OAAO,IAAIU,gBAAgB,QAAQ,sBAAsB;AAClE,SAASV,OAAO,IAAIW,aAAa,QAAQ,mBAAmB;AAC5D,SAASX,OAAO,IAAIY,WAAW,QAAQ,iBAAiB;AACxD,SAASZ,OAAO,IAAIa,cAAc,QAAQ,oBAAoB;AAC9D,SAASb,OAAO,IAAIc,0BAA0B,QAAQ,kCAAkC;AACxF,SAASd,OAAO,IAAIe,wBAAwB,QAAQ,gCAAgC;AACpF,SAASf,OAAO,IAAIgB,OAAO,QAAQ,WAAW;AAC9C,SAAShB,OAAO,IAAIiB,MAAM,QAAQ,UAAU;AAC5C,SAASjB,OAAO,IAAIkB,WAAW,QAAQ,gBAAgB;AACvD,SAASlB,OAAO,IAAImB,MAAM,QAAQ,UAAU;AAC5C,SAASnB,OAAO,IAAIoB,UAAU,QAAQ,eAAe;AACrD,SAASpB,OAAO,IAAIqB,IAAI,QAAQ,QAAQ;AACxC,SAASrB,OAAO,IAAIsB,mBAAmB,QAAQ,cAAc;AAC7D,SAAStB,OAAO,IAAIuB,OAAO,QAAQ,YAAY;AAC/C,SAASvB,OAAO,IAAIwB,iBAAiB,QAAQ,uBAAuB;AACpE,SAASxB,OAAO,IAAIyB,KAAK,QAAQ,UAAU;AAC3C,SAASzB,OAAO,IAAI0B,QAAQ,QAAQ,aAAa"}
|
@@ -3,6 +3,7 @@
|
|
3
3
|
*/
|
4
4
|
import isTextField from './is-text-field';
|
5
5
|
import isHTMLInputElement from './is-html-input-element';
|
6
|
+
|
6
7
|
/**
|
7
8
|
* Check whether the given input field or textarea contains a (uncollapsed)
|
8
9
|
* selection of text.
|
@@ -20,26 +21,25 @@ import isHTMLInputElement from './is-html-input-element';
|
|
20
21
|
*
|
21
22
|
* @return {boolean} Whether the input/textareaa element has some "selection".
|
22
23
|
*/
|
23
|
-
|
24
24
|
export default function inputFieldHasUncollapsedSelection(element) {
|
25
25
|
if (!isHTMLInputElement(element) && !isTextField(element)) {
|
26
26
|
return false;
|
27
|
-
}
|
27
|
+
}
|
28
|
+
|
29
|
+
// Safari throws a type error when trying to get `selectionStart` and
|
28
30
|
// `selectionEnd` on non-text <input> elements, so a try/catch construct is
|
29
31
|
// necessary.
|
30
|
-
|
31
|
-
|
32
32
|
try {
|
33
33
|
const {
|
34
34
|
selectionStart,
|
35
35
|
selectionEnd
|
36
|
-
} =
|
37
|
-
|
38
|
-
|
39
|
-
return (// `null` means the input type doesn't implement selection, thus we
|
36
|
+
} = /** @type {HTMLInputElement | HTMLTextAreaElement} */element;
|
37
|
+
return (
|
38
|
+
// `null` means the input type doesn't implement selection, thus we
|
40
39
|
// cannot determine whether the selection is collapsed, so we
|
41
40
|
// default to true.
|
42
|
-
selectionStart === null ||
|
41
|
+
selectionStart === null ||
|
42
|
+
// when not null, compare the two points
|
43
43
|
selectionStart !== selectionEnd
|
44
44
|
);
|
45
45
|
} catch (error) {
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"names":["isTextField","isHTMLInputElement","inputFieldHasUncollapsedSelection","element","selectionStart","selectionEnd","error"],"sources":["@wordpress/dom/src/dom/input-field-has-uncollapsed-selection.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport isTextField from './is-text-field';\nimport isHTMLInputElement from './is-html-input-element';\n\n/**\n * Check whether the given input field or textarea contains a (uncollapsed)\n * selection of text.\n *\n * CAVEAT: Only specific text-based HTML inputs support the selection APIs\n * needed to determine whether they have a collapsed or uncollapsed selection.\n * This function defaults to returning `true` when the selection cannot be\n * inspected, such as with `<input type=\"time\">`. The rationale is that this\n * should cause the block editor to defer to the browser's native selection\n * handling (e.g. copying and pasting), thereby reducing friction for the user.\n *\n * See: https://html.spec.whatwg.org/multipage/input.html#do-not-apply\n *\n * @param {Element} element The HTML element.\n *\n * @return {boolean} Whether the input/textareaa element has some \"selection\".\n */\nexport default function inputFieldHasUncollapsedSelection( element ) {\n\tif ( ! isHTMLInputElement( element ) && ! isTextField( element ) ) {\n\t\treturn false;\n\t}\n\n\t// Safari throws a type error when trying to get `selectionStart` and\n\t// `selectionEnd` on non-text <input> elements, so a try/catch construct is\n\t// necessary.\n\ttry {\n\t\tconst { selectionStart, selectionEnd } =\n\t\t\t/** @type {HTMLInputElement | HTMLTextAreaElement} */ ( element );\n\t\treturn (\n\t\t\t// `null` means the input type doesn't implement selection, thus we\n\t\t\t// cannot determine whether the selection is collapsed, so we\n\t\t\t// default to true.\n\t\t\tselectionStart === null ||\n\t\t\t// when not null, compare the two points\n\t\t\tselectionStart !== selectionEnd\n\t\t);\n\t} catch ( error ) {\n\t\t// This is Safari's way of saying that the input type doesn't implement\n\t\t// selection, so we default to true.\n\t\treturn true;\n\t}\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,WAAW,MAAM,iBAAiB;AACzC,OAAOC,kBAAkB,MAAM,yBAAyB;;AAExD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,iCAAiCA,CAAEC,OAAO,EAAG;EACpE,IAAK,CAAEF,kBAAkB,CAAEE,OAAQ,CAAC,IAAI,CAAEH,WAAW,CAAEG,OAAQ,CAAC,EAAG;IAClE,OAAO,KAAK;EACb;;EAEA;EACA;EACA;EACA,IAAI;IACH,MAAM;MAAEC,cAAc;MAAEC;IAAa,CAAC,GACrC,qDAAwDF,OAAS;IAClE;MACC;MACA;MACA;MACAC,cAAc,KAAK,IAAI;MACvB;MACAA,cAAc,KAAKC;IAAY;EAEjC,CAAC,CAAC,OAAQC,KAAK,EAAG;IACjB;IACA;IACA,OAAO,IAAI;EACZ;AACD"}
|
@@ -2,6 +2,7 @@
|
|
2
2
|
* Internal dependencies
|
3
3
|
*/
|
4
4
|
import { assertIsDefined } from '../utils/assert-is-defined';
|
5
|
+
|
5
6
|
/**
|
6
7
|
* Given two DOM nodes, inserts the former in the DOM as the next sibling of
|
7
8
|
* the latter.
|
@@ -10,7 +11,6 @@ import { assertIsDefined } from '../utils/assert-is-defined';
|
|
10
11
|
* @param {Node} referenceNode Node after which to perform the insertion.
|
11
12
|
* @return {void}
|
12
13
|
*/
|
13
|
-
|
14
14
|
export default function insertAfter(newNode, referenceNode) {
|
15
15
|
assertIsDefined(referenceNode.parentNode, 'referenceNode.parentNode');
|
16
16
|
referenceNode.parentNode.insertBefore(newNode, referenceNode.nextSibling);
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"
|
1
|
+
{"version":3,"names":["assertIsDefined","insertAfter","newNode","referenceNode","parentNode","insertBefore","nextSibling"],"sources":["@wordpress/dom/src/dom/insert-after.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { assertIsDefined } from '../utils/assert-is-defined';\n\n/**\n * Given two DOM nodes, inserts the former in the DOM as the next sibling of\n * the latter.\n *\n * @param {Node} newNode Node to be inserted.\n * @param {Node} referenceNode Node after which to perform the insertion.\n * @return {void}\n */\nexport default function insertAfter( newNode, referenceNode ) {\n\tassertIsDefined( referenceNode.parentNode, 'referenceNode.parentNode' );\n\treferenceNode.parentNode.insertBefore( newNode, referenceNode.nextSibling );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,eAAe,QAAQ,4BAA4B;;AAE5D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,WAAWA,CAAEC,OAAO,EAAEC,aAAa,EAAG;EAC7DH,eAAe,CAAEG,aAAa,CAACC,UAAU,EAAE,0BAA2B,CAAC;EACvED,aAAa,CAACC,UAAU,CAACC,YAAY,CAAEH,OAAO,EAAEC,aAAa,CAACG,WAAY,CAAC;AAC5E"}
|