Skip to content

Commit eb594ef

Browse files
committed
Fixed the panning with touch
1 parent ef8fab2 commit eb594ef

File tree

2 files changed

+7
-49
lines changed

2 files changed

+7
-49
lines changed

src/components/editor/canvas.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,14 @@ export default function Canvas({
235235
edges={edges}
236236
nodeTypes={nodeTypes}
237237
nodes={nodes} // <-- This is the key change. We're now using the nodes directly which include the callbacks
238+
panOnDrag={true}
239+
panOnScroll={false}
238240
proOptions={proOptions}
239241
selectionOnDrag={true}
240242
snapGrid={[10, 10]}
241243
snapToGrid={showGrid}
244+
zoomOnPinch={true}
245+
zoomOnScroll={true}
242246
onConnect={onConnect}
243247
onEdgesChange={onEdgesChange}
244248
onInit={onInit}

src/components/editor/nodes/base-node.tsx

Lines changed: 3 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -299,57 +299,12 @@ export const BaseNode = memo(
299299
const resolvedUrl = resolveNodeUrl(data.url);
300300
const textAlign = textProps?.textAlign ?? "left";
301301

302-
const forwardTouchPointer = (
303-
event: React.PointerEvent<HTMLDivElement>,
304-
) => {
305-
if (event.pointerType !== "touch") {
306-
return;
307-
}
308-
309-
const nodeElement = containerRef.current;
310-
311-
if (!nodeElement) {
312-
return;
313-
}
314-
315-
const interactiveAncestor = (
316-
event.target as HTMLElement | null
317-
)?.closest("button, a, textarea, input");
318-
319-
if (interactiveAncestor) {
320-
return;
321-
}
322-
323-
const pointerInit: PointerEventInit = {
324-
bubbles: true,
325-
cancelable: true,
326-
pointerType: "touch",
327-
clientX: event.clientX,
328-
clientY: event.clientY,
329-
};
330-
331-
if (typeof PointerEvent === "function") {
332-
nodeElement.dispatchEvent(
333-
new PointerEvent("pointerdown", pointerInit),
334-
);
335-
} else {
336-
nodeElement.dispatchEvent(
337-
new MouseEvent("mousedown", {
338-
bubbles: true,
339-
cancelable: true,
340-
clientX: event.clientX,
341-
clientY: event.clientY,
342-
}),
343-
);
344-
}
345-
};
346-
347302
return (
348303
<div
349304
className={clsx(
350305
"h-full flex flex-col min-h-[16px]",
351306
resolvedDescriptionClass,
352-
"px-1 touch-none select-none", // Add consistent padding and ensure touch dragging propagates
307+
"px-1 ", // Add consistent padding
353308
// Text alignment horizontal
354309
textProps?.textAlign === "left" && "text-left",
355310
textProps?.textAlign === "center" && "text-center",
@@ -366,11 +321,10 @@ export const BaseNode = memo(
366321
textProps?.strikethrough && "line-through",
367322
)}
368323
onDoubleClick={handleDoubleClick}
369-
onPointerDownCapture={forwardTouchPointer}
370324
>
371325
<div
372326
className={clsx(
373-
"inline-flex w-full flex-wrap items-start gap-1 touch-none pointer-events-none select-none",
327+
"inline-flex w-full flex-wrap items-start gap-1",
374328
textAlign === "center" && "justify-center",
375329
textAlign === "right" && "justify-end",
376330
textAlign === "justify" && "justify-center",
@@ -383,7 +337,7 @@ export const BaseNode = memo(
383337
<IconButton
384338
disableRipple
385339
aria-label="Open link"
386-
className="pointer-events-auto select-none"
340+
className="pointer-events-auto"
387341
size="small"
388342
sx={{
389343
padding: "2px",

0 commit comments

Comments
 (0)