@fluentui/react-positioning 0.0.0-nightly-20250606-0405.1 → 0.0.0-nightly-20250610-0406.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -7
- package/dist/index.d.ts +24 -0
- package/lib/SafeZoneArea.js +306 -0
- package/lib/SafeZoneArea.js.map +1 -0
- package/lib/SafeZoneArea.styles.js +34 -0
- package/lib/SafeZoneArea.styles.js.map +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/useSafeZoneArea.js +145 -0
- package/lib/useSafeZoneArea.js.map +1 -0
- package/lib-commonjs/PositioningConfigurationContext.js +1 -1
- package/lib-commonjs/PositioningConfigurationContext.js.map +1 -1
- package/lib-commonjs/SafeZoneArea.js +316 -0
- package/lib-commonjs/SafeZoneArea.js.map +1 -0
- package/lib-commonjs/SafeZoneArea.styles.js +63 -0
- package/lib-commonjs/SafeZoneArea.styles.js.map +1 -0
- package/lib-commonjs/constants.js.map +1 -1
- package/lib-commonjs/createArrowStyles.js.map +1 -1
- package/lib-commonjs/createPositionManager.js.map +1 -1
- package/lib-commonjs/createSlideStyles.js.map +1 -1
- package/lib-commonjs/createVirtualElementFromClick.js +4 -1
- package/lib-commonjs/createVirtualElementFromClick.js.map +1 -1
- package/lib-commonjs/index.js +4 -0
- package/lib-commonjs/index.js.map +1 -1
- package/lib-commonjs/middleware/coverTarget.js.map +1 -1
- package/lib-commonjs/middleware/flip.js.map +1 -1
- package/lib-commonjs/middleware/intersecting.js.map +1 -1
- package/lib-commonjs/middleware/matchTargetSize.js.map +1 -1
- package/lib-commonjs/middleware/maxSize.js.map +1 -1
- package/lib-commonjs/middleware/offset.js.map +1 -1
- package/lib-commonjs/middleware/shift.js.map +1 -1
- package/lib-commonjs/usePositioning.js.map +1 -1
- package/lib-commonjs/usePositioningMouseTarget.js.map +1 -1
- package/lib-commonjs/usePositioningOptions.js +3 -6
- package/lib-commonjs/usePositioningOptions.js.map +1 -1
- package/lib-commonjs/useSafeZoneArea.js +156 -0
- package/lib-commonjs/useSafeZoneArea.js.map +1 -0
- package/lib-commonjs/utils/devtools.js.map +1 -1
- package/lib-commonjs/utils/fromFloatingUIPlacement.js.map +1 -1
- package/lib-commonjs/utils/getBoundary.js.map +1 -1
- package/lib-commonjs/utils/getFloatingUIOffset.js.map +1 -1
- package/lib-commonjs/utils/getReactFiberFromNode.js.map +1 -1
- package/lib-commonjs/utils/getScrollParent.js.map +1 -1
- package/lib-commonjs/utils/hasAutoFocusFilter.js.map +1 -1
- package/lib-commonjs/utils/listScrollParents.js.map +1 -1
- package/lib-commonjs/utils/mergeArrowOffset.js +9 -1
- package/lib-commonjs/utils/mergeArrowOffset.js.map +1 -1
- package/lib-commonjs/utils/normalizeAutoSize.js +5 -1
- package/lib-commonjs/utils/normalizeAutoSize.js.map +1 -1
- package/lib-commonjs/utils/parseFloatingUIPlacement.js +6 -1
- package/lib-commonjs/utils/parseFloatingUIPlacement.js.map +1 -1
- package/lib-commonjs/utils/resolvePositioningShorthand.js +1 -1
- package/lib-commonjs/utils/resolvePositioningShorthand.js.map +1 -1
- package/lib-commonjs/utils/toFloatingUIPlacement.js.map +1 -1
- package/lib-commonjs/utils/toggleScrollListener.js.map +1 -1
- package/lib-commonjs/utils/useCallbackRef.js.map +1 -1
- package/lib-commonjs/utils/writeArrowUpdates.js +3 -1
- package/lib-commonjs/utils/writeArrowUpdates.js.map +1 -1
- package/lib-commonjs/utils/writeContainerupdates.js.map +1 -1
- package/package.json +8 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,20 +1,29 @@
|
|
|
1
1
|
# Change Log - @fluentui/react-positioning
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Tue, 10 Jun 2025 04:22:19 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
-
## [0.0.0-nightly-
|
|
7
|
+
## [0.0.0-nightly-20250610-0406.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-positioning_v0.0.0-nightly-20250610-0406.1)
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-positioning_v9.17.
|
|
9
|
+
Tue, 10 Jun 2025 04:22:19 GMT
|
|
10
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-positioning_v9.17.1..@fluentui/react-positioning_v0.0.0-nightly-20250610-0406.1)
|
|
11
11
|
|
|
12
12
|
### Changes
|
|
13
13
|
|
|
14
14
|
- Release nightly v9 ([commit](https://github.com/microsoft/fluentui/commit/not available) by fluentui-internal@service.microsoft.com)
|
|
15
|
-
- Bump @fluentui/react-shared-contexts to v0.0.0-nightly-
|
|
16
|
-
- Bump @fluentui/react-theme to v0.0.0-nightly-
|
|
17
|
-
- Bump @fluentui/react-utilities to v0.0.0-nightly-
|
|
15
|
+
- Bump @fluentui/react-shared-contexts to v0.0.0-nightly-20250610-0406.1 ([commit](https://github.com/microsoft/fluentui/commit/a18ca95f71f3fcdd891b8a84b365cb938d37b111) by beachball)
|
|
16
|
+
- Bump @fluentui/react-theme to v0.0.0-nightly-20250610-0406.1 ([commit](https://github.com/microsoft/fluentui/commit/a18ca95f71f3fcdd891b8a84b365cb938d37b111) by beachball)
|
|
17
|
+
- Bump @fluentui/react-utilities to v0.0.0-nightly-20250610-0406.1 ([commit](https://github.com/microsoft/fluentui/commit/a18ca95f71f3fcdd891b8a84b365cb938d37b111) by beachball)
|
|
18
|
+
|
|
19
|
+
## [9.17.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-positioning_v9.17.1)
|
|
20
|
+
|
|
21
|
+
Fri, 06 Jun 2025 13:15:17 GMT
|
|
22
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-positioning_v9.17.0..@fluentui/react-positioning_v9.17.1)
|
|
23
|
+
|
|
24
|
+
### Patches
|
|
25
|
+
|
|
26
|
+
- Bump @fluentui/react-utilities to v9.20.0 ([PR #34572](https://github.com/microsoft/fluentui/pull/34572) by beachball)
|
|
18
27
|
|
|
19
28
|
## [9.17.0](https://github.com/microsoft/fluentui/tree/@fluentui/react-positioning_v9.17.0)
|
|
20
29
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { GriffelStyle } from '@griffel/react';
|
|
2
2
|
import * as React_2 from 'react';
|
|
3
|
+
import { RefObjectFunction } from '@fluentui/react-utilities';
|
|
3
4
|
|
|
4
5
|
export declare type Alignment = 'top' | 'bottom' | 'start' | 'end' | 'center';
|
|
5
6
|
|
|
@@ -296,6 +297,23 @@ export declare type PositioningVirtualElement = {
|
|
|
296
297
|
|
|
297
298
|
export declare function resolvePositioningShorthand(shorthand: PositioningShorthand | undefined | null): Readonly<PositioningProps>;
|
|
298
299
|
|
|
300
|
+
export declare type SafeBufferAreaOptions = {
|
|
301
|
+
/** Enables debug mode: makes drawn shapes visible. */
|
|
302
|
+
debug?: boolean;
|
|
303
|
+
/** Disables the safe zone area. */
|
|
304
|
+
disabled?: boolean;
|
|
305
|
+
/** The time in milliseconds to wait before clearing the safe zone. */
|
|
306
|
+
timeout?: number;
|
|
307
|
+
/** Called when the mouse enters the safe zone. */
|
|
308
|
+
onSafeZoneEnter?: (e: React_2.MouseEvent) => void;
|
|
309
|
+
/** Called when the mouse moves within the safe zone. */
|
|
310
|
+
onSafeZoneMove?: (e: React_2.MouseEvent) => void;
|
|
311
|
+
/** Called when the mouse leaves the safe zone. */
|
|
312
|
+
onSafeZoneLeave?: (e: React_2.MouseEvent) => void;
|
|
313
|
+
/** Called when the safe zone times out, even if a cursor is still over a safe zone. */
|
|
314
|
+
onSafeZoneTimeout?: () => void;
|
|
315
|
+
};
|
|
316
|
+
|
|
299
317
|
export declare type SetVirtualMouseTarget = (event: React_2.MouseEvent | MouseEvent | undefined | null) => void;
|
|
300
318
|
|
|
301
319
|
declare type TargetElement = HTMLElement | PositioningVirtualElement;
|
|
@@ -322,4 +340,10 @@ declare interface UsePositioningReturn {
|
|
|
322
340
|
arrowRef: React_2.MutableRefObject<any>;
|
|
323
341
|
}
|
|
324
342
|
|
|
343
|
+
export declare function useSafeZoneArea({ debug, disabled, onSafeZoneEnter, onSafeZoneMove, onSafeZoneLeave, onSafeZoneTimeout, timeout, }?: SafeBufferAreaOptions): {
|
|
344
|
+
containerRef: RefObjectFunction<HTMLElement>;
|
|
345
|
+
targetRef: RefObjectFunction<HTMLElement>;
|
|
346
|
+
elementToRender: JSX.Element | null;
|
|
347
|
+
};
|
|
348
|
+
|
|
325
349
|
export { }
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
import { mergeClasses } from '@griffel/react';
|
|
2
|
+
import { useId } from '@fluentui/react-utilities';
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { useSyncExternalStore } from 'use-sync-external-store/shim';
|
|
5
|
+
import { useStyles } from './SafeZoneArea.styles';
|
|
6
|
+
export function createSafeZoneAreaStateStore() {
|
|
7
|
+
let isActive = false;
|
|
8
|
+
const listeners = [];
|
|
9
|
+
return {
|
|
10
|
+
isActive () {
|
|
11
|
+
return isActive;
|
|
12
|
+
},
|
|
13
|
+
toggleActive (newIsActive) {
|
|
14
|
+
isActive = newIsActive;
|
|
15
|
+
listeners.forEach((listener)=>listener(isActive));
|
|
16
|
+
},
|
|
17
|
+
subscribe (listener) {
|
|
18
|
+
listeners.push(listener);
|
|
19
|
+
return ()=>{
|
|
20
|
+
const index = listeners.indexOf(listener);
|
|
21
|
+
if (index > -1) {
|
|
22
|
+
listeners.splice(index, 1);
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* A component that renders a safe zone area with SVG shapes. Uses `useSyncExternalStore` to manage its active state
|
|
30
|
+
* to avoid causing re-renders in `useSafeZoneArea()` as the hook might be used in host components like `Menu`.
|
|
31
|
+
*
|
|
32
|
+
* Draws two shapes:
|
|
33
|
+
* - a triangle that points to the target element which is an actual safe zone
|
|
34
|
+
* - a rectangle for a clip path that clips out the target element
|
|
35
|
+
*
|
|
36
|
+
* @internal
|
|
37
|
+
*/ export const SafeZoneArea = /*#__PURE__*/ React.memo((props)=>{
|
|
38
|
+
const { debug, onMouseEnter, onMouseMove, onMouseLeave, stateStore } = props;
|
|
39
|
+
const clipPathId = useId();
|
|
40
|
+
const styles = useStyles();
|
|
41
|
+
const active = useSyncExternalStore(stateStore.subscribe, stateStore.isActive);
|
|
42
|
+
const svgRef = React.useRef(null);
|
|
43
|
+
React.useImperativeHandle(props.imperativeRef, ()=>({
|
|
44
|
+
updateSVG ({ containerPlacementSide, containerRect, mouseCoordinates, targetRect }) {
|
|
45
|
+
const svgEl = svgRef.current;
|
|
46
|
+
if (!svgEl) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const trianglePathEl = svgEl.children.item(0);
|
|
50
|
+
const debugRectEl = svgEl.children.item(2);
|
|
51
|
+
const clipPathEl = svgEl.children.item(1);
|
|
52
|
+
const clipPathRect = clipPathEl.firstElementChild;
|
|
53
|
+
const SIZE_MULTIPLIER = 0.9;
|
|
54
|
+
let svgStyle;
|
|
55
|
+
let tringlePoints = [];
|
|
56
|
+
let clipPoints = [];
|
|
57
|
+
switch(containerPlacementSide){
|
|
58
|
+
case 'top':
|
|
59
|
+
svgStyle = {
|
|
60
|
+
width: `${containerRect.width}px`,
|
|
61
|
+
height: `${targetRect.bottom - containerRect.bottom}px`,
|
|
62
|
+
transform: `translate(${containerRect.left}px, ${containerRect.bottom}px)`
|
|
63
|
+
};
|
|
64
|
+
tringlePoints = [
|
|
65
|
+
[
|
|
66
|
+
containerRect.width,
|
|
67
|
+
0
|
|
68
|
+
],
|
|
69
|
+
[
|
|
70
|
+
mouseCoordinates.x - containerRect.left,
|
|
71
|
+
(mouseCoordinates.y - containerRect.bottom) / SIZE_MULTIPLIER
|
|
72
|
+
],
|
|
73
|
+
[
|
|
74
|
+
0,
|
|
75
|
+
0
|
|
76
|
+
]
|
|
77
|
+
];
|
|
78
|
+
clipPoints = [
|
|
79
|
+
[
|
|
80
|
+
0,
|
|
81
|
+
0
|
|
82
|
+
],
|
|
83
|
+
[
|
|
84
|
+
0,
|
|
85
|
+
targetRect.bottom - containerRect.bottom
|
|
86
|
+
],
|
|
87
|
+
[
|
|
88
|
+
targetRect.left - containerRect.left,
|
|
89
|
+
targetRect.bottom - containerRect.bottom
|
|
90
|
+
],
|
|
91
|
+
[
|
|
92
|
+
targetRect.left - containerRect.left,
|
|
93
|
+
targetRect.top - containerRect.bottom
|
|
94
|
+
],
|
|
95
|
+
[
|
|
96
|
+
targetRect.right - containerRect.left,
|
|
97
|
+
targetRect.top - containerRect.bottom
|
|
98
|
+
],
|
|
99
|
+
[
|
|
100
|
+
targetRect.right - containerRect.left,
|
|
101
|
+
targetRect.bottom - containerRect.bottom
|
|
102
|
+
],
|
|
103
|
+
[
|
|
104
|
+
containerRect.width,
|
|
105
|
+
targetRect.bottom - containerRect.bottom
|
|
106
|
+
],
|
|
107
|
+
[
|
|
108
|
+
containerRect.width,
|
|
109
|
+
0
|
|
110
|
+
]
|
|
111
|
+
];
|
|
112
|
+
break;
|
|
113
|
+
case 'bottom':
|
|
114
|
+
svgStyle = {
|
|
115
|
+
width: `${containerRect.width}px`,
|
|
116
|
+
height: `${containerRect.top - targetRect.top}px`,
|
|
117
|
+
transform: `translate(${containerRect.left}px, ${targetRect.top}px)`
|
|
118
|
+
};
|
|
119
|
+
tringlePoints = [
|
|
120
|
+
[
|
|
121
|
+
containerRect.width,
|
|
122
|
+
containerRect.top - targetRect.top
|
|
123
|
+
],
|
|
124
|
+
[
|
|
125
|
+
mouseCoordinates.x - containerRect.left,
|
|
126
|
+
(mouseCoordinates.y - targetRect.top) * SIZE_MULTIPLIER
|
|
127
|
+
],
|
|
128
|
+
[
|
|
129
|
+
0,
|
|
130
|
+
containerRect.top - targetRect.top
|
|
131
|
+
]
|
|
132
|
+
];
|
|
133
|
+
clipPoints = [
|
|
134
|
+
[
|
|
135
|
+
0,
|
|
136
|
+
0
|
|
137
|
+
],
|
|
138
|
+
[
|
|
139
|
+
0,
|
|
140
|
+
containerRect.top - targetRect.top
|
|
141
|
+
],
|
|
142
|
+
[
|
|
143
|
+
containerRect.width,
|
|
144
|
+
containerRect.top - targetRect.top
|
|
145
|
+
],
|
|
146
|
+
[
|
|
147
|
+
containerRect.width,
|
|
148
|
+
0
|
|
149
|
+
],
|
|
150
|
+
[
|
|
151
|
+
targetRect.right - containerRect.left,
|
|
152
|
+
0
|
|
153
|
+
],
|
|
154
|
+
[
|
|
155
|
+
targetRect.right - containerRect.left,
|
|
156
|
+
targetRect.height
|
|
157
|
+
],
|
|
158
|
+
[
|
|
159
|
+
targetRect.left - containerRect.left,
|
|
160
|
+
targetRect.height
|
|
161
|
+
],
|
|
162
|
+
[
|
|
163
|
+
targetRect.left - containerRect.left,
|
|
164
|
+
0
|
|
165
|
+
]
|
|
166
|
+
];
|
|
167
|
+
break;
|
|
168
|
+
case 'left':
|
|
169
|
+
svgStyle = {
|
|
170
|
+
width: `${targetRect.right - containerRect.right}px`,
|
|
171
|
+
height: `${containerRect.height}px`,
|
|
172
|
+
transform: `translate(${containerRect.right}px, ${containerRect.top}px)`
|
|
173
|
+
};
|
|
174
|
+
tringlePoints = [
|
|
175
|
+
[
|
|
176
|
+
(mouseCoordinates.x - containerRect.right) / SIZE_MULTIPLIER,
|
|
177
|
+
mouseCoordinates.y - containerRect.top
|
|
178
|
+
],
|
|
179
|
+
[
|
|
180
|
+
0,
|
|
181
|
+
containerRect.height
|
|
182
|
+
],
|
|
183
|
+
[
|
|
184
|
+
0,
|
|
185
|
+
0
|
|
186
|
+
]
|
|
187
|
+
];
|
|
188
|
+
clipPoints = [
|
|
189
|
+
[
|
|
190
|
+
0,
|
|
191
|
+
0
|
|
192
|
+
],
|
|
193
|
+
[
|
|
194
|
+
0,
|
|
195
|
+
containerRect.height
|
|
196
|
+
],
|
|
197
|
+
[
|
|
198
|
+
targetRect.right - containerRect.right,
|
|
199
|
+
containerRect.height
|
|
200
|
+
],
|
|
201
|
+
[
|
|
202
|
+
targetRect.right - containerRect.right,
|
|
203
|
+
targetRect.bottom - containerRect.top
|
|
204
|
+
],
|
|
205
|
+
[
|
|
206
|
+
targetRect.left - containerRect.right,
|
|
207
|
+
targetRect.bottom - containerRect.top
|
|
208
|
+
],
|
|
209
|
+
[
|
|
210
|
+
targetRect.left - containerRect.right,
|
|
211
|
+
targetRect.top - containerRect.top
|
|
212
|
+
],
|
|
213
|
+
[
|
|
214
|
+
targetRect.right - containerRect.right,
|
|
215
|
+
targetRect.top - containerRect.top
|
|
216
|
+
],
|
|
217
|
+
[
|
|
218
|
+
targetRect.right - containerRect.right,
|
|
219
|
+
0
|
|
220
|
+
]
|
|
221
|
+
];
|
|
222
|
+
break;
|
|
223
|
+
default:
|
|
224
|
+
svgStyle = {
|
|
225
|
+
width: `${containerRect.left - targetRect.left}px`,
|
|
226
|
+
height: `${containerRect.height}px`,
|
|
227
|
+
transform: `translate(${targetRect.left}px, ${containerRect.top}px)`
|
|
228
|
+
};
|
|
229
|
+
tringlePoints = [
|
|
230
|
+
[
|
|
231
|
+
(mouseCoordinates.x - targetRect.left) * SIZE_MULTIPLIER,
|
|
232
|
+
mouseCoordinates.y - containerRect.y
|
|
233
|
+
],
|
|
234
|
+
[
|
|
235
|
+
containerRect.left - targetRect.left,
|
|
236
|
+
containerRect.height
|
|
237
|
+
],
|
|
238
|
+
[
|
|
239
|
+
containerRect.left - targetRect.left,
|
|
240
|
+
0
|
|
241
|
+
]
|
|
242
|
+
];
|
|
243
|
+
clipPoints = [
|
|
244
|
+
[
|
|
245
|
+
0,
|
|
246
|
+
0
|
|
247
|
+
],
|
|
248
|
+
[
|
|
249
|
+
0,
|
|
250
|
+
targetRect.top - containerRect.top
|
|
251
|
+
],
|
|
252
|
+
[
|
|
253
|
+
targetRect.width,
|
|
254
|
+
targetRect.top - containerRect.top
|
|
255
|
+
],
|
|
256
|
+
[
|
|
257
|
+
targetRect.width,
|
|
258
|
+
targetRect.bottom - containerRect.top
|
|
259
|
+
],
|
|
260
|
+
[
|
|
261
|
+
0,
|
|
262
|
+
targetRect.bottom - containerRect.top
|
|
263
|
+
],
|
|
264
|
+
[
|
|
265
|
+
0,
|
|
266
|
+
containerRect.height
|
|
267
|
+
],
|
|
268
|
+
[
|
|
269
|
+
containerRect.left - targetRect.left,
|
|
270
|
+
containerRect.height
|
|
271
|
+
],
|
|
272
|
+
[
|
|
273
|
+
containerRect.left - targetRect.left,
|
|
274
|
+
0
|
|
275
|
+
]
|
|
276
|
+
];
|
|
277
|
+
break;
|
|
278
|
+
}
|
|
279
|
+
const trianglePath = `M ${tringlePoints.flatMap((p)=>p).join(' ')} z`;
|
|
280
|
+
const clipPath = `M ${clipPoints.flatMap((p)=>p).join(' ')} z`;
|
|
281
|
+
Object.assign(svgEl.style, svgStyle);
|
|
282
|
+
trianglePathEl.setAttributeNS(null, 'd', trianglePath);
|
|
283
|
+
clipPathRect.setAttributeNS(null, 'd', clipPath);
|
|
284
|
+
debugRectEl === null || debugRectEl === void 0 ? void 0 : debugRectEl.setAttributeNS(null, 'd', clipPath);
|
|
285
|
+
}
|
|
286
|
+
}), []);
|
|
287
|
+
return /*#__PURE__*/ React.createElement("div", {
|
|
288
|
+
className: mergeClasses(styles.wrapper, active && styles.wrapperActive),
|
|
289
|
+
"data-safe-zone": ""
|
|
290
|
+
}, active ? /*#__PURE__*/ React.createElement("svg", {
|
|
291
|
+
"aria-hidden": true,
|
|
292
|
+
className: styles.svg,
|
|
293
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
294
|
+
ref: svgRef
|
|
295
|
+
}, /*#__PURE__*/ React.createElement("path", {
|
|
296
|
+
className: mergeClasses(styles.triangle, debug && styles.triangleDebug),
|
|
297
|
+
clipPath: `url(#${clipPathId})`,
|
|
298
|
+
onMouseEnter: onMouseEnter,
|
|
299
|
+
onMouseMove: onMouseMove,
|
|
300
|
+
onMouseLeave: onMouseLeave
|
|
301
|
+
}), /*#__PURE__*/ React.createElement("clipPath", {
|
|
302
|
+
id: clipPathId
|
|
303
|
+
}, /*#__PURE__*/ React.createElement("path", null)), debug && /*#__PURE__*/ React.createElement("path", {
|
|
304
|
+
className: styles.rectDebug
|
|
305
|
+
})) : null);
|
|
306
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/SafeZoneArea.tsx"],"sourcesContent":["import { mergeClasses } from '@griffel/react';\nimport { useId } from '@fluentui/react-utilities';\nimport type { Side as PlacementSide } from '@floating-ui/dom';\nimport * as React from 'react';\nimport { useSyncExternalStore } from 'use-sync-external-store/shim';\n\nimport { useStyles } from './SafeZoneArea.styles';\n\nexport type SafeZoneAreaImperativeHandle = {\n updateSVG: (options: {\n containerPlacementSide: PlacementSide;\n containerRect: DOMRect;\n targetRect: DOMRect;\n mouseCoordinates: { x: number; y: number };\n }) => 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\nexport function createSafeZoneAreaStateStore() {\n let isActive = false;\n const listeners: ((value: boolean) => void)[] = [];\n\n return {\n isActive() {\n return isActive;\n },\n toggleActive(newIsActive: boolean) {\n isActive = newIsActive;\n listeners.forEach(listener => listener(isActive));\n },\n\n subscribe(listener: (value: boolean) => void) {\n listeners.push(listener);\n\n return () => {\n const index = listeners.indexOf(listener);\n\n if (index > -1) {\n listeners.splice(index, 1);\n }\n };\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) => {\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 React.useImperativeHandle(\n props.imperativeRef,\n () => ({\n updateSVG({ containerPlacementSide, containerRect, mouseCoordinates, targetRect }) {\n const svgEl = svgRef.current;\n\n if (!svgEl) {\n return;\n }\n\n const trianglePathEl = svgEl.children.item(0) as SVGPathElement;\n const debugRectEl = svgEl.children.item(2) as SVGPathElement | null;\n const clipPathEl = svgEl.children.item(1) as SVGClipPathElement;\n const clipPathRect = clipPathEl.firstElementChild as SVGRectElement;\n\n const SIZE_MULTIPLIER = 0.9;\n\n let svgStyle: Partial<CSSStyleDeclaration>;\n\n let tringlePoints: [number, number][] = [];\n let clipPoints: [number, number][] = [];\n\n switch (containerPlacementSide) {\n case 'top':\n svgStyle = {\n width: `${containerRect.width}px`,\n height: `${targetRect.bottom - containerRect.bottom}px`,\n transform: `translate(${containerRect.left}px, ${containerRect.bottom}px)`,\n };\n\n tringlePoints = [\n [containerRect.width, 0],\n [mouseCoordinates.x - containerRect.left, (mouseCoordinates.y - containerRect.bottom) / SIZE_MULTIPLIER],\n [0, 0],\n ];\n clipPoints = [\n [0, 0],\n [0, targetRect.bottom - containerRect.bottom],\n [targetRect.left - containerRect.left, targetRect.bottom - containerRect.bottom],\n [targetRect.left - containerRect.left, targetRect.top - containerRect.bottom],\n [targetRect.right - containerRect.left, targetRect.top - containerRect.bottom],\n [targetRect.right - containerRect.left, targetRect.bottom - containerRect.bottom],\n [containerRect.width, targetRect.bottom - containerRect.bottom],\n [containerRect.width, 0],\n ];\n\n break;\n\n case 'bottom':\n svgStyle = {\n width: `${containerRect.width}px`,\n height: `${containerRect.top - targetRect.top}px`,\n transform: `translate(${containerRect.left}px, ${targetRect.top}px)`,\n };\n\n tringlePoints = [\n [containerRect.width, containerRect.top - targetRect.top],\n [mouseCoordinates.x - containerRect.left, (mouseCoordinates.y - targetRect.top) * SIZE_MULTIPLIER],\n [0, containerRect.top - targetRect.top],\n ];\n clipPoints = [\n [0, 0],\n [0, containerRect.top - targetRect.top],\n [containerRect.width, containerRect.top - targetRect.top],\n [containerRect.width, 0],\n [targetRect.right - containerRect.left, 0],\n [targetRect.right - containerRect.left, targetRect.height],\n [targetRect.left - containerRect.left, targetRect.height],\n [targetRect.left - containerRect.left, 0],\n ];\n\n break;\n\n case 'left':\n svgStyle = {\n width: `${targetRect.right - containerRect.right}px`,\n height: `${containerRect.height}px`,\n transform: `translate(${containerRect.right}px, ${containerRect.top}px)`,\n };\n\n tringlePoints = [\n [(mouseCoordinates.x - containerRect.right) / SIZE_MULTIPLIER, mouseCoordinates.y - containerRect.top],\n [0, containerRect.height],\n [0, 0],\n ];\n clipPoints = [\n [0, 0],\n [0, containerRect.height],\n [targetRect.right - containerRect.right, containerRect.height],\n [targetRect.right - containerRect.right, targetRect.bottom - containerRect.top],\n [targetRect.left - containerRect.right, targetRect.bottom - containerRect.top],\n [targetRect.left - containerRect.right, targetRect.top - containerRect.top],\n [targetRect.right - containerRect.right, targetRect.top - containerRect.top],\n [targetRect.right - containerRect.right, 0],\n ];\n\n break;\n\n default:\n svgStyle = {\n width: `${containerRect.left - targetRect.left}px`,\n height: `${containerRect.height}px`,\n transform: `translate(${targetRect.left}px, ${containerRect.top}px)`,\n };\n\n tringlePoints = [\n [(mouseCoordinates.x - targetRect.left) * SIZE_MULTIPLIER, mouseCoordinates.y - containerRect.y],\n [containerRect.left - targetRect.left, containerRect.height],\n [containerRect.left - targetRect.left, 0],\n ];\n clipPoints = [\n [0, 0],\n [0, targetRect.top - containerRect.top],\n [targetRect.width, targetRect.top - containerRect.top],\n [targetRect.width, targetRect.bottom - containerRect.top],\n [0, targetRect.bottom - containerRect.top],\n [0, containerRect.height],\n [containerRect.left - targetRect.left, containerRect.height],\n [containerRect.left - targetRect.left, 0],\n ];\n\n break;\n }\n\n const trianglePath = `M ${tringlePoints.flatMap(p => p).join(' ')} z`;\n const clipPath = `M ${clipPoints.flatMap(p => p).join(' ')} z`;\n\n Object.assign(svgEl.style, svgStyle);\n\n trianglePathEl.setAttributeNS(null, 'd', trianglePath);\n clipPathRect.setAttributeNS(null, 'd', clipPath);\n debugRectEl?.setAttributeNS(null, 'd', clipPath);\n },\n }),\n [],\n );\n\n return (\n <div className={mergeClasses(styles.wrapper, active && styles.wrapperActive)} data-safe-zone=\"\">\n {active ? (\n <svg aria-hidden className={styles.svg} xmlns=\"http://www.w3.org/2000/svg\" ref={svgRef}>\n <path\n className={mergeClasses(styles.triangle, debug && styles.triangleDebug)}\n clipPath={`url(#${clipPathId})`}\n onMouseEnter={onMouseEnter}\n onMouseMove={onMouseMove}\n onMouseLeave={onMouseLeave}\n />\n <clipPath id={clipPathId}>\n <path />\n </clipPath>\n\n {debug && <path className={styles.rectDebug} />}\n </svg>\n ) : null}\n </div>\n );\n});\n"],"names":["mergeClasses","useId","React","useSyncExternalStore","useStyles","createSafeZoneAreaStateStore","isActive","listeners","toggleActive","newIsActive","forEach","listener","subscribe","push","index","indexOf","splice","SafeZoneArea","memo","props","debug","onMouseEnter","onMouseMove","onMouseLeave","stateStore","clipPathId","styles","active","svgRef","useRef","useImperativeHandle","imperativeRef","updateSVG","containerPlacementSide","containerRect","mouseCoordinates","targetRect","svgEl","current","trianglePathEl","children","item","debugRectEl","clipPathEl","clipPathRect","firstElementChild","SIZE_MULTIPLIER","svgStyle","tringlePoints","clipPoints","width","height","bottom","transform","left","x","y","top","right","trianglePath","flatMap","p","join","clipPath","Object","assign","style","setAttributeNS","div","className","wrapper","wrapperActive","data-safe-zone","svg","aria-hidden","xmlns","ref","path","triangle","triangleDebug","id","rectDebug"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,YAAY,QAAQ,iBAAiB;AAC9C,SAASC,KAAK,QAAQ,4BAA4B;AAElD,YAAYC,WAAW,QAAQ;AAC/B,SAASC,oBAAoB,QAAQ,+BAA+B;AAEpE,SAASC,SAAS,QAAQ,wBAAwB;AA4BlD,OAAO,SAASC;IACd,IAAIC,WAAW;IACf,MAAMC,YAA0C,EAAE;IAElD,OAAO;QACLD;YACE,OAAOA;QACT;QACAE,cAAaC,WAAoB;YAC/BH,WAAWG;YACXF,UAAUG,OAAO,CAACC,CAAAA,WAAYA,SAASL;QACzC;QAEAM,WAAUD,QAAkC;YAC1CJ,UAAUM,IAAI,CAACF;YAEf,OAAO;gBACL,MAAMG,QAAQP,UAAUQ,OAAO,CAACJ;gBAEhC,IAAIG,QAAQ,CAAC,GAAG;oBACdP,UAAUS,MAAM,CAACF,OAAO;gBAC1B;YACF;QACF;IACF;AACF;AAEA;;;;;;;;;CASC,GACD,OAAO,MAAMG,6BAAef,MAAMgB,IAAI,CAAC,CAACC;IACtC,MAAM,EAAEC,KAAK,EAAEC,YAAY,EAAEC,WAAW,EAAEC,YAAY,EAAEC,UAAU,EAAE,GA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AcA;sBAEhB,oBAACwC;QAASiB,IAAIvD;qBACZ,oBAACoD,gBAGFzD,uBAAS,oBAACyD;QAAKR,WAAW3C,OAAOuD,SAAS;UAE3C;AAGV,GAAG"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { __styles } from '@griffel/react';
|
|
2
|
+
import { tokens } from '@fluentui/react-theme';
|
|
3
|
+
export const useStyles = /*#__PURE__*/__styles({
|
|
4
|
+
wrapper: {
|
|
5
|
+
mc9l5x: "fjseox",
|
|
6
|
+
Bqenvij: "fniina8",
|
|
7
|
+
a9b677: "f3tsq5r",
|
|
8
|
+
Bkecrkj: "f1aehjj5"
|
|
9
|
+
},
|
|
10
|
+
wrapperActive: {
|
|
11
|
+
mc9l5x: "ftgm304"
|
|
12
|
+
},
|
|
13
|
+
svg: {
|
|
14
|
+
Bkfmm31: "f1au8mb3",
|
|
15
|
+
Bkecrkj: "f1aehjj5",
|
|
16
|
+
qhf8xq: "f19dog8a",
|
|
17
|
+
Bhzewxz: "f15twtuk",
|
|
18
|
+
oyh7mz: ["f1vgc2s3", "f1e31b4d"]
|
|
19
|
+
},
|
|
20
|
+
triangle: {
|
|
21
|
+
Bkecrkj: "f1cguypg"
|
|
22
|
+
},
|
|
23
|
+
triangleDebug: {
|
|
24
|
+
Bceei9c: "f7116n6",
|
|
25
|
+
Bkfmm31: "f1xab38x",
|
|
26
|
+
ojy3ng: "f1wle4v7",
|
|
27
|
+
Be5yapy: "f1t0ei4n"
|
|
28
|
+
},
|
|
29
|
+
rectDebug: {
|
|
30
|
+
Bkfmm31: "fyegryc"
|
|
31
|
+
}
|
|
32
|
+
}, {
|
|
33
|
+
d: [".fjseox{display:none;}", ".fniina8{height:0;}", ".f3tsq5r{width:0;}", ".f1aehjj5{pointer-events:none;}", ".ftgm304{display:block;}", ".f1au8mb3{fill:transparent;}", ".f19dog8a{position:fixed;}", ".f15twtuk{top:0;}", ".f1vgc2s3{left:0;}", ".f1e31b4d{right:0;}", ".f1cguypg{pointer-events:auto;}", ".f7116n6{cursor:crosshair;}", ".f1xab38x{fill:color-mix(in srgb, var(--colorPaletteGreenBackground3) 20%, transparent);}", ".f1wle4v7{stroke:color-mix(in srgb, var(--colorPaletteGreenBackground3) 60%, transparent);}", ".f1t0ei4n{stroke-width:2px;}", ".fyegryc{fill:color-mix(in srgb, var(--colorPaletteRedBackground3) 20%, transparent);}"]
|
|
34
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__styles","tokens","useStyles","wrapper","mc9l5x","Bqenvij","a9b677","Bkecrkj","wrapperActive","svg","Bkfmm31","qhf8xq","Bhzewxz","oyh7mz","triangle","triangleDebug","Bceei9c","ojy3ng","Be5yapy","rectDebug","d"],"sources":["SafeZoneArea.styles.js"],"sourcesContent":["import { makeStyles } from '@griffel/react';\nimport { tokens } from '@fluentui/react-theme';\nexport const useStyles = makeStyles({\n wrapper: {\n display: 'none',\n height: 0,\n width: 0,\n pointerEvents: 'none'\n },\n wrapperActive: {\n display: 'block'\n },\n svg: {\n fill: 'transparent',\n pointerEvents: 'none',\n position: 'fixed',\n top: 0,\n left: 0\n },\n triangle: {\n pointerEvents: 'auto'\n },\n triangleDebug: {\n cursor: 'crosshair',\n fill: `color-mix(in srgb, ${tokens.colorPaletteGreenBackground3} 20%, transparent)`,\n stroke: `color-mix(in srgb, ${tokens.colorPaletteGreenBackground3} 60%, transparent)`,\n strokeWidth: '2px'\n },\n rectDebug: {\n fill: `color-mix(in srgb, ${tokens.colorPaletteRedBackground3} 20%, transparent)`\n }\n});\n"],"mappings":"AAAA,SAAAA,QAAA,QAA2B,gBAAgB;AAC3C,SAASC,MAAM,QAAQ,uBAAuB;AAC9C,OAAO,MAAMC,SAAS,gBAAGF,QAAA;EAAAG,OAAA;IAAAC,MAAA;IAAAC,OAAA;IAAAC,MAAA;IAAAC,OAAA;EAAA;EAAAC,aAAA;IAAAJ,MAAA;EAAA;EAAAK,GAAA;IAAAC,OAAA;IAAAH,OAAA;IAAAI,MAAA;IAAAC,OAAA;IAAAC,MAAA;EAAA;EAAAC,QAAA;IAAAP,OAAA;EAAA;EAAAQ,aAAA;IAAAC,OAAA;IAAAN,OAAA;IAAAO,MAAA;IAAAC,OAAA;EAAA;EAAAC,SAAA;IAAAT,OAAA;EAAA;AAAA;EAAAU,CAAA;AAAA,CA6BxB,CAAC","ignoreList":[]}
|
package/lib/index.js
CHANGED
|
@@ -4,4 +4,5 @@ export { createSlideStyles } from './createSlideStyles';
|
|
|
4
4
|
export { PositioningConfigurationProvider } from './PositioningConfigurationContext';
|
|
5
5
|
export { usePositioning } from './usePositioning';
|
|
6
6
|
export { usePositioningMouseTarget } from './usePositioningMouseTarget';
|
|
7
|
+
export { useSafeZoneArea } from './useSafeZoneArea';
|
|
7
8
|
export { resolvePositioningShorthand, mergeArrowOffset } from './utils/index';
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export { createVirtualElementFromClick } from './createVirtualElementFromClick';\nexport { createArrowHeightStyles, createArrowStyles } from './createArrowStyles';\nexport { createSlideStyles } from './createSlideStyles';\nexport type { CreateArrowStylesOptions } from './createArrowStyles';\n\nexport { PositioningConfigurationProvider } from './PositioningConfigurationContext';\n\nexport { usePositioning } from './usePositioning';\nexport { usePositioningMouseTarget } from './usePositioningMouseTarget';\nexport { resolvePositioningShorthand, mergeArrowOffset } from './utils/index';\n\nexport type {\n Alignment,\n AutoSize,\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n Boundary,\n Offset,\n OffsetFunction,\n OffsetFunctionParam,\n OffsetObject,\n OffsetShorthand,\n Position,\n PositioningBoundary,\n PositioningImperativeRef,\n PositioningProps,\n PositioningRect,\n PositioningShorthand,\n PositioningShorthandValue,\n PositioningVirtualElement,\n SetVirtualMouseTarget,\n PositioningConfigurationFn,\n PositioningConfigurationFnOptions,\n} from './types';\n"],"names":["createVirtualElementFromClick","createArrowHeightStyles","createArrowStyles","createSlideStyles","PositioningConfigurationProvider","usePositioning","usePositioningMouseTarget","resolvePositioningShorthand","mergeArrowOffset"],"rangeMappings":"
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export { createVirtualElementFromClick } from './createVirtualElementFromClick';\nexport { createArrowHeightStyles, createArrowStyles } from './createArrowStyles';\nexport { createSlideStyles } from './createSlideStyles';\nexport type { CreateArrowStylesOptions } from './createArrowStyles';\n\nexport { PositioningConfigurationProvider } from './PositioningConfigurationContext';\n\nexport { usePositioning } from './usePositioning';\nexport { usePositioningMouseTarget } from './usePositioningMouseTarget';\nexport { useSafeZoneArea } from './useSafeZoneArea';\nexport type { SafeBufferAreaOptions } from './useSafeZoneArea';\nexport { resolvePositioningShorthand, mergeArrowOffset } from './utils/index';\n\nexport type {\n Alignment,\n AutoSize,\n // eslint-disable-next-line @typescript-eslint/no-deprecated\n Boundary,\n Offset,\n OffsetFunction,\n OffsetFunctionParam,\n OffsetObject,\n OffsetShorthand,\n Position,\n PositioningBoundary,\n PositioningImperativeRef,\n PositioningProps,\n PositioningRect,\n PositioningShorthand,\n PositioningShorthandValue,\n PositioningVirtualElement,\n SetVirtualMouseTarget,\n PositioningConfigurationFn,\n PositioningConfigurationFnOptions,\n} from './types';\n"],"names":["createVirtualElementFromClick","createArrowHeightStyles","createArrowStyles","createSlideStyles","PositioningConfigurationProvider","usePositioning","usePositioningMouseTarget","useSafeZoneArea","resolvePositioningShorthand","mergeArrowOffset"],"rangeMappings":";;;;;;;","mappings":"AAAA,SAASA,6BAA6B,QAAQ,kCAAkC;AAChF,SAASC,uBAAuB,EAAEC,iBAAiB,QAAQ,sBAAsB;AACjF,SAASC,iBAAiB,QAAQ,sBAAsB;AAGxD,SAASC,gCAAgC,QAAQ,oCAAoC;AAErF,SAASC,cAAc,QAAQ,mBAAmB;AAClD,SAASC,yBAAyB,QAAQ,8BAA8B;AACxE,SAASC,eAAe,QAAQ,oBAAoB;AAEpD,SAASC,2BAA2B,EAAEC,gBAAgB,QAAQ,gBAAgB"}
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { useFluent_unstable } from '@fluentui/react-shared-contexts';
|
|
2
|
+
import { useEventCallback, useMergedRefs } from '@fluentui/react-utilities';
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { createSafeZoneAreaStateStore, SafeZoneArea } from './SafeZoneArea';
|
|
5
|
+
import { parseFloatingUIPlacement } from './utils';
|
|
6
|
+
export function useSafeZoneArea({ debug = false, disabled = false, onSafeZoneEnter, onSafeZoneMove, onSafeZoneLeave, onSafeZoneTimeout, timeout = 1500 } = {}) {
|
|
7
|
+
const [stateStore] = React.useState(createSafeZoneAreaStateStore);
|
|
8
|
+
const { targetDocument } = useFluent_unstable();
|
|
9
|
+
const safeZoneAreaRef = React.useRef(null);
|
|
10
|
+
const containerRef = React.useRef(null);
|
|
11
|
+
const targetRef = React.useRef(null);
|
|
12
|
+
const timeoutIdRef = React.useRef(null);
|
|
13
|
+
const mouseMoveIdRef = React.useRef(null);
|
|
14
|
+
const containerListenerRef = React.useMemo(()=>{
|
|
15
|
+
if (disabled) {
|
|
16
|
+
return ()=>{
|
|
17
|
+
// do nothing
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
let containerEl = null;
|
|
21
|
+
function onContainerMouseEnter() {
|
|
22
|
+
const targetWindow = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView;
|
|
23
|
+
if (!targetWindow) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
if (timeoutIdRef.current) {
|
|
27
|
+
targetWindow.clearTimeout(timeoutIdRef.current);
|
|
28
|
+
timeoutIdRef.current = null;
|
|
29
|
+
}
|
|
30
|
+
stateStore.toggleActive(false);
|
|
31
|
+
}
|
|
32
|
+
return (el)=>{
|
|
33
|
+
if (el === null) {
|
|
34
|
+
containerEl === null || containerEl === void 0 ? void 0 : containerEl.removeEventListener('mouseenter', onContainerMouseEnter);
|
|
35
|
+
}
|
|
36
|
+
containerEl = el;
|
|
37
|
+
el === null || el === void 0 ? void 0 : el.addEventListener('mouseenter', onContainerMouseEnter);
|
|
38
|
+
};
|
|
39
|
+
}, [
|
|
40
|
+
disabled,
|
|
41
|
+
stateStore,
|
|
42
|
+
targetDocument
|
|
43
|
+
]);
|
|
44
|
+
const targetListenerRef = React.useMemo(()=>{
|
|
45
|
+
if (disabled) {
|
|
46
|
+
return ()=>{
|
|
47
|
+
// do nothing
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
let targetEl = null;
|
|
51
|
+
function onTargetMouseMove(e) {
|
|
52
|
+
const targetWindow = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView;
|
|
53
|
+
if (!targetWindow) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (timeoutIdRef.current) {
|
|
57
|
+
targetWindow.clearTimeout(timeoutIdRef.current);
|
|
58
|
+
timeoutIdRef.current = null;
|
|
59
|
+
}
|
|
60
|
+
if (!stateStore.isActive()) {
|
|
61
|
+
stateStore.toggleActive(true);
|
|
62
|
+
}
|
|
63
|
+
mouseMoveIdRef.current = targetWindow.requestAnimationFrame(()=>{
|
|
64
|
+
var _safeZoneAreaRef_current;
|
|
65
|
+
const containerEl = containerRef.current;
|
|
66
|
+
if (!containerEl || !targetEl) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
(_safeZoneAreaRef_current = safeZoneAreaRef.current) === null || _safeZoneAreaRef_current === void 0 ? void 0 : _safeZoneAreaRef_current.updateSVG({
|
|
70
|
+
containerPlacementSide: parseFloatingUIPlacement(containerEl.dataset.popperPlacement).side,
|
|
71
|
+
containerRect: containerEl.getBoundingClientRect(),
|
|
72
|
+
mouseCoordinates: {
|
|
73
|
+
x: e.clientX,
|
|
74
|
+
y: e.clientY
|
|
75
|
+
},
|
|
76
|
+
targetRect: targetEl.getBoundingClientRect()
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
return (el)=>{
|
|
81
|
+
if (el === null) {
|
|
82
|
+
const targetWindow = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView;
|
|
83
|
+
if (targetWindow) {
|
|
84
|
+
if (mouseMoveIdRef.current) {
|
|
85
|
+
targetWindow.cancelAnimationFrame(mouseMoveIdRef.current);
|
|
86
|
+
mouseMoveIdRef.current = null;
|
|
87
|
+
}
|
|
88
|
+
if (timeoutIdRef.current) {
|
|
89
|
+
targetWindow.clearTimeout(timeoutIdRef.current);
|
|
90
|
+
timeoutIdRef.current = null;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
targetEl === null || targetEl === void 0 ? void 0 : targetEl.removeEventListener('mousemove', onTargetMouseMove);
|
|
94
|
+
}
|
|
95
|
+
targetEl = el;
|
|
96
|
+
el === null || el === void 0 ? void 0 : el.addEventListener('mousemove', onTargetMouseMove);
|
|
97
|
+
};
|
|
98
|
+
}, [
|
|
99
|
+
disabled,
|
|
100
|
+
stateStore,
|
|
101
|
+
targetDocument
|
|
102
|
+
]);
|
|
103
|
+
const onSvgMouseEnter = useEventCallback((e)=>{
|
|
104
|
+
onSafeZoneEnter === null || onSafeZoneEnter === void 0 ? void 0 : onSafeZoneEnter(e);
|
|
105
|
+
const targetWindow = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView;
|
|
106
|
+
if (!targetWindow) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
if (timeoutIdRef.current) {
|
|
110
|
+
targetWindow.clearTimeout(timeoutIdRef.current);
|
|
111
|
+
timeoutIdRef.current = null;
|
|
112
|
+
}
|
|
113
|
+
// React 17 still uses pooled synthetic events
|
|
114
|
+
e.persist();
|
|
115
|
+
timeoutIdRef.current = targetWindow.setTimeout(()=>{
|
|
116
|
+
stateStore.toggleActive(false);
|
|
117
|
+
onSafeZoneTimeout === null || onSafeZoneTimeout === void 0 ? void 0 : onSafeZoneTimeout();
|
|
118
|
+
}, timeout);
|
|
119
|
+
});
|
|
120
|
+
const onSvgMouseMove = useEventCallback((e)=>{
|
|
121
|
+
onSafeZoneMove === null || onSafeZoneMove === void 0 ? void 0 : onSafeZoneMove(e);
|
|
122
|
+
});
|
|
123
|
+
const onSvgMouseLeave = useEventCallback((e)=>{
|
|
124
|
+
onSafeZoneLeave === null || onSafeZoneLeave === void 0 ? void 0 : onSafeZoneLeave(e);
|
|
125
|
+
});
|
|
126
|
+
return {
|
|
127
|
+
containerRef: useMergedRefs(containerRef, containerListenerRef),
|
|
128
|
+
targetRef: useMergedRefs(targetRef, targetListenerRef),
|
|
129
|
+
elementToRender: React.useMemo(()=>disabled ? null : /*#__PURE__*/ React.createElement(SafeZoneArea, {
|
|
130
|
+
debug: debug,
|
|
131
|
+
onMouseEnter: onSvgMouseEnter,
|
|
132
|
+
onMouseMove: onSvgMouseMove,
|
|
133
|
+
onMouseLeave: onSvgMouseLeave,
|
|
134
|
+
imperativeRef: safeZoneAreaRef,
|
|
135
|
+
stateStore: stateStore
|
|
136
|
+
}), [
|
|
137
|
+
disabled,
|
|
138
|
+
debug,
|
|
139
|
+
onSvgMouseEnter,
|
|
140
|
+
onSvgMouseMove,
|
|
141
|
+
onSvgMouseLeave,
|
|
142
|
+
stateStore
|
|
143
|
+
])
|
|
144
|
+
};
|
|
145
|
+
}
|