@@ -1047,26 +1047,59 @@ const mutations = {
10471047 [ payload . route ] : payload . img . replace ( / \\ / g, "/" ) ,
10481048 } ;
10491049 } ,
1050+
10501051 [ types . CLEAR_IMAGE ] : ( state , payload ) => {
10511052 if ( state . imagePath [ payload . route ] ) state . imagePath [ payload . route ] = "" ;
10521053 } ,
1054+
10531055 [ types . SET_IMAGE_PATH ] : ( state , payload ) => {
10541056 state . imagePath = { ...state . imagePath , ...payload } ;
10551057 } ,
1058+
10561059 //change library array
10571060 [ types . CHANGE_LIB ] : ( state , payload ) => {
10581061 state . importLibraries . push ( payload . libName ) ;
10591062
10601063 } ,
1064+
10611065 [ types . CHANGE_LIB_COMPONENT_DISPLAY ] : ( state , payload ) => {
10621066 state . displaylibComponent = payload . displaylibComponent ;
1063- } ,
1067+ } ,
10641068
1065- [ types . ADD_LIB_COMPONENTS ] : ( state , payload ) => {
1069+ [ types . ADD_LIB_COMPONENTS ] : ( state , payload ) => {
10661070 for ( let key in payload ) {
10671071 state . icons [ key ] = payload [ key ] ;
10681072 }
1069- } ,
1073+ } ,
1074+
1075+ // change grid density
1076+ [ types . CHANGE_GRID_DENSITY ] : ( state , payload ) => {
1077+ // state.gridLayout = payload.direction === 'height' ? [state.gridLayout[0], payload.densityNum]:[payload.densityNum, state.gridLayout[1]];
1078+ console . log ( payload ) ;
1079+ if ( payload . direction === 'height' ) {
1080+ state . gridLayout [ 1 ] = payload . densityNum ;
1081+
1082+ }
1083+ else {
1084+ state . gridLayout [ 0 ] = payload . densityNum ;
1085+ }
1086+ state . routes [ state . activeRoute ] . forEach ( ( updatedComponent ) => {
1087+ if ( updatedComponent . w === undefined ) { updatedComponent . w = ( 2 * state . containerW / state . gridLayout [ 0 ] ) ; }
1088+ if ( updatedComponent . h === undefined ) { updatedComponent . h = ( 2 * state . containerH / state . gridLayout [ 1 ] ) ; }
1089+ // add one - CSS grid-area is one-indexed
1090+ const rowStart = 1 + Math . round ( state . gridLayout [ 0 ] * updatedComponent . x / state . containerW ) ;
1091+ const colStart = 1 + Math . round ( state . gridLayout [ 1 ] * updatedComponent . y / state . containerH ) ;
1092+ const rowEnd = 1 + Math . round ( state . gridLayout [ 0 ] * ( updatedComponent . x + updatedComponent . w ) / state . containerW ) ;
1093+ const colEnd = 1 + Math . round ( state . gridLayout [ 1 ] * ( updatedComponent . y + updatedComponent . h ) / state . containerH ) ;
1094+ updatedComponent . htmlAttributes . gridArea = [ rowStart , colStart , rowEnd , colEnd ] ;
1095+ updatedComponent . x = ( rowStart - 1 ) * state . containerW / state . gridLayout [ 0 ] ;
1096+ updatedComponent . y = ( colStart - 1 ) * state . containerH / state . gridLayout [ 1 ] ;
1097+ updatedComponent . w = ( rowEnd - 1 ) * state . containerW / state . gridLayout [ 0 ] - updatedComponent . x ;
1098+ updatedComponent . h = ( colEnd - 1 ) * state . containerH / state . gridLayout [ 1 ] - updatedComponent . y ;
1099+ // Math.round((rowEnd - 1) * state.containerW / state.gridLayout[0]) - updatedComponent.x
1100+ }
1101+ ) ;
1102+ } ,
10701103 // *** INACTIVE MUTATIONS - kept for reference *** //////////////////////////////////////////////
10711104
10721105 // [types.SET_STATE]: (state, payload) => {
0 commit comments