@alfalab/core-components-base-modal 3.0.1 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,6 @@
1
1
  declare function isScrolledToTop(target: HTMLElement): boolean;
2
2
  declare function isScrolledToBottom(target: HTMLElement): boolean;
3
3
  declare function hasScrollbar(target: HTMLElement): boolean;
4
- declare const handleContainer: (container: HTMLElement) => () => void;
5
- export { isScrolledToTop, isScrolledToBottom, hasScrollbar, handleContainer };
4
+ declare const restoreContainerStyles: (container: HTMLElement) => void;
5
+ declare const handleContainer: (container?: HTMLElement | undefined) => void;
6
+ export { isScrolledToTop, isScrolledToBottom, hasScrollbar, restoreContainerStyles, handleContainer };
@@ -1,3 +1,5 @@
1
+ import { getModalStore } from '@alfalab/core-components-global-store/dist/modern';
2
+
1
3
  function isScrolledToTop(target) {
2
4
  return target.scrollTop <= 0;
3
5
  }
@@ -28,12 +30,39 @@ const isOverflowing = (container) => {
28
30
  const getPaddingRight = (node) => {
29
31
  return parseInt(window.getComputedStyle(node).paddingRight, 10) || 0;
30
32
  };
33
+ const restoreContainerStyles = (container) => {
34
+ const modalRestoreStyles = getModalStore().getRestoreStyles();
35
+ const index = modalRestoreStyles.findIndex(s => s.container === container);
36
+ const existingStyles = modalRestoreStyles[index];
37
+ if (!existingStyles)
38
+ return;
39
+ existingStyles.modals -= 1;
40
+ if (existingStyles.modals <= 0) {
41
+ modalRestoreStyles.splice(index, 1);
42
+ existingStyles.styles.forEach(({ value, el, key }) => {
43
+ if (value) {
44
+ el.style.setProperty(key, value);
45
+ }
46
+ else {
47
+ el.style.removeProperty(key);
48
+ }
49
+ });
50
+ }
51
+ };
31
52
  const handleContainer = (container) => {
32
- const restoreStyle = [];
53
+ if (!container)
54
+ return;
55
+ const modalRestoreStyles = getModalStore().getRestoreStyles();
56
+ const existingStyles = modalRestoreStyles.find(s => s.container === container);
57
+ if (existingStyles) {
58
+ existingStyles.modals += 1;
59
+ return;
60
+ }
61
+ const containerStyles = [];
33
62
  if (isOverflowing(container)) {
34
63
  // Вычисляет размер до применения `overflow hidden` для избежания скачков
35
64
  const scrollbarSize = getScrollbarSize();
36
- restoreStyle.push({
65
+ containerStyles.push({
37
66
  value: container.style.paddingRight,
38
67
  key: 'padding-right',
39
68
  el: container,
@@ -52,23 +81,18 @@ const handleContainer = (container) => {
52
81
  : container;
53
82
  // Блокируем скролл даже если отсутствует скроллбар
54
83
  if (scrollContainer.style.overflow !== 'hidden') {
55
- restoreStyle.push({
84
+ containerStyles.push({
56
85
  value: scrollContainer.style.overflow,
57
86
  key: 'overflow',
58
87
  el: scrollContainer,
59
88
  });
60
89
  }
61
90
  scrollContainer.style.overflow = 'hidden';
62
- return () => {
63
- restoreStyle.forEach(({ value, el, key }) => {
64
- if (value) {
65
- el.style.setProperty(key, value);
66
- }
67
- else {
68
- el.style.removeProperty(key);
69
- }
70
- });
71
- };
91
+ modalRestoreStyles.push({
92
+ container,
93
+ modals: 1,
94
+ styles: containerStyles,
95
+ });
72
96
  };
73
97
 
74
- export { handleContainer, hasScrollbar, isScrolledToBottom, isScrolledToTop };
98
+ export { handleContainer, hasScrollbar, isScrolledToBottom, isScrolledToTop, restoreContainerStyles };
package/dist/utils.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  declare function isScrolledToTop(target: HTMLElement): boolean;
2
2
  declare function isScrolledToBottom(target: HTMLElement): boolean;
3
3
  declare function hasScrollbar(target: HTMLElement): boolean;
4
- declare const handleContainer: (container: HTMLElement) => () => void;
5
- export { isScrolledToTop, isScrolledToBottom, hasScrollbar, handleContainer };
4
+ declare const restoreContainerStyles: (container: HTMLElement) => void;
5
+ declare const handleContainer: (container?: HTMLElement | undefined) => void;
6
+ export { isScrolledToTop, isScrolledToBottom, hasScrollbar, restoreContainerStyles, handleContainer };
package/dist/utils.js CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var coreComponentsGlobalStore = require('@alfalab/core-components-global-store');
6
+
5
7
  function isScrolledToTop(target) {
6
8
  return target.scrollTop <= 0;
7
9
  }
@@ -32,12 +34,40 @@ var isOverflowing = function (container) {
32
34
  var getPaddingRight = function (node) {
33
35
  return parseInt(window.getComputedStyle(node).paddingRight, 10) || 0;
34
36
  };
37
+ var restoreContainerStyles = function (container) {
38
+ var modalRestoreStyles = coreComponentsGlobalStore.getModalStore().getRestoreStyles();
39
+ var index = modalRestoreStyles.findIndex(function (s) { return s.container === container; });
40
+ var existingStyles = modalRestoreStyles[index];
41
+ if (!existingStyles)
42
+ return;
43
+ existingStyles.modals -= 1;
44
+ if (existingStyles.modals <= 0) {
45
+ modalRestoreStyles.splice(index, 1);
46
+ existingStyles.styles.forEach(function (_a) {
47
+ var value = _a.value, el = _a.el, key = _a.key;
48
+ if (value) {
49
+ el.style.setProperty(key, value);
50
+ }
51
+ else {
52
+ el.style.removeProperty(key);
53
+ }
54
+ });
55
+ }
56
+ };
35
57
  var handleContainer = function (container) {
36
- var restoreStyle = [];
58
+ if (!container)
59
+ return;
60
+ var modalRestoreStyles = coreComponentsGlobalStore.getModalStore().getRestoreStyles();
61
+ var existingStyles = modalRestoreStyles.find(function (s) { return s.container === container; });
62
+ if (existingStyles) {
63
+ existingStyles.modals += 1;
64
+ return;
65
+ }
66
+ var containerStyles = [];
37
67
  if (isOverflowing(container)) {
38
68
  // Вычисляет размер до применения `overflow hidden` для избежания скачков
39
69
  var scrollbarSize = getScrollbarSize();
40
- restoreStyle.push({
70
+ containerStyles.push({
41
71
  value: container.style.paddingRight,
42
72
  key: 'padding-right',
43
73
  el: container,
@@ -56,27 +86,22 @@ var handleContainer = function (container) {
56
86
  : container;
57
87
  // Блокируем скролл даже если отсутствует скроллбар
58
88
  if (scrollContainer.style.overflow !== 'hidden') {
59
- restoreStyle.push({
89
+ containerStyles.push({
60
90
  value: scrollContainer.style.overflow,
61
91
  key: 'overflow',
62
92
  el: scrollContainer,
63
93
  });
64
94
  }
65
95
  scrollContainer.style.overflow = 'hidden';
66
- return function () {
67
- restoreStyle.forEach(function (_a) {
68
- var value = _a.value, el = _a.el, key = _a.key;
69
- if (value) {
70
- el.style.setProperty(key, value);
71
- }
72
- else {
73
- el.style.removeProperty(key);
74
- }
75
- });
76
- };
96
+ modalRestoreStyles.push({
97
+ container: container,
98
+ modals: 1,
99
+ styles: containerStyles,
100
+ });
77
101
  };
78
102
 
79
103
  exports.handleContainer = handleContainer;
80
104
  exports.hasScrollbar = hasScrollbar;
81
105
  exports.isScrolledToBottom = isScrolledToBottom;
82
106
  exports.isScrolledToTop = isScrolledToTop;
107
+ exports.restoreContainerStyles = restoreContainerStyles;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alfalab/core-components-base-modal",
3
- "version": "3.0.1",
3
+ "version": "3.2.0",
4
4
  "description": "BaseModal component",
5
5
  "keywords": [],
6
6
  "license": "MIT",
@@ -16,6 +16,7 @@
16
16
  },
17
17
  "dependencies": {
18
18
  "@alfalab/core-components-backdrop": "^2.0.1",
19
+ "@alfalab/core-components-global-store": "^1.1.0",
19
20
  "@alfalab/core-components-portal": "^2.0.1",
20
21
  "@alfalab/core-components-stack": "^3.0.1",
21
22
  "classnames": "^2.2.6",
@@ -30,5 +31,5 @@
30
31
  "peerDependencies": {
31
32
  "react": "^16.9.0 || ^17.0.1"
32
33
  },
33
- "gitHead": "0934905ac76c93940e8dd2b0ea9bb3131908ac00"
34
+ "gitHead": "ddf4fab6035139cf412e0acb7174ef388f23e4f2"
34
35
  }