68 lines
2.1 KiB
TypeScript
68 lines
2.1 KiB
TypeScript
import type { ComponentType } from "react";
|
|
import invariant from "tiny-invariant";
|
|
import { PaneProvider, type PaneContextValue } from "@/panels/pane-context";
|
|
import { getPanelRegistration } from "@/panels/panel-registry";
|
|
import { ensurePanelsRegistered } from "@/panels/register-panels";
|
|
import type { WorkspaceTabDescriptor } from "@/screens/workspace/workspace-tabs-types";
|
|
|
|
export interface WorkspacePaneContentModel {
|
|
key: string;
|
|
Component: ComponentType;
|
|
paneContextValue: PaneContextValue;
|
|
}
|
|
|
|
export interface BuildWorkspacePaneContentModelInput {
|
|
tab: WorkspaceTabDescriptor;
|
|
normalizedServerId: string;
|
|
normalizedWorkspaceId: string;
|
|
isPaneFocused: boolean;
|
|
onOpenTab: (target: WorkspaceTabDescriptor["target"]) => void;
|
|
onCloseCurrentTab: () => void;
|
|
onRetargetCurrentTab: (target: WorkspaceTabDescriptor["target"]) => void;
|
|
onOpenWorkspaceFile: (filePath: string) => void;
|
|
}
|
|
|
|
export function buildWorkspacePaneContentModel({
|
|
tab,
|
|
normalizedServerId,
|
|
normalizedWorkspaceId,
|
|
isPaneFocused,
|
|
onOpenTab,
|
|
onCloseCurrentTab,
|
|
onRetargetCurrentTab,
|
|
onOpenWorkspaceFile,
|
|
}: BuildWorkspacePaneContentModelInput): WorkspacePaneContentModel {
|
|
ensurePanelsRegistered();
|
|
const registration = getPanelRegistration(tab.kind);
|
|
invariant(registration, `No panel registration for kind: ${tab.kind}`);
|
|
return {
|
|
key: `${normalizedServerId}:${normalizedWorkspaceId}:${tab.tabId}:${tab.kind}`,
|
|
Component: registration.component,
|
|
paneContextValue: {
|
|
serverId: normalizedServerId,
|
|
workspaceId: normalizedWorkspaceId,
|
|
tabId: tab.tabId,
|
|
isPaneFocused,
|
|
target: tab.target,
|
|
openTab: onOpenTab,
|
|
closeCurrentTab: onCloseCurrentTab,
|
|
retargetCurrentTab: onRetargetCurrentTab,
|
|
openFileInWorkspace: onOpenWorkspaceFile,
|
|
},
|
|
};
|
|
}
|
|
|
|
export interface WorkspacePaneContentProps {
|
|
content: WorkspacePaneContentModel;
|
|
}
|
|
|
|
export function WorkspacePaneContent({ content }: WorkspacePaneContentProps) {
|
|
const { Component, key, paneContextValue } = content;
|
|
|
|
return (
|
|
<PaneProvider value={paneContextValue}>
|
|
<Component key={key} />
|
|
</PaneProvider>
|
|
);
|
|
}
|