@@ -31,10 +31,14 @@ export const getCSSCustomPropsForElement = (el, pfx = "") => {
3131 . filter ( ( pv ) => pv [ 1 ] !== "" ) ;
3232} ;
3333
34- export const propSet = ( obj , path , value ) => {
34+ export const propSet = ( obj , path , value , overwrite ) => {
3535 path . reduce ( ( acc , part , idx ) => {
36- if ( ! acc ?. [ part ] ) {
37- acc [ part ] = idx === path . length - 1 ? value : { } ;
36+ if ( idx === path . length - 1 ) {
37+ if ( overwrite || ! acc [ part ] ) {
38+ acc [ part ] = value ;
39+ }
40+ } else if ( ! acc [ part ] ) {
41+ acc [ part ] = { } ;
3842 }
3943
4044 return acc [ part ] ;
@@ -46,13 +50,13 @@ export const propGet = (obj, path) => {
4650 return path . reduce ( ( acc , part ) => acc ?. [ part ] , obj ) ;
4751} ;
4852
49- export const propsToObject = ( props , propObj , pfx = "" ) => {
53+ export const propsToObject = ( props , propObj , pfx = "" , overwrite = false ) => {
5054 propObj = propObj || { } ;
5155 propObj = props . reduce ( ( obj , [ prop , val ] ) => {
5256 const propname = prop . replace ( "--" + ( pfx ? pfx + "-" : "" ) , "" ) ;
5357 const proppath = propname . split ( "-" ) ;
5458
55- propSet ( obj , proppath , val ) ;
59+ propSet ( obj , proppath , val , overwrite ) ;
5660
5761 return obj ;
5862 } , propObj ) ;
0 commit comments