@open-slide/core 1.17.1 → 1.19.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 (37) hide show
  1. package/dist/{build-DaL4Gjn-.js → build-CaV_vhIw.js} +1 -1
  2. package/dist/cli/bin.js +3 -3
  3. package/dist/{config-DIvIP8vY.d.ts → config-CDHB8Oow.d.ts} +2 -1
  4. package/dist/{config-CCHio3pk.js → config-GA6NMgs_.js} +1 -0
  5. package/dist/{dev-DLRQoCkT.js → dev-D57ui2yV.js} +1 -1
  6. package/dist/{format-CxmsgcBh.js → format-74A3B6zu.js} +120 -4
  7. package/dist/index.d.ts +7 -7
  8. package/dist/index.js +1 -1
  9. package/dist/locale/index.d.ts +1 -1
  10. package/dist/locale/index.js +1 -1
  11. package/dist/{preview-D3qVGc0S.js → preview-D40Zw_o0.js} +1 -1
  12. package/dist/{types-Di7nvL8V.d.ts → types-8HghULIe.d.ts} +32 -0
  13. package/dist/vite/index.d.ts +2 -2
  14. package/dist/vite/index.js +1 -1
  15. package/package.json +6 -3
  16. package/src/app/components/command/command-menu.tsx +227 -0
  17. package/src/app/components/command/command.tsx +142 -0
  18. package/src/app/components/command/home-command-menu.tsx +96 -0
  19. package/src/app/components/command/slide-command-menu.tsx +171 -0
  20. package/src/app/components/icon-tooltip.tsx +34 -0
  21. package/src/app/components/language-toggle.tsx +15 -8
  22. package/src/app/components/player.tsx +8 -1
  23. package/src/app/components/present/use-presenter-channel.ts +2 -1
  24. package/src/app/components/sidebar/sidebar-footer.tsx +2 -37
  25. package/src/app/components/sidebar/sidebar.tsx +4 -0
  26. package/src/app/components/theme-toggle.tsx +16 -9
  27. package/src/app/lib/export-html.ts +15 -2
  28. package/src/app/lib/use-restart-server.ts +78 -0
  29. package/src/app/lib/use-slide-titles.ts +29 -0
  30. package/src/app/routes/home-shell.tsx +15 -0
  31. package/src/app/routes/presenter.tsx +214 -8
  32. package/src/app/routes/slide.tsx +92 -17
  33. package/src/locale/en.ts +30 -0
  34. package/src/locale/ja.ts +30 -0
  35. package/src/locale/types.ts +33 -0
  36. package/src/locale/zh-cn.ts +30 -0
  37. package/src/locale/zh-tw.ts +30 -0
@@ -96,6 +96,9 @@ async function renderPagesToHtml(pages: NonNullable<SlideModule['default']>): Pr
96
96
  );
97
97
  await nextPaint();
98
98
  await nextPaint();
99
+ for (const video of host.querySelectorAll('video')) {
100
+ video.defaultMuted = video.muted;
101
+ }
99
102
  result.push(host.innerHTML);
100
103
  root.unmount();
101
104
  container.removeChild(host);
@@ -143,7 +146,7 @@ function collectExternalStylesheetLinks(): string {
143
146
 
144
147
  function findHtmlAssetUrls(html: string): string[] {
145
148
  const out: string[] = [];
146
- const attrRe = /\s(?:src|href)="([^"]+)"/g;
149
+ const attrRe = /\s(?:src|href|poster)="([^"]+)"/g;
147
150
  for (const m of html.matchAll(attrRe)) {
148
151
  if (looksLikeAsset(m[1])) out.push(m[1]);
149
152
  }
@@ -282,7 +285,17 @@ html, body { margin: 0; height: 100%; background: #000; overflow: hidden; font-f
282
285
  }
283
286
  function go(i) {
284
287
  idx = Math.max(0, Math.min(pages.length - 1, i));
285
- pages.forEach(function (p, n) { p.hidden = n !== idx; });
288
+ pages.forEach(function (p, n) {
289
+ p.hidden = n !== idx;
290
+ p.querySelectorAll('video').forEach(function (video) {
291
+ if (p.hidden) {
292
+ video.pause();
293
+ try { video.currentTime = 0; } catch {}
294
+ } else if (video.autoplay) {
295
+ video.play().catch(function () {});
296
+ }
297
+ });
298
+ });
286
299
  cur.textContent = String(idx + 1);
287
300
  }
288
301
  window.addEventListener('resize', fit);
@@ -0,0 +1,78 @@
1
+ import { useCallback, useEffect, useSyncExternalStore } from 'react';
2
+ import { toast } from 'sonner';
3
+ import { useLocale } from '@/lib/use-locale';
4
+
5
+ type ServerStatus = { executionId: string; canRestart: boolean };
6
+
7
+ async function fetchServerStatus(): Promise<ServerStatus | null> {
8
+ const res = await fetch('/__server-status');
9
+ if (!res.ok) return null;
10
+ return (await res.json()) as ServerStatus;
11
+ }
12
+
13
+ // Module scope, not per-hook state: the sidebar footer and the command menu can
14
+ // both be mounted, and each firing its own POST plus polling loop would race.
15
+ let state = { canRestart: false, restarting: false };
16
+ let statusProbed = false;
17
+ let inFlight: Promise<boolean> | null = null;
18
+ const listeners = new Set<() => void>();
19
+
20
+ function setState(next: Partial<typeof state>): void {
21
+ state = { ...state, ...next };
22
+ for (const listener of listeners) listener();
23
+ }
24
+
25
+ function subscribe(listener: () => void): () => void {
26
+ listeners.add(listener);
27
+ return () => {
28
+ listeners.delete(listener);
29
+ };
30
+ }
31
+
32
+ function getSnapshot(): typeof state {
33
+ return state;
34
+ }
35
+
36
+ async function performRestart(): Promise<boolean> {
37
+ const before = await fetchServerStatus();
38
+ if (!before) return false;
39
+ const res = await fetch('/__restart-server', { method: 'POST' });
40
+ if (!res.ok) return false;
41
+ // A different executionId means the replacement process is serving.
42
+ for (let attempt = 0; attempt < 30; attempt++) {
43
+ await new Promise((resolve) => setTimeout(resolve, 500));
44
+ const status = await fetchServerStatus().catch(() => null);
45
+ if (status && status.executionId !== before.executionId) {
46
+ window.location.reload();
47
+ return true;
48
+ }
49
+ }
50
+ return false;
51
+ }
52
+
53
+ export function useRestartServer() {
54
+ const t = useLocale();
55
+ const { canRestart, restarting } = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
56
+
57
+ useEffect(() => {
58
+ if (!import.meta.env.DEV || statusProbed) return;
59
+ statusProbed = true;
60
+ fetchServerStatus()
61
+ .then((status) => {
62
+ if (status) setState({ canRestart: status.canRestart });
63
+ })
64
+ .catch(() => {});
65
+ }, []);
66
+
67
+ const restartServer = useCallback(async () => {
68
+ if (inFlight) return;
69
+ inFlight = performRestart().catch(() => false);
70
+ setState({ restarting: true });
71
+ const restarted = await inFlight;
72
+ inFlight = null;
73
+ setState({ restarting: false });
74
+ if (!restarted) toast.error(t.home.restartServerFailed);
75
+ }, [t.home.restartServerFailed]);
76
+
77
+ return { canRestart, restarting, restartServer };
78
+ }
@@ -0,0 +1,29 @@
1
+ import { useEffect, useRef, useState } from 'react';
2
+ import { loadSlide, slideIds } from './slides';
3
+
4
+ /**
5
+ * Resolves every deck's display title once `enabled` first turns true. The home
6
+ * grid only mounts the cards of the selected folder, so cross-folder search
7
+ * needs its own pass over the slide modules — kept lazy since it imports them all.
8
+ */
9
+ export function useSlideTitles(enabled: boolean): Record<string, string> {
10
+ const [titles, setTitles] = useState<Record<string, string>>({});
11
+ const startedRef = useRef(false);
12
+
13
+ useEffect(() => {
14
+ if (!enabled || startedRef.current) return;
15
+ startedRef.current = true;
16
+ void Promise.all(
17
+ slideIds.map(async (id): Promise<[string, string]> => {
18
+ try {
19
+ const mod = await loadSlide(id);
20
+ return [id, mod.meta?.title ?? id];
21
+ } catch {
22
+ return [id, id];
23
+ }
24
+ }),
25
+ ).then((entries) => setTitles(Object.fromEntries(entries)));
26
+ }, [enabled]);
27
+
28
+ return titles;
29
+ }
@@ -14,6 +14,8 @@ import { useAssets } from '@/lib/assets';
14
14
  import { useFolders } from '@/lib/folders';
15
15
  import { format, useLocale } from '@/lib/use-locale';
16
16
  import { cn } from '@/lib/utils';
17
+ import { CommandMenuTrigger } from '../components/command/command-menu';
18
+ import { HomeCommandMenu } from '../components/command/home-command-menu';
17
19
  import { FolderIconChip } from '../components/sidebar/folder-item';
18
20
  import { ALL_SLIDES_ID, ASSETS_ID, Sidebar, THEMES_ID } from '../components/sidebar/sidebar';
19
21
  import type { FoldersManifest } from '../lib/sdk';
@@ -62,6 +64,9 @@ export function HomeShell() {
62
64
 
63
65
  const selectedId = pathToSelectedId(location.pathname, searchParams);
64
66
 
67
+ const [commandOpen, setCommandOpen] = useState(false);
68
+ const openCommandMenu = useCallback(() => setCommandOpen(true), []);
69
+
65
70
  const [titleMap, setTitleMap] = useState<Record<string, string>>({});
66
71
  const reportTitle = useCallback((slideId: string, slideTitle: string) => {
67
72
  setTitleMap((prev) =>
@@ -158,6 +163,7 @@ export function HomeShell() {
158
163
  toast.error(t.home.toastFolderDeleteFailed);
159
164
  }
160
165
  }}
166
+ onOpenCommandMenu={openCommandMenu}
161
167
  onDropToFolder={(folderId, slideId) => moveSlideWithToast(slideId, folderId)}
162
168
  onDropToDraft={(slideId) => moveSlideWithToast(slideId, null)}
163
169
  onReorder={async (ids) => {
@@ -174,6 +180,7 @@ export function HomeShell() {
174
180
  <div className="flex items-center justify-between border-b border-hairline bg-sidebar px-4 py-3 md:hidden">
175
181
  <h1 className="font-heading text-lg font-bold tracking-tight">{t.home.appTitle}</h1>
176
182
  <div className="-mr-1.5 flex items-center gap-0.5">
183
+ <CommandMenuTrigger onClick={openCommandMenu} />
177
184
  <LanguageToggle />
178
185
  <ThemeToggle />
179
186
  <DropdownMenu>
@@ -234,6 +241,14 @@ export function HomeShell() {
234
241
  <Outlet context={ctx} />
235
242
  </div>
236
243
  </div>
244
+
245
+ <HomeCommandMenu
246
+ open={commandOpen}
247
+ onOpenChange={setCommandOpen}
248
+ folders={manifest.folders}
249
+ titleMap={titleMap}
250
+ onSelectView={selectFolder}
251
+ />
237
252
  </div>
238
253
  );
239
254
  }
@@ -1,15 +1,25 @@
1
1
  import {
2
2
  AArrowDown,
3
3
  AArrowUp,
4
+ Check,
5
+ ChevronDown,
4
6
  ChevronLeft,
5
7
  ChevronRight,
6
8
  RotateCcw,
7
9
  Square,
8
10
  Sun,
9
11
  } from 'lucide-react';
10
- import { type ReactNode, useCallback, useEffect, useRef, useState } from 'react';
11
- import { useParams } from 'react-router-dom';
12
+ import {
13
+ type KeyboardEvent as ReactKeyboardEvent,
14
+ type ReactNode,
15
+ useCallback,
16
+ useEffect,
17
+ useRef,
18
+ useState,
19
+ } from 'react';
20
+ import { useNavigate, useParams } from 'react-router-dom';
12
21
  import { Button } from '@/components/ui/button';
22
+ import { Dialog, DialogContent, DialogTitle, DialogTrigger } from '@/components/ui/dialog';
13
23
  import { format, useLocale } from '@/lib/use-locale';
14
24
  import { cn } from '@/lib/utils';
15
25
  import {
@@ -19,7 +29,8 @@ import {
19
29
  import { SlideCanvas } from '../components/slide-canvas';
20
30
  import { isDeckWarmed, markDeckWarmed, SlidePreloadLayer } from '../components/slide-preload-layer';
21
31
  import { SlidePageProvider } from '../lib/page-context';
22
- import { CANVAS_HEIGHT, CANVAS_WIDTH } from '../lib/sdk';
32
+ import { CANVAS_HEIGHT, CANVAS_WIDTH, type SlideModule } from '../lib/sdk';
33
+ import { loadSlide, slideIds } from '../lib/slides';
23
34
  import { type StepController, StepHost } from '../lib/step-context';
24
35
  import { useSlideModule } from '../lib/use-slide-module';
25
36
 
@@ -50,7 +61,19 @@ export function Presenter() {
50
61
  }
51
62
  });
52
63
 
64
+ // A deck switch reuses this route instance, so the handshake state from
65
+ // the previous deck must be dropped before rejoining on the new channel.
66
+ // Render-phase reset so the new deck never renders with the old state.
67
+ const prevSlideIdRef = useRef(slideId);
68
+ if (prevSlideIdRef.current !== slideId) {
69
+ prevSlideIdRef.current = slideId;
70
+ setState(null);
71
+ setHasProjection(false);
72
+ requestedRef.current = false;
73
+ }
74
+
53
75
  // Hydrate from the projection window once.
76
+ // biome-ignore lint/correctness/useExhaustiveDependencies: slideId re-fires the handshake on a deck switch even when the channel memo keeps its identity (available toggling false→true in one commit nets to no change)
54
77
  useEffect(() => {
55
78
  if (!channel.available || requestedRef.current) return;
56
79
  requestedRef.current = true;
@@ -58,9 +81,18 @@ export function Presenter() {
58
81
  // If nothing answers within a beat, surface the "no projection" hint.
59
82
  const t = setTimeout(() => setHasProjection((v) => v), 600);
60
83
  return () => clearTimeout(t);
61
- }, [channel]);
84
+ }, [channel, slideId]);
62
85
 
86
+ const navigate = useNavigate();
63
87
  const send = channel.send;
88
+ const switchDeck = useCallback(
89
+ (id: string) => {
90
+ if (id === slideId) return;
91
+ send({ type: 'switch-slide', slideId: id });
92
+ navigate(`/s/${encodeURIComponent(id)}/presenter`, { replace: true });
93
+ },
94
+ [slideId, send, navigate],
95
+ );
64
96
  const goPrev = useCallback(() => send({ type: 'prev' }), [send]);
65
97
  const goNext = useCallback(() => send({ type: 'next' }), [send]);
66
98
  const goTo = useCallback((i: number) => send({ type: 'goto', index: i }), [send]);
@@ -71,6 +103,8 @@ export function Presenter() {
71
103
  // presenter can drive without the mouse.
72
104
  useEffect(() => {
73
105
  const onKey = (e: KeyboardEvent) => {
106
+ // The deck-switcher menu owns its own arrow-key navigation.
107
+ if (e.defaultPrevented) return;
74
108
  if (e.target instanceof HTMLElement && e.target.matches('input, textarea')) return;
75
109
  if (e.altKey || e.ctrlKey || e.metaKey) return;
76
110
  if (
@@ -175,8 +209,10 @@ export function Presenter() {
175
209
  index={index}
176
210
  total={total}
177
211
  startedAt={startedAt}
212
+ slideId={slideId}
178
213
  slideTitle={slide.meta?.title ?? slideId}
179
214
  connected={hasProjection}
215
+ onSwitchDeck={switchDeck}
180
216
  />
181
217
 
182
218
  <div className="grid min-h-0 flex-1 grid-cols-1 gap-6 px-6 pb-4 lg:grid-cols-[2fr_1fr]">
@@ -252,23 +288,31 @@ function PresenterTopBar({
252
288
  index,
253
289
  total,
254
290
  startedAt,
291
+ slideId,
255
292
  slideTitle,
256
293
  connected,
294
+ onSwitchDeck,
257
295
  }: {
258
296
  index: number;
259
297
  total: number;
260
298
  startedAt: number;
299
+ slideId: string;
261
300
  slideTitle: string;
262
301
  connected: boolean;
302
+ onSwitchDeck: (slideId: string) => void;
263
303
  }) {
264
304
  const t = useLocale();
265
305
  return (
266
306
  <header className="flex h-12 shrink-0 items-center justify-between border-b border-hairline px-6">
267
- <div className="flex items-baseline gap-3">
307
+ <div className="flex min-w-0 items-center gap-3">
268
308
  <span className="eyebrow text-white/45">{t.presenter.eyebrow}</span>
269
- <span className="truncate font-heading text-[14px] font-semibold tracking-tight">
270
- {slideTitle}
271
- </span>
309
+ {slideIds.length > 1 ? (
310
+ <DeckSwitcher slideId={slideId} slideTitle={slideTitle} onSwitchDeck={onSwitchDeck} />
311
+ ) : (
312
+ <span className="truncate font-heading text-[14px] font-semibold tracking-tight">
313
+ {slideTitle}
314
+ </span>
315
+ )}
272
316
  {!connected && (
273
317
  <span className="rounded-[3px] border border-amber-300/30 bg-amber-300/10 px-1.5 py-0.5 font-mono text-[10px] tracking-[0.06em] uppercase text-amber-200/85">
274
318
  {t.presenter.notLinked}
@@ -288,6 +332,168 @@ function PresenterTopBar({
288
332
  );
289
333
  }
290
334
 
335
+ // Listing decks means importing every deck's chunk for its meta and pages.
336
+ // That warms the module cache for switches; assets only load on render, so
337
+ // this stays cheap.
338
+ function useDeckModules(): Record<string, SlideModule> {
339
+ const [modules, setModules] = useState<Record<string, SlideModule>>({});
340
+ useEffect(() => {
341
+ let cancelled = false;
342
+ for (const id of slideIds) {
343
+ loadSlide(id)
344
+ .then((mod) => {
345
+ if (cancelled) return;
346
+ setModules((cur) => (cur[id] === mod ? cur : { ...cur, [id]: mod }));
347
+ })
348
+ .catch(() => {});
349
+ }
350
+ return () => {
351
+ cancelled = true;
352
+ };
353
+ }, []);
354
+ return modules;
355
+ }
356
+
357
+ function DeckSwitcher({
358
+ slideId,
359
+ slideTitle,
360
+ onSwitchDeck,
361
+ }: {
362
+ slideId: string;
363
+ slideTitle: string;
364
+ onSwitchDeck: (slideId: string) => void;
365
+ }) {
366
+ const t = useLocale();
367
+ const modules = useDeckModules();
368
+ const [open, setOpen] = useState(false);
369
+ const [query, setQuery] = useState('');
370
+ const [activeIndex, setActiveIndex] = useState(0);
371
+ const listRef = useRef<HTMLDivElement | null>(null);
372
+
373
+ const trimmed = query.trim().toLowerCase();
374
+ const filtered = slideIds.filter((id) => {
375
+ if (!trimmed) return true;
376
+ const title = modules[id]?.meta?.title;
377
+ return id.toLowerCase().includes(trimmed) || title?.toLowerCase().includes(trimmed);
378
+ });
379
+ const active = Math.min(activeIndex, Math.max(0, filtered.length - 1));
380
+
381
+ const handleOpenChange = (next: boolean) => {
382
+ setOpen(next);
383
+ if (next) {
384
+ setQuery('');
385
+ setActiveIndex(0);
386
+ }
387
+ };
388
+
389
+ const select = (id: string) => {
390
+ setOpen(false);
391
+ onSwitchDeck(id);
392
+ };
393
+
394
+ useEffect(() => {
395
+ listRef.current
396
+ ?.querySelector(`[data-index="${active}"]`)
397
+ ?.scrollIntoView({ block: 'nearest' });
398
+ }, [active]);
399
+
400
+ const onSearchKeyDown = (e: ReactKeyboardEvent<HTMLInputElement>) => {
401
+ if (e.nativeEvent.isComposing) return;
402
+ if (e.key === 'ArrowDown') {
403
+ e.preventDefault();
404
+ setActiveIndex(Math.min(filtered.length - 1, active + 1));
405
+ } else if (e.key === 'ArrowUp') {
406
+ e.preventDefault();
407
+ setActiveIndex(Math.max(0, active - 1));
408
+ } else if (e.key === 'Enter') {
409
+ e.preventDefault();
410
+ const id = filtered[active];
411
+ if (id) select(id);
412
+ }
413
+ };
414
+
415
+ return (
416
+ <Dialog open={open} onOpenChange={handleOpenChange}>
417
+ <DialogTrigger
418
+ aria-label={t.presenter.switchDeck}
419
+ title={t.presenter.switchDeck}
420
+ className="group -mx-1.5 flex min-w-0 items-center gap-1 rounded-[5px] px-1.5 py-0.5 outline-none hover:bg-card focus-visible:ring-2 focus-visible:ring-ring/30"
421
+ >
422
+ <span className="truncate font-heading text-[14px] font-semibold tracking-tight">
423
+ {slideTitle}
424
+ </span>
425
+ <ChevronDown className="size-3.5 shrink-0 text-muted-foreground" />
426
+ </DialogTrigger>
427
+ <DialogContent
428
+ showCloseButton={false}
429
+ className="dark top-[16%] translate-y-0 gap-0 overflow-hidden p-0 sm:max-w-lg"
430
+ >
431
+ <DialogTitle className="sr-only">{t.presenter.switchDeck}</DialogTitle>
432
+ <input
433
+ value={query}
434
+ onChange={(e) => {
435
+ setQuery(e.target.value);
436
+ setActiveIndex(0);
437
+ }}
438
+ onKeyDown={onSearchKeyDown}
439
+ placeholder={t.presenter.searchDecks}
440
+ className="w-full border-b border-hairline bg-transparent px-4 py-3 text-[13px] text-foreground outline-none placeholder:text-muted-foreground"
441
+ />
442
+ <div ref={listRef} className="max-h-[55vh] overflow-y-auto p-1.5">
443
+ {filtered.length === 0 ? (
444
+ <div className="px-3 py-8 text-center text-[12px] text-muted-foreground">
445
+ {t.presenter.noDecksFound}
446
+ </div>
447
+ ) : (
448
+ filtered.map((id, i) => {
449
+ const mod = modules[id];
450
+ const FirstPage = mod?.default[0];
451
+ return (
452
+ <button
453
+ type="button"
454
+ key={id}
455
+ data-index={i}
456
+ onClick={() => select(id)}
457
+ onMouseMove={() => setActiveIndex(i)}
458
+ className={cn(
459
+ 'flex w-full items-center gap-3 rounded-[6px] p-2 text-left',
460
+ i === active && 'bg-muted',
461
+ )}
462
+ >
463
+ <div
464
+ className="w-24 shrink-0 overflow-hidden rounded-[4px] bg-black ring-1 ring-border"
465
+ style={{ aspectRatio: `${CANVAS_WIDTH}/${CANVAS_HEIGHT}` }}
466
+ >
467
+ {FirstPage && (
468
+ <SlideCanvas flat freezeMotion design={mod.design}>
469
+ <SlidePageProvider index={0} total={mod.default.length}>
470
+ <PreviewStepHost revealed={0}>
471
+ <FirstPage />
472
+ </PreviewStepHost>
473
+ </SlidePageProvider>
474
+ </SlideCanvas>
475
+ )}
476
+ </div>
477
+ <div className="min-w-0 flex-1">
478
+ <div className="truncate text-[13px] font-medium text-foreground">
479
+ {mod?.meta?.title ?? id}
480
+ </div>
481
+ <div className="mt-0.5 truncate font-mono text-[10.5px] text-muted-foreground">
482
+ {id}
483
+ {mod && ` · ${mod.default.length.toString().padStart(2, '0')}`}
484
+ </div>
485
+ </div>
486
+ {id === slideId && <Check className="size-3.5 shrink-0 text-muted-foreground" />}
487
+ </button>
488
+ );
489
+ })
490
+ )}
491
+ </div>
492
+ </DialogContent>
493
+ </Dialog>
494
+ );
495
+ }
496
+
291
497
  function PresenterBottomBar({
292
498
  index,
293
499
  total,
@@ -14,9 +14,10 @@ import {
14
14
  MoreHorizontal,
15
15
  Play,
16
16
  Presentation,
17
+ Terminal,
17
18
  } from 'lucide-react';
18
19
  import { type RefObject, useCallback, useEffect, useMemo, useRef, useState } from 'react';
19
- import { Link, useParams, useSearchParams } from 'react-router-dom';
20
+ import { Link, useNavigate, useParams, useSearchParams } from 'react-router-dom';
20
21
  import { toast } from 'sonner';
21
22
  import { AssetView } from '@/components/asset-view';
22
23
  import { HistoryProvider } from '@/components/history-provider';
@@ -49,6 +50,7 @@ import { useIsMobile } from '@/lib/use-is-mobile';
49
50
  import { format, useLocale } from '@/lib/use-locale';
50
51
  import { useWheelPageNavigation } from '@/lib/use-wheel-page-navigation';
51
52
  import { cn } from '@/lib/utils';
53
+ import { SlideCommandMenu } from '../components/command/slide-command-menu';
52
54
  import { NotesDrawer } from '../components/notes-drawer';
53
55
  import { OverviewGrid } from '../components/overview-grid';
54
56
  import { PdfProgressToast } from '../components/pdf-progress-toast';
@@ -68,16 +70,30 @@ import { useSlideModule } from '../lib/use-slide-module';
68
70
 
69
71
  const { showSlideUi, showSlideBrowser, allowHtmlDownload } = config.build;
70
72
 
73
+ const noop = () => {};
74
+
71
75
  export function Slide() {
72
76
  const { slideId = '' } = useParams();
73
77
  const [searchParams, setSearchParams] = useSearchParams();
78
+ const navigate = useNavigate();
74
79
  const { slide, error } = useSlideModule(slideId);
75
80
  const [playMode, setPlayMode] = useState<'window' | 'fullscreen' | null>(null);
81
+ // Last deck the Player showed. During a presenter-driven deck switch the
82
+ // route's slideId changes while the new module loads and warms; rendering
83
+ // from this cache keeps the Player mounted, which preserves fullscreen
84
+ // (re-entry needs a user gesture) and the elapsed timer.
85
+ const lastPresentedRef = useRef<{
86
+ slideId: string;
87
+ slide: SlideModule;
88
+ pages: SlideModule['default'];
89
+ index: number;
90
+ } | null>(null);
76
91
  const [exporting, setExporting] = useState(false);
77
92
  const [linkCopied, setLinkCopied] = useState(false);
78
93
  const linkCopiedTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
79
94
  const [designOpen, setDesignOpen] = useState(false);
80
95
  const [overviewOpen, setOverviewOpen] = useState(false);
96
+ const [commandOpen, setCommandOpen] = useState(false);
81
97
  const [, setWarmedTick] = useState(0);
82
98
  const handleAssetsWarmed = useCallback(() => {
83
99
  markDeckWarmed(slideId);
@@ -117,6 +133,13 @@ export function Slide() {
117
133
  });
118
134
  }, [slideId, index, pageCount, slide, view]);
119
135
 
136
+ const switchPresentedSlide = useCallback(
137
+ (id: string) => {
138
+ navigate(`/s/${encodeURIComponent(id)}`, { replace: true });
139
+ },
140
+ [navigate],
141
+ );
142
+
120
143
  const goTo = useCallback(
121
144
  (i: number) => {
122
145
  const clamped = Math.max(0, Math.min(pageCount - 1, i));
@@ -311,6 +334,45 @@ export function Slide() {
311
334
  );
312
335
  }
313
336
 
337
+ const presentReady = Boolean(slide) && pageCount > 0 && isDeckWarmed(slideId);
338
+ if (playMode && slide && presentReady) {
339
+ lastPresentedRef.current = { slideId, slide, pages, index };
340
+ }
341
+ const presented = playMode
342
+ ? slide && presentReady
343
+ ? { slideId, slide, pages, index }
344
+ : (lastPresentedRef.current ??
345
+ (slide && pageCount > 0 ? { slideId, slide, pages, index } : null))
346
+ : null;
347
+
348
+ if (playMode && presented) {
349
+ return (
350
+ <>
351
+ <Player
352
+ pages={presented.pages}
353
+ design={presented.slide.design}
354
+ transition={presented.slide.transition}
355
+ index={presented.index}
356
+ onIndexChange={presentReady ? goTo : noop}
357
+ onExit={() => setPlayMode(null)}
358
+ controls
359
+ slideId={presented.slideId}
360
+ onSwitchSlide={switchPresentedSlide}
361
+ fullscreen={playMode === 'fullscreen'}
362
+ />
363
+ {!presentReady && slide && pageCount > 0 && (
364
+ <SlidePreloadLayer
365
+ pages={pages}
366
+ index={index}
367
+ design={slide.design}
368
+ includeCurrent
369
+ onDone={handleAssetsWarmed}
370
+ />
371
+ )}
372
+ </>
373
+ );
374
+ }
375
+
314
376
  if (!slide) {
315
377
  return (
316
378
  <div className="grid min-h-dvh place-items-center px-8 text-muted-foreground">
@@ -398,22 +460,6 @@ export function Slide() {
398
460
  );
399
461
  }
400
462
 
401
- if (playMode) {
402
- return (
403
- <Player
404
- pages={pages}
405
- design={slide.design}
406
- transition={slide.transition}
407
- index={index}
408
- onIndexChange={goTo}
409
- onExit={() => setPlayMode(null)}
410
- controls
411
- slideId={slideId}
412
- fullscreen={playMode === 'fullscreen'}
413
- />
414
- );
415
- }
416
-
417
463
  const title = slide.meta?.title ?? slideId;
418
464
 
419
465
  const copyLink = async () => {
@@ -661,6 +707,10 @@ export function Slide() {
661
707
  )}
662
708
  </DropdownMenuTrigger>
663
709
  <DropdownMenuContent align="end" className="min-w-[200px]">
710
+ <DropdownMenuItem onClick={() => setCommandOpen(true)}>
711
+ <Terminal />
712
+ {t.commandMenu.trigger}
713
+ </DropdownMenuItem>
664
714
  <DropdownMenuItem onClick={copyLink}>
665
715
  <Link2 />
666
716
  {t.slide.copyLink}
@@ -812,6 +862,31 @@ export function Slide() {
812
862
  </div>
813
863
  </DesignProvider>
814
864
  )}
865
+
866
+ {view === 'slides' && (
867
+ <SlideCommandMenu
868
+ open={commandOpen}
869
+ onOpenChange={setCommandOpen}
870
+ pageCount={pageCount}
871
+ currentIndex={index}
872
+ exporting={exporting}
873
+ handlers={{
874
+ onPresentWindow: () => setPlayMode('window'),
875
+ onPresentFullscreen: () => setPlayMode('fullscreen'),
876
+ onPresenterView: () => {
877
+ if (slideId) openPresenterWindow(slideId);
878
+ setPlayMode('window');
879
+ },
880
+ onCopyLink: copyLink,
881
+ onOverview: () => setOverviewOpen(true),
882
+ onToggleDesignPanel: () => setDesignOpen((v) => !v),
883
+ onExportHtml: exportHtml,
884
+ onExportPdf: exportPdf,
885
+ onExportImagePptx: exportImagePptx,
886
+ onGoToPage: goTo,
887
+ }}
888
+ />
889
+ )}
815
890
  </div>
816
891
  </InspectorProvider>
817
892
  </HistoryProvider>