@activecollab/components 2.0.591 → 2.0.593
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/BatchEdit/BatchEdit.js +164 -23
- package/dist/cjs/components/BatchEdit/BatchEdit.js.map +1 -1
- package/dist/cjs/components/BatchEdit/BatchProperties.js +19 -3
- package/dist/cjs/components/BatchEdit/BatchProperties.js.map +1 -1
- package/dist/cjs/components/BatchEdit/Styles.js +67 -1
- package/dist/cjs/components/BatchEdit/Styles.js.map +1 -1
- package/dist/cjs/components/PillButton/PillButton.js.map +1 -1
- package/dist/cjs/components/PillButton/Styles.js +1 -1
- package/dist/cjs/components/PillButton/Styles.js.map +1 -1
- package/dist/cjs/components/Popper/Popper.js +20 -2
- package/dist/cjs/components/Popper/Popper.js.map +1 -1
- package/dist/cjs/presentation/__tests__/WhiteboardElbow.test.js +55 -0
- package/dist/cjs/presentation/__tests__/WhiteboardElbow.test.js.map +1 -0
- package/dist/cjs/presentation/whiteboard/elementToolbars.js +18 -18
- package/dist/cjs/presentation/whiteboard/elementToolbars.js.map +1 -1
- package/dist/cjs/presentation/whiteboard/lineElements.js +182 -224
- package/dist/cjs/presentation/whiteboard/lineElements.js.map +1 -1
- package/dist/cjs/presentation/whiteboard/lineInspector.js +1 -1
- package/dist/cjs/presentation/whiteboard/lineInspector.js.map +1 -1
- package/dist/cjs/presentation/whiteboard/lineModel.js +322 -84
- package/dist/cjs/presentation/whiteboard/lineModel.js.map +1 -1
- package/dist/esm/components/BatchEdit/BatchEdit.d.ts +33 -2
- package/dist/esm/components/BatchEdit/BatchEdit.d.ts.map +1 -1
- package/dist/esm/components/BatchEdit/BatchEdit.js +149 -24
- package/dist/esm/components/BatchEdit/BatchEdit.js.map +1 -1
- package/dist/esm/components/BatchEdit/BatchProperties.d.ts +7 -1
- package/dist/esm/components/BatchEdit/BatchProperties.d.ts.map +1 -1
- package/dist/esm/components/BatchEdit/BatchProperties.js +20 -4
- package/dist/esm/components/BatchEdit/BatchProperties.js.map +1 -1
- package/dist/esm/components/BatchEdit/Styles.d.ts +18 -0
- package/dist/esm/components/BatchEdit/Styles.d.ts.map +1 -1
- package/dist/esm/components/BatchEdit/Styles.js +66 -0
- package/dist/esm/components/BatchEdit/Styles.js.map +1 -1
- package/dist/esm/components/PillButton/PillButton.d.ts +1 -1
- package/dist/esm/components/PillButton/PillButton.d.ts.map +1 -1
- package/dist/esm/components/PillButton/PillButton.js.map +1 -1
- package/dist/esm/components/PillButton/Styles.d.ts.map +1 -1
- package/dist/esm/components/PillButton/Styles.js +1 -1
- package/dist/esm/components/PillButton/Styles.js.map +1 -1
- package/dist/esm/components/Popper/Popper.d.ts.map +1 -1
- package/dist/esm/components/Popper/Popper.js +18 -2
- package/dist/esm/components/Popper/Popper.js.map +1 -1
- package/dist/esm/presentation/__tests__/WhiteboardElbow.test.d.ts +2 -0
- package/dist/esm/presentation/__tests__/WhiteboardElbow.test.d.ts.map +1 -0
- package/dist/esm/presentation/__tests__/WhiteboardElbow.test.js +46 -0
- package/dist/esm/presentation/__tests__/WhiteboardElbow.test.js.map +1 -0
- package/dist/esm/presentation/whiteboard/elementToolbars.d.ts.map +1 -1
- package/dist/esm/presentation/whiteboard/elementToolbars.js +8 -8
- package/dist/esm/presentation/whiteboard/elementToolbars.js.map +1 -1
- package/dist/esm/presentation/whiteboard/lineElements.d.ts +7 -4
- package/dist/esm/presentation/whiteboard/lineElements.d.ts.map +1 -1
- package/dist/esm/presentation/whiteboard/lineElements.js +155 -190
- package/dist/esm/presentation/whiteboard/lineElements.js.map +1 -1
- package/dist/esm/presentation/whiteboard/lineInspector.d.ts.map +1 -1
- package/dist/esm/presentation/whiteboard/lineInspector.js +1 -1
- package/dist/esm/presentation/whiteboard/lineInspector.js.map +1 -1
- package/dist/esm/presentation/whiteboard/lineModel.d.ts +29 -11
- package/dist/esm/presentation/whiteboard/lineModel.d.ts.map +1 -1
- package/dist/esm/presentation/whiteboard/lineModel.js +290 -82
- package/dist/esm/presentation/whiteboard/lineModel.js.map +1 -1
- package/dist/index.js +485 -255
- 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
|
@@ -5,9 +5,7 @@ import React from "react";
|
|
|
5
5
|
|
|
6
6
|
// mirrors: no payload yet
|
|
7
7
|
|
|
8
|
-
// mirrors: no payload yet
|
|
9
|
-
|
|
10
|
-
// mirrors: new-activecollab-front Whiteboards connectionShape (type, start_element_id, end_element_id, start_anchor, end_anchor, style); line fields, waypoints and label: no payload yet
|
|
8
|
+
// mirrors: new-activecollab-front Whiteboards connectionShape (type, start_element_id, end_element_id, start_anchor, end_anchor, style); waypoints: AC task 481540 (one list for Curved and Elbow, elbow waypoints are the corners, at most 20; board coordinates in this mock); label: no payload yet
|
|
11
9
|
|
|
12
10
|
export const MAX_WAYPOINTS = 20;
|
|
13
11
|
export const LINE_HIT_WIDTH = 10;
|
|
@@ -102,6 +100,7 @@ export const DEFAULT_LABEL = {
|
|
|
102
100
|
strikethrough: false
|
|
103
101
|
};
|
|
104
102
|
export const dashArray = (pattern, width) => pattern === "dashed" ? width * 4 + " " + width * 3 : pattern === "dotted" ? width + " " + width * 2 : undefined;
|
|
103
|
+
const EPSILON = 0.0001;
|
|
105
104
|
const distance = (a, b) => Math.hypot(b.x - a.x, b.y - a.y);
|
|
106
105
|
const towards = (from, to, length) => {
|
|
107
106
|
const total = distance(from, to) || 1;
|
|
@@ -114,7 +113,19 @@ const midpoint = (a, b) => ({
|
|
|
114
113
|
x: (a.x + b.x) / 2,
|
|
115
114
|
y: (a.y + b.y) / 2
|
|
116
115
|
});
|
|
116
|
+
const samePoint = (a, b) => Math.abs(a.x - b.x) < EPSILON && Math.abs(a.y - b.y) < EPSILON;
|
|
117
117
|
const dedupe = points => points.filter((point, index) => index === 0 || distance(points[index - 1], point) > 0.5);
|
|
118
|
+
const projectOnSegment = (a, b, point) => {
|
|
119
|
+
const length = distance(a, b);
|
|
120
|
+
if (!length) {
|
|
121
|
+
return a;
|
|
122
|
+
}
|
|
123
|
+
const t = Math.max(0, Math.min(1, ((point.x - a.x) * (b.x - a.x) + (point.y - a.y) * (b.y - a.y)) / (length * length)));
|
|
124
|
+
return {
|
|
125
|
+
x: a.x + (b.x - a.x) * t,
|
|
126
|
+
y: a.y + (b.y - a.y) * t
|
|
127
|
+
};
|
|
128
|
+
};
|
|
118
129
|
export const anchorPoint = (box, anchor, toward) => {
|
|
119
130
|
const cx = box.x + box.width / 2;
|
|
120
131
|
const cy = box.y + box.height / 2;
|
|
@@ -178,6 +189,7 @@ export const anchorPoint = (box, anchor, toward) => {
|
|
|
178
189
|
}
|
|
179
190
|
}
|
|
180
191
|
};
|
|
192
|
+
const flip = axis => axis === "h" ? "v" : "h";
|
|
181
193
|
export const elbowAxis = (start, end, anchor) => {
|
|
182
194
|
if (anchor === "left" || anchor === "right") {
|
|
183
195
|
return "h";
|
|
@@ -187,30 +199,193 @@ export const elbowAxis = (start, end, anchor) => {
|
|
|
187
199
|
}
|
|
188
200
|
return Math.abs(end.x - start.x) >= Math.abs(end.y - start.y) ? "h" : "v";
|
|
189
201
|
};
|
|
190
|
-
export const
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
202
|
+
export const elbowFirstAxis = (start, corners, anchor) => {
|
|
203
|
+
var _corners$;
|
|
204
|
+
if (anchor === "left" || anchor === "right") {
|
|
205
|
+
return "h";
|
|
206
|
+
}
|
|
207
|
+
if (anchor === "top" || anchor === "bottom") {
|
|
208
|
+
return "v";
|
|
209
|
+
}
|
|
210
|
+
for (let segment = 1; segment < corners.length; segment += 1) {
|
|
211
|
+
const from = corners[segment - 1];
|
|
212
|
+
const to = corners[segment];
|
|
213
|
+
if (!samePoint(from, to)) {
|
|
214
|
+
const sameY = Math.abs(from.y - to.y) < EPSILON;
|
|
215
|
+
const sameX = Math.abs(from.x - to.x) < EPSILON;
|
|
216
|
+
if (sameY || sameX) {
|
|
217
|
+
const axis = sameY ? "h" : "v";
|
|
218
|
+
return segment % 2 === 0 ? axis : flip(axis);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return elbowAxis(start, (_corners$ = corners[0]) != null ? _corners$ : start);
|
|
223
|
+
};
|
|
224
|
+
export const segmentAxis = (first, segment) => segment % 2 === 0 ? first : flip(first);
|
|
225
|
+
export const applyElbowRule = (start, end, corners, anchor) => {
|
|
226
|
+
if (!corners.length) {
|
|
227
|
+
return [];
|
|
228
|
+
}
|
|
229
|
+
let axis = elbowFirstAxis(start, corners, anchor);
|
|
230
|
+
let previous = start;
|
|
231
|
+
const aligned = corners.map(corner => {
|
|
232
|
+
const next = axis === "h" ? {
|
|
233
|
+
x: corner.x,
|
|
234
|
+
y: previous.y
|
|
199
235
|
} : {
|
|
200
|
-
x:
|
|
201
|
-
y:
|
|
236
|
+
x: previous.x,
|
|
237
|
+
y: corner.y
|
|
202
238
|
};
|
|
203
|
-
|
|
239
|
+
previous = next;
|
|
240
|
+
axis = flip(axis);
|
|
241
|
+
return next;
|
|
204
242
|
});
|
|
205
|
-
|
|
206
|
-
|
|
243
|
+
const last = aligned.length - 1;
|
|
244
|
+
aligned[last] = axis === "h" ? {
|
|
245
|
+
x: aligned[last].x,
|
|
207
246
|
y: end.y
|
|
208
247
|
} : {
|
|
209
248
|
x: end.x,
|
|
210
|
-
y:
|
|
249
|
+
y: aligned[last].y
|
|
250
|
+
};
|
|
251
|
+
return aligned;
|
|
252
|
+
};
|
|
253
|
+
export const simplifyPath = points => {
|
|
254
|
+
const unique = points.reduce((kept, point) => kept.length && samePoint(kept[kept.length - 1], point) ? kept : [...kept, point], []);
|
|
255
|
+
return unique.filter((point, index) => {
|
|
256
|
+
if (index === 0 || index === unique.length - 1) {
|
|
257
|
+
return true;
|
|
258
|
+
}
|
|
259
|
+
const before = unique[index - 1];
|
|
260
|
+
const after = unique[index + 1];
|
|
261
|
+
const cross = (point.x - before.x) * (after.y - point.y) - (point.y - before.y) * (after.x - point.x);
|
|
262
|
+
const dot = (point.x - before.x) * (after.x - point.x) + (point.y - before.y) * (after.y - point.y);
|
|
263
|
+
return Math.abs(cross) > EPSILON || dot < 0;
|
|
211
264
|
});
|
|
212
|
-
|
|
213
|
-
|
|
265
|
+
};
|
|
266
|
+
export const autoElbowRoute = (start, end, anchor) => {
|
|
267
|
+
const middle = midpoint(start, end);
|
|
268
|
+
return simplifyPath(elbowAxis(start, end, anchor) === "h" ? [start, {
|
|
269
|
+
x: middle.x,
|
|
270
|
+
y: start.y
|
|
271
|
+
}, {
|
|
272
|
+
x: middle.x,
|
|
273
|
+
y: end.y
|
|
274
|
+
}, end] : [start, {
|
|
275
|
+
x: start.x,
|
|
276
|
+
y: middle.y
|
|
277
|
+
}, {
|
|
278
|
+
x: end.x,
|
|
279
|
+
y: middle.y
|
|
280
|
+
}, end]);
|
|
281
|
+
};
|
|
282
|
+
export const elbowCorners = (line, start, end) => line.waypoints.length ? applyElbowRule(start, end, line.waypoints, line.start_anchor) : autoElbowRoute(start, end, line.start_anchor).slice(1, -1);
|
|
283
|
+
export const elbowSegmentAxes = (frame, corners) => {
|
|
284
|
+
const first = elbowFirstAxis(frame.start, corners, frame.anchor);
|
|
285
|
+
return [...corners, frame.end].map((_, segment) => segmentAxis(first, segment));
|
|
286
|
+
};
|
|
287
|
+
const ruled = (frame, corners) => applyElbowRule(frame.start, frame.end, corners, frame.anchor);
|
|
288
|
+
export const addElbowStep = (frame, corners, point) => {
|
|
289
|
+
if (corners.length + 2 > MAX_WAYPOINTS) {
|
|
290
|
+
return null;
|
|
291
|
+
}
|
|
292
|
+
const path = [frame.start, ...corners, frame.end];
|
|
293
|
+
let best = 0;
|
|
294
|
+
let bestGap = Infinity;
|
|
295
|
+
let bestPoint = frame.start;
|
|
296
|
+
for (let segment = 0; segment < path.length - 1; segment += 1) {
|
|
297
|
+
const projected = projectOnSegment(path[segment], path[segment + 1], point);
|
|
298
|
+
const gap = distance(projected, point);
|
|
299
|
+
if (gap < bestGap) {
|
|
300
|
+
best = segment;
|
|
301
|
+
bestGap = gap;
|
|
302
|
+
bestPoint = projected;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
return {
|
|
306
|
+
corners: ruled(frame, [...corners.slice(0, best), bestPoint, bestPoint, ...corners.slice(best)]),
|
|
307
|
+
selected: best + 1
|
|
308
|
+
};
|
|
309
|
+
};
|
|
310
|
+
const takeAxis = (corner, axis, from) => axis === "h" ? {
|
|
311
|
+
x: corner.x,
|
|
312
|
+
y: from.y
|
|
313
|
+
} : {
|
|
314
|
+
x: from.x,
|
|
315
|
+
y: corner.y
|
|
316
|
+
};
|
|
317
|
+
export const dragElbowCorner = (frame, corners, index, point) => {
|
|
318
|
+
const axes = elbowSegmentAxes(frame, corners);
|
|
319
|
+
const last = corners.length - 1;
|
|
320
|
+
let moved = point;
|
|
321
|
+
if (index === 0) {
|
|
322
|
+
moved = axes[0] === "h" ? {
|
|
323
|
+
x: moved.x,
|
|
324
|
+
y: corners[0].y
|
|
325
|
+
} : {
|
|
326
|
+
x: corners[0].x,
|
|
327
|
+
y: moved.y
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
if (index === last) {
|
|
331
|
+
moved = axes[last + 1] === "h" ? {
|
|
332
|
+
x: moved.x,
|
|
333
|
+
y: corners[last].y
|
|
334
|
+
} : {
|
|
335
|
+
x: corners[last].x,
|
|
336
|
+
y: moved.y
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
return ruled(frame, corners.map((corner, at) => {
|
|
340
|
+
if (at === index) {
|
|
341
|
+
return moved;
|
|
342
|
+
}
|
|
343
|
+
if (at === index - 1) {
|
|
344
|
+
return takeAxis(corner, axes[index], moved);
|
|
345
|
+
}
|
|
346
|
+
if (at === index + 1) {
|
|
347
|
+
return takeAxis(corner, axes[index + 1], moved);
|
|
348
|
+
}
|
|
349
|
+
return corner;
|
|
350
|
+
}));
|
|
351
|
+
};
|
|
352
|
+
export const dragElbowSegment = (frame, corners, index, point) => {
|
|
353
|
+
const axis = elbowSegmentAxes(frame, corners)[index + 1];
|
|
354
|
+
return ruled(frame, corners.map((corner, at) => at === index || at === index + 1 ? axis === "v" ? {
|
|
355
|
+
x: point.x,
|
|
356
|
+
y: corner.y
|
|
357
|
+
} : {
|
|
358
|
+
x: corner.x,
|
|
359
|
+
y: point.y
|
|
360
|
+
} : corner));
|
|
361
|
+
};
|
|
362
|
+
export const removeElbowCorner = (frame, corners, index) => {
|
|
363
|
+
const partner = corners.length === 1 ? index : index === 0 ? 1 : index - 1;
|
|
364
|
+
const next = corners.filter((_, at) => at !== index && at !== partner);
|
|
365
|
+
return next.length ? ruled(frame, next) : [];
|
|
366
|
+
};
|
|
367
|
+
export const removeElbowSegment = (frame, corners, index) => {
|
|
368
|
+
const next = corners.filter((_, at) => at !== index && at !== index + 1);
|
|
369
|
+
return next.length ? ruled(frame, next) : [];
|
|
370
|
+
};
|
|
371
|
+
export const addCurvedWaypoint = (start, end, waypoints, point) => {
|
|
372
|
+
if (waypoints.length >= MAX_WAYPOINTS) {
|
|
373
|
+
return null;
|
|
374
|
+
}
|
|
375
|
+
const path = [start, ...waypoints, end];
|
|
376
|
+
let best = 0;
|
|
377
|
+
let bestDetour = Infinity;
|
|
378
|
+
for (let index = 0; index < path.length - 1; index += 1) {
|
|
379
|
+
const detour = distance(path[index], point) + distance(point, path[index + 1]) - distance(path[index], path[index + 1]);
|
|
380
|
+
if (detour < bestDetour) {
|
|
381
|
+
best = index;
|
|
382
|
+
bestDetour = detour;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
return {
|
|
386
|
+
waypoints: [...waypoints.slice(0, best), point, ...waypoints.slice(best)],
|
|
387
|
+
selected: best
|
|
388
|
+
};
|
|
214
389
|
};
|
|
215
390
|
export const roundedPolylinePath = (raw, radius) => {
|
|
216
391
|
const points = dedupe(raw);
|
|
@@ -234,24 +409,49 @@ export const roundedPolylinePath = (raw, radius) => {
|
|
|
234
409
|
const last = points[points.length - 1];
|
|
235
410
|
return d + " L " + last.x + " " + last.y;
|
|
236
411
|
};
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
c2: {
|
|
249
|
-
x: to.x - (after.x - from.x) / 6,
|
|
250
|
-
y: to.y - (after.y - from.y) / 6
|
|
251
|
-
},
|
|
252
|
-
to
|
|
253
|
-
};
|
|
412
|
+
const combine = (terms, divisor) => ({
|
|
413
|
+
x: terms.reduce((sum, _ref) => {
|
|
414
|
+
let weight = _ref[0],
|
|
415
|
+
point = _ref[1];
|
|
416
|
+
return sum + weight * point.x;
|
|
417
|
+
}, 0) / divisor,
|
|
418
|
+
y: terms.reduce((sum, _ref2) => {
|
|
419
|
+
let weight = _ref2[0],
|
|
420
|
+
point = _ref2[1];
|
|
421
|
+
return sum + weight * point.y;
|
|
422
|
+
}, 0) / divisor
|
|
254
423
|
});
|
|
424
|
+
export const catmullRomSegments = raw => {
|
|
425
|
+
const points = raw.reduce((kept, point) => kept.length && distance(kept[kept.length - 1], point) < EPSILON ? kept : [...kept, point], []);
|
|
426
|
+
if (points.length <= 2) {
|
|
427
|
+
return [];
|
|
428
|
+
}
|
|
429
|
+
const last = points.length - 1;
|
|
430
|
+
const at = index => {
|
|
431
|
+
if (index < 0) {
|
|
432
|
+
return combine([[2, points[0]], [-1, points[1]]], 1);
|
|
433
|
+
}
|
|
434
|
+
if (index > last) {
|
|
435
|
+
return combine([[2, points[last]], [-1, points[last - 1]]], 1);
|
|
436
|
+
}
|
|
437
|
+
return points[index];
|
|
438
|
+
};
|
|
439
|
+
return points.slice(0, -1).map((from, index) => {
|
|
440
|
+
const a = at(index - 1);
|
|
441
|
+
const b = from;
|
|
442
|
+
const c = at(index + 1);
|
|
443
|
+
const d = at(index + 2);
|
|
444
|
+
const d1 = Math.sqrt(distance(a, b));
|
|
445
|
+
const d2 = Math.sqrt(distance(b, c));
|
|
446
|
+
const d3 = Math.sqrt(distance(c, d));
|
|
447
|
+
return {
|
|
448
|
+
from,
|
|
449
|
+
c1: d1 < EPSILON ? b : combine([[d1 * d1, c], [-d2 * d2, a], [2 * d1 * d1 + 3 * d1 * d2 + d2 * d2, b]], 3 * d1 * (d1 + d2)),
|
|
450
|
+
c2: d3 < EPSILON ? c : combine([[d3 * d3, b], [-d2 * d2, d], [2 * d3 * d3 + 3 * d3 * d2 + d2 * d2, c]], 3 * d3 * (d3 + d2)),
|
|
451
|
+
to: c
|
|
452
|
+
};
|
|
453
|
+
});
|
|
454
|
+
};
|
|
255
455
|
const cubicAt = (segment, t) => {
|
|
256
456
|
const u = 1 - t;
|
|
257
457
|
const a = u * u * u;
|
|
@@ -265,8 +465,8 @@ const cubicAt = (segment, t) => {
|
|
|
265
465
|
};
|
|
266
466
|
const angleOf = (from, to) => Math.atan2(to.y - from.y, to.x - from.x);
|
|
267
467
|
export const lineGeometry = (line, start, end) => {
|
|
268
|
-
|
|
269
|
-
|
|
468
|
+
const segments = line.type === "curved" && line.waypoints.length ? catmullRomSegments([start, ...line.waypoints, end]) : [];
|
|
469
|
+
if (segments.length) {
|
|
270
470
|
const samples = [start];
|
|
271
471
|
const sampleSegments = [0];
|
|
272
472
|
segments.forEach((segment, index) => {
|
|
@@ -281,23 +481,21 @@ export const lineGeometry = (line, start, end) => {
|
|
|
281
481
|
d: segments.reduce((path, segment) => path + " C " + segment.c1.x + " " + segment.c1.y + " " + segment.c2.x + " " + segment.c2.y + " " + segment.to.x + " " + segment.to.y, "M " + start.x + " " + start.y),
|
|
282
482
|
samples,
|
|
283
483
|
sampleSegments,
|
|
284
|
-
route: [start, ...line.waypoints
|
|
484
|
+
route: [start, ...line.waypoints, end],
|
|
285
485
|
startAngle: angleOf(first.c1, start),
|
|
286
486
|
endAngle: angleOf(last.c2, end)
|
|
287
487
|
};
|
|
288
488
|
}
|
|
289
489
|
if (line.type === "elbow") {
|
|
290
|
-
var
|
|
291
|
-
const route =
|
|
292
|
-
const clean = dedupe(route);
|
|
293
|
-
const sampleSegments = route.map((_, index) => Math.max(0, index - 1));
|
|
490
|
+
var _route$, _route;
|
|
491
|
+
const route = simplifyPath([start, ...elbowCorners(line, start, end), end]);
|
|
294
492
|
return {
|
|
295
493
|
d: roundedPolylinePath(route, line.style.corner_radius),
|
|
296
494
|
samples: route,
|
|
297
|
-
sampleSegments,
|
|
495
|
+
sampleSegments: route.map((_, index) => Math.max(0, index - 1)),
|
|
298
496
|
route,
|
|
299
|
-
startAngle: angleOf((
|
|
300
|
-
endAngle: angleOf((
|
|
497
|
+
startAngle: angleOf((_route$ = route[1]) != null ? _route$ : end, start),
|
|
498
|
+
endAngle: angleOf((_route = route[route.length - 2]) != null ? _route : start, end)
|
|
301
499
|
};
|
|
302
500
|
}
|
|
303
501
|
return {
|
|
@@ -358,37 +556,47 @@ export const projectOnSamples = (samples, sampleSegments, point) => {
|
|
|
358
556
|
point: best.point
|
|
359
557
|
};
|
|
360
558
|
};
|
|
361
|
-
export const
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
for (let index = 0; index < route.length - 1; index += 1) {
|
|
365
|
-
const projection = projectOnSamples([route[index], route[index + 1]], [index, index], point);
|
|
366
|
-
const gap = distance(projection.point, point);
|
|
367
|
-
if (gap < bestGap) {
|
|
368
|
-
bestGap = gap;
|
|
369
|
-
bestIndex = index;
|
|
370
|
-
}
|
|
559
|
+
export const withLineType = function (line, type, start, end, snap) {
|
|
560
|
+
if (snap === void 0) {
|
|
561
|
+
snap = point => point;
|
|
371
562
|
}
|
|
372
|
-
|
|
373
|
-
};
|
|
374
|
-
export const withLineType = (line, type, start, end) => {
|
|
375
|
-
if (type === "line" || line.waypoints[type].length) {
|
|
563
|
+
if (type === "line" || line.waypoints.length) {
|
|
376
564
|
return _extends({}, line, {
|
|
377
565
|
type
|
|
378
566
|
});
|
|
379
567
|
}
|
|
380
568
|
const middle = midpoint(start, end);
|
|
381
|
-
const length = distance(start, end)
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
569
|
+
const length = distance(start, end);
|
|
570
|
+
if (type === "curved") {
|
|
571
|
+
const bend = Math.max(24, 0.2 * length);
|
|
572
|
+
return _extends({}, line, {
|
|
573
|
+
type,
|
|
574
|
+
waypoints: [snap({
|
|
575
|
+
x: middle.x + (length ? (end.y - start.y) / length : 0) * bend,
|
|
576
|
+
y: middle.y - (length ? (end.x - start.x) / length : 1) * bend
|
|
577
|
+
})]
|
|
578
|
+
});
|
|
579
|
+
}
|
|
580
|
+
if (line.kind === "connector") {
|
|
581
|
+
return _extends({}, line, {
|
|
582
|
+
type
|
|
583
|
+
});
|
|
584
|
+
}
|
|
387
585
|
return _extends({}, line, {
|
|
388
586
|
type,
|
|
389
|
-
waypoints:
|
|
390
|
-
|
|
391
|
-
|
|
587
|
+
waypoints: elbowAxis(start, end) === "h" ? [{
|
|
588
|
+
x: middle.x,
|
|
589
|
+
y: start.y
|
|
590
|
+
}, {
|
|
591
|
+
x: middle.x,
|
|
592
|
+
y: end.y
|
|
593
|
+
}] : [{
|
|
594
|
+
x: start.x,
|
|
595
|
+
y: middle.y
|
|
596
|
+
}, {
|
|
597
|
+
x: end.x,
|
|
598
|
+
y: middle.y
|
|
599
|
+
}]
|
|
392
600
|
});
|
|
393
601
|
};
|
|
394
602
|
export const constrainAngle = (from, to) => {
|
|
@@ -476,17 +684,17 @@ const TYPE_PATHS = {
|
|
|
476
684
|
};
|
|
477
685
|
|
|
478
686
|
// ds-exception: no line-type glyphs in src/components/Icons — Design System task
|
|
479
|
-
export const LineTypeGlyph =
|
|
480
|
-
let type =
|
|
687
|
+
export const LineTypeGlyph = _ref3 => {
|
|
688
|
+
let type = _ref3.type;
|
|
481
689
|
return /*#__PURE__*/React.createElement("svg", GLYPH_PROPS, /*#__PURE__*/React.createElement("path", {
|
|
482
690
|
d: TYPE_PATHS[type]
|
|
483
691
|
}));
|
|
484
692
|
};
|
|
485
693
|
|
|
486
694
|
// ds-exception: no line-end glyphs in src/components/Icons — Design System task
|
|
487
|
-
export const LineEndGlyph =
|
|
488
|
-
let type =
|
|
489
|
-
side =
|
|
695
|
+
export const LineEndGlyph = _ref4 => {
|
|
696
|
+
let type = _ref4.type,
|
|
697
|
+
side = _ref4.side;
|
|
490
698
|
const tip = side === "end" ? {
|
|
491
699
|
x: 17,
|
|
492
700
|
y: 10
|
|
@@ -501,8 +709,8 @@ export const LineEndGlyph = _ref2 => {
|
|
|
501
709
|
};
|
|
502
710
|
|
|
503
711
|
// ds-exception: no stroke-pattern glyphs in src/components/Icons — Design System task
|
|
504
|
-
export const LinePatternGlyph =
|
|
505
|
-
let pattern =
|
|
712
|
+
export const LinePatternGlyph = _ref5 => {
|
|
713
|
+
let pattern = _ref5.pattern;
|
|
506
714
|
return /*#__PURE__*/React.createElement("svg", _extends({}, GLYPH_PROPS, {
|
|
507
715
|
strokeWidth: 2,
|
|
508
716
|
strokeLinecap: "butt"
|
|
@@ -513,8 +721,8 @@ export const LinePatternGlyph = _ref3 => {
|
|
|
513
721
|
};
|
|
514
722
|
|
|
515
723
|
// ds-exception: no stroke-thickness glyphs in src/components/Icons — Design System task
|
|
516
|
-
export const LineThicknessGlyph =
|
|
517
|
-
let width =
|
|
724
|
+
export const LineThicknessGlyph = _ref6 => {
|
|
725
|
+
let width = _ref6.width;
|
|
518
726
|
return /*#__PURE__*/React.createElement("svg", _extends({}, GLYPH_PROPS, {
|
|
519
727
|
strokeWidth: width
|
|
520
728
|
}), /*#__PURE__*/React.createElement("path", {
|
|
@@ -523,8 +731,8 @@ export const LineThicknessGlyph = _ref4 => {
|
|
|
523
731
|
};
|
|
524
732
|
|
|
525
733
|
// ds-exception: no corner-radius glyph in src/components/Icons — Design System task
|
|
526
|
-
export const CornerRadiusGlyph =
|
|
527
|
-
let radius =
|
|
734
|
+
export const CornerRadiusGlyph = _ref7 => {
|
|
735
|
+
let radius = _ref7.radius;
|
|
528
736
|
const size = Math.min(10, radius / 4);
|
|
529
737
|
return /*#__PURE__*/React.createElement("svg", GLYPH_PROPS, /*#__PURE__*/React.createElement("path", {
|
|
530
738
|
d: size ? "M4 17 V" + (4 + size) + " A" + size + " " + size + " 0 0 1 " + (4 + size) + " 4 H17" : "M4 17 V4 H17"
|
|
@@ -546,7 +754,7 @@ export const resolveEndpoints = (line, boxOf) => {
|
|
|
546
754
|
const to = line.end_element_id ? boxOf(line.end_element_id) : null;
|
|
547
755
|
const fromCenter = from ? boxCenter(from) : line.start;
|
|
548
756
|
const toCenter = to ? boxCenter(to) : line.end;
|
|
549
|
-
const bends = line.type === "
|
|
757
|
+
const bends = line.type === "line" ? [] : line.waypoints;
|
|
550
758
|
return {
|
|
551
759
|
start: from ? anchorPoint(from, (_line$start_anchor = line.start_anchor) != null ? _line$start_anchor : "center", (_bends$ = bends[0]) != null ? _bends$ : toCenter) : line.start,
|
|
552
760
|
end: to ? anchorPoint(to, (_line$end_anchor = line.end_anchor) != null ? _line$end_anchor : "center", (_bends = bends[bends.length - 1]) != null ? _bends : fromCenter) : line.end
|