@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.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
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
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.
|
|
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;
|
|
@@ -660,6 +685,9 @@ var useInteractionGesture = (ref, store, tool) => {
|
|
|
660
685
|
case "reconnect-edge":
|
|
661
686
|
commitReconnect(e);
|
|
662
687
|
break;
|
|
688
|
+
case "edge-midpoint":
|
|
689
|
+
commitEdgeMidpoint();
|
|
690
|
+
break;
|
|
663
691
|
}
|
|
664
692
|
pointerDownAt = null;
|
|
665
693
|
activeGesture = "idle";
|