@almadar/ui 3.8.3 → 3.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.
@@ -51367,7 +51367,7 @@ function useTraitStateMachine(traitBindings, slotsActions, options) {
51367
51367
  effects: result.effects,
51368
51368
  traitDefinition: binding.trait
51369
51369
  };
51370
- const handlers = createClientEffectHandlers({
51370
+ const clientHandlers = createClientEffectHandlers({
51371
51371
  eventBus,
51372
51372
  slotSetter: {
51373
51373
  addPattern: (slot, pattern, props) => {
@@ -51382,6 +51382,43 @@ function useTraitStateMachine(traitBindings, slotsActions, options) {
51382
51382
  navigate: optionsRef.current?.navigate,
51383
51383
  notify: optionsRef.current?.notify
51384
51384
  });
51385
+ const persistence = optionsRef.current?.persistence;
51386
+ let handlers = clientHandlers;
51387
+ if (persistence) {
51388
+ const sharedBindings = {
51389
+ entity: payload ?? {},
51390
+ payload: payload || {},
51391
+ state: result.previousState
51392
+ };
51393
+ if (binding.config) {
51394
+ sharedBindings.config = binding.config;
51395
+ }
51396
+ const serverHandlers = runtime.createServerEffectHandlers({
51397
+ persistence,
51398
+ eventBus,
51399
+ entityType: linkedEntity,
51400
+ entityId,
51401
+ bindings: sharedBindings,
51402
+ context: {
51403
+ traitName: binding.trait.name,
51404
+ state: result.previousState,
51405
+ transition: `${result.previousState}->${result.newState}`,
51406
+ linkedEntity,
51407
+ entityId
51408
+ },
51409
+ source: { trait: binding.trait.name },
51410
+ callService: optionsRef.current?.callService
51411
+ });
51412
+ handlers = {
51413
+ ...serverHandlers,
51414
+ // Client handlers own UI + emit: keep the slot setter
51415
+ // and pre-prefixed UI:* emit path intact.
51416
+ emit: clientHandlers.emit,
51417
+ renderUI: clientHandlers.renderUI,
51418
+ navigate: clientHandlers.navigate,
51419
+ notify: clientHandlers.notify
51420
+ };
51421
+ }
51385
51422
  const entityFromPayload = payload ?? {};
51386
51423
  const bindingCtx = {
51387
51424
  entity: entityFromPayload,
@@ -51881,7 +51918,7 @@ function applyServerEffects(effects, uiSlots, onNavigate) {
51881
51918
  }
51882
51919
  }
51883
51920
  }
51884
- function TraitInitializer({ traits: traits2, orbitalNames, onNavigate, onLocalFallback }) {
51921
+ function TraitInitializer({ traits: traits2, orbitalNames, onNavigate, onLocalFallback, persistence }) {
51885
51922
  const slotsActions = useSlotsActions();
51886
51923
  const bridge = useServerBridge();
51887
51924
  const uiSlots = useUISlots();
@@ -51893,7 +51930,7 @@ function TraitInitializer({ traits: traits2, orbitalNames, onNavigate, onLocalFa
51893
51930
  applyServerEffects(effects, uiSlots, onNavigate);
51894
51931
  }
51895
51932
  }, [bridge.connected, bridge.sendEvent, orbitalNames, uiSlots, onNavigate]);
51896
- const opts = orbitalNames ? { onEventProcessed, navigate: onNavigate } : { navigate: onNavigate };
51933
+ const opts = orbitalNames ? { onEventProcessed, navigate: onNavigate } : { navigate: onNavigate, persistence };
51897
51934
  const { sendEvent } = useTraitStateMachine(traits2, slotsActions, opts);
51898
51935
  const initSentRef = React126.useRef(false);
51899
51936
  React126.useEffect(() => {
@@ -51938,7 +51975,7 @@ function TraitInitializer({ traits: traits2, orbitalNames, onNavigate, onLocalFa
51938
51975
  }, [bridge.connected, orbitalNames, bridge.sendEvent, uiSlots, onNavigate]);
51939
51976
  return null;
51940
51977
  }
51941
- function SchemaRunner({ schema, serverUrl, mockData, pageName, onNavigate, onLocalFallback }) {
51978
+ function SchemaRunner({ schema, serverUrl, mockData, pageName, onNavigate, onLocalFallback, persistence }) {
51942
51979
  const { traits: traits2, allEntities, ir } = useResolvedSchema(schema, pageName);
51943
51980
  const allPageTraits = React126.useMemo(() => {
51944
51981
  if (pageName && traits2.length > 0) return traits2;
@@ -51971,7 +52008,8 @@ function SchemaRunner({ schema, serverUrl, mockData, pageName, onNavigate, onLoc
51971
52008
  traits: allPageTraits,
51972
52009
  orbitalNames: serverUrl ? orbitalNames : void 0,
51973
52010
  onNavigate,
51974
- onLocalFallback
52011
+ onLocalFallback,
52012
+ persistence
51975
52013
  }
51976
52014
  ),
51977
52015
  /* @__PURE__ */ jsxRuntime.jsx(SlotBridge, {}),
@@ -52019,6 +52057,13 @@ function OrbPreview({
52019
52057
  }, [schema, autoMock, serverUrl, mockData]);
52020
52058
  const parsedSchema = parseResult.ok ? parseResult.schema : null;
52021
52059
  const effectiveMockData = parseResult.ok ? parseResult.mockData : {};
52060
+ const persistence = React126.useMemo(() => {
52061
+ if (!parsedSchema || serverUrl) return void 0;
52062
+ if (!autoMock) return void 0;
52063
+ const adapter = new runtime.InMemoryPersistence();
52064
+ adapter.seed(effectiveMockData);
52065
+ return adapter;
52066
+ }, [parsedSchema, serverUrl, autoMock, effectiveMockData]);
52022
52067
  const pages = React126.useMemo(() => {
52023
52068
  if (!parsedSchema) return [];
52024
52069
  try {
@@ -52073,7 +52118,8 @@ function OrbPreview({
52073
52118
  mockData: effectiveMockData,
52074
52119
  pageName: currentPage,
52075
52120
  onNavigate: handleNavigate,
52076
- onLocalFallback: handleLocalFallback
52121
+ onLocalFallback: handleLocalFallback,
52122
+ persistence
52077
52123
  }
52078
52124
  ) }) })
52079
52125
  ]
package/dist/avl/index.js CHANGED
@@ -43,7 +43,7 @@ import { EffectComposer, Bloom, DepthOfField, Vignette } from '@react-three/post
43
43
  import ELK from 'elkjs/lib/elk.bundled.js';
44
44
  import { MarkerType, Handle, Position, getBezierPath, EdgeLabelRenderer, BaseEdge, ReactFlowProvider, useNodesState, useEdgesState, useReactFlow, ReactFlow, Controls, Background, BackgroundVariant } from '@xyflow/react';
45
45
  import '@tanstack/react-query';
46
- import { StateMachineManager, createContextFromBindings, interpolateValue, EffectExecutor } from '@almadar/runtime';
46
+ import { InMemoryPersistence, StateMachineManager, createContextFromBindings, interpolateValue, createServerEffectHandlers, EffectExecutor } from '@almadar/runtime';
47
47
 
48
48
  var __defProp = Object.defineProperty;
49
49
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -51321,7 +51321,7 @@ function useTraitStateMachine(traitBindings, slotsActions, options) {
51321
51321
  effects: result.effects,
51322
51322
  traitDefinition: binding.trait
51323
51323
  };
51324
- const handlers = createClientEffectHandlers({
51324
+ const clientHandlers = createClientEffectHandlers({
51325
51325
  eventBus,
51326
51326
  slotSetter: {
51327
51327
  addPattern: (slot, pattern, props) => {
@@ -51336,6 +51336,43 @@ function useTraitStateMachine(traitBindings, slotsActions, options) {
51336
51336
  navigate: optionsRef.current?.navigate,
51337
51337
  notify: optionsRef.current?.notify
51338
51338
  });
51339
+ const persistence = optionsRef.current?.persistence;
51340
+ let handlers = clientHandlers;
51341
+ if (persistence) {
51342
+ const sharedBindings = {
51343
+ entity: payload ?? {},
51344
+ payload: payload || {},
51345
+ state: result.previousState
51346
+ };
51347
+ if (binding.config) {
51348
+ sharedBindings.config = binding.config;
51349
+ }
51350
+ const serverHandlers = createServerEffectHandlers({
51351
+ persistence,
51352
+ eventBus,
51353
+ entityType: linkedEntity,
51354
+ entityId,
51355
+ bindings: sharedBindings,
51356
+ context: {
51357
+ traitName: binding.trait.name,
51358
+ state: result.previousState,
51359
+ transition: `${result.previousState}->${result.newState}`,
51360
+ linkedEntity,
51361
+ entityId
51362
+ },
51363
+ source: { trait: binding.trait.name },
51364
+ callService: optionsRef.current?.callService
51365
+ });
51366
+ handlers = {
51367
+ ...serverHandlers,
51368
+ // Client handlers own UI + emit: keep the slot setter
51369
+ // and pre-prefixed UI:* emit path intact.
51370
+ emit: clientHandlers.emit,
51371
+ renderUI: clientHandlers.renderUI,
51372
+ navigate: clientHandlers.navigate,
51373
+ notify: clientHandlers.notify
51374
+ };
51375
+ }
51339
51376
  const entityFromPayload = payload ?? {};
51340
51377
  const bindingCtx = {
51341
51378
  entity: entityFromPayload,
@@ -51835,7 +51872,7 @@ function applyServerEffects(effects, uiSlots, onNavigate) {
51835
51872
  }
51836
51873
  }
51837
51874
  }
51838
- function TraitInitializer({ traits: traits2, orbitalNames, onNavigate, onLocalFallback }) {
51875
+ function TraitInitializer({ traits: traits2, orbitalNames, onNavigate, onLocalFallback, persistence }) {
51839
51876
  const slotsActions = useSlotsActions();
51840
51877
  const bridge = useServerBridge();
51841
51878
  const uiSlots = useUISlots();
@@ -51847,7 +51884,7 @@ function TraitInitializer({ traits: traits2, orbitalNames, onNavigate, onLocalFa
51847
51884
  applyServerEffects(effects, uiSlots, onNavigate);
51848
51885
  }
51849
51886
  }, [bridge.connected, bridge.sendEvent, orbitalNames, uiSlots, onNavigate]);
51850
- const opts = orbitalNames ? { onEventProcessed, navigate: onNavigate } : { navigate: onNavigate };
51887
+ const opts = orbitalNames ? { onEventProcessed, navigate: onNavigate } : { navigate: onNavigate, persistence };
51851
51888
  const { sendEvent } = useTraitStateMachine(traits2, slotsActions, opts);
51852
51889
  const initSentRef = useRef(false);
51853
51890
  useEffect(() => {
@@ -51892,7 +51929,7 @@ function TraitInitializer({ traits: traits2, orbitalNames, onNavigate, onLocalFa
51892
51929
  }, [bridge.connected, orbitalNames, bridge.sendEvent, uiSlots, onNavigate]);
51893
51930
  return null;
51894
51931
  }
51895
- function SchemaRunner({ schema, serverUrl, mockData, pageName, onNavigate, onLocalFallback }) {
51932
+ function SchemaRunner({ schema, serverUrl, mockData, pageName, onNavigate, onLocalFallback, persistence }) {
51896
51933
  const { traits: traits2, allEntities, ir } = useResolvedSchema(schema, pageName);
51897
51934
  const allPageTraits = useMemo(() => {
51898
51935
  if (pageName && traits2.length > 0) return traits2;
@@ -51925,7 +51962,8 @@ function SchemaRunner({ schema, serverUrl, mockData, pageName, onNavigate, onLoc
51925
51962
  traits: allPageTraits,
51926
51963
  orbitalNames: serverUrl ? orbitalNames : void 0,
51927
51964
  onNavigate,
51928
- onLocalFallback
51965
+ onLocalFallback,
51966
+ persistence
51929
51967
  }
51930
51968
  ),
51931
51969
  /* @__PURE__ */ jsx(SlotBridge, {}),
@@ -51973,6 +52011,13 @@ function OrbPreview({
51973
52011
  }, [schema, autoMock, serverUrl, mockData]);
51974
52012
  const parsedSchema = parseResult.ok ? parseResult.schema : null;
51975
52013
  const effectiveMockData = parseResult.ok ? parseResult.mockData : {};
52014
+ const persistence = useMemo(() => {
52015
+ if (!parsedSchema || serverUrl) return void 0;
52016
+ if (!autoMock) return void 0;
52017
+ const adapter = new InMemoryPersistence();
52018
+ adapter.seed(effectiveMockData);
52019
+ return adapter;
52020
+ }, [parsedSchema, serverUrl, autoMock, effectiveMockData]);
51976
52021
  const pages = useMemo(() => {
51977
52022
  if (!parsedSchema) return [];
51978
52023
  try {
@@ -52027,7 +52072,8 @@ function OrbPreview({
52027
52072
  mockData: effectiveMockData,
52028
52073
  pageName: currentPage,
52029
52074
  onNavigate: handleNavigate,
52030
- onLocalFallback: handleLocalFallback
52075
+ onLocalFallback: handleLocalFallback,
52076
+ persistence
52031
52077
  }
52032
52078
  ) }) })
52033
52079
  ]
@@ -38163,7 +38163,7 @@ function useTraitStateMachine(traitBindings, slotsActions, options) {
38163
38163
  effects: result.effects,
38164
38164
  traitDefinition: binding.trait
38165
38165
  };
38166
- const handlers = createClientEffectHandlers({
38166
+ const clientHandlers = createClientEffectHandlers({
38167
38167
  eventBus,
38168
38168
  slotSetter: {
38169
38169
  addPattern: (slot, pattern, props) => {
@@ -38178,6 +38178,43 @@ function useTraitStateMachine(traitBindings, slotsActions, options) {
38178
38178
  navigate: optionsRef.current?.navigate,
38179
38179
  notify: optionsRef.current?.notify
38180
38180
  });
38181
+ const persistence = optionsRef.current?.persistence;
38182
+ let handlers = clientHandlers;
38183
+ if (persistence) {
38184
+ const sharedBindings = {
38185
+ entity: payload ?? {},
38186
+ payload: payload || {},
38187
+ state: result.previousState
38188
+ };
38189
+ if (binding.config) {
38190
+ sharedBindings.config = binding.config;
38191
+ }
38192
+ const serverHandlers = runtime.createServerEffectHandlers({
38193
+ persistence,
38194
+ eventBus,
38195
+ entityType: linkedEntity,
38196
+ entityId,
38197
+ bindings: sharedBindings,
38198
+ context: {
38199
+ traitName: binding.trait.name,
38200
+ state: result.previousState,
38201
+ transition: `${result.previousState}->${result.newState}`,
38202
+ linkedEntity,
38203
+ entityId
38204
+ },
38205
+ source: { trait: binding.trait.name },
38206
+ callService: optionsRef.current?.callService
38207
+ });
38208
+ handlers = {
38209
+ ...serverHandlers,
38210
+ // Client handlers own UI + emit: keep the slot setter
38211
+ // and pre-prefixed UI:* emit path intact.
38212
+ emit: clientHandlers.emit,
38213
+ renderUI: clientHandlers.renderUI,
38214
+ navigate: clientHandlers.navigate,
38215
+ notify: clientHandlers.notify
38216
+ };
38217
+ }
38181
38218
  const entityFromPayload = payload ?? {};
38182
38219
  const bindingCtx = {
38183
38220
  entity: entityFromPayload,
@@ -38799,7 +38836,7 @@ function applyServerEffects(effects, uiSlots, onNavigate) {
38799
38836
  }
38800
38837
  }
38801
38838
  }
38802
- function TraitInitializer({ traits: traits2, orbitalNames, onNavigate, onLocalFallback }) {
38839
+ function TraitInitializer({ traits: traits2, orbitalNames, onNavigate, onLocalFallback, persistence }) {
38803
38840
  const slotsActions = useSlotsActions();
38804
38841
  const bridge = useServerBridge();
38805
38842
  const uiSlots = context.useUISlots();
@@ -38811,7 +38848,7 @@ function TraitInitializer({ traits: traits2, orbitalNames, onNavigate, onLocalFa
38811
38848
  applyServerEffects(effects, uiSlots, onNavigate);
38812
38849
  }
38813
38850
  }, [bridge.connected, bridge.sendEvent, orbitalNames, uiSlots, onNavigate]);
38814
- const opts = orbitalNames ? { onEventProcessed, navigate: onNavigate } : { navigate: onNavigate };
38851
+ const opts = orbitalNames ? { onEventProcessed, navigate: onNavigate } : { navigate: onNavigate, persistence };
38815
38852
  const { sendEvent } = useTraitStateMachine(traits2, slotsActions, opts);
38816
38853
  const initSentRef = React116.useRef(false);
38817
38854
  React116.useEffect(() => {
@@ -38856,7 +38893,7 @@ function TraitInitializer({ traits: traits2, orbitalNames, onNavigate, onLocalFa
38856
38893
  }, [bridge.connected, orbitalNames, bridge.sendEvent, uiSlots, onNavigate]);
38857
38894
  return null;
38858
38895
  }
38859
- function SchemaRunner({ schema, serverUrl, mockData, pageName, onNavigate, onLocalFallback }) {
38896
+ function SchemaRunner({ schema, serverUrl, mockData, pageName, onNavigate, onLocalFallback, persistence }) {
38860
38897
  const { traits: traits2, allEntities, ir } = useResolvedSchema(schema, pageName);
38861
38898
  const allPageTraits = React116.useMemo(() => {
38862
38899
  if (pageName && traits2.length > 0) return traits2;
@@ -38889,7 +38926,8 @@ function SchemaRunner({ schema, serverUrl, mockData, pageName, onNavigate, onLoc
38889
38926
  traits: allPageTraits,
38890
38927
  orbitalNames: serverUrl ? orbitalNames : void 0,
38891
38928
  onNavigate,
38892
- onLocalFallback
38929
+ onLocalFallback,
38930
+ persistence
38893
38931
  }
38894
38932
  ),
38895
38933
  /* @__PURE__ */ jsxRuntime.jsx(SlotBridge, {}),
@@ -38937,6 +38975,13 @@ function OrbPreview({
38937
38975
  }, [schema, autoMock, serverUrl, mockData]);
38938
38976
  const parsedSchema = parseResult.ok ? parseResult.schema : null;
38939
38977
  const effectiveMockData = parseResult.ok ? parseResult.mockData : {};
38978
+ const persistence = React116.useMemo(() => {
38979
+ if (!parsedSchema || serverUrl) return void 0;
38980
+ if (!autoMock) return void 0;
38981
+ const adapter = new runtime.InMemoryPersistence();
38982
+ adapter.seed(effectiveMockData);
38983
+ return adapter;
38984
+ }, [parsedSchema, serverUrl, autoMock, effectiveMockData]);
38940
38985
  const pages = React116.useMemo(() => {
38941
38986
  if (!parsedSchema) return [];
38942
38987
  try {
@@ -38991,7 +39036,8 @@ function OrbPreview({
38991
39036
  mockData: effectiveMockData,
38992
39037
  pageName: currentPage,
38993
39038
  onNavigate: handleNavigate,
38994
- onLocalFallback: handleLocalFallback
39039
+ onLocalFallback: handleLocalFallback,
39040
+ persistence
38995
39041
  }
38996
39042
  ) }) })
38997
39043
  ]
@@ -36,7 +36,7 @@ import langGo from 'react-syntax-highlighter/dist/esm/languages/prism/go.js';
36
36
  import langGraphql from 'react-syntax-highlighter/dist/esm/languages/prism/graphql.js';
37
37
  import { isCircuitEvent, schemaToIR, getPage, clearSchemaCache as clearSchemaCache$1, isEntityCall, isInlineTrait } from '@almadar/core';
38
38
  import '@tanstack/react-query';
39
- import { StateMachineManager, createContextFromBindings, interpolateValue, EffectExecutor } from '@almadar/runtime';
39
+ import { StateMachineManager, createContextFromBindings, interpolateValue, createServerEffectHandlers, EffectExecutor, InMemoryPersistence } from '@almadar/runtime';
40
40
 
41
41
  var __defProp = Object.defineProperty;
42
42
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -38118,7 +38118,7 @@ function useTraitStateMachine(traitBindings, slotsActions, options) {
38118
38118
  effects: result.effects,
38119
38119
  traitDefinition: binding.trait
38120
38120
  };
38121
- const handlers = createClientEffectHandlers({
38121
+ const clientHandlers = createClientEffectHandlers({
38122
38122
  eventBus,
38123
38123
  slotSetter: {
38124
38124
  addPattern: (slot, pattern, props) => {
@@ -38133,6 +38133,43 @@ function useTraitStateMachine(traitBindings, slotsActions, options) {
38133
38133
  navigate: optionsRef.current?.navigate,
38134
38134
  notify: optionsRef.current?.notify
38135
38135
  });
38136
+ const persistence = optionsRef.current?.persistence;
38137
+ let handlers = clientHandlers;
38138
+ if (persistence) {
38139
+ const sharedBindings = {
38140
+ entity: payload ?? {},
38141
+ payload: payload || {},
38142
+ state: result.previousState
38143
+ };
38144
+ if (binding.config) {
38145
+ sharedBindings.config = binding.config;
38146
+ }
38147
+ const serverHandlers = createServerEffectHandlers({
38148
+ persistence,
38149
+ eventBus,
38150
+ entityType: linkedEntity,
38151
+ entityId,
38152
+ bindings: sharedBindings,
38153
+ context: {
38154
+ traitName: binding.trait.name,
38155
+ state: result.previousState,
38156
+ transition: `${result.previousState}->${result.newState}`,
38157
+ linkedEntity,
38158
+ entityId
38159
+ },
38160
+ source: { trait: binding.trait.name },
38161
+ callService: optionsRef.current?.callService
38162
+ });
38163
+ handlers = {
38164
+ ...serverHandlers,
38165
+ // Client handlers own UI + emit: keep the slot setter
38166
+ // and pre-prefixed UI:* emit path intact.
38167
+ emit: clientHandlers.emit,
38168
+ renderUI: clientHandlers.renderUI,
38169
+ navigate: clientHandlers.navigate,
38170
+ notify: clientHandlers.notify
38171
+ };
38172
+ }
38136
38173
  const entityFromPayload = payload ?? {};
38137
38174
  const bindingCtx = {
38138
38175
  entity: entityFromPayload,
@@ -38754,7 +38791,7 @@ function applyServerEffects(effects, uiSlots, onNavigate) {
38754
38791
  }
38755
38792
  }
38756
38793
  }
38757
- function TraitInitializer({ traits: traits2, orbitalNames, onNavigate, onLocalFallback }) {
38794
+ function TraitInitializer({ traits: traits2, orbitalNames, onNavigate, onLocalFallback, persistence }) {
38758
38795
  const slotsActions = useSlotsActions();
38759
38796
  const bridge = useServerBridge();
38760
38797
  const uiSlots = useUISlots();
@@ -38766,7 +38803,7 @@ function TraitInitializer({ traits: traits2, orbitalNames, onNavigate, onLocalFa
38766
38803
  applyServerEffects(effects, uiSlots, onNavigate);
38767
38804
  }
38768
38805
  }, [bridge.connected, bridge.sendEvent, orbitalNames, uiSlots, onNavigate]);
38769
- const opts = orbitalNames ? { onEventProcessed, navigate: onNavigate } : { navigate: onNavigate };
38806
+ const opts = orbitalNames ? { onEventProcessed, navigate: onNavigate } : { navigate: onNavigate, persistence };
38770
38807
  const { sendEvent } = useTraitStateMachine(traits2, slotsActions, opts);
38771
38808
  const initSentRef = useRef(false);
38772
38809
  useEffect(() => {
@@ -38811,7 +38848,7 @@ function TraitInitializer({ traits: traits2, orbitalNames, onNavigate, onLocalFa
38811
38848
  }, [bridge.connected, orbitalNames, bridge.sendEvent, uiSlots, onNavigate]);
38812
38849
  return null;
38813
38850
  }
38814
- function SchemaRunner({ schema, serverUrl, mockData, pageName, onNavigate, onLocalFallback }) {
38851
+ function SchemaRunner({ schema, serverUrl, mockData, pageName, onNavigate, onLocalFallback, persistence }) {
38815
38852
  const { traits: traits2, allEntities, ir } = useResolvedSchema(schema, pageName);
38816
38853
  const allPageTraits = useMemo(() => {
38817
38854
  if (pageName && traits2.length > 0) return traits2;
@@ -38844,7 +38881,8 @@ function SchemaRunner({ schema, serverUrl, mockData, pageName, onNavigate, onLoc
38844
38881
  traits: allPageTraits,
38845
38882
  orbitalNames: serverUrl ? orbitalNames : void 0,
38846
38883
  onNavigate,
38847
- onLocalFallback
38884
+ onLocalFallback,
38885
+ persistence
38848
38886
  }
38849
38887
  ),
38850
38888
  /* @__PURE__ */ jsx(SlotBridge, {}),
@@ -38892,6 +38930,13 @@ function OrbPreview({
38892
38930
  }, [schema, autoMock, serverUrl, mockData]);
38893
38931
  const parsedSchema = parseResult.ok ? parseResult.schema : null;
38894
38932
  const effectiveMockData = parseResult.ok ? parseResult.mockData : {};
38933
+ const persistence = useMemo(() => {
38934
+ if (!parsedSchema || serverUrl) return void 0;
38935
+ if (!autoMock) return void 0;
38936
+ const adapter = new InMemoryPersistence();
38937
+ adapter.seed(effectiveMockData);
38938
+ return adapter;
38939
+ }, [parsedSchema, serverUrl, autoMock, effectiveMockData]);
38895
38940
  const pages = useMemo(() => {
38896
38941
  if (!parsedSchema) return [];
38897
38942
  try {
@@ -38946,7 +38991,8 @@ function OrbPreview({
38946
38991
  mockData: effectiveMockData,
38947
38992
  pageName: currentPage,
38948
38993
  onNavigate: handleNavigate,
38949
- onLocalFallback: handleLocalFallback
38994
+ onLocalFallback: handleLocalFallback,
38995
+ persistence
38950
38996
  }
38951
38997
  ) }) })
38952
38998
  ]
@@ -38,6 +38,17 @@ export interface UseTraitStateMachineOptions {
38
38
  navigate?: (path: string, params?: Record<string, unknown>) => void;
39
39
  /** Notification function for notify effects */
40
40
  notify?: (message: string, type?: 'success' | 'error' | 'warning' | 'info') => void;
41
+ /**
42
+ * Offline-preview persistence layer. When set, the client runtime merges
43
+ * `@almadar/runtime` `createServerEffectHandlers` on top of the default
44
+ * client handlers so `fetch` / `persist` / `set` / `ref` / `deref` /
45
+ * `swap!` / `atomic` / `callService` run against this adapter — matching
46
+ * what `OrbitalServerRuntime` would do on the server. Left unset in the
47
+ * server-bridge path; effects there flow to the real server.
48
+ */
49
+ persistence?: import('@almadar/runtime').PersistenceAdapter;
50
+ /** Optional consumer `call-service` hook forwarded to the mock server handlers. */
51
+ callService?: (service: string, action: string, params: unknown) => Promise<unknown>;
41
52
  }
42
53
  /**
43
54
  * useTraitStateMachine - Manages state machines for multiple traits
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@almadar/ui",
3
- "version": "3.8.3",
3
+ "version": "3.9.0",
4
4
  "description": "React UI components, hooks, and providers for Almadar",
5
5
  "type": "module",
6
6
  "main": "./dist/components/index.js",
@@ -121,7 +121,7 @@
121
121
  "@almadar/core": ">=5.7.0",
122
122
  "@almadar/evaluator": ">=2.9.2",
123
123
  "@almadar/patterns": ">=2.17.1",
124
- "@almadar/runtime": ">=4.3.0",
124
+ "@almadar/runtime": "^4.11.1",
125
125
  "@almadar/std": ">=6.4.1",
126
126
  "@almadar/syntax": ">=1.3.1",
127
127
  "@xyflow/react": "12.10.1",