@activecollab/components 2.0.587 → 2.0.589
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/Capsule/Capsule.js +41 -0
- package/dist/cjs/components/Capsule/Capsule.js.map +1 -0
- package/dist/cjs/components/Capsule/CapsuleButton.js +115 -0
- package/dist/cjs/components/Capsule/CapsuleButton.js.map +1 -0
- package/dist/cjs/components/Capsule/Styles.js +36 -0
- package/dist/cjs/components/Capsule/Styles.js.map +1 -0
- package/dist/cjs/components/Capsule/index.js +28 -0
- package/dist/cjs/components/Capsule/index.js.map +1 -0
- package/dist/cjs/components/Icons/collection/Pointer.js +58 -0
- package/dist/cjs/components/Icons/collection/Pointer.js.map +1 -0
- package/dist/cjs/components/Icons/collection/index.js +7 -0
- package/dist/cjs/components/Icons/collection/index.js.map +1 -1
- package/dist/cjs/components/index.js +12 -0
- package/dist/cjs/components/index.js.map +1 -1
- package/dist/cjs/presentation/whiteboard/elementToolbars.js +192 -1
- package/dist/cjs/presentation/whiteboard/elementToolbars.js.map +1 -1
- package/dist/cjs/presentation/whiteboard/inspector.js +6 -1
- package/dist/cjs/presentation/whiteboard/inspector.js.map +1 -1
- package/dist/cjs/presentation/whiteboard/lineElements.js +982 -0
- package/dist/cjs/presentation/whiteboard/lineElements.js.map +1 -0
- package/dist/cjs/presentation/whiteboard/lineInspector.js +301 -0
- package/dist/cjs/presentation/whiteboard/lineInspector.js.map +1 -0
- package/dist/cjs/presentation/whiteboard/lineModel.js +596 -0
- package/dist/cjs/presentation/whiteboard/lineModel.js.map +1 -0
- package/dist/cjs/presentation/whiteboard/outline.js +31 -12
- package/dist/cjs/presentation/whiteboard/outline.js.map +1 -1
- package/dist/cjs/presentation/whiteboardModern/contextToolbar.js +18 -20
- package/dist/cjs/presentation/whiteboardModern/contextToolbar.js.map +1 -1
- package/dist/cjs/presentation/whiteboardModern/toolDock.js +24 -29
- package/dist/cjs/presentation/whiteboardModern/toolDock.js.map +1 -1
- package/dist/cjs/presentation/whiteboardModern/topBars.js +11 -11
- package/dist/cjs/presentation/whiteboardModern/topBars.js.map +1 -1
- package/dist/esm/components/Capsule/Capsule.d.ts +11 -0
- package/dist/esm/components/Capsule/Capsule.d.ts.map +1 -0
- package/dist/esm/components/Capsule/Capsule.js +32 -0
- package/dist/esm/components/Capsule/Capsule.js.map +1 -0
- package/dist/esm/components/Capsule/CapsuleButton.d.ts +31 -0
- package/dist/esm/components/Capsule/CapsuleButton.d.ts.map +1 -0
- package/dist/esm/components/Capsule/CapsuleButton.js +102 -0
- package/dist/esm/components/Capsule/CapsuleButton.js.map +1 -0
- package/dist/esm/components/Capsule/Styles.d.ts +10 -0
- package/dist/esm/components/Capsule/Styles.d.ts.map +1 -0
- package/dist/esm/components/Capsule/Styles.js +29 -0
- package/dist/esm/components/Capsule/Styles.js.map +1 -0
- package/dist/esm/components/Capsule/index.d.ts +3 -0
- package/dist/esm/components/Capsule/index.d.ts.map +1 -0
- package/dist/esm/components/Capsule/index.js +3 -0
- package/dist/esm/components/Capsule/index.js.map +1 -0
- package/dist/esm/components/Icons/collection/Pointer.d.ts +30 -0
- package/dist/esm/components/Icons/collection/Pointer.d.ts.map +1 -0
- package/dist/esm/components/Icons/collection/Pointer.js +51 -0
- package/dist/esm/components/Icons/collection/Pointer.js.map +1 -0
- package/dist/esm/components/Icons/collection/index.d.ts +1 -0
- package/dist/esm/components/Icons/collection/index.d.ts.map +1 -1
- package/dist/esm/components/Icons/collection/index.js +1 -0
- package/dist/esm/components/Icons/collection/index.js.map +1 -1
- package/dist/esm/components/index.d.ts +1 -0
- package/dist/esm/components/index.d.ts.map +1 -1
- package/dist/esm/components/index.js +1 -0
- package/dist/esm/components/index.js.map +1 -1
- package/dist/esm/presentation/whiteboard/elementToolbars.d.ts +22 -0
- package/dist/esm/presentation/whiteboard/elementToolbars.d.ts.map +1 -1
- package/dist/esm/presentation/whiteboard/elementToolbars.js +151 -2
- package/dist/esm/presentation/whiteboard/elementToolbars.js.map +1 -1
- package/dist/esm/presentation/whiteboard/inspector.d.ts +10 -2
- package/dist/esm/presentation/whiteboard/inspector.d.ts.map +1 -1
- package/dist/esm/presentation/whiteboard/inspector.js +6 -2
- package/dist/esm/presentation/whiteboard/inspector.js.map +1 -1
- package/dist/esm/presentation/whiteboard/lineElements.d.ts +23 -0
- package/dist/esm/presentation/whiteboard/lineElements.d.ts.map +1 -0
- package/dist/esm/presentation/whiteboard/lineElements.js +851 -0
- package/dist/esm/presentation/whiteboard/lineElements.js.map +1 -0
- package/dist/esm/presentation/whiteboard/lineInspector.d.ts +9 -0
- package/dist/esm/presentation/whiteboard/lineInspector.d.ts.map +1 -0
- package/dist/esm/presentation/whiteboard/lineInspector.js +224 -0
- package/dist/esm/presentation/whiteboard/lineInspector.js.map +1 -0
- package/dist/esm/presentation/whiteboard/lineModel.d.ts +132 -0
- package/dist/esm/presentation/whiteboard/lineModel.d.ts.map +1 -0
- package/dist/esm/presentation/whiteboard/lineModel.js +555 -0
- package/dist/esm/presentation/whiteboard/lineModel.js.map +1 -0
- package/dist/esm/presentation/whiteboard/outline.d.ts +4 -2
- package/dist/esm/presentation/whiteboard/outline.d.ts.map +1 -1
- package/dist/esm/presentation/whiteboard/outline.js +20 -7
- package/dist/esm/presentation/whiteboard/outline.js.map +1 -1
- package/dist/esm/presentation/whiteboardModern/contextToolbar.d.ts.map +1 -1
- package/dist/esm/presentation/whiteboardModern/contextToolbar.js +13 -15
- package/dist/esm/presentation/whiteboardModern/contextToolbar.js.map +1 -1
- package/dist/esm/presentation/whiteboardModern/toolDock.d.ts +2 -2
- package/dist/esm/presentation/whiteboardModern/toolDock.d.ts.map +1 -1
- package/dist/esm/presentation/whiteboardModern/toolDock.js +20 -25
- package/dist/esm/presentation/whiteboardModern/toolDock.js.map +1 -1
- package/dist/esm/presentation/whiteboardModern/topBars.d.ts.map +1 -1
- package/dist/esm/presentation/whiteboardModern/topBars.js +9 -9
- package/dist/esm/presentation/whiteboardModern/topBars.js.map +1 -1
- package/dist/index.js +1158 -952
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/package.json +1 -1
- package/dist/cjs/presentation/whiteboardModern/surface.js +0 -119
- package/dist/cjs/presentation/whiteboardModern/surface.js.map +0 -1
- package/dist/esm/presentation/whiteboardModern/surface.d.ts +0 -29
- package/dist/esm/presentation/whiteboardModern/surface.d.ts.map +0 -1
- package/dist/esm/presentation/whiteboardModern/surface.js +0 -111
- package/dist/esm/presentation/whiteboardModern/surface.js.map +0 -1
|
@@ -0,0 +1,851 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import React, { useCallback, useEffect, useRef, useState } from "react";
|
|
3
|
+
import styled from "styled-components";
|
|
4
|
+
import { SELECTION_BLUE, snapValue, withOpacity } from "./elements";
|
|
5
|
+
import { LineFormattingToolbar, LineLabelToolbar } from "./elementToolbars";
|
|
6
|
+
import { DEFAULT_LABEL, DEFAULT_LINE_STYLE, LINE_DEFAULT_LENGTH, LINE_HIT_WIDTH, MAX_WAYPOINTS, barIsVertical, constrainAngle, dashArray, elbowAxis, elbowRoute, elbowSegmentIndex, lineEndGlyph, lineGeometry, pointAtFraction, projectOnSamples, resolveEndpoints, withLineType } from "./lineModel";
|
|
7
|
+
import { GUIDE_COLOR, resolveBoardColor } from "./palette";
|
|
8
|
+
import { EditableText } from "../../components/EditableText";
|
|
9
|
+
import { Body2 } from "../../components/Typography";
|
|
10
|
+
export const SEEDED_LINES = [{
|
|
11
|
+
id: "line-scope-arrow",
|
|
12
|
+
kind: "line",
|
|
13
|
+
name: "Scope arrow",
|
|
14
|
+
type: "line",
|
|
15
|
+
start: {
|
|
16
|
+
x: 80,
|
|
17
|
+
y: 136
|
|
18
|
+
},
|
|
19
|
+
end: {
|
|
20
|
+
x: 256,
|
|
21
|
+
y: 232
|
|
22
|
+
},
|
|
23
|
+
waypoints: {
|
|
24
|
+
curved: [],
|
|
25
|
+
elbow: []
|
|
26
|
+
},
|
|
27
|
+
style: _extends({}, DEFAULT_LINE_STYLE, {
|
|
28
|
+
arrow_end: "arrow"
|
|
29
|
+
}),
|
|
30
|
+
label: null
|
|
31
|
+
}, {
|
|
32
|
+
id: "line-boundary",
|
|
33
|
+
kind: "line",
|
|
34
|
+
name: "Out of scope boundary",
|
|
35
|
+
type: "line",
|
|
36
|
+
start: {
|
|
37
|
+
x: 80,
|
|
38
|
+
y: 312
|
|
39
|
+
},
|
|
40
|
+
end: {
|
|
41
|
+
x: 256,
|
|
42
|
+
y: 312
|
|
43
|
+
},
|
|
44
|
+
waypoints: {
|
|
45
|
+
curved: [],
|
|
46
|
+
elbow: []
|
|
47
|
+
},
|
|
48
|
+
style: _extends({}, DEFAULT_LINE_STYLE, {
|
|
49
|
+
stroke: "purple",
|
|
50
|
+
stroke_pattern: "dashed"
|
|
51
|
+
}),
|
|
52
|
+
label: null
|
|
53
|
+
}, {
|
|
54
|
+
id: "line-handoff",
|
|
55
|
+
kind: "line",
|
|
56
|
+
name: "Handoff path",
|
|
57
|
+
type: "elbow",
|
|
58
|
+
start: {
|
|
59
|
+
x: 96,
|
|
60
|
+
y: 400
|
|
61
|
+
},
|
|
62
|
+
end: {
|
|
63
|
+
x: 304,
|
|
64
|
+
y: 608
|
|
65
|
+
},
|
|
66
|
+
waypoints: {
|
|
67
|
+
curved: [],
|
|
68
|
+
elbow: [{
|
|
69
|
+
x: 200,
|
|
70
|
+
y: 504
|
|
71
|
+
}]
|
|
72
|
+
},
|
|
73
|
+
style: _extends({}, DEFAULT_LINE_STYLE, {
|
|
74
|
+
stroke: "blueSky",
|
|
75
|
+
arrow_end: "arrow",
|
|
76
|
+
corner_radius: 16
|
|
77
|
+
}),
|
|
78
|
+
label: _extends({}, DEFAULT_LABEL, {
|
|
79
|
+
text: "Handoff",
|
|
80
|
+
position: 0.5
|
|
81
|
+
})
|
|
82
|
+
}, {
|
|
83
|
+
id: "line-feedback-loop",
|
|
84
|
+
kind: "line",
|
|
85
|
+
name: "Feedback loop",
|
|
86
|
+
type: "curved",
|
|
87
|
+
start: {
|
|
88
|
+
x: 616,
|
|
89
|
+
y: 472
|
|
90
|
+
},
|
|
91
|
+
end: {
|
|
92
|
+
x: 888,
|
|
93
|
+
y: 472
|
|
94
|
+
},
|
|
95
|
+
waypoints: {
|
|
96
|
+
curved: [{
|
|
97
|
+
x: 704,
|
|
98
|
+
y: 416
|
|
99
|
+
}, {
|
|
100
|
+
x: 800,
|
|
101
|
+
y: 544
|
|
102
|
+
}],
|
|
103
|
+
elbow: []
|
|
104
|
+
},
|
|
105
|
+
style: _extends({}, DEFAULT_LINE_STYLE, {
|
|
106
|
+
stroke: "coral",
|
|
107
|
+
arrow_start: "dot",
|
|
108
|
+
arrow_end: "arrow"
|
|
109
|
+
}),
|
|
110
|
+
label: null
|
|
111
|
+
}, {
|
|
112
|
+
id: "connector-discovery-kickoff",
|
|
113
|
+
kind: "connector",
|
|
114
|
+
name: null,
|
|
115
|
+
type: "curved",
|
|
116
|
+
start: {
|
|
117
|
+
x: 0,
|
|
118
|
+
y: 0
|
|
119
|
+
},
|
|
120
|
+
end: {
|
|
121
|
+
x: 0,
|
|
122
|
+
y: 0
|
|
123
|
+
},
|
|
124
|
+
start_element_id: "shape-circle",
|
|
125
|
+
end_element_id: "shape-rounded",
|
|
126
|
+
start_anchor: "right",
|
|
127
|
+
end_anchor: "left",
|
|
128
|
+
waypoints: {
|
|
129
|
+
curved: [{
|
|
130
|
+
x: 488,
|
|
131
|
+
y: 232
|
|
132
|
+
}],
|
|
133
|
+
elbow: []
|
|
134
|
+
},
|
|
135
|
+
style: _extends({}, DEFAULT_LINE_STYLE, {
|
|
136
|
+
arrow_end: "arrow"
|
|
137
|
+
}),
|
|
138
|
+
label: _extends({}, DEFAULT_LABEL, {
|
|
139
|
+
text: "leads to",
|
|
140
|
+
position: 0.35
|
|
141
|
+
})
|
|
142
|
+
}];
|
|
143
|
+
const StyledLineLayer = styled.div.withConfig({
|
|
144
|
+
displayName: "lineElements__StyledLineLayer",
|
|
145
|
+
componentId: "sc-8q987b-0"
|
|
146
|
+
})(["position:absolute;inset:0;z-index:30;pointer-events:none;.wb-lines{position:absolute;left:0;top:0;width:100%;height:100%;overflow:visible;pointer-events:none;}.wb-line-hit{pointer-events:stroke;cursor:pointer;}.wb-line-halo{opacity:0;transition:opacity 120ms ease;}.wb-line:hover .wb-line-halo{opacity:0.3;}.wb-line.is-selected .wb-line-halo{opacity:0.2;}.wb-handle{pointer-events:all;cursor:grab;fill:var(--only-white);stroke:", ";stroke-width:1.5;}.wb-handle.is-active{fill:", ";}.wb-handle.is-anchored{cursor:default;fill:", ";}.wb-handle.is-ns{cursor:ns-resize;}.wb-handle.is-ew{cursor:ew-resize;}.wb-draw-surface{position:absolute;inset:0;pointer-events:auto;cursor:crosshair;}.wb-line-label{position:absolute;transform:translate(-50%,-50%);padding:2px 6px;border-radius:4px;box-sizing:border-box;white-space:nowrap;background-color:var(--page-paper-main);pointer-events:auto;cursor:move;}.wb-line-label.is-selected{box-shadow:0 0 0 1.5px ", ";}.wb-line-label textarea,.wb-line-label .presentation{font-size:inherit;font-weight:inherit;font-style:inherit;color:inherit;}.wb-toolbar-host{position:absolute;left:0;top:0;}.wb-toolbar-host > *{pointer-events:auto;}"], SELECTION_BLUE, SELECTION_BLUE, SELECTION_BLUE, SELECTION_BLUE);
|
|
147
|
+
const GUIDE_REACH = 6;
|
|
148
|
+
const offset = (point, dx, dy) => ({
|
|
149
|
+
x: point.x + dx,
|
|
150
|
+
y: point.y + dy
|
|
151
|
+
});
|
|
152
|
+
const elbowBars = (line, start, end) => line.waypoints.elbow.length ? line.waypoints.elbow : [{
|
|
153
|
+
x: (start.x + end.x) / 2,
|
|
154
|
+
y: (start.y + end.y) / 2
|
|
155
|
+
}];
|
|
156
|
+
export const LineLayer = _ref => {
|
|
157
|
+
var _lines$find;
|
|
158
|
+
let lines = _ref.lines,
|
|
159
|
+
setLines = _ref.setLines,
|
|
160
|
+
selectedId = _ref.selectedId,
|
|
161
|
+
setSelectedId = _ref.onSelectedIdChange,
|
|
162
|
+
armed = _ref.armed,
|
|
163
|
+
onToolUsed = _ref.onToolUsed,
|
|
164
|
+
snapStep = _ref.snapStep,
|
|
165
|
+
boxOf = _ref.boxOf,
|
|
166
|
+
locks = _ref.locks,
|
|
167
|
+
onToggleLock = _ref.onToggleLock,
|
|
168
|
+
_ref$initialWaypoint = _ref.initialWaypoint,
|
|
169
|
+
initialWaypoint = _ref$initialWaypoint === void 0 ? null : _ref$initialWaypoint;
|
|
170
|
+
const layerRef = useRef(null);
|
|
171
|
+
const counterRef = useRef(0);
|
|
172
|
+
const _useState = useState(initialWaypoint),
|
|
173
|
+
waypointSelection = _useState[0],
|
|
174
|
+
setWaypointSelection = _useState[1];
|
|
175
|
+
const _useState2 = useState(null),
|
|
176
|
+
labelFor = _useState2[0],
|
|
177
|
+
setLabelFor = _useState2[1];
|
|
178
|
+
const _useState3 = useState(null),
|
|
179
|
+
editingFor = _useState3[0],
|
|
180
|
+
setEditingFor = _useState3[1];
|
|
181
|
+
const _useState4 = useState(null),
|
|
182
|
+
draft = _useState4[0],
|
|
183
|
+
setDraft = _useState4[1];
|
|
184
|
+
const _useState5 = useState(null),
|
|
185
|
+
guides = _useState5[0],
|
|
186
|
+
setGuides = _useState5[1];
|
|
187
|
+
const selectedLine = (_lines$find = lines.find(line => line.id === selectedId)) != null ? _lines$find : null;
|
|
188
|
+
const selectedWaypoint = waypointSelection && waypointSelection.lineId === selectedId ? waypointSelection.index : null;
|
|
189
|
+
const labelSelected = labelFor !== null && labelFor === selectedId;
|
|
190
|
+
const editing = editingFor !== null && editingFor === selectedId;
|
|
191
|
+
const canvasPoint = useCallback((clientX, clientY) => {
|
|
192
|
+
var _layerRef$current, _rect$left, _rect$top;
|
|
193
|
+
const rect = (_layerRef$current = layerRef.current) == null ? void 0 : _layerRef$current.getBoundingClientRect();
|
|
194
|
+
return {
|
|
195
|
+
x: clientX - ((_rect$left = rect == null ? void 0 : rect.left) != null ? _rect$left : 0),
|
|
196
|
+
y: clientY - ((_rect$top = rect == null ? void 0 : rect.top) != null ? _rect$top : 0)
|
|
197
|
+
};
|
|
198
|
+
}, []);
|
|
199
|
+
const updateLine = useCallback((id, update) => setLines(current => current.map(line => line.id === id ? update(line) : line)), [setLines]);
|
|
200
|
+
const updateLabel = (id, partial) => updateLine(id, line => line.label ? _extends({}, line, {
|
|
201
|
+
label: _extends({}, line.label, partial)
|
|
202
|
+
}) : line);
|
|
203
|
+
const removeLabel = id => {
|
|
204
|
+
updateLine(id, line => _extends({}, line, {
|
|
205
|
+
label: null
|
|
206
|
+
}));
|
|
207
|
+
setLabelFor(null);
|
|
208
|
+
setEditingFor(null);
|
|
209
|
+
};
|
|
210
|
+
const startLabelEdit = function (line, position) {
|
|
211
|
+
if (position === void 0) {
|
|
212
|
+
position = 0.5;
|
|
213
|
+
}
|
|
214
|
+
if (!line.label) {
|
|
215
|
+
updateLine(line.id, current => _extends({}, current, {
|
|
216
|
+
label: _extends({}, DEFAULT_LABEL, {
|
|
217
|
+
position
|
|
218
|
+
})
|
|
219
|
+
}));
|
|
220
|
+
}
|
|
221
|
+
setSelectedId(line.id);
|
|
222
|
+
setWaypointSelection(null);
|
|
223
|
+
setLabelFor(line.id);
|
|
224
|
+
setEditingFor(line.id);
|
|
225
|
+
};
|
|
226
|
+
const snapWithGuides = (point, others) => {
|
|
227
|
+
let x = snapValue(point.x, snapStep);
|
|
228
|
+
let y = snapValue(point.y, snapStep);
|
|
229
|
+
const found = {};
|
|
230
|
+
others.forEach(other => {
|
|
231
|
+
if (found.x === undefined && Math.abs(other.x - point.x) <= GUIDE_REACH) {
|
|
232
|
+
x = other.x;
|
|
233
|
+
found.x = other.x;
|
|
234
|
+
}
|
|
235
|
+
if (found.y === undefined && Math.abs(other.y - point.y) <= GUIDE_REACH) {
|
|
236
|
+
y = other.y;
|
|
237
|
+
found.y = other.y;
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
setGuides(found.x !== undefined || found.y !== undefined ? found : null);
|
|
241
|
+
return {
|
|
242
|
+
x,
|
|
243
|
+
y
|
|
244
|
+
};
|
|
245
|
+
};
|
|
246
|
+
const beginDrag = (event, onMove) => {
|
|
247
|
+
event.preventDefault();
|
|
248
|
+
event.stopPropagation();
|
|
249
|
+
const handleMove = move => onMove(canvasPoint(move.clientX, move.clientY), move);
|
|
250
|
+
const handleUp = () => {
|
|
251
|
+
setGuides(null);
|
|
252
|
+
window.removeEventListener("mousemove", handleMove);
|
|
253
|
+
window.removeEventListener("mouseup", handleUp);
|
|
254
|
+
};
|
|
255
|
+
window.addEventListener("mousemove", handleMove);
|
|
256
|
+
window.addEventListener("mouseup", handleUp);
|
|
257
|
+
};
|
|
258
|
+
const pointsOf = line => {
|
|
259
|
+
const _resolveEndpoints = resolveEndpoints(line, boxOf),
|
|
260
|
+
start = _resolveEndpoints.start,
|
|
261
|
+
end = _resolveEndpoints.end;
|
|
262
|
+
return [start, end, ...(line.type === "line" ? [] : line.waypoints[line.type])];
|
|
263
|
+
};
|
|
264
|
+
const insertWaypoint = (line, geometry, point) => {
|
|
265
|
+
const _resolveEndpoints2 = resolveEndpoints(line, boxOf),
|
|
266
|
+
start = _resolveEndpoints2.start,
|
|
267
|
+
end = _resolveEndpoints2.end;
|
|
268
|
+
if (line.type === "curved") {
|
|
269
|
+
if (line.waypoints.curved.length >= MAX_WAYPOINTS) {
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
const projection = projectOnSamples(geometry.samples, geometry.sampleSegments, point);
|
|
273
|
+
const curved = [...line.waypoints.curved];
|
|
274
|
+
curved.splice(projection.segment, 0, projection.point);
|
|
275
|
+
updateLine(line.id, current => _extends({}, current, {
|
|
276
|
+
waypoints: _extends({}, current.waypoints, {
|
|
277
|
+
curved
|
|
278
|
+
})
|
|
279
|
+
}));
|
|
280
|
+
setWaypointSelection({
|
|
281
|
+
lineId: line.id,
|
|
282
|
+
index: projection.segment
|
|
283
|
+
});
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
const bars = elbowBars(line, start, end);
|
|
287
|
+
if (bars.length + 2 > MAX_WAYPOINTS) {
|
|
288
|
+
return;
|
|
289
|
+
}
|
|
290
|
+
const segment = elbowSegmentIndex(geometry.route, point);
|
|
291
|
+
const at = Math.min(segment, bars.length);
|
|
292
|
+
const projection = projectOnSamples([geometry.route[segment], geometry.route[segment + 1]], [segment, segment], point).point;
|
|
293
|
+
const elbow = [...bars];
|
|
294
|
+
elbow.splice(at, 0, projection, projection);
|
|
295
|
+
updateLine(line.id, current => _extends({}, current, {
|
|
296
|
+
waypoints: _extends({}, current.waypoints, {
|
|
297
|
+
elbow
|
|
298
|
+
})
|
|
299
|
+
}));
|
|
300
|
+
setWaypointSelection({
|
|
301
|
+
lineId: line.id,
|
|
302
|
+
index: segment <= bars.length ? at + 1 : at
|
|
303
|
+
});
|
|
304
|
+
};
|
|
305
|
+
const removeWaypoint = (line, index) => {
|
|
306
|
+
if (line.type === "curved") {
|
|
307
|
+
updateLine(line.id, current => _extends({}, current, {
|
|
308
|
+
waypoints: _extends({}, current.waypoints, {
|
|
309
|
+
curved: current.waypoints.curved.filter((_, at) => at !== index)
|
|
310
|
+
})
|
|
311
|
+
}));
|
|
312
|
+
} else if (line.type === "elbow") {
|
|
313
|
+
const bars = line.waypoints.elbow;
|
|
314
|
+
const partner = index + 1 < bars.length ? index + 1 : index - 1;
|
|
315
|
+
updateLine(line.id, current => _extends({}, current, {
|
|
316
|
+
waypoints: _extends({}, current.waypoints, {
|
|
317
|
+
elbow: bars.filter((_, at) => at !== index && (bars.length < 2 || at !== partner))
|
|
318
|
+
})
|
|
319
|
+
}));
|
|
320
|
+
}
|
|
321
|
+
setWaypointSelection(null);
|
|
322
|
+
};
|
|
323
|
+
const nudgeWaypoint = (line, index, dx, dy) => {
|
|
324
|
+
if (line.type === "curved") {
|
|
325
|
+
updateLine(line.id, current => _extends({}, current, {
|
|
326
|
+
waypoints: _extends({}, current.waypoints, {
|
|
327
|
+
curved: current.waypoints.curved.map((point, at) => at === index ? offset(point, dx, dy) : point)
|
|
328
|
+
})
|
|
329
|
+
}));
|
|
330
|
+
} else if (line.type === "elbow") {
|
|
331
|
+
const _resolveEndpoints3 = resolveEndpoints(line, boxOf),
|
|
332
|
+
start = _resolveEndpoints3.start,
|
|
333
|
+
end = _resolveEndpoints3.end;
|
|
334
|
+
const vertical = barIsVertical(index, elbowAxis(start, end, line.start_anchor));
|
|
335
|
+
updateLine(line.id, current => _extends({}, current, {
|
|
336
|
+
waypoints: _extends({}, current.waypoints, {
|
|
337
|
+
elbow: current.waypoints.elbow.map((point, at) => at === index ? offset(point, vertical ? dx : 0, vertical ? 0 : dy) : point)
|
|
338
|
+
})
|
|
339
|
+
}));
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
const deleteLine = id => {
|
|
343
|
+
setLines(current => current.filter(line => line.id !== id));
|
|
344
|
+
setSelectedId(null);
|
|
345
|
+
};
|
|
346
|
+
const keyStateRef = useRef({
|
|
347
|
+
selectedLine,
|
|
348
|
+
selectedWaypoint,
|
|
349
|
+
labelSelected,
|
|
350
|
+
editing
|
|
351
|
+
});
|
|
352
|
+
keyStateRef.current = {
|
|
353
|
+
selectedLine,
|
|
354
|
+
selectedWaypoint,
|
|
355
|
+
labelSelected,
|
|
356
|
+
editing
|
|
357
|
+
};
|
|
358
|
+
const actionsRef = useRef({
|
|
359
|
+
removeWaypoint,
|
|
360
|
+
nudgeWaypoint,
|
|
361
|
+
removeLabel,
|
|
362
|
+
deleteLine,
|
|
363
|
+
startLabelEdit
|
|
364
|
+
});
|
|
365
|
+
actionsRef.current = {
|
|
366
|
+
removeWaypoint,
|
|
367
|
+
nudgeWaypoint,
|
|
368
|
+
removeLabel,
|
|
369
|
+
deleteLine,
|
|
370
|
+
startLabelEdit
|
|
371
|
+
};
|
|
372
|
+
useEffect(() => {
|
|
373
|
+
if (!selectedLine) {
|
|
374
|
+
return undefined;
|
|
375
|
+
}
|
|
376
|
+
const handleKeyDown = event => {
|
|
377
|
+
var _locks$line$id, _line$label$position, _line$label;
|
|
378
|
+
const target = event.target;
|
|
379
|
+
if (target instanceof Element && target.closest("input, textarea, [contenteditable='true']")) {
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
const state = keyStateRef.current;
|
|
383
|
+
const actions = actionsRef.current;
|
|
384
|
+
const line = state.selectedLine;
|
|
385
|
+
if (!line || state.editing) {
|
|
386
|
+
return;
|
|
387
|
+
}
|
|
388
|
+
const locked = (_locks$line$id = locks[line.id]) != null ? _locks$line$id : false;
|
|
389
|
+
const step = event.shiftKey ? 10 : snapStep != null ? snapStep : 1;
|
|
390
|
+
switch (event.key) {
|
|
391
|
+
case "Escape":
|
|
392
|
+
if (state.selectedWaypoint !== null) {
|
|
393
|
+
setWaypointSelection(null);
|
|
394
|
+
} else if (state.labelSelected) {
|
|
395
|
+
setLabelFor(null);
|
|
396
|
+
} else {
|
|
397
|
+
setSelectedId(null);
|
|
398
|
+
}
|
|
399
|
+
break;
|
|
400
|
+
case "Delete":
|
|
401
|
+
case "Backspace":
|
|
402
|
+
if (locked) {
|
|
403
|
+
break;
|
|
404
|
+
}
|
|
405
|
+
event.preventDefault();
|
|
406
|
+
if (state.selectedWaypoint !== null) {
|
|
407
|
+
actions.removeWaypoint(line, state.selectedWaypoint);
|
|
408
|
+
} else if (state.labelSelected) {
|
|
409
|
+
actions.removeLabel(line.id);
|
|
410
|
+
} else {
|
|
411
|
+
actions.deleteLine(line.id);
|
|
412
|
+
}
|
|
413
|
+
break;
|
|
414
|
+
case "Enter":
|
|
415
|
+
event.preventDefault();
|
|
416
|
+
actions.startLabelEdit(line, (_line$label$position = (_line$label = line.label) == null ? void 0 : _line$label.position) != null ? _line$label$position : 0.5);
|
|
417
|
+
break;
|
|
418
|
+
case "ArrowLeft":
|
|
419
|
+
case "ArrowRight":
|
|
420
|
+
case "ArrowUp":
|
|
421
|
+
case "ArrowDown":
|
|
422
|
+
if (state.selectedWaypoint === null || locked) {
|
|
423
|
+
break;
|
|
424
|
+
}
|
|
425
|
+
event.preventDefault();
|
|
426
|
+
actions.nudgeWaypoint(line, state.selectedWaypoint, event.key === "ArrowLeft" ? -step : event.key === "ArrowRight" ? step : 0, event.key === "ArrowUp" ? -step : event.key === "ArrowDown" ? step : 0);
|
|
427
|
+
break;
|
|
428
|
+
default:
|
|
429
|
+
break;
|
|
430
|
+
}
|
|
431
|
+
};
|
|
432
|
+
document.addEventListener("keydown", handleKeyDown);
|
|
433
|
+
return () => document.removeEventListener("keydown", handleKeyDown);
|
|
434
|
+
}, [selectedLine, locks, snapStep, setSelectedId]);
|
|
435
|
+
const handleDrawStart = event => {
|
|
436
|
+
if (event.button !== 0) {
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
const from = snapWithGuides(canvasPoint(event.clientX, event.clientY), []);
|
|
440
|
+
setGuides(null);
|
|
441
|
+
setDraft({
|
|
442
|
+
from,
|
|
443
|
+
to: from
|
|
444
|
+
});
|
|
445
|
+
const handleMove = move => {
|
|
446
|
+
const point = canvasPoint(move.clientX, move.clientY);
|
|
447
|
+
setDraft({
|
|
448
|
+
from,
|
|
449
|
+
to: move.shiftKey ? constrainAngle(from, point) : {
|
|
450
|
+
x: snapValue(point.x, snapStep),
|
|
451
|
+
y: snapValue(point.y, snapStep)
|
|
452
|
+
}
|
|
453
|
+
});
|
|
454
|
+
};
|
|
455
|
+
const handleUp = up => {
|
|
456
|
+
window.removeEventListener("mousemove", handleMove);
|
|
457
|
+
window.removeEventListener("mouseup", handleUp);
|
|
458
|
+
const point = canvasPoint(up.clientX, up.clientY);
|
|
459
|
+
const to = up.shiftKey ? constrainAngle(from, point) : {
|
|
460
|
+
x: snapValue(point.x, snapStep),
|
|
461
|
+
y: snapValue(point.y, snapStep)
|
|
462
|
+
};
|
|
463
|
+
const end = Math.hypot(to.x - from.x, to.y - from.y) < 8 ? {
|
|
464
|
+
x: from.x + LINE_DEFAULT_LENGTH,
|
|
465
|
+
y: from.y
|
|
466
|
+
} : to;
|
|
467
|
+
counterRef.current += 1;
|
|
468
|
+
const id = "line-created-" + counterRef.current;
|
|
469
|
+
setDraft(null);
|
|
470
|
+
setLines(current => [...current, {
|
|
471
|
+
id,
|
|
472
|
+
kind: "line",
|
|
473
|
+
name: null,
|
|
474
|
+
type: "line",
|
|
475
|
+
start: from,
|
|
476
|
+
end,
|
|
477
|
+
waypoints: {
|
|
478
|
+
curved: [],
|
|
479
|
+
elbow: []
|
|
480
|
+
},
|
|
481
|
+
style: DEFAULT_LINE_STYLE,
|
|
482
|
+
label: null
|
|
483
|
+
}]);
|
|
484
|
+
setSelectedId(id);
|
|
485
|
+
window.setTimeout(onToolUsed, 0);
|
|
486
|
+
};
|
|
487
|
+
event.preventDefault();
|
|
488
|
+
window.addEventListener("mousemove", handleMove);
|
|
489
|
+
window.addEventListener("mouseup", handleUp);
|
|
490
|
+
};
|
|
491
|
+
const renderLine = line => {
|
|
492
|
+
var _locks$line$id2;
|
|
493
|
+
const _resolveEndpoints4 = resolveEndpoints(line, boxOf),
|
|
494
|
+
start = _resolveEndpoints4.start,
|
|
495
|
+
end = _resolveEndpoints4.end;
|
|
496
|
+
const geometry = lineGeometry(line, start, end);
|
|
497
|
+
const selected = line.id === selectedId;
|
|
498
|
+
const locked = (_locks$line$id2 = locks[line.id]) != null ? _locks$line$id2 : false;
|
|
499
|
+
const color = withOpacity(resolveBoardColor(line.style.stroke, "stroke"), line.style.stroke_opacity);
|
|
500
|
+
const dash = dashArray(line.style.stroke_pattern, line.style.stroke_width);
|
|
501
|
+
const handleHitDown = event => {
|
|
502
|
+
if (event.button !== 0) {
|
|
503
|
+
return;
|
|
504
|
+
}
|
|
505
|
+
setSelectedId(line.id);
|
|
506
|
+
setWaypointSelection(null);
|
|
507
|
+
setLabelFor(null);
|
|
508
|
+
if (line.kind === "connector" || locked) {
|
|
509
|
+
event.stopPropagation();
|
|
510
|
+
return;
|
|
511
|
+
}
|
|
512
|
+
const origin = canvasPoint(event.clientX, event.clientY);
|
|
513
|
+
const snapshot = line;
|
|
514
|
+
beginDrag(event, point => {
|
|
515
|
+
const dx = snapValue(point.x - origin.x, snapStep);
|
|
516
|
+
const dy = snapValue(point.y - origin.y, snapStep);
|
|
517
|
+
updateLine(line.id, () => _extends({}, snapshot, {
|
|
518
|
+
start: offset(snapshot.start, dx, dy),
|
|
519
|
+
end: offset(snapshot.end, dx, dy),
|
|
520
|
+
waypoints: {
|
|
521
|
+
curved: snapshot.waypoints.curved.map(p => offset(p, dx, dy)),
|
|
522
|
+
elbow: snapshot.waypoints.elbow.map(p => offset(p, dx, dy))
|
|
523
|
+
}
|
|
524
|
+
}));
|
|
525
|
+
});
|
|
526
|
+
};
|
|
527
|
+
const handleHitDoubleClick = event => {
|
|
528
|
+
event.stopPropagation();
|
|
529
|
+
if (locked) {
|
|
530
|
+
return;
|
|
531
|
+
}
|
|
532
|
+
const point = canvasPoint(event.clientX, event.clientY);
|
|
533
|
+
if (line.type === "line") {
|
|
534
|
+
var _line$label$position2, _line$label2;
|
|
535
|
+
startLabelEdit(line, (_line$label$position2 = (_line$label2 = line.label) == null ? void 0 : _line$label2.position) != null ? _line$label$position2 : projectOnSamples(geometry.samples, geometry.sampleSegments, point).fraction);
|
|
536
|
+
} else {
|
|
537
|
+
insertWaypoint(line, geometry, point);
|
|
538
|
+
}
|
|
539
|
+
};
|
|
540
|
+
return /*#__PURE__*/React.createElement("g", {
|
|
541
|
+
key: line.id,
|
|
542
|
+
className: selected ? "wb-line is-selected" : "wb-line"
|
|
543
|
+
}, /*#__PURE__*/React.createElement("path", {
|
|
544
|
+
className: "wb-line-halo",
|
|
545
|
+
d: geometry.d,
|
|
546
|
+
fill: "none",
|
|
547
|
+
strokeWidth: line.style.stroke_width + 6,
|
|
548
|
+
strokeLinecap: "round",
|
|
549
|
+
strokeLinejoin: "round",
|
|
550
|
+
style: {
|
|
551
|
+
stroke: SELECTION_BLUE
|
|
552
|
+
}
|
|
553
|
+
}), /*#__PURE__*/React.createElement("path", {
|
|
554
|
+
d: geometry.d,
|
|
555
|
+
fill: "none",
|
|
556
|
+
strokeWidth: line.style.stroke_width,
|
|
557
|
+
strokeDasharray: dash,
|
|
558
|
+
strokeLinecap: dash ? "butt" : "round",
|
|
559
|
+
strokeLinejoin: "round",
|
|
560
|
+
style: {
|
|
561
|
+
stroke: color
|
|
562
|
+
}
|
|
563
|
+
}), lineEndGlyph(line.style.arrow_start, start, geometry.startAngle, line.style.stroke_width, color), lineEndGlyph(line.style.arrow_end, end, geometry.endAngle, line.style.stroke_width, color), /*#__PURE__*/React.createElement("path", {
|
|
564
|
+
className: "wb-line-hit",
|
|
565
|
+
d: geometry.d,
|
|
566
|
+
fill: "none",
|
|
567
|
+
stroke: "transparent",
|
|
568
|
+
strokeWidth: LINE_HIT_WIDTH,
|
|
569
|
+
onMouseDown: handleHitDown,
|
|
570
|
+
onClick: event => event.stopPropagation(),
|
|
571
|
+
onDoubleClick: handleHitDoubleClick
|
|
572
|
+
}));
|
|
573
|
+
};
|
|
574
|
+
const renderHandles = line => {
|
|
575
|
+
var _locks$line$id3;
|
|
576
|
+
const _resolveEndpoints5 = resolveEndpoints(line, boxOf),
|
|
577
|
+
start = _resolveEndpoints5.start,
|
|
578
|
+
end = _resolveEndpoints5.end;
|
|
579
|
+
const geometry = lineGeometry(line, start, end);
|
|
580
|
+
const locked = (_locks$line$id3 = locks[line.id]) != null ? _locks$line$id3 : false;
|
|
581
|
+
const anchored = line.kind === "connector";
|
|
582
|
+
const others = except => lines.flatMap(entry => pointsOf(entry)).filter(point => point !== except);
|
|
583
|
+
const dragEnd = side => event => {
|
|
584
|
+
setWaypointSelection(null);
|
|
585
|
+
if (anchored || locked) {
|
|
586
|
+
event.stopPropagation();
|
|
587
|
+
return;
|
|
588
|
+
}
|
|
589
|
+
const fixed = side === "start" ? line.end : line.start;
|
|
590
|
+
const moving = side === "start" ? line.start : line.end;
|
|
591
|
+
beginDrag(event, (point, move) => {
|
|
592
|
+
const next = move.shiftKey ? constrainAngle(fixed, point) : snapWithGuides(point, others(moving));
|
|
593
|
+
updateLine(line.id, current => _extends({}, current, {
|
|
594
|
+
[side]: next
|
|
595
|
+
}));
|
|
596
|
+
});
|
|
597
|
+
};
|
|
598
|
+
const dragWaypoint = index => event => {
|
|
599
|
+
setWaypointSelection({
|
|
600
|
+
lineId: line.id,
|
|
601
|
+
index
|
|
602
|
+
});
|
|
603
|
+
setLabelFor(null);
|
|
604
|
+
if (locked) {
|
|
605
|
+
event.stopPropagation();
|
|
606
|
+
return;
|
|
607
|
+
}
|
|
608
|
+
const list = line.type === "elbow" ? line.waypoints.elbow : line.waypoints.curved;
|
|
609
|
+
const vertical = line.type === "elbow" && barIsVertical(index, elbowAxis(start, end, line.start_anchor));
|
|
610
|
+
beginDrag(event, point => {
|
|
611
|
+
const snapped = snapWithGuides(point, others(list[index]));
|
|
612
|
+
updateLine(line.id, current => {
|
|
613
|
+
if (current.type === "elbow") {
|
|
614
|
+
return _extends({}, current, {
|
|
615
|
+
waypoints: _extends({}, current.waypoints, {
|
|
616
|
+
elbow: current.waypoints.elbow.map((bar, at) => at === index ? vertical ? _extends({}, bar, {
|
|
617
|
+
x: snapped.x
|
|
618
|
+
}) : _extends({}, bar, {
|
|
619
|
+
y: snapped.y
|
|
620
|
+
}) : bar)
|
|
621
|
+
})
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
return _extends({}, current, {
|
|
625
|
+
waypoints: _extends({}, current.waypoints, {
|
|
626
|
+
curved: current.waypoints.curved.map((waypoint, at) => at === index ? snapped : waypoint)
|
|
627
|
+
})
|
|
628
|
+
});
|
|
629
|
+
});
|
|
630
|
+
});
|
|
631
|
+
};
|
|
632
|
+
const axis = elbowAxis(start, end, line.start_anchor);
|
|
633
|
+
const bars = line.type === "elbow" ? line.waypoints.elbow : [];
|
|
634
|
+
const route = line.type === "elbow" && bars.length ? elbowRoute(start, end, bars, axis) : geometry.route;
|
|
635
|
+
return /*#__PURE__*/React.createElement("g", null, line.type === "curved" ? line.waypoints.curved.map((waypoint, index) => /*#__PURE__*/React.createElement("circle", {
|
|
636
|
+
key: "waypoint-" + index,
|
|
637
|
+
className: selectedWaypoint === index ? "wb-handle is-active" : "wb-handle",
|
|
638
|
+
cx: waypoint.x,
|
|
639
|
+
cy: waypoint.y,
|
|
640
|
+
r: selectedWaypoint === index ? 6 : 5,
|
|
641
|
+
onMouseDown: dragWaypoint(index),
|
|
642
|
+
onClick: event => event.stopPropagation()
|
|
643
|
+
})) : null, bars.map((_, index) => {
|
|
644
|
+
const from = route[index + 1];
|
|
645
|
+
const to = route[index + 2];
|
|
646
|
+
const vertical = barIsVertical(index, axis);
|
|
647
|
+
const active = selectedWaypoint === index;
|
|
648
|
+
return /*#__PURE__*/React.createElement("rect", {
|
|
649
|
+
key: "segment-" + index,
|
|
650
|
+
className: ["wb-handle", vertical ? "is-ew" : "is-ns", active ? "is-active" : ""].filter(Boolean).join(" "),
|
|
651
|
+
x: (from.x + to.x) / 2 - (vertical ? 3 : 8),
|
|
652
|
+
y: (from.y + to.y) / 2 - (vertical ? 8 : 3),
|
|
653
|
+
width: vertical ? 6 : 16,
|
|
654
|
+
height: vertical ? 16 : 6,
|
|
655
|
+
rx: 3,
|
|
656
|
+
onMouseDown: dragWaypoint(index),
|
|
657
|
+
onClick: event => event.stopPropagation()
|
|
658
|
+
});
|
|
659
|
+
}), [{
|
|
660
|
+
side: "start",
|
|
661
|
+
at: start
|
|
662
|
+
}, {
|
|
663
|
+
side: "end",
|
|
664
|
+
at: end
|
|
665
|
+
}].map(_ref2 => {
|
|
666
|
+
let side = _ref2.side,
|
|
667
|
+
at = _ref2.at;
|
|
668
|
+
return /*#__PURE__*/React.createElement("circle", {
|
|
669
|
+
key: side,
|
|
670
|
+
className: anchored ? "wb-handle is-anchored" : "wb-handle",
|
|
671
|
+
cx: at.x,
|
|
672
|
+
cy: at.y,
|
|
673
|
+
r: anchored ? 4 : 5,
|
|
674
|
+
onMouseDown: dragEnd(side),
|
|
675
|
+
onClick: event => event.stopPropagation()
|
|
676
|
+
});
|
|
677
|
+
}));
|
|
678
|
+
};
|
|
679
|
+
const renderLabel = line => {
|
|
680
|
+
if (!line.label) {
|
|
681
|
+
return null;
|
|
682
|
+
}
|
|
683
|
+
const _resolveEndpoints6 = resolveEndpoints(line, boxOf),
|
|
684
|
+
start = _resolveEndpoints6.start,
|
|
685
|
+
end = _resolveEndpoints6.end;
|
|
686
|
+
const geometry = lineGeometry(line, start, end);
|
|
687
|
+
const at = pointAtFraction(geometry.samples, line.label.position);
|
|
688
|
+
const selected = labelSelected && line.id === selectedId;
|
|
689
|
+
const isEditing = editing && line.id === selectedId;
|
|
690
|
+
const label = line.label;
|
|
691
|
+
const handleLabelDown = event => {
|
|
692
|
+
if (event.button !== 0 || isEditing) {
|
|
693
|
+
event.stopPropagation();
|
|
694
|
+
return;
|
|
695
|
+
}
|
|
696
|
+
setSelectedId(line.id);
|
|
697
|
+
setWaypointSelection(null);
|
|
698
|
+
setLabelFor(line.id);
|
|
699
|
+
if (locks[line.id]) {
|
|
700
|
+
event.stopPropagation();
|
|
701
|
+
return;
|
|
702
|
+
}
|
|
703
|
+
beginDrag(event, point => {
|
|
704
|
+
const fraction = projectOnSamples(geometry.samples, geometry.sampleSegments, point).fraction;
|
|
705
|
+
updateLabel(line.id, {
|
|
706
|
+
position: Math.min(0.95, Math.max(0.05, fraction))
|
|
707
|
+
});
|
|
708
|
+
});
|
|
709
|
+
};
|
|
710
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
711
|
+
key: "label-" + line.id,
|
|
712
|
+
className: selected ? "wb-line-label is-selected" : "wb-line-label",
|
|
713
|
+
style: {
|
|
714
|
+
left: at.x,
|
|
715
|
+
top: at.y,
|
|
716
|
+
color: resolveBoardColor(line.style.stroke, "text"),
|
|
717
|
+
fontSize: label.font_size,
|
|
718
|
+
fontWeight: label.bold ? 700 : 400,
|
|
719
|
+
fontStyle: label.italic ? "italic" : "normal"
|
|
720
|
+
},
|
|
721
|
+
onMouseDown: handleLabelDown,
|
|
722
|
+
onClick: event => event.stopPropagation(),
|
|
723
|
+
onDoubleClick: event => {
|
|
724
|
+
event.stopPropagation();
|
|
725
|
+
startLabelEdit(line);
|
|
726
|
+
}
|
|
727
|
+
}, isEditing ? /*#__PURE__*/React.createElement(EditableText, {
|
|
728
|
+
wrap: true,
|
|
729
|
+
allowEmptyString: true,
|
|
730
|
+
value: label.text,
|
|
731
|
+
inputProps: {
|
|
732
|
+
autoFocus: true,
|
|
733
|
+
placeholder: "Label"
|
|
734
|
+
},
|
|
735
|
+
onSave: event => {
|
|
736
|
+
const text = event.target.value.trim();
|
|
737
|
+
if (text) {
|
|
738
|
+
updateLabel(line.id, {
|
|
739
|
+
text
|
|
740
|
+
});
|
|
741
|
+
setEditingFor(null);
|
|
742
|
+
} else {
|
|
743
|
+
removeLabel(line.id);
|
|
744
|
+
}
|
|
745
|
+
},
|
|
746
|
+
onCancel: () => {
|
|
747
|
+
if (label.text) {
|
|
748
|
+
setEditingFor(null);
|
|
749
|
+
} else {
|
|
750
|
+
removeLabel(line.id);
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
}) :
|
|
754
|
+
/*#__PURE__*/
|
|
755
|
+
// ds-exception: the label's font size is its own text style, picked in its toolbar
|
|
756
|
+
React.createElement(Body2, {
|
|
757
|
+
weight: label.bold ? "bold" : "regular",
|
|
758
|
+
italic: label.italic,
|
|
759
|
+
style: {
|
|
760
|
+
fontSize: label.font_size,
|
|
761
|
+
color: "inherit",
|
|
762
|
+
textDecoration: [label.underline ? "underline" : "", label.strikethrough ? "line-through" : ""].filter(Boolean).join(" ") || undefined
|
|
763
|
+
}
|
|
764
|
+
}, label.text));
|
|
765
|
+
};
|
|
766
|
+
const renderToolbar = () => {
|
|
767
|
+
var _locks$selectedLine$i;
|
|
768
|
+
if (!selectedLine || draft) {
|
|
769
|
+
return null;
|
|
770
|
+
}
|
|
771
|
+
const _resolveEndpoints7 = resolveEndpoints(selectedLine, boxOf),
|
|
772
|
+
start = _resolveEndpoints7.start,
|
|
773
|
+
end = _resolveEndpoints7.end;
|
|
774
|
+
const geometry = lineGeometry(selectedLine, start, end);
|
|
775
|
+
const xs = geometry.samples.map(point => point.x);
|
|
776
|
+
const ys = geometry.samples.map(point => point.y);
|
|
777
|
+
const left = (Math.min(...xs) + Math.max(...xs)) / 2;
|
|
778
|
+
const top = Math.min(...ys) - 12;
|
|
779
|
+
if (labelSelected && selectedLine.label) {
|
|
780
|
+
const at = pointAtFraction(geometry.samples, selectedLine.label.position);
|
|
781
|
+
return /*#__PURE__*/React.createElement(LineLabelToolbar, {
|
|
782
|
+
left: at.x,
|
|
783
|
+
top: at.y - selectedLine.label.font_size,
|
|
784
|
+
label: selectedLine.label,
|
|
785
|
+
onChange: partial => updateLabel(selectedLine.id, partial),
|
|
786
|
+
onRemove: () => removeLabel(selectedLine.id)
|
|
787
|
+
});
|
|
788
|
+
}
|
|
789
|
+
return /*#__PURE__*/React.createElement(LineFormattingToolbar, {
|
|
790
|
+
left: left,
|
|
791
|
+
top: top,
|
|
792
|
+
line: selectedLine,
|
|
793
|
+
locked: (_locks$selectedLine$i = locks[selectedLine.id]) != null ? _locks$selectedLine$i : false,
|
|
794
|
+
onToggleLock: () => onToggleLock(selectedLine.id),
|
|
795
|
+
onDelete: () => deleteLine(selectedLine.id),
|
|
796
|
+
onLabel: () => {
|
|
797
|
+
var _selectedLine$label$p, _selectedLine$label;
|
|
798
|
+
return startLabelEdit(selectedLine, (_selectedLine$label$p = (_selectedLine$label = selectedLine.label) == null ? void 0 : _selectedLine$label.position) != null ? _selectedLine$label$p : 0.5);
|
|
799
|
+
},
|
|
800
|
+
onTypeChange: type => {
|
|
801
|
+
setWaypointSelection(null);
|
|
802
|
+
updateLine(selectedLine.id, current => withLineType(current, type, start, end));
|
|
803
|
+
},
|
|
804
|
+
onStyleChange: partial => updateLine(selectedLine.id, current => _extends({}, current, {
|
|
805
|
+
style: _extends({}, current.style, partial)
|
|
806
|
+
})),
|
|
807
|
+
onAnchorChange: (side, anchor) => updateLine(selectedLine.id, current => _extends({}, current, {
|
|
808
|
+
[side === "start" ? "start_anchor" : "end_anchor"]: anchor
|
|
809
|
+
}))
|
|
810
|
+
});
|
|
811
|
+
};
|
|
812
|
+
const ordered = selectedLine ? [...lines.filter(line => line.id !== selectedId), selectedLine] : lines;
|
|
813
|
+
return /*#__PURE__*/React.createElement(StyledLineLayer, {
|
|
814
|
+
ref: layerRef
|
|
815
|
+
}, armed ? /*#__PURE__*/React.createElement("div", {
|
|
816
|
+
className: "wb-draw-surface",
|
|
817
|
+
onMouseDown: handleDrawStart,
|
|
818
|
+
onClick: event => event.stopPropagation()
|
|
819
|
+
}) : null, /*#__PURE__*/React.createElement("svg", {
|
|
820
|
+
className: "wb-lines"
|
|
821
|
+
}, ordered.map(renderLine), selectedLine && !draft ? renderHandles(selectedLine) : null, draft ? /*#__PURE__*/React.createElement("path", {
|
|
822
|
+
d: "M " + draft.from.x + " " + draft.from.y + " L " + draft.to.x + " " + draft.to.y,
|
|
823
|
+
strokeWidth: DEFAULT_LINE_STYLE.stroke_width,
|
|
824
|
+
strokeLinecap: "round",
|
|
825
|
+
style: {
|
|
826
|
+
stroke: resolveBoardColor("default", "stroke"),
|
|
827
|
+
opacity: 0.6
|
|
828
|
+
}
|
|
829
|
+
}) : null, (guides == null ? void 0 : guides.x) !== undefined ? /*#__PURE__*/React.createElement("line", {
|
|
830
|
+
x1: guides.x,
|
|
831
|
+
x2: guides.x,
|
|
832
|
+
y1: -10000,
|
|
833
|
+
y2: 10000,
|
|
834
|
+
strokeWidth: 1,
|
|
835
|
+
style: {
|
|
836
|
+
stroke: GUIDE_COLOR
|
|
837
|
+
}
|
|
838
|
+
}) : null, (guides == null ? void 0 : guides.y) !== undefined ? /*#__PURE__*/React.createElement("line", {
|
|
839
|
+
x1: -10000,
|
|
840
|
+
x2: 10000,
|
|
841
|
+
y1: guides.y,
|
|
842
|
+
y2: guides.y,
|
|
843
|
+
strokeWidth: 1,
|
|
844
|
+
style: {
|
|
845
|
+
stroke: GUIDE_COLOR
|
|
846
|
+
}
|
|
847
|
+
}) : null), ordered.map(renderLabel), /*#__PURE__*/React.createElement("div", {
|
|
848
|
+
className: "wb-toolbar-host"
|
|
849
|
+
}, renderToolbar()));
|
|
850
|
+
};
|
|
851
|
+
//# sourceMappingURL=lineElements.js.map
|