Skip to content

Commit

Permalink
Merge 644894b into b9313a0
Browse files Browse the repository at this point in the history
  • Loading branch information
earlyriser committed Sep 23, 2019
2 parents b9313a0 + 644894b commit 13f4d81
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions src/components/metadata/field.js
Expand Up @@ -2,7 +2,7 @@

const React = require('react')
const { Editable } = require('../editable')
const { DragSource, DropTarget, getEmptyImage } = require('../dnd')
const { DragSource, DropTarget, getEmptyImage, NativeTypes } = require('../dnd')
const { FormattedMessage } = require('react-intl')
const { blank, noop, pluck, URI } = require('../../common/util')
const { IconLock, IconWarningSm } = require('../icons')
Expand Down Expand Up @@ -260,12 +260,32 @@ const DragSourceCollect = (connect) => ({

const DropTargetSpec = {
canDrop({ id, property }, monitor) {
let type = monitor.getItemType()
let item = monitor.getItem()
return id === item.id && property.id !== item.property

switch (type) {
case NativeTypes.TEXT:
return true
case DND.FIELD:
return id === item.id && property.id !== item.property
}
return false
},

drop({ property }) {
return { property: property.id }
drop({ onChange, property, type }, monitor) {
let droptype = monitor.getItemType()
let item = monitor.getItem()

switch (droptype) {
case NativeTypes.TEXT:
onChange({
[property.id]: { text: item.text, type }
}, true)
break
case DND.FIELD:
return { property: property.id }
}

}
}

Expand All @@ -281,5 +301,5 @@ module.exports.NewMetadataField = NewMetadataField
module.exports.MetadataField = DragSource(
DND.FIELD, DragSourceSpec, DragSourceCollect
)(DropTarget(
DND.FIELD, DropTargetSpec, DropTargetCollect
[DND.FIELD, NativeTypes.TEXT], DropTargetSpec, DropTargetCollect
)(MetadataField))

0 comments on commit 13f4d81

Please sign in to comment.