@octaviaflow/core 3.0.18-beta.11 → 3.0.18-beta.12

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
@@ -29797,6 +29797,9 @@ function createHandleRegistry() {
29797
29797
  resolve(nodeId, type, handleId) {
29798
29798
  return map.get(key(nodeId, type, handleId));
29799
29799
  },
29800
+ all() {
29801
+ return Array.from(map.values());
29802
+ },
29800
29803
  subscribe(listener) {
29801
29804
  listeners.add(listener);
29802
29805
  return () => {
@@ -30192,10 +30195,12 @@ function Handle({
30192
30195
  type,
30193
30196
  side: position,
30194
30197
  index,
30195
- total
30198
+ total,
30199
+ canStart,
30200
+ canEnd
30196
30201
  });
30197
30202
  return dispose;
30198
- }, [registry, node.id, id, type, position, index, total]);
30203
+ }, [registry, node.id, id, type, position, index, total, canStart, canEnd]);
30199
30204
  const handlePointerDown = (e) => {
30200
30205
  if (!canStart) return;
30201
30206
  e.stopPropagation();
@@ -31331,49 +31336,54 @@ function FlowCanvas2(props) {
31331
31336
  }
31332
31337
  const c = connRef.current;
31333
31338
  if (c && c.pointerId === e.pointerId) {
31334
- let handleEl = null;
31335
- if (typeof document !== "undefined") {
31336
- const stack = document.elementsFromPoint(e.clientX, e.clientY);
31337
- for (const el of stack) {
31338
- const candidate = el.closest(
31339
- "[data-handle-id]"
31340
- );
31341
- if (!candidate) continue;
31342
- if (candidate.dataset.handleNodeId === c.from.nodeId) continue;
31343
- handleEl = candidate;
31344
- break;
31339
+ const rect = containerRef.current?.getBoundingClientRect();
31340
+ const flowPos = rect ? screenToFlow({ x: e.clientX - rect.left, y: e.clientY - rect.top }, vp) : { x: 0, y: 0 };
31341
+ const snapRadius = 26 / Math.max(0.1, vp.zoom);
31342
+ let bestDesc = null;
31343
+ let bestDist = snapRadius;
31344
+ for (const desc of handleRegistry.all()) {
31345
+ if (desc.nodeId === c.from.nodeId) continue;
31346
+ if (desc.type === c.from.handleType) continue;
31347
+ if (!desc.canEnd) continue;
31348
+ const targetNode = nodesRef.current.find((n) => n.id === desc.nodeId);
31349
+ if (!targetNode || targetNode.hidden) continue;
31350
+ const centre = handleCentre(targetNode, desc.side, desc.index, desc.total);
31351
+ const dist = Math.hypot(centre.x - flowPos.x, centre.y - flowPos.y);
31352
+ if (dist < bestDist) {
31353
+ bestDist = dist;
31354
+ bestDesc = desc;
31345
31355
  }
31346
31356
  }
31347
31357
  let connection = null;
31348
31358
  let connectedTo;
31349
- if (handleEl) {
31350
- const targetNodeId = handleEl.dataset.handleNodeId;
31351
- const targetHandleId = handleEl.dataset.handleId;
31352
- const targetType = handleEl.dataset.handleType;
31353
- const connectableEnd = handleEl.dataset.handleConnectableEnd === "true";
31354
- if (connectableEnd && (targetNodeId !== c.from.nodeId || targetHandleId !== c.from.handleId) && targetType !== c.from.handleType) {
31355
- const source = c.from.handleType === "source" ? c.from : { nodeId: targetNodeId, handleId: targetHandleId, handleType: "source" };
31356
- const target2 = c.from.handleType === "target" ? c.from : { nodeId: targetNodeId, handleId: targetHandleId, handleType: "target" };
31357
- connection = {
31358
- source: source.nodeId,
31359
- sourceHandle: source.handleId,
31360
- target: target2.nodeId,
31361
- targetHandle: target2.handleId
31362
- };
31363
- connectedTo = {
31364
- nodeId: targetNodeId,
31365
- handleId: targetHandleId,
31366
- handleType: targetType
31367
- };
31368
- const validator = isValidConnectionRef.current;
31369
- if (validator && !validator(connection)) {
31370
- connection = null;
31371
- connectedTo = void 0;
31372
- }
31359
+ if (bestDesc) {
31360
+ const source = c.from.handleType === "source" ? c.from : {
31361
+ nodeId: bestDesc.nodeId,
31362
+ handleId: bestDesc.handleId,
31363
+ handleType: "source"
31364
+ };
31365
+ const target2 = c.from.handleType === "target" ? c.from : {
31366
+ nodeId: bestDesc.nodeId,
31367
+ handleId: bestDesc.handleId,
31368
+ handleType: "target"
31369
+ };
31370
+ connection = {
31371
+ source: source.nodeId,
31372
+ sourceHandle: source.handleId,
31373
+ target: target2.nodeId,
31374
+ targetHandle: target2.handleId
31375
+ };
31376
+ connectedTo = {
31377
+ nodeId: bestDesc.nodeId,
31378
+ handleId: bestDesc.handleId,
31379
+ handleType: bestDesc.type
31380
+ };
31381
+ const validator = isValidConnectionRef.current;
31382
+ if (validator && !validator(connection)) {
31383
+ connection = null;
31384
+ connectedTo = void 0;
31373
31385
  }
31374
31386
  }
31375
- const rect = containerRef.current?.getBoundingClientRect();
31376
- const flowPos = rect ? screenToFlow({ x: e.clientX - rect.left, y: e.clientY - rect.top }, vp) : { x: 0, y: 0 };
31377
31387
  const endState = {
31378
31388
  cancelled: !connection,
31379
31389
  position: { x: e.clientX, y: e.clientY },