@picked/svelte 0.0.1-dev.1768358359956 → 0.0.1-dev.1768970669177
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.
- package/dist/form/form.d.ts +12 -4
- package/dist/form/form.js +21 -1
- package/dist/utils/deprecation.d.ts +9 -0
- package/dist/utils/deprecation.js +4 -0
- package/package.json +2 -2
package/dist/form/form.d.ts
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
import { FieldValue, ValidationError } from '@picked/client';
|
|
2
2
|
import { EventCallable, Store } from 'effector';
|
|
3
|
-
type ExtractFieldIds<TFieldIds extends readonly string[]> = TFieldIds[number];
|
|
4
3
|
interface GetFormOptions<TFieldIds extends readonly string[]> {
|
|
5
4
|
id: string;
|
|
6
5
|
title: string;
|
|
7
6
|
fieldIds: TFieldIds;
|
|
7
|
+
onSuccess?: never;
|
|
8
|
+
onError?: never;
|
|
9
|
+
}
|
|
10
|
+
interface GetFormOptionsLegacy {
|
|
11
|
+
id: string;
|
|
12
|
+
title: string;
|
|
13
|
+
fieldIds?: never;
|
|
14
|
+
onSuccess?: () => void | Promise<void>;
|
|
15
|
+
onError?: (errors: ValidationError[]) => void | Promise<void>;
|
|
8
16
|
}
|
|
9
17
|
type SuccessCallback<TFieldIds extends string = string> = (options: {
|
|
10
18
|
data: Record<TFieldIds, FieldValue>;
|
|
@@ -15,7 +23,7 @@ type SubmitCallback<TFieldIds extends string = string> = (data: Record<TFieldIds
|
|
|
15
23
|
type SubmitEventWithCurrentTarget = SubmitEvent & {
|
|
16
24
|
currentTarget: EventTarget & HTMLFormElement;
|
|
17
25
|
};
|
|
18
|
-
export declare function getForm<const TFieldIds extends readonly string[]>(
|
|
26
|
+
export declare function getForm<const TFieldIds extends readonly string[]>(options: GetFormOptions<TFieldIds> | GetFormOptionsLegacy): {
|
|
19
27
|
form: {
|
|
20
28
|
onsubmit: EventCallable<SubmitEventWithCurrentTarget>;
|
|
21
29
|
};
|
|
@@ -170,8 +178,8 @@ export declare function getForm<const TFieldIds extends readonly string[]>({ id:
|
|
|
170
178
|
doNotStoreValue?: boolean;
|
|
171
179
|
};
|
|
172
180
|
})[]>;
|
|
173
|
-
onFormSubmit: (callback: SubmitCallback<
|
|
174
|
-
onFormSuccess: (callback: SuccessCallback<
|
|
181
|
+
onFormSubmit: (callback: SubmitCallback<string>) => void;
|
|
182
|
+
onFormSuccess: (callback: SuccessCallback<string>) => void;
|
|
175
183
|
onFormError: (callback: ErrorCallback) => void;
|
|
176
184
|
isFormSubmitting: import('effector').StoreWritable<boolean>;
|
|
177
185
|
};
|
package/dist/form/form.js
CHANGED
|
@@ -1 +1,21 @@
|
|
|
1
|
-
import*as
|
|
1
|
+
import*as X from"svelte/internal/client";import{getStepFields as Y}from"@picked/client";import{createStore as b,combine as $,attach as N,createEffect as g,sample as n,createEvent as h,split as j}from"effector";import{getContext as z}from"svelte";import{getPicked as G,getExperience as H}from"../hooks/client.js";import{STEP_CONTEXT_KEY as J}from"../context.js";import"svelte/store";import"@picked/analytics";import{warnDeprecation as Q}from"../utils/deprecation.js";function B(l){let u=[];return{executeFx:g(async(...f)=>await l(u,...f)),register:f=>{X.user_effect(()=>(u.push(f),()=>{u=u.filter(v=>v!==f)}))}}}function ne(l){const{id:u,title:F}=l,k=!("fieldIds"in l)||l.fieldIds===void 0;let f,v,I;if(k){v=l.onSuccess,I=l.onError;try{const e=z(J);if(!e)throw new Error("Step context not found");f=e.step.getState().fieldIds}catch{throw new Error("getForm() called without fieldIds parameter requires being inside a <Step> component. Either wrap this component in <Step>, or use the new API: getForm({ id, title, fieldIds: [...] })")}Q("getForm({ onSuccess, onError })",`This API pattern is deprecated. Please migrate to the new observable pattern:
|
|
2
|
+
|
|
3
|
+
Before (deprecated):
|
|
4
|
+
const { form } = getForm({
|
|
5
|
+
id: "my-form",
|
|
6
|
+
title: "My Form",
|
|
7
|
+
onSuccess: () => {...},
|
|
8
|
+
onError: (errors) => {...}
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
After (recommended):
|
|
12
|
+
const { form, onFormSuccess, onFormError } = getForm({
|
|
13
|
+
id: "my-form",
|
|
14
|
+
title: "My Form",
|
|
15
|
+
fieldIds: ["field1", "field2"] as const
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
onFormSuccess(({ data, stopNavigation }) => {...})
|
|
19
|
+
onFormError((errors) => {...})
|
|
20
|
+
|
|
21
|
+
Benefits: Access to form data, type safety, multiple callbacks, navigation control`)}else f=l.fieldIds;const m=G();let i=null,x,w=null;try{i=H(),x=i.currentStepStore,w=i.goToNextStep}catch{x=b(null)}const A=b([]),W=$({fields:A,responses:m.responses.listStore},({fields:e,responses:t})=>e.map(s=>{var a;const p=(a=t.find(r=>r.fieldId===s.id))==null?void 0:a.value;return{...s,value:p}})),O=N({source:m.fields.listStore,effect:g(async e=>{const t=e.filter(s=>f.some(p=>p===s.id));return await Y(m,t)})});n({clock:O.doneData,target:A}),O();const y=h(),T=h(),C=h(),q=h(),P=h(),_=b(!1),M=b(!1);M.on(q,()=>!0).on(y,()=>!1);const E=B(async(e,t)=>{await Promise.all(e.map(s=>Promise.resolve(s(t))))}),S=B(async(e,t)=>{await Promise.all(e.map(s=>Promise.resolve(s(t))))}),D=B(async(e,t)=>{let s=t;for(const p of e){const a=await Promise.resolve(p(s));a!==void 0&&(s=a)}return s}),K=g(async e=>{const t=await m.responses.commit(e);return{data:e,errors:t.errors}}),L=N({source:{step:x},mapParams:(e,t)=>({step:t.step,data:e.data}),effect:g(async({step:e,data:t})=>(i&&m.eventBus({type:"form_submit_success",form:{id:u,title:F},experience:i,step:e??void 0}),t))}),V=N({source:{step:x},mapParams:(e,t)=>({step:t.step,errors:e.errors}),effect:g(async({step:e,errors:t})=>(i&&(m.eventBus({type:"form_submit_error",form:{id:u,title:F},exception:{reason:t},experience:i,step:e??void 0}),t.forEach(s=>{m.eventBus({type:"field_validation_error",exception:{reason:[s]},experience:i,step:e??void 0})})),t))});return n({clock:y,fn:()=>!0,target:_}),n({clock:y,source:{step:x},fn:({step:e})=>({formId:u,title:F,step:e}),target:g(({formId:e,title:t,step:s})=>{i&&m.eventBus({type:"form_submit",form:{id:e,title:t},experience:i,step:s??void 0})})}),n({clock:y,source:{stepFields:A},fn:({stepFields:e},t)=>{t.preventDefault();const s=new FormData(t.currentTarget),p=Array.from(s.entries()),a={data:{},push(r){const c=r.questionId,o=this.data[c];o?Array.isArray(o)&&Array.isArray(r.value)?Array.isArray(o)&&Array.isArray(r.value)&&(typeof o[0]=="string"?this.data[c]=[...o,...r.value].map(String):typeof o[0]=="number"?this.data[c]=[...o,...r.value].map(Number):typeof o[0]=="boolean"?this.data[c]=[...o,...r.value].map(d=>!!d):this.data[c]=r.value):this.data[c]=r.value:this.data[c]=r.value}};return e.forEach(r=>{let c=p.filter(([o])=>o===r.id);c.length===0&&(c=[[r.id,""]]),c.forEach(([,o])=>{const d=r.id;if(o===""){a.push({questionId:d,value:null});return}switch(r.type){case"text":a.push({questionId:d,value:r.multiple?[String(o)]:String(o)});break;case"number":a.push({questionId:d,value:r.multiple?[Number(o)]:Number(o)});break;case"boolean":a.push({questionId:d,value:r.multiple?[o==="true"]:o==="true"});break}})}),a.data},target:D.executeFx}),n({clock:D.executeFx.doneData,target:K}),j({source:K.doneData,match:{hasErrors:({errors:e})=>e.length>0},cases:{hasErrors:V,__:L}}),n({clock:L.doneData,target:T}),n({clock:T,fn:e=>({data:e,stopNavigation:q}),target:E.executeFx}),n({clock:E.executeFx.done,target:P}),w&&n({clock:P,source:M,filter:e=>!e,target:w}),n({clock:V.doneData,target:C}),n({clock:C,target:S.executeFx}),n({clock:[P,S.executeFx.done],fn:()=>!1,target:_}),k&&(v&&E.register(()=>v()),I&&S.register(e=>I(e))),{form:{onsubmit:y},fields:W,onFormSubmit:D.register,onFormSuccess:E.register,onFormError:S.register,isFormSubmitting:_}}export{ne as getForm};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Deprecation warning system
|
|
3
|
+
* Ensures warnings are shown only once per feature per session
|
|
4
|
+
*/
|
|
5
|
+
export declare function warnDeprecation(feature: string, message: string): void;
|
|
6
|
+
/**
|
|
7
|
+
* Clear all deprecation warnings (useful for testing)
|
|
8
|
+
*/
|
|
9
|
+
export declare function clearDeprecationWarnings(): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@picked/svelte",
|
|
3
|
-
"version": "0.0.1-dev.
|
|
3
|
+
"version": "0.0.1-dev.1768970669177",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"d3": "^7.9.0"
|
|
6
6
|
},
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
],
|
|
76
76
|
"module": "./dist/index.js",
|
|
77
77
|
"peerDependencies": {
|
|
78
|
-
"@picked/client": "0.0.1-dev.
|
|
78
|
+
"@picked/client": "0.0.1-dev.1768970669177",
|
|
79
79
|
"effector": "^23.3.0",
|
|
80
80
|
"svelte": "^5.34.3"
|
|
81
81
|
},
|