Files
tutti/packages/workbench/surface/src/host/hostNodeContext.ts
T
agent-radar 2ed3415fb7
Publish Claude Code Binaries / Stage and publish binaries (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-arm64 (push) Canceled after 0s
Publish Tutti App Runtime / Build darwin-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build linux-amd64 (push) Canceled after 0s
Publish Tutti App Runtime / Build windows-amd64 (push) Canceled after 0s
Sync Tutti Agent Skills / sync (push) Canceled after 0s
Windows Agent Adapters / Test Windows agent adapters (push) Canceled after 0s
Windows Daemon Adapters / Test Windows daemon adapters (push) Canceled after 0s
Publish Tutti App Runtime / Publish runtime catalog (push) Canceled after 0s
源码快照 @ 2026-09-01 (source-only, 剔除非源码素材)
2026-09-01 20:17:27 +08:00

133 lines
4.0 KiB
TypeScript

import { selectFocusedWorkbenchNode } from "../core/selectors.ts";
import type {
WorkbenchRenderNodeContext,
WorkbenchRenderWindowHeader
} from "../react/types.ts";
import {
readWorkbenchHostExternalState,
type WorkbenchHostExternalState
} from "./externalState.ts";
import { createWorkbenchHostNodeHeaderWindowActions } from "./windowActions.ts";
import type {
WorkbenchHostExternalStateSource,
WorkbenchHostHandle,
WorkbenchHostNodeBodyContext,
WorkbenchHostNodeData,
WorkbenchHostNodeDefinition,
WorkbenchHostNodeHeaderContext
} from "./types.ts";
export function createWorkbenchHostNodeBodyContext<
TExternalNodeState,
TExternalWorkspaceState
>({
context,
externalState,
externalStateSource,
host,
isVisible,
workspaceId
}: {
context: WorkbenchRenderNodeContext<WorkbenchHostNodeData>;
definition: WorkbenchHostNodeDefinition<
TExternalNodeState,
TExternalWorkspaceState
>;
externalState?: WorkbenchHostExternalState;
externalStateSource?: WorkbenchHostExternalStateSource;
host: WorkbenchHostHandle;
isVisible: boolean;
workspaceId: string;
}): WorkbenchHostNodeBodyContext<TExternalNodeState, TExternalWorkspaceState> {
const resolvedExternalState =
externalState ??
readWorkbenchHostExternalState({
externalStateSource,
node: context.node,
workspaceId
});
return {
activation: context.node.data.activation ?? null,
displayMode: context.node.displayMode,
externalNodeState:
resolvedExternalState.externalNodeState as TExternalNodeState,
externalWorkspaceState:
resolvedExternalState.externalWorkspaceState as TExternalWorkspaceState,
focus() {
host.focusNode(context.node.id);
},
host,
instanceId: context.node.data.instanceId,
instanceKey: context.node.data.instanceKey ?? null,
isDragging: context.isDragging,
isFocused:
selectFocusedWorkbenchNode(host.getSnapshot())?.id === context.node.id,
isResizing: context.isResizing,
isVisible,
isPresentationVisible:
context.layout.presentation?.mode === "mission-control" &&
context.layout.presentation.visibleNodeIds.has(context.node.id),
presentationMode: context.layout.presentation?.mode ?? null,
node: context.node,
setNodeRuntimeState(state) {
host.setNodeRuntimeState(context.node.id, state);
},
setSnapshotNodeState(state) {
host.setSnapshotNodeState(context.node.id, state);
}
};
}
export function createWorkbenchHostNodeHeaderContext<
TExternalNodeState,
TExternalWorkspaceState
>({
context,
externalState,
externalStateSource,
host,
workspaceId
}: {
context: Parameters<WorkbenchRenderWindowHeader<WorkbenchHostNodeData>>[0];
definition: WorkbenchHostNodeDefinition<
TExternalNodeState,
TExternalWorkspaceState
>;
externalState?: WorkbenchHostExternalState;
externalStateSource?: WorkbenchHostExternalStateSource;
host: WorkbenchHostHandle;
workspaceId: string;
}): WorkbenchHostNodeHeaderContext<
TExternalNodeState,
TExternalWorkspaceState
> {
const resolvedExternalState =
externalState ??
readWorkbenchHostExternalState({
externalStateSource,
node: context.node,
workspaceId
});
return {
activation: context.node.data.activation ?? null,
defaultActions: context.defaultActions,
displayMode: context.node.displayMode,
dragHandleProps: context.dragHandleProps,
externalNodeState:
resolvedExternalState.externalNodeState as TExternalNodeState,
externalWorkspaceState:
resolvedExternalState.externalWorkspaceState as TExternalWorkspaceState,
instanceId: context.node.data.instanceId,
instanceKey: context.node.data.instanceKey ?? null,
isDragging: context.isDragging,
isFocused: context.isFocused,
isResizing: context.isResizing,
node: context.node,
surfaceSize: context.surfaceSize,
windowActions: createWorkbenchHostNodeHeaderWindowActions(context, {
requestNodeClose: (nodeId) => host.requestNodeClose(nodeId)
})
};
}