Archived
refactor(plugin-api): clean up workspace panel context
This commit is contained in:
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
"@jmfederico/pi-web": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Clean up the workspace panel plugin context by removing the legacy `openTerminal` alias and moving render invalidation to `context.host.requestRender()`.
|
||||||
+7
-6
@@ -501,14 +501,15 @@ interface WorkspacePanelContext {
|
|||||||
open?: boolean;
|
open?: boolean;
|
||||||
}): Promise<TerminalCommandRunHandle>;
|
}): Promise<TerminalCommandRunHandle>;
|
||||||
};
|
};
|
||||||
requestRender: () => void;
|
host: {
|
||||||
openTerminal: (options?: { terminalId?: string }) => void;
|
requestRender(): void;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
`icon` is optional and is used in the compact mobile tab bar. Prefer an SVG rendered with the `svg` helper from `PluginActivationContext`; use `currentColor` so PI WEB themes can style it. If `icon` is omitted, mobile tabs fall back to initials from the panel title, or to the full title when initials collide.
|
`icon` is optional and is used in the compact mobile tab bar. Prefer an SVG rendered with the `svg` helper from `PluginActivationContext`; use `currentColor` so PI WEB themes can style it. If `icon` is omitted, mobile tabs fall back to initials from the panel title, or to the full title when initials collide.
|
||||||
|
|
||||||
`machine`, `workspace`, `files`, `terminal`, `requestRender()`, and `openTerminal()` are documented as stable for panel callbacks. `terminal.open()` is equivalent to `openTerminal()`; new plugins should prefer `terminal.open()` so terminal-related helpers live under one capability.
|
`machine`, `workspace`, `files`, `terminal`, and `host` are documented as stable for panel callbacks. Use `terminal.open()` to switch to the built-in terminal panel; pass `{ terminalId }` to deep-link to a specific terminal. Call `host.requestRender()` when async plugin-owned state changes should make PI WEB re-evaluate panel callbacks such as `badge`, `visible`, or `render`.
|
||||||
|
|
||||||
Useful workspace and machine shapes:
|
Useful workspace and machine shapes:
|
||||||
|
|
||||||
@@ -644,8 +645,8 @@ workspacePanels: [
|
|||||||
{
|
{
|
||||||
id: "workspace.env",
|
id: "workspace.env",
|
||||||
title: "Env",
|
title: "Env",
|
||||||
render: ({ files, requestRender }) => html`
|
render: ({ files }) => html`
|
||||||
<my-env-viewer .files=${files} .requestRender=${requestRender}></my-env-viewer>
|
<my-env-viewer .files=${files}></my-env-viewer>
|
||||||
`,
|
`,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
@@ -728,7 +729,7 @@ If you are an AI agent building or editing a PI WEB plugin, follow this checklis
|
|||||||
9. Add workspace panels for larger workspace UI.
|
9. Add workspace panels for larger workspace UI.
|
||||||
10. Add workspace labels for compact inline metadata.
|
10. Add workspace labels for compact inline metadata.
|
||||||
11. Return arrays from workspace label `items()`; return an empty array to render nothing.
|
11. Return arrays from workspace label `items()`; return an empty array to render nothing.
|
||||||
12. Use documented context helpers first: `files`, `terminal`, `requestRender`, `workspace`, `machine`, `state.selectedWorkspace`, `state.selectedSession`, and `state.piWebStatus`.
|
12. Use documented context helpers first: `files`, `terminal`, `host.requestRender`, `workspace`, `machine`, `state.selectedWorkspace`, `state.selectedSession`, and `state.piWebStatus`.
|
||||||
13. Do not fetch PI WEB `/api/...` endpoints directly. If an unstable runtime field is intentionally required, import the type from `@jmfederico/pi-web/plugin-api/unstable` and type-assert locally.
|
13. Do not fetch PI WEB `/api/...` endpoints directly. If an unstable runtime field is intentionally required, import the type from `@jmfederico/pi-web/plugin-api/unstable` and type-assert locally.
|
||||||
14. Treat plugins as trusted code and avoid reading or displaying secrets unless intentional.
|
14. Treat plugins as trusted code and avoid reading or displaying secrets unless intentional.
|
||||||
15. After local edits, tell the user to hard reload the browser and check the console for plugin errors.
|
15. After local edits, tell the user to hard reload the browser and check the console for plugin errors.
|
||||||
|
|||||||
@@ -218,7 +218,7 @@ async function refreshWorkspaceConfig(context: WorkspacePanelContext): Promise<C
|
|||||||
detail: error instanceof Error ? error.message : String(error),
|
detail: error instanceof Error ? error.message : String(error),
|
||||||
}));
|
}));
|
||||||
configCache.set(key, state);
|
configCache.set(key, state);
|
||||||
context.requestRender();
|
context.host.requestRender();
|
||||||
window.dispatchEvent(new Event(configChangedEvent));
|
window.dispatchEvent(new Event(configChangedEvent));
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -908,7 +908,9 @@ export class PiWebApp extends LitElement {
|
|||||||
open: (options) => { void this.openRuntimeTerminal(machineId, workspace, options); },
|
open: (options) => { void this.openRuntimeTerminal(machineId, workspace, options); },
|
||||||
runCommand: (input) => terminalCommandRuns.runCommand({ ...input, workspace }),
|
runCommand: (input) => terminalCommandRuns.runCommand({ ...input, workspace }),
|
||||||
},
|
},
|
||||||
requestRender: () => { this.requestUpdate(); },
|
host: {
|
||||||
|
requestRender: () => { this.requestUpdate(); },
|
||||||
|
},
|
||||||
piWebUnstable: { terminalCommandRuns },
|
piWebUnstable: { terminalCommandRuns },
|
||||||
fileTree: this.state.fileTree,
|
fileTree: this.state.fileTree,
|
||||||
expandedDirs: this.state.expandedDirs,
|
expandedDirs: this.state.expandedDirs,
|
||||||
@@ -923,7 +925,6 @@ export class PiWebApp extends LitElement {
|
|||||||
activeTerminalCount: this.state.activeTerminalCount,
|
activeTerminalCount: this.state.activeTerminalCount,
|
||||||
selectedTerminalId: this.state.selectedTerminalId,
|
selectedTerminalId: this.state.selectedTerminalId,
|
||||||
terminalAutoStart: this.terminalAutoStartWorkspaceId === workspace.id,
|
terminalAutoStart: this.terminalAutoStartWorkspaceId === workspace.id,
|
||||||
openTerminal: (options) => { this.openTerminal(options); },
|
|
||||||
onRefreshFiles: () => { void this.files.refreshFiles(); },
|
onRefreshFiles: () => { void this.files.refreshFiles(); },
|
||||||
onExpandDir: (path: string) => { void this.files.expandDir(path); },
|
onExpandDir: (path: string) => { void this.files.expandDir(path); },
|
||||||
onSelectFile: (path: string) => { void this.files.selectFile(path); },
|
onSelectFile: (path: string) => { void this.files.selectFile(path); },
|
||||||
|
|||||||
@@ -56,6 +56,10 @@ export interface WorkspacePanelTerminal {
|
|||||||
runCommand(input: WorkspaceTerminalCommandInput): Promise<TerminalCommandRunHandle>;
|
runCommand(input: WorkspaceTerminalCommandInput): Promise<TerminalCommandRunHandle>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface WorkspacePanelHost {
|
||||||
|
requestRender(): void;
|
||||||
|
}
|
||||||
|
|
||||||
export interface PiWebUnstableRuntimeContext {
|
export interface PiWebUnstableRuntimeContext {
|
||||||
terminalCommandRuns: TerminalCommandRunsInternalRuntime;
|
terminalCommandRuns: TerminalCommandRunsInternalRuntime;
|
||||||
openSettings?: (section?: SettingsSection) => void;
|
openSettings?: (section?: SettingsSection) => void;
|
||||||
@@ -116,7 +120,7 @@ export interface WorkspacePanelContext {
|
|||||||
state: AppState;
|
state: AppState;
|
||||||
files: WorkspacePanelFiles;
|
files: WorkspacePanelFiles;
|
||||||
terminal: WorkspacePanelTerminal;
|
terminal: WorkspacePanelTerminal;
|
||||||
requestRender: () => void;
|
host: WorkspacePanelHost;
|
||||||
piWebUnstable?: Pick<PiWebUnstableRuntimeContext, "terminalCommandRuns">;
|
piWebUnstable?: Pick<PiWebUnstableRuntimeContext, "terminalCommandRuns">;
|
||||||
fileTree: FileTreeEntry[];
|
fileTree: FileTreeEntry[];
|
||||||
expandedDirs: Record<string, FileTreeEntry[]>;
|
expandedDirs: Record<string, FileTreeEntry[]>;
|
||||||
@@ -131,7 +135,6 @@ export interface WorkspacePanelContext {
|
|||||||
activeTerminalCount: number;
|
activeTerminalCount: number;
|
||||||
selectedTerminalId: string | undefined;
|
selectedTerminalId: string | undefined;
|
||||||
terminalAutoStart: boolean;
|
terminalAutoStart: boolean;
|
||||||
openTerminal: (options?: { terminalId?: string | undefined }) => void;
|
|
||||||
onRefreshFiles: () => void;
|
onRefreshFiles: () => void;
|
||||||
onExpandDir: (path: string) => void;
|
onExpandDir: (path: string) => void;
|
||||||
onSelectFile: (path: string) => void;
|
onSelectFile: (path: string) => void;
|
||||||
|
|||||||
+5
-2
@@ -124,14 +124,17 @@ export interface WorkspacePanelTerminal {
|
|||||||
runCommand(input: WorkspaceTerminalCommandInput): Promise<TerminalCommandRunHandle>;
|
runCommand(input: WorkspaceTerminalCommandInput): Promise<TerminalCommandRunHandle>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface WorkspacePanelHost {
|
||||||
|
requestRender(): void;
|
||||||
|
}
|
||||||
|
|
||||||
export interface WorkspacePanelContext {
|
export interface WorkspacePanelContext {
|
||||||
machine: PluginMachine;
|
machine: PluginMachine;
|
||||||
workspace: Workspace;
|
workspace: Workspace;
|
||||||
state?: PluginRuntimeState;
|
state?: PluginRuntimeState;
|
||||||
files: WorkspacePanelFiles;
|
files: WorkspacePanelFiles;
|
||||||
terminal: WorkspacePanelTerminal;
|
terminal: WorkspacePanelTerminal;
|
||||||
requestRender: () => void;
|
host: WorkspacePanelHost;
|
||||||
openTerminal: (options?: { terminalId?: string | undefined }) => void;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type WorkspacePanelIcon = TemplateResult;
|
export type WorkspacePanelIcon = TemplateResult;
|
||||||
|
|||||||
Reference in New Issue
Block a user