1 | import getVariation from "./getVariation.js";
|
2 | import { variationPlacements, basePlacements, placements as allPlacements } from "../enums.js";
|
3 | import detectOverflow from "./detectOverflow.js";
|
4 | import getBasePlacement from "./getBasePlacement.js";
|
5 | export default function computeAutoPlacement(state, options) {
|
6 | if (options === void 0) {
|
7 | options = {};
|
8 | }
|
9 |
|
10 | var _options = options,
|
11 | placement = _options.placement,
|
12 | boundary = _options.boundary,
|
13 | rootBoundary = _options.rootBoundary,
|
14 | padding = _options.padding,
|
15 | flipVariations = _options.flipVariations,
|
16 | _options$allowedAutoP = _options.allowedAutoPlacements,
|
17 | allowedAutoPlacements = _options$allowedAutoP === void 0 ? allPlacements : _options$allowedAutoP;
|
18 | var variation = getVariation(placement);
|
19 | var placements = variation ? flipVariations ? variationPlacements : variationPlacements.filter(function (placement) {
|
20 | return getVariation(placement) === variation;
|
21 | }) : basePlacements;
|
22 | var allowedPlacements = placements.filter(function (placement) {
|
23 | return allowedAutoPlacements.indexOf(placement) >= 0;
|
24 | });
|
25 |
|
26 | if (allowedPlacements.length === 0) {
|
27 | allowedPlacements = placements;
|
28 | }
|
29 |
|
30 |
|
31 | var overflows = allowedPlacements.reduce(function (acc, placement) {
|
32 | acc[placement] = detectOverflow(state, {
|
33 | placement: placement,
|
34 | boundary: boundary,
|
35 | rootBoundary: rootBoundary,
|
36 | padding: padding
|
37 | })[getBasePlacement(placement)];
|
38 | return acc;
|
39 | }, {});
|
40 | return Object.keys(overflows).sort(function (a, b) {
|
41 | return overflows[a] - overflows[b];
|
42 | });
|
43 | } |
\ | No newline at end of file |