@picked/react 0.0.1-dev.1773729274420 → 0.0.1-dev.1773804563218

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.
@@ -1,16 +1,16 @@
1
1
  import { ExperienceInstance, Picked } from '@picked/client';
2
2
  /**
3
- * Retrieves the Picked Client for the Experience Instance
4
- *
5
- * @returns The Picked client instance that provides access to experiences, steps, and other Picked functionality
3
+ * Retrieves the Picked Client for the Experience Instance.
4
+ * @returns The Picked client instance that provides access to experiences, steps, and other Picked functionality.
5
+ * @example
6
+ * const client = usePicked()
6
7
  */
7
8
  export declare function usePicked(): Picked;
8
9
  /**
9
- * Retrieves the Experience Store for the current Experience Instance
10
- *
11
- * @returns The Experience store instance that provides access to experience configuration and state
10
+ * Retrieves the Experience Store for the current Experience Instance.
11
+ * @returns The Experience store instance that provides access to experience configuration and state.
12
+ * @example
13
+ * const experience = useExperience()
12
14
  */
13
15
  export declare function useExperience(): ExperienceInstance;
14
- export declare const getPicked: typeof usePicked;
15
- export declare const getExperience: typeof useExperience;
16
16
  //# sourceMappingURL=client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/hooks/client.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAGhE;;;;GAIG;AACH,wBAAgB,SAAS,IAAI,MAAM,CAOlC;AAED;;;;GAIG;AACH,wBAAgB,aAAa,IAAI,kBAAkB,CAOlD;AAGD,eAAO,MAAM,SAAS,kBAAY,CAAA;AAClC,eAAO,MAAM,aAAa,sBAAgB,CAAA"}
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/hooks/client.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAA;AAGhE;;;;;GAKG;AACH,wBAAgB,SAAS,IAAI,MAAM,CAOlC;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,IAAI,kBAAkB,CAOlD"}
@@ -1 +1 @@
1
- import{useContext as t}from"react";import{ExperienceContext as n,ClientContext as r}from"../context.js";function i(){const e=t(r);if(!e)throw new Error("usePicked must be used within a ClientProvider");return e}function o(){const e=t(n);if(!e)throw new Error("useExperience must be used within an ExperienceProvider");return e}const u=i,x=o;export{x as getExperience,u as getPicked,o as useExperience,i as usePicked};
1
+ import{useContext as t}from"react";import{ExperienceContext as r,ClientContext as n}from"../context.js";function u(){const e=t(n);if(!e)throw new Error("usePicked must be used within a ClientProvider");return e}function c(){const e=t(r);if(!e)throw new Error("useExperience must be used within an ExperienceProvider");return e}export{c as useExperience,u as usePicked};
@@ -4,5 +4,5 @@ export interface GetFieldResponse {
4
4
  value: Store<FieldValue>;
5
5
  field: Store<Field | null>;
6
6
  }
7
- export declare function getField(id: string): GetFieldResponse;
7
+ export declare function getField(key: string): GetFieldResponse;
8
8
  //# sourceMappingURL=field.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"field.d.ts","sourceRoot":"","sources":["../../src/hooks/field.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AACvD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAGrC,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,CAAA;IACxB,KAAK,EAAE,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC,CAAA;CAC3B;AAED,wBAAgB,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,gBAAgB,CAQrD"}
1
+ {"version":3,"file":"field.d.ts","sourceRoot":"","sources":["../../src/hooks/field.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AACvD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAGrC,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,CAAA;IACxB,KAAK,EAAE,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC,CAAA;CAC3B;AAED,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,gBAAgB,CAQtD"}
@@ -1 +1 @@
1
- import{getPicked as s}from"./client.js";function r(e){const t=s(),n=t.fields.getById(e),o=t.responses.getByFieldId(e);return{field:n,value:o}}export{r as getField};
1
+ import{usePicked as o}from"./client.js";function r(e){const t=o(),s=t.fields.getByKey(e),n=t.responses.getByFieldKey(e);return{field:s,value:n}}export{r as getField};
@@ -1,5 +1,10 @@
1
- export { usePicked, useExperience, getPicked, getExperience } from './client';
1
+ /**
2
+ * @file Public re-exports for the hooks entry point.
3
+ */
4
+ export { usePicked, useExperience } from './client';
2
5
  export { useStep, useSetStepContext } from './step';
6
+ export type { StepContext } from './step';
3
7
  export { useSessionStorage, useLocalStorage } from './storage';
8
+ export type { UseStorageOptions } from './storage';
4
9
  export * from './field';
5
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAC7E,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAA;AACnD,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AAC9D,cAAc,SAAS,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACnD,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,QAAQ,CAAA;AACnD,YAAY,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAA;AACzC,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AAC9D,YAAY,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAA;AAClD,cAAc,SAAS,CAAA"}
@@ -1 +1 @@
1
- import{getExperience as o,getPicked as r,useExperience as p,usePicked as s}from"./client.js";import{useSetStepContext as i,useStep as u}from"./step.js";import{useLocalStorage as c,useSessionStorage as g}from"./storage.js";import{getField as m}from"./field.js";export{o as getExperience,m as getField,r as getPicked,p as useExperience,c as useLocalStorage,s as usePicked,g as useSessionStorage,i as useSetStepContext,u as useStep};
1
+ import{useExperience as t,usePicked as r}from"./client.js";import{useSetStepContext as p,useStep as u}from"./step.js";import{useLocalStorage as S,useSessionStorage as f}from"./storage.js";import{getField as m}from"./field.js";export{m as getField,t as useExperience,S as useLocalStorage,r as usePicked,f as useSessionStorage,p as useSetStepContext,u as useStep};
@@ -2,21 +2,36 @@ import { Field, Response } from '@picked/client';
2
2
  type FieldWithValue = Field & {
3
3
  value: Response | undefined;
4
4
  };
5
- type StepWithLabel = {
5
+ interface StepWithLabel {
6
6
  id: string;
7
7
  label: string;
8
- };
8
+ }
9
9
  export interface StepContext {
10
10
  step: StepWithLabel;
11
11
  fields: FieldWithValue[];
12
12
  isActiveStep?: boolean;
13
13
  }
14
14
  export declare const StepContextProvider: import('react').Context<StepContext | null>;
15
+ /**
16
+ * Returns the current step context, including step metadata and evaluated fields.
17
+ * Must be used within a component wrapped by `StepContextProvider`.
18
+ * @returns The step, its evaluated fields, and whether this is the active step.
19
+ * @example
20
+ * const { step, fields, isActiveStep } = useStep()
21
+ */
15
22
  export declare function useStep(): {
16
23
  step: StepWithLabel;
17
24
  fields: FieldWithValue[];
18
25
  isActiveStep: boolean;
19
26
  };
27
+ /**
28
+ * Creates and returns step context stores for the given step ID.
29
+ * Evaluates field conditions reactively whenever fields or responses change.
30
+ * @param stepId - The ID of the step to set context for.
31
+ * @returns The step metadata, evaluated fields, and active step indicator.
32
+ * @example
33
+ * const { step, fields, isActiveStep } = useSetStepContext('step-123')
34
+ */
20
35
  export declare function useSetStepContext(stepId: string): {
21
36
  step: StepWithLabel;
22
37
  fields: FieldWithValue[];
@@ -1 +1 @@
1
- {"version":3,"file":"step.d.ts","sourceRoot":"","sources":["../../src/hooks/step.ts"],"names":[],"mappings":"AAEA,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,aAAa,CAAA;IACnB,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB;AAED,eAAO,MAAM,mBAAmB,6CAA0C,CAAA;AAE1E,wBAAgB,OAAO;;;;EAWtB;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM;;;;EA+F/C"}
1
+ {"version":3,"file":"step.d.ts","sourceRoot":"","sources":["../../src/hooks/step.ts"],"names":[],"mappings":"AAKA,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,UAAU,aAAa;IACrB,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,MAAM,CAAA;CACd;AAOD,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,aAAa,CAAA;IACnB,MAAM,EAAE,cAAc,EAAE,CAAA;IACxB,YAAY,CAAC,EAAE,OAAO,CAAA;CACvB;AAED,eAAO,MAAM,mBAAmB,6CAA0C,CAAA;AAE1E;;;;;;GAMG;AACH,wBAAgB,OAAO;;;;EAWtB;AAeD;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM;;;;EA8G/C"}
@@ -1 +1 @@
1
- import{createContext as w,useMemo as a,useContext as b}from"react";import{attach as E,createEffect as F,combine as R,createStore as A,sample as P}from"effector";import{evaluateRuleLogic as g}from"@picked/client";import{useUnit as k}from"effector-react";import{useStepRouter as y}from"../router/context.js";import{useExperience as D,usePicked as L}from"./client.js";const M=w(null);function B(){const e=b(M);if(!e)throw new Error("useStep must be used within a StepContextProvider");return{step:e.step,fields:e.fields,isActiveStep:e.isActiveStep??!1}}function G(e){const l=D(),s=L(),{activeStep:p}=y(),m=a(()=>p?.id===e,[p?.id,e]),{stepContext:S}=a(()=>{const o=E({source:R({steps:l.treeStore.map(i=>i.steps),fields:s.fields.listStore,responses:s.responses.listStore}),effect:F(async({steps:i,fields:r,responses:x})=>{const n=i.find(t=>t.id===e);if(!n)throw new Error(`Step with id "${e}" not found in the experience tree.`);const v=r.filter(t=>n.fieldIds.includes(t.id)),c=[];for(const t of v)t.condition?await g(s,t.condition)&&c.push(t):c.push(t);const C=c.map(t=>{const u=x.find(h=>h.fieldId===t.id)?.value;return{...t,value:u}});return{step:{id:n.id,label:n.label},fields:C}})}),f=A({step:{id:e,label:""},fields:[]});return f.on(o.doneData,(i,r)=>r),P({clock:[s.fields.listStore,s.responses.listStore],target:o}),o(),{stepContextFx:o,stepContext:f}},[e,s,l]),d=k(S);return{step:d?.step,fields:d?.fields||[],isActiveStep:m}}export{M as StepContextProvider,G as useSetStepContext,B as useStep};
1
+ import{createContext as y,useMemo as m,useContext as E}from"react";import{combine as S,attach as F,createEffect as P,createStore as R,sample as k}from"effector";import{evaluateRuleLogic as A}from"@picked/client";import{useUnit as g}from"effector-react";import{useStepRouter as K}from"../router/context.js";import{useExperience as _,usePicked as B}from"./client.js";const D=y(null);function G(){const t=E(D);if(!t)throw new Error("useStep must be used within a StepContextProvider");return{step:t.step,fields:t.fields,isActiveStep:t.isActiveStep??!1}}function H(t){const l=_(),s=B(),{activeStep:f}=K(),x=m(()=>f?.id===t,[f?.id,t]),{stepContext:v}=m(()=>{const C=l.treeStore.map(o=>o.steps),h=S(C,s.steps.listStore,(o,i)=>i.filter(c=>o.includes(c.id))),r=F({source:S({steps:h,fields:s.fields.listStore,responses:s.responses.listStore}),mapParams:(o,i)=>i,effect:P(async({steps:o,fields:i,responses:c})=>{const n=o.find(e=>e.id===t);if(!n)throw new Error(`Step with id "${t}" not found in the experience tree.`);const w=i.filter(e=>(n.fieldIds??[]).includes(e.id)),p=[];for(const e of w)e.condition?await A(s,e.condition)&&p.push(e):p.push(e);const a={};for(const e of c)a[e.fieldKey]=e;const b=p.map(e=>({...e,value:a[e.key]?.value}));return{step:{id:n.id,label:n.name??n.label},fields:b}})}),u=R({step:{id:t,label:""},fields:[]});return u.on(r.doneData,(o,i)=>i),k({clock:[s.fields.listStore,s.responses.listStore],target:r}),r(),{stepContextFx:r,stepContext:u}},[t,s,l]),d=g(v);return{step:d.step,fields:d.fields,isActiveStep:x}}export{D as StepContextProvider,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.1-dev.1773729274420",
3
+ "version": "0.0.1-dev.1773804563218",
4
4
  "devDependencies": {
5
5
  "@picked/client": "workspace:*",
6
6
  "@repo/eslint-config": "workspace:*",
@@ -59,16 +59,33 @@
59
59
  "dist"
60
60
  ],
61
61
  "knip": {
62
+ "entry": [
63
+ "src/index.ts",
64
+ "src/server/index.ts",
65
+ "src/router/index.ts",
66
+ "src/form/index.ts",
67
+ "src/hooks/index.ts",
68
+ "src/plugins/framework/index.ts"
69
+ ],
70
+ "ignore": [
71
+ "eslint.config.js"
72
+ ],
62
73
  "ignoreBinaries": [
74
+ "attw",
63
75
  "knip",
64
76
  "jscpd",
65
77
  "eslint",
66
78
  "tsc"
79
+ ],
80
+ "ignoreDependencies": [
81
+ "@picked/client",
82
+ "@repo/eslint-config",
83
+ "@repo/typescript-config"
67
84
  ]
68
85
  },
69
86
  "module": "./dist/index.js",
70
87
  "peerDependencies": {
71
- "@picked/client": "0.0.1-dev.1773729274420",
88
+ "@picked/client": "0.0.1-dev.1773804563218",
72
89
  "effector": "^23.3.0",
73
90
  "effector-react": "^23.3.0",
74
91
  "react": "19.2.2",