import { EventEmitter } from "eventemitter3"; import * as GoldenLayout from "golden-layout"; import * as React from "react"; import { IEnvironmentMethods } from "./environment"; import { ComponentRegistry } from "./registry"; import { DragSource, FallbackHandler, HigherOrderComponent, IItemConfigurationOptions, ItemConfigType, ItemVisitor, IWorkbenchState, PanelPredicate, WorkbenchStateTransformer } from "./types"; export declare class Workbench extends EventEmitter { private _blockedEvents; private _config; private _configDefaults; private _dragSources; private _domNode; private _layout; private _nextUnblockId; private _registry; private _stateGuard; /** * The environment that the workbench lives in. Methods of this object are * used to communicate with the application that hosts the workbench. */ environment: IEnvironmentMethods; /** * An optional React higher-order component that will be called with every * React component that is being registered in the workbench. You can use this * in conjunction with HOC libraries (e.g., `recompose`) to provide context * for React components or to wrap them in another component. * * This feature replaces the `contextProvider` property in previous versions * of `react-flexible-workbench`; you can use the `withContext()` HOC from * `recompose` to achieve the same functionality. * * Note that changing this property when the workbench is already rendered * will not affect the workbench. */ hoc: HigherOrderComponent | undefined; /** * Constructor. Creates an empty workbench. */ constructor(); /** * Alias to the `addListener()` method to allow the workbench object to be * used with `react-event-listener` or other classes that expect a DOM-like * API. * * DOM event APIs typically use all-lowercase event names; however, the * workbench uses mixed-case event names (e.g., `stateChanged`). Therefore, * this method will map all-lowercase event names to their correctly capitalized * versions for all events that are officially supported by `golden-layout` */ addEventListener(eventName: string | symbol, listener: EventEmitter.ListenerFn): void; /** * Adds a new item to the workbench programmatically. * * @param nameOrComponent the name of the component constructor or the * React component * @param options additional options that can be used to tweak the * configuration object */ addNewItem(nameOrComponent: string | React.ComponentType, options?: Partial): void; /** * Adds a new item to the workbench, given a configuration object that * defines how the item should be added. * * This is a low-level function; you probably need `addNewItem()` instead. * * @param config the item configuration object */ addNewItemWithConfiguration(config: GoldenLayout.ItemConfigType): void; /** * Brings the given panel to the front in a workbench if the panel is * participating in a stack. * * @param panel the panel to bring to the front or its ID * @return whether the panel was found and brought to the front successfully */ bringToFront(panel: string | GoldenLayout.ContentItem): boolean; /** * Configures the workbench with the given configuration object. See the * documentation of golden-layout for more details. * * This function may be called multiple times. Subsequent calls will merge * the new configuration values into the ones that were previously applied. * * @param {GoldenLayout.Config} config the configuration object * @param clean whether the merging should be performed with a clean slate, * i.e. not reusing the existing configuration */ configure(config: GoldenLayout.Config, { clean }?: { clean?: boolean; }): void; /** * Registers a new item to be used as a drag source in the workbench. The * item can then be dragged to the workbench to create a new panel. * * @param element the element to register in the workbench as a drag source * @param config the item that will be created when the item is dragged to * the workbench * @return an opaque object that identifies the drag source and that can be * passed to removeDragSource() later on to remove it */ createDragSource(element: HTMLElement | JQuery, itemConfiguration: GoldenLayout.ItemConfigType): DragSource; /** * Creates a new item configuration object for the given registered component * constructor name or React component. * * @param nameOrComponent the name of the component constructor or the * React component * @param options additional options that can be used to tweak the * configuration object */ createItemConfigurationFor(nameOrComponent: string | React.ComponentType, options?: Partial): ItemConfigType; /** * Destroys the workbench and removes it from the DOM. */ destroy(): void; /** * Detaches the workbench and removes it from the DOM, leaving the * possibility open to re-mount it later. */ detach(): void; /** * Ensures that the given component name or React component is registered * in the workbench. * * When the input argument is a React component and it was not registered yet * in the workbench, registers it under the display name of the component. * * @param nameOrComponent the name of the component constructor or the React * component to check * @return the name corresponding to the input argument * @throws Error if the input argument is a component constructor name and * it has not been registered yet */ ensureComponentIsRegistered(nameOrComponent: string | React.ComponentType): string; /** * Iterates over all panels in the workbench and finds the first one that * matches the given predicate. * * @param pred the predicate */ findFirstPanelMatching(pred: PanelPredicate): GoldenLayout.ContentItem | undefined; /** * Iterates over all panels in the workbench and finds the one that has the * given ID. * * @param id the ID of the panel to look for * @param func [description] */ findPanelById(id: string): GoldenLayout.ContentItem | undefined; /** * Calls the given function for each container and panel in the workbench, * in DFS order. */ forEach(func: ItemVisitor): void; /** * Calls the given function for each *visible* container and panel in the * workbench, in DFS order. Panels that are hidden in a stack will not be * visited. */ forEachVisible(func: ItemVisitor): void; /** * Fallback component or function that is used to resolve errors when the * user tries to create a component that is not registered in the workbench. * The function will be called with the registered name of the component that * the user tried to create and its props, and it must return a React node * to render as fallback. */ get fallback(): FallbackHandler | undefined; set fallback(value: FallbackHandler | undefined); /** * Returns the raw Golden-Layout object behind this workbench. */ get layout(): GoldenLayout | undefined; /** * Registry that keeps track of the association between component names * (strings) and the corresponding React components or component factories. */ get registry(): ComponentRegistry; /** * Returns a serialized representation of the current state of the workbench. * * Note that the state object returned here is not the full state of the * workbench, only the part that encodes where the panels are and how they * are sized relative to each other. */ getState(): IWorkbenchState; /** * Returns whether the workbench is currently attached to a DOM node. */ get isRendered(): boolean; /** * Removes the given drag source from the workbench so it cannot be used to * drag new items into the workbench any more. */ removeDragSource(dragSource: DragSource): void; /** * Alias to the `removeListener()` method to allow the workbench object to be * used with `react-event-listener` or other classes that expect a DOM-like * API. */ removeEventListener(eventName: string | symbol, listener?: EventEmitter.ListenerFn): void; /** * Renders the workbench in the given node of the page. * * @param node the node to render the workbench into; omitting it means that * the workbench must fill the entire page. */ render(node?: Element | JQuery | Text | string): void; /** * Restores a saved state previously obtained by getState(). */ restoreState(state: IWorkbenchState): void; /** * Sets the state transformer function that takes a workbench state object * that is about to be applied to the workbench, and returns another one * (or the same one after some modifications) that _will_ actually be loaded * instead of the original one. This can be used to prevent the user from * seeing certain panels when a previously saved state object is restored. * * The default state transformer function is the identity function. */ setStateGuard(func: WorkbenchStateTransformer): void; /** * Updates the size of the workbench to the given values. If no values * are given, the workbench will measure the DOM node it is attached to * and adjusts its own size to the size of that node. */ updateSize(width?: number, height?: number): void; /** * Blocks the next event with the given name coming from the wrapped workbench * instance so it is not re-dispatched from this instance. * * @param event the name of the event to block * @param duration the duration for which the event will be blocked, in * milliseconds */ private _blockNextEvent; /** * Creates a new golden-layout object from the current * configuration object and the DOM node that the workbench is associated * to. * * The method must be called only after the workbench was associated to a * DOM node. * * This method takes care of post-processing the provided configuration * object such that the appropriate context is provided for React components * where needed. * * @return the newly created golden-layout object */ private _createLayoutFromConfig; /** * Returns the golden-layout object associated to the workbench * if it has been created already yet, or throws an exception if the workbench * is not ready. */ private _getLayout; /** * Event handler that is called when the DOM node hosting the workbench * has been resized. */ private _onWorkbenchResized; /** * Proposes a location for a new item in the workbench. * * The function will find the largest visible panel in the workbench and then * it will attempt to split the panel in half. * * @return the place where a new item should be added in the workbench */ private _proposePlaceForNewItem; /** * Re-dispatches the given event originating from the wrapped workbench * object, optionally swallowing certain events that we want to suppress. */ private _redispatch; /** * Sets the golden-layout object associated to the workbench. * Also takes care of registering or deregistering all the event handlers * that the Workbench instance might be interested in. */ private _setLayout; private _resolve; }