import { Meta, Source } from '@storybook/addon-docs/blocks'

<Meta title='@dxtmisha/en/figma-code/Classes/FigmaFramesSelected - Managing selected frames'/>

# Class `FigmaFramesSelected`

A static utility class for managing a list of frame identifiers selected by the user within the plugin context. It handles data persistence using Figma's storage and ensures synchronization between the plugin logic and the user interface.

## Key Features

- **Data Persistence** — The list of selected IDs is saved via `FigmaStorage`, allowing the selection to persist across plugin sessions.
- **Bi-directional Sync** — The `send()` method initializes listeners for UI messages, enabling seamless updates to the selection list.
- **Efficient Caching** — Uses an internal cache to provide instant access to the selection list without frequent storage reads.

## Initialization

Since this is a static class, no instantiation is required. Typically, you only need to call the communication setup in your main plugin file.

```typescript
import { FigmaFramesSelected } from '@dxtmisha/figma-code'

// Setup listeners for UI messages
FigmaFramesSelected.send()
```

## Methods

### Selection Management

Methods for interacting with the current list of selected frame IDs.

- `has(id: string): boolean` — Checks if a specific frame ID is in the selection list.
- `get(): string[]` — Retrieves the current list of selected frame IDs (uses cache).
- `add(id: string): void` — Adds a frame ID to the list and persists the change.
- `remove(id: string): void` — Removes a frame ID from the list and persists the change.
- `toggle(id: string, selected: boolean): void` — Adds or removes an ID based on the `selected` flag.

### Communication

Methods for synchronizing state with the UI.

- `send(): void` — Sets up `FigmaPluginMessenger` listeners to handle selection updates from the UI.
