-
-
Notifications
You must be signed in to change notification settings - Fork 596
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve default sortableKeyboardCoordinates getter
- Loading branch information
Showing
11 changed files
with
122 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@dnd-kit/core': patch | ||
--- | ||
|
||
The `Data` and `DataRef` types are now exported by `@dnd-kit/core`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import type {UniqueIdentifier} from '@dnd-kit/core'; | ||
|
||
export type SortableData = { | ||
sortable: { | ||
containerId: UniqueIdentifier; | ||
items: UniqueIdentifier[]; | ||
index: number; | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,3 @@ | ||
import type {ClientRect} from '@dnd-kit/core'; | ||
import type {Transform} from '@dnd-kit/utilities'; | ||
|
||
export type SortingStrategy = (args: { | ||
activeNodeRect: ClientRect | null; | ||
activeIndex: number; | ||
index: number; | ||
rects: ClientRect[]; | ||
overIndex: number; | ||
}) => Transform | null; | ||
export type {SortableData} from './data'; | ||
export type {SortingStrategy} from './strategies'; | ||
export {hasSortableData} from './type-guard'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import type {ClientRect} from '@dnd-kit/core'; | ||
import type {Transform} from '@dnd-kit/utilities'; | ||
|
||
export type SortingStrategy = (args: { | ||
activeNodeRect: ClientRect | null; | ||
activeIndex: number; | ||
index: number; | ||
rects: ClientRect[]; | ||
overIndex: number; | ||
}) => Transform | null; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import type {Data, DroppableContainer, DraggableNode} from '@dnd-kit/core'; | ||
|
||
import type {SortableData} from './data'; | ||
|
||
export function hasSortableData<T extends DraggableNode | DroppableContainer>( | ||
entry: T | null | undefined | ||
): entry is T & {data: {current: Data<SortableData>}} { | ||
if (!entry) { | ||
return false; | ||
} | ||
|
||
const data = entry.data.current; | ||
|
||
if ( | ||
data && | ||
'sortable' in data && | ||
typeof data.sortable === 'object' && | ||
'containerId' in data.sortable && | ||
'items' in data.sortable && | ||
'index' in data.sortable | ||
) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} |