Dashboard sipadu mbip
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. "use strict";
  2. exports.__esModule = true;
  3. exports.default = void 0;
  4. var _class = _interopRequireDefault(require("dom-helpers/class"));
  5. var _style = _interopRequireDefault(require("dom-helpers/style"));
  6. var _scrollbarSize = _interopRequireDefault(require("dom-helpers/util/scrollbarSize"));
  7. var _isOverflowing = _interopRequireDefault(require("./utils/isOverflowing"));
  8. var _manageAriaHidden = require("./utils/manageAriaHidden");
  9. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10. function findIndexOf(arr, cb) {
  11. var idx = -1;
  12. arr.some(function (d, i) {
  13. if (cb(d, i)) {
  14. idx = i;
  15. return true;
  16. }
  17. });
  18. return idx;
  19. }
  20. /**
  21. * Proper state managment for containers and the modals in those containers.
  22. *
  23. * @internal Used by the Modal to ensure proper styling of containers.
  24. */
  25. var ModalManager =
  26. /*#__PURE__*/
  27. function () {
  28. function ModalManager(_temp) {
  29. var _ref = _temp === void 0 ? {} : _temp,
  30. _ref$hideSiblingNodes = _ref.hideSiblingNodes,
  31. hideSiblingNodes = _ref$hideSiblingNodes === void 0 ? true : _ref$hideSiblingNodes,
  32. _ref$handleContainerO = _ref.handleContainerOverflow,
  33. handleContainerOverflow = _ref$handleContainerO === void 0 ? true : _ref$handleContainerO;
  34. this.hideSiblingNodes = hideSiblingNodes;
  35. this.handleContainerOverflow = handleContainerOverflow;
  36. this.modals = [];
  37. this.containers = [];
  38. this.data = [];
  39. this.scrollbarSize = (0, _scrollbarSize.default)();
  40. }
  41. var _proto = ModalManager.prototype;
  42. _proto.isContainerOverflowing = function isContainerOverflowing(modal) {
  43. var data = this.data[this.containerIndexFromModal(modal)];
  44. return data && data.overflowing;
  45. };
  46. _proto.containerIndexFromModal = function containerIndexFromModal(modal) {
  47. return findIndexOf(this.data, function (d) {
  48. return d.modals.indexOf(modal) !== -1;
  49. });
  50. };
  51. _proto.setContainerStyle = function setContainerStyle(containerState, container) {
  52. var style = {
  53. overflow: 'hidden' // we are only interested in the actual `style` here
  54. // becasue we will override it
  55. };
  56. containerState.style = {
  57. overflow: container.style.overflow,
  58. paddingRight: container.style.paddingRight
  59. };
  60. if (containerState.overflowing) {
  61. // use computed style, here to get the real padding
  62. // to add our scrollbar width
  63. style.paddingRight = parseInt((0, _style.default)(container, 'paddingRight') || 0, 10) + this.scrollbarSize + "px";
  64. }
  65. (0, _style.default)(container, style);
  66. };
  67. _proto.removeContainerStyle = function removeContainerStyle(containerState, container) {
  68. var style = containerState.style;
  69. Object.keys(style).forEach(function (key) {
  70. container.style[key] = style[key];
  71. });
  72. };
  73. _proto.add = function add(modal, container, className) {
  74. var modalIdx = this.modals.indexOf(modal);
  75. var containerIdx = this.containers.indexOf(container);
  76. if (modalIdx !== -1) {
  77. return modalIdx;
  78. }
  79. modalIdx = this.modals.length;
  80. this.modals.push(modal);
  81. if (this.hideSiblingNodes) {
  82. (0, _manageAriaHidden.hideSiblings)(container, modal);
  83. }
  84. if (containerIdx !== -1) {
  85. this.data[containerIdx].modals.push(modal);
  86. return modalIdx;
  87. }
  88. var data = {
  89. modals: [modal],
  90. //right now only the first modal of a container will have its classes applied
  91. classes: className ? className.split(/\s+/) : [],
  92. overflowing: (0, _isOverflowing.default)(container)
  93. };
  94. if (this.handleContainerOverflow) {
  95. this.setContainerStyle(data, container);
  96. }
  97. data.classes.forEach(_class.default.addClass.bind(null, container));
  98. this.containers.push(container);
  99. this.data.push(data);
  100. return modalIdx;
  101. };
  102. _proto.remove = function remove(modal) {
  103. var modalIdx = this.modals.indexOf(modal);
  104. if (modalIdx === -1) {
  105. return;
  106. }
  107. var containerIdx = this.containerIndexFromModal(modal);
  108. var data = this.data[containerIdx];
  109. var container = this.containers[containerIdx];
  110. data.modals.splice(data.modals.indexOf(modal), 1);
  111. this.modals.splice(modalIdx, 1); // if that was the last modal in a container,
  112. // clean up the container
  113. if (data.modals.length === 0) {
  114. data.classes.forEach(_class.default.removeClass.bind(null, container));
  115. if (this.handleContainerOverflow) {
  116. this.removeContainerStyle(data, container);
  117. }
  118. if (this.hideSiblingNodes) {
  119. (0, _manageAriaHidden.showSiblings)(container, modal);
  120. }
  121. this.containers.splice(containerIdx, 1);
  122. this.data.splice(containerIdx, 1);
  123. } else if (this.hideSiblingNodes) {
  124. //otherwise make sure the next top modal is visible to a SR
  125. var _data$modals = data.modals[data.modals.length - 1],
  126. backdrop = _data$modals.backdrop,
  127. dialog = _data$modals.dialog;
  128. (0, _manageAriaHidden.ariaHidden)(false, dialog);
  129. (0, _manageAriaHidden.ariaHidden)(false, backdrop);
  130. }
  131. };
  132. _proto.isTopModal = function isTopModal(modal) {
  133. return !!this.modals.length && this.modals[this.modals.length - 1] === modal;
  134. };
  135. return ModalManager;
  136. }();
  137. var _default = ModalManager;
  138. exports.default = _default;
  139. module.exports = exports.default;