@picked/react 0.0.6-next.1 → 0.0.7-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/context.d.ts CHANGED
@@ -2,6 +2,7 @@ import { Picked } from '@picked/client';
2
2
  export declare const ClientContext: import('react').Context<Picked | null>;
3
3
  export declare const ClientProvider: import('react').Provider<Picked | null>;
4
4
  export declare const ExperienceContext: import('react').Context<{
5
+ id: string;
5
6
  experienceId: string;
6
7
  configStore: import('effector').Store<{
7
8
  type: string;
@@ -38,6 +39,7 @@ export declare const ExperienceContext: import('react').Context<{
38
39
  stepsHistoryStore: import('effector').Store<import('@picked/client').HistoryEntry[]>;
39
40
  } | null>;
40
41
  export declare const ExperienceProvider: import('react').Provider<{
42
+ id: string;
41
43
  experienceId: string;
42
44
  configStore: import('effector').Store<{
43
45
  type: string;
@@ -1 +1 @@
1
- {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAsB,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAEhE,eAAO,MAAM,aAAa,wCAAqC,CAAA;AAC/D,eAAO,MAAM,cAAc,yCAAyB,CAAA;AAEpD,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SAAiD,CAAA;AAC/E,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SAA6B,CAAA"}
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAsB,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAEhE,eAAO,MAAM,aAAa,wCAAqC,CAAA;AAC/D,eAAO,MAAM,cAAc,yCAAyB,CAAA;AAEpD,eAAO,MAAM,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SAAiD,CAAA;AAC/E,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SAA6B,CAAA"}
@@ -1,25 +1,26 @@
1
+ import { Store } from 'effector';
1
2
  import { Field, Response } from '@picked/client';
2
- export interface StepContextValue {
3
- step: {
4
- id: string;
5
- label: string;
6
- };
7
- fields: {
8
- field: Field | undefined;
9
- value: Response | undefined;
10
- }[];
11
- isActiveStep: boolean;
3
+ type FieldWithValue = Field & {
4
+ value: Response | undefined;
5
+ };
6
+ type StepWithLabel = {
7
+ id: string;
8
+ label: string;
9
+ };
10
+ export interface StepContext {
11
+ step: Store<StepWithLabel>;
12
+ fields: Store<FieldWithValue[]>;
13
+ isActiveStep?: boolean;
12
14
  }
13
- export declare function useStep(): StepContextValue;
15
+ export declare function useStep(): {
16
+ step: StepWithLabel;
17
+ fields: FieldWithValue[];
18
+ isActiveStep: boolean;
19
+ };
14
20
  export declare function useSetStepContext(stepId: string): {
15
- step: {
16
- id: string;
17
- label: string;
18
- };
19
- fields: {
20
- field: Field | undefined;
21
- value: import('@picked/client').FieldValue | undefined;
22
- }[];
21
+ step: StepWithLabel;
22
+ fields: FieldWithValue[];
23
23
  isActiveStep: boolean;
24
24
  };
25
+ export {};
25
26
  //# sourceMappingURL=step.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"step.d.ts","sourceRoot":"","sources":["../../src/hooks/step.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAKrD,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE;QACJ,EAAE,EAAE,MAAM,CAAA;QACV,KAAK,EAAE,MAAM,CAAA;KACd,CAAA;IACD,MAAM,EAAE;QAAE,KAAK,EAAE,KAAK,GAAG,SAAS,CAAC;QAAC,KAAK,EAAE,QAAQ,GAAG,SAAS,CAAA;KAAE,EAAE,CAAA;IACnE,YAAY,EAAE,OAAO,CAAA;CACtB;AAID,wBAAgB,OAAO,qBAOtB;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM;;;;;;;;;;EA4C/C"}
1
+ {"version":3,"file":"step.d.ts","sourceRoot":"","sources":["../../src/hooks/step.ts"],"names":[],"mappings":"AACA,OAAO,EAAsD,KAAK,KAAK,EAAE,MAAM,UAAU,CAAA;AACzF,OAAO,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAoC,MAAM,gBAAgB,CAAA;AAMvF,KAAK,cAAc,GAAG,KAAK,GAAG;IAAE,KAAK,EAAE,QAAQ,GAAG,SAAS,CAAA;CAAE,CAAA;AAC7D,KAAK,aAAa,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAA;AAOlD,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,KAAK,CAAC,aAAa,CAAC,CAAA;IAC1B,MAAM,EAAE,KAAK,CAAC,cAAc,EAAE,CAAC,CAAA;IAC/B,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB;AAID,wBAAgB,OAAO;;;;EActB;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM;;;;EA+F/C"}
@@ -1 +1 @@
1
- import{createContext as a,useContext as w,useMemo as h}from"react";import{combine as C}from"effector";import{useUnit as b}from"effector-react";import{useStepRouter as E}from"../router/context.js";import{useExperience as P,usePicked as k}from"./client.js";const v=a(null);function $(){const e=w(v);if(!e)throw new Error("useStep must be used within a StepContextProvider");return e}function g(e){const d=P(),s=k(),{activeStep:t}=E(),p=h(()=>(t==null?void 0:t.id)===e,[t==null?void 0:t.id,e]),i=b(C({tree:d.treeStore,fields:s.fields.listStore,responses:s.responses.listStore},({tree:c,fields:f,responses:l})=>{const n=c.steps.find(o=>o.id===e);if(!n)throw new Error(`Step with id "${e}" not found in the experience tree.`);const m=n.fieldIds.map(o=>{var u;const x=f.find(r=>r.id===o),S=(u=l.find(r=>r.fieldId===o))==null?void 0:u.value;return{field:x,value:S}});return{step:{id:n.id,label:n.label},fields:m}}));return{step:i.step,fields:i.fields,isActiveStep:p}}export{g as useSetStepContext,$ as useStep};
1
+ import{createContext as E,useContext as F,useMemo as x}from"react";import{attach as R,createEffect as A,combine as P,createStore as g,sample as k}from"effector";import{evaluateRuleLogic as y}from"@picked/client";import{useUnit as f}from"effector-react";import{useStepRouter as D}from"../router/context.js";import{useExperience as L,usePicked as M}from"./client.js";const U=E(null);function G(){const e=F(U);if(!e)throw new Error("useStep must be used within a StepContextProvider");const i=f(e.step),s=f(e.fields);return{step:i,fields:s,isActiveStep:e.isActiveStep??!1}}function H(e){const i=L(),s=M(),{activeStep:o}=D(),S=x(()=>(o==null?void 0:o.id)===e,[o==null?void 0:o.id,e]),{stepContext:C}=x(()=>{const r=R({source:P({steps:i.treeStore.map(c=>c.steps),fields:s.fields.listStore,responses:s.responses.listStore}),effect:A(async({steps:c,fields:p,responses:h})=>{const l=c.find(t=>t.id===e);if(!l)throw new Error(`Step with id "${e}" not found in the experience tree.`);const w=p.filter(t=>l.fieldIds.includes(t.id)),d=[];for(const t of w)t.condition?await y(s,t.condition)&&d.push(t):d.push(t);const v=d.map(t=>{var m;const a=(m=h.find(b=>b.fieldId===t.id))==null?void 0:m.value;return{...t,value:a}});return{step:{id:l.id,label:l.label},fields:v}})}),u=g({step:{id:e,label:""},fields:[]});return u.on(r.doneData,(c,p)=>p),k({clock:[s.fields.listStore,s.responses.listStore],target:r}),r(),{stepContextFx:r,stepContext:u}},[e,s,i]),n=f(C);return{step:n==null?void 0:n.step,fields:(n==null?void 0:n.fields)||[],isActiveStep:S}}export{H as useSetStepContext,G as useStep};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@picked/react",
3
- "version": "0.0.6-next.1",
3
+ "version": "0.0.7-next.1",
4
4
  "devDependencies": {
5
5
  "@picked/client": "workspace:*",
6
6
  "@repo/eslint-config": "workspace:*",
@@ -54,7 +54,7 @@
54
54
  ],
55
55
  "module": "./dist/index.js",
56
56
  "peerDependencies": {
57
- "@picked/client": "0.0.6-next.1",
57
+ "@picked/client": "0.0.7-next.1",
58
58
  "effector": "^23.3.0",
59
59
  "effector-react": "^23.3.0",
60
60
  "react": "^19.1.0",