npm package: @sigma-plugins/common-services-ng
Description: Angular services for Sigma plugin development
Author: Sigma Computing
Latest version: 1.0.11

# @sigma-plugins/common-services-ng

Angular services for Sigma plugin development. This package provides reusable Angular services for common Sigma plugin functionality.

## Installation

```bash
npm install @sigma-plugins/common-services-ng
```

## Peer Dependencies

Make sure you have the following peer dependencies installed:

```bash
npm install @angular/core @sigmacomputing/plugin rxjs
```

## Usage

### Import the Module

Import the `CommonServicesNgModule` in your Angular module:

```typescript
import { NgModule } from '@angular/core';
import { CommonServicesNgModule } from '@sigma-plugins/common-services-ng';

@NgModule({
  imports: [
    CommonServicesNgModule,
    // other imports...
  ],
  // ...
})
export class AppModule { }
```

### Using Individual Services

You can also import and use individual services:

```typescript
import { Injectable } from '@angular/core';
import { ConfigService, ElementDataService, VariableService, PluginService } from '@sigma-plugins/common-services-ng';

@Injectable()
export class MyService {
  constructor(
    private configService: ConfigService,
    private elementDataService: ElementDataService,
    private variableService: VariableService,
    private pluginService: PluginService
  ) {}
}
```

## Services

### ConfigService

Manages plugin configuration and provides reactive access to configuration changes.

**Methods:**
- `getConfig(): Observable<any>` - Get the full configuration object
- `getConfigKey(key: string): Observable<any>` - Get a specific configuration key

**Example:**
```typescript
this.configService.getConfig().subscribe(config => {
  console.log('Current config:', config);
});

this.configService.getConfigKey('allowExpansion').subscribe(value => {
  console.log('Allow expansion:', value);
});
```

### ElementDataService

Manages workbook element data subscriptions for different configuration IDs.

**Methods:**
- `getElementData(configId: string): Observable<WorkbookElementData>` - Subscribe to element data changes

**Example:**
```typescript
this.elementDataService.getElementData('source').subscribe(data => {
  console.log('Element data:', data);
});
```

### VariableService

Manages workbook variables with reactive subscriptions and synchronous access.

**Methods:**
- `getVariable(id: string): Observable<WorkbookVariable | undefined>` - Subscribe to variable changes
- `setVariable(id: string, ...values: unknown[]): void` - Set variable value
- `getVariableValue(id: string): WorkbookVariable | undefined` - Get current value synchronously

**Example:**
```typescript
// Subscribe to variable changes
this.variableService.getVariable('taskIdControl').subscribe(variable => {
  console.log('Variable value:', variable?.value);
});

// Set variable value
this.variableService.setVariable('taskIdControl', 'task1,task2,task3');

// Get current value synchronously
const currentValue = this.variableService.getVariableValue('taskIdControl');
```

### PluginService

Provides access to the Sigma plugin client instance.

**Methods:**
- `getPluginInstance()` - Get the Sigma plugin client instance

**Example:**
```typescript
const client = this.pluginService.getPluginInstance();
// Use client for direct plugin API access
```

## Development

### Building

```bash
npm run build
```

### Building TypeScript only

```bash
npm run build:tsc
```

## License

MIT

## Contributing

1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Commit your changes (`git commit -m 'Add some amazing feature'`)
4. Push to the branch (`git push origin feature/amazing-feature`)
5. Open a Pull Request