mirror of
https://github.com/t8y2/dbx.git
synced 2026-10-28 08:08:02 +00:00
27 lines
643 B
TypeScript
27 lines
643 B
TypeScript
export interface TabLike {
|
|
id: string;
|
|
}
|
|
|
|
export interface TabCloseState<T extends TabLike> {
|
|
tabs: T[];
|
|
activeTabId: string | null;
|
|
}
|
|
|
|
export function closeOtherTabsState<T extends TabLike>(
|
|
tabs: readonly T[],
|
|
activeTabId: string | null,
|
|
targetTabId: string,
|
|
): TabCloseState<T> {
|
|
const target = tabs.find((tab) => tab.id === targetTabId);
|
|
if (!target) return { tabs: [...tabs], activeTabId };
|
|
|
|
return { tabs: [target], activeTabId: target.id };
|
|
}
|
|
|
|
export function closeAllTabsState<T extends TabLike>(
|
|
_tabs: readonly T[],
|
|
_activeTabId: string | null,
|
|
): TabCloseState<T> {
|
|
return { tabs: [], activeTabId: null };
|
|
}
|