3 lines
21 KiB
JavaScript
3 lines
21 KiB
JavaScript
|
import{c as G}from"./_commonjsHelpers-725317a4.js";const{addons:Y}=__STORYBOOK_MODULE_PREVIEW_API__,{once:V,logger:K}=__STORYBOOK_MODULE_CLIENT_LOGGER__,{FORCE_REMOUNT:M,STORY_RENDER_PHASE_CHANGED:W,SET_CURRENT_STORY:$,IGNORED_EXCEPTION:z}=__STORYBOOK_MODULE_CORE_EVENTS__,{global:g}=__STORYBOOK_MODULE_GLOBAL__;var H=(s=>(s.DONE="done",s.ERROR="error",s.ACTIVE="active",s.WAITING="waiting",s))(H||{}),y={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"},T={start:!1,back:!1,goto:!1,next:!1,end:!1},A=new Error("This function ran after the play function completed. Did you forget to `await` it?"),P=s=>Object.prototype.toString.call(s)==="[object Object]",X=s=>Object.prototype.toString.call(s)==="[object Module]",J=s=>{if(!P(s)&&!X(s))return!1;if(s.constructor===void 0)return!0;let t=s.constructor.prototype;return!(!P(t)||Object.prototype.hasOwnProperty.call(t,"isPrototypeOf")===!1)},q=s=>{try{return new s.constructor}catch{return{}}},R=()=>({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}),N=(s,t=!1)=>{let e=(t?s.shadowCalls:s.calls).filter(o=>o.retain);if(!e.length)return;let c=new Map(Array.from(s.callRefsByResult.entries()).filter(([,o])=>o.retain));return{cursor:e.length,calls:e,callRefsByResult:c}},Q=class{constructor(){this.initialized=!1,this.channel=Y.getChannel(),this.state=g.window.parent.__STORYBOOK_ADDON_INTERACTIONS_INSTRUMENTER_STATE__||{};let s=({storyId:i,isPlaying:n=!0,isDebugging:r=!1})=>{let l=this.getState(i);this.setState(i,{...R(),...N(l,r),shadowCalls:r?l.shadowCalls:[],chainedCallIds:r?l.chainedCallIds:new Set,playUntil:r?l.playUntil:void 0,isPlaying:n,isDebugging:r}),this.sync(i)};this.channel.on(M,s),this.channel.on(W,({storyId:i,newPhase:n})=>{let{isDebugging:r}=this.getState(i);this.setState(i,{renderPhase:n}),n==="preparing"&&r&&s({storyId:i}),n==="playing"&&s({storyId:i,isDebugging:r}),n==="played"&&this.setState(i,{isLocked:!1,isPlaying:!1,isDebugging:!1}),n==="errored"&&this.setState(i,{isLocked:!1,isPlaying:!1})}),this.channel.on($,()=>{this.initialized?this.cleanup():this.initialized=!0});let t=({storyId:i,playUntil:n})=>{this.getState(i).isDebugging||this.setState(i,({calls:l})=>({calls:[],shadowCalls:l.map(u=>({...u,status:"waiting"})),isDebugging:!0}));let r=this.getLog(i);this.setState(i,({shadowCalls:l})=>{var f;if(n||!r.length)return{playUntil:n};let u=l.findIndex(_=>_.id===r[0].callId);return{playUntil:(f=l.slice(0,u).filter(_=>_.interceptable&&!_.ancestors.length).slice(-1)[0])==null?void 0:f.id}}),this.channel.emit(M,{storyId:i,isDebugging:!0})},e=({storyId:i})=>{var l;let n=this.getLog(i).filter(u=>!u.ancestors.length),r=n.reduceRight((u,f,_)=>u>=0||f.status==="waiting"?u:_,-1);t({storyId:i,playUntil:(l=n[r-1])==null?void 0:l.callId})},c=({storyId:i,callId:n})=>{var d;let{calls:r,shadowCalls:l,resolvers:u}=this.getState(i),f=r.find(({id:p})=>p===n),_=l.find(({id:p})=>p===n);if(!f&&_&&Object.values(u).length>0){let p=(d=this.getLog(i).find(h=>h.status==="waiting"))==null?void 0:d.callId;_.id!==p&&this.setState(i,{playUntil:_.id}),Object.values(u).forEach(h=>h())}else t({storyId:i,playUntil:n})},o=({storyId:i})=>{var r;let{resolvers:n}=this.getState(i);if(Object.values(n).length>0)Object.values(n).forEach(l=>l());else{let l=(r=this.getLog(i).find(u=>u.status==="waiting"))==null?void 0:r.callId;l?t({storyId:i,playUntil:l}):a({storyId:i})}},a=({storyId:i})=>{this.setState(i,{playUntil:void 0,isDebugging:!1}),Object.values(this.getState(i).resolvers).forEach(n=>n())};this.channel.on(y.START,t),this.channel.on(y.BACK,e),this.channel.on(y.GOTO,c),this.channel.on(y.NEXT,o),this.channel.on(y.END,a)}getState(s){return this.state[s]||R()}setState(s,t){let e=this.getState(s),c=typeof t=="function"?t(e):t;this.state={...this.state,[s]:{...e,...c}},g.wi
|
||
|
//# sourceMappingURL=preview-5c6325c3.js.map
|