UNPKG

@popperjs/core

Version:

Tooltip and Popover Positioning Engine

33 lines (31 loc) 1.25 kB
import getVariation from "./getVariation.js"; import { variationPlacements, basePlacements } from "../enums.js"; import detectOverflow from "./detectOverflow.js"; import getBasePlacement from "./getBasePlacement.js"; export default function computeAutoPlacement(state, options) { if (options === void 0) { options = {}; } var _options = options, placement = _options.placement, boundary = _options.boundary, rootBoundary = _options.rootBoundary, padding = _options.padding, flipVariations = _options.flipVariations; var variation = getVariation(placement); var placements = variation ? flipVariations ? variationPlacements : variationPlacements.filter(function (placement) { return getVariation(placement) === variation; }) : basePlacements; // $FlowFixMe: Flow seems to have problems with two array unions... var overflows = placements.reduce(function (acc, placement) { acc[placement] = detectOverflow(state, { placement: placement, boundary: boundary, rootBoundary: rootBoundary, padding: padding })[getBasePlacement(placement)]; return acc; }, {}); return Object.keys(overflows).sort(function (a, b) { return overflows[a] - overflows[b]; }); }