@dexhq/canvas 0.17.0 → 0.18.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 (174) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/app/canvas/canvas-commands.ts +2 -10
  3. package/app/canvas/canvas-context.tsx +11 -2
  4. package/app/canvas/canvas-document.ts +5 -1
  5. package/app/canvas/canvas-keys.ts +1 -1
  6. package/app/canvas/canvas-model.ts +195 -20
  7. package/app/canvas/canvas-scene.ts +176 -171
  8. package/app/canvas/canvas-ui.ts +4 -11
  9. package/app/canvas/canvas.css +159 -179
  10. package/app/canvas/change-pictures.tsx +156 -0
  11. package/app/canvas/comment-drafts.ts +31 -0
  12. package/app/canvas/comment-layer.tsx +125 -71
  13. package/app/canvas/comments.tsx +38 -2
  14. package/app/canvas/element-picker.ts +20 -0
  15. package/app/canvas/engine/canvas-gestures.ts +15 -3
  16. package/app/canvas/engine/canvas-store.ts +5 -0
  17. package/app/canvas/engine/canvas-view.tsx +22 -5
  18. package/app/canvas/find-bar.tsx +57 -41
  19. package/app/canvas/flow-canvas.tsx +147 -272
  20. package/app/canvas/frame-copies.ts +14 -17
  21. package/app/canvas/frame-drops.ts +15 -7
  22. package/app/canvas/frame-inspector.ts +192 -41
  23. package/app/canvas/frame-node.tsx +123 -75
  24. package/app/canvas/frame-resize.tsx +321 -83
  25. package/app/canvas/insert-hint.tsx +5 -15
  26. package/app/canvas/inspect-layer.tsx +73 -19
  27. package/app/canvas/label-action.tsx +13 -2
  28. package/app/canvas/layout.ts +233 -98
  29. package/app/canvas/live-page.ts +5 -0
  30. package/app/canvas/new-frame.ts +10 -25
  31. package/app/canvas/note-placing.ts +55 -84
  32. package/app/canvas/picked-box.tsx +5 -0
  33. package/app/canvas/picks-menu.tsx +3 -9
  34. package/app/canvas/readable-colour.ts +52 -0
  35. package/app/canvas/request-node.tsx +19 -10
  36. package/app/canvas/scrolling-page.ts +45 -0
  37. package/app/canvas/section-node.tsx +36 -53
  38. package/app/canvas/settle.ts +21 -0
  39. package/app/canvas/snapping.ts +96 -8
  40. package/app/canvas/spec-frame.tsx +8 -5
  41. package/app/canvas/spot-pins.tsx +15 -3
  42. package/app/canvas/stack-frame.tsx +13 -57
  43. package/app/canvas/stack-model.ts +5 -0
  44. package/app/canvas/stack-toggle.tsx +89 -0
  45. package/app/canvas/styles-layer.tsx +23 -43
  46. package/app/canvas/text-layer.tsx +26 -10
  47. package/app/canvas/thread-focus.tsx +18 -1
  48. package/app/canvas/tool-cursors.ts +2 -2
  49. package/app/canvas/toolbar-parts.tsx +48 -8
  50. package/app/canvas/toolbar.tsx +12 -10
  51. package/app/canvas/use-canvas-clipboard.tsx +13 -5
  52. package/app/canvas/use-reveal.ts +86 -0
  53. package/app/editor/extensions.ts +2 -0
  54. package/app/editor/line-break-caret.ts +57 -0
  55. package/app/git/branch-panel.tsx +61 -20
  56. package/app/i18n/locales/en/messages.po +64 -17
  57. package/app/i18n/locales/en/messages.ts +1 -1
  58. package/app/i18n/locales/pseudo/messages.po +64 -17
  59. package/app/i18n/locales/pseudo/messages.ts +1 -1
  60. package/app/icons/glyphs.tsx +2 -0
  61. package/app/live/studio-live.ts +29 -9
  62. package/app/pages/canvas.tsx +1 -1
  63. package/app/pages/commands-settings.tsx +70 -76
  64. package/app/pages/play-bar.tsx +6 -11
  65. package/app/pages/play.tsx +52 -33
  66. package/app/shell/feedback-form.tsx +29 -5
  67. package/app/ui/prompt-editor.tsx +2 -0
  68. package/app/ui/use-field-list.ts +90 -0
  69. package/dist/cli/commands/mcp.mjs +6 -4
  70. package/dist/cli/mcp-relay.mjs +10 -6
  71. package/dist/content/content.d.mts +26 -9
  72. package/dist/content/content.mjs +65 -8
  73. package/dist/content/screenshot.d.mts +2 -0
  74. package/dist/content/screenshot.mjs +3 -0
  75. package/dist/content/snapshot-client.d.mts +2 -0
  76. package/dist/content/snapshot-client.mjs +12 -1
  77. package/dist/inspector.js +96 -19
  78. package/dist/paste/paste.d.mts +5 -0
  79. package/dist/paste/paste.mjs +7 -2
  80. package/dist/server/agent-tools.d.mts +1 -0
  81. package/dist/server/agent-tools.mjs +4 -3
  82. package/dist/server/change-picture-store.d.mts +13 -0
  83. package/dist/server/change-picture-store.mjs +42 -0
  84. package/dist/server/change-pictures.d.mts +25 -0
  85. package/dist/server/change-pictures.mjs +104 -0
  86. package/dist/server/close-check.d.mts +11 -0
  87. package/dist/server/close-check.mjs +37 -5
  88. package/dist/server/comments/agent-actions.d.mts +8 -4
  89. package/dist/server/comments/agent-actions.mjs +16 -7
  90. package/dist/server/comments/close-tools.mjs +7 -5
  91. package/dist/server/comments/files.d.mts +5 -1
  92. package/dist/server/comments/hand-out.d.mts +1 -1
  93. package/dist/server/comments/hand-out.mjs +4 -1
  94. package/dist/server/comments/push.d.mts +19 -10
  95. package/dist/server/comments/push.mjs +45 -30
  96. package/dist/server/comments/studio-files.d.mts +14 -1
  97. package/dist/server/comments/studio-files.mjs +44 -31
  98. package/dist/server/comments/tools.d.mts +1 -1
  99. package/dist/server/comments/workspace.mjs +1 -0
  100. package/dist/server/dev-server.mjs +34 -0
  101. package/dist/server/own-copies.mjs +4 -23
  102. package/dist/server/requests.mjs +57 -3
  103. package/dist/server/response-budget.d.mts +2 -1
  104. package/dist/server/response-budget.mjs +4 -3
  105. package/dist/server/roster.d.mts +19 -8
  106. package/dist/server/roster.mjs +50 -22
  107. package/dist/server/studio-for.d.mts +7 -0
  108. package/dist/server/studio-for.mjs +23 -7
  109. package/dist/server/thread-forms.d.mts +3 -0
  110. package/dist/server/thread-forms.mjs +21 -1
  111. package/dist/server/tools/place-frame.d.mts +1 -0
  112. package/dist/server/tools/place-frame.mjs +33 -9
  113. package/dist/server/tools/result.mjs +2 -2
  114. package/dist/server/tools/snapshot.d.mts +1 -1
  115. package/dist/server/tools/snapshot.mjs +2 -1
  116. package/dist/server/tools/studio-context.d.mts +2 -1
  117. package/dist/server/tools/studio-context.mjs +2 -1
  118. package/dist/server/tools/watch.mjs +29 -12
  119. package/dist/server/work-groups.mjs +1 -1
  120. package/dist/shared/canvas-core.d.mts +39 -5
  121. package/dist/shared/canvas-core.mjs +60 -15
  122. package/dist/shared/canvas-file.d.mts +7 -4
  123. package/dist/shared/change-pictures-core.d.mts +6 -0
  124. package/dist/shared/change-pictures-core.mjs +5 -0
  125. package/dist/shared/page-looks.d.mts +12 -0
  126. package/dist/shared/page-looks.mjs +49 -0
  127. package/dist/shared/snapshot-clipboard.d.mts +6 -0
  128. package/dist/shared/studio-routes.d.mts +11 -0
  129. package/extension/dist/manifest.json +1 -1
  130. package/extension/dist/picker.js +114 -108
  131. package/package.json +4 -3
  132. package/src/cli/commands/mcp.ts +18 -8
  133. package/src/cli/mcp-relay.ts +13 -6
  134. package/src/content/content.ts +90 -16
  135. package/src/content/screenshot.ts +9 -1
  136. package/src/content/snapshot-client.ts +17 -0
  137. package/src/paste/paste.ts +18 -1
  138. package/src/server/agent-tools.ts +5 -4
  139. package/src/server/change-picture-store.ts +71 -0
  140. package/src/server/change-pictures.ts +244 -0
  141. package/src/server/close-check.ts +69 -6
  142. package/src/server/comments/agent-actions.ts +51 -12
  143. package/src/server/comments/close-tools.ts +20 -10
  144. package/src/server/comments/files.ts +10 -2
  145. package/src/server/comments/hand-out.ts +2 -2
  146. package/src/server/comments/push.ts +94 -46
  147. package/src/server/comments/studio-files.ts +77 -46
  148. package/src/server/comments/workspace.ts +1 -0
  149. package/src/server/dev-server.ts +70 -0
  150. package/src/server/own-copies.ts +5 -33
  151. package/src/server/requests.ts +84 -4
  152. package/src/server/response-budget.ts +5 -3
  153. package/src/server/roster.ts +78 -28
  154. package/src/server/studio-for.ts +32 -7
  155. package/src/server/thread-forms.ts +41 -1
  156. package/src/server/tools/place-frame.ts +71 -14
  157. package/src/server/tools/result.ts +2 -2
  158. package/src/server/tools/snapshot.ts +2 -1
  159. package/src/server/tools/studio-context.ts +24 -14
  160. package/src/server/tools/watch.ts +38 -13
  161. package/src/server/work-groups.ts +1 -1
  162. package/src/shared/canvas-core.ts +119 -27
  163. package/src/shared/canvas-file.ts +7 -4
  164. package/src/shared/change-pictures-core.ts +8 -0
  165. package/src/shared/page-looks.ts +133 -0
  166. package/src/shared/snapshot-clipboard.ts +6 -0
  167. package/src/shared/studio-routes.ts +7 -1
  168. package/templates/agents/dex-worker.md +9 -7
  169. package/templates/feedback-workflow.md +1 -1
  170. package/templates/methods/review.md +7 -6
  171. package/templates/rules/canvas-frames.md +8 -7
  172. package/templates/rules/canvas.md +10 -8
  173. package/templates/rules/prototypes.md +5 -3
  174. package/app/canvas/stack-node.tsx +0 -100
@@ -1,11 +1,16 @@
1
1
  /* oxlint-disable shadcn/no-inline-styles -- computed at runtime: the inspected element's box, from the page's geometry, and the tool's cursor */
2
- import { useEffect } from "react";
2
+ import { useCallback, useEffect, useRef } from "react";
3
3
 
4
4
  import type { InspectBox, StudioInspect } from "../kit/inspect-runtime";
5
5
  import { useCanvasUi, useCanvasUiStore } from "./canvas-ui";
6
- import { pointOnPage } from "./element-picker";
7
- import { useFrameInspector, useInspectorKeys } from "./frame-inspector";
6
+ import {
7
+ framePoint,
8
+ isWholeFrame,
9
+ useFrameInspector,
10
+ useInspectorKeys,
11
+ } from "./frame-inspector";
8
12
  import type { LivePage } from "./live-page";
13
+ import { FrameOutline } from "./picked-box";
9
14
  import { toolCursor } from "./tool-cursors";
10
15
 
11
16
  // Inspecting a frame: a layer over its page that outlines the design-system
@@ -14,7 +19,9 @@ import { toolCursor } from "./tool-cursors";
14
19
  // and Escape lets go. ↑ and ↓ step to the component that holds it and back
15
20
  // down, ← and → to the components beside it, as every tool that chooses an
16
21
  // element steps (frame-inspector.ts): the component inspected, else the one
17
- // outlined. The elements between components are passed over.
22
+ // outlined. The elements between components are passed over. What is
23
+ // chosen is the frame's inspector's (frame-inspector.ts): an element chosen
24
+ // in another tool is inspected as the component it is in.
18
25
 
19
26
  const Outline = ({ box, picked }: { box: InspectBox; picked?: boolean }) => (
20
27
  <div
@@ -42,6 +49,18 @@ const insideComponent = (
42
49
  );
43
50
  };
44
51
 
52
+ /** The top of the component an element is in; none outside every one. */
53
+ const componentOf = (
54
+ inspect: StudioInspect | undefined,
55
+ element: Element
56
+ ): Element | undefined => {
57
+ for (let at: Element | null = element; at !== null; at = at.parentElement) {
58
+ if (!insideComponent(inspect, at)) {
59
+ return at;
60
+ }
61
+ }
62
+ };
63
+
45
64
  export const InspectLayer = ({
46
65
  frameKey: key,
47
66
  page,
@@ -58,11 +77,19 @@ export const InspectLayer = ({
58
77
  state.inspected?.frame === key ? state.inspected : undefined
59
78
  );
60
79
 
61
- const inspecting = useFrameInspector(page, {
62
- elementAt: (point) => page?.inspectAt(point.x, point.y)?.element,
63
- skip: (element) => insideComponent(page?.inspector(), element),
64
- // What is chosen here is what the props panel shows.
65
- onChoose: (element) => {
80
+ const componentInspectedElsewhere = useCanvasUi(
81
+ (state) => state.inspected !== undefined && state.inspected.frame !== key
82
+ );
83
+
84
+ /** Shows an element's component in the props panel, or none. */
85
+ const show = useCallback(
86
+ (element: Element | undefined) => {
87
+ if (isWholeFrame(element)) {
88
+ ui.setInspected(undefined);
89
+
90
+ return;
91
+ }
92
+
66
93
  const { inspected: now } = ui.get();
67
94
  const shown = now?.frame === key ? now.element : undefined;
68
95
 
@@ -81,27 +108,52 @@ export const InspectLayer = ({
81
108
  );
82
109
  }
83
110
  },
111
+ [key, page, ui]
112
+ );
113
+
114
+ const inspecting = useFrameInspector(page, {
115
+ elementAt: (point) => page?.inspectAt(point.x, point.y)?.element,
116
+ skip: (element) => insideComponent(page?.inspector(), element),
117
+ // What is chosen here is what the props panel shows.
118
+ onChoose: show,
84
119
  });
85
120
 
121
+ // As the tool starts, an element chosen on this frame in another canvas
122
+ // tool is inspected: the component it is in. Unless another frame's
123
+ // component is inspected already: the props panel shows one.
124
+ useEffect(() => {
125
+ const { chosen } = inspecting;
126
+ const top = chosen && componentOf(page?.inspector(), chosen);
127
+
128
+ if (top && !ui.get().inspected) {
129
+ inspecting.choose(top);
130
+ show(top);
131
+ }
132
+ }, [inspecting, page, show, ui]);
133
+
86
134
  // And the other way: a component inspected in another frame, or found
87
- // again once the page loads anew (props-panel.tsx), is chosen here.
135
+ // again once the page loads anew (props-panel.tsx), is chosen here; one
136
+ // let go of there, while it was this frame's, is let go of here.
88
137
  const element = inspected?.element;
138
+ const shown = useRef(element);
89
139
 
90
140
  useEffect(() => {
91
- if (inspecting.chosen === element) {
92
- return;
93
- }
141
+ const before = shown.current;
142
+ shown.current = element;
143
+ const { chosen } = inspecting;
94
144
 
95
- if (element) {
145
+ if (element && element !== chosen) {
96
146
  inspecting.choose(element);
97
- } else {
147
+ } else if (
148
+ isWholeFrame(chosen) ? componentInspectedElsewhere : !element && before
149
+ ) {
98
150
  inspecting.release();
99
151
  }
100
- }, [inspecting, element]);
152
+ }, [inspecting, element, componentInspectedElsewhere]);
101
153
 
102
154
  useInspectorKeys(inspecting, { choose: () => inspecting.choose() });
103
155
 
104
- const { current } = inspecting;
156
+ const { chosen, current } = inspecting;
105
157
  const hover = current && page?.inspector()?.at(current)?.box;
106
158
 
107
159
  return (
@@ -110,16 +162,18 @@ export const InspectLayer = ({
110
162
  className="nodrag nopan absolute inset-0 z-20"
111
163
  onClick={(event) => {
112
164
  event.stopPropagation();
113
- inspecting.hover(pointOnPage(event, width));
165
+ inspecting.click(framePoint(event, width));
114
166
  inspecting.choose();
115
167
  }}
116
168
  onDoubleClick={(event) => event.stopPropagation()}
117
169
  onMouseLeave={() => inspecting.hover()}
118
- onMouseMove={(event) => inspecting.hover(pointOnPage(event, width))}
170
+ onMouseMove={(event) => inspecting.hover(framePoint(event, width))}
119
171
  style={{ cursor: toolCursor("inspect") }}
120
172
  >
121
173
  {hover ? <Outline box={hover} /> : null}
174
+ {isWholeFrame(current) && current !== chosen ? <FrameOutline /> : null}
122
175
  {inspected ? <Outline box={inspected.found.box} picked /> : null}
176
+ {isWholeFrame(chosen) ? <FrameOutline picked /> : null}
123
177
  </div>
124
178
  );
125
179
  };
@@ -1,5 +1,5 @@
1
1
  import { cn } from "cn";
2
- import type { MouseEvent, ReactNode } from "react";
2
+ import type { KeyboardEvent, MouseEvent, ReactNode } from "react";
3
3
  import { Link } from "wouter";
4
4
 
5
5
  /**
@@ -10,17 +10,22 @@ import { Link } from "wouter";
10
10
  export const LabelAction = ({
11
11
  children,
12
12
  className,
13
+ expanded,
13
14
  href,
14
15
  label,
15
16
  onClick,
17
+ onKeyDown,
16
18
  pressed,
17
19
  shown = false,
18
20
  }: {
19
21
  children: ReactNode;
20
22
  className?: string;
23
+ /** For a toggle that opens something, such as a stack. */
24
+ expanded?: boolean;
21
25
  href?: string;
22
26
  label: string;
23
27
  onClick?: () => void;
28
+ onKeyDown?: (event: KeyboardEvent) => void;
24
29
  pressed?: boolean;
25
30
  /** Shown whether or not you reach for it. */
26
31
  shown?: boolean;
@@ -44,7 +49,13 @@ export const LabelAction = ({
44
49
  {children}
45
50
  </Link>
46
51
  ) : (
47
- <button {...props} aria-pressed={pressed} type="button">
52
+ <button
53
+ {...props}
54
+ aria-expanded={expanded}
55
+ aria-pressed={pressed}
56
+ onKeyDown={onKeyDown}
57
+ type="button"
58
+ >
48
59
  {children}
49
60
  </button>
50
61
  );