@wordpress/dom 3.2.2-next.5df0cd52b7.0 → 3.2.5

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.
Files changed (58) hide show
  1. package/README.md +0 -1
  2. package/build/dom/caret-range-from-point.js +7 -3
  3. package/build/dom/caret-range-from-point.js.map +1 -1
  4. package/build/dom/is-edge.js +1 -1
  5. package/build/dom/is-edge.js.map +1 -1
  6. package/build/dom/place-caret-at-edge.js +108 -0
  7. package/build/dom/place-caret-at-edge.js.map +1 -0
  8. package/build/dom/place-caret-at-horizontal-edge.js +2 -84
  9. package/build/dom/place-caret-at-horizontal-edge.js.map +1 -1
  10. package/build/dom/place-caret-at-vertical-edge.js +6 -56
  11. package/build/dom/place-caret-at-vertical-edge.js.map +1 -1
  12. package/build/focusable.js +29 -18
  13. package/build/focusable.js.map +1 -1
  14. package/build/phrasing-content.js +1 -1
  15. package/build/phrasing-content.js.map +1 -1
  16. package/build/tabbable.js +2 -2
  17. package/build/tabbable.js.map +1 -1
  18. package/build-module/dom/caret-range-from-point.js +7 -3
  19. package/build-module/dom/caret-range-from-point.js.map +1 -1
  20. package/build-module/dom/is-edge.js +1 -1
  21. package/build-module/dom/is-edge.js.map +1 -1
  22. package/build-module/dom/place-caret-at-edge.js +95 -0
  23. package/build-module/dom/place-caret-at-edge.js.map +1 -0
  24. package/build-module/dom/place-caret-at-horizontal-edge.js +2 -81
  25. package/build-module/dom/place-caret-at-horizontal-edge.js.map +1 -1
  26. package/build-module/dom/place-caret-at-vertical-edge.js +6 -54
  27. package/build-module/dom/place-caret-at-vertical-edge.js.map +1 -1
  28. package/build-module/focusable.js +29 -18
  29. package/build-module/focusable.js.map +1 -1
  30. package/build-module/phrasing-content.js +1 -1
  31. package/build-module/phrasing-content.js.map +1 -1
  32. package/build-module/tabbable.js +2 -2
  33. package/build-module/tabbable.js.map +1 -1
  34. package/build-types/dom/caret-range-from-point.d.ts +12 -4
  35. package/build-types/dom/caret-range-from-point.d.ts.map +1 -1
  36. package/build-types/dom/is-edge.d.ts.map +1 -1
  37. package/build-types/dom/place-caret-at-edge.d.ts +9 -0
  38. package/build-types/dom/place-caret-at-edge.d.ts.map +1 -0
  39. package/build-types/dom/place-caret-at-horizontal-edge.d.ts.map +1 -1
  40. package/build-types/dom/place-caret-at-vertical-edge.d.ts +4 -5
  41. package/build-types/dom/place-caret-at-vertical-edge.d.ts.map +1 -1
  42. package/build-types/focusable.d.ts +11 -2
  43. package/build-types/focusable.d.ts.map +1 -1
  44. package/build-types/phrasing-content.d.ts +2 -4
  45. package/build-types/phrasing-content.d.ts.map +1 -1
  46. package/build-types/tabbable.d.ts +3 -3
  47. package/build-types/tabbable.d.ts.map +1 -1
  48. package/package.json +2 -2
  49. package/src/dom/caret-range-from-point.js +8 -3
  50. package/src/dom/is-edge.js +4 -1
  51. package/src/dom/place-caret-at-edge.js +95 -0
  52. package/src/dom/place-caret-at-horizontal-edge.js +2 -83
  53. package/src/dom/place-caret-at-vertical-edge.js +6 -64
  54. package/src/focusable.js +37 -32
  55. package/src/phrasing-content.js +1 -1
  56. package/src/tabbable.js +2 -4
  57. package/src/test/dom.js +8 -0
  58. package/tsconfig.tsbuildinfo +1 -1170
package/README.md CHANGED
@@ -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 {Document} 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.
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 {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 *\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"]}
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"]}
@@ -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
  }
@@ -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,MAAK,gCAAmBF,SAAnB,CAAL,EAAsC;AACrC,QAAKA,SAAS,CAACG,cAAV,KAA6BH,SAAS,CAACI,YAA5C,EAA2D;AAC1D,aAAO,KAAP;AACA;;AAED,QAAKH,SAAL,EAAiB;AAChB,aAAOD,SAAS,CAACG,cAAV,KAA6B,CAApC;AACA;;AAED,WAAOH,SAAS,CAACK,KAAV,CAAgBC,MAAhB,KAA2BN,SAAS,CAACG,cAA5C;AACA;;AAED,MAAK;AAAG;AAA6BH,EAAAA,SAAF,CAAcO,iBAAjD,EAAsE;AACrE,WAAO,IAAP;AACA;;AAED,QAAM;AAAEC,IAAAA;AAAF,MAAoBR,SAA1B;AACA,QAAM;AAAES,IAAAA;AAAF,MAAkBD,aAAxB;AAEA,wCAAiBC,WAAjB,EAA8B,aAA9B;AACA,QAAMC,SAAS,GAAGD,WAAW,CAACE,YAAZ,EAAlB;;AAEA,MAAK,CAAED,SAAF,IAAe,CAAEA,SAAS,CAACE,UAAhC,EAA6C;AAC5C,WAAO,KAAP;AACA;;AAED,QAAMC,KAAK,GAAGH,SAAS,CAACI,UAAV,CAAsB,CAA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AmB;AAClB,WAAO,KAAP;AACA;;AAED,QAAMC,QAAQ,GAAG,oCAAuBD,SAAvB,CAAjB;;AAEA,MAAK,CAAEC,QAAP,EAAkB;AACjB,WAAO,KAAP;AACA;;AAED,QAAMC,YAAY,GAAGlC,SAAS,GAAG,KAAH,GAAW,QAAzC;AACA,QAAMmC,cAAc,GAAGZ,YAAY,GAAG,MAAH,GAAY,OAA/C;AACA,QAAMa,YAAY,GAAGH,QAAQ,CAAEC,YAAF,CAAR,GAA2Bd,SAAS,CAAEc,YAAF,CAAzD;AACA,QAAMG,cAAc,GACnBJ,QAAQ,CAAEE,cAAF,CAAR,GAA6BhB,kBAAkB,CAAEgB,cAAF,CADhD,CA7F4E,CAgG5E;;AACA,QAAMG,eAAe,GAAGC,IAAI,CAACC,GAAL,CAAUJ,YAAV,KAA4B,CAApD;AACA,QAAMK,iBAAiB,GAAGF,IAAI,CAACC,GAAL,CAAUH,cAAV,KAA8B,CAAxD;AAEA,SAAOpC,YAAY,GAChBqC,eADgB,GAEhBA,eAAe,IAAIG,iBAFtB;AAGA","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 ( isInputOrTextArea( container ) ) {\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"]}
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,MACC,gCAAmBF,SAAnB,KACA,OAAO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iBAAiB,GAAGF,IAAI,CAACC,GAAL,CAAUH,cAAV,KAA8B,CAAxD;AAEA,SAAOpC,YAAY,GAChBqC,eADgB,GAEhBA,eAAe,IAAIG,iBAFtB;AAGA","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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,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 _assertIsDefined = require("../utils/assert-is-defined");
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
- if (!container) {
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":["getRange","container","isReverse","ownerDocument","isReverseDir","containerRect","getBoundingClientRect","x","right","left","y","bottom","top","placeCaretAtHorizontalEdge","focus","selectionStart","value","length","selectionEnd","isContentEditable","range","startContainer","contains","scrollIntoView","defaultView","selection","getSelection","removeAllRanges","addRange"],"mappings":";;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;AAVA;AACA;AACA;;AAGA;AACA;AACA;;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,QAAT,CAAmBC,SAAnB,EAA8BC,SAA9B,EAA0C;AACzC,QAAM;AAAEC,IAAAA;AAAF,MAAoBF,SAA1B,CADyC,CAEzC;;AACA,Q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,CAACC,cADR,IAEA,CAAEpB,SAAS,CAACqB,QAAV,CAAoBF,KAAK,CAACC,cAA1B,CAHH,EAIE;AACDpB,IAAAA,SAAS,CAACsB,cAAV,CAA0BrB,SAA1B;AACAkB,IAAAA,KAAK,GAAGpB,QAAQ,CAAEC,SAAF,EAAaC,SAAb,CAAhB;;AAEA,QACC,CAAEkB,KAAF,IACA,CAAEA,KAAK,CAACC,cADR,IAEA,CAAEpB,SAAS,CAACqB,QAAV,CAAoBF,KAAK,CAACC,cAA1B,CAHH,EAIE;AACD;AACA;AACD;;AAED,QAAM;AAAElB,IAAAA;AAAF,MAAoBF,SAA1B;AACA,QAAM;AAAEuB,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 { assertIsDefined } from '../utils/assert-is-defined';\n\n/**\n * Internal dependencies\n */\nimport hiddenCaretRangeFromPoint from './hidden-caret-range-from-point';\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 *\n * @return {Range|null} The range to place.\n */\nfunction getRange( container, isReverse ) {\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\tconst x = isReverse ? containerRect.right - 1 : containerRect.left + 1;\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 */\nexport default function placeCaretAtHorizontalEdge( container, isReverse ) {\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 );\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 = getRange( container, isReverse );\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"]}
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 _placeCaretAtHorizontalEdge = _interopRequireDefault(require("./place-caret-at-horizontal-edge"));
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 Focusable element.
24
- * @param {boolean} isReverse True for bottom, false for top.
25
- * @param {DOMRect} [rect] The rectangle to position the caret with.
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, mayUseScroll = true) {
29
- if (!container) {
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","mayUseScroll","isContentEditable","focus","buffer","height","editableRect","getBoundingClientRect","x","left","y","bottom","top","ownerDocument","defaultView","range","contains","startContainer","scrollIntoView","selection","getSelection","removeAllRanges","addRange"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AALA;AACA;AACA;;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,wBAAT,CACdC,SADc,EAEdC,SAFc,EAGdC,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WAAW,CAACM,YAAZ,EAAlB;AACA,wCAAiBD,SAAjB,EAA4B,WAA5B;AACAA,EAAAA,SAAS,CAACE,eAAV;AACAF,EAAAA,SAAS,CAACG,QAAV,CAAoBP,KAApB;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport placeCaretAtHorizontalEdge from './place-caret-at-horizontal-edge';\nimport hiddenCaretRangeFromPoint from './hidden-caret-range-from-point';\nimport { assertIsDefined } from '../utils/assert-is-defined';\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 * @param {boolean} [mayUseScroll=true] True to allow scrolling, false to disallow.\n */\nexport default function placeCaretAtVerticalEdge(\n\tcontainer,\n\tisReverse,\n\trect,\n\tmayUseScroll = true\n) {\n\tif ( ! container ) {\n\t\treturn;\n\t}\n\n\tif ( ! rect || ! container.isContentEditable ) {\n\t\tplaceCaretAtHorizontalEdge( container, isReverse );\n\t\treturn;\n\t}\n\n\tcontainer.focus();\n\n\t// Offset by a buffer half the height of the caret rect. This is needed\n\t// because caretRangeFromPoint may default to the end of the selection if\n\t// offset is too close to the edge. It's unclear how to precisely calculate\n\t// this threshold; it may be the padded area of some combination of line\n\t// height, caret height, and font size. The buffer offset is effectively\n\t// equivalent to a point at half the height of a line of text.\n\tconst buffer = rect.height / 2;\n\tconst editableRect = container.getBoundingClientRect();\n\tconst x = rect.left;\n\tconst y = isReverse\n\t\t? editableRect.bottom - buffer\n\t\t: editableRect.top + buffer;\n\n\tconst { ownerDocument } = container;\n\tconst { defaultView } = ownerDocument;\n\tconst range = hiddenCaretRangeFromPoint( ownerDocument, x, y, container );\n\n\tif ( ! range || ! container.contains( range.startContainer ) ) {\n\t\tif (\n\t\t\tmayUseScroll &&\n\t\t\t( ! range ||\n\t\t\t\t! range.startContainer ||\n\t\t\t\t! range.startContainer.contains( container ) )\n\t\t) {\n\t\t\t// Might be out of view.\n\t\t\t// Easier than attempting to calculate manually.\n\t\t\tcontainer.scrollIntoView( isReverse );\n\t\t\tplaceCaretAtVerticalEdge( container, isReverse, rect, false );\n\t\t\treturn;\n\t\t}\n\n\t\tplaceCaretAtHorizontalEdge( container, isReverse );\n\t\treturn;\n\t}\n\n\tassertIsDefined( defaultView, 'defaultView' );\n\tconst selection = defaultView.getSelection();\n\tassertIsDefined( selection, 'selection' );\n\tselection.removeAllRanges();\n\tselection.addRange( range );\n}\n"]}
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"]}
@@ -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
- const SELECTOR = ['[tabindex]', 'a[href]', 'button:not([disabled])', 'input:not([type="hidden"]):not([disabled])', 'select:not([disabled])', 'textarea:not([disabled])', 'iframe', 'object', 'embed', 'area[href]', '[contenteditable]:not([contenteditable=false])'].join(',');
26
+
27
27
  /**
28
- * Returns true if the specified element is visible (i.e. neither display: none
29
- * nor visibility: hidden).
28
+ * Returns a CSS selector used to query for focusable elements.
30
29
  *
31
- * @param {HTMLElement} element DOM element to test.
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 {boolean} Whether element is visible.
36
+ * @return {string} CSS selector.
34
37
  */
35
-
36
- function isVisible(element) {
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 should be skipped from focusable elements.
41
- * For now it rather specific for `iframes` and if tabindex attribute is set to -1.
42
+ * Returns true if the specified element is visible (i.e. neither display: none
43
+ * nor visibility: hidden).
42
44
  *
43
- * @param {Element} element DOM element to test.
45
+ * @param {HTMLElement} element DOM element to test.
44
46
  *
45
- * @return {boolean} Whether element should be skipped from focusable elements.
47
+ * @return {boolean} Whether element is visible.
46
48
  */
47
49
 
48
50
 
49
- function skipFocus(element) {
50
- return element.nodeName.toLowerCase() === 'iframe' && element.getAttribute('tabindex') === '-1';
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 Element in which to search.
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(SELECTOR);
102
+ const elements = context.querySelectorAll(buildSelector(sequential));
92
103
  return Array.from(elements).filter(element => {
93
- if (!isVisible(element) || skipFocus(element)) {
104
+ if (!isVisible(element)) {
94
105
  return false;
95
106
  }
96
107
 
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/dom/src/focusable.js"],"names":["SELECTOR","join","isVisible","element","offsetWidth","offsetHeight","getClientRects","length","skipFocus","nodeName","toLowerCase","getAttribute","isValidFocusableArea","map","closest","img","ownerDocument","querySelector","name","find","context","elements","querySelectorAll","Array","from","filter"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA,MAAMA,QAAQ,GAAG,CAChB,YADgB,EAEhB,SAFgB,EAGhB,wBAHgB,EAIhB,4CAJgB,EAKhB,wBALgB,EAMhB,0BANgB,EAOhB,QAPgB,EAQhB,QARgB,EAShB,OATgB,EAUhB,YAVgB,EAWhB,gDAXgB,EAYfC,IAZe,CAYT,GAZS,CAAjB;AAcA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,SAAT,CAAoBC,OAApB,EAA8B;AAC7B,SACCA,OAAO,CAACC,WAAR,GAAsB,CAAtB,IACAD,OAAO,CAACE,YAAR,GAAuB,CADvB,IAEAF,OAAO,CAACG,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R/html5/editing.html#focus-management\n *\n * Sequential focus navigation:\n * - https://www.w3.org/TR/html5/editing.html#sequential-focus-navigation-and-the-tabindex-attribute\n *\n * Disabled elements:\n * - https://www.w3.org/TR/html5/disabled-elements.html#disabled-elements\n *\n * getClientRects algorithm (requiring layout box):\n * - https://www.w3.org/TR/cssom-view-1/#extension-to-the-element-interface\n *\n * AREA elements associated with an IMG:\n * - https://w3c.github.io/html/editing.html#data-model\n */\n\nconst SELECTOR = [\n\t'[tabindex]',\n\t'a[href]',\n\t'button:not([disabled])',\n\t'input:not([type=\"hidden\"]):not([disabled])',\n\t'select:not([disabled])',\n\t'textarea:not([disabled])',\n\t'iframe',\n\t'object',\n\t'embed',\n\t'area[href]',\n\t'[contenteditable]:not([contenteditable=false])',\n].join( ',' );\n\n/**\n * Returns true if the specified element is visible (i.e. neither display: none\n * nor visibility: hidden).\n *\n * @param {HTMLElement} element DOM element to test.\n *\n * @return {boolean} Whether element is visible.\n */\nfunction isVisible( element ) {\n\treturn (\n\t\telement.offsetWidth > 0 ||\n\t\telement.offsetHeight > 0 ||\n\t\telement.getClientRects().length > 0\n\t);\n}\n\n/**\n * Returns true if the specified element should be skipped from focusable elements.\n * For now it rather specific for `iframes` and if tabindex attribute is set to -1.\n *\n * @param {Element} element DOM element to test.\n *\n * @return {boolean} Whether element should be skipped from focusable elements.\n */\nfunction skipFocus( element ) {\n\treturn (\n\t\telement.nodeName.toLowerCase() === 'iframe' &&\n\t\telement.getAttribute( 'tabindex' ) === '-1'\n\t);\n}\n\n/**\n * Returns true if the specified area element is a valid focusable element, or\n * false otherwise. Area is only focusable if within a map where a named map\n * referenced by an image somewhere in the document.\n *\n * @param {HTMLAreaElement} element DOM area element to test.\n *\n * @return {boolean} Whether area element is valid for focus.\n */\nfunction isValidFocusableArea( element ) {\n\t/** @type {HTMLMapElement | null} */\n\tconst map = element.closest( 'map[name]' );\n\tif ( ! map ) {\n\t\treturn false;\n\t}\n\n\t/** @type {HTMLImageElement | null} */\n\tconst img = element.ownerDocument.querySelector(\n\t\t'img[usemap=\"#' + map.name + '\"]'\n\t);\n\treturn !! img && isVisible( img );\n}\n\n/**\n * Returns all focusable elements within a given context.\n *\n * @param {Element} context Element in which to search.\n *\n * @return {Element[]} Focusable elements.\n */\nexport function find( context ) {\n\t/* eslint-disable jsdoc/no-undefined-types */\n\t/** @type {NodeListOf<HTMLElement>} */\n\t/* eslint-enable jsdoc/no-undefined-types */\n\tconst elements = context.querySelectorAll( SELECTOR );\n\n\treturn Array.from( elements ).filter( ( element ) => {\n\t\tif ( ! isVisible( element ) || skipFocus( element ) ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst { nodeName } = element;\n\t\tif ( 'AREA' === nodeName ) {\n\t\t\treturn isValidFocusableArea(\n\t\t\t\t/** @type {HTMLAreaElement} */ ( element )\n\t\t\t);\n\t\t}\n\n\t\treturn true;\n\t} );\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/dom/src/focusable.js"],"names":["buildSelector","sequential","join","isVisible","element","offsetWidth","offsetHeight","getClientRects","length","isValidFocusableArea","map","closest","img","ownerDocument","querySelector","name","find","context","elements","querySelectorAll","Array","from","filter","nodeName"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,aAAT,CAAwBC,UAAxB,EAAqC;AACpC,SAAO,CACNA,UAAU,GAAG,iCAAH,GAAuC,YAD3C,EAEN,SAFM,EAGN,wBAHM,EAIN,4CAJM,EAKN,wBALM,EAMN,0BANM,EAON,6BAPM,EAQN,QARM,EASN,OATM,EAUN,YAVM,EAWN,gDAXM,EAYLC,IAZK,CAYC,GAZD,CAAP;AAaA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASC,SAAT,CAAoBC,OAApB,EAA8B;AAC7B,SACCA,OAAO,CAACC,WAAR,GAAsB,CAAtB,IACAD,OAAO,CAACE,YAAR,GAAuB,CADvB,IAEAF,OAAO,CAACG,cAAR,GAAyBC,MAAzB,GAAkC,CAHnC;AAKA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASC,oBAAT,CAA+BL,OAA/B,EAAyC;AACxC;AACA,QAAMM,GAAG,GAAGN,OAAO,CAACO,OAAR,CAAiB,WAAjB,CAAZ;;AACA,MAAK,CAAED,GAAP,EAAa;AACZ,WAAO,KAAP;AACA;AAED;;;AACA,QAAME,GAAG,GAAGR,OAAO,CAACS,aAAR,CAAsBC,aAAtB,CACX,kBAAkBJ,GAAG,CAACK,IAAtB,GAA6B,IADlB,CAAZ;AAGA,SAAO,CAAC,CAAEH,GAAH,IAAUT,SAAS,CAAES,GAAF,CAA1B;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASI,IAAT,CAAeC,OAAf,EAAwB;AAAEhB,EAAAA,UAAU,GAAG;AAAf,IAAyB,EAAjD,EAAsD;AAC5D;;AACA;;AACA;AACA,QAAMiB,QAAQ,GAAGD,OAAO,CAACE,gBAAR,CAA0BnB,aAAa,CAAEC,UAAF,CAAvC,CAAjB;AAEA,SAAOmB,KAAK,CAACC,IAAN,CAAYH,QAAZ,EAAuBI,MAAvB,CAAiClB,OAAF,IAAe;AACpD,QAAK,CAAED,SAAS,CAAEC,OAAF,CAAhB,EAA8B;AAC7B,aAAO,KAAP;AACA;;AAED,UAAM;AAAEmB,MAAAA;AAAF,QAAenB,OAArB;;AACA,QAAK,WAAWmB,QAAhB,EAA2B;AAC1B,aAAOd,oBAAoB;AAC1B;AAAiCL,MAAAA,OADP,CAA3B;AAGA;;AAED,WAAO,IAAP;AACA,GAbM,CAAP;AAcA","sourcesContent":["/**\n * References:\n *\n * Focusable:\n * - https://www.w3.org/TR/html5/editing.html#focus-management\n *\n * Sequential focus navigation:\n * - https://www.w3.org/TR/html5/editing.html#sequential-focus-navigation-and-the-tabindex-attribute\n *\n * Disabled elements:\n * - https://www.w3.org/TR/html5/disabled-elements.html#disabled-elements\n *\n * getClientRects algorithm (requiring layout box):\n * - https://www.w3.org/TR/cssom-view-1/#extension-to-the-element-interface\n *\n * AREA elements associated with an IMG:\n * - https://w3c.github.io/html/editing.html#data-model\n */\n\n/**\n * Returns a CSS selector used to query for focusable elements.\n *\n * @param {boolean} sequential If set, only query elements that are sequentially\n * focusable. Non-interactive elements with a\n * negative `tabindex` are focusable but not\n * sequentially focusable.\n * https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute\n *\n * @return {string} CSS selector.\n */\nfunction buildSelector( sequential ) {\n\treturn [\n\t\tsequential ? '[tabindex]:not([tabindex^=\"-\"])' : '[tabindex]',\n\t\t'a[href]',\n\t\t'button:not([disabled])',\n\t\t'input:not([type=\"hidden\"]):not([disabled])',\n\t\t'select:not([disabled])',\n\t\t'textarea:not([disabled])',\n\t\t'iframe:not([tabindex^=\"-\"])',\n\t\t'object',\n\t\t'embed',\n\t\t'area[href]',\n\t\t'[contenteditable]:not([contenteditable=false])',\n\t].join( ',' );\n}\n\n/**\n * Returns true if the specified element is visible (i.e. neither display: none\n * nor visibility: hidden).\n *\n * @param {HTMLElement} element DOM element to test.\n *\n * @return {boolean} Whether element is visible.\n */\nfunction isVisible( element ) {\n\treturn (\n\t\telement.offsetWidth > 0 ||\n\t\telement.offsetHeight > 0 ||\n\t\telement.getClientRects().length > 0\n\t);\n}\n\n/**\n * Returns true if the specified area element is a valid focusable element, or\n * false otherwise. Area is only focusable if within a map where a named map\n * referenced by an image somewhere in the document.\n *\n * @param {HTMLAreaElement} element DOM area element to test.\n *\n * @return {boolean} Whether area element is valid for focus.\n */\nfunction isValidFocusableArea( element ) {\n\t/** @type {HTMLMapElement | null} */\n\tconst map = element.closest( 'map[name]' );\n\tif ( ! map ) {\n\t\treturn false;\n\t}\n\n\t/** @type {HTMLImageElement | null} */\n\tconst img = element.ownerDocument.querySelector(\n\t\t'img[usemap=\"#' + map.name + '\"]'\n\t);\n\treturn !! img && isVisible( img );\n}\n\n/**\n * Returns all focusable elements within a given context.\n *\n * @param {Element} context Element in which to search.\n * @param {Object} [options]\n * @param {boolean} [options.sequential] If set, only return elements that are\n * sequentially focusable.\n * Non-interactive elements with a\n * negative `tabindex` are focusable but\n * not sequentially focusable.\n * https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute\n *\n * @return {Element[]} Focusable elements.\n */\nexport function find( context, { sequential = false } = {} ) {\n\t/* eslint-disable jsdoc/no-undefined-types */\n\t/** @type {NodeListOf<HTMLElement>} */\n\t/* eslint-enable jsdoc/no-undefined-types */\n\tconst elements = context.querySelectorAll( buildSelector( sequential ) );\n\n\treturn Array.from( elements ).filter( ( element ) => {\n\t\tif ( ! isVisible( element ) ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst { nodeName } = element;\n\t\tif ( 'AREA' === nodeName ) {\n\t\t\treturn isValidFocusableArea(\n\t\t\t\t/** @type {HTMLAreaElement} */ ( element )\n\t\t\t);\n\t\t}\n\n\t\treturn true;\n\t} );\n}\n"]}
@@ -43,7 +43,7 @@ const textContentSchema = {
43
43
  del: {},
44
44
  ins: {},
45
45
  a: {
46
- attributes: ['href', 'target', 'rel']
46
+ attributes: ['href', 'target', 'rel', 'id']
47
47
  },
48
48
  code: {},
49
49
  abbr: {
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/dom/src/phrasing-content.js"],"names":["textContentSchema","strong","em","s","del","ins","a","attributes","code","abbr","sub","sup","br","small","q","dfn","data","time","var","samp","kbd","i","b","u","mark","ruby","rt","rp","bdi","bdo","wbr","Object","keys","forEach","tag","children","embeddedContentSchema","audio","canvas","embed","img","object","video","phrasingContentSchema","getPhrasingContentSchema","context","isPhrasingContent","node","nodeName","toLowerCase","hasOwnProperty","isTextContent"],"mappings":";;;;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AAC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,EAA+B;AACrC,QAAMb,GAAG,GAAGa,IAAI,CAACC,QAAL,CAAcC,WAAd,EAAZ;AACA,SAAOjD,iBAAiB,CAACkD,cAAlB,CAAkChB,GAAlC,KAA2CA,GAAG,KAAK,MAA1D;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { omit, without } from 'lodash';\n\n/**\n * All phrasing content elements.\n *\n * @see https://www.w3.org/TR/2011/WD-html5-20110525/content-models.html#phrasing-content-0\n */\n\n/**\n * @typedef {Record<string,SemanticElementDefinition>} ContentSchema\n */\n\n/**\n * @typedef SemanticElementDefinition\n * @property {string[]} [attributes] Content attributes\n * @property {ContentSchema} [children] Content attributes\n */\n\n/**\n * All text-level semantic elements.\n *\n * @see https://html.spec.whatwg.org/multipage/text-level-semantics.html\n *\n * @type {ContentSchema}\n */\nconst textContentSchema = {\n\tstrong: {},\n\tem: {},\n\ts: {},\n\tdel: {},\n\tins: {},\n\ta: { attributes: [ 'href', 'target', 'rel' ] },\n\tcode: {},\n\tabbr: { attributes: [ 'title' ] },\n\tsub: {},\n\tsup: {},\n\tbr: {},\n\tsmall: {},\n\t// To do: fix blockquote.\n\t// cite: {},\n\tq: { attributes: [ 'cite' ] },\n\tdfn: { attributes: [ 'title' ] },\n\tdata: { attributes: [ 'value' ] },\n\ttime: { attributes: [ 'datetime' ] },\n\tvar: {},\n\tsamp: {},\n\tkbd: {},\n\ti: {},\n\tb: {},\n\tu: {},\n\tmark: {},\n\truby: {},\n\trt: {},\n\trp: {},\n\tbdi: { attributes: [ 'dir' ] },\n\tbdo: { attributes: [ 'dir' ] },\n\twbr: {},\n\t'#text': {},\n};\n\n// Recursion is needed.\n// Possible: strong > em > strong.\n// Impossible: strong > strong.\nwithout( Object.keys( textContentSchema ), '#text', 'br' ).forEach( ( tag ) => {\n\ttextContentSchema[ tag ].children = omit( textContentSchema, tag );\n} );\n\n/**\n * Embedded content elements.\n *\n * @see https://www.w3.org/TR/2011/WD-html5-20110525/content-models.html#embedded-content-0\n *\n * @type {ContentSchema}\n */\nconst embeddedContentSchema = {\n\taudio: {\n\t\tattributes: [\n\t\t\t'src',\n\t\t\t'preload',\n\t\t\t'autoplay',\n\t\t\t'mediagroup',\n\t\t\t'loop',\n\t\t\t'muted',\n\t\t],\n\t},\n\tcanvas: { attributes: [ 'width', 'height' ] },\n\tembed: { attributes: [ 'src', 'type', 'width', 'height' ] },\n\timg: {\n\t\tattributes: [\n\t\t\t'alt',\n\t\t\t'src',\n\t\t\t'srcset',\n\t\t\t'usemap',\n\t\t\t'ismap',\n\t\t\t'width',\n\t\t\t'height',\n\t\t],\n\t},\n\tobject: {\n\t\tattributes: [\n\t\t\t'data',\n\t\t\t'type',\n\t\t\t'name',\n\t\t\t'usemap',\n\t\t\t'form',\n\t\t\t'width',\n\t\t\t'height',\n\t\t],\n\t},\n\tvideo: {\n\t\tattributes: [\n\t\t\t'src',\n\t\t\t'poster',\n\t\t\t'preload',\n\t\t\t'autoplay',\n\t\t\t'mediagroup',\n\t\t\t'loop',\n\t\t\t'muted',\n\t\t\t'controls',\n\t\t\t'width',\n\t\t\t'height',\n\t\t],\n\t},\n};\n\n/**\n * Phrasing content elements.\n *\n * @see https://www.w3.org/TR/2011/WD-html5-20110525/content-models.html#phrasing-content-0\n */\nconst phrasingContentSchema = {\n\t...textContentSchema,\n\t...embeddedContentSchema,\n};\n\n/**\n * Get schema of possible paths for phrasing content.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories#Phrasing_content\n *\n * @param {string} [context] Set to \"paste\" to exclude invisible elements and\n * sensitive data.\n *\n * @return {Partial<ContentSchema>} Schema.\n */\nexport function getPhrasingContentSchema( context ) {\n\tif ( context !== 'paste' ) {\n\t\treturn phrasingContentSchema;\n\t}\n\n\treturn omit(\n\t\t{\n\t\t\t...phrasingContentSchema,\n\t\t\t// We shouldn't paste potentially sensitive information which is not\n\t\t\t// visible to the user when pasted, so strip the attributes.\n\t\t\tins: { children: phrasingContentSchema.ins.children },\n\t\t\tdel: { children: phrasingContentSchema.del.children },\n\t\t},\n\t\t[\n\t\t\t'u', // Used to mark misspelling. Shouldn't be pasted.\n\t\t\t'abbr', // Invisible.\n\t\t\t'data', // Invisible.\n\t\t\t'time', // Invisible.\n\t\t\t'wbr', // Invisible.\n\t\t\t'bdi', // Invisible.\n\t\t\t'bdo', // Invisible.\n\t\t]\n\t);\n}\n\n/**\n * Find out whether or not the given node is phrasing content.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories#Phrasing_content\n *\n * @param {Node} node The node to test.\n *\n * @return {boolean} True if phrasing content, false if not.\n */\nexport function isPhrasingContent( node ) {\n\tconst tag = node.nodeName.toLowerCase();\n\treturn getPhrasingContentSchema().hasOwnProperty( tag ) || tag === 'span';\n}\n\n/**\n * @param {Node} node\n * @return {boolean} Node is text content\n */\nexport function isTextContent( node ) {\n\tconst tag = node.nodeName.toLowerCase();\n\treturn textContentSchema.hasOwnProperty( tag ) || tag === 'span';\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/dom/src/phrasing-content.js"],"names":["textContentSchema","strong","em","s","del","ins","a","attributes","code","abbr","sub","sup","br","small","q","dfn","data","time","var","samp","kbd","i","b","u","mark","ruby","rt","rp","bdi","bdo","wbr","Object","keys","forEach","tag","children","embeddedContentSchema","audio","canvas","embed","img","object","video","phrasingContentSchema","getPhrasingContentSchema","context","isPhrasingContent","node","nodeName","toLowerCase","hasOwnProperty","isTextContent"],"mappings":";;;;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,iBAAiB,GAAG;AACzBC,EAAAA,MAAM,EAAE,EADiB;AAEzBC,EAAAA,EAAE,EAAE,EAFqB;AAGzBC,EAAAA,CAAC,EAAE,EAHsB;AAIzBC,EAAAA,GAAG,EAAE,EAJoB;AAKzBC,EAAAA,GAAG,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A9B;AAmDA;AACA;AACA;AACA;AACA;;AACA,MAAMoC,qBAAqB,GAAG,EAC7B,GAAG3C,iBAD0B;AAE7B,KAAGoC;AAF0B,CAA9B;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACO,SAASQ,wBAAT,CAAmCC,OAAnC,EAA6C;AACnD,MAAKA,OAAO,KAAK,OAAjB,EAA2B;AAC1B,WAAOF,qBAAP;AACA;;AAED,SAAO,kBACN,EACC,GAAGA,qBADJ;AAEC;AACA;AACAtC,IAAAA,GAAG,EAAE;AAAE8B,MAAAA,QAAQ,EAAEQ,qBAAqB,CAACtC,GAAtB,CAA0B8B;AAAtC,KAJN;AAKC/B,IAAAA,GAAG,EAAE;AAAE+B,MAAAA,QAAQ,EAAEQ,qBAAqB,CAACvC,GAAtB,CAA0B+B;AAAtC;AALN,GADM,EAQN,CACC,GADD,EACM;AACL,QAFD,EAES;AACR,QAHD,EAGS;AACR,QAJD,EAIS;AACR,OALD,EAKQ;AACP,OAND,EAMQ;AACP,OAPD,CAOQ;AAPR,GARM,CAAP;AAkBA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASW,iBAAT,CAA4BC,IAA5B,EAAmC;AACzC,QAAMb,GAAG,GAAGa,IAAI,CAACC,QAAL,CAAcC,WAAd,EAAZ;AACA,SAAOL,wBAAwB,GAAGM,cAA3B,CAA2ChB,GAA3C,KAAoDA,GAAG,KAAK,MAAnE;AACA;AAED;AACA;AACA;AACA;;;AACO,SAASiB,aAAT,CAAwBJ,IAAxB,EAA+B;AACrC,QAAMb,GAAG,GAAGa,IAAI,CAACC,QAAL,CAAcC,WAAd,EAAZ;AACA,SAAOjD,iBAAiB,CAACkD,cAAlB,CAAkChB,GAAlC,KAA2CA,GAAG,KAAK,MAA1D;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { omit, without } from 'lodash';\n\n/**\n * All phrasing content elements.\n *\n * @see https://www.w3.org/TR/2011/WD-html5-20110525/content-models.html#phrasing-content-0\n */\n\n/**\n * @typedef {Record<string,SemanticElementDefinition>} ContentSchema\n */\n\n/**\n * @typedef SemanticElementDefinition\n * @property {string[]} [attributes] Content attributes\n * @property {ContentSchema} [children] Content attributes\n */\n\n/**\n * All text-level semantic elements.\n *\n * @see https://html.spec.whatwg.org/multipage/text-level-semantics.html\n *\n * @type {ContentSchema}\n */\nconst textContentSchema = {\n\tstrong: {},\n\tem: {},\n\ts: {},\n\tdel: {},\n\tins: {},\n\ta: { attributes: [ 'href', 'target', 'rel', 'id' ] },\n\tcode: {},\n\tabbr: { attributes: [ 'title' ] },\n\tsub: {},\n\tsup: {},\n\tbr: {},\n\tsmall: {},\n\t// To do: fix blockquote.\n\t// cite: {},\n\tq: { attributes: [ 'cite' ] },\n\tdfn: { attributes: [ 'title' ] },\n\tdata: { attributes: [ 'value' ] },\n\ttime: { attributes: [ 'datetime' ] },\n\tvar: {},\n\tsamp: {},\n\tkbd: {},\n\ti: {},\n\tb: {},\n\tu: {},\n\tmark: {},\n\truby: {},\n\trt: {},\n\trp: {},\n\tbdi: { attributes: [ 'dir' ] },\n\tbdo: { attributes: [ 'dir' ] },\n\twbr: {},\n\t'#text': {},\n};\n\n// Recursion is needed.\n// Possible: strong > em > strong.\n// Impossible: strong > strong.\nwithout( Object.keys( textContentSchema ), '#text', 'br' ).forEach( ( tag ) => {\n\ttextContentSchema[ tag ].children = omit( textContentSchema, tag );\n} );\n\n/**\n * Embedded content elements.\n *\n * @see https://www.w3.org/TR/2011/WD-html5-20110525/content-models.html#embedded-content-0\n *\n * @type {ContentSchema}\n */\nconst embeddedContentSchema = {\n\taudio: {\n\t\tattributes: [\n\t\t\t'src',\n\t\t\t'preload',\n\t\t\t'autoplay',\n\t\t\t'mediagroup',\n\t\t\t'loop',\n\t\t\t'muted',\n\t\t],\n\t},\n\tcanvas: { attributes: [ 'width', 'height' ] },\n\tembed: { attributes: [ 'src', 'type', 'width', 'height' ] },\n\timg: {\n\t\tattributes: [\n\t\t\t'alt',\n\t\t\t'src',\n\t\t\t'srcset',\n\t\t\t'usemap',\n\t\t\t'ismap',\n\t\t\t'width',\n\t\t\t'height',\n\t\t],\n\t},\n\tobject: {\n\t\tattributes: [\n\t\t\t'data',\n\t\t\t'type',\n\t\t\t'name',\n\t\t\t'usemap',\n\t\t\t'form',\n\t\t\t'width',\n\t\t\t'height',\n\t\t],\n\t},\n\tvideo: {\n\t\tattributes: [\n\t\t\t'src',\n\t\t\t'poster',\n\t\t\t'preload',\n\t\t\t'autoplay',\n\t\t\t'mediagroup',\n\t\t\t'loop',\n\t\t\t'muted',\n\t\t\t'controls',\n\t\t\t'width',\n\t\t\t'height',\n\t\t],\n\t},\n};\n\n/**\n * Phrasing content elements.\n *\n * @see https://www.w3.org/TR/2011/WD-html5-20110525/content-models.html#phrasing-content-0\n */\nconst phrasingContentSchema = {\n\t...textContentSchema,\n\t...embeddedContentSchema,\n};\n\n/**\n * Get schema of possible paths for phrasing content.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories#Phrasing_content\n *\n * @param {string} [context] Set to \"paste\" to exclude invisible elements and\n * sensitive data.\n *\n * @return {Partial<ContentSchema>} Schema.\n */\nexport function getPhrasingContentSchema( context ) {\n\tif ( context !== 'paste' ) {\n\t\treturn phrasingContentSchema;\n\t}\n\n\treturn omit(\n\t\t{\n\t\t\t...phrasingContentSchema,\n\t\t\t// We shouldn't paste potentially sensitive information which is not\n\t\t\t// visible to the user when pasted, so strip the attributes.\n\t\t\tins: { children: phrasingContentSchema.ins.children },\n\t\t\tdel: { children: phrasingContentSchema.del.children },\n\t\t},\n\t\t[\n\t\t\t'u', // Used to mark misspelling. Shouldn't be pasted.\n\t\t\t'abbr', // Invisible.\n\t\t\t'data', // Invisible.\n\t\t\t'time', // Invisible.\n\t\t\t'wbr', // Invisible.\n\t\t\t'bdi', // Invisible.\n\t\t\t'bdo', // Invisible.\n\t\t]\n\t);\n}\n\n/**\n * Find out whether or not the given node is phrasing content.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories#Phrasing_content\n *\n * @param {Node} node The node to test.\n *\n * @return {boolean} True if phrasing content, false if not.\n */\nexport function isPhrasingContent( node ) {\n\tconst tag = node.nodeName.toLowerCase();\n\treturn getPhrasingContentSchema().hasOwnProperty( tag ) || tag === 'span';\n}\n\n/**\n * @param {Node} node\n * @return {boolean} Node is text content\n */\nexport function isTextContent( node ) {\n\tconst tag = node.nodeName.toLowerCase();\n\treturn textContentSchema.hasOwnProperty( tag ) || tag === 'span';\n}\n"]}
package/build/tabbable.js CHANGED
@@ -199,9 +199,9 @@ function findPrevious(element) {
199
199
 
200
200
  function findNext(element) {
201
201
  const focusables = (0, _focusable.find)(element.ownerDocument.body);
202
- const index = focusables.indexOf(element); // Remove all focusables before and inside `element`.
202
+ const index = focusables.indexOf(element); // Remove all focusables before and including `element`.
203
203
 
204
- const remaining = focusables.slice(index + 1).filter(node => !element.contains(node));
204
+ const remaining = focusables.slice(index + 1);
205
205
  return (0, _lodash.first)(filterTabbable(remaining));
206
206
  }
207
207
  //# sourceMappingURL=tabbable.js.map