{"version":3,"file":"PanelContext.cjs","sources":["../../../../src/components/PanelChrome/PanelContext.ts"],"sourcesContent":["import { createContext, useContext } from 'react';\n\nimport {\n  EventBusSrv,\n  EventBus,\n  DashboardCursorSync,\n  AnnotationEventUIModel,\n  ThresholdsConfig,\n  CoreApp,\n  DataFrame,\n  DataLinkPostProcessor,\n} from '@grafana/data';\n\nimport { AdHocFilterItem } from '../Table/types';\n\nimport { OnSelectRangeCallback, SeriesVisibilityChangeMode } from './types';\n\n/** @alpha */\nexport interface PanelContext {\n  /** Identifier for the events scope */\n  eventsScope: string;\n  eventBus: EventBus;\n\n  /** Dashboard panels sync */\n  sync?: () => DashboardCursorSync;\n\n  /** Information on what the outer container is */\n  app?: CoreApp | 'string';\n\n  /**\n   * Called when a component wants to change the color for a series\n   *\n   * @alpha -- experimental\n   */\n  onSeriesColorChange?: (label: string, color: string) => void;\n\n  onToggleSeriesVisibility?: (label: string, mode: SeriesVisibilityChangeMode) => void;\n\n  canAddAnnotations?: () => boolean;\n  canEditAnnotations?: (dashboardUID?: string) => boolean;\n  canDeleteAnnotations?: (dashboardUID?: string) => boolean;\n  canExecuteActions?: () => boolean;\n  onAnnotationCreate?: (annotation: AnnotationEventUIModel) => void;\n  onAnnotationUpdate?: (annotation: AnnotationEventUIModel) => void;\n  onAnnotationDelete?: (id: string) => void;\n\n  /**\n   * Called when a user selects an area on the panel, if defined will override the default behavior of the panel,\n   * which is to update the time range\n   */\n  onSelectRange?: OnSelectRangeCallback;\n\n  /**\n   * Used from visualizations like Table to add ad-hoc filters from cell values\n   */\n  onAddAdHocFilter?: (item: AdHocFilterItem) => void;\n\n  /**\n   * Returns filters based on existing grouping or an empty array\n   */\n  getFiltersBasedOnGrouping?: (items: AdHocFilterItem[]) => AdHocFilterItem[];\n  /**\n   *\n   * Used to apply multiple filters at once\n   */\n  onAddAdHocFilters?: (items: AdHocFilterItem[]) => void;\n  /**\n   * Enables modifying thresholds directly from the panel\n   *\n   * @alpha -- experimental\n   */\n  canEditThresholds?: boolean;\n\n  /**\n   * Shows threshold indicators on the right-hand side of the panel\n   *\n   * @alpha -- experimental\n   */\n  showThresholds?: boolean;\n\n  /**\n   * Called when a panel wants to change default thresholds configuration\n   *\n   * @alpha -- experimental\n   */\n  onThresholdsChange?: (thresholds: ThresholdsConfig) => void;\n\n  /** For instance state that can be shared between panel & options UI  */\n  instanceState?: any;\n\n  /** Update instance state, this is only supported in dashboard panel context currently */\n  onInstanceStateChange?: (state: any) => void;\n\n  /**\n   * Called when a panel is changing the sort order of the legends.\n   */\n  onToggleLegendSort?: (sortBy: string) => void;\n\n  /**\n   * Optional, only some contexts support this. This action can be cancelled by user which will result\n   * in a the Promise resolving to a false value.\n   */\n  onUpdateData?: (frames: DataFrame[]) => Promise<boolean>;\n\n  /**\n   * Optional supplier for internal data links. If not provided a link pointing to Explore will be generated.\n   * @internal\n   * @deprecated Please use DataLinksContext instead. This property will be removed in next major.\n   */\n  dataLinkPostProcessor?: DataLinkPostProcessor;\n}\n\nexport const PanelContextRoot = createContext<PanelContext>({\n  eventsScope: 'global',\n  eventBus: new EventBusSrv(),\n});\n\n/**\n * @alpha\n */\nexport const PanelContextProvider = PanelContextRoot.Provider;\n\n/**\n * @alpha\n */\nexport const usePanelContext = () => useContext(PanelContextRoot);\n"],"names":["createContext","EventBusSrv","useContext"],"mappings":";;;;;;;;AAgHO,MAAM,mBAAmBA,mBAAA,CAA4B;AAAA,EAC1D,WAAA,EAAa,QAAA;AAAA,EACb,QAAA,EAAU,IAAIC,gBAAA;AAChB,CAAC;AAKM,MAAM,uBAAuB,gBAAA,CAAiB;AAK9C,MAAM,eAAA,GAAkB,MAAMC,gBAAA,CAAW,gBAAgB;;;;;;"}