-
Notifications
You must be signed in to change notification settings - Fork 79
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
1 parent
f9e0402
commit f14a00f
Showing
16 changed files
with
83,883 additions
and
249 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
100 changes: 37 additions & 63 deletions
100
client/src/components/GalleryItem/GalleryItemDragLayer.js
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 |
---|---|---|
@@ -1,76 +1,50 @@ | ||
import React, { Component } from 'react'; | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { DragLayer } from 'react-dnd'; | ||
import Badge from 'components/Badge/Badge'; | ||
import GalleryItem from './GalleryItem'; | ||
|
||
class GalleryItemDragLayer extends Component { | ||
getOffset() { | ||
const { | ||
offset, | ||
dragged, | ||
} = this.props; | ||
return { | ||
transform: offset && `translate(${offset.x + dragged.x}px, ${offset.y + dragged.y}px)`, | ||
}; | ||
} | ||
function GalleryItemDragLayer(props) { | ||
const { draggingItems, draggingItemProps } = props; | ||
const selectionCount = draggingItems.length; | ||
const shadows = [ | ||
selectionCount > 1 | ||
? <div key="1" className="gallery-item__drag-shadow" /> | ||
: null, | ||
selectionCount > 2 | ||
? <div key="2" className="gallery-item__drag-shadow gallery-item__drag-shadow--second" /> | ||
: null, | ||
]; | ||
|
||
render() { | ||
if (!this.props.isDragging) { | ||
return null; | ||
} | ||
const { item } = this.props; | ||
if (!item.selected) { | ||
return null; | ||
} | ||
const selectionCount = item.selected.length; | ||
const shadows = [ | ||
selectionCount > 1 | ||
? <div key="1" className="gallery-item__drag-shadow" /> | ||
: null, | ||
selectionCount > 2 | ||
? <div key="2" className="gallery-item__drag-shadow gallery-item__drag-shadow--second" /> | ||
: null, | ||
]; | ||
// Depending on whether the dragging item is a folder, the badge showing how many | ||
// items are currently being dragged needs to be in a different spot in the DOM | ||
// so it correctly renders in the corner of the drag preview | ||
const isFolder = draggingItemProps.item.type === 'folder'; | ||
let badge = null; | ||
if (selectionCount > 1) { | ||
badge = <Badge | ||
className="gallery-item__drag-layer-count" | ||
status="info" | ||
message={`${selectionCount}`} | ||
/>; | ||
} | ||
|
||
return ( | ||
<div className="gallery-item__drag-layer"> | ||
<div className="gallery-item__drag-layer-item" style={this.getOffset()}> | ||
<div className="gallery-item__drag-layer-preview"> | ||
{shadows} | ||
<GalleryItem {...item.props} isDragging /> | ||
</div> | ||
{selectionCount > 1 | ||
? ( | ||
<Badge | ||
className="gallery-item__drag-layer-count" | ||
status="info" | ||
message={`${selectionCount}`} | ||
/> | ||
) | ||
: null | ||
} | ||
return ( | ||
<div className="gallery-item__drag-layer"> | ||
<div className="gallery-item__drag-layer-item"> | ||
<div className="gallery-item__drag-layer-preview"> | ||
{shadows} | ||
<GalleryItem {...draggingItemProps} isDragging /> | ||
{isFolder && badge} | ||
</div> | ||
{!isFolder && badge} | ||
</div> | ||
); | ||
} | ||
</div> | ||
); | ||
} | ||
|
||
GalleryItemDragLayer.propTypes = { | ||
item: PropTypes.object, | ||
offset: PropTypes.shape({ | ||
x: PropTypes.number.isRequired, | ||
y: PropTypes.number.isRequired, | ||
}), | ||
isDragging: PropTypes.bool.isRequired, | ||
draggingItems: PropTypes.arrayOf(PropTypes.number), | ||
draggingItemProps: PropTypes.object, | ||
}; | ||
|
||
const collect = (monitor) => ({ | ||
item: monitor.getItem(), | ||
offset: monitor.getInitialClientOffset(), | ||
dragged: monitor.getDifferenceFromInitialOffset(), | ||
isDragging: monitor.isDragging(), | ||
}); | ||
|
||
// eslint-disable-next-line new-cap | ||
export default DragLayer(collect)(GalleryItemDragLayer); | ||
export default GalleryItemDragLayer; |
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
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 |
---|---|---|
@@ -1,75 +1,35 @@ | ||
import React, { Component } from 'react'; | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { DragSource } from 'react-dnd'; | ||
import { getEmptyImage } from 'react-dnd-html5-backend'; | ||
import { useDraggable } from '@dnd-kit/core'; | ||
|
||
export default function draggable(type) { | ||
const spec = { | ||
canDrag(props) { | ||
return props.canDrag; | ||
}, | ||
beginDrag(props) { | ||
const { id } = props.item; | ||
if (typeof props.onDrag === 'function') { | ||
props.onDrag(true, id); | ||
} | ||
const selected = props.selectedFiles.concat([]); | ||
if (!selected.includes(id)) { | ||
selected.push(id); | ||
} | ||
|
||
return { selected, props }; | ||
}, | ||
endDrag(props) { | ||
const { id } = props.item; | ||
if (typeof props.onDrag === 'function') { | ||
props.onDrag(false, id); | ||
} | ||
}, | ||
}; | ||
|
||
const collect = (connect, monitor) => ({ | ||
connectDragPreview: connect.dragPreview(), | ||
connectDragSource: connect.dragSource(), | ||
isDragging: monitor.isDragging(), | ||
}); | ||
|
||
// eslint-disable-next-line new-cap | ||
const dragItem = DragSource(type, spec, collect); | ||
|
||
return (Item) => { | ||
class DraggableItem extends Component { | ||
componentDidMount() { | ||
// Use empty image as a drag preview so browsers don't draw it | ||
// and we can draw whatever we want on the custom drag layer instead. | ||
this.props.connectDragPreview(getEmptyImage(), { | ||
// IE fallback: specify that we'd rather screenshot the node | ||
// when it already knows it's being dragged so we can hide it with CSS. | ||
captureDraggingState: true, | ||
}); | ||
} | ||
|
||
render() { | ||
const { connectDragSource } = this.props; | ||
const item = <Item {...this.props} />; | ||
|
||
if (typeof item.type === 'string') { | ||
return connectDragSource(item); | ||
} | ||
return connectDragSource(<div className="gallery-item__draggable">{ item }</div>); | ||
} | ||
export default function draggable(Item, uniqueID = null) { | ||
function DraggableItem(props) { | ||
let id = uniqueID; | ||
if (id === null) { | ||
id = props.item.id; | ||
} | ||
|
||
DraggableItem.propTypes = { | ||
connectDragSource: PropTypes.func.isRequired, | ||
connectDragPreview: PropTypes.func.isRequired, | ||
item: PropTypes.shape({ | ||
id: PropTypes.number.isRequired, | ||
}).isRequired, | ||
onDrag: PropTypes.func, | ||
selectedFiles: PropTypes.arrayOf(PropTypes.number), | ||
}; | ||
|
||
return dragItem(DraggableItem); | ||
const canDrag = typeof props.canDrag === 'boolean' ? props.canDrag : true; | ||
const { attributes, listeners, setNodeRef } = useDraggable({ disabled: !canDrag, id, data: { props } }); | ||
const item = <Item {...props} />; | ||
|
||
return <div | ||
className="gallery-item__draggable" | ||
draggable | ||
ref={setNodeRef} | ||
{...listeners} | ||
{...attributes} | ||
>{ item }</div>; | ||
} | ||
|
||
DraggableItem.propTypes = { | ||
item: PropTypes.shape({ | ||
id: PropTypes.number.isRequired, | ||
}).isRequired, | ||
onDrag: PropTypes.func, | ||
canDrag: PropTypes.bool, | ||
selectedFiles: PropTypes.arrayOf(PropTypes.number), | ||
}; | ||
|
||
return DraggableItem; | ||
} |
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 |
---|---|---|
@@ -1,55 +1,26 @@ | ||
import React, { Component } from 'react'; | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { DropTarget } from 'react-dnd'; | ||
import { useDroppable } from '@dnd-kit/core'; | ||
|
||
export default function droppable(types) { | ||
const spec = { | ||
drop(props, monitor) { | ||
if (monitor.canDrop()) { | ||
const item = monitor.getItem(); | ||
props.onDropFiles(props.item.id, item.selected); | ||
} | ||
}, | ||
canDrop(props, monitor) { | ||
const item = monitor.getItem(); | ||
|
||
// check that it is not a folder by itself dragged onto itself | ||
return !item.selected.includes(props.item.id); | ||
}, | ||
}; | ||
|
||
const collect = (connect, monitor) => { | ||
const over = monitor.isOver(); | ||
return { | ||
isDropping: over && monitor.canDrop(), | ||
connectDropTarget: connect.dropTarget(), | ||
isOver: over, | ||
}; | ||
}; | ||
|
||
// eslint-disable-next-line new-cap | ||
const dropItem = DropTarget(types, spec, collect); | ||
|
||
return (Item) => { | ||
class DroppableItem extends Component { | ||
render() { | ||
const { connectDropTarget } = this.props; | ||
const item = <Item {...this.props} />; | ||
|
||
if (typeof item.type === 'string') { | ||
return connectDropTarget(item); | ||
} | ||
return connectDropTarget(<div className="gallery-item__droppable">{ item }</div>); | ||
} | ||
export default function droppable(Item, uniqueID = null) { | ||
function DroppableItem(props) { | ||
let id = uniqueID; | ||
if (id === null) { | ||
id = props.item.id; | ||
} | ||
|
||
DroppableItem.propTypes = { | ||
connectDropTarget: PropTypes.func.isRequired, | ||
item: PropTypes.shape({ | ||
id: PropTypes.number.isRequired, | ||
}).isRequired, | ||
}; | ||
const { setNodeRef, isOver } = useDroppable({ id }); | ||
const item = <Item isDropping={isOver} {...props} />; | ||
|
||
return dropItem(DroppableItem); | ||
return <div ref={setNodeRef} className="gallery-item__droppable">{ item }</div>; | ||
} | ||
|
||
DroppableItem.propTypes = { | ||
connectDropTarget: PropTypes.func.isRequired, | ||
item: PropTypes.shape({ | ||
id: PropTypes.number.isRequired, | ||
}).isRequired, | ||
}; | ||
|
||
return DroppableItem; | ||
} |
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
Oops, something went wrong.