carbon-react 104.58.4 → 104.58.5
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.
- package/esm/hooks/__internal__/useScrollBlock/scroll-block-manager.d.ts +2 -0
- package/esm/hooks/__internal__/useScrollBlock/scroll-block-manager.js +18 -2
- package/esm/hooks/__internal__/useScrollBlock/useScrollBlock.js +30 -5
- package/lib/hooks/__internal__/useScrollBlock/scroll-block-manager.d.ts +2 -0
- package/lib/hooks/__internal__/useScrollBlock/scroll-block-manager.js +18 -2
- package/lib/hooks/__internal__/useScrollBlock/useScrollBlock.js +29 -4
- package/package.json +1 -1
|
@@ -5,6 +5,8 @@ declare class ScrollBlockManager {
|
|
|
5
5
|
registerComponent(id: any): void;
|
|
6
6
|
unregisterComponent(id: any): void;
|
|
7
7
|
saveOriginalValues(values: any): void;
|
|
8
|
+
saveRestoreValuesCallback(callback: any): void;
|
|
9
|
+
getRestoreValuesCallback(): any;
|
|
8
10
|
getOriginalValues(): any;
|
|
9
11
|
isBlocked(): boolean;
|
|
10
12
|
}
|
|
@@ -4,6 +4,8 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
|
|
|
4
4
|
|
|
5
5
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
6
6
|
|
|
7
|
+
// TODO: This component can be refactored to remove redundant code after
|
|
8
|
+
// we can confirm that all Sage products use version 105.0.0^
|
|
7
9
|
let ScrollBlockManager = /*#__PURE__*/function () {
|
|
8
10
|
function ScrollBlockManager() {
|
|
9
11
|
_classCallCheck(this, ScrollBlockManager);
|
|
@@ -13,11 +15,13 @@ let ScrollBlockManager = /*#__PURE__*/function () {
|
|
|
13
15
|
if (!window.__CARBON_INTERNALS_SCROLL_BLOCKERS) {
|
|
14
16
|
window.__CARBON_INTERNALS_SCROLL_BLOCKERS = {
|
|
15
17
|
components: {},
|
|
18
|
+
// originalValues can be removed
|
|
16
19
|
originalValues: []
|
|
17
20
|
};
|
|
18
21
|
}
|
|
19
22
|
|
|
20
|
-
this.components = window.__CARBON_INTERNALS_SCROLL_BLOCKERS.components;
|
|
23
|
+
this.components = window.__CARBON_INTERNALS_SCROLL_BLOCKERS.components; // TODO: originalValues can be removed
|
|
24
|
+
|
|
21
25
|
this.originalValues = window.__CARBON_INTERNALS_SCROLL_BLOCKERS.originalValues;
|
|
22
26
|
}
|
|
23
27
|
|
|
@@ -30,13 +34,25 @@ let ScrollBlockManager = /*#__PURE__*/function () {
|
|
|
30
34
|
key: "unregisterComponent",
|
|
31
35
|
value: function unregisterComponent(id) {
|
|
32
36
|
delete this.components[id];
|
|
33
|
-
}
|
|
37
|
+
} // TODO: saveOriginalValues can be removed
|
|
38
|
+
|
|
34
39
|
}, {
|
|
35
40
|
key: "saveOriginalValues",
|
|
36
41
|
value: function saveOriginalValues(values) {
|
|
37
42
|
this.originalValues.length = 0;
|
|
38
43
|
this.originalValues.push(...values);
|
|
39
44
|
}
|
|
45
|
+
}, {
|
|
46
|
+
key: "saveRestoreValuesCallback",
|
|
47
|
+
value: function saveRestoreValuesCallback(callback) {
|
|
48
|
+
window.__CARBON_INTERNALS_SCROLL_BLOCKERS.restoreValues = callback;
|
|
49
|
+
}
|
|
50
|
+
}, {
|
|
51
|
+
key: "getRestoreValuesCallback",
|
|
52
|
+
value: function getRestoreValuesCallback() {
|
|
53
|
+
return window.__CARBON_INTERNALS_SCROLL_BLOCKERS.restoreValues;
|
|
54
|
+
} // TODO: getOriginalValues can be removed
|
|
55
|
+
|
|
40
56
|
}, {
|
|
41
57
|
key: "getOriginalValues",
|
|
42
58
|
value: function getOriginalValues() {
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { useRef, useCallback, useMemo } from "react";
|
|
2
2
|
import guid from "../../../__internal__/utils/helpers/guid";
|
|
3
|
-
import ScrollBlockManager from "./scroll-block-manager";
|
|
3
|
+
import ScrollBlockManager from "./scroll-block-manager"; // TODO: This component can be refactored to remove redundant code after
|
|
4
|
+
// we can confirm that all Sage products use version 105.0.0^
|
|
5
|
+
|
|
4
6
|
const scrollBlockManager = new ScrollBlockManager();
|
|
5
7
|
/* istanbul ignore next */
|
|
6
8
|
|
|
@@ -10,6 +12,7 @@ const useScrollBlock = () => {
|
|
|
10
12
|
const {
|
|
11
13
|
current: containerGuid
|
|
12
14
|
} = useRef(guid());
|
|
15
|
+
const originalValuesRef = useRef();
|
|
13
16
|
const rules = useMemo(() => {
|
|
14
17
|
const {
|
|
15
18
|
documentElement,
|
|
@@ -17,7 +20,8 @@ const useScrollBlock = () => {
|
|
|
17
20
|
} = safeDocument;
|
|
18
21
|
const scrollBarWidth = window.innerWidth - documentElement.clientWidth;
|
|
19
22
|
const bodyPaddingRight = parseInt(window.getComputedStyle(body).getPropertyValue("padding-right")) || 0;
|
|
20
|
-
return [
|
|
23
|
+
return [// TODO: First two entries of this array with the documentElement can be removed
|
|
24
|
+
{
|
|
21
25
|
element: documentElement,
|
|
22
26
|
property: "position",
|
|
23
27
|
blockingValue: "relative"
|
|
@@ -39,6 +43,14 @@ const useScrollBlock = () => {
|
|
|
39
43
|
blockingValue: `${bodyPaddingRight + scrollBarWidth}px`
|
|
40
44
|
}];
|
|
41
45
|
}, []);
|
|
46
|
+
const restoreValues = useCallback(() => {
|
|
47
|
+
rules.forEach(({
|
|
48
|
+
element,
|
|
49
|
+
property
|
|
50
|
+
}, index) => {
|
|
51
|
+
element.style[property] = originalValuesRef.current[index];
|
|
52
|
+
});
|
|
53
|
+
}, [rules]);
|
|
42
54
|
const blockScroll = useCallback(() => {
|
|
43
55
|
const isBlocked = scrollBlockManager.isBlocked();
|
|
44
56
|
scrollBlockManager.registerComponent(containerGuid);
|
|
@@ -51,19 +63,32 @@ const useScrollBlock = () => {
|
|
|
51
63
|
element,
|
|
52
64
|
property
|
|
53
65
|
}) => element.style[property]);
|
|
54
|
-
|
|
55
|
-
|
|
66
|
+
originalValuesRef.current = originalValues;
|
|
67
|
+
scrollBlockManager.saveRestoreValuesCallback(restoreValues); // TODO: saveOriginalValues can be removed
|
|
68
|
+
|
|
69
|
+
scrollBlockManager.saveOriginalValues(originalValues); // TODO: slice san be removed
|
|
70
|
+
|
|
71
|
+
rules.slice(-3).forEach(({
|
|
56
72
|
element,
|
|
57
73
|
property,
|
|
58
74
|
blockingValue
|
|
59
75
|
}) => {
|
|
60
76
|
element.style[property] = blockingValue;
|
|
61
77
|
});
|
|
62
|
-
}, [containerGuid, rules]);
|
|
78
|
+
}, [restoreValues, containerGuid, rules]);
|
|
63
79
|
const allowScroll = useCallback(() => {
|
|
64
80
|
scrollBlockManager.unregisterComponent(containerGuid);
|
|
65
81
|
const isBlocked = scrollBlockManager.isBlocked();
|
|
66
82
|
if (isBlocked) return;
|
|
83
|
+
const restoreValuesCallback = scrollBlockManager.getRestoreValuesCallback();
|
|
84
|
+
|
|
85
|
+
if (restoreValuesCallback) {
|
|
86
|
+
restoreValuesCallback();
|
|
87
|
+
scrollBlockManager.saveRestoreValuesCallback(null);
|
|
88
|
+
return;
|
|
89
|
+
} // TODO: all of the code below can be removed from this block
|
|
90
|
+
|
|
91
|
+
|
|
67
92
|
const originalValues = scrollBlockManager.getOriginalValues();
|
|
68
93
|
rules.forEach(({
|
|
69
94
|
element,
|
|
@@ -5,6 +5,8 @@ declare class ScrollBlockManager {
|
|
|
5
5
|
registerComponent(id: any): void;
|
|
6
6
|
unregisterComponent(id: any): void;
|
|
7
7
|
saveOriginalValues(values: any): void;
|
|
8
|
+
saveRestoreValuesCallback(callback: any): void;
|
|
9
|
+
getRestoreValuesCallback(): any;
|
|
8
10
|
getOriginalValues(): any;
|
|
9
11
|
isBlocked(): boolean;
|
|
10
12
|
}
|
|
@@ -11,6 +11,8 @@ function _defineProperties(target, props) { for (var i = 0; i < props.length; i+
|
|
|
11
11
|
|
|
12
12
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
13
13
|
|
|
14
|
+
// TODO: This component can be refactored to remove redundant code after
|
|
15
|
+
// we can confirm that all Sage products use version 105.0.0^
|
|
14
16
|
let ScrollBlockManager = /*#__PURE__*/function () {
|
|
15
17
|
function ScrollBlockManager() {
|
|
16
18
|
_classCallCheck(this, ScrollBlockManager);
|
|
@@ -20,11 +22,13 @@ let ScrollBlockManager = /*#__PURE__*/function () {
|
|
|
20
22
|
if (!window.__CARBON_INTERNALS_SCROLL_BLOCKERS) {
|
|
21
23
|
window.__CARBON_INTERNALS_SCROLL_BLOCKERS = {
|
|
22
24
|
components: {},
|
|
25
|
+
// originalValues can be removed
|
|
23
26
|
originalValues: []
|
|
24
27
|
};
|
|
25
28
|
}
|
|
26
29
|
|
|
27
|
-
this.components = window.__CARBON_INTERNALS_SCROLL_BLOCKERS.components;
|
|
30
|
+
this.components = window.__CARBON_INTERNALS_SCROLL_BLOCKERS.components; // TODO: originalValues can be removed
|
|
31
|
+
|
|
28
32
|
this.originalValues = window.__CARBON_INTERNALS_SCROLL_BLOCKERS.originalValues;
|
|
29
33
|
}
|
|
30
34
|
|
|
@@ -37,13 +41,25 @@ let ScrollBlockManager = /*#__PURE__*/function () {
|
|
|
37
41
|
key: "unregisterComponent",
|
|
38
42
|
value: function unregisterComponent(id) {
|
|
39
43
|
delete this.components[id];
|
|
40
|
-
}
|
|
44
|
+
} // TODO: saveOriginalValues can be removed
|
|
45
|
+
|
|
41
46
|
}, {
|
|
42
47
|
key: "saveOriginalValues",
|
|
43
48
|
value: function saveOriginalValues(values) {
|
|
44
49
|
this.originalValues.length = 0;
|
|
45
50
|
this.originalValues.push(...values);
|
|
46
51
|
}
|
|
52
|
+
}, {
|
|
53
|
+
key: "saveRestoreValuesCallback",
|
|
54
|
+
value: function saveRestoreValuesCallback(callback) {
|
|
55
|
+
window.__CARBON_INTERNALS_SCROLL_BLOCKERS.restoreValues = callback;
|
|
56
|
+
}
|
|
57
|
+
}, {
|
|
58
|
+
key: "getRestoreValuesCallback",
|
|
59
|
+
value: function getRestoreValuesCallback() {
|
|
60
|
+
return window.__CARBON_INTERNALS_SCROLL_BLOCKERS.restoreValues;
|
|
61
|
+
} // TODO: getOriginalValues can be removed
|
|
62
|
+
|
|
47
63
|
}, {
|
|
48
64
|
key: "getOriginalValues",
|
|
49
65
|
value: function getOriginalValues() {
|
|
@@ -13,6 +13,8 @@ var _scrollBlockManager = _interopRequireDefault(require("./scroll-block-manager
|
|
|
13
13
|
|
|
14
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
15
|
|
|
16
|
+
// TODO: This component can be refactored to remove redundant code after
|
|
17
|
+
// we can confirm that all Sage products use version 105.0.0^
|
|
16
18
|
const scrollBlockManager = new _scrollBlockManager.default();
|
|
17
19
|
/* istanbul ignore next */
|
|
18
20
|
|
|
@@ -22,6 +24,7 @@ const useScrollBlock = () => {
|
|
|
22
24
|
const {
|
|
23
25
|
current: containerGuid
|
|
24
26
|
} = (0, _react.useRef)((0, _guid.default)());
|
|
27
|
+
const originalValuesRef = (0, _react.useRef)();
|
|
25
28
|
const rules = (0, _react.useMemo)(() => {
|
|
26
29
|
const {
|
|
27
30
|
documentElement,
|
|
@@ -29,7 +32,8 @@ const useScrollBlock = () => {
|
|
|
29
32
|
} = safeDocument;
|
|
30
33
|
const scrollBarWidth = window.innerWidth - documentElement.clientWidth;
|
|
31
34
|
const bodyPaddingRight = parseInt(window.getComputedStyle(body).getPropertyValue("padding-right")) || 0;
|
|
32
|
-
return [
|
|
35
|
+
return [// TODO: First two entries of this array with the documentElement can be removed
|
|
36
|
+
{
|
|
33
37
|
element: documentElement,
|
|
34
38
|
property: "position",
|
|
35
39
|
blockingValue: "relative"
|
|
@@ -51,6 +55,14 @@ const useScrollBlock = () => {
|
|
|
51
55
|
blockingValue: `${bodyPaddingRight + scrollBarWidth}px`
|
|
52
56
|
}];
|
|
53
57
|
}, []);
|
|
58
|
+
const restoreValues = (0, _react.useCallback)(() => {
|
|
59
|
+
rules.forEach(({
|
|
60
|
+
element,
|
|
61
|
+
property
|
|
62
|
+
}, index) => {
|
|
63
|
+
element.style[property] = originalValuesRef.current[index];
|
|
64
|
+
});
|
|
65
|
+
}, [rules]);
|
|
54
66
|
const blockScroll = (0, _react.useCallback)(() => {
|
|
55
67
|
const isBlocked = scrollBlockManager.isBlocked();
|
|
56
68
|
scrollBlockManager.registerComponent(containerGuid);
|
|
@@ -63,19 +75,32 @@ const useScrollBlock = () => {
|
|
|
63
75
|
element,
|
|
64
76
|
property
|
|
65
77
|
}) => element.style[property]);
|
|
66
|
-
|
|
67
|
-
|
|
78
|
+
originalValuesRef.current = originalValues;
|
|
79
|
+
scrollBlockManager.saveRestoreValuesCallback(restoreValues); // TODO: saveOriginalValues can be removed
|
|
80
|
+
|
|
81
|
+
scrollBlockManager.saveOriginalValues(originalValues); // TODO: slice san be removed
|
|
82
|
+
|
|
83
|
+
rules.slice(-3).forEach(({
|
|
68
84
|
element,
|
|
69
85
|
property,
|
|
70
86
|
blockingValue
|
|
71
87
|
}) => {
|
|
72
88
|
element.style[property] = blockingValue;
|
|
73
89
|
});
|
|
74
|
-
}, [containerGuid, rules]);
|
|
90
|
+
}, [restoreValues, containerGuid, rules]);
|
|
75
91
|
const allowScroll = (0, _react.useCallback)(() => {
|
|
76
92
|
scrollBlockManager.unregisterComponent(containerGuid);
|
|
77
93
|
const isBlocked = scrollBlockManager.isBlocked();
|
|
78
94
|
if (isBlocked) return;
|
|
95
|
+
const restoreValuesCallback = scrollBlockManager.getRestoreValuesCallback();
|
|
96
|
+
|
|
97
|
+
if (restoreValuesCallback) {
|
|
98
|
+
restoreValuesCallback();
|
|
99
|
+
scrollBlockManager.saveRestoreValuesCallback(null);
|
|
100
|
+
return;
|
|
101
|
+
} // TODO: all of the code below can be removed from this block
|
|
102
|
+
|
|
103
|
+
|
|
79
104
|
const originalValues = scrollBlockManager.getOriginalValues();
|
|
80
105
|
rules.forEach(({
|
|
81
106
|
element,
|