Select Git revision
Drop_facts.ts
Drop_facts.ts 4.10 KiB
// ignore
if (event.dataTransfer === null
|| event.target === null
|| !(event.target instanceof HTMLElement)) {
console.log("Ignored illegal DragEvent")
return
}
event.preventDefault()
console.log("dropHandler", event)
const data = event.dataTransfer.getData("application/json")
//const data = event.dataTransfer.getData("text/plain")
console.log(`Dropped data: '${event.dataTransfer.types}'`, event.dataTransfer.types)
const fact: Fact = JSON.parse(data)
console.warn(`Dropped Fact '${fact.label}':`, fact)
const target: HTMLElement = event.target
if (target.dataset.allowedTypes !== undefined) {
//const allowedTypesStr = element.dataset["allowed-types"]
const allowedTypesStr = target.dataset.allowedTypes
const allowedTypes = allowedTypesStr.split(" ")
if (!allowedTypes.includes(fact.type)) {
console.warn(`The drop target is of type '${fact.type}' is not a member of the allowed types: ${allowedTypesStr}`)
return
}
}
//element.fact = fact
target.dataset.factId = fact.uri
$(target).trigger("FactAssigned", fact)
// Mathmind belongs into Unity.
// const mathMind = document.querySelector('#math-mind-canvas')
// if(mathMind instanceof HTMLCanvasElement)
// {
// if (fact instanceof Point_Fact) {
// mathMind.dispatchEvent(new CustomEvent("PointAssigned", {detail: fact}))
// }
// }
}
/** @param {MouseEvent} event */
function clickHandler(event: MouseEvent) {
// ignore
if (event.target == null
|| !(event.target instanceof HTMLElement)) {
console.warn("Ignored illegal DragEvent")
return
}
event.preventDefault()
console.log("clickHandler")
console.log("clickHandler", event)
const target: HTMLElement = event.target
switch (event.button) {
case 0:
console.log("Left button clicked")
target.dataset.factId = undefined
target.dispatchEvent(new Event("factUnassigned"))
break
case 1:
console.log("Middle button clicked")
break
case 2:
console.log("Right button clicked")
if (target.dataset.slotId) {
getHint(target.dataset.slotId)