@atlaskit/top-layer 4.4.5 → 5.0.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 +50 -0
- package/README.md +13 -4
- package/dist/cjs/dialog/dialog-content.js +2 -0
- package/dist/cjs/entry-points/use-popover-id.js +5 -10
- package/dist/cjs/internal/anchor-positioning/apply-anchor-positioning.js +86 -0
- package/dist/cjs/internal/anchor-positioning/cross-axis-shift-margins.js +34 -0
- package/dist/cjs/internal/anchor-positioning/edge-margin.js +21 -0
- package/dist/cjs/internal/anchor-positioning/fit-margins.js +77 -0
- package/dist/cjs/internal/anchor-positioning/get-existing-anchor-name.js +18 -0
- package/dist/cjs/internal/{placement-to-position-area.js → anchor-positioning/placement-to-position-area.js} +11 -11
- package/dist/cjs/internal/anchor-positioning/placement-to-try-fallbacks.js +95 -0
- package/dist/cjs/internal/anchored-popover-size.js +345 -0
- package/dist/cjs/internal/get-aria-for-trigger.js +7 -13
- package/dist/cjs/internal/is-native-element-open.js +19 -0
- package/dist/cjs/internal/{anchor-positioning-fallback.js → javascript-fallback/anchor-positioning-fallback.js} +12 -33
- package/dist/cjs/internal/javascript-fallback/apply-javascript-fallback-positioning.js +297 -0
- package/dist/cjs/internal/javascript-fallback/resolve-css-length-to-pixels.js +90 -0
- package/dist/cjs/internal/javascript-fallback/warn-fallback-failure.js +19 -0
- package/dist/cjs/internal/resolve-placement.js +14 -6
- package/dist/cjs/internal/supports-anchor-positioning.js +17 -0
- package/dist/cjs/internal/supports-anchor-size.js +17 -0
- package/dist/cjs/internal/supports-css-declaration.js +25 -0
- package/dist/cjs/internal/surface-reset.js +5 -0
- package/dist/cjs/internal/use-anchored-popover-at-point.js +124 -0
- package/dist/cjs/internal/use-anchored-popover.js +277 -0
- package/dist/cjs/internal/use-animated-visibility.js +11 -23
- package/dist/cjs/popover/popover.compiled.css +4 -0
- package/dist/cjs/popover/popover.js +63 -61
- package/dist/cjs/testing/polyfill.js +6 -7
- package/dist/es2019/dialog/dialog-content.js +2 -0
- package/dist/es2019/entry-points/use-popover-id.js +6 -10
- package/dist/es2019/internal/anchor-positioning/apply-anchor-positioning.js +83 -0
- package/dist/es2019/internal/anchor-positioning/cross-axis-shift-margins.js +29 -0
- package/dist/es2019/internal/anchor-positioning/edge-margin.js +18 -0
- package/dist/es2019/internal/anchor-positioning/fit-margins.js +69 -0
- package/dist/es2019/internal/anchor-positioning/get-existing-anchor-name.js +12 -0
- package/dist/es2019/internal/{placement-to-position-area.js → anchor-positioning/placement-to-position-area.js} +9 -9
- package/dist/es2019/internal/anchor-positioning/placement-to-try-fallbacks.js +94 -0
- package/dist/es2019/internal/anchored-popover-size.js +343 -0
- package/dist/es2019/internal/get-aria-for-trigger.js +7 -13
- package/dist/es2019/internal/is-native-element-open.js +14 -0
- package/dist/es2019/internal/{anchor-positioning-fallback.js → javascript-fallback/anchor-positioning-fallback.js} +12 -33
- package/dist/es2019/internal/javascript-fallback/apply-javascript-fallback-positioning.js +291 -0
- package/dist/es2019/internal/javascript-fallback/resolve-css-length-to-pixels.js +87 -0
- package/dist/es2019/internal/javascript-fallback/warn-fallback-failure.js +14 -0
- package/dist/es2019/internal/resolve-placement.js +14 -6
- package/dist/es2019/internal/supports-anchor-positioning.js +12 -0
- package/dist/es2019/internal/supports-anchor-size.js +12 -0
- package/dist/es2019/internal/supports-css-declaration.js +20 -0
- package/dist/es2019/internal/surface-reset.js +1 -0
- package/dist/es2019/internal/use-anchored-popover-at-point.js +116 -0
- package/dist/es2019/internal/use-anchored-popover.js +265 -0
- package/dist/es2019/internal/use-animated-visibility.js +1 -14
- package/dist/es2019/popover/popover.compiled.css +4 -0
- package/dist/es2019/popover/popover.js +69 -61
- package/dist/es2019/testing/polyfill.js +6 -7
- package/dist/esm/dialog/dialog-content.js +2 -0
- package/dist/esm/entry-points/use-popover-id.js +6 -10
- package/dist/esm/internal/anchor-positioning/apply-anchor-positioning.js +80 -0
- package/dist/esm/internal/anchor-positioning/cross-axis-shift-margins.js +28 -0
- package/dist/esm/internal/anchor-positioning/edge-margin.js +15 -0
- package/dist/esm/internal/anchor-positioning/fit-margins.js +71 -0
- package/dist/esm/internal/anchor-positioning/get-existing-anchor-name.js +12 -0
- package/dist/esm/internal/{placement-to-position-area.js → anchor-positioning/placement-to-position-area.js} +11 -12
- package/dist/esm/internal/anchor-positioning/placement-to-try-fallbacks.js +89 -0
- package/dist/esm/internal/anchored-popover-size.js +338 -0
- package/dist/esm/internal/get-aria-for-trigger.js +7 -13
- package/dist/esm/internal/is-native-element-open.js +13 -0
- package/dist/esm/internal/{anchor-positioning-fallback.js → javascript-fallback/anchor-positioning-fallback.js} +12 -33
- package/dist/esm/internal/javascript-fallback/apply-javascript-fallback-positioning.js +290 -0
- package/dist/esm/internal/javascript-fallback/resolve-css-length-to-pixels.js +85 -0
- package/dist/esm/internal/javascript-fallback/warn-fallback-failure.js +13 -0
- package/dist/esm/internal/resolve-placement.js +14 -6
- package/dist/esm/internal/supports-anchor-positioning.js +12 -0
- package/dist/esm/internal/supports-anchor-size.js +12 -0
- package/dist/esm/internal/supports-css-declaration.js +19 -0
- package/dist/esm/internal/surface-reset.js +1 -0
- package/dist/esm/internal/use-anchored-popover-at-point.js +118 -0
- package/dist/esm/internal/use-anchored-popover.js +271 -0
- package/dist/esm/internal/use-animated-visibility.js +10 -22
- package/dist/esm/popover/popover.compiled.css +4 -0
- package/dist/esm/popover/popover.js +63 -61
- package/dist/esm/testing/polyfill.js +6 -7
- package/dist/types/entry-points/placement-map.d.ts +2 -2
- package/dist/types/entry-points/use-popover-id.d.ts +3 -7
- package/dist/types/internal/anchor-positioning/apply-anchor-positioning.d.ts +26 -0
- package/dist/types/internal/anchor-positioning/cross-axis-shift-margins.d.ts +19 -0
- package/dist/types/internal/anchor-positioning/edge-margin.d.ts +10 -0
- package/dist/types/internal/anchor-positioning/fit-margins.d.ts +30 -0
- package/dist/types/internal/anchor-positioning/get-existing-anchor-name.d.ts +8 -0
- package/dist/types/internal/{placement-to-position-area.d.ts → anchor-positioning/placement-to-position-area.d.ts} +10 -6
- package/dist/types/internal/anchor-positioning/placement-to-try-fallbacks.d.ts +30 -0
- package/dist/types/internal/anchored-popover-size.d.ts +126 -0
- package/dist/types/internal/get-aria-for-trigger.d.ts +13 -25
- package/dist/types/internal/is-native-element-open.d.ts +3 -0
- package/dist/types/internal/javascript-fallback/anchor-positioning-fallback.d.ts +36 -0
- package/dist/types/internal/javascript-fallback/apply-javascript-fallback-positioning.d.ts +15 -0
- package/dist/types/internal/javascript-fallback/resolve-css-length-to-pixels.d.ts +20 -0
- package/dist/types/internal/javascript-fallback/warn-fallback-failure.d.ts +7 -0
- package/dist/types/internal/resolve-placement.d.ts +18 -2
- package/dist/types/internal/supports-anchor-positioning.d.ts +5 -0
- package/dist/types/internal/supports-anchor-size.d.ts +5 -0
- package/dist/types/internal/supports-css-declaration.d.ts +11 -0
- package/dist/types/internal/surface-reset.d.ts +25 -0
- package/dist/types/internal/use-anchored-popover-at-point.d.ts +48 -0
- package/dist/types/internal/use-anchored-popover.d.ts +143 -0
- package/dist/types/popover/index.d.ts +2 -1
- package/dist/types/popover/popover.d.ts +1 -1
- package/dist/types/popover/types.d.ts +15 -17
- package/dist/types/testing/polyfill.d.ts +3 -3
- package/package.json +2 -2
- package/use-anchored-popover/package.json +10 -0
- package/use-anchored-popover-at-point/package.json +10 -0
- package/dist/cjs/internal/placement-to-try-fallbacks.js +0 -108
- package/dist/cjs/internal/resolve-css-length-to-pixels.js +0 -104
- package/dist/cjs/internal/use-anchor-position-at-point.js +0 -129
- package/dist/cjs/internal/use-anchor-position.js +0 -501
- package/dist/cjs/internal/use-width-from-anchor.js +0 -124
- package/dist/es2019/internal/placement-to-try-fallbacks.js +0 -108
- package/dist/es2019/internal/resolve-css-length-to-pixels.js +0 -101
- package/dist/es2019/internal/use-anchor-position-at-point.js +0 -124
- package/dist/es2019/internal/use-anchor-position.js +0 -480
- package/dist/es2019/internal/use-width-from-anchor.js +0 -120
- package/dist/esm/internal/placement-to-try-fallbacks.js +0 -103
- package/dist/esm/internal/resolve-css-length-to-pixels.js +0 -98
- package/dist/esm/internal/use-anchor-position-at-point.js +0 -124
- package/dist/esm/internal/use-anchor-position.js +0 -494
- package/dist/esm/internal/use-width-from-anchor.js +0 -118
- package/dist/types/internal/anchor-positioning-fallback.d.ts +0 -51
- package/dist/types/internal/placement-to-try-fallbacks.d.ts +0 -13
- package/dist/types/internal/resolve-css-length-to-pixels.d.ts +0 -20
- package/dist/types/internal/use-anchor-position-at-point.d.ts +0 -67
- package/dist/types/internal/use-anchor-position.d.ts +0 -87
- package/dist/types/internal/use-width-from-anchor.d.ts +0 -19
- package/use-anchor-position/package.json +0 -10
- package/use-anchor-position-at-point/package.json +0 -10
- package/use-width-from-anchor/package.json +0 -10
|
@@ -13,9 +13,9 @@
|
|
|
13
13
|
* - Popover open state tracked via `data-popover-open` (no `:popover-open` in jsdom).
|
|
14
14
|
* - Auto popovers: maintain an open stack, perform light-dismiss on document mousedown
|
|
15
15
|
* outside the open chain, and dismiss the topmost on Escape.
|
|
16
|
-
* - On open, removes any inline `opacity: 0` from the popover element so
|
|
17
|
-
*
|
|
18
|
-
*
|
|
16
|
+
* - On open, removes any inline `opacity: 0` from the popover element, so the
|
|
17
|
+
* JavaScript positioning fallback's `ResizeObserver` reveal is not needed in
|
|
18
|
+
* jsdom, where its non-zero-layout guard can never pass.
|
|
19
19
|
*
|
|
20
20
|
* Companion `toBeVisible` patch lives at `./to-be-visible`.
|
|
21
21
|
*
|
|
@@ -256,10 +256,9 @@ function stackForMode({
|
|
|
256
256
|
return null;
|
|
257
257
|
}
|
|
258
258
|
|
|
259
|
-
// Polyfill-only. Real browsers reveal the popover
|
|
260
|
-
//
|
|
261
|
-
//
|
|
262
|
-
// the open toggle has fired.
|
|
259
|
+
// Polyfill-only. Real browsers reveal the popover on the first non-zero layout
|
|
260
|
+
// their `ResizeObserver` reports; jsdom always reports 0, so that guard never
|
|
261
|
+
// passes and the inline `opacity: 0` is cleared on the open toggle instead.
|
|
263
262
|
function clearOpacityOnOpenToggle({
|
|
264
263
|
element
|
|
265
264
|
}) {
|
|
@@ -19,9 +19,11 @@ import { useSafariEscapeFix } from '../internal/use-safari-escape-fix';
|
|
|
19
19
|
//
|
|
20
20
|
// KEEP IN SYNC with the identical `surfaceResetStyles` in `popover/popover.tsx`
|
|
21
21
|
// (ADS forbids sharing styles across files, so it is co-located and duplicated).
|
|
22
|
+
// The `satisfies` check below fails the build if either copy drifts.
|
|
22
23
|
var surfaceResetStyles = {
|
|
23
24
|
root: "_lcxv1wug _o5724jg8 _1nmz4jg8 _1i4q4jg8 _y3gnv2br _azhwidpf _1p1dglyw"
|
|
24
25
|
};
|
|
26
|
+
true;
|
|
25
27
|
var dialogStyles = {
|
|
26
28
|
root: "_19itglyw _19pk1wug _2hwx1wug _otyr1wug _18u01wug _1q51ze3t _y4tize3t _85i5ze3t _bozgze3t _p12fglyw _c71lglyw _bfhk1j28",
|
|
27
29
|
motion: "_k8m011k7 _1oeci9qs _1s9z1a5r _1o511hrf _bl8aglyw _156y147i",
|
|
@@ -1,17 +1,13 @@
|
|
|
1
1
|
import { useId } from '@atlaskit/ds-lib/use-id';
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
4
|
+
* A stable `id` for wiring a trigger to its popover: the popover's `id`, and the
|
|
5
|
+
* trigger's matching `aria-controls` / `popovertarget`.
|
|
5
6
|
*
|
|
6
|
-
*
|
|
7
|
-
* for the matching `aria-controls` / `popovertarget` references on the
|
|
8
|
-
* trigger. It is NOT a CSS `anchor-name` value: CSS anchor positioning is
|
|
9
|
-
* handled internally by `useAnchorPosition`, which mints and applies its
|
|
10
|
-
* own `anchor-name` on the trigger element.
|
|
7
|
+
* NOT a CSS `anchor-name` - `useAnchoredPopover` mints and writes its own.
|
|
11
8
|
*/
|
|
12
9
|
export function usePopoverId() {
|
|
13
|
-
// `@atlaskit/ds-lib/use-id
|
|
14
|
-
//
|
|
15
|
-
// tokens. The `popover-` prefix is purely for DOM debug clarity.
|
|
10
|
+
// `@atlaskit/ds-lib/use-id`, not React's `useId`: React's output contains
|
|
11
|
+
// `:`, `«` and `»`, which are invalid in an HTML id token.
|
|
16
12
|
return "popover-".concat(useId());
|
|
17
13
|
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
+
/**
|
|
3
|
+
* The CSS Anchor Positioning path: `position-anchor`, `position-area`,
|
|
4
|
+
* `position-try-fallbacks` and the gap / shift margins, all declared on the
|
|
5
|
+
* popover so the browser owns placement and flipping. The twin of
|
|
6
|
+
* `../javascript-fallback/apply-javascript-fallback-positioning`.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { setStyle } from '../set-style';
|
|
10
|
+
import { crossAxisShiftMargins } from './cross-axis-shift-margins';
|
|
11
|
+
import { edgeMargin } from './edge-margin';
|
|
12
|
+
import { getFitMarginDeclarations } from './fit-margins';
|
|
13
|
+
import { getExistingAnchorName } from './get-existing-anchor-name';
|
|
14
|
+
import { placementToPositionArea } from './placement-to-position-area';
|
|
15
|
+
import { placementToTryFallbacks } from './placement-to-try-fallbacks';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Returns the cleanup.
|
|
19
|
+
*/
|
|
20
|
+
export function applyAnchorPositioning(_ref) {
|
|
21
|
+
var anchor = _ref.anchor,
|
|
22
|
+
popover = _ref.popover,
|
|
23
|
+
placement = _ref.placement,
|
|
24
|
+
sizeStyles = _ref.sizeStyles,
|
|
25
|
+
isFitting = _ref.isFitting,
|
|
26
|
+
fallbackAnchorName = _ref.fallbackAnchorName;
|
|
27
|
+
// Reuse rather than mint: another popover may already be anchored to it, or a
|
|
28
|
+
// CONSUMER may have set it on their own element, as `post-office` does.
|
|
29
|
+
var existingAnchorName = getExistingAnchorName(anchor);
|
|
30
|
+
var anchorName = existingAnchorName !== null && existingAnchorName !== void 0 ? existingAnchorName : fallbackAnchorName;
|
|
31
|
+
var gap = edgeMargin({
|
|
32
|
+
placement: placement,
|
|
33
|
+
offset: placement.offset.gap
|
|
34
|
+
});
|
|
35
|
+
var crossAxisShift = crossAxisShiftMargins({
|
|
36
|
+
placement: placement,
|
|
37
|
+
crossAxisShiftCssValue: placement.offset.crossAxisShift.value,
|
|
38
|
+
direction: placement.offset.crossAxisShift.direction
|
|
39
|
+
});
|
|
40
|
+
var popoverStyles = [{
|
|
41
|
+
property: 'position-anchor',
|
|
42
|
+
value: anchorName
|
|
43
|
+
}, {
|
|
44
|
+
property: 'position-area',
|
|
45
|
+
value: placementToPositionArea({
|
|
46
|
+
placement: placement
|
|
47
|
+
})
|
|
48
|
+
}, {
|
|
49
|
+
property: 'position-try-fallbacks',
|
|
50
|
+
value: placementToTryFallbacks({
|
|
51
|
+
placement: placement
|
|
52
|
+
})
|
|
53
|
+
},
|
|
54
|
+
// Reset browser default popover positioning that conflicts
|
|
55
|
+
// with anchor positioning (UA: `inset: 0; margin: auto;`)
|
|
56
|
+
{
|
|
57
|
+
property: 'margin',
|
|
58
|
+
value: '0'
|
|
59
|
+
}, {
|
|
60
|
+
property: 'inset',
|
|
61
|
+
value: 'auto'
|
|
62
|
+
}, gap].concat(_toConsumableArray(isFitting ? getFitMarginDeclarations({
|
|
63
|
+
placement: placement,
|
|
64
|
+
crossAxisShiftMargins: crossAxisShift
|
|
65
|
+
}) : crossAxisShift), _toConsumableArray(sizeStyles));
|
|
66
|
+
|
|
67
|
+
// Anchor names are never cleaned up: multiple popovers can share an anchor,
|
|
68
|
+
// and even with reference counting an async React update could remove the name
|
|
69
|
+
// while something else still uses it. See
|
|
70
|
+
// `notes/decisions/anchor-name-lifetime.md`. Only written when minted: a name
|
|
71
|
+
// from a stylesheet may be a list, which an inline copy of its first entry
|
|
72
|
+
// would collapse.
|
|
73
|
+
if (existingAnchorName === null) {
|
|
74
|
+
anchor.style.setProperty('anchor-name', anchorName);
|
|
75
|
+
}
|
|
76
|
+
return setStyle({
|
|
77
|
+
element: popover,
|
|
78
|
+
styles: popoverStyles
|
|
79
|
+
});
|
|
80
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The cross-axis shift, written antisymmetrically on BOTH cross-axis sides rather
|
|
3
|
+
* than as one margin. Do not collapse it to one side: a single margin widens the
|
|
4
|
+
* margin box, so `anchor-center` displaces the border box by only half the value,
|
|
5
|
+
* a `<position-area>` fallback sliding across the cross axis drops it entirely,
|
|
6
|
+
* and the widened box changes where the popover is judged to overflow.
|
|
7
|
+
*
|
|
8
|
+
* A positive value always moves the popover toward the cross-axis END, so
|
|
9
|
+
* `direction: 'forwards'` means the same thing for every `align` value. See
|
|
10
|
+
* `notes/decisions/placement-offset.md`.
|
|
11
|
+
*/
|
|
12
|
+
export function crossAxisShiftMargins(_ref) {
|
|
13
|
+
var placement = _ref.placement,
|
|
14
|
+
crossAxisShiftCssValue = _ref.crossAxisShiftCssValue,
|
|
15
|
+
direction = _ref.direction;
|
|
16
|
+
var crossAxis = placement.axis === 'block' ? 'inline' : 'block';
|
|
17
|
+
// `calc()` rather than JavaScript math, so opaque values such as design tokens
|
|
18
|
+
// negate correctly.
|
|
19
|
+
var negated = "calc(-1 * ".concat(crossAxisShiftCssValue, ")");
|
|
20
|
+
var isForwards = direction === 'forwards';
|
|
21
|
+
return [{
|
|
22
|
+
property: "margin-".concat(crossAxis, "-start"),
|
|
23
|
+
value: isForwards ? crossAxisShiftCssValue : negated
|
|
24
|
+
}, {
|
|
25
|
+
property: "margin-".concat(crossAxis, "-end"),
|
|
26
|
+
value: isForwards ? negated : crossAxisShiftCssValue
|
|
27
|
+
}];
|
|
28
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The margin that creates the gap between the popover and its anchor.
|
|
3
|
+
*/
|
|
4
|
+
export function edgeMargin(_ref) {
|
|
5
|
+
var placement = _ref.placement,
|
|
6
|
+
offset = _ref.offset;
|
|
7
|
+
var axis = placement.axis,
|
|
8
|
+
edge = placement.edge;
|
|
9
|
+
// The side FACING the anchor is always opposite the placement edge.
|
|
10
|
+
var anchorFacingEdge = edge === 'end' ? 'start' : 'end';
|
|
11
|
+
return {
|
|
12
|
+
property: "margin-".concat(axis, "-").concat(anchorFacingEdge),
|
|
13
|
+
value: offset
|
|
14
|
+
};
|
|
15
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
+
import { VIEWPORT_PADDING } from '../anchored-popover-size';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Every logical margin property the fit recipe can write. Declared here and
|
|
6
|
+
* imported by `edge-margin.tsx` and `cross-axis-shift-margins.tsx`: two
|
|
7
|
+
* structurally identical declarations are interchangeable to the compiler, so a
|
|
8
|
+
* divergence would surface only as a silently-ignored property name at
|
|
9
|
+
* `setStyle`.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The cross-axis sides that face the viewport rather than the anchor, and so take
|
|
14
|
+
* the reserved padding.
|
|
15
|
+
*
|
|
16
|
+
* A `span-*` cell aligns the popover's MARGIN box to the anchor's edge, so padding
|
|
17
|
+
* on the anchor-facing side does not reserve space at the viewport: it insets the
|
|
18
|
+
* border box from the edge the consumer asked it to line up with. A centred
|
|
19
|
+
* popover has no anchor-facing side, and padding both keeps the shift pair
|
|
20
|
+
* antisymmetric so `anchor-center` still centres.
|
|
21
|
+
*
|
|
22
|
+
* Known cost: the slide fallbacks do not swap the inline margins the way
|
|
23
|
+
* `flip-inline` does, so a slid popover keeps its padding on the anchor side (or,
|
|
24
|
+
* re-centred, sits 2.5px off centre). Alignment in the requested position wins.
|
|
25
|
+
*/
|
|
26
|
+
function viewportFacingCrossAxisSides(_ref) {
|
|
27
|
+
var align = _ref.align;
|
|
28
|
+
if (align === 'center') {
|
|
29
|
+
return ['start', 'end'];
|
|
30
|
+
}
|
|
31
|
+
// `align: 'start'` sits on the anchor's start edge and expands toward end.
|
|
32
|
+
return [align === 'start' ? 'end' : 'start'];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The margin half of the fit recipe. The caps reserve the viewport padding by
|
|
37
|
+
* subtracting it, but nothing makes the reservation land on the viewport side, so
|
|
38
|
+
* a capped popover packs flush against the edge it slid or flipped to.
|
|
39
|
+
*
|
|
40
|
+
* The padding buys visual clearance and nothing else: at the cap the margin box
|
|
41
|
+
* is exactly `100%` of the cell, so these margins never make
|
|
42
|
+
* `position-try-fallbacks` fire. Only the unclamped placement-axis floor does
|
|
43
|
+
* that; see `getPlacementAxisFloor`.
|
|
44
|
+
*
|
|
45
|
+
* The cross-axis sides are composed, not overwritten: they already carry the
|
|
46
|
+
* antisymmetric `crossAxisShift` pair.
|
|
47
|
+
*/
|
|
48
|
+
export function getFitMarginDeclarations(_ref2) {
|
|
49
|
+
var placement = _ref2.placement,
|
|
50
|
+
crossAxisShiftMargins = _ref2.crossAxisShiftMargins;
|
|
51
|
+
var crossAxis = placement.axis === 'block' ? 'inline' : 'block';
|
|
52
|
+
var paddedProperties = new Set(viewportFacingCrossAxisSides({
|
|
53
|
+
align: placement.align
|
|
54
|
+
}).map(function (side) {
|
|
55
|
+
return "margin-".concat(crossAxis, "-").concat(side);
|
|
56
|
+
}));
|
|
57
|
+
return [{
|
|
58
|
+
property: "margin-".concat(placement.axis, "-").concat(placement.edge),
|
|
59
|
+
value: VIEWPORT_PADDING
|
|
60
|
+
}].concat(_toConsumableArray(crossAxisShiftMargins.map(function (_ref3) {
|
|
61
|
+
var property = _ref3.property,
|
|
62
|
+
value = _ref3.value;
|
|
63
|
+
return paddedProperties.has(property) ? {
|
|
64
|
+
property: property,
|
|
65
|
+
value: "calc(".concat(value, " + ").concat(VIEWPORT_PADDING, ")")
|
|
66
|
+
} : {
|
|
67
|
+
property: property,
|
|
68
|
+
value: value
|
|
69
|
+
};
|
|
70
|
+
})));
|
|
71
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `anchor-name` an element already carries, or `null`. Computed as well as
|
|
3
|
+
* inline, so a name set from a STYLESHEET is found: a minted inline name would
|
|
4
|
+
* otherwise override it for every other rule anchored to that element.
|
|
5
|
+
* `anchor-name` is a list and `position-anchor` takes one ident, so the first
|
|
6
|
+
* name is the one to anchor to.
|
|
7
|
+
*/
|
|
8
|
+
export function getExistingAnchorName(element) {
|
|
9
|
+
var declared = element.style.getPropertyValue('anchor-name') || getComputedStyle(element).getPropertyValue('anchor-name');
|
|
10
|
+
var first = declared.split(',')[0].trim();
|
|
11
|
+
return first !== '' && first !== 'none' ? first : null;
|
|
12
|
+
}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { resolvePlacement } from './resolve-placement';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
|
-
* Resolves placement
|
|
2
|
+
* Resolves a placement to CSS `position-area` syntax.
|
|
5
3
|
*
|
|
6
4
|
* The `align` field represents the *visual* alignment:
|
|
7
5
|
* - `align: 'start'` means "aligned to the trigger's start edge" (left in LTR for block axis)
|
|
@@ -12,19 +10,20 @@ import { resolvePlacement } from './resolve-placement';
|
|
|
12
10
|
* Visual start-alignment requires `span-{cross-axis}-end` (expand toward end = start-aligned).
|
|
13
11
|
* This function handles the inversion internally.
|
|
14
12
|
*
|
|
13
|
+
* Takes the RESOLVED placement, which the hook threads through positioning,
|
|
14
|
+
* sizing and margins alike, so nothing here can disagree with them.
|
|
15
|
+
*
|
|
15
16
|
* @example
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
17
|
+
* // For a `block-end` placement, by `align`:
|
|
18
|
+
* // 'center' → 'block-end'
|
|
19
|
+
* // 'start' → 'block-end span-inline-end'
|
|
20
|
+
* // 'end' → 'block-end span-inline-start'
|
|
19
21
|
*/
|
|
20
22
|
export function placementToPositionArea(_ref) {
|
|
21
23
|
var placement = _ref.placement;
|
|
22
|
-
var
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
axis = _resolvePlacement.axis,
|
|
26
|
-
edge = _resolvePlacement.edge,
|
|
27
|
-
align = _resolvePlacement.align;
|
|
24
|
+
var axis = placement.axis,
|
|
25
|
+
edge = placement.edge,
|
|
26
|
+
align = placement.align;
|
|
28
27
|
var edgeValue = "".concat(axis, "-").concat(edge);
|
|
29
28
|
if (align === 'center') {
|
|
30
29
|
return edgeValue;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The placement axis joined to its edge, e.g. `block-end`.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The cells to slide to along one edge, on the cross axis.
|
|
7
|
+
*
|
|
8
|
+
* A try option is only worth listing if its margin box can fit where an earlier
|
|
9
|
+
* one did not, and two options over the SAME cell have the same margin box and
|
|
10
|
+
* the same fit result. That rules out three cells for an aligned placement: the
|
|
11
|
+
* near span on the requested edge IS the base position-area, and on the opposite
|
|
12
|
+
* edge the near and far spans are where `flip-{A}` and the diagonal flip land.
|
|
13
|
+
*
|
|
14
|
+
* A centred placement has no near or far, so it slides to both spans on both
|
|
15
|
+
* edges.
|
|
16
|
+
*/
|
|
17
|
+
function slideOnEdge(_ref) {
|
|
18
|
+
var align = _ref.align,
|
|
19
|
+
edgeKey = _ref.edgeKey,
|
|
20
|
+
crossAxis = _ref.crossAxis,
|
|
21
|
+
isOppositeEdge = _ref.isOppositeEdge;
|
|
22
|
+
if (align === 'center') {
|
|
23
|
+
return ["".concat(edgeKey, " span-").concat(crossAxis, "-end"), "".concat(edgeKey, " span-").concat(crossAxis, "-start")];
|
|
24
|
+
}
|
|
25
|
+
if (isOppositeEdge) {
|
|
26
|
+
return [edgeKey];
|
|
27
|
+
}
|
|
28
|
+
// For `align: 'start'` the popover expands toward `end`, so the far span is
|
|
29
|
+
// `start`; `align: 'end'` mirrors this.
|
|
30
|
+
var far = align === 'start' ? 'start' : 'end';
|
|
31
|
+
return [edgeKey, "".concat(edgeKey, " span-").concat(crossAxis, "-").concat(far)];
|
|
32
|
+
}
|
|
33
|
+
function flipDiagonally(_ref2) {
|
|
34
|
+
var axis = _ref2.axis;
|
|
35
|
+
var flipOnMainAxis = axis === 'block' ? 'flip-block' : 'flip-inline';
|
|
36
|
+
var flipToCrossAxis = axis === 'block' ? 'flip-inline' : 'flip-block';
|
|
37
|
+
return "".concat(flipOnMainAxis, " ").concat(flipToCrossAxis);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Returns the `position-try-fallbacks` value for a RESOLVED placement. The
|
|
42
|
+
* browser tries the entries in order and uses the first one whose margin box
|
|
43
|
+
* fits, so an entry over a cell already tried can never be chosen; `slideOnEdge`
|
|
44
|
+
* explains which ones those are.
|
|
45
|
+
*
|
|
46
|
+
* Centred: slide along the requested edge to either span, flip to the opposite
|
|
47
|
+
* edge, then slide along that edge to either span.
|
|
48
|
+
*
|
|
49
|
+
* Start / end aligned: slide along the requested edge (re-centred, then the far
|
|
50
|
+
* span), flip to the opposite edge keeping the alignment, flip on the diagonal
|
|
51
|
+
* into the opposite corner, then re-centre on the opposite edge. The diagonal is
|
|
52
|
+
* the clean escape when the popover would land off screen on both axes: a flip
|
|
53
|
+
* keyword carries the gap and shift margins across, where a position-area slide
|
|
54
|
+
* leaves them on the original sides.
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* // Centred on the block-end edge (the default placement):
|
|
58
|
+
* placementToTryFallbacks({ placement: resolvePlacement({ placement: {} }) });
|
|
59
|
+
* // => 'block-end span-inline-end, block-end span-inline-start, flip-block,
|
|
60
|
+
* // block-start span-inline-end, block-start span-inline-start'
|
|
61
|
+
*
|
|
62
|
+
* // Start-aligned on the block-end edge:
|
|
63
|
+
* placementToTryFallbacks({ placement: resolvePlacement({ placement: { align: 'start' } }) });
|
|
64
|
+
* // => 'block-end, block-end span-inline-start, flip-block, flip-block flip-inline, block-start'
|
|
65
|
+
*/
|
|
66
|
+
export function placementToTryFallbacks(_ref3) {
|
|
67
|
+
var placement = _ref3.placement;
|
|
68
|
+
var axis = placement.axis,
|
|
69
|
+
edge = placement.edge,
|
|
70
|
+
align = placement.align;
|
|
71
|
+
var crossAxis = axis === 'block' ? 'inline' : 'block';
|
|
72
|
+
var flippedEdge = edge === 'start' ? 'end' : 'start';
|
|
73
|
+
var sameEdgeArea = "".concat(axis, "-").concat(edge);
|
|
74
|
+
var oppositeEdgeArea = "".concat(axis, "-").concat(flippedEdge);
|
|
75
|
+
var flipOnMainAxis = axis === 'block' ? 'flip-block' : 'flip-inline';
|
|
76
|
+
return [slideOnEdge({
|
|
77
|
+
align: align,
|
|
78
|
+
edgeKey: sameEdgeArea,
|
|
79
|
+
crossAxis: crossAxis,
|
|
80
|
+
isOppositeEdge: false
|
|
81
|
+
}), flipOnMainAxis, align !== 'center' ? flipDiagonally({
|
|
82
|
+
axis: axis
|
|
83
|
+
}) : null, slideOnEdge({
|
|
84
|
+
align: align,
|
|
85
|
+
edgeKey: oppositeEdgeArea,
|
|
86
|
+
crossAxis: crossAxis,
|
|
87
|
+
isOppositeEdge: true
|
|
88
|
+
})].filter(Boolean).flat().join(', ');
|
|
89
|
+
}
|