@@ -2,14 +2,15 @@ import type { Input } from "@/lib/types/model/channel";
22import type { ContributionState } from "@/lib/types/state/contribution" ;
33import type { ComponentState } from "@/lib/types/state/component" ;
44import { isContainerState } from "@/lib/actions/helpers/isContainerState" ;
5- import { getValue , toObjPath } from ' @/lib/utils/objPath' ;
5+ import { formatObjPath , getValue , normalizeObjPath } from " @/lib/utils/objPath" ;
66import { isObject } from "@/lib/utils/isObject" ;
7+ import type { GetDerivedState } from "@/lib/types/state/store" ;
78
89export function getInputValues < S extends object = object > (
910 inputs : Input [ ] ,
1011 contributionState : ContributionState ,
1112 hostState ?: S | undefined ,
12- getDerivedHostState ?: ( hostState : object , property : string ) => unknown ,
13+ getDerivedHostState ?: GetDerivedState ,
1314) : unknown [ ] {
1415 return inputs . map ( ( input ) =>
1516 getInputValue ( input , contributionState , hostState , getDerivedHostState ) ,
@@ -22,7 +23,7 @@ export function getInputValue<S extends object = object>(
2223 input : Input ,
2324 contributionState : ContributionState ,
2425 hostState ?: S ,
25- getDerivedHostState ?: ( hostState : object , propertyName : string ) => unknown ,
26+ getDerivedHostState ?: GetDerivedState < S > ,
2627) : unknown {
2728 let inputValue : unknown = undefined ;
2829 const dataSource = input . link || "component" ;
@@ -31,7 +32,11 @@ export function getInputValue<S extends object = object>(
3132 } else if ( dataSource === "container" && contributionState . container ) {
3233 inputValue = getInputValueFromState ( input , contributionState . container ) ;
3334 } else if ( dataSource === "app" && hostState ) {
34- inputValue = getInputValueFromState ( input , hostState , getDerivedHostState ) ;
35+ inputValue = getInputValueFromState (
36+ input ,
37+ hostState ,
38+ getDerivedHostState as GetDerivedState ,
39+ ) ;
3540 } else {
3641 console . warn ( `input with unknown data source:` , input ) ;
3742 }
@@ -66,19 +71,18 @@ export function getInputValueFromComponent(
6671export function getInputValueFromState (
6772 input : Input ,
6873 state : object | undefined ,
69- getDerivedState ?: ( state : object , propertyName : string ) => unknown ,
74+ getDerivedState ?: GetDerivedState ,
7075) : unknown {
7176 let inputValue : unknown = state ;
7277 if ( input . id && isObject ( inputValue ) ) {
7378 inputValue = inputValue [ input . id ] ;
7479 }
7580 if ( isObject ( inputValue ) ) {
7681 const state = inputValue ;
77- const property = toObjPath ( input . property ) ;
82+ const property = normalizeObjPath ( input . property ) ;
7883 inputValue = getValue ( state , property ) ;
7984 if ( inputValue === undefined && getDerivedState !== undefined ) {
80- const propertyName = property . map ( v => typeof v === "number" ? v . toString ( ) : v ) . join ( "." ) ;
81- inputValue = getDerivedState ( state , propertyName ) ;
85+ inputValue = getDerivedState ( state , formatObjPath ( input . property ) ) ;
8286 }
8387 }
8488 return inputValue ;
0 commit comments