@tylertech/forge-core 2.2.2 → 2.4.0-dev.0

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.
@@ -637,11 +637,12 @@ export function deepQuerySelectorAll(rootElement, selectors, checkRootElement =
637
637
  }
638
638
  /**
639
639
  * Gets the currently focused element within the document by also traversing shadow roots.
640
+ * @param {Document} doc The document to get the active element from. Defaults to the current document.
640
641
  * @returns {Element}
641
642
  */
642
- export function getActiveElement() {
643
- const activeElement = document.activeElement;
644
- if (!activeElement || activeElement === document.body) {
643
+ export function getActiveElement(doc = document) {
644
+ const activeElement = doc.activeElement;
645
+ if (!activeElement || activeElement === doc.body) {
645
646
  return activeElement;
646
647
  }
647
648
  return getActiveShadowElement(activeElement);
@@ -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 { topLayerOverTransforms } from './top-layer-over-transforms';
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(topLayerOverTransforms());
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,69 @@
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
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tylertech/forge-core",
3
- "version": "2.2.2",
3
+ "version": "2.4.0-dev.0",
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": "^0.5.0",
16
+ "@floating-ui/dom": "^1.5.3",
17
17
  "tslib": "^2.3.1"
18
18
  }
19
- }
19
+ }
@@ -211,9 +211,10 @@ export declare function matchesSelectors(el: Element | Node, selectors: string |
211
211
  export declare function deepQuerySelectorAll(rootElement: Element, selectors: string | string[], checkRootElement?: boolean): Element[];
212
212
  /**
213
213
  * Gets the currently focused element within the document by also traversing shadow roots.
214
+ * @param {Document} doc The document to get the active element from. Defaults to the current document.
214
215
  * @returns {Element}
215
216
  */
216
- export declare function getActiveElement(): Element;
217
+ export declare function getActiveElement(doc?: Document): Element;
217
218
  /**
218
219
  * Gets the active element within the provided elements shadow root. If the element
219
220
  * does not have a shadow root, the provided element is returned.
@@ -1,8 +1,4 @@
1
- import { Options as FlipOptions } from '@floating-ui/core/src/middleware/flip';
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,9 +32,11 @@ 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<AutoOptions>;
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
42
  /** Should positining be applied using a `transform` style. */
@@ -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;
@@ -0,0 +1,2 @@
1
+ import type { Middleware } from '@floating-ui/dom';
2
+ export declare const topLayerOverTransforms: () => Middleware;