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