Skip to content

Commit

Permalink
its happening
Browse files Browse the repository at this point in the history
  • Loading branch information
alexreardon committed Jun 18, 2018
1 parent 59479bc commit 59c4c17
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 39 deletions.
4 changes: 2 additions & 2 deletions src/state/auto-scroller/get-best-scrollable-droppable.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import memoizeOne from 'memoize-one';
import invariant from 'tiny-invariant';
import { type Position } from 'css-box-model';
import isPositionInFrame from '../visibility/is-position-in-frame';
import { toDroppableList } from '../dimension-structures';
import type {
DroppableId,
DroppableDimension,
Expand All @@ -12,8 +13,7 @@ import type {

const getScrollableDroppables = memoizeOne(
(droppables: DroppableDimensionMap): DroppableDimension[] => (
Object.keys(droppables)
.map((id: DroppableId): DroppableDimension => droppables[id])
toDroppableList(droppables)
.filter((droppable: DroppableDimension): boolean => {
// exclude disabled droppables
if (!droppable.isEnabled) {
Expand Down
21 changes: 13 additions & 8 deletions src/state/dimension-structures.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @flow
import memoizeOne from 'memoize-one';
import type {
DroppableId,
DraggableId,
Expand All @@ -8,24 +9,28 @@ import type {
DraggableDimensionMap,
} from '../types';

export const toDroppableMap =
export const toDroppableMap = memoizeOne(
(droppables: DroppableDimension[]): DroppableDimensionMap =>
droppables.reduce((previous, current) => {
previous[current.descriptor.id] = current;
return previous;
}, {});
}, {})
);

export const toDraggableMap =
export const toDraggableMap = memoizeOne(
(draggables: DraggableDimension[]): DraggableDimensionMap =>
draggables.reduce((previous, current) => {
previous[current.descriptor.id] = current;
return previous;
}, {});
}, {})
);

export const toDroppableList =
export const toDroppableList = memoizeOne(
(droppables: DroppableDimensionMap): DroppableDimension[] =>
Object.keys(droppables).map((id: DroppableId): DroppableDimension => droppables[id]);
Object.keys(droppables).map((id: DroppableId): DroppableDimension => droppables[id])
);

export const toDraggableList =
export const toDraggableList = memoizeOne(
(draggables: DraggableDimensionMap): DraggableDimension[] =>
Object.keys(draggables).map((id: DraggableId): DraggableDimension => draggables[id]);
Object.keys(draggables).map((id: DraggableId): DraggableDimension => draggables[id])
);
5 changes: 2 additions & 3 deletions src/state/get-draggables-inside-droppable.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @flow
import memoizeOne from 'memoize-one';
import { toDraggableList } from './dimension-structures';
import type {
DraggableId,
DraggableDimension,
DroppableDimension,
DraggableDimensionMap,
Expand All @@ -11,8 +11,7 @@ export default memoizeOne(
(droppable: DroppableDimension,
draggables: DraggableDimensionMap,
): DraggableDimension[] =>
Object.keys(draggables)
.map((id: DraggableId): DraggableDimension => draggables[id])
toDraggableList(draggables)
.filter((draggable: DraggableDimension): boolean => (
droppable.descriptor.id === draggable.descriptor.droppableId
))
Expand Down
40 changes: 20 additions & 20 deletions src/state/get-droppable-over.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import isPositionInFrame from './visibility/is-position-in-frame';
import { patch } from './position';
import { expandByPosition } from './spacing';
import { clip } from './droppable-dimension';
import { toDroppableList } from './dimension-structures';
import type {
Scrollable,
DraggableDimension,
Expand Down Expand Up @@ -132,28 +133,27 @@ export default ({
previousDroppableOverId,
}: Args): ?DroppableId => {
const maybe: ?DroppableDimension =
Object.keys(droppables)
.map((id: DroppableId): DroppableDimension => droppables[id])
toDroppableList(droppables)
// only want enabled droppables
.filter((droppable: DroppableDimension) => droppable.isEnabled)
.find((droppable: DroppableDimension): boolean => {
// If previously dragging over a droppable we give it a
// bit of room on the subsequent drags so that user and move
// items in the space that the placeholder takes up
const withPlaceholder: ?Rect = getClippedRectWithPlaceholder({
draggable, draggables, droppable, previousDroppableOverId,
.filter((droppable: DroppableDimension) => droppable.isEnabled)
.find((droppable: DroppableDimension): boolean => {
// If previously dragging over a droppable we give it a
// bit of room on the subsequent drags so that user and move
// items in the space that the placeholder takes up
const withPlaceholder: ?Rect = getClippedRectWithPlaceholder({
draggable, draggables, droppable, previousDroppableOverId,
});

if (!withPlaceholder) {
return false;
}

// Not checking to see if visible in viewport
// as the target might be off screen if dragging a large draggable
// Not adjusting target for droppable scroll as we are just checking
// if it is over the droppable - not its internal impact
return isPositionInFrame(withPlaceholder)(target);
});

if (!withPlaceholder) {
return false;
}

// Not checking to see if visible in viewport
// as the target might be off screen if dragging a large draggable
// Not adjusting target for droppable scroll as we are just checking
// if it is over the droppable - not its internal impact
return isPositionInFrame(withPlaceholder)(target);
});

return maybe ? maybe.descriptor.id : null;
};
4 changes: 2 additions & 2 deletions src/state/move-cross-axis/get-best-cross-axis-droppable.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { closest } from '../position';
import isWithin from '../is-within';
import { getCorners } from '../spacing';
import isPartiallyVisibleThroughFrame from '../visibility/is-partially-visible-through-frame';
import { toDroppableList } from '../dimension-structures';
import type {
Axis,
DroppableDimension,
Expand Down Expand Up @@ -50,8 +51,7 @@ export default ({
sourceClipped[axis.start],
sourceClipped[axis.end]
);
const candidates: DroppableDimension[] = Object.keys(droppables)
.map((id: DroppableId): DroppableDimension => droppables[id])
const candidates: DroppableDimension[] = toDroppableList(droppables)
// Remove the source droppable from the list
.filter((droppable: DroppableDimension): boolean => droppable !== source)
// Remove any options that are not enabled
Expand Down
4 changes: 0 additions & 4 deletions src/state/publish/get-drag-positions.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,9 @@ export default ({
const centerDiff: Position = subtract(newClientBorderBoxCenter, oldClientBorderBoxCenter);
// const displacement: Position = negate(centerDiff);

console.log('center offset', centerDiff);

const clientSelection: Position = add(
oldInitial.client.selection, centerDiff
);
console.log('old client selection', oldInitial.client.selection);
console.log('new client selection', clientSelection);

const initial: DragPositions = (() => {
const client: ItemPositions = {
Expand Down

0 comments on commit 59c4c17

Please sign in to comment.