@open-slide/core 1.17.0 → 1.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/dist/{build-D7-fnqn8.js → build-DaL4Gjn-.js} +1 -1
  2. package/dist/cli/bin.js +3 -3
  3. package/dist/{config-CSgUUnlv.js → config-CCHio3pk.js} +9 -1
  4. package/dist/{config-DIvIP8vY.d.ts → config-CYs4WJfL.d.ts} +1 -1
  5. package/dist/{dev-BkJdG_0u.js → dev-DLRQoCkT.js} +1 -1
  6. package/dist/{format-CxmsgcBh.js → format-CxPnpVRu.js} +104 -0
  7. package/dist/index.d.ts +10 -10
  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-CC_DNgvi.js → preview-D3qVGc0S.js} +1 -1
  12. package/dist/{types-Di7nvL8V.d.ts → types-Wz88-Fe1.d.ts} +29 -0
  13. package/dist/vite/index.d.ts +2 -2
  14. package/dist/vite/index.js +1 -1
  15. package/package.json +12 -9
  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/inspector/inspect-overlay.tsx +1 -1
  22. package/src/app/components/language-toggle.tsx +15 -8
  23. package/src/app/components/sidebar/sidebar-footer.tsx +2 -37
  24. package/src/app/components/sidebar/sidebar.tsx +4 -0
  25. package/src/app/components/theme-toggle.tsx +16 -9
  26. package/src/app/lib/use-click-page-navigation.ts +1 -1
  27. package/src/app/lib/use-restart-server.ts +78 -0
  28. package/src/app/lib/use-slide-titles.ts +29 -0
  29. package/src/app/lib/use-wheel-page-navigation.ts +1 -1
  30. package/src/app/routes/home-shell.tsx +15 -0
  31. package/src/app/routes/slide.tsx +33 -1
  32. package/src/locale/en.ts +27 -0
  33. package/src/locale/ja.ts +27 -0
  34. package/src/locale/types.ts +30 -0
  35. package/src/locale/zh-cn.ts +27 -0
  36. package/src/locale/zh-tw.ts +27 -0
@@ -1,5 +1,5 @@
1
1
  import "./design-cpzS8aud.js";
2
- import { createViteConfig } from "./config-CSgUUnlv.js";
2
+ import { createViteConfig } from "./config-CCHio3pk.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-BkJdG_0u.js");
60
+ const { dev } = await import("../dev-DLRQoCkT.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-D7-fnqn8.js");
64
+ const { build } = await import("../build-DaL4Gjn-.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-CC_DNgvi.js");
68
+ const { preview } = await import("../preview-D3qVGc0S.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) => {
@@ -4314,7 +4314,15 @@ async function createViteConfig(opts) {
4314
4314
  "class-variance-authority",
4315
4315
  "emoji-picker-react"
4316
4316
  ],
4317
- rolldownOptions: { external: [/^virtual:open-slide\//] }
4317
+ esbuildOptions: { plugins: [{
4318
+ name: "open-slide:virtual-externals",
4319
+ setup(build$1) {
4320
+ build$1.onResolve({ filter: /^virtual:open-slide\// }, (args) => ({
4321
+ path: args.path,
4322
+ external: true
4323
+ }));
4324
+ }
4325
+ }] }
4318
4326
  },
4319
4327
  server: {
4320
4328
  port: config.port ?? 5173,
@@ -1,4 +1,4 @@
1
- import { Locale } from "./types-Di7nvL8V.js";
1
+ import { Locale } from "./types-Wz88-Fe1.js";
2
2
 
3
3
  //#region src/config.d.ts
4
4
  type OpenSlideBuildConfig = {
@@ -1,5 +1,5 @@
1
1
  import "./design-cpzS8aud.js";
2
- import { DEV_SUPERVISED_ENV, RESTART_EXIT_CODE, createViteConfig } from "./config-CSgUUnlv.js";
2
+ import { DEV_SUPERVISED_ENV, RESTART_EXIT_CODE, createViteConfig } from "./config-CCHio3pk.js";
3
3
  import chalk from "chalk";
4
4
  import path from "node:path";
5
5
  import { existsSync } from "node:fs";
@@ -390,6 +390,32 @@ const en = {
390
390
  generating: "Building presentation…",
391
391
  done: "Done"
392
392
  },
393
+ commandMenu: {
394
+ trigger: "Commands",
395
+ triggerAria: "Open command menu",
396
+ triggerTooltip: "Search",
397
+ placeholder: "Search slides or run a command…",
398
+ slidePlaceholder: "Search this deck or run a command…",
399
+ empty: "No results.",
400
+ groupSlides: "Slides",
401
+ groupFolders: "Folders",
402
+ groupNavigation: "Go to",
403
+ groupPresent: "Present",
404
+ groupDeck: "This deck",
405
+ groupExport: "Export",
406
+ groupPages: "Pages",
407
+ groupAppearance: "Appearance",
408
+ groupDeveloper: "Developer",
409
+ goToPage: "Page {n}",
410
+ overview: "Slide overview",
411
+ designPanel: "Toggle design panel",
412
+ backToSlides: "Back to all slides",
413
+ themeItem: "Theme: {name}",
414
+ languageItem: "Language: {name}",
415
+ hintNavigate: "Navigate",
416
+ hintSelect: "Select",
417
+ hintClose: "Close"
418
+ },
393
419
  themeToggle: {
394
420
  toggleAria: "Toggle theme",
395
421
  title: "Theme",
@@ -827,6 +853,32 @@ const ja = {
827
853
  generating: "プレゼンテーションを構築中…",
828
854
  done: "完了"
829
855
  },
856
+ commandMenu: {
857
+ trigger: "コマンド",
858
+ triggerAria: "コマンドメニューを開く",
859
+ triggerTooltip: "検索",
860
+ placeholder: "スライドを検索、またはコマンドを実行…",
861
+ slidePlaceholder: "このデッキを検索、またはコマンドを実行…",
862
+ empty: "結果がありません。",
863
+ groupSlides: "スライド",
864
+ groupFolders: "フォルダ",
865
+ groupNavigation: "移動",
866
+ groupPresent: "発表",
867
+ groupDeck: "このデッキ",
868
+ groupExport: "エクスポート",
869
+ groupPages: "ページ",
870
+ groupAppearance: "外観",
871
+ groupDeveloper: "開発",
872
+ goToPage: "{n} ページ目",
873
+ overview: "ページ一覧",
874
+ designPanel: "デザインパネルの切り替え",
875
+ backToSlides: "すべてのスライドへ戻る",
876
+ themeItem: "テーマ: {name}",
877
+ languageItem: "言語: {name}",
878
+ hintNavigate: "移動",
879
+ hintSelect: "選択",
880
+ hintClose: "閉じる"
881
+ },
830
882
  themeToggle: {
831
883
  toggleAria: "テーマを切り替え",
832
884
  title: "テーマ",
@@ -1264,6 +1316,32 @@ const zhCN = {
1264
1316
  generating: "正在组合演示文稿…",
1265
1317
  done: "完成"
1266
1318
  },
1319
+ commandMenu: {
1320
+ trigger: "命令",
1321
+ triggerAria: "打开命令菜单",
1322
+ triggerTooltip: "搜索",
1323
+ placeholder: "搜索幻灯片或执行命令…",
1324
+ slidePlaceholder: "搜索这份幻灯片或执行命令…",
1325
+ empty: "没有匹配的结果。",
1326
+ groupSlides: "幻灯片",
1327
+ groupFolders: "文件夹",
1328
+ groupNavigation: "前往",
1329
+ groupPresent: "放映",
1330
+ groupDeck: "这份幻灯片",
1331
+ groupExport: "导出",
1332
+ groupPages: "页面",
1333
+ groupAppearance: "外观",
1334
+ groupDeveloper: "开发",
1335
+ goToPage: "第 {n} 页",
1336
+ overview: "页面总览",
1337
+ designPanel: "切换设计面板",
1338
+ backToSlides: "回到所有幻灯片",
1339
+ themeItem: "主题:{name}",
1340
+ languageItem: "语言:{name}",
1341
+ hintNavigate: "移动",
1342
+ hintSelect: "选择",
1343
+ hintClose: "关闭"
1344
+ },
1267
1345
  themeToggle: {
1268
1346
  toggleAria: "切换主题",
1269
1347
  title: "主题",
@@ -1701,6 +1779,32 @@ const zhTW = {
1701
1779
  generating: "正在組合簡報…",
1702
1780
  done: "完成"
1703
1781
  },
1782
+ commandMenu: {
1783
+ trigger: "指令",
1784
+ triggerAria: "開啟指令選單",
1785
+ triggerTooltip: "搜尋",
1786
+ placeholder: "搜尋簡報或執行指令…",
1787
+ slidePlaceholder: "搜尋這份簡報或執行指令…",
1788
+ empty: "沒有符合的結果。",
1789
+ groupSlides: "簡報",
1790
+ groupFolders: "資料夾",
1791
+ groupNavigation: "前往",
1792
+ groupPresent: "播放",
1793
+ groupDeck: "這份簡報",
1794
+ groupExport: "匯出",
1795
+ groupPages: "頁面",
1796
+ groupAppearance: "外觀",
1797
+ groupDeveloper: "開發",
1798
+ goToPage: "第 {n} 頁",
1799
+ overview: "頁面總覽",
1800
+ designPanel: "切換設計面板",
1801
+ backToSlides: "回到所有簡報",
1802
+ themeItem: "主題:{name}",
1803
+ languageItem: "語言:{name}",
1804
+ hintNavigate: "移動",
1805
+ hintSelect: "選擇",
1806
+ hintClose: "關閉"
1807
+ },
1704
1808
  themeToggle: {
1705
1809
  toggleAria: "切換主題",
1706
1810
  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";
3
- import * as react1 from "react";
4
- import * as react0 from "react";
5
- import * as react3 from "react";
6
- import * as react4 from "react";
1
+ import { Locale, Plural } from "./types-Wz88-Fe1.js";
2
+ import { OpenSlideConfig } from "./config-CYs4WJfL.js";
7
3
  import { CSSProperties, ComponentType, HTMLAttributes, PropsWithChildren, ReactNode } from "react";
4
+ import * as react_jsx_runtime0 from "react/jsx-runtime";
5
+ import * as react_jsx_runtime1 from "react/jsx-runtime";
6
+ 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 = {
@@ -21,7 +21,7 @@ declare function ImagePlaceholder({
21
21
  style,
22
22
  className,
23
23
  ...rest
24
- }: ImagePlaceholderProps): react1.JSX.Element;
24
+ }: ImagePlaceholderProps): react_jsx_runtime0.JSX.Element;
25
25
 
26
26
  //#endregion
27
27
  //#region src/app/components/morph-element.d.ts
@@ -36,7 +36,7 @@ declare function MorphElement({
36
36
  children,
37
37
  className,
38
38
  style
39
- }: MorphElementProps): react0.JSX.Element;
39
+ }: MorphElementProps): react_jsx_runtime1.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): react3.JSX.Element;
121
+ }: StepsProps): react_jsx_runtime4.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): react4.JSX.Element;
132
+ }: InternalStepProps): react_jsx_runtime5.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-CxPnpVRu.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-Wz88-Fe1.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-CxPnpVRu.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-CSgUUnlv.js";
2
+ import { createViteConfig } from "./config-CCHio3pk.js";
3
3
  import { mergeConfig, preview as preview$1 } from "vite";
4
4
 
5
5
  //#region src/cli/preview.ts
@@ -423,6 +423,35 @@ type Locale = {
423
423
  generating: string;
424
424
  done: string;
425
425
  };
426
+ commandMenu: {
427
+ trigger: string;
428
+ triggerAria: string;
429
+ triggerTooltip: string;
430
+ placeholder: string;
431
+ slidePlaceholder: string;
432
+ empty: string;
433
+ groupSlides: string;
434
+ groupFolders: string;
435
+ groupNavigation: string;
436
+ groupPresent: string;
437
+ groupDeck: string;
438
+ groupExport: string;
439
+ groupPages: string;
440
+ groupAppearance: string;
441
+ groupDeveloper: string;
442
+ /** template: "Page {n}" */
443
+ goToPage: string;
444
+ overview: string;
445
+ designPanel: string;
446
+ backToSlides: string;
447
+ /** template: "Theme: {name}" */
448
+ themeItem: string;
449
+ /** template: "Language: {name}" */
450
+ languageItem: string;
451
+ hintNavigate: string;
452
+ hintSelect: string;
453
+ hintClose: string;
454
+ };
426
455
  themeToggle: {
427
456
  toggleAria: string;
428
457
  title: string;
@@ -1,5 +1,5 @@
1
- import "../types-Di7nvL8V.js";
2
- import { OpenSlideConfig } from "../config-DIvIP8vY.js";
1
+ import "../types-Wz88-Fe1.js";
2
+ import { OpenSlideConfig } from "../config-CYs4WJfL.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-CSgUUnlv.js";
2
+ import { createViteConfig } from "../config-CCHio3pk.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.0",
3
+ "version": "1.18.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": {
@@ -67,10 +67,11 @@
67
67
  "@dnd-kit/utilities": "^3.2.2",
68
68
  "@fontsource-variable/geist": "^5.2.8",
69
69
  "@tailwindcss/vite": "^4.3.3",
70
- "@vitejs/plugin-react": "^6.0.3",
71
- "chalk": "^5.3.0",
70
+ "@vitejs/plugin-react": "^4.3.3",
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",
@@ -78,8 +79,8 @@
78
79
  "html-to-image": "^1.11.13",
79
80
  "lucide-react": "^1.25.0",
80
81
  "next-themes": "^0.4.6",
81
- "react": "^19.2.7",
82
- "react-dom": "^19.2.7",
82
+ "react": "^18.3.1",
83
+ "react-dom": "^18.3.1",
83
84
  "react-image-crop": "^11.0.10",
84
85
  "react-router-dom": "^7.18.1",
85
86
  "shadcn": "^4.12.0",
@@ -88,17 +89,19 @@
88
89
  "tailwindcss": "^4.2.2",
89
90
  "tw-animate-css": "^1.4.0",
90
91
  "use-sync-external-store": "^1.6.0",
91
- "vite": "^8.1.5"
92
+ "vite": "^5.4.10"
92
93
  },
93
94
  "devDependencies": {
95
+ "@playwright/test": "~1.56.1",
94
96
  "@types/node": "^22.19.17",
95
- "@types/react": "^19.2.17",
96
- "@types/react-dom": "^19.2.3",
97
+ "@types/react": "^18.3.12",
98
+ "@types/react-dom": "^18.3.1",
97
99
  "tsdown": "^0.9.9",
98
100
  "typescript": "^5.9.3"
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
+ }