UNPKG

@kvaser/canking-api

Version:

CanKing API to communicate with the CanKing service using Node.js.

101 lines (100 loc) 5.35 kB
import { IWorkspacePaneData } from '../models'; import { IUndoState, IUndoObject } from './useUndo'; /** * Merges saved session/project data with default values. * @param saved - Saved session/project data (will be null/undefined if not present). * @param defaultValue - Default value to use as base. * @returns Merged data combining default and saved values. * @internal */ export declare function mergeData<T>(saved: unknown, defaultValue: T): T; /** * Calculate the maximum number of active intervals allowed based on workspace panes. * @param numPanes - Number of active workspace panes * @returns Maximum allowed active intervals * @internal */ export declare function calculateMaxActiveProjectDataIntervals(numPanes: number): number; /** * A hook for data that should be saved to the current project. * @param id - The unique id of the view. * @param slice - The slice name for the project data. * @param defaultValue - The default value or a function that returns the default value. * @param loadedCallback - Optional callback invoked once after data is loaded. * @returns An object with a flag indicating if the project data has been initialized, the current project data and a setter callback. */ export declare const useProjectDataSlice: <T>(id: number, slice: string, defaultValue: T | (() => T), loadedCallback?: (value: T) => void) => [T, React.Dispatch<React.SetStateAction<T>>, boolean]; /** * A hook for data that should be saved to the current project. * @param id - The unique id of the view. * @param defaultValue - The default value or a function that returns the default value. * @returns An object with a flag indicating if the project data has been initialized, the current project data and a setter callback. */ export declare const useProjectData: <T>(id: number, defaultValue: T | (() => T)) => { projectDataIsInitialized: boolean; projectData: T; setProjectData: React.Dispatch<React.SetStateAction<T>>; }; /** * Calculate the maximum number of active intervals allowed based on workspace panes. * @param numPanes - Number of active workspace panes * @returns Maximum allowed active intervals * @internal */ export declare function calculateMaxActiveSessionDataIntervals(numPanes: number): number; /** * A hook for data that should be saved to the session data. * @param id - The unique id of the view. * @param defaultValue - The default value or a function that returns the default value. * @param loadedCallback - Optional callback invoked once after data is loaded. * @returns An object with the current session data, a setter, and an initialization flag. */ export declare const useSessionData: <T>(id: number, defaultValue: T | (() => T), loadedCallback?: (value: T) => void) => { sessionDataIsInitialized: boolean; sessionData: T; setSessionData: React.Dispatch<React.SetStateAction<T>>; }; /** * A hook for persistent (session) data tied to a specific view slice. * @param id - The unique id of the view. * @param slice - The slice name for the session data. * @param defaultValue - The default value or a function that returns the default value. * @param loadedCallback - Optional callback invoked once after data is loaded. * @returns [state, setState, loaded] the current data, setter, and loaded flag. */ export declare function useSessionDataSlice<T>(id: number, slice: string, defaultValue: T | (() => T), loadedCallback?: (value: T) => void): [T, React.Dispatch<React.SetStateAction<T>>, boolean]; /** * Custom hook to manage undo/redo state using session data storage. * @param id - The unique id of the view. * @param slice - The slice name for the session data. * @param initialState - The initial undo state. * @returns [undoObject, loaded] - An undo object for managing state history and loaded flag. */ export declare function useUndoSessionDataSlice<T>(id: number, slice: string, initialState?: IUndoState<T>): [IUndoObject<T>, boolean]; /** * Hook to get/set a workspace pane by id. */ export declare const useWorkspacePaneWithId: (id: number) => IWorkspacePaneData | null; /** * Callback type for when the view goes online. * @param isNewView - Whether the view is newly created. * @param isMounting - Whether the view is mounting. * @param onlineCounter - The number of times CanKing has gone online. */ export type OnGoingOnlineCallback = (isNewView: boolean, isMounting: boolean, onlineCounter: number) => void; /** * Callback type for when the view goes offline. * @param isNewView - Whether the view is newly created. * @param isMounting - Whether the view is mounting. * @param onlineCounter - The number of times CanKing has gone online. */ export type OnGoingOfflineCallback = (isNewView: boolean, isMounting: boolean, onlineCounter: number) => void; /** * Custom hook to synchronize session state with online/offline status changes. * @param parentIsInitialized - Whether the parent component is initialized. * @param id - The unique id of the view. * @param onGoingOnline - Callback function to handle going online. * @param onGoingOffline - Callback function to handle going offline. * @returns The current online status. */ export declare function useOnlineStatusSync(parentIsInitialized: boolean, id: number, onGoingOnline: OnGoingOnlineCallback, onGoingOffline: OnGoingOfflineCallback): boolean;