@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
@@ -59,8 +59,10 @@ import { ActionNotice, TopNotices } from "../canvas/change-notice";
59
59
  import {
60
60
  CommentsPanel,
61
61
  FloatingCommentCard,
62
+ showWhileHidden,
62
63
  useHideCommentsWhile,
63
64
  useIsTeamComment,
65
+ useOpenedWhileHidden,
64
66
  } from "../canvas/comments";
65
67
  import { DrawLayer } from "../canvas/draw-layer";
66
68
  import type { DrawKind } from "../canvas/draw-model";
@@ -68,6 +70,7 @@ import {
68
70
  CanvasViewProvider,
69
71
  useCanvasView,
70
72
  } from "../canvas/engine/canvas-view";
73
+ import { FindBar } from "../canvas/find-bar";
71
74
  import { FlowCanvas } from "../canvas/flow-canvas";
72
75
  import { askName } from "../canvas/flow-naming";
73
76
  import { CommentsOrReviewsBody } from "../canvas/imported-reviews";
@@ -184,6 +187,8 @@ const savedCanvas = (editor: CanvasEditor) =>
184
187
  const CanvasFloatingComment = ({ threads }: { threads: ThreadsApi }) => {
185
188
  const ui = useCanvasUiStore();
186
189
  const floating = useCanvasUi((state) => state.floating);
190
+ const specThread = useCanvasUi((state) => state.specThread);
191
+ useOpenedWhileHidden(floating, specThread);
187
192
  return (
188
193
  <FloatingCommentCard
189
194
  floating={floating}
@@ -285,23 +290,22 @@ const CanvasWorkspace = ({ prototype }: { prototype: Prototype }) => {
285
290
  const seeChange = useRef<(thread: Thread) => void>(() => undefined);
286
291
  // The heads-up opens comments with one function for good, so the
287
292
  // canvas rendering never renders it again.
288
- const openThreadNow = useRef<(id: string, at: ScreenPoint) => void>(
289
- () => undefined
290
- );
293
+ const openThreadNow = useRef<(id: string) => void>(() => undefined);
291
294
  const openFromBar = useCallback(
292
- (id: string, at: ScreenPoint) => openThreadNow.current(id, at),
295
+ (id: string) => openThreadNow.current(id),
293
296
  []
294
297
  );
295
298
  // A spec's thread opens beside its spec, where its words are: on the
296
299
  // canvas when the spec is placed there, else with the spec full screen.
297
300
  // A document's, and any other, as a floating card.
298
301
  const openAnyThread = useCallback(
299
- (id: string, at: ScreenPoint) => {
302
+ (id: string, at?: ScreenPoint) => {
300
303
  const thread = threads.threads.find((entry) => entry.id === id);
301
304
  // Reading a completed comment counts its change as seen.
302
305
  if (thread) {
303
306
  seeChange.current(thread);
304
307
  }
308
+ showWhileHidden(id);
305
309
  const spec =
306
310
  thread?.target.kind === "spec" ? thread.target.spec : undefined;
307
311
  if (spec === undefined || spec.startsWith("docs/")) {
@@ -315,9 +319,6 @@ const CanvasWorkspace = ({ prototype }: { prototype: Prototype }) => {
315
319
  },
316
320
  [threads.threads, ui, openThread, editor.canvas, fullScreenSpec]
317
321
  );
318
- useLayoutEffect(() => {
319
- openThreadNow.current = openAnyThread;
320
- }, [openAnyThread]);
321
322
  const focusThread = useThreadFocus(
322
323
  threads.threads,
323
324
  editor.canvas,
@@ -432,6 +433,23 @@ const CanvasWorkspace = ({ prototype }: { prototype: Prototype }) => {
432
433
  threads: threads.threads,
433
434
  });
434
435
  seeChange.current = agentChanges.see;
436
+ // From the heads-up, the canvas moves to the comment, and its card opens
437
+ // at its pin. One an agent completed outlines where its change landed,
438
+ // and goes there when the comment has no pin (a request for a view, or a
439
+ // comment on the whole file).
440
+ const { outline } = agentChanges;
441
+ useLayoutEffect(() => {
442
+ openThreadNow.current = (id) => {
443
+ const thread = threads.threads.find((entry) => entry.id === id);
444
+ if (!thread) {
445
+ return;
446
+ }
447
+ const atPin = focusThread(thread);
448
+ if (thread.status === "resolved") {
449
+ outline([thread], { move: !atPin });
450
+ }
451
+ };
452
+ }, [threads.threads, focusThread, outline]);
435
453
  const { toggle: togglePanel } = panels;
436
454
  const toggleStickers = useCallback(
437
455
  () => togglePanel("stickers"),
@@ -696,6 +714,7 @@ const CanvasWorkspace = ({ prototype }: { prototype: Prototype }) => {
696
714
  GUEST_REVIEW && !focused && panels.right === "comments"
697
715
  }
698
716
  />
717
+ <FindBar writable={studio.local} />
699
718
  <ServerNotice />
700
719
  <TopNotices>
701
720
  <ActionNotice notice={inspect.notice} />
@@ -16,7 +16,13 @@ import {
16
16
  import { Switch } from "@studio/ui/shadcn/switch";
17
17
  import { Textarea } from "@studio/ui/shadcn/textarea";
18
18
  import { cn } from "cn";
19
- import { Fragment, type ReactNode, useId, useState } from "react";
19
+ import {
20
+ type DragEvent,
21
+ Fragment,
22
+ type ReactNode,
23
+ useId,
24
+ useState,
25
+ } from "react";
20
26
  import {
21
27
  type Command,
22
28
  type CommandSwitch,
@@ -254,6 +260,13 @@ const QuickBarPicker = ({
254
260
  }) => {
255
261
  const { t } = useLingui();
256
262
  const [dragging, setDragging] = useState<string>();
263
+ // Only a skill being moved, on dragenter as on dragover (file-drop.ts says
264
+ // why): a file dragged over the quick bar is not one of its skills.
265
+ const takeMove = (event: DragEvent) => {
266
+ if (dragging) {
267
+ event.preventDefault();
268
+ }
269
+ };
257
270
  const choose = useStudioAction(
258
271
  (quick: string[]) =>
259
272
  studioRequest("commands", { method: "PUT", body: { quick } }),
@@ -307,7 +320,8 @@ const QuickBarPicker = ({
307
320
  draggable
308
321
  key={name}
309
322
  onDragEnd={() => setDragging(undefined)}
310
- onDragOver={(event) => event.preventDefault()}
323
+ onDragEnter={takeMove}
324
+ onDragOver={takeMove}
311
325
  onDragStart={() => setDragging(name)}
312
326
  onDrop={() => {
313
327
  if (dragging && dragging !== name) {
@@ -1,5 +1,6 @@
1
1
  import { Plural, Trans, useLingui } from "@lingui/react/macro";
2
2
  import { Icon } from "@studio/icons";
3
+ import { useFileDrop } from "@studio/ui/file-drop";
3
4
  import { Segmented } from "@studio/ui/segmented";
4
5
  import {
5
6
  Attachment,
@@ -23,7 +24,6 @@ import { Textarea } from "@studio/ui/shadcn/textarea";
23
24
  import { cn } from "cn";
24
25
  import {
25
26
  type ClipboardEvent,
26
- type DragEvent,
27
27
  type FormEvent,
28
28
  type KeyboardEvent,
29
29
  type ReactNode,
@@ -53,7 +53,9 @@ import { PRODUCT } from "../../src/shared/product.ts";
53
53
  // what was written when it doesn't go. The same form serves Dex's dialog
54
54
  // and the extension's page (extension/feedback.tsx), which starts it with the
55
55
  // page's screenshot attached; Markup ports it, line for line, into its shadow
56
- // root.
56
+ // root. Each puts it on a surface with no padding of its own: the form pads
57
+ // itself, so it fills the surface to the edge and a file dropped anywhere on
58
+ // what looks like the form lands on it, not on the page, which would open it.
57
59
 
58
60
  /**
59
61
  * Dex information, sent when the person keeps "Add Dex information"
@@ -117,7 +119,6 @@ export const FeedbackForm = ({
117
119
  const [files, setFiles] = useState<File[]>(draft.files ?? []);
118
120
  const [withDetails, setWithDetails] = useState(true);
119
121
  const [status, setStatus] = useState<Status>({ step: "writing" });
120
- const [over, setOver] = useState(false);
121
122
 
122
123
  const feedback: Feedback = {
123
124
  kind,
@@ -149,6 +150,9 @@ export const FeedbackForm = ({
149
150
  // Every file, so one it can't take stays to say why, not vanish.
150
151
  setFiles((current) => [...current, ...more]);
151
152
 
153
+ // A file dropped anywhere on the form attaches.
154
+ const { over, zone } = useFileDrop(attach);
155
+
152
156
  if (status.step === "sent") {
153
157
  return <Thanks email={status.email} onClose={onClose} />;
154
158
  }
@@ -164,24 +168,9 @@ export const FeedbackForm = ({
164
168
  // biome-ignore lint/a11y/noNoninteractiveElementInteractions: ⌘Enter sends from any field, and files dropped anywhere on the form attach
165
169
  <form
166
170
  aria-labelledby={`${ids}-title`}
167
- className="flex min-w-0 flex-col gap-4"
171
+ className="flex min-w-0 flex-col gap-4 p-6"
168
172
  noValidate
169
- onDragLeave={(event: DragEvent) => {
170
- if (!event.currentTarget.contains(event.relatedTarget as Node)) {
171
- setOver(false);
172
- }
173
- }}
174
- onDragOver={(event: DragEvent) => {
175
- if (event.dataTransfer.types.includes("Files")) {
176
- event.preventDefault();
177
- setOver(true);
178
- }
179
- }}
180
- onDrop={(event: DragEvent) => {
181
- event.preventDefault();
182
- setOver(false);
183
- attach([...event.dataTransfer.files]);
184
- }}
173
+ {...zone}
185
174
  onKeyDown={(event: KeyboardEvent) => {
186
175
  if (event.key === "Enter" && (event.metaKey || event.ctrlKey)) {
187
176
  event.preventDefault();
@@ -608,7 +597,7 @@ const Thumbnail = ({ file }: { file: File }) => {
608
597
 
609
598
  /** Sent: thanks, where a reply would go, and a way out. */
610
599
  const Thanks = ({ email, onClose }: { email: string; onClose: () => void }) => (
611
- <div className="flex flex-col items-center gap-3 py-4 text-center">
600
+ <div className="flex flex-col items-center gap-3 px-6 py-10 text-center">
612
601
  <span className="flex size-10 items-center justify-center rounded-xl bg-muted">
613
602
  <Icon className="size-5" name="CircleCheck" />
614
603
  </span>
@@ -32,9 +32,10 @@ export const FeedbackLink = ({ className }: { className: string }) => {
32
32
  </Tip>
33
33
  </TipGroup>
34
34
  <Dialog onOpenChange={setOpen} open={open}>
35
+ {/* No padding: the form pads itself, so a file dropped on its edge lands on it. */}
35
36
  <DialogContent
36
37
  aria-label={t`Send feedback`}
37
- className="max-h-[calc(100dvh-2rem)] overflow-y-auto sm:max-w-md"
38
+ className="max-h-[calc(100dvh-2rem)] overflow-y-auto p-0 sm:max-w-md"
38
39
  showCloseButton={false}
39
40
  >
40
41
  <DexFeedback onClose={() => setOpen(false)} />
@@ -7,8 +7,20 @@ import {
7
7
  useState,
8
8
  } from "react";
9
9
  import { withBase } from "../base";
10
+ import { setPageStyle } from "../canvas/page-style";
10
11
  import { VIEWPORTS } from "../canvas/viewports";
11
12
 
13
+ /**
14
+ * Holds a thumbnail's page still (see the effect in ScaledFrame); Safari
15
+ * before 18.2 knows only the -webkit- way to hide a scrollbar.
16
+ */
17
+ const STILL_ID = "studio-still";
18
+ const STILL_CSS = `
19
+ html, body { overflow: hidden !important; }
20
+ * { scrollbar-width: none !important; }
21
+ ::-webkit-scrollbar { display: none !important; }
22
+ `;
23
+
12
24
  /** How a scaled page sits in its box: its size there, and how far across. */
13
25
  interface Fitted {
14
26
  left: number;
@@ -89,23 +101,23 @@ export const ScaledFrame = ({
89
101
  );
90
102
  // A thumbnail is a still of the page's top: nobody can scroll it, so its
91
103
  // page doesn't scroll, at its root or its body (either can be the
92
- // document's scroller), and no scrollbar shows in it or narrows the page.
104
+ // document's scroller), and no scrollbar shows in it or narrows the page,
105
+ // nor on a scroller in the view (an app's main pane): the still is what
106
+ // the page looks like where scrollbars only show while scrolling.
93
107
  // A page in use scrolls as it would anywhere; back to a still, it shows
94
- // its top again. A scroller inside the view is the design's own, and stays.
108
+ // its top again.
95
109
  useEffect(() => {
96
110
  if (!iframe) {
97
111
  return;
98
112
  }
99
113
  const hold = () => {
100
114
  const page = iframe.contentDocument;
101
- const overflow = interactive ? "" : "hidden";
102
- for (const element of [page?.documentElement, page?.body]) {
103
- element?.style.setProperty("overflow", overflow);
104
- }
105
- if (!interactive && page?.body) {
106
- iframe.contentWindow?.scrollTo(0, 0);
107
- page.body.scrollTop = 0;
115
+ setPageStyle(page, STILL_ID, STILL_CSS, !interactive);
116
+ if (interactive || !page?.body) {
117
+ return;
108
118
  }
119
+ iframe.contentWindow?.scrollTo(0, 0);
120
+ page.body.scrollTop = 0;
109
121
  };
110
122
  hold();
111
123
  iframe.addEventListener("load", hold);
package/app/types.ts CHANGED
@@ -3,12 +3,30 @@
3
3
  // threads-core, for the studio and the cloud workspace alike.
4
4
 
5
5
  import type { FrameAnchor } from "../src/shared/annotations-core.ts";
6
- import type { SlideLayout, Viewport } from "../src/shared/canvas-core.ts";
7
- import type { FrameGrid, FrameGuide } from "../src/shared/frame-grids.ts";
8
- import type { Sketch } from "../src/shared/sketch-core.ts";
6
+ import type {
7
+ DocFrame,
8
+ SketchFrame,
9
+ SpecFrame,
10
+ ViewFrame,
11
+ } from "../src/shared/canvas-file.ts";
9
12
 
10
13
  export type { Viewport } from "../src/shared/canvas-core.ts";
14
+ export type {
15
+ Canvas,
16
+ DocFrame,
17
+ Frame,
18
+ Row,
19
+ Section,
20
+ SketchFrame,
21
+ SpecFrame,
22
+ UnknownFrame,
23
+ ViewFrame,
24
+ } from "../src/shared/canvas-file.ts";
11
25
  export type { Sketch, SketchBox } from "../src/shared/sketch-core.ts";
26
+ export type {
27
+ Contributor,
28
+ Discipline,
29
+ } from "../src/shared/studio-files.ts";
12
30
  export type {
13
31
  ClosedStatus,
14
32
  PersonChange,
@@ -21,18 +39,6 @@ export type {
21
39
  ThreadWithPrototype,
22
40
  } from "../src/shared/threads-core.ts";
23
41
 
24
- export type Discipline = "product" | "brand" | "engineering";
25
-
26
- export interface Contributor {
27
- discipline: Discipline;
28
- /** Git user names that identify this person, so the agent knows who it is working for. */
29
- git: string[];
30
- /** Their GitHub username, for their avatar. */
31
- github?: string;
32
- name: string;
33
- slug: string;
34
- }
35
-
36
42
  export type PrototypeStatus =
37
43
  | "exploring"
38
44
  | "in-review"
@@ -56,120 +62,6 @@ export interface PrototypeManifest {
56
62
  was?: string;
57
63
  }
58
64
 
59
- interface FrameBase {
60
- /**
61
- * On a column's first frame: the id of a frame stacked further down a
62
- * column to its left, in its row, for this column to start level with
63
- * rather than at the row's top.
64
- */
65
- beside?: string;
66
- id: string;
67
- /**
68
- * The step this frame shows, counted from 1: its column on the canvas. Leave
69
- * out to follow the previous frame in the row.
70
- */
71
- step?: number;
72
- title?: string;
73
- /**
74
- * Which frame this is, for good: kept when it moves or is renamed, new on
75
- * a copy. Picks follow it. Given to the saver's frames that have none when
76
- * they save.
77
- */
78
- uid?: string;
79
- /**
80
- * Stacked directly below the frame before it in its row, in that frame's
81
- * column, rather than in a column of its own.
82
- */
83
- under?: true;
84
- }
85
-
86
- /** A live, interactive render of one of the prototype's views. */
87
- export interface ViewFrame extends FrameBase {
88
- doc?: undefined;
89
- /** The frame's own grids, shown in place of the canvas's (Figma's, pasted). */
90
- grids?: FrameGrid[];
91
- /** Guide lines on the frame. */
92
- guides?: FrameGuide[];
93
- params?: Record<string, string>;
94
- /** A fixed size in pixels, for a snapshot of one element; else the viewport's. */
95
- size?: { height: number; width: number };
96
- sketch?: undefined;
97
- /**
98
- * Where a snapshot was captured from, and when; and the image it is, when
99
- * it is one, in the prototype's folder: "images/….png".
100
- */
101
- snapshot?: { captured: string; image?: string; url: string };
102
- spec?: undefined;
103
- view: string;
104
- viewport?: Viewport;
105
- }
106
-
107
- /** A markdown document from the prototype's docs folder. */
108
- export interface DocFrame extends FrameBase {
109
- doc: string;
110
- /** A size of its own in pixels, set by resizing it; else 640 by 900. */
111
- size?: { height: number; width: number };
112
- sketch?: undefined;
113
- spec?: undefined;
114
- view?: undefined;
115
- }
116
-
117
- /**
118
- * A spec, edited in place on the canvas: a markdown file in its placer's
119
- * folder. In a section, it is that section's spec; outside any section, it is part
120
- * of the file spec.
121
- */
122
- export interface SpecFrame extends FrameBase {
123
- doc?: undefined;
124
- /**
125
- * A slide's layout: its first frame beside its words (the default), or
126
- * centred above them. Only a slide (people/<person>/slides/) has one.
127
- */
128
- layout?: SlideLayout;
129
- /**
130
- * A width of its own in pixels, set by resizing it; else 520. With a
131
- * height, it is never taller than that, and scrolls; without one, it is
132
- * as tall as its words (never less than 240). A slide's is fixed, both
133
- * ways: 1920 by 1080 until resized.
134
- */
135
- size?: { height?: number; width: number };
136
- sketch?: undefined;
137
- /** Its file, from the file's folder: "people/ana/specs/checkout.md". */
138
- spec: string;
139
- view?: undefined;
140
- }
141
-
142
- export interface SketchFrame extends FrameBase {
143
- doc?: undefined;
144
- sketch: Sketch;
145
- spec?: undefined;
146
- /** Required, as an older Dex names a frame by its title or view. */
147
- title: string;
148
- view?: undefined;
149
- }
150
-
151
- declare const readFromDisk: unique symbol;
152
-
153
- /**
154
- * A frame this Dex cannot show: a kind from a newer Dex, or a mistake.
155
- * Only reading a canvas makes one, so the studio never writes a frame that
156
- * shows nothing.
157
- */
158
- export interface UnknownFrame extends FrameBase {
159
- doc?: undefined;
160
- sketch?: undefined;
161
- spec?: undefined;
162
- view?: undefined;
163
- readonly [readFromDisk]: true;
164
- }
165
-
166
- export type Frame =
167
- | ViewFrame
168
- | DocFrame
169
- | SpecFrame
170
- | SketchFrame
171
- | UnknownFrame;
172
-
173
65
  /**
174
66
  * A frame about to be added. A view or doc frame is named after what it
175
67
  * shows; a sketch shows nothing else to name it by, so it comes with an id.
@@ -179,79 +71,3 @@ export type NewFrame =
179
71
  | Omit<DocFrame, "id">
180
72
  | SpecFrame
181
73
  | SketchFrame;
182
-
183
- /**
184
- * One pass through the section's steps: the main path, an error state, an
185
- * alternative. Its frames are the steps, left to right.
186
- */
187
- export interface Row {
188
- /**
189
- * In a person's copy of someone else's section: the id of their row this one
190
- * is shown under (people-core.ts).
191
- */
192
- after?: string;
193
- /**
194
- * Whose it is, when not its section's: someone's version of a row in
195
- * another person's section. Set when the canvas is read, never written.
196
- */
197
- author?: string;
198
- /** The id of the section in its author's file that keeps it. */
199
- copy?: string;
200
- frames: Frame[];
201
- id: string;
202
- }
203
-
204
- /**
205
- * A section. Rows below the first are iterations of it. With `at`, a frame of
206
- * its own instead: one frame, drawn at that point, with no section around it.
207
- */
208
- export interface Section {
209
- /** Where a frame of its own's top left corner is, in canvas pixels. */
210
- at?: { x: number; y: number };
211
- /**
212
- * Whose it is: the person whose people/<person>/canvas.json it is in. Set
213
- * when the canvas is read, never written; only they change it.
214
- */
215
- author?: string;
216
- /** The id of the section it is a copy of, shown right below it. */
217
- copyOf?: string;
218
- /** When it was added, as an ISO date. */
219
- created?: string;
220
- description?: string;
221
- /** Whose section it was copied from, when it is a copy. */
222
- from?: string;
223
- id: string;
224
- /**
225
- * Where the section's area starts, its top left corner in canvas pixels,
226
- * once someone has drawn it or dragged it there. None stacks it with the
227
- * others, top to bottom.
228
- */
229
- position?: { x: number; y: number };
230
- rows: Row[];
231
- /**
232
- * The least size of a section's area, in canvas pixels, once someone has
233
- * sized it or frames have left it: its frames still grow it, but it never
234
- * shrinks below this.
235
- */
236
- size?: { height: number; width: number };
237
- title: string;
238
- }
239
-
240
- /**
241
- * canvas.json: sections stacked top to bottom, and frames of their own where
242
- * they were drawn. In each section, steps run left to right and iterations
243
- * (states, errors, alternatives) top to bottom.
244
- */
245
- export interface Canvas {
246
- /**
247
- * Whose sections come first, as the canvas was read: each
248
- * person by when they joined. Never saved.
249
- */
250
- people?: readonly string[];
251
- sections: Section[];
252
- /**
253
- * Whose canvas.json has given its frames uids, as the canvas was read: a
254
- * frame of theirs with none is new. Never saved.
255
- */
256
- uidsGiven?: readonly string[];
257
- }
@@ -0,0 +1,128 @@
1
+ import { type DragEvent, useState } from "react";
2
+
3
+ // Files dragged from the desktop: every place that takes them takes them
4
+ // here, and a page refuses the rest. Two rules make a drop land in every
5
+ // browser, and WebKit (Safari, the Dex app) is why both are needed:
6
+ //
7
+ // - A drop zone takes a file drag on dragenter as well as on dragover. Just
8
+ // after the pointer crosses onto an element, WebKit goes by that element's
9
+ // dragenter alone. When it wasn't taken, WebKit fires no drop; or, if the
10
+ // element before took the drag, it opens the file in place of the page (in
11
+ // Preview, from the Dex app). Chromium fires a dragover straight after
12
+ // every dragenter, so only WebKit shows it.
13
+ // - A file drag nothing takes is refused, not left to the browser, which
14
+ // opens the file in place of the page.
15
+ //
16
+ // Dex's (packages/studio/app/ui) and Markup's (packages/markup/src/ui/dex)
17
+ // are one file: Markup's copy-from-dex script writes its copy from Dex's.
18
+
19
+ /** What a drag event carries, the browser's or React's. */
20
+ interface DragEventLike {
21
+ dataTransfer: DataTransfer | null;
22
+ preventDefault: () => void;
23
+ }
24
+
25
+ /** Whether a drag carries files: text and links dragged in are left alone. */
26
+ export const carriesFiles = <Drag extends Pick<DragEventLike, "dataTransfer">>(
27
+ event: Drag
28
+ ): event is Drag & { dataTransfer: DataTransfer } =>
29
+ event.dataTransfer?.types.includes("Files") ?? false;
30
+
31
+ /**
32
+ * Takes a file drag over a drop zone, on dragenter and dragover alike: says
33
+ * the drop is wanted, as a copy (unasked, WebKit offers Finder a move).
34
+ * Returns whether the drag carried files, so a zone can show it takes them.
35
+ */
36
+ export const takeFileDrag = (event: DragEventLike): boolean => {
37
+ if (!carriesFiles(event)) {
38
+ return false;
39
+ }
40
+ event.preventDefault();
41
+ event.dataTransfer.dropEffect = "copy";
42
+ return true;
43
+ };
44
+
45
+ /**
46
+ * A drop zone: `zone` is the handlers to spread on its element, which
47
+ * should cover all of what looks like the zone; `over` is whether files are
48
+ * being dragged over it now. `onFiles` takes what is dropped.
49
+ */
50
+ export const useFileDrop = (onFiles: (files: File[]) => void) => {
51
+ const [over, setOver] = useState(false);
52
+ const take = (event: DragEvent) => {
53
+ if (takeFileDrag(event)) {
54
+ setOver(true);
55
+ }
56
+ };
57
+ const zone = {
58
+ onDragEnter: take,
59
+ onDragLeave: (event: DragEvent) => {
60
+ // Onto a part of the zone, the drag is still over it.
61
+ const onto = event.relatedTarget;
62
+ if (!(onto instanceof Node && event.currentTarget.contains(onto))) {
63
+ setOver(false);
64
+ }
65
+ },
66
+ onDragOver: take,
67
+ onDrop: (event: DragEvent) => {
68
+ if (!carriesFiles(event)) {
69
+ return;
70
+ }
71
+ event.preventDefault();
72
+ setOver(false);
73
+ onFiles([...event.dataTransfer.files]);
74
+ },
75
+ };
76
+ return { over, zone };
77
+ };
78
+
79
+ const DRAG_TYPES = ["dragenter", "dragover", "drop"];
80
+
81
+ const isFileInput = (target: EventTarget | null): boolean =>
82
+ target instanceof HTMLInputElement && target.type === "file";
83
+
84
+ /**
85
+ * Refuses every file drag that reaches `target`, the page's window or the
86
+ * root of a part of it, with nothing taking it, so a file let go anywhere
87
+ * else is never opened in place of the page. It decides last: after every
88
+ * drop zone, and after every listener on `target` itself, even one added
89
+ * later. A file input, which takes a drop of its own, is left to do so.
90
+ * Returns how to stop.
91
+ */
92
+ export const refuseStrayFileDrops = (target: EventTarget): (() => void) => {
93
+ const refuse = (event: Event) => {
94
+ // Only drag events are listened for.
95
+ const drag = event as globalThis.DragEvent;
96
+ if (
97
+ drag.defaultPrevented ||
98
+ !carriesFiles(drag) ||
99
+ isFileInput(drag.target)
100
+ ) {
101
+ return;
102
+ }
103
+ // Cancelled, the drop is never the browser's to open. WebKit still fires
104
+ // one after a refused dragenter when the element before took the drag.
105
+ drag.preventDefault();
106
+ if (drag.type !== "drop") {
107
+ drag.dataTransfer.dropEffect = "none";
108
+ }
109
+ };
110
+ // Each drag reaches `target` twice: first on the way to the element under
111
+ // the pointer (capture), then on the way back (bubble). The first time,
112
+ // the refusal moves to the end of the listeners for the second, so the
113
+ // listeners a page added after it still go first.
114
+ const keepRefusalLast = (event: Event) => {
115
+ target.removeEventListener(event.type, refuse);
116
+ target.addEventListener(event.type, refuse);
117
+ };
118
+ for (const type of DRAG_TYPES) {
119
+ target.addEventListener(type, keepRefusalLast, { capture: true });
120
+ target.addEventListener(type, refuse);
121
+ }
122
+ return () => {
123
+ for (const type of DRAG_TYPES) {
124
+ target.removeEventListener(type, keepRefusalLast, { capture: true });
125
+ target.removeEventListener(type, refuse);
126
+ }
127
+ };
128
+ };
@@ -124,7 +124,7 @@ function InputGroupInput({
124
124
  <Input
125
125
  data-slot="input-group-control"
126
126
  className={cn(
127
- "flex-1 rounded-none border-0 bg-transparent shadow-none ring-0 focus-visible:ring-0 aria-invalid:ring-0 dark:bg-transparent",
127
+ "flex-1 rounded-none border-0 bg-transparent shadow-none ring-0 focus-visible:ring-0 focus-visible:outline-none aria-invalid:ring-0 dark:bg-transparent",
128
128
  className
129
129
  )}
130
130
  {...props}
@@ -140,7 +140,7 @@ function InputGroupTextarea({
140
140
  <Textarea
141
141
  data-slot="input-group-control"
142
142
  className={cn(
143
- "flex-1 resize-none rounded-none border-0 bg-transparent py-2 shadow-none ring-0 focus-visible:ring-0 aria-invalid:ring-0 dark:bg-transparent",
143
+ "flex-1 resize-none rounded-none border-0 bg-transparent py-2 shadow-none ring-0 focus-visible:ring-0 focus-visible:outline-none aria-invalid:ring-0 dark:bg-transparent",
144
144
  className
145
145
  )}
146
146
  {...props}