import type * as React from 'react'; import { type Store } from '@mui/x-internals/store'; import type { MergeSignaturesProperty, OptionalIfEmpty } from "./helpers.js"; import type { ChartCorePluginSignatures } from "../corePlugins/index.js"; import { type ChartSeriesConfig } from "./seriesConfig/index.js"; import { type ChartState } from "./chart.js"; export interface ChartPluginOptions { /** * An imperative api available for internal use. */ instance: ChartUsedInstance; /** * The parameters after being processed with the default values. */ params: ChartUsedDefaultizedParams; /** * The store that can be used to access the state of other plugins. */ store: ChartUsedStore; /** * Reference to the main svg element. */ svgRef: React.RefObject; /** * Reference to the chart root element. */ chartRootRef: React.RefObject; /** * All the plugins that are used in the chart. */ plugins: ChartPlugin[]; /** * All the series configurations that are currently loaded. */ seriesConfig: ChartSeriesConfig; } export type ChartResponse = OptionalIfEmpty<'publicAPI', TSignature['publicAPI']> & OptionalIfEmpty<'instance', TSignature['instance']>; export type ChartPluginSignature = { /** * The raw properties that can be passed to the plugin. */ params: T extends { params: {}; } ? T['params'] : {}; /** * The params after being processed with the default values. */ defaultizedParams: T extends { defaultizedParams: {}; } ? T['defaultizedParams'] : {}; /** * An imperative api available for internal use. */ instance: T extends { instance: {}; } ? T['instance'] : {}; /** * The state is the mutable data that will actually be stored in the plugin state and can be accessed by other plugins. */ state: T extends { state: {}; } ? T['state'] : {}; /** * The public imperative API that will be exposed to the user. * Accessed through the `apiRef` property of the plugin. */ publicAPI: T extends { publicAPI: {}; } ? T['publicAPI'] : {}; /** * Any plugins that this plugin depends on. */ dependencies: T extends { dependencies: Array; } ? T['dependencies'] : []; /** * Same as dependencies but the plugin might not have been initialized. */ optionalDependencies: T extends { optionalDependencies: Array; } ? T['optionalDependencies'] : []; }; export type ChartAnyPluginSignature = ChartPluginSignature<{ params: any; defaultizedParams: any; instance: any; publicAPI: any; state: any; dependencies: any; optionalDependencies: any; }>; type ChartRequiredPlugins = [...ChartCorePluginSignatures, ...TSignature['dependencies']]; type PluginPropertyWithDependencies = TSignature[TProperty] & MergeSignaturesProperty, TProperty> & Partial>; export type ChartUsedParams = MergeSignaturesProperty & PluginPropertyWithDependencies; type ChartUsedDefaultizedParams = PluginPropertyWithDependencies; export type ChartUsedInstance = PluginPropertyWithDependencies & { /** * Private property only defined in TypeScript to be able to access the plugin signature from the instance object. */ $$signature: TSignature; }; export type ChartUsedStore = Store>; export type ChartPlugin = { /** * The main function of the plugin that will be executed by the chart. * * This should be a valid React `use` function, as it will be executed in the render phase and can contain hooks. */ (options: ChartPluginOptions): ChartResponse; /** * The initial state is computed after the default values are applied. * It set up the state for the first render. * Other state modifications have to be done in effects and so could not be applied on the initial render. * * @param {ChartUsedDefaultizedParams} params The parameters after being processed with the default values. * @param {MergeSignaturesProperty, 'state'>} currentState The current state of the chart. * @param {ChartSeriesConfig} seriesConfig The series configuration. * * @returns {TSignature['state']} The initial state of the plugin. */ getInitialState?: (params: ChartUsedDefaultizedParams, currentState: MergeSignaturesProperty, 'state'>, seriesConfig: ChartSeriesConfig) => TSignature['state']; /** * An object where each property used by the plugin is set to `true`. */ params: Record; /** * A function that receives the parameters and returns the parameters after being processed with the default values. * * @param {ChartUsedParams} options The options object. * @param {ChartUsedParams['params']} options.params The parameters before being processed with the default values. * @returns {TSignature['defaultizedParams']} The parameters after being processed with the default values. */ getDefaultizedParams?: (options: { params: ChartUsedParams; }) => TSignature['defaultizedParams']; }; export {};