cbvirtua 1.0.5 → 1.0.6
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/package.json +1 -1
- package/v2/App.vue +56 -0
- package/v2/components/Dropdown.vue +28 -0
- package/v2/components/Menu.vue +9 -0
- package/{floating → v2}/components/Popper.js +1 -1
- package/v2/components/PopperContent.vue +270 -0
- package/v2/components/PopperWrapper.vue +101 -0
- package/v2/components/ResizeObserver.vue +151 -0
- package/v2/components/Tooltip.vue +22 -0
- package/v2/components/TooltipDirective.vue +171 -0
- package/v2/floating-ui/core/computeCoordsFromPlacement.js +39 -0
- package/v2/floating-ui/core/computePosition.js +52 -0
- package/v2/floating-ui/core/detectOverflow.js +36 -0
- package/v2/floating-ui/core/enums.js +7 -0
- package/v2/floating-ui/core/index.js +11 -0
- package/v2/floating-ui/core/middleware/arrow.js +52 -0
- package/v2/floating-ui/core/middleware/autoPlacement.js +84 -0
- package/v2/floating-ui/core/middleware/flip.js +82 -0
- package/v2/floating-ui/core/middleware/hide.js +36 -0
- package/v2/floating-ui/core/middleware/inline.js +100 -0
- package/v2/floating-ui/core/middleware/offset.js +26 -0
- package/v2/floating-ui/core/middleware/shift.js +99 -0
- package/v2/floating-ui/core/middleware/size.js +58 -0
- package/v2/floating-ui/core/types.js +11 -0
- package/v2/floating-ui/core/utils/expandPaddingObject.js +3 -0
- package/v2/floating-ui/core/utils/getAlignment.js +3 -0
- package/v2/floating-ui/core/utils/getAlignmentSides.js +23 -0
- package/v2/floating-ui/core/utils/getBasePlacement.js +3 -0
- package/v2/floating-ui/core/utils/getCrossAxis.js +3 -0
- package/v2/floating-ui/core/utils/getExpandedPlacements.js +10 -0
- package/v2/floating-ui/core/utils/getLengthFromAxis.js +3 -0
- package/v2/floating-ui/core/utils/getMainAxisFromPlacement.js +4 -0
- package/v2/floating-ui/core/utils/getOppositeAlignmentPlacement.js +4 -0
- package/v2/floating-ui/core/utils/getOppositePlacement.js +4 -0
- package/v2/floating-ui/core/utils/getPaddingObject.js +6 -0
- package/v2/floating-ui/core/utils/math.js +2 -0
- package/v2/floating-ui/core/utils/rectToClientRect.js +9 -0
- package/v2/floating-ui/core/utils/within.js +4 -0
- package/v2/floating-ui/dom/index.js +5 -0
- package/v2/floating-ui/dom/platform.js +20 -0
- package/v2/floating-ui/dom/utils/contains.js +22 -0
- package/v2/floating-ui/dom/utils/convertOffsetParentRelativeRectToViewportRelativeRect.js +35 -0
- package/v2/floating-ui/dom/utils/getBoundingClientRect.js +27 -0
- package/v2/floating-ui/dom/utils/getClippingClientRect.js +76 -0
- package/v2/floating-ui/dom/utils/getComputedStyle.js +4 -0
- package/v2/floating-ui/dom/utils/getDimensions.js +6 -0
- package/v2/floating-ui/dom/utils/getDocumentElement.js +4 -0
- package/v2/floating-ui/dom/utils/getDocumentRect.js +21 -0
- package/v2/floating-ui/dom/utils/getNodeName.js +4 -0
- package/v2/floating-ui/dom/utils/getNodeScroll.js +13 -0
- package/v2/floating-ui/dom/utils/getOffsetParent.js +43 -0
- package/v2/floating-ui/dom/utils/getParentNode.js +16 -0
- package/v2/floating-ui/dom/utils/getRectRelativeToOffsetParent.js +40 -0
- package/v2/floating-ui/dom/utils/getScrollParent.js +13 -0
- package/v2/floating-ui/dom/utils/getScrollParents.js +18 -0
- package/v2/floating-ui/dom/utils/getViewportRect.js +25 -0
- package/v2/floating-ui/dom/utils/getWindowScrollBarX.js +9 -0
- package/v2/floating-ui/dom/utils/is.js +38 -0
- package/v2/floating-ui/dom/utils/math.js +3 -0
- package/v2/floating-ui/dom/utils/window.js +13 -0
- package/{floating → v2}/index.js +2 -1
- package/floating/demo/TestDropdown.vue +0 -22
- package/floating/demo/TestSubMenu.vue +0 -87
- package/floating/demo/TestTooltip.vue +0 -19
- package/floating/directives/v-tooltip.spec.js +0 -28
- /package/{floating → v2}/components/PopperMethods.js +0 -0
- /package/{floating → v2}/components/ThemeClass.js +0 -0
- /package/{floating → v2}/config.js +0 -0
- /package/{floating → v2}/directives/v-close-popper.js +0 -0
- /package/{floating → v2}/directives/v-tooltip.js +0 -0
- /package/{floating → v2}/util/assign-deep.js +0 -0
- /package/{floating → v2}/util/env.js +0 -0
- /package/{floating → v2}/util/events.js +0 -0
- /package/{floating → v2}/util/frame.js +0 -0
- /package/{floating → v2}/util/lang.js +0 -0
- /package/{floating → v2}/util/popper.js +0 -0
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<Popper
|
|
3
|
+
ref="popper"
|
|
4
|
+
v-slot="{
|
|
5
|
+
popperId,
|
|
6
|
+
isShown,
|
|
7
|
+
shouldMountContent,
|
|
8
|
+
skipTransition,
|
|
9
|
+
autoHide,
|
|
10
|
+
hide,
|
|
11
|
+
handleResize,
|
|
12
|
+
onResize,
|
|
13
|
+
classes,
|
|
14
|
+
result,
|
|
15
|
+
}"
|
|
16
|
+
v-bind="$attrs"
|
|
17
|
+
:theme="theme"
|
|
18
|
+
:popper-node="() => $refs.popperContent.$el"
|
|
19
|
+
v-on="$listeners"
|
|
20
|
+
@apply-show="onShow"
|
|
21
|
+
@apply-hide="onHide"
|
|
22
|
+
>
|
|
23
|
+
<PopperContent
|
|
24
|
+
ref="popperContent"
|
|
25
|
+
:class="{
|
|
26
|
+
'v-popper--tooltip-loading': loading,
|
|
27
|
+
}"
|
|
28
|
+
:popper-id="popperId"
|
|
29
|
+
:theme="theme"
|
|
30
|
+
:shown="isShown"
|
|
31
|
+
:mounted="shouldMountContent"
|
|
32
|
+
:skip-transition="skipTransition"
|
|
33
|
+
:auto-hide="autoHide"
|
|
34
|
+
:handle-resize="handleResize"
|
|
35
|
+
:classes="classes"
|
|
36
|
+
:result="result"
|
|
37
|
+
@hide="hide"
|
|
38
|
+
@resize="onResize"
|
|
39
|
+
>
|
|
40
|
+
<div
|
|
41
|
+
v-if="html"
|
|
42
|
+
v-html="finalContent"
|
|
43
|
+
/>
|
|
44
|
+
<div
|
|
45
|
+
v-else
|
|
46
|
+
v-text="finalContent"
|
|
47
|
+
/>
|
|
48
|
+
</PopperContent>
|
|
49
|
+
</Popper>
|
|
50
|
+
</template>
|
|
51
|
+
|
|
52
|
+
<script lang="ts">
|
|
53
|
+
import Popper from './Popper'
|
|
54
|
+
import PopperContent from './PopperContent.vue'
|
|
55
|
+
import { getDefaultConfig } from '../config'
|
|
56
|
+
import PopperMethods from './PopperMethods'
|
|
57
|
+
|
|
58
|
+
export default {
|
|
59
|
+
name: 'VTooltipDirective',
|
|
60
|
+
|
|
61
|
+
components: {
|
|
62
|
+
Popper: Popper(),
|
|
63
|
+
PopperContent,
|
|
64
|
+
},
|
|
65
|
+
|
|
66
|
+
mixins: [
|
|
67
|
+
PopperMethods,
|
|
68
|
+
],
|
|
69
|
+
|
|
70
|
+
inheritAttrs: false,
|
|
71
|
+
|
|
72
|
+
props: {
|
|
73
|
+
theme: {
|
|
74
|
+
type: String,
|
|
75
|
+
default: 'tooltip',
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
html: {
|
|
79
|
+
type: Boolean,
|
|
80
|
+
default () {
|
|
81
|
+
return getDefaultConfig(this.theme, 'html')
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
|
|
85
|
+
content: {
|
|
86
|
+
type: [String, Number, Function],
|
|
87
|
+
default: null,
|
|
88
|
+
},
|
|
89
|
+
|
|
90
|
+
loadingContent: {
|
|
91
|
+
type: String,
|
|
92
|
+
default () {
|
|
93
|
+
return getDefaultConfig(this.theme, 'loadingContent')
|
|
94
|
+
},
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
|
|
98
|
+
data () {
|
|
99
|
+
return {
|
|
100
|
+
asyncContent: null,
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
|
|
104
|
+
computed: {
|
|
105
|
+
isContentAsync () {
|
|
106
|
+
return typeof this.content === 'function'
|
|
107
|
+
},
|
|
108
|
+
|
|
109
|
+
loading () {
|
|
110
|
+
return this.isContentAsync && this.asyncContent == null
|
|
111
|
+
},
|
|
112
|
+
|
|
113
|
+
finalContent () {
|
|
114
|
+
if (this.isContentAsync) {
|
|
115
|
+
return this.loading ? this.loadingContent : this.asyncContent
|
|
116
|
+
}
|
|
117
|
+
return this.content
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
|
|
121
|
+
watch: {
|
|
122
|
+
content: {
|
|
123
|
+
handler () {
|
|
124
|
+
this.fetchContent(true)
|
|
125
|
+
},
|
|
126
|
+
immediate: true,
|
|
127
|
+
},
|
|
128
|
+
|
|
129
|
+
async finalContent (value) {
|
|
130
|
+
await this.$nextTick()
|
|
131
|
+
this.$refs.popper.onResize()
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
|
|
135
|
+
created () {
|
|
136
|
+
this.$_fetchId = 0
|
|
137
|
+
},
|
|
138
|
+
|
|
139
|
+
methods: {
|
|
140
|
+
fetchContent (force) {
|
|
141
|
+
if (typeof this.content === 'function' && this.$_isShown &&
|
|
142
|
+
(force || (!this.$_loading && this.asyncContent == null))) {
|
|
143
|
+
this.asyncContent = null
|
|
144
|
+
this.$_loading = true
|
|
145
|
+
const fetchId = ++this.$_fetchId
|
|
146
|
+
const result = this.content(this)
|
|
147
|
+
if (result.then) {
|
|
148
|
+
result.then(res => this.onResult(fetchId, res))
|
|
149
|
+
} else {
|
|
150
|
+
this.onResult(fetchId, result)
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
|
|
155
|
+
onResult (fetchId, result) {
|
|
156
|
+
if (fetchId !== this.$_fetchId) return
|
|
157
|
+
this.$_loading = false
|
|
158
|
+
this.asyncContent = result
|
|
159
|
+
},
|
|
160
|
+
|
|
161
|
+
onShow () {
|
|
162
|
+
this.$_isShown = true
|
|
163
|
+
this.fetchContent()
|
|
164
|
+
},
|
|
165
|
+
|
|
166
|
+
onHide () {
|
|
167
|
+
this.$_isShown = false
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
}
|
|
171
|
+
</script>
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { getBasePlacement } from './utils/getBasePlacement';
|
|
2
|
+
import { getAlignment } from './utils/getAlignment';
|
|
3
|
+
import { getMainAxisFromPlacement } from './utils/getMainAxisFromPlacement';
|
|
4
|
+
import { getLengthFromAxis } from './utils/getLengthFromAxis';
|
|
5
|
+
export function computeCoordsFromPlacement({ reference, floating, placement, }) {
|
|
6
|
+
const commonX = reference.x + reference.width / 2 - floating.width / 2;
|
|
7
|
+
const commonY = reference.y + reference.height / 2 - floating.height / 2;
|
|
8
|
+
let coords;
|
|
9
|
+
switch (getBasePlacement(placement)) {
|
|
10
|
+
case 'top':
|
|
11
|
+
coords = { x: commonX, y: reference.y - floating.height };
|
|
12
|
+
break;
|
|
13
|
+
case 'bottom':
|
|
14
|
+
coords = { x: commonX, y: reference.y + reference.height };
|
|
15
|
+
break;
|
|
16
|
+
case 'right':
|
|
17
|
+
coords = { x: reference.x + reference.width, y: commonY };
|
|
18
|
+
break;
|
|
19
|
+
case 'left':
|
|
20
|
+
coords = { x: reference.x - floating.width, y: commonY };
|
|
21
|
+
break;
|
|
22
|
+
default:
|
|
23
|
+
coords = { x: reference.x, y: reference.y };
|
|
24
|
+
}
|
|
25
|
+
const mainAxis = getMainAxisFromPlacement(placement);
|
|
26
|
+
const length = getLengthFromAxis(mainAxis);
|
|
27
|
+
switch (getAlignment(placement)) {
|
|
28
|
+
case 'start':
|
|
29
|
+
coords[mainAxis] =
|
|
30
|
+
coords[mainAxis] - (reference[length] / 2 - floating[length] / 2);
|
|
31
|
+
break;
|
|
32
|
+
case 'end':
|
|
33
|
+
coords[mainAxis] =
|
|
34
|
+
coords[mainAxis] + (reference[length] / 2 - floating[length] / 2);
|
|
35
|
+
break;
|
|
36
|
+
default:
|
|
37
|
+
}
|
|
38
|
+
return coords;
|
|
39
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { computeCoordsFromPlacement } from './computeCoordsFromPlacement';
|
|
2
|
+
export const computePosition = async (reference, floating, config) => {
|
|
3
|
+
const { placement = 'bottom', strategy = 'absolute', middleware = [], platform, } = config;
|
|
4
|
+
let rects = await platform.getElementRects({ reference, floating, strategy });
|
|
5
|
+
let { x, y } = computeCoordsFromPlacement({ ...rects, placement });
|
|
6
|
+
let statefulPlacement = placement;
|
|
7
|
+
let middlewareData = {};
|
|
8
|
+
let _debug_loop_count_ = 0;
|
|
9
|
+
for (let i = 0; i < middleware.length; i++) {
|
|
10
|
+
const { name, fn } = middleware[i];
|
|
11
|
+
const { x: nextX, y: nextY, data, reset, } = await fn({
|
|
12
|
+
x,
|
|
13
|
+
y,
|
|
14
|
+
initialPlacement: placement,
|
|
15
|
+
placement: statefulPlacement,
|
|
16
|
+
strategy,
|
|
17
|
+
middlewareData,
|
|
18
|
+
rects,
|
|
19
|
+
platform,
|
|
20
|
+
elements: { reference, floating },
|
|
21
|
+
});
|
|
22
|
+
x = nextX !== null && nextX !== void 0 ? nextX : x;
|
|
23
|
+
y = nextY !== null && nextY !== void 0 ? nextY : y;
|
|
24
|
+
middlewareData = { ...middlewareData, [name]: data !== null && data !== void 0 ? data : {} };
|
|
25
|
+
if (reset) {
|
|
26
|
+
if (typeof reset === 'object') {
|
|
27
|
+
if (reset.placement) {
|
|
28
|
+
statefulPlacement = reset.placement;
|
|
29
|
+
}
|
|
30
|
+
if (reset.rects) {
|
|
31
|
+
rects =
|
|
32
|
+
reset.rects === true
|
|
33
|
+
? await platform.getElementRects({ reference, floating, strategy })
|
|
34
|
+
: reset.rects;
|
|
35
|
+
}
|
|
36
|
+
({ x, y } = computeCoordsFromPlacement({
|
|
37
|
+
...rects,
|
|
38
|
+
placement: statefulPlacement,
|
|
39
|
+
}));
|
|
40
|
+
}
|
|
41
|
+
i = -1;
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
x,
|
|
47
|
+
y,
|
|
48
|
+
placement: statefulPlacement,
|
|
49
|
+
strategy,
|
|
50
|
+
middlewareData,
|
|
51
|
+
};
|
|
52
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { getSideObjectFromPadding } from './utils/getPaddingObject';
|
|
2
|
+
import { rectToClientRect } from './utils/rectToClientRect';
|
|
3
|
+
export async function detectOverflow(middlewareArguments, options = {}) {
|
|
4
|
+
const { x, y, platform, rects, elements, strategy } = middlewareArguments;
|
|
5
|
+
const { boundary = 'clippingParents', rootBoundary = 'viewport', elementContext = 'floating', altBoundary = false, padding = 0, } = options;
|
|
6
|
+
const paddingObject = getSideObjectFromPadding(padding);
|
|
7
|
+
const altContext = elementContext === 'floating' ? 'reference' : 'floating';
|
|
8
|
+
const element = elements[altBoundary ? altContext : elementContext];
|
|
9
|
+
const clippingClientRect = await platform.getClippingClientRect({
|
|
10
|
+
element: (await platform.isElement(element))
|
|
11
|
+
? element
|
|
12
|
+
: element.contextElement ||
|
|
13
|
+
(await platform.getDocumentElement({ element: elements.floating })),
|
|
14
|
+
boundary,
|
|
15
|
+
rootBoundary,
|
|
16
|
+
});
|
|
17
|
+
const elementClientRect = rectToClientRect(await platform.convertOffsetParentRelativeRectToViewportRelativeRect({
|
|
18
|
+
rect: elementContext === 'floating'
|
|
19
|
+
? { ...rects.floating, x, y }
|
|
20
|
+
: rects.reference,
|
|
21
|
+
offsetParent: await platform.getOffsetParent({
|
|
22
|
+
element: elements.floating,
|
|
23
|
+
}),
|
|
24
|
+
strategy,
|
|
25
|
+
}));
|
|
26
|
+
// positive = overflowing the clipping rect
|
|
27
|
+
// 0 or negative = within the clipping rect
|
|
28
|
+
return {
|
|
29
|
+
top: clippingClientRect.top - elementClientRect.top + paddingObject.top,
|
|
30
|
+
bottom: elementClientRect.bottom -
|
|
31
|
+
clippingClientRect.bottom +
|
|
32
|
+
paddingObject.bottom,
|
|
33
|
+
left: clippingClientRect.left - elementClientRect.left + paddingObject.left,
|
|
34
|
+
right: elementClientRect.right - clippingClientRect.right + paddingObject.right,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { computePosition } from './computePosition';
|
|
2
|
+
export { detectOverflow } from './detectOverflow';
|
|
3
|
+
export { arrow } from './middleware/arrow';
|
|
4
|
+
export { autoPlacement } from './middleware/autoPlacement';
|
|
5
|
+
export { flip } from './middleware/flip';
|
|
6
|
+
export { hide } from './middleware/hide';
|
|
7
|
+
export { offset } from './middleware/offset';
|
|
8
|
+
export { shift, limitShift } from './middleware/shift';
|
|
9
|
+
export { size } from './middleware/size';
|
|
10
|
+
export { inline } from './middleware/inline';
|
|
11
|
+
export { rectToClientRect } from './utils/rectToClientRect';
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { getBasePlacement } from '../utils/getBasePlacement';
|
|
2
|
+
import { getLengthFromAxis } from '../utils/getLengthFromAxis';
|
|
3
|
+
import { getMainAxisFromPlacement } from '../utils/getMainAxisFromPlacement';
|
|
4
|
+
import { getSideObjectFromPadding } from '../utils/getPaddingObject';
|
|
5
|
+
import { within } from '../utils/within';
|
|
6
|
+
export const arrow = (options) => ({
|
|
7
|
+
name: 'arrow',
|
|
8
|
+
options,
|
|
9
|
+
async fn(middlewareArguments) {
|
|
10
|
+
// Since `element` is required, we don't Partial<> the type
|
|
11
|
+
const { element, padding = 0 } = options !== null && options !== void 0 ? options : {};
|
|
12
|
+
const { x, y, placement, rects, platform } = middlewareArguments;
|
|
13
|
+
if (element == null) {
|
|
14
|
+
if (__DEV__) {
|
|
15
|
+
console.warn('Floating UI: No `element` was passed to the `arrow` middleware.');
|
|
16
|
+
}
|
|
17
|
+
return {};
|
|
18
|
+
}
|
|
19
|
+
const paddingObject = getSideObjectFromPadding(padding);
|
|
20
|
+
const coords = { x, y };
|
|
21
|
+
const basePlacement = getBasePlacement(placement);
|
|
22
|
+
const axis = getMainAxisFromPlacement(basePlacement);
|
|
23
|
+
const length = getLengthFromAxis(axis);
|
|
24
|
+
const arrowDimensions = await platform.getDimensions({ element });
|
|
25
|
+
const minProp = axis === 'y' ? 'top' : 'left';
|
|
26
|
+
const maxProp = axis === 'y' ? 'bottom' : 'right';
|
|
27
|
+
const endDiff = rects.reference[length] +
|
|
28
|
+
rects.reference[axis] -
|
|
29
|
+
coords[axis] -
|
|
30
|
+
rects.floating[length];
|
|
31
|
+
const startDiff = coords[axis] - rects.reference[axis];
|
|
32
|
+
const arrowOffsetParent = await platform.getOffsetParent({ element });
|
|
33
|
+
const clientSize = arrowOffsetParent
|
|
34
|
+
? axis === 'y'
|
|
35
|
+
? arrowOffsetParent.clientHeight || 0
|
|
36
|
+
: arrowOffsetParent.clientWidth || 0
|
|
37
|
+
: 0;
|
|
38
|
+
const centerToReference = endDiff / 2 - startDiff / 2;
|
|
39
|
+
// Make sure the arrow doesn't overflow the floating element if the center
|
|
40
|
+
// point is outside of the floating element's bounds
|
|
41
|
+
const min = paddingObject[minProp];
|
|
42
|
+
const max = clientSize - arrowDimensions[length] - paddingObject[maxProp];
|
|
43
|
+
const center = clientSize / 2 - arrowDimensions[length] / 2 + centerToReference;
|
|
44
|
+
const offset = within(min, center, max);
|
|
45
|
+
return {
|
|
46
|
+
data: {
|
|
47
|
+
[axis]: offset,
|
|
48
|
+
centerOffset: center - offset,
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
},
|
|
52
|
+
});
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { detectOverflow, } from '../detectOverflow';
|
|
2
|
+
import { getBasePlacement } from '../utils/getBasePlacement';
|
|
3
|
+
import { getAlignment } from '../utils/getAlignment';
|
|
4
|
+
import { getAlignmentSides } from '../utils/getAlignmentSides';
|
|
5
|
+
import { getOppositeAlignmentPlacement } from '../utils/getOppositeAlignmentPlacement';
|
|
6
|
+
import { allPlacements } from '../enums';
|
|
7
|
+
export function getPlacementList(alignment, autoAlignment, allowedPlacements) {
|
|
8
|
+
const allowedPlacementsSortedByAlignment = alignment
|
|
9
|
+
? [
|
|
10
|
+
...allowedPlacements.filter((placement) => getAlignment(placement) === alignment),
|
|
11
|
+
...allowedPlacements.filter((placement) => getAlignment(placement) !== alignment),
|
|
12
|
+
]
|
|
13
|
+
: allowedPlacements.filter((placement) => getBasePlacement(placement) === placement);
|
|
14
|
+
return allowedPlacementsSortedByAlignment.filter((placement) => {
|
|
15
|
+
if (alignment) {
|
|
16
|
+
return (getAlignment(placement) === alignment ||
|
|
17
|
+
(autoAlignment
|
|
18
|
+
? getOppositeAlignmentPlacement(placement) !== placement
|
|
19
|
+
: false));
|
|
20
|
+
}
|
|
21
|
+
return true;
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
export const autoPlacement = (options = {}) => ({
|
|
25
|
+
name: 'autoPlacement',
|
|
26
|
+
options,
|
|
27
|
+
async fn(middlewareArguments) {
|
|
28
|
+
var _a, _b, _c, _d, _e, _f;
|
|
29
|
+
const { x, y, rects, middlewareData, placement } = middlewareArguments;
|
|
30
|
+
const { alignment = null, allowedPlacements = allPlacements, autoAlignment = true, ...detectOverflowOptions } = options;
|
|
31
|
+
if ((_a = middlewareData.autoPlacement) === null || _a === void 0 ? void 0 : _a.skip) {
|
|
32
|
+
return {};
|
|
33
|
+
}
|
|
34
|
+
const placements = getPlacementList(alignment, autoAlignment, allowedPlacements);
|
|
35
|
+
const overflow = await detectOverflow(middlewareArguments, detectOverflowOptions);
|
|
36
|
+
const currentIndex = (_c = (_b = middlewareData.autoPlacement) === null || _b === void 0 ? void 0 : _b.index) !== null && _c !== void 0 ? _c : 0;
|
|
37
|
+
const currentPlacement = placements[currentIndex];
|
|
38
|
+
const { main, cross } = getAlignmentSides(currentPlacement, rects);
|
|
39
|
+
// Make `computeCoords` start from the right place
|
|
40
|
+
if (placement !== currentPlacement) {
|
|
41
|
+
return {
|
|
42
|
+
x,
|
|
43
|
+
y,
|
|
44
|
+
reset: {
|
|
45
|
+
placement: placements[0],
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
const currentOverflows = [
|
|
50
|
+
overflow[getBasePlacement(currentPlacement)],
|
|
51
|
+
overflow[main],
|
|
52
|
+
overflow[cross],
|
|
53
|
+
];
|
|
54
|
+
const allOverflows = [
|
|
55
|
+
...((_e = (_d = middlewareData.autoPlacement) === null || _d === void 0 ? void 0 : _d.overflows) !== null && _e !== void 0 ? _e : []),
|
|
56
|
+
{ placement: currentPlacement, overflows: currentOverflows },
|
|
57
|
+
];
|
|
58
|
+
const nextPlacement = placements[currentIndex + 1];
|
|
59
|
+
// There are more placements to check
|
|
60
|
+
if (nextPlacement) {
|
|
61
|
+
return {
|
|
62
|
+
data: {
|
|
63
|
+
index: currentIndex + 1,
|
|
64
|
+
overflows: allOverflows,
|
|
65
|
+
},
|
|
66
|
+
reset: {
|
|
67
|
+
placement: nextPlacement,
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
const placementsSortedByLeastOverflow = allOverflows
|
|
72
|
+
.slice()
|
|
73
|
+
.sort((a, b) => a.overflows[0] - b.overflows[0]);
|
|
74
|
+
const placementThatFitsOnAllSides = (_f = placementsSortedByLeastOverflow.find(({ overflows }) => overflows.every((overflow) => overflow <= 0))) === null || _f === void 0 ? void 0 : _f.placement;
|
|
75
|
+
return {
|
|
76
|
+
data: {
|
|
77
|
+
skip: true,
|
|
78
|
+
},
|
|
79
|
+
reset: {
|
|
80
|
+
placement: placementThatFitsOnAllSides !== null && placementThatFitsOnAllSides !== void 0 ? placementThatFitsOnAllSides : placementsSortedByLeastOverflow[0].placement,
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
},
|
|
84
|
+
});
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { getOppositePlacement } from '../utils/getOppositePlacement';
|
|
2
|
+
import { getBasePlacement } from '../utils/getBasePlacement';
|
|
3
|
+
import { detectOverflow, } from '../detectOverflow';
|
|
4
|
+
import { getAlignmentSides } from '../utils/getAlignmentSides';
|
|
5
|
+
import { getExpandedPlacements } from '../utils/getExpandedPlacements';
|
|
6
|
+
export const flip = (options = {}) => ({
|
|
7
|
+
name: 'flip',
|
|
8
|
+
options,
|
|
9
|
+
async fn(middlewareArguments) {
|
|
10
|
+
var _a, _b, _c, _d, _e;
|
|
11
|
+
const { placement, middlewareData, rects, initialPlacement } = middlewareArguments;
|
|
12
|
+
if ((_a = middlewareData.flip) === null || _a === void 0 ? void 0 : _a.skip) {
|
|
13
|
+
return {};
|
|
14
|
+
}
|
|
15
|
+
const { mainAxis: checkMainAxis = true, crossAxis: checkCrossAxis = true, fallbackPlacements: specifiedFallbackPlacements, fallbackStrategy = 'bestFit', flipAlignment = true, ...detectOverflowOptions } = options;
|
|
16
|
+
const basePlacement = getBasePlacement(placement);
|
|
17
|
+
const isBasePlacement = basePlacement === initialPlacement;
|
|
18
|
+
const fallbackPlacements = specifiedFallbackPlacements ||
|
|
19
|
+
(isBasePlacement || !flipAlignment
|
|
20
|
+
? [getOppositePlacement(initialPlacement)]
|
|
21
|
+
: getExpandedPlacements(initialPlacement));
|
|
22
|
+
const placements = [initialPlacement, ...fallbackPlacements];
|
|
23
|
+
const overflow = await detectOverflow(middlewareArguments, detectOverflowOptions);
|
|
24
|
+
const overflows = [];
|
|
25
|
+
let overflowsData = ((_b = middlewareData.flip) === null || _b === void 0 ? void 0 : _b.overflows) || [];
|
|
26
|
+
if (checkMainAxis) {
|
|
27
|
+
overflows.push(overflow[basePlacement]);
|
|
28
|
+
}
|
|
29
|
+
if (checkCrossAxis) {
|
|
30
|
+
const { main, cross } = getAlignmentSides(placement, rects);
|
|
31
|
+
overflows.push(overflow[main], overflow[cross]);
|
|
32
|
+
}
|
|
33
|
+
overflowsData = [...overflowsData, { placement, overflows }];
|
|
34
|
+
// One or more sides is overflowing
|
|
35
|
+
if (!overflows.every((side) => side <= 0)) {
|
|
36
|
+
const nextIndex = ((_d = (_c = middlewareData.flip) === null || _c === void 0 ? void 0 : _c.index) !== null && _d !== void 0 ? _d : 0) + 1;
|
|
37
|
+
const nextPlacement = placements[nextIndex];
|
|
38
|
+
if (nextPlacement) {
|
|
39
|
+
// Try next placement and re-run the lifecycle
|
|
40
|
+
return {
|
|
41
|
+
data: {
|
|
42
|
+
index: nextIndex,
|
|
43
|
+
overflows: overflowsData,
|
|
44
|
+
},
|
|
45
|
+
reset: {
|
|
46
|
+
placement: nextPlacement,
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
let resetPlacement = 'bottom';
|
|
51
|
+
switch (fallbackStrategy) {
|
|
52
|
+
case 'bestFit': {
|
|
53
|
+
const placement = (_e = overflowsData
|
|
54
|
+
.slice()
|
|
55
|
+
.sort((a, b) => a.overflows
|
|
56
|
+
.filter((overflow) => overflow > 0)
|
|
57
|
+
.reduce((acc, overflow) => acc + overflow, 0) -
|
|
58
|
+
b.overflows
|
|
59
|
+
.filter((overflow) => overflow > 0)
|
|
60
|
+
.reduce((acc, overflow) => acc + overflow, 0))[0]) === null || _e === void 0 ? void 0 : _e.placement;
|
|
61
|
+
if (placement) {
|
|
62
|
+
resetPlacement = placement;
|
|
63
|
+
}
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
case 'initialPlacement':
|
|
67
|
+
resetPlacement = initialPlacement;
|
|
68
|
+
break;
|
|
69
|
+
default:
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
data: {
|
|
73
|
+
skip: true,
|
|
74
|
+
},
|
|
75
|
+
reset: {
|
|
76
|
+
placement: resetPlacement,
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
return {};
|
|
81
|
+
},
|
|
82
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { basePlacements } from '../enums';
|
|
2
|
+
import { detectOverflow } from '../detectOverflow';
|
|
3
|
+
function getSideOffsets(overflow, rect) {
|
|
4
|
+
return {
|
|
5
|
+
top: overflow.top - rect.height,
|
|
6
|
+
right: overflow.right - rect.width,
|
|
7
|
+
bottom: overflow.bottom - rect.height,
|
|
8
|
+
left: overflow.left - rect.width,
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
function isAnySideFullyClipped(overflow) {
|
|
12
|
+
return basePlacements.some((side) => overflow[side] >= 0);
|
|
13
|
+
}
|
|
14
|
+
export const hide = () => ({
|
|
15
|
+
name: 'hide',
|
|
16
|
+
async fn(modifierArguments) {
|
|
17
|
+
const referenceOverflow = await detectOverflow(modifierArguments, {
|
|
18
|
+
elementContext: 'reference',
|
|
19
|
+
});
|
|
20
|
+
const floatingAltOverflow = await detectOverflow(modifierArguments, {
|
|
21
|
+
altBoundary: true,
|
|
22
|
+
});
|
|
23
|
+
const referenceHiddenOffsets = getSideOffsets(referenceOverflow, modifierArguments.rects.reference);
|
|
24
|
+
const escapedOffsets = getSideOffsets(floatingAltOverflow, modifierArguments.rects.floating);
|
|
25
|
+
const referenceHidden = isAnySideFullyClipped(referenceHiddenOffsets);
|
|
26
|
+
const escaped = isAnySideFullyClipped(escapedOffsets);
|
|
27
|
+
return {
|
|
28
|
+
data: {
|
|
29
|
+
referenceHidden,
|
|
30
|
+
referenceHiddenOffsets,
|
|
31
|
+
escaped,
|
|
32
|
+
escapedOffsets,
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
});
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { getBasePlacement } from '../utils/getBasePlacement';
|
|
2
|
+
import { getMainAxisFromPlacement } from '../utils/getMainAxisFromPlacement';
|
|
3
|
+
import { getSideObjectFromPadding } from '../utils/getPaddingObject';
|
|
4
|
+
import { max, min } from '../utils/math';
|
|
5
|
+
import { rectToClientRect } from '../utils/rectToClientRect';
|
|
6
|
+
export const inline = (options = {}) => ({
|
|
7
|
+
name: 'inline',
|
|
8
|
+
options,
|
|
9
|
+
async fn(middlewareArguments) {
|
|
10
|
+
var _a, _b, _c;
|
|
11
|
+
const { placement, elements, rects, platform, strategy, middlewareData } = middlewareArguments;
|
|
12
|
+
// A MouseEvent's client{X,Y} coords can be up to 2 pixels off a
|
|
13
|
+
// ClientRect's bounds, despite the event listener being triggered. A
|
|
14
|
+
// padding of 2 seems to handle this issue.
|
|
15
|
+
const { padding = 2, x, y } = options;
|
|
16
|
+
if ((_a = middlewareData.inline) === null || _a === void 0 ? void 0 : _a.skip) {
|
|
17
|
+
return {};
|
|
18
|
+
}
|
|
19
|
+
const fallback = rectToClientRect(await platform.convertOffsetParentRelativeRectToViewportRelativeRect({
|
|
20
|
+
rect: rects.reference,
|
|
21
|
+
offsetParent: await platform.getOffsetParent({
|
|
22
|
+
element: elements.floating,
|
|
23
|
+
}),
|
|
24
|
+
strategy,
|
|
25
|
+
}));
|
|
26
|
+
const clientRects = Array.from((_c = (await ((_b = platform.getClientRects) === null || _b === void 0 ? void 0 : _b.call(platform, { element: elements.reference })))) !== null && _c !== void 0 ? _c : []);
|
|
27
|
+
const paddingObject = getSideObjectFromPadding(padding);
|
|
28
|
+
function getBoundingClientRect() {
|
|
29
|
+
var _a;
|
|
30
|
+
// There are two rects and they are disjoined
|
|
31
|
+
if (clientRects.length === 2 &&
|
|
32
|
+
clientRects[0].left > clientRects[1].right &&
|
|
33
|
+
x != null &&
|
|
34
|
+
y != null) {
|
|
35
|
+
// Find the first rect in which the point is fully inside
|
|
36
|
+
return ((_a = clientRects.find((rect) => x > rect.left - paddingObject.left &&
|
|
37
|
+
x < rect.right + paddingObject.right &&
|
|
38
|
+
y > rect.top - paddingObject.top &&
|
|
39
|
+
y < rect.bottom + paddingObject.bottom)) !== null && _a !== void 0 ? _a : fallback);
|
|
40
|
+
}
|
|
41
|
+
// There are 2 or more connected rects
|
|
42
|
+
if (clientRects.length >= 2) {
|
|
43
|
+
if (getMainAxisFromPlacement(placement) === 'x') {
|
|
44
|
+
const firstRect = clientRects[0];
|
|
45
|
+
const lastRect = clientRects[clientRects.length - 1];
|
|
46
|
+
const isTop = getBasePlacement(placement) === 'top';
|
|
47
|
+
const top = firstRect.top;
|
|
48
|
+
const bottom = lastRect.bottom;
|
|
49
|
+
const left = isTop ? firstRect.left : lastRect.left;
|
|
50
|
+
const right = isTop ? firstRect.right : lastRect.right;
|
|
51
|
+
const width = right - left;
|
|
52
|
+
const height = bottom - top;
|
|
53
|
+
return {
|
|
54
|
+
top,
|
|
55
|
+
bottom,
|
|
56
|
+
left,
|
|
57
|
+
right,
|
|
58
|
+
width,
|
|
59
|
+
height,
|
|
60
|
+
x: left,
|
|
61
|
+
y: top,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
const isLeftPlacement = getBasePlacement(placement) === 'left';
|
|
65
|
+
const maxRight = max(...clientRects.map((rect) => rect.right));
|
|
66
|
+
const minLeft = min(...clientRects.map((rect) => rect.left));
|
|
67
|
+
const measureRects = clientRects.filter((rect) => isLeftPlacement ? rect.left === minLeft : rect.right === maxRight);
|
|
68
|
+
const top = measureRects[0].top;
|
|
69
|
+
const bottom = measureRects[measureRects.length - 1].bottom;
|
|
70
|
+
const left = minLeft;
|
|
71
|
+
const right = maxRight;
|
|
72
|
+
const width = right - left;
|
|
73
|
+
const height = bottom - top;
|
|
74
|
+
return {
|
|
75
|
+
top,
|
|
76
|
+
bottom,
|
|
77
|
+
left,
|
|
78
|
+
right,
|
|
79
|
+
width,
|
|
80
|
+
height,
|
|
81
|
+
x: left,
|
|
82
|
+
y: top,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
return fallback;
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
data: {
|
|
89
|
+
skip: true,
|
|
90
|
+
},
|
|
91
|
+
reset: {
|
|
92
|
+
rects: await platform.getElementRects({
|
|
93
|
+
reference: { getBoundingClientRect },
|
|
94
|
+
floating: elements.floating,
|
|
95
|
+
strategy,
|
|
96
|
+
}),
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
},
|
|
100
|
+
});
|