@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/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
|
|
5
|
+
export const fillRef = (ref, node) => {
|
|
7
6
|
if (typeof ref === 'function') {
|
|
8
7
|
ref(node);
|
|
9
|
-
} else if (
|
|
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
|
|
18
|
-
|
|
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
|
|
26
|
-
refs.forEach(
|
|
21
|
+
return node => {
|
|
22
|
+
refs.forEach(ref => {
|
|
27
23
|
fillRef(ref, node);
|
|
28
24
|
});
|
|
29
25
|
};
|
|
30
26
|
};
|
|
31
|
-
export
|
|
32
|
-
|
|
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,
|
|
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
|
|
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
|
-
|
|
41
|
+
const type = isMemo(nodeOrComponent) ? nodeOrComponent.type.type : nodeOrComponent.type;
|
|
56
42
|
|
|
57
43
|
// Function component node
|
|
58
|
-
if (typeof type === 'function' && !
|
|
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' && !
|
|
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
|
|
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
|
|
66
|
+
export const getNodeRef = node => {
|
|
81
67
|
if (node && isReactElement(node)) {
|
|
82
|
-
|
|
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
|
-
|
|
13
|
-
element =
|
|
14
|
-
|
|
15
|
-
|
|
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(
|
|
18
|
+
styleKeys.forEach(key => {
|
|
19
19
|
oldStyle[key] = element.style[key];
|
|
20
20
|
});
|
|
21
|
-
styleKeys.forEach(
|
|
21
|
+
styleKeys.forEach(key => {
|
|
22
22
|
element.style[key] = style[key];
|
|
23
23
|
});
|
|
24
24
|
return oldStyle;
|
package/es/test/domHook.js
CHANGED
|
@@ -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
|
-
|
|
3
|
+
const NO_EXIST = {
|
|
10
4
|
__NOT_EXIST: true
|
|
11
5
|
};
|
|
12
6
|
export function spyElementPrototypes(elementClass, properties) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
propNames.forEach(
|
|
16
|
-
|
|
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
|
-
|
|
12
|
+
const spyProp = properties[propName];
|
|
19
13
|
if (typeof spyProp === 'function') {
|
|
20
14
|
// If is a function
|
|
21
|
-
elementClass.prototype[propName] = function spyFunc() {
|
|
22
|
-
|
|
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,
|
|
30
|
-
|
|
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
|
|
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
|
|
48
|
-
propNames.forEach(
|
|
49
|
-
|
|
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,
|
|
54
|
+
return spyElementPrototypes(Element, {
|
|
55
|
+
[propName]: property
|
|
56
|
+
});
|
|
63
57
|
}
|
|
64
58
|
/* eslint-enable */
|
package/es/utils/get.js
CHANGED
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
|
-
|
|
22
|
-
|
|
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 =
|
|
11
|
+
clone = [...entity];
|
|
29
12
|
} else {
|
|
30
|
-
clone =
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
62
|
-
|
|
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
|
-
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
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 ||
|
|
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(
|
|
83
|
-
internalMerge([
|
|
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
|
-
|
|
3
|
-
|
|
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
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
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(
|
|
38
|
+
console.warn(`Note: ${finalMessage}`);
|
|
43
39
|
}
|
|
44
40
|
}
|
|
45
41
|
}
|
package/lib/Children/toArray.js
CHANGED
|
@@ -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
|
-
|
|
12
|
-
|
|
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
|
}
|
package/lib/Dom/contains.js
CHANGED
package/lib/Dom/dynamicCSS.js
CHANGED
|
@@ -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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
function
|
|
18
|
-
|
|
19
|
-
|
|
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 :
|
|
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
|
-
|
|
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(
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
priority =
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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,
|
|
59
|
+
styleNode.setAttribute(APPEND_PRIORITY, `${priority}`);
|
|
68
60
|
}
|
|
69
|
-
if (csp
|
|
70
|
-
styleNode.nonce = csp
|
|
61
|
+
if (csp?.nonce) {
|
|
62
|
+
styleNode.nonce = csp?.nonce;
|
|
71
63
|
}
|
|
72
64
|
styleNode.innerHTML = css;
|
|
73
|
-
|
|
74
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
103
|
-
|
|
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
|
-
|
|
110
|
-
var existNode = findExistNode(key, option);
|
|
99
|
+
function removeCSS(key, option = {}) {
|
|
100
|
+
const existNode = findExistNode(key, option);
|
|
111
101
|
if (existNode) {
|
|
112
|
-
|
|
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
|
-
|
|
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
|
-
|
|
126
|
-
|
|
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
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
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
|
-
|
|
140
|
+
const existNode = findExistNode(key, option);
|
|
149
141
|
if (existNode) {
|
|
150
|
-
|
|
151
|
-
|
|
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
|
-
|
|
150
|
+
const newNode = injectCSS(css, option);
|
|
161
151
|
newNode.setAttribute(getMark(option), key);
|
|
162
152
|
return newNode;
|
|
163
153
|
}
|
package/lib/Dom/findDOMNode.js
CHANGED
|
@@ -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 &&
|
|
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
|
-
|
|
35
|
+
const domNode = getDOM(node);
|
|
37
36
|
if (domNode) {
|
|
38
37
|
return domNode;
|
|
39
38
|
}
|
|
40
39
|
if (node instanceof _react.default.Component) {
|
|
41
|
-
|
|
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
|
}
|