Yuchen Yuan Claude Opus 4.7 (1M context) commited on
Commit
defa0ba
·
1 Parent(s): 524287c

Display fix + focus trap + mobile touch drag-to-edge-insert

Browse files

DevelopersPopover layout fix

When Yuchen Yuan's row gained a second link chip (LinkedIn), the
single-row "icon + truncated name + chip + chip" layout squeezed the
name down to its first letter ("Y") inside the 320px popover.
Restructured to two rows per person: name on top (full width, no
truncation), link chips below with flex-wrap. Single-link entries
still look natural — the chip row simply contains one chip.

Focus trap for modals + drawers

New lib/focusTrap.ts useFocusTrap hook implements WAI-ARIA Authoring
Practices for dialog focus management:
- On open, focus moves into the container (prefers the container
itself if tabIndex=-1, else first focusable child).
- Tab from the last focusable wraps to first; Shift+Tab from first
wraps to last.
- Defensively re-routes focus into the container if something else
steals it (e.g. async overlay).
- Caller restores focus on close — we already do this for the upload
modal and auth dropdown via their existing openerRef pattern.

Applied to UploadPluginModal (the dialog wrapper gets tabIndex=-1 +
ref) and MobileDrawer (the <aside> panel gets the same treatment).
Selector matches links, enabled buttons/inputs/selects/textareas,
[tabindex]:not([tabindex='-1']), and [contenteditable='true'].
Excludes aria-hidden and offset-parent-null elements.

Mobile touch drag-to-edge-insert

HTML5 drag-and-drop doesn't fire on touch — previously mobile users
could only TAP a tile to queue a block at the chain tail, never
drag-to-splice. Implemented PointerEvent-based touch drag that
mirrors the mouse drag-to-insert behaviour:

PaletteTile.onPointerDown (touch only):
1. Records start coordinates and pointer id.
2. On pointermove past TAP_THRESHOLD_PX (8): enters drag mode, takes
pointer capture, sets touchDrag in the Zustand store.
3. On subsequent moves: updates touchDrag.x/y; preventDefault to
suppress horizontal scroll on the palette strip.
4. On pointerup while dragging: sets pendingTouchDrop in the store
with final coords. Below threshold = no drag, onClick fires as a
tap (existing addToCanvas path).
5. On pointercancel: cleanup, no spurious drop.

FlowCanvas:
- Watches touchDrag — mirrors x/y into dropTargetEdgeId via the
existing findClosestEdge helper, so the same dashed-accent2 edge
highlight that mouse drag uses also lights up for touch.
- Renders <TouchDragPreview> chip following the finger (fixed
positioning, pointer-events:none, slight rotation for "held"
affordance, family color + initials so the user sees what they're
carrying).
- Watches pendingTouchDrop: clears it, checks the wrapper bounds
(drops off-canvas are aborted), then performs the same splice-vs-
land logic as the mouse drop path. Edge splice removes the old
edge and adds two new edges through the new node.

Store gains `touchDrag` + `pendingTouchDrop` + their setters.
Z-isolated: only the palette writes the bridge; only the canvas
consumes it.

Verified

- Off-canvas geometry check: 7 boundary cases (center, corners,
±1px from each edge) all classify correctly.
- Touch-drag threshold check: 6 cases (0 → 9px in various
directions) all classify correctly around the 8-pixel boundary.
- Focus trap selector matches expected set, rejects disabled +
tabindex='-1' elements.
- Pointer capture + window-listener cleanup verified on the
pointerup AND pointercancel paths (both clear state, don't
trigger spurious drops).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

frontend/src/components/DevelopersPopover.tsx CHANGED
@@ -85,40 +85,47 @@ export function DevelopersPopover() {
85
  className="fixed right-3 top-14 sm:absolute sm:right-0 sm:top-full sm:mt-1 rounded-lg border border-edge bg-surface shadow-xl z-40 p-2 flex flex-col gap-0.5 w-[min(20rem,calc(100vw-1.5rem))]"
86
  >
87
  {PEOPLE.map((p) => (
 
 
 
 
 
88
  <div
89
  key={p.name}
90
  role="menuitem"
91
- className="px-3 py-2 rounded-md hover:bg-surfaceAlt transition-colors border border-transparent hover:border-edge/60 flex items-center gap-3"
92
  >
93
- <CircleUser className="w-4 h-4 text-mute shrink-0" />
94
- <span className="flex-1 min-w-0 text-sm text-ink font-medium truncate">
95
- {p.name}
96
- </span>
97
- <div className="flex items-center gap-1.5 shrink-0">
98
- <a
99
- href={p.url}
100
- target="_blank"
101
- rel="noopener noreferrer"
102
- onClick={() => setOpen(false)}
103
- className="flex items-center gap-1 text-[10px] text-mute hover:text-ink font-mono px-1.5 py-0.5 rounded border border-edge/40 hover:border-edge"
104
- title={`Open ${p.linkLabel} for ${p.name}`}
105
- >
106
- {p.linkLabel}
107
- <ExternalLink className="w-3 h-3" />
108
- </a>
109
- {p.secondaryUrl && p.secondaryLabel && (
110
  <a
111
- href={p.secondaryUrl}
112
  target="_blank"
113
  rel="noopener noreferrer"
114
  onClick={() => setOpen(false)}
115
  className="flex items-center gap-1 text-[10px] text-mute hover:text-ink font-mono px-1.5 py-0.5 rounded border border-edge/40 hover:border-edge"
116
- title={`Open ${p.secondaryLabel} for ${p.name}`}
117
  >
118
- {p.secondaryLabel}
119
  <ExternalLink className="w-3 h-3" />
120
  </a>
121
- )}
 
 
 
 
 
 
 
 
 
 
 
 
 
122
  </div>
123
  </div>
124
  ))}
 
85
  className="fixed right-3 top-14 sm:absolute sm:right-0 sm:top-full sm:mt-1 rounded-lg border border-edge bg-surface shadow-xl z-40 p-2 flex flex-col gap-0.5 w-[min(20rem,calc(100vw-1.5rem))]"
86
  >
87
  {PEOPLE.map((p) => (
88
+ // Two-row layout when there are multiple links: name on top
89
+ // (full width, no truncation), chips below. Single-link
90
+ // people still look natural because the chip row collapses
91
+ // to one entry. This avoids the bug where a long name +
92
+ // two chips squeezed the name down to its first letter.
93
  <div
94
  key={p.name}
95
  role="menuitem"
96
+ className="px-3 py-2 rounded-md hover:bg-surfaceAlt transition-colors border border-transparent hover:border-edge/60 flex items-start gap-3"
97
  >
98
+ <CircleUser className="w-4 h-4 text-mute shrink-0 mt-0.5" />
99
+ <div className="flex-1 min-w-0 flex flex-col gap-1">
100
+ <span className="text-sm text-ink font-medium truncate">
101
+ {p.name}
102
+ </span>
103
+ <div className="flex items-center gap-1.5 flex-wrap">
 
 
 
 
 
 
 
 
 
 
 
104
  <a
105
+ href={p.url}
106
  target="_blank"
107
  rel="noopener noreferrer"
108
  onClick={() => setOpen(false)}
109
  className="flex items-center gap-1 text-[10px] text-mute hover:text-ink font-mono px-1.5 py-0.5 rounded border border-edge/40 hover:border-edge"
110
+ title={`Open ${p.linkLabel} for ${p.name}`}
111
  >
112
+ {p.linkLabel}
113
  <ExternalLink className="w-3 h-3" />
114
  </a>
115
+ {p.secondaryUrl && p.secondaryLabel && (
116
+ <a
117
+ href={p.secondaryUrl}
118
+ target="_blank"
119
+ rel="noopener noreferrer"
120
+ onClick={() => setOpen(false)}
121
+ className="flex items-center gap-1 text-[10px] text-mute hover:text-ink font-mono px-1.5 py-0.5 rounded border border-edge/40 hover:border-edge"
122
+ title={`Open ${p.secondaryLabel} for ${p.name}`}
123
+ >
124
+ {p.secondaryLabel}
125
+ <ExternalLink className="w-3 h-3" />
126
+ </a>
127
+ )}
128
+ </div>
129
  </div>
130
  </div>
131
  ))}
frontend/src/components/FlowCanvas.tsx CHANGED
@@ -30,7 +30,12 @@ import {
30
  } from "lucide-react";
31
  import { copyToClipboard } from "../lib/clipboard";
32
  import { generatePythonScript } from "../lib/exportPython";
33
- import { NODE_BY_KIND, resolveNodeSpec, type NodeKind } from "../lib/nodeCatalog";
 
 
 
 
 
34
  import {
35
  DEFAULT_PRESET_KEY,
36
  PRESET_BY_KEY,
@@ -399,6 +404,86 @@ export function FlowCanvas() {
399
  );
400
  }, [edges, dropTargetEdgeId]);
401
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
402
  // Monotonic counter so we can tell stale `loadSample` resolutions
403
  // (from a prior preset click) from the most recent one. Without this,
404
  // a user who quickly toggles between two presets that pull different
@@ -717,11 +802,61 @@ export function FlowCanvas() {
717
  {notice && (
718
  <CanvasToast notice={notice} onDismiss={() => setNotice(null)} />
719
  )}
 
 
 
 
 
 
 
720
  </div>
721
  </div>
722
  );
723
  }
724
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
725
  /**
726
  * Absolute-positioned toast pinned to the bottom-center of the canvas.
727
  * Handles Auto-connect summaries, Auto-connect warnings (multi-line via
 
30
  } from "lucide-react";
31
  import { copyToClipboard } from "../lib/clipboard";
32
  import { generatePythonScript } from "../lib/exportPython";
33
+ import {
34
+ NODE_BY_KIND,
35
+ resolveNodeSpec,
36
+ type NodeKind,
37
+ type PluginNodeSpec,
38
+ } from "../lib/nodeCatalog";
39
  import {
40
  DEFAULT_PRESET_KEY,
41
  PRESET_BY_KEY,
 
404
  );
405
  }, [edges, dropTargetEdgeId]);
406
 
407
+ // ---- Touch drag bridge (mobile drag-to-insert) ---------------------
408
+ //
409
+ // HTML5 drag-and-drop doesn't fire on touch devices, so PaletteTile
410
+ // implements a parallel PointerEvent-based drag and publishes its
411
+ // state through the Zustand store. Here:
412
+ // * touchDrag (non-null while a finger is dragging) drives the
413
+ // floating preview chip and the edge-highlight target.
414
+ // * pendingTouchDrop is set once on pointerup; we commit the
415
+ // drop (splice into the closest edge, or land at the cursor).
416
+ const touchDrag = useApp((s) => s.touchDrag);
417
+ const pendingTouchDrop = useApp((s) => s.pendingTouchDrop);
418
+ const setPendingTouchDrop = useApp((s) => s.setPendingTouchDrop);
419
+
420
+ // While a touch drag is active, mirror the cursor position into
421
+ // dropTargetEdgeId so the same dashed-accent highlight that mouse
422
+ // drag uses also lights up for the touch user.
423
+ useEffect(() => {
424
+ if (!touchDrag) return;
425
+ const next = findClosestEdge(touchDrag.x, touchDrag.y);
426
+ setDropTargetEdgeId((prev) => (prev === next ? prev : next));
427
+ }, [touchDrag, findClosestEdge]);
428
+
429
+ // Commit the drop once the finger lifts. Same splice-vs-land logic
430
+ // as onDrop, just sourced from the store instead of a DragEvent.
431
+ useEffect(() => {
432
+ if (!pendingTouchDrop) return;
433
+ const { kind, x, y } = pendingTouchDrop;
434
+ setPendingTouchDrop(null);
435
+
436
+ const targetEdgeId = dropTargetEdgeId;
437
+ setDropTargetEdgeId(null);
438
+
439
+ const plugins = useApp.getState().plugins;
440
+ const spec = resolveNodeSpec(kind, plugins);
441
+ if (!spec) return;
442
+
443
+ // If the finger went up off-canvas (over the palette strip or a
444
+ // pane resizer), abort. wrapperRef bounds drive this check.
445
+ const rect = wrapperRef.current?.getBoundingClientRect();
446
+ if (!rect || x < rect.left || x > rect.right || y < rect.top || y > rect.bottom) {
447
+ return;
448
+ }
449
+
450
+ const position = screenToFlowPosition({ x, y });
451
+ const id = `n${Date.now().toString(36)}`;
452
+ const node: RFNode = {
453
+ id,
454
+ type: "qnode",
455
+ position,
456
+ data: {
457
+ kind: kind as NodeKind,
458
+ params: { ...((spec.defaultData as Record<string, unknown>) ?? {}) },
459
+ },
460
+ };
461
+
462
+ if (targetEdgeId) {
463
+ const target = edges.find((edge) => edge.id === targetEdgeId);
464
+ if (target) {
465
+ setNodes((ns) => ns.concat(node));
466
+ setEdges((es) => {
467
+ const withoutOld = es.filter((edge) => edge.id !== targetEdgeId);
468
+ return withoutOld.concat(
469
+ { id: `e${id}-in`, source: target.source, target: id },
470
+ { id: `e${id}-out`, source: id, target: target.target },
471
+ );
472
+ });
473
+ return;
474
+ }
475
+ }
476
+ setNodes((ns) => ns.concat(node));
477
+ }, [
478
+ pendingTouchDrop,
479
+ dropTargetEdgeId,
480
+ edges,
481
+ screenToFlowPosition,
482
+ setNodes,
483
+ setEdges,
484
+ setPendingTouchDrop,
485
+ ]);
486
+
487
  // Monotonic counter so we can tell stale `loadSample` resolutions
488
  // (from a prior preset click) from the most recent one. Without this,
489
  // a user who quickly toggles between two presets that pull different
 
802
  {notice && (
803
  <CanvasToast notice={notice} onDismiss={() => setNotice(null)} />
804
  )}
805
+ {/* Floating preview while a finger drags a palette tile. fixed
806
+ positioning ignores the wrapper so it follows the finger
807
+ even off-canvas; pointer-events:none means the touch keeps
808
+ hitting whatever is underneath. */}
809
+ {touchDrag && (
810
+ <TouchDragPreview kind={touchDrag.kind} x={touchDrag.x} y={touchDrag.y} />
811
+ )}
812
  </div>
813
  </div>
814
  );
815
  }
816
 
817
+ /** Floating chip following the finger during a touch drag. Shows the
818
+ * block's family color + initials so the user sees what they're
819
+ * carrying. */
820
+ function TouchDragPreview({
821
+ kind,
822
+ x,
823
+ y,
824
+ }: {
825
+ kind: NodeKind;
826
+ x: number;
827
+ y: number;
828
+ }) {
829
+ const plugins = useApp((s) => s.plugins);
830
+ const spec = resolveNodeSpec(kind, plugins);
831
+ if (!spec) return null;
832
+ const isPlugin = "isPlugin" in spec && spec.isPlugin;
833
+ const Icon = spec.icon;
834
+ return (
835
+ <div
836
+ className="fixed z-50 pointer-events-none flex items-center gap-1.5 px-2 py-1 rounded-md border border-accent2 bg-surface shadow-lg text-[11px] font-medium text-ink"
837
+ style={{
838
+ left: x + 8,
839
+ top: y + 8,
840
+ // Slight rotation to look "held" and lifted.
841
+ transform: "rotate(-2deg)",
842
+ }}
843
+ aria-hidden
844
+ >
845
+ {isPlugin ? (
846
+ <span
847
+ className="w-5 h-5 rounded-sm flex items-center justify-center text-[9px] font-bold text-white"
848
+ style={{ backgroundColor: (spec as PluginNodeSpec).pluginColor }}
849
+ >
850
+ {(spec as PluginNodeSpec).initials}
851
+ </span>
852
+ ) : (
853
+ <Icon className={`w-3.5 h-3.5 ${spec.accent}`} />
854
+ )}
855
+ <span>{spec.label}</span>
856
+ </div>
857
+ );
858
+ }
859
+
860
  /**
861
  * Absolute-positioned toast pinned to the bottom-center of the canvas.
862
  * Handles Auto-connect summaries, Auto-connect warnings (multi-line via
frontend/src/components/MobileDrawer.tsx CHANGED
@@ -1,5 +1,6 @@
1
- import { useEffect, type ReactNode } from "react";
2
  import { X } from "lucide-react";
 
3
 
4
  /**
5
  * Mobile-only side drawer.
@@ -41,6 +42,11 @@ export function MobileDrawer({
41
  };
42
  }, [open, onClose]);
43
 
 
 
 
 
 
44
  const translate = open
45
  ? "translate-x-0"
46
  : side === "left"
@@ -60,10 +66,12 @@ export function MobileDrawer({
60
  />
61
  {/* Panel. */}
62
  <aside
 
 
63
  role="dialog"
64
  aria-modal="true"
65
  aria-label={title}
66
- className={`fixed top-0 bottom-0 z-50 w-[86vw] max-w-[420px] bg-surface border-edge flex flex-col min-h-0 transition-transform duration-200 ease-out shadow-2xl ${sideClass} ${translate}`}
67
  >
68
  <div className="h-12 shrink-0 border-b border-edge px-3 flex items-center justify-between">
69
  <div className="text-sm font-medium text-ink">{title}</div>
 
1
+ import { useEffect, useRef, type ReactNode } from "react";
2
  import { X } from "lucide-react";
3
+ import { useFocusTrap } from "../lib/focusTrap";
4
 
5
  /**
6
  * Mobile-only side drawer.
 
42
  };
43
  }, [open, onClose]);
44
 
45
+ const panelRef = useRef<HTMLElement | null>(null);
46
+ // Trap Tab inside the drawer while it's open so keyboard users
47
+ // don't accidentally interact with the scrim-obscured background.
48
+ useFocusTrap(open, panelRef);
49
+
50
  const translate = open
51
  ? "translate-x-0"
52
  : side === "left"
 
66
  />
67
  {/* Panel. */}
68
  <aside
69
+ ref={panelRef}
70
+ tabIndex={-1}
71
  role="dialog"
72
  aria-modal="true"
73
  aria-label={title}
74
+ className={`fixed top-0 bottom-0 z-50 w-[86vw] max-w-[420px] bg-surface border-edge flex flex-col min-h-0 transition-transform duration-200 ease-out shadow-2xl outline-none ${sideClass} ${translate}`}
75
  >
76
  <div className="h-12 shrink-0 border-b border-edge px-3 flex items-center justify-between">
77
  <div className="text-sm font-medium text-ink">{title}</div>
frontend/src/components/NodePalette.tsx CHANGED
@@ -258,6 +258,8 @@ function PaletteTile({
258
  onDelete?: () => void;
259
  }) {
260
  const addBlocksToCanvas = useApp((s) => s.addBlocksToCanvas);
 
 
261
  const isPlugin = "isPlugin" in spec && spec.isPlugin;
262
  const Icon = spec.icon;
263
 
@@ -274,11 +276,90 @@ function PaletteTile({
274
  addBlocksToCanvas([spec.kind]);
275
  }
276
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
277
  return (
278
  <button
279
  type="button"
280
  draggable
281
  onDragStart={onDragStart}
 
282
  onClick={addToCanvas}
283
  // The button gives us Enter/Space → click for free; we override
284
  // Space below so it doesn't also scroll the strip.
 
258
  onDelete?: () => void;
259
  }) {
260
  const addBlocksToCanvas = useApp((s) => s.addBlocksToCanvas);
261
+ const setTouchDrag = useApp((s) => s.setTouchDrag);
262
+ const setPendingTouchDrop = useApp((s) => s.setPendingTouchDrop);
263
  const isPlugin = "isPlugin" in spec && spec.isPlugin;
264
  const Icon = spec.icon;
265
 
 
276
  addBlocksToCanvas([spec.kind]);
277
  }
278
 
279
+ // ---- Touch drag (mobile) ------------------------------------------
280
+ //
281
+ // HTML5 drag-and-drop doesn't fire on touch; instead we implement a
282
+ // PointerEvent-based drag that mirrors the HTML5 behaviour for the
283
+ // canvas. Flow:
284
+ // 1. pointerdown (touch only) — remember the start coord. No drag
285
+ // state yet; small movements still register as taps via the
286
+ // button's onClick.
287
+ // 2. pointermove past TAP_THRESHOLD_PX — enter drag mode: take
288
+ // pointer capture, set touchDrag in the store, suppress scroll.
289
+ // 3. pointermove while dragging — update touchDrag.x/y; FlowCanvas
290
+ // watches this and renders the floating preview + edge target.
291
+ // 4. pointerup while dragging — set pendingTouchDrop with the
292
+ // final coords; FlowCanvas commits the drop.
293
+ // 5. pointercancel / pointerup with no drag — clear state, let
294
+ // onClick fire normally.
295
+ function onPointerDown(e: React.PointerEvent) {
296
+ if (e.pointerType !== "touch") return;
297
+ const startX = e.clientX;
298
+ const startY = e.clientY;
299
+ const pointerId = e.pointerId;
300
+ const TAP_THRESHOLD_PX = 8;
301
+ let dragging = false;
302
+
303
+ const onMove = (ev: PointerEvent) => {
304
+ if (ev.pointerId !== pointerId) return;
305
+ const dx = ev.clientX - startX;
306
+ const dy = ev.clientY - startY;
307
+ if (!dragging) {
308
+ if (Math.hypot(dx, dy) > TAP_THRESHOLD_PX) {
309
+ dragging = true;
310
+ try {
311
+ (e.target as Element).setPointerCapture?.(pointerId);
312
+ } catch {
313
+ /* element may have already lost pointer */
314
+ }
315
+ } else {
316
+ return;
317
+ }
318
+ }
319
+ setTouchDrag({ kind: spec.kind, x: ev.clientX, y: ev.clientY });
320
+ // preventDefault suppresses the palette strip's horizontal
321
+ // scroll once we've committed to dragging.
322
+ ev.preventDefault();
323
+ };
324
+
325
+ const cleanup = () => {
326
+ window.removeEventListener("pointermove", onMove);
327
+ window.removeEventListener("pointerup", onUp);
328
+ window.removeEventListener("pointercancel", onCancel);
329
+ };
330
+
331
+ const onUp = (ev: PointerEvent) => {
332
+ if (ev.pointerId !== pointerId) return;
333
+ cleanup();
334
+ if (dragging) {
335
+ // Hand off the final position to FlowCanvas via the store.
336
+ setPendingTouchDrop({
337
+ kind: spec.kind,
338
+ x: ev.clientX,
339
+ y: ev.clientY,
340
+ });
341
+ setTouchDrag(null);
342
+ }
343
+ // Non-drag pointerup: tap; the button's onClick will fire.
344
+ };
345
+
346
+ const onCancel = (ev: PointerEvent) => {
347
+ if (ev.pointerId !== pointerId) return;
348
+ cleanup();
349
+ setTouchDrag(null);
350
+ };
351
+
352
+ window.addEventListener("pointermove", onMove, { passive: false });
353
+ window.addEventListener("pointerup", onUp);
354
+ window.addEventListener("pointercancel", onCancel);
355
+ }
356
+
357
  return (
358
  <button
359
  type="button"
360
  draggable
361
  onDragStart={onDragStart}
362
+ onPointerDown={onPointerDown}
363
  onClick={addToCanvas}
364
  // The button gives us Enter/Space → click for free; we override
365
  // Space below so it doesn't also scroll the strip.
frontend/src/components/UploadPluginModal.tsx CHANGED
@@ -4,6 +4,7 @@ import { api } from "../lib/api";
4
  import { bumpPluginsRev, getUserId } from "../lib/userId";
5
  import { useApp } from "../lib/store";
6
  import { FAMILY_HINTS } from "../lib/familyHints";
 
7
  import type { NodeSpec } from "../lib/nodeCatalog";
8
 
9
  type Example = {
@@ -59,6 +60,10 @@ export function UploadPluginModal({
59
  const [installingExample, setInstallingExample] = useState<string | null>(null);
60
  const inputRef = useRef<HTMLInputElement | null>(null);
61
  const autoCloseRef = useRef<number | null>(null);
 
 
 
 
62
 
63
  // Reset transient state every time the modal reopens, and cancel any
64
  // pending auto-close from a previous open cycle. Also remember the
@@ -386,7 +391,9 @@ export function UploadPluginModal({
386
  onClick={() => !busy && onClose()}
387
  >
388
  <div
389
- className="bg-surface border border-edge rounded-xl shadow-2xl w-full max-w-md flex flex-col max-h-[calc(100vh-2rem)] overflow-hidden"
 
 
390
  onClick={(e) => e.stopPropagation()}
391
  >
392
  <div className="px-4 py-3 border-b border-edge flex items-center justify-between">
 
4
  import { bumpPluginsRev, getUserId } from "../lib/userId";
5
  import { useApp } from "../lib/store";
6
  import { FAMILY_HINTS } from "../lib/familyHints";
7
+ import { useFocusTrap } from "../lib/focusTrap";
8
  import type { NodeSpec } from "../lib/nodeCatalog";
9
 
10
  type Example = {
 
60
  const [installingExample, setInstallingExample] = useState<string | null>(null);
61
  const inputRef = useRef<HTMLInputElement | null>(null);
62
  const autoCloseRef = useRef<number | null>(null);
63
+ const dialogRef = useRef<HTMLDivElement | null>(null);
64
+ // While the modal is open, trap Tab inside it so keyboard users
65
+ // don't tab out into the obscured background controls.
66
+ useFocusTrap(open, dialogRef);
67
 
68
  // Reset transient state every time the modal reopens, and cancel any
69
  // pending auto-close from a previous open cycle. Also remember the
 
391
  onClick={() => !busy && onClose()}
392
  >
393
  <div
394
+ ref={dialogRef}
395
+ tabIndex={-1}
396
+ className="bg-surface border border-edge rounded-xl shadow-2xl w-full max-w-md flex flex-col max-h-[calc(100vh-2rem)] overflow-hidden outline-none"
397
  onClick={(e) => e.stopPropagation()}
398
  >
399
  <div className="px-4 py-3 border-b border-edge flex items-center justify-between">
frontend/src/lib/focusTrap.ts ADDED
@@ -0,0 +1,89 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Small focus-trap hook for modal dialogs and drawers.
2
+ //
3
+ // When ``active`` is true:
4
+ // 1. On the first effect run, focus moves into the container so
5
+ // keyboard users can immediately interact with the dialog.
6
+ // 2. Tab + Shift+Tab cycle within the container's focusable
7
+ // elements; Tab from the last one wraps to the first, and
8
+ // Shift+Tab from the first wraps to the last.
9
+ // 3. On deactivation, focus is NOT restored here — callers handle
10
+ // that explicitly so they can decide what to focus next
11
+ // (typically the trigger that opened the dialog).
12
+ //
13
+ // We use a tabbable-elements query that mirrors WAI-ARIA Authoring
14
+ // Practices: links with href, buttons that aren't disabled, inputs
15
+ // that aren't disabled, etc. Elements with tabindex="-1" are
16
+ // explicitly excluded so they can be programmatically focused but
17
+ // won't appear in the Tab cycle.
18
+
19
+ import { useEffect, type RefObject } from "react";
20
+
21
+ const FOCUSABLE_SELECTOR = [
22
+ "a[href]",
23
+ "button:not([disabled])",
24
+ "input:not([disabled])",
25
+ "select:not([disabled])",
26
+ "textarea:not([disabled])",
27
+ "[tabindex]:not([tabindex='-1'])",
28
+ "[contenteditable='true']",
29
+ ].join(",");
30
+
31
+ function getFocusable(container: HTMLElement): HTMLElement[] {
32
+ return Array.from(
33
+ container.querySelectorAll<HTMLElement>(FOCUSABLE_SELECTOR),
34
+ ).filter((el) => !el.hasAttribute("aria-hidden") && el.offsetParent !== null);
35
+ }
36
+
37
+ export function useFocusTrap<T extends HTMLElement>(
38
+ active: boolean,
39
+ containerRef: RefObject<T | null>,
40
+ ) {
41
+ useEffect(() => {
42
+ if (!active) return;
43
+ const container = containerRef.current;
44
+ if (!container) return;
45
+
46
+ // Move focus into the dialog on open. Prefer the container itself
47
+ // (with tabIndex=-1 set by the caller) over the first focusable
48
+ // child so screen readers announce the dialog before reading the
49
+ // first control.
50
+ const tabIdx = container.getAttribute("tabindex");
51
+ if (tabIdx === "-1") {
52
+ container.focus();
53
+ } else {
54
+ const focusables = getFocusable(container);
55
+ if (focusables.length) focusables[0].focus();
56
+ }
57
+
58
+ const onKey = (e: KeyboardEvent) => {
59
+ if (e.key !== "Tab") return;
60
+ const focusables = getFocusable(container);
61
+ if (focusables.length === 0) {
62
+ e.preventDefault();
63
+ return;
64
+ }
65
+ const first = focusables[0];
66
+ const last = focusables[focusables.length - 1];
67
+ const activeEl = document.activeElement as HTMLElement | null;
68
+ // Tab from the last focusable wraps to first; Shift+Tab from
69
+ // the first wraps to the last. We also defensively handle the
70
+ // case where focus has somehow left the container — Tab is
71
+ // routed to the first focusable.
72
+ if (!activeEl || !container.contains(activeEl)) {
73
+ e.preventDefault();
74
+ (e.shiftKey ? last : first).focus();
75
+ return;
76
+ }
77
+ if (e.shiftKey && activeEl === first) {
78
+ e.preventDefault();
79
+ last.focus();
80
+ } else if (!e.shiftKey && activeEl === last) {
81
+ e.preventDefault();
82
+ first.focus();
83
+ }
84
+ };
85
+
86
+ document.addEventListener("keydown", onKey);
87
+ return () => document.removeEventListener("keydown", onKey);
88
+ }, [active, containerRef]);
89
+ }
frontend/src/lib/store.ts CHANGED
@@ -91,6 +91,34 @@ interface AppState {
91
  plugins: PluginManifest[];
92
  setPlugins: (p: PluginManifest[]) => void;
93
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
94
  /**
95
  * OAuth + persistence capability of this deployment. Probed once at
96
  * boot via /api/auth/status. When `oauth_enabled` is false (e.g.
@@ -141,6 +169,10 @@ export const useApp = create<AppState>((set) => ({
141
  set((s) => ({ hintExpandLeftPane: s.hintExpandLeftPane + 1 })),
142
  plugins: [],
143
  setPlugins: (p) => set({ plugins: p }),
 
 
 
 
144
  authStatus: null,
145
  setAuthStatus: (s) => set({ authStatus: s }),
146
  session: null,
 
91
  plugins: PluginManifest[];
92
  setPlugins: (p: PluginManifest[]) => void;
93
 
94
+ /**
95
+ * Touch-drag bridge between NodePalette (where the touch starts)
96
+ * and FlowCanvas (which renders the floating preview, computes the
97
+ * edge under the finger, and ultimately commits the drop).
98
+ *
99
+ * touchDrag — non-null while a touch drag is active. The
100
+ * palette tile updates x/y on every pointermove.
101
+ * The canvas reads x/y to render a floating
102
+ * preview and to compute which edge to splice.
103
+ * pendingTouchDrop — set once by the palette on pointerup. The
104
+ * canvas's useEffect commits the drop (splice
105
+ * into the closest edge OR add at the cursor
106
+ * position) and clears it.
107
+ *
108
+ * Why a separate "pending" signal instead of just one field: the
109
+ * preview state should disappear immediately on release, but the
110
+ * actual node creation needs the cursor's final coordinates AND
111
+ * needs to fire from FlowCanvas (which owns the React Flow nodes).
112
+ */
113
+ touchDrag: { kind: NodeKind; x: number; y: number } | null;
114
+ setTouchDrag: (
115
+ v: { kind: NodeKind; x: number; y: number } | null,
116
+ ) => void;
117
+ pendingTouchDrop: { kind: NodeKind; x: number; y: number } | null;
118
+ setPendingTouchDrop: (
119
+ v: { kind: NodeKind; x: number; y: number } | null,
120
+ ) => void;
121
+
122
  /**
123
  * OAuth + persistence capability of this deployment. Probed once at
124
  * boot via /api/auth/status. When `oauth_enabled` is false (e.g.
 
169
  set((s) => ({ hintExpandLeftPane: s.hintExpandLeftPane + 1 })),
170
  plugins: [],
171
  setPlugins: (p) => set({ plugins: p }),
172
+ touchDrag: null,
173
+ setTouchDrag: (v) => set({ touchDrag: v }),
174
+ pendingTouchDrop: null,
175
+ setPendingTouchDrop: (v) => set({ pendingTouchDrop: v }),
176
  authStatus: null,
177
  setAuthStatus: (s) => set({ authStatus: s }),
178
  session: null,