@dexhq/canvas 0.14.0 → 0.15.0

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.
Files changed (229) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/README.md +5 -3
  3. package/app/canvas/activity.tsx +8 -15
  4. package/app/canvas/anchoring.ts +3 -5
  5. package/app/canvas/canvas-input.ts +151 -14
  6. package/app/canvas/canvas-keys.ts +9 -0
  7. package/app/canvas/canvas-model.ts +5 -42
  8. package/app/canvas/canvas-panels.ts +1 -17
  9. package/app/canvas/canvas-scene.ts +7 -3
  10. package/app/canvas/canvas-ui.ts +2 -1
  11. package/app/canvas/canvas.css +61 -26
  12. package/app/canvas/change-notice.tsx +10 -1
  13. package/app/canvas/comment-layer.tsx +2 -1
  14. package/app/canvas/comments.tsx +204 -82
  15. package/app/canvas/element-picker.ts +200 -27
  16. package/app/canvas/engine/canvas-gestures.ts +72 -17
  17. package/app/canvas/engine/canvas-store.ts +17 -1
  18. package/app/canvas/engine/engine.css +6 -3
  19. package/app/canvas/find-bar.tsx +817 -0
  20. package/app/canvas/find-model.ts +135 -0
  21. package/app/canvas/flow-canvas.tsx +18 -2
  22. package/app/canvas/follow-pin.ts +26 -6
  23. package/app/canvas/frame-node.tsx +9 -9
  24. package/app/canvas/imported-reviews.tsx +12 -22
  25. package/app/canvas/layout.ts +27 -0
  26. package/app/canvas/live-page.ts +142 -19
  27. package/app/canvas/page-find.ts +220 -0
  28. package/app/canvas/page-style.ts +23 -0
  29. package/app/canvas/section-node.tsx +2 -0
  30. package/app/canvas/spec-threads.ts +24 -23
  31. package/app/canvas/thread-focus.tsx +14 -12
  32. package/app/canvas/use-activity.ts +0 -8
  33. package/app/canvas/use-agent-changes.tsx +34 -40
  34. package/app/canvas/use-canvas-clipboard.tsx +11 -14
  35. package/app/canvas/xray.ts +3 -12
  36. package/app/frame.tsx +5 -0
  37. package/app/i18n/locales/en/messages.po +88 -8
  38. package/app/i18n/locales/en/messages.ts +1 -1
  39. package/app/i18n/locales/pseudo/messages.po +88 -8
  40. package/app/i18n/locales/pseudo/messages.ts +1 -1
  41. package/app/icons/glyphs.tsx +4 -0
  42. package/app/main.tsx +3 -0
  43. package/app/pages/canvas.tsx +27 -8
  44. package/app/pages/commands-settings.tsx +16 -2
  45. package/app/shell/feedback-form.tsx +10 -21
  46. package/app/shell/feedback-link.tsx +2 -1
  47. package/app/shell/scaled-frame.tsx +21 -9
  48. package/app/types.ts +21 -205
  49. package/app/ui/file-drop.ts +128 -0
  50. package/app/ui/shadcn/input-group.tsx +2 -2
  51. package/dist/cli/banner.d.mts +4 -2
  52. package/dist/cli/banner.mjs +34 -11
  53. package/dist/cli/commands/app.mjs +19 -11
  54. package/dist/cli/commands/hook.mjs +2 -1
  55. package/dist/config/project-files.d.mts +6 -0
  56. package/dist/config/project-files.mjs +14 -2
  57. package/dist/config/renamed.d.mts +0 -2
  58. package/dist/config/renamed.mjs +1 -3
  59. package/dist/content/capture.d.mts +2 -2
  60. package/dist/content/capture.mjs +2 -2
  61. package/dist/content/content.d.mts +3 -141
  62. package/dist/content/content.mjs +7 -62
  63. package/dist/content/flow-specs.mjs +1 -1
  64. package/dist/content/prototype-summary.d.mts +3 -39
  65. package/dist/content/prototype-summary.mjs +2 -3
  66. package/dist/content/prototypes.mjs +1 -1
  67. package/dist/content/text-replace.d.mts +30 -0
  68. package/dist/content/text-replace.mjs +309 -0
  69. package/dist/content/thread-module.mjs +1 -1
  70. package/dist/content/threads.mjs +1 -1
  71. package/dist/paste/paste.mjs +1 -1
  72. package/dist/paths.d.mts +0 -2
  73. package/dist/paths.mjs +1 -3
  74. package/dist/server/agent-env.d.mts +5 -1
  75. package/dist/server/agent-env.mjs +7 -2
  76. package/dist/server/agent-session.d.mts +14 -1
  77. package/dist/server/agent-session.mjs +84 -19
  78. package/dist/server/build-pictures.mjs +1 -1
  79. package/dist/server/channel.d.mts +13 -24
  80. package/dist/server/channel.mjs +55 -37
  81. package/dist/server/claimed-presence.d.mts +3 -2
  82. package/dist/server/claimed-presence.mjs +15 -7
  83. package/dist/server/close-check.mjs +2 -2
  84. package/dist/server/comments/actions.d.mts +153 -0
  85. package/dist/server/comments/actions.mjs +154 -0
  86. package/dist/server/comments/routes.d.mts +25 -0
  87. package/dist/server/comments/routes.mjs +88 -0
  88. package/dist/server/comments/tools.d.mts +6 -0
  89. package/dist/server/comments/tools.mjs +154 -0
  90. package/dist/server/dev-server.mjs +27 -13
  91. package/dist/server/file-lock.d.mts +2 -2
  92. package/dist/server/file-lock.mjs +130 -36
  93. package/dist/server/mcp.d.mts +0 -2
  94. package/dist/server/mcp.mjs +7 -8
  95. package/dist/server/me.d.mts +1 -1
  96. package/dist/server/open-page.d.mts +22 -0
  97. package/dist/server/open-page.mjs +20 -2
  98. package/dist/server/outcome.d.mts +22 -0
  99. package/dist/server/outcome.mjs +8 -0
  100. package/dist/server/own-copies.mjs +2 -2
  101. package/dist/server/people.d.mts +1 -1
  102. package/dist/server/port.d.mts +12 -0
  103. package/dist/server/port.mjs +66 -14
  104. package/dist/server/presence.d.mts +4 -1
  105. package/dist/server/presence.mjs +2 -2
  106. package/dist/server/requests.d.mts +5 -1
  107. package/dist/server/requests.mjs +33 -48
  108. package/dist/server/studio-for.d.mts +5 -0
  109. package/dist/server/studio-for.mjs +17 -3
  110. package/dist/server/sync-install.d.mts +8 -12
  111. package/dist/server/sync-install.mjs +12 -30
  112. package/dist/server/thread-source.mjs +2 -2
  113. package/dist/server/tools/describe.d.mts +1 -1
  114. package/dist/server/tools/describe.mjs +1 -1
  115. package/dist/server/tools/feedback.d.mts +1 -1
  116. package/dist/server/tools/reading.mjs +13 -4
  117. package/dist/server/tools/show.d.mts +1 -1
  118. package/dist/server/tools/snapshot.d.mts +1 -1
  119. package/dist/server/tools/thread-list.mjs +1 -1
  120. package/dist/server/tools/watch.mjs +5 -3
  121. package/dist/server/vite.mjs +2 -2
  122. package/dist/server/web-app.mjs +4 -7
  123. package/dist/server/work-groups.mjs +1 -1
  124. package/dist/setup/create.d.mts +4 -2
  125. package/dist/setup/create.mjs +67 -17
  126. package/dist/setup/design-system-checks.mjs +3 -12
  127. package/dist/setup/desktop-app-script.mjs +4 -3
  128. package/dist/setup/desktop-app-start.d.mts +8 -2
  129. package/dist/setup/desktop-app-start.mjs +64 -29
  130. package/dist/setup/desktop-app.d.mts +8 -0
  131. package/dist/setup/desktop-app.mjs +19 -3
  132. package/dist/setup/detect.d.mts +0 -2
  133. package/dist/setup/detect.mjs +1 -3
  134. package/dist/setup/doctor.mjs +1 -1
  135. package/dist/setup/migrate/row-titles.mjs +1 -1
  136. package/dist/setup/project.d.mts +6 -1
  137. package/dist/setup/project.mjs +9 -9
  138. package/dist/setup/starters.d.mts +2 -0
  139. package/dist/setup/starters.mjs +7 -1
  140. package/dist/shared/annotations-core.mjs +1 -1
  141. package/dist/shared/canvas-core.mjs +1 -1
  142. package/dist/shared/canvas-file.d.mts +201 -0
  143. package/dist/shared/canvas-file.mjs +1 -0
  144. package/dist/shared/comments/routes.d.mts +53 -0
  145. package/dist/shared/comments/routes.mjs +37 -0
  146. package/dist/shared/feedback.d.mts +8 -0
  147. package/dist/shared/feedback.mjs +10 -2
  148. package/dist/shared/page-review.d.mts +2 -11
  149. package/dist/shared/page-review.mjs +4 -13
  150. package/dist/shared/presence-core.d.mts +11 -0
  151. package/dist/shared/presence-core.mjs +11 -2
  152. package/dist/shared/review-file.d.mts +5 -0
  153. package/dist/shared/review-file.mjs +23 -13
  154. package/dist/shared/server-page.mjs +1 -1
  155. package/dist/shared/signup.d.mts +2 -5
  156. package/dist/shared/signup.mjs +2 -35
  157. package/dist/shared/studio-events.d.mts +0 -6
  158. package/dist/shared/studio-events.mjs +1 -5
  159. package/dist/shared/studio-files.d.mts +12 -0
  160. package/dist/shared/studio-files.mjs +6 -1
  161. package/dist/shared/studio-routes.d.mts +16 -62
  162. package/dist/shared/studio-routes.mjs +1 -69
  163. package/dist/shared/threads-core.d.mts +2 -2
  164. package/dist/shared/threads-core.mjs +1 -1
  165. package/extension/dist/feedback.js +148 -138
  166. package/extension/dist/manifest.json +1 -1
  167. package/extension/dist/picker.js +146 -136
  168. package/package.json +2 -2
  169. package/src/cli/banner.ts +45 -11
  170. package/src/cli/commands/app.ts +23 -8
  171. package/src/cli/commands/hook.ts +4 -1
  172. package/src/config/project-files.ts +21 -6
  173. package/src/config/renamed.ts +0 -3
  174. package/src/content/capture.ts +6 -12
  175. package/src/content/content.ts +7 -241
  176. package/src/content/flow-specs.ts +2 -1
  177. package/src/content/prototype-summary.ts +4 -44
  178. package/src/content/review-pages.ts +2 -1
  179. package/src/content/text-replace.ts +449 -0
  180. package/src/paths.ts +0 -8
  181. package/src/server/agent-env.ts +12 -2
  182. package/src/server/agent-session.ts +124 -34
  183. package/src/server/channel.ts +94 -52
  184. package/src/server/claimed-presence.ts +26 -10
  185. package/src/server/comments/actions.ts +352 -0
  186. package/src/server/comments/routes.ts +176 -0
  187. package/src/server/comments/tools.ts +317 -0
  188. package/src/server/dev-server.ts +36 -15
  189. package/src/server/file-lock.ts +205 -54
  190. package/src/server/mcp.ts +13 -14
  191. package/src/server/me.ts +2 -5
  192. package/src/server/open-page.ts +54 -4
  193. package/src/server/outcome.ts +26 -0
  194. package/src/server/people.ts +2 -1
  195. package/src/server/port.ts +94 -20
  196. package/src/server/presence.ts +11 -3
  197. package/src/server/requests.ts +60 -70
  198. package/src/server/studio-for.ts +26 -2
  199. package/src/server/sync-install.ts +35 -26
  200. package/src/server/thread-place.ts +2 -4
  201. package/src/server/tools/reading.ts +16 -3
  202. package/src/server/tools/watch.ts +7 -7
  203. package/src/server/web-app.ts +11 -9
  204. package/src/setup/create.ts +91 -17
  205. package/src/setup/design-system-checks.ts +7 -15
  206. package/src/setup/desktop-app-script.ts +4 -3
  207. package/src/setup/desktop-app-start.ts +94 -26
  208. package/src/setup/desktop-app.ts +23 -2
  209. package/src/setup/detect.ts +0 -4
  210. package/src/setup/project.ts +9 -8
  211. package/src/setup/starters.ts +8 -1
  212. package/src/shared/canvas-file.ts +205 -0
  213. package/src/shared/comments/routes.ts +79 -0
  214. package/src/shared/feedback.ts +14 -4
  215. package/src/shared/page-review.ts +11 -16
  216. package/src/shared/presence-core.ts +16 -2
  217. package/src/shared/review-file.ts +28 -12
  218. package/src/shared/server-page.ts +2 -1
  219. package/src/shared/signup.ts +4 -28
  220. package/src/shared/studio-events.ts +0 -13
  221. package/src/shared/studio-files.ts +14 -0
  222. package/src/shared/studio-routes.ts +21 -64
  223. package/src/shared/threads-core.ts +2 -2
  224. package/dist/server/tools/close-reply.d.mts +0 -6
  225. package/dist/server/tools/close-reply.mjs +0 -138
  226. package/dist/server/tools/comment.d.mts +0 -6
  227. package/dist/server/tools/comment.mjs +0 -49
  228. package/src/server/tools/close-reply.ts +0 -271
  229. package/src/server/tools/comment.ts +0 -96
@@ -30,7 +30,9 @@ import { cn } from "cn";
30
30
  import {
31
31
  type ReactNode,
32
32
  type RefObject,
33
+ useCallback,
33
34
  useEffect,
35
+ useLayoutEffect,
34
36
  useMemo,
35
37
  useRef,
36
38
  useState,
@@ -81,6 +83,7 @@ import {
81
83
  type ThreadsApi,
82
84
  useCanvasIfAny,
83
85
  } from "./canvas-context";
86
+ import { threadItemId } from "./canvas-scene";
84
87
  import {
85
88
  commandTrigger,
86
89
  QuickCommands,
@@ -113,6 +116,19 @@ const CARD_MARGIN = 16;
113
116
  const CARD_MAX_HEIGHT = 480;
114
117
  /** Between a pin and its card. */
115
118
  const PIN_GAP = 8;
119
+ /**
120
+ * How long a card opened at its pin waits for it, unseen: while the canvas
121
+ * moves to it, and its frame's page loads and is measured. After, it shows
122
+ * by its frame until the pin comes.
123
+ */
124
+ export const PIN_WAIT_MS = 1500;
125
+ const CARD_OFFSET = 360;
126
+
127
+ /** Where a card with no pin to hang from opens: top right. */
128
+ export const cardPoint = (): ScreenPoint => ({
129
+ left: window.innerWidth - CARD_OFFSET - 32,
130
+ top: 96,
131
+ });
116
132
 
117
133
  /** A pin's place on screen, as getBoundingClientRect gives it. */
118
134
  interface PinRect {
@@ -213,48 +229,94 @@ const useDismiss = (
213
229
  };
214
230
 
215
231
  /** Where a card goes beside its pin: on the right, else the left, on screen. */
216
- const beside = (pin: DOMRect, card: HTMLElement): ScreenPoint =>
232
+ const beside = (pin: PinRect, card: HTMLElement): ScreenPoint =>
217
233
  besidePin(
218
234
  pin,
219
235
  { height: card.offsetHeight, width: CARD_WIDTH },
220
236
  { height: window.innerHeight, width: window.innerWidth }
221
237
  );
222
238
 
239
+ /**
240
+ * Where a card goes on its frame when its pin isn't drawn (its element is
241
+ * gone): beside the frame's top right corner, where a comment on the whole
242
+ * frame has its pin.
243
+ */
244
+ const besideCorner = (frame: DOMRect, card: HTMLElement): ScreenPoint =>
245
+ beside(
246
+ {
247
+ bottom: frame.top,
248
+ left: frame.right,
249
+ right: frame.right,
250
+ top: frame.top,
251
+ },
252
+ card
253
+ );
254
+
223
255
  /**
224
256
  * A card beside its pin, if it has one there, else at a point on screen kept
225
- * inside the window. Escape closes it.
257
+ * inside the window. With no point of its own, it waits unseen for its pin
258
+ * (PIN_WAIT_MS), once: open it again with a new key to wait again. If none
259
+ * comes, it shows by its frame, else top right. Escape closes it.
226
260
  */
227
261
  const FloatingCard = ({
228
262
  anchor,
229
263
  at,
230
264
  children,
265
+ frame,
231
266
  label,
232
267
  onClose,
233
268
  }: {
234
269
  /** The pin it hangs from, as a selector: it follows it as the canvas moves. */
235
270
  anchor?: string;
236
- at: ScreenPoint;
271
+ /** Where it opens; left out, at its pin. */
272
+ at?: ScreenPoint;
237
273
  children: ReactNode;
274
+ /** The frame its pin is on, as a selector: where it shows if the pin isn't. */
275
+ frame?: string;
238
276
  label: string;
239
277
  onClose: () => void;
240
278
  }) => {
241
279
  const ref = useRef<HTMLElement>(null);
280
+ const opensAtPin = at === undefined;
281
+ // Its pin drawn and the card put beside it; or the wait for it over.
282
+ const [pinSeen, setPinSeen] = useState(false);
283
+ const [waitOver, setWaitOver] = useState(false);
284
+ const seePin = useCallback(() => setPinSeen(true), []);
242
285
  useDismiss(ref, onClose);
243
- useFollowPin(ref, anchor, beside);
286
+ useFollowPin(ref, anchor, beside, {
287
+ onFound: seePin,
288
+ orElse:
289
+ opensAtPin && waitOver && !pinSeen && frame
290
+ ? { anchor: frame, place: besideCorner }
291
+ : undefined,
292
+ });
293
+ useEffect(() => {
294
+ if (!opensAtPin) {
295
+ return;
296
+ }
297
+ const timer = window.setTimeout(() => setWaitOver(true), PIN_WAIT_MS);
298
+ return () => window.clearTimeout(timer);
299
+ }, [opensAtPin]);
300
+ const start = at ?? cardPoint();
244
301
  const left = Math.max(
245
302
  CARD_MARGIN,
246
- Math.min(at.left, window.innerWidth - CARD_WIDTH - CARD_MARGIN)
303
+ Math.min(start.left, window.innerWidth - CARD_WIDTH - CARD_MARGIN)
247
304
  );
248
305
  const top = Math.max(
249
306
  CARD_MARGIN,
250
- Math.min(at.top, window.innerHeight - CARD_MAX_HEIGHT - CARD_MARGIN)
307
+ Math.min(start.top, window.innerHeight - CARD_MAX_HEIGHT - CARD_MARGIN)
251
308
  );
252
309
  return (
253
310
  <section
254
311
  aria-label={label}
255
312
  className="studio-overlay fixed z-50 flex max-h-[30rem] flex-col overflow-hidden"
256
313
  ref={ref}
257
- style={{ left, top, width: CARD_WIDTH }}
314
+ style={{
315
+ left,
316
+ top,
317
+ width: CARD_WIDTH,
318
+ visibility: opensAtPin && !(pinSeen || waitOver) ? "hidden" : undefined,
319
+ }}
258
320
  >
259
321
  {children}
260
322
  </section>
@@ -508,6 +570,31 @@ export const Composer = ({
508
570
  );
509
571
  };
510
572
 
573
+ /** A suggestion's Accept and Reject, small and side by side. */
574
+ const AcceptOrReject = ({
575
+ accepting,
576
+ onAccept,
577
+ onReject,
578
+ }: {
579
+ accepting?: boolean;
580
+ onAccept: () => void;
581
+ onReject: () => void;
582
+ }) => {
583
+ const { t } = useLingui();
584
+ return (
585
+ <div className="mt-2 flex gap-1.5">
586
+ <Button disabled={accepting} onClick={onAccept} size="xs">
587
+ <Icon data-icon="inline-start" name="Check" />
588
+ {t`Accept`}
589
+ </Button>
590
+ <Button onClick={onReject} size="xs" variant="outline">
591
+ <Icon data-icon="inline-start" name="X" />
592
+ {t`Reject`}
593
+ </Button>
594
+ </div>
595
+ );
596
+ };
597
+
511
598
  /**
512
599
  * A suggestion's change, as its entry's own words: the old struck, the new
513
600
  * after them; then Accept, which changes the words in the spec, and Reject,
@@ -520,7 +607,6 @@ const SuggestionChange = ({
520
607
  thread: Thread;
521
608
  threads: ThreadsApi;
522
609
  }) => {
523
- const { t } = useLingui();
524
610
  const me = useMe();
525
611
  const accept = useStudioAction(() => threads.accept(thread.id), {
526
612
  fallback: msg`Not accepted. Try again.`,
@@ -543,24 +629,11 @@ const SuggestionChange = ({
543
629
  {!CAN_WRITE ||
544
630
  isClosed(thread) ||
545
631
  !mayEditSpec(target.spec, me.contributor?.slug) ? null : (
546
- <div className="mt-2 flex gap-1.5">
547
- <Button
548
- disabled={accept.pending}
549
- onClick={() => accept.run()}
550
- size="xs"
551
- >
552
- <Icon data-icon="inline-start" name="Check" />
553
- {t`Accept`}
554
- </Button>
555
- <Button
556
- onClick={() => threads.send(thread.id, { status: "dismissed" })}
557
- size="xs"
558
- variant="outline"
559
- >
560
- <Icon data-icon="inline-start" name="X" />
561
- {t`Reject`}
562
- </Button>
563
- </div>
632
+ <AcceptOrReject
633
+ accepting={accept.pending}
634
+ onAccept={() => accept.run()}
635
+ onReject={() => threads.send(thread.id, { status: "dismissed" })}
636
+ />
564
637
  )}
565
638
  {problem ? (
566
639
  <p className="studio-small mt-1 text-destructive" role="alert">
@@ -582,7 +655,6 @@ const RenameChange = ({
582
655
  thread: Thread;
583
656
  threads: ThreadsApi;
584
657
  }) => {
585
- const { t } = useLingui();
586
658
  const canvas = useCanvasIfAny();
587
659
  const { target } = thread;
588
660
  if (!isRenameSuggestion(target)) {
@@ -603,25 +675,12 @@ const RenameChange = ({
603
675
  <span className="underline underline-offset-4">{target.rename}</span>
604
676
  </p>
605
677
  {CAN_WRITE && !isClosed(thread) && theirs ? (
606
- <div className="mt-2 flex gap-1.5">
607
- <Button
608
- onClick={() =>
609
- canvas && acceptRename(threads, canvas.editor, thread)
610
- }
611
- size="xs"
612
- >
613
- <Icon data-icon="inline-start" name="Check" />
614
- {t`Accept`}
615
- </Button>
616
- <Button
617
- onClick={() => threads.send(thread.id, { status: "dismissed" })}
618
- size="xs"
619
- variant="outline"
620
- >
621
- <Icon data-icon="inline-start" name="X" />
622
- {t`Reject`}
623
- </Button>
624
- </div>
678
+ <AcceptOrReject
679
+ onAccept={() =>
680
+ canvas && acceptRename(threads, canvas.editor, thread)
681
+ }
682
+ onReject={() => threads.send(thread.id, { status: "dismissed" })}
683
+ />
625
684
  ) : null}
626
685
  </>
627
686
  );
@@ -1367,16 +1426,20 @@ const ThreadCard = ({
1367
1426
  thread,
1368
1427
  threads,
1369
1428
  }: {
1370
- at: ScreenPoint;
1429
+ at?: ScreenPoint;
1371
1430
  onClose: () => void;
1372
1431
  thread: Thread;
1373
1432
  threads: ThreadsApi;
1374
1433
  }) => {
1375
1434
  const { t } = useLingui();
1435
+ // The frame it is on, wherever that has moved: on the canvas, not in Play.
1436
+ const canvas = useCanvasIfAny()?.editor.canvas;
1437
+ const frame = canvas ? threadItemId(thread, canvas) : undefined;
1376
1438
  return (
1377
1439
  <FloatingCard
1378
1440
  anchor={threadAnchor(thread.id)}
1379
1441
  at={at}
1442
+ frame={frame ? `[data-frame-key="${CSS.escape(frame)}"]` : undefined}
1380
1443
  label={t`Comment`}
1381
1444
  onClose={onClose}
1382
1445
  >
@@ -1402,13 +1465,18 @@ export const DEFAULT_FILTER: CommentFilter = {
1402
1465
 
1403
1466
  /**
1404
1467
  * How comments are shown, shared by the Comments panel's header, its list
1405
- * and the pins: whether they are hidden (⇧C, or the panel's ⋯ menu), the
1406
- * filter, and what is searched for. It lasts until the page reloads; the
1468
+ * and the pins: whether their pins are hidden (⇧C, or the panel's ⋯ menu),
1469
+ * the filter, and what is searched for. It lasts until the page reloads; the
1407
1470
  * search, until the panel closes.
1408
1471
  */
1409
1472
  export interface CommentsView {
1410
1473
  filter: CommentFilter;
1411
1474
  hidden: boolean;
1475
+ /**
1476
+ * While comments are hidden, the thread opened since, from the list or the
1477
+ * heads-up: its card and its pin show.
1478
+ */
1479
+ opened?: string;
1412
1480
  /** The panel's page: the team's comments, or reviewers' reviews. */
1413
1481
  page: "comments" | "reviews";
1414
1482
  query: string;
@@ -1425,7 +1493,8 @@ const FIRST_VIEW: CommentsView = {
1425
1493
  hidden: false,
1426
1494
  page: "comments",
1427
1495
  query: "",
1428
- reviewsResolved: false,
1496
+ // As the team's: a review stays in sight once its comments are closed.
1497
+ reviewsResolved: true,
1429
1498
  reviewsShowing: false,
1430
1499
  };
1431
1500
 
@@ -1446,9 +1515,15 @@ export const resetCommentsView = () => updateCommentsView(FIRST_VIEW);
1446
1515
  export const setCommentsAudience = (audience: CommentFilter["audience"]) =>
1447
1516
  updateCommentsView({ filter: { ...view.filter, audience } });
1448
1517
 
1518
+ /** Whether a thread is out of sight: comments are hidden, and it wasn't opened since. */
1519
+ export const isHiddenThread = (
1520
+ { hidden, opened }: Pick<CommentsView, "hidden" | "opened">,
1521
+ id: string
1522
+ ) => hidden && opened !== id;
1523
+
1449
1524
  export const setCommentsHidden = (hidden: boolean) => {
1450
1525
  if (hidden !== view.hidden) {
1451
- updateCommentsView({ hidden });
1526
+ updateCommentsView({ hidden, opened: undefined });
1452
1527
  }
1453
1528
  };
1454
1529
 
@@ -1468,6 +1543,13 @@ export const useCommentsView = () =>
1468
1543
  /** Whether comments are hidden, as ⇧C or the ⋯ menu last left them. */
1469
1544
  export const useCommentsHidden = () => useCommentsView().hidden;
1470
1545
 
1546
+ /**
1547
+ * Whether a thread's marks on the canvas are out of sight (isHiddenThread):
1548
+ * its pin, and the tick where an agent's change for it landed.
1549
+ */
1550
+ export const useIsHiddenThread = (id: string) =>
1551
+ isHiddenThread(useCommentsView(), id);
1552
+
1471
1553
  /**
1472
1554
  * Comments hide while `active` is true; ⇧C still shows them. After, they
1473
1555
  * are as they were before.
@@ -1477,9 +1559,10 @@ export const useHideCommentsWhile = (active: boolean) => {
1477
1559
  if (!active) {
1478
1560
  return;
1479
1561
  }
1480
- const before = view.hidden;
1481
- setCommentsHidden(true);
1482
- return () => setCommentsHidden(before);
1562
+ // A thread opened while they were hidden hides too, and comes back.
1563
+ const before = { hidden: view.hidden, opened: view.opened };
1564
+ updateCommentsView({ hidden: true, opened: undefined });
1565
+ return () => updateCommentsView(before);
1483
1566
  }, [active]);
1484
1567
  };
1485
1568
 
@@ -1640,7 +1723,10 @@ export const DraftPin = () => {
1640
1723
  );
1641
1724
  };
1642
1725
 
1643
- /** A thread's pin on the canvas: click it to open the thread. None while comments are hidden. */
1726
+ /**
1727
+ * A thread's pin on the canvas: click it to open the thread. None while
1728
+ * comments are hidden, but the open thread's when it was opened since.
1729
+ */
1644
1730
  export const Pin = ({
1645
1731
  folded = false,
1646
1732
  onOpen,
@@ -1652,8 +1738,8 @@ export const Pin = ({
1652
1738
  thread: Thread;
1653
1739
  }) => {
1654
1740
  const { t } = useLingui();
1655
- const commentsHidden = useCommentsHidden();
1656
- if (commentsHidden) {
1741
+ const hidden = useIsHiddenThread(thread.id);
1742
+ if (hidden) {
1657
1743
  return null;
1658
1744
  }
1659
1745
  const first = thread.messages[0];
@@ -1691,7 +1777,12 @@ export type FloatingComment =
1691
1777
  /** The quick bar first, centred above `at`, then the composer. */
1692
1778
  quick?: boolean;
1693
1779
  }
1694
- | { kind: "thread"; id: string; at: ScreenPoint };
1780
+ | {
1781
+ kind: "thread";
1782
+ id: string;
1783
+ /** Where its card opens; left out, at its pin, once that is drawn. */
1784
+ at?: ScreenPoint;
1785
+ };
1695
1786
 
1696
1787
  /** While its composer is open, the composer closes itself. */
1697
1788
  const NO_CLOSE = () => undefined;
@@ -1764,11 +1855,48 @@ const QuickBar = ({
1764
1855
  );
1765
1856
  };
1766
1857
 
1858
+ /**
1859
+ * A thread opened while comments are hidden, from the list or the heads-up,
1860
+ * shows with its pin: its card, or its words beside a spec. Hiding comments
1861
+ * again hides it, as any open thread.
1862
+ */
1863
+ export const showWhileHidden = (id: string) => {
1864
+ if (view.hidden && view.opened !== id) {
1865
+ updateCommentsView({ opened: id });
1866
+ }
1867
+ };
1868
+
1869
+ /**
1870
+ * Forgets the thread opened while comments are hidden once it closes, or
1871
+ * another opens: the floating one, or the spec thread open beside its spec.
1872
+ */
1873
+ export const useOpenedWhileHidden = (
1874
+ floating: FloatingComment | undefined,
1875
+ specThread: string | undefined
1876
+ ) => {
1877
+ useLayoutEffect(() => {
1878
+ const id = floating?.kind === "thread" ? floating.id : specThread;
1879
+ if (view.opened !== undefined && view.opened !== id) {
1880
+ updateCommentsView({ opened: undefined });
1881
+ }
1882
+ }, [floating, specThread]);
1883
+ // Leaving the canvas (for Play), it is no longer open.
1884
+ useEffect(
1885
+ () => () => {
1886
+ if (view.opened !== undefined) {
1887
+ updateCommentsView({ opened: undefined });
1888
+ }
1889
+ },
1890
+ []
1891
+ );
1892
+ };
1893
+
1767
1894
  /**
1768
1895
  * The card for what is floating, if anything; a thread gone since shows
1769
- * none, and an open thread hides with comments (a comment being written
1770
- * stays). On the canvas and in Play it is always there, so it also listens
1771
- * for ⇧C, which hides comments.
1896
+ * none, and an open thread hides with comments, unless it was opened since
1897
+ * (showWhileHidden; a comment being written stays). On the canvas and
1898
+ * in Play it is always there, so it also listens for ⇧C, which hides
1899
+ * comments.
1772
1900
  */
1773
1901
  export const FloatingCommentCard = ({
1774
1902
  floating,
@@ -1780,7 +1908,7 @@ export const FloatingCommentCard = ({
1780
1908
  threads: ThreadsApi;
1781
1909
  }) => {
1782
1910
  useHideCommentsKey();
1783
- const commentsHidden = useCommentsHidden();
1911
+ const commentsView = useCommentsView();
1784
1912
  if (floating?.kind === "compose" && floating.quick) {
1785
1913
  return (
1786
1914
  <QuickBar
@@ -1803,12 +1931,15 @@ export const FloatingCommentCard = ({
1803
1931
  );
1804
1932
  }
1805
1933
  const thread =
1806
- floating?.kind === "thread" && !commentsHidden
1934
+ floating?.kind === "thread" && !isHiddenThread(commentsView, floating.id)
1807
1935
  ? threads.threads.find((entry) => entry.id === floating.id)
1808
1936
  : undefined;
1937
+ // A card for each thread and each way it opens: one opened at its pin
1938
+ // waits for it afresh.
1809
1939
  return floating && thread ? (
1810
1940
  <ThreadCard
1811
1941
  at={floating.at}
1942
+ key={floating.at ? thread.id : `${thread.id}@pin`}
1812
1943
  onClose={onClose}
1813
1944
  thread={thread}
1814
1945
  threads={threads}
@@ -2090,8 +2221,9 @@ export const CommentsTools = () => {
2090
2221
  * Every thread on the prototype, open ones first, then resolved ones,
2091
2222
  * dimmed; filtered by where they stand, who they are from and what they
2092
2223
  * say, as CommentsTools sets. A row opens its thread on the canvas, and
2093
- * resolves or reopens it from its corner, except in a built studio. While
2094
- * comments are hidden, the list is too. Closing the panel clears the search.
2224
+ * resolves or reopens it from its corner, except in a built studio. With
2225
+ * comments hidden on the canvas, the list still shows them. Closing the
2226
+ * panel clears the search.
2095
2227
  */
2096
2228
  export const CommentsPanel = ({
2097
2229
  onResolve,
@@ -2102,18 +2234,16 @@ export const CommentsPanel = ({
2102
2234
  onSelect: (thread: Thread, at: ScreenPoint) => void;
2103
2235
  threads: Thread[];
2104
2236
  }) => {
2105
- const { filter, hidden, query } = useCommentsView();
2237
+ const { filter, query } = useCommentsView();
2106
2238
  useEffect(() => () => updateCommentsView({ query: "" }), []);
2107
2239
  return (
2108
2240
  <div className="flex min-h-0 flex-1 flex-col">
2109
- {hidden ? null : (
2110
- <StatusTabs
2111
- onChange={(status) =>
2112
- updateCommentsView({ filter: { ...filter, status } })
2113
- }
2114
- value={filter.status}
2115
- />
2116
- )}
2241
+ <StatusTabs
2242
+ onChange={(status) =>
2243
+ updateCommentsView({ filter: { ...filter, status } })
2244
+ }
2245
+ value={filter.status}
2246
+ />
2117
2247
  <CommentsBody
2118
2248
  filter={filter}
2119
2249
  onResolve={onResolve}
@@ -2139,16 +2269,8 @@ const CommentsBody = ({
2139
2269
  query: string;
2140
2270
  threads: Thread[];
2141
2271
  }) => {
2142
- const commentsHidden = useCommentsHidden();
2143
2272
  const shown = filterThreads(threads, filter, query);
2144
2273
  const words = query.trim();
2145
- if (commentsHidden) {
2146
- return (
2147
- <EmptyState icon="MessageCircle" title={<Trans>Comments hidden</Trans>}>
2148
- <Trans>Press ⇧C, or choose Show comments in ⋯, to see them.</Trans>
2149
- </EmptyState>
2150
- );
2151
- }
2152
2274
  // A search that finds nothing says so in a line, where without it the
2153
2275
  // filter would show threads.
2154
2276
  if (