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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/README.md +0 -1
  2. package/build/dom/caret-range-from-point.js +7 -3
  3. package/build/dom/caret-range-from-point.js.map +1 -1
  4. package/build/dom/is-edge.js +1 -1
  5. package/build/dom/is-edge.js.map +1 -1
  6. package/build/dom/place-caret-at-edge.js +108 -0
  7. package/build/dom/place-caret-at-edge.js.map +1 -0
  8. package/build/dom/place-caret-at-horizontal-edge.js +2 -84
  9. package/build/dom/place-caret-at-horizontal-edge.js.map +1 -1
  10. package/build/dom/place-caret-at-vertical-edge.js +6 -56
  11. package/build/dom/place-caret-at-vertical-edge.js.map +1 -1
  12. package/build/focusable.js +29 -18
  13. package/build/focusable.js.map +1 -1
  14. package/build/phrasing-content.js +1 -1
  15. package/build/phrasing-content.js.map +1 -1
  16. package/build/tabbable.js +2 -2
  17. package/build/tabbable.js.map +1 -1
  18. package/build-module/dom/caret-range-from-point.js +7 -3
  19. package/build-module/dom/caret-range-from-point.js.map +1 -1
  20. package/build-module/dom/is-edge.js +1 -1
  21. package/build-module/dom/is-edge.js.map +1 -1
  22. package/build-module/dom/place-caret-at-edge.js +95 -0
  23. package/build-module/dom/place-caret-at-edge.js.map +1 -0
  24. package/build-module/dom/place-caret-at-horizontal-edge.js +2 -81
  25. package/build-module/dom/place-caret-at-horizontal-edge.js.map +1 -1
  26. package/build-module/dom/place-caret-at-vertical-edge.js +6 -54
  27. package/build-module/dom/place-caret-at-vertical-edge.js.map +1 -1
  28. package/build-module/focusable.js +29 -18
  29. package/build-module/focusable.js.map +1 -1
  30. package/build-module/phrasing-content.js +1 -1
  31. package/build-module/phrasing-content.js.map +1 -1
  32. package/build-module/tabbable.js +2 -2
  33. package/build-module/tabbable.js.map +1 -1
  34. package/build-types/dom/caret-range-from-point.d.ts +12 -4
  35. package/build-types/dom/caret-range-from-point.d.ts.map +1 -1
  36. package/build-types/dom/is-edge.d.ts.map +1 -1
  37. package/build-types/dom/place-caret-at-edge.d.ts +9 -0
  38. package/build-types/dom/place-caret-at-edge.d.ts.map +1 -0
  39. package/build-types/dom/place-caret-at-horizontal-edge.d.ts.map +1 -1
  40. package/build-types/dom/place-caret-at-vertical-edge.d.ts +4 -5
  41. package/build-types/dom/place-caret-at-vertical-edge.d.ts.map +1 -1
  42. package/build-types/focusable.d.ts +11 -2
  43. package/build-types/focusable.d.ts.map +1 -1
  44. package/build-types/phrasing-content.d.ts +2 -4
  45. package/build-types/phrasing-content.d.ts.map +1 -1
  46. package/build-types/tabbable.d.ts +3 -3
  47. package/build-types/tabbable.d.ts.map +1 -1
  48. package/package.json +2 -2
  49. package/src/dom/caret-range-from-point.js +8 -3
  50. package/src/dom/is-edge.js +4 -1
  51. package/src/dom/place-caret-at-edge.js +95 -0
  52. package/src/dom/place-caret-at-horizontal-edge.js +2 -83
  53. package/src/dom/place-caret-at-vertical-edge.js +6 -64
  54. package/src/focusable.js +37 -32
  55. package/src/phrasing-content.js +1 -1
  56. package/src/tabbable.js +2 -4
  57. package/src/test/dom.js +8 -0
  58. package/tsconfig.tsbuildinfo +1 -1170
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/dom/src/phrasing-content.js"],"names":["omit","without","textContentSchema","strong","em","s","del","ins","a","attributes","code","abbr","sub","sup","br","small","q","dfn","data","time","var","samp","kbd","i","b","u","mark","ruby","rt","rp","bdi","bdo","wbr","Object","keys","forEach","tag","children","embeddedContentSchema","audio","canvas","embed","img","object","video","phrasingContentSchema","getPhrasingContentSchema","context","isPhrasingContent","node","nodeName","toLowerCase","hasOwnProperty","isTextContent"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,IAAT,EAAeC,OAAf,QAA8B,QAA9B;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;A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CAACC,QAAL,CAAcC,WAAd,EAAZ;AACA,SAAOjD,iBAAiB,CAACkD,cAAlB,CAAkChB,GAAlC,KAA2CA,GAAG,KAAK,MAA1D;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { omit, without } from 'lodash';\n\n/**\n * All phrasing content elements.\n *\n * @see https://www.w3.org/TR/2011/WD-html5-20110525/content-models.html#phrasing-content-0\n */\n\n/**\n * @typedef {Record<string,SemanticElementDefinition>} ContentSchema\n */\n\n/**\n * @typedef SemanticElementDefinition\n * @property {string[]} [attributes] Content attributes\n * @property {ContentSchema} [children] Content attributes\n */\n\n/**\n * All text-level semantic elements.\n *\n * @see https://html.spec.whatwg.org/multipage/text-level-semantics.html\n *\n * @type {ContentSchema}\n */\nconst textContentSchema = {\n\tstrong: {},\n\tem: {},\n\ts: {},\n\tdel: {},\n\tins: {},\n\ta: { attributes: [ 'href', 'target', 'rel' ] },\n\tcode: {},\n\tabbr: { attributes: [ 'title' ] },\n\tsub: {},\n\tsup: {},\n\tbr: {},\n\tsmall: {},\n\t// To do: fix blockquote.\n\t// cite: {},\n\tq: { attributes: [ 'cite' ] },\n\tdfn: { attributes: [ 'title' ] },\n\tdata: { attributes: [ 'value' ] },\n\ttime: { attributes: [ 'datetime' ] },\n\tvar: {},\n\tsamp: {},\n\tkbd: {},\n\ti: {},\n\tb: {},\n\tu: {},\n\tmark: {},\n\truby: {},\n\trt: {},\n\trp: {},\n\tbdi: { attributes: [ 'dir' ] },\n\tbdo: { attributes: [ 'dir' ] },\n\twbr: {},\n\t'#text': {},\n};\n\n// Recursion is needed.\n// Possible: strong > em > strong.\n// Impossible: strong > strong.\nwithout( Object.keys( textContentSchema ), '#text', 'br' ).forEach( ( tag ) => {\n\ttextContentSchema[ tag ].children = omit( textContentSchema, tag );\n} );\n\n/**\n * Embedded content elements.\n *\n * @see https://www.w3.org/TR/2011/WD-html5-20110525/content-models.html#embedded-content-0\n *\n * @type {ContentSchema}\n */\nconst embeddedContentSchema = {\n\taudio: {\n\t\tattributes: [\n\t\t\t'src',\n\t\t\t'preload',\n\t\t\t'autoplay',\n\t\t\t'mediagroup',\n\t\t\t'loop',\n\t\t\t'muted',\n\t\t],\n\t},\n\tcanvas: { attributes: [ 'width', 'height' ] },\n\tembed: { attributes: [ 'src', 'type', 'width', 'height' ] },\n\timg: {\n\t\tattributes: [\n\t\t\t'alt',\n\t\t\t'src',\n\t\t\t'srcset',\n\t\t\t'usemap',\n\t\t\t'ismap',\n\t\t\t'width',\n\t\t\t'height',\n\t\t],\n\t},\n\tobject: {\n\t\tattributes: [\n\t\t\t'data',\n\t\t\t'type',\n\t\t\t'name',\n\t\t\t'usemap',\n\t\t\t'form',\n\t\t\t'width',\n\t\t\t'height',\n\t\t],\n\t},\n\tvideo: {\n\t\tattributes: [\n\t\t\t'src',\n\t\t\t'poster',\n\t\t\t'preload',\n\t\t\t'autoplay',\n\t\t\t'mediagroup',\n\t\t\t'loop',\n\t\t\t'muted',\n\t\t\t'controls',\n\t\t\t'width',\n\t\t\t'height',\n\t\t],\n\t},\n};\n\n/**\n * Phrasing content elements.\n *\n * @see https://www.w3.org/TR/2011/WD-html5-20110525/content-models.html#phrasing-content-0\n */\nconst phrasingContentSchema = {\n\t...textContentSchema,\n\t...embeddedContentSchema,\n};\n\n/**\n * Get schema of possible paths for phrasing content.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories#Phrasing_content\n *\n * @param {string} [context] Set to \"paste\" to exclude invisible elements and\n * sensitive data.\n *\n * @return {Partial<ContentSchema>} Schema.\n */\nexport function getPhrasingContentSchema( context ) {\n\tif ( context !== 'paste' ) {\n\t\treturn phrasingContentSchema;\n\t}\n\n\treturn omit(\n\t\t{\n\t\t\t...phrasingContentSchema,\n\t\t\t// We shouldn't paste potentially sensitive information which is not\n\t\t\t// visible to the user when pasted, so strip the attributes.\n\t\t\tins: { children: phrasingContentSchema.ins.children },\n\t\t\tdel: { children: phrasingContentSchema.del.children },\n\t\t},\n\t\t[\n\t\t\t'u', // Used to mark misspelling. Shouldn't be pasted.\n\t\t\t'abbr', // Invisible.\n\t\t\t'data', // Invisible.\n\t\t\t'time', // Invisible.\n\t\t\t'wbr', // Invisible.\n\t\t\t'bdi', // Invisible.\n\t\t\t'bdo', // Invisible.\n\t\t]\n\t);\n}\n\n/**\n * Find out whether or not the given node is phrasing content.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Content_categories#Phrasing_content\n *\n * @param {Node} node The node to test.\n *\n * @return {boolean} True if phrasing content, false if not.\n */\nexport function isPhrasingContent( node ) {\n\tconst tag = node.nodeName.toLowerCase();\n\treturn getPhrasingContentSchema().hasOwnProperty( tag ) || tag === 'span';\n}\n\n/**\n * @param {Node} node\n * @return {boolean} Node is text content\n */\nexport function isTextContent( node ) {\n\tconst tag = node.nodeName.toLowerCase();\n\treturn textContentSchema.hasOwnProperty( tag ) || tag === 'span';\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/dom/src/phrasing-content.js"],"names":["omit","without","textContentSchema","strong","em","s","del","ins","a","attributes","code","abbr","sub","sup","br","small","q","dfn","data","time","var","samp","kbd","i","b","u","mark","ruby","rt","rp","bdi","bdo","wbr","Object","keys","forEach","tag","children","embeddedContentSchema","audio","canvas","embed","img","object","video","phrasingContentSchema","getPhrasingContentSchema","context","isPhrasingContent","node","nodeName","toLowerCase","hasOwnProperty","isTextContent"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,IAAT,EAAeC,OAAf,QAA8B,QAA9B;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,MAAMC,iBAAiB,GAAG;AACzBC,EAAAA,MAAM,EAAE,EADiB;AAEzBC,EAAAA,EAAE,EAAE,EAFqB;AAGzBC,EAAAA,CAAC,EAAE,EAHsB;AAIzBC,EAAAA,GAAG,EAAE,EAJoB;AAKzBC,EAAAA,GAAG,EAAE,E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ADN;AAnCsB,CAA9B;AAmDA;AACA;AACA;AACA;AACA;;AACA,MAAMoC,qBAAqB,GAAG,EAC7B,GAAG3C,iBAD0B;AAE7B,KAAGoC;AAF0B,CAA9B;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASQ,wBAAT,CAAmCC,OAAnC,EAA6C;AACnD,MAAKA,OAAO,KAAK,OAAjB,EAA2B;AAC1B,WAAOF,qBAAP;AACA;;AAED,SAAO7C,IAAI,CACV,EACC,GAAG6C,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,GADU,EAQV,CACC,GADD,EACM;AACL,QAFD,EAES;AACR,QAHD,EAGS;AACR,QAJD,EAIS;AACR,OALD,EAKQ;AACP,OAND,EAMQ;AACP,OAPD,CAOQ;AAPR,GARU,CAAX;AAkBA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASW,iBAAT,CAA4BC,IAA5B,EAAmC;AACzC,QAAMb,GAAG,GAAGa,IAAI,CAACC,QAAL,CAAcC,WAAd,EAAZ;AACA,SAAOL,wBAAwB,GAAGM,cAA3B,CAA2ChB,GAA3C,KAAoDA,GAAG,KAAK,MAAnE;AACA;AAED;AACA;AACA;AACA;;AACA,OAAO,SAASiB,aAAT,CAAwBJ,IAAxB,EAA+B;AACrC,QAAMb,GAAG,GAAGa,IAAI,CAACC,QAAL,CAAcC,WAAd,EAAZ;AACA,SAAOjD,iBAAiB,CAACkD,cAAlB,CAAkChB,GAAlC,KAA2CA,GAAG,KAAK,MAA1D;AACA","sourcesContent":["/**\n * External dependencies\n */\nimport { omit, without } from 'lodash';\n\n/**\n * All phrasing content elements.\n *\n * @see https://www.w3.org/TR/2011/WD-html5-20110525/content-models.html#phrasing-content-0\n */\n\n/**\n * @typedef {Record<string,SemanticElementDefinition>} ContentSchema\n */\n\n/**\n * @typedef SemanticElementDefinition\n * @property {string[]} [attributes] Content attributes\n * @property {ContentSchema} [children] Content attributes\n */\n\n/**\n * All text-level semantic elements.\n *\n * @see https://html.spec.whatwg.org/multipage/text-level-semantics.html\n *\n * @type {ContentSchema}\n */\nconst textContentSchema = {\n\tstrong: {},\n\tem: {},\n\ts: {},\n\tdel: {},\n\tins: {},\n\ta: { attributes: [ 'href', 'target', 'rel', '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"]}
@@ -184,9 +184,9 @@ export function findPrevious(element) {
184
184
 
185
185
  export function findNext(element) {
186
186
  const focusables = findFocusable(element.ownerDocument.body);
187
- const index = focusables.indexOf(element); // Remove all focusables before and inside `element`.
187
+ const index = focusables.indexOf(element); // Remove all focusables before and including `element`.
188
188
 
189
- const remaining = focusables.slice(index + 1).filter(node => !element.contains(node));
189
+ const remaining = focusables.slice(index + 1);
190
190
  return first(filterTabbable(remaining));
191
191
  }
192
192
  //# sourceMappingURL=tabbable.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/dom/src/tabbable.js"],"names":["without","first","last","find","findFocusable","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","context","findPrevious","ownerDocument","body","indexOf","length","findNext","remaining","slice","node","contains"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,OAAT,EAAkBC,KAAlB,EAAyBC,IAAzB,QAAqC,QAArC;AAEA;AACA;AACA;;AACA,SAASC,IAAI,IAAIC,aAAjB,QAAsC,aAAtC;A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AArB;AACA;AAED;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASC,YAAT,CAAuBlC,OAAvB,EAAiC;AACvC,QAAM4B,UAAU,GAAG9B,aAAa,CAAEE,OAAO,CAACmC,aAAR,CAAsBC,IAAxB,CAAhC;AACA,QAAMjB,KAAK,GAAGS,UAAU,CAACS,OAAX,CAAoBrC,OAApB,CAAd,CAFuC,CAIvC;;AACA4B,EAAAA,UAAU,CAACU,MAAX,GAAoBnB,KAApB;AAEA,SAAOvB,IAAI,CAAE+B,cAAc,CAAEC,UAAF,CAAhB,CAAX;AACA;AAED;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,SAASW,QAAT,CAAmBvC,OAAnB,EAA6B;AACnC,QAAM4B,UAAU,GAAG9B,aAAa,CAAEE,OAAO,CAACmC,aAAR,CAAsBC,IAAxB,CAAhC;AACA,QAAMjB,KAAK,GAAGS,UAAU,CAACS,OAAX,CAAoBrC,OAApB,CAAd,CAFmC,CAInC;;AACA,QAAMwC,SAAS,GAAGZ,UAAU,CAC1Ba,KADgB,CACTtB,KAAK,GAAG,CADC,EAEhBU,MAFgB,CAENa,IAAF,IAAY,CAAE1C,OAAO,CAAC2C,QAAR,CAAkBD,IAAlB,CAFN,CAAlB;AAIA,SAAO/C,KAAK,CAAEgC,cAAc,CAAEa,SAAF,CAAhB,CAAZ;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":["without","first","last","find","findFocusable","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","context","findPrevious","ownerDocument","body","indexOf","length","findNext","remaining","slice"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,OAAT,EAAkBC,KAAlB,EAAyBC,IAAzB,QAAqC,QAArC;AAEA;AACA;AACA;;AACA,SAASC,IAAI,IAAIC,aAAjB,QAAsC,aAAtC;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,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;;;AACA,OAAO,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,QAAM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R,CAAsBC,IAAxB,CAAhC;AACA,QAAMjB,KAAK,GAAGS,UAAU,CAACS,OAAX,CAAoBrC,OAApB,CAAd,CAFmC,CAInC;;AACA,QAAMwC,SAAS,GAAGZ,UAAU,CAACa,KAAX,CAAkBtB,KAAK,GAAG,CAA1B,CAAlB;AAEA,SAAOxB,KAAK,CAAEgC,cAAc,CAAEa,SAAF,CAAhB,CAAZ;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,11 +4,19 @@
4
4
  *
5
5
  * @see https://developer.mozilla.org/en-US/docs/Web/API/Document/caretRangeFromPoint
6
6
  *
7
- * @param {Document} doc The document of the range.
8
- * @param {number} x Horizontal position within the current viewport.
9
- * @param {number} y Vertical position within the current viewport.
7
+ * @param {DocumentMaybeWithCaretPositionFromPoint} doc The document of the range.
8
+ * @param {number} x Horizontal position within the current viewport.
9
+ * @param {number} y Vertical position within the current viewport.
10
10
  *
11
11
  * @return {Range | null} The best range for the given point.
12
12
  */
13
- export default function caretRangeFromPoint(doc: Document, x: number, y: number): Range | null;
13
+ export default function caretRangeFromPoint(doc: DocumentMaybeWithCaretPositionFromPoint, x: number, y: number): Range | null;
14
+ export type DocumentMaybeWithCaretPositionFromPoint = {
15
+ caretPositionFromPoint?: ((x: number, y: number) => CaretPosition | null) | undefined;
16
+ } & Document;
17
+ export type CaretPosition = {
18
+ readonly offset: number;
19
+ readonly offsetNode: Node;
20
+ getClientRect(): DOMRect | null;
21
+ };
14
22
  //# sourceMappingURL=caret-range-from-point.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"caret-range-from-point.d.ts","sourceRoot":"","sources":["../../src/dom/caret-range-from-point.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,iDANW,QAAQ,KACR,MAAM,KACN,MAAM,GAEL,KAAK,GAAG,IAAI,CAyBvB"}
1
+ {"version":3,"file":"caret-range-from-point.d.ts","sourceRoot":"","sources":["../../src/dom/caret-range-from-point.js"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,iDANW,uCAAuC,KACvC,MAAM,KACN,MAAM,GAEL,KAAK,GAAG,IAAI,CAyBvB;;kCAG0C,MAAM,KAAK,MAAM,KAAI,aAAa,GAAG,IAAI;;4BACvE;IAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,UAAU,EAAE,IAAI,CAAC;IAAC,aAAa,IAAI,OAAO,GAAG,IAAI,CAAC;CAAE"}
@@ -1 +1 @@
1
- {"version":3,"file":"is-edge.d.ts","sourceRoot":"","sources":["../../src/dom/is-edge.js"],"names":[],"mappings":"AAWA;;;;;;;;;;GAUG;AACH,0CANW,OAAO,aACP,OAAO,uCAGN,OAAO,CAyGlB"}
1
+ {"version":3,"file":"is-edge.d.ts","sourceRoot":"","sources":["../../src/dom/is-edge.js"],"names":[],"mappings":"AAWA;;;;;;;;;;GAUG;AACH,0CANW,OAAO,aACP,OAAO,uCAGN,OAAO,CA4GlB"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Places the caret at start or end of a given element.
3
+ *
4
+ * @param {HTMLElement} container Focusable element.
5
+ * @param {boolean} isReverse True for end, false for start.
6
+ * @param {number|undefined} x X coordinate to vertically position.
7
+ */
8
+ export default function placeCaretAtEdge(container: HTMLElement, isReverse: boolean, x: number | undefined): void;
9
+ //# sourceMappingURL=place-caret-at-edge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"place-caret-at-edge.d.ts","sourceRoot":"","sources":["../../src/dom/place-caret-at-edge.js"],"names":[],"mappings":"AA+BA;;;;;;GAMG;AACH,oDAJW,WAAW,aACX,OAAO,KACP,MAAM,GAAC,SAAS,QA0D1B"}
@@ -1 +1 @@
1
- {"version":3,"file":"place-caret-at-horizontal-edge.d.ts","sourceRoot":"","sources":["../../src/dom/place-caret-at-horizontal-edge.js"],"names":[],"mappings":"AAgCA;;;;;GAKG;AACH,8DAHW,WAAW,aACX,OAAO,QA0DjB"}
1
+ {"version":3,"file":"place-caret-at-horizontal-edge.d.ts","sourceRoot":"","sources":["../../src/dom/place-caret-at-horizontal-edge.js"],"names":[],"mappings":"AAKA;;;;;GAKG;AACH,8DAHW,WAAW,aACX,OAAO,QAIjB"}
@@ -1,10 +1,9 @@
1
1
  /**
2
2
  * Places the caret at the top or bottom of a given element.
3
3
  *
4
- * @param {HTMLElement} container Focusable element.
5
- * @param {boolean} isReverse True for bottom, false for top.
6
- * @param {DOMRect} [rect] The rectangle to position the caret with.
7
- * @param {boolean} [mayUseScroll=true] True to allow scrolling, false to disallow.
4
+ * @param {HTMLElement} container Focusable element.
5
+ * @param {boolean} isReverse True for bottom, false for top.
6
+ * @param {DOMRect} [rect] The rectangle to position the caret with.
8
7
  */
9
- export default function placeCaretAtVerticalEdge(container: HTMLElement, isReverse: boolean, rect?: DOMRect | undefined, mayUseScroll?: boolean | undefined): void;
8
+ export default function placeCaretAtVerticalEdge(container: HTMLElement, isReverse: boolean, rect?: DOMRect | undefined): void;
10
9
  //# sourceMappingURL=place-caret-at-vertical-edge.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"place-caret-at-vertical-edge.d.ts","sourceRoot":"","sources":["../../src/dom/place-caret-at-vertical-edge.js"],"names":[],"mappings":"AAOA;;;;;;;GAOG;AACH,4DALW,WAAW,aACX,OAAO,wEA6DjB"}
1
+ {"version":3,"file":"place-caret-at-vertical-edge.d.ts","sourceRoot":"","sources":["../../src/dom/place-caret-at-vertical-edge.js"],"names":[],"mappings":"AAKA;;;;;;GAMG;AACH,4DAJW,WAAW,aACX,OAAO,oCAKjB"}
@@ -1,9 +1,18 @@
1
1
  /**
2
2
  * Returns all focusable elements within a given context.
3
3
  *
4
- * @param {Element} context Element in which to search.
4
+ * @param {Element} context Element in which to search.
5
+ * @param {Object} [options]
6
+ * @param {boolean} [options.sequential] If set, only return elements that are
7
+ * sequentially focusable.
8
+ * Non-interactive elements with a
9
+ * negative `tabindex` are focusable but
10
+ * not sequentially focusable.
11
+ * https://html.spec.whatwg.org/multipage/interaction.html#the-tabindex-attribute
5
12
  *
6
13
  * @return {Element[]} Focusable elements.
7
14
  */
8
- export function find(context: Element): Element[];
15
+ export function find(context: Element, { sequential }?: {
16
+ sequential?: boolean | undefined;
17
+ } | undefined): Element[];
9
18
  //# sourceMappingURL=focusable.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"focusable.d.ts","sourceRoot":"","sources":["../src/focusable.js"],"names":[],"mappings":"AAuFA;;;;;;GAMG;AACH,8BAJW,OAAO,GAEN,OAAO,EAAE,CAsBpB"}
1
+ {"version":3,"file":"focusable.d.ts","sourceRoot":"","sources":["../src/focusable.js"],"names":[],"mappings":"AAqFA;;;;;;;;;;;;;GAaG;AACH,8BAXW,OAAO;;gBASN,OAAO,EAAE,CAsBpB"}
@@ -24,9 +24,7 @@ export function isPhrasingContent(node: Node): boolean;
24
24
  * @return {boolean} Node is text content
25
25
  */
26
26
  export function isTextContent(node: Node): boolean;
27
- export type ContentSchema = {
28
- [x: string]: SemanticElementDefinition;
29
- };
27
+ export type ContentSchema = Record<string, SemanticElementDefinition>;
30
28
  export type SemanticElementDefinition = {
31
29
  /**
32
30
  * Content attributes
@@ -35,6 +33,6 @@ export type SemanticElementDefinition = {
35
33
  /**
36
34
  * Content attributes
37
35
  */
38
- children?: Record<string, SemanticElementDefinition> | undefined;
36
+ children?: ContentSchema | undefined;
39
37
  };
40
38
  //# sourceMappingURL=phrasing-content.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"phrasing-content.d.ts","sourceRoot":"","sources":["../src/phrasing-content.js"],"names":[],"mappings":"AA0IA;;;;;;;;;GASG;AACH,wEAFY,QAAQ,aAAa,CAAC,CAyBjC;AAED;;;;;;;;GAQG;AACH,wCAJW,IAAI,GAEH,OAAO,CAKlB;AAED;;;GAGG;AACH,oCAHW,IAAI,GACH,OAAO,CAKlB"}
1
+ {"version":3,"file":"phrasing-content.d.ts","sourceRoot":"","sources":["../src/phrasing-content.js"],"names":[],"mappings":"AA0IA;;;;;;;;;GASG;AACH,wEAFY,QAAQ,aAAa,CAAC,CAyBjC;AAED;;;;;;;;GAQG;AACH,wCAJW,IAAI,GAEH,OAAO,CAKlB;AAED;;;GAGG;AACH,oCAHW,IAAI,GACH,OAAO,CAKlB;4BAtLY,OAAO,MAAM,EAAC,yBAAyB,CAAC"}
@@ -26,8 +26,8 @@ export function findPrevious(element: Element): Element | undefined;
26
26
  */
27
27
  export function findNext(element: Element): Element | undefined;
28
28
  export type MaybeHTMLInputElement = Element & {
29
- type?: string | undefined;
30
- checked?: boolean | undefined;
31
- name?: string | undefined;
29
+ type?: string;
30
+ checked?: boolean;
31
+ name?: string;
32
32
  };
33
33
  //# sourceMappingURL=tabbable.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"tabbable.d.ts","sourceRoot":"","sources":["../src/tabbable.js"],"names":[],"mappings":"AA2BA;;;;;;GAMG;AACH,yCAJW,OAAO,GAEN,OAAO,CAIlB;AAiHD;;;GAGG;AACH,8BAHW,OAAO,GACN,OAAO,EAAE,CAIpB;AAED;;;;;GAKG;AACH,sCAHW,OAAO,uBAWjB;AAED;;;;;GAKG;AACH,kCAHW,OAAO,uBAajB"}
1
+ {"version":3,"file":"tabbable.d.ts","sourceRoot":"","sources":["../src/tabbable.js"],"names":[],"mappings":"AA2BA;;;;;;GAMG;AACH,yCAJW,OAAO,GAEN,OAAO,CAIlB;AAiHD;;;GAGG;AACH,8BAHW,OAAO,GACN,OAAO,EAAE,CAIpB;AAED;;;;;GAKG;AACH,sCAHW,OAAO,uBAWjB;AAED;;;;;GAKG;AACH,kCAHW,OAAO,uBAWjB;oCArJa,OAAO,GAAG;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/dom",
3
- "version": "3.2.2-next.5df0cd52b7.0",
3
+ "version": "3.2.5",
4
4
  "description": "DOM utilities module for WordPress.",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -34,5 +34,5 @@
34
34
  "publishConfig": {
35
35
  "access": "public"
36
36
  },
37
- "gitHead": "558d577d12bec15f05e694eb49a094836d885cca"
37
+ "gitHead": "157f4ae53ab98e574af01f72213ae5a9613159ff"
38
38
  }
@@ -4,9 +4,9 @@
4
4
  *
5
5
  * @see https://developer.mozilla.org/en-US/docs/Web/API/Document/caretRangeFromPoint
6
6
  *
7
- * @param {Document} doc The document of the range.
8
- * @param {number} x Horizontal position within the current viewport.
9
- * @param {number} y Vertical position within the current viewport.
7
+ * @param {DocumentMaybeWithCaretPositionFromPoint} doc The document of the range.
8
+ * @param {number} x Horizontal position within the current viewport.
9
+ * @param {number} y Vertical position within the current viewport.
10
10
  *
11
11
  * @return {Range | null} The best range for the given point.
12
12
  */
@@ -34,3 +34,8 @@ export default function caretRangeFromPoint( doc, x, y ) {
34
34
 
35
35
  return range;
36
36
  }
37
+
38
+ /**
39
+ * @typedef {{caretPositionFromPoint?: (x: number, y: number)=> CaretPosition | null} & Document } DocumentMaybeWithCaretPositionFromPoint
40
+ * @typedef {{ readonly offset: number; readonly offsetNode: Node; getClientRect(): DOMRect | null; }} CaretPosition
41
+ */
@@ -21,7 +21,10 @@ import isInputOrTextArea from './is-input-or-text-area';
21
21
  * @return {boolean} True if at the edge, false if not.
22
22
  */
23
23
  export default function isEdge( container, isReverse, onlyVertical = false ) {
24
- if ( isInputOrTextArea( container ) ) {
24
+ if (
25
+ isInputOrTextArea( container ) &&
26
+ typeof container.selectionStart === 'number'
27
+ ) {
25
28
  if ( container.selectionStart !== container.selectionEnd ) {
26
29
  return false;
27
30
  }
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ import hiddenCaretRangeFromPoint from './hidden-caret-range-from-point';
5
+ import { assertIsDefined } from '../utils/assert-is-defined';
6
+ import isInputOrTextArea from './is-input-or-text-area';
7
+ import isRTL from './is-rtl';
8
+
9
+ /**
10
+ * Gets the range to place.
11
+ *
12
+ * @param {HTMLElement} container Focusable element.
13
+ * @param {boolean} isReverse True for end, false for start.
14
+ * @param {number|undefined} x X coordinate to vertically position.
15
+ *
16
+ * @return {Range|null} The range to place.
17
+ */
18
+ function getRange( container, isReverse, x ) {
19
+ const { ownerDocument } = container;
20
+ // In the case of RTL scripts, the horizontal edge is at the opposite side.
21
+ const isReverseDir = isRTL( container ) ? ! isReverse : isReverse;
22
+ const containerRect = container.getBoundingClientRect();
23
+ // When placing at the end (isReverse), find the closest range to the bottom
24
+ // right corner. When placing at the start, to the top left corner.
25
+ if ( x === undefined ) {
26
+ x = isReverse ? containerRect.right - 1 : containerRect.left + 1;
27
+ }
28
+ const y = isReverseDir ? containerRect.bottom - 1 : containerRect.top + 1;
29
+ return hiddenCaretRangeFromPoint( ownerDocument, x, y, container );
30
+ }
31
+
32
+ /**
33
+ * Places the caret at start or end of a given element.
34
+ *
35
+ * @param {HTMLElement} container Focusable element.
36
+ * @param {boolean} isReverse True for end, false for start.
37
+ * @param {number|undefined} x X coordinate to vertically position.
38
+ */
39
+ export default function placeCaretAtEdge( container, isReverse, x ) {
40
+ if ( ! container ) {
41
+ return;
42
+ }
43
+
44
+ container.focus();
45
+
46
+ if ( isInputOrTextArea( container ) ) {
47
+ // The element may not support selection setting.
48
+ if ( typeof container.selectionStart !== 'number' ) {
49
+ return;
50
+ }
51
+
52
+ if ( isReverse ) {
53
+ container.selectionStart = container.value.length;
54
+ container.selectionEnd = container.value.length;
55
+ } else {
56
+ container.selectionStart = 0;
57
+ container.selectionEnd = 0;
58
+ }
59
+
60
+ return;
61
+ }
62
+
63
+ if ( ! container.isContentEditable ) {
64
+ return;
65
+ }
66
+
67
+ let range = getRange( container, isReverse, x );
68
+
69
+ // If no range range can be created or it is outside the container, the
70
+ // element may be out of view.
71
+ if (
72
+ ! range ||
73
+ ! range.startContainer ||
74
+ ! container.contains( range.startContainer )
75
+ ) {
76
+ container.scrollIntoView( isReverse );
77
+ range = range = getRange( container, isReverse, x );
78
+
79
+ if (
80
+ ! range ||
81
+ ! range.startContainer ||
82
+ ! container.contains( range.startContainer )
83
+ ) {
84
+ return;
85
+ }
86
+ }
87
+
88
+ const { ownerDocument } = container;
89
+ const { defaultView } = ownerDocument;
90
+ assertIsDefined( defaultView, 'defaultView' );
91
+ const selection = defaultView.getSelection();
92
+ assertIsDefined( selection, 'selection' );
93
+ selection.removeAllRanges();
94
+ selection.addRange( range );
95
+ }
@@ -1,34 +1,7 @@
1
1
  /**
2
2
  * Internal dependencies
3
3
  */
4
- import { assertIsDefined } from '../utils/assert-is-defined';
5
-
6
- /**
7
- * Internal dependencies
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
- /**
14
- * Gets the range to place.
15
- *
16
- * @param {HTMLElement} container Focusable element.
17
- * @param {boolean} isReverse True for end, false for start.
18
- *
19
- * @return {Range|null} The range to place.
20
- */
21
- function getRange( container, isReverse ) {
22
- const { ownerDocument } = container;
23
- // In the case of RTL scripts, the horizontal edge is at the opposite side.
24
- const isReverseDir = isRTL( container ) ? ! isReverse : isReverse;
25
- const containerRect = container.getBoundingClientRect();
26
- // When placing at the end (isReverse), find the closest range to the bottom
27
- // right corner. When placing at the start, to the top left corner.
28
- const x = isReverse ? containerRect.right - 1 : containerRect.left + 1;
29
- const y = isReverseDir ? containerRect.bottom - 1 : containerRect.top + 1;
30
- return hiddenCaretRangeFromPoint( ownerDocument, x, y, container );
31
- }
4
+ import placeCaretAtEdge from './place-caret-at-edge';
32
5
 
33
6
  /**
34
7
  * Places the caret at start or end of a given element.
@@ -37,59 +10,5 @@ function getRange( container, isReverse ) {
37
10
  * @param {boolean} isReverse True for end, false for start.
38
11
  */
39
12
  export default function placeCaretAtHorizontalEdge( container, isReverse ) {
40
- if ( ! container ) {
41
- return;
42
- }
43
-
44
- container.focus();
45
-
46
- if ( isInputOrTextArea( container ) ) {
47
- // The element may not support selection setting.
48
- if ( typeof container.selectionStart !== 'number' ) {
49
- return;
50
- }
51
-
52
- if ( isReverse ) {
53
- container.selectionStart = container.value.length;
54
- container.selectionEnd = container.value.length;
55
- } else {
56
- container.selectionStart = 0;
57
- container.selectionEnd = 0;
58
- }
59
-
60
- return;
61
- }
62
-
63
- if ( ! container.isContentEditable ) {
64
- return;
65
- }
66
-
67
- let range = getRange( container, isReverse );
68
-
69
- // If no range range can be created or it is outside the container, the
70
- // element may be out of view.
71
- if (
72
- ! range ||
73
- ! range.startContainer ||
74
- ! container.contains( range.startContainer )
75
- ) {
76
- container.scrollIntoView( isReverse );
77
- range = getRange( container, isReverse );
78
-
79
- if (
80
- ! range ||
81
- ! range.startContainer ||
82
- ! container.contains( range.startContainer )
83
- ) {
84
- return;
85
- }
86
- }
87
-
88
- const { ownerDocument } = container;
89
- const { defaultView } = ownerDocument;
90
- assertIsDefined( defaultView, 'defaultView' );
91
- const selection = defaultView.getSelection();
92
- assertIsDefined( selection, 'selection' );
93
- selection.removeAllRanges();
94
- selection.addRange( range );
13
+ return placeCaretAtEdge( container, isReverse, undefined );
95
14
  }
@@ -1,73 +1,15 @@
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
  /**
9
7
  * Places the caret at the top or bottom of a given element.
10
8
  *
11
- * @param {HTMLElement} container Focusable element.
12
- * @param {boolean} isReverse True for bottom, false for top.
13
- * @param {DOMRect} [rect] The rectangle to position the caret with.
14
- * @param {boolean} [mayUseScroll=true] True to allow scrolling, false to disallow.
9
+ * @param {HTMLElement} container Focusable element.
10
+ * @param {boolean} isReverse True for bottom, false for top.
11
+ * @param {DOMRect} [rect] The rectangle to position the caret with.
15
12
  */
16
- export default function placeCaretAtVerticalEdge(
17
- container,
18
- isReverse,
19
- rect,
20
- mayUseScroll = true
21
- ) {
22
- if ( ! container ) {
23
- return;
24
- }
25
-
26
- if ( ! rect || ! container.isContentEditable ) {
27
- placeCaretAtHorizontalEdge( container, isReverse );
28
- return;
29
- }
30
-
31
- container.focus();
32
-
33
- // Offset by a buffer half the height of the caret rect. This is needed
34
- // because caretRangeFromPoint may default to the end of the selection if
35
- // offset is too close to the edge. It's unclear how to precisely calculate
36
- // this threshold; it may be the padded area of some combination of line
37
- // height, caret height, and font size. The buffer offset is effectively
38
- // equivalent to a point at half the height of a line of text.
39
- const buffer = rect.height / 2;
40
- const editableRect = container.getBoundingClientRect();
41
- const x = rect.left;
42
- const y = isReverse
43
- ? editableRect.bottom - buffer
44
- : editableRect.top + buffer;
45
-
46
- const { ownerDocument } = container;
47
- const { defaultView } = ownerDocument;
48
- const range = hiddenCaretRangeFromPoint( ownerDocument, x, y, container );
49
-
50
- if ( ! range || ! container.contains( range.startContainer ) ) {
51
- if (
52
- mayUseScroll &&
53
- ( ! range ||
54
- ! range.startContainer ||
55
- ! range.startContainer.contains( container ) )
56
- ) {
57
- // Might be out of view.
58
- // Easier than attempting to calculate manually.
59
- container.scrollIntoView( isReverse );
60
- placeCaretAtVerticalEdge( container, isReverse, rect, false );
61
- return;
62
- }
63
-
64
- placeCaretAtHorizontalEdge( container, isReverse );
65
- return;
66
- }
67
-
68
- assertIsDefined( defaultView, 'defaultView' );
69
- const selection = defaultView.getSelection();
70
- assertIsDefined( selection, 'selection' );
71
- selection.removeAllRanges();
72
- selection.addRange( range );
13
+ export default function placeCaretAtVerticalEdge( container, isReverse, rect ) {
14
+ return placeCaretAtEdge( container, isReverse, rect?.left );
73
15
  }