@storybook/instrumenter 7.0.7 → 7.0.8

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.
Files changed (2) hide show
  1. package/dist/index.mjs +8 -1
  2. package/package.json +10 -10
package/dist/index.mjs CHANGED
@@ -1 +1,8 @@
1
- import{addons}from"@storybook/preview-api";import{once,logger}from"@storybook/client-logger";import{FORCE_REMOUNT,IGNORED_EXCEPTION,SET_CURRENT_STORY,STORY_RENDER_PHASE_CHANGED}from"@storybook/core-events";import{global}from"@storybook/global";var CallStates=(CallStates2=>(CallStates2.DONE="done",CallStates2.ERROR="error",CallStates2.ACTIVE="active",CallStates2.WAITING="waiting",CallStates2))(CallStates||{});var EVENTS={CALL:"storybook/instrumenter/call",SYNC:"storybook/instrumenter/sync",START:"storybook/instrumenter/start",BACK:"storybook/instrumenter/back",GOTO:"storybook/instrumenter/goto",NEXT:"storybook/instrumenter/next",END:"storybook/instrumenter/end"},controlsDisabled={start:!1,back:!1,goto:!1,next:!1,end:!1},alreadyCompletedException=new Error("This function ran after the play function completed. Did you forget to `await` it?"),isObject=o=>Object.prototype.toString.call(o)==="[object Object]",isModule=o=>Object.prototype.toString.call(o)==="[object Module]",isInstrumentable=o=>{if(!isObject(o)&&!isModule(o))return!1;if(o.constructor===void 0)return!0;let proto=o.constructor.prototype;return!(!isObject(proto)||Object.prototype.hasOwnProperty.call(proto,"isPrototypeOf")===!1)},construct=obj=>{try{return new obj.constructor}catch{return{}}},getInitialState=()=>({renderPhase:void 0,isDebugging:!1,isPlaying:!1,isLocked:!1,cursor:0,calls:[],shadowCalls:[],callRefsByResult:new Map,chainedCallIds:new Set,ancestors:[],playUntil:void 0,resolvers:{},syncTimeout:void 0}),getRetainedState=(state,isDebugging=!1)=>{let calls=(isDebugging?state.shadowCalls:state.calls).filter(call=>call.retain);if(!calls.length)return;let callRefsByResult=new Map(Array.from(state.callRefsByResult.entries()).filter(([,ref])=>ref.retain));return{cursor:calls.length,calls,callRefsByResult}},Instrumenter=class{constructor(){this.initialized=!1;this.channel=addons.getChannel(),this.state=global.window.parent.__STORYBOOK_ADDON_INTERACTIONS_INSTRUMENTER_STATE__||{};let resetState=({storyId,isPlaying=!0,isDebugging=!1})=>{let state=this.getState(storyId);this.setState(storyId,{...getInitialState(),...getRetainedState(state,isDebugging),shadowCalls:isDebugging?state.shadowCalls:[],chainedCallIds:isDebugging?state.chainedCallIds:new Set,playUntil:isDebugging?state.playUntil:void 0,isPlaying,isDebugging}),this.sync(storyId)};this.channel.on(FORCE_REMOUNT,resetState),this.channel.on(STORY_RENDER_PHASE_CHANGED,({storyId,newPhase})=>{let{isDebugging}=this.getState(storyId);this.setState(storyId,{renderPhase:newPhase}),newPhase==="preparing"&&isDebugging&&resetState({storyId}),newPhase==="playing"&&resetState({storyId,isDebugging}),newPhase==="played"&&this.setState(storyId,{isLocked:!1,isPlaying:!1,isDebugging:!1}),newPhase==="errored"&&this.setState(storyId,{isLocked:!1,isPlaying:!1})}),this.channel.on(SET_CURRENT_STORY,()=>{this.initialized?this.cleanup():this.initialized=!0});let start=({storyId,playUntil})=>{this.getState(storyId).isDebugging||this.setState(storyId,({calls})=>({calls:[],shadowCalls:calls.map(call=>({...call,status:"waiting"})),isDebugging:!0}));let log=this.getLog(storyId);this.setState(storyId,({shadowCalls})=>{if(playUntil||!log.length)return{playUntil};let firstRowIndex=shadowCalls.findIndex(call=>call.id===log[0].callId);return{playUntil:shadowCalls.slice(0,firstRowIndex).filter(call=>call.interceptable&&!call.ancestors.length).slice(-1)[0]?.id}}),this.channel.emit(FORCE_REMOUNT,{storyId,isDebugging:!0})},back=({storyId})=>{let log=this.getLog(storyId).filter(call=>!call.ancestors.length),last=log.reduceRight((res,item,index)=>res>=0||item.status==="waiting"?res:index,-1);start({storyId,playUntil:log[last-1]?.callId})},goto=({storyId,callId})=>{let{calls,shadowCalls,resolvers}=this.getState(storyId),call=calls.find(({id})=>id===callId),shadowCall=shadowCalls.find(({id})=>id===callId);if(!call&&shadowCall&&Object.values(resolvers).length>0){let nextId=this.getLog(storyId).find(c=>c.status==="waiting")?.callId;shadowCall.id!==nextId&&this.setState(storyId,{playUntil:shadowCall.id}),Object.values(resolvers).forEach(resolve=>resolve())}else start({storyId,playUntil:callId})},next=({storyId})=>{let{resolvers}=this.getState(storyId);if(Object.values(resolvers).length>0)Object.values(resolvers).forEach(resolve=>resolve());else{let nextId=this.getLog(storyId).find(c=>c.status==="waiting")?.callId;nextId?start({storyId,playUntil:nextId}):end({storyId})}},end=({storyId})=>{this.setState(storyId,{playUntil:void 0,isDebugging:!1}),Object.values(this.getState(storyId).resolvers).forEach(resolve=>resolve())};this.channel.on(EVENTS.START,start),this.channel.on(EVENTS.BACK,back),this.channel.on(EVENTS.GOTO,goto),this.channel.on(EVENTS.NEXT,next),this.channel.on(EVENTS.END,end)}getState(storyId){return this.state[storyId]||getInitialState()}setState(storyId,update){let state=this.getState(storyId),patch=typeof update=="function"?update(state):update;this.state={...this.state,[storyId]:{...state,...patch}},global.window.parent.__STORYBOOK_ADDON_INTERACTIONS_INSTRUMENTER_STATE__=this.state}cleanup(){this.state=Object.entries(this.state).reduce((acc,[storyId,state])=>{let retainedState=getRetainedState(state);return retainedState&&(acc[storyId]=Object.assign(getInitialState(),retainedState)),acc},{});let payload={controlStates:controlsDisabled,logItems:[]};this.channel.emit(EVENTS.SYNC,payload),global.window.parent.__STORYBOOK_ADDON_INTERACTIONS_INSTRUMENTER_STATE__=this.state}getLog(storyId){let{calls,shadowCalls}=this.getState(storyId),merged=[...shadowCalls];calls.forEach((call,index)=>{merged[index]=call});let seen=new Set;return merged.reduceRight((acc,call)=>(call.args.forEach(arg=>{arg?.__callId__&&seen.add(arg.__callId__)}),call.path.forEach(node=>{node.__callId__&&seen.add(node.__callId__)}),(call.interceptable||call.exception)&&!seen.has(call.id)&&(acc.unshift({callId:call.id,status:call.status,ancestors:call.ancestors}),seen.add(call.id)),acc),[])}instrument(obj,options){if(!isInstrumentable(obj))return obj;let{mutate=!1,path=[]}=options;return Object.keys(obj).reduce((acc,key)=>{let value=obj[key];return typeof value!="function"?(acc[key]=this.instrument(value,{...options,path:path.concat(key)}),acc):typeof value.__originalFn__=="function"?(acc[key]=value,acc):(acc[key]=(...args)=>this.track(key,value,args,options),acc[key].__originalFn__=value,Object.defineProperty(acc[key],"name",{value:key,writable:!1}),Object.keys(value).length>0&&Object.assign(acc[key],this.instrument({...value},{...options,path:path.concat(key)})),acc)},mutate?obj:construct(obj))}track(method,fn,args,options){let storyId=args?.[0]?.__storyId__||global.__STORYBOOK_PREVIEW__?.selectionStore?.selection?.storyId,{cursor,ancestors}=this.getState(storyId);this.setState(storyId,{cursor:cursor+1});let id=`${ancestors.slice(-1)[0]||storyId} [${cursor}] ${method}`,{path=[],intercept=!1,retain=!1}=options,interceptable=typeof intercept=="function"?intercept(method,path):intercept,call={id,cursor,storyId,ancestors,path,method,args,interceptable,retain},result=(interceptable&&!ancestors.length?this.intercept:this.invoke).call(this,fn,call,options);return this.instrument(result,{...options,mutate:!0,path:[{__callId__:call.id}]})}intercept(fn,call,options){let{chainedCallIds,isDebugging,playUntil}=this.getState(call.storyId),isChainedUpon=chainedCallIds.has(call.id);return!isDebugging||isChainedUpon||playUntil?(playUntil===call.id&&this.setState(call.storyId,{playUntil:void 0}),this.invoke(fn,call,options)):new Promise(resolve=>{this.setState(call.storyId,({resolvers})=>({isLocked:!1,resolvers:{...resolvers,[call.id]:resolve}}))}).then(()=>(this.setState(call.storyId,state=>{let{[call.id]:_,...resolvers}=state.resolvers;return{isLocked:!0,resolvers}}),this.invoke(fn,call,options)))}invoke(fn,call,options){let{callRefsByResult,renderPhase}=this.getState(call.storyId),serializeValues=value=>{if(callRefsByResult.has(value))return callRefsByResult.get(value);if(value instanceof Array)return value.map(serializeValues);if(value instanceof Date)return{__date__:{value:value.toISOString()}};if(value instanceof Error){let{name,message,stack}=value;return{__error__:{name,message,stack}}}if(value instanceof RegExp){let{flags,source}=value;return{__regexp__:{flags,source}}}if(value instanceof global.window.HTMLElement){let{prefix,localName,id,classList,innerText}=value,classNames=Array.from(classList);return{__element__:{prefix,localName,id,classNames,innerText}}}return typeof value=="function"?{__function__:{name:value.name}}:typeof value=="symbol"?{__symbol__:{description:value.description}}:typeof value=="object"&&value?.constructor?.name&&value?.constructor?.name!=="Object"?{__class__:{name:value.constructor.name}}:Object.prototype.toString.call(value)==="[object Object]"?Object.fromEntries(Object.entries(value).map(([key,val])=>[key,serializeValues(val)])):value},info={...call,args:call.args.map(serializeValues)};call.path.forEach(ref=>{ref?.__callId__&&this.setState(call.storyId,({chainedCallIds})=>({chainedCallIds:new Set(Array.from(chainedCallIds).concat(ref.__callId__))}))});let handleException=e=>{if(e instanceof Error){let{name,message,stack,callId=call.id}=e,exception={name,message,stack,callId};if(this.update({...info,status:"error",exception}),this.setState(call.storyId,state=>({callRefsByResult:new Map([...Array.from(state.callRefsByResult.entries()),[e,{__callId__:call.id,retain:call.retain}]])})),call.ancestors.length)throw Object.prototype.hasOwnProperty.call(e,"callId")||Object.defineProperty(e,"callId",{value:call.id}),e;if(e!==alreadyCompletedException)throw logger.warn(e),IGNORED_EXCEPTION}throw e};try{if(renderPhase==="played"&&!call.retain)throw alreadyCompletedException;let finalArgs=(options.getArgs?options.getArgs(call,this.getState(call.storyId)):call.args).map(arg=>typeof arg!="function"||Object.keys(arg).length?arg:(...args)=>{let{cursor,ancestors}=this.getState(call.storyId);this.setState(call.storyId,{cursor:0,ancestors:[...ancestors,call.id]});let restore=()=>this.setState(call.storyId,{cursor,ancestors}),willRestore=!1;try{let res=arg(...args);return res instanceof Promise?(willRestore=!0,res.finally(restore)):res}finally{willRestore||restore()}}),result=fn(...finalArgs);return result&&["object","function","symbol"].includes(typeof result)&&this.setState(call.storyId,state=>({callRefsByResult:new Map([...Array.from(state.callRefsByResult.entries()),[result,{__callId__:call.id,retain:call.retain}]])})),this.update({...info,status:result instanceof Promise?"active":"done"}),result instanceof Promise?result.then(value=>(this.update({...info,status:"done"}),value),handleException):result}catch(e){return handleException(e)}}update(call){this.channel.emit(EVENTS.CALL,call),this.setState(call.storyId,({calls})=>{let callsById=calls.concat(call).reduce((a,c)=>Object.assign(a,{[c.id]:c}),{});return{calls:Object.values(callsById).sort((a,b)=>a.id.localeCompare(b.id,void 0,{numeric:!0}))}}),this.sync(call.storyId)}sync(storyId){let synchronize=()=>{let{isLocked,isPlaying}=this.getState(storyId),logItems=this.getLog(storyId),pausedAt=logItems.filter(({ancestors})=>!ancestors.length).find(item=>item.status==="waiting")?.callId,hasActive=logItems.some(item=>item.status==="active");if(isLocked||hasActive||logItems.length===0){let payload2={controlStates:controlsDisabled,logItems};this.channel.emit(EVENTS.SYNC,payload2);return}let hasPrevious=logItems.some(item=>["done","error"].includes(item.status)),payload={controlStates:{start:hasPrevious,back:hasPrevious,goto:!0,next:isPlaying,end:isPlaying},logItems,pausedAt};this.channel.emit(EVENTS.SYNC,payload)};this.setState(storyId,({syncTimeout})=>(clearTimeout(syncTimeout),{syncTimeout:setTimeout(synchronize,0)}))}};function instrument(obj,options={}){try{let forceInstrument=!1,skipInstrument=!1;return global.window.location?.search?.includes("instrument=true")?forceInstrument=!0:global.window.location?.search?.includes("instrument=false")&&(skipInstrument=!0),global.window.parent===global.window&&!forceInstrument||skipInstrument?obj:(global.window.__STORYBOOK_ADDON_INTERACTIONS_INSTRUMENTER__||(global.window.__STORYBOOK_ADDON_INTERACTIONS_INSTRUMENTER__=new Instrumenter),global.window.__STORYBOOK_ADDON_INTERACTIONS_INSTRUMENTER__.instrument(obj,options))}catch(e){return once.warn(e),obj}}export{CallStates,EVENTS,instrument};
1
+ import { addons } from '@storybook/preview-api';
2
+ import { once, logger } from '@storybook/client-logger';
3
+ import { FORCE_REMOUNT, STORY_RENDER_PHASE_CHANGED, SET_CURRENT_STORY, IGNORED_EXCEPTION } from '@storybook/core-events';
4
+ import { global } from '@storybook/global';
5
+
6
+ var CallStates=(CallStates2=>(CallStates2.DONE="done",CallStates2.ERROR="error",CallStates2.ACTIVE="active",CallStates2.WAITING="waiting",CallStates2))(CallStates||{});var EVENTS={CALL:"storybook/instrumenter/call",SYNC:"storybook/instrumenter/sync",START:"storybook/instrumenter/start",BACK:"storybook/instrumenter/back",GOTO:"storybook/instrumenter/goto",NEXT:"storybook/instrumenter/next",END:"storybook/instrumenter/end"},controlsDisabled={start:!1,back:!1,goto:!1,next:!1,end:!1},alreadyCompletedException=new Error("This function ran after the play function completed. Did you forget to `await` it?"),isObject=o=>Object.prototype.toString.call(o)==="[object Object]",isModule=o=>Object.prototype.toString.call(o)==="[object Module]",isInstrumentable=o=>{if(!isObject(o)&&!isModule(o))return !1;if(o.constructor===void 0)return !0;let proto=o.constructor.prototype;return !(!isObject(proto)||Object.prototype.hasOwnProperty.call(proto,"isPrototypeOf")===!1)},construct=obj=>{try{return new obj.constructor}catch{return {}}},getInitialState=()=>({renderPhase:void 0,isDebugging:!1,isPlaying:!1,isLocked:!1,cursor:0,calls:[],shadowCalls:[],callRefsByResult:new Map,chainedCallIds:new Set,ancestors:[],playUntil:void 0,resolvers:{},syncTimeout:void 0}),getRetainedState=(state,isDebugging=!1)=>{let calls=(isDebugging?state.shadowCalls:state.calls).filter(call=>call.retain);if(!calls.length)return;let callRefsByResult=new Map(Array.from(state.callRefsByResult.entries()).filter(([,ref])=>ref.retain));return {cursor:calls.length,calls,callRefsByResult}},Instrumenter=class{constructor(){this.initialized=!1;this.channel=addons.getChannel(),this.state=global.window.parent.__STORYBOOK_ADDON_INTERACTIONS_INSTRUMENTER_STATE__||{};let resetState=({storyId,isPlaying=!0,isDebugging=!1})=>{let state=this.getState(storyId);this.setState(storyId,{...getInitialState(),...getRetainedState(state,isDebugging),shadowCalls:isDebugging?state.shadowCalls:[],chainedCallIds:isDebugging?state.chainedCallIds:new Set,playUntil:isDebugging?state.playUntil:void 0,isPlaying,isDebugging}),this.sync(storyId);};this.channel.on(FORCE_REMOUNT,resetState),this.channel.on(STORY_RENDER_PHASE_CHANGED,({storyId,newPhase})=>{let{isDebugging}=this.getState(storyId);this.setState(storyId,{renderPhase:newPhase}),newPhase==="preparing"&&isDebugging&&resetState({storyId}),newPhase==="playing"&&resetState({storyId,isDebugging}),newPhase==="played"&&this.setState(storyId,{isLocked:!1,isPlaying:!1,isDebugging:!1}),newPhase==="errored"&&this.setState(storyId,{isLocked:!1,isPlaying:!1});}),this.channel.on(SET_CURRENT_STORY,()=>{this.initialized?this.cleanup():this.initialized=!0;});let start=({storyId,playUntil})=>{this.getState(storyId).isDebugging||this.setState(storyId,({calls})=>({calls:[],shadowCalls:calls.map(call=>({...call,status:"waiting"})),isDebugging:!0}));let log=this.getLog(storyId);this.setState(storyId,({shadowCalls})=>{if(playUntil||!log.length)return {playUntil};let firstRowIndex=shadowCalls.findIndex(call=>call.id===log[0].callId);return {playUntil:shadowCalls.slice(0,firstRowIndex).filter(call=>call.interceptable&&!call.ancestors.length).slice(-1)[0]?.id}}),this.channel.emit(FORCE_REMOUNT,{storyId,isDebugging:!0});},back=({storyId})=>{let log=this.getLog(storyId).filter(call=>!call.ancestors.length),last=log.reduceRight((res,item,index)=>res>=0||item.status==="waiting"?res:index,-1);start({storyId,playUntil:log[last-1]?.callId});},goto=({storyId,callId})=>{let{calls,shadowCalls,resolvers}=this.getState(storyId),call=calls.find(({id})=>id===callId),shadowCall=shadowCalls.find(({id})=>id===callId);if(!call&&shadowCall&&Object.values(resolvers).length>0){let nextId=this.getLog(storyId).find(c=>c.status==="waiting")?.callId;shadowCall.id!==nextId&&this.setState(storyId,{playUntil:shadowCall.id}),Object.values(resolvers).forEach(resolve=>resolve());}else start({storyId,playUntil:callId});},next=({storyId})=>{let{resolvers}=this.getState(storyId);if(Object.values(resolvers).length>0)Object.values(resolvers).forEach(resolve=>resolve());else {let nextId=this.getLog(storyId).find(c=>c.status==="waiting")?.callId;nextId?start({storyId,playUntil:nextId}):end({storyId});}},end=({storyId})=>{this.setState(storyId,{playUntil:void 0,isDebugging:!1}),Object.values(this.getState(storyId).resolvers).forEach(resolve=>resolve());};this.channel.on(EVENTS.START,start),this.channel.on(EVENTS.BACK,back),this.channel.on(EVENTS.GOTO,goto),this.channel.on(EVENTS.NEXT,next),this.channel.on(EVENTS.END,end);}getState(storyId){return this.state[storyId]||getInitialState()}setState(storyId,update){let state=this.getState(storyId),patch=typeof update=="function"?update(state):update;this.state={...this.state,[storyId]:{...state,...patch}},global.window.parent.__STORYBOOK_ADDON_INTERACTIONS_INSTRUMENTER_STATE__=this.state;}cleanup(){this.state=Object.entries(this.state).reduce((acc,[storyId,state])=>{let retainedState=getRetainedState(state);return retainedState&&(acc[storyId]=Object.assign(getInitialState(),retainedState)),acc},{});let payload={controlStates:controlsDisabled,logItems:[]};this.channel.emit(EVENTS.SYNC,payload),global.window.parent.__STORYBOOK_ADDON_INTERACTIONS_INSTRUMENTER_STATE__=this.state;}getLog(storyId){let{calls,shadowCalls}=this.getState(storyId),merged=[...shadowCalls];calls.forEach((call,index)=>{merged[index]=call;});let seen=new Set;return merged.reduceRight((acc,call)=>(call.args.forEach(arg=>{arg?.__callId__&&seen.add(arg.__callId__);}),call.path.forEach(node=>{node.__callId__&&seen.add(node.__callId__);}),(call.interceptable||call.exception)&&!seen.has(call.id)&&(acc.unshift({callId:call.id,status:call.status,ancestors:call.ancestors}),seen.add(call.id)),acc),[])}instrument(obj,options){if(!isInstrumentable(obj))return obj;let{mutate=!1,path=[]}=options;return Object.keys(obj).reduce((acc,key)=>{let value=obj[key];return typeof value!="function"?(acc[key]=this.instrument(value,{...options,path:path.concat(key)}),acc):typeof value.__originalFn__=="function"?(acc[key]=value,acc):(acc[key]=(...args)=>this.track(key,value,args,options),acc[key].__originalFn__=value,Object.defineProperty(acc[key],"name",{value:key,writable:!1}),Object.keys(value).length>0&&Object.assign(acc[key],this.instrument({...value},{...options,path:path.concat(key)})),acc)},mutate?obj:construct(obj))}track(method,fn,args,options){let storyId=args?.[0]?.__storyId__||global.__STORYBOOK_PREVIEW__?.selectionStore?.selection?.storyId,{cursor,ancestors}=this.getState(storyId);this.setState(storyId,{cursor:cursor+1});let id=`${ancestors.slice(-1)[0]||storyId} [${cursor}] ${method}`,{path=[],intercept=!1,retain=!1}=options,interceptable=typeof intercept=="function"?intercept(method,path):intercept,call={id,cursor,storyId,ancestors,path,method,args,interceptable,retain},result=(interceptable&&!ancestors.length?this.intercept:this.invoke).call(this,fn,call,options);return this.instrument(result,{...options,mutate:!0,path:[{__callId__:call.id}]})}intercept(fn,call,options){let{chainedCallIds,isDebugging,playUntil}=this.getState(call.storyId),isChainedUpon=chainedCallIds.has(call.id);return !isDebugging||isChainedUpon||playUntil?(playUntil===call.id&&this.setState(call.storyId,{playUntil:void 0}),this.invoke(fn,call,options)):new Promise(resolve=>{this.setState(call.storyId,({resolvers})=>({isLocked:!1,resolvers:{...resolvers,[call.id]:resolve}}));}).then(()=>(this.setState(call.storyId,state=>{let{[call.id]:_,...resolvers}=state.resolvers;return {isLocked:!0,resolvers}}),this.invoke(fn,call,options)))}invoke(fn,call,options){let{callRefsByResult,renderPhase}=this.getState(call.storyId),serializeValues=value=>{if(callRefsByResult.has(value))return callRefsByResult.get(value);if(value instanceof Array)return value.map(serializeValues);if(value instanceof Date)return {__date__:{value:value.toISOString()}};if(value instanceof Error){let{name,message,stack}=value;return {__error__:{name,message,stack}}}if(value instanceof RegExp){let{flags,source}=value;return {__regexp__:{flags,source}}}if(value instanceof global.window.HTMLElement){let{prefix,localName,id,classList,innerText}=value,classNames=Array.from(classList);return {__element__:{prefix,localName,id,classNames,innerText}}}return typeof value=="function"?{__function__:{name:value.name}}:typeof value=="symbol"?{__symbol__:{description:value.description}}:typeof value=="object"&&value?.constructor?.name&&value?.constructor?.name!=="Object"?{__class__:{name:value.constructor.name}}:Object.prototype.toString.call(value)==="[object Object]"?Object.fromEntries(Object.entries(value).map(([key,val])=>[key,serializeValues(val)])):value},info={...call,args:call.args.map(serializeValues)};call.path.forEach(ref=>{ref?.__callId__&&this.setState(call.storyId,({chainedCallIds})=>({chainedCallIds:new Set(Array.from(chainedCallIds).concat(ref.__callId__))}));});let handleException=e=>{if(e instanceof Error){let{name,message,stack,callId=call.id}=e,exception={name,message,stack,callId};if(this.update({...info,status:"error",exception}),this.setState(call.storyId,state=>({callRefsByResult:new Map([...Array.from(state.callRefsByResult.entries()),[e,{__callId__:call.id,retain:call.retain}]])})),call.ancestors.length)throw Object.prototype.hasOwnProperty.call(e,"callId")||Object.defineProperty(e,"callId",{value:call.id}),e;if(e!==alreadyCompletedException)throw logger.warn(e),IGNORED_EXCEPTION}throw e};try{if(renderPhase==="played"&&!call.retain)throw alreadyCompletedException;let finalArgs=(options.getArgs?options.getArgs(call,this.getState(call.storyId)):call.args).map(arg=>typeof arg!="function"||Object.keys(arg).length?arg:(...args)=>{let{cursor,ancestors}=this.getState(call.storyId);this.setState(call.storyId,{cursor:0,ancestors:[...ancestors,call.id]});let restore=()=>this.setState(call.storyId,{cursor,ancestors}),willRestore=!1;try{let res=arg(...args);return res instanceof Promise?(willRestore=!0,res.finally(restore)):res}finally{willRestore||restore();}}),result=fn(...finalArgs);return result&&["object","function","symbol"].includes(typeof result)&&this.setState(call.storyId,state=>({callRefsByResult:new Map([...Array.from(state.callRefsByResult.entries()),[result,{__callId__:call.id,retain:call.retain}]])})),this.update({...info,status:result instanceof Promise?"active":"done"}),result instanceof Promise?result.then(value=>(this.update({...info,status:"done"}),value),handleException):result}catch(e){return handleException(e)}}update(call){this.channel.emit(EVENTS.CALL,call),this.setState(call.storyId,({calls})=>{let callsById=calls.concat(call).reduce((a,c)=>Object.assign(a,{[c.id]:c}),{});return {calls:Object.values(callsById).sort((a,b)=>a.id.localeCompare(b.id,void 0,{numeric:!0}))}}),this.sync(call.storyId);}sync(storyId){let synchronize=()=>{let{isLocked,isPlaying}=this.getState(storyId),logItems=this.getLog(storyId),pausedAt=logItems.filter(({ancestors})=>!ancestors.length).find(item=>item.status==="waiting")?.callId,hasActive=logItems.some(item=>item.status==="active");if(isLocked||hasActive||logItems.length===0){let payload2={controlStates:controlsDisabled,logItems};this.channel.emit(EVENTS.SYNC,payload2);return}let hasPrevious=logItems.some(item=>["done","error"].includes(item.status)),payload={controlStates:{start:hasPrevious,back:hasPrevious,goto:!0,next:isPlaying,end:isPlaying},logItems,pausedAt};this.channel.emit(EVENTS.SYNC,payload);};this.setState(storyId,({syncTimeout})=>(clearTimeout(syncTimeout),{syncTimeout:setTimeout(synchronize,0)}));}};function instrument(obj,options={}){try{let forceInstrument=!1,skipInstrument=!1;return global.window.location?.search?.includes("instrument=true")?forceInstrument=!0:global.window.location?.search?.includes("instrument=false")&&(skipInstrument=!0),global.window.parent===global.window&&!forceInstrument||skipInstrument?obj:(global.window.__STORYBOOK_ADDON_INTERACTIONS_INSTRUMENTER__||(global.window.__STORYBOOK_ADDON_INTERACTIONS_INSTRUMENTER__=new Instrumenter),global.window.__STORYBOOK_ADDON_INTERACTIONS_INSTRUMENTER__.instrument(obj,options))}catch(e){return once.warn(e),obj}}
7
+
8
+ export { CallStates, EVENTS, instrument };
package/package.json CHANGED
@@ -1,18 +1,18 @@
1
1
  {
2
2
  "name": "@storybook/instrumenter",
3
- "version": "7.0.7",
3
+ "version": "7.0.8",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "storybook"
7
7
  ],
8
- "homepage": "https://github.com/storybookjs/storybook/tree/main/lib/instrumenter",
8
+ "homepage": "https://github.com/storybookjs/storybook/tree/next/code/lib/instrumenter",
9
9
  "bugs": {
10
10
  "url": "https://github.com/storybookjs/storybook/issues"
11
11
  },
12
12
  "repository": {
13
13
  "type": "git",
14
14
  "url": "https://github.com/storybookjs/storybook.git",
15
- "directory": "lib/instrumenter"
15
+ "directory": "code/lib/instrumenter"
16
16
  },
17
17
  "funding": {
18
18
  "type": "opencollective",
@@ -22,10 +22,10 @@
22
22
  "sideEffects": false,
23
23
  "exports": {
24
24
  ".": {
25
+ "types": "./dist/index.d.ts",
25
26
  "node": "./dist/index.js",
26
27
  "require": "./dist/index.js",
27
- "import": "./dist/index.mjs",
28
- "types": "./dist/index.d.ts"
28
+ "import": "./dist/index.mjs"
29
29
  },
30
30
  "./package.json": "./package.json"
31
31
  },
@@ -43,11 +43,11 @@
43
43
  "prep": "../../../scripts/prepare/bundle.ts"
44
44
  },
45
45
  "dependencies": {
46
- "@storybook/channels": "7.0.7",
47
- "@storybook/client-logger": "7.0.7",
48
- "@storybook/core-events": "7.0.7",
46
+ "@storybook/channels": "7.0.8",
47
+ "@storybook/client-logger": "7.0.8",
48
+ "@storybook/core-events": "7.0.8",
49
49
  "@storybook/global": "^5.0.0",
50
- "@storybook/preview-api": "7.0.7"
50
+ "@storybook/preview-api": "7.0.8"
51
51
  },
52
52
  "devDependencies": {
53
53
  "typescript": "~4.9.3"
@@ -60,5 +60,5 @@
60
60
  "./src/index.ts"
61
61
  ]
62
62
  },
63
- "gitHead": "9e352853ca5ce94d81fcdb06c303b4fbf43f8971"
63
+ "gitHead": "9991b68c7d0cd1543c974f358cae9e0d02b29e7e"
64
64
  }