@react-aria/dnd 3.0.0-alpha.9 → 3.0.0-nightly-4980928d3-240906
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 +432 -0
- package/dist/DragManager.main.js.map +1 -0
- package/dist/DragManager.mjs +423 -0
- package/dist/DragManager.module.js +423 -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 +123 -0
- package/dist/ListDropTargetDelegate.main.js.map +1 -0
- package/dist/ListDropTargetDelegate.mjs +118 -0
- package/dist/ListDropTargetDelegate.module.js +118 -0
- package/dist/ListDropTargetDelegate.module.js.map +1 -0
- package/dist/ar-AE.main.js +44 -0
- package/dist/ar-AE.main.js.map +1 -0
- package/dist/ar-AE.mjs +46 -0
- package/dist/ar-AE.module.js +46 -0
- package/dist/ar-AE.module.js.map +1 -0
- package/dist/bg-BG.main.js +44 -0
- package/dist/bg-BG.main.js.map +1 -0
- package/dist/bg-BG.mjs +46 -0
- package/dist/bg-BG.module.js +46 -0
- package/dist/bg-BG.module.js.map +1 -0
- 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.main.js +45 -0
- package/dist/cs-CZ.main.js.map +1 -0
- package/dist/cs-CZ.mjs +47 -0
- package/dist/cs-CZ.module.js +47 -0
- package/dist/cs-CZ.module.js.map +1 -0
- package/dist/da-DK.main.js +44 -0
- package/dist/da-DK.main.js.map +1 -0
- package/dist/da-DK.mjs +46 -0
- package/dist/da-DK.module.js +46 -0
- package/dist/da-DK.module.js.map +1 -0
- package/dist/de-DE.main.js +44 -0
- package/dist/de-DE.main.js.map +1 -0
- package/dist/de-DE.mjs +46 -0
- package/dist/de-DE.module.js +46 -0
- package/dist/de-DE.module.js.map +1 -0
- package/dist/el-GR.main.js +44 -0
- package/dist/el-GR.main.js.map +1 -0
- package/dist/el-GR.mjs +46 -0
- package/dist/el-GR.module.js +46 -0
- package/dist/el-GR.module.js.map +1 -0
- package/dist/en-US.main.js +44 -0
- package/dist/en-US.main.js.map +1 -0
- package/dist/en-US.mjs +46 -0
- package/dist/en-US.module.js +46 -0
- package/dist/en-US.module.js.map +1 -0
- package/dist/es-ES.main.js +44 -0
- package/dist/es-ES.main.js.map +1 -0
- package/dist/es-ES.mjs +46 -0
- package/dist/es-ES.module.js +46 -0
- package/dist/es-ES.module.js.map +1 -0
- package/dist/et-EE.main.js +44 -0
- package/dist/et-EE.main.js.map +1 -0
- package/dist/et-EE.mjs +46 -0
- package/dist/et-EE.module.js +46 -0
- package/dist/et-EE.module.js.map +1 -0
- package/dist/fi-FI.main.js +44 -0
- package/dist/fi-FI.main.js.map +1 -0
- package/dist/fi-FI.mjs +46 -0
- package/dist/fi-FI.module.js +46 -0
- package/dist/fi-FI.module.js.map +1 -0
- package/dist/fr-FR.main.js +44 -0
- package/dist/fr-FR.main.js.map +1 -0
- package/dist/fr-FR.mjs +46 -0
- package/dist/fr-FR.module.js +46 -0
- package/dist/fr-FR.module.js.map +1 -0
- package/dist/he-IL.main.js +44 -0
- package/dist/he-IL.main.js.map +1 -0
- package/dist/he-IL.mjs +46 -0
- package/dist/he-IL.module.js +46 -0
- package/dist/he-IL.module.js.map +1 -0
- package/dist/hr-HR.main.js +44 -0
- package/dist/hr-HR.main.js.map +1 -0
- package/dist/hr-HR.mjs +46 -0
- package/dist/hr-HR.module.js +46 -0
- package/dist/hr-HR.module.js.map +1 -0
- package/dist/hu-HU.main.js +44 -0
- package/dist/hu-HU.main.js.map +1 -0
- package/dist/hu-HU.mjs +46 -0
- package/dist/hu-HU.module.js +46 -0
- package/dist/hu-HU.module.js.map +1 -0
- package/dist/import.mjs +39 -0
- 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.main.js +44 -0
- package/dist/it-IT.main.js.map +1 -0
- package/dist/it-IT.mjs +46 -0
- package/dist/it-IT.module.js +46 -0
- package/dist/it-IT.module.js.map +1 -0
- package/dist/ja-JP.main.js +44 -0
- package/dist/ja-JP.main.js.map +1 -0
- package/dist/ja-JP.mjs +46 -0
- package/dist/ja-JP.module.js +46 -0
- package/dist/ja-JP.module.js.map +1 -0
- package/dist/ko-KR.main.js +44 -0
- package/dist/ko-KR.main.js.map +1 -0
- package/dist/ko-KR.mjs +46 -0
- package/dist/ko-KR.module.js +46 -0
- package/dist/ko-KR.module.js.map +1 -0
- package/dist/lt-LT.main.js +44 -0
- package/dist/lt-LT.main.js.map +1 -0
- package/dist/lt-LT.mjs +46 -0
- package/dist/lt-LT.module.js +46 -0
- package/dist/lt-LT.module.js.map +1 -0
- package/dist/lv-LV.main.js +44 -0
- package/dist/lv-LV.main.js.map +1 -0
- package/dist/lv-LV.mjs +46 -0
- package/dist/lv-LV.module.js +46 -0
- package/dist/lv-LV.module.js.map +1 -0
- package/dist/main.js +39 -1873
- package/dist/main.js.map +1 -1
- package/dist/module.js +24 -1853
- package/dist/module.js.map +1 -1
- package/dist/nb-NO.main.js +44 -0
- package/dist/nb-NO.main.js.map +1 -0
- package/dist/nb-NO.mjs +46 -0
- package/dist/nb-NO.module.js +46 -0
- package/dist/nb-NO.module.js.map +1 -0
- package/dist/nl-NL.main.js +44 -0
- package/dist/nl-NL.main.js.map +1 -0
- package/dist/nl-NL.mjs +46 -0
- package/dist/nl-NL.module.js +46 -0
- package/dist/nl-NL.module.js.map +1 -0
- package/dist/pl-PL.main.js +44 -0
- package/dist/pl-PL.main.js.map +1 -0
- package/dist/pl-PL.mjs +46 -0
- package/dist/pl-PL.module.js +46 -0
- package/dist/pl-PL.module.js.map +1 -0
- package/dist/pt-BR.main.js +44 -0
- package/dist/pt-BR.main.js.map +1 -0
- package/dist/pt-BR.mjs +46 -0
- package/dist/pt-BR.module.js +46 -0
- package/dist/pt-BR.module.js.map +1 -0
- package/dist/pt-PT.main.js +44 -0
- package/dist/pt-PT.main.js.map +1 -0
- package/dist/pt-PT.mjs +46 -0
- package/dist/pt-PT.module.js +46 -0
- package/dist/pt-PT.module.js.map +1 -0
- package/dist/ro-RO.main.js +44 -0
- package/dist/ro-RO.main.js.map +1 -0
- package/dist/ro-RO.mjs +46 -0
- package/dist/ro-RO.module.js +46 -0
- package/dist/ro-RO.module.js.map +1 -0
- package/dist/ru-RU.main.js +44 -0
- package/dist/ru-RU.main.js.map +1 -0
- package/dist/ru-RU.mjs +46 -0
- package/dist/ru-RU.module.js +46 -0
- package/dist/ru-RU.module.js.map +1 -0
- package/dist/sk-SK.main.js +44 -0
- package/dist/sk-SK.main.js.map +1 -0
- package/dist/sk-SK.mjs +46 -0
- package/dist/sk-SK.module.js +46 -0
- package/dist/sk-SK.module.js.map +1 -0
- package/dist/sl-SI.main.js +44 -0
- package/dist/sl-SI.main.js.map +1 -0
- package/dist/sl-SI.mjs +46 -0
- package/dist/sl-SI.module.js +46 -0
- package/dist/sl-SI.module.js.map +1 -0
- package/dist/sr-SP.main.js +44 -0
- package/dist/sr-SP.main.js.map +1 -0
- package/dist/sr-SP.mjs +46 -0
- package/dist/sr-SP.module.js +46 -0
- package/dist/sr-SP.module.js.map +1 -0
- package/dist/sv-SE.main.js +44 -0
- package/dist/sv-SE.main.js.map +1 -0
- package/dist/sv-SE.mjs +46 -0
- package/dist/sv-SE.module.js +46 -0
- package/dist/sv-SE.module.js.map +1 -0
- package/dist/tr-TR.main.js +44 -0
- package/dist/tr-TR.main.js.map +1 -0
- package/dist/tr-TR.mjs +46 -0
- package/dist/tr-TR.module.js +46 -0
- package/dist/tr-TR.module.js.map +1 -0
- package/dist/types.d.ts +177 -29
- package/dist/types.d.ts.map +1 -1
- package/dist/uk-UA.main.js +44 -0
- package/dist/uk-UA.main.js.map +1 -0
- package/dist/uk-UA.mjs +46 -0
- package/dist/uk-UA.module.js +46 -0
- package/dist/uk-UA.module.js.map +1 -0
- 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 +286 -0
- package/dist/useDrag.main.js.map +1 -0
- package/dist/useDrag.mjs +281 -0
- package/dist/useDrag.module.js +281 -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 +592 -0
- package/dist/useDroppableCollection.main.js.map +1 -0
- package/dist/useDroppableCollection.mjs +587 -0
- package/dist/useDroppableCollection.module.js +587 -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.main.js +44 -0
- package/dist/zh-CN.main.js.map +1 -0
- package/dist/zh-CN.mjs +46 -0
- package/dist/zh-CN.module.js +46 -0
- package/dist/zh-CN.module.js.map +1 -0
- package/dist/zh-TW.main.js +44 -0
- package/dist/zh-TW.main.js.map +1 -0
- package/dist/zh-TW.mjs +46 -0
- package/dist/zh-TW.module.js +46 -0
- package/dist/zh-TW.module.js.map +1 -0
- package/package.json +20 -16
- package/src/DragManager.ts +87 -52
- package/src/DragPreview.tsx +3 -3
- package/src/ListDropTargetDelegate.ts +173 -0
- package/src/constants.ts +2 -0
- package/src/index.ts +55 -9
- package/src/useAutoScroll.ts +26 -6
- package/src/useClipboard.ts +65 -59
- package/src/useDrag.ts +179 -31
- package/src/useDraggableCollection.ts +29 -0
- package/src/useDraggableItem.ts +105 -12
- package/src/useDrop.ts +273 -93
- package/src/useDropIndicator.ts +47 -21
- package/src/useDroppableCollection.ts +315 -115
- package/src/useDroppableItem.ts +33 -17
- package/src/useVirtualDrop.ts +5 -5
- package/src/utils.ts +92 -17
- package/LICENSE +0 -201
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":";AAAA,4BAAiB;IAAG,2BAA2B,CAAC,uEAAe,CAAC;IAC9D,8BAA8B,CAAC,2EAAmB,CAAC;IACnD,4BAA4B,CAAC,gEAAQ,CAAC;IACtC,wBAAwB,CAAC,gFAAU,CAAC;IACpC,0BAA0B,CAAC,wFAAW,CAAC;IACvC,YAAY,CAAC,OAAS,CAAC,wBAAG,EAAE,KAAK,QAAQ,CAAC,QAAC,CAAC;IAC5C,qBAAqB,CAAC,MAAM,YAAc,CAAC,iBAAG,EAAE,UAAU,MAAM,CAAC,KAAK,KAAK,EAAE;YAAC,KAAK,IAAM,CAAC,EAAE,UAAU,MAAM,CAAC,KAAK,KAAK,EAAE,yCAAM,CAAC;YAAE,OAAO,IAAM,CAAC,EAAE,UAAU,MAAM,CAAC,KAAK,KAAK,EAAE,yCAAM,CAAC;QAAA,GAAG,CAAC;IAC1L,wBAAwB,CAAC,MAAM,YAAc,CAAC,gDAAa,EAAE,UAAU,MAAM,CAAC,KAAK,KAAK,EAAE;YAAC,KAAK,IAAM,CAAC,EAAE,UAAU,MAAM,CAAC,KAAK,KAAK,EAAE,yCAAM,CAAC;YAAE,OAAO,IAAM,CAAC,EAAE,UAAU,MAAM,CAAC,KAAK,KAAK,EAAE,yCAAM,CAAC;QAAA,GAAG,QAAC,CAAC;IACxM,2BAA2B,CAAC,MAAM,YAAc,CAAC,oDAAiB,EAAE,UAAU,MAAM,CAAC,KAAK,KAAK,EAAE;YAAC,KAAK,IAAM,CAAC,EAAE,UAAU,MAAM,CAAC,KAAK,KAAK,EAAE,yCAAM,CAAC;YAAE,OAAO,IAAM,CAAC,EAAE,UAAU,MAAM,CAAC,KAAK,KAAK,EAAE,yCAAM,CAAC;QAAA,GAAG,QAAC,CAAC;IAC/M,yBAAyB,CAAC,MAAM,YAAc,CAAC,yCAAM,EAAE,UAAU,MAAM,CAAC,KAAK,KAAK,EAAE;YAAC,KAAK,IAAM,CAAC,EAAE,UAAU,MAAM,CAAC,KAAK,KAAK,EAAE,yCAAM,CAAC;YAAE,OAAO,IAAM,CAAC,EAAE,UAAU,MAAM,CAAC,KAAK,KAAK,EAAE,yCAAM,CAAC;QAAA,GAAG,QAAC,CAAC;IAClM,uBAAuB,CAAC,oRAAoD,CAAC;IAC7E,oBAAoB,CAAC,gMAAwB,CAAC;IAC9C,sBAAsB,CAAC,uOAAmC,CAAC;IAC3D,gBAAgB,CAAC,gDAAM,CAAC;IACxB,gBAAgB,CAAC,gDAAM,CAAC;IACxB,2BAA2B,CAAC,+HAA6B,CAAC;IAC1D,wBAAwB,CAAC,gEAAQ,CAAC;IAClC,0BAA0B,CAAC,wEAAS,CAAC;IACrC,iBAAiB,CAAC,wCAAK,CAAC;IACxB,cAAc,CAAC,OAAS,CAAC,gCAAI,EAAE,KAAK,QAAQ,CAAC,gBAAE,CAAC;IAChD,cAAc,CAAC,wBAAG,CAAC;IACnB,mBAAmB,CAAC,uGAAmB,CAAC;IACxC,gBAAgB,CAAC,gHAAc,CAAC;IAChC,kBAAkB,CAAC,wHAAe,CAAC;IACnC,eAAe,CAAC,OAAS,CAAC,gCAAI,EAAE,KAAK,QAAQ,CAAC,wBAAG,CAAC;IAClD,gBAAgB,CAAC,OAAS,CAAC,gCAAI,EAAE,KAAK,QAAQ,CAAC,wBAAG,CAAC;IACnD,iBAAiB,CAAC,OAAS,CAAC,gCAAI,EAAE,KAAK,cAAc,CAAC,wBAAG,EAAE,KAAK,aAAa,CAAC,wBAAG,CAAC;AACpF","sources":["packages/@react-aria/dnd/intl/zh-TW.json"],"sourcesContent":["{\n \"dragDescriptionKeyboard\": \"按 Enter 鍵以開始拖曳。\",\n \"dragDescriptionKeyboardAlt\": \"按 Alt+Enter 鍵以開始拖曳。\",\n \"dragDescriptionLongPress\": \"長按以開始拖曳。\",\n \"dragDescriptionTouch\": \"輕點兩下以開始拖曳。\",\n \"dragDescriptionVirtual\": \"按一下滑鼠以開始拖曳。\",\n \"dragItem\": \"拖曳「{itemText}」\",\n \"dragSelectedItems\": \"拖曳 {count, plural, one {# 個選定項目} other {# 個選定項目}}\",\n \"dragSelectedKeyboard\": \"按 Enter 鍵以拖曳 {count, plural, one {# 個選定項目} other {# 個選定項目}}。\",\n \"dragSelectedKeyboardAlt\": \"按 Alt+Enter 鍵以拖曳 {count, plural, one {# 個選定項目} other {# 個選定項目}}。\",\n \"dragSelectedLongPress\": \"長按以拖曳 {count, plural, one {# 個選定項目} other {# 個選定項目}}。\",\n \"dragStartedKeyboard\": \"已開始拖曳。按 Tab 鍵以瀏覽至放置目標,然後按 Enter 鍵以放置,或按 Escape 鍵以取消。\",\n \"dragStartedTouch\": \"已開始拖曳。瀏覽至放置目標,然後輕點兩下以放置。\",\n \"dragStartedVirtual\": \"已開始拖曳。瀏覽至放置目標,然後按一下滑鼠或按 Enter 鍵以放置。\",\n \"dropCanceled\": \"放置已取消。\",\n \"dropComplete\": \"放置已完成。\",\n \"dropDescriptionKeyboard\": \"按 Enter 鍵以放置。按 Escape 鍵以取消拖曳。\",\n \"dropDescriptionTouch\": \"輕點兩下以放置。\",\n \"dropDescriptionVirtual\": \"按一下滑鼠以放置。\",\n \"dropIndicator\": \"放置指示器\",\n \"dropOnItem\": \"放置在「{itemText}」上\",\n \"dropOnRoot\": \"放置在\",\n \"endDragKeyboard\": \"拖曳中。按 Enter 鍵以取消拖曳。\",\n \"endDragTouch\": \"拖曳中。輕點兩下以取消拖曳。\",\n \"endDragVirtual\": \"拖曳中。按一下滑鼠以取消拖曳。\",\n \"insertAfter\": \"插入至「{itemText}」之後\",\n \"insertBefore\": \"插入至「{itemText}」之前\",\n \"insertBetween\": \"插入至「{beforeItemText}」和「{afterItemText}」之間\"\n}\n"],"names":[],"version":3,"file":"zh-TW.module.js.map"}
|
package/package.json
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-aria/dnd",
|
|
3
|
-
"version": "3.0.0-
|
|
3
|
+
"version": "3.0.0-nightly-4980928d3-240906",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
7
7
|
"module": "dist/module.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
"types": "./dist/types.d.ts",
|
|
10
|
+
"import": "./dist/import.mjs",
|
|
11
|
+
"require": "./dist/main.js"
|
|
12
|
+
},
|
|
8
13
|
"types": "dist/types.d.ts",
|
|
9
14
|
"source": "src/index.ts",
|
|
10
15
|
"files": [
|
|
@@ -17,24 +22,23 @@
|
|
|
17
22
|
"url": "https://github.com/adobe/react-spectrum"
|
|
18
23
|
},
|
|
19
24
|
"dependencies": {
|
|
20
|
-
"@
|
|
21
|
-
"@react-aria/i18n": "^3.
|
|
22
|
-
"@react-aria/interactions": "^3.
|
|
23
|
-
"@react-aria/live-announcer": "^3.
|
|
24
|
-
"@react-aria/overlays": "^3.
|
|
25
|
-
"@react-aria/utils": "^3.
|
|
26
|
-
"@react-
|
|
27
|
-
"@react-
|
|
28
|
-
"@react-
|
|
29
|
-
"@
|
|
30
|
-
"@react-types/shared": "^3.13.0"
|
|
25
|
+
"@internationalized/string": "^3.0.0-nightly-4980928d3-240906",
|
|
26
|
+
"@react-aria/i18n": "^3.0.0-nightly-4980928d3-240906",
|
|
27
|
+
"@react-aria/interactions": "^3.0.0-nightly-4980928d3-240906",
|
|
28
|
+
"@react-aria/live-announcer": "^3.0.0-nightly-4980928d3-240906",
|
|
29
|
+
"@react-aria/overlays": "^3.0.0-nightly-4980928d3-240906",
|
|
30
|
+
"@react-aria/utils": "^3.0.0-nightly-4980928d3-240906",
|
|
31
|
+
"@react-stately/dnd": "^3.0.0-nightly-4980928d3-240906",
|
|
32
|
+
"@react-types/button": "^3.0.0-nightly-4980928d3-240906",
|
|
33
|
+
"@react-types/shared": "^3.0.0-nightly-4980928d3-240906",
|
|
34
|
+
"@swc/helpers": "^0.5.0"
|
|
31
35
|
},
|
|
32
36
|
"peerDependencies": {
|
|
33
|
-
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0",
|
|
34
|
-
"react-dom": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0"
|
|
37
|
+
"react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0",
|
|
38
|
+
"react-dom": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0"
|
|
35
39
|
},
|
|
36
40
|
"publishConfig": {
|
|
37
41
|
"access": "public"
|
|
38
42
|
},
|
|
39
|
-
"
|
|
40
|
-
}
|
|
43
|
+
"stableVersion": "3.7.2"
|
|
44
|
+
}
|
package/src/DragManager.ts
CHANGED
|
@@ -12,8 +12,10 @@
|
|
|
12
12
|
|
|
13
13
|
import {announce} from '@react-aria/live-announcer';
|
|
14
14
|
import {ariaHideOutside} from '@react-aria/overlays';
|
|
15
|
-
import {DragEndEvent, DragItem, DropActivateEvent, DropEnterEvent, DropEvent, DropExitEvent, DropItem, DropOperation, DropTarget as DroppableCollectionTarget} from '@react-types/shared';
|
|
15
|
+
import {DragEndEvent, DragItem, DropActivateEvent, DropEnterEvent, DropEvent, DropExitEvent, DropItem, DropOperation, DropTarget as DroppableCollectionTarget, FocusableElement} from '@react-types/shared';
|
|
16
16
|
import {getDragModality, getTypes} from './utils';
|
|
17
|
+
import {isVirtualClick, isVirtualPointerEvent} from '@react-aria/utils';
|
|
18
|
+
import type {LocalizedStringFormatter} from '@internationalized/string';
|
|
17
19
|
import {useEffect, useState} from 'react';
|
|
18
20
|
|
|
19
21
|
let dropTargets = new Map<Element, DropTarget>();
|
|
@@ -22,7 +24,8 @@ let dragSession: DragSession = null;
|
|
|
22
24
|
let subscriptions = new Set<() => void>();
|
|
23
25
|
|
|
24
26
|
interface DropTarget {
|
|
25
|
-
element:
|
|
27
|
+
element: FocusableElement,
|
|
28
|
+
preventFocusOnDrop?: boolean,
|
|
26
29
|
getDropOperation?: (types: Set<string>, allowedOperations: DropOperation[]) => DropOperation,
|
|
27
30
|
onDropEnter?: (e: DropEnterEvent, dragTarget: DragTarget) => void,
|
|
28
31
|
onDropExit?: (e: DropExitEvent) => void,
|
|
@@ -42,7 +45,7 @@ export function registerDropTarget(target: DropTarget) {
|
|
|
42
45
|
}
|
|
43
46
|
|
|
44
47
|
interface DroppableItem {
|
|
45
|
-
element:
|
|
48
|
+
element: FocusableElement,
|
|
46
49
|
target: DroppableCollectionTarget,
|
|
47
50
|
getDropOperation?: (types: Set<string>, allowedOperations: DropOperation[]) => DropOperation
|
|
48
51
|
}
|
|
@@ -55,21 +58,20 @@ export function registerDropItem(item: DroppableItem) {
|
|
|
55
58
|
}
|
|
56
59
|
|
|
57
60
|
interface DragTarget {
|
|
58
|
-
element:
|
|
61
|
+
element: FocusableElement,
|
|
59
62
|
items: DragItem[],
|
|
60
63
|
allowedDropOperations: DropOperation[],
|
|
61
64
|
onDragEnd?: (e: DragEndEvent) => void
|
|
62
65
|
}
|
|
63
66
|
|
|
64
|
-
export function beginDragging(target: DragTarget,
|
|
67
|
+
export function beginDragging(target: DragTarget, stringFormatter: LocalizedStringFormatter) {
|
|
65
68
|
if (dragSession) {
|
|
66
69
|
throw new Error('Cannot begin dragging while already dragging');
|
|
67
70
|
}
|
|
68
71
|
|
|
69
|
-
dragSession = new DragSession(target,
|
|
72
|
+
dragSession = new DragSession(target, stringFormatter);
|
|
70
73
|
requestAnimationFrame(() => {
|
|
71
74
|
dragSession.setup();
|
|
72
|
-
|
|
73
75
|
if (getDragModality() === 'keyboard') {
|
|
74
76
|
dragSession.next();
|
|
75
77
|
}
|
|
@@ -94,6 +96,11 @@ export function useDragSession() {
|
|
|
94
96
|
return session;
|
|
95
97
|
}
|
|
96
98
|
|
|
99
|
+
/** @private */
|
|
100
|
+
export function isVirtualDragging(): boolean {
|
|
101
|
+
return !!dragSession;
|
|
102
|
+
}
|
|
103
|
+
|
|
97
104
|
function endDragging() {
|
|
98
105
|
dragSession = null;
|
|
99
106
|
for (let cb of subscriptions) {
|
|
@@ -129,7 +136,6 @@ const CANCELED_EVENTS = [
|
|
|
129
136
|
'touchstart',
|
|
130
137
|
'touchmove',
|
|
131
138
|
'touchend',
|
|
132
|
-
'keyup',
|
|
133
139
|
'focusin',
|
|
134
140
|
'focusout'
|
|
135
141
|
];
|
|
@@ -153,25 +159,28 @@ class DragSession {
|
|
|
153
159
|
currentDropItem: DroppableItem;
|
|
154
160
|
dropOperation: DropOperation;
|
|
155
161
|
private mutationObserver: MutationObserver;
|
|
156
|
-
private mutationImmediate: NodeJS.Immediate;
|
|
157
162
|
private restoreAriaHidden: () => void;
|
|
158
|
-
private
|
|
163
|
+
private stringFormatter: LocalizedStringFormatter;
|
|
159
164
|
private isVirtualClick: boolean;
|
|
165
|
+
private initialFocused: boolean;
|
|
160
166
|
|
|
161
|
-
constructor(target: DragTarget,
|
|
167
|
+
constructor(target: DragTarget, stringFormatter: LocalizedStringFormatter) {
|
|
162
168
|
this.dragTarget = target;
|
|
163
|
-
this.
|
|
169
|
+
this.stringFormatter = stringFormatter;
|
|
164
170
|
|
|
165
171
|
this.onKeyDown = this.onKeyDown.bind(this);
|
|
172
|
+
this.onKeyUp = this.onKeyUp.bind(this);
|
|
166
173
|
this.onFocus = this.onFocus.bind(this);
|
|
167
174
|
this.onBlur = this.onBlur.bind(this);
|
|
168
175
|
this.onClick = this.onClick.bind(this);
|
|
169
176
|
this.onPointerDown = this.onPointerDown.bind(this);
|
|
170
177
|
this.cancelEvent = this.cancelEvent.bind(this);
|
|
178
|
+
this.initialFocused = false;
|
|
171
179
|
}
|
|
172
180
|
|
|
173
181
|
setup() {
|
|
174
182
|
document.addEventListener('keydown', this.onKeyDown, true);
|
|
183
|
+
document.addEventListener('keyup', this.onKeyUp, true);
|
|
175
184
|
window.addEventListener('focus', this.onFocus, true);
|
|
176
185
|
window.addEventListener('blur', this.onBlur, true);
|
|
177
186
|
document.addEventListener('click', this.onClick, true);
|
|
@@ -186,11 +195,12 @@ class DragSession {
|
|
|
186
195
|
);
|
|
187
196
|
this.updateValidDropTargets();
|
|
188
197
|
|
|
189
|
-
announce(this.
|
|
198
|
+
announce(this.stringFormatter.format(MESSAGES[getDragModality()]));
|
|
190
199
|
}
|
|
191
200
|
|
|
192
201
|
teardown() {
|
|
193
202
|
document.removeEventListener('keydown', this.onKeyDown, true);
|
|
203
|
+
document.removeEventListener('keyup', this.onKeyUp, true);
|
|
194
204
|
window.removeEventListener('focus', this.onFocus, true);
|
|
195
205
|
window.removeEventListener('blur', this.onBlur, true);
|
|
196
206
|
document.removeEventListener('click', this.onClick, true);
|
|
@@ -202,9 +212,6 @@ class DragSession {
|
|
|
202
212
|
|
|
203
213
|
this.mutationObserver.disconnect();
|
|
204
214
|
this.restoreAriaHidden();
|
|
205
|
-
if (this.mutationImmediate) {
|
|
206
|
-
clearImmediate(this.mutationImmediate);
|
|
207
|
-
}
|
|
208
215
|
}
|
|
209
216
|
|
|
210
217
|
onKeyDown(e: KeyboardEvent) {
|
|
@@ -215,15 +222,6 @@ class DragSession {
|
|
|
215
222
|
return;
|
|
216
223
|
}
|
|
217
224
|
|
|
218
|
-
if (e.key === 'Enter') {
|
|
219
|
-
if (e.altKey) {
|
|
220
|
-
this.activate();
|
|
221
|
-
} else {
|
|
222
|
-
this.drop();
|
|
223
|
-
}
|
|
224
|
-
return;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
225
|
if (e.key === 'Tab' && !(e.metaKey || e.altKey || e.ctrlKey)) {
|
|
228
226
|
if (e.shiftKey) {
|
|
229
227
|
this.previous();
|
|
@@ -237,6 +235,18 @@ class DragSession {
|
|
|
237
235
|
}
|
|
238
236
|
}
|
|
239
237
|
|
|
238
|
+
onKeyUp(e: KeyboardEvent) {
|
|
239
|
+
this.cancelEvent(e);
|
|
240
|
+
|
|
241
|
+
if (e.key === 'Enter') {
|
|
242
|
+
if (e.altKey) {
|
|
243
|
+
this.activate();
|
|
244
|
+
} else {
|
|
245
|
+
this.drop();
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
240
250
|
onFocus(e: FocusEvent) {
|
|
241
251
|
// Prevent focus events, except to the original drag target.
|
|
242
252
|
if (e.target !== this.dragTarget.element) {
|
|
@@ -248,7 +258,10 @@ class DragSession {
|
|
|
248
258
|
return;
|
|
249
259
|
}
|
|
250
260
|
|
|
251
|
-
let dropTarget =
|
|
261
|
+
let dropTarget =
|
|
262
|
+
this.validDropTargets.find(target => target.element === e.target as HTMLElement) ||
|
|
263
|
+
this.validDropTargets.find(target => target.element.contains(e.target as HTMLElement));
|
|
264
|
+
|
|
252
265
|
if (!dropTarget) {
|
|
253
266
|
if (this.currentDropTarget) {
|
|
254
267
|
this.currentDropTarget.element.focus();
|
|
@@ -280,7 +293,7 @@ class DragSession {
|
|
|
280
293
|
|
|
281
294
|
onClick(e: MouseEvent) {
|
|
282
295
|
this.cancelEvent(e);
|
|
283
|
-
if (e
|
|
296
|
+
if (isVirtualClick(e) || this.isVirtualClick) {
|
|
284
297
|
if (e.target === this.dragTarget.element) {
|
|
285
298
|
this.cancel();
|
|
286
299
|
return;
|
|
@@ -328,6 +341,16 @@ class DragSession {
|
|
|
328
341
|
}
|
|
329
342
|
|
|
330
343
|
this.validDropTargets = findValidDropTargets(this.dragTarget);
|
|
344
|
+
|
|
345
|
+
// Shuffle drop target order based on starting drag target.
|
|
346
|
+
if (this.validDropTargets.length > 0) {
|
|
347
|
+
let nearestIndex = this.findNearestDropTarget();
|
|
348
|
+
this.validDropTargets = [
|
|
349
|
+
...this.validDropTargets.slice(nearestIndex),
|
|
350
|
+
...this.validDropTargets.slice(0, nearestIndex)
|
|
351
|
+
];
|
|
352
|
+
}
|
|
353
|
+
|
|
331
354
|
if (this.currentDropTarget && !this.validDropTargets.includes(this.currentDropTarget)) {
|
|
332
355
|
this.setCurrentDropTarget(this.validDropTargets[0]);
|
|
333
356
|
}
|
|
@@ -409,6 +432,26 @@ class DragSession {
|
|
|
409
432
|
}
|
|
410
433
|
}
|
|
411
434
|
|
|
435
|
+
findNearestDropTarget(): number {
|
|
436
|
+
let dragTargetRect = this.dragTarget.element.getBoundingClientRect();
|
|
437
|
+
|
|
438
|
+
let minDistance = Infinity;
|
|
439
|
+
let nearest = -1;
|
|
440
|
+
for (let i = 0; i < this.validDropTargets.length; i++) {
|
|
441
|
+
let dropTarget = this.validDropTargets[i];
|
|
442
|
+
let rect = dropTarget.element.getBoundingClientRect();
|
|
443
|
+
let dx = rect.left - dragTargetRect.left;
|
|
444
|
+
let dy = rect.top - dragTargetRect.top;
|
|
445
|
+
let dist = (dx * dx) + (dy * dy);
|
|
446
|
+
if (dist < minDistance) {
|
|
447
|
+
minDistance = dist;
|
|
448
|
+
nearest = i;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
return nearest;
|
|
453
|
+
}
|
|
454
|
+
|
|
412
455
|
setCurrentDropTarget(dropTarget: DropTarget, item?: DroppableItem) {
|
|
413
456
|
if (dropTarget !== this.currentDropTarget) {
|
|
414
457
|
if (this.currentDropTarget && typeof this.currentDropTarget.onDropExit === 'function') {
|
|
@@ -438,7 +481,6 @@ class DragSession {
|
|
|
438
481
|
}
|
|
439
482
|
}
|
|
440
483
|
|
|
441
|
-
|
|
442
484
|
if (item !== this.currentDropItem) {
|
|
443
485
|
if (item && typeof this.currentDropTarget.onDropTargetEnter === 'function') {
|
|
444
486
|
this.currentDropTarget.onDropTargetEnter(item?.target);
|
|
@@ -446,11 +488,19 @@ class DragSession {
|
|
|
446
488
|
|
|
447
489
|
item?.element.focus();
|
|
448
490
|
this.currentDropItem = item;
|
|
491
|
+
|
|
492
|
+
// Announce first drop target after drag start announcement finishes.
|
|
493
|
+
// Otherwise, it will never get announced because drag start announcement is assertive.
|
|
494
|
+
if (!this.initialFocused) {
|
|
495
|
+
announce(item?.element.getAttribute('aria-label'), 'polite');
|
|
496
|
+
this.initialFocused = true;
|
|
497
|
+
}
|
|
449
498
|
}
|
|
450
499
|
}
|
|
451
500
|
|
|
452
501
|
end() {
|
|
453
502
|
this.teardown();
|
|
503
|
+
endDragging();
|
|
454
504
|
|
|
455
505
|
if (typeof this.dragTarget.onDragEnd === 'function') {
|
|
456
506
|
let target = this.currentDropTarget && this.dropOperation !== 'cancel' ? this.currentDropTarget : this.dragTarget;
|
|
@@ -459,27 +509,28 @@ class DragSession {
|
|
|
459
509
|
type: 'dragend',
|
|
460
510
|
x: rect.x + (rect.width / 2),
|
|
461
511
|
y: rect.y + (rect.height / 2),
|
|
462
|
-
dropOperation: this.dropOperation
|
|
512
|
+
dropOperation: this.dropOperation || 'cancel'
|
|
463
513
|
});
|
|
464
514
|
}
|
|
465
515
|
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
this.
|
|
516
|
+
if (this.currentDropTarget && !this.currentDropTarget.preventFocusOnDrop) {
|
|
517
|
+
// Re-trigger focus event on active element, since it will not have received it during dragging (see cancelEvent).
|
|
518
|
+
// This corrects state such as whether focus ring should appear.
|
|
519
|
+
// useDroppableCollection handles this itself, so this is only for standalone drop zones.
|
|
520
|
+
document.activeElement.dispatchEvent(new FocusEvent('focusin', {bubbles: true}));
|
|
470
521
|
}
|
|
471
522
|
|
|
472
523
|
this.setCurrentDropTarget(null);
|
|
473
|
-
endDragging();
|
|
474
524
|
}
|
|
475
525
|
|
|
476
526
|
cancel() {
|
|
527
|
+
this.setCurrentDropTarget(null);
|
|
477
528
|
this.end();
|
|
478
529
|
if (!this.dragTarget.element.closest('[aria-hidden="true"]')) {
|
|
479
530
|
this.dragTarget.element.focus();
|
|
480
531
|
}
|
|
481
532
|
|
|
482
|
-
announce(this.
|
|
533
|
+
announce(this.stringFormatter.format('dropCanceled'));
|
|
483
534
|
}
|
|
484
535
|
|
|
485
536
|
drop(item?: DroppableItem) {
|
|
@@ -517,7 +568,7 @@ class DragSession {
|
|
|
517
568
|
}
|
|
518
569
|
|
|
519
570
|
this.end();
|
|
520
|
-
announce(this.
|
|
571
|
+
announce(this.stringFormatter.format('dropComplete'));
|
|
521
572
|
}
|
|
522
573
|
|
|
523
574
|
activate() {
|
|
@@ -546,19 +597,3 @@ function findValidDropTargets(options: DragTarget) {
|
|
|
546
597
|
return true;
|
|
547
598
|
});
|
|
548
599
|
}
|
|
549
|
-
|
|
550
|
-
function isVirtualPointerEvent(event: PointerEvent) {
|
|
551
|
-
// If the pointer size is zero, then we assume it's from a screen reader.
|
|
552
|
-
// Android TalkBack double tap will sometimes return a event with width and height of 1
|
|
553
|
-
// and pointerType === 'mouse' so we need to check for a specific combination of event attributes.
|
|
554
|
-
// Cannot use "event.pressure === 0" as the sole check due to Safari pointer events always returning pressure === 0
|
|
555
|
-
// instead of .5, see https://bugs.webkit.org/show_bug.cgi?id=206216
|
|
556
|
-
return (
|
|
557
|
-
(event.width === 0 && event.height === 0) ||
|
|
558
|
-
(event.width === 1 &&
|
|
559
|
-
event.height === 1 &&
|
|
560
|
-
event.pressure === 0 &&
|
|
561
|
-
event.detail === 0
|
|
562
|
-
)
|
|
563
|
-
);
|
|
564
|
-
}
|
package/src/DragPreview.tsx
CHANGED
|
@@ -10,15 +10,15 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
import {DragItem, DragPreviewRenderer} from '@react-types/shared';
|
|
13
|
+
import {DragItem, DragPreviewRenderer, RefObject} from '@react-types/shared';
|
|
14
14
|
import {flushSync} from 'react-dom';
|
|
15
|
-
import React, {
|
|
15
|
+
import React, {JSX, useImperativeHandle, useRef, useState} from 'react';
|
|
16
16
|
|
|
17
17
|
export interface DragPreviewProps {
|
|
18
18
|
children: (items: DragItem[]) => JSX.Element
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
function DragPreview(props: DragPreviewProps, ref: RefObject<DragPreviewRenderer>) {
|
|
21
|
+
function DragPreview(props: DragPreviewProps, ref: RefObject<DragPreviewRenderer | null>) {
|
|
22
22
|
let render = props.children;
|
|
23
23
|
let [children, setChildren] = useState<JSX.Element>(null);
|
|
24
24
|
let domRef = useRef(null);
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import {Direction, DropTarget, DropTargetDelegate, Node, Orientation, RefObject} from '@react-types/shared';
|
|
2
|
+
|
|
3
|
+
interface ListDropTargetDelegateOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Whether the items are arranged in a stack or grid.
|
|
6
|
+
* @default 'stack'
|
|
7
|
+
*/
|
|
8
|
+
layout?: 'stack' | 'grid',
|
|
9
|
+
/**
|
|
10
|
+
* The primary orientation of the items. Usually this is the
|
|
11
|
+
* direction that the collection scrolls.
|
|
12
|
+
* @default 'vertical'
|
|
13
|
+
*/
|
|
14
|
+
orientation?: Orientation,
|
|
15
|
+
/**
|
|
16
|
+
* The horizontal layout direction.
|
|
17
|
+
* @default 'ltr'
|
|
18
|
+
*/
|
|
19
|
+
direction?: Direction
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Terms used in the below code:
|
|
23
|
+
// * "Primary" – The main layout direction. For stacks, this is the direction
|
|
24
|
+
// that the stack is arranged in (e.g. horizontal or vertical).
|
|
25
|
+
// For grids, this is the main scroll direction.
|
|
26
|
+
// * "Secondary" – The secondary layout direction. For stacks, there is no secondary
|
|
27
|
+
// layout direction. For grids, this is the opposite of the primary direction.
|
|
28
|
+
// * "Flow" – The flow direction of the items. For stacks, this is the the primary
|
|
29
|
+
// direction. For grids, it is the secondary direction.
|
|
30
|
+
|
|
31
|
+
export class ListDropTargetDelegate implements DropTargetDelegate {
|
|
32
|
+
private collection: Iterable<Node<unknown>>;
|
|
33
|
+
private ref: RefObject<HTMLElement | null>;
|
|
34
|
+
private layout: 'stack' | 'grid';
|
|
35
|
+
private orientation: Orientation;
|
|
36
|
+
private direction: Direction;
|
|
37
|
+
|
|
38
|
+
constructor(collection: Iterable<Node<unknown>>, ref: RefObject<HTMLElement | null>, options?: ListDropTargetDelegateOptions) {
|
|
39
|
+
this.collection = collection;
|
|
40
|
+
this.ref = ref;
|
|
41
|
+
this.layout = options?.layout || 'stack';
|
|
42
|
+
this.orientation = options?.orientation || 'vertical';
|
|
43
|
+
this.direction = options?.direction || 'ltr';
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
private getPrimaryStart(rect: DOMRect) {
|
|
47
|
+
return this.orientation === 'horizontal' ? rect.left : rect.top;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
private getPrimaryEnd(rect: DOMRect) {
|
|
51
|
+
return this.orientation === 'horizontal' ? rect.right : rect.bottom;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
private getSecondaryStart(rect: DOMRect) {
|
|
55
|
+
return this.orientation === 'horizontal' ? rect.top : rect.left;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
private getSecondaryEnd(rect: DOMRect) {
|
|
59
|
+
return this.orientation === 'horizontal' ? rect.bottom : rect.right;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
private getFlowStart(rect: DOMRect) {
|
|
63
|
+
return this.layout === 'stack' ? this.getPrimaryStart(rect) : this.getSecondaryStart(rect);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
private getFlowEnd(rect: DOMRect) {
|
|
67
|
+
return this.layout === 'stack' ? this.getPrimaryEnd(rect) : this.getSecondaryEnd(rect);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
private getFlowSize(rect: DOMRect) {
|
|
71
|
+
return this.getFlowEnd(rect) - this.getFlowStart(rect);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
getDropTargetFromPoint(x: number, y: number, isValidDropTarget: (target: DropTarget) => boolean): DropTarget {
|
|
75
|
+
if (this.collection[Symbol.iterator]().next().done) {
|
|
76
|
+
return {type: 'root'};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
let rect = this.ref.current.getBoundingClientRect();
|
|
80
|
+
let primary = this.orientation === 'horizontal' ? x : y;
|
|
81
|
+
let secondary = this.orientation === 'horizontal' ? y : x;
|
|
82
|
+
primary += this.getPrimaryStart(rect);
|
|
83
|
+
secondary += this.getSecondaryStart(rect);
|
|
84
|
+
|
|
85
|
+
let flow = this.layout === 'stack' ? primary : secondary;
|
|
86
|
+
let isPrimaryRTL = this.orientation === 'horizontal' && this.direction === 'rtl';
|
|
87
|
+
let isSecondaryRTL = this.layout === 'grid' && this.orientation === 'vertical' && this.direction === 'rtl';
|
|
88
|
+
let isFlowRTL = this.layout === 'stack' ? isPrimaryRTL : isSecondaryRTL;
|
|
89
|
+
|
|
90
|
+
let elements = this.ref.current.querySelectorAll('[data-key]');
|
|
91
|
+
let elementMap = new Map<string, HTMLElement>();
|
|
92
|
+
for (let item of elements) {
|
|
93
|
+
if (item instanceof HTMLElement) {
|
|
94
|
+
elementMap.set(item.dataset.key, item);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// TODO: assume that only item type items are valid drop targets. This is to prevent a crash when dragging over the loader
|
|
99
|
+
// row since it doesn't have a data-key set on it. Will eventually need to handle the case with drag and drop and loaders located between rows aka tree.
|
|
100
|
+
// Can see https://github.com/adobe/react-spectrum/pull/4210/files#diff-21e555e0c597a28215e36137f5be076a65a1e1456c92cd0fdd60f866929aae2a for additional logic
|
|
101
|
+
// that may need to happen then
|
|
102
|
+
let items = [...this.collection].filter(item => item.type === 'item');
|
|
103
|
+
let low = 0;
|
|
104
|
+
let high = items.length;
|
|
105
|
+
while (low < high) {
|
|
106
|
+
let mid = Math.floor((low + high) / 2);
|
|
107
|
+
let item = items[mid];
|
|
108
|
+
let element = elementMap.get(String(item.key));
|
|
109
|
+
let rect = element.getBoundingClientRect();
|
|
110
|
+
let update = (isGreater: boolean) => {
|
|
111
|
+
if (isGreater) {
|
|
112
|
+
low = mid + 1;
|
|
113
|
+
} else {
|
|
114
|
+
high = mid;
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
if (primary < this.getPrimaryStart(rect)) {
|
|
119
|
+
update(isPrimaryRTL);
|
|
120
|
+
} else if (primary > this.getPrimaryEnd(rect)) {
|
|
121
|
+
update(!isPrimaryRTL);
|
|
122
|
+
} else if (secondary < this.getSecondaryStart(rect)) {
|
|
123
|
+
update(isSecondaryRTL);
|
|
124
|
+
} else if (secondary > this.getSecondaryEnd(rect)) {
|
|
125
|
+
update(!isSecondaryRTL);
|
|
126
|
+
} else {
|
|
127
|
+
let target: DropTarget = {
|
|
128
|
+
type: 'item',
|
|
129
|
+
key: item.key,
|
|
130
|
+
dropPosition: 'on'
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
if (isValidDropTarget(target)) {
|
|
134
|
+
// Otherwise, if dropping on the item is accepted, try the before/after positions if within 5px
|
|
135
|
+
// of the start or end of the item.
|
|
136
|
+
if (flow <= this.getFlowStart(rect) + 5 && isValidDropTarget({...target, dropPosition: 'before'})) {
|
|
137
|
+
target.dropPosition = isFlowRTL ? 'after' : 'before';
|
|
138
|
+
} else if (flow >= this.getFlowEnd(rect) - 5 && isValidDropTarget({...target, dropPosition: 'after'})) {
|
|
139
|
+
target.dropPosition = isFlowRTL ? 'before' : 'after';
|
|
140
|
+
}
|
|
141
|
+
} else {
|
|
142
|
+
// If dropping on the item isn't accepted, try the target before or after depending on the position.
|
|
143
|
+
let mid = this.getFlowStart(rect) + this.getFlowSize(rect) / 2;
|
|
144
|
+
if (flow <= mid && isValidDropTarget({...target, dropPosition: 'before'})) {
|
|
145
|
+
target.dropPosition = isFlowRTL ? 'after' : 'before';
|
|
146
|
+
} else if (flow >= mid && isValidDropTarget({...target, dropPosition: 'after'})) {
|
|
147
|
+
target.dropPosition = isFlowRTL ? 'before' : 'after';
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return target;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
let item = items[Math.min(low, items.length - 1)];
|
|
156
|
+
let element = elementMap.get(String(item.key));
|
|
157
|
+
rect = element.getBoundingClientRect();
|
|
158
|
+
|
|
159
|
+
if (primary < this.getPrimaryStart(rect) || Math.abs(flow - this.getFlowStart(rect)) < Math.abs(flow - this.getFlowEnd(rect))) {
|
|
160
|
+
return {
|
|
161
|
+
type: 'item',
|
|
162
|
+
key: item.key,
|
|
163
|
+
dropPosition: isFlowRTL ? 'after' : 'before'
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return {
|
|
168
|
+
type: 'item',
|
|
169
|
+
key: item.key,
|
|
170
|
+
dropPosition: isFlowRTL ? 'before' : 'after'
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
}
|
package/src/constants.ts
CHANGED
|
@@ -32,6 +32,8 @@ export const DROP_OPERATION_ALLOWED = {
|
|
|
32
32
|
};
|
|
33
33
|
|
|
34
34
|
export const EFFECT_ALLOWED = invert(DROP_OPERATION_ALLOWED);
|
|
35
|
+
EFFECT_ALLOWED[DROP_OPERATION.all] = 'all'; // ensure we don't map to 'uninitialized'.
|
|
36
|
+
|
|
35
37
|
export const DROP_EFFECT = invert(DROP_OPERATION);
|
|
36
38
|
export const DROP_EFFECT_TO_DROP_OPERATION: {[name: string]: DropOperation} = {
|
|
37
39
|
none: 'cancel',
|
package/src/index.ts
CHANGED
|
@@ -10,13 +10,59 @@
|
|
|
10
10
|
* governing permissions and limitations under the License.
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
-
export
|
|
14
|
-
export
|
|
15
|
-
export
|
|
16
|
-
export
|
|
17
|
-
export
|
|
18
|
-
export * from './useDraggableItem';
|
|
19
|
-
export * from './useClipboard';
|
|
20
|
-
export {DragPreview} from './DragPreview';
|
|
21
|
-
|
|
13
|
+
export type {DroppableCollectionOptions, DroppableCollectionResult} from './useDroppableCollection';
|
|
14
|
+
export type {DroppableItemOptions, DroppableItemResult} from './useDroppableItem';
|
|
15
|
+
export type {DropIndicatorProps, DropIndicatorAria} from './useDropIndicator';
|
|
16
|
+
export type {DraggableItemProps, DraggableItemResult} from './useDraggableItem';
|
|
17
|
+
export type {DraggableCollectionOptions} from './useDraggableCollection';
|
|
22
18
|
export type {DragPreviewProps} from './DragPreview';
|
|
19
|
+
export type {DragOptions, DragResult} from './useDrag';
|
|
20
|
+
export type {DropOptions, DropResult} from './useDrop';
|
|
21
|
+
export type {ClipboardProps, ClipboardResult} from './useClipboard';
|
|
22
|
+
export type {
|
|
23
|
+
DirectoryDropItem,
|
|
24
|
+
DragEndEvent,
|
|
25
|
+
DraggableCollectionEndEvent,
|
|
26
|
+
DraggableCollectionMoveEvent,
|
|
27
|
+
DraggableCollectionStartEvent,
|
|
28
|
+
DragItem,
|
|
29
|
+
DragMoveEvent,
|
|
30
|
+
DragPreviewRenderer,
|
|
31
|
+
DragStartEvent,
|
|
32
|
+
DragTypes,
|
|
33
|
+
DropEnterEvent,
|
|
34
|
+
DropEvent,
|
|
35
|
+
DropExitEvent,
|
|
36
|
+
DropItem,
|
|
37
|
+
DropMoveEvent,
|
|
38
|
+
DropOperation,
|
|
39
|
+
DroppableCollectionDropEvent,
|
|
40
|
+
DroppableCollectionEnterEvent,
|
|
41
|
+
DroppableCollectionExitEvent,
|
|
42
|
+
DroppableCollectionInsertDropEvent,
|
|
43
|
+
DroppableCollectionMoveEvent,
|
|
44
|
+
DroppableCollectionOnItemDropEvent,
|
|
45
|
+
DroppableCollectionReorderEvent,
|
|
46
|
+
DroppableCollectionRootDropEvent,
|
|
47
|
+
DropPosition,
|
|
48
|
+
DropTarget,
|
|
49
|
+
DropTargetDelegate,
|
|
50
|
+
FileDropItem,
|
|
51
|
+
ItemDropTarget,
|
|
52
|
+
RootDropTarget,
|
|
53
|
+
TextDropItem
|
|
54
|
+
} from '@react-types/shared';
|
|
55
|
+
|
|
56
|
+
export {DIRECTORY_DRAG_TYPE} from './utils';
|
|
57
|
+
export {useDrag} from './useDrag';
|
|
58
|
+
export {useDrop} from './useDrop';
|
|
59
|
+
export {useDroppableCollection} from './useDroppableCollection';
|
|
60
|
+
export {useDroppableItem} from './useDroppableItem';
|
|
61
|
+
export {useDropIndicator} from './useDropIndicator';
|
|
62
|
+
export {useDraggableItem} from './useDraggableItem';
|
|
63
|
+
export {useDraggableCollection} from './useDraggableCollection';
|
|
64
|
+
export {useClipboard} from './useClipboard';
|
|
65
|
+
export {DragPreview} from './DragPreview';
|
|
66
|
+
export {ListDropTargetDelegate} from './ListDropTargetDelegate';
|
|
67
|
+
export {isVirtualDragging} from './DragManager';
|
|
68
|
+
export {isDirectoryDropItem, isFileDropItem, isTextDropItem} from './utils';
|