UNPKG

react-elegant-ui

Version:

Elegant UI components, made by BEM best practices for react

50 lines (49 loc) 1.58 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.autoCorrection = void 0; var _isEqual = require("../../../../lib/isEqual"); var __assign = void 0 && (void 0).__assign || function () { __assign = Object.assign || function (t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; /** * Modifier to auto correction of position * * This modifier compare rects with previous and force update if it is not equal * It fix cases when right after changes popup have wrong position and should recalculate it */ var autoCorrection = exports.autoCorrection = { name: 'autoCorrection', enabled: true, phase: 'main', fn: function (_a) { var state = _a.state, instance = _a.instance, options = _a.options; var _b = options.rects, rects = _b === void 0 ? ['reference'] : _b; var patchedState = state; // Create modifier storage if (patchedState.__autoCorrection === undefined) { patchedState.__autoCorrection = {}; } // Compare current rects with previous var prevData = patchedState.__autoCorrection; var isEqualData = rects.every(function (key) { return (0, _isEqual.isEqual)(prevData[key], state.rects[key]); }); // Write new data and force update if need patchedState.__autoCorrection = __assign({}, state.rects); if (!isEqualData) { instance.update(); } } };