@ringcentral/juno 2.5.0 → 2.6.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/components/Buttons/IconButton/IconButton.d.ts +5 -1
- package/components/Buttons/IconButton/IconButton.js +2 -2
- package/components/Downshift/styles/DownshiftStyle.d.ts +1 -1
- package/components/Forms/Picker/DatePicker/styles/StyledDatePickerHeader.d.ts +1 -1
- package/components/Forms/Picker/DatePicker/styles/StyledYear.d.ts +1 -1
- package/components/Forms/Picker/TimePicker/styles/StyledSelectionItem.d.ts +1 -1
- package/components/Forms/Picker/TimePicker/styles/StyledTimeIconButton.d.ts +1 -1
- package/components/Forms/Picker/styles/PickerBaseIconButton.d.ts +1 -1
- package/components/Forms/TextField/styles/ClearIconButton.d.ts +2 -2
- package/es6/components/Buttons/IconButton/IconButton.js +2 -2
- package/es6/foundation/hooks/useEventListener/useEventListener.js +27 -8
- package/es6/foundation/hooks/useGlobalListener/createGlobalListener.js +81 -0
- package/es6/foundation/hooks/useGlobalListener/index.js +1 -0
- package/es6/foundation/hooks/useGlobalListener/useGlobalListener.js +67 -97
- package/es6/foundation/hooks/useLongPress/useLongPress.js +50 -31
- package/es6/foundation/hooks/useTouchMouseEvent/useTouchMouseEvent.js +27 -28
- package/foundation/hooks/useEventListener/useEventListener.d.ts +12 -16
- package/foundation/hooks/useEventListener/useEventListener.js +26 -7
- package/foundation/hooks/useGlobalListener/createGlobalListener.d.ts +55 -0
- package/foundation/hooks/useGlobalListener/createGlobalListener.js +83 -0
- package/foundation/hooks/useGlobalListener/index.d.ts +1 -0
- package/foundation/hooks/useGlobalListener/index.js +1 -0
- package/foundation/hooks/useGlobalListener/useGlobalListener.d.ts +11 -105
- package/foundation/hooks/useGlobalListener/useGlobalListener.js +67 -97
- package/foundation/hooks/useLongPress/useLongPress.d.ts +8 -8
- package/foundation/hooks/useLongPress/useLongPress.js +48 -29
- package/foundation/hooks/useTouchMouseEvent/useTouchMouseEvent.d.ts +27 -14
- package/foundation/hooks/useTouchMouseEvent/useTouchMouseEvent.js +27 -28
- package/foundation/typings/deepPartial.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,108 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export declare
|
|
1
|
+
import { SyntheticEvent } from 'react';
|
|
2
|
+
import { createGlobalListener, CreateGlobalListenerConfig } from './createGlobalListener';
|
|
3
|
+
declare type GlobalListener = ReturnType<typeof createGlobalListener>;
|
|
4
|
+
export declare type UseGlobalListenerConfig = CreateGlobalListenerConfig & {
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* start listening when component mounted
|
|
7
|
+
*
|
|
8
|
+
* @default true
|
|
7
9
|
*/
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* all listener
|
|
11
|
-
*/
|
|
12
|
-
listeners: Set<(e: any) => void>;
|
|
13
|
-
}>;
|
|
14
|
-
/**
|
|
15
|
-
* create globalListener handler for share one listener event
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```ts
|
|
19
|
-
* const globalListener = createGlobalListener('focus', () => { console.log('focus') });
|
|
20
|
-
* const globalListener2 = createGlobalListener('focus', () => { console.log('focus') });
|
|
21
|
-
* globalListener.listen();
|
|
22
|
-
* globalListener2.listen();
|
|
23
|
-
*
|
|
24
|
-
* => // that will only create an event listener on window, but every callback will get emit value when event triggered
|
|
25
|
-
* ```
|
|
26
|
-
*/
|
|
27
|
-
export declare const createGlobalListener: (key: string, listener: EventListener, { customKey, target: targetProp, }?: {
|
|
28
|
-
/**
|
|
29
|
-
* custom key for determining different event group, default is same as `key`
|
|
30
|
-
*/
|
|
31
|
-
customKey?: string | undefined;
|
|
32
|
-
/**
|
|
33
|
-
* custom binding event target, default is `window`
|
|
34
|
-
*/
|
|
35
|
-
target?: EventTarget | HTMLElement | import("react").RefObject<HTMLElement> | (() => HTMLElement) | undefined;
|
|
36
|
-
}) => {
|
|
37
|
-
/**
|
|
38
|
-
* bind listener again
|
|
39
|
-
*/
|
|
40
|
-
listen: () => void;
|
|
41
|
-
/**
|
|
42
|
-
* remove listener
|
|
43
|
-
*/
|
|
44
|
-
remove: () => void;
|
|
45
|
-
/**
|
|
46
|
-
* current listener state
|
|
47
|
-
*/
|
|
48
|
-
readonly state: {
|
|
49
|
-
/**
|
|
50
|
-
* current listener state count
|
|
51
|
-
*/
|
|
52
|
-
readonly count: number;
|
|
53
|
-
/**
|
|
54
|
-
* is that be listening
|
|
55
|
-
*/
|
|
56
|
-
listening: boolean;
|
|
57
|
-
};
|
|
58
|
-
};
|
|
59
|
-
/**
|
|
60
|
-
* bind global event, when you bind same key event,
|
|
61
|
-
* that will reuse one event listener and trigger both callback once that listener be triggered.
|
|
62
|
-
*
|
|
63
|
-
* also you can control listener with method `listen` and `remove`
|
|
64
|
-
* and get listener `state` for check listener count number and current listing state.
|
|
65
|
-
*
|
|
66
|
-
* - `key` `options` only work when set first time, never change after first render
|
|
67
|
-
*
|
|
68
|
-
* @example
|
|
69
|
-
* ```ts
|
|
70
|
-
* useGlobalListener('keyup', () => console.log('window key up1'))
|
|
71
|
-
* useGlobalListener('keyup', () => console.log('window key up2'))
|
|
72
|
-
* useGlobalListener('keyup', () => console.log('window key up3'))
|
|
73
|
-
*
|
|
74
|
-
* => // that will only create an event listener on `window`, but every callback will get emit value when event triggered
|
|
75
|
-
* ```
|
|
76
|
-
*/
|
|
77
|
-
export declare function useGlobalListener(key: string, listener: EventListener, options?: {
|
|
78
|
-
/**
|
|
79
|
-
* custom key for determining different event group, default is same as `key`
|
|
80
|
-
*/
|
|
81
|
-
customKey?: string;
|
|
82
|
-
/**
|
|
83
|
-
* custom binding event target, default is `window`
|
|
84
|
-
*/
|
|
85
|
-
target?: RefOrElementOrCallback | EventTarget;
|
|
86
|
-
}): {
|
|
87
|
-
/**
|
|
88
|
-
* bind listener again
|
|
89
|
-
*/
|
|
90
|
-
listen: () => void;
|
|
91
|
-
/**
|
|
92
|
-
* remove listener
|
|
93
|
-
*/
|
|
94
|
-
remove: () => void;
|
|
95
|
-
/**
|
|
96
|
-
* current listener state
|
|
97
|
-
*/
|
|
98
|
-
readonly state: {
|
|
99
|
-
/**
|
|
100
|
-
* current listener state count
|
|
101
|
-
*/
|
|
102
|
-
readonly count: number;
|
|
103
|
-
/**
|
|
104
|
-
* is that be listening
|
|
105
|
-
*/
|
|
106
|
-
listening: boolean;
|
|
107
|
-
};
|
|
10
|
+
startImmediately?: boolean;
|
|
108
11
|
};
|
|
12
|
+
export declare function useGlobalListener<T extends SyntheticEvent>(key: string, listener: (event?: T) => void, config?: UseGlobalListenerConfig): GlobalListener;
|
|
13
|
+
export declare function useGlobalListener<T extends SyntheticEvent>(key: string, listener: (event?: T) => void, options?: AddEventListenerOptions | boolean, config?: UseGlobalListenerConfig): GlobalListener;
|
|
14
|
+
export {};
|
|
@@ -1,91 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
var tslib_1 = require("tslib");
|
|
3
4
|
var react_1 = require("react");
|
|
4
5
|
var utils_1 = require("../../utils");
|
|
5
6
|
var useEventCallback_1 = require("../useEventCallback");
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* create globalListener handler for share one listener event
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* ```ts
|
|
12
|
-
* const globalListener = createGlobalListener('focus', () => { console.log('focus') });
|
|
13
|
-
* const globalListener2 = createGlobalListener('focus', () => { console.log('focus') });
|
|
14
|
-
* globalListener.listen();
|
|
15
|
-
* globalListener2.listen();
|
|
16
|
-
*
|
|
17
|
-
* => // that will only create an event listener on window, but every callback will get emit value when event triggered
|
|
18
|
-
* ```
|
|
19
|
-
*/
|
|
20
|
-
exports.createGlobalListener = function (key, listener, _a) {
|
|
21
|
-
var _b = _a === void 0 ? {} : _a, _c = _b.customKey, customKey = _c === void 0 ? key : _c, _d = _b.target, targetProp = _d === void 0 ? window : _d;
|
|
22
|
-
var listening = false;
|
|
23
|
-
var getMapValue = function () { return exports.globalListenerEventMap.get(customKey); };
|
|
24
|
-
var addListener = function () {
|
|
25
|
-
if (listening)
|
|
26
|
-
return;
|
|
27
|
-
var savedEvent = getMapValue();
|
|
28
|
-
if (!(savedEvent === null || savedEvent === void 0 ? void 0 : savedEvent.exec)) {
|
|
29
|
-
var exec = function (e) {
|
|
30
|
-
var event = getMapValue();
|
|
31
|
-
event === null || event === void 0 ? void 0 : event.listeners.forEach(function (c) { return c(e); });
|
|
32
|
-
};
|
|
33
|
-
exports.globalListenerEventMap.set(customKey, {
|
|
34
|
-
exec: exec,
|
|
35
|
-
listeners: new Set([listener]),
|
|
36
|
-
});
|
|
37
|
-
var target = utils_1.getRefElement(targetProp);
|
|
38
|
-
target === null || target === void 0 ? void 0 : target.addEventListener(key, exec);
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
savedEvent.listeners.add(listener);
|
|
42
|
-
}
|
|
43
|
-
listening = true;
|
|
44
|
-
};
|
|
45
|
-
var removeListener = function () {
|
|
46
|
-
if (!listening)
|
|
47
|
-
return;
|
|
48
|
-
listening = false;
|
|
49
|
-
var _savedEvent = getMapValue();
|
|
50
|
-
if (!_savedEvent)
|
|
51
|
-
return;
|
|
52
|
-
var listeners = _savedEvent.listeners;
|
|
53
|
-
listeners.delete(listener);
|
|
54
|
-
if (listeners.size === 0) {
|
|
55
|
-
var target = utils_1.getRefElement(targetProp);
|
|
56
|
-
target === null || target === void 0 ? void 0 : target.removeEventListener(key, _savedEvent.exec);
|
|
57
|
-
exports.globalListenerEventMap.delete(customKey);
|
|
58
|
-
}
|
|
59
|
-
};
|
|
60
|
-
return {
|
|
61
|
-
/**
|
|
62
|
-
* bind listener again
|
|
63
|
-
*/
|
|
64
|
-
listen: function () { return addListener(); },
|
|
65
|
-
/**
|
|
66
|
-
* remove listener
|
|
67
|
-
*/
|
|
68
|
-
remove: function () { return removeListener(); },
|
|
69
|
-
/**
|
|
70
|
-
* current listener state
|
|
71
|
-
*/
|
|
72
|
-
get state() {
|
|
73
|
-
return {
|
|
74
|
-
/**
|
|
75
|
-
* current listener state count
|
|
76
|
-
*/
|
|
77
|
-
get count() {
|
|
78
|
-
var _a;
|
|
79
|
-
return ((_a = getMapValue()) === null || _a === void 0 ? void 0 : _a.listeners.size) || 0;
|
|
80
|
-
},
|
|
81
|
-
/**
|
|
82
|
-
* is that be listening
|
|
83
|
-
*/
|
|
84
|
-
listening: listening,
|
|
85
|
-
};
|
|
86
|
-
},
|
|
87
|
-
};
|
|
88
|
-
};
|
|
7
|
+
var createGlobalListener_1 = require("./createGlobalListener");
|
|
89
8
|
/**
|
|
90
9
|
* bind global event, when you bind same key event,
|
|
91
10
|
* that will reuse one event listener and trigger both callback once that listener be triggered.
|
|
@@ -93,41 +12,92 @@ exports.createGlobalListener = function (key, listener, _a) {
|
|
|
93
12
|
* also you can control listener with method `listen` and `remove`
|
|
94
13
|
* and get listener `state` for check listener count number and current listing state.
|
|
95
14
|
*
|
|
96
|
-
*
|
|
15
|
+
* config:
|
|
16
|
+
* - `target`: custom binding event target, default is `window`
|
|
17
|
+
* - `customKey`: custom key for determining different event group, default is same as `key`
|
|
18
|
+
* - `startImmediately`: start listener immediately, default is `true`
|
|
19
|
+
*
|
|
20
|
+
* * `key`, `options` only work when set first time, never change after first render
|
|
97
21
|
*
|
|
98
22
|
* @example
|
|
99
23
|
* ```ts
|
|
100
24
|
* useGlobalListener('keyup', () => console.log('window key up1'))
|
|
25
|
+
*
|
|
101
26
|
* useGlobalListener('keyup', () => console.log('window key up2'))
|
|
102
|
-
*
|
|
27
|
+
*
|
|
28
|
+
* useGlobalListener('touchend', () => console.log('window key up3'), {
|
|
29
|
+
* target: someWantHostElement,
|
|
30
|
+
* customKey: 'hostTouchend',
|
|
31
|
+
* })
|
|
32
|
+
*
|
|
33
|
+
* useGlobalListener('touchend', () => console.log('window key up3'), { passive: false }, {
|
|
34
|
+
* target: someWantHostElement,
|
|
35
|
+
* customKey: 'hostTouchend',
|
|
36
|
+
* })
|
|
103
37
|
*
|
|
104
38
|
* => // that will only create an event listener on `window`, but every callback will get emit value when event triggered
|
|
105
39
|
* ```
|
|
106
40
|
*/
|
|
107
|
-
function useGlobalListener(key, listener
|
|
108
|
-
|
|
41
|
+
function useGlobalListener(key, listener) {
|
|
42
|
+
var args = [];
|
|
43
|
+
for (var _i = 2; _i < arguments.length; _i++) {
|
|
44
|
+
args[_i - 2] = arguments[_i];
|
|
45
|
+
}
|
|
46
|
+
var _a = getListenerOverloadOption(args), options = _a.options, config = _a.config;
|
|
47
|
+
var _b = config || {}, _c = _b.customKey, customKey = _c === void 0 ? key : _c, _d = _b.target, targetProp = _d === void 0 ? window : _d, _e = _b.startImmediately, startImmediately = _e === void 0 ? true : _e;
|
|
109
48
|
var _listener = useEventCallback_1.useEventCallback(listener);
|
|
110
|
-
var globalListener = react_1.useRef(
|
|
49
|
+
var globalListener = react_1.useRef(createGlobalListener_1.createGlobalListener(key, _listener, options, {
|
|
50
|
+
customKey: customKey,
|
|
51
|
+
target: targetProp,
|
|
52
|
+
})).current;
|
|
111
53
|
if (process.env.NODE_ENV !== 'production') {
|
|
112
|
-
var _a = options.customKey, customKey_1 = _a === void 0 ? key : _a, _b = options.target, targetProp_1 = _b === void 0 ? window : _b;
|
|
113
54
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
114
55
|
react_1.useEffect(function () {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
56
|
+
if (customKey === key) {
|
|
57
|
+
if (Object.keys(options).length > 0) {
|
|
58
|
+
utils_1.logInDev({
|
|
59
|
+
component: 'useGlobalListener',
|
|
60
|
+
message: 'when have set options, suggest you also bind customKey, otherwise, it may use previous listener without same options',
|
|
61
|
+
level: 'warn',
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
var target = utils_1.getRefElement(targetProp);
|
|
65
|
+
if (target !== window) {
|
|
66
|
+
utils_1.logInDev({
|
|
67
|
+
component: 'useGlobalListener',
|
|
68
|
+
message: 'When you custom binding event target, you must custom key for determining different event group',
|
|
69
|
+
level: 'error',
|
|
70
|
+
});
|
|
71
|
+
}
|
|
122
72
|
}
|
|
123
73
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
124
74
|
}, []);
|
|
125
75
|
}
|
|
126
76
|
react_1.useEffect(function () {
|
|
127
|
-
|
|
77
|
+
if (startImmediately) {
|
|
78
|
+
globalListener.listen();
|
|
79
|
+
}
|
|
128
80
|
return globalListener.remove;
|
|
129
81
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
130
82
|
}, []);
|
|
131
83
|
return globalListener;
|
|
132
84
|
}
|
|
133
85
|
exports.useGlobalListener = useGlobalListener;
|
|
86
|
+
function getListenerOverloadOption(args) {
|
|
87
|
+
var options;
|
|
88
|
+
var config;
|
|
89
|
+
if (typeof args[0] === 'boolean') {
|
|
90
|
+
options = args[0];
|
|
91
|
+
config = args[1];
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
var _a = tslib_1.__assign(tslib_1.__assign({}, (args[0] || {})), (args[1] || {})), startImmediately = _a.startImmediately, customKey = _a.customKey, target = _a.target, restOptions = tslib_1.__rest(_a, ["startImmediately", "customKey", "target"]);
|
|
95
|
+
options = restOptions;
|
|
96
|
+
config = {
|
|
97
|
+
startImmediately: startImmediately,
|
|
98
|
+
customKey: customKey,
|
|
99
|
+
target: target,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
return { options: options, config: config };
|
|
103
|
+
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { UseTouchMouseEvent } from '../useTouchMouseEvent';
|
|
3
|
+
export declare const isTouchEvent: <T = unknown>(ev: React.MouseEvent<T, MouseEvent> | React.TouchEvent<T>) => ev is React.TouchEvent<T>;
|
|
3
4
|
export interface UseLongPressOptions {
|
|
4
|
-
/**
|
|
5
|
+
/**
|
|
6
|
+
* auto event.preventDefault for `mousedown`, `touchstart`, `touchend`
|
|
7
|
+
* always use for not leave that element
|
|
8
|
+
*/
|
|
5
9
|
isPreventDefault?: boolean;
|
|
6
10
|
/** the longPress delay */
|
|
7
11
|
delay?: number;
|
|
@@ -18,7 +22,6 @@ export declare type UseLongPressOutput<T> = {
|
|
|
18
22
|
export declare type UseLongPressInput<T> = {
|
|
19
23
|
onKeyUp?: (e: React.KeyboardEvent<T>) => void;
|
|
20
24
|
onKeyDown?: (e: React.KeyboardEvent<T>) => void;
|
|
21
|
-
onContextMenu?: (e: React.MouseEvent<T, MouseEvent>) => void;
|
|
22
25
|
} & UseTouchMouseEvent<T>;
|
|
23
26
|
/**
|
|
24
27
|
* Provide longPress helper, both `click`/`tab`/`keydown` will trigger event
|
|
@@ -26,14 +29,11 @@ export declare type UseLongPressInput<T> = {
|
|
|
26
29
|
* - Trigger `onTap` when user action leave small than delay time.
|
|
27
30
|
* - Trigger `onPress` when action time is long than delay time.
|
|
28
31
|
*
|
|
29
|
-
* @default UseLongPressOptions {
|
|
32
|
+
* @default UseLongPressOptions { delay = 300 }
|
|
30
33
|
*/
|
|
31
|
-
export declare const useLongPress: <T =
|
|
32
|
-
onTouchStart: (e: any) => void;
|
|
33
|
-
onTouchEnd: (e: any) => void;
|
|
34
|
+
export declare const useLongPress: <T extends HTMLElement = HTMLElement>({ onTap, onPress }: UseLongPressOutput<T>, { onTouchStart: onTouchStartArg, onTouchEnd: onTouchEndArg, onMouseDown, onKeyDown, onKeyUp, onMouseUp: onMouseUpArg, }?: UseLongPressInput<T>, { isPreventDefault, delay, externalWindow, }?: UseLongPressOptions) => {
|
|
34
35
|
onMouseDown: (event: React.MouseEvent<T, MouseEvent>) => void;
|
|
35
|
-
ref: React.
|
|
36
|
-
onContextMenu: (e: any) => void;
|
|
36
|
+
ref: React.MutableRefObject<T | null>;
|
|
37
37
|
onKeyDown: (e: any) => void;
|
|
38
38
|
onKeyUp: (e: any) => void;
|
|
39
39
|
};
|
|
@@ -5,22 +5,27 @@ var react_1 = require("react");
|
|
|
5
5
|
var useA11yKeyEvent_1 = require("../useA11yKeyEvent");
|
|
6
6
|
var useDebounce_1 = require("../useDebounce");
|
|
7
7
|
var useEventCallback_1 = require("../useEventCallback");
|
|
8
|
+
var useEventListener_1 = require("../useEventListener");
|
|
9
|
+
var useGlobalListener_1 = require("../useGlobalListener");
|
|
8
10
|
var useTouchMouseEvent_1 = require("../useTouchMouseEvent");
|
|
11
|
+
exports.isTouchEvent = function (ev) {
|
|
12
|
+
return 'touches' in ev;
|
|
13
|
+
};
|
|
9
14
|
/**
|
|
10
15
|
* Provide longPress helper, both `click`/`tab`/`keydown` will trigger event
|
|
11
16
|
*
|
|
12
17
|
* - Trigger `onTap` when user action leave small than delay time.
|
|
13
18
|
* - Trigger `onPress` when action time is long than delay time.
|
|
14
19
|
*
|
|
15
|
-
* @default UseLongPressOptions {
|
|
20
|
+
* @default UseLongPressOptions { delay = 300 }
|
|
16
21
|
*/
|
|
17
22
|
exports.useLongPress = function (_a, _b, _c) {
|
|
18
23
|
var onTap = _a.onTap, onPress = _a.onPress;
|
|
19
|
-
var _d = _b === void 0 ? {} : _b,
|
|
24
|
+
var _d = _b === void 0 ? {} : _b, onTouchStartArg = _d.onTouchStart, onTouchEndArg = _d.onTouchEnd, onMouseDown = _d.onMouseDown, onKeyDown = _d.onKeyDown, onKeyUp = _d.onKeyUp, onMouseUpArg = _d.onMouseUp;
|
|
20
25
|
var _e = _c === void 0 ? {} : _c, _f = _e.isPreventDefault, isPreventDefault = _f === void 0 ? true : _f, _g = _e.delay, delay = _g === void 0 ? 300 : _g, _h = _e.externalWindow, externalWindow = _h === void 0 ? window : _h;
|
|
21
26
|
var isEmittedRef = react_1.useRef(false);
|
|
22
27
|
var isA11yDownRef = react_1.useRef(false);
|
|
23
|
-
var
|
|
28
|
+
var actionRef = react_1.useRef(null);
|
|
24
29
|
var reasonRef = react_1.useRef('click');
|
|
25
30
|
var emitLongPress = useDebounce_1.useDebounce(function (e) {
|
|
26
31
|
// * only when have onPress set have emit
|
|
@@ -29,10 +34,10 @@ exports.useLongPress = function (_a, _b, _c) {
|
|
|
29
34
|
isEmittedRef.current = true;
|
|
30
35
|
}
|
|
31
36
|
}, delay);
|
|
32
|
-
var end = function (e) {
|
|
37
|
+
var end = function (e, isInside) {
|
|
33
38
|
// ! mouse up only trigger when up on element, so we host that in document
|
|
34
|
-
|
|
35
|
-
if (!isEmittedRef.current &&
|
|
39
|
+
globalMouseUpListener.remove();
|
|
40
|
+
if (!isEmittedRef.current && isInside) {
|
|
36
41
|
onTap === null || onTap === void 0 ? void 0 : onTap(e, reasonRef.current);
|
|
37
42
|
}
|
|
38
43
|
reasonRef.current = 'click';
|
|
@@ -41,11 +46,8 @@ exports.useLongPress = function (_a, _b, _c) {
|
|
|
41
46
|
};
|
|
42
47
|
var start = function (e) {
|
|
43
48
|
// ! mouse up only trigger when up on element, so we host that in document
|
|
44
|
-
|
|
49
|
+
globalMouseUpListener.listen();
|
|
45
50
|
var isTouch = e.type === 'touchstart';
|
|
46
|
-
if (!isTouch)
|
|
47
|
-
e.preventDefault();
|
|
48
|
-
e.stopPropagation();
|
|
49
51
|
if (isTouch) {
|
|
50
52
|
reasonRef.current = 'tap';
|
|
51
53
|
}
|
|
@@ -53,22 +55,49 @@ exports.useLongPress = function (_a, _b, _c) {
|
|
|
53
55
|
};
|
|
54
56
|
var _j = useTouchMouseEvent_1.useTouchMouseEvent({
|
|
55
57
|
onTouchStart: function (e) {
|
|
56
|
-
|
|
58
|
+
// prevent long touch leave element focus
|
|
59
|
+
if (isPreventDefault) {
|
|
60
|
+
e.preventDefault();
|
|
61
|
+
}
|
|
62
|
+
onTouchStartArg === null || onTouchStartArg === void 0 ? void 0 : onTouchStartArg(e);
|
|
57
63
|
start(e);
|
|
58
64
|
},
|
|
59
|
-
onTouchEnd: function (e) {
|
|
60
|
-
|
|
61
|
-
|
|
65
|
+
onTouchEnd: function (e, isInside) {
|
|
66
|
+
// prevent leave element focus
|
|
67
|
+
if (isPreventDefault) {
|
|
68
|
+
e.preventDefault();
|
|
69
|
+
}
|
|
70
|
+
onTouchEndArg === null || onTouchEndArg === void 0 ? void 0 : onTouchEndArg(e, isInside);
|
|
71
|
+
end(e, isInside);
|
|
62
72
|
},
|
|
63
73
|
onMouseDown: function (e) {
|
|
74
|
+
if (isPreventDefault) {
|
|
75
|
+
e.preventDefault();
|
|
76
|
+
}
|
|
64
77
|
onMouseDown === null || onMouseDown === void 0 ? void 0 : onMouseDown(e);
|
|
65
78
|
start(e);
|
|
66
79
|
},
|
|
67
|
-
onMouseUp: function (e) {
|
|
80
|
+
onMouseUp: function (e, isInside) {
|
|
81
|
+
// prevent leave element focus
|
|
82
|
+
if (isPreventDefault) {
|
|
83
|
+
e.preventDefault();
|
|
84
|
+
}
|
|
68
85
|
onMouseUpArg === null || onMouseUpArg === void 0 ? void 0 : onMouseUpArg(e);
|
|
69
|
-
end(e);
|
|
86
|
+
end(e, isInside);
|
|
70
87
|
},
|
|
71
|
-
}, {
|
|
88
|
+
}, { actionRef: actionRef }), onMouseUp = _j.onMouseUp, onTouchEnd = _j.onTouchEnd, onTouchStart = _j.onTouchStart, events = tslib_1.__rest(_j, ["onMouseUp", "onTouchEnd", "onTouchStart"]);
|
|
89
|
+
// use event listener for make event `passive` work in safari
|
|
90
|
+
useEventListener_1.useEventListener(actionRef, 'touchstart', onTouchStart, {
|
|
91
|
+
passive: false,
|
|
92
|
+
});
|
|
93
|
+
// use event listener for make event `passive` work in safari
|
|
94
|
+
useEventListener_1.useEventListener(actionRef, 'touchend', onTouchEnd, {
|
|
95
|
+
passive: false,
|
|
96
|
+
});
|
|
97
|
+
var globalMouseUpListener = useGlobalListener_1.useGlobalListener('mouseup', onMouseUp, {
|
|
98
|
+
target: externalWindow,
|
|
99
|
+
startImmediately: false,
|
|
100
|
+
});
|
|
72
101
|
var handleDeleteKeyDown = useA11yKeyEvent_1.useA11yKeyEvent(function (e) {
|
|
73
102
|
reasonRef.current = 'keyboard';
|
|
74
103
|
// * keydown when hold will trigger many time, show when current is a11y down, not trigger again
|
|
@@ -84,18 +113,8 @@ exports.useLongPress = function (_a, _b, _c) {
|
|
|
84
113
|
var handleKeyUp = useEventCallback_1.useEventCallback(function (e) {
|
|
85
114
|
onKeyUp === null || onKeyUp === void 0 ? void 0 : onKeyUp(e);
|
|
86
115
|
if (isA11yDownRef.current)
|
|
87
|
-
end(e);
|
|
116
|
+
end(e, true);
|
|
88
117
|
isA11yDownRef.current = false;
|
|
89
118
|
});
|
|
90
|
-
|
|
91
|
-
onContextMenu === null || onContextMenu === void 0 ? void 0 : onContextMenu(e);
|
|
92
|
-
e.preventDefault();
|
|
93
|
-
});
|
|
94
|
-
react_1.useEffect(function () {
|
|
95
|
-
return function () {
|
|
96
|
-
// * clean when in start remove
|
|
97
|
-
externalWindow.document.removeEventListener('mouseup', onMouseUp);
|
|
98
|
-
};
|
|
99
|
-
}, [onMouseUp, externalWindow]);
|
|
100
|
-
return tslib_1.__assign({ ref: elmRef, onContextMenu: handleContextMenu, onKeyDown: handleKeyDown, onKeyUp: handleKeyUp }, events);
|
|
119
|
+
return tslib_1.__assign({ ref: actionRef, onKeyDown: handleKeyDown, onKeyUp: handleKeyUp }, events);
|
|
101
120
|
};
|
|
@@ -1,14 +1,31 @@
|
|
|
1
|
-
/// <reference types="styled-jsx" />
|
|
2
1
|
import { MouseEventHandler, TouchEventHandler } from 'react';
|
|
3
2
|
import { RefOrElementOrCallback } from '../../utils';
|
|
4
|
-
export interface UseTouchMouseEvent<T> {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
export interface UseTouchMouseEvent<T> extends Partial<UseTouchMouseOutputEvent<T>> {
|
|
4
|
+
onTouchEnd?: (event: React.TouchEvent<T>,
|
|
5
|
+
/**
|
|
6
|
+
* when set insideRef, that will also emit the state of host reference contain pointer element when action stop
|
|
7
|
+
*/
|
|
8
|
+
isInside?: boolean) => void;
|
|
9
|
+
onMouseUp?: (event: React.MouseEvent<T, globalThis.MouseEvent>,
|
|
10
|
+
/**
|
|
11
|
+
* when set insideRef, that will also emit the state of host reference contain pointer element when action stop
|
|
12
|
+
*/
|
|
13
|
+
isInside?: boolean) => void;
|
|
9
14
|
}
|
|
10
|
-
export interface
|
|
11
|
-
|
|
15
|
+
export interface UseTouchMouseOutputEvent<T> {
|
|
16
|
+
onMouseUp: MouseEventHandler<T>;
|
|
17
|
+
onMouseDown: MouseEventHandler<T>;
|
|
18
|
+
onTouchEnd: TouchEventHandler<T>;
|
|
19
|
+
onTouchStart: TouchEventHandler<T>;
|
|
20
|
+
}
|
|
21
|
+
export interface UseTouchMouseEventOptions<T extends HTMLElement> {
|
|
22
|
+
/**
|
|
23
|
+
* when set that elementRef, event will bring with leave state when `touchend` and `mouseup`
|
|
24
|
+
*
|
|
25
|
+
* stop action event in browser default can be trigger when `touchend`, `mouseup` outside target element,
|
|
26
|
+
* set that host ref to make sure `touchend`, `mouseup` event only trigger when release inside target element
|
|
27
|
+
*/
|
|
28
|
+
actionRef?: RefOrElementOrCallback<T>;
|
|
12
29
|
}
|
|
13
30
|
/**
|
|
14
31
|
* Provide a utils for switch trigger touch event or mouse event between different device
|
|
@@ -20,6 +37,7 @@ export interface UseTouchMouseEventOptions {
|
|
|
20
37
|
* - onMouseDown
|
|
21
38
|
* - onMouseUp
|
|
22
39
|
*
|
|
40
|
+
* ### Once that is touch support device, that mouse event will never can be trigger
|
|
23
41
|
* https://developer.mozilla.org/en-US/docs/Web/API/Touch_events/Supporting_both_TouchEvent_and_MouseEvent
|
|
24
42
|
*
|
|
25
43
|
* Event order:
|
|
@@ -31,12 +49,7 @@ export interface UseTouchMouseEventOptions {
|
|
|
31
49
|
* - mouseup
|
|
32
50
|
* - click
|
|
33
51
|
*/
|
|
34
|
-
export declare const useTouchMouseEvent: <T =
|
|
35
|
-
onTouchStart: (e: any) => void;
|
|
36
|
-
onTouchEnd: (e: any) => void;
|
|
37
|
-
onMouseDown: (event: import("react").MouseEvent<T, MouseEvent>) => void;
|
|
38
|
-
onMouseUp: (e: any) => void;
|
|
39
|
-
};
|
|
52
|
+
export declare const useTouchMouseEvent: <T extends HTMLElement = HTMLElement>({ onMouseDown: onMouseDownArg, onMouseUp: onMouseUpArg, onTouchStart: onTouchStartArg, onTouchEnd: onTouchEndArg, }: UseTouchMouseEvent<T>, { actionRef }?: UseTouchMouseEventOptions<T>) => UseTouchMouseOutputEvent<T>;
|
|
40
53
|
/**
|
|
41
54
|
* check is element equal or contains target element
|
|
42
55
|
*/
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
var react_1 = require("react");
|
|
4
|
+
var contexts_1 = require("../../contexts");
|
|
4
5
|
var utils_1 = require("../../utils");
|
|
5
6
|
var useEventCallback_1 = require("../useEventCallback");
|
|
6
7
|
/**
|
|
@@ -13,6 +14,7 @@ var useEventCallback_1 = require("../useEventCallback");
|
|
|
13
14
|
* - onMouseDown
|
|
14
15
|
* - onMouseUp
|
|
15
16
|
*
|
|
17
|
+
* ### Once that is touch support device, that mouse event will never can be trigger
|
|
16
18
|
* https://developer.mozilla.org/en-US/docs/Web/API/Touch_events/Supporting_both_TouchEvent_and_MouseEvent
|
|
17
19
|
*
|
|
18
20
|
* Event order:
|
|
@@ -26,47 +28,44 @@ var useEventCallback_1 = require("../useEventCallback");
|
|
|
26
28
|
*/
|
|
27
29
|
exports.useTouchMouseEvent = function (_a, _b) {
|
|
28
30
|
var onMouseDownArg = _a.onMouseDown, onMouseUpArg = _a.onMouseUp, onTouchStartArg = _a.onTouchStart, onTouchEndArg = _a.onTouchEnd;
|
|
29
|
-
var
|
|
30
|
-
var
|
|
31
|
-
var
|
|
32
|
-
var startAction = function () { return (isStartRef.current = true); };
|
|
33
|
-
var endAction = function () { return (isStartRef.current = false); };
|
|
31
|
+
var actionRef = (_b === void 0 ? {} : _b).actionRef;
|
|
32
|
+
var stopMouseEventRef = react_1.useRef(false);
|
|
33
|
+
var document = contexts_1.useRcPortalWindowContext().document;
|
|
34
34
|
var onTouchStart = useEventCallback_1.useEventCallback(function (e) {
|
|
35
|
-
|
|
35
|
+
stopMouseEventRef.current = true;
|
|
36
36
|
onTouchStartArg === null || onTouchStartArg === void 0 ? void 0 : onTouchStartArg(e);
|
|
37
37
|
});
|
|
38
|
+
function checkInside(elm) {
|
|
39
|
+
var hostElement = utils_1.getRefElement(actionRef);
|
|
40
|
+
if (hostElement) {
|
|
41
|
+
return !!(elm && exports.isElmEqualOrContain(elm, hostElement));
|
|
42
|
+
}
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
38
45
|
var onTouchEnd = useEventCallback_1.useEventCallback(function (e) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
if (isPreventDefault) {
|
|
45
|
-
e.preventDefault();
|
|
46
|
-
e.stopPropagation();
|
|
46
|
+
var isInside;
|
|
47
|
+
if (actionRef && e.touches.length < 2 && e.changedTouches.length < 2) {
|
|
48
|
+
var touch = e.touches[0] || e.changedTouches[0];
|
|
49
|
+
var elm = document.elementFromPoint(touch.pageX, touch.pageY);
|
|
50
|
+
isInside = !!elm && checkInside(elm);
|
|
47
51
|
}
|
|
48
|
-
|
|
52
|
+
onTouchEndArg === null || onTouchEndArg === void 0 ? void 0 : onTouchEndArg(e, isInside);
|
|
53
|
+
});
|
|
49
54
|
var onMouseDown = useEventCallback_1.useEventCallback(function (e) {
|
|
50
|
-
|
|
51
|
-
if (isLiveEndRef.current) {
|
|
52
|
-
e.preventDefault();
|
|
53
|
-
e.stopPropagation();
|
|
55
|
+
if (stopMouseEventRef.current) {
|
|
54
56
|
return;
|
|
55
57
|
}
|
|
56
58
|
onMouseDownArg === null || onMouseDownArg === void 0 ? void 0 : onMouseDownArg(e);
|
|
57
59
|
});
|
|
58
60
|
var onMouseUp = useEventCallback_1.useEventCallback(function (e) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
63
|
-
endAction();
|
|
64
|
-
if (isLiveEndRef.current) {
|
|
65
|
-
isLiveEndRef.current = false;
|
|
66
|
-
preventDefaultEvent(e);
|
|
61
|
+
var isInside;
|
|
62
|
+
if (stopMouseEventRef.current)
|
|
67
63
|
return;
|
|
64
|
+
if (actionRef) {
|
|
65
|
+
var elm = e.target;
|
|
66
|
+
isInside = !!elm && checkInside(elm);
|
|
68
67
|
}
|
|
69
|
-
onMouseUpArg === null || onMouseUpArg === void 0 ? void 0 : onMouseUpArg(e);
|
|
68
|
+
onMouseUpArg === null || onMouseUpArg === void 0 ? void 0 : onMouseUpArg(e, isInside);
|
|
70
69
|
});
|
|
71
70
|
return {
|
|
72
71
|
onTouchStart: onTouchStart,
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export declare type DeepPartial<T> = {
|
|
2
|
-
[P in keyof T]?: T[P] extends Array<infer U> ? Array<DeepPartial<U>> : T[P] extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : DeepPartial<T[P]
|
|
2
|
+
[P in keyof T]?: T[P] extends Array<infer U> ? Array<DeepPartial<U>> : T[P] extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T[P] extends Record<any, any> ? DeepPartial<T[P]> : T[P];
|
|
3
3
|
};
|