@almadar/ui 2.7.0 → 2.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,280 @@
1
+ import { TraitState, EffectHandlers } from '@almadar/runtime';
2
+ import { PatternConfig, ResolvedTrait, ResolvedTraitBinding, ResolvedPage, ResolvedEntity, ResolvedIR, OrbitalSchema } from '@almadar/core';
3
+ export { ResolvedEntity, ResolvedIR, ResolvedPage, ResolvedTrait, ResolvedTraitBinding } from '@almadar/core';
4
+ import React__default from 'react';
5
+
6
+ /**
7
+ * SlotsContext - React state-based UI slot management
8
+ *
9
+ * Replaces the UIEnvironment observable store with plain React state.
10
+ * No stacking logic, no priority system, no source tracking for arbitration.
11
+ *
12
+ * A transition's effects produce the COMPLETE content for each slot.
13
+ * The runtime collects all render-ui effects from a transition, groups by slot,
14
+ * and sets each slot's patterns array in one atomic operation.
15
+ *
16
+ * @packageDocumentation
17
+ */
18
+
19
+ /** A single pattern entry in a slot */
20
+ interface SlotPatternEntry {
21
+ pattern: PatternConfig;
22
+ props: Record<string, unknown>;
23
+ }
24
+ /**
25
+ * Source metadata for a rendered slot.
26
+ * Used by the Slot Inspector to show debug info.
27
+ */
28
+ interface SlotSource {
29
+ trait: string;
30
+ state: string;
31
+ transition: string;
32
+ effects?: unknown[];
33
+ /** Full trait definition for inspector */
34
+ traitDefinition?: ResolvedTrait;
35
+ }
36
+ /** Full state of a single slot */
37
+ interface SlotState {
38
+ patterns: SlotPatternEntry[];
39
+ source?: SlotSource;
40
+ }
41
+ /** All slots state */
42
+ type SlotsState = Record<string, SlotState>;
43
+ /** Mutation functions for slots (stable references, won't trigger re-renders) */
44
+ interface SlotsActions {
45
+ /** Set all patterns for a slot atomically (replaces previous content) */
46
+ setSlotPatterns: (slot: string, patterns: SlotPatternEntry[], source?: SlotSource) => void;
47
+ /** Clear a single slot */
48
+ clearSlot: (slot: string) => void;
49
+ /** Clear all slots */
50
+ clearAllSlots: () => void;
51
+ }
52
+ interface SlotsProviderProps {
53
+ children: React__default.ReactNode;
54
+ }
55
+ /**
56
+ * SlotsProvider - Manages UI slot state via React useState.
57
+ *
58
+ * Replaces UIEnvironmentProvider. No observable store, no stacking logic.
59
+ * Slots are set atomically per transition — React diffs and re-renders.
60
+ */
61
+ declare function SlotsProvider({ children }: SlotsProviderProps): React__default.ReactElement;
62
+ /**
63
+ * Get the full slots state. Triggers re-render on ANY slot change.
64
+ * Prefer useSlotContent(name) for individual slot subscriptions.
65
+ */
66
+ declare function useSlots(): SlotsState;
67
+ /**
68
+ * Get content for a specific slot. Returns null if slot is empty.
69
+ */
70
+ declare function useSlotContent(slotName: string): SlotState | null;
71
+ /**
72
+ * Get slot mutation actions. Stable reference — never triggers re-renders.
73
+ */
74
+ declare function useSlotsActions(): SlotsActions;
75
+
76
+ /**
77
+ * useTraitStateMachine Hook
78
+ *
79
+ * Manages trait state machines with event-driven transitions.
80
+ * Subscribes to eventBus events and executes effects when transitions occur.
81
+ *
82
+ * CONSOLIDATED RUNTIME:
83
+ * - Uses StateMachineManager from @almadar/runtime for state management
84
+ * - Uses the same state machine logic as the server runtime (OrbitalServerRuntime)
85
+ * - Ensures consistent behavior between client preview and server execution
86
+ *
87
+ * SLOT MANAGEMENT:
88
+ * - Collects all render-ui effects from a transition, groups by slot
89
+ * - Sets each slot's patterns array atomically via SlotsActions
90
+ * - No stacking logic, no priority system — transition produces complete slot content
91
+ *
92
+ * @packageDocumentation
93
+ */
94
+
95
+ interface TraitStateMachineResult {
96
+ /** Current state for each trait */
97
+ traitStates: Map<string, TraitState>;
98
+ /** Send an event to trigger a transition */
99
+ sendEvent: (eventKey: string, payload?: Record<string, unknown>) => void;
100
+ /** Get current state for a specific trait */
101
+ getTraitState: (traitName: string) => TraitState | undefined;
102
+ /** Check if a trait can handle an event from its current state */
103
+ canHandleEvent: (traitName: string, eventKey: string) => boolean;
104
+ }
105
+ interface UseTraitStateMachineOptions {
106
+ /** Callback invoked after each event is processed (for server forwarding) */
107
+ onEventProcessed?: (eventKey: string, payload?: Record<string, unknown>) => void;
108
+ /** Router navigate function for navigate effects */
109
+ navigate?: (path: string, params?: Record<string, unknown>) => void;
110
+ /** Notification function for notify effects */
111
+ notify?: (message: string, type?: 'success' | 'error' | 'warning' | 'info') => void;
112
+ }
113
+ /**
114
+ * useTraitStateMachine - Manages state machines for multiple traits
115
+ *
116
+ * Uses the shared StateMachineManager for consistent behavior with server runtime.
117
+ * Collects render-ui effects per transition and sets slot content atomically.
118
+ */
119
+ declare function useTraitStateMachine(traitBindings: ResolvedTraitBinding[], slotsActions: SlotsActions, options?: UseTraitStateMachineOptions): TraitStateMachineResult;
120
+
121
+ /**
122
+ * useResolvedSchema Hook
123
+ *
124
+ * Resolves OrbitalSchema to IR for the OrbitalRuntime.
125
+ * Uses the shared resolver to ensure consistency with the compiler.
126
+ *
127
+ * TRAIT-DRIVEN ARCHITECTURE:
128
+ * - Pages have traits, NOT sections
129
+ * - UI is produced by trait effects (render_ui)
130
+ * - No backwards compatibility with legacy formats
131
+ *
132
+ * @packageDocumentation
133
+ */
134
+
135
+ interface ResolvedSchemaResult {
136
+ /** The resolved page (or undefined if not found) */
137
+ page: ResolvedPage | undefined;
138
+ /** Trait bindings for this page */
139
+ traits: ResolvedTraitBinding[];
140
+ /** Entities used by this page */
141
+ entities: Map<string, ResolvedEntity>;
142
+ /** All entities from schema */
143
+ allEntities: Map<string, ResolvedEntity>;
144
+ /** All resolved traits */
145
+ allTraits: Map<string, ResolvedTrait>;
146
+ /** Loading state */
147
+ loading: boolean;
148
+ /** Error message if resolution failed */
149
+ error: string | null;
150
+ /** Full IR (for debugging) */
151
+ ir: ResolvedIR | null;
152
+ }
153
+ /**
154
+ * Hook to resolve an OrbitalSchema to IR.
155
+ *
156
+ * @param schema - The OrbitalSchema to resolve
157
+ * @param pageName - Optional page name (defaults to first page or initial page)
158
+ * @returns Resolved schema data including page, traits, and entities
159
+ */
160
+ declare function useResolvedSchema(schema: OrbitalSchema | null | undefined, pageName?: string): ResolvedSchemaResult;
161
+ /**
162
+ * Clear the schema resolution cache
163
+ */
164
+ declare function clearSchemaCache(): void;
165
+
166
+ /**
167
+ * EntitySchemaContext
168
+ *
169
+ * Minimal context providing entity schema definitions (field metadata).
170
+ * This is NOT a data store - data comes from FetchedDataContext via server.
171
+ *
172
+ * Replaces EntityStore's schema functionality without the mock data generation.
173
+ *
174
+ * @packageDocumentation
175
+ */
176
+
177
+ interface EntitySchemaContextValue {
178
+ /** Entity definitions (schema metadata only) */
179
+ entities: Map<string, ResolvedEntity>;
180
+ }
181
+ interface EntitySchemaProviderProps {
182
+ /** Entity definitions from resolved schema */
183
+ entities: ResolvedEntity[];
184
+ /** Children */
185
+ children: React__default.ReactNode;
186
+ }
187
+ /**
188
+ * Provides entity schema definitions to the component tree.
189
+ *
190
+ * This is a lightweight provider that only holds schema metadata (field definitions).
191
+ * Actual entity data comes from FetchedDataContext via server responses.
192
+ */
193
+ declare function EntitySchemaProvider({ entities, children, }: EntitySchemaProviderProps): React__default.ReactElement;
194
+ /**
195
+ * Access entity schema definitions.
196
+ * Use this for field metadata (form building, filter enrichment).
197
+ * For actual data, use useFetchedDataContext.
198
+ */
199
+ declare function useEntitySchema(): EntitySchemaContextValue;
200
+ /**
201
+ * Get a specific entity's schema definition.
202
+ */
203
+ declare function useEntityDefinition(entityName: string): ResolvedEntity | undefined;
204
+
205
+ /**
206
+ * TraitProvider Component
207
+ *
208
+ * Provides trait state machines to child components via React context.
209
+ *
210
+ * @packageDocumentation
211
+ */
212
+
213
+ interface TraitInstance {
214
+ /** Trait name */
215
+ name: string;
216
+ /** Current state */
217
+ currentState: string;
218
+ /** Available events (can be triggered) */
219
+ availableEvents: string[];
220
+ /** Dispatch an event to the state machine */
221
+ dispatch: (eventKey: string, payload?: Record<string, unknown>) => void;
222
+ /** Check if an event can be dispatched */
223
+ canDispatch: (eventKey: string) => boolean;
224
+ /** Get the full trait definition */
225
+ trait: ResolvedTrait;
226
+ }
227
+ interface TraitContextValue {
228
+ /** All trait instances on this page */
229
+ traits: Map<string, TraitInstance>;
230
+ /** Get a trait instance by name */
231
+ getTrait: (name: string) => TraitInstance | undefined;
232
+ /** Dispatch an event to a specific trait */
233
+ dispatchToTrait: (traitName: string, eventKey: string, payload?: Record<string, unknown>) => void;
234
+ /** Check if an event can be dispatched to a trait */
235
+ canDispatch: (traitName: string, eventKey: string) => boolean;
236
+ }
237
+ declare const TraitContext: React__default.Context<TraitContextValue | null>;
238
+ interface TraitProviderProps {
239
+ /** Trait bindings for this page */
240
+ traits: ResolvedTraitBinding[];
241
+ /** Entity map for context */
242
+ entities: Map<string, ResolvedEntity>;
243
+ /** Children to render */
244
+ children: React__default.ReactNode;
245
+ }
246
+ declare function TraitProvider({ traits: traitBindings, children, }: TraitProviderProps): React__default.ReactElement;
247
+ /**
248
+ * Access the trait context from within the TraitProvider.
249
+ */
250
+ declare function useTraitContext(): TraitContextValue;
251
+ /**
252
+ * Access a specific trait instance.
253
+ */
254
+ declare function useTrait(traitName: string): TraitInstance | undefined;
255
+
256
+ /**
257
+ * Client Effect Handlers Factory
258
+ *
259
+ * Creates the standard effect handler set for client-side trait execution.
260
+ *
261
+ * @packageDocumentation
262
+ */
263
+
264
+ interface ClientEventBus {
265
+ emit: (type: string, payload?: Record<string, unknown>) => void;
266
+ }
267
+ interface SlotSetter {
268
+ addPattern: (slot: string, pattern: unknown, props?: Record<string, unknown>) => void;
269
+ clearSlot: (slot: string) => void;
270
+ }
271
+ interface CreateClientEffectHandlersOptions {
272
+ eventBus: ClientEventBus;
273
+ slotSetter: SlotSetter;
274
+ navigate?: (path: string, params?: Record<string, unknown>) => void;
275
+ notify?: (message: string, type: 'success' | 'error' | 'warning' | 'info') => void;
276
+ enrichPattern?: (pattern: unknown) => unknown;
277
+ }
278
+ declare function createClientEffectHandlers(options: CreateClientEffectHandlersOptions): EffectHandlers;
279
+
280
+ export { type ClientEventBus, type CreateClientEffectHandlersOptions, type EntitySchemaContextValue, EntitySchemaProvider, type EntitySchemaProviderProps, type ResolvedSchemaResult, type SlotPatternEntry, type SlotSetter, type SlotSource, type SlotState, type SlotsActions, SlotsProvider, type SlotsProviderProps, type SlotsState, TraitContext, type TraitContextValue, type TraitInstance, TraitProvider, type TraitProviderProps, type TraitStateMachineResult, type UseTraitStateMachineOptions, clearSchemaCache, createClientEffectHandlers, useEntityDefinition, useEntitySchema, useResolvedSchema, useSlotContent, useSlots, useSlotsActions, useTrait, useTraitContext, useTraitStateMachine };