Skip to main content

sdk.stateapi

Home > @kittl/sdk > StateAPI

StateAPI interface

API for design state operations, including implementing sub-states into the main design.

Signature:

export interface StateAPI 

Methods

Method

Description

implementSubState(params, opts)

Implements a sub-state into the main design by duplicating it with new unique IDs

This function takes a partial design state (sub-state) and integrates it into the current design by creating a complete copy with newly generated UUIDs for all boards and group structures. This is useful for duplicating, importing, or cloning portions of a design without ID conflicts.

**Key Features:** - **ID Regeneration**: Generates new UUIDs for all boards and group structures - **Deep Reference Updates**: Updates all ID references throughout the state tree - **Key Transformation**: Updates object keys to match new IDs - **Immutability**: Original input state remains unchanged - **Patch Integration**: Automatically generates patches for state updates

**What Gets Transformed:** - Board IDs and all references to them - Group structure IDs and their relationships - Object keys in boards and groupStructures collections - Keys in boardsIndices and groupStructuresIndices - All string references throughout nested objects (boardId, groupStructureId, parentId, etc.)

**Processing Steps:** 1. Creates a deep clone of the input state 2. Generates new UUIDs for all boards and group structures 3. Traverses and replaces all ID values in properties 4. Traverses and replaces all object keys that match old IDs 5. Builds UPSERT patches for all transformed entities 6. Returns the transformed state with new IDs

This is particularly useful for operations like: - Duplicating pages or artboards - Importing design templates - Copying design elements between projects - Cloning group structures with all relationships intact