@picked/react 0.0.1-dev.1773807602703 → 0.0.1-dev.1773878362211
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 +23 -11
- package/dist/form/index.d.ts.map +1 -1
- package/dist/form/index.js +1 -1
- package/dist/hooks/client.d.ts +8 -8
- package/dist/hooks/client.d.ts.map +1 -1
- package/dist/hooks/client.js +1 -1
- package/dist/hooks/field.d.ts +1 -1
- package/dist/hooks/field.d.ts.map +1 -1
- package/dist/hooks/field.js +1 -1
- package/dist/hooks/index.d.ts +1 -6
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +1 -1
- package/dist/hooks/step.d.ts +2 -17
- package/dist/hooks/step.d.ts.map +1 -1
- package/dist/hooks/step.js +1 -1
- package/package.json +2 -19
package/dist/form/index.d.ts
CHANGED
|
@@ -1,16 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
interface
|
|
3
|
-
|
|
1
|
+
import { FormInstance as CoreFormInstance, ErrorCallback, SubmitCallback, SuccessCallback } from '@picked/client/form';
|
|
2
|
+
interface UseFormOptions {
|
|
3
|
+
formId: string;
|
|
4
4
|
title: string;
|
|
5
|
-
|
|
6
|
-
onError?: (errors: ValidationError[]) => void | Promise<void>;
|
|
5
|
+
fieldIds: string[];
|
|
7
6
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
/**
|
|
8
|
+
* React FormInstance — identical to core but callback registration returns void
|
|
9
|
+
* (cleanup is handled automatically via useEffect, not by the consumer).
|
|
10
|
+
*/
|
|
11
|
+
interface FormInstance<TFieldIds extends string = string> extends Omit<CoreFormInstance<TFieldIds>, 'form'> {
|
|
12
|
+
form: Omit<CoreFormInstance<TFieldIds>['form'], 'onSubmit' | 'onSuccess' | 'onError'> & {
|
|
13
|
+
onSubmit: (callback: SubmitCallback<TFieldIds>) => void;
|
|
14
|
+
onSuccess: (callback: SuccessCallback<TFieldIds>) => void;
|
|
15
|
+
onError: (callback: ErrorCallback) => void;
|
|
13
16
|
};
|
|
14
|
-
}
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* React hook wrapping the framework-agnostic createForm from @picked/client/form.
|
|
20
|
+
*
|
|
21
|
+
* - Injects client and experienceInstance from React context
|
|
22
|
+
* - Collects unsubscribe functions from callback registration and cleans them
|
|
23
|
+
* up on unmount via a single useEffect
|
|
24
|
+
* - Consumer DX: `form.onSuccess(cb)` — no hooks or lifecycle awareness needed
|
|
25
|
+
*/
|
|
26
|
+
export declare function useForm({ formId, title, fieldIds }: UseFormOptions): FormInstance;
|
|
15
27
|
export {};
|
|
16
28
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/form/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/form/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/form/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,YAAY,IAAI,gBAAgB,EACrC,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,eAAe,EACrB,MAAM,qBAAqB,CAAA;AAG5B,UAAU,cAAc;IACtB,MAAM,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,EAAE,CAAA;CACnB;AAED;;;GAGG;AACH,UAAU,YAAY,CAAC,SAAS,SAAS,MAAM,GAAG,MAAM,CACtD,SAAQ,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IACjD,IAAI,EAAE,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,EAAE,UAAU,GAAG,WAAW,GAAG,SAAS,CAAC,GAAG;QACtF,QAAQ,EAAE,CAAC,QAAQ,EAAE,cAAc,CAAC,SAAS,CAAC,KAAK,IAAI,CAAA;QACvD,SAAS,EAAE,CAAC,QAAQ,EAAE,eAAe,CAAC,SAAS,CAAC,KAAK,IAAI,CAAA;QACzD,OAAO,EAAE,CAAC,QAAQ,EAAE,aAAa,KAAK,IAAI,CAAA;KAC3C,CAAA;CACF;AAED;;;;;;;GAOG;AACH,wBAAgB,OAAO,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,cAAc,GAAG,YAAY,CAyCjF"}
|
package/dist/form/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{usePicked as
|
|
1
|
+
import{useMemo as t,useRef as S,useEffect as a}from"react";import{createStore as p}from"effector";import{createForm as E}from"@picked/client/form";import{usePicked as h,useExperience as l}from"../hooks/client.js";import"../hooks/step.js";import"@picked/client";function P({formId:c,title:n,fieldIds:s}){const u=h(),m=l(),f=t(()=>p(n),[n]),i=t(()=>p(s),[s]),e=t(()=>E({client:u,experienceInstance:m},c,f,i),[u,m,c,f,i]),o=S([]);return a(()=>()=>{o.current.forEach(r=>r()),o.current=[]},[]),{form:t(()=>({...e.form,onSubmit:r=>{o.current.push(e.form.onSubmit(r))},onSuccess:r=>{o.current.push(e.form.onSuccess(r))},onError:r=>{o.current.push(e.form.onError(r))}}),[e]),fields:e.fields}}export{P as useForm};
|
package/dist/hooks/client.d.ts
CHANGED
|
@@ -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
|
-
* @
|
|
6
|
-
* const client = usePicked()
|
|
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
|
|
7
6
|
*/
|
|
8
7
|
export declare function usePicked(): Picked;
|
|
9
8
|
/**
|
|
10
|
-
* Retrieves the Experience Store for the current Experience Instance
|
|
11
|
-
*
|
|
12
|
-
* @
|
|
13
|
-
* const experience = useExperience()
|
|
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
|
|
14
12
|
*/
|
|
15
13
|
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":"
|
|
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"}
|
package/dist/hooks/client.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useContext as t}from"react";import{ExperienceContext as
|
|
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};
|
package/dist/hooks/field.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field.d.ts","sourceRoot":"","sources":["../../src/hooks/field.ts"],"names":[],"mappings":"AAAA
|
|
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"}
|
package/dist/hooks/field.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
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};
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
* @file Public re-exports for the hooks entry point.
|
|
3
|
-
*/
|
|
4
|
-
export { usePicked, useExperience } from './client';
|
|
1
|
+
export { usePicked, useExperience, getPicked, getExperience } from './client';
|
|
5
2
|
export { useStep, useSetStepContext } from './step';
|
|
6
|
-
export type { StepContext } from './step';
|
|
7
3
|
export { useSessionStorage, useLocalStorage } from './storage';
|
|
8
|
-
export type { UseStorageOptions } from './storage';
|
|
9
4
|
export * from './field';
|
|
10
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA
|
|
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"}
|
package/dist/hooks/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useExperience as
|
|
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};
|
package/dist/hooks/step.d.ts
CHANGED
|
@@ -2,36 +2,21 @@ import { Field, Response } from '@picked/client';
|
|
|
2
2
|
type FieldWithValue = Field & {
|
|
3
3
|
value: Response | undefined;
|
|
4
4
|
};
|
|
5
|
-
|
|
5
|
+
type 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
|
-
*/
|
|
22
15
|
export declare function useStep(): {
|
|
23
16
|
step: StepWithLabel;
|
|
24
17
|
fields: FieldWithValue[];
|
|
25
18
|
isActiveStep: boolean;
|
|
26
19
|
};
|
|
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
|
-
*/
|
|
35
20
|
export declare function useSetStepContext(stepId: string): {
|
|
36
21
|
step: StepWithLabel;
|
|
37
22
|
fields: FieldWithValue[];
|
package/dist/hooks/step.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"step.d.ts","sourceRoot":"","sources":["../../src/hooks/step.ts"],"names":[],"mappings":"
|
|
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"}
|
package/dist/hooks/step.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createContext as
|
|
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};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@picked/react",
|
|
3
|
-
"version": "0.0.1-dev.
|
|
3
|
+
"version": "0.0.1-dev.1773878362211",
|
|
4
4
|
"devDependencies": {
|
|
5
5
|
"@picked/client": "workspace:*",
|
|
6
6
|
"@repo/eslint-config": "workspace:*",
|
|
@@ -59,33 +59,16 @@
|
|
|
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
|
-
],
|
|
73
62
|
"ignoreBinaries": [
|
|
74
|
-
"attw",
|
|
75
63
|
"knip",
|
|
76
64
|
"jscpd",
|
|
77
65
|
"eslint",
|
|
78
66
|
"tsc"
|
|
79
|
-
],
|
|
80
|
-
"ignoreDependencies": [
|
|
81
|
-
"@picked/client",
|
|
82
|
-
"@repo/eslint-config",
|
|
83
|
-
"@repo/typescript-config"
|
|
84
67
|
]
|
|
85
68
|
},
|
|
86
69
|
"module": "./dist/index.js",
|
|
87
70
|
"peerDependencies": {
|
|
88
|
-
"@picked/client": "0.0.1-dev.
|
|
71
|
+
"@picked/client": "0.0.1-dev.1773878362211",
|
|
89
72
|
"effector": "^23.3.0",
|
|
90
73
|
"effector-react": "^23.3.0",
|
|
91
74
|
"react": "19.2.2",
|