UNPKG

@deephaven/golden-layout

Version:

A multi-screen javascript Layout manager

226 lines • 7.98 kB
import { BubblingEvent, EventEmitter } from '../utils'; import type { ItemConfig } from '../config'; import type LayoutManager from '../LayoutManager'; import type Tab from '../controls/Tab'; import type Stack from './Stack'; import type Component from './Component'; import type Root from './Root'; export declare function isStack(item: AbstractContentItem): item is Stack; export declare function isComponent(item: AbstractContentItem): item is Component; export declare function isRoot(item: AbstractContentItem): item is Root; export type ItemArea<C = AbstractContentItem> = { x1: number; x2: number; y1: number; y2: number; surface: number; side: 'left' | 'right' | 'top' | 'bottom' | ''; contentItem: C; }; /** * This is the baseclass that all content items inherit from. * Most methods provide a subset of what the sub-classes do. * * It also provides a number of functions for tree traversal * * @param {lm.LayoutManager} layoutManager * @param {item node configuration} config * @param {lm.item} parent * * @event stateChanged * @event beforeItemDestroyed * @event itemDestroyed * @event itemCreated * @event componentCreated * @event rowCreated * @event columnCreated * @event stackCreated * * @constructor */ export default abstract class AbstractContentItem extends EventEmitter { config: ItemConfig; type: string; contentItems: AbstractContentItem[]; parent: AbstractContentItem | null; layoutManager: LayoutManager; element: JQuery<HTMLElement>; childElementContainer?: JQuery<HTMLElement>; componentName?: string; isInitialised: boolean; isMaximised: boolean; isRoot: boolean; isRow: boolean; isColumn: boolean; isStack: boolean; isComponent: boolean; tab?: Tab; private _pendingEventPropagations; private _throttledEvents; constructor(layoutManager: LayoutManager, config: ItemConfig, parent: AbstractContentItem | null, element: JQuery<HTMLElement>); /** * Set the size of the component and its children, called recursively * * @abstract */ abstract setSize(width?: number, height?: number): void; /** * Calls a method recursively downwards on the tree * * @param functionName the name of the function to be called * @param functionArguments optional arguments that are passed to every function * @param bottomUp Call methods from bottom to top, defaults to false * @param skipSelf Don't invoke the method on the class that calls it, defaults to false */ callDownwards<N extends 'setSize' | '_$destroy' | '_$init' | '_$show'>(functionName: N, functionArguments?: Parameters<AbstractContentItem[N]>, bottomUp?: boolean, skipSelf?: boolean): void; /** * Removes a child node (and its children) from the tree * * @param contentItem */ removeChild(contentItem: AbstractContentItem, keepChild?: boolean): void; /** * Sets up the tree structure for the newly added child * The responsibility for the actual DOM manipulations lies * with the concrete item * * @param contentItem * @param index If omitted item will be appended */ addChild(contentItem: AbstractContentItem | ItemConfig, index?: number): void; /** * Replaces oldChild with newChild. This used to use jQuery.replaceWith... which for * some reason removes all event listeners, so isn't really an option. * * @param oldChild * @param newChild */ replaceChild(oldChild: AbstractContentItem, newChild: AbstractContentItem, _$destroyOldChild?: boolean): void; /** * Convenience method. * Shorthand for this.parent.removeChild( this ) */ remove(): void; /** * Removes the component from the layout and creates a new * browser window with the component and its children inside */ popout(): import("..").BrowserPopout | undefined; /** * Maximises the Item or minimises it if it is already maximised */ toggleMaximise(e?: Event): void; /** * Selects the item if it is not already selected */ select(): void; /** * De-selects the item if it is selected */ deselect(): void; /** * Set this component's title * @param title */ setTitle(title: string): void; /** * Checks whether a provided id is present * @param id * @returns isPresent */ hasId(id: string): boolean | undefined; /** * Adds an id. Adds it as a string if the component doesn't * have an id yet or creates/uses an array * @param id */ addId(id: string): void; /** * Removes an existing id. Throws an error * if the id is not present * @param id */ removeId(id: string): void; /**************************************** * SELECTOR ****************************************/ getItemsByFilter(filter: (item: AbstractContentItem) => boolean): AbstractContentItem[]; getItemsById(id: string): AbstractContentItem[]; getItemsByType(type: string): AbstractContentItem[]; getComponentsByName(componentName: string): unknown[]; /**************************************** * PACKAGE PRIVATE ****************************************/ _$getItemsByProperty(key: keyof AbstractContentItem, value: string): AbstractContentItem[]; _$setParent(parent: AbstractContentItem | null): void; _$highlightDropZone(x: number, y: number, area: ItemArea): void; _$onDrop(contentItem: AbstractContentItem, area: ItemArea): void; _$hide(): void; _$show(): void; _callOnActiveComponents(methodName: 'hide' | 'show'): void; /** * Destroys this item ands its children */ _$destroy(): void; /** * Returns the area the component currently occupies in the format * * { * x1: int * x2: int * y1: int * y2: int * contentItem: contentItem * } */ _$getArea(element?: JQuery<HTMLElement>): ItemArea<this> | null; /** * The tree of content items is created in two steps: First all content items are instantiated, * then init is called recursively from top to bottem. This is the basic init function, * it can be used, extended or overwritten by the content items * * Its behaviour depends on the content item */ _$init(): void; /** * Emit an event that bubbles up the item tree. * * @param name The name of the event */ emitBubblingEvent(name: string): void; /** * Private method, creates all content items for this node at initialisation time * PLEASE NOTE, please see addChild for adding contentItems add runtime * @param {configuration item node} config */ _createContentItems(config: ItemConfig): void; /** * Extends an item configuration node with default settings * @param config * @returns extended config */ _extendItemNode<TConfig extends ItemConfig>(config: TConfig): TConfig; /** * Called for every event on the item tree. Decides whether the event is a bubbling * event and propagates it to its parent * * @param name the name of the event * @param event */ _propagateEvent(name: string, event: BubblingEvent): void; /** * All raw events bubble up to the root element. Some events that * are propagated to - and emitted by - the layoutManager however are * only string-based, batched and sanitized to make them more usable * * @param name the name of the event */ _scheduleEventPropagationToLayoutManager(name: string, event: BubblingEvent): void; /** * Callback for events scheduled by _scheduleEventPropagationToLayoutManager * * @param name the name of the event */ _propagateEventToLayoutManager(name: string, event: BubblingEvent): void; } //# sourceMappingURL=AbstractContentItem.d.ts.map