@rc-component/util 1.0.0
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/LICENSE +22 -0
- package/README.md +303 -0
- package/es/Children/toArray.d.ts +5 -0
- package/es/Children/toArray.js +19 -0
- package/es/Dom/canUseDom.d.ts +1 -0
- package/es/Dom/canUseDom.js +3 -0
- package/es/Dom/contains.d.ts +1 -0
- package/es/Dom/contains.js +20 -0
- package/es/Dom/dynamicCSS.d.ts +25 -0
- package/es/Dom/dynamicCSS.js +153 -0
- package/es/Dom/findDOMNode.d.ts +12 -0
- package/es/Dom/findDOMNode.js +36 -0
- package/es/Dom/focus.d.ts +8 -0
- package/es/Dom/focus.js +87 -0
- package/es/Dom/isVisible.d.ts +2 -0
- package/es/Dom/isVisible.js +27 -0
- package/es/Dom/scrollLocker.d.ts +12 -0
- package/es/Dom/scrollLocker.js +135 -0
- package/es/Dom/shadow.d.ts +8 -0
- package/es/Dom/shadow.js +18 -0
- package/es/Dom/styleChecker.d.ts +2 -0
- package/es/Dom/styleChecker.js +26 -0
- package/es/KeyCode.d.ts +436 -0
- package/es/KeyCode.js +538 -0
- package/es/Portal.d.ts +9 -0
- package/es/Portal.js +44 -0
- package/es/PortalWrapper.d.ts +51 -0
- package/es/PortalWrapper.js +217 -0
- package/es/React/isFragment.d.ts +4 -0
- package/es/React/isFragment.js +18 -0
- package/es/React/render.d.ts +13 -0
- package/es/React/render.js +114 -0
- package/es/composeProps.d.ts +2 -0
- package/es/composeProps.js +24 -0
- package/es/getScrollBarSize.d.ts +7 -0
- package/es/getScrollBarSize.js +76 -0
- package/es/hooks/useEffect.d.ts +2 -0
- package/es/hooks/useEffect.js +14 -0
- package/es/hooks/useEvent.d.ts +2 -0
- package/es/hooks/useEvent.js +16 -0
- package/es/hooks/useId.d.ts +4 -0
- package/es/hooks/useId.js +69 -0
- package/es/hooks/useLayoutEffect.d.ts +4 -0
- package/es/hooks/useLayoutEffect.js +30 -0
- package/es/hooks/useMemo.d.ts +1 -0
- package/es/hooks/useMemo.js +9 -0
- package/es/hooks/useMergedState.d.ts +12 -0
- package/es/hooks/useMergedState.js +68 -0
- package/es/hooks/useMobile.d.ts +6 -0
- package/es/hooks/useMobile.js +25 -0
- package/es/hooks/useState.d.ts +14 -0
- package/es/hooks/useState.js +32 -0
- package/es/hooks/useSyncState.d.ts +9 -0
- package/es/hooks/useSyncState.js +29 -0
- package/es/index.d.ts +6 -0
- package/es/index.js +6 -0
- package/es/isEqual.d.ts +9 -0
- package/es/isEqual.js +55 -0
- package/es/isMobile.d.ts +2 -0
- package/es/isMobile.js +7 -0
- package/es/omit.d.ts +1 -0
- package/es/omit.js +9 -0
- package/es/pickAttrs.d.ts +11 -0
- package/es/pickAttrs.js +51 -0
- package/es/proxyObject.d.ts +4 -0
- package/es/proxyObject.js +19 -0
- package/es/raf.d.ts +6 -0
- package/es/raf.js +54 -0
- package/es/ref.d.ts +19 -0
- package/es/ref.js +89 -0
- package/es/setStyle.d.ts +12 -0
- package/es/setStyle.js +26 -0
- package/es/test/domHook.d.ts +8 -0
- package/es/test/domHook.js +64 -0
- package/es/utils/get.d.ts +1 -0
- package/es/utils/get.js +10 -0
- package/es/utils/set.d.ts +6 -0
- package/es/utils/set.js +93 -0
- package/es/warning.d.ts +32 -0
- package/es/warning.js +68 -0
- package/lib/Children/toArray.d.ts +5 -0
- package/lib/Children/toArray.js +26 -0
- package/lib/Dom/canUseDom.d.ts +1 -0
- package/lib/Dom/canUseDom.js +9 -0
- package/lib/Dom/contains.d.ts +1 -0
- package/lib/Dom/contains.js +26 -0
- package/lib/Dom/dynamicCSS.d.ts +25 -0
- package/lib/Dom/dynamicCSS.js +163 -0
- package/lib/Dom/findDOMNode.d.ts +12 -0
- package/lib/Dom/findDOMNode.js +45 -0
- package/lib/Dom/focus.d.ts +8 -0
- package/lib/Dom/focus.js +98 -0
- package/lib/Dom/isVisible.d.ts +2 -0
- package/lib/Dom/isVisible.js +33 -0
- package/lib/Dom/scrollLocker.d.ts +12 -0
- package/lib/Dom/scrollLocker.js +141 -0
- package/lib/Dom/shadow.d.ts +8 -0
- package/lib/Dom/shadow.js +25 -0
- package/lib/Dom/styleChecker.d.ts +2 -0
- package/lib/Dom/styleChecker.js +33 -0
- package/lib/KeyCode.d.ts +436 -0
- package/lib/KeyCode.js +544 -0
- package/lib/Portal.d.ts +9 -0
- package/lib/Portal.js +51 -0
- package/lib/PortalWrapper.d.ts +51 -0
- package/lib/PortalWrapper.js +226 -0
- package/lib/React/isFragment.d.ts +4 -0
- package/lib/React/isFragment.js +24 -0
- package/lib/React/render.d.ts +13 -0
- package/lib/React/render.js +125 -0
- package/lib/composeProps.d.ts +2 -0
- package/lib/composeProps.js +30 -0
- package/lib/getScrollBarSize.d.ts +7 -0
- package/lib/getScrollBarSize.js +84 -0
- package/lib/hooks/useEffect.d.ts +2 -0
- package/lib/hooks/useEffect.js +22 -0
- package/lib/hooks/useEvent.d.ts +2 -0
- package/lib/hooks/useEvent.js +26 -0
- package/lib/hooks/useId.d.ts +4 -0
- package/lib/hooks/useId.js +78 -0
- package/lib/hooks/useLayoutEffect.d.ts +4 -0
- package/lib/hooks/useLayoutEffect.js +39 -0
- package/lib/hooks/useMemo.d.ts +1 -0
- package/lib/hooks/useMemo.js +18 -0
- package/lib/hooks/useMergedState.d.ts +12 -0
- package/lib/hooks/useMergedState.js +75 -0
- package/lib/hooks/useMobile.d.ts +6 -0
- package/lib/hooks/useMobile.js +31 -0
- package/lib/hooks/useState.d.ts +14 -0
- package/lib/hooks/useState.js +41 -0
- package/lib/hooks/useSyncState.d.ts +9 -0
- package/lib/hooks/useSyncState.js +39 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.js +60 -0
- package/lib/isEqual.d.ts +9 -0
- package/lib/isEqual.js +61 -0
- package/lib/isMobile.d.ts +2 -0
- package/lib/isMobile.js +13 -0
- package/lib/omit.d.ts +1 -0
- package/lib/omit.js +15 -0
- package/lib/pickAttrs.d.ts +11 -0
- package/lib/pickAttrs.js +57 -0
- package/lib/proxyObject.d.ts +4 -0
- package/lib/proxyObject.js +25 -0
- package/lib/raf.d.ts +6 -0
- package/lib/raf.js +60 -0
- package/lib/ref.d.ts +19 -0
- package/lib/ref.js +96 -0
- package/lib/setStyle.d.ts +12 -0
- package/lib/setStyle.js +32 -0
- package/lib/test/domHook.d.ts +8 -0
- package/lib/test/domHook.js +71 -0
- package/lib/utils/get.d.ts +1 -0
- package/lib/utils/get.js +16 -0
- package/lib/utils/set.d.ts +6 -0
- package/lib/utils/set.js +101 -0
- package/lib/warning.d.ts +32 -0
- package/lib/warning.js +81 -0
- package/package.json +76 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import canUseDom from "../Dom/canUseDom";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Wrap `React.useLayoutEffect` which will not throw warning message in test env
|
|
6
|
+
*/
|
|
7
|
+
var useInternalLayoutEffect = process.env.NODE_ENV !== 'test' && canUseDom() ? React.useLayoutEffect : React.useEffect;
|
|
8
|
+
var useLayoutEffect = function useLayoutEffect(callback, deps) {
|
|
9
|
+
var firstMountRef = React.useRef(true);
|
|
10
|
+
useInternalLayoutEffect(function () {
|
|
11
|
+
return callback(firstMountRef.current);
|
|
12
|
+
}, deps);
|
|
13
|
+
|
|
14
|
+
// We tell react that first mount has passed
|
|
15
|
+
useInternalLayoutEffect(function () {
|
|
16
|
+
firstMountRef.current = false;
|
|
17
|
+
return function () {
|
|
18
|
+
firstMountRef.current = true;
|
|
19
|
+
};
|
|
20
|
+
}, []);
|
|
21
|
+
};
|
|
22
|
+
export var useLayoutUpdateEffect = function useLayoutUpdateEffect(callback, deps) {
|
|
23
|
+
useLayoutEffect(function (firstMount) {
|
|
24
|
+
if (!firstMount) {
|
|
25
|
+
return callback();
|
|
26
|
+
}
|
|
27
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
28
|
+
}, deps);
|
|
29
|
+
};
|
|
30
|
+
export default useLayoutEffect;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function useMemo<Value, Condition = any[]>(getValue: () => Value, condition: Condition, shouldUpdate: (prev: Condition, next: Condition) => boolean): Value;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export default function useMemo(getValue, condition, shouldUpdate) {
|
|
3
|
+
var cacheRef = React.useRef({});
|
|
4
|
+
if (!('value' in cacheRef.current) || shouldUpdate(cacheRef.current.condition, condition)) {
|
|
5
|
+
cacheRef.current.value = getValue();
|
|
6
|
+
cacheRef.current.condition = condition;
|
|
7
|
+
}
|
|
8
|
+
return cacheRef.current.value;
|
|
9
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
type Updater<T> = (updater: T | ((origin: T) => T), ignoreDestroy?: boolean) => void;
|
|
2
|
+
/**
|
|
3
|
+
* Similar to `useState` but will use props value if provided.
|
|
4
|
+
* Note that internal use rc-util `useState` hook.
|
|
5
|
+
*/
|
|
6
|
+
export default function useMergedState<T, R = T>(defaultStateValue: T | (() => T), option?: {
|
|
7
|
+
defaultValue?: T | (() => T);
|
|
8
|
+
value?: T;
|
|
9
|
+
onChange?: (value: T, prevValue: T) => void;
|
|
10
|
+
postState?: (value: T) => T;
|
|
11
|
+
}): [R, Updater<T>];
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
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."); }
|
|
3
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
|
+
function _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; }
|
|
5
|
+
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; } }
|
|
6
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
+
import useEvent from "./useEvent";
|
|
8
|
+
import { useLayoutUpdateEffect } from "./useLayoutEffect";
|
|
9
|
+
import useState from "./useState";
|
|
10
|
+
/** We only think `undefined` is empty */
|
|
11
|
+
function hasValue(value) {
|
|
12
|
+
return value !== undefined;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Similar to `useState` but will use props value if provided.
|
|
17
|
+
* Note that internal use rc-util `useState` hook.
|
|
18
|
+
*/
|
|
19
|
+
export default function useMergedState(defaultStateValue, option) {
|
|
20
|
+
var _ref = option || {},
|
|
21
|
+
defaultValue = _ref.defaultValue,
|
|
22
|
+
value = _ref.value,
|
|
23
|
+
onChange = _ref.onChange,
|
|
24
|
+
postState = _ref.postState;
|
|
25
|
+
|
|
26
|
+
// ======================= Init =======================
|
|
27
|
+
var _useState = useState(function () {
|
|
28
|
+
if (hasValue(value)) {
|
|
29
|
+
return value;
|
|
30
|
+
} else if (hasValue(defaultValue)) {
|
|
31
|
+
return typeof defaultValue === 'function' ? defaultValue() : defaultValue;
|
|
32
|
+
} else {
|
|
33
|
+
return typeof defaultStateValue === 'function' ? defaultStateValue() : defaultStateValue;
|
|
34
|
+
}
|
|
35
|
+
}),
|
|
36
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
37
|
+
innerValue = _useState2[0],
|
|
38
|
+
setInnerValue = _useState2[1];
|
|
39
|
+
var mergedValue = value !== undefined ? value : innerValue;
|
|
40
|
+
var postMergedValue = postState ? postState(mergedValue) : mergedValue;
|
|
41
|
+
|
|
42
|
+
// ====================== Change ======================
|
|
43
|
+
var onChangeFn = useEvent(onChange);
|
|
44
|
+
var _useState3 = useState([mergedValue]),
|
|
45
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
46
|
+
prevValue = _useState4[0],
|
|
47
|
+
setPrevValue = _useState4[1];
|
|
48
|
+
useLayoutUpdateEffect(function () {
|
|
49
|
+
var prev = prevValue[0];
|
|
50
|
+
if (innerValue !== prev) {
|
|
51
|
+
onChangeFn(innerValue, prev);
|
|
52
|
+
}
|
|
53
|
+
}, [prevValue]);
|
|
54
|
+
|
|
55
|
+
// Sync value back to `undefined` when it from control to un-control
|
|
56
|
+
useLayoutUpdateEffect(function () {
|
|
57
|
+
if (!hasValue(value)) {
|
|
58
|
+
setInnerValue(value);
|
|
59
|
+
}
|
|
60
|
+
}, [value]);
|
|
61
|
+
|
|
62
|
+
// ====================== Update ======================
|
|
63
|
+
var triggerChange = useEvent(function (updater, ignoreDestroy) {
|
|
64
|
+
setInnerValue(updater, ignoreDestroy);
|
|
65
|
+
setPrevValue([mergedValue], ignoreDestroy);
|
|
66
|
+
});
|
|
67
|
+
return [postMergedValue, triggerChange];
|
|
68
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
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."); }
|
|
3
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
|
+
function _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; }
|
|
5
|
+
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; } }
|
|
6
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
+
import { useState } from 'react';
|
|
8
|
+
import isMobile from "../isMobile";
|
|
9
|
+
import useLayoutEffect from "./useLayoutEffect";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Hook to detect if the user is on a mobile device
|
|
13
|
+
* Notice that this hook will only detect the device type in effect, so it will always be false in server side
|
|
14
|
+
*/
|
|
15
|
+
var useMobile = function useMobile() {
|
|
16
|
+
var _useState = useState(false),
|
|
17
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
18
|
+
mobile = _useState2[0],
|
|
19
|
+
setMobile = _useState2[1];
|
|
20
|
+
useLayoutEffect(function () {
|
|
21
|
+
setMobile(isMobile());
|
|
22
|
+
}, []);
|
|
23
|
+
return mobile;
|
|
24
|
+
};
|
|
25
|
+
export default useMobile;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
type Updater<T> = T | ((prevValue: T) => T);
|
|
2
|
+
export type SetState<T> = (nextValue: Updater<T>,
|
|
3
|
+
/**
|
|
4
|
+
* Will not update state when destroyed.
|
|
5
|
+
* Developer should make sure this is safe to ignore.
|
|
6
|
+
*/
|
|
7
|
+
ignoreDestroy?: boolean) => void;
|
|
8
|
+
/**
|
|
9
|
+
* Same as React.useState but `setState` accept `ignoreDestroy` param to not to setState after destroyed.
|
|
10
|
+
* We do not make this auto is to avoid real memory leak.
|
|
11
|
+
* Developer should confirm it's safe to ignore themselves.
|
|
12
|
+
*/
|
|
13
|
+
export default function useSafeState<T>(defaultValue?: T | (() => T)): [T, SetState<T>];
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
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."); }
|
|
3
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
|
+
function _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; }
|
|
5
|
+
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; } }
|
|
6
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
+
import * as React from 'react';
|
|
8
|
+
/**
|
|
9
|
+
* Same as React.useState but `setState` accept `ignoreDestroy` param to not to setState after destroyed.
|
|
10
|
+
* We do not make this auto is to avoid real memory leak.
|
|
11
|
+
* Developer should confirm it's safe to ignore themselves.
|
|
12
|
+
*/
|
|
13
|
+
export default function useSafeState(defaultValue) {
|
|
14
|
+
var destroyRef = React.useRef(false);
|
|
15
|
+
var _React$useState = React.useState(defaultValue),
|
|
16
|
+
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
17
|
+
value = _React$useState2[0],
|
|
18
|
+
setValue = _React$useState2[1];
|
|
19
|
+
React.useEffect(function () {
|
|
20
|
+
destroyRef.current = false;
|
|
21
|
+
return function () {
|
|
22
|
+
destroyRef.current = true;
|
|
23
|
+
};
|
|
24
|
+
}, []);
|
|
25
|
+
function safeSetState(updater, ignoreDestroy) {
|
|
26
|
+
if (ignoreDestroy && destroyRef.current) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
setValue(updater);
|
|
30
|
+
}
|
|
31
|
+
return [value, safeSetState];
|
|
32
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
type Updater<T> = T | ((prevValue: T) => T);
|
|
2
|
+
export type SetState<T> = (nextValue: Updater<T>) => void;
|
|
3
|
+
/**
|
|
4
|
+
* Same as React.useState but will always get latest state.
|
|
5
|
+
* This is useful when React merge multiple state updates into one.
|
|
6
|
+
* e.g. onTransitionEnd trigger multiple event at once will be merged state update in React.
|
|
7
|
+
*/
|
|
8
|
+
export default function useSyncState<T>(defaultValue?: T): [get: () => T, set: SetState<T>];
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
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."); }
|
|
3
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
4
|
+
function _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; }
|
|
5
|
+
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; } }
|
|
6
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
+
import * as React from 'react';
|
|
8
|
+
import useEvent from "./useEvent";
|
|
9
|
+
/**
|
|
10
|
+
* Same as React.useState but will always get latest state.
|
|
11
|
+
* This is useful when React merge multiple state updates into one.
|
|
12
|
+
* e.g. onTransitionEnd trigger multiple event at once will be merged state update in React.
|
|
13
|
+
*/
|
|
14
|
+
export default function useSyncState(defaultValue) {
|
|
15
|
+
var _React$useReducer = React.useReducer(function (x) {
|
|
16
|
+
return x + 1;
|
|
17
|
+
}, 0),
|
|
18
|
+
_React$useReducer2 = _slicedToArray(_React$useReducer, 2),
|
|
19
|
+
forceUpdate = _React$useReducer2[1];
|
|
20
|
+
var currentValueRef = React.useRef(defaultValue);
|
|
21
|
+
var getValue = useEvent(function () {
|
|
22
|
+
return currentValueRef.current;
|
|
23
|
+
});
|
|
24
|
+
var setValue = useEvent(function (updater) {
|
|
25
|
+
currentValueRef.current = typeof updater === 'function' ? updater(currentValueRef.current) : updater;
|
|
26
|
+
forceUpdate();
|
|
27
|
+
});
|
|
28
|
+
return [getValue, setValue];
|
|
29
|
+
}
|
package/es/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { default as useEvent } from './hooks/useEvent';
|
|
2
|
+
export { default as useMergedState } from './hooks/useMergedState';
|
|
3
|
+
export { supportNodeRef, supportRef, useComposeRef } from './ref';
|
|
4
|
+
export { default as get } from './utils/get';
|
|
5
|
+
export { default as set } from './utils/set';
|
|
6
|
+
export { default as warning } from './warning';
|
package/es/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { default as useEvent } from "./hooks/useEvent";
|
|
2
|
+
export { default as useMergedState } from "./hooks/useMergedState";
|
|
3
|
+
export { supportNodeRef, supportRef, useComposeRef } from "./ref";
|
|
4
|
+
export { default as get } from "./utils/get";
|
|
5
|
+
export { default as set } from "./utils/set";
|
|
6
|
+
export { default as warning } from "./warning";
|
package/es/isEqual.d.ts
ADDED
package/es/isEqual.js
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
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
|
+
import warning from "./warning";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Deeply compares two object literals.
|
|
6
|
+
* @param obj1 object 1
|
|
7
|
+
* @param obj2 object 2
|
|
8
|
+
* @param shallow shallow compare
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
function isEqual(obj1, obj2) {
|
|
12
|
+
var shallow = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
13
|
+
// https://github.com/mapbox/mapbox-gl-js/pull/5979/files#diff-fde7145050c47cc3a306856efd5f9c3016e86e859de9afbd02c879be5067e58f
|
|
14
|
+
var refSet = new Set();
|
|
15
|
+
function deepEqual(a, b) {
|
|
16
|
+
var level = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
|
|
17
|
+
var circular = refSet.has(a);
|
|
18
|
+
warning(!circular, 'Warning: There may be circular references');
|
|
19
|
+
if (circular) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
if (a === b) {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
if (shallow && level > 1) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
refSet.add(a);
|
|
29
|
+
var newLevel = level + 1;
|
|
30
|
+
if (Array.isArray(a)) {
|
|
31
|
+
if (!Array.isArray(b) || a.length !== b.length) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
for (var i = 0; i < a.length; i++) {
|
|
35
|
+
if (!deepEqual(a[i], b[i], newLevel)) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
if (a && b && _typeof(a) === 'object' && _typeof(b) === 'object') {
|
|
42
|
+
var keys = Object.keys(a);
|
|
43
|
+
if (keys.length !== Object.keys(b).length) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
return keys.every(function (key) {
|
|
47
|
+
return deepEqual(a[key], b[key], newLevel);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
// other
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
return deepEqual(obj1, obj2);
|
|
54
|
+
}
|
|
55
|
+
export default isEqual;
|
package/es/isMobile.d.ts
ADDED
package/es/isMobile.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export default (function () {
|
|
2
|
+
if (typeof navigator === 'undefined' || typeof window === 'undefined') {
|
|
3
|
+
return false;
|
|
4
|
+
}
|
|
5
|
+
var agent = navigator.userAgent || navigator.vendor || window.opera;
|
|
6
|
+
return /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk/i.test(agent) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw-(n|u)|c55\/|capi|ccwa|cdm-|cell|chtm|cldc|cmd-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc-s|devi|dica|dmob|do(c|p)o|ds(12|-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(-|_)|g1 u|g560|gene|gf-5|g-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd-(m|p|t)|hei-|hi(pt|ta)|hp( i|ip)|hs-c|ht(c(-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i-(20|go|ma)|i230|iac( |-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|-[a-w])|libw|lynx|m1-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|-([1-8]|c))|phil|pire|pl(ay|uc)|pn-2|po(ck|rt|se)|prox|psio|pt-g|qa-a|qc(07|12|21|32|60|-[2-7]|i-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h-|oo|p-)|sdk\/|se(c(-|0|1)|47|mc|nd|ri)|sgh-|shar|sie(-|m)|sk-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h-|v-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl-|tdg-|tel(i|m)|tim-|t-mo|to(pl|sh)|ts(70|m-|m3|m5)|tx-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas-|your|zeto|zte-/i.test(agent === null || agent === void 0 ? void 0 : agent.substr(0, 4));
|
|
7
|
+
});
|
package/es/omit.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function omit<T extends object, K extends keyof T>(obj: T, fields: K[] | readonly K[]): Omit<T, K>;
|
package/es/omit.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface PickConfig {
|
|
2
|
+
aria?: boolean;
|
|
3
|
+
data?: boolean;
|
|
4
|
+
attr?: boolean;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* Picker props from exist props with filter
|
|
8
|
+
* @param props Passed props
|
|
9
|
+
* @param ariaOnly boolean | { aria?: boolean; data?: boolean; attr?: boolean; } filter config
|
|
10
|
+
*/
|
|
11
|
+
export default function pickAttrs(props: object, ariaOnly?: boolean | PickConfig): {};
|
package/es/pickAttrs.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
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
|
+
var attributes = "accept acceptCharset accessKey action allowFullScreen allowTransparency\n alt async autoComplete autoFocus autoPlay capture cellPadding cellSpacing challenge\n charSet checked classID className colSpan cols content contentEditable contextMenu\n controls coords crossOrigin data dateTime default defer dir disabled download draggable\n encType form formAction formEncType formMethod formNoValidate formTarget frameBorder\n headers height hidden high href hrefLang htmlFor httpEquiv icon id inputMode integrity\n is keyParams keyType kind label lang list loop low manifest marginHeight marginWidth max maxLength media\n mediaGroup method min minLength multiple muted name noValidate nonce open\n optimum pattern placeholder poster preload radioGroup readOnly rel required\n reversed role rowSpan rows sandbox scope scoped scrolling seamless selected\n shape size sizes span spellCheck src srcDoc srcLang srcSet start step style\n summary tabIndex target title type useMap value width wmode wrap";
|
|
8
|
+
var eventsName = "onCopy onCut onPaste onCompositionEnd onCompositionStart onCompositionUpdate onKeyDown\n onKeyPress onKeyUp onFocus onBlur onChange onInput onSubmit onClick onContextMenu onDoubleClick\n onDrag onDragEnd onDragEnter onDragExit onDragLeave onDragOver onDragStart onDrop onMouseDown\n onMouseEnter onMouseLeave onMouseMove onMouseOut onMouseOver onMouseUp onSelect onTouchCancel\n onTouchEnd onTouchMove onTouchStart onScroll onWheel onAbort onCanPlay onCanPlayThrough\n onDurationChange onEmptied onEncrypted onEnded onError onLoadedData onLoadedMetadata\n onLoadStart onPause onPlay onPlaying onProgress onRateChange onSeeked onSeeking onStalled onSuspend onTimeUpdate onVolumeChange onWaiting onLoad onError";
|
|
9
|
+
var propList = "".concat(attributes, " ").concat(eventsName).split(/[\s\n]+/);
|
|
10
|
+
|
|
11
|
+
/* eslint-enable max-len */
|
|
12
|
+
var ariaPrefix = 'aria-';
|
|
13
|
+
var dataPrefix = 'data-';
|
|
14
|
+
function match(key, prefix) {
|
|
15
|
+
return key.indexOf(prefix) === 0;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Picker props from exist props with filter
|
|
19
|
+
* @param props Passed props
|
|
20
|
+
* @param ariaOnly boolean | { aria?: boolean; data?: boolean; attr?: boolean; } filter config
|
|
21
|
+
*/
|
|
22
|
+
export default function pickAttrs(props) {
|
|
23
|
+
var ariaOnly = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
24
|
+
var mergedConfig;
|
|
25
|
+
if (ariaOnly === false) {
|
|
26
|
+
mergedConfig = {
|
|
27
|
+
aria: true,
|
|
28
|
+
data: true,
|
|
29
|
+
attr: true
|
|
30
|
+
};
|
|
31
|
+
} else if (ariaOnly === true) {
|
|
32
|
+
mergedConfig = {
|
|
33
|
+
aria: true
|
|
34
|
+
};
|
|
35
|
+
} else {
|
|
36
|
+
mergedConfig = _objectSpread({}, ariaOnly);
|
|
37
|
+
}
|
|
38
|
+
var attrs = {};
|
|
39
|
+
Object.keys(props).forEach(function (key) {
|
|
40
|
+
if (
|
|
41
|
+
// Aria
|
|
42
|
+
mergedConfig.aria && (key === 'role' || match(key, ariaPrefix)) ||
|
|
43
|
+
// Data
|
|
44
|
+
mergedConfig.data && match(key, dataPrefix) ||
|
|
45
|
+
// Attr
|
|
46
|
+
mergedConfig.attr && propList.includes(key)) {
|
|
47
|
+
attrs[key] = props[key];
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
return attrs;
|
|
51
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Proxy object if environment supported
|
|
3
|
+
*/
|
|
4
|
+
export default function proxyObject(obj, extendProps) {
|
|
5
|
+
if (typeof Proxy !== 'undefined' && obj) {
|
|
6
|
+
return new Proxy(obj, {
|
|
7
|
+
get: function get(target, prop) {
|
|
8
|
+
if (extendProps[prop]) {
|
|
9
|
+
return extendProps[prop];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
// Proxy origin property
|
|
13
|
+
var originProp = target[prop];
|
|
14
|
+
return typeof originProp === 'function' ? originProp.bind(target) : originProp;
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return obj;
|
|
19
|
+
}
|
package/es/raf.d.ts
ADDED
package/es/raf.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
var raf = function raf(callback) {
|
|
2
|
+
return +setTimeout(callback, 16);
|
|
3
|
+
};
|
|
4
|
+
var caf = function caf(num) {
|
|
5
|
+
return clearTimeout(num);
|
|
6
|
+
};
|
|
7
|
+
if (typeof window !== 'undefined' && 'requestAnimationFrame' in window) {
|
|
8
|
+
raf = function raf(callback) {
|
|
9
|
+
return window.requestAnimationFrame(callback);
|
|
10
|
+
};
|
|
11
|
+
caf = function caf(handle) {
|
|
12
|
+
return window.cancelAnimationFrame(handle);
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
var rafUUID = 0;
|
|
16
|
+
var rafIds = new Map();
|
|
17
|
+
function cleanup(id) {
|
|
18
|
+
rafIds.delete(id);
|
|
19
|
+
}
|
|
20
|
+
var wrapperRaf = function wrapperRaf(callback) {
|
|
21
|
+
var times = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
|
|
22
|
+
rafUUID += 1;
|
|
23
|
+
var id = rafUUID;
|
|
24
|
+
function callRef(leftTimes) {
|
|
25
|
+
if (leftTimes === 0) {
|
|
26
|
+
// Clean up
|
|
27
|
+
cleanup(id);
|
|
28
|
+
|
|
29
|
+
// Trigger
|
|
30
|
+
callback();
|
|
31
|
+
} else {
|
|
32
|
+
// Next raf
|
|
33
|
+
var realId = raf(function () {
|
|
34
|
+
callRef(leftTimes - 1);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// Bind real raf id
|
|
38
|
+
rafIds.set(id, realId);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
callRef(times);
|
|
42
|
+
return id;
|
|
43
|
+
};
|
|
44
|
+
wrapperRaf.cancel = function (id) {
|
|
45
|
+
var realId = rafIds.get(id);
|
|
46
|
+
cleanup(id);
|
|
47
|
+
return caf(realId);
|
|
48
|
+
};
|
|
49
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
50
|
+
wrapperRaf.ids = function () {
|
|
51
|
+
return rafIds;
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
export default wrapperRaf;
|
package/es/ref.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type * as React from 'react';
|
|
2
|
+
export declare const fillRef: <T>(ref: React.Ref<T>, node: T) => void;
|
|
3
|
+
/**
|
|
4
|
+
* Merge refs into one ref function to support ref passing.
|
|
5
|
+
*/
|
|
6
|
+
export declare const composeRef: <T>(...refs: React.Ref<T>[]) => React.Ref<T>;
|
|
7
|
+
export declare const useComposeRef: <T>(...refs: React.Ref<T>[]) => React.Ref<T>;
|
|
8
|
+
export declare const supportRef: (nodeOrComponent: any) => boolean;
|
|
9
|
+
interface RefAttributes<T> extends React.Attributes {
|
|
10
|
+
ref: React.Ref<T>;
|
|
11
|
+
}
|
|
12
|
+
export declare const supportNodeRef: <T = any>(node: React.ReactNode) => node is React.ReactElement<any, string | React.JSXElementConstructor<any>> & RefAttributes<T>;
|
|
13
|
+
/**
|
|
14
|
+
* In React 19. `ref` is not a property from node.
|
|
15
|
+
* But a property from `props.ref`.
|
|
16
|
+
* To check if `props.ref` exist or fallback to `ref`.
|
|
17
|
+
*/
|
|
18
|
+
export declare const getNodeRef: <T = any>(node: React.ReactNode) => React.Ref<T> | null;
|
|
19
|
+
export {};
|
package/es/ref.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
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
|
+
import { isValidElement } from 'react';
|
|
3
|
+
import { ForwardRef, isMemo } from 'react-is';
|
|
4
|
+
import useMemo from "./hooks/useMemo";
|
|
5
|
+
import isFragment from "./React/isFragment";
|
|
6
|
+
export var fillRef = function fillRef(ref, node) {
|
|
7
|
+
if (typeof ref === 'function') {
|
|
8
|
+
ref(node);
|
|
9
|
+
} else if (_typeof(ref) === 'object' && ref && 'current' in ref) {
|
|
10
|
+
ref.current = node;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Merge refs into one ref function to support ref passing.
|
|
16
|
+
*/
|
|
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);
|
|
22
|
+
if (refList.length <= 1) {
|
|
23
|
+
return refList[0];
|
|
24
|
+
}
|
|
25
|
+
return function (node) {
|
|
26
|
+
refs.forEach(function (ref) {
|
|
27
|
+
fillRef(ref, node);
|
|
28
|
+
});
|
|
29
|
+
};
|
|
30
|
+
};
|
|
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
|
+
},
|
|
38
|
+
// 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
|
+
});
|
|
44
|
+
};
|
|
45
|
+
export var supportRef = function supportRef(nodeOrComponent) {
|
|
46
|
+
var _type$prototype, _nodeOrComponent$prot;
|
|
47
|
+
if (!nodeOrComponent) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// React 19 no need `forwardRef` anymore. So just pass if is a React element.
|
|
52
|
+
if (isReactElement(nodeOrComponent) && nodeOrComponent.props.propertyIsEnumerable('ref')) {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
var type = isMemo(nodeOrComponent) ? nodeOrComponent.type.type : nodeOrComponent.type;
|
|
56
|
+
|
|
57
|
+
// Function component node
|
|
58
|
+
if (typeof type === 'function' && !((_type$prototype = type.prototype) !== null && _type$prototype !== void 0 && _type$prototype.render) && type.$$typeof !== ForwardRef) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Class component
|
|
63
|
+
if (typeof nodeOrComponent === 'function' && !((_nodeOrComponent$prot = nodeOrComponent.prototype) !== null && _nodeOrComponent$prot !== void 0 && _nodeOrComponent$prot.render) && nodeOrComponent.$$typeof !== ForwardRef) {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
return true;
|
|
67
|
+
};
|
|
68
|
+
function isReactElement(node) {
|
|
69
|
+
return /*#__PURE__*/isValidElement(node) && !isFragment(node);
|
|
70
|
+
}
|
|
71
|
+
export var supportNodeRef = function supportNodeRef(node) {
|
|
72
|
+
return isReactElement(node) && supportRef(node);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* In React 19. `ref` is not a property from node.
|
|
77
|
+
* But a property from `props.ref`.
|
|
78
|
+
* To check if `props.ref` exist or fallback to `ref`.
|
|
79
|
+
*/
|
|
80
|
+
export var getNodeRef = function getNodeRef(node) {
|
|
81
|
+
if (node && isReactElement(node)) {
|
|
82
|
+
var ele = node;
|
|
83
|
+
|
|
84
|
+
// Source from:
|
|
85
|
+
// https://github.com/mui/material-ui/blob/master/packages/mui-utils/src/getReactNodeRef/getReactNodeRef.ts
|
|
86
|
+
return ele.props.propertyIsEnumerable('ref') ? ele.props.ref : ele.ref;
|
|
87
|
+
}
|
|
88
|
+
return null;
|
|
89
|
+
};
|
package/es/setStyle.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type React from 'react';
|
|
2
|
+
export interface SetStyleOptions {
|
|
3
|
+
element?: HTMLElement;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Easy to set element style, return previous style
|
|
7
|
+
* IE browser compatible(IE browser doesn't merge overflow style, need to set it separately)
|
|
8
|
+
* https://github.com/ant-design/ant-design/issues/19393
|
|
9
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
declare function setStyle(style: React.CSSProperties, options?: SetStyleOptions): React.CSSProperties;
|
|
12
|
+
export default setStyle;
|