@wordpress/dom 3.8.0 → 3.11.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 (58) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +8 -9
  3. package/build/dom/clean-node-list.js +4 -2
  4. package/build/dom/clean-node-list.js.map +1 -1
  5. package/build/dom/document-has-selection.js +4 -4
  6. package/build/dom/document-has-selection.js.map +1 -1
  7. package/build/dom/document-has-uncollapsed-selection.js +4 -4
  8. package/build/dom/document-has-uncollapsed-selection.js.map +1 -1
  9. package/build/dom/get-rectangle-from-range.js.map +1 -1
  10. package/build/dom/input-field-has-uncollapsed-selection.js +24 -18
  11. package/build/dom/input-field-has-uncollapsed-selection.js.map +1 -1
  12. package/build/dom/is-edge.js.map +1 -1
  13. package/build/dom/is-empty.js.map +1 -1
  14. package/build/dom/is-html-input-element.js +1 -1
  15. package/build/dom/is-html-input-element.js.map +1 -1
  16. package/build/dom/is-number-input.js +14 -4
  17. package/build/dom/is-number-input.js.map +1 -1
  18. package/build/dom/is-text-field.js +1 -1
  19. package/build/dom/is-text-field.js.map +1 -1
  20. package/build-module/dom/clean-node-list.js +4 -1
  21. package/build-module/dom/clean-node-list.js.map +1 -1
  22. package/build-module/dom/document-has-selection.js +4 -4
  23. package/build-module/dom/document-has-selection.js.map +1 -1
  24. package/build-module/dom/document-has-uncollapsed-selection.js +4 -4
  25. package/build-module/dom/document-has-uncollapsed-selection.js.map +1 -1
  26. package/build-module/dom/get-rectangle-from-range.js.map +1 -1
  27. package/build-module/dom/input-field-has-uncollapsed-selection.js +24 -18
  28. package/build-module/dom/input-field-has-uncollapsed-selection.js.map +1 -1
  29. package/build-module/dom/is-edge.js.map +1 -1
  30. package/build-module/dom/is-empty.js.map +1 -1
  31. package/build-module/dom/is-html-input-element.js +1 -1
  32. package/build-module/dom/is-html-input-element.js.map +1 -1
  33. package/build-module/dom/is-number-input.js +13 -4
  34. package/build-module/dom/is-number-input.js.map +1 -1
  35. package/build-module/dom/is-text-field.js +1 -1
  36. package/build-module/dom/is-text-field.js.map +1 -1
  37. package/build-types/dom/clean-node-list.d.ts.map +1 -1
  38. package/build-types/dom/document-has-selection.d.ts +2 -2
  39. package/build-types/dom/document-has-uncollapsed-selection.d.ts +4 -4
  40. package/build-types/dom/input-field-has-uncollapsed-selection.d.ts +9 -5
  41. package/build-types/dom/input-field-has-uncollapsed-selection.d.ts.map +1 -1
  42. package/build-types/dom/is-number-input.d.ts +2 -3
  43. package/build-types/dom/is-number-input.d.ts.map +1 -1
  44. package/build-types/dom/is-text-field.d.ts.map +1 -1
  45. package/package.json +3 -2
  46. package/src/dom/clean-node-list.js +130 -125
  47. package/src/dom/document-has-selection.js +5 -5
  48. package/src/dom/document-has-uncollapsed-selection.js +4 -4
  49. package/src/dom/get-rectangle-from-range.js +3 -3
  50. package/src/dom/input-field-has-uncollapsed-selection.js +28 -22
  51. package/src/dom/is-edge.js +1 -1
  52. package/src/dom/is-empty.js +3 -3
  53. package/src/dom/is-html-input-element.js +1 -1
  54. package/src/dom/is-number-input.js +12 -4
  55. package/src/dom/is-text-field.js +2 -0
  56. package/src/test/dom.js +3 -23
  57. package/tsconfig.json +1 -3
  58. package/tsconfig.tsbuildinfo +1 -1
@@ -4,13 +4,13 @@
4
4
  import documentHasTextSelection from './document-has-text-selection';
5
5
  import inputFieldHasUncollapsedSelection from './input-field-has-uncollapsed-selection';
6
6
  /**
7
- * Check whether the current document has any sort of selection. This includes
8
- * ranges of text across elements and any selection inside `<input>` and
9
- * `<textarea>` elements.
7
+ * Check whether the current document has any sort of (uncollapsed) selection.
8
+ * This includes ranges of text across elements and any selection inside
9
+ * textual `<input>` and `<textarea>` elements.
10
10
  *
11
11
  * @param {Document} doc The document to check.
12
12
  *
13
- * @return {boolean} Whether there is any sort of "selection" in the document.
13
+ * @return {boolean} Whether there is any recognizable text selection in the document.
14
14
  */
15
15
 
16
16
  export default function documentHasUncollapsedSelection(doc) {
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/dom/src/dom/document-has-uncollapsed-selection.js"],"names":["documentHasTextSelection","inputFieldHasUncollapsedSelection","documentHasUncollapsedSelection","doc","activeElement"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,wBAAP,MAAqC,+BAArC;AACA,OAAOC,iCAAP,MAA8C,yCAA9C;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAe,SAASC,+BAAT,CAA0CC,GAA1C,EAAgD;AAC9D,SACCH,wBAAwB,CAAEG,GAAF,CAAxB,IACE,CAAC,CAAEA,GAAG,CAACC,aAAP,IACDH,iCAAiC,CAAEE,GAAG,CAACC,aAAN,CAHnC;AAKA","sourcesContent":["/**\n * Internal dependencies\n */\nimport documentHasTextSelection from './document-has-text-selection';\nimport inputFieldHasUncollapsedSelection from './input-field-has-uncollapsed-selection';\n\n/**\n * Check whether the current document has any sort of selection. This includes\n * ranges of text across elements and any selection inside `<input>` and\n * `<textarea>` elements.\n *\n * @param {Document} doc The document to check.\n *\n * @return {boolean} Whether there is any sort of \"selection\" in the document.\n */\nexport default function documentHasUncollapsedSelection( doc ) {\n\treturn (\n\t\tdocumentHasTextSelection( doc ) ||\n\t\t( !! doc.activeElement &&\n\t\t\tinputFieldHasUncollapsedSelection( doc.activeElement ) )\n\t);\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/dom/src/dom/document-has-uncollapsed-selection.js"],"names":["documentHasTextSelection","inputFieldHasUncollapsedSelection","documentHasUncollapsedSelection","doc","activeElement"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,wBAAP,MAAqC,+BAArC;AACA,OAAOC,iCAAP,MAA8C,yCAA9C;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAe,SAASC,+BAAT,CAA0CC,GAA1C,EAAgD;AAC9D,SACCH,wBAAwB,CAAEG,GAAF,CAAxB,IACE,CAAC,CAAEA,GAAG,CAACC,aAAP,IACDH,iCAAiC,CAAEE,GAAG,CAACC,aAAN,CAHnC;AAKA","sourcesContent":["/**\n * Internal dependencies\n */\nimport documentHasTextSelection from './document-has-text-selection';\nimport inputFieldHasUncollapsedSelection from './input-field-has-uncollapsed-selection';\n\n/**\n * Check whether the current document has any sort of (uncollapsed) selection.\n * This includes ranges of text across elements and any selection inside\n * textual `<input>` and `<textarea>` elements.\n *\n * @param {Document} doc The document to check.\n *\n * @return {boolean} Whether there is any recognizable text selection in the document.\n */\nexport default function documentHasUncollapsedSelection( doc ) {\n\treturn (\n\t\tdocumentHasTextSelection( doc ) ||\n\t\t( !! doc.activeElement &&\n\t\t\tinputFieldHasUncollapsedSelection( doc.activeElement ) )\n\t);\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/dom/src/dom/get-rectangle-from-range.js"],"names":["assertIsDefined","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","padNode","createTextNode","cloneRange","insertNode","removeChild"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,eAAT,QAAgC,4BAAhC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAe,SAASC,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;AAAA,UAAE;AAAEC,QAAAA;AAAF,OAAF;AAAA,a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AAwBtB,IAAAA,KAAK,CAACC,IAAN,CACrCoB,UAAU,CAACE,UAD0B,CAAF,CAEhCC,OAFgC,CAEvBN,cAFuB,CAApC;AAIAvB,IAAAA,eAAe,CAAEwB,aAAF,EAAiB,eAAjB,CAAf;AACAtB,IAAAA,KAAK,GAAGsB,aAAa,CAACM,WAAd,EAAR;AACA5B,IAAAA,KAAK,CAAC6B,QAAN,CAAgBL,UAAhB,EAA4BC,KAA5B;AACAzB,IAAAA,KAAK,CAAC8B,MAAN,CAAcN,UAAd,EAA0BC,KAA1B;AACA;;AAED,MAAIM,IAAI,GAAG/B,KAAK,CAACK,cAAN,GAAwB,CAAxB,CAAX,CA/DsD,CAiEtD;AACA;AACA;AACA;AACA;;AACA,MAAK,CAAE0B,IAAP,EAAc;AACbjC,IAAAA,eAAe,CAAEwB,aAAF,EAAiB,eAAjB,CAAf;AACA,UAAMU,OAAO,GAAGV,aAAa,CAACW,cAAd,CAA8B,QAA9B,CAAhB,CAFa,CAGb;;AACAjC,IAAAA,KAAK,GAAGA,KAAK,CAACkC,UAAN,EAAR;AACAlC,IAAAA,KAAK,CAACmC,UAAN,CAAkBH,OAAlB;AACAD,IAAAA,IAAI,GAAG/B,KAAK,CAACK,cAAN,GAAwB,CAAxB,CAAP;AACAP,IAAAA,eAAe,CAAEkC,OAAO,CAACR,UAAV,EAAsB,oBAAtB,CAAf;AACAQ,IAAAA,OAAO,CAACR,UAAR,CAAmBY,WAAnB,CAAgCJ,OAAhC;AACA;;AAED,SAAOD,IAAP;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport { assertIsDefined } from '../utils/assert-is-defined';\n\n/**\n * Get the rectangle of a given Range.\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[]} */ ( Array.from(\n\t\t\tparentNode.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\tlet rect = range.getClientRects()[ 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 ) {\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,"sources":["@wordpress/dom/src/dom/get-rectangle-from-range.js"],"names":["assertIsDefined","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","padNode","createTextNode","cloneRange","insertNode","removeChild"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,eAAT,QAAgC,4BAAhC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAe,SAASC,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;AAAA,UAAE;AAAEC,QAAAA;AAAF,OAAF;AAAA,aAAiBA,KAAK,GAAG,CAAzB;AAAA,KAAd,CAAtB,CATwB,CAWxB;;AACA,QAAKF,aAAa,CAACD,MAAd,KAAyB,CAA9B,EAA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,IAAAA,eAAe,CAAEwB,aAAF,EAAiB,eAAjB,CAAf;AACAtB,IAAAA,KAAK,GAAGsB,aAAa,CAACM,WAAd,EAAR;AACA5B,IAAAA,KAAK,CAAC6B,QAAN,CAAgBL,UAAhB,EAA4BC,KAA5B;AACAzB,IAAAA,KAAK,CAAC8B,MAAN,CAAcN,UAAd,EAA0BC,KAA1B;AACA;;AAED,MAAIM,IAAI,GAAG/B,KAAK,CAACK,cAAN,GAAwB,CAAxB,CAAX,CA/DsD,CAiEtD;AACA;AACA;AACA;AACA;;AACA,MAAK,CAAE0B,IAAP,EAAc;AACbjC,IAAAA,eAAe,CAAEwB,aAAF,EAAiB,eAAjB,CAAf;AACA,UAAMU,OAAO,GAAGV,aAAa,CAACW,cAAd,CAA8B,QAA9B,CAAhB,CAFa,CAGb;;AACAjC,IAAAA,KAAK,GAAGA,KAAK,CAACkC,UAAN,EAAR;AACAlC,IAAAA,KAAK,CAACmC,UAAN,CAAkBH,OAAlB;AACAD,IAAAA,IAAI,GAAG/B,KAAK,CAACK,cAAN,GAAwB,CAAxB,CAAP;AACAP,IAAAA,eAAe,CAAEkC,OAAO,CAACR,UAAV,EAAsB,oBAAtB,CAAf;AACAQ,IAAAA,OAAO,CAACR,UAAR,CAAmBY,WAAnB,CAAgCJ,OAAhC;AACA;;AAED,SAAOD,IAAP;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport { assertIsDefined } from '../utils/assert-is-defined';\n\n/**\n * Get the rectangle of a given Range.\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\tlet rect = range.getClientRects()[ 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 ) {\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"]}
@@ -2,15 +2,19 @@
2
2
  * Internal dependencies
3
3
  */
4
4
  import isTextField from './is-text-field';
5
- import isNumberInput from './is-number-input';
5
+ import isHTMLInputElement from './is-html-input-element';
6
6
  /**
7
- * Check whether the given element, assumed an input field or textarea,
8
- * contains a (uncollapsed) selection of text.
7
+ * Check whether the given input field or textarea contains a (uncollapsed)
8
+ * selection of text.
9
9
  *
10
- * Note: this is perhaps an abuse of the term "selection", since these elements
11
- * manage selection differently and aren't covered by Selection#collapsed.
10
+ * CAVEAT: Only specific text-based HTML inputs support the selection APIs
11
+ * needed to determine whether they have a collapsed or uncollapsed selection.
12
+ * This function defaults to returning `true` when the selection cannot be
13
+ * inspected, such as with `<input type="time">`. The rationale is that this
14
+ * should cause the block editor to defer to the browser's native selection
15
+ * handling (e.g. copying and pasting), thereby reducing friction for the user.
12
16
  *
13
- * See: https://developer.mozilla.org/en-US/docs/Web/API/Window/getSelection#Related_objects.
17
+ * See: https://html.spec.whatwg.org/multipage/input.html#do-not-apply
14
18
  *
15
19
  * @param {Element} element The HTML element.
16
20
  *
@@ -18,9 +22,12 @@ import isNumberInput from './is-number-input';
18
22
  */
19
23
 
20
24
  export default function inputFieldHasUncollapsedSelection(element) {
21
- if (!isTextField(element) && !isNumberInput(element)) {
25
+ if (!isHTMLInputElement(element) && !isTextField(element)) {
22
26
  return false;
23
- }
27
+ } // Safari throws a type error when trying to get `selectionStart` and
28
+ // `selectionEnd` on non-text <input> elements, so a try/catch construct is
29
+ // necessary.
30
+
24
31
 
25
32
  try {
26
33
  const {
@@ -29,17 +36,16 @@ export default function inputFieldHasUncollapsedSelection(element) {
29
36
  } =
30
37
  /** @type {HTMLInputElement | HTMLTextAreaElement} */
31
38
  element;
32
- return selectionStart !== null && selectionStart !== selectionEnd;
39
+ return (// `null` means the input type doesn't implement selection, thus we
40
+ // cannot determine whether the selection is collapsed, so we
41
+ // default to true.
42
+ selectionStart === null || // when not null, compare the two points
43
+ selectionStart !== selectionEnd
44
+ );
33
45
  } catch (error) {
34
- // Safari throws an exception when trying to get `selectionStart`
35
- // on non-text <input> elements (which, understandably, don't
36
- // have the text selection API). We catch this via a try/catch
37
- // block, as opposed to a more explicit check of the element's
38
- // input types, because of Safari's non-standard behavior. This
39
- // also means we don't have to worry about the list of input
40
- // types that support `selectionStart` changing as the HTML spec
41
- // evolves over time.
42
- return false;
46
+ // This is Safari's way of saying that the input type doesn't implement
47
+ // selection, so we default to true.
48
+ return true;
43
49
  }
44
50
  }
45
51
  //# sourceMappingURL=input-field-has-uncollapsed-selection.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/dom/src/dom/input-field-has-uncollapsed-selection.js"],"names":["isTextField","isNumberInput","inputFieldHasUncollapsedSelection","element","selectionStart","selectionEnd","error"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,WAAP,MAAwB,iBAAxB;AACA,OAAOC,aAAP,MAA0B,mBAA1B;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAe,SAASC,iCAAT,CAA4CC,OAA5C,EAAsD;AACpE,MAAK,CAAEH,WAAW,CAAEG,OAAF,CAAb,IAA4B,CAAEF,aAAa,CAAEE,OAAF,CAAhD,EAA8D;AAC7D,WAAO,KAAP;AACA;;AACD,MAAI;AACH,UAAM;AACLC,MAAAA,cADK;AAELC,MAAAA;AAFK;AAGF;AAAwDF,IAAAA,OAH5D;AAKA,WAAOC,cAAc,KAAK,IAAnB,IAA2BA,cAAc,KAAKC,YAArD;AACA,GAPD,CAOE,OAAQC,KAAR,EAAgB;AACjB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,WAAO,KAAP;AACA;AACD","sourcesContent":["/**\n * Internal dependencies\n */\nimport isTextField from './is-text-field';\nimport isNumberInput from './is-number-input';\n\n/**\n * Check whether the given element, assumed an input field or textarea,\n * contains a (uncollapsed) selection of text.\n *\n * Note: this is perhaps an abuse of the term \"selection\", since these elements\n * manage selection differently and aren't covered by Selection#collapsed.\n *\n * See: https://developer.mozilla.org/en-US/docs/Web/API/Window/getSelection#Related_objects.\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 ( ! isTextField( element ) && ! isNumberInput( element ) ) {\n\t\treturn false;\n\t}\n\ttry {\n\t\tconst {\n\t\t\tselectionStart,\n\t\t\tselectionEnd,\n\t\t} = /** @type {HTMLInputElement | HTMLTextAreaElement} */ ( element );\n\n\t\treturn selectionStart !== null && selectionStart !== selectionEnd;\n\t} catch ( error ) {\n\t\t// Safari throws an exception when trying to get `selectionStart`\n\t\t// on non-text <input> elements (which, understandably, don't\n\t\t// have the text selection API). We catch this via a try/catch\n\t\t// block, as opposed to a more explicit check of the element's\n\t\t// input types, because of Safari's non-standard behavior. This\n\t\t// also means we don't have to worry about the list of input\n\t\t// types that support `selectionStart` changing as the HTML spec\n\t\t// evolves over time.\n\t\treturn false;\n\t}\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/dom/src/dom/input-field-has-uncollapsed-selection.js"],"names":["isTextField","isHTMLInputElement","inputFieldHasUncollapsedSelection","element","selectionStart","selectionEnd","error"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,WAAP,MAAwB,iBAAxB;AACA,OAAOC,kBAAP,MAA+B,yBAA/B;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAe,SAASC,iCAAT,CAA4CC,OAA5C,EAAsD;AACpE,MAAK,CAAEF,kBAAkB,CAAEE,OAAF,CAApB,IAAmC,CAAEH,WAAW,CAAEG,OAAF,CAArD,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 +1 @@
1
- {"version":3,"sources":["@wordpress/dom/src/dom/is-edge.js"],"names":["isRTL","getRangeHeight","getRectangleFromRange","isSelectionForward","hiddenCaretRangeFromPoint","assertIsDefined","isInputOrTextArea","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":"AAAA;AACA;AACA;AACA,OAAOA,KAAP,MAAkB,UAAlB;AACA,OAAOC,cAAP,MAA2B,oBAA3B;AACA,OAAOC,qBAAP,MAAkC,4BAAlC;AACA,OAAOC,kBAAP,MAA+B,wBAA/B;AACA,OAAOC,yBAAP,MAAsC,iCAAtC;AACA,SAASC,eAAT,QAAgC,4BAAhC;AACA,OAAOC,iBAAP,MAA8B,yBAA9B;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAe,SAASC,MAAT,CAAiBC,SAAjB,EAA4BC,SAA5B,EAA8D;AAAA,MAAvBC,YAAuB,uEAAR,KAAQ;;AAC5E,MACCJ,iBAAiB,CAAEE,SAAF,CAAjB,IACA,OAAOA,SAAS,CAACG,cAAjB,KAAoC,QAFrC,EAGE;AACD,QAAKH,SAAS,CAACG,cAAV,KAA6BH,SAAS,CAACI,YAA5C,EAA2D;AAC1D,aAAO,KAAP;AACA;;AAED,QAAKH,SAAL,EAAiB;AAChB,aAAOD,SAAS,CAACG,cAAV,KAA6B,CAApC;AACA;;AAED,WAAOH,SAAS,CAACK,KAAV,CAAgBC,MAAhB,KAA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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,"sources":["@wordpress/dom/src/dom/is-edge.js"],"names":["isRTL","getRangeHeight","getRectangleFromRange","isSelectionForward","hiddenCaretRangeFromPoint","assertIsDefined","isInputOrTextArea","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":"AAAA;AACA;AACA;AACA,OAAOA,KAAP,MAAkB,UAAlB;AACA,OAAOC,cAAP,MAA2B,oBAA3B;AACA,OAAOC,qBAAP,MAAkC,4BAAlC;AACA,OAAOC,kBAAP,MAA+B,wBAA/B;AACA,OAAOC,yBAAP,MAAsC,iCAAtC;AACA,SAASC,eAAT,QAAgC,4BAAhC;AACA,OAAOC,iBAAP,MAA8B,yBAA9B;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAe,SAASC,MAAT,CAAiBC,SAAjB,EAA4BC,SAA5B,EAA8D;AAAA,MAAvBC,YAAuB,uEAAR,KAAQ;;AAC5E,MACCJ,iBAAiB,CAAEE,SAAF,CAAjB,IACA,OAAOA,SAAS,CAACG,cAAjB,KAAoC,QAFrC,EAGE;AACD,QAAKH,SAAS,CAACG,cAAV,KAA6BH,SAAS,CAACI,YAA5C,EAA2D;AAC1D,aAAO,KAAP;AACA;;AAED,QAAKH,SAAL,EAAiB;AAChB,aAAOD,SAAS,CAACG,cAAV,KAA6B,CAApC;AACA;;AAED,WAAOH,SAAS,CAACK,KAAV,CAAgBC,MAAhB,KAA2BN,SAAS,CAACG,cAA5C;AACA;;AAED,MAAK;AAAI;AAA6BH,EAAAA,SAAF,CAAcO,iBAAlD,EAAwE;AACvE,WAAO,IAAP;AACA;;AAED,Q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A;AACA;AACA;;AACA,QAAMC,CAAC,GAAGH,YAAY,GAAGC,aAAa,CAACG,IAAd,GAAqB,CAAxB,GAA4BH,aAAa,CAACI,KAAd,GAAsB,CAAxE;AACA,QAAMC,CAAC,GAAG7B,SAAS,GAAGwB,aAAa,CAACM,GAAd,GAAoB,CAAvB,GAA2BN,aAAa,CAACO,MAAd,GAAuB,CAArE;AACA,QAAMC,SAAS,GAAGrC,yBAAyB,CAC1CY,aAD0C,EAE1CmB,CAF0C,EAG1CG,CAH0C;AAI1C;AAA6B9B,EAAAA,SAJa,CAA3C;;AAOA,MAAK,CAAEiC,SAAP,EAAmB;AAClB,WAAO,KAAP;AACA;;AAED,QAAMC,QAAQ,GAAGxC,qBAAqB,CAAEuC,SAAF,CAAtC;;AAEA,MAAK,CAAEC,QAAP,EAAkB;AACjB,WAAO,KAAP;AACA;;AAED,QAAMC,YAAY,GAAGlC,SAAS,GAAG,KAAH,GAAW,QAAzC;AACA,QAAMmC,cAAc,GAAGZ,YAAY,GAAG,MAAH,GAAY,OAA/C;AACA,QAAMa,YAAY,GAAGH,QAAQ,CAAEC,YAAF,CAAR,GAA2Bd,SAAS,CAAEc,YAAF,CAAzD;AACA,QAAMG,cAAc,GACnBJ,QAAQ,CAAEE,cAAF,CAAR,GAA6BhB,kBAAkB,CAAEgB,cAAF,CADhD,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 +1 @@
1
- {"version":3,"sources":["@wordpress/dom/src/dom/is-empty.js"],"names":["isEmpty","element","nodeType","TEXT_NODE","test","nodeValue","ELEMENT_NODE","hasAttributes","hasChildNodes","Array","from","childNodes","every"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASA,OAAT,CAAkBC,OAAlB,EAA4B;AAC1C,UAASA,OAAO,CAACC,QAAjB;AACC,SAAKD,OAAO,CAACE,SAAb;AACC;AACA;AACA,aAAO,yBAAyBC,IAAzB,CAA+BH,OAAO,CAACI,SAAR,IAAqB,EAApD,CAAP;;AACD,SAAKJ,OAAO,CAACK,YAAb;AACC,UAAKL,OAAO,CAACM,aAAR,EAAL,EAA+B;AAC9B,eAAO,KAAP;AACA,OAFD,MAEO,IAAK,CAAEN,OAAO,CAACO,aAAR,EAAP,EAAiC;AACvC,eAAO,IAAP;AACA;;AAED;AAAO;AAA2BC,QAAAA,KAAK,CAACC,IAAN,CACjCT,OAAO,CAACU,UADyB,CAAF,CAE5BC,KAF4B,CAErBZ,OAFqB;AAAhC;;AAGD;AACC,aAAO,IAAP;AAhBF;AAkBA","sourcesContent":["/**\n * Recursively checks if an element is empty. An element is not empty if it\n * contains text or contains elements with attributes such as images.\n *\n * @param {Element} element The element to check.\n *\n * @return {boolean} Whether or not the element is empty.\n */\nexport default function isEmpty( element ) {\n\tswitch ( element.nodeType ) {\n\t\tcase element.TEXT_NODE:\n\t\t\t// We cannot use \\s since it includes special spaces which we want\n\t\t\t// to preserve.\n\t\t\treturn /^[ \\f\\n\\r\\t\\v\\u00a0]*$/.test( element.nodeValue || '' );\n\t\tcase element.ELEMENT_NODE:\n\t\t\tif ( element.hasAttributes() ) {\n\t\t\t\treturn false;\n\t\t\t} else if ( ! element.hasChildNodes() ) {\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\treturn /** @type {Element[]} */ ( Array.from(\n\t\t\t\telement.childNodes\n\t\t\t) ).every( isEmpty );\n\t\tdefault:\n\t\t\treturn true;\n\t}\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/dom/src/dom/is-empty.js"],"names":["isEmpty","element","nodeType","TEXT_NODE","test","nodeValue","ELEMENT_NODE","hasAttributes","hasChildNodes","Array","from","childNodes","every"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASA,OAAT,CAAkBC,OAAlB,EAA4B;AAC1C,UAASA,OAAO,CAACC,QAAjB;AACC,SAAKD,OAAO,CAACE,SAAb;AACC;AACA;AACA,aAAO,yBAAyBC,IAAzB,CAA+BH,OAAO,CAACI,SAAR,IAAqB,EAApD,CAAP;;AACD,SAAKJ,OAAO,CAACK,YAAb;AACC,UAAKL,OAAO,CAACM,aAAR,EAAL,EAA+B;AAC9B,eAAO,KAAP;AACA,OAFD,MAEO,IAAK,CAAEN,OAAO,CAACO,aAAR,EAAP,EAAiC;AACvC,eAAO,IAAP;AACA;;AAED;AAAO;AACNC,QAAAA,KAAK,CAACC,IAAN,CAAYT,OAAO,CAACU,UAApB,CAD+B,CAE9BC,KAF8B,CAEvBZ,OAFuB;AAAhC;;AAGD;AACC,aAAO,IAAP;AAhBF;AAkBA","sourcesContent":["/**\n * Recursively checks if an element is empty. An element is not empty if it\n * contains text or contains elements with attributes such as images.\n *\n * @param {Element} element The element to check.\n *\n * @return {boolean} Whether or not the element is empty.\n */\nexport default function isEmpty( element ) {\n\tswitch ( element.nodeType ) {\n\t\tcase element.TEXT_NODE:\n\t\t\t// We cannot use \\s since it includes special spaces which we want\n\t\t\t// to preserve.\n\t\t\treturn /^[ \\f\\n\\r\\t\\v\\u00a0]*$/.test( element.nodeValue || '' );\n\t\tcase element.ELEMENT_NODE:\n\t\t\tif ( element.hasAttributes() ) {\n\t\t\t\treturn false;\n\t\t\t} else if ( ! element.hasChildNodes() ) {\n\t\t\t\treturn true;\n\t\t\t}\n\n\t\t\treturn /** @type {Element[]} */ (\n\t\t\t\tArray.from( element.childNodes )\n\t\t\t).every( isEmpty );\n\t\tdefault:\n\t\t\treturn true;\n\t}\n}\n"]}
@@ -6,6 +6,6 @@
6
6
  */
7
7
  export default function isHTMLInputElement(node) {
8
8
  /* eslint-enable jsdoc/valid-types */
9
- return !!node && node.nodeName === 'INPUT';
9
+ return (node === null || node === void 0 ? void 0 : node.nodeName) === 'INPUT';
10
10
  }
11
11
  //# sourceMappingURL=is-html-input-element.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/dom/src/dom/is-html-input-element.js"],"names":["isHTMLInputElement","node","nodeName"],"mappings":"AAAA;;AACA;AACA;AACA;AACA;AACA,eAAe,SAASA,kBAAT,CAA6BC,IAA7B,EAAoC;AAClD;AACA,SAAO,CAAC,CAAEA,IAAH,IAAWA,IAAI,CAACC,QAAL,KAAkB,OAApC;AACA","sourcesContent":["/* eslint-disable jsdoc/valid-types */\n/**\n * @param {Node} node\n * @return {node is HTMLInputElement} Whether the node is an HTMLInputElement.\n */\nexport default function isHTMLInputElement( node ) {\n\t/* eslint-enable jsdoc/valid-types */\n\treturn !! node && node.nodeName === 'INPUT';\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/dom/src/dom/is-html-input-element.js"],"names":["isHTMLInputElement","node","nodeName"],"mappings":"AAAA;;AACA;AACA;AACA;AACA;AACA,eAAe,SAASA,kBAAT,CAA6BC,IAA7B,EAAoC;AAClD;AACA,SAAO,CAAAA,IAAI,SAAJ,IAAAA,IAAI,WAAJ,YAAAA,IAAI,CAAEC,QAAN,MAAmB,OAA1B;AACA","sourcesContent":["/* eslint-disable jsdoc/valid-types */\n/**\n * @param {Node} node\n * @return {node is HTMLInputElement} Whether the node is an HTMLInputElement.\n */\nexport default function isHTMLInputElement( node ) {\n\t/* eslint-enable jsdoc/valid-types */\n\treturn node?.nodeName === 'INPUT';\n}\n"]}
@@ -1,20 +1,29 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import deprecated from '@wordpress/deprecated';
1
5
  /**
2
6
  * Internal dependencies
3
7
  */
8
+
4
9
  import isHTMLInputElement from './is-html-input-element';
5
10
  /* eslint-disable jsdoc/valid-types */
6
11
 
7
12
  /**
8
- * Check whether the given element is an input field of type number
9
- * and has a valueAsNumber
13
+ * Check whether the given element is an input field of type number.
10
14
  *
11
15
  * @param {Node} node The HTML node.
12
16
  *
13
- * @return {node is HTMLInputElement} True if the node is input and holds a number.
17
+ * @return {node is HTMLInputElement} True if the node is number input.
14
18
  */
15
19
 
16
20
  export default function isNumberInput(node) {
21
+ deprecated('wp.dom.isNumberInput', {
22
+ since: '6.1',
23
+ version: '6.5'
24
+ });
17
25
  /* eslint-enable jsdoc/valid-types */
18
- return isHTMLInputElement(node) && node.type === 'number' && !!node.valueAsNumber;
26
+
27
+ return isHTMLInputElement(node) && node.type === 'number' && !isNaN(node.valueAsNumber);
19
28
  }
20
29
  //# sourceMappingURL=is-number-input.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/dom/src/dom/is-number-input.js"],"names":["isHTMLInputElement","isNumberInput","node","type","valueAsNumber"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,kBAAP,MAA+B,yBAA/B;AAEA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAe,SAASC,aAAT,CAAwBC,IAAxB,EAA+B;AAC7C;AACA,SACCF,kBAAkB,CAAEE,IAAF,CAAlB,IACAA,IAAI,CAACC,IAAL,KAAc,QADd,IAEA,CAAC,CAAED,IAAI,CAACE,aAHT;AAKA","sourcesContent":["/**\n * Internal dependencies\n */\nimport isHTMLInputElement from './is-html-input-element';\n\n/* eslint-disable jsdoc/valid-types */\n/**\n * Check whether the given element is an input field of type number\n * and has a valueAsNumber\n *\n * @param {Node} node The HTML node.\n *\n * @return {node is HTMLInputElement} True if the node is input and holds a number.\n */\nexport default function isNumberInput( node ) {\n\t/* eslint-enable jsdoc/valid-types */\n\treturn (\n\t\tisHTMLInputElement( node ) &&\n\t\tnode.type === 'number' &&\n\t\t!! node.valueAsNumber\n\t);\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/dom/src/dom/is-number-input.js"],"names":["deprecated","isHTMLInputElement","isNumberInput","node","since","version","type","isNaN","valueAsNumber"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,UAAP,MAAuB,uBAAvB;AAEA;AACA;AACA;;AACA,OAAOC,kBAAP,MAA+B,yBAA/B;AAEA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAe,SAASC,aAAT,CAAwBC,IAAxB,EAA+B;AAC7CH,EAAAA,UAAU,CAAE,sBAAF,EAA0B;AACnCI,IAAAA,KAAK,EAAE,KAD4B;AAEnCC,IAAAA,OAAO,EAAE;AAF0B,GAA1B,CAAV;AAIA;;AACA,SACCJ,kBAAkB,CAAEE,IAAF,CAAlB,IACAA,IAAI,CAACG,IAAL,KAAc,QADd,IAEA,CAAEC,KAAK,CAAEJ,IAAI,CAACK,aAAP,CAHR;AAKA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport isHTMLInputElement from './is-html-input-element';\n\n/* eslint-disable jsdoc/valid-types */\n/**\n * Check whether the given element is an input field of type number.\n *\n * @param {Node} node The HTML node.\n *\n * @return {node is HTMLInputElement} True if the node is number input.\n */\nexport default function isNumberInput( node ) {\n\tdeprecated( 'wp.dom.isNumberInput', {\n\t\tsince: '6.1',\n\t\tversion: '6.5',\n\t} );\n\t/* eslint-enable jsdoc/valid-types */\n\treturn (\n\t\tisHTMLInputElement( node ) &&\n\t\tnode.type === 'number' &&\n\t\t! isNaN( node.valueAsNumber )\n\t);\n}\n"]}
@@ -16,7 +16,7 @@ import isHTMLInputElement from './is-html-input-element';
16
16
 
17
17
  export default function isTextField(node) {
18
18
  /* eslint-enable jsdoc/valid-types */
19
- const nonTextInputs = ['button', 'checkbox', 'hidden', 'file', 'radio', 'image', 'range', 'reset', 'submit', 'number'];
19
+ const nonTextInputs = ['button', 'checkbox', 'hidden', 'file', 'radio', 'image', 'range', 'reset', 'submit', 'number', 'email', 'time'];
20
20
  return isHTMLInputElement(node) && node.type && !nonTextInputs.includes(node.type) || node.nodeName === 'TEXTAREA' ||
21
21
  /** @type {HTMLElement} */
22
22
  node.contentEditable === 'true';
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/dom/src/dom/is-text-field.js"],"names":["isHTMLInputElement","isTextField","node","nonTextInputs","type","includes","nodeName","contentEditable"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,kBAAP,MAA+B,yBAA/B;AAEA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAe,SAASC,WAAT,CAAsBC,IAAtB,EAA6B;AAC3C;AACA,QAAMC,aAAa,GAAG,CACrB,QADqB,EAErB,UAFqB,EAGrB,QAHqB,EAIrB,MAJqB,EAKrB,OALqB,EAMrB,OANqB,EAOrB,OAPqB,EAQrB,OARqB,EASrB,QATqB,EAUrB,QAVqB,CAAtB;AAYA,SACGH,kBAAkB,CAAEE,IAAF,CAAlB,IACDA,IAAI,CAACE,IADJ,IAED,CAAED,aAAa,CAACE,QAAd,CAAwBH,IAAI,CAACE,IAA7B,CAFH,IAGAF,IAAI,CAACI,QAAL,KAAkB,UAHlB;AAIA;AAA6BJ,EAAAA,IAAF,CAASK,eAAT,KAA6B,MALzD;AAOA","sourcesContent":["/**\n * Internal dependencies\n */\nimport isHTMLInputElement from './is-html-input-element';\n\n/* eslint-disable jsdoc/valid-types */\n/**\n * Check whether the given element is a text field, where text field is defined\n * by the ability to select within the input, or that it is contenteditable.\n *\n * See: https://html.spec.whatwg.org/#textFieldSelection\n *\n * @param {Node} node The HTML element.\n * @return {node is HTMLElement} True if the element is an text field, false if not.\n */\nexport default function isTextField( node ) {\n\t/* eslint-enable jsdoc/valid-types */\n\tconst nonTextInputs = [\n\t\t'button',\n\t\t'checkbox',\n\t\t'hidden',\n\t\t'file',\n\t\t'radio',\n\t\t'image',\n\t\t'range',\n\t\t'reset',\n\t\t'submit',\n\t\t'number',\n\t];\n\treturn (\n\t\t( isHTMLInputElement( node ) &&\n\t\t\tnode.type &&\n\t\t\t! nonTextInputs.includes( node.type ) ) ||\n\t\tnode.nodeName === 'TEXTAREA' ||\n\t\t/** @type {HTMLElement} */ ( node ).contentEditable === 'true'\n\t);\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/dom/src/dom/is-text-field.js"],"names":["isHTMLInputElement","isTextField","node","nonTextInputs","type","includes","nodeName","contentEditable"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,kBAAP,MAA+B,yBAA/B;AAEA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAe,SAASC,WAAT,CAAsBC,IAAtB,EAA6B;AAC3C;AACA,QAAMC,aAAa,GAAG,CACrB,QADqB,EAErB,UAFqB,EAGrB,QAHqB,EAIrB,MAJqB,EAKrB,OALqB,EAMrB,OANqB,EAOrB,OAPqB,EAQrB,OARqB,EASrB,QATqB,EAUrB,QAVqB,EAWrB,OAXqB,EAYrB,MAZqB,CAAtB;AAcA,SACGH,kBAAkB,CAAEE,IAAF,CAAlB,IACDA,IAAI,CAACE,IADJ,IAED,CAAED,aAAa,CAACE,QAAd,CAAwBH,IAAI,CAACE,IAA7B,CAFH,IAGAF,IAAI,CAACI,QAAL,KAAkB,UAHlB;AAIA;AAA6BJ,EAAAA,IAAF,CAASK,eAAT,KAA6B,MALzD;AAOA","sourcesContent":["/**\n * Internal dependencies\n */\nimport isHTMLInputElement from './is-html-input-element';\n\n/* eslint-disable jsdoc/valid-types */\n/**\n * Check whether the given element is a text field, where text field is defined\n * by the ability to select within the input, or that it is contenteditable.\n *\n * See: https://html.spec.whatwg.org/#textFieldSelection\n *\n * @param {Node} node The HTML element.\n * @return {node is HTMLElement} True if the element is an text field, false if not.\n */\nexport default function isTextField( node ) {\n\t/* eslint-enable jsdoc/valid-types */\n\tconst nonTextInputs = [\n\t\t'button',\n\t\t'checkbox',\n\t\t'hidden',\n\t\t'file',\n\t\t'radio',\n\t\t'image',\n\t\t'range',\n\t\t'reset',\n\t\t'submit',\n\t\t'number',\n\t\t'email',\n\t\t'time',\n\t];\n\treturn (\n\t\t( isHTMLInputElement( node ) &&\n\t\t\tnode.type &&\n\t\t\t! nonTextInputs.includes( node.type ) ) ||\n\t\tnode.nodeName === 'TEXTAREA' ||\n\t\t/** @type {HTMLElement} */ ( node ).contentEditable === 'true'\n\t);\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"clean-node-list.d.ts","sourceRoot":"","sources":["../../src/dom/clean-node-list.js"],"names":[],"mappings":"AAgBA;;;;;;;;GAQG;AAEH,sDAAsD;AAGtD;;;;;;;;GAQG;AACH,gDALW,QAAQ,OACR,QAAQ,UACR,MAAM,UACN,OAAO,QAqJjB;;;;;;;;;;;;;;;;;;;;;;;gBAnKa,OAAO;;;;sBACA,IAAI,KAAK,OAAO"}
1
+ {"version":3,"file":"clean-node-list.d.ts","sourceRoot":"","sources":["../../src/dom/clean-node-list.js"],"names":[],"mappings":"AAkBA;;;;;;;;GAQG;AAEH,sDAAsD;AAGtD;;;;;;;;GAQG;AACH,gDALW,QAAQ,OACR,QAAQ,UACR,MAAM,UACN,OAAO,QAwJjB;;;;;;;;;;;;;;;;;;;;;;;gBAtKa,OAAO;;;;sBACA,IAAI,KAAK,OAAO"}
@@ -1,6 +1,6 @@
1
1
  /**
2
- * Check whether the current document has a selection. This checks for both
3
- * focus in an input field and general text selection.
2
+ * Check whether the current document has a selection. This includes focus in
3
+ * input fields, textareas, and general rich-text selection.
4
4
  *
5
5
  * @param {Document} doc The document to check.
6
6
  *
@@ -1,11 +1,11 @@
1
1
  /**
2
- * Check whether the current document has any sort of selection. This includes
3
- * ranges of text across elements and any selection inside `<input>` and
4
- * `<textarea>` elements.
2
+ * Check whether the current document has any sort of (uncollapsed) selection.
3
+ * This includes ranges of text across elements and any selection inside
4
+ * textual `<input>` and `<textarea>` elements.
5
5
  *
6
6
  * @param {Document} doc The document to check.
7
7
  *
8
- * @return {boolean} Whether there is any sort of "selection" in the document.
8
+ * @return {boolean} Whether there is any recognizable text selection in the document.
9
9
  */
10
10
  export default function documentHasUncollapsedSelection(doc: Document): boolean;
11
11
  //# sourceMappingURL=document-has-uncollapsed-selection.d.ts.map
@@ -1,11 +1,15 @@
1
1
  /**
2
- * Check whether the given element, assumed an input field or textarea,
3
- * contains a (uncollapsed) selection of text.
2
+ * Check whether the given input field or textarea contains a (uncollapsed)
3
+ * selection of text.
4
4
  *
5
- * Note: this is perhaps an abuse of the term "selection", since these elements
6
- * manage selection differently and aren't covered by Selection#collapsed.
5
+ * CAVEAT: Only specific text-based HTML inputs support the selection APIs
6
+ * needed to determine whether they have a collapsed or uncollapsed selection.
7
+ * This function defaults to returning `true` when the selection cannot be
8
+ * inspected, such as with `<input type="time">`. The rationale is that this
9
+ * should cause the block editor to defer to the browser's native selection
10
+ * handling (e.g. copying and pasting), thereby reducing friction for the user.
7
11
  *
8
- * See: https://developer.mozilla.org/en-US/docs/Web/API/Window/getSelection#Related_objects.
12
+ * See: https://html.spec.whatwg.org/multipage/input.html#do-not-apply
9
13
  *
10
14
  * @param {Element} element The HTML element.
11
15
  *
@@ -1 +1 @@
1
- {"version":3,"file":"input-field-has-uncollapsed-selection.d.ts","sourceRoot":"","sources":["../../src/dom/input-field-has-uncollapsed-selection.js"],"names":[],"mappings":"AAMA;;;;;;;;;;;;GAYG;AACH,mEAJW,OAAO,GAEN,OAAO,CAwBlB"}
1
+ {"version":3,"file":"input-field-has-uncollapsed-selection.d.ts","sourceRoot":"","sources":["../../src/dom/input-field-has-uncollapsed-selection.js"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;;;GAgBG;AACH,mEAJW,OAAO,GAEN,OAAO,CA0BlB"}
@@ -1,10 +1,9 @@
1
1
  /**
2
- * Check whether the given element is an input field of type number
3
- * and has a valueAsNumber
2
+ * Check whether the given element is an input field of type number.
4
3
  *
5
4
  * @param {Node} node The HTML node.
6
5
  *
7
- * @return {node is HTMLInputElement} True if the node is input and holds a number.
6
+ * @return {node is HTMLInputElement} True if the node is number input.
8
7
  */
9
8
  export default function isNumberInput(node: Node): node is HTMLInputElement;
10
9
  //# sourceMappingURL=is-number-input.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"is-number-input.d.ts","sourceRoot":"","sources":["../../src/dom/is-number-input.js"],"names":[],"mappings":"AAMA;;;;;;;GAOG;AACH,4CAJW,IAAI,4BAWd"}
1
+ {"version":3,"file":"is-number-input.d.ts","sourceRoot":"","sources":["../../src/dom/is-number-input.js"],"names":[],"mappings":"AAWA;;;;;;GAMG;AACH,4CAJW,IAAI,4BAed"}
@@ -1 +1 @@
1
- {"version":3,"file":"is-text-field.d.ts","sourceRoot":"","sources":["../../src/dom/is-text-field.js"],"names":[],"mappings":"AAMA;;;;;;;;GAQG;AACH,0CAHW,IAAI,uBAwBd"}
1
+ {"version":3,"file":"is-text-field.d.ts","sourceRoot":"","sources":["../../src/dom/is-text-field.js"],"names":[],"mappings":"AAMA;;;;;;;;GAQG;AACH,0CAHW,IAAI,uBA0Bd"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/dom",
3
- "version": "3.8.0",
3
+ "version": "3.11.0",
4
4
  "description": "DOM utilities module for WordPress.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -29,10 +29,11 @@
29
29
  "sideEffects": false,
30
30
  "dependencies": {
31
31
  "@babel/runtime": "^7.16.0",
32
+ "@wordpress/deprecated": "^3.8.0",
32
33
  "lodash": "^4.17.21"
33
34
  },
34
35
  "publishConfig": {
35
36
  "access": "public"
36
37
  },
37
- "gitHead": "4631d515033397fcfeda77e5755960253caef9bf"
38
+ "gitHead": "48d5f37dfb52d2e77c8eeb662f9874cf141b8c6b"
38
39
  }