mirror of
https://github.com/Termix-SSH/Termix.git
synced 2026-10-29 22:55:24 +00:00
feat: load plugin frontends at runtime and remove plugin ids from the shell
This commit is contained in:
1 parent
49f0286a14
commit
e88d5a52e3
721 files changed
+54265
-44416
No files matched your search
@@ -0,0 +1,40 @@
|
||||
import type { ComponentType } from "react";
|
||||
import type { Host } from "@/types/ui-types";
|
||||
import { byOrderThenId, createRegistry } from "@/lib/registry";
|
||||
import type { TabShellCallbacks } from "./tab-registry";
|
||||
|
||||
/** A command palette entry a plugin contributes. */
|
||||
export interface PaletteEntryDef {
|
||||
id: string;
|
||||
pluginId?: string;
|
||||
titleKey: string;
|
||||
icon?: ComponentType<{ className?: string }>;
|
||||
keywords?: string[];
|
||||
scope: "global" | "host";
|
||||
when?: (host?: Host) => boolean;
|
||||
run: (shell: TabShellCallbacks, host?: Host) => void;
|
||||
order?: number;
|
||||
}
|
||||
|
||||
const registry = createRegistry<PaletteEntryDef>(byOrderThenId);
|
||||
|
||||
export const registerPaletteEntry = registry.register;
|
||||
export const usePaletteEntries = registry.useList;
|
||||
export const listPaletteEntries = registry.list;
|
||||
export const resetPaletteEntries = registry.reset;
|
||||
|
||||
export function paletteEntriesFor(
|
||||
all: PaletteEntryDef[],
|
||||
scope: PaletteEntryDef["scope"],
|
||||
host?: Host,
|
||||
): PaletteEntryDef[] {
|
||||
return all.filter((entry) => {
|
||||
if (entry.scope !== scope) return false;
|
||||
if (!entry.when) return true;
|
||||
try {
|
||||
return entry.when(host);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user