Skip to content

Commit

Permalink
0.12.0 adjust center if it's outsude container when inited
Browse files Browse the repository at this point in the history
  • Loading branch information
kutlugsahin committed Apr 14, 2019
1 parent b6f7d33 commit 68853ec
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
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.11.0",
"version": "0.12.0",
"description": "Drag and Drop library",
"main": "./dist/index.js",
"scripts": {
Expand Down
16 changes: 6 additions & 10 deletions src/container.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { animationClass, containerClass, containerInstance, dropPlaceholderFlexContainerClass, dropPlaceholderInnerClass, dropPlaceholderWrapperClass, stretcherElementClass, stretcherElementInstance, translationValue, wrapperClass, dropPlaceholderDefaultClass } from './constants';
import { defaultOptions } from './defaults';
import { domDropHandler } from './dropHandlers';
import { ContainerOptions, SmoothDnD, SmoothDnDCreator } from './exportTypes';
import { ContainerOptions, SmoothDnD, SmoothDnDCreator, DropPlaceholderOptions } from './exportTypes';
import { ContainerProps, DraggableInfo, DragInfo, DragResult, ElementX, IContainer, LayoutManager } from './interfaces';
import layoutManager from './layoutManager';
import Mediator from './mediator';
Expand All @@ -17,10 +17,6 @@ function setAnimation(element: HTMLElement, add: boolean, animationDuration = de
}
}

function initOptions(props = defaultOptions): ContainerOptions {
return Object.assign({}, defaultOptions, props);
}

function isDragRelevant({ element, getOptions }: ContainerProps) {
return function (sourceContainer: IContainer, payload: any) {
const options = getOptions();
Expand Down Expand Up @@ -301,12 +297,12 @@ function getShadowBeginEndForDropZone({ layout }: ContainerProps) {
};
}

function drawDropPreview({ layout, element, getOptions }: ContainerProps) {
function drawDropPlaceholder({ layout, element, getOptions }: ContainerProps) {
let prevAddedIndex: number | null = null;
return ({ dragResult: { elementSize, shadowBeginEnd, addedIndex, dropPlaceholderContainer } }: DragInfo) => {
const options = getOptions();
if (options.dropPlaceholder) {
const { animationDuration, className, showOnTop } = typeof options.dropPlaceholder === 'boolean' ? {} as any : options.dropPlaceholder;
const { animationDuration, className, showOnTop } = typeof options.dropPlaceholder === 'boolean' ? {} as any as DropPlaceholderOptions : options.dropPlaceholder as DropPlaceholderOptions;
if (addedIndex !== null) {
if (!dropPlaceholderContainer) {
const innerElement = document.createElement('div');
Expand Down Expand Up @@ -633,7 +629,7 @@ function getDragHandler(params: ContainerProps) {
handleInsertionSizeChange,
calculateTranslations,
getShadowBeginEnd,
drawDropPreview,
drawDropPlaceholder,
handleFirstInsertShadowAdjustment,
fireDragEnterLeaveEvents,
fireOnDropReady
Expand Down Expand Up @@ -789,8 +785,8 @@ const smoothDnD: SmoothDnDCreator = function (element: HTMLElement, options?: Co
Mediator.unregister(container);
container.dispose(container);
},
setOptions(options: ContainerOptions) {
container.setOptions(options);
setOptions(options: ContainerOptions, merge?: boolean) {
container.setOptions(options, merge);
}
};
};
Expand Down
4 changes: 2 additions & 2 deletions src/exportTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface DropResult {
element?: HTMLElement;
}

export interface DropPreviewOptions {
export interface DropPlaceholderOptions {
className?: string;
animationDuration?: number;
showOnTop?: boolean;
Expand Down Expand Up @@ -59,5 +59,5 @@ export interface ContainerOptions {
removeOnDropOut?: boolean;
getGhostParent?: () => HTMLElement;
onDragEnd?: DragEndCallback;
dropPlaceholder?: DropPreviewOptions | boolean;
dropPlaceholder?: DropPlaceholderOptions | boolean;
}
2 changes: 1 addition & 1 deletion src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export interface IContainer {
setDraggables: () => void;
fireRemoveElement: () => void;
getScrollMaxSpeed: () => number | undefined;
setOptions: (options: ContainerOptions) => void;
setOptions: (options: ContainerOptions, merge?: boolean) => void;
shouldUseTransformForGhost: () => boolean;
}

Expand Down
10 changes: 7 additions & 3 deletions src/mediator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,13 @@ function getGhostParent() {
}

function getGhostElement(wrapperElement: HTMLElement, { x, y }: Position, container: IContainer, cursor: string): GhostInfo {
const { left, top, right, bottom } = wrapperElement.getBoundingClientRect();
const midX = left + (right - left) / 2;
const midY = top + (bottom - top) / 2;
const wrapperRect = wrapperElement.getBoundingClientRect();
const { left, top, right, bottom } = wrapperRect;

const wrapperVisibleRect = Utils.getIntersection(container.layout.getContainerRectangles().visibleRect, wrapperRect);

const midX = wrapperVisibleRect.left + (wrapperVisibleRect.right - wrapperVisibleRect.left) / 2;
const midY = wrapperVisibleRect.top + (wrapperVisibleRect.bottom - wrapperVisibleRect.top) / 2;
const ghost: HTMLElement = wrapperElement.cloneNode(true) as HTMLElement;
ghost.style.zIndex = '1000';
ghost.style.boxSizing = 'border-box';
Expand Down

0 comments on commit 68853ec

Please sign in to comment.