MCPcopy Index your code
hub / github.com/SplootCode/splootcode / DragOverlayInternal

Class DragOverlayInternal

packages/editor/src/components/drag_overlay.tsx:55–113  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

53}
54
55class DragOverlayInternal extends React.Component<DragOverlayInternalProps, DragOverlayInternalState> {
56 constructor(props) {
57 super(props)
58 this.state = {
59 x: this.props.initialX,
60 y: this.props.initialY,
61 }
62 }
63
64 render() {
65 const { fragment } = this.props
66 const { x, y } = this.state
67 return (
68 <div onMouseUp={this.onMouseUp} onMouseMove={this.onMouseMove}>
69 <svg
70 className="drag-overlay"
71 xmlns="http://www.w3.org/2000/svg"
72 height={window.innerHeight}
73 width={window.innerWidth}
74 preserveAspectRatio="none"
75 >
76 <g transform={`translate(${x} ${y})`}>
77 <FragmentView fragment={fragment} />
78 </g>
79 </svg>
80 </div>
81 )
82 }
83
84 onMouseUp = (event: React.MouseEvent) => {
85 const { selection, fragment, editorRef } = this.props
86
87 const refBox = editorRef.current.getBoundingClientRect()
88 const x = event.pageX - refBox.left
89 const y = event.pageY - refBox.top
90
91 selection.placeCursorByXYCoordinate(x, y)
92 selection.insertFragment(fragment.fragment.clone())
93 this.props.onEndDrag()
94 }
95
96 onMouseMove = (event: React.MouseEvent) => {
97 if (event.buttons === 0) {
98 this.props.onEndDrag()
99 } else {
100 const { selection } = this.props
101 this.setState({
102 x: event.pageX,
103 y: event.pageY,
104 })
105 const refBox = this.props.editorRef.current.getBoundingClientRect()
106 const x = event.pageX - refBox.left
107 const y = event.pageY - refBox.top
108
109 // TODO: Only allow cursors in positions that make sense.
110 selection.placeCursorByXYCoordinate(x, y)
111 }
112 }

Callers

nothing calls this directly

Calls 3

insertFragmentMethod · 0.80
cloneMethod · 0.45

Tested by

no test coverage detected