@picked/react 0.0.1-dev.1774244905386 → 0.0.1-dev.1774924249530
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/step.d.ts +36 -33
- package/dist/hooks/step.d.ts.map +1 -1
- package/dist/hooks/step.js +1 -1
- package/dist/router/Step.js +1 -1
- package/dist/router/StepRouter.js +1 -1
- package/dist/router/context.d.ts +1 -0
- package/dist/router/context.d.ts.map +1 -1
- package/package.json +8 -3
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'], 'onBeforeSubmit' | 'onSuccess' | 'onError'> & {
|
|
13
|
+
onBeforeSubmit: (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,CAAE,SAAQ,IAAI,CACpE,gBAAgB,CAAC,SAAS,CAAC,EAC3B,MAAM,CACP;IACC,IAAI,EAAE,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,EAAE,gBAAgB,GAAG,WAAW,GAAG,SAAS,CAAC,GAAG;QAC5F,cAAc,EAAE,CAAC,QAAQ,EAAE,cAAc,CAAC,SAAS,CAAC,KAAK,IAAI,CAAA;QAC7D,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,CAwCjF"}
|
package/dist/form/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useExperience as e,usePicked as t}from"../hooks/client.js";import"../hooks/index.js";
|
|
1
|
+
import{useExperience as e,usePicked as t}from"../hooks/client.js";import"../hooks/index.js";import{useEffect as n,useMemo as r,useRef as i}from"react";import{createStore as a}from"effector";import{createForm as o}from"@picked/client/form";function s({formId:s,title:c,fieldIds:l}){let u=t(),d=e(),f=r(()=>a(c),[c]),p=r(()=>a(l),[l]),m=r(()=>o({client:u,experienceInstance:d},s,f,p),[u,d,s,f,p]),h=i([]);return n(()=>()=>{h.current.forEach(e=>e()),h.current=[]},[]),{form:r(()=>({...m.form,onBeforeSubmit:e=>{h.current.push(m.form.onBeforeSubmit(e))},onSuccess:e=>{h.current.push(m.form.onSuccess(e))},onError:e=>{h.current.push(m.form.onError(e))}}),[m]),fields:m.fields}}export{s as useForm};
|
package/dist/hooks/step.d.ts
CHANGED
|
@@ -1,41 +1,44 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
interface StepWithLabel {
|
|
6
|
-
id: string;
|
|
7
|
-
label: string;
|
|
8
|
-
}
|
|
1
|
+
import { EventCallable, Store } from 'effector';
|
|
2
|
+
import { ExperienceStep, ValidationError } from '@picked/client';
|
|
3
|
+
import { FormField, ErrorCallback, SubmitCallback, SubmitEventWithCurrentTarget, SuccessCallback } from '@picked/client/form';
|
|
9
4
|
export interface StepContext {
|
|
10
|
-
step:
|
|
11
|
-
fields
|
|
12
|
-
|
|
5
|
+
step: Store<ExperienceStep>;
|
|
6
|
+
/** Reactive store of fields with current values, errors, touched state, and event handlers. */
|
|
7
|
+
fields: Store<FormField[]>;
|
|
8
|
+
isActive: boolean;
|
|
9
|
+
/** @deprecated Use `isActive` instead. */
|
|
10
|
+
isActiveStep: boolean;
|
|
11
|
+
form: {
|
|
12
|
+
/** HTML-safe attributes to spread onto a form element. */
|
|
13
|
+
props: {
|
|
14
|
+
onsubmit: EventCallable<SubmitEventWithCurrentTarget>;
|
|
15
|
+
};
|
|
16
|
+
/** Flat list of all current validation errors. */
|
|
17
|
+
errors: Store<ValidationError[]>;
|
|
18
|
+
/** Whether the form is currently submitting. */
|
|
19
|
+
submitting: Store<boolean>;
|
|
20
|
+
/** Register a callback to transform data before submission. Cleanup is automatic. */
|
|
21
|
+
onBeforeSubmit: (callback: SubmitCallback) => void;
|
|
22
|
+
/** Register a callback to run on successful submission. Cleanup is automatic. */
|
|
23
|
+
onSuccess: (callback: SuccessCallback) => void;
|
|
24
|
+
/** Register a callback to run on validation errors. Cleanup is automatic. */
|
|
25
|
+
onError: (callback: ErrorCallback) => void;
|
|
26
|
+
};
|
|
13
27
|
}
|
|
14
28
|
export declare const StepContextProvider: import('react').Context<StepContext | null>;
|
|
15
29
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* @returns The step
|
|
19
|
-
* @example
|
|
20
|
-
* const { step, fields, isActiveStep } = useStep()
|
|
30
|
+
* Retrieves the step context from the nearest provider.
|
|
31
|
+
*
|
|
32
|
+
* @returns {StepContext} The current step context.
|
|
33
|
+
* @example useStep()
|
|
21
34
|
*/
|
|
22
|
-
export declare function useStep():
|
|
23
|
-
step: StepWithLabel;
|
|
24
|
-
fields: FieldWithValue[];
|
|
25
|
-
isActiveStep: boolean;
|
|
26
|
-
};
|
|
35
|
+
export declare function useStep(): StepContext;
|
|
27
36
|
/**
|
|
28
|
-
* Creates and
|
|
29
|
-
*
|
|
30
|
-
* @param stepId - The
|
|
31
|
-
* @returns The step
|
|
32
|
-
* @example
|
|
33
|
-
* const { step, fields, isActiveStep } = useSetStepContext('step-123')
|
|
37
|
+
* Creates and provides step context for the given step ID.
|
|
38
|
+
*
|
|
39
|
+
* @param {string} stepId - The step identifier.
|
|
40
|
+
* @returns {StepContext} The step context with form, fields, and active state.
|
|
41
|
+
* @example useSetStepContext('step-1')
|
|
34
42
|
*/
|
|
35
|
-
export declare function useSetStepContext(stepId: string):
|
|
36
|
-
step: StepWithLabel;
|
|
37
|
-
fields: FieldWithValue[];
|
|
38
|
-
isActiveStep: boolean;
|
|
39
|
-
};
|
|
40
|
-
export {};
|
|
43
|
+
export declare function useSetStepContext(stepId: string): StepContext;
|
|
41
44
|
//# sourceMappingURL=step.d.ts.map
|
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,aAAa,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AACpD,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AACrE,OAAO,EAEL,KAAK,SAAS,EACd,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,KAAK,4BAA4B,EACjC,KAAK,eAAe,EACrB,MAAM,qBAAqB,CAAA;AAI5B,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,KAAK,CAAC,cAAc,CAAC,CAAA;IAC3B,+FAA+F;IAC/F,MAAM,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC,CAAA;IAC1B,QAAQ,EAAE,OAAO,CAAA;IACjB,0CAA0C;IAC1C,YAAY,EAAE,OAAO,CAAA;IACrB,IAAI,EAAE;QACJ,0DAA0D;QAC1D,KAAK,EAAE;YACL,QAAQ,EAAE,aAAa,CAAC,4BAA4B,CAAC,CAAA;SACtD,CAAA;QACD,kDAAkD;QAClD,MAAM,EAAE,KAAK,CAAC,eAAe,EAAE,CAAC,CAAA;QAChC,gDAAgD;QAChD,UAAU,EAAE,KAAK,CAAC,OAAO,CAAC,CAAA;QAC1B,qFAAqF;QACrF,cAAc,EAAE,CAAC,QAAQ,EAAE,cAAc,KAAK,IAAI,CAAA;QAClD,iFAAiF;QACjF,SAAS,EAAE,CAAC,QAAQ,EAAE,eAAe,KAAK,IAAI,CAAA;QAC9C,6EAA6E;QAC7E,OAAO,EAAE,CAAC,QAAQ,EAAE,aAAa,KAAK,IAAI,CAAA;KAC3C,CAAA;CACF;AAED,eAAO,MAAM,mBAAmB,6CAA0C,CAAA;AAE1E;;;;;GAKG;AACH,wBAAgB,OAAO,IAAI,WAAW,CAOrC;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,WAAW,CAkE7D"}
|
package/dist/hooks/step.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useExperience as e,usePicked as t}from"./client.js";import{useStepRouter as n}from"../router/context.js";import{createContext as r,useContext as i,
|
|
1
|
+
import{useExperience as e,usePicked as t}from"./client.js";import{useStepRouter as n}from"../router/context.js";import{createContext as r,useContext as i,useEffect as a,useMemo as o,useRef as s}from"react";import{createForm as c}from"@picked/client/form";var l=r(null);function u(){let e=i(l);if(!e)throw Error(`useStep must be used within a StepContextProvider`);return e}function d(r){let i=e(),l=t(),{activeStep:u}=n(),d=o(()=>u?.key===r,[u?.key,r]),f=o(()=>i.treeStore.map(e=>{let t=e.steps.find(e=>e.id===r);if(!t)throw Error(`Step with id "${r}" not found in the experience tree.`);return t}),[i,r]),p=o(()=>f.map(e=>e.name),[f]),m=o(()=>f.map(e=>e.fieldIds),[f]),h=o(()=>c({client:l,experienceInstance:i},r,p,m),[l,i,r,p,m]),g=s([]);a(()=>()=>{g.current.forEach(e=>e()),g.current=[]},[]);let _=o(()=>({...h.form,onBeforeSubmit:e=>{g.current.push(h.form.onBeforeSubmit(e))},onSuccess:e=>{g.current.push(h.form.onSuccess(e))},onError:e=>{g.current.push(h.form.onError(e))}}),[h]);return{step:f,fields:h.fields,isActive:d,isActiveStep:d,form:_}}export{l as StepContextProvider,d as useSetStepContext,u as useStep};
|
package/dist/router/Step.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useStepRouter as e}from"./context.js";import{StepContextProvider as t,useSetStepContext as n}from"../hooks/step.js";import{useEffect as r,useState as
|
|
1
|
+
import{useStepRouter as e}from"./context.js";import{StepContextProvider as t,useSetStepContext as n}from"../hooks/step.js";import{useEffect as r,useMemo as i,useState as a}from"react";import{jsx as o}from"react/jsx-runtime";function s({stepKey:s,id:c,component:l,children:u}){let d=s??c??``,f=i(()=>({id:d,key:d}),[d]),{registerStep:p,unregisterStep:m}=e(),h=i(()=>typeof l==`function`?l:null,[l]),[g,_]=a(null),v=n(d);r(()=>(p(f),()=>m(f)),[p,m,f]),r(()=>{l&&typeof l!=`function`&&Promise.resolve(l).then(e=>{typeof e==`object`&&`default`in e?_(()=>e.default):typeof e==`function`&&_(()=>e)})},[l]);let y=h??g;return l?y?o(t.Provider,{value:v,children:o(y,{})}):null:o(t.Provider,{value:v,children:u})}export{s as default};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useExperience as e}from"../hooks/client.js";import{StepRouterProvider as t}from"./context.js";import"../hooks/index.js";import{useCallback as n,
|
|
1
|
+
import{useExperience as e}from"../hooks/client.js";import{StepRouterProvider as t}from"./context.js";import"../hooks/index.js";import{useCallback as n,useMemo as r,useRef as i,useState as a}from"react";import{supportsWindow as o}from"@picked/client";import{useUnit as s}from"effector-react";import{jsx as c}from"react/jsx-runtime";function l({children:l}){let{currentStepStore:u}=e(),d=s(u),f=i(!1),[p,m]=a([]),[h,g]=a(null),_=n(e=>{if(o())m(t=>[...t,e]);else{if(f.current)return;e.key===d?.key&&(g(e),f.current=!0)}},[d?.key]),v=n(e=>{m(t=>t.filter(t=>t!==e))},[]),y=r(()=>h??p.find(e=>e.key===d?.key)??null,[h,p,d?.key]),b=r(()=>({activeStep:y,registerStep:_,unregisterStep:v}),[y,_,v]);return d?.key?c(t,{value:b,children:l}):null}export{l as default};
|
package/dist/router/context.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/router/context.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/router/context.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,IAAI;IACnB,EAAE,EAAE,MAAM,CAAA;IACV,GAAG,EAAE,MAAM,CAAA;CACZ;AAED,UAAU,cAAc;IACtB,UAAU,CAAC,EAAE,IAAI,GAAG,IAAI,CAAA;IACxB,cAAc,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAA;IACpC,YAAY,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,IAAI,CAAA;CACnC;AAID,eAAO,MAAM,kBAAkB,iDAA6B,CAAA;AAE5D,eAAO,MAAM,aAAa,sBAOzB,CAAA"}
|
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.1774924249530",
|
|
4
4
|
"devDependencies": {
|
|
5
5
|
"@picked/client": "workspace:*",
|
|
6
6
|
"@repo/eslint-config": "workspace:*",
|
|
@@ -76,11 +76,16 @@
|
|
|
76
76
|
"jscpd",
|
|
77
77
|
"eslint",
|
|
78
78
|
"tsgo"
|
|
79
|
+
],
|
|
80
|
+
"ignoreDependencies": [
|
|
81
|
+
"@picked/client",
|
|
82
|
+
"@repo/eslint-config",
|
|
83
|
+
"@repo/typescript-config"
|
|
79
84
|
]
|
|
80
85
|
},
|
|
81
86
|
"module": "./dist/index.js",
|
|
82
87
|
"peerDependencies": {
|
|
83
|
-
"@picked/client": "0.0.1-dev.
|
|
88
|
+
"@picked/client": "0.0.1-dev.1774924249530",
|
|
84
89
|
"effector": "^23.3.0",
|
|
85
90
|
"effector-react": "^23.3.0",
|
|
86
91
|
"react": "19.2.2",
|
|
@@ -100,7 +105,7 @@
|
|
|
100
105
|
"lint:report": "eslint . -o './.reports/eslint.json' -f json || [ -f './.reports/eslint.json' ]",
|
|
101
106
|
"size": "size-limit",
|
|
102
107
|
"test": "vitest run",
|
|
103
|
-
"test:coverage": "vitest
|
|
108
|
+
"test:coverage": "../../scripts/vitest-coverage.sh",
|
|
104
109
|
"test:packaged-types": "attw --pack",
|
|
105
110
|
"test:watch": "vitest",
|
|
106
111
|
"type-check": "tsgo -p . --noEmit"
|