1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
import React, { Component } from 'react'
import { Link } from 'react-router-dom'
import { history } from '../../../store'
export default class PageHandle extends Component {
constructor(props){
super(props)
this.ref = React.createRef()
}
componentDidMount(){
this.measure()
}
componentDidUpdate(prevProps){
if (this.props.page.title !== prevProps.page.title) {
this.measure()
}
}
measure() {
const { offsetWidth: width, offsetHeight: height } = this.ref.current
const { id } = this.props.page
// console.log(id, width, height)
this.props.onMeasure({ id, width, height })
}
render() {
const { graph, page, bounds, box, onMouseDown } = this.props
let style;
if (box) {
style = {
top: (bounds.height) * box.y,
left: (bounds.width) * box.x,
}
} else {
style = {
top: (bounds.height) * Math.min(page.settings.y, 0.95),
left: (bounds.width) * Math.min(page.settings.x, 0.95),
}
}
const url = '/' + graph.path + '/' + page.path
// console.log(style)
return (
<div
className='handle'
ref={this.ref}
onMouseDown={onMouseDown}
onDoubleClick={() => history.push(url)}
style={style}
>
{page.path}
<Link to={url}>{'>'}</Link>
</div>
)
}
}
|