@picked/svelte 0.0.1-dev.1772057362040 → 0.0.1-dev.1772064704206

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.
@@ -1,13 +1,13 @@
1
1
  import { ValidationError } from '@picked/client';
2
- type SubmitEventWithCurrentTarget = SubmitEvent & {
3
- currentTarget: EventTarget & HTMLFormElement;
4
- };
5
2
  interface GetFormOptions {
6
3
  id: string;
7
4
  title: string;
8
5
  onSuccess?: () => void | Promise<void>;
9
6
  onError?: (errors: ValidationError[]) => void | Promise<void>;
10
7
  }
8
+ type SubmitEventWithCurrentTarget = SubmitEvent & {
9
+ currentTarget: EventTarget & HTMLFormElement;
10
+ };
11
11
  export declare function getForm({ id: formId, title, onError, onSuccess }: GetFormOptions): {
12
12
  form: {
13
13
  onsubmit: import('effector').EventCallable<SubmitEventWithCurrentTarget>;
@@ -1 +1 @@
1
- import{createEvent as g,createEffect as s,attach as u,sample as f,split as E}from"effector";import{getPicked as F,getExperience as b}from"../hooks/client.js";import"@picked/client";import{getStep as h}from"../hooks/step.js";import"svelte";import"svelte/store";import"@picked/analytics";import{buildResponsesFromFormData as S}from"./build-responses.js";function j({id:c,title:n,onError:d,onSuccess:l}){const r=F(),x=h(),o=b(),{currentStepStore:i}=o,p=g(),a=s(e=>r.responses.commit(e)),v=u({source:{step:i},effect:s(({step:e})=>{r.eventBus({type:"form_submit_success",form:{id:c,title:n},experience:o,step:e??void 0}),l?.()})}),_=u({source:{step:i},mapParams:(e,t)=>({step:t.step,errors:e.errors}),effect:s(({step:e,errors:t})=>{r.eventBus({type:"form_submit_error",form:{id:c,title:n},exception:{reason:t},experience:o,step:e??void 0}),t.forEach(m=>{r.eventBus({type:"field_validation_error",exception:{reason:[m]},experience:o,step:e??void 0})}),d?.(t)})});return f({clock:p,source:{step:i},fn:({step:e})=>({formId:c,title:n,step:e}),target:s(({formId:e,title:t,step:m})=>{r.eventBus({type:"form_submit",form:{id:e,title:t},experience:o,step:m??void 0})})}),f({clock:p,source:{stepFields:x.fields},fn:({stepFields:e},t)=>(t.preventDefault(),S(e,new FormData(t.currentTarget))),target:a}),E({source:a.doneData,match:{hasErrors:({errors:e})=>e.length>0},cases:{hasErrors:_,__:v}}),{form:{onsubmit:p}}}export{j as getForm};
1
+ import{createEvent as _,createEffect as m,attach as v,sample as y,split as k}from"effector";import{getPicked as D,getExperience as F}from"../hooks/client.js";import"@picked/client";import{getStep as B}from"../hooks/step.js";import"svelte";import"svelte/store";import"@picked/analytics";function z({id:f,title:l,onError:b,onSuccess:g}){const a=D(),x=B(),i=F(),{currentStepStore:u}=i,d=_(),h=m(r=>a.responses.commit(r)),E=v({source:{step:u},effect:m(({step:r})=>{a.eventBus({type:"form_submit_success",form:{id:f,title:l},experience:i,step:r??void 0}),g?.()})}),S=v({source:{step:u},mapParams:(r,o)=>({step:o.step,errors:r.errors}),effect:m(({step:r,errors:o})=>{a.eventBus({type:"form_submit_error",form:{id:f,title:l},exception:{reason:o},experience:i,step:r??void 0}),o.forEach(c=>{a.eventBus({type:"field_validation_error",exception:{reason:[c]},experience:i,step:r??void 0})}),b?.(o)})});return y({clock:d,source:{step:u},fn:({step:r})=>({formId:f,title:l,step:r}),target:m(({formId:r,title:o,step:c})=>{a.eventBus({type:"form_submit",form:{id:r,title:o},experience:i,step:c??void 0})})}),y({clock:d,source:{fields:a.fields.listStore,stepFields:x.fields,step:u},fn:({stepFields:r},o)=>{o.preventDefault();const c=new FormData(o.currentTarget),A=Array.from(c.entries()),p={data:{},push(t){const s=t.questionId,e=this.data[s];e?Array.isArray(e)&&Array.isArray(t.value)?Array.isArray(e)&&Array.isArray(t.value)&&(typeof e[0]=="string"?this.data[s]=[...e,...t.value].map(String):typeof e[0]=="number"?this.data[s]=[...e,...t.value].map(Number):typeof e[0]=="boolean"?this.data[s]=[...e,...t.value].map(n=>!!n):this.data[s]=t.value):this.data[s]=t.value:this.data[s]=t.value}};return r.forEach(t=>{let s=A.filter(([e])=>e===t.id);s.length===0&&(s=[[t.id,""]]),s.forEach(([,e])=>{const n=t.id;if(e===""){p.push({questionId:n,value:null});return}switch(t.type){case"text":p.push({questionId:n,value:t.multiple?[String(e)]:String(e)});break;case"number":p.push({questionId:n,value:t.multiple?[Number(e)]:Number(e)});break;case"boolean":p.push({questionId:n,value:t.multiple?[e==="true"]:e==="true"});break}})}),p.data},target:h}),k({source:h.doneData,match:{hasErrors:({errors:r})=>r.length>0},cases:{hasErrors:S,__:E}}),{form:{onsubmit:d}}}export{z as getForm};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@picked/svelte",
3
- "version": "0.0.1-dev.1772057362040",
3
+ "version": "0.0.1-dev.1772064704206",
4
4
  "dependencies": {
5
5
  "d3": "^7.9.0"
6
6
  },
@@ -86,7 +86,7 @@
86
86
  },
87
87
  "module": "./dist/index.js",
88
88
  "peerDependencies": {
89
- "@picked/client": "0.0.1-dev.1772057362040",
89
+ "@picked/client": "0.0.1-dev.1772064704206",
90
90
  "effector": "^23.3.0",
91
91
  "svelte": "^5.34.3"
92
92
  },