@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
@@ -76,7 +76,7 @@ import {
76
76
  } from "../shell/thread-list";
77
77
  import { shortTimeAgo } from "../shell/time-ago";
78
78
  import type { Thread, ThreadAudience, ThreadTarget } from "../types";
79
- import { detailsOf, PromptEditor } from "../ui/prompt-editor";
79
+ import { PromptEditor } from "../ui/prompt-editor";
80
80
  import { ReferenceDetails, ReferenceText } from "../ui/reference";
81
81
  import {
82
82
  type ScreenPoint,
@@ -92,6 +92,16 @@ import {
92
92
  } from "./command-menu";
93
93
  import { acceptRename } from "./flow-renames";
94
94
  import { useFollowPin } from "./follow-pin";
95
+ import {
96
+ MessageWords,
97
+ mentionsMe,
98
+ mentionTrigger,
99
+ POSTED_TRIGGERS,
100
+ useFrames,
101
+ useMentionable,
102
+ usePeople,
103
+ usePostedDetails,
104
+ } from "./mentions";
95
105
  import { overPin, QUICK_BAR_GAP } from "./quick-bar";
96
106
  import {
97
107
  ReviewMarker,
@@ -430,10 +440,23 @@ export const MessageInput = ({
430
440
  }) => {
431
441
  const [body, setBody] = useState(initial);
432
442
  const { t } = useLingui();
433
- const triggers = useMemo(
434
- () => (commands.length > 0 ? [commandTrigger(commands, t`Commands`)] : []),
435
- [commands, t]
436
- );
443
+ const people = usePeople({ ask: true });
444
+ const frames = useFrames();
445
+ const triggers = useMemo(() => {
446
+ // The "@" menu is named for what it lists.
447
+ let mentions = t`People and frames`;
448
+ if (frames.length === 0) {
449
+ mentions = t`People`;
450
+ } else if (people.length === 0) {
451
+ mentions = t`Frames`;
452
+ }
453
+ return [
454
+ ...(commands.length > 0 ? [commandTrigger(commands, t`Commands`)] : []),
455
+ ...(people.length > 0 || frames.length > 0
456
+ ? [mentionTrigger(people, frames, mentions)]
457
+ : []),
458
+ ];
459
+ }, [commands, frames, people, t]);
437
460
  const sendBody = useStudioAction(
438
461
  async (text: string) => {
439
462
  // False keeps the words: the post was held back, not made.
@@ -783,7 +806,7 @@ export const Reactions = ({
783
806
  );
784
807
  };
785
808
 
786
- /** A message's words, with the commands it names as chips. */
809
+ /** A message's words, with the commands and people it names as chips. */
787
810
  const MessageText = ({ body }: { body: string }) =>
788
811
  body ? (
789
812
  <p className="whitespace-pre-wrap">
@@ -791,9 +814,6 @@ const MessageText = ({ body }: { body: string }) =>
791
814
  </p>
792
815
  ) : null;
793
816
 
794
- /** The triggers a posted message's chips can start with: commands'. */
795
- const POSTED_TRIGGERS = ["/"];
796
-
797
817
  /** One entry in a thread: who, when, what they said, and anything under it. */
798
818
  const Entry = ({
799
819
  agent,
@@ -884,7 +904,7 @@ const ClosingLine = ({ body }: { body: string }) => {
884
904
  <p
885
905
  className={cn("whitespace-pre-wrap", long && !whole && "line-clamp-4")}
886
906
  >
887
- {body}
907
+ <MessageWords text={body} />
888
908
  </p>
889
909
  {long ? (
890
910
  <Button
@@ -1233,15 +1253,12 @@ export const ThreadBody = ({
1233
1253
  threads: ThreadsApi;
1234
1254
  }) => {
1235
1255
  const { i18n, t } = useLingui();
1236
- // Every command: the details of those its messages name (one may have
1237
- // left the / menu since), and, in work for the agent, what a reply or an
1238
- // edit can run as well.
1256
+ // Every command and person: the details of those its messages name (a
1257
+ // command may have left the / menu since), and, in work for the agent,
1258
+ // what a reply or an edit can run as well.
1239
1259
  const [answer] = useCommands(!GUEST_REVIEW);
1240
1260
  const known = answer?.commands ?? NO_COMMANDS;
1241
- const describe = useMemo(
1242
- () => detailsOf([commandTrigger(known, "")]),
1243
- [known]
1244
- );
1261
+ const describe = usePostedDetails();
1245
1262
  const commands = audienceOf(thread) === "agent" ? known : NO_COMMANDS;
1246
1263
  const closed = isClosed(thread);
1247
1264
  const state = threadState(thread);
@@ -1675,9 +1692,12 @@ export const usePinFilter = (showResolved: boolean, activeThread?: string) => {
1675
1692
  } = useCommentsView();
1676
1693
  const canvas = useCanvasIfAny();
1677
1694
  const isTeamComment = useIsTeamComment(canvas?.prototype.slug ?? "");
1695
+ const me = useMentionable();
1678
1696
  const resolvedShown = showResolved && status !== "open";
1679
- // On a deployed studio, "You" leaves only a guest's own pins.
1697
+ // On a deployed studio, "You" leaves only a guest's own pins; Mentions,
1698
+ // only those of threads that mention you.
1680
1699
  const onlyYours = audience === "yours";
1700
+ const onlyMentions = audience === "mentions";
1681
1701
  // Reviewers' imported comments stay within Reviews: on the canvas while
1682
1702
  // it shows (one review's, when one is picked), and never beside the team's.
1683
1703
  if (reviewsShowing) {
@@ -1689,7 +1709,8 @@ export const usePinFilter = (showResolved: boolean, activeThread?: string) => {
1689
1709
  thread.id === activeThread ||
1690
1710
  (isTeamComment(thread) &&
1691
1711
  (resolvedShown || !isClosed(thread)) &&
1692
- !(onlyYours && !isGuestThread(thread)));
1712
+ !(onlyYours && !isGuestThread(thread)) &&
1713
+ !(onlyMentions && !mentionsMe(me)(thread)));
1693
1714
  };
1694
1715
 
1695
1716
  /**
@@ -1966,14 +1987,15 @@ const says = (query: string) => {
1966
1987
 
1967
1988
  /**
1968
1989
  * The threads `filter` shows that say `query`: open ones (the agent's
1969
- * replies first, then newest), then resolved ones, newest first.
1990
+ * replies first, then newest), then resolved ones, newest first. `me`, a
1991
+ * contributor's slug, is who Mentions is for.
1970
1992
  */
1971
1993
  export const filterThreads = <T extends Thread>(
1972
1994
  threads: T[],
1973
1995
  { audience, status }: CommentFilter,
1974
- query = ""
1996
+ { me, query = "" }: { me?: string; query?: string } = {}
1975
1997
  ) => {
1976
- const mine = threads.filter(byFilter(audience)).filter(says(query));
1998
+ const mine = threads.filter(byFilter(audience, me)).filter(says(query));
1977
1999
  const open = mine.filter((thread) => !isClosed(thread)).sort(yourTurnFirst);
1978
2000
  const closed =
1979
2001
  status === "open" ? [] : mine.filter(isClosed).sort(newestFirst);
@@ -1997,6 +2019,15 @@ const emptyCopy = (
1997
2019
  ),
1998
2020
  };
1999
2021
  }
2022
+ if (filter.audience === "mentions") {
2023
+ return {
2024
+ icon: "AtSign",
2025
+ title: <Trans>No mentions</Trans>,
2026
+ line: (
2027
+ <Trans>Comments where someone writes @ and your name show here.</Trans>
2028
+ ),
2029
+ };
2030
+ }
2000
2031
  if (filter.audience === "people") {
2001
2032
  return {
2002
2033
  icon: "MessageCircle",
@@ -2061,6 +2092,7 @@ const FROM_OPTIONS: { id: ThreadFilter; label: MessageDescriptor }[] =
2061
2092
  { id: "all", label: msg`All` },
2062
2093
  { id: "people", label: msg`People` },
2063
2094
  { id: "agents", label: msg`Agents` },
2095
+ { id: "mentions", label: msg`Mentions` },
2064
2096
  ];
2065
2097
 
2066
2098
  /**
@@ -2075,6 +2107,8 @@ const FilterMenu = ({
2075
2107
  value: CommentFilter;
2076
2108
  }) => {
2077
2109
  const { i18n, t } = useLingui();
2110
+ // Only someone the workspace knows can be mentioned.
2111
+ const known = useMentionable() !== undefined;
2078
2112
  const label = t`Filter comments`;
2079
2113
  const filtered = value.audience !== DEFAULT_FILTER.audience;
2080
2114
  return (
@@ -2108,11 +2142,13 @@ const FilterMenu = ({
2108
2142
  }
2109
2143
  value={value.audience}
2110
2144
  >
2111
- {FROM_OPTIONS.map(({ id, label: name }) => (
2112
- <DropdownMenuRadioItem key={id} value={id}>
2113
- {i18n._(name)}
2114
- </DropdownMenuRadioItem>
2115
- ))}
2145
+ {FROM_OPTIONS.filter(({ id }) => known || id !== "mentions").map(
2146
+ ({ id, label: name }) => (
2147
+ <DropdownMenuRadioItem key={id} value={id}>
2148
+ {i18n._(name)}
2149
+ </DropdownMenuRadioItem>
2150
+ )
2151
+ )}
2116
2152
  </DropdownMenuRadioGroup>
2117
2153
  </DropdownMenuGroup>
2118
2154
  </DropdownMenuContent>
@@ -2269,14 +2305,15 @@ const CommentsBody = ({
2269
2305
  query: string;
2270
2306
  threads: Thread[];
2271
2307
  }) => {
2272
- const shown = filterThreads(threads, filter, query);
2308
+ const me = useMentionable();
2309
+ const shown = filterThreads(threads, filter, { me, query });
2273
2310
  const words = query.trim();
2274
2311
  // A search that finds nothing says so in a line, where without it the
2275
2312
  // filter would show threads.
2276
2313
  if (
2277
2314
  words !== "" &&
2278
2315
  shown.length === 0 &&
2279
- filterThreads(threads, filter).length > 0
2316
+ filterThreads(threads, filter, { me }).length > 0
2280
2317
  ) {
2281
2318
  return (
2282
2319
  <p className="px-3 py-4 text-center text-muted-foreground">
@@ -0,0 +1,135 @@
1
+ import { isRecord, isText } from "../../src/shared/checks.ts";
2
+ import {
3
+ type ChangePlace,
4
+ changePlace,
5
+ type PlacedElement,
6
+ } from "../../src/shared/threads-core.ts";
7
+ import type { ThreadTarget } from "../types";
8
+
9
+ // A link to elements on a frame (?element=<place>), copied from the menu a
10
+ // right-click on a frame opens: to the element under the pointer. It finds
11
+ // its frame as an agent's "where" does (changePlace), after the frame moves,
12
+ // and its elements as a comment's pin does: by selector, words and the code
13
+ // that renders them, in the states of the page they are in, folded onto
14
+ // what opens them while that is closed. Opening one: linked-element.tsx.
15
+
16
+ /** The query parameter that holds a link's place. */
17
+ const ELEMENT_PARAM = "element";
18
+
19
+ /** The longest of each thing kept about an element, as a comment keeps it. */
20
+ const MOST = { code: 300, selector: 500, text: 200, state: 200 } as const;
21
+ /** At most this many states, openers or more elements. */
22
+ const MOST_ENTRIES = 10;
23
+
24
+ const shortText = (value: unknown, most: number): string | undefined =>
25
+ isText(value) && value.length <= most ? value : undefined;
26
+
27
+ const states = (value: unknown): string[] | undefined => {
28
+ if (!Array.isArray(value)) {
29
+ return;
30
+ }
31
+ const kept = value
32
+ .slice(0, MOST_ENTRIES)
33
+ .flatMap((state) => shortText(state, MOST.state) ?? []);
34
+ return kept.length > 0 ? kept : undefined;
35
+ };
36
+
37
+ /** An element as a link keeps it, with only the fields it has. */
38
+ const placedElement = (value: unknown): PlacedElement | undefined => {
39
+ if (!isRecord(value)) {
40
+ return;
41
+ }
42
+ const selector = shortText(value.selector, MOST.selector);
43
+ if (!selector) {
44
+ return;
45
+ }
46
+ const code = shortText(value.code, MOST.code);
47
+ const text = shortText(value.text, MOST.text);
48
+ const within = states(value.within);
49
+ return {
50
+ selector,
51
+ ...(code ? { code } : {}),
52
+ ...(text ? { text } : {}),
53
+ ...(within ? { within } : {}),
54
+ };
55
+ };
56
+
57
+ const placedElements = (value: unknown): PlacedElement[] | undefined => {
58
+ if (!Array.isArray(value)) {
59
+ return;
60
+ }
61
+ const kept = value
62
+ .slice(0, MOST_ENTRIES)
63
+ .flatMap((entry) => placedElement(entry) ?? []);
64
+ return kept.length > 0 ? kept : undefined;
65
+ };
66
+
67
+ /**
68
+ * A place a link can go to, from what it says: its frame and view (as
69
+ * changePlace keeps them) and, for elements, how to find them on the page.
70
+ * Anything else is left out.
71
+ */
72
+ const readPlace = (value: unknown): ChangePlace | undefined => {
73
+ const place = changePlace(value);
74
+ if (!(place && place.kind === "element" && isRecord(value))) {
75
+ return place;
76
+ }
77
+ const first = placedElement(value);
78
+ const openers = placedElements(value.openers);
79
+ const also = placedElements(value.also);
80
+ return {
81
+ ...place,
82
+ ...first,
83
+ ...(openers ? { openers } : {}),
84
+ ...(also ? { also } : {}),
85
+ };
86
+ };
87
+
88
+ /**
89
+ * Where a link to what a comment would be on goes: its elements, or else its
90
+ * whole frame. None for what is on no frame.
91
+ */
92
+ export const placeToLink = (target: ThreadTarget): ChangePlace | undefined => {
93
+ if (!(target.kind === "element" || target.kind === "frame")) {
94
+ return;
95
+ }
96
+ return (
97
+ readPlace(target) ??
98
+ changePlace({
99
+ kind: "frame",
100
+ frame: target.frame,
101
+ view: target.view,
102
+ params: target.params,
103
+ })
104
+ );
105
+ };
106
+
107
+ /** A link to a place, on the canvas open at `href`. */
108
+ export const elementLink = (place: ChangePlace, href: string): string => {
109
+ const url = new URL(href);
110
+ url.search = new URLSearchParams({
111
+ [ELEMENT_PARAM]: JSON.stringify(place),
112
+ }).toString();
113
+ url.hash = "";
114
+ return url.toString();
115
+ };
116
+
117
+ /** The place an address links to, if it names one Dex can read. */
118
+ export const placeFromAddress = (search: string): ChangePlace | undefined => {
119
+ const value = new URLSearchParams(search).get(ELEMENT_PARAM);
120
+ if (!value) {
121
+ return;
122
+ }
123
+ try {
124
+ return readPlace(JSON.parse(value));
125
+ } catch {
126
+ return;
127
+ }
128
+ };
129
+
130
+ /** An address without its link, once the canvas has gone there. */
131
+ export const withoutLink = (href: string): string => {
132
+ const url = new URL(href);
133
+ url.searchParams.delete(ELEMENT_PARAM);
134
+ return url.toString();
135
+ };
@@ -124,6 +124,29 @@ export const textRun = (element: Element): Text[] | undefined => {
124
124
  export const isEditableText = (element: Element) =>
125
125
  textRun(element) !== undefined;
126
126
 
127
+ /** Where the dev server stamps an element's words as written (source-stamp.ts). */
128
+ const TEXT_PLACE = "data-studio-text";
129
+
130
+ const textOfElement = (element: Element) =>
131
+ (element.textContent ?? "").replace(WHITESPACE_RE, " ").trim();
132
+
133
+ /**
134
+ * Where an element's text is written in the code, as the dev server stamps
135
+ * it: the element's own place, or that of the component around it when it
136
+ * shows only this text (a button's label in a span of its own). None when
137
+ * the text is written elsewhere, or what is around it says more.
138
+ */
139
+ export const textPlace = (element: Element): string | undefined => {
140
+ const stamped = element.closest(`[${TEXT_PLACE}]`);
141
+ if (
142
+ !stamped ||
143
+ (stamped !== element && textOfElement(stamped) !== textOfElement(element))
144
+ ) {
145
+ return;
146
+ }
147
+ return stamped.getAttribute(TEXT_PLACE) ?? undefined;
148
+ };
149
+
127
150
  /** Whether an element shows: not hidden, nor see-through. */
128
151
  const shows = (element: Element) =>
129
152
  element.checkVisibility?.({
@@ -0,0 +1,265 @@
1
+ import type { MessageDescriptor } from "@lingui/core";
2
+ import { msg } from "@lingui/core/macro";
3
+ import { Trans, useLingui } from "@lingui/react/macro";
4
+ import { Button } from "@studio/ui/shadcn/button";
5
+ import { Checkbox } from "@studio/ui/shadcn/checkbox";
6
+ import {
7
+ Dialog,
8
+ DialogContent,
9
+ DialogDescription,
10
+ DialogFooter,
11
+ DialogHeader,
12
+ DialogTitle,
13
+ } from "@studio/ui/shadcn/dialog";
14
+ import { Spinner } from "@studio/ui/shadcn/spinner";
15
+ import { cn } from "cn";
16
+ import { useState, useSyncExternalStore } from "react";
17
+ import { parseFrameKey } from "../../src/shared/canvas-core.ts";
18
+ import {
19
+ AGENT_PREPARED,
20
+ EXPORT_COMMAND,
21
+ EXPORT_KINDS,
22
+ type ExportChoice,
23
+ type ExportKind,
24
+ exportFileName,
25
+ } from "../../src/shared/export-core.ts";
26
+ import { problemsOf } from "../live/studio-action";
27
+ import { studioRequest } from "../live/studio-request";
28
+ import { saveFile } from "../save-file";
29
+ import { frameTarget } from "./anchoring";
30
+ import { useCanvas } from "./canvas-context";
31
+ import type { MenuFrame } from "./frame-context-menu";
32
+
33
+ // Export…, from the frames' right-click menu: the frames, or their whole
34
+ // sections, as a zip that opens by double-click, offline
35
+ // (src/server/export/), saved where the browser saves downloads. Each kind
36
+ // is a card; the content and source packs need the views prepared first,
37
+ // which the agent does (templates/skills/export-prototype).
38
+
39
+ const KINDS: Record<
40
+ ExportKind,
41
+ { description: MessageDescriptor; title: MessageDescriptor }
42
+ > = {
43
+ clickable: {
44
+ title: msg`Clickable`,
45
+ description: msg`One page that steps through the frames, as Play does.`,
46
+ },
47
+ pages: {
48
+ title: msg`Page per frame`,
49
+ description: msg`A page for each frame, to link to one directly.`,
50
+ },
51
+ content: {
52
+ title: msg`Content pack`,
53
+ description: msg`The words and data in content.js, to change without the code.`,
54
+ },
55
+ source: {
56
+ title: msg`Source pack`,
57
+ description: msg`The views' own files beside it, to build on.`,
58
+ },
59
+ };
60
+
61
+ // Which frames the dialog is open for: set from the menu, which closes as
62
+ // the dialog opens.
63
+ let asked: MenuFrame[] | undefined;
64
+ const listeners = new Set<() => void>();
65
+ const setAsked = (frames: MenuFrame[] | undefined) => {
66
+ asked = frames;
67
+ for (const listener of listeners) {
68
+ listener();
69
+ }
70
+ };
71
+ const subscribe = (listener: () => void) => {
72
+ listeners.add(listener);
73
+ return () => listeners.delete(listener);
74
+ };
75
+
76
+ /** Open Export… for these frames. */
77
+ export const openExport = (frames: MenuFrame[]) => setAsked(frames);
78
+
79
+ const KindCard = ({
80
+ checked,
81
+ kind,
82
+ onPick,
83
+ }: {
84
+ checked: boolean;
85
+ kind: ExportKind;
86
+ onPick: () => void;
87
+ }) => {
88
+ const { i18n } = useLingui();
89
+ return (
90
+ <label
91
+ className={cn(
92
+ "flex cursor-pointer flex-col items-start gap-1 rounded-lg border p-3 transition-colors has-[:focus-visible]:ring-2 has-[:focus-visible]:ring-ring",
93
+ checked
94
+ ? "border-primary bg-primary/5"
95
+ : "border-border hover:bg-muted/60"
96
+ )}
97
+ >
98
+ <input
99
+ checked={checked}
100
+ className="sr-only"
101
+ name="export-kind"
102
+ onChange={onPick}
103
+ type="radio"
104
+ value={kind}
105
+ />
106
+ <span className="font-medium">{i18n._(KINDS[kind].title)}</span>
107
+ <span className="text-muted-foreground text-xs">
108
+ {i18n._(KINDS[kind].description)}
109
+ </span>
110
+ {AGENT_PREPARED.has(kind) ? (
111
+ <span className="text-muted-foreground text-xs">
112
+ <Trans>The agent prepares the views first.</Trans>
113
+ </span>
114
+ ) : null}
115
+ </label>
116
+ );
117
+ };
118
+
119
+ const ExportDialog = ({
120
+ frames,
121
+ onClose,
122
+ }: {
123
+ frames: MenuFrame[];
124
+ onClose: () => void;
125
+ }) => {
126
+ const { i18n, t } = useLingui();
127
+ const { editor, prototype, threads } = useCanvas();
128
+ const [kind, setKind] = useState<ExportKind>("clickable");
129
+ const [whole, setWhole] = useState(false);
130
+ const [flows, setFlows] = useState(false);
131
+ const [working, setWorking] = useState(false);
132
+ const [problem, setProblem] = useState<string>();
133
+
134
+ const keys = frames.map(({ key }) => key);
135
+ const sections = [...new Set(keys.map((key) => parseFrameKey(key).section))];
136
+ // Each row is a flow to switch to: there is a choice only with two or more.
137
+ const flowCount = whole
138
+ ? editor.canvas.sections
139
+ .filter((section) => sections.includes(section.id))
140
+ .reduce((count, section) => count + section.rows.length, 0)
141
+ : new Set(
142
+ keys.map((key) => {
143
+ const { row, section } = parseFrameKey(key);
144
+ return `${section}/${row}`;
145
+ })
146
+ ).size;
147
+ const switching = flows && flowCount > 1;
148
+ const choice: ExportChoice = {
149
+ kind,
150
+ flows: switching,
151
+ ...(whole ? { sections } : { frames: keys }),
152
+ };
153
+
154
+ const exportNow = async () => {
155
+ setWorking(true);
156
+ setProblem(undefined);
157
+ try {
158
+ const zip = await studioRequest("export", {
159
+ method: "POST",
160
+ query: { slug: prototype.slug },
161
+ body: choice,
162
+ });
163
+ saveFile(zip, exportFileName(prototype.title ?? prototype.slug));
164
+ onClose();
165
+ } catch (error) {
166
+ setProblem(problemsOf(error, i18n).join(" ") || t`The export failed.`);
167
+ } finally {
168
+ setWorking(false);
169
+ }
170
+ };
171
+
172
+ const askAgent = () => {
173
+ const [first] = frames;
174
+ if (!first) {
175
+ return;
176
+ }
177
+ const scope = whole
178
+ ? t`their sections (${sections.join(", ")})`
179
+ : t`these frames (${keys.join(", ")})`;
180
+ threads.create(
181
+ frameTarget(first.key, first.frame),
182
+ `/${EXPORT_COMMAND} ${kind}: ${scope}${switching ? t`, letting people switch flows` : ""}.`
183
+ );
184
+ onClose();
185
+ };
186
+
187
+ return (
188
+ <Dialog onOpenChange={(open) => (open ? undefined : onClose())} open>
189
+ <DialogContent className="sm:max-w-lg">
190
+ <DialogHeader>
191
+ <DialogTitle>
192
+ <Trans>Export frames</Trans>
193
+ </DialogTitle>
194
+ <DialogDescription>
195
+ <Trans>
196
+ A zip that opens by double-click, offline: a page, its script and
197
+ its stylesheet. It goes to your downloads.
198
+ </Trans>
199
+ </DialogDescription>
200
+ </DialogHeader>
201
+ <fieldset className="grid grid-cols-2 gap-2">
202
+ <legend className="sr-only">
203
+ <Trans>What to export</Trans>
204
+ </legend>
205
+ {EXPORT_KINDS.map((each) => (
206
+ <KindCard
207
+ checked={kind === each}
208
+ key={each}
209
+ kind={each}
210
+ onPick={() => setKind(each)}
211
+ />
212
+ ))}
213
+ </fieldset>
214
+ <div className="flex flex-col gap-2">
215
+ {/* biome-ignore lint/a11y/noLabelWithoutControl: the checkbox is inside the label */}
216
+ <label className="flex items-center gap-2">
217
+ <Checkbox
218
+ checked={whole}
219
+ onCheckedChange={(checked) => setWhole(checked)}
220
+ />
221
+ {sections.length > 1 ? (
222
+ <Trans>All of their {sections.length} sections</Trans>
223
+ ) : (
224
+ <Trans>All of their section</Trans>
225
+ )}
226
+ </label>
227
+ {flowCount > 1 ? (
228
+ // biome-ignore lint/a11y/noLabelWithoutControl: the checkbox is inside the label
229
+ <label className="flex items-center gap-2">
230
+ <Checkbox
231
+ checked={flows}
232
+ onCheckedChange={(checked) => setFlows(checked)}
233
+ />
234
+ <Trans>Let people switch between flows</Trans>
235
+ </label>
236
+ ) : null}
237
+ </div>
238
+ {problem ? (
239
+ <p className="text-destructive text-sm" role="alert">
240
+ {problem}
241
+ </p>
242
+ ) : null}
243
+ <DialogFooter>
244
+ {AGENT_PREPARED.has(kind) ? (
245
+ <Button onClick={askAgent} variant="outline">
246
+ <Trans>Ask the agent to prepare it</Trans>
247
+ </Button>
248
+ ) : null}
249
+ <Button disabled={working} onClick={exportNow}>
250
+ {working ? <Spinner /> : null}
251
+ {working ? <Trans>Exporting…</Trans> : <Trans>Export</Trans>}
252
+ </Button>
253
+ </DialogFooter>
254
+ </DialogContent>
255
+ </Dialog>
256
+ );
257
+ };
258
+
259
+ /** Where Export… opens, on the canvas. */
260
+ export const ExportDialogHost = () => {
261
+ const frames = useSyncExternalStore(subscribe, () => asked);
262
+ return frames ? (
263
+ <ExportDialog frames={frames} onClose={() => setAsked(undefined)} />
264
+ ) : null;
265
+ };