@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/lib/getScrollBarSize.js
CHANGED
|
@@ -8,14 +8,14 @@ exports.getTargetScrollBarSize = getTargetScrollBarSize;
|
|
|
8
8
|
var _dynamicCSS = require("./Dom/dynamicCSS");
|
|
9
9
|
/* eslint-disable no-param-reassign */
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
let cached;
|
|
12
12
|
function measureScrollbarSize(ele) {
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
const randomId = `rc-scrollbar-measure-${Math.random().toString(36).substring(7)}`;
|
|
14
|
+
const measureEle = document.createElement('div');
|
|
15
15
|
measureEle.id = randomId;
|
|
16
16
|
|
|
17
17
|
// Create Style
|
|
18
|
-
|
|
18
|
+
const measureStyle = measureEle.style;
|
|
19
19
|
measureStyle.position = 'absolute';
|
|
20
20
|
measureStyle.left = '0';
|
|
21
21
|
measureStyle.top = '0';
|
|
@@ -24,23 +24,27 @@ function measureScrollbarSize(ele) {
|
|
|
24
24
|
measureStyle.overflow = 'scroll';
|
|
25
25
|
|
|
26
26
|
// Clone Style if needed
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
let fallbackWidth;
|
|
28
|
+
let fallbackHeight;
|
|
29
29
|
if (ele) {
|
|
30
|
-
|
|
30
|
+
const targetStyle = getComputedStyle(ele);
|
|
31
31
|
measureStyle.scrollbarColor = targetStyle.scrollbarColor;
|
|
32
32
|
measureStyle.scrollbarWidth = targetStyle.scrollbarWidth;
|
|
33
33
|
|
|
34
34
|
// Set Webkit style
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
const webkitScrollbarStyle = getComputedStyle(ele, '::-webkit-scrollbar');
|
|
36
|
+
const width = parseInt(webkitScrollbarStyle.width, 10);
|
|
37
|
+
const height = parseInt(webkitScrollbarStyle.height, 10);
|
|
38
38
|
|
|
39
39
|
// Try wrap to handle CSP case
|
|
40
40
|
try {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
(0, _dynamicCSS.updateCSS)(
|
|
41
|
+
const widthStyle = width ? `width: ${webkitScrollbarStyle.width};` : '';
|
|
42
|
+
const heightStyle = height ? `height: ${webkitScrollbarStyle.height};` : '';
|
|
43
|
+
(0, _dynamicCSS.updateCSS)(`
|
|
44
|
+
#${randomId}::-webkit-scrollbar {
|
|
45
|
+
${widthStyle}
|
|
46
|
+
${heightStyle}
|
|
47
|
+
}`, randomId);
|
|
44
48
|
} catch (e) {
|
|
45
49
|
// Can't wrap, just log error
|
|
46
50
|
console.error(e);
|
|
@@ -53,8 +57,8 @@ function measureScrollbarSize(ele) {
|
|
|
53
57
|
document.body.appendChild(measureEle);
|
|
54
58
|
|
|
55
59
|
// Measure. Get fallback style if provided
|
|
56
|
-
|
|
57
|
-
|
|
60
|
+
const scrollWidth = ele && fallbackWidth && !isNaN(fallbackWidth) ? fallbackWidth : measureEle.offsetWidth - measureEle.clientWidth;
|
|
61
|
+
const scrollHeight = ele && fallbackHeight && !isNaN(fallbackHeight) ? fallbackHeight : measureEle.offsetHeight - measureEle.clientHeight;
|
|
58
62
|
|
|
59
63
|
// Clean up
|
|
60
64
|
document.body.removeChild(measureEle);
|
package/lib/hooks/useEffect.js
CHANGED
|
@@ -1,20 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
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); }
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.default = useEffect;
|
|
8
7
|
var React = _interopRequireWildcard(require("react"));
|
|
9
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function
|
|
10
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" !=
|
|
8
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
9
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
11
10
|
/** As `React.useEffect` but pass origin value in callback and not need care deps length change. */
|
|
12
11
|
function useEffect(callback, deps) {
|
|
13
|
-
|
|
14
|
-
React.useEffect(
|
|
15
|
-
if (deps.length !== prevRef.current.length || deps.some(
|
|
16
|
-
return dep !== prevRef.current[index];
|
|
17
|
-
})) {
|
|
12
|
+
const prevRef = React.useRef(deps);
|
|
13
|
+
React.useEffect(() => {
|
|
14
|
+
if (deps.length !== prevRef.current.length || deps.some((dep, index) => dep !== prevRef.current[index])) {
|
|
18
15
|
callback(prevRef.current);
|
|
19
16
|
}
|
|
20
17
|
prevRef.current = deps;
|
package/lib/hooks/useEvent.js
CHANGED
|
@@ -1,26 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
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); }
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.default = void 0;
|
|
8
7
|
var React = _interopRequireWildcard(require("react"));
|
|
9
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function
|
|
10
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" !=
|
|
8
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
9
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
11
10
|
/* eslint-disable @typescript-eslint/ban-types */
|
|
12
11
|
/* eslint-disable react-hooks/exhaustive-deps */
|
|
13
12
|
|
|
14
13
|
function useEvent(callback) {
|
|
15
|
-
|
|
14
|
+
const fnRef = React.useRef();
|
|
16
15
|
fnRef.current = callback;
|
|
17
|
-
|
|
18
|
-
var _fnRef$current;
|
|
19
|
-
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
20
|
-
args[_key] = arguments[_key];
|
|
21
|
-
}
|
|
22
|
-
return (_fnRef$current = fnRef.current) === null || _fnRef$current === void 0 ? void 0 : _fnRef$current.call.apply(_fnRef$current, [fnRef].concat(args));
|
|
23
|
-
}, []);
|
|
16
|
+
const memoFn = React.useCallback((...args) => fnRef.current?.(...args), []);
|
|
24
17
|
return memoFn;
|
|
25
18
|
}
|
|
26
19
|
var _default = exports.default = useEvent;
|
package/lib/hooks/useId.js
CHANGED
|
@@ -6,26 +6,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
exports.resetUuid = resetUuid;
|
|
8
8
|
var React = _interopRequireWildcard(require("react"));
|
|
9
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function
|
|
10
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" !=
|
|
11
|
-
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); }
|
|
12
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
13
|
-
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."); }
|
|
14
|
-
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); }
|
|
15
|
-
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; }
|
|
16
|
-
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
17
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
18
|
-
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; }
|
|
19
|
-
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; }
|
|
20
|
-
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; }
|
|
21
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
22
|
-
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); }
|
|
9
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
10
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
23
11
|
function getUseId() {
|
|
24
12
|
// We need fully clone React function here to avoid webpack warning React 17 do not export `useId`
|
|
25
|
-
|
|
13
|
+
const fullClone = {
|
|
14
|
+
...React
|
|
15
|
+
};
|
|
26
16
|
return fullClone.useId;
|
|
27
17
|
}
|
|
28
|
-
|
|
18
|
+
let uuid = 0;
|
|
29
19
|
|
|
30
20
|
/** @private Note only worked in develop env. Not work in production. */
|
|
31
21
|
function resetUuid() {
|
|
@@ -33,11 +23,11 @@ function resetUuid() {
|
|
|
33
23
|
uuid = 0;
|
|
34
24
|
}
|
|
35
25
|
}
|
|
36
|
-
|
|
26
|
+
const useOriginId = getUseId();
|
|
37
27
|
var _default = exports.default = useOriginId ?
|
|
38
28
|
// Use React `useId`
|
|
39
29
|
function useId(id) {
|
|
40
|
-
|
|
30
|
+
const reactId = useOriginId();
|
|
41
31
|
|
|
42
32
|
// Developer passed id is single source of truth
|
|
43
33
|
if (id) {
|
|
@@ -53,14 +43,11 @@ function useId(id) {
|
|
|
53
43
|
// Use compatible of `useId`
|
|
54
44
|
function useCompatId(id) {
|
|
55
45
|
// Inner id for accessibility usage. Only work in client side
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
setInnerId = _React$useState2[1];
|
|
60
|
-
React.useEffect(function () {
|
|
61
|
-
var nextId = uuid;
|
|
46
|
+
const [innerId, setInnerId] = React.useState('ssr-id');
|
|
47
|
+
React.useEffect(() => {
|
|
48
|
+
const nextId = uuid;
|
|
62
49
|
uuid += 1;
|
|
63
|
-
setInnerId(
|
|
50
|
+
setInnerId(`rc_unique_${nextId}`);
|
|
64
51
|
}, []);
|
|
65
52
|
|
|
66
53
|
// Developer passed id is single source of truth
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
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); }
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
@@ -8,32 +7,33 @@ exports.useLayoutUpdateEffect = exports.default = void 0;
|
|
|
8
7
|
var React = _interopRequireWildcard(require("react"));
|
|
9
8
|
var _canUseDom = _interopRequireDefault(require("../Dom/canUseDom"));
|
|
10
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function
|
|
12
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" !=
|
|
10
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
11
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
13
12
|
/**
|
|
14
13
|
* Wrap `React.useLayoutEffect` which will not throw warning message in test env
|
|
15
14
|
*/
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
useInternalLayoutEffect(
|
|
15
|
+
const useInternalLayoutEffect = process.env.NODE_ENV !== 'test' && (0, _canUseDom.default)() ? React.useLayoutEffect : React.useEffect;
|
|
16
|
+
const useLayoutEffect = (callback, deps) => {
|
|
17
|
+
const firstMountRef = React.useRef(true);
|
|
18
|
+
useInternalLayoutEffect(() => {
|
|
20
19
|
return callback(firstMountRef.current);
|
|
21
20
|
}, deps);
|
|
22
21
|
|
|
23
22
|
// We tell react that first mount has passed
|
|
24
|
-
useInternalLayoutEffect(
|
|
23
|
+
useInternalLayoutEffect(() => {
|
|
25
24
|
firstMountRef.current = false;
|
|
26
|
-
return
|
|
25
|
+
return () => {
|
|
27
26
|
firstMountRef.current = true;
|
|
28
27
|
};
|
|
29
28
|
}, []);
|
|
30
29
|
};
|
|
31
|
-
|
|
32
|
-
useLayoutEffect(
|
|
30
|
+
const useLayoutUpdateEffect = (callback, deps) => {
|
|
31
|
+
useLayoutEffect(firstMount => {
|
|
33
32
|
if (!firstMount) {
|
|
34
33
|
return callback();
|
|
35
34
|
}
|
|
36
35
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
37
36
|
}, deps);
|
|
38
37
|
};
|
|
38
|
+
exports.useLayoutUpdateEffect = useLayoutUpdateEffect;
|
|
39
39
|
var _default = exports.default = useLayoutEffect;
|
package/lib/hooks/useMemo.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
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); }
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.default = useMemo;
|
|
8
7
|
var React = _interopRequireWildcard(require("react"));
|
|
9
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function
|
|
10
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" !=
|
|
8
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
9
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
11
10
|
function useMemo(getValue, condition, shouldUpdate) {
|
|
12
|
-
|
|
11
|
+
const cacheRef = React.useRef({});
|
|
13
12
|
if (!('value' in cacheRef.current) || shouldUpdate(cacheRef.current.condition, condition)) {
|
|
14
13
|
cacheRef.current.value = getValue();
|
|
15
14
|
cacheRef.current.condition = condition;
|
|
@@ -6,14 +6,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = useMergedState;
|
|
7
7
|
var _useEvent = _interopRequireDefault(require("./useEvent"));
|
|
8
8
|
var _useLayoutEffect = require("./useLayoutEffect");
|
|
9
|
-
var
|
|
9
|
+
var _useState = _interopRequireDefault(require("./useState"));
|
|
10
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
12
|
-
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."); }
|
|
13
|
-
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); }
|
|
14
|
-
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; }
|
|
15
|
-
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
16
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
17
11
|
/** We only think `undefined` is empty */
|
|
18
12
|
function hasValue(value) {
|
|
19
13
|
return value !== undefined;
|
|
@@ -24,50 +18,45 @@ function hasValue(value) {
|
|
|
24
18
|
* Note that internal use rc-util `useState` hook.
|
|
25
19
|
*/
|
|
26
20
|
function useMergedState(defaultStateValue, option) {
|
|
27
|
-
|
|
28
|
-
defaultValue
|
|
29
|
-
value
|
|
30
|
-
onChange
|
|
31
|
-
postState
|
|
21
|
+
const {
|
|
22
|
+
defaultValue,
|
|
23
|
+
value,
|
|
24
|
+
onChange,
|
|
25
|
+
postState
|
|
26
|
+
} = option || {};
|
|
32
27
|
|
|
33
28
|
// ======================= Init =======================
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
setInnerValue = _useState2[1];
|
|
46
|
-
var mergedValue = value !== undefined ? value : innerValue;
|
|
47
|
-
var postMergedValue = postState ? postState(mergedValue) : mergedValue;
|
|
29
|
+
const [innerValue, setInnerValue] = (0, _useState.default)(() => {
|
|
30
|
+
if (hasValue(value)) {
|
|
31
|
+
return value;
|
|
32
|
+
} else if (hasValue(defaultValue)) {
|
|
33
|
+
return typeof defaultValue === 'function' ? defaultValue() : defaultValue;
|
|
34
|
+
} else {
|
|
35
|
+
return typeof defaultStateValue === 'function' ? defaultStateValue() : defaultStateValue;
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
const mergedValue = value !== undefined ? value : innerValue;
|
|
39
|
+
const postMergedValue = postState ? postState(mergedValue) : mergedValue;
|
|
48
40
|
|
|
49
41
|
// ====================== Change ======================
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
setPrevValue = _useState4[1];
|
|
55
|
-
(0, _useLayoutEffect.useLayoutUpdateEffect)(function () {
|
|
56
|
-
var prev = prevValue[0];
|
|
42
|
+
const onChangeFn = (0, _useEvent.default)(onChange);
|
|
43
|
+
const [prevValue, setPrevValue] = (0, _useState.default)([mergedValue]);
|
|
44
|
+
(0, _useLayoutEffect.useLayoutUpdateEffect)(() => {
|
|
45
|
+
const prev = prevValue[0];
|
|
57
46
|
if (innerValue !== prev) {
|
|
58
47
|
onChangeFn(innerValue, prev);
|
|
59
48
|
}
|
|
60
49
|
}, [prevValue]);
|
|
61
50
|
|
|
62
51
|
// Sync value back to `undefined` when it from control to un-control
|
|
63
|
-
(0, _useLayoutEffect.useLayoutUpdateEffect)(
|
|
52
|
+
(0, _useLayoutEffect.useLayoutUpdateEffect)(() => {
|
|
64
53
|
if (!hasValue(value)) {
|
|
65
54
|
setInnerValue(value);
|
|
66
55
|
}
|
|
67
56
|
}, [value]);
|
|
68
57
|
|
|
69
58
|
// ====================== Update ======================
|
|
70
|
-
|
|
59
|
+
const triggerChange = (0, _useEvent.default)((updater, ignoreDestroy) => {
|
|
71
60
|
setInnerValue(updater, ignoreDestroy);
|
|
72
61
|
setPrevValue([mergedValue], ignoreDestroy);
|
|
73
62
|
});
|
package/lib/hooks/useMobile.js
CHANGED
|
@@ -8,22 +8,13 @@ var _react = require("react");
|
|
|
8
8
|
var _isMobile = _interopRequireDefault(require("../isMobile"));
|
|
9
9
|
var _useLayoutEffect = _interopRequireDefault(require("./useLayoutEffect"));
|
|
10
10
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
12
|
-
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."); }
|
|
13
|
-
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); }
|
|
14
|
-
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; }
|
|
15
|
-
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
16
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
17
11
|
/**
|
|
18
12
|
* Hook to detect if the user is on a mobile device
|
|
19
13
|
* Notice that this hook will only detect the device type in effect, so it will always be false in server side
|
|
20
14
|
*/
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
mobile = _useState2[0],
|
|
25
|
-
setMobile = _useState2[1];
|
|
26
|
-
(0, _useLayoutEffect.default)(function () {
|
|
15
|
+
const useMobile = () => {
|
|
16
|
+
const [mobile, setMobile] = (0, _react.useState)(false);
|
|
17
|
+
(0, _useLayoutEffect.default)(() => {
|
|
27
18
|
setMobile((0, _isMobile.default)());
|
|
28
19
|
}, []);
|
|
29
20
|
return mobile;
|
package/lib/hooks/useState.js
CHANGED
|
@@ -1,33 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
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); }
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.default = useSafeState;
|
|
8
7
|
var React = _interopRequireWildcard(require("react"));
|
|
9
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function
|
|
10
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" !=
|
|
11
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
12
|
-
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."); }
|
|
13
|
-
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); }
|
|
14
|
-
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; }
|
|
15
|
-
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
16
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
8
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
9
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
17
10
|
/**
|
|
18
11
|
* Same as React.useState but `setState` accept `ignoreDestroy` param to not to setState after destroyed.
|
|
19
12
|
* We do not make this auto is to avoid real memory leak.
|
|
20
13
|
* Developer should confirm it's safe to ignore themselves.
|
|
21
14
|
*/
|
|
22
15
|
function useSafeState(defaultValue) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
value = _React$useState2[0],
|
|
27
|
-
setValue = _React$useState2[1];
|
|
28
|
-
React.useEffect(function () {
|
|
16
|
+
const destroyRef = React.useRef(false);
|
|
17
|
+
const [value, setValue] = React.useState(defaultValue);
|
|
18
|
+
React.useEffect(() => {
|
|
29
19
|
destroyRef.current = false;
|
|
30
|
-
return
|
|
20
|
+
return () => {
|
|
31
21
|
destroyRef.current = true;
|
|
32
22
|
};
|
|
33
23
|
}, []);
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
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); }
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
@@ -8,30 +7,20 @@ exports.default = useSyncState;
|
|
|
8
7
|
var React = _interopRequireWildcard(require("react"));
|
|
9
8
|
var _useEvent = _interopRequireDefault(require("./useEvent"));
|
|
10
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function
|
|
12
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" !=
|
|
13
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
14
|
-
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."); }
|
|
15
|
-
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); }
|
|
16
|
-
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; }
|
|
17
|
-
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
18
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
10
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
11
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
19
12
|
/**
|
|
20
13
|
* Same as React.useState but will always get latest state.
|
|
21
14
|
* This is useful when React merge multiple state updates into one.
|
|
22
15
|
* e.g. onTransitionEnd trigger multiple event at once will be merged state update in React.
|
|
23
16
|
*/
|
|
24
17
|
function useSyncState(defaultValue) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
_React$useReducer2 = _slicedToArray(_React$useReducer, 2),
|
|
29
|
-
forceUpdate = _React$useReducer2[1];
|
|
30
|
-
var currentValueRef = React.useRef(defaultValue);
|
|
31
|
-
var getValue = (0, _useEvent.default)(function () {
|
|
18
|
+
const [, forceUpdate] = React.useReducer(x => x + 1, 0);
|
|
19
|
+
const currentValueRef = React.useRef(defaultValue);
|
|
20
|
+
const getValue = (0, _useEvent.default)(() => {
|
|
32
21
|
return currentValueRef.current;
|
|
33
22
|
});
|
|
34
|
-
|
|
23
|
+
const setValue = (0, _useEvent.default)(updater => {
|
|
35
24
|
currentValueRef.current = typeof updater === 'function' ? updater(currentValueRef.current) : updater;
|
|
36
25
|
forceUpdate();
|
|
37
26
|
});
|
package/lib/index.js
CHANGED
|
@@ -5,49 +5,49 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
Object.defineProperty(exports, "get", {
|
|
7
7
|
enumerable: true,
|
|
8
|
-
get: function
|
|
8
|
+
get: function () {
|
|
9
9
|
return _get.default;
|
|
10
10
|
}
|
|
11
11
|
});
|
|
12
12
|
Object.defineProperty(exports, "set", {
|
|
13
13
|
enumerable: true,
|
|
14
|
-
get: function
|
|
14
|
+
get: function () {
|
|
15
15
|
return _set.default;
|
|
16
16
|
}
|
|
17
17
|
});
|
|
18
18
|
Object.defineProperty(exports, "supportNodeRef", {
|
|
19
19
|
enumerable: true,
|
|
20
|
-
get: function
|
|
20
|
+
get: function () {
|
|
21
21
|
return _ref.supportNodeRef;
|
|
22
22
|
}
|
|
23
23
|
});
|
|
24
24
|
Object.defineProperty(exports, "supportRef", {
|
|
25
25
|
enumerable: true,
|
|
26
|
-
get: function
|
|
26
|
+
get: function () {
|
|
27
27
|
return _ref.supportRef;
|
|
28
28
|
}
|
|
29
29
|
});
|
|
30
30
|
Object.defineProperty(exports, "useComposeRef", {
|
|
31
31
|
enumerable: true,
|
|
32
|
-
get: function
|
|
32
|
+
get: function () {
|
|
33
33
|
return _ref.useComposeRef;
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
36
|
Object.defineProperty(exports, "useEvent", {
|
|
37
37
|
enumerable: true,
|
|
38
|
-
get: function
|
|
38
|
+
get: function () {
|
|
39
39
|
return _useEvent.default;
|
|
40
40
|
}
|
|
41
41
|
});
|
|
42
42
|
Object.defineProperty(exports, "useMergedState", {
|
|
43
43
|
enumerable: true,
|
|
44
|
-
get: function
|
|
44
|
+
get: function () {
|
|
45
45
|
return _useMergedState.default;
|
|
46
46
|
}
|
|
47
47
|
});
|
|
48
48
|
Object.defineProperty(exports, "warning", {
|
|
49
49
|
enumerable: true,
|
|
50
|
-
get: function
|
|
50
|
+
get: function () {
|
|
51
51
|
return _warning.default;
|
|
52
52
|
}
|
|
53
53
|
});
|
package/lib/isEqual.js
CHANGED
|
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _warning = _interopRequireDefault(require("./warning"));
|
|
8
8
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
9
|
-
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); }
|
|
10
9
|
/**
|
|
11
10
|
* Deeply compares two object literals.
|
|
12
11
|
* @param obj1 object 1
|
|
@@ -14,13 +13,11 @@ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" ==
|
|
|
14
13
|
* @param shallow shallow compare
|
|
15
14
|
* @returns
|
|
16
15
|
*/
|
|
17
|
-
function isEqual(obj1, obj2) {
|
|
18
|
-
var shallow = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
16
|
+
function isEqual(obj1, obj2, shallow = false) {
|
|
19
17
|
// https://github.com/mapbox/mapbox-gl-js/pull/5979/files#diff-fde7145050c47cc3a306856efd5f9c3016e86e859de9afbd02c879be5067e58f
|
|
20
|
-
|
|
21
|
-
function deepEqual(a, b) {
|
|
22
|
-
|
|
23
|
-
var circular = refSet.has(a);
|
|
18
|
+
const refSet = new Set();
|
|
19
|
+
function deepEqual(a, b, level = 1) {
|
|
20
|
+
const circular = refSet.has(a);
|
|
24
21
|
(0, _warning.default)(!circular, 'Warning: There may be circular references');
|
|
25
22
|
if (circular) {
|
|
26
23
|
return false;
|
|
@@ -32,26 +29,24 @@ function isEqual(obj1, obj2) {
|
|
|
32
29
|
return false;
|
|
33
30
|
}
|
|
34
31
|
refSet.add(a);
|
|
35
|
-
|
|
32
|
+
const newLevel = level + 1;
|
|
36
33
|
if (Array.isArray(a)) {
|
|
37
34
|
if (!Array.isArray(b) || a.length !== b.length) {
|
|
38
35
|
return false;
|
|
39
36
|
}
|
|
40
|
-
for (
|
|
37
|
+
for (let i = 0; i < a.length; i++) {
|
|
41
38
|
if (!deepEqual(a[i], b[i], newLevel)) {
|
|
42
39
|
return false;
|
|
43
40
|
}
|
|
44
41
|
}
|
|
45
42
|
return true;
|
|
46
43
|
}
|
|
47
|
-
if (a && b &&
|
|
48
|
-
|
|
44
|
+
if (a && b && typeof a === 'object' && typeof b === 'object') {
|
|
45
|
+
const keys = Object.keys(a);
|
|
49
46
|
if (keys.length !== Object.keys(b).length) {
|
|
50
47
|
return false;
|
|
51
48
|
}
|
|
52
|
-
return keys.every(
|
|
53
|
-
return deepEqual(a[key], b[key], newLevel);
|
|
54
|
-
});
|
|
49
|
+
return keys.every(key => deepEqual(a[key], b[key], newLevel));
|
|
55
50
|
}
|
|
56
51
|
// other
|
|
57
52
|
return false;
|