@dexhq/canvas 0.15.0 → 0.16.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 (307) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/app/canvas/activity-parts.tsx +50 -6
  3. package/app/canvas/activity.tsx +2 -3
  4. package/app/canvas/agent-changes.ts +18 -8
  5. package/app/canvas/anchoring.ts +13 -3
  6. package/app/canvas/canvas-context.tsx +6 -2
  7. package/app/canvas/canvas-input.ts +35 -0
  8. package/app/canvas/canvas-model.ts +2 -2
  9. package/app/canvas/canvas-scene.ts +243 -24
  10. package/app/canvas/canvas-ui.ts +11 -2
  11. package/app/canvas/canvas.css +86 -3
  12. package/app/canvas/comments.tsx +66 -29
  13. package/app/canvas/element-link.ts +135 -0
  14. package/app/canvas/element-picker.ts +23 -0
  15. package/app/canvas/export-dialog.tsx +265 -0
  16. package/app/canvas/flow-canvas.tsx +65 -14
  17. package/app/canvas/frame-context-menu.tsx +61 -7
  18. package/app/canvas/frame-node.tsx +10 -11
  19. package/app/canvas/layout.ts +41 -22
  20. package/app/canvas/linked-element.tsx +196 -0
  21. package/app/canvas/live-page.ts +14 -0
  22. package/app/canvas/mentions.tsx +209 -0
  23. package/app/canvas/picked-box.tsx +21 -0
  24. package/app/canvas/removed-views-panel.tsx +4 -4
  25. package/app/canvas/request-node.tsx +151 -0
  26. package/app/canvas/review-panel.tsx +8 -3
  27. package/app/canvas/section-node.tsx +4 -133
  28. package/app/canvas/spec-margin.tsx +4 -1
  29. package/app/canvas/teammates-layer.tsx +205 -0
  30. package/app/canvas/text-layer.tsx +103 -17
  31. package/app/canvas/tool-cursors.ts +7 -6
  32. package/app/canvas/tool-icons.tsx +24 -56
  33. package/app/canvas/typing.ts +12 -0
  34. package/app/canvas/use-agent-changes.tsx +6 -2
  35. package/app/canvas/use-canvas-editor.ts +4 -2
  36. package/app/export/player-model.ts +159 -0
  37. package/app/export/player.tsx +198 -0
  38. package/app/export.html +31 -0
  39. package/app/export.tsx +9 -0
  40. package/app/frame/announce-refreshes.ts +21 -0
  41. package/app/frame/start-frame.tsx +50 -0
  42. package/app/frame/view-loads.ts +161 -0
  43. package/app/frame/views.ts +13 -49
  44. package/app/frame.tsx +2 -38
  45. package/app/i18n/locales/en/messages.po +145 -6
  46. package/app/i18n/locales/en/messages.ts +1 -1
  47. package/app/i18n/locales/pseudo/messages.po +144 -5
  48. package/app/i18n/locales/pseudo/messages.ts +1 -1
  49. package/app/icons/dex-glyphs.tsx +219 -0
  50. package/app/icons/glyphs.tsx +76 -80
  51. package/app/kit/use-flow.ts +2 -1
  52. package/app/live/canvas-teammates.ts +90 -0
  53. package/app/live/studio-api.ts +30 -20
  54. package/app/pages/canvas.tsx +18 -6
  55. package/app/pages/commands-settings.tsx +1 -1
  56. package/app/pages/render.tsx +39 -11
  57. package/app/shell/bell.tsx +15 -5
  58. package/app/shell/presence.tsx +123 -26
  59. package/app/shell/thread-list.tsx +25 -8
  60. package/app/shell/working-on.tsx +35 -3
  61. package/app/ui/prompt-editor.tsx +39 -11
  62. package/app/ui/reference.tsx +21 -8
  63. package/bin/sudio.mjs +1 -1
  64. package/dist/cli/commands/create.d.mts +5 -5
  65. package/dist/cli/commands/create.mjs +4 -4
  66. package/dist/cli/commands/export.d.mts +40 -0
  67. package/dist/cli/commands/export.mjs +66 -0
  68. package/dist/cli/commands/init.d.mts +2 -2
  69. package/dist/cli/commands/upgrade.mjs +1 -1
  70. package/dist/cli/help.d.mts +1 -1
  71. package/dist/cli/help.mjs +13 -7
  72. package/dist/cli/main.d.mts +42 -5
  73. package/dist/cli/main.mjs +1 -0
  74. package/dist/config/load.mjs +14 -2
  75. package/dist/config/project-files.d.mts +5 -0
  76. package/dist/config/project-files.mjs +10 -1
  77. package/dist/config/renamed.d.mts +7 -0
  78. package/dist/config/renamed.mjs +13 -1
  79. package/dist/content/commands.d.mts +11 -9
  80. package/dist/content/commands.mjs +22 -16
  81. package/dist/content/comments-log.mjs +2 -1
  82. package/dist/content/content.d.mts +11 -3
  83. package/dist/content/content.mjs +49 -15
  84. package/dist/content/element-words.d.mts +42 -0
  85. package/dist/content/element-words.mjs +112 -0
  86. package/dist/content/hosted-person.d.mts +31 -0
  87. package/dist/content/hosted-person.mjs +68 -0
  88. package/dist/content/merge-rules.d.mts +5 -0
  89. package/dist/content/merge-rules.mjs +17 -1
  90. package/dist/content/screenshot.mjs +9 -0
  91. package/dist/content/text-edit.d.mts +24 -14
  92. package/dist/content/text-edit.mjs +92 -81
  93. package/dist/content/text-replace.mjs +2 -26
  94. package/dist/content/thread-module.d.mts +2 -4
  95. package/dist/content/thread-module.mjs +4 -5
  96. package/dist/server/agents.d.mts +10 -0
  97. package/dist/server/agents.mjs +21 -6
  98. package/dist/server/canvas-presence.d.mts +22 -0
  99. package/dist/server/canvas-presence.mjs +160 -0
  100. package/dist/server/command-settings.mjs +1 -1
  101. package/dist/server/comments/actions.d.mts +0 -8
  102. package/dist/server/comments/actions.mjs +1 -9
  103. package/dist/server/comments/routes.mjs +10 -31
  104. package/dist/server/dev-server.mjs +35 -13
  105. package/dist/server/export/build.d.mts +15 -0
  106. package/dist/server/export/build.mjs +220 -0
  107. package/dist/server/export/page.d.mts +25 -0
  108. package/dist/server/export/page.mjs +40 -0
  109. package/dist/server/export/plugin.d.mts +31 -0
  110. package/dist/server/export/plugin.mjs +69 -0
  111. package/dist/server/export/run.d.mts +9 -0
  112. package/dist/server/export/run.mjs +61 -0
  113. package/dist/server/export/save.d.mts +7 -0
  114. package/dist/server/export/save.mjs +29 -0
  115. package/dist/server/hosted.d.mts +8 -0
  116. package/dist/server/hosted.mjs +78 -0
  117. package/dist/server/live-mirror.mjs +66 -10
  118. package/dist/server/live.mjs +28 -1
  119. package/dist/server/mcp.mjs +2 -0
  120. package/dist/server/me.d.mts +2 -0
  121. package/dist/server/me.mjs +8 -2
  122. package/dist/server/notices.d.mts +1 -1
  123. package/dist/server/notices.mjs +1 -1
  124. package/dist/server/own-copies.mjs +1 -1
  125. package/dist/server/people.d.mts +7 -2
  126. package/dist/server/people.mjs +6 -2
  127. package/dist/server/pictures.d.mts +1 -1
  128. package/dist/server/pictures.mjs +2 -2
  129. package/dist/server/prebundle.d.mts +32 -0
  130. package/dist/server/prebundle.mjs +115 -0
  131. package/dist/server/problems.d.mts +8 -0
  132. package/dist/server/problems.mjs +13 -0
  133. package/dist/server/requests.mjs +43 -30
  134. package/dist/server/source-stamp.d.mts +4 -3
  135. package/dist/server/source-stamp.mjs +60 -31
  136. package/dist/server/state.d.mts +19 -10
  137. package/dist/server/state.mjs +27 -18
  138. package/dist/server/thread-source.d.mts +8 -0
  139. package/dist/server/thread-source.mjs +24 -5
  140. package/dist/server/tools/export.d.mts +5 -0
  141. package/dist/server/tools/export.mjs +35 -0
  142. package/dist/server/tools/place-frame.mjs +16 -16
  143. package/dist/server/tools/thread-list.mjs +1 -1
  144. package/dist/server/vite.d.mts +9 -4
  145. package/dist/server/vite.mjs +63 -61
  146. package/dist/server/welcome.mjs +2 -1
  147. package/dist/setup/apply.d.mts +4 -0
  148. package/dist/setup/apply.mjs +5 -4
  149. package/dist/setup/create.mjs +5 -5
  150. package/dist/setup/design-system-checks.mjs +1 -6
  151. package/dist/setup/detect/workspace.d.mts +10 -10
  152. package/dist/setup/detect/workspace.mjs +10 -12
  153. package/dist/setup/doctor.d.mts +4 -1
  154. package/dist/setup/doctor.mjs +7 -5
  155. package/dist/setup/migrate/dex-folder.d.mts +61 -0
  156. package/dist/setup/migrate/dex-folder.mjs +544 -0
  157. package/dist/setup/migrate/files-folder.mjs +1 -1
  158. package/dist/setup/migrate/guides.mjs +1 -1
  159. package/dist/setup/migrate/migrations.mjs +4 -0
  160. package/dist/setup/migrate/setup-files.d.mts +5 -0
  161. package/dist/setup/migrate/setup-files.mjs +115 -0
  162. package/dist/setup/migrate/studio-state.d.mts +2 -2
  163. package/dist/setup/migrate/studio-state.mjs +4 -4
  164. package/dist/setup/placement.d.mts +1 -1
  165. package/dist/setup/placement.mjs +5 -4
  166. package/dist/setup/plan.d.mts +5 -5
  167. package/dist/setup/plan.mjs +8 -12
  168. package/dist/setup/project.mjs +1 -1
  169. package/dist/setup/prompts.d.mts +2 -1
  170. package/dist/setup/prompts.mjs +4 -3
  171. package/dist/setup/questions.mjs +3 -2
  172. package/dist/setup/starters.d.mts +1 -1
  173. package/dist/setup/starters.mjs +2 -2
  174. package/dist/setup/write.d.mts +15 -3
  175. package/dist/setup/write.mjs +23 -3
  176. package/dist/shared/canvas-core.d.mts +22 -7
  177. package/dist/shared/canvas-core.mjs +38 -10
  178. package/dist/shared/comments/routes.d.mts +3 -1
  179. package/dist/shared/comments/routes.mjs +4 -2
  180. package/dist/shared/export-core.d.mts +62 -0
  181. package/dist/shared/export-core.mjs +101 -0
  182. package/dist/shared/live-core.d.mts +2 -0
  183. package/dist/shared/live-core.mjs +6 -1
  184. package/dist/shared/live-presence.d.mts +57 -2
  185. package/dist/shared/live-presence.mjs +90 -4
  186. package/dist/shared/page-messages.d.mts +14 -1
  187. package/dist/shared/page-messages.mjs +30 -3
  188. package/dist/shared/people-core.d.mts +28 -0
  189. package/dist/shared/people-core.mjs +27 -1
  190. package/dist/shared/presence-core.d.mts +2 -0
  191. package/dist/shared/references-core.d.mts +4 -0
  192. package/dist/shared/references-core.mjs +12 -4
  193. package/dist/shared/studio-files.d.mts +9 -0
  194. package/dist/shared/studio-files.mjs +11 -2
  195. package/dist/shared/studio-routes.d.mts +13 -1
  196. package/dist/shared/threads-core.d.mts +27 -4
  197. package/dist/shared/threads-core.mjs +67 -12
  198. package/extension/dist/feedback.js +104 -294
  199. package/extension/dist/manifest.json +1 -1
  200. package/extension/dist/picker.js +104 -294
  201. package/package.json +2 -2
  202. package/src/cli/commands/create.ts +4 -4
  203. package/src/cli/commands/export.ts +78 -0
  204. package/src/cli/commands/upgrade.ts +1 -1
  205. package/src/cli/help.ts +13 -7
  206. package/src/cli/main.ts +1 -0
  207. package/src/config/load.ts +26 -2
  208. package/src/config/project-files.ts +15 -0
  209. package/src/config/renamed.ts +19 -1
  210. package/src/content/commands.ts +30 -18
  211. package/src/content/comments-log.ts +4 -1
  212. package/src/content/content.ts +64 -16
  213. package/src/content/element-words.ts +175 -0
  214. package/src/content/hosted-person.ts +107 -0
  215. package/src/content/merge-rules.ts +29 -0
  216. package/src/content/screenshot.ts +14 -0
  217. package/src/content/text-edit.ts +172 -105
  218. package/src/content/text-replace.ts +3 -32
  219. package/src/content/thread-module.ts +2 -4
  220. package/src/content/trash.ts +1 -1
  221. package/src/server/agents.ts +48 -17
  222. package/src/server/canvas-presence.ts +237 -0
  223. package/src/server/channel.ts +1 -1
  224. package/src/server/command-settings.ts +1 -1
  225. package/src/server/comments/actions.ts +0 -19
  226. package/src/server/comments/routes.ts +9 -54
  227. package/src/server/dev-server.ts +66 -26
  228. package/src/server/export/build.ts +310 -0
  229. package/src/server/export/page.ts +85 -0
  230. package/src/server/export/plugin.ts +138 -0
  231. package/src/server/export/run.ts +79 -0
  232. package/src/server/export/save.ts +38 -0
  233. package/src/server/hosted.ts +113 -0
  234. package/src/server/live-mirror.ts +93 -8
  235. package/src/server/live.ts +46 -1
  236. package/src/server/machine-update.ts +3 -3
  237. package/src/server/mcp.ts +2 -0
  238. package/src/server/me.ts +10 -1
  239. package/src/server/notices.ts +2 -2
  240. package/src/server/people.ts +11 -2
  241. package/src/server/pictures.ts +2 -2
  242. package/src/server/prebundle.ts +230 -0
  243. package/src/server/presence.ts +1 -1
  244. package/src/server/problems.ts +11 -0
  245. package/src/server/requests.ts +55 -40
  246. package/src/server/roster.ts +1 -1
  247. package/src/server/saved.ts +1 -1
  248. package/src/server/source-stamp.ts +118 -37
  249. package/src/server/state.ts +53 -31
  250. package/src/server/thread-source.ts +35 -3
  251. package/src/server/tools/export.ts +56 -0
  252. package/src/server/tools/place-frame.ts +23 -15
  253. package/src/server/tools/thread-list.ts +1 -1
  254. package/src/server/updates.ts +2 -2
  255. package/src/server/vite.ts +106 -110
  256. package/src/server/welcome.ts +3 -1
  257. package/src/setup/apply.ts +8 -5
  258. package/src/setup/create.ts +10 -10
  259. package/src/setup/design-system-checks.ts +1 -6
  260. package/src/setup/detect/workspace.ts +20 -21
  261. package/src/setup/doctor.ts +13 -6
  262. package/src/setup/migrate/dex-folder.ts +842 -0
  263. package/src/setup/migrate/files-folder.ts +1 -1
  264. package/src/setup/migrate/guides.ts +3 -1
  265. package/src/setup/migrate/migrations.ts +8 -2
  266. package/src/setup/migrate/setup-files.ts +198 -0
  267. package/src/setup/migrate/studio-state.ts +12 -10
  268. package/src/setup/own-app.ts +1 -1
  269. package/src/setup/placement.ts +7 -6
  270. package/src/setup/plan.ts +13 -18
  271. package/src/setup/project.ts +2 -2
  272. package/src/setup/prompts.ts +5 -4
  273. package/src/setup/questions.ts +6 -3
  274. package/src/setup/starters.ts +3 -3
  275. package/src/setup/write.ts +34 -3
  276. package/src/shared/canvas-core.ts +48 -9
  277. package/src/shared/comments/routes.ts +3 -1
  278. package/src/shared/export-core.ts +198 -0
  279. package/src/shared/live-core.ts +8 -0
  280. package/src/shared/live-presence.ts +171 -2
  281. package/src/shared/page-messages.ts +38 -2
  282. package/src/shared/people-core.ts +44 -0
  283. package/src/shared/presence-core.ts +2 -0
  284. package/src/shared/references-core.ts +22 -3
  285. package/src/shared/studio-files.ts +15 -1
  286. package/src/shared/studio-routes.ts +11 -1
  287. package/src/shared/threads-core.ts +132 -10
  288. package/templates/methods/explore.md +1 -1
  289. package/templates/methods/handoff.md +1 -1
  290. package/templates/methods/review.md +2 -1
  291. package/templates/rules/canvas-frames.md +6 -3
  292. package/templates/rules/commands.md +1 -0
  293. package/templates/rules/prototypes.md +1 -1
  294. package/templates/rules/studio.md +17 -11
  295. package/templates/skills/comprehend/SKILL.md +56 -0
  296. package/templates/skills/distill/SKILL.md +172 -0
  297. package/templates/skills/export-prototype/SKILL.md +35 -0
  298. package/templates/skills/riff/SKILL.md +21 -0
  299. package/templates/skills/riff-deep/SKILL.md +40 -0
  300. package/templates/skills/riff-max/SKILL.md +46 -0
  301. package/templates/skills/riff-state/SKILL.md +45 -0
  302. package/templates/skills/riff-up/SKILL.md +38 -0
  303. package/templates/skills/riff-wide/SKILL.md +40 -0
  304. package/templates/starters/standalone/README.md +1 -1
  305. package/templates/starters/turborepo/README.md +2 -2
  306. package/templates/starters/turborepo/apps/web/src/app.tsx +2 -2
  307. package/templates/starters/vite/README.md +1 -1
@@ -48,6 +48,11 @@ export interface LivePage {
48
48
  editableTextAt: (x: number, y: number) => PickedElement | undefined;
49
49
  /** The element at a point on the page, in its CSS pixels. */
50
50
  elementAt: (x: number, y: number) => PickedElement | undefined;
51
+ /**
52
+ * The element at a point on the screen, in the studio window's pixels:
53
+ * where the canvas shows the page, however far it is zoomed.
54
+ */
55
+ elementAtScreen: (x: number, y: number) => PickedElement | undefined;
51
56
  /** The elements a dragged area holds (see elementsIn). */
52
57
  elementsIn: (area: Box) => PickedElement[];
53
58
  /** The design-system component at a point, through the inspect runtime. */
@@ -235,6 +240,15 @@ export const iframePage = (
235
240
  return {
236
241
  editableTextAt: (x, y) => editableTextAt(doc(), x, y),
237
242
  elementAt: (x, y) => elementAt(doc(), x, y),
243
+ elementAtScreen: (x, y) => {
244
+ // Not laid out: its frame shows its picture.
245
+ if (iframe.offsetWidth === 0) {
246
+ return;
247
+ }
248
+ const rect = iframe.getBoundingClientRect();
249
+ const scale = rect.width / iframe.offsetWidth;
250
+ return elementAt(doc(), (x - rect.left) / scale, (y - rect.top) / scale);
251
+ },
238
252
  elementsIn: (area) => elementsIn(doc(), area),
239
253
  texts: () => {
240
254
  const shown = doc();
@@ -0,0 +1,209 @@
1
+ import { useEffect, useMemo, useSyncExternalStore } from "react";
2
+ import { frameTitle } from "../../src/shared/canvas-core.ts";
3
+ import type { Canvas } from "../../src/shared/canvas-file.ts";
4
+ import { MENTION, mentionsIn } from "../../src/shared/references-core.ts";
5
+ import type { Person } from "../../src/shared/studio-routes.ts";
6
+ import { AGENT_NAMES } from "../../src/shared/threads-core.ts";
7
+ import { CAN_WRITE, useMe } from "../live/studio-api";
8
+ import { studioRequest } from "../live/studio-request";
9
+ import type { Thread } from "../types";
10
+ import {
11
+ detailsOf,
12
+ type PromptChoice,
13
+ type PromptTrigger,
14
+ } from "../ui/prompt-editor";
15
+ import { ReferenceDetails, ReferenceText } from "../ui/reference";
16
+ import { useCanvasIfAny } from "./canvas-context";
17
+ import { commandTrigger, useLoadedCommands } from "./command-menu";
18
+
19
+ // Mentions: "@" in a comment names a person of the workspace
20
+ // (contributors.json) by their slug, "@ana", kept in the words as written,
21
+ // so a renamed person stays mentioned and agents read plain text. The box
22
+ // offers them as a menu, as "/" offers commands; a posted message draws
23
+ // each as a chip with their name, and the Comments panel and the bell can
24
+ // show only the threads that mention you (thread-list.tsx's byFilter).
25
+ // "@" names a frame on the canvas too, by its view, "@checkout", so a
26
+ // comment can point at another frame ("move this to @checkout"); the agent
27
+ // is told which view's file each one is (server/thread-source.ts).
28
+
29
+ /**
30
+ * Whether someone else's message in a thread mentions `slug` (a
31
+ * contributor's), "@ana": your own words never do.
32
+ */
33
+ export const mentionsMe =
34
+ (slug: string | undefined) =>
35
+ (thread: Thread): boolean =>
36
+ slug !== undefined &&
37
+ thread.messages.some(
38
+ (message) =>
39
+ message.authorId !== slug && mentionsIn(message.body).includes(slug)
40
+ );
41
+
42
+ /**
43
+ * Who you are mentioned as: your contributor's slug, or none when Dex does
44
+ * not know you as one (nobody can mention you).
45
+ */
46
+ export const useMentionable = (): string | undefined =>
47
+ useMe().contributor?.slug;
48
+
49
+ // The people, as the page knows them: one copy for every comment box and
50
+ // message, asked for again each time a box opens (names only, so cheap),
51
+ // so one added to contributors.json since is there to mention.
52
+ let shared: readonly Person[] | undefined;
53
+ let loading = false;
54
+ const listeners = new Set<() => void>();
55
+
56
+ const setPeople = (people: readonly Person[]) => {
57
+ shared = people;
58
+ for (const listener of listeners) {
59
+ listener();
60
+ }
61
+ };
62
+
63
+ /** Names only: who can be mentioned needs no commits counted. */
64
+ const refresh = () => {
65
+ if (loading) {
66
+ return;
67
+ }
68
+ loading = true;
69
+ studioRequest("people", { query: { commits: "0" } })
70
+ .then((answer) => setPeople(answer.people))
71
+ .catch(() => undefined)
72
+ .finally(() => {
73
+ loading = false;
74
+ });
75
+ };
76
+
77
+ const subscribe = (listener: () => void) => {
78
+ listeners.add(listener);
79
+ return () => {
80
+ listeners.delete(listener);
81
+ };
82
+ };
83
+ const current = () => shared;
84
+
85
+ /** Forget them, as a new page would: for tests. */
86
+ export const forgetPeople = () => {
87
+ shared = undefined;
88
+ loading = false;
89
+ };
90
+
91
+ const NO_PEOPLE: readonly Person[] = [];
92
+
93
+ /**
94
+ * The workspace's people; none when built. `ask` asks for them again as it
95
+ * mounts (a comment box opening); otherwise only if the page has none (what
96
+ * mounts many times over, as each message does).
97
+ */
98
+ export const usePeople = ({ ask = false }: { ask?: boolean } = {}) => {
99
+ const people = useSyncExternalStore(subscribe, current, current);
100
+ useEffect(() => {
101
+ if (CAN_WRITE && (ask || !shared)) {
102
+ refresh();
103
+ }
104
+ }, [ask]);
105
+ return (CAN_WRITE && people) || NO_PEOPLE;
106
+ };
107
+
108
+ const NO_FRAMES: readonly PromptChoice[] = [];
109
+
110
+ /**
111
+ * The frames "@" can name: each view on the canvas once, by its name, shown
112
+ * by its first frame's name as the canvas shows it, with its section's
113
+ * under it; a frame of its own goes by its section's title, with none.
114
+ */
115
+ export const frameChoices = (canvas: Canvas): PromptChoice[] => {
116
+ const seen = new Map<string, PromptChoice>();
117
+ for (const section of canvas.sections) {
118
+ for (const row of section.rows) {
119
+ for (const frame of row.frames) {
120
+ // "@agent" asks the agent, whatever view has that name.
121
+ if (
122
+ frame.view &&
123
+ !seen.has(frame.view) &&
124
+ !AGENT_NAMES.includes(frame.view)
125
+ ) {
126
+ seen.set(
127
+ frame.view,
128
+ section.at
129
+ ? { id: frame.view, name: section.title }
130
+ : {
131
+ id: frame.view,
132
+ name: frameTitle(frame),
133
+ description: section.title,
134
+ }
135
+ );
136
+ }
137
+ }
138
+ }
139
+ }
140
+ return [...seen.values()];
141
+ };
142
+
143
+ /** The canvas's frames, as "@" names them; none off the canvas. */
144
+ export const useFrames = (): readonly PromptChoice[] => {
145
+ const canvas = useCanvasIfAny()?.editor.canvas;
146
+ return useMemo(() => (canvas ? frameChoices(canvas) : NO_FRAMES), [canvas]);
147
+ };
148
+
149
+ /**
150
+ * What "@" names in a message box: people by slug, shown by name, then the
151
+ * canvas's frames by view. A person comes first where a view has their slug.
152
+ */
153
+ export const mentionTrigger = (
154
+ people: readonly Person[],
155
+ frames: readonly PromptChoice[],
156
+ label: string
157
+ ): PromptTrigger => {
158
+ const slugs = new Set(people.map(({ slug }) => slug));
159
+ return {
160
+ char: MENTION,
161
+ label,
162
+ choices: [
163
+ ...people.map(({ name, slug }) => ({ id: slug, name })),
164
+ ...frames.filter(({ id }) => !slugs.has(id)),
165
+ ],
166
+ };
167
+ };
168
+
169
+ /**
170
+ * What a posted message's chips are: the commands Dex knows, the
171
+ * workspace's people and the canvas's frames.
172
+ */
173
+ export const usePostedDetails = () => {
174
+ const commands = useLoadedCommands()?.commands;
175
+ const people = usePeople();
176
+ const frames = useFrames();
177
+ return useMemo(
178
+ () =>
179
+ detailsOf([
180
+ commandTrigger(commands ?? [], ""),
181
+ mentionTrigger(people, frames, ""),
182
+ ]),
183
+ [commands, people, frames]
184
+ );
185
+ };
186
+
187
+ /** The triggers a posted message's chips can start with. */
188
+ export const POSTED_TRIGGERS = ["/", MENTION];
189
+
190
+ /**
191
+ * A posted message's words, with the commands and people it names as
192
+ * chips: in a thread, a list's row, a section's line. Plain text where
193
+ * nothing is known (a built studio).
194
+ */
195
+ export const MessageWords = ({
196
+ still = false,
197
+ text,
198
+ }: {
199
+ /** Chips without their details, inside what is itself a button. */
200
+ still?: boolean;
201
+ text: string;
202
+ }) => {
203
+ const describe = usePostedDetails();
204
+ return (
205
+ <ReferenceDetails describe={describe}>
206
+ <ReferenceText still={still} text={text} triggers={POSTED_TRIGGERS} />
207
+ </ReferenceDetails>
208
+ );
209
+ };
@@ -0,0 +1,21 @@
1
+ import type { Box } from "./layout";
2
+
3
+ // An element outlined on a frame's page, as the comment tool tints what it
4
+ // picked: the open thread's elements, and what a link opened the canvas on.
5
+
6
+ /** Where a box sits on its page, as a style. */
7
+ export const boxStyle = ({ x, y, width, height }: Box) => ({
8
+ left: x,
9
+ top: y,
10
+ width,
11
+ height,
12
+ });
13
+
14
+ /** One element's outline, over its box on the page. */
15
+ export const PickedBox = ({ box }: { box: Box }) => (
16
+ <div className="studio-pick z-20" data-picked style={boxStyle(box)} />
17
+ );
18
+
19
+ /** A key for a box among others on a page. */
20
+ export const boxKey = ({ x, y, width, height }: Box) =>
21
+ `${x},${y},${width},${height}`;
@@ -29,7 +29,7 @@ import { useScheme, useViewPicture } from "./frame-pictures";
29
29
 
30
30
  // "Removed from canvas": the views a delete on the canvas left behind, which
31
31
  // nothing shows any more. Each can go back on the canvas, or, when it is
32
- // yours, to the trash (.studio/trash/ on this machine) with the images only
32
+ // yours, to the trash (.local/trash/ in the Dex folder, on this machine) with the images only
33
33
  // it shows. Near-copies sit together and each says where it was last, so
34
34
  // views that look alike can be told apart.
35
35
 
@@ -267,9 +267,9 @@ const ConfirmDialog = ({
267
267
  </Trans>
268
268
  ) : (
269
269
  <Trans>
270
- These files move to .studio/trash/ on this machine, at their
271
- paths: copy one back to keep it. The trash empties after 30
272
- days.
270
+ These files move to .local/trash/ in the Dex folder, on this
271
+ machine, at their paths: copy one back to keep it. The trash
272
+ empties after 30 days.
273
273
  </Trans>
274
274
  )}
275
275
  </DialogDescription>
@@ -0,0 +1,151 @@
1
+ import { Trans, useLingui } from "@lingui/react/macro";
2
+ import { Button } from "@studio/ui/shadcn/button";
3
+ import { memo, useMemo, useState } from "react";
4
+ import { threadState } from "../../src/shared/threads-core.ts";
5
+ import { STATE_LABELS } from "../live/thread-state";
6
+ import {
7
+ neighbourGuess,
8
+ Presence,
9
+ StillSkeleton,
10
+ sketchGuess,
11
+ } from "../shell/presence";
12
+ import type { Thread } from "../types";
13
+ import { useCanvas } from "./canvas-context";
14
+ import { useCanvasUi } from "./canvas-ui";
15
+ import { ResizeHandles, type Size } from "./frame-resize";
16
+ import { MessageWords } from "./mentions";
17
+ import { SketchPage } from "./sketch-boxes";
18
+
19
+ export interface RequestNodeData {
20
+ height: number;
21
+ /** Whether the person may move and resize it: a cell they may change. */
22
+ movable: boolean;
23
+ thread: Thread;
24
+ width: number;
25
+ }
26
+
27
+ const PendingStatus = ({
28
+ author,
29
+ status,
30
+ }: {
31
+ author?: string;
32
+ status: Thread["status"];
33
+ }) => {
34
+ if (status !== "acknowledged") {
35
+ return <Trans>Waiting for an agent</Trans>;
36
+ }
37
+ return author ? (
38
+ <Trans>{author} is building this</Trans>
39
+ ) : (
40
+ <Trans>An agent is building this</Trans>
41
+ );
42
+ };
43
+
44
+ /**
45
+ * A request for a new view, in the cell it waits in until its view is
46
+ * there: all page, as what the person drew for it, else as the step before
47
+ * it in its row, else as any view in its section, with the request said
48
+ * above it, as a frame's name is. Dragged to another cell and resized as a
49
+ * frame is (flow-canvas.tsx): its thread keeps where it waits and its size,
50
+ * and the view is put there at that size.
51
+ */
52
+ export const RequestNode = memo(({ data }: { data: RequestNodeData }) => {
53
+ const { editor, say, threads } = useCanvas();
54
+ const { i18n, t } = useLingui();
55
+ const { movable, thread } = data;
56
+ // Resized with the cursor, as a frame is.
57
+ const resizable = useCanvasUi((state) => state.tool === "select") && movable;
58
+ const [draft, setDraft] = useState<Size>();
59
+ const shown = { width: data.width, height: data.height };
60
+ const size = draft ?? shown;
61
+ const latest = thread.messages.at(-1);
62
+ const author = latest?.agent ? latest.author : undefined;
63
+ const waiting = thread.status !== "acknowledged";
64
+ const { sketch, target } = thread;
65
+ const section = target.kind === "view" ? target.section : undefined;
66
+ const row = target.kind === "view" ? target.row : undefined;
67
+ const guess = useMemo(() => {
68
+ if (sketch) {
69
+ return sketchGuess(sketch);
70
+ }
71
+ const prefixes = section ? [`${section}/`] : [];
72
+ if (section && row) {
73
+ prefixes.unshift(`${section}/${row}/`);
74
+ }
75
+ return neighbourGuess(prefixes);
76
+ }, [row, section, sketch]);
77
+
78
+ /** The size its view takes, or the frame's before it with none. */
79
+ const resize = async (next?: Size) => {
80
+ if (target.kind !== "view") {
81
+ return;
82
+ }
83
+ const { size: _was, ...place } = target;
84
+ try {
85
+ await threads.send(thread.id, {
86
+ target: next ? { ...place, size: next } : place,
87
+ });
88
+ } catch {
89
+ say(t`The request was not resized. Try again.`);
90
+ } finally {
91
+ setDraft(undefined);
92
+ }
93
+ };
94
+
95
+ return (
96
+ <div className="studio-request relative" style={size}>
97
+ <div
98
+ className="studio-screen absolute bottom-full left-0 origin-bottom-left pb-1.5"
99
+ style={{ width: `calc(${size.width}px * var(--zoom))` }}
100
+ >
101
+ <div className="studio-small flex h-6 items-center gap-2 whitespace-nowrap text-muted-foreground">
102
+ <span className="shrink-0" role="status">
103
+ <PendingStatus author={author} status={thread.status} />
104
+ </span>
105
+ <span aria-hidden>·</span>
106
+ <span className="min-w-0 truncate text-foreground">
107
+ <MessageWords text={thread.messages[0]?.body ?? ""} />
108
+ </span>
109
+ {editor.editable ? (
110
+ <Button
111
+ className="nodrag nopan ml-auto shrink-0"
112
+ onClick={() => threads.send(thread.id, { status: "dismissed" })}
113
+ size="xs"
114
+ variant="ghost"
115
+ >
116
+ <Trans>Cancel</Trans>
117
+ </Button>
118
+ ) : (
119
+ <span className="ml-auto shrink-0">
120
+ {i18n._(STATE_LABELS[threadState(thread)])}
121
+ </span>
122
+ )}
123
+ </div>
124
+ </div>
125
+ <div
126
+ className="studio-pending absolute inset-0 overflow-hidden"
127
+ data-waiting={waiting || undefined}
128
+ >
129
+ {sketch ? (
130
+ // What the person drew stays in sight while the page is built.
131
+ <div className="absolute top-0 left-0 opacity-80">
132
+ <SketchPage sketch={sketch} />
133
+ </div>
134
+ ) : null}
135
+ {waiting && !sketch ? <StillSkeleton guess={guess} /> : null}
136
+ <Presence active={!waiting} blank guess={guess} />
137
+ </div>
138
+ {resizable ? (
139
+ <ResizeHandles
140
+ onDraft={setDraft}
141
+ onReset={
142
+ target.kind === "view" && target.size ? () => resize() : undefined
143
+ }
144
+ onResize={resize}
145
+ size={shown}
146
+ />
147
+ ) : null}
148
+ </div>
149
+ );
150
+ });
151
+ RequestNode.displayName = "RequestNode";
@@ -63,6 +63,7 @@ import {
63
63
  CommentsTools,
64
64
  setCommentsAudience,
65
65
  } from "./comments";
66
+ import { MessageWords } from "./mentions";
66
67
  import { ReviewMarker } from "./review-marker";
67
68
  import { matchesWords, placeOf } from "./thread-place";
68
69
  import { VIEWPORTS } from "./viewports";
@@ -616,14 +617,16 @@ const ReviewComment = ({
616
617
  </div>
617
618
  </form>
618
619
  ) : (
619
- <p className="whitespace-pre-wrap text-pretty">{first?.body}</p>
620
+ <p className="whitespace-pre-wrap text-pretty">
621
+ <MessageWords text={first?.body ?? ""} />
622
+ </p>
620
623
  )}
621
624
  {replies.map((reply) => (
622
625
  <p
623
626
  className="studio-small mt-1 border-l-2 pl-2 text-muted-foreground"
624
627
  key={reply.at}
625
628
  >
626
- {reply.author}: {reply.body}
629
+ {reply.author}: <MessageWords text={reply.body} />
627
630
  </p>
628
631
  ))}
629
632
  <div className={cn("absolute -top-1 right-0", locked && "hidden")}>
@@ -1324,7 +1327,9 @@ export const ReviewReport = () => {
1324
1327
  {timeFormat.format(new Date(first.at))}
1325
1328
  </time>
1326
1329
  ) : null}
1327
- <p className="whitespace-pre-wrap text-pretty">{first?.body}</p>
1330
+ <p className="whitespace-pre-wrap text-pretty">
1331
+ <MessageWords text={first?.body ?? ""} />
1332
+ </p>
1328
1333
  </div>
1329
1334
  <div
1330
1335
  className="shrink-0 self-start overflow-hidden rounded-md ring-1 ring-border"
@@ -1,17 +1,8 @@
1
1
  import { Trans, useLingui } from "@lingui/react/macro";
2
2
  import { Icon } from "@studio/icons";
3
- import { Button } from "@studio/ui/shadcn/button";
4
- import { memo, useEffect, useMemo, useState } from "react";
3
+ import { memo, useEffect, useState } from "react";
5
4
  import { isOthers } from "../../src/shared/people-core.ts";
6
- import { threadState } from "../../src/shared/threads-core.ts";
7
- import { STATE_LABELS } from "../live/thread-state";
8
- import {
9
- neighbourGuess,
10
- Presence,
11
- StillSkeleton,
12
- sketchGuess,
13
- } from "../shell/presence";
14
- import type { Section, Thread } from "../types";
5
+ import type { Section } from "../types";
15
6
  import { useCanvas } from "./canvas-context";
16
7
  import { stepFrame, updateSection } from "./canvas-model";
17
8
  import { useCanvasUi, useCanvasUiStore } from "./canvas-ui";
@@ -20,126 +11,15 @@ import { namesNow } from "./flow-naming";
20
11
  import { resolveRenameTo, suggestRename } from "./flow-renames";
21
12
  import { ResizeHandles, type Size } from "./frame-resize";
22
13
  import { LabelAction } from "./label-action";
23
- import {
24
- type Box,
25
- type PlacedSection,
26
- sectionArea,
27
- sectionSizeShowing,
28
- } from "./layout";
29
- import { SketchPage } from "./sketch-boxes";
14
+ import { type PlacedSection, sectionArea, sectionSizeShowing } from "./layout";
30
15
  import { playHref } from "./viewports";
31
16
 
32
17
  export interface SectionNodeData {
33
18
  index: number;
34
19
  layout: PlacedSection;
35
- /** Requests for new views waiting in this section, with their cells. */
36
- pending: { box: Box; thread: Thread }[];
37
20
  section: Section;
38
21
  }
39
22
 
40
- const PendingStatus = ({
41
- author,
42
- status,
43
- }: {
44
- author?: string;
45
- status: Thread["status"];
46
- }) => {
47
- if (status !== "acknowledged") {
48
- return <Trans>Waiting for an agent</Trans>;
49
- }
50
- return author ? (
51
- <Trans>{author} is building this</Trans>
52
- ) : (
53
- <Trans>An agent is building this</Trans>
54
- );
55
- };
56
-
57
- const PendingCell = ({
58
- box,
59
- origin,
60
- thread,
61
- }: {
62
- box: Box;
63
- origin: Box;
64
- thread: Thread;
65
- }) => {
66
- const { editor, threads } = useCanvas();
67
- const { i18n } = useLingui();
68
- const latest = thread.messages.at(-1);
69
- const author = latest?.agent ? latest.author : undefined;
70
- const waiting = thread.status !== "acknowledged";
71
- const { sketch, target } = thread;
72
- const section = target.kind === "view" ? target.section : undefined;
73
- const row = target.kind === "view" ? target.row : undefined;
74
- // The page to come is drawn as what the person drew for it, else as the
75
- // step before it in its row, else as any view in its section.
76
- const guess = useMemo(() => {
77
- if (sketch) {
78
- return sketchGuess(sketch);
79
- }
80
- const prefixes = section ? [`${section}/`] : [];
81
- if (section && row) {
82
- prefixes.unshift(`${section}/${row}/`);
83
- }
84
- return neighbourGuess(prefixes);
85
- }, [row, section, sketch]);
86
- // The cell is all page, and the request is said above it, as a frame's
87
- // name is.
88
- return (
89
- <div
90
- className="pointer-events-auto absolute"
91
- style={{
92
- left: box.x - origin.x,
93
- top: box.y - origin.y,
94
- width: box.width,
95
- height: box.height,
96
- }}
97
- >
98
- <div
99
- className="studio-screen absolute bottom-full left-0 origin-bottom-left pb-1.5"
100
- style={{ width: `calc(${box.width}px * var(--zoom))` }}
101
- >
102
- <div className="studio-small flex h-6 items-center gap-2 whitespace-nowrap text-muted-foreground">
103
- <span className="shrink-0" role="status">
104
- <PendingStatus author={author} status={thread.status} />
105
- </span>
106
- <span aria-hidden>·</span>
107
- <span className="min-w-0 truncate text-foreground">
108
- {thread.messages[0]?.body}
109
- </span>
110
- {editor.editable ? (
111
- <Button
112
- className="nodrag nopan ml-auto shrink-0"
113
- onClick={() => threads.send(thread.id, { status: "dismissed" })}
114
- size="xs"
115
- variant="ghost"
116
- >
117
- <Trans>Cancel</Trans>
118
- </Button>
119
- ) : (
120
- <span className="ml-auto shrink-0">
121
- {i18n._(STATE_LABELS[threadState(thread)])}
122
- </span>
123
- )}
124
- </div>
125
- </div>
126
- <div
127
- className="studio-pending absolute inset-0 overflow-hidden"
128
- data-waiting={waiting || undefined}
129
- >
130
- {thread.sketch ? (
131
- // What the person drew stays in sight while the page is built.
132
- <div className="absolute top-0 left-0 opacity-80">
133
- <SketchPage sketch={thread.sketch} />
134
- </div>
135
- ) : null}
136
- {waiting && !thread.sketch ? <StillSkeleton guess={guess} /> : null}
137
- <Presence active={!waiting} blank guess={guess} />
138
- </div>
139
- </div>
140
- );
141
- };
142
-
143
23
  /**
144
24
  * Whose a section is, and the editor as it applies to it: someone else's
145
25
  * section is theirs, shown and commented on, not changed. Naming it
@@ -190,7 +70,7 @@ export const SectionNode = memo(
190
70
  );
191
71
  const canvasEditable = canvas.editable;
192
72
  const { t } = useLingui();
193
- const { layout, pending, section } = data;
73
+ const { layout, section } = data;
194
74
  const { editor, rename } = useSectionAuthor(section);
195
75
  const firstRow = section.rows.find((row) =>
196
76
  row.frames.some((frame) => stepFrame(frame))
@@ -264,15 +144,6 @@ export const SectionNode = memo(
264
144
  what="flow"
265
145
  />
266
146
  ) : null}
267
-
268
- {pending.map(({ box, thread }) => (
269
- <PendingCell
270
- box={box}
271
- key={thread.id}
272
- origin={layout}
273
- thread={thread}
274
- />
275
- ))}
276
147
  </div>
277
148
  );
278
149
  }
@@ -12,6 +12,7 @@ import { Avatar } from "../shell/avatar";
12
12
  import { useSpecHost } from "./canvas-context";
13
13
  import { useCanvasUiStore } from "./canvas-ui";
14
14
  import { ThreadBody } from "./comments";
15
+ import { MessageWords } from "./mentions";
15
16
 
16
17
  // A spec's threads beside its words, each level with them, pushed down so
17
18
  // none overlap. Three looks of one placement:
@@ -152,7 +153,9 @@ const ShortCard = ({
152
153
  {t`Its words are gone from the spec.`}
153
154
  </span>
154
155
  ) : null}
155
- <span className="studio-small line-clamp-3">{first?.body}</span>
156
+ <span className="studio-small line-clamp-3">
157
+ <MessageWords still text={first?.body ?? ""} />
158
+ </span>
156
159
  </button>
157
160
  );
158
161
  };