sdk.objectapi.removeobject
Home > @kittl/sdk > ObjectAPI > removeObject
ObjectAPI.removeObject() method
Removes an object from the design canvas and cleans up all associated data
This function permanently deletes an object from the design, including: - Removing it from the canvas rendering - Cleaning up the object from the state - Updating any group structures that contain the object - Triggering proper canvas re-rendering
**Key Features:** - **Complete Cleanup**: Removes object from all state structures - **Canvas Integration**: Properly removes object from fabric.js canvas - **Group Management**: Updates parent groups and group structures - **State Consistency**: Maintains design state integrity - **History Support**: Operation is tracked for undo/redo functionality
**What Gets Removed:** - Object data from the design state - Canvas representation and rendering - References in group structures - Any associated metadata
This is a destructive operation that cannot be easily reversed without using the undo functionality. Users should be prompted for confirmation when removing important design elements.
Signature:
removeObject(params: RemoveObjectParams, opts?: DesignApiOptions): RemoveObjectResult;
Parameters
Parameter | Type | Description |
|---|---|---|
params | Configuration parameters for removing the object | |
opts | (Optional) Additional options for the design API operation |
Returns:
Result object containing the removed object ID
Exceptions
When the specified object ID is not found in the design state
When the object ID is invalid or empty
When the object cannot be removed due to dependencies
Example
const objectApi = new ObjectAPI(projectManager, store);
// Remove a design object
const result = await objectApi.removeObject({
id: 'text-element-456'
});
// result: { id: 'text-element-456' }
// Remove with batch operations
const batchClient = new BatchClient();
await objectApi.removeObject({
id: 'background-shape-789'
}, { batchClient });