@atlaskit/top-layer 0.11.0 → 0.12.1

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 (96) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/cjs/animations/presets.js +5 -0
  3. package/dist/cjs/entry-points/use-arrow-navigation.js +3 -2
  4. package/dist/cjs/internal/placement-to-position-area.js +43 -0
  5. package/dist/cjs/internal/placement-to-try-fallbacks.js +82 -0
  6. package/dist/cjs/internal/use-anchor-position.js +18 -131
  7. package/dist/cjs/internal/use-animated-visibility.js +84 -7
  8. package/dist/cjs/popover/popover.js +2 -0
  9. package/dist/cjs/popup/popup-content.js +55 -15
  10. package/dist/cjs/popup/popup-context.js +14 -33
  11. package/dist/cjs/popup/popup-provider.js +15 -0
  12. package/dist/cjs/popup/popup-trigger-function.js +9 -6
  13. package/dist/cjs/popup/popup-trigger.js +14 -9
  14. package/dist/cjs/popup/popup.js +7 -7
  15. package/dist/cjs/popup/use-maybe-popup-context.js +17 -0
  16. package/dist/cjs/popup/use-popup-context.js +20 -0
  17. package/dist/cjs/use-arrow-navigation/index.js +3 -2
  18. package/dist/cjs/use-arrow-navigation/is-at-current-menu-level.js +87 -0
  19. package/dist/cjs/use-arrow-navigation/use-arrow-navigation.js +0 -82
  20. package/dist/es2019/animations/presets.js +5 -0
  21. package/dist/es2019/entry-points/use-arrow-navigation.js +2 -1
  22. package/dist/es2019/internal/placement-to-position-area.js +40 -0
  23. package/dist/es2019/internal/placement-to-try-fallbacks.js +77 -0
  24. package/dist/es2019/internal/use-anchor-position.js +2 -116
  25. package/dist/es2019/internal/use-animated-visibility.js +84 -7
  26. package/dist/es2019/popover/popover.js +2 -0
  27. package/dist/es2019/popup/popup-content.js +55 -14
  28. package/dist/es2019/popup/popup-context.js +14 -30
  29. package/dist/es2019/popup/popup-provider.js +10 -0
  30. package/dist/es2019/popup/popup-trigger-function.js +8 -5
  31. package/dist/es2019/popup/popup-trigger.js +14 -8
  32. package/dist/es2019/popup/popup.js +4 -4
  33. package/dist/es2019/popup/use-maybe-popup-context.js +12 -0
  34. package/dist/es2019/popup/use-popup-context.js +15 -0
  35. package/dist/es2019/use-arrow-navigation/index.js +2 -1
  36. package/dist/es2019/use-arrow-navigation/is-at-current-menu-level.js +81 -0
  37. package/dist/es2019/use-arrow-navigation/use-arrow-navigation.js +0 -81
  38. package/dist/esm/animations/presets.js +5 -0
  39. package/dist/esm/entry-points/use-arrow-navigation.js +2 -1
  40. package/dist/esm/internal/placement-to-position-area.js +38 -0
  41. package/dist/esm/internal/placement-to-try-fallbacks.js +76 -0
  42. package/dist/esm/internal/use-anchor-position.js +16 -127
  43. package/dist/esm/internal/use-animated-visibility.js +84 -7
  44. package/dist/esm/popover/popover.js +2 -0
  45. package/dist/esm/popup/popup-content.js +55 -14
  46. package/dist/esm/popup/popup-context.js +14 -30
  47. package/dist/esm/popup/popup-provider.js +10 -0
  48. package/dist/esm/popup/popup-trigger-function.js +8 -5
  49. package/dist/esm/popup/popup-trigger.js +14 -8
  50. package/dist/esm/popup/popup.js +6 -6
  51. package/dist/esm/popup/use-maybe-popup-context.js +12 -0
  52. package/dist/esm/popup/use-popup-context.js +15 -0
  53. package/dist/esm/use-arrow-navigation/index.js +2 -1
  54. package/dist/esm/use-arrow-navigation/is-at-current-menu-level.js +81 -0
  55. package/dist/esm/use-arrow-navigation/use-arrow-navigation.js +0 -81
  56. package/dist/types/animations/types.d.ts +5 -1
  57. package/dist/types/entry-points/use-arrow-navigation.d.ts +2 -1
  58. package/dist/types/internal/placement-to-position-area.d.ts +21 -0
  59. package/dist/types/internal/placement-to-try-fallbacks.d.ts +36 -0
  60. package/dist/types/internal/use-anchor-position.d.ts +0 -55
  61. package/dist/types/internal/use-animated-visibility.d.ts +8 -2
  62. package/dist/types/popover/types.d.ts +8 -0
  63. package/dist/types/popup/popup-context.d.ts +25 -25
  64. package/dist/types/popup/popup-provider.d.ts +10 -0
  65. package/dist/types/popup/types.d.ts +12 -0
  66. package/dist/types/popup/use-maybe-popup-context.d.ts +8 -0
  67. package/dist/types/popup/use-popup-context.d.ts +7 -0
  68. package/dist/types/use-arrow-navigation/index.d.ts +2 -1
  69. package/dist/types/use-arrow-navigation/is-at-current-menu-level.d.ts +48 -0
  70. package/dist/types/use-arrow-navigation/use-arrow-navigation.d.ts +0 -48
  71. package/dist/types-ts4.5/animations/types.d.ts +5 -1
  72. package/dist/types-ts4.5/entry-points/use-arrow-navigation.d.ts +2 -1
  73. package/dist/types-ts4.5/internal/placement-to-position-area.d.ts +21 -0
  74. package/dist/types-ts4.5/internal/placement-to-try-fallbacks.d.ts +36 -0
  75. package/dist/types-ts4.5/internal/use-anchor-position.d.ts +0 -55
  76. package/dist/types-ts4.5/internal/use-animated-visibility.d.ts +8 -2
  77. package/dist/types-ts4.5/popover/types.d.ts +8 -0
  78. package/dist/types-ts4.5/popup/popup-context.d.ts +25 -25
  79. package/dist/types-ts4.5/popup/popup-provider.d.ts +10 -0
  80. package/dist/types-ts4.5/popup/types.d.ts +12 -0
  81. package/dist/types-ts4.5/popup/use-maybe-popup-context.d.ts +8 -0
  82. package/dist/types-ts4.5/popup/use-popup-context.d.ts +7 -0
  83. package/dist/types-ts4.5/use-arrow-navigation/index.d.ts +2 -1
  84. package/dist/types-ts4.5/use-arrow-navigation/is-at-current-menu-level.d.ts +48 -0
  85. package/dist/types-ts4.5/use-arrow-navigation/use-arrow-navigation.d.ts +0 -48
  86. package/package.json +2 -2
  87. package/dist/cjs/arrow/index.js +0 -131
  88. package/dist/cjs/arrow/types.js +0 -5
  89. package/dist/es2019/arrow/index.js +0 -269
  90. package/dist/es2019/arrow/types.js +0 -1
  91. package/dist/esm/arrow/index.js +0 -124
  92. package/dist/esm/arrow/types.js +0 -1
  93. package/dist/types/arrow/index.d.ts +0 -24
  94. package/dist/types/arrow/types.d.ts +0 -29
  95. package/dist/types-ts4.5/arrow/index.d.ts +0 -24
  96. package/dist/types-ts4.5/arrow/types.d.ts +0 -29
@@ -1,5 +1,5 @@
1
1
  import React, { useCallback, useId, useRef, useState } from 'react';
2
- import { PopupProvider } from './popup-context';
2
+ import { PopupProvider } from './popup-provider';
3
3
  /**
4
4
  * Popup compound: trigger + popover content.
5
5
  *
@@ -36,7 +36,7 @@ export function PopupRoot(props) {
36
36
  const popoverId = `popover-${sanitizedId}`;
37
37
  const triggerRef = useRef(null);
38
38
  const popoverRef = useRef(null);
39
- const [isOpen, setIsOpen] = useState(false);
39
+ const [popupState, setPopupState] = useState('closed');
40
40
  // Initial seed before `Popup.Content`'s layout effect resolves the
41
41
  // real role on first paint.
42
42
  const [ariaHasPopup, setAriaHasPopup] = useState('dialog');
@@ -52,8 +52,8 @@ export function PopupRoot(props) {
52
52
  onClose: onClose ? handleClose : null,
53
53
  triggerRef,
54
54
  popoverRef,
55
- isOpen,
56
- setIsOpen,
55
+ popupState,
56
+ setPopupState,
57
57
  onOpenChange,
58
58
  mode,
59
59
  ariaHasPopup,
@@ -0,0 +1,12 @@
1
+ import { useContext } from 'react';
2
+ import { PopupContext } from './popup-context';
3
+
4
+ /**
5
+ * Returns the popup context if available, or `null` when used outside `<Popup>`.
6
+ *
7
+ * Used by `PopupContent` to support standalone usage (e.g. tooltip)
8
+ * where values are passed as props instead of coming from a compound component.
9
+ */
10
+ export function useMaybePopupContext() {
11
+ return useContext(PopupContext);
12
+ }
@@ -0,0 +1,15 @@
1
+ import { useContext } from 'react';
2
+ import { PopupContext } from './popup-context';
3
+
4
+ /**
5
+ * Returns the nearest `Popup` context value.
6
+ *
7
+ * Throws if called outside of a `<Popup>` compound component.
8
+ */
9
+ export function usePopupContext() {
10
+ const ctx = useContext(PopupContext);
11
+ if (ctx === null) {
12
+ throw new Error('@atlaskit/top-layer: Popup compound components must be used within <Popup>.');
13
+ }
14
+ return ctx;
15
+ }
@@ -1 +1,2 @@
1
- export { useArrowNavigation, isAtCurrentMenuLevel } from './use-arrow-navigation';
1
+ export { useArrowNavigation } from './use-arrow-navigation';
2
+ export { isAtCurrentMenuLevel } from './is-at-current-menu-level';
@@ -0,0 +1,81 @@
1
+ const menuScope = '[role="menu"]';
2
+
3
+ /**
4
+ * Returns true if the element belongs to the current menu level of the
5
+ * container, i.e. it is NOT inside a nested `role="menu"` sub-container.
6
+ *
7
+ * Uses `element.closest('[role="menu"]')` to determine the nearest menu
8
+ * scope. If the nearest scope is the container's own `role="menu"` element,
9
+ * the element belongs to this level. If it is a different (nested) menu,
10
+ * the element belongs to a child level and should be excluded.
11
+ *
12
+ * Supports two container patterns:
13
+ *
14
+ * **1. Container has `role="menu"` directly** (preferred, used by avatar-group):
15
+ * ```
16
+ * <div ref={containerRef} role="menu">
17
+ * <button role="menuitem" /> ← isAtCurrentMenuLevel → true
18
+ * <div role="menu"> ← nested sub-menu
19
+ * <button role="menuitem" /> ← isAtCurrentMenuLevel → false
20
+ * </div>
21
+ * </div>
22
+ * ```
23
+ * Uses the simple check: `element.closest('[role="menu"]') === container`
24
+ *
25
+ * **2. Container is a wrapper without `role="menu"`** (used by dropdown-menu,
26
+ * where `MenuGroup` owns `role="menu"` but does not accept a ref):
27
+ * ```
28
+ * <div ref={containerRef}> ← wrapper (no role="menu")
29
+ * <MenuGroup role="menu">
30
+ * <button role="menuitem" /> ← isAtCurrentMenuLevel → true
31
+ * <div role="menu"> ← nested sub-menu
32
+ * <button role="menuitem" /> ← isAtCurrentMenuLevel → false
33
+ * </div>
34
+ * </MenuGroup>
35
+ * </div>
36
+ * ```
37
+ * Falls back to walking the DOM to check that the element's closest
38
+ * `role="menu"` is the container's own menu (not doubly nested).
39
+ *
40
+ * Ideally all consumers should use pattern 1 (place the ref directly on the
41
+ * `role="menu"` element). Pattern 2 exists because `@atlaskit/menu`'s
42
+ * `MenuGroup` does not currently accept a ref. If `MenuGroup` gains ref
43
+ * support in the future, dropdown-menu should switch to pattern 1 and the
44
+ * fallback path can be removed.
45
+ *
46
+ * Used both as a `TFocusableFilter` (to scope getNextFocusable etc.) and as
47
+ * a guard to prevent parent menu handlers from acting on events that
48
+ * belong to a nested menu.
49
+ */
50
+ export function isAtCurrentMenuLevel(element, container) {
51
+ const closestMenu = element.closest(menuScope);
52
+
53
+ // Container itself has role="menu". Element belongs to this level
54
+ // if its closest menu is the container.
55
+ if (container.getAttribute('role') === 'menu') {
56
+ return closestMenu === container;
57
+ }
58
+
59
+ // Container is a wrapper without role="menu" (e.g. dropdown-menu
60
+ // wraps a MenuGroup). The element belongs to the top level if its
61
+ // closest role="menu" ancestor is a direct child of the container,
62
+ // i.e. there is no nested role="menu" between them.
63
+ if (closestMenu === null) {
64
+ return true;
65
+ }
66
+
67
+ // Walk up from the closest menu to see if it is "owned" by this
68
+ // container without passing through another role="menu" first.
69
+ let parent = closestMenu.parentElement;
70
+ while (parent && parent !== container) {
71
+ if (parent.getAttribute('role') === 'menu') {
72
+ // There is a parent menu between the closest menu and the
73
+ // container, so the element is in a nested sub-menu.
74
+ return false;
75
+ }
76
+ parent = parent.parentElement;
77
+ }
78
+
79
+ // The closest menu is directly inside the container (no nesting).
80
+ return parent === container;
81
+ }
@@ -5,86 +5,6 @@ import { KEY_DOWN, KEY_END, KEY_HOME, KEY_TAB, KEY_UP } from '@atlaskit/ds-lib/k
5
5
  import { getFirstFocusable, getLastFocusable, getNextFocusable } from '../focus';
6
6
  const menuScope = '[role="menu"]';
7
7
 
8
- /**
9
- * Returns true if the element belongs to the current menu level of the
10
- * container, i.e. it is NOT inside a nested `role="menu"` sub-container.
11
- *
12
- * Uses `element.closest('[role="menu"]')` to determine the nearest menu
13
- * scope. If the nearest scope is the container's own `role="menu"` element,
14
- * the element belongs to this level. If it is a different (nested) menu,
15
- * the element belongs to a child level and should be excluded.
16
- *
17
- * Supports two container patterns:
18
- *
19
- * **1. Container has `role="menu"` directly** (preferred, used by avatar-group):
20
- * ```
21
- * <div ref={containerRef} role="menu">
22
- * <button role="menuitem" /> ← isAtCurrentMenuLevel → true
23
- * <div role="menu"> ← nested sub-menu
24
- * <button role="menuitem" /> ← isAtCurrentMenuLevel → false
25
- * </div>
26
- * </div>
27
- * ```
28
- * Uses the simple check: `element.closest('[role="menu"]') === container`
29
- *
30
- * **2. Container is a wrapper without `role="menu"`** (used by dropdown-menu,
31
- * where `MenuGroup` owns `role="menu"` but does not accept a ref):
32
- * ```
33
- * <div ref={containerRef}> ← wrapper (no role="menu")
34
- * <MenuGroup role="menu">
35
- * <button role="menuitem" /> ← isAtCurrentMenuLevel → true
36
- * <div role="menu"> ← nested sub-menu
37
- * <button role="menuitem" /> ← isAtCurrentMenuLevel → false
38
- * </div>
39
- * </MenuGroup>
40
- * </div>
41
- * ```
42
- * Falls back to walking the DOM to check that the element's closest
43
- * `role="menu"` is the container's own menu (not doubly nested).
44
- *
45
- * Ideally all consumers should use pattern 1 (place the ref directly on the
46
- * `role="menu"` element). Pattern 2 exists because `@atlaskit/menu`'s
47
- * `MenuGroup` does not currently accept a ref. If `MenuGroup` gains ref
48
- * support in the future, dropdown-menu should switch to pattern 1 and the
49
- * fallback path can be removed.
50
- *
51
- * Used both as a `TFocusableFilter` (to scope getNextFocusable etc.) and as
52
- * a guard to prevent parent menu handlers from acting on events that
53
- * belong to a nested menu.
54
- */
55
- export function isAtCurrentMenuLevel(element, container) {
56
- const closestMenu = element.closest(menuScope);
57
-
58
- // Container itself has role="menu". Element belongs to this level
59
- // if its closest menu is the container.
60
- if (container.getAttribute('role') === 'menu') {
61
- return closestMenu === container;
62
- }
63
-
64
- // Container is a wrapper without role="menu" (e.g. dropdown-menu
65
- // wraps a MenuGroup). The element belongs to the top level if its
66
- // closest role="menu" ancestor is a direct child of the container,
67
- // i.e. there is no nested role="menu" between them.
68
- if (closestMenu === null) {
69
- return true;
70
- }
71
-
72
- // Walk up from the closest menu to see if it is "owned" by this
73
- // container without passing through another role="menu" first.
74
- let parent = closestMenu.parentElement;
75
- while (parent && parent !== container) {
76
- if (parent.getAttribute('role') === 'menu') {
77
- // There is a parent menu between the closest menu and the
78
- // container, so the element is in a nested sub-menu.
79
- return false;
80
- }
81
- parent = parent.parentElement;
82
- }
83
-
84
- // The closest menu is directly inside the container (no nesting).
85
- return parent === container;
86
- }
87
-
88
8
  /**
89
9
  * Args for `useArrowNavigation`.
90
10
  *
@@ -135,7 +55,6 @@ export function isAtCurrentMenuLevel(element, container) {
135
55
  * });
136
56
  * ```
137
57
  */
138
- // eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
139
58
  export function useArrowNavigation({
140
59
  containerRef,
141
60
  onClose,
@@ -77,6 +77,7 @@ export function slideAndFade(options) {
77
77
  distance: distance
78
78
  });
79
79
  },
80
+ enterDurationMs: 350,
80
81
  exitDurationMs: 175
81
82
  };
82
83
  }
@@ -102,6 +103,7 @@ export function fade() {
102
103
  return {
103
104
  name: 'fade',
104
105
  css: FADE_CSS,
106
+ enterDurationMs: 350,
105
107
  exitDurationMs: 175
106
108
  };
107
109
  }
@@ -127,6 +129,7 @@ export function scaleAndFade() {
127
129
  return {
128
130
  name: 'scale-and-fade',
129
131
  css: SCALE_AND_FADE_CSS,
132
+ enterDurationMs: 350,
130
133
  exitDurationMs: 175
131
134
  };
132
135
  }
@@ -166,6 +169,7 @@ export function dialogSlideUpAndFade(options) {
166
169
  return {
167
170
  name: distance === 12 ? 'slide-up-and-fade' : "slide-up-and-fade-".concat(distance),
168
171
  css: distance === 12 ? DIALOG_SLIDE_UP_AND_FADE_CSS : DIALOG_SLIDE_UP_AND_FADE_CSS.replace(/12px/g, "".concat(distance, "px")),
172
+ enterDurationMs: 350,
169
173
  exitDurationMs: 175
170
174
  };
171
175
  }
@@ -194,6 +198,7 @@ export function dialogFade() {
194
198
  return {
195
199
  name: 'fade',
196
200
  css: DIALOG_FADE_CSS,
201
+ enterDurationMs: 350,
197
202
  exitDurationMs: 175
198
203
  };
199
204
  }
@@ -1 +1,2 @@
1
- export { useArrowNavigation, isAtCurrentMenuLevel } from '../use-arrow-navigation';
1
+ export { useArrowNavigation } from '../use-arrow-navigation';
2
+ export { isAtCurrentMenuLevel } from '../use-arrow-navigation/is-at-current-menu-level';
@@ -0,0 +1,38 @@
1
+ import { getPlacement } from './resolve-placement';
2
+
3
+ /**
4
+ * Resolves placement options to CSS `position-area` syntax.
5
+ *
6
+ * The `align` field represents the *visual* alignment:
7
+ * - `align: 'start'` means "aligned to the trigger's start edge" (left in LTR for block axis)
8
+ * - `align: 'end'` means "aligned to the trigger's end edge"
9
+ * - `align: 'center'` means centered (single-axis position-area)
10
+ *
11
+ * CSS `position-area` uses `span-*` keywords which indicate the *expansion direction*.
12
+ * Visual start-alignment requires `span-{cross-axis}-end` (expand toward end = start-aligned).
13
+ * This function handles the inversion internally.
14
+ *
15
+ * @example
16
+ * placementToPositionArea({ placement: { axis: 'block', edge: 'end', align: 'center' } }) // → 'block-end'
17
+ * placementToPositionArea({ placement: { axis: 'block', edge: 'end', align: 'start' } }) // → 'block-end span-inline-end'
18
+ * placementToPositionArea({ placement: { axis: 'block', edge: 'end', align: 'end' } }) // → 'block-end span-inline-start'
19
+ */
20
+ export function placementToPositionArea(_ref) {
21
+ var placement = _ref.placement;
22
+ var _getPlacement = getPlacement({
23
+ placement: placement
24
+ }),
25
+ axis = _getPlacement.axis,
26
+ edge = _getPlacement.edge,
27
+ align = _getPlacement.align;
28
+ var edgeValue = "".concat(axis, "-").concat(edge);
29
+ if (align === 'center') {
30
+ return edgeValue;
31
+ }
32
+
33
+ // Cross-axis name: block ↔ inline
34
+ var crossAxis = axis === 'block' ? 'inline' : 'block';
35
+ // Invert align → CSS span direction: visual 'start' → span toward 'end'
36
+ var spanDir = align === 'start' ? 'end' : 'start';
37
+ return "".concat(edgeValue, " span-").concat(crossAxis, "-").concat(spanDir);
38
+ }
@@ -0,0 +1,76 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
+ import { getPlacement } from './resolve-placement';
3
+
4
+ /**
5
+ * Returns `position-try-fallbacks` value based on placement.
6
+ *
7
+ * For centered placements, includes cross-axis aligned position-area
8
+ * values so the browser can shift the popover along the cross-axis
9
+ * when the centered position would overflow the viewport edge.
10
+ *
11
+ * Fallback order for centered placements (e.g. `block-end`):
12
+ * 1. Same edge, start-aligned (shift for near-edge overflow)
13
+ * 2. Same edge, end-aligned (shift for far-edge overflow)
14
+ * 3. Flipped edge, centered
15
+ * 4. Flipped edge, start-aligned
16
+ * 5. Flipped edge, end-aligned
17
+ *
18
+ * For aligned placements (start/end), includes the same-edge centered
19
+ * position as fallbacks so the browser can try centering when the aligned
20
+ * position would overflow, before flipping to the opposite edge.
21
+ *
22
+ * **Why `flip-inline flip-block` (or `flip-block flip-inline`) is included:**
23
+ *
24
+ * When a popup is in a viewport corner (e.g. inline-end align-end at the
25
+ * top-right), flipping only the primary axis (`flip-inline`) moves the popup
26
+ * to the left but keeps the same cross-axis span direction (e.g. upward),
27
+ * which is still off-screen. The combined keyword `flip-inline flip-block`
28
+ * mirrors the popup diagonally. It flips BOTH the position-area AND both
29
+ * inline and block margins simultaneously, placing the popup at the
30
+ * diagonally opposite corner where there is always space.
31
+ *
32
+ * Named `position-area` entries (e.g. `inline-start span-block-end`) in
33
+ * `position-try-fallbacks` do NOT update margins, so only the `flip-*`
34
+ * tactic keywords correctly flip the gap margin along with the position.
35
+ */
36
+ export function placementToTryFallbacks(_ref) {
37
+ var placement = _ref.placement;
38
+ var _getPlacement = getPlacement({
39
+ placement: placement
40
+ }),
41
+ axis = _getPlacement.axis,
42
+ edge = _getPlacement.edge,
43
+ align = _getPlacement.align;
44
+ var crossAxis = axis === 'block' ? 'inline' : 'block';
45
+ var flippedEdge = edge === 'start' ? 'end' : 'start';
46
+ var sameEdge = "".concat(axis, "-").concat(edge);
47
+ var oppositeEdge = "".concat(axis, "-").concat(flippedEdge);
48
+ var flipKeyword = axis === 'block' ? 'flip-block' : 'flip-inline';
49
+ var flipCrossKeyword = axis === 'block' ? 'flip-inline' : 'flip-block';
50
+
51
+ // Single algorithm: produce the shift list against any base alignment.
52
+ // For `align: 'start'` the "near" shift expands toward `end`; for
53
+ // `align: 'end'` it expands toward `start`; for `align: 'center'`
54
+ // either order is symmetric (we use end-then-start to match the
55
+ // historical fallback list).
56
+ function shifts(baseAlign, edgeKey) {
57
+ if (baseAlign === 'center') {
58
+ return ["".concat(edgeKey, " span-").concat(crossAxis, "-end"), "".concat(edgeKey, " span-").concat(crossAxis, "-start")];
59
+ }
60
+ var near = baseAlign === 'start' ? 'end' : 'start';
61
+ var far = baseAlign === 'start' ? 'start' : 'end';
62
+ return ["".concat(edgeKey, " span-").concat(crossAxis, "-").concat(near), edgeKey, "".concat(edgeKey, " span-").concat(crossAxis, "-").concat(far)];
63
+ }
64
+ if (align !== 'center') {
65
+ // Aligned (start/end): try same-edge shifts, then single-axis flip,
66
+ // then diagonal flip for corner overflow, then opposite-edge shifts.
67
+ // Legacy Popper fallback ordering for e.g. bottom-start:
68
+ // [bottom, bottom-end, top-start, top, top-end, auto].
69
+ return [].concat(_toConsumableArray(shifts(align, sameEdge)), [flipKeyword, "".concat(flipKeyword, " ").concat(flipCrossKeyword)], _toConsumableArray(shifts(align, oppositeEdge))).join(', ');
70
+ }
71
+
72
+ // Centered: same-edge shifts, single-axis flip, opposite-edge shifts.
73
+ // Diagonal flip is unnecessary because centered placements expand
74
+ // equally in both cross-axis directions.
75
+ return [].concat(_toConsumableArray(shifts('center', sameEdge)), [flipKeyword], _toConsumableArray(shifts('center', oppositeEdge))).join(', ');
76
+ }
@@ -1,4 +1,3 @@
1
- import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
1
  import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
3
2
  import _createClass from "@babel/runtime/helpers/createClass";
4
3
  /**
@@ -21,6 +20,8 @@ import rafSchedule from 'raf-schd';
21
20
  import once from '@atlaskit/ds-lib/once';
22
21
  import { computeFallbackPosition } from './anchor-positioning-fallback';
23
22
  import { combine } from './combine';
23
+ import { placementToPositionArea } from './placement-to-position-area';
24
+ import { placementToTryFallbacks } from './placement-to-try-fallbacks';
24
25
  import { resolveCssLengthToPixels } from './resolve-css-length-to-pixels';
25
26
  import { getPlacement } from './resolve-placement';
26
27
  import { setStyle } from './set-style';
@@ -49,118 +50,6 @@ var NoopResizeObserver = /*#__PURE__*/function () {
49
50
  }]);
50
51
  }();
51
52
 
52
- /**
53
- * Resolves placement options to CSS `position-area` syntax.
54
- *
55
- * The `align` field represents the *visual* alignment:
56
- * - `align: 'start'` means "aligned to the trigger's start edge" (left in LTR for block axis)
57
- * - `align: 'end'` means "aligned to the trigger's end edge"
58
- * - `align: 'center'` means centered (single-axis position-area)
59
- *
60
- * CSS `position-area` uses `span-*` keywords which indicate the *expansion direction*.
61
- * Visual start-alignment requires `span-{cross-axis}-end` (expand toward end = start-aligned).
62
- * This function handles the inversion internally.
63
- *
64
- * @example
65
- * placementToPositionArea({ placement: { axis: 'block', edge: 'end', align: 'center' } }) // → 'block-end'
66
- * placementToPositionArea({ placement: { axis: 'block', edge: 'end', align: 'start' } }) // → 'block-end span-inline-end'
67
- * placementToPositionArea({ placement: { axis: 'block', edge: 'end', align: 'end' } }) // → 'block-end span-inline-start'
68
- */
69
- export function placementToPositionArea(_ref) {
70
- var placement = _ref.placement;
71
- var _getPlacement = getPlacement({
72
- placement: placement
73
- }),
74
- axis = _getPlacement.axis,
75
- edge = _getPlacement.edge,
76
- align = _getPlacement.align;
77
- var edgeValue = "".concat(axis, "-").concat(edge);
78
- if (align === 'center') {
79
- return edgeValue;
80
- }
81
-
82
- // Cross-axis name: block ↔ inline
83
- var crossAxis = axis === 'block' ? 'inline' : 'block';
84
- // Invert align → CSS span direction: visual 'start' → span toward 'end'
85
- var spanDir = align === 'start' ? 'end' : 'start';
86
- return "".concat(edgeValue, " span-").concat(crossAxis, "-").concat(spanDir);
87
- }
88
-
89
- /**
90
- * Returns `position-try-fallbacks` value based on placement.
91
- *
92
- * For centered placements, includes cross-axis aligned position-area
93
- * values so the browser can shift the popover along the cross-axis
94
- * when the centered position would overflow the viewport edge.
95
- *
96
- * Fallback order for centered placements (e.g. `block-end`):
97
- * 1. Same edge, start-aligned (shift for near-edge overflow)
98
- * 2. Same edge, end-aligned (shift for far-edge overflow)
99
- * 3. Flipped edge, centered
100
- * 4. Flipped edge, start-aligned
101
- * 5. Flipped edge, end-aligned
102
- *
103
- * For aligned placements (start/end), includes the same-edge centered
104
- * position as fallbacks so the browser can try centering when the aligned
105
- * position would overflow, before flipping to the opposite edge.
106
- *
107
- * **Why `flip-inline flip-block` (or `flip-block flip-inline`) is included:**
108
- *
109
- * When a popup is in a viewport corner (e.g. inline-end align-end at the
110
- * top-right), flipping only the primary axis (`flip-inline`) moves the popup
111
- * to the left but keeps the same cross-axis span direction (e.g. upward),
112
- * which is still off-screen. The combined keyword `flip-inline flip-block`
113
- * mirrors the popup diagonally. It flips BOTH the position-area AND both
114
- * inline and block margins simultaneously, placing the popup at the
115
- * diagonally opposite corner where there is always space.
116
- *
117
- * Named `position-area` entries (e.g. `inline-start span-block-end`) in
118
- * `position-try-fallbacks` do NOT update margins, so only the `flip-*`
119
- * tactic keywords correctly flip the gap margin along with the position.
120
- */
121
- // eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
122
- export function placementToTryFallbacks(_ref2) {
123
- var placement = _ref2.placement;
124
- var _getPlacement2 = getPlacement({
125
- placement: placement
126
- }),
127
- axis = _getPlacement2.axis,
128
- edge = _getPlacement2.edge,
129
- align = _getPlacement2.align;
130
- var crossAxis = axis === 'block' ? 'inline' : 'block';
131
- var flippedEdge = edge === 'start' ? 'end' : 'start';
132
- var sameEdge = "".concat(axis, "-").concat(edge);
133
- var oppositeEdge = "".concat(axis, "-").concat(flippedEdge);
134
- var flipKeyword = axis === 'block' ? 'flip-block' : 'flip-inline';
135
- var flipCrossKeyword = axis === 'block' ? 'flip-inline' : 'flip-block';
136
-
137
- // Single algorithm: produce the shift list against any base alignment.
138
- // For `align: 'start'` the "near" shift expands toward `end`; for
139
- // `align: 'end'` it expands toward `start`; for `align: 'center'`
140
- // either order is symmetric (we use end-then-start to match the
141
- // historical fallback list).
142
- function shifts(baseAlign, edgeKey) {
143
- if (baseAlign === 'center') {
144
- return ["".concat(edgeKey, " span-").concat(crossAxis, "-end"), "".concat(edgeKey, " span-").concat(crossAxis, "-start")];
145
- }
146
- var near = baseAlign === 'start' ? 'end' : 'start';
147
- var far = baseAlign === 'start' ? 'start' : 'end';
148
- return ["".concat(edgeKey, " span-").concat(crossAxis, "-").concat(near), edgeKey, "".concat(edgeKey, " span-").concat(crossAxis, "-").concat(far)];
149
- }
150
- if (align !== 'center') {
151
- // Aligned (start/end): try same-edge shifts, then single-axis flip,
152
- // then diagonal flip for corner overflow, then opposite-edge shifts.
153
- // Legacy Popper fallback ordering for e.g. bottom-start:
154
- // [bottom, bottom-end, top-start, top, top-end, auto].
155
- return [].concat(_toConsumableArray(shifts(align, sameEdge)), [flipKeyword, "".concat(flipKeyword, " ").concat(flipCrossKeyword)], _toConsumableArray(shifts(align, oppositeEdge))).join(', ');
156
- }
157
-
158
- // Centered: same-edge shifts, single-axis flip, opposite-edge shifts.
159
- // Diagonal flip is unnecessary because centered placements expand
160
- // equally in both cross-axis directions.
161
- return [].concat(_toConsumableArray(shifts('center', sameEdge)), [flipKeyword], _toConsumableArray(shifts('center', oppositeEdge))).join(', ');
162
- }
163
-
164
53
  /**
165
54
  * Returns true when the popover is currently open. Wrapped because the
166
55
  * `:popover-open` pseudo-class is not implemented in some test environments
@@ -192,9 +81,9 @@ var supportsAnchorPositioning = once(function () {
192
81
  * For example, a `block-end` placement (popover below) gets
193
82
  * `margin-block-start: 8px` to push it away from the trigger's bottom edge.
194
83
  */
195
- function edgeMargin(_ref3) {
196
- var placement = _ref3.placement,
197
- offset = _ref3.offset;
84
+ function edgeMargin(_ref) {
85
+ var placement = _ref.placement,
86
+ offset = _ref.offset;
198
87
  var axis = placement.axis,
199
88
  edge = placement.edge;
200
89
  var value = offset;
@@ -235,10 +124,10 @@ function edgeMargin(_ref3) {
235
124
  * positive), `align: 'center'` uses START. Margin on the un-anchored side
236
125
  * has no effect under CSS Anchor Positioning.
237
126
  */
238
- function crossAxisShiftMargin(_ref4) {
239
- var placement = _ref4.placement,
240
- crossAxisShiftCssValue = _ref4.crossAxisShiftCssValue,
241
- direction = _ref4.direction;
127
+ function crossAxisShiftMargin(_ref2) {
128
+ var placement = _ref2.placement,
129
+ crossAxisShiftCssValue = _ref2.crossAxisShiftCssValue,
130
+ direction = _ref2.direction;
242
131
  var axis = placement.axis,
243
132
  align = placement.align;
244
133
  var directionSign = direction === 'forwards' ? 1 : -1;
@@ -317,13 +206,13 @@ function useStablePlacement(placement) {
317
206
  * placement shape is unchanged.
318
207
  */
319
208
  // eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
320
- export function useAnchorPosition(_ref5) {
321
- var anchorRef = _ref5.anchorRef,
322
- popoverRef = _ref5.popoverRef,
323
- _ref5$placement = _ref5.placement,
324
- placement = _ref5$placement === void 0 ? {} : _ref5$placement,
325
- _ref5$forceFallbackPo = _ref5.forceFallbackPositioning,
326
- forceFallbackPositioning = _ref5$forceFallbackPo === void 0 ? false : _ref5$forceFallbackPo;
209
+ export function useAnchorPosition(_ref3) {
210
+ var anchorRef = _ref3.anchorRef,
211
+ popoverRef = _ref3.popoverRef,
212
+ _ref3$placement = _ref3.placement,
213
+ placement = _ref3$placement === void 0 ? {} : _ref3$placement,
214
+ _ref3$forceFallbackPo = _ref3.forceFallbackPositioning,
215
+ forceFallbackPositioning = _ref3$forceFallbackPo === void 0 ? false : _ref3$forceFallbackPo;
327
216
  var id = useId();
328
217
  // Stabilize `placement` object so the same object literal
329
218
  // value returns an object with the same reference