@tylertech/forge-core 2.4.0-dev.1 → 2.4.0-dev.3
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { computePosition, flip as flipMiddleware, hide as hideMiddleware, shift as shiftMiddleware, autoPlacement as autoPlacementMiddleware } from '@floating-ui/dom';
|
|
1
|
+
import { computePosition, flip as flipMiddleware, hide as hideMiddleware, shift as shiftMiddleware, offset as offsetMiddleware, arrow as arrowMiddleware, autoPlacement as autoPlacementMiddleware } from '@floating-ui/dom';
|
|
2
2
|
import { getContainingBlock } from '@floating-ui/utils/dom';
|
|
3
3
|
import { topLayer as topLayerMiddleware } from './top-layer-middleware';
|
|
4
4
|
/** Adjusts the x and y axes by a specified offset amount. */
|
|
@@ -16,15 +16,20 @@ export const positionOffsetMiddleware = ({ x: offsetX, y: offsetY }) => ({
|
|
|
16
16
|
* @param {IPositionElementConfig} config Configuration to provide when positioning the element.
|
|
17
17
|
* @returns {IElementPositionResult} The result of the positioning logic.
|
|
18
18
|
*/
|
|
19
|
-
export async function positionElementAsync({ element, targetElement, placement = 'bottom-start', offset, strategy = 'absolute', apply = true, flip = true, flipOptions = {
|
|
19
|
+
export async function positionElementAsync({ element, targetElement, placement = 'bottom-start', offset = false, offsetOptions, strategy = 'absolute', apply = true, flip = true, flipOptions = {
|
|
20
20
|
fallbackPlacements: ['top-start', 'top', 'top-end', 'left-start', 'left', 'left-end', 'right-start', 'right', 'right-end'],
|
|
21
21
|
fallbackStrategy: 'initialPlacement'
|
|
22
|
-
}, auto = false, autoOptions, shift = true, shiftOptions, hide = false, hideOptions, topLayer = false, transform = true, translateFunction = 'translate3d' }) {
|
|
22
|
+
}, auto = false, autoOptions, shift = true, shiftOptions, hide = false, hideOptions, arrowElement, arrowOptions = {}, topLayer = false, transform = true, translateFunction = 'translate3d' }) {
|
|
23
23
|
var _a;
|
|
24
24
|
const middleware = [];
|
|
25
25
|
// Order of the following middleware is **important**
|
|
26
26
|
if (offset) {
|
|
27
|
-
|
|
27
|
+
if (typeof offset === 'object' && (offset.hasOwnProperty('x') || offset.hasOwnProperty('y'))) {
|
|
28
|
+
middleware.push(positionOffsetMiddleware(offset));
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
middleware.push(offsetMiddleware(offsetOptions));
|
|
32
|
+
}
|
|
28
33
|
}
|
|
29
34
|
if (shift) {
|
|
30
35
|
middleware.push(shiftMiddleware(shiftOptions));
|
|
@@ -41,7 +46,10 @@ export async function positionElementAsync({ element, targetElement, placement =
|
|
|
41
46
|
if (topLayer) {
|
|
42
47
|
middleware.push(topLayerMiddleware());
|
|
43
48
|
}
|
|
44
|
-
|
|
49
|
+
if (arrowElement) {
|
|
50
|
+
middleware.push(arrowMiddleware(Object.assign(Object.assign({}, arrowOptions), { element: arrowElement })));
|
|
51
|
+
}
|
|
52
|
+
const { x, y, placement: finalPlacement, middlewareData } = await computePosition(targetElement, element, { strategy, placement, middleware });
|
|
45
53
|
const visibility = ((_a = middlewareData.hide) === null || _a === void 0 ? void 0 : _a.referenceHidden) ? 'hidden' : 'visible';
|
|
46
54
|
// Should we apply the position information to the element?
|
|
47
55
|
if (apply) {
|
|
@@ -60,7 +68,13 @@ export async function positionElementAsync({ element, targetElement, placement =
|
|
|
60
68
|
}
|
|
61
69
|
Object.assign(element.style, styles);
|
|
62
70
|
}
|
|
63
|
-
return {
|
|
71
|
+
return {
|
|
72
|
+
x,
|
|
73
|
+
y,
|
|
74
|
+
visibility,
|
|
75
|
+
placement: finalPlacement,
|
|
76
|
+
arrow: middlewareData.arrow
|
|
77
|
+
};
|
|
64
78
|
}
|
|
65
79
|
/**
|
|
66
80
|
* Determines if the provided element is a child of a containment block.
|
package/package.json
CHANGED
|
@@ -1,12 +1,15 @@
|
|
|
1
|
-
import { FlipOptions, ShiftOptions, AutoPlacementOptions, HideOptions, Middleware, Placement, Strategy } from '@floating-ui/dom';
|
|
1
|
+
import { FlipOptions, ShiftOptions, AutoPlacementOptions, HideOptions, Middleware, Placement, Strategy, OffsetOptions, MiddlewareData, ArrowOptions } from '@floating-ui/dom';
|
|
2
2
|
export declare type PositionPlacement = Placement;
|
|
3
3
|
export declare type PositionStrategy = Strategy;
|
|
4
|
+
/** @deprecated Will be removed in next major version, use `offsetOptions` instead. */
|
|
4
5
|
export interface IElementPosition {
|
|
5
6
|
x: number;
|
|
6
7
|
y: number;
|
|
7
8
|
}
|
|
8
9
|
export interface IElementPositionResult extends IElementPosition {
|
|
9
10
|
visibility: 'visible' | 'hidden';
|
|
11
|
+
placement: PositionPlacement;
|
|
12
|
+
arrow?: MiddlewareData['arrow'];
|
|
10
13
|
}
|
|
11
14
|
export interface IPositionElementConfig {
|
|
12
15
|
/** The element to apply position to. */
|
|
@@ -33,8 +36,14 @@ export interface IPositionElementConfig {
|
|
|
33
36
|
auto?: boolean;
|
|
34
37
|
/** Options to provide to the autoPlacement middleware. */
|
|
35
38
|
autoOptions?: Partial<AutoPlacementOptions>;
|
|
36
|
-
/**
|
|
37
|
-
offset?: IElementPosition;
|
|
39
|
+
/** Should any offset values be applied to the element. */
|
|
40
|
+
offset?: boolean | IElementPosition;
|
|
41
|
+
/** The options provide to the offset middleware. */
|
|
42
|
+
offsetOptions?: Partial<OffsetOptions>;
|
|
43
|
+
/** The element to use as an arrow. */
|
|
44
|
+
arrowElement?: HTMLElement;
|
|
45
|
+
/** Options to provide to the arrow middleware. */
|
|
46
|
+
arrowOptions?: Partial<ArrowOptions>;
|
|
38
47
|
/** Should the top-layer middleware be applied or not. */
|
|
39
48
|
topLayer?: boolean;
|
|
40
49
|
/** The positioning strategy. */
|
|
@@ -51,7 +60,7 @@ export declare const positionOffsetMiddleware: ({ x: offsetX, y: offsetY }: IEle
|
|
|
51
60
|
* @param {IPositionElementConfig} config Configuration to provide when positioning the element.
|
|
52
61
|
* @returns {IElementPositionResult} The result of the positioning logic.
|
|
53
62
|
*/
|
|
54
|
-
export declare function positionElementAsync({ element, targetElement, placement, offset, strategy, apply, flip, flipOptions, auto, autoOptions, shift, shiftOptions, hide, hideOptions, topLayer, transform, translateFunction }: IPositionElementConfig): Promise<IElementPositionResult>;
|
|
63
|
+
export declare function positionElementAsync({ element, targetElement, placement, offset, offsetOptions, strategy, apply, flip, flipOptions, auto, autoOptions, shift, shiftOptions, hide, hideOptions, arrowElement, arrowOptions, topLayer, transform, translateFunction }: IPositionElementConfig): Promise<IElementPositionResult>;
|
|
55
64
|
/**
|
|
56
65
|
* Determines if the provided element is a child of a containment block.
|
|
57
66
|
* @param element The element to check.
|