@almadar/ui 4.13.1 → 4.14.1

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,48 @@
1
+ /**
2
+ * Per-transition slot pattern types — shared by `useTraitStateMachine`
3
+ * (the state-machine accumulator) and any consumer that wants to look at
4
+ * the raw pattern + props pair before unwrap.
5
+ *
6
+ * Pre-consolidation these lived in `SlotsContext.tsx` together with a
7
+ * React Provider that maintained a parallel `slots` store. That store
8
+ * was removed in favor of consolidating onto `useUISlots`, so only the
9
+ * structural types remain here.
10
+ *
11
+ * @packageDocumentation
12
+ */
13
+ import type { PatternConfig, EventSource, ResolvedTrait } from '@almadar/core';
14
+ /**
15
+ * Slot-render observability channel. Used by `useTraitStateMachine`,
16
+ * `OrbPreview.applyServerEffects`, and the `<SlotContentRenderer>` to
17
+ * surface every slot write/clear at debug level. Pre-consolidation
18
+ * lived in `SlotsContext.tsx`; consolidated here so consumers don't
19
+ * depend on the now-removed React provider.
20
+ */
21
+ export declare const slotLog: import("../../lib").Logger;
22
+ /**
23
+ * Stable per-object id used by slot-render logs to compare entity
24
+ * references across renders (e.g. spotting the form-reset bug where
25
+ * the same logical row arrives with a fresh ref id every transition).
26
+ */
27
+ export declare function refId(obj: unknown): number | null;
28
+ /**
29
+ * One pattern within a slot's accumulated render-ui set, plus any
30
+ * caller-supplied props that should be merged on top.
31
+ */
32
+ export interface SlotPatternEntry {
33
+ pattern: PatternConfig;
34
+ props: Record<string, unknown>;
35
+ }
36
+ /**
37
+ * The originating trait + state for a slot write. Embedded in the
38
+ * `useUISlots` SlotContent's metadata so observers (verifier, debugger,
39
+ * cross-orbital tracer) can attribute every render to the trait that
40
+ * caused it.
41
+ */
42
+ export interface SlotSource extends EventSource {
43
+ trait: string;
44
+ state: string;
45
+ transition: string;
46
+ effects: unknown[];
47
+ traitDefinition: ResolvedTrait;
48
+ }
@@ -19,7 +19,7 @@
19
19
  import type { EventPayload } from '@almadar/core';
20
20
  import { type TraitState } from '@almadar/runtime';
21
21
  import type { ResolvedTraitBinding } from './types';
22
- import type { SlotsActions } from './ui/SlotsContext';
22
+ import type { useUISlots } from '../context/UISlotContext';
23
23
  export type { TraitState };
24
24
  export interface TraitStateMachineResult {
25
25
  /** Current state for each trait */
@@ -76,12 +76,30 @@ export interface UseTraitStateMachineOptions {
76
76
  * `ResolvedTraitBinding`, so the caller assembles the map directly.
77
77
  */
78
78
  orbitalsByTrait?: Record<string, string>;
79
+ /**
80
+ * Set of trait names referenced via `@trait.X` by some sibling
81
+ * layout in the resolved schema. Slot writes from these traits go
82
+ * to the per-trait sidecar via `uiSlots.updateTraitContent`; the
83
+ * layout owns the slot and embeds via `<TraitFrame>`. Mirrors
84
+ * compiled-path codegen semantics.
85
+ */
86
+ embeddedTraits?: ReadonlySet<string>;
79
87
  }
80
88
  /**
81
89
  * useTraitStateMachine - Manages state machines for multiple traits
82
90
  *
83
91
  * Uses the shared StateMachineManager for consistent behavior with server runtime.
84
92
  * Collects render-ui effects per transition and sets slot content atomically.
93
+ *
94
+ * Slot writes go directly to `useUISlots` (the canonical store the DOM
95
+ * reads from) instead of routing through the now-removed `SlotsContext`
96
+ * + `SlotBridge` mirror. Trait names listed in `embeddedTraits` are
97
+ * referenced via `@trait.X` by some sibling layout's render-ui — for
98
+ * those, slot writes update the per-trait sidecar (via
99
+ * `updateTraitContent`) so `<TraitFrame>` can pick them up without the
100
+ * atom landing as a separate slot source. Mirrors compiled-path
101
+ * codegen, where atom views are inlined as JSX inside the layout's
102
+ * pattern rather than each writing a shared slot.
85
103
  */
86
- export declare function useTraitStateMachine(traitBindings: ResolvedTraitBinding[], slotsActions: SlotsActions, options?: UseTraitStateMachineOptions): TraitStateMachineResult;
104
+ export declare function useTraitStateMachine(traitBindings: ResolvedTraitBinding[], uiSlots: ReturnType<typeof useUISlots>, options?: UseTraitStateMachineOptions): TraitStateMachineResult;
87
105
  export default useTraitStateMachine;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@almadar/ui",
3
- "version": "4.13.1",
3
+ "version": "4.14.1",
4
4
  "description": "React UI components, hooks, and providers for Almadar",
5
5
  "type": "module",
6
6
  "main": "./dist/components/index.js",
@@ -1,114 +0,0 @@
1
- /**
2
- * SlotsContext - React state-based UI slot management
3
- *
4
- * Replaces the UIEnvironment observable store with plain React state.
5
- * No stacking logic, no priority system.
6
- *
7
- * A transition's effects produce the COMPLETE content for each slot
8
- * from the POV of the trait that fired. The runtime collects all render-ui
9
- * effects from a transition, groups by slot, and calls
10
- * `setSlotPatterns(slot, patterns, source)` once per slot.
11
- *
12
- * Multi-trait parity with the compiled path (2026-04-24):
13
- * State is keyed by (slot, sourceTraitName). When ProbeCreate renders to
14
- * "main" and ProbePersistor also renders to "main", both entries coexist —
15
- * each source owns its own sub-entry. Consumers see them as a list in
16
- * insertion order. Prior model was single-entry per slot (last-writer-wins),
17
- * which diverged from the compiled path's VStack-of-trait-views layout.
18
- *
19
- * @packageDocumentation
20
- */
21
- import React from 'react';
22
- import type { PatternConfig, EventSource, ResolvedTrait } from '@almadar/core';
23
- declare const slotLog: import("../../lib").Logger;
24
- export declare function refId(obj: unknown): number | null;
25
- export { slotLog };
26
- /** A single pattern entry in a slot */
27
- export interface SlotPatternEntry {
28
- pattern: PatternConfig;
29
- props: Record<string, unknown>;
30
- }
31
- /**
32
- * Source metadata for a rendered slot. Extends `@almadar/core`'s
33
- * `EventSource` (which owns the `{ trait, transition?, tick? }` shape
34
- * shared with the event bus) with UI-only debug fields used by the Slot
35
- * Inspector. Keeping the core subset aligned means the slot machinery
36
- * can round-trip with event bus metadata without re-coercion.
37
- */
38
- export interface SlotSource extends EventSource {
39
- /** Source trait's current state at the moment of render. */
40
- state: string;
41
- /** Raw effects block that produced this render, for inspector display. */
42
- effects?: unknown[];
43
- /** Full trait definition for inspector */
44
- traitDefinition?: ResolvedTrait;
45
- }
46
- /**
47
- * One source's contribution to a slot. The same slot can receive
48
- * contributions from multiple source traits (e.g. a page-level layout
49
- * where ProbeCreate and ProbePersistor both render to "main").
50
- */
51
- export interface SlotEntry {
52
- patterns: SlotPatternEntry[];
53
- source?: SlotSource;
54
- }
55
- /**
56
- * All source contributions to a single slot, keyed by the source trait's
57
- * name. The sentinel `'__default__'` key is used when `setSlotPatterns`
58
- * is called without a source (legacy / unscoped callers).
59
- *
60
- * Iteration order reflects insertion order — the first trait to write to
61
- * the slot renders first, which matches the compiled-path VStack order
62
- * set by the .lolo's `page ... -> Trait1, Trait2, ...` declaration.
63
- */
64
- export type SlotState = Record<string, SlotEntry>;
65
- /** All slots state */
66
- export type SlotsState = Record<string, SlotState>;
67
- /** Mutation functions for slots (stable references, won't trigger re-renders) */
68
- export interface SlotsActions {
69
- /**
70
- * Set this source's contribution to a slot atomically. Replaces any
71
- * prior content FROM THE SAME SOURCE only; other sources' entries in
72
- * the slot are untouched.
73
- */
74
- setSlotPatterns: (slot: string, patterns: SlotPatternEntry[], source?: SlotSource) => void;
75
- /**
76
- * Clear a slot entirely. Wipes all source entries; consumers see an
77
- * empty slot (no patterns from any source).
78
- */
79
- clearSlot: (slot: string) => void;
80
- /** Remove a single source's contribution from a slot, keeping others. */
81
- clearSlotForSource: (slot: string, sourceTrait: string) => void;
82
- /** Clear all slots */
83
- clearAllSlots: () => void;
84
- }
85
- /** Entries in render order for a slot (insertion order, empty-filtered). */
86
- export declare function slotEntriesInOrder(slot: SlotState | null | undefined): Array<{
87
- sourceKey: string;
88
- entry: SlotEntry;
89
- }>;
90
- export interface SlotsProviderProps {
91
- children: React.ReactNode;
92
- }
93
- /**
94
- * SlotsProvider - Manages UI slot state via React useState.
95
- *
96
- * Replaces UIEnvironmentProvider. No observable store, no stacking logic.
97
- * Slots are set atomically per (transition, source) — React diffs and re-renders.
98
- */
99
- export declare function SlotsProvider({ children }: SlotsProviderProps): React.ReactElement;
100
- /**
101
- * Get the full slots state. Triggers re-render on ANY slot change.
102
- * Prefer useSlotContent(name) for individual slot subscriptions.
103
- */
104
- export declare function useSlots(): SlotsState;
105
- /**
106
- * Get the per-source state map for a specific slot. Returns null if
107
- * nothing has written to this slot yet. To iterate sources in render
108
- * order, use `slotEntriesInOrder(useSlotContent(name))`.
109
- */
110
- export declare function useSlotContent(slotName: string): SlotState | null;
111
- /**
112
- * Get slot mutation actions. Stable reference — never triggers re-renders.
113
- */
114
- export declare function useSlotsActions(): SlotsActions;