@react-stately/dnd 3.5.4 → 3.6.1
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/types.d.ts.map +1 -1
- package/dist/useDraggableCollectionState.main.js +21 -5
- package/dist/useDraggableCollectionState.main.js.map +1 -1
- package/dist/useDraggableCollectionState.mjs +21 -5
- package/dist/useDraggableCollectionState.module.js +21 -5
- package/dist/useDraggableCollectionState.module.js.map +1 -1
- package/dist/useDroppableCollectionState.main.js +22 -10
- package/dist/useDroppableCollectionState.main.js.map +1 -1
- package/dist/useDroppableCollectionState.mjs +22 -10
- package/dist/useDroppableCollectionState.module.js +22 -10
- package/dist/useDroppableCollectionState.module.js.map +1 -1
- package/package.json +9 -5
- package/src/useDraggableCollectionState.ts +27 -7
- package/src/useDroppableCollectionState.ts +45 -8
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;AAgBA,gDAAiD,SAAQ,wBAAwB;IAC/E,6BAA6B;IAC7B,UAAU,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC;IACtC,sEAAsE;IACtE,gBAAgB,EAAE,wBAAwB,CAAC;IAC3C,kDAAkD;IAClD,UAAU,CAAC,EAAE,OAAO,CAAA;CACrB;AAED;IACE,6BAA6B;IAC7B,UAAU,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC;IACtC,sEAAsE;IACtE,gBAAgB,EAAE,wBAAwB,CAAC;IAC3C,iDAAiD;IACjD,UAAU,EAAE,GAAG,GAAG,IAAI,CAAC;IACvB,8DAA8D;IAC9D,YAAY,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;IACvB,wCAAwC;IACxC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,gEAAgE;IAChE,UAAU,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC;IAC9B,mGAAmG;IACnG,cAAc,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,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AC,MAAM,EAAE,UAAU,GAAG,IAAI,GAAG,IAAI,CAAC;IAC3C,iFAAiF;IACjF,YAAY,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI,GAAG,OAAO,CAAC;IACjD,2DAA2D;IAC3D,gBAAgB,CAAC,CAAC,EAAE,kBAAkB,GAAG,aAAa,CAAA;CACvD;AAED;;GAEG;AACH,4CAA4C,KAAK,EAAE,+BAA+B,GAAG,wBAAwB,CAkJ5G","sources":["packages/@react-stately/dnd/src/packages/@react-stately/dnd/src/useDraggableCollectionState.ts","packages/@react-stately/dnd/src/packages/@react-stately/dnd/src/useDroppableCollectionState.ts","packages/@react-stately/dnd/src/packages/@react-stately/dnd/src/index.ts","packages/@react-stately/dnd/src/index.ts"],"sourcesContent":[null,null,null,"/*\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\nexport type {DraggableCollectionStateOptions, DraggableCollectionState} from './useDraggableCollectionState';\nexport type {DroppableCollectionStateOptions, DroppableCollectionState} from './useDroppableCollectionState';\nexport {useDraggableCollectionState} from './useDraggableCollectionState';\nexport {useDroppableCollectionState} from './useDroppableCollectionState';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
|
|
@@ -24,12 +24,28 @@ function $481a240e3d51b276$export$29efd034f1d79f81(props) {
|
|
|
24
24
|
let draggedKey = (0, $ijIvR$react.useRef)(null);
|
|
25
25
|
let getKeys = (key)=>{
|
|
26
26
|
// The clicked item is always added to the drag. If it is selected, then all of the
|
|
27
|
-
// other selected items are also dragged. If it is not selected,
|
|
27
|
+
// other selected items are also dragged. If it is not selected, then only the clicked
|
|
28
28
|
// item is dragged. This matches native macOS behavior.
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
// Additionally, we filter out any keys that are children of any of the other selected keys
|
|
30
|
+
let keys = new Set();
|
|
31
|
+
if (selectionManager.isSelected(key)) for (let currentKey of selectionManager.selectedKeys){
|
|
32
|
+
let node = collection.getItem(currentKey);
|
|
33
|
+
if (node) {
|
|
34
|
+
let isChild = false;
|
|
35
|
+
let parentKey = node.parentKey;
|
|
36
|
+
while(parentKey != null){
|
|
37
|
+
// eslint-disable-next-line max-depth
|
|
38
|
+
if (selectionManager.selectedKeys.has(parentKey)) {
|
|
39
|
+
isChild = true;
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
let parentNode = collection.getItem(parentKey);
|
|
43
|
+
parentKey = parentNode ? parentNode.parentKey : null;
|
|
44
|
+
}
|
|
45
|
+
if (!isChild) keys.add(currentKey);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
else keys.add(key);
|
|
33
49
|
return keys;
|
|
34
50
|
};
|
|
35
51
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;AA+CM,SAAS,0CAA4B,KAAsC;IAChF,IAAI,YACF,QAAQ,cACR,UAAU,cACV,UAAU,oBACV,gBAAgB,eAChB,WAAW,cACX,UAAU,aACV,SAAS,WACT,OAAO,4BACP,wBAAwB,EACzB,GAAG;IACJ,IAAI,GAAG,YAAY,GAAG,CAAA,GAAA,qBAAO,EAAE;IAC/B,IAAI,eAAe,CAAA,GAAA,mBAAK,EAAE,IAAI;IAC9B,IAAI,aAAa,CAAA,GAAA,mBAAK,EAAc;IACpC,IAAI,UAAU,CAAC;QACb,mFAAmF;QACnF,
|
|
1
|
+
{"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;AA+CM,SAAS,0CAA4B,KAAsC;IAChF,IAAI,YACF,QAAQ,cACR,UAAU,cACV,UAAU,oB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,OAAO,gBAAgB,YACzB,YAAY;gBACV,GAAG,KAAK;sBACR;YACF;QAEJ;QACA,UAAS,KAAK;YACZ,IAAI,OAAO,eAAe,YACxB,WAAW;gBACT,GAAG,KAAK;gBACR,MAAM,aAAa,OAAO;YAC5B;QAEJ;QACA,SAAQ,KAAK;YACX,IAAI,cACF,UAAU,EACX,GAAG;YAEJ,IAAI,OAAO,cAAc,YACvB,UAAU;gBACR,GAAG,KAAK;gBACR,MAAM,aAAa,OAAO;4BAC1B;YACF;YAGF,aAAa,OAAO,GAAG,IAAI;YAC3B,WAAW,OAAO,GAAG;YACrB,YAAY;QACd;IACF;AACF","sources":["packages/@react-stately/dnd/src/useDraggableCollectionState.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 {Collection, DraggableCollectionEndEvent, DraggableCollectionProps, DragItem, DragMoveEvent, DragPreviewRenderer, DragStartEvent, DropOperation, Key, Node, RefObject} from '@react-types/shared';\nimport {MultipleSelectionManager} from '@react-stately/selection';\nimport {useRef, useState} from 'react';\n\nexport interface DraggableCollectionStateOptions extends DraggableCollectionProps {\n /** A collection of items. */\n collection: Collection<Node<unknown>>,\n /** An interface for reading and updating multiple selection state. */\n selectionManager: MultipleSelectionManager,\n /** Whether the drag events should be disabled. */\n isDisabled?: boolean\n}\n\nexport interface DraggableCollectionState {\n /** A collection of items. */\n collection: Collection<Node<unknown>>,\n /** An interface for reading and updating multiple selection state. */\n selectionManager: MultipleSelectionManager,\n /** The key of the item that initiated a drag. */\n draggedKey: Key | null,\n /** The keys of the items that are currently being dragged. */\n draggingKeys: Set<Key>,\n /** Whether drag events are disabled. */\n isDisabled?: boolean,\n /** Returns whether the given key is currently being dragged. */\n isDragging(key: Key): boolean,\n /** Returns the keys of the items that will be dragged with the given key (e.g. selected items). */\n getKeysForDrag(key: Key): Set<Key>,\n /** Returns the items to drag for the given key. */\n getItems(key: Key): DragItem[],\n /** The ref of the element that will be rendered as the drag preview while dragging. */\n preview?: RefObject<DragPreviewRenderer | null>,\n /** Function that returns the drop operations that are allowed for the dragged items. If not provided, all drop operations are allowed. */\n getAllowedDropOperations?: () => DropOperation[],\n /** Begins a drag for the given key. This triggers the onDragStart event. */\n startDrag(key: Key, event: DragStartEvent): void,\n /** Triggers an onDragMove event. */\n moveDrag(event: DragMoveEvent): void,\n /** Ends the current drag, and emits an onDragEnd event. */\n endDrag(event: DraggableCollectionEndEvent): void\n}\n\n/**\n * Manages state for a draggable collection.\n */\nexport function useDraggableCollectionState(props: DraggableCollectionStateOptions): DraggableCollectionState {\n let {\n getItems,\n isDisabled,\n collection,\n selectionManager,\n onDragStart,\n onDragMove,\n onDragEnd,\n preview,\n getAllowedDropOperations\n } = props;\n let [, setDragging] = useState(false);\n let draggingKeys = useRef(new Set<Key>());\n let draggedKey = useRef<Key | null>(null);\n let getKeys = (key: Key) => {\n // The clicked item is always added to the drag. If it is selected, then all of the\n // other selected items are also dragged. If it is not selected, then only the clicked\n // item is dragged. This matches native macOS behavior.\n // Additionally, we filter out any keys that are children of any of the other selected keys\n let keys = new Set<Key>();\n if (selectionManager.isSelected(key)) {\n for (let currentKey of selectionManager.selectedKeys) {\n let node = collection.getItem(currentKey);\n if (node) {\n let isChild = false;\n let parentKey = node.parentKey;\n while (parentKey != null) {\n // eslint-disable-next-line max-depth\n if (selectionManager.selectedKeys.has(parentKey)) {\n isChild = true;\n break;\n }\n let parentNode = collection.getItem(parentKey);\n parentKey = parentNode ? parentNode.parentKey : null;\n }\n\n if (!isChild) {\n keys.add(currentKey);\n }\n }\n }\n } else {\n keys.add(key);\n }\n\n return keys;\n };\n\n return {\n collection,\n selectionManager,\n get draggedKey() {\n return draggedKey.current;\n },\n get draggingKeys() {\n return draggingKeys.current;\n },\n isDragging(key) {\n return draggingKeys.current.has(key);\n },\n getKeysForDrag: getKeys,\n getItems(key) {\n return getItems(getKeys(key));\n },\n isDisabled,\n preview,\n getAllowedDropOperations,\n startDrag(key, event) {\n let keys = getKeys(key);\n draggingKeys.current = keys;\n draggedKey.current = key;\n selectionManager.setFocused(false);\n setDragging(true);\n if (typeof onDragStart === 'function') {\n onDragStart({\n ...event,\n keys\n });\n }\n },\n moveDrag(event) {\n if (typeof onDragMove === 'function') {\n onDragMove({\n ...event,\n keys: draggingKeys.current\n });\n }\n },\n endDrag(event) {\n let {\n isInternal\n } = event;\n\n if (typeof onDragEnd === 'function') {\n onDragEnd({\n ...event,\n keys: draggingKeys.current,\n isInternal\n });\n }\n\n draggingKeys.current = new Set();\n draggedKey.current = null;\n setDragging(false);\n }\n };\n}\n"],"names":[],"version":3,"file":"useDraggableCollectionState.main.js.map"}
|
|
@@ -18,12 +18,28 @@ function $b45bbbaf0c3785df$export$29efd034f1d79f81(props) {
|
|
|
18
18
|
let draggedKey = (0, $8rdZD$useRef)(null);
|
|
19
19
|
let getKeys = (key)=>{
|
|
20
20
|
// The clicked item is always added to the drag. If it is selected, then all of the
|
|
21
|
-
// other selected items are also dragged. If it is not selected,
|
|
21
|
+
// other selected items are also dragged. If it is not selected, then only the clicked
|
|
22
22
|
// item is dragged. This matches native macOS behavior.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
// Additionally, we filter out any keys that are children of any of the other selected keys
|
|
24
|
+
let keys = new Set();
|
|
25
|
+
if (selectionManager.isSelected(key)) for (let currentKey of selectionManager.selectedKeys){
|
|
26
|
+
let node = collection.getItem(currentKey);
|
|
27
|
+
if (node) {
|
|
28
|
+
let isChild = false;
|
|
29
|
+
let parentKey = node.parentKey;
|
|
30
|
+
while(parentKey != null){
|
|
31
|
+
// eslint-disable-next-line max-depth
|
|
32
|
+
if (selectionManager.selectedKeys.has(parentKey)) {
|
|
33
|
+
isChild = true;
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
let parentNode = collection.getItem(parentKey);
|
|
37
|
+
parentKey = parentNode ? parentNode.parentKey : null;
|
|
38
|
+
}
|
|
39
|
+
if (!isChild) keys.add(currentKey);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else keys.add(key);
|
|
27
43
|
return keys;
|
|
28
44
|
};
|
|
29
45
|
return {
|
|
@@ -18,12 +18,28 @@ function $b45bbbaf0c3785df$export$29efd034f1d79f81(props) {
|
|
|
18
18
|
let draggedKey = (0, $8rdZD$useRef)(null);
|
|
19
19
|
let getKeys = (key)=>{
|
|
20
20
|
// The clicked item is always added to the drag. If it is selected, then all of the
|
|
21
|
-
// other selected items are also dragged. If it is not selected,
|
|
21
|
+
// other selected items are also dragged. If it is not selected, then only the clicked
|
|
22
22
|
// item is dragged. This matches native macOS behavior.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
// Additionally, we filter out any keys that are children of any of the other selected keys
|
|
24
|
+
let keys = new Set();
|
|
25
|
+
if (selectionManager.isSelected(key)) for (let currentKey of selectionManager.selectedKeys){
|
|
26
|
+
let node = collection.getItem(currentKey);
|
|
27
|
+
if (node) {
|
|
28
|
+
let isChild = false;
|
|
29
|
+
let parentKey = node.parentKey;
|
|
30
|
+
while(parentKey != null){
|
|
31
|
+
// eslint-disable-next-line max-depth
|
|
32
|
+
if (selectionManager.selectedKeys.has(parentKey)) {
|
|
33
|
+
isChild = true;
|
|
34
|
+
break;
|
|
35
|
+
}
|
|
36
|
+
let parentNode = collection.getItem(parentKey);
|
|
37
|
+
parentKey = parentNode ? parentNode.parentKey : null;
|
|
38
|
+
}
|
|
39
|
+
if (!isChild) keys.add(currentKey);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else keys.add(key);
|
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aAAa,WAAW,OAAO,CAAC;oBACpC,YAAY,aAAa,WAAW,SAAS,GAAG;gBAClD;gBAEA,IAAI,CAAC,SACH,KAAK,GAAG,CAAC;YAEb;QACF;aAEA,KAAK,GAAG,CAAC;QAGX,OAAO;IACT;IAEA,OAAO;oBACL;0BACA;QACA,IAAI,cAAa;YACf,OAAO,WAAW,OAAO;QAC3B;QACA,IAAI,gBAAe;YACjB,OAAO,aAAa,OAAO;QAC7B;QACA,YAAW,GAAG;YACZ,OAAO,aAAa,OAAO,CAAC,GAAG,CAAC;QAClC;QACA,gBAAgB;QAChB,UAAS,GAAG;YACV,OAAO,SAAS,QAAQ;QAC1B;oBACA;iBACA;kCACA;QACA,WAAU,GAAG,EAAE,KAAK;YAClB,IAAI,OAAO,QAAQ;YACnB,aAAa,OAAO,GAAG;YACvB,WAAW,OAAO,GAAG;YACrB,iBAAiB,UAAU,CAAC;YAC5B,YAAY;YACZ,IAAI,OAAO,gBAAgB,YACzB,YAAY;gBACV,GAAG,KAAK;sBACR;YACF;QAEJ;QACA,UAAS,KAAK;YACZ,IAAI,OAAO,eAAe,YACxB,WAAW;gBACT,GAAG,KAAK;gBACR,MAAM,aAAa,OAAO;YAC5B;QAEJ;QACA,SAAQ,KAAK;YACX,IAAI,cACF,UAAU,EACX,GAAG;YAEJ,IAAI,OAAO,cAAc,YACvB,UAAU;gBACR,GAAG,KAAK;gBACR,MAAM,aAAa,OAAO;4BAC1B;YACF;YAGF,aAAa,OAAO,GAAG,IAAI;YAC3B,WAAW,OAAO,GAAG;YACrB,YAAY;QACd;IACF;AACF","sources":["packages/@react-stately/dnd/src/useDraggableCollectionState.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 {Collection, DraggableCollectionEndEvent, DraggableCollectionProps, DragItem, DragMoveEvent, DragPreviewRenderer, DragStartEvent, DropOperation, Key, Node, RefObject} from '@react-types/shared';\nimport {MultipleSelectionManager} from '@react-stately/selection';\nimport {useRef, useState} from 'react';\n\nexport interface DraggableCollectionStateOptions extends DraggableCollectionProps {\n /** A collection of items. */\n collection: Collection<Node<unknown>>,\n /** An interface for reading and updating multiple selection state. */\n selectionManager: MultipleSelectionManager,\n /** Whether the drag events should be disabled. */\n isDisabled?: boolean\n}\n\nexport interface DraggableCollectionState {\n /** A collection of items. */\n collection: Collection<Node<unknown>>,\n /** An interface for reading and updating multiple selection state. */\n selectionManager: MultipleSelectionManager,\n /** The key of the item that initiated a drag. */\n draggedKey: Key | null,\n /** The keys of the items that are currently being dragged. */\n draggingKeys: Set<Key>,\n /** Whether drag events are disabled. */\n isDisabled?: boolean,\n /** Returns whether the given key is currently being dragged. */\n isDragging(key: Key): boolean,\n /** Returns the keys of the items that will be dragged with the given key (e.g. selected items). */\n getKeysForDrag(key: Key): Set<Key>,\n /** Returns the items to drag for the given key. */\n getItems(key: Key): DragItem[],\n /** The ref of the element that will be rendered as the drag preview while dragging. */\n preview?: RefObject<DragPreviewRenderer | null>,\n /** Function that returns the drop operations that are allowed for the dragged items. If not provided, all drop operations are allowed. */\n getAllowedDropOperations?: () => DropOperation[],\n /** Begins a drag for the given key. This triggers the onDragStart event. */\n startDrag(key: Key, event: DragStartEvent): void,\n /** Triggers an onDragMove event. */\n moveDrag(event: DragMoveEvent): void,\n /** Ends the current drag, and emits an onDragEnd event. */\n endDrag(event: DraggableCollectionEndEvent): void\n}\n\n/**\n * Manages state for a draggable collection.\n */\nexport function useDraggableCollectionState(props: DraggableCollectionStateOptions): DraggableCollectionState {\n let {\n getItems,\n isDisabled,\n collection,\n selectionManager,\n onDragStart,\n onDragMove,\n onDragEnd,\n preview,\n getAllowedDropOperations\n } = props;\n let [, setDragging] = useState(false);\n let draggingKeys = useRef(new Set<Key>());\n let draggedKey = useRef<Key | null>(null);\n let getKeys = (key: Key) => {\n // The clicked item is always added to the drag. If it is selected, then all of the\n // other selected items are also dragged. If it is not selected, then only the clicked\n // item is dragged. This matches native macOS behavior.\n // Additionally, we filter out any keys that are children of any of the other selected keys\n let keys = new Set<Key>();\n if (selectionManager.isSelected(key)) {\n for (let currentKey of selectionManager.selectedKeys) {\n let node = collection.getItem(currentKey);\n if (node) {\n let isChild = false;\n let parentKey = node.parentKey;\n while (parentKey != null) {\n // eslint-disable-next-line max-depth\n if (selectionManager.selectedKeys.has(parentKey)) {\n isChild = true;\n break;\n }\n let parentNode = collection.getItem(parentKey);\n parentKey = parentNode ? parentNode.parentKey : null;\n }\n\n if (!isChild) {\n keys.add(currentKey);\n }\n }\n }\n } else {\n keys.add(key);\n }\n\n return keys;\n };\n\n return {\n collection,\n selectionManager,\n get draggedKey() {\n return draggedKey.current;\n },\n get draggingKeys() {\n return draggingKeys.current;\n },\n isDragging(key) {\n return draggingKeys.current.has(key);\n },\n getKeysForDrag: getKeys,\n getItems(key) {\n return getItems(getKeys(key));\n },\n isDisabled,\n preview,\n getAllowedDropOperations,\n startDrag(key, event) {\n let keys = getKeys(key);\n draggingKeys.current = keys;\n draggedKey.current = key;\n selectionManager.setFocused(false);\n setDragging(true);\n if (typeof onDragStart === 'function') {\n onDragStart({\n ...event,\n keys\n });\n }\n },\n moveDrag(event) {\n if (typeof onDragMove === 'function') {\n onDragMove({\n ...event,\n keys: draggingKeys.current\n });\n }\n },\n endDrag(event) {\n let {\n isInternal\n } = event;\n\n if (typeof onDragEnd === 'function') {\n onDragEnd({\n ...event,\n keys: draggingKeys.current,\n isInternal\n });\n }\n\n draggingKeys.current = new Set();\n draggedKey.current = null;\n setDragging(false);\n }\n };\n}\n"],"names":[],"version":3,"file":"useDraggableCollectionState.module.js.map"}
|
|
@@ -18,22 +18,22 @@ $parcel$export(module.exports, "useDroppableCollectionState", () => $6ce4cbfbe5e
|
|
|
18
18
|
* governing permissions and limitations under the License.
|
|
19
19
|
*/
|
|
20
20
|
function $6ce4cbfbe5e354f1$export$926850f6ecef79d0(props) {
|
|
21
|
-
let { acceptedDragTypes: acceptedDragTypes = 'all', isDisabled: isDisabled, onInsert: onInsert, onRootDrop: onRootDrop, onItemDrop: onItemDrop, onReorder: onReorder, shouldAcceptItemDrop: shouldAcceptItemDrop, collection: collection, selectionManager: selectionManager, onDropEnter: onDropEnter, getDropOperation: getDropOperation, onDrop: onDrop } = props;
|
|
21
|
+
let { acceptedDragTypes: acceptedDragTypes = 'all', isDisabled: isDisabled, onInsert: onInsert, onRootDrop: onRootDrop, onItemDrop: onItemDrop, onReorder: onReorder, onMove: onMove, shouldAcceptItemDrop: shouldAcceptItemDrop, collection: collection, selectionManager: selectionManager, onDropEnter: onDropEnter, getDropOperation: getDropOperation, onDrop: onDrop } = props;
|
|
22
22
|
let [target, setTarget] = (0, $ax21c$react.useState)(null);
|
|
23
23
|
let targetRef = (0, $ax21c$react.useRef)(null);
|
|
24
24
|
let getOppositeTarget = (target)=>{
|
|
25
25
|
if (target.dropPosition === 'before') {
|
|
26
|
-
let
|
|
27
|
-
return
|
|
26
|
+
let node = collection.getItem(target.key);
|
|
27
|
+
return node && node.prevKey != null ? {
|
|
28
28
|
type: 'item',
|
|
29
|
-
key:
|
|
29
|
+
key: node.prevKey,
|
|
30
30
|
dropPosition: 'after'
|
|
31
31
|
} : null;
|
|
32
32
|
} else if (target.dropPosition === 'after') {
|
|
33
|
-
let
|
|
34
|
-
return
|
|
33
|
+
let node = collection.getItem(target.key);
|
|
34
|
+
return node && node.nextKey != null ? {
|
|
35
35
|
type: 'item',
|
|
36
|
-
key:
|
|
36
|
+
key: node.nextKey,
|
|
37
37
|
dropPosition: 'before'
|
|
38
38
|
} : null;
|
|
39
39
|
}
|
|
@@ -44,12 +44,14 @@ function $6ce4cbfbe5e354f1$export$926850f6ecef79d0(props) {
|
|
|
44
44
|
if (isDisabled || !target) return 'cancel';
|
|
45
45
|
if (acceptedDragTypes === 'all' || acceptedDragTypes.some((type)=>types.has(type))) {
|
|
46
46
|
let isValidInsert = onInsert && target.type === 'item' && !isInternal && (target.dropPosition === 'before' || target.dropPosition === 'after');
|
|
47
|
-
let isValidReorder = onReorder && target.type === 'item' && isInternal && (target.dropPosition === 'before' || target.dropPosition === 'after');
|
|
47
|
+
let isValidReorder = onReorder && target.type === 'item' && isInternal && (target.dropPosition === 'before' || target.dropPosition === 'after') && $6ce4cbfbe5e354f1$var$isDraggingWithinParent(collection, target, draggingKeys);
|
|
48
|
+
let isItemDropAllowed = target.type !== 'item' || target.dropPosition !== 'on' || !shouldAcceptItemDrop || shouldAcceptItemDrop(target, types);
|
|
49
|
+
let isValidMove = onMove && target.type === 'item' && isInternal && isItemDropAllowed;
|
|
48
50
|
// Feedback was that internal root drop was weird so preventing that from happening
|
|
49
51
|
let isValidRootDrop = onRootDrop && target.type === 'root' && !isInternal;
|
|
50
52
|
// Automatically prevent items (i.e. folders) from being dropped on themselves.
|
|
51
|
-
let isValidOnItemDrop = onItemDrop && target.type === 'item' && target.dropPosition === 'on' && !(isInternal && target.key != null && draggingKeys.has(target.key)) &&
|
|
52
|
-
if (onDrop || isValidInsert || isValidReorder || isValidRootDrop || isValidOnItemDrop) {
|
|
53
|
+
let isValidOnItemDrop = onItemDrop && target.type === 'item' && target.dropPosition === 'on' && !(isInternal && target.key != null && draggingKeys.has(target.key)) && isItemDropAllowed;
|
|
54
|
+
if (onDrop || isValidInsert || isValidReorder || isValidMove || isValidRootDrop || isValidOnItemDrop) {
|
|
53
55
|
if (getDropOperation) return getDropOperation(target, types, allowedOperations);
|
|
54
56
|
else return allowedOperations[0];
|
|
55
57
|
}
|
|
@@ -57,6 +59,7 @@ function $6ce4cbfbe5e354f1$export$926850f6ecef79d0(props) {
|
|
|
57
59
|
return 'cancel';
|
|
58
60
|
}, [
|
|
59
61
|
isDisabled,
|
|
62
|
+
collection,
|
|
60
63
|
acceptedDragTypes,
|
|
61
64
|
getDropOperation,
|
|
62
65
|
onInsert,
|
|
@@ -64,6 +67,7 @@ function $6ce4cbfbe5e354f1$export$926850f6ecef79d0(props) {
|
|
|
64
67
|
onItemDrop,
|
|
65
68
|
shouldAcceptItemDrop,
|
|
66
69
|
onReorder,
|
|
70
|
+
onMove,
|
|
67
71
|
onDrop
|
|
68
72
|
]);
|
|
69
73
|
return {
|
|
@@ -111,6 +115,14 @@ function $6ce4cbfbe5e354f1$var$isEqualDropTarget(a, b) {
|
|
|
111
115
|
return (b === null || b === void 0 ? void 0 : b.type) === 'item' && (b === null || b === void 0 ? void 0 : b.key) === a.key && (b === null || b === void 0 ? void 0 : b.dropPosition) === a.dropPosition;
|
|
112
116
|
}
|
|
113
117
|
}
|
|
118
|
+
function $6ce4cbfbe5e354f1$var$isDraggingWithinParent(collection, target, draggingKeys) {
|
|
119
|
+
let targetNode = collection.getItem(target.key);
|
|
120
|
+
for (let key of draggingKeys){
|
|
121
|
+
let node = collection.getItem(key);
|
|
122
|
+
if ((node === null || node === void 0 ? void 0 : node.parentKey) !== (targetNode === null || targetNode === void 0 ? void 0 : targetNode.parentKey)) return false;
|
|
123
|
+
}
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
114
126
|
|
|
115
127
|
|
|
116
128
|
//# sourceMappingURL=useDroppableCollectionState.main.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;AA2CM,SAAS,0CAA4B,KAAsC;IAChF,IAAI,qBACF,oBAAoB,mBACpB,UAAU,YACV,QAAQ,cACR,UAAU,cACV,UAAU,aACV,SAAS,wBACT,oBAAoB,cACpB,UAAU,oBACV,gBAAgB,eAChB,WAAW,oBACX,gBAAgB,UAChB,MAAM,EACP,GAAG;IACJ,IAAI,CAAC,QAAQ,UAAU,GAAG,CAAA,GAAA,qBAAO,EAAqB;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,OAAO,CAAA,cAAA,wBAAA,EAAG,IAAI,MAAK;QACrB,KAAK;YACH,OAAO,CAAA,cAAA,wBAAA,EAAG,IAAI,MAAK,UAAU,CAAA,cAAA,wBAAA,EAAG,GAAG,MAAK,EAAE,GAAG,IAAI,CAAA,cAAA,wBAAA,EAAG,YAAY,MAAK,EAAE,YAAY;IACvF;AACF","sources":["packages/@react-stately/dnd/src/useDroppableCollectionState.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 {Collection, DragTypes, DropOperation, DroppableCollectionProps, DropTarget, ItemDropTarget, Key, Node} from '@react-types/shared';\nimport {MultipleSelectionManager} from '@react-stately/selection';\nimport {useCallback, useRef, useState} from 'react';\n\ninterface DropOperationEvent {\n target: DropTarget,\n types: DragTypes,\n allowedOperations: DropOperation[],\n isInternal: boolean,\n draggingKeys: Set<Key>\n}\n\nexport interface DroppableCollectionStateOptions extends Omit<DroppableCollectionProps, 'onDropMove' | 'onDropActivate'> {\n /** A collection of items. */\n collection: Collection<Node<unknown>>,\n /** An interface for reading and updating multiple selection state. */\n selectionManager: MultipleSelectionManager,\n /** Whether the drop events should be disabled. */\n isDisabled?: boolean\n}\n\nexport interface DroppableCollectionState {\n /** A collection of items. */\n collection: Collection<Node<unknown>>,\n /** An interface for reading and updating multiple selection state. */\n selectionManager: MultipleSelectionManager,\n /** The current drop target. */\n target: DropTarget | null,\n /** Whether drop events are disabled. */\n isDisabled?: boolean,\n /** Sets the current drop target. */\n setTarget(target: DropTarget | null): void,\n /** Returns whether the given target is equivalent to the current drop target. */\n isDropTarget(target: DropTarget | null): boolean,\n /** Returns the drop operation for the given parameters. */\n getDropOperation(e: DropOperationEvent): DropOperation\n}\n\n/**\n * Manages state for a droppable collection.\n */\nexport function useDroppableCollectionState(props: DroppableCollectionStateOptions): DroppableCollectionState {\n let {\n acceptedDragTypes = 'all',\n isDisabled,\n onInsert,\n onRootDrop,\n onItemDrop,\n onReorder,\n shouldAcceptItemDrop,\n collection,\n selectionManager,\n onDropEnter,\n getDropOperation,\n onDrop\n } = props;\n let [target, setTarget] = useState<DropTarget | null>(null);\n let targetRef = useRef<DropTarget | null>(null);\n\n let getOppositeTarget = (target: ItemDropTarget): ItemDropTarget | null => {\n if (target.dropPosition === 'before') {\n let key = collection.getKeyBefore(target.key);\n return key != null ? {type: 'item', key, dropPosition: 'after'} : null;\n } else if (target.dropPosition === 'after') {\n let key = collection.getKeyAfter(target.key);\n return key != null ? {type: 'item', key, dropPosition: 'before'} : null;\n }\n return null;\n };\n\n let defaultGetDropOperation = useCallback((e: DropOperationEvent) => {\n let {\n target,\n types,\n allowedOperations,\n isInternal,\n draggingKeys\n } = e;\n\n if (isDisabled || !target) {\n return 'cancel';\n }\n\n if (acceptedDragTypes === 'all' || acceptedDragTypes.some(type => types.has(type))) {\n let isValidInsert = onInsert && target.type === 'item' && !isInternal && (target.dropPosition === 'before' || target.dropPosition === 'after');\n let isValidReorder = onReorder && target.type === 'item' && isInternal && (target.dropPosition === 'before' || target.dropPosition === 'after');\n // Feedback was that internal root drop was weird so preventing that from happening\n let isValidRootDrop = onRootDrop && target.type === 'root' && !isInternal;\n // Automatically prevent items (i.e. folders) from being dropped on themselves.\n let isValidOnItemDrop = onItemDrop && target.type === 'item' && target.dropPosition === 'on' && !(isInternal && target.key != null && draggingKeys.has(target.key)) && (!shouldAcceptItemDrop || shouldAcceptItemDrop(target, types));\n\n if (onDrop || isValidInsert || isValidReorder || isValidRootDrop || isValidOnItemDrop) {\n if (getDropOperation) {\n return getDropOperation(target, types, allowedOperations);\n } else {\n return allowedOperations[0];\n }\n }\n }\n\n return 'cancel';\n }, [isDisabled, acceptedDragTypes, getDropOperation, onInsert, onRootDrop, onItemDrop, shouldAcceptItemDrop, onReorder, onDrop]);\n\n return {\n collection,\n selectionManager,\n isDisabled,\n target,\n setTarget(newTarget) {\n if (this.isDropTarget(newTarget)) {\n return;\n }\n\n let target = targetRef.current;\n if (target && typeof props.onDropExit === 'function') {\n props.onDropExit({\n type: 'dropexit',\n x: 0, // todo\n y: 0,\n target\n });\n }\n\n if (newTarget && typeof onDropEnter === 'function') {\n onDropEnter({\n type: 'dropenter',\n x: 0, // todo\n y: 0,\n target: newTarget\n });\n }\n\n targetRef.current = newTarget ?? null;\n setTarget(newTarget ?? null);\n },\n isDropTarget(dropTarget) {\n let target = targetRef.current;\n if (!target || !dropTarget) {\n return false;\n }\n if (isEqualDropTarget(dropTarget, target)) {\n return true;\n }\n\n // Check if the targets point at the same point between two items, one referring before, and the other after.\n if (\n dropTarget?.type === 'item' &&\n target?.type === 'item' &&\n dropTarget.key !== target.key &&\n dropTarget.dropPosition !== target.dropPosition &&\n dropTarget.dropPosition !== 'on' &&\n target.dropPosition !== 'on'\n ) {\n return isEqualDropTarget(getOppositeTarget(dropTarget), target) ||\n isEqualDropTarget(dropTarget, getOppositeTarget(target));\n }\n\n return false;\n },\n getDropOperation(e) {\n return defaultGetDropOperation(e);\n }\n };\n}\n\nfunction isEqualDropTarget(a?: DropTarget | null, b?: DropTarget | null) {\n if (!a) {\n return !b;\n }\n\n switch (a.type) {\n case 'root':\n return b?.type === 'root';\n case 'item':\n return b?.type === 'item' && b?.key === a.key && b?.dropPosition === a.dropPosition;\n }\n}\n"],"names":[],"version":3,"file":"useDroppableCollectionState.main.js.map"}
|
|
1
|
+
{"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;AA2CM,SAAS,0CAA4B,KAAsC;IAChF,IAAI,qBACF,oBAAoB,mBACpB,UAAU,YACV,QAAQ,cACR,UAAU,cACV,UAAU,aACV,SAAS,UACT,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I,MAAK,UACjB,WAAW,GAAG,KAAK,OAAO,GAAG,IAC7B,WAAW,YAAY,KAAK,OAAO,YAAY,IAC/C,WAAW,YAAY,KAAK,QAC5B,OAAO,YAAY,KAAK,MAExB,OAAO,wCAAkB,kBAAkB,aAAa,WACtD,wCAAkB,YAAY,kBAAkB;YAGpD,OAAO;QACT;QACA,kBAAiB,CAAC;YAChB,OAAO,wBAAwB;QACjC;IACF;AACF;AAEA,SAAS,wCAAkB,CAAqB,EAAE,CAAqB;IACrE,IAAI,CAAC,GACH,OAAO,CAAC;IAGV,OAAQ,EAAE,IAAI;QACZ,KAAK;YACH,OAAO,CAAA,cAAA,wBAAA,EAAG,IAAI,MAAK;QACrB,KAAK;YACH,OAAO,CAAA,cAAA,wBAAA,EAAG,IAAI,MAAK,UAAU,CAAA,cAAA,wBAAA,EAAG,GAAG,MAAK,EAAE,GAAG,IAAI,CAAA,cAAA,wBAAA,EAAG,YAAY,MAAK,EAAE,YAAY;IACvF;AACF;AAEA,SAAS,6CAAuB,UAAqC,EAAE,MAAsB,EAAE,YAAsB;IACnH,IAAI,aAAa,WAAW,OAAO,CAAC,OAAO,GAAG;IAE9C,KAAK,IAAI,OAAO,aAAc;QAC5B,IAAI,OAAO,WAAW,OAAO,CAAC;QAC9B,IAAI,CAAA,iBAAA,2BAAA,KAAM,SAAS,OAAK,uBAAA,iCAAA,WAAY,SAAS,GAC3C,OAAO;IAEX;IAEA,OAAO;AACT","sources":["packages/@react-stately/dnd/src/useDroppableCollectionState.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 {Collection, DragTypes, DropOperation, DroppableCollectionProps, DropTarget, ItemDropTarget, Key, Node} from '@react-types/shared';\nimport {MultipleSelectionManager} from '@react-stately/selection';\nimport {useCallback, useRef, useState} from 'react';\n\ninterface DropOperationEvent {\n target: DropTarget,\n types: DragTypes,\n allowedOperations: DropOperation[],\n isInternal: boolean,\n draggingKeys: Set<Key>\n}\n\nexport interface DroppableCollectionStateOptions extends Omit<DroppableCollectionProps, 'onDropMove' | 'onDropActivate'> {\n /** A collection of items. */\n collection: Collection<Node<unknown>>,\n /** An interface for reading and updating multiple selection state. */\n selectionManager: MultipleSelectionManager,\n /** Whether the drop events should be disabled. */\n isDisabled?: boolean\n}\n\nexport interface DroppableCollectionState {\n /** A collection of items. */\n collection: Collection<Node<unknown>>,\n /** An interface for reading and updating multiple selection state. */\n selectionManager: MultipleSelectionManager,\n /** The current drop target. */\n target: DropTarget | null,\n /** Whether drop events are disabled. */\n isDisabled?: boolean,\n /** Sets the current drop target. */\n setTarget(target: DropTarget | null): void,\n /** Returns whether the given target is equivalent to the current drop target. */\n isDropTarget(target: DropTarget | null): boolean,\n /** Returns the drop operation for the given parameters. */\n getDropOperation(e: DropOperationEvent): DropOperation\n}\n\n/**\n * Manages state for a droppable collection.\n */\nexport function useDroppableCollectionState(props: DroppableCollectionStateOptions): DroppableCollectionState {\n let {\n acceptedDragTypes = 'all',\n isDisabled,\n onInsert,\n onRootDrop,\n onItemDrop,\n onReorder,\n onMove,\n shouldAcceptItemDrop,\n collection,\n selectionManager,\n onDropEnter,\n getDropOperation,\n onDrop\n } = props;\n let [target, setTarget] = useState<DropTarget | null>(null);\n let targetRef = useRef<DropTarget | null>(null);\n\n let getOppositeTarget = (target: ItemDropTarget): ItemDropTarget | null => {\n if (target.dropPosition === 'before') {\n let node = collection.getItem(target.key);\n return node && node.prevKey != null\n ? {type: 'item', key: node.prevKey, dropPosition: 'after'} \n : null;\n } else if (target.dropPosition === 'after') {\n let node = collection.getItem(target.key);\n return node && node.nextKey != null\n ? {type: 'item', key: node.nextKey, dropPosition: 'before'} \n : null;\n }\n return null;\n };\n\n let defaultGetDropOperation = useCallback((e: DropOperationEvent) => {\n let {\n target,\n types,\n allowedOperations,\n isInternal,\n draggingKeys\n } = e;\n\n if (isDisabled || !target) {\n return 'cancel';\n }\n\n if (acceptedDragTypes === 'all' || acceptedDragTypes.some(type => types.has(type))) {\n let isValidInsert = onInsert && target.type === 'item' && !isInternal && (target.dropPosition === 'before' || target.dropPosition === 'after');\n let isValidReorder = onReorder\n && target.type === 'item'\n && isInternal\n && (target.dropPosition === 'before' || target.dropPosition === 'after')\n && isDraggingWithinParent(collection, target, draggingKeys);\n\n let isItemDropAllowed = target.type !== 'item'\n || target.dropPosition !== 'on'\n || (!shouldAcceptItemDrop || shouldAcceptItemDrop(target, types));\n\n let isValidMove = onMove\n && target.type === 'item'\n && isInternal\n && isItemDropAllowed;\n\n // Feedback was that internal root drop was weird so preventing that from happening\n let isValidRootDrop = onRootDrop && target.type === 'root' && !isInternal;\n \n // Automatically prevent items (i.e. folders) from being dropped on themselves.\n let isValidOnItemDrop = onItemDrop \n && target.type === 'item' \n && target.dropPosition === 'on' \n && !(isInternal && target.key != null && draggingKeys.has(target.key)) \n && isItemDropAllowed;\n\n if (onDrop || isValidInsert || isValidReorder || isValidMove || isValidRootDrop || isValidOnItemDrop) {\n if (getDropOperation) {\n return getDropOperation(target, types, allowedOperations);\n } else {\n return allowedOperations[0];\n }\n }\n }\n\n return 'cancel';\n }, [isDisabled, collection, acceptedDragTypes, getDropOperation, onInsert, onRootDrop, onItemDrop, shouldAcceptItemDrop, onReorder, onMove, onDrop]);\n\n return {\n collection,\n selectionManager,\n isDisabled,\n target,\n setTarget(newTarget) {\n if (this.isDropTarget(newTarget)) {\n return;\n }\n\n let target = targetRef.current;\n if (target && typeof props.onDropExit === 'function') {\n props.onDropExit({\n type: 'dropexit',\n x: 0, // todo\n y: 0,\n target\n });\n }\n\n if (newTarget && typeof onDropEnter === 'function') {\n onDropEnter({\n type: 'dropenter',\n x: 0, // todo\n y: 0,\n target: newTarget\n });\n }\n\n targetRef.current = newTarget ?? null;\n setTarget(newTarget ?? null);\n },\n isDropTarget(dropTarget) {\n let target = targetRef.current;\n if (!target || !dropTarget) {\n return false;\n }\n if (isEqualDropTarget(dropTarget, target)) {\n return true;\n }\n\n // Check if the targets point at the same point between two items, one referring before, and the other after.\n if (\n dropTarget?.type === 'item' &&\n target?.type === 'item' &&\n dropTarget.key !== target.key &&\n dropTarget.dropPosition !== target.dropPosition &&\n dropTarget.dropPosition !== 'on' &&\n target.dropPosition !== 'on'\n ) {\n return isEqualDropTarget(getOppositeTarget(dropTarget), target) ||\n isEqualDropTarget(dropTarget, getOppositeTarget(target));\n }\n\n return false;\n },\n getDropOperation(e) {\n return defaultGetDropOperation(e);\n }\n };\n}\n\nfunction isEqualDropTarget(a?: DropTarget | null, b?: DropTarget | null) {\n if (!a) {\n return !b;\n }\n\n switch (a.type) {\n case 'root':\n return b?.type === 'root';\n case 'item':\n return b?.type === 'item' && b?.key === a.key && b?.dropPosition === a.dropPosition;\n }\n}\n\nfunction isDraggingWithinParent(collection: Collection<Node<unknown>>, target: ItemDropTarget, draggingKeys: Set<Key>) {\n let targetNode = collection.getItem(target.key);\n\n for (let key of draggingKeys) {\n let node = collection.getItem(key);\n if (node?.parentKey !== targetNode?.parentKey) {\n return false;\n }\n }\n\n return true;\n}\n"],"names":[],"version":3,"file":"useDroppableCollectionState.main.js.map"}
|
|
@@ -12,22 +12,22 @@ import {useState as $lyPoT$useState, useRef as $lyPoT$useRef, useCallback as $ly
|
|
|
12
12
|
* governing permissions and limitations under the License.
|
|
13
13
|
*/
|
|
14
14
|
function $e672e8bc247525d1$export$926850f6ecef79d0(props) {
|
|
15
|
-
let { acceptedDragTypes: acceptedDragTypes = 'all', isDisabled: isDisabled, onInsert: onInsert, onRootDrop: onRootDrop, onItemDrop: onItemDrop, onReorder: onReorder, shouldAcceptItemDrop: shouldAcceptItemDrop, collection: collection, selectionManager: selectionManager, onDropEnter: onDropEnter, getDropOperation: getDropOperation, onDrop: onDrop } = props;
|
|
15
|
+
let { acceptedDragTypes: acceptedDragTypes = 'all', isDisabled: isDisabled, onInsert: onInsert, onRootDrop: onRootDrop, onItemDrop: onItemDrop, onReorder: onReorder, onMove: onMove, shouldAcceptItemDrop: shouldAcceptItemDrop, collection: collection, selectionManager: selectionManager, onDropEnter: onDropEnter, getDropOperation: getDropOperation, onDrop: onDrop } = props;
|
|
16
16
|
let [target, setTarget] = (0, $lyPoT$useState)(null);
|
|
17
17
|
let targetRef = (0, $lyPoT$useRef)(null);
|
|
18
18
|
let getOppositeTarget = (target)=>{
|
|
19
19
|
if (target.dropPosition === 'before') {
|
|
20
|
-
let
|
|
21
|
-
return
|
|
20
|
+
let node = collection.getItem(target.key);
|
|
21
|
+
return node && node.prevKey != null ? {
|
|
22
22
|
type: 'item',
|
|
23
|
-
key:
|
|
23
|
+
key: node.prevKey,
|
|
24
24
|
dropPosition: 'after'
|
|
25
25
|
} : null;
|
|
26
26
|
} else if (target.dropPosition === 'after') {
|
|
27
|
-
let
|
|
28
|
-
return
|
|
27
|
+
let node = collection.getItem(target.key);
|
|
28
|
+
return node && node.nextKey != null ? {
|
|
29
29
|
type: 'item',
|
|
30
|
-
key:
|
|
30
|
+
key: node.nextKey,
|
|
31
31
|
dropPosition: 'before'
|
|
32
32
|
} : null;
|
|
33
33
|
}
|
|
@@ -38,12 +38,14 @@ function $e672e8bc247525d1$export$926850f6ecef79d0(props) {
|
|
|
38
38
|
if (isDisabled || !target) return 'cancel';
|
|
39
39
|
if (acceptedDragTypes === 'all' || acceptedDragTypes.some((type)=>types.has(type))) {
|
|
40
40
|
let isValidInsert = onInsert && target.type === 'item' && !isInternal && (target.dropPosition === 'before' || target.dropPosition === 'after');
|
|
41
|
-
let isValidReorder = onReorder && target.type === 'item' && isInternal && (target.dropPosition === 'before' || target.dropPosition === 'after');
|
|
41
|
+
let isValidReorder = onReorder && target.type === 'item' && isInternal && (target.dropPosition === 'before' || target.dropPosition === 'after') && $e672e8bc247525d1$var$isDraggingWithinParent(collection, target, draggingKeys);
|
|
42
|
+
let isItemDropAllowed = target.type !== 'item' || target.dropPosition !== 'on' || !shouldAcceptItemDrop || shouldAcceptItemDrop(target, types);
|
|
43
|
+
let isValidMove = onMove && target.type === 'item' && isInternal && isItemDropAllowed;
|
|
42
44
|
// Feedback was that internal root drop was weird so preventing that from happening
|
|
43
45
|
let isValidRootDrop = onRootDrop && target.type === 'root' && !isInternal;
|
|
44
46
|
// Automatically prevent items (i.e. folders) from being dropped on themselves.
|
|
45
|
-
let isValidOnItemDrop = onItemDrop && target.type === 'item' && target.dropPosition === 'on' && !(isInternal && target.key != null && draggingKeys.has(target.key)) &&
|
|
46
|
-
if (onDrop || isValidInsert || isValidReorder || isValidRootDrop || isValidOnItemDrop) {
|
|
47
|
+
let isValidOnItemDrop = onItemDrop && target.type === 'item' && target.dropPosition === 'on' && !(isInternal && target.key != null && draggingKeys.has(target.key)) && isItemDropAllowed;
|
|
48
|
+
if (onDrop || isValidInsert || isValidReorder || isValidMove || isValidRootDrop || isValidOnItemDrop) {
|
|
47
49
|
if (getDropOperation) return getDropOperation(target, types, allowedOperations);
|
|
48
50
|
else return allowedOperations[0];
|
|
49
51
|
}
|
|
@@ -51,6 +53,7 @@ function $e672e8bc247525d1$export$926850f6ecef79d0(props) {
|
|
|
51
53
|
return 'cancel';
|
|
52
54
|
}, [
|
|
53
55
|
isDisabled,
|
|
56
|
+
collection,
|
|
54
57
|
acceptedDragTypes,
|
|
55
58
|
getDropOperation,
|
|
56
59
|
onInsert,
|
|
@@ -58,6 +61,7 @@ function $e672e8bc247525d1$export$926850f6ecef79d0(props) {
|
|
|
58
61
|
onItemDrop,
|
|
59
62
|
shouldAcceptItemDrop,
|
|
60
63
|
onReorder,
|
|
64
|
+
onMove,
|
|
61
65
|
onDrop
|
|
62
66
|
]);
|
|
63
67
|
return {
|
|
@@ -105,6 +109,14 @@ function $e672e8bc247525d1$var$isEqualDropTarget(a, b) {
|
|
|
105
109
|
return (b === null || b === void 0 ? void 0 : b.type) === 'item' && (b === null || b === void 0 ? void 0 : b.key) === a.key && (b === null || b === void 0 ? void 0 : b.dropPosition) === a.dropPosition;
|
|
106
110
|
}
|
|
107
111
|
}
|
|
112
|
+
function $e672e8bc247525d1$var$isDraggingWithinParent(collection, target, draggingKeys) {
|
|
113
|
+
let targetNode = collection.getItem(target.key);
|
|
114
|
+
for (let key of draggingKeys){
|
|
115
|
+
let node = collection.getItem(key);
|
|
116
|
+
if ((node === null || node === void 0 ? void 0 : node.parentKey) !== (targetNode === null || targetNode === void 0 ? void 0 : targetNode.parentKey)) return false;
|
|
117
|
+
}
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
108
120
|
|
|
109
121
|
|
|
110
122
|
export {$e672e8bc247525d1$export$926850f6ecef79d0 as useDroppableCollectionState};
|
|
@@ -12,22 +12,22 @@ import {useState as $lyPoT$useState, useRef as $lyPoT$useRef, useCallback as $ly
|
|
|
12
12
|
* governing permissions and limitations under the License.
|
|
13
13
|
*/
|
|
14
14
|
function $e672e8bc247525d1$export$926850f6ecef79d0(props) {
|
|
15
|
-
let { acceptedDragTypes: acceptedDragTypes = 'all', isDisabled: isDisabled, onInsert: onInsert, onRootDrop: onRootDrop, onItemDrop: onItemDrop, onReorder: onReorder, shouldAcceptItemDrop: shouldAcceptItemDrop, collection: collection, selectionManager: selectionManager, onDropEnter: onDropEnter, getDropOperation: getDropOperation, onDrop: onDrop } = props;
|
|
15
|
+
let { acceptedDragTypes: acceptedDragTypes = 'all', isDisabled: isDisabled, onInsert: onInsert, onRootDrop: onRootDrop, onItemDrop: onItemDrop, onReorder: onReorder, onMove: onMove, shouldAcceptItemDrop: shouldAcceptItemDrop, collection: collection, selectionManager: selectionManager, onDropEnter: onDropEnter, getDropOperation: getDropOperation, onDrop: onDrop } = props;
|
|
16
16
|
let [target, setTarget] = (0, $lyPoT$useState)(null);
|
|
17
17
|
let targetRef = (0, $lyPoT$useRef)(null);
|
|
18
18
|
let getOppositeTarget = (target)=>{
|
|
19
19
|
if (target.dropPosition === 'before') {
|
|
20
|
-
let
|
|
21
|
-
return
|
|
20
|
+
let node = collection.getItem(target.key);
|
|
21
|
+
return node && node.prevKey != null ? {
|
|
22
22
|
type: 'item',
|
|
23
|
-
key:
|
|
23
|
+
key: node.prevKey,
|
|
24
24
|
dropPosition: 'after'
|
|
25
25
|
} : null;
|
|
26
26
|
} else if (target.dropPosition === 'after') {
|
|
27
|
-
let
|
|
28
|
-
return
|
|
27
|
+
let node = collection.getItem(target.key);
|
|
28
|
+
return node && node.nextKey != null ? {
|
|
29
29
|
type: 'item',
|
|
30
|
-
key:
|
|
30
|
+
key: node.nextKey,
|
|
31
31
|
dropPosition: 'before'
|
|
32
32
|
} : null;
|
|
33
33
|
}
|
|
@@ -38,12 +38,14 @@ function $e672e8bc247525d1$export$926850f6ecef79d0(props) {
|
|
|
38
38
|
if (isDisabled || !target) return 'cancel';
|
|
39
39
|
if (acceptedDragTypes === 'all' || acceptedDragTypes.some((type)=>types.has(type))) {
|
|
40
40
|
let isValidInsert = onInsert && target.type === 'item' && !isInternal && (target.dropPosition === 'before' || target.dropPosition === 'after');
|
|
41
|
-
let isValidReorder = onReorder && target.type === 'item' && isInternal && (target.dropPosition === 'before' || target.dropPosition === 'after');
|
|
41
|
+
let isValidReorder = onReorder && target.type === 'item' && isInternal && (target.dropPosition === 'before' || target.dropPosition === 'after') && $e672e8bc247525d1$var$isDraggingWithinParent(collection, target, draggingKeys);
|
|
42
|
+
let isItemDropAllowed = target.type !== 'item' || target.dropPosition !== 'on' || !shouldAcceptItemDrop || shouldAcceptItemDrop(target, types);
|
|
43
|
+
let isValidMove = onMove && target.type === 'item' && isInternal && isItemDropAllowed;
|
|
42
44
|
// Feedback was that internal root drop was weird so preventing that from happening
|
|
43
45
|
let isValidRootDrop = onRootDrop && target.type === 'root' && !isInternal;
|
|
44
46
|
// Automatically prevent items (i.e. folders) from being dropped on themselves.
|
|
45
|
-
let isValidOnItemDrop = onItemDrop && target.type === 'item' && target.dropPosition === 'on' && !(isInternal && target.key != null && draggingKeys.has(target.key)) &&
|
|
46
|
-
if (onDrop || isValidInsert || isValidReorder || isValidRootDrop || isValidOnItemDrop) {
|
|
47
|
+
let isValidOnItemDrop = onItemDrop && target.type === 'item' && target.dropPosition === 'on' && !(isInternal && target.key != null && draggingKeys.has(target.key)) && isItemDropAllowed;
|
|
48
|
+
if (onDrop || isValidInsert || isValidReorder || isValidMove || isValidRootDrop || isValidOnItemDrop) {
|
|
47
49
|
if (getDropOperation) return getDropOperation(target, types, allowedOperations);
|
|
48
50
|
else return allowedOperations[0];
|
|
49
51
|
}
|
|
@@ -51,6 +53,7 @@ function $e672e8bc247525d1$export$926850f6ecef79d0(props) {
|
|
|
51
53
|
return 'cancel';
|
|
52
54
|
}, [
|
|
53
55
|
isDisabled,
|
|
56
|
+
collection,
|
|
54
57
|
acceptedDragTypes,
|
|
55
58
|
getDropOperation,
|
|
56
59
|
onInsert,
|
|
@@ -58,6 +61,7 @@ function $e672e8bc247525d1$export$926850f6ecef79d0(props) {
|
|
|
58
61
|
onItemDrop,
|
|
59
62
|
shouldAcceptItemDrop,
|
|
60
63
|
onReorder,
|
|
64
|
+
onMove,
|
|
61
65
|
onDrop
|
|
62
66
|
]);
|
|
63
67
|
return {
|
|
@@ -105,6 +109,14 @@ function $e672e8bc247525d1$var$isEqualDropTarget(a, b) {
|
|
|
105
109
|
return (b === null || b === void 0 ? void 0 : b.type) === 'item' && (b === null || b === void 0 ? void 0 : b.key) === a.key && (b === null || b === void 0 ? void 0 : b.dropPosition) === a.dropPosition;
|
|
106
110
|
}
|
|
107
111
|
}
|
|
112
|
+
function $e672e8bc247525d1$var$isDraggingWithinParent(collection, target, draggingKeys) {
|
|
113
|
+
let targetNode = collection.getItem(target.key);
|
|
114
|
+
for (let key of draggingKeys){
|
|
115
|
+
let node = collection.getItem(key);
|
|
116
|
+
if ((node === null || node === void 0 ? void 0 : node.parentKey) !== (targetNode === null || targetNode === void 0 ? void 0 : targetNode.parentKey)) return false;
|
|
117
|
+
}
|
|
118
|
+
return true;
|
|
119
|
+
}
|
|
108
120
|
|
|
109
121
|
|
|
110
122
|
export {$e672e8bc247525d1$export$926850f6ecef79d0 as useDroppableCollectionState};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;AAAA;;;;;;;;;;CAUC;AA2CM,SAAS,0CAA4B,KAAsC;IAChF,IAAI,qBACF,oBAAoB,mBACpB,UAAU,YACV,QAAQ,cACR,UAAU,cACV,UAAU,aACV,SAAS,wBACT,oBAAoB,cACpB,UAAU,oBACV,gBAAgB,eAChB,WAAW,oBACX,gBAAgB,UAChB,MAAM,EACP,GAAG;IACJ,IAAI,CAAC,QAAQ,UAAU,GAAG,CAAA,GAAA,eAAO,EAAqB;IACtD,IAAI,YAAY,CAAA,GAAA,aAAK,EAAqB;IAE1C,IAAI,oBAAoB,CAAC;QACvB,IAAI,OAAO,YAAY,KAAK,UAAU;YACpC,IAAI,MAAM,WAAW,YAAY,CAAC,OAAO,GAAG;YAC5C,OAAO,OAAO,OAAO;gBAAC,MAAM;qBAAQ;gBAAK,cAAc;YAAO,IAAI;QACpE,OAAO,IAAI,OAAO,YAAY,KAAK,SAAS;YAC1C,IAAI,MAAM,WAAW,WAAW,CAAC,OAAO,GAAG;YAC3C,OAAO,OAAO,OAAO;gBAAC,MAAM;qBAAQ;gBAAK,cAAc;YAAQ,IAAI;QACrE;QACA,OAAO;IACT;IAEA,IAAI,0BAA0B,CAAA,GAAA,kBAAU,EAAE,CAAC;QACzC,IAAI,UACF,MAAM,SACN,KAAK,qBACL,iBAAiB,cACjB,UAAU,gBACV,YAAY,EACb,GAAG;QAEJ,IAAI,cAAc,CAAC,QACjB,OAAO;QAGT,IAAI,sBAAsB,SAAS,kBAAkB,IAAI,CAAC,CAAA,OAAQ,MAAM,GAAG,CAAC,QAAQ;YAClF,IAAI,gBAAgB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AC,YACd,OAAO;YAET,IAAI,wCAAkB,YAAY,SAChC,OAAO;YAGT,6GAA6G;YAC7G,IACE,CAAA,uBAAA,iCAAA,WAAY,IAAI,MAAK,UACrB,CAAA,mBAAA,6BAAA,OAAQ,IAAI,MAAK,UACjB,WAAW,GAAG,KAAK,OAAO,GAAG,IAC7B,WAAW,YAAY,KAAK,OAAO,YAAY,IAC/C,WAAW,YAAY,KAAK,QAC5B,OAAO,YAAY,KAAK,MAExB,OAAO,wCAAkB,kBAAkB,aAAa,WACtD,wCAAkB,YAAY,kBAAkB;YAGpD,OAAO;QACT;QACA,kBAAiB,CAAC;YAChB,OAAO,wBAAwB;QACjC;IACF;AACF;AAEA,SAAS,wCAAkB,CAAqB,EAAE,CAAqB;IACrE,IAAI,CAAC,GACH,OAAO,CAAC;IAGV,OAAQ,EAAE,IAAI;QACZ,KAAK;YACH,OAAO,CAAA,cAAA,wBAAA,EAAG,IAAI,MAAK;QACrB,KAAK;YACH,OAAO,CAAA,cAAA,wBAAA,EAAG,IAAI,MAAK,UAAU,CAAA,cAAA,wBAAA,EAAG,GAAG,MAAK,EAAE,GAAG,IAAI,CAAA,cAAA,wBAAA,EAAG,YAAY,MAAK,EAAE,YAAY;IACvF;AACF","sources":["packages/@react-stately/dnd/src/useDroppableCollectionState.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 {Collection, DragTypes, DropOperation, DroppableCollectionProps, DropTarget, ItemDropTarget, Key, Node} from '@react-types/shared';\nimport {MultipleSelectionManager} from '@react-stately/selection';\nimport {useCallback, useRef, useState} from 'react';\n\ninterface DropOperationEvent {\n target: DropTarget,\n types: DragTypes,\n allowedOperations: DropOperation[],\n isInternal: boolean,\n draggingKeys: Set<Key>\n}\n\nexport interface DroppableCollectionStateOptions extends Omit<DroppableCollectionProps, 'onDropMove' | 'onDropActivate'> {\n /** A collection of items. */\n collection: Collection<Node<unknown>>,\n /** An interface for reading and updating multiple selection state. */\n selectionManager: MultipleSelectionManager,\n /** Whether the drop events should be disabled. */\n isDisabled?: boolean\n}\n\nexport interface DroppableCollectionState {\n /** A collection of items. */\n collection: Collection<Node<unknown>>,\n /** An interface for reading and updating multiple selection state. */\n selectionManager: MultipleSelectionManager,\n /** The current drop target. */\n target: DropTarget | null,\n /** Whether drop events are disabled. */\n isDisabled?: boolean,\n /** Sets the current drop target. */\n setTarget(target: DropTarget | null): void,\n /** Returns whether the given target is equivalent to the current drop target. */\n isDropTarget(target: DropTarget | null): boolean,\n /** Returns the drop operation for the given parameters. */\n getDropOperation(e: DropOperationEvent): DropOperation\n}\n\n/**\n * Manages state for a droppable collection.\n */\nexport function useDroppableCollectionState(props: DroppableCollectionStateOptions): DroppableCollectionState {\n let {\n acceptedDragTypes = 'all',\n isDisabled,\n onInsert,\n onRootDrop,\n onItemDrop,\n onReorder,\n shouldAcceptItemDrop,\n collection,\n selectionManager,\n onDropEnter,\n getDropOperation,\n onDrop\n } = props;\n let [target, setTarget] = useState<DropTarget | null>(null);\n let targetRef = useRef<DropTarget | null>(null);\n\n let getOppositeTarget = (target: ItemDropTarget): ItemDropTarget | null => {\n if (target.dropPosition === 'before') {\n let key = collection.getKeyBefore(target.key);\n return key != null ? {type: 'item', key, dropPosition: 'after'} : null;\n } else if (target.dropPosition === 'after') {\n let key = collection.getKeyAfter(target.key);\n return key != null ? {type: 'item', key, dropPosition: 'before'} : null;\n }\n return null;\n };\n\n let defaultGetDropOperation = useCallback((e: DropOperationEvent) => {\n let {\n target,\n types,\n allowedOperations,\n isInternal,\n draggingKeys\n } = e;\n\n if (isDisabled || !target) {\n return 'cancel';\n }\n\n if (acceptedDragTypes === 'all' || acceptedDragTypes.some(type => types.has(type))) {\n let isValidInsert = onInsert && target.type === 'item' && !isInternal && (target.dropPosition === 'before' || target.dropPosition === 'after');\n let isValidReorder = onReorder && target.type === 'item' && isInternal && (target.dropPosition === 'before' || target.dropPosition === 'after');\n // Feedback was that internal root drop was weird so preventing that from happening\n let isValidRootDrop = onRootDrop && target.type === 'root' && !isInternal;\n // Automatically prevent items (i.e. folders) from being dropped on themselves.\n let isValidOnItemDrop = onItemDrop && target.type === 'item' && target.dropPosition === 'on' && !(isInternal && target.key != null && draggingKeys.has(target.key)) && (!shouldAcceptItemDrop || shouldAcceptItemDrop(target, types));\n\n if (onDrop || isValidInsert || isValidReorder || isValidRootDrop || isValidOnItemDrop) {\n if (getDropOperation) {\n return getDropOperation(target, types, allowedOperations);\n } else {\n return allowedOperations[0];\n }\n }\n }\n\n return 'cancel';\n }, [isDisabled, acceptedDragTypes, getDropOperation, onInsert, onRootDrop, onItemDrop, shouldAcceptItemDrop, onReorder, onDrop]);\n\n return {\n collection,\n selectionManager,\n isDisabled,\n target,\n setTarget(newTarget) {\n if (this.isDropTarget(newTarget)) {\n return;\n }\n\n let target = targetRef.current;\n if (target && typeof props.onDropExit === 'function') {\n props.onDropExit({\n type: 'dropexit',\n x: 0, // todo\n y: 0,\n target\n });\n }\n\n if (newTarget && typeof onDropEnter === 'function') {\n onDropEnter({\n type: 'dropenter',\n x: 0, // todo\n y: 0,\n target: newTarget\n });\n }\n\n targetRef.current = newTarget ?? null;\n setTarget(newTarget ?? null);\n },\n isDropTarget(dropTarget) {\n let target = targetRef.current;\n if (!target || !dropTarget) {\n return false;\n }\n if (isEqualDropTarget(dropTarget, target)) {\n return true;\n }\n\n // Check if the targets point at the same point between two items, one referring before, and the other after.\n if (\n dropTarget?.type === 'item' &&\n target?.type === 'item' &&\n dropTarget.key !== target.key &&\n dropTarget.dropPosition !== target.dropPosition &&\n dropTarget.dropPosition !== 'on' &&\n target.dropPosition !== 'on'\n ) {\n return isEqualDropTarget(getOppositeTarget(dropTarget), target) ||\n isEqualDropTarget(dropTarget, getOppositeTarget(target));\n }\n\n return false;\n },\n getDropOperation(e) {\n return defaultGetDropOperation(e);\n }\n };\n}\n\nfunction isEqualDropTarget(a?: DropTarget | null, b?: DropTarget | null) {\n if (!a) {\n return !b;\n }\n\n switch (a.type) {\n case 'root':\n return b?.type === 'root';\n case 'item':\n return b?.type === 'item' && b?.key === a.key && b?.dropPosition === a.dropPosition;\n }\n}\n"],"names":[],"version":3,"file":"useDroppableCollectionState.module.js.map"}
|
|
1
|
+
{"mappings":";;AAAA;;;;;;;;;;CAUC;AA2CM,SAAS,0CAA4B,KAAsC;IAChF,IAAI,qBACF,oBAAoB,mBACpB,UAAU,YACV,QAAQ,cACR,UAAU,cACV,UAAU,aACV,SAAS,UACT,MAAM,wBACN,oBAAoB,cACpB,UAAU,oBACV,gBAAgB,eAChB,WAAW,oBACX,gBAAgB,UAChB,MAAM,EACP,GAAG;IACJ,IAAI,CAAC,QAAQ,UAAU,GAAG,CAAA,GAAA,eAAO,EAAqB;IACtD,IAAI,YAAY,CAAA,GAAA,aAAK,EAAqB;IAE1C,IAAI,oBAAoB,CAAC;QACvB,IAAI,OAAO,YAAY,KAAK,UAAU;YACpC,IAAI,OAAO,WAAW,OAAO,CAAC,OAAO,GAAG;YACxC,OAAO,QAAQ,KAAK,OAAO,IAAI,OAC3B;gBAAC,MAAM;gBAAQ,KAAK,KAAK,OAAO;gBAAE,cAAc;YAAO,IACvD;QACN,OAAO,IAAI,OAAO,YAAY,KAAK,SAAS;YAC1C,IAAI,OAAO,WAAW,OAAO,CAAC,OAAO,GAAG;YACxC,OAAO,QAAQ,KAAK,OAAO,IAAI,OAC3B;gBAAC,MAAM;gBAAQ,KAAK,KAAK,OAAO;gBAAE,cAAc;YAAQ,IACxD;QACN;QACA,OAAO;IACT;IAEA,IAAI,0BAA0B,CAAA,GAAA,kBAAU,EAAE,CAAC;QAC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,OAAO,GAAG;IAE9C,KAAK,IAAI,OAAO,aAAc;QAC5B,IAAI,OAAO,WAAW,OAAO,CAAC;QAC9B,IAAI,CAAA,iBAAA,2BAAA,KAAM,SAAS,OAAK,uBAAA,iCAAA,WAAY,SAAS,GAC3C,OAAO;IAEX;IAEA,OAAO;AACT","sources":["packages/@react-stately/dnd/src/useDroppableCollectionState.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 {Collection, DragTypes, DropOperation, DroppableCollectionProps, DropTarget, ItemDropTarget, Key, Node} from '@react-types/shared';\nimport {MultipleSelectionManager} from '@react-stately/selection';\nimport {useCallback, useRef, useState} from 'react';\n\ninterface DropOperationEvent {\n target: DropTarget,\n types: DragTypes,\n allowedOperations: DropOperation[],\n isInternal: boolean,\n draggingKeys: Set<Key>\n}\n\nexport interface DroppableCollectionStateOptions extends Omit<DroppableCollectionProps, 'onDropMove' | 'onDropActivate'> {\n /** A collection of items. */\n collection: Collection<Node<unknown>>,\n /** An interface for reading and updating multiple selection state. */\n selectionManager: MultipleSelectionManager,\n /** Whether the drop events should be disabled. */\n isDisabled?: boolean\n}\n\nexport interface DroppableCollectionState {\n /** A collection of items. */\n collection: Collection<Node<unknown>>,\n /** An interface for reading and updating multiple selection state. */\n selectionManager: MultipleSelectionManager,\n /** The current drop target. */\n target: DropTarget | null,\n /** Whether drop events are disabled. */\n isDisabled?: boolean,\n /** Sets the current drop target. */\n setTarget(target: DropTarget | null): void,\n /** Returns whether the given target is equivalent to the current drop target. */\n isDropTarget(target: DropTarget | null): boolean,\n /** Returns the drop operation for the given parameters. */\n getDropOperation(e: DropOperationEvent): DropOperation\n}\n\n/**\n * Manages state for a droppable collection.\n */\nexport function useDroppableCollectionState(props: DroppableCollectionStateOptions): DroppableCollectionState {\n let {\n acceptedDragTypes = 'all',\n isDisabled,\n onInsert,\n onRootDrop,\n onItemDrop,\n onReorder,\n onMove,\n shouldAcceptItemDrop,\n collection,\n selectionManager,\n onDropEnter,\n getDropOperation,\n onDrop\n } = props;\n let [target, setTarget] = useState<DropTarget | null>(null);\n let targetRef = useRef<DropTarget | null>(null);\n\n let getOppositeTarget = (target: ItemDropTarget): ItemDropTarget | null => {\n if (target.dropPosition === 'before') {\n let node = collection.getItem(target.key);\n return node && node.prevKey != null\n ? {type: 'item', key: node.prevKey, dropPosition: 'after'} \n : null;\n } else if (target.dropPosition === 'after') {\n let node = collection.getItem(target.key);\n return node && node.nextKey != null\n ? {type: 'item', key: node.nextKey, dropPosition: 'before'} \n : null;\n }\n return null;\n };\n\n let defaultGetDropOperation = useCallback((e: DropOperationEvent) => {\n let {\n target,\n types,\n allowedOperations,\n isInternal,\n draggingKeys\n } = e;\n\n if (isDisabled || !target) {\n return 'cancel';\n }\n\n if (acceptedDragTypes === 'all' || acceptedDragTypes.some(type => types.has(type))) {\n let isValidInsert = onInsert && target.type === 'item' && !isInternal && (target.dropPosition === 'before' || target.dropPosition === 'after');\n let isValidReorder = onReorder\n && target.type === 'item'\n && isInternal\n && (target.dropPosition === 'before' || target.dropPosition === 'after')\n && isDraggingWithinParent(collection, target, draggingKeys);\n\n let isItemDropAllowed = target.type !== 'item'\n || target.dropPosition !== 'on'\n || (!shouldAcceptItemDrop || shouldAcceptItemDrop(target, types));\n\n let isValidMove = onMove\n && target.type === 'item'\n && isInternal\n && isItemDropAllowed;\n\n // Feedback was that internal root drop was weird so preventing that from happening\n let isValidRootDrop = onRootDrop && target.type === 'root' && !isInternal;\n \n // Automatically prevent items (i.e. folders) from being dropped on themselves.\n let isValidOnItemDrop = onItemDrop \n && target.type === 'item' \n && target.dropPosition === 'on' \n && !(isInternal && target.key != null && draggingKeys.has(target.key)) \n && isItemDropAllowed;\n\n if (onDrop || isValidInsert || isValidReorder || isValidMove || isValidRootDrop || isValidOnItemDrop) {\n if (getDropOperation) {\n return getDropOperation(target, types, allowedOperations);\n } else {\n return allowedOperations[0];\n }\n }\n }\n\n return 'cancel';\n }, [isDisabled, collection, acceptedDragTypes, getDropOperation, onInsert, onRootDrop, onItemDrop, shouldAcceptItemDrop, onReorder, onMove, onDrop]);\n\n return {\n collection,\n selectionManager,\n isDisabled,\n target,\n setTarget(newTarget) {\n if (this.isDropTarget(newTarget)) {\n return;\n }\n\n let target = targetRef.current;\n if (target && typeof props.onDropExit === 'function') {\n props.onDropExit({\n type: 'dropexit',\n x: 0, // todo\n y: 0,\n target\n });\n }\n\n if (newTarget && typeof onDropEnter === 'function') {\n onDropEnter({\n type: 'dropenter',\n x: 0, // todo\n y: 0,\n target: newTarget\n });\n }\n\n targetRef.current = newTarget ?? null;\n setTarget(newTarget ?? null);\n },\n isDropTarget(dropTarget) {\n let target = targetRef.current;\n if (!target || !dropTarget) {\n return false;\n }\n if (isEqualDropTarget(dropTarget, target)) {\n return true;\n }\n\n // Check if the targets point at the same point between two items, one referring before, and the other after.\n if (\n dropTarget?.type === 'item' &&\n target?.type === 'item' &&\n dropTarget.key !== target.key &&\n dropTarget.dropPosition !== target.dropPosition &&\n dropTarget.dropPosition !== 'on' &&\n target.dropPosition !== 'on'\n ) {\n return isEqualDropTarget(getOppositeTarget(dropTarget), target) ||\n isEqualDropTarget(dropTarget, getOppositeTarget(target));\n }\n\n return false;\n },\n getDropOperation(e) {\n return defaultGetDropOperation(e);\n }\n };\n}\n\nfunction isEqualDropTarget(a?: DropTarget | null, b?: DropTarget | null) {\n if (!a) {\n return !b;\n }\n\n switch (a.type) {\n case 'root':\n return b?.type === 'root';\n case 'item':\n return b?.type === 'item' && b?.key === a.key && b?.dropPosition === a.dropPosition;\n }\n}\n\nfunction isDraggingWithinParent(collection: Collection<Node<unknown>>, target: ItemDropTarget, draggingKeys: Set<Key>) {\n let targetNode = collection.getItem(target.key);\n\n for (let key of draggingKeys) {\n let node = collection.getItem(key);\n if (node?.parentKey !== targetNode?.parentKey) {\n return false;\n }\n }\n\n return true;\n}\n"],"names":[],"version":3,"file":"useDroppableCollectionState.module.js.map"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-stately/dnd",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.6.1",
|
|
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
8
|
"exports": {
|
|
9
|
-
"
|
|
9
|
+
"source": "./src/index.ts",
|
|
10
|
+
"types": [
|
|
11
|
+
"./dist/types.d.ts",
|
|
12
|
+
"./src/index.ts"
|
|
13
|
+
],
|
|
10
14
|
"import": "./dist/import.mjs",
|
|
11
15
|
"require": "./dist/main.js"
|
|
12
16
|
},
|
|
@@ -22,8 +26,8 @@
|
|
|
22
26
|
"url": "https://github.com/adobe/react-spectrum"
|
|
23
27
|
},
|
|
24
28
|
"dependencies": {
|
|
25
|
-
"@react-stately/selection": "^3.20.
|
|
26
|
-
"@react-types/shared": "^3.
|
|
29
|
+
"@react-stately/selection": "^3.20.4",
|
|
30
|
+
"@react-types/shared": "^3.31.0",
|
|
27
31
|
"@swc/helpers": "^0.5.0"
|
|
28
32
|
},
|
|
29
33
|
"peerDependencies": {
|
|
@@ -32,5 +36,5 @@
|
|
|
32
36
|
"publishConfig": {
|
|
33
37
|
"access": "public"
|
|
34
38
|
},
|
|
35
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "8b9348ff255e018b2dd9b27e2a45507cadfa1d35"
|
|
36
40
|
}
|
|
@@ -72,15 +72,35 @@ export function useDraggableCollectionState(props: DraggableCollectionStateOptio
|
|
|
72
72
|
let draggedKey = useRef<Key | null>(null);
|
|
73
73
|
let getKeys = (key: Key) => {
|
|
74
74
|
// The clicked item is always added to the drag. If it is selected, then all of the
|
|
75
|
-
// other selected items are also dragged. If it is not selected,
|
|
75
|
+
// other selected items are also dragged. If it is not selected, then only the clicked
|
|
76
76
|
// item is dragged. This matches native macOS behavior.
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
77
|
+
// Additionally, we filter out any keys that are children of any of the other selected keys
|
|
78
|
+
let keys = new Set<Key>();
|
|
79
|
+
if (selectionManager.isSelected(key)) {
|
|
80
|
+
for (let currentKey of selectionManager.selectedKeys) {
|
|
81
|
+
let node = collection.getItem(currentKey);
|
|
82
|
+
if (node) {
|
|
83
|
+
let isChild = false;
|
|
84
|
+
let parentKey = node.parentKey;
|
|
85
|
+
while (parentKey != null) {
|
|
86
|
+
// eslint-disable-next-line max-depth
|
|
87
|
+
if (selectionManager.selectedKeys.has(parentKey)) {
|
|
88
|
+
isChild = true;
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
let parentNode = collection.getItem(parentKey);
|
|
92
|
+
parentKey = parentNode ? parentNode.parentKey : null;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (!isChild) {
|
|
96
|
+
keys.add(currentKey);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
} else {
|
|
101
|
+
keys.add(key);
|
|
102
|
+
}
|
|
82
103
|
|
|
83
|
-
keys.add(key);
|
|
84
104
|
return keys;
|
|
85
105
|
};
|
|
86
106
|
|
|
@@ -59,6 +59,7 @@ export function useDroppableCollectionState(props: DroppableCollectionStateOptio
|
|
|
59
59
|
onRootDrop,
|
|
60
60
|
onItemDrop,
|
|
61
61
|
onReorder,
|
|
62
|
+
onMove,
|
|
62
63
|
shouldAcceptItemDrop,
|
|
63
64
|
collection,
|
|
64
65
|
selectionManager,
|
|
@@ -71,11 +72,15 @@ export function useDroppableCollectionState(props: DroppableCollectionStateOptio
|
|
|
71
72
|
|
|
72
73
|
let getOppositeTarget = (target: ItemDropTarget): ItemDropTarget | null => {
|
|
73
74
|
if (target.dropPosition === 'before') {
|
|
74
|
-
let
|
|
75
|
-
return
|
|
75
|
+
let node = collection.getItem(target.key);
|
|
76
|
+
return node && node.prevKey != null
|
|
77
|
+
? {type: 'item', key: node.prevKey, dropPosition: 'after'}
|
|
78
|
+
: null;
|
|
76
79
|
} else if (target.dropPosition === 'after') {
|
|
77
|
-
let
|
|
78
|
-
return
|
|
80
|
+
let node = collection.getItem(target.key);
|
|
81
|
+
return node && node.nextKey != null
|
|
82
|
+
? {type: 'item', key: node.nextKey, dropPosition: 'before'}
|
|
83
|
+
: null;
|
|
79
84
|
}
|
|
80
85
|
return null;
|
|
81
86
|
};
|
|
@@ -95,13 +100,32 @@ export function useDroppableCollectionState(props: DroppableCollectionStateOptio
|
|
|
95
100
|
|
|
96
101
|
if (acceptedDragTypes === 'all' || acceptedDragTypes.some(type => types.has(type))) {
|
|
97
102
|
let isValidInsert = onInsert && target.type === 'item' && !isInternal && (target.dropPosition === 'before' || target.dropPosition === 'after');
|
|
98
|
-
let isValidReorder = onReorder
|
|
103
|
+
let isValidReorder = onReorder
|
|
104
|
+
&& target.type === 'item'
|
|
105
|
+
&& isInternal
|
|
106
|
+
&& (target.dropPosition === 'before' || target.dropPosition === 'after')
|
|
107
|
+
&& isDraggingWithinParent(collection, target, draggingKeys);
|
|
108
|
+
|
|
109
|
+
let isItemDropAllowed = target.type !== 'item'
|
|
110
|
+
|| target.dropPosition !== 'on'
|
|
111
|
+
|| (!shouldAcceptItemDrop || shouldAcceptItemDrop(target, types));
|
|
112
|
+
|
|
113
|
+
let isValidMove = onMove
|
|
114
|
+
&& target.type === 'item'
|
|
115
|
+
&& isInternal
|
|
116
|
+
&& isItemDropAllowed;
|
|
117
|
+
|
|
99
118
|
// Feedback was that internal root drop was weird so preventing that from happening
|
|
100
119
|
let isValidRootDrop = onRootDrop && target.type === 'root' && !isInternal;
|
|
120
|
+
|
|
101
121
|
// Automatically prevent items (i.e. folders) from being dropped on themselves.
|
|
102
|
-
let isValidOnItemDrop = onItemDrop
|
|
122
|
+
let isValidOnItemDrop = onItemDrop
|
|
123
|
+
&& target.type === 'item'
|
|
124
|
+
&& target.dropPosition === 'on'
|
|
125
|
+
&& !(isInternal && target.key != null && draggingKeys.has(target.key))
|
|
126
|
+
&& isItemDropAllowed;
|
|
103
127
|
|
|
104
|
-
if (onDrop || isValidInsert || isValidReorder || isValidRootDrop || isValidOnItemDrop) {
|
|
128
|
+
if (onDrop || isValidInsert || isValidReorder || isValidMove || isValidRootDrop || isValidOnItemDrop) {
|
|
105
129
|
if (getDropOperation) {
|
|
106
130
|
return getDropOperation(target, types, allowedOperations);
|
|
107
131
|
} else {
|
|
@@ -111,7 +135,7 @@ export function useDroppableCollectionState(props: DroppableCollectionStateOptio
|
|
|
111
135
|
}
|
|
112
136
|
|
|
113
137
|
return 'cancel';
|
|
114
|
-
}, [isDisabled, acceptedDragTypes, getDropOperation, onInsert, onRootDrop, onItemDrop, shouldAcceptItemDrop, onReorder, onDrop]);
|
|
138
|
+
}, [isDisabled, collection, acceptedDragTypes, getDropOperation, onInsert, onRootDrop, onItemDrop, shouldAcceptItemDrop, onReorder, onMove, onDrop]);
|
|
115
139
|
|
|
116
140
|
return {
|
|
117
141
|
collection,
|
|
@@ -187,3 +211,16 @@ function isEqualDropTarget(a?: DropTarget | null, b?: DropTarget | null) {
|
|
|
187
211
|
return b?.type === 'item' && b?.key === a.key && b?.dropPosition === a.dropPosition;
|
|
188
212
|
}
|
|
189
213
|
}
|
|
214
|
+
|
|
215
|
+
function isDraggingWithinParent(collection: Collection<Node<unknown>>, target: ItemDropTarget, draggingKeys: Set<Key>) {
|
|
216
|
+
let targetNode = collection.getItem(target.key);
|
|
217
|
+
|
|
218
|
+
for (let key of draggingKeys) {
|
|
219
|
+
let node = collection.getItem(key);
|
|
220
|
+
if (node?.parentKey !== targetNode?.parentKey) {
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
return true;
|
|
226
|
+
}
|