@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,135 @@
1
+ import { matcherOf, matchesIn } from "./page-find.ts";
2
+
3
+ // Find on the canvas, apart from any page: the matches of the words on each
4
+ // frame, in the canvas's order, the one that is current, and the words
5
+ // around each for the list. A frame's texts are what its page showed when it
6
+ // was last on the canvas, so a frame scrolled off still counts.
7
+
8
+ /** Most matches counted; past it the count says there are more. */
9
+ export const MOST_HITS = 1000;
10
+
11
+ /** A frame's texts, as its page showed them, in the page's order. */
12
+ export interface FrameTexts {
13
+ key: string;
14
+ texts: readonly string[];
15
+ title: string;
16
+ }
17
+
18
+ /** One match: on which frame, which of its matches, and the text it is in. */
19
+ export interface Hit {
20
+ frame: string;
21
+ /** Its place among the frame's matches, from 0. */
22
+ index: number;
23
+ /** Where in its text the match starts. */
24
+ start: number;
25
+ text: string;
26
+ title: string;
27
+ }
28
+
29
+ export interface Found {
30
+ hits: Hit[];
31
+ /** More matched than MOST_HITS: only that many are counted. */
32
+ more: boolean;
33
+ }
34
+
35
+ /** Each frame's texts as one, made once for each list of them. */
36
+ const wholes = new WeakMap<readonly string[], string>();
37
+ const wholeOf = (texts: readonly string[]) => {
38
+ let whole = wholes.get(texts);
39
+ if (whole === undefined) {
40
+ // A line between texts, so no match runs from one into the next.
41
+ whole = texts.join("\n");
42
+ wholes.set(texts, whole);
43
+ }
44
+ return whole;
45
+ };
46
+
47
+ /** Every match of `query` on the frames, in the frames' order. */
48
+ export const findOnFrames = (
49
+ frames: readonly FrameTexts[],
50
+ query: string
51
+ ): Found => {
52
+ const hits: Hit[] = [];
53
+ if (!query.trim()) {
54
+ return { hits, more: false };
55
+ }
56
+ for (const { key, texts, title } of frames) {
57
+ // Most frames hold none of the words: one look at all of it says so.
58
+ if (!matcherOf(query).test(wholeOf(texts))) {
59
+ continue;
60
+ }
61
+ let index = 0;
62
+ for (const text of texts) {
63
+ for (const start of matchesIn(text, query)) {
64
+ if (hits.length >= MOST_HITS) {
65
+ return { hits, more: true };
66
+ }
67
+ hits.push({ frame: key, index, start, text, title });
68
+ index += 1;
69
+ }
70
+ }
71
+ }
72
+ return { hits, more: false };
73
+ };
74
+
75
+ /** The match `by` steps from `current`, round from the last to the first. */
76
+ export const stepHit = (current: number, by: 1 | -1, count: number) =>
77
+ count === 0 ? 0 : (current + by + count) % count;
78
+
79
+ /** The matches grouped by frame, in order, each with its place in `hits`. */
80
+ export const hitsByFrame = (hits: readonly Hit[]) => {
81
+ const groups: {
82
+ frame: string;
83
+ hits: { at: number; hit: Hit }[];
84
+ title: string;
85
+ }[] = [];
86
+ hits.forEach((hit, at) => {
87
+ const last = groups.at(-1);
88
+ if (last?.frame === hit.frame) {
89
+ last.hits.push({ at, hit });
90
+ } else {
91
+ groups.push({ frame: hit.frame, hits: [{ at, hit }], title: hit.title });
92
+ }
93
+ });
94
+ return groups;
95
+ };
96
+
97
+ /** Words either side of a match in the list, at most. */
98
+ const AROUND = 28;
99
+ const SPACES_RE = /\s+/g;
100
+
101
+ /** A match with the words around it, cut to fit a row of the list. */
102
+ export const snippet = (hit: Hit, length: number) => {
103
+ const from = Math.max(0, hit.start - AROUND);
104
+ const to = Math.min(hit.text.length, hit.start + length + AROUND);
105
+ const tidy = (text: string) => text.replace(SPACES_RE, " ");
106
+ return {
107
+ after:
108
+ tidy(hit.text.slice(hit.start + length, to)) +
109
+ (to < hit.text.length ? "…" : ""),
110
+ before:
111
+ (from > 0 ? "…" : "") + tidy(hit.text.slice(from, hit.start)).trimStart(),
112
+ match: hit.text.slice(hit.start, hit.start + length),
113
+ };
114
+ };
115
+
116
+ /**
117
+ * The texts a Replace all sends: each on a frame that holds `query`, once,
118
+ * however many matches there are, so the code only changes where the
119
+ * frames showed the words.
120
+ */
121
+ export const seenTexts = (
122
+ frames: readonly { key: string }[],
123
+ texts: ReadonlyMap<string, readonly string[]>,
124
+ query: string
125
+ ) => {
126
+ const seen = new Set<string>();
127
+ for (const { key } of frames) {
128
+ for (const text of texts.get(key) ?? []) {
129
+ if (matchesIn(text, query).length > 0) {
130
+ seen.add(text);
131
+ }
132
+ }
133
+ }
134
+ return [...seen];
135
+ };
@@ -49,7 +49,7 @@ import { FrameNode, settle } from "./frame-node";
49
49
  import { setPicturesZoom, useCanvasPictures } from "./frame-pictures";
50
50
  import { frameSource } from "./frame-source";
51
51
  import { InsertHint } from "./insert-hint";
52
- import type { Box, DropMark, Gap } from "./layout";
52
+ import { type Box, type DropMark, type Gap, sectionNamesZoom } from "./layout";
53
53
  import { usePlaceNote } from "./note-placing";
54
54
  import { RowNode } from "./row-node";
55
55
  import { useCanvasScene } from "./scene-context";
@@ -61,10 +61,15 @@ import { storedViewport, storeViewport } from "./stored-viewport";
61
61
  import { surfaceCursor } from "./tool-cursors";
62
62
  import { useSpecCopiesApart } from "./use-spec-copies";
63
63
 
64
- /** Below this zoom frame names hide; section names carry the canvas. */
64
+ /**
65
+ * Below this zoom frame names hide; section names carry the canvas, until
66
+ * they hide too (sectionNamesZoom).
67
+ */
65
68
  const FAR_ZOOM = 0.15;
66
69
  /** Below this, row names would reach into the section above, so they go. */
67
70
  const SMALL_ZOOM = 0.35;
71
+ /** A root font's size when the page can't say. */
72
+ const DEFAULT_REM_PX = 16;
68
73
  /**
69
74
  * How far the zoom moves, as a log ratio, before labels follow it mid-move:
70
75
  * 2%, less than a label's edge can show.
@@ -394,6 +399,9 @@ export const FlowCanvas = ({
394
399
  // every one of them restyles when it changes. A pan leaves it as it was;
395
400
  // a pinch moves it in steps too small to see, and exactly once it ends.
396
401
  const zoomShown = useRef<number>(undefined);
402
+ // Section names are sized in rem, so the zoom they hide below follows the
403
+ // root font: read once, as the canvas first shows.
404
+ const namesZoom = useRef<number>(undefined);
397
405
  const setZoom = useCallback((zoom: number, exact: boolean) => {
398
406
  const element = surface.current;
399
407
  const shown = zoomShown.current;
@@ -403,10 +411,18 @@ export const FlowCanvas = ({
403
411
  return;
404
412
  }
405
413
  zoomShown.current = zoom;
414
+ namesZoom.current ??= sectionNamesZoom(
415
+ Number.parseFloat(getComputedStyle(document.documentElement).fontSize) ||
416
+ DEFAULT_REM_PX
417
+ );
406
418
  element.setAttribute("data-pictures", String(setPicturesZoom(zoom)));
407
419
  element.style.setProperty("--zoom", String(zoom));
408
420
  element.setAttribute("data-far", String(zoom < FAR_ZOOM));
409
421
  element.setAttribute("data-small", String(zoom < SMALL_ZOOM));
422
+ element.setAttribute(
423
+ "data-section-names",
424
+ String(zoom >= namesZoom.current)
425
+ );
410
426
  }, []);
411
427
  useEffect(() => {
412
428
  setZoom(view.getZoom(), true);
@@ -16,34 +16,54 @@ export const anchorElement = (anchor: string): Element | null => {
16
16
  return page ? page.querySelector(anchor) : (last ?? null);
17
17
  };
18
18
 
19
+ type Place = (pin: DOMRect, floating: HTMLElement) => ScreenPoint;
20
+
19
21
  /**
20
22
  * Keeps something floating hung from its pin, as a selector, wherever `place`
21
23
  * puts it from the pin's box. Pans, zooms and a frame laid out again all
22
24
  * move the pin, the canvas's camera only some of them and Play's page none,
23
25
  * so it asks where its pin is each frame, and moves itself without
24
- * rendering. No pin, and it stays where it was put.
26
+ * rendering. No pin, and it hangs from `orElse`, if given, or stays where it
27
+ * was put. `onFound` runs when it first finds its pin.
25
28
  */
26
29
  export const useFollowPin = (
27
30
  ref: RefObject<HTMLElement | null>,
28
31
  anchor: string | undefined,
29
- place: (pin: DOMRect, floating: HTMLElement) => ScreenPoint
32
+ place: Place,
33
+ {
34
+ onFound,
35
+ orElse,
36
+ }: { onFound?: () => void; orElse?: { anchor: string; place: Place } } = {}
30
37
  ) => {
38
+ const elseAnchor = orElse?.anchor;
39
+ const elsePlace = orElse?.place;
31
40
  useLayoutEffect(() => {
32
41
  if (!anchor) {
33
42
  return;
34
43
  }
35
44
  let frame = 0;
45
+ let found = false;
46
+ const moveTo = (floating: HTMLElement, { left, top }: ScreenPoint) => {
47
+ floating.style.left = `${left}px`;
48
+ floating.style.top = `${top}px`;
49
+ };
36
50
  const follow = () => {
37
51
  const floating = ref.current;
38
52
  const pin = anchorElement(anchor);
53
+ const fallback =
54
+ pin || !elseAnchor ? null : document.querySelector(elseAnchor);
39
55
  if (floating && pin) {
40
- const { left, top } = place(pin.getBoundingClientRect(), floating);
41
- floating.style.left = `${left}px`;
42
- floating.style.top = `${top}px`;
56
+ moveTo(floating, place(pin.getBoundingClientRect(), floating));
57
+ if (!found) {
58
+ found = true;
59
+ onFound?.();
60
+ }
61
+ } else if (floating && fallback && elsePlace) {
62
+ moveTo(floating, elsePlace(fallback.getBoundingClientRect(), floating));
43
63
  }
44
64
  frame = window.requestAnimationFrame(follow);
45
65
  };
46
66
  follow();
47
67
  return () => window.cancelAnimationFrame(frame);
48
- }, [anchor, place, ref]);
68
+ }, [anchor, elseAnchor, elsePlace, onFound, place, ref]);
49
69
  };
@@ -57,7 +57,7 @@ import {
57
57
  threadsOn,
58
58
  } from "./anchoring";
59
59
  import { type CanvasContextValue, useCanvas } from "./canvas-context";
60
- import { keepPageWheel } from "./canvas-input";
60
+ import { keepPageWheel, takeKeyboardFrom } from "./canvas-input";
61
61
  import { AddBeside } from "./canvas-menus";
62
62
  import {
63
63
  type FrameAddress,
@@ -75,7 +75,7 @@ import {
75
75
  } from "./canvas-ui";
76
76
  import { AgentPin } from "./change-notice";
77
77
  import { CommentLayer } from "./comment-layer";
78
- import { DraftPin, Pin, usePinFilter } from "./comments";
78
+ import { cardPoint, DraftPin, Pin, usePinFilter } from "./comments";
79
79
  import { DevicePicker } from "./device-picker";
80
80
  import { EditableText } from "./editable-text";
81
81
  import { frameControls } from "./frame-context-menu";
@@ -121,7 +121,6 @@ import { useSpecMarks } from "./spec-threads";
121
121
  import { useStateOf } from "./state-store";
122
122
  import { StylesLayer } from "./styles-layer";
123
123
  import { TextLayer } from "./text-layer";
124
- import { cardPoint } from "./thread-focus";
125
124
  import { Tip, TipGroup } from "./tip";
126
125
  import { UnknownFrame } from "./unknown-frame";
127
126
  import { useAgentChangesOf } from "./use-agent-changes";
@@ -404,13 +403,14 @@ const FramePins = ({
404
403
  const { editor, openThread, showResolved, threads } = useCanvas();
405
404
  const activeThread = useCanvasUi(activeThreadOf);
406
405
  const draft = useCanvasUi((state) => draftOn(state, key));
407
- const pins = threadsOn(threads.threads, editor.canvas, key).filter(
408
- usePinFilter(showResolved, activeThread)
409
- );
406
+ const shown = usePinFilter(showResolved, activeThread);
407
+ const pins = threadsOn(threads.threads, editor.canvas, key).filter(shown);
410
408
  // Where agents' changes landed on this frame: unseen, or just gone to.
409
+ // Each shows where its comment's pin would.
411
410
  const changes = useAgentChangesOf();
412
411
  const landed = threads.threads.flatMap((thread) => {
413
- if (!changes?.pinned.has(thread.id)) {
412
+ const ticked = Boolean(changes?.pinned.has(thread.id)) && shown(thread);
413
+ if (!ticked) {
414
414
  return [];
415
415
  }
416
416
  const placed = landedOn(thread, editor.canvas);
@@ -1351,8 +1351,8 @@ export const FrameNode = memo(
1351
1351
  const changesOutlined = Boolean(useAgentChangesOf()?.outlined.has(key));
1352
1352
  // A frame left behind takes the keyboard with it back to the canvas.
1353
1353
  useEffect(() => {
1354
- if (!live && iframe && iframe.ownerDocument.activeElement === iframe) {
1355
- iframe.blur();
1354
+ if (!live && iframe) {
1355
+ takeKeyboardFrom(iframe);
1356
1356
  }
1357
1357
  }, [iframe, live]);
1358
1358
  const view = viewOf(frame);
@@ -11,6 +11,7 @@ import type { I18n } from "@lingui/core";
11
11
  import { msg } from "@lingui/core/macro";
12
12
  import { Plural, Trans, useLingui } from "@lingui/react/macro";
13
13
  import { Icon } from "@studio/icons";
14
+ import { useFileDrop } from "@studio/ui/file-drop";
14
15
  import { Segmented } from "@studio/ui/segmented";
15
16
  import { Button } from "@studio/ui/shadcn/button";
16
17
  import {
@@ -32,13 +33,7 @@ import {
32
33
  InputGroupInput,
33
34
  } from "@studio/ui/shadcn/input-group";
34
35
  import { cn } from "cn";
35
- import {
36
- type DragEvent,
37
- type ReactNode,
38
- useEffect,
39
- useRef,
40
- useState,
41
- } from "react";
36
+ import { type ReactNode, useEffect, useRef, useState } from "react";
42
37
  import {
43
38
  isPageReview,
44
39
  isZip,
@@ -654,13 +649,10 @@ const ImportReviewsDialog = ({
654
649
  const [picked, setPicked] = useState<Picked[]>([]);
655
650
  const [sending, setSending] = useState(false);
656
651
  const [problem, setProblem] = useState<string>();
657
- const add = async (files: FileList | null) => {
658
- if (!files) {
659
- return;
660
- }
652
+ const add = async (files: File[]) => {
661
653
  const prototype = canvas?.prototype.slug ?? "";
662
654
  const read = await Promise.all(
663
- [...files].map((file) => readPicked(file, i18n, prototype))
655
+ files.map((file) => readPicked(file, i18n, prototype))
664
656
  );
665
657
  // A review picked twice is one row.
666
658
  setPicked((current) => {
@@ -687,10 +679,8 @@ const ImportReviewsDialog = ({
687
679
  (each) => each.review && !isReviewIn(threads, each.review)
688
680
  );
689
681
  const count = fresh.length;
690
- const drop = (event: DragEvent<HTMLElement>) => {
691
- event.preventDefault();
692
- add(event.dataTransfer.files);
693
- };
682
+ // Files dropped anywhere on the dialog are picked, as on its drop box.
683
+ const { over, zone } = useFileDrop(add);
694
684
  const send = async () => {
695
685
  if (!canvas || fresh.length === 0) {
696
686
  return;
@@ -722,18 +712,18 @@ const ImportReviewsDialog = ({
722
712
  };
723
713
  return (
724
714
  <Dialog onOpenChange={close} open={open}>
725
- <DialogContent className="sm:max-w-md">
715
+ <DialogContent className="sm:max-w-md" {...zone}>
726
716
  <DialogHeader>
727
717
  <DialogTitle>
728
718
  <Trans>Import reviews</Trans>
729
719
  </DialogTitle>
730
720
  </DialogHeader>
731
- {/* biome-ignore lint/a11y/noNoninteractiveElementInteractions: dropping files is the mouse's way in; Choose files is the keyboard's */}
732
721
  <section
733
722
  aria-label={t`Review files`}
734
- className="flex items-center justify-between gap-3 rounded-lg border border-dashed px-3 py-2.5 text-muted-foreground"
735
- onDragOver={(event) => event.preventDefault()}
736
- onDrop={drop}
723
+ className={cn(
724
+ "flex items-center justify-between gap-3 rounded-lg border border-dashed px-3 py-2.5 text-muted-foreground transition-colors",
725
+ over && "border-ring bg-muted/50"
726
+ )}
737
727
  >
738
728
  <Trans>Drop reviews’ .json or .zip files here</Trans>
739
729
  <Button
@@ -749,7 +739,7 @@ const ImportReviewsDialog = ({
749
739
  className="sr-only"
750
740
  multiple
751
741
  onChange={(event) => {
752
- add(event.target.files);
742
+ add([...(event.target.files ?? [])]);
753
743
  event.target.value = "";
754
744
  }}
755
745
  ref={input}
@@ -44,6 +44,33 @@ export const ROW_GAP = 200;
44
44
  export const STACK_GAP = COLUMN_GAP;
45
45
  export const SECTION_GAP = 360;
46
46
  export const SECTION_PADDING = 96;
47
+ /**
48
+ * How tall a section's name is on screen at any zoom, in rem: a line of
49
+ * small text and the space under it (section-node's handle).
50
+ */
51
+ export const SECTION_NAME_REMS = 1.625;
52
+ /**
53
+ * How far past a frame or a section its resize handles reach on screen, at
54
+ * any zoom: the corner's, the furthest (canvas.css,
55
+ * .studio-resize[data-edge="corner"]).
56
+ */
57
+ export const RESIZE_REACH = 6;
58
+ /**
59
+ * The least zoom section names show at, with a root font this many pixels
60
+ * tall. A name sits above its section, as tall on screen at any zoom, so in
61
+ * the canvas it reaches its height over the zoom up into the gap. Any further
62
+ * out it would reach into the section above, or, with a small root font,
63
+ * meet the resize handles reaching down from its frames, which would take a
64
+ * press on it. The section above's own handles reach under the name a little
65
+ * sooner, but the name is drawn over them: the section below comes later.
66
+ */
67
+ export const sectionNamesZoom = (remPx: number) => {
68
+ const name = SECTION_NAME_REMS * remPx;
69
+ return Math.max(
70
+ name / SECTION_GAP,
71
+ (name + RESIZE_REACH) / (SECTION_GAP + SECTION_PADDING)
72
+ );
73
+ };
47
74
 
48
75
  /**
49
76
  * The area a section of this size shows: a column's gap narrower, as a
@@ -17,6 +17,7 @@ import {
17
17
  locatorKey,
18
18
  type PickedElement,
19
19
  } from "./element-picker";
20
+ import { type PageHit, pageTexts, paintHits } from "./page-find";
20
21
  import type { PageMeasure } from "./page-heights";
21
22
  import { type Scroll, watchPageScroll } from "./page-scroll";
22
23
  import { setXray } from "./xray";
@@ -55,6 +56,11 @@ export interface LivePage {
55
56
  inspector: () => StudioInspect | undefined;
56
57
  /** Runs `callback` once the page has rendered its next frame. */
57
58
  nextFrame: (callback: () => void) => void;
59
+ /**
60
+ * Each time what the page shows may have changed (its elements or its
61
+ * text), and when it loads another page.
62
+ */
63
+ onChange: (listener: () => void) => () => void;
58
64
  /** Each control the view declares with useViewControl. */
59
65
  onControl: (
60
66
  listener: (name: string, options: readonly string[]) => void
@@ -76,16 +82,22 @@ export interface LivePage {
76
82
  * page the frame loads after: a page loading, or one with no view, never.
77
83
  */
78
84
  onPainted: (listener: () => void) => () => void;
85
+ /** Paints matches `find` found, the current one brighter; none, none. */
86
+ paintHits: (hits: readonly PageHit[], current?: Range) => void;
79
87
  /** The first element written at a place in the code, now. */
80
88
  placed: (place: string) => Element | undefined;
81
89
  /** X-ray on or off; on stays on as the page reloads. */
82
90
  setXray: (on: boolean) => void;
91
+ /** Each text the page shows a person, in its order (page-find). */
92
+ texts: () => Text[];
83
93
  /**
84
94
  * Where the elements some locators find are, in the page's pixels from its
85
95
  * top left however far it has scrolled, by each locator's key: now, when
86
96
  * it loads, and every few seconds after, so they follow the page as it
87
97
  * changes. An element that doesn't show, in another state of the page or
88
- * hidden, has no box.
98
+ * hidden, has no box. While the page isn't laid out (its frame hidden
99
+ * under its picture), an element still on it keeps the box it had when the
100
+ * page was last laid out.
89
101
  */
90
102
  watchBoxes: (
91
103
  locators: readonly ElementLocator[],
@@ -109,6 +121,25 @@ const isDrawn = (element: Element): boolean =>
109
121
  typeof element.checkVisibility !== "function" ||
110
122
  element.checkVisibility({ visibilityProperty: true });
111
123
 
124
+ /**
125
+ * Whether a frame's page is laid out, so its elements can be measured. An
126
+ * iframe hidden with `display: none`, as a frame's is zoomed out under its
127
+ * picture, has no box: Chromium then lays out nothing on its page, and every
128
+ * element on it measures as nothing, while WebKit keeps the last layout.
129
+ * Browsers without the check go by the boxes alone.
130
+ */
131
+ const isLaidOut = (iframe: HTMLIFrameElement): boolean =>
132
+ typeof iframe.checkVisibility !== "function" || iframe.checkVisibility();
133
+
134
+ /** The element a locator finds on a page; none for a selector it can't parse. */
135
+ const locateOn = (page: Document | null, locator: ElementLocator) => {
136
+ try {
137
+ return page ? locate(page, locator) : undefined;
138
+ } catch {
139
+ return;
140
+ }
141
+ };
142
+
112
143
  /** Where the elements locators find are on a page, as watchBoxes says. */
113
144
  const measureBoxes = (
114
145
  page: Document | null,
@@ -117,19 +148,35 @@ const measureBoxes = (
117
148
  const boxes = new Map<string, Box>();
118
149
  const view = page?.defaultView;
119
150
  for (const locator of locators) {
120
- try {
121
- const found = page ? locate(page, locator) : undefined;
122
- const rect = found?.getBoundingClientRect();
123
- if (found && rect && rect.width + rect.height > 0 && isDrawn(found)) {
124
- boxes.set(locatorKey(locator), {
125
- x: rect.left + (view?.scrollX ?? 0),
126
- y: rect.top + (view?.scrollY ?? 0),
127
- width: rect.width,
128
- height: rect.height,
129
- });
130
- }
131
- } catch {
132
- // A selector the page cannot parse just has no box.
151
+ const element = locateOn(page, locator);
152
+ const rect = element?.getBoundingClientRect();
153
+ if (element && rect && rect.width + rect.height > 0 && isDrawn(element)) {
154
+ boxes.set(locatorKey(locator), {
155
+ x: rect.left + (view?.scrollX ?? 0),
156
+ y: rect.top + (view?.scrollY ?? 0),
157
+ width: rect.width,
158
+ height: rect.height,
159
+ });
160
+ }
161
+ }
162
+ return boxes;
163
+ };
164
+
165
+ /**
166
+ * Where the elements locators find were when the page was last laid out, for
167
+ * a page that isn't now: an element gone from it since has no box.
168
+ */
169
+ const lastBoxes = (
170
+ page: Document | null,
171
+ locators: readonly ElementLocator[],
172
+ laidOut: ReadonlyMap<string, Box>
173
+ ) => {
174
+ const boxes = new Map<string, Box>();
175
+ for (const locator of locators) {
176
+ const key = locatorKey(locator);
177
+ const box = laidOut.get(key);
178
+ if (box && locateOn(page, locator)) {
179
+ boxes.set(key, box);
133
180
  }
134
181
  }
135
182
  return boxes;
@@ -179,11 +226,20 @@ export const iframePage = (
179
226
  }
180
227
  );
181
228
  let stopXray: (() => void) | undefined;
229
+ /**
230
+ * Where each locator's element was when the page was last laid out, for
231
+ * while it isn't: it may have moved since, until the page shows again.
232
+ */
233
+ const laidOutBoxes = new Map<string, Box>();
182
234
 
183
235
  return {
184
236
  editableTextAt: (x, y) => editableTextAt(doc(), x, y),
185
237
  elementAt: (x, y) => elementAt(doc(), x, y),
186
238
  elementsIn: (area) => elementsIn(doc(), area),
239
+ texts: () => {
240
+ const shown = doc();
241
+ return shown ? pageTexts(shown) : [];
242
+ },
187
243
  inspectAt: (x, y) => {
188
244
  const picked = componentElementAt(doc(), x, y);
189
245
  const found = picked && view()?.__studioInspect?.at(picked.element);
@@ -239,6 +295,33 @@ export const iframePage = (
239
295
  ),
240
296
  onNavigate: (listener) =>
241
297
  hear("studio:navigate", ({ path }) => listener(path)),
298
+ onChange: (listener) => {
299
+ let observer: MutationObserver | undefined;
300
+ return eachPage(
301
+ () => {
302
+ const root = doc()?.documentElement;
303
+ if (root) {
304
+ observer = new MutationObserver(() => listener());
305
+ // Attributes too: what shows can change by a style alone, as
306
+ // React's Suspense hides and shows a view with one.
307
+ observer.observe(root, {
308
+ attributeFilter: ["class", "hidden", "style"],
309
+ characterData: true,
310
+ childList: true,
311
+ subtree: true,
312
+ });
313
+ listener();
314
+ }
315
+ },
316
+ () => observer?.disconnect()
317
+ );
318
+ },
319
+ paintHits: (hits, current) => {
320
+ const shown = doc();
321
+ if (shown) {
322
+ paintHits(shown, hits, current);
323
+ }
324
+ },
242
325
  onKeyDown: (listener) => {
243
326
  let page: Window | null = null;
244
327
  const onKey = (event: KeyboardEvent) => {
@@ -282,20 +365,41 @@ export const iframePage = (
282
365
  last = JSON.stringify([...boxes]);
283
366
  onBoxes(boxes);
284
367
  };
285
- const measure = () => report(measureBoxes(doc(), locators));
286
- // A change to the page (a tab picked, a menu closed) measures again
287
- // in the next frame, so a pin leaves with its state at once; the
288
- // timer still catches what moves without one, like a transition.
368
+ // On a page that isn't laid out (isLaidOut), its elements keep the
369
+ // boxes they last had, so its pins stay on its frame's picture.
370
+ const boxesNow = () => {
371
+ if (!isLaidOut(iframe)) {
372
+ return lastBoxes(doc(), locators, laidOutBoxes);
373
+ }
374
+ const boxes = measureBoxes(doc(), locators);
375
+ for (const locator of locators) {
376
+ const key = locatorKey(locator);
377
+ const box = boxes.get(key);
378
+ if (box) {
379
+ laidOutBoxes.set(key, box);
380
+ } else {
381
+ laidOutBoxes.delete(key);
382
+ }
383
+ }
384
+ return boxes;
385
+ };
386
+ const measure = () => report(boxesNow());
387
+ // A change to the page (a tab picked, a menu closed) or to its
388
+ // iframe's size (shown again after its picture) measures again in the
389
+ // next frame, so a pin leaves with its state at once; the timer still
390
+ // catches what moves without one, like a transition.
289
391
  let pending = 0;
290
392
  const changed = () => {
291
393
  pending ||= studio.requestAnimationFrame(() => {
292
394
  pending = 0;
293
- const boxes = measureBoxes(doc(), locators);
395
+ const boxes = boxesNow();
294
396
  if (JSON.stringify([...boxes]) !== last) {
295
397
  report(boxes);
296
398
  }
297
399
  });
298
400
  };
401
+ const sizeObserver = new ResizeObserver(changed);
402
+ sizeObserver.observe(iframe);
299
403
  let observer: MutationObserver | undefined;
300
404
  const stop = eachPage(
301
405
  () => {
@@ -315,6 +419,7 @@ export const iframePage = (
315
419
  const timer = studio.setInterval(measure, MEASURE_EVERY_MS);
316
420
  return () => {
317
421
  stop();
422
+ sizeObserver.disconnect();
318
423
  studio.clearInterval(timer);
319
424
  studio.cancelAnimationFrame(pending);
320
425
  };
@@ -331,6 +436,22 @@ export const useLivePage = (iframe: HTMLIFrameElement | null) =>
331
436
  /** Each frame's live page, by frame key, while its iframe is on the canvas. */
332
437
  export const framePages = new Map<string, LivePage>();
333
438
 
439
+ const framePagesListeners = new Set<() => void>();
440
+
441
+ /** Each time a frame's live page comes on the canvas or leaves it. */
442
+ export const onFramePages = (listener: () => void) => {
443
+ framePagesListeners.add(listener);
444
+ return () => {
445
+ framePagesListeners.delete(listener);
446
+ };
447
+ };
448
+
449
+ const framePagesChanged = () => {
450
+ for (const listener of framePagesListeners) {
451
+ listener();
452
+ }
453
+ };
454
+
334
455
  /** A canvas frame's live page, found in framePages by its key too. */
335
456
  export const useFramePage = (key: string, iframe: HTMLIFrameElement | null) => {
336
457
  const page = useLivePage(iframe);
@@ -339,9 +460,11 @@ export const useFramePage = (key: string, iframe: HTMLIFrameElement | null) => {
339
460
  return;
340
461
  }
341
462
  framePages.set(key, page);
463
+ framePagesChanged();
342
464
  return () => {
343
465
  if (framePages.get(key) === page) {
344
466
  framePages.delete(key);
467
+ framePagesChanged();
345
468
  }
346
469
  };
347
470
  }, [key, page]);