UNPKG

2.71 kBJavaScriptView Raw
1"use strict";
2
3var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
5exports.__esModule = true;
6exports.toModifierMap = toModifierMap;
7exports.toModifierArray = toModifierArray;
8exports["default"] = mergeOptionsWithPopperConfig;
9
10var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
12function toModifierMap(modifiers) {
13 var result = {};
14
15 if (!Array.isArray(modifiers)) {
16 return modifiers || result;
17 } // eslint-disable-next-line no-unused-expressions
18
19
20 modifiers == null ? void 0 : modifiers.forEach(function (m) {
21 result[m.name] = m;
22 });
23 return result;
24}
25
26function toModifierArray(map) {
27 if (map === void 0) {
28 map = {};
29 }
30
31 if (Array.isArray(map)) return map;
32 return Object.keys(map).map(function (k) {
33 map[k].name = k;
34 return map[k];
35 });
36}
37
38function mergeOptionsWithPopperConfig(_ref) {
39 var _modifiers$preventOve, _modifiers$preventOve2, _modifiers$offset, _modifiers$arrow;
40
41 var enabled = _ref.enabled,
42 enableEvents = _ref.enableEvents,
43 placement = _ref.placement,
44 flip = _ref.flip,
45 offset = _ref.offset,
46 fixed = _ref.fixed,
47 containerPadding = _ref.containerPadding,
48 arrowElement = _ref.arrowElement,
49 _ref$popperConfig = _ref.popperConfig,
50 popperConfig = _ref$popperConfig === void 0 ? {} : _ref$popperConfig;
51 var modifiers = toModifierMap(popperConfig.modifiers);
52 return (0, _extends2["default"])({}, popperConfig, {
53 placement: placement,
54 enabled: enabled,
55 strategy: fixed ? 'fixed' : popperConfig.strategy,
56 modifiers: toModifierArray((0, _extends2["default"])({}, modifiers, {
57 eventListeners: {
58 enabled: enableEvents
59 },
60 preventOverflow: (0, _extends2["default"])({}, modifiers.preventOverflow, {
61 options: containerPadding ? (0, _extends2["default"])({
62 padding: containerPadding
63 }, (_modifiers$preventOve = modifiers.preventOverflow) == null ? void 0 : _modifiers$preventOve.options) : (_modifiers$preventOve2 = modifiers.preventOverflow) == null ? void 0 : _modifiers$preventOve2.options
64 }),
65 offset: {
66 options: (0, _extends2["default"])({
67 offset: offset
68 }, (_modifiers$offset = modifiers.offset) == null ? void 0 : _modifiers$offset.options)
69 },
70 arrow: (0, _extends2["default"])({}, modifiers.arrow, {
71 enabled: !!arrowElement,
72 options: (0, _extends2["default"])({}, (_modifiers$arrow = modifiers.arrow) == null ? void 0 : _modifiers$arrow.options, {
73 element: arrowElement
74 })
75 }),
76 flip: (0, _extends2["default"])({
77 enabled: !!flip
78 }, modifiers.flip)
79 }))
80 });
81}
\No newline at end of file