@react-stately/dnd 3.6.1 → 3.7.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Collection, DraggableCollectionEndEvent, DraggableCollectionProps, DragItem, DragMoveEvent, DragPreviewRenderer, DragStartEvent, DropOperation, Key, Node, RefObject, DragTypes, DroppableCollectionProps, DropTarget } from "@react-types/shared";
2
2
  import { MultipleSelectionManager } from "@react-stately/selection";
3
- export interface DraggableCollectionStateOptions extends DraggableCollectionProps {
3
+ export interface DraggableCollectionStateOptions<T = object> extends DraggableCollectionProps<T> {
4
4
  /** A collection of items. */
5
5
  collection: Collection<Node<unknown>>;
6
6
  /** An interface for reading and updating multiple selection state. */
@@ -39,7 +39,7 @@ export interface DraggableCollectionState {
39
39
  /**
40
40
  * Manages state for a draggable collection.
41
41
  */
42
- export function useDraggableCollectionState(props: DraggableCollectionStateOptions): DraggableCollectionState;
42
+ export function useDraggableCollectionState<T = object>(props: DraggableCollectionStateOptions<T>): DraggableCollectionState;
43
43
  interface DropOperationEvent {
44
44
  target: DropTarget;
45
45
  types: DragTypes;
@@ -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,wC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AAC,CAAC;IACtC,sEAAsE;IACtE,gBAAgB,EAAE,wBAAwB,CAAC;IAC3C,+BAA+B;IAC/B,MAAM,EAAE,UAAU,GAAG,IAAI,CAAC;IAC1B,wCAAwC;IACxC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,oCAAoC;IACpC,SAAS,CAAC,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"}
1
+ {"mappings":";;AAgBA,iDAAiD,CAAC,GAAG,MAAM,CAAE,SAA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,MAAM,EAAE,UAAU,CAAC;IACnB,KAAK,EAAE,SAAS,CAAC;IACjB,iBAAiB,EAAE,aAAa,EAAE,CAAC;IACnC,UAAU,EAAE,OAAO,CAAC;IACpB,YAAY,EAAE,GAAG,CAAC,GAAG,CAAC,CAAA;CACvB;AAED,gDAAiD,SAAQ,IAAI,CAAC,wBAAwB,EAAE,YAAY,GAAG,gBAAgB,CAAC;IACtH,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,+BAA+B;IAC/B,MAAM,EAAE,UAAU,GAAG,IAAI,CAAC;IAC1B,wCAAwC;IACxC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,oCAAoC;IACpC,SAAS,CAAC,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"}
@@ -62,7 +62,14 @@ function $481a240e3d51b276$export$29efd034f1d79f81(props) {
62
62
  },
63
63
  getKeysForDrag: getKeys,
64
64
  getItems (key) {
65
- return getItems(getKeys(key));
65
+ let keys = getKeys(key);
66
+ let items = [];
67
+ for (let key of keys){
68
+ var _collection_getItem;
69
+ let value = (_collection_getItem = collection.getItem(key)) === null || _collection_getItem === void 0 ? void 0 : _collection_getItem.value;
70
+ if (value != null) items.push(value);
71
+ }
72
+ return getItems(getKeys(key), items);
66
73
  },
67
74
  isDisabled: isDisabled,
68
75
  preview: preview,
@@ -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,sFAAsF;QACtF,uDAAuD;QACvD,2FAA2F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ACF;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"}
1
+ {"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC;AA+CM,SAAS,0CAAwC,KAAyC;IAC/F,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,sFAAsF;QACtF,uDAAuD;QACvD,2FAA2F;QAC3F,IAAI,OAAO,IAAI;QACf,IAAI,iBAAiB,UAAU,CAAC,MAC9B,KAAK,IAAI,cAAc,iBAAiB,YAAY,CAAE;YACpD,IAAI,OAAO,WAAW,OAAO,CAAC;YAC9B,IAAI,MAAM;gBACR,IAAI,UAAU;gBACd,IAAI,YAAY,KAAK,SAAS;gBAC9B,MAAO,aAAa,KAAM;oBACxB,qCAAqC;oBACrC,IAAI,iBAAiB,YAAY,CAAC,GAAG,CAAC,YAAY;wBAChD,UAAU;wBACV;oBACF;oBACA,IAAI,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,IAAI,OAAO,QAAQ;YACnB,IAAI,QAAe,EAAE;YACrB,KAAK,IAAI,OAAO,KAAM;oBACR;gBAAZ,IAAI,SAAQ,sBAAA,WAAW,OAAO,CAAC,kBAAnB,0CAAA,oBAAyB,KAAK;gBAC1C,IAAI,SAAS,MACX,MAAM,IAAI,CAAC;YAEf;YAEA,OAAO,SAAS,QAAQ,MAAM;QAChC;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<T = object> extends DraggableCollectionProps<T> {\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<T = object>(props: DraggableCollectionStateOptions<T>): 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 let keys = getKeys(key);\n let items: any[] = [];\n for (let key of keys) {\n let value = collection.getItem(key)?.value;\n if (value != null) {\n items.push(value);\n }\n }\n\n return getItems(getKeys(key), items);\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"}
@@ -56,7 +56,14 @@ function $b45bbbaf0c3785df$export$29efd034f1d79f81(props) {
56
56
  },
57
57
  getKeysForDrag: getKeys,
58
58
  getItems (key) {
59
- return getItems(getKeys(key));
59
+ let keys = getKeys(key);
60
+ let items = [];
61
+ for (let key of keys){
62
+ var _collection_getItem;
63
+ let value = (_collection_getItem = collection.getItem(key)) === null || _collection_getItem === void 0 ? void 0 : _collection_getItem.value;
64
+ if (value != null) items.push(value);
65
+ }
66
+ return getItems(getKeys(key), items);
60
67
  },
61
68
  isDisabled: isDisabled,
62
69
  preview: preview,
@@ -56,7 +56,14 @@ function $b45bbbaf0c3785df$export$29efd034f1d79f81(props) {
56
56
  },
57
57
  getKeysForDrag: getKeys,
58
58
  getItems (key) {
59
- return getItems(getKeys(key));
59
+ let keys = getKeys(key);
60
+ let items = [];
61
+ for (let key of keys){
62
+ var _collection_getItem;
63
+ let value = (_collection_getItem = collection.getItem(key)) === null || _collection_getItem === void 0 ? void 0 : _collection_getItem.value;
64
+ if (value != null) items.push(value);
65
+ }
66
+ return getItems(getKeys(key), items);
60
67
  },
61
68
  isDisabled: isDisabled,
62
69
  preview: preview,
@@ -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,eAAO,EAAE;IAC/B,IAAI,eAAe,CAAA,GAAA,aAAK,EAAE,IAAI;IAC9B,IAAI,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ACF,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"}
1
+ {"mappings":";;AAAA;;;;;;;;;;CAUC;AA+CM,SAAS,0CAAwC,KAAyC;IAC/F,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,eAAO,EAAE;IAC/B,IAAI,eAAe,CAAA,GAAA,aAAK,EAAE,IAAI;IAC9B,IAAI,aAAa,CAAA,GAAA,aAAK,EAAc;IACpC,IAAI,UAAU,CAAC;QACb,mFAAmF;QACnF,sFAAsF;QACtF,uDAAuD;QACvD,2FAA2F;QAC3F,IAAI,OAAO,IAAI;QACf,IAAI,iBAAiB,UAAU,CAAC,MAC9B,KAAK,IAAI,cAAc,iBAAiB,YAAY,CAAE;YACpD,IAAI,OAAO,WAAW,OAAO,CAAC;YAC9B,IAAI,MAAM;gBACR,IAAI,UAAU;gBACd,IAAI,YAAY,KAAK,SAAS;gBAC9B,MAAO,aAAa,KAAM;oBACxB,qCAAqC;oBACrC,IAAI,iBAAiB,YAAY,CAAC,GAAG,CAAC,YAAY;wBAChD,UAAU;wBACV;oBACF;oBACA,IAAI,aAAa,WAAW,OAAO,CAAC;oBACpC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 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<T = object> extends DraggableCollectionProps<T> {\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<T = object>(props: DraggableCollectionStateOptions<T>): 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 let keys = getKeys(key);\n let items: any[] = [];\n for (let key of keys) {\n let value = collection.getItem(key)?.value;\n if (value != null) {\n items.push(value);\n }\n }\n\n return getItems(getKeys(key), items);\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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-stately/dnd",
3
- "version": "3.6.1",
3
+ "version": "3.7.1",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -26,8 +26,8 @@
26
26
  "url": "https://github.com/adobe/react-spectrum"
27
27
  },
28
28
  "dependencies": {
29
- "@react-stately/selection": "^3.20.4",
30
- "@react-types/shared": "^3.31.0",
29
+ "@react-stately/selection": "^3.20.6",
30
+ "@react-types/shared": "^3.32.1",
31
31
  "@swc/helpers": "^0.5.0"
32
32
  },
33
33
  "peerDependencies": {
@@ -36,5 +36,5 @@
36
36
  "publishConfig": {
37
37
  "access": "public"
38
38
  },
39
- "gitHead": "8b9348ff255e018b2dd9b27e2a45507cadfa1d35"
39
+ "gitHead": "0bda51183baa23306342af32a82012ea0fe0f2dc"
40
40
  }
@@ -14,7 +14,7 @@ import {Collection, DraggableCollectionEndEvent, DraggableCollectionProps, DragI
14
14
  import {MultipleSelectionManager} from '@react-stately/selection';
15
15
  import {useRef, useState} from 'react';
16
16
 
17
- export interface DraggableCollectionStateOptions extends DraggableCollectionProps {
17
+ export interface DraggableCollectionStateOptions<T = object> extends DraggableCollectionProps<T> {
18
18
  /** A collection of items. */
19
19
  collection: Collection<Node<unknown>>,
20
20
  /** An interface for reading and updating multiple selection state. */
@@ -55,7 +55,7 @@ export interface DraggableCollectionState {
55
55
  /**
56
56
  * Manages state for a draggable collection.
57
57
  */
58
- export function useDraggableCollectionState(props: DraggableCollectionStateOptions): DraggableCollectionState {
58
+ export function useDraggableCollectionState<T = object>(props: DraggableCollectionStateOptions<T>): DraggableCollectionState {
59
59
  let {
60
60
  getItems,
61
61
  isDisabled,
@@ -118,7 +118,16 @@ export function useDraggableCollectionState(props: DraggableCollectionStateOptio
118
118
  },
119
119
  getKeysForDrag: getKeys,
120
120
  getItems(key) {
121
- return getItems(getKeys(key));
121
+ let keys = getKeys(key);
122
+ let items: any[] = [];
123
+ for (let key of keys) {
124
+ let value = collection.getItem(key)?.value;
125
+ if (value != null) {
126
+ items.push(value);
127
+ }
128
+ }
129
+
130
+ return getItems(getKeys(key), items);
122
131
  },
123
132
  isDisabled,
124
133
  preview,