@ringcentral/juno 2.2.0 → 2.3.3
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/README.md +1 -2
- package/components/Animations/Highlight/Highlight.d.ts +2 -2
- package/components/Badge/Badge.js +1 -1
- package/components/Downshift/SuggestionList/utils/useSuggestionList.js +1 -2
- package/components/Downshift/utils/useDownshift.js +2 -3
- package/components/Downshift/utils/useDownshiftTag.js +1 -2
- package/components/Forms/Picker/DatePicker/DatePicker.js +10 -11
- package/components/Forms/Select/PlainSelect/PlainSelect.js +1 -2
- package/components/Forms/TextField/styles/ClearIconButton.d.ts +3 -6
- package/components/Forms/TextField/styles/ClearIconButton.js +16 -9
- package/components/PortalHost/Connectable/ThrottleScheduler.d.ts +0 -1
- package/components/PortalHost/Connectable/ThrottleScheduler.js +3 -5
- package/components/Table/Table.d.ts +14 -0
- package/components/Table/Table.js +17 -0
- package/components/Table/TableBody/TableBody.d.ts +8 -0
- package/components/Table/TableBody/TableBody.js +14 -0
- package/components/Table/TableBody/index.d.ts +1 -0
- package/components/Table/TableBody/index.js +4 -0
- package/components/Table/TableCell/TableCell.d.ts +27 -0
- package/components/Table/TableCell/TableCell.js +39 -0
- package/components/Table/TableCell/index.d.ts +1 -0
- package/components/Table/TableCell/index.js +4 -0
- package/components/Table/TableCell/styles/TableCellStyle.d.ts +3 -0
- package/components/Table/TableCell/styles/TableCellStyle.js +16 -0
- package/components/Table/TableCell/styles/index.d.ts +1 -0
- package/components/Table/TableCell/styles/index.js +4 -0
- package/components/Table/TableCell/utils/TableCellUtils.d.ts +1 -0
- package/components/Table/TableCell/utils/TableCellUtils.js +4 -0
- package/components/Table/TableCell/utils/index.d.ts +1 -0
- package/components/Table/TableCell/utils/index.js +4 -0
- package/components/Table/TableContainer/TableContainer.d.ts +19 -0
- package/components/Table/TableContainer/TableContainer.js +22 -0
- package/components/Table/TableContainer/index.d.ts +1 -0
- package/components/Table/TableContainer/index.js +4 -0
- package/components/Table/TableContainer/styles/TableContainerStyle.d.ts +3 -0
- package/components/Table/TableContainer/styles/TableContainerStyle.js +13 -0
- package/components/Table/TableContainer/styles/index.d.ts +1 -0
- package/components/Table/TableContainer/styles/index.js +4 -0
- package/components/Table/TableHead/TableHead.d.ts +8 -0
- package/components/Table/TableHead/TableHead.js +14 -0
- package/components/Table/TableHead/index.d.ts +1 -0
- package/components/Table/TableHead/index.js +4 -0
- package/components/Table/TableRow/TableRow.d.ts +15 -0
- package/components/Table/TableRow/TableRow.js +20 -0
- package/components/Table/TableRow/index.d.ts +1 -0
- package/components/Table/TableRow/index.js +4 -0
- package/components/Table/TableRow/styles/TableRowStyle.d.ts +3 -0
- package/components/Table/TableRow/styles/TableRowStyle.js +9 -0
- package/components/Table/TableRow/styles/index.d.ts +1 -0
- package/components/Table/TableRow/styles/index.js +4 -0
- package/components/Table/TableRow/utils/TableRowUtils.d.ts +1 -0
- package/components/Table/TableRow/utils/TableRowUtils.js +4 -0
- package/components/Table/TableRow/utils/index.d.ts +1 -0
- package/components/Table/TableRow/utils/index.js +4 -0
- package/components/Table/context.d.ts +10 -0
- package/components/Table/context.js +4 -0
- package/components/Table/index.d.ts +8 -0
- package/components/Table/index.js +10 -0
- package/components/Table/types.d.ts +1 -0
- package/components/Table/types.js +2 -0
- package/components/Tables/TableHead.d.ts +1 -1
- package/components/Tables/TableHead.js +1 -3
- package/components/Tables/TableHeadCell.d.ts +1 -1
- package/components/Tables/TableHeadCell.js +1 -2
- package/components/Tooltip/utils/useTooltipForceHide.js +24 -10
- package/components/index.d.ts +1 -1
- package/components/index.js +1 -1
- package/es6/README.md +1 -2
- package/es6/components/Badge/Badge.js +2 -2
- package/es6/components/Downshift/SuggestionList/utils/useSuggestionList.js +1 -2
- package/es6/components/Downshift/utils/useDownshift.js +1 -2
- package/es6/components/Downshift/utils/useDownshiftTag.js +1 -2
- package/es6/components/Forms/Picker/DatePicker/DatePicker.js +1 -2
- package/es6/components/Forms/Select/PlainSelect/PlainSelect.js +1 -2
- package/es6/components/Forms/TextField/styles/ClearIconButton.js +16 -9
- package/es6/components/PortalHost/Connectable/ThrottleScheduler.js +3 -5
- package/es6/components/Table/Table.js +15 -0
- package/es6/components/Table/TableBody/TableBody.js +12 -0
- package/es6/components/Table/TableBody/index.js +1 -0
- package/es6/components/Table/TableCell/TableCell.js +37 -0
- package/es6/components/Table/TableCell/index.js +1 -0
- package/es6/components/Table/TableCell/styles/TableCellStyle.js +14 -0
- package/es6/components/Table/TableCell/styles/index.js +1 -0
- package/es6/components/Table/TableCell/utils/TableCellUtils.js +2 -0
- package/es6/components/Table/TableCell/utils/index.js +1 -0
- package/es6/components/Table/TableContainer/TableContainer.js +20 -0
- package/es6/components/Table/TableContainer/index.js +1 -0
- package/es6/components/Table/TableContainer/styles/TableContainerStyle.js +11 -0
- package/es6/components/Table/TableContainer/styles/index.js +1 -0
- package/es6/components/Table/TableHead/TableHead.js +12 -0
- package/es6/components/Table/TableHead/index.js +1 -0
- package/es6/components/Table/TableRow/TableRow.js +18 -0
- package/es6/components/Table/TableRow/index.js +1 -0
- package/es6/components/Table/TableRow/styles/TableRowStyle.js +7 -0
- package/es6/components/Table/TableRow/styles/index.js +1 -0
- package/es6/components/Table/TableRow/utils/TableRowUtils.js +2 -0
- package/es6/components/Table/TableRow/utils/index.js +1 -0
- package/es6/components/Table/context.js +2 -0
- package/es6/components/Table/index.js +7 -0
- package/es6/components/Table/types.js +0 -0
- package/es6/components/Tables/TableHead.js +1 -3
- package/es6/components/Tables/TableHeadCell.js +2 -3
- package/es6/components/Tooltip/utils/useTooltipForceHide.js +25 -11
- package/es6/components/index.js +1 -1
- package/es6/foundation/hooks/index.js +2 -0
- package/es6/foundation/hooks/useControlled/index.js +1 -0
- package/es6/foundation/hooks/useControlled/useControlled.js +1 -0
- package/es6/foundation/hooks/useEventListener/useEventListener.js +8 -6
- package/es6/foundation/hooks/useGlobalListener/index.js +1 -0
- package/es6/foundation/hooks/useGlobalListener/useGlobalListener.js +130 -0
- package/es6/foundation/hooks/useHiddenTabindex/useHiddenTabindex.js +4 -3
- package/es6/foundation/hooks/useLongPress/useLongPress.js +2 -3
- package/es6/foundation/hooks/useOverflow/useOverflow.js +18 -15
- package/es6/foundation/hooks/useResizeObserver/useResizeObserver.js +4 -4
- package/es6/foundation/hooks/useTouchMouseEvent/useTouchMouseEvent.js +8 -5
- package/es6/foundation/utils/getRefElement.js +13 -0
- package/es6/foundation/utils/index.js +1 -0
- package/es6/foundation/utils/removeClassName.js +4 -3
- package/es6/foundation/utils/selectionHandler.js +7 -6
- package/foundation/hooks/index.d.ts +2 -0
- package/foundation/hooks/index.js +2 -0
- package/foundation/hooks/useControlled/index.d.ts +1 -0
- package/foundation/hooks/useControlled/index.js +4 -0
- package/foundation/hooks/useControlled/useControlled.d.ts +1 -0
- package/foundation/hooks/useControlled/useControlled.js +4 -0
- package/foundation/hooks/useEventListener/useEventListener.d.ts +2 -2
- package/foundation/hooks/useEventListener/useEventListener.js +8 -6
- package/foundation/hooks/useGlobalListener/index.d.ts +1 -0
- package/foundation/hooks/useGlobalListener/index.js +4 -0
- package/foundation/hooks/useGlobalListener/useGlobalListener.d.ts +108 -0
- package/foundation/hooks/useGlobalListener/useGlobalListener.js +133 -0
- package/foundation/hooks/useHiddenTabindex/useHiddenTabindex.d.ts +2 -2
- package/foundation/hooks/useHiddenTabindex/useHiddenTabindex.js +4 -3
- package/foundation/hooks/useLongPress/useLongPress.js +1 -2
- package/foundation/hooks/useOverflow/useOverflow.d.ts +2 -3
- package/foundation/hooks/useOverflow/useOverflow.js +18 -15
- package/foundation/hooks/useResizeObserver/useResizeObserver.d.ts +2 -3
- package/foundation/hooks/useResizeObserver/useResizeObserver.js +3 -3
- package/foundation/hooks/useTouchMouseEvent/useTouchMouseEvent.d.ts +5 -1
- package/foundation/hooks/useTouchMouseEvent/useTouchMouseEvent.js +8 -5
- package/foundation/theme/theme.type.d.ts +6 -3
- package/foundation/utils/getRefElement.d.ts +6 -0
- package/foundation/utils/getRefElement.js +15 -0
- package/foundation/utils/index.d.ts +1 -0
- package/foundation/utils/index.js +1 -0
- package/foundation/utils/removeClassName.d.ts +3 -3
- package/foundation/utils/removeClassName.js +4 -3
- package/foundation/utils/selectionHandler.d.ts +3 -3
- package/foundation/utils/selectionHandler.js +7 -6
- package/package.json +1 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { __assign, __makeTemplateObject, __rest } from "tslib";
|
|
2
|
+
import MuiTableHead from '@material-ui/core/TableHead';
|
|
3
|
+
import React, { forwardRef } from 'react';
|
|
4
|
+
import { styled, useThemeProps } from '../../../foundation';
|
|
5
|
+
var _RcTableHead = forwardRef(function (props, ref) {
|
|
6
|
+
var _a = useThemeProps({ props: props, name: 'RcTableHead' }), children = _a.children, rest = __rest(_a, ["children"]);
|
|
7
|
+
return (React.createElement(MuiTableHead, __assign({}, rest, { ref: ref }), children));
|
|
8
|
+
});
|
|
9
|
+
var RcTableHead = styled(_RcTableHead)(templateObject_1 || (templateObject_1 = __makeTemplateObject([""], [""])));
|
|
10
|
+
RcTableHead.displayName = 'RcTableHead';
|
|
11
|
+
export { RcTableHead };
|
|
12
|
+
var templateObject_1;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './TableHead';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { __assign, __makeTemplateObject, __rest } from "tslib";
|
|
2
|
+
import React, { forwardRef, useMemo } from 'react';
|
|
3
|
+
import MuiTableRow from '@material-ui/core/TableRow';
|
|
4
|
+
import { combineClasses, styled, useThemeProps, } from '../../../foundation';
|
|
5
|
+
import { TableRowStyle } from './styles';
|
|
6
|
+
import { RcTableRowClasses } from './utils';
|
|
7
|
+
import clsx from 'clsx';
|
|
8
|
+
var _RcTableRow = forwardRef(function (props, ref) {
|
|
9
|
+
var _a;
|
|
10
|
+
var _b = useThemeProps({ props: props, name: 'RcTableRow' }), className = _b.className, classesProp = _b.classes, children = _b.children, disabled = _b.disabled, rest = __rest(_b, ["className", "classes", "children", "disabled"]);
|
|
11
|
+
var classes = useMemo(function () { return combineClasses(RcTableRowClasses, classesProp); }, [classesProp]);
|
|
12
|
+
return (React.createElement(MuiTableRow, __assign({}, rest, { ref: ref, classes: classes, className: clsx(className, (_a = {}, _a[RcTableRowClasses.disabled] = disabled, _a)) }), children));
|
|
13
|
+
});
|
|
14
|
+
var RcTableRow = styled(_RcTableRow)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", "\n"], ["\n ", "\n"])), TableRowStyle);
|
|
15
|
+
RcTableRow.defaultProps = {};
|
|
16
|
+
RcTableRow.displayName = 'RcTableRow';
|
|
17
|
+
export { RcTableRow };
|
|
18
|
+
var templateObject_1;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './TableRow';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { __makeTemplateObject } from "tslib";
|
|
2
|
+
import { css, nonTouchHoverMedia, palette2, setOpacity, } from '../../../../foundation';
|
|
3
|
+
import { RcTableRowClasses } from '../utils';
|
|
4
|
+
export var TableRowStyle = function () {
|
|
5
|
+
return css(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", " {\n &.", ", &:hover {\n background-color: ", ";\n }\n }\n\n &.", " {\n &,\n &:hover {\n background-color: ", ";\n }\n }\n\n &.", " {\n &.", ", &.", ", &:hover {\n background-color: unset;\n }\n }\n "], ["\n ", " {\n &.", ", &:hover {\n background-color: ", ";\n }\n }\n\n &.", " {\n &,\n &:hover {\n background-color: ", ";\n }\n }\n\n &.", " {\n &.", ", &.", ", &:hover {\n background-color: unset;\n }\n }\n "])), nonTouchHoverMedia, RcTableRowClasses.hover, setOpacity(palette2('action', 'grayLight'), '08'), RcTableRowClasses.selected, setOpacity(palette2('interactive', 'f01'), '08'), RcTableRowClasses.disabled, RcTableRowClasses.selected, RcTableRowClasses.hover);
|
|
6
|
+
};
|
|
7
|
+
var templateObject_1;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './TableRowStyle';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './TableRowUtils';
|
|
File without changes
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { useThemeProps } from '../../foundation';
|
|
3
2
|
import { StyledTableRow } from './styled';
|
|
4
3
|
import { RcTableHeadCell } from './TableHeadCell';
|
|
5
4
|
import { ORDER_TABLE_BY } from './types';
|
|
6
|
-
var RcTableHeadView = function (
|
|
7
|
-
var props = useThemeProps({ props: inProps, name: 'RcTableHeadView' });
|
|
5
|
+
var RcTableHeadView = function (props) {
|
|
8
6
|
var columnData = props.columnData, sortMap = props.sortMap, sortHandler = props.sortHandler;
|
|
9
7
|
return (React.createElement("thead", null,
|
|
10
8
|
React.createElement(StyledTableRow, null, columnData.map(function (column) {
|
|
@@ -3,12 +3,11 @@ import React, { useMemo } from 'react';
|
|
|
3
3
|
import isFunction from 'lodash/isFunction';
|
|
4
4
|
import isNumber from 'lodash/isNumber';
|
|
5
5
|
import { JumpToLatest as arrowDown, JumpToUnread as arrowUp, } from '@ringcentral/juno-icon';
|
|
6
|
-
import { useA11yKeyEvent
|
|
6
|
+
import { useA11yKeyEvent } from '../../foundation';
|
|
7
7
|
import { RcIcon } from '../Icon';
|
|
8
8
|
import { StyledSortIconWrapper, StyledTableHeadCell, StyledTableHeadCellContent, StyledTableHeadText, } from './styled';
|
|
9
9
|
import { ARIA_SORT_VALUES, ORDER_TABLE_BY, SORT_ICON_CLASS, } from './types';
|
|
10
|
-
var RcTableHeadCell = function (
|
|
11
|
-
var props = useThemeProps({ props: inProps, name: 'RcTableHeadCell' });
|
|
10
|
+
var RcTableHeadCell = function (props) {
|
|
12
11
|
var automationID = props.automationID, title = props.title, width = props.width, sortDirection = props.sortDirection, sortKey = props.sortKey, textAlign = props.textAlign;
|
|
13
12
|
var onClick = function () {
|
|
14
13
|
var sortHandler = props.sortHandler, sortKey = props.sortKey, sortDirection = props.sortDirection;
|
|
@@ -1,8 +1,24 @@
|
|
|
1
1
|
import { __read } from "tslib";
|
|
2
|
+
/* eslint-disable react-hooks/rules-of-hooks */
|
|
2
3
|
import { useRef } from 'react';
|
|
3
|
-
import { useChange, useEventCallback, useEventListener, usePrevious, useRefState, } from '../../../foundation';
|
|
4
|
+
import { logInDev, useChange, useEventCallback, useEventListener, usePrevious, useRefState, } from '../../../foundation';
|
|
4
5
|
export var useTooltipForceHide = function (_a) {
|
|
5
6
|
var tooltipForceHide = _a.tooltipForceHide, openProp = _a.open, onClose = _a.onClose, onOpen = _a.onOpen, ref = _a.ref;
|
|
7
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
8
|
+
useChange(function (prev) {
|
|
9
|
+
// ignore first time
|
|
10
|
+
if (prev !== undefined) {
|
|
11
|
+
logInDev({
|
|
12
|
+
component: 'RcTooltip',
|
|
13
|
+
message: 'Should not change tooltipForceHide between controlled and uncontrolled, tooltipForceHide should always be boolean value',
|
|
14
|
+
level: 'error',
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
}, function () { return tooltipForceHide === undefined; });
|
|
18
|
+
}
|
|
19
|
+
// * when not set tooltipForceHide, always return undefined directly, not bind any event addition
|
|
20
|
+
if (tooltipForceHide === undefined)
|
|
21
|
+
return undefined;
|
|
6
22
|
var _b = __read(useRefState(false), 2), openRef = _b[0], setOpen = _b[1];
|
|
7
23
|
var isOverRef = useRef(false);
|
|
8
24
|
var openState = tooltipForceHide ? false : openProp !== null && openProp !== void 0 ? openProp : openRef.current;
|
|
@@ -35,14 +51,12 @@ export var useTooltipForceHide = function (_a) {
|
|
|
35
51
|
setOpen(false);
|
|
36
52
|
onClose === null || onClose === void 0 ? void 0 : onClose(event);
|
|
37
53
|
});
|
|
38
|
-
return
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
: undefined;
|
|
54
|
+
return {
|
|
55
|
+
disableFocusListener: tooltipForceHide,
|
|
56
|
+
disableHoverListener: tooltipForceHide,
|
|
57
|
+
disableTouchListener: tooltipForceHide,
|
|
58
|
+
open: openState,
|
|
59
|
+
onOpen: handleOpen,
|
|
60
|
+
onClose: handleClose,
|
|
61
|
+
};
|
|
48
62
|
};
|
package/es6/components/index.js
CHANGED
|
@@ -41,7 +41,7 @@ export * from './Responsive';
|
|
|
41
41
|
export * from './Snackbar';
|
|
42
42
|
export * from './Stepper';
|
|
43
43
|
export * from './TablePagination';
|
|
44
|
-
export * from './
|
|
44
|
+
export * from './Table';
|
|
45
45
|
export * from './Tabs';
|
|
46
46
|
export * from './Tag';
|
|
47
47
|
export * from './Text';
|
|
@@ -2,12 +2,14 @@ export * from './useA11yKeyEvent';
|
|
|
2
2
|
export * from './useAnnouncer';
|
|
3
3
|
export * from './useAudio';
|
|
4
4
|
export * from './useChange';
|
|
5
|
+
export * from './useControlled';
|
|
5
6
|
export * from './useDebounce';
|
|
6
7
|
export * from './useEventCallback';
|
|
7
8
|
export * from './useEventListener';
|
|
8
9
|
export * from './useEver';
|
|
9
10
|
export * from './useForceUpdate';
|
|
10
11
|
export * from './useForkRef';
|
|
12
|
+
export * from './useGlobalListener';
|
|
11
13
|
export * from './useHiddenTabindex';
|
|
12
14
|
export * from './useId';
|
|
13
15
|
export * from './useInterval';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useControlled';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useControlled } from '@material-ui/core/utils';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __read } from "tslib";
|
|
2
2
|
import { useEffect, useRef } from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import { getRefElement } from '../../utils';
|
|
4
4
|
import { useEventCallback } from '../useEventCallback';
|
|
5
5
|
/**
|
|
6
6
|
* bind event when component mount and auto remove event when destroy.
|
|
@@ -26,16 +26,18 @@ export function useEventListener(target) {
|
|
|
26
26
|
var listener = useEventCallback(cb);
|
|
27
27
|
var cancelRef = useRef(function () { });
|
|
28
28
|
var bindRef = useRef(function () { });
|
|
29
|
-
var currentRefElm =
|
|
29
|
+
var currentRefElm = getRefElement(target);
|
|
30
30
|
useEffect(function () {
|
|
31
31
|
if (!target)
|
|
32
32
|
return;
|
|
33
|
-
var
|
|
34
|
-
if (!
|
|
33
|
+
var currentElm = getRefElement(target);
|
|
34
|
+
if (!currentElm) {
|
|
35
35
|
return cancelRef.current;
|
|
36
36
|
}
|
|
37
|
-
bindRef.current = function () { return
|
|
38
|
-
cancelRef.current = function () {
|
|
37
|
+
bindRef.current = function () { return currentElm.addEventListener(key, listener, options); };
|
|
38
|
+
cancelRef.current = function () {
|
|
39
|
+
return currentElm.removeEventListener(key, listener, options);
|
|
40
|
+
};
|
|
39
41
|
bindRef.current();
|
|
40
42
|
return cancelRef.current;
|
|
41
43
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useGlobalListener';
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
import { getRefElement, logInDev } from '../../utils';
|
|
3
|
+
import { useEventCallback } from '../useEventCallback';
|
|
4
|
+
export var globalListenerEventMap = new Map();
|
|
5
|
+
/**
|
|
6
|
+
* create globalListener handler for share one listener event
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* const globalListener = createGlobalListener('focus', () => { console.log('focus') });
|
|
11
|
+
* const globalListener2 = createGlobalListener('focus', () => { console.log('focus') });
|
|
12
|
+
* globalListener.listen();
|
|
13
|
+
* globalListener2.listen();
|
|
14
|
+
*
|
|
15
|
+
* => // that will only create an event listener on window, but every callback will get emit value when event triggered
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export var createGlobalListener = function (key, listener, _a) {
|
|
19
|
+
var _b = _a === void 0 ? {} : _a, _c = _b.customKey, customKey = _c === void 0 ? key : _c, _d = _b.target, targetProp = _d === void 0 ? window : _d;
|
|
20
|
+
var listening = false;
|
|
21
|
+
var getMapValue = function () { return globalListenerEventMap.get(customKey); };
|
|
22
|
+
var addListener = function () {
|
|
23
|
+
if (listening)
|
|
24
|
+
return;
|
|
25
|
+
var savedEvent = getMapValue();
|
|
26
|
+
if (!(savedEvent === null || savedEvent === void 0 ? void 0 : savedEvent.exec)) {
|
|
27
|
+
var exec = function (e) {
|
|
28
|
+
var event = getMapValue();
|
|
29
|
+
event === null || event === void 0 ? void 0 : event.listeners.forEach(function (c) { return c(e); });
|
|
30
|
+
};
|
|
31
|
+
globalListenerEventMap.set(customKey, {
|
|
32
|
+
exec: exec,
|
|
33
|
+
listeners: new Set([listener]),
|
|
34
|
+
});
|
|
35
|
+
var target = getRefElement(targetProp);
|
|
36
|
+
target === null || target === void 0 ? void 0 : target.addEventListener(key, exec);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
savedEvent.listeners.add(listener);
|
|
40
|
+
}
|
|
41
|
+
listening = true;
|
|
42
|
+
};
|
|
43
|
+
var removeListener = function () {
|
|
44
|
+
if (!listening)
|
|
45
|
+
return;
|
|
46
|
+
listening = false;
|
|
47
|
+
var _savedEvent = getMapValue();
|
|
48
|
+
if (!_savedEvent)
|
|
49
|
+
return;
|
|
50
|
+
var listeners = _savedEvent.listeners;
|
|
51
|
+
listeners.delete(listener);
|
|
52
|
+
if (listeners.size === 0) {
|
|
53
|
+
var target = getRefElement(targetProp);
|
|
54
|
+
target === null || target === void 0 ? void 0 : target.removeEventListener(key, _savedEvent.exec);
|
|
55
|
+
globalListenerEventMap.delete(customKey);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
return {
|
|
59
|
+
/**
|
|
60
|
+
* bind listener again
|
|
61
|
+
*/
|
|
62
|
+
listen: function () { return addListener(); },
|
|
63
|
+
/**
|
|
64
|
+
* remove listener
|
|
65
|
+
*/
|
|
66
|
+
remove: function () { return removeListener(); },
|
|
67
|
+
/**
|
|
68
|
+
* current listener state
|
|
69
|
+
*/
|
|
70
|
+
get state() {
|
|
71
|
+
return {
|
|
72
|
+
/**
|
|
73
|
+
* current listener state count
|
|
74
|
+
*/
|
|
75
|
+
get count() {
|
|
76
|
+
var _a;
|
|
77
|
+
return ((_a = getMapValue()) === null || _a === void 0 ? void 0 : _a.listeners.size) || 0;
|
|
78
|
+
},
|
|
79
|
+
/**
|
|
80
|
+
* is that be listening
|
|
81
|
+
*/
|
|
82
|
+
listening: listening,
|
|
83
|
+
};
|
|
84
|
+
},
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* bind global event, when you bind same key event,
|
|
89
|
+
* that will reuse one event listener and trigger both callback once that listener be triggered.
|
|
90
|
+
*
|
|
91
|
+
* also you can control listener with method `listen` and `remove`
|
|
92
|
+
* and get listener `state` for check listener count number and current listing state.
|
|
93
|
+
*
|
|
94
|
+
* - `key` `options` only work when set first time, never change after first render
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```ts
|
|
98
|
+
* useGlobalListener('keyup', () => console.log('window key up1'))
|
|
99
|
+
* useGlobalListener('keyup', () => console.log('window key up2'))
|
|
100
|
+
* useGlobalListener('keyup', () => console.log('window key up3'))
|
|
101
|
+
*
|
|
102
|
+
* => // that will only create an event listener on `window`, but every callback will get emit value when event triggered
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
export function useGlobalListener(key, listener, options) {
|
|
106
|
+
if (options === void 0) { options = {}; }
|
|
107
|
+
var _listener = useEventCallback(listener);
|
|
108
|
+
var globalListener = useRef(createGlobalListener(key, _listener, options)).current;
|
|
109
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
110
|
+
var _a = options.customKey, customKey_1 = _a === void 0 ? key : _a, _b = options.target, targetProp_1 = _b === void 0 ? window : _b;
|
|
111
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
112
|
+
useEffect(function () {
|
|
113
|
+
var target = getRefElement(targetProp_1);
|
|
114
|
+
if (target !== window && customKey_1 === key) {
|
|
115
|
+
logInDev({
|
|
116
|
+
component: 'useGlobalListener',
|
|
117
|
+
message: 'When you custom binding event target, you must custom key for determining different event group',
|
|
118
|
+
level: 'error',
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
122
|
+
}, []);
|
|
123
|
+
}
|
|
124
|
+
useEffect(function () {
|
|
125
|
+
globalListener.listen();
|
|
126
|
+
return globalListener.remove;
|
|
127
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
128
|
+
}, []);
|
|
129
|
+
return globalListener;
|
|
130
|
+
}
|
|
@@ -1,17 +1,18 @@
|
|
|
1
|
+
import { getRefElement } from '../../utils';
|
|
1
2
|
import { useEventCallback } from '../useEventCallback';
|
|
2
3
|
/**
|
|
3
4
|
* group hidden logic, when binding events element focus,
|
|
4
5
|
* that hiddenRef will auto be `tabindex={-1}` *
|
|
5
6
|
*/
|
|
6
|
-
export var useHiddenTabindex = function (
|
|
7
|
+
export var useHiddenTabindex = function (target) {
|
|
7
8
|
var handleFocus = useEventCallback(function () {
|
|
8
|
-
var hiddenElm =
|
|
9
|
+
var hiddenElm = getRefElement(target);
|
|
9
10
|
if (hiddenElm && hiddenElm.tabIndex === 0) {
|
|
10
11
|
hiddenElm.tabIndex = -1;
|
|
11
12
|
}
|
|
12
13
|
});
|
|
13
14
|
var handleBlur = useEventCallback(function () {
|
|
14
|
-
var hiddenElm =
|
|
15
|
+
var hiddenElm = getRefElement(target);
|
|
15
16
|
if (hiddenElm && hiddenElm.tabIndex === -1) {
|
|
16
17
|
hiddenElm.tabIndex = 0;
|
|
17
18
|
}
|
|
@@ -3,7 +3,7 @@ import { useEffect, useRef } from 'react';
|
|
|
3
3
|
import { useA11yKeyEvent } from '../useA11yKeyEvent';
|
|
4
4
|
import { useDebounce } from '../useDebounce';
|
|
5
5
|
import { useEventCallback } from '../useEventCallback';
|
|
6
|
-
import {
|
|
6
|
+
import { isElmEqualOrContain, useTouchMouseEvent, } from '../useTouchMouseEvent';
|
|
7
7
|
/**
|
|
8
8
|
* Provide longPress helper, both `click`/`tab`/`keydown` will trigger event
|
|
9
9
|
*
|
|
@@ -30,8 +30,7 @@ export var useLongPress = function (_a, _b, _c) {
|
|
|
30
30
|
var end = function (e) {
|
|
31
31
|
// ! mouse up only trigger when up on element, so we host that in document
|
|
32
32
|
document.removeEventListener('mouseup', onMouseUp);
|
|
33
|
-
if (!isEmittedRef.current &&
|
|
34
|
-
isElmEqualOrContainRef(e.target, elmRef)) {
|
|
33
|
+
if (!isEmittedRef.current && isElmEqualOrContain(e.target, elmRef)) {
|
|
35
34
|
onTap === null || onTap === void 0 ? void 0 : onTap(e, reasonRef.current);
|
|
36
35
|
}
|
|
37
36
|
reasonRef.current = 'click';
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { useRef } from 'react';
|
|
2
|
+
import { getRefElement } from '../../utils';
|
|
2
3
|
import { useResizeObserver } from '../useResizeObserver';
|
|
3
4
|
/**
|
|
4
5
|
* trigger when overflow state change
|
|
5
6
|
*/
|
|
6
7
|
export var useOverflow = function (
|
|
7
8
|
/** target element ref */
|
|
8
|
-
|
|
9
|
+
target,
|
|
9
10
|
/** trigger when `ResizeObserver` emit */
|
|
10
11
|
cb,
|
|
11
12
|
/**
|
|
@@ -20,19 +21,21 @@ performance) {
|
|
|
20
21
|
}; }
|
|
21
22
|
// * not have default value for that can trigger change first time.
|
|
22
23
|
var showRef = useRef();
|
|
23
|
-
return useResizeObserver(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
24
|
+
return useResizeObserver(target, function () {
|
|
25
|
+
var element = getRefElement(target);
|
|
26
|
+
if (!element)
|
|
27
|
+
return;
|
|
28
|
+
var scrollWidth = element.scrollWidth, clientWidth = element.clientWidth, scrollHeight = element.scrollHeight, clientHeight = element.clientHeight;
|
|
29
|
+
var show = scrollWidth > clientWidth || scrollHeight > clientHeight;
|
|
30
|
+
if (showRef.current === show)
|
|
31
|
+
return;
|
|
32
|
+
// only emit when state change
|
|
33
|
+
showRef.current = show;
|
|
34
|
+
cb(show, {
|
|
35
|
+
scrollWidth: scrollWidth,
|
|
36
|
+
clientWidth: clientWidth,
|
|
37
|
+
scrollHeight: scrollHeight,
|
|
38
|
+
clientHeight: clientHeight,
|
|
39
|
+
});
|
|
37
40
|
}, performance);
|
|
38
41
|
};
|
|
@@ -4,7 +4,7 @@ import debounce from 'lodash/debounce';
|
|
|
4
4
|
import throttle from 'lodash/throttle';
|
|
5
5
|
import ResizeObserverPolyfill from 'resize-observer-polyfill';
|
|
6
6
|
import { useRcPortalWindowContext } from '../../contexts';
|
|
7
|
-
import { logInDev } from '../../utils';
|
|
7
|
+
import { getRefElement, logInDev } from '../../utils';
|
|
8
8
|
import { useEventCallback } from '../useEventCallback';
|
|
9
9
|
import { useResultRef } from '../useResultRef';
|
|
10
10
|
/**
|
|
@@ -38,7 +38,7 @@ export var getResizeObserver = function (callback, externalWindow) {
|
|
|
38
38
|
*/
|
|
39
39
|
export var useResizeObserver = function (
|
|
40
40
|
/** target element ref */
|
|
41
|
-
|
|
41
|
+
target,
|
|
42
42
|
/** trigger when `ResizeObserver` emit */
|
|
43
43
|
callback,
|
|
44
44
|
/** performance options, `mode`, `time`, `ignoreFireWhenObserve` */
|
|
@@ -74,8 +74,8 @@ performance) {
|
|
|
74
74
|
return getResizeObserver(resizeCallback, externalWindow);
|
|
75
75
|
});
|
|
76
76
|
useLayoutEffect(function () {
|
|
77
|
+
var elm = getRefElement(target);
|
|
77
78
|
var observer = observerRef.current;
|
|
78
|
-
var elm = ref.current;
|
|
79
79
|
if (!elm) {
|
|
80
80
|
throw new Error('please check element exist before bind resize observer');
|
|
81
81
|
}
|
|
@@ -85,6 +85,6 @@ performance) {
|
|
|
85
85
|
};
|
|
86
86
|
// TODO: wait https://github.com/facebook/react/pull/20477 eslint support to remove this exhaustive-deps comment with support custom hooks
|
|
87
87
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
88
|
-
}, [
|
|
88
|
+
}, [target]);
|
|
89
89
|
return observerRef.current;
|
|
90
90
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useRef } from 'react';
|
|
2
|
+
import { getRefElement } from '../../utils';
|
|
2
3
|
import { useEventCallback } from '../useEventCallback';
|
|
3
4
|
/**
|
|
4
5
|
* Provide a utils for switch trigger touch event or mouse event between different device
|
|
@@ -72,9 +73,11 @@ export var useTouchMouseEvent = function (_a, _b) {
|
|
|
72
73
|
onMouseUp: onMouseUp,
|
|
73
74
|
};
|
|
74
75
|
};
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
76
|
+
/**
|
|
77
|
+
* check is element equal or contains target element
|
|
78
|
+
*/
|
|
79
|
+
export var isElmEqualOrContain = function (sourceTarget, containTarget) {
|
|
80
|
+
var elm = getRefElement(sourceTarget);
|
|
81
|
+
var target = getRefElement(containTarget);
|
|
82
|
+
return elm && target && (target === elm || target.contains(elm));
|
|
80
83
|
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { isRef } from './isRef';
|
|
2
|
+
/**
|
|
3
|
+
* get element from React ref or callback
|
|
4
|
+
*/
|
|
5
|
+
export var getRefElement = function (ref) {
|
|
6
|
+
if (typeof ref === 'function') {
|
|
7
|
+
return ref();
|
|
8
|
+
}
|
|
9
|
+
if (isRef(ref)) {
|
|
10
|
+
return ref.current;
|
|
11
|
+
}
|
|
12
|
+
return ref;
|
|
13
|
+
};
|
|
@@ -4,6 +4,7 @@ export * from './classes';
|
|
|
4
4
|
export * from './clearReactReferencesInNode';
|
|
5
5
|
export * from './combineProps';
|
|
6
6
|
export * from './deepmerge';
|
|
7
|
+
export * from './getRefElement';
|
|
7
8
|
export * from './getScrollbarSize';
|
|
8
9
|
export * from './hasValue';
|
|
9
10
|
export * from './isRcElement';
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { getRefElement } from './getRefElement';
|
|
1
2
|
/**
|
|
2
3
|
* remove className from element, default will not scan child nodes, if you want to scan child nodes, set `scanChildren` to `true`.
|
|
3
4
|
*
|
|
4
|
-
* @param
|
|
5
|
+
* @param target target element reference or element or callback
|
|
5
6
|
* @param removeClass className to remove, default will use class `includes` to check, if you want to use full match, set `fullMatch` to `true`
|
|
6
7
|
*
|
|
7
8
|
* @example
|
|
@@ -16,9 +17,9 @@
|
|
|
16
17
|
* elm => <div class="efg"></div>
|
|
17
18
|
* ```
|
|
18
19
|
*/
|
|
19
|
-
export function removeClassName(
|
|
20
|
+
export function removeClassName(target, removeClass, _a) {
|
|
20
21
|
var _b = _a === void 0 ? {} : _a, _c = _b.scanChildren, scanChildren = _c === void 0 ? false : _c, _d = _b.fullMatch, fullMatch = _d === void 0 ? false : _d;
|
|
21
|
-
var elm =
|
|
22
|
+
var elm = getRefElement(target);
|
|
22
23
|
if (!elm)
|
|
23
24
|
return;
|
|
24
25
|
if (elm.className.includes(removeClass)) {
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { getRefElement } from './getRefElement';
|
|
1
2
|
/**
|
|
2
3
|
* get current input element selection position and is that selectRange state
|
|
3
4
|
*/
|
|
4
|
-
export function getSelectionPosition(
|
|
5
|
-
var
|
|
6
|
-
var currentPosition =
|
|
7
|
-
var currentPositionEnd =
|
|
5
|
+
export function getSelectionPosition(sourceTarget) {
|
|
6
|
+
var input = getRefElement(sourceTarget);
|
|
7
|
+
var currentPosition = input === null || input === void 0 ? void 0 : input.selectionStart;
|
|
8
|
+
var currentPositionEnd = input === null || input === void 0 ? void 0 : input.selectionEnd;
|
|
8
9
|
var isSelectRange = currentPosition !== currentPositionEnd;
|
|
9
10
|
return {
|
|
10
11
|
isSelectRange: isSelectRange,
|
|
@@ -15,8 +16,8 @@ export function getSelectionPosition(inputRef) {
|
|
|
15
16
|
* set input element selection position position,
|
|
16
17
|
* if you need scroll that into view set `scrollIntoView` as true
|
|
17
18
|
*/
|
|
18
|
-
export function setSelectionPosition(
|
|
19
|
-
var elm =
|
|
19
|
+
export function setSelectionPosition(target, options) {
|
|
20
|
+
var elm = getRefElement(target);
|
|
20
21
|
if (elm && options.start !== null && options.end !== null) {
|
|
21
22
|
// * use blur and refocus to refocus position into view
|
|
22
23
|
if (options.scrollIntoView)
|
|
@@ -2,12 +2,14 @@ export * from './useA11yKeyEvent';
|
|
|
2
2
|
export * from './useAnnouncer';
|
|
3
3
|
export * from './useAudio';
|
|
4
4
|
export * from './useChange';
|
|
5
|
+
export * from './useControlled';
|
|
5
6
|
export * from './useDebounce';
|
|
6
7
|
export * from './useEventCallback';
|
|
7
8
|
export * from './useEventListener';
|
|
8
9
|
export * from './useEver';
|
|
9
10
|
export * from './useForceUpdate';
|
|
10
11
|
export * from './useForkRef';
|
|
12
|
+
export * from './useGlobalListener';
|
|
11
13
|
export * from './useHiddenTabindex';
|
|
12
14
|
export * from './useId';
|
|
13
15
|
export * from './useInterval';
|
|
@@ -5,12 +5,14 @@ tslib_1.__exportStar(require("./useA11yKeyEvent"), exports);
|
|
|
5
5
|
tslib_1.__exportStar(require("./useAnnouncer"), exports);
|
|
6
6
|
tslib_1.__exportStar(require("./useAudio"), exports);
|
|
7
7
|
tslib_1.__exportStar(require("./useChange"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./useControlled"), exports);
|
|
8
9
|
tslib_1.__exportStar(require("./useDebounce"), exports);
|
|
9
10
|
tslib_1.__exportStar(require("./useEventCallback"), exports);
|
|
10
11
|
tslib_1.__exportStar(require("./useEventListener"), exports);
|
|
11
12
|
tslib_1.__exportStar(require("./useEver"), exports);
|
|
12
13
|
tslib_1.__exportStar(require("./useForceUpdate"), exports);
|
|
13
14
|
tslib_1.__exportStar(require("./useForkRef"), exports);
|
|
15
|
+
tslib_1.__exportStar(require("./useGlobalListener"), exports);
|
|
14
16
|
tslib_1.__exportStar(require("./useHiddenTabindex"), exports);
|
|
15
17
|
tslib_1.__exportStar(require("./useId"), exports);
|
|
16
18
|
tslib_1.__exportStar(require("./useInterval"), exports);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './useControlled';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useControlled } from '@material-ui/core/utils';
|