@atlaskit/top-layer 0.12.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.
- package/CHANGELOG.md +8 -0
- package/dist/cjs/entry-points/use-arrow-navigation.js +3 -2
- package/dist/cjs/internal/placement-to-position-area.js +43 -0
- package/dist/cjs/internal/placement-to-try-fallbacks.js +82 -0
- package/dist/cjs/internal/use-anchor-position.js +18 -131
- package/dist/cjs/popup/popup-content.js +2 -2
- package/dist/cjs/popup/popup-context.js +2 -38
- package/dist/cjs/popup/popup-provider.js +15 -0
- package/dist/cjs/popup/popup-trigger-function.js +2 -2
- package/dist/cjs/popup/popup-trigger.js +2 -2
- package/dist/cjs/popup/popup.js +2 -2
- package/dist/cjs/popup/use-maybe-popup-context.js +17 -0
- package/dist/cjs/popup/use-popup-context.js +20 -0
- package/dist/cjs/use-arrow-navigation/index.js +3 -2
- package/dist/cjs/use-arrow-navigation/is-at-current-menu-level.js +87 -0
- package/dist/cjs/use-arrow-navigation/use-arrow-navigation.js +0 -82
- package/dist/es2019/entry-points/use-arrow-navigation.js +2 -1
- package/dist/es2019/internal/placement-to-position-area.js +40 -0
- package/dist/es2019/internal/placement-to-try-fallbacks.js +77 -0
- package/dist/es2019/internal/use-anchor-position.js +2 -116
- package/dist/es2019/popup/popup-content.js +2 -1
- package/dist/es2019/popup/popup-context.js +2 -36
- package/dist/es2019/popup/popup-provider.js +10 -0
- package/dist/es2019/popup/popup-trigger-function.js +1 -1
- package/dist/es2019/popup/popup-trigger.js +2 -1
- package/dist/es2019/popup/popup.js +1 -1
- package/dist/es2019/popup/use-maybe-popup-context.js +12 -0
- package/dist/es2019/popup/use-popup-context.js +15 -0
- package/dist/es2019/use-arrow-navigation/index.js +2 -1
- package/dist/es2019/use-arrow-navigation/is-at-current-menu-level.js +81 -0
- package/dist/es2019/use-arrow-navigation/use-arrow-navigation.js +0 -81
- package/dist/esm/entry-points/use-arrow-navigation.js +2 -1
- package/dist/esm/internal/placement-to-position-area.js +38 -0
- package/dist/esm/internal/placement-to-try-fallbacks.js +76 -0
- package/dist/esm/internal/use-anchor-position.js +16 -127
- package/dist/esm/popup/popup-content.js +2 -1
- package/dist/esm/popup/popup-context.js +2 -36
- package/dist/esm/popup/popup-provider.js +10 -0
- package/dist/esm/popup/popup-trigger-function.js +1 -1
- package/dist/esm/popup/popup-trigger.js +2 -1
- package/dist/esm/popup/popup.js +1 -1
- package/dist/esm/popup/use-maybe-popup-context.js +12 -0
- package/dist/esm/popup/use-popup-context.js +15 -0
- package/dist/esm/use-arrow-navigation/index.js +2 -1
- package/dist/esm/use-arrow-navigation/is-at-current-menu-level.js +81 -0
- package/dist/esm/use-arrow-navigation/use-arrow-navigation.js +0 -81
- package/dist/types/entry-points/use-arrow-navigation.d.ts +2 -1
- package/dist/types/internal/placement-to-position-area.d.ts +21 -0
- package/dist/types/internal/placement-to-try-fallbacks.d.ts +36 -0
- package/dist/types/internal/use-anchor-position.d.ts +0 -55
- package/dist/types/popup/popup-context.d.ts +1 -21
- package/dist/types/popup/popup-provider.d.ts +10 -0
- package/dist/types/popup/use-maybe-popup-context.d.ts +8 -0
- package/dist/types/popup/use-popup-context.d.ts +7 -0
- package/dist/types/use-arrow-navigation/index.d.ts +2 -1
- package/dist/types/use-arrow-navigation/is-at-current-menu-level.d.ts +48 -0
- package/dist/types/use-arrow-navigation/use-arrow-navigation.d.ts +0 -48
- package/dist/types-ts4.5/entry-points/use-arrow-navigation.d.ts +2 -1
- package/dist/types-ts4.5/internal/placement-to-position-area.d.ts +21 -0
- package/dist/types-ts4.5/internal/placement-to-try-fallbacks.d.ts +36 -0
- package/dist/types-ts4.5/internal/use-anchor-position.d.ts +0 -55
- package/dist/types-ts4.5/popup/popup-context.d.ts +1 -21
- package/dist/types-ts4.5/popup/popup-provider.d.ts +10 -0
- package/dist/types-ts4.5/popup/use-maybe-popup-context.d.ts +8 -0
- package/dist/types-ts4.5/popup/use-popup-context.d.ts +7 -0
- package/dist/types-ts4.5/use-arrow-navigation/index.d.ts +2 -1
- package/dist/types-ts4.5/use-arrow-navigation/is-at-current-menu-level.d.ts +48 -0
- package/dist/types-ts4.5/use-arrow-navigation/use-arrow-navigation.d.ts +0 -48
- package/package.json +2 -2
- package/dist/cjs/arrow/index.js +0 -131
- package/dist/cjs/arrow/types.js +0 -5
- package/dist/es2019/arrow/index.js +0 -269
- package/dist/es2019/arrow/types.js +0 -1
- package/dist/esm/arrow/index.js +0 -124
- package/dist/esm/arrow/types.js +0 -1
- package/dist/types/arrow/index.d.ts +0 -24
- package/dist/types/arrow/types.d.ts +0 -29
- package/dist/types-ts4.5/arrow/index.d.ts +0 -24
- package/dist/types-ts4.5/arrow/types.d.ts +0 -29
|
@@ -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(
|
|
196
|
-
var placement =
|
|
197
|
-
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(
|
|
239
|
-
var placement =
|
|
240
|
-
crossAxisShiftCssValue =
|
|
241
|
-
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(
|
|
321
|
-
var anchorRef =
|
|
322
|
-
popoverRef =
|
|
323
|
-
|
|
324
|
-
placement =
|
|
325
|
-
|
|
326
|
-
forceFallbackPositioning =
|
|
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
|
|
@@ -8,7 +8,8 @@ import { roleToAriaHasPopup, shouldFocusIntoPopover } from '../internal/role-typ
|
|
|
8
8
|
import { useAnchorPosition } from '../internal/use-anchor-position';
|
|
9
9
|
import { useWidthFromAnchor } from '../internal/use-width-from-anchor';
|
|
10
10
|
import { Popover } from '../popover/popover';
|
|
11
|
-
import { useMaybePopupContext } from './popup-context';
|
|
11
|
+
import { useMaybePopupContext } from './use-maybe-popup-context';
|
|
12
|
+
|
|
12
13
|
/**
|
|
13
14
|
* Thin context wrapper that composes `Popover` + `useAnchorPosition`.
|
|
14
15
|
*
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createContext
|
|
1
|
+
import { createContext } from 'react';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Represents the lifecycle state of the popup.
|
|
@@ -17,38 +17,4 @@ import { createContext, useContext } from 'react';
|
|
|
17
17
|
* the trigger (and thus the popup anchor) mid-animation.
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
|
-
var PopupContext = /*#__PURE__*/createContext(null);
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* __Popup provider__
|
|
24
|
-
*
|
|
25
|
-
* Provides shared popup state (placement, popoverId, triggerRef,
|
|
26
|
-
* isOpen, onClose) to compound child components such as `Popup.Trigger` and
|
|
27
|
-
* `Popup.Content`.
|
|
28
|
-
*/
|
|
29
|
-
export var PopupProvider = PopupContext.Provider;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Returns the nearest `Popup` context value.
|
|
33
|
-
*
|
|
34
|
-
* Throws if called outside of a `<Popup>` compound component.
|
|
35
|
-
*/
|
|
36
|
-
// eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
|
|
37
|
-
export function usePopupContext() {
|
|
38
|
-
var ctx = useContext(PopupContext);
|
|
39
|
-
if (ctx === null) {
|
|
40
|
-
throw new Error('@atlaskit/top-layer: Popup compound components must be used within <Popup>.');
|
|
41
|
-
}
|
|
42
|
-
return ctx;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Returns the popup context if available, or `null` when used outside `<Popup>`.
|
|
47
|
-
*
|
|
48
|
-
* Used by `PopupContent` to support standalone usage (e.g. tooltip)
|
|
49
|
-
* where values are passed as props instead of coming from a compound component.
|
|
50
|
-
*/
|
|
51
|
-
// eslint-disable-next-line @atlaskit/volt-strict-mode/no-multiple-exports
|
|
52
|
-
export function useMaybePopupContext() {
|
|
53
|
-
return useContext(PopupContext);
|
|
54
|
-
}
|
|
20
|
+
export var PopupContext = /*#__PURE__*/createContext(null);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { PopupContext } from './popup-context';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* __Popup provider__
|
|
5
|
+
*
|
|
6
|
+
* Provides shared popup state (placement, popoverId, triggerRef,
|
|
7
|
+
* isOpen, onClose) to compound child components such as `Popup.Trigger` and
|
|
8
|
+
* `Popup.Content`.
|
|
9
|
+
*/
|
|
10
|
+
export var PopupProvider = PopupContext.Provider;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React, { isValidElement, useCallback } from 'react';
|
|
2
2
|
import { Slot } from '../internal/slot';
|
|
3
|
-
import { usePopupContext } from './popup-context';
|
|
3
|
+
import { usePopupContext } from './use-popup-context';
|
|
4
|
+
|
|
4
5
|
/**
|
|
5
6
|
* Wraps a single trigger element via `cloneElement`. Attaches aria
|
|
6
7
|
* attributes, the toggle handler, and the anchor-name. `aria-haspopup`
|
package/dist/esm/popup/popup.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
2
|
import React, { useCallback, useId, useRef, useState } from 'react';
|
|
3
|
-
import { PopupProvider } from './popup-
|
|
3
|
+
import { PopupProvider } from './popup-provider';
|
|
4
4
|
/**
|
|
5
5
|
* Popup compound: trigger + popover content.
|
|
6
6
|
*
|
|
@@ -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
|
+
var 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
|
|
1
|
+
export { useArrowNavigation } from './use-arrow-navigation';
|
|
2
|
+
export { isAtCurrentMenuLevel } from './is-at-current-menu-level';
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
var 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
|
+
var 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
|
+
var 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
|
var 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
|
-
var 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
|
-
var 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(_ref) {
|
|
140
59
|
var containerRef = _ref.containerRef,
|
|
141
60
|
onClose = _ref.onClose,
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export { useArrowNavigation
|
|
1
|
+
export { useArrowNavigation } from '../use-arrow-navigation';
|
|
2
2
|
export type { TUseArrowNavigationArgs } from '../use-arrow-navigation';
|
|
3
|
+
export { isAtCurrentMenuLevel } from '../use-arrow-navigation/is-at-current-menu-level';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type TPlacementOptions } from '../internal/resolve-placement';
|
|
2
|
+
/**
|
|
3
|
+
* Resolves placement options to CSS `position-area` syntax.
|
|
4
|
+
*
|
|
5
|
+
* The `align` field represents the *visual* alignment:
|
|
6
|
+
* - `align: 'start'` means "aligned to the trigger's start edge" (left in LTR for block axis)
|
|
7
|
+
* - `align: 'end'` means "aligned to the trigger's end edge"
|
|
8
|
+
* - `align: 'center'` means centered (single-axis position-area)
|
|
9
|
+
*
|
|
10
|
+
* CSS `position-area` uses `span-*` keywords which indicate the *expansion direction*.
|
|
11
|
+
* Visual start-alignment requires `span-{cross-axis}-end` (expand toward end = start-aligned).
|
|
12
|
+
* This function handles the inversion internally.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* placementToPositionArea({ placement: { axis: 'block', edge: 'end', align: 'center' } }) // → 'block-end'
|
|
16
|
+
* placementToPositionArea({ placement: { axis: 'block', edge: 'end', align: 'start' } }) // → 'block-end span-inline-end'
|
|
17
|
+
* placementToPositionArea({ placement: { axis: 'block', edge: 'end', align: 'end' } }) // → 'block-end span-inline-start'
|
|
18
|
+
*/
|
|
19
|
+
export declare function placementToPositionArea({ placement }: {
|
|
20
|
+
placement: TPlacementOptions;
|
|
21
|
+
}): string;
|