@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.
Files changed (137) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/README.md +13 -4
  3. package/dist/cjs/dialog/dialog-content.js +2 -0
  4. package/dist/cjs/entry-points/use-popover-id.js +5 -10
  5. package/dist/cjs/internal/anchor-positioning/apply-anchor-positioning.js +86 -0
  6. package/dist/cjs/internal/anchor-positioning/cross-axis-shift-margins.js +34 -0
  7. package/dist/cjs/internal/anchor-positioning/edge-margin.js +21 -0
  8. package/dist/cjs/internal/anchor-positioning/fit-margins.js +77 -0
  9. package/dist/cjs/internal/anchor-positioning/get-existing-anchor-name.js +18 -0
  10. package/dist/cjs/internal/{placement-to-position-area.js → anchor-positioning/placement-to-position-area.js} +11 -11
  11. package/dist/cjs/internal/anchor-positioning/placement-to-try-fallbacks.js +95 -0
  12. package/dist/cjs/internal/anchored-popover-size.js +345 -0
  13. package/dist/cjs/internal/get-aria-for-trigger.js +7 -13
  14. package/dist/cjs/internal/is-native-element-open.js +19 -0
  15. package/dist/cjs/internal/{anchor-positioning-fallback.js → javascript-fallback/anchor-positioning-fallback.js} +12 -33
  16. package/dist/cjs/internal/javascript-fallback/apply-javascript-fallback-positioning.js +297 -0
  17. package/dist/cjs/internal/javascript-fallback/resolve-css-length-to-pixels.js +90 -0
  18. package/dist/cjs/internal/javascript-fallback/warn-fallback-failure.js +19 -0
  19. package/dist/cjs/internal/resolve-placement.js +14 -6
  20. package/dist/cjs/internal/supports-anchor-positioning.js +17 -0
  21. package/dist/cjs/internal/supports-anchor-size.js +17 -0
  22. package/dist/cjs/internal/supports-css-declaration.js +25 -0
  23. package/dist/cjs/internal/surface-reset.js +5 -0
  24. package/dist/cjs/internal/use-anchored-popover-at-point.js +124 -0
  25. package/dist/cjs/internal/use-anchored-popover.js +277 -0
  26. package/dist/cjs/internal/use-animated-visibility.js +11 -23
  27. package/dist/cjs/popover/popover.compiled.css +4 -0
  28. package/dist/cjs/popover/popover.js +63 -61
  29. package/dist/cjs/testing/polyfill.js +6 -7
  30. package/dist/es2019/dialog/dialog-content.js +2 -0
  31. package/dist/es2019/entry-points/use-popover-id.js +6 -10
  32. package/dist/es2019/internal/anchor-positioning/apply-anchor-positioning.js +83 -0
  33. package/dist/es2019/internal/anchor-positioning/cross-axis-shift-margins.js +29 -0
  34. package/dist/es2019/internal/anchor-positioning/edge-margin.js +18 -0
  35. package/dist/es2019/internal/anchor-positioning/fit-margins.js +69 -0
  36. package/dist/es2019/internal/anchor-positioning/get-existing-anchor-name.js +12 -0
  37. package/dist/es2019/internal/{placement-to-position-area.js → anchor-positioning/placement-to-position-area.js} +9 -9
  38. package/dist/es2019/internal/anchor-positioning/placement-to-try-fallbacks.js +94 -0
  39. package/dist/es2019/internal/anchored-popover-size.js +343 -0
  40. package/dist/es2019/internal/get-aria-for-trigger.js +7 -13
  41. package/dist/es2019/internal/is-native-element-open.js +14 -0
  42. package/dist/es2019/internal/{anchor-positioning-fallback.js → javascript-fallback/anchor-positioning-fallback.js} +12 -33
  43. package/dist/es2019/internal/javascript-fallback/apply-javascript-fallback-positioning.js +291 -0
  44. package/dist/es2019/internal/javascript-fallback/resolve-css-length-to-pixels.js +87 -0
  45. package/dist/es2019/internal/javascript-fallback/warn-fallback-failure.js +14 -0
  46. package/dist/es2019/internal/resolve-placement.js +14 -6
  47. package/dist/es2019/internal/supports-anchor-positioning.js +12 -0
  48. package/dist/es2019/internal/supports-anchor-size.js +12 -0
  49. package/dist/es2019/internal/supports-css-declaration.js +20 -0
  50. package/dist/es2019/internal/surface-reset.js +1 -0
  51. package/dist/es2019/internal/use-anchored-popover-at-point.js +116 -0
  52. package/dist/es2019/internal/use-anchored-popover.js +265 -0
  53. package/dist/es2019/internal/use-animated-visibility.js +1 -14
  54. package/dist/es2019/popover/popover.compiled.css +4 -0
  55. package/dist/es2019/popover/popover.js +69 -61
  56. package/dist/es2019/testing/polyfill.js +6 -7
  57. package/dist/esm/dialog/dialog-content.js +2 -0
  58. package/dist/esm/entry-points/use-popover-id.js +6 -10
  59. package/dist/esm/internal/anchor-positioning/apply-anchor-positioning.js +80 -0
  60. package/dist/esm/internal/anchor-positioning/cross-axis-shift-margins.js +28 -0
  61. package/dist/esm/internal/anchor-positioning/edge-margin.js +15 -0
  62. package/dist/esm/internal/anchor-positioning/fit-margins.js +71 -0
  63. package/dist/esm/internal/anchor-positioning/get-existing-anchor-name.js +12 -0
  64. package/dist/esm/internal/{placement-to-position-area.js → anchor-positioning/placement-to-position-area.js} +11 -12
  65. package/dist/esm/internal/anchor-positioning/placement-to-try-fallbacks.js +89 -0
  66. package/dist/esm/internal/anchored-popover-size.js +338 -0
  67. package/dist/esm/internal/get-aria-for-trigger.js +7 -13
  68. package/dist/esm/internal/is-native-element-open.js +13 -0
  69. package/dist/esm/internal/{anchor-positioning-fallback.js → javascript-fallback/anchor-positioning-fallback.js} +12 -33
  70. package/dist/esm/internal/javascript-fallback/apply-javascript-fallback-positioning.js +290 -0
  71. package/dist/esm/internal/javascript-fallback/resolve-css-length-to-pixels.js +85 -0
  72. package/dist/esm/internal/javascript-fallback/warn-fallback-failure.js +13 -0
  73. package/dist/esm/internal/resolve-placement.js +14 -6
  74. package/dist/esm/internal/supports-anchor-positioning.js +12 -0
  75. package/dist/esm/internal/supports-anchor-size.js +12 -0
  76. package/dist/esm/internal/supports-css-declaration.js +19 -0
  77. package/dist/esm/internal/surface-reset.js +1 -0
  78. package/dist/esm/internal/use-anchored-popover-at-point.js +118 -0
  79. package/dist/esm/internal/use-anchored-popover.js +271 -0
  80. package/dist/esm/internal/use-animated-visibility.js +10 -22
  81. package/dist/esm/popover/popover.compiled.css +4 -0
  82. package/dist/esm/popover/popover.js +63 -61
  83. package/dist/esm/testing/polyfill.js +6 -7
  84. package/dist/types/entry-points/placement-map.d.ts +2 -2
  85. package/dist/types/entry-points/use-popover-id.d.ts +3 -7
  86. package/dist/types/internal/anchor-positioning/apply-anchor-positioning.d.ts +26 -0
  87. package/dist/types/internal/anchor-positioning/cross-axis-shift-margins.d.ts +19 -0
  88. package/dist/types/internal/anchor-positioning/edge-margin.d.ts +10 -0
  89. package/dist/types/internal/anchor-positioning/fit-margins.d.ts +30 -0
  90. package/dist/types/internal/anchor-positioning/get-existing-anchor-name.d.ts +8 -0
  91. package/dist/types/internal/{placement-to-position-area.d.ts → anchor-positioning/placement-to-position-area.d.ts} +10 -6
  92. package/dist/types/internal/anchor-positioning/placement-to-try-fallbacks.d.ts +30 -0
  93. package/dist/types/internal/anchored-popover-size.d.ts +126 -0
  94. package/dist/types/internal/get-aria-for-trigger.d.ts +13 -25
  95. package/dist/types/internal/is-native-element-open.d.ts +3 -0
  96. package/dist/types/internal/javascript-fallback/anchor-positioning-fallback.d.ts +36 -0
  97. package/dist/types/internal/javascript-fallback/apply-javascript-fallback-positioning.d.ts +15 -0
  98. package/dist/types/internal/javascript-fallback/resolve-css-length-to-pixels.d.ts +20 -0
  99. package/dist/types/internal/javascript-fallback/warn-fallback-failure.d.ts +7 -0
  100. package/dist/types/internal/resolve-placement.d.ts +18 -2
  101. package/dist/types/internal/supports-anchor-positioning.d.ts +5 -0
  102. package/dist/types/internal/supports-anchor-size.d.ts +5 -0
  103. package/dist/types/internal/supports-css-declaration.d.ts +11 -0
  104. package/dist/types/internal/surface-reset.d.ts +25 -0
  105. package/dist/types/internal/use-anchored-popover-at-point.d.ts +48 -0
  106. package/dist/types/internal/use-anchored-popover.d.ts +143 -0
  107. package/dist/types/popover/index.d.ts +2 -1
  108. package/dist/types/popover/popover.d.ts +1 -1
  109. package/dist/types/popover/types.d.ts +15 -17
  110. package/dist/types/testing/polyfill.d.ts +3 -3
  111. package/package.json +2 -2
  112. package/use-anchored-popover/package.json +10 -0
  113. package/use-anchored-popover-at-point/package.json +10 -0
  114. package/dist/cjs/internal/placement-to-try-fallbacks.js +0 -108
  115. package/dist/cjs/internal/resolve-css-length-to-pixels.js +0 -104
  116. package/dist/cjs/internal/use-anchor-position-at-point.js +0 -129
  117. package/dist/cjs/internal/use-anchor-position.js +0 -501
  118. package/dist/cjs/internal/use-width-from-anchor.js +0 -124
  119. package/dist/es2019/internal/placement-to-try-fallbacks.js +0 -108
  120. package/dist/es2019/internal/resolve-css-length-to-pixels.js +0 -101
  121. package/dist/es2019/internal/use-anchor-position-at-point.js +0 -124
  122. package/dist/es2019/internal/use-anchor-position.js +0 -480
  123. package/dist/es2019/internal/use-width-from-anchor.js +0 -120
  124. package/dist/esm/internal/placement-to-try-fallbacks.js +0 -103
  125. package/dist/esm/internal/resolve-css-length-to-pixels.js +0 -98
  126. package/dist/esm/internal/use-anchor-position-at-point.js +0 -124
  127. package/dist/esm/internal/use-anchor-position.js +0 -494
  128. package/dist/esm/internal/use-width-from-anchor.js +0 -118
  129. package/dist/types/internal/anchor-positioning-fallback.d.ts +0 -51
  130. package/dist/types/internal/placement-to-try-fallbacks.d.ts +0 -13
  131. package/dist/types/internal/resolve-css-length-to-pixels.d.ts +0 -20
  132. package/dist/types/internal/use-anchor-position-at-point.d.ts +0 -67
  133. package/dist/types/internal/use-anchor-position.d.ts +0 -87
  134. package/dist/types/internal/use-width-from-anchor.d.ts +0 -19
  135. package/use-anchor-position/package.json +0 -10
  136. package/use-anchor-position-at-point/package.json +0 -10
  137. package/use-width-from-anchor/package.json +0 -10
@@ -1,67 +0,0 @@
1
- import { type RefObject } from 'react';
2
- import { type TPlacementOptions } from './resolve-placement';
3
- /**
4
- * A point in viewport coordinates (CSS pixels) at which the synthetic
5
- * anchor should be placed.
6
- *
7
- * Axis-named (`x`/`y`) rather than edge-named (`left`/`top`) so the
8
- * shape is unambiguous in RTL writing modes - there is no ambiguity
9
- * about whether a coordinate is logical (`inline-start`/`block-start`)
10
- * or physical (`left`/`top`). Viewport coordinates are always
11
- * physical, so we name them with the physical axis labels.
12
- */
13
- export type TAnchorPoint = {
14
- x: number;
15
- y: number;
16
- };
17
- /**
18
- * Positions a popover at a consumer-supplied viewport coordinate using a
19
- * hidden synthetic anchor.
20
- *
21
- * @example
22
- * ```tsx
23
- * function PointPositionedPopover({ popoverRef, placement, mousePos }) {
24
- * useAnchorPositionAtPoint({
25
- * popoverRef,
26
- * placement,
27
- * isEnabled: Boolean(mousePos),
28
- * getPoint: () => {
29
- * if (!mousePos) return null;
30
- * return { x: mousePos.clientX, y: mousePos.clientY };
31
- * },
32
- * });
33
- * return <Popover ref={popoverRef}>...</Popover>;
34
- * }
35
- * ```
36
- */
37
- export declare function useAnchorPositionAtPoint({ popoverRef, placement, getPoint, isEnabled, isOpen, }: {
38
- /**
39
- * Element being positioned. Passed to `useAnchorPosition`.
40
- */
41
- popoverRef: RefObject<HTMLElement | null>;
42
- /**
43
- * Where the popover sits relative to the anchor.
44
- */
45
- placement: TPlacementOptions;
46
- /**
47
- * Lazy callback returning the viewport coordinate to anchor at.
48
- * Called once per activation (every `isEnabled: false → true`
49
- * transition); the result is latched and not re-read.
50
- *
51
- * Return `null` to signal "no point yet" - the hook stays in a
52
- * no-DOM state so another positioning strategy can own the popover.
53
- *
54
- * Read from a ref, so it does not need to be memoized.
55
- */
56
- getPoint: () => TAnchorPoint | null;
57
- /**
58
- * When `false`, the hook is a no-op: no synthetic anchor is created
59
- * and no positioning is applied. Defaults to `true`.
60
- */
61
- isEnabled?: boolean;
62
- /**
63
- * Whether the popover is currently open. Forwarded to the inner
64
- * `useAnchorPosition` so it re-runs across host remount cycles.
65
- */
66
- isOpen: boolean;
67
- }): void;
@@ -1,87 +0,0 @@
1
- /**
2
- * Anchor positioning for top-layer popovers. See
3
- * `notes/architecture/positioning.md` for the full model.
4
- *
5
- * Two runtime paths: CSS Anchor Positioning (modern browsers) and a JS
6
- * fallback that measures the trigger and writes `top`/`left`.
7
- *
8
- * Both paths honour `offset.gap` and `offset.crossAxisShift`. The
9
- * CSS path passes the values through as strings; the JS fallback resolves
10
- * them to pixels via a hidden DOM probe (see `resolveCssLengthToPixels`)
11
- * so tokens, `calc()`, `var()`, etc all work. The JS fallback hides the
12
- * popover with `opacity: 0` until the first measurement completes, so it
13
- * is never painted at the wrong location.
14
- */
15
- import { type RefObject } from 'react';
16
- import { type TPlacementOptions } from '../internal/resolve-placement';
17
- /**
18
- * Hook that positions an element relative to an anchor element using
19
- * CSS Anchor Positioning (with a JS fallback for older browsers).
20
- *
21
- * This hook is the positioning primitive. It has no knowledge of popovers,
22
- * visibility, or animation. Compose it with `Popover` for anchor-positioned
23
- * top-layer content.
24
- *
25
- * When CSS Anchor Positioning is supported, it sets CSS properties
26
- * (`anchor-name`, `position-anchor`, `position-area`, `position-try-fallbacks`)
27
- * directly on the elements via `el.style.setProperty()`.
28
- *
29
- * When not supported, it falls back to JavaScript-based positioning using
30
- * `position: fixed` with measured coordinates, re-running on scroll (capture)
31
- * and resize events.
32
- */
33
- export declare function useAnchorPosition({ anchorRef, popoverRef, placement, forceFallbackPositioning, isEnabled, isOpen, }: {
34
- /**
35
- * Element to position relative to.
36
- */
37
- anchorRef: RefObject<HTMLElement | null>;
38
- /**
39
- * Element being positioned (typically a popover).
40
- *
41
- * The popover host may be unmounted between opens (the `Popover`
42
- * primitive unmounts after its exit animation). Pass `isOpen` so the
43
- * positioning effect re-runs against the freshly mounted element on
44
- * the next open. Without it, the effect's bound listeners and styles
45
- * would target the previous (detached) element.
46
- */
47
- popoverRef: RefObject<HTMLElement | null>;
48
- /**
49
- * Where to place the element relative to the anchor.
50
- * `offset.gap` and `offset.crossAxisShift` are part of the
51
- * placement object.
52
- *
53
- * All fields are optional. Omitted fields fall back to:
54
- * - `axis`: `'block'`
55
- * - `edge`: `'end'`
56
- * - `align`: `'center'`
57
- * - `offset.gap`: `token('space.100', '8px')`
58
- * - `offset.crossAxisShift.value`: `'0px'`
59
- * - `offset.crossAxisShift.direction`: `'forwards'`
60
- *
61
- * The full default placement (`{}`) renders the popover centered
62
- * below the trigger with one `space.100` of gap and no cross-axis
63
- * shift.
64
- *
65
- * `offset.gap` and `offset.crossAxisShift.value` accept either a
66
- * number (pixels) or a CSS length string (eg `token('space.200')`).
67
- */
68
- placement?: TPlacementOptions;
69
- /**
70
- * Forces the JavaScript positioning fallback even when the browser
71
- * supports CSS Anchor Positioning. Useful for testing fallback
72
- * behavior in any environment, including production.
73
- */
74
- forceFallbackPositioning?: boolean;
75
- /**
76
- * When `false`, the hook is a no-op and applies no positioning.
77
- * Defaults to `true`.
78
- */
79
- isEnabled?: boolean;
80
- /**
81
- * Whether the popover is currently open. Drives a re-run of the
82
- * positioning effect when the popover host element is unmounted
83
- * and remounted across open cycles, so listeners and styles are
84
- * always wired to the live host element.
85
- */
86
- isOpen: boolean;
87
- }): void;
@@ -1,19 +0,0 @@
1
- import { type RefObject } from 'react';
2
- import type { TWidthFromAnchorMode } from '../popover/types';
3
- /**
4
- * Sets the width of a popover element relative to its anchor element.
5
- *
6
- * - `'match-anchor'` → `inline-size: anchor-size(self-inline)`, exact
7
- * - `'min-anchor'` → `min-inline-size: anchor-size(self-inline)`, floor only
8
- * - `'none'` → `min-inline-size: max-content`, content floor (default)
9
- *
10
- * `self-inline` is the inline axis of the element USING the function (the popover), never the
11
- * anchor, so it matches the axis `inline-size` constrains. See
12
- * `notes/decisions/width-from-anchor-floors.md`.
13
- */
14
- export declare function useWidthFromAnchor({ mode, popoverRef, anchorRef, isOpen, }: {
15
- mode: TWidthFromAnchorMode;
16
- popoverRef: RefObject<HTMLElement | null>;
17
- anchorRef: RefObject<HTMLElement | null>;
18
- isOpen: boolean;
19
- }): void;
@@ -1,10 +0,0 @@
1
- {
2
- "name": "@atlaskit/top-layer/use-anchor-position",
3
- "main": "../dist/cjs/internal/use-anchor-position.js",
4
- "module": "../dist/esm/internal/use-anchor-position.js",
5
- "module:es2019": "../dist/es2019/internal/use-anchor-position.js",
6
- "sideEffects": [
7
- "*.compiled.css"
8
- ],
9
- "types": "../dist/types/internal/use-anchor-position.d.ts"
10
- }
@@ -1,10 +0,0 @@
1
- {
2
- "name": "@atlaskit/top-layer/use-anchor-position-at-point",
3
- "main": "../dist/cjs/internal/use-anchor-position-at-point.js",
4
- "module": "../dist/esm/internal/use-anchor-position-at-point.js",
5
- "module:es2019": "../dist/es2019/internal/use-anchor-position-at-point.js",
6
- "sideEffects": [
7
- "*.compiled.css"
8
- ],
9
- "types": "../dist/types/internal/use-anchor-position-at-point.d.ts"
10
- }
@@ -1,10 +0,0 @@
1
- {
2
- "name": "@atlaskit/top-layer/use-width-from-anchor",
3
- "main": "../dist/cjs/internal/use-width-from-anchor.js",
4
- "module": "../dist/esm/internal/use-width-from-anchor.js",
5
- "module:es2019": "../dist/es2019/internal/use-width-from-anchor.js",
6
- "sideEffects": [
7
- "*.compiled.css"
8
- ],
9
- "types": "../dist/types/internal/use-width-from-anchor.d.ts"
10
- }