import { TocItem } from './Item.js'; import '@arcgis/core/layers/Layer'; import '@arcgis/core/layers/support/Sublayer'; import '@arcgis/core/layers/support/WMSSublayer'; import '@arcgis/core/Map'; /** * Provides additional action definitions to the TOC. * * Use the interface name `toc.ActionDefinitionFactory` to register an implementation with the system. */ interface ActionDefinitionFactory { /** * A list of action ids supported by this factory. * * Ids listed here can be used as an argument to {@link createDefinitionById}. */ readonly supportedIds: readonly string[]; /** * Constructs an action definition for the given id. */ createDefinitionById(id: string): ActionDefinition | undefined; } /** * Properties shared by all action definitions. */ interface BaseActionDefinition { /** This action's unique id. */ readonly id: string; /** The type of this action. */ readonly type: ActionType; /** A textual label (or title) for this action. */ readonly label?: string; /** * Returns `true` if the action shall be available for the given item. * Should return `false` otherwise. * * Note that this method may be asynchronous (i.e. return a `Promise`). */ isVisibleForItem?(item: TocItem): boolean | Promise; } /** Supported action types. */ type ActionType = "button" | "button-row" | "slider" | "text-label"; /** An action definition that provides a text label. */ interface TextLabelActionDefinition extends BaseActionDefinition { readonly type: "text-label"; /** Icon of the menu entry. */ readonly icon?: string; /** * Threshold that defines when to auto shorten the text and * provide a "show more" link instead. * * If set to -1 text is never truncated. */ readonly truncationThreshold?: number; /** Label for the "show more" link. */ readonly labelMore?: string; /** * Returns a text representation for the given item. */ valueOf(item: TocItem): string | undefined; /** * Called when the "show more" link is clicked. * Must be implemented if {@link truncationThreshold} is used. */ trigger?(item: TocItem): void; } /** An action definition that provides a button. */ interface ButtonActionDefinition extends BaseActionDefinition { readonly type: "button"; /** Icon of the menu entry. */ readonly icon?: string; /** Method to decide if the action should be shown as disabled (optional). */ isDisabledForItem?(item: TocItem): boolean; /** Called if the menu item is clicked. */ trigger(item: TocItem): void; } /** An action definition that provides multiple buttons. */ interface ButtonRowActionDefinition extends BaseActionDefinition { readonly type: "button-row"; /** * Icons for the action buttons. */ readonly icons: readonly string[]; /** * Aria labels for the action buttons. * The tooltip values in the array should match the order given in the `icons` property. */ readonly actionLabels?: readonly string[]; /** * Tooltips for the action buttons. * The tooltip values in the array should match the order given in the `icons` property. */ readonly actionTooltips?: readonly string[]; /** * Method to decide if the action should be shown as disabled (optional). * The boolean values in the returned array should match the order given in the `icons` property. */ isDisabledForItem?(item: TocItem): boolean[]; /** * Called if the menu item is clicked. * The `buttonIndex` identifies the target button in this row. */ trigger(item: TocItem, buttonIndex: number): void; } /** An action definition that provides a slider. */ interface SliderActionDefinition extends BaseActionDefinition { readonly type: "slider"; /** Icon of the menu entry. */ readonly icon?: string; /** Label of the left side of the slider. */ readonly fromLabel?: string; /** Icon of the left side of the slider. */ readonly fromIcon?: string; /** Label of the right side of the slider. */ readonly toLabel?: string; /** Icon of the right side of the slider. */ readonly toIcon?: string; /** Minimum slider value (left side). */ readonly min: number; /** Maximum slider value (right side). */ readonly max: number; /** Increment value of the slider. */ readonly step: number; /** This method must return the current value of the item. */ valueOf(item: TocItem): number; /** This method is called if the value of the slider was changed. */ changeValueOf(item: TocItem, value: number): void; } /** * Defines an action within the TOC. */ type ActionDefinition = TextLabelActionDefinition | ButtonActionDefinition | ButtonRowActionDefinition | SliderActionDefinition; export type { ActionDefinition, ActionDefinitionFactory, ActionType, BaseActionDefinition, ButtonActionDefinition, ButtonRowActionDefinition, SliderActionDefinition, TextLabelActionDefinition };