@tylertech/forge-core 2.4.0-dev.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,6 +1,6 @@
1
1
  import { computePosition, flip as flipMiddleware, hide as hideMiddleware, shift as shiftMiddleware, autoPlacement as autoPlacementMiddleware } from '@floating-ui/dom';
2
2
  import { getContainingBlock } from '@floating-ui/utils/dom';
3
- import { topLayerOverTransforms } from './top-layer-over-transforms';
3
+ import { topLayer as topLayerMiddleware } from './top-layer-middleware';
4
4
  /** Adjusts the x and y axes by a specified offset amount. */
5
5
  export const positionOffsetMiddleware = ({ x: offsetX, y: offsetY }) => ({
6
6
  name: 'positionOffset',
@@ -39,7 +39,7 @@ export async function positionElementAsync({ element, targetElement, placement =
39
39
  middleware.push(hideMiddleware(hideOptions));
40
40
  }
41
41
  if (topLayer) {
42
- middleware.push(topLayerOverTransforms());
42
+ middleware.push(topLayerMiddleware());
43
43
  }
44
44
  const { x, y, middlewareData } = await computePosition(targetElement, element, { strategy, placement, middleware });
45
45
  const visibility = ((_a = middlewareData.hide) === null || _a === void 0 ? void 0 : _a.referenceHidden) ? 'hidden' : 'visible';
@@ -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.4.0-dev.0",
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",
@@ -39,7 +39,7 @@ export interface IPositionElementConfig {
39
39
  topLayer?: boolean;
40
40
  /** The positioning strategy. */
41
41
  strategy?: PositionStrategy;
42
- /** Should positining be applied using a `transform` style. */
42
+ /** Should positioning be applied using a `transform` style. */
43
43
  transform?: boolean;
44
44
  /** The CSS `translate` function to apply to the `transform`. Only applied when `transform` is `true`. */
45
45
  translateFunction?: 'translate3d' | 'translate';
@@ -0,0 +1,2 @@
1
+ import type { Middleware } from '@floating-ui/dom';
2
+ export declare const topLayer: () => Middleware;
@@ -1,69 +0,0 @@
1
- import { getContainingBlock, getWindow, isContainingBlock } from '@floating-ui/utils/dom';
2
- export const topLayerOverTransforms = () => ({
3
- name: 'topLayer',
4
- async fn(middlewareArguments) {
5
- const { x, y, elements: { reference, floating } } = middlewareArguments;
6
- let onTopLayer = false;
7
- let topLayerIsFloating = false;
8
- let withinReference = false;
9
- const diffCoords = { x: 0, y: 0 };
10
- try {
11
- onTopLayer = onTopLayer || floating.matches(':popover-open');
12
- }
13
- catch (error) { }
14
- try {
15
- onTopLayer = onTopLayer || floating.matches(':open');
16
- }
17
- catch (error) { }
18
- try {
19
- onTopLayer = onTopLayer || floating.matches(':modal');
20
- }
21
- catch (error) { }
22
- topLayerIsFloating = onTopLayer;
23
- const dialogAncestorQueryEvent = new Event('floating-ui-dialog-test', { composed: true, bubbles: true });
24
- floating.addEventListener('floating-ui-dialog-test', (event) => {
25
- event.composedPath().forEach((el) => {
26
- withinReference = withinReference || el === reference;
27
- if (el === floating || el.localName !== 'dialog') {
28
- return;
29
- }
30
- try {
31
- onTopLayer = onTopLayer || el.matches(':modal');
32
- }
33
- catch (error) { }
34
- });
35
- }, { once: true });
36
- floating.dispatchEvent(dialogAncestorQueryEvent);
37
- let overTransforms = false;
38
- const root = (withinReference ? reference : floating);
39
- const containingBlock = isContainingBlock(root) ? root : getContainingBlock(root);
40
- if (containingBlock !== null && getWindow(containingBlock) !== containingBlock) {
41
- const css = getComputedStyle(containingBlock);
42
- overTransforms = css.transform !== 'none' || css.filter ? css.filter !== 'none' : false;
43
- }
44
- if (onTopLayer && overTransforms && containingBlock) {
45
- const rect = containingBlock.getBoundingClientRect();
46
- diffCoords.x = rect.x;
47
- diffCoords.y = rect.y;
48
- }
49
- if (onTopLayer && topLayerIsFloating) {
50
- return {
51
- x: x + diffCoords.x,
52
- y: y + diffCoords.y,
53
- data: diffCoords
54
- };
55
- }
56
- if (onTopLayer) {
57
- return {
58
- x,
59
- y,
60
- data: diffCoords
61
- };
62
- }
63
- return {
64
- x: x - diffCoords.x,
65
- y: y - diffCoords.y,
66
- data: diffCoords
67
- };
68
- }
69
- });
@@ -1,2 +0,0 @@
1
- import type { Middleware } from '@floating-ui/dom';
2
- export declare const topLayerOverTransforms: () => Middleware;