Standard Library
Standard library behaviors for Almadar applications
1. Overview
The Standard Library provides 34 reusable behaviors (standard traits) for the Orbital system. Each behavior is a self-contained OrbitalSchema that can function as a standalone .orb file.
Behavior Categories
| Category | Behaviors |
|---|---|
| Game Core | GameLoop, Physics2D, Input, Collision |
| Game Entity | Health, Score, Movement, Combat, Inventory |
| Game UI | GameFlow, Dialogue, LevelProgress |
| UI Interaction | List, Detail, Form, Modal, Drawer, Tabs, Wizard, MasterDetail, Filter |
| Data Management | Pagination, Selection, Sort, Filter, Search |
| Async | Loading, Fetch, Submit, Retry, Poll |
| Feedback | Notification, Confirmation, Undo |
2. Behavior Structure (OrbitalSchema)
Each behavior is a complete OrbitalSchema (aliased as BehaviorSchema):
import type { BehaviorSchema } from '@almadar/std';
export const LIST_BEHAVIOR: BehaviorSchema = {
name: 'std-list',
version: '1.0.0',
description: 'Entity list with selection and actions',
orbitals: [{
name: 'ListOrbital',
entity: {
name: 'ListState',
persistence: 'runtime',
fields: [
{ name: 'id', type: 'string', required: true },
{ name: 'selectedId', type: 'string', default: null },
{ name: 'items', type: 'array', default: [] },
],
},
traits: [{
name: 'List',
linkedEntity: 'ListState',
category: 'interaction',
stateMachine: {
states: [
{ name: 'Empty', isInitial: true },
{ name: 'Loaded' },
{ name: 'ItemSelected' },
],
events: [/* ... */],
transitions: [/* ... */],
},
}],
pages: [],
}],
};
Key Structure Points
name: Kebab-case withstd-prefix (e.g.,std-list,std-gameloop)orbitals: Array containing one orbital with entity, traits, and pagesentity: Runtime state fieldstraits: Array of trait definitions withlinkedEntitypages: Empty array (required by type, can be populated for pages)
3. Type-Safe Pattern Validation
PatternType Union
The render-ui effect enforces valid pattern types at compile-time:
import type { PatternConfig } from '@almadar/core';
export interface PatternConfig {
type: PatternType; // 203 valid patterns
[key: string]: unknown;
}
The PatternType union includes all registered patterns:
export type PatternType =
| 'entity-table'
| 'card'
| 'form'
| 'button'
// ... 199 more patterns
;
Usage in Behaviors
// ✅ Valid - 'entity-table' with typed props
['render-ui', 'main', { patternType: 'entity-table', columns: ['name', 'email'] }]
// ❌ TypeScript error - 'fake-pattern' is not a valid PatternType
['render-ui', 'main', { patternType: 'fake-pattern' }]
// ❌ TypeScript error - missing required 'columns' prop
['render-ui', 'main', { patternType: 'entity-table' }]
4. Usage
Import Behaviors
import {
LIST_BEHAVIOR,
FORM_BEHAVIOR,
LOADING_BEHAVIOR,
STANDARD_BEHAVIORS,
} from '@almadar/std';
// Access all 34 behaviors
console.log(STANDARD_BEHAVIORS.length); // 34
Type Imports
import type {
BehaviorSchema, // OrbitalSchema alias
OrbitalSchema, // Full schema type
Orbital, // Single orbital
Entity, // Entity definition
} from '@almadar/std';
Registry Functions
import {
getBehavior,
isKnownBehavior,
getAllBehaviorNames,
getBehaviorLibraryStats,
} from '@almadar/std';
// Get behavior by name
const list = getBehavior('std-list');
// Check if valid
if (isKnownBehavior('std-form')) { /* ... */ }
// Get stats
const stats = getBehaviorLibraryStats();
// { totalBehaviors: 34, totalStates: X, totalEvents: X, ... }