@@ -45,13 +45,49 @@ function resolveInitialOverlayId(overlays, initialOverlayId) {
4545 return exists ? requestedId : overlays [ 0 ] . id ;
4646}
4747
48+ function normalizeRuntimeExtensionEntry ( entry ) {
49+ if ( ! entry || typeof entry !== 'object' ) {
50+ return null ;
51+ }
52+
53+ const overlayId = String ( entry . overlayId || '' ) . trim ( ) ;
54+ const onStep = typeof entry . onStep === 'function' ? entry . onStep : null ;
55+ const onRender = typeof entry . onRender === 'function' ? entry . onRender : null ;
56+ if ( ! onStep && ! onRender ) {
57+ return null ;
58+ }
59+
60+ return Object . freeze ( {
61+ overlayId,
62+ onStep,
63+ onRender,
64+ } ) ;
65+ }
66+
67+ function normalizeRuntimeExtensions ( runtimeExtensions ) {
68+ if ( ! Array . isArray ( runtimeExtensions ) || runtimeExtensions . length === 0 ) {
69+ return Object . freeze ( [ ] ) ;
70+ }
71+
72+ const normalized = [ ] ;
73+ for ( let i = 0 ; i < runtimeExtensions . length ; i += 1 ) {
74+ const candidate = normalizeRuntimeExtensionEntry ( runtimeExtensions [ i ] ) ;
75+ if ( ! candidate ) {
76+ continue ;
77+ }
78+ normalized . push ( candidate ) ;
79+ }
80+ return Object . freeze ( normalized ) ;
81+ }
82+
4883export function defineOverlayExtensionContract ( {
4984 id = '' ,
5085 overlays = [ ] ,
5186 initialOverlayId = '' ,
5287 cycleKey = '' ,
5388 persistenceKey = '' ,
5489 channel = DEFAULT_CHANNEL ,
90+ runtimeExtensions = [ ] ,
5591 metadata = { } ,
5692} = { } ) {
5793 const normalizedId = String ( id || '' ) . trim ( ) ;
@@ -68,6 +104,7 @@ export function defineOverlayExtensionContract({
68104 const normalizedPersistenceKey = String ( persistenceKey || '' ) . trim ( ) ;
69105 const normalizedChannel = String ( channel || DEFAULT_CHANNEL ) . trim ( ) || DEFAULT_CHANNEL ;
70106 const normalizedInitialOverlayId = resolveInitialOverlayId ( normalizedOverlays , initialOverlayId ) ;
107+ const normalizedRuntimeExtensions = normalizeRuntimeExtensions ( runtimeExtensions ) ;
71108
72109 return Object . freeze ( {
73110 id : normalizedId ,
@@ -76,6 +113,7 @@ export function defineOverlayExtensionContract({
76113 initialOverlayId : normalizedInitialOverlayId ,
77114 cycleKey : normalizedCycleKey ,
78115 persistenceKey : normalizedPersistenceKey ,
116+ runtimeExtensions : normalizedRuntimeExtensions ,
79117 metadata : Object . freeze ( { ...( metadata || { } ) } ) ,
80118 } ) ;
81119}
@@ -105,5 +143,6 @@ export function getOverlayControllerConfigFromContract(contract) {
105143 initialOverlayId : contract . initialOverlayId ,
106144 cycleKey : contract . cycleKey ,
107145 persistenceKey : contract . persistenceKey ,
146+ runtimeExtensions : contract . runtimeExtensions ,
108147 } ) ;
109148}
0 commit comments