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