# Classes

Import these from `@grafloria/element`.

## Classes

### `CardHandle`

```ts
abstract class CardHandle
```

**Methods**

- `constructor( protected readonly api: HandleApi, readonly id: string )`
- `get exists(): boolean`
- `get node(): unknown` — Escape hatch to the underlying NodeModel (typed loosely on purpose).
- `get width(): number`
- `get height(): number`
- `abstract get name(): string`
- `abstract rename(name: string): Promise<boolean>` — Rename the card title — one undoable step.
- `abstract resize(size: { width?: number; height?: number }): Promise<boolean>` — Resize the card — one undoable step (kit body scrolls when capped).
- `select(): void`
- `async undo(): Promise<void>`
- `async redo(): Promise<void>`
- `onRowSelect( cb: (e: { field: ErField | null; selected: RowRef | null }) => void ): () => void` — Row-selection events for THIS card only (the kit's `axk:row-select`,
filtered). ER cards resolve the selection to a typed {@link ErField} when
possible. Returns an unbind function.

### `ErColumnList`

The columns collection of an {@link ErTable}. Iterable of {@link ErField}.

```ts
class ErColumnList implements Iterable<ErField>
```

**Methods**

- `constructor(private readonly table: ErTable)`
- `get length(): number`
- `names(): string[]`
- `at(index: number): ErField | undefined`
- `get(name: string): ErField | undefined`
- `[Symbol.iterator](): Iterator<ErField>`
- `add(column: ErColumn, opts: { at?: number } = {}): Promise<boolean>`
- `removeAt(index: number): Promise<boolean>`
- `renameAt(index: number, name: string): Promise<boolean>`
- `patchAt(index: number, patch: Partial<ErColumn>): Promise<boolean>`
- `move(from: number, to: number): Promise<boolean>`
- `[Symbol.iterator](): Iterator<ErField>`

### `ErField`

A column of an {@link ErTable} — itself just (table, name): stateless.

```ts
class ErField
```

**Methods**

- `constructor( readonly table: ErTable, private readonly columnName: string )`
- `get exists(): boolean`
- `get name(): string`
- `get index(): number`
- `get type(): string | undefined`
- `get pk(): boolean`
- `get fk(): boolean`
- `rename(name: string): Promise<boolean>` — Rename — the field port keeps its id, so attached edges stay glued.
- `setType(type: string): Promise<boolean>`
- `setKeys(keys: { pk?: boolean; fk?: boolean }): Promise<boolean>`
- `remove(): Promise<boolean>` — Remove this column (its ports and attached edges are dropped).

### `ErTable`

Also has every member of `CardHandle`, listed on its own entry.

```ts
class ErTable extends CardHandle
```

**Properties**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `columns` |  |  |  |

**Methods**

- `get spec(): ErEntitySpec` — A deep COPY of the stored entity spec — never a live reference.
- `get name(): string`
- `rename(name: string): Promise<boolean>` — Rename the card title — one undoable step.
- `resize(size: { width?: number; height?: number }): Promise<boolean>` — Resize the card — one undoable step (kit body scrolls when capped).
- `update(delta: Parameters<typeof updateEntity>[2]): Promise<boolean>` — The raw delta path — everything above funnels through here.

### `UmlClass`

Also has every member of `CardHandle`, listed on its own entry.

```ts
class UmlClass extends CardHandle
```

**Properties**

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `attributes` |  |  |  |
| `methods` |  |  |  |

**Methods**

- `get spec(): UmlClassSpec` — A deep COPY of the stored class spec — never a live reference.
- `get name(): string`
- `get abstract(): boolean`
- `get stereotype(): string | undefined`
- `rename(name: string): Promise<boolean>` — Rename the card title — one undoable step.
- `resize(size: { width?: number; height?: number }): Promise<boolean>` — Resize the card — one undoable step (kit body scrolls when capped).
- `setAbstract(abstract: boolean): Promise<boolean>`
- `setStereotype(stereotype: string | undefined): Promise<boolean>`
- `update(delta: Parameters<typeof updateClass>[2]): Promise<boolean>`

### `UmlMemberList`

attributes / methods of a {@link UmlClass} (members are plain strings).

```ts
class UmlMemberList
```

**Methods**

- `constructor( private readonly cls: UmlClass, private readonly kind: 'attributes' | 'methods' )`
- `list(): string[]`
- `get length(): number`
- `at(index: number): string | undefined`
- `add(member: string, opts: { at?: number } = {}): Promise<boolean>`
- `removeAt(index: number): Promise<boolean>`
- `renameAt(index: number, member: string): Promise<boolean>`
