@canlooks/can-ui 0.0.41 → 0.0.43
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/dist/cjs/components/alert/alert.style.js +1 -0
- package/dist/cjs/components/checkboxBase/checkboxBase.js +1 -2
- package/dist/cjs/components/checkboxBaseGroup/checkboxBaseGroup.d.ts +0 -2
- package/dist/cjs/components/checkboxBaseGroup/checkboxBaseGroup.js +3 -3
- package/dist/cjs/components/clickAway/clickAway.d.ts +285 -1
- package/dist/cjs/components/clickAway/clickAway.js +1 -2
- package/dist/cjs/components/dataGrid/columnResize.js +5 -5
- package/dist/cjs/components/dataGrid/dataGrid.js +1 -1
- package/dist/cjs/components/dataGrid/dataGridRows.js +3 -1
- package/dist/cjs/components/descriptions/descriptionItem.d.ts +3 -3
- package/dist/cjs/components/draggable/draggable.d.ts +6 -6
- package/dist/cjs/components/draggable/draggable.js +13 -18
- package/dist/cjs/components/{image/imagePreview.d.ts → gallery/gallery.d.ts} +7 -3
- package/dist/cjs/components/gallery/gallery.js +165 -0
- package/dist/{esm/components/image/imagePreview.style.d.ts → cjs/components/gallery/gallery.style.d.ts} +3 -1
- package/dist/cjs/components/{image/imagePreview.style.js → gallery/gallery.style.js} +49 -13
- package/dist/cjs/components/gallery/imageItem.d.ts +14 -0
- package/dist/cjs/components/gallery/imageItem.js +51 -0
- package/dist/cjs/components/gallery/index.d.ts +1 -0
- package/dist/cjs/components/gallery/index.js +4 -0
- package/dist/cjs/components/image/image.d.ts +2 -2
- package/dist/cjs/components/image/image.js +3 -3
- package/dist/cjs/components/image/index.d.ts +0 -1
- package/dist/cjs/components/image/index.js +0 -1
- package/dist/cjs/components/overlayBase/overlayBase.js +1 -1
- package/dist/cjs/components/palette/palette.d.ts +3 -3
- package/dist/cjs/components/palette/palette.js +9 -9
- package/dist/cjs/components/pickerDialog/pickerDialog.style.js +6 -0
- package/dist/cjs/components/pinchable/index.d.ts +1 -0
- package/dist/cjs/components/pinchable/index.js +4 -0
- package/dist/cjs/components/pinchable/pinchable.d.ts +33 -0
- package/dist/cjs/components/pinchable/pinchable.js +160 -0
- package/dist/cjs/components/pinchable/pinchable.style.d.ts +6 -0
- package/dist/cjs/components/pinchable/pinchable.style.js +21 -0
- package/dist/cjs/components/placeholder/placeholder.style.js +1 -0
- package/dist/cjs/components/progress/progress.d.ts +1 -1
- package/dist/cjs/components/rating/rating.d.ts +2 -2
- package/dist/cjs/components/rating/rating.js +2 -5
- package/dist/cjs/components/rating/rating.style.js +1 -2
- package/dist/cjs/components/resizable/resizable.d.ts +2 -2
- package/dist/cjs/components/resizable/resizable.js +12 -12
- package/dist/cjs/components/scrollbar/scrollbar.d.ts +1 -1
- package/dist/cjs/components/scrollbar/scrollbar.js +6 -6
- package/dist/cjs/components/segmented/SegmentedOption.d.ts +1 -1
- package/dist/cjs/components/selectedList/selectedItem.js +1 -1
- package/dist/cjs/components/selectedList/selectedList.style.js +1 -1
- package/dist/cjs/components/skeleton/skeleton.d.ts +1 -1
- package/dist/cjs/components/slidableActions/slidableActions.d.ts +9 -5
- package/dist/cjs/components/slidableActions/slidableActions.js +21 -25
- package/dist/cjs/components/slidableActions/slidableActions.style.d.ts +1 -1
- package/dist/cjs/components/slidableActions/slidableActions.style.js +14 -13
- package/dist/cjs/components/slidableActions/slidableActionsAction.d.ts +4 -2
- package/dist/cjs/components/slidableActions/slidableActionsAction.js +6 -2
- package/dist/cjs/components/slider/slider.d.ts +3 -3
- package/dist/cjs/components/slider/slider.js +8 -8
- package/dist/cjs/components/tabs/tabs.js +1 -1
- package/dist/cjs/components/theme/themeVariables.js +1 -1
- package/dist/cjs/components/upload/itemStatus.d.ts +1 -1
- package/dist/cjs/components/upload/itemStatus.js +3 -0
- package/dist/cjs/components/upload/upload.d.ts +3 -3
- package/dist/cjs/components/upload/upload.js +1 -1
- package/dist/cjs/extensions/documentViewer/documentViewer.js +1 -2
- package/dist/cjs/index.d.ts +2 -0
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/utils/dnd.d.ts +0 -42
- package/dist/cjs/utils/dnd.js +0 -121
- package/dist/cjs/utils/gesture.d.ts +69 -0
- package/dist/cjs/utils/gesture.js +250 -0
- package/dist/cjs/utils/index.d.ts +1 -0
- package/dist/cjs/utils/index.js +1 -0
- package/dist/cjs/utils/style.js +1 -1
- package/dist/cjs/utils/utils.d.ts +0 -2
- package/dist/cjs/utils/utils.js +0 -2
- package/dist/esm/components/alert/alert.style.js +1 -0
- package/dist/esm/components/checkboxBase/checkboxBase.js +1 -2
- package/dist/esm/components/checkboxBaseGroup/checkboxBaseGroup.d.ts +0 -2
- package/dist/esm/components/checkboxBaseGroup/checkboxBaseGroup.js +4 -4
- package/dist/esm/components/clickAway/clickAway.d.ts +285 -1
- package/dist/esm/components/clickAway/clickAway.js +2 -3
- package/dist/esm/components/dataGrid/columnResize.js +6 -6
- package/dist/esm/components/dataGrid/dataGrid.js +1 -1
- package/dist/esm/components/dataGrid/dataGridRows.js +3 -1
- package/dist/esm/components/descriptions/descriptionItem.d.ts +3 -3
- package/dist/esm/components/draggable/draggable.d.ts +6 -6
- package/dist/esm/components/draggable/draggable.js +14 -19
- package/dist/esm/components/{image/imagePreview.d.ts → gallery/gallery.d.ts} +7 -3
- package/dist/esm/components/gallery/gallery.js +162 -0
- package/dist/{cjs/components/image/imagePreview.style.d.ts → esm/components/gallery/gallery.style.d.ts} +3 -1
- package/dist/esm/components/{image/imagePreview.style.js → gallery/gallery.style.js} +49 -13
- package/dist/esm/components/gallery/imageItem.d.ts +14 -0
- package/dist/esm/components/gallery/imageItem.js +48 -0
- package/dist/esm/components/gallery/index.d.ts +1 -0
- package/dist/esm/components/gallery/index.js +1 -0
- package/dist/esm/components/image/image.d.ts +2 -2
- package/dist/esm/components/image/image.js +3 -3
- package/dist/esm/components/image/index.d.ts +0 -1
- package/dist/esm/components/image/index.js +0 -1
- package/dist/esm/components/overlayBase/overlayBase.js +1 -1
- package/dist/esm/components/palette/palette.d.ts +3 -3
- package/dist/esm/components/palette/palette.js +10 -10
- package/dist/esm/components/pickerDialog/pickerDialog.style.js +6 -0
- package/dist/esm/components/pinchable/index.d.ts +1 -0
- package/dist/esm/components/pinchable/index.js +1 -0
- package/dist/esm/components/pinchable/pinchable.d.ts +33 -0
- package/dist/esm/components/pinchable/pinchable.js +157 -0
- package/dist/esm/components/pinchable/pinchable.style.d.ts +6 -0
- package/dist/esm/components/pinchable/pinchable.style.js +18 -0
- package/dist/esm/components/placeholder/placeholder.style.js +1 -0
- package/dist/esm/components/progress/progress.d.ts +1 -1
- package/dist/esm/components/rating/rating.d.ts +2 -2
- package/dist/esm/components/rating/rating.js +2 -5
- package/dist/esm/components/rating/rating.style.js +1 -2
- package/dist/esm/components/resizable/resizable.d.ts +2 -2
- package/dist/esm/components/resizable/resizable.js +13 -13
- package/dist/esm/components/scrollbar/scrollbar.d.ts +1 -1
- package/dist/esm/components/scrollbar/scrollbar.js +7 -7
- package/dist/esm/components/segmented/SegmentedOption.d.ts +1 -1
- package/dist/esm/components/selectedList/selectedItem.js +1 -1
- package/dist/esm/components/selectedList/selectedList.style.js +1 -1
- package/dist/esm/components/skeleton/skeleton.d.ts +1 -1
- package/dist/esm/components/slidableActions/slidableActions.d.ts +9 -5
- package/dist/esm/components/slidableActions/slidableActions.js +22 -26
- package/dist/esm/components/slidableActions/slidableActions.style.d.ts +1 -1
- package/dist/esm/components/slidableActions/slidableActions.style.js +14 -13
- package/dist/esm/components/slidableActions/slidableActionsAction.d.ts +4 -2
- package/dist/esm/components/slidableActions/slidableActionsAction.js +6 -2
- package/dist/esm/components/slider/slider.d.ts +3 -3
- package/dist/esm/components/slider/slider.js +9 -9
- package/dist/esm/components/tabs/tabs.js +1 -1
- package/dist/esm/components/theme/themeVariables.js +1 -1
- package/dist/esm/components/upload/itemStatus.d.ts +1 -1
- package/dist/esm/components/upload/itemStatus.js +3 -0
- package/dist/esm/components/upload/upload.d.ts +3 -3
- package/dist/esm/components/upload/upload.js +1 -1
- package/dist/esm/extensions/documentViewer/documentViewer.js +2 -3
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/utils/dnd.d.ts +0 -42
- package/dist/esm/utils/dnd.js +0 -120
- package/dist/esm/utils/gesture.d.ts +69 -0
- package/dist/esm/utils/gesture.js +245 -0
- package/dist/esm/utils/index.d.ts +1 -0
- package/dist/esm/utils/index.js +1 -0
- package/dist/esm/utils/style.js +1 -1
- package/dist/esm/utils/utils.d.ts +0 -2
- package/dist/esm/utils/utils.js +0 -2
- package/documentation/dist/assets/{index-B6FOULC1.js → index-DXo4Z-bc.js} +1281 -1271
- package/documentation/dist/components/actionSheet.md +3 -3
- package/documentation/dist/components/autocomplete.md +10 -10
- package/documentation/dist/components/breadcrumb.md +1 -1
- package/documentation/dist/components/checkbox.md +24 -1
- package/documentation/dist/components/contextMenu.md +1 -1
- package/documentation/dist/components/counter.md +13 -13
- package/documentation/dist/components/dialog.md +3 -3
- package/documentation/dist/components/formDialog.md +6 -6
- package/documentation/dist/components/image.md +5 -3
- package/documentation/dist/components/menu.md +1 -1
- package/documentation/dist/components/pagination.md +15 -1
- package/documentation/dist/components/pickerDialog.md +56 -0
- package/documentation/dist/components/placeholder.md +30 -0
- package/documentation/dist/components/progress.md +43 -0
- package/documentation/dist/components/radio.md +37 -0
- package/documentation/dist/components/rating.md +35 -0
- package/documentation/dist/components/resizable.md +41 -0
- package/documentation/dist/components/scrollbar.md +31 -0
- package/documentation/dist/components/segmented.md +56 -0
- package/documentation/dist/components/select.md +30 -0
- package/documentation/dist/components/skeleton.md +26 -0
- package/documentation/dist/components/slidableActions.md +53 -0
- package/documentation/dist/guide/globalMethods.md +6 -6
- package/documentation/dist/index.html +1 -1
- package/package.json +6 -6
- package/dist/cjs/components/image/imagePreview.js +0 -63
- package/dist/esm/components/image/imagePreview.js +0 -60
|
@@ -2,18 +2,14 @@ import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
|
2
2
|
import { cloneElement, createContext, isValidElement, memo, useContext, useMemo, useRef, useState } from 'react';
|
|
3
3
|
import { ClickAway } from '../clickAway';
|
|
4
4
|
import { classes, style } from './slidableActions.style';
|
|
5
|
-
import { cubicBezier, clsx, useSyncState, range,
|
|
5
|
+
import { cubicBezier, clsx, useSyncState, range, toArray, useDraggable } from '../../utils';
|
|
6
6
|
import { SlidableActionsAction } from './slidableActionsAction';
|
|
7
|
-
const
|
|
8
|
-
const SlidableActionsContext = createContext({
|
|
9
|
-
actionsContainer: [],
|
|
10
|
-
translate: 0,
|
|
11
|
-
maxDistance: 0
|
|
12
|
-
});
|
|
7
|
+
const bounceBezier = cubicBezier(0, 0, 0, 1);
|
|
8
|
+
const SlidableActionsContext = createContext({});
|
|
13
9
|
export function useSlidableActionsContext() {
|
|
14
10
|
return useContext(SlidableActionsContext);
|
|
15
11
|
}
|
|
16
|
-
export const SlidableActions = memo(({ bounceElementTranslate =
|
|
12
|
+
export const SlidableActions = memo(({ bounceElementTranslate = 12, bounceDragDistance = 240, effectiveSpeed = 450, leftActions, rightActions, autoReturn = true, disabled, gestureOptions, ...props }) => {
|
|
17
13
|
const leftActionsContainer = useRef([]);
|
|
18
14
|
const rightActionsContainer = useRef([]);
|
|
19
15
|
const [distanceRange, setDistanceRange] = useSyncState([0, 0]);
|
|
@@ -31,37 +27,37 @@ export const SlidableActions = memo(({ bounceElementTranslate = 24, bounceDragDi
|
|
|
31
27
|
const [translate, setTranslate] = useState(0);
|
|
32
28
|
const [dragging, setDragging] = useState(false);
|
|
33
29
|
const startTranslate = useRef(0);
|
|
34
|
-
const
|
|
35
|
-
...
|
|
30
|
+
const draggableHandles = useDraggable({
|
|
31
|
+
...gestureOptions,
|
|
36
32
|
disabled,
|
|
37
|
-
|
|
33
|
+
preventNativeTouchMove: true,
|
|
38
34
|
onDragStart(e) {
|
|
39
|
-
|
|
35
|
+
gestureOptions?.onDragStart?.(e);
|
|
40
36
|
setDragging(true);
|
|
41
37
|
startTranslate.current = translate;
|
|
42
38
|
getDistanceRange();
|
|
43
39
|
},
|
|
44
40
|
onDrag(info, e) {
|
|
45
|
-
|
|
41
|
+
gestureOptions?.onDrag?.(info, e);
|
|
46
42
|
const [min, max] = distanceRange.current;
|
|
47
43
|
const bounceMin = min < 0 ? min - bounceDragDistance : min;
|
|
48
44
|
const bounceMax = max > 0 ? max + bounceDragDistance : max;
|
|
49
|
-
let newTranslate = range(startTranslate.current + info.
|
|
45
|
+
let newTranslate = range(startTranslate.current + info.diff[0], bounceMin, bounceMax);
|
|
50
46
|
// 拖拽超过正常距离,模拟弹性
|
|
51
47
|
if (newTranslate < min) {
|
|
52
|
-
newTranslate = min -
|
|
48
|
+
newTranslate = min - bounceBezier(-(newTranslate - min) / bounceDragDistance) * bounceElementTranslate;
|
|
53
49
|
}
|
|
54
50
|
else if (newTranslate > max) {
|
|
55
|
-
newTranslate = max +
|
|
51
|
+
newTranslate = max + bounceBezier((newTranslate - max) / bounceDragDistance) * bounceElementTranslate;
|
|
56
52
|
}
|
|
57
53
|
setTranslate(newTranslate);
|
|
58
54
|
},
|
|
59
55
|
onDragEnd(info) {
|
|
60
|
-
|
|
56
|
+
gestureOptions?.onDragEnd?.(info);
|
|
61
57
|
setDragging(false);
|
|
62
58
|
const start = startTranslate.current;
|
|
63
59
|
const [min, max] = distanceRange.current;
|
|
64
|
-
const isSpeedSatisfied = () => effectiveSpeed && info.
|
|
60
|
+
const isSpeedSatisfied = () => effectiveSpeed && info.speed[0] * 1000 >= effectiveSpeed;
|
|
65
61
|
// 拖拽距离达到一半,或者满足速度要求
|
|
66
62
|
if (start < 0) {
|
|
67
63
|
if (translate > start && (translate >= min / 2 || isSpeedSatisfied())) {
|
|
@@ -82,14 +78,14 @@ export const SlidableActions = memo(({ bounceElementTranslate = 24, bounceDragDi
|
|
|
82
78
|
else {
|
|
83
79
|
// 原本在中间
|
|
84
80
|
if (translate < min / 2 || translate > max / 2 || isSpeedSatisfied()) {
|
|
85
|
-
return setTranslate(info.
|
|
81
|
+
return setTranslate(info.diff[0] > 0 ? max : min);
|
|
86
82
|
}
|
|
87
83
|
}
|
|
88
84
|
// 未满足条件,返回原位
|
|
89
85
|
setTranslate(startTranslate.current);
|
|
90
86
|
},
|
|
91
87
|
onDragCancel(info) {
|
|
92
|
-
|
|
88
|
+
gestureOptions?.onDragCancel?.(info);
|
|
93
89
|
setDragging(false);
|
|
94
90
|
const [min, max] = distanceRange.current;
|
|
95
91
|
translate < min / 2 && translate > max / 2
|
|
@@ -97,7 +93,7 @@ export const SlidableActions = memo(({ bounceElementTranslate = 24, bounceDragDi
|
|
|
97
93
|
: setTranslate(0);
|
|
98
94
|
}
|
|
99
95
|
});
|
|
100
|
-
const
|
|
96
|
+
const resetTranslate = () => {
|
|
101
97
|
translate && setTranslate(0);
|
|
102
98
|
};
|
|
103
99
|
const renderActions = (actions) => {
|
|
@@ -112,16 +108,16 @@ export const SlidableActions = memo(({ bounceElementTranslate = 24, bounceDragDi
|
|
|
112
108
|
: child;
|
|
113
109
|
});
|
|
114
110
|
};
|
|
115
|
-
return (_jsx(ClickAway, { eventType: "pointerdown", onClickAway:
|
|
111
|
+
return (_jsx(ClickAway, { eventType: "pointerdown", onClickAway: resetTranslate, children: _jsxs("div", { ...props, css: style, className: clsx(classes.root, props.className), "data-dragging": dragging, children: [_jsx("div", { className: classes.content, ...draggableHandles, style: { translate: `${translate}px 0` }, children: props.children }), _jsxs("div", { className: classes.actions, children: [_jsx(SlidableActionsContext, { value: useMemo(() => ({
|
|
116
112
|
actionsContainer: leftActionsContainer.current,
|
|
117
|
-
translate,
|
|
113
|
+
translate, resetTranslate, autoReturn,
|
|
118
114
|
maxDistance: distanceRange.current[1]
|
|
119
|
-
}), [translate, distanceRange.current]), children: _jsx("div", { className: classes.actionsLeft, children: !!leftActions &&
|
|
115
|
+
}), [translate, distanceRange.current, autoReturn]), children: _jsx("div", { className: classes.actionsLeft, children: !!leftActions &&
|
|
120
116
|
renderActions(leftActions) }) }), _jsx(SlidableActionsContext, { value: useMemo(() => ({
|
|
121
117
|
actionsContainer: rightActionsContainer.current,
|
|
122
|
-
translate,
|
|
118
|
+
translate, resetTranslate, autoReturn,
|
|
123
119
|
maxDistance: -distanceRange.current[0]
|
|
124
|
-
}), [translate, distanceRange.current]), children: _jsx("div", { className: classes.actionsRight, children: !!rightActions &&
|
|
120
|
+
}), [translate, distanceRange.current, autoReturn]), children: _jsx("div", { className: classes.actionsRight, children: !!rightActions &&
|
|
125
121
|
renderActions(rightActions) }) })] })] }) }));
|
|
126
122
|
});
|
|
127
123
|
SlidableActions.Action = SlidableActionsAction;
|
|
@@ -6,29 +6,29 @@ export const classes = defineInnerClasses('slidable-actions', [
|
|
|
6
6
|
'actionsLeft',
|
|
7
7
|
'actionsRight',
|
|
8
8
|
'actionItem',
|
|
9
|
-
'
|
|
9
|
+
'actionItemButton',
|
|
10
10
|
'actionItemIcon'
|
|
11
11
|
]);
|
|
12
12
|
export const style = defineCss(({ background }) => css `
|
|
13
13
|
position: relative;
|
|
14
14
|
overflow: hidden;
|
|
15
|
-
|
|
15
|
+
|
|
16
16
|
.${classes.content} {
|
|
17
17
|
touch-action: pan-y;
|
|
18
18
|
position: relative;
|
|
19
19
|
z-index: 1;
|
|
20
20
|
}
|
|
21
|
-
|
|
21
|
+
|
|
22
22
|
.${classes.actions} {
|
|
23
23
|
position: absolute;
|
|
24
24
|
inset: 0;
|
|
25
|
-
|
|
25
|
+
|
|
26
26
|
.${classes.actionsLeft}, .${classes.actionsRight} {
|
|
27
27
|
width: 100%;
|
|
28
28
|
height: 100%;
|
|
29
29
|
position: absolute;
|
|
30
30
|
top: 0;
|
|
31
|
-
|
|
31
|
+
|
|
32
32
|
.${classes.actionItem} {
|
|
33
33
|
width: 100%;
|
|
34
34
|
height: 100%;
|
|
@@ -38,34 +38,35 @@ export const style = defineCss(({ background }) => css `
|
|
|
38
38
|
color: ${background.content};
|
|
39
39
|
position: absolute;
|
|
40
40
|
top: 0;
|
|
41
|
-
|
|
42
|
-
.${classes.
|
|
41
|
+
|
|
42
|
+
.${classes.actionItemButton} {
|
|
43
43
|
flex: 1;
|
|
44
44
|
display: flex;
|
|
45
45
|
flex-direction: column;
|
|
46
46
|
align-items: center;
|
|
47
47
|
justify-content: center;
|
|
48
|
-
padding: 0 18px;
|
|
48
|
+
padding: 0 18px;
|
|
49
|
+
border-radius: 0;
|
|
49
50
|
}
|
|
50
|
-
|
|
51
|
+
|
|
51
52
|
.${classes.actionItemIcon} {
|
|
52
53
|
display: flex;
|
|
53
54
|
}
|
|
54
55
|
}
|
|
55
56
|
}
|
|
56
|
-
|
|
57
|
+
|
|
57
58
|
.${classes.actionsLeft} {
|
|
58
59
|
right: 100%;
|
|
59
|
-
|
|
60
|
+
|
|
60
61
|
.${classes.actionItem} {
|
|
61
62
|
align-items: flex-end;
|
|
62
63
|
right: 0;
|
|
63
64
|
}
|
|
64
65
|
}
|
|
65
|
-
|
|
66
|
+
|
|
66
67
|
.${classes.actionsRight} {
|
|
67
68
|
left: 100%;
|
|
68
|
-
|
|
69
|
+
|
|
69
70
|
.${classes.actionItem} {
|
|
70
71
|
align-items: flex-start;
|
|
71
72
|
left: 0;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ReactNode } from 'react';
|
|
1
|
+
import React, { ReactNode } from 'react';
|
|
2
2
|
import { ColorPropsValue, DivProps } from '../../types';
|
|
3
3
|
import { ButtonProps } from '../button';
|
|
4
4
|
export interface SlidableActionsActionProps extends DivProps {
|
|
@@ -6,7 +6,9 @@ export interface SlidableActionsActionProps extends DivProps {
|
|
|
6
6
|
label?: ReactNode;
|
|
7
7
|
icon?: ReactNode;
|
|
8
8
|
buttonProps?: Omit<ButtonProps, 'onClick'>;
|
|
9
|
+
/** 点击action后是否自动归位,默认为`true` */
|
|
10
|
+
autoReturn?: boolean;
|
|
9
11
|
/** @private */
|
|
10
12
|
_index?: number;
|
|
11
13
|
}
|
|
12
|
-
export declare const SlidableActionsAction:
|
|
14
|
+
export declare const SlidableActionsAction: React.MemoExoticComponent<({ color, label, icon, buttonProps, _index, ...props }: SlidableActionsActionProps) => import("@emotion/react/jsx-runtime").JSX.Element>;
|
|
@@ -6,7 +6,7 @@ import { clsx, cloneRef, colorTransfer } from '../../utils';
|
|
|
6
6
|
import { useTheme } from '../theme';
|
|
7
7
|
import { useSlidableActionsContext } from './slidableActions';
|
|
8
8
|
export const SlidableActionsAction = memo(({ color = 'default', label, icon, buttonProps, _index, ...props }) => {
|
|
9
|
-
const { actionsContainer, translate, maxDistance } = useSlidableActionsContext();
|
|
9
|
+
const { actionsContainer, translate, resetTranslate, maxDistance, autoReturn } = useSlidableActionsContext();
|
|
10
10
|
const innerButtonRef = useRef(null);
|
|
11
11
|
useEffect(() => {
|
|
12
12
|
actionsContainer[_index] = innerButtonRef.current;
|
|
@@ -29,8 +29,12 @@ export const SlidableActionsAction = memo(({ color = 'default', label, icon, but
|
|
|
29
29
|
? '#aaaaaa'
|
|
30
30
|
: colorTransfer(color, theme);
|
|
31
31
|
}, [color, theme]);
|
|
32
|
+
const clickHandler = (e) => {
|
|
33
|
+
props.onClick?.(e);
|
|
34
|
+
autoReturn && resetTranslate();
|
|
35
|
+
};
|
|
32
36
|
return (_jsx("div", { ...props, className: classes.actionItem, style: {
|
|
33
37
|
translate: `${currentTranslate}px 0`,
|
|
34
38
|
backgroundColor
|
|
35
|
-
}, children: _jsx(Button, { ...buttonProps, ref: cloneRef(buttonProps?.ref, innerButtonRef), className: clsx(classes.
|
|
39
|
+
}, onClick: clickHandler, children: _jsx(Button, { ...buttonProps, ref: cloneRef(buttonProps?.ref, innerButtonRef), className: clsx(classes.actionItemButton, buttonProps?.className), prefix: icon, color: color, variant: "flatted", children: label }) }));
|
|
36
40
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HTMLAttributes, ReactNode, JSX } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { GestureOptions } from '../../utils';
|
|
3
3
|
import { ColorPropsValue, DivProps } from '../../types';
|
|
4
4
|
import { TooltipProps } from '../tooltip';
|
|
5
5
|
export interface MarkItem extends DivProps {
|
|
@@ -41,7 +41,7 @@ interface SliderBaseProps extends Omit<DivProps, 'defaultValue' | 'onChange' | '
|
|
|
41
41
|
markLabelOffset?: number;
|
|
42
42
|
markSize?: number;
|
|
43
43
|
disableTrack?: boolean;
|
|
44
|
-
|
|
44
|
+
gestureOptions?: GestureOptions;
|
|
45
45
|
}
|
|
46
46
|
export interface SliderSingleProps extends SliderBaseProps {
|
|
47
47
|
defaultValue?: number;
|
|
@@ -58,5 +58,5 @@ export interface SliderRangeProps extends SliderBaseProps {
|
|
|
58
58
|
suffix?: ReactNode | ((value: [number, number]) => ReactNode);
|
|
59
59
|
}
|
|
60
60
|
export type SliderProps = SliderSingleProps | SliderRangeProps;
|
|
61
|
-
export declare const Slider: import("react").MemoExoticComponent<({ color, orientation, variant, inset, railSize, railProps, renderRail, handleSize, handleProps, disableHandleOutline, renderHandle, tooltipProps, min, max, step, marks, markLabelOffset, prefix, suffix, disableTrack,
|
|
61
|
+
export declare const Slider: import("react").MemoExoticComponent<({ color, orientation, variant, inset, railSize, railProps, renderRail, handleSize, handleProps, disableHandleOutline, renderHandle, tooltipProps, min, max, step, marks, markLabelOffset, prefix, suffix, disableTrack, gestureOptions, defaultValue, value, onChange, ...props }: SliderProps) => import("@emotion/react/jsx-runtime").JSX.Element>;
|
|
62
62
|
export {};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
|
|
2
2
|
import { createElement as _createElement } from "@emotion/react";
|
|
3
3
|
import { memo, useEffect, useMemo, useRef } from 'react';
|
|
4
|
-
import { clsx, cloneRef, isUnset, useControlled,
|
|
4
|
+
import { clsx, cloneRef, isUnset, useControlled, useDraggable } from '../../utils';
|
|
5
5
|
import { classes, useStyle } from './slider.style';
|
|
6
6
|
import { Tooltip } from '../tooltip';
|
|
7
7
|
import { useTheme } from '../theme';
|
|
8
|
-
export const Slider = memo(({ color = 'primary', orientation = 'horizontal', variant = 'filled', inset, railSize = inset ? 14 : 4, railProps, renderRail, handleSize = 14, handleProps, disableHandleOutline, renderHandle, tooltipProps, min = 0, max = 100, step = 1, marks, markLabelOffset, prefix, suffix, disableTrack,
|
|
8
|
+
export const Slider = memo(({ color = 'primary', orientation = 'horizontal', variant = 'filled', inset, railSize = inset ? 14 : 4, railProps, renderRail, handleSize = 14, handleProps, disableHandleOutline, renderHandle, tooltipProps, min = 0, max = 100, step = 1, marks, markLabelOffset, prefix, suffix, disableTrack, gestureOptions, defaultValue = min, value, onChange, ...props }) => {
|
|
9
9
|
const { spacing } = useTheme();
|
|
10
10
|
markLabelOffset ??= inset ? spacing[1] : spacing[2];
|
|
11
11
|
const orderedMarks = useMemo(() => {
|
|
@@ -87,10 +87,10 @@ export const Slider = memo(({ color = 'primary', orientation = 'horizontal', var
|
|
|
87
87
|
const railRef = useRef(null);
|
|
88
88
|
const handleRefs = useRef([]);
|
|
89
89
|
const dragStartData = useRef(void 0);
|
|
90
|
-
const
|
|
91
|
-
...
|
|
90
|
+
const draggableHandles = useDraggable({
|
|
91
|
+
...gestureOptions,
|
|
92
92
|
onDragStart(e) {
|
|
93
|
-
|
|
93
|
+
gestureOptions?.onDragStart?.(e);
|
|
94
94
|
const railLength = orientation === 'horizontal' ? railRef.current.offsetWidth : railRef.current.offsetHeight;
|
|
95
95
|
let handleIndex = 0;
|
|
96
96
|
let percent;
|
|
@@ -147,9 +147,9 @@ export const Slider = memo(({ color = 'primary', orientation = 'horizontal', var
|
|
|
147
147
|
dragStartData.current = { railLength, percent, handleIndex };
|
|
148
148
|
},
|
|
149
149
|
onDrag(info, e) {
|
|
150
|
-
|
|
150
|
+
gestureOptions?.onDrag?.(info, e);
|
|
151
151
|
const { percent, railLength, handleIndex } = dragStartData.current;
|
|
152
|
-
const delta = orientation === 'horizontal' ? info.
|
|
152
|
+
const delta = orientation === 'horizontal' ? info.diff[0] : -info.diff[1];
|
|
153
153
|
setInnerValue(percentToValue(percent + delta / railLength * 100), handleIndex);
|
|
154
154
|
}
|
|
155
155
|
});
|
|
@@ -184,7 +184,7 @@ export const Slider = memo(({ color = 'primary', orientation = 'horizontal', var
|
|
|
184
184
|
onPointerDown(e) {
|
|
185
185
|
e.stopPropagation();
|
|
186
186
|
handleProps?.onPointerDown?.(e);
|
|
187
|
-
|
|
187
|
+
draggableHandles.onPointerDown(e);
|
|
188
188
|
}
|
|
189
189
|
};
|
|
190
190
|
return renderHandle
|
|
@@ -226,7 +226,7 @@ export const Slider = memo(({ color = 'primary', orientation = 'horizontal', var
|
|
|
226
226
|
},
|
|
227
227
|
onPointerDown: e => {
|
|
228
228
|
railProps?.onPointerDown?.(e);
|
|
229
|
-
|
|
229
|
+
draggableHandles.onPointerDown(e);
|
|
230
230
|
},
|
|
231
231
|
children: (_jsxs("div", { className: classes.railWrap, children: [!disableTrack &&
|
|
232
232
|
_jsx("div", { className: classes.track, style: valueIsArray
|
|
@@ -94,7 +94,7 @@ export const Tabs = memo(({ tabs, labelKey = 'label', primaryKey = 'value', vari
|
|
|
94
94
|
});
|
|
95
95
|
};
|
|
96
96
|
if (position === 'top' || position === 'bottom') {
|
|
97
|
-
scroller.addEventListener('wheel', onWheel
|
|
97
|
+
scroller.addEventListener('wheel', onWheel);
|
|
98
98
|
}
|
|
99
99
|
const resizeObserver = new ResizeObserver(setShadow);
|
|
100
100
|
resizeObserver.observe(scroller);
|
|
@@ -103,7 +103,7 @@ export const defaultBreakpoints = {
|
|
|
103
103
|
sm: 600,
|
|
104
104
|
md: 900,
|
|
105
105
|
lg: 1200,
|
|
106
|
-
xl:
|
|
106
|
+
xl: 1500
|
|
107
107
|
};
|
|
108
108
|
export const defaultFontFamily = `-apple-system, BlinkMacSystemFont, 'Segoe UI',
|
|
109
109
|
Roboto, 'Helvetica Neue', Arial, 'Noto Sans', 'Apple Color Emoji', 'Segoe UI Emoji',
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Dispatch, Ref, SetStateAction } from 'react';
|
|
2
2
|
import { UploadSharedProps, UploadFile, UploadStatus } from './upload';
|
|
3
3
|
export type ItemRef<R, A extends any[]> = {
|
|
4
|
-
upload(...args: A): Promise<R>;
|
|
4
|
+
upload(...args: A): Promise<R | undefined>;
|
|
5
5
|
setStatus: Dispatch<SetStateAction<UploadStatus>>;
|
|
6
6
|
setProgress: Dispatch<SetStateAction<number>>;
|
|
7
7
|
};
|
|
@@ -8,11 +8,11 @@ export interface UploadFile<R, A extends any[]> extends File {
|
|
|
8
8
|
progress?: number;
|
|
9
9
|
status?: UploadStatus;
|
|
10
10
|
url?: string;
|
|
11
|
-
upload?(...args: A): Promise<R>;
|
|
11
|
+
upload?(...args: A): Promise<R | undefined>;
|
|
12
12
|
}
|
|
13
13
|
export interface UploadSharedProps<R, A extends any[]> {
|
|
14
14
|
type?: 'file' | 'image';
|
|
15
|
-
onUpload(files: UploadFile<R, A>[], setProgress: Dispatch<SetStateAction<number>>, ...args: A): Promise<R>;
|
|
15
|
+
onUpload?(files: UploadFile<R, A>[], setProgress: Dispatch<SetStateAction<number>>, ...args: A): Promise<R>;
|
|
16
16
|
}
|
|
17
17
|
export interface UploadProps<R, A extends any[]> extends UploadSharedProps<R, A>, Omit<DivProps, 'defaultValue' | 'onChange'> {
|
|
18
18
|
inputProps?: JSX.IntrinsicElements['input'];
|
|
@@ -37,7 +37,7 @@ export interface UploadProps<R, A extends any[]> extends UploadSharedProps<R, A>
|
|
|
37
37
|
onChange?(value: UploadFile<R, A>[]): void;
|
|
38
38
|
}
|
|
39
39
|
export interface UploadRef<R = any, A extends any[] = any[]> extends HTMLDivElement {
|
|
40
|
-
upload(...args: A): Promise<R>;
|
|
40
|
+
upload(...args: A): Promise<R | undefined>;
|
|
41
41
|
}
|
|
42
42
|
export declare const Upload: {
|
|
43
43
|
<R, A extends any[]>(props: UploadProps<R, A>): ReactElement;
|
|
@@ -31,7 +31,7 @@ export const Upload = memo(({ inputProps, type = 'file', accept = type === 'imag
|
|
|
31
31
|
itemRef?.setProgress(0);
|
|
32
32
|
}
|
|
33
33
|
try {
|
|
34
|
-
const ret = await onUpload(innerValue.current, progress => {
|
|
34
|
+
const ret = await onUpload?.(innerValue.current, progress => {
|
|
35
35
|
for (const [, itemRef] of itemRefs.current) {
|
|
36
36
|
itemRef?.setProgress(progress);
|
|
37
37
|
}
|
|
@@ -7,8 +7,7 @@ import { Button } from '../../components/button';
|
|
|
7
7
|
import { iframeStyle } from './documentViewer.style';
|
|
8
8
|
import { useDerivedState, useLoading } from '../../utils';
|
|
9
9
|
import { PdfViewer } from './pdfViewer';
|
|
10
|
-
import {
|
|
11
|
-
import { Icon } from '../..';
|
|
10
|
+
import { Gallery, Icon } from '../..';
|
|
12
11
|
import { faDownload } from '@fortawesome/free-solid-svg-icons/faDownload';
|
|
13
12
|
export const DocumentViewer = memo(({ src, filename, onError, type, extension, setDocumentTitle = true }) => {
|
|
14
13
|
const mimeType = useMemo(() => {
|
|
@@ -59,7 +58,7 @@ export const DocumentViewer = memo(({ src, filename, onError, type, extension, s
|
|
|
59
58
|
}
|
|
60
59
|
// image
|
|
61
60
|
if (mimeType.includes('image/')) {
|
|
62
|
-
return _jsx(
|
|
61
|
+
return _jsx(Gallery, { src: src, open: true, showClose: false });
|
|
63
62
|
}
|
|
64
63
|
return empty;
|
|
65
64
|
});
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -37,6 +37,7 @@ export * from './components/dropdown';
|
|
|
37
37
|
export * from './components/flex';
|
|
38
38
|
export * from './components/form';
|
|
39
39
|
export * from './components/formDialog';
|
|
40
|
+
export * from './components/gallery';
|
|
40
41
|
export * from './components/grid';
|
|
41
42
|
export * from './components/highlight';
|
|
42
43
|
export * from './components/image';
|
|
@@ -52,6 +53,7 @@ export * from './components/overlayBase';
|
|
|
52
53
|
export * from './components/pagination';
|
|
53
54
|
export * from './components/palette';
|
|
54
55
|
export * from './components/pickerDialog';
|
|
56
|
+
export * from './components/pinchable';
|
|
55
57
|
export * from './components/placeholder';
|
|
56
58
|
export * from './components/popper';
|
|
57
59
|
export * from './components/progress';
|
package/dist/esm/index.js
CHANGED
|
@@ -37,6 +37,7 @@ export * from './components/dropdown';
|
|
|
37
37
|
export * from './components/flex';
|
|
38
38
|
export * from './components/form';
|
|
39
39
|
export * from './components/formDialog';
|
|
40
|
+
export * from './components/gallery';
|
|
40
41
|
export * from './components/grid';
|
|
41
42
|
export * from './components/highlight';
|
|
42
43
|
export * from './components/image';
|
|
@@ -52,6 +53,7 @@ export * from './components/overlayBase';
|
|
|
52
53
|
export * from './components/pagination';
|
|
53
54
|
export * from './components/palette';
|
|
54
55
|
export * from './components/pickerDialog';
|
|
56
|
+
export * from './components/pinchable';
|
|
55
57
|
export * from './components/placeholder';
|
|
56
58
|
export * from './components/popper';
|
|
57
59
|
export * from './components/progress';
|
package/dist/esm/utils/dnd.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import React, { HTMLAttributes } from 'react';
|
|
2
1
|
import { DragEndEvent } from '@dnd-kit/core';
|
|
3
2
|
import { Obj } from '../types';
|
|
4
3
|
/**
|
|
@@ -12,44 +11,3 @@ export declare function useDndSensors(): import("@dnd-kit/core").SensorDescripto
|
|
|
12
11
|
* @param primaryKey 索引用的主键
|
|
13
12
|
*/
|
|
14
13
|
export declare function onDndDragEnd<S extends Obj>(e: DragEndEvent, prevState: S[], primaryKey?: string): S[] | undefined;
|
|
15
|
-
export type DraggableOptions<T extends Element = Element, D = any> = {
|
|
16
|
-
disabled?: boolean;
|
|
17
|
-
/** 按下后经过一段时间才触发拖拽事件,单位ms */
|
|
18
|
-
delay?: number;
|
|
19
|
-
/** 拖拽一段距离后才触发拖拽事件,单位px */
|
|
20
|
-
distance?: number;
|
|
21
|
-
onDragStart?(e: React.PointerEvent<T>): D;
|
|
22
|
-
onDrag?(info: DragInfo<D>, e: PointerEvent): void;
|
|
23
|
-
onDragEnd?(info: DragEndInfo<D>): void;
|
|
24
|
-
onDragCancel?(info: DragEndInfo<D>): void;
|
|
25
|
-
/** 若设为true,则会禁用浏览器默认拖拽行为,通常在触屏端使用 */
|
|
26
|
-
disableNativeTouchMove?: boolean;
|
|
27
|
-
/** 托管原有的onPointerDown、onTouchStart、onClick事件 */
|
|
28
|
-
onPointerDown?(e: React.PointerEvent<T>): void;
|
|
29
|
-
onTouchStart?(e: React.TouchEvent<T>): void;
|
|
30
|
-
onClick?(e: React.MouseEvent<T>): void;
|
|
31
|
-
/** 若拖拽节点受zoom样式的影响,可传入zoom值修正 */
|
|
32
|
-
zoom?: number;
|
|
33
|
-
};
|
|
34
|
-
export type DragInfo<T> = {
|
|
35
|
-
/** 开始位置 */
|
|
36
|
-
startX: number;
|
|
37
|
-
startY: number;
|
|
38
|
-
/** 当前位置 */
|
|
39
|
-
currentX: number;
|
|
40
|
-
currentY: number;
|
|
41
|
-
/** 拖拽距离,往右下拖拽为正数,往左上拖拽为负数 */
|
|
42
|
-
deltaX: number;
|
|
43
|
-
deltaY: number;
|
|
44
|
-
/** `onDragStart`的返回值 */
|
|
45
|
-
startData: T | undefined;
|
|
46
|
-
};
|
|
47
|
-
export interface DragEndInfo<T> extends DragInfo<T> {
|
|
48
|
-
/** 从按下到抬起经过的时长(ms) */
|
|
49
|
-
duration: number;
|
|
50
|
-
/** 拖拽速度(px/ms) */
|
|
51
|
-
speedX: number;
|
|
52
|
-
speedY: number;
|
|
53
|
-
}
|
|
54
|
-
export type HandleProps<T extends Element> = Required<Pick<HTMLAttributes<T>, 'onPointerDown' | 'onTouchStart' | 'onClick' | 'onDragStart'>>;
|
|
55
|
-
export declare function useDraggableHandle<T extends Element, D = any>(options?: DraggableOptions<T, D>): HandleProps<T>;
|
package/dist/esm/utils/dnd.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
import { useCallback, useRef } from 'react';
|
|
2
|
-
import { useSync } from './hooks';
|
|
3
1
|
import { PointerSensor, useSensor, useSensors } from '@dnd-kit/core';
|
|
4
2
|
import { arrayMove } from '@dnd-kit/sortable';
|
|
5
|
-
import { useTheme } from '../components/theme';
|
|
6
3
|
/**
|
|
7
4
|
* 默认提供给@dnd-kit的sensors属性
|
|
8
5
|
*/
|
|
@@ -29,120 +26,3 @@ export function onDndDragEnd(e, prevState, primaryKey = 'id') {
|
|
|
29
26
|
const newIndex = prevState.findIndex(v => v[primaryKey] === over.id);
|
|
30
27
|
return arrayMove(prevState, oldIndex, newIndex);
|
|
31
28
|
}
|
|
32
|
-
export function useDraggableHandle(options = {}) {
|
|
33
|
-
const { zoom } = useTheme();
|
|
34
|
-
options.zoom ||= zoom;
|
|
35
|
-
const syncOptions = useSync(options);
|
|
36
|
-
const preventDefaultCallback = useRef(void 0);
|
|
37
|
-
const onTouchStart = useCallback(() => {
|
|
38
|
-
if (syncOptions.current.disabled || !syncOptions.current.disableNativeTouchMove) {
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
addEventListener('touchmove', preventDefaultCallback.current = e => {
|
|
42
|
-
e.cancelable && e.preventDefault();
|
|
43
|
-
}, { passive: false });
|
|
44
|
-
}, []);
|
|
45
|
-
const startTime = useRef(0);
|
|
46
|
-
const startPosition = useRef([0, 0]);
|
|
47
|
-
const delay = useRef(void 0);
|
|
48
|
-
const data = useRef(void 0);
|
|
49
|
-
const onPointerDown = useCallback((e) => {
|
|
50
|
-
if (syncOptions.current.disabled) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
isDragged.current = false;
|
|
54
|
-
const dragStart = () => {
|
|
55
|
-
startTime.current = Date.now();
|
|
56
|
-
startPosition.current = [e.clientX, e.clientY];
|
|
57
|
-
data.current = syncOptions.current.onDragStart?.(e);
|
|
58
|
-
document.documentElement.style.userSelect = 'none';
|
|
59
|
-
};
|
|
60
|
-
if (syncOptions.current.delay) {
|
|
61
|
-
delay.current = setTimeout(() => {
|
|
62
|
-
delay.current = void 0;
|
|
63
|
-
dragStart();
|
|
64
|
-
}, syncOptions.current.delay);
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
dragStart();
|
|
68
|
-
}
|
|
69
|
-
addEventListener('pointermove', onPointerMove);
|
|
70
|
-
addEventListener('pointerup', onPointerUp);
|
|
71
|
-
addEventListener('pointercancel', onPointerCancel);
|
|
72
|
-
}, []);
|
|
73
|
-
const buildDragInfo = ({ clientX, clientY }) => {
|
|
74
|
-
const [startX, startY] = startPosition.current;
|
|
75
|
-
const deltaX = (clientX - startX) / (syncOptions.current.zoom);
|
|
76
|
-
const deltaY = (clientY - startY) / (syncOptions.current.zoom);
|
|
77
|
-
return {
|
|
78
|
-
startX, startY,
|
|
79
|
-
currentX: clientX, currentY: clientY,
|
|
80
|
-
deltaX, deltaY,
|
|
81
|
-
startData: data.current
|
|
82
|
-
};
|
|
83
|
-
};
|
|
84
|
-
const onPointerMove = (e) => {
|
|
85
|
-
e.preventDefault();
|
|
86
|
-
const dragInfo = buildDragInfo(e);
|
|
87
|
-
const absDeltaX = Math.abs(dragInfo.deltaX);
|
|
88
|
-
const absDeltaY = Math.abs(dragInfo.deltaY);
|
|
89
|
-
if (delay.current) {
|
|
90
|
-
// 延迟尚未结束,但偏移量过大,取消拖拽
|
|
91
|
-
(absDeltaX > 5 || absDeltaY > 5) && onPointerCancel(e);
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
const distance = syncOptions.current.distance || 0;
|
|
95
|
-
if (absDeltaX < distance && absDeltaY < distance) {
|
|
96
|
-
// 拖拽距离未达到起步距离
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
isDragged.current = true;
|
|
100
|
-
syncOptions.current.onDrag?.(dragInfo, e);
|
|
101
|
-
};
|
|
102
|
-
const removeListener = () => {
|
|
103
|
-
delay.current && clearTimeout(delay.current);
|
|
104
|
-
delay.current = void 0;
|
|
105
|
-
if (preventDefaultCallback.current) {
|
|
106
|
-
removeEventListener('touchmove', preventDefaultCallback.current);
|
|
107
|
-
preventDefaultCallback.current = void 0;
|
|
108
|
-
}
|
|
109
|
-
document.documentElement.style.userSelect = '';
|
|
110
|
-
removeEventListener('pointermove', onPointerMove);
|
|
111
|
-
removeEventListener('pointerup', onPointerUp);
|
|
112
|
-
removeEventListener('pointercancel', onPointerCancel);
|
|
113
|
-
};
|
|
114
|
-
const buildDragEndInfo = (e) => {
|
|
115
|
-
const dragInfo = buildDragInfo(e);
|
|
116
|
-
const duration = Date.now() - startTime.current;
|
|
117
|
-
return {
|
|
118
|
-
...dragInfo,
|
|
119
|
-
duration,
|
|
120
|
-
speedX: Math.abs(dragInfo.deltaX / duration),
|
|
121
|
-
speedY: Math.abs(dragInfo.deltaY / duration)
|
|
122
|
-
};
|
|
123
|
-
};
|
|
124
|
-
const onPointerUp = (e) => {
|
|
125
|
-
removeListener();
|
|
126
|
-
syncOptions.current.onDragEnd?.(buildDragEndInfo(e));
|
|
127
|
-
};
|
|
128
|
-
const onPointerCancel = (e) => {
|
|
129
|
-
removeListener();
|
|
130
|
-
const callback = syncOptions.current.onDragCancel || syncOptions.current.onDragEnd;
|
|
131
|
-
callback?.(buildDragEndInfo(e));
|
|
132
|
-
};
|
|
133
|
-
const isDragged = useRef(false);
|
|
134
|
-
const onClick = useCallback((e) => {
|
|
135
|
-
if (isDragged.current) {
|
|
136
|
-
// 已经触发了拖拽,避免触发点击事件
|
|
137
|
-
e.preventDefault();
|
|
138
|
-
e.stopPropagation();
|
|
139
|
-
}
|
|
140
|
-
else {
|
|
141
|
-
syncOptions.current.onClick?.(e);
|
|
142
|
-
}
|
|
143
|
-
}, []);
|
|
144
|
-
const onDragStart = useCallback((e) => {
|
|
145
|
-
e.preventDefault();
|
|
146
|
-
}, []);
|
|
147
|
-
return { onTouchStart, onPointerDown, onClick, onDragStart };
|
|
148
|
-
}
|