1 | import { top, bottom, left, right } from "../enums.js";
|
---|
2 | import detectOverflow from "../utils/detectOverflow.js";
|
---|
3 |
|
---|
4 | function getSideOffsets(overflow, rect, preventedOffsets) {
|
---|
5 | if (preventedOffsets === void 0) {
|
---|
6 | preventedOffsets = {
|
---|
7 | x: 0,
|
---|
8 | y: 0
|
---|
9 | };
|
---|
10 | }
|
---|
11 |
|
---|
12 | return {
|
---|
13 | top: overflow.top - rect.height - preventedOffsets.y,
|
---|
14 | right: overflow.right - rect.width + preventedOffsets.x,
|
---|
15 | bottom: overflow.bottom - rect.height + preventedOffsets.y,
|
---|
16 | left: overflow.left - rect.width - preventedOffsets.x
|
---|
17 | };
|
---|
18 | }
|
---|
19 |
|
---|
20 | function isAnySideFullyClipped(overflow) {
|
---|
21 | return [top, right, bottom, left].some(function (side) {
|
---|
22 | return overflow[side] >= 0;
|
---|
23 | });
|
---|
24 | }
|
---|
25 |
|
---|
26 | function hide(_ref) {
|
---|
27 | var state = _ref.state,
|
---|
28 | name = _ref.name;
|
---|
29 | var referenceRect = state.rects.reference;
|
---|
30 | var popperRect = state.rects.popper;
|
---|
31 | var preventedOffsets = state.modifiersData.preventOverflow;
|
---|
32 | var referenceOverflow = detectOverflow(state, {
|
---|
33 | elementContext: 'reference'
|
---|
34 | });
|
---|
35 | var popperAltOverflow = detectOverflow(state, {
|
---|
36 | altBoundary: true
|
---|
37 | });
|
---|
38 | var referenceClippingOffsets = getSideOffsets(referenceOverflow, referenceRect);
|
---|
39 | var popperEscapeOffsets = getSideOffsets(popperAltOverflow, popperRect, preventedOffsets);
|
---|
40 | var isReferenceHidden = isAnySideFullyClipped(referenceClippingOffsets);
|
---|
41 | var hasPopperEscaped = isAnySideFullyClipped(popperEscapeOffsets);
|
---|
42 | state.modifiersData[name] = {
|
---|
43 | referenceClippingOffsets: referenceClippingOffsets,
|
---|
44 | popperEscapeOffsets: popperEscapeOffsets,
|
---|
45 | isReferenceHidden: isReferenceHidden,
|
---|
46 | hasPopperEscaped: hasPopperEscaped
|
---|
47 | };
|
---|
48 | state.attributes.popper = Object.assign({}, state.attributes.popper, {
|
---|
49 | 'data-popper-reference-hidden': isReferenceHidden,
|
---|
50 | 'data-popper-escaped': hasPopperEscaped
|
---|
51 | });
|
---|
52 | } // eslint-disable-next-line import/no-unused-modules
|
---|
53 |
|
---|
54 |
|
---|
55 | export default {
|
---|
56 | name: 'hide',
|
---|
57 | enabled: true,
|
---|
58 | phase: 'main',
|
---|
59 | requiresIfExists: ['preventOverflow'],
|
---|
60 | fn: hide
|
---|
61 | }; |
---|