@wordpress/dom 3.2.2 → 3.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/README.md +3 -4
  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/document-has-text-selection.js +1 -1
  5. package/build/dom/document-has-text-selection.js.map +1 -1
  6. package/build/dom/document-has-uncollapsed-selection.js +2 -2
  7. package/build/dom/document-has-uncollapsed-selection.js.map +1 -1
  8. package/build/dom/is-edge.js +1 -1
  9. package/build/dom/is-edge.js.map +1 -1
  10. package/build/dom/place-caret-at-edge.js +108 -0
  11. package/build/dom/place-caret-at-edge.js.map +1 -0
  12. package/build/dom/place-caret-at-horizontal-edge.js +2 -84
  13. package/build/dom/place-caret-at-horizontal-edge.js.map +1 -1
  14. package/build/dom/place-caret-at-vertical-edge.js +6 -56
  15. package/build/dom/place-caret-at-vertical-edge.js.map +1 -1
  16. package/build/dom/strip-html.js +14 -2
  17. package/build/dom/strip-html.js.map +1 -1
  18. package/build/focusable.js +29 -18
  19. package/build/focusable.js.map +1 -1
  20. package/build/phrasing-content.js +1 -1
  21. package/build/phrasing-content.js.map +1 -1
  22. package/build/tabbable.js +2 -2
  23. package/build/tabbable.js.map +1 -1
  24. package/build-module/dom/caret-range-from-point.js +7 -3
  25. package/build-module/dom/caret-range-from-point.js.map +1 -1
  26. package/build-module/dom/document-has-text-selection.js +1 -1
  27. package/build-module/dom/document-has-text-selection.js.map +1 -1
  28. package/build-module/dom/document-has-uncollapsed-selection.js +2 -2
  29. package/build-module/dom/document-has-uncollapsed-selection.js.map +1 -1
  30. package/build-module/dom/is-edge.js +1 -1
  31. package/build-module/dom/is-edge.js.map +1 -1
  32. package/build-module/dom/place-caret-at-edge.js +95 -0
  33. package/build-module/dom/place-caret-at-edge.js.map +1 -0
  34. package/build-module/dom/place-caret-at-horizontal-edge.js +2 -81
  35. package/build-module/dom/place-caret-at-horizontal-edge.js.map +1 -1
  36. package/build-module/dom/place-caret-at-vertical-edge.js +6 -54
  37. package/build-module/dom/place-caret-at-vertical-edge.js.map +1 -1
  38. package/build-module/dom/strip-html.js +11 -2
  39. package/build-module/dom/strip-html.js.map +1 -1
  40. package/build-module/focusable.js +29 -18
  41. package/build-module/focusable.js.map +1 -1
  42. package/build-module/phrasing-content.js +1 -1
  43. package/build-module/phrasing-content.js.map +1 -1
  44. package/build-module/tabbable.js +2 -2
  45. package/build-module/tabbable.js.map +1 -1
  46. package/build-types/dom/caret-range-from-point.d.ts +12 -4
  47. package/build-types/dom/caret-range-from-point.d.ts.map +1 -1
  48. package/build-types/dom/clean-node-list.d.ts +2 -2
  49. package/build-types/dom/document-has-text-selection.d.ts +1 -1
  50. package/build-types/dom/document-has-uncollapsed-selection.d.ts +2 -2
  51. package/build-types/dom/is-edge.d.ts.map +1 -1
  52. package/build-types/dom/place-caret-at-edge.d.ts +9 -0
  53. package/build-types/dom/place-caret-at-edge.d.ts.map +1 -0
  54. package/build-types/dom/place-caret-at-horizontal-edge.d.ts.map +1 -1
  55. package/build-types/dom/place-caret-at-vertical-edge.d.ts +4 -5
  56. package/build-types/dom/place-caret-at-vertical-edge.d.ts.map +1 -1
  57. package/build-types/dom/strip-html.d.ts.map +1 -1
  58. package/build-types/focusable.d.ts +11 -2
  59. package/build-types/focusable.d.ts.map +1 -1
  60. package/build-types/phrasing-content.d.ts +2 -4
  61. package/build-types/phrasing-content.d.ts.map +1 -1
  62. package/build-types/tabbable.d.ts +3 -3
  63. package/build-types/tabbable.d.ts.map +1 -1
  64. package/package.json +2 -2
  65. package/src/dom/caret-range-from-point.js +8 -3
  66. package/src/dom/document-has-text-selection.js +1 -1
  67. package/src/dom/document-has-uncollapsed-selection.js +2 -2
  68. package/src/dom/is-edge.js +4 -1
  69. package/src/dom/place-caret-at-edge.js +95 -0
  70. package/src/dom/place-caret-at-horizontal-edge.js +2 -83
  71. package/src/dom/place-caret-at-vertical-edge.js +6 -64
  72. package/src/dom/strip-html.js +12 -5
  73. package/src/dom/test/strip-html.js +64 -0
  74. package/src/focusable.js +37 -32
  75. package/src/phrasing-content.js +1 -1
  76. package/src/tabbable.js +2 -4
  77. package/src/test/dom.js +8 -15
  78. package/tsconfig.tsbuildinfo +1 -1170
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/dom/src/focusable.js"],"names":["SELECTOR","join","isVisible","element","offsetWidth","offsetHeight","getClientRects","length","skipFocus","nodeName","toLowerCase","getAttribute","isValidFocusableArea","map","closest","img","ownerDocument","querySelector","name","find","context","elements","querySelectorAll","Array","from","filter"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAEA,MAAMA,QAAQ,GAAG,CAChB,YADgB,EAEhB,SAFgB,EAGhB,wBAHgB,EAIhB,4CAJgB,EAKhB,wBALgB,EAMhB,0BANgB,EAOhB,QAPgB,EAQhB,QARgB,EAShB,OATgB,EAUhB,YAVgB,EAWhB,gDAXgB,EAYfC,IAZe,CAYT,GAZS,CAAjB;AAcA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,SAAT,CAAoBC,OAApB,EAA8B;AAC7B,SACCA,OAAO,CAACC,WAAR,GAAsB,CAAtB,IACAD,OAAO,CAACE,YAAR,GAAuB,CADvB,IAEAF,OAAO,CAACG,cAAR,GAAyBC,MAAzB,GAAkC,CAHnC;AAKA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASC,SAAT,CAAoBL,OAApB,EAA8B;AAC7B,SACCA,OAAO,CAACM,QAAR,CAAiBC,WAAjB,OAAmC,QAAnC,IACAP,OAAO,CAACQ,YAAR,CAAsB,UAAtB,MAAuC,IAFxC;AAIA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASC,oBAAT,CAA+BT,OAA/B,EAAyC;AACxC;AACA,QAAMU,GAAG,GAAGV,OAAO,CAACW,OAAR,CAAiB,WAAjB,CAAZ;;AACA,MAAK,CAAED,GAAP,EAAa;AACZ,WAAO,KAAP;AACA;AAED;;;AACA,QAAME,GAAG,GAAGZ,OAAO,CAACa,aAAR,CAAsBC,aAAtB,CACX,kBAAkBJ,GAAG,CAACK,IAAtB,GAA6B,IADlB,CAAZ;AAGA,SAAO,CAAC,CAAEH,GAAH,IAAUb,SAAS,CAAEa,GAAF,CAA1B;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASI,IAAT,CAAeC,OAAf,EAAyB;AAC/B;;AACA;;AACA;AACA,QAAMC,QAAQ,GAAGD,OAAO,CAACE,gBAAR,CAA0BtB,QAA1B,CAAjB;AAEA,SAAOuB,KAAK,CAACC,IAAN,CAAYH,QAAZ,EAAuBI,MAAvB,CAAiCtB,OAAF,IAAe;AACpD,QAAK,CAAED,SAAS,CAAEC,OAAF,CAAX,IAA0BK,SAAS,CAAEL,OAAF,CAAxC,EAAsD;AACrD,aAAO,KAAP;AACA;;AAED,UAAM;AAAEM,MAAAA;AAAF,QAAeN,OAArB;;AACA,QAAK,WAAWM,QAAhB,EAA2B;AAC1B,aAAOG,oBAAoB;AAC1B;AAAiCT,MAAAA,OADP,CAA3B;AAGA;;AAED,WAAO,IAAP;AACA,GAbM,CAAP;AAcA","sourcesContent":["/**\n * References:\n *\n * Focusable:\n * - https://www.w3.org/TR/html5/editing.html#focus-management\n *\n * Sequential focus navigation:\n * - https://www.w3.org/TR/html5/editing.html#sequential-focus-navigation-and-the-tabindex-attribute\n *\n * Disabled elements:\n * - https://www.w3.org/TR/html5/disabled-elements.html#disabled-elements\n *\n * getClientRects algorithm (requiring layout box):\n * - https://www.w3.org/TR/cssom-view-1/#extension-to-the-element-interface\n *\n * AREA elements associated with an IMG:\n * - https://w3c.github.io/html/editing.html#data-model\n */\n\nconst SELECTOR = [\n\t'[tabindex]',\n\t'a[href]',\n\t'button:not([disabled])',\n\t'input:not([type=\"hidden\"]):not([disabled])',\n\t'select:not([disabled])',\n\t'textarea:not([disabled])',\n\t'iframe',\n\t'object',\n\t'embed',\n\t'area[href]',\n\t'[contenteditable]:not([contenteditable=false])',\n].join( ',' );\n\n/**\n * Returns true if the specified element is visible (i.e. neither display: none\n * nor visibility: hidden).\n *\n * @param {HTMLElement} element DOM element to test.\n *\n * @return {boolean} Whether element is visible.\n */\nfunction isVisible( element ) {\n\treturn (\n\t\telement.offsetWidth > 0 ||\n\t\telement.offsetHeight > 0 ||\n\t\telement.getClientRects().length > 0\n\t);\n}\n\n/**\n * Returns true if the specified element should be skipped from focusable elements.\n * For now it rather specific for `iframes` and if tabindex attribute is set to -1.\n *\n * @param {Element} element DOM element to test.\n *\n * @return {boolean} Whether element should be skipped from focusable elements.\n */\nfunction skipFocus( element ) {\n\treturn (\n\t\telement.nodeName.toLowerCase() === 'iframe' &&\n\t\telement.getAttribute( 'tabindex' ) === '-1'\n\t);\n}\n\n/**\n * Returns true if the specified area element is a valid focusable element, or\n * false otherwise. Area is only focusable if within a map where a named map\n * referenced by an image somewhere in the document.\n *\n * @param {HTMLAreaElement} element DOM area element to test.\n *\n * @return {boolean} Whether area element is valid for focus.\n */\nfunction isValidFocusableArea( element ) {\n\t/** @type {HTMLMapElement | null} */\n\tconst map = element.closest( 'map[name]' );\n\tif ( ! map ) {\n\t\treturn false;\n\t}\n\n\t/** @type {HTMLImageElement | null} */\n\tconst img = element.ownerDocument.querySelector(\n\t\t'img[usemap=\"#' + map.name + '\"]'\n\t);\n\treturn !! img && isVisible( img );\n}\n\n/**\n * Returns all focusable elements within a given context.\n *\n * @param {Element} context Element in which to search.\n *\n * @return {Element[]} Focusable elements.\n */\nexport function find( context ) {\n\t/* eslint-disable jsdoc/no-undefined-types */\n\t/** @type {NodeListOf<HTMLElement>} */\n\t/* eslint-enable jsdoc/no-undefined-types */\n\tconst elements = context.querySelectorAll( SELECTOR );\n\n\treturn Array.from( elements ).filter( ( element ) => {\n\t\tif ( ! isVisible( element ) || skipFocus( element ) ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst { nodeName } = element;\n\t\tif ( 'AREA' === nodeName ) {\n\t\t\treturn isValidFocusableArea(\n\t\t\t\t/** @type {HTMLAreaElement} */ ( element )\n\t\t\t);\n\t\t}\n\n\t\treturn true;\n\t} );\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/dom/src/focusable.js"],"names":["buildSelector","sequential","join","isVisible","element","offsetWidth","offsetHeight","getClientRects","length","isValidFocusableArea","map","closest","img","ownerDocument","querySelector","name","find","context","elements","querySelectorAll","Array","from","filter","nodeName"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,aAAT,CAAwBC,UAAxB,EAAqC;AACpC,SAAO,CACNA,UAAU,GAAG,iCAAH,GAAuC,YAD3C,EAEN,SAFM,EAGN,wBAHM,EAIN,4CAJM,EAKN,wBALM,EAMN,0BANM,EAON,6BAPM,EAQN,QARM,EASN,OATM,EAUN,YAVM,EAWN,gDAXM,EAYLC,IAZK,CAYC,GAZD,CAAP;AAaA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASC,SAAT,CAAoBC,OAApB,EAA8B;AAC7B,SACCA,OAAO,CAACC,WAAR,GAAsB,CAAtB,IACAD,OAAO,CAACE,YAAR,GAAuB,CADvB,IAEAF,OAAO,CAACG,cAAR,GAAyBC,MAAzB,GAAkC,CAHnC;AAKA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASC,oBAAT,CAA+BL,OAA/B,EAAyC;AACxC;AACA,QAAMM,GAAG,GAAGN,OAAO,CAACO,OAAR,CAAiB,WAAjB,CAAZ;;AACA,MAAK,CAAED,GAAP,EAAa;AACZ,WAAO,KAAP;AACA;AAED;;;AACA,QAAME,GAAG,GAAGR,OAAO,CAACS,aAAR,CAAsBC,aAAtB,CACX,kBAAkBJ,GAAG,CAACK,IAAtB,GAA6B,IADlB,CAAZ;AAGA,SAAO,CAAC,CAAEH,GAAH,IAAUT,SAAS,CAAES,GAAF,CAA1B;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASI,IAAT,CAAeC,OAAf,EAAwB;AAAEhB,EAAAA,UAAU,GAAG;AAAf,IAAyB,EAAjD,EAAsD;AAC5D;;AACA;;AACA;AACA,QAAMiB,QAAQ,GAAGD,OAAO,CAACE,gBAAR,CAA0BnB,aAAa,CAAEC,UAAF,CAAvC,CAAjB;AAEA,SAAOmB,KAAK,CAACC,IAAN,CAAYH,QAAZ,EAAuBI,MAAvB,CAAiClB,OAAF,IAAe;AACpD,QAAK,CAAED,SAAS,CAAEC,OAAF,CAAhB,EAA8B;AAC7B,aAAO,KAAP;AACA;;AAED,UAAM;AAAEmB,MAAAA;AAAF,QAAenB,OAArB;;AACA,QAAK,WAAWmB,QAAhB,EAA2B;AAC1B,aAAOd,oBAAoB;AAC1B;AAAiCL,MAAAA,OADP,CAA3B;AAGA;;AAED,WAAO,IAAP;AACA,GAbM,CAAP;AAcA","sourcesContent":["/**\n * References:\n *\n * Focusable:\n * - https://www.w3.org/TR/html5/editing.html#focus-management\n *\n * Sequential focus navigation:\n * - https://www.w3.org/TR/html5/editing.html#sequential-focus-navigation-and-the-tabindex-attribute\n *\n * Disabled elements:\n * - https://www.w3.org/TR/html5/disabled-elements.html#disabled-elements\n *\n * getClientRects algorithm (requiring layout box):\n * - https://www.w3.org/TR/cssom-view-1/#extension-to-the-element-interface\n *\n * AREA elements associated with an IMG:\n * - https://w3c.github.io/html/editing.html#data-model\n */\n\n/**\n * Returns a CSS selector used to query for focusable elements.\n *\n * @param {boolean} sequential If set, only query elements that are sequentially\n * focusable. Non-interactive elements with a\n * negative `tabindex` are focusable but not\n * sequentially focusable.\n * https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute\n *\n * @return {string} CSS selector.\n */\nfunction buildSelector( sequential ) {\n\treturn [\n\t\tsequential ? '[tabindex]:not([tabindex^=\"-\"])' : '[tabindex]',\n\t\t'a[href]',\n\t\t'button:not([disabled])',\n\t\t'input:not([type=\"hidden\"]):not([disabled])',\n\t\t'select:not([disabled])',\n\t\t'textarea:not([disabled])',\n\t\t'iframe:not([tabindex^=\"-\"])',\n\t\t'object',\n\t\t'embed',\n\t\t'area[href]',\n\t\t'[contenteditable]:not([contenteditable=false])',\n\t].join( ',' );\n}\n\n/**\n * Returns true if the specified element is visible (i.e. neither display: none\n * nor visibility: hidden).\n *\n * @param {HTMLElement} element DOM element to test.\n *\n * @return {boolean} Whether element is visible.\n */\nfunction isVisible( element ) {\n\treturn (\n\t\telement.offsetWidth > 0 ||\n\t\telement.offsetHeight > 0 ||\n\t\telement.getClientRects().length > 0\n\t);\n}\n\n/**\n * Returns true if the specified area element is a valid focusable element, or\n * false otherwise. Area is only focusable if within a map where a named map\n * referenced by an image somewhere in the document.\n *\n * @param {HTMLAreaElement} element DOM area element to test.\n *\n * @return {boolean} Whether area element is valid for focus.\n */\nfunction isValidFocusableArea( element ) {\n\t/** @type {HTMLMapElement | null} */\n\tconst map = element.closest( 'map[name]' );\n\tif ( ! map ) {\n\t\treturn false;\n\t}\n\n\t/** @type {HTMLImageElement | null} */\n\tconst img = element.ownerDocument.querySelector(\n\t\t'img[usemap=\"#' + map.name + '\"]'\n\t);\n\treturn !! img && isVisible( img );\n}\n\n/**\n * Returns all focusable elements within a given context.\n *\n * @param {Element} context Element in which to search.\n * @param {Object} [options]\n * @param {boolean} [options.sequential] If set, only return elements that are\n * sequentially focusable.\n * Non-interactive elements with a\n * negative `tabindex` are focusable but\n * not sequentially focusable.\n * https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute\n *\n * @return {Element[]} Focusable elements.\n */\nexport function find( context, { sequential = false } = {} ) {\n\t/* eslint-disable jsdoc/no-undefined-types */\n\t/** @type {NodeListOf<HTMLElement>} */\n\t/* eslint-enable jsdoc/no-undefined-types */\n\tconst elements = context.querySelectorAll( buildSelector( sequential ) );\n\n\treturn Array.from( elements ).filter( ( element ) => {\n\t\tif ( ! isVisible( element ) ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst { nodeName } = element;\n\t\tif ( 'AREA' === nodeName ) {\n\t\t\treturn isValidFocusableArea(\n\t\t\t\t/** @type {HTMLAreaElement} */ ( element )\n\t\t\t);\n\t\t}\n\n\t\treturn true;\n\t} );\n}\n"]}
@@ -43,7 +43,7 @@ const textContentSchema = {
43
43
  del: {},
44
44
  ins: {},
45
45
  a: {
46
- attributes: ['href', 'target', 'rel']
46
+ attributes: ['href', 'target', 'rel', 'id']
47
47
  },
48
48
  code: {},
49
49
  abbr: {
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/dom/src/phrasing-content.js"],"names":["textContentSchema","strong","em","s","del","ins","a","attributes","code","abbr","sub","sup","br","small","q","dfn","data","time","var","samp","kbd","i","b","u","mark","ruby","rt","rp","bdi","bdo","wbr","Object","keys","forEach","tag","children","embeddedContentSchema","audio","canvas","embed","img","object","video","phrasingContentSchema","getPhrasingContentSchema","context","isPhrasingContent","node","nodeName","toLowerCase","hasOwnProperty","isTextContent"],"mappings":";;;;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,iBAAiB,GAAG;AACzBC,EAAAA,MAAM,EAAE,EADiB;AAEzBC,EAAAA,EAAE,EAAE,EAFqB;AAGzBC,EAAAA,CAAC,EAAE,EAHsB;AAIzBC,EAAAA,GAAG,EAAE,EAJoB;AAKzBC,EAAAA,GAAG,EAAE,EALoB;AAMzBC,EAAAA,CAAC,EAAE;AAAEC,IAAAA,UAAU,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,iBAD0B;AAE7B,KAAGoC;AAF0B,CAA9B;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACO,SAASQ,wBAAT,CAAmCC,OAAnC,EAA6C;AACnD,MAAKA,OAAO,KAAK,OAAjB,EAA2B;AAC1B,WAAOF,qBAAP;AACA;;AAED,SAAO,kBACN,EACC,GAAGA,qBADJ;AAEC;AACA;AACAtC,IAAAA,GAAG,EAAE;AAAE8B,MAAAA,QAAQ,EAAEQ,qBAAqB,CAACtC,GAAtB,CAA0B8B;AAAtC,KAJN;AAKC/B,IAAAA,GAAG,EAAE;AAAE+B,MAAAA,QAAQ,EAAEQ,qBAAqB,CAACvC,GAAtB,CAA0B+B;AAAtC;AALN,GADM,EAQN,CACC,GADD,EACM;AACL,QAFD,EAES;AACR,QAHD,EAGS;AACR,QAJD,EAIS;AACR,OALD,EAKQ;AACP,OAND,EAMQ;AACP,OAPD,CAOQ;AAPR,GARM,CAAP;AAkBA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASW,iBAAT,CAA4BC,IAA5B,EAAmC;AACzC,QAAMb,GAAG,GAAGa,IAAI,CAACC,QAAL,CAAcC,WAAd,EAAZ;AACA,SAAOL,wBAAwB,GAAGM,cAA3B,CAA2ChB,GAA3C,KAAoDA,GAAG,KAAK,MAAnE;AACA;AAED;AACA;AACA;AACA;;;AACO,SAASiB,aAAT,CAAwBJ,IAAxB,EAA+B;AACrC,QAAMb,GAAG,GAAGa,IAAI,CAACC,QAAL,CAAcC,WAAd,EAAZ;AACA,SAAOjD,iBAAiB,CAACkD,cAAlB,CAAkChB,GAAlC,KAA2CA,GAAG,KAAK,MAA1D;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { omit, without } from 'lodash';\n\n/**\n * All phrasing content elements.\n *\n * @see https://www.w3.org/TR/2011/WD-html5-20110525/content-models.html#phrasing-content-0\n */\n\n/**\n * @typedef {Record<string,SemanticElementDefinition>} ContentSchema\n */\n\n/**\n * @typedef SemanticElementDefinition\n * @property {string[]} [attributes] Content attributes\n * @property {ContentSchema} [children] Content attributes\n */\n\n/**\n * All text-level semantic elements.\n *\n * @see https://html.spec.whatwg.org/multipage/text-level-semantics.html\n *\n * @type {ContentSchema}\n */\nconst textContentSchema = {\n\tstrong: {},\n\tem: {},\n\ts: {},\n\tdel: {},\n\tins: {},\n\ta: { attributes: [ 'href', 'target', 'rel' ] },\n\tcode: {},\n\tabbr: { attributes: [ 'title' ] },\n\tsub: {},\n\tsup: {},\n\tbr: {},\n\tsmall: {},\n\t// To do: fix blockquote.\n\t// cite: {},\n\tq: { attributes: [ 'cite' ] },\n\tdfn: { attributes: [ 'title' ] },\n\tdata: { attributes: [ 'value' ] },\n\ttime: { attributes: [ 'datetime' ] },\n\tvar: {},\n\tsamp: {},\n\tkbd: {},\n\ti: {},\n\tb: {},\n\tu: {},\n\tmark: {},\n\truby: {},\n\trt: {},\n\trp: {},\n\tbdi: { attributes: [ 'dir' ] },\n\tbdo: { attributes: [ 'dir' ] },\n\twbr: {},\n\t'#text': {},\n};\n\n// Recursion is needed.\n// Possible: strong > em > strong.\n// Impossible: strong > strong.\nwithout( Object.keys( textContentSchema ), '#text', 'br' ).forEach( ( tag ) => {\n\ttextContentSchema[ tag ].children = omit( textContentSchema, tag );\n} );\n\n/**\n * Embedded content elements.\n *\n * @see https://www.w3.org/TR/2011/WD-html5-20110525/content-models.html#embedded-content-0\n *\n * @type {ContentSchema}\n */\nconst embeddedContentSchema = {\n\taudio: {\n\t\tattributes: [\n\t\t\t'src',\n\t\t\t'preload',\n\t\t\t'autoplay',\n\t\t\t'mediagroup',\n\t\t\t'loop',\n\t\t\t'muted',\n\t\t],\n\t},\n\tcanvas: { attributes: [ 'width', 'height' ] },\n\tembed: { attributes: [ 'src', 'type', 'width', 'height' ] },\n\timg: {\n\t\tattributes: [\n\t\t\t'alt',\n\t\t\t'src',\n\t\t\t'srcset',\n\t\t\t'usemap',\n\t\t\t'ismap',\n\t\t\t'width',\n\t\t\t'height',\n\t\t],\n\t},\n\tobject: {\n\t\tattributes: [\n\t\t\t'data',\n\t\t\t'type',\n\t\t\t'name',\n\t\t\t'usemap',\n\t\t\t'form',\n\t\t\t'width',\n\t\t\t'height',\n\t\t],\n\t},\n\tvideo: {\n\t\tattributes: [\n\t\t\t'src',\n\t\t\t'poster',\n\t\t\t'preload',\n\t\t\t'autoplay',\n\t\t\t'mediagroup',\n\t\t\t'loop',\n\t\t\t'muted',\n\t\t\t'controls',\n\t\t\t'width',\n\t\t\t'height',\n\t\t],\n\t},\n};\n\n/**\n * Phrasing content elements.\n *\n * @see https://www.w3.org/TR/2011/WD-html5-20110525/content-models.html#phrasing-content-0\n */\nconst phrasingContentSchema = {\n\t...textContentSchema,\n\t...embeddedContentSchema,\n};\n\n/**\n * Get schema of possible paths for phrasing content.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories#Phrasing_content\n *\n * @param {string} [context] Set to \"paste\" to exclude invisible elements and\n * sensitive data.\n *\n * @return {Partial<ContentSchema>} Schema.\n */\nexport function getPhrasingContentSchema( context ) {\n\tif ( context !== 'paste' ) {\n\t\treturn phrasingContentSchema;\n\t}\n\n\treturn omit(\n\t\t{\n\t\t\t...phrasingContentSchema,\n\t\t\t// We shouldn't paste potentially sensitive information which is not\n\t\t\t// visible to the user when pasted, so strip the attributes.\n\t\t\tins: { children: phrasingContentSchema.ins.children },\n\t\t\tdel: { children: phrasingContentSchema.del.children },\n\t\t},\n\t\t[\n\t\t\t'u', // Used to mark misspelling. Shouldn't be pasted.\n\t\t\t'abbr', // Invisible.\n\t\t\t'data', // Invisible.\n\t\t\t'time', // Invisible.\n\t\t\t'wbr', // Invisible.\n\t\t\t'bdi', // Invisible.\n\t\t\t'bdo', // Invisible.\n\t\t]\n\t);\n}\n\n/**\n * Find out whether or not the given node is phrasing content.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories#Phrasing_content\n *\n * @param {Node} node The node to test.\n *\n * @return {boolean} True if phrasing content, false if not.\n */\nexport function isPhrasingContent( node ) {\n\tconst tag = node.nodeName.toLowerCase();\n\treturn getPhrasingContentSchema().hasOwnProperty( tag ) || tag === 'span';\n}\n\n/**\n * @param {Node} node\n * @return {boolean} Node is text content\n */\nexport function isTextContent( node ) {\n\tconst tag = node.nodeName.toLowerCase();\n\treturn textContentSchema.hasOwnProperty( tag ) || tag === 'span';\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/dom/src/phrasing-content.js"],"names":["textContentSchema","strong","em","s","del","ins","a","attributes","code","abbr","sub","sup","br","small","q","dfn","data","time","var","samp","kbd","i","b","u","mark","ruby","rt","rp","bdi","bdo","wbr","Object","keys","forEach","tag","children","embeddedContentSchema","audio","canvas","embed","img","object","video","phrasingContentSchema","getPhrasingContentSchema","context","isPhrasingContent","node","nodeName","toLowerCase","hasOwnProperty","isTextContent"],"mappings":";;;;;;;;;AAGA;;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,iBAAiB,GAAG;AACzBC,EAAAA,MAAM,EAAE,EADiB;AAEzBC,EAAAA,EAAE,EAAE,EAFqB;AAGzBC,EAAAA,CAAC,EAAE,EAHsB;AAIzBC,EAAAA,GAAG,EAAE,EAJoB;AAKzBC,EAAAA,GAAG,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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AAG,EAAE;AAAE8B,MAAAA,QAAQ,EAAEQ,qBAAqB,CAACtC,GAAtB,CAA0B8B;AAAtC,KAJN;AAKC/B,IAAAA,GAAG,EAAE;AAAE+B,MAAAA,QAAQ,EAAEQ,qBAAqB,CAACvC,GAAtB,CAA0B+B;AAAtC;AALN,GADM,EAQN,CACC,GADD,EACM;AACL,QAFD,EAES;AACR,QAHD,EAGS;AACR,QAJD,EAIS;AACR,OALD,EAKQ;AACP,OAND,EAMQ;AACP,OAPD,CAOQ;AAPR,GARM,CAAP;AAkBA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASW,iBAAT,CAA4BC,IAA5B,EAAmC;AACzC,QAAMb,GAAG,GAAGa,IAAI,CAACC,QAAL,CAAcC,WAAd,EAAZ;AACA,SAAOL,wBAAwB,GAAGM,cAA3B,CAA2ChB,GAA3C,KAAoDA,GAAG,KAAK,MAAnE;AACA;AAED;AACA;AACA;AACA;;;AACO,SAASiB,aAAT,CAAwBJ,IAAxB,EAA+B;AACrC,QAAMb,GAAG,GAAGa,IAAI,CAACC,QAAL,CAAcC,WAAd,EAAZ;AACA,SAAOjD,iBAAiB,CAACkD,cAAlB,CAAkChB,GAAlC,KAA2CA,GAAG,KAAK,MAA1D;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { omit, without } from 'lodash';\n\n/**\n * All phrasing content elements.\n *\n * @see https://www.w3.org/TR/2011/WD-html5-20110525/content-models.html#phrasing-content-0\n */\n\n/**\n * @typedef {Record<string,SemanticElementDefinition>} ContentSchema\n */\n\n/**\n * @typedef SemanticElementDefinition\n * @property {string[]} [attributes] Content attributes\n * @property {ContentSchema} [children] Content attributes\n */\n\n/**\n * All text-level semantic elements.\n *\n * @see https://html.spec.whatwg.org/multipage/text-level-semantics.html\n *\n * @type {ContentSchema}\n */\nconst textContentSchema = {\n\tstrong: {},\n\tem: {},\n\ts: {},\n\tdel: {},\n\tins: {},\n\ta: { attributes: [ 'href', 'target', 'rel', 'id' ] },\n\tcode: {},\n\tabbr: { attributes: [ 'title' ] },\n\tsub: {},\n\tsup: {},\n\tbr: {},\n\tsmall: {},\n\t// To do: fix blockquote.\n\t// cite: {},\n\tq: { attributes: [ 'cite' ] },\n\tdfn: { attributes: [ 'title' ] },\n\tdata: { attributes: [ 'value' ] },\n\ttime: { attributes: [ 'datetime' ] },\n\tvar: {},\n\tsamp: {},\n\tkbd: {},\n\ti: {},\n\tb: {},\n\tu: {},\n\tmark: {},\n\truby: {},\n\trt: {},\n\trp: {},\n\tbdi: { attributes: [ 'dir' ] },\n\tbdo: { attributes: [ 'dir' ] },\n\twbr: {},\n\t'#text': {},\n};\n\n// Recursion is needed.\n// Possible: strong > em > strong.\n// Impossible: strong > strong.\nwithout( Object.keys( textContentSchema ), '#text', 'br' ).forEach( ( tag ) => {\n\ttextContentSchema[ tag ].children = omit( textContentSchema, tag );\n} );\n\n/**\n * Embedded content elements.\n *\n * @see https://www.w3.org/TR/2011/WD-html5-20110525/content-models.html#embedded-content-0\n *\n * @type {ContentSchema}\n */\nconst embeddedContentSchema = {\n\taudio: {\n\t\tattributes: [\n\t\t\t'src',\n\t\t\t'preload',\n\t\t\t'autoplay',\n\t\t\t'mediagroup',\n\t\t\t'loop',\n\t\t\t'muted',\n\t\t],\n\t},\n\tcanvas: { attributes: [ 'width', 'height' ] },\n\tembed: { attributes: [ 'src', 'type', 'width', 'height' ] },\n\timg: {\n\t\tattributes: [\n\t\t\t'alt',\n\t\t\t'src',\n\t\t\t'srcset',\n\t\t\t'usemap',\n\t\t\t'ismap',\n\t\t\t'width',\n\t\t\t'height',\n\t\t],\n\t},\n\tobject: {\n\t\tattributes: [\n\t\t\t'data',\n\t\t\t'type',\n\t\t\t'name',\n\t\t\t'usemap',\n\t\t\t'form',\n\t\t\t'width',\n\t\t\t'height',\n\t\t],\n\t},\n\tvideo: {\n\t\tattributes: [\n\t\t\t'src',\n\t\t\t'poster',\n\t\t\t'preload',\n\t\t\t'autoplay',\n\t\t\t'mediagroup',\n\t\t\t'loop',\n\t\t\t'muted',\n\t\t\t'controls',\n\t\t\t'width',\n\t\t\t'height',\n\t\t],\n\t},\n};\n\n/**\n * Phrasing content elements.\n *\n * @see https://www.w3.org/TR/2011/WD-html5-20110525/content-models.html#phrasing-content-0\n */\nconst phrasingContentSchema = {\n\t...textContentSchema,\n\t...embeddedContentSchema,\n};\n\n/**\n * Get schema of possible paths for phrasing content.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories#Phrasing_content\n *\n * @param {string} [context] Set to \"paste\" to exclude invisible elements and\n * sensitive data.\n *\n * @return {Partial<ContentSchema>} Schema.\n */\nexport function getPhrasingContentSchema( context ) {\n\tif ( context !== 'paste' ) {\n\t\treturn phrasingContentSchema;\n\t}\n\n\treturn omit(\n\t\t{\n\t\t\t...phrasingContentSchema,\n\t\t\t// We shouldn't paste potentially sensitive information which is not\n\t\t\t// visible to the user when pasted, so strip the attributes.\n\t\t\tins: { children: phrasingContentSchema.ins.children },\n\t\t\tdel: { children: phrasingContentSchema.del.children },\n\t\t},\n\t\t[\n\t\t\t'u', // Used to mark misspelling. Shouldn't be pasted.\n\t\t\t'abbr', // Invisible.\n\t\t\t'data', // Invisible.\n\t\t\t'time', // Invisible.\n\t\t\t'wbr', // Invisible.\n\t\t\t'bdi', // Invisible.\n\t\t\t'bdo', // Invisible.\n\t\t]\n\t);\n}\n\n/**\n * Find out whether or not the given node is phrasing content.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories#Phrasing_content\n *\n * @param {Node} node The node to test.\n *\n * @return {boolean} True if phrasing content, false if not.\n */\nexport function isPhrasingContent( node ) {\n\tconst tag = node.nodeName.toLowerCase();\n\treturn getPhrasingContentSchema().hasOwnProperty( tag ) || tag === 'span';\n}\n\n/**\n * @param {Node} node\n * @return {boolean} Node is text content\n */\nexport function isTextContent( node ) {\n\tconst tag = node.nodeName.toLowerCase();\n\treturn textContentSchema.hasOwnProperty( tag ) || tag === 'span';\n}\n"]}
package/build/tabbable.js CHANGED
@@ -199,9 +199,9 @@ function findPrevious(element) {
199
199
 
200
200
  function findNext(element) {
201
201
  const focusables = (0, _focusable.find)(element.ownerDocument.body);
202
- const index = focusables.indexOf(element); // Remove all focusables before and inside `element`.
202
+ const index = focusables.indexOf(element); // Remove all focusables before and including `element`.
203
203
 
204
- const remaining = focusables.slice(index + 1).filter(node => !element.contains(node));
204
+ const remaining = focusables.slice(index + 1);
205
205
  return (0, _lodash.first)(filterTabbable(remaining));
206
206
  }
207
207
  //# sourceMappingURL=tabbable.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/dom/src/tabbable.js"],"names":["getTabIndex","element","tabIndex","getAttribute","parseInt","isTabbableIndex","createStatefulCollapseRadioGroup","CHOSEN_RADIO_BY_NAME","collapseRadioGroup","result","nodeName","type","checked","name","concat","hasChosen","hasOwnProperty","isChosen","hadChosenElement","mapElementToObjectTabbable","index","mapObjectTabbableToElement","object","compareObjectTabbables","a","b","aTabIndex","bTabIndex","filterTabbable","focusables","filter","map","sort","reduce","find","context","findPrevious","ownerDocument","body","indexOf","length","findNext","remaining","slice","node","contains"],"mappings":";;;;;;;;;;AAGA;;AAKA;;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,WAAT,CAAsBC,OAAtB,EAAgC;AAC/B,QAAMC,QAAQ,GAAGD,OAAO,CAACE,YAAR,CAAsB,UAAtB,CAAjB;AACA,SAAOD,QAAQ,KAAK,IAAb,GAAoB,CAApB,GAAwBE,QAAQ,CAAEF,QAAF,EAAY,EAAZ,CAAvC;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASG,eAAT,CAA0BJ,OAA1B,EAAoC;AAC1C,SAAOD,WAAW,CAAEC,OAAF,CAAX,KAA2B,CAAC,CAAnC;AACA;AAED;;AAEA;AACA;AACA;AACA;AACA;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AACoC,aAAR,CAAsBC,IAArC,CAAnB;AACA,QAAMlB,KAAK,GAAGS,UAAU,CAACU,OAAX,CAAoBtC,OAApB,CAAd,CAFmC,CAInC;;AACA,QAAMyC,SAAS,GAAGb,UAAU,CAC1Bc,KADgB,CACTvB,KAAK,GAAG,CADC,EAEhBU,MAFgB,CAENc,IAAF,IAAY,CAAE3C,OAAO,CAAC4C,QAAR,CAAkBD,IAAlB,CAFN,CAAlB;AAIA,SAAO,mBAAOhB,cAAc,CAAEc,SAAF,CAArB,CAAP;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { without, first, last } from 'lodash';\n\n/**\n * Internal dependencies\n */\nimport { find as findFocusable } from './focusable';\n\n/**\n * Returns the tab index of the given element. In contrast with the tabIndex\n * property, this normalizes the default (0) to avoid browser inconsistencies,\n * operating under the assumption that this function is only ever called with a\n * focusable node.\n *\n * @see https://bugzilla.mozilla.org/show_bug.cgi?id=1190261\n *\n * @param {Element} element Element from which to retrieve.\n *\n * @return {number} Tab index of element (default 0).\n */\nfunction getTabIndex( element ) {\n\tconst tabIndex = element.getAttribute( 'tabindex' );\n\treturn tabIndex === null ? 0 : parseInt( tabIndex, 10 );\n}\n\n/**\n * Returns true if the specified element is tabbable, or false otherwise.\n *\n * @param {Element} element Element to test.\n *\n * @return {boolean} Whether element is tabbable.\n */\nexport function isTabbableIndex( element ) {\n\treturn getTabIndex( element ) !== -1;\n}\n\n/** @typedef {Element & { type?: string, checked?: boolean, name?: string }} MaybeHTMLInputElement */\n\n/**\n * Returns a stateful reducer function which constructs a filtered array of\n * tabbable elements, where at most one radio input is selected for a given\n * name, giving priority to checked input, falling back to the first\n * encountered.\n *\n * @return {(acc: MaybeHTMLInputElement[], el: MaybeHTMLInputElement) => MaybeHTMLInputElement[]} Radio group collapse reducer.\n */\nfunction createStatefulCollapseRadioGroup() {\n\t/** @type {Record<string, MaybeHTMLInputElement>} */\n\tconst CHOSEN_RADIO_BY_NAME = {};\n\n\treturn function collapseRadioGroup(\n\t\t/** @type {MaybeHTMLInputElement[]} */ result,\n\t\t/** @type {MaybeHTMLInputElement} */ element\n\t) {\n\t\tconst { nodeName, type, checked, name } = element;\n\n\t\t// For all non-radio tabbables, construct to array by concatenating.\n\t\tif ( nodeName !== 'INPUT' || type !== 'radio' || ! name ) {\n\t\t\treturn result.concat( element );\n\t\t}\n\n\t\tconst hasChosen = CHOSEN_RADIO_BY_NAME.hasOwnProperty( name );\n\n\t\t// Omit by skipping concatenation if the radio element is not chosen.\n\t\tconst isChosen = checked || ! hasChosen;\n\t\tif ( ! isChosen ) {\n\t\t\treturn result;\n\t\t}\n\n\t\t// At this point, if there had been a chosen element, the current\n\t\t// element is checked and should take priority. Retroactively remove\n\t\t// the element which had previously been considered the chosen one.\n\t\tif ( hasChosen ) {\n\t\t\tconst hadChosenElement = CHOSEN_RADIO_BY_NAME[ name ];\n\t\t\tresult = without( result, hadChosenElement );\n\t\t}\n\n\t\tCHOSEN_RADIO_BY_NAME[ name ] = element;\n\n\t\treturn result.concat( element );\n\t};\n}\n\n/**\n * An array map callback, returning an object with the element value and its\n * array index location as properties. This is used to emulate a proper stable\n * sort where equal tabIndex should be left in order of their occurrence in the\n * document.\n *\n * @param {Element} element Element.\n * @param {number} index Array index of element.\n *\n * @return {{ element: Element, index: number }} Mapped object with element, index.\n */\nfunction mapElementToObjectTabbable( element, index ) {\n\treturn { element, index };\n}\n\n/**\n * An array map callback, returning an element of the given mapped object's\n * element value.\n *\n * @param {{ element: Element }} object Mapped object with element.\n *\n * @return {Element} Mapped object element.\n */\nfunction mapObjectTabbableToElement( object ) {\n\treturn object.element;\n}\n\n/**\n * A sort comparator function used in comparing two objects of mapped elements.\n *\n * @see mapElementToObjectTabbable\n *\n * @param {{ element: Element, index: number }} a First object to compare.\n * @param {{ element: Element, index: number }} b Second object to compare.\n *\n * @return {number} Comparator result.\n */\nfunction compareObjectTabbables( a, b ) {\n\tconst aTabIndex = getTabIndex( a.element );\n\tconst bTabIndex = getTabIndex( b.element );\n\n\tif ( aTabIndex === bTabIndex ) {\n\t\treturn a.index - b.index;\n\t}\n\n\treturn aTabIndex - bTabIndex;\n}\n\n/**\n * Givin focusable elements, filters out tabbable element.\n *\n * @param {Element[]} focusables Focusable elements to filter.\n *\n * @return {Element[]} Tabbable elements.\n */\nfunction filterTabbable( focusables ) {\n\treturn focusables\n\t\t.filter( isTabbableIndex )\n\t\t.map( mapElementToObjectTabbable )\n\t\t.sort( compareObjectTabbables )\n\t\t.map( mapObjectTabbableToElement )\n\t\t.reduce( createStatefulCollapseRadioGroup(), [] );\n}\n\n/**\n * @param {Element} context\n * @return {Element[]} Tabbable elements within the context.\n */\nexport function find( context ) {\n\treturn filterTabbable( findFocusable( context ) );\n}\n\n/**\n * Given a focusable element, find the preceding tabbable element.\n *\n * @param {Element} element The focusable element before which to look. Defaults\n * to the active element.\n */\nexport function findPrevious( element ) {\n\tconst focusables = findFocusable( element.ownerDocument.body );\n\tconst index = focusables.indexOf( element );\n\n\t// Remove all focusables after and including `element`.\n\tfocusables.length = index;\n\n\treturn last( filterTabbable( focusables ) );\n}\n\n/**\n * Given a focusable element, find the next tabbable element.\n *\n * @param {Element} element The focusable element after which to look. Defaults\n * to the active element.\n */\nexport function findNext( element ) {\n\tconst focusables = findFocusable( element.ownerDocument.body );\n\tconst index = focusables.indexOf( element );\n\n\t// Remove all focusables before and inside `element`.\n\tconst remaining = focusables\n\t\t.slice( index + 1 )\n\t\t.filter( ( node ) => ! element.contains( node ) );\n\n\treturn first( filterTabbable( remaining ) );\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/dom/src/tabbable.js"],"names":["getTabIndex","element","tabIndex","getAttribute","parseInt","isTabbableIndex","createStatefulCollapseRadioGroup","CHOSEN_RADIO_BY_NAME","collapseRadioGroup","result","nodeName","type","checked","name","concat","hasChosen","hasOwnProperty","isChosen","hadChosenElement","mapElementToObjectTabbable","index","mapObjectTabbableToElement","object","compareObjectTabbables","a","b","aTabIndex","bTabIndex","filterTabbable","focusables","filter","map","sort","reduce","find","context","findPrevious","ownerDocument","body","indexOf","length","findNext","remaining","slice"],"mappings":";;;;;;;;;;AAGA;;AAKA;;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,WAAT,CAAsBC,OAAtB,EAAgC;AAC/B,QAAMC,QAAQ,GAAGD,OAAO,CAACE,YAAR,CAAsB,UAAtB,CAAjB;AACA,SAAOD,QAAQ,KAAK,IAAb,GAAoB,CAApB,GAAwBE,QAAQ,CAAEF,QAAF,EAAY,EAAZ,CAAvC;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASG,eAAT,CAA0BJ,OAA1B,EAAoC;AAC1C,SAAOD,WAAW,CAAEC,OAAF,CAAX,KAA2B,CAAC,CAAnC;AACA;AAED;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASK,gCAAT,GAA4C;AAC3C;AACA,QAAMC,oBAAoB,GAAG,EAA7B;AAEA,SAAO,SAASC,kBAAT;AACN;AAAuCC,EAAAA,MADjC;AAEN;AAAqCR,EAAAA,OAF/B,EAGL;AACD,UAAM;AAAES,MAAAA,QAAF;AAAYC,MAAAA,IAAZ;AAAkBC,MAAAA,OAAlB;AAA2BC,MAAAA;AAA3B,QAAoCZ,OAA1C,CADC,CAGD;;AACA,QAAKS,QAAQ,KAAK,OAAb,IAAwBC,IAAI,KAAK,OAAjC,IAA4C,CAAEE,IAAnD,EAA0D;AACzD,aAAOJ,MAAM,CAACK,MAAP,CAAeb,OAAf,CAAP;AACA;;AAED,UAAMc,SAAS,GAAGR,oBAAoB,CAACS,cAArB,CAAqCH,IAArC,CAAlB,CARC,CAUD;;AACA,UAAMI,QAAQ,GAAGL,OAAO,IAAI,CAAEG,SAA9B;;AACA,QAAK,CAAEE,QAAP,EAAkB;AACjB,aAAOR,MAAP;AACA,KAdA,CAgBD;AACA;AACA;;;AACA,QAAKM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ACA;AACA;AACA;;;AACO,SAAS4B,IAAT,CAAeC,OAAf,EAAyB;AAC/B,SAAOP,cAAc,CAAE,qBAAeO,OAAf,CAAF,CAArB;AACA;AAED;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASC,YAAT,CAAuBnC,OAAvB,EAAiC;AACvC,QAAM4B,UAAU,GAAG,qBAAe5B,OAAO,CAACoC,aAAR,CAAsBC,IAArC,CAAnB;AACA,QAAMlB,KAAK,GAAGS,UAAU,CAACU,OAAX,CAAoBtC,OAApB,CAAd,CAFuC,CAIvC;;AACA4B,EAAAA,UAAU,CAACW,MAAX,GAAoBpB,KAApB;AAEA,SAAO,kBAAMQ,cAAc,CAAEC,UAAF,CAApB,CAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;;;AACO,SAASY,QAAT,CAAmBxC,OAAnB,EAA6B;AACnC,QAAM4B,UAAU,GAAG,qBAAe5B,OAAO,CAACoC,aAAR,CAAsBC,IAArC,CAAnB;AACA,QAAMlB,KAAK,GAAGS,UAAU,CAACU,OAAX,CAAoBtC,OAApB,CAAd,CAFmC,CAInC;;AACA,QAAMyC,SAAS,GAAGb,UAAU,CAACc,KAAX,CAAkBvB,KAAK,GAAG,CAA1B,CAAlB;AAEA,SAAO,mBAAOQ,cAAc,CAAEc,SAAF,CAArB,CAAP;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { without, first, last } from 'lodash';\n\n/**\n * Internal dependencies\n */\nimport { find as findFocusable } from './focusable';\n\n/**\n * Returns the tab index of the given element. In contrast with the tabIndex\n * property, this normalizes the default (0) to avoid browser inconsistencies,\n * operating under the assumption that this function is only ever called with a\n * focusable node.\n *\n * @see https://bugzilla.mozilla.org/show_bug.cgi?id=1190261\n *\n * @param {Element} element Element from which to retrieve.\n *\n * @return {number} Tab index of element (default 0).\n */\nfunction getTabIndex( element ) {\n\tconst tabIndex = element.getAttribute( 'tabindex' );\n\treturn tabIndex === null ? 0 : parseInt( tabIndex, 10 );\n}\n\n/**\n * Returns true if the specified element is tabbable, or false otherwise.\n *\n * @param {Element} element Element to test.\n *\n * @return {boolean} Whether element is tabbable.\n */\nexport function isTabbableIndex( element ) {\n\treturn getTabIndex( element ) !== -1;\n}\n\n/** @typedef {Element & { type?: string, checked?: boolean, name?: string }} MaybeHTMLInputElement */\n\n/**\n * Returns a stateful reducer function which constructs a filtered array of\n * tabbable elements, where at most one radio input is selected for a given\n * name, giving priority to checked input, falling back to the first\n * encountered.\n *\n * @return {(acc: MaybeHTMLInputElement[], el: MaybeHTMLInputElement) => MaybeHTMLInputElement[]} Radio group collapse reducer.\n */\nfunction createStatefulCollapseRadioGroup() {\n\t/** @type {Record<string, MaybeHTMLInputElement>} */\n\tconst CHOSEN_RADIO_BY_NAME = {};\n\n\treturn function collapseRadioGroup(\n\t\t/** @type {MaybeHTMLInputElement[]} */ result,\n\t\t/** @type {MaybeHTMLInputElement} */ element\n\t) {\n\t\tconst { nodeName, type, checked, name } = element;\n\n\t\t// For all non-radio tabbables, construct to array by concatenating.\n\t\tif ( nodeName !== 'INPUT' || type !== 'radio' || ! name ) {\n\t\t\treturn result.concat( element );\n\t\t}\n\n\t\tconst hasChosen = CHOSEN_RADIO_BY_NAME.hasOwnProperty( name );\n\n\t\t// Omit by skipping concatenation if the radio element is not chosen.\n\t\tconst isChosen = checked || ! hasChosen;\n\t\tif ( ! isChosen ) {\n\t\t\treturn result;\n\t\t}\n\n\t\t// At this point, if there had been a chosen element, the current\n\t\t// element is checked and should take priority. Retroactively remove\n\t\t// the element which had previously been considered the chosen one.\n\t\tif ( hasChosen ) {\n\t\t\tconst hadChosenElement = CHOSEN_RADIO_BY_NAME[ name ];\n\t\t\tresult = without( result, hadChosenElement );\n\t\t}\n\n\t\tCHOSEN_RADIO_BY_NAME[ name ] = element;\n\n\t\treturn result.concat( element );\n\t};\n}\n\n/**\n * An array map callback, returning an object with the element value and its\n * array index location as properties. This is used to emulate a proper stable\n * sort where equal tabIndex should be left in order of their occurrence in the\n * document.\n *\n * @param {Element} element Element.\n * @param {number} index Array index of element.\n *\n * @return {{ element: Element, index: number }} Mapped object with element, index.\n */\nfunction mapElementToObjectTabbable( element, index ) {\n\treturn { element, index };\n}\n\n/**\n * An array map callback, returning an element of the given mapped object's\n * element value.\n *\n * @param {{ element: Element }} object Mapped object with element.\n *\n * @return {Element} Mapped object element.\n */\nfunction mapObjectTabbableToElement( object ) {\n\treturn object.element;\n}\n\n/**\n * A sort comparator function used in comparing two objects of mapped elements.\n *\n * @see mapElementToObjectTabbable\n *\n * @param {{ element: Element, index: number }} a First object to compare.\n * @param {{ element: Element, index: number }} b Second object to compare.\n *\n * @return {number} Comparator result.\n */\nfunction compareObjectTabbables( a, b ) {\n\tconst aTabIndex = getTabIndex( a.element );\n\tconst bTabIndex = getTabIndex( b.element );\n\n\tif ( aTabIndex === bTabIndex ) {\n\t\treturn a.index - b.index;\n\t}\n\n\treturn aTabIndex - bTabIndex;\n}\n\n/**\n * Givin focusable elements, filters out tabbable element.\n *\n * @param {Element[]} focusables Focusable elements to filter.\n *\n * @return {Element[]} Tabbable elements.\n */\nfunction filterTabbable( focusables ) {\n\treturn focusables\n\t\t.filter( isTabbableIndex )\n\t\t.map( mapElementToObjectTabbable )\n\t\t.sort( compareObjectTabbables )\n\t\t.map( mapObjectTabbableToElement )\n\t\t.reduce( createStatefulCollapseRadioGroup(), [] );\n}\n\n/**\n * @param {Element} context\n * @return {Element[]} Tabbable elements within the context.\n */\nexport function find( context ) {\n\treturn filterTabbable( findFocusable( context ) );\n}\n\n/**\n * Given a focusable element, find the preceding tabbable element.\n *\n * @param {Element} element The focusable element before which to look. Defaults\n * to the active element.\n */\nexport function findPrevious( element ) {\n\tconst focusables = findFocusable( element.ownerDocument.body );\n\tconst index = focusables.indexOf( element );\n\n\t// Remove all focusables after and including `element`.\n\tfocusables.length = index;\n\n\treturn last( filterTabbable( focusables ) );\n}\n\n/**\n * Given a focusable element, find the next tabbable element.\n *\n * @param {Element} element The focusable element after which to look. Defaults\n * to the active element.\n */\nexport function findNext( element ) {\n\tconst focusables = findFocusable( element.ownerDocument.body );\n\tconst index = focusables.indexOf( element );\n\n\t// Remove all focusables before and including `element`.\n\tconst remaining = focusables.slice( index + 1 );\n\n\treturn first( filterTabbable( remaining ) );\n}\n"]}
@@ -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
  */
@@ -31,4 +31,8 @@ export default function caretRangeFromPoint(doc, x, y) {
31
31
  range.collapse(true);
32
32
  return range;
33
33
  }
34
+ /**
35
+ * @typedef {{caretPositionFromPoint?: (x: number, y: number)=> CaretPosition | null} & Document } DocumentMaybeWithCaretPositionFromPoint
36
+ * @typedef {{ readonly offset: number; readonly offsetNode: Node; getClientRect(): DOMRect | null; }} CaretPosition
37
+ */
34
38
  //# sourceMappingURL=caret-range-from-point.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/dom/src/dom/caret-range-from-point.js"],"names":["caretRangeFromPoint","doc","x","y","caretPositionFromPoint","point","range","createRange","setStart","offsetNode","offset","collapse"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASA,mBAAT,CAA8BC,GAA9B,EAAmCC,CAAnC,EAAsCC,CAAtC,EAA0C;AACxD,MAAKF,GAAG,CAACD,mBAAT,EAA+B;AAC9B,WAAOC,GAAG,CAACD,mBAAJ,CAAyBE,CAAzB,EAA4BC,CAA5B,CAAP;AACA;;AAED,MAAK,CAAEF,GAAG,CAACG,sBAAX,EAAoC;AACnC,WAAO,IAAP;AACA;;AAED,QAAMC,KAAK,GAAGJ,GAAG,CAACG,sBAAJ,CAA4BF,CAA5B,EAA+BC,CAA/B,CAAd,CATwD,CAWxD;AACA;;AACA,MAAK,CAAEE,KAAP,EAAe;AACd,WAAO,IAAP;AACA;;AAED,QAAMC,KAAK,GAAGL,GAAG,CAACM,WAAJ,EAAd;AAEAD,EAAAA,KAAK,CAACE,QAAN,CAAgBH,KAAK,CAACI,UAAtB,EAAkCJ,KAAK,CAACK,MAAxC;AACAJ,EAAAA,KAAK,CAACK,QAAN,CAAgB,IAAhB;AAEA,SAAOL,KAAP;AACA","sourcesContent":["/**\n * Polyfill.\n * Get a collapsed range for a given point.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Document/caretRangeFromPoint\n *\n * @param {Document} doc The document of the range.\n * @param {number} x Horizontal position within the current viewport.\n * @param {number} y Vertical position within the current viewport.\n *\n * @return {Range | null} The best range for the given point.\n */\nexport default function caretRangeFromPoint( doc, x, y ) {\n\tif ( doc.caretRangeFromPoint ) {\n\t\treturn doc.caretRangeFromPoint( x, y );\n\t}\n\n\tif ( ! doc.caretPositionFromPoint ) {\n\t\treturn null;\n\t}\n\n\tconst point = doc.caretPositionFromPoint( x, y );\n\n\t// If x or y are negative, outside viewport, or there is no text entry node.\n\t// https://developer.mozilla.org/en-US/docs/Web/API/Document/caretRangeFromPoint\n\tif ( ! point ) {\n\t\treturn null;\n\t}\n\n\tconst range = doc.createRange();\n\n\trange.setStart( point.offsetNode, point.offset );\n\trange.collapse( true );\n\n\treturn range;\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/dom/src/dom/caret-range-from-point.js"],"names":["caretRangeFromPoint","doc","x","y","caretPositionFromPoint","point","range","createRange","setStart","offsetNode","offset","collapse"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASA,mBAAT,CAA8BC,GAA9B,EAAmCC,CAAnC,EAAsCC,CAAtC,EAA0C;AACxD,MAAKF,GAAG,CAACD,mBAAT,EAA+B;AAC9B,WAAOC,GAAG,CAACD,mBAAJ,CAAyBE,CAAzB,EAA4BC,CAA5B,CAAP;AACA;;AAED,MAAK,CAAEF,GAAG,CAACG,sBAAX,EAAoC;AACnC,WAAO,IAAP;AACA;;AAED,QAAMC,KAAK,GAAGJ,GAAG,CAACG,sBAAJ,CAA4BF,CAA5B,EAA+BC,CAA/B,CAAd,CATwD,CAWxD;AACA;;AACA,MAAK,CAAEE,KAAP,EAAe;AACd,WAAO,IAAP;AACA;;AAED,QAAMC,KAAK,GAAGL,GAAG,CAACM,WAAJ,EAAd;AAEAD,EAAAA,KAAK,CAACE,QAAN,CAAgBH,KAAK,CAACI,UAAtB,EAAkCJ,KAAK,CAACK,MAAxC;AACAJ,EAAAA,KAAK,CAACK,QAAN,CAAgB,IAAhB;AAEA,SAAOL,KAAP;AACA;AAED;AACA;AACA;AACA","sourcesContent":["/**\n * Polyfill.\n * Get a collapsed range for a given point.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Document/caretRangeFromPoint\n *\n * @param {DocumentMaybeWithCaretPositionFromPoint} doc The document of the range.\n * @param {number} x Horizontal position within the current viewport.\n * @param {number} y Vertical position within the current viewport.\n *\n * @return {Range | null} The best range for the given point.\n */\nexport default function caretRangeFromPoint( doc, x, y ) {\n\tif ( doc.caretRangeFromPoint ) {\n\t\treturn doc.caretRangeFromPoint( x, y );\n\t}\n\n\tif ( ! doc.caretPositionFromPoint ) {\n\t\treturn null;\n\t}\n\n\tconst point = doc.caretPositionFromPoint( x, y );\n\n\t// If x or y are negative, outside viewport, or there is no text entry node.\n\t// https://developer.mozilla.org/en-US/docs/Web/API/Document/caretRangeFromPoint\n\tif ( ! point ) {\n\t\treturn null;\n\t}\n\n\tconst range = doc.createRange();\n\n\trange.setStart( point.offsetNode, point.offset );\n\trange.collapse( true );\n\n\treturn range;\n}\n\n/**\n * @typedef {{caretPositionFromPoint?: (x: number, y: number)=> CaretPosition | null} & Document } DocumentMaybeWithCaretPositionFromPoint\n * @typedef {{ readonly offset: number; readonly offsetNode: Node; getClientRect(): DOMRect | null; }} CaretPosition\n */\n"]}
@@ -4,7 +4,7 @@
4
4
  import { assertIsDefined } from '../utils/assert-is-defined';
5
5
  /**
6
6
  * Check whether the current document has selected text. This applies to ranges
7
- * of text in the document, and not selection inside <input> and <textarea>
7
+ * of text in the document, and not selection inside `<input>` and `<textarea>`
8
8
  * elements.
9
9
  *
10
10
  * See: https://developer.mozilla.org/en-US/docs/Web/API/Window/getSelection#Related_objects.
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/dom/src/dom/document-has-text-selection.js"],"names":["assertIsDefined","documentHasTextSelection","doc","defaultView","selection","getSelection","range","rangeCount","getRangeAt","collapsed"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,eAAT,QAAgC,4BAAhC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAe,SAASC,wBAAT,CAAmCC,GAAnC,EAAyC;AACvDF,EAAAA,eAAe,CAAEE,GAAG,CAACC,WAAN,EAAmB,iBAAnB,CAAf;AACA,QAAMC,SAAS,GAAGF,GAAG,CAACC,WAAJ,CAAgBE,YAAhB,EAAlB;AACAL,EAAAA,eAAe,CAAEI,SAAF,EAAa,WAAb,CAAf;AACA,QAAME,KAAK,GAAGF,SAAS,CAACG,UAAV,GAAuBH,SAAS,CAACI,UAAV,CAAsB,CAAtB,CAAvB,GAAmD,IAAjE;AACA,SAAO,CAAC,CAAEF,KAAH,IAAY,CAAEA,KAAK,CAACG,SAA3B;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport { assertIsDefined } from '../utils/assert-is-defined';\n\n/**\n * Check whether the current document has selected text. This applies to ranges\n * of text in the document, and not selection inside <input> and <textarea>\n * elements.\n *\n * See: https://developer.mozilla.org/en-US/docs/Web/API/Window/getSelection#Related_objects.\n *\n * @param {Document} doc The document to check.\n *\n * @return {boolean} True if there is selection, false if not.\n */\nexport default function documentHasTextSelection( doc ) {\n\tassertIsDefined( doc.defaultView, 'doc.defaultView' );\n\tconst selection = doc.defaultView.getSelection();\n\tassertIsDefined( selection, 'selection' );\n\tconst range = selection.rangeCount ? selection.getRangeAt( 0 ) : null;\n\treturn !! range && ! range.collapsed;\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/dom/src/dom/document-has-text-selection.js"],"names":["assertIsDefined","documentHasTextSelection","doc","defaultView","selection","getSelection","range","rangeCount","getRangeAt","collapsed"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,eAAT,QAAgC,4BAAhC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAe,SAASC,wBAAT,CAAmCC,GAAnC,EAAyC;AACvDF,EAAAA,eAAe,CAAEE,GAAG,CAACC,WAAN,EAAmB,iBAAnB,CAAf;AACA,QAAMC,SAAS,GAAGF,GAAG,CAACC,WAAJ,CAAgBE,YAAhB,EAAlB;AACAL,EAAAA,eAAe,CAAEI,SAAF,EAAa,WAAb,CAAf;AACA,QAAME,KAAK,GAAGF,SAAS,CAACG,UAAV,GAAuBH,SAAS,CAACI,UAAV,CAAsB,CAAtB,CAAvB,GAAmD,IAAjE;AACA,SAAO,CAAC,CAAEF,KAAH,IAAY,CAAEA,KAAK,CAACG,SAA3B;AACA","sourcesContent":["/**\n * Internal dependencies\n */\nimport { assertIsDefined } from '../utils/assert-is-defined';\n\n/**\n * Check whether the current document has selected text. This applies to ranges\n * of text in the document, and not selection inside `<input>` and `<textarea>`\n * elements.\n *\n * See: https://developer.mozilla.org/en-US/docs/Web/API/Window/getSelection#Related_objects.\n *\n * @param {Document} doc The document to check.\n *\n * @return {boolean} True if there is selection, false if not.\n */\nexport default function documentHasTextSelection( doc ) {\n\tassertIsDefined( doc.defaultView, 'doc.defaultView' );\n\tconst selection = doc.defaultView.getSelection();\n\tassertIsDefined( selection, 'selection' );\n\tconst range = selection.rangeCount ? selection.getRangeAt( 0 ) : null;\n\treturn !! range && ! range.collapsed;\n}\n"]}
@@ -5,8 +5,8 @@ import documentHasTextSelection from './document-has-text-selection';
5
5
  import inputFieldHasUncollapsedSelection from './input-field-has-uncollapsed-selection';
6
6
  /**
7
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.
8
+ * ranges of text across elements and any selection inside `<input>` and
9
+ * `<textarea>` elements.
10
10
  *
11
11
  * @param {Document} doc The document to check.
12
12
  *
@@ -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 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"]}
@@ -21,7 +21,7 @@ import isInputOrTextArea from './is-input-or-text-area';
21
21
  */
22
22
 
23
23
  export default function isEdge(container, isReverse, onlyVertical = false) {
24
- if (isInputOrTextArea(container)) {
24
+ if (isInputOrTextArea(container) && typeof container.selectionStart === 'number') {
25
25
  if (container.selectionStart !== container.selectionEnd) {
26
26
  return false;
27
27
  }
@@ -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,EAAuCC,YAAY,GAAG,KAAtD,EAA8D;AAC5E,MAAKJ,iBAAiB,CAAEE,SAAF,CAAtB,EAAsC;AACrC,QAAKA,SAAS,CAACG,cAAV,KAA6BH,SAAS,CAACI,YAA5C,EAA2D;AAC1D,aAAO,KAAP;AACA;;AAED,QAAKH,SAAL,EAAiB;AAChB,aAAOD,SAAS,CAACG,cAAV,KAA6B,CAApC;AACA;;AAED,WAAOH,SAAS,CAACK,KAAV,CAAgBC,MAAhB,KAA2BN,SAAS,CAACG,cAA5C;AACA;;AAED,MAAK;AAAG;AAA6BH,EAAAA,SAAF,CAAcO,iBAAjD,EAAsE;AACrE,WAAO,IAAP;AACA;;AAED,QAAM;AAAEC,IAAAA;AAAF,MAAoBR,SAA1B;AACA,QAAM;AAAES,IAAAA;AAAF,MAAkBD,aAAxB;AAEAX,EAAAA,eAAe,CAAEY,WAAF,EAAe,aAAf,CAAf;AACA,QAAMC,SAAS,GAAGD,WAAW,CAACE,YAAZ,EAAlB;;AAEA,MAAK,CAAED,SAAF,IAAe,CAAEA,SAAS,CAACE,UAAhC,EAA6C;AAC5C,WAAO,KAAP;AACA;;AAED,QAAMC,KAAK,GAA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0C,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,CA7F4E,CAgG5E;;AACA,QAAMG,eAAe,GAAGC,IAAI,CAACC,GAAL,CAAUJ,YAAV,KAA4B,CAApD;AACA,QAAMK,iBAAiB,GAAGF,IAAI,CAACC,GAAL,CAAUH,cAAV,KAA8B,CAAxD;AAEA,SAAOpC,YAAY,GAChBqC,eADgB,GAEhBA,eAAe,IAAIG,iBAFtB;AAGA","sourcesContent":["/**\n * Internal dependencies\n */\nimport isRTL from './is-rtl';\nimport getRangeHeight from './get-range-height';\nimport getRectangleFromRange from './get-rectangle-from-range';\nimport isSelectionForward from './is-selection-forward';\nimport hiddenCaretRangeFromPoint from './hidden-caret-range-from-point';\nimport { assertIsDefined } from '../utils/assert-is-defined';\nimport isInputOrTextArea from './is-input-or-text-area';\n\n/**\n * Check whether the selection is at the edge of the container. Checks for\n * horizontal position by default. Set `onlyVertical` to true to check only\n * vertically.\n *\n * @param {Element} container Focusable element.\n * @param {boolean} isReverse Set to true to check left, false to check right.\n * @param {boolean} [onlyVertical=false] Set to true to check only vertical position.\n *\n * @return {boolean} True if at the edge, false if not.\n */\nexport default function isEdge( container, isReverse, onlyVertical = false ) {\n\tif ( isInputOrTextArea( container ) ) {\n\t\tif ( container.selectionStart !== container.selectionEnd ) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif ( isReverse ) {\n\t\t\treturn container.selectionStart === 0;\n\t\t}\n\n\t\treturn container.value.length === container.selectionStart;\n\t}\n\n\tif ( ! (/** @type {HTMLElement} */ ( container ).isContentEditable) ) {\n\t\treturn true;\n\t}\n\n\tconst { ownerDocument } = container;\n\tconst { defaultView } = ownerDocument;\n\n\tassertIsDefined( defaultView, 'defaultView' );\n\tconst selection = defaultView.getSelection();\n\n\tif ( ! selection || ! selection.rangeCount ) {\n\t\treturn false;\n\t}\n\n\tconst range = selection.getRangeAt( 0 );\n\tconst collapsedRange = range.cloneRange();\n\tconst isForward = isSelectionForward( selection );\n\tconst isCollapsed = selection.isCollapsed;\n\n\t// Collapse in direction of selection.\n\tif ( ! isCollapsed ) {\n\t\tcollapsedRange.collapse( ! isForward );\n\t}\n\n\tconst collapsedRangeRect = getRectangleFromRange( collapsedRange );\n\tconst rangeRect = getRectangleFromRange( range );\n\n\tif ( ! collapsedRangeRect || ! rangeRect ) {\n\t\treturn false;\n\t}\n\n\t// Only consider the multiline selection at the edge if the direction is\n\t// towards the edge. The selection is multiline if it is taller than the\n\t// collapsed selection.\n\tconst rangeHeight = getRangeHeight( range );\n\tif (\n\t\t! isCollapsed &&\n\t\trangeHeight &&\n\t\trangeHeight > collapsedRangeRect.height &&\n\t\tisForward === isReverse\n\t) {\n\t\treturn false;\n\t}\n\n\t// In the case of RTL scripts, the horizontal edge is at the opposite side.\n\tconst isReverseDir = isRTL( container ) ? ! isReverse : isReverse;\n\tconst containerRect = container.getBoundingClientRect();\n\n\t// To check if a selection is at the edge, we insert a test selection at the\n\t// edge of the container and check if the selections have the same vertical\n\t// or horizontal position. If they do, the selection is at the edge.\n\t// This method proves to be better than a DOM-based calculation for the\n\t// horizontal edge, since it ignores empty textnodes and a trailing line\n\t// break element. In other words, we need to check visual positioning, not\n\t// DOM positioning.\n\t// It also proves better than using the computed style for the vertical\n\t// edge, because we cannot know the padding and line height reliably in\n\t// pixels. `getComputedStyle` may return a value with different units.\n\tconst x = isReverseDir ? containerRect.left + 1 : containerRect.right - 1;\n\tconst y = isReverse ? containerRect.top + 1 : containerRect.bottom - 1;\n\tconst testRange = hiddenCaretRangeFromPoint(\n\t\townerDocument,\n\t\tx,\n\t\ty,\n\t\t/** @type {HTMLElement} */ ( container )\n\t);\n\n\tif ( ! testRange ) {\n\t\treturn false;\n\t}\n\n\tconst testRect = getRectangleFromRange( testRange );\n\n\tif ( ! testRect ) {\n\t\treturn false;\n\t}\n\n\tconst verticalSide = isReverse ? 'top' : 'bottom';\n\tconst horizontalSide = isReverseDir ? 'left' : 'right';\n\tconst verticalDiff = testRect[ verticalSide ] - rangeRect[ verticalSide ];\n\tconst horizontalDiff =\n\t\ttestRect[ horizontalSide ] - collapsedRangeRect[ horizontalSide ];\n\n\t// Allow the position to be 1px off.\n\tconst hasVerticalDiff = Math.abs( verticalDiff ) <= 1;\n\tconst hasHorizontalDiff = Math.abs( horizontalDiff ) <= 1;\n\n\treturn onlyVertical\n\t\t? hasVerticalDiff\n\t\t: hasVerticalDiff && hasHorizontalDiff;\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/dom/src/dom/is-edge.js"],"names":["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,MAA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tC;;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"]}
@@ -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;AACA;AACA;AACA,OAAOA,yBAAP,MAAsC,iCAAtC;AACA,SAASC,eAAT,QAAgC,4BAAhC;AACA,OAAOC,iBAAP,MAA8B,yBAA9B;AACA,OAAOC,KAAP,MAAkB,UAAlB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,QAAT,CAAmBC,SAAnB,EAA8BC,SAA9B,EAAyCC,CAAzC,EAA6C;AAC5C,QAAM;AAAEC,IAAAA;AAAF,MAAoBH,SAA1B,CAD4C,CAE5C;;AACA,QAAMI,YAAY,GAAGN,KAAK,CAAEE,SAAF,CAAL,GAAqB,CAAEC,SAAvB,GAAmCA,SAAxD;AACA,QAAMI,aAAa,GAAGL,SAAS,CAACM,qBAAV,EAAtB,CAJ4C,CAK5C;AACA;;AACA,MAAKJ,CAAC,KAAKK,SAAX,EAAuB;AACtBL,IAAAA,CAAC,GAAGD,SAAS,GAAGI,aAAa,CAACG,KAAd,GAAsB,CAAzB,GAA6BH,aAAa,CAACI,IAAd,GAAqB,CAA/D;AACA;;AACD,QAAMC,CAAC,GAAGN,YAAY,GAAGC,aAAa,CAACM,MAAd,GAAuB,CAA1B,GAA8BN,aAAa,CAACO,GAAd,GAAoB,CAAxE;AACA,SAAOjB,yBAAyB,CAAEQ,aAAF,EAAiBD,CAAjB,EAAoBQ,CAApB,EAAuBV,SAAvB,CAAhC;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,eAAe,SAASa,gBAAT,CAA2Bb,SAA3B,EAAsCC,SAAtC,EAAiDC,CAAjD,EAAqD;AACnE,MAAK,CAAEF,SAAP,EAAmB;AAClB;AACA;;AAEDA,EAAAA,SAAS,CAACc,KAAV;;AAEA,MAAKjB,iBAAiB,CA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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":"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AV,GAAyBjB,SAAS,CAACe,KAAV,CAAgBC,MAAzC;AACA,KAHD,MAGO;AACNhB,MAAAA,SAAS,CAACc,cAAV,GAA2B,CAA3B;AACAd,MAAAA,SAAS,CAACiB,YAAV,GAAyB,CAAzB;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,MAAuC,kCAAvC;AACA,OAAOC,yBAAP,MAAsC,iCAAtC;AACA,SAASC,eAAT,QAAgC,4BAAhC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAe,SAASC,wBAAT,CACdC,SADc,EAEdC,SAFc,EAGdC,IAHc,EAIdC,YAAY,GAAG,IAJD,EAKb;AACD,MAAK,CAAEH,SAAP,EAAmB;AAClB;AACA;;AAED,MAAK,CAAEE,IAAF,IAAU,CAAEF,SAAS,CAACI,iBAA3B,EAA+C;AAC9CR,IAAAA,0BAA0B,CAAEI,SAAF,EAAaC,SAAb,CAA1B;AACA;AACA;;AAEDD,EAAAA,SAAS,CAACK,KAAV,GAVC,CAYD;AACA;AACA;AACA;AACA;AACA;;AACA,QAAMC,MAAM,GAAGJ,IAAI,CAACK,MAAL,GAAc,CAA7B;AACA,QAAMC,YAAY,GAAGR,SAAS,CAACS,qBAAV,EAArB;AACA,QAAMC,CAAC,GAAGR,IAAI,CAACS,IAAf;AACA,QAAMC,CAAC,GAAGX,SAAS,GAChBO,YAAY,CAACK,MAAb,GAAsBP,MADN,GAEhBE,YAAY,CAACM,GAAb,GAAmBR,MAFtB;AAIA,QAAM;AAAES,IAAAA;AAAF,MAAoBf,SAA1B;AACA,QAAM;AAAEgB,IAAAA;AAAF,MAAkBD,aAAxB;AACA,QAAME,KAAK,GAAGpB,yBAAyB,CAAEkB,aAAF,EAAiBL,CAAjB,EAAoBE,CAApB,EAAuBZ,SAAvB,CAAvC;;AAEA,MAAK,CAAEiB,KAAF,IAAW,CAAEjB,SAAS,CAACkB,QAAV,CAAoBD,KAAK,CAACE,cAA1B,CAAlB,EAA+D;AAC9D,QACChB,YAAY,KACV,CAAEc,KAAF,IACD,CAAEA,KAAK,CAACE,cADP,IAED,CAAEF,KAAK,CAACE,cAAN,CAAqBD,QAArB,CAA+BlB,SAA/B,CAHS,CADb,EAKE;AACD;AACA;AACAA,MAAAA,SAAS,CAACoB,cAAV,CAA0BnB,SAA1B;AACAF,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"]}