@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
@@ -77,7 +77,10 @@
77
77
 
78
78
  /* A note is as tall as its words: only its width is set. */
79
79
  .studio-canvas-item:has(.studio-frame[data-note="true"])
80
- :is(.studio-size-pill, .studio-resize:not([data-edge="right"])) {
80
+ :is(
81
+ .studio-size-pill,
82
+ .studio-resize:not([data-edge="left"], [data-edge="right"])
83
+ ) {
81
84
  display: none;
82
85
  }
83
86
 
@@ -88,8 +91,9 @@
88
91
  visibility: hidden;
89
92
  }
90
93
 
91
- /* A section header: a band across the canvas's content, its words large, as
92
- a design file's section header rows are. In the darkest ink the theme has
94
+ /* A section header: a band across what it fills (its section, or on its
95
+ own the canvas's content), its words large, as a design file's section
96
+ header rows are. In the darkest ink the theme has
93
97
  (black in light; in dark its lightest, as black would vanish into a dark
94
98
  canvas). Its words take its size, whatever block they are written in. */
95
99
  .studio-artboard[data-note="true"][data-header="true"] {
@@ -130,12 +134,15 @@
130
134
  }
131
135
  }
132
136
 
133
- /* Further out than sections' names fit above them (they come down inside,
134
- sectionNameDrop), its words would be too small to read on it: they sit
135
- just left of it, where the canvas is empty (a header starts at the left
136
- edge of everything on it), as large on screen as a section's name, and
137
- the band stays a line across the canvas. */
138
- .studio-canvas[data-section-names="inside"] .studio-header-words {
137
+ /* Further out than sections' names fit above them (sectionNamesFit), the
138
+ words of a header on its own would be too small to read on it: they sit
139
+ just left of it, where the canvas is empty (such a header starts at the
140
+ left edge of everything on it), as large on screen as a section's name,
141
+ and the band stays a line across the canvas. One in a section has frames
142
+ to its left: its words stay on it. */
143
+ .studio-canvas[data-section-names="overlap"]
144
+ .studio-frame[data-header-alone="true"]
145
+ .studio-header-words {
139
146
  color: var(--foreground);
140
147
  text-align: right;
141
148
  transform: translateX(-100%)
@@ -169,14 +176,6 @@
169
176
  visibility: hidden;
170
177
  }
171
178
 
172
- /* A section's name: the same size on screen at any zoom, above its section.
173
- Further out than the gap above holds it, it comes down into the section's
174
- top left as far as it must (sectionNameDrop in layout.ts, on screen, so
175
- over the zoom in the canvas), over the section's frames. */
176
- .studio-section-name {
177
- translate: 0 calc(var(--studio-section-name-drop, 0px) / var(--zoom));
178
- }
179
-
180
179
  /* Sections are a name over open canvas, on a surface a shade off the canvas's
181
180
  so each reads as one piece: surfaces, not borders, until far out. Square,
182
181
  like the frames in them. */
@@ -501,60 +500,8 @@
501
500
  visibility: hidden;
502
501
  }
503
502
 
504
- /* A stack's handle: the row's, turned on its side, above the stack's first
505
- frame. It shows while the pointer is over the stack, and when held. */
506
- .studio-stack-handle {
507
- --studio-shown: 0;
508
- display: flex;
509
- align-items: center;
510
- justify-content: center;
511
- width: 3rem;
512
- height: 1.5rem;
513
- color: var(--muted-foreground);
514
- cursor: grab;
515
- background: var(--background);
516
- border-radius: 999px;
517
- box-shadow: 0 0 0 1px var(--border);
518
- opacity: var(--studio-shown);
519
- transition: --studio-shown 120ms ease-out;
520
- }
521
-
522
- .studio-stack-dots {
523
- width: 16px;
524
- height: 10px;
525
- background: radial-gradient(circle, currentColor 1.5px, transparent 1.75px) 0
526
- 0 / 6px 6px;
527
- background-position: -1px -1px;
528
- }
529
-
530
- .studio-canvas-item[data-hover="true"] .studio-stack-handle,
531
- .studio-canvas-item[data-dragging="true"] .studio-stack-handle,
532
- .studio-stack-handle:hover,
533
- .studio-stack-handle:focus-visible {
534
- --studio-shown: 1;
535
- }
536
-
537
- .studio-stack-handle:hover,
538
- .studio-stack-handle:focus-visible,
539
- .studio-canvas-item[data-dragging="true"] .studio-stack-handle {
540
- color: white;
541
- outline: none;
542
- background: var(--studio-accent);
543
- box-shadow: 0 0 0 1px var(--studio-accent);
544
- }
545
-
546
- .studio-stack-handle:active {
547
- cursor: grabbing;
548
- }
549
-
550
- .studio-canvas[data-far="true"] .studio-stack-handle,
551
- .studio-canvas:not([data-tool="select"]) .studio-stack-handle {
552
- visibility: hidden;
553
- }
554
-
555
503
  @media (hover: none) {
556
- .studio-row-handle,
557
- .studio-stack-handle {
504
+ .studio-row-handle {
558
505
  --studio-shown: 1;
559
506
  }
560
507
  }
@@ -808,7 +755,52 @@
808
755
  border-radius: 999px;
809
756
  }
810
757
 
811
- /* Resize handles on a frame's right edge, bottom edge and corner. */
758
+ .studio-frame-edge {
759
+ --studio-frame-edge: 6px;
760
+ --studio-edge-width: calc(var(--studio-frame-edge) / var(--zoom));
761
+ position: absolute;
762
+ inset: 0;
763
+ z-index: 24;
764
+ pointer-events: none;
765
+ }
766
+
767
+ .studio-frame-edge > * {
768
+ position: absolute;
769
+ pointer-events: auto;
770
+ }
771
+
772
+ .studio-frame-edge > :is([data-side="top"], [data-side="bottom"]) {
773
+ right: calc(-1 * var(--studio-edge-width));
774
+ left: calc(-1 * var(--studio-edge-width));
775
+ height: var(--studio-edge-width);
776
+ }
777
+
778
+ .studio-frame-edge > :is([data-side="left"], [data-side="right"]) {
779
+ top: 0;
780
+ bottom: 0;
781
+ width: var(--studio-edge-width);
782
+ }
783
+
784
+ .studio-frame-edge > [data-side="top"] {
785
+ top: calc(-1 * var(--studio-edge-width));
786
+ }
787
+
788
+ .studio-frame-edge > [data-side="right"] {
789
+ right: calc(-1 * var(--studio-edge-width));
790
+ }
791
+
792
+ .studio-frame-edge > [data-side="bottom"] {
793
+ bottom: calc(-1 * var(--studio-edge-width));
794
+ }
795
+
796
+ .studio-frame-edge > [data-side="left"] {
797
+ left: calc(-1 * var(--studio-edge-width));
798
+ }
799
+
800
+ .studio-frame:has(> .studio-frame-edge > :hover) .studio-artboard {
801
+ box-shadow: 0 0 0 calc(1.5px / var(--zoom)) var(--studio-accent);
802
+ }
803
+
812
804
  .studio-resize {
813
805
  position: absolute;
814
806
  z-index: 25;
@@ -821,31 +813,84 @@
821
813
  pointer-events: auto;
822
814
  }
823
815
 
824
- .studio-resize[data-edge="right"] {
816
+ .studio-resize:is([data-edge="left"], [data-edge="right"]) {
825
817
  top: 0;
826
- right: calc(-4px / var(--zoom));
827
818
  bottom: 0;
828
819
  width: calc(8px / var(--zoom));
829
820
  cursor: ew-resize;
830
821
  }
831
822
 
832
- .studio-resize[data-edge="bottom"] {
823
+ .studio-resize[data-edge="left"] {
824
+ left: calc(-4px / var(--zoom));
825
+ }
826
+
827
+ .studio-resize[data-edge="right"] {
828
+ right: calc(-4px / var(--zoom));
829
+ }
830
+
831
+ .studio-resize:is([data-edge="top"], [data-edge="bottom"]) {
833
832
  right: 0;
834
- bottom: calc(-4px / var(--zoom));
835
833
  left: 0;
836
834
  height: calc(8px / var(--zoom));
837
835
  cursor: ns-resize;
838
836
  }
839
837
 
838
+ .studio-resize[data-edge="top"] {
839
+ top: calc(-4px / var(--zoom));
840
+ }
841
+
842
+ .studio-resize[data-edge="bottom"] {
843
+ bottom: calc(-4px / var(--zoom));
844
+ }
845
+
840
846
  /* How far it reaches past the frame is layout's RESIZE_REACH. */
841
- .studio-resize[data-edge="corner"] {
842
- right: calc(-6px / var(--zoom));
843
- bottom: calc(-6px / var(--zoom));
847
+ .studio-resize:is(
848
+ [data-edge="top-left"],
849
+ [data-edge="top-right"],
850
+ [data-edge="bottom-right"],
851
+ [data-edge="bottom-left"]
852
+ ) {
853
+ z-index: 26;
844
854
  width: calc(12px / var(--zoom));
845
855
  height: calc(12px / var(--zoom));
856
+ }
857
+
858
+ .studio-resize:is([data-edge="top-left"], [data-edge="top-right"]) {
859
+ top: calc(-6px / var(--zoom));
860
+ }
861
+
862
+ .studio-resize:is([data-edge="bottom-left"], [data-edge="bottom-right"]) {
863
+ bottom: calc(-6px / var(--zoom));
864
+ }
865
+
866
+ .studio-resize:is([data-edge="top-left"], [data-edge="bottom-left"]) {
867
+ left: calc(-6px / var(--zoom));
868
+ }
869
+
870
+ .studio-resize:is([data-edge="top-right"], [data-edge="bottom-right"]) {
871
+ right: calc(-6px / var(--zoom));
872
+ }
873
+
874
+ .studio-resize:is([data-edge="top-left"], [data-edge="bottom-right"]) {
846
875
  cursor: nwse-resize;
847
876
  }
848
877
 
878
+ .studio-resize:is([data-edge="top-right"], [data-edge="bottom-left"]) {
879
+ cursor: nesw-resize;
880
+ }
881
+
882
+ .studio-resize-ghost {
883
+ position: absolute;
884
+ top: var(--studio-ghost-y);
885
+ left: var(--studio-ghost-x);
886
+ z-index: 24;
887
+ width: var(--studio-ghost-width);
888
+ height: var(--studio-ghost-height);
889
+ pointer-events: none;
890
+ background: color-mix(in oklab, var(--studio-accent) 6%, transparent);
891
+ border: calc(1px / var(--zoom)) dashed var(--studio-accent);
892
+ }
893
+
849
894
  /* The element under the pointer while commenting in a played section. */
850
895
  .studio-play-pick {
851
896
  position: absolute;
@@ -876,11 +921,12 @@
876
921
  border: calc(1px / var(--zoom)) dashed var(--studio-accent);
877
922
  }
878
923
 
879
- /* One handle, as in design tools: a white square on the corner, in light
880
- and dark, that resizes both ways, shown while the frame is selected (a
881
- request, never selected, while the pointer is on it). The edges resize
882
- too, with only the cursor to say so. */
883
- .studio-resize[data-edge="corner"]::after {
924
+ .studio-resize:is(
925
+ [data-edge="top-left"],
926
+ [data-edge="top-right"],
927
+ [data-edge="bottom-right"],
928
+ [data-edge="bottom-left"]
929
+ )::after {
884
930
  --studio-shown: 0;
885
931
  position: absolute;
886
932
  inset: calc(2px / var(--zoom));
@@ -892,10 +938,9 @@
892
938
  transition: --studio-shown 120ms ease-out;
893
939
  }
894
940
 
895
- .studio-frame[data-selected="true"] .studio-resize[data-edge="corner"]::after,
896
- .studio-section-region[data-selected="true"]
897
- .studio-resize[data-edge="corner"]::after,
898
- .studio-request:hover .studio-resize[data-edge="corner"]::after {
941
+ .studio-frame[data-selected="true"] .studio-resize::after,
942
+ .studio-section-region[data-selected="true"] .studio-resize::after,
943
+ .studio-request:hover .studio-resize::after {
899
944
  --studio-shown: 1;
900
945
  }
901
946
 
@@ -936,7 +981,7 @@
936
981
  }
937
982
 
938
983
  /* For a moment after a frame changes size, the canvas eases into its new
939
- layout instead of jumping (see settle in frame-node.tsx). */
984
+ layout instead of jumping. */
940
985
  @media (prefers-reduced-motion: no-preference) {
941
986
  /* A frame just dropped stays over the rest until it is in its place. */
942
987
  .studio-canvas[data-settling="true"] .studio-canvas-item {
@@ -977,13 +1022,32 @@
977
1022
  cursor: inherit;
978
1023
  }
979
1024
 
980
- /* Come down into its section (.studio-section-name), a name is on the
981
- section's surface over its frames, as tall as above it (py-1 for mb-2):
982
- sectionNameDrop counts on it. */
983
- .studio-canvas[data-section-names="inside"] .studio-section-handle {
984
- padding: 0.25rem;
985
- margin: 0;
1025
+ /* A section's name stays right on its section's top at every zoom. Further
1026
+ out than the gap above holds it (sectionNamesFit in layout.ts), it goes
1027
+ over the section above and its frames, so it sits on a pill of its own
1028
+ section's shade, edged as the + is: it reads over them, as part of its
1029
+ section. As tall as without it: sectionNamesFit counts on that. */
1030
+ .studio-canvas[data-section-names="overlap"] .studio-section-handle {
1031
+ padding-inline: 0.5rem;
986
1032
  background: var(--studio-section-surface);
1033
+ border-radius: 999px;
1034
+ box-shadow: 0 0 0 1px var(--border);
1035
+ }
1036
+
1037
+ /* Until it shows (.studio-reveal: the name hovered, or Play itself
1038
+ focused), Play takes no room on the pill, so the pill ends with the name
1039
+ and widens to show Play. Still there to tab to. */
1040
+ @media (hover: hover) {
1041
+ .studio-canvas[data-section-names="overlap"]
1042
+ .studio-section-handle:not(:hover, :has(.studio-reveal:focus-within)) {
1043
+ column-gap: 0;
1044
+
1045
+ & .studio-reveal {
1046
+ max-width: 0;
1047
+ padding-inline: 0;
1048
+ overflow: hidden;
1049
+ }
1050
+ }
987
1051
  }
988
1052
 
989
1053
  /* Zoomed out, row names would float into the section above: leave them. */
@@ -1255,6 +1319,7 @@
1255
1319
  /* Open, an edge stays where it is and fades as its frame slides down out of
1256
1320
  it. */
1257
1321
  .studio-stack[data-state="open"] .studio-stack-edge {
1322
+ --studio-shown: 0;
1258
1323
  transition:
1259
1324
  transform 400ms cubic-bezier(0.2, 0, 0, 1),
1260
1325
  --studio-shown 120ms ease-out;
@@ -1303,91 +1368,6 @@
1303
1368
  0 0 0 calc(4px / var(--zoom)) var(--studio-accent);
1304
1369
  }
1305
1370
 
1306
- /* How many it holds, at its top right corner, and its bar, at its top
1307
- left: the same size at any zoom. The count is grey, as a closed comment's
1308
- pin is, never black: it says how many, not that something waits. */
1309
- .studio-stack-count-at,
1310
- .studio-stack-bar-at {
1311
- position: absolute;
1312
- top: 0;
1313
- z-index: 3;
1314
- width: 0;
1315
- height: 0;
1316
- transform: scale(calc(1 / var(--zoom)));
1317
- transform-origin: 0 0;
1318
- }
1319
-
1320
- .studio-stack-count-at {
1321
- right: 0;
1322
- opacity: var(--studio-shown);
1323
- transition: --studio-shown 150ms ease-out;
1324
- }
1325
-
1326
- .studio-stack-count {
1327
- position: absolute;
1328
- top: 0;
1329
- left: 0;
1330
- display: inline-flex;
1331
- align-items: center;
1332
- justify-content: center;
1333
- min-width: 1.5rem;
1334
- height: 1.5rem;
1335
- padding: 0 0.4375rem;
1336
- font-size: 0.75rem;
1337
- font-weight: 600;
1338
- font-variant-numeric: tabular-nums;
1339
- line-height: 1;
1340
- color: var(--muted-foreground);
1341
- background: var(--muted);
1342
- border-radius: 9999px;
1343
- box-shadow: 0 0 0 2px var(--background);
1344
- transform: translate(-50%, -50%);
1345
- }
1346
-
1347
- .studio-stack[data-state="open"]
1348
- :is(.studio-stack-count-at, .studio-stack-edge) {
1349
- --studio-shown: 0;
1350
- }
1351
-
1352
- /* Open, its bar sits over the top frame's name: what it holds, Collapse
1353
- and Unstack. A plain surface: a blurred one would promote the canvas. */
1354
- .studio-stack-bar-at {
1355
- left: 0;
1356
- }
1357
-
1358
- .studio-stack-bar {
1359
- position: absolute;
1360
- bottom: 2.25rem;
1361
- left: 0;
1362
- display: flex;
1363
- gap: 0.125rem;
1364
- align-items: center;
1365
- padding: 0.25rem;
1366
- white-space: nowrap;
1367
- background: var(--popover);
1368
- border-radius: 9999px;
1369
- box-shadow:
1370
- 0 0 0 1px var(--border),
1371
- 0 2px 8px rgb(0 0 0 / 0.08);
1372
- opacity: var(--studio-shown);
1373
- animation: studio-pill-in 200ms ease-out;
1374
- }
1375
-
1376
- .studio-stack-title {
1377
- display: inline-flex;
1378
- gap: 0.375rem;
1379
- align-items: center;
1380
- height: 1.5rem;
1381
- padding: 0 0.625rem;
1382
- font-size: 0.75rem;
1383
- font-weight: 500;
1384
- border-radius: 9999px;
1385
- }
1386
-
1387
- .studio-stack-title:hover {
1388
- background: var(--studio-hover);
1389
- }
1390
-
1391
1371
  /* Under a stack fanned out, the rest of the canvas dims: a click on it folds
1392
1372
  the stack back. Under the stack's frames (canvas-scene's OPEN_STACK_Z). */
1393
1373
  .studio-stack-scrim {
@@ -0,0 +1,156 @@
1
+ import { Trans, useLingui } from "@lingui/react/macro";
2
+ import { Button } from "@studio/ui/shadcn/button";
3
+ import {
4
+ Dialog,
5
+ DialogContent,
6
+ DialogHeader,
7
+ DialogTitle,
8
+ DialogTrigger,
9
+ } from "@studio/ui/shadcn/dialog";
10
+ import { cn } from "cn";
11
+ import { useEffect, useRef, useState } from "react";
12
+
13
+ import type { StudioAnswers } from "../../src/shared/studio-routes.ts";
14
+ import { CAN_WRITE } from "../live/studio-api";
15
+ import { onReconnect } from "../live/studio-live";
16
+ import { studioRequest, studioUrl } from "../live/studio-request";
17
+
18
+ type Kept = StudioAnswers["change-pictures"]["GET"];
19
+
20
+ const useKeptPictures = (
21
+ thread: string,
22
+ closedAt: string
23
+ ): Kept | undefined => {
24
+ const [kept, setKept] = useState<{ closedAt: string; pictures: Kept }>();
25
+
26
+ useEffect(() => {
27
+ if (!CAN_WRITE) {
28
+ return;
29
+ }
30
+
31
+ let asking = new AbortController();
32
+
33
+ const ask = () => {
34
+ asking.abort();
35
+ asking = new AbortController();
36
+
37
+ studioRequest("change-pictures", {
38
+ query: { thread },
39
+ signal: asking.signal,
40
+ })
41
+ .then((pictures) => setKept({ closedAt, pictures }))
42
+ .catch(() => undefined);
43
+ };
44
+
45
+ ask();
46
+ const stopListening = onReconnect(ask);
47
+
48
+ return () => {
49
+ stopListening();
50
+ asking.abort();
51
+ };
52
+ }, [closedAt, thread]);
53
+
54
+ return kept?.closedAt === closedAt ? kept.pictures : undefined;
55
+ };
56
+
57
+ const pictureUrl = (thread: string, moment: keyof Kept, stamp: number) =>
58
+ studioUrl("change-picture", { thread, moment, v: String(stamp) });
59
+
60
+ export const ChangePictures = ({
61
+ closedAt,
62
+ thread,
63
+ }: {
64
+ closedAt: string;
65
+ thread: string;
66
+ }) => {
67
+ const { t } = useLingui();
68
+ const kept = useKeptPictures(thread, closedAt);
69
+ const [opened, setOpened] = useState<Kept>();
70
+ const [gone, setGone] = useState<Kept>();
71
+ const place = useRef<HTMLDivElement>(null);
72
+ const shown = opened ?? kept;
73
+
74
+ if (shown?.after === undefined) {
75
+ return null;
76
+ }
77
+
78
+ const offered = kept?.after !== undefined && gone !== kept;
79
+ const missing = gone === shown;
80
+
81
+ const pictures = (
82
+ [
83
+ ["before", t`Before`, t`The frame before the change`],
84
+ ["after", t`After`, t`The frame after the change`],
85
+ ] as const
86
+ ).flatMap(([moment, label, alt]) => {
87
+ const stamp = shown[moment];
88
+
89
+ return stamp === undefined
90
+ ? []
91
+ : [{ alt, label, moment, src: pictureUrl(thread, moment, stamp) }];
92
+ });
93
+
94
+ return (
95
+ <div className="outline-none" ref={place} tabIndex={-1}>
96
+ <Dialog
97
+ onOpenChange={(open) => setOpened(open ? kept : undefined)}
98
+ open={opened !== undefined}
99
+ >
100
+ {offered ? (
101
+ <DialogTrigger
102
+ render={
103
+ <Button
104
+ className="text-muted-foreground -ml-2"
105
+ size="xs"
106
+ variant="ghost"
107
+ />
108
+ }
109
+ >
110
+ <Trans>Show the change</Trans>
111
+ </DialogTrigger>
112
+ ) : null}
113
+ <DialogContent
114
+ className="sm:max-w-5xl"
115
+ finalFocus={offered ? true : place}
116
+ >
117
+ <DialogHeader>
118
+ <DialogTitle>
119
+ {shown.before === undefined ? (
120
+ <Trans>After the change</Trans>
121
+ ) : (
122
+ <Trans>Before and after</Trans>
123
+ )}
124
+ </DialogTitle>
125
+ </DialogHeader>
126
+ {missing ? (
127
+ <p className="text-muted-foreground">
128
+ <Trans>Dex no longer has the pictures of this change.</Trans>
129
+ </p>
130
+ ) : (
131
+ <div
132
+ className={cn(
133
+ "grid max-h-[75vh] gap-4 overflow-auto",
134
+ pictures.length > 1 && "grid-cols-2"
135
+ )}
136
+ >
137
+ {pictures.map(({ alt, label, moment, src }) => (
138
+ <figure className="flex min-w-0 flex-col gap-2" key={moment}>
139
+ <figcaption className="studio-small text-muted-foreground">
140
+ {label}
141
+ </figcaption>
142
+ <img
143
+ alt={alt}
144
+ className="border-border w-full rounded-md border"
145
+ onError={() => setGone(shown)}
146
+ src={src}
147
+ />
148
+ </figure>
149
+ ))}
150
+ </div>
151
+ )}
152
+ </DialogContent>
153
+ </Dialog>
154
+ </div>
155
+ );
156
+ };
@@ -0,0 +1,31 @@
1
+ import type { ThreadTarget } from "../types";
2
+
3
+ // Words written in a new comment and not posted yet, kept by the file and
4
+ // what the comment is on, so closing its card (Escape, a click away) never
5
+ // throws them away: the next card on the same thing starts with them, as
6
+ // after switching to Inspect styles and back to Comment. Posting forgets
7
+ // them. They last as long as the studio's page.
8
+
9
+ const drafts = new Map<string, string>();
10
+
11
+ /**
12
+ * What a draft is kept by: the file and what the comment is on, but not
13
+ * where on an element it was clicked.
14
+ */
15
+ export const draftKey = (file: string, target: ThreadTarget): string =>
16
+ JSON.stringify([
17
+ file,
18
+ target.kind === "element" ? { ...target, point: undefined } : target,
19
+ ]);
20
+
21
+ /** The words kept for a comment, or none. */
22
+ export const draftOf = (key: string): string => drafts.get(key) ?? "";
23
+
24
+ /** Keeps a comment's words as they are typed; none forgets them. */
25
+ export const keepDraft = (key: string, words: string) => {
26
+ if (words.trim()) {
27
+ drafts.set(key, words);
28
+ } else {
29
+ drafts.delete(key);
30
+ }
31
+ };