@duct-sdk/sdk 0.4.1 → 0.4.2

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,6 +2,11 @@
2
2
 
3
3
  Public release notes for the Duct SDK. Versioning follows [semver](https://semver.org).
4
4
 
5
+ ## [0.4.2] — 2026-07-03
6
+
7
+ ### Fixed
8
+ - **`DuctShell` drag position after handoff** — panel drag position is now persisted in `localStorage` alongside the launcher bubble, so deeplink/sign-in navigations no longer reset a repositioned embed. Legacy `{ x, y }` bubble-only storage remains supported.
9
+
5
10
  ## [0.4.1] — 2026-07-03
6
11
 
7
12
  ### Added
@@ -116,6 +116,46 @@ function ShellDragHandle({ onPointerDown, isDragging, isDark, label = "Drag to m
116
116
  : "0 8px 24px rgba(12,11,9,0.12)",
117
117
  }, children: label }))] }));
118
118
  }
119
+ function shellLayoutStorageKey(shellId) {
120
+ return `duct-shell-pos:${shellId}`;
121
+ }
122
+ /** Read persisted bubble/panel positions (supports legacy `{ x, y }` bubble-only blobs). */
123
+ function readStoredShellLayout(shellId) {
124
+ if (typeof window === "undefined")
125
+ return {};
126
+ try {
127
+ const raw = window.localStorage.getItem(shellLayoutStorageKey(shellId));
128
+ if (!raw)
129
+ return {};
130
+ const parsed = JSON.parse(raw);
131
+ if (!parsed || typeof parsed !== "object")
132
+ return {};
133
+ if ("x" in parsed && "y" in parsed) {
134
+ const legacy = parsed;
135
+ if (typeof legacy.x === "number" && typeof legacy.y === "number") {
136
+ return { bubble: { x: legacy.x, y: legacy.y } };
137
+ }
138
+ }
139
+ const layout = parsed;
140
+ const out = {};
141
+ if (layout.bubble && typeof layout.bubble.x === "number" && typeof layout.bubble.y === "number") {
142
+ out.bubble = layout.bubble;
143
+ }
144
+ if (layout.panel && typeof layout.panel.x === "number" && typeof layout.panel.y === "number") {
145
+ out.panel = layout.panel;
146
+ }
147
+ return out;
148
+ }
149
+ catch {
150
+ return {};
151
+ }
152
+ }
153
+ function writeStoredShellLayout(shellId, layout) {
154
+ try {
155
+ window.localStorage.setItem(shellLayoutStorageKey(shellId), JSON.stringify(layout));
156
+ }
157
+ catch { /* ignore quota / private mode */ }
158
+ }
119
159
  /** Keep a dragged panel visible inside the viewport. */
120
160
  function clampPanel(x, y, width, height) {
121
161
  if (typeof window === "undefined")
@@ -407,21 +447,35 @@ export function DuctShell({ shellId, userContext, onTokenRequest, onNavigate, on
407
447
  mq.addEventListener("change", handler);
408
448
  return () => mq.removeEventListener("change", handler);
409
449
  }, [theme]);
410
- // Restore a previously dragged bubble position.
450
+ // Restore bubble position saved from a prior visit (survives deeplink handoff navigations).
411
451
  useEffect(() => {
412
452
  if (!draggable || typeof window === "undefined")
413
453
  return;
414
- try {
415
- const raw = window.localStorage.getItem(`duct-shell-pos:${shellId}`);
416
- if (raw) {
417
- const parsed = JSON.parse(raw);
418
- if (typeof parsed.x === "number" && typeof parsed.y === "number") {
419
- setBubblePos(clampBubble(parsed.x, parsed.y));
420
- }
421
- }
454
+ const layout = readStoredShellLayout(shellId);
455
+ if (layout.bubble) {
456
+ setBubblePos(clampBubble(layout.bubble.x, layout.bubble.y));
422
457
  }
423
- catch { /* ignore corrupt storage */ }
424
458
  }, [shellId, draggable]);
459
+ // Restore or re-clamp panel position when dimensions change (e.g. manifest widget preset).
460
+ useEffect(() => {
461
+ if (!draggable || typeof window === "undefined")
462
+ return;
463
+ const dims = resolveShellDimensions({
464
+ preset: dynamicPreset ?? preset,
465
+ width: dynamicWidth ?? panelWidth,
466
+ height: dynamicHeight ?? panelHeight,
467
+ });
468
+ const w = typeof dims.width === "number" ? dims.width : panelWidth;
469
+ const h = typeof dims.height === "number" ? dims.height : panelHeight;
470
+ setPanelPos((prev) => {
471
+ if (prev)
472
+ return clampPanel(prev.x, prev.y, w, h);
473
+ const stored = readStoredShellLayout(shellId).panel;
474
+ if (!stored)
475
+ return null;
476
+ return clampPanel(stored.x, stored.y, w, h);
477
+ });
478
+ }, [shellId, draggable, dynamicPreset, preset, dynamicWidth, panelWidth, dynamicHeight, panelHeight]);
425
479
  // Launcher bubble: pointer stays default until the user actually drags (4px threshold).
426
480
  // A tap opens; a drag repositions — no separate handle or grab cursor on hover.
427
481
  const onBubblePointerDown = useCallback((e) => {
@@ -471,10 +525,7 @@ export function DuctShell({ shellId, userContext, onTokenRequest, onNavigate, on
471
525
  const pos = finalPos ?? bubbleDragPending.current;
472
526
  if (pos) {
473
527
  setBubblePos(pos);
474
- try {
475
- window.localStorage.setItem(`duct-shell-pos:${shellId}`, JSON.stringify(pos));
476
- }
477
- catch { /* ignore */ }
528
+ writeStoredShellLayout(shellId, { bubble: pos });
478
529
  }
479
530
  setPanelPos(null);
480
531
  }
@@ -519,11 +570,16 @@ export function DuctShell({ shellId, userContext, onTokenRequest, onNavigate, on
519
570
  window.removeEventListener("pointerup", onUp);
520
571
  panelDragState.current = null;
521
572
  setIsPanelDragging(false);
522
- cancelRafUpdate(panelDragRaf, panelDragPending, commitPanelPos);
573
+ const finalPos = cancelRafUpdate(panelDragRaf, panelDragPending, commitPanelPos);
574
+ if (finalPos) {
575
+ setPanelPos(finalPos);
576
+ const layout = readStoredShellLayout(shellId);
577
+ writeStoredShellLayout(shellId, { ...layout, panel: finalPos });
578
+ }
523
579
  };
524
580
  window.addEventListener("pointermove", onMove);
525
581
  window.addEventListener("pointerup", onUp);
526
- }, [draggable]);
582
+ }, [draggable, shellId]);
527
583
  if (!shellId) {
528
584
  console.error("[DuctShell] shellId prop is required");
529
585
  return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@duct-sdk/sdk",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
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",