/*! * Copyright 2017 - 2020 by ChartIQ, Inc. * All rights reserved. */ /** * WindowClient is primarily responsible for managing window state (the window's location and size) and app state (data inside of your app). * @module WindowClient */ import { WindowIdentifier } from "../services/window/types"; import { StandardCallback, StandardError, StandardErrorCallback, StandardPromise } from "../types"; import { MonitorCoordinates, MonitorInfoDetail, WindowOptions } from "../FEA"; import { WindowBounds } from "../services/window/types"; import { MonitorCommand } from "../common/Monitors"; import { Bounds } from "../services/window/types"; import { FEAWindow } from "../FEA"; import { SystemStartupData } from "./Startup/types"; /** * The WindowClientController is a singleton which serves as the backing for the WindowClient export. Even though WindowClient * is exported, there can still be more than one instance when running with an FEA preload. In these circumstances, the singleton * nature of the controller ensures that both instances have access to the same static data, and that there are only ever * one set of router messages/event listeners. * * WindowClient accesses the WindowClientController's internal objects using getters and setters. This allows multiple copies * of WindowClient to each maintain a reference to the singleton's members, guaranteeing consistency. * * The WindowClientController must be started from an entry point (FSBLDesktop or FSBLService). */ declare class WindowClientController { options: WindowOptions; title: string | null; windowGroups: GroupData[]; commandChannel: ((arg0: any, arg1: any) => void) | undefined; constructor(); /** * Handler for group updates from the window service. Stores the groups that this window is in, * if any. * @param err the error, if any * @param res the received updated group data */ groupUpdateHandler(err: StandardError, res: GroupUpdate): void; /** * Sends a command to the header. Commands affect the header state, * so that the UI reflects what is going on in the component window. * @param {string} command The state object to set * @param {object} state The new state (merged with existing) */ updateHeaderState(command: string, state: any): void; setStartupData(systemStartupData: SystemStartupData): void; start(): Promise; } /** * @ignore */ export declare const getControllerInstance: () => WindowClientController; declare type getStackedWindowParams = { /** if true and StackedWindow isn't defined, a stacked window will be created. */ create?: boolean; /** If creating a stacked window, you can optionally specify an array of other windowIdentifiers to add to the stack on creation. The calling window will automatically be added. */ windowIdentifiers?: WindowIdentifier[]; }; declare type GroupData = { windowNames: string[]; isMovable: boolean; isAlwaysOnTop: boolean; topRightWindow: string; isARectangle: boolean; }; declare type GroupUpdate = { data: { groupData: { [k: string]: GroupData; }; }; }; /** * Returns a list of the groups this window is in, if any. * @deprecated */ declare const getWindowGroups: () => GroupData[]; /** * Closes window. Defaults are to remove the window from the workspace if the user presses the X button, but not if the window is closed via an app-level request (e.g., switching workspaces, so all windows need to close). * * ```javascript * //Close window and remove from workspace (e.g., user closes the window). * FSBL.Clients.WindowClient.close({ removeFromWorkspace: true, closeWindow: true }); * //Close window and keep in workspace (e.g., application requests that all windows close themselves). * FSBL.Clients.WindowClient.close({ removeFromWorkspace: false, closeWindow: false }); * ``` * @param {object} params * @param {boolean} params.removeFromWorkspace Whether to remove the window from the workspace. * @param {boolean} params.closeWindow Whether to close the window. On shutdown this method is called, but the Window Service actually closes the window. * @param {boolean} params.userInitiated Whether the user clicked the X, or if the system asked the window to close. * @param {boolean} params.ignoreParent Whether or not to update the parent (stack) window when closing. * @param {function} cb The callback to be invoked after the method completes successfully. */ export declare const close: (params: { removeFromWorkspace: boolean; closeWindow: boolean; ignoreParent?: boolean; userInitiated?: boolean; }, cb?: StandardErrorCallback) => StandardPromise; /** * Retrieves the window's title. * * ```javascript * let windowTitle = FSBL.Clients.WindowClient.getWindowTitle(); * ``` * @returns {String} title */ export declare const getWindowTitle: () => string | null; /** * This function retrieves the dimensions of the monitor that the window is on. It's currently used in the LauncherClient. * @param {function} callback */ declare const retrieveMonitorDimensions: (cb: (monitorInfo: MonitorCoordinates) => void) => Promise; /** * Gets the bounds for the window on startup and saves them to the workspace. */ declare const cacheInitialBounds: () => Promise; /** * Returns windowBounds as of the last save. * @returns {object} * @todo deprecate and remove from linkerClient */ declare const getWindowBounds: () => Bounds; /** * * Saves the window's state. Rarely called manually, as it's called every time your window moves. * * The code below is the bulk of our listener for the bounds-changed event from the window. Every time the bounds-changed event is fired (when the window is resized or moved), we save the window's state. The first few lines just prevent the window from being dropped behind the toolbar. * ```javascript *finWindow.addEventListener('disabled-frame-bounds-changed', function (bounds) { * if (bounds.top < 45) { * finWindow.moveTo(bounds.left, 45); * return; * } * self.saveWindowBounds(bounds); * ``` * @param {Object} bounds optional param. * @param {boolean} setActiveWorkspaceDirty *}); */ declare const saveWindowBounds: (bounds: WindowBounds, setActiveWorkspaceDirty: boolean) => void; /** * Maximizes the window taking into account any claimed space on the monitor. * * ```javascript * FSBL.Clients.WindowClient.maximize(); * ``` * @param {function} cb Optional callback to be invoked after the method completes successfully. */ export declare const maximize: (cb?: StandardErrorCallback) => StandardPromise; /** * Minimizes window. * * ```javascript * FSBL.Clients.WindowClient.minimize(); * ``` * @param {function} cb Optional callback to be invoked after the method completes successfully. */ export declare const minimize: (cb?: StandardErrorCallback) => StandardPromise; /** * Brings the window to the top of all other windows. * * ```javascript * FSBL.Clients.WindowClient.bringWindowToFront(); * ``` */ export declare const bringToFront: (cb?: StandardErrorCallback) => StandardPromise; /** * Brings the window to the top of all other windows * * This is a non-promisifed version for backward compatibility. Please use WindowClient.bringToFront() * * @deprecated Use `bringToFront()` instead, which returns a promise. */ export declare const bringWindowToFront: (cb?: StandardErrorCallback) => void; /** * Sets whether window is always on top. By default, this is false. * * ```javascript * FSBL.Clients.WindowClient.setAlwaysOnTop(true); * ``` * @param {boolean} alwaysOnTop The new mode for the window's alwaysOnTop option to be set to. * @param {function} cb Optional callback to be invoked after the method completes successfully. */ export declare const setAlwaysOnTop: (alwaysOnTop: boolean, cb?: StandardErrorCallback) => StandardPromise; /** * Restores window from a maximized or minimized state. * * ```javascript * FSBL.Clients.WindowClient.restore(); * ``` * @param {function} cb Optional callback to be invoked after the method completes successfully. */ export declare const restore: (cb?: StandardErrorCallback) => StandardPromise; /** * _This feature is experimental. The signature may change in the future._ * * Sets an overlay image on the MS Windows taskbar, for instance to indicate activity. * (This is sometimes referred to as a "badge"). * * The url must point to a 16x16 png image. Images of other sizes or types will not display. * * Note: MacOS does not support taskbar overlay images. This function is safe to call * on MacOS but will not perform any function. * @param url - The url of the icon to use. Pass null to remove the overlay icon. */ export declare const setTaskbarIconOverlay: (url: string | null) => void; /** * This function injects the header bar into all windows without frames that request it. This should only be used if you've decided not to use the provided WindowClient.start() method. * * **NOTE:** If you are using the Finsemble window title bar component, you do not need to call this function. */ declare const injectDOM: (headerHeight: number) => void; /** * Given a field, this function retrieves app state. If no params are given, the full state is returned. * * The example below shows how we retrieve data to restore the layout in our charts. * ```javascript * FSBL.Clients.WindowClient.getComponentState({ * field: 'myChartLayout', * }, function (err, state) { * importLayout(state); * }); * * FSBL.Clients.WindowClient.getComponentState({ * fields: ['myChartLayout', 'chartType'], * }, function (err, state) { * let chartType = state['chartType']; * let myChartLayout = state['myChartLayout']; * }); * ``` * @param {object} params * @param {string} params.field Field to retrieve. * @param {Array.} params.fields Fields to retrieve. * @param {string} params.windowName Window whose component state you are retrieving. If null, the default is to the calling window. * @param {function} cb The callback to be invoked after the method completes successfully. */ export declare const getComponentState: (params: { field?: string; fields?: string[]; windowName?: string; }, cb?: StandardErrorCallback | undefined) => StandardPromise; /** * Given a field, this function sets and persists app state. * * The example below shows how we save our chart layout when it changes. * ```javascript * let s = stx.exportLayout(true); * //saving layout' * FSBL.Clients.WindowClient.setComponentState({ field: 'myChartLayout', value: s }); * FSBL.Clients.WindowClient.setComponentState({ fields: [{field:'myChartLayout', value: s }, {field:'chartType', value: 'mountain'}]); * ``` * @param {object} params Object of data to be saved * @param {string} params.field The key name of the field to be saved. Required if not using `fields`. * @param {Array.} params.fields An array of objects with `field` and `value` keys to be saved. * @param {string} params.windowName Name of the component whose state you are setting. Defaults to the calling window. * @param {any} params.value Value of the data being saved. Required if not using `fields`. * @param {function} cb The callback to be invoked after the method completes successfully. */ export declare const setComponentState: (params: { field?: string | undefined; fields?: { field: string; value: T; }[] | undefined; value?: T | undefined; windowName?: string | undefined; }, cb?: StandardErrorCallback) => StandardPromise; /** * Given a field, this function removes it from app state. * * The example below shows how we would remove our chart layout when it no longer needed. * ```javascript * // remove unused state value * FSBL.Clients.WindowClient.removeComponentState({ field: 'myChartLayout'}); * FSBL.Clients.WindowClient.removeComponentState({ fields: [{field:'myChartLayout'}, {field:'chartType'}]); * ``` * @param {object} params Object of data to be removed * @param {string} params.field The key name of the field to be saved. Required if not using `fields`. * @param {Array.} params.fields An array of objects with `field` keys to be removed. * @param {string} params.windowName The name of the window to remove component state from * @param {function} cb The callback to be invoked after the method completes successfully. */ export declare const removeComponentState: (params: { field?: string; fields?: { field: string; }[]; windowName?: string; }, cb?: StandardErrorCallback) => StandardPromise; /** * Gets the window name of current window or the parent, if tabbed. The code that manages window movement will not see a child window if it's part of a stacked window. This function will return the window name that the Window Service cares about for window movement. * @deprecated */ export declare const getWindowNameForDocking: () => any; /** * Forms a group with any window that is touching the border of this window. */ export declare const formGroup: () => void; /** * Adds finsembleWindow listeners for the command channel to the WindowTitleBar. * * These listeners are auto-cleaning when a window closes, so there is no need to manually close * them during destruction. */ declare const addListeners: () => void; /** * Establishes a command channel with the Finsemble window title bar component. The Window Client can * update the title bar's state via this channel. This code will be moved into finsemble-ui. * @param {function} commandChannel A function callback that receives commands. */ declare const headerCommandChannel: (commandChannel: (arg0: any, arg1: any) => void) => void; /** * Ejects the window from the docking group * @deprecated This code will be moved to finsemble-ui */ export declare const ejectFromGroup: () => void; /** * @param title Title for the window */ declare const setWindowTitlePrivate: (title: string) => void; /** * Deprecated. Please simply set the application's `document.title` element to change the title that appears * in the windowTitleBar. Or, set `components["Window Manager"].title` in the app's manifest. * * Old documentation: * This function sets the window's title in the windowTitleBar component, and in the DOM's title element. * This is useful to set the title dynamically based on state information: you can keep the window's title in sync with a piece of data (e.g., a Symbol). * This title will not persist between sessions automatically; use setComponentState/getComponentState to persist the title. * @param {String} title Window title. * @deprecated */ declare const setWindowTitle: (title: string) => void; /** * Retrieves data that was set with LauncherClient.spawn. * @returns The spawnData that was passed to calls to LauncherClient.spawn, or an empty object. */ export declare const getSpawnData: () => any; /** * Returns a reference to the current FEAWindow for the component. * @returns {finWindow} * @deprecated Use `FSBL.System.Window.getCurrent()` */ export declare const getCurrentWindow: () => FEAWindow; /** * For the DOM element that has been passed in, this function returns a bounding box that is relative * to the virtual monitor space. That is, it returns the position of the DOM element on the desktop. * @param {HTMLElement|string} element A selector or HTMLElement */ declare const getDesktopBoundingBox: (element: string | Element) => Promise<{ top: number; left: number; width: number; height: number; right: number; bottom: number; }>; /** * @deprecated This code will be moved into finsemble-ui */ declare const isPointInBox: (point: { x: number; y: number; }, box: { top: number; left: number; bottom?: number; right?: number; width: number; height: number; }) => boolean; /** * Returns (via callback) true if the mouse is currently located (hovering) over the requested element. * @param {HTMLElement|string} element The element, or a selector, to check * @param {function} cb A function that returns a boolean */ declare const isMouseOverDOMElement: (element: Element, cb?: ((result: boolean) => void) | undefined) => Promise; /** * Returns the window identifier for the current component. * @returns {WindowIdentifier} */ export declare const getWindowIdentifier: () => WindowIdentifier; /** * Highlights the window as active by creating a border around the window. * * @param {boolean} active Set to false to turn off activity * @deprecated */ declare const setActive: (active: boolean) => void; /** * Returns the object defining bounds for the current window including the position of the left and right edges measured in pixels from the left edge of the monitor, the top and bottom edges measured in pixels from the top edge, and the width and height of the component in pixels. * Please note that this method differs from the right and bottom coordinates passed to LauncherClient.spawn(); those are measured from the right and bottom edges of the screen. * @param {StandardCallback} cb The callback to be invoked after the method completes successfully. */ export declare const getBounds: (cb: StandardErrorCallback) => StandardPromise; /** * Defines areas of the window that will be displayed and clickable. All other areas of the window will be transparent. * Can be used to create click-through areas of a window. * * @param params Optional. Takes an array of rectangle Objects for the areas of the window that will be displayed and clickable. * Passing in an empty array or omitting this parameter will cause the full area of the window to be displayed and clickable. * A rectangle is defined as: { * x: x coordinate for the origin of the rectangle (integer) * y: x coordinate for the origin of the rectangle (integer) * width: width of the rectangle (integer) * height: height of the rectangle (integer) * } * @param callback: Function = Function.prototype */ export declare const setShape: (params?: Array<{ x: Number; y: Number; width: Number; height: Number; } | null>, callback?: Function) => void; /** * This is used by the Finsemble window title bar when a tab is dragged for tiling or tabbing. * @param {*} params - params.windowIdentifier is required. * @param {WindowIdentifier} params.windowIdentifier The Finsemble identifier for the target window. * @param {*} cb The callback to be invoked after the method completes successfully. * @deprecated This code will be moved into finsemble-ui */ export declare const startTilingOrTabbing: (params: { windowIdentifier: WindowIdentifier; }, cb?: () => void) => void; /** * Begin programmatically moving the window; the first parameter is a mouse event. Until `stopMovingWindow` is invoked, the window will follow the user's mouse. This should be invoked inside of a `mouseDown` event handler. */ export declare const startMovingWindow: (event: MouseEvent) => void; /** * Stops moving a window that was set in motion via `startMovingWindow`. */ export declare const stopMovingWindow: () => void; /** * This is used to cancel a tabbing or tiling operation. * * @param {object} params * @param {WindowIdentifier} params.windowIdentifier The Finsemble identifier for the window. * @param {Function} cb - The callback to be invoked after the method completes successfully. * @deprecated This code will be moved into finsemble-ui */ export declare const cancelTilingOrTabbing: (params: { windowIdentifier?: WindowIdentifier; }, cb?: () => void) => void; /** * This is used to let Finsemble know which window is being dragged. params.windowIdentifier must be the identifier of the tab being dragged. This is only used if the identifier is unknown when startTilingOrTabbing is called. * @param {*} params - The windowIdentifier is required. * @param {WindowIdentifier} params.windowIdentifier The Finsemble identifier for the target window. * @param {*} cb - The callback to be invoked after the method completes successfully. * @deprecated This code will be moved into finsemble-ui */ export declare const sendIdentifierForTilingOrTabbing: (params: { windowIdentifier: WindowIdentifier; }, cb?: () => void) => void; /** * This function is used by the Finsemble window title bar to end tiling or tabbing. * @param {*} params * @param {object} params.mousePosition Where the pointer is on the screen * @param {number} params.mousePosition.x X position of the pointer * @param {number} params.mousePosition.y Y position of the pointer * @param {boolean} params.allowDropOnSelf Determines whether a tab can be dropped on the window where the drag originated. * @param {*} cb - The callback to be invoked after the method completes successfully. * @deprecated This code will be moved into finsemble-ui */ export declare const stopTilingOrTabbing: (params: { mousePosition?: { x: number; y: number; }; action?: string; allowDropOnSelf?: boolean; }, cb?: () => void) => void; /** * Gets the stackedWindow (if this window is a child of a stacked window). * * If the calling window is not part of a stacked window, the stacked window identifier will be returned null -- unless params.create is true. In this case, a stacked window will be created and the calling window will be set as the first child * * (Typically used by Tabbing Presentation component to manage tabs.) * * @param {object=} params * @param {array=} params.create if true and StackedWindow isn't defined, then it will be created * @param {array=} params.windowIdentifiers if creating, then can optionally specify an array of other windowIdentifiers to add to stack on creation (in addition to this window). * @param {function} cb cb(err, stackedWindowIdentifier) * * Typically used by Tabbing Presentation component. * @deprecated Move this code into UI library (windowTitleBarStore) */ declare const getStackedWindow: (params?: getStackedWindowParams | StandardCallback, cb?: StandardCallback) => void; /** * */ declare const getMonitorInfo: (params?: { monitor?: MonitorCommand; windowIdentifier?: WindowIdentifier; }, cb?: StandardErrorCallback) => StandardPromise; /** * Moves the window so that it's centered above the user's mouse. */ export declare const showAtMousePosition: () => void; export declare const fitToDOM: (params?: { padding?: { height: number; width: number; }; maxHeight?: number; maxWidth?: number; } | null, cb?: () => void) => Promise; /** * @ignore * * Getters and setters are used to map `options`,`title`,`windowGroups` and `commandChannel` to the WindowClientController * singleton. See its comments for a more complete discussion. */ export declare const WindowClient: { options: WindowOptions; title: string | null; windowGroups: GroupData[]; commandChannel: ((arg0: any, arg1: any) => void) | undefined; fitToDOM: typeof fitToDOM; getBounds: typeof getBounds; getWindowGroups: typeof getWindowGroups; initialize: Function; onReady: Function; showAtMousePosition: typeof showAtMousePosition; getMonitorInfo: typeof getMonitorInfo; getStackedWindow: typeof getStackedWindow; cancelTilingOrTabbing: typeof cancelTilingOrTabbing; startTilingOrTabbing: typeof startTilingOrTabbing; stopTilingOrTabbing: typeof stopTilingOrTabbing; sendIdentifierForTilingOrTabbing: typeof sendIdentifierForTilingOrTabbing; stopMovingWindow: typeof stopMovingWindow; startMovingWindow: typeof startMovingWindow; setShape: typeof setShape; setActive: typeof setActive; getWindowIdentifier: typeof getWindowIdentifier; isMouseOverDOMElement: typeof isMouseOverDOMElement; isPointInBox: typeof isPointInBox; getDesktopBoundingBox: typeof getDesktopBoundingBox; getCurrentWindow: typeof getCurrentWindow; getSpawnData: typeof getSpawnData; setWindowTitle: typeof setWindowTitle; ejectFromGroup: typeof ejectFromGroup; headerCommandChannel: typeof headerCommandChannel; addListeners: typeof addListeners; formGroup: typeof formGroup; getWindowNameForDocking: typeof getWindowNameForDocking; removeComponentState: typeof removeComponentState; setComponentState: typeof setComponentState; getComponentState: typeof getComponentState; injectDOM: typeof injectDOM; setTaskbarIconOverlay: typeof setTaskbarIconOverlay; restore: typeof restore; setAlwaysOnTop: typeof setAlwaysOnTop; bringWindowToFront: typeof bringWindowToFront; bringToFront: typeof bringToFront; minimize: typeof minimize; maximize: typeof maximize; saveWindowBounds: typeof saveWindowBounds; getWindowBounds: typeof getWindowBounds; cacheInitialBounds: typeof cacheInitialBounds; retrieveMonitorDimensions: typeof retrieveMonitorDimensions; getWindowTitle: typeof getWindowTitle; close: typeof close; setWindowTitlePrivate: typeof setWindowTitlePrivate; }; /** * @ignore */ export default WindowClient; //# sourceMappingURL=windowClient.d.ts.map