@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.
- package/dist/{build-COxfoC_P.js → build-DTmKJyjX.js} +1 -1
- package/dist/cli/bin.js +3 -3
- package/dist/{config-CNhYSo4C.js → config-Ces2X_3T.js} +103 -14
- package/dist/{config-DHPbCCnt.d.ts → config-CpmGqpQi.d.ts} +1 -1
- package/dist/{dev-CujpTS3T.js → dev-ldYag-pR.js} +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/locale/index.d.ts +1 -1
- package/dist/locale/index.js +1 -1
- package/dist/{preview-kU5R6QXJ.js → preview-GYMbZvvk.js} +1 -1
- package/dist/{types-BGUi9COY.d.ts → types-CvAqFqsY.d.ts} +9 -4
- package/dist/vite/index.d.ts +1 -1
- package/dist/vite/index.js +1 -1
- package/dist/{zh-tw-BbFb4PZW.js → zh-tw-B7_Oqv2q.js} +35 -20
- package/package.json +1 -1
- package/skills/apply-comments/SKILL.md +9 -6
- package/src/app/components/icon-switcher-indicator.tsx +1 -1
- package/src/app/components/inspector/comment-layer.tsx +992 -0
- package/src/app/components/inspector/inspect-overlay.tsx +2 -39
- package/src/app/components/inspector/inspector-panel.tsx +9 -92
- package/src/app/components/inspector/inspector-provider.tsx +120 -46
- package/src/app/components/thumbnail-rail.tsx +39 -1
- package/src/app/lib/inspector/freeze-motion.ts +61 -0
- package/src/app/lib/inspector/use-comments.ts +32 -3
- package/src/app/routes/slide.tsx +6 -5
- package/src/app/styles.css +64 -80
- package/src/locale/en.ts +7 -4
- package/src/locale/es.ts +7 -5
- package/src/locale/ja.ts +7 -5
- package/src/locale/types.ts +9 -4
- package/src/locale/zh-cn.ts +7 -4
- package/src/locale/zh-tw.ts +7 -4
- package/src/app/components/inspector/comment-widget.tsx +0 -119
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Crop, ImageIcon } from 'lucide-react';
|
|
2
2
|
import { useEffect, useLayoutEffect, useRef, useState } from 'react';
|
|
3
3
|
import { findSlideSource } from '@/lib/inspector/fiber';
|
|
4
|
+
import { useFreezeSlideMotion } from '@/lib/inspector/freeze-motion';
|
|
4
5
|
import {
|
|
5
6
|
type Guide,
|
|
6
7
|
type Point,
|
|
@@ -98,19 +99,7 @@ export function InspectOverlay() {
|
|
|
98
99
|
const [scale, setScale] = useState(1);
|
|
99
100
|
const displayed = localTargets ?? selection;
|
|
100
101
|
|
|
101
|
-
|
|
102
|
-
if (!active) return;
|
|
103
|
-
const root = document.querySelector<HTMLElement>('[data-inspector-root]');
|
|
104
|
-
if (!root) return;
|
|
105
|
-
const style = document.createElement('style');
|
|
106
|
-
style.textContent = EDITING_FREEZE_CSS;
|
|
107
|
-
document.head.appendChild(style);
|
|
108
|
-
root.dataset.inspectorEditing = 'true';
|
|
109
|
-
return () => {
|
|
110
|
-
style.remove();
|
|
111
|
-
delete root.dataset.inspectorEditing;
|
|
112
|
-
};
|
|
113
|
-
}, [active]);
|
|
102
|
+
useFreezeSlideMotion(active ? 'edit' : null);
|
|
114
103
|
|
|
115
104
|
useLayoutEffect(() => {
|
|
116
105
|
if (!active) return;
|
|
@@ -656,29 +645,3 @@ export function InspectOverlay() {
|
|
|
656
645
|
</div>
|
|
657
646
|
);
|
|
658
647
|
}
|
|
659
|
-
|
|
660
|
-
const EDITING_FREEZE_CSS = `
|
|
661
|
-
[data-inspector-editing] { touch-action: none; }
|
|
662
|
-
[data-inspector-editing] *:not([data-inspector-ui], [data-inspector-ui] *),
|
|
663
|
-
[data-inspector-editing] *:not([data-inspector-ui], [data-inspector-ui] *)::before,
|
|
664
|
-
[data-inspector-editing] *:not([data-inspector-ui], [data-inspector-ui] *)::after {
|
|
665
|
-
animation-duration: 1ms !important;
|
|
666
|
-
animation-delay: 0s !important;
|
|
667
|
-
animation-iteration-count: 1 !important;
|
|
668
|
-
animation-fill-mode: forwards !important;
|
|
669
|
-
transition: none !important;
|
|
670
|
-
view-transition-name: none !important;
|
|
671
|
-
user-select: none;
|
|
672
|
-
}
|
|
673
|
-
[data-inspector-editing] *:not([data-inspector-ui], [data-inspector-ui] *, [data-visual-gesture], [data-visual-gesture] *),
|
|
674
|
-
[data-inspector-editing] *:not([data-inspector-ui], [data-inspector-ui] *, [data-visual-gesture], [data-visual-gesture] *)::before,
|
|
675
|
-
[data-inspector-editing] *:not([data-inspector-ui], [data-inspector-ui] *, [data-visual-gesture], [data-visual-gesture] *)::after {
|
|
676
|
-
cursor: default !important;
|
|
677
|
-
}
|
|
678
|
-
[data-inspector-editing] [data-visual-gesture],
|
|
679
|
-
[data-inspector-editing] [data-visual-gesture] *,
|
|
680
|
-
[data-inspector-editing] [data-visual-gesture] *::before,
|
|
681
|
-
[data-inspector-editing] [data-visual-gesture] *::after {
|
|
682
|
-
cursor: var(--osd-gesture-cursor, default) !important;
|
|
683
|
-
}
|
|
684
|
-
`;
|
|
@@ -46,7 +46,7 @@ import { styleContext } from '@/lib/inspector/text-selection';
|
|
|
46
46
|
import type { EditOp } from '@/lib/inspector/use-editor';
|
|
47
47
|
import { useAgentSocketConnected } from '@/lib/use-agent-socket';
|
|
48
48
|
import { format, useLocale } from '@/lib/use-locale';
|
|
49
|
-
import {
|
|
49
|
+
import { round2 } from '@/lib/utils';
|
|
50
50
|
import type { Locale } from '../../../locale/types';
|
|
51
51
|
import { ArrangePanel } from './arrange-panel';
|
|
52
52
|
import { AssetPickerDialog } from './asset-picker-dialog';
|
|
@@ -107,7 +107,6 @@ export function InspectorPanel({
|
|
|
107
107
|
bufferOps,
|
|
108
108
|
pendingCount,
|
|
109
109
|
opsVersion,
|
|
110
|
-
add,
|
|
111
110
|
applyEdit,
|
|
112
111
|
} = useInspector();
|
|
113
112
|
const [snapshot, setSnapshot] = useState<ElementSnapshot | null>(null);
|
|
@@ -256,19 +255,14 @@ export function InspectorPanel({
|
|
|
256
255
|
);
|
|
257
256
|
const footer =
|
|
258
257
|
selected && snapshot && !multiple ? (
|
|
259
|
-
|
|
260
|
-
<
|
|
261
|
-
<
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
<
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
</span>
|
|
268
|
-
<AgentWatchingBadge />
|
|
269
|
-
</div>
|
|
270
|
-
</CollapsibleSection>
|
|
271
|
-
</>
|
|
258
|
+
<CollapsibleSection title={t.inspector.sourceSection}>
|
|
259
|
+
<div className="flex items-center justify-between gap-2">
|
|
260
|
+
<span className="font-mono text-[10.5px] text-muted-foreground">
|
|
261
|
+
<{selected.anchor.tagName.toLowerCase()}> · {selected.line}:{selected.column}
|
|
262
|
+
</span>
|
|
263
|
+
<AgentWatchingBadge />
|
|
264
|
+
</div>
|
|
265
|
+
</CollapsibleSection>
|
|
272
266
|
) : undefined;
|
|
273
267
|
|
|
274
268
|
return (
|
|
@@ -894,83 +888,6 @@ function AgentWatchingBadge() {
|
|
|
894
888
|
);
|
|
895
889
|
}
|
|
896
890
|
|
|
897
|
-
// The cue animation re-mounts with every element selection; without this
|
|
898
|
-
// guard it replays each time instead of once per inspector session.
|
|
899
|
-
let commentCuePlayed = false;
|
|
900
|
-
|
|
901
|
-
function CommentsSection({
|
|
902
|
-
selected,
|
|
903
|
-
onAdd,
|
|
904
|
-
}: {
|
|
905
|
-
selected: { line: number; column: number };
|
|
906
|
-
onAdd: (line: number, column: number, text: string) => Promise<void>;
|
|
907
|
-
}) {
|
|
908
|
-
const [draft, setDraft] = useState('');
|
|
909
|
-
const [submitting, setSubmitting] = useState(false);
|
|
910
|
-
const [showCue] = useState(() => !commentCuePlayed);
|
|
911
|
-
const wrapRef = useRef<HTMLDivElement>(null);
|
|
912
|
-
const t = useLocale();
|
|
913
|
-
|
|
914
|
-
useEffect(() => {
|
|
915
|
-
commentCuePlayed = true;
|
|
916
|
-
}, []);
|
|
917
|
-
|
|
918
|
-
useEffect(() => {
|
|
919
|
-
const onKey = (e: KeyboardEvent) => {
|
|
920
|
-
if (e.key !== '/') return;
|
|
921
|
-
if (!(e.metaKey || e.ctrlKey)) return;
|
|
922
|
-
if (e.altKey || e.shiftKey) return;
|
|
923
|
-
const ta = wrapRef.current?.querySelector('textarea');
|
|
924
|
-
if (!ta) return;
|
|
925
|
-
e.preventDefault();
|
|
926
|
-
const details = ta.closest('details');
|
|
927
|
-
if (details) details.open = true;
|
|
928
|
-
ta.focus({ preventScroll: true });
|
|
929
|
-
};
|
|
930
|
-
window.addEventListener('keydown', onKey);
|
|
931
|
-
return () => window.removeEventListener('keydown', onKey);
|
|
932
|
-
}, []);
|
|
933
|
-
|
|
934
|
-
const submit = async () => {
|
|
935
|
-
const trimmed = draft.trim();
|
|
936
|
-
if (!trimmed) return;
|
|
937
|
-
setSubmitting(true);
|
|
938
|
-
try {
|
|
939
|
-
await onAdd(selected.line, selected.column, trimmed);
|
|
940
|
-
setDraft('');
|
|
941
|
-
} finally {
|
|
942
|
-
setSubmitting(false);
|
|
943
|
-
}
|
|
944
|
-
};
|
|
945
|
-
|
|
946
|
-
return (
|
|
947
|
-
<>
|
|
948
|
-
<div ref={wrapRef} className={cn('rounded-[6px]', showCue && 'comment-cue')}>
|
|
949
|
-
<Textarea
|
|
950
|
-
value={draft}
|
|
951
|
-
onChange={(e) => setDraft(e.target.value)}
|
|
952
|
-
onKeyDown={(e) => {
|
|
953
|
-
if (e.key === 'Enter' && (e.metaKey || e.ctrlKey)) {
|
|
954
|
-
e.preventDefault();
|
|
955
|
-
submit();
|
|
956
|
-
}
|
|
957
|
-
}}
|
|
958
|
-
placeholder={t.inspector.commentPlaceholder}
|
|
959
|
-
className="min-h-16 resize-none text-[12px]"
|
|
960
|
-
/>
|
|
961
|
-
</div>
|
|
962
|
-
<div className="flex items-center justify-between gap-2">
|
|
963
|
-
<span className="font-mono text-[10.5px] text-muted-foreground/70">
|
|
964
|
-
{t.inspector.commentShortcutHint}
|
|
965
|
-
</span>
|
|
966
|
-
<Button size="sm" variant="brand" disabled={submitting || !draft.trim()} onClick={submit}>
|
|
967
|
-
{t.inspector.addComment}
|
|
968
|
-
</Button>
|
|
969
|
-
</div>
|
|
970
|
-
</>
|
|
971
|
-
);
|
|
972
|
-
}
|
|
973
|
-
|
|
974
891
|
function readSnapshot(el: HTMLElement): ElementSnapshot {
|
|
975
892
|
const cs = getComputedStyle(el);
|
|
976
893
|
const text =
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Eye, PanelRight, Pencil } from 'lucide-react';
|
|
1
|
+
import { Eye, MessageSquare, PanelRight, Pencil } from 'lucide-react';
|
|
2
2
|
import {
|
|
3
3
|
createContext,
|
|
4
4
|
type ReactNode,
|
|
@@ -12,20 +12,22 @@ import {
|
|
|
12
12
|
import { toast } from 'sonner';
|
|
13
13
|
import { useHistory } from '@/components/history-provider';
|
|
14
14
|
import { IconSwitcherIndicator } from '@/components/icon-switcher-indicator';
|
|
15
|
+
import { IconTooltip } from '@/components/icon-tooltip';
|
|
15
16
|
import { Button } from '@/components/ui/button';
|
|
16
17
|
import { ToggleGroup, ToggleGroupItem } from '@/components/ui/toggle-group';
|
|
18
|
+
import { TooltipTrigger } from '@/components/ui/tooltip';
|
|
17
19
|
import { findSlideSource } from '@/lib/inspector/fiber';
|
|
18
20
|
import {
|
|
19
21
|
appendTextEdit,
|
|
20
22
|
type TextEditOp,
|
|
21
23
|
type TextEditStep,
|
|
22
24
|
} from '@/lib/inspector/text-edit-timeline';
|
|
23
|
-
import { type SlideComment, useComments } from '@/lib/inspector/use-comments';
|
|
25
|
+
import { type AddCommentInput, type SlideComment, useComments } from '@/lib/inspector/use-comments';
|
|
24
26
|
import { type Edit, type EditOp, useEditor } from '@/lib/inspector/use-editor';
|
|
25
27
|
import { useVisualEditor, type VisualEdit } from '@/lib/inspector/use-visual-editor';
|
|
26
28
|
import { isShortcutControlTarget, isTypingTarget } from '@/lib/keys';
|
|
27
29
|
import { textDiff } from '@/lib/text-diff';
|
|
28
|
-
import { useLocale } from '@/lib/use-locale';
|
|
30
|
+
import { format, plural, useLocale } from '@/lib/use-locale';
|
|
29
31
|
import { round2 } from '@/lib/utils';
|
|
30
32
|
import { AssetPickerDialog } from './asset-picker-dialog';
|
|
31
33
|
import { ImageCropDialog, type ImageCropRect } from './image-crop-dialog';
|
|
@@ -367,9 +369,17 @@ function replayDomTextEdits(el: HTMLElement, snapshot: TextDomSnapshot, steps: T
|
|
|
367
369
|
if (el.innerHTML !== next) el.innerHTML = next;
|
|
368
370
|
}
|
|
369
371
|
|
|
372
|
+
export type InspectorMode = 'preview' | 'edit' | 'comment';
|
|
373
|
+
|
|
370
374
|
type InspectorCtx = {
|
|
371
375
|
slideId: string;
|
|
376
|
+
pageIndex: number;
|
|
377
|
+
mode: InspectorMode;
|
|
378
|
+
setMode: (mode: InspectorMode) => void;
|
|
379
|
+
// True while the visual editor owns the canvas (`mode === 'edit'`).
|
|
372
380
|
active: boolean;
|
|
381
|
+
commentMode: boolean;
|
|
382
|
+
exitCommentMode: () => void;
|
|
373
383
|
toggle: () => void;
|
|
374
384
|
panelOpen: boolean;
|
|
375
385
|
panelHidden: boolean;
|
|
@@ -377,7 +387,8 @@ type InspectorCtx = {
|
|
|
377
387
|
cancel: () => void;
|
|
378
388
|
comments: SlideComment[];
|
|
379
389
|
error: string | null;
|
|
380
|
-
add: (
|
|
390
|
+
add: (input: AddCommentInput) => Promise<void>;
|
|
391
|
+
update: (id: string, text: string) => Promise<void>;
|
|
381
392
|
remove: (id: string) => Promise<void>;
|
|
382
393
|
selection: SelectedTarget[];
|
|
383
394
|
setSelection: (targets: SelectedTarget[]) => void;
|
|
@@ -416,6 +427,10 @@ export function useInspector(): InspectorCtx {
|
|
|
416
427
|
return v;
|
|
417
428
|
}
|
|
418
429
|
|
|
430
|
+
export function useOptionalInspector(): InspectorCtx | null {
|
|
431
|
+
return useContext(Ctx);
|
|
432
|
+
}
|
|
433
|
+
|
|
419
434
|
export function InspectorProvider({
|
|
420
435
|
slideId,
|
|
421
436
|
pageIndex,
|
|
@@ -429,7 +444,11 @@ export function InspectorProvider({
|
|
|
429
444
|
onPanelOpen?: () => void;
|
|
430
445
|
children: ReactNode;
|
|
431
446
|
}) {
|
|
432
|
-
const [
|
|
447
|
+
const [mode, setModeState] = useState<InspectorMode>(import.meta.env.DEV ? 'edit' : 'preview');
|
|
448
|
+
const active = mode === 'edit';
|
|
449
|
+
const commentMode = mode === 'comment';
|
|
450
|
+
// Where Esc / toggling the comment tool off returns the user to.
|
|
451
|
+
const modeBeforeCommentRef = useRef<Exclude<InspectorMode, 'comment'>>('preview');
|
|
433
452
|
const [panelOpen, setPanelOpen] = useState(
|
|
434
453
|
() => typeof window !== 'undefined' && window.innerWidth >= 1024,
|
|
435
454
|
);
|
|
@@ -475,7 +494,7 @@ export function InspectorProvider({
|
|
|
475
494
|
[],
|
|
476
495
|
);
|
|
477
496
|
const [opsVersion, setOpsVersion] = useState(0);
|
|
478
|
-
const { comments, error, add, remove } = useComments(slideId);
|
|
497
|
+
const { comments, error, add, update, remove } = useComments(slideId);
|
|
479
498
|
const { applyEdit, applyEdits } = useEditor(slideId);
|
|
480
499
|
const history = useHistory();
|
|
481
500
|
|
|
@@ -1252,19 +1271,32 @@ export function InspectorProvider({
|
|
|
1252
1271
|
return () => observer.disconnect();
|
|
1253
1272
|
}, [selection, setSelection, slideId]);
|
|
1254
1273
|
|
|
1274
|
+
const setMode = useCallback(
|
|
1275
|
+
(next: InspectorMode) => {
|
|
1276
|
+
if (next === mode) return;
|
|
1277
|
+
if (next === 'comment' && mode !== 'comment') modeBeforeCommentRef.current = mode;
|
|
1278
|
+
if (mode === 'edit') {
|
|
1279
|
+
setSelected(null);
|
|
1280
|
+
setInlineEdit(null);
|
|
1281
|
+
}
|
|
1282
|
+
setModeState(next);
|
|
1283
|
+
},
|
|
1284
|
+
[mode, setSelected],
|
|
1285
|
+
);
|
|
1286
|
+
|
|
1255
1287
|
const toggle = useCallback(() => {
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
}, [
|
|
1288
|
+
setMode(active ? 'preview' : 'edit');
|
|
1289
|
+
}, [active, setMode]);
|
|
1290
|
+
|
|
1291
|
+
const exitCommentMode = useCallback(() => {
|
|
1292
|
+
if (commentMode) setMode(modeBeforeCommentRef.current);
|
|
1293
|
+
}, [commentMode, setMode]);
|
|
1262
1294
|
|
|
1263
1295
|
const togglePanel = useCallback(() => {
|
|
1264
1296
|
setPanelOpen(!active || panelHidden || !panelOpen);
|
|
1265
|
-
|
|
1297
|
+
setMode('edit');
|
|
1266
1298
|
onPanelOpen?.();
|
|
1267
|
-
}, [active, panelHidden, panelOpen, onPanelOpen]);
|
|
1299
|
+
}, [active, panelHidden, panelOpen, onPanelOpen, setMode]);
|
|
1268
1300
|
|
|
1269
1301
|
const cancel = useCallback(() => {
|
|
1270
1302
|
setSelected(null);
|
|
@@ -1320,13 +1352,24 @@ export function InspectorProvider({
|
|
|
1320
1352
|
e.altKey
|
|
1321
1353
|
)
|
|
1322
1354
|
return;
|
|
1323
|
-
if (e.key
|
|
1324
|
-
|
|
1325
|
-
|
|
1355
|
+
if (e.key === 'i' || e.key === 'I') {
|
|
1356
|
+
e.preventDefault();
|
|
1357
|
+
togglePanel();
|
|
1358
|
+
} else if (e.key === 'c' || e.key === 'C') {
|
|
1359
|
+
e.preventDefault();
|
|
1360
|
+
if (commentMode) exitCommentMode();
|
|
1361
|
+
else setMode('comment');
|
|
1362
|
+
} else if (e.key === 'v' || e.key === 'V') {
|
|
1363
|
+
e.preventDefault();
|
|
1364
|
+
setMode('preview');
|
|
1365
|
+
} else if (e.key === 'e' || e.key === 'E') {
|
|
1366
|
+
e.preventDefault();
|
|
1367
|
+
setMode('edit');
|
|
1368
|
+
}
|
|
1326
1369
|
};
|
|
1327
1370
|
window.addEventListener('keydown', onKey);
|
|
1328
1371
|
return () => window.removeEventListener('keydown', onKey);
|
|
1329
|
-
}, [togglePanel]);
|
|
1372
|
+
}, [togglePanel, commentMode, exitCommentMode, setMode]);
|
|
1330
1373
|
|
|
1331
1374
|
const openCrop = useCallback((anchor: HTMLImageElement) => {
|
|
1332
1375
|
const loc = anchor.dataset.slideLoc;
|
|
@@ -1352,7 +1395,12 @@ export function InspectorProvider({
|
|
|
1352
1395
|
const value = useMemo<InspectorCtx>(
|
|
1353
1396
|
() => ({
|
|
1354
1397
|
slideId,
|
|
1398
|
+
pageIndex,
|
|
1399
|
+
mode,
|
|
1400
|
+
setMode,
|
|
1355
1401
|
active,
|
|
1402
|
+
commentMode,
|
|
1403
|
+
exitCommentMode,
|
|
1356
1404
|
toggle,
|
|
1357
1405
|
panelOpen,
|
|
1358
1406
|
panelHidden,
|
|
@@ -1361,6 +1409,7 @@ export function InspectorProvider({
|
|
|
1361
1409
|
comments,
|
|
1362
1410
|
error,
|
|
1363
1411
|
add,
|
|
1412
|
+
update,
|
|
1364
1413
|
remove,
|
|
1365
1414
|
selection,
|
|
1366
1415
|
setSelection,
|
|
@@ -1387,7 +1436,12 @@ export function InspectorProvider({
|
|
|
1387
1436
|
}),
|
|
1388
1437
|
[
|
|
1389
1438
|
slideId,
|
|
1439
|
+
pageIndex,
|
|
1440
|
+
mode,
|
|
1441
|
+
setMode,
|
|
1390
1442
|
active,
|
|
1443
|
+
commentMode,
|
|
1444
|
+
exitCommentMode,
|
|
1391
1445
|
toggle,
|
|
1392
1446
|
panelOpen,
|
|
1393
1447
|
panelHidden,
|
|
@@ -1396,6 +1450,7 @@ export function InspectorProvider({
|
|
|
1396
1450
|
comments,
|
|
1397
1451
|
error,
|
|
1398
1452
|
add,
|
|
1453
|
+
update,
|
|
1399
1454
|
remove,
|
|
1400
1455
|
selection,
|
|
1401
1456
|
setSelection,
|
|
@@ -1552,44 +1607,63 @@ function parsePercent(s: string, fallback: number): number {
|
|
|
1552
1607
|
|
|
1553
1608
|
export function InspectModeSwitcher() {
|
|
1554
1609
|
const t = useLocale();
|
|
1555
|
-
const {
|
|
1610
|
+
const { mode, setMode, comments } = useInspector();
|
|
1556
1611
|
if (import.meta.env.PROD) return null;
|
|
1612
|
+
const items: { value: InspectorMode; label: string; shortcut: string; icon: ReactNode }[] = [
|
|
1613
|
+
{ value: 'preview', label: t.inspector.previewMode, shortcut: 'V', icon: <Eye /> },
|
|
1614
|
+
{ value: 'edit', label: t.inspector.editMode, shortcut: 'E', icon: <Pencil /> },
|
|
1615
|
+
{ value: 'comment', label: t.inspector.commentMode, shortcut: 'C', icon: <MessageSquare /> },
|
|
1616
|
+
];
|
|
1617
|
+
const index = Math.max(
|
|
1618
|
+
0,
|
|
1619
|
+
items.findIndex((item) => item.value === mode),
|
|
1620
|
+
);
|
|
1621
|
+
const pending = comments.length;
|
|
1622
|
+
const accessibleName = (item: (typeof items)[number]) =>
|
|
1623
|
+
item.value === 'comment' && pending > 0
|
|
1624
|
+
? `${item.label} · ${format(plural(pending, t.inspector.commentsCount), { count: pending })}`
|
|
1625
|
+
: item.label;
|
|
1557
1626
|
return (
|
|
1558
1627
|
<ToggleGroup
|
|
1559
1628
|
size="sm"
|
|
1560
1629
|
spacing={1}
|
|
1561
|
-
value={[
|
|
1630
|
+
value={[mode]}
|
|
1562
1631
|
onValueChange={(value) => {
|
|
1563
|
-
const next = value[0];
|
|
1564
|
-
if (next &&
|
|
1632
|
+
const next = value[0] as InspectorMode | undefined;
|
|
1633
|
+
if (next && next !== mode) setMode(next);
|
|
1565
1634
|
}}
|
|
1566
|
-
aria-label={`${t.inspector.previewMode} / ${t.inspector.editMode}`}
|
|
1635
|
+
aria-label={`${t.inspector.previewMode} / ${t.inspector.editMode} / ${t.inspector.commentMode}`}
|
|
1567
1636
|
data-inspector-ui
|
|
1568
1637
|
className="relative isolate h-8 gap-0 rounded-lg border border-border/70 bg-muted/70 p-0.5"
|
|
1569
1638
|
>
|
|
1570
|
-
<IconSwitcherIndicator index={
|
|
1571
|
-
|
|
1572
|
-
value=
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1639
|
+
<IconSwitcherIndicator index={index} />
|
|
1640
|
+
{items.map((item) => (
|
|
1641
|
+
<IconTooltip key={item.value} label={item.label} shortcut={item.shortcut}>
|
|
1642
|
+
<TooltipTrigger
|
|
1643
|
+
render={
|
|
1644
|
+
<ToggleGroupItem
|
|
1645
|
+
value={item.value}
|
|
1646
|
+
aria-label={accessibleName(item)}
|
|
1647
|
+
data-inspector-mode={item.value}
|
|
1648
|
+
onClick={(event) => {
|
|
1649
|
+
if (event.detail > 0) event.currentTarget.blur();
|
|
1650
|
+
}}
|
|
1651
|
+
className="relative z-10 h-full w-8 rounded-md px-0 text-muted-foreground hover:bg-transparent data-pressed:bg-transparent data-pressed:text-foreground data-pressed:shadow-none"
|
|
1652
|
+
/>
|
|
1653
|
+
}
|
|
1654
|
+
>
|
|
1655
|
+
{item.icon}
|
|
1656
|
+
{item.value === 'comment' && pending > 0 && (
|
|
1657
|
+
<span
|
|
1658
|
+
aria-hidden
|
|
1659
|
+
className="pointer-events-none absolute -top-1.5 -right-1.5 flex h-3.5 min-w-3.5 items-center justify-center rounded-full bg-brand px-1 font-mono text-[9px] font-semibold leading-none text-brand-foreground nums"
|
|
1660
|
+
>
|
|
1661
|
+
{pending > 99 ? '99+' : pending}
|
|
1662
|
+
</span>
|
|
1663
|
+
)}
|
|
1664
|
+
</TooltipTrigger>
|
|
1665
|
+
</IconTooltip>
|
|
1666
|
+
))}
|
|
1593
1667
|
</ToggleGroup>
|
|
1594
1668
|
);
|
|
1595
1669
|
}
|
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
Trash2,
|
|
27
27
|
} from 'lucide-react';
|
|
28
28
|
import { Fragment, useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
|
|
29
|
+
import { useOptionalInspector } from '@/components/inspector/inspector-provider';
|
|
29
30
|
import { Button } from '@/components/ui/button';
|
|
30
31
|
import {
|
|
31
32
|
ContextMenu,
|
|
@@ -36,7 +37,7 @@ import {
|
|
|
36
37
|
} from '@/components/ui/context-menu';
|
|
37
38
|
import { ScrollArea } from '@/components/ui/scroll-area';
|
|
38
39
|
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip';
|
|
39
|
-
import { format, useLocale } from '@/lib/use-locale';
|
|
40
|
+
import { format, plural, useLocale } from '@/lib/use-locale';
|
|
40
41
|
import { cn, pad2 } from '@/lib/utils';
|
|
41
42
|
import type { DesignSystem } from '../lib/design';
|
|
42
43
|
import { SlidePageProvider } from '../lib/page-context';
|
|
@@ -74,6 +75,36 @@ type Props = {
|
|
|
74
75
|
onOverview?: () => void;
|
|
75
76
|
};
|
|
76
77
|
|
|
78
|
+
// Per-page pending comment counts, shown on the rail only while the
|
|
79
|
+
// comment tool is active.
|
|
80
|
+
function usePageCommentCounts(): Map<number, number> | null {
|
|
81
|
+
const inspector = useOptionalInspector();
|
|
82
|
+
if (!inspector?.commentMode) return null;
|
|
83
|
+
const counts = new Map<number, number>();
|
|
84
|
+
for (const comment of inspector.comments) {
|
|
85
|
+
if (comment.page === undefined) continue;
|
|
86
|
+
counts.set(comment.page, (counts.get(comment.page) ?? 0) + 1);
|
|
87
|
+
}
|
|
88
|
+
return counts;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function CommentCountBadge({ count, className }: { count: number; className?: string }) {
|
|
92
|
+
const t = useLocale();
|
|
93
|
+
return (
|
|
94
|
+
<span
|
|
95
|
+
role="img"
|
|
96
|
+
aria-label={format(plural(count, t.inspector.commentsCount), { count })}
|
|
97
|
+
data-page-comments={count}
|
|
98
|
+
className={cn(
|
|
99
|
+
'flex h-4 min-w-4 items-center justify-center rounded-full bg-brand px-1 font-mono text-[9.5px] font-semibold leading-none text-brand-foreground tabular-nums',
|
|
100
|
+
className,
|
|
101
|
+
)}
|
|
102
|
+
>
|
|
103
|
+
{count}
|
|
104
|
+
</span>
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
|
|
77
108
|
const DEFAULT_VERTICAL_THUMB_WIDTH = 184;
|
|
78
109
|
const VERTICAL_RAIL_CHROME = 80;
|
|
79
110
|
const MIN_VERTICAL_THUMB_WIDTH = 120;
|
|
@@ -522,10 +553,12 @@ function HorizontalVirtualThumbList({
|
|
|
522
553
|
}, [current, itemWidth, pages.length, thumbWidth]);
|
|
523
554
|
|
|
524
555
|
const visibleRange = clampVisibleRange(range, current, pages.length);
|
|
556
|
+
const commentCounts = usePageCommentCounts();
|
|
525
557
|
const visible = [];
|
|
526
558
|
for (let i = visibleRange.start; i < visibleRange.end; i++) {
|
|
527
559
|
const PageComp = pages[i];
|
|
528
560
|
const active = i === current;
|
|
561
|
+
const commentCount = commentCounts?.get(i) ?? 0;
|
|
529
562
|
const button = (
|
|
530
563
|
<button
|
|
531
564
|
type="button"
|
|
@@ -562,6 +595,9 @@ function HorizontalVirtualThumbList({
|
|
|
562
595
|
</SlidePageProvider>
|
|
563
596
|
</SlideCanvas>
|
|
564
597
|
</div>
|
|
598
|
+
{commentCount > 0 && (
|
|
599
|
+
<CommentCountBadge count={commentCount} className="absolute -top-0.5 -right-1" />
|
|
600
|
+
)}
|
|
565
601
|
</button>
|
|
566
602
|
);
|
|
567
603
|
|
|
@@ -798,6 +834,7 @@ function ThumbContents({
|
|
|
798
834
|
}, [PageComp]);
|
|
799
835
|
|
|
800
836
|
const hasTransition = Boolean(PageComp.transition ?? moduleTransition);
|
|
837
|
+
const commentCount = usePageCommentCounts()?.get(index) ?? 0;
|
|
801
838
|
|
|
802
839
|
return (
|
|
803
840
|
<>
|
|
@@ -810,6 +847,7 @@ function ThumbContents({
|
|
|
810
847
|
>
|
|
811
848
|
{pad2(index + 1)}
|
|
812
849
|
</span>
|
|
850
|
+
{commentCount > 0 && <CommentCountBadge count={commentCount} />}
|
|
813
851
|
{(hasTransition || hasSteps) && (
|
|
814
852
|
<div className="flex flex-col items-end gap-0.5">
|
|
815
853
|
{hasTransition && (
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
export type FreezeMode = 'edit' | 'comment';
|
|
4
|
+
|
|
5
|
+
// Pauses slide animations and transitions while an overlay measures and
|
|
6
|
+
// hit-tests the canvas, so element rects stay put under the pointer.
|
|
7
|
+
export function useFreezeSlideMotion(mode: FreezeMode | null): void {
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
if (!mode) return;
|
|
10
|
+
const root = document.querySelector<HTMLElement>('[data-inspector-root]');
|
|
11
|
+
if (!root) return;
|
|
12
|
+
const style = document.createElement('style');
|
|
13
|
+
style.textContent = FREEZE_CSS;
|
|
14
|
+
document.head.appendChild(style);
|
|
15
|
+
root.dataset.inspectorEditing = mode;
|
|
16
|
+
return () => {
|
|
17
|
+
style.remove();
|
|
18
|
+
delete root.dataset.inspectorEditing;
|
|
19
|
+
};
|
|
20
|
+
}, [mode]);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// A speech-bubble pin with its tip at the bottom-left corner; the hotspot
|
|
24
|
+
// sits on that tip so the pointer "stamps" where the comment will land.
|
|
25
|
+
const COMMENT_CURSOR_SVG = [
|
|
26
|
+
"<svg xmlns='http://www.w3.org/2000/svg' width='24' height='24' viewBox='0 0 24 24'>",
|
|
27
|
+
"<path d='M12 3a9 9 0 0 1 9 9a9 9 0 0 1-9 9H5a2 2 0 0 1-2-2v-7a9 9 0 0 1 9-9z' ",
|
|
28
|
+
"fill='#fff' stroke='#111' stroke-width='1.5' stroke-linejoin='round'/></svg>",
|
|
29
|
+
].join('');
|
|
30
|
+
const COMMENT_CURSOR = `url("data:image/svg+xml;utf8,${encodeURIComponent(COMMENT_CURSOR_SVG)}") 3 21, crosshair`;
|
|
31
|
+
|
|
32
|
+
const FREEZE_CSS = `
|
|
33
|
+
[data-inspector-editing] { touch-action: none; }
|
|
34
|
+
[data-inspector-editing] *:not([data-inspector-ui], [data-inspector-ui] *),
|
|
35
|
+
[data-inspector-editing] *:not([data-inspector-ui], [data-inspector-ui] *)::before,
|
|
36
|
+
[data-inspector-editing] *:not([data-inspector-ui], [data-inspector-ui] *)::after {
|
|
37
|
+
animation-duration: 1ms !important;
|
|
38
|
+
animation-delay: 0s !important;
|
|
39
|
+
animation-iteration-count: 1 !important;
|
|
40
|
+
animation-fill-mode: forwards !important;
|
|
41
|
+
transition: none !important;
|
|
42
|
+
view-transition-name: none !important;
|
|
43
|
+
user-select: none;
|
|
44
|
+
}
|
|
45
|
+
[data-inspector-editing] *:not([data-inspector-ui], [data-inspector-ui] *, [data-visual-gesture], [data-visual-gesture] *),
|
|
46
|
+
[data-inspector-editing] *:not([data-inspector-ui], [data-inspector-ui] *, [data-visual-gesture], [data-visual-gesture] *)::before,
|
|
47
|
+
[data-inspector-editing] *:not([data-inspector-ui], [data-inspector-ui] *, [data-visual-gesture], [data-visual-gesture] *)::after {
|
|
48
|
+
cursor: default !important;
|
|
49
|
+
}
|
|
50
|
+
[data-inspector-editing] [data-visual-gesture],
|
|
51
|
+
[data-inspector-editing] [data-visual-gesture] *,
|
|
52
|
+
[data-inspector-editing] [data-visual-gesture] *::before,
|
|
53
|
+
[data-inspector-editing] [data-visual-gesture] *::after {
|
|
54
|
+
cursor: var(--osd-gesture-cursor, default) !important;
|
|
55
|
+
}
|
|
56
|
+
[data-inspector-editing="comment"] *:not([data-inspector-ui], [data-inspector-ui] *),
|
|
57
|
+
[data-inspector-editing="comment"] *:not([data-inspector-ui], [data-inspector-ui] *)::before,
|
|
58
|
+
[data-inspector-editing="comment"] *:not([data-inspector-ui], [data-inspector-ui] *)::after {
|
|
59
|
+
cursor: ${COMMENT_CURSOR} !important;
|
|
60
|
+
}
|
|
61
|
+
`;
|