@tylertech/forge-core 2.3.0 → 2.4.0-dev.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.
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { computePosition, flip as flipMiddleware, hide as hideMiddleware, shift as shiftMiddleware, autoPlacement as autoPlacementMiddleware } from '@floating-ui/dom';
|
|
2
|
+
import { getContainingBlock } from '@floating-ui/utils/dom';
|
|
3
|
+
import { topLayer as topLayerMiddleware } from './top-layer-middleware';
|
|
2
4
|
/** Adjusts the x and y axes by a specified offset amount. */
|
|
3
5
|
export const positionOffsetMiddleware = ({ x: offsetX, y: offsetY }) => ({
|
|
4
6
|
name: 'positionOffset',
|
|
@@ -17,7 +19,7 @@ export const positionOffsetMiddleware = ({ x: offsetX, y: offsetY }) => ({
|
|
|
17
19
|
export async function positionElementAsync({ element, targetElement, placement = 'bottom-start', offset, strategy = 'absolute', apply = true, flip = true, flipOptions = {
|
|
18
20
|
fallbackPlacements: ['top-start', 'top', 'top-end', 'left-start', 'left', 'left-end', 'right-start', 'right', 'right-end'],
|
|
19
21
|
fallbackStrategy: 'initialPlacement'
|
|
20
|
-
}, auto = false, autoOptions, shift = true, shiftOptions, hide = false, hideOptions, transform = true, translateFunction = 'translate3d' }) {
|
|
22
|
+
}, auto = false, autoOptions, shift = true, shiftOptions, hide = false, hideOptions, topLayer = false, transform = true, translateFunction = 'translate3d' }) {
|
|
21
23
|
var _a;
|
|
22
24
|
const middleware = [];
|
|
23
25
|
// Order of the following middleware is **important**
|
|
@@ -36,6 +38,9 @@ export async function positionElementAsync({ element, targetElement, placement =
|
|
|
36
38
|
if (hide) {
|
|
37
39
|
middleware.push(hideMiddleware(hideOptions));
|
|
38
40
|
}
|
|
41
|
+
if (topLayer) {
|
|
42
|
+
middleware.push(topLayerMiddleware());
|
|
43
|
+
}
|
|
39
44
|
const { x, y, middlewareData } = await computePosition(targetElement, element, { strategy, placement, middleware });
|
|
40
45
|
const visibility = ((_a = middlewareData.hide) === null || _a === void 0 ? void 0 : _a.referenceHidden) ? 'hidden' : 'visible';
|
|
41
46
|
// Should we apply the position information to the element?
|
|
@@ -57,3 +62,11 @@ export async function positionElementAsync({ element, targetElement, placement =
|
|
|
57
62
|
}
|
|
58
63
|
return { x, y, visibility };
|
|
59
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* Determines if the provided element is a child of a containment block.
|
|
67
|
+
* @param element The element to check.
|
|
68
|
+
* @returns {boolean} `true` if the element is within a containment block, otherwise `false`.
|
|
69
|
+
*/
|
|
70
|
+
export function isWithinContainingBlock(element) {
|
|
71
|
+
return Boolean(getContainingBlock(element));
|
|
72
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { getContainingBlock } from '@floating-ui/utils/dom';
|
|
2
|
+
export const topLayer = () => ({
|
|
3
|
+
name: 'topLayer',
|
|
4
|
+
async fn({ x, y, elements: { reference, floating } }) {
|
|
5
|
+
let isTopLayer = false;
|
|
6
|
+
const referenceEl = reference;
|
|
7
|
+
const diffCoords = { x: 0, y: 0 };
|
|
8
|
+
try {
|
|
9
|
+
isTopLayer = isTopLayer || floating.matches(':popover-open');
|
|
10
|
+
}
|
|
11
|
+
catch (error) { }
|
|
12
|
+
try {
|
|
13
|
+
isTopLayer = isTopLayer || floating.matches(':open');
|
|
14
|
+
}
|
|
15
|
+
catch (error) { }
|
|
16
|
+
try {
|
|
17
|
+
isTopLayer = isTopLayer || floating.matches(':modal');
|
|
18
|
+
}
|
|
19
|
+
catch (error) { }
|
|
20
|
+
if (!isTopLayer) {
|
|
21
|
+
return { x, y, data: diffCoords };
|
|
22
|
+
}
|
|
23
|
+
const containingBlock = getContainingBlock(referenceEl);
|
|
24
|
+
const inContainingBlock = containingBlock && !isWindow(containingBlock);
|
|
25
|
+
if (isTopLayer && inContainingBlock) {
|
|
26
|
+
const rect = referenceEl.getBoundingClientRect();
|
|
27
|
+
diffCoords.x = Math.trunc(rect.x - referenceEl.offsetLeft);
|
|
28
|
+
diffCoords.y = Math.trunc(rect.y - referenceEl.offsetTop);
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
x: x + diffCoords.x,
|
|
32
|
+
y: y + diffCoords.y,
|
|
33
|
+
data: diffCoords
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
function isWindow(value) {
|
|
38
|
+
return (value &&
|
|
39
|
+
value.document &&
|
|
40
|
+
value.location &&
|
|
41
|
+
value.alert &&
|
|
42
|
+
value.setInterval);
|
|
43
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tylertech/forge-core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.0-dev.1",
|
|
4
4
|
"description": "A library of core web utilities that support Forge Web Component libraries.",
|
|
5
5
|
"author": "Tyler Technologies, Inc.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"typings": "typings/index.d.ts",
|
|
14
14
|
"sideEffects": false,
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@floating-ui/dom": "^
|
|
16
|
+
"@floating-ui/dom": "^1.5.3",
|
|
17
17
|
"tslib": "^2.3.1"
|
|
18
18
|
}
|
|
19
|
-
}
|
|
19
|
+
}
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Options as AutoOptions } from '@floating-ui/core/src/middleware/autoPlacement';
|
|
3
|
-
import { Options as ShiftOptions } from '@floating-ui/core/src/middleware/shift';
|
|
4
|
-
import { Options as HideOptions } from '@floating-ui/core/src/middleware/hide';
|
|
5
|
-
import { Middleware, Placement, Strategy } from '@floating-ui/dom';
|
|
1
|
+
import { FlipOptions, ShiftOptions, AutoPlacementOptions, HideOptions, Middleware, Placement, Strategy } from '@floating-ui/dom';
|
|
6
2
|
export declare type PositionPlacement = Placement;
|
|
7
3
|
export declare type PositionStrategy = Strategy;
|
|
8
4
|
export interface IElementPosition {
|
|
@@ -36,12 +32,14 @@ export interface IPositionElementConfig {
|
|
|
36
32
|
/** Should the element automatically attempt to locate the best placement, */
|
|
37
33
|
auto?: boolean;
|
|
38
34
|
/** Options to provide to the autoPlacement middleware. */
|
|
39
|
-
autoOptions?: Partial<
|
|
35
|
+
autoOptions?: Partial<AutoPlacementOptions>;
|
|
40
36
|
/** Offset positioning to apply to the placement. */
|
|
41
37
|
offset?: IElementPosition;
|
|
38
|
+
/** Should the top-layer middleware be applied or not. */
|
|
39
|
+
topLayer?: boolean;
|
|
42
40
|
/** The positioning strategy. */
|
|
43
41
|
strategy?: PositionStrategy;
|
|
44
|
-
/** Should
|
|
42
|
+
/** Should positioning be applied using a `transform` style. */
|
|
45
43
|
transform?: boolean;
|
|
46
44
|
/** The CSS `translate` function to apply to the `transform`. Only applied when `transform` is `true`. */
|
|
47
45
|
translateFunction?: 'translate3d' | 'translate';
|
|
@@ -53,4 +51,10 @@ export declare const positionOffsetMiddleware: ({ x: offsetX, y: offsetY }: IEle
|
|
|
53
51
|
* @param {IPositionElementConfig} config Configuration to provide when positioning the element.
|
|
54
52
|
* @returns {IElementPositionResult} The result of the positioning logic.
|
|
55
53
|
*/
|
|
56
|
-
export declare function positionElementAsync({ element, targetElement, placement, offset, strategy, apply, flip, flipOptions, auto, autoOptions, shift, shiftOptions, hide, hideOptions, transform, translateFunction }: IPositionElementConfig): Promise<IElementPositionResult>;
|
|
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>;
|
|
55
|
+
/**
|
|
56
|
+
* Determines if the provided element is a child of a containment block.
|
|
57
|
+
* @param element The element to check.
|
|
58
|
+
* @returns {boolean} `true` if the element is within a containment block, otherwise `false`.
|
|
59
|
+
*/
|
|
60
|
+
export declare function isWithinContainingBlock(element: Element): boolean;
|