@fluentui/react-positioning 9.18.0 → 9.18.2
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 +21 -2
- package/README.md +11 -9
- package/lib/SafeZoneArea.js +3 -0
- package/lib/SafeZoneArea.js.map +1 -1
- package/lib/useSafeZoneArea.js +43 -21
- package/lib/useSafeZoneArea.js.map +1 -1
- package/lib-commonjs/SafeZoneArea.js +3 -0
- package/lib-commonjs/SafeZoneArea.js.map +1 -1
- package/lib-commonjs/useSafeZoneArea.js +43 -21
- package/lib-commonjs/useSafeZoneArea.js.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
@@ -1,12 +1,31 @@
|
|
1
1
|
# Change Log - @fluentui/react-positioning
|
2
2
|
|
3
|
-
This log was last generated on
|
3
|
+
This log was last generated on Wed, 18 Jun 2025 17:29:27 GMT and should not be manually modified.
|
4
4
|
|
5
5
|
<!-- Start content -->
|
6
6
|
|
7
|
+
## [9.18.2](https://github.com/microsoft/fluentui/tree/@fluentui/react-positioning_v9.18.2)
|
8
|
+
|
9
|
+
Wed, 18 Jun 2025 17:29:27 GMT
|
10
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-positioning_v9.18.1..@fluentui/react-positioning_v9.18.2)
|
11
|
+
|
12
|
+
### Patches
|
13
|
+
|
14
|
+
- Bump @fluentui/react-shared-contexts to v9.24.0 ([PR #34675](https://github.com/microsoft/fluentui/pull/34675) by beachball)
|
15
|
+
- Bump @fluentui/react-utilities to v9.21.1 ([PR #34675](https://github.com/microsoft/fluentui/pull/34675) by beachball)
|
16
|
+
|
17
|
+
## [9.18.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-positioning_v9.18.1)
|
18
|
+
|
19
|
+
Fri, 13 Jun 2025 12:32:51 GMT
|
20
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-positioning_v9.18.0..@fluentui/react-positioning_v9.18.1)
|
21
|
+
|
22
|
+
### Patches
|
23
|
+
|
24
|
+
- fix: update logic for triggering updates ([PR #34639](https://github.com/microsoft/fluentui/pull/34639) by olfedias@microsoft.com)
|
25
|
+
|
7
26
|
## [9.18.0](https://github.com/microsoft/fluentui/tree/@fluentui/react-positioning_v9.18.0)
|
8
27
|
|
9
|
-
Thu, 12 Jun 2025 09:
|
28
|
+
Thu, 12 Jun 2025 09:43:33 GMT
|
10
29
|
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-positioning_v9.17.2..@fluentui/react-positioning_v9.18.0)
|
11
30
|
|
12
31
|
### Minor changes
|
package/README.md
CHANGED
@@ -1,23 +1,25 @@
|
|
1
1
|
# @fluentui/react-positioning
|
2
2
|
|
3
|
-
A
|
3
|
+
A React utilities built on top of [Floating UI](https://floating-ui.com/) for positioning elements in the DOM.
|
4
4
|
|
5
5
|
## Usage
|
6
6
|
|
7
7
|
```tsx
|
8
|
-
import React from 'react';
|
9
|
-
import {
|
8
|
+
import * as React from 'react';
|
9
|
+
import { usePositiniong } from '@fluentui/react-positioning';
|
10
10
|
|
11
|
-
|
12
|
-
const {targetRef, containerRef} =
|
11
|
+
const PopupExample: React.FC = ({ children }) => {
|
12
|
+
const { targetRef, containerRef } = usePositiniong();
|
13
13
|
const [open, setOpen] = React.useState(false);
|
14
14
|
|
15
15
|
const onClick = () => setOpen(s => !s);
|
16
16
|
return (
|
17
17
|
<>
|
18
|
-
<button ref={targetRef} onClick={onClick}>
|
19
|
-
|
18
|
+
<button ref={targetRef} onClick={onClick}>
|
19
|
+
Toggle popup
|
20
|
+
</button>
|
21
|
+
{open && <div ref={containerRef}>{children}</div>}
|
20
22
|
</>
|
21
|
-
)
|
22
|
-
}
|
23
|
+
);
|
24
|
+
};
|
23
25
|
```
|
package/lib/SafeZoneArea.js
CHANGED
package/lib/SafeZoneArea.js.map
CHANGED
@@ -1 +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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AcoB,IAAI,GAAGlB,WAAWkB,IAAI;gCAAE;6BAAE;yBAC1C;wBAED;gBACJ;gBAEA,MAAMK,eAAe,CAAC,EAAE,EAAEX,cAAcY,OAAO,CAACC,CAAAA,IAAKA,GAAGC,IAAI,CAAC,KAAK,EAAE,CAAC;gBACrE,MAAMC,WAAW,CAAC,EAAE,EAAEd,WAAWW,OAAO,CAACC,CAAAA,IAAKA,GAAGC,IAAI,CAAC,KAAK,EAAE,CAAC;gBAE9DE,OAAOC,MAAM,CAAC5B,MAAM6B,KAAK,EAAEnB;gBAE3BR,eAAe4B,cAAc,CAAC,MAAM,KAAKR;gBACzCf,aAAauB,cAAc,CAAC,MAAM,KAAKJ;gBACvCrB,wBAAAA,kCAAAA,YAAayB,cAAc,CAAC,MAAM,KAAKJ;YACzC;QACF,CAAA,GACA,EAAE;IAGJ,qBACE,oBAACK;QAAIC,WAAWrE,aAAa0B,OAAO4C,OAAO,EAAE3C,UAAUD,OAAO6C,aAAa;QAAGC,kBAAe;OAC1F7C,uBACC,oBAAC8C;QAAIC,eAAAA;QAAYL,WAAW3C,OAAO+C,GAAG;QAAEE,OAAM;QAA6BC,KAAKhD;qBAC9E,oBAACiD;QACCR,WAAWrE,aAAa0B,OAAOoD,QAAQ,EAAE1D,SAASM,OAAOqD,aAAa;QACtEhB,UAAU,CAAC,KAAK,EAAEtC,WAAW,CAAC,CAAC;QAC/BJ,cAAcA;QACdC,aAAaA;QACbC,cAAcA;sBAEhB,oBAACwC;QAASiB,IAAIvD;qBACZ,oBAACoD,gBAGFzD,uBAAS,oBAACyD;QAAKR,WAAW3C,OAAOuD,SAAS;UAE3C;AAGV,GAAG"}
|
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 if (isActive === newIsActive) {\n return;\n }\n\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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EA,MAAMK,eAAe,CAAC,EAAE,EAAEX,cAAcY,OAAO,CAACC,CAAAA,IAAKA,GAAGC,IAAI,CAAC,KAAK,EAAE,CAAC;gBACrE,MAAMC,WAAW,CAAC,EAAE,EAAEd,WAAWW,OAAO,CAACC,CAAAA,IAAKA,GAAGC,IAAI,CAAC,KAAK,EAAE,CAAC;gBAE9DE,OAAOC,MAAM,CAAC5B,MAAM6B,KAAK,EAAEnB;gBAE3BR,eAAe4B,cAAc,CAAC,MAAM,KAAKR;gBACzCf,aAAauB,cAAc,CAAC,MAAM,KAAKJ;gBACvCrB,wBAAAA,kCAAAA,YAAayB,cAAc,CAAC,MAAM,KAAKJ;YACzC;QACF,CAAA,GACA,EAAE;IAGJ,qBACE,oBAACK;QAAIC,WAAWrE,aAAa0B,OAAO4C,OAAO,EAAE3C,UAAUD,OAAO6C,aAAa;QAAGC,kBAAe;OAC1F7C,uBACC,oBAAC8C;QAAIC,eAAAA;QAAYL,WAAW3C,OAAO+C,GAAG;QAAEE,OAAM;QAA6BC,KAAKhD;qBAC9E,oBAACiD;QACCR,WAAWrE,aAAa0B,OAAOoD,QAAQ,EAAE1D,SAASM,OAAOqD,aAAa;QACtEhB,UAAU,CAAC,KAAK,EAAEtC,WAAW,CAAC,CAAC;QAC/BJ,cAAcA;QACdC,aAAaA;QACbC,cAAcA;sBAEhB,oBAACwC;QAASiB,IAAIvD;qBACZ,oBAACoD,gBAGFzD,uBAAS,oBAACyD;QAAKR,WAAW3C,OAAOuD,SAAS;UAE3C;AAGV,GAAG"}
|
package/lib/useSafeZoneArea.js
CHANGED
@@ -11,6 +11,10 @@ export function useSafeZoneArea({ debug = false, disabled = false, onSafeZoneEnt
|
|
11
11
|
const targetRef = React.useRef(null);
|
12
12
|
const timeoutIdRef = React.useRef(null);
|
13
13
|
const mouseMoveIdRef = React.useRef(null);
|
14
|
+
const mouseCoordinatesRef = React.useRef({
|
15
|
+
x: 0,
|
16
|
+
y: 0
|
17
|
+
});
|
14
18
|
const containerListenerRef = React.useMemo(()=>{
|
15
19
|
if (disabled) {
|
16
20
|
return ()=>{
|
@@ -49,33 +53,18 @@ export function useSafeZoneArea({ debug = false, disabled = false, onSafeZoneEnt
|
|
49
53
|
}
|
50
54
|
let targetEl = null;
|
51
55
|
function onTargetMouseMove(e) {
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
}
|
56
|
+
mouseCoordinatesRef.current = {
|
57
|
+
x: e.clientX,
|
58
|
+
y: e.clientY
|
59
|
+
};
|
56
60
|
if (timeoutIdRef.current) {
|
57
|
-
|
61
|
+
var _targetDocument_defaultView;
|
62
|
+
targetDocument === null || targetDocument === void 0 ? void 0 : (_targetDocument_defaultView = targetDocument.defaultView) === null || _targetDocument_defaultView === void 0 ? void 0 : _targetDocument_defaultView.clearTimeout(timeoutIdRef.current);
|
58
63
|
timeoutIdRef.current = null;
|
59
64
|
}
|
60
65
|
if (!stateStore.isActive()) {
|
61
66
|
stateStore.toggleActive(true);
|
62
67
|
}
|
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
68
|
}
|
80
69
|
return (el)=>{
|
81
70
|
if (el === null) {
|
@@ -123,6 +112,39 @@ export function useSafeZoneArea({ debug = false, disabled = false, onSafeZoneEnt
|
|
123
112
|
const onSvgMouseLeave = useEventCallback((e)=>{
|
124
113
|
onSafeZoneLeave === null || onSafeZoneLeave === void 0 ? void 0 : onSafeZoneLeave(e);
|
125
114
|
});
|
115
|
+
React.useEffect(()=>{
|
116
|
+
return stateStore.subscribe((isActive)=>{
|
117
|
+
if (isActive) {
|
118
|
+
function updateSVGs() {
|
119
|
+
const containerEl = containerRef.current;
|
120
|
+
const targetEl = targetRef.current;
|
121
|
+
const targetWindow = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView;
|
122
|
+
if (containerEl && targetEl) {
|
123
|
+
var _safeZoneAreaRef_current;
|
124
|
+
(_safeZoneAreaRef_current = safeZoneAreaRef.current) === null || _safeZoneAreaRef_current === void 0 ? void 0 : _safeZoneAreaRef_current.updateSVG({
|
125
|
+
containerPlacementSide: parseFloatingUIPlacement(containerEl.dataset.popperPlacement).side,
|
126
|
+
containerRect: containerEl.getBoundingClientRect(),
|
127
|
+
mouseCoordinates: mouseCoordinatesRef.current,
|
128
|
+
targetRect: targetEl.getBoundingClientRect()
|
129
|
+
});
|
130
|
+
}
|
131
|
+
if (targetWindow) {
|
132
|
+
mouseMoveIdRef.current = targetWindow.requestAnimationFrame(updateSVGs);
|
133
|
+
}
|
134
|
+
}
|
135
|
+
updateSVGs();
|
136
|
+
return;
|
137
|
+
}
|
138
|
+
if (mouseMoveIdRef.current) {
|
139
|
+
var _targetDocument_defaultView;
|
140
|
+
targetDocument === null || targetDocument === void 0 ? void 0 : (_targetDocument_defaultView = targetDocument.defaultView) === null || _targetDocument_defaultView === void 0 ? void 0 : _targetDocument_defaultView.cancelAnimationFrame(mouseMoveIdRef.current);
|
141
|
+
mouseMoveIdRef.current = null;
|
142
|
+
}
|
143
|
+
});
|
144
|
+
}, [
|
145
|
+
stateStore,
|
146
|
+
targetDocument
|
147
|
+
]);
|
126
148
|
return {
|
127
149
|
containerRef: useMergedRefs(containerRef, containerListenerRef),
|
128
150
|
targetRef: useMergedRefs(targetRef, targetListenerRef),
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/useSafeZoneArea.tsx"],"sourcesContent":["import { useFluent_unstable } from '@fluentui/react-shared-contexts';\nimport { useEventCallback, useMergedRefs } from '@fluentui/react-utilities';\nimport type { Placement } from '@floating-ui/dom';\nimport * as React from 'react';\n\nimport { createSafeZoneAreaStateStore, type SafeZoneAreaImperativeHandle, SafeZoneArea } from './SafeZoneArea';\nimport { parseFloatingUIPlacement } from './utils';\n\nexport type SafeBufferAreaOptions = {\n /** Enables debug mode: makes drawn shapes visible. */\n debug?: boolean;\n\n /** Disables the safe zone area. */\n disabled?: boolean;\n\n /** The time in milliseconds to wait before clearing the safe zone. */\n timeout?: number;\n\n /** Called when the mouse enters the safe zone. */\n onSafeZoneEnter?: (e: React.MouseEvent) => void;\n\n /** Called when the mouse moves within the safe zone. */\n onSafeZoneMove?: (e: React.MouseEvent) => void;\n\n /** Called when the mouse leaves the safe zone. */\n onSafeZoneLeave?: (e: React.MouseEvent) => void;\n\n /** Called when the safe zone times out, even if a cursor is still over a safe zone. */\n onSafeZoneTimeout?: () => void;\n};\n\nexport function useSafeZoneArea({\n debug = false,\n disabled = false,\n\n onSafeZoneEnter,\n onSafeZoneMove,\n onSafeZoneLeave,\n onSafeZoneTimeout,\n\n timeout = 1500,\n}: SafeBufferAreaOptions = {}) {\n const [stateStore] = React.useState(createSafeZoneAreaStateStore);\n const { targetDocument } = useFluent_unstable();\n\n const safeZoneAreaRef = React.useRef<SafeZoneAreaImperativeHandle>(null);\n const containerRef = React.useRef<HTMLElement>(null);\n const targetRef = React.useRef<HTMLElement>(null);\n\n const timeoutIdRef = React.useRef<number | null>(null);\n const mouseMoveIdRef = React.useRef<number | null>(null);\n\n const containerListenerRef = React.useMemo(() => {\n if (disabled) {\n return () => {\n // do nothing\n };\n }\n\n let containerEl: HTMLElement | null = null;\n\n function onContainerMouseEnter() {\n const targetWindow = targetDocument?.defaultView;\n\n if (!targetWindow) {\n return;\n }\n\n if (timeoutIdRef.current) {\n targetWindow.clearTimeout(timeoutIdRef.current);\n timeoutIdRef.current = null;\n }\n\n stateStore.toggleActive(false);\n }\n\n return (el: HTMLElement | null) => {\n if (el === null) {\n containerEl?.removeEventListener('mouseenter', onContainerMouseEnter);\n }\n\n containerEl = el;\n el?.addEventListener('mouseenter', onContainerMouseEnter);\n };\n }, [disabled, stateStore, targetDocument]);\n\n const targetListenerRef = React.useMemo(() => {\n if (disabled) {\n return () => {\n // do nothing\n };\n }\n\n let targetEl: HTMLElement | null = null;\n\n function onTargetMouseMove(e: MouseEvent) {\n const targetWindow = targetDocument?.defaultView;\n\n if (!targetWindow) {\n return;\n }\n\n if (timeoutIdRef.current) {\n targetWindow.clearTimeout(timeoutIdRef.current);\n timeoutIdRef.current = null;\n }\n\n if (!stateStore.isActive()) {\n stateStore.toggleActive(true);\n }\n\n mouseMoveIdRef.current = targetWindow.requestAnimationFrame(() => {\n const containerEl = containerRef.current;\n\n if (!containerEl || !targetEl) {\n return;\n }\n\n safeZoneAreaRef.current?.updateSVG({\n containerPlacementSide: parseFloatingUIPlacement(containerEl.dataset.popperPlacement as Placement).side,\n containerRect: containerEl.getBoundingClientRect(),\n mouseCoordinates: { x: e.clientX, y: e.clientY },\n targetRect: targetEl.getBoundingClientRect(),\n });\n });\n }\n\n return (el: HTMLElement | null) => {\n if (el === null) {\n const targetWindow = targetDocument?.defaultView;\n\n if (targetWindow) {\n if (mouseMoveIdRef.current) {\n targetWindow.cancelAnimationFrame(mouseMoveIdRef.current);\n mouseMoveIdRef.current = null;\n }\n\n if (timeoutIdRef.current) {\n targetWindow.clearTimeout(timeoutIdRef.current);\n timeoutIdRef.current = null;\n }\n }\n\n targetEl?.removeEventListener('mousemove', onTargetMouseMove);\n }\n\n targetEl = el;\n el?.addEventListener('mousemove', onTargetMouseMove);\n };\n }, [disabled, stateStore, targetDocument]);\n\n const onSvgMouseEnter = useEventCallback((e: React.MouseEvent) => {\n onSafeZoneEnter?.(e);\n\n const targetWindow = targetDocument?.defaultView;\n\n if (!targetWindow) {\n return;\n }\n\n if (timeoutIdRef.current) {\n targetWindow.clearTimeout(timeoutIdRef.current);\n timeoutIdRef.current = null;\n }\n\n // React 17 still uses pooled synthetic events\n e.persist();\n\n timeoutIdRef.current = targetWindow.setTimeout(() => {\n stateStore.toggleActive(false);\n onSafeZoneTimeout?.();\n }, timeout);\n });\n\n const onSvgMouseMove = useEventCallback((e: React.MouseEvent) => {\n onSafeZoneMove?.(e);\n });\n\n const onSvgMouseLeave = useEventCallback((e: React.MouseEvent) => {\n onSafeZoneLeave?.(e);\n });\n\n return {\n containerRef: useMergedRefs(containerRef, containerListenerRef),\n targetRef: useMergedRefs(targetRef, targetListenerRef),\n\n elementToRender: React.useMemo(\n () =>\n disabled ? null : (\n <SafeZoneArea\n debug={debug}\n onMouseEnter={onSvgMouseEnter}\n onMouseMove={onSvgMouseMove}\n onMouseLeave={onSvgMouseLeave}\n imperativeRef={safeZoneAreaRef}\n stateStore={stateStore}\n />\n ),\n [disabled, debug, onSvgMouseEnter, onSvgMouseMove, onSvgMouseLeave, stateStore],\n ),\n };\n}\n"],"names":["useFluent_unstable","useEventCallback","useMergedRefs","React","createSafeZoneAreaStateStore","SafeZoneArea","parseFloatingUIPlacement","useSafeZoneArea","debug","disabled","onSafeZoneEnter","onSafeZoneMove","onSafeZoneLeave","onSafeZoneTimeout","timeout","stateStore","useState","targetDocument","safeZoneAreaRef","useRef","containerRef","targetRef","timeoutIdRef","mouseMoveIdRef","containerListenerRef","useMemo","containerEl","onContainerMouseEnter","targetWindow","defaultView","current","clearTimeout","toggleActive","el","removeEventListener","addEventListener","targetListenerRef","targetEl","onTargetMouseMove","e","isActive","requestAnimationFrame","updateSVG","containerPlacementSide","dataset","popperPlacement","side","containerRect","getBoundingClientRect","mouseCoordinates","x","clientX","y","clientY","targetRect","cancelAnimationFrame","onSvgMouseEnter","persist","setTimeout","onSvgMouseMove","onSvgMouseLeave","elementToRender","onMouseEnter","onMouseMove","onMouseLeave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,YAAYA;gBAGlB;YAACN;YAAUD;YAAOgD;YAAiBG;YAAgBC;YAAiB7C;SAAW;IAEnF;AACF"}
|
1
|
+
{"version":3,"sources":["../src/useSafeZoneArea.tsx"],"sourcesContent":["import { useFluent_unstable } from '@fluentui/react-shared-contexts';\nimport { useEventCallback, useMergedRefs } from '@fluentui/react-utilities';\nimport type { Placement } from '@floating-ui/dom';\nimport * as React from 'react';\n\nimport { createSafeZoneAreaStateStore, type SafeZoneAreaImperativeHandle, SafeZoneArea } from './SafeZoneArea';\nimport { parseFloatingUIPlacement } from './utils';\n\nexport type SafeBufferAreaOptions = {\n /** Enables debug mode: makes drawn shapes visible. */\n debug?: boolean;\n\n /** Disables the safe zone area. */\n disabled?: boolean;\n\n /** The time in milliseconds to wait before clearing the safe zone. */\n timeout?: number;\n\n /** Called when the mouse enters the safe zone. */\n onSafeZoneEnter?: (e: React.MouseEvent) => void;\n\n /** Called when the mouse moves within the safe zone. */\n onSafeZoneMove?: (e: React.MouseEvent) => void;\n\n /** Called when the mouse leaves the safe zone. */\n onSafeZoneLeave?: (e: React.MouseEvent) => void;\n\n /** Called when the safe zone times out, even if a cursor is still over a safe zone. */\n onSafeZoneTimeout?: () => void;\n};\n\nexport function useSafeZoneArea({\n debug = false,\n disabled = false,\n\n onSafeZoneEnter,\n onSafeZoneMove,\n onSafeZoneLeave,\n onSafeZoneTimeout,\n\n timeout = 1500,\n}: SafeBufferAreaOptions = {}) {\n const [stateStore] = React.useState(createSafeZoneAreaStateStore);\n const { targetDocument } = useFluent_unstable();\n\n const safeZoneAreaRef = React.useRef<SafeZoneAreaImperativeHandle>(null);\n const containerRef = React.useRef<HTMLElement>(null);\n const targetRef = React.useRef<HTMLElement>(null);\n\n const timeoutIdRef = React.useRef<number | null>(null);\n const mouseMoveIdRef = React.useRef<number | null>(null);\n\n const mouseCoordinatesRef = React.useRef<{ x: number; y: number }>({ x: 0, y: 0 });\n\n const containerListenerRef = React.useMemo(() => {\n if (disabled) {\n return () => {\n // do nothing\n };\n }\n\n let containerEl: HTMLElement | null = null;\n\n function onContainerMouseEnter() {\n const targetWindow = targetDocument?.defaultView;\n\n if (!targetWindow) {\n return;\n }\n\n if (timeoutIdRef.current) {\n targetWindow.clearTimeout(timeoutIdRef.current);\n timeoutIdRef.current = null;\n }\n\n stateStore.toggleActive(false);\n }\n\n return (el: HTMLElement | null) => {\n if (el === null) {\n containerEl?.removeEventListener('mouseenter', onContainerMouseEnter);\n }\n\n containerEl = el;\n el?.addEventListener('mouseenter', onContainerMouseEnter);\n };\n }, [disabled, stateStore, targetDocument]);\n\n const targetListenerRef = React.useMemo(() => {\n if (disabled) {\n return () => {\n // do nothing\n };\n }\n\n let targetEl: HTMLElement | null = null;\n\n function onTargetMouseMove(e: MouseEvent) {\n mouseCoordinatesRef.current = { x: e.clientX, y: e.clientY };\n\n if (timeoutIdRef.current) {\n targetDocument?.defaultView?.clearTimeout(timeoutIdRef.current);\n timeoutIdRef.current = null;\n }\n\n if (!stateStore.isActive()) {\n stateStore.toggleActive(true);\n }\n }\n\n return (el: HTMLElement | null) => {\n if (el === null) {\n const targetWindow = targetDocument?.defaultView;\n\n if (targetWindow) {\n if (mouseMoveIdRef.current) {\n targetWindow.cancelAnimationFrame(mouseMoveIdRef.current);\n mouseMoveIdRef.current = null;\n }\n\n if (timeoutIdRef.current) {\n targetWindow.clearTimeout(timeoutIdRef.current);\n timeoutIdRef.current = null;\n }\n }\n\n targetEl?.removeEventListener('mousemove', onTargetMouseMove);\n }\n\n targetEl = el;\n el?.addEventListener('mousemove', onTargetMouseMove);\n };\n }, [disabled, stateStore, targetDocument]);\n\n const onSvgMouseEnter = useEventCallback((e: React.MouseEvent) => {\n onSafeZoneEnter?.(e);\n\n const targetWindow = targetDocument?.defaultView;\n\n if (!targetWindow) {\n return;\n }\n\n if (timeoutIdRef.current) {\n targetWindow.clearTimeout(timeoutIdRef.current);\n timeoutIdRef.current = null;\n }\n\n // React 17 still uses pooled synthetic events\n e.persist();\n\n timeoutIdRef.current = targetWindow.setTimeout(() => {\n stateStore.toggleActive(false);\n onSafeZoneTimeout?.();\n }, timeout);\n });\n\n const onSvgMouseMove = useEventCallback((e: React.MouseEvent) => {\n onSafeZoneMove?.(e);\n });\n\n const onSvgMouseLeave = useEventCallback((e: React.MouseEvent) => {\n onSafeZoneLeave?.(e);\n });\n\n React.useEffect(() => {\n return stateStore.subscribe(isActive => {\n if (isActive) {\n function updateSVGs() {\n const containerEl = containerRef.current;\n const targetEl = targetRef.current;\n const targetWindow = targetDocument?.defaultView;\n\n if (containerEl && targetEl) {\n safeZoneAreaRef.current?.updateSVG({\n containerPlacementSide: parseFloatingUIPlacement(containerEl.dataset.popperPlacement as Placement).side,\n containerRect: containerEl.getBoundingClientRect(),\n mouseCoordinates: mouseCoordinatesRef.current,\n targetRect: targetEl.getBoundingClientRect(),\n });\n }\n\n if (targetWindow) {\n mouseMoveIdRef.current = targetWindow.requestAnimationFrame(updateSVGs);\n }\n }\n\n updateSVGs();\n return;\n }\n\n if (mouseMoveIdRef.current) {\n targetDocument?.defaultView?.cancelAnimationFrame(mouseMoveIdRef.current);\n mouseMoveIdRef.current = null;\n }\n });\n }, [stateStore, targetDocument]);\n\n return {\n containerRef: useMergedRefs(containerRef, containerListenerRef),\n targetRef: useMergedRefs(targetRef, targetListenerRef),\n\n elementToRender: React.useMemo(\n () =>\n disabled ? null : (\n <SafeZoneArea\n debug={debug}\n onMouseEnter={onSvgMouseEnter}\n onMouseMove={onSvgMouseMove}\n onMouseLeave={onSvgMouseLeave}\n imperativeRef={safeZoneAreaRef}\n stateStore={stateStore}\n />\n ),\n [disabled, debug, onSvgMouseEnter, onSvgMouseMove, onSvgMouseLeave, stateStore],\n ),\n };\n}\n"],"names":["useFluent_unstable","useEventCallback","useMergedRefs","React","createSafeZoneAreaStateStore","SafeZoneArea","parseFloatingUIPlacement","useSafeZoneArea","debug","disabled","onSafeZoneEnter","onSafeZoneMove","onSafeZoneLeave","onSafeZoneTimeout","timeout","stateStore","useState","targetDocument","safeZoneAreaRef","useRef","containerRef","targetRef","timeoutIdRef","mouseMoveIdRef","mouseCoordinatesRef","x","y","containerListenerRef","useMemo","containerEl","onContainerMouseEnter","targetWindow","defaultView","current","clearTimeout","toggleActive","el","removeEventListener","addEventListener","targetListenerRef","targetEl","onTargetMouseMove","e","clientX","clientY","isActive","cancelAnimationFrame","onSvgMouseEnter","persist","setTimeout","onSvgMouseMove","onSvgMouseLeave","useEffect","subscribe","updateSVGs","updateSVG","containerPlacementSide","dataset","popperPlacement","side","containerRect","getBoundingClientRect","mouseCoordinates","targetRect","requestAnimationFrame","elementToRender","onMouseEnter","onMouseMove","onMouseLeave","imperativeRef"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,kBAAkB,QAAQ,kCAAkC;AACrE,SAASC,gBAAgB,EAAEC,aAAa,QAAQ,4BAA4B;AAE5E,YAAYC,WAAW,QAAQ;AAE/B,SAASC,4BAA4B,EAAqCC,YAAY,QAAQ,iBAAiB;AAC/G,SAASC,wBAAwB,QAAQ,UAAU;AAyBnD,OAAO,SAASC,gBAAgB,EAC9BC,QAAQ,KAAK,EACbC,WAAW,KAAK,EAEhBC,eAAe,EACfC,cAAc,EACdC,eAAe,EACfC,iBAAiB,EAEjBC,UAAU,IAAI,EACQ,GAAG,CAAC,CAAC;IAC3B,MAAM,CAACC,WAAW,GAAGZ,MAAMa,QAAQ,CAACZ;IACpC,MAAM,EAAEa,cAAc,EAAE,GAAGjB;IAE3B,MAAMkB,kBAAkBf,MAAMgB,MAAM,CAA+B;IACnE,MAAMC,eAAejB,MAAMgB,MAAM,CAAc;IAC/C,MAAME,YAAYlB,MAAMgB,MAAM,CAAc;IA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ACP,MAAMzB,cAAcT,aAAaa,OAAO;oBACxC,MAAMO,WAAWnB,UAAUY,OAAO;oBAClC,MAAMF,eAAed,2BAAAA,qCAAAA,eAAgBe,WAAW;oBAEhD,IAAIH,eAAeW,UAAU;4BAC3BtB;yBAAAA,2BAAAA,gBAAgBe,OAAO,cAAvBf,+CAAAA,yBAAyBqC,SAAS,CAAC;4BACjCC,wBAAwBlD,yBAAyBuB,YAAY4B,OAAO,CAACC,eAAe,EAAeC,IAAI;4BACvGC,eAAe/B,YAAYgC,qBAAqB;4BAChDC,kBAAkBtC,oBAAoBS,OAAO;4BAC7C8B,YAAYvB,SAASqB,qBAAqB;wBAC5C;oBACF;oBAEA,IAAI9B,cAAc;wBAChBR,eAAeU,OAAO,GAAGF,aAAaiC,qBAAqB,CAACV;oBAC9D;gBACF;gBAEAA;gBACA;YACF;YAEA,IAAI/B,eAAeU,OAAO,EAAE;oBAC1BhB;gBAAAA,2BAAAA,sCAAAA,8BAAAA,eAAgBe,WAAW,cAA3Bf,kDAAAA,4BAA6B6B,oBAAoB,CAACvB,eAAeU,OAAO;gBACxEV,eAAeU,OAAO,GAAG;YAC3B;QACF;IACF,GAAG;QAAClB;QAAYE;KAAe;IAE/B,OAAO;QACLG,cAAclB,cAAckB,cAAcO;QAC1CN,WAAWnB,cAAcmB,WAAWkB;QAEpC0B,iBAAiB9D,MAAMyB,OAAO,CAC5B,IACEnB,WAAW,qBACT,oBAACJ;gBACCG,OAAOA;gBACP0D,cAAcnB;gBACdoB,aAAajB;gBACbkB,cAAcjB;gBACdkB,eAAenD;gBACfH,YAAYA;gBAGlB;YAACN;YAAUD;YAAOuC;YAAiBG;YAAgBC;YAAiBpC;SAAW;IAEnF;AACF"}
|
@@ -1 +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":["SafeZoneArea","createSafeZoneAreaStateStore","isActive","listeners","toggleActive","newIsActive","forEach","listener","subscribe","push","index","indexOf","splice","React","memo","props","debug","onMouseEnter","onMouseMove","onMouseLeave","stateStore","clipPathId","useId","styles","useStyles","active","useSyncExternalStore","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","createElement","div","className","mergeClasses","wrapper","wrapperActive","data-safe-zone","svg","aria-hidden","xmlns","ref","path","triangle","triangleDebug","id","rectDebug"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,CAAAA,IAAKA,GAAGC,IAAI,CAAC,KAAK,EAAE,CAAC;gBACrE,MAAMC,WAAW,CAAC,EAAE,EAAEd,WAAWW,OAAO,CAACC,CAAAA,IAAKA,GAAGC,IAAI,CAAC,KAAK,EAAE,CAAC;gBAE9DE,OAAOC,MAAM,CAAC5B,MAAM6B,KAAK,EAAEnB;gBAE3BR,eAAe4B,cAAc,CAAC,MAAM,KAAKR;gBACzCf,aAAauB,cAAc,CAAC,MAAM,KAAKJ;gBACvCrB,gBAAAA,QAAAA,gBAAAA,KAAAA,IAAAA,KAAAA,IAAAA,YAAayB,cAAc,CAAC,MAAM,KAAKJ;YACzC;QACF,CAAA,GACA,EAAE;IAGJ,OAAA,WAAA,GACEjD,QAAAsD,aAAA,CAACC,OAAAA;QAAIC,WAAWC,IAAAA,mBAAAA,EAAa/C,OAAOgD,OAAO,EAAE9C,UAAUF,OAAOiD,aAAa;QAAGC,kBAAe;OAC1FhD,SAAAA,WAAAA,GACCZ,QAAAsD,aAAA,CAACO,OAAAA;QAAIC,eAAAA;QAAYN,WAAW9C,OAAOmD,GAAG;QAAEE,OAAM;QAA6BC,KAAKlD;qBAC9Ed,QAAAsD,aAAA,CAACW,QAAAA;QACCT,WAAWC,IAAAA,mBAAAA,EAAa/C,OAAOwD,QAAQ,EAAE/D,SAASO,OAAOyD,aAAa;QACtElB,UAAU,CAAC,KAAK,EAAEzC,WAAW,CAAC,CAAC;QAC/BJ,cAAcA;QACdC,aAAaA;QACbC,cAAcA;sBAEhBN,QAAAsD,aAAA,CAACL,YAAAA;QAASmB,IAAI5D;qBACZR,QAAAsD,aAAA,CAACW,QAAAA,QAGF9D,SAAAA,WAAAA,GAASH,QAAAsD,aAAA,CAACW,QAAAA;QAAKT,WAAW9C,OAAO2D,SAAS;UAE3C;AAGV"}
|
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 if (isActive === newIsActive) {\n return;\n }\n\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":["SafeZoneArea","createSafeZoneAreaStateStore","isActive","listeners","toggleActive","newIsActive","forEach","listener","subscribe","push","index","indexOf","splice","React","memo","props","debug","onMouseEnter","onMouseMove","onMouseLeave","stateStore","clipPathId","useId","styles","useStyles","active","useSyncExternalStore","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","createElement","div","className","mergeClasses","wrapper","wrapperActive","data-safe-zone","svg","aria-hidden","xmlns","ref","path","triangle","triangleDebug","id","rectDebug"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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-22,6 +22,10 @@ function useSafeZoneArea({ debug = false, disabled = false, onSafeZoneEnter, onS
|
|
22
22
|
const targetRef = _react.useRef(null);
|
23
23
|
const timeoutIdRef = _react.useRef(null);
|
24
24
|
const mouseMoveIdRef = _react.useRef(null);
|
25
|
+
const mouseCoordinatesRef = _react.useRef({
|
26
|
+
x: 0,
|
27
|
+
y: 0
|
28
|
+
});
|
25
29
|
const containerListenerRef = _react.useMemo(()=>{
|
26
30
|
if (disabled) {
|
27
31
|
return ()=>{
|
@@ -60,33 +64,18 @@ function useSafeZoneArea({ debug = false, disabled = false, onSafeZoneEnter, onS
|
|
60
64
|
}
|
61
65
|
let targetEl = null;
|
62
66
|
function onTargetMouseMove(e) {
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
}
|
67
|
+
mouseCoordinatesRef.current = {
|
68
|
+
x: e.clientX,
|
69
|
+
y: e.clientY
|
70
|
+
};
|
67
71
|
if (timeoutIdRef.current) {
|
68
|
-
|
72
|
+
var _targetDocument_defaultView;
|
73
|
+
targetDocument === null || targetDocument === void 0 ? void 0 : (_targetDocument_defaultView = targetDocument.defaultView) === null || _targetDocument_defaultView === void 0 ? void 0 : _targetDocument_defaultView.clearTimeout(timeoutIdRef.current);
|
69
74
|
timeoutIdRef.current = null;
|
70
75
|
}
|
71
76
|
if (!stateStore.isActive()) {
|
72
77
|
stateStore.toggleActive(true);
|
73
78
|
}
|
74
|
-
mouseMoveIdRef.current = targetWindow.requestAnimationFrame(()=>{
|
75
|
-
var _safeZoneAreaRef_current;
|
76
|
-
const containerEl = containerRef.current;
|
77
|
-
if (!containerEl || !targetEl) {
|
78
|
-
return;
|
79
|
-
}
|
80
|
-
(_safeZoneAreaRef_current = safeZoneAreaRef.current) === null || _safeZoneAreaRef_current === void 0 ? void 0 : _safeZoneAreaRef_current.updateSVG({
|
81
|
-
containerPlacementSide: (0, _utils.parseFloatingUIPlacement)(containerEl.dataset.popperPlacement).side,
|
82
|
-
containerRect: containerEl.getBoundingClientRect(),
|
83
|
-
mouseCoordinates: {
|
84
|
-
x: e.clientX,
|
85
|
-
y: e.clientY
|
86
|
-
},
|
87
|
-
targetRect: targetEl.getBoundingClientRect()
|
88
|
-
});
|
89
|
-
});
|
90
79
|
}
|
91
80
|
return (el)=>{
|
92
81
|
if (el === null) {
|
@@ -134,6 +123,39 @@ function useSafeZoneArea({ debug = false, disabled = false, onSafeZoneEnter, onS
|
|
134
123
|
const onSvgMouseLeave = (0, _reactutilities.useEventCallback)((e)=>{
|
135
124
|
onSafeZoneLeave === null || onSafeZoneLeave === void 0 ? void 0 : onSafeZoneLeave(e);
|
136
125
|
});
|
126
|
+
_react.useEffect(()=>{
|
127
|
+
return stateStore.subscribe((isActive)=>{
|
128
|
+
if (isActive) {
|
129
|
+
function updateSVGs() {
|
130
|
+
const containerEl = containerRef.current;
|
131
|
+
const targetEl = targetRef.current;
|
132
|
+
const targetWindow = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.defaultView;
|
133
|
+
if (containerEl && targetEl) {
|
134
|
+
var _safeZoneAreaRef_current;
|
135
|
+
(_safeZoneAreaRef_current = safeZoneAreaRef.current) === null || _safeZoneAreaRef_current === void 0 ? void 0 : _safeZoneAreaRef_current.updateSVG({
|
136
|
+
containerPlacementSide: (0, _utils.parseFloatingUIPlacement)(containerEl.dataset.popperPlacement).side,
|
137
|
+
containerRect: containerEl.getBoundingClientRect(),
|
138
|
+
mouseCoordinates: mouseCoordinatesRef.current,
|
139
|
+
targetRect: targetEl.getBoundingClientRect()
|
140
|
+
});
|
141
|
+
}
|
142
|
+
if (targetWindow) {
|
143
|
+
mouseMoveIdRef.current = targetWindow.requestAnimationFrame(updateSVGs);
|
144
|
+
}
|
145
|
+
}
|
146
|
+
updateSVGs();
|
147
|
+
return;
|
148
|
+
}
|
149
|
+
if (mouseMoveIdRef.current) {
|
150
|
+
var _targetDocument_defaultView;
|
151
|
+
targetDocument === null || targetDocument === void 0 ? void 0 : (_targetDocument_defaultView = targetDocument.defaultView) === null || _targetDocument_defaultView === void 0 ? void 0 : _targetDocument_defaultView.cancelAnimationFrame(mouseMoveIdRef.current);
|
152
|
+
mouseMoveIdRef.current = null;
|
153
|
+
}
|
154
|
+
});
|
155
|
+
}, [
|
156
|
+
stateStore,
|
157
|
+
targetDocument
|
158
|
+
]);
|
137
159
|
return {
|
138
160
|
containerRef: (0, _reactutilities.useMergedRefs)(containerRef, containerListenerRef),
|
139
161
|
targetRef: (0, _reactutilities.useMergedRefs)(targetRef, targetListenerRef),
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"sources":["../src/useSafeZoneArea.tsx"],"sourcesContent":["import { useFluent_unstable } from '@fluentui/react-shared-contexts';\nimport { useEventCallback, useMergedRefs } from '@fluentui/react-utilities';\nimport type { Placement } from '@floating-ui/dom';\nimport * as React from 'react';\n\nimport { createSafeZoneAreaStateStore, type SafeZoneAreaImperativeHandle, SafeZoneArea } from './SafeZoneArea';\nimport { parseFloatingUIPlacement } from './utils';\n\nexport type SafeBufferAreaOptions = {\n /** Enables debug mode: makes drawn shapes visible. */\n debug?: boolean;\n\n /** Disables the safe zone area. */\n disabled?: boolean;\n\n /** The time in milliseconds to wait before clearing the safe zone. */\n timeout?: number;\n\n /** Called when the mouse enters the safe zone. */\n onSafeZoneEnter?: (e: React.MouseEvent) => void;\n\n /** Called when the mouse moves within the safe zone. */\n onSafeZoneMove?: (e: React.MouseEvent) => void;\n\n /** Called when the mouse leaves the safe zone. */\n onSafeZoneLeave?: (e: React.MouseEvent) => void;\n\n /** Called when the safe zone times out, even if a cursor is still over a safe zone. */\n onSafeZoneTimeout?: () => void;\n};\n\nexport function useSafeZoneArea({\n debug = false,\n disabled = false,\n\n onSafeZoneEnter,\n onSafeZoneMove,\n onSafeZoneLeave,\n onSafeZoneTimeout,\n\n timeout = 1500,\n}: SafeBufferAreaOptions = {}) {\n const [stateStore] = React.useState(createSafeZoneAreaStateStore);\n const { targetDocument } = useFluent_unstable();\n\n const safeZoneAreaRef = React.useRef<SafeZoneAreaImperativeHandle>(null);\n const containerRef = React.useRef<HTMLElement>(null);\n const targetRef = React.useRef<HTMLElement>(null);\n\n const timeoutIdRef = React.useRef<number | null>(null);\n const mouseMoveIdRef = React.useRef<number | null>(null);\n\n const containerListenerRef = React.useMemo(() => {\n if (disabled) {\n return () => {\n // do nothing\n };\n }\n\n let containerEl: HTMLElement | null = null;\n\n function onContainerMouseEnter() {\n const targetWindow = targetDocument?.defaultView;\n\n if (!targetWindow) {\n return;\n }\n\n if (timeoutIdRef.current) {\n targetWindow.clearTimeout(timeoutIdRef.current);\n timeoutIdRef.current = null;\n }\n\n stateStore.toggleActive(false);\n }\n\n return (el: HTMLElement | null) => {\n if (el === null) {\n containerEl?.removeEventListener('mouseenter', onContainerMouseEnter);\n }\n\n containerEl = el;\n el?.addEventListener('mouseenter', onContainerMouseEnter);\n };\n }, [disabled, stateStore, targetDocument]);\n\n const targetListenerRef = React.useMemo(() => {\n if (disabled) {\n return () => {\n // do nothing\n };\n }\n\n let targetEl: HTMLElement | null = null;\n\n function onTargetMouseMove(e: MouseEvent) {\n const targetWindow = targetDocument?.defaultView;\n\n if (!targetWindow) {\n return;\n }\n\n if (timeoutIdRef.current) {\n targetWindow.clearTimeout(timeoutIdRef.current);\n timeoutIdRef.current = null;\n }\n\n if (!stateStore.isActive()) {\n stateStore.toggleActive(true);\n }\n\n mouseMoveIdRef.current = targetWindow.requestAnimationFrame(() => {\n const containerEl = containerRef.current;\n\n if (!containerEl || !targetEl) {\n return;\n }\n\n safeZoneAreaRef.current?.updateSVG({\n containerPlacementSide: parseFloatingUIPlacement(containerEl.dataset.popperPlacement as Placement).side,\n containerRect: containerEl.getBoundingClientRect(),\n mouseCoordinates: { x: e.clientX, y: e.clientY },\n targetRect: targetEl.getBoundingClientRect(),\n });\n });\n }\n\n return (el: HTMLElement | null) => {\n if (el === null) {\n const targetWindow = targetDocument?.defaultView;\n\n if (targetWindow) {\n if (mouseMoveIdRef.current) {\n targetWindow.cancelAnimationFrame(mouseMoveIdRef.current);\n mouseMoveIdRef.current = null;\n }\n\n if (timeoutIdRef.current) {\n targetWindow.clearTimeout(timeoutIdRef.current);\n timeoutIdRef.current = null;\n }\n }\n\n targetEl?.removeEventListener('mousemove', onTargetMouseMove);\n }\n\n targetEl = el;\n el?.addEventListener('mousemove', onTargetMouseMove);\n };\n }, [disabled, stateStore, targetDocument]);\n\n const onSvgMouseEnter = useEventCallback((e: React.MouseEvent) => {\n onSafeZoneEnter?.(e);\n\n const targetWindow = targetDocument?.defaultView;\n\n if (!targetWindow) {\n return;\n }\n\n if (timeoutIdRef.current) {\n targetWindow.clearTimeout(timeoutIdRef.current);\n timeoutIdRef.current = null;\n }\n\n // React 17 still uses pooled synthetic events\n e.persist();\n\n timeoutIdRef.current = targetWindow.setTimeout(() => {\n stateStore.toggleActive(false);\n onSafeZoneTimeout?.();\n }, timeout);\n });\n\n const onSvgMouseMove = useEventCallback((e: React.MouseEvent) => {\n onSafeZoneMove?.(e);\n });\n\n const onSvgMouseLeave = useEventCallback((e: React.MouseEvent) => {\n onSafeZoneLeave?.(e);\n });\n\n return {\n containerRef: useMergedRefs(containerRef, containerListenerRef),\n targetRef: useMergedRefs(targetRef, targetListenerRef),\n\n elementToRender: React.useMemo(\n () =>\n disabled ? null : (\n <SafeZoneArea\n debug={debug}\n onMouseEnter={onSvgMouseEnter}\n onMouseMove={onSvgMouseMove}\n onMouseLeave={onSvgMouseLeave}\n imperativeRef={safeZoneAreaRef}\n stateStore={stateStore}\n />\n ),\n [disabled, debug, onSvgMouseEnter, onSvgMouseMove, onSvgMouseLeave, stateStore],\n ),\n };\n}\n"],"names":["useSafeZoneArea","debug","disabled","onSafeZoneEnter","onSafeZoneMove","onSafeZoneLeave","onSafeZoneTimeout","timeout","stateStore","React","useState","createSafeZoneAreaStateStore","targetDocument","useFluent_unstable","safeZoneAreaRef","useRef","containerRef","targetRef","timeoutIdRef","mouseMoveIdRef","containerListenerRef","useMemo","containerEl","onContainerMouseEnter","targetWindow","defaultView","current","clearTimeout","toggleActive","el","removeEventListener","addEventListener","targetListenerRef","targetEl","onTargetMouseMove","e","isActive","requestAnimationFrame","updateSVG","containerPlacementSide","parseFloatingUIPlacement","dataset","popperPlacement","side","containerRect","getBoundingClientRect","mouseCoordinates","x","clientX","y","clientY","targetRect","cancelAnimationFrame","onSvgMouseEnter","useEventCallback","persist","setTimeout","onSvgMouseMove","onSvgMouseLeave","useMergedRefs","elementToRender","createElement","SafeZoneArea","onMouseEnter","onMouseMove","onMouseLeave","imperativeRef"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":";;;;+BA+BgBA;;;eAAAA;;;;qCA/BmB;gCACa;iEAEzB;8BAEuE;uBACrD;AAyBlC,SAASA,gBAAgB,EAC9BC,QAAQ,KAAK,EACbC,WAAW,KAAK,EAEhBC,eAAe,EACfC,cAAc,EACdC,eAAe,EACfC,iBAAiB,EAEjBC,UAAU,IAAI,EACQ,GAAG,CAAC,CAAC;IAC3B,MAAM,CAACC,WAAW,GAAGC,OAAMC,QAAQ,CAACC,0CAAAA;IACpC,MAAM,EAAEC,cAAc,EAAE,GAAGC,IAAAA,uCAAAA;IAE3B,MAAMC,kBAAkBL,OAAMM,MAAM,CAA+B;IACnE,MAAMC,eAAeP,OAAMM,MAAM,CAAc;IAC/C,MAAME,YAAYR,OAAMM,MAAM,CAAc;IAE5C,MAAMG,eAAeT,OAAMM,MAAM,CAAgB;IACjD,MAAMI,iBAAiBV,OAAMM,MAAM,CAAgB;IAEnD,MAAMK,uBAAuBX,OAAMY,OAAO,CAAC;QACzC,IAAInB,UAAU;YACZ,OAAO;YACL,aAAa;YACf;QACF;QAEA,IAAIoB,cAAkC;QAEtC,SAASC;YACP,MAAMC,e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CAACT,aAAaQ,OAAO;YAC9CR,aAAaQ,OAAO,GAAG;QACzB;QAEA,8CAA8C;QAC9CS,EAAEoB,OAAO;QAETrC,aAAaQ,OAAO,GAAGF,aAAagC,UAAU,CAAC;YAC7ChD,WAAWoB,YAAY,CAAC;YACxBtB,sBAAAA,QAAAA,sBAAAA,KAAAA,IAAAA,KAAAA,IAAAA;QACF,GAAGC;IACL;IAEA,MAAMkD,iBAAiBH,IAAAA,gCAAAA,EAAiB,CAACnB;QACvC/B,mBAAAA,QAAAA,mBAAAA,KAAAA,IAAAA,KAAAA,IAAAA,eAAiB+B;IACnB;IAEA,MAAMuB,kBAAkBJ,IAAAA,gCAAAA,EAAiB,CAACnB;QACxC9B,oBAAAA,QAAAA,oBAAAA,KAAAA,IAAAA,KAAAA,IAAAA,gBAAkB8B;IACpB;IAEA,OAAO;QACLnB,cAAc2C,IAAAA,6BAAAA,EAAc3C,cAAcI;QAC1CH,WAAW0C,IAAAA,6BAAAA,EAAc1C,WAAWe;QAEpC4B,iBAAiBnD,OAAMY,OAAO,CAC5B,IACEnB,WAAW,OAAA,WAAA,GACTO,OAAAoD,aAAA,CAACC,0BAAAA,EAAAA;gBACC7D,OAAOA;gBACP8D,cAAcV;gBACdW,aAAaP;gBACbQ,cAAcP;gBACdQ,eAAepD;gBACfN,YAAYA;gBAGlB;YAACN;YAAUD;YAAOoD;YAAiBI;YAAgBC;YAAiBlD;SAAW;IAEnF;AACF"}
|
1
|
+
{"version":3,"sources":["../src/useSafeZoneArea.tsx"],"sourcesContent":["import { useFluent_unstable } from '@fluentui/react-shared-contexts';\nimport { useEventCallback, useMergedRefs } from '@fluentui/react-utilities';\nimport type { Placement } from '@floating-ui/dom';\nimport * as React from 'react';\n\nimport { createSafeZoneAreaStateStore, type SafeZoneAreaImperativeHandle, SafeZoneArea } from './SafeZoneArea';\nimport { parseFloatingUIPlacement } from './utils';\n\nexport type SafeBufferAreaOptions = {\n /** Enables debug mode: makes drawn shapes visible. */\n debug?: boolean;\n\n /** Disables the safe zone area. */\n disabled?: boolean;\n\n /** The time in milliseconds to wait before clearing the safe zone. */\n timeout?: number;\n\n /** Called when the mouse enters the safe zone. */\n onSafeZoneEnter?: (e: React.MouseEvent) => void;\n\n /** Called when the mouse moves within the safe zone. */\n onSafeZoneMove?: (e: React.MouseEvent) => void;\n\n /** Called when the mouse leaves the safe zone. */\n onSafeZoneLeave?: (e: React.MouseEvent) => void;\n\n /** Called when the safe zone times out, even if a cursor is still over a safe zone. */\n onSafeZoneTimeout?: () => void;\n};\n\nexport function useSafeZoneArea({\n debug = false,\n disabled = false,\n\n onSafeZoneEnter,\n onSafeZoneMove,\n onSafeZoneLeave,\n onSafeZoneTimeout,\n\n timeout = 1500,\n}: SafeBufferAreaOptions = {}) {\n const [stateStore] = React.useState(createSafeZoneAreaStateStore);\n const { targetDocument } = useFluent_unstable();\n\n const safeZoneAreaRef = React.useRef<SafeZoneAreaImperativeHandle>(null);\n const containerRef = React.useRef<HTMLElement>(null);\n const targetRef = React.useRef<HTMLElement>(null);\n\n const timeoutIdRef = React.useRef<number | null>(null);\n const mouseMoveIdRef = React.useRef<number | null>(null);\n\n const mouseCoordinatesRef = React.useRef<{ x: number; y: number }>({ x: 0, y: 0 });\n\n const containerListenerRef = React.useMemo(() => {\n if (disabled) {\n return () => {\n // do nothing\n };\n }\n\n let containerEl: HTMLElement | null = null;\n\n function onContainerMouseEnter() {\n const targetWindow = targetDocument?.defaultView;\n\n if (!targetWindow) {\n return;\n }\n\n if (timeoutIdRef.current) {\n targetWindow.clearTimeout(timeoutIdRef.current);\n timeoutIdRef.current = null;\n }\n\n stateStore.toggleActive(false);\n }\n\n return (el: HTMLElement | null) => {\n if (el === null) {\n containerEl?.removeEventListener('mouseenter', onContainerMouseEnter);\n }\n\n containerEl = el;\n el?.addEventListener('mouseenter', onContainerMouseEnter);\n };\n }, [disabled, stateStore, targetDocument]);\n\n const targetListenerRef = React.useMemo(() => {\n if (disabled) {\n return () => {\n // do nothing\n };\n }\n\n let targetEl: HTMLElement | null = null;\n\n function onTargetMouseMove(e: MouseEvent) {\n mouseCoordinatesRef.current = { x: e.clientX, y: e.clientY };\n\n if (timeoutIdRef.current) {\n targetDocument?.defaultView?.clearTimeout(timeoutIdRef.current);\n timeoutIdRef.current = null;\n }\n\n if (!stateStore.isActive()) {\n stateStore.toggleActive(true);\n }\n }\n\n return (el: HTMLElement | null) => {\n if (el === null) {\n const targetWindow = targetDocument?.defaultView;\n\n if (targetWindow) {\n if (mouseMoveIdRef.current) {\n targetWindow.cancelAnimationFrame(mouseMoveIdRef.current);\n mouseMoveIdRef.current = null;\n }\n\n if (timeoutIdRef.current) {\n targetWindow.clearTimeout(timeoutIdRef.current);\n timeoutIdRef.current = null;\n }\n }\n\n targetEl?.removeEventListener('mousemove', onTargetMouseMove);\n }\n\n targetEl = el;\n el?.addEventListener('mousemove', onTargetMouseMove);\n };\n }, [disabled, stateStore, targetDocument]);\n\n const onSvgMouseEnter = useEventCallback((e: React.MouseEvent) => {\n onSafeZoneEnter?.(e);\n\n const targetWindow = targetDocument?.defaultView;\n\n if (!targetWindow) {\n return;\n }\n\n if (timeoutIdRef.current) {\n targetWindow.clearTimeout(timeoutIdRef.current);\n timeoutIdRef.current = null;\n }\n\n // React 17 still uses pooled synthetic events\n e.persist();\n\n timeoutIdRef.current = targetWindow.setTimeout(() => {\n stateStore.toggleActive(false);\n onSafeZoneTimeout?.();\n }, timeout);\n });\n\n const onSvgMouseMove = useEventCallback((e: React.MouseEvent) => {\n onSafeZoneMove?.(e);\n });\n\n const onSvgMouseLeave = useEventCallback((e: React.MouseEvent) => {\n onSafeZoneLeave?.(e);\n });\n\n React.useEffect(() => {\n return stateStore.subscribe(isActive => {\n if (isActive) {\n function updateSVGs() {\n const containerEl = containerRef.current;\n const targetEl = targetRef.current;\n const targetWindow = targetDocument?.defaultView;\n\n if (containerEl && targetEl) {\n safeZoneAreaRef.current?.updateSVG({\n containerPlacementSide: parseFloatingUIPlacement(containerEl.dataset.popperPlacement as Placement).side,\n containerRect: containerEl.getBoundingClientRect(),\n mouseCoordinates: mouseCoordinatesRef.current,\n targetRect: targetEl.getBoundingClientRect(),\n });\n }\n\n if (targetWindow) {\n mouseMoveIdRef.current = targetWindow.requestAnimationFrame(updateSVGs);\n }\n }\n\n updateSVGs();\n return;\n }\n\n if (mouseMoveIdRef.current) {\n targetDocument?.defaultView?.cancelAnimationFrame(mouseMoveIdRef.current);\n mouseMoveIdRef.current = null;\n }\n });\n }, [stateStore, targetDocument]);\n\n return {\n containerRef: useMergedRefs(containerRef, containerListenerRef),\n targetRef: useMergedRefs(targetRef, targetListenerRef),\n\n elementToRender: React.useMemo(\n () =>\n disabled ? null : (\n <SafeZoneArea\n debug={debug}\n onMouseEnter={onSvgMouseEnter}\n onMouseMove={onSvgMouseMove}\n onMouseLeave={onSvgMouseLeave}\n imperativeRef={safeZoneAreaRef}\n stateStore={stateStore}\n />\n ),\n [disabled, debug, onSvgMouseEnter, onSvgMouseMove, onSvgMouseLeave, stateStore],\n ),\n };\n}\n"],"names":["useSafeZoneArea","debug","disabled","onSafeZoneEnter","onSafeZoneMove","onSafeZoneLeave","onSafeZoneTimeout","timeout","stateStore","React","useState","createSafeZoneAreaStateStore","targetDocument","useFluent_unstable","safeZoneAreaRef","useRef","containerRef","targetRef","timeoutIdRef","mouseMoveIdRef","mouseCoordinatesRef","x","y","containerListenerRef","useMemo","containerEl","onContainerMouseEnter","targetWindow","defaultView","current","clearTimeout","toggleActive","el","removeEventListener","addEventListener","targetListenerRef","targetEl","onTargetMouseMove","e","clientX","clientY","isActive","cancelAnimationFrame","onSvgMouseEnter","useEventCallback","persist","setTimeout","onSvgMouseMove","onSvgMouseLeave","useEffect","subscribe","updateSVGs","updateSVG","containerPlacementSide","parseFloatingUIPlacement","dataset","popperPlacement","side","containerRect","getBoundingClientRect","mouseCoordinates","targetRect","requestAnimationFrame","useMergedRefs","elementToRender","createElement","SafeZoneArea","onMouseEnter","onMouseMove","onMouseLeave","imper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lB;YAACN;YAAUD;YAAO0C;YAAiBI;YAAgBC;YAAiBxC;SAAW;IAEnF;AACF"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@fluentui/react-positioning",
|
3
|
-
"version": "9.18.
|
3
|
+
"version": "9.18.2",
|
4
4
|
"description": "A react wrapper around Popper.js for Fluent UI",
|
5
5
|
"main": "lib-commonjs/index.js",
|
6
6
|
"module": "lib/index.js",
|
@@ -19,9 +19,9 @@
|
|
19
19
|
"dependencies": {
|
20
20
|
"@floating-ui/dom": "^1.6.12",
|
21
21
|
"@floating-ui/devtools": "0.2.1",
|
22
|
-
"@fluentui/react-shared-contexts": "^9.
|
22
|
+
"@fluentui/react-shared-contexts": "^9.24.0",
|
23
23
|
"@fluentui/react-theme": "^9.1.24",
|
24
|
-
"@fluentui/react-utilities": "^9.21.
|
24
|
+
"@fluentui/react-utilities": "^9.21.1",
|
25
25
|
"@griffel/react": "^1.5.22",
|
26
26
|
"@swc/helpers": "^0.5.1",
|
27
27
|
"use-sync-external-store": "^1.2.0"
|