You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

react-overlays

Package Overview
Dependencies
Maintainers
2
Versions
85
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-overlays - npm Package Compare versions

Comparing version

to
1.0.0-beta.4

159

lib/ModalManager.js

@@ -28,56 +28,71 @@ "use strict";

}
/**
* Proper state managment for containers and the modals in those containers.
*
* @internal Used by the Modal to ensure proper styling of containers.
*/
function findContainer(data, modal) {
return findIndexOf(data, function (d) {
return d.modals.indexOf(modal) !== -1;
});
}
function setContainerStyle(state, container) {
var style = {
overflow: 'hidden' // we are only interested in the actual `style` here
// becasue we will override it
var ModalManager =
/*#__PURE__*/
function () {
function ModalManager(_temp) {
var _ref = _temp === void 0 ? {} : _temp,
_ref$hideSiblingNodes = _ref.hideSiblingNodes,
hideSiblingNodes = _ref$hideSiblingNodes === void 0 ? true : _ref$hideSiblingNodes,
_ref$handleContainerO = _ref.handleContainerOverflow,
handleContainerOverflow = _ref$handleContainerO === void 0 ? true : _ref$handleContainerO;
this.hideSiblingNodes = hideSiblingNodes;
this.handleContainerOverflow = handleContainerOverflow;
this.modals = [];
this.containers = [];
this.data = [];
this.scrollbarSize = (0, _scrollbarSize.default)();
}
var _proto = ModalManager.prototype;
_proto.isContainerOverflowing = function isContainerOverflowing(modal) {
var data = this.data[this.containerIndexFromModal(modal)];
return data && data.overflowing;
};
state.style = {
overflow: container.style.overflow,
paddingRight: container.style.paddingRight
_proto.containerIndexFromModal = function containerIndexFromModal(modal) {
return findIndexOf(this.data, function (d) {
return d.modals.indexOf(modal) !== -1;
});
};
if (state.overflowing) {
// use computed style, here to get the real padding
// to add our scrollbar width
style.paddingRight = parseInt((0, _style.default)(container, 'paddingRight') || 0, 10) + (0, _scrollbarSize.default)() + 'px';
}
_proto.setContainerStyle = function setContainerStyle(containerState, container) {
var style = {
overflow: 'hidden' // we are only interested in the actual `style` here
// becasue we will override it
(0, _style.default)(container, style);
}
};
containerState.style = {
overflow: container.style.overflow,
paddingRight: container.style.paddingRight
};
function removeContainerStyle(_ref, container) {
var style = _ref.style;
Object.keys(style).forEach(function (key) {
return container.style[key] = style[key];
});
}
/**
* Proper state managment for containers and the modals in those containers.
*
* @internal Used by the Modal to ensure proper styling of containers.
*/
if (containerState.overflowing) {
// use computed style, here to get the real padding
// to add our scrollbar width
style.paddingRight = parseInt((0, _style.default)(container, 'paddingRight') || 0, 10) + this.scrollbarSize + "px";
}
(0, _style.default)(container, style);
};
var ModalManager = function ModalManager(_temp) {
var _this = this;
_proto.removeContainerStyle = function removeContainerStyle(containerState, container) {
var style = containerState.style;
Object.keys(style).forEach(function (key) {
container.style[key] = style[key];
});
};
var _ref2 = _temp === void 0 ? {} : _temp,
_ref2$hideSiblingNode = _ref2.hideSiblingNodes,
hideSiblingNodes = _ref2$hideSiblingNode === void 0 ? true : _ref2$hideSiblingNode,
_ref2$handleContainer = _ref2.handleContainerOverflow,
handleContainerOverflow = _ref2$handleContainer === void 0 ? true : _ref2$handleContainer;
_proto.add = function add(modal, container, className) {
var modalIdx = this.modals.indexOf(modal);
var containerIdx = this.containers.indexOf(container);
this.add = function (modal, container, className) {
var modalIdx = _this.modals.indexOf(modal);
var containerIdx = _this.containers.indexOf(container);
if (modalIdx !== -1) {

@@ -87,7 +102,6 @@ return modalIdx;

modalIdx = _this.modals.length;
modalIdx = this.modals.length;
this.modals.push(modal);
_this.modals.push(modal);
if (_this.hideSiblingNodes) {
if (this.hideSiblingNodes) {
(0, _manageAriaHidden.hideSiblings)(container, modal);

@@ -97,4 +111,3 @@ }

if (containerIdx !== -1) {
_this.data[containerIdx].modals.push(modal);
this.data[containerIdx].modals.push(modal);
return modalIdx;

@@ -110,17 +123,14 @@ }

if (_this.handleContainerOverflow) {
setContainerStyle(data, container);
if (this.handleContainerOverflow) {
this.setContainerStyle(data, container);
}
data.classes.forEach(_class.default.addClass.bind(null, container));
_this.containers.push(container);
_this.data.push(data);
this.containers.push(container);
this.data.push(data);
return modalIdx;
};
this.remove = function (modal) {
var modalIdx = _this.modals.indexOf(modal);
_proto.remove = function remove(modal) {
var modalIdx = this.modals.indexOf(modal);

@@ -131,26 +141,23 @@ if (modalIdx === -1) {

var containerIdx = findContainer(_this.data, modal);
var data = _this.data[containerIdx];
var container = _this.containers[containerIdx];
var containerIdx = this.containerIndexFromModal(modal);
var data = this.data[containerIdx];
var container = this.containers[containerIdx];
data.modals.splice(data.modals.indexOf(modal), 1);
_this.modals.splice(modalIdx, 1); // if that was the last modal in a container,
this.modals.splice(modalIdx, 1); // if that was the last modal in a container,
// clean up the container
if (data.modals.length === 0) {
data.classes.forEach(_class.default.removeClass.bind(null, container));
if (_this.handleContainerOverflow) {
removeContainerStyle(data, container);
if (this.handleContainerOverflow) {
this.removeContainerStyle(data, container);
}
if (_this.hideSiblingNodes) {
if (this.hideSiblingNodes) {
(0, _manageAriaHidden.showSiblings)(container, modal);
}
_this.containers.splice(containerIdx, 1);
_this.data.splice(containerIdx, 1);
} else if (_this.hideSiblingNodes) {
this.containers.splice(containerIdx, 1);
this.data.splice(containerIdx, 1);
} else if (this.hideSiblingNodes) {
//otherwise make sure the next top modal is visible to a SR

@@ -165,12 +172,8 @@ var _data$modals = data.modals[data.modals.length - 1],

this.isTopModal = function (modal) {
return !!_this.modals.length && _this.modals[_this.modals.length - 1] === modal;
_proto.isTopModal = function isTopModal(modal) {
return !!this.modals.length && this.modals[this.modals.length - 1] === modal;
};
this.hideSiblingNodes = hideSiblingNodes;
this.handleContainerOverflow = handleContainerOverflow;
this.modals = [];
this.containers = [];
this.data = [];
};
return ModalManager;
}();

@@ -177,0 +180,0 @@ var _default = ModalManager;

{
"name": "react-overlays",
"version": "1.0.0-beta.3",
"version": "1.0.0-beta.4",
"description": "Utilities for creating robust overlay components",

@@ -5,0 +5,0 @@ "author": "Jason Quense <monastic.panic@gmail.com>",

Sorry, the diff of this file is not supported yet