@wordpress/dom 4.56.0 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (327) hide show
  1. package/README.md +22 -22
  2. package/build/data-transfer.cjs +1 -1
  3. package/build/data-transfer.cjs.map +3 -3
  4. package/build/dom/caret-range-from-point.cjs +1 -1
  5. package/build/dom/caret-range-from-point.cjs.map +3 -3
  6. package/build/dom/clean-node-list.cjs +1 -1
  7. package/build/dom/clean-node-list.cjs.map +3 -3
  8. package/build/dom/compute-caret-rect.cjs +1 -1
  9. package/build/dom/compute-caret-rect.cjs.map +3 -3
  10. package/build/dom/document-has-selection.cjs +1 -1
  11. package/build/dom/document-has-selection.cjs.map +3 -3
  12. package/build/dom/document-has-text-selection.cjs +1 -1
  13. package/build/dom/document-has-text-selection.cjs.map +3 -3
  14. package/build/dom/document-has-uncollapsed-selection.cjs +1 -1
  15. package/build/dom/document-has-uncollapsed-selection.cjs.map +3 -3
  16. package/build/dom/get-computed-style.cjs +1 -1
  17. package/build/dom/get-computed-style.cjs.map +3 -3
  18. package/build/dom/get-offset-parent.cjs +7 -15
  19. package/build/dom/get-offset-parent.cjs.map +4 -4
  20. package/build/dom/get-range-height.cjs +1 -1
  21. package/build/dom/get-range-height.cjs.map +3 -3
  22. package/build/dom/get-rectangle-from-range.cjs +3 -8
  23. package/build/dom/get-rectangle-from-range.cjs.map +3 -3
  24. package/build/dom/get-scroll-container.cjs +2 -6
  25. package/build/dom/get-scroll-container.cjs.map +3 -3
  26. package/build/dom/hidden-caret-range-from-point.cjs +1 -1
  27. package/build/dom/hidden-caret-range-from-point.cjs.map +3 -3
  28. package/build/dom/index.cjs +1 -1
  29. package/build/dom/index.cjs.map +1 -1
  30. package/build/dom/input-field-has-uncollapsed-selection.cjs +2 -5
  31. package/build/dom/input-field-has-uncollapsed-selection.cjs.map +3 -3
  32. package/build/dom/insert-after.cjs +1 -1
  33. package/build/dom/insert-after.cjs.map +3 -3
  34. package/build/dom/is-edge.cjs +1 -1
  35. package/build/dom/is-edge.cjs.map +3 -3
  36. package/build/dom/is-element.cjs +1 -1
  37. package/build/dom/is-element.cjs.map +3 -3
  38. package/build/dom/is-empty.cjs +2 -5
  39. package/build/dom/is-empty.cjs.map +3 -3
  40. package/build/dom/is-entirely-selected.cjs +2 -5
  41. package/build/dom/is-entirely-selected.cjs.map +3 -3
  42. package/build/dom/is-form-element.cjs +1 -1
  43. package/build/dom/is-form-element.cjs.map +3 -3
  44. package/build/dom/is-horizontal-edge.cjs +1 -1
  45. package/build/dom/is-horizontal-edge.cjs.map +3 -3
  46. package/build/dom/is-html-input-element.cjs +1 -1
  47. package/build/dom/is-html-input-element.cjs.map +3 -3
  48. package/build/dom/is-input-or-text-area.cjs +1 -1
  49. package/build/dom/is-input-or-text-area.cjs.map +3 -3
  50. package/build/dom/is-number-input.cjs +1 -1
  51. package/build/dom/is-number-input.cjs.map +3 -3
  52. package/build/dom/is-rtl.cjs +1 -1
  53. package/build/dom/is-rtl.cjs.map +3 -3
  54. package/build/dom/is-selection-forward.cjs +1 -1
  55. package/build/dom/is-selection-forward.cjs.map +3 -3
  56. package/build/dom/is-text-field.cjs +2 -3
  57. package/build/dom/is-text-field.cjs.map +3 -3
  58. package/build/dom/is-vertical-edge.cjs +1 -1
  59. package/build/dom/is-vertical-edge.cjs.map +3 -3
  60. package/build/dom/place-caret-at-edge.cjs +1 -1
  61. package/build/dom/place-caret-at-edge.cjs.map +3 -3
  62. package/build/dom/place-caret-at-horizontal-edge.cjs +1 -1
  63. package/build/dom/place-caret-at-horizontal-edge.cjs.map +3 -3
  64. package/build/dom/place-caret-at-vertical-edge.cjs +1 -1
  65. package/build/dom/place-caret-at-vertical-edge.cjs.map +3 -3
  66. package/build/dom/remove-invalid-html.cjs +1 -1
  67. package/build/dom/remove-invalid-html.cjs.map +3 -3
  68. package/build/dom/remove.cjs +1 -1
  69. package/build/dom/remove.cjs.map +3 -3
  70. package/build/dom/replace-tag.cjs +1 -1
  71. package/build/dom/replace-tag.cjs.map +3 -3
  72. package/build/dom/replace.cjs +1 -1
  73. package/build/dom/replace.cjs.map +3 -3
  74. package/build/dom/safe-html.cjs +1 -1
  75. package/build/dom/safe-html.cjs.map +3 -3
  76. package/build/dom/scroll-if-no-range.cjs +1 -1
  77. package/build/dom/scroll-if-no-range.cjs.map +3 -3
  78. package/build/dom/strip-html.cjs +1 -1
  79. package/build/dom/strip-html.cjs.map +3 -3
  80. package/build/dom/types.cjs +19 -0
  81. package/build/dom/types.cjs.map +7 -0
  82. package/build/dom/unwrap.cjs +1 -1
  83. package/build/dom/unwrap.cjs.map +3 -3
  84. package/build/dom/wrap.cjs +1 -1
  85. package/build/dom/wrap.cjs.map +3 -3
  86. package/build/focusable.cjs +5 -6
  87. package/build/focusable.cjs.map +3 -3
  88. package/build/index.cjs +1 -1
  89. package/build/index.cjs.map +2 -2
  90. package/build/phrasing-content.cjs +1 -1
  91. package/build/phrasing-content.cjs.map +3 -3
  92. package/build/tabbable.cjs +1 -1
  93. package/build/tabbable.cjs.map +3 -3
  94. package/build/types.cjs +19 -0
  95. package/build/types.cjs.map +7 -0
  96. package/build-module/data-transfer.mjs +1 -1
  97. package/build-module/data-transfer.mjs.map +3 -3
  98. package/build-module/dom/caret-range-from-point.mjs +1 -1
  99. package/build-module/dom/caret-range-from-point.mjs.map +3 -3
  100. package/build-module/dom/clean-node-list.mjs +1 -1
  101. package/build-module/dom/clean-node-list.mjs.map +3 -3
  102. package/build-module/dom/compute-caret-rect.mjs +1 -1
  103. package/build-module/dom/compute-caret-rect.mjs.map +3 -3
  104. package/build-module/dom/document-has-selection.mjs +1 -1
  105. package/build-module/dom/document-has-selection.mjs.map +3 -3
  106. package/build-module/dom/document-has-text-selection.mjs +1 -1
  107. package/build-module/dom/document-has-text-selection.mjs.map +3 -3
  108. package/build-module/dom/document-has-uncollapsed-selection.mjs +1 -1
  109. package/build-module/dom/document-has-uncollapsed-selection.mjs.map +3 -3
  110. package/build-module/dom/get-computed-style.mjs +1 -1
  111. package/build-module/dom/get-computed-style.mjs.map +3 -3
  112. package/build-module/dom/get-offset-parent.mjs +7 -15
  113. package/build-module/dom/get-offset-parent.mjs.map +3 -3
  114. package/build-module/dom/get-range-height.mjs +1 -1
  115. package/build-module/dom/get-range-height.mjs.map +3 -3
  116. package/build-module/dom/get-rectangle-from-range.mjs +3 -8
  117. package/build-module/dom/get-rectangle-from-range.mjs.map +3 -3
  118. package/build-module/dom/get-scroll-container.mjs +2 -6
  119. package/build-module/dom/get-scroll-container.mjs.map +3 -3
  120. package/build-module/dom/hidden-caret-range-from-point.mjs +1 -1
  121. package/build-module/dom/hidden-caret-range-from-point.mjs.map +3 -3
  122. package/build-module/dom/index.mjs +1 -1
  123. package/build-module/dom/index.mjs.map +1 -1
  124. package/build-module/dom/input-field-has-uncollapsed-selection.mjs +2 -5
  125. package/build-module/dom/input-field-has-uncollapsed-selection.mjs.map +3 -3
  126. package/build-module/dom/insert-after.mjs +1 -1
  127. package/build-module/dom/insert-after.mjs.map +3 -3
  128. package/build-module/dom/is-edge.mjs +1 -1
  129. package/build-module/dom/is-edge.mjs.map +3 -3
  130. package/build-module/dom/is-element.mjs +1 -1
  131. package/build-module/dom/is-element.mjs.map +3 -3
  132. package/build-module/dom/is-empty.mjs +2 -5
  133. package/build-module/dom/is-empty.mjs.map +3 -3
  134. package/build-module/dom/is-entirely-selected.mjs +2 -5
  135. package/build-module/dom/is-entirely-selected.mjs.map +3 -3
  136. package/build-module/dom/is-form-element.mjs +1 -1
  137. package/build-module/dom/is-form-element.mjs.map +3 -3
  138. package/build-module/dom/is-horizontal-edge.mjs +1 -1
  139. package/build-module/dom/is-horizontal-edge.mjs.map +3 -3
  140. package/build-module/dom/is-html-input-element.mjs +1 -1
  141. package/build-module/dom/is-html-input-element.mjs.map +3 -3
  142. package/build-module/dom/is-input-or-text-area.mjs +1 -1
  143. package/build-module/dom/is-input-or-text-area.mjs.map +3 -3
  144. package/build-module/dom/is-number-input.mjs +1 -1
  145. package/build-module/dom/is-number-input.mjs.map +3 -3
  146. package/build-module/dom/is-rtl.mjs +1 -1
  147. package/build-module/dom/is-rtl.mjs.map +3 -3
  148. package/build-module/dom/is-selection-forward.mjs +1 -1
  149. package/build-module/dom/is-selection-forward.mjs.map +3 -3
  150. package/build-module/dom/is-text-field.mjs +2 -3
  151. package/build-module/dom/is-text-field.mjs.map +3 -3
  152. package/build-module/dom/is-vertical-edge.mjs +1 -1
  153. package/build-module/dom/is-vertical-edge.mjs.map +3 -3
  154. package/build-module/dom/place-caret-at-edge.mjs +1 -1
  155. package/build-module/dom/place-caret-at-edge.mjs.map +3 -3
  156. package/build-module/dom/place-caret-at-horizontal-edge.mjs +1 -1
  157. package/build-module/dom/place-caret-at-horizontal-edge.mjs.map +3 -3
  158. package/build-module/dom/place-caret-at-vertical-edge.mjs +1 -1
  159. package/build-module/dom/place-caret-at-vertical-edge.mjs.map +3 -3
  160. package/build-module/dom/remove-invalid-html.mjs +1 -1
  161. package/build-module/dom/remove-invalid-html.mjs.map +3 -3
  162. package/build-module/dom/remove.mjs +1 -1
  163. package/build-module/dom/remove.mjs.map +3 -3
  164. package/build-module/dom/replace-tag.mjs +1 -1
  165. package/build-module/dom/replace-tag.mjs.map +3 -3
  166. package/build-module/dom/replace.mjs +1 -1
  167. package/build-module/dom/replace.mjs.map +3 -3
  168. package/build-module/dom/safe-html.mjs +1 -1
  169. package/build-module/dom/safe-html.mjs.map +3 -3
  170. package/build-module/dom/scroll-if-no-range.mjs +1 -1
  171. package/build-module/dom/scroll-if-no-range.mjs.map +3 -3
  172. package/build-module/dom/strip-html.mjs +1 -1
  173. package/build-module/dom/strip-html.mjs.map +3 -3
  174. package/build-module/dom/types.mjs +1 -0
  175. package/build-module/dom/types.mjs.map +7 -0
  176. package/build-module/dom/unwrap.mjs +1 -1
  177. package/build-module/dom/unwrap.mjs.map +3 -3
  178. package/build-module/dom/wrap.mjs +1 -1
  179. package/build-module/dom/wrap.mjs.map +3 -3
  180. package/build-module/focusable.mjs +5 -6
  181. package/build-module/focusable.mjs.map +3 -3
  182. package/build-module/index.mjs +1 -1
  183. package/build-module/index.mjs.map +2 -2
  184. package/build-module/phrasing-content.mjs +1 -1
  185. package/build-module/phrasing-content.mjs.map +3 -3
  186. package/build-module/tabbable.mjs +1 -1
  187. package/build-module/tabbable.mjs.map +3 -3
  188. package/build-module/types.mjs +1 -0
  189. package/build-module/types.mjs.map +7 -0
  190. package/build-types/data-transfer.d.ts +2 -2
  191. package/build-types/data-transfer.d.ts.map +1 -1
  192. package/build-types/dom/caret-range-from-point.d.ts +4 -4
  193. package/build-types/dom/caret-range-from-point.d.ts.map +1 -1
  194. package/build-types/dom/clean-node-list.d.ts +5 -45
  195. package/build-types/dom/clean-node-list.d.ts.map +1 -1
  196. package/build-types/dom/compute-caret-rect.d.ts +2 -2
  197. package/build-types/dom/compute-caret-rect.d.ts.map +1 -1
  198. package/build-types/dom/document-has-selection.d.ts +2 -2
  199. package/build-types/dom/document-has-selection.d.ts.map +1 -1
  200. package/build-types/dom/document-has-text-selection.d.ts +2 -2
  201. package/build-types/dom/document-has-text-selection.d.ts.map +1 -1
  202. package/build-types/dom/document-has-uncollapsed-selection.d.ts +2 -2
  203. package/build-types/dom/document-has-uncollapsed-selection.d.ts.map +1 -1
  204. package/build-types/dom/get-computed-style.d.ts +3 -3
  205. package/build-types/dom/get-computed-style.d.ts.map +1 -1
  206. package/build-types/dom/get-offset-parent.d.ts +2 -2
  207. package/build-types/dom/get-offset-parent.d.ts.map +1 -1
  208. package/build-types/dom/get-range-height.d.ts +2 -2
  209. package/build-types/dom/get-range-height.d.ts.map +1 -1
  210. package/build-types/dom/get-rectangle-from-range.d.ts +2 -2
  211. package/build-types/dom/get-rectangle-from-range.d.ts.map +1 -1
  212. package/build-types/dom/get-scroll-container.d.ts +5 -5
  213. package/build-types/dom/get-scroll-container.d.ts.map +1 -1
  214. package/build-types/dom/hidden-caret-range-from-point.d.ts +5 -5
  215. package/build-types/dom/hidden-caret-range-from-point.d.ts.map +1 -1
  216. package/build-types/dom/index.d.ts.map +1 -1
  217. package/build-types/dom/input-field-has-uncollapsed-selection.d.ts +2 -2
  218. package/build-types/dom/input-field-has-uncollapsed-selection.d.ts.map +1 -1
  219. package/build-types/dom/insert-after.d.ts +2 -3
  220. package/build-types/dom/insert-after.d.ts.map +1 -1
  221. package/build-types/dom/is-edge.d.ts +4 -4
  222. package/build-types/dom/is-edge.d.ts.map +1 -1
  223. package/build-types/dom/is-element.d.ts.map +1 -1
  224. package/build-types/dom/is-empty.d.ts +3 -3
  225. package/build-types/dom/is-empty.d.ts.map +1 -1
  226. package/build-types/dom/is-entirely-selected.d.ts +2 -2
  227. package/build-types/dom/is-entirely-selected.d.ts.map +1 -1
  228. package/build-types/dom/is-form-element.d.ts +3 -3
  229. package/build-types/dom/is-form-element.d.ts.map +1 -1
  230. package/build-types/dom/is-horizontal-edge.d.ts.map +1 -1
  231. package/build-types/dom/is-html-input-element.d.ts +1 -1
  232. package/build-types/dom/is-html-input-element.d.ts.map +1 -1
  233. package/build-types/dom/is-input-or-text-area.d.ts.map +1 -1
  234. package/build-types/dom/is-number-input.d.ts +2 -2
  235. package/build-types/dom/is-number-input.d.ts.map +1 -1
  236. package/build-types/dom/is-rtl.d.ts +2 -2
  237. package/build-types/dom/is-rtl.d.ts.map +1 -1
  238. package/build-types/dom/is-selection-forward.d.ts +2 -2
  239. package/build-types/dom/is-selection-forward.d.ts.map +1 -1
  240. package/build-types/dom/is-text-field.d.ts +2 -2
  241. package/build-types/dom/is-text-field.d.ts.map +1 -1
  242. package/build-types/dom/is-vertical-edge.d.ts.map +1 -1
  243. package/build-types/dom/place-caret-at-edge.d.ts +3 -3
  244. package/build-types/dom/place-caret-at-edge.d.ts.map +1 -1
  245. package/build-types/dom/place-caret-at-horizontal-edge.d.ts.map +1 -1
  246. package/build-types/dom/place-caret-at-vertical-edge.d.ts.map +1 -1
  247. package/build-types/dom/remove-invalid-html.d.ts +5 -4
  248. package/build-types/dom/remove-invalid-html.d.ts.map +1 -1
  249. package/build-types/dom/remove.d.ts +1 -2
  250. package/build-types/dom/remove.d.ts.map +1 -1
  251. package/build-types/dom/replace-tag.d.ts +3 -3
  252. package/build-types/dom/replace-tag.d.ts.map +1 -1
  253. package/build-types/dom/replace.d.ts +2 -3
  254. package/build-types/dom/replace.d.ts.map +1 -1
  255. package/build-types/dom/safe-html.d.ts +2 -2
  256. package/build-types/dom/safe-html.d.ts.map +1 -1
  257. package/build-types/dom/scroll-if-no-range.d.ts +5 -5
  258. package/build-types/dom/scroll-if-no-range.d.ts.map +1 -1
  259. package/build-types/dom/strip-html.d.ts +2 -2
  260. package/build-types/dom/strip-html.d.ts.map +1 -1
  261. package/build-types/dom/types.d.ts +32 -0
  262. package/build-types/dom/types.d.ts.map +1 -0
  263. package/build-types/dom/unwrap.d.ts +1 -3
  264. package/build-types/dom/unwrap.d.ts.map +1 -1
  265. package/build-types/dom/wrap.d.ts +2 -2
  266. package/build-types/dom/wrap.d.ts.map +1 -1
  267. package/build-types/focusable.d.ts +11 -30
  268. package/build-types/focusable.d.ts.map +1 -1
  269. package/build-types/index.d.ts +17 -0
  270. package/build-types/index.d.ts.map +1 -1
  271. package/build-types/phrasing-content.d.ts +9 -24
  272. package/build-types/phrasing-content.d.ts.map +1 -1
  273. package/build-types/tabbable.d.ts +10 -15
  274. package/build-types/tabbable.d.ts.map +1 -1
  275. package/build-types/types.d.ts +29 -0
  276. package/build-types/types.d.ts.map +1 -0
  277. package/package.json +6 -7
  278. package/src/{data-transfer.js → data-transfer.ts} +3 -3
  279. package/src/dom/{caret-range-from-point.js → caret-range-from-point.ts} +9 -5
  280. package/src/dom/{clean-node-list.js → clean-node-list.ts} +16 -24
  281. package/src/dom/{compute-caret-rect.js → compute-caret-rect.ts} +3 -3
  282. package/src/dom/{document-has-selection.js → document-has-selection.ts} +3 -3
  283. package/src/dom/{document-has-text-selection.js → document-has-text-selection.ts} +3 -3
  284. package/src/dom/{document-has-uncollapsed-selection.js → document-has-uncollapsed-selection.ts} +5 -3
  285. package/src/dom/{get-computed-style.js → get-computed-style.ts} +5 -3
  286. package/src/dom/{get-offset-parent.js → get-offset-parent.ts} +9 -14
  287. package/src/dom/{get-range-height.js → get-range-height.ts} +3 -3
  288. package/src/dom/{get-rectangle-from-range.js → get-rectangle-from-range.ts} +6 -12
  289. package/src/dom/{get-scroll-container.js → get-scroll-container.ts} +9 -9
  290. package/src/dom/{hidden-caret-range-from-point.js → hidden-caret-range-from-point.ts} +11 -6
  291. package/src/dom/{input-field-has-uncollapsed-selection.js → input-field-has-uncollapsed-selection.ts} +7 -5
  292. package/src/dom/{insert-after.js → insert-after.ts} +6 -4
  293. package/src/dom/{is-edge.js → is-edge.ts} +9 -5
  294. package/src/dom/{is-element.js → is-element.ts} +3 -1
  295. package/src/dom/{is-empty.js → is-empty.ts} +5 -7
  296. package/src/dom/{is-entirely-selected.js → is-entirely-selected.ts} +14 -11
  297. package/src/dom/{is-form-element.js → is-form-element.ts} +5 -3
  298. package/src/dom/{is-horizontal-edge.js → is-horizontal-edge.ts} +4 -1
  299. package/src/dom/{is-html-input-element.js → is-html-input-element.ts} +3 -1
  300. package/src/dom/{is-input-or-text-area.js → is-input-or-text-area.ts} +3 -1
  301. package/src/dom/{is-number-input.js → is-number-input.ts} +3 -3
  302. package/src/dom/{is-rtl.js → is-rtl.ts} +3 -3
  303. package/src/dom/{is-selection-forward.js → is-selection-forward.ts} +3 -3
  304. package/src/dom/{is-text-field.js → is-text-field.ts} +4 -4
  305. package/src/dom/{is-vertical-edge.js → is-vertical-edge.ts} +4 -1
  306. package/src/dom/{place-caret-at-edge.js → place-caret-at-edge.ts} +17 -9
  307. package/src/dom/{place-caret-at-horizontal-edge.js → place-caret-at-horizontal-edge.ts} +4 -1
  308. package/src/dom/{place-caret-at-vertical-edge.js → place-caret-at-vertical-edge.ts} +5 -1
  309. package/src/dom/{remove-invalid-html.js → remove-invalid-html.ts} +9 -4
  310. package/src/dom/{remove.js → remove.ts} +2 -3
  311. package/src/dom/{replace-tag.js → replace-tag.ts} +4 -4
  312. package/src/dom/{replace.js → replace.ts} +6 -4
  313. package/src/dom/{safe-html.js → safe-html.ts} +3 -3
  314. package/src/dom/{scroll-if-no-range.js → scroll-if-no-range.ts} +9 -5
  315. package/src/dom/{strip-html.js → strip-html.ts} +3 -3
  316. package/src/dom/types.ts +28 -0
  317. package/src/dom/{unwrap.js → unwrap.ts} +2 -4
  318. package/src/dom/{wrap.js → wrap.ts} +3 -3
  319. package/src/{focusable.js → focusable.ts} +34 -32
  320. package/src/index.ts +33 -0
  321. package/src/{phrasing-content.js → phrasing-content.ts} +15 -30
  322. package/src/{tabbable.js → tabbable.ts} +48 -39
  323. package/src/test/dom.jsdom.test.js +21 -0
  324. package/src/types.ts +32 -0
  325. package/CHANGELOG.md +0 -315
  326. package/src/index.js +0 -12
  327. /package/src/dom/{index.js → index.ts} +0 -0
@@ -1,3 +1,4 @@
1
+ import type { MaybeHTMLInputElement, ObjectTabbable } from './types';
1
2
  import { find as findFocusable } from './focusable';
2
3
 
3
4
  /**
@@ -8,11 +9,11 @@ import { find as findFocusable } from './focusable';
8
9
  *
9
10
  * @see https://bugzilla.mozilla.org/show_bug.cgi?id=1190261
10
11
  *
11
- * @param {Element} element Element from which to retrieve.
12
+ * @param element Element from which to retrieve.
12
13
  *
13
- * @return {number} Tab index of element (default 0).
14
+ * @return Tab index of element (default 0).
14
15
  */
15
- function getTabIndex( element ) {
16
+ function getTabIndex( element: Element ): number {
16
17
  const tabIndex = element.getAttribute( 'tabindex' );
17
18
  return tabIndex === null ? 0 : parseInt( tabIndex, 10 );
18
19
  }
@@ -20,31 +21,31 @@ function getTabIndex( element ) {
20
21
  /**
21
22
  * Returns true if the specified element is tabbable, or false otherwise.
22
23
  *
23
- * @param {Element} element Element to test.
24
+ * @param element Element to test.
24
25
  *
25
- * @return {boolean} Whether element is tabbable.
26
+ * @return Whether element is tabbable.
26
27
  */
27
- export function isTabbableIndex( element ) {
28
+ export function isTabbableIndex( element: Element ): boolean {
28
29
  return getTabIndex( element ) !== -1;
29
30
  }
30
31
 
31
- /** @typedef {HTMLElement & { type?: string, checked?: boolean, name?: string }} MaybeHTMLInputElement */
32
-
33
32
  /**
34
33
  * Returns a stateful reducer function which constructs a filtered array of
35
34
  * tabbable elements, where at most one radio input is selected for a given
36
35
  * name, giving priority to checked input, falling back to the first
37
36
  * encountered.
38
37
  *
39
- * @return {(acc: MaybeHTMLInputElement[], el: MaybeHTMLInputElement) => MaybeHTMLInputElement[]} Radio group collapse reducer.
38
+ * @return Radio group collapse reducer.
40
39
  */
41
- function createStatefulCollapseRadioGroup() {
42
- /** @type {Record<string, MaybeHTMLInputElement>} */
43
- const CHOSEN_RADIO_BY_NAME = {};
40
+ function createStatefulCollapseRadioGroup(): (
41
+ acc: MaybeHTMLInputElement[],
42
+ el: MaybeHTMLInputElement
43
+ ) => MaybeHTMLInputElement[] {
44
+ const CHOSEN_RADIO_BY_NAME: Record< string, MaybeHTMLInputElement > = {};
44
45
 
45
46
  return function collapseRadioGroup(
46
- /** @type {MaybeHTMLInputElement[]} */ result,
47
- /** @type {MaybeHTMLInputElement} */ element
47
+ result: MaybeHTMLInputElement[],
48
+ element: MaybeHTMLInputElement
48
49
  ) {
49
50
  const { nodeName, type, checked, name } = element;
50
51
 
@@ -81,12 +82,15 @@ function createStatefulCollapseRadioGroup() {
81
82
  * sort where equal tabIndex should be left in order of their occurrence in the
82
83
  * document.
83
84
  *
84
- * @param {HTMLElement} element Element.
85
- * @param {number} index Array index of element.
85
+ * @param element Element.
86
+ * @param index Array index of element.
86
87
  *
87
- * @return {{ element: HTMLElement, index: number }} Mapped object with element, index.
88
+ * @return Mapped object with element, index.
88
89
  */
89
- function mapElementToObjectTabbable( element, index ) {
90
+ function mapElementToObjectTabbable(
91
+ element: HTMLElement,
92
+ index: number
93
+ ): ObjectTabbable {
90
94
  return { element, index };
91
95
  }
92
96
 
@@ -94,11 +98,13 @@ function mapElementToObjectTabbable( element, index ) {
94
98
  * An array map callback, returning an element of the given mapped object's
95
99
  * element value.
96
100
  *
97
- * @param {{ element: HTMLElement }} object Mapped object with element.
101
+ * @param object Mapped object with element.
98
102
  *
99
- * @return {HTMLElement} Mapped object element.
103
+ * @return Mapped object element.
100
104
  */
101
- function mapObjectTabbableToElement( object ) {
105
+ function mapObjectTabbableToElement(
106
+ object: Pick< ObjectTabbable, 'element' >
107
+ ): HTMLElement {
102
108
  return object.element;
103
109
  }
104
110
 
@@ -107,12 +113,15 @@ function mapObjectTabbableToElement( object ) {
107
113
  *
108
114
  * @see mapElementToObjectTabbable
109
115
  *
110
- * @param {{ element: HTMLElement, index: number }} a First object to compare.
111
- * @param {{ element: HTMLElement, index: number }} b Second object to compare.
116
+ * @param a First object to compare.
117
+ * @param b Second object to compare.
112
118
  *
113
- * @return {number} Comparator result.
119
+ * @return Comparator result.
114
120
  */
115
- function compareObjectTabbables( a, b ) {
121
+ function compareObjectTabbables(
122
+ a: ObjectTabbable,
123
+ b: ObjectTabbable
124
+ ): number {
116
125
  const aTabIndex = getTabIndex( a.element );
117
126
  const bTabIndex = getTabIndex( b.element );
118
127
 
@@ -126,11 +135,11 @@ function compareObjectTabbables( a, b ) {
126
135
  /**
127
136
  * Given focusable elements, filters out tabbable element.
128
137
  *
129
- * @param {HTMLElement[]} focusables Focusable elements to filter.
138
+ * @param focusables Focusable elements to filter.
130
139
  *
131
- * @return {HTMLElement[]} Tabbable elements.
140
+ * @return Tabbable elements.
132
141
  */
133
- function filterTabbable( focusables ) {
142
+ function filterTabbable( focusables: HTMLElement[] ): HTMLElement[] {
134
143
  return focusables
135
144
  .filter( isTabbableIndex )
136
145
  .map( mapElementToObjectTabbable )
@@ -140,22 +149,22 @@ function filterTabbable( focusables ) {
140
149
  }
141
150
 
142
151
  /**
143
- * @param {Element} context
144
- * @return {HTMLElement[]} Tabbable elements within the context.
152
+ * @param context
153
+ * @return Tabbable elements within the context.
145
154
  */
146
- export function find( context ) {
155
+ export function find( context: Element ): HTMLElement[] {
147
156
  return filterTabbable( findFocusable( context ) );
148
157
  }
149
158
 
150
159
  /**
151
160
  * Given a focusable element, find the preceding tabbable element.
152
161
  *
153
- * @param {Element} element The focusable element before which to look. Defaults
154
- * to the active element.
162
+ * @param element The focusable element before which to look. Defaults
163
+ * to the active element.
155
164
  *
156
- * @return {HTMLElement|undefined} Preceding tabbable element.
165
+ * @return Preceding tabbable element.
157
166
  */
158
- export function findPrevious( element ) {
167
+ export function findPrevious( element: Element ): HTMLElement | undefined {
159
168
  return filterTabbable( findFocusable( element.ownerDocument.body ) )
160
169
  .reverse()
161
170
  .find(
@@ -169,12 +178,12 @@ export function findPrevious( element ) {
169
178
  /**
170
179
  * Given a focusable element, find the next tabbable element.
171
180
  *
172
- * @param {Element} element The focusable element after which to look. Defaults
173
- * to the active element.
181
+ * @param element The focusable element after which to look. Defaults
182
+ * to the active element.
174
183
  *
175
- * @return {HTMLElement|undefined} Next tabbable element.
184
+ * @return Next tabbable element.
176
185
  */
177
- export function findNext( element ) {
186
+ export function findNext( element: Element ): HTMLElement | undefined {
178
187
  return filterTabbable( findFocusable( element.ownerDocument.body ) ).find(
179
188
  ( focusable ) =>
180
189
  // eslint-disable-next-line no-bitwise
@@ -5,6 +5,7 @@ import {
5
5
  isTextField,
6
6
  removeInvalidHTML,
7
7
  isEmpty,
8
+ getOffsetParent,
8
9
  } from '../dom';
9
10
  import { getPhrasingContentSchema } from '../phrasing-content';
10
11
 
@@ -170,6 +171,26 @@ describe( 'DOM', () => {
170
171
  );
171
172
  } );
172
173
  } );
174
+
175
+ describe( 'getOffsetParent', () => {
176
+ it( 'should return the closest element when it is positioned', () => {
177
+ parent.style.position = 'relative';
178
+ const text = document.createTextNode( 'text' );
179
+ parent.appendChild( text );
180
+
181
+ expect( getOffsetParent( text ) ).toBe( parent );
182
+ } );
183
+
184
+ it( 'should return null when no ancestor is an element', () => {
185
+ expect( getOffsetParent( document.documentElement ) ).toBe( null );
186
+
187
+ const fragment = document.createDocumentFragment();
188
+ const text = document.createTextNode( 'text' );
189
+ fragment.appendChild( text );
190
+
191
+ expect( getOffsetParent( text ) ).toBe( null );
192
+ } );
193
+ } );
173
194
  } );
174
195
 
175
196
  describe( 'removeInvalidHTML', () => {
package/src/types.ts ADDED
@@ -0,0 +1,32 @@
1
+ export interface SemanticElementDefinition {
2
+ /**
3
+ * Content attributes
4
+ */
5
+ attributes?: string[];
6
+ /**
7
+ * Allowed child elements, or `'*'` for any
8
+ */
9
+ children?: ContentSchema | '*';
10
+ }
11
+
12
+ export type ContentSchema = Record< string, SemanticElementDefinition >;
13
+
14
+ export interface FindFocusableOptions {
15
+ /**
16
+ * If set, only return elements that are sequentially focusable.
17
+ * Non-interactive elements with a negative `tabindex` are focusable but
18
+ * not sequentially focusable.
19
+ */
20
+ sequential?: boolean;
21
+ }
22
+
23
+ export type MaybeHTMLInputElement = HTMLElement & {
24
+ type?: string;
25
+ checked?: boolean;
26
+ name?: string;
27
+ };
28
+
29
+ export interface ObjectTabbable {
30
+ element: HTMLElement;
31
+ index: number;
32
+ }
package/CHANGELOG.md DELETED
@@ -1,315 +0,0 @@
1
- <!-- Learn how to maintain this file at https://github.com/WordPress/gutenberg/tree/HEAD/packages#maintaining-changelogs. -->
2
-
3
- ## Unreleased
4
-
5
- ## 4.56.0 (2026-09-23)
6
-
7
- ### Bug Fixes
8
-
9
- - `getRectangleFromRange`: Measure a collapsed range on an element at the text position next to it instead of inserting a temporary text node under the caret ([#82977](https://github.com/WordPress/gutenberg/pull/82977)).
10
- - `focusable.find`: Return linked image-map areas when their mapped image is visible and outside an inert subtree ([#82736](https://github.com/WordPress/gutenberg/pull/82736)).
11
-
12
- ## 4.55.0 (2026-09-10)
13
-
14
- ### Bug Fixes
15
-
16
- - `focusable.find`: Exclude elements hidden by CSS `visibility` or `content-visibility` while preserving explicitly visible descendants ([#82574](https://github.com/WordPress/gutenberg/pull/82574)).
17
-
18
- ## 4.54.0 (2026-08-26)
19
-
20
- ### Bug Fixes
21
-
22
- - `cleanNodeList`: Unwrap whitespace-only phrasing content elements instead of removing them, so pasting content like `a<em> </em>b` no longer loses the space between words ([#76696](https://github.com/WordPress/gutenberg/pull/76696)).
23
-
24
- ## 4.53.0 (2026-08-12)
25
-
26
-
27
- ## 4.52.0 (2026-07-29)
28
-
29
- ## 4.51.0 (2026-07-14)
30
-
31
- ### Bug Fixes
32
-
33
- - `placeCaretAtEdge`: only place a caret when the container is itself an editable element, not when it merely inherits content editability from an editing host ancestor ([#79105](https://github.com/WordPress/gutenberg/pull/79105)).
34
-
35
- ## 4.50.0 (2026-07-01)
36
-
37
- ## 4.49.0 (2026-06-24)
38
-
39
- ## 4.48.1 (2026-06-16)
40
-
41
- ## 4.48.0 (2026-06-10)
42
-
43
- ## 4.47.0 (2026-05-27)
44
-
45
- ## 4.46.0 (2026-05-14)
46
-
47
- ## 4.45.0 (2026-04-29)
48
-
49
- ## 4.44.0 (2026-04-15)
50
-
51
- ## 4.43.0 (2026-04-01)
52
-
53
- ## 4.42.0 (2026-03-18)
54
-
55
- ## 4.41.0 (2026-03-04)
56
-
57
- ## 4.40.0 (2026-02-18)
58
-
59
- ## 4.39.0 (2026-01-29)
60
-
61
- ## 4.38.0 (2026-01-16)
62
-
63
- ## 4.36.0 (2025-11-26)
64
-
65
- ## 4.35.0 (2025-11-12)
66
-
67
- ## 4.34.0 (2025-10-29)
68
-
69
- ## 4.33.0 (2025-10-17)
70
-
71
- ## 4.32.0 (2025-10-01)
72
-
73
- ## 4.31.0 (2025-09-17)
74
-
75
- ## 4.30.0 (2025-09-03)
76
-
77
- ## 4.29.0 (2025-08-20)
78
-
79
- ## 4.28.0 (2025-08-07)
80
-
81
- ## 4.27.0 (2025-07-23)
82
-
83
- ## 4.26.0 (2025-06-25)
84
-
85
- ## 4.25.0 (2025-06-04)
86
-
87
- ## 4.24.0 (2025-05-22)
88
-
89
- ## 4.23.0 (2025-05-07)
90
-
91
- ## 4.22.0 (2025-04-11)
92
-
93
- ## 4.21.0 (2025-03-27)
94
-
95
- ## 4.20.0 (2025-03-13)
96
-
97
- ## 4.19.0 (2025-02-28)
98
-
99
- ## 4.18.0 (2025-02-12)
100
-
101
- ## 4.17.0 (2025-01-29)
102
-
103
- ## 4.16.0 (2025-01-15)
104
-
105
- ## 4.15.0 (2025-01-02)
106
-
107
- ## 4.14.0 (2024-12-11)
108
-
109
- ## 4.13.0 (2024-11-27)
110
-
111
- ## 4.12.0 (2024-11-16)
112
-
113
- ## 4.11.0 (2024-10-30)
114
-
115
- ## 4.10.0 (2024-10-16)
116
-
117
- ## 4.9.0 (2024-10-03)
118
-
119
- ## 4.8.0 (2024-09-19)
120
-
121
- ## 4.7.0 (2024-09-05)
122
-
123
- ## 4.6.0 (2024-08-21)
124
-
125
- ## 4.5.0 (2024-08-07)
126
-
127
- ## 4.4.0 (2024-07-24)
128
-
129
- ## 4.3.0 (2024-07-10)
130
-
131
- ## 4.2.0 (2024-06-26)
132
-
133
- ## 4.1.0 (2024-06-15)
134
-
135
- ## 4.0.0 (2024-05-31)
136
-
137
- ### Breaking Changes
138
-
139
- - Increase the minimum required Node.js version to v18.12.0 matching long-term support releases ([#31270](https://github.com/WordPress/gutenberg/pull/61930)). Learn more about [Node.js releases](https://nodejs.org/en/about/previous-releases).
140
-
141
- ## 3.58.0 (2024-05-16)
142
-
143
- ## 3.57.0 (2024-05-02)
144
-
145
- ## 3.56.0 (2024-04-19)
146
-
147
- ## 3.55.0 (2024-04-03)
148
-
149
- - fix return types of `focus.tabbable` methods to be `HTMLElement` instead of `Element`.
150
-
151
- ## 3.54.0 (2024-03-21)
152
-
153
- ## 3.53.0 (2024-03-06)
154
-
155
- ## 3.52.0 (2024-02-21)
156
-
157
- ## 3.51.0 (2024-02-09)
158
-
159
- ## 3.50.0 (2024-01-24)
160
-
161
- ## 3.49.0 (2024-01-10)
162
-
163
- ## 3.48.0 (2023-12-13)
164
-
165
- ## 3.47.0 (2023-11-29)
166
-
167
- ## 3.46.0 (2023-11-16)
168
-
169
- ## 3.45.0 (2023-11-02)
170
-
171
- ## 3.44.0 (2023-10-18)
172
-
173
- ## 3.43.0 (2023-10-05)
174
-
175
- ## 3.42.0 (2023-09-20)
176
-
177
- ## 3.41.0 (2023-08-31)
178
-
179
- ## 3.40.0 (2023-08-16)
180
-
181
- ## 3.39.0 (2023-08-10)
182
-
183
- ## 3.38.0 (2023-07-20)
184
-
185
- ## 3.37.0 (2023-07-05)
186
-
187
- ## 3.36.0 (2023-06-23)
188
-
189
- ## 3.35.0 (2023-06-07)
190
-
191
- ## 3.34.0 (2023-05-24)
192
-
193
- ## 3.33.0 (2023-05-10)
194
-
195
- ## 3.32.0 (2023-04-26)
196
-
197
- ## 3.31.0 (2023-04-12)
198
-
199
- ## 3.30.0 (2023-03-29)
200
-
201
- ## 3.29.0 (2023-03-15)
202
-
203
- ## 3.28.0 (2023-03-01)
204
-
205
- ## 3.27.0 (2023-02-15)
206
-
207
- ## 3.26.0 (2023-02-01)
208
-
209
- ## 3.25.0 (2023-01-11)
210
-
211
- ## 3.24.0 (2023-01-02)
212
-
213
- ## 3.23.0 (2022-12-14)
214
-
215
- ## 3.22.0 (2022-11-16)
216
-
217
- ## 3.21.0 (2022-11-02)
218
-
219
- ## 3.20.0 (2022-10-19)
220
-
221
- ## 3.19.0 (2022-10-05)
222
-
223
- ## 3.18.0 (2022-09-21)
224
-
225
- ## 3.17.0 (2022-09-13)
226
-
227
- ## 3.16.0 (2022-08-24)
228
-
229
- ## 3.15.0 (2022-08-10)
230
-
231
- ## 3.14.0 (2022-07-27)
232
-
233
- - `getRectangleFromRange` may now return `null`.
234
-
235
- ## 3.13.0 (2022-07-13)
236
-
237
- ## 3.12.0 (2022-06-29)
238
-
239
- ## 3.11.0 (2022-06-15)
240
-
241
- ## 3.10.0 (2022-06-01)
242
-
243
- ## 3.9.0 (2022-05-18)
244
-
245
- ### Deprecations
246
-
247
- - Deprecate `isNumberInput`, as it is no longer used internally ([#40896](https://github.com/WordPress/gutenberg/pull/40896)).
248
-
249
- ## 3.8.0 (2022-05-04)
250
-
251
- ## 3.7.0 (2022-04-21)
252
-
253
- ## 3.6.0 (2022-04-08)
254
-
255
- ## 3.5.0 (2022-03-23)
256
-
257
- ## 3.4.0 (2022-03-11)
258
-
259
- ## 3.3.0 (2022-01-27)
260
-
261
- ## 3.2.0 (2021-07-21)
262
-
263
- ## 3.1.0 (2021-05-20)
264
-
265
- ## 3.0.0 (2021-05-14)
266
-
267
- ### Breaking Changes
268
-
269
- - Drop support for Internet Explorer 11 ([#31110](https://github.com/WordPress/gutenberg/pull/31110)). Learn more at https://make.wordpress.org/core/2021/04/22/ie-11-support-phase-out-plan/.
270
- - Increase the minimum Node.js version to v12 matching Long Term Support releases ([#31270](https://github.com/WordPress/gutenberg/pull/31270)). Learn more at https://nodejs.org/en/about/releases/.
271
-
272
- ## 2.18.0 (2021-04-29)
273
-
274
- ### New Features
275
-
276
- - Export type definitions.
277
-
278
- ## 2.17.0 (2021-03-17)
279
-
280
- ## 2.11.0 (2020-06-15)
281
-
282
- ### New Features
283
-
284
- - Add `documentHasUncollapsedSelection` to inquire about ranges of selected text in the document, including the separately managed selections inside <input> and <textarea> elements.
285
-
286
- ## 2.10.0 (2020-05-28)
287
-
288
- ### New Features
289
-
290
- - Add `documentHasTextSelection` to inquire specifically about ranges of selected text, in addition to the existing `documentHasSelection`.
291
-
292
- ## 2.1.0 (2019-03-06)
293
-
294
- ### Bug Fixes
295
-
296
- - Update `isHorizontalEdge` to account for empty text nodes.
297
- - `tabbables.find` considers at most a single radio input for a given name. The checked input is given priority, falling back to the first in the tabindex-sorted set if there is no checked input.
298
-
299
- ## 2.0.8 (2019-01-03)
300
-
301
- ## 2.0.7 (2018-11-20)
302
-
303
- ## 2.0.6 (2018-11-09)
304
-
305
- ## 2.0.5 (2018-11-09)
306
-
307
- ## 2.0.4 (2018-10-19)
308
-
309
- ## 2.0.3 (2018-10-18)
310
-
311
- ## 2.0.0 (2018-09-05)
312
-
313
- ### Breaking Changes
314
-
315
- - Change how required built-ins are polyfilled with Babel 7 ([#9171](https://github.com/WordPress/gutenberg/pull/9171)). If you're using an environment that has limited or no support for ES2015+ such as lower versions of IE then using [core-js](https://github.com/zloirock/core-js) or [@babel/polyfill](https://babeljs.io/docs/en/next/babel-polyfill) will add support for these methods.
package/src/index.js DELETED
@@ -1,12 +0,0 @@
1
- import * as focusable from './focusable';
2
- import * as tabbable from './tabbable';
3
-
4
- /**
5
- * Object grouping `focusable` and `tabbable` utils
6
- * under the keys with the same name.
7
- */
8
- export const focus = { focusable, tabbable };
9
-
10
- export * from './dom';
11
- export * from './phrasing-content';
12
- export * from './data-transfer';
File without changes