@wordpress/dom 3.2.2 → 3.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -4
- package/build/dom/caret-range-from-point.js +7 -3
- package/build/dom/caret-range-from-point.js.map +1 -1
- package/build/dom/document-has-text-selection.js +1 -1
- package/build/dom/document-has-text-selection.js.map +1 -1
- package/build/dom/document-has-uncollapsed-selection.js +2 -2
- package/build/dom/document-has-uncollapsed-selection.js.map +1 -1
- package/build/dom/is-edge.js +1 -1
- package/build/dom/is-edge.js.map +1 -1
- package/build/dom/place-caret-at-edge.js +108 -0
- package/build/dom/place-caret-at-edge.js.map +1 -0
- package/build/dom/place-caret-at-horizontal-edge.js +2 -84
- package/build/dom/place-caret-at-horizontal-edge.js.map +1 -1
- package/build/dom/place-caret-at-vertical-edge.js +6 -56
- package/build/dom/place-caret-at-vertical-edge.js.map +1 -1
- package/build/dom/strip-html.js +14 -2
- package/build/dom/strip-html.js.map +1 -1
- package/build/focusable.js +29 -18
- package/build/focusable.js.map +1 -1
- package/build/phrasing-content.js +1 -1
- package/build/phrasing-content.js.map +1 -1
- package/build/tabbable.js +2 -2
- package/build/tabbable.js.map +1 -1
- package/build-module/dom/caret-range-from-point.js +7 -3
- package/build-module/dom/caret-range-from-point.js.map +1 -1
- package/build-module/dom/document-has-text-selection.js +1 -1
- package/build-module/dom/document-has-text-selection.js.map +1 -1
- package/build-module/dom/document-has-uncollapsed-selection.js +2 -2
- package/build-module/dom/document-has-uncollapsed-selection.js.map +1 -1
- package/build-module/dom/is-edge.js +1 -1
- package/build-module/dom/is-edge.js.map +1 -1
- package/build-module/dom/place-caret-at-edge.js +95 -0
- package/build-module/dom/place-caret-at-edge.js.map +1 -0
- package/build-module/dom/place-caret-at-horizontal-edge.js +2 -81
- package/build-module/dom/place-caret-at-horizontal-edge.js.map +1 -1
- package/build-module/dom/place-caret-at-vertical-edge.js +6 -54
- package/build-module/dom/place-caret-at-vertical-edge.js.map +1 -1
- package/build-module/dom/strip-html.js +11 -2
- package/build-module/dom/strip-html.js.map +1 -1
- package/build-module/focusable.js +29 -18
- package/build-module/focusable.js.map +1 -1
- package/build-module/phrasing-content.js +1 -1
- package/build-module/phrasing-content.js.map +1 -1
- package/build-module/tabbable.js +2 -2
- package/build-module/tabbable.js.map +1 -1
- package/build-types/dom/caret-range-from-point.d.ts +12 -4
- package/build-types/dom/caret-range-from-point.d.ts.map +1 -1
- package/build-types/dom/clean-node-list.d.ts +2 -2
- package/build-types/dom/document-has-text-selection.d.ts +1 -1
- package/build-types/dom/document-has-uncollapsed-selection.d.ts +2 -2
- package/build-types/dom/is-edge.d.ts.map +1 -1
- package/build-types/dom/place-caret-at-edge.d.ts +9 -0
- package/build-types/dom/place-caret-at-edge.d.ts.map +1 -0
- package/build-types/dom/place-caret-at-horizontal-edge.d.ts.map +1 -1
- package/build-types/dom/place-caret-at-vertical-edge.d.ts +4 -5
- package/build-types/dom/place-caret-at-vertical-edge.d.ts.map +1 -1
- package/build-types/dom/strip-html.d.ts.map +1 -1
- package/build-types/focusable.d.ts +11 -2
- package/build-types/focusable.d.ts.map +1 -1
- package/build-types/phrasing-content.d.ts +2 -4
- package/build-types/phrasing-content.d.ts.map +1 -1
- package/build-types/tabbable.d.ts +3 -3
- package/build-types/tabbable.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/dom/caret-range-from-point.js +8 -3
- package/src/dom/document-has-text-selection.js +1 -1
- package/src/dom/document-has-uncollapsed-selection.js +2 -2
- package/src/dom/is-edge.js +4 -1
- package/src/dom/place-caret-at-edge.js +95 -0
- package/src/dom/place-caret-at-horizontal-edge.js +2 -83
- package/src/dom/place-caret-at-vertical-edge.js +6 -64
- package/src/dom/strip-html.js +12 -5
- package/src/dom/test/strip-html.js +64 -0
- package/src/focusable.js +37 -32
- package/src/phrasing-content.js +1 -1
- package/src/tabbable.js +2 -4
- package/src/test/dom.js +8 -15
- package/tsconfig.tsbuildinfo +1 -1170
package/README.md
CHANGED
@@ -42,7 +42,7 @@ _Returns_
|
|
42
42
|
### documentHasTextSelection
|
43
43
|
|
44
44
|
Check whether the current document has selected text. This applies to ranges
|
45
|
-
of text in the document, and not selection inside
|
45
|
+
of text in the document, and not selection inside `<input>` and `<textarea>`
|
46
46
|
elements.
|
47
47
|
|
48
48
|
See: <https://developer.mozilla.org/en-US/docs/Web/API/Window/getSelection#Related_objects>.
|
@@ -58,8 +58,8 @@ _Returns_
|
|
58
58
|
### documentHasUncollapsedSelection
|
59
59
|
|
60
60
|
Check whether the current document has any sort of selection. This includes
|
61
|
-
ranges of text across elements and any selection inside
|
62
|
-
|
61
|
+
ranges of text across elements and any selection inside `<input>` and
|
62
|
+
`<textarea>` elements.
|
63
63
|
|
64
64
|
_Parameters_
|
65
65
|
|
@@ -294,7 +294,6 @@ _Parameters_
|
|
294
294
|
- _container_ `HTMLElement`: Focusable element.
|
295
295
|
- _isReverse_ `boolean`: True for bottom, false for top.
|
296
296
|
- _rect_ `[DOMRect]`: The rectangle to position the caret with.
|
297
|
-
- _mayUseScroll_ `[boolean]`: True to allow scrolling, false to disallow.
|
298
297
|
|
299
298
|
### remove
|
300
299
|
|
@@ -11,9 +11,9 @@ exports.default = caretRangeFromPoint;
|
|
11
11
|
*
|
12
12
|
* @see https://developer.mozilla.org/en-US/docs/Web/API/Document/caretRangeFromPoint
|
13
13
|
*
|
14
|
-
* @param {
|
15
|
-
* @param {number}
|
16
|
-
* @param {number}
|
14
|
+
* @param {DocumentMaybeWithCaretPositionFromPoint} doc The document of the range.
|
15
|
+
* @param {number} x Horizontal position within the current viewport.
|
16
|
+
* @param {number} y Vertical position within the current viewport.
|
17
17
|
*
|
18
18
|
* @return {Range | null} The best range for the given point.
|
19
19
|
*/
|
@@ -38,4 +38,8 @@ function caretRangeFromPoint(doc, x, y) {
|
|
38
38
|
range.collapse(true);
|
39
39
|
return range;
|
40
40
|
}
|
41
|
+
/**
|
42
|
+
* @typedef {{caretPositionFromPoint?: (x: number, y: number)=> CaretPosition | null} & Document } DocumentMaybeWithCaretPositionFromPoint
|
43
|
+
* @typedef {{ readonly offset: number; readonly offsetNode: Node; getClientRect(): DOMRect | null; }} CaretPosition
|
44
|
+
*/
|
41
45
|
//# sourceMappingURL=caret-range-from-point.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["@wordpress/dom/src/dom/caret-range-from-point.js"],"names":["caretRangeFromPoint","doc","x","y","caretPositionFromPoint","point","range","createRange","setStart","offsetNode","offset","collapse"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,mBAAT,CAA8BC,GAA9B,EAAmCC,CAAnC,EAAsCC,CAAtC,EAA0C;AACxD,MAAKF,GAAG,CAACD,mBAAT,EAA+B;AAC9B,WAAOC,GAAG,CAACD,mBAAJ,CAAyBE,CAAzB,EAA4BC,CAA5B,CAAP;AACA;;AAED,MAAK,CAAEF,GAAG,CAACG,sBAAX,EAAoC;AACnC,WAAO,IAAP;AACA;;AAED,QAAMC,KAAK,GAAGJ,GAAG,CAACG,sBAAJ,CAA4BF,CAA5B,EAA+BC,CAA/B,CAAd,CATwD,CAWxD;AACA;;AACA,MAAK,CAAEE,KAAP,EAAe;AACd,WAAO,IAAP;AACA;;AAED,QAAMC,KAAK,GAAGL,GAAG,CAACM,WAAJ,EAAd;AAEAD,EAAAA,KAAK,CAACE,QAAN,CAAgBH,KAAK,CAACI,UAAtB,EAAkCJ,KAAK,CAACK,MAAxC;AACAJ,EAAAA,KAAK,CAACK,QAAN,CAAgB,IAAhB;AAEA,SAAOL,KAAP;AACA","sourcesContent":["/**\n * Polyfill.\n * Get a collapsed range for a given point.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Document/caretRangeFromPoint\n *\n * @param {
|
1
|
+
{"version":3,"sources":["@wordpress/dom/src/dom/caret-range-from-point.js"],"names":["caretRangeFromPoint","doc","x","y","caretPositionFromPoint","point","range","createRange","setStart","offsetNode","offset","collapse"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,mBAAT,CAA8BC,GAA9B,EAAmCC,CAAnC,EAAsCC,CAAtC,EAA0C;AACxD,MAAKF,GAAG,CAACD,mBAAT,EAA+B;AAC9B,WAAOC,GAAG,CAACD,mBAAJ,CAAyBE,CAAzB,EAA4BC,CAA5B,CAAP;AACA;;AAED,MAAK,CAAEF,GAAG,CAACG,sBAAX,EAAoC;AACnC,WAAO,IAAP;AACA;;AAED,QAAMC,KAAK,GAAGJ,GAAG,CAACG,sBAAJ,CAA4BF,CAA5B,EAA+BC,CAA/B,CAAd,CATwD,CAWxD;AACA;;AACA,MAAK,CAAEE,KAAP,EAAe;AACd,WAAO,IAAP;AACA;;AAED,QAAMC,KAAK,GAAGL,GAAG,CAACM,WAAJ,EAAd;AAEAD,EAAAA,KAAK,CAACE,QAAN,CAAgBH,KAAK,CAACI,UAAtB,EAAkCJ,KAAK,CAACK,MAAxC;AACAJ,EAAAA,KAAK,CAACK,QAAN,CAAgB,IAAhB;AAEA,SAAOL,KAAP;AACA;AAED;AACA;AACA;AACA","sourcesContent":["/**\n * Polyfill.\n * Get a collapsed range for a given point.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Document/caretRangeFromPoint\n *\n * @param {DocumentMaybeWithCaretPositionFromPoint} doc The document of the range.\n * @param {number} x Horizontal position within the current viewport.\n * @param {number} y Vertical position within the current viewport.\n *\n * @return {Range | null} The best range for the given point.\n */\nexport default function caretRangeFromPoint( doc, x, y ) {\n\tif ( doc.caretRangeFromPoint ) {\n\t\treturn doc.caretRangeFromPoint( x, y );\n\t}\n\n\tif ( ! doc.caretPositionFromPoint ) {\n\t\treturn null;\n\t}\n\n\tconst point = doc.caretPositionFromPoint( x, y );\n\n\t// If x or y are negative, outside viewport, or there is no text entry node.\n\t// https://developer.mozilla.org/en-US/docs/Web/API/Document/caretRangeFromPoint\n\tif ( ! point ) {\n\t\treturn null;\n\t}\n\n\tconst range = doc.createRange();\n\n\trange.setStart( point.offsetNode, point.offset );\n\trange.collapse( true );\n\n\treturn range;\n}\n\n/**\n * @typedef {{caretPositionFromPoint?: (x: number, y: number)=> CaretPosition | null} & Document } DocumentMaybeWithCaretPositionFromPoint\n * @typedef {{ readonly offset: number; readonly offsetNode: Node; getClientRect(): DOMRect | null; }} CaretPosition\n */\n"]}
|
@@ -13,7 +13,7 @@ var _assertIsDefined = require("../utils/assert-is-defined");
|
|
13
13
|
|
14
14
|
/**
|
15
15
|
* Check whether the current document has selected text. This applies to ranges
|
16
|
-
* of text in the document, and not selection inside
|
16
|
+
* of text in the document, and not selection inside `<input>` and `<textarea>`
|
17
17
|
* elements.
|
18
18
|
*
|
19
19
|
* See: https://developer.mozilla.org/en-US/docs/Web/API/Window/getSelection#Related_objects.
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["@wordpress/dom/src/dom/document-has-text-selection.js"],"names":["documentHasTextSelection","doc","defaultView","selection","getSelection","range","rangeCount","getRangeAt","collapsed"],"mappings":";;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,wBAAT,CAAmCC,GAAnC,EAAyC;AACvD,wCAAiBA,GAAG,CAACC,WAArB,EAAkC,iBAAlC;AACA,QAAMC,SAAS,GAAGF,GAAG,CAACC,WAAJ,CAAgBE,YAAhB,EAAlB;AACA,wCAAiBD,SAAjB,EAA4B,WAA5B;AACA,QAAME,KAAK,GAAGF,SAAS,CAACG,UAAV,GAAuBH,SAAS,CAACI,UAAV,CAAsB,CAAtB,CAAvB,GAAmD,IAAjE;AACA,SAAO,CAAC,CAAEF,KAAH,IAAY,CAAEA,KAAK,CAACG,SAA3B;AACA","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
|
1
|
+
{"version":3,"sources":["@wordpress/dom/src/dom/document-has-text-selection.js"],"names":["documentHasTextSelection","doc","defaultView","selection","getSelection","range","rangeCount","getRangeAt","collapsed"],"mappings":";;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,wBAAT,CAAmCC,GAAnC,EAAyC;AACvD,wCAAiBA,GAAG,CAACC,WAArB,EAAkC,iBAAlC;AACA,QAAMC,SAAS,GAAGF,GAAG,CAACC,WAAJ,CAAgBE,YAAhB,EAAlB;AACA,wCAAiBD,SAAjB,EAA4B,WAA5B;AACA,QAAME,KAAK,GAAGF,SAAS,CAACG,UAAV,GAAuBH,SAAS,CAACI,UAAV,CAAsB,CAAtB,CAAvB,GAAmD,IAAjE;AACA,SAAO,CAAC,CAAEF,KAAH,IAAY,CAAEA,KAAK,CAACG,SAA3B;AACA","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"]}
|
@@ -17,8 +17,8 @@ var _inputFieldHasUncollapsedSelection = _interopRequireDefault(require("./input
|
|
17
17
|
|
18
18
|
/**
|
19
19
|
* Check whether the current document has any sort of selection. This includes
|
20
|
-
* ranges of text across elements and any selection inside
|
21
|
-
*
|
20
|
+
* ranges of text across elements and any selection inside `<input>` and
|
21
|
+
* `<textarea>` elements.
|
22
22
|
*
|
23
23
|
* @param {Document} doc The document to check.
|
24
24
|
*
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["@wordpress/dom/src/dom/document-has-uncollapsed-selection.js"],"names":["documentHasUncollapsedSelection","doc","activeElement"],"mappings":";;;;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,+BAAT,CAA0CC,GAA1C,EAAgD;AAC9D,SACC,uCAA0BA,GAA1B,KACE,CAAC,CAAEA,GAAG,CAACC,aAAP,IACD,gDAAmCD,GAAG,CAACC,aAAvC,CAHF;AAKA","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 selection. This includes\n * ranges of text across elements and any selection inside
|
1
|
+
{"version":3,"sources":["@wordpress/dom/src/dom/document-has-uncollapsed-selection.js"],"names":["documentHasUncollapsedSelection","doc","activeElement"],"mappings":";;;;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,+BAAT,CAA0CC,GAA1C,EAAgD;AAC9D,SACC,uCAA0BA,GAA1B,KACE,CAAC,CAAEA,GAAG,CAACC,aAAP,IACD,gDAAmCD,GAAG,CAACC,aAAvC,CAHF;AAKA","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 selection. This includes\n * ranges of text across elements and any selection inside `<input>` and\n * `<textarea>` elements.\n *\n * @param {Document} doc The document to check.\n *\n * @return {boolean} Whether there is any sort of \"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"]}
|
package/build/dom/is-edge.js
CHANGED
@@ -37,7 +37,7 @@ var _isInputOrTextArea = _interopRequireDefault(require("./is-input-or-text-area
|
|
37
37
|
* @return {boolean} True if at the edge, false if not.
|
38
38
|
*/
|
39
39
|
function isEdge(container, isReverse, onlyVertical = false) {
|
40
|
-
if ((0, _isInputOrTextArea.default)(container)) {
|
40
|
+
if ((0, _isInputOrTextArea.default)(container) && typeof container.selectionStart === 'number') {
|
41
41
|
if (container.selectionStart !== container.selectionEnd) {
|
42
42
|
return false;
|
43
43
|
}
|
package/build/dom/is-edge.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["@wordpress/dom/src/dom/is-edge.js"],"names":["isEdge","container","isReverse","onlyVertical","selectionStart","selectionEnd","value","length","isContentEditable","ownerDocument","defaultView","selection","getSelection","rangeCount","range","getRangeAt","collapsedRange","cloneRange","isForward","isCollapsed","collapse","collapsedRangeRect","rangeRect","rangeHeight","height","isReverseDir","containerRect","getBoundingClientRect","x","left","right","y","top","bottom","testRange","testRect","verticalSide","horizontalSide","verticalDiff","horizontalDiff","hasVerticalDiff","Math","abs","hasHorizontalDiff"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AATA;AACA;AACA;;AASA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,MAAT,CAAiBC,SAAjB,EAA4BC,SAA5B,EAAuCC,YAAY,GAAG,KAAtD,EAA8D;AAC5E,
|
1
|
+
{"version":3,"sources":["@wordpress/dom/src/dom/is-edge.js"],"names":["isEdge","container","isReverse","onlyVertical","selectionStart","selectionEnd","value","length","isContentEditable","ownerDocument","defaultView","selection","getSelection","rangeCount","range","getRangeAt","collapsedRange","cloneRange","isForward","isCollapsed","collapse","collapsedRangeRect","rangeRect","rangeHeight","height","isReverseDir","containerRect","getBoundingClientRect","x","left","right","y","top","bottom","testRange","testRect","verticalSide","horizontalSide","verticalDiff","horizontalDiff","hasVerticalDiff","Math","abs","hasHorizontalDiff"],"mappings":"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","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';\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 {Element} 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 ( ! (/** @type {HTMLElement} */ ( 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 = hiddenCaretRangeFromPoint(\n\t\townerDocument,\n\t\tx,\n\t\ty,\n\t\t/** @type {HTMLElement} */ ( 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"]}
|
@@ -0,0 +1,108 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
+
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
6
|
+
value: true
|
7
|
+
});
|
8
|
+
exports.default = placeCaretAtEdge;
|
9
|
+
|
10
|
+
var _hiddenCaretRangeFromPoint = _interopRequireDefault(require("./hidden-caret-range-from-point"));
|
11
|
+
|
12
|
+
var _assertIsDefined = require("../utils/assert-is-defined");
|
13
|
+
|
14
|
+
var _isInputOrTextArea = _interopRequireDefault(require("./is-input-or-text-area"));
|
15
|
+
|
16
|
+
var _isRtl = _interopRequireDefault(require("./is-rtl"));
|
17
|
+
|
18
|
+
/**
|
19
|
+
* Internal dependencies
|
20
|
+
*/
|
21
|
+
|
22
|
+
/**
|
23
|
+
* Gets the range to place.
|
24
|
+
*
|
25
|
+
* @param {HTMLElement} container Focusable element.
|
26
|
+
* @param {boolean} isReverse True for end, false for start.
|
27
|
+
* @param {number|undefined} x X coordinate to vertically position.
|
28
|
+
*
|
29
|
+
* @return {Range|null} The range to place.
|
30
|
+
*/
|
31
|
+
function getRange(container, isReverse, x) {
|
32
|
+
const {
|
33
|
+
ownerDocument
|
34
|
+
} = container; // In the case of RTL scripts, the horizontal edge is at the opposite side.
|
35
|
+
|
36
|
+
const isReverseDir = (0, _isRtl.default)(container) ? !isReverse : isReverse;
|
37
|
+
const containerRect = container.getBoundingClientRect(); // When placing at the end (isReverse), find the closest range to the bottom
|
38
|
+
// right corner. When placing at the start, to the top left corner.
|
39
|
+
|
40
|
+
if (x === undefined) {
|
41
|
+
x = isReverse ? containerRect.right - 1 : containerRect.left + 1;
|
42
|
+
}
|
43
|
+
|
44
|
+
const y = isReverseDir ? containerRect.bottom - 1 : containerRect.top + 1;
|
45
|
+
return (0, _hiddenCaretRangeFromPoint.default)(ownerDocument, x, y, container);
|
46
|
+
}
|
47
|
+
/**
|
48
|
+
* Places the caret at start or end of a given element.
|
49
|
+
*
|
50
|
+
* @param {HTMLElement} container Focusable element.
|
51
|
+
* @param {boolean} isReverse True for end, false for start.
|
52
|
+
* @param {number|undefined} x X coordinate to vertically position.
|
53
|
+
*/
|
54
|
+
|
55
|
+
|
56
|
+
function placeCaretAtEdge(container, isReverse, x) {
|
57
|
+
if (!container) {
|
58
|
+
return;
|
59
|
+
}
|
60
|
+
|
61
|
+
container.focus();
|
62
|
+
|
63
|
+
if ((0, _isInputOrTextArea.default)(container)) {
|
64
|
+
// The element may not support selection setting.
|
65
|
+
if (typeof container.selectionStart !== 'number') {
|
66
|
+
return;
|
67
|
+
}
|
68
|
+
|
69
|
+
if (isReverse) {
|
70
|
+
container.selectionStart = container.value.length;
|
71
|
+
container.selectionEnd = container.value.length;
|
72
|
+
} else {
|
73
|
+
container.selectionStart = 0;
|
74
|
+
container.selectionEnd = 0;
|
75
|
+
}
|
76
|
+
|
77
|
+
return;
|
78
|
+
}
|
79
|
+
|
80
|
+
if (!container.isContentEditable) {
|
81
|
+
return;
|
82
|
+
}
|
83
|
+
|
84
|
+
let range = getRange(container, isReverse, x); // If no range range can be created or it is outside the container, the
|
85
|
+
// element may be out of view.
|
86
|
+
|
87
|
+
if (!range || !range.startContainer || !container.contains(range.startContainer)) {
|
88
|
+
container.scrollIntoView(isReverse);
|
89
|
+
range = range = getRange(container, isReverse, x);
|
90
|
+
|
91
|
+
if (!range || !range.startContainer || !container.contains(range.startContainer)) {
|
92
|
+
return;
|
93
|
+
}
|
94
|
+
}
|
95
|
+
|
96
|
+
const {
|
97
|
+
ownerDocument
|
98
|
+
} = container;
|
99
|
+
const {
|
100
|
+
defaultView
|
101
|
+
} = ownerDocument;
|
102
|
+
(0, _assertIsDefined.assertIsDefined)(defaultView, 'defaultView');
|
103
|
+
const selection = defaultView.getSelection();
|
104
|
+
(0, _assertIsDefined.assertIsDefined)(selection, 'selection');
|
105
|
+
selection.removeAllRanges();
|
106
|
+
selection.addRange(range);
|
107
|
+
}
|
108
|
+
//# sourceMappingURL=place-caret-at-edge.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["@wordpress/dom/src/dom/place-caret-at-edge.js"],"names":["getRange","container","isReverse","x","ownerDocument","isReverseDir","containerRect","getBoundingClientRect","undefined","right","left","y","bottom","top","placeCaretAtEdge","focus","selectionStart","value","length","selectionEnd","isContentEditable","range","startContainer","contains","scrollIntoView","defaultView","selection","getSelection","removeAllRanges","addRange"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AACA;;AANA;AACA;AACA;;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,QAAT,CAAmBC,SAAnB,EAA8BC,SAA9B,EAAyCC,CAAzC,EAA6C;AAC5C,QAAM;AAAEC,IAAAA;AAAF,MAAoBH,SAA1B,CAD4C,CAE5C;;AACA,QAAMI,YAAY,GAAG,oBAAOJ,SAAP,IAAqB,CAAEC,SAAvB,GAAmCA,SAAxD;AACA,QAAMI,aAAa,GAAGL,SAAS,CAACM,qBAAV,EAAtB,CAJ4C,CAK5C;AACA;;AACA,MAAKJ,CAAC,KAAKK,SAAX,EAAuB;AACtBL,IAAAA,CAAC,GAAGD,SAAS,GAAGI,aAAa,CAACG,KAAd,GAAsB,CAAzB,GAA6BH,aAAa,CAACI,IAAd,GAAqB,CAA/D;AACA;;AACD,QAAMC,CAAC,GAAGN,YAAY,GAAGC,aAAa,CAACM,MAAd,GAAuB,CAA1B,GAA8BN,aAAa,CAACO,GAAd,GAAoB,CAAxE;AACA,SAAO,wCAA2BT,aAA3B,EAA0CD,CAA1C,EAA6CQ,CAA7C,EAAgDV,SAAhD,CAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACe,SAASa,gBAAT,CAA2Bb,SAA3B,EAAsCC,SAAtC,EAAiDC,CAAjD,EAAqD;AACnE,MAAK,CAAEF,SAAP,EAAmB;AAClB;AACA;;AAEDA,EAAAA,SAAS,CAACc,KAAV;;AAEA,MAAK,gCAAmBd,SAAnB,CAAL,EAAsC;AACrC;AACA,QAAK,OAAOA,SAAS,CAACe,cAAjB,KAAoC,QAAzC,EAAoD;AACnD;AACA;;AAED,QAAKd,SAAL,EAAiB;AAChBD,MAAAA,SAAS,CAACe,cAAV,GAA2Bf,SAAS,CAACgB,KAAV,CAAgBC,MAA3C;AACAjB,MAAAA,SAAS,CAACkB,YAAV,GAAyBlB,SAAS,CAACgB,KAAV,CAAgBC,MAAzC;AACA,KAHD,MAGO;AACNjB,MAAAA,SAAS,CAACe,cAAV,GAA2B,CAA3B;AACAf,MAAAA,SAAS,CAACkB,YAAV,GAAyB,CAAzB;AACA;;AAED;AACA;;AAED,MAAK,CAAElB,SAAS,CAACmB,iBAAjB,EAAqC;AACpC;AACA;;AAED,MAAIC,KAAK,GAAGrB,QAAQ,CAAEC,SAAF,EAAaC,SAAb,EAAwBC,CAAxB,CAApB,CA5BmE,CA8BnE;AACA;;AACA,MACC,CAAEkB,KAAF,IACA,CAAEA,KAAK,CAACC,cADR,IAEA,CAAErB,SAAS,CAACsB,QAAV,CAAoBF,KAAK,CAACC,cAA1B,CAHH,EAIE;AACDrB,IAAAA,SAAS,CAACuB,cAAV,CAA0BtB,SAA1B;AACAmB,IAAAA,KAAK,GAAGA,KAAK,GAAGrB,QAAQ,CAAEC,SAAF,EAAaC,SAAb,EAAwBC,CAAxB,CAAxB;;AAEA,QACC,CAAEkB,KAAF,IACA,CAAEA,KAAK,CAACC,cADR,IAEA,CAAErB,SAAS,CAACsB,QAAV,CAAoBF,KAAK,CAACC,cAA1B,CAHH,EAIE;AACD;AACA;AACD;;AAED,QAAM;AAAElB,IAAAA;AAAF,MAAoBH,SAA1B;AACA,QAAM;AAAEwB,IAAAA;AAAF,MAAkBrB,aAAxB;AACA,wCAAiBqB,WAAjB,EAA8B,aAA9B;AACA,QAAMC,SAAS,GAAGD,WAAW,CAACE,YAAZ,EAAlB;AACA,wCAAiBD,SAAjB,EAA4B,WAA5B;AACAA,EAAAA,SAAS,CAACE,eAAV;AACAF,EAAAA,SAAS,CAACG,QAAV,CAAoBR,KAApB;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport hiddenCaretRangeFromPoint from './hidden-caret-range-from-point';\nimport { assertIsDefined } from '../utils/assert-is-defined';\nimport isInputOrTextArea from './is-input-or-text-area';\nimport isRTL from './is-rtl';\n\n/**\n * Gets the range to place.\n *\n * @param {HTMLElement} container Focusable element.\n * @param {boolean} isReverse True for end, false for start.\n * @param {number|undefined} x X coordinate to vertically position.\n *\n * @return {Range|null} The range to place.\n */\nfunction getRange( container, isReverse, x ) {\n\tconst { ownerDocument } = container;\n\t// In the case of RTL scripts, the horizontal edge is at the opposite side.\n\tconst isReverseDir = isRTL( container ) ? ! isReverse : isReverse;\n\tconst containerRect = container.getBoundingClientRect();\n\t// When placing at the end (isReverse), find the closest range to the bottom\n\t// right corner. When placing at the start, to the top left corner.\n\tif ( x === undefined ) {\n\t\tx = isReverse ? containerRect.right - 1 : containerRect.left + 1;\n\t}\n\tconst y = isReverseDir ? containerRect.bottom - 1 : containerRect.top + 1;\n\treturn hiddenCaretRangeFromPoint( ownerDocument, x, y, container );\n}\n\n/**\n * Places the caret at start or end of a given element.\n *\n * @param {HTMLElement} container Focusable element.\n * @param {boolean} isReverse True for end, false for start.\n * @param {number|undefined} x X coordinate to vertically position.\n */\nexport default function placeCaretAtEdge( container, isReverse, x ) {\n\tif ( ! container ) {\n\t\treturn;\n\t}\n\n\tcontainer.focus();\n\n\tif ( isInputOrTextArea( container ) ) {\n\t\t// The element may not support selection setting.\n\t\tif ( typeof container.selectionStart !== 'number' ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( isReverse ) {\n\t\t\tcontainer.selectionStart = container.value.length;\n\t\t\tcontainer.selectionEnd = container.value.length;\n\t\t} else {\n\t\t\tcontainer.selectionStart = 0;\n\t\t\tcontainer.selectionEnd = 0;\n\t\t}\n\n\t\treturn;\n\t}\n\n\tif ( ! container.isContentEditable ) {\n\t\treturn;\n\t}\n\n\tlet range = getRange( container, isReverse, x );\n\n\t// If no range range can be created or it is outside the container, the\n\t// element may be out of view.\n\tif (\n\t\t! range ||\n\t\t! range.startContainer ||\n\t\t! container.contains( range.startContainer )\n\t) {\n\t\tcontainer.scrollIntoView( isReverse );\n\t\trange = range = getRange( container, isReverse, x );\n\n\t\tif (\n\t\t\t! range ||\n\t\t\t! range.startContainer ||\n\t\t\t! container.contains( range.startContainer )\n\t\t) {\n\t\t\treturn;\n\t\t}\n\t}\n\n\tconst { ownerDocument } = container;\n\tconst { defaultView } = ownerDocument;\n\tassertIsDefined( defaultView, 'defaultView' );\n\tconst selection = defaultView.getSelection();\n\tassertIsDefined( selection, 'selection' );\n\tselection.removeAllRanges();\n\tselection.addRange( range );\n}\n"]}
|
@@ -7,101 +7,19 @@ Object.defineProperty(exports, "__esModule", {
|
|
7
7
|
});
|
8
8
|
exports.default = placeCaretAtHorizontalEdge;
|
9
9
|
|
10
|
-
var
|
11
|
-
|
12
|
-
var _hiddenCaretRangeFromPoint = _interopRequireDefault(require("./hidden-caret-range-from-point"));
|
13
|
-
|
14
|
-
var _isInputOrTextArea = _interopRequireDefault(require("./is-input-or-text-area"));
|
15
|
-
|
16
|
-
var _isRtl = _interopRequireDefault(require("./is-rtl"));
|
17
|
-
|
18
|
-
/**
|
19
|
-
* Internal dependencies
|
20
|
-
*/
|
10
|
+
var _placeCaretAtEdge = _interopRequireDefault(require("./place-caret-at-edge"));
|
21
11
|
|
22
12
|
/**
|
23
13
|
* Internal dependencies
|
24
14
|
*/
|
25
15
|
|
26
|
-
/**
|
27
|
-
* Gets the range to place.
|
28
|
-
*
|
29
|
-
* @param {HTMLElement} container Focusable element.
|
30
|
-
* @param {boolean} isReverse True for end, false for start.
|
31
|
-
*
|
32
|
-
* @return {Range|null} The range to place.
|
33
|
-
*/
|
34
|
-
function getRange(container, isReverse) {
|
35
|
-
const {
|
36
|
-
ownerDocument
|
37
|
-
} = container; // In the case of RTL scripts, the horizontal edge is at the opposite side.
|
38
|
-
|
39
|
-
const isReverseDir = (0, _isRtl.default)(container) ? !isReverse : isReverse;
|
40
|
-
const containerRect = container.getBoundingClientRect(); // When placing at the end (isReverse), find the closest range to the bottom
|
41
|
-
// right corner. When placing at the start, to the top left corner.
|
42
|
-
|
43
|
-
const x = isReverse ? containerRect.right - 1 : containerRect.left + 1;
|
44
|
-
const y = isReverseDir ? containerRect.bottom - 1 : containerRect.top + 1;
|
45
|
-
return (0, _hiddenCaretRangeFromPoint.default)(ownerDocument, x, y, container);
|
46
|
-
}
|
47
16
|
/**
|
48
17
|
* Places the caret at start or end of a given element.
|
49
18
|
*
|
50
19
|
* @param {HTMLElement} container Focusable element.
|
51
20
|
* @param {boolean} isReverse True for end, false for start.
|
52
21
|
*/
|
53
|
-
|
54
|
-
|
55
22
|
function placeCaretAtHorizontalEdge(container, isReverse) {
|
56
|
-
|
57
|
-
return;
|
58
|
-
}
|
59
|
-
|
60
|
-
container.focus();
|
61
|
-
|
62
|
-
if ((0, _isInputOrTextArea.default)(container)) {
|
63
|
-
// The element may not support selection setting.
|
64
|
-
if (typeof container.selectionStart !== 'number') {
|
65
|
-
return;
|
66
|
-
}
|
67
|
-
|
68
|
-
if (isReverse) {
|
69
|
-
container.selectionStart = container.value.length;
|
70
|
-
container.selectionEnd = container.value.length;
|
71
|
-
} else {
|
72
|
-
container.selectionStart = 0;
|
73
|
-
container.selectionEnd = 0;
|
74
|
-
}
|
75
|
-
|
76
|
-
return;
|
77
|
-
}
|
78
|
-
|
79
|
-
if (!container.isContentEditable) {
|
80
|
-
return;
|
81
|
-
}
|
82
|
-
|
83
|
-
let range = getRange(container, isReverse); // If no range range can be created or it is outside the container, the
|
84
|
-
// element may be out of view.
|
85
|
-
|
86
|
-
if (!range || !range.startContainer || !container.contains(range.startContainer)) {
|
87
|
-
container.scrollIntoView(isReverse);
|
88
|
-
range = getRange(container, isReverse);
|
89
|
-
|
90
|
-
if (!range || !range.startContainer || !container.contains(range.startContainer)) {
|
91
|
-
return;
|
92
|
-
}
|
93
|
-
}
|
94
|
-
|
95
|
-
const {
|
96
|
-
ownerDocument
|
97
|
-
} = container;
|
98
|
-
const {
|
99
|
-
defaultView
|
100
|
-
} = ownerDocument;
|
101
|
-
(0, _assertIsDefined.assertIsDefined)(defaultView, 'defaultView');
|
102
|
-
const selection = defaultView.getSelection();
|
103
|
-
(0, _assertIsDefined.assertIsDefined)(selection, 'selection');
|
104
|
-
selection.removeAllRanges();
|
105
|
-
selection.addRange(range);
|
23
|
+
return (0, _placeCaretAtEdge.default)(container, isReverse, undefined);
|
106
24
|
}
|
107
25
|
//# sourceMappingURL=place-caret-at-horizontal-edge.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["@wordpress/dom/src/dom/place-caret-at-horizontal-edge.js"],"names":["
|
1
|
+
{"version":3,"sources":["@wordpress/dom/src/dom/place-caret-at-horizontal-edge.js"],"names":["placeCaretAtHorizontalEdge","container","isReverse","undefined"],"mappings":";;;;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,0BAAT,CAAqCC,SAArC,EAAgDC,SAAhD,EAA4D;AAC1E,SAAO,+BAAkBD,SAAlB,EAA6BC,SAA7B,EAAwCC,SAAxC,CAAP;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport placeCaretAtEdge from './place-caret-at-edge';\n\n/**\n * Places the caret at start or end of a given element.\n *\n * @param {HTMLElement} container Focusable element.\n * @param {boolean} isReverse True for end, false for start.\n */\nexport default function placeCaretAtHorizontalEdge( container, isReverse ) {\n\treturn placeCaretAtEdge( container, isReverse, undefined );\n}\n"]}
|
@@ -7,11 +7,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
7
7
|
});
|
8
8
|
exports.default = placeCaretAtVerticalEdge;
|
9
9
|
|
10
|
-
var
|
11
|
-
|
12
|
-
var _hiddenCaretRangeFromPoint = _interopRequireDefault(require("./hidden-caret-range-from-point"));
|
13
|
-
|
14
|
-
var _assertIsDefined = require("../utils/assert-is-defined");
|
10
|
+
var _placeCaretAtEdge = _interopRequireDefault(require("./place-caret-at-edge"));
|
15
11
|
|
16
12
|
/**
|
17
13
|
* Internal dependencies
|
@@ -20,57 +16,11 @@ var _assertIsDefined = require("../utils/assert-is-defined");
|
|
20
16
|
/**
|
21
17
|
* Places the caret at the top or bottom of a given element.
|
22
18
|
*
|
23
|
-
* @param {HTMLElement} container
|
24
|
-
* @param {boolean} isReverse
|
25
|
-
* @param {DOMRect} [rect]
|
26
|
-
* @param {boolean} [mayUseScroll=true] True to allow scrolling, false to disallow.
|
19
|
+
* @param {HTMLElement} container Focusable element.
|
20
|
+
* @param {boolean} isReverse True for bottom, false for top.
|
21
|
+
* @param {DOMRect} [rect] The rectangle to position the caret with.
|
27
22
|
*/
|
28
|
-
function placeCaretAtVerticalEdge(container, isReverse, rect
|
29
|
-
|
30
|
-
return;
|
31
|
-
}
|
32
|
-
|
33
|
-
if (!rect || !container.isContentEditable) {
|
34
|
-
(0, _placeCaretAtHorizontalEdge.default)(container, isReverse);
|
35
|
-
return;
|
36
|
-
}
|
37
|
-
|
38
|
-
container.focus(); // Offset by a buffer half the height of the caret rect. This is needed
|
39
|
-
// because caretRangeFromPoint may default to the end of the selection if
|
40
|
-
// offset is too close to the edge. It's unclear how to precisely calculate
|
41
|
-
// this threshold; it may be the padded area of some combination of line
|
42
|
-
// height, caret height, and font size. The buffer offset is effectively
|
43
|
-
// equivalent to a point at half the height of a line of text.
|
44
|
-
|
45
|
-
const buffer = rect.height / 2;
|
46
|
-
const editableRect = container.getBoundingClientRect();
|
47
|
-
const x = rect.left;
|
48
|
-
const y = isReverse ? editableRect.bottom - buffer : editableRect.top + buffer;
|
49
|
-
const {
|
50
|
-
ownerDocument
|
51
|
-
} = container;
|
52
|
-
const {
|
53
|
-
defaultView
|
54
|
-
} = ownerDocument;
|
55
|
-
const range = (0, _hiddenCaretRangeFromPoint.default)(ownerDocument, x, y, container);
|
56
|
-
|
57
|
-
if (!range || !container.contains(range.startContainer)) {
|
58
|
-
if (mayUseScroll && (!range || !range.startContainer || !range.startContainer.contains(container))) {
|
59
|
-
// Might be out of view.
|
60
|
-
// Easier than attempting to calculate manually.
|
61
|
-
container.scrollIntoView(isReverse);
|
62
|
-
placeCaretAtVerticalEdge(container, isReverse, rect, false);
|
63
|
-
return;
|
64
|
-
}
|
65
|
-
|
66
|
-
(0, _placeCaretAtHorizontalEdge.default)(container, isReverse);
|
67
|
-
return;
|
68
|
-
}
|
69
|
-
|
70
|
-
(0, _assertIsDefined.assertIsDefined)(defaultView, 'defaultView');
|
71
|
-
const selection = defaultView.getSelection();
|
72
|
-
(0, _assertIsDefined.assertIsDefined)(selection, 'selection');
|
73
|
-
selection.removeAllRanges();
|
74
|
-
selection.addRange(range);
|
23
|
+
function placeCaretAtVerticalEdge(container, isReverse, rect) {
|
24
|
+
return (0, _placeCaretAtEdge.default)(container, isReverse, rect === null || rect === void 0 ? void 0 : rect.left);
|
75
25
|
}
|
76
26
|
//# sourceMappingURL=place-caret-at-vertical-edge.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["@wordpress/dom/src/dom/place-caret-at-vertical-edge.js"],"names":["placeCaretAtVerticalEdge","container","isReverse","rect","
|
1
|
+
{"version":3,"sources":["@wordpress/dom/src/dom/place-caret-at-vertical-edge.js"],"names":["placeCaretAtVerticalEdge","container","isReverse","rect","left"],"mappings":";;;;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,wBAAT,CAAmCC,SAAnC,EAA8CC,SAA9C,EAAyDC,IAAzD,EAAgE;AAC9E,SAAO,+BAAkBF,SAAlB,EAA6BC,SAA7B,EAAwCC,IAAxC,aAAwCA,IAAxC,uBAAwCA,IAAI,CAAEC,IAA9C,CAAP;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport placeCaretAtEdge from './place-caret-at-edge';\n\n/**\n * Places the caret at the top or bottom of a given element.\n *\n * @param {HTMLElement} container Focusable element.\n * @param {boolean} isReverse True for bottom, false for top.\n * @param {DOMRect} [rect] The rectangle to position the caret with.\n */\nexport default function placeCaretAtVerticalEdge( container, isReverse, rect ) {\n\treturn placeCaretAtEdge( container, isReverse, rect?.left );\n}\n"]}
|
package/build/dom/strip-html.js
CHANGED
@@ -1,10 +1,18 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4
|
+
|
3
5
|
Object.defineProperty(exports, "__esModule", {
|
4
6
|
value: true
|
5
7
|
});
|
6
8
|
exports.default = stripHTML;
|
7
9
|
|
10
|
+
var _safeHtml = _interopRequireDefault(require("./safe-html"));
|
11
|
+
|
12
|
+
/**
|
13
|
+
* Internal dependencies
|
14
|
+
*/
|
15
|
+
|
8
16
|
/**
|
9
17
|
* Removes any HTML tags from the provided string.
|
10
18
|
*
|
@@ -13,7 +21,11 @@ exports.default = stripHTML;
|
|
13
21
|
* @return {string} The text content with any html removed.
|
14
22
|
*/
|
15
23
|
function stripHTML(html) {
|
16
|
-
|
17
|
-
|
24
|
+
// Remove any script tags or on* attributes otherwise their *contents* will be left
|
25
|
+
// in place following removal of HTML tags.
|
26
|
+
html = (0, _safeHtml.default)(html);
|
27
|
+
const doc = document.implementation.createHTMLDocument('');
|
28
|
+
doc.body.innerHTML = html;
|
29
|
+
return doc.body.textContent || '';
|
18
30
|
}
|
19
31
|
//# sourceMappingURL=strip-html.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["@wordpress/dom/src/dom/strip-html.js"],"names":["stripHTML","html","
|
1
|
+
{"version":3,"sources":["@wordpress/dom/src/dom/strip-html.js"],"names":["stripHTML","html","doc","document","implementation","createHTMLDocument","body","innerHTML","textContent"],"mappings":";;;;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,SAAT,CAAoBC,IAApB,EAA2B;AACzC;AACA;AACAA,EAAAA,IAAI,GAAG,uBAAUA,IAAV,CAAP;AAEA,QAAMC,GAAG,GAAGC,QAAQ,CAACC,cAAT,CAAwBC,kBAAxB,CAA4C,EAA5C,CAAZ;AACAH,EAAAA,GAAG,CAACI,IAAJ,CAASC,SAAT,GAAqBN,IAArB;AACA,SAAOC,GAAG,CAACI,IAAJ,CAASE,WAAT,IAAwB,EAA/B;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport safeHTML from './safe-html';\n\n/**\n * Removes any HTML tags from the provided string.\n *\n * @param {string} html The string containing html.\n *\n * @return {string} The text content with any html removed.\n */\nexport default function stripHTML( html ) {\n\t// Remove any script tags or on* attributes otherwise their *contents* will be left\n\t// in place following removal of HTML tags.\n\thtml = safeHTML( html );\n\n\tconst doc = document.implementation.createHTMLDocument( '' );\n\tdoc.body.innerHTML = html;\n\treturn doc.body.textContent || '';\n}\n"]}
|
package/build/focusable.js
CHANGED
@@ -23,31 +23,33 @@ exports.find = find;
|
|
23
23
|
* AREA elements associated with an IMG:
|
24
24
|
* - https://w3c.github.io/html/editing.html#data-model
|
25
25
|
*/
|
26
|
-
|
26
|
+
|
27
27
|
/**
|
28
|
-
* Returns
|
29
|
-
* nor visibility: hidden).
|
28
|
+
* Returns a CSS selector used to query for focusable elements.
|
30
29
|
*
|
31
|
-
* @param {
|
30
|
+
* @param {boolean} sequential If set, only query elements that are sequentially
|
31
|
+
* focusable. Non-interactive elements with a
|
32
|
+
* negative `tabindex` are focusable but not
|
33
|
+
* sequentially focusable.
|
34
|
+
* https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute
|
32
35
|
*
|
33
|
-
* @return {
|
36
|
+
* @return {string} CSS selector.
|
34
37
|
*/
|
35
|
-
|
36
|
-
|
37
|
-
return element.offsetWidth > 0 || element.offsetHeight > 0 || element.getClientRects().length > 0;
|
38
|
+
function buildSelector(sequential) {
|
39
|
+
return [sequential ? '[tabindex]:not([tabindex^="-"])' : '[tabindex]', 'a[href]', 'button:not([disabled])', 'input:not([type="hidden"]):not([disabled])', 'select:not([disabled])', 'textarea:not([disabled])', 'iframe:not([tabindex^="-"])', 'object', 'embed', 'area[href]', '[contenteditable]:not([contenteditable=false])'].join(',');
|
38
40
|
}
|
39
41
|
/**
|
40
|
-
* Returns true if the specified element
|
41
|
-
*
|
42
|
+
* Returns true if the specified element is visible (i.e. neither display: none
|
43
|
+
* nor visibility: hidden).
|
42
44
|
*
|
43
|
-
* @param {
|
45
|
+
* @param {HTMLElement} element DOM element to test.
|
44
46
|
*
|
45
|
-
* @return {boolean} Whether element
|
47
|
+
* @return {boolean} Whether element is visible.
|
46
48
|
*/
|
47
49
|
|
48
50
|
|
49
|
-
function
|
50
|
-
return element.
|
51
|
+
function isVisible(element) {
|
52
|
+
return element.offsetWidth > 0 || element.offsetHeight > 0 || element.getClientRects().length > 0;
|
51
53
|
}
|
52
54
|
/**
|
53
55
|
* Returns true if the specified area element is a valid focusable element, or
|
@@ -76,21 +78,30 @@ function isValidFocusableArea(element) {
|
|
76
78
|
/**
|
77
79
|
* Returns all focusable elements within a given context.
|
78
80
|
*
|
79
|
-
* @param {Element} context
|
81
|
+
* @param {Element} context Element in which to search.
|
82
|
+
* @param {Object} [options]
|
83
|
+
* @param {boolean} [options.sequential] If set, only return elements that are
|
84
|
+
* sequentially focusable.
|
85
|
+
* Non-interactive elements with a
|
86
|
+
* negative `tabindex` are focusable but
|
87
|
+
* not sequentially focusable.
|
88
|
+
* https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute
|
80
89
|
*
|
81
90
|
* @return {Element[]} Focusable elements.
|
82
91
|
*/
|
83
92
|
|
84
93
|
|
85
|
-
function find(context
|
94
|
+
function find(context, {
|
95
|
+
sequential = false
|
96
|
+
} = {}) {
|
86
97
|
/* eslint-disable jsdoc/no-undefined-types */
|
87
98
|
|
88
99
|
/** @type {NodeListOf<HTMLElement>} */
|
89
100
|
|
90
101
|
/* eslint-enable jsdoc/no-undefined-types */
|
91
|
-
const elements = context.querySelectorAll(
|
102
|
+
const elements = context.querySelectorAll(buildSelector(sequential));
|
92
103
|
return Array.from(elements).filter(element => {
|
93
|
-
if (!isVisible(element)
|
104
|
+
if (!isVisible(element)) {
|
94
105
|
return false;
|
95
106
|
}
|
96
107
|
|