@itwin/core-frontend
Version:
iTwin.js frontend components
375 lines • 18.9 kB
TypeScript
/** @packageDocumentation
* @module IModelApp
*/
/** @public */
export declare const ITWINJS_CORE_VERSION: string;
import { UiAdmin } from "@itwin/appui-abstract";
import { AccessToken, BeDuration, BeEvent, GuidString } from "@itwin/core-bentley";
import { AuthorizationClient, Localization, RealityDataAccess, RpcInterfaceDefinition } from "@itwin/core-common";
import { FormatsProvider } from "@itwin/core-quantity";
import { WebGLRenderCompatibilityInfo } from "@itwin/webgl-compatibility";
import { AccuDraw } from "./AccuDraw";
import { AccuSnap } from "./AccuSnap";
import { ExtensionAdmin } from "./extension/ExtensionAdmin";
import { ElementLocateManager } from "./ElementLocateManager";
import { EntityState } from "./EntityState";
import { FrontendHubAccess } from "./FrontendHubAccess";
import { NotificationManager } from "./NotificationManager";
import { QuantityFormatter } from "./quantity-formatting/QuantityFormatter";
import { RenderSystem } from "./render/RenderSystem";
import { TentativePoint } from "./TentativePoint";
import { RealityDataSourceProviderRegistry } from "./RealityDataSource";
import { MapLayerFormatRegistry, MapLayerOptions, TerrainProviderRegistry, TileAdmin } from "./tile/internal";
import { ToolRegistry } from "./tools/Tool";
import { ToolAdmin } from "./tools/ToolAdmin";
import { UserPreferencesAccess } from "./UserPreferences";
import { ViewManager } from "./ViewManager";
import "./IModeljs-css";
/** Options that can be supplied with [[IModelAppOptions]] to customize frontend security.
* @public
* @extensions
*/
export interface FrontendSecurityOptions {
/** Configures protection from Cross Site Request Forgery attacks. */
readonly csrfProtection?: {
/** If enabled, IModelApp will extract the CSRF token for the current session from the document's cookies and send it with each request as a header value. */
readonly enabled: boolean;
/** Defaults to XSRF-TOKEN. */
readonly cookieName?: string;
/** Defaults to X-XSRF-TOKEN. */
readonly headerName?: string;
};
}
/** Options that can be supplied to [[IModelApp.startup]] to customize frontend behavior.
* @public
*/
export interface IModelAppOptions {
/** If present, supplies the [[FrontendHubAccess]] for this session. */
hubAccess?: FrontendHubAccess;
/** If present, supplies the Id of this application. Applications must set this to the Bentley Global Product Registry Id (GPRID) for usage logging. */
applicationId?: string;
/** If present, supplies the version of this application. Must be set for usage logging. */
applicationVersion?: string;
/** If present, supplies the [[UserPreferencesAccess]] for this session.
* @beta
*/
userPreferences?: UserPreferencesAccess;
/** If present, supplies the [[ViewManager]] for this session. */
viewManager?: ViewManager;
/** If present, supplies Map Layer Options for this session such as Azure Access Keys
* @beta
*/
mapLayerOptions?: MapLayerOptions;
/** If present, supplies the properties with which to initialize the [[TileAdmin]] for this session. */
tileAdmin?: TileAdmin.Props;
/** If present, supplies the [[NotificationManager]] for this session. */
notifications?: NotificationManager;
/** If present, supplies the [[ToolAdmin]] for this session. */
toolAdmin?: ToolAdmin;
/** If present, supplies the [[AccuDraw]] for this session. */
accuDraw?: AccuDraw;
/** If present, supplies the [[AccuSnap]] for this session. */
accuSnap?: AccuSnap;
/** If present, supplies the [[Localization]] for this session. Defaults to [ITwinLocalization]($i18n). */
localization?: Localization;
/** The AuthorizationClient used to obtain [AccessToken]($bentley)s. */
authorizationClient?: AuthorizationClient;
/** If present, supplies security options for the frontend. */
security?: FrontendSecurityOptions;
/** @internal */
sessionId?: GuidString;
/** @internal */
locateManager?: ElementLocateManager;
/** If present, supplies the [[TentativePoint]] for this session. */
tentativePoint?: TentativePoint;
/** @internal */
quantityFormatter?: QuantityFormatter;
/** If present, supplies an implementation of the render system, or options for initializing the default render system. */
renderSys?: RenderSystem | RenderSystem.Options;
/** If present, supplies the [[UiAdmin]] for this session. */
uiAdmin?: UiAdmin;
/** If present, supplies the [[FormatsProvider]] for this session. */
formatsProvider?: FormatsProvider;
/** If present, determines whether iModelApp is a NoRenderApp
* @internal
*/
noRender?: boolean;
/**
* @deprecated in 3.7 - might be removed in next major version. Specify desired RPC interfaces in the platform-specific RPC manager call instead.
* See [[MobileRpcManager.initializeClient]], [[ElectronRpcManager.initializeFrontend]], [[BentleyCloudRpcManager.initializeClient]].
*/
rpcInterfaces?: RpcInterfaceDefinition[];
/** @beta */
realityDataAccess?: RealityDataAccess;
/** If present, overrides where public assets are fetched. The default is to fetch assets relative to the current URL.
* The path should always end with a trailing `/`.
*/
publicPath?: string;
}
/** Options for [[IModelApp.makeModalDiv]]
* @public
*/
export interface ModalOptions {
/** Width for the Modal dialog box. */
width?: number;
/** The dialog should be dismissed if the user clicks anywhere or hits Enter or Escape on the keyboard. */
autoClose?: boolean;
/** Show an 'x' in the upper right corner to close the dialog */
closeBox?: boolean;
/** The parent for the semi transparent *darkening* div. If not present, use `document.body` */
rootDiv?: HTMLElement;
}
/** Return type for [[IModelApp.makeModalDiv]]
* @public
*/
export interface ModalReturn {
/** The modal HTMLDivElement created. */
modal: HTMLDivElement;
/** A function that can be set as an event handler to stop the modal dialog. This can be used if [[ModalOptions.autoClose]] or [[IModalOptions.closeBox]]
* were not enabled for the dialog.
*/
stop: (_ev: Event) => void;
}
/**
* Global singleton that connects the user interface with the iTwin.js services. There can be only one IModelApp active in a session. All
* members of IModelApp are static, and it serves as a singleton object for gaining access to session information.
*
* Before any interactive operations may be performed by the `@itwin/core-frontend package`, [[IModelApp.startup]] must be called and awaited.
* Applications may customize the frontend behavior of iTwin.js by supplying options to [[IModelApp.startup]].
*
* @public
*/
export declare class IModelApp {
private static _initialized;
private static _accuDraw;
private static _accuSnap;
private static _applicationId;
private static _applicationVersion;
private static _localization;
private static _locateManager;
private static _notifications;
private static _quantityFormatter;
private static _renderSystem?;
private static _userPreferences?;
private static _tentativePoint;
private static _tileAdmin;
private static _toolAdmin;
private static _viewManager;
private static _uiAdmin;
private static _noRender;
private static _wantEventLoop;
private static _animationRequested;
private static _animationInterval;
private static _animationIntervalId?;
private static _securityOptions;
private static _mapLayerFormatRegistry;
private static _terrainProviderRegistry;
private static _realityDataSourceProviders;
private static _hubAccess?;
private static _realityDataAccess?;
private static _publicPath;
private static _formatsProviderManager;
protected constructor();
/** Event raised just before the frontend IModelApp is to be [[shutdown]]. */
static readonly onBeforeShutdown: BeEvent<() => void>;
/** Event raised after IModelApp [[startup]] completes. */
static readonly onAfterStartup: BeEvent<() => void>;
/** The AuthorizationClient used to obtain [AccessToken]($bentley)s. */
static authorizationClient?: AuthorizationClient;
/** The [[ToolRegistry]] for this session. */
static readonly tools: ToolRegistry;
/** A uniqueId for this session */
static sessionId: GuidString;
/** The [[MapLayerFormatRegistry]] for this session. */
static get mapLayerFormatRegistry(): MapLayerFormatRegistry;
/** The [[TerrainProviderRegistry]] for this session. */
static get terrainProviderRegistry(): TerrainProviderRegistry;
/** The [[RealityDataSourceProviderRegistry]] for this session.
* @beta
*/
static get realityDataSourceProviders(): RealityDataSourceProviderRegistry;
/** The [[RenderSystem]] for this session. */
static get renderSystem(): RenderSystem;
/** The [[ViewManager]] for this session. */
static get viewManager(): ViewManager;
/** The [[NotificationManager]] for this session. */
static get notifications(): NotificationManager;
/** The [[TileAdmin]] for this session. */
static get tileAdmin(): TileAdmin;
/** The [[QuantityFormatter]] for this session. */
static get quantityFormatter(): QuantityFormatter;
/** The [[ToolAdmin]] for this session. */
static get toolAdmin(): ToolAdmin;
/** The [[AccuDraw]] for this session. */
static get accuDraw(): AccuDraw;
/** The [[AccuSnap]] for this session. */
static get accuSnap(): AccuSnap;
static get locateManager(): ElementLocateManager;
/** The [[TentativePoint]] for this session]]. */
static get tentativePoint(): TentativePoint;
/** The [[Localization]] for this session. */
static get localization(): Localization;
/** The [[UserPreferencesAccess]] for this session.
* @beta
*/
static get userPreferences(): UserPreferencesAccess | undefined;
/** The Id of this application. Applications must set this to the Global Product Registry ID (GPRID) for usage logging. */
static get applicationId(): string;
/** The version of this application. Must be set for usage logging. */
static get applicationVersion(): string;
/** True after [[startup]] has been called, until [[shutdown]] is called. */
static get initialized(): boolean;
/** Provides access to IModelHub services. */
static get hubAccess(): FrontendHubAccess | undefined;
/** Provides access to the RealityData service implementation for this IModelApp
* @beta
*/
static get realityDataAccess(): RealityDataAccess | undefined;
/** Whether the [renderSystem[]] has been successfully initialized.
* This will always be `false` before calling [[startup]] and after calling [[shutdown]].
* In rare circumstances (e.g., while executing in a headless test environment) it may remain `false` due to a failure to
* obtain a [WebGL rendering context](https://www.google.com/search?channel=fs&client=ubuntu-sn&q=mdn+webglrenderingcontext).
* As long as you have called [[startup]], you can generally assume it to be `true`.
*/
static get hasRenderSystem(): boolean;
/** The [[UiAdmin]] for this session. */
static get uiAdmin(): UiAdmin;
/** The requested security options for the frontend. */
static get securityOptions(): FrontendSecurityOptions;
/** If present, overrides where public assets are fetched. The default is to fetch assets relative to the current URL.
* The path should always end with a trailing `/`.
*/
static get publicPath(): string;
/** The [[FormatsProvider]] for this session.
* @param provider The provider to use for formatting quantities.
* @beta
*/
static get formatsProvider(): FormatsProvider;
static set formatsProvider(provider: FormatsProvider);
/** @alpha */
static readonly extensionAdmin: ExtensionAdmin;
/** Map of classFullName to EntityState class */
private static _entityClasses;
/** Register all of the subclasses of EntityState from a module.
* @internal
*/
static registerModuleEntities(moduleObj: any): void;
/** Register an EntityState class by its classFullName
* @internal
*/
static registerEntityState(classFullName: string, classType: typeof EntityState): void;
/** @internal */
static lookupEntityClass(classFullName: string): typeof EntityState | undefined;
/**
* Obtain WebGL rendering compatibility information for the client system. This information describes whether the client meets the
* minimum rendering capabilities. It also describes whether the system lacks any optional capabilities that could improve quality
* and/or performance.
* @note As of 4.x, iTwin.js requires WebGL 2. If the client does not support WebGL 2, the `status` field of the returned compatibility info will be [WebGLRenderCompatibilityStatus.CannotCreateContext]($webgl-compatibility).
*/
static queryRenderCompatibility(): WebGLRenderCompatibilityInfo;
/**
* This method must be called before any other `@itwin/core-frontend` methods are used.
* Somewhere in your startup code, call [[IModelApp.startup]]. E.g.:
* ``` ts
* await IModelApp.startup( {applicationId: myAppId} );
* ```
* @param opts The options for configuring IModelApp
*/
static startup(opts?: IModelAppOptions): Promise<void>;
/** Must be called before the application exits to release any held resources. */
static shutdown(): Promise<void>;
/** Controls how frequently the application polls for changes that may require a new animation frame to be requested.
* Such changes include resizing a Viewport or changing the device pixel ratio by zooming in or out in the browser.
* The default interval is 1 second. It may be desirable to override the default for specific apps and/or devices.
* - Increasing the interval can conserve battery life on battery-powered devices at the expense of slower response to resize events.
* - An application that only displays a single Viewport whose dimensions only change when the dimensions of the application window change, and which does not support changing application zoom level, could disable the interval altogether.
* @param interval The interval at which to poll for changes. If undefined (or negative), the application will never poll. If zero, the application will poll as frequently as possible.
* @beta
*/
static get animationInterval(): BeDuration | undefined;
static set animationInterval(interval: BeDuration | undefined);
/** Request that the event loop execute on the next [animation frame](https://developer.mozilla.org/en-US/docs/Web/API/window/requestAnimationFrame).
* There is generally no reason for applications to invoke this method directly.
*/
static requestNextAnimation(): void;
/** @internal */
private static clearIntervalAnimation;
/** @internal */
private static requestIntervalAnimation;
/** @internal */
static startEventLoop(): void;
/** Strictly for tests. @internal */
static stopEventLoop(): void;
/** The main event processing loop for Tools and rendering. */
private static eventLoop;
/** Get the user's access token for this IModelApp, or a blank string if none is available.
* @note Access tokens expire periodically and are automatically refreshed, if possible. Therefore tokens should not be saved, and the value
* returned by this method may change over time throughout the course of a session.
*/
static getAccessToken(): Promise<AccessToken>;
/** @internal */
static createRenderSys(opts?: RenderSystem.Options): RenderSystem;
private static _setupRpcRequestContext;
/** Shortcut for creating an HTMLElement with optional parent, className, id, innerHTML, innerText. */
static makeHTMLElement<K extends keyof HTMLElementTagNameMap>(type: K, opt?: {
/** The parent for the new HTMLElement */
parent?: HTMLElement;
/** The className for the new HTMLElement */
className?: string;
/** The Id for the new HTMLElement */
id?: string;
/** innerHTML for the new HTMLElement */
innerHTML?: string;
/** innerText for the new HTMLElement */
innerText?: string;
}): HTMLElementTagNameMap[K];
/** Shortcut for making a modal dialog on top of the root of the application. The returned HTMLDivElement will be placed topmost, all other application
* windows will be covered with a semi-transparent background that intercepts all key/mouse/touch events until the modal is dismissed.
* @param options The options that describe how the modal should work.
*/
static makeModalDiv(options: ModalOptions): ModalReturn;
/** Applications may implement this method to supply a Logo Card.
* @beta
*/
static applicationLogoCard?: () => HTMLTableRowElement;
/** Make a new Logo Card. Call this method from your implementation of [[IModelApp.applicationLogoCard]]
* @param opts Options for Logo Card
* @beta
*/
static makeLogoCard(opts: {
/** The heading to be put at the top of this logo card inside an <h2>. May include HTML. */
heading: string | HTMLElement;
/** The URL or HTMLImageElement for the icon on this logo card. */
iconSrc?: string | HTMLImageElement;
/** The width of the icon, if `iconSrc` is a string. Default is 64. */
iconWidth?: number;
/** A *notice* string to be shown on the logo card. May include HTML. */
notice?: string | HTMLElement;
}): HTMLTableRowElement;
/** Make the logo card for the library itself. This card gets placed at the top of the stack.
* @internal
*/
static makeIModelJsLogoCard(): HTMLTableRowElement;
/** Format the tooltip strings returned by [[IModelConnection.getToolTipMessage]].
* @alpha
*/
static formatElementToolTip(msg: string[]): HTMLElement;
/** Localize an error status
* @param status one of the status values from [BentleyStatus]($core-bentley), [IModelStatus]($core-bentley) or [DbResult]($core-bentley)
* @returns a localized error message
* @beta
*/
static translateStatus(status: number): string;
/**
* Resets the formatsProvider back to the default [[QuantityTypeFormatsProvider]].
* @beta
*/
static resetFormatsProvider(): void;
/**
* Creates an instance of the ExtensionAdmin
* and registers an event to execute after startup is complete
* @returns an instance of ExtensionAdmin
*/
private static _createExtensionAdmin;
}
//# sourceMappingURL=IModelApp.d.ts.map