@fluentui/react-positioning 0.0.0-nightly-20230501-0418.1 → 0.0.0-nightly-20230503-0419.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.json +9 -9
- package/CHANGELOG.md +7 -7
- package/dist/index.d.ts +267 -0
- package/lib/constants.js +5 -0
- package/lib/constants.js.map +1 -0
- package/lib/createArrowStyles.js +87 -0
- package/lib/createArrowStyles.js.map +1 -0
- package/lib/createPositionManager.js +120 -0
- package/lib/createPositionManager.js.map +1 -0
- package/lib/createVirtualElementFromClick.js +25 -0
- package/lib/createVirtualElementFromClick.js.map +1 -0
- package/lib/index.js +6 -0
- package/lib/index.js.map +1 -0
- package/lib/middleware/coverTarget.js +35 -0
- package/lib/middleware/coverTarget.js.map +1 -0
- package/lib/middleware/flip.js +36 -0
- package/lib/middleware/flip.js.map +1 -0
- package/lib/middleware/index.js +7 -0
- package/lib/middleware/index.js.map +1 -0
- package/lib/middleware/intersecting.js +21 -0
- package/lib/middleware/intersecting.js.map +1 -0
- package/lib/middleware/maxSize.js +38 -0
- package/lib/middleware/maxSize.js.map +1 -0
- package/lib/middleware/offset.js +10 -0
- package/lib/middleware/offset.js.map +1 -0
- package/lib/middleware/shift.js +35 -0
- package/lib/middleware/shift.js.map +1 -0
- package/lib/types.js +2 -0
- package/lib/types.js.map +1 -0
- package/lib/usePositioning.js +169 -0
- package/lib/usePositioning.js.map +1 -0
- package/lib/usePositioningMouseTarget.js +34 -0
- package/lib/usePositioningMouseTarget.js.map +1 -0
- package/lib/utils/debounce.js +20 -0
- package/lib/utils/debounce.js.map +1 -0
- package/lib/utils/fromFloatingUIPlacement.js +38 -0
- package/lib/utils/fromFloatingUIPlacement.js.map +1 -0
- package/lib/utils/getBoundary.js +21 -0
- package/lib/utils/getBoundary.js.map +1 -0
- package/lib/utils/getFloatingUIOffset.js +33 -0
- package/lib/utils/getFloatingUIOffset.js.map +1 -0
- package/lib/utils/getReactFiberFromNode.js +43 -0
- package/lib/utils/getReactFiberFromNode.js.map +1 -0
- package/lib/utils/getScrollParent.js +58 -0
- package/lib/utils/getScrollParent.js.map +1 -0
- package/lib/utils/hasAutoFocusFilter.js +23 -0
- package/lib/utils/hasAutoFocusFilter.js.map +1 -0
- package/lib/utils/index.js +16 -0
- package/lib/utils/index.js.map +1 -0
- package/lib/utils/mergeArrowOffset.js +38 -0
- package/lib/utils/mergeArrowOffset.js.map +1 -0
- package/lib/utils/parseFloatingUIPlacement.js +13 -0
- package/lib/utils/parseFloatingUIPlacement.js.map +1 -0
- package/lib/utils/resolvePositioningShorthand.js +61 -0
- package/lib/utils/resolvePositioningShorthand.js.map +1 -0
- package/lib/utils/toFloatingUIPadding.js +23 -0
- package/lib/utils/toFloatingUIPadding.js.map +1 -0
- package/lib/utils/toFloatingUIPlacement.js +34 -0
- package/lib/utils/toFloatingUIPlacement.js.map +1 -0
- package/lib/utils/toggleScrollListener.js +22 -0
- package/lib/utils/toggleScrollListener.js.map +1 -0
- package/lib/utils/useCallbackRef.js +51 -0
- package/lib/utils/useCallbackRef.js.map +1 -0
- package/lib/utils/writeArrowUpdates.js +20 -0
- package/lib/utils/writeArrowUpdates.js.map +1 -0
- package/lib/utils/writeContainerupdates.js +43 -0
- package/lib/utils/writeContainerupdates.js.map +1 -0
- package/package.json +4 -4
package/CHANGELOG.json
CHANGED
@@ -2,9 +2,9 @@
|
|
2
2
|
"name": "@fluentui/react-positioning",
|
3
3
|
"entries": [
|
4
4
|
{
|
5
|
-
"date": "
|
6
|
-
"tag": "@fluentui/react-positioning_v0.0.0-nightly-
|
7
|
-
"version": "0.0.0-nightly-
|
5
|
+
"date": "Wed, 03 May 2023 04:25:41 GMT",
|
6
|
+
"tag": "@fluentui/react-positioning_v0.0.0-nightly-20230503-0419.1",
|
7
|
+
"version": "0.0.0-nightly-20230503-0419.1",
|
8
8
|
"comments": {
|
9
9
|
"prerelease": [
|
10
10
|
{
|
@@ -16,20 +16,20 @@
|
|
16
16
|
{
|
17
17
|
"author": "beachball",
|
18
18
|
"package": "@fluentui/react-positioning",
|
19
|
-
"comment": "Bump @fluentui/react-shared-contexts to v0.0.0-nightly-
|
20
|
-
"commit": "
|
19
|
+
"comment": "Bump @fluentui/react-shared-contexts to v0.0.0-nightly-20230503-0419.1",
|
20
|
+
"commit": "a9a6cef152f4c3885a3697ddf9ded12bfce5a2be"
|
21
21
|
},
|
22
22
|
{
|
23
23
|
"author": "beachball",
|
24
24
|
"package": "@fluentui/react-positioning",
|
25
|
-
"comment": "Bump @fluentui/react-theme to v0.0.0-nightly-
|
26
|
-
"commit": "
|
25
|
+
"comment": "Bump @fluentui/react-theme to v0.0.0-nightly-20230503-0419.1",
|
26
|
+
"commit": "a9a6cef152f4c3885a3697ddf9ded12bfce5a2be"
|
27
27
|
},
|
28
28
|
{
|
29
29
|
"author": "beachball",
|
30
30
|
"package": "@fluentui/react-positioning",
|
31
|
-
"comment": "Bump @fluentui/react-utilities to v0.0.0-nightly-
|
32
|
-
"commit": "
|
31
|
+
"comment": "Bump @fluentui/react-utilities to v0.0.0-nightly-20230503-0419.1",
|
32
|
+
"commit": "a9a6cef152f4c3885a3697ddf9ded12bfce5a2be"
|
33
33
|
}
|
34
34
|
]
|
35
35
|
}
|
package/CHANGELOG.md
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
# Change Log - @fluentui/react-positioning
|
2
2
|
|
3
|
-
This log was last generated on
|
3
|
+
This log was last generated on Wed, 03 May 2023 04:25:41 GMT and should not be manually modified.
|
4
4
|
|
5
5
|
<!-- Start content -->
|
6
6
|
|
7
|
-
## [0.0.0-nightly-
|
7
|
+
## [0.0.0-nightly-20230503-0419.1](https://github.com/microsoft/fluentui/tree/@fluentui/react-positioning_v0.0.0-nightly-20230503-0419.1)
|
8
8
|
|
9
|
-
|
10
|
-
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-positioning_v9.5.10..@fluentui/react-positioning_v0.0.0-nightly-
|
9
|
+
Wed, 03 May 2023 04:25:41 GMT
|
10
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/react-positioning_v9.5.10..@fluentui/react-positioning_v0.0.0-nightly-20230503-0419.1)
|
11
11
|
|
12
12
|
### Changes
|
13
13
|
|
14
14
|
- Release nightly v9 ([commit](https://github.com/microsoft/fluentui/commit/not available) by fluentui-internal@service.microsoft.com)
|
15
|
-
- Bump @fluentui/react-shared-contexts to v0.0.0-nightly-
|
16
|
-
- Bump @fluentui/react-theme to v0.0.0-nightly-
|
17
|
-
- Bump @fluentui/react-utilities to v0.0.0-nightly-
|
15
|
+
- Bump @fluentui/react-shared-contexts to v0.0.0-nightly-20230503-0419.1 ([commit](https://github.com/microsoft/fluentui/commit/a9a6cef152f4c3885a3697ddf9ded12bfce5a2be) by beachball)
|
16
|
+
- Bump @fluentui/react-theme to v0.0.0-nightly-20230503-0419.1 ([commit](https://github.com/microsoft/fluentui/commit/a9a6cef152f4c3885a3697ddf9ded12bfce5a2be) by beachball)
|
17
|
+
- Bump @fluentui/react-utilities to v0.0.0-nightly-20230503-0419.1 ([commit](https://github.com/microsoft/fluentui/commit/a9a6cef152f4c3885a3697ddf9ded12bfce5a2be) by beachball)
|
18
18
|
|
19
19
|
## [9.5.10](https://github.com/microsoft/fluentui/tree/@fluentui/react-positioning_v9.5.10)
|
20
20
|
|
package/dist/index.d.ts
ADDED
@@ -0,0 +1,267 @@
|
|
1
|
+
import type { GriffelStyle } from '@griffel/react';
|
2
|
+
import * as React_2 from 'react';
|
3
|
+
|
4
|
+
export declare type Alignment = 'top' | 'bottom' | 'start' | 'end' | 'center';
|
5
|
+
|
6
|
+
export declare type AutoSize = 'height' | 'height-always' | 'width' | 'width-always' | 'always' | boolean;
|
7
|
+
|
8
|
+
export declare type Boundary = HTMLElement | Array<HTMLElement> | 'clippingParents' | 'scrollParent' | 'window';
|
9
|
+
|
10
|
+
/**
|
11
|
+
* @internal
|
12
|
+
* Creates CSS styles to size the arrow created by createArrowStyles to the given height.
|
13
|
+
*
|
14
|
+
* Use this when you need to create classes for several different arrow sizes. If you only need a
|
15
|
+
* constant arrow size, you can pass the `arrowHeight` param to createArrowStyles instead.
|
16
|
+
*/
|
17
|
+
export declare function createArrowHeightStyles(arrowHeight: number): {
|
18
|
+
width: string;
|
19
|
+
height: string;
|
20
|
+
};
|
21
|
+
|
22
|
+
/**
|
23
|
+
* @internal
|
24
|
+
* Helper that creates a makeStyles rule for an arrow element.
|
25
|
+
* For runtime arrow size toggling simply create extra classnames to apply to the arrow element
|
26
|
+
*
|
27
|
+
* ```ts
|
28
|
+
* makeStyles({
|
29
|
+
* arrowWithSize: createArrowStyles({ arrowHeight: 6 }),
|
30
|
+
*
|
31
|
+
* arrowWithoutSize: createArrowStyles({ arrowHeight: undefined }),
|
32
|
+
* mediumArrow: createArrowHeightStyles(4),
|
33
|
+
* smallArrow: createArrowHeightStyles(2),
|
34
|
+
* })
|
35
|
+
* ...
|
36
|
+
*
|
37
|
+
* state.arrowWithSize.className = styles.arrowWithSize;
|
38
|
+
* state.arrowWithoutSize.className = mergeClasses(
|
39
|
+
* styles.arrowWithoutSize,
|
40
|
+
* state.smallArrow && styles.smallArrow,
|
41
|
+
* state.mediumArrow && styles.mediumArrow,
|
42
|
+
* )
|
43
|
+
* ```
|
44
|
+
*/
|
45
|
+
export declare function createArrowStyles(options: CreateArrowStylesOptions): GriffelStyle;
|
46
|
+
|
47
|
+
/**
|
48
|
+
* @internal
|
49
|
+
* Options parameter for the createArrowStyles function
|
50
|
+
*/
|
51
|
+
export declare type CreateArrowStylesOptions = {
|
52
|
+
/**
|
53
|
+
* The height of the arrow from the base to the tip, in px. The base width of the arrow is always twice its height.
|
54
|
+
*
|
55
|
+
* This can be undefined to leave out the arrow size styles. You must then add styles created by
|
56
|
+
* createArrowHeightStyles to set the arrow's size correctly. This can be useful if the arrow can be different sizes.
|
57
|
+
*/
|
58
|
+
arrowHeight: number | undefined;
|
59
|
+
/**
|
60
|
+
* The borderWidth of the arrow. Should be the same borderWidth as the parent element.
|
61
|
+
*
|
62
|
+
* @defaultvalue 1px
|
63
|
+
*/
|
64
|
+
borderWidth?: GriffelStyle['borderBottomWidth'];
|
65
|
+
/**
|
66
|
+
* The borderStyle for the arrow. Should be the same borderStyle as the parent element.
|
67
|
+
*
|
68
|
+
* @defaultvalue solid
|
69
|
+
*/
|
70
|
+
borderStyle?: GriffelStyle['borderBottomStyle'];
|
71
|
+
/**
|
72
|
+
* The borderColor of the arrow. Should be the same borderColor as the parent element.
|
73
|
+
*
|
74
|
+
* @defaultvalue tokens.colorTransparentStroke
|
75
|
+
*/
|
76
|
+
borderColor?: GriffelStyle['borderBottomColor'];
|
77
|
+
};
|
78
|
+
|
79
|
+
/**
|
80
|
+
* Creates a virtual element based on the position of a click event
|
81
|
+
* Can be used as a target for popper in scenarios such as context menus
|
82
|
+
*/
|
83
|
+
export declare function createVirtualElementFromClick(nativeEvent: MouseEvent): PositioningVirtualElement;
|
84
|
+
|
85
|
+
/**
|
86
|
+
* Generally when adding an arrow to popper, it's necessary to offset the position of the popper by the
|
87
|
+
* height of the arrow. A simple utility to merge a provided offset with an arrow height to return the final offset
|
88
|
+
*
|
89
|
+
* @internal
|
90
|
+
* @param userOffset - The offset provided by the user
|
91
|
+
* @param arrowHeight - The height of the arrow in px
|
92
|
+
* @returns User offset augmented with arrow height
|
93
|
+
*/
|
94
|
+
export declare function mergeArrowOffset(userOffset: Offset | undefined | null, arrowHeight: number): Offset;
|
95
|
+
|
96
|
+
export declare type Offset = OffsetFunction | OffsetObject | OffsetShorthand;
|
97
|
+
|
98
|
+
export declare type OffsetFunction = (param: OffsetFunctionParam) => OffsetObject | OffsetShorthand;
|
99
|
+
|
100
|
+
export declare type OffsetFunctionParam = {
|
101
|
+
positionedRect: Rect;
|
102
|
+
targetRect: Rect;
|
103
|
+
position: Position;
|
104
|
+
alignment?: Alignment;
|
105
|
+
};
|
106
|
+
|
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: TargetElement) => void;
|
127
|
+
};
|
128
|
+
|
129
|
+
declare interface PositioningOptions {
|
130
|
+
/** Alignment for the component. Only has an effect if used with the @see position option */
|
131
|
+
align?: Alignment;
|
132
|
+
/** The element which will define the boundaries of the positioned element for the flip behavior. */
|
133
|
+
flipBoundary?: Boundary | null;
|
134
|
+
/** The element which will define the boundaries of the positioned element for the overflow behavior. */
|
135
|
+
overflowBoundary?: Boundary | null;
|
136
|
+
/**
|
137
|
+
* Applies a padding to the overflow bounadry, so that overflow is detected earlier before the
|
138
|
+
* positioned surface hits the overflow boundary.
|
139
|
+
*/
|
140
|
+
overflowBoundaryPadding?: number | Partial<{
|
141
|
+
top: number;
|
142
|
+
end: number;
|
143
|
+
bottom: number;
|
144
|
+
start: number;
|
145
|
+
}>;
|
146
|
+
/**
|
147
|
+
* Position for the component. Position has higher priority than align. If position is vertical ('above' | 'below')
|
148
|
+
* and align is also vertical ('top' | 'bottom') or if both position and align are horizontal ('before' | 'after'
|
149
|
+
* and 'start' | 'end' respectively),
|
150
|
+
* then provided value for 'align' will be ignored and 'center' will be used instead.
|
151
|
+
*/
|
152
|
+
position?: Position;
|
153
|
+
/**
|
154
|
+
* Enables the position element to be positioned with 'fixed' (default value is position: 'absolute')
|
155
|
+
* @default false
|
156
|
+
*/
|
157
|
+
positionFixed?: boolean;
|
158
|
+
/**
|
159
|
+
* Lets you displace a positioned element from its reference element.
|
160
|
+
* This can be useful if you need to apply some margin between them or if you need to fine tune the
|
161
|
+
* position according to some custom logic.
|
162
|
+
*/
|
163
|
+
offset?: Offset;
|
164
|
+
/**
|
165
|
+
* Defines padding between the corner of the popup element and the arrow.
|
166
|
+
* Use to prevent the arrow from overlapping a rounded corner, for example.
|
167
|
+
*/
|
168
|
+
arrowPadding?: number;
|
169
|
+
/**
|
170
|
+
* Applies max-height and max-width on the positioned element to fit it within the available space in viewport.
|
171
|
+
* true enables this for both width and height when overflow happens.
|
172
|
+
* 'always' applies `max-height`/`max-width` regardless of overflow.
|
173
|
+
* 'height' applies `max-height` when overflow happens, and 'width' for `max-width`
|
174
|
+
* `height-always` applies `max-height` regardless of overflow, and 'width-always' for always applying `max-width`
|
175
|
+
*/
|
176
|
+
autoSize?: AutoSize;
|
177
|
+
/**
|
178
|
+
* Modifies position and alignment to cover the target
|
179
|
+
*/
|
180
|
+
coverTarget?: boolean;
|
181
|
+
/**
|
182
|
+
* Disables automatic repositioning of the component; it will always be placed according to the values of `align` and
|
183
|
+
* `position` props, regardless of the size of the component, the reference element or the viewport.
|
184
|
+
*/
|
185
|
+
pinned?: boolean;
|
186
|
+
/**
|
187
|
+
* When the reference element or the viewport is outside viewport allows a positioned element to be fully in viewport.
|
188
|
+
* "all" enables this behavior for all axis.
|
189
|
+
*/
|
190
|
+
unstable_disableTether?: boolean | 'all';
|
191
|
+
/**
|
192
|
+
* If flip fails to stop the positioned element from overflowing
|
193
|
+
* its boundaries, use a specified fallback positions.
|
194
|
+
*/
|
195
|
+
fallbackPositions?: PositioningShorthandValue[];
|
196
|
+
}
|
197
|
+
|
198
|
+
export declare interface PositioningProps extends Pick<PositioningOptions, 'align' | 'flipBoundary' | 'overflowBoundary' | 'overflowBoundaryPadding' | 'position' | 'offset' | 'arrowPadding' | 'autoSize' | 'coverTarget' | 'pinned'> {
|
199
|
+
/** An imperative handle to Popper methods. */
|
200
|
+
positioningRef?: React_2.Ref<PositioningImperativeRef>;
|
201
|
+
/**
|
202
|
+
* Manual override for the target element. Useful for scenarios where a component accepts user prop to override target
|
203
|
+
*/
|
204
|
+
target?: TargetElement | null;
|
205
|
+
}
|
206
|
+
|
207
|
+
export declare type PositioningShorthand = PositioningProps | PositioningShorthandValue;
|
208
|
+
|
209
|
+
export declare type PositioningShorthandValue = 'above' | 'above-start' | 'above-end' | 'below' | 'below-start' | 'below-end' | 'before' | 'before-top' | 'before-bottom' | 'after' | 'after-top' | 'after-bottom';
|
210
|
+
|
211
|
+
export declare type PositioningVirtualElement = {
|
212
|
+
getBoundingClientRect: () => {
|
213
|
+
x: number;
|
214
|
+
y: number;
|
215
|
+
top: number;
|
216
|
+
left: number;
|
217
|
+
bottom: number;
|
218
|
+
right: number;
|
219
|
+
width: number;
|
220
|
+
height: number;
|
221
|
+
};
|
222
|
+
contextElement?: Element;
|
223
|
+
};
|
224
|
+
|
225
|
+
declare type Rect = {
|
226
|
+
width: number;
|
227
|
+
height: number;
|
228
|
+
x: number;
|
229
|
+
y: number;
|
230
|
+
};
|
231
|
+
|
232
|
+
export declare function resolvePositioningShorthand(shorthand: PositioningShorthand | undefined | null): Readonly<PositioningProps>;
|
233
|
+
|
234
|
+
export declare type SetVirtualMouseTarget = (event: React_2.MouseEvent | MouseEvent | undefined | null) => void;
|
235
|
+
|
236
|
+
declare type TargetElement = HTMLElement | PositioningVirtualElement;
|
237
|
+
|
238
|
+
/**
|
239
|
+
* @internal
|
240
|
+
*/
|
241
|
+
export declare function usePositioning(options: UsePositioningOptions): UsePositioningReturn;
|
242
|
+
|
243
|
+
/**
|
244
|
+
* @internal
|
245
|
+
* A state hook that manages a popper virtual element from mouseevents.
|
246
|
+
* Useful for scenarios where a component needs to be positioned by mouse click (e.g. contextmenu)
|
247
|
+
* React synthetic events are not persisted by this hook
|
248
|
+
*
|
249
|
+
* @param initialState - initializes a user provided state similare to useState
|
250
|
+
* @returns state and dispatcher for a Popper virtual element that uses native/synthetic mouse events
|
251
|
+
*/
|
252
|
+
export declare const usePositioningMouseTarget: (initialState?: PositioningVirtualElement | (() => PositioningVirtualElement) | undefined) => readonly [PositioningVirtualElement | undefined, SetVirtualMouseTarget];
|
253
|
+
|
254
|
+
declare interface UsePositioningOptions extends PositioningProps, Pick<PositioningOptions, 'fallbackPositions' | 'pinned'> {
|
255
|
+
/**
|
256
|
+
* If false, does not position anything
|
257
|
+
*/
|
258
|
+
enabled?: boolean;
|
259
|
+
}
|
260
|
+
|
261
|
+
declare interface UsePositioningReturn {
|
262
|
+
targetRef: React_2.MutableRefObject<any>;
|
263
|
+
containerRef: React_2.MutableRefObject<any>;
|
264
|
+
arrowRef: React_2.MutableRefObject<any>;
|
265
|
+
}
|
266
|
+
|
267
|
+
export { }
|
package/lib/constants.js
ADDED
@@ -0,0 +1,5 @@
|
|
1
|
+
export const DATA_POSITIONING_INTERSECTING = 'data-popper-is-intersecting';
|
2
|
+
export const DATA_POSITIONING_ESCAPED = 'data-popper-escaped';
|
3
|
+
export const DATA_POSITIONING_HIDDEN = 'data-popper-reference-hidden';
|
4
|
+
export const DATA_POSITIONING_PLACEMENT = 'data-popper-placement';
|
5
|
+
//# sourceMappingURL=constants.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["DATA_POSITIONING_INTERSECTING","DATA_POSITIONING_ESCAPED","DATA_POSITIONING_HIDDEN","DATA_POSITIONING_PLACEMENT"],"sources":["../src/constants.ts"],"sourcesContent":["export const DATA_POSITIONING_INTERSECTING = 'data-popper-is-intersecting';\nexport const DATA_POSITIONING_ESCAPED = 'data-popper-escaped';\nexport const DATA_POSITIONING_HIDDEN = 'data-popper-reference-hidden';\nexport const DATA_POSITIONING_PLACEMENT = 'data-popper-placement';\n"],"mappings":"AAAA,OAAO,MAAMA,6BAAA,GAAgC;AAC7C,OAAO,MAAMC,wBAAA,GAA2B;AACxC,OAAO,MAAMC,uBAAA,GAA0B;AACvC,OAAO,MAAMC,0BAAA,GAA6B"}
|
@@ -0,0 +1,87 @@
|
|
1
|
+
import { shorthands } from '@griffel/react';
|
2
|
+
import { tokens } from '@fluentui/react-theme';
|
3
|
+
/**
|
4
|
+
* @internal
|
5
|
+
* Helper that creates a makeStyles rule for an arrow element.
|
6
|
+
* For runtime arrow size toggling simply create extra classnames to apply to the arrow element
|
7
|
+
*
|
8
|
+
* ```ts
|
9
|
+
* makeStyles({
|
10
|
+
* arrowWithSize: createArrowStyles({ arrowHeight: 6 }),
|
11
|
+
*
|
12
|
+
* arrowWithoutSize: createArrowStyles({ arrowHeight: undefined }),
|
13
|
+
* mediumArrow: createArrowHeightStyles(4),
|
14
|
+
* smallArrow: createArrowHeightStyles(2),
|
15
|
+
* })
|
16
|
+
* ...
|
17
|
+
*
|
18
|
+
* state.arrowWithSize.className = styles.arrowWithSize;
|
19
|
+
* state.arrowWithoutSize.className = mergeClasses(
|
20
|
+
* styles.arrowWithoutSize,
|
21
|
+
* state.smallArrow && styles.smallArrow,
|
22
|
+
* state.mediumArrow && styles.mediumArrow,
|
23
|
+
* )
|
24
|
+
* ```
|
25
|
+
*/
|
26
|
+
export function createArrowStyles(options) {
|
27
|
+
const {
|
28
|
+
arrowHeight,
|
29
|
+
borderWidth = '1px',
|
30
|
+
borderStyle = 'solid',
|
31
|
+
borderColor = tokens.colorTransparentStroke
|
32
|
+
} = options;
|
33
|
+
return {
|
34
|
+
position: 'absolute',
|
35
|
+
backgroundColor: 'inherit',
|
36
|
+
visibility: 'hidden',
|
37
|
+
zIndex: -1,
|
38
|
+
...(arrowHeight && createArrowHeightStyles(arrowHeight)),
|
39
|
+
'::before': {
|
40
|
+
content: '""',
|
41
|
+
visibility: 'visible',
|
42
|
+
position: 'absolute',
|
43
|
+
boxSizing: 'border-box',
|
44
|
+
width: 'inherit',
|
45
|
+
height: 'inherit',
|
46
|
+
backgroundColor: 'inherit',
|
47
|
+
...shorthands.borderRight(`${borderWidth} /* @noflip */`, `${borderStyle} /* @noflip */`, `${borderColor} /* @noflip */`),
|
48
|
+
...shorthands.borderBottom(borderWidth, borderStyle, borderColor),
|
49
|
+
borderBottomRightRadius: tokens.borderRadiusSmall,
|
50
|
+
transform: 'rotate(var(--angle)) translate(0, 50%) rotate(45deg)'
|
51
|
+
},
|
52
|
+
// Popper sets data-popper-placement on the root element, which is used to align the arrow
|
53
|
+
':global([data-popper-placement^="top"])': {
|
54
|
+
bottom: `-${borderWidth}`,
|
55
|
+
'--angle': '0'
|
56
|
+
},
|
57
|
+
':global([data-popper-placement^="right"])': {
|
58
|
+
left: `-${borderWidth} /* @noflip */`,
|
59
|
+
'--angle': '90deg'
|
60
|
+
},
|
61
|
+
':global([data-popper-placement^="bottom"])': {
|
62
|
+
top: `-${borderWidth}`,
|
63
|
+
'--angle': '180deg'
|
64
|
+
},
|
65
|
+
':global([data-popper-placement^="left"])': {
|
66
|
+
right: `-${borderWidth} /* @noflip */`,
|
67
|
+
'--angle': '270deg'
|
68
|
+
}
|
69
|
+
};
|
70
|
+
}
|
71
|
+
/**
|
72
|
+
* @internal
|
73
|
+
* Creates CSS styles to size the arrow created by createArrowStyles to the given height.
|
74
|
+
*
|
75
|
+
* Use this when you need to create classes for several different arrow sizes. If you only need a
|
76
|
+
* constant arrow size, you can pass the `arrowHeight` param to createArrowStyles instead.
|
77
|
+
*/
|
78
|
+
export function createArrowHeightStyles(arrowHeight) {
|
79
|
+
// The arrow is a square rotated 45 degrees to have its bottom and right edges form a right triangle.
|
80
|
+
// Multiply the triangle's height by sqrt(2) to get length of its edges.
|
81
|
+
const edgeLength = `${1.414 * arrowHeight}px`;
|
82
|
+
return {
|
83
|
+
width: edgeLength,
|
84
|
+
height: edgeLength
|
85
|
+
};
|
86
|
+
}
|
87
|
+
//# sourceMappingURL=createArrowStyles.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["shorthands","tokens","createArrowStyles","options","arrowHeight","borderWidth","borderStyle","borderColor","colorTransparentStroke","position","backgroundColor","visibility","zIndex","createArrowHeightStyles","content","boxSizing","width","height","borderRight","borderBottom","borderBottomRightRadius","borderRadiusSmall","transform","bottom","left","top","right","edgeLength"],"sources":["../src/createArrowStyles.ts"],"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"],"mappings":"AAAA,SAASA,UAAU,QAAQ;AAC3B,SAASC,MAAM,QAAQ;AAsCvB;;;;;;;;;;;;;;;;;;;;;;;AAuBA,OAAO,SAASC,kBAAkBC,OAAiC,EAAgB;EACjF,MAAM;IACJC,WAAA;IACAC,WAAA,GAAc;IACdC,WAAA,GAAc;IACdC,WAAA,GAAcN,MAAA,CAAOO;EAAsB,CAC5C,GAAGL,OAAA;EAEJ,OAAO;IACLM,QAAA,EAAU;IACVC,eAAA,EAAiB;IACjBC,UAAA,EAAY;IACZC,MAAA,EAAQ,CAAC;IAET,IAAIR,WAAA,IAAeS,uBAAA,CAAwBT,WAAA,CAAY;IAEvD,YAAY;MACVU,OAAA,EAAS;MACTH,UAAA,EAAY;MACZF,QAAA,EAAU;MACVM,SAAA,EAAW;MACXC,KAAA,EAAO;MACPC,MAAA,EAAQ;MACRP,eAAA,EAAiB;MACjB,GAAGV,UAAA,CAAWkB,WAAW,CACtB,GAAEb,WAAY,gBAAe,EAC7B,GAAEC,WAAY,gBAAe,EAC7B,GAAEC,WAAY,gBAAe,CAC/B;MACD,GAAGP,UAAA,CAAWmB,YAAY,CAACd,WAAA,EAAaC,WAAA,EAAaC,WAAA,CAAY;MACjEa,uBAAA,EAAyBnB,MAAA,CAAOoB,iBAAiB;MACjDC,SAAA,EAAW;IACb;IAEA;IACA,2CAA2C;MACzCC,MAAA,EAAS,IAAGlB,WAAY,EAAC;MACzB,WAAW;IACb;IACA,6CAA6C;MAC3CmB,IAAA,EAAO,IAAGnB,WAAY,gBAAe;MACrC,WAAW;IACb;IACA,8CAA8C;MAC5CoB,GAAA,EAAM,IAAGpB,WAAY,EAAC;MACtB,WAAW;IACb;IACA,4CAA4C;MAC1CqB,KAAA,EAAQ,IAAGrB,WAAY,gBAAe;MACtC,WAAW;IACb;EACF;AACF;AAEA;;;;;;;AAOA,OAAO,SAASQ,wBAAwBT,WAAmB,EAAE;EAC3D;EACA;EACA,MAAMuB,UAAA,GAAc,GAAE,QAAQvB,WAAY,IAAG;EAC7C,OAAO;IAAEY,KAAA,EAAOW,UAAA;IAAYV,MAAA,EAAQU;EAAW;AACjD"}
|
@@ -0,0 +1,120 @@
|
|
1
|
+
import { computePosition } from '@floating-ui/dom';
|
2
|
+
import { debounce, writeArrowUpdates, writeContainerUpdates, getScrollParent } from './utils';
|
3
|
+
import { isHTMLElement } from '@fluentui/react-utilities';
|
4
|
+
/**
|
5
|
+
* @internal
|
6
|
+
* @returns manager that handles positioning out of the react lifecycle
|
7
|
+
*/
|
8
|
+
export function createPositionManager(options) {
|
9
|
+
const {
|
10
|
+
container,
|
11
|
+
target,
|
12
|
+
arrow,
|
13
|
+
strategy,
|
14
|
+
middleware,
|
15
|
+
placement
|
16
|
+
} = options;
|
17
|
+
let isDestroyed = false;
|
18
|
+
if (!target || !container) {
|
19
|
+
return {
|
20
|
+
updatePosition: () => undefined,
|
21
|
+
dispose: () => undefined
|
22
|
+
};
|
23
|
+
}
|
24
|
+
let isFirstUpdate = true;
|
25
|
+
const scrollParents = new Set();
|
26
|
+
const targetWindow = container.ownerDocument.defaultView;
|
27
|
+
// When the container is first resolved, set position `fixed` to avoid scroll jumps.
|
28
|
+
// Without this scroll jumps can occur when the element is rendered initially and receives focus
|
29
|
+
Object.assign(container.style, {
|
30
|
+
position: 'fixed',
|
31
|
+
left: 0,
|
32
|
+
top: 0,
|
33
|
+
margin: 0
|
34
|
+
});
|
35
|
+
const forceUpdate = () => {
|
36
|
+
// debounced update can still occur afterwards
|
37
|
+
// early return to avoid memory leaks
|
38
|
+
if (isDestroyed) {
|
39
|
+
return;
|
40
|
+
}
|
41
|
+
if (isFirstUpdate) {
|
42
|
+
scrollParents.add(getScrollParent(container));
|
43
|
+
if (isHTMLElement(target)) {
|
44
|
+
scrollParents.add(getScrollParent(target));
|
45
|
+
}
|
46
|
+
scrollParents.forEach(scrollParent => {
|
47
|
+
scrollParent.addEventListener('scroll', updatePosition);
|
48
|
+
});
|
49
|
+
isFirstUpdate = false;
|
50
|
+
}
|
51
|
+
Object.assign(container.style, {
|
52
|
+
position: strategy
|
53
|
+
});
|
54
|
+
computePosition(target, container, {
|
55
|
+
placement,
|
56
|
+
middleware,
|
57
|
+
strategy
|
58
|
+
}).then(({
|
59
|
+
x,
|
60
|
+
y,
|
61
|
+
middlewareData,
|
62
|
+
placement: computedPlacement
|
63
|
+
}) => {
|
64
|
+
// Promise can still resolve after destruction
|
65
|
+
// early return to avoid applying outdated position
|
66
|
+
if (isDestroyed) {
|
67
|
+
return;
|
68
|
+
}
|
69
|
+
writeArrowUpdates({
|
70
|
+
arrow,
|
71
|
+
middlewareData
|
72
|
+
});
|
73
|
+
writeContainerUpdates({
|
74
|
+
container,
|
75
|
+
middlewareData,
|
76
|
+
placement: computedPlacement,
|
77
|
+
coordinates: {
|
78
|
+
x,
|
79
|
+
y
|
80
|
+
},
|
81
|
+
lowPPI: ((targetWindow === null || targetWindow === void 0 ? void 0 : targetWindow.devicePixelRatio) || 1) <= 1,
|
82
|
+
strategy
|
83
|
+
});
|
84
|
+
}).catch(err => {
|
85
|
+
// https://github.com/floating-ui/floating-ui/issues/1845
|
86
|
+
// FIXME for node > 14
|
87
|
+
// node 15 introduces promise rejection which means that any components
|
88
|
+
// tests need to be `it('', async () => {})` otherwise there can be race conditions with
|
89
|
+
// JSDOM being torn down before this promise is resolved so globals like `window` and `document` don't exist
|
90
|
+
// Unless all tests that ever use `usePositioning` are turned into async tests, any logging during testing
|
91
|
+
// will actually be counter productive
|
92
|
+
if (process.env.NODE_ENV === 'development') {
|
93
|
+
// eslint-disable-next-line no-console
|
94
|
+
console.error('[usePositioning]: Failed to calculate position', err);
|
95
|
+
}
|
96
|
+
});
|
97
|
+
};
|
98
|
+
const updatePosition = debounce(() => forceUpdate());
|
99
|
+
const dispose = () => {
|
100
|
+
isDestroyed = true;
|
101
|
+
if (targetWindow) {
|
102
|
+
targetWindow.removeEventListener('scroll', updatePosition);
|
103
|
+
targetWindow.removeEventListener('resize', updatePosition);
|
104
|
+
}
|
105
|
+
scrollParents.forEach(scrollParent => {
|
106
|
+
scrollParent.removeEventListener('scroll', updatePosition);
|
107
|
+
});
|
108
|
+
};
|
109
|
+
if (targetWindow) {
|
110
|
+
targetWindow.addEventListener('scroll', updatePosition);
|
111
|
+
targetWindow.addEventListener('resize', updatePosition);
|
112
|
+
}
|
113
|
+
// Update the position on initialization
|
114
|
+
updatePosition();
|
115
|
+
return {
|
116
|
+
updatePosition,
|
117
|
+
dispose
|
118
|
+
};
|
119
|
+
}
|
120
|
+
//# sourceMappingURL=createPositionManager.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["computePosition","debounce","writeArrowUpdates","writeContainerUpdates","getScrollParent","isHTMLElement","createPositionManager","options","container","target","arrow","strategy","middleware","placement","isDestroyed","updatePosition","undefined","dispose","isFirstUpdate","scrollParents","Set","targetWindow","ownerDocument","defaultView","Object","assign","style","position","left","top","margin","forceUpdate","add","forEach","scrollParent","addEventListener","then","x","y","middlewareData","computedPlacement","coordinates","lowPPI","devicePixelRatio","catch","err","process","env","NODE_ENV","console","error","removeEventListener"],"sources":["../src/createPositionManager.ts"],"sourcesContent":["import { computePosition } from '@floating-ui/dom';\nimport type { Middleware, Placement, Strategy } from '@floating-ui/dom';\nimport type { PositionManager, TargetElement } from './types';\nimport { debounce, writeArrowUpdates, writeContainerUpdates, getScrollParent } from './utils';\nimport { isHTMLElement } from '@fluentui/react-utilities';\n\ninterface PositionManagerOptions {\n /**\n * The positioned element\n */\n container: HTMLElement;\n /**\n * Element that the container will be anchored to\n */\n target: TargetElement;\n /**\n * Arrow that points from the container to the target\n */\n arrow: HTMLElement | null;\n /**\n * The value of the css `position` property\n * @default absolute\n */\n strategy: Strategy;\n /**\n * [Floating UI middleware](https://floating-ui.com/docs/middleware)\n */\n middleware: Middleware[];\n /**\n * [Floating UI placement](https://floating-ui.com/docs/computePosition#placement)\n */\n placement?: Placement;\n}\n\n/**\n * @internal\n * @returns manager that handles positioning out of the react lifecycle\n */\nexport function createPositionManager(options: PositionManagerOptions): PositionManager {\n const { container, target, arrow, strategy, middleware, placement } = options;\n let isDestroyed = false;\n if (!target || !container) {\n return {\n updatePosition: () => undefined,\n dispose: () => undefined,\n };\n }\n\n let isFirstUpdate = true;\n const scrollParents: Set<HTMLElement> = new Set<HTMLElement>();\n const targetWindow = container.ownerDocument.defaultView;\n\n // When the container is first resolved, set position `fixed` to avoid scroll jumps.\n // Without this scroll jumps can occur when the element is rendered initially and receives focus\n Object.assign(container.style, { position: 'fixed', left: 0, top: 0, margin: 0 });\n\n const forceUpdate = () => {\n // debounced update can still occur afterwards\n // early return to avoid memory leaks\n if (isDestroyed) {\n return;\n }\n\n if (isFirstUpdate) {\n scrollParents.add(getScrollParent(container));\n if (isHTMLElement(target)) {\n scrollParents.add(getScrollParent(target));\n }\n\n scrollParents.forEach(scrollParent => {\n scrollParent.addEventListener('scroll', updatePosition);\n });\n\n isFirstUpdate = false;\n }\n\n Object.assign(container.style, { position: strategy });\n computePosition(target, container, { placement, middleware, strategy })\n .then(({ x, y, middlewareData, placement: computedPlacement }) => {\n // Promise can still resolve after destruction\n // early return to avoid applying outdated position\n if (isDestroyed) {\n return;\n }\n\n writeArrowUpdates({ arrow, middlewareData });\n writeContainerUpdates({\n container,\n middlewareData,\n placement: computedPlacement,\n coordinates: { x, y },\n lowPPI: (targetWindow?.devicePixelRatio || 1) <= 1,\n strategy,\n });\n })\n .catch(err => {\n // https://github.com/floating-ui/floating-ui/issues/1845\n // FIXME for node > 14\n // node 15 introduces promise rejection which means that any components\n // tests need to be `it('', async () => {})` otherwise there can be race conditions with\n // JSDOM being torn down before this promise is resolved so globals like `window` and `document` don't exist\n // Unless all tests that ever use `usePositioning` are turned into async tests, any logging during testing\n // will actually be counter productive\n if (process.env.NODE_ENV === 'development') {\n // eslint-disable-next-line no-console\n console.error('[usePositioning]: Failed to calculate position', err);\n }\n });\n };\n\n const updatePosition = debounce(() => forceUpdate());\n\n const dispose = () => {\n isDestroyed = true;\n\n if (targetWindow) {\n targetWindow.removeEventListener('scroll', updatePosition);\n targetWindow.removeEventListener('resize', updatePosition);\n }\n\n scrollParents.forEach(scrollParent => {\n scrollParent.removeEventListener('scroll', updatePosition);\n });\n };\n\n if (targetWindow) {\n targetWindow.addEventListener('scroll', updatePosition);\n targetWindow.addEventListener('resize', updatePosition);\n }\n\n // Update the position on initialization\n updatePosition();\n\n return {\n updatePosition,\n dispose,\n };\n}\n"],"mappings":"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"}
|
@@ -0,0 +1,25 @@
|
|
1
|
+
/**
|
2
|
+
* Creates a virtual element based on the position of a click event
|
3
|
+
* Can be used as a target for popper in scenarios such as context menus
|
4
|
+
*/export function createVirtualElementFromClick(nativeEvent) {
|
5
|
+
const left = nativeEvent.clientX;
|
6
|
+
const top = nativeEvent.clientY;
|
7
|
+
const right = left + 1;
|
8
|
+
const bottom = top + 1;
|
9
|
+
function getBoundingClientRect() {
|
10
|
+
return {
|
11
|
+
left,
|
12
|
+
top,
|
13
|
+
right,
|
14
|
+
bottom,
|
15
|
+
x: left,
|
16
|
+
y: top,
|
17
|
+
height: 1,
|
18
|
+
width: 1
|
19
|
+
};
|
20
|
+
}
|
21
|
+
return {
|
22
|
+
getBoundingClientRect
|
23
|
+
};
|
24
|
+
}
|
25
|
+
//# sourceMappingURL=createVirtualElementFromClick.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["createVirtualElementFromClick","nativeEvent","left","clientX","top","clientY","right","bottom","getBoundingClientRect","x","y","height","width"],"sources":["../src/createVirtualElementFromClick.ts"],"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"],"mappings":"AAEA;;;GAIA,OAAO,SAASA,8BAA8BC,WAAuB,EAA6B;EAChG,MAAMC,IAAA,GAAOD,WAAA,CAAYE,OAAO;EAChC,MAAMC,GAAA,GAAMH,WAAA,CAAYI,OAAO;EAC/B,MAAMC,KAAA,GAAQJ,IAAA,GAAO;EACrB,MAAMK,MAAA,GAASH,GAAA,GAAM;EAErB,SAASI,sBAAA,EAAwB;IAC/B,OAAO;MACLN,IAAA;MACAE,GAAA;MACAE,KAAA;MACAC,MAAA;MACAE,CAAA,EAAGP,IAAA;MACHQ,CAAA,EAAGN,GAAA;MACHO,MAAA,EAAQ;MACRC,KAAA,EAAO;IACT;EACF;EAEA,OAAO;IACLJ;EACF;AACF"}
|
package/lib/index.js
ADDED
@@ -0,0 +1,6 @@
|
|
1
|
+
export { createVirtualElementFromClick } from './createVirtualElementFromClick';
|
2
|
+
export { createArrowHeightStyles, createArrowStyles } from './createArrowStyles';
|
3
|
+
export { usePositioning } from './usePositioning';
|
4
|
+
export { usePositioningMouseTarget } from './usePositioningMouseTarget';
|
5
|
+
export { resolvePositioningShorthand, mergeArrowOffset } from './utils/index';
|
6
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["createVirtualElementFromClick","createArrowHeightStyles","createArrowStyles","usePositioning","usePositioningMouseTarget","resolvePositioningShorthand","mergeArrowOffset"],"sources":["../src/index.ts"],"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 SetVirtualMouseTarget,\n} from './types';\n"],"mappings":"AAAA,SAASA,6BAA6B,QAAQ;AAC9C,SAASC,uBAAuB,EAAEC,iBAAiB,QAAQ;AAE3D,SAASC,cAAc,QAAQ;AAC/B,SAASC,yBAAyB,QAAQ;AAC1C,SAASC,2BAA2B,EAAEC,gBAAgB,QAAQ"}
|