@@ -12,6 +12,7 @@ import {
1212 breadthFirstSearch ,
1313 breadthFirstSearchParent
1414} from '../utils/search.util'
15+ import _ from 'lodash'
1516
1617const cloneDeep = require ( 'lodash.clonedeep' )
1718
@@ -220,17 +221,70 @@ const mutations = {
220221 } ,
221222
222223 [ types . DELETE_USER_STATE ] : ( state , payload ) => {
223- // delete state.userState[payload];
224- // console.log('userState: ', state.userState);
224+ // need to loop through components and take out matching state
225+ for ( const component in state . componentMap ) {
226+ // first don't go through if component is App or Homeview
227+ if ( component === 'App' || component === 'HomeView' ) continue ;
228+ // splice out if there is a match
229+ const newState = state . componentMap [ component ] . state ;
230+ const index = newState . indexOf ( payload ) ;
231+ if ( index > - 1 ) {
232+ newState . splice ( index , 1 ) ;
233+ state . componentMap [ component ] . state = newState ;
234+ } else {
235+ continue ;
236+ }
237+ }
238+ // remove from userState
225239 let index = state . userState . indexOf ( payload ) ;
226240 state . userState . splice ( index , 1 ) ;
227241 } ,
228242
229243 [ types . DELETE_USER_ACTIONS ] : ( state , payload ) => {
230- // payload should be a string of the name of the action to remove
244+ for ( const component in state . componentMap ) {
245+ // first don't go through if component is App or Homeview
246+ if ( component === 'App' || component === 'HomeView' ) continue ;
247+ // splice out if there is a match
248+ const newActions = state . componentMap [ component ] . actions ;
249+ const index = newActions . indexOf ( payload ) ;
250+ if ( index > - 1 ) {
251+ newActions . splice ( index , 1 ) ;
252+ state . componentMap [ component ] . actions = newActions ;
253+ } else {
254+ continue ;
255+ }
256+ }
231257 let index = state . userActions . indexOf ( payload ) ;
232258 state . userActions . splice ( index , 1 ) ;
233259 } ,
260+ // copy and paste functionality
261+ [ types . COPY_ACTIVE_COMPONENT ] : ( state , payload ) => {
262+ // copy activeComponentObj and place in the state but without children
263+ const copy = { ...state . activeComponentObj } ;
264+ copy . componentName ;
265+ copy . children = [ ] ;
266+ copy . isActive = false ;
267+ state . copiedComponent = copy ;
268+ // reset the number of copies created
269+ state . copyNumber = 0 ;
270+ } ,
271+
272+ [ types . PASTE_ACTIVE_COMPONENT ] : ( state ) => {
273+ // check if copied exists
274+ if ( state . copiedComponent ) {
275+ const { copiedComponent } = state ;
276+ // offset duplicate's coordinates
277+ copiedComponent . x += 20 ;
278+ copiedComponent . y += 20 ;
279+ const pastedComponent = { ...copiedComponent }
280+ state . componentMap [ pastedComponent . componentName += ` (${ state . copyNumber } )` ] = pastedComponent ;
281+
282+ // increment copyNumber
283+ state . copyNumber += 1 ;
284+ // track for pastedComponent
285+ state . pastedComponent = pastedComponent ;
286+ }
287+ } ,
234288
235289 // *** EDIT FUNCTIONALITY *** //////////////////////////////////////////////
236290
@@ -447,7 +501,7 @@ const mutations = {
447501 } ,
448502
449503 [ types . ADD_PARENT ] : ( state , payload ) => {
450- state . componentMap [ payload . componentName ] . parent [ state . parentSelected ] = state . componentMap [ state . parentSelected ]
504+ state . componentMap [ payload . componentName ] . parent [ state . parentSelected ] = state . componentMap [ state . parentSelected ] ;
451505 state . componentMap [ state . parentSelected ] . children . push (
452506 payload . componentName
453507 )
@@ -456,6 +510,14 @@ const mutations = {
456510 )
457511 } ,
458512
513+ [ types . ADD_COPIED_PARENT ] : ( state , payload ) => {
514+ const parentSelected = Object . values ( payload . parent ) [ 0 ] . componentName ;
515+ // push into parent's children array
516+ state . componentMap [ parentSelected ] . children . push ( payload . componentName )
517+ // push into parent's htmlList array
518+ state . componentMap [ parentSelected ] . htmlList . push ( payload . componentName )
519+ } ,
520+
459521 [ types . DELETE_ACTIVE_COMPONENT ] : state => {
460522 const { componentMap, activeComponent, activeRoute } = state
461523
0 commit comments