@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
package/CHANGELOG.md CHANGED
@@ -1,5 +1,41 @@
1
1
  # @dexhq/canvas
2
2
 
3
+ ## 0.15.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 7e4d6e8: ⌘F finds words on every frame of the canvas: each match painted yellow on its page, the canvas moving to the current one, the count, steps either way and a list of matches by frame. Replace all changes the words where they are written as text in your own files, with Undo.
8
+
9
+ ### Patch Changes
10
+
11
+ - ea8099e: Opening an agent from the canvas works when the login shell doesn't put Node on its PATH (nvm loaded only in some shells): the terminal Dex opens puts the Node running Dex first on it.
12
+ - 589f164: The Mac app made by a Dex that moved off a taken port now opens the port that Dex moved to, so it starts, and `dex app install` says which address the app opens. Opened from its start link, the app no longer starts a second `dex dev`. When something else holds the app's port, the app says what (another checkout's Dex, or the process), where this project's Dex runs if it runs elsewhere, and only suggests fixes the app can use.
13
+ - 3eaf154: A field in an input group shows its focus once, around the group: the canvas's comment search no longer draws a second outline through its search icon.
14
+ - 9ac6654: In Safari and the Dex app, the canvas's keys work again once you leave a live frame with Escape, or outline an element in one with the comment tool. Before, the frame's page kept the keyboard, so H, ⇧C and the other hotkeys did nothing; only C, V, Escape and the zoom keys reached the canvas.
15
+ - 6d1cb80: In Safari and the Mac app, the canvas stays sharp zoomed in with a frame selected or the pointer over it: the size label has no backdrop blur, and what fades or grows in on the canvas no longer makes WebKit draw the whole canvas at the screen's scale and stretch it.
16
+ - 2adbb05: The green tick where an agent's change landed now hides with the comment pins (⇧C), and shows only where its comment's pin would, so a Comments filter that leaves out resolved comments leaves out ticks too. A Done comment opened while comments are hidden shows its tick with its pin.
17
+ - b6582b4: Comments from people and agents now go through one set of actions, and request bodies are checked: a comment request with a field of the wrong type is refused, naming the field.
18
+ - 3e7bd3b: A comment opened from the agent heads-up now opens, one an agent completed too: the canvas moves to it, and its card appears at its pin, or by its frame when its element is gone, not at the top right. ⇧C hides comment pins on the canvas only: the Comments list still shows every comment, and one opened from it shows with its pin.
19
+ - 44c259f: Escape that closes a dialog on a live frame's page stays with the page, whatever design system made the dialog: the frame stays live and keeps showing Reset, where before it left the frame too, and a `<dialog>` opened with `showModal()` closes on Escape again.
20
+ - 087af74: A file dropped on the feedback form attaches wherever it lands: on its edge too, and in Safari and the Dex app when let go just as the pointer moves onto another part of the form, where it used to open in place of the page (or in Preview, from the app); dragging one over the form shows a copy, not a move.
21
+ - 087af74: A file dropped anywhere on Import reviews, or on the canvas just as the pointer reaches it, is taken in Safari and the Dex app too, and one dropped where nothing takes it (the toolbar, a dialog's backdrop, a live frame, Markup's panel) is refused instead of opening in place of the page.
22
+ - ca91b55: Remove canvas model code nothing called: moving a section, updating several frames at once, the off-canvas test and the panel feature list.
23
+ - 54dc82e: Code that was in two places is in one: the canvas's types, sending to the feedback relay, the update after Sync, a review's header and a suggestion's buttons. Nothing Dex or Markup does changes.
24
+ - 2863775: Remove CLI and server code nothing called, and stop shipping the interface's import check, which only a test ran.
25
+ - 41dffdd: An imported review stays on Comments' Reviews page once its comments are closed: resolved, Done and Not done comments show there, dimmed, and keep their pins, as the team's do. Hide resolved still hides them.
26
+ - 29c4136: Two Dex processes on one machine no longer end up holding one lock at once (the repository's turn, the install lock, comments, canvases, presence). A Dex that comes back late, after its lock was taken over, leaves the next holder's lock alone, and a takeover left halfway by a process that stopped no longer lets two waiters in.
27
+ - 339e54c: A comment's pin stays on its element when the element's words change, as when an agent rewrites a heading a comment is on, and when the words change before the comment is posted; it used to disappear while the comment stayed in the agent's threads. A comment whose row moves in a list, or whose element gets new markup around it, follows its words there. A plain element (no ARIA states, no design-system component) that another takes the place of keeps the pin there.
28
+ - e360183: In Chrome, zoomed out where frames show their pictures, a frame's comment pins and the ticks where an agent's changes landed stay on its picture, as in Safari and the Dex app, instead of going a moment later. So a comment opened from the heads-up on a tall frame opens beside its pin, not at the frame's corner.
29
+ - c1cdf84: `dex dev` no longer takes a port that another checkout's Dex, or another process, already holds on the other address family (IPv4 or IPv6) or on every address, where a browser on `localhost` could reach it instead. It counts that port as taken: it moves to the next free one, or, when `STUDIO_PORT` asks for that port, says what holds it.
30
+ - f8c405c: An agent stops showing at work on the canvas once its work ends, however it ends: a comment closed, answered or let go, back to `watch` with nothing in hand, or its session ended or killed. Claude Code's edit marks now go with it, not two minutes later. `where` says who the canvas shows at work on the open file, and until when.
31
+ - d21b6aa: Importing a review no longer reloads the page when its snapshots are written where earlier ones were deleted, so the Comments panel stays open on Reviews with the review listed. Their frames update in place.
32
+ - bf9b26c: Zoomed out so far that a section's name would reach into the section above (below about 7% with the browser's usual font size, as fitting a canvas of many stacked sections does), section names hide, as frame names already do further in. A press there reaches what is drawn, and dragging a section by its name no longer resizes a frame in the section above. A section drawn that far out still asks for its name.
33
+ - 3b50db2: Canvas: a section dragged while you zoom keeps its frames with it, even as their pages load and grow.
34
+ - ea8099e: `dex create` in a folder with files but no package.json (an agent's `work/` and `outputs/`) starts the new project beside them instead of stopping, and a new project connects the agent running setup instead of always Claude Code.
35
+ - 0e503a9: Run again under Bun, setup no longer takes a studio in Bun's global cache for one the project has installed, so it still runs the install the project needs.
36
+ - 029ae68: A thumbnail no longer shows the scrollbar of a scrolling area inside its frame, such as an app's main pane, where the system always shows scrollbars; a frame in use still scrolls as before.
37
+ - 65a5fbc: Canvas: in Safari and the Dex app, a pinch over a frame in use zooms as smoothly and as far as one over the empty canvas, and a pinch never jumps as it starts.
38
+
3
39
  ## 0.14.0
4
40
 
5
41
  ### Minor Changes
package/README.md CHANGED
@@ -125,11 +125,13 @@ npm create dex@latest
125
125
 
126
126
  `pnpm create dex`, `yarn create dex` and `bun create dex` work too;
127
127
  with npm, flags go after `--` (`npm create dex@latest -- --yes`). It runs
128
- `dex create` from `@dexhq/canvas`, which `npx @dexhq/canvas create` runs
129
- directly.
128
+ `dex create` from `@dexhq/canvas`, which
129
+ `npx --package=@dexhq/canvas dex create` runs directly (the package has two
130
+ commands, so npx needs the one to run).
130
131
 
131
132
  Run it where the project's `package.json` is, or anywhere in a workspace
132
- (monorepo). In an empty folder it starts a new project from the shadcn
133
+ (monorepo). In a folder with no `package.json` (empty, or holding only
134
+ notes or an agent's `work/` and `outputs/`) it starts a new project from the shadcn
133
135
  starter instead (Vite, React and shadcn on Base UI, with every component the
134
136
  studio's own interface uses), then sets the studio up in it the same way. It
135
137
  says what it does at each step:
@@ -42,7 +42,6 @@ import {
42
42
  Matrix,
43
43
  } from "./activity-parts";
44
44
  import { commentWords } from "./agent-changes";
45
- import type { ScreenPoint } from "./canvas-context";
46
45
  import { DoneTick } from "./change-notice";
47
46
  import { DOCKS_CHANGED } from "./toolbar-parts";
48
47
  import { type ActivityState, useActivity } from "./use-activity";
@@ -416,7 +415,7 @@ const ItemRow = ({
416
415
  onOpen,
417
416
  }: {
418
417
  item: ActivityItem;
419
- onOpen: (thread: Thread, at: HTMLElement) => void;
418
+ onOpen: (thread: Thread) => void;
420
419
  }) => {
421
420
  const { t } = useLingui();
422
421
  const words: Record<ActivityItem["status"], string> = {
@@ -447,7 +446,7 @@ const ItemRow = ({
447
446
  <span className="font-medium">{words[item.status]}</span>{" "}
448
447
  <button
449
448
  className="text-muted-foreground underline decoration-foreground/25 underline-offset-[3px] outline-none hover:text-foreground hover:decoration-foreground focus-visible:text-foreground"
450
- onClick={(event) => onOpen(item.thread, event.currentTarget)}
449
+ onClick={() => onOpen(item.thread)}
451
450
  type="button"
452
451
  >
453
452
  {commentWords(item.thread)}
@@ -487,7 +486,7 @@ const Log = ({
487
486
  items: ActivityItem[];
488
487
  /** The comment the bar speaks of, kept in the log however old. */
489
488
  news?: Thread;
490
- onOpen: (thread: Thread, at: HTMLElement) => void;
489
+ onOpen: (thread: Thread) => void;
491
490
  }) => {
492
491
  const ref = useRef<HTMLDivElement>(null);
493
492
  // At the newest end, a new comment keeps it there; scrolled away to read
@@ -680,7 +679,7 @@ const PanelContent = ({
680
679
  activity: ActivityState;
681
680
  kind: PanelKind;
682
681
  onFullSetup: () => void;
683
- onOpen: (thread: Thread, at: HTMLElement) => void;
682
+ onOpen: (thread: Thread) => void;
684
683
  opensUp: boolean;
685
684
  }) => {
686
685
  const { t } = useLingui();
@@ -810,13 +809,14 @@ const PANEL_FOR: Partial<Record<BarAction, PanelKind>> = {
810
809
  * The agent heads-up, docked in a corner of the canvas: a leaf that reads
811
810
  * the live data itself, so the canvas rendering never renders it, nor it the
812
811
  * canvas. `slug` is the file whose comments its log lists; `openThread`
813
- * opens one, and stays the same function.
812
+ * moves the canvas to one and opens it at its pin (one an agent completed
813
+ * also outlines where its change landed), and stays the same function.
814
814
  */
815
815
  export const Activity = memo(function Activity({
816
816
  openThread,
817
817
  slug,
818
818
  }: {
819
- openThread: (id: string, at: ScreenPoint) => void;
819
+ openThread: (id: string) => void;
820
820
  slug: string;
821
821
  }) {
822
822
  const [connecting, setConnecting] = useState(false);
@@ -857,14 +857,7 @@ export const Activity = memo(function Activity({
857
857
  setPanel(PANEL_FOR[action]);
858
858
  };
859
859
 
860
- const openItem = (thread: Thread, at: HTMLElement) => {
861
- if (thread.status === "resolved") {
862
- activity.goToChange(thread);
863
- return;
864
- }
865
- const box = at.getBoundingClientRect();
866
- openThread(thread.id, { left: box.left, top: box.top });
867
- };
860
+ const openItem = (thread: Thread) => openThread(thread.id);
868
861
 
869
862
  const shown = panel ? (
870
863
  <PanelContent
@@ -41,7 +41,8 @@ export interface Point {
41
41
 
42
42
  type Frames = ReadonlyMap<string, Frame>;
43
43
 
44
- const isOnFrame = (target: ThreadTarget): target is OnFrameTarget =>
44
+ /** Whether a comment is on a frame: on one of its elements, or all of it. */
45
+ export const isOnFrame = (target: ThreadTarget): target is OnFrameTarget =>
45
46
  target.kind === "element" || target.kind === "frame";
46
47
 
47
48
  const sameParams = (
@@ -171,10 +172,6 @@ const indexOf = (threads: readonly Thread[], canvas: Canvas): Index => {
171
172
  export const frameOf = (thread: Thread, canvas: Canvas) =>
172
173
  anchorIn(framesOf(canvas), thread);
173
174
 
174
- /** A comment on a frame that is no longer on the canvas. */
175
- export const isOffCanvas = (thread: Thread, canvas: Canvas) =>
176
- isOnFrame(thread.target) && frameOf(thread, canvas) === undefined;
177
-
178
175
  /** The threads on one frame, wherever it has moved. */
179
176
  export const threadsOn = (
180
177
  threads: readonly Thread[],
@@ -258,6 +255,7 @@ export const locatorsOf = (target: ThreadTarget): ElementLocator[] =>
258
255
  text: target.text,
259
256
  code: target.code,
260
257
  within: target.within,
258
+ openers: target.openers,
261
259
  },
262
260
  ...(target.also ?? []),
263
261
  ...(target.openers ?? []),
@@ -1,5 +1,6 @@
1
- import { toolFromFrame, zoomCommand } from "./canvas-keys.ts";
1
+ import { isFindKey, toolFromFrame, zoomCommand } from "./canvas-keys.ts";
2
2
  import { zoomsCanvas } from "./engine/camera.ts";
3
+ import { KEEPS_POINTER, MOVING } from "./engine/canvas-store.ts";
3
4
  import { isTyping, pressesControl } from "./typing.ts";
4
5
 
5
6
  // Wheels, pinches and zoom keys that are the canvas's wherever they happen,
@@ -23,7 +24,10 @@ import { isTyping, pressesControl } from "./typing.ts";
23
24
  // every live page on it ask, keeps the canvas or the page it started on
24
25
  // moving to its end, and nothing else.
25
26
 
26
- /** Wheel events this close together are one gesture, and go one way. */
27
+ /**
28
+ * Wheel events, or the steps of a pinch, this close together are one
29
+ * gesture, and go one way.
30
+ */
27
31
  const GESTURE_GAP_MS = 200;
28
32
  /** The canvas zooms by 2^(-deltaY / 50) for a pinch on a Mac (camera.ts). */
29
33
  const PINCH_DELTA_PER_DOUBLING = 50;
@@ -181,14 +185,18 @@ const gestureOn = (element: Element) =>
181
185
  /** Wheels a frame's page passed on: the gesture sent them to the canvas. */
182
186
  const passedOn = new WeakSet<Event>();
183
187
 
184
- /** Turns Safari's pinch into the ctrl-wheel the canvas zooms by. */
188
+ /**
189
+ * Turns Safari's pinch into the ctrl-wheel the canvas zooms by. WebKit keeps
190
+ * a scale per page and can start a pinch where an earlier one on that page
191
+ * left off, so each step zooms by its change from the scale before it.
192
+ */
185
193
  const pinchAsWheel = (onWheel: (wheel: WheelEventInit) => void) => {
186
194
  let scale = 1;
187
195
  return (event: Event) => {
188
196
  const gesture = event as GestureEvent;
189
197
  event.preventDefault();
190
198
  if (event.type === "gesturestart") {
191
- scale = 1;
199
+ scale = gesture.scale || 1;
192
200
  return;
193
201
  }
194
202
  const ratio = gesture.scale / scale;
@@ -206,13 +214,54 @@ const GESTURES = ["gesturestart", "gesturechange"] as const;
206
214
 
207
215
  /**
208
216
  * The keys a frame's page passes on and takes from the page: the zoom keys,
209
- * and Escape to leave the frame. The page uses them first: an Escape that
210
- * closes a menu there, or ends typing an accent, stays.
217
+ * ⌘F, and Escape to leave the frame. The page uses them first: an Escape that
218
+ * closes a dialog or menu there, or ends typing an accent, stays.
211
219
  */
212
220
  const isCanvasKey = (event: KeyboardEvent) =>
213
221
  zoomCommand(event) !== undefined ||
222
+ isFindKey(event) ||
214
223
  (event.key === "Escape" && !event.isComposing);
215
224
 
225
+ /**
226
+ * What Escape closes on a page wherever it is pressed: a modal (a `<dialog>`
227
+ * opened with showModal, or a dialog marked aria-modal) and a popover that
228
+ * light dismisses. In `:is()`, a browser that doesn't know one of them still
229
+ * reads the others.
230
+ */
231
+ const CLOSES_ON_ESCAPE =
232
+ ':is(:modal, :popover-open:not([popover="manual" i]), [aria-modal="true"])';
233
+
234
+ /**
235
+ * What Escape closes when it is pressed in it: those, in a shadow root too,
236
+ * and a design system's dialog marked only by its role. A `<dialog>` opened
237
+ * with show() stays open.
238
+ */
239
+ const CLOSES_FROM_INSIDE = `:is(${CLOSES_ON_ESCAPE}, [role="dialog"], [role="alertdialog"])`;
240
+
241
+ /**
242
+ * Whether an element shows. One kept on the page while closed is hidden;
243
+ * browsers without the check go by its being there.
244
+ */
245
+ const shows = (element: Element) =>
246
+ element.checkVisibility?.({
247
+ opacityProperty: true,
248
+ visibilityProperty: true,
249
+ }) ?? true;
250
+
251
+ /**
252
+ * Whether `page` has a use for an Escape, asked before it hears it: one
253
+ * pressed in a dialog or popover (CLOSES_FROM_INSIDE), or while a modal or
254
+ * popover shows there, closes it. A dialog that closes without preventing
255
+ * the key is gone by the time the page's window hears it, and a `<dialog>`
256
+ * or popover closes only if the key keeps its default.
257
+ */
258
+ const pageTakesEscape = (event: KeyboardEvent, page: Window) =>
259
+ event
260
+ .composedPath()
261
+ .some(
262
+ (target) => asElement(target)?.matches(CLOSES_FROM_INSIDE) === true
263
+ ) || [...page.document.querySelectorAll(CLOSES_ON_ESCAPE)].some(shows);
264
+
216
265
  /** Menus, lists and trees, which jump to the item a letter starts. */
217
266
  const TYPES_AHEAD =
218
267
  '[role="menu"], [role="menubar"], [role="listbox"], [role="tree"], [role="treegrid"]';
@@ -260,6 +309,53 @@ const HELD_KEYS = new Set([
260
309
  "ControlRight",
261
310
  ]);
262
311
 
312
+ /**
313
+ * Keeps a frame taking the pointer while the canvas moves with the pinch its
314
+ * page passes on (engine.css), until the pinch is over and the canvas has
315
+ * settled. WebKit gives a pinch only to the page it started on, and drops
316
+ * the rest of it once that page lets the pointer through. Wheels need no
317
+ * hold: WebKit keeps a scroll with the page it started on whatever the
318
+ * pointer does, and Chromium asks where each wheel is.
319
+ */
320
+ const holdPointer = (iframe: HTMLIFrameElement) => {
321
+ const surface = iframe.closest(RENDERER);
322
+ const moving = () => surface?.classList.contains(MOVING) === true;
323
+ let pinchEnd: ReturnType<typeof setTimeout> | undefined;
324
+ const cancelRelease = () => {
325
+ clearTimeout(pinchEnd);
326
+ settling.disconnect();
327
+ };
328
+ const release = () => {
329
+ cancelRelease();
330
+ iframe.removeAttribute(KEEPS_POINTER);
331
+ };
332
+ const settling = new MutationObserver(() => {
333
+ if (!moving()) {
334
+ release();
335
+ }
336
+ });
337
+ const pinchOver = () => {
338
+ if (surface && moving()) {
339
+ settling.observe(surface, { attributeFilter: ["class"] });
340
+ } else {
341
+ release();
342
+ }
343
+ };
344
+ return {
345
+ /** A step of the pinch its page passes on. */
346
+ hold: () => {
347
+ cancelRelease();
348
+ // Marked once: a pinch steps 60 to 120 times a second.
349
+ if (!iframe.hasAttribute(KEEPS_POINTER)) {
350
+ iframe.setAttribute(KEEPS_POINTER, "true");
351
+ }
352
+ pinchEnd = setTimeout(pinchOver, GESTURE_GAP_MS);
353
+ },
354
+ /** Lets the pointer through again: its page has gone, or is unwatched. */
355
+ release,
356
+ };
357
+ };
358
+
263
359
  /**
264
360
  * Passes what is the canvas's over a frame's page on to the canvas, as wheels
265
361
  * and keys over the frame: now, and on each page the frame loads. A page from
@@ -268,6 +364,7 @@ const HELD_KEYS = new Set([
268
364
  */
269
365
  export const watchFrameInput = (iframe: HTMLIFrameElement): (() => void) => {
270
366
  const gesture = gestureOn(iframe);
367
+ const pointer = holdPointer(iframe);
271
368
  // The page's pixels are scaled by the canvas's zoom.
272
369
  const toCanvas = (wheel: WheelEventInit) => {
273
370
  const box = iframe.getBoundingClientRect();
@@ -331,7 +428,7 @@ export const watchFrameInput = (iframe: HTMLIFrameElement): (() => void) => {
331
428
  * Lets go of every key the page passed down: its page has gone, or lost
332
429
  * the keyboard to another app, and their key-ups will never come.
333
430
  */
334
- const release = () => {
431
+ const releaseKeys = () => {
335
432
  for (const [code, key] of down) {
336
433
  iframe.dispatchEvent(
337
434
  new KeyboardEvent("keyup", { bubbles: true, code, key })
@@ -339,8 +436,17 @@ export const watchFrameInput = (iframe: HTMLIFrameElement): (() => void) => {
339
436
  }
340
437
  down.clear();
341
438
  };
439
+ // The Escapes the page has a use for, noted before it hears them (listen).
440
+ const pageEscapes = new WeakSet<KeyboardEvent>();
441
+ // Whether the Escape held down went to the page: its repeats go there too,
442
+ // though the dialog it closed has gone. The page's until onKey hears it: a
443
+ // press the page stops never reaches onKey.
444
+ let escapeToPage = false;
342
445
  const onKey = (event: KeyboardEvent) => {
343
- if (event.defaultPrevented) {
446
+ if (event.key === "Escape" && !event.repeat) {
447
+ escapeToPage = event.defaultPrevented || pageEscapes.has(event);
448
+ }
449
+ if (event.defaultPrevented || (event.key === "Escape" && escapeToPage)) {
344
450
  return;
345
451
  }
346
452
  // Space held is the hand, as it is over the canvas, unless the page has
@@ -387,13 +493,29 @@ export const watchFrameInput = (iframe: HTMLIFrameElement): (() => void) => {
387
493
  const onBlur = () => {
388
494
  setTimeout(() => {
389
495
  if (!iframe.ownerDocument.hasFocus()) {
390
- release();
496
+ releaseKeys();
391
497
  }
392
498
  }, 0);
393
499
  };
394
- const onGesture = pinchAsWheel(toCanvas);
500
+ const pinch = pinchAsWheel(toCanvas);
501
+ const onGesture = (event: Event) => {
502
+ pointer.hold();
503
+ pinch(event);
504
+ };
395
505
  const listen = (page: Window) => {
506
+ const onKeyBeforePage = (event: KeyboardEvent) => {
507
+ if (event.key !== "Escape") {
508
+ return;
509
+ }
510
+ if (!event.repeat) {
511
+ escapeToPage = true;
512
+ }
513
+ if (pageTakesEscape(event, page)) {
514
+ pageEscapes.add(event);
515
+ }
516
+ };
396
517
  page.addEventListener("wheel", onWheel, { passive: false });
518
+ page.addEventListener("keydown", onKeyBeforePage, { capture: true });
397
519
  page.addEventListener("keydown", onKey);
398
520
  page.addEventListener("keyup", onKeyUp);
399
521
  page.addEventListener("blur", onBlur);
@@ -402,6 +524,7 @@ export const watchFrameInput = (iframe: HTMLIFrameElement): (() => void) => {
402
524
  }
403
525
  return () => {
404
526
  page.removeEventListener("wheel", onWheel);
527
+ page.removeEventListener("keydown", onKeyBeforePage, { capture: true });
405
528
  page.removeEventListener("keydown", onKey);
406
529
  page.removeEventListener("keyup", onKeyUp);
407
530
  page.removeEventListener("blur", onBlur);
@@ -412,18 +535,19 @@ export const watchFrameInput = (iframe: HTMLIFrameElement): (() => void) => {
412
535
  };
413
536
  let unlisten: (() => void) | undefined;
414
537
  const unwatch = () => {
415
- release();
538
+ releaseKeys();
416
539
  try {
417
540
  unlisten?.();
418
541
  } catch {
419
542
  // The page is from another origin now, and took its listeners with it.
420
543
  }
421
544
  unlisten = undefined;
545
+ // The page that had a gesture has gone, and the next starts afresh.
546
+ gesture.forget(iframe);
547
+ pointer.release();
422
548
  };
423
549
  const watch = () => {
424
550
  unwatch();
425
- // The page that had a gesture has gone, and the next starts afresh.
426
- gesture.forget(iframe);
427
551
  try {
428
552
  const page = iframe.contentWindow;
429
553
  unlisten = page ? listen(page) : undefined;
@@ -436,10 +560,23 @@ export const watchFrameInput = (iframe: HTMLIFrameElement): (() => void) => {
436
560
  return () => {
437
561
  iframe.removeEventListener("load", watch);
438
562
  unwatch();
439
- gesture.forget(iframe);
440
563
  };
441
564
  };
442
565
 
566
+ /**
567
+ * Gives the canvas back the keyboard, if a frame's page has it. Blurring the
568
+ * iframe is not enough: WebKit (Safari, the Dex app) leaves the keyboard in
569
+ * its page, which keeps every key but the few it passes on (watchFrameInput).
570
+ * Focusing the canvas's window takes it back there too.
571
+ */
572
+ export const takeKeyboardFrom = (iframe: HTMLIFrameElement): void => {
573
+ if (iframe.ownerDocument.activeElement !== iframe) {
574
+ return;
575
+ }
576
+ iframe.blur();
577
+ iframe.ownerDocument.defaultView?.focus();
578
+ };
579
+
443
580
  /**
444
581
  * Makes `element`, a live frame on the canvas's own page, a page of its own
445
582
  * to the canvas's wheels (canvasTakesWheel): a gesture that starts by
@@ -145,6 +145,15 @@ export const zoomCommand = (
145
145
  }
146
146
  };
147
147
 
148
+ /**
149
+ * ⌘F (Ctrl F off a Mac): find on the frames, in place of the browser's own
150
+ * find, which would search the studio around them. It works while typing.
151
+ */
152
+ export const isFindKey = (key: CanvasKey): boolean =>
153
+ (key.metaKey || key.ctrlKey) &&
154
+ !(key.altKey || key.shiftKey) &&
155
+ key.key.toLowerCase() === "f";
156
+
148
157
  /**
149
158
  * ⌘ with Z, \, A or D, and ⌥⌘Enter, Figma's Present, to play the one selected
150
159
  * frame. While wireframing, ⌘A and ⌥⌘Enter leave the frames alone.
@@ -274,18 +274,12 @@ const rowFor = (section: Section, cell: Pick<Cell, "above" | "row">): Row => {
274
274
  return row;
275
275
  };
276
276
 
277
- /** Move a frame to a cell in any section, or to a new row. */
278
- export const placeFrame = (
279
- canvas: Canvas,
280
- from: FrameAddress,
281
- to: Cell
282
- ): Canvas => moveFrame(canvas, from, to).canvas;
283
-
284
277
  /**
285
- * placeFrame, with the key the frame ends at: its id may change, when the
286
- * row it lands in has a frame by that id. A frame already on that step, as
287
- * one pushed there by another frame of the same drop is, ends where it is.
288
- * No key when there is no such frame or cell.
278
+ * Move a frame to a cell in any section, or to a new row, with the key the
279
+ * frame ends at: its id may change, when the row it lands in has a frame by
280
+ * that id. A frame already on that step, as one pushed there by another
281
+ * frame of the same drop is, ends where it is. No key when there is no such
282
+ * frame or cell.
289
283
  */
290
284
  export const moveFrame = (
291
285
  canvas: Canvas,
@@ -662,17 +656,6 @@ export const editSketch = (
662
656
  };
663
657
  };
664
658
 
665
- /** Change several frames the same way: grids on every selected frame. */
666
- export const updateFrames = (
667
- canvas: Canvas,
668
- addresses: FrameAddress[],
669
- patch: FramePatch
670
- ): Canvas =>
671
- addresses.reduce(
672
- (changed, address) => updateFrame(changed, address, patch),
673
- canvas
674
- );
675
-
676
659
  export const frameName = (frame: Frame | NewFrame): string => {
677
660
  const it = kinded(frame);
678
661
  switch (it.kind) {
@@ -837,26 +820,6 @@ export function updateSection(
837
820
  return next;
838
821
  }
839
822
 
840
- /** Move a section so it sits before `index` (or last). */
841
- export function moveSection(
842
- canvas: Canvas,
843
- sectionId: string,
844
- index: number
845
- ): Canvas {
846
- const next = clone(canvas);
847
- const from = next.sections.findIndex((section) => section.id === sectionId);
848
- if (from < 0) {
849
- return canvas;
850
- }
851
- const [section] = next.sections.splice(from, 1);
852
- if (!section) {
853
- return canvas;
854
- }
855
- const at = index > from ? index - 1 : index;
856
- next.sections.splice(Math.min(at, next.sections.length), 0, section);
857
- return next;
858
- }
859
-
860
823
  /**
861
824
  * Move a row of a section so it sits before `index` among its rows (or last).
862
825
  * The same canvas when it is there already.
@@ -1,4 +1,3 @@
1
- import type { features } from "virtual:studio-ui";
2
1
  import type { MessageDescriptor } from "@lingui/core";
3
2
  import { msg } from "@lingui/core/macro";
4
3
  import type { IconName } from "@studio/icons";
@@ -6,11 +5,7 @@ import { useCallback, useMemo, useState } from "react";
6
5
  import type { CanvasTool } from "./canvas-context";
7
6
 
8
7
  // The canvas's floating panels, each attached under the group it opens from:
9
- // what each is, where it opens and which feature shows it. One panel per side
10
- // is open at a time.
11
-
12
- /** One of the studio's unreleased features. */
13
- type Feature = keyof typeof features;
8
+ // what each is and where it opens. One panel per side is open at a time.
14
9
 
15
10
  export type PanelSide = "left" | "right";
16
11
 
@@ -30,8 +25,6 @@ export type PanelId =
30
25
  | "removed";
31
26
 
32
27
  export interface CanvasPanel {
33
- /** The feature that shows it; none, always there. */
34
- feature?: Feature;
35
28
  group: PanelGroup;
36
29
  icon: IconName;
37
30
  id: PanelId;
@@ -55,7 +48,6 @@ export const CANVAS_PANELS: readonly CanvasPanel[] = [
55
48
  label: msg`Components`,
56
49
  side: "left",
57
50
  group: "toolbar",
58
- feature: "stickers",
59
51
  },
60
52
  {
61
53
  id: "wireframe",
@@ -63,7 +55,6 @@ export const CANVAS_PANELS: readonly CanvasPanel[] = [
63
55
  label: msg`Wireframe`,
64
56
  side: "left",
65
57
  group: "mode",
66
- feature: "wireframes",
67
58
  tool: "wireframe",
68
59
  },
69
60
  {
@@ -72,7 +63,6 @@ export const CANVAS_PANELS: readonly CanvasPanel[] = [
72
63
  label: msg`Inspect`,
73
64
  side: "left",
74
65
  group: "mode",
75
- feature: "inspector",
76
66
  tool: "inspect",
77
67
  },
78
68
  {
@@ -100,12 +90,6 @@ export const panelRow = (id: PanelId): CanvasPanel => {
100
90
  return row;
101
91
  };
102
92
 
103
- /** The panels whose feature is on, in the table's order. */
104
- export const panelsOn = (
105
- features: Partial<Record<Feature, boolean>>
106
- ): CanvasPanel[] =>
107
- CANVAS_PANELS.filter((row) => !row.feature || Boolean(features[row.feature]));
108
-
109
93
  /** The panel a mode's tool keeps open, if the tool is a mode's. */
110
94
  export const panelOfTool = (tool: CanvasTool): PanelId | undefined =>
111
95
  CANVAS_PANELS.find((row) => row.tool === tool)?.id;
@@ -91,10 +91,14 @@ export const threadItemId = (thread: Thread, canvas: Canvas) => {
91
91
  if (target.kind === "view" || target.kind === "flow") {
92
92
  return sectionNodeId(target.section);
93
93
  }
94
- // A spec's words are in its frame: the first showing that spec.
94
+ // A spec's words are in its frame: the first showing that spec, or that
95
+ // document (docs/<name>.md).
95
96
  if (target.kind === "spec") {
96
- return canvasFrames(canvas).find(({ frame }) => frame.spec === target.spec)
97
- ?.key;
97
+ return canvasFrames(canvas).find(
98
+ ({ frame }) =>
99
+ frame.spec === target.spec ||
100
+ (frame.doc !== undefined && `docs/${frame.doc}.md` === target.spec)
101
+ )?.key;
98
102
  }
99
103
  return frameOf(thread, canvas);
100
104
  };
@@ -53,7 +53,8 @@ export const createCanvasUi = (initial: Partial<CanvasUiState> = {}) => {
53
53
  ...(options?.quick ? { quick: true } : {}),
54
54
  },
55
55
  }),
56
- openThread: (id: string, at: ScreenPoint) =>
56
+ /** Open a thread's card at `at`; left out, at its pin. */
57
+ openThread: (id: string, at?: ScreenPoint) =>
57
58
  set({ floating: { kind: "thread", id, at } }),
58
59
  /** Ask an agent for a new view in a cell: its card, near the top middle. */
59
60
  requestView: (cell: { row?: string; section: string; step: number }) =>