@react-spectrum/dnd 3.5.8 → 3.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/types.d.ts
CHANGED
|
@@ -2,10 +2,10 @@ import { DraggableCollectionOptions, DraggableItemProps, DraggableItemResult, Dr
|
|
|
2
2
|
import { DraggableCollectionProps, DragItem, DroppableCollectionProps, Key, RefObject } from "@react-types/shared";
|
|
3
3
|
import { DraggableCollectionState, DraggableCollectionStateOptions, DroppableCollectionState, DroppableCollectionStateOptions } from "@react-stately/dnd";
|
|
4
4
|
import { JSX } from "react";
|
|
5
|
-
interface DraggableCollectionStateOpts extends Omit<DraggableCollectionStateOptions
|
|
5
|
+
interface DraggableCollectionStateOpts<T> extends Omit<DraggableCollectionStateOptions<T>, 'getItems'> {
|
|
6
6
|
}
|
|
7
|
-
interface DragHooks {
|
|
8
|
-
useDraggableCollectionState?: (props: DraggableCollectionStateOpts) => DraggableCollectionState;
|
|
7
|
+
interface DragHooks<T = object> {
|
|
8
|
+
useDraggableCollectionState?: (props: DraggableCollectionStateOpts<T>) => DraggableCollectionState;
|
|
9
9
|
useDraggableCollection?: (props: DraggableCollectionOptions, state: DraggableCollectionState, ref: RefObject<HTMLElement | null>) => void;
|
|
10
10
|
useDraggableItem?: (props: DraggableItemProps, state: DraggableCollectionState) => DraggableItemResult;
|
|
11
11
|
DragPreview?: typeof DragPreview;
|
|
@@ -16,26 +16,26 @@ interface DropHooks {
|
|
|
16
16
|
useDroppableItem?: (options: DroppableItemOptions, state: DroppableCollectionState, ref: RefObject<HTMLElement | null>) => DroppableItemResult;
|
|
17
17
|
useDropIndicator?: (props: DropIndicatorProps, state: DroppableCollectionState, ref: RefObject<HTMLElement | null>) => DropIndicatorAria;
|
|
18
18
|
}
|
|
19
|
-
export interface DragAndDropHooks {
|
|
19
|
+
export interface DragAndDropHooks<T = object> {
|
|
20
20
|
/** Drag and drop hooks for the collection element. */
|
|
21
|
-
dragAndDropHooks: DragHooks & DropHooks & {
|
|
21
|
+
dragAndDropHooks: DragHooks<T> & DropHooks & {
|
|
22
22
|
isVirtualDragging?: () => boolean;
|
|
23
23
|
renderPreview?: (keys: Set<Key>, draggedKey: Key) => JSX.Element;
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
|
-
export interface DragAndDropOptions extends Omit<DraggableCollectionProps, 'preview' | 'getItems'>, Omit<DroppableCollectionProps, 'onMove'> {
|
|
26
|
+
export interface DragAndDropOptions<T = object> extends Omit<DraggableCollectionProps, 'preview' | 'getItems'>, Omit<DroppableCollectionProps, 'onMove'> {
|
|
27
27
|
/**
|
|
28
28
|
* A function that returns the items being dragged. If not specified, we assume that the collection is not draggable.
|
|
29
29
|
* @default () => []
|
|
30
30
|
*/
|
|
31
|
-
getItems?: (keys: Set<Key
|
|
31
|
+
getItems?: (keys: Set<Key>, items: T[]) => DragItem[];
|
|
32
32
|
/** Provide a custom drag preview. `draggedKey` represents the key of the item the user actually dragged. */
|
|
33
33
|
renderPreview?: (keys: Set<Key>, draggedKey: Key) => JSX.Element;
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
36
36
|
* Provides the hooks required to enable drag and drop behavior for a drag and drop compatible React Spectrum component.
|
|
37
37
|
*/
|
|
38
|
-
export function useDragAndDrop(options: DragAndDropOptions): DragAndDropHooks;
|
|
38
|
+
export function useDragAndDrop<T = object>(options: DragAndDropOptions<T>): DragAndDropHooks;
|
|
39
39
|
export { DIRECTORY_DRAG_TYPE } from '@react-aria/dnd';
|
|
40
40
|
export type { DirectoryDropItem, DraggableCollectionEndEvent, DraggableCollectionMoveEvent, DraggableCollectionStartEvent, DragPreviewRenderer, DragTypes, DropItem, DropOperation, DroppableCollectionDropEvent, DroppableCollectionEnterEvent, DroppableCollectionExitEvent, DroppableCollectionInsertDropEvent, DroppableCollectionMoveEvent, DroppableCollectionOnItemDropEvent, DroppableCollectionReorderEvent, DroppableCollectionRootDropEvent, DropPosition, DropTarget, FileDropItem, ItemDropTar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/dnd/src/index.ts","packages/@react-spectrum/dnd/src/index.ts"],"sourcesContent":[null,null,"/*\n * Copyright 2022 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\n/// <reference types=\"css-module-types\" />\n\nexport type {DragAndDropOptions, DragAndDropHooks} from './useDragAndDrop';\nexport {useDragAndDrop} from './useDragAndDrop';\nexport {DIRECTORY_DRAG_TYPE} from '@react-aria/dnd';\n\nexport type {\n DirectoryDropItem,\n DraggableCollectionEndEvent,\n DraggableCollectionMoveEvent,\n DraggableCollectionStartEvent,\n DragPreviewRenderer,\n DragTypes,\n DropItem,\n DropOperation,\n DroppableCollectionDropEvent,\n DroppableCollectionEnterEvent,\n DroppableCollectionExitEvent,\n DroppableCollectionInsertDropEvent,\n DroppableCollectionMoveEvent,\n DroppableCollectionOnItemDropEvent,\n DroppableCollectionReorderEvent,\n DroppableCollectionRootDropEvent,\n DropPosition,\n DropTarget,\n FileDropItem,\n ItemDropTarget,\n RootDropTarget,\n TextDropItem\n} from '@react-types/shared';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;AAiEM,SAAS,
|
|
1
|
+
{"mappings":";;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;AAiEM,SAAS,0CAA2B,OAA8B;IACvE,IAAI,mBAAmB,CAAA,GAAA,oBAAM,EAAE;QAC7B,IAAI,UACF,MAAM,YACN,QAAQ,cACR,UAAU,aACV,SAAS,cACT,UAAU,YACV,QAAQ,iBACR,aAAa,EACb,GAAG;QAEL,IAAI,cAAc,CAAC,CAAC;QACpB,IAAI,cAAc,CAAC,CAAE,CAAA,UAAU,YAAY,cAAc,aAAa,UAAS;QAE/E,IAAI,QAAQ,CAAC;QACb,IAAI,aAAa;YACf,MAAM,2BAA2B,GAAG,SAAS,oCAAoC,KAAsC;gBACrH,OAAO,CAAA,GAAA,kDAA0B,EAAE;oBAAC,GAAG,KAAK;oBAAE,GAAG,OAAO;oBAAE,UAAU,QAAQ,QAAQ;gBAAC;YACvF;YACA,MAAM,sBAAsB,GAAG,CAAA,GAAA,0CAAqB;YACpD,MAAM,gBAAgB,GAAG,CAAA,GAAA,oCAAe;YACxC,MAAM,WAAW,GAAG,CAAA,GAAA,+BAAU;YAC9B,MAAM,aAAa,GAAG;QACxB;QAEA,IAAI,aAAa;YACf,MAAM,2BAA2B,GAAG,SAAS,oCAAoC,KAAsC;gBACrH,OAAO,CAAA,GAAA,kDAA0B,EAAE;oBAAC,GAAG,KAAK;oBAAE,GAAG,OAAO;gBAAA;YAC1D;YACA,MAAM,gBAAgB,GAAG,CAAA,GAAA,oCAAe;YACxC,MAAM,sBAAsB,GAAG,SAAS,+BAA+B,KAAiC,EAAE,KAA+B,EAAE,GAAkC;gBAC3K,OAAO,CAAA,GAAA,0CAAqB,EAAE;oBAAC,GAAG,KAAK;oBAAE,GAAG,OAAO;gBAAA,GAAG,OAAO;YAC/D;YACA,MAAM,gBAAgB,GAAG,CAAA,GAAA,oCAAe;QAC1C;QAEA,IAAI,eAAe,aACjB,MAAM,iBAAiB,GAAG,CAAA,GAAA,qCAAgB;QAG5C,OAAO;IACT,GAAG;QAAC;KAAQ;IAEZ,OAAO;QACL,kBAAkB;IACpB;AACF","sources":["packages/@react-spectrum/dnd/src/useDragAndDrop.ts"],"sourcesContent":["/*\n * Copyright 2022 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 {\n DraggableCollectionOptions,\n DraggableItemProps,\n DraggableItemResult,\n DragPreview,\n DropIndicatorAria,\n DropIndicatorProps,\n DroppableCollectionOptions,\n DroppableCollectionResult,\n DroppableItemOptions,\n DroppableItemResult,\n isVirtualDragging,\n useDraggableCollection,\n useDraggableItem,\n useDropIndicator,\n useDroppableCollection,\n useDroppableItem\n} from '@react-aria/dnd';\nimport {DraggableCollectionProps, DragItem, DroppableCollectionProps, Key, RefObject} from '@react-types/shared';\nimport {\n DraggableCollectionState,\n DraggableCollectionStateOptions,\n DroppableCollectionState,\n DroppableCollectionStateOptions,\n useDraggableCollectionState,\n useDroppableCollectionState\n} from '@react-stately/dnd';\nimport {JSX, useMemo} from 'react';\n\ninterface DraggableCollectionStateOpts<T> extends Omit<DraggableCollectionStateOptions<T>, 'getItems'> {}\n\ninterface DragHooks<T = object> {\n useDraggableCollectionState?: (props: DraggableCollectionStateOpts<T>) => DraggableCollectionState,\n useDraggableCollection?: (props: DraggableCollectionOptions, state: DraggableCollectionState, ref: RefObject<HTMLElement | null>) => void,\n useDraggableItem?: (props: DraggableItemProps, state: DraggableCollectionState) => DraggableItemResult,\n DragPreview?: typeof DragPreview\n}\n\ninterface DropHooks {\n useDroppableCollectionState?: (props: DroppableCollectionStateOptions) => DroppableCollectionState,\n useDroppableCollection?: (props: DroppableCollectionOptions, state: DroppableCollectionState, ref: RefObject<HTMLElement | null>) => DroppableCollectionResult,\n useDroppableItem?: (options: DroppableItemOptions, state: DroppableCollectionState, ref: RefObject<HTMLElement | null>) => DroppableItemResult,\n useDropIndicator?: (props: DropIndicatorProps, state: DroppableCollectionState, ref: RefObject<HTMLElement | null>) => DropIndicatorAria\n}\n\nexport interface DragAndDropHooks<T = object> {\n /** Drag and drop hooks for the collection element. */\n dragAndDropHooks: DragHooks<T> & DropHooks & {isVirtualDragging?: () => boolean, renderPreview?: (keys: Set<Key>, draggedKey: Key) => JSX.Element}\n}\n\nexport interface DragAndDropOptions<T = object> extends Omit<DraggableCollectionProps, 'preview' | 'getItems'>, Omit<DroppableCollectionProps, 'onMove'> {\n /**\n * A function that returns the items being dragged. If not specified, we assume that the collection is not draggable.\n * @default () => []\n */\n getItems?: (keys: Set<Key>, items: T[]) => DragItem[],\n /** Provide a custom drag preview. `draggedKey` represents the key of the item the user actually dragged. */\n renderPreview?: (keys: Set<Key>, draggedKey: Key) => JSX.Element\n}\n\n/**\n * Provides the hooks required to enable drag and drop behavior for a drag and drop compatible React Spectrum component.\n */\nexport function useDragAndDrop<T = object>(options: DragAndDropOptions<T>): DragAndDropHooks {\n let dragAndDropHooks = useMemo(() => {\n let {\n onDrop,\n onInsert,\n onItemDrop,\n onReorder,\n onRootDrop,\n getItems,\n renderPreview\n } = options;\n\n let isDraggable = !!getItems;\n let isDroppable = !!(onDrop || onInsert || onItemDrop || onReorder || onRootDrop);\n\n let hooks = {} as DragHooks & DropHooks & {isVirtualDragging?: () => boolean, renderPreview?: (keys: Set<Key>, draggedKey: Key) => JSX.Element};\n if (isDraggable) {\n hooks.useDraggableCollectionState = function useDraggableCollectionStateOverride(props: DraggableCollectionStateOpts<T>) {\n return useDraggableCollectionState({...props, ...options, getItems: options.getItems!});\n };\n hooks.useDraggableCollection = useDraggableCollection;\n hooks.useDraggableItem = useDraggableItem;\n hooks.DragPreview = DragPreview;\n hooks.renderPreview = renderPreview;\n }\n\n if (isDroppable) {\n hooks.useDroppableCollectionState = function useDroppableCollectionStateOverride(props: DroppableCollectionStateOptions) {\n return useDroppableCollectionState({...props, ...options});\n };\n hooks.useDroppableItem = useDroppableItem;\n hooks.useDroppableCollection = function useDroppableCollectionOverride(props: DroppableCollectionOptions, state: DroppableCollectionState, ref: RefObject<HTMLElement | null>) {\n return useDroppableCollection({...props, ...options}, state, ref);\n };\n hooks.useDropIndicator = useDropIndicator;\n }\n\n if (isDraggable || isDroppable) {\n hooks.isVirtualDragging = isVirtualDragging;\n }\n\n return hooks;\n }, [options]);\n\n return {\n dragAndDropHooks: dragAndDropHooks\n };\n}\n"],"names":[],"version":3,"file":"useDragAndDrop.main.js.map"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;AAAA;;;;;;;;;;CAUC;;;AAiEM,SAAS,
|
|
1
|
+
{"mappings":";;;;AAAA;;;;;;;;;;CAUC;;;AAiEM,SAAS,0CAA2B,OAA8B;IACvE,IAAI,mBAAmB,CAAA,GAAA,cAAM,EAAE;QAC7B,IAAI,UACF,MAAM,YACN,QAAQ,cACR,UAAU,aACV,SAAS,cACT,UAAU,YACV,QAAQ,iBACR,aAAa,EACb,GAAG;QAEL,IAAI,cAAc,CAAC,CAAC;QACpB,IAAI,cAAc,CAAC,CAAE,CAAA,UAAU,YAAY,cAAc,aAAa,UAAS;QAE/E,IAAI,QAAQ,CAAC;QACb,IAAI,aAAa;YACf,MAAM,2BAA2B,GAAG,SAAS,oCAAoC,KAAsC;gBACrH,OAAO,CAAA,GAAA,kCAA0B,EAAE;oBAAC,GAAG,KAAK;oBAAE,GAAG,OAAO;oBAAE,UAAU,QAAQ,QAAQ;gBAAC;YACvF;YACA,MAAM,sBAAsB,GAAG,CAAA,GAAA,6BAAqB;YACpD,MAAM,gBAAgB,GAAG,CAAA,GAAA,uBAAe;YACxC,MAAM,WAAW,GAAG,CAAA,GAAA,kBAAU;YAC9B,MAAM,aAAa,GAAG;QACxB;QAEA,IAAI,aAAa;YACf,MAAM,2BAA2B,GAAG,SAAS,oCAAoC,KAAsC;gBACrH,OAAO,CAAA,GAAA,kCAA0B,EAAE;oBAAC,GAAG,KAAK;oBAAE,GAAG,OAAO;gBAAA;YAC1D;YACA,MAAM,gBAAgB,GAAG,CAAA,GAAA,uBAAe;YACxC,MAAM,sBAAsB,GAAG,SAAS,+BAA+B,KAAiC,EAAE,KAA+B,EAAE,GAAkC;gBAC3K,OAAO,CAAA,GAAA,6BAAqB,EAAE;oBAAC,GAAG,KAAK;oBAAE,GAAG,OAAO;gBAAA,GAAG,OAAO;YAC/D;YACA,MAAM,gBAAgB,GAAG,CAAA,GAAA,uBAAe;QAC1C;QAEA,IAAI,eAAe,aACjB,MAAM,iBAAiB,GAAG,CAAA,GAAA,wBAAgB;QAG5C,OAAO;IACT,GAAG;QAAC;KAAQ;IAEZ,OAAO;QACL,kBAAkB;IACpB;AACF","sources":["packages/@react-spectrum/dnd/src/useDragAndDrop.ts"],"sourcesContent":["/*\n * Copyright 2022 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 {\n DraggableCollectionOptions,\n DraggableItemProps,\n DraggableItemResult,\n DragPreview,\n DropIndicatorAria,\n DropIndicatorProps,\n DroppableCollectionOptions,\n DroppableCollectionResult,\n DroppableItemOptions,\n DroppableItemResult,\n isVirtualDragging,\n useDraggableCollection,\n useDraggableItem,\n useDropIndicator,\n useDroppableCollection,\n useDroppableItem\n} from '@react-aria/dnd';\nimport {DraggableCollectionProps, DragItem, DroppableCollectionProps, Key, RefObject} from '@react-types/shared';\nimport {\n DraggableCollectionState,\n DraggableCollectionStateOptions,\n DroppableCollectionState,\n DroppableCollectionStateOptions,\n useDraggableCollectionState,\n useDroppableCollectionState\n} from '@react-stately/dnd';\nimport {JSX, useMemo} from 'react';\n\ninterface DraggableCollectionStateOpts<T> extends Omit<DraggableCollectionStateOptions<T>, 'getItems'> {}\n\ninterface DragHooks<T = object> {\n useDraggableCollectionState?: (props: DraggableCollectionStateOpts<T>) => DraggableCollectionState,\n useDraggableCollection?: (props: DraggableCollectionOptions, state: DraggableCollectionState, ref: RefObject<HTMLElement | null>) => void,\n useDraggableItem?: (props: DraggableItemProps, state: DraggableCollectionState) => DraggableItemResult,\n DragPreview?: typeof DragPreview\n}\n\ninterface DropHooks {\n useDroppableCollectionState?: (props: DroppableCollectionStateOptions) => DroppableCollectionState,\n useDroppableCollection?: (props: DroppableCollectionOptions, state: DroppableCollectionState, ref: RefObject<HTMLElement | null>) => DroppableCollectionResult,\n useDroppableItem?: (options: DroppableItemOptions, state: DroppableCollectionState, ref: RefObject<HTMLElement | null>) => DroppableItemResult,\n useDropIndicator?: (props: DropIndicatorProps, state: DroppableCollectionState, ref: RefObject<HTMLElement | null>) => DropIndicatorAria\n}\n\nexport interface DragAndDropHooks<T = object> {\n /** Drag and drop hooks for the collection element. */\n dragAndDropHooks: DragHooks<T> & DropHooks & {isVirtualDragging?: () => boolean, renderPreview?: (keys: Set<Key>, draggedKey: Key) => JSX.Element}\n}\n\nexport interface DragAndDropOptions<T = object> extends Omit<DraggableCollectionProps, 'preview' | 'getItems'>, Omit<DroppableCollectionProps, 'onMove'> {\n /**\n * A function that returns the items being dragged. If not specified, we assume that the collection is not draggable.\n * @default () => []\n */\n getItems?: (keys: Set<Key>, items: T[]) => DragItem[],\n /** Provide a custom drag preview. `draggedKey` represents the key of the item the user actually dragged. */\n renderPreview?: (keys: Set<Key>, draggedKey: Key) => JSX.Element\n}\n\n/**\n * Provides the hooks required to enable drag and drop behavior for a drag and drop compatible React Spectrum component.\n */\nexport function useDragAndDrop<T = object>(options: DragAndDropOptions<T>): DragAndDropHooks {\n let dragAndDropHooks = useMemo(() => {\n let {\n onDrop,\n onInsert,\n onItemDrop,\n onReorder,\n onRootDrop,\n getItems,\n renderPreview\n } = options;\n\n let isDraggable = !!getItems;\n let isDroppable = !!(onDrop || onInsert || onItemDrop || onReorder || onRootDrop);\n\n let hooks = {} as DragHooks & DropHooks & {isVirtualDragging?: () => boolean, renderPreview?: (keys: Set<Key>, draggedKey: Key) => JSX.Element};\n if (isDraggable) {\n hooks.useDraggableCollectionState = function useDraggableCollectionStateOverride(props: DraggableCollectionStateOpts<T>) {\n return useDraggableCollectionState({...props, ...options, getItems: options.getItems!});\n };\n hooks.useDraggableCollection = useDraggableCollection;\n hooks.useDraggableItem = useDraggableItem;\n hooks.DragPreview = DragPreview;\n hooks.renderPreview = renderPreview;\n }\n\n if (isDroppable) {\n hooks.useDroppableCollectionState = function useDroppableCollectionStateOverride(props: DroppableCollectionStateOptions) {\n return useDroppableCollectionState({...props, ...options});\n };\n hooks.useDroppableItem = useDroppableItem;\n hooks.useDroppableCollection = function useDroppableCollectionOverride(props: DroppableCollectionOptions, state: DroppableCollectionState, ref: RefObject<HTMLElement | null>) {\n return useDroppableCollection({...props, ...options}, state, ref);\n };\n hooks.useDropIndicator = useDropIndicator;\n }\n\n if (isDraggable || isDroppable) {\n hooks.isVirtualDragging = isVirtualDragging;\n }\n\n return hooks;\n }, [options]);\n\n return {\n dragAndDropHooks: dragAndDropHooks\n };\n}\n"],"names":[],"version":3,"file":"useDragAndDrop.module.js.map"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-spectrum/dnd",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.6.1",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -40,9 +40,9 @@
|
|
|
40
40
|
"url": "https://github.com/adobe/react-spectrum"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@react-aria/dnd": "^3.11.
|
|
44
|
-
"@react-stately/dnd": "^3.
|
|
45
|
-
"@react-types/shared": "^3.
|
|
43
|
+
"@react-aria/dnd": "^3.11.2",
|
|
44
|
+
"@react-stately/dnd": "^3.7.0",
|
|
45
|
+
"@react-types/shared": "^3.32.0",
|
|
46
46
|
"@swc/helpers": "^0.5.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
@@ -56,5 +56,5 @@
|
|
|
56
56
|
"publishConfig": {
|
|
57
57
|
"access": "public"
|
|
58
58
|
},
|
|
59
|
-
"gitHead": "
|
|
59
|
+
"gitHead": "ed4815e15c9d1659208fa687e8c3a094879854bb"
|
|
60
60
|
}
|
package/src/useDragAndDrop.ts
CHANGED
|
@@ -39,10 +39,10 @@ import {
|
|
|
39
39
|
} from '@react-stately/dnd';
|
|
40
40
|
import {JSX, useMemo} from 'react';
|
|
41
41
|
|
|
42
|
-
interface DraggableCollectionStateOpts extends Omit<DraggableCollectionStateOptions
|
|
42
|
+
interface DraggableCollectionStateOpts<T> extends Omit<DraggableCollectionStateOptions<T>, 'getItems'> {}
|
|
43
43
|
|
|
44
|
-
interface DragHooks {
|
|
45
|
-
useDraggableCollectionState?: (props: DraggableCollectionStateOpts) => DraggableCollectionState,
|
|
44
|
+
interface DragHooks<T = object> {
|
|
45
|
+
useDraggableCollectionState?: (props: DraggableCollectionStateOpts<T>) => DraggableCollectionState,
|
|
46
46
|
useDraggableCollection?: (props: DraggableCollectionOptions, state: DraggableCollectionState, ref: RefObject<HTMLElement | null>) => void,
|
|
47
47
|
useDraggableItem?: (props: DraggableItemProps, state: DraggableCollectionState) => DraggableItemResult,
|
|
48
48
|
DragPreview?: typeof DragPreview
|
|
@@ -55,17 +55,17 @@ interface DropHooks {
|
|
|
55
55
|
useDropIndicator?: (props: DropIndicatorProps, state: DroppableCollectionState, ref: RefObject<HTMLElement | null>) => DropIndicatorAria
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
-
export interface DragAndDropHooks {
|
|
58
|
+
export interface DragAndDropHooks<T = object> {
|
|
59
59
|
/** Drag and drop hooks for the collection element. */
|
|
60
|
-
dragAndDropHooks: DragHooks & DropHooks & {isVirtualDragging?: () => boolean, renderPreview?: (keys: Set<Key>, draggedKey: Key) => JSX.Element}
|
|
60
|
+
dragAndDropHooks: DragHooks<T> & DropHooks & {isVirtualDragging?: () => boolean, renderPreview?: (keys: Set<Key>, draggedKey: Key) => JSX.Element}
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
export interface DragAndDropOptions extends Omit<DraggableCollectionProps, 'preview' | 'getItems'>, Omit<DroppableCollectionProps, 'onMove'> {
|
|
63
|
+
export interface DragAndDropOptions<T = object> extends Omit<DraggableCollectionProps, 'preview' | 'getItems'>, Omit<DroppableCollectionProps, 'onMove'> {
|
|
64
64
|
/**
|
|
65
65
|
* A function that returns the items being dragged. If not specified, we assume that the collection is not draggable.
|
|
66
66
|
* @default () => []
|
|
67
67
|
*/
|
|
68
|
-
getItems?: (keys: Set<Key
|
|
68
|
+
getItems?: (keys: Set<Key>, items: T[]) => DragItem[],
|
|
69
69
|
/** Provide a custom drag preview. `draggedKey` represents the key of the item the user actually dragged. */
|
|
70
70
|
renderPreview?: (keys: Set<Key>, draggedKey: Key) => JSX.Element
|
|
71
71
|
}
|
|
@@ -73,7 +73,7 @@ export interface DragAndDropOptions extends Omit<DraggableCollectionProps, 'prev
|
|
|
73
73
|
/**
|
|
74
74
|
* Provides the hooks required to enable drag and drop behavior for a drag and drop compatible React Spectrum component.
|
|
75
75
|
*/
|
|
76
|
-
export function useDragAndDrop(options: DragAndDropOptions): DragAndDropHooks {
|
|
76
|
+
export function useDragAndDrop<T = object>(options: DragAndDropOptions<T>): DragAndDropHooks {
|
|
77
77
|
let dragAndDropHooks = useMemo(() => {
|
|
78
78
|
let {
|
|
79
79
|
onDrop,
|
|
@@ -90,7 +90,7 @@ export function useDragAndDrop(options: DragAndDropOptions): DragAndDropHooks {
|
|
|
90
90
|
|
|
91
91
|
let hooks = {} as DragHooks & DropHooks & {isVirtualDragging?: () => boolean, renderPreview?: (keys: Set<Key>, draggedKey: Key) => JSX.Element};
|
|
92
92
|
if (isDraggable) {
|
|
93
|
-
hooks.useDraggableCollectionState = function useDraggableCollectionStateOverride(props: DraggableCollectionStateOpts) {
|
|
93
|
+
hooks.useDraggableCollectionState = function useDraggableCollectionStateOverride(props: DraggableCollectionStateOpts<T>) {
|
|
94
94
|
return useDraggableCollectionState({...props, ...options, getItems: options.getItems!});
|
|
95
95
|
};
|
|
96
96
|
hooks.useDraggableCollection = useDraggableCollection;
|