@open-slide/core 2.1.0 → 2.2.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 (33) hide show
  1. package/dist/{build-COxfoC_P.js → build-DTmKJyjX.js} +1 -1
  2. package/dist/cli/bin.js +3 -3
  3. package/dist/{config-CNhYSo4C.js → config-Ces2X_3T.js} +103 -14
  4. package/dist/{config-DHPbCCnt.d.ts → config-CpmGqpQi.d.ts} +1 -1
  5. package/dist/{dev-CujpTS3T.js → dev-ldYag-pR.js} +1 -1
  6. package/dist/index.d.ts +2 -2
  7. package/dist/index.js +1 -1
  8. package/dist/locale/index.d.ts +1 -1
  9. package/dist/locale/index.js +1 -1
  10. package/dist/{preview-kU5R6QXJ.js → preview-GYMbZvvk.js} +1 -1
  11. package/dist/{types-BGUi9COY.d.ts → types-CvAqFqsY.d.ts} +9 -4
  12. package/dist/vite/index.d.ts +1 -1
  13. package/dist/vite/index.js +1 -1
  14. package/dist/{zh-tw-BbFb4PZW.js → zh-tw-B7_Oqv2q.js} +35 -20
  15. package/package.json +1 -1
  16. package/skills/apply-comments/SKILL.md +9 -6
  17. package/src/app/components/icon-switcher-indicator.tsx +1 -1
  18. package/src/app/components/inspector/comment-layer.tsx +992 -0
  19. package/src/app/components/inspector/inspect-overlay.tsx +2 -39
  20. package/src/app/components/inspector/inspector-panel.tsx +9 -92
  21. package/src/app/components/inspector/inspector-provider.tsx +120 -46
  22. package/src/app/components/thumbnail-rail.tsx +39 -1
  23. package/src/app/lib/inspector/freeze-motion.ts +61 -0
  24. package/src/app/lib/inspector/use-comments.ts +32 -3
  25. package/src/app/routes/slide.tsx +6 -5
  26. package/src/app/styles.css +64 -80
  27. package/src/locale/en.ts +7 -4
  28. package/src/locale/es.ts +7 -5
  29. package/src/locale/ja.ts +7 -5
  30. package/src/locale/types.ts +9 -4
  31. package/src/locale/zh-cn.ts +7 -4
  32. package/src/locale/zh-tw.ts +7 -4
  33. package/src/app/components/inspector/comment-widget.tsx +0 -119
@@ -1,11 +1,24 @@
1
1
  import { useCallback, useEffect, useState } from 'react';
2
2
 
3
+ export type CommentRect = { x: number; y: number; w: number; h: number };
4
+
3
5
  export type SlideComment = {
4
6
  id: string;
5
7
  line: number;
6
8
  ts: string;
7
9
  note: string;
8
10
  hint?: string;
11
+ rect?: CommentRect;
12
+ page?: number;
13
+ target?: { line: number; column: number } | null;
14
+ };
15
+
16
+ export type AddCommentInput = {
17
+ line: number;
18
+ column: number;
19
+ text: string;
20
+ rect?: CommentRect;
21
+ page?: number;
9
22
  };
10
23
 
11
24
  type ListResponse = { comments: SlideComment[] };
@@ -31,11 +44,11 @@ export function useComments(slideId: string) {
31
44
  }, [slideId]);
32
45
 
33
46
  const add = useCallback(
34
- async (line: number, column: number, text: string) => {
47
+ async (input: AddCommentInput) => {
35
48
  const res = await fetch('/__comments/add', {
36
49
  method: 'POST',
37
50
  headers: { 'content-type': 'application/json' },
38
- body: JSON.stringify({ slideId, line, column, text }),
51
+ body: JSON.stringify({ slideId, ...input }),
39
52
  });
40
53
  if (!res.ok) {
41
54
  const body = (await res.json().catch(() => ({}))) as { error?: string };
@@ -46,6 +59,22 @@ export function useComments(slideId: string) {
46
59
  [slideId, refetch],
47
60
  );
48
61
 
62
+ const update = useCallback(
63
+ async (id: string, text: string) => {
64
+ const res = await fetch(`/__comments/${id}`, {
65
+ method: 'PUT',
66
+ headers: { 'content-type': 'application/json' },
67
+ body: JSON.stringify({ slideId, text }),
68
+ });
69
+ if (!res.ok) {
70
+ const body = (await res.json().catch(() => ({}))) as { error?: string };
71
+ throw new Error(body.error ?? `PUT /__comments/${id} → ${res.status}`);
72
+ }
73
+ await refetch();
74
+ },
75
+ [slideId, refetch],
76
+ );
77
+
49
78
  const remove = useCallback(
50
79
  async (id: string) => {
51
80
  const res = await fetch(`/__comments/${id}?slideId=${encodeURIComponent(slideId)}`, {
@@ -70,5 +99,5 @@ export function useComments(slideId: string) {
70
99
  };
71
100
  }, [refetch]);
72
101
 
73
- return { comments, error, add, remove };
102
+ return { comments, error, add, update, remove };
74
103
  }
@@ -29,7 +29,7 @@ import { Link, useNavigate, useParams, useSearchParams } from 'react-router-dom'
29
29
  import { toast } from 'sonner';
30
30
  import { AssetView } from '@/components/asset-view';
31
31
  import { HistoryProvider } from '@/components/history-provider';
32
- import { CommentWidget } from '@/components/inspector/comment-widget';
32
+ import { CommentLayer } from '@/components/inspector/comment-layer';
33
33
  import { InlineEditLayer } from '@/components/inspector/inline-text-editor';
34
34
  import { InspectOverlay } from '@/components/inspector/inspect-overlay';
35
35
  import {
@@ -855,7 +855,7 @@ export function Slide() {
855
855
  <InspectOverlay />
856
856
  <InlineEditLayer />
857
857
  <SaveBar />
858
- {import.meta.env.DEV && <CommentWidget />}
858
+ {import.meta.env.DEV && <CommentLayer />}
859
859
  </main>
860
860
  {/* Mobile-only horizontal rail. Sits below the canvas and
861
861
  pads its bottom for the iOS home indicator / Safari URL bar. */}
@@ -1167,13 +1167,14 @@ function SlideViewportNavigation({
1167
1167
  canPrev: boolean;
1168
1168
  canNext: boolean;
1169
1169
  }) {
1170
- const { active, inlineEdit } = useInspector();
1170
+ const { mode, inlineEdit } = useInspector();
1171
1171
  const isMobile = useIsMobile();
1172
1172
  const editing = !!inlineEdit;
1173
+ const browsing = mode === 'preview';
1173
1174
 
1174
1175
  useWheelPageNavigation({
1175
1176
  ref: targetRef,
1176
- enabled: !active && !editing,
1177
+ enabled: browsing && !editing,
1177
1178
  canPrev,
1178
1179
  canNext,
1179
1180
  onPrev,
@@ -1185,7 +1186,7 @@ function SlideViewportNavigation({
1185
1186
  // zones). Interactive slide content keeps its tap via the hook's passthrough.
1186
1187
  useClickPageNavigation({
1187
1188
  ref: targetRef,
1188
- enabled: isMobile && !active && !editing,
1189
+ enabled: isMobile && browsing && !editing,
1189
1190
  edgeRatio: 0.18,
1190
1191
  canPrev,
1191
1192
  canNext,
@@ -222,109 +222,93 @@
222
222
  }
223
223
 
224
224
  /*
225
- * Comment input cue — kept from the original design but retoned to match
226
- * the new palette (warm vermillion + amber instead of the AI-classic
227
- * blue/violet halo). Plays once on first open, then settles.
225
+ * Indeterminate "line loader" — a hairline track with a short bar that
226
+ * glides back and forth. Used for full-screen loading states in place of
227
+ * a spinner; quieter, more typographic, easier on the eye.
228
228
  */
229
- @property --comment-cue-angle {
230
- syntax: "<angle>";
231
- initial-value: 0deg;
232
- inherits: false;
229
+ /* Comment-mode hint pill: the shell materializes once, then every text
230
+ swap blurs the old copy out while the new one blurs in. */
231
+ @keyframes island-enter {
232
+ from {
233
+ opacity: 0;
234
+ filter: blur(6px);
235
+ transform: translateY(6px) scale(0.9);
236
+ }
233
237
  }
234
238
 
235
- .comment-cue {
236
- position: relative;
237
- isolation: isolate;
239
+ @keyframes island-arrive {
240
+ from {
241
+ opacity: 0;
242
+ filter: blur(6px);
243
+ transform: scale(0.94);
244
+ }
238
245
  }
239
246
 
240
- .comment-cue::before {
241
- content: "";
242
- position: absolute;
243
- inset: -1px;
244
- border-radius: calc(var(--radius-md) + 1px);
245
- padding: 1.25px;
246
- background: conic-gradient(
247
- from var(--comment-cue-angle),
248
- transparent 0deg,
249
- transparent 250deg,
250
- oklch(0.78 0.14 60 / 0.55) 295deg,
251
- oklch(0.62 0.2 28 / 0.85) 325deg,
252
- oklch(0.78 0.14 60 / 0.55) 350deg,
253
- transparent 360deg
254
- );
255
- -webkit-mask:
256
- linear-gradient(#000 0 0) content-box,
257
- linear-gradient(#000 0 0);
258
- -webkit-mask-composite: xor;
259
- mask:
260
- linear-gradient(#000 0 0) content-box,
261
- linear-gradient(#000 0 0);
262
- mask-composite: exclude;
263
- pointer-events: none;
264
- opacity: 0;
265
- z-index: 1;
266
- animation: comment-cue-trace 1500ms cubic-bezier(0.22, 0.61, 0.36, 1) 220ms 1 both;
247
+ @keyframes island-leave {
248
+ to {
249
+ opacity: 0;
250
+ filter: blur(6px);
251
+ transform: scale(0.94);
252
+ }
267
253
  }
268
254
 
269
- .comment-cue::after {
270
- content: "";
271
- position: absolute;
272
- inset: -10px;
273
- border-radius: calc(var(--radius-md) + 10px);
274
- background:
275
- radial-gradient(80% 60% at 30% 50%, oklch(0.62 0.2 28 / 0.18), transparent 70%),
276
- radial-gradient(70% 60% at 75% 60%, oklch(0.78 0.14 60 / 0.16), transparent 70%);
277
- filter: blur(14px);
278
- opacity: 0;
279
- z-index: -1;
255
+ .island-enter {
256
+ animation: island-enter 420ms cubic-bezier(0.32, 0.72, 0, 1) both;
257
+ }
258
+
259
+ .island-arrive {
260
+ animation: island-arrive 320ms cubic-bezier(0.32, 0.72, 0, 1) both;
261
+ }
262
+
263
+ .island-leave {
280
264
  pointer-events: none;
281
- animation: comment-cue-halo 1700ms ease-out 180ms 1 both;
265
+ animation: island-leave 320ms cubic-bezier(0.32, 0.72, 0, 1) both;
282
266
  }
283
267
 
284
- @keyframes comment-cue-trace {
285
- 0% {
286
- --comment-cue-angle: 0deg;
287
- opacity: 0;
288
- }
289
- 18% {
290
- opacity: 1;
291
- }
292
- 82% {
293
- opacity: 1;
294
- }
295
- 100% {
296
- --comment-cue-angle: 360deg;
268
+ /* Counter digits roll in the direction of the change (--roll: 1 up, -1 down). */
269
+ @keyframes roll-arrive {
270
+ from {
297
271
  opacity: 0;
272
+ transform: translateY(calc(var(--roll, 1) * 100%));
298
273
  }
299
274
  }
300
275
 
301
- @keyframes comment-cue-halo {
302
- 0% {
303
- opacity: 0;
304
- transform: scale(0.97);
305
- }
306
- 40% {
307
- opacity: 1;
308
- transform: scale(1);
309
- }
310
- 100% {
276
+ @keyframes roll-leave {
277
+ to {
311
278
  opacity: 0;
312
- transform: scale(1.015);
279
+ transform: translateY(calc(var(--roll, 1) * -100%));
313
280
  }
314
281
  }
315
282
 
283
+ .roll-arrive {
284
+ animation: roll-arrive 320ms cubic-bezier(0.32, 0.72, 0, 1) both;
285
+ }
286
+
287
+ .roll-leave {
288
+ pointer-events: none;
289
+ animation: roll-leave 320ms cubic-bezier(0.32, 0.72, 0, 1) both;
290
+ }
291
+
316
292
  @media (prefers-reduced-motion: reduce) {
317
- .comment-cue::before,
318
- .comment-cue::after {
293
+ .island-enter,
294
+ .island-arrive {
295
+ animation: island-arrive 160ms ease-out both;
296
+ filter: none;
297
+ transform: none;
298
+ }
299
+
300
+ .island-leave,
301
+ .roll-leave {
319
302
  animation: none;
303
+ opacity: 0;
304
+ }
305
+
306
+ .roll-arrive {
307
+ animation: island-arrive 160ms ease-out both;
308
+ transform: none;
320
309
  }
321
310
  }
322
311
 
323
- /*
324
- * Indeterminate "line loader" — a hairline track with a short bar that
325
- * glides back and forth. Used for full-screen loading states in place of
326
- * a spinner; quieter, more typographic, easier on the eye.
327
- */
328
312
  @keyframes osd-line-loader {
329
313
  0% {
330
314
  transform: translateX(0%);
package/src/locale/en.ts CHANGED
@@ -287,10 +287,9 @@ export const en: Locale = {
287
287
  cropFitCover: 'Fill',
288
288
  cropFitContain: 'Fit',
289
289
  cropApply: 'Apply',
290
- leaveComment: 'Comment',
290
+ commentMode: 'Comment',
291
291
  commentPlaceholder: 'Describe a change for the agent…',
292
- commentShortcutHint: '⌘/ to focus · ⌘↵ to add',
293
- addComment: 'Add comment',
292
+ commentPost: 'Post',
294
293
  unsavedChanges: {
295
294
  one: '{count} unsaved change',
296
295
  other: '{count} unsaved changes',
@@ -300,10 +299,14 @@ export const en: Locale = {
300
299
  other: '{count} comments',
301
300
  },
302
301
  commentLineLabel: 'line {n}',
303
- commentsEmpty: 'No comments yet. Select an object and open Comment in the Format panel.',
302
+ commentRegionLabel: 'region',
303
+ commentEmptyHint: 'Click an element or drag across a region to leave a comment.',
304
304
  commentsApplyHintPrefix: 'Run ',
305
305
  commentsApplyHintSuffix: ' in your agent to apply these.',
306
306
  commentDeleteAria: 'Delete',
307
+ commentUpdateFailed: "Couldn't update comment:",
308
+ commentAddFailed: "Couldn't add comment:",
309
+ commentRegionNoTarget: "Couldn't find an element to attach this region to.",
307
310
  saveFailed: "Couldn't save:",
308
311
  decreaseFontSize: 'Decrease font size',
309
312
  increaseFontSize: 'Increase font size',
package/src/locale/es.ts CHANGED
@@ -292,10 +292,9 @@ export const es: Locale = {
292
292
  cropFitCover: 'Rellenar',
293
293
  cropFitContain: 'Ajustar',
294
294
  cropApply: 'Aplicar',
295
- leaveComment: 'Comentar',
295
+ commentMode: 'Comentar',
296
296
  commentPlaceholder: 'Describe un cambio para el agente…',
297
- commentShortcutHint: '⌘/ para enfocar · ⌘↵ para añadir',
298
- addComment: 'Añadir comentario',
297
+ commentPost: 'Publicar',
299
298
  unsavedChanges: {
300
299
  one: '{count} cambio sin guardar',
301
300
  other: '{count} cambios sin guardar',
@@ -305,11 +304,14 @@ export const es: Locale = {
305
304
  other: '{count} comentarios',
306
305
  },
307
306
  commentLineLabel: 'línea {n}',
308
- commentsEmpty:
309
- 'Aún no hay comentarios. Selecciona un objeto y abre Comentar en el panel de formato.',
307
+ commentRegionLabel: 'zona',
308
+ commentEmptyHint: 'Haz clic en un elemento o arrastra sobre una zona para dejar un comentario.',
310
309
  commentsApplyHintPrefix: 'Ejecuta ',
311
310
  commentsApplyHintSuffix: ' en tu agente para aplicarlos.',
312
311
  commentDeleteAria: 'Eliminar',
312
+ commentUpdateFailed: 'No se pudo actualizar el comentario:',
313
+ commentAddFailed: 'No se pudo añadir el comentario:',
314
+ commentRegionNoTarget: 'No se encontró un elemento al que asociar esta zona.',
313
315
  saveFailed: 'No se pudo guardar:',
314
316
  decreaseFontSize: 'Reducir tamaño de fuente',
315
317
  increaseFontSize: 'Aumentar tamaño de fuente',
package/src/locale/ja.ts CHANGED
@@ -290,10 +290,9 @@ export const ja: Locale = {
290
290
  agentNotWatching: 'エージェント未接続',
291
291
  agentNotWatchingTooltip:
292
292
  'dev server との接続が切れたため、選択中の要素がエージェントに見えなくなっています。dev server を再起動して接続を復旧してください。',
293
- leaveComment: 'コメント',
293
+ commentMode: 'コメント',
294
294
  commentPlaceholder: 'エージェントに依頼する変更を記述…',
295
- commentShortcutHint: '⌘/ でフォーカス · ⌘↵ で追加',
296
- addComment: 'コメントを追加',
295
+ commentPost: '投稿',
297
296
  unsavedChanges: {
298
297
  one: '未保存の変更 {count} 件',
299
298
  other: '未保存の変更 {count} 件',
@@ -303,11 +302,14 @@ export const ja: Locale = {
303
302
  other: 'コメント {count} 件',
304
303
  },
305
304
  commentLineLabel: '行 {n}',
306
- commentsEmpty:
307
- 'まだコメントはありません。インスペクトを有効にしてスライド要素をクリックしてください。',
305
+ commentRegionLabel: '範囲',
306
+ commentEmptyHint: '要素をクリックするか、範囲をドラッグしてコメントを残せます。',
308
307
  commentsApplyHintPrefix: 'エージェントで ',
309
308
  commentsApplyHintSuffix: ' を実行して適用してください。',
310
309
  commentDeleteAria: '削除',
310
+ commentUpdateFailed: 'コメントを更新できませんでした:',
311
+ commentAddFailed: 'コメントを追加できませんでした:',
312
+ commentRegionNoTarget: 'この範囲を付けられる要素が見つかりませんでした。',
311
313
  saveFailed: '保存に失敗しました:',
312
314
  decreaseFontSize: 'フォントサイズを縮小',
313
315
  increaseFontSize: 'フォントサイズを拡大',
@@ -287,20 +287,25 @@ export type Locale = {
287
287
  cropFitCover: string;
288
288
  cropFitContain: string;
289
289
  cropApply: string;
290
- leaveComment: string;
290
+ commentMode: string;
291
291
  commentPlaceholder: string;
292
- commentShortcutHint: string;
293
- addComment: string;
292
+ commentPost: string;
294
293
  /** templates: "{count} unsaved change" / "{count} unsaved changes" */
295
294
  unsavedChanges: Plural;
296
295
  /** templates: "{count} comment" / "{count} comments" */
297
296
  commentsCount: Plural;
298
297
  /** template: "line {n}" */
299
298
  commentLineLabel: string;
300
- commentsEmpty: string;
299
+ commentRegionLabel: string;
300
+ commentEmptyHint: string;
301
301
  commentsApplyHintPrefix: string;
302
302
  commentsApplyHintSuffix: string;
303
303
  commentDeleteAria: string;
304
+ /** Prefix for the toast shown when a comment edit fails to write to disk. */
305
+ commentUpdateFailed: string;
306
+ /** Prefix for the toast shown when a comment fails to write to disk. */
307
+ commentAddFailed: string;
308
+ commentRegionNoTarget: string;
304
309
  /** Prefix for the toast shown when one or more buffered edits fail to write to disk. */
305
310
  saveFailed: string;
306
311
  decreaseFontSize: string;
@@ -284,10 +284,9 @@ export const zhCN: Locale = {
284
284
  agentNotWatching: 'Agent 没在关注',
285
285
  agentNotWatchingTooltip:
286
286
  '已和 dev server 断开连接,agent 看不到你选的元素了。请重新启动 dev server 来恢复连接。',
287
- leaveComment: '评论',
287
+ commentMode: '评论',
288
288
  commentPlaceholder: '描述你希望代理执行的更改…',
289
- commentShortcutHint: '⌘/ 聚焦 · ⌘↵ 添加',
290
- addComment: '添加 comment',
289
+ commentPost: '发送',
291
290
  unsavedChanges: {
292
291
  one: '{count} 项未保存的更改',
293
292
  other: '{count} 项未保存的更改',
@@ -297,10 +296,14 @@ export const zhCN: Locale = {
297
296
  other: '{count} 条评论',
298
297
  },
299
298
  commentLineLabel: '第 {n} 行',
300
- commentsEmpty: '还没有评论。选中对象后,在格式面板中打开“评论”。',
299
+ commentRegionLabel: '区域',
300
+ commentEmptyHint: '点击元素或拖拽框选一个区域来评论。',
301
301
  commentsApplyHintPrefix: '在你的代理中运行 ',
302
302
  commentsApplyHintSuffix: ' 以应用这些更改。',
303
303
  commentDeleteAria: '删除',
304
+ commentUpdateFailed: '无法更新评论:',
305
+ commentAddFailed: '无法添加评论:',
306
+ commentRegionNoTarget: '找不到可以附加该区域的元素。',
304
307
  saveFailed: '保存失败:',
305
308
  decreaseFontSize: '缩小字号',
306
309
  increaseFontSize: '放大字号',
@@ -284,10 +284,9 @@ export const zhTW: Locale = {
284
284
  agentNotWatching: 'Agent 沒在關注',
285
285
  agentNotWatchingTooltip:
286
286
  '已和 dev server 斷線,agent 看不到你選的元素了。請重新啟動 dev server 來恢復連線。',
287
- leaveComment: '留言',
287
+ commentMode: '留言',
288
288
  commentPlaceholder: '描述你希望代理進行的修改…',
289
- commentShortcutHint: '⌘/ 聚焦 · ⌘↵ 新增',
290
- addComment: '新增 comment',
289
+ commentPost: '送出',
291
290
  unsavedChanges: {
292
291
  one: '{count} 項未儲存的變更',
293
292
  other: '{count} 項未儲存的變更',
@@ -297,10 +296,14 @@ export const zhTW: Locale = {
297
296
  other: '{count} 則留言',
298
297
  },
299
298
  commentLineLabel: '第 {n} 行',
300
- commentsEmpty: '還沒有留言。選取物件後,在格式面板中開啟「留言」。',
299
+ commentRegionLabel: '範圍',
300
+ commentEmptyHint: '點選元件或拖曳框選一個範圍來留言。',
301
301
  commentsApplyHintPrefix: '在你的代理中執行 ',
302
302
  commentsApplyHintSuffix: ' 以套用這些變更。',
303
303
  commentDeleteAria: '刪除',
304
+ commentUpdateFailed: '無法更新留言:',
305
+ commentAddFailed: '無法新增留言:',
306
+ commentRegionNoTarget: '找不到可以附加這個範圍的元件。',
304
307
  saveFailed: '儲存失敗:',
305
308
  decreaseFontSize: '縮小字級',
306
309
  increaseFontSize: '放大字級',
@@ -1,119 +0,0 @@
1
- import { MessageSquare, Trash2, X } from 'lucide-react';
2
- import { useEffect, useRef, useState } from 'react';
3
- import { usePanelMount } from '@/components/panel/panel-shell';
4
- import { format, plural, useLocale } from '@/lib/use-locale';
5
- import { cn } from '@/lib/utils';
6
- import { useInspector } from './inspector-provider';
7
-
8
- export function CommentWidget() {
9
- const t = useLocale();
10
- const { comments, remove, error } = useInspector();
11
- const [open, setOpen] = useState(false);
12
- const count = comments.length;
13
- const ref = useRef<HTMLDivElement>(null);
14
- const panelRef = useRef<HTMLDivElement>(null);
15
- const fabRef = useRef<HTMLButtonElement>(null);
16
- const { mounted, animVisible } = usePanelMount(open);
17
-
18
- useEffect(() => {
19
- if (!open) return;
20
- const onPointerDown = (e: PointerEvent) => {
21
- if (!ref.current?.contains(e.target as Node)) setOpen(false);
22
- };
23
- document.addEventListener('pointerdown', onPointerDown);
24
- return () => document.removeEventListener('pointerdown', onPointerDown);
25
- }, [open]);
26
-
27
- // The panel stays mounted through its close fade; hand focus back to the
28
- // toggle so it doesn't sit on a control that's about to unmount.
29
- useEffect(() => {
30
- if (open) return;
31
- if (panelRef.current?.contains(document.activeElement)) fabRef.current?.focus();
32
- }, [open]);
33
-
34
- return (
35
- <div
36
- ref={ref}
37
- data-inspector-ui
38
- className="absolute right-4 bottom-4 z-20 flex flex-col items-end gap-2"
39
- >
40
- {mounted && (
41
- <div
42
- ref={panelRef}
43
- aria-hidden={!animVisible}
44
- className={cn(
45
- 'w-80 origin-bottom-right rounded-[8px] border bg-card shadow-overlay',
46
- 'motion-safe:transition-[opacity,translate,scale] motion-safe:duration-200 motion-safe:ease-swift',
47
- animVisible
48
- ? 'translate-y-0 scale-100 opacity-100'
49
- : 'pointer-events-none translate-y-1.5 scale-95 opacity-0',
50
- )}
51
- >
52
- <div className="flex items-center justify-between border-b px-3 py-2">
53
- <span className="text-xs font-semibold">
54
- {format(plural(count, t.inspector.commentsCount), { count })}
55
- </span>
56
- <button
57
- type="button"
58
- aria-label={t.common.close}
59
- className="-m-1 rounded-[5px] p-1 text-muted-foreground transition-[color,scale] duration-150 hover:text-foreground active:scale-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/40"
60
- onClick={() => setOpen(false)}
61
- >
62
- <X className="size-3.5" />
63
- </button>
64
- </div>
65
- {error && <p className="px-3 py-2 text-xs text-destructive">{error}</p>}
66
- {count === 0 ? (
67
- <p className="px-3 py-6 text-center text-xs text-muted-foreground">
68
- {t.inspector.commentsEmpty}
69
- </p>
70
- ) : (
71
- <>
72
- <ul className="max-h-72 overflow-auto">
73
- {comments.map((c) => (
74
- <li
75
- key={c.id}
76
- className="flex items-start gap-2 border-b px-3 py-2 last:border-0"
77
- >
78
- <div className="min-w-0 flex-1">
79
- <div className="text-[10px] font-mono text-muted-foreground">
80
- {format(t.inspector.commentLineLabel, { n: c.line })}
81
- </div>
82
- <div className="mt-0.5 text-xs break-words">{c.note}</div>
83
- </div>
84
- <button
85
- type="button"
86
- onClick={() => remove(c.id)}
87
- className="shrink-0 rounded-[5px] p-1 text-muted-foreground transition-[color,background-color,scale] duration-150 hover:bg-muted hover:text-destructive active:scale-90 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/40"
88
- aria-label={t.inspector.commentDeleteAria}
89
- title={t.inspector.commentDeleteAria}
90
- >
91
- <Trash2 className="size-3.5" />
92
- </button>
93
- </li>
94
- ))}
95
- </ul>
96
- <div className="border-t px-3 py-2 text-[11px] text-muted-foreground">
97
- {t.inspector.commentsApplyHintPrefix}
98
- <code className="rounded bg-muted px-1 py-0.5 font-mono text-foreground">
99
- /apply-comments
100
- </code>
101
- {t.inspector.commentsApplyHintSuffix}
102
- </div>
103
- </>
104
- )}
105
- </div>
106
- )}
107
- <button
108
- ref={fabRef}
109
- type="button"
110
- onClick={() => setOpen((o) => !o)}
111
- className="flex items-center gap-2 rounded-full border bg-card px-3 py-2 text-xs font-medium shadow-floating transition-[background-color,scale] duration-150 hover:bg-muted active:scale-[0.96] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/40"
112
- aria-expanded={open}
113
- >
114
- <MessageSquare className="size-4" />
115
- <span className="nums">{count}</span>
116
- </button>
117
- </div>
118
- );
119
- }