@sassoftware/vi-api
Version:
Types used in the SAS Visual Investigator API
70 lines (69 loc) • 2.66 kB
TypeScript
import { OnDestroy } from "@angular/core";
import { INavigationBarTab, INavigationBarTabs } from "./shell-tabs-api";
import { Observable } from "rxjs";
export type PotentialTabItem<T = any, U = any> = Partial<OnAttachTab<T> & OnTabEnter & OnTabLeave & OnTabSaveConfirm & OnTabClose & TabWithToolbar<U> & OnDestroy>;
export interface OnAttachTab<T = any> {
currentNavigationBarTab?: INavigationBarTab<T>;
/**
* Runs when a navigation bar tab is first attached to the implementing component.
* If the tab is recycled, it will only run once.
*/
onAttachTab?(): void;
}
export interface OnTabEnterParams {
from?: INavigationBarTab;
fromSecondary?: INavigationBarTab;
to: INavigationBarTab;
toSecondary?: INavigationBarTab;
recycled: boolean;
}
export type OnTabLeaveParams = Omit<OnTabEnterParams, "recycled">;
export interface OnTabEnter {
/**
* Function to run when the Tab is entered, this happens on first load as well
* @param params - from is previous tab (possibly undefined on first load), to is always this tab;
* type {@link INavigationBarTab}, recycled is whether the component was recycled or not
*/
onTabEnter(params: OnTabEnterParams): void;
}
export interface OnTabLeave {
/**
* Function to run when the Tab is left
* @param params - from is always this tab, to is where the user is going; type {@link INavigationBarTab}
*/
onTabLeave(params: OnTabLeaveParams): void;
}
export interface TabToolbarFor<T = any> {
currentComponentAndTab?: {
tab: INavigationBarTabs;
component: T;
};
onAttachComponent?(): void;
}
export interface TabWithToolbar<T> {
currentToolbar?: T;
onAttachToolbar?(): void;
}
export interface OnTabClose {
/**
* @param tab the current tab model that is closing.
*/
onTabClose(tab: INavigationBarTab): boolean | Promise<boolean> | Observable<boolean>;
}
export interface OnTabSaveConfirm {
/**
* @param tab the current tab model that is closing.
*/
onTabSaveConfirm(tab: INavigationBarTab): INavigationBarTabSaveOptions | undefined;
}
export interface INavigationBarTabSaveOptions {
dialogTitle: string;
dialogMessage: string;
saveFunction(): Promise<boolean> | Observable<boolean> | boolean;
}
export type WebElementTabApi<NavBarDataType = any, ComponentType = any> = Omit<PotentialTabItem<NavBarDataType, ComponentType>, "onAttachTab" | keyof TabWithToolbar<ComponentType>> & {
onAttachTab?(tab: INavigationBarTab<NavBarDataType>): void;
};
export type WebTabApiElement = HTMLElement & {
tabApi?: WebElementTabApi;
};