@affino/diagram-core 0.11.0 → 0.11.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.
@@ -49,7 +49,7 @@ export declare class DiagramInteractionController {
49
49
  pointerMove(event: DiagramPointerEvent): void;
50
50
  pointerUp(event: DiagramPointerEvent): void;
51
51
  cancel(): void;
52
- /** Returns the renderer-ready geometry for the active move preview. */
52
+ /** Returns renderer-ready geometry for active move and table resize previews. */
53
53
  getPreviewGeometry(id: DiagramId): DiagramGeometry | null;
54
54
  getSnapshot(): DiagramInteractionSnapshot;
55
55
  getPendingMoveCount(): number;
@@ -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,EAAkB,SAAS,EAAE,eAAe,EAAE,6BAA6B,EAAE,0BAA0B,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,mBAAmB,EAAiD,mBAAmB,EAAoB,MAAM,YAAY,CAAA;AAE9R,KAAK,aAAa,GAAG,CAAC,QAAQ,EAAE,MAAM,IAAI,KAAK,IAAI,CAAA;AAGnD,MAAM,MAAM,yBAAyB,GAAG,QAAQ,CAAC;IAC/C,aAAa,CAAC,EAAE,aAAa,CAAA;IAC7B,WAAW,CAAC,EAAE,kBAAkB,CAAA;IAChC,IAAI,CAAC,EAAE,6BAA6B,CAAA;CACrC,CAAC,CAAA;AAEF,qBAAa,4BAA4B;IAkC3B,OAAO,CAAC,QAAQ,CAAC,MAAM;IAjCnC,OAAO,CAAC,IAAI,CAAmC;IAC/C,OAAO,CAAC,aAAa,CAAmC;IACxD,OAAO,CAAC,UAAU,CAA4B;IAC9C,OAAO,CAAC,WAAW,CAA4B;IAC/C,OAAO,CAAC,cAAc,CAAQ;IAC9B,OAAO,CAAC,SAAS,CAAyB;IAC1C,OAAO,CAAC,YAAY,CAA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14 +391,39 @@ export class DiagramInteractionController {
391
391
  this.clearGesture();
392
392
  this.tool = "select";
393
393
  }
394
- /** Returns the renderer-ready geometry for the active move preview. */
394
+ /** Returns renderer-ready geometry for active move and table resize previews. */
395
395
  getPreviewGeometry(id) {
396
- var _a, _b, _c, _d, _e;
396
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
397
397
  const geometry = this.engine.getGeometrySnapshot(id);
398
- if ((geometry === null || geometry === void 0 ? void 0 : geometry.kind) === "edge" && ((_a = geometry.path) === null || _a === void 0 ? void 0 : _a.length) && this.edgeEndpointId === id && this.edgeEndpointKind && this.edgeEndpointPreview) {
398
+ if ((geometry === null || geometry === void 0 ? void 0 : geometry.kind) === "table") {
399
+ const directEntry = this.resizePreviewEntries.find((entry) => entry.id === id);
400
+ if (directEntry)
401
+ return resizePreviewGeometry(geometry, directEntry);
402
+ if (this.tool === "resize-selection") {
403
+ const scene = this.engine.getScene();
404
+ const ownerGroup = [...scene.entities.groupsById.values()].find((group) => group.childIds.includes(id));
405
+ const groupEntry = ownerGroup ? this.resizePreviewEntries.find((entry) => entry.id === ownerGroup.id) : undefined;
406
+ const groupGeometry = ownerGroup && groupEntry ? this.engine.getGeometrySnapshot(ownerGroup.id) : null;
407
+ if (ownerGroup && groupEntry && groupGeometry) {
408
+ const from = groupGeometry.bounds;
409
+ const to = { x: (_a = groupEntry.x) !== null && _a !== void 0 ? _a : from.x, y: (_b = groupEntry.y) !== null && _b !== void 0 ? _b : from.y, width: (_c = groupEntry.width) !== null && _c !== void 0 ? _c : from.width, height: (_d = groupEntry.height) !== null && _d !== void 0 ? _d : from.height };
410
+ const scaleX = from.width === 0 ? 1 : to.width / from.width;
411
+ const scaleY = from.height === 0 ? 1 : to.height / from.height;
412
+ const tableBounds = (_e = geometry.unrotatedBounds) !== null && _e !== void 0 ? _e : geometry.bounds;
413
+ return resizePreviewGeometry(geometry, {
414
+ id,
415
+ x: to.x + (tableBounds.x - from.x) * scaleX,
416
+ y: to.y + (tableBounds.y - from.y) * scaleY,
417
+ width: tableBounds.width * scaleX,
418
+ height: tableBounds.height * scaleY,
419
+ });
420
+ }
421
+ }
422
+ }
423
+ if ((geometry === null || geometry === void 0 ? void 0 : geometry.kind) === "edge" && ((_f = geometry.path) === null || _f === void 0 ? void 0 : _f.length) && this.edgeEndpointId === id && this.edgeEndpointKind && this.edgeEndpointPreview) {
399
424
  const path = [
400
425
  this.edgeEndpointKind === "source" ? this.edgeEndpointPreview : geometry.path[0],
401
- ...((_b = this.edgeWaypointPreview) !== null && _b !== void 0 ? _b : geometry.path.slice(1, -1)),
426
+ ...((_g = this.edgeWaypointPreview) !== null && _g !== void 0 ? _g : geometry.path.slice(1, -1)),
402
427
  this.edgeEndpointKind === "target" ? this.edgeEndpointPreview : geometry.path[geometry.path.length - 1],
403
428
  ];
404
429
  const bounds = boundsFromPoints(path);
@@ -419,7 +444,7 @@ export class DiagramInteractionController {
419
444
  ? moved.has(endpoint.nodeId)
420
445
  : moved.has((_b = (_a = scene.entities.portsById.get(endpoint.portId)) === null || _a === void 0 ? void 0 : _a.nodeId) !== null && _b !== void 0 ? _b : "");
421
446
  };
422
- const path = (_c = geometry.path) === null || _c === void 0 ? void 0 : _c.map((point, index) => {
447
+ const path = (_h = geometry.path) === null || _h === void 0 ? void 0 : _h.map((point, index) => {
423
448
  var _a, _b;
424
449
  const isSource = index === 0;
425
450
  const isTarget = index === ((_b = (_a = geometry.path) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0) - 1;
@@ -442,8 +467,8 @@ export class DiagramInteractionController {
442
467
  bounds: { ...geometry.bounds, x: geometry.bounds.x + this.previewDelta.x, y: geometry.bounds.y + this.previewDelta.y },
443
468
  hitBounds: { ...geometry.hitBounds, x: geometry.hitBounds.x + this.previewDelta.x, y: geometry.hitBounds.y + this.previewDelta.y },
444
469
  unrotatedBounds: geometry.unrotatedBounds ? { ...geometry.unrotatedBounds, x: geometry.unrotatedBounds.x + this.previewDelta.x, y: geometry.unrotatedBounds.y + this.previewDelta.y } : undefined,
445
- corners: (_d = geometry.corners) === null || _d === void 0 ? void 0 : _d.map(move),
446
- path: (_e = geometry.path) === null || _e === void 0 ? void 0 : _e.map(move),
470
+ corners: (_j = geometry.corners) === null || _j === void 0 ? void 0 : _j.map(move),
471
+ path: (_k = geometry.path) === null || _k === void 0 ? void 0 : _k.map(move),
447
472
  point: geometry.point ? move(geometry.point) : undefined,
448
473
  });
449
474
  }
@@ -732,6 +757,17 @@ export class DiagramInteractionController {
732
757
  this.pendingMoveCount = 0;
733
758
  }
734
759
  }
760
+ function resizePreviewGeometry(geometry, entry) {
761
+ var _a, _b, _c, _d, _e;
762
+ const previous = (_a = geometry.unrotatedBounds) !== null && _a !== void 0 ? _a : geometry.bounds;
763
+ const bounds = {
764
+ x: (_b = entry.x) !== null && _b !== void 0 ? _b : previous.x,
765
+ y: (_c = entry.y) !== null && _c !== void 0 ? _c : previous.y,
766
+ width: (_d = entry.width) !== null && _d !== void 0 ? _d : previous.width,
767
+ height: (_e = entry.height) !== null && _e !== void 0 ? _e : previous.height,
768
+ };
769
+ return Object.freeze({ ...geometry, bounds, unrotatedBounds: bounds, hitBounds: inflateRect(bounds, 3), rotation: 0 });
770
+ }
735
771
  export function createDiagramInteractionController(engine, options = {}) {
736
772
  return new DiagramInteractionController(engine, options);
737
773
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@affino/diagram-core",
3
- "version": "0.11.0",
3
+ "version": "0.11.1",
4
4
  "author": "Anton Pavlov <a.pavlov@affino.dev>",
5
5
  "type": "module",
6
6
  "description": "Headless diagram core for Affino UI primitives",