@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.
Files changed (76) hide show
  1. package/es/Children/toArray.js +3 -4
  2. package/es/Dom/contains.js +1 -1
  3. package/es/Dom/dynamicCSS.js +50 -60
  4. package/es/Dom/findDOMNode.js +3 -5
  5. package/es/Dom/focus.js +13 -21
  6. package/es/Dom/isVisible.js +10 -8
  7. package/es/Dom/scrollLocker.js +63 -89
  8. package/es/Dom/shadow.js +1 -2
  9. package/es/Dom/styleChecker.js +9 -9
  10. package/es/KeyCode.js +4 -2
  11. package/es/Portal.js +15 -16
  12. package/es/PortalWrapper.js +150 -175
  13. package/es/React/isFragment.js +4 -5
  14. package/es/React/render.js +32 -63
  15. package/es/composeProps.js +9 -16
  16. package/es/getScrollBarSize.js +19 -15
  17. package/es/hooks/useEffect.js +3 -5
  18. package/es/hooks/useEvent.js +2 -8
  19. package/es/hooks/useId.js +10 -23
  20. package/es/hooks/useLayoutEffect.js +8 -8
  21. package/es/hooks/useMemo.js +1 -1
  22. package/es/hooks/useMergedState.js +23 -34
  23. package/es/hooks/useMobile.js +3 -12
  24. package/es/hooks/useState.js +4 -13
  25. package/es/hooks/useSyncState.js +4 -14
  26. package/es/isEqual.js +9 -14
  27. package/es/isMobile.js +3 -3
  28. package/es/omit.js +2 -2
  29. package/es/pickAttrs.js +29 -17
  30. package/es/proxyObject.js +2 -2
  31. package/es/raf.js +12 -23
  32. package/es/ref.js +16 -30
  33. package/es/setStyle.js +8 -8
  34. package/es/test/domHook.js +19 -25
  35. package/es/utils/get.js +2 -2
  36. package/es/utils/set.js +19 -38
  37. package/es/warning.js +7 -11
  38. package/lib/Children/toArray.js +3 -4
  39. package/lib/Dom/contains.js +1 -1
  40. package/lib/Dom/dynamicCSS.js +50 -60
  41. package/lib/Dom/findDOMNode.js +3 -5
  42. package/lib/Dom/focus.js +13 -21
  43. package/lib/Dom/isVisible.js +12 -9
  44. package/lib/Dom/scrollLocker.js +64 -88
  45. package/lib/Dom/shadow.js +1 -2
  46. package/lib/Dom/styleChecker.js +9 -9
  47. package/lib/KeyCode.js +4 -2
  48. package/lib/Portal.js +15 -16
  49. package/lib/PortalWrapper.js +154 -177
  50. package/lib/React/isFragment.js +4 -5
  51. package/lib/React/render.js +34 -65
  52. package/lib/composeProps.js +9 -16
  53. package/lib/getScrollBarSize.js +19 -15
  54. package/lib/hooks/useEffect.js +5 -8
  55. package/lib/hooks/useEvent.js +4 -11
  56. package/lib/hooks/useId.js +12 -25
  57. package/lib/hooks/useLayoutEffect.js +11 -11
  58. package/lib/hooks/useMemo.js +3 -4
  59. package/lib/hooks/useMergedState.js +24 -35
  60. package/lib/hooks/useMobile.js +3 -12
  61. package/lib/hooks/useState.js +6 -16
  62. package/lib/hooks/useSyncState.js +6 -17
  63. package/lib/index.js +8 -8
  64. package/lib/isEqual.js +9 -14
  65. package/lib/isMobile.js +5 -4
  66. package/lib/omit.js +2 -2
  67. package/lib/pickAttrs.js +29 -17
  68. package/lib/proxyObject.js +2 -2
  69. package/lib/raf.js +12 -23
  70. package/lib/ref.js +23 -31
  71. package/lib/setStyle.js +8 -8
  72. package/lib/test/domHook.js +19 -25
  73. package/lib/utils/get.js +2 -2
  74. package/lib/utils/set.js +19 -38
  75. package/lib/warning.js +8 -11
  76. package/package.json +3 -3
@@ -1,9 +1,8 @@
1
1
  import isFragment from "../React/isFragment";
2
2
  import React from 'react';
3
- export default function toArray(children) {
4
- var option = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
5
- var ret = [];
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
  }
@@ -9,7 +9,7 @@ export default function contains(root, n) {
9
9
  }
10
10
 
11
11
  // `document.contains` not support with IE11
12
- var node = n;
12
+ let node = n;
13
13
  while (node) {
14
14
  if (node === root) {
15
15
  return true;
@@ -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
- var APPEND_ORDER = 'data-rc-order';
10
- var APPEND_PRIORITY = 'data-rc-priority';
11
- var MARK_KEY = "rc-util-key";
12
- var containerCache = new Map();
13
- function getMark() {
14
- var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
15
- mark = _ref.mark;
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 : "data-".concat(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
- var head = document.querySelector('head');
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(function (node) {
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
- var csp = option.csp,
49
- prepend = option.prepend,
50
- _option$priority = option.priority,
51
- priority = _option$priority === void 0 ? 0 : _option$priority;
52
- var mergedOrder = getOrder(prepend);
53
- var isPrependQueue = mergedOrder === 'prependQueue';
54
- var styleNode = document.createElement('style');
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, "".concat(priority));
49
+ styleNode.setAttribute(APPEND_PRIORITY, `${priority}`);
58
50
  }
59
- if (csp !== null && csp !== void 0 && csp.nonce) {
60
- styleNode.nonce = csp === null || csp === void 0 ? void 0 : csp.nonce;
51
+ if (csp?.nonce) {
52
+ styleNode.nonce = csp?.nonce;
61
53
  }
62
54
  styleNode.innerHTML = css;
63
- var container = getContainer(option);
64
- var firstChild = container.firstChild;
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
- var existStyle = (option.styles || findStyles(container)).filter(function (node) {
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
- var nodePriority = Number(node.getAttribute(APPEND_PRIORITY) || 0);
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
- var option = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
93
- var container = getContainer(option);
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
- var option = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
100
- var existNode = findExistNode(key, option);
89
+ export function removeCSS(key, option = {}) {
90
+ const existNode = findExistNode(key, option);
101
91
  if (existNode) {
102
- var container = getContainer(option);
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
- var cachedRealContainer = containerCache.get(container);
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
- var placeholderStyle = injectCSS('', option);
116
- var parentNode = placeholderStyle.parentNode;
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
- var originOption = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
130
- var container = getContainer(originOption);
131
- var styles = findStyles(container);
132
- var option = _objectSpread(_objectSpread({}, originOption), {}, {
133
- styles: 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
- var existNode = findExistNode(key, option);
130
+ const existNode = findExistNode(key, option);
139
131
  if (existNode) {
140
- var _option$csp, _option$csp2;
141
- if ((_option$csp = option.csp) !== null && _option$csp !== void 0 && _option$csp.nonce && existNode.nonce !== ((_option$csp2 = option.csp) === null || _option$csp2 === void 0 ? void 0 : _option$csp2.nonce)) {
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
- var newNode = injectCSS(css, option);
140
+ const newNode = injectCSS(css, option);
151
141
  newNode.setAttribute(getMark(option), key);
152
142
  return newNode;
153
143
  }
@@ -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 && _typeof(node) === 'object' && isDOM(node.nativeElement)) {
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
- var domNode = getDOM(node);
26
+ const domNode = getDOM(node);
28
27
  if (domNode) {
29
28
  return domNode;
30
29
  }
31
30
  if (node instanceof React.Component) {
32
- var _ReactDOM$findDOMNode;
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
- var nodeName = node.nodeName.toLowerCase();
12
- var isFocusableElement =
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
- var tabIndexAttr = node.getAttribute('tabindex');
22
- var tabIndexNum = Number(tabIndexAttr);
14
+ const tabIndexAttr = node.getAttribute('tabindex');
15
+ const tabIndexNum = Number(tabIndexAttr);
23
16
 
24
17
  // Parse as number if validate
25
- var tabIndex = null;
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
- var includePositive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
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
- var lastFocusElement = null;
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
- var tabNodeList = getFocusNodeList(node);
79
- var lastTabNode = tabNodeList[e.shiftKey ? 0 : tabNodeList.length - 1];
80
- var leavingTab = lastTabNode === document.activeElement || node === document.activeElement;
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
- var target = tabNodeList[e.shiftKey ? tabNodeList.length - 1 : 0];
74
+ const target = tabNodeList[e.shiftKey ? tabNodeList.length - 1 : 0];
83
75
  target.focus();
84
76
  e.preventDefault();
85
77
  }
@@ -1,4 +1,4 @@
1
- export default (function (element) {
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
- var _getBBox = element.getBBox(),
11
- width = _getBBox.width,
12
- height = _getBBox.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
- var _element$getBoundingC = element.getBoundingClientRect(),
19
- _width = _element$getBoundingC.width,
20
- _height = _element$getBoundingC.height;
21
- if (_width || _height) {
19
+ const {
20
+ width,
21
+ height
22
+ } = element.getBoundingClientRect();
23
+ if (width || height) {
22
24
  return true;
23
25
  }
24
26
  }
@@ -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
- var uuid = 0;
17
- var locks = [];
18
- var scrollingEffectClassName = 'ant-scrolling-effect';
19
- var scrollingEffectClassNameReg = new RegExp("".concat(scrollingEffectClassName), 'g');
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
- var cacheStyle = new Map();
24
- var ScrollLocker = /*#__PURE__*/_createClass(function ScrollLocker(_options) {
25
- var _this = this;
26
- _classCallCheck(this, ScrollLocker);
27
- _defineProperty(this, "lockTarget", void 0);
28
- _defineProperty(this, "options", void 0);
29
- _defineProperty(this, "getContainer", function () {
30
- var _this$options;
31
- return (_this$options = _this.options) === null || _this$options === void 0 ? void 0 : _this$options.container;
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
- _defineProperty(this, "reLock", function (options) {
35
- var findLock = locks.find(function (_ref) {
36
- var target = _ref.target;
37
- return target === _this.lockTarget;
38
- });
24
+ reLock = options => {
25
+ const findLock = locks.find(({
26
+ target
27
+ }) => target === this.lockTarget);
39
28
  if (findLock) {
40
- _this.unLock();
29
+ this.unLock();
41
30
  }
42
- _this.options = options;
31
+ this.options = options;
43
32
  if (findLock) {
44
33
  findLock.options = options;
45
- _this.lock();
34
+ this.lock();
46
35
  }
47
- });
48
- _defineProperty(this, "lock", function () {
49
- var _this$options3;
36
+ };
37
+ lock = () => {
50
38
  // If lockTarget exist return
51
- if (locks.some(function (_ref2) {
52
- var target = _ref2.target;
53
- return target === _this.lockTarget;
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(function (_ref3) {
60
- var _this$options2;
61
- var options = _ref3.options;
62
- return (options === null || options === void 0 ? void 0 : options.container) === ((_this$options2 = _this.options) === null || _this$options2 === void 0 ? void 0 : _this$options2.container);
63
- })) {
64
- locks = [].concat(_toConsumableArray(locks), [{
65
- target: _this.lockTarget,
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
- var scrollBarSize = 0;
71
- var container = ((_this$options3 = _this.options) === null || _this$options3 === void 0 ? void 0 : _this$options3.container) || document.body;
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
- var containerClassName = container.className;
78
- if (locks.filter(function (_ref4) {
79
- var _this$options4;
80
- var options = _ref4.options;
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 ? "calc(100% - ".concat(scrollBarSize, "px)") : undefined,
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
- var addClassName = "".concat(containerClassName, " ").concat(scrollingEffectClassName);
78
+ const addClassName = `${containerClassName} ${scrollingEffectClassName}`;
96
79
  container.className = addClassName.trim();
97
80
  }
98
- locks = [].concat(_toConsumableArray(locks), [{
99
- target: _this.lockTarget,
100
- options: _this.options
101
- }]);
102
- });
103
- _defineProperty(this, "unLock", function () {
104
- var _this$options5;
105
- var findLock = locks.find(function (_ref5) {
106
- var target = _ref5.target;
107
- return target === _this.lockTarget;
108
- });
109
- locks = locks.filter(function (_ref6) {
110
- var target = _ref6.target;
111
- return target !== _this.lockTarget;
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
- var container = ((_this$options5 = _this.options) === null || _this$options5 === void 0 ? void 0 : _this$options5.container) || document.body;
123
- var containerClassName = container.className;
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
- // eslint-disable-next-line no-plusplus
132
- this.lockTarget = uuid++;
133
- this.options = _options;
134
- });
135
- export { ScrollLocker as default };
108
+ };
109
+ }
package/es/Dom/shadow.js CHANGED
@@ -1,6 +1,5 @@
1
1
  function getRoot(ele) {
2
- var _ele$getRootNode;
3
- return ele === null || ele === void 0 || (_ele$getRootNode = ele.getRootNode) === null || _ele$getRootNode === void 0 ? void 0 : _ele$getRootNode.call(ele);
2
+ return ele?.getRootNode?.();
4
3
  }
5
4
 
6
5
  /**
@@ -1,20 +1,20 @@
1
1
  import canUseDom from "./canUseDom";
2
- var isStyleNameSupport = function isStyleNameSupport(styleName) {
2
+ const isStyleNameSupport = styleName => {
3
3
  if (canUseDom() && window.document.documentElement) {
4
- var styleNameList = Array.isArray(styleName) ? styleName : [styleName];
5
- var documentElement = window.document.documentElement;
6
- return styleNameList.some(function (name) {
7
- return name in documentElement.style;
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
- var isStyleValueSupport = function isStyleValueSupport(styleName, value) {
12
+ const isStyleValueSupport = (styleName, value) => {
13
13
  if (!isStyleNameSupport(styleName)) {
14
14
  return false;
15
15
  }
16
- var ele = document.createElement('div');
17
- var origin = ele.style[styleName];
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
- var KeyCode = {
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
- var keyCode = e.keyCode;
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) {