Skip to content

Commit 71e28d0

Browse files
author
hackape
committed
Accept Merge Request #12 修复文件拖动上传:(yangzhen/filetree -> ot)
Merge Request: 修复文件拖动上传 Created By: @杨臻
2 parents e918d32 + a1ec931 commit 71e28d0

File tree

8 files changed

+73
-20
lines changed

8 files changed

+73
-20
lines changed

app/components/Collaboration/index.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ class Collaboration extends Component {
7070
icon='fa fa-users'
7171
size='40'
7272
id='d1'
73+
key='d1'
7374
actions={action}
7475
>
7576
<Collaborators />
@@ -79,6 +80,7 @@ class Collaboration extends Component {
7980
icon='fa fa-comments'
8081
size='40'
8182
id='d2'
83+
key='d2'
8284
actions={chatSetting}
8385
>
8486
<Chat />

app/components/DragAndDrop.jsx

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { Component } from 'react'
2+
import debounce from 'lodash/debounce'
23
import { dispatch } from '../store'
34
import mobxStore from '../mobxStore'
45
import { observer } from 'mobx-react'
@@ -8,6 +9,7 @@ import * as PaneActions from './Pane/actions'
89
import PaneState from './Pane/state'
910
import * as TabActions from 'components/Tab/actions'
1011
import * as FileTreeActions from './FileTree/actions'
12+
import FileTreeState from './FileTree/state'
1113

1214
// Corner case: file dragging doesn't trigger 'dragend' natively
1315
// so need to patch for this behavior
@@ -20,6 +22,12 @@ class DragAndDrop extends Component {
2022

2123
constructor (props) {
2224
super(props)
25+
this.state = {
26+
dragPos: {
27+
x: 0,
28+
y: 0,
29+
}
30+
}
2331
}
2432

2533
render () {
@@ -51,19 +59,41 @@ class DragAndDrop extends Component {
5159
}
5260

5361
onDragLeave = (e) => {
62+
this.resetDragPos()
5463
e.preventDefault()
5564
if (isFileDragEnd(e)) dnd.dragEnd()
5665
}
5766

5867
onDragOver = (e) => {
5968
e.preventDefault()
60-
const { source, droppables = [], meta } = dnd
61-
if (!source) {
62-
dnd.dragStart({
63-
type: 'EXTERNAL_FILE',
64-
id: Date.now(),
65-
})
69+
const dx = this.state.dragPos.x - e.x
70+
const dy = this.state.dragPos.y - e.y
71+
if ((dx < -5 || dx > 5) || (dy < -5 || dy > 5)) {
72+
const { source } = dnd
73+
this.state.dragPos = {
74+
x: e.x,
75+
y: e.y,
76+
}
77+
if (!source || !source.id) {
78+
dnd.dragStart({
79+
type: 'EXTERNAL_FILE',
80+
id: Date.now(),
81+
})
82+
}
83+
this.handleDropOver(e)
6684
}
85+
}
86+
87+
resetDragPos = () => {
88+
this.state.dragPos = {
89+
x: 0,
90+
y: 0,
91+
}
92+
}
93+
94+
handleDropOver = debounce((e) => {
95+
dnd.updateDroppables()
96+
const { source, droppables = [], meta } = dnd
6797
const [oX, oY] = [e.pageX, e.pageY]
6898
const target = droppables.reduce((result, droppable) => {
6999
const {top, left, right, bottom} = droppable.rect
@@ -89,9 +119,10 @@ class DragAndDrop extends Component {
89119

90120
default:
91121
}
92-
}
122+
}, 1000)
93123

94124
onDrop = (e) => {
125+
this.resetDragPos()
95126
e.preventDefault()
96127
const { source, target, meta } = dnd
97128
if (!source || !target) return
@@ -121,6 +152,7 @@ class DragAndDrop extends Component {
121152
}
122153

123154
onDragEnd = (e) => {
155+
this.resetDragPos()
124156
e.preventDefault()
125157
dnd.dragEnd()
126158
}
@@ -135,12 +167,13 @@ class DragAndDrop extends Component {
135167
}
136168

137169
dragTabOverFileTree (e, target) {
138-
const id = target.id
139-
if (id.split('_')[0] === 'folder') {
140-
const DOMNode = document.getElementById(target.id)
141-
DOMNode.firstChild.click()
170+
const { id, DOMNode } = target
171+
const node = FileTreeState.entities.get(id)
172+
if (node.isDir && node.isFolded) {
173+
FileTreeActions.openNode(node)
142174
}
143175
}
176+
144177
dragTabOverPane (e, target) {
145178
if (target.type !== 'PANE') return
146179
const { source, meta } = dnd

app/components/FileTree/contextMenuItems.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,28 @@ const items = [
55
{
66
name: i18n`fileTree.contextMenu.newFile`,
77
icon: '',
8-
command: 'file:new_file'
8+
command: 'file:new_file',
9+
id: 'filetree_menu_new_file',
910
}, {
1011
name: i18n`fileTree.contextMenu.newFolder`,
1112
icon: '',
12-
command: 'file:new_folder'
13+
command: 'file:new_folder',
14+
id: 'filetree_menu_new_folder',
1315
}, {
1416
name: i18n`fileTree.contextMenu.delete`,
1517
icon: '',
16-
command: 'file:delete'
18+
command: 'file:delete',
19+
id: 'filetree_menu_delete',
1720
}, {
1821
name: i18n`fileTree.contextMenu.rename`,
1922
icon: '',
20-
command: 'file:rename'
23+
command: 'file:rename',
24+
id: 'filetree_menu_rename',
2125
}, {
2226
name: i18n`fileTree.contextMenu.delete`,
2327
icon: '',
24-
command: 'file:download'
28+
command: 'file:download',
29+
id: 'filetree_menu_download',
2530
}, {
2631
name: i18n`fileTree.contextMenu.upload`,
2732
icon: '',
@@ -31,13 +36,15 @@ const items = [
3136
const input = document.getElementById('filetree-hidden-input')
3237
input.dispatchEvent(new MouseEvent('click'))
3338
},
34-
getIsHidden: ctx => !ctx.isDir
39+
getIsHidden: ctx => !ctx.isDir,
40+
id: 'filetree_menu_upload',
3541
}, {
3642
name: i18n`fileTree.contextMenu.gitBlame`,
3743
icon: '',
3844
command: (c) => {
3945
gitBlameNode(c)
4046
},
47+
id: 'filetree_menu_gitBlame',
4148
}
4249
]
4350

app/components/Menu/MenuItem.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ class MenuItem extends Component {
9898
})}
9999
onMouseEnter={this.onMouseEnter}
100100
onClick={this.execCommand}
101+
id={item.id}
101102
>
102103
{(item.icon || item.iconElement) && (
103104
<div className={cx('menu-item-icon', item.icon)}>

app/components/ResizeBar2.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ const ResizeBar = ({ parentFlexDirection, confirmResize }) => {
8888

8989
ResizeBar.propTypes = {
9090
parentFlexDirection: PropTypes.string.isRequired,
91-
confirmResize: PropTypes.func.isRequired,
91+
confirmResize: PropTypes.func,
9292
}
9393

9494
export default ResizeBar

app/styles/core-ui/Bar.styl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ $bar-size= 25px
1313
text-align right;
1414
}
1515
}
16+
&.right {
17+
.side-bar-label {
18+
padding: 5px 1px;
19+
}
20+
}
1621
&.top, &.bottom {
1722
height: $bar-size;
1823
flex-direction: row;

app/styles/core-ui/FileTree.styl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ $filetree-indent = 1em;
1111
.filetree-node-container {
1212
float: left; // <- ✝
1313
min-width: 100%; // <- ✝
14-
14+
min-height: 100%;
1515
> .filetree-node {
1616
margin-left: -0.6em;
1717
}

app/utils/dnd.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export const DND_DRAG_START = 'DND_DRAG_START'
66
export const DND_DRAG_OVER = 'DND_DRAG_OVER'
77
export const DND_UPDATE_DRAG_OVER_META = 'DND_UPDATE_DRAG_OVER_META'
88
export const DND_DRAG_END = 'DND_DRAG_END'
9+
export const DND_UPDATE_DROPPABLES = 'DND_UPDATE_DROPPABLES'
910

1011
function getDroppables () {
1112
const droppables = map(document.querySelectorAll('[data-droppable]'), DOMNode => ({
@@ -29,7 +30,7 @@ dnd.dragStart = source => emitter.emit(DND_DRAG_START, source)
2930
dnd.dragOver = target => emitter.emit(DND_DRAG_OVER, target)
3031
dnd.updateDragOverMeta = meta => emitter.emit(DND_UPDATE_DRAG_OVER_META, meta)
3132
dnd.dragEnd = () => emitter.emit(DND_DRAG_END)
32-
33+
dnd.updateDroppables = () => emitter.emit(DND_UPDATE_DROPPABLES)
3334

3435
emitter.on(DND_DRAG_START, (source = {}) => {
3536
dnd.isDragging = true
@@ -50,4 +51,8 @@ emitter.on(DND_DRAG_END, () => {
5051
dnd.source = dnd.target = {}
5152
})
5253

54+
emitter.on(DND_UPDATE_DROPPABLES, () => {
55+
dnd.droppables = observable.shallowArray(getDroppables())
56+
})
57+
5358
export default dnd

0 commit comments

Comments
 (0)