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