Skip to content

Commit

Permalink
Convert SortableEvent to typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
tsov committed Oct 4, 2023
1 parent a0c3c90 commit fb5354f
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 6 deletions.
5 changes: 5 additions & 0 deletions .changeset/khaki-candles-jog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/draggable': patch
---

Convert SortableEvent to typescript
2 changes: 1 addition & 1 deletion src/Draggable/DragEvent/DragEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export class DragMoveEvent extends DragEvent<DragEventData> {
* DragOverEventData
* @interface DragOverEventData
*/
interface DragOverEventData extends DragEventData {
export interface DragOverEventData extends DragEventData {
overContainer: HTMLElement;
over: HTMLElement;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,38 @@
import AbstractEvent from 'shared/AbstractEvent';

import {
DragEvent,
DragEventData,
DragOverEvent,
DragOutEvent,
DragOverContainerEvent,
DragOutContainerEvent,
} from '../../Draggable/DragEvent';

interface SortableEventData {
dragEvent: DragEvent<DragEventData>;
}

/**
* Base sortable event
* @class SortableEvent
* @module SortableEvent
* @extends AbstractEvent
*/
export class SortableEvent extends AbstractEvent {
export class SortableEvent<
T extends SortableEventData,
> extends AbstractEvent<SortableEventData> {
static type = 'sortable';

/**
* SortableEvent constructor.
* @constructs SortableEvent
* @param {SortableEventData} data - Event data
*/
constructor(public data: T) {
super(data);
}

/**
* Original drag event that triggered this sortable event
* @property dragEvent
Expand All @@ -20,13 +44,18 @@ export class SortableEvent extends AbstractEvent {
}
}

interface SortableStartEventData extends SortableEventData {
startIndex: number;
startContainer: HTMLElement;
}

/**
* Sortable start event
* @class SortableStartEvent
* @module SortableStartEvent
* @extends SortableEvent
*/
export class SortableStartEvent extends SortableEvent {
export class SortableStartEvent extends SortableEvent<SortableStartEventData> {
static type = 'sortable:start';
static cancelable = true;

Expand All @@ -51,13 +80,23 @@ export class SortableStartEvent extends SortableEvent {
}
}

interface SortableSortEventData extends SortableEventData {
dragEvent:
| DragOverEvent
| DragOutEvent
| DragOverContainerEvent
| DragOutContainerEvent;
currentIndex: number;
over: HTMLElement;
}

/**
* Sortable sort event
* @class SortableSortEvent
* @module SortableSortEvent
* @extends SortableEvent
*/
export class SortableSortEvent extends SortableEvent {
export class SortableSortEvent extends SortableEvent<SortableSortEventData> {
static type = 'sortable:sort';
static cancelable = true;

Expand Down Expand Up @@ -92,13 +131,20 @@ export class SortableSortEvent extends SortableEvent {
}
}

interface SortableSortedEventData extends SortableEventData {
oldIndex: number;
newIndex: number;
oldContainer: HTMLElement;
newContainer: HTMLElement;
}

/**
* Sortable sorted event
* @class SortableSortedEvent
* @module SortableSortedEvent
* @extends SortableEvent
*/
export class SortableSortedEvent extends SortableEvent {
export class SortableSortedEvent extends SortableEvent<SortableSortedEventData> {
static type = 'sortable:sorted';

/**
Expand Down Expand Up @@ -142,13 +188,20 @@ export class SortableSortedEvent extends SortableEvent {
}
}

interface SortableStopEventData extends SortableEventData {
oldIndex: number;
newIndex: number;
oldContainer: HTMLElement;
newContainer: HTMLElement;
}

/**
* Sortable stop event
* @class SortableStopEvent
* @module SortableStopEvent
* @extends SortableEvent
*/
export class SortableStopEvent extends SortableEvent {
export class SortableStopEvent extends SortableEvent<SortableStopEventData> {
static type = 'sortable:stop';

/**
Expand Down
File renamed without changes.

0 comments on commit fb5354f

Please sign in to comment.