@wordpress/dom 3.2.2-next.253d9b6e21.0 → 3.2.4

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 (46) 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/phrasing-content.js +1 -1
  13. package/build/phrasing-content.js.map +1 -1
  14. package/build-module/dom/caret-range-from-point.js +7 -3
  15. package/build-module/dom/caret-range-from-point.js.map +1 -1
  16. package/build-module/dom/is-edge.js +1 -1
  17. package/build-module/dom/is-edge.js.map +1 -1
  18. package/build-module/dom/place-caret-at-edge.js +95 -0
  19. package/build-module/dom/place-caret-at-edge.js.map +1 -0
  20. package/build-module/dom/place-caret-at-horizontal-edge.js +2 -81
  21. package/build-module/dom/place-caret-at-horizontal-edge.js.map +1 -1
  22. package/build-module/dom/place-caret-at-vertical-edge.js +6 -54
  23. package/build-module/dom/place-caret-at-vertical-edge.js.map +1 -1
  24. package/build-module/phrasing-content.js +1 -1
  25. package/build-module/phrasing-content.js.map +1 -1
  26. package/build-types/dom/caret-range-from-point.d.ts +12 -4
  27. package/build-types/dom/caret-range-from-point.d.ts.map +1 -1
  28. package/build-types/dom/is-edge.d.ts.map +1 -1
  29. package/build-types/dom/place-caret-at-edge.d.ts +9 -0
  30. package/build-types/dom/place-caret-at-edge.d.ts.map +1 -0
  31. package/build-types/dom/place-caret-at-horizontal-edge.d.ts.map +1 -1
  32. package/build-types/dom/place-caret-at-vertical-edge.d.ts +4 -5
  33. package/build-types/dom/place-caret-at-vertical-edge.d.ts.map +1 -1
  34. package/build-types/phrasing-content.d.ts +2 -4
  35. package/build-types/phrasing-content.d.ts.map +1 -1
  36. package/build-types/tabbable.d.ts +3 -3
  37. package/build-types/tabbable.d.ts.map +1 -1
  38. package/package.json +2 -2
  39. package/src/dom/caret-range-from-point.js +8 -3
  40. package/src/dom/is-edge.js +4 -1
  41. package/src/dom/place-caret-at-edge.js +95 -0
  42. package/src/dom/place-caret-at-horizontal-edge.js +2 -83
  43. package/src/dom/place-caret-at-vertical-edge.js +6 -64
  44. package/src/phrasing-content.js +1 -1
  45. package/src/test/dom.js +8 -0
  46. package/tsconfig.tsbuildinfo +1 -1170
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ import hiddenCaretRangeFromPoint from './hidden-caret-range-from-point';
5
+ import { assertIsDefined } from '../utils/assert-is-defined';
6
+ import isInputOrTextArea from './is-input-or-text-area';
7
+ import isRTL from './is-rtl';
8
+ /**
9
+ * Gets the range to place.
10
+ *
11
+ * @param {HTMLElement} container Focusable element.
12
+ * @param {boolean} isReverse True for end, false for start.
13
+ * @param {number|undefined} x X coordinate to vertically position.
14
+ *
15
+ * @return {Range|null} The range to place.
16
+ */
17
+
18
+ function getRange(container, isReverse, x) {
19
+ const {
20
+ ownerDocument
21
+ } = container; // In the case of RTL scripts, the horizontal edge is at the opposite side.
22
+
23
+ const isReverseDir = isRTL(container) ? !isReverse : isReverse;
24
+ const containerRect = container.getBoundingClientRect(); // When placing at the end (isReverse), find the closest range to the bottom
25
+ // right corner. When placing at the start, to the top left corner.
26
+
27
+ if (x === undefined) {
28
+ x = isReverse ? containerRect.right - 1 : containerRect.left + 1;
29
+ }
30
+
31
+ const y = isReverseDir ? containerRect.bottom - 1 : containerRect.top + 1;
32
+ return hiddenCaretRangeFromPoint(ownerDocument, x, y, container);
33
+ }
34
+ /**
35
+ * Places the caret at start or end of a given element.
36
+ *
37
+ * @param {HTMLElement} container Focusable element.
38
+ * @param {boolean} isReverse True for end, false for start.
39
+ * @param {number|undefined} x X coordinate to vertically position.
40
+ */
41
+
42
+
43
+ export default function placeCaretAtEdge(container, isReverse, x) {
44
+ if (!container) {
45
+ return;
46
+ }
47
+
48
+ container.focus();
49
+
50
+ if (isInputOrTextArea(container)) {
51
+ // The element may not support selection setting.
52
+ if (typeof container.selectionStart !== 'number') {
53
+ return;
54
+ }
55
+
56
+ if (isReverse) {
57
+ container.selectionStart = container.value.length;
58
+ container.selectionEnd = container.value.length;
59
+ } else {
60
+ container.selectionStart = 0;
61
+ container.selectionEnd = 0;
62
+ }
63
+
64
+ return;
65
+ }
66
+
67
+ if (!container.isContentEditable) {
68
+ return;
69
+ }
70
+
71
+ let range = getRange(container, isReverse, x); // If no range range can be created or it is outside the container, the
72
+ // element may be out of view.
73
+
74
+ if (!range || !range.startContainer || !container.contains(range.startContainer)) {
75
+ container.scrollIntoView(isReverse);
76
+ range = range = getRange(container, isReverse, x);
77
+
78
+ if (!range || !range.startContainer || !container.contains(range.startContainer)) {
79
+ return;
80
+ }
81
+ }
82
+
83
+ const {
84
+ ownerDocument
85
+ } = container;
86
+ const {
87
+ defaultView
88
+ } = ownerDocument;
89
+ assertIsDefined(defaultView, 'defaultView');
90
+ const selection = defaultView.getSelection();
91
+ assertIsDefined(selection, 'selection');
92
+ selection.removeAllRanges();
93
+ selection.addRange(range);
94
+ }
95
+ //# sourceMappingURL=place-caret-at-edge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["@wordpress/dom/src/dom/place-caret-at-edge.js"],"names":["hiddenCaretRangeFromPoint","assertIsDefined","isInputOrTextArea","isRTL","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":"AAAA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V,GAA2Bf,SAAS,CAACgB,KAAV,CAAgBC,MAA3C;AACAjB,MAAAA,SAAS,CAACkB,YAAV,GAAyBlB,SAAS,CAACgB,KAAV,CAAgBC,MAAzC;AACA,KAHD,MAGO;AACNjB,MAAAA,SAAS,CAACe,cAAV,GAA2B,CAA3B;AACAf,MAAAA,SAAS,CAACkB,YAAV,GAAyB,CAAzB;AACA;;AAED;AACA;;AAED,MAAK,CAAElB,SAAS,CAACmB,iBAAjB,EAAqC;AACpC;AACA;;AAED,MAAIC,KAAK,GAAGrB,QAAQ,CAAEC,SAAF,EAAaC,SAAb,EAAwBC,CAAxB,CAApB,CA5BmE,CA8BnE;AACA;;AACA,MACC,CAAEkB,KAAF,IACA,CAAEA,KAAK,CAACC,cADR,IAEA,CAAErB,SAAS,CAACsB,QAAV,CAAoBF,KAAK,CAACC,cAA1B,CAHH,EAIE;AACDrB,IAAAA,SAAS,CAACuB,cAAV,CAA0BtB,SAA1B;AACAmB,IAAAA,KAAK,GAAGA,KAAK,GAAGrB,QAAQ,CAAEC,SAAF,EAAaC,SAAb,EAAwBC,CAAxB,CAAxB;;AAEA,QACC,CAAEkB,KAAF,IACA,CAAEA,KAAK,CAACC,cADR,IAEA,CAAErB,SAAS,CAACsB,QAAV,CAAoBF,KAAK,CAACC,cAA1B,CAHH,EAIE;AACD;AACA;AACD;;AAED,QAAM;AAAElB,IAAAA;AAAF,MAAoBH,SAA1B;AACA,QAAM;AAAEwB,IAAAA;AAAF,MAAkBrB,aAAxB;AACAP,EAAAA,eAAe,CAAE4B,WAAF,EAAe,aAAf,CAAf;AACA,QAAMC,SAAS,GAAGD,WAAW,CAACE,YAAZ,EAAlB;AACA9B,EAAAA,eAAe,CAAE6B,SAAF,EAAa,WAAb,CAAf;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"]}
@@ -1,36 +1,7 @@
1
1
  /**
2
2
  * Internal dependencies
3
3
  */
4
- import { assertIsDefined } from '../utils/assert-is-defined';
5
- /**
6
- * Internal dependencies
7
- */
8
-
9
- import hiddenCaretRangeFromPoint from './hidden-caret-range-from-point';
10
- import isInputOrTextArea from './is-input-or-text-area';
11
- import isRTL from './is-rtl';
12
- /**
13
- * Gets the range to place.
14
- *
15
- * @param {HTMLElement} container Focusable element.
16
- * @param {boolean} isReverse True for end, false for start.
17
- *
18
- * @return {Range|null} The range to place.
19
- */
20
-
21
- function getRange(container, isReverse) {
22
- const {
23
- ownerDocument
24
- } = container; // In the case of RTL scripts, the horizontal edge is at the opposite side.
25
-
26
- const isReverseDir = isRTL(container) ? !isReverse : isReverse;
27
- const containerRect = container.getBoundingClientRect(); // When placing at the end (isReverse), find the closest range to the bottom
28
- // right corner. When placing at the start, to the top left corner.
29
-
30
- const x = isReverse ? containerRect.right - 1 : containerRect.left + 1;
31
- const y = isReverseDir ? containerRect.bottom - 1 : containerRect.top + 1;
32
- return hiddenCaretRangeFromPoint(ownerDocument, x, y, container);
33
- }
4
+ import placeCaretAtEdge from './place-caret-at-edge';
34
5
  /**
35
6
  * Places the caret at start or end of a given element.
36
7
  *
@@ -38,57 +9,7 @@ function getRange(container, isReverse) {
38
9
  * @param {boolean} isReverse True for end, false for start.
39
10
  */
40
11
 
41
-
42
12
  export default function placeCaretAtHorizontalEdge(container, isReverse) {
43
- if (!container) {
44
- return;
45
- }
46
-
47
- container.focus();
48
-
49
- if (isInputOrTextArea(container)) {
50
- // The element may not support selection setting.
51
- if (typeof container.selectionStart !== 'number') {
52
- return;
53
- }
54
-
55
- if (isReverse) {
56
- container.selectionStart = container.value.length;
57
- container.selectionEnd = container.value.length;
58
- } else {
59
- container.selectionStart = 0;
60
- container.selectionEnd = 0;
61
- }
62
-
63
- return;
64
- }
65
-
66
- if (!container.isContentEditable) {
67
- return;
68
- }
69
-
70
- let range = getRange(container, isReverse); // If no range range can be created or it is outside the container, the
71
- // element may be out of view.
72
-
73
- if (!range || !range.startContainer || !container.contains(range.startContainer)) {
74
- container.scrollIntoView(isReverse);
75
- range = getRange(container, isReverse);
76
-
77
- if (!range || !range.startContainer || !container.contains(range.startContainer)) {
78
- return;
79
- }
80
- }
81
-
82
- const {
83
- ownerDocument
84
- } = container;
85
- const {
86
- defaultView
87
- } = ownerDocument;
88
- assertIsDefined(defaultView, 'defaultView');
89
- const selection = defaultView.getSelection();
90
- assertIsDefined(selection, 'selection');
91
- selection.removeAllRanges();
92
- selection.addRange(range);
13
+ return placeCaretAtEdge(container, isReverse, undefined);
93
14
  }
94
15
  //# 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":["assertIsDefined","hiddenCaretRangeFromPoint","isInputOrTextArea","isRTL","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":"AAAA;AACA;AACA;AACA,SAASA,eAAT,QAAgC,4BAAhC;AAEA;AACA;AACA;;AACA,OAAOC,yBAAP,MAAsC,iCAAtC;AACA,OAAOC,iBAAP,MAA8B,yBAA9B;AACA,OAAOC,KAAP,MAAk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AACA;;AAED;AACA;;AAED,MAAK,CAAEjB,SAAS,CAACkB,iBAAjB,EAAqC;AACpC;AACA;;AAED,MAAIC,KAAK,GAAGpB,QAAQ,CAAEC,SAAF,EAAaC,SAAb,CAApB,CA5B0E,CA8B1E;AACA;;AACA,MACC,CAAEkB,KAAF,IACA,CAAEA,KAAK,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;AACAP,EAAAA,eAAe,CAAE4B,WAAF,EAAe,aAAf,CAAf;AACA,QAAMC,SAAS,GAAGD,WAAW,CAACE,YAAZ,EAAlB;AACA9B,EAAAA,eAAe,CAAE6B,SAAF,EAAa,WAAb,CAAf;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":["placeCaretAtEdge","placeCaretAtHorizontalEdge","container","isReverse","undefined"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,gBAAP,MAA6B,uBAA7B;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAe,SAASC,0BAAT,CAAqCC,SAArC,EAAgDC,SAAhD,EAA4D;AAC1E,SAAOH,gBAAgB,CAAEE,SAAF,EAAaC,SAAb,EAAwBC,SAAxB,CAAvB;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"]}
@@ -1,64 +1,16 @@
1
1
  /**
2
2
  * Internal dependencies
3
3
  */
4
- import placeCaretAtHorizontalEdge from './place-caret-at-horizontal-edge';
5
- import hiddenCaretRangeFromPoint from './hidden-caret-range-from-point';
6
- import { assertIsDefined } from '../utils/assert-is-defined';
4
+ import placeCaretAtEdge from './place-caret-at-edge';
7
5
  /**
8
6
  * Places the caret at the top or bottom of a given element.
9
7
  *
10
- * @param {HTMLElement} container Focusable element.
11
- * @param {boolean} isReverse True for bottom, false for top.
12
- * @param {DOMRect} [rect] The rectangle to position the caret with.
13
- * @param {boolean} [mayUseScroll=true] True to allow scrolling, false to disallow.
8
+ * @param {HTMLElement} container Focusable element.
9
+ * @param {boolean} isReverse True for bottom, false for top.
10
+ * @param {DOMRect} [rect] The rectangle to position the caret with.
14
11
  */
15
12
 
16
- export default function placeCaretAtVerticalEdge(container, isReverse, rect, mayUseScroll = true) {
17
- if (!container) {
18
- return;
19
- }
20
-
21
- if (!rect || !container.isContentEditable) {
22
- placeCaretAtHorizontalEdge(container, isReverse);
23
- return;
24
- }
25
-
26
- container.focus(); // Offset by a buffer half the height of the caret rect. This is needed
27
- // because caretRangeFromPoint may default to the end of the selection if
28
- // offset is too close to the edge. It's unclear how to precisely calculate
29
- // this threshold; it may be the padded area of some combination of line
30
- // height, caret height, and font size. The buffer offset is effectively
31
- // equivalent to a point at half the height of a line of text.
32
-
33
- const buffer = rect.height / 2;
34
- const editableRect = container.getBoundingClientRect();
35
- const x = rect.left;
36
- const y = isReverse ? editableRect.bottom - buffer : editableRect.top + buffer;
37
- const {
38
- ownerDocument
39
- } = container;
40
- const {
41
- defaultView
42
- } = ownerDocument;
43
- const range = hiddenCaretRangeFromPoint(ownerDocument, x, y, container);
44
-
45
- if (!range || !container.contains(range.startContainer)) {
46
- if (mayUseScroll && (!range || !range.startContainer || !range.startContainer.contains(container))) {
47
- // Might be out of view.
48
- // Easier than attempting to calculate manually.
49
- container.scrollIntoView(isReverse);
50
- placeCaretAtVerticalEdge(container, isReverse, rect, false);
51
- return;
52
- }
53
-
54
- placeCaretAtHorizontalEdge(container, isReverse);
55
- return;
56
- }
57
-
58
- assertIsDefined(defaultView, 'defaultView');
59
- const selection = defaultView.getSelection();
60
- assertIsDefined(selection, 'selection');
61
- selection.removeAllRanges();
62
- selection.addRange(range);
13
+ export default function placeCaretAtVerticalEdge(container, isReverse, rect) {
14
+ return placeCaretAtEdge(container, isReverse, rect === null || rect === void 0 ? void 0 : rect.left);
63
15
  }
64
16
  //# 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":["placeCaretAtHorizontalEdge","hiddenCaretRangeFromPoint","assertIsDefined","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":"AAAA;AACA;AACA;AACA,OAAOA,0BAAP,MA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F,MAAAA,wBAAwB,CAAEC,SAAF,EAAaC,SAAb,EAAwBC,IAAxB,EAA8B,KAA9B,CAAxB;AACA;AACA;;AAEDN,IAAAA,0BAA0B,CAAEI,SAAF,EAAaC,SAAb,CAA1B;AACA;AACA;;AAEDH,EAAAA,eAAe,CAAEkB,WAAF,EAAe,aAAf,CAAf;AACA,QAAMK,SAAS,GAAGL,WAAW,CAACM,YAAZ,EAAlB;AACAxB,EAAAA,eAAe,CAAEuB,SAAF,EAAa,WAAb,CAAf;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":["placeCaretAtEdge","placeCaretAtVerticalEdge","container","isReverse","rect","left"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,gBAAP,MAA6B,uBAA7B;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAe,SAASC,wBAAT,CAAmCC,SAAnC,EAA8CC,SAA9C,EAAyDC,IAAzD,EAAgE;AAC9E,SAAOJ,gBAAgB,CAAEE,SAAF,EAAaC,SAAb,EAAwBC,IAAxB,aAAwBA,IAAxB,uBAAwBA,IAAI,CAAEC,IAA9B,CAAvB;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"]}
@@ -33,7 +33,7 @@ const textContentSchema = {
33
33
  del: {},
34
34
  ins: {},
35
35
  a: {
36
- attributes: ['href', 'target', 'rel']
36
+ attributes: ['href', 'target', 'rel', 'id']
37
37
  },
38
38
  code: {},
39
39
  abbr: {
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/dom/src/phrasing-content.js"],"names":["omit","without","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":"AAAA;AACA;AACA;AACA,SAASA,IAAT,EAAeC,OAAf,QAA8B,QAA9B;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,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,EAAE,EALoB;AAMzBC,EAAAA,CAAC,EAAE;AAAEC,IAAAA,UAAU,EAAE,CAAE,MAAF,EAAU,QAAV,EAAoB,KAApB;AAAd,GANsB;AAOzBC,EAAAA,IAAI,EAAE,EAPmB;AAQzBC,EAAAA,IAAI,EAAE;AAAEF,IAAAA,UAAU,EAAE,CAAE,OAAF;AAAd,GARmB;AASzBG,EAAAA,GAAG,EAAE,EAToB;AAUzBC,EAAAA,GAAG,EAAE,EAVoB;AAWzBC,EAAAA,EAAE,EAAE,EAXqB;AAYzBC,EAAAA,KAAK,EAAE,EAZkB;AAazB;AACA;AACAC,EAAAA,CAAC,EAAE;AAAEP,IAA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tC,GAAtB,CAA0B8B;AAAtC,KAJN;AAKC/B,IAAAA,GAAG,EAAE;AAAE+B,MAAAA,QAAQ,EAAEQ,qBAAqB,CAACvC,GAAtB,CAA0B+B;AAAtC;AALN,GADU,EAQV,CACC,GADD,EACM;AACL,QAFD,EAES;AACR,QAHD,EAGS;AACR,QAJD,EAIS;AACR,OALD,EAKQ;AACP,OAND,EAMQ;AACP,OAPD,CAOQ;AAPR,GARU,CAAX;AAkBA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,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;;AACA,OAAO,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' ] },\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":["omit","without","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":"AAAA;AACA;AACA;AACA,SAASA,IAAT,EAAeC,OAAf,QAA8B,QAA9B;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,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,EAAE,EALoB;AAMzBC,EAAAA,CAAC,EAAE;AAAEC,IAAAA,UAAU,EAAE,CAAE,MAAF,EAAU,QAAV,EAAoB,KAApB,EAA2B,IAA3B;AAAd,GANsB;AAOzBC,EAAAA,IAAI,EAAE,EAPmB;AAQzBC,EAAAA,IAAI,EAAE;AAAEF,IAAAA,UAAU,EAAE,CAAE,OAAF;AAAd,GARmB;AASzBG,EAAAA,GAAG,EAAE,EAToB;AAUzBC,EAAAA,GAAG,EAAE,EAVoB;AAWzBC,EAAAA,EAAE,EAAE,EAXqB;AAYzBC,EAAAA,KAAK,EAAE,EAZkB;AAazB;AACA;AACAC,EAAAA,CAAC,EAAE;AAAEP,IAAAA,UAAU,EAAE,CAAE,MAAF;AAAd,GAfsB;AAgBzBQ,EAAAA,GAAG,EAAE;AAAER,IAAAA,UAAU,EAAE,CAAE,OAAF;AAAd,GAhBoB;AAiBzBS,EAAAA,IAAI,EAAE;AAAET,IAAAA,UAAU,EAAE,CAAE,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QAHD,EAGS;AACR,QAJD,EAIS;AACR,OALD,EAKQ;AACP,OAND,EAMQ;AACP,OAPD,CAOQ;AAPR,GARU,CAAX;AAkBA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,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;;AACA,OAAO,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"]}
@@ -4,11 +4,19 @@
4
4
  *
5
5
  * @see https://developer.mozilla.org/en-US/docs/Web/API/Document/caretRangeFromPoint
6
6
  *
7
- * @param {Document} doc The document of the range.
8
- * @param {number} x Horizontal position within the current viewport.
9
- * @param {number} y Vertical position within the current viewport.
7
+ * @param {DocumentMaybeWithCaretPositionFromPoint} doc The document of the range.
8
+ * @param {number} x Horizontal position within the current viewport.
9
+ * @param {number} y Vertical position within the current viewport.
10
10
  *
11
11
  * @return {Range | null} The best range for the given point.
12
12
  */
13
- export default function caretRangeFromPoint(doc: Document, x: number, y: number): Range | null;
13
+ export default function caretRangeFromPoint(doc: DocumentMaybeWithCaretPositionFromPoint, x: number, y: number): Range | null;
14
+ export type DocumentMaybeWithCaretPositionFromPoint = {
15
+ caretPositionFromPoint?: ((x: number, y: number) => CaretPosition | null) | undefined;
16
+ } & Document;
17
+ export type CaretPosition = {
18
+ readonly offset: number;
19
+ readonly offsetNode: Node;
20
+ getClientRect(): DOMRect | null;
21
+ };
14
22
  //# sourceMappingURL=caret-range-from-point.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"caret-range-from-point.d.ts","sourceRoot":"","sources":["../../src/dom/caret-range-from-point.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,iDANW,QAAQ,KACR,MAAM,KACN,MAAM,GAEL,KAAK,GAAG,IAAI,CAyBvB"}
1
+ {"version":3,"file":"caret-range-from-point.d.ts","sourceRoot":"","sources":["../../src/dom/caret-range-from-point.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,iDANW,uCAAuC,KACvC,MAAM,KACN,MAAM,GAEL,KAAK,GAAG,IAAI,CAyBvB;;kCAG0C,MAAM,KAAK,MAAM,KAAI,aAAa,GAAG,IAAI;;4BACvE;IAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,UAAU,EAAE,IAAI,CAAC;IAAC,aAAa,IAAI,OAAO,GAAG,IAAI,CAAC;CAAE"}
@@ -1 +1 @@
1
- {"version":3,"file":"is-edge.d.ts","sourceRoot":"","sources":["../../src/dom/is-edge.js"],"names":[],"mappings":"AAWA;;;;;;;;;;GAUG;AACH,0CANW,OAAO,aACP,OAAO,uCAGN,OAAO,CAyGlB"}
1
+ {"version":3,"file":"is-edge.d.ts","sourceRoot":"","sources":["../../src/dom/is-edge.js"],"names":[],"mappings":"AAWA;;;;;;;;;;GAUG;AACH,0CANW,OAAO,aACP,OAAO,uCAGN,OAAO,CA4GlB"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Places the caret at start or end of a given element.
3
+ *
4
+ * @param {HTMLElement} container Focusable element.
5
+ * @param {boolean} isReverse True for end, false for start.
6
+ * @param {number|undefined} x X coordinate to vertically position.
7
+ */
8
+ export default function placeCaretAtEdge(container: HTMLElement, isReverse: boolean, x: number | undefined): void;
9
+ //# sourceMappingURL=place-caret-at-edge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"place-caret-at-edge.d.ts","sourceRoot":"","sources":["../../src/dom/place-caret-at-edge.js"],"names":[],"mappings":"AA+BA;;;;;;GAMG;AACH,oDAJW,WAAW,aACX,OAAO,KACP,MAAM,GAAC,SAAS,QA0D1B"}
@@ -1 +1 @@
1
- {"version":3,"file":"place-caret-at-horizontal-edge.d.ts","sourceRoot":"","sources":["../../src/dom/place-caret-at-horizontal-edge.js"],"names":[],"mappings":"AAgCA;;;;;GAKG;AACH,8DAHW,WAAW,aACX,OAAO,QA0DjB"}
1
+ {"version":3,"file":"place-caret-at-horizontal-edge.d.ts","sourceRoot":"","sources":["../../src/dom/place-caret-at-horizontal-edge.js"],"names":[],"mappings":"AAKA;;;;;GAKG;AACH,8DAHW,WAAW,aACX,OAAO,QAIjB"}
@@ -1,10 +1,9 @@
1
1
  /**
2
2
  * Places the caret at the top or bottom of a given element.
3
3
  *
4
- * @param {HTMLElement} container Focusable element.
5
- * @param {boolean} isReverse True for bottom, false for top.
6
- * @param {DOMRect} [rect] The rectangle to position the caret with.
7
- * @param {boolean} [mayUseScroll=true] True to allow scrolling, false to disallow.
4
+ * @param {HTMLElement} container Focusable element.
5
+ * @param {boolean} isReverse True for bottom, false for top.
6
+ * @param {DOMRect} [rect] The rectangle to position the caret with.
8
7
  */
9
- export default function placeCaretAtVerticalEdge(container: HTMLElement, isReverse: boolean, rect?: DOMRect | undefined, mayUseScroll?: boolean | undefined): void;
8
+ export default function placeCaretAtVerticalEdge(container: HTMLElement, isReverse: boolean, rect?: DOMRect | undefined): void;
10
9
  //# sourceMappingURL=place-caret-at-vertical-edge.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"place-caret-at-vertical-edge.d.ts","sourceRoot":"","sources":["../../src/dom/place-caret-at-vertical-edge.js"],"names":[],"mappings":"AAOA;;;;;;;GAOG;AACH,4DALW,WAAW,aACX,OAAO,wEA6DjB"}
1
+ {"version":3,"file":"place-caret-at-vertical-edge.d.ts","sourceRoot":"","sources":["../../src/dom/place-caret-at-vertical-edge.js"],"names":[],"mappings":"AAKA;;;;;;GAMG;AACH,4DAJW,WAAW,aACX,OAAO,oCAKjB"}
@@ -24,9 +24,7 @@ export function isPhrasingContent(node: Node): boolean;
24
24
  * @return {boolean} Node is text content
25
25
  */
26
26
  export function isTextContent(node: Node): boolean;
27
- export type ContentSchema = {
28
- [x: string]: SemanticElementDefinition;
29
- };
27
+ export type ContentSchema = Record<string, SemanticElementDefinition>;
30
28
  export type SemanticElementDefinition = {
31
29
  /**
32
30
  * Content attributes
@@ -35,6 +33,6 @@ export type SemanticElementDefinition = {
35
33
  /**
36
34
  * Content attributes
37
35
  */
38
- children?: Record<string, SemanticElementDefinition> | undefined;
36
+ children?: ContentSchema | undefined;
39
37
  };
40
38
  //# sourceMappingURL=phrasing-content.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"phrasing-content.d.ts","sourceRoot":"","sources":["../src/phrasing-content.js"],"names":[],"mappings":"AA0IA;;;;;;;;;GASG;AACH,wEAFY,QAAQ,aAAa,CAAC,CAyBjC;AAED;;;;;;;;GAQG;AACH,wCAJW,IAAI,GAEH,OAAO,CAKlB;AAED;;;GAGG;AACH,oCAHW,IAAI,GACH,OAAO,CAKlB"}
1
+ {"version":3,"file":"phrasing-content.d.ts","sourceRoot":"","sources":["../src/phrasing-content.js"],"names":[],"mappings":"AA0IA;;;;;;;;;GASG;AACH,wEAFY,QAAQ,aAAa,CAAC,CAyBjC;AAED;;;;;;;;GAQG;AACH,wCAJW,IAAI,GAEH,OAAO,CAKlB;AAED;;;GAGG;AACH,oCAHW,IAAI,GACH,OAAO,CAKlB;4BAtLY,OAAO,MAAM,EAAC,yBAAyB,CAAC"}
@@ -26,8 +26,8 @@ export function findPrevious(element: Element): Element | undefined;
26
26
  */
27
27
  export function findNext(element: Element): Element | undefined;
28
28
  export type MaybeHTMLInputElement = Element & {
29
- type?: string | undefined;
30
- checked?: boolean | undefined;
31
- name?: string | undefined;
29
+ type?: string;
30
+ checked?: boolean;
31
+ name?: string;
32
32
  };
33
33
  //# sourceMappingURL=tabbable.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tabbable.d.ts","sourceRoot":"","sources":["../src/tabbable.js"],"names":[],"mappings":"AA2BA;;;;;;GAMG;AACH,yCAJW,OAAO,GAEN,OAAO,CAIlB;AAiHD;;;GAGG;AACH,8BAHW,OAAO,GACN,OAAO,EAAE,CAIpB;AAED;;;;;GAKG;AACH,sCAHW,OAAO,uBAWjB;AAED;;;;;GAKG;AACH,kCAHW,OAAO,uBAajB"}
1
+ {"version":3,"file":"tabbable.d.ts","sourceRoot":"","sources":["../src/tabbable.js"],"names":[],"mappings":"AA2BA;;;;;;GAMG;AACH,yCAJW,OAAO,GAEN,OAAO,CAIlB;AAiHD;;;GAGG;AACH,8BAHW,OAAO,GACN,OAAO,EAAE,CAIpB;AAED;;;;;GAKG;AACH,sCAHW,OAAO,uBAWjB;AAED;;;;;GAKG;AACH,kCAHW,OAAO,uBAajB;oCAvJa,OAAO,GAAG;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/dom",
3
- "version": "3.2.2-next.253d9b6e21.0",
3
+ "version": "3.2.4",
4
4
  "description": "DOM utilities module for WordPress.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -34,5 +34,5 @@
34
34
  "publishConfig": {
35
35
  "access": "public"
36
36
  },
37
- "gitHead": "c4b9acee18dfcc1767c35631f90725c7d604c5e9"
37
+ "gitHead": "8f7f052bc04e3f4eb50f479ced14be1489b9fa79"
38
38
  }
@@ -4,9 +4,9 @@
4
4
  *
5
5
  * @see https://developer.mozilla.org/en-US/docs/Web/API/Document/caretRangeFromPoint
6
6
  *
7
- * @param {Document} doc The document of the range.
8
- * @param {number} x Horizontal position within the current viewport.
9
- * @param {number} y Vertical position within the current viewport.
7
+ * @param {DocumentMaybeWithCaretPositionFromPoint} doc The document of the range.
8
+ * @param {number} x Horizontal position within the current viewport.
9
+ * @param {number} y Vertical position within the current viewport.
10
10
  *
11
11
  * @return {Range | null} The best range for the given point.
12
12
  */
@@ -34,3 +34,8 @@ export default function caretRangeFromPoint( doc, x, y ) {
34
34
 
35
35
  return range;
36
36
  }
37
+
38
+ /**
39
+ * @typedef {{caretPositionFromPoint?: (x: number, y: number)=> CaretPosition | null} & Document } DocumentMaybeWithCaretPositionFromPoint
40
+ * @typedef {{ readonly offset: number; readonly offsetNode: Node; getClientRect(): DOMRect | null; }} CaretPosition
41
+ */
@@ -21,7 +21,10 @@ import isInputOrTextArea from './is-input-or-text-area';
21
21
  * @return {boolean} True if at the edge, false if not.
22
22
  */
23
23
  export default function isEdge( container, isReverse, onlyVertical = false ) {
24
- if ( isInputOrTextArea( container ) ) {
24
+ if (
25
+ isInputOrTextArea( container ) &&
26
+ typeof container.selectionStart === 'number'
27
+ ) {
25
28
  if ( container.selectionStart !== container.selectionEnd ) {
26
29
  return false;
27
30
  }
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ import hiddenCaretRangeFromPoint from './hidden-caret-range-from-point';
5
+ import { assertIsDefined } from '../utils/assert-is-defined';
6
+ import isInputOrTextArea from './is-input-or-text-area';
7
+ import isRTL from './is-rtl';
8
+
9
+ /**
10
+ * Gets the range to place.
11
+ *
12
+ * @param {HTMLElement} container Focusable element.
13
+ * @param {boolean} isReverse True for end, false for start.
14
+ * @param {number|undefined} x X coordinate to vertically position.
15
+ *
16
+ * @return {Range|null} The range to place.
17
+ */
18
+ function getRange( container, isReverse, x ) {
19
+ const { ownerDocument } = container;
20
+ // In the case of RTL scripts, the horizontal edge is at the opposite side.
21
+ const isReverseDir = isRTL( container ) ? ! isReverse : isReverse;
22
+ const containerRect = container.getBoundingClientRect();
23
+ // When placing at the end (isReverse), find the closest range to the bottom
24
+ // right corner. When placing at the start, to the top left corner.
25
+ if ( x === undefined ) {
26
+ x = isReverse ? containerRect.right - 1 : containerRect.left + 1;
27
+ }
28
+ const y = isReverseDir ? containerRect.bottom - 1 : containerRect.top + 1;
29
+ return hiddenCaretRangeFromPoint( ownerDocument, x, y, container );
30
+ }
31
+
32
+ /**
33
+ * Places the caret at start or end of a given element.
34
+ *
35
+ * @param {HTMLElement} container Focusable element.
36
+ * @param {boolean} isReverse True for end, false for start.
37
+ * @param {number|undefined} x X coordinate to vertically position.
38
+ */
39
+ export default function placeCaretAtEdge( container, isReverse, x ) {
40
+ if ( ! container ) {
41
+ return;
42
+ }
43
+
44
+ container.focus();
45
+
46
+ if ( isInputOrTextArea( container ) ) {
47
+ // The element may not support selection setting.
48
+ if ( typeof container.selectionStart !== 'number' ) {
49
+ return;
50
+ }
51
+
52
+ if ( isReverse ) {
53
+ container.selectionStart = container.value.length;
54
+ container.selectionEnd = container.value.length;
55
+ } else {
56
+ container.selectionStart = 0;
57
+ container.selectionEnd = 0;
58
+ }
59
+
60
+ return;
61
+ }
62
+
63
+ if ( ! container.isContentEditable ) {
64
+ return;
65
+ }
66
+
67
+ let range = getRange( container, isReverse, x );
68
+
69
+ // If no range range can be created or it is outside the container, the
70
+ // element may be out of view.
71
+ if (
72
+ ! range ||
73
+ ! range.startContainer ||
74
+ ! container.contains( range.startContainer )
75
+ ) {
76
+ container.scrollIntoView( isReverse );
77
+ range = range = getRange( container, isReverse, x );
78
+
79
+ if (
80
+ ! range ||
81
+ ! range.startContainer ||
82
+ ! container.contains( range.startContainer )
83
+ ) {
84
+ return;
85
+ }
86
+ }
87
+
88
+ const { ownerDocument } = container;
89
+ const { defaultView } = ownerDocument;
90
+ assertIsDefined( defaultView, 'defaultView' );
91
+ const selection = defaultView.getSelection();
92
+ assertIsDefined( selection, 'selection' );
93
+ selection.removeAllRanges();
94
+ selection.addRange( range );
95
+ }