| 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) |