@picked/svelte 0.0.52 → 0.0.53-next.1
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/create-form.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getExperience as e,getPicked as t}from"../hooks/client.js";import{createForm as n}from"@picked/client/form";import*as r from"svelte/internal/client";function i(i,a,o){let s=n({client:t(),experienceInstance:e()},i,a,o);return{...s,form:{...s.form,onBeforeSubmit:e=>{r.user_effect(()=>s.form.onBeforeSubmit(e))},onSuccess:e=>{r.user_effect(()=>s.form.onSuccess(e))},onError:e=>{r.user_effect(()=>s.form.onError(e))}}}}export{i as createForm};
|
|
1
|
+
import{getExperience as e,getPicked as t}from"../hooks/client.js";import{createForm as n}from"@picked/client/form";import*as r from"svelte/internal/client";function i(i,a,o){let s=n({client:t(),experienceInstance:e()},i,a,o);return{...s,form:{...s.form,props:{...s.form.props,onsubmit:e=>s.form.props.onsubmit(e)},onBeforeSubmit:e=>{r.user_effect(()=>s.form.onBeforeSubmit(e))},onSuccess:e=>{r.user_effect(()=>s.form.onSuccess(e))},onError:e=>{r.user_effect(()=>s.form.onError(e))}}}}export{i as createForm};
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
import { Store } from 'effector';
|
|
2
|
-
import { FormInstance as CoreFormInstance, ErrorCallback, SubmitCallback, SuccessCallback } from '@picked/client/form';
|
|
2
|
+
import { FormInstance as CoreFormInstance, ErrorCallback, SubmitCallback, SubmitEventWithCurrentTarget, SuccessCallback } from '@picked/client/form';
|
|
3
3
|
export type { FormField } from '@picked/client/form';
|
|
4
4
|
/**
|
|
5
5
|
* Svelte FormInstance — identical to core but callback registration returns void
|
|
6
6
|
* (cleanup is handled automatically via $effect, not by the consumer).
|
|
7
7
|
*/
|
|
8
8
|
export interface FormInstance<TFieldIds extends string = string> extends Omit<CoreFormInstance<TFieldIds>, 'form'> {
|
|
9
|
-
form: Omit<CoreFormInstance<TFieldIds>['form'], 'onBeforeSubmit' | 'onSuccess' | 'onError'> & {
|
|
9
|
+
form: Omit<CoreFormInstance<TFieldIds>['form'], 'onBeforeSubmit' | 'onSuccess' | 'onError' | 'props'> & {
|
|
10
|
+
props: {
|
|
11
|
+
onsubmit: (e: SubmitEventWithCurrentTarget) => void;
|
|
12
|
+
};
|
|
10
13
|
onBeforeSubmit: (callback: SubmitCallback<TFieldIds>) => void;
|
|
11
14
|
onSuccess: (callback: SuccessCallback<TFieldIds>) => void;
|
|
12
15
|
onError: (callback: ErrorCallback) => void;
|
|
@@ -15,10 +18,20 @@ export interface FormInstance<TFieldIds extends string = string> extends Omit<Co
|
|
|
15
18
|
/**
|
|
16
19
|
* Creates a form instance with Svelte lifecycle management.
|
|
17
20
|
*
|
|
18
|
-
* Wraps the framework-agnostic createForm from
|
|
19
|
-
* - Injects client and experienceInstance from Svelte context
|
|
20
|
-
* -
|
|
21
|
+
* Wraps the framework-agnostic createForm from `@picked/client/form`:
|
|
22
|
+
* - Injects client and experienceInstance from Svelte context.
|
|
23
|
+
* - Wraps `form.props.onsubmit` as a plain function (not an Effector EventCallable).
|
|
24
|
+
* - Auto-wires callback cleanup via `$effect` so consumers don't need to manage lifecycle.
|
|
21
25
|
*
|
|
22
26
|
* Used internally by setStepContext — access via getStep() in components.
|
|
27
|
+
*
|
|
28
|
+
* @param {string} formId - Unique identifier for this form instance.
|
|
29
|
+
* @param {Store<string>} title - Reactive store holding the form/step title.
|
|
30
|
+
* @param {Store<string[]>} fieldIds - Reactive store of field IDs that belong to this form.
|
|
31
|
+
* @returns {FormInstance} A form instance with reactive field stores, submission handlers, and callback registration.
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* const { form, fields } = createForm('lead-capture', $title, $fieldIds)
|
|
35
|
+
* ```
|
|
23
36
|
*/
|
|
24
37
|
export declare function createForm(formId: string, title: Store<string>, fieldIds: Store<string[]>): FormInstance;
|
package/dist/form/get-form.d.ts
CHANGED
|
@@ -8,6 +8,19 @@ interface GetFormOptions {
|
|
|
8
8
|
type SubmitEventWithCurrentTarget = SubmitEvent & {
|
|
9
9
|
currentTarget: EventTarget & HTMLFormElement;
|
|
10
10
|
};
|
|
11
|
+
/**
|
|
12
|
+
* Creates a form submission handler with imperative callback lifecycle.
|
|
13
|
+
*
|
|
14
|
+
* Wires an Effector pipeline that builds responses from FormData and commits them.
|
|
15
|
+
* Unhandled commit failures are surfaced via the onError callback.
|
|
16
|
+
*
|
|
17
|
+
* @param {GetFormOptions} options - Form configuration including callbacks.
|
|
18
|
+
* @returns {object} An object with the form submit event to spread onto a form element.
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* const { form } = getForm({ id: 'lead', title: 'Lead Capture', onSuccess: () => {} })
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
11
24
|
export declare function getForm({ id: formId, title, onError, onSuccess }: GetFormOptions): {
|
|
12
25
|
form: {
|
|
13
26
|
onsubmit: import('effector').EventCallable<SubmitEventWithCurrentTarget>;
|
package/dist/form/get-form.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getExperience as e,getPicked as t}from"../hooks/client.js";import{getStep as n}from"../hooks/step.js";import"../hooks/index.js";import{buildResponsesFromFormData as r}from"@picked/client/form";import{attach as i,createEffect as a,createEvent as o,sample as s,split as c}from"effector";function l({id:l,title:u,onError:d,onSuccess:f}){let p=t(),m=n(),h=e(),{currentStepStore:g}=h,_=o(),v=a(e=>p.responses.commit(e)),y=i({source:{step:g},effect:a(({step:e})=>{p.eventBus({type:`form_submit_success`,form:{id:l,title:u},experience:h,step:e??void 0}),f?.()})}),b=i({source:{step:g},mapParams:(e,t)=>({step:t.step,errors:e.errors}),effect:a(({step:e,errors:t})=>{p.eventBus({type:`form_submit_error`,form:{id:l,title:u},exception:{reason:t},experience:h,step:e??void 0}),t.forEach(t=>{p.eventBus({type:`field_validation_error`,exception:{reason:[t]},experience:h,step:e??void 0})}),d?.(t)})});return s({clock:_,source:{step:g},fn:({step:e})=>({formId:l,title:u,step:e}),target:a(({formId:e,title:t,step:n})=>{p.eventBus({type:`form_submit`,form:{id:e,title:t},experience:h,step:n??void 0})})}),s({clock:_,source:{fields:p.fields.listStore,stepFields:m.fields,step:g},fn:({stepFields:e},t)=>(t.preventDefault(),r(e,new FormData(t.currentTarget))),target:v}),c({source:v.doneData,match:{hasErrors:({errors:e})=>e.length>0},cases:{hasErrors:b,__:y}}),{form:{onsubmit:_}}}export{l as getForm};
|
|
1
|
+
import{getExperience as e,getPicked as t}from"../hooks/client.js";import{getStep as n}from"../hooks/step.js";import"../hooks/index.js";import{buildResponsesFromFormData as r}from"@picked/client/form";import{attach as i,createEffect as a,createEvent as o,sample as s,split as c}from"effector";function l({id:l,title:u,onError:d,onSuccess:f}){let p=t(),m=n(),h=e(),{currentStepStore:g}=h,_=o(),v=a(e=>p.responses.commit(e)),y=i({source:{step:g},effect:a(({step:e})=>{p.eventBus({type:`form_submit_success`,form:{id:l,title:u},experience:h,step:e??void 0}),f?.()})}),b=i({source:{step:g},mapParams:(e,t)=>({step:t.step,errors:e.errors}),effect:a(({step:e,errors:t})=>{p.eventBus({type:`form_submit_error`,form:{id:l,title:u},exception:{reason:t},experience:h,step:e??void 0}),t.forEach(t=>{p.eventBus({type:`field_validation_error`,exception:{reason:[t]},experience:h,step:e??void 0})}),d?.(t)})});return s({clock:_,source:{step:g},fn:({step:e})=>({formId:l,title:u,step:e}),target:a(({formId:e,title:t,step:n})=>{p.eventBus({type:`form_submit`,form:{id:e,title:t},experience:h,step:n??void 0})})}),s({clock:_,source:{fields:p.fields.listStore,stepFields:m.fields,step:g},fn:({stepFields:e},t)=>(t.preventDefault(),r(e,new FormData(t.currentTarget))),target:v}),c({source:v.doneData,match:{hasErrors:({errors:e})=>e.length>0},cases:{hasErrors:b,__:y}}),s({clock:v.fail,fn:({error:e})=>({errors:[{fieldKey:``,userMessage:`An unexpected error occurred`,systemMessage:e instanceof Error?e.message:String(e),value:null}]}),target:b}),{form:{onsubmit:_}}}export{l as getForm};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@picked/svelte",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.53-next.1",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"d3": "^7.9.0"
|
|
6
6
|
},
|
|
@@ -88,7 +88,7 @@
|
|
|
88
88
|
},
|
|
89
89
|
"module": "./dist/index.js",
|
|
90
90
|
"peerDependencies": {
|
|
91
|
-
"@picked/client": "0.0.
|
|
91
|
+
"@picked/client": "0.0.53-next.1",
|
|
92
92
|
"effector": "^23.3.0",
|
|
93
93
|
"svelte": "^5.46.4"
|
|
94
94
|
},
|