notCharles 61da930909 wip
2025-04-24 19:03:34 -04:00

2 lines
1.5 KiB
JavaScript

function p({isSkippable:s,isStepPersistedInQueryString:i,key:n,startStep:r,stepQueryStringKey:o}){return{step:null,init:function(){this.$watch("step",()=>this.updateQueryString()),this.step=this.getSteps().at(r-1),this.autofocusFields()},requestNextStep:async function(){await this.$wire.callSchemaComponentMethod(n,"nextStep",{currentStepIndex:this.getStepIndex(this.step)})},goToNextStep:function(){let t=this.getStepIndex(this.step)+1;t>=this.getSteps().length||(this.step=this.getSteps()[t],this.autofocusFields(),this.scroll())},goToPreviousStep:function(){let t=this.getStepIndex(this.step)-1;t<0||(this.step=this.getSteps()[t],this.autofocusFields(),this.scroll())},scroll:function(){this.$nextTick(()=>{this.$refs.header.children[this.getStepIndex(this.step)].scrollIntoView({behavior:"smooth",block:"start"})})},autofocusFields:function(){this.$nextTick(()=>this.$refs[`step-${this.step}`].querySelector("[autofocus]")?.focus())},getStepIndex:function(t){let e=this.getSteps().findIndex(h=>h===t);return e===-1?0:e},getSteps:function(){return JSON.parse(this.$refs.stepsData.value)},isFirstStep:function(){return this.getStepIndex(this.step)<=0},isLastStep:function(){return this.getStepIndex(this.step)+1>=this.getSteps().length},isStepAccessible:function(t){return s||this.getStepIndex(this.step)>this.getStepIndex(t)},updateQueryString:function(){if(!i)return;let t=new URL(window.location.href);t.searchParams.set(o,this.step),history.replaceState(null,document.title,t.toString())}}}export{p as default};