Add an opt-in context menu for files and directories

Apps set browser.contextMenu to a list of { label, action, when?, danger? }
items; when(entry, path) scopes an item to directories, files, or any
other match. Right-click, the Menu key, or a touch long press opens it.
The demo adds sample items, including a .json-only one.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-09-23 18:50:21 -07:00
co-authored by Claude Opus 5.5
parent 13e2654415
commit d8b8012e40
12 changed files with 292 additions and 18 deletions
+9 -1
View File
@@ -13,6 +13,13 @@ export interface OctopusOpenDetail {
path: string[];
}
export interface OctopusMenuItem {
label: string;
action: (entry: OctopusEntry, path: string[]) => void;
when?: (entry: OctopusEntry, path: string[]) => boolean;
danger?: boolean;
}
export interface OctopusNavigateDetail {
path: string[];
}
@@ -25,6 +32,7 @@ export interface OctopusFileBrowserEventMap {
export class OctopusFileBrowser extends HTMLElement {
entries: OctopusEntry[];
path: string[];
contextMenu: OctopusMenuItem[];
addEventListener<K extends keyof OctopusFileBrowserEventMap>(
type: K,
listener: (this: OctopusFileBrowser, event: OctopusFileBrowserEventMap[K]) => void,
@@ -39,7 +47,7 @@ export class OctopusFileBrowser extends HTMLElement {
export function createOctopusFileBrowser(
target: Element,
options?: { entries?: OctopusEntry[]; path?: string[]; emptyLabel?: string },
options?: { entries?: OctopusEntry[]; path?: string[]; contextMenu?: OctopusMenuItem[]; emptyLabel?: string },
): OctopusFileBrowser;
export function fileKindLabel(name?: string): string;