@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
@@ -1,5 +1,5 @@
1
1
  import "./design-cpzS8aud.js";
2
- import { createViteConfig } from "./config-CCHio3pk.js";
2
+ import { createViteConfig } from "./config-GA6NMgs_.js";
3
3
  import path from "node:path";
4
4
  import { build as build$1, mergeConfig } from "vite";
5
5
 
package/dist/cli/bin.js CHANGED
@@ -57,15 +57,15 @@ async function run(argv) {
57
57
  program.name("open-slide").description("Author slides — we handle the Vite/React stack.").version(version, "-v, --version", "print version").helpOption("-h, --help", "show help").showHelpAfterError(chalk.dim("(run `open-slide --help` for usage)"));
58
58
  program.command("dev").description("Start the dev server").addOption(new Option("-p, --port <port>", "port to listen on").argParser(parsePort)).addOption(new Option("--host [host]", "expose on the network (optional host)")).option("--open", "open the browser on start").option("--no-skills-check", "skip the built-in skills drift check").action(async (flags) => {
59
59
  if (flags.skillsCheck !== false) await runSkillsDriftCheck(resolveBuiltinSkillsDir());
60
- const { dev } = await import("../dev-DLRQoCkT.js");
60
+ const { dev } = await import("../dev-D57ui2yV.js");
61
61
  await dev(flags);
62
62
  });
63
63
  program.command("build").description("Build a static site").option("--out-dir <dir>", "output directory (defaults to `dist`)").action(async (flags) => {
64
- const { build } = await import("../build-DaL4Gjn-.js");
64
+ const { build } = await import("../build-CaV_vhIw.js");
65
65
  await build(flags);
66
66
  });
67
67
  program.command("preview").description("Preview the production build").addOption(new Option("-p, --port <port>", "port to listen on").argParser(parsePort)).addOption(new Option("--host [host]", "expose on the network (optional host)")).option("--open", "open the browser on start").action(async (flags) => {
68
- const { preview } = await import("../preview-D3qVGc0S.js");
68
+ const { preview } = await import("../preview-D40Zw_o0.js");
69
69
  await preview(flags);
70
70
  });
71
71
  program.command("sync:skills").description("Sync built-in skills from @open-slide/core into this workspace").option("--dry-run", "show what would change without writing").action(async (flags) => {
@@ -1,4 +1,4 @@
1
- import { Locale } from "./types-Di7nvL8V.js";
1
+ import { Locale } from "./types-8HghULIe.js";
2
2
 
3
3
  //#region src/config.d.ts
4
4
  type OpenSlideBuildConfig = {
@@ -12,6 +12,7 @@ type OpenSlideConfig = {
12
12
  themesDir?: string;
13
13
  assetsDir?: string;
14
14
  port?: number;
15
+ allowedHosts?: string[] | true;
15
16
  /**
16
17
  * @deprecated Pick the UI language from the language switcher in the slide UI
17
18
  * instead. When set, this only seeds the initial language until the user
@@ -4326,6 +4326,7 @@ async function createViteConfig(opts) {
4326
4326
  },
4327
4327
  server: {
4328
4328
  port: config.port ?? 5173,
4329
+ ...config.allowedHosts !== void 0 ? { allowedHosts: config.allowedHosts } : {},
4329
4330
  fs: { allow: [
4330
4331
  APP_ROOT,
4331
4332
  userCwd,
@@ -1,5 +1,5 @@
1
1
  import "./design-cpzS8aud.js";
2
- import { DEV_SUPERVISED_ENV, RESTART_EXIT_CODE, createViteConfig } from "./config-CCHio3pk.js";
2
+ import { DEV_SUPERVISED_ENV, RESTART_EXIT_CODE, createViteConfig } from "./config-GA6NMgs_.js";
3
3
  import chalk from "chalk";
4
4
  import path from "node:path";
5
5
  import { existsSync } from "node:fs";
@@ -156,7 +156,10 @@ const en = {
156
156
  elapsed: "Elapsed",
157
157
  jump: "Jump",
158
158
  loadingSlide: "Loading {slideId}…",
159
- loadingAssets: "Loading assets…"
159
+ loadingAssets: "Loading assets…",
160
+ switchDeck: "Switch presentation",
161
+ searchDecks: "Search presentations…",
162
+ noDecksFound: "No presentations match"
160
163
  },
161
164
  present: {
162
165
  prevSlideAria: "Previous slide (←)",
@@ -390,6 +393,32 @@ const en = {
390
393
  generating: "Building presentation…",
391
394
  done: "Done"
392
395
  },
396
+ commandMenu: {
397
+ trigger: "Commands",
398
+ triggerAria: "Open command menu",
399
+ triggerTooltip: "Search",
400
+ placeholder: "Search slides or run a command…",
401
+ slidePlaceholder: "Search this deck or run a command…",
402
+ empty: "No results.",
403
+ groupSlides: "Slides",
404
+ groupFolders: "Folders",
405
+ groupNavigation: "Go to",
406
+ groupPresent: "Present",
407
+ groupDeck: "This deck",
408
+ groupExport: "Export",
409
+ groupPages: "Pages",
410
+ groupAppearance: "Appearance",
411
+ groupDeveloper: "Developer",
412
+ goToPage: "Page {n}",
413
+ overview: "Slide overview",
414
+ designPanel: "Toggle design panel",
415
+ backToSlides: "Back to all slides",
416
+ themeItem: "Theme: {name}",
417
+ languageItem: "Language: {name}",
418
+ hintNavigate: "Navigate",
419
+ hintSelect: "Select",
420
+ hintClose: "Close"
421
+ },
393
422
  themeToggle: {
394
423
  toggleAria: "Toggle theme",
395
424
  title: "Theme",
@@ -593,7 +622,10 @@ const ja = {
593
622
  elapsed: "経過時間",
594
623
  jump: "ジャンプ",
595
624
  loadingSlide: "{slideId} を読み込み中…",
596
- loadingAssets: "アセットを読み込み中…"
625
+ loadingAssets: "アセットを読み込み中…",
626
+ switchDeck: "デッキを切り替え",
627
+ searchDecks: "デッキを検索…",
628
+ noDecksFound: "一致するデッキがありません"
597
629
  },
598
630
  present: {
599
631
  prevSlideAria: "前のスライド (←)",
@@ -827,6 +859,32 @@ const ja = {
827
859
  generating: "プレゼンテーションを構築中…",
828
860
  done: "完了"
829
861
  },
862
+ commandMenu: {
863
+ trigger: "コマンド",
864
+ triggerAria: "コマンドメニューを開く",
865
+ triggerTooltip: "検索",
866
+ placeholder: "スライドを検索、またはコマンドを実行…",
867
+ slidePlaceholder: "このデッキを検索、またはコマンドを実行…",
868
+ empty: "結果がありません。",
869
+ groupSlides: "スライド",
870
+ groupFolders: "フォルダ",
871
+ groupNavigation: "移動",
872
+ groupPresent: "発表",
873
+ groupDeck: "このデッキ",
874
+ groupExport: "エクスポート",
875
+ groupPages: "ページ",
876
+ groupAppearance: "外観",
877
+ groupDeveloper: "開発",
878
+ goToPage: "{n} ページ目",
879
+ overview: "ページ一覧",
880
+ designPanel: "デザインパネルの切り替え",
881
+ backToSlides: "すべてのスライドへ戻る",
882
+ themeItem: "テーマ: {name}",
883
+ languageItem: "言語: {name}",
884
+ hintNavigate: "移動",
885
+ hintSelect: "選択",
886
+ hintClose: "閉じる"
887
+ },
830
888
  themeToggle: {
831
889
  toggleAria: "テーマを切り替え",
832
890
  title: "テーマ",
@@ -1030,7 +1088,10 @@ const zhCN = {
1030
1088
  elapsed: "已用时",
1031
1089
  jump: "跳至",
1032
1090
  loadingSlide: "正在加载 {slideId}…",
1033
- loadingAssets: "正在加载资源…"
1091
+ loadingAssets: "正在加载资源…",
1092
+ switchDeck: "切换演示文稿",
1093
+ searchDecks: "搜索演示文稿…",
1094
+ noDecksFound: "没有匹配的演示文稿"
1034
1095
  },
1035
1096
  present: {
1036
1097
  prevSlideAria: "上一张幻灯片 (←)",
@@ -1264,6 +1325,32 @@ const zhCN = {
1264
1325
  generating: "正在组合演示文稿…",
1265
1326
  done: "完成"
1266
1327
  },
1328
+ commandMenu: {
1329
+ trigger: "命令",
1330
+ triggerAria: "打开命令菜单",
1331
+ triggerTooltip: "搜索",
1332
+ placeholder: "搜索幻灯片或执行命令…",
1333
+ slidePlaceholder: "搜索这份幻灯片或执行命令…",
1334
+ empty: "没有匹配的结果。",
1335
+ groupSlides: "幻灯片",
1336
+ groupFolders: "文件夹",
1337
+ groupNavigation: "前往",
1338
+ groupPresent: "放映",
1339
+ groupDeck: "这份幻灯片",
1340
+ groupExport: "导出",
1341
+ groupPages: "页面",
1342
+ groupAppearance: "外观",
1343
+ groupDeveloper: "开发",
1344
+ goToPage: "第 {n} 页",
1345
+ overview: "页面总览",
1346
+ designPanel: "切换设计面板",
1347
+ backToSlides: "回到所有幻灯片",
1348
+ themeItem: "主题:{name}",
1349
+ languageItem: "语言:{name}",
1350
+ hintNavigate: "移动",
1351
+ hintSelect: "选择",
1352
+ hintClose: "关闭"
1353
+ },
1267
1354
  themeToggle: {
1268
1355
  toggleAria: "切换主题",
1269
1356
  title: "主题",
@@ -1467,7 +1554,10 @@ const zhTW = {
1467
1554
  elapsed: "已耗時",
1468
1555
  jump: "跳至",
1469
1556
  loadingSlide: "正在載入 {slideId}…",
1470
- loadingAssets: "正在載入資源…"
1557
+ loadingAssets: "正在載入資源…",
1558
+ switchDeck: "切換簡報",
1559
+ searchDecks: "搜尋簡報…",
1560
+ noDecksFound: "沒有符合的簡報"
1471
1561
  },
1472
1562
  present: {
1473
1563
  prevSlideAria: "上一張投影片 (←)",
@@ -1701,6 +1791,32 @@ const zhTW = {
1701
1791
  generating: "正在組合簡報…",
1702
1792
  done: "完成"
1703
1793
  },
1794
+ commandMenu: {
1795
+ trigger: "指令",
1796
+ triggerAria: "開啟指令選單",
1797
+ triggerTooltip: "搜尋",
1798
+ placeholder: "搜尋簡報或執行指令…",
1799
+ slidePlaceholder: "搜尋這份簡報或執行指令…",
1800
+ empty: "沒有符合的結果。",
1801
+ groupSlides: "簡報",
1802
+ groupFolders: "資料夾",
1803
+ groupNavigation: "前往",
1804
+ groupPresent: "播放",
1805
+ groupDeck: "這份簡報",
1806
+ groupExport: "匯出",
1807
+ groupPages: "頁面",
1808
+ groupAppearance: "外觀",
1809
+ groupDeveloper: "開發",
1810
+ goToPage: "第 {n} 頁",
1811
+ overview: "頁面總覽",
1812
+ designPanel: "切換設計面板",
1813
+ backToSlides: "回到所有簡報",
1814
+ themeItem: "主題:{name}",
1815
+ languageItem: "語言:{name}",
1816
+ hintNavigate: "移動",
1817
+ hintSelect: "選擇",
1818
+ hintClose: "關閉"
1819
+ },
1704
1820
  themeToggle: {
1705
1821
  toggleAria: "切換主題",
1706
1822
  title: "主題",
package/dist/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
- import { Locale, Plural } from "./types-Di7nvL8V.js";
2
- import { OpenSlideConfig } from "./config-DIvIP8vY.js";
1
+ import { Locale, Plural } from "./types-8HghULIe.js";
2
+ import { OpenSlideConfig } from "./config-CDHB8Oow.js";
3
3
  import { CSSProperties, ComponentType, HTMLAttributes, PropsWithChildren, ReactNode } from "react";
4
4
  import * as react_jsx_runtime1 from "react/jsx-runtime";
5
- import * as react_jsx_runtime2 from "react/jsx-runtime";
5
+ import * as react_jsx_runtime0 from "react/jsx-runtime";
6
+ import * as react_jsx_runtime3 from "react/jsx-runtime";
6
7
  import * as react_jsx_runtime4 from "react/jsx-runtime";
7
- import * as react_jsx_runtime5 from "react/jsx-runtime";
8
8
 
9
9
  //#region src/app/components/image-placeholder.d.ts
10
10
  type ImagePlaceholderProps = {
@@ -36,7 +36,7 @@ declare function MorphElement({
36
36
  children,
37
37
  className,
38
38
  style
39
- }: MorphElementProps): react_jsx_runtime2.JSX.Element;
39
+ }: MorphElementProps): react_jsx_runtime0.JSX.Element;
40
40
 
41
41
  //#endregion
42
42
  //#region src/app/lib/design.d.ts
@@ -118,7 +118,7 @@ declare function useIsActivePage(): boolean;
118
118
  type StepsProps = PropsWithChildren;
119
119
  declare function Steps({
120
120
  children
121
- }: StepsProps): react_jsx_runtime4.JSX.Element;
121
+ }: StepsProps): react_jsx_runtime3.JSX.Element;
122
122
  type StepProps = PropsWithChildren<{
123
123
  duration?: number;
124
124
  }>;
@@ -129,7 +129,7 @@ declare function Step({
129
129
  children,
130
130
  duration,
131
131
  _revealed
132
- }: InternalStepProps): react_jsx_runtime5.JSX.Element;
132
+ }: InternalStepProps): react_jsx_runtime4.JSX.Element;
133
133
 
134
134
  //#endregion
135
135
  export { CANVAS_HEIGHT, CANVAS_WIDTH, DesignFonts, DesignPalette, DesignSystem, DesignTypeScale, ImagePlaceholder, ImagePlaceholderProps, Locale, MorphElement, MorphElementProps, MorphTransition, OpenSlideConfig, Page, Plural, SlideMeta, SlideModule, SlideTransition, Step, StepProps, Steps, StepsProps, TransitionPhase, cssVarsToString, defaultDesign, designToCssVars, useIsActivePage, useSlidePageNumber };
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { en, ja, zhCN, zhTW } from "./format-CxmsgcBh.js";
1
+ import { en, ja, zhCN, zhTW } from "./format-74A3B6zu.js";
2
2
  import { cssVarsToString, defaultDesign, designToCssVars } from "./design-cpzS8aud.js";
3
3
  import { Children, cloneElement, createContext, isValidElement, useCallback, useContext, useEffect, useLayoutEffect, useRef, useState, useSyncExternalStore } from "react";
4
4
  import { toast } from "sonner";
@@ -1,4 +1,4 @@
1
- import { Locale, Plural } from "../types-Di7nvL8V.js";
1
+ import { Locale, Plural } from "../types-8HghULIe.js";
2
2
 
3
3
  //#region src/locale/en.d.ts
4
4
  declare const en: Locale;
@@ -1,3 +1,3 @@
1
- import { en, format, ja, plural, zhCN, zhTW } from "../format-CxmsgcBh.js";
1
+ import { en, format, ja, plural, zhCN, zhTW } from "../format-74A3B6zu.js";
2
2
 
3
3
  export { en, format, ja, plural, zhCN, zhTW };
@@ -1,5 +1,5 @@
1
1
  import "./design-cpzS8aud.js";
2
- import { createViteConfig } from "./config-CCHio3pk.js";
2
+ import { createViteConfig } from "./config-GA6NMgs_.js";
3
3
  import { mergeConfig, preview as preview$1 } from "vite";
4
4
 
5
5
  //#region src/cli/preview.ts
@@ -166,6 +166,9 @@ type Locale = {
166
166
  /** template: "Loading {slideId}…" */
167
167
  loadingSlide: string;
168
168
  loadingAssets: string;
169
+ switchDeck: string;
170
+ searchDecks: string;
171
+ noDecksFound: string;
169
172
  };
170
173
  present: {
171
174
  prevSlideAria: string;
@@ -423,6 +426,35 @@ type Locale = {
423
426
  generating: string;
424
427
  done: string;
425
428
  };
429
+ commandMenu: {
430
+ trigger: string;
431
+ triggerAria: string;
432
+ triggerTooltip: string;
433
+ placeholder: string;
434
+ slidePlaceholder: string;
435
+ empty: string;
436
+ groupSlides: string;
437
+ groupFolders: string;
438
+ groupNavigation: string;
439
+ groupPresent: string;
440
+ groupDeck: string;
441
+ groupExport: string;
442
+ groupPages: string;
443
+ groupAppearance: string;
444
+ groupDeveloper: string;
445
+ /** template: "Page {n}" */
446
+ goToPage: string;
447
+ overview: string;
448
+ designPanel: string;
449
+ backToSlides: string;
450
+ /** template: "Theme: {name}" */
451
+ themeItem: string;
452
+ /** template: "Language: {name}" */
453
+ languageItem: string;
454
+ hintNavigate: string;
455
+ hintSelect: string;
456
+ hintClose: string;
457
+ };
426
458
  themeToggle: {
427
459
  toggleAria: string;
428
460
  title: string;
@@ -1,5 +1,5 @@
1
- import "../types-Di7nvL8V.js";
2
- import { OpenSlideConfig } from "../config-DIvIP8vY.js";
1
+ import "../types-8HghULIe.js";
2
+ import { OpenSlideConfig } from "../config-CDHB8Oow.js";
3
3
  import { InlineConfig } from "vite";
4
4
 
5
5
  //#region src/vite/config.d.ts
@@ -1,4 +1,4 @@
1
1
  import "../design-cpzS8aud.js";
2
- import { createViteConfig } from "../config-CCHio3pk.js";
2
+ import { createViteConfig } from "../config-GA6NMgs_.js";
3
3
 
4
4
  export { createViteConfig };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@open-slide/core",
3
- "version": "1.17.1",
3
+ "version": "1.19.0",
4
4
  "description": "Runtime and CLI for open-slide — write slides in slides/, we handle the rest.",
5
5
  "type": "module",
6
6
  "exports": {
@@ -68,9 +68,10 @@
68
68
  "@fontsource-variable/geist": "^5.2.8",
69
69
  "@tailwindcss/vite": "^4.3.3",
70
70
  "@vitejs/plugin-react": "^4.3.3",
71
- "chalk": "^5.3.0",
71
+ "chalk": "^6.0.0",
72
72
  "class-variance-authority": "^0.7.1",
73
73
  "clsx": "^2.1.1",
74
+ "cmdk": "^1.1.1",
74
75
  "commander": "^15.0.0",
75
76
  "emoji-picker-react": "^4.19.1",
76
77
  "fast-glob": "^3.3.2",
@@ -91,6 +92,7 @@
91
92
  "vite": "^5.4.10"
92
93
  },
93
94
  "devDependencies": {
95
+ "@playwright/test": "~1.62.1",
94
96
  "@types/node": "^22.19.17",
95
97
  "@types/react": "^18.3.12",
96
98
  "@types/react-dom": "^18.3.1",
@@ -99,6 +101,7 @@
99
101
  },
100
102
  "scripts": {
101
103
  "build": "tsdown",
102
- "typecheck": "tsc --noEmit"
104
+ "typecheck": "tsc --noEmit",
105
+ "test:e2e": "pnpm run build && playwright test"
103
106
  }
104
107
  }
@@ -0,0 +1,227 @@
1
+ import { Check, Languages, Loader2, Monitor, Moon, RotateCw, Search, Sun } from 'lucide-react';
2
+ import { useTheme } from 'next-themes';
3
+ import { type ReactNode, useEffect, useMemo, useState } from 'react';
4
+ import { IconTooltip } from '@/components/icon-tooltip';
5
+ import { buttonVariants } from '@/components/ui/button';
6
+ import { TooltipTrigger } from '@/components/ui/tooltip';
7
+ import { LOCALE_OPTIONS, setLocale } from '@/lib/locale-store';
8
+ import { format, useLocale } from '@/lib/use-locale';
9
+ import { useRestartServer } from '@/lib/use-restart-server';
10
+ import {
11
+ Command,
12
+ CommandDialog,
13
+ CommandEmpty,
14
+ CommandGroup,
15
+ CommandInput,
16
+ CommandItem,
17
+ CommandList,
18
+ CommandShortcut,
19
+ } from './command';
20
+
21
+ export type CommandSpec = {
22
+ id: string;
23
+ label: string;
24
+ icon?: ReactNode;
25
+ /** Extra match terms — ASCII aliases keep commands findable under any locale. */
26
+ keywords?: string[];
27
+ shortcut?: string;
28
+ disabled?: boolean;
29
+ active?: boolean;
30
+ run: () => void | Promise<void>;
31
+ };
32
+
33
+ export type CommandGroupSpec = {
34
+ id: string;
35
+ heading: string;
36
+ items: CommandSpec[];
37
+ /** Long lists (deck pages) only surface once the user types, so the idle menu stays scannable. */
38
+ searchOnly?: boolean;
39
+ };
40
+
41
+ export function CommandMenu({
42
+ open,
43
+ onOpenChange,
44
+ groups,
45
+ placeholder,
46
+ }: {
47
+ open: boolean;
48
+ onOpenChange: (open: boolean) => void;
49
+ groups: CommandGroupSpec[];
50
+ placeholder: string;
51
+ }) {
52
+ const t = useLocale();
53
+ const [search, setSearch] = useState('');
54
+ const sharedGroups = useSharedCommandGroups();
55
+
56
+ useEffect(() => {
57
+ const onKey = (event: KeyboardEvent) => {
58
+ if (event.key !== 'k' && event.key !== 'K') return;
59
+ if (!event.metaKey && !event.ctrlKey) return;
60
+ // Auto-repeat while the combo is held would toggle the menu shut again.
61
+ if (event.repeat) return;
62
+ event.preventDefault();
63
+ onOpenChange(!open);
64
+ };
65
+ window.addEventListener('keydown', onKey);
66
+ return () => window.removeEventListener('keydown', onKey);
67
+ }, [open, onOpenChange]);
68
+
69
+ useEffect(() => {
70
+ if (!open) setSearch('');
71
+ }, [open]);
72
+
73
+ const searching = search.trim().length > 0;
74
+ const visibleGroups = [...groups, ...sharedGroups].filter(
75
+ (group) => group.items.length > 0 && (searching || !group.searchOnly),
76
+ );
77
+
78
+ const run = (item: CommandSpec) => {
79
+ if (item.disabled) return;
80
+ // Close first: exports, fullscreen and panels all expect an unobstructed page.
81
+ onOpenChange(false);
82
+ void item.run();
83
+ };
84
+
85
+ return (
86
+ <CommandDialog
87
+ open={open}
88
+ onOpenChange={onOpenChange}
89
+ title={t.commandMenu.trigger}
90
+ description={placeholder}
91
+ >
92
+ <Command label={t.commandMenu.trigger} loop>
93
+ <CommandInput value={search} onValueChange={setSearch} placeholder={placeholder} />
94
+ <CommandList>
95
+ <CommandEmpty>{t.commandMenu.empty}</CommandEmpty>
96
+ {visibleGroups.map((group) => (
97
+ <CommandGroup key={group.id} heading={group.heading}>
98
+ {group.items.map((item) => (
99
+ <CommandItem
100
+ key={item.id}
101
+ value={item.id}
102
+ keywords={[item.label, ...(item.keywords ?? [])]}
103
+ disabled={item.disabled}
104
+ onSelect={() => run(item)}
105
+ >
106
+ {item.icon}
107
+ <span className="min-w-0 flex-1 truncate">{item.label}</span>
108
+ {item.active && <Check className="ml-auto opacity-100 text-brand" aria-hidden />}
109
+ {item.shortcut && <CommandShortcut>{item.shortcut}</CommandShortcut>}
110
+ </CommandItem>
111
+ ))}
112
+ </CommandGroup>
113
+ ))}
114
+ </CommandList>
115
+ <CommandFooter />
116
+ </Command>
117
+ </CommandDialog>
118
+ );
119
+ }
120
+
121
+ const IS_APPLE =
122
+ typeof navigator !== 'undefined' && /Mac|iPhone|iPad|iPod/.test(navigator.userAgent);
123
+
124
+ export const COMMAND_MENU_SHORTCUT = IS_APPLE ? '⌘K' : 'Ctrl K';
125
+
126
+ export function CommandMenuTrigger({ onClick }: { onClick: () => void }) {
127
+ const t = useLocale();
128
+ return (
129
+ <IconTooltip label={t.commandMenu.triggerTooltip} shortcut={COMMAND_MENU_SHORTCUT}>
130
+ <TooltipTrigger
131
+ type="button"
132
+ onClick={onClick}
133
+ aria-label={t.commandMenu.triggerAria}
134
+ aria-haspopup="dialog"
135
+ className={buttonVariants({ variant: 'ghost', size: 'icon-sm' })}
136
+ >
137
+ <Search className="size-3.5" />
138
+ </TooltipTrigger>
139
+ </IconTooltip>
140
+ );
141
+ }
142
+
143
+ function CommandFooter() {
144
+ const t = useLocale();
145
+ return (
146
+ <div className="flex items-center justify-between gap-3 border-t border-hairline bg-muted/30 px-3 py-2 text-[10.5px] text-muted-foreground">
147
+ <Hint keys="esc" label={t.commandMenu.hintClose} />
148
+ <span className="inline-flex items-center gap-3">
149
+ <Hint keys="↑↓" label={t.commandMenu.hintNavigate} />
150
+ <Hint keys="↵" label={t.commandMenu.hintSelect} />
151
+ </span>
152
+ </div>
153
+ );
154
+ }
155
+
156
+ function Hint({ keys, label }: { keys: string; label: string }) {
157
+ return (
158
+ <span className="inline-flex items-center gap-1">
159
+ <kbd className="rounded-[3px] border border-hairline bg-card px-1 py-0.5 font-mono text-[9.5px] leading-none">
160
+ {keys}
161
+ </kbd>
162
+ {label}
163
+ </span>
164
+ );
165
+ }
166
+
167
+ function useSharedCommandGroups(): CommandGroupSpec[] {
168
+ const t = useLocale();
169
+ const { theme, setTheme } = useTheme();
170
+ const { canRestart, restarting, restartServer } = useRestartServer();
171
+
172
+ return useMemo(() => {
173
+ const appearance: CommandSpec[] = [
174
+ {
175
+ id: 'theme-light',
176
+ label: format(t.commandMenu.themeItem, { name: t.themeToggle.light }),
177
+ icon: <Sun />,
178
+ keywords: ['theme', 'light', 'appearance'],
179
+ active: theme === 'light',
180
+ run: () => setTheme('light'),
181
+ },
182
+ {
183
+ id: 'theme-dark',
184
+ label: format(t.commandMenu.themeItem, { name: t.themeToggle.dark }),
185
+ icon: <Moon />,
186
+ keywords: ['theme', 'dark', 'appearance'],
187
+ active: theme === 'dark',
188
+ run: () => setTheme('dark'),
189
+ },
190
+ {
191
+ id: 'theme-system',
192
+ label: format(t.commandMenu.themeItem, { name: t.themeToggle.system }),
193
+ icon: <Monitor />,
194
+ keywords: ['theme', 'system', 'appearance'],
195
+ active: theme === 'system',
196
+ run: () => setTheme('system'),
197
+ },
198
+ ...LOCALE_OPTIONS.map((option) => ({
199
+ id: `locale-${option.id}`,
200
+ label: format(t.commandMenu.languageItem, { name: option.label }),
201
+ icon: <Languages />,
202
+ keywords: ['language', 'locale', option.id],
203
+ active: t.id === option.id,
204
+ run: () => setLocale(option.id),
205
+ })),
206
+ ];
207
+
208
+ const developer: CommandSpec[] =
209
+ import.meta.env.DEV && canRestart
210
+ ? [
211
+ {
212
+ id: 'restart-dev-server',
213
+ label: restarting ? t.home.restartingServer : t.home.restartServer,
214
+ icon: restarting ? <Loader2 className="animate-spin" /> : <RotateCw />,
215
+ keywords: ['restart', 'dev', 'server', 'reload'],
216
+ disabled: restarting,
217
+ run: restartServer,
218
+ },
219
+ ]
220
+ : [];
221
+
222
+ return [
223
+ { id: 'appearance', heading: t.commandMenu.groupAppearance, items: appearance },
224
+ { id: 'developer', heading: t.commandMenu.groupDeveloper, items: developer },
225
+ ];
226
+ }, [t, theme, setTheme, canRestart, restarting, restartServer]);
227
+ }