{"version":3,"sources":["webpack:///./src/main/web/components/dnd/DragAndDropApi.ts","webpack:///./src/main/web/components/dnd/DraggableComponent.ts"],"names":["DRAG_AND_DROP_FORMAT","DRAG_AND_DROP_FORMAT_IE","DroppableContextTypes","droppableApi","PropTypes","any","isRequired","props","setHandlers","source","findDOMNode","addEventListener","onDragStart","onDragEnd","removeEventListener","e","dataTransfer","setData","iri","ex","setState","isDragged","mpDragStart","CustomEvent","detail","window","dispatchEvent","mpDragEnd","state","componentWillMount","children","Error","render","child","Children","only","this","dragStyles","style","_","extend","className","classNames","cloneElement","ref","draggable","onMouseDown","stopPropagation","Component","Draggable"],"mappings":"8HAmBA,WAOa,EAAAA,qBAAuB,+BAMvB,EAAAC,wBAA0B,gBAK1B,EAAAC,sBAAwB,CACnCC,aAAcC,EAAUC,IAAIC,a,iFCnB9B,OACA,QACA,OACA,QAEA,SAkCA,cAGE,mBAAYC,GAAZ,MACE,YAAMA,IAAM,K,OAkBN,EAAAC,YAAc,SAACC,GACjBA,GACF,EAAKA,OAAS,EAAAC,YAAYD,GAE1B,EAAKA,OAAOE,iBAAiB,YAAa,EAAKC,aAC/C,EAAKH,OAAOE,iBAAiB,UAAW,EAAKE,YACpC,EAAKJ,SACd,EAAKA,OAAOK,oBAAoB,YAAa,EAAKF,aAClD,EAAKH,OAAOK,oBAAoB,UAAW,EAAKD,aAI5C,EAAAD,YAAc,SAACG,GACrB,IACEA,EAAEC,aAAaC,QAAQ,EAAAjB,qBAAsB,EAAKO,MAAMW,KACxD,MAAOC,IAITJ,EAAEC,aAAaC,QAAQ,EAAAhB,wBAAyB,EAAKM,MAAMW,KAE3D,EAAKE,SAAS,CAAEC,WAAW,IACvB,EAAKd,MAAMK,aACb,EAAKL,MAAMK,YAAY,EAAKL,MAAMW,KAGpC,IAAMI,EAAc,IAAIC,YAAY,eAAgB,CAAEC,OAAQ,CAAEN,IAAK,EAAKX,MAAMW,OAChFO,OAAOC,cAAcJ,IAGf,EAAAT,UAAY,SAACE,GACnB,EAAKK,SAAS,CAAEC,WAAW,IACvB,EAAKd,MAAMM,WACb,EAAKN,MAAMM,YAGb,IAAMc,EAAY,IAAIJ,YAAY,cAClCE,OAAOC,cAAcC,IAtDrB,EAAKC,MAAQ,CACXP,WAAW,G,EA6EjB,OAnF+B,yBAU7B,oBAAAQ,mBAAA,WACU,IAAAC,EAAA,WAAAA,SAER,GAAwB,iBAAbA,EACT,MAAMC,MAAM,6CAGd,IAAKD,EACH,MAAMC,MAAM,qCA4CT,oBAAAC,OAAP,WACE,IAAMC,EAAQ,EAAAC,SAASC,KAAKC,KAAK7B,MAAMuB,UAC/BO,EAAA,WAAAA,WACAhB,EAAA,WAAAA,UAEFiB,EAAQ,GACdC,EAAEC,OAAOF,EAAOL,EAAM1B,MAAM+B,OAAS,IACrCC,EAAEC,OAAOF,EAAOjB,GAAagB,EAAaA,EAAa,IAEvD,IAAMI,EAAYC,EAAWT,EAAM1B,MAAMkC,UAAW,CAClD,uBAAwBpB,IAG1B,OAAO,EAAAsB,aAAaV,EAAO,CACzBW,IAAKR,KAAK5B,YACViC,UAAWA,EACXH,MAAOA,EACPO,WAAW,EACXC,YAAa,SAAC/B,GAAM,OAAAA,EAAEgC,sBAG5B,UAnFA,CAA+B,EAAAC,WAAlB,EAAAC,YAqFb,UAAeA","file":"mp-draggable-a128b6f2de2636dba35a.js","sourcesContent":["/**\n * ResearchSpace\n * Copyright (C) 2020, © Trustees of the British Museum\n * Copyright (C) 2015-2019, metaphacts GmbH\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\nimport * as PropTypes from 'prop-types';\n\nimport { Rdf } from 'platform/api/rdf';\n\n/**\n * Type of drag data\n */\nexport const DRAG_AND_DROP_FORMAT = 'application/mp-draggable-iri';\n\n/**\n * Type of drag data for IE.\n * IE doesn't support custom mime type.\n */\nexport const DRAG_AND_DROP_FORMAT_IE = 'text/uri-list';\n\n/**\n * Context types of droppable component\n */\nexport const DroppableContextTypes = {\n droppableApi: PropTypes.any.isRequired,\n};\n\n/**\n * Context of droppable component\n */\nexport interface DroppableContext {\n droppableApi: DroppableApi;\n}\n\n/**\n * API of droppable component\n */\nexport interface DroppableApi {\n /**\n * Iri of dropped source\n */\n drop: Data.Maybe;\n}\n","/**\n * ResearchSpace\n * Copyright (C) 2020, © Trustees of the British Museum\n * Copyright (C) 2015-2019, metaphacts GmbH\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see .\n */\n\nimport { Component, Children, ReactElement, cloneElement, CSSProperties } from 'react';\nimport { findDOMNode } from 'react-dom';\nimport * as classNames from 'classnames';\nimport * as _ from 'lodash';\n\nimport { DRAG_AND_DROP_FORMAT, DRAG_AND_DROP_FORMAT_IE } from './DragAndDropApi';\n\nexport interface DraggableProps {\n /**\n * Resource identifier\n */\n iri: string;\n /**\n * Styles that are added to the component, if it dragged.\n */\n dragStyles?: CSSProperties;\n /**\n * Callback which fires when component becomes dragged.\n */\n onDragStart?: (iri?: string) => void;\n /**\n * Callback which fires when component stops being dragged.\n */\n onDragEnd?: () => void;\n}\n\ninterface State {\n isDragged: boolean;\n}\n\n/**\n * This component takes inner html and makes it automatically draggable.\n * Child element could be any HTML-element (not text node).\n *\n * @example\n * \n * Content
\n * \n */\nexport class Draggable extends Component {\n private source: Element;\n\n constructor(props: DraggableProps) {\n super(props);\n this.state = {\n isDragged: false,\n };\n }\n\n componentWillMount() {\n const { children } = this.props;\n\n if (typeof children === 'string') {\n throw Error(`The child element couldn't be a text node`);\n }\n\n if (!children) {\n throw Error(`The child element doesn't exists`);\n }\n }\n\n private setHandlers = (source: any) => {\n if (source) {\n this.source = findDOMNode(source) as Element;\n\n this.source.addEventListener('dragstart', this.onDragStart);\n this.source.addEventListener('dragend', this.onDragEnd);\n } else if (this.source) {\n this.source.removeEventListener('dragstart', this.onDragStart);\n this.source.removeEventListener('dragend', this.onDragEnd);\n }\n };\n\n private onDragStart = (e) => {\n try {\n e.dataTransfer.setData(DRAG_AND_DROP_FORMAT, this.props.iri);\n } catch (ex) {\n // IE fix\n }\n // One can drop into draft-js contenteditable only if some known to browser mime-type is set\n e.dataTransfer.setData(DRAG_AND_DROP_FORMAT_IE, this.props.iri);\n\n this.setState({ isDragged: true });\n if (this.props.onDragStart) {\n this.props.onDragStart(this.props.iri);\n }\n\n const mpDragStart = new CustomEvent('mp-dragstart', { detail: { iri: this.props.iri } });\n window.dispatchEvent(mpDragStart);\n };\n\n private onDragEnd = (e) => {\n this.setState({ isDragged: false });\n if (this.props.onDragEnd) {\n this.props.onDragEnd();\n }\n\n const mpDragEnd = new CustomEvent('mp-dragend');\n window.dispatchEvent(mpDragEnd);\n };\n\n public render() {\n const child = Children.only(this.props.children) as ReactElement;\n const { dragStyles } = this.props;\n const { isDragged } = this.state;\n\n const style = {};\n _.extend(style, child.props.style || {});\n _.extend(style, isDragged && dragStyles ? dragStyles : {});\n\n const className = classNames(child.props.className, {\n 'mp-draggable-dragged': isDragged,\n });\n\n return cloneElement(child, {\n ref: this.setHandlers,\n className: className,\n style: style,\n draggable: true,\n onMouseDown: (e) => e.stopPropagation(),\n });\n }\n}\n\nexport default Draggable;\n"],"sourceRoot":""}