@@ -64,6 +64,7 @@ import CollectionRunnerModal from './modals/CollectionRunnerModal.vue'
6464import CollectionRunnerProgressModal from ' ./modals/CollectionRunnerProgressModal.vue'
6565import { mapState } from ' vuex'
6666import { flattenTree , exportRestfoxCollection , generateNewIdsForTree , deepClone } from ' @/helpers'
67+ import { resolveSidebarDropTarget } from ' @/utils/sidebar-drop'
6768import { generateCode } from ' @/utils/generate-code'
6869import AddGraphQLRequestModal from ' @/components/modals/AddGraphQLRequestModal.vue'
6970
@@ -470,29 +471,6 @@ export default {
470471 this .enableOptionsForEmptyContextMenu = true
471472 this .showContextMenu = true
472473 },
473- getDropTargetElementContainer (event ) {
474- let container
475- const sidebarItem = event .target .closest (' .sidebar-item' )
476- const sidebarListContainer = event .target .closest (' .sidebar-list-container' )
477- if (sidebarItem) {
478- container = {
479- type: ' sidebar-item' ,
480- element: sidebarItem
481- }
482- } else if (sidebarListContainer) {
483- const innerList = sidebarListContainer .querySelector (' .sidebar-list' )
484- if (! innerList) {
485- return
486- }
487- container = {
488- type: ' sidebar-list' ,
489- element: innerList
490- }
491- } else {
492- return null
493- }
494- return container
495- },
496474 dragStart (event ) {
497475 if (this .collectionFilter ) { // disable drag functionality if collection is being filtered
498476 return
@@ -517,12 +495,12 @@ export default {
517495 if (! this .draggedSidebarElement ) {
518496 return
519497 }
520- const container = this . getDropTargetElementContainer (event )
521- if (! container ) {
498+ const target = resolveSidebarDropTarget (event . target )
499+ if (! target ) {
522500 return
523501 }
524502
525- const elementToDropOn = container . element
503+ const { element : elementToDropOn } = target
526504 const rect = elementToDropOn .getBoundingClientRect ()
527505 const offset = rect .top + document .body .scrollTop
528506 const elementHeight = parseFloat (getComputedStyle (elementToDropOn, null ).height .replace (' px' , ' ' ))
@@ -535,7 +513,7 @@ export default {
535513 elementToDropOn .style .backgroundColor = ' '
536514 } else {
537515 this .sidebarItemCursorPosition = ' bottom'
538- if (elementToDropOn . dataset .type === ' request_group' ) {
516+ if (target .type === ' request_group' ) {
539517 elementToDropOn .style .borderTop = ' '
540518 elementToDropOn .style .borderBottom = ' '
541519 elementToDropOn .style .backgroundColor = ' var(--drop-target-background-color)'
@@ -547,54 +525,49 @@ export default {
547525 }
548526 event .preventDefault ()
549527 },
528+ clearDropTargetStyling (element ) {
529+ element .style .borderTop = ' '
530+ element .style .borderBottom = ' '
531+ element .style .backgroundColor = ' '
532+ },
550533 dragLeave (event ) {
551534 if (! this .draggedSidebarElement ) {
552535 return
553536 }
554- const container = this . getDropTargetElementContainer (event )
555- if (! container ) {
537+ const target = resolveSidebarDropTarget (event . target )
538+ if (! target ) {
556539 return
557540 }
558- const elementToDropOn = container .element
559- if (elementToDropOn) {
560- elementToDropOn .style .borderBottom = ' '
561- elementToDropOn .style .borderTop = ' '
562- elementToDropOn .style .backgroundColor = ' '
563- }
541+ this .clearDropTargetStyling (target .element )
564542 },
565543 drop (event ) {
566544 if (! this .draggedSidebarElement ) {
567545 return
568546 }
569547 event .preventDefault ()
570- const container = this . getDropTargetElementContainer (event )
571- if (! container ) {
548+ const target = resolveSidebarDropTarget (event . target )
549+ if (! target ) {
572550 return
573551 }
574552
575- const elementToDropOn = container .element
576- if (elementToDropOn) {
577- elementToDropOn .style .borderTop = ' '
578- elementToDropOn .style .borderBottom = ' '
579- elementToDropOn .style .backgroundColor = ' '
553+ this .clearDropTargetStyling (target .element )
580554
581- this .$store .dispatch (' reorderCollectionItem' , {
582- from: {
583- parentId: this .draggedSidebarElement .dataset .parentId ,
584- id: this .draggedSidebarElement .dataset .id
585- },
586- to: {
587- parentId: elementToDropOn . dataset .parentId ,
588- id: elementToDropOn . dataset .id ,
589- type: elementToDropOn . dataset . type ?? container .type ,
590- cursorPosition: this .sidebarItemCursorPosition
591- }
592- })
555+ this .$store .dispatch (' reorderCollectionItem' , {
556+ from: {
557+ parentId: this .draggedSidebarElement .dataset .parentId ,
558+ id: this .draggedSidebarElement .dataset .id
559+ },
560+ to: {
561+ parentId: target .parentId ,
562+ id: target .id ,
563+ type: target .type ,
564+ cursorPosition: this .sidebarItemCursorPosition
565+ }
566+ })
593567
594- this .draggedSidebarElement .style .backgroundColor = ' '
595- this .draggedSidebarElement .style .opacity = ' '
596- this .draggedSidebarElement = null
597- }
568+ this .draggedSidebarElement .style .backgroundColor = ' '
569+ this .draggedSidebarElement .style .opacity = ' '
570+ this .draggedSidebarElement = null
598571 },
599572 async updateCollectionItem (collectionItem ) {
600573 const result = await this .$store .dispatch (' updateCollectionItem' , {
0 commit comments