chiplet 0.3.0 → 0.5.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 (316) hide show
  1. package/README.md +2 -5
  2. package/dist/assets/positioning.css.ts.vanilla-BLJ90UCF.css +60 -0
  3. package/dist/component/button/Button.js +5 -5
  4. package/dist/component/button/Button.js.map +1 -1
  5. package/dist/component/button/IconButton.js +1 -1
  6. package/dist/component/button/IconButton.js.map +1 -1
  7. package/dist/component/button/Interactive.js +2 -17
  8. package/dist/component/button/Interactive.js.map +1 -1
  9. package/dist/component/button/LinkButton.js +7 -5
  10. package/dist/component/button/LinkButton.js.map +1 -1
  11. package/dist/component/button/index.js +1 -0
  12. package/dist/component/button/index.js.map +1 -1
  13. package/dist/component/button/style/{index.css.vanilla.js → index.css.js} +5 -5
  14. package/dist/component/button/style/index.css.js.map +1 -0
  15. package/dist/component/checkbox/Checkbox.js +9 -19
  16. package/dist/component/checkbox/Checkbox.js.map +1 -1
  17. package/dist/component/checkbox/CheckboxGroup.js +2 -17
  18. package/dist/component/checkbox/CheckboxGroup.js.map +1 -1
  19. package/dist/component/checkbox/Radio.js +7 -18
  20. package/dist/component/checkbox/Radio.js.map +1 -1
  21. package/dist/component/checkbox/RadioGroup.js +2 -17
  22. package/dist/component/checkbox/RadioGroup.js.map +1 -1
  23. package/dist/component/checkbox/Switch.js +2 -2
  24. package/dist/component/checkbox/Switch.js.map +1 -1
  25. package/dist/component/checkbox/icon/index.js +0 -29
  26. package/dist/component/checkbox/icon/index.js.map +1 -1
  27. package/dist/component/checkbox/style/{index.css.vanilla.js → index.css.js} +4 -5
  28. package/dist/component/checkbox/style/index.css.js.map +1 -0
  29. package/dist/component/header/Header.js +2 -2
  30. package/dist/component/header/Header.js.map +1 -1
  31. package/dist/component/header/style/index.css.js +7 -0
  32. package/dist/component/header/style/index.css.js.map +1 -0
  33. package/dist/component/index.js +21 -19
  34. package/dist/component/index.js.map +1 -1
  35. package/dist/component/input/Input.js +7 -18
  36. package/dist/component/input/Input.js.map +1 -1
  37. package/dist/component/input/SearchInput.js +7 -13
  38. package/dist/component/input/SearchInput.js.map +1 -1
  39. package/dist/component/input/style/{index.css.vanilla.js → index.css.js} +5 -5
  40. package/dist/component/input/style/index.css.js.map +1 -0
  41. package/dist/component/menu/Menu.js +2 -28
  42. package/dist/component/menu/Menu.js.map +1 -1
  43. package/dist/component/menu/MenuButton.js +1 -3
  44. package/dist/component/menu/MenuButton.js.map +1 -1
  45. package/dist/component/menu/MenuItem.js +2 -18
  46. package/dist/component/menu/MenuItem.js.map +1 -1
  47. package/dist/component/menu/MenuItemCheckbox.js +4 -31
  48. package/dist/component/menu/MenuItemCheckbox.js.map +1 -1
  49. package/dist/component/menu/MenuItemRadio.js +5 -32
  50. package/dist/component/menu/MenuItemRadio.js.map +1 -1
  51. package/dist/component/menu/renderMenuItem.js +6 -2
  52. package/dist/component/menu/renderMenuItem.js.map +1 -1
  53. package/dist/component/popover/Dialog.js +2 -17
  54. package/dist/component/popover/Dialog.js.map +1 -1
  55. package/dist/component/popover/DismissButton.js +2 -19
  56. package/dist/component/popover/DismissButton.js.map +1 -1
  57. package/dist/component/popover/Popover.js +2 -17
  58. package/dist/component/popover/Popover.js.map +1 -1
  59. package/dist/component/popover/ShadowRoot.js +34 -0
  60. package/dist/component/popover/ShadowRoot.js.map +1 -0
  61. package/dist/component/popover/Tooltip.js +4 -18
  62. package/dist/component/popover/Tooltip.js.map +1 -1
  63. package/dist/component/popover/index.js +1 -0
  64. package/dist/component/popover/index.js.map +1 -1
  65. package/dist/component/popover/style/{index.css.vanilla.js → index.css.js} +5 -5
  66. package/dist/component/popover/style/index.css.js.map +1 -0
  67. package/dist/component/progress/Spinner.js +1 -1
  68. package/dist/component/progress/style/{index.css.vanilla.js → index.css.js} +4 -5
  69. package/dist/component/progress/style/index.css.js.map +1 -0
  70. package/dist/component/select/AutoComplete.js +7 -30
  71. package/dist/component/select/AutoComplete.js.map +1 -1
  72. package/dist/component/select/Group.js +3 -18
  73. package/dist/component/select/Group.js.map +1 -1
  74. package/dist/component/select/Option.js +7 -22
  75. package/dist/component/select/Option.js.map +1 -1
  76. package/dist/component/select/Select.js +6 -29
  77. package/dist/component/select/Select.js.map +1 -1
  78. package/dist/component/select/Separator.js +1 -1
  79. package/dist/component/select/style/{index.css.vanilla.js → index.css.js} +5 -5
  80. package/dist/component/select/style/index.css.js.map +1 -0
  81. package/dist/component/style/article.css.js +6 -0
  82. package/dist/component/style/article.css.js.map +1 -0
  83. package/dist/component/style/index.js +1 -1
  84. package/dist/component/typography/Body1.js +1 -1
  85. package/dist/component/typography/Body2.js +1 -1
  86. package/dist/component/typography/Body3.js +1 -1
  87. package/dist/component/typography/Caption1.js +1 -1
  88. package/dist/component/typography/Caption2.js +1 -1
  89. package/dist/component/typography/Heading1.js +1 -1
  90. package/dist/component/typography/Heading2.js +1 -1
  91. package/dist/component/typography/Heading3.js +1 -1
  92. package/dist/component/typography/Heading4.js +1 -1
  93. package/dist/component/typography/style/{index.css.vanilla.js → index.css.js} +4 -5
  94. package/dist/component/typography/style/index.css.js.map +1 -0
  95. package/dist/hook/accessibility/keyboard/Keyboard.js +6 -18
  96. package/dist/hook/accessibility/keyboard/Keyboard.js.map +1 -1
  97. package/dist/hook/accessibility/keyboard/Roving.js +0 -15
  98. package/dist/hook/accessibility/keyboard/Roving.js.map +1 -1
  99. package/dist/hook/accessibility/keyboard/context/index.js.map +1 -1
  100. package/dist/hook/accessibility/keyboard/hook/useLastFocused.js +1 -4
  101. package/dist/hook/accessibility/keyboard/hook/useLastFocused.js.map +1 -1
  102. package/dist/hook/accessibility/keyboard/hook/useNavigate.js.map +1 -1
  103. package/dist/hook/accessibility/keyboard/resolve.js +1 -4
  104. package/dist/hook/accessibility/keyboard/resolve.js.map +1 -1
  105. package/dist/hook/accessibility/keyboard/sort.js +0 -3
  106. package/dist/hook/accessibility/keyboard/sort.js.map +1 -1
  107. package/dist/hook/accessibility/keyboard/tree.js +1 -4
  108. package/dist/hook/accessibility/keyboard/tree.js.map +1 -1
  109. package/dist/hook/accessibility/keyboard/useController.js +2 -15
  110. package/dist/hook/accessibility/keyboard/useController.js.map +1 -1
  111. package/dist/hook/accessibility/keyboard/useKeyboard.js +2 -16
  112. package/dist/hook/accessibility/keyboard/useKeyboard.js.map +1 -1
  113. package/dist/hook/document/useHighlight.js +1 -6
  114. package/dist/hook/document/useHighlight.js.map +1 -1
  115. package/dist/hook/form/context/index.js.map +1 -1
  116. package/dist/hook/form/useAutoComplete.js +2 -16
  117. package/dist/hook/form/useAutoComplete.js.map +1 -1
  118. package/dist/hook/form/useChange.js.map +1 -1
  119. package/dist/hook/form/useCheckbox.js +0 -16
  120. package/dist/hook/form/useCheckbox.js.map +1 -1
  121. package/dist/hook/form/useChecked.js +1 -14
  122. package/dist/hook/form/useChecked.js.map +1 -1
  123. package/dist/hook/form/useForm.js +1 -15
  124. package/dist/hook/form/useForm.js.map +1 -1
  125. package/dist/hook/form/useGroup.js +18 -30
  126. package/dist/hook/form/useGroup.js.map +1 -1
  127. package/dist/hook/form/useName.js.map +1 -1
  128. package/dist/hook/form/useOption.js +0 -16
  129. package/dist/hook/form/useOption.js.map +1 -1
  130. package/dist/hook/form/useRadio.js +0 -16
  131. package/dist/hook/form/useRadio.js.map +1 -1
  132. package/dist/hook/form/useSelect.js +0 -16
  133. package/dist/hook/form/useSelect.js.map +1 -1
  134. package/dist/hook/form/useValue.js +0 -15
  135. package/dist/hook/form/useValue.js.map +1 -1
  136. package/dist/hook/index.js +22 -21
  137. package/dist/hook/index.js.map +1 -1
  138. package/dist/hook/observable/useObservable.js +6 -1
  139. package/dist/hook/observable/useObservable.js.map +1 -1
  140. package/dist/hook/popover/context/index.js.map +1 -1
  141. package/dist/hook/popover/index.js +2 -1
  142. package/dist/hook/popover/index.js.map +1 -1
  143. package/dist/hook/popover/style/positioning.css.js +13 -0
  144. package/dist/hook/popover/style/positioning.css.js.map +1 -0
  145. package/dist/hook/popover/useAnchorPositioning.js +6 -88
  146. package/dist/hook/popover/useAnchorPositioning.js.map +1 -1
  147. package/dist/hook/popover/useDialog.js +1 -15
  148. package/dist/hook/popover/useDialog.js.map +1 -1
  149. package/dist/hook/popover/useLightDismiss.js +16 -4
  150. package/dist/hook/popover/useLightDismiss.js.map +1 -1
  151. package/dist/hook/popover/useOverlay.js +8 -20
  152. package/dist/hook/popover/useOverlay.js.map +1 -1
  153. package/dist/hook/popover/usePopover.js +12 -23
  154. package/dist/hook/popover/usePopover.js.map +1 -1
  155. package/dist/hook/popover/usePositioning.js +10 -16
  156. package/dist/hook/popover/usePositioning.js.map +1 -1
  157. package/dist/hook/popover/useReturnFocus.js.map +1 -1
  158. package/dist/hook/popover/useTooltip.js +4 -15
  159. package/dist/hook/popover/useTooltip.js.map +1 -1
  160. package/dist/hook/promise/usePromise.js +1 -1
  161. package/dist/hook/promise/usePromise.js.map +1 -1
  162. package/dist/hook/react/refValue.js +0 -3
  163. package/dist/hook/react/refValue.js.map +1 -1
  164. package/dist/hook/react/useActivate.js +4 -4
  165. package/dist/hook/react/useActivate.js.map +1 -1
  166. package/dist/hook/react/useConst.js +3 -2
  167. package/dist/hook/react/useConst.js.map +1 -1
  168. package/dist/hook/react/useInteractive.js +1 -4
  169. package/dist/hook/react/useInteractive.js.map +1 -1
  170. package/dist/hook/react/useRefCallback.js.map +1 -1
  171. package/dist/hook/react/useUniqueId.js +1 -4
  172. package/dist/hook/react/useUniqueId.js.map +1 -1
  173. package/dist/index.js +112 -109
  174. package/dist/index.js.map +1 -1
  175. package/dist/infra/index.js +1 -1
  176. package/dist/infra/logging/logger.js +13 -10
  177. package/dist/infra/logging/logger.js.map +1 -1
  178. package/dist/theme/defineTheme.js +0 -3
  179. package/dist/theme/defineTheme.js.map +1 -1
  180. package/dist/theme/{global.css.vanilla.js → global.css.js} +4 -4
  181. package/dist/theme/global.css.js.map +1 -0
  182. package/dist/theme/index.js +5 -3
  183. package/dist/theme/index.js.map +1 -1
  184. package/dist/theme/{theme.css.vanilla.js → theme.css.js} +3 -3
  185. package/dist/theme/theme.css.js.map +1 -0
  186. package/dist/theme/{token.css.vanilla.js → token.css.js} +2 -2
  187. package/dist/theme/token.css.js.map +1 -0
  188. package/dist/theme/useSystemColorScheme.js +16 -16
  189. package/dist/theme/useSystemColorScheme.js.map +1 -1
  190. package/dist/util/array/index.js +0 -1
  191. package/dist/util/array/index.js.map +1 -1
  192. package/dist/util/document/{accessibility.css.vanilla.js → accessibility.css.js} +1 -1
  193. package/dist/util/document/accessibility.css.js.map +1 -0
  194. package/dist/util/document/index.js +1 -1
  195. package/dist/util/file/readAsDataURL.js +15 -4
  196. package/dist/util/file/readAsDataURL.js.map +1 -1
  197. package/dist/util/index.js +28 -30
  198. package/dist/util/index.js.map +1 -1
  199. package/dist/util/linked-list/buildLinkedList.js.map +1 -1
  200. package/dist/util/lock/lock.js +0 -2
  201. package/dist/util/lock/lock.js.map +1 -1
  202. package/dist/util/random/index.js +0 -1
  203. package/dist/util/random/index.js.map +1 -1
  204. package/dist/util/tree/addTreeNode.js.map +1 -1
  205. package/dist/util/tree/attachChild.js +7 -1
  206. package/dist/util/tree/attachChild.js.map +1 -1
  207. package/dist/util/tree/buildTree.js.map +1 -1
  208. package/dist/util/tree/detachChild.js +3 -0
  209. package/dist/util/tree/detachChild.js.map +1 -1
  210. package/dist/util/tree/iterateChildren.js.map +1 -1
  211. package/dist/util/tree/iterateTree.js.map +1 -1
  212. package/package.json +49 -47
  213. package/src/component/button/Button.tsx +4 -5
  214. package/src/component/button/IconButton.tsx +1 -1
  215. package/src/component/button/LinkButton.tsx +14 -6
  216. package/src/component/button/index.ts +1 -0
  217. package/src/component/checkbox/Checkbox.tsx +8 -1
  218. package/src/component/checkbox/Radio.tsx +5 -1
  219. package/src/component/checkbox/Switch.tsx +1 -1
  220. package/src/component/checkbox/icon/index.ts +1 -1
  221. package/src/component/header/Header.tsx +1 -1
  222. package/src/component/input/Input.tsx +5 -1
  223. package/src/component/input/SearchInput.tsx +10 -9
  224. package/src/component/menu/Menu.tsx +1 -1
  225. package/src/component/menu/MenuItemCheckbox.tsx +1 -1
  226. package/src/component/menu/MenuItemRadio.tsx +1 -1
  227. package/src/component/menu/renderMenuItem.tsx +5 -1
  228. package/src/component/popover/ShadowRoot.tsx +42 -0
  229. package/src/component/popover/Tooltip.tsx +2 -2
  230. package/src/component/popover/index.ts +1 -0
  231. package/src/component/select/AutoComplete.tsx +3 -7
  232. package/src/component/select/Group.tsx +1 -1
  233. package/src/component/select/Option.tsx +1 -1
  234. package/src/component/select/Select.tsx +3 -7
  235. package/src/hook/accessibility/keyboard/Keyboard.tsx +1 -1
  236. package/src/hook/accessibility/keyboard/Roving.tsx +1 -1
  237. package/src/hook/accessibility/keyboard/context/index.ts +2 -2
  238. package/src/hook/accessibility/keyboard/hook/useLastFocused.ts +7 -1
  239. package/src/hook/accessibility/keyboard/hook/useNavigate.ts +1 -1
  240. package/src/hook/accessibility/keyboard/resolve.ts +1 -1
  241. package/src/hook/accessibility/keyboard/useController.ts +3 -2
  242. package/src/hook/accessibility/keyboard/useKeyboard.ts +3 -2
  243. package/src/hook/document/useHighlight.ts +5 -4
  244. package/src/hook/form/context/index.ts +1 -1
  245. package/src/hook/form/useAutoComplete.ts +14 -14
  246. package/src/hook/form/useChange.ts +1 -1
  247. package/src/hook/form/useCheckbox.ts +2 -2
  248. package/src/hook/form/useChecked.ts +3 -2
  249. package/src/hook/form/useForm.ts +1 -1
  250. package/src/hook/form/useGroup.ts +20 -21
  251. package/src/hook/form/useName.ts +1 -1
  252. package/src/hook/form/useOption.ts +2 -2
  253. package/src/hook/form/useRadio.ts +2 -2
  254. package/src/hook/form/useSelect.ts +15 -12
  255. package/src/hook/form/useValue.ts +3 -2
  256. package/src/hook/observable/useObservable.ts +14 -1
  257. package/src/hook/popover/context/index.ts +1 -1
  258. package/src/hook/popover/style/positioning.css.ts +112 -0
  259. package/src/hook/popover/useAnchorPositioning.ts +16 -105
  260. package/src/hook/popover/useDialog.ts +5 -4
  261. package/src/hook/popover/useLightDismiss.ts +27 -0
  262. package/src/hook/popover/useOverlay.ts +17 -8
  263. package/src/hook/popover/usePopover.ts +22 -24
  264. package/src/hook/popover/usePositioning.ts +17 -20
  265. package/src/hook/popover/useReturnFocus.ts +12 -3
  266. package/src/hook/popover/useTooltip.ts +10 -9
  267. package/src/hook/promise/usePromise.ts +4 -1
  268. package/src/hook/react/useActivate.ts +8 -1
  269. package/src/hook/react/useConst.ts +3 -3
  270. package/src/hook/react/useRefCallback.ts +3 -1
  271. package/src/infra/logging/logger.ts +43 -19
  272. package/src/theme/global.css.ts +1 -28
  273. package/src/theme/index.ts +4 -0
  274. package/src/theme/useSystemColorScheme.ts +22 -20
  275. package/src/util/array/index.ts +0 -1
  276. package/src/util/document/accessibility.css.ts +1 -1
  277. package/src/util/file/readAsDataURL.ts +17 -4
  278. package/src/util/linked-list/buildLinkedList.ts +1 -1
  279. package/src/util/number/index.ts +2 -0
  280. package/src/util/random/index.ts +4 -1
  281. package/src/util/tree/addTreeNode.ts +1 -1
  282. package/src/util/tree/attachChild.ts +13 -2
  283. package/src/util/tree/buildTree.ts +1 -1
  284. package/src/util/tree/detachChild.ts +7 -1
  285. package/src/util/tree/iterateChildren.ts +1 -1
  286. package/src/util/tree/iterateTree.ts +1 -1
  287. package/dist/component/button/style/index.css.vanilla.js.map +0 -1
  288. package/dist/component/checkbox/style/index.css.vanilla.js.map +0 -1
  289. package/dist/component/header/style/index.css.vanilla.js +0 -7
  290. package/dist/component/header/style/index.css.vanilla.js.map +0 -1
  291. package/dist/component/input/style/index.css.vanilla.js.map +0 -1
  292. package/dist/component/popover/style/index.css.vanilla.js.map +0 -1
  293. package/dist/component/progress/style/index.css.vanilla.js.map +0 -1
  294. package/dist/component/select/style/index.css.vanilla.js.map +0 -1
  295. package/dist/component/style/article.css.vanilla.js +0 -6
  296. package/dist/component/style/article.css.vanilla.js.map +0 -1
  297. package/dist/component/typography/style/index.css.vanilla.js.map +0 -1
  298. package/dist/theme/global.css.vanilla.js.map +0 -1
  299. package/dist/theme/theme.css.vanilla.js.map +0 -1
  300. package/dist/theme/token.css.vanilla.js.map +0 -1
  301. package/dist/util/array/fromAsync.js +0 -11
  302. package/dist/util/array/fromAsync.js.map +0 -1
  303. package/dist/util/document/accessibility.css.vanilla.js.map +0 -1
  304. package/src/util/array/fromAsync.ts +0 -11
  305. /package/dist/{article.css → assets/article.css.ts.vanilla-s_HEpsy3.css} +0 -0
  306. /package/dist/{global.css → assets/global.css.ts.vanilla-CTwjHiaM.css} +0 -0
  307. /package/dist/{index8.css → assets/index.css.ts.vanilla-9qGDrdgn.css} +0 -0
  308. /package/dist/{index6.css → assets/index.css.ts.vanilla-BsBngo8U.css} +0 -0
  309. /package/dist/{index2.css → assets/index.css.ts.vanilla-CVNLkHc9.css} +0 -0
  310. /package/dist/{index3.css → assets/index.css.ts.vanilla-C_RzxiYH.css} +0 -0
  311. /package/dist/{index5.css → assets/index.css.ts.vanilla-CvQQLJ-M.css} +0 -0
  312. /package/dist/{index.css → assets/index.css.ts.vanilla-DGmHFJbF.css} +0 -0
  313. /package/dist/{index4.css → assets/index.css.ts.vanilla-VHSAjLub.css} +0 -0
  314. /package/dist/{index7.css → assets/index.css.ts.vanilla-kgyRRvgH.css} +0 -0
  315. /package/dist/{theme.css → assets/theme.css.ts.vanilla-Bjn8sb_B.css} +0 -0
  316. /package/dist/{token.css → assets/token.css.ts.vanilla-B3LtFaO7.css} +0 -0
@@ -0,0 +1,112 @@
1
+ import { entries, fromEntries, keys } from '#util'
2
+ import type { Alignment, Placement } from '@floating-ui/utils'
3
+ import { globalStyle } from '@vanilla-extract/css'
4
+ import type { Simplify } from 'type-fest'
5
+ import { generateDeterministicId } from '../../../util/random/generateDeterministicId'
6
+
7
+ export type Side = 'above' | 'below' | 'before' | 'after'
8
+ export type Axis = 'block' | 'inline'
9
+ export type Position = Simplify<Side | `${Side}-${Alignment}`>
10
+
11
+ export const Position = [
12
+ 'above',
13
+ 'below',
14
+ 'before',
15
+ 'after',
16
+ 'above-start',
17
+ 'above-end',
18
+ 'below-start',
19
+ 'below-end',
20
+ 'before-start',
21
+ 'before-end',
22
+ 'after-start',
23
+ 'after-end',
24
+ ] as const
25
+
26
+ export const positionMap: Record<Position, Placement> = {
27
+ 'above': 'top',
28
+ 'below': 'bottom',
29
+ 'before': 'left',
30
+ 'after': 'right',
31
+ 'above-start': 'top-start',
32
+ 'above-end': 'top-end',
33
+ 'below-start': 'bottom-start',
34
+ 'below-end': 'bottom-end',
35
+ 'before-start': 'left-start',
36
+ 'before-end': 'left-end',
37
+ 'after-start': 'right-start',
38
+ 'after-end': 'right-end',
39
+ }
40
+
41
+ export const placementMap: Record<Placement, Position> = fromEntries(
42
+ entries(positionMap).map(([position, placement]) => [placement, position])
43
+ )
44
+
45
+ export const positionAxisMap: Record<Position, Axis> = {
46
+ 'above': 'block',
47
+ 'above-start': 'block',
48
+ 'above-end': 'block',
49
+ 'below': 'block',
50
+ 'below-start': 'block',
51
+ 'below-end': 'block',
52
+ 'before': 'inline',
53
+ 'before-start': 'inline',
54
+ 'before-end': 'inline',
55
+ 'after': 'inline',
56
+ 'after-start': 'inline',
57
+ 'after-end': 'inline',
58
+ }
59
+
60
+ /**
61
+ * https://developer.mozilla.org/en-US/docs/Web/CSS/position-area_value#logical_grid_keyword_defaults
62
+ */
63
+ export const positionAreaMap: Record<Position, string> = {
64
+ 'above': 'block-start',
65
+ 'below': 'block-end',
66
+ 'before': 'inline-start',
67
+ 'after': 'inline-end',
68
+ 'above-start': 'start span-end',
69
+ 'above-end': 'start span-start',
70
+ 'below-start': 'end span-end',
71
+ 'below-end': 'end span-start',
72
+ 'before-start': 'inline-start span-block-end',
73
+ 'before-end': 'inline-start span-block-start',
74
+ 'after-start': 'inline-end span-block-end',
75
+ 'after-end': 'inline-end span-block-start',
76
+ }
77
+
78
+ export const positionInsetMap: Record<Position, keyof React.CSSProperties> = {
79
+ 'above': 'insetBlockEnd',
80
+ 'above-start': 'insetBlockEnd',
81
+ 'above-end': 'insetBlockEnd',
82
+ 'below': 'insetBlockStart',
83
+ 'below-start': 'insetBlockStart',
84
+ 'below-end': 'insetBlockStart',
85
+ 'before': 'insetInlineEnd',
86
+ 'before-start': 'insetInlineEnd',
87
+ 'before-end': 'insetInlineEnd',
88
+ 'after': 'insetInlineStart',
89
+ 'after-start': 'insetInlineStart',
90
+ 'after-end': 'insetInlineStart',
91
+ }
92
+
93
+ export const PositionOffset = generateDeterministicId('--offset')
94
+
95
+ const PositionTryOptionName = generateDeterministicId('')
96
+
97
+ export const positionTryOptionMap: Record<Position, string> = fromEntries(
98
+ keys(positionMap).map((position) => [
99
+ position,
100
+ `--position-try-option-${position}-${PositionTryOptionName}`,
101
+ ])
102
+ )
103
+
104
+ for (const [position, area] of entries(positionAreaMap)) {
105
+ globalStyle(`@position-try ${positionTryOptionMap[position]}`, {
106
+ inset: 'auto',
107
+ [positionInsetMap[position]]: `var(${PositionOffset})`,
108
+ positionArea: area,
109
+ // TODO: extend 'positionTryOptionMap', add '@starting-style' entry
110
+ // animation, and try to reuse 'PopoverStyle'
111
+ })
112
+ }
@@ -1,15 +1,21 @@
1
- import { entries, fromEntries } from '#util'
2
1
  import {
3
2
  getAlignment,
4
3
  getExpandedPlacements,
5
4
  getOppositeAxisPlacements,
6
5
  getOppositePlacement,
7
- type Alignment,
8
- type Placement,
9
6
  } from '@floating-ui/utils'
10
7
  import { useMemo } from 'react'
11
- import type { Simplify } from 'type-fest'
12
- import { useUniqueId } from '../react'
8
+ import { useUniqueId } from '../react/useUniqueId'
9
+ import {
10
+ placementMap,
11
+ positionAreaMap,
12
+ positionAxisMap,
13
+ positionInsetMap,
14
+ positionMap,
15
+ PositionOffset,
16
+ positionTryOptionMap,
17
+ type Position,
18
+ } from './style/positioning.css'
13
19
  import type { Positioning, PositioningOptions } from './usePositioning'
14
20
 
15
21
  /**
@@ -36,22 +42,19 @@ export function useAnchorPositioning(options: PositioningOptions): Positioning {
36
42
  }
37
43
 
38
44
  positionedStyle = {
45
+ [PositionOffset]: `${offset}px`,
39
46
  position: strategy,
40
47
  positionAnchor: anchorName,
41
48
  positionArea: positionAreaMap[position],
42
- // TODO: https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/At-rules/@position-try
43
49
  positionTry: fallback
44
- .map((position) => positionAreaMap[position])
50
+ .map((position) => positionTryOptionMap[position])
45
51
  .join(', '),
46
52
  margin: '0',
47
- inset: 'auto', // https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/Properties/position-area#using_position-area_to_position_popovers
48
- // https://developer.mozilla.org/en-US/docs/Web/CSS/position-area#adjusted_default_behavior
49
- // When an anchor-positioned element is positioned using the position-area property,
50
- // any inset properties set, such as top or inset-inline-end, specify offsets from the position-area.
51
- [insetMap[position]]: `${offset}px`,
53
+ inset: 'auto',
54
+ [positionInsetMap[position]]: `var(${PositionOffset})`,
52
55
  }
53
56
 
54
- switch (options.align && positionAxis(position)) {
57
+ switch (options.align && positionAxisMap[position]) {
55
58
  case 'block':
56
59
  positionedStyle.minInlineSize = `min(100vi, 100%, anchor-size(self-inline))`
57
60
  break
@@ -71,83 +74,6 @@ export function useAnchorPositioning(options: PositioningOptions): Positioning {
71
74
  }
72
75
  }
73
76
 
74
- type Side = 'above' | 'below' | 'before' | 'after'
75
-
76
- export type Position = Simplify<Side | `${Side}-${Alignment}`>
77
-
78
- export const Position = [
79
- 'above',
80
- 'below',
81
- 'before',
82
- 'after',
83
- 'above-start',
84
- 'above-end',
85
- 'below-start',
86
- 'below-end',
87
- 'before-start',
88
- 'before-end',
89
- 'after-start',
90
- 'after-end',
91
- ] as const
92
-
93
- type Axis = 'block' | 'inline'
94
-
95
- function positionSide(position: Position): Side {
96
- return position.split('-')[0] as Side
97
- }
98
-
99
- export function positionAxis(position: Position): Axis {
100
- switch (positionSide(position)) {
101
- case 'above':
102
- case 'below':
103
- return 'block'
104
- case 'before':
105
- case 'after':
106
- return 'inline'
107
- }
108
- }
109
-
110
- export const positionMap: Record<Position, Placement> = {
111
- 'above': 'top',
112
- 'below': 'bottom',
113
- 'before': 'left',
114
- 'after': 'right',
115
- 'above-start': 'top-start',
116
- 'above-end': 'top-end',
117
- 'below-start': 'bottom-start',
118
- 'below-end': 'bottom-end',
119
- 'before-start': 'left-start',
120
- 'before-end': 'left-end',
121
- 'after-start': 'right-start',
122
- 'after-end': 'right-end',
123
- }
124
-
125
- export const placementMap: Record<Placement, Position> = fromEntries(
126
- entries(positionMap).map(([position, placement]) => [placement, position])
127
- )
128
-
129
- /**
130
- * TODO
131
- * - above => [flip-block, flip-start, flip-start flip-inline]
132
- * - above-start => [flip-inline, flip-block, flip-block flip-inline, flip-start, flip-start flip-block, flip-start flip-inline, flip-start flip-inline flip-block]
133
- *
134
- * https://developer.mozilla.org/en-US/docs/Web/CSS/position-area_value#logical_grid_keyword_defaults
135
- */
136
- export const positionAreaMap: Record<Position, string> = {
137
- 'above': 'block-start',
138
- 'below': 'block-end',
139
- 'before': 'inline-start',
140
- 'after': 'inline-end',
141
- 'above-start': 'start span-end',
142
- 'above-end': 'start span-start',
143
- 'below-start': 'end span-end',
144
- 'below-end': 'end span-start',
145
- 'before-start': 'inline-start span-block-end',
146
- 'before-end': 'inline-start span-block-start',
147
- 'after-start': 'inline-end span-block-end',
148
- 'after-end': 'inline-end span-block-start',
149
- }
150
-
151
77
  /**
152
78
  * https://floating-ui.com/docs/flip#fallbackplacements
153
79
  *
@@ -167,21 +93,6 @@ export function positionTry(position: Position, tryCrossAxis?: boolean) {
167
93
  ).map((placement) => placementMap[placement])
168
94
  }
169
95
 
170
- const insetMap: Record<Position, string> = {
171
- 'above': 'insetBlock', // TODO: when flipping to the before/after position, we should use the `inset-inline` property instead.
172
- 'below': 'insetBlock',
173
- 'before': 'insetInline',
174
- 'after': 'insetInline',
175
- 'above-start': 'insetBlock',
176
- 'above-end': 'insetBlock',
177
- 'below-start': 'insetBlock',
178
- 'below-end': 'insetBlock',
179
- 'before-start': 'insetInline',
180
- 'before-end': 'insetInline',
181
- 'after-start': 'insetInline',
182
- 'after-end': 'insetInline',
183
- }
184
-
185
96
  export function usePositioningOptions(options: PositioningOptions) {
186
97
  const { position = 'below' } = options
187
98
 
@@ -1,5 +1,4 @@
1
1
  'use client'
2
- import { useRefObject, useUniqueId } from '#hook'
3
2
  import {
4
3
  cloneElement,
5
4
  createElement,
@@ -7,16 +6,18 @@ import {
7
6
  useLayoutEffect,
8
7
  useRef,
9
8
  } from 'react'
9
+ import { useRefObject } from '../react/useRefObject'
10
+ import { useUniqueId } from '../react/useUniqueId'
10
11
  import { OverlayContext } from './context'
11
12
  import { useAnchor } from './useAnchor'
13
+ import { useLightDismiss } from './useLightDismiss'
12
14
  import {
13
- useLightDismiss,
14
15
  useOverlay,
15
- useReturnFocus,
16
16
  type Overlay,
17
17
  type OverlayAnchorProps,
18
18
  type ToggleCallback,
19
- } from '.'
19
+ } from './useOverlay'
20
+ import { useReturnFocus } from './useReturnFocus'
20
21
 
21
22
  type DialogTag = 'dialog'
22
23
 
@@ -28,6 +28,33 @@ export function useLightDismiss<
28
28
  ref.current.source = source
29
29
  })
30
30
 
31
+ {
32
+ const { onKeyDown } = anchorProps
33
+
34
+ anchorProps = {
35
+ ...anchorProps,
36
+ onKeyDown: useCallback<NonNullable<typeof onKeyDown>>(
37
+ (ev) => {
38
+ onKeyDown?.(ev)
39
+
40
+ // A pending open or close claims the escape key to abort
41
+ // itself by reverting to the committed state. A committed
42
+ // open or an idle overlay toggles to a no-op and defers to
43
+ // the document listener below, which closes the topmost
44
+ // overlay instead.
45
+ if (
46
+ !ev.defaultPrevented &&
47
+ isEscapeKey(ev) &&
48
+ ref.current.overlay.toggle(ev, ref.current.overlay.open, 'escape')
49
+ ) {
50
+ ev.preventDefault()
51
+ }
52
+ },
53
+ [onKeyDown]
54
+ ),
55
+ }
56
+ }
57
+
31
58
  {
32
59
  const { onClickCapture } = positionedProps
33
60
 
@@ -1,7 +1,7 @@
1
1
  'use client'
2
- import { useDefault } from '#hook'
3
- import type { GlobalAttributes } from '#hook/react/element.d'
4
2
  import { useCallback, useLayoutEffect, useMemo, useRef } from 'react'
3
+ import { useDefault } from '../form/useDefault'
4
+ import type { GlobalAttributes } from '../react/element.d'
5
5
 
6
6
  export interface OverlayAnchorProps
7
7
  extends GlobalAttributes, React.AriaAttributes, React.RefAttributes<Element> {
@@ -9,6 +9,7 @@ export interface OverlayAnchorProps
9
9
  onFocus?: React.FocusEventHandler<Element> | undefined
10
10
  onBlur?: React.FocusEventHandler<Element> | undefined
11
11
  onClick?: React.MouseEventHandler<Element> | undefined
12
+ onKeyDown?: React.KeyboardEventHandler<Element> | undefined
12
13
  onPointerEnter?: React.PointerEventHandler<Element> | undefined
13
14
  onPointerLeave?: React.PointerEventHandler<Element> | undefined
14
15
  }
@@ -33,7 +34,7 @@ export interface Overlay<T extends HTMLElement = HTMLElement> {
33
34
  ev: Event | React.SyntheticEvent,
34
35
  open?: boolean,
35
36
  hint?: string
36
- ) => void
37
+ ) => boolean
37
38
  }
38
39
 
39
40
  export function useOverlay<T extends HTMLElement>(options: OverlayOptions<T>) {
@@ -55,13 +56,21 @@ export function useOverlay<T extends HTMLElement>(options: OverlayOptions<T>) {
55
56
  (ev, open, hint) => {
56
57
  open ??= !ref.current
57
58
 
58
- if (ref.current !== open) {
59
- setOpen(ev, open, hint)
59
+ if (ref.current === open) {
60
+ return false
61
+ }
62
+
63
+ setOpen(ev, open, hint)
60
64
 
61
- if (!ev.defaultPrevented) {
62
- ref.current = open
63
- }
65
+ // A vetoed change (`onToggle` preventing the event) never commits in
66
+ // `useDefault`, so the uncommitted mirror in `ref` must not advance.
67
+ if (ev.defaultPrevented) {
68
+ return false
64
69
  }
70
+
71
+ ref.current = open
72
+
73
+ return true
65
74
  },
66
75
  [setOpen]
67
76
  )
@@ -1,15 +1,4 @@
1
1
  'use client'
2
- import {
3
- Keyboard,
4
- useController,
5
- useRefCallback,
6
- useRefObject,
7
- useUniqueId,
8
- type KeyboardOptions,
9
- type KeyboardProps,
10
- type NavigationDirection,
11
- } from '#hook'
12
- import type { HTMLElementRef } from '#hook/react/element.d'
13
2
  import {
14
3
  cloneElement,
15
4
  createElement,
@@ -17,6 +6,17 @@ import {
17
6
  useLayoutEffect,
18
7
  useRef,
19
8
  } from 'react'
9
+ import {
10
+ Keyboard,
11
+ type KeyboardOptions,
12
+ type KeyboardProps,
13
+ type NavigationDirection,
14
+ } from '../accessibility/keyboard/Keyboard'
15
+ import { useController } from '../accessibility/keyboard/useController'
16
+ import type { HTMLElementRef } from '../react/element.d'
17
+ import { useRefCallback } from '../react/useRefCallback'
18
+ import { useRefObject } from '../react/useRefObject'
19
+ import { useUniqueId } from '../react/useUniqueId'
20
20
  import { OverlayContext } from './context'
21
21
  import { useAnchor } from './useAnchor'
22
22
  import { useLightDismiss } from './useLightDismiss'
@@ -149,6 +149,12 @@ export function usePopover<T extends React.HTMLElementType = 'div'>(
149
149
  ref: anchorRef,
150
150
  }
151
151
 
152
+ keyboardProps = {
153
+ ...keyboardProps,
154
+ ref: setKeyboardRef,
155
+ children,
156
+ }
157
+
152
158
  positionedProps = {
153
159
  ...positionedProps,
154
160
  role: positionedProps.role || 'dialog',
@@ -160,21 +166,13 @@ export function usePopover<T extends React.HTMLElementType = 'div'>(
160
166
  ...positionedProps.style,
161
167
  },
162
168
  ref: positionedRef,
169
+ children: createElement(
170
+ OverlayContext,
171
+ { value: overlay },
172
+ createElement(Keyboard, keyboardProps)
173
+ ),
163
174
  }
164
175
 
165
- keyboardProps = {
166
- ...keyboardProps,
167
- ref: setKeyboardRef,
168
- children,
169
- }
170
-
171
- // eslint-disable-next-line react-hooks/refs
172
- positionedProps.children = createElement(
173
- OverlayContext,
174
- { value: overlay },
175
- createElement(Keyboard, keyboardProps)
176
- )
177
-
178
176
  return {
179
177
  overlay,
180
178
  position: positioning.position,
@@ -13,15 +13,20 @@ import {
13
13
  } from '@floating-ui/dom'
14
14
  import { getOppositePlacement, getSide } from '@floating-ui/utils'
15
15
  import { isEqual } from 'lodash-es'
16
- import { useEffect, useLayoutEffect, useRef, useState } from 'react'
16
+ import { useLayoutEffect, useRef, useState } from 'react'
17
17
  import { flushSync } from 'react-dom'
18
- import { refValue, type RefValue } from '../react'
19
- import type { Position } from './useAnchorPositioning'
20
- import {
18
+ import { refValue, type RefValue } from '../react/refValue'
19
+ import type { Position } from './style/positioning.css'
20
+ import { placementMap, positionMap } from './style/positioning.css'
21
+ import { usePositioningOptions } from './useAnchorPositioning'
22
+
23
+ export {
21
24
  placementMap,
25
+ Position,
26
+ positionAreaMap,
27
+ positionAxisMap,
22
28
  positionMap,
23
- usePositioningOptions,
24
- } from './useAnchorPositioning'
29
+ } from './style/positioning.css'
25
30
 
26
31
  export interface PositioningOptions {
27
32
  disabled?: boolean | undefined
@@ -61,22 +66,14 @@ export function usePositioning(
61
66
  arrowRef?: RefValue<HTMLElement> | undefined
62
67
  }
63
68
  ): Positioning {
64
- {
65
- const ref = useRef(_options)
69
+ const [stableOptions, setStableOptions] = useState(_options)
66
70
 
67
- // eslint-disable-next-line react-hooks/refs
68
- if (isEqual(_options, ref.current)) {
69
- // eslint-disable-next-line react-hooks/immutability, react-hooks/refs
70
- _options = ref.current
71
- }
72
-
73
- useEffect(() => {
74
- ref.current = _options
75
- })
71
+ if (!isEqual(_options, stableOptions)) {
72
+ setStableOptions(_options)
76
73
  }
77
74
 
78
- const { anchorRef, positionedRef, arrowRef } = _options
79
- const options = usePositioningOptions(_options)
75
+ const { anchorRef, positionedRef, arrowRef } = stableOptions
76
+ const options = usePositioningOptions(stableOptions)
80
77
  const { position, strategy } = options
81
78
  const [state, setState] = useState<State>({ x: 0, y: 0, position, strategy })
82
79
  const ref = useRef({ state })
@@ -96,7 +93,7 @@ export function usePositioning(
96
93
  const { signal } = (controller = new AbortController())
97
94
 
98
95
  try {
99
- const isRTL = await platform.isRTL(positionedEl) // https://github.com/floating-ui/floating-ui/blob/1b76112bd89dfe1822248e8d6a72c1e73dad8254/packages/core/src/computePosition.ts#L24
96
+ const isRTL = await platform.isRTL(positionedEl) // https://github.com/floating-ui/floating-ui/blob/c3042f1f37d96dfadff1d8894daa31e120d89ed4/packages/core/src/computePosition.ts#L35
100
97
  const placement = resolve(positionMap[options.position], isRTL)
101
98
  const fallbackPlacements = options.fallback.map((position) =>
102
99
  resolve(positionMap[position], isRTL)
@@ -28,8 +28,14 @@ export function useReturnFocus(overlay: Overlay) {
28
28
  }
29
29
  }, [overlay.open])
30
30
 
31
- // See the file "useReturnFocus.test.tsx" for more information,
32
- // the "useLayoutEffect" hook does not work here.
31
+ // React records the active element before its mutation phase and, at the
32
+ // end of that phase, moves focus back to it when focus moved elsewhere
33
+ // and the element is still connected. The 'useLayoutEffect' cleanup of a
34
+ // component deleted during the commit runs inside the mutation phase, so
35
+ // focus it restores is immediately moved back by React. The passive
36
+ // 'useEffect' cleanup runs after the commit, so its restoration survives.
37
+ // See the 'useReturnFocus - unmount while open' test in
38
+ // 'useReturnFocus.browser.test.tsx'.
33
39
  useEffect(() => {
34
40
  const anchor = ref.current.source
35
41
  const { positioned } = ref.current
@@ -70,7 +76,10 @@ export function useReturnFocus(overlay: Overlay) {
70
76
  }
71
77
  }, [overlay.open])
72
78
 
73
- // https://react.dev/link/setstate-in-render
79
+ // The focused element is tracked by the document-level 'focusin' listener
80
+ // above rather than by React state, so the latest value can only be read
81
+ // from the ref. Returning it during render is intentional: consumers use
82
+ // it to know where focus will return.
74
83
  // eslint-disable-next-line react-hooks/refs
75
84
  return ref.current.source
76
85
  }
@@ -1,5 +1,4 @@
1
1
  'use client'
2
- import { useRefObject, useUniqueId } from '#hook'
3
2
  import {
4
3
  cloneElement,
5
4
  useCallback,
@@ -7,16 +6,17 @@ import {
7
6
  useLayoutEffect,
8
7
  useRef,
9
8
  } from 'react'
9
+ import { useRefObject } from '../react/useRefObject'
10
+ import { useUniqueId } from '../react/useUniqueId'
11
+ import { useLightDismiss } from './useLightDismiss'
10
12
  import {
11
- useLightDismiss,
12
13
  useOverlay,
13
- usePositioning,
14
- useReturnFocus,
15
14
  type Overlay,
16
15
  type OverlayAnchorProps,
17
- type PositioningOptions,
18
16
  type ToggleCallback,
19
- } from '.'
17
+ } from './useOverlay'
18
+ import { usePositioning, type PositioningOptions } from './usePositioning'
19
+ import { useReturnFocus } from './useReturnFocus'
20
20
 
21
21
  type TooltipTag = 'div'
22
22
 
@@ -48,7 +48,6 @@ export function useTooltip(options: TooltipOptions) {
48
48
 
49
49
  let anchorProps: OverlayAnchorProps = { ...anchor?.props }
50
50
  let positionedProps: React.JSX.IntrinsicElements[TooltipTag] = { ...props }
51
- let arrowProps: React.ComponentProps<'div'>
52
51
 
53
52
  const _id = useUniqueId('tooltip-')
54
53
  positionedProps.id ||= _id
@@ -237,8 +236,7 @@ export function useTooltip(options: TooltipOptions) {
237
236
  ref: positionedRef,
238
237
  }
239
238
 
240
- // eslint-disable-next-line prefer-const
241
- arrowProps = {
239
+ const arrowProps: React.ComponentProps<'div'> = {
242
240
  style: {
243
241
  ...positioning.arrowStyle,
244
242
  },
@@ -248,6 +246,9 @@ export function useTooltip(options: TooltipOptions) {
248
246
  return {
249
247
  overlay,
250
248
  position: positioning.position,
249
+ // Passing the anchor ref through 'cloneElement' is the standard anchor
250
+ // injection pattern; the rule cannot prove the element is not a function
251
+ // component, so it conservatively flags the ref.
251
252
  // eslint-disable-next-line react-hooks/refs
252
253
  anchor: anchor == null ? null : cloneElement(anchor, anchorProps),
253
254
  positioned: { props: positionedProps },
@@ -43,7 +43,10 @@ export function usePromise<T>(
43
43
  return () => {
44
44
  destroyed = true
45
45
  }
46
- }, [promise, signal?.aborted])
46
+ // Depend on the signal instance, not its 'aborted' state, so the effect
47
+ // re-runs and the callbacks close over the latest signal when it is
48
+ // swapped between renders.
49
+ }, [promise, signal])
47
50
 
48
51
  useEffect(() => {
49
52
  if (error) {
@@ -21,12 +21,19 @@ export function useActivate(onActivate?: ActivateCallback) {
21
21
 
22
22
  const ref = useRef({ isActivated, onActivate })
23
23
 
24
+ // Keep the ref in sync so 'activate' always invokes the latest
25
+ // 'onActivate', not the one captured when 'activate' was memoized.
26
+ useLayoutEffect(() => {
27
+ ref.current.onActivate = onActivate
28
+ })
29
+
24
30
  useLayoutEffect(() => {
25
31
  const handleBlur = (ev: FocusEvent) => {
26
32
  setIsActivated((ref.current.isActivated = false))
27
33
  }
28
34
 
29
- // The 'keyup' event may not have been applied to this element.
35
+ // The 'keyup' may not fire on this element, so watch for it on the
36
+ // document.
30
37
  const handleKeyUp = (ev: KeyboardEvent) => {
31
38
  if (ref.current.isActivated && isSpaceKey(ev)) {
32
39
  setIsActivated((ref.current.isActivated = false))
@@ -1,6 +1,6 @@
1
- import { useMemo } from 'react'
1
+ import { useState } from 'react'
2
2
 
3
3
  export function useConst<T>(initialize: () => T): T {
4
- // eslint-disable-next-line react-hooks/exhaustive-deps, react-hooks/use-memo
5
- return useMemo(initialize, [])
4
+ const [value] = useState(initialize)
5
+ return value
6
6
  }
@@ -13,7 +13,9 @@ export function useRefCallback<T>(ref: Ref<T> | undefined) {
13
13
  if (typeof ref === 'function') {
14
14
  destroy = ref(current)
15
15
  } else if (ref) {
16
- // eslint-disable-next-line react-hooks/immutability
16
+ // Writing to the forwarded 'ref' argument is the purpose of this
17
+ // hook; the rules conservatively forbid mutating hook arguments.
18
+ // eslint-disable-next-line react-hooks/immutability, react-compiler/react-compiler
17
19
  ref.current = current
18
20
  }
19
21