@react-stately/dnd 3.0.0-nightly.3491 → 3.0.0-nightly.3506

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/main.js CHANGED
@@ -139,8 +139,8 @@ function $6ce4cbfbe5e354f1$export$926850f6ecef79d0(props) {
139
139
  y: 0,
140
140
  target: newTarget
141
141
  });
142
- setTarget(newTarget);
143
142
  targetRef.current = newTarget;
143
+ setTarget(newTarget);
144
144
  },
145
145
  isDropTarget (dropTarget) {
146
146
  let target = targetRef.current;
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;SCoCgB,yCAA2B,CAAC,KAAsC,EAA4B,CAAC;IAC7G,GAAG,CAAC,CAAC,WACH,QAAQ,eACR,UAAU,qBACV,gBAAgB,gBAChB,WAAW,eACX,UAAU,cACV,SAAS,YACT,OAAO,6BACP,wBAAwB,EAC1B,CAAC,GAAG,KAAK;IACT,GAAG,IAAI,WAAW,IAAI,qBAAQ,CAAC,KAAK;IACpC,GAAG,CAAC,YAAY,GAAG,mBAAM,CAAC,GAAG,CAAC,GAAG;IACjC,GAAG,CAAC,UAAU,GAAG,mBAAM,CAAC,IAAI;IAC5B,GAAG,CAAC,OAAO,IAAI,IAAQ,GAAK,CAAC;QAC3B,EAAmF,AAAnF,iFAAmF;QACnF,EAAqF,AAArF,mFAAqF;QACrF,EAAuD,AAAvD,qDAAuD;QACvD,GAAG,CAAC,IAAI,GAAG,GAAG,CAAC,GAAG,CAChB,gBAAgB,CAAC,UAAU,CAAC,IAAG,IAC3B,GAAG,CAAC,GAAG,CAAC,CAAC;eAAG,gBAAgB,CAAC,YAAY;QAAA,CAAC,CAAC,MAAM,EAAC,GAAG,KAAM,UAAU,CAAC,OAAO,CAAC,GAAG;aACjF,CAAC,CAAC;QAGR,IAAI,CAAC,GAAG,CAAC,IAAG;QACZ,MAAM,CAAC,IAAI;IACb,CAAC;IAED,MAAM,CAAC,CAAC;oBAC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AI,OAChC,MAAM,CAAC,YAAY,KAAK,CAAI,KAE5B,MAAM,CAAC,uCAAiB,CAAC,iBAAiB,CAAC,UAAU,GAAG,MAAM,KAC5D,uCAAiB,CAAC,UAAU,EAAE,iBAAiB,CAAC,MAAM;YAG1D,MAAM,CAAC,KAAK;QACd,CAAC;QACD,gBAAgB,EAAC,CAAC,EAAE,CAAC;YACnB,MAAM,CAAC,uBAAuB,CAAC,CAAC;QAClC,CAAC;IACH,CAAC;AACH,CAAC;SAEQ,uCAAiB,CAAC,CAAa,EAAE,CAAa,EAAE,CAAC;IACxD,EAAE,GAAG,CAAC,EACJ,MAAM,EAAE,CAAC;IAGX,MAAM,CAAE,CAAC,CAAC,IAAI;QACZ,IAAI,CAAC,CAAM;YACT,MAAM,EAAC,CAAC,aAAD,CAAC,KAAD,IAAI,CAAJ,CAAO,GAAP,IAAI,CAAJ,CAAO,GAAP,CAAC,CAAE,IAAI,MAAK,CAAM;QAC3B,IAAI,CAAC,CAAM;YACT,MAAM,EAAC,CAAC,aAAD,CAAC,KAAD,IAAI,CAAJ,CAAO,GAAP,IAAI,CAAJ,CAAO,GAAP,CAAC,CAAE,IAAI,MAAK,CAAM,UAAI,CAAC,aAAD,CAAC,KAAD,IAAI,CAAJ,CAAM,GAAN,IAAI,CAAJ,CAAM,GAAN,CAAC,CAAE,GAAG,MAAK,CAAC,CAAC,GAAG,KAAI,CAAC,aAAD,CAAC,KAAD,IAAI,CAAJ,CAAe,GAAf,IAAI,CAAJ,CAAe,GAAf,CAAC,CAAE,YAAY,MAAK,CAAC,CAAC,YAAY;;AAEzF,CAAC;;","sources":["packages/@react-stately/dnd/src/index.ts","packages/@react-stately/dnd/src/useDraggableCollectionState.ts","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\nexport type {DraggableCollectionStateOptions, DraggableCollectionState} from './useDraggableCollectionState';\nexport type {DroppableCollectionStateOptions, DroppableCollectionState} from './useDroppableCollectionState';\nexport {useDraggableCollectionState} from './useDraggableCollectionState';\nexport {useDroppableCollectionState} from './useDroppableCollectionState';\n","/*\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, Node} from '@react-types/shared';\nimport {Key, RefObject, useRef, useState} from 'react';\nimport {MultipleSelectionManager} from '@react-stately/selection';\n\nexport interface DraggableCollectionStateOptions extends DraggableCollectionProps {\n collection: Collection<Node<unknown>>,\n selectionManager: MultipleSelectionManager\n}\n\nexport interface DraggableCollectionState {\n collection: Collection<Node<unknown>>,\n selectionManager: MultipleSelectionManager,\n draggedKey: Key | null,\n draggingKeys: Set<Key>,\n isDragging(key: Key): boolean,\n getKeysForDrag(key: Key): Set<Key>,\n getItems(key: Key): DragItem[],\n preview?: RefObject<DragPreviewRenderer>,\n getAllowedDropOperations?: () => DropOperation[],\n startDrag(key: Key, event: DragStartEvent): void,\n moveDrag(event: DragMoveEvent): void,\n endDrag(event: DraggableCollectionEndEvent): void\n}\n\nexport function useDraggableCollectionState(props: DraggableCollectionStateOptions): DraggableCollectionState {\n let {\n getItems,\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(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, the only the clicked\n // item is dragged. This matches native macOS behavior.\n let keys = new Set(\n selectionManager.isSelected(key)\n ? new Set([...selectionManager.selectedKeys].filter(key => !!collection.getItem(key)))\n : []\n );\n\n keys.add(key);\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 preview,\n getAllowedDropOperations,\n startDrag(key, event) {\n setDragging(true);\n let keys = getKeys(key);\n draggingKeys.current = keys;\n draggedKey.current = key;\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 setDragging(false);\n draggingKeys.current = new Set();\n draggedKey.current = null;\n }\n };\n}\n","/*\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, Node} from '@react-types/shared';\nimport {Key, useCallback, useRef, useState} from 'react';\nimport {MultipleSelectionManager} from '@react-stately/selection';\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 collection: Collection<Node<unknown>>,\n selectionManager: MultipleSelectionManager\n}\n\nexport interface DroppableCollectionState {\n collection: Collection<Node<unknown>>,\n selectionManager: MultipleSelectionManager,\n target: DropTarget,\n setTarget(target: DropTarget): void,\n isDropTarget(target: DropTarget): boolean,\n getDropOperation(e: DropOperationEvent): DropOperation\n}\n\nexport function useDroppableCollectionState(props: DroppableCollectionStateOptions): DroppableCollectionState {\n let {\n acceptedDragTypes = 'all',\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);\n let targetRef = useRef<DropTarget>(null);\n\n let getOppositeTarget = (target: ItemDropTarget): ItemDropTarget => {\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 };\n\n let defaultGetDropOperation = useCallback((e: DropOperationEvent) => {\n let {\n target,\n types,\n allowedOperations,\n isInternal,\n draggingKeys\n } = e;\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 && 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 }, [acceptedDragTypes, getDropOperation, onInsert, onRootDrop, onItemDrop, shouldAcceptItemDrop, onReorder, onDrop]);\n\n return {\n collection,\n selectionManager,\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 setTarget(newTarget);\n targetRef.current = newTarget;\n },\n isDropTarget(dropTarget) {\n let target = targetRef.current;\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, b: DropTarget) {\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?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AC;SAEQ,uCAAiB,CAAC,CAAa,EAAE,CAAa,EAAE,CAAC;IACxD,EAAE,GAAG,CAAC,EACJ,MAAM,EAAE,CAAC;IAGX,MAAM,CAAE,CAAC,CAAC,IAAI;QACZ,IAAI,CAAC,CAAM;YACT,MAAM,EAAC,CAAC,aAAD,CAAC,KAAD,IAAI,CAAJ,CAAO,GAAP,IAAI,CAAJ,CAAO,GAAP,CAAC,CAAE,IAAI,MAAK,CAAM;QAC3B,IAAI,CAAC,CAAM;YACT,MAAM,EAAC,CAAC,aAAD,CAAC,KAAD,IAAI,CAAJ,CAAO,GAAP,IAAI,CAAJ,CAAO,GAAP,CAAC,CAAE,IAAI,MAAK,CAAM,UAAI,CAAC,aAAD,CAAC,KAAD,IAAI,CAAJ,CAAM,GAAN,IAAI,CAAJ,CAAM,GAAN,CAAC,CAAE,GAAG,MAAK,CAAC,CAAC,GAAG,KAAI,CAAC,aAAD,CAAC,KAAD,IAAI,CAAJ,CAAe,GAAf,IAAI,CAAJ,CAAe,GAAf,CAAC,CAAE,YAAY,MAAK,CAAC,CAAC,YAAY;;AAEzF,CAAC;;","sources":["packages/@react-stately/dnd/src/index.ts","packages/@react-stately/dnd/src/useDraggableCollectionState.ts","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\nexport type {DraggableCollectionStateOptions, DraggableCollectionState} from './useDraggableCollectionState';\nexport type {DroppableCollectionStateOptions, DroppableCollectionState} from './useDroppableCollectionState';\nexport {useDraggableCollectionState} from './useDraggableCollectionState';\nexport {useDroppableCollectionState} from './useDroppableCollectionState';\n","/*\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, Node} from '@react-types/shared';\nimport {Key, RefObject, useRef, useState} from 'react';\nimport {MultipleSelectionManager} from '@react-stately/selection';\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}\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 /** 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>,\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 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(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, the only the clicked\n // item is dragged. This matches native macOS behavior.\n let keys = new Set(\n selectionManager.isSelected(key)\n ? new Set([...selectionManager.selectedKeys].filter(key => !!collection.getItem(key)))\n : []\n );\n\n keys.add(key);\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 preview,\n getAllowedDropOperations,\n startDrag(key, event) {\n setDragging(true);\n let keys = getKeys(key);\n draggingKeys.current = keys;\n draggedKey.current = key;\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 setDragging(false);\n draggingKeys.current = new Set();\n draggedKey.current = null;\n }\n };\n}\n","/*\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, Node} from '@react-types/shared';\nimport {Key, useCallback, useRef, useState} from 'react';\nimport {MultipleSelectionManager} from '@react-stately/selection';\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}\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 /** Sets the current drop target. */\n setTarget(target: DropTarget): void,\n /** Returns whether the given target is equivalent to the current drop target. */\n isDropTarget(target: DropTarget): 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 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);\n let targetRef = useRef<DropTarget>(null);\n\n let getOppositeTarget = (target: ItemDropTarget): ItemDropTarget => {\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 };\n\n let defaultGetDropOperation = useCallback((e: DropOperationEvent) => {\n let {\n target,\n types,\n allowedOperations,\n isInternal,\n draggingKeys\n } = e;\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 && 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 }, [acceptedDragTypes, getDropOperation, onInsert, onRootDrop, onItemDrop, shouldAcceptItemDrop, onReorder, onDrop]);\n\n return {\n collection,\n selectionManager,\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;\n setTarget(newTarget);\n },\n isDropTarget(dropTarget) {\n let target = targetRef.current;\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, b: DropTarget) {\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":"main.js.map"}
package/dist/module.js CHANGED
@@ -133,8 +133,8 @@ function $e672e8bc247525d1$export$926850f6ecef79d0(props) {
133
133
  y: 0,
134
134
  target: newTarget
135
135
  });
136
- setTarget(newTarget);
137
136
  targetRef.current = newTarget;
137
+ setTarget(newTarget);
138
138
  },
139
139
  isDropTarget (dropTarget) {
140
140
  let target = targetRef.current;
@@ -1 +1 @@
1
- {"mappings":";;;SCoCgB,yCAA2B,CAAC,KAAsC,EAA4B,CAAC;IAC7G,GAAG,CAAC,CAAC,WACH,QAAQ,eACR,UAAU,qBACV,gBAAgB,gBAChB,WAAW,eACX,UAAU,cACV,SAAS,YACT,OAAO,6BACP,wBAAwB,EAC1B,CAAC,GAAG,KAAK;IACT,GAAG,IAAI,WAAW,IAAI,eAAQ,CAAC,KAAK;IACpC,GAAG,CAAC,YAAY,GAAG,aAAM,CAAC,GAAG,CAAC,GAAG;IACjC,GAAG,CAAC,UAAU,GAAG,aAAM,CAAC,IAAI;IAC5B,GAAG,CAAC,OAAO,IAAI,IAAQ,GAAK,CAAC;QAC3B,EAAmF,AAAnF,iFAAmF;QACnF,EAAqF,AAArF,mFAAqF;QACrF,EAAuD,AAAvD,qDAAuD;QACvD,GAAG,CAAC,IAAI,GAAG,GAAG,CAAC,GAAG,CAChB,gBAAgB,CAAC,UAAU,CAAC,IAAG,IAC3B,GAAG,CAAC,GAAG,CAAC,CAAC;eAAG,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ages/@react-stately/dnd/src/useDraggableCollectionState.ts","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\nexport type {DraggableCollectionStateOptions, DraggableCollectionState} from './useDraggableCollectionState';\nexport type {DroppableCollectionStateOptions, DroppableCollectionState} from './useDroppableCollectionState';\nexport {useDraggableCollectionState} from './useDraggableCollectionState';\nexport {useDroppableCollectionState} from './useDroppableCollectionState';\n","/*\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, Node} from '@react-types/shared';\nimport {Key, RefObject, useRef, useState} from 'react';\nimport {MultipleSelectionManager} from '@react-stately/selection';\n\nexport interface DraggableCollectionStateOptions extends DraggableCollectionProps {\n collection: Collection<Node<unknown>>,\n selectionManager: MultipleSelectionManager\n}\n\nexport interface DraggableCollectionState {\n collection: Collection<Node<unknown>>,\n selectionManager: MultipleSelectionManager,\n draggedKey: Key | null,\n draggingKeys: Set<Key>,\n isDragging(key: Key): boolean,\n getKeysForDrag(key: Key): Set<Key>,\n getItems(key: Key): DragItem[],\n preview?: RefObject<DragPreviewRenderer>,\n getAllowedDropOperations?: () => DropOperation[],\n startDrag(key: Key, event: DragStartEvent): void,\n moveDrag(event: DragMoveEvent): void,\n endDrag(event: DraggableCollectionEndEvent): void\n}\n\nexport function useDraggableCollectionState(props: DraggableCollectionStateOptions): DraggableCollectionState {\n let {\n getItems,\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(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, the only the clicked\n // item is dragged. This matches native macOS behavior.\n let keys = new Set(\n selectionManager.isSelected(key)\n ? new Set([...selectionManager.selectedKeys].filter(key => !!collection.getItem(key)))\n : []\n );\n\n keys.add(key);\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 preview,\n getAllowedDropOperations,\n startDrag(key, event) {\n setDragging(true);\n let keys = getKeys(key);\n draggingKeys.current = keys;\n draggedKey.current = key;\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 setDragging(false);\n draggingKeys.current = new Set();\n draggedKey.current = null;\n }\n };\n}\n","/*\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, Node} from '@react-types/shared';\nimport {Key, useCallback, useRef, useState} from 'react';\nimport {MultipleSelectionManager} from '@react-stately/selection';\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 collection: Collection<Node<unknown>>,\n selectionManager: MultipleSelectionManager\n}\n\nexport interface DroppableCollectionState {\n collection: Collection<Node<unknown>>,\n selectionManager: MultipleSelectionManager,\n target: DropTarget,\n setTarget(target: DropTarget): void,\n isDropTarget(target: DropTarget): boolean,\n getDropOperation(e: DropOperationEvent): DropOperation\n}\n\nexport function useDroppableCollectionState(props: DroppableCollectionStateOptions): DroppableCollectionState {\n let {\n acceptedDragTypes = 'all',\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);\n let targetRef = useRef<DropTarget>(null);\n\n let getOppositeTarget = (target: ItemDropTarget): ItemDropTarget => {\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 };\n\n let defaultGetDropOperation = useCallback((e: DropOperationEvent) => {\n let {\n target,\n types,\n allowedOperations,\n isInternal,\n draggingKeys\n } = e;\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 && 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 }, [acceptedDragTypes, getDropOperation, onInsert, onRootDrop, onItemDrop, shouldAcceptItemDrop, onReorder, onDrop]);\n\n return {\n collection,\n selectionManager,\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 setTarget(newTarget);\n targetRef.current = newTarget;\n },\n isDropTarget(dropTarget) {\n let target = targetRef.current;\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, b: DropTarget) {\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":"module.js.map"}
1
+ {"mappings":";;;SCqDgB,yCAA2B,CAAC,KAAsC,EAA4B,CAAC;IAC7G,GAAG,CAAC,CAAC,WACH,QAAQ,eACR,UAAU,qBACV,gBAAgB,gBAChB,WAAW,eACX,UAAU,cACV,SAAS,YACT,OAAO,6BACP,wBAAwB,EAC1B,CAAC,GAAG,KAAK;IACT,GAAG,IAAI,WAAW,IAAI,eAAQ,CAAC,KAAK;IACpC,GAAG,CAAC,YAAY,GAAG,aAAM,CAAC,GAAG,CAAC,GAAG;IACjC,GAAG,CAAC,UAAU,GAAG,aAAM,CAAC,IAAI;IAC5B,GAAG,CAAC,OAAO,IAAI,IAAQ,GAAK,CAAC;QAC3B,EAAmF,AAAnF,iFAAmF;QACnF,EAAqF,AAArF,mFAAqF;QACrF,EAAuD,AAAvD,qDAAuD;QACvD,GAAG,CAAC,IAAI,GAAG,GAAG,CAAC,GAAG,CAChB,gBAAgB,CAAC,UAAU,CAAC,IAAG,IAC3B,GAAG,CAAC,GAAG,CAAC,CAAC;eAAG,gBAAgB,CAAC,YAAY;QAAA,CAAC,CAAC,MAAM,EAAC,GAAG,KAAM,UAAU,CAAC,OAAO,CAAC,GAAG;aACjF,CAAC,CAAC;QAGR,IAAI,CAAC,GAAG,CAAC,IAAG;QACZ,MAAM,CAAC,IAAI;IACb,CAAC;IAED,MAAM,CAAC,CAAC;oBACN,UAAU;0BACV,gBAAgB;YACZ,UAAU,IAAG,CAAC;YAChB,MAAM,CAAC,UAAU,CAAC,OAAO;QAC3B,CAAC;YACG,YAAY,I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5D,uCAAiB,CAAC,UAAU,EAAE,iBAAiB,CAAC,MAAM;YAG1D,MAAM,CAAC,KAAK;QACd,CAAC;QACD,gBAAgB,EAAC,CAAC,EAAE,CAAC;YACnB,MAAM,CAAC,uBAAuB,CAAC,CAAC;QAClC,CAAC;IACH,CAAC;AACH,CAAC;SAEQ,uCAAiB,CAAC,CAAa,EAAE,CAAa,EAAE,CAAC;IACxD,EAAE,GAAG,CAAC,EACJ,MAAM,EAAE,CAAC;IAGX,MAAM,CAAE,CAAC,CAAC,IAAI;QACZ,IAAI,CAAC,CAAM;YACT,MAAM,EAAC,CAAC,aAAD,CAAC,KAAD,IAAI,CAAJ,CAAO,GAAP,IAAI,CAAJ,CAAO,GAAP,CAAC,CAAE,IAAI,MAAK,CAAM;QAC3B,IAAI,CAAC,CAAM;YACT,MAAM,EAAC,CAAC,aAAD,CAAC,KAAD,IAAI,CAAJ,CAAO,GAAP,IAAI,CAAJ,CAAO,GAAP,CAAC,CAAE,IAAI,MAAK,CAAM,UAAI,CAAC,aAAD,CAAC,KAAD,IAAI,CAAJ,CAAM,GAAN,IAAI,CAAJ,CAAM,GAAN,CAAC,CAAE,GAAG,MAAK,CAAC,CAAC,GAAG,KAAI,CAAC,aAAD,CAAC,KAAD,IAAI,CAAJ,CAAe,GAAf,IAAI,CAAJ,CAAe,GAAf,CAAC,CAAE,YAAY,MAAK,CAAC,CAAC,YAAY;;AAEzF,CAAC;;","sources":["packages/@react-stately/dnd/src/index.ts","packages/@react-stately/dnd/src/useDraggableCollectionState.ts","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\nexport type {DraggableCollectionStateOptions, DraggableCollectionState} from './useDraggableCollectionState';\nexport type {DroppableCollectionStateOptions, DroppableCollectionState} from './useDroppableCollectionState';\nexport {useDraggableCollectionState} from './useDraggableCollectionState';\nexport {useDroppableCollectionState} from './useDroppableCollectionState';\n","/*\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, Node} from '@react-types/shared';\nimport {Key, RefObject, useRef, useState} from 'react';\nimport {MultipleSelectionManager} from '@react-stately/selection';\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}\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 /** 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>,\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 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(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, the only the clicked\n // item is dragged. This matches native macOS behavior.\n let keys = new Set(\n selectionManager.isSelected(key)\n ? new Set([...selectionManager.selectedKeys].filter(key => !!collection.getItem(key)))\n : []\n );\n\n keys.add(key);\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 preview,\n getAllowedDropOperations,\n startDrag(key, event) {\n setDragging(true);\n let keys = getKeys(key);\n draggingKeys.current = keys;\n draggedKey.current = key;\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 setDragging(false);\n draggingKeys.current = new Set();\n draggedKey.current = null;\n }\n };\n}\n","/*\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, Node} from '@react-types/shared';\nimport {Key, useCallback, useRef, useState} from 'react';\nimport {MultipleSelectionManager} from '@react-stately/selection';\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}\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 /** Sets the current drop target. */\n setTarget(target: DropTarget): void,\n /** Returns whether the given target is equivalent to the current drop target. */\n isDropTarget(target: DropTarget): 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 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);\n let targetRef = useRef<DropTarget>(null);\n\n let getOppositeTarget = (target: ItemDropTarget): ItemDropTarget => {\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 };\n\n let defaultGetDropOperation = useCallback((e: DropOperationEvent) => {\n let {\n target,\n types,\n allowedOperations,\n isInternal,\n draggingKeys\n } = e;\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 && 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 }, [acceptedDragTypes, getDropOperation, onInsert, onRootDrop, onItemDrop, shouldAcceptItemDrop, onReorder, onDrop]);\n\n return {\n collection,\n selectionManager,\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;\n setTarget(newTarget);\n },\n isDropTarget(dropTarget) {\n let target = targetRef.current;\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, b: DropTarget) {\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":"module.js.map"}
package/dist/types.d.ts CHANGED
@@ -2,23 +2,40 @@ import { Collection, DraggableCollectionEndEvent, DraggableCollectionProps, Drag
2
2
  import { Key, RefObject } from "react";
3
3
  import { MultipleSelectionManager } from "@react-stately/selection";
4
4
  export interface DraggableCollectionStateOptions extends DraggableCollectionProps {
5
+ /** A collection of items. */
5
6
  collection: Collection<Node<unknown>>;
7
+ /** An interface for reading and updating multiple selection state. */
6
8
  selectionManager: MultipleSelectionManager;
7
9
  }
8
10
  export interface DraggableCollectionState {
11
+ /** A collection of items. */
9
12
  collection: Collection<Node<unknown>>;
13
+ /** An interface for reading and updating multiple selection state. */
10
14
  selectionManager: MultipleSelectionManager;
15
+ /** The key of the item that initiated a drag. */
11
16
  draggedKey: Key | null;
17
+ /** The keys of the items that are currently being dragged. */
12
18
  draggingKeys: Set<Key>;
19
+ /** Returns whether the given key is currently being dragged. */
13
20
  isDragging(key: Key): boolean;
21
+ /** Returns the keys of the items that will be dragged with the given key (e.g. selected items). */
14
22
  getKeysForDrag(key: Key): Set<Key>;
23
+ /** Returns the items to drag for the given key. */
15
24
  getItems(key: Key): DragItem[];
25
+ /** The ref of the element that will be rendered as the drag preview while dragging. */
16
26
  preview?: RefObject<DragPreviewRenderer>;
27
+ /** Function that returns the drop operations that are allowed for the dragged items. If not provided, all drop operations are allowed. */
17
28
  getAllowedDropOperations?: () => DropOperation[];
29
+ /** Begins a drag for the given key. This triggers the onDragStart event. */
18
30
  startDrag(key: Key, event: DragStartEvent): void;
31
+ /** Triggers an onDragMove event. */
19
32
  moveDrag(event: DragMoveEvent): void;
33
+ /** Ends the current drag, and emits an onDragEnd event. */
20
34
  endDrag(event: DraggableCollectionEndEvent): void;
21
35
  }
36
+ /**
37
+ * Manages state for a draggable collection.
38
+ */
22
39
  export function useDraggableCollectionState(props: DraggableCollectionStateOptions): DraggableCollectionState;
23
40
  interface DropOperationEvent {
24
41
  target: DropTarget;
@@ -28,17 +45,28 @@ interface DropOperationEvent {
28
45
  draggingKeys: Set<Key>;
29
46
  }
30
47
  export interface DroppableCollectionStateOptions extends Omit<DroppableCollectionProps, 'onDropMove' | 'onDropActivate'> {
48
+ /** A collection of items. */
31
49
  collection: Collection<Node<unknown>>;
50
+ /** An interface for reading and updating multiple selection state. */
32
51
  selectionManager: MultipleSelectionManager;
33
52
  }
34
53
  export interface DroppableCollectionState {
54
+ /** A collection of items. */
35
55
  collection: Collection<Node<unknown>>;
56
+ /** An interface for reading and updating multiple selection state. */
36
57
  selectionManager: MultipleSelectionManager;
37
- target: DropTarget;
58
+ /** The current drop target. */
59
+ target: DropTarget | null;
60
+ /** Sets the current drop target. */
38
61
  setTarget(target: DropTarget): void;
62
+ /** Returns whether the given target is equivalent to the current drop target. */
39
63
  isDropTarget(target: DropTarget): boolean;
64
+ /** Returns the drop operation for the given parameters. */
40
65
  getDropOperation(e: DropOperationEvent): DropOperation;
41
66
  }
67
+ /**
68
+ * Manages state for a droppable collection.
69
+ */
42
70
  export function useDroppableCollectionState(props: DroppableCollectionStateOptions): DroppableCollectionState;
43
71
 
44
72
  //# sourceMappingURL=types.d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BAAwB,CAAA;CAC3C;AAED;IACE,UAAU,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC;IACtC,gBAAgB,EAAE,wBAAwB,CAAC;IAC3C,MAAM,EAAE,UAAU,CAAC;IACnB,SAAS,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI,CAAC;IACpC,YAAY,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC;IAC1C,gBAAgB,CAAC,CAAC,EAAE,kBAAkB,GAAG,aAAa,CAAA;CACvD;AAED,4CAA4C,KAAK,EAAE,+BAA+B,GAAG,wBAAwB,CAgH5G","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"}
1
+ {"mappings":";;;AAgBA,gDAAiD,SAAQ,wBAAwB;IAC/E,6BAA6B;IAC7B,UAAU,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC;IACtC,sEAAsE;IACtE,gBAAgB,EAAE,wBAAwB,CAAA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AAK,OAAO,CAAC,CAAC,CAAC;IACtC,sEAAsE;IACtE,gBAAgB,EAAE,wBAAwB,CAAA;CAC3C;AAED;IACE,6BAA6B;IAC7B,UAAU,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC;IACtC,sEAAsE;IACtE,gBAAgB,EAAE,wBAAwB,CAAC;IAC3C,+BAA+B;IAC/B,MAAM,EAAE,UAAU,GAAG,IAAI,CAAC;IAC1B,oCAAoC;IACpC,SAAS,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI,CAAC;IACpC,iFAAiF;IACjF,YAAY,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC;IAC1C,2DAA2D;IAC3D,gBAAgB,CAAC,CAAC,EAAE,kBAAkB,GAAG,aAAa,CAAA;CACvD;AAED;;GAEG;AACH,4CAA4C,KAAK,EAAE,+BAA+B,GAAG,wBAAwB,CAgH5G","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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-stately/dnd",
3
- "version": "3.0.0-nightly.3491+25a36b7d4",
3
+ "version": "3.0.0-nightly.3506+5c9db40f1",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -18,8 +18,8 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "@babel/runtime": "^7.6.2",
21
- "@react-stately/selection": "3.0.0-nightly.1791+25a36b7d4",
22
- "@react-types/shared": "3.0.0-nightly.1791+25a36b7d4"
21
+ "@react-stately/selection": "3.0.0-nightly.1806+5c9db40f1",
22
+ "@react-types/shared": "3.0.0-nightly.1806+5c9db40f1"
23
23
  },
24
24
  "peerDependencies": {
25
25
  "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0"
@@ -27,5 +27,5 @@
27
27
  "publishConfig": {
28
28
  "access": "public"
29
29
  },
30
- "gitHead": "25a36b7d40a7b20ff9ea67850c456119788c64d6"
30
+ "gitHead": "5c9db40f10b9e68d4eab0268b9775baf2a840987"
31
31
  }
@@ -15,25 +15,42 @@ import {Key, RefObject, useRef, useState} from 'react';
15
15
  import {MultipleSelectionManager} from '@react-stately/selection';
16
16
 
17
17
  export interface DraggableCollectionStateOptions extends DraggableCollectionProps {
18
+ /** A collection of items. */
18
19
  collection: Collection<Node<unknown>>,
20
+ /** An interface for reading and updating multiple selection state. */
19
21
  selectionManager: MultipleSelectionManager
20
22
  }
21
23
 
22
24
  export interface DraggableCollectionState {
25
+ /** A collection of items. */
23
26
  collection: Collection<Node<unknown>>,
27
+ /** An interface for reading and updating multiple selection state. */
24
28
  selectionManager: MultipleSelectionManager,
29
+ /** The key of the item that initiated a drag. */
25
30
  draggedKey: Key | null,
31
+ /** The keys of the items that are currently being dragged. */
26
32
  draggingKeys: Set<Key>,
33
+ /** Returns whether the given key is currently being dragged. */
27
34
  isDragging(key: Key): boolean,
35
+ /** Returns the keys of the items that will be dragged with the given key (e.g. selected items). */
28
36
  getKeysForDrag(key: Key): Set<Key>,
37
+ /** Returns the items to drag for the given key. */
29
38
  getItems(key: Key): DragItem[],
39
+ /** The ref of the element that will be rendered as the drag preview while dragging. */
30
40
  preview?: RefObject<DragPreviewRenderer>,
41
+ /** Function that returns the drop operations that are allowed for the dragged items. If not provided, all drop operations are allowed. */
31
42
  getAllowedDropOperations?: () => DropOperation[],
43
+ /** Begins a drag for the given key. This triggers the onDragStart event. */
32
44
  startDrag(key: Key, event: DragStartEvent): void,
45
+ /** Triggers an onDragMove event. */
33
46
  moveDrag(event: DragMoveEvent): void,
47
+ /** Ends the current drag, and emits an onDragEnd event. */
34
48
  endDrag(event: DraggableCollectionEndEvent): void
35
49
  }
36
50
 
51
+ /**
52
+ * Manages state for a draggable collection.
53
+ */
37
54
  export function useDraggableCollectionState(props: DraggableCollectionStateOptions): DraggableCollectionState {
38
55
  let {
39
56
  getItems,
@@ -23,19 +23,30 @@ interface DropOperationEvent {
23
23
  }
24
24
 
25
25
  export interface DroppableCollectionStateOptions extends Omit<DroppableCollectionProps, 'onDropMove' | 'onDropActivate'> {
26
+ /** A collection of items. */
26
27
  collection: Collection<Node<unknown>>,
28
+ /** An interface for reading and updating multiple selection state. */
27
29
  selectionManager: MultipleSelectionManager
28
30
  }
29
31
 
30
32
  export interface DroppableCollectionState {
33
+ /** A collection of items. */
31
34
  collection: Collection<Node<unknown>>,
35
+ /** An interface for reading and updating multiple selection state. */
32
36
  selectionManager: MultipleSelectionManager,
33
- target: DropTarget,
37
+ /** The current drop target. */
38
+ target: DropTarget | null,
39
+ /** Sets the current drop target. */
34
40
  setTarget(target: DropTarget): void,
41
+ /** Returns whether the given target is equivalent to the current drop target. */
35
42
  isDropTarget(target: DropTarget): boolean,
43
+ /** Returns the drop operation for the given parameters. */
36
44
  getDropOperation(e: DropOperationEvent): DropOperation
37
45
  }
38
46
 
47
+ /**
48
+ * Manages state for a droppable collection.
49
+ */
39
50
  export function useDroppableCollectionState(props: DroppableCollectionStateOptions): DroppableCollectionState {
40
51
  let {
41
52
  acceptedDragTypes = 'all',
@@ -120,8 +131,8 @@ export function useDroppableCollectionState(props: DroppableCollectionStateOptio
120
131
  });
121
132
  }
122
133
 
123
- setTarget(newTarget);
124
134
  targetRef.current = newTarget;
135
+ setTarget(newTarget);
125
136
  },
126
137
  isDropTarget(dropTarget) {
127
138
  let target = targetRef.current;