@wordpress/dom 3.38.0 → 3.40.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (202) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/README.md +2 -2
  3. package/build/data-transfer.js +0 -2
  4. package/build/data-transfer.js.map +1 -1
  5. package/build/dom/caret-range-from-point.js +3 -5
  6. package/build/dom/caret-range-from-point.js.map +1 -1
  7. package/build/dom/clean-node-list.js +25 -42
  8. package/build/dom/clean-node-list.js.map +1 -1
  9. package/build/dom/compute-caret-rect.js +0 -6
  10. package/build/dom/compute-caret-rect.js.map +1 -1
  11. package/build/dom/document-has-selection.js +0 -5
  12. package/build/dom/document-has-selection.js.map +1 -1
  13. package/build/dom/document-has-text-selection.js +0 -2
  14. package/build/dom/document-has-text-selection.js.map +1 -1
  15. package/build/dom/document-has-uncollapsed-selection.js +0 -4
  16. package/build/dom/document-has-uncollapsed-selection.js.map +1 -1
  17. package/build/dom/get-computed-style.js +0 -3
  18. package/build/dom/get-computed-style.js.map +1 -1
  19. package/build/dom/get-offset-parent.js +8 -19
  20. package/build/dom/get-offset-parent.js.map +1 -1
  21. package/build/dom/get-range-height.js +0 -3
  22. package/build/dom/get-range-height.js.map +1 -1
  23. package/build/dom/get-rectangle-from-range.js +15 -22
  24. package/build/dom/get-rectangle-from-range.js.map +1 -1
  25. package/build/dom/get-scroll-container.js +3 -13
  26. package/build/dom/get-scroll-container.js.map +1 -1
  27. package/build/dom/hidden-caret-range-from-point.js +2 -6
  28. package/build/dom/hidden-caret-range-from-point.js.map +1 -1
  29. package/build/dom/index.js +0 -27
  30. package/build/dom/index.js.map +1 -1
  31. package/build/dom/input-field-has-uncollapsed-selection.js +8 -12
  32. package/build/dom/input-field-has-uncollapsed-selection.js.map +1 -1
  33. package/build/dom/insert-after.js +0 -2
  34. package/build/dom/insert-after.js.map +1 -1
  35. package/build/dom/is-edge.js +18 -40
  36. package/build/dom/is-edge.js.map +1 -1
  37. package/build/dom/is-element.js +0 -2
  38. package/build/dom/is-element.js.map +1 -1
  39. package/build/dom/is-empty.js +1 -7
  40. package/build/dom/is-empty.js.map +1 -1
  41. package/build/dom/is-entirely-selected.js +2 -18
  42. package/build/dom/is-entirely-selected.js.map +1 -1
  43. package/build/dom/is-form-element.js +0 -4
  44. package/build/dom/is-form-element.js.map +1 -1
  45. package/build/dom/is-horizontal-edge.js +2 -5
  46. package/build/dom/is-horizontal-edge.js.map +1 -1
  47. package/build/dom/is-html-input-element.js +0 -2
  48. package/build/dom/is-html-input-element.js.map +1 -1
  49. package/build/dom/is-input-or-text-area.js +0 -2
  50. package/build/dom/is-input-or-text-area.js.map +1 -1
  51. package/build/dom/is-number-input.js +0 -6
  52. package/build/dom/is-number-input.js.map +1 -1
  53. package/build/dom/is-rtl.js +0 -3
  54. package/build/dom/is-rtl.js.map +1 -1
  55. package/build/dom/is-selection-forward.js +6 -10
  56. package/build/dom/is-selection-forward.js.map +1 -1
  57. package/build/dom/is-text-field.js +1 -7
  58. package/build/dom/is-text-field.js.map +1 -1
  59. package/build/dom/is-vertical-edge.js +2 -5
  60. package/build/dom/is-vertical-edge.js.map +1 -1
  61. package/build/dom/place-caret-at-edge.js +8 -31
  62. package/build/dom/place-caret-at-edge.js.map +1 -1
  63. package/build/dom/place-caret-at-horizontal-edge.js +0 -3
  64. package/build/dom/place-caret-at-horizontal-edge.js.map +1 -1
  65. package/build/dom/place-caret-at-vertical-edge.js +0 -3
  66. package/build/dom/place-caret-at-vertical-edge.js.map +1 -1
  67. package/build/dom/remove-invalid-html.js +0 -3
  68. package/build/dom/remove-invalid-html.js.map +1 -1
  69. package/build/dom/remove.js +0 -2
  70. package/build/dom/remove.js.map +1 -1
  71. package/build/dom/replace-tag.js +0 -4
  72. package/build/dom/replace-tag.js.map +1 -1
  73. package/build/dom/replace.js +0 -5
  74. package/build/dom/replace.js.map +1 -1
  75. package/build/dom/safe-html.js +0 -8
  76. package/build/dom/safe-html.js.map +1 -1
  77. package/build/dom/scroll-if-no-range.js +31 -0
  78. package/build/dom/scroll-if-no-range.js.map +1 -0
  79. package/build/dom/strip-html.js +0 -3
  80. package/build/dom/strip-html.js.map +1 -1
  81. package/build/dom/unwrap.js +0 -4
  82. package/build/dom/unwrap.js.map +1 -1
  83. package/build/dom/wrap.js +0 -2
  84. package/build/dom/wrap.js.map +1 -1
  85. package/build/focusable.js +5 -18
  86. package/build/focusable.js.map +1 -1
  87. package/build/index.js +0 -11
  88. package/build/index.js.map +1 -1
  89. package/build/phrasing-content.js +13 -14
  90. package/build/phrasing-content.js.map +1 -1
  91. package/build/tabbable.js +21 -37
  92. package/build/tabbable.js.map +1 -1
  93. package/build/utils/assert-is-defined.js +0 -1
  94. package/build/utils/assert-is-defined.js.map +1 -1
  95. package/build-module/data-transfer.js +0 -1
  96. package/build-module/data-transfer.js.map +1 -1
  97. package/build-module/dom/caret-range-from-point.js +3 -4
  98. package/build-module/dom/caret-range-from-point.js.map +1 -1
  99. package/build-module/dom/clean-node-list.js +24 -35
  100. package/build-module/dom/clean-node-list.js.map +1 -1
  101. package/build-module/dom/compute-caret-rect.js +1 -3
  102. package/build-module/dom/compute-caret-rect.js.map +1 -1
  103. package/build-module/dom/document-has-selection.js +1 -1
  104. package/build-module/dom/document-has-selection.js.map +1 -1
  105. package/build-module/dom/document-has-text-selection.js +1 -1
  106. package/build-module/dom/document-has-text-selection.js.map +1 -1
  107. package/build-module/dom/document-has-uncollapsed-selection.js +1 -1
  108. package/build-module/dom/document-has-uncollapsed-selection.js.map +1 -1
  109. package/build-module/dom/get-computed-style.js +1 -2
  110. package/build-module/dom/get-computed-style.js.map +1 -1
  111. package/build-module/dom/get-offset-parent.js +9 -17
  112. package/build-module/dom/get-offset-parent.js.map +1 -1
  113. package/build-module/dom/get-range-height.js +0 -2
  114. package/build-module/dom/get-range-height.js.map +1 -1
  115. package/build-module/dom/get-rectangle-from-range.js +16 -21
  116. package/build-module/dom/get-rectangle-from-range.js.map +1 -1
  117. package/build-module/dom/get-scroll-container.js +4 -11
  118. package/build-module/dom/get-scroll-container.js.map +1 -1
  119. package/build-module/dom/hidden-caret-range-from-point.js +3 -3
  120. package/build-module/dom/hidden-caret-range-from-point.js.map +1 -1
  121. package/build-module/dom/index.js.map +1 -1
  122. package/build-module/dom/input-field-has-uncollapsed-selection.js +9 -9
  123. package/build-module/dom/input-field-has-uncollapsed-selection.js.map +1 -1
  124. package/build-module/dom/insert-after.js +1 -1
  125. package/build-module/dom/insert-after.js.map +1 -1
  126. package/build-module/dom/is-edge.js +19 -32
  127. package/build-module/dom/is-edge.js.map +1 -1
  128. package/build-module/dom/is-element.js +0 -1
  129. package/build-module/dom/is-element.js.map +1 -1
  130. package/build-module/dom/is-empty.js +1 -6
  131. package/build-module/dom/is-empty.js.map +1 -1
  132. package/build-module/dom/is-entirely-selected.js +3 -14
  133. package/build-module/dom/is-entirely-selected.js.map +1 -1
  134. package/build-module/dom/is-form-element.js +1 -2
  135. package/build-module/dom/is-form-element.js.map +1 -1
  136. package/build-module/dom/is-horizontal-edge.js +3 -3
  137. package/build-module/dom/is-horizontal-edge.js.map +1 -1
  138. package/build-module/dom/is-html-input-element.js +0 -1
  139. package/build-module/dom/is-html-input-element.js.map +1 -1
  140. package/build-module/dom/is-input-or-text-area.js +0 -1
  141. package/build-module/dom/is-input-or-text-area.js.map +1 -1
  142. package/build-module/dom/is-number-input.js +2 -4
  143. package/build-module/dom/is-number-input.js.map +1 -1
  144. package/build-module/dom/is-rtl.js +1 -1
  145. package/build-module/dom/is-rtl.js.map +1 -1
  146. package/build-module/dom/is-selection-forward.js +7 -9
  147. package/build-module/dom/is-selection-forward.js.map +1 -1
  148. package/build-module/dom/is-text-field.js +2 -5
  149. package/build-module/dom/is-text-field.js.map +1 -1
  150. package/build-module/dom/is-vertical-edge.js +3 -3
  151. package/build-module/dom/is-vertical-edge.js.map +1 -1
  152. package/build-module/dom/place-caret-at-edge.js +9 -26
  153. package/build-module/dom/place-caret-at-edge.js.map +1 -1
  154. package/build-module/dom/place-caret-at-horizontal-edge.js +1 -1
  155. package/build-module/dom/place-caret-at-horizontal-edge.js.map +1 -1
  156. package/build-module/dom/place-caret-at-vertical-edge.js +1 -1
  157. package/build-module/dom/place-caret-at-vertical-edge.js.map +1 -1
  158. package/build-module/dom/remove-invalid-html.js +1 -1
  159. package/build-module/dom/remove-invalid-html.js.map +1 -1
  160. package/build-module/dom/remove.js +1 -1
  161. package/build-module/dom/remove.js.map +1 -1
  162. package/build-module/dom/replace-tag.js +1 -3
  163. package/build-module/dom/replace-tag.js.map +1 -1
  164. package/build-module/dom/replace.js +1 -1
  165. package/build-module/dom/replace.js.map +1 -1
  166. package/build-module/dom/safe-html.js +1 -6
  167. package/build-module/dom/safe-html.js.map +1 -1
  168. package/build-module/dom/scroll-if-no-range.js +25 -0
  169. package/build-module/dom/scroll-if-no-range.js.map +1 -0
  170. package/build-module/dom/strip-html.js +1 -1
  171. package/build-module/dom/strip-html.js.map +1 -1
  172. package/build-module/dom/unwrap.js +1 -3
  173. package/build-module/dom/unwrap.js.map +1 -1
  174. package/build-module/dom/wrap.js +1 -1
  175. package/build-module/dom/wrap.js.map +1 -1
  176. package/build-module/focusable.js +5 -17
  177. package/build-module/focusable.js.map +1 -1
  178. package/build-module/index.js +1 -1
  179. package/build-module/index.js.map +1 -1
  180. package/build-module/phrasing-content.js +13 -11
  181. package/build-module/phrasing-content.js.map +1 -1
  182. package/build-module/tabbable.js +22 -33
  183. package/build-module/tabbable.js.map +1 -1
  184. package/build-module/utils/assert-is-defined.js.map +1 -1
  185. package/build-types/dom/is-edge.d.ts +4 -4
  186. package/build-types/dom/is-edge.d.ts.map +1 -1
  187. package/build-types/dom/is-horizontal-edge.d.ts +3 -3
  188. package/build-types/dom/is-horizontal-edge.d.ts.map +1 -1
  189. package/build-types/dom/is-vertical-edge.d.ts +3 -3
  190. package/build-types/dom/is-vertical-edge.d.ts.map +1 -1
  191. package/build-types/dom/place-caret-at-edge.d.ts.map +1 -1
  192. package/build-types/dom/scroll-if-no-range.d.ts +12 -0
  193. package/build-types/dom/scroll-if-no-range.d.ts.map +1 -0
  194. package/build-types/index.d.ts +2 -2
  195. package/build-types/index.d.ts.map +1 -1
  196. package/package.json +3 -3
  197. package/src/dom/is-edge.js +6 -8
  198. package/src/dom/is-horizontal-edge.js +2 -2
  199. package/src/dom/is-vertical-edge.js +2 -2
  200. package/src/dom/place-caret-at-edge.js +5 -19
  201. package/src/dom/scroll-if-no-range.js +34 -0
  202. package/tsconfig.tsbuildinfo +1 -1
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = getRectangleFromRange;
7
-
8
7
  var _assertIsDefined = require("../utils/assert-is-defined");
9
-
10
8
  /**
11
9
  * Internal dependencies
12
10
  */
@@ -24,32 +22,31 @@ function getRectangleFromRange(range) {
24
22
  // range; this a rectangle enclosing the union of the bounding rectangles
25
23
  // for all the elements in the range.
26
24
  if (!range.collapsed) {
27
- const rects = Array.from(range.getClientRects()); // If there's just a single rect, return it.
25
+ const rects = Array.from(range.getClientRects());
28
26
 
27
+ // If there's just a single rect, return it.
29
28
  if (rects.length === 1) {
30
29
  return rects[0];
31
- } // Ignore tiny selection at the edge of a range.
32
-
30
+ }
33
31
 
32
+ // Ignore tiny selection at the edge of a range.
34
33
  const filteredRects = rects.filter(({
35
34
  width
36
- }) => width > 1); // If it's full of tiny selections, return browser default.
35
+ }) => width > 1);
37
36
 
37
+ // If it's full of tiny selections, return browser default.
38
38
  if (filteredRects.length === 0) {
39
39
  return range.getBoundingClientRect();
40
40
  }
41
-
42
41
  if (filteredRects.length === 1) {
43
42
  return filteredRects[0];
44
43
  }
45
-
46
44
  let {
47
45
  top: furthestTop,
48
46
  bottom: furthestBottom,
49
47
  left: furthestLeft,
50
48
  right: furthestRight
51
49
  } = filteredRects[0];
52
-
53
50
  for (const {
54
51
  top,
55
52
  bottom,
@@ -61,55 +58,51 @@ function getRectangleFromRange(range) {
61
58
  if (left < furthestLeft) furthestLeft = left;
62
59
  if (right > furthestRight) furthestRight = right;
63
60
  }
64
-
65
61
  return new window.DOMRect(furthestLeft, furthestTop, furthestRight - furthestLeft, furthestBottom - furthestTop);
66
62
  }
67
-
68
63
  const {
69
64
  startContainer
70
65
  } = range;
71
66
  const {
72
67
  ownerDocument
73
- } = startContainer; // Correct invalid "BR" ranges. The cannot contain any children.
68
+ } = startContainer;
74
69
 
70
+ // Correct invalid "BR" ranges. The cannot contain any children.
75
71
  if (startContainer.nodeName === 'BR') {
76
72
  const {
77
73
  parentNode
78
74
  } = startContainer;
79
75
  (0, _assertIsDefined.assertIsDefined)(parentNode, 'parentNode');
80
- const index =
81
- /** @type {Node[]} */
82
- Array.from(parentNode.childNodes).indexOf(startContainer);
76
+ const index = /** @type {Node[]} */Array.from(parentNode.childNodes).indexOf(startContainer);
83
77
  (0, _assertIsDefined.assertIsDefined)(ownerDocument, 'ownerDocument');
84
78
  range = ownerDocument.createRange();
85
79
  range.setStart(parentNode, index);
86
80
  range.setEnd(parentNode, index);
87
81
  }
82
+ const rects = range.getClientRects();
88
83
 
89
- const rects = range.getClientRects(); // If we have multiple rectangles for a collapsed range, there's no way to
84
+ // If we have multiple rectangles for a collapsed range, there's no way to
90
85
  // know which it is, so don't return anything.
91
-
92
86
  if (rects.length > 1) {
93
87
  return null;
94
88
  }
89
+ let rect = rects[0];
95
90
 
96
- let rect = rects[0]; // If the collapsed range starts (and therefore ends) at an element node,
91
+ // If the collapsed range starts (and therefore ends) at an element node,
97
92
  // `getClientRects` can be empty in some browsers. This can be resolved
98
93
  // by adding a temporary text node with zero-width space to the range.
99
94
  //
100
95
  // See: https://stackoverflow.com/a/6847328/995445
101
-
102
96
  if (!rect || rect.height === 0) {
103
97
  (0, _assertIsDefined.assertIsDefined)(ownerDocument, 'ownerDocument');
104
- const padNode = ownerDocument.createTextNode('\u200b'); // Do not modify the live range.
105
-
98
+ const padNode = ownerDocument.createTextNode('\u200b');
99
+ // Do not modify the live range.
106
100
  range = range.cloneRange();
107
101
  range.insertNode(padNode);
108
102
  rect = range.getClientRects()[0];
109
103
  (0, _assertIsDefined.assertIsDefined)(padNode.parentNode, 'padNode.parentNode');
110
104
  padNode.parentNode.removeChild(padNode);
111
105
  }
112
-
113
106
  return rect;
114
107
  }
115
108
  //# sourceMappingURL=get-rectangle-from-range.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/dom/src/dom/get-rectangle-from-range.js"],"names":["getRectangleFromRange","range","collapsed","rects","Array","from","getClientRects","length","filteredRects","filter","width","getBoundingClientRect","top","furthestTop","bottom","furthestBottom","left","furthestLeft","right","furthestRight","window","DOMRect","startContainer","ownerDocument","nodeName","parentNode","index","childNodes","indexOf","createRange","setStart","setEnd","rect","height","padNode","createTextNode","cloneRange","insertNode","removeChild"],"mappings":";;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,qBAAT,CAAgCC,KAAhC,EAAwC;AACtD;AACA;AACA;AACA,MAAK,CAAEA,KAAK,CAACC,SAAb,EAAyB;AACxB,UAAMC,KAAK,GAAGC,KAAK,CAACC,IAAN,CAAYJ,KAAK,CAACK,cAAN,EAAZ,CAAd,CADwB,CAGxB;;AACA,QAAKH,KAAK,CAACI,MAAN,KAAiB,CAAtB,EAA0B;AACzB,aAAOJ,KAAK,CAAE,CAAF,CAAZ;AACA,KANuB,CAQxB;;;AACA,UAAMK,aAAa,GAAGL,KAAK,CAACM,MAAN,CAAc,CAAE;AAAEC,MAAAA;AAAF,KAAF,KAAiBA,KAAK,GAAG,CAAvC,CAAtB,CATwB,CAWxB;;AACA,QAAKF,aAAa,CAACD,MAAd,KAAyB,CAA9B,EAAkC;AACjC,aAAON,KAAK,CAACU,qBAAN,EAAP;AACA;;AAED,QAAKH,aAAa,CAACD,MAAd,KAAyB,CAA9B,EAAkC;AACjC,aAAOC,aAAa,CAAE,CAAF,CAApB;AACA;;AAED,QAAI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,CAAC8B,MAAN,CAAcN,UAAd,EAA0BC,KAA1B;AACA;;AAED,QAAMvB,KAAK,GAAGF,KAAK,CAACK,cAAN,EAAd,CA/DsD,CAiEtD;AACA;;AACA,MAAKH,KAAK,CAACI,MAAN,GAAe,CAApB,EAAwB;AACvB,WAAO,IAAP;AACA;;AAED,MAAIyB,IAAI,GAAG7B,KAAK,CAAE,CAAF,CAAhB,CAvEsD,CAyEtD;AACA;AACA;AACA;AACA;;AACA,MAAK,CAAE6B,IAAF,IAAUA,IAAI,CAACC,MAAL,KAAgB,CAA/B,EAAmC;AAClC,0CAAiBV,aAAjB,EAAgC,eAAhC;AACA,UAAMW,OAAO,GAAGX,aAAa,CAACY,cAAd,CAA8B,QAA9B,CAAhB,CAFkC,CAGlC;;AACAlC,IAAAA,KAAK,GAAGA,KAAK,CAACmC,UAAN,EAAR;AACAnC,IAAAA,KAAK,CAACoC,UAAN,CAAkBH,OAAlB;AACAF,IAAAA,IAAI,GAAG/B,KAAK,CAACK,cAAN,GAAwB,CAAxB,CAAP;AACA,0CAAiB4B,OAAO,CAACT,UAAzB,EAAqC,oBAArC;AACAS,IAAAA,OAAO,CAACT,UAAR,CAAmBa,WAAnB,CAAgCJ,OAAhC;AACA;;AAED,SAAOF,IAAP;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport { assertIsDefined } from '../utils/assert-is-defined';\n\n/**\n * Get the rectangle of a given Range. Returns `null` if no suitable rectangle\n * can be found.\n *\n * @param {Range} range The range.\n *\n * @return {DOMRect?} The rectangle.\n */\nexport default function getRectangleFromRange( range ) {\n\t// For uncollapsed ranges, get the rectangle that bounds the contents of the\n\t// range; this a rectangle enclosing the union of the bounding rectangles\n\t// for all the elements in the range.\n\tif ( ! range.collapsed ) {\n\t\tconst rects = Array.from( range.getClientRects() );\n\n\t\t// If there's just a single rect, return it.\n\t\tif ( rects.length === 1 ) {\n\t\t\treturn rects[ 0 ];\n\t\t}\n\n\t\t// Ignore tiny selection at the edge of a range.\n\t\tconst filteredRects = rects.filter( ( { width } ) => width > 1 );\n\n\t\t// If it's full of tiny selections, return browser default.\n\t\tif ( filteredRects.length === 0 ) {\n\t\t\treturn range.getBoundingClientRect();\n\t\t}\n\n\t\tif ( filteredRects.length === 1 ) {\n\t\t\treturn filteredRects[ 0 ];\n\t\t}\n\n\t\tlet {\n\t\t\ttop: furthestTop,\n\t\t\tbottom: furthestBottom,\n\t\t\tleft: furthestLeft,\n\t\t\tright: furthestRight,\n\t\t} = filteredRects[ 0 ];\n\n\t\tfor ( const { top, bottom, left, right } of filteredRects ) {\n\t\t\tif ( top < furthestTop ) furthestTop = top;\n\t\t\tif ( bottom > furthestBottom ) furthestBottom = bottom;\n\t\t\tif ( left < furthestLeft ) furthestLeft = left;\n\t\t\tif ( right > furthestRight ) furthestRight = right;\n\t\t}\n\n\t\treturn new window.DOMRect(\n\t\t\tfurthestLeft,\n\t\t\tfurthestTop,\n\t\t\tfurthestRight - furthestLeft,\n\t\t\tfurthestBottom - furthestTop\n\t\t);\n\t}\n\n\tconst { startContainer } = range;\n\tconst { ownerDocument } = startContainer;\n\n\t// Correct invalid \"BR\" ranges. The cannot contain any children.\n\tif ( startContainer.nodeName === 'BR' ) {\n\t\tconst { parentNode } = startContainer;\n\t\tassertIsDefined( parentNode, 'parentNode' );\n\t\tconst index = /** @type {Node[]} */ (\n\t\t\tArray.from( parentNode.childNodes )\n\t\t).indexOf( startContainer );\n\n\t\tassertIsDefined( ownerDocument, 'ownerDocument' );\n\t\trange = ownerDocument.createRange();\n\t\trange.setStart( parentNode, index );\n\t\trange.setEnd( parentNode, index );\n\t}\n\n\tconst rects = range.getClientRects();\n\n\t// If we have multiple rectangles for a collapsed range, there's no way to\n\t// know which it is, so don't return anything.\n\tif ( rects.length > 1 ) {\n\t\treturn null;\n\t}\n\n\tlet rect = rects[ 0 ];\n\n\t// If the collapsed range starts (and therefore ends) at an element node,\n\t// `getClientRects` can be empty in some browsers. This can be resolved\n\t// by adding a temporary text node with zero-width space to the range.\n\t//\n\t// See: https://stackoverflow.com/a/6847328/995445\n\tif ( ! rect || rect.height === 0 ) {\n\t\tassertIsDefined( ownerDocument, 'ownerDocument' );\n\t\tconst padNode = ownerDocument.createTextNode( '\\u200b' );\n\t\t// Do not modify the live range.\n\t\trange = range.cloneRange();\n\t\trange.insertNode( padNode );\n\t\trect = range.getClientRects()[ 0 ];\n\t\tassertIsDefined( padNode.parentNode, 'padNode.parentNode' );\n\t\tpadNode.parentNode.removeChild( padNode );\n\t}\n\n\treturn rect;\n}\n"]}
1
+ {"version":3,"names":["_assertIsDefined","require","getRectangleFromRange","range","collapsed","rects","Array","from","getClientRects","length","filteredRects","filter","width","getBoundingClientRect","top","furthestTop","bottom","furthestBottom","left","furthestLeft","right","furthestRight","window","DOMRect","startContainer","ownerDocument","nodeName","parentNode","assertIsDefined","index","childNodes","indexOf","createRange","setStart","setEnd","rect","height","padNode","createTextNode","cloneRange","insertNode","removeChild"],"sources":["@wordpress/dom/src/dom/get-rectangle-from-range.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { assertIsDefined } from '../utils/assert-is-defined';\n\n/**\n * Get the rectangle of a given Range. Returns `null` if no suitable rectangle\n * can be found.\n *\n * @param {Range} range The range.\n *\n * @return {DOMRect?} The rectangle.\n */\nexport default function getRectangleFromRange( range ) {\n\t// For uncollapsed ranges, get the rectangle that bounds the contents of the\n\t// range; this a rectangle enclosing the union of the bounding rectangles\n\t// for all the elements in the range.\n\tif ( ! range.collapsed ) {\n\t\tconst rects = Array.from( range.getClientRects() );\n\n\t\t// If there's just a single rect, return it.\n\t\tif ( rects.length === 1 ) {\n\t\t\treturn rects[ 0 ];\n\t\t}\n\n\t\t// Ignore tiny selection at the edge of a range.\n\t\tconst filteredRects = rects.filter( ( { width } ) => width > 1 );\n\n\t\t// If it's full of tiny selections, return browser default.\n\t\tif ( filteredRects.length === 0 ) {\n\t\t\treturn range.getBoundingClientRect();\n\t\t}\n\n\t\tif ( filteredRects.length === 1 ) {\n\t\t\treturn filteredRects[ 0 ];\n\t\t}\n\n\t\tlet {\n\t\t\ttop: furthestTop,\n\t\t\tbottom: furthestBottom,\n\t\t\tleft: furthestLeft,\n\t\t\tright: furthestRight,\n\t\t} = filteredRects[ 0 ];\n\n\t\tfor ( const { top, bottom, left, right } of filteredRects ) {\n\t\t\tif ( top < furthestTop ) furthestTop = top;\n\t\t\tif ( bottom > furthestBottom ) furthestBottom = bottom;\n\t\t\tif ( left < furthestLeft ) furthestLeft = left;\n\t\t\tif ( right > furthestRight ) furthestRight = right;\n\t\t}\n\n\t\treturn new window.DOMRect(\n\t\t\tfurthestLeft,\n\t\t\tfurthestTop,\n\t\t\tfurthestRight - furthestLeft,\n\t\t\tfurthestBottom - furthestTop\n\t\t);\n\t}\n\n\tconst { startContainer } = range;\n\tconst { ownerDocument } = startContainer;\n\n\t// Correct invalid \"BR\" ranges. The cannot contain any children.\n\tif ( startContainer.nodeName === 'BR' ) {\n\t\tconst { parentNode } = startContainer;\n\t\tassertIsDefined( parentNode, 'parentNode' );\n\t\tconst index = /** @type {Node[]} */ (\n\t\t\tArray.from( parentNode.childNodes )\n\t\t).indexOf( startContainer );\n\n\t\tassertIsDefined( ownerDocument, 'ownerDocument' );\n\t\trange = ownerDocument.createRange();\n\t\trange.setStart( parentNode, index );\n\t\trange.setEnd( parentNode, index );\n\t}\n\n\tconst rects = range.getClientRects();\n\n\t// If we have multiple rectangles for a collapsed range, there's no way to\n\t// know which it is, so don't return anything.\n\tif ( rects.length > 1 ) {\n\t\treturn null;\n\t}\n\n\tlet rect = rects[ 0 ];\n\n\t// If the collapsed range starts (and therefore ends) at an element node,\n\t// `getClientRects` can be empty in some browsers. This can be resolved\n\t// by adding a temporary text node with zero-width space to the range.\n\t//\n\t// See: https://stackoverflow.com/a/6847328/995445\n\tif ( ! rect || rect.height === 0 ) {\n\t\tassertIsDefined( ownerDocument, 'ownerDocument' );\n\t\tconst padNode = ownerDocument.createTextNode( '\\u200b' );\n\t\t// Do not modify the live range.\n\t\trange = range.cloneRange();\n\t\trange.insertNode( padNode );\n\t\trect = range.getClientRects()[ 0 ];\n\t\tassertIsDefined( padNode.parentNode, 'padNode.parentNode' );\n\t\tpadNode.parentNode.removeChild( padNode );\n\t}\n\n\treturn rect;\n}\n"],"mappings":";;;;;;AAGA,IAAAA,gBAAA,GAAAC,OAAA;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASC,qBAAqBA,CAAEC,KAAK,EAAG;EACtD;EACA;EACA;EACA,IAAK,CAAEA,KAAK,CAACC,SAAS,EAAG;IACxB,MAAMC,KAAK,GAAGC,KAAK,CAACC,IAAI,CAAEJ,KAAK,CAACK,cAAc,CAAC,CAAE,CAAC;;IAElD;IACA,IAAKH,KAAK,CAACI,MAAM,KAAK,CAAC,EAAG;MACzB,OAAOJ,KAAK,CAAE,CAAC,CAAE;IAClB;;IAEA;IACA,MAAMK,aAAa,GAAGL,KAAK,CAACM,MAAM,CAAE,CAAE;MAAEC;IAAM,CAAC,KAAMA,KAAK,GAAG,CAAE,CAAC;;IAEhE;IACA,IAAKF,aAAa,CAACD,MAAM,KAAK,CAAC,EAAG;MACjC,OAAON,KAAK,CAACU,qBAAqB,CAAC,CAAC;IACrC;IAEA,IAAKH,aAAa,CAACD,MAAM,KAAK,CAAC,EAAG;MACjC,OAAOC,aAAa,CAAE,CAAC,CAAE;IAC1B;IAEA,IAAI;MACHI,GAAG,EAAEC,WAAW;MAChBC,MAAM,EAAEC,cAAc;MACtBC,IAAI,EAAEC,YAAY;MAClBC,KAAK,EAAEC;IACR,CAAC,GAAGX,aAAa,CAAE,CAAC,CAAE;IAEtB,KAAM,MAAM;MAAEI,GAAG;MAAEE,MAAM;MAAEE,IAAI;MAAEE;IAAM,CAAC,IAAIV,aAAa,EAAG;MAC3D,IAAKI,GAAG,GAAGC,WAAW,EAAGA,WAAW,GAAGD,GAAG;MAC1C,IAAKE,MAAM,GAAGC,cAAc,EAAGA,cAAc,G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,aAAa,CAACa,cAAc,CAAE,QAAS,CAAC;IACxD;IACAnC,KAAK,GAAGA,KAAK,CAACoC,UAAU,CAAC,CAAC;IAC1BpC,KAAK,CAACqC,UAAU,CAAEH,OAAQ,CAAC;IAC3BF,IAAI,GAAGhC,KAAK,CAACK,cAAc,CAAC,CAAC,CAAE,CAAC,CAAE;IAClC,IAAAoB,gCAAe,EAAES,OAAO,CAACV,UAAU,EAAE,oBAAqB,CAAC;IAC3DU,OAAO,CAACV,UAAU,CAACc,WAAW,CAAEJ,OAAQ,CAAC;EAC1C;EAEA,OAAOF,IAAI;AACZ"}
@@ -1,14 +1,11 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.default = getScrollContainer;
9
-
10
8
  var _getComputedStyle = _interopRequireDefault(require("./get-computed-style"));
11
-
12
9
  /**
13
10
  * Internal dependencies
14
11
  */
@@ -26,7 +23,6 @@ function getScrollContainer(node, direction = 'vertical') {
26
23
  if (!node) {
27
24
  return undefined;
28
25
  }
29
-
30
26
  if (direction === 'vertical' || direction === 'all') {
31
27
  // Scrollable if scrollable height exceeds displayed...
32
28
  if (node.scrollHeight > node.clientHeight) {
@@ -34,13 +30,11 @@ function getScrollContainer(node, direction = 'vertical') {
34
30
  const {
35
31
  overflowY
36
32
  } = (0, _getComputedStyle.default)(node);
37
-
38
33
  if (/(auto|scroll)/.test(overflowY)) {
39
34
  return node;
40
35
  }
41
36
  }
42
37
  }
43
-
44
38
  if (direction === 'horizontal' || direction === 'all') {
45
39
  // Scrollable if scrollable width exceeds displayed...
46
40
  if (node.scrollWidth > node.clientWidth) {
@@ -48,20 +42,16 @@ function getScrollContainer(node, direction = 'vertical') {
48
42
  const {
49
43
  overflowX
50
44
  } = (0, _getComputedStyle.default)(node);
51
-
52
45
  if (/(auto|scroll)/.test(overflowX)) {
53
46
  return node;
54
47
  }
55
48
  }
56
49
  }
57
-
58
50
  if (node.ownerDocument === node.parentNode) {
59
51
  return node;
60
- } // Continue traversing.
61
-
52
+ }
62
53
 
63
- return getScrollContainer(
64
- /** @type {Element} */
65
- node.parentNode, direction);
54
+ // Continue traversing.
55
+ return getScrollContainer( /** @type {Element} */node.parentNode, direction);
66
56
  }
67
57
  //# sourceMappingURL=get-scroll-container.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/dom/src/dom/get-scroll-container.js"],"names":["getScrollContainer","node","direction","undefined","scrollHeight","clientHeight","overflowY","test","scrollWidth","clientWidth","overflowX","ownerDocument","parentNode"],"mappings":";;;;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,kBAAT,CAA6BC,IAA7B,EAAmCC,SAAS,GAAG,UAA/C,EAA4D;AAC1E,MAAK,CAAED,IAAP,EAAc;AACb,WAAOE,SAAP;AACA;;AAED,MAAKD,SAAS,KAAK,UAAd,IAA4BA,SAAS,KAAK,KAA/C,EAAuD;AACtD;AACA,QAAKD,IAAI,CAACG,YAAL,GAAoBH,IAAI,CAACI,YAA9B,EAA6C;AAC5C;AACA,YAAM;AAAEC,QAAAA;AAAF,UAAgB,+BAAkBL,IAAlB,CAAtB;;AAEA,UAAK,gBAAgBM,IAAhB,CAAsBD,SAAtB,CAAL,EAAyC;AACxC,eAAOL,IAAP;AACA;AACD;AACD;;AAED,MAAKC,SAAS,KAAK,YAAd,IAA8BA,SAAS,KAAK,KAAjD,EAAyD;AACxD;AACA,QAAKD,IAAI,CAACO,WAAL,GAAmBP,IAAI,CAACQ,WAA7B,EAA2C;AAC1C;AACA,YAAM;AAAEC,QAAAA;AAAF,UAAgB,+BAAkBT,IAAlB,CAAtB;;AAEA,UAAK,gBAAgBM,IAAhB,CAAsBG,SAAtB,CAAL,EAAyC;AACxC,eAAOT,IAAP;AACA;AACD;AACD;;AAED,MAAKA,IAAI,CAACU,aAAL,KAAuBV,IAAI,CAACW,UAAjC,EAA8C;AAC7C,WAAOX,IAAP;AACA,GA/ByE,CAiC1E;;;AACA,SAAOD,kBAAkB;AACxB;AAAyBC,EAAAA,IAAI,CAACW,UADN,EAExBV,SAFwB,CAAzB;AAIA","sourcesContent":["/**\n * Internal dependencies\n */\nimport getComputedStyle from './get-computed-style';\n\n/**\n * Given a DOM node, finds the closest scrollable container node or the node\n * itself, if scrollable.\n *\n * @param {Element | null} node Node from which to start.\n * @param {?string} direction Direction of scrollable container to search for ('vertical', 'horizontal', 'all').\n * Defaults to 'vertical'.\n * @return {Element | undefined} Scrollable container node, if found.\n */\nexport default function getScrollContainer( node, direction = 'vertical' ) {\n\tif ( ! node ) {\n\t\treturn undefined;\n\t}\n\n\tif ( direction === 'vertical' || direction === 'all' ) {\n\t\t// Scrollable if scrollable height exceeds displayed...\n\t\tif ( node.scrollHeight > node.clientHeight ) {\n\t\t\t// ...except when overflow is defined to be hidden or visible\n\t\t\tconst { overflowY } = getComputedStyle( node );\n\n\t\t\tif ( /(auto|scroll)/.test( overflowY ) ) {\n\t\t\t\treturn node;\n\t\t\t}\n\t\t}\n\t}\n\n\tif ( direction === 'horizontal' || direction === 'all' ) {\n\t\t// Scrollable if scrollable width exceeds displayed...\n\t\tif ( node.scrollWidth > node.clientWidth ) {\n\t\t\t// ...except when overflow is defined to be hidden or visible\n\t\t\tconst { overflowX } = getComputedStyle( node );\n\n\t\t\tif ( /(auto|scroll)/.test( overflowX ) ) {\n\t\t\t\treturn node;\n\t\t\t}\n\t\t}\n\t}\n\n\tif ( node.ownerDocument === node.parentNode ) {\n\t\treturn node;\n\t}\n\n\t// Continue traversing.\n\treturn getScrollContainer(\n\t\t/** @type {Element} */ ( node.parentNode ),\n\t\tdirection\n\t);\n}\n"]}
1
+ {"version":3,"names":["_getComputedStyle","_interopRequireDefault","require","getScrollContainer","node","direction","undefined","scrollHeight","clientHeight","overflowY","getComputedStyle","test","scrollWidth","clientWidth","overflowX","ownerDocument","parentNode"],"sources":["@wordpress/dom/src/dom/get-scroll-container.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport getComputedStyle from './get-computed-style';\n\n/**\n * Given a DOM node, finds the closest scrollable container node or the node\n * itself, if scrollable.\n *\n * @param {Element | null} node Node from which to start.\n * @param {?string} direction Direction of scrollable container to search for ('vertical', 'horizontal', 'all').\n * Defaults to 'vertical'.\n * @return {Element | undefined} Scrollable container node, if found.\n */\nexport default function getScrollContainer( node, direction = 'vertical' ) {\n\tif ( ! node ) {\n\t\treturn undefined;\n\t}\n\n\tif ( direction === 'vertical' || direction === 'all' ) {\n\t\t// Scrollable if scrollable height exceeds displayed...\n\t\tif ( node.scrollHeight > node.clientHeight ) {\n\t\t\t// ...except when overflow is defined to be hidden or visible\n\t\t\tconst { overflowY } = getComputedStyle( node );\n\n\t\t\tif ( /(auto|scroll)/.test( overflowY ) ) {\n\t\t\t\treturn node;\n\t\t\t}\n\t\t}\n\t}\n\n\tif ( direction === 'horizontal' || direction === 'all' ) {\n\t\t// Scrollable if scrollable width exceeds displayed...\n\t\tif ( node.scrollWidth > node.clientWidth ) {\n\t\t\t// ...except when overflow is defined to be hidden or visible\n\t\t\tconst { overflowX } = getComputedStyle( node );\n\n\t\t\tif ( /(auto|scroll)/.test( overflowX ) ) {\n\t\t\t\treturn node;\n\t\t\t}\n\t\t}\n\t}\n\n\tif ( node.ownerDocument === node.parentNode ) {\n\t\treturn node;\n\t}\n\n\t// Continue traversing.\n\treturn getScrollContainer(\n\t\t/** @type {Element} */ ( node.parentNode ),\n\t\tdirection\n\t);\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,iBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASC,kBAAkBA,CAAEC,IAAI,EAAEC,SAAS,GAAG,UAAU,EAAG;EAC1E,IAAK,CAAED,IAAI,EAAG;IACb,OAAOE,SAAS;EACjB;EAEA,IAAKD,SAAS,KAAK,UAAU,IAAIA,SAAS,KAAK,KAAK,EAAG;IACtD;IACA,IAAKD,IAAI,CAACG,YAAY,GAAGH,IAAI,CAACI,YAAY,EAAG;MAC5C;MACA,MAAM;QAAEC;MAAU,CAAC,GAAG,IAAAC,yBAAgB,EAAEN,IAAK,CAAC;MAE9C,IAAK,eAAe,CAACO,IAAI,CAAEF,SAAU,CAAC,EAAG;QACxC,OAAOL,IAAI;MACZ;IACD;EACD;EAEA,IAAKC,SAAS,KAAK,YAAY,IAAIA,SAAS,KAAK,KAAK,EAAG;IACxD;IACA,IAAKD,IAAI,CAACQ,WAAW,GAAGR,IAAI,CAACS,WAAW,EAAG;MAC1C;MACA,MAAM;QAAEC;MAAU,CAAC,GAAG,IAAAJ,yBAAgB,EAAEN,IAAK,CAAC;MAE9C,IAAK,eAAe,CAACO,IAAI,CAAEG,SAAU,CAAC,EAAG;QACxC,OAAOV,IAAI;MACZ;IACD;EACD;EAEA,IAAKA,IAAI,CAACW,aAAa,KAAKX,IAAI,CAACY,UAAU,EAAG;IAC7C,OAAOZ,IAAI;EACZ;;EAEA;EACA,OAAOD,kBAAkB,EACxB,sBAAyBC,IAAI,CAACY,UAAU,EACxCX,SACD,CAAC;AACF"}
@@ -1,16 +1,12 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.default = hiddenCaretRangeFromPoint;
9
-
10
8
  var _caretRangeFromPoint = _interopRequireDefault(require("./caret-range-from-point"));
11
-
12
9
  var _getComputedStyle = _interopRequireDefault(require("./get-computed-style"));
13
-
14
10
  /**
15
11
  * Internal dependencies
16
12
  */
@@ -32,12 +28,12 @@ function hiddenCaretRangeFromPoint(doc, x, y, container) {
32
28
  const originalPosition = container.style.position;
33
29
  const {
34
30
  position = 'static'
35
- } = (0, _getComputedStyle.default)(container); // A z-index only works if the element position is not static.
31
+ } = (0, _getComputedStyle.default)(container);
36
32
 
33
+ // A z-index only works if the element position is not static.
37
34
  if (position === 'static') {
38
35
  container.style.position = 'relative';
39
36
  }
40
-
41
37
  container.style.zIndex = '10000';
42
38
  const range = (0, _caretRangeFromPoint.default)(doc, x, y);
43
39
  container.style.zIndex = originalZIndex;
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/dom/src/dom/hidden-caret-range-from-point.js"],"names":["hiddenCaretRangeFromPoint","doc","x","y","container","originalZIndex","style","zIndex","originalPosition","position","range"],"mappings":";;;;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,yBAAT,CAAoCC,GAApC,EAAyCC,CAAzC,EAA4CC,CAA5C,EAA+CC,SAA/C,EAA2D;AACzE,QAAMC,cAAc,GAAGD,SAAS,CAACE,KAAV,CAAgBC,MAAvC;AACA,QAAMC,gBAAgB,GAAGJ,SAAS,CAACE,KAAV,CAAgBG,QAAzC;AAEA,QAAM;AAAEA,IAAAA,QAAQ,GAAG;AAAb,MAA0B,+BAAkBL,SAAlB,CAAhC,CAJyE,CAMzE;;AACA,MAAKK,QAAQ,KAAK,QAAlB,EAA6B;AAC5BL,IAAAA,SAAS,CAACE,KAAV,CAAgBG,QAAhB,GAA2B,UAA3B;AACA;;AAEDL,EAAAA,SAAS,CAACE,KAAV,CAAgBC,MAAhB,GAAyB,OAAzB;AAEA,QAAMG,KAAK,GAAG,kCAAqBT,GAArB,EAA0BC,CAA1B,EAA6BC,CAA7B,CAAd;AAEAC,EAAAA,SAAS,CAACE,KAAV,CAAgBC,MAAhB,GAAyBF,cAAzB;AACAD,EAAAA,SAAS,CAACE,KAAV,CAAgBG,QAAhB,GAA2BD,gBAA3B;AAEA,SAAOE,KAAP;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport caretRangeFromPoint from './caret-range-from-point';\nimport getComputedStyle from './get-computed-style';\n\n/**\n * Get a collapsed range for a given point.\n * Gives the container a temporary high z-index (above any UI).\n * This is preferred over getting the UI nodes and set styles there.\n *\n * @param {Document} doc The document of the range.\n * @param {number} x Horizontal position within the current viewport.\n * @param {number} y Vertical position within the current viewport.\n * @param {HTMLElement} container Container in which the range is expected to be found.\n *\n * @return {?Range} The best range for the given point.\n */\nexport default function hiddenCaretRangeFromPoint( doc, x, y, container ) {\n\tconst originalZIndex = container.style.zIndex;\n\tconst originalPosition = container.style.position;\n\n\tconst { position = 'static' } = getComputedStyle( container );\n\n\t// A z-index only works if the element position is not static.\n\tif ( position === 'static' ) {\n\t\tcontainer.style.position = 'relative';\n\t}\n\n\tcontainer.style.zIndex = '10000';\n\n\tconst range = caretRangeFromPoint( doc, x, y );\n\n\tcontainer.style.zIndex = originalZIndex;\n\tcontainer.style.position = originalPosition;\n\n\treturn range;\n}\n"]}
1
+ {"version":3,"names":["_caretRangeFromPoint","_interopRequireDefault","require","_getComputedStyle","hiddenCaretRangeFromPoint","doc","x","y","container","originalZIndex","style","zIndex","originalPosition","position","getComputedStyle","range","caretRangeFromPoint"],"sources":["@wordpress/dom/src/dom/hidden-caret-range-from-point.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport caretRangeFromPoint from './caret-range-from-point';\nimport getComputedStyle from './get-computed-style';\n\n/**\n * Get a collapsed range for a given point.\n * Gives the container a temporary high z-index (above any UI).\n * This is preferred over getting the UI nodes and set styles there.\n *\n * @param {Document} doc The document of the range.\n * @param {number} x Horizontal position within the current viewport.\n * @param {number} y Vertical position within the current viewport.\n * @param {HTMLElement} container Container in which the range is expected to be found.\n *\n * @return {?Range} The best range for the given point.\n */\nexport default function hiddenCaretRangeFromPoint( doc, x, y, container ) {\n\tconst originalZIndex = container.style.zIndex;\n\tconst originalPosition = container.style.position;\n\n\tconst { position = 'static' } = getComputedStyle( container );\n\n\t// A z-index only works if the element position is not static.\n\tif ( position === 'static' ) {\n\t\tcontainer.style.position = 'relative';\n\t}\n\n\tcontainer.style.zIndex = '10000';\n\n\tconst range = caretRangeFromPoint( doc, x, y );\n\n\tcontainer.style.zIndex = originalZIndex;\n\tcontainer.style.position = originalPosition;\n\n\treturn range;\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,oBAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,iBAAA,GAAAF,sBAAA,CAAAC,OAAA;AAJA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASE,yBAAyBA,CAAEC,GAAG,EAAEC,CAAC,EAAEC,CAAC,EAAEC,SAAS,EAAG;EACzE,MAAMC,cAAc,GAAGD,SAAS,CAACE,KAAK,CAACC,MAAM;EAC7C,MAAMC,gBAAgB,GAAGJ,SAAS,CAACE,KAAK,CAACG,QAAQ;EAEjD,MAAM;IAAEA,QAAQ,GAAG;EAAS,CAAC,GAAG,IAAAC,yBAAgB,EAAEN,SAAU,CAAC;;EAE7D;EACA,IAAKK,QAAQ,KAAK,QAAQ,EAAG;IAC5BL,SAAS,CAACE,KAAK,CAACG,QAAQ,GAAG,UAAU;EACtC;EAEAL,SAAS,CAACE,KAAK,CAACC,MAAM,GAAG,OAAO;EAEhC,MAAMI,KAAK,GAAG,IAAAC,4BAAmB,EAAEX,GAAG,EAAEC,CAAC,EAAEC,CAAE,CAAC;EAE9CC,SAAS,CAACE,KAAK,CAACC,MAAM,GAAGF,cAAc;EACvCD,SAAS,CAACE,KAAK,CAACG,QAAQ,GAAGD,gBAAgB;EAE3C,OAAOG,KAAK;AACb"}
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
@@ -161,56 +160,30 @@ Object.defineProperty(exports, "wrap", {
161
160
  return _wrap.default;
162
161
  }
163
162
  });
164
-
165
163
  var _computeCaretRect = _interopRequireDefault(require("./compute-caret-rect"));
166
-
167
164
  var _documentHasTextSelection = _interopRequireDefault(require("./document-has-text-selection"));
168
-
169
165
  var _documentHasUncollapsedSelection = _interopRequireDefault(require("./document-has-uncollapsed-selection"));
170
-
171
166
  var _documentHasSelection = _interopRequireDefault(require("./document-has-selection"));
172
-
173
167
  var _getRectangleFromRange = _interopRequireDefault(require("./get-rectangle-from-range"));
174
-
175
168
  var _getScrollContainer = _interopRequireDefault(require("./get-scroll-container"));
176
-
177
169
  var _getOffsetParent = _interopRequireDefault(require("./get-offset-parent"));
178
-
179
170
  var _isEntirelySelected = _interopRequireDefault(require("./is-entirely-selected"));
180
-
181
171
  var _isFormElement = _interopRequireDefault(require("./is-form-element"));
182
-
183
172
  var _isHorizontalEdge = _interopRequireDefault(require("./is-horizontal-edge"));
184
-
185
173
  var _isNumberInput = _interopRequireDefault(require("./is-number-input"));
186
-
187
174
  var _isTextField = _interopRequireDefault(require("./is-text-field"));
188
-
189
175
  var _isVerticalEdge = _interopRequireDefault(require("./is-vertical-edge"));
190
-
191
176
  var _placeCaretAtHorizontalEdge = _interopRequireDefault(require("./place-caret-at-horizontal-edge"));
192
-
193
177
  var _placeCaretAtVerticalEdge = _interopRequireDefault(require("./place-caret-at-vertical-edge"));
194
-
195
178
  var _replace = _interopRequireDefault(require("./replace"));
196
-
197
179
  var _remove = _interopRequireDefault(require("./remove"));
198
-
199
180
  var _insertAfter = _interopRequireDefault(require("./insert-after"));
200
-
201
181
  var _unwrap = _interopRequireDefault(require("./unwrap"));
202
-
203
182
  var _replaceTag = _interopRequireDefault(require("./replace-tag"));
204
-
205
183
  var _wrap = _interopRequireDefault(require("./wrap"));
206
-
207
184
  var _stripHtml = _interopRequireDefault(require("./strip-html"));
208
-
209
185
  var _isEmpty = _interopRequireDefault(require("./is-empty"));
210
-
211
186
  var _removeInvalidHtml = _interopRequireDefault(require("./remove-invalid-html"));
212
-
213
187
  var _isRtl = _interopRequireDefault(require("./is-rtl"));
214
-
215
188
  var _safeHtml = _interopRequireDefault(require("./safe-html"));
216
189
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/dom/src/dom/index.js"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA","sourcesContent":["export { default as computeCaretRect } from './compute-caret-rect';\nexport { default as documentHasTextSelection } from './document-has-text-selection';\nexport { default as documentHasUncollapsedSelection } from './document-has-uncollapsed-selection';\nexport { default as documentHasSelection } from './document-has-selection';\nexport { default as getRectangleFromRange } from './get-rectangle-from-range';\nexport { default as getScrollContainer } from './get-scroll-container';\nexport { default as getOffsetParent } from './get-offset-parent';\nexport { default as isEntirelySelected } from './is-entirely-selected';\nexport { default as isFormElement } from './is-form-element';\nexport { default as isHorizontalEdge } from './is-horizontal-edge';\nexport { default as isNumberInput } from './is-number-input';\nexport { default as isTextField } from './is-text-field';\nexport { default as isVerticalEdge } from './is-vertical-edge';\nexport { default as placeCaretAtHorizontalEdge } from './place-caret-at-horizontal-edge';\nexport { default as placeCaretAtVerticalEdge } from './place-caret-at-vertical-edge';\nexport { default as replace } from './replace';\nexport { default as remove } from './remove';\nexport { default as insertAfter } from './insert-after';\nexport { default as unwrap } from './unwrap';\nexport { default as replaceTag } from './replace-tag';\nexport { default as wrap } from './wrap';\nexport { default as __unstableStripHTML } from './strip-html';\nexport { default as isEmpty } from './is-empty';\nexport { default as removeInvalidHTML } from './remove-invalid-html';\nexport { default as isRTL } from './is-rtl';\nexport { default as safeHTML } from './safe-html';\n"]}
1
+ {"version":3,"names":["_computeCaretRect","_interopRequireDefault","require","_documentHasTextSelection","_documentHasUncollapsedSelection","_documentHasSelection","_getRectangleFromRange","_getScrollContainer","_getOffsetParent","_isEntirelySelected","_isFormElement","_isHorizontalEdge","_isNumberInput","_isTextField","_isVerticalEdge","_placeCaretAtHorizontalEdge","_placeCaretAtVerticalEdge","_replace","_remove","_insertAfter","_unwrap","_replaceTag","_wrap","_stripHtml","_isEmpty","_removeInvalidHtml","_isRtl","_safeHtml"],"sources":["@wordpress/dom/src/dom/index.js"],"sourcesContent":["export { default as computeCaretRect } from './compute-caret-rect';\nexport { default as documentHasTextSelection } from './document-has-text-selection';\nexport { default as documentHasUncollapsedSelection } from './document-has-uncollapsed-selection';\nexport { default as documentHasSelection } from './document-has-selection';\nexport { default as getRectangleFromRange } from './get-rectangle-from-range';\nexport { default as getScrollContainer } from './get-scroll-container';\nexport { default as getOffsetParent } from './get-offset-parent';\nexport { default as isEntirelySelected } from './is-entirely-selected';\nexport { default as isFormElement } from './is-form-element';\nexport { default as isHorizontalEdge } from './is-horizontal-edge';\nexport { default as isNumberInput } from './is-number-input';\nexport { default as isTextField } from './is-text-field';\nexport { default as isVerticalEdge } from './is-vertical-edge';\nexport { default as placeCaretAtHorizontalEdge } from './place-caret-at-horizontal-edge';\nexport { default as placeCaretAtVerticalEdge } from './place-caret-at-vertical-edge';\nexport { default as replace } from './replace';\nexport { default as remove } from './remove';\nexport { default as insertAfter } from './insert-after';\nexport { default as unwrap } from './unwrap';\nexport { default as replaceTag } from './replace-tag';\nexport { default as wrap } from './wrap';\nexport { default as __unstableStripHTML } from './strip-html';\nexport { default as isEmpty } from './is-empty';\nexport { default as removeInvalidHTML } from './remove-invalid-html';\nexport { default as isRTL } from './is-rtl';\nexport { default as safeHTML } from './safe-html';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AAC,OAAA;AACA,IAAAwB,MAAA,GAAAzB,sBAAA,CAAAC,OAAA;AACA,IAAAyB,SAAA,GAAA1B,sBAAA,CAAAC,OAAA"}
@@ -1,16 +1,12 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.default = inputFieldHasUncollapsedSelection;
9
-
10
8
  var _isTextField = _interopRequireDefault(require("./is-text-field"));
11
-
12
9
  var _isHtmlInputElement = _interopRequireDefault(require("./is-html-input-element"));
13
-
14
10
  /**
15
11
  * Internal dependencies
16
12
  */
@@ -35,22 +31,22 @@ var _isHtmlInputElement = _interopRequireDefault(require("./is-html-input-elemen
35
31
  function inputFieldHasUncollapsedSelection(element) {
36
32
  if (!(0, _isHtmlInputElement.default)(element) && !(0, _isTextField.default)(element)) {
37
33
  return false;
38
- } // Safari throws a type error when trying to get `selectionStart` and
34
+ }
35
+
36
+ // Safari throws a type error when trying to get `selectionStart` and
39
37
  // `selectionEnd` on non-text <input> elements, so a try/catch construct is
40
38
  // necessary.
41
-
42
-
43
39
  try {
44
40
  const {
45
41
  selectionStart,
46
42
  selectionEnd
47
- } =
48
- /** @type {HTMLInputElement | HTMLTextAreaElement} */
49
- element;
50
- return (// `null` means the input type doesn't implement selection, thus we
43
+ } = /** @type {HTMLInputElement | HTMLTextAreaElement} */element;
44
+ return (
45
+ // `null` means the input type doesn't implement selection, thus we
51
46
  // cannot determine whether the selection is collapsed, so we
52
47
  // default to true.
53
- selectionStart === null || // when not null, compare the two points
48
+ selectionStart === null ||
49
+ // when not null, compare the two points
54
50
  selectionStart !== selectionEnd
55
51
  );
56
52
  } catch (error) {
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/dom/src/dom/input-field-has-uncollapsed-selection.js"],"names":["inputFieldHasUncollapsedSelection","element","selectionStart","selectionEnd","error"],"mappings":";;;;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,iCAAT,CAA4CC,OAA5C,EAAsD;AACpE,MAAK,CAAE,iCAAoBA,OAApB,CAAF,IAAmC,CAAE,0BAAaA,OAAb,CAA1C,EAAmE;AAClE,WAAO,KAAP;AACA,GAHmE,CAKpE;AACA;AACA;;;AACA,MAAI;AACH,UAAM;AAAEC,MAAAA,cAAF;AAAkBC,MAAAA;AAAlB;AACL;AAAwDF,IAAAA,OADzD;AAEA,WACC;AACA;AACA;AACAC,MAAAA,cAAc,KAAK,IAAnB,IACA;AACAA,MAAAA,cAAc,KAAKC;AANpB;AAQA,GAXD,CAWE,OAAQC,KAAR,EAAgB;AACjB;AACA;AACA,WAAO,IAAP;AACA;AACD","sourcesContent":["/**\n * Internal dependencies\n */\nimport isTextField from './is-text-field';\nimport isHTMLInputElement from './is-html-input-element';\n\n/**\n * Check whether the given input field or textarea contains a (uncollapsed)\n * selection of text.\n *\n * CAVEAT: Only specific text-based HTML inputs support the selection APIs\n * needed to determine whether they have a collapsed or uncollapsed selection.\n * This function defaults to returning `true` when the selection cannot be\n * inspected, such as with `<input type=\"time\">`. The rationale is that this\n * should cause the block editor to defer to the browser's native selection\n * handling (e.g. copying and pasting), thereby reducing friction for the user.\n *\n * See: https://html.spec.whatwg.org/multipage/input.html#do-not-apply\n *\n * @param {Element} element The HTML element.\n *\n * @return {boolean} Whether the input/textareaa element has some \"selection\".\n */\nexport default function inputFieldHasUncollapsedSelection( element ) {\n\tif ( ! isHTMLInputElement( element ) && ! isTextField( element ) ) {\n\t\treturn false;\n\t}\n\n\t// Safari throws a type error when trying to get `selectionStart` and\n\t// `selectionEnd` on non-text <input> elements, so a try/catch construct is\n\t// necessary.\n\ttry {\n\t\tconst { selectionStart, selectionEnd } =\n\t\t\t/** @type {HTMLInputElement | HTMLTextAreaElement} */ ( element );\n\t\treturn (\n\t\t\t// `null` means the input type doesn't implement selection, thus we\n\t\t\t// cannot determine whether the selection is collapsed, so we\n\t\t\t// default to true.\n\t\t\tselectionStart === null ||\n\t\t\t// when not null, compare the two points\n\t\t\tselectionStart !== selectionEnd\n\t\t);\n\t} catch ( error ) {\n\t\t// This is Safari's way of saying that the input type doesn't implement\n\t\t// selection, so we default to true.\n\t\treturn true;\n\t}\n}\n"]}
1
+ {"version":3,"names":["_isTextField","_interopRequireDefault","require","_isHtmlInputElement","inputFieldHasUncollapsedSelection","element","isHTMLInputElement","isTextField","selectionStart","selectionEnd","error"],"sources":["@wordpress/dom/src/dom/input-field-has-uncollapsed-selection.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport isTextField from './is-text-field';\nimport isHTMLInputElement from './is-html-input-element';\n\n/**\n * Check whether the given input field or textarea contains a (uncollapsed)\n * selection of text.\n *\n * CAVEAT: Only specific text-based HTML inputs support the selection APIs\n * needed to determine whether they have a collapsed or uncollapsed selection.\n * This function defaults to returning `true` when the selection cannot be\n * inspected, such as with `<input type=\"time\">`. The rationale is that this\n * should cause the block editor to defer to the browser's native selection\n * handling (e.g. copying and pasting), thereby reducing friction for the user.\n *\n * See: https://html.spec.whatwg.org/multipage/input.html#do-not-apply\n *\n * @param {Element} element The HTML element.\n *\n * @return {boolean} Whether the input/textareaa element has some \"selection\".\n */\nexport default function inputFieldHasUncollapsedSelection( element ) {\n\tif ( ! isHTMLInputElement( element ) && ! isTextField( element ) ) {\n\t\treturn false;\n\t}\n\n\t// Safari throws a type error when trying to get `selectionStart` and\n\t// `selectionEnd` on non-text <input> elements, so a try/catch construct is\n\t// necessary.\n\ttry {\n\t\tconst { selectionStart, selectionEnd } =\n\t\t\t/** @type {HTMLInputElement | HTMLTextAreaElement} */ ( element );\n\t\treturn (\n\t\t\t// `null` means the input type doesn't implement selection, thus we\n\t\t\t// cannot determine whether the selection is collapsed, so we\n\t\t\t// default to true.\n\t\t\tselectionStart === null ||\n\t\t\t// when not null, compare the two points\n\t\t\tselectionStart !== selectionEnd\n\t\t);\n\t} catch ( error ) {\n\t\t// This is Safari's way of saying that the input type doesn't implement\n\t\t// selection, so we default to true.\n\t\treturn true;\n\t}\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,YAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,mBAAA,GAAAF,sBAAA,CAAAC,OAAA;AAJA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASE,iCAAiCA,CAAEC,OAAO,EAAG;EACpE,IAAK,CAAE,IAAAC,2BAAkB,EAAED,OAAQ,CAAC,IAAI,CAAE,IAAAE,oBAAW,EAAEF,OAAQ,CAAC,EAAG;IAClE,OAAO,KAAK;EACb;;EAEA;EACA;EACA;EACA,IAAI;IACH,MAAM;MAAEG,cAAc;MAAEC;IAAa,CAAC,GACrC,qDAAwDJ,OAAS;IAClE;MACC;MACA;MACA;MACAG,cAAc,KAAK,IAAI;MACvB;MACAA,cAAc,KAAKC;IAAY;EAEjC,CAAC,CAAC,OAAQC,KAAK,EAAG;IACjB;IACA;IACA,OAAO,IAAI;EACZ;AACD"}
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = insertAfter;
7
-
8
7
  var _assertIsDefined = require("../utils/assert-is-defined");
9
-
10
8
  /**
11
9
  * Internal dependencies
12
10
  */
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/dom/src/dom/insert-after.js"],"names":["insertAfter","newNode","referenceNode","parentNode","insertBefore","nextSibling"],"mappings":";;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,WAAT,CAAsBC,OAAtB,EAA+BC,aAA/B,EAA+C;AAC7D,wCAAiBA,aAAa,CAACC,UAA/B,EAA2C,0BAA3C;AACAD,EAAAA,aAAa,CAACC,UAAd,CAAyBC,YAAzB,CAAuCH,OAAvC,EAAgDC,aAAa,CAACG,WAA9D;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport { assertIsDefined } from '../utils/assert-is-defined';\n\n/**\n * Given two DOM nodes, inserts the former in the DOM as the next sibling of\n * the latter.\n *\n * @param {Node} newNode Node to be inserted.\n * @param {Node} referenceNode Node after which to perform the insertion.\n * @return {void}\n */\nexport default function insertAfter( newNode, referenceNode ) {\n\tassertIsDefined( referenceNode.parentNode, 'referenceNode.parentNode' );\n\treferenceNode.parentNode.insertBefore( newNode, referenceNode.nextSibling );\n}\n"]}
1
+ {"version":3,"names":["_assertIsDefined","require","insertAfter","newNode","referenceNode","assertIsDefined","parentNode","insertBefore","nextSibling"],"sources":["@wordpress/dom/src/dom/insert-after.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { assertIsDefined } from '../utils/assert-is-defined';\n\n/**\n * Given two DOM nodes, inserts the former in the DOM as the next sibling of\n * the latter.\n *\n * @param {Node} newNode Node to be inserted.\n * @param {Node} referenceNode Node after which to perform the insertion.\n * @return {void}\n */\nexport default function insertAfter( newNode, referenceNode ) {\n\tassertIsDefined( referenceNode.parentNode, 'referenceNode.parentNode' );\n\treferenceNode.parentNode.insertBefore( newNode, referenceNode.nextSibling );\n}\n"],"mappings":";;;;;;AAGA,IAAAA,gBAAA,GAAAC,OAAA;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASC,WAAWA,CAAEC,OAAO,EAAEC,aAAa,EAAG;EAC7D,IAAAC,gCAAe,EAAED,aAAa,CAACE,UAAU,EAAE,0BAA2B,CAAC;EACvEF,aAAa,CAACE,UAAU,CAACC,YAAY,CAAEJ,OAAO,EAAEC,aAAa,CAACI,WAAY,CAAC;AAC5E"}
@@ -1,26 +1,18 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.default = isEdge;
9
-
10
8
  var _isRtl = _interopRequireDefault(require("./is-rtl"));
11
-
12
9
  var _getRangeHeight = _interopRequireDefault(require("./get-range-height"));
13
-
14
10
  var _getRectangleFromRange = _interopRequireDefault(require("./get-rectangle-from-range"));
15
-
16
11
  var _isSelectionForward = _interopRequireDefault(require("./is-selection-forward"));
17
-
18
12
  var _hiddenCaretRangeFromPoint = _interopRequireDefault(require("./hidden-caret-range-from-point"));
19
-
20
13
  var _assertIsDefined = require("../utils/assert-is-defined");
21
-
22
14
  var _isInputOrTextArea = _interopRequireDefault(require("./is-input-or-text-area"));
23
-
15
+ var _scrollIfNoRange = require("./scroll-if-no-range");
24
16
  /**
25
17
  * Internal dependencies
26
18
  */
@@ -30,9 +22,9 @@ var _isInputOrTextArea = _interopRequireDefault(require("./is-input-or-text-area
30
22
  * horizontal position by default. Set `onlyVertical` to true to check only
31
23
  * vertically.
32
24
  *
33
- * @param {Element} container Focusable element.
34
- * @param {boolean} isReverse Set to true to check left, false to check right.
35
- * @param {boolean} [onlyVertical=false] Set to true to check only vertical position.
25
+ * @param {HTMLElement} container Focusable element.
26
+ * @param {boolean} isReverse Set to true to check left, false to check right.
27
+ * @param {boolean} [onlyVertical=false] Set to true to check only vertical position.
36
28
  *
37
29
  * @return {boolean} True if at the edge, false if not.
38
30
  */
@@ -41,20 +33,14 @@ function isEdge(container, isReverse, onlyVertical = false) {
41
33
  if (container.selectionStart !== container.selectionEnd) {
42
34
  return false;
43
35
  }
44
-
45
36
  if (isReverse) {
46
37
  return container.selectionStart === 0;
47
38
  }
48
-
49
39
  return container.value.length === container.selectionStart;
50
40
  }
51
-
52
- if (!
53
- /** @type {HTMLElement} */
54
- container.isContentEditable) {
41
+ if (! /** @type {HTMLElement} */container.isContentEditable) {
55
42
  return true;
56
43
  }
57
-
58
44
  const {
59
45
  ownerDocument
60
46
  } = container;
@@ -63,39 +49,37 @@ function isEdge(container, isReverse, onlyVertical = false) {
63
49
  } = ownerDocument;
64
50
  (0, _assertIsDefined.assertIsDefined)(defaultView, 'defaultView');
65
51
  const selection = defaultView.getSelection();
66
-
67
52
  if (!selection || !selection.rangeCount) {
68
53
  return false;
69
54
  }
70
-
71
55
  const range = selection.getRangeAt(0);
72
56
  const collapsedRange = range.cloneRange();
73
57
  const isForward = (0, _isSelectionForward.default)(selection);
74
- const isCollapsed = selection.isCollapsed; // Collapse in direction of selection.
58
+ const isCollapsed = selection.isCollapsed;
75
59
 
60
+ // Collapse in direction of selection.
76
61
  if (!isCollapsed) {
77
62
  collapsedRange.collapse(!isForward);
78
63
  }
79
-
80
64
  const collapsedRangeRect = (0, _getRectangleFromRange.default)(collapsedRange);
81
65
  const rangeRect = (0, _getRectangleFromRange.default)(range);
82
-
83
66
  if (!collapsedRangeRect || !rangeRect) {
84
67
  return false;
85
- } // Only consider the multiline selection at the edge if the direction is
68
+ }
69
+
70
+ // Only consider the multiline selection at the edge if the direction is
86
71
  // towards the edge. The selection is multiline if it is taller than the
87
72
  // collapsed selection.
88
-
89
-
90
73
  const rangeHeight = (0, _getRangeHeight.default)(range);
91
-
92
74
  if (!isCollapsed && rangeHeight && rangeHeight > collapsedRangeRect.height && isForward === isReverse) {
93
75
  return false;
94
- } // In the case of RTL scripts, the horizontal edge is at the opposite side.
95
-
76
+ }
96
77
 
78
+ // In the case of RTL scripts, the horizontal edge is at the opposite side.
97
79
  const isReverseDir = (0, _isRtl.default)(container) ? !isReverse : isReverse;
98
- const containerRect = container.getBoundingClientRect(); // To check if a selection is at the edge, we insert a test selection at the
80
+ const containerRect = container.getBoundingClientRect();
81
+
82
+ // To check if a selection is at the edge, we insert a test selection at the
99
83
  // edge of the container and check if the selections have the same vertical
100
84
  // or horizontal position. If they do, the selection is at the edge.
101
85
  // This method proves to be better than a DOM-based calculation for the
@@ -105,28 +89,22 @@ function isEdge(container, isReverse, onlyVertical = false) {
105
89
  // It also proves better than using the computed style for the vertical
106
90
  // edge, because we cannot know the padding and line height reliably in
107
91
  // pixels. `getComputedStyle` may return a value with different units.
108
-
109
92
  const x = isReverseDir ? containerRect.left + 1 : containerRect.right - 1;
110
93
  const y = isReverse ? containerRect.top + 1 : containerRect.bottom - 1;
111
- const testRange = (0, _hiddenCaretRangeFromPoint.default)(ownerDocument, x, y,
112
- /** @type {HTMLElement} */
113
- container);
114
-
94
+ const testRange = (0, _scrollIfNoRange.scrollIfNoRange)(container, isReverse, () => (0, _hiddenCaretRangeFromPoint.default)(ownerDocument, x, y, container));
115
95
  if (!testRange) {
116
96
  return false;
117
97
  }
118
-
119
98
  const testRect = (0, _getRectangleFromRange.default)(testRange);
120
-
121
99
  if (!testRect) {
122
100
  return false;
123
101
  }
124
-
125
102
  const verticalSide = isReverse ? 'top' : 'bottom';
126
103
  const horizontalSide = isReverseDir ? 'left' : 'right';
127
104
  const verticalDiff = testRect[verticalSide] - rangeRect[verticalSide];
128
- const horizontalDiff = testRect[horizontalSide] - collapsedRangeRect[horizontalSide]; // Allow the position to be 1px off.
105
+ const horizontalDiff = testRect[horizontalSide] - collapsedRangeRect[horizontalSide];
129
106
 
107
+ // Allow the position to be 1px off.
130
108
  const hasVerticalDiff = Math.abs(verticalDiff) <= 1;
131
109
  const hasHorizontalDiff = Math.abs(horizontalDiff) <= 1;
132
110
  return onlyVertical ? hasVerticalDiff : hasVerticalDiff && hasHorizontalDiff;
@@ -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;;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,CAAEc,YAAF,CAAzD;AACA,QAAMG,cAAc,GACnBJ,QAAQ,CAAEE,cAAF,CAAR,GAA6BhB,kBAAkB,CAAEgB,cAAF,CADhD,CAhG4E,CAmG5E;;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 (\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"]}
1
+ {"version":3,"names":["_isRtl","_interopRequireDefault","require","_getRangeHeight","_getRectangleFromRange","_isSelectionForward","_hiddenCaretRangeFromPoint","_assertIsDefined","_isInputOrTextArea","_scrollIfNoRange","isEdge","container","isReverse","onlyVertical","isInputOrTextArea","selectionStart","selectionEnd","value","length","isContentEditable","ownerDocument","defaultView","assertIsDefined","selection","getSelection","rangeCount","range","getRangeAt","collapsedRange","cloneRange","isForward","isSelectionForward","isCollapsed","collapse","collapsedRangeRect","getRectangleFromRange","rangeRect","rangeHeight","getRangeHeight","height","isReverseDir","isRTL","containerRect","getBoundingClientRect","x","left","right","y","top","bottom","testRange","scrollIfNoRange","hiddenCaretRangeFromPoint","testRect","verticalSide","horizontalSide","verticalDiff","horizontalDiff","hasVerticalDiff","Math","abs","hasHorizontalDiff"],"sources":["@wordpress/dom/src/dom/is-edge.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport isRTL from './is-rtl';\nimport getRangeHeight from './get-range-height';\nimport getRectangleFromRange from './get-rectangle-from-range';\nimport isSelectionForward from './is-selection-forward';\nimport hiddenCaretRangeFromPoint from './hidden-caret-range-from-point';\nimport { assertIsDefined } from '../utils/assert-is-defined';\nimport isInputOrTextArea from './is-input-or-text-area';\nimport { scrollIfNoRange } from './scroll-if-no-range';\n\n/**\n * Check whether the selection is at the edge of the container. Checks for\n * horizontal position by default. Set `onlyVertical` to true to check only\n * vertically.\n *\n * @param {HTMLElement} container Focusable element.\n * @param {boolean} isReverse Set to true to check left, false to check right.\n * @param {boolean} [onlyVertical=false] Set to true to check only vertical position.\n *\n * @return {boolean} True if at the edge, false if not.\n */\nexport default function isEdge( container, isReverse, onlyVertical = false ) {\n\tif (\n\t\tisInputOrTextArea( container ) &&\n\t\ttypeof container.selectionStart === 'number'\n\t) {\n\t\tif ( container.selectionStart !== container.selectionEnd ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif ( isReverse ) {\n\t\t\treturn container.selectionStart === 0;\n\t\t}\n\n\t\treturn container.value.length === container.selectionStart;\n\t}\n\n\tif ( ! ( /** @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 = scrollIfNoRange( container, isReverse, () =>\n\t\thiddenCaretRangeFromPoint( ownerDocument, x, y, container )\n\t);\n\n\tif ( ! testRange ) {\n\t\treturn false;\n\t}\n\n\tconst testRect = getRectangleFromRange( testRange );\n\n\tif ( ! testRect ) {\n\t\treturn false;\n\t}\n\n\tconst verticalSide = isReverse ? 'top' : 'bottom';\n\tconst horizontalSide = isReverseDir ? 'left' : 'right';\n\tconst verticalDiff = testRect[ verticalSide ] - rangeRect[ verticalSide ];\n\tconst horizontalDiff =\n\t\ttestRect[ horizontalSide ] - collapsedRangeRect[ horizontalSide ];\n\n\t// Allow the position to be 1px off.\n\tconst hasVerticalDiff = Math.abs( verticalDiff ) <= 1;\n\tconst hasHorizontalDiff = Math.abs( horizontalDiff ) <= 1;\n\n\treturn onlyVertical\n\t\t? hasVerticalDiff\n\t\t: hasVerticalDiff && hasHorizontalDiff;\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,eAAA,GAAAF,sBAAA,CAAAC,OAAA;AACA,IAAAE,sBAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,mBAAA,GAAAJ,sBAAA,CAAAC,OAAA;AACA,IAAAI,0BAAA,GAAAL,sBAAA,CAAAC,OAAA;AACA,IAAAK,gBAAA,GAAA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C,SAAS,GAAG,KAAK,GAAG,QAAQ;EACjD,MAAM2C,cAAc,GAAGf,YAAY,GAAG,MAAM,GAAG,OAAO;EACtD,MAAMgB,YAAY,GAAGH,QAAQ,CAAEC,YAAY,CAAE,GAAGlB,SAAS,CAAEkB,YAAY,CAAE;EACzE,MAAMG,cAAc,GACnBJ,QAAQ,CAAEE,cAAc,CAAE,GAAGrB,kBAAkB,CAAEqB,cAAc,CAAE;;EAElE;EACA,MAAMG,eAAe,GAAGC,IAAI,CAACC,GAAG,CAAEJ,YAAa,CAAC,IAAI,CAAC;EACrD,MAAMK,iBAAiB,GAAGF,IAAI,CAACC,GAAG,CAAEH,cAAe,CAAC,IAAI,CAAC;EAEzD,OAAO5C,YAAY,GAChB6C,eAAe,GACfA,eAAe,IAAIG,iBAAiB;AACxC"}
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = isElement;
7
-
8
7
  /* eslint-disable jsdoc/valid-types */
9
-
10
8
  /**
11
9
  * @param {Node | null | undefined} node
12
10
  * @return {node is Element} True if node is an Element node