@picked/svelte 0.0.1-dev.1756875690387 → 0.0.1-dev.1762908210565
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 -4
- package/dist/form/index.js +1 -1
- package/dist/hooks/step.d.ts +8 -11
- package/dist/hooks/step.js +1 -1
- package/dist/plugins/devtools/experience.js +1 -1
- package/dist/plugins/devtools/screens/experiences/ExperienceTreeScreen.svelte +1 -1
- package/dist/router/StepRouter.svelte +29 -15
- package/dist/router/context.d.ts +2 -2
- package/package.json +17 -17
package/dist/form/index.d.ts
CHANGED
|
@@ -5,11 +5,12 @@ interface GetFormOptions {
|
|
|
5
5
|
onSuccess?: () => void | Promise<void>;
|
|
6
6
|
onError?: (errors: ValidationError[]) => void | Promise<void>;
|
|
7
7
|
}
|
|
8
|
-
|
|
8
|
+
type SubmitEventWithCurrentTarget = SubmitEvent & {
|
|
9
|
+
currentTarget: EventTarget & HTMLFormElement;
|
|
10
|
+
};
|
|
11
|
+
export declare function getForm({ id: formId, title, onError, onSuccess }: GetFormOptions): {
|
|
9
12
|
form: {
|
|
10
|
-
onsubmit: (
|
|
11
|
-
currentTarget: EventTarget & HTMLFormElement;
|
|
12
|
-
}) => Promise<void>;
|
|
13
|
+
onsubmit: import('effector').EventCallable<SubmitEventWithCurrentTarget>;
|
|
13
14
|
};
|
|
14
15
|
};
|
|
15
16
|
export {};
|
package/dist/form/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getPicked as
|
|
1
|
+
import{createEvent as k,createEffect as l,attach as b,sample as x,split as B}from"effector";import{getPicked as F,getExperience as D}from"../hooks/client.js";import"svelte";import"@picked/client";import"svelte/store";function I({id:f,title:m,onError:d,onSuccess:v}){const i=F(),o=D(),{currentStepStore:p}=o,h=k(),y=l(e=>i.responses.commit(e)),g=b({source:{step:p},effect:l(({step:e})=>{i.eventBus({type:"form_submit_success",form:{id:f,title:m},experience:o,step:e??void 0}),v==null||v()})}),_=b({source:{step:p},mapParams:(e,a)=>({step:a.step,errors:e.errors}),effect:l(({step:e,errors:a})=>{i.eventBus({type:"form_submit_error",form:{id:f,title:m},exception:{reason:a},experience:o,step:e??void 0}),a.forEach(n=>{i.eventBus({type:"field_validation_error",exception:{reason:[n]},experience:o,step:e??void 0})}),d==null||d(a)})});return x({clock:h,source:{step:p},fn:({step:e})=>({formId:f,title:m,step:e}),target:l(({formId:e,title:a,step:n})=>{i.eventBus({type:"form_submit",form:{id:e,title:a},experience:o,step:n??void 0})})}),x({clock:h,source:{fields:i.fields.listStore,step:p},fn:({fields:e},a)=>{a.preventDefault();const n=new FormData(a.currentTarget),u={data:{},push(s){const r=s.questionId,t=this.data[r];t?Array.isArray(t)&&Array.isArray(s.value)?Array.isArray(t)&&Array.isArray(s.value)&&(typeof t[0]=="string"?this.data[r]=[...t,...s.value].map(String):typeof t[0]=="number"?this.data[r]=[...t,...s.value].map(Number):typeof t[0]=="boolean"?this.data[r]=[...t,...s.value].map(c=>!!c):this.data[r]=s.value):this.data[r]=s.value:this.data[r]=s.value}};for(const[s,r]of n.entries()){const t=e.find(A=>A.id===s);if(!t)continue;const c=t.id;switch(t.type){case"text":u.push({questionId:c,value:t.multiple?[String(r)]:String(r)});break;case"number":u.push({questionId:c,value:t.multiple?[Number(r)]:Number(r)});break;case"boolean":u.push({questionId:c,value:t.multiple?[r==="true"]:r==="true"});break}}return u.data},target:y}),B({source:y.doneData,match:{hasErrors:({errors:e})=>e.length>0},cases:{hasErrors:_,__:g}}),{form:{onsubmit:h}}}export{I as getForm};
|
package/dist/hooks/step.d.ts
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
import { Store } from 'effector';
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { ExperienceStep, Field, Response } from '@picked/client';
|
|
3
|
+
type FieldWithValue = Field & {
|
|
4
|
+
value: Response | undefined;
|
|
5
|
+
};
|
|
4
6
|
export interface StepContext {
|
|
5
|
-
step: Store<
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}>;
|
|
9
|
-
fields: Store<{
|
|
10
|
-
field: Field | undefined;
|
|
11
|
-
value: Response | undefined;
|
|
12
|
-
}[]>;
|
|
13
|
-
isActiveStep?: Readable<boolean>;
|
|
7
|
+
step: Store<ExperienceStep>;
|
|
8
|
+
fields: Store<FieldWithValue[]>;
|
|
9
|
+
isActiveStep: Store<boolean>;
|
|
14
10
|
}
|
|
15
11
|
export declare function getStep(): StepContext;
|
|
16
12
|
export declare function setStepContext(stepId: string): StepContext;
|
|
13
|
+
export {};
|
package/dist/hooks/step.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getContext as
|
|
1
|
+
import{getContext as v,setContext as E}from"svelte";import{createStore as h,combine as a,attach as w,createEffect as C,sample as l}from"effector";import{getStepFields as A}from"@picked/client";import{STEP_CONTEXT_KEY as d}from"../context.js";import{getStepRouter as F}from"../router/context.js";import{getExperience as T,getPicked as P}from"./client.js";function N(){return v(d)}function O(o){const u=T(),i=P(),{activeStep:m}=F(),n=m.map(e=>(e==null?void 0:e.id)===o),s=u.treeStore.map(e=>{const t=e.steps.find(r=>r.id===o);if(!t)throw new Error(`Step with id "${o}" not found in the experience tree.`);return t}),c=h([]),S=a({fields:c,responses:i.responses.listStore},({fields:e,responses:t})=>e.map(r=>{var f;const g=(f=t.find(x=>x.fieldId===r.id))==null?void 0:f.value;return{...r,value:g}})),p=w({source:a({step:s,fields:i.fields.listStore}),effect:C(async({step:{fieldIds:e},fields:t})=>await A(i,t.filter(r=>e.includes(r.id))))});return l({source:{isActiveStep:n},filter:({isActiveStep:e})=>e,target:p}),l({source:p.doneData,target:c}),E(d,{step:s,fields:S,isActiveStep:n})}export{N as getStep,O as setStepContext};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createExperience as e}from"@picked/client/plugins/create-experience";import{adaptSvelteComponent as o}from"../../component.js";import t from"./DevToolsExperience.svelte";const p=e({id:"svelte-devtools",name:"Picked Devtools",decide:{},targets:[{selector:"main",placement:"append"}],
|
|
1
|
+
import{createExperience as e}from"@picked/client/plugins/create-experience";import{adaptSvelteComponent as o}from"../../component.js";import t from"./DevToolsExperience.svelte";const p=e({id:"svelte-devtools",name:"Picked Devtools",decide:{},targets:[{selector:"main",placement:"append"}],component:o(t)});p.addStep({label:"Tools"});export{p as devtoolsExperience};
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
if (node.type === 'origin') return 'Start'
|
|
49
49
|
if (node.type === 'step' && node.stepId)
|
|
50
50
|
return stepsMap.get(node.stepId)?.label ?? 'Unknown Step'
|
|
51
|
-
if (node.type === 'conditional' && node.conditionalId) return `Condition
|
|
51
|
+
if (node.type === 'conditional' && node.conditionalId) return `Condition`
|
|
52
52
|
return 'Unknown Node'
|
|
53
53
|
}
|
|
54
54
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import {
|
|
2
|
+
import { createEvent, createStore, sample } from 'effector'
|
|
3
|
+
import { supportsWindow } from '@picked/client'
|
|
3
4
|
import { getExperience } from '../hooks'
|
|
4
5
|
import { setStepRouter, type Step } from './context'
|
|
5
6
|
|
|
@@ -7,45 +8,58 @@
|
|
|
7
8
|
|
|
8
9
|
const { currentStepStore } = experience
|
|
9
10
|
|
|
10
|
-
const
|
|
11
|
+
const activeStepStore = createStore<Step | null>(null)
|
|
11
12
|
let hasActiveStep = false
|
|
12
|
-
const
|
|
13
|
+
const stepsStore = createStore<Step[]>([])
|
|
14
|
+
|
|
15
|
+
const registerStepEvent = createEvent<Step>()
|
|
16
|
+
const unregisterStepEvent = createEvent<Step>()
|
|
17
|
+
const setActiveStepEvent = createEvent<Step | null>()
|
|
18
|
+
|
|
19
|
+
stepsStore.on(registerStepEvent, (state, step) => [...state, step])
|
|
20
|
+
stepsStore.on(unregisterStepEvent, (state, step) => state.filter((s) => s !== step))
|
|
21
|
+
|
|
22
|
+
sample({
|
|
23
|
+
source: setActiveStepEvent,
|
|
24
|
+
filter: (step) => step !== null,
|
|
25
|
+
target: activeStepStore,
|
|
26
|
+
})
|
|
13
27
|
|
|
14
28
|
const registerStep = (step: Step) => {
|
|
15
29
|
// todo: getIsSSR context
|
|
16
30
|
|
|
17
|
-
if (
|
|
31
|
+
if (!supportsWindow()) {
|
|
18
32
|
// In SSR we should set the activeStep immediately if it is a match.
|
|
19
33
|
// If there are more Routes being registered after a match is found,
|
|
20
34
|
// we just skip them.
|
|
21
35
|
if (hasActiveStep) return
|
|
22
36
|
|
|
23
|
-
const isMatchingStep = step.id ===
|
|
37
|
+
const isMatchingStep = step.id === currentStepStore.getState()?.id
|
|
24
38
|
|
|
25
39
|
if (isMatchingStep) {
|
|
26
|
-
|
|
40
|
+
setActiveStepEvent(step)
|
|
27
41
|
hasActiveStep = true
|
|
28
42
|
}
|
|
29
43
|
} else {
|
|
30
|
-
|
|
44
|
+
registerStepEvent(step)
|
|
31
45
|
}
|
|
32
46
|
}
|
|
33
47
|
|
|
34
48
|
const unregisterStep = (step: Step) => {
|
|
35
|
-
|
|
49
|
+
unregisterStepEvent(step)
|
|
36
50
|
}
|
|
37
51
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
52
|
+
sample({
|
|
53
|
+
source: { steps: stepsStore, currentStep: currentStepStore },
|
|
54
|
+
fn: ({ steps, currentStep }) => steps.find((s) => s.id === currentStep?.id) || null,
|
|
55
|
+
target: setActiveStepEvent,
|
|
56
|
+
})
|
|
41
57
|
|
|
42
58
|
setStepRouter({
|
|
43
59
|
registerStep,
|
|
44
60
|
unregisterStep,
|
|
45
|
-
activeStep,
|
|
61
|
+
activeStep: activeStepStore.map((val) => val),
|
|
46
62
|
})
|
|
47
63
|
</script>
|
|
48
64
|
|
|
49
|
-
|
|
50
|
-
<slot />
|
|
51
|
-
{/if}
|
|
65
|
+
<slot />
|
package/dist/router/context.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Store } from 'effector';
|
|
2
2
|
export interface Step {
|
|
3
3
|
id: string;
|
|
4
4
|
}
|
|
5
5
|
interface ContextOptions {
|
|
6
|
-
activeStep
|
|
6
|
+
activeStep: Store<Step | null>;
|
|
7
7
|
unregisterStep: (step: Step) => void;
|
|
8
8
|
registerStep: (step: Step) => void;
|
|
9
9
|
}
|
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.1762908210565",
|
|
4
4
|
"dependencies": {
|
|
5
5
|
"d3": "^7.9.0"
|
|
6
6
|
},
|
|
@@ -18,51 +18,51 @@
|
|
|
18
18
|
"svelte-check": "^4.2.2",
|
|
19
19
|
"typedoc": "^0.28.5",
|
|
20
20
|
"typedoc-plugin-markdown": "^4.6.3",
|
|
21
|
-
"vite": "^6.
|
|
21
|
+
"vite": "^6.4.1",
|
|
22
22
|
"vite-plugin-dts": "^4.5.4"
|
|
23
23
|
},
|
|
24
24
|
"exports": {
|
|
25
25
|
".": {
|
|
26
26
|
"types": "./dist/index.d.ts",
|
|
27
27
|
"import": "./dist/index.js",
|
|
28
|
-
"
|
|
29
|
-
"
|
|
28
|
+
"svelte": "./dist/index.js",
|
|
29
|
+
"default": "./dist/index.js"
|
|
30
30
|
},
|
|
31
31
|
"./server": {
|
|
32
32
|
"types": "./dist/server/index.d.ts",
|
|
33
33
|
"import": "./dist/server/index.js",
|
|
34
|
-
"
|
|
35
|
-
"
|
|
34
|
+
"svelte": "./dist/server/index.js",
|
|
35
|
+
"default": "./dist/server/index.js"
|
|
36
36
|
},
|
|
37
37
|
"./router": {
|
|
38
38
|
"types": "./dist/router/index.d.ts",
|
|
39
39
|
"import": "./dist/router/index.js",
|
|
40
|
-
"
|
|
41
|
-
"
|
|
40
|
+
"svelte": "./dist/router/index.js",
|
|
41
|
+
"default": "./dist/router/index.js"
|
|
42
42
|
},
|
|
43
43
|
"./form": {
|
|
44
44
|
"types": "./dist/form/index.d.ts",
|
|
45
45
|
"import": "./dist/form/index.js",
|
|
46
|
-
"
|
|
47
|
-
"
|
|
46
|
+
"svelte": "./dist/form/index.js",
|
|
47
|
+
"default": "./dist/form/index.js"
|
|
48
48
|
},
|
|
49
49
|
"./hooks": {
|
|
50
50
|
"types": "./dist/hooks/index.d.ts",
|
|
51
51
|
"import": "./dist/hooks/index.js",
|
|
52
|
-
"
|
|
53
|
-
"
|
|
52
|
+
"svelte": "./dist/hooks/index.js",
|
|
53
|
+
"default": "./dist/hooks/index.js"
|
|
54
54
|
},
|
|
55
55
|
"./plugins/framework": {
|
|
56
56
|
"types": "./dist/plugins/framework/index.d.ts",
|
|
57
57
|
"import": "./dist/plugins/framework/index.js",
|
|
58
|
-
"
|
|
59
|
-
"
|
|
58
|
+
"svelte": "./dist/plugins/framework/index.js",
|
|
59
|
+
"default": "./dist/plugins/framework/index.js"
|
|
60
60
|
},
|
|
61
61
|
"./plugins/devtools": {
|
|
62
62
|
"types": "./dist/plugins/devtools/index.d.ts",
|
|
63
63
|
"import": "./dist/plugins/devtools/index.js",
|
|
64
|
-
"
|
|
65
|
-
"
|
|
64
|
+
"svelte": "./dist/plugins/devtools/index.js",
|
|
65
|
+
"default": "./dist/plugins/devtools/index.js"
|
|
66
66
|
}
|
|
67
67
|
},
|
|
68
68
|
"files": [
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
],
|
|
71
71
|
"module": "./dist/index.js",
|
|
72
72
|
"peerDependencies": {
|
|
73
|
-
"@picked/client": "0.0.1-dev.
|
|
73
|
+
"@picked/client": "0.0.1-dev.1762908210565",
|
|
74
74
|
"effector": "^23.3.0",
|
|
75
75
|
"svelte": "^5.34.3"
|
|
76
76
|
},
|