@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
package/es/ref.js CHANGED
@@ -1,12 +1,11 @@
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 { isValidElement } from 'react';
3
2
  import { ForwardRef, isMemo } from 'react-is';
4
3
  import useMemo from "./hooks/useMemo";
5
4
  import isFragment from "./React/isFragment";
6
- export var fillRef = function fillRef(ref, node) {
5
+ export const fillRef = (ref, node) => {
7
6
  if (typeof ref === 'function') {
8
7
  ref(node);
9
- } else if (_typeof(ref) === 'object' && ref && 'current' in ref) {
8
+ } else if (typeof ref === 'object' && ref && 'current' in ref) {
10
9
  ref.current = node;
11
10
  }
12
11
  };
@@ -14,36 +13,23 @@ export var fillRef = function fillRef(ref, node) {
14
13
  /**
15
14
  * Merge refs into one ref function to support ref passing.
16
15
  */
17
- export var composeRef = function composeRef() {
18
- for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
19
- refs[_key] = arguments[_key];
20
- }
21
- var refList = refs.filter(Boolean);
16
+ export const composeRef = (...refs) => {
17
+ const refList = refs.filter(Boolean);
22
18
  if (refList.length <= 1) {
23
19
  return refList[0];
24
20
  }
25
- return function (node) {
26
- refs.forEach(function (ref) {
21
+ return node => {
22
+ refs.forEach(ref => {
27
23
  fillRef(ref, node);
28
24
  });
29
25
  };
30
26
  };
31
- export var useComposeRef = function useComposeRef() {
32
- for (var _len2 = arguments.length, refs = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
33
- refs[_key2] = arguments[_key2];
34
- }
35
- return useMemo(function () {
36
- return composeRef.apply(void 0, refs);
37
- },
27
+ export const useComposeRef = (...refs) => {
28
+ return useMemo(() => composeRef(...refs),
38
29
  // eslint-disable-next-line react-hooks/exhaustive-deps
39
- refs, function (prev, next) {
40
- return prev.length !== next.length || prev.every(function (ref, i) {
41
- return ref !== next[i];
42
- });
43
- });
30
+ refs, (prev, next) => prev.length !== next.length || prev.every((ref, i) => ref !== next[i]));
44
31
  };
45
- export var supportRef = function supportRef(nodeOrComponent) {
46
- var _type$prototype, _nodeOrComponent$prot;
32
+ export const supportRef = nodeOrComponent => {
47
33
  if (!nodeOrComponent) {
48
34
  return false;
49
35
  }
@@ -52,15 +38,15 @@ export var supportRef = function supportRef(nodeOrComponent) {
52
38
  if (isReactElement(nodeOrComponent) && nodeOrComponent.props.propertyIsEnumerable('ref')) {
53
39
  return true;
54
40
  }
55
- var type = isMemo(nodeOrComponent) ? nodeOrComponent.type.type : nodeOrComponent.type;
41
+ const type = isMemo(nodeOrComponent) ? nodeOrComponent.type.type : nodeOrComponent.type;
56
42
 
57
43
  // Function component node
58
- if (typeof type === 'function' && !((_type$prototype = type.prototype) !== null && _type$prototype !== void 0 && _type$prototype.render) && type.$$typeof !== ForwardRef) {
44
+ if (typeof type === 'function' && !type.prototype?.render && type.$$typeof !== ForwardRef) {
59
45
  return false;
60
46
  }
61
47
 
62
48
  // Class component
63
- if (typeof nodeOrComponent === 'function' && !((_nodeOrComponent$prot = nodeOrComponent.prototype) !== null && _nodeOrComponent$prot !== void 0 && _nodeOrComponent$prot.render) && nodeOrComponent.$$typeof !== ForwardRef) {
49
+ if (typeof nodeOrComponent === 'function' && !nodeOrComponent.prototype?.render && nodeOrComponent.$$typeof !== ForwardRef) {
64
50
  return false;
65
51
  }
66
52
  return true;
@@ -68,7 +54,7 @@ export var supportRef = function supportRef(nodeOrComponent) {
68
54
  function isReactElement(node) {
69
55
  return /*#__PURE__*/isValidElement(node) && !isFragment(node);
70
56
  }
71
- export var supportNodeRef = function supportNodeRef(node) {
57
+ export const supportNodeRef = node => {
72
58
  return isReactElement(node) && supportRef(node);
73
59
  };
74
60
 
@@ -77,9 +63,9 @@ export var supportNodeRef = function supportNodeRef(node) {
77
63
  * But a property from `props.ref`.
78
64
  * To check if `props.ref` exist or fallback to `ref`.
79
65
  */
80
- export var getNodeRef = function getNodeRef(node) {
66
+ export const getNodeRef = node => {
81
67
  if (node && isReactElement(node)) {
82
- var ele = node;
68
+ const ele = node;
83
69
 
84
70
  // Source from:
85
71
  // https://github.com/mui/material-ui/blob/master/packages/mui-utils/src/getReactNodeRef/getReactNodeRef.ts
package/es/setStyle.js CHANGED
@@ -4,21 +4,21 @@
4
4
  * https://github.com/ant-design/ant-design/issues/19393
5
5
  *
6
6
  */
7
- function setStyle(style) {
8
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
7
+ function setStyle(style, options = {}) {
9
8
  if (!style) {
10
9
  return {};
11
10
  }
12
- var _options$element = options.element,
13
- element = _options$element === void 0 ? document.body : _options$element;
14
- var oldStyle = {};
15
- var styleKeys = Object.keys(style);
11
+ const {
12
+ element = document.body
13
+ } = options;
14
+ const oldStyle = {};
15
+ const styleKeys = Object.keys(style);
16
16
 
17
17
  // IE browser compatible
18
- styleKeys.forEach(function (key) {
18
+ styleKeys.forEach(key => {
19
19
  oldStyle[key] = element.style[key];
20
20
  });
21
- styleKeys.forEach(function (key) {
21
+ styleKeys.forEach(key => {
22
22
  element.style[key] = style[key];
23
23
  });
24
24
  return oldStyle;
@@ -1,52 +1,44 @@
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
  /* eslint-disable @typescript-eslint/ban-types */
8
2
  /* eslint-disable no-param-reassign */
9
- var NO_EXIST = {
3
+ const NO_EXIST = {
10
4
  __NOT_EXIST: true
11
5
  };
12
6
  export function spyElementPrototypes(elementClass, properties) {
13
- var propNames = Object.keys(properties);
14
- var originDescriptors = {};
15
- propNames.forEach(function (propName) {
16
- var originDescriptor = Object.getOwnPropertyDescriptor(elementClass.prototype, propName);
7
+ const propNames = Object.keys(properties);
8
+ const originDescriptors = {};
9
+ propNames.forEach(propName => {
10
+ const originDescriptor = Object.getOwnPropertyDescriptor(elementClass.prototype, propName);
17
11
  originDescriptors[propName] = originDescriptor || NO_EXIST;
18
- var spyProp = properties[propName];
12
+ const spyProp = properties[propName];
19
13
  if (typeof spyProp === 'function') {
20
14
  // If is a function
21
- elementClass.prototype[propName] = function spyFunc() {
22
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
23
- args[_key] = arguments[_key];
24
- }
25
- return spyProp.call.apply(spyProp, [this, originDescriptor].concat(args));
15
+ elementClass.prototype[propName] = function spyFunc(...args) {
16
+ return spyProp.call(this, originDescriptor, ...args);
26
17
  };
27
18
  } else {
28
19
  // Otherwise tread as a property
29
- Object.defineProperty(elementClass.prototype, propName, _objectSpread(_objectSpread({}, spyProp), {}, {
30
- set: function set(value) {
20
+ Object.defineProperty(elementClass.prototype, propName, {
21
+ ...spyProp,
22
+ set(value) {
31
23
  if (spyProp.set) {
32
24
  return spyProp.set.call(this, originDescriptor, value);
33
25
  }
34
26
  return originDescriptor.set(value);
35
27
  },
36
- get: function get() {
28
+ get() {
37
29
  if (spyProp.get) {
38
30
  return spyProp.get.call(this, originDescriptor);
39
31
  }
40
32
  return originDescriptor.get();
41
33
  },
42
34
  configurable: true
43
- }));
35
+ });
44
36
  }
45
37
  });
46
38
  return {
47
- mockRestore: function mockRestore() {
48
- propNames.forEach(function (propName) {
49
- var originDescriptor = originDescriptors[propName];
39
+ mockRestore() {
40
+ propNames.forEach(propName => {
41
+ const originDescriptor = originDescriptors[propName];
50
42
  if (originDescriptor === NO_EXIST) {
51
43
  delete elementClass.prototype[propName];
52
44
  } else if (typeof originDescriptor === 'function') {
@@ -59,6 +51,8 @@ export function spyElementPrototypes(elementClass, properties) {
59
51
  };
60
52
  }
61
53
  export function spyElementPrototype(Element, propName, property) {
62
- return spyElementPrototypes(Element, _defineProperty({}, propName, property));
54
+ return spyElementPrototypes(Element, {
55
+ [propName]: property
56
+ });
63
57
  }
64
58
  /* eslint-enable */
package/es/utils/get.js CHANGED
@@ -1,6 +1,6 @@
1
1
  export default function get(entity, path) {
2
- var current = entity;
3
- for (var i = 0; i < path.length; i += 1) {
2
+ let current = entity;
3
+ for (let i = 0; i < path.length; i += 1) {
4
4
  if (current === null || current === undefined) {
5
5
  return undefined;
6
6
  }
package/es/utils/set.js CHANGED
@@ -1,33 +1,18 @@
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
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
8
- 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."); }
9
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
10
- function _toArray(arr) { return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest(); }
11
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
12
- 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); }
13
- 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; }
14
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
15
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
16
1
  import get from "./get";
17
2
  function internalSet(entity, paths, value, removeIfUndefined) {
18
3
  if (!paths.length) {
19
4
  return value;
20
5
  }
21
- var _paths = _toArray(paths),
22
- path = _paths[0],
23
- restPath = _paths.slice(1);
24
- var clone;
6
+ const [path, ...restPath] = paths;
7
+ let clone;
25
8
  if (!entity && typeof path === 'number') {
26
9
  clone = [];
27
10
  } else if (Array.isArray(entity)) {
28
- clone = _toConsumableArray(entity);
11
+ clone = [...entity];
29
12
  } else {
30
- clone = _objectSpread({}, entity);
13
+ clone = {
14
+ ...entity
15
+ };
31
16
  }
32
17
 
33
18
  // Delete prop if `removeIfUndefined` and value is undefined
@@ -38,8 +23,7 @@ function internalSet(entity, paths, value, removeIfUndefined) {
38
23
  }
39
24
  return clone;
40
25
  }
41
- export default function set(entity, paths, value) {
42
- var removeIfUndefined = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
26
+ export default function set(entity, paths, value, removeIfUndefined = false) {
43
27
  // Do nothing if `removeIfUndefined` and parent object not exist
44
28
  if (paths.length && removeIfUndefined && value === undefined && !get(entity, paths.slice(0, -1))) {
45
29
  return entity;
@@ -47,40 +31,37 @@ export default function set(entity, paths, value) {
47
31
  return internalSet(entity, paths, value, removeIfUndefined);
48
32
  }
49
33
  function isObject(obj) {
50
- return _typeof(obj) === 'object' && obj !== null && Object.getPrototypeOf(obj) === Object.prototype;
34
+ return typeof obj === 'object' && obj !== null && Object.getPrototypeOf(obj) === Object.prototype;
51
35
  }
52
36
  function createEmpty(source) {
53
37
  return Array.isArray(source) ? [] : {};
54
38
  }
55
- var keys = typeof Reflect === 'undefined' ? Object.keys : Reflect.ownKeys;
39
+ const keys = typeof Reflect === 'undefined' ? Object.keys : Reflect.ownKeys;
56
40
 
57
41
  /**
58
42
  * Merge objects which will create
59
43
  */
60
- export function merge() {
61
- for (var _len = arguments.length, sources = new Array(_len), _key = 0; _key < _len; _key++) {
62
- sources[_key] = arguments[_key];
63
- }
64
- var clone = createEmpty(sources[0]);
65
- sources.forEach(function (src) {
44
+ export function merge(...sources) {
45
+ let clone = createEmpty(sources[0]);
46
+ sources.forEach(src => {
66
47
  function internalMerge(path, parentLoopSet) {
67
- var loopSet = new Set(parentLoopSet);
68
- var value = get(src, path);
69
- var isArr = Array.isArray(value);
48
+ const loopSet = new Set(parentLoopSet);
49
+ const value = get(src, path);
50
+ const isArr = Array.isArray(value);
70
51
  if (isArr || isObject(value)) {
71
52
  // Only add not loop obj
72
53
  if (!loopSet.has(value)) {
73
54
  loopSet.add(value);
74
- var originValue = get(clone, path);
55
+ const originValue = get(clone, path);
75
56
  if (isArr) {
76
57
  // Array will always be override
77
58
  clone = set(clone, path, []);
78
- } else if (!originValue || _typeof(originValue) !== 'object') {
59
+ } else if (!originValue || typeof originValue !== 'object') {
79
60
  // Init container if not exist
80
61
  clone = set(clone, path, createEmpty(value));
81
62
  }
82
- keys(value).forEach(function (key) {
83
- internalMerge([].concat(_toConsumableArray(path), [key]), loopSet);
63
+ keys(value).forEach(key => {
64
+ internalMerge([...path, key], loopSet);
84
65
  });
85
66
  }
86
67
  } else {
package/es/warning.js CHANGED
@@ -1,12 +1,12 @@
1
1
  /* eslint-disable no-console */
2
- var warned = {};
3
- var preWarningFns = [];
2
+ let warned = {};
3
+ const preWarningFns = [];
4
4
 
5
5
  /**
6
6
  * Pre warning enable you to parse content before console.error.
7
7
  * Modify to null will prevent warning.
8
8
  */
9
- export var preMessage = function preMessage(fn) {
9
+ export const preMessage = fn => {
10
10
  preWarningFns.push(fn);
11
11
  };
12
12
 
@@ -23,11 +23,9 @@ export var preMessage = function preMessage(fn) {
23
23
  */
24
24
  export function warning(valid, message) {
25
25
  if (process.env.NODE_ENV !== 'production' && !valid && console !== undefined) {
26
- var finalMessage = preWarningFns.reduce(function (msg, preMessageFn) {
27
- return preMessageFn(msg !== null && msg !== void 0 ? msg : '', 'warning');
28
- }, message);
26
+ const finalMessage = preWarningFns.reduce((msg, preMessageFn) => preMessageFn(msg ?? '', 'warning'), message);
29
27
  if (finalMessage) {
30
- console.error("Warning: ".concat(finalMessage));
28
+ console.error(`Warning: ${finalMessage}`);
31
29
  }
32
30
  }
33
31
  }
@@ -35,11 +33,9 @@ export function warning(valid, message) {
35
33
  /** @see Similar to {@link warning} */
36
34
  export function note(valid, message) {
37
35
  if (process.env.NODE_ENV !== 'production' && !valid && console !== undefined) {
38
- var finalMessage = preWarningFns.reduce(function (msg, preMessageFn) {
39
- return preMessageFn(msg !== null && msg !== void 0 ? msg : '', 'note');
40
- }, message);
36
+ const finalMessage = preWarningFns.reduce((msg, preMessageFn) => preMessageFn(msg ?? '', 'note'), message);
41
37
  if (finalMessage) {
42
- console.warn("Note: ".concat(finalMessage));
38
+ console.warn(`Note: ${finalMessage}`);
43
39
  }
44
40
  }
45
41
  }
@@ -7,10 +7,9 @@ exports.default = toArray;
7
7
  var _isFragment = _interopRequireDefault(require("../React/isFragment"));
8
8
  var _react = _interopRequireDefault(require("react"));
9
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
- function toArray(children) {
11
- var option = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
12
- var ret = [];
13
- _react.default.Children.forEach(children, function (child) {
10
+ function toArray(children, option = {}) {
11
+ let ret = [];
12
+ _react.default.Children.forEach(children, child => {
14
13
  if ((child === undefined || child === null) && !option.keepEmpty) {
15
14
  return;
16
15
  }
@@ -15,7 +15,7 @@ function contains(root, n) {
15
15
  }
16
16
 
17
17
  // `document.contains` not support with IE11
18
- var node = n;
18
+ let node = n;
19
19
  while (node) {
20
20
  if (node === root) {
21
21
  return true;
@@ -10,21 +10,15 @@ exports.updateCSS = updateCSS;
10
10
  var _canUseDom = _interopRequireDefault(require("./canUseDom"));
11
11
  var _contains = _interopRequireDefault(require("./contains"));
12
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
- 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); }
14
- 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; }
15
- 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; }
16
- 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; }
17
- function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
18
- 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); }
19
- var APPEND_ORDER = 'data-rc-order';
20
- var APPEND_PRIORITY = 'data-rc-priority';
21
- var MARK_KEY = "rc-util-key";
22
- var containerCache = new Map();
23
- function getMark() {
24
- var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
25
- mark = _ref.mark;
13
+ const APPEND_ORDER = 'data-rc-order';
14
+ const APPEND_PRIORITY = 'data-rc-priority';
15
+ const MARK_KEY = `rc-util-key`;
16
+ const containerCache = new Map();
17
+ function getMark({
18
+ mark
19
+ } = {}) {
26
20
  if (mark) {
27
- return mark.startsWith('data-') ? mark : "data-".concat(mark);
21
+ return mark.startsWith('data-') ? mark : `data-${mark}`;
28
22
  }
29
23
  return MARK_KEY;
30
24
  }
@@ -32,7 +26,7 @@ function getContainer(option) {
32
26
  if (option.attachTo) {
33
27
  return option.attachTo;
34
28
  }
35
- var head = document.querySelector('head');
29
+ const head = document.querySelector('head');
36
30
  return head || document.body;
37
31
  }
38
32
  function getOrder(prepend) {
@@ -46,43 +40,43 @@ function getOrder(prepend) {
46
40
  * Find style which inject by rc-util
47
41
  */
48
42
  function findStyles(container) {
49
- return Array.from((containerCache.get(container) || container).children).filter(function (node) {
50
- return node.tagName === 'STYLE';
51
- });
43
+ return Array.from((containerCache.get(container) || container).children).filter(node => node.tagName === 'STYLE');
52
44
  }
53
- function injectCSS(css) {
54
- var option = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
45
+ function injectCSS(css, option = {}) {
55
46
  if (!(0, _canUseDom.default)()) {
56
47
  return null;
57
48
  }
58
- var csp = option.csp,
59
- prepend = option.prepend,
60
- _option$priority = option.priority,
61
- priority = _option$priority === void 0 ? 0 : _option$priority;
62
- var mergedOrder = getOrder(prepend);
63
- var isPrependQueue = mergedOrder === 'prependQueue';
64
- var styleNode = document.createElement('style');
49
+ const {
50
+ csp,
51
+ prepend,
52
+ priority = 0
53
+ } = option;
54
+ const mergedOrder = getOrder(prepend);
55
+ const isPrependQueue = mergedOrder === 'prependQueue';
56
+ const styleNode = document.createElement('style');
65
57
  styleNode.setAttribute(APPEND_ORDER, mergedOrder);
66
58
  if (isPrependQueue && priority) {
67
- styleNode.setAttribute(APPEND_PRIORITY, "".concat(priority));
59
+ styleNode.setAttribute(APPEND_PRIORITY, `${priority}`);
68
60
  }
69
- if (csp !== null && csp !== void 0 && csp.nonce) {
70
- styleNode.nonce = csp === null || csp === void 0 ? void 0 : csp.nonce;
61
+ if (csp?.nonce) {
62
+ styleNode.nonce = csp?.nonce;
71
63
  }
72
64
  styleNode.innerHTML = css;
73
- var container = getContainer(option);
74
- var firstChild = container.firstChild;
65
+ const container = getContainer(option);
66
+ const {
67
+ firstChild
68
+ } = container;
75
69
  if (prepend) {
76
70
  // If is queue `prepend`, it will prepend first style and then append rest style
77
71
  if (isPrependQueue) {
78
- var existStyle = (option.styles || findStyles(container)).filter(function (node) {
72
+ const existStyle = (option.styles || findStyles(container)).filter(node => {
79
73
  // Ignore style which not injected by rc-util with prepend
80
74
  if (!['prepend', 'prependQueue'].includes(node.getAttribute(APPEND_ORDER))) {
81
75
  return false;
82
76
  }
83
77
 
84
78
  // Ignore style which priority less then new style
85
- var nodePriority = Number(node.getAttribute(APPEND_PRIORITY) || 0);
79
+ const nodePriority = Number(node.getAttribute(APPEND_PRIORITY) || 0);
86
80
  return priority >= nodePriority;
87
81
  });
88
82
  if (existStyle.length) {
@@ -98,18 +92,14 @@ function injectCSS(css) {
98
92
  }
99
93
  return styleNode;
100
94
  }
101
- function findExistNode(key) {
102
- var option = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
103
- var container = getContainer(option);
104
- return (option.styles || findStyles(container)).find(function (node) {
105
- return node.getAttribute(getMark(option)) === key;
106
- });
95
+ function findExistNode(key, option = {}) {
96
+ const container = getContainer(option);
97
+ return (option.styles || findStyles(container)).find(node => node.getAttribute(getMark(option)) === key);
107
98
  }
108
- function removeCSS(key) {
109
- var option = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
110
- var existNode = findExistNode(key, option);
99
+ function removeCSS(key, option = {}) {
100
+ const existNode = findExistNode(key, option);
111
101
  if (existNode) {
112
- var container = getContainer(option);
102
+ const container = getContainer(option);
113
103
  container.removeChild(existNode);
114
104
  }
115
105
  }
@@ -118,12 +108,14 @@ function removeCSS(key) {
118
108
  * qiankun will inject `appendChild` to insert into other
119
109
  */
120
110
  function syncRealContainer(container, option) {
121
- var cachedRealContainer = containerCache.get(container);
111
+ const cachedRealContainer = containerCache.get(container);
122
112
 
123
113
  // Find real container when not cached or cached container removed
124
114
  if (!cachedRealContainer || !(0, _contains.default)(document, cachedRealContainer)) {
125
- var placeholderStyle = injectCSS('', option);
126
- var parentNode = placeholderStyle.parentNode;
115
+ const placeholderStyle = injectCSS('', option);
116
+ const {
117
+ parentNode
118
+ } = placeholderStyle;
127
119
  containerCache.set(container, parentNode);
128
120
  container.removeChild(placeholderStyle);
129
121
  }
@@ -135,29 +127,27 @@ function syncRealContainer(container, option) {
135
127
  function clearContainerCache() {
136
128
  containerCache.clear();
137
129
  }
138
- function updateCSS(css, key) {
139
- var originOption = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
140
- var container = getContainer(originOption);
141
- var styles = findStyles(container);
142
- var option = _objectSpread(_objectSpread({}, originOption), {}, {
143
- styles: styles
144
- });
130
+ function updateCSS(css, key, originOption = {}) {
131
+ const container = getContainer(originOption);
132
+ const styles = findStyles(container);
133
+ const option = {
134
+ ...originOption,
135
+ styles
136
+ };
145
137
 
146
138
  // Sync real parent
147
139
  syncRealContainer(container, option);
148
- var existNode = findExistNode(key, option);
140
+ const existNode = findExistNode(key, option);
149
141
  if (existNode) {
150
- var _option$csp, _option$csp2;
151
- 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)) {
152
- var _option$csp3;
153
- existNode.nonce = (_option$csp3 = option.csp) === null || _option$csp3 === void 0 ? void 0 : _option$csp3.nonce;
142
+ if (option.csp?.nonce && existNode.nonce !== option.csp?.nonce) {
143
+ existNode.nonce = option.csp?.nonce;
154
144
  }
155
145
  if (existNode.innerHTML !== css) {
156
146
  existNode.innerHTML = css;
157
147
  }
158
148
  return existNode;
159
149
  }
160
- var newNode = injectCSS(css, option);
150
+ const newNode = injectCSS(css, option);
161
151
  newNode.setAttribute(getMark(option), key);
162
152
  return newNode;
163
153
  }
@@ -9,7 +9,6 @@ exports.isDOM = isDOM;
9
9
  var _react = _interopRequireDefault(require("react"));
10
10
  var _reactDom = _interopRequireDefault(require("react-dom"));
11
11
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
12
- 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); }
13
12
  function isDOM(node) {
14
13
  // https://developer.mozilla.org/en-US/docs/Web/API/Element
15
14
  // Since XULElement is also subclass of Element, we only need HTMLElement and SVGElement
@@ -20,7 +19,7 @@ function isDOM(node) {
20
19
  * Retrieves a DOM node via a ref, and does not invoke `findDOMNode`.
21
20
  */
22
21
  function getDOM(node) {
23
- if (node && _typeof(node) === 'object' && isDOM(node.nativeElement)) {
22
+ if (node && typeof node === 'object' && isDOM(node.nativeElement)) {
24
23
  return node.nativeElement;
25
24
  }
26
25
  if (isDOM(node)) {
@@ -33,13 +32,12 @@ function getDOM(node) {
33
32
  * Return if a node is a DOM node. Else will return by `findDOMNode`
34
33
  */
35
34
  function findDOMNode(node) {
36
- var domNode = getDOM(node);
35
+ const domNode = getDOM(node);
37
36
  if (domNode) {
38
37
  return domNode;
39
38
  }
40
39
  if (node instanceof _react.default.Component) {
41
- var _ReactDOM$findDOMNode;
42
- return (_ReactDOM$findDOMNode = _reactDom.default.findDOMNode) === null || _ReactDOM$findDOMNode === void 0 ? void 0 : _ReactDOM$findDOMNode.call(_reactDom.default, node);
40
+ return _reactDom.default.findDOMNode?.(node);
43
41
  }
44
42
  return null;
45
43
  }