@react-aria/dnd 3.5.4-nightly.4555 → 3.5.4-nightly.4560
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/DragManager.main.js +444 -0
- package/dist/DragManager.main.js.map +1 -0
- package/dist/DragManager.mjs +435 -0
- package/dist/DragManager.module.js +435 -0
- package/dist/DragManager.module.js.map +1 -0
- package/dist/DragPreview.main.js +59 -0
- package/dist/DragPreview.main.js.map +1 -0
- package/dist/DragPreview.mjs +50 -0
- package/dist/DragPreview.module.js +50 -0
- package/dist/DragPreview.module.js.map +1 -0
- package/dist/ListDropTargetDelegate.main.js +119 -0
- package/dist/ListDropTargetDelegate.main.js.map +1 -0
- package/dist/ListDropTargetDelegate.mjs +114 -0
- package/dist/ListDropTargetDelegate.module.js +114 -0
- package/dist/ListDropTargetDelegate.module.js.map +1 -0
- package/dist/ar-AE.mjs +1 -1
- package/dist/bg-BG.mjs +1 -1
- package/dist/constants.main.js +65 -0
- package/dist/constants.main.js.map +1 -0
- package/dist/constants.mjs +53 -0
- package/dist/constants.module.js +53 -0
- package/dist/constants.module.js.map +1 -0
- package/dist/cs-CZ.mjs +1 -1
- package/dist/da-DK.mjs +1 -1
- package/dist/de-DE.mjs +1 -1
- package/dist/el-GR.mjs +1 -1
- package/dist/en-US.mjs +1 -1
- package/dist/es-ES.mjs +1 -1
- package/dist/et-EE.mjs +1 -1
- package/dist/fi-FI.mjs +1 -1
- package/dist/fr-FR.mjs +1 -1
- package/dist/he-IL.mjs +1 -1
- package/dist/hr-HR.mjs +1 -1
- package/dist/hu-HU.mjs +1 -1
- package/dist/import.mjs +12 -2582
- package/dist/intlStrings.main.js +108 -0
- package/dist/intlStrings.main.js.map +1 -0
- package/dist/intlStrings.mjs +110 -0
- package/dist/intlStrings.module.js +110 -0
- package/dist/intlStrings.module.js.map +1 -0
- package/dist/it-IT.mjs +1 -1
- package/dist/ja-JP.mjs +1 -1
- package/dist/ko-KR.mjs +1 -1
- package/dist/lt-LT.mjs +1 -1
- package/dist/lv-LV.mjs +1 -1
- package/dist/main.js +27 -2597
- package/dist/main.js.map +1 -1
- package/dist/module.js +12 -2582
- package/dist/module.js.map +1 -1
- package/dist/nb-NO.mjs +1 -1
- package/dist/nl-NL.mjs +1 -1
- package/dist/pl-PL.mjs +1 -1
- package/dist/pt-BR.mjs +1 -1
- package/dist/pt-PT.mjs +1 -1
- package/dist/ro-RO.mjs +1 -1
- package/dist/ru-RU.mjs +1 -1
- package/dist/sk-SK.mjs +1 -1
- package/dist/sl-SI.mjs +1 -1
- package/dist/sr-SP.mjs +1 -1
- package/dist/sv-SE.mjs +1 -1
- package/dist/tr-TR.mjs +1 -1
- package/dist/uk-UA.mjs +1 -1
- package/dist/useAutoScroll.main.js +89 -0
- package/dist/useAutoScroll.main.js.map +1 -0
- package/dist/useAutoScroll.mjs +84 -0
- package/dist/useAutoScroll.module.js +84 -0
- package/dist/useAutoScroll.module.js.map +1 -0
- package/dist/useClipboard.main.js +107 -0
- package/dist/useClipboard.main.js.map +1 -0
- package/dist/useClipboard.mjs +102 -0
- package/dist/useClipboard.module.js +102 -0
- package/dist/useClipboard.module.js.map +1 -0
- package/dist/useDrag.main.js +279 -0
- package/dist/useDrag.main.js.map +1 -0
- package/dist/useDrag.mjs +274 -0
- package/dist/useDrag.module.js +274 -0
- package/dist/useDrag.module.js.map +1 -0
- package/dist/useDraggableCollection.main.js +27 -0
- package/dist/useDraggableCollection.main.js.map +1 -0
- package/dist/useDraggableCollection.mjs +22 -0
- package/dist/useDraggableCollection.module.js +22 -0
- package/dist/useDraggableCollection.module.js.map +1 -0
- package/dist/useDraggableItem.main.js +128 -0
- package/dist/useDraggableItem.main.js.map +1 -0
- package/dist/useDraggableItem.mjs +123 -0
- package/dist/useDraggableItem.module.js +123 -0
- package/dist/useDraggableItem.module.js.map +1 -0
- package/dist/useDrop.main.js +299 -0
- package/dist/useDrop.main.js.map +1 -0
- package/dist/useDrop.mjs +294 -0
- package/dist/useDrop.module.js +294 -0
- package/dist/useDrop.module.js.map +1 -0
- package/dist/useDropIndicator.main.js +93 -0
- package/dist/useDropIndicator.main.js.map +1 -0
- package/dist/useDropIndicator.mjs +88 -0
- package/dist/useDropIndicator.module.js +88 -0
- package/dist/useDropIndicator.module.js.map +1 -0
- package/dist/useDroppableCollection.main.js +583 -0
- package/dist/useDroppableCollection.main.js.map +1 -0
- package/dist/useDroppableCollection.mjs +578 -0
- package/dist/useDroppableCollection.module.js +578 -0
- package/dist/useDroppableCollection.module.js.map +1 -0
- package/dist/useDroppableItem.main.js +79 -0
- package/dist/useDroppableItem.main.js.map +1 -0
- package/dist/useDroppableItem.mjs +74 -0
- package/dist/useDroppableItem.module.js +74 -0
- package/dist/useDroppableItem.module.js.map +1 -0
- package/dist/useVirtualDrop.main.js +56 -0
- package/dist/useVirtualDrop.main.js.map +1 -0
- package/dist/useVirtualDrop.mjs +51 -0
- package/dist/useVirtualDrop.module.js +51 -0
- package/dist/useVirtualDrop.module.js.map +1 -0
- package/dist/utils.main.js +283 -0
- package/dist/utils.main.js.map +1 -0
- package/dist/utils.mjs +255 -0
- package/dist/utils.module.js +255 -0
- package/dist/utils.module.js.map +1 -0
- package/dist/zh-CN.mjs +1 -1
- package/dist/zh-TW.mjs +1 -1
- package/package.json +11 -11
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
var $8QIlU$reactariautils = require("@react-aria/utils");
|
|
2
|
+
var $8QIlU$react = require("react");
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
function $parcel$export(e, n, v, s) {
|
|
6
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
$parcel$export(module.exports, "useAutoScroll", () => $12cc069a1c69155b$export$6323452ca4533ed8);
|
|
10
|
+
/*
|
|
11
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
12
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
13
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
14
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
15
|
+
*
|
|
16
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
17
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
18
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
19
|
+
* governing permissions and limitations under the License.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
const $12cc069a1c69155b$var$AUTOSCROLL_AREA_SIZE = 20;
|
|
23
|
+
function $12cc069a1c69155b$export$6323452ca4533ed8(ref) {
|
|
24
|
+
let scrollableRef = (0, $8QIlU$react.useRef)(null);
|
|
25
|
+
let scrollableX = (0, $8QIlU$react.useRef)(true);
|
|
26
|
+
let scrollableY = (0, $8QIlU$react.useRef)(true);
|
|
27
|
+
(0, $8QIlU$react.useEffect)(()=>{
|
|
28
|
+
if (ref.current) {
|
|
29
|
+
scrollableRef.current = (0, $8QIlU$reactariautils.isScrollable)(ref.current) ? ref.current : (0, $8QIlU$reactariautils.getScrollParent)(ref.current);
|
|
30
|
+
let style = window.getComputedStyle(scrollableRef.current);
|
|
31
|
+
scrollableX.current = /(auto|scroll)/.test(style.overflowX);
|
|
32
|
+
scrollableY.current = /(auto|scroll)/.test(style.overflowY);
|
|
33
|
+
}
|
|
34
|
+
}, [
|
|
35
|
+
ref
|
|
36
|
+
]);
|
|
37
|
+
let state = (0, $8QIlU$react.useRef)({
|
|
38
|
+
timer: null,
|
|
39
|
+
dx: 0,
|
|
40
|
+
dy: 0
|
|
41
|
+
}).current;
|
|
42
|
+
(0, $8QIlU$react.useEffect)(()=>{
|
|
43
|
+
return ()=>{
|
|
44
|
+
if (state.timer) {
|
|
45
|
+
cancelAnimationFrame(state.timer);
|
|
46
|
+
state.timer = null;
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
// state will become a new object, so it's ok to use in the dependency array for unmount
|
|
50
|
+
}, [
|
|
51
|
+
state
|
|
52
|
+
]);
|
|
53
|
+
let scroll = (0, $8QIlU$react.useCallback)(()=>{
|
|
54
|
+
if (scrollableX.current) scrollableRef.current.scrollLeft += state.dx;
|
|
55
|
+
if (scrollableY.current) scrollableRef.current.scrollTop += state.dy;
|
|
56
|
+
if (state.timer) state.timer = requestAnimationFrame(scroll);
|
|
57
|
+
}, [
|
|
58
|
+
scrollableRef,
|
|
59
|
+
state
|
|
60
|
+
]);
|
|
61
|
+
return {
|
|
62
|
+
move (x, y) {
|
|
63
|
+
// Most browsers auto scroll natively, but WebKit on macOS does not (iOS does 🤷♂️).
|
|
64
|
+
// https://bugs.webkit.org/show_bug.cgi?id=222636
|
|
65
|
+
if (!(0, $8QIlU$reactariautils.isWebKit)() || (0, $8QIlU$reactariautils.isIOS)() || !scrollableRef.current) return;
|
|
66
|
+
let box = scrollableRef.current.getBoundingClientRect();
|
|
67
|
+
let left = $12cc069a1c69155b$var$AUTOSCROLL_AREA_SIZE;
|
|
68
|
+
let top = $12cc069a1c69155b$var$AUTOSCROLL_AREA_SIZE;
|
|
69
|
+
let bottom = box.height - $12cc069a1c69155b$var$AUTOSCROLL_AREA_SIZE;
|
|
70
|
+
let right = box.width - $12cc069a1c69155b$var$AUTOSCROLL_AREA_SIZE;
|
|
71
|
+
if (x < left || x > right || y < top || y > bottom) {
|
|
72
|
+
if (x < left) state.dx = x - left;
|
|
73
|
+
else if (x > right) state.dx = x - right;
|
|
74
|
+
if (y < top) state.dy = y - top;
|
|
75
|
+
else if (y > bottom) state.dy = y - bottom;
|
|
76
|
+
if (!state.timer) state.timer = requestAnimationFrame(scroll);
|
|
77
|
+
} else this.stop();
|
|
78
|
+
},
|
|
79
|
+
stop () {
|
|
80
|
+
if (state.timer) {
|
|
81
|
+
cancelAnimationFrame(state.timer);
|
|
82
|
+
state.timer = null;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|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B,OAAO;QACL,MAAK,CAAC,EAAE,CAAC;YACP,qFAAqF;YACrF,iDAAiD;YACjD,IAAI,CAAC,CAAA,GAAA,8BAAO,OAAO,CAAA,GAAA,2BAAI,OAAO,CAAC,cAAc,OAAO,EAClD;YAGF,IAAI,MAAM,cAAc,OAAO,CAAC,qBAAqB;YACrD,IAAI,OAAO;YACX,IAAI,MAAM;YACV,IAAI,SAAS,IAAI,MAAM,GAAG;YAC1B,IAAI,QAAQ,IAAI,KAAK,GAAG;YACxB,IAAI,IAAI,QAAQ,IAAI,SAAS,IAAI,OAAO,IAAI,QAAQ;gBAClD,IAAI,IAAI,MACN,MAAM,EAAE,GAAG,IAAI;qBACV,IAAI,IAAI,OACb,MAAM,EAAE,GAAG,IAAI;gBAEjB,IAAI,IAAI,KACN,MAAM,EAAE,GAAG,IAAI;qBACV,IAAI,IAAI,QACb,MAAM,EAAE,GAAG,IAAI;gBAGjB,IAAI,CAAC,MAAM,KAAK,EACd,MAAM,KAAK,GAAG,sBAAsB;YAExC,OACE,IAAI,CAAC,IAAI;QAEb;QACA;YACE,IAAI,MAAM,KAAK,EAAE;gBACf,qBAAqB,MAAM,KAAK;gBAChC,MAAM,KAAK,GAAG;YAChB;QACF;IACF;AACF","sources":["packages/@react-aria/dnd/src/useAutoScroll.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {getScrollParent, isIOS, isScrollable, isWebKit} from '@react-aria/utils';\nimport {RefObject, useCallback, useEffect, useRef} from 'react';\n\nconst AUTOSCROLL_AREA_SIZE = 20;\n\nexport function useAutoScroll(ref: RefObject<Element>) {\n let scrollableRef = useRef<Element>(null);\n let scrollableX = useRef(true);\n let scrollableY = useRef(true);\n useEffect(() => {\n if (ref.current) {\n scrollableRef.current = isScrollable(ref.current) ? ref.current : getScrollParent(ref.current);\n let style = window.getComputedStyle(scrollableRef.current);\n scrollableX.current = /(auto|scroll)/.test(style.overflowX);\n scrollableY.current = /(auto|scroll)/.test(style.overflowY);\n }\n }, [ref]);\n\n let state = useRef({\n timer: null,\n dx: 0,\n dy: 0\n }).current;\n\n useEffect(() => {\n return () => {\n if (state.timer) {\n cancelAnimationFrame(state.timer);\n state.timer = null;\n }\n };\n // state will become a new object, so it's ok to use in the dependency array for unmount\n }, [state]);\n\n let scroll = useCallback(() => {\n if (scrollableX.current) {\n scrollableRef.current.scrollLeft += state.dx;\n }\n if (scrollableY.current) {\n scrollableRef.current.scrollTop += state.dy;\n }\n\n if (state.timer) {\n state.timer = requestAnimationFrame(scroll);\n }\n }, [scrollableRef, state]);\n\n return {\n move(x, y) {\n // Most browsers auto scroll natively, but WebKit on macOS does not (iOS does 🤷♂️).\n // https://bugs.webkit.org/show_bug.cgi?id=222636\n if (!isWebKit() || isIOS() || !scrollableRef.current) {\n return;\n }\n\n let box = scrollableRef.current.getBoundingClientRect();\n let left = AUTOSCROLL_AREA_SIZE;\n let top = AUTOSCROLL_AREA_SIZE;\n let bottom = box.height - AUTOSCROLL_AREA_SIZE;\n let right = box.width - AUTOSCROLL_AREA_SIZE;\n if (x < left || x > right || y < top || y > bottom) {\n if (x < left) {\n state.dx = x - left;\n } else if (x > right) {\n state.dx = x - right;\n }\n if (y < top) {\n state.dy = y - top;\n } else if (y > bottom) {\n state.dy = y - bottom;\n }\n\n if (!state.timer) {\n state.timer = requestAnimationFrame(scroll);\n }\n } else {\n this.stop();\n }\n },\n stop() {\n if (state.timer) {\n cancelAnimationFrame(state.timer);\n state.timer = null;\n }\n }\n };\n}\n"],"names":[],"version":3,"file":"useAutoScroll.main.js.map"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import {isScrollable as $2wNms$isScrollable, getScrollParent as $2wNms$getScrollParent, isWebKit as $2wNms$isWebKit, isIOS as $2wNms$isIOS} from "@react-aria/utils";
|
|
2
|
+
import {useRef as $2wNms$useRef, useEffect as $2wNms$useEffect, useCallback as $2wNms$useCallback} from "react";
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
6
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
8
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
11
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
12
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
13
|
+
* governing permissions and limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
const $80d9daea3067eff3$var$AUTOSCROLL_AREA_SIZE = 20;
|
|
17
|
+
function $80d9daea3067eff3$export$6323452ca4533ed8(ref) {
|
|
18
|
+
let scrollableRef = (0, $2wNms$useRef)(null);
|
|
19
|
+
let scrollableX = (0, $2wNms$useRef)(true);
|
|
20
|
+
let scrollableY = (0, $2wNms$useRef)(true);
|
|
21
|
+
(0, $2wNms$useEffect)(()=>{
|
|
22
|
+
if (ref.current) {
|
|
23
|
+
scrollableRef.current = (0, $2wNms$isScrollable)(ref.current) ? ref.current : (0, $2wNms$getScrollParent)(ref.current);
|
|
24
|
+
let style = window.getComputedStyle(scrollableRef.current);
|
|
25
|
+
scrollableX.current = /(auto|scroll)/.test(style.overflowX);
|
|
26
|
+
scrollableY.current = /(auto|scroll)/.test(style.overflowY);
|
|
27
|
+
}
|
|
28
|
+
}, [
|
|
29
|
+
ref
|
|
30
|
+
]);
|
|
31
|
+
let state = (0, $2wNms$useRef)({
|
|
32
|
+
timer: null,
|
|
33
|
+
dx: 0,
|
|
34
|
+
dy: 0
|
|
35
|
+
}).current;
|
|
36
|
+
(0, $2wNms$useEffect)(()=>{
|
|
37
|
+
return ()=>{
|
|
38
|
+
if (state.timer) {
|
|
39
|
+
cancelAnimationFrame(state.timer);
|
|
40
|
+
state.timer = null;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
// state will become a new object, so it's ok to use in the dependency array for unmount
|
|
44
|
+
}, [
|
|
45
|
+
state
|
|
46
|
+
]);
|
|
47
|
+
let scroll = (0, $2wNms$useCallback)(()=>{
|
|
48
|
+
if (scrollableX.current) scrollableRef.current.scrollLeft += state.dx;
|
|
49
|
+
if (scrollableY.current) scrollableRef.current.scrollTop += state.dy;
|
|
50
|
+
if (state.timer) state.timer = requestAnimationFrame(scroll);
|
|
51
|
+
}, [
|
|
52
|
+
scrollableRef,
|
|
53
|
+
state
|
|
54
|
+
]);
|
|
55
|
+
return {
|
|
56
|
+
move (x, y) {
|
|
57
|
+
// Most browsers auto scroll natively, but WebKit on macOS does not (iOS does 🤷♂️).
|
|
58
|
+
// https://bugs.webkit.org/show_bug.cgi?id=222636
|
|
59
|
+
if (!(0, $2wNms$isWebKit)() || (0, $2wNms$isIOS)() || !scrollableRef.current) return;
|
|
60
|
+
let box = scrollableRef.current.getBoundingClientRect();
|
|
61
|
+
let left = $80d9daea3067eff3$var$AUTOSCROLL_AREA_SIZE;
|
|
62
|
+
let top = $80d9daea3067eff3$var$AUTOSCROLL_AREA_SIZE;
|
|
63
|
+
let bottom = box.height - $80d9daea3067eff3$var$AUTOSCROLL_AREA_SIZE;
|
|
64
|
+
let right = box.width - $80d9daea3067eff3$var$AUTOSCROLL_AREA_SIZE;
|
|
65
|
+
if (x < left || x > right || y < top || y > bottom) {
|
|
66
|
+
if (x < left) state.dx = x - left;
|
|
67
|
+
else if (x > right) state.dx = x - right;
|
|
68
|
+
if (y < top) state.dy = y - top;
|
|
69
|
+
else if (y > bottom) state.dy = y - bottom;
|
|
70
|
+
if (!state.timer) state.timer = requestAnimationFrame(scroll);
|
|
71
|
+
} else this.stop();
|
|
72
|
+
},
|
|
73
|
+
stop () {
|
|
74
|
+
if (state.timer) {
|
|
75
|
+
cancelAnimationFrame(state.timer);
|
|
76
|
+
state.timer = null;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
export {$80d9daea3067eff3$export$6323452ca4533ed8 as useAutoScroll};
|
|
84
|
+
//# sourceMappingURL=useAutoScroll.mjs.map
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import {isScrollable as $2wNms$isScrollable, getScrollParent as $2wNms$getScrollParent, isWebKit as $2wNms$isWebKit, isIOS as $2wNms$isIOS} from "@react-aria/utils";
|
|
2
|
+
import {useRef as $2wNms$useRef, useEffect as $2wNms$useEffect, useCallback as $2wNms$useCallback} from "react";
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
6
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
8
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
11
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
12
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
13
|
+
* governing permissions and limitations under the License.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
const $80d9daea3067eff3$var$AUTOSCROLL_AREA_SIZE = 20;
|
|
17
|
+
function $80d9daea3067eff3$export$6323452ca4533ed8(ref) {
|
|
18
|
+
let scrollableRef = (0, $2wNms$useRef)(null);
|
|
19
|
+
let scrollableX = (0, $2wNms$useRef)(true);
|
|
20
|
+
let scrollableY = (0, $2wNms$useRef)(true);
|
|
21
|
+
(0, $2wNms$useEffect)(()=>{
|
|
22
|
+
if (ref.current) {
|
|
23
|
+
scrollableRef.current = (0, $2wNms$isScrollable)(ref.current) ? ref.current : (0, $2wNms$getScrollParent)(ref.current);
|
|
24
|
+
let style = window.getComputedStyle(scrollableRef.current);
|
|
25
|
+
scrollableX.current = /(auto|scroll)/.test(style.overflowX);
|
|
26
|
+
scrollableY.current = /(auto|scroll)/.test(style.overflowY);
|
|
27
|
+
}
|
|
28
|
+
}, [
|
|
29
|
+
ref
|
|
30
|
+
]);
|
|
31
|
+
let state = (0, $2wNms$useRef)({
|
|
32
|
+
timer: null,
|
|
33
|
+
dx: 0,
|
|
34
|
+
dy: 0
|
|
35
|
+
}).current;
|
|
36
|
+
(0, $2wNms$useEffect)(()=>{
|
|
37
|
+
return ()=>{
|
|
38
|
+
if (state.timer) {
|
|
39
|
+
cancelAnimationFrame(state.timer);
|
|
40
|
+
state.timer = null;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
// state will become a new object, so it's ok to use in the dependency array for unmount
|
|
44
|
+
}, [
|
|
45
|
+
state
|
|
46
|
+
]);
|
|
47
|
+
let scroll = (0, $2wNms$useCallback)(()=>{
|
|
48
|
+
if (scrollableX.current) scrollableRef.current.scrollLeft += state.dx;
|
|
49
|
+
if (scrollableY.current) scrollableRef.current.scrollTop += state.dy;
|
|
50
|
+
if (state.timer) state.timer = requestAnimationFrame(scroll);
|
|
51
|
+
}, [
|
|
52
|
+
scrollableRef,
|
|
53
|
+
state
|
|
54
|
+
]);
|
|
55
|
+
return {
|
|
56
|
+
move (x, y) {
|
|
57
|
+
// Most browsers auto scroll natively, but WebKit on macOS does not (iOS does 🤷♂️).
|
|
58
|
+
// https://bugs.webkit.org/show_bug.cgi?id=222636
|
|
59
|
+
if (!(0, $2wNms$isWebKit)() || (0, $2wNms$isIOS)() || !scrollableRef.current) return;
|
|
60
|
+
let box = scrollableRef.current.getBoundingClientRect();
|
|
61
|
+
let left = $80d9daea3067eff3$var$AUTOSCROLL_AREA_SIZE;
|
|
62
|
+
let top = $80d9daea3067eff3$var$AUTOSCROLL_AREA_SIZE;
|
|
63
|
+
let bottom = box.height - $80d9daea3067eff3$var$AUTOSCROLL_AREA_SIZE;
|
|
64
|
+
let right = box.width - $80d9daea3067eff3$var$AUTOSCROLL_AREA_SIZE;
|
|
65
|
+
if (x < left || x > right || y < top || y > bottom) {
|
|
66
|
+
if (x < left) state.dx = x - left;
|
|
67
|
+
else if (x > right) state.dx = x - right;
|
|
68
|
+
if (y < top) state.dy = y - top;
|
|
69
|
+
else if (y > bottom) state.dy = y - bottom;
|
|
70
|
+
if (!state.timer) state.timer = requestAnimationFrame(scroll);
|
|
71
|
+
} else this.stop();
|
|
72
|
+
},
|
|
73
|
+
stop () {
|
|
74
|
+
if (state.timer) {
|
|
75
|
+
cancelAnimationFrame(state.timer);
|
|
76
|
+
state.timer = null;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
export {$80d9daea3067eff3$export$6323452ca4533ed8 as useAutoScroll};
|
|
84
|
+
//# sourceMappingURL=useAutoScroll.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;AAAA;;;;;;;;;;CAUC;;AAKD,MAAM,6CAAuB;AAEtB,SAAS,0CAAc,GAAuB;IACnD,IAAI,gBAAgB,CAAA,GAAA,aAAK,EAAW;IACpC,IAAI,cAAc,CAAA,GAAA,aAAK,EAAE;IACzB,IAAI,cAAc,CAAA,GAAA,aAAK,EAAE;IACzB,CAAA,GAAA,gBAAQ,EAAE;QACR,IAAI,IAAI,OAAO,EAAE;YACf,cAAc,OAAO,GAAG,CAAA,GAAA,mBAAW,EAAE,IAAI,OAAO,IAAI,IAAI,OAAO,GAAG,CAAA,GAAA,sBAAc,EAAE,IAAI,OAAO;YAC7F,IAAI,QAAQ,OAAO,gBAAgB,CAAC,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AI,QACb,MAAM,EAAE,GAAG,IAAI;gBAGjB,IAAI,CAAC,MAAM,KAAK,EACd,MAAM,KAAK,GAAG,sBAAsB;YAExC,OACE,IAAI,CAAC,IAAI;QAEb;QACA;YACE,IAAI,MAAM,KAAK,EAAE;gBACf,qBAAqB,MAAM,KAAK;gBAChC,MAAM,KAAK,GAAG;YAChB;QACF;IACF;AACF","sources":["packages/@react-aria/dnd/src/useAutoScroll.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {getScrollParent, isIOS, isScrollable, isWebKit} from '@react-aria/utils';\nimport {RefObject, useCallback, useEffect, useRef} from 'react';\n\nconst AUTOSCROLL_AREA_SIZE = 20;\n\nexport function useAutoScroll(ref: RefObject<Element>) {\n let scrollableRef = useRef<Element>(null);\n let scrollableX = useRef(true);\n let scrollableY = useRef(true);\n useEffect(() => {\n if (ref.current) {\n scrollableRef.current = isScrollable(ref.current) ? ref.current : getScrollParent(ref.current);\n let style = window.getComputedStyle(scrollableRef.current);\n scrollableX.current = /(auto|scroll)/.test(style.overflowX);\n scrollableY.current = /(auto|scroll)/.test(style.overflowY);\n }\n }, [ref]);\n\n let state = useRef({\n timer: null,\n dx: 0,\n dy: 0\n }).current;\n\n useEffect(() => {\n return () => {\n if (state.timer) {\n cancelAnimationFrame(state.timer);\n state.timer = null;\n }\n };\n // state will become a new object, so it's ok to use in the dependency array for unmount\n }, [state]);\n\n let scroll = useCallback(() => {\n if (scrollableX.current) {\n scrollableRef.current.scrollLeft += state.dx;\n }\n if (scrollableY.current) {\n scrollableRef.current.scrollTop += state.dy;\n }\n\n if (state.timer) {\n state.timer = requestAnimationFrame(scroll);\n }\n }, [scrollableRef, state]);\n\n return {\n move(x, y) {\n // Most browsers auto scroll natively, but WebKit on macOS does not (iOS does 🤷♂️).\n // https://bugs.webkit.org/show_bug.cgi?id=222636\n if (!isWebKit() || isIOS() || !scrollableRef.current) {\n return;\n }\n\n let box = scrollableRef.current.getBoundingClientRect();\n let left = AUTOSCROLL_AREA_SIZE;\n let top = AUTOSCROLL_AREA_SIZE;\n let bottom = box.height - AUTOSCROLL_AREA_SIZE;\n let right = box.width - AUTOSCROLL_AREA_SIZE;\n if (x < left || x > right || y < top || y > bottom) {\n if (x < left) {\n state.dx = x - left;\n } else if (x > right) {\n state.dx = x - right;\n }\n if (y < top) {\n state.dy = y - top;\n } else if (y > bottom) {\n state.dy = y - bottom;\n }\n\n if (!state.timer) {\n state.timer = requestAnimationFrame(scroll);\n }\n } else {\n this.stop();\n }\n },\n stop() {\n if (state.timer) {\n cancelAnimationFrame(state.timer);\n state.timer = null;\n }\n }\n };\n}\n"],"names":[],"version":3,"file":"useAutoScroll.module.js.map"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
var $4620ae0dc40f0031$exports = require("./utils.main.js");
|
|
2
|
+
var $gAFdr$reactariautils = require("@react-aria/utils");
|
|
3
|
+
var $gAFdr$react = require("react");
|
|
4
|
+
var $gAFdr$reactariainteractions = require("@react-aria/interactions");
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
function $parcel$export(e, n, v, s) {
|
|
8
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
$parcel$export(module.exports, "useClipboard", () => $74f3dedaa4d234b4$export$2314ca2a3e892862);
|
|
12
|
+
/*
|
|
13
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
14
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
15
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
16
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
17
|
+
*
|
|
18
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
19
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
20
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
21
|
+
* governing permissions and limitations under the License.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
const $74f3dedaa4d234b4$var$globalEvents = new Map();
|
|
27
|
+
function $74f3dedaa4d234b4$var$addGlobalEventListener(event, fn) {
|
|
28
|
+
let eventData = $74f3dedaa4d234b4$var$globalEvents.get(event);
|
|
29
|
+
if (!eventData) {
|
|
30
|
+
let handlers = new Set();
|
|
31
|
+
let listener = (e)=>{
|
|
32
|
+
for (let handler of handlers)handler(e);
|
|
33
|
+
};
|
|
34
|
+
eventData = {
|
|
35
|
+
listener: listener,
|
|
36
|
+
handlers: handlers
|
|
37
|
+
};
|
|
38
|
+
$74f3dedaa4d234b4$var$globalEvents.set(event, eventData);
|
|
39
|
+
document.addEventListener(event, listener);
|
|
40
|
+
}
|
|
41
|
+
eventData.handlers.add(fn);
|
|
42
|
+
return ()=>{
|
|
43
|
+
eventData.handlers.delete(fn);
|
|
44
|
+
if (eventData.handlers.size === 0) {
|
|
45
|
+
document.removeEventListener(event, eventData.listener);
|
|
46
|
+
$74f3dedaa4d234b4$var$globalEvents.delete(event);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function $74f3dedaa4d234b4$export$2314ca2a3e892862(options) {
|
|
51
|
+
let { isDisabled: isDisabled } = options;
|
|
52
|
+
let isFocusedRef = (0, $gAFdr$react.useRef)(false);
|
|
53
|
+
let { focusProps: focusProps } = (0, $gAFdr$reactariainteractions.useFocus)({
|
|
54
|
+
onFocusChange: (isFocused)=>{
|
|
55
|
+
isFocusedRef.current = isFocused;
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
let onBeforeCopy = (0, $gAFdr$reactariautils.useEffectEvent)((e)=>{
|
|
59
|
+
// Enable the "Copy" menu item in Safari if this element is focused and copying is supported.
|
|
60
|
+
if (isFocusedRef.current && options.getItems) e.preventDefault();
|
|
61
|
+
});
|
|
62
|
+
let onCopy = (0, $gAFdr$reactariautils.useEffectEvent)((e)=>{
|
|
63
|
+
var _options_onCopy;
|
|
64
|
+
if (!isFocusedRef.current || !options.getItems) return;
|
|
65
|
+
e.preventDefault();
|
|
66
|
+
(0, $4620ae0dc40f0031$exports.writeToDataTransfer)(e.clipboardData, options.getItems());
|
|
67
|
+
(_options_onCopy = options.onCopy) === null || _options_onCopy === void 0 ? void 0 : _options_onCopy.call(options);
|
|
68
|
+
});
|
|
69
|
+
let onBeforeCut = (0, $gAFdr$reactariautils.useEffectEvent)((e)=>{
|
|
70
|
+
if (isFocusedRef.current && options.onCut && options.getItems) e.preventDefault();
|
|
71
|
+
});
|
|
72
|
+
let onCut = (0, $gAFdr$reactariautils.useEffectEvent)((e)=>{
|
|
73
|
+
if (!isFocusedRef.current || !options.onCut || !options.getItems) return;
|
|
74
|
+
e.preventDefault();
|
|
75
|
+
(0, $4620ae0dc40f0031$exports.writeToDataTransfer)(e.clipboardData, options.getItems());
|
|
76
|
+
options.onCut();
|
|
77
|
+
});
|
|
78
|
+
let onBeforePaste = (0, $gAFdr$reactariautils.useEffectEvent)((e)=>{
|
|
79
|
+
// Unfortunately, e.clipboardData.types is not available in this event so we always
|
|
80
|
+
// have to enable the Paste menu item even if the type of data is unsupported.
|
|
81
|
+
if (isFocusedRef.current && options.onPaste) e.preventDefault();
|
|
82
|
+
});
|
|
83
|
+
let onPaste = (0, $gAFdr$reactariautils.useEffectEvent)((e)=>{
|
|
84
|
+
if (!isFocusedRef.current || !options.onPaste) return;
|
|
85
|
+
e.preventDefault();
|
|
86
|
+
let items = (0, $4620ae0dc40f0031$exports.readFromDataTransfer)(e.clipboardData);
|
|
87
|
+
options.onPaste(items);
|
|
88
|
+
});
|
|
89
|
+
(0, $gAFdr$react.useEffect)(()=>{
|
|
90
|
+
if (isDisabled) return;
|
|
91
|
+
return (0, $gAFdr$reactariautils.chain)($74f3dedaa4d234b4$var$addGlobalEventListener("beforecopy", onBeforeCopy), $74f3dedaa4d234b4$var$addGlobalEventListener("copy", onCopy), $74f3dedaa4d234b4$var$addGlobalEventListener("beforecut", onBeforeCut), $74f3dedaa4d234b4$var$addGlobalEventListener("cut", onCut), $74f3dedaa4d234b4$var$addGlobalEventListener("beforepaste", onBeforePaste), $74f3dedaa4d234b4$var$addGlobalEventListener("paste", onPaste));
|
|
92
|
+
}, [
|
|
93
|
+
isDisabled,
|
|
94
|
+
onBeforeCopy,
|
|
95
|
+
onCopy,
|
|
96
|
+
onBeforeCut,
|
|
97
|
+
onCut,
|
|
98
|
+
onBeforePaste,
|
|
99
|
+
onPaste
|
|
100
|
+
]);
|
|
101
|
+
return {
|
|
102
|
+
clipboardProps: focusProps
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
//# sourceMappingURL=useClipboard.main.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;AA0BD,MAAM,qCAAe,IAAI;AACzB,SAAS,6CAAuB,KAAK,EAAE,EAAE;IACvC,IAAI,YAAY,mCAAa,GAAG,CAAC;IACjC,IAAI,CAAC,WAAW;QACd,IAAI,WAAW,IAAI;QACnB,IAAI,WAAW,CAAC;YACd,KAAK,IAAI,WAAW,SAClB,QAAQ;QAEZ;QAEA,YAAY;sBAAC;sBAAU;QAAQ;QAC/B,mCAAa,GAAG,CAAC,OAAO;QAExB,SAAS,gBAAgB,CAAC,OAAO;IACnC;IAEA,UAAU,QAAQ,CAAC,GAAG,CAAC;IACvB,OAAO;QACL,UAAU,QAAQ,CAAC,MAAM,CAAC;QAC1B,IAAI,UAAU,QAAQ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AO,EACzC,EAAE,cAAc;IAEpB;IAEA,IAAI,UAAU,CAAA,GAAA,oCAAa,EAAE,CAAC;QAC5B,IAAI,CAAC,aAAa,OAAO,IAAI,CAAC,QAAQ,OAAO,EAC3C;QAGF,EAAE,cAAc;QAChB,IAAI,QAAQ,CAAA,GAAA,8CAAmB,EAAE,EAAE,aAAa;QAChD,QAAQ,OAAO,CAAC;IAClB;IAEA,CAAA,GAAA,sBAAQ,EAAE;QACR,IAAI,YACF;QAEF,OAAO,CAAA,GAAA,2BAAI,EACT,6CAAuB,cAAc,eACrC,6CAAuB,QAAQ,SAC/B,6CAAuB,aAAa,cACpC,6CAAuB,OAAO,QAC9B,6CAAuB,eAAe,gBACtC,6CAAuB,SAAS;IAEpC,GAAG;QAAC;QAAY;QAAc;QAAQ;QAAa;QAAO;QAAe;KAAQ;IAEjF,OAAO;QACL,gBAAgB;IAClB;AACF","sources":["packages/@react-aria/dnd/src/useClipboard.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {chain, useEffectEvent} from '@react-aria/utils';\nimport {DOMAttributes, DragItem, DropItem} from '@react-types/shared';\nimport {readFromDataTransfer, writeToDataTransfer} from './utils';\nimport {useEffect, useRef} from 'react';\nimport {useFocus} from '@react-aria/interactions';\n\nexport interface ClipboardProps {\n /** A function that returns the items to copy. */\n getItems?: () => DragItem[],\n /** Handler that is called when the user triggers a copy interaction. */\n onCopy?: () => void,\n /** Handler that is called when the user triggers a cut interaction. */\n onCut?: () => void,\n /** Handler that is called when the user triggers a paste interaction. */\n onPaste?: (items: DropItem[]) => void,\n /** Whether the clipboard is disabled. */\n isDisabled?: boolean\n}\n\nexport interface ClipboardResult {\n /** Props for the element that will handle clipboard events. */\n clipboardProps: DOMAttributes\n}\n\nconst globalEvents = new Map();\nfunction addGlobalEventListener(event, fn) {\n let eventData = globalEvents.get(event);\n if (!eventData) {\n let handlers = new Set<(e: Event) => void>();\n let listener = (e) => {\n for (let handler of handlers) {\n handler(e);\n }\n };\n\n eventData = {listener, handlers};\n globalEvents.set(event, eventData);\n\n document.addEventListener(event, listener);\n }\n\n eventData.handlers.add(fn);\n return () => {\n eventData.handlers.delete(fn);\n if (eventData.handlers.size === 0) {\n document.removeEventListener(event, eventData.listener);\n globalEvents.delete(event);\n }\n };\n}\n\n/**\n * Handles clipboard interactions for a focusable element. Supports items of multiple\n * data types, and integrates with the operating system native clipboard.\n */\nexport function useClipboard(options: ClipboardProps): ClipboardResult {\n let {isDisabled} = options;\n let isFocusedRef = useRef(false);\n let {focusProps} = useFocus({\n onFocusChange: (isFocused) => {\n isFocusedRef.current = isFocused;\n }\n });\n\n let onBeforeCopy = useEffectEvent((e: ClipboardEvent) => {\n // Enable the \"Copy\" menu item in Safari if this element is focused and copying is supported.\n if (isFocusedRef.current && options.getItems) {\n e.preventDefault();\n }\n });\n\n let onCopy = useEffectEvent((e: ClipboardEvent) => {\n if (!isFocusedRef.current || !options.getItems) {\n return;\n }\n\n e.preventDefault();\n writeToDataTransfer(e.clipboardData, options.getItems());\n options.onCopy?.();\n });\n\n let onBeforeCut = useEffectEvent((e: ClipboardEvent) => {\n if (isFocusedRef.current && options.onCut && options.getItems) {\n e.preventDefault();\n }\n });\n\n let onCut = useEffectEvent((e: ClipboardEvent) => {\n if (!isFocusedRef.current || !options.onCut || !options.getItems) {\n return;\n }\n\n e.preventDefault();\n writeToDataTransfer(e.clipboardData, options.getItems());\n options.onCut();\n });\n\n let onBeforePaste = useEffectEvent((e: ClipboardEvent) => {\n // Unfortunately, e.clipboardData.types is not available in this event so we always\n // have to enable the Paste menu item even if the type of data is unsupported.\n if (isFocusedRef.current && options.onPaste) {\n e.preventDefault();\n }\n });\n\n let onPaste = useEffectEvent((e: ClipboardEvent) => {\n if (!isFocusedRef.current || !options.onPaste) {\n return;\n }\n\n e.preventDefault();\n let items = readFromDataTransfer(e.clipboardData);\n options.onPaste(items);\n });\n\n useEffect(() => {\n if (isDisabled) {\n return;\n }\n return chain(\n addGlobalEventListener('beforecopy', onBeforeCopy),\n addGlobalEventListener('copy', onCopy),\n addGlobalEventListener('beforecut', onBeforeCut),\n addGlobalEventListener('cut', onCut),\n addGlobalEventListener('beforepaste', onBeforePaste),\n addGlobalEventListener('paste', onPaste)\n );\n }, [isDisabled, onBeforeCopy, onCopy, onBeforeCut, onCut, onBeforePaste, onPaste]);\n\n return {\n clipboardProps: focusProps\n };\n}\n"],"names":[],"version":3,"file":"useClipboard.main.js.map"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import {readFromDataTransfer as $7252cd45fc48c07c$export$d9e760437831f8b3, writeToDataTransfer as $7252cd45fc48c07c$export$f9c1490890ddd063} from "./utils.mjs";
|
|
2
|
+
import {useEffectEvent as $9Tt78$useEffectEvent, chain as $9Tt78$chain} from "@react-aria/utils";
|
|
3
|
+
import {useRef as $9Tt78$useRef, useEffect as $9Tt78$useEffect} from "react";
|
|
4
|
+
import {useFocus as $9Tt78$useFocus} from "@react-aria/interactions";
|
|
5
|
+
|
|
6
|
+
/*
|
|
7
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
8
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
9
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
10
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
13
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
14
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
15
|
+
* governing permissions and limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
const $9fcc7f0d70d084ee$var$globalEvents = new Map();
|
|
21
|
+
function $9fcc7f0d70d084ee$var$addGlobalEventListener(event, fn) {
|
|
22
|
+
let eventData = $9fcc7f0d70d084ee$var$globalEvents.get(event);
|
|
23
|
+
if (!eventData) {
|
|
24
|
+
let handlers = new Set();
|
|
25
|
+
let listener = (e)=>{
|
|
26
|
+
for (let handler of handlers)handler(e);
|
|
27
|
+
};
|
|
28
|
+
eventData = {
|
|
29
|
+
listener: listener,
|
|
30
|
+
handlers: handlers
|
|
31
|
+
};
|
|
32
|
+
$9fcc7f0d70d084ee$var$globalEvents.set(event, eventData);
|
|
33
|
+
document.addEventListener(event, listener);
|
|
34
|
+
}
|
|
35
|
+
eventData.handlers.add(fn);
|
|
36
|
+
return ()=>{
|
|
37
|
+
eventData.handlers.delete(fn);
|
|
38
|
+
if (eventData.handlers.size === 0) {
|
|
39
|
+
document.removeEventListener(event, eventData.listener);
|
|
40
|
+
$9fcc7f0d70d084ee$var$globalEvents.delete(event);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function $9fcc7f0d70d084ee$export$2314ca2a3e892862(options) {
|
|
45
|
+
let { isDisabled: isDisabled } = options;
|
|
46
|
+
let isFocusedRef = (0, $9Tt78$useRef)(false);
|
|
47
|
+
let { focusProps: focusProps } = (0, $9Tt78$useFocus)({
|
|
48
|
+
onFocusChange: (isFocused)=>{
|
|
49
|
+
isFocusedRef.current = isFocused;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
let onBeforeCopy = (0, $9Tt78$useEffectEvent)((e)=>{
|
|
53
|
+
// Enable the "Copy" menu item in Safari if this element is focused and copying is supported.
|
|
54
|
+
if (isFocusedRef.current && options.getItems) e.preventDefault();
|
|
55
|
+
});
|
|
56
|
+
let onCopy = (0, $9Tt78$useEffectEvent)((e)=>{
|
|
57
|
+
var _options_onCopy;
|
|
58
|
+
if (!isFocusedRef.current || !options.getItems) return;
|
|
59
|
+
e.preventDefault();
|
|
60
|
+
(0, $7252cd45fc48c07c$export$f9c1490890ddd063)(e.clipboardData, options.getItems());
|
|
61
|
+
(_options_onCopy = options.onCopy) === null || _options_onCopy === void 0 ? void 0 : _options_onCopy.call(options);
|
|
62
|
+
});
|
|
63
|
+
let onBeforeCut = (0, $9Tt78$useEffectEvent)((e)=>{
|
|
64
|
+
if (isFocusedRef.current && options.onCut && options.getItems) e.preventDefault();
|
|
65
|
+
});
|
|
66
|
+
let onCut = (0, $9Tt78$useEffectEvent)((e)=>{
|
|
67
|
+
if (!isFocusedRef.current || !options.onCut || !options.getItems) return;
|
|
68
|
+
e.preventDefault();
|
|
69
|
+
(0, $7252cd45fc48c07c$export$f9c1490890ddd063)(e.clipboardData, options.getItems());
|
|
70
|
+
options.onCut();
|
|
71
|
+
});
|
|
72
|
+
let onBeforePaste = (0, $9Tt78$useEffectEvent)((e)=>{
|
|
73
|
+
// Unfortunately, e.clipboardData.types is not available in this event so we always
|
|
74
|
+
// have to enable the Paste menu item even if the type of data is unsupported.
|
|
75
|
+
if (isFocusedRef.current && options.onPaste) e.preventDefault();
|
|
76
|
+
});
|
|
77
|
+
let onPaste = (0, $9Tt78$useEffectEvent)((e)=>{
|
|
78
|
+
if (!isFocusedRef.current || !options.onPaste) return;
|
|
79
|
+
e.preventDefault();
|
|
80
|
+
let items = (0, $7252cd45fc48c07c$export$d9e760437831f8b3)(e.clipboardData);
|
|
81
|
+
options.onPaste(items);
|
|
82
|
+
});
|
|
83
|
+
(0, $9Tt78$useEffect)(()=>{
|
|
84
|
+
if (isDisabled) return;
|
|
85
|
+
return (0, $9Tt78$chain)($9fcc7f0d70d084ee$var$addGlobalEventListener("beforecopy", onBeforeCopy), $9fcc7f0d70d084ee$var$addGlobalEventListener("copy", onCopy), $9fcc7f0d70d084ee$var$addGlobalEventListener("beforecut", onBeforeCut), $9fcc7f0d70d084ee$var$addGlobalEventListener("cut", onCut), $9fcc7f0d70d084ee$var$addGlobalEventListener("beforepaste", onBeforePaste), $9fcc7f0d70d084ee$var$addGlobalEventListener("paste", onPaste));
|
|
86
|
+
}, [
|
|
87
|
+
isDisabled,
|
|
88
|
+
onBeforeCopy,
|
|
89
|
+
onCopy,
|
|
90
|
+
onBeforeCut,
|
|
91
|
+
onCut,
|
|
92
|
+
onBeforePaste,
|
|
93
|
+
onPaste
|
|
94
|
+
]);
|
|
95
|
+
return {
|
|
96
|
+
clipboardProps: focusProps
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
export {$9fcc7f0d70d084ee$export$2314ca2a3e892862 as useClipboard};
|
|
102
|
+
//# sourceMappingURL=useClipboard.mjs.map
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import {readFromDataTransfer as $7252cd45fc48c07c$export$d9e760437831f8b3, writeToDataTransfer as $7252cd45fc48c07c$export$f9c1490890ddd063} from "./utils.module.js";
|
|
2
|
+
import {useEffectEvent as $9Tt78$useEffectEvent, chain as $9Tt78$chain} from "@react-aria/utils";
|
|
3
|
+
import {useRef as $9Tt78$useRef, useEffect as $9Tt78$useEffect} from "react";
|
|
4
|
+
import {useFocus as $9Tt78$useFocus} from "@react-aria/interactions";
|
|
5
|
+
|
|
6
|
+
/*
|
|
7
|
+
* Copyright 2020 Adobe. All rights reserved.
|
|
8
|
+
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
9
|
+
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
10
|
+
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
13
|
+
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
14
|
+
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
15
|
+
* governing permissions and limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
const $9fcc7f0d70d084ee$var$globalEvents = new Map();
|
|
21
|
+
function $9fcc7f0d70d084ee$var$addGlobalEventListener(event, fn) {
|
|
22
|
+
let eventData = $9fcc7f0d70d084ee$var$globalEvents.get(event);
|
|
23
|
+
if (!eventData) {
|
|
24
|
+
let handlers = new Set();
|
|
25
|
+
let listener = (e)=>{
|
|
26
|
+
for (let handler of handlers)handler(e);
|
|
27
|
+
};
|
|
28
|
+
eventData = {
|
|
29
|
+
listener: listener,
|
|
30
|
+
handlers: handlers
|
|
31
|
+
};
|
|
32
|
+
$9fcc7f0d70d084ee$var$globalEvents.set(event, eventData);
|
|
33
|
+
document.addEventListener(event, listener);
|
|
34
|
+
}
|
|
35
|
+
eventData.handlers.add(fn);
|
|
36
|
+
return ()=>{
|
|
37
|
+
eventData.handlers.delete(fn);
|
|
38
|
+
if (eventData.handlers.size === 0) {
|
|
39
|
+
document.removeEventListener(event, eventData.listener);
|
|
40
|
+
$9fcc7f0d70d084ee$var$globalEvents.delete(event);
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function $9fcc7f0d70d084ee$export$2314ca2a3e892862(options) {
|
|
45
|
+
let { isDisabled: isDisabled } = options;
|
|
46
|
+
let isFocusedRef = (0, $9Tt78$useRef)(false);
|
|
47
|
+
let { focusProps: focusProps } = (0, $9Tt78$useFocus)({
|
|
48
|
+
onFocusChange: (isFocused)=>{
|
|
49
|
+
isFocusedRef.current = isFocused;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
let onBeforeCopy = (0, $9Tt78$useEffectEvent)((e)=>{
|
|
53
|
+
// Enable the "Copy" menu item in Safari if this element is focused and copying is supported.
|
|
54
|
+
if (isFocusedRef.current && options.getItems) e.preventDefault();
|
|
55
|
+
});
|
|
56
|
+
let onCopy = (0, $9Tt78$useEffectEvent)((e)=>{
|
|
57
|
+
var _options_onCopy;
|
|
58
|
+
if (!isFocusedRef.current || !options.getItems) return;
|
|
59
|
+
e.preventDefault();
|
|
60
|
+
(0, $7252cd45fc48c07c$export$f9c1490890ddd063)(e.clipboardData, options.getItems());
|
|
61
|
+
(_options_onCopy = options.onCopy) === null || _options_onCopy === void 0 ? void 0 : _options_onCopy.call(options);
|
|
62
|
+
});
|
|
63
|
+
let onBeforeCut = (0, $9Tt78$useEffectEvent)((e)=>{
|
|
64
|
+
if (isFocusedRef.current && options.onCut && options.getItems) e.preventDefault();
|
|
65
|
+
});
|
|
66
|
+
let onCut = (0, $9Tt78$useEffectEvent)((e)=>{
|
|
67
|
+
if (!isFocusedRef.current || !options.onCut || !options.getItems) return;
|
|
68
|
+
e.preventDefault();
|
|
69
|
+
(0, $7252cd45fc48c07c$export$f9c1490890ddd063)(e.clipboardData, options.getItems());
|
|
70
|
+
options.onCut();
|
|
71
|
+
});
|
|
72
|
+
let onBeforePaste = (0, $9Tt78$useEffectEvent)((e)=>{
|
|
73
|
+
// Unfortunately, e.clipboardData.types is not available in this event so we always
|
|
74
|
+
// have to enable the Paste menu item even if the type of data is unsupported.
|
|
75
|
+
if (isFocusedRef.current && options.onPaste) e.preventDefault();
|
|
76
|
+
});
|
|
77
|
+
let onPaste = (0, $9Tt78$useEffectEvent)((e)=>{
|
|
78
|
+
if (!isFocusedRef.current || !options.onPaste) return;
|
|
79
|
+
e.preventDefault();
|
|
80
|
+
let items = (0, $7252cd45fc48c07c$export$d9e760437831f8b3)(e.clipboardData);
|
|
81
|
+
options.onPaste(items);
|
|
82
|
+
});
|
|
83
|
+
(0, $9Tt78$useEffect)(()=>{
|
|
84
|
+
if (isDisabled) return;
|
|
85
|
+
return (0, $9Tt78$chain)($9fcc7f0d70d084ee$var$addGlobalEventListener("beforecopy", onBeforeCopy), $9fcc7f0d70d084ee$var$addGlobalEventListener("copy", onCopy), $9fcc7f0d70d084ee$var$addGlobalEventListener("beforecut", onBeforeCut), $9fcc7f0d70d084ee$var$addGlobalEventListener("cut", onCut), $9fcc7f0d70d084ee$var$addGlobalEventListener("beforepaste", onBeforePaste), $9fcc7f0d70d084ee$var$addGlobalEventListener("paste", onPaste));
|
|
86
|
+
}, [
|
|
87
|
+
isDisabled,
|
|
88
|
+
onBeforeCopy,
|
|
89
|
+
onCopy,
|
|
90
|
+
onBeforeCut,
|
|
91
|
+
onCut,
|
|
92
|
+
onBeforePaste,
|
|
93
|
+
onPaste
|
|
94
|
+
]);
|
|
95
|
+
return {
|
|
96
|
+
clipboardProps: focusProps
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
export {$9fcc7f0d70d084ee$export$2314ca2a3e892862 as useClipboard};
|
|
102
|
+
//# sourceMappingURL=useClipboard.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";;;;;AAAA;;;;;;;;;;CAUC;;;;AA0BD,MAAM,qCAAe,IAAI;AACzB,SAAS,6CAAuB,KAAK,EAAE,EAAE;IACvC,IAAI,YAAY,mCAAa,GAAG,CAAC;IACjC,IAAI,CAAC,WAAW;QACd,IAAI,WAAW,IAAI;QACnB,IAAI,WAAW,CAAC;YACd,KAAK,IAAI,WAAW,SAClB,QAAQ;QAEZ;QAEA,YAAY;sBAAC;sBAAU;QAAQ;QAC/B,mCAAa,GAAG,CAAC,OAAO;QAExB,SAAS,gBAAgB,CAAC,OAAO;IACnC;IAEA,UAAU,QAAQ,CAAC,GAAG,CAAC;IACvB,OAAO;QACL,UAAU,QAAQ,CAAC,MAAM,CAAC;QAC1B,IAAI,UAAU,QAAQ,CAAC,IAAI,KAAK,GAAG;YACjC,SAAS,mBAAmB,CAAC,OAAO,UAAU,QAAQ;YACtD,mCAAa,MAAM,CAAC;QACtB;IACF;AACF;AAMO,SAAS,0CAAa,OAAuB;IAClD,IAAI,cAAC,UAAU,EAAC,GAAG;IACnB,IAAI,eAAe,CAAA,GAAA,aAAK,EAAE;IAC1B,IAAI,cAAC,UAAU,EAAC,GAAG,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AAA,GAAA,gBAAQ,EAAE;QACR,IAAI,YACF;QAEF,OAAO,CAAA,GAAA,YAAI,EACT,6CAAuB,cAAc,eACrC,6CAAuB,QAAQ,SAC/B,6CAAuB,aAAa,cACpC,6CAAuB,OAAO,QAC9B,6CAAuB,eAAe,gBACtC,6CAAuB,SAAS;IAEpC,GAAG;QAAC;QAAY;QAAc;QAAQ;QAAa;QAAO;QAAe;KAAQ;IAEjF,OAAO;QACL,gBAAgB;IAClB;AACF","sources":["packages/@react-aria/dnd/src/useClipboard.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {chain, useEffectEvent} from '@react-aria/utils';\nimport {DOMAttributes, DragItem, DropItem} from '@react-types/shared';\nimport {readFromDataTransfer, writeToDataTransfer} from './utils';\nimport {useEffect, useRef} from 'react';\nimport {useFocus} from '@react-aria/interactions';\n\nexport interface ClipboardProps {\n /** A function that returns the items to copy. */\n getItems?: () => DragItem[],\n /** Handler that is called when the user triggers a copy interaction. */\n onCopy?: () => void,\n /** Handler that is called when the user triggers a cut interaction. */\n onCut?: () => void,\n /** Handler that is called when the user triggers a paste interaction. */\n onPaste?: (items: DropItem[]) => void,\n /** Whether the clipboard is disabled. */\n isDisabled?: boolean\n}\n\nexport interface ClipboardResult {\n /** Props for the element that will handle clipboard events. */\n clipboardProps: DOMAttributes\n}\n\nconst globalEvents = new Map();\nfunction addGlobalEventListener(event, fn) {\n let eventData = globalEvents.get(event);\n if (!eventData) {\n let handlers = new Set<(e: Event) => void>();\n let listener = (e) => {\n for (let handler of handlers) {\n handler(e);\n }\n };\n\n eventData = {listener, handlers};\n globalEvents.set(event, eventData);\n\n document.addEventListener(event, listener);\n }\n\n eventData.handlers.add(fn);\n return () => {\n eventData.handlers.delete(fn);\n if (eventData.handlers.size === 0) {\n document.removeEventListener(event, eventData.listener);\n globalEvents.delete(event);\n }\n };\n}\n\n/**\n * Handles clipboard interactions for a focusable element. Supports items of multiple\n * data types, and integrates with the operating system native clipboard.\n */\nexport function useClipboard(options: ClipboardProps): ClipboardResult {\n let {isDisabled} = options;\n let isFocusedRef = useRef(false);\n let {focusProps} = useFocus({\n onFocusChange: (isFocused) => {\n isFocusedRef.current = isFocused;\n }\n });\n\n let onBeforeCopy = useEffectEvent((e: ClipboardEvent) => {\n // Enable the \"Copy\" menu item in Safari if this element is focused and copying is supported.\n if (isFocusedRef.current && options.getItems) {\n e.preventDefault();\n }\n });\n\n let onCopy = useEffectEvent((e: ClipboardEvent) => {\n if (!isFocusedRef.current || !options.getItems) {\n return;\n }\n\n e.preventDefault();\n writeToDataTransfer(e.clipboardData, options.getItems());\n options.onCopy?.();\n });\n\n let onBeforeCut = useEffectEvent((e: ClipboardEvent) => {\n if (isFocusedRef.current && options.onCut && options.getItems) {\n e.preventDefault();\n }\n });\n\n let onCut = useEffectEvent((e: ClipboardEvent) => {\n if (!isFocusedRef.current || !options.onCut || !options.getItems) {\n return;\n }\n\n e.preventDefault();\n writeToDataTransfer(e.clipboardData, options.getItems());\n options.onCut();\n });\n\n let onBeforePaste = useEffectEvent((e: ClipboardEvent) => {\n // Unfortunately, e.clipboardData.types is not available in this event so we always\n // have to enable the Paste menu item even if the type of data is unsupported.\n if (isFocusedRef.current && options.onPaste) {\n e.preventDefault();\n }\n });\n\n let onPaste = useEffectEvent((e: ClipboardEvent) => {\n if (!isFocusedRef.current || !options.onPaste) {\n return;\n }\n\n e.preventDefault();\n let items = readFromDataTransfer(e.clipboardData);\n options.onPaste(items);\n });\n\n useEffect(() => {\n if (isDisabled) {\n return;\n }\n return chain(\n addGlobalEventListener('beforecopy', onBeforeCopy),\n addGlobalEventListener('copy', onCopy),\n addGlobalEventListener('beforecut', onBeforeCut),\n addGlobalEventListener('cut', onCut),\n addGlobalEventListener('beforepaste', onBeforePaste),\n addGlobalEventListener('paste', onPaste)\n );\n }, [isDisabled, onBeforeCopy, onCopy, onBeforeCut, onCut, onBeforePaste, onPaste]);\n\n return {\n clipboardProps: focusProps\n };\n}\n"],"names":[],"version":3,"file":"useClipboard.module.js.map"}
|