@wordpress/dom 4.51.0 → 4.52.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 +2 -0
- package/build/dom/is-edge.cjs +5 -0
- package/build/dom/is-edge.cjs.map +2 -2
- package/build-module/dom/is-edge.mjs +5 -0
- package/build-module/dom/is-edge.mjs.map +2 -2
- package/build-types/dom/is-edge.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/dom/is-edge.js +26 -0
package/CHANGELOG.md
CHANGED
package/build/dom/is-edge.cjs
CHANGED
|
@@ -81,6 +81,11 @@ function isEdge(container, isReverse, onlyVertical = false) {
|
|
|
81
81
|
const containerRect = container.getBoundingClientRect();
|
|
82
82
|
const x = isReverseDir ? containerRect.left + 1 : containerRect.right - 1;
|
|
83
83
|
const y = isReverse ? containerRect.top + 1 : containerRect.bottom - 1;
|
|
84
|
+
const isFarFromVerticalEdge = (y < 0 || y > defaultView.innerHeight) && rangeRect.top >= 0 && rangeRect.bottom <= defaultView.innerHeight;
|
|
85
|
+
const isFarFromHorizontalEdge = (x < 0 || x > defaultView.innerWidth) && rangeRect.left >= 0 && rangeRect.right <= defaultView.innerWidth;
|
|
86
|
+
if (isFarFromVerticalEdge || !onlyVertical && isFarFromHorizontalEdge) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
84
89
|
const testRange = (0, import_scroll_if_no_range.scrollIfNoRange)(
|
|
85
90
|
container,
|
|
86
91
|
isReverse,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/dom/is-edge.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport isRTL from './is-rtl';\nimport getRangeHeight from './get-range-height';\nimport getRectangleFromRange from './get-rectangle-from-range';\nimport isSelectionForward from './is-selection-forward';\nimport hiddenCaretRangeFromPoint from './hidden-caret-range-from-point';\nimport { assertIsDefined } from '../utils/assert-is-defined';\nimport isInputOrTextArea from './is-input-or-text-area';\nimport { scrollIfNoRange } from './scroll-if-no-range';\n\n/**\n * Check whether the selection is at the edge of the container. Checks for\n * horizontal position by default. Set `onlyVertical` to true to check only\n * vertically.\n *\n * @param {HTMLElement} container Focusable element.\n * @param {boolean} isReverse Set to true to check left, false to check right.\n * @param {boolean} [onlyVertical=false] Set to true to check only vertical position.\n *\n * @return {boolean} True if at the edge, false if not.\n */\nexport default function isEdge( container, isReverse, onlyVertical = false ) {\n\tif (\n\t\tisInputOrTextArea( container ) &&\n\t\ttypeof container.selectionStart === 'number'\n\t) {\n\t\tif ( container.selectionStart !== container.selectionEnd ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif ( isReverse ) {\n\t\t\treturn container.selectionStart === 0;\n\t\t}\n\n\t\treturn container.value.length === container.selectionStart;\n\t}\n\n\tif ( ! container.isContentEditable ) {\n\t\treturn true;\n\t}\n\n\tconst { ownerDocument } = container;\n\tconst { defaultView } = ownerDocument;\n\n\tassertIsDefined( defaultView, 'defaultView' );\n\tconst selection = defaultView.getSelection();\n\n\tif ( ! selection || ! selection.rangeCount ) {\n\t\treturn false;\n\t}\n\n\tconst range = selection.getRangeAt( 0 );\n\tconst collapsedRange = range.cloneRange();\n\tconst isForward = isSelectionForward( selection );\n\tconst isCollapsed = selection.isCollapsed;\n\n\t// Collapse in direction of selection.\n\tif ( ! isCollapsed ) {\n\t\tcollapsedRange.collapse( ! isForward );\n\t}\n\n\tconst collapsedRangeRect = getRectangleFromRange( collapsedRange );\n\tconst rangeRect = getRectangleFromRange( range );\n\n\tif ( ! collapsedRangeRect || ! rangeRect ) {\n\t\treturn false;\n\t}\n\n\t// Only consider the multiline selection at the edge if the direction is\n\t// towards the edge. The selection is multiline if it is taller than the\n\t// collapsed selection.\n\tconst rangeHeight = getRangeHeight( range );\n\tif (\n\t\t! isCollapsed &&\n\t\trangeHeight &&\n\t\trangeHeight > collapsedRangeRect.height &&\n\t\tisForward === isReverse\n\t) {\n\t\treturn false;\n\t}\n\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\n\t// To check if a selection is at the edge, we insert a test selection at the\n\t// edge of the container and check if the selections have the same vertical\n\t// or horizontal position. If they do, the selection is at the edge.\n\t// This method proves to be better than a DOM-based calculation for the\n\t// horizontal edge, since it ignores empty textnodes and a trailing line\n\t// break element. In other words, we need to check visual positioning, not\n\t// DOM positioning.\n\t// It also proves better than using the computed style for the vertical\n\t// edge, because we cannot know the padding and line height reliably in\n\t// pixels. `getComputedStyle` may return a value with different units.\n\tconst x = isReverseDir ? containerRect.left + 1 : containerRect.right - 1;\n\tconst y = isReverse ? containerRect.top + 1 : containerRect.bottom - 1;\n\tconst testRange = scrollIfNoRange( container, isReverse, () =>\n\t\thiddenCaretRangeFromPoint( ownerDocument, x, y, container )\n\t);\n\n\tif ( ! testRange ) {\n\t\treturn false;\n\t}\n\n\tconst testRect = getRectangleFromRange( testRange );\n\n\tif ( ! testRect ) {\n\t\treturn false;\n\t}\n\n\tconst verticalSide = isReverse ? 'top' : 'bottom';\n\tconst horizontalSide = isReverseDir ? 'left' : 'right';\n\tconst verticalDiff = testRect[ verticalSide ] - rangeRect[ verticalSide ];\n\tconst horizontalDiff =\n\t\ttestRect[ horizontalSide ] - collapsedRangeRect[ horizontalSide ];\n\n\t// Allow the position to be 1px off.\n\tconst hasVerticalDiff = Math.abs( verticalDiff ) <= 1;\n\tconst hasHorizontalDiff = Math.abs( horizontalDiff ) <= 1;\n\n\treturn onlyVertical\n\t\t? hasVerticalDiff\n\t\t: hasVerticalDiff && hasHorizontalDiff;\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAAkB;AAClB,8BAA2B;AAC3B,sCAAkC;AAClC,kCAA+B;AAC/B,2CAAsC;AACtC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S;
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport isRTL from './is-rtl';\nimport getRangeHeight from './get-range-height';\nimport getRectangleFromRange from './get-rectangle-from-range';\nimport isSelectionForward from './is-selection-forward';\nimport hiddenCaretRangeFromPoint from './hidden-caret-range-from-point';\nimport { assertIsDefined } from '../utils/assert-is-defined';\nimport isInputOrTextArea from './is-input-or-text-area';\nimport { scrollIfNoRange } from './scroll-if-no-range';\n\n/**\n * Check whether the selection is at the edge of the container. Checks for\n * horizontal position by default. Set `onlyVertical` to true to check only\n * vertically.\n *\n * @param {HTMLElement} container Focusable element.\n * @param {boolean} isReverse Set to true to check left, false to check right.\n * @param {boolean} [onlyVertical=false] Set to true to check only vertical position.\n *\n * @return {boolean} True if at the edge, false if not.\n */\nexport default function isEdge( container, isReverse, onlyVertical = false ) {\n\tif (\n\t\tisInputOrTextArea( container ) &&\n\t\ttypeof container.selectionStart === 'number'\n\t) {\n\t\tif ( container.selectionStart !== container.selectionEnd ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif ( isReverse ) {\n\t\t\treturn container.selectionStart === 0;\n\t\t}\n\n\t\treturn container.value.length === container.selectionStart;\n\t}\n\n\tif ( ! container.isContentEditable ) {\n\t\treturn true;\n\t}\n\n\tconst { ownerDocument } = container;\n\tconst { defaultView } = ownerDocument;\n\n\tassertIsDefined( defaultView, 'defaultView' );\n\tconst selection = defaultView.getSelection();\n\n\tif ( ! selection || ! selection.rangeCount ) {\n\t\treturn false;\n\t}\n\n\tconst range = selection.getRangeAt( 0 );\n\tconst collapsedRange = range.cloneRange();\n\tconst isForward = isSelectionForward( selection );\n\tconst isCollapsed = selection.isCollapsed;\n\n\t// Collapse in direction of selection.\n\tif ( ! isCollapsed ) {\n\t\tcollapsedRange.collapse( ! isForward );\n\t}\n\n\tconst collapsedRangeRect = getRectangleFromRange( collapsedRange );\n\tconst rangeRect = getRectangleFromRange( range );\n\n\tif ( ! collapsedRangeRect || ! rangeRect ) {\n\t\treturn false;\n\t}\n\n\t// Only consider the multiline selection at the edge if the direction is\n\t// towards the edge. The selection is multiline if it is taller than the\n\t// collapsed selection.\n\tconst rangeHeight = getRangeHeight( range );\n\tif (\n\t\t! isCollapsed &&\n\t\trangeHeight &&\n\t\trangeHeight > collapsedRangeRect.height &&\n\t\tisForward === isReverse\n\t) {\n\t\treturn false;\n\t}\n\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\n\t// To check if a selection is at the edge, we insert a test selection at the\n\t// edge of the container and check if the selections have the same vertical\n\t// or horizontal position. If they do, the selection is at the edge.\n\t// This method proves to be better than a DOM-based calculation for the\n\t// horizontal edge, since it ignores empty textnodes and a trailing line\n\t// break element. In other words, we need to check visual positioning, not\n\t// DOM positioning.\n\t// It also proves better than using the computed style for the vertical\n\t// edge, because we cannot know the padding and line height reliably in\n\t// pixels. `getComputedStyle` may return a value with different units.\n\tconst x = isReverseDir ? containerRect.left + 1 : containerRect.right - 1;\n\tconst y = isReverse ? containerRect.top + 1 : containerRect.bottom - 1;\n\n\t// The test point can only be hit-tested when it is within the viewport\n\t// (`caretRangeFromPoint` returns nothing for a point outside it, upon\n\t// which `scrollIfNoRange` scrolls the container's edge into view to\n\t// measure, e.g. on every arrow press within a container taller than the\n\t// viewport). When the edge is outside the viewport and the selection is\n\t// within it, they are at least a viewport boundary apart along that\n\t// axis, so the selection cannot be at the edge. Check each axis\n\t// separately: the vertical check must not be short-circuited by a\n\t// horizontally overflowing container, and vice versa.\n\tconst isFarFromVerticalEdge =\n\t\t( y < 0 || y > defaultView.innerHeight ) &&\n\t\trangeRect.top >= 0 &&\n\t\trangeRect.bottom <= defaultView.innerHeight;\n\tconst isFarFromHorizontalEdge =\n\t\t( x < 0 || x > defaultView.innerWidth ) &&\n\t\trangeRect.left >= 0 &&\n\t\trangeRect.right <= defaultView.innerWidth;\n\n\tif (\n\t\tisFarFromVerticalEdge ||\n\t\t( ! onlyVertical && isFarFromHorizontalEdge )\n\t) {\n\t\treturn false;\n\t}\n\n\tconst testRange = scrollIfNoRange( container, isReverse, () =>\n\t\thiddenCaretRangeFromPoint( ownerDocument, x, y, container )\n\t);\n\n\tif ( ! testRange ) {\n\t\treturn false;\n\t}\n\n\tconst testRect = getRectangleFromRange( testRange );\n\n\tif ( ! testRect ) {\n\t\treturn false;\n\t}\n\n\tconst verticalSide = isReverse ? 'top' : 'bottom';\n\tconst horizontalSide = isReverseDir ? 'left' : 'right';\n\tconst verticalDiff = testRect[ verticalSide ] - rangeRect[ verticalSide ];\n\tconst horizontalDiff =\n\t\ttestRect[ horizontalSide ] - collapsedRangeRect[ horizontalSide ];\n\n\t// Allow the position to be 1px off.\n\tconst hasVerticalDiff = Math.abs( verticalDiff ) <= 1;\n\tconst hasHorizontalDiff = Math.abs( horizontalDiff ) <= 1;\n\n\treturn onlyVertical\n\t\t? hasVerticalDiff\n\t\t: hasVerticalDiff && hasHorizontalDiff;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,oBAAkB;AAClB,8BAA2B;AAC3B,sCAAkC;AAClC,kCAA+B;AAC/B,2CAAsC;AACtC,+BAAgC;AAChC,mCAA8B;AAC9B,gCAAgC;AAajB,SAAR,OAAyB,WAAW,WAAW,eAAe,OAAQ;AAC5E,UACC,6BAAAA,SAAmB,SAAU,KAC7B,OAAO,UAAU,mBAAmB,UACnC;AACD,QAAK,UAAU,mBAAmB,UAAU,cAAe;AAC1D,aAAO;AAAA,IACR;AAEA,QAAK,WAAY;AAChB,aAAO,UAAU,mBAAmB;AAAA,IACrC;AAEA,WAAO,UAAU,MAAM,WAAW,UAAU;AAAA,EAC7C;AAEA,MAAK,CAAE,UAAU,mBAAoB;AACpC,WAAO;AAAA,EACR;AAEA,QAAM,EAAE,cAAc,IAAI;AAC1B,QAAM,EAAE,Y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H,SAAuB,SAAU;AAElD,MAAK,CAAE,UAAW;AACjB,WAAO;AAAA,EACR;AAEA,QAAM,eAAe,YAAY,QAAQ;AACzC,QAAM,iBAAiB,eAAe,SAAS;AAC/C,QAAM,eAAe,SAAU,YAAa,IAAI,UAAW,YAAa;AACxE,QAAM,iBACL,SAAU,cAAe,IAAI,mBAAoB,cAAe;AAGjE,QAAM,kBAAkB,KAAK,IAAK,YAAa,KAAK;AACpD,QAAM,oBAAoB,KAAK,IAAK,cAAe,KAAK;AAExD,SAAO,eACJ,kBACA,mBAAmB;AACvB;",
|
|
6
6
|
"names": ["isInputOrTextArea", "isSelectionForward", "getRectangleFromRange", "getRangeHeight", "isRTL", "hiddenCaretRangeFromPoint"]
|
|
7
7
|
}
|
|
@@ -47,6 +47,11 @@ function isEdge(container, isReverse, onlyVertical = false) {
|
|
|
47
47
|
const containerRect = container.getBoundingClientRect();
|
|
48
48
|
const x = isReverseDir ? containerRect.left + 1 : containerRect.right - 1;
|
|
49
49
|
const y = isReverse ? containerRect.top + 1 : containerRect.bottom - 1;
|
|
50
|
+
const isFarFromVerticalEdge = (y < 0 || y > defaultView.innerHeight) && rangeRect.top >= 0 && rangeRect.bottom <= defaultView.innerHeight;
|
|
51
|
+
const isFarFromHorizontalEdge = (x < 0 || x > defaultView.innerWidth) && rangeRect.left >= 0 && rangeRect.right <= defaultView.innerWidth;
|
|
52
|
+
if (isFarFromVerticalEdge || !onlyVertical && isFarFromHorizontalEdge) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
50
55
|
const testRange = scrollIfNoRange(
|
|
51
56
|
container,
|
|
52
57
|
isReverse,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/dom/is-edge.js"],
|
|
4
|
-
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport isRTL from './is-rtl';\nimport getRangeHeight from './get-range-height';\nimport getRectangleFromRange from './get-rectangle-from-range';\nimport isSelectionForward from './is-selection-forward';\nimport hiddenCaretRangeFromPoint from './hidden-caret-range-from-point';\nimport { assertIsDefined } from '../utils/assert-is-defined';\nimport isInputOrTextArea from './is-input-or-text-area';\nimport { scrollIfNoRange } from './scroll-if-no-range';\n\n/**\n * Check whether the selection is at the edge of the container. Checks for\n * horizontal position by default. Set `onlyVertical` to true to check only\n * vertically.\n *\n * @param {HTMLElement} container Focusable element.\n * @param {boolean} isReverse Set to true to check left, false to check right.\n * @param {boolean} [onlyVertical=false] Set to true to check only vertical position.\n *\n * @return {boolean} True if at the edge, false if not.\n */\nexport default function isEdge( container, isReverse, onlyVertical = false ) {\n\tif (\n\t\tisInputOrTextArea( container ) &&\n\t\ttypeof container.selectionStart === 'number'\n\t) {\n\t\tif ( container.selectionStart !== container.selectionEnd ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif ( isReverse ) {\n\t\t\treturn container.selectionStart === 0;\n\t\t}\n\n\t\treturn container.value.length === container.selectionStart;\n\t}\n\n\tif ( ! container.isContentEditable ) {\n\t\treturn true;\n\t}\n\n\tconst { ownerDocument } = container;\n\tconst { defaultView } = ownerDocument;\n\n\tassertIsDefined( defaultView, 'defaultView' );\n\tconst selection = defaultView.getSelection();\n\n\tif ( ! selection || ! selection.rangeCount ) {\n\t\treturn false;\n\t}\n\n\tconst range = selection.getRangeAt( 0 );\n\tconst collapsedRange = range.cloneRange();\n\tconst isForward = isSelectionForward( selection );\n\tconst isCollapsed = selection.isCollapsed;\n\n\t// Collapse in direction of selection.\n\tif ( ! isCollapsed ) {\n\t\tcollapsedRange.collapse( ! isForward );\n\t}\n\n\tconst collapsedRangeRect = getRectangleFromRange( collapsedRange );\n\tconst rangeRect = getRectangleFromRange( range );\n\n\tif ( ! collapsedRangeRect || ! rangeRect ) {\n\t\treturn false;\n\t}\n\n\t// Only consider the multiline selection at the edge if the direction is\n\t// towards the edge. The selection is multiline if it is taller than the\n\t// collapsed selection.\n\tconst rangeHeight = getRangeHeight( range );\n\tif (\n\t\t! isCollapsed &&\n\t\trangeHeight &&\n\t\trangeHeight > collapsedRangeRect.height &&\n\t\tisForward === isReverse\n\t) {\n\t\treturn false;\n\t}\n\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\n\t// To check if a selection is at the edge, we insert a test selection at the\n\t// edge of the container and check if the selections have the same vertical\n\t// or horizontal position. If they do, the selection is at the edge.\n\t// This method proves to be better than a DOM-based calculation for the\n\t// horizontal edge, since it ignores empty textnodes and a trailing line\n\t// break element. In other words, we need to check visual positioning, not\n\t// DOM positioning.\n\t// It also proves better than using the computed style for the vertical\n\t// edge, because we cannot know the padding and line height reliably in\n\t// pixels. `getComputedStyle` may return a value with different units.\n\tconst x = isReverseDir ? containerRect.left + 1 : containerRect.right - 1;\n\tconst y = isReverse ? containerRect.top + 1 : containerRect.bottom - 1;\n\tconst testRange = scrollIfNoRange( container, isReverse, () =>\n\t\thiddenCaretRangeFromPoint( ownerDocument, x, y, container )\n\t);\n\n\tif ( ! testRange ) {\n\t\treturn false;\n\t}\n\n\tconst testRect = getRectangleFromRange( testRange );\n\n\tif ( ! testRect ) {\n\t\treturn false;\n\t}\n\n\tconst verticalSide = isReverse ? 'top' : 'bottom';\n\tconst horizontalSide = isReverseDir ? 'left' : 'right';\n\tconst verticalDiff = testRect[ verticalSide ] - rangeRect[ verticalSide ];\n\tconst horizontalDiff =\n\t\ttestRect[ horizontalSide ] - collapsedRangeRect[ horizontalSide ];\n\n\t// Allow the position to be 1px off.\n\tconst hasVerticalDiff = Math.abs( verticalDiff ) <= 1;\n\tconst hasHorizontalDiff = Math.abs( horizontalDiff ) <= 1;\n\n\treturn onlyVertical\n\t\t? hasVerticalDiff\n\t\t: hasVerticalDiff && hasHorizontalDiff;\n}\n"],
|
|
5
|
-
"mappings": ";AAGA,OAAO,WAAW;AAClB,OAAO,oBAAoB;AAC3B,OAAO,2BAA2B;A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AAI,cAAc,SAAS;
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport isRTL from './is-rtl';\nimport getRangeHeight from './get-range-height';\nimport getRectangleFromRange from './get-rectangle-from-range';\nimport isSelectionForward from './is-selection-forward';\nimport hiddenCaretRangeFromPoint from './hidden-caret-range-from-point';\nimport { assertIsDefined } from '../utils/assert-is-defined';\nimport isInputOrTextArea from './is-input-or-text-area';\nimport { scrollIfNoRange } from './scroll-if-no-range';\n\n/**\n * Check whether the selection is at the edge of the container. Checks for\n * horizontal position by default. Set `onlyVertical` to true to check only\n * vertically.\n *\n * @param {HTMLElement} container Focusable element.\n * @param {boolean} isReverse Set to true to check left, false to check right.\n * @param {boolean} [onlyVertical=false] Set to true to check only vertical position.\n *\n * @return {boolean} True if at the edge, false if not.\n */\nexport default function isEdge( container, isReverse, onlyVertical = false ) {\n\tif (\n\t\tisInputOrTextArea( container ) &&\n\t\ttypeof container.selectionStart === 'number'\n\t) {\n\t\tif ( container.selectionStart !== container.selectionEnd ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif ( isReverse ) {\n\t\t\treturn container.selectionStart === 0;\n\t\t}\n\n\t\treturn container.value.length === container.selectionStart;\n\t}\n\n\tif ( ! container.isContentEditable ) {\n\t\treturn true;\n\t}\n\n\tconst { ownerDocument } = container;\n\tconst { defaultView } = ownerDocument;\n\n\tassertIsDefined( defaultView, 'defaultView' );\n\tconst selection = defaultView.getSelection();\n\n\tif ( ! selection || ! selection.rangeCount ) {\n\t\treturn false;\n\t}\n\n\tconst range = selection.getRangeAt( 0 );\n\tconst collapsedRange = range.cloneRange();\n\tconst isForward = isSelectionForward( selection );\n\tconst isCollapsed = selection.isCollapsed;\n\n\t// Collapse in direction of selection.\n\tif ( ! isCollapsed ) {\n\t\tcollapsedRange.collapse( ! isForward );\n\t}\n\n\tconst collapsedRangeRect = getRectangleFromRange( collapsedRange );\n\tconst rangeRect = getRectangleFromRange( range );\n\n\tif ( ! collapsedRangeRect || ! rangeRect ) {\n\t\treturn false;\n\t}\n\n\t// Only consider the multiline selection at the edge if the direction is\n\t// towards the edge. The selection is multiline if it is taller than the\n\t// collapsed selection.\n\tconst rangeHeight = getRangeHeight( range );\n\tif (\n\t\t! isCollapsed &&\n\t\trangeHeight &&\n\t\trangeHeight > collapsedRangeRect.height &&\n\t\tisForward === isReverse\n\t) {\n\t\treturn false;\n\t}\n\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\n\t// To check if a selection is at the edge, we insert a test selection at the\n\t// edge of the container and check if the selections have the same vertical\n\t// or horizontal position. If they do, the selection is at the edge.\n\t// This method proves to be better than a DOM-based calculation for the\n\t// horizontal edge, since it ignores empty textnodes and a trailing line\n\t// break element. In other words, we need to check visual positioning, not\n\t// DOM positioning.\n\t// It also proves better than using the computed style for the vertical\n\t// edge, because we cannot know the padding and line height reliably in\n\t// pixels. `getComputedStyle` may return a value with different units.\n\tconst x = isReverseDir ? containerRect.left + 1 : containerRect.right - 1;\n\tconst y = isReverse ? containerRect.top + 1 : containerRect.bottom - 1;\n\n\t// The test point can only be hit-tested when it is within the viewport\n\t// (`caretRangeFromPoint` returns nothing for a point outside it, upon\n\t// which `scrollIfNoRange` scrolls the container's edge into view to\n\t// measure, e.g. on every arrow press within a container taller than the\n\t// viewport). When the edge is outside the viewport and the selection is\n\t// within it, they are at least a viewport boundary apart along that\n\t// axis, so the selection cannot be at the edge. Check each axis\n\t// separately: the vertical check must not be short-circuited by a\n\t// horizontally overflowing container, and vice versa.\n\tconst isFarFromVerticalEdge =\n\t\t( y < 0 || y > defaultView.innerHeight ) &&\n\t\trangeRect.top >= 0 &&\n\t\trangeRect.bottom <= defaultView.innerHeight;\n\tconst isFarFromHorizontalEdge =\n\t\t( x < 0 || x > defaultView.innerWidth ) &&\n\t\trangeRect.left >= 0 &&\n\t\trangeRect.right <= defaultView.innerWidth;\n\n\tif (\n\t\tisFarFromVerticalEdge ||\n\t\t( ! onlyVertical && isFarFromHorizontalEdge )\n\t) {\n\t\treturn false;\n\t}\n\n\tconst testRange = scrollIfNoRange( container, isReverse, () =>\n\t\thiddenCaretRangeFromPoint( ownerDocument, x, y, container )\n\t);\n\n\tif ( ! testRange ) {\n\t\treturn false;\n\t}\n\n\tconst testRect = getRectangleFromRange( testRange );\n\n\tif ( ! testRect ) {\n\t\treturn false;\n\t}\n\n\tconst verticalSide = isReverse ? 'top' : 'bottom';\n\tconst horizontalSide = isReverseDir ? 'left' : 'right';\n\tconst verticalDiff = testRect[ verticalSide ] - rangeRect[ verticalSide ];\n\tconst horizontalDiff =\n\t\ttestRect[ horizontalSide ] - collapsedRangeRect[ horizontalSide ];\n\n\t// Allow the position to be 1px off.\n\tconst hasVerticalDiff = Math.abs( verticalDiff ) <= 1;\n\tconst hasHorizontalDiff = Math.abs( horizontalDiff ) <= 1;\n\n\treturn onlyVertical\n\t\t? hasVerticalDiff\n\t\t: hasVerticalDiff && hasHorizontalDiff;\n}\n"],
|
|
5
|
+
"mappings": ";AAGA,OAAO,WAAW;AAClB,OAAO,oBAAoB;AAC3B,OAAO,2BAA2B;AAClC,OAAO,wBAAwB;AAC/B,OAAO,+BAA+B;AACtC,SAAS,uBAAuB;AAChC,OAAO,uBAAuB;AAC9B,SAAS,uBAAuB;AAajB,SAAR,OAAyB,WAAW,WAAW,eAAe,OAAQ;AAC5E,MACC,kBAAmB,SAAU,KAC7B,OAAO,UAAU,mBAAmB,UACnC;AACD,QAAK,UAAU,mBAAmB,UAAU,cAAe;AAC1D,aAAO;AAAA,IACR;AAEA,QAAK,WAAY;AAChB,aAAO,UAAU,mBAAmB;AAAA,IACrC;AAEA,WAAO,UAAU,MAAM,WAAW,UAAU;AAAA,EAC7C;AAEA,MAAK,CAAE,UAAU,mBAAoB;AACpC,WAAO;AAAA,EACR;AAEA,QAAM,EAAE,cAAc,IAAI;AAC1B,QAAM,EAAE,YAAY,IAAI;A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AAM,eAAe,YAAY,QAAQ;AACzC,QAAM,iBAAiB,eAAe,SAAS;AAC/C,QAAM,eAAe,SAAU,YAAa,IAAI,UAAW,YAAa;AACxE,QAAM,iBACL,SAAU,cAAe,IAAI,mBAAoB,cAAe;AAGjE,QAAM,kBAAkB,KAAK,IAAK,YAAa,KAAK;AACpD,QAAM,oBAAoB,KAAK,IAAK,cAAe,KAAK;AAExD,SAAO,eACJ,kBACA,mBAAmB;AACvB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"is-edge.d.ts","sourceRoot":"","sources":["../../src/dom/is-edge.js"],"names":[],"mappings":"AAYA;;;;;;;;;;GAUG;AACH,MAAM,CAAC,OAAO,UAAU,MAAM,CAAE,SAAS,EAN9B,WAM8B,EAAE,SAAS,EALzC,OAKyC,EAAE,YAAY,AAJ/D,CAEA,EAFQ,OAI+D,GAF9D,OAAO,
|
|
1
|
+
{"version":3,"file":"is-edge.d.ts","sourceRoot":"","sources":["../../src/dom/is-edge.js"],"names":[],"mappings":"AAYA;;;;;;;;;;GAUG;AACH,MAAM,CAAC,OAAO,UAAU,MAAM,CAAE,SAAS,EAN9B,WAM8B,EAAE,SAAS,EALzC,OAKyC,EAAE,YAAY,AAJ/D,CAEA,EAFQ,OAI+D,GAF9D,OAAO,CAmIlB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/dom",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.52.0",
|
|
4
4
|
"description": "DOM utilities module for WordPress.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -44,10 +44,10 @@
|
|
|
44
44
|
"types": "build-types",
|
|
45
45
|
"sideEffects": false,
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@wordpress/deprecated": "^4.
|
|
47
|
+
"@wordpress/deprecated": "^4.52.0"
|
|
48
48
|
},
|
|
49
49
|
"publishConfig": {
|
|
50
50
|
"access": "public"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "7e8b17a983f9391d3ebc7717af2a1c9ed7efc7ab"
|
|
53
53
|
}
|
package/src/dom/is-edge.js
CHANGED
|
@@ -97,6 +97,32 @@ export default function isEdge( container, isReverse, onlyVertical = false ) {
|
|
|
97
97
|
// pixels. `getComputedStyle` may return a value with different units.
|
|
98
98
|
const x = isReverseDir ? containerRect.left + 1 : containerRect.right - 1;
|
|
99
99
|
const y = isReverse ? containerRect.top + 1 : containerRect.bottom - 1;
|
|
100
|
+
|
|
101
|
+
// The test point can only be hit-tested when it is within the viewport
|
|
102
|
+
// (`caretRangeFromPoint` returns nothing for a point outside it, upon
|
|
103
|
+
// which `scrollIfNoRange` scrolls the container's edge into view to
|
|
104
|
+
// measure, e.g. on every arrow press within a container taller than the
|
|
105
|
+
// viewport). When the edge is outside the viewport and the selection is
|
|
106
|
+
// within it, they are at least a viewport boundary apart along that
|
|
107
|
+
// axis, so the selection cannot be at the edge. Check each axis
|
|
108
|
+
// separately: the vertical check must not be short-circuited by a
|
|
109
|
+
// horizontally overflowing container, and vice versa.
|
|
110
|
+
const isFarFromVerticalEdge =
|
|
111
|
+
( y < 0 || y > defaultView.innerHeight ) &&
|
|
112
|
+
rangeRect.top >= 0 &&
|
|
113
|
+
rangeRect.bottom <= defaultView.innerHeight;
|
|
114
|
+
const isFarFromHorizontalEdge =
|
|
115
|
+
( x < 0 || x > defaultView.innerWidth ) &&
|
|
116
|
+
rangeRect.left >= 0 &&
|
|
117
|
+
rangeRect.right <= defaultView.innerWidth;
|
|
118
|
+
|
|
119
|
+
if (
|
|
120
|
+
isFarFromVerticalEdge ||
|
|
121
|
+
( ! onlyVertical && isFarFromHorizontalEdge )
|
|
122
|
+
) {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
|
|
100
126
|
const testRange = scrollIfNoRange( container, isReverse, () =>
|
|
101
127
|
hiddenCaretRangeFromPoint( ownerDocument, x, y, container )
|
|
102
128
|
);
|