@duct-sdk/sdk 0.3.0 → 0.3.1

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/CHANGELOG.md CHANGED
@@ -2,11 +2,19 @@
2
2
 
3
3
  Public release notes for the Duct SDK. Versioning follows [semver](https://semver.org).
4
4
 
5
+ ## [0.3.1] — 2026-06-09
6
+
7
+ ### Added
8
+ - Draggable open panel with viewport clamping — panel stays on-screen after free-drag via top handle
9
+
10
+ ### Fixed
11
+ - Panel position clamped to viewport bounds on drag end
12
+
5
13
  ## [0.3.0] — 2026-06-09
6
14
 
7
15
  ### Added
8
16
  - **Shell size presets** — `widget.preset` and the `<DuctShell preset>` prop accept `'tall'` (vertical rectangle, default), `'square'` (Copilot-style), or `'large'`. Dimensions resolve from a single source of truth (`SHELL_PRESET_DIMENSIONS`, `resolveShellDimensions()`), replacing ad-hoc `width`/`height` guessing. Raw `width`/`height` still work as an override.
9
- - **Draggable launcher** — the floating bubble can be dragged anywhere on the page (free drop); position is persisted per shell in `localStorage`. `position` now only sets the starting corner. Disable with `draggable={false}`.
17
+ - **Draggable launcher and panel** — the floating bubble can be dragged anywhere on the page (free drop, persisted per shell), and the opened panel can also be moved via its top handle. `position` now only sets the starting corner. Disable with `draggable={false}`.
10
18
  - **Theme-aware bubble** — new `<DuctShell theme>` prop (`'light' | 'dark' | 'system'`, default `'system'`); the launcher chrome adapts to light/dark instead of a hardcoded dark circle.
11
19
  - `DUCT_PANEL_SIZE` postMessage now carries `preset`, so a shell's manifest can drive panel sizing on the host.
12
20
 
package/README.md CHANGED
@@ -58,7 +58,7 @@ export default function Layout({ children }) {
58
58
  <DuctShell
59
59
  shellId={process.env.NEXT_PUBLIC_DUCT_SHELL_ID}
60
60
  preset="tall" // "tall" | "square" | "large"
61
- position="bottom-right" // starting corner; the bubble is draggable
61
+ position="bottom-right" // starting corner; bubble + opened panel are draggable
62
62
  theme="system" // "system" | "light" | "dark"
63
63
  />
64
64
  </>
@@ -66,7 +66,7 @@ export default function Layout({ children }) {
66
66
  }
67
67
  ```
68
68
 
69
- The launcher bubble is **draggable** (drop it anywhere — position persists per shell) and **theme-aware**. Use `preset`
69
+ The launcher bubble and opened panel are **draggable** (drop the bubble anywhere — position persists per shell) and **theme-aware**. Use `preset`
70
70
  to size the panel, or pass `panelWidth`/`panelHeight` for a custom size. Set `draggable={false}` to pin the bubble.
71
71
 
72
72
  ---
@@ -2,7 +2,7 @@
2
2
  // @duct/sdk/next — DuctShell
3
3
  // The Next.js adapter shares the exact same client implementation as the
4
4
  // React adapter (floating launcher + iframe panel + postMessage bridge,
5
- // draggable bubble, size presets, theme-aware chrome). Re-export to avoid
5
+ // draggable bubble and panel, size presets, theme-aware chrome). Re-export to avoid
6
6
  // drift between the two adapters.
7
7
  // ============================================================
8
8
  "use client";
@@ -3,7 +3,7 @@
3
3
  // Floating launcher + iframe panel with postMessage bridge
4
4
  // ============================================================
5
5
  "use client";
6
- import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
6
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
7
7
  import React, { useEffect, useRef, useCallback, useState, } from "react";
8
8
  import { resolveShellDimensions, } from "../../core/types.js";
9
9
  /**
@@ -62,6 +62,18 @@ function clampBubble(x, y) {
62
62
  y: Math.min(Math.max(margin, y), Math.max(margin, maxY)),
63
63
  };
64
64
  }
65
+ /** Keep a dragged panel visible inside the viewport. */
66
+ function clampPanel(x, y, width, height) {
67
+ if (typeof window === "undefined")
68
+ return { x, y };
69
+ const margin = 8;
70
+ const maxX = window.innerWidth - width - margin;
71
+ const maxY = window.innerHeight - height - margin;
72
+ return {
73
+ x: Math.min(Math.max(margin, x), Math.max(margin, maxX)),
74
+ y: Math.min(Math.max(margin, y), Math.max(margin, maxY)),
75
+ };
76
+ }
65
77
  /**
66
78
  * DuctShell — a self-contained floating launcher button + chat panel.
67
79
  *
@@ -85,6 +97,7 @@ function clampBubble(x, y) {
85
97
  */
86
98
  export function DuctShell({ shellId, userContext, onTokenRequest, onNavigate, onPageContext, open, onOpenChange, defaultOpen = false, shellHost = DUCT_SHELL_HOST_DEFAULT, position = "bottom-right", preset, theme = "system", draggable = true, panelWidth = 420, panelHeight = 640, style, className, launcherIconSrc, readyCheck = false, }) {
87
99
  const iframeRef = useRef(null);
100
+ const panelRef = useRef(null);
88
101
  const [isReady, setIsReady] = useState(false);
89
102
  const [isOpen, setIsOpen] = useState(defaultOpen);
90
103
  const [isAnimating, setIsAnimating] = useState(false);
@@ -98,6 +111,10 @@ export function DuctShell({ shellId, userContext, onTokenRequest, onNavigate, on
98
111
  const [bubblePos, setBubblePos] = useState(null);
99
112
  const [isDragging, setIsDragging] = useState(false);
100
113
  const dragState = useRef(null);
114
+ // Open panel can also be dragged after launch. null = anchor near bubble/default corner.
115
+ const [panelPos, setPanelPos] = useState(null);
116
+ const [isPanelDragging, setIsPanelDragging] = useState(false);
117
+ const panelDragState = useRef(null);
101
118
  // Resolve theme for the launcher chrome (light/dark surface).
102
119
  const [isDarkChrome, setIsDarkChrome] = useState(theme === "dark");
103
120
  // Shell liveness — only checked when readyCheck=true
@@ -356,6 +373,28 @@ export function DuctShell({ shellId, userContext, onTokenRequest, onNavigate, on
356
373
  window.removeEventListener("pointerup", onUp);
357
374
  };
358
375
  }, [isDragging, bubblePos, openPanel, shellId]);
376
+ // Free-drag the open panel using a top handle. The handle sits outside the
377
+ // iframe so dragging works without relying on iframe internals.
378
+ useEffect(() => {
379
+ if (!isPanelDragging)
380
+ return;
381
+ const onMove = (e) => {
382
+ const st = panelDragState.current;
383
+ if (!st)
384
+ return;
385
+ setPanelPos(clampPanel(e.clientX - st.dx, e.clientY - st.dy, st.width, st.height));
386
+ };
387
+ const onUp = () => {
388
+ setIsPanelDragging(false);
389
+ panelDragState.current = null;
390
+ };
391
+ window.addEventListener("pointermove", onMove);
392
+ window.addEventListener("pointerup", onUp);
393
+ return () => {
394
+ window.removeEventListener("pointermove", onMove);
395
+ window.removeEventListener("pointerup", onUp);
396
+ };
397
+ }, [isPanelDragging]);
359
398
  const onBubblePointerDown = useCallback((e) => {
360
399
  if (!draggable)
361
400
  return;
@@ -365,6 +404,19 @@ export function DuctShell({ shellId, userContext, onTokenRequest, onNavigate, on
365
404
  setBubblePos((prev) => prev ?? clampBubble(rect.left, rect.top));
366
405
  setIsDragging(true);
367
406
  }, [draggable]);
407
+ const onPanelPointerDown = useCallback((e) => {
408
+ if (!draggable || !panelRef.current)
409
+ return;
410
+ const rect = panelRef.current.getBoundingClientRect();
411
+ panelDragState.current = {
412
+ dx: e.clientX - rect.left,
413
+ dy: e.clientY - rect.top,
414
+ width: rect.width,
415
+ height: rect.height,
416
+ };
417
+ setPanelPos(clampPanel(rect.left, rect.top, rect.width, rect.height));
418
+ setIsPanelDragging(true);
419
+ }, [draggable]);
368
420
  if (!shellId) {
369
421
  console.error("[DuctShell] shellId prop is required");
370
422
  return null;
@@ -409,7 +461,7 @@ export function DuctShell({ shellId, userContext, onTokenRequest, onNavigate, on
409
461
  })();
410
462
  const panelStyle = {
411
463
  position: "fixed",
412
- ...panelAnchor,
464
+ ...(panelPos ? { left: `${panelPos.x}px`, top: `${panelPos.y}px` } : panelAnchor),
413
465
  width: `min(${widthVal}, calc(100vw - 32px))`,
414
466
  height: `min(${heightVal}, calc(100dvh - 96px))`,
415
467
  zIndex: 9998,
@@ -418,7 +470,7 @@ export function DuctShell({ shellId, userContext, onTokenRequest, onNavigate, on
418
470
  boxShadow: "0 24px 64px rgba(0,0,0,0.18), 0 8px 24px rgba(0,0,0,0.10)",
419
471
  opacity: panelOpen && !isAnimating ? 1 : 0,
420
472
  transform: panelOpen && !isAnimating ? "translateY(0)" : "translateY(12px)",
421
- transition: "opacity 220ms cubic-bezier(0.16,1,0.3,1), transform 0.25s cubic-bezier(0.16, 1, 0.3, 1)",
473
+ transition: isPanelDragging ? "none" : "opacity 220ms cubic-bezier(0.16,1,0.3,1), transform 0.25s cubic-bezier(0.16, 1, 0.3, 1)",
422
474
  pointerEvents: panelOpen ? "auto" : "none",
423
475
  visibility: panelVisible ? "visible" : "hidden",
424
476
  ...style,
@@ -460,12 +512,21 @@ export function DuctShell({ shellId, userContext, onTokenRequest, onNavigate, on
460
512
  e.currentTarget.style.transform = "scale(1.07)";
461
513
  }, onMouseLeave: (e) => {
462
514
  e.currentTarget.style.transform = "scale(1)";
463
- }, children: !iconLoadFailed ? (_jsx("img", { src: currentIconSrc, alt: "Duct", width: 30, height: 30, draggable: false, onError: handleIconError, style: { width: "30px", height: "30px", objectFit: "contain", pointerEvents: "none" } })) : (_jsx("svg", { width: "28", height: "28", viewBox: "0 0 24 24", fill: "none", "aria-hidden": "true", children: _jsx("path", { d: "M18 12c0-3.3-2.2-5.5-5.5-5.5C9 6.5 7 8.7 7 12s2 5.5 5.5 5.5c2 0 3.6-.8 4.6-2.2l-2.2-1.6c-.6.8-1.4 1.3-2.4 1.3-1.6 0-2.8-1.2-2.8-3s1.2-3 2.8-3c1 0 1.8.5 2.3 1.3L18 12z", fill: isDarkChrome ? "#E8622A" : "#E8622A" }) })) })), _jsx("div", { style: panelStyle, "data-duct-shell": shellId, children: _jsx("iframe", { ref: iframeRef, src: shellUrl, title: "Duct Shell", sandbox: "allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox", allow: "clipboard-write", referrerPolicy: "no-referrer-when-downgrade", style: {
464
- width: "100%",
465
- height: "100%",
466
- border: "none",
467
- display: "block",
468
- } }) })] }));
515
+ }, children: !iconLoadFailed ? (_jsx("img", { src: currentIconSrc, alt: "Duct", width: 30, height: 30, draggable: false, onError: handleIconError, style: { width: "30px", height: "30px", objectFit: "contain", pointerEvents: "none" } })) : (_jsx("svg", { width: "28", height: "28", viewBox: "0 0 24 24", fill: "none", "aria-hidden": "true", children: _jsx("path", { d: "M18 12c0-3.3-2.2-5.5-5.5-5.5C9 6.5 7 8.7 7 12s2 5.5 5.5 5.5c2 0 3.6-.8 4.6-2.2l-2.2-1.6c-.6.8-1.4 1.3-2.4 1.3-1.6 0-2.8-1.2-2.8-3s1.2-3 2.8-3c1 0 1.8.5 2.3 1.3L18 12z", fill: isDarkChrome ? "#E8622A" : "#E8622A" }) })) })), _jsxs("div", { ref: panelRef, style: panelStyle, "data-duct-shell": shellId, children: [_jsx("div", { onPointerDown: onPanelPointerDown, "aria-hidden": "true", title: "Drag Duct Shell", style: {
516
+ position: "absolute",
517
+ top: 0,
518
+ left: 0,
519
+ right: 44,
520
+ height: 44,
521
+ zIndex: 2,
522
+ cursor: isPanelDragging ? "grabbing" : "grab",
523
+ touchAction: "none",
524
+ } }), _jsx("iframe", { ref: iframeRef, src: shellUrl, title: "Duct Shell", sandbox: "allow-scripts allow-same-origin allow-forms allow-popups allow-popups-to-escape-sandbox", allow: "clipboard-write", referrerPolicy: "no-referrer-when-downgrade", style: {
525
+ width: "100%",
526
+ height: "100%",
527
+ border: "none",
528
+ display: "block",
529
+ } })] })] }));
469
530
  }
470
531
  /**
471
532
  * Headless launch button — use when you want a custom trigger.
@@ -36,7 +36,7 @@ export function DuctShellEmbed() {
36
36
  position="${position}"
37
37
  preset="${preset}"
38
38
  // Size preset: "tall" (vertical), "square" (Copilot-style), or "large".
39
- // The bubble is draggable; \`position\` only sets the starting corner.
39
+ // The bubble and opened panel are draggable; \`position\` only sets the starting corner.
40
40
  // Optional: provide user context (not sensitive — this is metadata for the shell UI)
41
41
  // userContext={{ theme: "light", locale: "en-US" }}
42
42
  onTokenRequest={async (shellId) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duct-sdk/sdk",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "type": "module",
5
5
  "description": "Duct SDK — A shell (like terminal) that knows when to talk, when to show, and when to hand off.",
6
6
  "main": "dist/index.js",