@almadar/ui 1.0.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,382 @@
1
+ import { P as PatternConfig, R as ResolvedPattern, C as ClientEffect, b as ClientEffectExecutorConfig, N as NotifyOptions, D as DataContext, c as DataResolution, d as UISlot, S as SlotDefinition, e as SlotType } from '../offline-executor-CHr4uAhf.js';
2
+ export { E as EventResponse, O as OfflineExecutor, f as OfflineExecutorConfig, g as OfflineExecutorState, h as PendingSyncEffect, a as UseOfflineExecutorOptions, U as UseOfflineExecutorResult, i as createOfflineExecutor, u as useOfflineExecutor } from '../offline-executor-CHr4uAhf.js';
3
+ import * as React from 'react';
4
+
5
+ /**
6
+ * Pattern Resolver
7
+ *
8
+ * Resolves pattern configurations to component information.
9
+ * Uses the central pattern registry and component mapping from orbital-shared/patterns/.
10
+ *
11
+ * This is the shared logic used by both Builder's PatternRenderer and
12
+ * the compiled shell's UISlotRenderer.
13
+ *
14
+ * @packageDocumentation
15
+ */
16
+
17
+ /**
18
+ * Component mapping entry from component-mapping.json
19
+ */
20
+ interface ComponentMappingEntry {
21
+ component: string;
22
+ importPath: string;
23
+ category: string;
24
+ deprecated?: boolean;
25
+ replacedBy?: string;
26
+ }
27
+ /**
28
+ * Pattern definition from registry.json
29
+ */
30
+ interface PatternDefinition {
31
+ type: string;
32
+ category: string;
33
+ description: string;
34
+ propsSchema?: Record<string, {
35
+ required?: boolean;
36
+ types?: string[];
37
+ description?: string;
38
+ }>;
39
+ }
40
+ /**
41
+ * Initialize the pattern resolver with mappings.
42
+ * Called at app startup with data from JSON files.
43
+ */
44
+ declare function initializePatternResolver(config: {
45
+ componentMapping: Record<string, ComponentMappingEntry>;
46
+ patternRegistry: Record<string, PatternDefinition>;
47
+ }): void;
48
+ /**
49
+ * Set component mapping (alternative to full initialization).
50
+ */
51
+ declare function setComponentMapping(mapping: Record<string, ComponentMappingEntry>): void;
52
+ /**
53
+ * Set pattern registry (alternative to full initialization).
54
+ */
55
+ declare function setPatternRegistry(registry: Record<string, PatternDefinition>): void;
56
+ /**
57
+ * Resolve a pattern configuration to component information.
58
+ *
59
+ * @param config - Pattern configuration from render-ui effect
60
+ * @returns Resolved pattern with component name, import path, and validated props
61
+ * @throws Error if pattern type is unknown
62
+ *
63
+ * @example
64
+ * ```typescript
65
+ * const resolved = resolvePattern({
66
+ * type: 'entity-table',
67
+ * entity: 'Task',
68
+ * columns: ['title', 'status']
69
+ * });
70
+ * // resolved.component === 'DataTable'
71
+ * // resolved.importPath === '@/components/organisms/DataTable'
72
+ * ```
73
+ */
74
+ declare function resolvePattern(config: PatternConfig): ResolvedPattern;
75
+ /**
76
+ * Check if a pattern type is known.
77
+ */
78
+ declare function isKnownPattern(type: string): boolean;
79
+ /**
80
+ * Get all known pattern types.
81
+ */
82
+ declare function getKnownPatterns(): string[];
83
+ /**
84
+ * Get patterns by category.
85
+ */
86
+ declare function getPatternsByCategory(category: string): string[];
87
+ /**
88
+ * Get the component mapping for a pattern type.
89
+ */
90
+ declare function getPatternMapping(type: string): ComponentMappingEntry | undefined;
91
+ /**
92
+ * Get the pattern definition from the registry.
93
+ */
94
+ declare function getPatternDefinition(type: string): PatternDefinition | undefined;
95
+
96
+ /**
97
+ * Client Effect Executor
98
+ *
99
+ * Executes client effects returned from the server.
100
+ * This is the core of the dual execution model - the server processes
101
+ * events and returns client effects, which this module executes.
102
+ *
103
+ * Used by both Builder preview and compiled shells.
104
+ *
105
+ * @packageDocumentation
106
+ */
107
+
108
+ /**
109
+ * Execute an array of client effects.
110
+ *
111
+ * Effects are executed sequentially in order.
112
+ * Errors in one effect don't prevent subsequent effects from executing.
113
+ *
114
+ * @param effects - Array of client effects to execute
115
+ * @param config - Configuration providing implementations for each effect type
116
+ *
117
+ * @example
118
+ * ```typescript
119
+ * executeClientEffects(
120
+ * [
121
+ * ['render-ui', 'main', { type: 'entity-table', entity: 'Task' }],
122
+ * ['notify', 'Tasks loaded!', { type: 'success' }]
123
+ * ],
124
+ * {
125
+ * renderToSlot: (slot, pattern) => slotManager.render(slot, pattern),
126
+ * navigate: (path) => router.push(path),
127
+ * notify: (message, opts) => toast.show(message, opts),
128
+ * eventBus: { emit: (event, payload) => bus.emit(event, payload) }
129
+ * }
130
+ * );
131
+ * ```
132
+ */
133
+ declare function executeClientEffects(effects: ClientEffect[], config: ClientEffectExecutorConfig): void;
134
+ /**
135
+ * Parse a raw effect array into a typed ClientEffect.
136
+ * Handles unknown effect formats gracefully.
137
+ */
138
+ declare function parseClientEffect(raw: unknown[]): ClientEffect | null;
139
+ /**
140
+ * Parse an array of raw effects into typed ClientEffects.
141
+ * Filters out invalid effects.
142
+ */
143
+ declare function parseClientEffects(raw: unknown[] | undefined): ClientEffect[];
144
+ /**
145
+ * Filter effects by type.
146
+ */
147
+ declare function filterEffectsByType<T extends ClientEffect[0]>(effects: ClientEffect[], type: T): Extract<ClientEffect, [T, ...unknown[]]>[];
148
+ /**
149
+ * Get all render-ui effects.
150
+ */
151
+ declare function getRenderUIEffects(effects: ClientEffect[]): Array<['render-ui', string, PatternConfig | null]>;
152
+ /**
153
+ * Get all navigate effects.
154
+ */
155
+ declare function getNavigateEffects(effects: ClientEffect[]): Array<['navigate', string, Record<string, unknown>?]>;
156
+ /**
157
+ * Get all notify effects.
158
+ */
159
+ declare function getNotifyEffects(effects: ClientEffect[]): Array<['notify', string, NotifyOptions?]>;
160
+ /**
161
+ * Get all emit effects.
162
+ */
163
+ declare function getEmitEffects(effects: ClientEffect[]): Array<['emit', string, unknown?]>;
164
+
165
+ /**
166
+ * Options for the useClientEffects hook
167
+ */
168
+ interface UseClientEffectsOptions extends ClientEffectExecutorConfig {
169
+ /**
170
+ * Whether to execute effects. Defaults to true.
171
+ * Set to false to temporarily disable effect execution.
172
+ */
173
+ enabled?: boolean;
174
+ /**
175
+ * Debug mode - logs effect execution details.
176
+ */
177
+ debug?: boolean;
178
+ }
179
+ /**
180
+ * Result of useClientEffects hook
181
+ */
182
+ interface UseClientEffectsResult {
183
+ /**
184
+ * Number of effects executed in the last batch.
185
+ */
186
+ executedCount: number;
187
+ /**
188
+ * Whether effects are currently being executed.
189
+ */
190
+ executing: boolean;
191
+ /**
192
+ * Manually trigger effect execution.
193
+ * Useful for imperative control.
194
+ */
195
+ execute: (effects: ClientEffect[]) => void;
196
+ }
197
+ /**
198
+ * Execute client effects from server response.
199
+ *
200
+ * This hook automatically executes effects when they change,
201
+ * tracking which effects have been executed to prevent duplicates.
202
+ *
203
+ * @param effects - Array of client effects to execute (from server response)
204
+ * @param options - Configuration including effect implementations
205
+ * @returns Hook result with execution state and manual trigger
206
+ *
207
+ * @example
208
+ * ```typescript
209
+ * function useMyTrait() {
210
+ * const [state, setState] = useState({ pendingEffects: [] });
211
+ * const effectConfig = useClientEffectConfig();
212
+ *
213
+ * useClientEffects(state.pendingEffects, {
214
+ * ...effectConfig,
215
+ * onComplete: () => setState(s => ({ ...s, pendingEffects: [] }))
216
+ * });
217
+ *
218
+ * // ...
219
+ * }
220
+ * ```
221
+ */
222
+ declare function useClientEffects(effects: ClientEffect[] | undefined, options: UseClientEffectsOptions): UseClientEffectsResult;
223
+ declare const ClientEffectConfigContext: React.Context<ClientEffectExecutorConfig | null>;
224
+ /**
225
+ * Provider for client effect configuration.
226
+ */
227
+ declare const ClientEffectConfigProvider: React.Provider<ClientEffectExecutorConfig | null>;
228
+ /**
229
+ * Hook to get the client effect configuration from context.
230
+ *
231
+ * @throws Error if used outside of ClientEffectConfigProvider
232
+ *
233
+ * @example
234
+ * ```typescript
235
+ * function MyTraitHook() {
236
+ * const effectConfig = useClientEffectConfig();
237
+ *
238
+ * useClientEffects(pendingEffects, {
239
+ * ...effectConfig,
240
+ * onComplete: () => clearPendingEffects()
241
+ * });
242
+ * }
243
+ * ```
244
+ */
245
+ declare function useClientEffectConfig(): ClientEffectExecutorConfig;
246
+ /**
247
+ * Hook to get client effect configuration, returning null if not available.
248
+ * Use this for optional integration where effects may not be configured.
249
+ */
250
+ declare function useClientEffectConfigOptional(): ClientEffectExecutorConfig | null;
251
+
252
+ /**
253
+ * Data Resolver
254
+ *
255
+ * Resolves entity data for pattern rendering.
256
+ * Supports multiple data sources with priority:
257
+ * 1. Server-provided data (from EventResponse.data)
258
+ * 2. Entity store (Builder in-memory mock data)
259
+ * 3. Empty array (fallback)
260
+ *
261
+ * Used by both Builder's PatternRenderer and compiled shell's UISlotRenderer.
262
+ *
263
+ * @packageDocumentation
264
+ */
265
+
266
+ /**
267
+ * Resolve entity data from available sources.
268
+ *
269
+ * Priority:
270
+ * 1. fetchedData (from server response) - highest priority
271
+ * 2. entityStore (Builder mock data)
272
+ * 3. Empty array (fallback)
273
+ *
274
+ * @param entityName - Name of the entity to resolve data for
275
+ * @param context - Data context with available sources
276
+ * @returns Resolved data with loading state
277
+ *
278
+ * @example
279
+ * ```typescript
280
+ * const { data, loading } = resolveEntityData('Task', {
281
+ * fetchedData: response.data,
282
+ * entityStore: mockStore
283
+ * });
284
+ * ```
285
+ */
286
+ declare function resolveEntityData(entityName: string, context: DataContext): DataResolution;
287
+ /**
288
+ * Resolve entity data with query filtering.
289
+ *
290
+ * Applies query singleton filters if available.
291
+ *
292
+ * @param entityName - Name of the entity
293
+ * @param queryRef - Optional query reference for filtering
294
+ * @param context - Data context
295
+ * @returns Filtered resolved data
296
+ */
297
+ declare function resolveEntityDataWithQuery(entityName: string, queryRef: string | undefined, context: DataContext): DataResolution;
298
+ /**
299
+ * Get a single entity record by ID.
300
+ */
301
+ declare function resolveEntityById(entityName: string, id: string | number, context: DataContext): unknown | null;
302
+ /**
303
+ * Get the count of entities matching criteria.
304
+ */
305
+ declare function resolveEntityCount(entityName: string, context: DataContext, filters?: Record<string, unknown>): number;
306
+ /**
307
+ * Check if any entities exist for a given entity name.
308
+ */
309
+ declare function hasEntities(entityName: string, context: DataContext): boolean;
310
+ /**
311
+ * Create a data context from fetched data only.
312
+ * Convenience function for compiled shells.
313
+ */
314
+ declare function createFetchedDataContext(data: Record<string, unknown[]>): DataContext;
315
+ /**
316
+ * Merge multiple data contexts.
317
+ * Later contexts take precedence.
318
+ */
319
+ declare function mergeDataContexts(...contexts: DataContext[]): DataContext;
320
+
321
+ /**
322
+ * Slot Definitions
323
+ *
324
+ * Defines the available UI slots and their rendering behavior.
325
+ * Slots are either inline (rendered in the component tree) or
326
+ * portal (rendered to document.body via React Portal).
327
+ *
328
+ * @packageDocumentation
329
+ */
330
+
331
+ /**
332
+ * Definitions for all available UI slots.
333
+ *
334
+ * Inline slots render within the component hierarchy.
335
+ * Portal slots render to document.body, breaking out of overflow containers.
336
+ */
337
+ declare const SLOT_DEFINITIONS: Record<UISlot, SlotDefinition>;
338
+ /**
339
+ * Get the slot definition for a slot name.
340
+ */
341
+ declare function getSlotDefinition(slot: UISlot): SlotDefinition;
342
+ /**
343
+ * Check if a slot is a portal slot.
344
+ */
345
+ declare function isPortalSlot(slot: UISlot): boolean;
346
+ /**
347
+ * Check if a slot is an inline slot.
348
+ */
349
+ declare function isInlineSlot(slot: UISlot): boolean;
350
+ /**
351
+ * Get all slots of a specific type.
352
+ */
353
+ declare function getSlotsByType(type: SlotType): UISlot[];
354
+ /**
355
+ * Get all inline slots.
356
+ */
357
+ declare function getInlineSlots(): UISlot[];
358
+ /**
359
+ * Get all portal slots.
360
+ */
361
+ declare function getPortalSlots(): UISlot[];
362
+ /**
363
+ * All valid slot names.
364
+ */
365
+ declare const ALL_SLOTS: UISlot[];
366
+
367
+ /**
368
+ * Pattern Resolver Initialization
369
+ *
370
+ * Loads pattern registry and component mapping from orbital-shared/patterns/
371
+ * and initializes the pattern resolver at app startup.
372
+ *
373
+ * @packageDocumentation
374
+ */
375
+ /**
376
+ * Initialize the pattern resolver with shared pattern data.
377
+ * Must be called once at app startup before any pattern rendering.
378
+ * @returns The number of patterns initialized
379
+ */
380
+ declare function initializePatterns(): number;
381
+
382
+ export { ALL_SLOTS, ClientEffect, ClientEffectConfigContext, ClientEffectConfigProvider, ClientEffectExecutorConfig, DataContext, DataResolution, NotifyOptions, PatternConfig, ResolvedPattern, SLOT_DEFINITIONS, SlotDefinition, SlotType, UISlot, type UseClientEffectsOptions, type UseClientEffectsResult, createFetchedDataContext, executeClientEffects, filterEffectsByType, getEmitEffects, getInlineSlots, getKnownPatterns, getNavigateEffects, getNotifyEffects, getPatternDefinition, getPatternMapping, getPatternsByCategory, getPortalSlots, getRenderUIEffects, getSlotDefinition, getSlotsByType, hasEntities, initializePatternResolver, initializePatterns, isInlineSlot, isKnownPattern, isPortalSlot, mergeDataContexts, parseClientEffect, parseClientEffects, resolveEntityById, resolveEntityCount, resolveEntityData, resolveEntityDataWithQuery, resolvePattern, setComponentMapping, setPatternRegistry, useClientEffectConfig, useClientEffectConfigOptional, useClientEffects };