Files
octopus-file-browser-gone1/octopus-file-browser.d.ts
T
multipleof4andClaude Opus 5.5 d8b8012e40 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>
2026-09-23 18:50:21 -07:00

64 lines
1.8 KiB
TypeScript

export type OctopusDate = string | number | Date;
export interface OctopusEntry {
name: string;
type: 'file' | 'directory';
size?: number;
modified?: OctopusDate;
icon?: string;
}
export interface OctopusOpenDetail {
entry: OctopusEntry;
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[];
}
export interface OctopusFileBrowserEventMap {
'octopus:open': CustomEvent<OctopusOpenDetail>;
'octopus:navigate': CustomEvent<OctopusNavigateDetail>;
}
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,
options?: boolean | AddEventListenerOptions,
): void;
addEventListener(
type: string,
listener: EventListenerOrEventListenerObject | null,
options?: boolean | AddEventListenerOptions,
): void;
}
export function createOctopusFileBrowser(
target: Element,
options?: { entries?: OctopusEntry[]; path?: string[]; contextMenu?: OctopusMenuItem[]; emptyLabel?: string },
): OctopusFileBrowser;
export function fileKindLabel(name?: string): string;
export function formatFileSize(bytes?: number): string;
export function formatRelativeDate(value: OctopusDate, now?: number): string;
export function isRecent(value: OctopusDate, now?: number): boolean;
export function sortEntries(entries?: OctopusEntry[]): OctopusEntry[];
declare global {
interface HTMLElementTagNameMap {
'octopus-file-browser': OctopusFileBrowser;
}
}