import type { IShapeBuilderInfo } from './f-shape'; import { FWorksheet } from '@univerjs/sheets/facade'; import { FConnectorShape } from './f-connector-shape'; import { FShape } from './f-shape'; /** * Parameters for connecting shapes via a connector. */ export interface IConnectShapesParams { /** The connector/line shape to update. */ connector: FShape; /** Optional start target. If provided, connects the connector's start to this shape's connection site. */ startTarget?: { shape: FShape; connectionSiteIndex: number; }; /** Optional end target. If provided, connects the connector's end to this shape's connection site. */ endTarget?: { shape: FShape; connectionSiteIndex: number; }; } /** * @ignore */ export interface IFWorksheetShapeMixin { /** * Adds a new shape to this sheet. * @param {IShapeBuilderInfo} shapeBuilderInfo - The shape builder info returned by `FShape.build()`. * @returns {Promise} - Whether the shape was inserted successfully. * * @example * ```ts * const fWorkbook = univerAPI.getActiveWorkbook(); * const fWorksheet = fWorkbook.getActiveSheet(); * * // Create a rectangle shape at cell B2. * const shapeInfo = fWorksheet.newShape() * .setShapeType(univerAPI.Enum.ShapeTypeEnum.Rect) * .setPosition(1, 1, 0, 0) * .setWidth(200) * .setHeight(200) * .setStrokeColor('#000000') * .build(); * await fWorksheet.insertShape(shapeInfo); * ``` */ insertShape(shapeBuilderInfo: IShapeBuilderInfo): Promise; /** * Updates an existing shape on this sheet. * @param {IShapeBuilderInfo} shapeBuilderInfo - The shape builder info returned by `FShape.build()`. * @returns {Promise} - Whether the shape was updated successfully. * * @example * ```ts * const fWorkbook = univerAPI.getActiveWorkbook(); * const fWorksheet = fWorkbook.getActiveSheet(); * * // Create a rectangle shape at cell B2. * const shapeInfo = fWorksheet.newShape() * .setShapeType(univerAPI.Enum.ShapeTypeEnum.Rect) * .setPosition(1, 1, 0, 0) * .build(); * await fWorksheet.insertShape(shapeInfo); * * // Get all shapes on the active sheet. * const shapes = fWorksheet.getShapes(); * * // Update the first shape after 3 seconds. * setTimeout(async () => { * const newShapeInfo = fWorksheet.newShape(shapes[0]) * .setStrokeColor('#ff0000') * .setStrokeWidth(3) * .build(); * await fWorksheet.updateShape(newShapeInfo); * }, 3000); * ``` */ updateShape(shapeBuilderInfo: IShapeBuilderInfo): Promise; /** * Returns a builder to create a new shape for this sheet. The builder will not automatically create the shape. * You must call `build()` on the returned builder to get the shape info, then insert it via `insertShape(shapeInfo)`. * @description If an existing FShape is provided, the builder will be initialized with that shape's current properties (id, type, position, size) for updating. * @param {FShape} [existingShape] An existing shape to initialize the builder with for updating. * @returns {FShape} - A new shape builder. * * @example * ```ts * const fWorkbook = univerAPI.getActiveWorkbook(); * const fWorksheet = fWorkbook.getActiveSheet(); * * // Create a rectangle shape at cell B2 with 200x200 size. * const shapeInfo = fWorksheet.newShape() * .setShapeType(univerAPI.Enum.ShapeTypeEnum.Rect) * .setPosition(1, 1, 0, 0) * .setWidth(200) * .setHeight(200) * .build(); * await fWorksheet.insertShape(shapeInfo); * ``` */ newShape(existingShape?: FShape): FShape; /** * Returns an array of shapes on this sheet. * @returns {FShape[]} - An array of shapes on this sheet. * * @example * ```ts * const fWorkbook = univerAPI.getActiveWorkbook(); * const fWorksheet = fWorkbook.getActiveSheet(); * * // Get all shapes on the active sheet. * const shapes = fWorksheet.getShapes(); * console.log(shapes); * ``` */ getShapes(): FShape[]; /** * Removes a shape from this sheet. * @param {FShape} shape - The shape to remove. * @returns {Promise} - Whether the shape was removed successfully. * * @example * ```ts * const fWorkbook = univerAPI.getActiveWorkbook(); * const fWorksheet = fWorkbook.getActiveSheet(); * * // Create a rectangle shape. * const shapeInfo = fWorksheet.newShape() * .setShapeType(univerAPI.Enum.ShapeTypeEnum.Rect) * .setPosition(1, 1, 0, 0) * .build(); * await fWorksheet.insertShape(shapeInfo); * * // Get all shapes on the active sheet. * const shapes = fWorksheet.getShapes(); * * // Remove the first shape after 3 seconds. * setTimeout(async () => { * await fWorksheet.removeShape(shapes[0]); * console.log(fWorksheet.getShapes()); * }, 3000); * ``` */ removeShape(shape: FShape): Promise; /** * Connects a connector (line) shape's endpoints to basic shapes' connection sites. * At least one of `startTarget` or `endTarget` must be provided. If an endpoint is not provided, * its existing connection (if any) is preserved, or it remains as a free point. * * This method requires the sheet to be active (has a render context). * * @param {IConnectShapesParams} params - Parameters specifying the connector and target shapes. * @returns {Promise} - Whether the connection was established successfully. * * @example * ```ts * const fWorkbook = univerAPI.getActiveWorkbook(); * const fWorksheet = fWorkbook.getActiveSheet(); * * // Get all shapes on the sheet. * const shapes = fWorksheet.getShapes(); * const basicShapes = shapes.filter((s) => !s.isLineShape()); * const connectors = shapes.filter((s) => s.isLineShape()); * * if (connectors.length > 0 && basicShapes.length >= 2) { * // Connect the first connector's start to the first basic shape's cxn site 0, * // and the end to the second basic shape's cxn site 2. * await fWorksheet.connectShapes({ * connector: connectors[0], * startTarget: { shape: basicShapes[0], connectionSiteIndex: 0 }, * endTarget: { shape: basicShapes[1], connectionSiteIndex: 2 }, * }); * } * ``` */ connectShapes(params: IConnectShapesParams): Promise; /** * Returns a builder to create a new connector (line) shape for this sheet. The builder will not automatically create the connector. * You must call `build()` on the returned builder to get the shape info, then insert it via `insertShape(shapeInfo)`. * @description If an existing FShape is provided, the builder will be initialized with that shape's current properties (id, type, position, size) for updating. * @param {FShape} [existingShape] An existing connector shape to initialize the builder with for updating. * @returns {FConnectorShape} - A new connector shape builder. * * @example * ```ts * const fWorkbook = univerAPI.getActiveWorkbook(); * const fWorksheet = fWorkbook.getActiveSheet(); * * // Create a straight connector with arrows at cell B2 with 200x100 size. * const connectorInfo = fWorksheet.newConnector() * .setShapeType(univerAPI.Enum.ShapeTypeEnum.StraightConnector1) * .setPosition(1, 1, 0, 0) * .setWidth(200) * .setHeight(100) * .setStartArrowType(univerAPI.Enum.ShapeArrowTypeEnum.Arrow) * .setEndArrowType(univerAPI.Enum.ShapeArrowTypeEnum.Arrow) * .setStrokeColor('#000000') * .setStrokeWidth(2) * .build(); * await fWorksheet.insertShape(connectorInfo); * ``` */ newConnector(existingShape?: FShape): FConnectorShape; } export declare class FWorksheetShapeMixin extends FWorksheet implements IFWorksheetShapeMixin { insertShape(shapeBuilderInfo: IShapeBuilderInfo): Promise; updateShape(shapeBuilderInfo: IShapeBuilderInfo): Promise; newShape(existingShape?: FShape): FShape; newConnector(existingShape?: FShape): FConnectorShape; getShapes(): FShape[]; removeShape(shape: FShape): Promise; connectShapes(connectParams: IConnectShapesParams): Promise; /** * @ignore */ private _preloadShapeProperties; /** * @ignore */ private _resolveEndpoints; /** * @ignore */ private _resolveExistingOrFreeEndpoint; } /** * @ignore */ declare module '@univerjs/sheets/facade' { interface FWorksheet extends IFWorksheetShapeMixin { } }