|
@ -2,57 +2,64 @@ export class Display { |
|
|
constructor(baseUrl, dispatch, target) { |
|
|
constructor(baseUrl, dispatch, target) { |
|
|
this.baseUrl = baseUrl |
|
|
this.baseUrl = baseUrl |
|
|
this.target = target |
|
|
this.target = target |
|
|
target.addEventListener('click', e => { |
|
|
|
|
|
let target = e.target |
|
|
|
|
|
|
|
|
const findA = target => { |
|
|
while (target.nodeName !== 'A') { |
|
|
while (target.nodeName !== 'A') { |
|
|
target = target.parentNode |
|
|
target = target.parentNode |
|
|
if (!target) return |
|
|
if (!target) return |
|
|
} |
|
|
} |
|
|
|
|
|
return target |
|
|
|
|
|
} |
|
|
|
|
|
target.addEventListener('click', e => { |
|
|
|
|
|
let target = findA(e.target) |
|
|
|
|
|
if (!target) return |
|
|
window.history.pushState(null, "", target.href) |
|
|
window.history.pushState(null, "", target.href) |
|
|
dispatch(target.getAttribute('href')) |
|
|
dispatch(target.getAttribute('href')) |
|
|
e.preventDefault() |
|
|
e.preventDefault() |
|
|
}) |
|
|
}) |
|
|
this.graph = new Springy.Graph() |
|
|
|
|
|
this.layout = new Springy.Layout.ForceDirected( |
|
|
|
|
|
this.graph, |
|
|
|
|
|
400.0, // Spring stiffness
|
|
|
|
|
|
400.0, // Node repulsion
|
|
|
|
|
|
0.5 // Damping
|
|
|
|
|
|
) |
|
|
|
|
|
} |
|
|
|
|
|
render(state) { |
|
|
|
|
|
const target = document.createElement('div') |
|
|
|
|
|
target.className = 'wrapper' |
|
|
|
|
|
const field = document.createElement('ul') |
|
|
|
|
|
field.className = 'items' |
|
|
|
|
|
|
|
|
|
|
|
field.addEventListener('dragstart', e => { |
|
|
|
|
|
|
|
|
target.addEventListener('dragstart', e => { |
|
|
let target = findA(e.target) |
|
|
let target = findA(e.target) |
|
|
if (!target || !target.draggable) return |
|
|
if (!target || !target.draggable) return |
|
|
e.dataTransfer.setData('application/prs.x', target.dataset['id']) |
|
|
e.dataTransfer.setData('application/prs.x', target.dataset['id']) |
|
|
e.dataTransfer.effectAllowed = 'link' |
|
|
e.dataTransfer.effectAllowed = 'link' |
|
|
}) |
|
|
}) |
|
|
field.addEventListener('dragenter', e => { |
|
|
|
|
|
|
|
|
target.addEventListener('dragenter', e => { |
|
|
let target = findA(e.target) |
|
|
let target = findA(e.target) |
|
|
if (!target) return |
|
|
if (!target) return |
|
|
e.preventDefault() |
|
|
e.preventDefault() |
|
|
}) |
|
|
}) |
|
|
field.addEventListener('dragover', e => { |
|
|
|
|
|
|
|
|
target.addEventListener('dragover', e => { |
|
|
let target = findA(e.target) |
|
|
let target = findA(e.target) |
|
|
if (!target) return |
|
|
if (!target) return |
|
|
e.preventDefault() |
|
|
e.preventDefault() |
|
|
}) |
|
|
}) |
|
|
field.addEventListener('drop', e => { |
|
|
|
|
|
|
|
|
target.addEventListener('drop', e => { |
|
|
let target = findA(e.target) |
|
|
let target = findA(e.target) |
|
|
if (!target) return |
|
|
if (!target) return |
|
|
e.preventDefault() |
|
|
e.preventDefault() |
|
|
dispatch({ action: 'link', from: e.dataTransfer.getData("application/prs.x"), to: target.dataset['id']}) |
|
|
dispatch({ action: 'link', from: e.dataTransfer.getData("application/prs.x"), to: target.dataset['id']}) |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
this.graph = new Springy.Graph() |
|
|
|
|
|
this.layout = new Springy.Layout.ForceDirected( |
|
|
|
|
|
this.graph, |
|
|
|
|
|
400.0, // Spring stiffness
|
|
|
|
|
|
400.0, // Node repulsion
|
|
|
|
|
|
0.5 // Damping
|
|
|
|
|
|
) |
|
|
|
|
|
} |
|
|
|
|
|
render(state) { |
|
|
|
|
|
const target = document.createElement('div') |
|
|
|
|
|
target.className = 'wrapper' |
|
|
|
|
|
const field = document.createElement('ul') |
|
|
|
|
|
field.className = 'items' |
|
|
|
|
|
|
|
|
const graph = this.graph |
|
|
const graph = this.graph |
|
|
for (const item of state.items) { |
|
|
for (const item of state.items) { |
|
|
graph.addNode(new Springy.Node(item.id, item)) |
|
|
graph.addNode(new Springy.Node(item.id, item)) |
|
|
} |
|
|
} |
|
|
|
|
|
for (const item of state.links) { |
|
|
|
|
|
graph.addEdge(new Springy.Edge(item.id, graph.nodeSet[item.from], graph.nodeSet[item.to], {})) |
|
|
|
|
|
} |
|
|
let currentBB = this.layout.getBoundingBox() |
|
|
let currentBB = this.layout.getBoundingBox() |
|
|
let width = this.target.scrollWidth || 100 |
|
|
let width = this.target.scrollWidth || 100 |
|
|
let height = this.target.scrollHeight || 100 |
|
|
let height = this.target.scrollHeight || 100 |
|
@ -86,7 +93,12 @@ export class Display { |
|
|
const a = document.createElement('a') |
|
|
const a = document.createElement('a') |
|
|
const action = item.data.state == 'face-down' ? 'flip' : 'show' |
|
|
const action = item.data.state == 'face-down' ? 'flip' : 'show' |
|
|
a.href = `/${item.id}/${action}` |
|
|
a.href = `/${item.id}/${action}` |
|
|
a.style.backgroundImage = `url(img/${item.data.img})` |
|
|
|
|
|
|
|
|
a.draggable = false |
|
|
|
|
|
if (item.data.state !== 'face-down') { |
|
|
|
|
|
a.style.backgroundImage = `url(/img/${item.data.img})` |
|
|
|
|
|
a.dataset['id'] = item.id |
|
|
|
|
|
a.draggable = true |
|
|
|
|
|
} |
|
|
dom.className = item.data.state |
|
|
dom.className = item.data.state |
|
|
dom.style.position = 'absolute' |
|
|
dom.style.position = 'absolute' |
|
|
dom.style.left = target.x + 'px' |
|
|
dom.style.left = target.x + 'px' |
|
|