@canvas-harness/react 0.1.5 → 0.1.7

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/index.js CHANGED
@@ -325,13 +325,17 @@ var useInteractionGesture = (ref, store, tool) => {
325
325
  };
326
326
  const beginResize = (id, handle) => {
327
327
  dragOriginals = snapshotOriginals([id]);
328
+ const o = dragOriginals[0];
328
329
  store.setInteractionState({
329
330
  mode: "resizing",
330
331
  draggedIds: [id],
331
332
  dragOriginals,
332
333
  resizeHandle: handle,
333
334
  resizeLockAspect: false,
334
- resizeFromCenter: false
335
+ resizeFromCenter: false,
336
+ // Seed the draft with original geometry so the first frame
337
+ // before any pointermove already paints from the draft.
338
+ resizeDraft: o ? { x: o.x, y: o.y, w: o.w, h: o.h, angle: o.angle } : null
335
339
  });
336
340
  };
337
341
  const pointerAngleFromCenter = (node, world) => {
@@ -372,10 +376,10 @@ var useInteractionGesture = (ref, store, tool) => {
372
376
  const orig = dragOriginals[0];
373
377
  if (!orig || !resizeHandle) return;
374
378
  const next = computeResizeGeometry(orig, resizeHandle, worldPoint, modifiers);
375
- store.updateNode(orig.id, next);
376
379
  store.setInteractionState({
377
380
  resizeLockAspect: modifiers.shift,
378
- resizeFromCenter: modifiers.alt
381
+ resizeFromCenter: modifiers.alt,
382
+ resizeDraft: { x: next.x, y: next.y, w: next.w, h: next.h, angle: orig.angle }
379
383
  });
380
384
  };
381
385
  const commitDrag = () => {
@@ -391,13 +395,27 @@ var useInteractionGesture = (ref, store, tool) => {
391
395
  store.resetInteractionState();
392
396
  };
393
397
  const commitResize = () => {
394
- const selected = store.getSelection();
395
- for (const id of selected) {
396
- const node = store.getNode(id);
397
- if (!node) continue;
398
- if (!shouldAutoFit(node)) continue;
399
- const fitted = computeAutoFitHeight(node);
400
- if (fitted > node.h) store.updateNode(node.id, { h: fitted });
398
+ const interaction = store.getInteractionState();
399
+ const draft = interaction.resizeDraft;
400
+ const orig = dragOriginals[0];
401
+ if (draft && orig) {
402
+ store.batch(() => {
403
+ store.updateNode(orig.id, {
404
+ x: draft.x,
405
+ y: draft.y,
406
+ w: draft.w,
407
+ h: draft.h,
408
+ angle: draft.angle
409
+ });
410
+ const selected = store.getSelection();
411
+ for (const id of selected) {
412
+ const node = store.getNode(id);
413
+ if (!node) continue;
414
+ if (!shouldAutoFit(node)) continue;
415
+ const fitted = computeAutoFitHeight(node);
416
+ if (fitted > node.h) store.updateNode(node.id, { h: fitted });
417
+ }
418
+ });
401
419
  }
402
420
  store.resetInteractionState();
403
421
  };
@@ -580,7 +598,14 @@ var useInteractionGesture = (ref, store, tool) => {
580
598
  const geom = store.getEdgeGeometry(midpointEdgeId);
581
599
  if (!geom) return;
582
600
  const { c1, c2 } = midpointToCubicControls(geom.source, world, geom.target);
583
- store.updateEdge(midpointEdgeId, { control: [c1, c2] });
601
+ store.setInteractionState({
602
+ midpointDraft: { edgeId: midpointEdgeId, control: [c1, c2] }
603
+ });
604
+ };
605
+ const commitEdgeMidpoint = () => {
606
+ const draft = store.getInteractionState().midpointDraft;
607
+ if (draft) store.updateEdge(draft.edgeId, { control: draft.control });
608
+ store.resetInteractionState();
584
609
  };
585
610
  const updateReconnect = (world) => {
586
611
  if (!reconnectEdgeId || !reconnectEnd) return;
@@ -605,12 +630,8 @@ var useInteractionGesture = (ref, store, tool) => {
605
630
  if (hit?.kind === "body" && "nodeId" in hit) {
606
631
  const node = store.getNode(hit.nodeId);
607
632
  if (node) {
608
- const local = worldToNodeLocal(world, node);
609
- const clamped = {
610
- x: Math.max(0, Math.min(node.w, local.x)),
611
- y: Math.max(0, Math.min(node.h, local.y))
612
- };
613
- return { end: { nodeId: node.id, localOffset: clamped }, nodeId: node.id };
633
+ const localOffset = projectToNodeBoundary(world, node);
634
+ return { end: { nodeId: node.id, localOffset }, nodeId: node.id };
614
635
  }
615
636
  }
616
637
  return { end: { worldPoint: world }, nodeId: null };
@@ -658,6 +679,9 @@ var useInteractionGesture = (ref, store, tool) => {
658
679
  case "reconnect-edge":
659
680
  commitReconnect(e);
660
681
  break;
682
+ case "edge-midpoint":
683
+ commitEdgeMidpoint();
684
+ break;
661
685
  }
662
686
  pointerDownAt = null;
663
687
  activeGesture = "idle";