MCPcopy
hub / github.com/electerm/electerm / onDrop

Function onDrop

src/client/components/sidebar/transport-ui.jsx:104–140  ·  view source on GitHub ↗
(e)

Source from the content-addressed store, hash-verified

102 }
103
104 function onDrop (e) {
105 e.preventDefault()
106 const { target } = e
107 if (!target) {
108 return
109 }
110 let onDropTab = target
111 while (onDropTab) {
112 if (onDropTab.classList && onDropTab.classList.contains('sftp-transport')) {
113 break
114 }
115 onDropTab = onDropTab.parentElement
116 }
117 const fromId = JSON.parse(e.dataTransfer.getData('id'))
118 if (!onDropTab || !fromId) {
119 return
120 }
121
122 const dropId = onDropTab.getAttribute('data-id')
123 if (!dropId || dropId === fromId) {
124 return
125 }
126
127 const arr = window.store.fileTransfers
128 const indexFrom = arr.findIndex(t => t.id === fromId)
129 let indexDrop = arr.findIndex(t => t.id === dropId)
130 if (indexFrom >= 0 && indexDrop >= 0) {
131 // Reorder tabs and update batch
132 action(function () {
133 const [tr] = arr.splice(indexFrom, 1)
134 if (indexFrom < indexDrop) {
135 indexDrop = indexDrop - 1
136 }
137 arr.splice(indexDrop, 0, tr)
138 })()
139 }
140 }
141
142 function onDragEnd (e) {
143 removeClass(dom.current, onDragCls)

Callers

nothing calls this directly

Calls 3

actionFunction · 0.85
parseMethod · 0.80
getDataMethod · 0.80

Tested by

no test coverage detected