@cloudscape-design/components-themeable 3.0.624 → 3.0.626
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.
- package/lib/internal/manifest.json +1 -1
- package/lib/internal/scss/annotation-context/annotation/arrow.scss +7 -0
- package/lib/internal/scss/button-dropdown/category-elements/styles.scss +5 -0
- package/lib/internal/scss/popover/arrow.scss +7 -0
- package/lib/internal/scss/popover/container.scss +10 -0
- package/lib/internal/template/alert/index.d.ts.map +1 -1
- package/lib/internal/template/alert/index.js +5 -1
- package/lib/internal/template/alert/index.js.map +1 -1
- package/lib/internal/template/annotation-context/annotation/styles.css.js +24 -24
- package/lib/internal/template/annotation-context/annotation/styles.scoped.css +33 -29
- package/lib/internal/template/annotation-context/annotation/styles.selectors.js +24 -24
- package/lib/internal/template/app-layout/index.d.ts.map +1 -1
- package/lib/internal/template/app-layout/index.js +16 -12
- package/lib/internal/template/app-layout/index.js.map +1 -1
- package/lib/internal/template/button-dropdown/category-elements/styles.css.js +14 -14
- package/lib/internal/template/button-dropdown/category-elements/styles.scoped.css +25 -22
- package/lib/internal/template/button-dropdown/category-elements/styles.selectors.js +14 -14
- package/lib/internal/template/container/index.d.ts.map +1 -1
- package/lib/internal/template/container/index.js +1 -1
- package/lib/internal/template/container/index.js.map +1 -1
- package/lib/internal/template/flashbar/flash.d.ts.map +1 -1
- package/lib/internal/template/flashbar/flash.js +8 -2
- package/lib/internal/template/flashbar/flash.js.map +1 -1
- package/lib/internal/template/form/index.js +2 -2
- package/lib/internal/template/form/index.js.map +1 -1
- package/lib/internal/template/internal/analytics/components/analytics-funnel.d.ts +4 -4
- package/lib/internal/template/internal/analytics/components/analytics-funnel.d.ts.map +1 -1
- package/lib/internal/template/internal/analytics/components/analytics-funnel.js +9 -9
- package/lib/internal/template/internal/analytics/components/analytics-funnel.js.map +1 -1
- package/lib/internal/template/internal/analytics/context/analytics-context.d.ts +2 -2
- package/lib/internal/template/internal/analytics/context/analytics-context.d.ts.map +1 -1
- package/lib/internal/template/internal/analytics/context/analytics-context.js.map +1 -1
- package/lib/internal/template/internal/analytics/hooks/use-funnel.d.ts +1 -1
- package/lib/internal/template/internal/analytics/hooks/use-funnel.js +3 -3
- package/lib/internal/template/internal/analytics/hooks/use-funnel.js.map +1 -1
- package/lib/internal/template/internal/analytics/interfaces.d.ts +13 -7
- package/lib/internal/template/internal/analytics/interfaces.d.ts.map +1 -1
- package/lib/internal/template/internal/analytics/interfaces.js.map +1 -1
- package/lib/internal/template/internal/components/chart-popover/index.d.ts +1 -1
- package/lib/internal/template/internal/components/chart-popover/index.d.ts.map +1 -1
- package/lib/internal/template/internal/components/chart-popover/index.js.map +1 -1
- package/lib/internal/template/internal/components/dropdown/dropdown-fit-handler.d.ts +12 -12
- package/lib/internal/template/internal/components/dropdown/dropdown-fit-handler.d.ts.map +1 -1
- package/lib/internal/template/internal/components/dropdown/dropdown-fit-handler.js +103 -83
- package/lib/internal/template/internal/components/dropdown/dropdown-fit-handler.js.map +1 -1
- package/lib/internal/template/internal/components/dropdown/index.d.ts.map +1 -1
- package/lib/internal/template/internal/components/dropdown/index.js +30 -29
- package/lib/internal/template/internal/components/dropdown/index.js.map +1 -1
- package/lib/internal/template/internal/components/tooltip/index.d.ts +1 -1
- package/lib/internal/template/internal/components/tooltip/index.d.ts.map +1 -1
- package/lib/internal/template/internal/components/tooltip/index.js.map +1 -1
- package/lib/internal/template/internal/direction.d.ts +14 -0
- package/lib/internal/template/internal/direction.d.ts.map +1 -1
- package/lib/internal/template/internal/direction.js +25 -0
- package/lib/internal/template/internal/direction.js.map +1 -1
- package/lib/internal/template/internal/environment.js +1 -1
- package/lib/internal/template/internal/environment.json +1 -1
- package/lib/internal/template/internal/generated/theming/index.cjs +14 -14
- package/lib/internal/template/internal/generated/theming/index.js +14 -14
- package/lib/internal/template/internal/hooks/use-performance-marks.js +2 -2
- package/lib/internal/template/internal/hooks/use-performance-marks.js.map +1 -1
- package/lib/internal/template/internal/utils/scrollable-containers.d.ts +5 -5
- package/lib/internal/template/internal/utils/scrollable-containers.d.ts.map +1 -1
- package/lib/internal/template/internal/utils/scrollable-containers.js +19 -19
- package/lib/internal/template/internal/utils/scrollable-containers.js.map +1 -1
- package/lib/internal/template/popover/container.d.ts +1 -1
- package/lib/internal/template/popover/container.d.ts.map +1 -1
- package/lib/internal/template/popover/container.js.map +1 -1
- package/lib/internal/template/popover/interfaces.d.ts +4 -4
- package/lib/internal/template/popover/interfaces.d.ts.map +1 -1
- package/lib/internal/template/popover/interfaces.js.map +1 -1
- package/lib/internal/template/popover/styles.css.js +50 -50
- package/lib/internal/template/popover/styles.scoped.css +76 -64
- package/lib/internal/template/popover/styles.selectors.js +50 -50
- package/lib/internal/template/popover/use-popover-position.d.ts +1 -1
- package/lib/internal/template/popover/use-popover-position.d.ts.map +1 -1
- package/lib/internal/template/popover/use-popover-position.js +32 -29
- package/lib/internal/template/popover/use-popover-position.js.map +1 -1
- package/lib/internal/template/popover/utils/positions.d.ts +2 -2
- package/lib/internal/template/popover/utils/positions.d.ts.map +1 -1
- package/lib/internal/template/popover/utils/positions.js +74 -74
- package/lib/internal/template/popover/utils/positions.js.map +1 -1
- package/lib/internal/template/wizard/index.js +1 -1
- package/lib/internal/template/wizard/index.js.map +1 -1
- package/lib/internal/template/wizard/wizard-form.js +1 -1
- package/lib/internal/template/wizard/wizard-form.js.map +1 -1
- package/package.json +1 -1
|
@@ -2,55 +2,55 @@
|
|
|
2
2
|
// es-module interop with Babel and Typescript
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
module.exports.default = {
|
|
5
|
-
"arrow": "
|
|
6
|
-
"arrow-outer": "awsui_arrow-
|
|
7
|
-
"arrow-inner": "awsui_arrow-
|
|
8
|
-
"refresh": "
|
|
9
|
-
"arrow-position-right-top": "awsui_arrow-position-right-
|
|
10
|
-
"arrow-position-right-bottom": "awsui_arrow-position-right-
|
|
11
|
-
"arrow-position-left-top": "awsui_arrow-position-left-
|
|
12
|
-
"arrow-position-left-bottom": "awsui_arrow-position-left-
|
|
13
|
-
"arrow-position-top-center": "awsui_arrow-position-top-
|
|
14
|
-
"arrow-position-top-right": "awsui_arrow-position-top-
|
|
15
|
-
"arrow-position-top-left": "awsui_arrow-position-top-
|
|
16
|
-
"arrow-position-top-responsive": "awsui_arrow-position-top-
|
|
17
|
-
"arrow-position-bottom-center": "awsui_arrow-position-bottom-
|
|
18
|
-
"arrow-position-bottom-right": "awsui_arrow-position-bottom-
|
|
19
|
-
"arrow-position-bottom-left": "awsui_arrow-position-bottom-
|
|
20
|
-
"arrow-position-bottom-responsive": "awsui_arrow-position-bottom-
|
|
21
|
-
"body": "
|
|
22
|
-
"body-overflow-visible": "awsui_body-overflow-
|
|
23
|
-
"has-dismiss": "awsui_has-
|
|
24
|
-
"dismiss": "
|
|
25
|
-
"dismiss-control": "awsui_dismiss-
|
|
26
|
-
"header-row": "awsui_header-
|
|
27
|
-
"header": "
|
|
28
|
-
"content": "
|
|
29
|
-
"content-overflow-visible": "awsui_content-overflow-
|
|
30
|
-
"container": "
|
|
31
|
-
"container-body": "awsui_container-
|
|
32
|
-
"container-body-variant-annotation": "awsui_container-body-variant-
|
|
33
|
-
"container-body-size-small": "awsui_container-body-size-
|
|
34
|
-
"fixed-width": "awsui_fixed-
|
|
35
|
-
"container-body-size-medium": "awsui_container-body-size-
|
|
36
|
-
"container-body-size-large": "awsui_container-body-size-
|
|
37
|
-
"container-arrow": "awsui_container-
|
|
38
|
-
"container-arrow-position-right-top": "awsui_container-arrow-position-right-
|
|
39
|
-
"container-arrow-position-right-bottom": "awsui_container-arrow-position-right-
|
|
40
|
-
"container-arrow-position-left-top": "awsui_container-arrow-position-left-
|
|
41
|
-
"container-arrow-position-left-bottom": "awsui_container-arrow-position-left-
|
|
42
|
-
"container-arrow-position-top-center": "awsui_container-arrow-position-top-
|
|
43
|
-
"container-arrow-position-top-right": "awsui_container-arrow-position-top-
|
|
44
|
-
"container-arrow-position-top-left": "awsui_container-arrow-position-top-
|
|
45
|
-
"container-arrow-position-top-responsive": "awsui_container-arrow-position-top-
|
|
46
|
-
"container-arrow-position-bottom-center": "awsui_container-arrow-position-bottom-
|
|
47
|
-
"container-arrow-position-bottom-right": "awsui_container-arrow-position-bottom-
|
|
48
|
-
"container-arrow-position-bottom-left": "awsui_container-arrow-position-bottom-
|
|
49
|
-
"awsui-motion-fade-in": "awsui_awsui-motion-fade-
|
|
50
|
-
"root": "
|
|
51
|
-
"trigger": "
|
|
52
|
-
"trigger-type-text": "awsui_trigger-type-
|
|
53
|
-
"trigger-inner-text": "awsui_trigger-inner-
|
|
54
|
-
"popover-inline-content": "awsui_popover-inline-
|
|
5
|
+
"arrow": "awsui_arrow_xjuzf_2nwcz_197",
|
|
6
|
+
"arrow-outer": "awsui_arrow-outer_xjuzf_2nwcz_201",
|
|
7
|
+
"arrow-inner": "awsui_arrow-inner_xjuzf_2nwcz_201",
|
|
8
|
+
"refresh": "awsui_refresh_xjuzf_2nwcz_235",
|
|
9
|
+
"arrow-position-right-top": "awsui_arrow-position-right-top_xjuzf_2nwcz_245",
|
|
10
|
+
"arrow-position-right-bottom": "awsui_arrow-position-right-bottom_xjuzf_2nwcz_245",
|
|
11
|
+
"arrow-position-left-top": "awsui_arrow-position-left-top_xjuzf_2nwcz_248",
|
|
12
|
+
"arrow-position-left-bottom": "awsui_arrow-position-left-bottom_xjuzf_2nwcz_248",
|
|
13
|
+
"arrow-position-top-center": "awsui_arrow-position-top-center_xjuzf_2nwcz_251",
|
|
14
|
+
"arrow-position-top-right": "awsui_arrow-position-top-right_xjuzf_2nwcz_251",
|
|
15
|
+
"arrow-position-top-left": "awsui_arrow-position-top-left_xjuzf_2nwcz_251",
|
|
16
|
+
"arrow-position-top-responsive": "awsui_arrow-position-top-responsive_xjuzf_2nwcz_251",
|
|
17
|
+
"arrow-position-bottom-center": "awsui_arrow-position-bottom-center_xjuzf_2nwcz_254",
|
|
18
|
+
"arrow-position-bottom-right": "awsui_arrow-position-bottom-right_xjuzf_2nwcz_254",
|
|
19
|
+
"arrow-position-bottom-left": "awsui_arrow-position-bottom-left_xjuzf_2nwcz_254",
|
|
20
|
+
"arrow-position-bottom-responsive": "awsui_arrow-position-bottom-responsive_xjuzf_2nwcz_254",
|
|
21
|
+
"body": "awsui_body_xjuzf_2nwcz_356",
|
|
22
|
+
"body-overflow-visible": "awsui_body-overflow-visible_xjuzf_2nwcz_395",
|
|
23
|
+
"has-dismiss": "awsui_has-dismiss_xjuzf_2nwcz_399",
|
|
24
|
+
"dismiss": "awsui_dismiss_xjuzf_2nwcz_404",
|
|
25
|
+
"dismiss-control": "awsui_dismiss-control_xjuzf_2nwcz_412",
|
|
26
|
+
"header-row": "awsui_header-row_xjuzf_2nwcz_416",
|
|
27
|
+
"header": "awsui_header_xjuzf_2nwcz_416",
|
|
28
|
+
"content": "awsui_content_xjuzf_2nwcz_442",
|
|
29
|
+
"content-overflow-visible": "awsui_content-overflow-visible_xjuzf_2nwcz_450",
|
|
30
|
+
"container": "awsui_container_xjuzf_2nwcz_552",
|
|
31
|
+
"container-body": "awsui_container-body_xjuzf_2nwcz_560",
|
|
32
|
+
"container-body-variant-annotation": "awsui_container-body-variant-annotation_xjuzf_2nwcz_603",
|
|
33
|
+
"container-body-size-small": "awsui_container-body-size-small_xjuzf_2nwcz_608",
|
|
34
|
+
"fixed-width": "awsui_fixed-width_xjuzf_2nwcz_611",
|
|
35
|
+
"container-body-size-medium": "awsui_container-body-size-medium_xjuzf_2nwcz_615",
|
|
36
|
+
"container-body-size-large": "awsui_container-body-size-large_xjuzf_2nwcz_622",
|
|
37
|
+
"container-arrow": "awsui_container-arrow_xjuzf_2nwcz_634",
|
|
38
|
+
"container-arrow-position-right-top": "awsui_container-arrow-position-right-top_xjuzf_2nwcz_638",
|
|
39
|
+
"container-arrow-position-right-bottom": "awsui_container-arrow-position-right-bottom_xjuzf_2nwcz_638",
|
|
40
|
+
"container-arrow-position-left-top": "awsui_container-arrow-position-left-top_xjuzf_2nwcz_654",
|
|
41
|
+
"container-arrow-position-left-bottom": "awsui_container-arrow-position-left-bottom_xjuzf_2nwcz_654",
|
|
42
|
+
"container-arrow-position-top-center": "awsui_container-arrow-position-top-center_xjuzf_2nwcz_670",
|
|
43
|
+
"container-arrow-position-top-right": "awsui_container-arrow-position-top-right_xjuzf_2nwcz_670",
|
|
44
|
+
"container-arrow-position-top-left": "awsui_container-arrow-position-top-left_xjuzf_2nwcz_670",
|
|
45
|
+
"container-arrow-position-top-responsive": "awsui_container-arrow-position-top-responsive_xjuzf_2nwcz_670",
|
|
46
|
+
"container-arrow-position-bottom-center": "awsui_container-arrow-position-bottom-center_xjuzf_2nwcz_686",
|
|
47
|
+
"container-arrow-position-bottom-right": "awsui_container-arrow-position-bottom-right_xjuzf_2nwcz_690",
|
|
48
|
+
"container-arrow-position-bottom-left": "awsui_container-arrow-position-bottom-left_xjuzf_2nwcz_694",
|
|
49
|
+
"awsui-motion-fade-in": "awsui_awsui-motion-fade-in_xjuzf_2nwcz_1",
|
|
50
|
+
"root": "awsui_root_xjuzf_2nwcz_840",
|
|
51
|
+
"trigger": "awsui_trigger_xjuzf_2nwcz_876",
|
|
52
|
+
"trigger-type-text": "awsui_trigger-type-text_xjuzf_2nwcz_883",
|
|
53
|
+
"trigger-inner-text": "awsui_trigger-inner-text_xjuzf_2nwcz_918",
|
|
54
|
+
"popover-inline-content": "awsui_popover-inline-content_xjuzf_2nwcz_922"
|
|
55
55
|
};
|
|
56
56
|
|
|
@@ -4,7 +4,7 @@ export default function usePopoverPosition({ popoverRef, bodyRef, arrowRef, trac
|
|
|
4
4
|
popoverRef: React.RefObject<HTMLDivElement | null>;
|
|
5
5
|
bodyRef: React.RefObject<HTMLDivElement | null>;
|
|
6
6
|
arrowRef: React.RefObject<HTMLDivElement | null>;
|
|
7
|
-
trackRef: React.RefObject<
|
|
7
|
+
trackRef: React.RefObject<HTMLElement | SVGElement | null>;
|
|
8
8
|
contentRef: React.RefObject<HTMLDivElement | null>;
|
|
9
9
|
allowScrollToFit?: boolean;
|
|
10
10
|
allowVerticalOverflow?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-popover-position.d.ts","sourceRoot":"","sources":["../../../src/popover/use-popover-position.ts"],"names":[],"mappings":"AAGA,OAAO,KAAwC,MAAM,OAAO,CAAC;AAC7D,OAAO,EAAe,gBAAgB,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"use-popover-position.d.ts","sourceRoot":"","sources":["../../../src/popover/use-popover-position.ts"],"names":[],"mappings":"AAGA,OAAO,KAAwC,MAAM,OAAO,CAAC;AAC7D,OAAO,EAAe,gBAAgB,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAWnF,MAAM,CAAC,OAAO,UAAU,kBAAkB,CAAC,EACzC,UAAU,EACV,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,UAAU,EACV,gBAAgB,EAChB,qBAAqB,EACrB,iBAAiB,EACjB,gBAAgB,EAChB,YAAY,GACb,EAAE;IACD,UAAU,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;IACnD,OAAO,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;IAChD,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;IACjD,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,GAAG,UAAU,GAAG,IAAI,CAAC,CAAC;IAC3D,UAAU,EAAE,KAAK,CAAC,SAAS,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC;IACnD,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,iBAAiB,EAAE,YAAY,CAAC,QAAQ,CAAC;IACzC,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;;;;qDAMyC,IAAI;EAsI7C"}
|
|
@@ -5,6 +5,7 @@ import { calculatePosition, getDimensions, getOffsetDimensions } from './utils/p
|
|
|
5
5
|
import { nodeContains } from '@cloudscape-design/component-toolkit/dom';
|
|
6
6
|
import { calculateScroll, getFirstScrollableParent, scrollRectangleIntoView, } from '../internal/utils/scrollable-containers';
|
|
7
7
|
import { getContainingBlock } from '../internal/utils/dom';
|
|
8
|
+
import { getLogicalBoundingClientRect } from '../internal/direction';
|
|
8
9
|
export default function usePopoverPosition({ popoverRef, bodyRef, arrowRef, trackRef, contentRef, allowScrollToFit, allowVerticalOverflow, preferredPosition, renderWithPortal, keepPosition, }) {
|
|
9
10
|
const previousInternalPositionRef = useRef(null);
|
|
10
11
|
const [popoverStyle, setPopoverStyle] = useState({});
|
|
@@ -31,26 +32,26 @@ export default function usePopoverPosition({ popoverRef, bodyRef, arrowRef, trac
|
|
|
31
32
|
// Imperatively move body off-screen to give it room to expand.
|
|
32
33
|
// Not doing this in React because this recalculation should happen
|
|
33
34
|
// in the span of a single frame without rerendering anything.
|
|
34
|
-
const
|
|
35
|
-
const
|
|
36
|
-
popover.style.
|
|
37
|
-
popover.style.
|
|
35
|
+
const prevInsetBlockStart = popover.style.insetBlockStart;
|
|
36
|
+
const prevInsetInlineStart = popover.style.insetInlineStart;
|
|
37
|
+
popover.style.insetBlockStart = '0';
|
|
38
|
+
popover.style.insetInlineStart = '0';
|
|
38
39
|
// Imperatively remove body styles that can remain from the previous computation.
|
|
39
|
-
body.style.
|
|
40
|
+
body.style.maxBlockSize = '';
|
|
40
41
|
body.style.overflowX = '';
|
|
41
42
|
body.style.overflowY = '';
|
|
42
43
|
// Get rects representing key elements
|
|
43
44
|
// Use getComputedStyle for arrowRect to avoid modifications made by transform
|
|
44
45
|
const viewportRect = getViewportRect(document.defaultView);
|
|
45
|
-
const trackRect = track
|
|
46
|
+
const trackRect = getLogicalBoundingClientRect(track);
|
|
46
47
|
const arrowRect = getDimensions(arrow);
|
|
47
48
|
const containingBlock = getContainingBlock(popover);
|
|
48
|
-
const containingBlockRect = containingBlock ? containingBlock
|
|
49
|
+
const containingBlockRect = containingBlock ? getLogicalBoundingClientRect(containingBlock) : viewportRect;
|
|
49
50
|
const bodyBorderWidth = getBorderWidth(body);
|
|
50
|
-
const contentRect = contentRef.current
|
|
51
|
+
const contentRect = getLogicalBoundingClientRect(contentRef.current);
|
|
51
52
|
const contentBoundingBox = {
|
|
52
|
-
|
|
53
|
-
|
|
53
|
+
inlineSize: contentRect.inlineSize + 2 * bodyBorderWidth,
|
|
54
|
+
blockSize: contentRect.blockSize + 2 * bodyBorderWidth,
|
|
54
55
|
};
|
|
55
56
|
// When keepPosition is true and the recalculation was triggered by a resize of the popover content,
|
|
56
57
|
// we maintain the previously defined internal position,
|
|
@@ -75,11 +76,11 @@ export default function usePopoverPosition({ popoverRef, bodyRef, arrowRef, trac
|
|
|
75
76
|
// and use that to recalculate the new popover position.
|
|
76
77
|
const trackRelativeOffset = toRelativePosition(popoverOffset, toRelativePosition(trackRect, containingBlockRect));
|
|
77
78
|
// Bring back the container to its original position to prevent any flashing.
|
|
78
|
-
popover.style.
|
|
79
|
-
popover.style.
|
|
79
|
+
popover.style.insetBlockStart = prevInsetBlockStart;
|
|
80
|
+
popover.style.insetInlineStart = prevInsetInlineStart;
|
|
80
81
|
// Allow popover body to scroll if can't fit the popover into the container/viewport otherwise.
|
|
81
82
|
if (scrollable) {
|
|
82
|
-
body.style.
|
|
83
|
+
body.style.maxBlockSize = rect.blockSize + 'px';
|
|
83
84
|
body.style.overflowX = 'hidden';
|
|
84
85
|
body.style.overflowY = 'auto';
|
|
85
86
|
}
|
|
@@ -88,18 +89,20 @@ export default function usePopoverPosition({ popoverRef, bodyRef, arrowRef, trac
|
|
|
88
89
|
setInternalPosition(newInternalPosition);
|
|
89
90
|
const shouldScroll = allowScrollToFit && !shouldKeepPosition;
|
|
90
91
|
// Position the popover
|
|
91
|
-
const
|
|
92
|
-
|
|
92
|
+
const insetBlockStart = shouldScroll
|
|
93
|
+
? popoverOffset.insetBlockStart + calculateScroll(rect)
|
|
94
|
+
: popoverOffset.insetBlockStart;
|
|
95
|
+
setPopoverStyle({ insetBlockStart, insetInlineStart: popoverOffset.insetInlineStart });
|
|
93
96
|
// Scroll if necessary
|
|
94
97
|
if (shouldScroll) {
|
|
95
98
|
const scrollableParent = getFirstScrollableParent(popover);
|
|
96
99
|
scrollRectangleIntoView(rect, scrollableParent);
|
|
97
100
|
}
|
|
98
101
|
positionHandlerRef.current = () => {
|
|
99
|
-
const newTrackOffset = toRelativePosition(track
|
|
102
|
+
const newTrackOffset = toRelativePosition(getLogicalBoundingClientRect(track), containingBlock ? getLogicalBoundingClientRect(containingBlock) : viewportRect);
|
|
100
103
|
setPopoverStyle({
|
|
101
|
-
|
|
102
|
-
|
|
104
|
+
insetBlockStart: newTrackOffset.insetBlockStart + trackRelativeOffset.insetBlockStart,
|
|
105
|
+
insetInlineStart: newTrackOffset.insetInlineStart + trackRelativeOffset.insetInlineStart,
|
|
103
106
|
});
|
|
104
107
|
};
|
|
105
108
|
}, [
|
|
@@ -124,8 +127,8 @@ function getBorderWidth(element) {
|
|
|
124
127
|
*/
|
|
125
128
|
function toRelativePosition(element, parent) {
|
|
126
129
|
return {
|
|
127
|
-
|
|
128
|
-
|
|
130
|
+
insetBlockStart: element.insetBlockStart - parent.insetBlockStart,
|
|
131
|
+
insetInlineStart: element.insetInlineStart - parent.insetInlineStart,
|
|
129
132
|
};
|
|
130
133
|
}
|
|
131
134
|
/**
|
|
@@ -133,19 +136,19 @@ function toRelativePosition(element, parent) {
|
|
|
133
136
|
*/
|
|
134
137
|
function getViewportRect(window) {
|
|
135
138
|
return {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
139
|
+
insetBlockStart: 0,
|
|
140
|
+
insetInlineStart: 0,
|
|
141
|
+
inlineSize: window.innerWidth,
|
|
142
|
+
blockSize: window.innerHeight,
|
|
140
143
|
};
|
|
141
144
|
}
|
|
142
145
|
function getDocumentRect(document) {
|
|
143
|
-
const {
|
|
146
|
+
const { insetBlockStart, insetInlineStart } = getLogicalBoundingClientRect(document.documentElement);
|
|
144
147
|
return {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
148
|
+
insetBlockStart,
|
|
149
|
+
insetInlineStart,
|
|
150
|
+
inlineSize: document.documentElement.scrollWidth,
|
|
151
|
+
blockSize: document.documentElement.scrollHeight,
|
|
149
152
|
};
|
|
150
153
|
}
|
|
151
154
|
//# sourceMappingURL=use-popover-position.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-popover-position.js","sourceRoot":"","sources":["../../../src/popover/use-popover-position.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAEtC,OAAc,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE7D,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAC1F,OAAO,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAC;AACxE,OAAO,EACL,eAAe,EACf,wBAAwB,EACxB,uBAAuB,GACxB,MAAM,yCAAyC,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAE3D,MAAM,CAAC,OAAO,UAAU,kBAAkB,CAAC,EACzC,UAAU,EACV,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,UAAU,EACV,gBAAgB,EAChB,qBAAqB,EACrB,iBAAiB,EACjB,gBAAgB,EAChB,YAAY,GAYb;IACC,MAAM,2BAA2B,GAAG,MAAM,CAA0B,IAAI,CAAC,CAAC;IAC1E,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,CAAkB,EAAE,CAAC,CAAC;IACtE,MAAM,CAAC,gBAAgB,EAAE,mBAAmB,CAAC,G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C;AAED,SAAS,eAAe,CAAC,QAAkB;IACzC,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,QAAQ,CAAC,eAAe,CAAC,qBAAqB,EAAE,CAAC;IACvE,OAAO;QACL,GAAG;QACH,IAAI;QACJ,KAAK,EAAE,QAAQ,CAAC,eAAe,CAAC,WAAW;QAC3C,MAAM,EAAE,QAAQ,CAAC,eAAe,CAAC,YAAY;KAC9C,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport React, { useCallback, useRef, useState } from 'react';\nimport { BoundingBox, InternalPosition, Offset, PopoverProps } from './interfaces';\nimport { calculatePosition, getDimensions, getOffsetDimensions } from './utils/positions';\nimport { nodeContains } from '@cloudscape-design/component-toolkit/dom';\nimport {\n calculateScroll,\n getFirstScrollableParent,\n scrollRectangleIntoView,\n} from '../internal/utils/scrollable-containers';\nimport { getContainingBlock } from '../internal/utils/dom';\n\nexport default function usePopoverPosition({\n popoverRef,\n bodyRef,\n arrowRef,\n trackRef,\n contentRef,\n allowScrollToFit,\n allowVerticalOverflow,\n preferredPosition,\n renderWithPortal,\n keepPosition,\n}: {\n popoverRef: React.RefObject<HTMLDivElement | null>;\n bodyRef: React.RefObject<HTMLDivElement | null>;\n arrowRef: React.RefObject<HTMLDivElement | null>;\n trackRef: React.RefObject<Element | null>;\n contentRef: React.RefObject<HTMLDivElement | null>;\n allowScrollToFit?: boolean;\n allowVerticalOverflow?: boolean;\n preferredPosition: PopoverProps.Position;\n renderWithPortal?: boolean;\n keepPosition?: boolean;\n}) {\n const previousInternalPositionRef = useRef<InternalPosition | null>(null);\n const [popoverStyle, setPopoverStyle] = useState<Partial<Offset>>({});\n const [internalPosition, setInternalPosition] = useState<InternalPosition | null>(null);\n\n // Store the handler in a ref so that it can still be replaced from outside of the listener closure.\n const positionHandlerRef = useRef<() => void>(() => {});\n\n const updatePositionHandler = useCallback(\n (onContentResize = false) => {\n if (!trackRef.current || !popoverRef.current || !bodyRef.current || !contentRef.current || !arrowRef.current) {\n return;\n }\n\n // Get important elements\n const popover = popoverRef.current;\n const body = bodyRef.current;\n const arrow = arrowRef.current;\n const document = popover.ownerDocument;\n const track = trackRef.current;\n\n // If the popover body isn't being rendered for whatever reason (e.g. \"display: none\" or JSDOM),\n // or track does not belong to the document - bail on calculating dimensions.\n const { offsetWidth, offsetHeight } = getOffsetDimensions(popover);\n if (offsetWidth === 0 || offsetHeight === 0 || !nodeContains(document.body, track)) {\n return;\n }\n\n // Imperatively move body off-screen to give it room to expand.\n // Not doing this in React because this recalculation should happen\n // in the span of a single frame without rerendering anything.\n const prevTop = popover.style.top;\n const prevLeft = popover.style.left;\n\n popover.style.top = '0';\n popover.style.left = '0';\n // Imperatively remove body styles that can remain from the previous computation.\n body.style.maxHeight = '';\n body.style.overflowX = '';\n body.style.overflowY = '';\n\n // Get rects representing key elements\n // Use getComputedStyle for arrowRect to avoid modifications made by transform\n const viewportRect = getViewportRect(document.defaultView!);\n const trackRect = track.getBoundingClientRect();\n const arrowRect = getDimensions(arrow);\n const containingBlock = getContainingBlock(popover);\n const containingBlockRect = containingBlock ? containingBlock.getBoundingClientRect() : viewportRect;\n\n const bodyBorderWidth = getBorderWidth(body);\n const contentRect = contentRef.current.getBoundingClientRect();\n const contentBoundingBox = {\n width: contentRect.width + 2 * bodyBorderWidth,\n height: contentRect.height + 2 * bodyBorderWidth,\n };\n\n // When keepPosition is true and the recalculation was triggered by a resize of the popover content,\n // we maintain the previously defined internal position,\n // but we still call calculatePosition to know if the popover should be scrollable.\n const shouldKeepPosition = keepPosition && onContentResize && !!previousInternalPositionRef.current;\n const fixedInternalPosition = (shouldKeepPosition && previousInternalPositionRef.current) ?? undefined;\n\n // Calculate the arrow direction and viewport-relative position of the popover.\n const {\n scrollable,\n internalPosition: newInternalPosition,\n rect,\n } = calculatePosition({\n preferredPosition,\n fixedInternalPosition,\n trigger: trackRect,\n arrow: arrowRect,\n body: contentBoundingBox,\n container: containingBlock ? containingBlockRect : getDocumentRect(document),\n viewport: viewportRect,\n renderWithPortal,\n allowVerticalOverflow,\n });\n\n // Get the position of the popover relative to the offset parent.\n const popoverOffset = toRelativePosition(rect, containingBlockRect);\n\n // Cache the distance between the trigger and the popover (which stays the same as you scroll),\n // and use that to recalculate the new popover position.\n const trackRelativeOffset = toRelativePosition(popoverOffset, toRelativePosition(trackRect, containingBlockRect));\n\n // Bring back the container to its original position to prevent any flashing.\n popover.style.top = prevTop;\n popover.style.left = prevLeft;\n\n // Allow popover body to scroll if can't fit the popover into the container/viewport otherwise.\n if (scrollable) {\n body.style.maxHeight = rect.height + 'px';\n body.style.overflowX = 'hidden';\n body.style.overflowY = 'auto';\n }\n\n // Remember the internal position in case we want to keep it later.\n previousInternalPositionRef.current = newInternalPosition;\n setInternalPosition(newInternalPosition);\n\n const shouldScroll = allowScrollToFit && !shouldKeepPosition;\n\n // Position the popover\n const top = shouldScroll ? popoverOffset.top + calculateScroll(rect) : popoverOffset.top;\n setPopoverStyle({ top, left: popoverOffset.left });\n\n // Scroll if necessary\n if (shouldScroll) {\n const scrollableParent = getFirstScrollableParent(popover);\n scrollRectangleIntoView(rect, scrollableParent);\n }\n\n positionHandlerRef.current = () => {\n const newTrackOffset = toRelativePosition(\n track.getBoundingClientRect(),\n containingBlock ? containingBlock.getBoundingClientRect() : viewportRect\n );\n setPopoverStyle({\n top: newTrackOffset.top + trackRelativeOffset.top,\n left: newTrackOffset.left + trackRelativeOffset.left,\n });\n };\n },\n [\n trackRef,\n popoverRef,\n bodyRef,\n contentRef,\n arrowRef,\n keepPosition,\n allowScrollToFit,\n preferredPosition,\n renderWithPortal,\n allowVerticalOverflow,\n ]\n );\n return { updatePositionHandler, popoverStyle, internalPosition, positionHandlerRef };\n}\n\nfunction getBorderWidth(element: HTMLElement) {\n return parseInt(getComputedStyle(element).borderWidth) || 0;\n}\n\n/**\n * Convert a viewport-relative offset to an element-relative offset.\n */\nfunction toRelativePosition(element: Offset, parent: Offset): Offset {\n return {\n top: element.top - parent.top,\n left: element.left - parent.left,\n };\n}\n\n/**\n * Get a BoundingBox that represents the visible viewport.\n */\nfunction getViewportRect(window: Window): BoundingBox {\n return {\n top: 0,\n left: 0,\n width: window.innerWidth,\n height: window.innerHeight,\n };\n}\n\nfunction getDocumentRect(document: Document): BoundingBox {\n const { top, left } = document.documentElement.getBoundingClientRect();\n return {\n top,\n left,\n width: document.documentElement.scrollWidth,\n height: document.documentElement.scrollHeight,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"use-popover-position.js","sourceRoot":"","sources":["../../../src/popover/use-popover-position.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAEtC,OAAc,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAE7D,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAC1F,OAAO,EAAE,YAAY,EAAE,MAAM,0CAA0C,CAAC;AACxE,OAAO,EACL,eAAe,EACf,wBAAwB,EACxB,uBAAuB,GACxB,MAAM,yCAAyC,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAC3D,OAAO,EAAE,4BAA4B,EAAE,MAAM,uBAAuB,CAAC;AAErE,MAAM,CAAC,OAAO,UAAU,kBAAkB,CAAC,EACzC,UAAU,EACV,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,UAAU,EACV,gBAAgB,EAChB,qBAAqB,EACrB,iBAAiB,EACjB,gBAAgB,EAChB,YAAY,GAYb;IACC,MAAM,2BAA2B,GAAG,MAAM,CAA0B,IAAI,CAAC,CAAC;IAC1E,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,CAAkB,EAAE,CAAC,CAAC;IACtE,MAAM,CAAC,gBAAgB,EAAE,mBAAmB,CAAC,GAAG,QAAQ,CAA0B,IAAI,CAAC,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,CAAC;AAED,SAAS,eAAe,CAAC,QAAkB;IACzC,MAAM,EAAE,eAAe,EAAE,gBAAgB,EAAE,GAAG,4BAA4B,CAAC,QAAQ,CAAC,eAAe,CAAC,CAAC;IAErG,OAAO;QACL,eAAe;QACf,gBAAgB;QAChB,UAAU,EAAE,QAAQ,CAAC,eAAe,CAAC,WAAW;QAChD,SAAS,EAAE,QAAQ,CAAC,eAAe,CAAC,YAAY;KACjD,CAAC;AACJ,CAAC","sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport React, { useCallback, useRef, useState } from 'react';\nimport { BoundingBox, InternalPosition, Offset, PopoverProps } from './interfaces';\nimport { calculatePosition, getDimensions, getOffsetDimensions } from './utils/positions';\nimport { nodeContains } from '@cloudscape-design/component-toolkit/dom';\nimport {\n calculateScroll,\n getFirstScrollableParent,\n scrollRectangleIntoView,\n} from '../internal/utils/scrollable-containers';\nimport { getContainingBlock } from '../internal/utils/dom';\nimport { getLogicalBoundingClientRect } from '../internal/direction';\n\nexport default function usePopoverPosition({\n popoverRef,\n bodyRef,\n arrowRef,\n trackRef,\n contentRef,\n allowScrollToFit,\n allowVerticalOverflow,\n preferredPosition,\n renderWithPortal,\n keepPosition,\n}: {\n popoverRef: React.RefObject<HTMLDivElement | null>;\n bodyRef: React.RefObject<HTMLDivElement | null>;\n arrowRef: React.RefObject<HTMLDivElement | null>;\n trackRef: React.RefObject<HTMLElement | SVGElement | null>;\n contentRef: React.RefObject<HTMLDivElement | null>;\n allowScrollToFit?: boolean;\n allowVerticalOverflow?: boolean;\n preferredPosition: PopoverProps.Position;\n renderWithPortal?: boolean;\n keepPosition?: boolean;\n}) {\n const previousInternalPositionRef = useRef<InternalPosition | null>(null);\n const [popoverStyle, setPopoverStyle] = useState<Partial<Offset>>({});\n const [internalPosition, setInternalPosition] = useState<InternalPosition | null>(null);\n\n // Store the handler in a ref so that it can still be replaced from outside of the listener closure.\n const positionHandlerRef = useRef<() => void>(() => {});\n\n const updatePositionHandler = useCallback(\n (onContentResize = false) => {\n if (!trackRef.current || !popoverRef.current || !bodyRef.current || !contentRef.current || !arrowRef.current) {\n return;\n }\n\n // Get important elements\n const popover = popoverRef.current;\n const body = bodyRef.current;\n const arrow = arrowRef.current;\n const document = popover.ownerDocument;\n const track = trackRef.current;\n\n // If the popover body isn't being rendered for whatever reason (e.g. \"display: none\" or JSDOM),\n // or track does not belong to the document - bail on calculating dimensions.\n const { offsetWidth, offsetHeight } = getOffsetDimensions(popover);\n if (offsetWidth === 0 || offsetHeight === 0 || !nodeContains(document.body, track)) {\n return;\n }\n\n // Imperatively move body off-screen to give it room to expand.\n // Not doing this in React because this recalculation should happen\n // in the span of a single frame without rerendering anything.\n const prevInsetBlockStart = popover.style.insetBlockStart;\n const prevInsetInlineStart = popover.style.insetInlineStart;\n\n popover.style.insetBlockStart = '0';\n popover.style.insetInlineStart = '0';\n // Imperatively remove body styles that can remain from the previous computation.\n body.style.maxBlockSize = '';\n body.style.overflowX = '';\n body.style.overflowY = '';\n\n // Get rects representing key elements\n // Use getComputedStyle for arrowRect to avoid modifications made by transform\n const viewportRect = getViewportRect(document.defaultView!);\n const trackRect = getLogicalBoundingClientRect(track);\n const arrowRect = getDimensions(arrow);\n const containingBlock = getContainingBlock(popover);\n const containingBlockRect = containingBlock ? getLogicalBoundingClientRect(containingBlock) : viewportRect;\n\n const bodyBorderWidth = getBorderWidth(body);\n const contentRect = getLogicalBoundingClientRect(contentRef.current);\n const contentBoundingBox = {\n inlineSize: contentRect.inlineSize + 2 * bodyBorderWidth,\n blockSize: contentRect.blockSize + 2 * bodyBorderWidth,\n };\n\n // When keepPosition is true and the recalculation was triggered by a resize of the popover content,\n // we maintain the previously defined internal position,\n // but we still call calculatePosition to know if the popover should be scrollable.\n const shouldKeepPosition = keepPosition && onContentResize && !!previousInternalPositionRef.current;\n const fixedInternalPosition = (shouldKeepPosition && previousInternalPositionRef.current) ?? undefined;\n\n // Calculate the arrow direction and viewport-relative position of the popover.\n const {\n scrollable,\n internalPosition: newInternalPosition,\n rect,\n } = calculatePosition({\n preferredPosition,\n fixedInternalPosition,\n trigger: trackRect,\n arrow: arrowRect,\n body: contentBoundingBox,\n container: containingBlock ? containingBlockRect : getDocumentRect(document),\n viewport: viewportRect,\n renderWithPortal,\n allowVerticalOverflow,\n });\n\n // Get the position of the popover relative to the offset parent.\n const popoverOffset = toRelativePosition(rect, containingBlockRect);\n\n // Cache the distance between the trigger and the popover (which stays the same as you scroll),\n // and use that to recalculate the new popover position.\n const trackRelativeOffset = toRelativePosition(popoverOffset, toRelativePosition(trackRect, containingBlockRect));\n\n // Bring back the container to its original position to prevent any flashing.\n popover.style.insetBlockStart = prevInsetBlockStart;\n popover.style.insetInlineStart = prevInsetInlineStart;\n\n // Allow popover body to scroll if can't fit the popover into the container/viewport otherwise.\n if (scrollable) {\n body.style.maxBlockSize = rect.blockSize + 'px';\n body.style.overflowX = 'hidden';\n body.style.overflowY = 'auto';\n }\n\n // Remember the internal position in case we want to keep it later.\n previousInternalPositionRef.current = newInternalPosition;\n setInternalPosition(newInternalPosition);\n\n const shouldScroll = allowScrollToFit && !shouldKeepPosition;\n\n // Position the popover\n const insetBlockStart = shouldScroll\n ? popoverOffset.insetBlockStart + calculateScroll(rect)\n : popoverOffset.insetBlockStart;\n setPopoverStyle({ insetBlockStart, insetInlineStart: popoverOffset.insetInlineStart });\n\n // Scroll if necessary\n if (shouldScroll) {\n const scrollableParent = getFirstScrollableParent(popover);\n scrollRectangleIntoView(rect, scrollableParent);\n }\n\n positionHandlerRef.current = () => {\n const newTrackOffset = toRelativePosition(\n getLogicalBoundingClientRect(track),\n containingBlock ? getLogicalBoundingClientRect(containingBlock) : viewportRect\n );\n setPopoverStyle({\n insetBlockStart: newTrackOffset.insetBlockStart + trackRelativeOffset.insetBlockStart,\n insetInlineStart: newTrackOffset.insetInlineStart + trackRelativeOffset.insetInlineStart,\n });\n };\n },\n [\n trackRef,\n popoverRef,\n bodyRef,\n contentRef,\n arrowRef,\n keepPosition,\n allowScrollToFit,\n preferredPosition,\n renderWithPortal,\n allowVerticalOverflow,\n ]\n );\n return { updatePositionHandler, popoverStyle, internalPosition, positionHandlerRef };\n}\n\nfunction getBorderWidth(element: HTMLElement) {\n return parseInt(getComputedStyle(element).borderWidth) || 0;\n}\n\n/**\n * Convert a viewport-relative offset to an element-relative offset.\n */\nfunction toRelativePosition(element: Offset, parent: Offset): Offset {\n return {\n insetBlockStart: element.insetBlockStart - parent.insetBlockStart,\n insetInlineStart: element.insetInlineStart - parent.insetInlineStart,\n };\n}\n\n/**\n * Get a BoundingBox that represents the visible viewport.\n */\nfunction getViewportRect(window: Window): BoundingBox {\n return {\n insetBlockStart: 0,\n insetInlineStart: 0,\n inlineSize: window.innerWidth,\n blockSize: window.innerHeight,\n };\n}\n\nfunction getDocumentRect(document: Document): BoundingBox {\n const { insetBlockStart, insetInlineStart } = getLogicalBoundingClientRect(document.documentElement);\n\n return {\n insetBlockStart,\n insetInlineStart,\n inlineSize: document.documentElement.scrollWidth,\n blockSize: document.documentElement.scrollHeight,\n };\n}\n"]}
|
|
@@ -28,8 +28,8 @@ export declare function getOffsetDimensions(element: HTMLElement): {
|
|
|
28
28
|
offsetWidth: number;
|
|
29
29
|
};
|
|
30
30
|
export declare function getDimensions(element: HTMLElement): {
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
inlineSize: number;
|
|
32
|
+
blockSize: number;
|
|
33
33
|
};
|
|
34
34
|
export {};
|
|
35
35
|
//# sourceMappingURL=positions.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"positions.d.ts","sourceRoot":"","sources":["../../../../src/popover/utils/positions.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAGxF,UAAU,kBAAkB;IAC1B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,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AAED,wBAAgB,aAAa,CAAC,OAAO,EAAE,WAAW;;;EAMjD"}
|
|
@@ -52,109 +52,109 @@ export const PRIORITY_MAPPING = {
|
|
|
52
52
|
const RECTANGLE_CALCULATIONS = {
|
|
53
53
|
'top-center': ({ body, trigger, arrow }) => {
|
|
54
54
|
return {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
insetBlockStart: trigger.insetBlockStart - body.blockSize - arrow.blockSize,
|
|
56
|
+
insetInlineStart: trigger.insetInlineStart + trigger.inlineSize / 2 - body.inlineSize / 2,
|
|
57
|
+
inlineSize: body.inlineSize,
|
|
58
|
+
blockSize: body.blockSize,
|
|
59
59
|
};
|
|
60
60
|
},
|
|
61
61
|
'top-right': ({ body, trigger, arrow }) => {
|
|
62
62
|
return {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
insetBlockStart: trigger.insetBlockStart - body.blockSize - arrow.blockSize,
|
|
64
|
+
insetInlineStart: trigger.insetInlineStart + trigger.inlineSize / 2 - ARROW_OFFSET - arrow.inlineSize / 2,
|
|
65
|
+
inlineSize: body.inlineSize,
|
|
66
|
+
blockSize: body.blockSize,
|
|
67
67
|
};
|
|
68
68
|
},
|
|
69
69
|
'top-left': ({ body, trigger, arrow }) => {
|
|
70
70
|
return {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
71
|
+
insetBlockStart: trigger.insetBlockStart - body.blockSize - arrow.blockSize,
|
|
72
|
+
insetInlineStart: trigger.insetInlineStart + trigger.inlineSize / 2 + ARROW_OFFSET + arrow.inlineSize / 2 - body.inlineSize,
|
|
73
|
+
inlineSize: body.inlineSize,
|
|
74
|
+
blockSize: body.blockSize,
|
|
75
75
|
};
|
|
76
76
|
},
|
|
77
77
|
'bottom-center': ({ body, trigger, arrow }) => {
|
|
78
78
|
return {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
79
|
+
insetBlockStart: trigger.insetBlockStart + trigger.blockSize + arrow.blockSize,
|
|
80
|
+
insetInlineStart: trigger.insetInlineStart + trigger.inlineSize / 2 - body.inlineSize / 2,
|
|
81
|
+
inlineSize: body.inlineSize,
|
|
82
|
+
blockSize: body.blockSize,
|
|
83
83
|
};
|
|
84
84
|
},
|
|
85
85
|
'bottom-right': ({ body, trigger, arrow }) => {
|
|
86
86
|
return {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
87
|
+
insetBlockStart: trigger.insetBlockStart + trigger.blockSize + arrow.blockSize,
|
|
88
|
+
insetInlineStart: trigger.insetInlineStart + trigger.inlineSize / 2 - ARROW_OFFSET - arrow.inlineSize / 2,
|
|
89
|
+
inlineSize: body.inlineSize,
|
|
90
|
+
blockSize: body.blockSize,
|
|
91
91
|
};
|
|
92
92
|
},
|
|
93
93
|
'bottom-left': ({ body, trigger, arrow }) => {
|
|
94
94
|
return {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
95
|
+
insetBlockStart: trigger.insetBlockStart + trigger.blockSize + arrow.blockSize,
|
|
96
|
+
insetInlineStart: trigger.insetInlineStart + trigger.inlineSize / 2 + ARROW_OFFSET + arrow.inlineSize / 2 - body.inlineSize,
|
|
97
|
+
inlineSize: body.inlineSize,
|
|
98
|
+
blockSize: body.blockSize,
|
|
99
99
|
};
|
|
100
100
|
},
|
|
101
101
|
'right-top': ({ body, trigger, arrow }) => {
|
|
102
102
|
return {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
103
|
+
insetBlockStart: trigger.insetBlockStart + trigger.blockSize / 2 - ARROW_OFFSET - arrow.blockSize,
|
|
104
|
+
insetInlineStart: trigger.insetInlineStart + trigger.inlineSize + arrow.blockSize,
|
|
105
|
+
inlineSize: body.inlineSize,
|
|
106
|
+
blockSize: body.blockSize,
|
|
107
107
|
};
|
|
108
108
|
},
|
|
109
109
|
'right-bottom': ({ body, trigger, arrow }) => {
|
|
110
110
|
return {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
111
|
+
insetBlockStart: trigger.insetBlockStart + trigger.blockSize / 2 - body.blockSize + ARROW_OFFSET + arrow.blockSize,
|
|
112
|
+
insetInlineStart: trigger.insetInlineStart + trigger.inlineSize + arrow.blockSize,
|
|
113
|
+
inlineSize: body.inlineSize,
|
|
114
|
+
blockSize: body.blockSize,
|
|
115
115
|
};
|
|
116
116
|
},
|
|
117
117
|
'left-top': ({ body, trigger, arrow }) => {
|
|
118
118
|
return {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
119
|
+
insetBlockStart: trigger.insetBlockStart + trigger.blockSize / 2 - ARROW_OFFSET - arrow.blockSize,
|
|
120
|
+
insetInlineStart: trigger.insetInlineStart - body.inlineSize - arrow.blockSize,
|
|
121
|
+
inlineSize: body.inlineSize,
|
|
122
|
+
blockSize: body.blockSize,
|
|
123
123
|
};
|
|
124
124
|
},
|
|
125
125
|
'left-bottom': ({ body, trigger, arrow }) => {
|
|
126
126
|
return {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
127
|
+
insetBlockStart: trigger.insetBlockStart + trigger.blockSize / 2 - body.blockSize + ARROW_OFFSET + arrow.blockSize,
|
|
128
|
+
insetInlineStart: trigger.insetInlineStart - body.inlineSize - arrow.blockSize,
|
|
129
|
+
inlineSize: body.inlineSize,
|
|
130
|
+
blockSize: body.blockSize,
|
|
131
131
|
};
|
|
132
132
|
},
|
|
133
133
|
};
|
|
134
134
|
function fitIntoContainer(inner, outer) {
|
|
135
|
-
let {
|
|
135
|
+
let { insetInlineStart, inlineSize, insetBlockStart, blockSize } = inner;
|
|
136
136
|
// Adjust left boundary.
|
|
137
|
-
if (
|
|
138
|
-
|
|
139
|
-
|
|
137
|
+
if (insetInlineStart < outer.insetInlineStart) {
|
|
138
|
+
inlineSize = insetInlineStart + inlineSize - outer.insetInlineStart;
|
|
139
|
+
insetInlineStart = outer.insetInlineStart;
|
|
140
140
|
}
|
|
141
141
|
// Adjust right boundary.
|
|
142
|
-
else if (
|
|
143
|
-
|
|
142
|
+
else if (insetInlineStart + inlineSize > outer.insetInlineStart + outer.inlineSize) {
|
|
143
|
+
inlineSize = outer.insetInlineStart + outer.inlineSize - insetInlineStart;
|
|
144
144
|
}
|
|
145
145
|
// Adjust top boundary.
|
|
146
|
-
if (
|
|
147
|
-
|
|
148
|
-
|
|
146
|
+
if (insetBlockStart < outer.insetBlockStart) {
|
|
147
|
+
blockSize = insetBlockStart + blockSize - outer.insetBlockStart;
|
|
148
|
+
insetBlockStart = outer.insetBlockStart;
|
|
149
149
|
}
|
|
150
150
|
// Adjust bottom boundary.
|
|
151
|
-
else if (
|
|
152
|
-
|
|
151
|
+
else if (insetBlockStart + blockSize > outer.insetBlockStart + outer.blockSize) {
|
|
152
|
+
blockSize = outer.insetBlockStart + outer.blockSize - insetBlockStart;
|
|
153
153
|
}
|
|
154
|
-
return {
|
|
154
|
+
return { insetInlineStart, inlineSize, insetBlockStart, blockSize };
|
|
155
155
|
}
|
|
156
156
|
function getTallestRect(rect1, rect2) {
|
|
157
|
-
return rect1.
|
|
157
|
+
return rect1.blockSize >= rect2.blockSize ? rect1 : rect2;
|
|
158
158
|
}
|
|
159
159
|
function getIntersection(rectangles) {
|
|
160
160
|
let boundingBox = null;
|
|
@@ -163,18 +163,18 @@ function getIntersection(rectangles) {
|
|
|
163
163
|
boundingBox = currentRect;
|
|
164
164
|
continue;
|
|
165
165
|
}
|
|
166
|
-
const
|
|
167
|
-
const
|
|
168
|
-
const
|
|
169
|
-
const
|
|
170
|
-
if (
|
|
166
|
+
const insetInlineStart = Math.max(boundingBox.insetInlineStart, currentRect.insetInlineStart);
|
|
167
|
+
const insetBlockStart = Math.max(boundingBox.insetBlockStart, currentRect.insetBlockStart);
|
|
168
|
+
const insetInlineEnd = Math.min(boundingBox.insetInlineStart + boundingBox.inlineSize, currentRect.insetInlineStart + currentRect.inlineSize);
|
|
169
|
+
const insetBlockEnd = Math.min(boundingBox.insetBlockStart + boundingBox.blockSize, currentRect.insetBlockStart + currentRect.blockSize);
|
|
170
|
+
if (insetInlineEnd < insetInlineStart || insetBlockEnd < insetBlockStart) {
|
|
171
171
|
return null;
|
|
172
172
|
}
|
|
173
173
|
boundingBox = {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
174
|
+
insetInlineStart,
|
|
175
|
+
insetBlockStart,
|
|
176
|
+
inlineSize: insetInlineEnd - insetInlineStart,
|
|
177
|
+
blockSize: insetBlockEnd - insetBlockStart,
|
|
178
178
|
};
|
|
179
179
|
}
|
|
180
180
|
return boundingBox;
|
|
@@ -184,7 +184,7 @@ function getIntersection(rectangles) {
|
|
|
184
184
|
*/
|
|
185
185
|
export function intersectRectangles(rectangles) {
|
|
186
186
|
const boundingBox = getIntersection(rectangles);
|
|
187
|
-
return boundingBox && boundingBox.
|
|
187
|
+
return boundingBox && boundingBox.blockSize * boundingBox.inlineSize;
|
|
188
188
|
}
|
|
189
189
|
/**
|
|
190
190
|
* A functions that returns the correct popover position based on screen dimensions.
|
|
@@ -203,7 +203,7 @@ renderWithPortal, allowVerticalOverflow, }) {
|
|
|
203
203
|
const visibleArea = renderWithPortal
|
|
204
204
|
? getIntersection([rect, viewport])
|
|
205
205
|
: getIntersection([rect, viewport, container]);
|
|
206
|
-
const fitsWithoutOverflow = visibleArea && visibleArea.
|
|
206
|
+
const fitsWithoutOverflow = visibleArea && visibleArea.inlineSize === body.inlineSize && visibleArea.blockSize === body.blockSize;
|
|
207
207
|
if (fitsWithoutOverflow) {
|
|
208
208
|
return { internalPosition, rect };
|
|
209
209
|
}
|
|
@@ -220,15 +220,15 @@ renderWithPortal, allowVerticalOverflow, }) {
|
|
|
220
220
|
const tallestBoundingContainer = getTallestRect(viewport, container);
|
|
221
221
|
const boundingContainer = allowVerticalOverflow && isTopOrBottom(internalPosition)
|
|
222
222
|
? {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
223
|
+
insetBlockStart: tallestBoundingContainer.insetBlockStart,
|
|
224
|
+
blockSize: tallestBoundingContainer.blockSize,
|
|
225
|
+
insetInlineStart: viewport.insetInlineStart,
|
|
226
|
+
inlineSize: viewport.inlineSize,
|
|
227
227
|
}
|
|
228
228
|
: viewport;
|
|
229
229
|
const optimizedRect = fitIntoContainer(rect, boundingContainer);
|
|
230
230
|
// If largest possible rect is shorter than original - set body scroll.
|
|
231
|
-
const scrollable = optimizedRect.
|
|
231
|
+
const scrollable = optimizedRect.blockSize < rect.blockSize;
|
|
232
232
|
return { internalPosition, rect: optimizedRect, scrollable };
|
|
233
233
|
}
|
|
234
234
|
function getBestOption(option1, option2) {
|
|
@@ -241,11 +241,11 @@ function getBestOption(option1, option2) {
|
|
|
241
241
|
return option2;
|
|
242
242
|
}
|
|
243
243
|
// Only if none of the two options overflows horizontally, choose the best based on the visible height.
|
|
244
|
-
if (option1.visibleArea.
|
|
245
|
-
return option1.visibleArea.
|
|
244
|
+
if (option1.visibleArea.inlineSize === option2.visibleArea.inlineSize) {
|
|
245
|
+
return option1.visibleArea.blockSize > option2.visibleArea.blockSize ? option1 : option2;
|
|
246
246
|
}
|
|
247
247
|
// Otherwise, choose the option that is less cut off horizontally.
|
|
248
|
-
return option1.visibleArea.
|
|
248
|
+
return option1.visibleArea.inlineSize > option2.visibleArea.inlineSize ? option1 : option2;
|
|
249
249
|
}
|
|
250
250
|
export function getOffsetDimensions(element) {
|
|
251
251
|
return { offsetHeight: element.offsetHeight, offsetWidth: element.offsetWidth };
|
|
@@ -253,8 +253,8 @@ export function getOffsetDimensions(element) {
|
|
|
253
253
|
export function getDimensions(element) {
|
|
254
254
|
const computedStyle = getComputedStyle(element);
|
|
255
255
|
return {
|
|
256
|
-
|
|
257
|
-
|
|
256
|
+
inlineSize: parseFloat(computedStyle.inlineSize),
|
|
257
|
+
blockSize: parseFloat(computedStyle.blockSize),
|
|
258
258
|
};
|
|
259
259
|
}
|
|
260
260
|
function isTopOrBottom(internalPosition) {
|