Skip to content

Commit

Permalink
type exports
Browse files Browse the repository at this point in the history
  • Loading branch information
Kutlu Sahin committed Mar 19, 2019
1 parent 95f7569 commit 4c5cf6c
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 58 deletions.
2 changes: 1 addition & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 3,8 @@ module.exports = function (api) {

return {
presets: [
"@babel/preset-typescript",
"@babel/preset-env",
"@babel/preset-typescript"
]
};
}
Expand Down
13 changes: 10 additions & 3 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,9 1,16 @@
import container from './src/container';
import * as constants from './src/constants';
import container from './src/container';
import * as dropHandlers from './src/dropHandlers';
import { SmoothDnDCreator, ElementX, ContainerOptions } from './src/interfaces';
import { SmoothDnDCreator, ContainerOptions } from './src/exportTypes';
import { ElementX } from './src/interfaces';

export { container as smoothDnD, constants, dropHandlers };
export * from './src/exportTypes';

export {
container as smoothDnD,
constants,
dropHandlers,
};

const deprecetedDefaultExport: SmoothDnDCreator = function(element: ElementX, options?: ContainerOptions) {
console.warn('default export is deprecated. please use named export "smoothDnD"');
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 1,6 @@
{
"name": "smooth-dnd",
"version": "0.8.7",
"version": "0.8.8",
"description": "Drag and Drop library",
"main": "./dist/index.js",
"scripts": {
Expand Down
3 changes: 2 additions & 1 deletion src/container.ts
Original file line number Diff line number Diff line change
@@ -1,10 1,11 @@
import { animationClass, containerClass, containerInstance, stretcherElementClass, stretcherElementInstance, translationValue, wrapperClass } from './constants';
import { defaultOptions } from './defaults';
import { domDropHandler } from './dropHandlers';
import { ContainerOptions, ContainerProps, DraggableInfo, DragInfo, DragResult, ElementX, IContainer, SmoothDnD, SmoothDnDCreator } from './interfaces';
import { ContainerProps, DraggableInfo, DragInfo, DragResult, ElementX, IContainer } from './interfaces';
import layoutManager from './layoutManager';
import Mediator from './mediator';
import { addClass, getParent, getParentRelevantContainerElement, hasClass, removeClass, listenScrollParent } from './utils';
import { ContainerOptions, SmoothDnDCreator, SmoothDnD } from './exportTypes';



Expand Down
2 changes: 1 addition & 1 deletion src/defaults.ts
Original file line number Diff line number Diff line change
@@ -1,4 1,4 @@
import { ContainerOptions } from "./interfaces";
import { ContainerOptions } from "./exportTypes";

export const defaultOptions: ContainerOptions = {
groupName: undefined,
Expand Down
3 changes: 2 additions & 1 deletion src/dropHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 2,8 @@ import { addChildAt, removeChildAt } from './utils';
import {
wrapperClass,
} from './constants';
import { ContainerProps, DropResult, DropCallback } from './interfaces';
import { ContainerProps } from './interfaces';
import { DropCallback, DropResult } from './exportTypes';


export function domDropHandler({ element, draggables }: ContainerProps) {
Expand Down
43 changes: 43 additions & 0 deletions src/exportTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 1,43 @@
export interface SmoothDnD {
dispose: () => void;
}

export type SmoothDnDCreator = ((element: HTMLElement, options?: ContainerOptions) => SmoothDnD) & {
dropHandler?: any;
wrapChild?: boolean;
};

export interface DropResult {
removedIndex: number | null;
addedIndex: number | null;
payload?: any;
element?: HTMLElement;
}

export type DragStartEndCallback = (info: { isSource: boolean; payload: any; willAcceptDrop: boolean }) => void;
export type DropCallback = (dropResult: DropResult) => void;

export interface ContainerOptions {
behaviour?: 'move' | 'copy' | 'drop-zone' | 'contain';
groupName?: string; // if not defined => container will not interfere with other containers
orientation?: 'vertical' | 'horizontal';
dragHandleSelector?: string;
nonDragAreaSelector?: string;
dragBeginDelay?: number;
animationDuration?: number;
autoScrollEnabled?: boolean;
lockAxis?: 'x' | 'y';
dragClass?: string;
dropClass?: string;
onDragStart?: DragStartEndCallback;
onDrop?: DropCallback;
getChildPayload?: (index: number) => any;
shouldAnimateDrop?: (sourceContainerOptions: ContainerOptions, payload: any) => boolean;
shouldAcceptDrop?: (sourceContainerOptions: ContainerOptions, payload: any) => boolean;
onDragEnter?: () => void;
onDragLeave?: () => void;
onDropReady?: DropCallback;
removeOnDropOut?: boolean;
getGhostParent?: () => HTMLElement;
onDragEnd?: DragStartEndCallback;
}
50 changes: 4 additions & 46 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,4 1,5 @@
import layoutManager from './layoutManager';
import { ContainerOptions } from './exportTypes';

export type Position = { x: number; y: number };
export type MousePosition = { clientX: number; clientY: number };
Expand Down Expand Up @@ -31,20 32,10 @@ export interface ScrolableInfo {
axis: Axis;
}

export type SmoothDnDCreator = ((element: HTMLElement, options?: ContainerOptions) => SmoothDnD) & {
dropHandler?: any;
wrapChild?: boolean;
};

export interface SmoothDnD {
dispose: () => void;
}

export interface DropResult {
removedIndex: number | null;
addedIndex: number | null;
payload?: any;
element?: HTMLElement;
export interface DragInfo {
dragResult: DragResult;
draggableInfo: DraggableInfo;
}

export interface DragResult {
Expand Down Expand Up @@ -72,39 63,6 @@ export interface DraggableInfo {
relevantContainers: IContainer[];
}

export interface DragInfo {
dragResult: DragResult;
draggableInfo: DraggableInfo;
}

export type DragStartEndCallback = (info: { isSource: boolean; payload: any; willAcceptDrop: boolean }) => void;
export type DropCallback = (dropResult: DropResult) => void;

export interface ContainerOptions {
behaviour?: 'move' | 'copy' | 'drop-zone' | 'contain';
groupName?: string; // if not defined => container will not interfere with other containers
orientation?: 'vertical' | 'horizontal';
dragHandleSelector?: string;
nonDragAreaSelector?: string;
dragBeginDelay?: number;
animationDuration?: number;
autoScrollEnabled?: boolean;
lockAxis?: Axis;
dragClass?: string;
dropClass?: string;
onDragStart?: DragStartEndCallback;
onDrop?: DropCallback;
getChildPayload?: (index: number) => any;
shouldAnimateDrop?: (sourceContainerOptions: ContainerOptions, payload: any) => boolean;
shouldAcceptDrop?: (sourceContainerOptions: ContainerOptions, payload: any) => boolean;
onDragEnter?: () => void;
onDragLeave?: () => void;
onDropReady?: DropCallback;
removeOnDropOut?: boolean;
getGhostParent?: () => HTMLElement;
onDragEnd?: DragStartEndCallback;
}

export interface ContainerProps {
element: ElementX;
draggables: ElementX[];
Expand Down
6 changes: 2 additions & 4 deletions src/mediator.ts
Original file line number Diff line number Diff line change
@@ -1,10 1,11 @@
import * as constants from './constants';
import { defaultOptions } from './defaults';
import dragScroller from './scroller';
import { Axis, ContainerOptions, DraggableInfo, ElementX, GhostInfo, IContainer, MousePosition, Position, TopLeft } from './interfaces';
import { Axis, DraggableInfo, ElementX, GhostInfo, IContainer, MousePosition, Position, TopLeft } from './interfaces';
import './polyfills';
import { addCursorStyleToBody, addStyleToHead, removeStyle } from './styles';
import * as Utils from './utils';
import { ContainerOptions } from './exportTypes';

const grabEvents = ['mousedown', 'touchstart'];
const moveEvents = ['mousemove', 'touchmove'];
Expand All @@ -19,7 20,6 @@ let isDragging = false;

let handleDrag: (info: DraggableInfo) => void = null!;
let handleScroll: (props: { draggableInfo?: DraggableInfo; reset?: boolean }) => void = null!;
let sourceContainer = null;
let sourceContainerLockAxis: Axis | null = null;
let cursorStyleElement: HTMLStyleElement | null = null;
const containerRectableWatcher = watchRectangles();
Expand Down Expand Up @@ -379,7 379,6 @@ function onMouseUp() {
grabbedElement = null;
ghostInfo = null!;
draggableInfo = null!;
sourceContainer = null;
sourceContainerLockAxis = null;
handleDrag = null!;
});
Expand Down Expand Up @@ -444,7 443,6 @@ function initiateDrag(position: MousePosition, cursor: string) {
isDragging = true;
const container = (containers.filter(p => grabbedElement!.parentElement === p.element)[0]) as IContainer;
container.setDraggables();
sourceContainer = container;
sourceContainerLockAxis = container.getOptions().lockAxis ? container.getOptions().lockAxis!.toLowerCase() as Axis : null;

draggableInfo = getDraggableInfo(grabbedElement);
Expand Down

0 comments on commit 4c5cf6c

Please sign in to comment.