import type { CancelToken } from "@vertigis/arcgis-extensions/support/Cancellable"; import type { TranslatableText } from "@vertigis/viewer-spec/app-config/common/TranslatableText"; import type { ComponentType, ReactNode } from "react"; import type { Entity } from "../AppConfig"; import type { AttributeValue, Layout, LayoutNode, LayoutUrl, LayoutXml } from "../layout"; import type { Model } from "../models"; import type { ServiceBase } from "../services"; import type { ClosableDialogProps } from "./ClosableDialog"; /** * Properties for the dialog component when using displayDialog(). */ export type DialogProps = Omit & {}; /** * Creates a closeable dialog given a close function. */ export type CloseableDialogFactory = (closeDialog: () => void) => ReactNode; /** * A definition for a transient component. */ export interface TransientDefinition extends Omit { /** * Either a rendered component to display, or a factory. */ component: ReactNode | CloseableDialogFactory; /** * The parent node of this transient. */ parent?: string | LayoutNode | Entity; /** * Any additional layout attributes to use, eg: 'slot' to target a specific * map area. */ attributes?: Record; /** * Whether to display a header with a title and a close button. */ useHeader?: boolean; /** * The title to use in the header. */ title?: TranslatableText; /** * Optional icon that may be used by the transient UI container. */ icon?: string; /** * A callback for when the transient is closed. */ onClosed?: () => void; /** * A cancel token for external cancellation. */ cancelToken?: CancelToken; } /** * Implements operations and commands pertaining to the user interface. */ export interface UIService extends ServiceBase { /** * The current layout for the application, if there is one. */ readonly layout: Layout; /** * Loads the specified layout and renders it into the DOM. * * @param layout The layout to load. */ loadLayout(layout: LayoutUrl | LayoutXml | Layout): Promise; /** * Displays a component inside a modal dialog. * * @param component The component to display, or a factory that gets passed * a close function and returns the component. The latter is for when the * dialog content wants to control closing the dialog (e.g. OK button). * @param props Properties for the dialog itself. * @param cancelToken A cancellation token that will close the dialog if * triggered. * @param DialogComponent An optional replacement for the dialog component * itself. */ displayDialog(component: ReactNode | CloseableDialogFactory, props?: DialogProps, cancelToken?: CancelToken, DialogComponent?: ComponentType): Promise; /** * Temporarily displays a component. If a parent is specified it will be * shown as a transient child of an existing node, otherwise the component * will be shown inside a modal dialog. * * @param args The definition of this transient component. */ displayTransient(args: TransientDefinition): Promise; /** * Get the IDs of components in the current layout that are backed by the * given model. Most models are used by a single component, but in some * cases multiple components can share a model. * * @param model The model to use for the lookup. */ getComponentIds(model: Model): string[]; /** * Same as {@link getComponentIds}, but only returns activated components. * * @param model The model to use for the lookup. */ getActiveComponentIds(model: Model): string[]; /** * Gets an ordered list of component IDs that are direct children of the * given component. * * @param componentId The parent component's layout ID. */ getChildComponentIds(componentId: string): string[]; /** * Same as {@link getChildComponentIds}, but only returns activated child * components. * * @param componentId The parent component's layout ID. */ getActiveChildComponentIds(componentId: string): string[]; /** * Gets the model for a given component. * * @param componentId The component's layout ID. */ getComponentModel(componentId: string): Model; /** * Gets the models for immediate child components of given component. * * @param componentId The parent component's layout ID. */ getChildComponentModels(componentId: string): Model[]; }