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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
|
import { observable, computed, action } from "mobx";
import React = require("react");
import { SelectionManager } from "../util/SelectionManager";
import { observer } from "mobx-react";
import './DocumentDecorations.scss'
import { KeyStore } from '../../fields/KeyStore'
import { NumberField } from "../../fields/NumberField";
import { props } from "bluebird";
import { DragManager } from "../util/DragManager";
import { LinkMenu } from "./nodes/LinkMenu";
import { ListField } from "../../fields/ListField";
const higflyout = require("@hig/flyout");
const { anchorPoints } = higflyout;
const Flyout = higflyout.default;
@observer
export class DocumentDecorations extends React.Component {
static Instance: DocumentDecorations
private _resizer = ""
private _isPointerDown = false;
private _linkButton = React.createRef<HTMLDivElement>();
@observable private _hidden = false;
constructor(props: Readonly<{}>) {
super(props)
DocumentDecorations.Instance = this
}
@computed
get Bounds(): { x: number, y: number, b: number, r: number } {
return SelectionManager.SelectedDocuments().reduce((bounds, documentView) => {
if (documentView.props.isTopMost) {
return bounds;
}
let transform = (documentView.props.ScreenToLocalTransform().scale(documentView.props.ContentScaling())).inverse();
var [sptX, sptY] = transform.transformPoint(0, 0);
let [bptX, bptY] = transform.transformPoint(documentView.props.PanelWidth(), documentView.props.PanelHeight());
return {
x: Math.min(sptX, bounds.x), y: Math.min(sptY, bounds.y),
r: Math.max(bptX, bounds.r), b: Math.max(bptY, bounds.b)
}
}, { x: Number.MAX_VALUE, y: Number.MAX_VALUE, r: Number.MIN_VALUE, b: Number.MIN_VALUE });
}
@computed
public get Hidden() { return this._hidden; }
public set Hidden(value: boolean) { this._hidden = value; }
onPointerDown = (e: React.PointerEvent): void => {
e.stopPropagation();
if (e.button === 0) {
this._isPointerDown = true;
this._resizer = e.currentTarget.id;
document.removeEventListener("pointermove", this.onPointerMove);
document.addEventListener("pointermove", this.onPointerMove);
document.removeEventListener("pointerup", this.onPointerUp);
document.addEventListener("pointerup", this.onPointerUp);
}
}
onLinkButtonDown = (e: React.PointerEvent): void => {
// if ()
// let linkMenu = new LinkMenu(SelectionManager.SelectedDocuments()[0]);
// linkMenu.Hidden = false;
console.log("down");
e.stopPropagation();
document.removeEventListener("pointermove", this.onLinkButtonMoved)
document.addEventListener("pointermove", this.onLinkButtonMoved);
document.removeEventListener("pointerup", this.onLinkButtonUp)
document.addEventListener("pointerup", this.onLinkButtonUp);
}
onLinkButtonUp = (e: PointerEvent): void => {
console.log("up");
document.removeEventListener("pointermove", this.onLinkButtonMoved)
document.removeEventListener("pointerup", this.onLinkButtonUp)
e.stopPropagation();
}
onLinkButtonMoved = (e: PointerEvent): void => {
console.log("moved");
let dragData: { [id: string]: any } = {};
dragData["linkSourceDoc"] = SelectionManager.SelectedDocuments()[0];
if (this._linkButton.current != null) {
DragManager.StartDrag(this._linkButton.current, dragData, {
handlers: {
dragComplete: action(() => { }),
},
hideSource: false
})
}
document.removeEventListener("pointermove", this.onLinkButtonMoved)
document.removeEventListener("pointerup", this.onLinkButtonUp)
e.stopPropagation();
}
onPointerMove = (e: PointerEvent): void => {
e.stopPropagation();
e.preventDefault();
if (!this._isPointerDown) {
return;
}
let dX = 0, dY = 0, dW = 0, dH = 0;
switch (this._resizer) {
case "":
break;
case "documentDecorations-topLeftResizer":
dX = -1
dY = -1
dW = -(e.movementX)
dH = -(e.movementY)
break;
case "documentDecorations-topRightResizer":
dW = e.movementX
dY = -1
dH = -(e.movementY)
break;
case "documentDecorations-topResizer":
dY = -1
dH = -(e.movementY)
break;
case "documentDecorations-bottomLeftResizer":
dX = -1
dW = -(e.movementX)
dH = e.movementY
break;
case "documentDecorations-bottomRightResizer":
dW = e.movementX
dH = e.movementY
break;
case "documentDecorations-bottomResizer":
dH = e.movementY
break;
case "documentDecorations-leftResizer":
dX = -1
dW = -(e.movementX)
break;
case "documentDecorations-rightResizer":
dW = e.movementX
break;
}
SelectionManager.SelectedDocuments().forEach(element => {
const rect = element.screenRect();
if (rect.width !== 0) {
let doc = element.props.Document;
let width = doc.GetNumber(KeyStore.Width, 0);
let nwidth = doc.GetNumber(KeyStore.NativeWidth, 0);
let nheight = doc.GetNumber(KeyStore.NativeHeight, 0);
let height = doc.GetNumber(KeyStore.Height, nwidth ? nheight / nwidth * width : 0);
let x = doc.GetOrCreate(KeyStore.X, NumberField);
let y = doc.GetOrCreate(KeyStore.Y, NumberField);
let scale = width / rect.width;
let actualdW = Math.max(width + (dW * scale), 20);
let actualdH = Math.max(height + (dH * scale), 20);
x.Data += dX * (actualdW - width);
y.Data += dY * (actualdH - height);
var nativeWidth = doc.GetNumber(KeyStore.NativeWidth, 0);
var nativeHeight = doc.GetNumber(KeyStore.NativeHeight, 0);
if (nativeWidth > 0 && nativeHeight > 0) {
if (Math.abs(dW) > Math.abs(dH))
actualdH = nativeHeight / nativeWidth * actualdW;
else actualdW = nativeWidth / nativeHeight * actualdH;
}
doc.SetNumber(KeyStore.Width, actualdW);
doc.SetNumber(KeyStore.Height, actualdH);
}
})
}
onPointerUp = (e: PointerEvent): void => {
e.stopPropagation();
if (e.button === 0) {
e.preventDefault();
this._isPointerDown = false;
document.removeEventListener("pointermove", this.onPointerMove);
document.removeEventListener("pointerup", this.onPointerUp);
}
}
changeFlyoutContent = (): void => {
}
// buttonOnPointerUp = (e: React.PointerEvent): void => {
// e.stopPropagation();
// }
render() {
var bounds = this.Bounds;
if (this.Hidden) {
return (null);
}
if (isNaN(bounds.r) || isNaN(bounds.b) || isNaN(bounds.x) || isNaN(bounds.y)) {
console.log("DocumentDecorations: Bounds Error")
return (null);
}
let linkButton = null;
if (SelectionManager.SelectedDocuments().length > 0) {
let selFirst = SelectionManager.SelectedDocuments()[0];
linkButton = (<Flyout
anchorPoint={anchorPoints.RIGHT_TOP}
content={
<LinkMenu docView={selFirst} changeFlyout={this.changeFlyoutContent}>
</LinkMenu>
}>
<div className={"linkButton-" + (selFirst.props.Document.GetData(KeyStore.LinkedToDocs, ListField, []).length ? "nonempty" : "empty")} onPointerDown={this.onLinkButtonDown} ref={this._linkButton} />
</Flyout>);
}
return (
<div id="documentDecorations-container" style={{
width: (bounds.r - bounds.x + 40) + "px",
height: (bounds.b - bounds.y + 40) + "px",
left: bounds.x - 20,
top: bounds.y - 20,
}}>
<div id="documentDecorations-topLeftResizer" className="documentDecorations-resizer" onPointerDown={this.onPointerDown} onContextMenu={(e) => e.preventDefault()}></div>
<div id="documentDecorations-topResizer" className="documentDecorations-resizer" onPointerDown={this.onPointerDown} onContextMenu={(e) => e.preventDefault()}></div>
<div id="documentDecorations-topRightResizer" className="documentDecorations-resizer" onPointerDown={this.onPointerDown} onContextMenu={(e) => e.preventDefault()}></div>
<div id="documentDecorations-leftResizer" className="documentDecorations-resizer" onPointerDown={this.onPointerDown} onContextMenu={(e) => e.preventDefault()}></div>
<div id="documentDecorations-centerCont"></div>
<div id="documentDecorations-rightResizer" className="documentDecorations-resizer" onPointerDown={this.onPointerDown} onContextMenu={(e) => e.preventDefault()}></div>
<div id="documentDecorations-bottomLeftResizer" className="documentDecorations-resizer" onPointerDown={this.onPointerDown} onContextMenu={(e) => e.preventDefault()}></div>
<div id="documentDecorations-bottomResizer" className="documentDecorations-resizer" onPointerDown={this.onPointerDown} onContextMenu={(e) => e.preventDefault()}></div>
<div id="documentDecorations-bottomRightResizer" className="documentDecorations-resizer" onPointerDown={this.onPointerDown} onContextMenu={(e) => e.preventDefault()}></div>
{linkButton}
</div >
)
}
}
|