@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
@@ -0,0 +1,220 @@
1
+ // Find on a frame's page: the words it shows, where each match is, and the
2
+ // matches painted yellow. The paint is the browser's CSS Custom Highlight
3
+ // API, so the page's own elements are never touched: React keeps its tree,
4
+ // and nothing shifts as a match is marked. Only text a person can see is
5
+ // searched: not a script's, a style's, or what is hidden.
6
+
7
+ import { VIEW_RENDERED } from "../../src/shared/page-messages.ts";
8
+
9
+ /** A match on a page: where it is, and the text it is in. */
10
+ export interface PageHit {
11
+ range: Range;
12
+ /** The whole text the match is in, as the page has it. */
13
+ text: string;
14
+ }
15
+
16
+ /** The highlights' names, and how each paints. */
17
+ const HITS = "dex-find";
18
+ const CURRENT = "dex-find-current";
19
+ const STYLE_ID = "dex-find-style";
20
+ const STYLE = `::highlight(${HITS}){background-color:rgb(255 211 77 / 0.45);color:#0a0a0a}::highlight(${CURRENT}){background-color:#ffd34d;color:#0a0a0a}`;
21
+
22
+ const SKIPPED = new Set(["SCRIPT", "STYLE", "NOSCRIPT", "TEMPLATE", "TITLE"]);
23
+
24
+ /**
25
+ * Whether an element is shown: not hidden by the page, nor in its head. A
26
+ * page that is not laid out (its frame hidden under its picture, zoomed
27
+ * out) can only say what it hides itself, with `hidden`.
28
+ */
29
+ const shown = (
30
+ element: Element,
31
+ seen: Map<Element, boolean>,
32
+ laidOut: boolean
33
+ ): boolean => {
34
+ const known = seen.get(element);
35
+ if (known !== undefined) {
36
+ return known;
37
+ }
38
+ let visible = !SKIPPED.has(element.tagName);
39
+ if (visible && laidOut && typeof element.checkVisibility === "function") {
40
+ visible = element.checkVisibility();
41
+ } else if (visible && !laidOut) {
42
+ visible = element.closest("[hidden]") === null;
43
+ }
44
+ seen.set(element, visible);
45
+ return visible;
46
+ };
47
+
48
+ /** Each text on a page a person can read, in the page's order. */
49
+ export const pageTexts = (doc: Document): Text[] => {
50
+ const body = doc.body;
51
+ if (!body) {
52
+ return [];
53
+ }
54
+ const seen = new Map<Element, boolean>();
55
+ const laidOut = (doc.documentElement?.getClientRects().length ?? 0) > 0;
56
+ const walker = doc.createTreeWalker(body, NodeFilter.SHOW_TEXT);
57
+ const texts: Text[] = [];
58
+ for (let node = walker.nextNode(); node; node = walker.nextNode()) {
59
+ const text = node as Text;
60
+ const parent = text.parentElement;
61
+ if (text.data.trim() && parent && shown(parent, seen, laidOut)) {
62
+ texts.push(text);
63
+ }
64
+ }
65
+ return texts;
66
+ };
67
+
68
+ const SPECIAL_RE = /[.*+?^${}()|[\]\\]/g;
69
+ let finder: { query: string; re: RegExp } | undefined;
70
+
71
+ /** The one way words are matched, ignoring case: for finding and painting. */
72
+ export const matcherOf = (query: string): RegExp => {
73
+ if (finder?.query !== query) {
74
+ finder = {
75
+ query,
76
+ re: new RegExp(query.replace(SPECIAL_RE, "\\$&"), "gi"),
77
+ };
78
+ }
79
+ finder.re.lastIndex = 0;
80
+ return finder.re;
81
+ };
82
+
83
+ /**
84
+ * Where `query` is in `text`, ignoring case: the start of each match, in the
85
+ * text as it is, so a letter that lowercases longer ("İ") moves no match.
86
+ */
87
+ export const matchesIn = (text: string, query: string): number[] => {
88
+ const starts: number[] = [];
89
+ if (!query) {
90
+ return starts;
91
+ }
92
+ const re = matcherOf(query);
93
+ re.lastIndex = 0;
94
+ for (let found = re.exec(text); found; found = re.exec(text)) {
95
+ starts.push(found.index);
96
+ }
97
+ return starts;
98
+ };
99
+
100
+ /** Every match of `query` in a page's texts (pageTexts), up to `limit`. */
101
+ export const hitsIn = (
102
+ texts: readonly Text[],
103
+ query: string,
104
+ limit: number
105
+ ): PageHit[] => {
106
+ const hits: PageHit[] = [];
107
+ for (const text of texts) {
108
+ for (const start of matchesIn(text.data, query)) {
109
+ if (hits.length >= limit) {
110
+ return hits;
111
+ }
112
+ const range = text.ownerDocument.createRange();
113
+ range.setStart(text, start);
114
+ range.setEnd(text, Math.min(text.length, start + query.length));
115
+ hits.push({ range, text: text.data });
116
+ }
117
+ }
118
+ return hits;
119
+ };
120
+
121
+ /** The page's highlight registry, where the browser has one. */
122
+ const registry = (doc: Document) => {
123
+ const view = doc.defaultView as
124
+ | (Window & { CSS?: { highlights?: HighlightRegistry } })
125
+ | null;
126
+ const highlights = view?.CSS?.highlights;
127
+ const Made = (view as (Window & { Highlight?: typeof Highlight }) | null)
128
+ ?.Highlight;
129
+ return highlights && Made ? { highlights, Made } : undefined;
130
+ };
131
+
132
+ /**
133
+ * Paint matches on a page: each in a light yellow, the current one, if it is
134
+ * here, in the full yellow. No matches takes the paint off.
135
+ */
136
+ export const paintHits = (
137
+ doc: Document,
138
+ hits: readonly PageHit[],
139
+ current: Range | undefined
140
+ ) => {
141
+ const found = registry(doc);
142
+ if (!found) {
143
+ return;
144
+ }
145
+ const { highlights, Made } = found;
146
+ if (hits.length === 0) {
147
+ highlights.delete(HITS);
148
+ highlights.delete(CURRENT);
149
+ return;
150
+ }
151
+ if (!doc.getElementById(STYLE_ID)) {
152
+ const style = doc.createElement("style");
153
+ style.id = STYLE_ID;
154
+ style.textContent = STYLE;
155
+ (doc.head ?? doc.documentElement)?.append(style);
156
+ }
157
+ highlights.set(
158
+ HITS,
159
+ new Made(...hits.flatMap(({ range }) => (range === current ? [] : range)))
160
+ );
161
+ if (current) {
162
+ highlights.set(CURRENT, new Made(current));
163
+ } else {
164
+ highlights.delete(CURRENT);
165
+ }
166
+ };
167
+
168
+ /** Longest a page read off screen may take to render, in milliseconds. */
169
+ const READ_WAIT_MS = 8000;
170
+
171
+ /**
172
+ * The texts of a page that is not on the canvas, read in an iframe out of
173
+ * sight: once its view has rendered and painted, or when it is given up on,
174
+ * none. The iframe goes as soon as it has been read.
175
+ */
176
+ export const readPageTexts = (
177
+ src: string,
178
+ size: { height: number; width: number }
179
+ ): Promise<string[]> =>
180
+ new Promise((resolve) => {
181
+ const iframe = document.createElement("iframe");
182
+ iframe.setAttribute("aria-hidden", "true");
183
+ iframe.tabIndex = -1;
184
+ iframe.style.cssText = `position:fixed;left:-100000px;top:0;width:${size.width}px;height:${size.height}px;border:0;visibility:hidden;pointer-events:none`;
185
+ let done = false;
186
+ const finish = (texts: string[]) => {
187
+ if (done) {
188
+ return;
189
+ }
190
+ done = true;
191
+ clearInterval(poll);
192
+ clearTimeout(timeout);
193
+ iframe.remove();
194
+ resolve(texts);
195
+ };
196
+ const read = () => {
197
+ let doc: Document | null = null;
198
+ try {
199
+ doc = iframe.contentDocument;
200
+ } catch {
201
+ finish([]);
202
+ return;
203
+ }
204
+ const view = doc?.defaultView;
205
+ if (!(doc && view && doc.documentElement?.hasAttribute(VIEW_RENDERED))) {
206
+ return;
207
+ }
208
+ clearInterval(poll);
209
+ // Painted once the next frame starts, as the canvas waits for it.
210
+ view.requestAnimationFrame(() =>
211
+ view.requestAnimationFrame(() =>
212
+ finish(pageTexts(doc).map(({ data }) => data))
213
+ )
214
+ );
215
+ };
216
+ const poll = setInterval(read, 50);
217
+ const timeout = setTimeout(() => finish([]), READ_WAIT_MS);
218
+ iframe.src = src;
219
+ document.body.append(iframe);
220
+ });
@@ -0,0 +1,23 @@
1
+ // A style the studio adds to a frame's page and removes again, by its id;
2
+ // nothing else on the page is touched.
3
+
4
+ /** Add `css` to a page as the style `id`, once, or take it away. */
5
+ export function setPageStyle(
6
+ page: Document | null | undefined,
7
+ id: string,
8
+ css: string,
9
+ on: boolean
10
+ ) {
11
+ if (!page?.head) {
12
+ return;
13
+ }
14
+ const existing = page.getElementById(id);
15
+ if (on && !existing) {
16
+ const style = page.createElement("style");
17
+ style.id = id;
18
+ style.textContent = css;
19
+ page.head.append(style);
20
+ } else if (!on && existing) {
21
+ existing.remove();
22
+ }
23
+ }
@@ -222,6 +222,8 @@ export const SectionNode = memo(
222
222
  className="studio-screen absolute bottom-full left-0 flex origin-bottom-left flex-col"
223
223
  style={{ width: `calc(${layout.width}px * var(--zoom))` }}
224
224
  >
225
+ {/* As tall as layout's SECTION_NAME_REMS: Play's line, taller than
226
+ the name's, and pb-2. */}
225
227
  <div className="studio-reveal-group studio-section-handle @container pointer-events-auto flex select-none items-center gap-1 whitespace-nowrap pb-2">
226
228
  <span className="studio-label shrink-0">
227
229
  <EditableText
@@ -4,18 +4,18 @@ import type { DocumentMark } from "../editor/annotations";
4
4
  import type { QuoteActions } from "../editor/quote-bubble";
5
5
  import { useSpecHost } from "./canvas-context";
6
6
  import { useCanvasUi } from "./canvas-ui";
7
- import { DRAFT_WORDS, useCommentsHidden } from "./comments";
7
+ import { DRAFT_WORDS, isHiddenThread, useCommentsView } from "./comments";
8
8
 
9
9
  // A spec's threads on the canvas: its open comments and suggestions, drawn
10
10
  // over its words; Comment on words selected, which opens the canvas's own
11
11
  // card to write in; a click on words, which opens their thread.
12
- // Hiding comments (⇧C) hides them here too.
12
+ // Hiding comments (⇧C) hides them here too, all but one opened since.
13
13
 
14
14
  export const useSpecMarks = (spec: string) => {
15
15
  const { compose, openThread, showResolved, threads } = useSpecHost();
16
16
  // A spec's open thread shows beside it (canvas-ui's specThread).
17
17
  const active = useCanvasUi((state) => state.specThread);
18
- const hidden = useCommentsHidden();
18
+ const { hidden, opened } = useCommentsView();
19
19
  // The words a comment is being written on, marked even while comments
20
20
  // are hidden, as a draft pin shows: its card hangs from them.
21
21
  const draft = useCanvasUi((state) => {
@@ -25,26 +25,27 @@ export const useSpecMarks = (spec: string) => {
25
25
  });
26
26
  const marks = useMemo(
27
27
  (): DocumentMark[] =>
28
- hidden
29
- ? []
30
- : threads.threads.flatMap(({ id, status, target }): DocumentMark[] => {
31
- if (!(target.kind === "spec" && target.spec === spec)) {
32
- return [];
33
- }
34
- const { prefix, quote, replace, suffix } = target;
35
- if (!isClosed({ status })) {
36
- return [{ id, quote, prefix, suffix, replace }];
37
- }
38
- // Closed threads show as on the rest of the canvas: there when
39
- // resolved ones are shown, quieter. An accepted suggestion is
40
- // on the words it put in; a rejected one, on the words it kept.
41
- if (!showResolved) {
42
- return [];
43
- }
44
- const words = status === "resolved" && replace ? replace : quote;
45
- return [{ id, quote: words, prefix, suffix, closed: true }];
46
- }),
47
- [hidden, showResolved, spec, threads.threads]
28
+ threads.threads.flatMap(({ id, status, target }): DocumentMark[] => {
29
+ if (
30
+ !(target.kind === "spec" && target.spec === spec) ||
31
+ isHiddenThread({ hidden, opened }, id)
32
+ ) {
33
+ return [];
34
+ }
35
+ const { prefix, quote, replace, suffix } = target;
36
+ if (!isClosed({ status })) {
37
+ return [{ id, quote, prefix, suffix, replace }];
38
+ }
39
+ // Closed threads show as on the rest of the canvas: there when
40
+ // resolved ones are shown, quieter. An accepted suggestion is
41
+ // on the words it put in; a rejected one, on the words it kept.
42
+ if (!showResolved) {
43
+ return [];
44
+ }
45
+ const words = status === "resolved" && replace ? replace : quote;
46
+ return [{ id, quote: words, prefix, suffix, closed: true }];
47
+ }),
48
+ [hidden, opened, showResolved, spec, threads.threads]
48
49
  );
49
50
  const list = useMemo((): DocumentMark[] => {
50
51
  if (!draft) {
@@ -1,7 +1,9 @@
1
1
  import { useCallback, useEffect, useRef } from "react";
2
2
  import type { Canvas, Thread } from "../types";
3
+ import { isOnFrame, isSpot } from "./anchoring";
3
4
  import type { ScreenPoint } from "./canvas-context";
4
5
  import { threadItemId } from "./canvas-scene";
6
+ import { cardPoint } from "./comments";
5
7
  import { useCanvasView } from "./engine/canvas-view";
6
8
 
7
9
  // Getting from a thread to what it is about: pan the canvas to its frame, its
@@ -13,22 +15,17 @@ import { useCanvasView } from "./engine/canvas-view";
13
15
  export const FOCUS_PADDING = 0.25;
14
16
  /** How long the canvas takes to move there. */
15
17
  export const FOCUS_MS = 300;
16
- const CARD_OFFSET = 360;
17
-
18
- /** Where to open a thread's card once the canvas has moved to it. */
19
- export const cardPoint = (): ScreenPoint => ({
20
- left: window.innerWidth - CARD_OFFSET - 32,
21
- top: 96,
22
- });
23
18
 
24
19
  /**
25
- * Show a thread: move the canvas to what it is about, then open it. Opens a
26
- * thread named in the address (?thread=<id>) once threads have loaded.
20
+ * Show a thread: move the canvas to what it is about, then open it at `at`,
21
+ * or else at its pin (or its words) once the canvas has drawn it; top right
22
+ * when it has none. Says whether it opens at its pin. Opens a thread named
23
+ * in the address (?thread=<id>) once threads have loaded.
27
24
  */
28
25
  export function useThreadFocus(
29
26
  threads: Thread[],
30
27
  canvas: Canvas,
31
- openThread: (id: string, at: ScreenPoint) => void
28
+ openThread: (id: string, at?: ScreenPoint) => void
32
29
  ) {
33
30
  const view = useCanvasView();
34
31
  // Read when focusing, so an edit does not restart the wait for a linked
@@ -36,19 +33,24 @@ export function useThreadFocus(
36
33
  const latest = useRef(canvas);
37
34
  latest.current = canvas;
38
35
  const focus = useCallback(
39
- (thread: Thread, at?: ScreenPoint) => {
36
+ (thread: Thread, at?: ScreenPoint): boolean => {
40
37
  const node = threadItemId(thread, latest.current);
41
38
  const { target } = thread;
39
+ // Whether its pin, or its words, are on what the canvas moves to.
40
+ let hasPin = false;
42
41
  if (target.kind === "canvas") {
43
42
  view.setCenter(target.point.x, target.point.y, { duration: FOCUS_MS });
43
+ hasPin = true;
44
44
  } else if (node && view.getItem(node)) {
45
45
  view.fitView({
46
46
  nodes: [{ id: node }],
47
47
  padding: FOCUS_PADDING,
48
48
  duration: FOCUS_MS,
49
49
  });
50
+ hasPin = isSpot(target) || isOnFrame(target) || target.kind === "spec";
50
51
  }
51
- openThread(thread.id, at ?? cardPoint());
52
+ openThread(thread.id, at ?? (hasPin ? undefined : cardPoint()));
53
+ return hasPin;
52
54
  },
53
55
  [view, openThread]
54
56
  );
@@ -43,8 +43,6 @@ export interface ActivityState {
43
43
  bar: Bar | undefined;
44
44
  /** Make an agent the default, and open it. */
45
45
  choose: (agent: LaunchAgentId, makeDefault: boolean) => void;
46
- /** Count the comments of a finished agent seen, and go to the change. */
47
- goToChange: (thread: ActivityItem["thread"]) => void;
48
46
  items: ActivityItem[];
49
47
  /** Open an agent: the default, or the one named, set up first if needed. */
50
48
  open: (agent?: LaunchAgentId) => void;
@@ -274,15 +272,9 @@ export function useActivity(
274
272
  }
275
273
  }, [open, opening]);
276
274
 
277
- const goToChange = useCallback(
278
- (thread: ActivityItem["thread"]) => changes?.goTo([thread]),
279
- [changes]
280
- );
281
-
282
275
  return {
283
276
  bar,
284
277
  choose,
285
- goToChange,
286
278
  items,
287
279
  open,
288
280
  opening,
@@ -24,10 +24,11 @@ import { useCanvasView } from "./engine/canvas-view";
24
24
  import { FOCUS_MS, FOCUS_PADDING } from "./thread-focus";
25
25
 
26
26
  // Following what agents complete on this file, for you: the newest change
27
- // to arrive is news for a while, which the agent heads-up says; going to a
28
- // change outlines its frames. While you are busy, the comments panel is
29
- // open, or the server is away, new ones wait; changes already there when you
30
- // open the file are only unseen.
27
+ // to arrive is news for a while, which the agent heads-up says; opening a
28
+ // change's comment from it outlines the frames the change landed on, and
29
+ // goes to them when the comment has no place of its own. While you are busy,
30
+ // the comments panel is open, or the server is away, new ones wait; changes
31
+ // already there when you open the file are only unseen.
31
32
 
32
33
  /**
33
34
  * The newest change while it's news, kept outside React's state: only the
@@ -66,13 +67,16 @@ export const useNews = (store: NewsStore | undefined): Thread | undefined => {
66
67
  };
67
68
 
68
69
  interface AgentChanges {
69
- /** Go to these changes, and count them seen. */
70
- goTo: (threads: Thread[]) => void;
71
70
  /** The newest change while it's news (NEWS_MS): read it with useNews. */
72
71
  news: NewsStore;
73
- /** Frames outlined since you went to their changes. */
72
+ /**
73
+ * Outline the frames these changes landed on a while, and count them
74
+ * seen; with `move`, the canvas goes to them too.
75
+ */
76
+ outline: (threads: Thread[], options?: { move?: boolean }) => void;
77
+ /** Frames outlined since their changes were opened. */
74
78
  outlined: ReadonlySet<string>;
75
- /** Threads whose agent pins show: unseen, or just gone to. */
79
+ /** Threads whose agent pins show: unseen, or just outlined. */
76
80
  pinned: ReadonlySet<string>;
77
81
  /** Count a thread seen, as reading it in its card does. */
78
82
  see: (thread: Thread) => void;
@@ -241,43 +245,33 @@ export function useAgentChanges({
241
245
  }
242
246
  }, [unseen, loaded, file, seenOf.file, quiet, tell]);
243
247
 
244
- /** Move the canvas to these frames, and outline them a while. */
245
- const showFrames = useCallback(
246
- (keys: string[], ids: string[]) => {
247
- view.fitView({
248
- nodes: keys.map((id) => ({ id })),
249
- padding: FOCUS_PADDING,
250
- duration: FOCUS_MS,
251
- });
252
- outlineTimers.clear();
253
- setOutlined(new Set(keys));
254
- setShown(new Set(ids));
255
- outlineTimers.after(OUTLINE_MS, () => {
256
- setOutlined(NOTHING);
257
- setShown(NOTHING);
258
- });
259
- },
260
- [view, outlineTimers]
261
- );
262
-
263
- const goTo = useCallback(
264
- (targets: Thread[]) => {
248
+ const outline = useCallback(
249
+ (targets: Thread[], { move = false } = {}) => {
265
250
  if (targets.length === 0) {
266
251
  return;
267
252
  }
268
253
  newsTimers.clear();
269
254
  news.set(undefined);
270
255
  remember(targets);
271
- showFrames(
272
- [
273
- ...new Set(
274
- targets.flatMap((thread) => changedFrames(thread, canvas))
275
- ),
276
- ],
277
- targets.map((thread) => thread.id)
278
- );
256
+ const keys = [
257
+ ...new Set(targets.flatMap((thread) => changedFrames(thread, canvas))),
258
+ ];
259
+ if (move) {
260
+ view.fitView({
261
+ nodes: keys.map((id) => ({ id })),
262
+ padding: FOCUS_PADDING,
263
+ duration: FOCUS_MS,
264
+ });
265
+ }
266
+ outlineTimers.clear();
267
+ setOutlined(new Set(keys));
268
+ setShown(new Set(targets.map((thread) => thread.id)));
269
+ outlineTimers.after(OUTLINE_MS, () => {
270
+ setOutlined(NOTHING);
271
+ setShown(NOTHING);
272
+ });
279
273
  },
280
- [canvas, news, newsTimers, remember, showFrames]
274
+ [canvas, news, newsTimers, outlineTimers, remember, view]
281
275
  );
282
276
 
283
277
  const see = useCallback(
@@ -304,12 +298,12 @@ export function useAgentChanges({
304
298
  () => ({
305
299
  unseen,
306
300
  news,
307
- goTo,
301
+ outline,
308
302
  see,
309
303
  outlined,
310
304
  pinned,
311
305
  }),
312
- [unseen, news, goTo, see, outlined, pinned]
306
+ [unseen, news, outline, see, outlined, pinned]
313
307
  );
314
308
  }
315
309
 
@@ -14,6 +14,7 @@ import type { PastedImage } from "../../src/shared/pasted-image.ts";
14
14
  import type { PasteSource } from "../../src/shared/snapshot-clipboard.ts";
15
15
  import { CAN_WRITE } from "../live/studio-api";
16
16
  import type { Prototype } from "../registry";
17
+ import { carriesFiles, takeFileDrag } from "../ui/file-drop";
17
18
  import {
18
19
  contentsOf,
19
20
  isCanvasClipboardEvent,
@@ -73,9 +74,6 @@ export const useCanvasClipboard = () => useContext(ClipboardContext);
73
74
  const isOnCanvas = (target: EventTarget | null): boolean =>
74
75
  target instanceof Element && target.closest(".studio-canvas") !== null;
75
76
 
76
- const carriesFiles = (event: DragEvent): boolean =>
77
- event.dataTransfer?.types.includes("Files") ?? false;
78
-
79
77
  /** Says what the clipboard did, with the icon of the notice when it worked. */
80
78
  type Say = (text: string, icon?: IconName) => void;
81
79
 
@@ -300,14 +298,11 @@ export const useClipboard = ({
300
298
  event.preventDefault();
301
299
  }
302
300
  };
303
- // Files dragged over the canvas are taken, rather than opened in
304
- // place of the studio.
305
- const onDragOver = (event: DragEvent) => {
306
- if (takesFiles() && carriesFiles(event) && isOnCanvas(event.target)) {
307
- event.preventDefault();
308
- if (event.dataTransfer) {
309
- event.dataTransfer.dropEffect = "copy";
310
- }
301
+ // Files dragged over the canvas are taken (file-drop.ts), rather than
302
+ // opened in place of the studio, which refuses them anywhere else.
303
+ const onFileDrag = (event: DragEvent) => {
304
+ if (takesFiles() && isOnCanvas(event.target)) {
305
+ takeFileDrag(event);
311
306
  }
312
307
  };
313
308
  const onDrop = (event: DragEvent) => {
@@ -317,7 +312,7 @@ export const useClipboard = ({
317
312
  return;
318
313
  }
319
314
  event.preventDefault();
320
- const files = [...(event.dataTransfer?.files ?? [])];
315
+ const files = [...event.dataTransfer.files];
321
316
  const imageFiles = files.filter(isImage);
322
317
  if (imageFiles.length === 0) {
323
318
  now().say(now().words.onlyImages);
@@ -333,13 +328,15 @@ export const useClipboard = ({
333
328
  window.addEventListener("copy", copy);
334
329
  window.addEventListener("cut", cut);
335
330
  window.addEventListener("paste", onPaste);
336
- window.addEventListener("dragover", onDragOver);
331
+ window.addEventListener("dragenter", onFileDrag);
332
+ window.addEventListener("dragover", onFileDrag);
337
333
  window.addEventListener("drop", onDrop);
338
334
  return () => {
339
335
  window.removeEventListener("copy", copy);
340
336
  window.removeEventListener("cut", cut);
341
337
  window.removeEventListener("paste", onPaste);
342
- window.removeEventListener("dragover", onDragOver);
338
+ window.removeEventListener("dragenter", onFileDrag);
339
+ window.removeEventListener("dragover", onFileDrag);
343
340
  window.removeEventListener("drop", onDrop);
344
341
  };
345
342
  };
@@ -2,6 +2,8 @@
2
2
  // changing its layout, to see how it is built. A style is added to the page
3
3
  // and removed again; nothing else is touched.
4
4
 
5
+ import { setPageStyle } from "./page-style";
6
+
5
7
  const XRAY_ID = "studio-xray";
6
8
  const XRAY_CSS = `
7
9
  *, *::before, *::after {
@@ -13,16 +15,5 @@ const XRAY_CSS = `
13
15
 
14
16
  /** Show or hide x-ray on a page; the live page keeps it on as it reloads. */
15
17
  export function setXray(page: Document | null | undefined, on: boolean) {
16
- if (!page?.head) {
17
- return;
18
- }
19
- const existing = page.getElementById(XRAY_ID);
20
- if (on && !existing) {
21
- const style = page.createElement("style");
22
- style.id = XRAY_ID;
23
- style.textContent = XRAY_CSS;
24
- page.head.append(style);
25
- } else if (!on && existing) {
26
- existing.remove();
27
- }
18
+ setPageStyle(page, XRAY_ID, XRAY_CSS, on);
28
19
  }
package/app/frame.tsx CHANGED
@@ -11,10 +11,15 @@ import { FrameApp } from "./frame/frame-app";
11
11
  import { hashPath } from "./frame/frame-history";
12
12
  import { holdWindowFocus } from "./frame/hold-window-focus";
13
13
  import { preloadView } from "./frame/views";
14
+ import { refuseStrayFileDrops } from "./ui/file-drop";
14
15
  import { StudioThemeProvider } from "./ui/theme-provider";
15
16
 
16
17
  // Before the view, so its listeners come after this one.
17
18
  holdWindowFocus(window);
19
+ // A file dropped on the view where nothing in it takes the file is never
20
+ // opened in place of it, nor of the studio around a live frame. What the
21
+ // view takes, on its own elements or its window, it still takes.
22
+ refuseStrayFileDrops(window);
18
23
 
19
24
  const root = document.getElementById("root");
20
25
  if (!root) {