@statelyai/flow-dom 3.5.1 → 3.5.3
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/esm/index.js +49 -44
- package/package.json +2 -2
package/dist/esm/index.js
CHANGED
|
@@ -497,15 +497,14 @@ function createEntityGeometryObserver(store, options = {}) {
|
|
|
497
497
|
});
|
|
498
498
|
const first = pathData.segments[0]?.points[0];
|
|
499
499
|
const last = pathData.segments.at(-1)?.points.at(-1);
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
targetElement?.setAttribute("cy", String(last.y));
|
|
500
|
+
for (const [end, point] of [["source", first], ["target", last]]) {
|
|
501
|
+
if (!point) continue;
|
|
502
|
+
element.querySelectorAll(`[data-flow-edge-endpoint="${end}"]`).forEach((handle) => {
|
|
503
|
+
const x = Number(handle.dataset.flowEdgeEndpointOffsetX ?? 0);
|
|
504
|
+
const y = Number(handle.dataset.flowEdgeEndpointOffsetY ?? 0);
|
|
505
|
+
handle.setAttribute("cx", String(point.x + (Number.isFinite(x) ? x : 0)));
|
|
506
|
+
handle.setAttribute("cy", String(point.y + (Number.isFinite(y) ? y : 0)));
|
|
507
|
+
});
|
|
509
508
|
}
|
|
510
509
|
});
|
|
511
510
|
},
|
|
@@ -542,15 +541,15 @@ function createMeasurementObserver(store, options = {}) {
|
|
|
542
541
|
let rafId = null;
|
|
543
542
|
function flush() {
|
|
544
543
|
rafId = null;
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
}
|
|
544
|
+
const measurements = pendingMeasurements.filter(({ element, registration }) => elementMap.get(element) === registration).map(({ measurement }) => measurement);
|
|
545
|
+
pendingMeasurements = [];
|
|
546
|
+
if (measurements.length > 0) store.trigger.updateMeasurements({ measurements });
|
|
549
547
|
}
|
|
550
548
|
function scheduleFlush() {
|
|
551
549
|
if (rafId === null) rafId = requestAnimationFrame(flush);
|
|
552
550
|
}
|
|
553
|
-
function pushMeasurement(element,
|
|
551
|
+
function pushMeasurement(element, registration, layoutSize) {
|
|
552
|
+
const { target } = registration;
|
|
554
553
|
const viewport = store.getSnapshot().context.viewport;
|
|
555
554
|
const zoom = viewport.zoom || 1;
|
|
556
555
|
const rect = element.getBoundingClientRect();
|
|
@@ -566,15 +565,20 @@ function createMeasurementObserver(store, options = {}) {
|
|
|
566
565
|
const existing = store.getSnapshot().context.measurements.get(id);
|
|
567
566
|
if (existing && Math.abs(existing.x - measurement.x) < equalityThreshold && Math.abs(existing.y - measurement.y) < equalityThreshold && Math.abs(existing.width - measurement.width) < equalityThreshold && Math.abs(existing.height - measurement.height) < equalityThreshold) return;
|
|
568
567
|
pendingMeasurements.push({
|
|
569
|
-
|
|
570
|
-
|
|
568
|
+
element,
|
|
569
|
+
registration,
|
|
570
|
+
measurement: {
|
|
571
|
+
id,
|
|
572
|
+
rect: measurement
|
|
573
|
+
}
|
|
571
574
|
});
|
|
572
575
|
scheduleFlush();
|
|
573
576
|
}
|
|
574
|
-
const handleResize = (entries) => {
|
|
577
|
+
const handleResize = (entries, source) => {
|
|
578
|
+
if (source !== observer) return;
|
|
575
579
|
for (const entry of entries) {
|
|
576
|
-
const
|
|
577
|
-
if (!
|
|
580
|
+
const registration = elementMap.get(entry.target);
|
|
581
|
+
if (!registration) continue;
|
|
578
582
|
const box = entry.borderBoxSize?.[0];
|
|
579
583
|
const layoutSize = box ? {
|
|
580
584
|
width: box.inlineSize,
|
|
@@ -583,7 +587,7 @@ function createMeasurementObserver(store, options = {}) {
|
|
|
583
587
|
width: entry.contentRect.width,
|
|
584
588
|
height: entry.contentRect.height
|
|
585
589
|
} : void 0;
|
|
586
|
-
pushMeasurement(entry.target,
|
|
590
|
+
pushMeasurement(entry.target, registration, layoutSize);
|
|
587
591
|
}
|
|
588
592
|
};
|
|
589
593
|
let observer = null;
|
|
@@ -594,8 +598,11 @@ function createMeasurementObserver(store, options = {}) {
|
|
|
594
598
|
}
|
|
595
599
|
return {
|
|
596
600
|
observe(element, target) {
|
|
597
|
-
elementMap.
|
|
601
|
+
const replacing = elementMap.has(element);
|
|
602
|
+
const registration = { target };
|
|
603
|
+
elementMap.set(element, registration);
|
|
598
604
|
getObserver(element).observe(element);
|
|
605
|
+
if (replacing) pushMeasurement(element, registration);
|
|
599
606
|
},
|
|
600
607
|
/**
|
|
601
608
|
* Re-measure an observed element immediately. ResizeObserver only fires
|
|
@@ -603,20 +610,19 @@ function createMeasurementObserver(store, options = {}) {
|
|
|
603
610
|
* a port moving within its node) need an explicit re-measure.
|
|
604
611
|
*/
|
|
605
612
|
measure(element) {
|
|
606
|
-
const
|
|
607
|
-
if (
|
|
613
|
+
const registration = elementMap.get(element);
|
|
614
|
+
if (registration) pushMeasurement(element, registration);
|
|
608
615
|
},
|
|
609
616
|
refresh(targets) {
|
|
610
617
|
const requested = targets ? new Set(targets) : null;
|
|
611
|
-
for (const [element,
|
|
618
|
+
for (const [element, registration] of elementMap) {
|
|
619
|
+
const { target } = registration;
|
|
612
620
|
const id = "appearanceId" in target ? target.appearanceId : "portName" in target ? `${target.nodeId}:${target.portName}` : "nodeId" in target ? target.nodeId : target.edgeId;
|
|
613
621
|
if (requested && !requested.has(element) && !requested.has(id)) continue;
|
|
614
|
-
pushMeasurement(element,
|
|
622
|
+
pushMeasurement(element, registration);
|
|
615
623
|
}
|
|
616
624
|
},
|
|
617
625
|
unobserve(element) {
|
|
618
|
-
const target = elementMap.get(element);
|
|
619
|
-
if (target && "appearanceId" in target) pendingMeasurements = pendingMeasurements.filter(({ id }) => id !== target.appearanceId);
|
|
620
626
|
elementMap.delete(element);
|
|
621
627
|
observer?.unobserve(element);
|
|
622
628
|
},
|
|
@@ -708,18 +714,18 @@ function attachViewportTransform(store, element, options = {}) {
|
|
|
708
714
|
}, promoteIdleMs);
|
|
709
715
|
};
|
|
710
716
|
writeTransform(prevViewport);
|
|
711
|
-
if (prevState
|
|
717
|
+
if (prevState === "panning") promote();
|
|
712
718
|
const subscription = store.subscribe((snapshot) => {
|
|
713
719
|
const context = snapshot.context;
|
|
714
720
|
if (context.viewport !== prevViewport) {
|
|
715
721
|
prevViewport = context.viewport;
|
|
716
722
|
writeTransform(context.viewport);
|
|
717
723
|
promote();
|
|
718
|
-
if (context.canvasState
|
|
724
|
+
if (context.canvasState !== "panning") scheduleClear();
|
|
719
725
|
}
|
|
720
726
|
if (context.canvasState !== prevState) {
|
|
721
727
|
prevState = context.canvasState;
|
|
722
|
-
if (prevState
|
|
728
|
+
if (prevState === "panning") promote();
|
|
723
729
|
else scheduleClear();
|
|
724
730
|
}
|
|
725
731
|
});
|
|
@@ -737,6 +743,7 @@ function attachInput(options) {
|
|
|
737
743
|
const keyboardTarget = options.keyboardTarget ?? "container";
|
|
738
744
|
const keyboardElement = keyboardTarget === "window" ? win : keyboardTarget === "container" ? container : keyboardTarget;
|
|
739
745
|
let capturedPointerId = null;
|
|
746
|
+
let pointerCaptureOwner = {};
|
|
740
747
|
let gestureContainerOffset = null;
|
|
741
748
|
let lastContainerOffset = null;
|
|
742
749
|
let lastClient = null;
|
|
@@ -886,6 +893,7 @@ function attachInput(options) {
|
|
|
886
893
|
container.setPointerCapture(info.pointerId);
|
|
887
894
|
} catch {}
|
|
888
895
|
capturedPointerId = info.pointerId;
|
|
896
|
+
pointerCaptureOwner = {};
|
|
889
897
|
gestureContainerOffset = lastContainerOffset ?? (() => {
|
|
890
898
|
const rect = container.getBoundingClientRect();
|
|
891
899
|
return {
|
|
@@ -895,15 +903,7 @@ function attachInput(options) {
|
|
|
895
903
|
})();
|
|
896
904
|
scheduleAutoPan();
|
|
897
905
|
}
|
|
898
|
-
if (effects.sessionEnded && capturedPointerId !== null)
|
|
899
|
-
try {
|
|
900
|
-
if (container.hasPointerCapture(capturedPointerId)) container.releasePointerCapture(capturedPointerId);
|
|
901
|
-
} catch {}
|
|
902
|
-
capturedPointerId = null;
|
|
903
|
-
gestureContainerOffset = null;
|
|
904
|
-
lastClient = null;
|
|
905
|
-
stopAutoPan();
|
|
906
|
-
}
|
|
906
|
+
if (effects.sessionEnded && capturedPointerId !== null) releaseCapturedPointer();
|
|
907
907
|
return effects;
|
|
908
908
|
}
|
|
909
909
|
function touchPoints() {
|
|
@@ -952,10 +952,11 @@ function attachInput(options) {
|
|
|
952
952
|
}
|
|
953
953
|
function releaseCapturedPointer() {
|
|
954
954
|
if (capturedPointerId === null) return;
|
|
955
|
+
const pointerId = capturedPointerId;
|
|
956
|
+
capturedPointerId = null;
|
|
955
957
|
try {
|
|
956
|
-
if (container.hasPointerCapture(
|
|
958
|
+
if (container.hasPointerCapture(pointerId)) container.releasePointerCapture(pointerId);
|
|
957
959
|
} catch {}
|
|
958
|
-
capturedPointerId = null;
|
|
959
960
|
gestureContainerOffset = null;
|
|
960
961
|
lastClient = null;
|
|
961
962
|
stopAutoPan();
|
|
@@ -1065,19 +1066,23 @@ function attachInput(options) {
|
|
|
1065
1066
|
}
|
|
1066
1067
|
function handleKey(kind) {
|
|
1067
1068
|
return (event) => {
|
|
1068
|
-
|
|
1069
|
+
const previousCaptureOwner = pointerCaptureOwner;
|
|
1070
|
+
const effects = runtime.send({
|
|
1069
1071
|
kind,
|
|
1070
1072
|
key: event.key,
|
|
1071
1073
|
editableTarget: isEditableTarget(event.target),
|
|
1072
1074
|
modifiers: modifiers(event)
|
|
1073
|
-
})
|
|
1075
|
+
});
|
|
1076
|
+
if (effects.sessionEnded && pointerCaptureOwner === previousCaptureOwner) releaseCapturedPointer();
|
|
1077
|
+
applyEffects(event, effects);
|
|
1074
1078
|
};
|
|
1075
1079
|
}
|
|
1076
1080
|
const onPointerDown = handlePointer("pointer.down");
|
|
1077
1081
|
const onPointerMove = handlePointer("pointer.move");
|
|
1078
1082
|
const onPointerUp = handlePointer("pointer.up");
|
|
1079
1083
|
const onPointerCancel = handlePointer("pointer.cancel");
|
|
1080
|
-
const onLostPointerCapture = () => {
|
|
1084
|
+
const onLostPointerCapture = (event) => {
|
|
1085
|
+
if (capturedPointerId === null || capturedPointerId !== event.pointerId) return;
|
|
1081
1086
|
stopAutoPan();
|
|
1082
1087
|
runtime.cancelSession();
|
|
1083
1088
|
capturedPointerId = null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@statelyai/flow-dom",
|
|
3
|
-
"version": "3.5.
|
|
3
|
+
"version": "3.5.3",
|
|
4
4
|
"description": "DOM-specific helpers for @statelyai/flow with core re-exports.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
},
|
|
28
28
|
"license": "MIT",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@statelyai/flow": "0.
|
|
30
|
+
"@statelyai/flow": "0.13.1"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@vitest/coverage-v8": "^4.1.0",
|