{"version":3,"sources":["webpack:///./src/main/web/components/dnd/DroppableComponent.ts","webpack:///./src/main/web/components/dnd/index.ts"],"names":["OverlayTrigger","createFactory","ReactBootstrap","Popover","props","setHandlers","target","child","Children","only","children","findDOMNode","window","addEventListener","onDragStart","onDragEnd","onDragEnter","onDragOver","onDragLeave","onDrop","removeEventListener","ref","e","dragged","Rdf","iri","detail","shouldReactToDrag","setState","isSourceDragged","query","SparqlClient","setBindings","SparqlUtil","parseQuery","value","ask","context","repository","onValue","res","isDropEnabledKnown","isDropEnabled","state","isEventInsideRect","isHover","preventDefault","dataTransfer","dropEffect","stopPropagation","iriStr","getData","DRAG_AND_DROP_FORMAT","ex","DRAG_AND_DROP_FORMAT_IE","maybe","fromNullable","map","isNothing","get","showDisabledHover","Nothing","getChildContext","droppableApi","drop","this","componentWillMount","Error","event","rect","getBoundingClientRect","dists","clientX","left","right","clientY","top","bottom","shouldComponentUpdate","nextProps","nextState","dropComponents","disabledHover","refs","trigger","show","hide","render","dropStyles","style","_","extend","enabledStyle","enabled","enabledHoverStyle","enabledHover","disabledStyle","disabled","disabledHoverStyle","className","classNames","result","cloneElement","key","placement","overlay","id","defaultOverlayShown","childContextTypes","DroppableContextTypes","Component","Droppable","DroppableProps","Draggable","DraggableProps","DragAndDropApi","DragAndDropApi_"],"mappings":"2IAmBA,OACA,QACA,QACA,OACA,QACA,QAEA,QACA,QACA,SAOMA,EAAiB,EAAAC,cAAcC,EAAeF,gBAC9CG,EAAU,EAAAF,cAAcC,EAAeC,SAkE7C,cAIE,mBAAYC,GAAZ,MACE,YAAMA,IAAM,K,OAgCN,EAAAC,YAAc,SAACC,GACrB,IAAMC,EAAQ,EAAAC,SAASC,KAAK,EAAKL,MAAMM,UACnCJ,GACF,EAAKA,OAAS,EAAAK,YAAYL,GAE1BM,OAAOC,iBAAiB,eAAgB,EAAKC,aAC7CF,OAAOC,iBAAiB,aAAc,EAAKE,WAE3C,EAAKT,OAAOO,iBAAiB,YAAa,EAAKG,aAC/C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GzF,IAAMC,EAAYC,EAAW7F,EAAMH,MAAM+F,UAAW,CAClD,uBAAwB1D,GAAsBZ,GAAmBa,EACjE,wBAAyBD,GAAsBZ,IAAoBa,EACnE,qBAAsBD,GAAsBZ,GAAmBgB,IAG3DwD,EAAS,EAAAC,aAAa/F,EAAO,CACjCc,IAAK4C,KAAK5D,YACVkG,IAAK,oBACLJ,UAAWA,EACXV,MAAOA,IAET,OAAIxB,KAAK7D,MAAM6E,gBAAkBhB,KAAK7D,MAAM6E,eAAeC,cAClDlF,EACL,CACEoF,QAAS,GACT/D,IAAK,UACLmF,UAAW,MACXC,QAAStG,EAAQ,CAAEuG,GAAI,QAAU,EAAAJ,aAAarC,KAAK7D,MAAM6E,eAAeC,gBACxEyB,qBAAqB,GAEvBN,GAGKA,GAxNJ,UAAAO,kBAAoB,EAAAC,sBA2N7B,UA1OA,CAA+B,EAAAC,WAAlB,EAAAC,a,qECnFb,cAAS,EAAAA,UAAA,EAAAA,UAAW,EAAAC,eAAA,EAAAA,eACpB,aAAS,EAAAC,UAAA,EAAAA,UAAW,EAAAC,eAAA,EAAAA,eACpB,aACa,EAAAC,eAAiBC","file":"semantic-link-7c8acb62e6ecff4038a3.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 { Component, Children, ReactElement, cloneElement, createFactory, CSSProperties } from 'react';\nimport { findDOMNode } from 'react-dom';\nimport * as ReactBootstrap from 'react-bootstrap';\nimport * as classNames from 'classnames';\nimport * as maybe from 'data.maybe';\nimport * as _ from 'lodash';\n\nimport { Rdf } from 'platform/api/rdf';\nimport { SparqlClient, SparqlUtil } from 'platform/api/sparql';\nimport {\n DroppableContextTypes,\n DroppableContext,\n DRAG_AND_DROP_FORMAT,\n DRAG_AND_DROP_FORMAT_IE,\n} from './DragAndDropApi';\n\nconst OverlayTrigger = createFactory(ReactBootstrap.OverlayTrigger);\nconst Popover = createFactory(ReactBootstrap.Popover);\n\n// We should use OverlayTrigger as root in render return value\n// OverlayTrigger documentation doesn't describe methods to show/hide it\n// so we need to call it manually in shouldComponentUpdate through custom interface\ninterface OverlayTriggerOverride extends ReactBootstrap.OverlayTrigger {\n show: () => void;\n hide: () => void;\n}\n\nexport interface DroppableProps {\n /**\n * Allows to ignore event when a source being dragged.\n */\n shouldReactToDrag?: (dragged: Rdf.Iri) => boolean;\n\n /**\n * SPARQL ASK query\n */\n query?: string;\n\n /**\n * Repository to execute ASK query, \"default\" repository is used by default\n */\n repository?: string;\n\n /**\n * Callback that called when a source is dropped into the component\n */\n onDrop?: (drop: Rdf.Iri) => void;\n /**\n * Styles that are added to the component when it receives the appropriate state.\n */\n dropStyles?: {\n enabled?: CSSProperties;\n enabledHover?: CSSProperties;\n disabled?: CSSProperties;\n disabledHover?: CSSProperties;\n };\n /**\n * Components that will be displayed inside Overlay with child element\n */\n dropComponents?: {\n disabledHover?: any;\n };\n}\n\ninterface State {\n iri?: Data.Maybe;\n isSourceDragged?: boolean;\n isDropEnabledKnown?: boolean;\n isDropEnabled?: boolean;\n isHover?: boolean;\n}\n\n/**\n * This component takes inner html and makes it droppable.\n * Child element could be any HTML-element (not text node).\n * When a source has been dragged the component takes source's iri\n * and checks with SPARQL ASK query if it can be accepted or not.\n *\n * CSS classes for child component:\n * - `mp-droppable-enabled`\n * - `mp-droppable-disabled`\n * - `mp-droppable-hover`\n */\nexport class Droppable extends Component {\n private target: Element;\n public refs: { trigger: OverlayTriggerOverride };\n\n constructor(props: DroppableProps) {\n super(props);\n this.state = {\n iri: maybe.Nothing(),\n isSourceDragged: false,\n isDropEnabledKnown: false,\n isDropEnabled: false,\n isHover: false,\n };\n }\n\n static childContextTypes = DroppableContextTypes;\n\n getChildContext(): DroppableContext {\n return {\n droppableApi: {\n drop: this.state.iri,\n },\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 = (target) => {\n const child = Children.only(this.props.children) as ReactElement;\n if (target) {\n this.target = findDOMNode(target) as HTMLElement;\n\n window.addEventListener('mp-dragstart', this.onDragStart);\n window.addEventListener('mp-dragend', this.onDragEnd);\n\n this.target.addEventListener('dragenter', this.onDragEnter);\n this.target.addEventListener('dragover', this.onDragOver);\n this.target.addEventListener('dragleave', this.onDragLeave);\n this.target.addEventListener('drop', this.onDrop);\n } else if (this.target) {\n window.removeEventListener('mp-dragstart', this.onDragStart);\n window.removeEventListener('mp-dragend', this.onDragEnd);\n\n this.target.removeEventListener('dragenter', this.onDragEnter);\n this.target.removeEventListener('dragover', this.onDragOver);\n this.target.removeEventListener('dragleave', this.onDragLeave);\n this.target.removeEventListener('drop', this.onDrop);\n this.target = null;\n }\n // DroppableComponent insert own ref callback in order to set event handlers\n // so we need to call original ref callback\n // string refs are not supported, see ReactRef.attachRef/detachRef if you need\n if ((child as any).ref && typeof (child as any).ref === 'function') {\n (child as any).ref(target);\n }\n };\n\n private onDragStart = (e) => {\n const dragged = Rdf.iri(e.detail.iri);\n if (this.props.shouldReactToDrag && !this.props.shouldReactToDrag(dragged)) {\n return;\n }\n\n this.setState({ isSourceDragged: true });\n if (this.props.query) {\n const query =\n SparqlClient.setBindings(\n SparqlUtil.parseQuery(this.props.query),\n {value: dragged},\n );\n SparqlClient.ask(query, { context: { repository: this.props.repository } })\n .onValue((res) => {\n this.setState({ isDropEnabledKnown: true, isDropEnabled: res });\n });\n } else {\n this.setState({ isDropEnabledKnown: true, isDropEnabled: true });\n }\n };\n\n private isEventInsideRect(event, target): boolean {\n const rect = target.getBoundingClientRect();\n const dists = [\n event.clientX - rect.left,\n rect.right - event.clientX,\n event.clientY - rect.top,\n rect.bottom - event.clientY,\n ];\n return dists[0] > 0 && dists[1] > 0 && dists[2] > 0 && dists[3] > 0;\n }\n\n private onDragEnter = (e) => {\n if (this.state.isSourceDragged && this.isEventInsideRect(e, this.target)) {\n this.setState({ isHover: true });\n }\n };\n\n private onDragLeave = (e: MouseEvent) => {\n if (this.state.isSourceDragged && !this.isEventInsideRect(e, this.target)) {\n this.setState({ isHover: false });\n }\n };\n\n private onDragOver = (e) => {\n if (!this.state.isSourceDragged) {\n return;\n }\n\n if (e.preventDefault) {\n e.preventDefault(); // Necessary. Allows us to drop.\n }\n\n if (!this.state.isDropEnabled) {\n e.dataTransfer.dropEffect = 'none';\n }\n\n if (!this.state.isHover && this.isEventInsideRect(e, this.target)) {\n this.setState({ isHover: true });\n }\n\n return false;\n };\n\n private onDrop = (e: DragEvent) => {\n e.preventDefault();\n if (e.stopPropagation) {\n // Stops some browsers from redirecting.\n e.stopPropagation();\n }\n\n if (!this.state.isSourceDragged) {\n return;\n }\n\n if (this.state.isDropEnabled) {\n let iriStr: string;\n\n try {\n iriStr = e.dataTransfer.getData(DRAG_AND_DROP_FORMAT);\n } catch (ex) {\n // IE fix\n iriStr = e.dataTransfer.getData(DRAG_AND_DROP_FORMAT_IE);\n }\n\n const iri = maybe.fromNullable(iriStr).map(Rdf.iri);\n\n this.setState({ iri: iri });\n\n if (this.props.onDrop && !iri.isNothing) {\n this.props.onDrop(iri.get());\n }\n }\n\n return false;\n };\n\n private onDragEnd = (e) => {\n this.setState({\n isSourceDragged: false,\n isDropEnabledKnown: false,\n isDropEnabled: false,\n isHover: false,\n });\n };\n\n private showDisabledHover = (state: State) => state.isDropEnabledKnown && !state.isDropEnabled && state.isHover;\n\n public shouldComponentUpdate(nextProps, nextState) {\n if (this.props.dropComponents && this.props.dropComponents.disabledHover) {\n if (!this.showDisabledHover(this.state) && this.showDisabledHover(nextState)) {\n this.refs.trigger.show();\n } else if (this.showDisabledHover(this.state) && !this.showDisabledHover(nextState)) {\n this.refs.trigger.hide();\n }\n }\n return true;\n }\n\n public render() {\n const child = Children.only(this.props.children) as ReactElement;\n const { dropStyles } = this.props;\n const { isSourceDragged, isDropEnabledKnown, isDropEnabled, isHover } = this.state;\n\n const style = {};\n _.extend(style, child.props.style || {});\n\n if (isDropEnabledKnown && isSourceDragged && dropStyles) {\n const enabledStyle = dropStyles.enabled,\n enabledHoverStyle = dropStyles.enabledHover,\n disabledStyle = dropStyles.disabled,\n disabledHoverStyle = dropStyles.disabledHover;\n\n _.extend(style, isDropEnabled && enabledStyle ? enabledStyle : {});\n _.extend(style, isDropEnabled && isHover && enabledHoverStyle ? enabledHoverStyle : {});\n _.extend(style, !isDropEnabled && disabledStyle ? disabledStyle : {});\n _.extend(style, !isDropEnabled && isHover && disabledHoverStyle ? disabledHoverStyle : {});\n }\n\n const className = classNames(child.props.className, {\n 'mp-droppable-enabled': isDropEnabledKnown && isSourceDragged && isDropEnabled,\n 'mp-droppable-disabled': isDropEnabledKnown && isSourceDragged && !isDropEnabled,\n 'mp-droppable-hover': isDropEnabledKnown && isSourceDragged && isHover,\n });\n\n const result = cloneElement(child, {\n ref: this.setHandlers,\n key: 'wrapped-component',\n className: className,\n style: style,\n });\n if (this.props.dropComponents && this.props.dropComponents.disabledHover) {\n return OverlayTrigger(\n {\n trigger: [],\n ref: 'trigger',\n placement: 'top',\n overlay: Popover({ id: 'help' }, cloneElement(this.props.dropComponents.disabledHover)),\n defaultOverlayShown: false,\n },\n result\n );\n } else {\n return result;\n }\n }\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\nexport { Droppable, DroppableProps } from './DroppableComponent';\nexport { Draggable, DraggableProps } from './DraggableComponent';\nimport * as DragAndDropApi_ from './DragAndDropApi';\nexport const DragAndDropApi = DragAndDropApi_;\n"],"sourceRoot":""}