@atlaskit/top-layer 0.12.2 → 0.14.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 (245) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/README.md +61 -34
  3. package/dist/cjs/animations/presets.js +4 -4
  4. package/dist/cjs/entry-points/focus.js +6 -4
  5. package/dist/cjs/entry-points/get-aria-for-trigger.js +12 -0
  6. package/dist/cjs/entry-points/popover-surface.js +12 -0
  7. package/dist/cjs/entry-points/use-anchor-position-at-point.js +12 -0
  8. package/dist/cjs/entry-points/use-popover-id.js +21 -0
  9. package/dist/cjs/focus/get-first-focusable.js +19 -0
  10. package/dist/cjs/focus/get-focusables.js +30 -0
  11. package/dist/cjs/focus/get-last-focusable.js +19 -0
  12. package/dist/cjs/focus/get-next-focusable.js +43 -0
  13. package/dist/cjs/focus/is-in-same-layer.js +23 -0
  14. package/dist/cjs/focus/is-nested-layer-focused.js +32 -0
  15. package/dist/cjs/focus/selectors.js +19 -0
  16. package/dist/cjs/focus/types.js +1 -0
  17. package/dist/cjs/internal/get-aria-for-trigger.js +88 -0
  18. package/dist/cjs/internal/role-to-aria-has-popup.js +37 -0
  19. package/dist/cjs/internal/role-types.js +2 -35
  20. package/dist/cjs/internal/should-focus-into-popover.js +19 -0
  21. package/dist/cjs/internal/slot.js +1 -1
  22. package/dist/cjs/internal/use-anchor-position-at-point.js +127 -0
  23. package/dist/cjs/internal/use-anchor-position.js +36 -16
  24. package/dist/cjs/internal/use-focus-wrap.js +8 -5
  25. package/dist/cjs/internal/use-initial-focus.js +4 -4
  26. package/dist/cjs/placement-map/index.js +2 -2
  27. package/dist/cjs/placement-map/legacy-placements.js +2 -101
  28. package/dist/cjs/placement-map/placement-mapping.js +103 -0
  29. package/dist/cjs/popover/popover.js +79 -80
  30. package/dist/cjs/popover-surface/index.js +12 -0
  31. package/dist/cjs/{popup/popup-surface.js → popover-surface/popover-surface.js} +9 -12
  32. package/dist/cjs/testing/polyfill.js +9 -6
  33. package/dist/cjs/use-arrow-navigation/use-arrow-navigation.js +7 -5
  34. package/dist/es2019/animations/presets.js +4 -4
  35. package/dist/es2019/entry-points/focus.js +3 -1
  36. package/dist/es2019/entry-points/get-aria-for-trigger.js +1 -0
  37. package/dist/es2019/entry-points/popover-surface.js +1 -0
  38. package/dist/es2019/entry-points/use-anchor-position-at-point.js +1 -0
  39. package/dist/es2019/entry-points/use-popover-id.js +15 -0
  40. package/dist/es2019/focus/get-first-focusable.js +14 -0
  41. package/dist/es2019/focus/get-focusables.js +19 -0
  42. package/dist/es2019/focus/get-last-focusable.js +14 -0
  43. package/dist/es2019/focus/get-next-focusable.js +38 -0
  44. package/dist/es2019/focus/is-in-same-layer.js +18 -0
  45. package/dist/es2019/focus/is-nested-layer-focused.js +28 -0
  46. package/dist/es2019/focus/selectors.js +11 -0
  47. package/dist/es2019/focus/types.js +0 -0
  48. package/dist/es2019/internal/get-aria-for-trigger.js +84 -0
  49. package/dist/es2019/internal/role-to-aria-has-popup.js +32 -0
  50. package/dist/es2019/internal/role-types.js +0 -33
  51. package/dist/es2019/internal/should-focus-into-popover.js +14 -0
  52. package/dist/es2019/internal/slot.js +1 -1
  53. package/dist/es2019/internal/use-anchor-position-at-point.js +122 -0
  54. package/dist/es2019/internal/use-anchor-position.js +21 -14
  55. package/dist/es2019/internal/use-focus-wrap.js +4 -1
  56. package/dist/es2019/internal/use-initial-focus.js +1 -1
  57. package/dist/es2019/placement-map/index.js +1 -1
  58. package/dist/es2019/placement-map/legacy-placements.js +1 -100
  59. package/dist/es2019/placement-map/placement-mapping.js +97 -0
  60. package/dist/es2019/popover/popover.js +79 -80
  61. package/dist/es2019/popover-surface/index.js +1 -0
  62. package/dist/es2019/popover-surface/popover-surface.js +27 -0
  63. package/dist/es2019/testing/polyfill.js +9 -6
  64. package/dist/es2019/use-arrow-navigation/use-arrow-navigation.js +3 -1
  65. package/dist/esm/animations/presets.js +4 -4
  66. package/dist/esm/entry-points/focus.js +3 -1
  67. package/dist/esm/entry-points/get-aria-for-trigger.js +1 -0
  68. package/dist/esm/entry-points/popover-surface.js +1 -0
  69. package/dist/esm/entry-points/use-anchor-position-at-point.js +1 -0
  70. package/dist/esm/entry-points/use-popover-id.js +15 -0
  71. package/dist/esm/focus/get-first-focusable.js +13 -0
  72. package/dist/esm/focus/get-focusables.js +24 -0
  73. package/dist/esm/focus/get-last-focusable.js +13 -0
  74. package/dist/esm/focus/get-next-focusable.js +37 -0
  75. package/dist/esm/focus/is-in-same-layer.js +17 -0
  76. package/dist/esm/focus/is-nested-layer-focused.js +27 -0
  77. package/dist/esm/focus/selectors.js +13 -0
  78. package/dist/esm/focus/types.js +0 -0
  79. package/dist/esm/internal/get-aria-for-trigger.js +83 -0
  80. package/dist/esm/internal/role-to-aria-has-popup.js +31 -0
  81. package/dist/esm/internal/role-types.js +2 -34
  82. package/dist/esm/internal/should-focus-into-popover.js +13 -0
  83. package/dist/esm/internal/slot.js +1 -1
  84. package/dist/esm/internal/use-anchor-position-at-point.js +122 -0
  85. package/dist/esm/internal/use-anchor-position.js +36 -16
  86. package/dist/esm/internal/use-focus-wrap.js +4 -1
  87. package/dist/esm/internal/use-initial-focus.js +1 -1
  88. package/dist/esm/placement-map/index.js +1 -1
  89. package/dist/esm/placement-map/legacy-placements.js +1 -100
  90. package/dist/esm/placement-map/placement-mapping.js +97 -0
  91. package/dist/esm/popover/popover.js +79 -80
  92. package/dist/esm/popover-surface/index.js +1 -0
  93. package/dist/esm/popover-surface/popover-surface.js +26 -0
  94. package/dist/esm/testing/polyfill.js +9 -6
  95. package/dist/esm/use-arrow-navigation/use-arrow-navigation.js +3 -1
  96. package/dist/types/animations/presets.d.ts +4 -4
  97. package/dist/types/animations/types.d.ts +1 -1
  98. package/dist/types/dialog/types.d.ts +0 -8
  99. package/dist/types/entry-points/focus.d.ts +4 -2
  100. package/dist/types/entry-points/get-aria-for-trigger.d.ts +1 -0
  101. package/dist/types/entry-points/popover-surface.d.ts +2 -0
  102. package/dist/types/entry-points/popover.d.ts +1 -1
  103. package/dist/types/entry-points/use-anchor-position-at-point.d.ts +1 -0
  104. package/dist/types/entry-points/use-popover-id.d.ts +11 -0
  105. package/dist/types/focus/get-first-focusable.d.ts +8 -0
  106. package/dist/types/focus/get-focusables.d.ts +13 -0
  107. package/dist/types/focus/get-last-focusable.d.ts +8 -0
  108. package/dist/types/focus/get-next-focusable.d.ts +13 -0
  109. package/dist/types/focus/is-in-same-layer.d.ts +8 -0
  110. package/dist/types/focus/is-nested-layer-focused.d.ts +8 -0
  111. package/dist/types/focus/selectors.d.ts +4 -0
  112. package/dist/types/focus/types.d.ts +5 -0
  113. package/dist/types/internal/get-aria-for-trigger.d.ts +86 -0
  114. package/dist/types/internal/role-to-aria-has-popup.d.ts +13 -0
  115. package/dist/types/internal/role-types.d.ts +0 -12
  116. package/dist/types/internal/should-focus-into-popover.d.ts +8 -0
  117. package/dist/types/internal/slot.d.ts +2 -2
  118. package/dist/types/internal/use-anchor-position-at-point.d.ts +62 -0
  119. package/dist/types/internal/use-anchor-position.d.ts +6 -1
  120. package/dist/types/placement-map/index.d.ts +1 -1
  121. package/dist/types/placement-map/legacy-placements.d.ts +0 -12
  122. package/dist/types/placement-map/placement-mapping.d.ts +13 -0
  123. package/dist/types/popover/index.d.ts +1 -1
  124. package/dist/types/popover/popover.d.ts +6 -13
  125. package/dist/types/popover/types.d.ts +6 -5
  126. package/dist/types/popover-surface/index.d.ts +2 -0
  127. package/dist/types/popover-surface/popover-surface.d.ts +21 -0
  128. package/dist/types/use-arrow-navigation/use-arrow-navigation.d.ts +1 -1
  129. package/dist/types-ts4.5/animations/presets.d.ts +4 -4
  130. package/dist/types-ts4.5/animations/types.d.ts +1 -1
  131. package/dist/types-ts4.5/dialog/types.d.ts +0 -8
  132. package/dist/types-ts4.5/entry-points/focus.d.ts +4 -2
  133. package/dist/types-ts4.5/entry-points/get-aria-for-trigger.d.ts +1 -0
  134. package/dist/types-ts4.5/entry-points/popover-surface.d.ts +2 -0
  135. package/dist/types-ts4.5/entry-points/popover.d.ts +1 -1
  136. package/dist/types-ts4.5/entry-points/use-anchor-position-at-point.d.ts +1 -0
  137. package/dist/types-ts4.5/entry-points/use-popover-id.d.ts +11 -0
  138. package/dist/types-ts4.5/focus/get-first-focusable.d.ts +8 -0
  139. package/dist/types-ts4.5/focus/get-focusables.d.ts +13 -0
  140. package/dist/types-ts4.5/focus/get-last-focusable.d.ts +8 -0
  141. package/dist/types-ts4.5/focus/get-next-focusable.d.ts +13 -0
  142. package/dist/types-ts4.5/focus/is-in-same-layer.d.ts +8 -0
  143. package/dist/types-ts4.5/focus/is-nested-layer-focused.d.ts +8 -0
  144. package/dist/types-ts4.5/focus/selectors.d.ts +4 -0
  145. package/dist/types-ts4.5/focus/types.d.ts +5 -0
  146. package/dist/types-ts4.5/internal/get-aria-for-trigger.d.ts +86 -0
  147. package/dist/types-ts4.5/internal/role-to-aria-has-popup.d.ts +13 -0
  148. package/dist/types-ts4.5/internal/role-types.d.ts +0 -12
  149. package/dist/types-ts4.5/internal/should-focus-into-popover.d.ts +8 -0
  150. package/dist/types-ts4.5/internal/slot.d.ts +2 -2
  151. package/dist/types-ts4.5/internal/use-anchor-position-at-point.d.ts +62 -0
  152. package/dist/types-ts4.5/internal/use-anchor-position.d.ts +6 -1
  153. package/dist/types-ts4.5/placement-map/index.d.ts +1 -1
  154. package/dist/types-ts4.5/placement-map/legacy-placements.d.ts +0 -12
  155. package/dist/types-ts4.5/placement-map/placement-mapping.d.ts +13 -0
  156. package/dist/types-ts4.5/popover/index.d.ts +1 -1
  157. package/dist/types-ts4.5/popover/popover.d.ts +6 -13
  158. package/dist/types-ts4.5/popover/types.d.ts +6 -5
  159. package/dist/types-ts4.5/popover-surface/index.d.ts +2 -0
  160. package/dist/types-ts4.5/popover-surface/popover-surface.d.ts +21 -0
  161. package/dist/types-ts4.5/use-arrow-navigation/use-arrow-navigation.d.ts +1 -1
  162. package/get-aria-for-trigger/package.json +17 -0
  163. package/package.json +3 -3
  164. package/popover-surface/package.json +17 -0
  165. package/use-anchor-position-at-point/package.json +17 -0
  166. package/use-popover-id/package.json +17 -0
  167. package/dist/cjs/entry-points/popup-surface.js +0 -12
  168. package/dist/cjs/entry-points/popup.js +0 -12
  169. package/dist/cjs/focus/focus.js +0 -169
  170. package/dist/cjs/focus/index.js +0 -24
  171. package/dist/cjs/popup/index.js +0 -37
  172. package/dist/cjs/popup/popup-content.js +0 -214
  173. package/dist/cjs/popup/popup-context.js +0 -25
  174. package/dist/cjs/popup/popup-provider.js +0 -15
  175. package/dist/cjs/popup/popup-trigger-function.js +0 -80
  176. package/dist/cjs/popup/popup-trigger.js +0 -66
  177. package/dist/cjs/popup/popup.js +0 -81
  178. package/dist/cjs/popup/types.js +0 -5
  179. package/dist/cjs/popup/use-maybe-popup-context.js +0 -17
  180. package/dist/cjs/popup/use-popup-context.js +0 -20
  181. package/dist/es2019/entry-points/popup-surface.js +0 -1
  182. package/dist/es2019/entry-points/popup.js +0 -1
  183. package/dist/es2019/focus/focus.js +0 -158
  184. package/dist/es2019/focus/index.js +0 -1
  185. package/dist/es2019/popup/index.js +0 -33
  186. package/dist/es2019/popup/popup-content.js +0 -206
  187. package/dist/es2019/popup/popup-context.js +0 -20
  188. package/dist/es2019/popup/popup-provider.js +0 -10
  189. package/dist/es2019/popup/popup-surface.js +0 -30
  190. package/dist/es2019/popup/popup-trigger-function.js +0 -75
  191. package/dist/es2019/popup/popup-trigger.js +0 -61
  192. package/dist/es2019/popup/popup.js +0 -67
  193. package/dist/es2019/popup/types.js +0 -1
  194. package/dist/es2019/popup/use-maybe-popup-context.js +0 -12
  195. package/dist/es2019/popup/use-popup-context.js +0 -15
  196. package/dist/esm/entry-points/popup-surface.js +0 -1
  197. package/dist/esm/entry-points/popup.js +0 -1
  198. package/dist/esm/focus/focus.js +0 -160
  199. package/dist/esm/focus/index.js +0 -1
  200. package/dist/esm/popup/index.js +0 -33
  201. package/dist/esm/popup/popup-content.js +0 -206
  202. package/dist/esm/popup/popup-context.js +0 -20
  203. package/dist/esm/popup/popup-provider.js +0 -10
  204. package/dist/esm/popup/popup-surface.js +0 -29
  205. package/dist/esm/popup/popup-trigger-function.js +0 -75
  206. package/dist/esm/popup/popup-trigger.js +0 -59
  207. package/dist/esm/popup/popup.js +0 -72
  208. package/dist/esm/popup/types.js +0 -1
  209. package/dist/esm/popup/use-maybe-popup-context.js +0 -12
  210. package/dist/esm/popup/use-popup-context.js +0 -15
  211. package/dist/types/entry-points/popup-surface.d.ts +0 -2
  212. package/dist/types/entry-points/popup.d.ts +0 -2
  213. package/dist/types/focus/focus.d.ts +0 -50
  214. package/dist/types/focus/index.d.ts +0 -2
  215. package/dist/types/popup/index.d.ts +0 -34
  216. package/dist/types/popup/popup-content.d.ts +0 -14
  217. package/dist/types/popup/popup-context.d.ts +0 -96
  218. package/dist/types/popup/popup-provider.d.ts +0 -10
  219. package/dist/types/popup/popup-surface.d.ts +0 -22
  220. package/dist/types/popup/popup-trigger-function.d.ts +0 -112
  221. package/dist/types/popup/popup-trigger.d.ts +0 -14
  222. package/dist/types/popup/popup.d.ts +0 -14
  223. package/dist/types/popup/types.d.ts +0 -321
  224. package/dist/types/popup/use-maybe-popup-context.d.ts +0 -8
  225. package/dist/types/popup/use-popup-context.d.ts +0 -7
  226. package/dist/types-ts4.5/entry-points/popup-surface.d.ts +0 -2
  227. package/dist/types-ts4.5/entry-points/popup.d.ts +0 -2
  228. package/dist/types-ts4.5/focus/focus.d.ts +0 -50
  229. package/dist/types-ts4.5/focus/index.d.ts +0 -2
  230. package/dist/types-ts4.5/popup/index.d.ts +0 -34
  231. package/dist/types-ts4.5/popup/popup-content.d.ts +0 -14
  232. package/dist/types-ts4.5/popup/popup-context.d.ts +0 -96
  233. package/dist/types-ts4.5/popup/popup-provider.d.ts +0 -10
  234. package/dist/types-ts4.5/popup/popup-surface.d.ts +0 -22
  235. package/dist/types-ts4.5/popup/popup-trigger-function.d.ts +0 -112
  236. package/dist/types-ts4.5/popup/popup-trigger.d.ts +0 -14
  237. package/dist/types-ts4.5/popup/popup.d.ts +0 -14
  238. package/dist/types-ts4.5/popup/types.d.ts +0 -321
  239. package/dist/types-ts4.5/popup/use-maybe-popup-context.d.ts +0 -8
  240. package/dist/types-ts4.5/popup/use-popup-context.d.ts +0 -7
  241. package/popup/package.json +0 -17
  242. package/popup-surface/package.json +0 -17
  243. /package/dist/cjs/{popup/popup-surface.compiled.css → popover-surface/popover-surface.compiled.css} +0 -0
  244. /package/dist/es2019/{popup/popup-surface.compiled.css → popover-surface/popover-surface.compiled.css} +0 -0
  245. /package/dist/esm/{popup/popup-surface.compiled.css → popover-surface/popover-surface.compiled.css} +0 -0
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.shouldFocusIntoPopover = shouldFocusIntoPopover;
7
+ var rolesThatMoveFocus = new Set(['dialog', 'alertdialog', 'menu', 'listbox', 'tree', 'grid']);
8
+
9
+ /**
10
+ * Returns `true` when the given popover role moves focus into the popover
11
+ * on open, and `false` otherwise (including when `role` is `undefined`).
12
+ */
13
+ function shouldFocusIntoPopover(_ref) {
14
+ var role = _ref.role;
15
+ if (!role) {
16
+ return false;
17
+ }
18
+ return rolesThatMoveFocus.has(role);
19
+ }
@@ -52,7 +52,7 @@ function isSlotChild(child) {
52
52
  var Slot = exports.Slot = /*#__PURE__*/(0, _react.forwardRef)(function Slot(slotProps, ref) {
53
53
  var rawChildren = slotProps.children,
54
54
  props = (0, _objectWithoutProperties2.default)(slotProps, _excluded);
55
- // `TSlotProps` intersects `Record<string, unknown>`, so `children` is typed as `unknown`.
55
+ // `SlotProps` intersects `Record<string, unknown>`, so `children` is typed as `unknown`.
56
56
  var children = rawChildren;
57
57
  if (!isSlotChild(children)) {
58
58
  return children;
@@ -0,0 +1,127 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useAnchorPositionAtPoint = useAnchorPositionAtPoint;
7
+ var _react = require("react");
8
+ var _useAnchorPosition = require("./use-anchor-position");
9
+ /**
10
+ * A point in viewport coordinates (CSS pixels) at which the synthetic
11
+ * anchor should be placed.
12
+ *
13
+ * Axis-named (`x`/`y`) rather than edge-named (`left`/`top`) so the
14
+ * shape is unambiguous in RTL writing modes — there is no ambiguity
15
+ * about whether a coordinate is logical (`inline-start`/`block-start`)
16
+ * or physical (`left`/`top`). Viewport coordinates are always
17
+ * physical, so we name them with the physical axis labels.
18
+ */
19
+
20
+ /**
21
+ * Styles the synthetic anchor as an invisible, zero-size point.
22
+ * Dynamic `inset-*` overrides are written by the positioning effect.
23
+ *
24
+ * Uses `Object.assign` rather than Compiled CSS (element is outside the React tree)
25
+ * or the internal `setStyle` helper (we own this element entirely — it is created
26
+ * and removed by this hook — so the snapshot/restore semantics `setStyle`
27
+ * provides for caller-owned elements would be dead work here).
28
+ */
29
+ function applyStaticAnchorStyles(el) {
30
+ Object.assign(el.style, {
31
+ position: 'fixed',
32
+ // `top`/`left` rather than `inset-block-start`/`inset-inline-start`
33
+ // for consistency with the dynamic positioning effect below, which
34
+ // uses physical properties (see comment there for the rationale).
35
+ top: '0',
36
+ left: '0',
37
+ // Zero size — placement decides which side the popover sits on.
38
+ width: '0',
39
+ height: '0',
40
+ // Prevent the overlay from intercepting pointer events.
41
+ pointerEvents: 'none'
42
+ });
43
+ }
44
+
45
+ // `useAnchorPosition` requires a real DOM element. When the caller only
46
+ // has a viewport coordinate (e.g. cursor at hover time), this hook
47
+ // manages a hidden `<div>` at that point and delegates the rest.
48
+ //
49
+ // The `<div>` is appended directly to `document.body` to escape any
50
+ // transformed ancestor, which would otherwise break `position: fixed`
51
+ // viewport-relative resolution.
52
+
53
+ /**
54
+ * Positions a popover at a consumer-supplied viewport coordinate using a
55
+ * hidden synthetic anchor.
56
+ *
57
+ * @example
58
+ * ```tsx
59
+ * function PointPositionedPopover({ popoverRef, placement, mousePos }) {
60
+ * useAnchorPositionAtPoint({
61
+ * popoverRef,
62
+ * placement,
63
+ * isEnabled: Boolean(mousePos),
64
+ * getPoint: () => {
65
+ * if (!mousePos) return null;
66
+ * return { x: mousePos.clientX, y: mousePos.clientY };
67
+ * },
68
+ * });
69
+ * return <Popover ref={popoverRef}>...</Popover>;
70
+ * }
71
+ * ```
72
+ */
73
+ function useAnchorPositionAtPoint(_ref) {
74
+ var popoverRef = _ref.popoverRef,
75
+ placement = _ref.placement,
76
+ getPoint = _ref.getPoint,
77
+ _ref$isEnabled = _ref.isEnabled,
78
+ isEnabled = _ref$isEnabled === void 0 ? true : _ref$isEnabled;
79
+ var syntheticAnchorRef = (0, _react.useRef)(null);
80
+
81
+ // `getPoint` is kept in a ref so the layout effect can call the
82
+ // latest version without listing it as a dep — that would re-fire
83
+ // on every render and re-latch the point.
84
+ var getPointRef = (0, _react.useRef)(getPoint);
85
+ getPointRef.current = getPoint;
86
+
87
+ // Lazy element creation: the `<div>` is only created when both
88
+ // `isEnabled` is true AND `getPoint()` returns a non-null point.
89
+ // `useLayoutEffect` ensures the element exists before the inner
90
+ // `useAnchorPosition` (also a layout effect) reads the ref.
91
+ (0, _react.useLayoutEffect)(function () {
92
+ if (!isEnabled) {
93
+ return;
94
+ }
95
+ var point = getPointRef.current();
96
+ if (!point) {
97
+ return;
98
+ }
99
+ var anchor = document.createElement('div');
100
+ anchor.setAttribute('aria-hidden', 'true');
101
+ applyStaticAnchorStyles(anchor);
102
+ // `point.x`/`y` are physical viewport coordinates (from
103
+ // `MouseEvent.clientX/Y`), so map directly onto physical
104
+ // `left`/`top`. This is RTL-safe: `position: fixed` + physical
105
+ // insets is direction-independent. Using logical
106
+ // `inset-inline-start` would need `viewportWidth - point.x` in
107
+ // RTL to land at the same physical pixel.
108
+ anchor.style.top = "".concat(point.y, "px");
109
+ anchor.style.left = "".concat(point.x, "px");
110
+ document.body.appendChild(anchor);
111
+ syntheticAnchorRef.current = anchor;
112
+ return function cleanup() {
113
+ anchor.remove();
114
+ syntheticAnchorRef.current = null;
115
+ };
116
+ }, [isEnabled]);
117
+
118
+ // Mirror `isEnabled` so both hooks stay in sync — when disabled,
119
+ // neither this hook nor the inner one touches the popover, leaving
120
+ // any other positioning the consumer has set up free to take effect.
121
+ (0, _useAnchorPosition.useAnchorPosition)({
122
+ anchorRef: syntheticAnchorRef,
123
+ popoverRef: popoverRef,
124
+ placement: placement,
125
+ isEnabled: isEnabled
126
+ });
127
+ }
@@ -5,6 +5,8 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.useAnchorPosition = useAnchorPosition;
8
+ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
9
+ var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
8
10
  var _react = require("react");
9
11
  var _bindEventListener = require("bind-event-listener");
10
12
  var _rafSchd = _interopRequireDefault(require("raf-schd"));
@@ -35,15 +37,25 @@ var _setStyle = require("./set-style");
35
37
  // from `./resolve-placement` so search-and-jump lands at the source of truth.
36
38
 
37
39
  /**
38
- * Module-scope no-op `ResizeObserver` stub used in non-DOM jest environments where
40
+ * Module-scope no-op `ResizeObserver` used in non-DOM jest environments where
39
41
  * `ResizeObserver` is `undefined`. Hoisted out of the effect to avoid
40
- * re-allocating on every run.
42
+ * allocating a new class declaration on every run.
41
43
  */
42
- var noopResizeObserver = {
43
- observe: function observe() {},
44
- unobserve: function unobserve() {},
45
- disconnect: function disconnect() {}
46
- };
44
+ var NoopResizeObserver = /*#__PURE__*/function () {
45
+ function NoopResizeObserver() {
46
+ (0, _classCallCheck2.default)(this, NoopResizeObserver);
47
+ }
48
+ return (0, _createClass2.default)(NoopResizeObserver, [{
49
+ key: "observe",
50
+ value: function observe() {}
51
+ }, {
52
+ key: "unobserve",
53
+ value: function unobserve() {}
54
+ }, {
55
+ key: "disconnect",
56
+ value: function disconnect() {}
57
+ }]);
58
+ }();
47
59
 
48
60
  /**
49
61
  * Returns true when the popover is currently open. Wrapped because the
@@ -207,12 +219,17 @@ function useAnchorPosition(_ref3) {
207
219
  _ref3$placement = _ref3.placement,
208
220
  placement = _ref3$placement === void 0 ? {} : _ref3$placement,
209
221
  _ref3$forceFallbackPo = _ref3.forceFallbackPositioning,
210
- forceFallbackPositioning = _ref3$forceFallbackPo === void 0 ? false : _ref3$forceFallbackPo;
222
+ forceFallbackPositioning = _ref3$forceFallbackPo === void 0 ? false : _ref3$forceFallbackPo,
223
+ _ref3$isEnabled = _ref3.isEnabled,
224
+ isEnabled = _ref3$isEnabled === void 0 ? true : _ref3$isEnabled;
211
225
  var id = (0, _react.useId)();
212
226
  // Stabilize `placement` object so the same object literal
213
227
  // value returns an object with the same reference
214
228
  var stablePlacement = useStablePlacement(placement);
215
229
  (0, _react.useLayoutEffect)(function () {
230
+ if (!isEnabled) {
231
+ return;
232
+ }
216
233
  var trigger = anchorRef.current;
217
234
  var popover = popoverRef.current;
218
235
  if (!trigger || !popover) {
@@ -402,17 +419,20 @@ function useAnchorPosition(_ref3) {
402
419
  // Self-disconnects after one valid measurement; ongoing
403
420
  // scroll/resize is handled by the window listeners below.
404
421
  // `ResizeObserver` is missing in some non-DOM jest environments
405
- // (e.g. post-office's `node` environment). Fall back to the
406
- // module-scope `noopResizeObserver` stub there. The scroll/resize
407
- // listeners below still keep the popover positioned in the rare
408
- // case the consumer also polyfilled `showPopover` but not
409
- // `ResizeObserver`. Real browsers always have it.
410
- var resizeObserver = typeof ResizeObserver !== 'undefined' ? new ResizeObserver(function () {
422
+ // (e.g. post-office's `node` environment). Fall back to a no-op
423
+ // observer there. The scroll/resize listeners below still keep
424
+ // the popover positioned in the rare case the consumer also
425
+ // polyfilled `showPopover` but not `ResizeObserver`. Real
426
+ // browsers always have it. The `NoopResizeObserver` class is
427
+ // hoisted to module scope (see top of file) so we do not allocate
428
+ // a new constructor on every effect run.
429
+ var ResizeObserverImpl = typeof ResizeObserver !== 'undefined' ? ResizeObserver : NoopResizeObserver;
430
+ var resizeObserver = new ResizeObserverImpl(function () {
411
431
  if (popover.offsetWidth > 0 && popover.offsetHeight > 0) {
412
432
  update();
413
433
  resizeObserver.disconnect();
414
434
  }
415
- }) : noopResizeObserver;
435
+ });
416
436
 
417
437
  // If the popover is already open by the time this effect runs (for
418
438
  // example, the parent `useAnchorPosition` effect runs after the child
@@ -461,5 +481,5 @@ function useAnchorPosition(_ref3) {
461
481
  popover.style.removeProperty('opacity');
462
482
  });
463
483
  return undoPositioning;
464
- }, [anchorRef, popoverRef, stablePlacement, forceFallbackPositioning, id]);
484
+ }, [anchorRef, popoverRef, stablePlacement, forceFallbackPositioning, isEnabled, id]);
465
485
  }
@@ -6,7 +6,10 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.useFocusWrap = useFocusWrap;
7
7
  var _react = require("react");
8
8
  var _bindEventListener = require("bind-event-listener");
9
- var _focus = require("../focus/focus");
9
+ var _getFirstFocusable = require("../focus/get-first-focusable");
10
+ var _getLastFocusable = require("../focus/get-last-focusable");
11
+ var _getNextFocusable = require("../focus/get-next-focusable");
12
+ var _isNestedLayerFocused = require("../focus/is-nested-layer-focused");
10
13
  /**
11
14
  * Roles that require focus wrapping per WAI-ARIA APG.
12
15
  *
@@ -62,7 +65,7 @@ function useFocusWrap(_ref) {
62
65
 
63
66
  // If focus is already in a nested layer, then
64
67
  // we continue to let that nested layer own focus
65
- if ((0, _focus.isNestedLayerFocused)({
68
+ if ((0, _isNestedLayerFocused.isNestedLayerFocused)({
66
69
  container: element
67
70
  })) {
68
71
  return;
@@ -75,7 +78,7 @@ function useFocusWrap(_ref) {
75
78
 
76
79
  // Try to move to the next/previous focusable element relative
77
80
  // to the currently focused element within the container.
78
- var next = (0, _focus.getNextFocusable)({
81
+ var next = (0, _getNextFocusable.getNextFocusable)({
79
82
  container: element,
80
83
  direction: direction
81
84
  });
@@ -87,9 +90,9 @@ function useFocusWrap(_ref) {
87
90
  // Nothing is currently focused inside the container (or the
88
91
  // focused element is not in the focusable list). Fall back to
89
92
  // the first or last focusable element depending on direction.
90
- var fallback = direction === 'forwards' ? (0, _focus.getFirstFocusable)({
93
+ var fallback = direction === 'forwards' ? (0, _getFirstFocusable.getFirstFocusable)({
91
94
  container: element
92
- }) : (0, _focus.getLastFocusable)({
95
+ }) : (0, _getLastFocusable.getLastFocusable)({
93
96
  container: element
94
97
  });
95
98
  if (fallback) {
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.useInitialFocus = useInitialFocus;
7
7
  var _react = require("react");
8
- var _focus = require("../focus/focus");
8
+ var _getFirstFocusable = require("../focus/get-first-focusable");
9
9
  /**
10
10
  * Determines the correct element to receive initial focus within a popover,
11
11
  * based on its ARIA role.
@@ -33,7 +33,7 @@ function getInitialFocusTarget(_ref) {
33
33
  return autofocusEl;
34
34
  }
35
35
  // Fall back to first focusable element
36
- return (0, _focus.getFirstFocusable)({
36
+ return (0, _getFirstFocusable.getFirstFocusable)({
37
37
  container: container
38
38
  });
39
39
  }
@@ -44,7 +44,7 @@ function getInitialFocusTarget(_ref) {
44
44
  // of the consumer component (e.g. dropdown-menu), because menu keyboard
45
45
  // behavior varies by context (orientation, nesting, item type, control
46
46
  // pattern). See: notes/outputs/menu-keyboard-decision.md
47
- return (0, _focus.getFirstFocusable)({
47
+ return (0, _getFirstFocusable.getFirstFocusable)({
48
48
  container: container
49
49
  });
50
50
  }
@@ -54,7 +54,7 @@ function getInitialFocusTarget(_ref) {
54
54
  if (selectedOption) {
55
55
  return selectedOption;
56
56
  }
57
- return (0, _focus.getFirstFocusable)({
57
+ return (0, _getFirstFocusable.getFirstFocusable)({
58
58
  container: container
59
59
  });
60
60
  }
@@ -7,7 +7,7 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.fromLegacyPlacement = fromLegacyPlacement;
8
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
9
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
- var _legacyPlacements = require("./legacy-placements");
10
+ var _placementMapping = require("./placement-mapping");
11
11
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
12
12
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
13
13
  /**
@@ -54,7 +54,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
54
54
  function fromLegacyPlacement(_ref) {
55
55
  var legacy = _ref.legacy,
56
56
  offset = _ref.offset;
57
- var basePlacement = _legacyPlacements.placementMapping[legacy];
57
+ var basePlacement = _placementMapping.placementMapping[legacy];
58
58
  if (!offset) {
59
59
  return basePlacement;
60
60
  }
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.placementMapping = exports.LEGACY_PLACEMENTS = void 0;
6
+ exports.LEGACY_PLACEMENTS = void 0;
7
7
  /**
8
8
  * Legacy Popper.js placement values (used by `@atlaskit/popper`,
9
9
  * `@atlaskit/popup`, `@atlaskit/tooltip`, etc.). Re-exported from
@@ -11,103 +11,4 @@ exports.placementMapping = exports.LEGACY_PLACEMENTS = void 0;
11
11
  * to enumerate every placement (e.g. for a settings dropdown). New code
12
12
  * should use the object-based `TPlacementOptions` directly.
13
13
  */
14
- // eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
15
- var LEGACY_PLACEMENTS = exports.LEGACY_PLACEMENTS = ['auto', 'auto-start', 'auto-end', 'top', 'top-start', 'top-center', 'top-end', 'bottom', 'bottom-start', 'bottom-center', 'bottom-end', 'right', 'right-start', 'right-end', 'left', 'left-start', 'left-end'];
16
- /**
17
- * The full mapping record. Internal - use `fromLegacyPlacement` from the
18
- * public entry-point so the offset-tuple translation is applied consistently.
19
- *
20
- * Note: `auto`, `auto-start`, `auto-end` map to `block-end` placements. This
21
- * is a reduction in expressiveness vs Popper.js (which picked the best
22
- * placement at runtime). CSS `position-try-fallbacks` flips at the edge but
23
- * the initial placement is fixed. Migration consumers who relied on Popper's
24
- * dynamic auto-flip should pick an explicit placement instead.
25
- */
26
- // eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
27
- var placementMapping = exports.placementMapping = {
28
- top: {
29
- axis: 'block',
30
- edge: 'start',
31
- align: 'center'
32
- },
33
- 'top-start': {
34
- axis: 'block',
35
- edge: 'start',
36
- align: 'start'
37
- },
38
- 'top-center': {
39
- axis: 'block',
40
- edge: 'start',
41
- align: 'center'
42
- },
43
- 'top-end': {
44
- axis: 'block',
45
- edge: 'start',
46
- align: 'end'
47
- },
48
- bottom: {
49
- axis: 'block',
50
- edge: 'end',
51
- align: 'center'
52
- },
53
- 'bottom-start': {
54
- axis: 'block',
55
- edge: 'end',
56
- align: 'start'
57
- },
58
- 'bottom-center': {
59
- axis: 'block',
60
- edge: 'end',
61
- align: 'center'
62
- },
63
- 'bottom-end': {
64
- axis: 'block',
65
- edge: 'end',
66
- align: 'end'
67
- },
68
- right: {
69
- axis: 'inline',
70
- edge: 'end',
71
- align: 'center'
72
- },
73
- 'right-start': {
74
- axis: 'inline',
75
- edge: 'end',
76
- align: 'start'
77
- },
78
- 'right-end': {
79
- axis: 'inline',
80
- edge: 'end',
81
- align: 'end'
82
- },
83
- left: {
84
- axis: 'inline',
85
- edge: 'start',
86
- align: 'center'
87
- },
88
- 'left-start': {
89
- axis: 'inline',
90
- edge: 'start',
91
- align: 'start'
92
- },
93
- 'left-end': {
94
- axis: 'inline',
95
- edge: 'start',
96
- align: 'end'
97
- },
98
- auto: {
99
- axis: 'block',
100
- edge: 'end',
101
- align: 'center'
102
- },
103
- 'auto-start': {
104
- axis: 'block',
105
- edge: 'end',
106
- align: 'start'
107
- },
108
- 'auto-end': {
109
- axis: 'block',
110
- edge: 'end',
111
- align: 'end'
112
- }
113
- };
14
+ var LEGACY_PLACEMENTS = exports.LEGACY_PLACEMENTS = ['auto', 'auto-start', 'auto-end', 'top', 'top-start', 'top-center', 'top-end', 'bottom', 'bottom-start', 'bottom-center', 'bottom-end', 'right', 'right-start', 'right-end', 'left', 'left-start', 'left-end'];
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.placementMapping = void 0;
7
+ /**
8
+ * The full mapping record. Internal - use `fromLegacyPlacement` from the
9
+ * public entry-point so the offset-tuple translation is applied consistently.
10
+ *
11
+ * Note: `auto`, `auto-start`, `auto-end` map to `block-end` placements. This
12
+ * is a reduction in expressiveness vs Popper.js (which picked the best
13
+ * placement at runtime). CSS `position-try-fallbacks` flips at the edge but
14
+ * the initial placement is fixed. Migration consumers who relied on Popper's
15
+ * dynamic auto-flip should pick an explicit placement instead.
16
+ */
17
+ var placementMapping = exports.placementMapping = {
18
+ top: {
19
+ axis: 'block',
20
+ edge: 'start',
21
+ align: 'center'
22
+ },
23
+ 'top-start': {
24
+ axis: 'block',
25
+ edge: 'start',
26
+ align: 'start'
27
+ },
28
+ 'top-center': {
29
+ axis: 'block',
30
+ edge: 'start',
31
+ align: 'center'
32
+ },
33
+ 'top-end': {
34
+ axis: 'block',
35
+ edge: 'start',
36
+ align: 'end'
37
+ },
38
+ bottom: {
39
+ axis: 'block',
40
+ edge: 'end',
41
+ align: 'center'
42
+ },
43
+ 'bottom-start': {
44
+ axis: 'block',
45
+ edge: 'end',
46
+ align: 'start'
47
+ },
48
+ 'bottom-center': {
49
+ axis: 'block',
50
+ edge: 'end',
51
+ align: 'center'
52
+ },
53
+ 'bottom-end': {
54
+ axis: 'block',
55
+ edge: 'end',
56
+ align: 'end'
57
+ },
58
+ right: {
59
+ axis: 'inline',
60
+ edge: 'end',
61
+ align: 'center'
62
+ },
63
+ 'right-start': {
64
+ axis: 'inline',
65
+ edge: 'end',
66
+ align: 'start'
67
+ },
68
+ 'right-end': {
69
+ axis: 'inline',
70
+ edge: 'end',
71
+ align: 'end'
72
+ },
73
+ left: {
74
+ axis: 'inline',
75
+ edge: 'start',
76
+ align: 'center'
77
+ },
78
+ 'left-start': {
79
+ axis: 'inline',
80
+ edge: 'start',
81
+ align: 'start'
82
+ },
83
+ 'left-end': {
84
+ axis: 'inline',
85
+ edge: 'start',
86
+ align: 'end'
87
+ },
88
+ auto: {
89
+ axis: 'block',
90
+ edge: 'end',
91
+ align: 'center'
92
+ },
93
+ 'auto-start': {
94
+ axis: 'block',
95
+ edge: 'end',
96
+ align: 'start'
97
+ },
98
+ 'auto-end': {
99
+ axis: 'block',
100
+ edge: 'end',
101
+ align: 'end'
102
+ }
103
+ };