@affino/diagram-core 0.10.0 → 0.10.1
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/README.md +2 -2
- package/dist/interaction.d.ts +2 -0
- package/dist/interaction.d.ts.map +1 -1
- package/dist/interaction.js +40 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -109,11 +109,11 @@ Holding Shift during a resize preserves the original aspect ratio. The modifier
|
|
|
109
109
|
|
|
110
110
|
Selected edge endpoints use `beginEdgeEndpointHandle(id, endpoint, event)`. The controller publishes an `edgeEndpointPreview` on scheduled frames and `getPreviewGeometry(id)` returns the previewed route without changing the scene. Pointer up commits one undoable `moveEdgeEndpoint`; cancel discards the preview.
|
|
111
111
|
|
|
112
|
-
Holding Shift while dragging an endpoint constrains it to the dominant axis measured from its original position (horizontal wins an exact tie). Port, alignment, and grid snapping preserve that axis.
|
|
112
|
+
Holding Shift while dragging an endpoint constrains it to the dominant axis measured from its original position (horizontal wins an exact tie). After the pointer moves 4 screen pixels, the axis stays latched until Shift is released; pressing Shift again chooses a new axis from the current gesture direction. Port, alignment, and grid snapping preserve that axis. The same latch behavior applies to selection drags. Preview and final command use the same snapped geometry.
|
|
113
113
|
|
|
114
114
|
Selection drags snap by default to ports, alignments, and equal spacing. Configure grid spacing and screen-space tolerance when creating the controller; the tolerance is converted to world units using the viewport zoom. The `snapGuides` snapshot field contains world-space line segments for active alignment and equal-spacing matches. Set `enabled: false` to disable drag snapping. Moving a selected edge translates free endpoints and route points while preserving node/port endpoint attachments.
|
|
115
115
|
|
|
116
|
-
Holding Shift during a selection drag constrains the group to the dominant axis from the gesture origin (horizontal wins an exact tie). The constraint applies to the frame-batched preview and the committed delta
|
|
116
|
+
Holding Shift during a selection drag constrains the group to the dominant axis from the gesture origin (horizontal wins an exact tie). After the pointer moves 4 screen pixels, the axis stays latched until Shift is released; pressing Shift again chooses from the current gesture direction. The constraint applies to the frame-batched preview and the committed delta, and snapping stays on that axis. Shift-click continues to add or toggle selection. Direct `snapTranslation()` callers can set `axisConstraint: "x" | "y"` to apply the same axis-aware port, alignment, equal-spacing, and grid snapping.
|
|
117
117
|
|
|
118
118
|
```ts
|
|
119
119
|
const interaction = createDiagramInteractionController(engine, {
|
package/dist/interaction.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export declare class DiagramInteractionController {
|
|
|
13
13
|
private startPoint;
|
|
14
14
|
private latestPoint;
|
|
15
15
|
private latestShiftKey;
|
|
16
|
+
private shiftAxis;
|
|
16
17
|
private previewDelta;
|
|
17
18
|
private marquee;
|
|
18
19
|
private resizeOwnerId;
|
|
@@ -55,6 +56,7 @@ export declare class DiagramInteractionController {
|
|
|
55
56
|
private createSelectionResizePreviewEntries;
|
|
56
57
|
private createResizePreview;
|
|
57
58
|
private resizeGridSize;
|
|
59
|
+
private updateShiftAxis;
|
|
58
60
|
private getMarqueeSelectionIds;
|
|
59
61
|
private clearGesture;
|
|
60
62
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interaction.d.ts","sourceRoot":"","sources":["../src/interaction.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,6BAA6B,EAAE,0BAA0B,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,mBAAmB,EAAiD,mBAAmB,EAAoB,MAAM,YAAY,CAAA;AAE9Q,KAAK,aAAa,GAAG,CAAC,QAAQ,EAAE,MAAM,IAAI,KAAK,IAAI,CAAA;
|
|
1
|
+
{"version":3,"file":"interaction.d.ts","sourceRoot":"","sources":["../src/interaction.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,eAAe,EAAE,6BAA6B,EAAE,0BAA0B,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,mBAAm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@@
|
|
|
1
1
|
import { createEntityGeometry, inflateRect, rectFromPoints as boundsFromPoints } from "./geometry.js";
|
|
2
|
+
const AXIS_LOCK_ACTIVATION_TOLERANCE_PX = 4;
|
|
2
3
|
export class DiagramInteractionController {
|
|
3
4
|
constructor(engine, options = {}) {
|
|
4
5
|
var _a, _b, _c;
|
|
@@ -38,6 +39,12 @@ export class DiagramInteractionController {
|
|
|
38
39
|
writable: true,
|
|
39
40
|
value: false
|
|
40
41
|
});
|
|
42
|
+
Object.defineProperty(this, "shiftAxis", {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
configurable: true,
|
|
45
|
+
writable: true,
|
|
46
|
+
value: null
|
|
47
|
+
});
|
|
41
48
|
Object.defineProperty(this, "previewDelta", {
|
|
42
49
|
enumerable: true,
|
|
43
50
|
configurable: true,
|
|
@@ -191,6 +198,7 @@ export class DiagramInteractionController {
|
|
|
191
198
|
this.startPoint = event.point;
|
|
192
199
|
this.latestPoint = event.point;
|
|
193
200
|
this.latestShiftKey = event.shiftKey === true;
|
|
201
|
+
this.shiftAxis = null;
|
|
194
202
|
this.previewDelta = null;
|
|
195
203
|
this.marquee = null;
|
|
196
204
|
this.snapGuides = Object.freeze([]);
|
|
@@ -238,6 +246,7 @@ export class DiagramInteractionController {
|
|
|
238
246
|
this.startPoint = event.point;
|
|
239
247
|
this.latestPoint = event.point;
|
|
240
248
|
this.latestShiftKey = event.shiftKey === true;
|
|
249
|
+
this.shiftAxis = null;
|
|
241
250
|
this.resizeOwnerId = ownerId;
|
|
242
251
|
this.resizeHandle = handle;
|
|
243
252
|
this.resizeStartBounds = (_a = geometry.unrotatedBounds) !== null && _a !== void 0 ? _a : geometry.bounds;
|
|
@@ -256,6 +265,7 @@ export class DiagramInteractionController {
|
|
|
256
265
|
this.startPoint = event.point;
|
|
257
266
|
this.latestPoint = event.point;
|
|
258
267
|
this.latestShiftKey = event.shiftKey === true;
|
|
268
|
+
this.shiftAxis = null;
|
|
259
269
|
this.edgeEndpointId = ownerId;
|
|
260
270
|
this.edgeEndpointKind = endpoint;
|
|
261
271
|
this.edgeEndpointStart = point;
|
|
@@ -279,6 +289,7 @@ export class DiagramInteractionController {
|
|
|
279
289
|
this.startPoint = event.point;
|
|
280
290
|
this.latestPoint = event.point;
|
|
281
291
|
this.latestShiftKey = event.shiftKey === true;
|
|
292
|
+
this.shiftAxis = null;
|
|
282
293
|
this.resizeSelectionIds = ids;
|
|
283
294
|
this.resizeHandle = handle;
|
|
284
295
|
this.resizeStartBounds = bounds;
|
|
@@ -290,7 +301,7 @@ export class DiagramInteractionController {
|
|
|
290
301
|
return;
|
|
291
302
|
}
|
|
292
303
|
this.latestPoint = event.point;
|
|
293
|
-
this.
|
|
304
|
+
this.updateShiftAxis(event.shiftKey === true, event.point);
|
|
294
305
|
this.pendingMoveCount += 1;
|
|
295
306
|
if (!this.framePending) {
|
|
296
307
|
this.framePending = true;
|
|
@@ -308,7 +319,7 @@ export class DiagramInteractionController {
|
|
|
308
319
|
return;
|
|
309
320
|
}
|
|
310
321
|
this.latestPoint = event.point;
|
|
311
|
-
this.
|
|
322
|
+
this.updateShiftAxis(event.shiftKey === true, event.point);
|
|
312
323
|
this.flushPointerMove();
|
|
313
324
|
if (this.tool === "drag-selection" && this.previewDelta) {
|
|
314
325
|
const selection = this.engine.getScene().selection;
|
|
@@ -419,16 +430,14 @@ export class DiagramInteractionController {
|
|
|
419
430
|
return this.commitCount;
|
|
420
431
|
}
|
|
421
432
|
flushPointerMove() {
|
|
422
|
-
var _a, _b, _c, _d, _e, _f;
|
|
433
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
423
434
|
this.framePending = false;
|
|
424
435
|
if (!this.startPoint || !this.latestPoint) {
|
|
425
436
|
return;
|
|
426
437
|
}
|
|
427
438
|
const delta = { x: this.latestPoint.x - this.startPoint.x, y: this.latestPoint.y - this.startPoint.y };
|
|
428
439
|
if (this.tool === "drag-selection" || this.tool === "pan") {
|
|
429
|
-
const axisConstraint = this.tool === "drag-selection" && this.latestShiftKey
|
|
430
|
-
? Math.abs(delta.x) >= Math.abs(delta.y) ? "x" : "y"
|
|
431
|
-
: undefined;
|
|
440
|
+
const axisConstraint = this.tool === "drag-selection" && this.latestShiftKey ? (_a = this.shiftAxis) !== null && _a !== void 0 ? _a : undefined : undefined;
|
|
432
441
|
const constrainedDelta = axisConstraint === "x"
|
|
433
442
|
? { x: delta.x, y: 0 }
|
|
434
443
|
: axisConstraint === "y"
|
|
@@ -438,13 +447,13 @@ export class DiagramInteractionController {
|
|
|
438
447
|
const viewport = this.engine.getScene().viewport;
|
|
439
448
|
const zoom = viewport.zoom > 0 ? viewport.zoom : 1;
|
|
440
449
|
const selection = this.engine.getScene().selection;
|
|
441
|
-
const snapped = this.engine.snapTranslation({ ...selection, ids: this.dragSelectionIds, primaryId: this.dragSelectionIds.includes((
|
|
442
|
-
radius: ((
|
|
450
|
+
const snapped = this.engine.snapTranslation({ ...selection, ids: this.dragSelectionIds, primaryId: this.dragSelectionIds.includes((_b = selection.primaryId) !== null && _b !== void 0 ? _b : "") ? selection.primaryId : (_c = this.dragSelectionIds[0]) !== null && _c !== void 0 ? _c : null }, constrainedDelta, {
|
|
451
|
+
radius: ((_d = this.snapOptions.tolerancePx) !== null && _d !== void 0 ? _d : 6) / zoom,
|
|
443
452
|
gridSize: this.snapOptions.gridSize,
|
|
444
453
|
axisConstraint,
|
|
445
454
|
snapToPorts: this.snapOptions.snapToPorts,
|
|
446
455
|
snapToAlignment: this.snapOptions.snapToAlignment,
|
|
447
|
-
snapToEqualSpacing: (
|
|
456
|
+
snapToEqualSpacing: (_e = this.snapOptions.snapToEqualSpacing) !== null && _e !== void 0 ? _e : true,
|
|
448
457
|
});
|
|
449
458
|
this.previewDelta = snapped.point;
|
|
450
459
|
this.snapGuides = snapped.guides;
|
|
@@ -457,16 +466,14 @@ export class DiagramInteractionController {
|
|
|
457
466
|
}
|
|
458
467
|
if (this.tool === "resize-selection") {
|
|
459
468
|
this.resizePreviewEntries = this.createResizePreviewEntries(delta);
|
|
460
|
-
this.resizePreview = (
|
|
469
|
+
this.resizePreview = (_f = this.resizePreviewEntries[0]) !== null && _f !== void 0 ? _f : null;
|
|
461
470
|
return;
|
|
462
471
|
}
|
|
463
472
|
if (this.tool === "drag-edge-endpoint") {
|
|
464
473
|
if (!this.edgeEndpointStart)
|
|
465
474
|
return;
|
|
466
475
|
const origin = this.edgeEndpointStart;
|
|
467
|
-
const axisConstraint = this.latestShiftKey
|
|
468
|
-
? Math.abs(delta.x) >= Math.abs(delta.y) ? "x" : "y"
|
|
469
|
-
: undefined;
|
|
476
|
+
const axisConstraint = this.latestShiftKey ? (_g = this.shiftAxis) !== null && _g !== void 0 ? _g : undefined : undefined;
|
|
470
477
|
const desiredPoint = {
|
|
471
478
|
x: axisConstraint === "y" ? origin.x : this.latestPoint.x,
|
|
472
479
|
y: axisConstraint === "x" ? origin.y : this.latestPoint.y,
|
|
@@ -478,7 +485,7 @@ export class DiagramInteractionController {
|
|
|
478
485
|
const viewport = this.engine.getScene().viewport;
|
|
479
486
|
const zoom = viewport.zoom > 0 ? viewport.zoom : 1;
|
|
480
487
|
this.edgeEndpointPreview = this.engine.snapPoint(desiredPoint, {
|
|
481
|
-
radius: ((
|
|
488
|
+
radius: ((_h = this.snapOptions.tolerancePx) !== null && _h !== void 0 ? _h : 6) / zoom,
|
|
482
489
|
gridSize: this.snapOptions.gridSize,
|
|
483
490
|
axisConstraint,
|
|
484
491
|
snapToPorts: this.snapOptions.snapToPorts,
|
|
@@ -547,6 +554,24 @@ export class DiagramInteractionController {
|
|
|
547
554
|
resizeGridSize() {
|
|
548
555
|
return !this.latestShiftKey || this.snapOptions.enabled === false ? undefined : this.snapOptions.gridSize;
|
|
549
556
|
}
|
|
557
|
+
updateShiftAxis(shiftKey, point) {
|
|
558
|
+
const wasShifted = this.latestShiftKey;
|
|
559
|
+
this.latestShiftKey = shiftKey;
|
|
560
|
+
if (!shiftKey) {
|
|
561
|
+
this.shiftAxis = null;
|
|
562
|
+
return;
|
|
563
|
+
}
|
|
564
|
+
if (!wasShifted)
|
|
565
|
+
this.shiftAxis = null;
|
|
566
|
+
if (this.shiftAxis || !this.startPoint || (this.tool !== "drag-selection" && this.tool !== "drag-edge-endpoint"))
|
|
567
|
+
return;
|
|
568
|
+
const delta = { x: point.x - this.startPoint.x, y: point.y - this.startPoint.y };
|
|
569
|
+
const viewport = this.engine.getScene().viewport;
|
|
570
|
+
const zoom = viewport.zoom > 0 ? viewport.zoom : 1;
|
|
571
|
+
if (Math.hypot(delta.x, delta.y) * zoom < AXIS_LOCK_ACTIVATION_TOLERANCE_PX)
|
|
572
|
+
return;
|
|
573
|
+
this.shiftAxis = Math.abs(delta.x) >= Math.abs(delta.y) ? "x" : "y";
|
|
574
|
+
}
|
|
550
575
|
getMarqueeSelectionIds(rect) {
|
|
551
576
|
const visible = new Set(this.engine.queryVisible(rect));
|
|
552
577
|
const scene = this.engine.getScene();
|
|
@@ -570,6 +595,7 @@ export class DiagramInteractionController {
|
|
|
570
595
|
this.startPoint = null;
|
|
571
596
|
this.latestPoint = null;
|
|
572
597
|
this.latestShiftKey = false;
|
|
598
|
+
this.shiftAxis = null;
|
|
573
599
|
this.previewDelta = null;
|
|
574
600
|
this.marquee = null;
|
|
575
601
|
this.resizeOwnerId = null;
|