Files
NetMesh/domain/hostClickBehavior.ts
zhaolei 3c72efcb7f
Some checks failed
build-packages / resolve bundled mosh-client (push) Has been cancelled
build-packages / resolve bundled et-client (push) Has been cancelled
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
build-packages / update Nix release metadata (push) Has been cancelled
build-packages / bump homebrew tap (push) Has been cancelled
test / lint-and-test (push) Has been cancelled
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
build-et-binaries / build-linux-x64 (push) Has been cancelled
build-et-binaries / build-linux-arm64 (push) Has been cancelled
build-et-binaries / build-macos-universal (push) Has been cancelled
build-et-binaries / build-windows-x64 (push) Has been cancelled
build-et-binaries / release (push) Has been cancelled
[Init] Initial commit - NetMesh terminal manager
2026-09-13 18:24:01 +08:00

81 lines
2.3 KiB
TypeScript

/**
* Vault host/group click activation.
*
* - `connect` (default): single click immediately connects / opens
* - `select`: first click focuses; click the focused item again to activate
*/
export type HostClickBehavior = 'connect' | 'select';
export const DEFAULT_HOST_CLICK_BEHAVIOR: HostClickBehavior = 'connect';
export function isHostClickBehavior(value: unknown): value is HostClickBehavior {
return value === 'connect' || value === 'select';
}
export function resolveHostActivateAction(input: {
behavior: HostClickBehavior;
isMultiSelectMode: boolean;
focusedHostId: string | null | undefined;
hostId: string;
}): 'connect' | 'select' | 'toggle-multi' {
if (input.isMultiSelectMode) return 'toggle-multi';
if (input.behavior === 'connect') return 'connect';
if (input.focusedHostId === input.hostId) return 'connect';
return 'select';
}
export function isHostClickFocusSelected(input: {
behavior: HostClickBehavior;
isMultiSelectMode: boolean;
focusedHostId: string | null | undefined;
hostId: string;
}): boolean {
return (
input.behavior === 'select'
&& !input.isMultiSelectMode
&& input.focusedHostId === input.hostId
);
}
export function resolveGroupActivateAction(input: {
behavior: HostClickBehavior;
focusedGroupPath: string | null | undefined;
groupPath: string;
}): 'open' | 'select' {
if (input.behavior === 'connect') return 'open';
if (input.focusedGroupPath === input.groupPath) return 'open';
return 'select';
}
export function shouldClearHostFocusOnBackgroundClick(input: {
behavior: HostClickBehavior;
isMultiSelectMode: boolean;
clickedWithinHostList: boolean;
clickedHostOrGroup: boolean;
}): boolean {
return (
input.behavior === 'select' &&
!input.isMultiSelectMode &&
input.clickedWithinHostList &&
!input.clickedHostOrGroup
);
}
/**
* Focus styles for vault host/group cards.
* - Grid: recolor existing soft-card border to accent.
* - List/tree: hover-like background fill only (no border).
*/
export function hostCardFocusClassName(
viewMode: 'grid' | 'list' | 'tree',
isFocused: boolean,
): string {
if (!isFocused) return '';
// Grid soft-card already draws a border; force accent color (beat .soft-card).
if (viewMode === 'grid') {
return '!border-primary';
}
// List/tree: same glass fill as hover — no border.
return 'bg-secondary/60';
}