From 399bf9a0b68112fdc921f6ff0405248033025731 Mon Sep 17 00:00:00 2001 From: baseballyama Date: Wed, 28 Oct 2026 12:15:05 +0900 Subject: [PATCH 1/2] feat(editor): hide menu-bar items the editor can never run MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The menu bar listed every item of the reference desktop app's menus and disabled the ones without a counterpart (Print, Share, Macro, SmartArt, the online services, the Window menu …). Those items, the submenus left empty and the Window menu are now left out, and separators no longer double up. Items unavailable only in the current state stay disabled with their reason. Shortcuts still resolve against the full menus, so a hidden item's key does not reach the browser (⌘P does not print the page). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01MNFNHqy4AXFo8fhuoSyzJp --- .../editor-hide-unavailable-menu-items.md | 5 + packages/dev/NATIVE_PARITY.md | 4 +- packages/dev/test/browser/menubar.test.mjs | 474 +----------------- packages/editor/src/EditorApp.svelte | 2 +- packages/editor/src/core/menubar-visible.ts | 37 ++ packages/editor/src/i18n/ja.ts | 44 -- packages/editor/src/ribbon/ArrangeMenu.svelte | 2 +- packages/editor/src/ui/MenuBar.svelte | 8 +- packages/editor/src/ui/menubar-commands.ts | 273 ++++------ packages/editor/test/menubar-visible.test.mjs | 52 ++ 10 files changed, 230 insertions(+), 671 deletions(-) create mode 100644 .changeset/editor-hide-unavailable-menu-items.md create mode 100644 packages/editor/src/core/menubar-visible.ts create mode 100644 packages/editor/test/menubar-visible.test.mjs diff --git a/.changeset/editor-hide-unavailable-menu-items.md b/.changeset/editor-hide-unavailable-menu-items.md new file mode 100644 index 000000000..0eda7d550 --- /dev/null +++ b/.changeset/editor-hide-unavailable-menu-items.md @@ -0,0 +1,5 @@ +--- +'@office-kit/pptx-editor': minor +--- + +The menu bar no longer shows items the editor can never run. Before, it listed every item of the reference desktop app's menus and disabled the ones the editor has no counterpart for, or that a web page cannot do (Print, Share, Export, Macro, SmartArt, the online picture and translation services, the whole Window menu, and so on), so users scanned past dozens of greyed-out entries to find the ones that work. Those items, the submenus left empty and the Window menu are now gone, and separators no longer double up. Items that are unavailable only in the current state (Cut with nothing selected, Symbol outside text, Slide Show without a host that presents) stay, disabled with the reason as their tooltip. The shortcuts of hidden items still do nothing rather than reach the browser, so ⌘P does not print the editor page. diff --git a/packages/dev/NATIVE_PARITY.md b/packages/dev/NATIVE_PARITY.md index 1b1de4d3d..d71273e94 100644 --- a/packages/dev/NATIVE_PARITY.md +++ b/packages/dev/NATIVE_PARITY.md @@ -117,14 +117,14 @@ Measured like the Home ribbon above (AX dumps of the reference desktop app (Mac, Compared with the AX dump of the menu bar of the reference desktop app (Mac, 16.113.3) (every menu and submenu, English and Japanese UI, with nothing selected, a shape selected and text selected). A web page cannot own the macOS menu bar, so the title bar carries the menus in place of the old Edit and View buttons. `core/menubar-native.ts` is generated from the capture: order, separators, submenus, labels and shortcut glyphs are the reference desktop app's in both languages. -- **Menus**: File, Edit, View, Insert, Format, Arrange, Tools, Slide Show, Window and Help. The application menu ("the reference desktop app": About, Settings…, Services, Hide, Quit) is left out: those belong to the browser and the operating system, and the editor's language picker stays in the title bar. Lists that name the capture machine's state are not reproduced: Open Recent keeps only More... ⇧⌘O, and Subtitle Settings ▸ Spoken Language / Subtitle Language / Microphone have no items. Window lists this deck with the reference desktop app's • mark. U+200B in Japanese labels is stripped. +- **Menus**: File, Edit, View, Insert, Format, Arrange, Tools, Slide Show and Help. The application menu ("the reference desktop app": About, Settings…, Services, Hide, Quit) is left out: those belong to the browser and the operating system, and the editor's language picker stays in the title bar. Lists that name the capture machine's state are not reproduced. Items the editor can never run (no counterpart in the editor, or something a web page cannot do: Print, Share, Macro, SmartArt, the online services …) are left out, and so is the Window menu, whose items all belong to the browser; a submenu left empty goes too, and separators do not double up. Their shortcuts still resolve, so ⌘P does not print the page. Items unavailable only in the current state stay, disabled with the reason as their tooltip. U+200B in Japanese labels is stripped. - **Japanese differences**, from the capture: Pick Up Object Style is ⌥⌘C (⇧⌘C in English); the Window menu has a different order; Slide Show has no Rehearse with Coach. Japanese items carry their English item's id, so one command table serves both languages. - **States**: Undo and Repeat name the edit ("Undo Move", "Can't Repeat"); Format ▸ Apply To Defaults becomes Apply Object Style when something is selected; View ▸ Enter Full Screen becomes Exit Full Screen. Every item in the capture's enabled-state table (Cut, Copy, Duplicate, Symbol..., Action Settings..., Hyperlink..., Font..., Paragraph..., Columns..., Alignment ▸, More Options..., Pick Up / Apply Object Style, Format Object..., the stacking order, Rotate or Flip ▸ and Align or Distribute ▸ items) is enabled and checked as the reference desktop app's with nothing, a shape or text selected (Center ✓ for centred text, Align to Slide ✓). While text is being edited, the menus open without taking focus, so the caret and selection stay. A walk of every menu in the three states against the capture found no item enabled where the reference desktop app disables it except View ▸ Enter Full Screen (disabled in the capture, which the reference desktop app had in the background); the editor disables the unsupported items listed below and, with nothing selected, Insert ▸ Date and Time... and Slide Number (they insert a field into a selected text box). - **Commands**: items run the editor's existing commands (the same ones as the ribbon and context menus). Notable mappings: File ▸ Save saves to the project (or downloads outside the development preview) and Save As... downloads; Page Setup... opens Slide Size; Properties... edits the core properties; View ▸ Show Slides toggles the thumbnail pane; Format ▸ More Options... opens Text Options ▸ Text Box; Help ▸ Editor Help opens the command search. Disabled items name the reason as a tooltip. Not available: New from Template, Save as Template, Export, Print, Close, the cloud-storage items (Move, Rename, Version History, Share ▸), Restrict Permissions, Passwords, Always Open Read-Only, Paste Special, Clear, Replace Fonts, Find Next/Previous (use the Find dialog), Rename Section (Home ▸ Section), Handout and Notes Masters, Message Bar, Markup, Slides From ▸, SmartArt ▸, 3D Models ▸, Zoom ▸, Action Buttons ▸, Icons, Equation, Object, Cameo, the online media sources, Bullets and Numbering..., Animation Painter (Animations tab), Theme Colors... (Design ▸ Variants), Spelling, Thesaurus, Translate, Set Proofing Language (Review ▸ Language), AutoCorrect, Macros, Add-ins, Rehearse with Coach, subtitles, the Window menu's window management, and the system items (AutoFill, Start Dictation, Emoji & Symbols). - **Keyboard**: every captured shortcut is bound through the same table the menus display (`core/menubar-shortcuts.ts`) and runs its item whenever the item is enabled. Keys match by physical key, so Option's alternate characters do not matter. Control stands in for Command unless the reference desktop app gives the Control chord its own item (⌃F Advanced Find, ⌃H Replace, ⌃⌘V Paste Special, ⌃⌥⌘G Guides, ⌃⇧⇥ Show Slides), which keeps the editor's Ctrl+Z, Ctrl+T … working. While text is edited on the slide, ⌘ and ⌃ menu shortcuts act on the selected text (⌘L/⌘E/⌘R alignment, ⌘T, ⌘K, ⌥⌘M, the object-style keys, ⌥⇧⌘V Paste and Match Formatting); undo, the clipboard, Select All and ⌘↩ (which ends editing) stay with the text. In other text fields only document-wide commands run (File, the views, Slide Show, Find, New Slide, Help). A disabled item still swallows its ⌘/⌃ key, so ⌘D on text does not bookmark the page. - **Changed keys** (to the reference desktop app's): ⌘G is Find Next, so Group is only ⌥⌘G and Ungroup ⌥⇧⌘G; ⌘K is Insert ▸ Hyperlink, and the command search moved to ⌘? (Help ▸ Editor Help); ⌥⌘C / ⌥⌘V no longer paint formatting in English — Pick Up / Apply Object Style are ⇧⌘C (⌥⌘C in Japanese) / ⇧⌘V; pasting text without formatting is ⌥⇧⌘V (was ⇧⌘V); ⌘H no longer opens Replace (⌃H does). ⌘0 still fits the slide (the status bar names it). - **Keys a page cannot have**: the fn/Globe chords (View ▸ Enter Full Screen 🌐F; Window ▸ Fill 🌐⌃F, Center 🌐⌃C, Return to Previous Size 🌐⌃R) and the dictation/emoji keys never reach a web page. The browser or macOS keeps ⌘N, ⇧⌘N (Chrome's incognito window), ⌘W, ⌘Q, ⌘M, ⌘H, ⌘T (Chrome's new tab) and ⌃⇧⇥ (previous tab) in most browsers, and Chrome may keep ⌘1–⌘5 for tab switching outside the embedded preview; File ▸ New Presentation and Insert ▸ New Slide still run from the menus, and their keys work wherever the browser delivers them. -- Tests: `menubar.test.mjs` asserts all 33 menus and submenus (labels, separators, submenu markers, shortcut glyphs) in English and Japanese against the capture, the enabled and checked states of the capture's state table in the three selection states, and that ⌘D, ⌥⌘G, ⌥⇧⌘G, ⌘T, ⌘K, ⇧⌘1, ⇧⌘C (en) / ⌥⌘C (ja), ⌘L, ⌘E, ⌘4, ⌘1, ⇧⌘N, ⌥⌘R and ⌘? run their commands (and ⌘G and the other language's pick-up key do not). `site/test/menubar-shortcuts.test.mjs` covers glyph parsing, key matching, the Control fallback and the en/ja pairing. +- Tests: `menubar.test.mjs` asserts all 21 menus and submenus the editor shows (labels, separators, submenu markers, shortcut glyphs) in English and Japanese against the capture, the enabled and checked states of the capture's state table in the three selection states, and that ⌘D, ⌥⌘G, ⌥⇧⌘G, ⌘T, ⌘K, ⇧⌘1, ⇧⌘C (en) / ⌥⌘C (ja), ⌘L, ⌘E, ⌘4, ⌘1, ⇧⌘N, ⌥⌘R and ⌘? run their commands (and ⌘G and the other language's pick-up key do not). `site/test/menubar-shortcuts.test.mjs` covers glyph parsing, key matching, the Control fallback and the en/ja pairing. ## Text, table-cell, picture and slide-background menus (2026-10-07) diff --git a/packages/dev/test/browser/menubar.test.mjs b/packages/dev/test/browser/menubar.test.mjs index 172b9f831..4fac91dee 100644 --- a/packages/dev/test/browser/menubar.test.mjs +++ b/packages/dev/test/browser/menubar.test.mjs @@ -18,41 +18,24 @@ import { installRichTextSelection } from '../helpers/rich-text.mjs'; // selected, English and Japanese UI, 2026-10-07): order, separators, submenus // and shortcut glyphs. The application menu is the browser's and is left // out; so are the lists that name the capture machine's state (recent files, -// subtitle languages, microphones). Undo and Repeat name the last edit, and -// the Window menu lists this deck, as the reference desktop app lists its documents. +// subtitle languages, microphones). Undo and Repeat name the last edit. +// Items the editor can never run are left out (menubar-commands.ts HIDDEN), +// with the Window menu, whose items all belong to the browser. const NATIVE = { en: { File: [ 'New Presentation ⌘N', - 'New from Template... ⇧⌘P', 'Open... ⌘O', - 'Open Recent ▸', '----', - 'Close ⌘W', 'Save ⌘S', 'Save As... ⇧⌘S', - 'Save as Template...', - 'Export...', - 'Move...', - 'Rename...', - '----', - 'Browse Version History', - '----', - 'Share ▸', - '----', - 'Always Open Read-Only', - 'Restrict Permissions ▸', - 'Passwords...', '----', 'Compress Pictures...', '----', 'Page Setup...', - 'Print... ⌘P', '----', 'Properties', ], - 'File ▸ Open Recent': ['More... ⇧⌘O'], - 'File ▸ Share': ['Share...', '----', 'Send Presentation', 'Send PDF'], Edit: [ "Can't Undo ⌘Z", "Can't Repeat ⌘Y", @@ -61,36 +44,20 @@ const NATIVE = { 'Copy ⌘C', '----', 'Paste ⌘V', - 'Paste Special... ⌃⌘V', 'Paste and Match Formatting ⌥⇧⌘V', '----', - 'Clear', 'Select All ⌘A', 'Duplicate ⌘D', 'Delete Slide', '----', 'Remove Section', - 'Rename Section', '----', 'Find ▸', 'Select Data...', '----', 'Toggle Drawing ⌃⌘Z', - '----', - 'AutoFill ▸', - 'Start Dictation 🎤', - 'Emoji & Symbols 🌐', - ], - 'Edit ▸ Find': [ - 'Find... ⌘F', - 'Find Next ⌘G', - 'Find Previous ⇧⌘G', - 'Advanced Find... ⌃F', - '----', - 'Replace... ⌃H', - 'Replace Fonts...', ], - 'Edit ▸ AutoFill': ['Contact…', 'Passwords…', 'Credit Card…'], + 'Edit ▸ Find': ['Find... ⌘F', 'Advanced Find... ⌃F', '----', 'Replace... ⌃H'], View: [ 'Normal ⌘1', 'Slide Sorter ⌘2', @@ -105,11 +72,8 @@ const NATIVE = { 'Master ▸', '----', 'Ribbon ⌥⌘R', - 'Message Bar', '----', 'Header and Footer...', - 'Markup', - 'Advanced Markup', '----', 'Ruler', 'Grid and Guides ▸', @@ -130,7 +94,6 @@ const NATIVE = { Insert: [ 'New Slide ⇧⌘N', 'Duplicate Slide ⇧⌘D', - 'Slides From ▸', '----', 'Section', 'Comment ⇧⌘M', @@ -142,110 +105,33 @@ const NATIVE = { '----', 'Table...', 'Chart ▸', - 'SmartArt ▸', '----', 'Picture ▸', 'Audio ▸', 'Video ▸', - 'Cameo', - 'Equation', 'Symbol...', 'Shape ▸', '----', - 'Icons...', - '----', - '3D Models ▸', - '----', - 'Zoom ▸', - '----', - 'Action Buttons ▸', 'Action Settings...', '----', - 'Object...', 'Hyperlink... ⌘K', ], - 'Insert ▸ Slides From': ['Reuse Slides...', 'Outline...'], - 'Insert ▸ Chart': [ - 'Column', - 'Bar', - 'Line', - 'Area', - 'Pie', - 'Treemap', - 'Sunburst', - 'Histogram', - 'Pareto', - 'Box and Whisker', - 'X Y (Scatter)', - 'Waterfall', - 'Funnel', - 'Stock', - 'Surface', - 'Radar', - 'Filled Map', - ], - 'Insert ▸ SmartArt': [ - 'List', - 'Process', - 'Cycle', - 'Hierarchy', - 'Relationship', - 'Matrix', - 'Pyramid', - 'Picture', - 'Timeline', - 'Meet The Team', - 'Text Card', - ], - 'Insert ▸ Picture': [ - 'Photo Browser…', - 'Picture from File...', - 'Stock Images...', - 'Online Pictures...', - 'Brand Images...', - ], - 'Insert ▸ Audio': ['Audio Browser...', 'Audio from File...', '----', 'Record Audio...'], - 'Insert ▸ Video': [ - 'Movie Browser...', - 'Movie from File...', - 'Stock Videos...', - 'Online Movie...', - ], + 'Insert ▸ Chart': ['Column', 'Bar', 'Line', 'Area', 'Pie', 'Radar'], + 'Insert ▸ Picture': ['Picture from File...'], + 'Insert ▸ Audio': ['Audio from File...'], + 'Insert ▸ Video': ['Movie from File...'], 'Insert ▸ Shape': ['Rectangle', 'Rounded Rectangle', 'Triangle', 'Oval', 'Line'], - 'Insert ▸ 3D Models': ['Insert 3D Model From', 'Stock 3D Models...', 'This Device...'], - 'Insert ▸ Zoom': ['Summary Zoom', 'Section Zoom', 'Slide Zoom'], - 'Insert ▸ Action Buttons': [ - 'Action Buttons', - 'Back or Previous', - 'Forward or Next', - 'Beginning', - 'End', - 'Home', - 'Information', - 'Return', - 'Movie', - 'Document', - 'Sound', - 'Help', - 'Custom', - ], Format: [ 'Font... ⌘T', 'Paragraph... ⌥⌘M', '----', - 'Bullets and Numbering...', - '----', 'Columns...', 'Alignment ▸', 'More Options...', '----', 'Pick Up Object Style ⇧⌘C', 'Apply To Defaults ⇧⌘V', - 'Animation Painter ⌥⇧⌘C', '----', - 'Replace Fonts...', - '----', - 'Theme Colors...', 'Slide Background... ⇧⌘2', '----', 'Crop ⇧C', @@ -260,7 +146,6 @@ const NATIVE = { 'Distributed', ], Arrange: [ - 'Reorder Objects', 'Reorder Overlapping Objects', '----', 'Bring to Front ⇧⌘F', @@ -299,140 +184,36 @@ const NATIVE = { 'Align to Slide', 'Align Selected Objects', ], - Tools: [ - 'Spelling...', - 'Thesaurus... ⌃⌥⌘R', - 'Translate...', - 'Set Proofing Language...', - 'AutoCorrect Options...', - '----', - 'Check Accessibility', - '----', - 'Macro ▸', - 'Add-ins...', - ], - 'Tools ▸ Macro': ['Macros...', 'Visual Basic Editor'], + Tools: ['Check Accessibility'], 'Slide Show': [ 'Play from Start ⇧⌘↩', 'Play from Current Slide ⌘↩', '----', 'Custom Slide Show ▸', '----', - 'Rehearse with Coach', - '----', 'Presenter View ⌥↩', 'Rehearse Timings', 'Record Slide Show', '----', 'Hide Slide', 'Set Up Show...', - '----', - 'Always Use Subtitles', - 'Subtitle Settings ▸', - ], - 'Slide Show ▸ Subtitle Settings': [ - 'Spoken Language ▸', - 'Subtitle Language ▸', - '----', - 'Microphone ▸', - '----', - 'Bottom (Overlaid)', - 'Top (Overlaid)', - 'Below Slide', - 'Above Slide', - '----', - 'System Caption Preferences...', - ], - Window: [ - 'Minimize ⌘M', - 'Minimize All', - 'Zoom', - 'Zoom All', - 'Fill 🌐⌃F', - 'Center 🌐⌃C', - '----', - 'Move & Resize ▸', - 'Full Screen Tile', - '----', - 'Remove Window from Set', - '----', - 'New Window', - 'Arrange All', - 'Next Pane', - '----', - 'Bring All to Front', - 'Arrange in Front', - '----', - 'deck', - ], - 'Window ▸ Move & Resize': [ - 'Halves', - 'Left', - 'Right', - 'Top', - 'Bottom', - '----', - 'Quarters', - 'Top Left', - 'Top Right', - 'Bottom Left', - 'Bottom Right', - '----', - 'Arrange', - 'Left & Right', - 'Left & Quarters', - 'Right & Left', - 'Right & Quarters', - 'Top & Bottom', - 'Top & Quarters', - 'Bottom & Top', - 'Bottom & Quarters', - 'Quarters', - '----', - 'Return to Previous Size 🌐⌃R', - ], - Help: [ - 'Editor Help ⌘?', - '----', - 'Feedback', - '----', - 'Clear Application Data', - '----', - 'Check for Updates', ], + Help: ['Editor Help ⌘?', '----', 'Feedback'], }, ja: { ファイル: [ '新規作成 ⌘N', - 'テンプレートから新規作成... ⇧⌘P', '開く... ⌘O', - '最近使ったファイル ▸', '----', - '閉じる ⌘W', '保存 ⌘S', '名前を付けて保存... ⇧⌘S', - 'テンプレートとして保存...', - 'エクスポート...', - '移動...', - '名前の変更...', - '----', - 'バージョン履歴の表示', - '----', - '共有 ▸', - '----', - '常に読み取り専用で開く', - 'アクセスの制限 ▸', - 'パスワード...', '----', '図の圧縮...', '----', 'ページ設定...', - 'プリント... ⌘P', '----', 'プロパティ', ], - 'ファイル ▸ 最近使ったファイル': ['その他... ⇧⌘O'], - 'ファイル ▸ 共有': ['共有...', '----', 'プレゼンテーションを送信', 'PDF を送信'], 編集: [ '元に戻せません ⌘Z', '繰り返しできません ⌘Y', @@ -441,36 +222,20 @@ const NATIVE = { 'コピー ⌘C', '----', 'ペースト ⌘V', - '形式を選択してペースト... ⌃⌘V', 'ペーストしてスタイルを合わせる ⌥⇧⌘V', '----', - 'クリア', 'すべてを選択 ⌘A', '複製 ⌘D', 'スライドの削除', '----', 'セクションの削除', - 'セクション名の変更', '----', '検索 ▸', 'データの選択...', '----', '描画の切り替え ⌃⌘Z', - '----', - '自動入力 ▸', - '音声入力を開始 🎤', - '絵文字と記号 🌐', - ], - '編集 ▸ 検索': [ - '検索... ⌘F', - '次を検索 ⌘G', - '前を検索 ⇧⌘G', - '高度な検索... ⌃F', - '----', - '置換... ⌃H', - 'フォントの置換...', ], - '編集 ▸ 自動入力': ['連絡先…', 'パスワード…', 'クレジットカード…'], + '編集 ▸ 検索': ['検索... ⌘F', '高度な検索... ⌃F', '----', '置換... ⌃H'], 表示: [ '標準 ⌘1', 'スライド一覧 ⌘2', @@ -485,11 +250,8 @@ const NATIVE = { 'マスター ▸', '----', 'リボン ⌥⌘R', - 'メッセージ バー', '----', 'ヘッダーとフッター...', - 'コメントと注釈', - '高度なマークアップ', '----', 'ルーラー', 'グリッドとガイド ▸', @@ -516,7 +278,6 @@ const NATIVE = { 挿入: [ '新しいスライド ⇧⌘N', 'スライドの複製 ⇧⌘D', - 'スライドの指定 ▸', '----', 'セクション', 'コメント ⇧⌘M', @@ -528,115 +289,33 @@ const NATIVE = { '----', '表...', 'グラフ ▸', - 'SmartArt ▸', '----', '画像 ▸', 'オーディオ ▸', 'ビデオ ▸', - 'レリーフ', - '数式', '記号/文字...', '図形 ▸', '----', - 'アイコン...', - '----', - '3D モデル ▸', - '----', - 'ズーム ▸', - '----', - '動作設定ボタン ▸', 'オブジェクトの動作設定...', '----', - 'オブジェクト...', 'ハイパーリンク... ⌘K', ], - '挿入 ▸ スライドの指定': ['スライドの再利用...', 'アウトライン表示...'], - '挿入 ▸ グラフ': [ - '縦棒', - '横棒', - '折れ線', - '面', - '円', - 'ツリーマップ', - 'サンバースト', - 'ヒストグラム', - 'パレート図', - '箱ひげ図', - '散布図', - 'ウォーターフォール', - 'じょうご', - '株価', - '等高線', - 'レーダー', - '塗り分けマップ', - ], - '挿入 ▸ SmartArt': [ - 'リスト', - '手順', - '循環', - '階層構造', - '集合関係', - 'マトリックス', - 'ピラミッド', - '図', - 'タイムライン', - 'チームに会う', - 'テキスト カード', - ], - '挿入 ▸ 画像': [ - '写真ブラウザー…', - '画像をファイルから挿入...', - 'ストック画像...', - 'オンライン画像...', - 'ブランド イメージ...', - ], - '挿入 ▸ オーディオ': [ - 'サウンド ブラウザー...', - 'オーディーをファイルから挿入...', - '----', - 'オーディオの録音...', - ], - '挿入 ▸ ビデオ': [ - 'ムービー ブラウザー...', - 'ファイルからムービー...', - 'ストック ビデオ...', - 'オンライン ビデオ...', - ], + '挿入 ▸ グラフ': ['縦棒', '横棒', '折れ線', '面', '円', 'レーダー'], + '挿入 ▸ 画像': ['画像をファイルから挿入...'], + '挿入 ▸ オーディオ': ['オーディーをファイルから挿入...'], + '挿入 ▸ ビデオ': ['ファイルからムービー...'], '挿入 ▸ 図形': ['正方形/長方形', '角丸四角形', '三角形', '円/楕円', '線'], - '挿入 ▸ 3D モデル': ['3D モデルを挿入', '3D モデルのストック...', 'このデバイス...'], - '挿入 ▸ ズーム': ['サマリー ズーム', 'セクション ズーム', 'スライド ズーム'], - '挿入 ▸ 動作設定ボタン': [ - '動作設定ボタン', - '戻る/前へ', - '進む/次へ', - '先頭', - '終了', - 'ホーム', - '情報', - 'Return キー', - 'ムービー', - '文書', - 'サウンド', - 'ヘルプ', - 'ユーザー定義', - ], フォーマット: [ 'フォント... ⌘T', '段落... ⌥⌘M', '----', - '箇条書きと段落番号...', - '----', '段組み...', '配置 ▸', 'その他のオプション...', '----', 'オブジェクト スタイルのコピー ⌥⌘C', '標準に適用 ⇧⌘V', - 'アニメーションのコピー/貼り付け ⌥⇧⌘C', '----', - 'フォントの置換...', - '----', - 'テーマの配色...', 'スライドの背景... ⇧⌘2', '----', 'トリミング ⇧C', @@ -645,7 +324,6 @@ const NATIVE = { ], 'フォーマット ▸ 配置': ['左揃え ⌘L', '中央揃え ⌘E', '右揃え ⌘R', '両端揃え', '均等割り付け'], 配置: [ - 'オブジェクトの並べ替え', '重なり合ったオブジェクトの並べ替え', '----', '最前面へ移動 ⇧⌘F', @@ -684,19 +362,7 @@ const NATIVE = { 'スライドに合わせて配置', '選択したオブジェクトの配置', ], - ツール: [ - 'スペル チェック...', - '類義語辞典... ⌃⌥⌘R', - '翻訳...', - '校正言語の設定...', - 'オートコレクトのオプション...', - '----', - 'アクセシビリティ チェック', - '----', - 'マクロ ▸', - 'アドイン', - ], - 'ツール ▸ マクロ': ['マクロ...', 'Visual Basic Editor'], + ツール: ['アクセシビリティ チェック'], 'スライド ショー': [ '最初から再生 ⇧⌘↩', '現在のスライドから再生 ⌘↩', @@ -709,80 +375,8 @@ const NATIVE = { '----', '非表示スライドに設定', 'スライド ショーの設定...', - '----', - '常に字幕を使用する', - '字幕の設定 ▸', - ], - 'スライド ショー ▸ 字幕の設定': [ - '話し手の言語 ▸', - '字幕の言語 ▸', - '----', - 'マイク ▸', - '----', - '下部 (重ねて表示)', - '上部 (重ねて表示)', - 'スライドの下', - 'スライドの上', - '----', - 'システムのキャプション設定...', - ], - ウィンドウ: [ - 'しまう ⌘M', - 'ズーム', - '----', - '新しいウインドウを開く', - 'ウインドウの整列', - '次のペイン', - '----', - 'すべてを手前に移動', - 'すべてをしまう', - 'すべてを拡大/縮小', - '画面全体に表示 🌐⌃F', - '中央に配置 🌐⌃C', - '----', - '移動とサイズ変更 ▸', - 'フルスクリーンのタイル表示', - '----', - 'ウインドウをセットから削除', - 'ウインドウを整理', - '----', - 'deck', - ], - 'ウィンドウ ▸ 移動とサイズ変更': [ - '2分割', - '左', - '右', - '上', - '下', - '----', - '4分割', - '左上', - '右上', - '左下', - '右下', - '----', - '配置', - '左と右', - '左と4分割', - '右と左', - '右と4分割', - '上と下', - '上と4分割', - '下と上', - '下と4分割', - '4分割', - '----', - '前のサイズに戻す 🌐⌃R', - ], - ヘルプ: [ - 'エディター ヘルプ ⌘?', - '----', - 'フィードバック', - '----', - 'アプリケーション データのクリア', - '----', - '更新プログラムのチェック', ], + ヘルプ: ['エディター ヘルプ ⌘?', '----', 'フィードバック'], }, }; @@ -798,18 +392,7 @@ export default ( `; const SHOTS = process.env.MENUBAR_SHOTS; const TITLES = { - en: [ - 'File', - 'Edit', - 'View', - 'Insert', - 'Format', - 'Arrange', - 'Tools', - 'Slide Show', - 'Window', - 'Help', - ], + en: ['File', 'Edit', 'View', 'Insert', 'Format', 'Arrange', 'Tools', 'Slide Show', 'Help'], ja: [ 'ファイル', '編集', @@ -819,7 +402,6 @@ const TITLES = { '配置', 'ツール', 'スライド ショー', - 'ウィンドウ', 'ヘルプ', ], }; @@ -873,11 +455,6 @@ const STATES = [ ['View ▸ Master ▸ Handout Master', 'on', 'on', 'on'], ['View ▸ Master ▸ Notes Master', 'on', 'on', 'on'], ]; -// The editor cannot run these yet; they stay disabled with the reason. -const UNSUPPORTED = new Map([ - ['Format ▸ Bullets and Numbering...', 'The editor has no Bullets and Numbering dialog yet.'], - ['Tools ▸ Thesaurus...', 'The thesaurus needs an online reference service.'], -]); async function open(file) { const preview = await startPreview(file); @@ -993,12 +570,12 @@ test( await closeMenus(editor); } // A disabled item names the reason. - const tools = await openPath(editor, ['ツール']); + const insert = await openPath(editor, ['挿入']); assert.equal( - await tools - .getByRole('menuitem', { name: '類義語辞典...', exact: true }) + await insert + .getByRole('menuitem', { name: '記号/文字...', exact: true }) .getAttribute('title'), - '類義語辞典にはオンラインの参照サービスが必要です。', + '記号を挿入するには、文字列内にカーソルを置いてください。', ); await closeMenus(editor); // The dev tool turns Help ▸ Feedback on through the internal mount (the @@ -1064,13 +641,6 @@ test( STATES.map((row) => [row[0], row[index + 1]]), name, ); - for (const [path, reason] of UNSUPPORTED) { - const menu = await openPath(editor, path.split(' ▸ ').slice(0, -1)); - const item = menu.getByRole('menuitem', { name: path.split(' ▸ ').at(-1), exact: true }); - assert.equal(await item.isDisabled(), true, path); - assert.equal(await item.getAttribute('title'), reason); - await closeMenus(editor); - } if (name === 'text') { // The menus leave the caret and selection in the text. assert.deepEqual( diff --git a/packages/editor/src/EditorApp.svelte b/packages/editor/src/EditorApp.svelte index 2d6a2c05e..24b82885a 100644 --- a/packages/editor/src/EditorApp.svelte +++ b/packages/editor/src/EditorApp.svelte @@ -141,7 +141,7 @@ // Undo, Repeat, the clipboard and Select All keep their keys from the // menu bar's table, so they follow the reference desktop app's shortcuts exactly. - const menuKey = menuItemForKey(nativeMenus(editor), e)?.id; + const menuKey = menuItemForKey(nativeMenus(), e)?.id; if (menuKey === 'edit/undo') { e.preventDefault(); doc.undo(); diff --git a/packages/editor/src/core/menubar-visible.ts b/packages/editor/src/core/menubar-visible.ts new file mode 100644 index 000000000..4c384c256 --- /dev/null +++ b/packages/editor/src/core/menubar-visible.ts @@ -0,0 +1,37 @@ +import type { NativeMenu, NativeMenuEntry } from './menubar-native.ts'; + +/** + * The menus without the items `hide` names. A submenu left with no items goes + * too, as does a menu, and separators never lead, trail or double up. + */ +export function pruneMenus( + menus: readonly NativeMenu[], + hide: (id: string) => boolean, +): readonly NativeMenu[] { + return menus + .filter((menu) => !hide(menu.id)) + .map((menu) => ({ ...menu, items: pruneEntries(menu.items, hide) })) + .filter((menu) => menu.items.length > 0); +} + +function pruneEntries( + entries: readonly NativeMenuEntry[], + hide: (id: string) => boolean, +): readonly NativeMenuEntry[] { + const out: NativeMenuEntry[] = []; + for (const entry of entries) { + if (entry === '-') { + if (out.length > 0 && out.at(-1) !== '-') out.push(entry); + continue; + } + if (hide(entry.id)) continue; + if (!entry.children?.length) { + out.push(entry); + continue; + } + const children = pruneEntries(entry.children, hide); + if (children.length > 0) out.push({ ...entry, children }); + } + if (out.at(-1) === '-') out.pop(); + return out; +} diff --git a/packages/editor/src/i18n/ja.ts b/packages/editor/src/i18n/ja.ts index 6cd5aebf2..eb3c0fa83 100644 --- a/packages/editor/src/i18n/ja.ts +++ b/packages/editor/src/i18n/ja.ts @@ -2152,64 +2152,20 @@ export const ja: Record = { 'Search (⌘?)': '検索 (⌘?)', "Can't Undo": '元に戻せません', "Can't Repeat": '繰り返しできません', - 'The editor has no template gallery.': 'このエディタにはテンプレート ギャラリーがありません。', - 'The browser keeps no list of recent files.': - 'ブラウザーは最近使ったファイルの一覧を保持しません。', - 'Close the browser tab to close the presentation.': - 'プレゼンテーションを閉じるには、ブラウザーのタブを閉じてください。', - 'The editor cannot save templates.': 'このエディタではテンプレートを保存できません。', - 'Export to other formats is not available in this editor.': - 'このエディタでは他の形式へのエクスポートを利用できません。', - 'The editor cannot mark a file read-only.': - 'このエディタではファイルを読み取り専用に設定できません。', - 'Restricting permissions needs a rights management service.': - 'アクセスの制限には権利管理サービスが必要です。', - 'Password protection is not available in this editor.': - 'このエディタではパスワード保護を利用できません。', - 'Printing is not available in this editor.': 'このエディタでは印刷を利用できません。', 'Paste and Match Formatting pastes into text being edited.': '[ペーストしてスタイルを合わせる] は編集中の文字列にペーストします。', - 'Press Delete to remove the selection.': - '選択したものを削除するには Delete キーを押してください。', 'The current slide is not in a section.': '現在のスライドはセクションに含まれていません。', - 'Rename sections from Home ▸ Section.': - 'セクション名は [ホーム] ▸ [セクション] から変更してください。', - 'Use Next match and Previous match in the Find dialog.': - '検索ダイアログの [次の一致] と [前の一致] を使ってください。', - 'The editor has no Replace Fonts dialog yet.': - 'このエディタにはまだ [フォントの置換] ダイアログがありません。', - 'The editor has no message bar.': 'このエディタにはメッセージ バーがありません。', 'The browser does not allow full screen here.': 'ここではブラウザーが全画面表示を許可していません。', 'Place the cursor in text to insert a symbol.': '記号を挿入するには、文字列内にカーソルを置いてください。', - 'Use Animations ▸ Animation Painter.': - '[アニメーション] ▸ [アニメーションのコピー/貼り付け] を使ってください。', - 'Choose theme colors from Design ▸ Variants.': - 'テーマの配色は [デザイン] ▸ [バリエーション] から選んでください。', - 'Choose the proofing language from Review ▸ Language.': - '校正言語は [校閲] ▸ [言語] から選んでください。', - 'AutoCorrect is not available in this editor.': - 'このエディタではオートコレクトを利用できません。', 'The presentation has no custom shows.': 'このプレゼンテーションには目的別スライド ショーがありません。', - 'The editor keeps no application data to clear.': - 'このエディタには消去するアプリケーション データがありません。', - 'The editor updates with its npm package.': 'このエディタは npm パッケージと一緒に更新されます。', - 'Needs a presentation saved to cloud storage.': - 'クラウド ストレージに保存されたプレゼンテーションが必要です。', - 'The browser manages its own windows.': 'ウインドウはブラウザーが管理します。', 'The slide show runs in the preview page around the editor.': 'スライド ショーはエディタを囲むプレビュー ページで実行されます。', 'Press ⌘V to paste into the outline.': 'アウトラインにペーストするには ⌘V を押してください。', 'Edit the text on the slide to use this.': 'これを使うには、スライド上の文字列を編集してください。', - 'Importing slides from another file is not available in this editor.': - 'このエディタでは他のファイルからスライドを取り込めません。', - 'Action buttons are not in the editor’s shape gallery yet.': - '動作設定ボタンはまだエディタの図形ギャラリーにありません。', - 'macOS provides this to native apps, not to web pages.': - 'これは macOS がネイティブ アプリに提供する機能で、Web ページでは使えません。', // View ▸ masters, Notes Page and the status bar (the reference desktop app (Mac, 16), Japanese UI). 'Notes {n} of {count}': 'ノート {n} / {count}', 'Currently in Slide Master View.': '現在のモード: スライド マスター表示', diff --git a/packages/editor/src/ribbon/ArrangeMenu.svelte b/packages/editor/src/ribbon/ArrangeMenu.svelte index 9bac32609..dc959efa5 100644 --- a/packages/editor/src/ribbon/ArrangeMenu.svelte +++ b/packages/editor/src/ribbon/ArrangeMenu.svelte @@ -36,7 +36,7 @@ return { destroy() { window.removeEventListener('resize', position); } }; } function keys(event: KeyboardEvent) { - if (!event.isComposing && menuItemForKey(nativeMenus(editor), event)) { close(false); return; } + if (!event.isComposing && menuItemForKey(nativeMenus(), event)) { close(false); return; } event.stopPropagation(); if (event.key === 'Escape') { event.preventDefault(); close(); return; } if (event.key === 'Tab') { close(false); return; } diff --git a/packages/editor/src/ui/MenuBar.svelte b/packages/editor/src/ui/MenuBar.svelte index 4b6e8b681..ec8dd1624 100644 --- a/packages/editor/src/ui/MenuBar.svelte +++ b/packages/editor/src/ui/MenuBar.svelte @@ -10,12 +10,12 @@ import type { NativeMenuEntry, NativeMenuItem } from '../core/menubar-native.ts'; import { menuItemForKey } from '../core/menubar-shortcuts.ts'; import { t } from '../i18n/i18n.svelte.ts'; - import { menuCommand, nativeMenus, runMenuKey, type MenuHost } from './menubar-commands.ts'; + import { menuCommand, nativeMenus, runMenuKey, visibleMenus, type MenuHost } from './menubar-commands.ts'; import TextColumnsDialog from './TextColumnsDialog.svelte'; let { file }: { file: Pick } = $props(); const editor = getEditor(); - const menus = $derived(nativeMenus(editor)); + const menus = $derived(visibleMenus(editor)); let openMenu = $state(null); /** Open submenus by depth, outermost first. */ let path = $state([]); @@ -92,7 +92,7 @@ function onMenuKeydown(event: KeyboardEvent, depth: number) { // Shortcuts close the menu and run, as they do over a native menu. - if (menuItemForKey(menus, event)) return; + if (menuItemForKey(nativeMenus(), event)) return; event.stopPropagation(); const target = event.target as HTMLElement; const menu = target.closest('.menu'); @@ -210,7 +210,7 @@ onmousedown={(event) => { if (keepFocus) event.preventDefault(); }} onpointerenter={() => enter(entry, depth)} onclick={() => choose(entry)} - >{name}{#if entry.shortcut}{entry.shortcut}{/if} + >{name}{#if entry.shortcut}{entry.shortcut}{/if} {/if} {/if} {/each} diff --git a/packages/editor/src/ui/menubar-commands.ts b/packages/editor/src/ui/menubar-commands.ts index cb46d5785..0bec054a1 100644 --- a/packages/editor/src/ui/menubar-commands.ts +++ b/packages/editor/src/ui/menubar-commands.ts @@ -1,7 +1,8 @@ // What each menu-bar item does, keyed by the ids in core/menubar-native.ts. -// Every item reaches an existing editor command; items the editor cannot -// perform are disabled with the reason as their tooltip. The same lookup -// drives both the menus and their keyboard shortcuts. +// Every item reaches an existing editor command. Items the editor can never +// perform are left out of the menus; items unavailable in the current state +// are disabled with the reason as their tooltip. The same lookup drives both +// the menus and their keyboard shortcuts. import { getShapeKind, @@ -16,6 +17,7 @@ import { eventTarget } from '../core/dom-root.ts'; import { insertMedia } from '../core/insert-objects.ts'; import { APPLY_TO_DEFAULTS, NATIVE_MENUBAR, type NativeMenu } from '../core/menubar-native.ts'; import { menuItemForKey, parseShortcut, isModifiedChord } from '../core/menubar-shortcuts.ts'; +import { pruneMenus } from '../core/menubar-visible.ts'; import { alignParagraphs, canAlignParagraphs, @@ -45,8 +47,6 @@ export interface MenuCommand { readonly radio?: boolean; /** Replaces the native label, already localized (Edit ▸ Undo …). */ readonly label?: string; - /** The reference desktop app's window-list bullet rather than a check mark. */ - readonly bullet?: boolean; } /** What only the title bar can do: it owns the file input and the host's save. */ @@ -65,35 +65,10 @@ export interface MenuHost { const FEEDBACK = 'help/feedback'; -// Help ▸ Feedback and the separator before it. Only the internal dev mount -// gives the editor a feedback URL; every other host gets these menus. -function withoutFeedback(menus: readonly NativeMenu[]): readonly NativeMenu[] { - return menus.map((menu) => { - const at = menu.items.findIndex((item) => item !== '-' && item.id === FEEDBACK); - if (at < 0) return menu; - return { ...menu, items: menu.items.filter((_, index) => index !== at && index !== at - 1) }; - }); -} - -const MENUS_WITHOUT_FEEDBACK = { - en: withoutFeedback(NATIVE_MENUBAR.en), - ja: withoutFeedback(NATIVE_MENUBAR.ja), -}; - -export function nativeMenus(editor: EditorController): readonly NativeMenu[] { - return (editor.feedbackUrl === undefined ? MENUS_WITHOUT_FEEDBACK : NATIVE_MENUBAR)[getLocale()]; -} - const unavailable = (reason: string): MenuCommand => ({ disabled: true, reason }); // Reasons shared by several items. -const NO_CLOUD = 'Needs a presentation saved to cloud storage.'; -const WINDOWS = 'The browser manages its own windows.'; -const SUBTITLES = 'Live subtitles need an online service.'; const SLIDE_SHOW_HOST = 'The slide show runs in the preview page around the editor.'; -const ONLINE = 'Online pictures need an online image service.'; -const MEDIA_LIBRARY = 'The Photos and Music libraries are not available in the browser.'; -const OS_TEXT_SERVICE = 'macOS provides this to native apps, not to web pages.'; const OUTLINE_PASTE = 'Press ⌘V to paste into the outline.'; const SLIDE_TEXT = 'Edit the text on the slide to use this.'; @@ -157,21 +132,106 @@ const PARAGRAPH_ALIGN: Readonly> = { 'format/alignment/distributed': 'distribute', }; -// Whole submenus the editor has no counterpart for. -const UNAVAILABLE_GROUPS: readonly (readonly [string, string])[] = [ - ['file/share/', NO_CLOUD], - ['edit/autofill/', OS_TEXT_SERVICE], - ['insert/slides-from/', 'Importing slides from another file is not available in this editor.'], - ['insert/smartart/', 'SmartArt is not supported by the library yet.'], - ['insert/3d-models/', '3D models are not supported by the library yet.'], - ['insert/zoom/', 'Slide zoom is not supported by the library yet.'], - ['insert/action-buttons/', 'Action buttons are not in the editor’s shape gallery yet.'], - ['insert/chart/', 'This chart type is not supported by the library yet.'], - ['tools/macro/', 'Macros (VBA) do not run in this editor.'], - ['slide-show/subtitle-settings/', SUBTITLES], - ['window/', WINDOWS], +// Items the editor can never perform: it has no counterpart, or a browser +// page cannot do them. They stay out of the menus. +const HIDDEN = new Set([ + 'file/new-from-template', + 'file/close', + 'file/save-as-template', + 'file/export', + 'file/move', + 'file/rename', + 'file/browse-version-history', + 'file/always-open-read-only', + 'file/restrict-permissions', + 'file/passwords', + 'file/print', + 'edit/paste-special', + 'edit/clear', + 'edit/rename-section', + 'edit/find/find-next', + 'edit/find/find-previous', + 'edit/find/replace-fonts', + 'edit/start-dictation', + 'edit/emoji-and-symbols', + 'view/message-bar', + 'view/markup', + 'view/advanced-markup', + 'insert/picture/photo-browser', + 'insert/picture/stock-images', + 'insert/picture/online-pictures', + 'insert/picture/brand-images', + 'insert/audio/audio-browser', + 'insert/audio/record-audio', + 'insert/video/movie-browser', + 'insert/video/stock-videos', + 'insert/video/online-movie', + 'insert/cameo', + 'insert/equation', + 'insert/icons', + 'insert/object', + 'format/bullets-and-numbering', + 'format/animation-painter', + 'format/replace-fonts', + 'format/theme-colors', + 'arrange/reorder-objects', + 'tools/spelling', + 'tools/thesaurus', + 'tools/translate', + 'tools/set-proofing-language', + 'tools/autocorrect-options', + 'tools/add-ins', + 'slide-show/rehearse-with-coach', + 'slide-show/always-use-subtitles', + 'help/clear-application-data', + 'help/check-for-updates', +]); + +// Whole submenus (and the Window menu) the editor has no counterpart for. +const HIDDEN_GROUPS = [ + 'file/open-recent', + 'file/share', + 'edit/autofill', + 'insert/slides-from', + 'insert/smartart', + 'insert/3d-models', + 'insert/zoom', + 'insert/action-buttons', + 'tools/macro', + 'slide-show/subtitle-settings', + 'window', ]; +function isHidden(id: string): boolean { + if (HIDDEN.has(id)) return true; + if (id.startsWith('insert/chart/')) return !(id in CHARTS); + return HIDDEN_GROUPS.some((group) => id === group || id.startsWith(`${group}/`)); +} + +// Help ▸ Feedback is only there when the host gives the editor a feedback URL +// (the internal dev mount does). +const MENUS = { + en: pruneMenus(NATIVE_MENUBAR.en, isHidden), + ja: pruneMenus(NATIVE_MENUBAR.ja, isHidden), +}; +const MENUS_WITHOUT_FEEDBACK = { + en: pruneMenus(MENUS.en, (id) => id === FEEDBACK), + ja: pruneMenus(MENUS.ja, (id) => id === FEEDBACK), +}; + +/** The menus the menu bar shows. */ +export function visibleMenus(editor: EditorController): readonly NativeMenu[] { + return (editor.feedbackUrl === undefined ? MENUS_WITHOUT_FEEDBACK : MENUS)[getLocale()]; +} + +/** + * Every menu item, for keyboard shortcuts: a hidden item's shortcut still + * resolves, so the browser does not act on it (⌘P would print the page). + */ +export function nativeMenus(): readonly NativeMenu[] { + return NATIVE_MENUBAR[getLocale()]; +} + /** The command behind a menu-bar item in the editor's current state. */ export function menuCommand(editor: EditorController, host: MenuHost, id: string): MenuCommand { const doc = editor.doc; @@ -188,6 +248,7 @@ export function menuCommand(editor: EditorController, host: MenuHost, id: string const present = (action: Parameters[0]): MenuCommand => editor.canPresent ? { run: () => editor.present(action) } : unavailable(SLIDE_SHOW_HOST); + if (isHidden(id)) return { disabled: true }; if (id in VIEWS) { const mode = VIEWS[id]!; return { @@ -253,41 +314,16 @@ export function menuCommand(editor: EditorController, host: MenuHost, id: string // File case 'file/new-presentation': return { run: host.newPresentation }; - case 'file/new-from-template': - return unavailable('The editor has no template gallery.'); case 'file/open': return { run: host.open }; - case 'file/open-recent': - return {}; - case 'file/open-recent/more': - return unavailable('The browser keeps no list of recent files.'); - case 'file/close': - return unavailable('Close the browser tab to close the presentation.'); case 'file/save': return { run: host.save }; case 'file/save-as': return { run: host.download }; - case 'file/save-as-template': - return unavailable('The editor cannot save templates.'); - case 'file/export': - return unavailable('Export to other formats is not available in this editor.'); - case 'file/move': - case 'file/rename': - case 'file/browse-version-history': - case 'file/share': - return id === 'file/share' ? {} : unavailable(NO_CLOUD); - case 'file/always-open-read-only': - return unavailable('The editor cannot mark a file read-only.'); - case 'file/restrict-permissions': - return unavailable('Restricting permissions needs a rights management service.'); - case 'file/passwords': - return unavailable('Password protection is not available in this editor.'); case 'file/compress-pictures': return { run: () => (editor.activeDialog = 'compressPictures') }; case 'file/page-setup': return run('setSlideSize'); - case 'file/print': - return unavailable('Printing is not available in this editor.'); case 'file/properties': return run('setCoreProperties'); @@ -322,15 +358,9 @@ export function menuCommand(editor: EditorController, host: MenuHost, id: string case 'edit/paste': if (!text) return { run: () => void editor.paste() }; return text.clipboard ? { run: () => text.clipboard!('paste') } : unavailable(OUTLINE_PASTE); - case 'edit/paste-special': - return unavailable( - 'Paste Special needs the system clipboard formats, which the browser does not expose.', - ); case 'edit/paste-and-match-formatting': if (!text) return unavailable('Paste and Match Formatting pastes into text being edited.'); return text.pastePlain ? { run: text.pastePlain } : unavailable(OUTLINE_PASTE); - case 'edit/clear': - return unavailable('Press Delete to remove the selection.'); case 'edit/select-all': return { disabled: !slide, @@ -350,30 +380,16 @@ export function menuCommand(editor: EditorController, host: MenuHost, id: string doc.transact(t('Remove Section'), () => removeSection(doc.pres, section.start)), } : unavailable('The current slide is not in a section.'); - case 'edit/rename-section': - return unavailable( - section ? 'Rename sections from Home ▸ Section.' : 'The current slide is not in a section.', - ); case 'edit/find': return {}; case 'edit/find/find': case 'edit/find/advanced-find': case 'edit/find/replace': return { run: () => editor.runOrPrompt('replaceTextInPresentation') }; - case 'edit/find/find-next': - case 'edit/find/find-previous': - return unavailable('Use Next match and Previous match in the Find dialog.'); - case 'edit/find/replace-fonts': - return unavailable('The editor has no Replace Fonts dialog yet.'); case 'edit/select-data': return run('setChartSpec'); case 'edit/toggle-drawing': return { disabled: !slide, run: () => editor.ink.toggle('pen') }; - case 'edit/autofill': - return {}; - case 'edit/start-dictation': - case 'edit/emoji-and-symbols': - return unavailable(OS_TEXT_SERVICE); // View // Without a host viewer, Reading View is the editor's own full-window mode. @@ -395,14 +411,9 @@ export function menuCommand(editor: EditorController, host: MenuHost, id: string checked: editor.ribbonVisible, run: () => (editor.ribbonVisible = !editor.ribbonVisible), }; - case 'view/message-bar': - return unavailable('The editor has no message bar.'); case 'view/header-and-footer': case 'insert/header-and-footer': return { disabled: !slide, run: () => (editor.activeDialog = 'headerFooter') }; - case 'view/markup': - case 'view/advanced-markup': - return unavailable('Co-authoring is not available here.'); case 'view/ruler': return { disabled: sorter, @@ -485,38 +496,17 @@ export function menuCommand(editor: EditorController, host: MenuHost, id: string case 'insert/table': return run('addSlideTable'); case 'insert/chart': - case 'insert/smartart': case 'insert/picture': case 'insert/audio': case 'insert/video': case 'insert/shape': - case 'insert/3d-models': - case 'insert/zoom': - case 'insert/action-buttons': - case 'insert/slides-from': return {}; case 'insert/picture/picture-from-file': return run('addSlideImage'); - case 'insert/picture/photo-browser': - case 'insert/audio/audio-browser': - case 'insert/video/movie-browser': - return unavailable(MEDIA_LIBRARY); - case 'insert/picture/stock-images': - case 'insert/picture/online-pictures': - case 'insert/picture/brand-images': - case 'insert/video/stock-videos': - return unavailable(ONLINE); case 'insert/audio/audio-from-file': return { disabled: !slide, run: () => void insertMedia(editor, 'audio', t('Audio')) }; case 'insert/video/movie-from-file': return { disabled: !slide, run: () => void insertMedia(editor, 'video', t('Video')) }; - case 'insert/audio/record-audio': - case 'insert/cameo': - return unavailable('Recording is not available in the browser.'); - case 'insert/video/online-movie': - return unavailable('Online videos are not supported by the library yet.'); - case 'insert/equation': - return unavailable('Equations are not supported by the library yet.'); case 'insert/symbol': return text?.insertText ? { @@ -526,12 +516,8 @@ export function menuCommand(editor: EditorController, host: MenuHost, id: string }, } : unavailable('Place the cursor in text to insert a symbol.'); - case 'insert/icons': - return unavailable('The icon library is not available here.'); case 'insert/action-settings': return run('setShapeClickAction'); - case 'insert/object': - return unavailable('Embedded OLE objects are not supported by the library yet.'); case 'insert/hyperlink': if (text) { if (!text.hyperlink) return unavailable(SLIDE_TEXT); @@ -549,8 +535,6 @@ export function menuCommand(editor: EditorController, host: MenuHost, id: string }; case 'format/paragraph': return { disabled: !paragraphs, run: () => editor.openParagraphDialog(text?.element?.()) }; - case 'format/bullets-and-numbering': - return unavailable('The editor has no Bullets and Numbering dialog yet.'); case 'format/columns': return { disabled: !textShapes || locked, run: host.columns }; case 'format/alignment': @@ -565,12 +549,6 @@ export function menuCommand(editor: EditorController, host: MenuHost, id: string return shapeSelected ? { run: () => editor.pasteObjectFormat() } : { disabled: true, label: APPLY_TO_DEFAULTS[getLocale()] }; - case 'format/animation-painter': - return unavailable('Use Animations ▸ Animation Painter.'); - case 'format/replace-fonts': - return unavailable('The editor has no Replace Fonts dialog yet.'); - case 'format/theme-colors': - return unavailable('Choose theme colors from Design ▸ Variants.'); case 'format/slide-background': return { disabled: !slide, run: () => editor.showBackgroundFormat() }; case 'format/crop': @@ -582,8 +560,6 @@ export function menuCommand(editor: EditorController, host: MenuHost, id: string return { disabled: !objectSelected, run: () => editor.showShapeFormat() }; // Arrange - case 'arrange/reorder-objects': - return unavailable('The layered stacking view is not available in this editor.'); case 'arrange/reorder-overlapping-objects': return { disabled: editor.reorderMembers().length < 2, @@ -629,22 +605,8 @@ export function menuCommand(editor: EditorController, host: MenuHost, id: string }; // Tools - case 'tools/spelling': - return unavailable('Spelling is checked by the browser as you type.'); - case 'tools/thesaurus': - return unavailable('The thesaurus needs an online reference service.'); - case 'tools/translate': - return unavailable('Translation needs an online translation service.'); - case 'tools/set-proofing-language': - return unavailable('Choose the proofing language from Review ▸ Language.'); - case 'tools/autocorrect-options': - return unavailable('AutoCorrect is not available in this editor.'); case 'tools/check-accessibility': return { run: () => (editor.accessibilityOpen = true) }; - case 'tools/macro': - return {}; - case 'tools/add-ins': - return unavailable('Add-ins are not available in this editor.'); // Slide Show case 'slide-show/play-from-start': @@ -655,8 +617,6 @@ export function menuCommand(editor: EditorController, host: MenuHost, id: string return doc.customShows.length ? {} : unavailable('The presentation has no custom shows.'); case 'slide-show/custom-slide-show/custom-shows': return { run: () => editor.openCustomShows() }; - case 'slide-show/rehearse-with-coach': - return unavailable('Rehearse with Coach needs an online service.'); case 'slide-show/presenter-view': return present('presenter'); case 'slide-show/rehearse-timings': @@ -674,21 +634,6 @@ export function menuCommand(editor: EditorController, host: MenuHost, id: string }; case 'slide-show/set-up-show': return { run: () => (editor.activeDialog = 'showProperties') }; - case 'slide-show/always-use-subtitles': - return unavailable(SUBTITLES); - case 'slide-show/subtitle-settings': - return {}; - - // Window - case 'window/move-and-resize': - return {}; - case 'window/document': - return { - checked: true, - bullet: true, - label: doc.fileName.replace(/\.pptx$/i, ''), - run: () => {}, - }; // Help case 'help/editor-help': @@ -700,13 +645,7 @@ export function menuCommand(editor: EditorController, host: MenuHost, id: string ? { disabled: true } : { run: () => void window.open(url, '_blank', 'noopener') }; } - case 'help/clear-application-data': - return unavailable('The editor keeps no application data to clear.'); - case 'help/check-for-updates': - return unavailable('The editor updates with its npm package.'); } - const group = UNAVAILABLE_GROUPS.find(([prefix]) => id.startsWith(prefix)); - if (group) return unavailable(group[1]); throw new Error(`Menu item ${id} has no command`); } @@ -757,7 +696,7 @@ const DOCUMENT_SCOPE = [ * itself owns. */ export function menuKeyLeavesText(editor: EditorController, event: KeyboardEvent): boolean { - const item = menuItemForKey(nativeMenus(editor), event); + const item = menuItemForKey(nativeMenus(), event); if (!item || TEXT_KEYS.has(item.id)) return false; const chord = parseShortcut(item.shortcut!); return chord !== null && isModifiedChord(chord); @@ -776,7 +715,7 @@ export function runMenuKey( !editor.ownsEvent(event) ) return false; - const item = menuItemForKey(nativeMenus(editor), event); + const item = menuItemForKey(nativeMenus(), event); if (!item || WINDOW_KEYS.has(item.id)) return false; const origin = eventTarget(event); const target = origin instanceof HTMLElement ? origin : null; diff --git a/packages/editor/test/menubar-visible.test.mjs b/packages/editor/test/menubar-visible.test.mjs new file mode 100644 index 000000000..f83cb1d14 --- /dev/null +++ b/packages/editor/test/menubar-visible.test.mjs @@ -0,0 +1,52 @@ +import assert from 'node:assert/strict'; +import test from 'node:test'; +import { pruneMenus } from '../src/core/menubar-visible.ts'; + +const item = (id, children) => (children ? { id, label: id, children } : { id, label: id }); +const labels = (entries) => + entries.map((entry) => + entry === '-' ? '-' : entry.children ? [entry.id, labels(entry.children)] : entry.id, + ); + +test('hidden items leave no leading, trailing or doubled separators', () => { + const menus = [ + { + id: 'file', + label: 'File', + items: [item('a'), '-', item('b'), '-', item('c'), '-', item('d'), '-', item('e')], + }, + ]; + const hidden = new Set(['a', 'c', 'e']); + const [file] = pruneMenus(menus, (id) => hidden.has(id)); + assert.deepEqual(labels(file.items), ['b', '-', 'd']); +}); + +test('a submenu with every item hidden goes, and so does an emptied menu', () => { + const menus = [ + { + id: 'insert', + label: 'Insert', + items: [ + item('chart', [item('chart/pie'), item('chart/funnel')]), + item('art', [item('art/x')]), + ], + }, + { id: 'window', label: 'Window', items: [item('window/min')] }, + ]; + const hidden = (id) => id === 'chart/funnel' || id.startsWith('art/') || id.startsWith('window/'); + assert.deepEqual( + pruneMenus(menus, hidden).map((menu) => [menu.id, labels(menu.items)]), + [['insert', [['chart', ['chart/pie']]]]], + ); +}); + +test('a hidden menu goes whole', () => { + const menus = [ + { id: 'help', label: 'Help', items: [item('help/editor-help')] }, + { id: 'window', label: 'Window', items: [item('window/min')] }, + ]; + assert.deepEqual( + pruneMenus(menus, (id) => id === 'window').map((menu) => menu.id), + ['help'], + ); +}); From e65faf97c6bd033de44808276889ba60fb6c6237 Mon Sep 17 00:00:00 2001 From: baseballyama Date: Wed, 28 Oct 2026 12:51:02 +0900 Subject: [PATCH 2/2] test(editor): the public mount's Help menu has only Editor Help Clear Application Data and Check for Updates are now hidden with the other items the editor can never run. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01MNFNHqy4AXFo8fhuoSyzJp --- packages/editor/test/browser/embed.test.mjs | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/packages/editor/test/browser/embed.test.mjs b/packages/editor/test/browser/embed.test.mjs index 1a22f32c9..a4a0a093f 100644 --- a/packages/editor/test/browser/embed.test.mjs +++ b/packages/editor/test/browser/embed.test.mjs @@ -372,20 +372,8 @@ test('shows the Japanese interface and saves through it', async () => { // form or issue tracker anywhere, and offers agents no such command. test('the public mount has no feedback entry point, in English or Japanese', async () => { const HELP = { - en: { - menu: 'Help', - items: ['Editor Help', '----', 'Clear Application Data', '----', 'Check for Updates'], - }, - ja: { - menu: 'ヘルプ', - items: [ - 'エディター ヘルプ', - '----', - 'アプリケーション データのクリア', - '----', - '更新プログラムのチェック', - ], - }, + en: { menu: 'Help', items: ['Editor Help'] }, + ja: { menu: 'ヘルプ', items: ['エディター ヘルプ'] }, }; for (const [locale, help] of Object.entries(HELP)) { const { page, errors } = await hostPage();