@fluentui/react-positioning 0.0.0-nightlyff78d1e27a20220217.1 → 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. package/CHANGELOG.json +376 -10
  2. package/CHANGELOG.md +200 -75
  3. package/dist/{react-positioning.d.ts → index.d.ts} +78 -46
  4. package/{lib → dist}/tsdoc-metadata.json +0 -0
  5. package/lib/createArrowStyles.js +3 -1
  6. package/lib/createArrowStyles.js.map +1 -1
  7. package/lib/createVirtualElementFromClick.js +2 -0
  8. package/lib/createVirtualElementFromClick.js.map +1 -1
  9. package/lib/index.js +4 -5
  10. package/lib/index.js.map +1 -1
  11. package/lib/isIntersectingModifier.js +26 -0
  12. package/lib/isIntersectingModifier.js.map +1 -0
  13. package/lib/types.js.map +1 -1
  14. package/lib/{usePopper.js → usePositioning.js} +12 -9
  15. package/lib/usePositioning.js.map +1 -0
  16. package/lib/{usePopperMouseTarget.js → usePositioningMouseTarget.js} +4 -3
  17. package/lib/usePositioningMouseTarget.js.map +1 -0
  18. package/lib/utils/fromPopperPlacement.js +40 -0
  19. package/lib/utils/fromPopperPlacement.js.map +1 -0
  20. package/lib/utils/getBoundary.js.map +1 -1
  21. package/lib/utils/getPopperOffset.js +44 -0
  22. package/lib/utils/getPopperOffset.js.map +1 -0
  23. package/lib/utils/getReactFiberFromNode.js.map +1 -1
  24. package/lib/utils/getScrollParent.js.map +1 -1
  25. package/lib/utils/index.js +1 -1
  26. package/lib/utils/index.js.map +1 -1
  27. package/lib/utils/mergeArrowOffset.js +24 -22
  28. package/lib/utils/mergeArrowOffset.js.map +1 -1
  29. package/lib/utils/parsePopperPlacement.js +14 -0
  30. package/lib/utils/parsePopperPlacement.js.map +1 -0
  31. package/lib/utils/positioningHelper.js.map +1 -1
  32. package/lib/utils/resolvePositioningShorthand.js.map +1 -1
  33. package/lib/utils/useCallbackRef.js.map +1 -1
  34. package/lib-commonjs/createArrowStyles.js +3 -1
  35. package/lib-commonjs/createArrowStyles.js.map +1 -1
  36. package/lib-commonjs/createVirtualElementFromClick.js +2 -0
  37. package/lib-commonjs/createVirtualElementFromClick.js.map +1 -1
  38. package/lib-commonjs/index.js +38 -8
  39. package/lib-commonjs/index.js.map +1 -1
  40. package/lib-commonjs/isIntersectingModifier.js +34 -0
  41. package/lib-commonjs/isIntersectingModifier.js.map +1 -0
  42. package/lib-commonjs/{usePopper.js → usePositioning.js} +16 -11
  43. package/lib-commonjs/usePositioning.js.map +1 -0
  44. package/lib-commonjs/{usePopperMouseTarget.js → usePositioningMouseTarget.js} +6 -5
  45. package/lib-commonjs/usePositioningMouseTarget.js.map +1 -0
  46. package/lib-commonjs/utils/fromPopperPlacement.js +50 -0
  47. package/lib-commonjs/utils/fromPopperPlacement.js.map +1 -0
  48. package/lib-commonjs/utils/getBoundary.js.map +1 -1
  49. package/lib-commonjs/utils/getPopperOffset.js +54 -0
  50. package/lib-commonjs/utils/getPopperOffset.js.map +1 -0
  51. package/lib-commonjs/utils/getReactFiberFromNode.js.map +1 -1
  52. package/lib-commonjs/utils/getScrollParent.js.map +1 -1
  53. package/lib-commonjs/utils/index.js +2 -2
  54. package/lib-commonjs/utils/index.js.map +1 -1
  55. package/lib-commonjs/utils/mergeArrowOffset.js +24 -22
  56. package/lib-commonjs/utils/mergeArrowOffset.js.map +1 -1
  57. package/lib-commonjs/utils/parsePopperPlacement.js +23 -0
  58. package/lib-commonjs/utils/parsePopperPlacement.js.map +1 -0
  59. package/lib-commonjs/utils/positioningHelper.js.map +1 -1
  60. package/lib-commonjs/utils/resolvePositioningShorthand.js.map +1 -1
  61. package/lib-commonjs/utils/useCallbackRef.js.map +1 -1
  62. package/package.json +16 -14
  63. package/lib/createArrowStyles.d.ts +0 -64
  64. package/lib/createVirtualElementFromClick.d.ts +0 -6
  65. package/lib/index.d.ts +0 -6
  66. package/lib/types.d.ts +0 -89
  67. package/lib/usePopper.d.ts +0 -23
  68. package/lib/usePopper.js.map +0 -1
  69. package/lib/usePopperMouseTarget.d.ts +0 -11
  70. package/lib/usePopperMouseTarget.js.map +0 -1
  71. package/lib/utils/getBasePlacement.d.ts +0 -8
  72. package/lib/utils/getBasePlacement.js +0 -10
  73. package/lib/utils/getBasePlacement.js.map +0 -1
  74. package/lib/utils/getBoundary.d.ts +0 -6
  75. package/lib/utils/getReactFiberFromNode.d.ts +0 -108
  76. package/lib/utils/getScrollParent.d.ts +0 -12
  77. package/lib/utils/index.d.ts +0 -8
  78. package/lib/utils/mergeArrowOffset.d.ts +0 -10
  79. package/lib/utils/positioningHelper.d.ts +0 -7
  80. package/lib/utils/resolvePositioningShorthand.d.ts +0 -2
  81. package/lib/utils/useCallbackRef.d.ts +0 -19
  82. package/lib-commonjs/createArrowStyles.d.ts +0 -64
  83. package/lib-commonjs/createVirtualElementFromClick.d.ts +0 -6
  84. package/lib-commonjs/index.d.ts +0 -6
  85. package/lib-commonjs/types.d.ts +0 -89
  86. package/lib-commonjs/usePopper.d.ts +0 -23
  87. package/lib-commonjs/usePopper.js.map +0 -1
  88. package/lib-commonjs/usePopperMouseTarget.d.ts +0 -11
  89. package/lib-commonjs/usePopperMouseTarget.js.map +0 -1
  90. package/lib-commonjs/utils/getBasePlacement.d.ts +0 -8
  91. package/lib-commonjs/utils/getBasePlacement.js +0 -19
  92. package/lib-commonjs/utils/getBasePlacement.js.map +0 -1
  93. package/lib-commonjs/utils/getBoundary.d.ts +0 -6
  94. package/lib-commonjs/utils/getReactFiberFromNode.d.ts +0 -108
  95. package/lib-commonjs/utils/getScrollParent.d.ts +0 -12
  96. package/lib-commonjs/utils/index.d.ts +0 -8
  97. package/lib-commonjs/utils/mergeArrowOffset.d.ts +0 -10
  98. package/lib-commonjs/utils/positioningHelper.d.ts +0 -7
  99. package/lib-commonjs/utils/resolvePositioningShorthand.d.ts +0 -2
  100. package/lib-commonjs/utils/useCallbackRef.d.ts +0 -19
@@ -1,14 +1,14 @@
1
1
  import type { GriffelStyle } from '@griffel/react';
2
- import * as PopperJs from '@popperjs/core';
3
2
  import * as React_2 from 'react';
4
3
 
5
4
  export declare type Alignment = 'top' | 'bottom' | 'start' | 'end' | 'center';
6
5
 
7
6
  export declare type AutoSize = 'height' | 'height-always' | 'width' | 'width-always' | 'always' | boolean;
8
7
 
9
- export declare type Boundary = PopperJs.Boundary | 'scrollParent' | 'window';
8
+ export declare type Boundary = HTMLElement | Array<HTMLElement> | 'clippingParents' | 'scrollParent' | 'window';
10
9
 
11
10
  /**
11
+ * @internal
12
12
  * Creates CSS styles to size the arrow created by createArrowStyles to the given height.
13
13
  *
14
14
  * Use this when you need to create classes for several different arrow sizes. If you only need a
@@ -20,6 +20,7 @@ export declare function createArrowHeightStyles(arrowHeight: number): {
20
20
  };
21
21
 
22
22
  /**
23
+ * @internal
23
24
  * Helper that creates a makeStyles rule for an arrow element.
24
25
  * For runtime arrow size toggling simply create extra classnames to apply to the arrow element
25
26
  *
@@ -44,6 +45,7 @@ export declare function createArrowHeightStyles(arrowHeight: number): {
44
45
  export declare function createArrowStyles(options: CreateArrowStylesOptions): GriffelStyle;
45
46
 
46
47
  /**
48
+ * @internal
47
49
  * Options parameter for the createArrowStyles function
48
50
  */
49
51
  export declare type CreateArrowStylesOptions = {
@@ -78,9 +80,10 @@ export declare type CreateArrowStylesOptions = {
78
80
  * Creates a virtual element based on the position of a click event
79
81
  * Can be used as a target for popper in scenarios such as context menus
80
82
  */
81
- export declare function createVirtualElementFromClick(nativeEvent: MouseEvent): PopperVirtualElement;
83
+ export declare function createVirtualElementFromClick(nativeEvent: MouseEvent): PositioningVirtualElement;
82
84
 
83
85
  /**
86
+ * @internal
84
87
  * Generally when adding an arrow to popper, it's necessary to offset the position of the popper by the
85
88
  * height of the arrow. A simple utility to merge a provided offset with an arrow height to return the final offset
86
89
  *
@@ -90,22 +93,45 @@ export declare function createVirtualElementFromClick(nativeEvent: MouseEvent):
90
93
  */
91
94
  export declare function mergeArrowOffset(userOffset: Offset | undefined | null, arrowHeight: number): Offset;
92
95
 
93
- export declare type Offset = OffsetFunction | [number | null | undefined, number | null | undefined];
96
+ export declare type Offset = OffsetFunction | OffsetObject | OffsetShorthand;
94
97
 
95
- export declare type OffsetFunction = (param: OffsetFunctionParam) => [number | null | undefined, number | null | undefined];
98
+ export declare type OffsetFunction = (param: OffsetFunctionParam) => OffsetObject | OffsetShorthand;
96
99
 
97
100
  export declare type OffsetFunctionParam = {
98
- popper: PopperJs.Rect;
99
- reference: PopperJs.Rect;
100
- placement: PopperJs.Placement;
101
+ positionedRect: Rect;
102
+ targetRect: Rect;
103
+ position: Position;
104
+ alignment?: Alignment;
101
105
  };
102
106
 
103
- export declare interface PopperOptions {
107
+ export declare type OffsetObject = {
108
+ crossAxis?: number;
109
+ mainAxis: number;
110
+ };
111
+
112
+ export declare type OffsetShorthand = number;
113
+
114
+ export declare type Position = 'above' | 'below' | 'before' | 'after';
115
+
116
+ export declare type PositioningImperativeRef = {
117
+ /**
118
+ * Updates the position imperatively.
119
+ * Useful when the position of the target changes from other factors than scrolling of window resize.
120
+ */
121
+ updatePosition: () => void;
122
+ /**
123
+ * Sets the target and updates positioning imperatively.
124
+ * Useful for avoiding double renders with the target option.
125
+ */
126
+ setTarget: (target: HTMLElement | PositioningVirtualElement) => void;
127
+ };
128
+
129
+ declare interface PositioningOptions {
104
130
  /** Alignment for the component. Only has an effect if used with the @see position option */
105
131
  align?: Alignment;
106
- /** The element which will define the boundaries of the popper position for the flip behavior. */
132
+ /** The element which will define the boundaries of the positioned element for the flip behavior. */
107
133
  flipBoundary?: Boundary;
108
- /** The element which will define the boundaries of the popper position for the overflow behavior. */
134
+ /** The element which will define the boundaries of the positioned element for the overflow behavior. */
109
135
  overflowBoundary?: Boundary;
110
136
  /**
111
137
  * Position for the component. Position has higher priority than align. If position is vertical ('above' | 'below')
@@ -115,12 +141,12 @@ export declare interface PopperOptions {
115
141
  */
116
142
  position?: Position;
117
143
  /**
118
- * Enables the Popper box to position itself in 'fixed' mode (default value is position: 'absolute')
144
+ * Enables the position element to be positioned with 'fixed' (default value is position: 'absolute')
119
145
  * @default false
120
146
  */
121
147
  positionFixed?: boolean;
122
148
  /**
123
- * Lets you displace a popper element from its reference element.
149
+ * Lets you displace a positioned element from its reference element.
124
150
  * This can be useful if you need to apply some margin between them or if you need to fine tune the
125
151
  * position according to some custom logic.
126
152
  */
@@ -131,7 +157,7 @@ export declare interface PopperOptions {
131
157
  */
132
158
  arrowPadding?: number;
133
159
  /**
134
- * Applies max-height and max-width on popper to fit it within the available space in viewport.
160
+ * Applies max-height and max-width on the positioned element to fit it within the available space in viewport.
135
161
  * true enables this for both width and height when overflow happens.
136
162
  * 'always' applies `max-height`/`max-width` regardless of overflow.
137
163
  * 'height' applies `max-height` when overflow happens, and 'width' for `max-width`
@@ -148,45 +174,58 @@ export declare interface PopperOptions {
148
174
  */
149
175
  pinned?: boolean;
150
176
  /**
151
- * When the reference element or the viewport is outside viewport allows a popper element to be fully in viewport.
177
+ * When the reference element or the viewport is outside viewport allows a positioned element to be fully in viewport.
152
178
  * "all" enables this behavior for all axis.
153
179
  */
154
180
  unstable_disableTether?: boolean | 'all';
155
181
  }
156
182
 
157
- export declare type PopperRefHandle = {
158
- /**
159
- * Updates the position of the popper imperatively.
160
- * Useful when the position of the target changes from other factors than scrolling of window resize.
161
- */
162
- updatePosition: () => void;
163
- /**
164
- * Sets the target and updates positioning imperatively.
165
- * Useful for avoiding double renders with the target option.
166
- */
167
- setTarget: (target: HTMLElement) => void;
168
- };
169
-
170
- export declare type PopperVirtualElement = PopperJs.VirtualElement;
171
-
172
- export declare type Position = 'above' | 'below' | 'before' | 'after';
173
-
174
- export declare interface PositioningProps extends Omit<PopperOptions, 'positionFixed' | 'unstable_disableTether'> {
183
+ export declare interface PositioningProps extends Omit<PositioningOptions, 'positionFixed' | 'unstable_disableTether'> {
175
184
  /** An imperative handle to Popper methods. */
176
- popperRef?: React_2.Ref<PopperRefHandle>;
185
+ positioningRef?: React_2.Ref<PositioningImperativeRef>;
177
186
  /**
178
- * Manual override for popper target. Useful for scenarios where a component accepts user prop to override target
187
+ * Manual override for the target element. Useful for scenarios where a component accepts user prop to override target
179
188
  */
180
- target?: HTMLElement | PopperVirtualElement | null;
189
+ target?: HTMLElement | PositioningVirtualElement | null;
181
190
  }
182
191
 
183
192
  export declare type PositioningShorthand = PositioningProps | PositioningShorthandValue;
184
193
 
185
194
  export declare type PositioningShorthandValue = 'above' | 'above-start' | 'above-end' | 'below' | 'below-start' | 'below-end' | 'before' | 'before-top' | 'before-bottom' | 'after' | 'after-top' | 'after-bottom';
186
195
 
196
+ export declare type PositioningVirtualElement = {
197
+ getBoundingClientRect: () => {
198
+ x: number;
199
+ y: number;
200
+ top: number;
201
+ left: number;
202
+ bottom: number;
203
+ right: number;
204
+ width: number;
205
+ height: number;
206
+ };
207
+ contextElement?: Element;
208
+ };
209
+
210
+ declare type Rect = {
211
+ width: number;
212
+ height: number;
213
+ x: number;
214
+ y: number;
215
+ };
216
+
187
217
  export declare function resolvePositioningShorthand(shorthand: PositioningShorthand | undefined | null): Readonly<PositioningProps>;
188
218
 
219
+ declare interface UsePopperOptions extends PositioningProps {
220
+ /**
221
+ * If false, delays Popper's creation.
222
+ * @default true
223
+ */
224
+ enabled?: boolean;
225
+ }
226
+
189
227
  /**
228
+ * @internal
190
229
  * Exposes Popper positioning API via React hook. Contains few important differences between an official "react-popper"
191
230
  * package:
192
231
  * - style attributes are applied directly on DOM to avoid re-renders
@@ -194,13 +233,14 @@ export declare function resolvePositioningShorthand(shorthand: PositioningShorth
194
233
  * - contains a specific to React fix related to initial positioning when containers have components with managed focus
195
234
  * to avoid focus jumps
196
235
  */
197
- export declare function usePopper(options?: UsePopperOptions): {
236
+ export declare function usePositioning(options?: UsePopperOptions): {
198
237
  targetRef: React_2.MutableRefObject<any>;
199
238
  containerRef: React_2.MutableRefObject<any>;
200
239
  arrowRef: React_2.MutableRefObject<any>;
201
240
  };
202
241
 
203
242
  /**
243
+ * @internal
204
244
  * A state hook that manages a popper virtual element from mouseevents.
205
245
  * Useful for scenarios where a component needs to be positioned by mouse click (e.g. contextmenu)
206
246
  * React synthetic events are not persisted by this hook
@@ -208,14 +248,6 @@ export declare function usePopper(options?: UsePopperOptions): {
208
248
  * @param initialState - initializes a user provided state similare to useState
209
249
  * @returns state and dispatcher for a Popper virtual element that uses native/synthetic mouse events
210
250
  */
211
- export declare const usePopperMouseTarget: (initialState?: PopperJs.VirtualElement | (() => PopperJs.VirtualElement) | undefined) => readonly [PopperJs.VirtualElement | undefined, (event: React_2.MouseEvent | MouseEvent | undefined | null) => void];
212
-
213
- declare interface UsePopperOptions extends PositioningProps {
214
- /**
215
- * If false, delays Popper's creation.
216
- * @default true
217
- */
218
- enabled?: boolean;
219
- }
251
+ export declare const usePositioningMouseTarget: (initialState?: PositioningVirtualElement | (() => PositioningVirtualElement) | undefined) => readonly [PositioningVirtualElement | undefined, (event: React_2.MouseEvent | MouseEvent | undefined | null) => void];
220
252
 
221
253
  export { }
File without changes
@@ -1,6 +1,7 @@
1
1
  import { shorthands } from '@griffel/react';
2
2
  import { tokens } from '@fluentui/react-theme';
3
3
  /**
4
+ * @internal
4
5
  * Helper that creates a makeStyles rule for an arrow element.
5
6
  * For runtime arrow size toggling simply create extra classnames to apply to the arrow element
6
7
  *
@@ -36,7 +37,7 @@ export function createArrowStyles(options) {
36
37
  visibility: 'hidden',
37
38
  zIndex: -1,
38
39
  ...(arrowHeight && createArrowHeightStyles(arrowHeight)),
39
- ':before': {
40
+ '::before': {
40
41
  content: '""',
41
42
  visibility: 'visible',
42
43
  position: 'absolute',
@@ -69,6 +70,7 @@ export function createArrowStyles(options) {
69
70
  };
70
71
  }
71
72
  /**
73
+ * @internal
72
74
  * Creates CSS styles to size the arrow created by createArrowStyles to the given height.
73
75
  *
74
76
  * Use this when you need to create classes for several different arrow sizes. If you only need a
@@ -1 +1 @@
1
- {"version":3,"sources":["createArrowStyles.ts"],"names":[],"mappings":"AAAA,SAAS,UAAT,QAA2B,gBAA3B;AACA,SAAS,MAAT,QAAuB,uBAAvB;AAqCA;;;;;;;;;;;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,iBAAW;AAF+B;AAvCvC,GAAP;AA4CD;AAED;;;;;AAKG;;AACH,OAAM,SAAU,uBAAV,CAAkC,WAAlC,EAAqD;AACzD;AACA;AACA,QAAM,UAAU,GAAG,GAAG,QAAQ,WAAW,IAAzC;AACA,SAAO;AAAE,IAAA,KAAK,EAAE,UAAT;AAAqB,IAAA,MAAM,EAAE;AAA7B,GAAP;AACD","sourcesContent":["import { shorthands } from '@griffel/react';\nimport { tokens } from '@fluentui/react-theme';\nimport type { GriffelStyle } from '@griffel/react';\n\n/**\n * Options parameter for the createArrowStyles function\n */\nexport type CreateArrowStylesOptions = {\n /**\n * The height of the arrow from the base to the tip, in px. The base width of the arrow is always twice its height.\n *\n * This can be undefined to leave out the arrow size styles. You must then add styles created by\n * createArrowHeightStyles to set the arrow's size correctly. This can be useful if the arrow can be different sizes.\n */\n arrowHeight: number | undefined;\n\n /**\n * The borderWidth of the arrow. Should be the same borderWidth as the parent element.\n *\n * @defaultvalue 1px\n */\n borderWidth?: GriffelStyle['borderBottomWidth'];\n\n /**\n * The borderStyle for the arrow. Should be the same borderStyle as the parent element.\n *\n * @defaultvalue solid\n */\n borderStyle?: GriffelStyle['borderBottomStyle'];\n\n /**\n * The borderColor of the arrow. Should be the same borderColor as the parent element.\n *\n * @defaultvalue tokens.colorTransparentStroke\n */\n borderColor?: GriffelStyle['borderBottomColor'];\n};\n\n/**\n * Helper that creates a makeStyles rule for an arrow element.\n * For runtime arrow size toggling simply create extra classnames to apply to the arrow element\n *\n * ```ts\n * makeStyles({\n * arrowWithSize: createArrowStyles({ arrowHeight: 6 }),\n *\n * arrowWithoutSize: createArrowStyles({ arrowHeight: undefined }),\n * mediumArrow: createArrowHeightStyles(4),\n * smallArrow: createArrowHeightStyles(2),\n * })\n * ...\n *\n * state.arrowWithSize.className = styles.arrowWithSize;\n * state.arrowWithoutSize.className = mergeClasses(\n * styles.arrowWithoutSize,\n * state.smallArrow && styles.smallArrow,\n * state.mediumArrow && styles.mediumArrow,\n * )\n * ```\n */\nexport function createArrowStyles(options: CreateArrowStylesOptions): GriffelStyle {\n const {\n arrowHeight,\n borderWidth = '1px',\n borderStyle = 'solid',\n borderColor = tokens.colorTransparentStroke,\n } = options;\n\n return {\n position: 'absolute',\n backgroundColor: 'inherit',\n visibility: 'hidden',\n zIndex: -1,\n\n ...(arrowHeight && createArrowHeightStyles(arrowHeight)),\n\n ':before': {\n content: '\"\"',\n visibility: 'visible',\n position: 'absolute',\n boxSizing: 'border-box',\n width: 'inherit',\n height: 'inherit',\n backgroundColor: 'inherit',\n ...shorthands.borderRight(\n `${borderWidth} /* @noflip */`,\n `${borderStyle} /* @noflip */`,\n `${borderColor} /* @noflip */`,\n ),\n ...shorthands.borderBottom(borderWidth, borderStyle, borderColor),\n borderBottomRightRadius: tokens.borderRadiusSmall,\n transform: 'rotate(var(--angle)) translate(0, 50%) rotate(45deg)',\n },\n\n // Popper sets data-popper-placement on the root element, which is used to align the arrow\n ':global([data-popper-placement^=\"top\"])': {\n bottom: `-${borderWidth}`,\n '--angle': '0',\n },\n ':global([data-popper-placement^=\"right\"])': {\n left: `-${borderWidth} /* @noflip */`,\n '--angle': '90deg',\n },\n ':global([data-popper-placement^=\"bottom\"])': {\n top: `-${borderWidth}`,\n '--angle': '180deg',\n },\n ':global([data-popper-placement^=\"left\"])': {\n right: `-${borderWidth} /* @noflip */`,\n '--angle': '270deg',\n },\n };\n}\n\n/**\n * Creates CSS styles to size the arrow created by createArrowStyles to the given height.\n *\n * Use this when you need to create classes for several different arrow sizes. If you only need a\n * constant arrow size, you can pass the `arrowHeight` param to createArrowStyles instead.\n */\nexport function createArrowHeightStyles(arrowHeight: number) {\n // The arrow is a square rotated 45 degrees to have its bottom and right edges form a right triangle.\n // Multiply the triangle's height by sqrt(2) to get length of its edges.\n const edgeLength = `${1.414 * arrowHeight}px`;\n return { width: edgeLength, height: edgeLength };\n}\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["createArrowStyles.ts"],"names":[],"mappings":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;;;;;AAMG;;AACH,OAAM,SAAU,uBAAV,CAAkC,WAAlC,EAAqD;EACzD;EACA;EACA,MAAM,UAAU,GAAG,GAAG,QAAQ,WAAW,IAAzC;EACA,OAAO;IAAE,KAAK,EAAE,UAAT;IAAqB,MAAM,EAAE;EAA7B,CAAP;AACD","sourcesContent":["import { shorthands } from '@griffel/react';\nimport { tokens } from '@fluentui/react-theme';\nimport type { GriffelStyle } from '@griffel/react';\n\n/**\n * @internal\n * Options parameter for the createArrowStyles function\n */\nexport type CreateArrowStylesOptions = {\n /**\n * The height of the arrow from the base to the tip, in px. The base width of the arrow is always twice its height.\n *\n * This can be undefined to leave out the arrow size styles. You must then add styles created by\n * createArrowHeightStyles to set the arrow's size correctly. This can be useful if the arrow can be different sizes.\n */\n arrowHeight: number | undefined;\n\n /**\n * The borderWidth of the arrow. Should be the same borderWidth as the parent element.\n *\n * @defaultvalue 1px\n */\n borderWidth?: GriffelStyle['borderBottomWidth'];\n\n /**\n * The borderStyle for the arrow. Should be the same borderStyle as the parent element.\n *\n * @defaultvalue solid\n */\n borderStyle?: GriffelStyle['borderBottomStyle'];\n\n /**\n * The borderColor of the arrow. Should be the same borderColor as the parent element.\n *\n * @defaultvalue tokens.colorTransparentStroke\n */\n borderColor?: GriffelStyle['borderBottomColor'];\n};\n\n/**\n * @internal\n * Helper that creates a makeStyles rule for an arrow element.\n * For runtime arrow size toggling simply create extra classnames to apply to the arrow element\n *\n * ```ts\n * makeStyles({\n * arrowWithSize: createArrowStyles({ arrowHeight: 6 }),\n *\n * arrowWithoutSize: createArrowStyles({ arrowHeight: undefined }),\n * mediumArrow: createArrowHeightStyles(4),\n * smallArrow: createArrowHeightStyles(2),\n * })\n * ...\n *\n * state.arrowWithSize.className = styles.arrowWithSize;\n * state.arrowWithoutSize.className = mergeClasses(\n * styles.arrowWithoutSize,\n * state.smallArrow && styles.smallArrow,\n * state.mediumArrow && styles.mediumArrow,\n * )\n * ```\n */\nexport function createArrowStyles(options: CreateArrowStylesOptions): GriffelStyle {\n const {\n arrowHeight,\n borderWidth = '1px',\n borderStyle = 'solid',\n borderColor = tokens.colorTransparentStroke,\n } = options;\n\n return {\n position: 'absolute',\n backgroundColor: 'inherit',\n visibility: 'hidden',\n zIndex: -1,\n\n ...(arrowHeight && createArrowHeightStyles(arrowHeight)),\n\n '::before': {\n content: '\"\"',\n visibility: 'visible',\n position: 'absolute',\n boxSizing: 'border-box',\n width: 'inherit',\n height: 'inherit',\n backgroundColor: 'inherit',\n ...shorthands.borderRight(\n `${borderWidth} /* @noflip */`,\n `${borderStyle} /* @noflip */`,\n `${borderColor} /* @noflip */`,\n ),\n ...shorthands.borderBottom(borderWidth, borderStyle, borderColor),\n borderBottomRightRadius: tokens.borderRadiusSmall,\n transform: 'rotate(var(--angle)) translate(0, 50%) rotate(45deg)',\n },\n\n // Popper sets data-popper-placement on the root element, which is used to align the arrow\n ':global([data-popper-placement^=\"top\"])': {\n bottom: `-${borderWidth}`,\n '--angle': '0',\n },\n ':global([data-popper-placement^=\"right\"])': {\n left: `-${borderWidth} /* @noflip */`,\n '--angle': '90deg',\n },\n ':global([data-popper-placement^=\"bottom\"])': {\n top: `-${borderWidth}`,\n '--angle': '180deg',\n },\n ':global([data-popper-placement^=\"left\"])': {\n right: `-${borderWidth} /* @noflip */`,\n '--angle': '270deg',\n },\n };\n}\n\n/**\n * @internal\n * Creates CSS styles to size the arrow created by createArrowStyles to the given height.\n *\n * Use this when you need to create classes for several different arrow sizes. If you only need a\n * constant arrow size, you can pass the `arrowHeight` param to createArrowStyles instead.\n */\nexport function createArrowHeightStyles(arrowHeight: number) {\n // The arrow is a square rotated 45 degrees to have its bottom and right edges form a right triangle.\n // Multiply the triangle's height by sqrt(2) to get length of its edges.\n const edgeLength = `${1.414 * arrowHeight}px`;\n return { width: edgeLength, height: edgeLength };\n}\n"],"sourceRoot":"../src/"}
@@ -14,6 +14,8 @@ export function createVirtualElementFromClick(nativeEvent) {
14
14
  top,
15
15
  right,
16
16
  bottom,
17
+ x: left,
18
+ y: top,
17
19
  height: 1,
18
20
  width: 1
19
21
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["createVirtualElementFromClick.ts"],"names":[],"mappings":"AAEA;;;AAGG;AACH,OAAM,SAAU,6BAAV,CAAwC,WAAxC,EAA+D;AACnE,QAAM,IAAI,GAAG,WAAW,CAAC,OAAzB;AACA,QAAM,GAAG,GAAG,WAAW,CAAC,OAAxB;AACA,QAAM,KAAK,GAAG,IAAI,GAAG,CAArB;AACA,QAAM,MAAM,GAAG,GAAG,GAAG,CAArB;;AAEA,WAAS,qBAAT,GAA8B;AAC5B,WAAO;AACL,MAAA,IADK;AAEL,MAAA,GAFK;AAGL,MAAA,KAHK;AAIL,MAAA,MAJK;AAML,MAAA,MAAM,EAAE,CANH;AAOL,MAAA,KAAK,EAAE;AAPF,KAAP;AASD;;AAED,SAAO;AACL,IAAA;AADK,GAAP;AAGD","sourcesContent":["import type { PopperVirtualElement } from './types';\n\n/**\n * Creates a virtual element based on the position of a click event\n * Can be used as a target for popper in scenarios such as context menus\n */\nexport function createVirtualElementFromClick(nativeEvent: MouseEvent): PopperVirtualElement {\n const left = nativeEvent.clientX;\n const top = nativeEvent.clientY;\n const right = left + 1;\n const bottom = top + 1;\n\n function getBoundingClientRect(): ClientRect {\n return {\n left,\n top,\n right,\n bottom,\n\n height: 1,\n width: 1,\n };\n }\n\n return {\n getBoundingClientRect,\n };\n}\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["createVirtualElementFromClick.ts"],"names":[],"mappings":"AAEA;;;AAGG;AACH,OAAM,SAAU,6BAAV,CAAwC,WAAxC,EAA+D;EACnE,MAAM,IAAI,GAAG,WAAW,CAAC,OAAzB;EACA,MAAM,GAAG,GAAG,WAAW,CAAC,OAAxB;EACA,MAAM,KAAK,GAAG,IAAI,GAAG,CAArB;EACA,MAAM,MAAM,GAAG,GAAG,GAAG,CAArB;;EAEA,SAAS,qBAAT,GAA8B;IAC5B,OAAO;MACL,IADK;MAEL,GAFK;MAGL,KAHK;MAIL,MAJK;MAKL,CAAC,EAAE,IALE;MAML,CAAC,EAAE,GANE;MAOL,MAAM,EAAE,CAPH;MAQL,KAAK,EAAE;IARF,CAAP;EAUD;;EAED,OAAO;IACL;EADK,CAAP;AAGD","sourcesContent":["import type { PositioningVirtualElement } from './types';\n\n/**\n * Creates a virtual element based on the position of a click event\n * Can be used as a target for popper in scenarios such as context menus\n */\nexport function createVirtualElementFromClick(nativeEvent: MouseEvent): PositioningVirtualElement {\n const left = nativeEvent.clientX;\n const top = nativeEvent.clientY;\n const right = left + 1;\n const bottom = top + 1;\n\n function getBoundingClientRect() {\n return {\n left,\n top,\n right,\n bottom,\n x: left,\n y: top,\n height: 1,\n width: 1,\n };\n }\n\n return {\n getBoundingClientRect,\n };\n}\n"],"sourceRoot":"../src/"}
package/lib/index.js CHANGED
@@ -1,7 +1,6 @@
1
- export * from './createVirtualElementFromClick';
2
- export * from './createArrowStyles';
3
- export * from './usePopper';
4
- export * from './usePopperMouseTarget';
1
+ export { createVirtualElementFromClick } from './createVirtualElementFromClick';
2
+ export { createArrowHeightStyles, createArrowStyles } from './createArrowStyles';
3
+ export { usePositioning } from './usePositioning';
4
+ export { usePositioningMouseTarget } from './usePositioningMouseTarget';
5
5
  export { resolvePositioningShorthand, mergeArrowOffset } from './utils/index';
6
- export * from './types';
7
6
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"../src/","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,iCAAiC,CAAC;AAChD,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAC5B,cAAc,wBAAwB,CAAC;AACvC,OAAO,EAAE,2BAA2B,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAC9E,cAAc,SAAS,CAAC","sourcesContent":["export * from './createVirtualElementFromClick';\nexport * from './createArrowStyles';\nexport * from './usePopper';\nexport * from './usePopperMouseTarget';\nexport { resolvePositioningShorthand, mergeArrowOffset } from './utils/index';\nexport * from './types';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"../src/","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAChF,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAEjF,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAC;AACxE,OAAO,EAAE,2BAA2B,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC","sourcesContent":["export { createVirtualElementFromClick } from './createVirtualElementFromClick';\nexport { createArrowHeightStyles, createArrowStyles } from './createArrowStyles';\nexport type { CreateArrowStylesOptions } from './createArrowStyles';\nexport { usePositioning } from './usePositioning';\nexport { usePositioningMouseTarget } from './usePositioningMouseTarget';\nexport { resolvePositioningShorthand, mergeArrowOffset } from './utils/index';\nexport type {\n Alignment,\n AutoSize,\n Boundary,\n Offset,\n OffsetFunction,\n OffsetFunctionParam,\n OffsetObject,\n OffsetShorthand,\n Position,\n PositioningImperativeRef,\n PositioningProps,\n PositioningShorthand,\n PositioningShorthandValue,\n PositioningVirtualElement,\n} from './types';\n"]}
@@ -0,0 +1,26 @@
1
+ import { detectOverflow } from '@popperjs/core';
2
+ export const isIntersectingModifier = {
3
+ name: 'is-intersecting-modifier',
4
+ enabled: true,
5
+ phase: 'main',
6
+ requires: ['preventOverflow'],
7
+ fn: ({
8
+ state,
9
+ name
10
+ }) => {
11
+ const popperRect = state.rects.popper;
12
+ const popperAltOverflow = detectOverflow(state, {
13
+ altBoundary: true
14
+ });
15
+ const isIntersectingTop = popperAltOverflow.top < popperRect.height && popperAltOverflow.top > 0;
16
+ const isIntersectingBottom = popperAltOverflow.bottom < popperRect.height && popperAltOverflow.bottom > 0;
17
+ const isIntersecting = isIntersectingTop || isIntersectingBottom;
18
+ state.modifiersData[name] = {
19
+ isIntersecting
20
+ };
21
+ state.attributes.popper = { ...state.attributes.popper,
22
+ 'data-popper-is-intersecting': isIntersecting
23
+ };
24
+ }
25
+ };
26
+ //# sourceMappingURL=isIntersectingModifier.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["isIntersectingModifier.ts"],"names":[],"mappings":"AAAA,SAAS,cAAT,QAAyC,gBAAzC;AAEA,OAAO,MAAM,sBAAsB,GAA2B;EAC5D,IAAI,EAAE,0BADsD;EAE5D,OAAO,EAAE,IAFmD;EAG5D,KAAK,EAAE,MAHqD;EAI5D,QAAQ,EAAE,CAAC,iBAAD,CAJkD;EAK5D,EAAE,EAAE,CAAC;IAAE,KAAF;IAAS;EAAT,CAAD,KAAoB;IACtB,MAAM,UAAU,GAAG,KAAK,CAAC,KAAN,CAAY,MAA/B;IACA,MAAM,iBAAiB,GAAG,cAAc,CAAC,KAAD,EAAQ;MAAE,WAAW,EAAE;IAAf,CAAR,CAAxC;IAEA,MAAM,iBAAiB,GAAG,iBAAiB,CAAC,GAAlB,GAAwB,UAAU,CAAC,MAAnC,IAA6C,iBAAiB,CAAC,GAAlB,GAAwB,CAA/F;IACA,MAAM,oBAAoB,GAAG,iBAAiB,CAAC,MAAlB,GAA2B,UAAU,CAAC,MAAtC,IAAgD,iBAAiB,CAAC,MAAlB,GAA2B,CAAxG;IAEA,MAAM,cAAc,GAAG,iBAAiB,IAAI,oBAA5C;IAEA,KAAK,CAAC,aAAN,CAAoB,IAApB,IAA4B;MAC1B;IAD0B,CAA5B;IAGA,KAAK,CAAC,UAAN,CAAiB,MAAjB,GAA0B,EACxB,GAAG,KAAK,CAAC,UAAN,CAAiB,MADI;MAExB,+BAA+B;IAFP,CAA1B;EAID;AArB2D,CAAvD","sourcesContent":["import { detectOverflow, Modifier } from '@popperjs/core';\n\nexport const isIntersectingModifier: IsIntersectingModifier = {\n name: 'is-intersecting-modifier',\n enabled: true,\n phase: 'main',\n requires: ['preventOverflow'],\n fn: ({ state, name }) => {\n const popperRect = state.rects.popper;\n const popperAltOverflow = detectOverflow(state, { altBoundary: true });\n\n const isIntersectingTop = popperAltOverflow.top < popperRect.height && popperAltOverflow.top > 0;\n const isIntersectingBottom = popperAltOverflow.bottom < popperRect.height && popperAltOverflow.bottom > 0;\n\n const isIntersecting = isIntersectingTop || isIntersectingBottom;\n\n state.modifiersData[name] = {\n isIntersecting,\n };\n state.attributes.popper = {\n ...state.attributes.popper,\n 'data-popper-is-intersecting': isIntersecting,\n };\n },\n};\n\ntype IsIntersectingModifier = Modifier<'is-intersecting-modifier', never>;\n"],"sourceRoot":"../src/"}
package/lib/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"../src/","sources":["types.ts"],"names":[],"mappings":"","sourcesContent":["import * as PopperJs from '@popperjs/core';\nimport * as React from 'react';\n\nexport type OffsetFunctionParam = {\n popper: PopperJs.Rect;\n reference: PopperJs.Rect;\n placement: PopperJs.Placement;\n};\n\nexport type OffsetFunction = (param: OffsetFunctionParam) => [number | null | undefined, number | null | undefined];\n\nexport type Offset = OffsetFunction | [number | null | undefined, number | null | undefined];\n\nexport type Position = 'above' | 'below' | 'before' | 'after';\nexport type Alignment = 'top' | 'bottom' | 'start' | 'end' | 'center';\n\nexport type AutoSize = 'height' | 'height-always' | 'width' | 'width-always' | 'always' | boolean;\n\nexport type Boundary = PopperJs.Boundary | 'scrollParent' | 'window';\n\nexport type PopperRefHandle = {\n /**\n * Updates the position of the popper imperatively.\n * Useful when the position of the target changes from other factors than scrolling of window resize.\n */\n updatePosition: () => void;\n\n /**\n * Sets the target and updates positioning imperatively.\n * Useful for avoiding double renders with the target option.\n */\n setTarget: (target: HTMLElement) => void;\n};\n\nexport type PopperVirtualElement = PopperJs.VirtualElement;\n\nexport interface PopperOptions {\n /** Alignment for the component. Only has an effect if used with the @see position option */\n align?: Alignment;\n\n /** The element which will define the boundaries of the popper position for the flip behavior. */\n flipBoundary?: Boundary;\n\n /** The element which will define the boundaries of the popper position for the overflow behavior. */\n overflowBoundary?: Boundary;\n\n /**\n * Position for the component. Position has higher priority than align. If position is vertical ('above' | 'below')\n * and align is also vertical ('top' | 'bottom') or if both position and align are horizontal ('before' | 'after'\n * and 'start' | 'end' respectively),\n * then provided value for 'align' will be ignored and 'center' will be used instead.\n */\n position?: Position;\n\n /**\n * Enables the Popper box to position itself in 'fixed' mode (default value is position: 'absolute')\n * @default false\n */\n positionFixed?: boolean;\n\n /**\n * Lets you displace a popper element from its reference element.\n * This can be useful if you need to apply some margin between them or if you need to fine tune the\n * position according to some custom logic.\n */\n offset?: Offset;\n\n /**\n * Defines padding between the corner of the popup element and the arrow.\n * Use to prevent the arrow from overlapping a rounded corner, for example.\n */\n arrowPadding?: number;\n\n /**\n * Applies max-height and max-width on popper to fit it within the available space in viewport.\n * true enables this for both width and height when overflow happens.\n * 'always' applies `max-height`/`max-width` regardless of overflow.\n * 'height' applies `max-height` when overflow happens, and 'width' for `max-width`\n * `height-always` applies `max-height` regardless of overflow, and 'width-always' for always applying `max-width`\n */\n autoSize?: AutoSize;\n\n /**\n * Modifies position and alignment to cover the target\n */\n coverTarget?: boolean;\n\n /**\n * Disables automatic repositioning of the component; it will always be placed according to the values of `align` and\n * `position` props, regardless of the size of the component, the reference element or the viewport.\n */\n pinned?: boolean;\n\n /**\n * When the reference element or the viewport is outside viewport allows a popper element to be fully in viewport.\n * \"all\" enables this behavior for all axis.\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n unstable_disableTether?: boolean | 'all';\n}\n\nexport interface PositioningProps\n // \"positionFixed\" & \"unstable_disableTether\" are not exported as public API (yet)\n extends Omit<PopperOptions, 'positionFixed' | 'unstable_disableTether'> {\n /** An imperative handle to Popper methods. */\n popperRef?: React.Ref<PopperRefHandle>;\n\n /**\n * Manual override for popper target. Useful for scenarios where a component accepts user prop to override target\n */\n target?: HTMLElement | PopperVirtualElement | null;\n}\n\nexport type PositioningShorthandValue =\n | 'above'\n | 'above-start'\n | 'above-end'\n | 'below'\n | 'below-start'\n | 'below-end'\n | 'before'\n | 'before-top'\n | 'before-bottom'\n | 'after'\n | 'after-top'\n | 'after-bottom';\n\nexport type PositioningShorthand = PositioningProps | PositioningShorthandValue;\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"../src/","sources":["types.ts"],"names":[],"mappings":"","sourcesContent":["import * as React from 'react';\n\ntype Rect = {\n width: number;\n height: number;\n x: number;\n y: number;\n};\n\nexport type OffsetFunctionParam = {\n positionedRect: Rect;\n targetRect: Rect;\n position: Position;\n alignment?: Alignment;\n};\n\nexport type OffsetObject = { crossAxis?: number; mainAxis: number };\n\nexport type OffsetShorthand = number;\n\nexport type OffsetFunction = (param: OffsetFunctionParam) => OffsetObject | OffsetShorthand;\n\nexport type Offset = OffsetFunction | OffsetObject | OffsetShorthand;\n\nexport type Position = 'above' | 'below' | 'before' | 'after';\nexport type Alignment = 'top' | 'bottom' | 'start' | 'end' | 'center';\n\nexport type AutoSize = 'height' | 'height-always' | 'width' | 'width-always' | 'always' | boolean;\n\nexport type Boundary = HTMLElement | Array<HTMLElement> | 'clippingParents' | 'scrollParent' | 'window';\n\nexport type PositioningImperativeRef = {\n /**\n * Updates the position imperatively.\n * Useful when the position of the target changes from other factors than scrolling of window resize.\n */\n updatePosition: () => void;\n\n /**\n * Sets the target and updates positioning imperatively.\n * Useful for avoiding double renders with the target option.\n */\n setTarget: (target: HTMLElement | PositioningVirtualElement) => void;\n};\n\nexport type PositioningVirtualElement = {\n getBoundingClientRect: () => {\n x: number;\n y: number;\n top: number;\n left: number;\n bottom: number;\n right: number;\n width: number;\n height: number;\n };\n contextElement?: Element;\n};\n\nexport interface PositioningOptions {\n /** Alignment for the component. Only has an effect if used with the @see position option */\n align?: Alignment;\n\n /** The element which will define the boundaries of the positioned element for the flip behavior. */\n flipBoundary?: Boundary;\n\n /** The element which will define the boundaries of the positioned element for the overflow behavior. */\n overflowBoundary?: Boundary;\n\n /**\n * Position for the component. Position has higher priority than align. If position is vertical ('above' | 'below')\n * and align is also vertical ('top' | 'bottom') or if both position and align are horizontal ('before' | 'after'\n * and 'start' | 'end' respectively),\n * then provided value for 'align' will be ignored and 'center' will be used instead.\n */\n position?: Position;\n\n /**\n * Enables the position element to be positioned with 'fixed' (default value is position: 'absolute')\n * @default false\n */\n positionFixed?: boolean;\n\n /**\n * Lets you displace a positioned element from its reference element.\n * This can be useful if you need to apply some margin between them or if you need to fine tune the\n * position according to some custom logic.\n */\n offset?: Offset;\n\n /**\n * Defines padding between the corner of the popup element and the arrow.\n * Use to prevent the arrow from overlapping a rounded corner, for example.\n */\n arrowPadding?: number;\n\n /**\n * Applies max-height and max-width on the positioned element to fit it within the available space in viewport.\n * true enables this for both width and height when overflow happens.\n * 'always' applies `max-height`/`max-width` regardless of overflow.\n * 'height' applies `max-height` when overflow happens, and 'width' for `max-width`\n * `height-always` applies `max-height` regardless of overflow, and 'width-always' for always applying `max-width`\n */\n autoSize?: AutoSize;\n\n /**\n * Modifies position and alignment to cover the target\n */\n coverTarget?: boolean;\n\n /**\n * Disables automatic repositioning of the component; it will always be placed according to the values of `align` and\n * `position` props, regardless of the size of the component, the reference element or the viewport.\n */\n pinned?: boolean;\n\n /**\n * When the reference element or the viewport is outside viewport allows a positioned element to be fully in viewport.\n * \"all\" enables this behavior for all axis.\n */\n // eslint-disable-next-line @typescript-eslint/naming-convention\n unstable_disableTether?: boolean | 'all';\n}\n\nexport interface PositioningProps\n // \"positionFixed\" & \"unstable_disableTether\" are not exported as public API (yet)\n extends Omit<PositioningOptions, 'positionFixed' | 'unstable_disableTether'> {\n /** An imperative handle to Popper methods. */\n positioningRef?: React.Ref<PositioningImperativeRef>;\n\n /**\n * Manual override for the target element. Useful for scenarios where a component accepts user prop to override target\n */\n target?: HTMLElement | PositioningVirtualElement | null;\n}\n\nexport type PositioningShorthandValue =\n | 'above'\n | 'above-start'\n | 'above-end'\n | 'below'\n | 'below-start'\n | 'below-end'\n | 'before'\n | 'before-top'\n | 'before-bottom'\n | 'after'\n | 'after-top'\n | 'after-bottom';\n\nexport type PositioningShorthand = PositioningProps | PositioningShorthandValue;\n"]}
@@ -1,8 +1,10 @@
1
1
  import { useEventCallback, useIsomorphicLayoutEffect, useFirstMount, canUseDOM } from '@fluentui/react-utilities';
2
- import { useFluent } from '@fluentui/react-shared-contexts';
2
+ import { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';
3
3
  import * as PopperJs from '@popperjs/core';
4
4
  import * as React from 'react';
5
- import { getScrollParent, applyRtlToOffset, getPlacement, getReactFiberFromNode, getBoundary, useCallbackRef, getBasePlacement } from './utils/index'; //
5
+ import { isIntersectingModifier } from './isIntersectingModifier';
6
+ import { getScrollParent, applyRtlToOffset, getPlacement, getReactFiberFromNode, getBoundary, useCallbackRef, parsePopperPlacement } from './utils/index';
7
+ import { getPopperOffset } from './utils/getPopperOffset'; //
6
8
  // Dev utils to detect if nodes have "autoFocus" props.
7
9
  //
8
10
 
@@ -57,7 +59,7 @@ function usePopperOptions(options, popperOriginalPositionRef) {
57
59
  const offsetModifier = React.useMemo(() => offset ? {
58
60
  name: 'offset',
59
61
  options: {
60
- offset: isRtl ? applyRtlToOffset(offset) : offset
62
+ offset: isRtl ? applyRtlToOffset(getPopperOffset(offset)) : getPopperOffset(offset)
61
63
  }
62
64
  } : null, [offset, isRtl]);
63
65
  return React.useCallback((target, container, arrow) => {
@@ -65,7 +67,7 @@ function usePopperOptions(options, popperOriginalPositionRef) {
65
67
 
66
68
  const scrollParentElement = getScrollParent(container);
67
69
  const hasScrollableElement = scrollParentElement ? scrollParentElement !== ((_a = scrollParentElement.ownerDocument) === null || _a === void 0 ? void 0 : _a.body) : false;
68
- const modifiers = [
70
+ const modifiers = [isIntersectingModifier,
69
71
  /**
70
72
  * We are setting the position to `fixed` in the first effect to prevent scroll jumps in case of the content
71
73
  * with managed focus. Modifier sets the position to `fixed` before all other modifier effects. Another part of
@@ -174,7 +176,7 @@ function usePopperOptions(options, popperOriginalPositionRef) {
174
176
  width,
175
177
  height
176
178
  } = state.rects.popper;
177
- const basePlacement = getBasePlacement(state.placement);
179
+ const basePlacement = parsePopperPlacement(state.placement).basePlacement;
178
180
  const widthProp = basePlacement === 'left' ? 'left' : 'right';
179
181
  const heightProp = basePlacement === 'top' ? 'top' : 'bottom';
180
182
  const applyMaxWidth = autoSize === 'always' || autoSize === 'width-always' || overflow[widthProp] > 0 && (autoSize === true || autoSize === 'width');
@@ -214,7 +216,7 @@ function usePopperOptions(options, popperOriginalPositionRef) {
214
216
  fn({
215
217
  state
216
218
  }) {
217
- const basePlacement = getBasePlacement(state.placement);
219
+ const basePlacement = parsePopperPlacement(state.placement).basePlacement;
218
220
 
219
221
  switch (basePlacement) {
220
222
  case 'bottom':
@@ -247,6 +249,7 @@ function usePopperOptions(options, popperOriginalPositionRef) {
247
249
  popperOriginalPositionRef]);
248
250
  }
249
251
  /**
252
+ * @internal
250
253
  * Exposes Popper positioning API via React hook. Contains few important differences between an official "react-popper"
251
254
  * package:
252
255
  * - style attributes are applied directly on DOM to avoid re-renders
@@ -256,7 +259,7 @@ function usePopperOptions(options, popperOriginalPositionRef) {
256
259
  */
257
260
 
258
261
 
259
- export function usePopper(options = {}) {
262
+ export function usePositioning(options = {}) {
260
263
  const {
261
264
  enabled = true
262
265
  } = options;
@@ -323,7 +326,7 @@ export function usePopper(options = {}) {
323
326
  const arrowRef = useCallbackRef(null, handlePopperUpdate, true); // Stores external target from options.target or setTarget
324
327
 
325
328
  const overrideTargetRef = useCallbackRef(null, handlePopperUpdate, true);
326
- React.useImperativeHandle(options.popperRef, () => ({
329
+ React.useImperativeHandle(options.positioningRef, () => ({
327
330
  updatePosition: () => {
328
331
  var _a;
329
332
 
@@ -403,4 +406,4 @@ export function usePopper(options = {}) {
403
406
  arrowRef
404
407
  };
405
408
  }
406
- //# sourceMappingURL=usePopper.js.map
409
+ //# sourceMappingURL=usePositioning.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["usePositioning.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Effect, useFirstMount, canUseDOM } from '@fluentui/react-utilities';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport * as PopperJs from '@popperjs/core';\nimport * as React from 'react';\n\nimport { isIntersectingModifier } from './isIntersectingModifier';\nimport {\n getScrollParent,\n applyRtlToOffset,\n getPlacement,\n getReactFiberFromNode,\n getBoundary,\n useCallbackRef,\n parsePopperPlacement,\n} from './utils/index';\nimport type { PositioningVirtualElement, PositioningOptions, PositioningProps } from './types';\nimport { getPopperOffset } from './utils/getPopperOffset';\n\ntype PopperInstance = PopperJs.Instance & { isFirstRun?: boolean };\n\ninterface UsePopperOptions extends PositioningProps {\n /**\n * If false, delays Popper's creation.\n * @default true\n */\n enabled?: boolean;\n}\n\n//\n// Dev utils to detect if nodes have \"autoFocus\" props.\n//\n\n/**\n * Detects if a passed HTML node has \"autoFocus\" prop on a React's fiber. Is needed as React handles autofocus behavior\n * in React DOM and will not pass \"autoFocus\" to an actual HTML.\n */\nfunction hasAutofocusProp(node: Node): boolean {\n // https://github.com/facebook/react/blob/848bb2426e44606e0a55dfe44c7b3ece33772485/packages/react-dom/src/client/ReactDOMHostConfig.js#L157-L166\n const isAutoFocusableElement =\n node.nodeName === 'BUTTON' ||\n node.nodeName === 'INPUT' ||\n node.nodeName === 'SELECT' ||\n node.nodeName === 'TEXTAREA';\n\n if (isAutoFocusableElement) {\n return !!getReactFiberFromNode(node)?.pendingProps.autoFocus;\n }\n\n return false;\n}\n\nfunction hasAutofocusFilter(node: Node) {\n return hasAutofocusProp(node) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;\n}\n\n/**\n * Provides a callback to resolve Popper options, it's stable and should be used as a dependency to trigger updates\n * of Popper options.\n *\n * A callback is used there intentionally as some of Popper.js modifiers require DOM nodes (targer, container, arrow)\n * that can't be resolved properly during an initial rendering.\n */\nfunction usePopperOptions(options: PositioningOptions, popperOriginalPositionRef: React.MutableRefObject<string>) {\n const {\n align,\n arrowPadding,\n autoSize,\n coverTarget,\n flipBoundary,\n offset,\n overflowBoundary,\n pinned,\n position,\n positionFixed,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n unstable_disableTether,\n } = options;\n\n const isRtl = useFluent().dir === 'rtl';\n const placement = getPlacement(align, position, isRtl);\n const strategy = positionFixed ? 'fixed' : 'absolute';\n\n const offsetModifier = React.useMemo(\n () =>\n offset\n ? {\n name: 'offset',\n options: { offset: isRtl ? applyRtlToOffset(getPopperOffset(offset)) : getPopperOffset(offset) },\n }\n : null,\n [offset, isRtl],\n );\n\n return React.useCallback(\n (\n target: HTMLElement | PopperJs.VirtualElement | null,\n container: HTMLElement | null,\n arrow: HTMLElement | null,\n ): PopperJs.Options => {\n const scrollParentElement: HTMLElement = getScrollParent(container);\n const hasScrollableElement = scrollParentElement\n ? scrollParentElement !== scrollParentElement.ownerDocument?.body\n : false;\n\n const modifiers: PopperJs.Options['modifiers'] = [\n isIntersectingModifier,\n\n /**\n * We are setting the position to `fixed` in the first effect to prevent scroll jumps in case of the content\n * with managed focus. Modifier sets the position to `fixed` before all other modifier effects. Another part of\n * a patch modifies \".forceUpdate()\" directly after a Popper will be created.\n */\n {\n name: 'positionStyleFix',\n enabled: true,\n phase: 'afterWrite' as PopperJs.ModifierPhases,\n effect: ({ state, instance }: { state: PopperJs.State; instance: PopperInstance }) => {\n // \".isFirstRun\" is a part of our patch, on a first evaluation it will \"undefined\"\n // should be disabled for subsequent runs as it breaks positioning for them\n if (instance.isFirstRun !== false) {\n popperOriginalPositionRef.current = state.elements.popper.style.position;\n state.elements.popper.style.position = 'fixed';\n }\n\n return () => undefined;\n },\n requires: [],\n },\n\n { name: 'flip', options: { flipVariations: true } },\n\n /**\n * pinned disables the flip modifier by setting flip.enabled to false; this\n * disables automatic repositioning of the popper box; it will always be placed according to\n * the values of `align` and `position` props, regardless of the size of the component, the\n * reference element or the viewport.\n */\n pinned && { name: 'flip', enabled: false },\n\n /**\n * When the popper box is placed in the context of a scrollable element, we need to set\n * preventOverflow.escapeWithReference to true and flip.boundariesElement to 'scrollParent'\n * (default is 'viewport') so that the popper box will stick with the targetRef when we\n * scroll targetRef out of the viewport.\n */\n hasScrollableElement && { name: 'flip', options: { boundary: 'clippingParents' } },\n hasScrollableElement && { name: 'preventOverflow', options: { boundary: 'clippingParents' } },\n\n offsetModifier,\n\n /**\n * This modifier is necessary to retain behaviour from popper v1 where untethered poppers are allowed by\n * default. i.e. popper is still rendered fully in the viewport even if anchor element is no longer in the\n * viewport.\n */\n unstable_disableTether && {\n name: 'preventOverflow',\n options: { altAxis: unstable_disableTether === 'all', tether: false },\n },\n\n flipBoundary && {\n name: 'flip',\n options: {\n altBoundary: true,\n boundary: getBoundary(container, flipBoundary),\n },\n },\n overflowBoundary && {\n name: 'preventOverflow',\n options: {\n altBoundary: true,\n boundary: getBoundary(container, overflowBoundary),\n },\n },\n\n {\n // Similar code as popper-maxsize-modifier: https://github.com/atomiks/popper.js/blob/master/src/modifiers/maxSize.js\n // popper-maxsize-modifier only calculates the max sizes.\n // This modifier can apply max sizes always, or apply the max sizes only when overflow is detected\n name: 'applyMaxSize',\n enabled: !!autoSize,\n phase: 'beforeWrite' as PopperJs.ModifierPhases,\n requiresIfExists: ['offset', 'preventOverflow', 'flip'],\n options: {\n altBoundary: true,\n boundary: getBoundary(container, overflowBoundary),\n },\n fn({ state, options: modifierOptions }: PopperJs.ModifierArguments<{}>) {\n const overflow = PopperJs.detectOverflow(state, modifierOptions);\n const { x, y } = state.modifiersData.preventOverflow || { x: 0, y: 0 };\n const { width, height } = state.rects.popper;\n const basePlacement = parsePopperPlacement(state.placement).basePlacement;\n\n const widthProp: keyof PopperJs.SideObject = basePlacement === 'left' ? 'left' : 'right';\n const heightProp: keyof PopperJs.SideObject = basePlacement === 'top' ? 'top' : 'bottom';\n\n const applyMaxWidth =\n autoSize === 'always' ||\n autoSize === 'width-always' ||\n (overflow[widthProp] > 0 && (autoSize === true || autoSize === 'width'));\n const applyMaxHeight =\n autoSize === 'always' ||\n autoSize === 'height-always' ||\n (overflow[heightProp] > 0 && (autoSize === true || autoSize === 'height'));\n\n if (applyMaxWidth) {\n state.styles.popper.maxWidth = `${width - overflow[widthProp] - x}px`;\n }\n if (applyMaxHeight) {\n state.styles.popper.maxHeight = `${height - overflow[heightProp] - y}px`;\n }\n },\n },\n\n /**\n * This modifier is necessary in order to render the pointer. Refs are resolved in effects, so it can't be\n * placed under computed modifiers. Deep merge is not required as this modifier has only these properties.\n */\n {\n name: 'arrow',\n enabled: !!arrow,\n options: { element: arrow, padding: arrowPadding },\n },\n\n /**\n * Modifies popper offsets to cover the reference rect, but still keep edge alignment\n */\n {\n name: 'coverTarget',\n enabled: !!coverTarget,\n phase: 'main',\n requiresIfExists: ['offset', 'preventOverflow', 'flip'],\n fn({ state }: PopperJs.ModifierArguments<{}>) {\n const basePlacement = parsePopperPlacement(state.placement).basePlacement;\n switch (basePlacement) {\n case 'bottom':\n state.modifiersData.popperOffsets!.y -= state.rects.reference.height;\n break;\n case 'top':\n state.modifiersData.popperOffsets!.y += state.rects.reference.height;\n break;\n case 'left':\n state.modifiersData.popperOffsets!.x += state.rects.reference.width;\n break;\n case 'right':\n state.modifiersData.popperOffsets!.x -= state.rects.reference.width;\n break;\n }\n },\n },\n ].filter(Boolean) as PopperJs.Options['modifiers']; // filter boolean conditional spreading values\n\n const popperOptions: PopperJs.Options = {\n modifiers,\n\n placement,\n strategy,\n };\n\n return popperOptions;\n },\n [\n arrowPadding,\n autoSize,\n coverTarget,\n flipBoundary,\n offsetModifier,\n overflowBoundary,\n placement,\n strategy,\n unstable_disableTether,\n pinned,\n\n // These can be skipped from deps as they will not ever change\n popperOriginalPositionRef,\n ],\n );\n}\n\n/**\n * @internal\n * Exposes Popper positioning API via React hook. Contains few important differences between an official \"react-popper\"\n * package:\n * - style attributes are applied directly on DOM to avoid re-renders\n * - refs changes and resolution is handled properly without re-renders\n * - contains a specific to React fix related to initial positioning when containers have components with managed focus\n * to avoid focus jumps\n */\nexport function usePositioning(\n options: UsePopperOptions = {},\n): {\n // React refs are supposed to be contravariant\n // (allows a more general type to be passed rather than a more specific one)\n // However, Typescript currently can't infer that fact for refs\n // See https://github.com/microsoft/TypeScript/issues/30748 for more information\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n targetRef: React.MutableRefObject<any>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n containerRef: React.MutableRefObject<any>;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n arrowRef: React.MutableRefObject<any>;\n} {\n const { enabled = true } = options;\n const isFirstMount = useFirstMount();\n\n const popperOriginalPositionRef = React.useRef<string>('absolute');\n const resolvePopperOptions = usePopperOptions(options, popperOriginalPositionRef);\n\n const popperInstanceRef = React.useRef<PopperInstance | null>(null);\n\n const handlePopperUpdate = useEventCallback(() => {\n popperInstanceRef.current?.destroy();\n popperInstanceRef.current = null;\n\n const target = overrideTargetRef.current ?? targetRef.current;\n\n let popperInstance: PopperInstance | null = null;\n\n if (canUseDOM() && enabled) {\n if (target && containerRef.current) {\n popperInstance = PopperJs.createPopper(\n target,\n containerRef.current,\n resolvePopperOptions(target, containerRef.current, arrowRef.current),\n );\n }\n }\n\n if (popperInstance) {\n /**\n * The patch updates `.forceUpdate()` Popper function which restores the original position before the first\n * forceUpdate() call. See also \"positionStyleFix\" modifier in usePopperOptions().\n */\n const originalForceUpdate = popperInstance.forceUpdate;\n\n popperInstance.isFirstRun = true;\n popperInstance.forceUpdate = () => {\n if (popperInstance?.isFirstRun) {\n popperInstance.state.elements.popper.style.position = popperOriginalPositionRef.current;\n popperInstance.isFirstRun = false;\n }\n\n originalForceUpdate();\n };\n }\n\n popperInstanceRef.current = popperInstance;\n });\n\n // Refs are managed by useCallbackRef() to handle ref updates scenarios.\n //\n // The first scenario are updates for a targetRef, we can handle it properly only via callback refs, but it causes\n // re-renders (we would like to avoid them).\n //\n // The second problem is related to refs resolution on React's layer: refs are resolved in the same order as effects\n // that causes an issue when you have a container inside a target, for example: a menu in ChatMessage.\n //\n // function ChatMessage(props) {\n // <div className=\"message\" ref={targetRef}> // 3) ref will be resolved only now, but it's too late already\n // <Popper target={targetRef}> // 2) create a popper instance\n // <div className=\"menu\" /> // 1) capture ref from this element\n // </Popper>\n // </div>\n // }\n //\n // Check a demo on CodeSandbox: https://codesandbox.io/s/popper-refs-emy60.\n //\n // This again can be solved with callback refs. It's not a huge issue as with hooks we are moving popper's creation\n // to ChatMessage itself, however, without `useCallback()` refs it's still a Pandora box.\n const targetRef = useCallbackRef<HTMLElement | PopperJs.VirtualElement | null>(null, handlePopperUpdate, true);\n const containerRef = useCallbackRef<HTMLElement | null>(null, handlePopperUpdate, true);\n const arrowRef = useCallbackRef<HTMLElement | null>(null, handlePopperUpdate, true);\n\n // Stores external target from options.target or setTarget\n const overrideTargetRef = useCallbackRef<HTMLElement | PositioningVirtualElement | null>(\n null,\n handlePopperUpdate,\n true,\n );\n\n React.useImperativeHandle(\n options.positioningRef,\n () => ({\n updatePosition: () => {\n popperInstanceRef.current?.update();\n },\n setTarget: (target: HTMLElement | PositioningVirtualElement) => {\n if (options.target && process.env.NODE_ENV !== 'production') {\n const err = new Error();\n // eslint-disable-next-line no-console\n console.warn('Imperative setTarget should not be used at the same time as target option');\n // eslint-disable-next-line no-console\n console.warn(err.stack);\n }\n\n overrideTargetRef.current = target;\n },\n }),\n // Missing deps:\n // options.target - only used for a runtime warning\n // targetRef - Stable between renders\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [],\n );\n\n useIsomorphicLayoutEffect(() => {\n if (options.target) {\n overrideTargetRef.current = options.target;\n }\n }, [options.target, overrideTargetRef]);\n useIsomorphicLayoutEffect(() => {\n handlePopperUpdate();\n\n return () => {\n popperInstanceRef.current?.destroy();\n popperInstanceRef.current = null;\n };\n }, [handlePopperUpdate, options.enabled]);\n useIsomorphicLayoutEffect(\n () => {\n if (!isFirstMount) {\n popperInstanceRef.current?.setOptions(\n resolvePopperOptions(overrideTargetRef.current ?? targetRef.current, containerRef.current, arrowRef.current),\n );\n }\n },\n // Missing deps:\n // isFirstMount - Should never change after mount\n // arrowRef, containerRef, targetRef - Stable between renders\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [resolvePopperOptions],\n );\n\n if (process.env.NODE_ENV !== 'production') {\n // This checked should run only in development mode\n // eslint-disable-next-line react-hooks/rules-of-hooks\n React.useEffect(() => {\n if (containerRef.current) {\n const contentNode = containerRef.current;\n const treeWalker = contentNode.ownerDocument?.createTreeWalker(contentNode, NodeFilter.SHOW_ELEMENT, {\n acceptNode: hasAutofocusFilter,\n });\n\n while (treeWalker?.nextNode()) {\n const node = treeWalker.currentNode;\n // eslint-disable-next-line no-console\n console.warn('<Popper>:', node);\n // eslint-disable-next-line no-console\n console.warn(\n [\n '<Popper>: ^ this node contains \"autoFocus\" prop on a React element. This can break the initial',\n 'positioning of an element and cause a window jump effect. This issue occurs because React polyfills',\n '\"autoFocus\" behavior to solve inconsistencies between different browsers:',\n 'https://github.com/facebook/react/issues/11851#issuecomment-351787078',\n '\\n',\n 'However, \".focus()\" in this case occurs before any other React effects will be executed',\n '(React.useEffect(), componentDidMount(), etc.) and we can not prevent this behavior. If you really',\n 'want to use \"autoFocus\" please add \"position: fixed\" to styles of the element that is wrapped by',\n '\"Popper\".',\n `In general, it's not recommended to use \"autoFocus\" as it may break accessibility aspects:`,\n 'https://github.com/jsx-eslint/eslint-plugin-jsx-a11y/blob/master/docs/rules/no-autofocus.md',\n '\\n',\n 'We suggest to use the \"trapFocus\" prop on Fluent components or a catch \"ref\" and then use',\n '\"ref.current.focus\" in React.useEffect():',\n 'https://reactjs.org/docs/refs-and-the-dom.html#adding-a-ref-to-a-dom-element',\n ].join(' '),\n );\n }\n }\n // We run this check once, no need to add deps here\n // TODO: Should be rework to handle options.enabled and contentRef updates\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n }\n\n return { targetRef, containerRef, arrowRef };\n}\n"],"sourceRoot":"../src/"}
@@ -1,6 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import { createVirtualElementFromClick } from './createVirtualElementFromClick';
3
3
  /**
4
+ * @internal
4
5
  * A state hook that manages a popper virtual element from mouseevents.
5
6
  * Useful for scenarios where a component needs to be positioned by mouse click (e.g. contextmenu)
6
7
  * React synthetic events are not persisted by this hook
@@ -9,7 +10,7 @@ import { createVirtualElementFromClick } from './createVirtualElementFromClick';
9
10
  * @returns state and dispatcher for a Popper virtual element that uses native/synthetic mouse events
10
11
  */
11
12
 
12
- export const usePopperMouseTarget = initialState => {
13
+ export const usePositioningMouseTarget = initialState => {
13
14
  const [virtualElement, setVirtualElement] = React.useState(initialState);
14
15
 
15
16
  const setVirtualMouseTarget = event => {
@@ -28,7 +29,7 @@ export const usePopperMouseTarget = initialState => {
28
29
 
29
30
  if (!(mouseevent instanceof MouseEvent) && process.env.NODE_ENV !== 'production') {
30
31
  // eslint-disable-next-line no-console
31
- console.error('usePopperMouseTarget should only be used with MouseEvent');
32
+ console.error('usePositioningMouseTarget should only be used with MouseEvent');
32
33
  }
33
34
 
34
35
  const contextTarget = createVirtualElementFromClick(mouseevent);
@@ -37,4 +38,4 @@ export const usePopperMouseTarget = initialState => {
37
38
 
38
39
  return [virtualElement, setVirtualMouseTarget];
39
40
  };
40
- //# sourceMappingURL=usePopperMouseTarget.js.map
41
+ //# sourceMappingURL=usePositioningMouseTarget.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["usePositioningMouseTarget.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,6BAAT,QAA8C,iCAA9C;AAGA;;;;;;;;AAQG;;AACH,OAAO,MAAM,yBAAyB,GACpC,YADuC,IAErC;EACF,MAAM,CAAC,cAAD,EAAiB,iBAAjB,IAAsC,KAAK,CAAC,QAAN,CAAsD,YAAtD,CAA5C;;EAEA,MAAM,qBAAqB,GAAI,KAAD,IAA4D;IACxF,IAAI,KAAK,KAAK,SAAV,IAAuB,KAAK,KAAK,IAArC,EAA2C;MACzC,iBAAiB,CAAC,SAAD,CAAjB;MACA;IACD;;IAED,IAAI,UAAJ;;IACA,IAAI,EAAE,KAAK,YAAY,UAAnB,CAAJ,EAAoC;MAClC,UAAU,GAAG,KAAK,CAAC,WAAnB;IACD,CAFD,MAEO;MACL,UAAU,GAAG,KAAb;IACD;;IAED,IAAI,EAAE,UAAU,YAAY,UAAxB,KAAuC,OAAO,CAAC,GAAR,CAAY,QAAZ,KAAyB,YAApE,EAAkF;MAChF;MACA,OAAO,CAAC,KAAR,CAAc,+DAAd;IACD;;IAED,MAAM,aAAa,GAAG,6BAA6B,CAAC,UAAD,CAAnD;IACA,iBAAiB,CAAC,aAAD,CAAjB;EACD,CApBD;;EAsBA,OAAO,CAAC,cAAD,EAAiB,qBAAjB,CAAP;AACD,CA5BM","sourcesContent":["import * as React from 'react';\nimport { createVirtualElementFromClick } from './createVirtualElementFromClick';\nimport { PositioningVirtualElement } from './types';\n\n/**\n * @internal\n * A state hook that manages a popper virtual element from mouseevents.\n * Useful for scenarios where a component needs to be positioned by mouse click (e.g. contextmenu)\n * React synthetic events are not persisted by this hook\n *\n * @param initialState - initializes a user provided state similare to useState\n * @returns state and dispatcher for a Popper virtual element that uses native/synthetic mouse events\n */\nexport const usePositioningMouseTarget = (\n initialState?: PositioningVirtualElement | (() => PositioningVirtualElement),\n) => {\n const [virtualElement, setVirtualElement] = React.useState<PositioningVirtualElement | undefined>(initialState);\n\n const setVirtualMouseTarget = (event: React.MouseEvent | MouseEvent | undefined | null) => {\n if (event === undefined || event === null) {\n setVirtualElement(undefined);\n return;\n }\n\n let mouseevent: MouseEvent;\n if (!(event instanceof MouseEvent)) {\n mouseevent = event.nativeEvent;\n } else {\n mouseevent = event;\n }\n\n if (!(mouseevent instanceof MouseEvent) && process.env.NODE_ENV !== 'production') {\n // eslint-disable-next-line no-console\n console.error('usePositioningMouseTarget should only be used with MouseEvent');\n }\n\n const contextTarget = createVirtualElementFromClick(mouseevent);\n setVirtualElement(contextTarget);\n };\n\n return [virtualElement, setVirtualMouseTarget] as const;\n};\n"],"sourceRoot":"../src/"}