@picked/svelte 0.0.1-dev.1765906219520 → 0.0.1-dev.1765928585401
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/index.d.ts +5 -2
- package/dist/form/index.js +1 -1
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/step.d.ts +12 -5
- package/dist/hooks/step.js +1 -1
- package/dist/render/browser.js +1 -1
- package/dist/utils/ErrorBoundary.svelte +23 -0
- package/package.json +2 -2
package/dist/form/index.d.ts
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
import { ValidationError } from '@picked/client';
|
|
1
|
+
import { Field, ValidationError } from '@picked/client';
|
|
2
|
+
import { Store } from 'effector';
|
|
3
|
+
import { FieldWithValue } from '../hooks';
|
|
2
4
|
interface GetFormOptions {
|
|
3
5
|
id: string;
|
|
4
6
|
title: string;
|
|
7
|
+
fields: Store<Field[] | FieldWithValue[]>;
|
|
5
8
|
onSuccess?: () => void | Promise<void>;
|
|
6
9
|
onError?: (errors: ValidationError[]) => void | Promise<void>;
|
|
7
10
|
}
|
|
8
11
|
type SubmitEventWithCurrentTarget = SubmitEvent & {
|
|
9
12
|
currentTarget: EventTarget & HTMLFormElement;
|
|
10
13
|
};
|
|
11
|
-
export declare function getForm({ id: formId, title, onError, onSuccess }: GetFormOptions): {
|
|
14
|
+
export declare function getForm({ id: formId, title, fields, onError, onSuccess }: GetFormOptions): {
|
|
12
15
|
form: {
|
|
13
16
|
onsubmit: import('effector').EventCallable<SubmitEventWithCurrentTarget>;
|
|
14
17
|
};
|
package/dist/form/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createEvent as k,createEffect as
|
|
1
|
+
import{createEvent as k,createEffect as u,attach as b,sample as x,split as F}from"effector";import{getPicked as B,getExperience as D}from"../hooks/client.js";import"svelte";import"@picked/client";import"svelte/store";import"@picked/analytics";function T({id:m,title:f,fields:g,onError:l,onSuccess:d}){const o=B(),n=D(),{currentStepStore:h}=n,v=k(),y=u(r=>o.responses.commit(r)),A=b({source:{step:h},effect:u(({step:r})=>{o.eventBus({type:"form_submit_success",form:{id:m,title:f},experience:n,step:r??void 0}),d==null||d()})}),_=b({source:{step:h},mapParams:(r,s)=>({step:s.step,errors:r.errors}),effect:u(({step:r,errors:s})=>{o.eventBus({type:"form_submit_error",form:{id:m,title:f},exception:{reason:s},experience:n,step:r??void 0}),s.forEach(c=>{o.eventBus({type:"field_validation_error",exception:{reason:[c]},experience:n,step:r??void 0})}),console.error("[Picked] Form submission errors:",{errors:s}),l==null||l(s)})});return x({clock:v,source:{step:h},fn:({step:r})=>({formId:m,title:f,step:r}),target:u(({formId:r,title:s,step:c})=>{o.eventBus({type:"form_submit",form:{id:r,title:s},experience:n,step:c??void 0})})}),x({clock:v,source:{fields:o.fields.listStore,stepFields:g},fn:({stepFields:r},s)=>{s.preventDefault();const c=new FormData(s.currentTarget),E=Array.from(c.entries()),p={data:{},push(t){const a=t.questionId,e=this.data[a];e?Array.isArray(e)&&Array.isArray(t.value)?Array.isArray(e)&&Array.isArray(t.value)&&(typeof e[0]=="string"?this.data[a]=[...e,...t.value].map(String):typeof e[0]=="number"?this.data[a]=[...e,...t.value].map(Number):typeof e[0]=="boolean"?this.data[a]=[...e,...t.value].map(i=>!!i):this.data[a]=t.value):this.data[a]=t.value:this.data[a]=t.value}};return r.forEach(t=>{let a=E.filter(([e])=>e===t.id);a.length===0&&(a=[[t.id,""]]),a.forEach(([,e])=>{const i=t.id;if(e===""){p.push({questionId:i,value:null});return}switch(t.type){case"text":p.push({questionId:i,value:t.multiple?[String(e)]:String(e)});break;case"number":p.push({questionId:i,value:t.multiple?[Number(e)]:Number(e)});break;case"boolean":p.push({questionId:i,value:t.multiple?[e==="true"]:e==="true"});break}})}),p.data},target:y}),F({source:y.doneData,match:{hasErrors:({errors:r})=>r.length>0},cases:{hasErrors:_,__:A}}),{form:{onsubmit:v}}}export{T as getForm};
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { getPicked, getExperience } from './client';
|
|
2
|
-
export { getStep, setStepContext } from './step';
|
|
2
|
+
export { getStep, setStepContext, type FieldWithValue } from './step';
|
|
3
3
|
export { useUnit, getContextScope, setContextScope } from './stores';
|
|
4
4
|
export { createSessionStorageStore, createLocalStorageStore } from './storage.js';
|
|
5
5
|
export { getTrackRecommendationPresentEvent } from './events';
|
package/dist/hooks/step.d.ts
CHANGED
|
@@ -1,13 +1,20 @@
|
|
|
1
1
|
import { Store } from 'effector';
|
|
2
|
-
import { ExperienceStep, Field, Response } from '@picked/client';
|
|
3
|
-
|
|
2
|
+
import { ExperienceStep, Field, Response, ValidationError } from '@picked/client';
|
|
3
|
+
import { getForm } from '../form';
|
|
4
|
+
export type FieldWithValue = Field & {
|
|
4
5
|
value: Response | undefined;
|
|
5
6
|
};
|
|
6
|
-
|
|
7
|
+
interface BaseStepContext {
|
|
7
8
|
step: Store<ExperienceStep>;
|
|
8
9
|
fields: Store<FieldWithValue[]>;
|
|
9
10
|
isActiveStep: Store<boolean>;
|
|
10
11
|
}
|
|
11
|
-
export
|
|
12
|
-
|
|
12
|
+
export interface StepContext extends BaseStepContext {
|
|
13
|
+
form: ReturnType<typeof getForm>['form'];
|
|
14
|
+
}
|
|
15
|
+
export declare function getStep(options?: {
|
|
16
|
+
onFormSuccess?: () => void | Promise<void>;
|
|
17
|
+
onFormError?: (errors: ValidationError[]) => void | Promise<void>;
|
|
18
|
+
}): StepContext;
|
|
19
|
+
export declare function setStepContext(stepId: string): BaseStepContext;
|
|
13
20
|
export {};
|
package/dist/hooks/step.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getContext as v,setContext as
|
|
1
|
+
import{getContext as v,setContext as F}from"svelte";import{createStore as h,combine as m,attach as w,createEffect as C,sample as u}from"effector";import{getStepFields as T}from"@picked/client";import{STEP_CONTEXT_KEY as S}from"../context.js";import{getStepRouter as A}from"../router/context.js";import{getForm as b}from"../form/index.js";import{getExperience as p,getPicked as y}from"./client.js";function K(e){const i=v(S),n=p(),o=i.step.getState(),{form:a}=b({id:`${o.id}`,title:o.label||o.id,fields:i.fields,onError(f){var r;(r=e==null?void 0:e.onFormError)==null||r.call(e,f)},async onSuccess(){var r;await((r=e==null?void 0:e.onFormSuccess)==null?void 0:r.call(e))!==!1&&n.goToNextStep()}});return{...i,form:a}}function O(e){const i=p(),n=y(),{activeStep:o}=A(),a=o.map(t=>(t==null?void 0:t.id)===e),f=i.treeStore.map(t=>{const c=t.steps.find(s=>s.id===e);if(!c)throw new Error(`Step with id "${e}" not found in the experience tree.`);return c}),r=h([]),g=m({fields:r,responses:n.responses.listStore},({fields:t,responses:c})=>t.map(s=>{var d;const x=(d=c.find(E=>E.fieldId===s.id))==null?void 0:d.value;return{...s,value:x}})),l=w({source:m({step:f,fields:n.fields.listStore}),effect:C(async({step:{fieldIds:t},fields:c})=>await T(n,c.filter(s=>t.includes(s.id))))});return u({source:{isActiveStep:a},filter:({isActiveStep:t})=>t,target:l}),u({source:l.doneData,target:r}),F(S,{step:f,fields:g,isActiveStep:a})}export{K as getStep,O as setStepContext};
|
package/dist/render/browser.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{mount as
|
|
1
|
+
import{mount as d}from"svelte";import{isValidAdaptedComponent as E}from"../component.js";import{CLIENT_CONTEXT_KEY as f,EXPERIENCE_CONTEXT_KEY as y}from"../context.js";import{mergeArrays as u}from"../utils/array.js";import h from"../utils/ErrorBoundary.svelte";function C(n,e){return new Map([[f,n],[y,e]])}const k=async(n,e,s,o,i)=>{var p,a;if(!E(e))throw new Error("The component is invalid.");const c=u((p=e.style)==null?void 0:p.sheets,i.stylesheets),m=u((a=e.style)==null?void 0:a.css,i.css);c.length&&c.forEach(r=>{const t=document.createElement("link");t.setAttribute("rel","stylesheet"),t.setAttribute("href",r),t.setAttribute("type","text/css"),t.setAttribute("picked-injected","true"),n.appendChild(t)}),m.length&&m.forEach(r=>{const t=document.createElement("style");t.textContent=r,t.setAttribute("type","text/css"),t.setAttribute("picked-injected","true"),n.appendChild(t)});const l=r=>{d(h,{target:n,props:{component:r,componentProps:{client:s,experience:o}},context:C(s,o)})};if(e.component instanceof Promise){const{default:r}=await e.component;l(r);return}l(e.component)},N=n=>{};export{C as createContext,k as renderSvelteComponent,N as unRenderSvelteComponent};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { getPicked } from '../hooks'
|
|
3
|
+
import type { ComponentWithProps } from 'src/component'
|
|
4
|
+
|
|
5
|
+
interface Props {
|
|
6
|
+
component: ComponentWithProps
|
|
7
|
+
componentProps?: Record<string, unknown>
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const { component: InnerComponent, componentProps }: Props = $props()
|
|
11
|
+
|
|
12
|
+
function handleError(error: unknown) {
|
|
13
|
+
const client = getPicked()
|
|
14
|
+
|
|
15
|
+
client.eventBus({
|
|
16
|
+
type: 'exception',
|
|
17
|
+
level: 'error',
|
|
18
|
+
data: error,
|
|
19
|
+
})
|
|
20
|
+
}
|
|
21
|
+
</script>
|
|
22
|
+
|
|
23
|
+
<svelte:boundary onerror={handleError}><InnerComponent {...componentProps} /></svelte:boundary>
|
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.1765928585401",
|
|
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.1765928585401",
|
|
79
79
|
"effector": "^23.3.0",
|
|
80
80
|
"svelte": "^5.34.3"
|
|
81
81
|
},
|