@canvas-harness/react 0.1.5 → 0.1.6
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 +39 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +39 -11
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
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
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
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.
|
|
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;
|
|
@@ -658,6 +683,9 @@ var useInteractionGesture = (ref, store, tool) => {
|
|
|
658
683
|
case "reconnect-edge":
|
|
659
684
|
commitReconnect(e);
|
|
660
685
|
break;
|
|
686
|
+
case "edge-midpoint":
|
|
687
|
+
commitEdgeMidpoint();
|
|
688
|
+
break;
|
|
661
689
|
}
|
|
662
690
|
pointerDownAt = null;
|
|
663
691
|
activeGesture = "idle";
|