@rc-component/util 1.0.0 → 1.0.1
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/es/Children/toArray.js +3 -4
- package/es/Dom/contains.js +1 -1
- package/es/Dom/dynamicCSS.js +50 -60
- package/es/Dom/findDOMNode.js +3 -5
- package/es/Dom/focus.js +13 -21
- package/es/Dom/isVisible.js +10 -8
- package/es/Dom/scrollLocker.js +63 -89
- package/es/Dom/shadow.js +1 -2
- package/es/Dom/styleChecker.js +9 -9
- package/es/KeyCode.js +4 -2
- package/es/Portal.js +15 -16
- package/es/PortalWrapper.js +150 -175
- package/es/React/isFragment.js +4 -5
- package/es/React/render.js +32 -63
- package/es/composeProps.js +9 -16
- package/es/getScrollBarSize.js +19 -15
- package/es/hooks/useEffect.js +3 -5
- package/es/hooks/useEvent.js +2 -8
- package/es/hooks/useId.js +10 -23
- package/es/hooks/useLayoutEffect.js +8 -8
- package/es/hooks/useMemo.js +1 -1
- package/es/hooks/useMergedState.js +23 -34
- package/es/hooks/useMobile.js +3 -12
- package/es/hooks/useState.js +4 -13
- package/es/hooks/useSyncState.js +4 -14
- package/es/isEqual.js +9 -14
- package/es/isMobile.js +3 -3
- package/es/omit.js +2 -2
- package/es/pickAttrs.js +29 -17
- package/es/proxyObject.js +2 -2
- package/es/raf.js +12 -23
- package/es/ref.js +16 -30
- package/es/setStyle.js +8 -8
- package/es/test/domHook.js +19 -25
- package/es/utils/get.js +2 -2
- package/es/utils/set.js +19 -38
- package/es/warning.js +7 -11
- package/lib/Children/toArray.js +3 -4
- package/lib/Dom/contains.js +1 -1
- package/lib/Dom/dynamicCSS.js +50 -60
- package/lib/Dom/findDOMNode.js +3 -5
- package/lib/Dom/focus.js +13 -21
- package/lib/Dom/isVisible.js +12 -9
- package/lib/Dom/scrollLocker.js +64 -88
- package/lib/Dom/shadow.js +1 -2
- package/lib/Dom/styleChecker.js +9 -9
- package/lib/KeyCode.js +4 -2
- package/lib/Portal.js +15 -16
- package/lib/PortalWrapper.js +154 -177
- package/lib/React/isFragment.js +4 -5
- package/lib/React/render.js +34 -65
- package/lib/composeProps.js +9 -16
- package/lib/getScrollBarSize.js +19 -15
- package/lib/hooks/useEffect.js +5 -8
- package/lib/hooks/useEvent.js +4 -11
- package/lib/hooks/useId.js +12 -25
- package/lib/hooks/useLayoutEffect.js +11 -11
- package/lib/hooks/useMemo.js +3 -4
- package/lib/hooks/useMergedState.js +24 -35
- package/lib/hooks/useMobile.js +3 -12
- package/lib/hooks/useState.js +6 -16
- package/lib/hooks/useSyncState.js +6 -17
- package/lib/index.js +8 -8
- package/lib/isEqual.js +9 -14
- package/lib/isMobile.js +5 -4
- package/lib/omit.js +2 -2
- package/lib/pickAttrs.js +29 -17
- package/lib/proxyObject.js +2 -2
- package/lib/raf.js +12 -23
- package/lib/ref.js +23 -31
- package/lib/setStyle.js +8 -8
- package/lib/test/domHook.js +19 -25
- package/lib/utils/get.js +2 -2
- package/lib/utils/set.js +19 -38
- package/lib/warning.js +8 -11
- package/package.json +3 -3
package/es/Children/toArray.js
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import isFragment from "../React/isFragment";
|
|
2
2
|
import React from 'react';
|
|
3
|
-
export default function toArray(children) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
React.Children.forEach(children, function (child) {
|
|
3
|
+
export default function toArray(children, option = {}) {
|
|
4
|
+
let ret = [];
|
|
5
|
+
React.Children.forEach(children, child => {
|
|
7
6
|
if ((child === undefined || child === null) && !option.keepEmpty) {
|
|
8
7
|
return;
|
|
9
8
|
}
|
package/es/Dom/contains.js
CHANGED
package/es/Dom/dynamicCSS.js
CHANGED
|
@@ -1,20 +1,14 @@
|
|
|
1
|
-
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
-
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
5
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
|
-
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
1
|
import canUseDom from "./canUseDom";
|
|
8
2
|
import contains from "./contains";
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
function getMark(
|
|
14
|
-
|
|
15
|
-
|
|
3
|
+
const APPEND_ORDER = 'data-rc-order';
|
|
4
|
+
const APPEND_PRIORITY = 'data-rc-priority';
|
|
5
|
+
const MARK_KEY = `rc-util-key`;
|
|
6
|
+
const containerCache = new Map();
|
|
7
|
+
function getMark({
|
|
8
|
+
mark
|
|
9
|
+
} = {}) {
|
|
16
10
|
if (mark) {
|
|
17
|
-
return mark.startsWith('data-') ? mark :
|
|
11
|
+
return mark.startsWith('data-') ? mark : `data-${mark}`;
|
|
18
12
|
}
|
|
19
13
|
return MARK_KEY;
|
|
20
14
|
}
|
|
@@ -22,7 +16,7 @@ function getContainer(option) {
|
|
|
22
16
|
if (option.attachTo) {
|
|
23
17
|
return option.attachTo;
|
|
24
18
|
}
|
|
25
|
-
|
|
19
|
+
const head = document.querySelector('head');
|
|
26
20
|
return head || document.body;
|
|
27
21
|
}
|
|
28
22
|
function getOrder(prepend) {
|
|
@@ -36,43 +30,43 @@ function getOrder(prepend) {
|
|
|
36
30
|
* Find style which inject by rc-util
|
|
37
31
|
*/
|
|
38
32
|
function findStyles(container) {
|
|
39
|
-
return Array.from((containerCache.get(container) || container).children).filter(
|
|
40
|
-
return node.tagName === 'STYLE';
|
|
41
|
-
});
|
|
33
|
+
return Array.from((containerCache.get(container) || container).children).filter(node => node.tagName === 'STYLE');
|
|
42
34
|
}
|
|
43
|
-
export function injectCSS(css) {
|
|
44
|
-
var option = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
35
|
+
export function injectCSS(css, option = {}) {
|
|
45
36
|
if (!canUseDom()) {
|
|
46
37
|
return null;
|
|
47
38
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
priority =
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
39
|
+
const {
|
|
40
|
+
csp,
|
|
41
|
+
prepend,
|
|
42
|
+
priority = 0
|
|
43
|
+
} = option;
|
|
44
|
+
const mergedOrder = getOrder(prepend);
|
|
45
|
+
const isPrependQueue = mergedOrder === 'prependQueue';
|
|
46
|
+
const styleNode = document.createElement('style');
|
|
55
47
|
styleNode.setAttribute(APPEND_ORDER, mergedOrder);
|
|
56
48
|
if (isPrependQueue && priority) {
|
|
57
|
-
styleNode.setAttribute(APPEND_PRIORITY,
|
|
49
|
+
styleNode.setAttribute(APPEND_PRIORITY, `${priority}`);
|
|
58
50
|
}
|
|
59
|
-
if (csp
|
|
60
|
-
styleNode.nonce = csp
|
|
51
|
+
if (csp?.nonce) {
|
|
52
|
+
styleNode.nonce = csp?.nonce;
|
|
61
53
|
}
|
|
62
54
|
styleNode.innerHTML = css;
|
|
63
|
-
|
|
64
|
-
|
|
55
|
+
const container = getContainer(option);
|
|
56
|
+
const {
|
|
57
|
+
firstChild
|
|
58
|
+
} = container;
|
|
65
59
|
if (prepend) {
|
|
66
60
|
// If is queue `prepend`, it will prepend first style and then append rest style
|
|
67
61
|
if (isPrependQueue) {
|
|
68
|
-
|
|
62
|
+
const existStyle = (option.styles || findStyles(container)).filter(node => {
|
|
69
63
|
// Ignore style which not injected by rc-util with prepend
|
|
70
64
|
if (!['prepend', 'prependQueue'].includes(node.getAttribute(APPEND_ORDER))) {
|
|
71
65
|
return false;
|
|
72
66
|
}
|
|
73
67
|
|
|
74
68
|
// Ignore style which priority less then new style
|
|
75
|
-
|
|
69
|
+
const nodePriority = Number(node.getAttribute(APPEND_PRIORITY) || 0);
|
|
76
70
|
return priority >= nodePriority;
|
|
77
71
|
});
|
|
78
72
|
if (existStyle.length) {
|
|
@@ -88,18 +82,14 @@ export function injectCSS(css) {
|
|
|
88
82
|
}
|
|
89
83
|
return styleNode;
|
|
90
84
|
}
|
|
91
|
-
function findExistNode(key) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
return (option.styles || findStyles(container)).find(function (node) {
|
|
95
|
-
return node.getAttribute(getMark(option)) === key;
|
|
96
|
-
});
|
|
85
|
+
function findExistNode(key, option = {}) {
|
|
86
|
+
const container = getContainer(option);
|
|
87
|
+
return (option.styles || findStyles(container)).find(node => node.getAttribute(getMark(option)) === key);
|
|
97
88
|
}
|
|
98
|
-
export function removeCSS(key) {
|
|
99
|
-
|
|
100
|
-
var existNode = findExistNode(key, option);
|
|
89
|
+
export function removeCSS(key, option = {}) {
|
|
90
|
+
const existNode = findExistNode(key, option);
|
|
101
91
|
if (existNode) {
|
|
102
|
-
|
|
92
|
+
const container = getContainer(option);
|
|
103
93
|
container.removeChild(existNode);
|
|
104
94
|
}
|
|
105
95
|
}
|
|
@@ -108,12 +98,14 @@ export function removeCSS(key) {
|
|
|
108
98
|
* qiankun will inject `appendChild` to insert into other
|
|
109
99
|
*/
|
|
110
100
|
function syncRealContainer(container, option) {
|
|
111
|
-
|
|
101
|
+
const cachedRealContainer = containerCache.get(container);
|
|
112
102
|
|
|
113
103
|
// Find real container when not cached or cached container removed
|
|
114
104
|
if (!cachedRealContainer || !contains(document, cachedRealContainer)) {
|
|
115
|
-
|
|
116
|
-
|
|
105
|
+
const placeholderStyle = injectCSS('', option);
|
|
106
|
+
const {
|
|
107
|
+
parentNode
|
|
108
|
+
} = placeholderStyle;
|
|
117
109
|
containerCache.set(container, parentNode);
|
|
118
110
|
container.removeChild(placeholderStyle);
|
|
119
111
|
}
|
|
@@ -125,29 +117,27 @@ function syncRealContainer(container, option) {
|
|
|
125
117
|
export function clearContainerCache() {
|
|
126
118
|
containerCache.clear();
|
|
127
119
|
}
|
|
128
|
-
export function updateCSS(css, key) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
styles
|
|
134
|
-
}
|
|
120
|
+
export function updateCSS(css, key, originOption = {}) {
|
|
121
|
+
const container = getContainer(originOption);
|
|
122
|
+
const styles = findStyles(container);
|
|
123
|
+
const option = {
|
|
124
|
+
...originOption,
|
|
125
|
+
styles
|
|
126
|
+
};
|
|
135
127
|
|
|
136
128
|
// Sync real parent
|
|
137
129
|
syncRealContainer(container, option);
|
|
138
|
-
|
|
130
|
+
const existNode = findExistNode(key, option);
|
|
139
131
|
if (existNode) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
var _option$csp3;
|
|
143
|
-
existNode.nonce = (_option$csp3 = option.csp) === null || _option$csp3 === void 0 ? void 0 : _option$csp3.nonce;
|
|
132
|
+
if (option.csp?.nonce && existNode.nonce !== option.csp?.nonce) {
|
|
133
|
+
existNode.nonce = option.csp?.nonce;
|
|
144
134
|
}
|
|
145
135
|
if (existNode.innerHTML !== css) {
|
|
146
136
|
existNode.innerHTML = css;
|
|
147
137
|
}
|
|
148
138
|
return existNode;
|
|
149
139
|
}
|
|
150
|
-
|
|
140
|
+
const newNode = injectCSS(css, option);
|
|
151
141
|
newNode.setAttribute(getMark(option), key);
|
|
152
142
|
return newNode;
|
|
153
143
|
}
|
package/es/Dom/findDOMNode.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
1
|
import React from 'react';
|
|
3
2
|
import ReactDOM from 'react-dom';
|
|
4
3
|
export function isDOM(node) {
|
|
@@ -11,7 +10,7 @@ export function isDOM(node) {
|
|
|
11
10
|
* Retrieves a DOM node via a ref, and does not invoke `findDOMNode`.
|
|
12
11
|
*/
|
|
13
12
|
export function getDOM(node) {
|
|
14
|
-
if (node &&
|
|
13
|
+
if (node && typeof node === 'object' && isDOM(node.nativeElement)) {
|
|
15
14
|
return node.nativeElement;
|
|
16
15
|
}
|
|
17
16
|
if (isDOM(node)) {
|
|
@@ -24,13 +23,12 @@ export function getDOM(node) {
|
|
|
24
23
|
* Return if a node is a DOM node. Else will return by `findDOMNode`
|
|
25
24
|
*/
|
|
26
25
|
export default function findDOMNode(node) {
|
|
27
|
-
|
|
26
|
+
const domNode = getDOM(node);
|
|
28
27
|
if (domNode) {
|
|
29
28
|
return domNode;
|
|
30
29
|
}
|
|
31
30
|
if (node instanceof React.Component) {
|
|
32
|
-
|
|
33
|
-
return (_ReactDOM$findDOMNode = ReactDOM.findDOMNode) === null || _ReactDOM$findDOMNode === void 0 ? void 0 : _ReactDOM$findDOMNode.call(ReactDOM, node);
|
|
31
|
+
return ReactDOM.findDOMNode?.(node);
|
|
34
32
|
}
|
|
35
33
|
return null;
|
|
36
34
|
}
|
package/es/Dom/focus.js
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
2
|
-
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
5
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
6
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
7
1
|
import isVisible from "./isVisible";
|
|
8
|
-
function focusable(node) {
|
|
9
|
-
var includePositive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
2
|
+
function focusable(node, includePositive = false) {
|
|
10
3
|
if (isVisible(node)) {
|
|
11
|
-
|
|
12
|
-
|
|
4
|
+
const nodeName = node.nodeName.toLowerCase();
|
|
5
|
+
const isFocusableElement =
|
|
13
6
|
// Focusable element
|
|
14
7
|
['input', 'select', 'textarea', 'button'].includes(nodeName) ||
|
|
15
8
|
// Editable element
|
|
@@ -18,11 +11,11 @@ function focusable(node) {
|
|
|
18
11
|
nodeName === 'a' && !!node.getAttribute('href');
|
|
19
12
|
|
|
20
13
|
// Get tabIndex
|
|
21
|
-
|
|
22
|
-
|
|
14
|
+
const tabIndexAttr = node.getAttribute('tabindex');
|
|
15
|
+
const tabIndexNum = Number(tabIndexAttr);
|
|
23
16
|
|
|
24
17
|
// Parse as number if validate
|
|
25
|
-
|
|
18
|
+
let tabIndex = null;
|
|
26
19
|
if (tabIndexAttr && !Number.isNaN(tabIndexNum)) {
|
|
27
20
|
tabIndex = tabIndexNum;
|
|
28
21
|
} else if (isFocusableElement && tabIndex === null) {
|
|
@@ -37,9 +30,8 @@ function focusable(node) {
|
|
|
37
30
|
}
|
|
38
31
|
return false;
|
|
39
32
|
}
|
|
40
|
-
export function getFocusNodeList(node) {
|
|
41
|
-
|
|
42
|
-
var res = _toConsumableArray(node.querySelectorAll('*')).filter(function (child) {
|
|
33
|
+
export function getFocusNodeList(node, includePositive = false) {
|
|
34
|
+
const res = [...node.querySelectorAll('*')].filter(child => {
|
|
43
35
|
return focusable(child, includePositive);
|
|
44
36
|
});
|
|
45
37
|
if (focusable(node, includePositive)) {
|
|
@@ -47,7 +39,7 @@ export function getFocusNodeList(node) {
|
|
|
47
39
|
}
|
|
48
40
|
return res;
|
|
49
41
|
}
|
|
50
|
-
|
|
42
|
+
let lastFocusElement = null;
|
|
51
43
|
|
|
52
44
|
/** @deprecated Do not use since this may failed when used in async */
|
|
53
45
|
export function saveLastFocusNode() {
|
|
@@ -75,11 +67,11 @@ export function backLastFocusNode() {
|
|
|
75
67
|
}
|
|
76
68
|
export function limitTabRange(node, e) {
|
|
77
69
|
if (e.keyCode === 9) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
70
|
+
const tabNodeList = getFocusNodeList(node);
|
|
71
|
+
const lastTabNode = tabNodeList[e.shiftKey ? 0 : tabNodeList.length - 1];
|
|
72
|
+
const leavingTab = lastTabNode === document.activeElement || node === document.activeElement;
|
|
81
73
|
if (leavingTab) {
|
|
82
|
-
|
|
74
|
+
const target = tabNodeList[e.shiftKey ? tabNodeList.length - 1 : 0];
|
|
83
75
|
target.focus();
|
|
84
76
|
e.preventDefault();
|
|
85
77
|
}
|
package/es/Dom/isVisible.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export default (
|
|
1
|
+
export default (element => {
|
|
2
2
|
if (!element) {
|
|
3
3
|
return false;
|
|
4
4
|
}
|
|
@@ -7,18 +7,20 @@ export default (function (element) {
|
|
|
7
7
|
return true;
|
|
8
8
|
}
|
|
9
9
|
if (element.getBBox) {
|
|
10
|
-
|
|
11
|
-
width
|
|
12
|
-
height
|
|
10
|
+
const {
|
|
11
|
+
width,
|
|
12
|
+
height
|
|
13
|
+
} = element.getBBox();
|
|
13
14
|
if (width || height) {
|
|
14
15
|
return true;
|
|
15
16
|
}
|
|
16
17
|
}
|
|
17
18
|
if (element.getBoundingClientRect) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
const {
|
|
20
|
+
width,
|
|
21
|
+
height
|
|
22
|
+
} = element.getBoundingClientRect();
|
|
23
|
+
if (width || height) {
|
|
22
24
|
return true;
|
|
23
25
|
}
|
|
24
26
|
}
|
package/es/Dom/scrollLocker.js
CHANGED
|
@@ -1,87 +1,70 @@
|
|
|
1
|
-
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
3
|
-
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
5
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
6
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
7
|
-
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
8
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
9
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
10
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
11
|
-
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
12
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
13
|
-
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
14
1
|
import getScrollBarSize from "../getScrollBarSize";
|
|
15
2
|
import setStyle from "../setStyle";
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
3
|
+
let uuid = 0;
|
|
4
|
+
let locks = [];
|
|
5
|
+
const scrollingEffectClassName = 'ant-scrolling-effect';
|
|
6
|
+
const scrollingEffectClassNameReg = new RegExp(`${scrollingEffectClassName}`, 'g');
|
|
20
7
|
|
|
21
8
|
// https://github.com/ant-design/ant-design/issues/19340
|
|
22
9
|
// https://github.com/ant-design/ant-design/issues/19332
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
10
|
+
const cacheStyle = new Map();
|
|
11
|
+
export default class ScrollLocker {
|
|
12
|
+
lockTarget;
|
|
13
|
+
options;
|
|
14
|
+
constructor(options) {
|
|
15
|
+
// eslint-disable-next-line no-plusplus
|
|
16
|
+
this.lockTarget = uuid++;
|
|
17
|
+
this.options = options;
|
|
18
|
+
}
|
|
19
|
+
getContainer = () => {
|
|
20
|
+
return this.options?.container;
|
|
21
|
+
};
|
|
22
|
+
|
|
33
23
|
// if options change...
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
});
|
|
24
|
+
reLock = options => {
|
|
25
|
+
const findLock = locks.find(({
|
|
26
|
+
target
|
|
27
|
+
}) => target === this.lockTarget);
|
|
39
28
|
if (findLock) {
|
|
40
|
-
|
|
29
|
+
this.unLock();
|
|
41
30
|
}
|
|
42
|
-
|
|
31
|
+
this.options = options;
|
|
43
32
|
if (findLock) {
|
|
44
33
|
findLock.options = options;
|
|
45
|
-
|
|
34
|
+
this.lock();
|
|
46
35
|
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
var _this$options3;
|
|
36
|
+
};
|
|
37
|
+
lock = () => {
|
|
50
38
|
// If lockTarget exist return
|
|
51
|
-
if (locks.some(
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
})) {
|
|
39
|
+
if (locks.some(({
|
|
40
|
+
target
|
|
41
|
+
}) => target === this.lockTarget)) {
|
|
55
42
|
return;
|
|
56
43
|
}
|
|
57
44
|
|
|
58
45
|
// If same container effect, return
|
|
59
|
-
if (locks.some(
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
options: _this.options
|
|
67
|
-
}]);
|
|
46
|
+
if (locks.some(({
|
|
47
|
+
options
|
|
48
|
+
}) => options?.container === this.options?.container)) {
|
|
49
|
+
locks = [...locks, {
|
|
50
|
+
target: this.lockTarget,
|
|
51
|
+
options: this.options
|
|
52
|
+
}];
|
|
68
53
|
return;
|
|
69
54
|
}
|
|
70
|
-
|
|
71
|
-
|
|
55
|
+
let scrollBarSize = 0;
|
|
56
|
+
const container = this.options?.container || document.body;
|
|
72
57
|
if (container === document.body && window.innerWidth - document.documentElement.clientWidth > 0 || container.scrollHeight > container.clientHeight) {
|
|
73
58
|
if (getComputedStyle(container).overflow !== 'hidden') {
|
|
74
59
|
scrollBarSize = getScrollBarSize();
|
|
75
60
|
}
|
|
76
61
|
}
|
|
77
|
-
|
|
78
|
-
if (locks.filter(
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
return (options === null || options === void 0 ? void 0 : options.container) === ((_this$options4 = _this.options) === null || _this$options4 === void 0 ? void 0 : _this$options4.container);
|
|
82
|
-
}).length === 0) {
|
|
62
|
+
const containerClassName = container.className;
|
|
63
|
+
if (locks.filter(({
|
|
64
|
+
options
|
|
65
|
+
}) => options?.container === this.options?.container).length === 0) {
|
|
83
66
|
cacheStyle.set(container, setStyle({
|
|
84
|
-
width: scrollBarSize !== 0 ?
|
|
67
|
+
width: scrollBarSize !== 0 ? `calc(100% - ${scrollBarSize}px)` : undefined,
|
|
85
68
|
overflow: 'hidden',
|
|
86
69
|
overflowX: 'hidden',
|
|
87
70
|
overflowY: 'hidden'
|
|
@@ -92,44 +75,35 @@ var ScrollLocker = /*#__PURE__*/_createClass(function ScrollLocker(_options) {
|
|
|
92
75
|
|
|
93
76
|
// https://github.com/ant-design/ant-design/issues/19729
|
|
94
77
|
if (!scrollingEffectClassNameReg.test(containerClassName)) {
|
|
95
|
-
|
|
78
|
+
const addClassName = `${containerClassName} ${scrollingEffectClassName}`;
|
|
96
79
|
container.className = addClassName.trim();
|
|
97
80
|
}
|
|
98
|
-
locks = [
|
|
99
|
-
target:
|
|
100
|
-
options:
|
|
101
|
-
}]
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
})
|
|
113
|
-
if (!findLock || locks.some(function (_ref7) {
|
|
114
|
-
var _findLock$options;
|
|
115
|
-
var options = _ref7.options;
|
|
116
|
-
return (options === null || options === void 0 ? void 0 : options.container) === ((_findLock$options = findLock.options) === null || _findLock$options === void 0 ? void 0 : _findLock$options.container);
|
|
117
|
-
})) {
|
|
81
|
+
locks = [...locks, {
|
|
82
|
+
target: this.lockTarget,
|
|
83
|
+
options: this.options
|
|
84
|
+
}];
|
|
85
|
+
};
|
|
86
|
+
unLock = () => {
|
|
87
|
+
const findLock = locks.find(({
|
|
88
|
+
target
|
|
89
|
+
}) => target === this.lockTarget);
|
|
90
|
+
locks = locks.filter(({
|
|
91
|
+
target
|
|
92
|
+
}) => target !== this.lockTarget);
|
|
93
|
+
if (!findLock || locks.some(({
|
|
94
|
+
options
|
|
95
|
+
}) => options?.container === findLock.options?.container)) {
|
|
118
96
|
return;
|
|
119
97
|
}
|
|
120
98
|
|
|
121
99
|
// Remove Effect
|
|
122
|
-
|
|
123
|
-
|
|
100
|
+
const container = this.options?.container || document.body;
|
|
101
|
+
const containerClassName = container.className;
|
|
124
102
|
if (!scrollingEffectClassNameReg.test(containerClassName)) return;
|
|
125
103
|
setStyle(cacheStyle.get(container), {
|
|
126
104
|
element: container
|
|
127
105
|
});
|
|
128
106
|
cacheStyle.delete(container);
|
|
129
107
|
container.className = container.className.replace(scrollingEffectClassNameReg, '').trim();
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
this.lockTarget = uuid++;
|
|
133
|
-
this.options = _options;
|
|
134
|
-
});
|
|
135
|
-
export { ScrollLocker as default };
|
|
108
|
+
};
|
|
109
|
+
}
|
package/es/Dom/shadow.js
CHANGED
package/es/Dom/styleChecker.js
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
import canUseDom from "./canUseDom";
|
|
2
|
-
|
|
2
|
+
const isStyleNameSupport = styleName => {
|
|
3
3
|
if (canUseDom() && window.document.documentElement) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
const styleNameList = Array.isArray(styleName) ? styleName : [styleName];
|
|
5
|
+
const {
|
|
6
|
+
documentElement
|
|
7
|
+
} = window.document;
|
|
8
|
+
return styleNameList.some(name => name in documentElement.style);
|
|
9
9
|
}
|
|
10
10
|
return false;
|
|
11
11
|
};
|
|
12
|
-
|
|
12
|
+
const isStyleValueSupport = (styleName, value) => {
|
|
13
13
|
if (!isStyleNameSupport(styleName)) {
|
|
14
14
|
return false;
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
const ele = document.createElement('div');
|
|
17
|
+
const origin = ele.style[styleName];
|
|
18
18
|
ele.style[styleName] = value;
|
|
19
19
|
return ele.style[styleName] !== origin;
|
|
20
20
|
};
|
package/es/KeyCode.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* @author yiminghe@gmail.com
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
const KeyCode = {
|
|
8
8
|
/**
|
|
9
9
|
* MAC_ENTER
|
|
10
10
|
*/
|
|
@@ -455,7 +455,9 @@ var KeyCode = {
|
|
|
455
455
|
* whether text and modified key is entered at the same time.
|
|
456
456
|
*/
|
|
457
457
|
isTextModifyingKeyEvent: function isTextModifyingKeyEvent(e) {
|
|
458
|
-
|
|
458
|
+
const {
|
|
459
|
+
keyCode
|
|
460
|
+
} = e;
|
|
459
461
|
if (e.altKey && !e.ctrlKey || e.metaKey ||
|
|
460
462
|
// Function keys don't generate text
|
|
461
463
|
keyCode >= KeyCode.F1 && keyCode <= KeyCode.F12) {
|