import type { FWorksheet } from '@univerjs/sheets/facade'; import { FSheetChart } from './f-chart'; /** @ignore */ export interface IFSheetChartHostMixin { /** * Returns the chart's current host worksheet, including after moves and undo/redo. * The host is where the chart is placed, which may differ from its source data worksheet. * * @returns {FWorksheet | null} The current host, or null if the chart or its host no longer exists. * @example * ```ts * // Query where an existing chart is placed, rather than where its source cells are. * const fWorkbook = univerAPI.getActiveWorkbook(); * const fChart = fWorkbook?.getActiveSheet().getCharts()[0]; * const fHostSheet = fChart?.getWorksheet(); * if (fHostSheet) { * console.log(fHostSheet.getSheetId(), fHostSheet.getSheetName()); * } * ``` */ getWorksheet(): FWorksheet | null; /** * Checks whether this chart is the current primary chart of its Chart Sheet. * The chart created with insertChartSheet is primary; additional charts moved in from Grid are children. * This query reads the current role and does not change it. * * @returns {boolean} True for the current primary chart; false for children or a removed chart. * @example * ```ts * // Sales Report already contains a primary chart and additional child charts. * const fWorkbook = univerAPI.getActiveWorkbook(); * const fChartSheet = fWorkbook?.getSheetByName('Sales Report'); * fChartSheet?.getCharts().forEach((fChart) => { * // The primary reports true; each child reports false. * console.log(fChart.getId(), fChart.isPrimary()); * }); * ``` */ isPrimary(): boolean; /** * Moves this chart to an existing worksheet in the same workbook and Univer instance. * Moving a Grid chart into a Chart Sheet adds a child without replacing the primary. * A primary chart can leave only when no child charts remain; moving it out then deletes its Chart Sheet. * * @param {FWorksheet} target An existing target worksheet in the same workbook and Univer instance. * @returns {Promise} This same chart handle after the move. * @throws {CustomCommandExecutionError} If the target is invalid or the move is rejected. * @example * ```ts * // Data contains an embedded chart; Sales Report is an existing Chart Sheet. * const fWorkbook = univerAPI.getActiveWorkbook(); * const fDataSheet = fWorkbook?.getSheetByName('Data'); * const fChartSheet = fWorkbook?.getSheetByName('Sales Report'); * const fChart = fDataSheet?.getCharts()[0]; * if (fWorkbook && fChart && fChartSheet) { * await fChart.moveTo(fChartSheet); * console.log(fChart.isPrimary()); // false: moving it in adds a child, not a new primary. * console.log(fChart.getWorksheet()?.getSheetId() === fChartSheet.getSheetId()); // true * * await fWorkbook.undo(); // Move the chart back to Data. * await fWorkbook.redo(); // Move it into Sales Report again. * } * ``` */ moveTo(target: FWorksheet): Promise; } /** @ignore */ export declare class FSheetChartHostMixin extends FSheetChart implements IFSheetChartHostMixin { getWorksheet(): FWorksheet | null; isPrimary(): boolean; moveTo(target: FWorksheet): Promise; } declare module '@univerjs-pro/sheets-chart/facade' { interface FSheetChart extends IFSheetChartHostMixin { } }