@fluentui/react-positioning 9.22.3 → 9.74.3-experimental.esm.20260709-49ee7a20cf.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 +14 -2
- package/dist/index.d.cts +409 -0
- package/lib/PositioningConfigurationContext.js +1 -1
- package/lib/createArrowStyles.js +1 -1
- package/lib/createPositionManager.js +6 -6
- package/lib/createPositionManager.js.map +1 -1
- package/lib/createSlideStyles.js +2 -2
- package/lib/createSlideStyles.js.map +1 -1
- package/lib/hooks/useSafeZoneArea/SafeZoneArea.js +9 -9
- package/lib/hooks/useSafeZoneArea/SafeZoneArea.js.map +1 -1
- package/lib/hooks/useSafeZoneArea/SafeZoneArea.styles.js +2 -2
- package/lib/hooks/useSafeZoneArea/SafeZoneArea.styles.js.map +1 -1
- package/lib/hooks/useSafeZoneArea/SafeZoneArea.styles.raw.js +2 -2
- package/lib/hooks/useSafeZoneArea/useSafeZoneArea.js +4 -4
- package/lib/hooks/useSafeZoneArea/useSafeZoneArea.js.map +1 -1
- package/lib/index.js +10 -10
- package/lib/index.js.map +1 -1
- package/lib/middleware/coverTarget.js +1 -1
- package/lib/middleware/coverTarget.js.map +1 -1
- package/lib/middleware/flip.js +2 -2
- package/lib/middleware/flip.js.map +1 -1
- package/lib/middleware/index.js +7 -7
- package/lib/middleware/index.js.map +1 -1
- package/lib/middleware/intersecting.js +1 -1
- package/lib/middleware/maxSize.js +3 -3
- package/lib/middleware/maxSize.js.map +1 -1
- package/lib/middleware/offset.js +2 -2
- package/lib/middleware/offset.js.map +1 -1
- package/lib/middleware/shift.js +2 -2
- package/lib/middleware/shift.js.map +1 -1
- package/lib/usePositioning.js +6 -6
- package/lib/usePositioning.js.map +1 -1
- package/lib/usePositioningMouseTarget.js +2 -2
- package/lib/usePositioningMouseTarget.js.map +1 -1
- package/lib/usePositioningOptions.js +8 -8
- package/lib/usePositioningOptions.js.map +1 -1
- package/lib/usePositioningSlideDirection.js +3 -3
- package/lib/usePositioningSlideDirection.js.map +1 -1
- package/lib/utils/devtools.js +3 -3
- package/lib/utils/devtools.js.map +1 -1
- package/lib/utils/fromFloatingUIPlacement.js +1 -1
- package/lib/utils/fromFloatingUIPlacement.js.map +1 -1
- package/lib/utils/getBoundary.js +1 -1
- package/lib/utils/getBoundary.js.map +1 -1
- package/lib/utils/getFloatingUIOffset.js +1 -1
- package/lib/utils/getFloatingUIOffset.js.map +1 -1
- package/lib/utils/hasAutoFocusFilter.js +1 -1
- package/lib/utils/hasAutoFocusFilter.js.map +1 -1
- package/lib/utils/index.js +16 -16
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/listScrollParents.js +1 -1
- package/lib/utils/listScrollParents.js.map +1 -1
- package/lib/utils/toggleScrollListener.js +2 -2
- package/lib/utils/toggleScrollListener.js.map +1 -1
- package/lib/utils/useCallbackRef.js +2 -2
- package/lib/utils/writeContainerupdates.js +1 -1
- package/lib/utils/writeContainerupdates.js.map +1 -1
- package/lib-commonjs/{createPositionManager.js → createPositionManager.cjs} +7 -7
- package/lib-commonjs/{createPositionManager.js.map → createPositionManager.cjs.map} +1 -1
- package/lib-commonjs/{createSlideStyles.js → createSlideStyles.cjs} +1 -1
- package/lib-commonjs/{createSlideStyles.js.map → createSlideStyles.cjs.map} +1 -1
- package/lib-commonjs/hooks/useSafeZoneArea/{SafeZoneArea.js → SafeZoneArea.cjs} +5 -5
- package/lib-commonjs/hooks/useSafeZoneArea/{SafeZoneArea.js.map → SafeZoneArea.cjs.map} +1 -1
- package/lib-commonjs/hooks/useSafeZoneArea/SafeZoneArea.styles.cjs.map +1 -0
- package/lib-commonjs/hooks/useSafeZoneArea/{useSafeZoneArea.js → useSafeZoneArea.cjs} +2 -2
- package/lib-commonjs/hooks/useSafeZoneArea/{useSafeZoneArea.js.map → useSafeZoneArea.cjs.map} +1 -1
- package/lib-commonjs/{index.js → index.cjs} +10 -10
- package/lib-commonjs/{index.js.map → index.cjs.map} +1 -1
- package/lib-commonjs/middleware/{coverTarget.js → coverTarget.cjs} +1 -1
- package/lib-commonjs/middleware/{coverTarget.js.map → coverTarget.cjs.map} +1 -1
- package/lib-commonjs/middleware/{flip.js → flip.cjs} +1 -1
- package/lib-commonjs/middleware/{flip.js.map → flip.cjs.map} +1 -1
- package/lib-commonjs/middleware/{index.js → index.cjs} +7 -7
- package/lib-commonjs/middleware/{index.js.map → index.cjs.map} +1 -1
- package/lib-commonjs/middleware/{maxSize.js → maxSize.cjs} +3 -3
- package/lib-commonjs/middleware/{maxSize.js.map → maxSize.cjs.map} +1 -1
- package/lib-commonjs/middleware/{offset.js → offset.cjs} +1 -1
- package/lib-commonjs/middleware/{offset.js.map → offset.cjs.map} +1 -1
- package/lib-commonjs/middleware/{shift.js → shift.cjs} +1 -1
- package/lib-commonjs/middleware/{shift.js.map → shift.cjs.map} +1 -1
- package/lib-commonjs/{usePositioning.js → usePositioning.cjs} +8 -8
- package/lib-commonjs/{usePositioning.js.map → usePositioning.cjs.map} +1 -1
- package/lib-commonjs/{usePositioningMouseTarget.js → usePositioningMouseTarget.cjs} +1 -1
- package/lib-commonjs/{usePositioningMouseTarget.js.map → usePositioningMouseTarget.cjs.map} +1 -1
- package/lib-commonjs/{usePositioningOptions.js → usePositioningOptions.cjs} +15 -15
- package/lib-commonjs/{usePositioningOptions.js.map → usePositioningOptions.cjs.map} +1 -1
- package/lib-commonjs/{usePositioningSlideDirection.js → usePositioningSlideDirection.cjs} +1 -1
- package/lib-commonjs/{usePositioningSlideDirection.js.map → usePositioningSlideDirection.cjs.map} +1 -1
- package/lib-commonjs/utils/{devtools.js → devtools.cjs} +2 -2
- package/lib-commonjs/utils/{devtools.js.map → devtools.cjs.map} +1 -1
- package/lib-commonjs/utils/{fromFloatingUIPlacement.js → fromFloatingUIPlacement.cjs} +1 -1
- package/lib-commonjs/utils/{fromFloatingUIPlacement.js.map → fromFloatingUIPlacement.cjs.map} +1 -1
- package/lib-commonjs/utils/{getBoundary.js → getBoundary.cjs} +1 -1
- package/lib-commonjs/utils/{getBoundary.js.map → getBoundary.cjs.map} +1 -1
- package/lib-commonjs/utils/{getFloatingUIOffset.js → getFloatingUIOffset.cjs} +1 -1
- package/lib-commonjs/utils/{getFloatingUIOffset.js.map → getFloatingUIOffset.cjs.map} +1 -1
- package/lib-commonjs/utils/{hasAutoFocusFilter.js → hasAutoFocusFilter.cjs} +1 -1
- package/lib-commonjs/utils/{hasAutoFocusFilter.js.map → hasAutoFocusFilter.cjs.map} +1 -1
- package/lib-commonjs/utils/{index.js → index.cjs} +16 -16
- package/lib-commonjs/utils/{index.js.map → index.cjs.map} +1 -1
- package/lib-commonjs/utils/{listScrollParents.js → listScrollParents.cjs} +1 -1
- package/lib-commonjs/utils/{listScrollParents.js.map → listScrollParents.cjs.map} +1 -1
- package/lib-commonjs/utils/{toggleScrollListener.js → toggleScrollListener.cjs} +1 -1
- package/lib-commonjs/utils/{toggleScrollListener.js.map → toggleScrollListener.cjs.map} +1 -1
- package/lib-commonjs/utils/{writeContainerupdates.js → writeContainerupdates.cjs} +1 -1
- package/lib-commonjs/utils/{writeContainerupdates.js.map → writeContainerupdates.cjs.map} +1 -1
- package/package.json +17 -15
- package/lib-commonjs/hooks/useSafeZoneArea/SafeZoneArea.styles.js.map +0 -1
- /package/lib-commonjs/{PositioningConfigurationContext.js → PositioningConfigurationContext.cjs} +0 -0
- /package/lib-commonjs/{PositioningConfigurationContext.js.map → PositioningConfigurationContext.cjs.map} +0 -0
- /package/lib-commonjs/{constants.js → constants.cjs} +0 -0
- /package/lib-commonjs/{constants.js.map → constants.cjs.map} +0 -0
- /package/lib-commonjs/{createArrowStyles.js → createArrowStyles.cjs} +0 -0
- /package/lib-commonjs/{createArrowStyles.js.map → createArrowStyles.cjs.map} +0 -0
- /package/lib-commonjs/{createVirtualElementFromClick.js → createVirtualElementFromClick.cjs} +0 -0
- /package/lib-commonjs/{createVirtualElementFromClick.js.map → createVirtualElementFromClick.cjs.map} +0 -0
- /package/lib-commonjs/hooks/useSafeZoneArea/{SafeZoneArea.styles.js → SafeZoneArea.styles.cjs} +0 -0
- /package/lib-commonjs/hooks/useSafeZoneArea/{SafeZoneArea.styles.raw.js → SafeZoneArea.styles.raw.cjs} +0 -0
- /package/lib-commonjs/hooks/useSafeZoneArea/{SafeZoneArea.styles.raw.js.map → SafeZoneArea.styles.raw.cjs.map} +0 -0
- /package/lib-commonjs/hooks/useSafeZoneArea/{computeOutsideClipPath.js → computeOutsideClipPath.cjs} +0 -0
- /package/lib-commonjs/hooks/useSafeZoneArea/{computeOutsideClipPath.js.map → computeOutsideClipPath.cjs.map} +0 -0
- /package/lib-commonjs/hooks/useSafeZoneArea/{createSafeZoneAreaStateStore.js → createSafeZoneAreaStateStore.cjs} +0 -0
- /package/lib-commonjs/hooks/useSafeZoneArea/{createSafeZoneAreaStateStore.js.map → createSafeZoneAreaStateStore.cjs.map} +0 -0
- /package/lib-commonjs/hooks/useSafeZoneArea/{getMouseAnchor.js → getMouseAnchor.cjs} +0 -0
- /package/lib-commonjs/hooks/useSafeZoneArea/{getMouseAnchor.js.map → getMouseAnchor.cjs.map} +0 -0
- /package/lib-commonjs/hooks/useSafeZoneArea/{getRectCorners.js → getRectCorners.cjs} +0 -0
- /package/lib-commonjs/hooks/useSafeZoneArea/{getRectCorners.js.map → getRectCorners.cjs.map} +0 -0
- /package/lib-commonjs/hooks/useSafeZoneArea/{pointsToSvgPath.js → pointsToSvgPath.cjs} +0 -0
- /package/lib-commonjs/hooks/useSafeZoneArea/{pointsToSvgPath.js.map → pointsToSvgPath.cjs.map} +0 -0
- /package/lib-commonjs/hooks/useSafeZoneArea/{types.js → types.cjs} +0 -0
- /package/lib-commonjs/hooks/useSafeZoneArea/{types.js.map → types.cjs.map} +0 -0
- /package/lib-commonjs/middleware/{intersecting.js → intersecting.cjs} +0 -0
- /package/lib-commonjs/middleware/{intersecting.js.map → intersecting.cjs.map} +0 -0
- /package/lib-commonjs/middleware/{matchTargetSize.js → matchTargetSize.cjs} +0 -0
- /package/lib-commonjs/middleware/{matchTargetSize.js.map → matchTargetSize.cjs.map} +0 -0
- /package/lib-commonjs/{types.js → types.cjs} +0 -0
- /package/lib-commonjs/{types.js.map → types.cjs.map} +0 -0
- /package/lib-commonjs/utils/{createResizeObserver.js → createResizeObserver.cjs} +0 -0
- /package/lib-commonjs/utils/{createResizeObserver.js.map → createResizeObserver.cjs.map} +0 -0
- /package/lib-commonjs/utils/{debounce.js → debounce.cjs} +0 -0
- /package/lib-commonjs/utils/{debounce.js.map → debounce.cjs.map} +0 -0
- /package/lib-commonjs/utils/{getReactFiberFromNode.js → getReactFiberFromNode.cjs} +0 -0
- /package/lib-commonjs/utils/{getReactFiberFromNode.js.map → getReactFiberFromNode.cjs.map} +0 -0
- /package/lib-commonjs/utils/{getScrollParent.js → getScrollParent.cjs} +0 -0
- /package/lib-commonjs/utils/{getScrollParent.js.map → getScrollParent.cjs.map} +0 -0
- /package/lib-commonjs/utils/{mergeArrowOffset.js → mergeArrowOffset.cjs} +0 -0
- /package/lib-commonjs/utils/{mergeArrowOffset.js.map → mergeArrowOffset.cjs.map} +0 -0
- /package/lib-commonjs/utils/{normalizeAutoSize.js → normalizeAutoSize.cjs} +0 -0
- /package/lib-commonjs/utils/{normalizeAutoSize.js.map → normalizeAutoSize.cjs.map} +0 -0
- /package/lib-commonjs/utils/{parseFloatingUIPlacement.js → parseFloatingUIPlacement.cjs} +0 -0
- /package/lib-commonjs/utils/{parseFloatingUIPlacement.js.map → parseFloatingUIPlacement.cjs.map} +0 -0
- /package/lib-commonjs/utils/{resolvePositioningShorthand.js → resolvePositioningShorthand.cjs} +0 -0
- /package/lib-commonjs/utils/{resolvePositioningShorthand.js.map → resolvePositioningShorthand.cjs.map} +0 -0
- /package/lib-commonjs/utils/{toFloatingUIPadding.js → toFloatingUIPadding.cjs} +0 -0
- /package/lib-commonjs/utils/{toFloatingUIPadding.js.map → toFloatingUIPadding.cjs.map} +0 -0
- /package/lib-commonjs/utils/{toFloatingUIPlacement.js → toFloatingUIPlacement.cjs} +0 -0
- /package/lib-commonjs/utils/{toFloatingUIPlacement.js.map → toFloatingUIPlacement.cjs.map} +0 -0
- /package/lib-commonjs/utils/{useCallbackRef.js → useCallbackRef.cjs} +0 -0
- /package/lib-commonjs/utils/{useCallbackRef.js.map → useCallbackRef.cjs.map} +0 -0
- /package/lib-commonjs/utils/{writeArrowUpdates.js → writeArrowUpdates.cjs} +0 -0
- /package/lib-commonjs/utils/{writeArrowUpdates.js.map → writeArrowUpdates.cjs.map} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,24 @@
|
|
|
1
1
|
# Change Log - @fluentui/react-positioning
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Thu, 09 Jul 2026 17:34:14 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## [9.74.3-experimental.esm.20260709-49ee7a20cf.0](https://github.com/microsoft/fluentui/tree/@fluentui/react-positioning_v9.74.3-experimental.esm.20260709-49ee7a20cf.0)
|
|
8
|
+
|
|
9
|
+
Thu, 09 Jul 2026 17:34:14 GMT
|
|
10
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-positioning_v9.22.3..@fluentui/react-positioning_v9.74.3-experimental.esm.20260709-49ee7a20cf.0)
|
|
11
|
+
|
|
12
|
+
### Changes
|
|
13
|
+
|
|
14
|
+
- Release 9.74.3-experimental.esm.20260709-49ee7a20cf ([commit](https://github.com/microsoft/fluentui/commit/not available) by fluentui-internal@service.microsoft.com)
|
|
15
|
+
- Bump @fluentui/react-shared-contexts to v9.74.3-experimental.esm.20260709-49ee7a20cf.0 ([commit](https://github.com/microsoft/fluentui/commit/175a26e0c520dd90a54578d1185a3b0b6c446e15) by beachball)
|
|
16
|
+
- Bump @fluentui/react-theme to v9.74.3-experimental.esm.20260709-49ee7a20cf.0 ([commit](https://github.com/microsoft/fluentui/commit/175a26e0c520dd90a54578d1185a3b0b6c446e15) by beachball)
|
|
17
|
+
- Bump @fluentui/react-utilities to v9.74.3-experimental.esm.20260709-49ee7a20cf.0 ([commit](https://github.com/microsoft/fluentui/commit/175a26e0c520dd90a54578d1185a3b0b6c446e15) by beachball)
|
|
18
|
+
|
|
7
19
|
## [9.22.3](https://github.com/microsoft/fluentui/tree/@fluentui/react-positioning_v9.22.3)
|
|
8
20
|
|
|
9
|
-
Wed, 24 Jun 2026 11:
|
|
21
|
+
Wed, 24 Jun 2026 11:09:53 GMT
|
|
10
22
|
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-positioning_v9.22.2..@fluentui/react-positioning_v9.22.3)
|
|
11
23
|
|
|
12
24
|
### Patches
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
import type { GriffelStyle } from '@griffel/react';
|
|
2
|
+
import type { JSXElement } from '@fluentui/react-utilities';
|
|
3
|
+
import * as React_2 from 'react';
|
|
4
|
+
import type { RefObjectFunction } from '@fluentui/react-utilities';
|
|
5
|
+
|
|
6
|
+
export declare type Alignment = 'top' | 'bottom' | 'start' | 'end' | 'center';
|
|
7
|
+
|
|
8
|
+
export declare type AutoSize = 'height' | 'height-always' | 'width' | 'width-always' | 'always' | boolean;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @deprecated use PositioningBoundary instead
|
|
12
|
+
*/
|
|
13
|
+
export declare type Boundary = PositioningBoundary;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Creates CSS styles to size the arrow created by createArrowStyles to the given height.
|
|
17
|
+
*
|
|
18
|
+
* Use this when you need to create classes for several different arrow sizes. If you only need a
|
|
19
|
+
* constant arrow size, you can pass the `arrowHeight` param to createArrowStyles instead.
|
|
20
|
+
*
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
export declare function createArrowHeightStyles(arrowHeight: number): GriffelStyle;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Helper that creates a makeStyles rule for an arrow element.
|
|
27
|
+
* For runtime arrow size toggling simply create extra classnames to apply to the arrow element
|
|
28
|
+
*
|
|
29
|
+
* ```ts
|
|
30
|
+
* makeStyles({
|
|
31
|
+
* arrowWithSize: createArrowStyles({ arrowHeight: 6 }),
|
|
32
|
+
*
|
|
33
|
+
* arrowWithoutSize: createArrowStyles({ arrowHeight: undefined }),
|
|
34
|
+
* mediumArrow: createArrowHeightStyles(4),
|
|
35
|
+
* smallArrow: createArrowHeightStyles(2),
|
|
36
|
+
* })
|
|
37
|
+
* ...
|
|
38
|
+
*
|
|
39
|
+
* state.arrowWithSize.className = styles.arrowWithSize;
|
|
40
|
+
* state.arrowWithoutSize.className = mergeClasses(
|
|
41
|
+
* styles.arrowWithoutSize,
|
|
42
|
+
* state.smallArrow && styles.smallArrow,
|
|
43
|
+
* state.mediumArrow && styles.mediumArrow,
|
|
44
|
+
* )
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @internal
|
|
48
|
+
*/
|
|
49
|
+
export declare function createArrowStyles(options: CreateArrowStylesOptions): GriffelStyle;
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Options parameter for the createArrowStyles function
|
|
53
|
+
*
|
|
54
|
+
* @internal
|
|
55
|
+
*/
|
|
56
|
+
export declare type CreateArrowStylesOptions = {
|
|
57
|
+
/**
|
|
58
|
+
* The height of the arrow from the base to the tip, in px. The base width of the arrow is always twice its height.
|
|
59
|
+
*
|
|
60
|
+
* This can be undefined to leave out the arrow size styles. You must then add styles created by
|
|
61
|
+
* createArrowHeightStyles to set the arrow's size correctly. This can be useful if the arrow can be different sizes.
|
|
62
|
+
*/
|
|
63
|
+
arrowHeight: number | undefined;
|
|
64
|
+
/**
|
|
65
|
+
* The borderWidth of the arrow. Should be the same borderWidth as the parent element.
|
|
66
|
+
*
|
|
67
|
+
* @defaultvalue 1px
|
|
68
|
+
*/
|
|
69
|
+
borderWidth?: GriffelStyle['borderBottomWidth'];
|
|
70
|
+
/**
|
|
71
|
+
* The borderStyle for the arrow. Should be the same borderStyle as the parent element.
|
|
72
|
+
*
|
|
73
|
+
* @defaultvalue solid
|
|
74
|
+
*/
|
|
75
|
+
borderStyle?: GriffelStyle['borderBottomStyle'];
|
|
76
|
+
/**
|
|
77
|
+
* The borderColor of the arrow. Should be the same borderColor as the parent element.
|
|
78
|
+
*
|
|
79
|
+
* @defaultvalue tokens.colorTransparentStroke
|
|
80
|
+
*/
|
|
81
|
+
borderColor?: GriffelStyle['borderBottomColor'];
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Creates animation styles so that positioned elements slide in from the main axis
|
|
86
|
+
* @param mainAxis - distance than the element sides for
|
|
87
|
+
* @returns Griffel styles to spread to a slot
|
|
88
|
+
*
|
|
89
|
+
* @deprecated The popover-related components now use the Slide motion component,
|
|
90
|
+
* which they inject using the `surfaceMotion` slot.
|
|
91
|
+
*/
|
|
92
|
+
export declare function createSlideStyles(mainAxis: number): GriffelStyle;
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Creates a virtual element based on the position of a click event
|
|
96
|
+
* Can be used as a target for popper in scenarios such as context menus
|
|
97
|
+
*/
|
|
98
|
+
export declare function createVirtualElementFromClick(nativeEvent: MouseEvent): PositioningVirtualElement;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Generally when adding an arrow to popper, it's necessary to offset the position of the popper by the
|
|
102
|
+
* height of the arrow. A simple utility to merge a provided offset with an arrow height to return the final offset
|
|
103
|
+
*
|
|
104
|
+
* @internal
|
|
105
|
+
* @param userOffset - The offset provided by the user
|
|
106
|
+
* @param arrowHeight - The height of the arrow in px
|
|
107
|
+
* @returns User offset augmented with arrow height
|
|
108
|
+
*/
|
|
109
|
+
export declare function mergeArrowOffset(userOffset: Offset | undefined | null, arrowHeight: number): Offset;
|
|
110
|
+
|
|
111
|
+
export declare type Offset = OffsetFunction | OffsetObject | OffsetShorthand;
|
|
112
|
+
|
|
113
|
+
export declare type OffsetFunction = (param: OffsetFunctionParam) => OffsetObject | OffsetShorthand;
|
|
114
|
+
|
|
115
|
+
export declare type OffsetFunctionParam = {
|
|
116
|
+
positionedRect: PositioningRect;
|
|
117
|
+
targetRect: PositioningRect;
|
|
118
|
+
position: Position;
|
|
119
|
+
alignment?: Alignment;
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
export declare type OffsetObject = {
|
|
123
|
+
crossAxis?: number;
|
|
124
|
+
mainAxis: number;
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
export declare type OffsetShorthand = number;
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Custom DOM event dispatched on the positioned container element when a
|
|
131
|
+
* positioning update completes. Carries placement information in `event.detail`.
|
|
132
|
+
*/
|
|
133
|
+
declare type OnPositioningEndEvent = CustomEvent<OnPositioningEndEventDetail>;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Detail payload of the positioning end event, providing the final computed placement
|
|
137
|
+
* after all middleware (flip, shift, etc.) have run.
|
|
138
|
+
*/
|
|
139
|
+
declare type OnPositioningEndEventDetail = {
|
|
140
|
+
/**
|
|
141
|
+
* The computed placement of the positioned element. May differ from the requested
|
|
142
|
+
* placement if flip or other middleware adjusted it.
|
|
143
|
+
*/
|
|
144
|
+
placement: PositioningPlacement;
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
export declare type Position = 'above' | 'below' | 'before' | 'after';
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* CSS custom properties used to encode the slide direction for positioning-aware enter animations.
|
|
151
|
+
* Set at runtime by `usePositioningSlideDirection` and registered via the CSS
|
|
152
|
+
* `registerProperty()` API so browsers can interpolate them as `<length>` values.
|
|
153
|
+
*/
|
|
154
|
+
export declare const POSITIONING_SLIDE_DIRECTION_VAR_X = "--fui-positioning-slide-direction-x";
|
|
155
|
+
|
|
156
|
+
export declare const POSITIONING_SLIDE_DIRECTION_VAR_Y = "--fui-positioning-slide-direction-y";
|
|
157
|
+
|
|
158
|
+
export declare type PositioningBoundary = PositioningRect | HTMLElement | Array<HTMLElement> | 'clippingParents' | 'scrollParent' | 'window';
|
|
159
|
+
|
|
160
|
+
export declare type PositioningConfigurationFn = (params: {
|
|
161
|
+
container: HTMLElement;
|
|
162
|
+
arrow: HTMLElement | null;
|
|
163
|
+
options: PositioningConfigurationFnOptions;
|
|
164
|
+
}) => PositioningConfigurationFnOptions;
|
|
165
|
+
|
|
166
|
+
export declare type PositioningConfigurationFnOptions = Omit<PositioningOptions, 'enabled' | 'onPositioningEnd' | 'positionFixed'>;
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* A context provider for the positioning configuration.
|
|
170
|
+
*
|
|
171
|
+
* Accepts a function that takes the positioning options and returns them modified.
|
|
172
|
+
*/
|
|
173
|
+
export declare const PositioningConfigurationProvider: React_2.Provider<PositioningConfigurationFn | undefined>;
|
|
174
|
+
|
|
175
|
+
export declare type PositioningImperativeRef = {
|
|
176
|
+
/**
|
|
177
|
+
* Updates the position imperatively.
|
|
178
|
+
* Useful when the position of the target changes from other factors than scrolling of window resize.
|
|
179
|
+
*/
|
|
180
|
+
updatePosition: () => void;
|
|
181
|
+
/**
|
|
182
|
+
* Sets the target and updates positioning imperatively.
|
|
183
|
+
* Useful for avoiding double renders with the target option.
|
|
184
|
+
*/
|
|
185
|
+
setTarget: (target: TargetElement | null) => void;
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Internal options for positioning
|
|
190
|
+
*/
|
|
191
|
+
declare interface PositioningOptions {
|
|
192
|
+
/** Alignment for the component. Only has an effect if used with the @see position option */
|
|
193
|
+
align?: Alignment;
|
|
194
|
+
/** The element which will define the boundaries of the positioned element for the flip behavior. */
|
|
195
|
+
flipBoundary?: PositioningBoundary | null;
|
|
196
|
+
/** The element which will define the boundaries of the positioned element for the overflow behavior. */
|
|
197
|
+
overflowBoundary?: PositioningBoundary | null;
|
|
198
|
+
/**
|
|
199
|
+
* Applies a padding to the overflow bounadry, so that overflow is detected earlier before the
|
|
200
|
+
* positioned surface hits the overflow boundary.
|
|
201
|
+
*/
|
|
202
|
+
overflowBoundaryPadding?: number | Partial<{
|
|
203
|
+
top: number;
|
|
204
|
+
end: number;
|
|
205
|
+
bottom: number;
|
|
206
|
+
start: number;
|
|
207
|
+
}>;
|
|
208
|
+
/**
|
|
209
|
+
* Position for the component. Position has higher priority than align. If position is vertical ('above' | 'below')
|
|
210
|
+
* and align is also vertical ('top' | 'bottom') or if both position and align are horizontal ('before' | 'after'
|
|
211
|
+
* and 'start' | 'end' respectively),
|
|
212
|
+
* then provided value for 'align' will be ignored and 'center' will be used instead.
|
|
213
|
+
*/
|
|
214
|
+
position?: Position;
|
|
215
|
+
/**
|
|
216
|
+
* Enables the position element to be positioned with 'fixed' (default value is position: 'absolute')
|
|
217
|
+
* @default false
|
|
218
|
+
* @deprecated use `strategy` instead
|
|
219
|
+
*/
|
|
220
|
+
positionFixed?: boolean;
|
|
221
|
+
/**
|
|
222
|
+
* Specifies the type of CSS position property to use.
|
|
223
|
+
* @default absolute
|
|
224
|
+
*/
|
|
225
|
+
strategy?: 'absolute' | 'fixed';
|
|
226
|
+
/**
|
|
227
|
+
* Lets you displace a positioned element from its reference element.
|
|
228
|
+
* This can be useful if you need to apply some margin between them or if you need to fine tune the
|
|
229
|
+
* position according to some custom logic.
|
|
230
|
+
*/
|
|
231
|
+
offset?: Offset;
|
|
232
|
+
/**
|
|
233
|
+
* Defines padding between the corner of the popup element and the arrow.
|
|
234
|
+
* Use to prevent the arrow from overlapping a rounded corner, for example.
|
|
235
|
+
*/
|
|
236
|
+
arrowPadding?: number;
|
|
237
|
+
/**
|
|
238
|
+
* Applies styles on the positioned element to fit it within the available space in viewport.
|
|
239
|
+
* - true: set styles for max height/width.
|
|
240
|
+
* - 'height': set styles for max height.
|
|
241
|
+
* - 'width'': set styles for max width.
|
|
242
|
+
* Note that options 'always'/'height-always'/'width-always' are now obsolete, and equivalent to true/'height'/'width'.
|
|
243
|
+
*/
|
|
244
|
+
autoSize?: AutoSize;
|
|
245
|
+
/**
|
|
246
|
+
* Modifies position and alignment to cover the target
|
|
247
|
+
*/
|
|
248
|
+
coverTarget?: boolean;
|
|
249
|
+
/**
|
|
250
|
+
* Disables automatic repositioning of the component; it will always be placed according to the values of `align` and
|
|
251
|
+
* `position` props, regardless of the size of the component, the reference element or the viewport.
|
|
252
|
+
*/
|
|
253
|
+
pinned?: boolean;
|
|
254
|
+
/**
|
|
255
|
+
* When the reference element or the viewport is outside viewport allows a positioned element to be fully in viewport.
|
|
256
|
+
* "all" enables this behavior for all axis.
|
|
257
|
+
*/
|
|
258
|
+
unstable_disableTether?: boolean | 'all';
|
|
259
|
+
/**
|
|
260
|
+
* If flip fails to stop the positioned element from overflowing
|
|
261
|
+
* its boundaries, use a specified fallback positions.
|
|
262
|
+
*/
|
|
263
|
+
fallbackPositions?: PositioningShorthandValue[];
|
|
264
|
+
/**
|
|
265
|
+
* Modifies whether popover is positioned using transform.
|
|
266
|
+
* @default true
|
|
267
|
+
*/
|
|
268
|
+
useTransform?: boolean;
|
|
269
|
+
/**
|
|
270
|
+
* If false, does not position anything
|
|
271
|
+
*/
|
|
272
|
+
enabled?: boolean;
|
|
273
|
+
/**
|
|
274
|
+
* When set, the positioned element matches the chosen dimension(s) of the target element
|
|
275
|
+
*/
|
|
276
|
+
matchTargetSize?: 'width';
|
|
277
|
+
/**
|
|
278
|
+
* Called when a position update has finished. Multiple position updates can happen in a single render,
|
|
279
|
+
* since positioning happens outside of the React lifecycle.
|
|
280
|
+
* The event's `detail.placement` indicates the final computed placement after middleware adjustments.
|
|
281
|
+
*
|
|
282
|
+
* It's also possible to listen to the custom DOM event `fui-positioningend`
|
|
283
|
+
*/
|
|
284
|
+
onPositioningEnd?: (e: OnPositioningEndEvent) => void;
|
|
285
|
+
/**
|
|
286
|
+
* Disables the resize observer that updates position on target or dimension change
|
|
287
|
+
*/
|
|
288
|
+
disableUpdateOnResize?: boolean;
|
|
289
|
+
/**
|
|
290
|
+
* When true, the positioned element will shift to cover the target element when there's not enough space.
|
|
291
|
+
* @default false
|
|
292
|
+
*/
|
|
293
|
+
shiftToCoverTarget?: boolean;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* Physical placement of a positioned element relative to its target, as computed by Floating UI.
|
|
298
|
+
* This is a Fluent-owned equivalent of Floating UI's `Placement` type, avoiding a transitive
|
|
299
|
+
* dependency on `@floating-ui/dom` in the public API surface.
|
|
300
|
+
*/
|
|
301
|
+
declare type PositioningPlacement = 'top' | 'top-start' | 'top-end' | 'right' | 'right-start' | 'right-end' | 'bottom' | 'bottom-start' | 'bottom-end' | 'left' | 'left-start' | 'left-end';
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* Public api that allows components using react-positioning to specify positioning options
|
|
305
|
+
*/
|
|
306
|
+
export declare interface PositioningProps extends Pick<PositioningOptions, 'align' | 'arrowPadding' | 'autoSize' | 'coverTarget' | 'fallbackPositions' | 'flipBoundary' | 'offset' | 'overflowBoundary' | 'overflowBoundaryPadding' | 'pinned' | 'position' | 'strategy' | 'useTransform' | 'matchTargetSize' | 'onPositioningEnd' | 'disableUpdateOnResize' | 'shiftToCoverTarget'> {
|
|
307
|
+
/** An imperative handle to Popper methods. */
|
|
308
|
+
positioningRef?: React_2.Ref<PositioningImperativeRef>;
|
|
309
|
+
/**
|
|
310
|
+
* Manual override for the target element. Useful for scenarios where a component accepts user prop to override target
|
|
311
|
+
*/
|
|
312
|
+
target?: TargetElement | null;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
export declare type PositioningRect = {
|
|
316
|
+
width: number;
|
|
317
|
+
height: number;
|
|
318
|
+
x: number;
|
|
319
|
+
y: number;
|
|
320
|
+
};
|
|
321
|
+
|
|
322
|
+
export declare type PositioningShorthand = PositioningProps | PositioningShorthandValue;
|
|
323
|
+
|
|
324
|
+
export declare type PositioningShorthandValue = 'above' | 'above-start' | 'above-end' | 'below' | 'below-start' | 'below-end' | 'before' | 'before-top' | 'before-bottom' | 'after' | 'after-top' | 'after-bottom';
|
|
325
|
+
|
|
326
|
+
export declare type PositioningVirtualElement = {
|
|
327
|
+
getBoundingClientRect: () => {
|
|
328
|
+
x: number;
|
|
329
|
+
y: number;
|
|
330
|
+
top: number;
|
|
331
|
+
left: number;
|
|
332
|
+
bottom: number;
|
|
333
|
+
right: number;
|
|
334
|
+
width: number;
|
|
335
|
+
height: number;
|
|
336
|
+
};
|
|
337
|
+
contextElement?: Element;
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
export declare function resolvePositioningShorthand(shorthand: PositioningShorthand | undefined | null): Readonly<PositioningProps>;
|
|
341
|
+
|
|
342
|
+
export declare type SetVirtualMouseTarget = (event: React_2.MouseEvent | MouseEvent | undefined | null) => void;
|
|
343
|
+
|
|
344
|
+
declare type TargetElement = HTMLElement | PositioningVirtualElement;
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* @internal
|
|
348
|
+
*/
|
|
349
|
+
export declare function usePositioning(options: PositioningProps & PositioningOptions): UsePositioningReturn;
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* A state hook that manages a popper virtual element from mouseevents.
|
|
353
|
+
* Useful for scenarios where a component needs to be positioned by mouse click (e.g. contextmenu)
|
|
354
|
+
* React synthetic events are not persisted by this hook
|
|
355
|
+
*
|
|
356
|
+
* @internal
|
|
357
|
+
* @param initialState - initializes a user provided state similare to useState
|
|
358
|
+
* @returns state and dispatcher for a Popper virtual element that uses native/synthetic mouse events
|
|
359
|
+
*/
|
|
360
|
+
export declare const usePositioningMouseTarget: (initialState?: PositioningVirtualElement | (() => PositioningVirtualElement)) => readonly [PositioningVirtualElement | undefined, SetVirtualMouseTarget];
|
|
361
|
+
|
|
362
|
+
declare interface UsePositioningReturn {
|
|
363
|
+
targetRef: React_2.MutableRefObject<any>;
|
|
364
|
+
containerRef: React_2.MutableRefObject<any>;
|
|
365
|
+
arrowRef: React_2.MutableRefObject<any>;
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* A hook that manages CSS custom properties for slide direction based on positioning placement.
|
|
370
|
+
*
|
|
371
|
+
* It wraps the `onPositioningEnd` callback to set `--fui-positioning-slide-direction-x` and
|
|
372
|
+
* `--fui-positioning-slide-direction-y` CSS custom properties on the positioned element,
|
|
373
|
+
* and registers them via `CSS.registerProperty` to avoid properties propagation down to a DOM tree.
|
|
374
|
+
*
|
|
375
|
+
* @returns The wrapped `onPositioningEnd` handler to pass to the positioning config.
|
|
376
|
+
*/
|
|
377
|
+
export declare function usePositioningSlideDirection(options: UsePositioningSlideDirectionOptions): NonNullable<PositioningProps['onPositioningEnd']>;
|
|
378
|
+
|
|
379
|
+
declare type UsePositioningSlideDirectionOptions = {
|
|
380
|
+
/** The target document for CSS.registerProperty. */
|
|
381
|
+
targetDocument: Document | undefined;
|
|
382
|
+
/** The user's original onPositioningEnd callback, if any. */
|
|
383
|
+
onPositioningEnd?: PositioningProps['onPositioningEnd'];
|
|
384
|
+
};
|
|
385
|
+
|
|
386
|
+
export declare function useSafeZoneArea({ debug, disabled, onSafeZoneEnter, onSafeZoneMove, onSafeZoneLeave, onSafeZoneTimeout, timeout, }?: UseSafeZoneOptions): {
|
|
387
|
+
containerRef: RefObjectFunction<HTMLElement>;
|
|
388
|
+
targetRef: RefObjectFunction<HTMLElement>;
|
|
389
|
+
elementToRender: JSXElement | null;
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
export declare type UseSafeZoneOptions = {
|
|
393
|
+
/** Enables debug mode: makes drawn shapes visible. */
|
|
394
|
+
debug?: boolean;
|
|
395
|
+
/** Disables the safe zone area. */
|
|
396
|
+
disabled?: boolean;
|
|
397
|
+
/** The time in milliseconds to wait before clearing the safe zone. */
|
|
398
|
+
timeout?: number;
|
|
399
|
+
/** Called when the mouse enters the safe zone. */
|
|
400
|
+
onSafeZoneEnter?: (e: React_2.MouseEvent) => void;
|
|
401
|
+
/** Called when the mouse moves within the safe zone. */
|
|
402
|
+
onSafeZoneMove?: (e: React_2.MouseEvent) => void;
|
|
403
|
+
/** Called when the mouse leaves the safe zone. */
|
|
404
|
+
onSafeZoneLeave?: (e: React_2.MouseEvent) => void;
|
|
405
|
+
/** Called when the safe zone times out, even if a cursor is still over a safe zone. */
|
|
406
|
+
onSafeZoneTimeout?: () => void;
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
export { }
|
package/lib/createArrowStyles.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { computePosition } from
|
|
2
|
-
import { isHTMLElement } from
|
|
3
|
-
import { debounce, writeArrowUpdates, writeContainerUpdates } from
|
|
4
|
-
import { listScrollParents } from
|
|
5
|
-
import { POSITIONING_END_EVENT } from
|
|
6
|
-
import { createResizeObserver } from
|
|
1
|
+
import { computePosition } from "@floating-ui/dom";
|
|
2
|
+
import { isHTMLElement } from "@fluentui/react-utilities";
|
|
3
|
+
import { debounce, writeArrowUpdates, writeContainerUpdates } from "./utils/index.js";
|
|
4
|
+
import { listScrollParents } from "./utils/listScrollParents.js";
|
|
5
|
+
import { POSITIONING_END_EVENT } from "./constants.js";
|
|
6
|
+
import { createResizeObserver } from "./utils/createResizeObserver.js";
|
|
7
7
|
/**
|
|
8
8
|
* @internal
|
|
9
9
|
* @returns manager that handles positioning out of the react lifecycle
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/createPositionManager.ts"],"sourcesContent":["import { computePosition } from '@floating-ui/dom';\nimport type { Middleware, Placement, Strategy } from '@floating-ui/dom';\nimport { isHTMLElement } from '@fluentui/react-utilities';\nimport type { OnPositioningEndEventDetail, PositionManager, PositioningPlacement, TargetElement } from './types';\nimport { debounce, writeArrowUpdates, writeContainerUpdates } from './utils';\nimport { listScrollParents } from './utils/listScrollParents';\nimport { POSITIONING_END_EVENT } from './constants';\nimport { createResizeObserver } from './utils/createResizeObserver';\n\ninterface PositionManagerOptions {\n /**\n * The positioned element\n */\n container: HTMLElement;\n /**\n * Element that the container will be anchored to\n */\n target: TargetElement;\n /**\n * Arrow that points from the container to the target\n */\n arrow: HTMLElement | null;\n /**\n * The value of the css `position` property\n * @default absolute\n */\n strategy: Strategy;\n /**\n * [Floating UI middleware](https://floating-ui.com/docs/middleware)\n */\n middleware: Middleware[];\n /**\n * [Floating UI placement](https://floating-ui.com/docs/computePosition#placement)\n */\n placement?: Placement;\n /**\n * Modifies whether popover is positioned using transform.\n * @default true\n */\n useTransform?: boolean;\n /**\n * Disables the resize observer that updates position on target or dimension change\n */\n disableUpdateOnResize?: boolean;\n}\n\n/**\n * @internal\n * @returns manager that handles positioning out of the react lifecycle\n */\nexport function createPositionManager(options: PositionManagerOptions): PositionManager {\n let isDestroyed = false;\n const {\n container,\n target,\n arrow,\n strategy,\n middleware,\n placement,\n useTransform = true,\n disableUpdateOnResize = false,\n } = options;\n const targetWindow = container.ownerDocument.defaultView;\n if (!target || !container || !targetWindow) {\n return {\n updatePosition: () => undefined,\n dispose: () => undefined,\n };\n }\n\n // When the dimensions of the target or the container change - trigger a position update\n const resizeObserver = disableUpdateOnResize\n ? null\n : createResizeObserver(targetWindow, entries => {\n // If content rect dimensions to go 0 -> very likely that `display: none` is being used to hide the element\n // In this case don't update and let users update imperatively\n const shouldUpdateOnResize = entries.every(entry => {\n return entry.contentRect.width > 0 && entry.contentRect.height > 0;\n });\n\n if (shouldUpdateOnResize) {\n updatePosition();\n }\n });\n\n let isFirstUpdate = true;\n const scrollParents: Set<HTMLElement> = new Set<HTMLElement>();\n\n // When the container is first resolved, set position `fixed` to avoid scroll jumps.\n // Without this scroll jumps can occur when the element is rendered initially and receives focus\n Object.assign(container.style, { position: 'fixed', left: 0, top: 0, margin: 0 });\n\n const forceUpdate = () => {\n // debounced update can still occur afterwards\n // early return to avoid memory leaks\n if (isDestroyed) {\n return;\n }\n\n if (isFirstUpdate) {\n listScrollParents(container).forEach(scrollParent => scrollParents.add(scrollParent));\n if (isHTMLElement(target)) {\n listScrollParents(target).forEach(scrollParent => scrollParents.add(scrollParent));\n }\n\n scrollParents.forEach(scrollParent => {\n scrollParent.addEventListener('scroll', updatePosition, { passive: true });\n });\n\n resizeObserver?.observe(container);\n if (isHTMLElement(target)) {\n resizeObserver?.observe(target);\n }\n\n isFirstUpdate = false;\n }\n\n Object.assign(container.style, { position: strategy });\n computePosition(target, container, { placement, middleware, strategy })\n .then(({ x, y, middlewareData, placement: computedPlacement }) => {\n // Promise can still resolve after destruction\n // early return to avoid applying outdated position\n if (isDestroyed) {\n return;\n }\n\n writeArrowUpdates({ arrow, middlewareData });\n writeContainerUpdates({\n container,\n middlewareData,\n placement: computedPlacement,\n coordinates: { x, y },\n lowPPI: (targetWindow?.devicePixelRatio || 1) <= 1,\n strategy,\n useTransform,\n });\n\n container.dispatchEvent(\n new CustomEvent<OnPositioningEndEventDetail>(POSITIONING_END_EVENT, {\n detail: {\n // Cast from Floating UI's Placement to the Fluent-owned PositioningPlacement.\n // These are equivalent string unions; the cast avoids leaking @floating-ui/dom\n // types into the public API surface.\n placement: computedPlacement satisfies PositioningPlacement,\n },\n }),\n );\n })\n .catch(err => {\n // https://github.com/floating-ui/floating-ui/issues/1845\n // FIXME for node > 14\n // node 15 introduces promise rejection which means that any components\n // tests need to be `it('', async () => {})` otherwise there can be race conditions with\n // JSDOM being torn down before this promise is resolved so globals like `window` and `document` don't exist\n // Unless all tests that ever use `usePositioning` are turned into async tests, any logging during testing\n // will actually be counter productive\n if (process.env.NODE_ENV === 'development') {\n // eslint-disable-next-line no-console\n console.error('[usePositioning]: Failed to calculate position', err);\n }\n });\n };\n\n const updatePosition = debounce(() => forceUpdate());\n\n const dispose = () => {\n isDestroyed = true;\n\n if (targetWindow) {\n targetWindow.removeEventListener('scroll', updatePosition);\n targetWindow.removeEventListener('resize', updatePosition);\n }\n\n scrollParents.forEach(scrollParent => {\n scrollParent.removeEventListener('scroll', updatePosition);\n });\n scrollParents.clear();\n\n resizeObserver?.disconnect();\n };\n\n if (targetWindow) {\n targetWindow.addEventListener('scroll', updatePosition, { passive: true });\n targetWindow.addEventListener('resize', updatePosition);\n }\n\n // Update the position on initialization\n updatePosition();\n\n return {\n updatePosition,\n dispose,\n };\n}\n"],"names":["computePosition","isHTMLElement","debounce","writeArrowUpdates","writeContainerUpdates","listScrollParents","POSITIONING_END_EVENT","createResizeObserver","createPositionManager","options","isDestroyed","container","target","arrow","strategy","middleware","placement","useTransform","disableUpdateOnResize","targetWindow","ownerDocument","defaultView","updatePosition","undefined","dispose","resizeObserver","entries","shouldUpdateOnResize","every","entry","contentRect","width","height","isFirstUpdate","scrollParents","Set","Object","assign","style","position","left","top","margin","forceUpdate","forEach","scrollParent","add","addEventListener","passive","observe","then","x","y","middlewareData","computedPlacement","coordinates","lowPPI","devicePixelRatio","dispatchEvent","CustomEvent","detail","catch","err","process","env","NODE_ENV","console","error","removeEventListener","clear","disconnect"],"mappings":"AAAA,SAASA,eAAe,QAAQ,mBAAmB;AAEnD,SAASC,aAAa,QAAQ,4BAA4B;AAE1D,SAASC,QAAQ,EAAEC,iBAAiB,EAAEC,qBAAqB,QAAQ,UAAU;AAC7E,SAASC,iBAAiB,QAAQ,4BAA4B;AAC9D,SAASC,qBAAqB,QAAQ,cAAc;AACpD,SAASC,oBAAoB,QAAQ,+BAA+B;AAuCpE;;;CAGC,GACD,OAAO,SAASC,sBAAsBC,OAA+B;IACnE,IAAIC,cAAc;IAClB,MAAM,EACJC,SAAS,EACTC,MAAM,EACNC,KAAK,EACLC,QAAQ,EACRC,UAAU,EACVC,SAAS,EACTC,eAAe,IAAI,EACnBC,wBAAwB,KAAK,EAC9B,GAAGT;IACJ,MAAMU,eAAeR,UAAUS,aAAa,CAACC,WAAW;IACxD,IAAI,CAACT,UAAU,CAACD,aAAa,CAACQ,cAAc;QAC1C,OAAO;YACLG,gBAAgB,IAAMC;YACtBC,SAAS,IAAMD;QACjB;IACF;IAEA,wFAAwF;IACxF,MAAME,iB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/createPositionManager.ts"],"sourcesContent":["import { computePosition } from '@floating-ui/dom';\nimport type { Middleware, Placement, Strategy } from '@floating-ui/dom';\nimport { isHTMLElement } from '@fluentui/react-utilities';\nimport type { OnPositioningEndEventDetail, PositionManager, PositioningPlacement, TargetElement } from './types';\nimport { debounce, writeArrowUpdates, writeContainerUpdates } from './utils';\nimport { listScrollParents } from './utils/listScrollParents';\nimport { POSITIONING_END_EVENT } from './constants';\nimport { createResizeObserver } from './utils/createResizeObserver';\n\ninterface PositionManagerOptions {\n /**\n * The positioned element\n */\n container: HTMLElement;\n /**\n * Element that the container will be anchored to\n */\n target: TargetElement;\n /**\n * Arrow that points from the container to the target\n */\n arrow: HTMLElement | null;\n /**\n * The value of the css `position` property\n * @default absolute\n */\n strategy: Strategy;\n /**\n * [Floating UI middleware](https://floating-ui.com/docs/middleware)\n */\n middleware: Middleware[];\n /**\n * [Floating UI placement](https://floating-ui.com/docs/computePosition#placement)\n */\n placement?: Placement;\n /**\n * Modifies whether popover is positioned using transform.\n * @default true\n */\n useTransform?: boolean;\n /**\n * Disables the resize observer that updates position on target or dimension change\n */\n disableUpdateOnResize?: boolean;\n}\n\n/**\n * @internal\n * @returns manager that handles positioning out of the react lifecycle\n */\nexport function createPositionManager(options: PositionManagerOptions): PositionManager {\n let isDestroyed = false;\n const {\n container,\n target,\n arrow,\n strategy,\n middleware,\n placement,\n useTransform = true,\n disableUpdateOnResize = false,\n } = options;\n const targetWindow = container.ownerDocument.defaultView;\n if (!target || !container || !targetWindow) {\n return {\n updatePosition: () => undefined,\n dispose: () => undefined,\n };\n }\n\n // When the dimensions of the target or the container change - trigger a position update\n const resizeObserver = disableUpdateOnResize\n ? null\n : createResizeObserver(targetWindow, entries => {\n // If content rect dimensions to go 0 -> very likely that `display: none` is being used to hide the element\n // In this case don't update and let users update imperatively\n const shouldUpdateOnResize = entries.every(entry => {\n return entry.contentRect.width > 0 && entry.contentRect.height > 0;\n });\n\n if (shouldUpdateOnResize) {\n updatePosition();\n }\n });\n\n let isFirstUpdate = true;\n const scrollParents: Set<HTMLElement> = new Set<HTMLElement>();\n\n // When the container is first resolved, set position `fixed` to avoid scroll jumps.\n // Without this scroll jumps can occur when the element is rendered initially and receives focus\n Object.assign(container.style, { position: 'fixed', left: 0, top: 0, margin: 0 });\n\n const forceUpdate = () => {\n // debounced update can still occur afterwards\n // early return to avoid memory leaks\n if (isDestroyed) {\n return;\n }\n\n if (isFirstUpdate) {\n listScrollParents(container).forEach(scrollParent => scrollParents.add(scrollParent));\n if (isHTMLElement(target)) {\n listScrollParents(target).forEach(scrollParent => scrollParents.add(scrollParent));\n }\n\n scrollParents.forEach(scrollParent => {\n scrollParent.addEventListener('scroll', updatePosition, { passive: true });\n });\n\n resizeObserver?.observe(container);\n if (isHTMLElement(target)) {\n resizeObserver?.observe(target);\n }\n\n isFirstUpdate = false;\n }\n\n Object.assign(container.style, { position: strategy });\n computePosition(target, container, { placement, middleware, strategy })\n .then(({ x, y, middlewareData, placement: computedPlacement }) => {\n // Promise can still resolve after destruction\n // early return to avoid applying outdated position\n if (isDestroyed) {\n return;\n }\n\n writeArrowUpdates({ arrow, middlewareData });\n writeContainerUpdates({\n container,\n middlewareData,\n placement: computedPlacement,\n coordinates: { x, y },\n lowPPI: (targetWindow?.devicePixelRatio || 1) <= 1,\n strategy,\n useTransform,\n });\n\n container.dispatchEvent(\n new CustomEvent<OnPositioningEndEventDetail>(POSITIONING_END_EVENT, {\n detail: {\n // Cast from Floating UI's Placement to the Fluent-owned PositioningPlacement.\n // These are equivalent string unions; the cast avoids leaking @floating-ui/dom\n // types into the public API surface.\n placement: computedPlacement satisfies PositioningPlacement,\n },\n }),\n );\n })\n .catch(err => {\n // https://github.com/floating-ui/floating-ui/issues/1845\n // FIXME for node > 14\n // node 15 introduces promise rejection which means that any components\n // tests need to be `it('', async () => {})` otherwise there can be race conditions with\n // JSDOM being torn down before this promise is resolved so globals like `window` and `document` don't exist\n // Unless all tests that ever use `usePositioning` are turned into async tests, any logging during testing\n // will actually be counter productive\n if (process.env.NODE_ENV === 'development') {\n // eslint-disable-next-line no-console\n console.error('[usePositioning]: Failed to calculate position', err);\n }\n });\n };\n\n const updatePosition = debounce(() => forceUpdate());\n\n const dispose = () => {\n isDestroyed = true;\n\n if (targetWindow) {\n targetWindow.removeEventListener('scroll', updatePosition);\n targetWindow.removeEventListener('resize', updatePosition);\n }\n\n scrollParents.forEach(scrollParent => {\n scrollParent.removeEventListener('scroll', updatePosition);\n });\n scrollParents.clear();\n\n resizeObserver?.disconnect();\n };\n\n if (targetWindow) {\n targetWindow.addEventListener('scroll', updatePosition, { passive: true });\n targetWindow.addEventListener('resize', updatePosition);\n }\n\n // Update the position on initialization\n updatePosition();\n\n return {\n updatePosition,\n dispose,\n };\n}\n"],"names":["computePosition","isHTMLElement","debounce","writeArrowUpdates","writeContainerUpdates","listScrollParents","POSITIONING_END_EVENT","createResizeObserver","createPositionManager","options","isDestroyed","container","target","arrow","strategy","middleware","placement","useTransform","disableUpdateOnResize","targetWindow","ownerDocument","defaultView","updatePosition","undefined","dispose","resizeObserver","entries","shouldUpdateOnResize","every","entry","contentRect","width","height","isFirstUpdate","scrollParents","Set","Object","assign","style","position","left","top","margin","forceUpdate","forEach","scrollParent","add","addEventListener","passive","observe","then","x","y","middlewareData","computedPlacement","coordinates","lowPPI","devicePixelRatio","dispatchEvent","CustomEvent","detail","catch","err","process","env","NODE_ENV","console","error","removeEventListener","clear","disconnect"],"mappings":"AAAA,SAASA,eAAe,QAAQ,mBAAmB;AAEnD,SAASC,aAAa,QAAQ,4BAA4B;AAE1D,SAASC,QAAQ,EAAEC,iBAAiB,EAAEC,qBAAqB,QAAQ,mBAAU;AAC7E,SAASC,iBAAiB,QAAQ,+BAA4B;AAC9D,SAASC,qBAAqB,QAAQ,iBAAc;AACpD,SAASC,oBAAoB,QAAQ,kCAA+B;AAuCpE;;;CAGC,GACD,OAAO,SAASC,sBAAsBC,OAA+B;IACnE,IAAIC,cAAc;IAClB,MAAM,E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AAmB,CAAC,UAAU9C;QAC7C;QACAY,cAAcmC,KAAK;QAEnB5C,2BAAAA,qCAAAA,eAAgB6C,UAAU;IAC5B;IAEA,IAAInD,cAAc;QAChBA,aAAa4B,gBAAgB,CAAC,UAAUzB,gBAAgB;YAAE0B,SAAS;QAAK;QACxE7B,aAAa4B,gBAAgB,CAAC,UAAUzB;IAC1C;IAEA,wCAAwC;IACxCA;IAEA,OAAO;QACLA;QACAE;IACF;AACF"}
|
package/lib/createSlideStyles.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { tokens } from
|
|
2
|
-
import { DATA_POSITIONING_PLACEMENT } from
|
|
1
|
+
import { tokens } from "@fluentui/react-theme";
|
|
2
|
+
import { DATA_POSITIONING_PLACEMENT } from "./constants.js";
|
|
3
3
|
/**
|
|
4
4
|
* Creates animation styles so that positioned elements slide in from the main axis
|
|
5
5
|
* @param mainAxis - distance than the element sides for
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/createSlideStyles.ts"],"sourcesContent":["import { tokens } from '@fluentui/react-theme';\nimport type { GriffelStyle } from '@griffel/react';\nimport { DATA_POSITIONING_PLACEMENT } from './constants';\n\n/**\n * Creates animation styles so that positioned elements slide in from the main axis\n * @param mainAxis - distance than the element sides for\n * @returns Griffel styles to spread to a slot\n *\n * @deprecated The popover-related components now use the Slide motion component,\n * which they inject using the `surfaceMotion` slot.\n */\nexport function createSlideStyles(mainAxis: number): GriffelStyle {\n // With 'accumulate' animation composition, these opacity keyframes are added onto the default opacity of 1.\n const fadeIn = {\n from: {\n opacity: -1, // becomes opacity: 0\n },\n to: {\n opacity: 0, // becomes opacity: 1\n },\n };\n\n const slideDistanceVarX = '--fui-positioning-slide-distance-x';\n const slideDistanceVarY = '--fui-positioning-slide-distance-y';\n\n return {\n // NOTE: there was a previous attempt to give fadeIn a separate composition mode:\n // animationComposition: 'replace, accumulate',\n // but somehow this was linked to a performance regression observed in Teams (bug #4255933)\n animationComposition: 'accumulate',\n animationDuration: tokens.durationSlower,\n animationTimingFunction: tokens.curveDecelerateMid,\n [slideDistanceVarX]: `0px`,\n [slideDistanceVarY]: `${mainAxis}px`,\n [`&[${DATA_POSITIONING_PLACEMENT}^=right]`]: {\n [slideDistanceVarX]: `-${mainAxis}px`,\n [slideDistanceVarY]: '0px',\n },\n\n [`&[${DATA_POSITIONING_PLACEMENT}^=bottom]`]: {\n [slideDistanceVarX]: '0px',\n [slideDistanceVarY]: `-${mainAxis}px`,\n },\n\n [`&[${DATA_POSITIONING_PLACEMENT}^=left]`]: {\n [slideDistanceVarX]: `${mainAxis}px`,\n [slideDistanceVarY]: '0px',\n },\n\n animationName: [\n fadeIn,\n {\n from: {\n transform: `translate(var(${slideDistanceVarX}), var(${slideDistanceVarY}))`,\n },\n to: {},\n },\n ],\n\n // Note: at-rules have more specificity in Griffel\n '@media(prefers-reduced-motion)': {\n [`&[${DATA_POSITIONING_PLACEMENT}]`]: {\n animationDuration: '1ms',\n animationName: fadeIn,\n },\n },\n\n // Tested in Firefox 79\n '@supports not (animation-composition: accumulate)': {\n [`&[${DATA_POSITIONING_PLACEMENT}]`]: {\n animationName: fadeIn,\n },\n },\n };\n}\n"],"names":["tokens","DATA_POSITIONING_PLACEMENT","createSlideStyles","mainAxis","fadeIn","from","opacity","to","slideDistanceVarX","slideDistanceVarY","animationComposition","animationDuration","durationSlower","animationTimingFunction","curveDecelerateMid","animationName","transform"],"mappings":"AAAA,SAASA,MAAM,QAAQ,wBAAwB;AAE/C,SAASC,0BAA0B,QAAQ,
|
|
1
|
+
{"version":3,"sources":["../src/createSlideStyles.ts"],"sourcesContent":["import { tokens } from '@fluentui/react-theme';\nimport type { GriffelStyle } from '@griffel/react';\nimport { DATA_POSITIONING_PLACEMENT } from './constants';\n\n/**\n * Creates animation styles so that positioned elements slide in from the main axis\n * @param mainAxis - distance than the element sides for\n * @returns Griffel styles to spread to a slot\n *\n * @deprecated The popover-related components now use the Slide motion component,\n * which they inject using the `surfaceMotion` slot.\n */\nexport function createSlideStyles(mainAxis: number): GriffelStyle {\n // With 'accumulate' animation composition, these opacity keyframes are added onto the default opacity of 1.\n const fadeIn = {\n from: {\n opacity: -1, // becomes opacity: 0\n },\n to: {\n opacity: 0, // becomes opacity: 1\n },\n };\n\n const slideDistanceVarX = '--fui-positioning-slide-distance-x';\n const slideDistanceVarY = '--fui-positioning-slide-distance-y';\n\n return {\n // NOTE: there was a previous attempt to give fadeIn a separate composition mode:\n // animationComposition: 'replace, accumulate',\n // but somehow this was linked to a performance regression observed in Teams (bug #4255933)\n animationComposition: 'accumulate',\n animationDuration: tokens.durationSlower,\n animationTimingFunction: tokens.curveDecelerateMid,\n [slideDistanceVarX]: `0px`,\n [slideDistanceVarY]: `${mainAxis}px`,\n [`&[${DATA_POSITIONING_PLACEMENT}^=right]`]: {\n [slideDistanceVarX]: `-${mainAxis}px`,\n [slideDistanceVarY]: '0px',\n },\n\n [`&[${DATA_POSITIONING_PLACEMENT}^=bottom]`]: {\n [slideDistanceVarX]: '0px',\n [slideDistanceVarY]: `-${mainAxis}px`,\n },\n\n [`&[${DATA_POSITIONING_PLACEMENT}^=left]`]: {\n [slideDistanceVarX]: `${mainAxis}px`,\n [slideDistanceVarY]: '0px',\n },\n\n animationName: [\n fadeIn,\n {\n from: {\n transform: `translate(var(${slideDistanceVarX}), var(${slideDistanceVarY}))`,\n },\n to: {},\n },\n ],\n\n // Note: at-rules have more specificity in Griffel\n '@media(prefers-reduced-motion)': {\n [`&[${DATA_POSITIONING_PLACEMENT}]`]: {\n animationDuration: '1ms',\n animationName: fadeIn,\n },\n },\n\n // Tested in Firefox 79\n '@supports not (animation-composition: accumulate)': {\n [`&[${DATA_POSITIONING_PLACEMENT}]`]: {\n animationName: fadeIn,\n },\n },\n };\n}\n"],"names":["tokens","DATA_POSITIONING_PLACEMENT","createSlideStyles","mainAxis","fadeIn","from","opacity","to","slideDistanceVarX","slideDistanceVarY","animationComposition","animationDuration","durationSlower","animationTimingFunction","curve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AC,EAAE;gBACpCU,mBAAmB;gBACnBI,eAAeX;YACjB;QACF;QAEA,uBAAuB;QACvB,qDAAqD;YACnD,CAAC,CAAC,EAAE,EAAEH,2BAA2B,CAAC,CAAC,CAAC,EAAE;gBACpCc,eAAeX;YACjB;QACF;IACF;AACF"}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import { mergeClasses } from
|
|
3
|
-
import { useId } from
|
|
4
|
-
import * as React from
|
|
5
|
-
import { useSyncExternalStore } from
|
|
6
|
-
import { getRectCorners } from
|
|
7
|
-
import { getMouseAnchor } from
|
|
8
|
-
import { pointsToSvgPath } from
|
|
9
|
-
import { useStyles } from
|
|
10
|
-
import { computeOutsideClipPath } from
|
|
2
|
+
import { mergeClasses } from "@griffel/react";
|
|
3
|
+
import { useId } from "@fluentui/react-utilities";
|
|
4
|
+
import * as React from "react";
|
|
5
|
+
import { useSyncExternalStore } from "use-sync-external-store/shim";
|
|
6
|
+
import { getRectCorners } from "./getRectCorners.js";
|
|
7
|
+
import { getMouseAnchor } from "./getMouseAnchor.js";
|
|
8
|
+
import { pointsToSvgPath } from "./pointsToSvgPath.js";
|
|
9
|
+
import { useStyles } from "./SafeZoneArea.styles.js";
|
|
10
|
+
import { computeOutsideClipPath } from "./computeOutsideClipPath.js";
|
|
11
11
|
// ---
|
|
12
12
|
const EMPTY_RECT = {
|
|
13
13
|
top: 0,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/hooks/useSafeZoneArea/SafeZoneArea.tsx"],"sourcesContent":["'use client';\n\nimport { mergeClasses } from '@griffel/react';\nimport { useId } from '@fluentui/react-utilities';\nimport type { JSXElement } from '@fluentui/react-utilities';\nimport * as React from 'react';\nimport { useSyncExternalStore } from 'use-sync-external-store/shim';\n\nimport type { createSafeZoneAreaStateStore } from './createSafeZoneAreaStateStore';\nimport { getRectCorners } from './getRectCorners';\nimport { getMouseAnchor } from './getMouseAnchor';\nimport { pointsToSvgPath } from './pointsToSvgPath';\nimport { useStyles } from './SafeZoneArea.styles';\nimport type { Point } from './types';\nimport { computeOutsideClipPath } from './computeOutsideClipPath';\n\nexport type SafeZoneAreaImperativeHandle = {\n updateSVG: (options: { containerRect: DOMRect; targetRect: DOMRect; mouseCoordinates: Point }) => void;\n};\n\nexport type SafeZoneAreaProps = {\n /** Enables debug mode: makes drawn shapes visible. */\n debug: boolean;\n\n /** A reference to the SafeZoneArea imperative handle. */\n imperativeRef: React.Ref<SafeZoneAreaImperativeHandle>;\n\n // eslint-disable-next-line @nx/workspace-consistent-callback-type\n onMouseEnter: (e: React.MouseEvent) => void;\n // eslint-disable-next-line @nx/workspace-consistent-callback-type\n onMouseMove: (e: React.MouseEvent) => void;\n // eslint-disable-next-line @nx/workspace-consistent-callback-type\n onMouseLeave: (e: React.MouseEvent) => void;\n\n stateStore: ReturnType<typeof createSafeZoneAreaStateStore>;\n};\n\n/**\n * @internal\n */\ntype SafeZoneAreaState = {\n containerRect: DOMRect;\n targetRect: DOMRect;\n mouseCoordinates: Point;\n};\n\n// ---\n\nconst EMPTY_RECT: DOMRect = {\n top: 0,\n right: 0,\n bottom: 0,\n left: 0,\n width: 0,\n height: 0,\n x: 0,\n y: 0,\n toJSON() {\n return '';\n },\n};\n\nexport function isSameRect(a: DOMRect, b: DOMRect): boolean {\n return (\n a.top === b.top &&\n a.right === b.right &&\n a.bottom === b.bottom &&\n a.left === b.left &&\n a.width === b.width &&\n a.height === b.height\n );\n}\n\nexport function isSameCoordinates(a: Point, b: Point): boolean {\n return a[0] === b[0] && a[1] === b[1];\n}\n\n// ---\n\n/**\n * A component that renders a safe zone area with SVG shapes. Uses `useSyncExternalStore` to manage its active state\n * to avoid causing re-renders in `useSafeZoneArea()` as the hook might be used in host components like `Menu`.\n *\n * Draws two shapes:\n * - a triangle that points to the target element which is an actual safe zone\n * - a rectangle for a clip path that clips out the target element\n *\n * @internal\n */\nexport const SafeZoneArea = React.memo((props: SafeZoneAreaProps): JSXElement => {\n const { debug, onMouseEnter, onMouseMove, onMouseLeave, stateStore } = props;\n\n const clipPathId = useId();\n const styles = useStyles();\n\n const active = useSyncExternalStore(stateStore.subscribe, stateStore.isActive);\n const svgRef = React.useRef<SVGSVGElement>(null);\n\n const [state, setState] = React.useState<SafeZoneAreaState>(() => ({\n containerRect: EMPTY_RECT,\n targetRect: EMPTY_RECT,\n mouseCoordinates: [0, 0],\n }));\n\n React.useImperativeHandle(\n props.imperativeRef,\n () => ({\n updateSVG(newState) {\n setState(prevState => {\n // Heads up!\n // A small optimization to avoid unnecessary re-renders\n if (\n isSameRect(prevState.containerRect, newState.containerRect) &&\n isSameRect(prevState.targetRect, newState.targetRect) &&\n isSameCoordinates(prevState.mouseCoordinates, newState.mouseCoordinates)\n ) {\n return prevState;\n }\n\n return newState;\n });\n },\n }),\n [],\n );\n\n const { containerRect, targetRect, mouseCoordinates } = state;\n\n const topOffset = Math.min(targetRect.top, containerRect.top);\n const leftOffset = Math.min(targetRect.left, containerRect.left);\n const bottomOffset = Math.max(targetRect.bottom, containerRect.bottom);\n const rightOffset = Math.max(targetRect.right, containerRect.right);\n\n // ---\n\n const containerCorners = getRectCorners(containerRect, [leftOffset, topOffset]);\n const targetCorners = getRectCorners(targetRect, [leftOffset, topOffset]);\n\n // Heads up!\n // The SVG coordinate system starts at the top-left corner of the SVG element,\n // so we need to adjust the mouse coordinates relative to the SVG's top-left corner.\n const relativeMouseCoordinates: Point = [mouseCoordinates[0] - leftOffset, mouseCoordinates[1] - topOffset];\n const mouseAnchor = getMouseAnchor(containerCorners.topLeft, containerCorners.bottomRight, relativeMouseCoordinates);\n\n const triangleA = [mouseAnchor, containerCorners.topLeft, containerCorners.topRight];\n const triangleB = [mouseAnchor, containerCorners.topRight, containerCorners.bottomRight];\n const triangleC = [mouseAnchor, containerCorners.bottomRight, containerCorners.bottomLeft];\n const triangleD = [mouseAnchor, containerCorners.bottomLeft, containerCorners.topLeft];\n\n const svgWidth = rightOffset - leftOffset;\n const svgHeight = bottomOffset - topOffset;\n\n const clipPath = computeOutsideClipPath(\n svgWidth,\n svgHeight,\n {\n x: targetCorners.topLeft[0],\n y: targetCorners.topLeft[1],\n width: targetRect.width,\n height: targetRect.height,\n },\n {\n x: containerCorners.topLeft[0],\n y: containerCorners.topLeft[1],\n width: containerRect.width,\n height: containerRect.height,\n },\n );\n\n return (\n <div className={mergeClasses(styles.wrapper, active && styles.wrapperActive)} data-safe-zone=\"\">\n {active ? (\n <svg\n aria-hidden\n className={styles.svg}\n xmlns=\"http://www.w3.org/2000/svg\"\n ref={svgRef}\n style={{\n width: `${svgWidth}px`,\n height: `${svgHeight}px`,\n transform: `translate(${leftOffset}px, ${topOffset}px)`,\n }}\n >\n <g\n className={mergeClasses(styles.triangle, debug && styles.triangleDebug)}\n clipPath={`url(#${clipPathId})`}\n onMouseEnter={onMouseEnter}\n onMouseMove={onMouseMove}\n onMouseLeave={onMouseLeave}\n >\n <path d={pointsToSvgPath(triangleA)} />\n <path d={pointsToSvgPath(triangleB)} />\n <path d={pointsToSvgPath(triangleC)} />\n <path d={pointsToSvgPath(triangleD)} />\n </g>\n\n <clipPath id={clipPathId}>\n <path d={clipPath} />\n </clipPath>\n\n {debug && <path className={styles.rectDebug} d={clipPath} />}\n </svg>\n ) : null}\n </div>\n );\n});\n"],"names":["mergeClasses","useId","React","useSyncExternalStore","getRectCorners","getMouseAnchor","pointsToSvgPath","useStyles","computeOutsideClipPath","EMPTY_RECT","top","right","bottom","left","width","height","x","y","toJSON","isSameRect","a","b","isSameCoordinates","SafeZoneArea","memo","props","debug","onMouseEnter","onMouseMove","onMouseLeave","stateStore","clipPathId","styles","active","subscribe","isActive","svgRef","useRef","state","setState","useState","containerRect","targetRect","mouseCoordinates","useImperativeHandle","imperativeRef","updateSVG","newState","prevState","topOffset","Math","min","leftOffset","bottomOffset","max","rightOffset","containerCorners","targetCorners","relativeMouseCoordinates","mouseAnchor","topLeft","bottomRight","triangleA","topRight","triangleB","triangleC","bottomLeft","triangleD","svgWidth","svgHeight","clipPath","div","className","wrapper","wrapperActive","data-safe-zone","svg","aria-hidden","xmlns","ref","style","transform","g","triangle","triangleDebug","path","d","id","rectDebug"],"mappings":"AAAA;AAEA,SAASA,YAAY,QAAQ,iBAAiB;AAC9C,SAASC,KAAK,QAAQ,4BAA4B;AAElD,YAAYC,WAAW,QAAQ;AAC/B,SAASC,oBAAoB,QAAQ,+BAA+B;AAGpE,SAASC,cAAc,QAAQ,mBAAmB;AAClD,SAASC,cAAc,QAAQ,mBAAmB;AAClD,SAASC,eAAe,QAAQ,oBAAoB;AACpD,SAASC,SAAS,QAAQ,wBAAwB;AAElD,SAASC,sBAAsB,QAAQ,2BAA2B;AAgClE,MAAM;AAEN,MAAMC,aAAsB;IAC1BC,KAAK;IACLC,OAAO;IACPC,QAAQ;IACRC,MAAM;IACNC,OAAO;IACPC,QAAQ;IACRC,GAAG;IACHC,GAAG;IACHC;QACE,OAAO;IACT;AACF;AAEA,OAAO,SAASC,WAAWC,CAAU,EAAEC,CAAU;IAC/C,OACED,EAAEV,GAAG,KAAKW,EAAEX,GAAG,IACfU,EAAET,KAAK,KAAKU,EAAEV,KAAK,IACnBS,EAAER,MAAM,KAAKS,EAAET,MAAM,IACrBQ,EAAEP,IAAI,KAAKQ,EAAER,IAAI,IACjBO,EAAEN,KAAK,KAAKO,EAAEP,KAAK,IACnBM,EAAEL,MAAM,KAAKM,EAAEN,MAAM;AAEzB;AAEA,OAAO,SAASO,kBAAkBF,CAAQ,EAAEC,CAAQ;IAClD,OAAOD,CAAC,CAAC,EAAE,KAAKC,CAAC,CAAC,EAAE,IAAID,CAAC,CAAC,EAAE,KAAKC,CAAC,CAAC,EAAE;AACvC;AAEA,MAAM;AAEN;;;;;;;;;CASC,GACD,OAAO,MAAME,6BAAerB,MAAMsB,IAAI,CAAC,CAACC;IACtC,MAAM,EAAEC,KAAK,EAAEC,YAAY,EAAEC,WAAW,EAAEC,YAAY,EAAEC,UAAU,EAAE,GAAGL;IAEvE,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E7B,WAAW,IAAI,EAAEH,UAAU,GAAG,CAAC;QACzD;qBAEA,oBAACiC;QACCV,WAAWxE,aAAagC,OAAOmD,QAAQ,EAAEzD,SAASM,OAAOoD,aAAa;QACtEd,UAAU,CAAC,KAAK,EAAEvC,WAAW,CAAC,CAAC;QAC/BJ,cAAcA;QACdC,aAAaA;QACbC,cAAcA;qBAEd,oBAACwD;QAAKC,GAAGhF,gBAAgBwD;sBACzB,oBAACuB;QAAKC,GAAGhF,gBAAgB0D;sBACzB,oBAACqB;QAAKC,GAAGhF,gBAAgB2D;sBACzB,oBAACoB;QAAKC,GAAGhF,gBAAgB6D;uBAG3B,oBAACG;QAASiB,IAAIxD;qBACZ,oBAACsD;QAAKC,GAAGhB;SAGV5C,uBAAS,oBAAC2D;QAAKb,WAAWxC,OAAOwD,SAAS;QAAEF,GAAGhB;UAEhD;AAGV,GAAG"}
|
|
1
|
+
{"version":3,"sources":["../src/hooks/useSafeZoneArea/SafeZoneArea.tsx"],"sourcesContent":["'use client';\n\nimport { mergeClasses } from '@griffel/react';\nimport { useId } from '@fluentui/react-utilities';\nimport type { JSXElement } from '@fluentui/react-utilities';\nimport * as React from 'react';\nimport { useSyncExternalStore } from 'use-sync-external-store/shim';\n\nimport type { createSafeZoneAreaStateStore } from './createSafeZoneAreaStateStore';\nimport { getRectCorners } from './getRectCorners';\nimport { getMouseAnchor } from './getMouseAnchor';\nimport { pointsToSvgPath } from './pointsToSvgPath';\nimport { useStyles } from './SafeZoneArea.styles';\nimport type { Point } from './types';\nimport { computeOutsideClipPath } from './computeOutsideClipPath';\n\nexport type SafeZoneAreaImperativeHandle = {\n updateSVG: (options: { containerRect: DOMRect; targetRect: DOMRect; mouseCoordinates: Point }) => void;\n};\n\nexport type SafeZoneAreaProps = {\n /** Enables debug mode: makes drawn shapes visible. */\n debug: boolean;\n\n /** A reference to the SafeZoneArea imperative handle. */\n imperativeRef: React.Ref<SafeZoneAreaImperativeHandle>;\n\n // eslint-disable-next-line @nx/workspace-consistent-callback-type\n onMouseEnter: (e: React.MouseEvent) => void;\n // eslint-disable-next-line @nx/workspace-consistent-callback-type\n onMouseMove: (e: React.MouseEvent) => void;\n // eslint-disable-next-line @nx/workspace-consistent-callback-type\n onMouseLeave: (e: React.MouseEvent) => void;\n\n stateStore: ReturnType<typeof createSafeZoneAreaStateStore>;\n};\n\n/**\n * @internal\n */\ntype SafeZoneAreaState = {\n containerRect: DOMRect;\n targetRect: DOMRect;\n mouseCoordinates: Point;\n};\n\n// ---\n\nconst EMPTY_RECT: DOMRect = {\n top: 0,\n right: 0,\n bottom: 0,\n left: 0,\n width: 0,\n height: 0,\n x: 0,\n y: 0,\n toJSON() {\n return '';\n },\n};\n\nexport function isSameRect(a: DOMRect, b: DOMRect): boolean {\n return (\n a.top === b.top &&\n a.right === b.right &&\n a.bottom === b.bottom &&\n a.left === b.left &&\n a.width === b.width &&\n a.height === b.height\n );\n}\n\nexport function isSameCoordinates(a: Point, b: Point): boolean {\n return a[0] === b[0] && a[1] === b[1];\n}\n\n// ---\n\n/**\n * A component that renders a safe zone area with SVG shapes. Uses `useSyncExternalStore` to manage its active state\n * to avoid causing re-renders in `useSafeZoneArea()` as the hook might be used in host components like `Menu`.\n *\n * Draws two shapes:\n * - a triangle that points to the target element which is an actual safe zone\n * - a rectangle for a clip path that clips out the target element\n *\n * @internal\n */\nexport const SafeZoneArea = React.memo((props: SafeZoneAreaProps): JSXElement => {\n const { debug, onMouseEnter, onMouseMove, onMouseLeave, stateStore } = props;\n\n const clipPathId = useId();\n const styles = useStyles();\n\n const active = useSyncExternalStore(stateStore.subscribe, stateStore.isActive);\n const svgRef = React.useRef<SVGSVGElement>(null);\n\n const [state, setState] = React.useState<SafeZoneAreaState>(() => ({\n containerRect: EMPTY_RECT,\n targetRect: EMPTY_RECT,\n mouseCoordinates: [0, 0],\n }));\n\n React.useImperativeHandle(\n props.imperativeRef,\n () => ({\n updateSVG(newState) {\n setState(prevState => {\n // Heads up!\n // A small optimization to avoid unnecessary re-renders\n if (\n isSameRect(prevState.containerRect, newState.containerRect) &&\n isSameRect(prevState.targetRect, newState.targetRect) &&\n isSameCoordinates(prevState.mouseCoordinates, newState.mouseCoordinates)\n ) {\n return prevState;\n }\n\n return newState;\n });\n },\n }),\n [],\n );\n\n const { containerRect, targetRect, mouseCoordinates } = state;\n\n const topOffset = Math.min(targetRect.top, containerRect.top);\n const leftOffset = Math.min(targetRect.left, containerRect.left);\n const bottomOffset = Math.max(targetRect.bottom, containerRect.bottom);\n const rightOffset = Math.max(targetRect.right, containerRect.right);\n\n // ---\n\n const containerCorners = getRectCorners(containerRect, [leftOffset, topOffset]);\n const targetCorners = getRectCorners(targetRect, [leftOffset, topOffset]);\n\n // Heads up!\n // The SVG coordinate system starts at the top-left corner of the SVG element,\n // so we need to adjust the mouse coordinates relative to the SVG's top-left corner.\n const relativeMouseCoordinates: Point = [mouseCoordinates[0] - leftOffset, mouseCoordinates[1] - topOffset];\n const mouseAnchor = getMouseAnchor(containerCorners.topLeft, containerCorners.bottomRight, relativeMouseCoordinates);\n\n const triangleA = [mouseAnchor, containerCorners.topLeft, containerCorners.topRight];\n const triangleB = [mouseAnchor, containerCorners.topRight, containerCorners.bottomRight];\n const triangleC = [mouseAnchor, containerCorners.bottomRight, containerCorners.bottomLeft];\n const triangleD = [mouseAnchor, containerCorners.bottomLeft, containerCorners.topLeft];\n\n const svgWidth = rightOffset - leftOffset;\n const svgHeight = bottomOffset - topOffset;\n\n const clipPath = computeOutsideClipPath(\n svgWidth,\n svgHeight,\n {\n x: targetCorners.topLeft[0],\n y: targetCorners.topLeft[1],\n width: targetRect.width,\n height: targetRect.height,\n },\n {\n x: containerCorners.topLeft[0],\n y: containerCorners.topLeft[1],\n width: containerRect.width,\n height: containerRect.height,\n },\n );\n\n return (\n <div className={mergeClasses(styles.wrapper, active && styles.wrapperActive)} data-safe-zone=\"\">\n {active ? (\n <svg\n aria-hidden\n className={styles.svg}\n xmlns=\"http://www.w3.org/2000/svg\"\n ref={svgRef}\n style={{\n width: `${svgWidth}px`,\n height: `${svgHeight}px`,\n transform: `translate(${leftOffset}px, ${topOffset}px)`,\n }}\n >\n <g\n className={mergeClasses(styles.triangle, debug && styles.triangleDebug)}\n clipPath={`url(#${clipPathId})`}\n onMouseEnter={onMouseEnter}\n onMouseMove={onMouseMove}\n onMouseLeave={onMouseLeave}\n >\n <path d={pointsToSvgPath(triangleA)} />\n <path d={pointsToSvgPath(triangleB)} />\n <path d={pointsToSvgPath(triangleC)} />\n <path d={pointsToSvgPath(triangleD)} />\n </g>\n\n <clipPath id={clipPathId}>\n <path d={clipPath} />\n </clipPath>\n\n {debug && <path className={styles.rectDebug} d={clipPath} />}\n </svg>\n ) : null}\n </div>\n );\n});\n"],"names":["mergeClasses","useId","React","useSyncExternalStore","getRectCorners","getMouseAnchor","pointsToSvgPath","useStyles","computeOutsideClipPath","EMPTY_RECT","top","right","bottom","left","width","height","x","y","toJSON","isSameRect","a","b","isSameCoordinates","SafeZoneArea","memo","props","debug","onMouseEnter","onMouseMove","onMouseLeave","stateStore","clipPathId","styles","active","subscribe","isActive","svgRef","useRef","state","setState","useState","containerRect","targetRect","mouseCoordinates","useImperativeHandle","imperativeRef","updateSVG","newState","prevState","topOffset","Math","min","leftOffset","bottomOffset","max","rightOffset","containerCorners","targetCorners","relativeMouseCoordinates","mouseAnchor","topLeft","bottomRight","triangleA","topRight","triangleB","triangleC","bottomLeft","triangleD","svgWidth","svgHeight","clipPath","div","className","wrapper","wrapperActive","data-safe-zone","svg","aria-hidden","xmlns","ref","style","transform","g","triangle","triangleDebug","path","d","id","rectDebug"],"mappings":"AAAA;AAEA,SAASA,YAAY,QAAQ,iBAAiB;AAC9C,SAASC,KAAK,QAAQ,4BAA4B;AAElD,YAAYC,WAAW,QAAQ;AAC/B,SAASC,oBAAoB,QAAQ,+BAA+B;AAGpE,SAASC,cAAc,QAAQ,sBAAmB;AAClD,SAASC,cAAc,QAAQ,sBAAmB;AAClD,SAASC,eAAe,QAAQ,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