UNPKG

catreact

Version:

Catavolt Core React Components

353 lines (352 loc) 12.3 kB
/** * Created by rburson on 1/6/16. */ import * as React from 'react'; import { NavRequest, AppWinDef, AppContext, PaneContext, DialogRedirection, SessionContext, Future, ActionSource } from 'catavolt-sdk'; /** Base interface for Catavolt component properties Components may choose to support any of these properties */ export interface CvProps { /** * The Catavolt SDK entry point, an instance of the sdk {AppContext} which is always available to components. * A singleton instance is used by the underlying components to interact with the sdk. */ catavolt?: AppContext; /** * The {@link CvEventRegistry} handles decoupled communication between components. Any component may subscribe to and publish * {@link CvEvent}s. See also {@link CvListener} and {@link CvEventType} */ eventRegistry?: CvEventRegistry; /** * Allows for a component's rendering logic to be overridden and completely customized. * The first argument, the {@link CvContext}, exposes the {@link CvScopeContext} which provides the relevant SDK object * for use by the renderer. {@link CvScopeContext.scopeObj} will always be an SDK object exposing the data related to * the current component. */ renderer?: (cvContext: CvContext, callbackObj?: any) => {}; } /** Base interface for catavolt component state */ export interface CvState { } /** Top-level Catavolt Context Object */ export interface CvContext { /** * The Catavolt SDK entry point, an instance of the sdk {AppContext} which is always available to components. * A singleton instance is used by the underlying components to interact with the sdk. */ catavolt?: AppContext; /** * The {@link CvEventRegistry} handles decoupled communication between components. Any component may subscribe to and publish * {@link CvEvent}s. See also {@link CvListener} and {@link CvEventType} */ eventRegistry?: CvEventRegistry; /** Allows for exposing a 'scope' object to child components This is usually the corresponding SDK object */ scopeCtx?: CvScopeContext; } /** Allows for exposing a 'scope' object to child components This is usually the corresponding SDK object */ export interface CvScopeContext { /** * The object relevant to this components 'scope'. Usually an SDK object corresponding to the component type. */ scopeObj: any; /** * The parent's scope context (if any) * This allows for navigation back up the component hierarchy */ parentScopeCtx: CvScopeContext; } /** Base Mixin for all catavolt components */ export declare var CvBaseMixin: { contextTypes: { cvContext: React.Requireable<any>; }; childContextTypes: { cvContext: React.Requireable<any>; }; catavolt: () => AppContext; eventRegistry: () => CvEventRegistry; findFirstDescendant: (elem: any, filter: (o: any) => boolean) => any; findAllDescendants: (elem: any, filter: (o: any) => boolean, results?: any[]) => any[]; findFirstScopeCtx: (matchFn: (scopeCtx: CvScopeContext) => boolean, startingCtx?: CvScopeContext) => CvScopeContext; findEntityRec: (startingContext?: CvScopeContext) => any; findPaneContext: (startingContext: CvScopeContext) => any; findPaneTitle: (paneContext: PaneContext) => string; firstInScope: (type: any, startingScopeCtx?: CvScopeContext) => any; getDefaultChildContext: () => { cvContext: { catavolt: any; eventRegistry: any; scopeCtx: { scopeObj: any; parentScopeCtx: any; }; }; }; scopeCtx: () => CvScopeContext; }; /** ****************************************************************** * General Callback mechanism ****************************************************************** */ export interface CvResultCallback<A> { (success: A, error?: any): void; } export interface CvListener<T> { (event: CvEvent<T>): void; } export interface CvEvent<T> { type: CvEventType; eventObj: T; resourceId?: string; } /** * Enumeration of event types to be used with {@link CvEvent} * There is also a corresponding 'payload' object type for each of these * enum values, that is used as the {@link CvEvent.eventObj} type */ export declare enum CvEventType { LOGIN = 0, LOGOUT = 1, ACTION_FIRED = 2, NAVIGATION = 3, STATE_CHANGE = 4, MESSAGE = 5, SESSION_UPDATE = 6, } export interface CvLoginResult { appWinDef: AppWinDef; } export interface CvLogoutResult { tenantId: string; } export declare enum CvNavigationResultType { FORM = 0, URL = 1, NULL = 2, } export interface CvNavigationResult { navRequest: NavRequest; workbenchId?: string; actionId?: string; navTarget?: string; sourceIsDestroyed?: boolean; noTransition?: boolean; type: CvNavigationResultType; } export declare enum CvMessageType { ERROR = 0, WARN = 1, INFO = 2, } export interface CvMessage { type: CvMessageType; message: string; messageObj?: any; } export interface CvSessionUpdateResult { appWinDef: AppWinDef; } export declare enum CvStateChangeType { PANE_DEF_CHANGE = 0, DATA_CHANGE = 1, DESTROYED = 2, MODE_CHANGE_READ = 3, MODE_CHANGE_WRITE = 4, } export interface CvStateChangeResult { source?: PaneContext; type: CvStateChangeType; } export declare enum CvActionFiredResultType { ACTION_STARTED = 0, ACTION_COMPLETED = 1, } export interface CvActionFiredResult { actionId: string; type: CvActionFiredResultType; source: PaneContext; clientAction: boolean; } /** * The {@link CvEventRegistry} handles decoupled communication between components. Any component may subscribe to and publish * {@link CvEvent}s. See also {@link CvListener} and {@link CvEventType}. It also provides resource caching (i.e. caching of * some server provided objects to allow retrieval by 'id') */ export declare class CvEventRegistry { private _cache; private _listenerMap; constructor(); clearAll(): void; clearCache(): void; enableCache(): void; disableCache(): void; isCacheEnabled(): boolean; getEventByKey<T>(key: string): CvEvent<T>; publish<T>(event: CvEvent<T>, shouldCache?: boolean): void; publishError(message: string, messageObj?: string): void; cacheObjectAt(id: string, obj: any): void; removeFromCache(key: string): void; subscribe<T>(listener: CvListener<T>, eventType: CvEventType): void; removeAllListeners(): void; unsubscribe(listener: CvListener<any>): void; } /** * This is a mechanism used throughout the framework * A generalized interface for allowing two components to communicate 'state' changes * i.e. a workbench display and a workbench selector menu * The following compose this mechanism: {@link CvValueListener}, {@link CvValueProvider}, {@link CvValueAdapter} */ export interface CvValueListener<T> { (value: T): void; } export interface CvValueProvider<T> { subscribe(updateListener: CvValueListener<T>): void; } export declare class CvValueAdapter<T> implements CvValueProvider<T> { private _value; private _subscriberArray; getDelegateValueListener(): CvValueListener<T>; /** * @deprecated since 2.0.32 Use getNotifyFunction() instead */ createValueListener(): CvValueListener<T>; subscribe(updateListener: CvValueListener<T>): void; } /** Utilities */ export declare class CvNavigationResultUtil { static determineType(navRequest: NavRequest): CvNavigationResultType; static publishNavigation(catavolt: AppContext, eventRegistry: CvEventRegistry, navRequest: NavRequest, actionId: string, workbenchId: string, navTarget: string, navigationListeners: Array<(event: CvEvent<CvNavigationResult>) => void>, sourceIsDestroyed: boolean, noTransition: boolean): CvEvent<CvNavigationResult>; } export declare class CvSessionManager { static removeSession(): void; static storeSession(sessionContext: SessionContext): void; static getSession(): SessionContext; static updateSession(catavolt: AppContext, eventRegistry: CvEventRegistry): Future<AppWinDef>; } export declare class CvResourceManager { private static PARAM_DELIM; static deserializeRedirection(token: string): { redirection: DialogRedirection; actionSource: ActionSource; }; static shouldCacheResult(eventRegistry: CvEventRegistry): boolean; static resourceIdForObject(o: any, catavolt: AppContext): string; /** * @private * * This is an attempt to preserve a redirection and all it's state along with the action source, * in a single 'token' that can be used on the URL. This along with the session information, are used to make a * 'stateless' transition to a new URL. * The sdk and server require quite a bit of state to be retained by the client in order to 'rebuild' a navigation. * * @param redirection * @param actionSource * @returns {string} */ private static serializeRedirection(redirection, actionSource); } export declare class ColorUtil { static toColor(c: { red: number; green: number; blue: number; alpha: number; }): string; static toColorFromNum(num: any): string; static toColorFromNumWithAlpha(num: any, a: any): string; } export declare class DateUtil { static toISOFormatNoOffset(d: Date): string; } /** * CvImage Action Components * A CvImage has a property for actions. An action (CvImageAction) simply represents a button with a button style * and a parameterless callback action to be executed when the button is pressed. * * A CvImageProducer is a candidate representation of a CvAction. It has flags to determine when a CvAction should be * created or not (i.e. you can't delete an image if there is not already an image). UI will configure a set of * CvImageProducers that are appopriate for the UI. A signature control never supports a delete, while an image * control might support create/delete/undo. * * A CvImagePackage is an abstract class with 5 concrete subclasses. An instance of CvImagePackage is the value to * be set on the CvImageProducer call back listener. */ export declare enum CvImageExistenceState { Missing = 0, Present = 1, Deleted = 2, } export interface CvImageAction { callback: () => void; buttonClassName: string; } export interface CvImageProducer { prodImageCB?: (listener: CvValueListener<Object>) => void; buttonClassName: string; includeWhenImageisPresent: boolean; includeWhenImageIsDeleted: boolean; includeWhenImageIsMissing: boolean; } export declare class CvImagePackage { isUrl(): boolean; isDelete(): boolean; isPick(): boolean; isUndo(): boolean; isRedo(): boolean; } export declare class CvImagePackageUrl extends CvImagePackage { constructor(url: any); private _url; readonly url: string; isUrl(): boolean; } export declare class CvImagePackagePick extends CvImagePackage { isPick(): boolean; } export declare class CvImagePackageUndo extends CvImagePackage { isUndo(): boolean; } export declare class CvImagePackageRedo extends CvImagePackage { isRedo(): boolean; } export declare class CvImagePackageDelete extends CvImagePackage { isDelete(): boolean; } export declare class ImageUtil { /** * Conserve aspect ratio of the orignal region. Useful when shrinking/enlarging * images to fit into a certain area. * * In most cases this is not needed as the object-fit:contain CSS will obtain * the desired result. * * @param {Number} srcWidth Source area width * @param {Number} srcHeight Source area height * @param {Number} maxWidth Fittable area maximum available width * @param {Number} maxHeight Fittable area maximum available height * @return {Object} { width, heigth } */ static calculateAspectRatioFit(srcWidth: any, srcHeight: any, maxWidth: any, maxHeight: any): { width: number; height: number; }; } export declare class UIUtil { static debounce(func: Function, wait: number, immediate?: boolean): Function; }