@loomhq/lens 10.32.11 → 10.32.14

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.
@@ -9,8 +9,8 @@ var __rest = (this && this.__rest) || function (s, e) {
9
9
  }
10
10
  return t;
11
11
  };
12
- import { flip, offset as floatingUiOffset, getScrollParents, shift, useFloating, } from '@floating-ui/react-dom';
13
- import React, { useEffect, useState } from 'react';
12
+ import { autoUpdate, flip, offset as floatingUiOffset, limitShift, shift, useFloating, } from '@floating-ui/react-dom';
13
+ import React, { useEffect } from 'react';
14
14
  import ReactDOM from 'react-dom';
15
15
  import styled from '@emotion/styled';
16
16
  import { unit } from '../../variables';
@@ -34,35 +34,35 @@ const Wrapper = styled.div `
34
34
  width: fit-content;
35
35
  // transform forces the popover to calculate the position from the trigger instead of the viewport
36
36
  transform: translate(0);
37
+ z-index: 1;
37
38
  `;
38
39
  const ContentWrapper = styled.div `
39
40
  ${props => props.zIndex && `z-index: ${props.zIndex}`};
40
41
  `;
41
42
  const Popover = (_a) => {
42
- var { children, content, offset = 1, boundaryOffset = 1, isOpen, zIndex = 500, placement = 'topCenter', rootId, boundaryElement = 'body', transitionDuration = 0, transitionDelay = 0 } = _a, props = __rest(_a, ["children", "content", "offset", "boundaryOffset", "isOpen", "zIndex", "placement", "rootId", "boundaryElement", "transitionDuration", "transitionDelay"]);
43
+ var { children, content, offset = 0.5, boundaryOffset = 0.5, isOpen, zIndex = 500, placement = 'topCenter', rootId, boundaryElement = 'body', transitionDuration = 0, transitionDelay = 0 } = _a, props = __rest(_a, ["children", "content", "offset", "boundaryOffset", "isOpen", "zIndex", "placement", "rootId", "boundaryElement", "transitionDuration", "transitionDelay"]);
43
44
  const unitOffset = offset * unit;
44
45
  const unitBoundaryOffset = boundaryOffset * unit;
45
- const [bodyElement, setBodyElement] = useState(null);
46
+ const isBrowser = typeof window !== 'undefined';
47
+ const rootNode = rootId && isBrowser ? document.getElementById(rootId) : undefined;
46
48
  const { stage, shouldMount } = useTransition(isOpen, transitionDuration + transitionDelay);
47
- useEffect(() => {
48
- setBodyElement(document === null || document === void 0 ? void 0 : document.querySelector('body'));
49
- }, []);
50
49
  const getBoundaryElement = () => {
51
- if (boundaryElement) {
52
- if (boundaryElement === 'body') {
53
- return bodyElement;
54
- }
55
- return boundaryElement;
50
+ if (boundaryElement === 'body' && isBrowser) {
51
+ return document.body;
56
52
  }
57
- return 'clippingParents';
53
+ return boundaryElement;
58
54
  };
59
55
  const { x, y, reference, floating, strategy, update, refs } = useFloating({
60
56
  placement: placements[placement],
61
57
  middleware: [
62
- flip({ fallbackPlacements: ['top', 'bottom'] }),
63
58
  shift({
64
59
  padding: unitBoundaryOffset,
65
- boundary: getBoundaryElement(),
60
+ boundary: boundaryElement ? getBoundaryElement() : undefined,
61
+ limiter: limitShift(),
62
+ }),
63
+ flip({
64
+ fallbackPlacements: ['top', 'bottom'],
65
+ fallbackStrategy: 'initialPlacement',
66
66
  }),
67
67
  floatingUiOffset(unitOffset),
68
68
  ],
@@ -72,27 +72,9 @@ const Popover = (_a) => {
72
72
  if (!refs.reference.current || !refs.floating.current) {
73
73
  return;
74
74
  }
75
- const parents = [
76
- ...getScrollParents(refs.reference.current),
77
- ...getScrollParents(refs.floating.current),
78
- ];
79
- parents.forEach(parent => {
80
- parent.addEventListener('scroll', update);
81
- parent.addEventListener('resize', update);
82
- });
83
- return () => {
84
- parents.forEach(parent => {
85
- parent.removeEventListener('scroll', update);
86
- parent.removeEventListener('resize', update);
87
- });
88
- };
89
- }, [refs.reference, refs.floating, update, isOpen, shouldMount]);
90
- const [rootNode, setRootNode] = useState(null);
91
- useEffect(() => {
92
- if (rootId) {
93
- setRootNode(document === null || document === void 0 ? void 0 : document.getElementById(rootId));
94
- }
95
- }, [rootId]);
75
+ // Only call this when the floating element is rendered
76
+ return autoUpdate(refs.reference.current, refs.floating.current, update);
77
+ }, [refs.reference, refs.floating, update, shouldMount]);
96
78
  const contentProps = {
97
79
  zIndex,
98
80
  ref: floating,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loomhq/lens",
3
- "version": "10.32.11",
3
+ "version": "10.32.14",
4
4
  "scripts": {
5
5
  "dev": "next",
6
6
  "build:next": "next build",
@@ -22,7 +22,7 @@
22
22
  ]
23
23
  },
24
24
  "dependencies": {
25
- "@floating-ui/react-dom": "^0.4.3",
25
+ "@floating-ui/react-dom": "^0.6.0",
26
26
  "downshift": "^5.4.7",
27
27
  "lodash": "^4.17.21",
28
28
  "react-color": "^2.19.3",