-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
1,297 additions
and
0 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,101 @@ | ||
export declare type AnimationType = 'dynamic' | 'spring' | 'none'; | ||
|
||
export declare type BeforeSwapEvent = { | ||
fromSlot: string; | ||
toSlot: string; | ||
draggingItem: string; | ||
swapWithItem: string; | ||
}; | ||
|
||
export declare type BeforeSwapHandler = (event: BeforeSwapEvent) => boolean; | ||
|
||
export declare type Config = { | ||
animation: AnimationType; | ||
enabled: boolean; | ||
swapMode: 'hover' | 'drop'; | ||
dragOnHold: boolean; | ||
autoScrollOnDrag: boolean; | ||
dragAxis: DragAxis; | ||
manualSwap: boolean; | ||
}; | ||
|
||
export declare function createSwapy(container: HTMLElement, config?: Partial<Config>): Swapy; | ||
|
||
declare type DragAxis = 'x' | 'y' | 'both'; | ||
|
||
declare function dynamicSwapy<Item>(swapy: Swapy | null, items: Array<Item>, idField: keyof Item, slotItemMap: SlotItemMapArray, setSlotItemMap: (slotItemMap: SlotItemMapArray) => void, removeItemOnly?: boolean): void; | ||
|
||
export declare function getClosestScrollableContainer(element: HTMLElement): HTMLElement | Window; | ||
|
||
declare function initSlotItemMap<Item>(items: Array<Item>, idField: keyof Item): SlotItemMapArray; | ||
|
||
export declare type SlotItemMap = { | ||
asObject: SlotItemMapObject; | ||
asMap: SlotItemMapMap; | ||
asArray: SlotItemMapArray; | ||
}; | ||
|
||
export declare type SlotItemMapArray = Array<{ | ||
slot: string; | ||
item: string; | ||
}>; | ||
|
||
export declare type SlotItemMapMap = Map<string, string>; | ||
|
||
export declare type SlotItemMapObject = Record<string, string>; | ||
|
||
declare type SlottedItems<Item> = Array<{ | ||
slotId: string; | ||
itemId: string; | ||
item: Item | null; | ||
}>; | ||
|
||
export declare type SwapEndEvent = { | ||
slotItemMap: SlotItemMap; | ||
hasChanged: boolean; | ||
}; | ||
|
||
export declare type SwapEndEventHandler = (event: SwapEndEvent) => void; | ||
|
||
export declare type SwapEvent = { | ||
oldSlotItemMap: SlotItemMap; | ||
newSlotItemMap: SlotItemMap; | ||
fromSlot: string; | ||
toSlot: string; | ||
draggingItem: string; | ||
swappedWithItem: string; | ||
}; | ||
|
||
export declare type SwapEventHandler = (event: SwapEvent) => void; | ||
|
||
export declare type SwapStartEvent = { | ||
slotItemMap: SlotItemMap; | ||
draggingItem: string; | ||
fromSlot: string; | ||
}; | ||
|
||
export declare type SwapStartEventHandler = (event: SwapStartEvent) => void; | ||
|
||
export declare interface Swapy { | ||
enable(enabled: boolean): void; | ||
onSwapStart(handler: SwapStartEventHandler): void; | ||
onSwap(handler: SwapEventHandler): void; | ||
onSwapEnd(handler: SwapEndEventHandler): void; | ||
onBeforeSwap(handler: BeforeSwapHandler): void; | ||
slotItemMap(): SlotItemMap; | ||
update(): void; | ||
destroy(): void; | ||
} | ||
|
||
declare function toSlottedItems<Item>(items: Array<Item>, idField: keyof Item, slotItemMap: SlotItemMapArray): SlottedItems<Item>; | ||
|
||
export declare namespace utils { | ||
export { | ||
toSlottedItems, | ||
initSlotItemMap, | ||
dynamicSwapy, | ||
SlottedItems | ||
} | ||
} | ||
|
||
export { } |
Oops, something went wrong.