@@ -46,11 +46,9 @@ export function useDraggableChildren({
46
46
const id = stateRef . current . id ;
47
47
const item = listRef . current . modify [ idx ] ;
48
48
const emit = ( ) : void => {
49
- console . log ( 'emit' , stateRef . current . id ) ;
50
49
// preverRef.current = null;
51
50
if ( isListChanged ( ) ) {
52
51
const result = listRef . current . modify . slice ( ) ;
53
- console . log ( 'onchange' , result ) ;
54
52
onChange ?.( result ) ;
55
53
}
56
54
} ;
@@ -118,14 +116,17 @@ export function useDraggableChildren({
118
116
//
119
117
// if (from === index) return;
120
118
// move(from, index);
121
- console . log ( 'onDrop' ) ;
122
119
e . preventDefault ( ) ;
123
120
stateRef . current . index = - 1 ;
124
121
125
122
const from = fromRef . current ;
126
123
if ( ! from ) return ;
127
124
128
125
if ( from . id !== id ) from . drop ?.( id ) ;
126
+ else if ( ! isListChanged ( ) ) {
127
+ // 当在同一个组件拖动过但又没有实际变动时,刷新当前拖动项的选中状态
128
+ updateChildrenOf ( from . children , idx ) ;
129
+ }
129
130
// 在同一个组件内拖拽的话 to = from
130
131
// if (from.id !== toRef.current?.id) toRef.current?.drop?.(id);
131
132
const to = toRef . current ;
@@ -137,7 +138,6 @@ export function useDraggableChildren({
137
138
// eslint-disable-next-line perfectionist/sort-objects
138
139
onDragEnterCapture ( e : DragEvent ) : void {
139
140
const index = listRef . current . modify . indexOf ( item ) ;
140
- console . log ( 'enter' , id , index , stateRef . current . index ) ;
141
141
const target = e . target as HTMLElement ;
142
142
e . preventDefault ( ) ;
143
143
@@ -150,12 +150,9 @@ export function useDraggableChildren({
150
150
151
151
const from = fromRef . current ;
152
152
const prever = toRef . current || from ;
153
- console . log ( prever ) ;
154
153
if ( ! prever || ! from ) return ;
155
- console . log ( item , from . item ) ;
156
154
prever . enter ?.( id ) ;
157
155
158
- console . log ( prever . id , id , prever . id === id ) ;
159
156
const fromIndex = listRef . current . modify . indexOf ( from . item ) ;
160
157
if ( from . item !== item ) {
161
158
if ( prever . id === id || fromIndex !== - 1 ) {
@@ -175,7 +172,6 @@ export function useDraggableChildren({
175
172
move ( cloneAndAddClassName ( from . children ) , fromIndex , toIndex ) ;
176
173
} else moveFromGroup ( from . item , from . children , index ) ;
177
174
} else {
178
- console . log ( 'uuuuuuuuuuup' ) ;
179
175
updateChildrenOf (
180
176
cloneAndAddClassName (
181
177
modifyChildrenRef . current [ fromIndex ] as ReactElement ,
@@ -187,14 +183,12 @@ export function useDraggableChildren({
187
183
stateRef . current . index = index ;
188
184
toRef . current = {
189
185
enter : ( id2 ) : void => {
190
- console . log ( 'id===id' , id2 === id ) ;
191
186
if ( id2 !== id ) {
192
187
stateRef . current . index = - 1 ;
193
188
if ( ! listRef . current . origin . includes ( from . item ) ) {
194
189
removeItem ( from . item ) ;
195
190
}
196
191
if ( type === 'move' ) {
197
- console . log ( 'mmmmmmmmm' , item , from . item ) ;
198
192
updateChildrenOf (
199
193
cloneAndAddClassName ( from . children , cls [ '--' ] . hidden ) ,
200
194
listRef . current . modify . indexOf ( from . item ) ,
@@ -205,13 +199,11 @@ export function useDraggableChildren({
205
199
stateRef . current . index = - 1 ;
206
200
} ,
207
201
cancel : ( _id2 ) : void => {
208
- console . log ( 'oncancel' , id , _id2 , prever . id , target ) ;
209
202
stateRef . current . index = - 1 ;
210
203
if ( ! listRef . current . origin . includes ( from . item ) ) {
211
204
removeItem ( from . item ) ;
212
205
toRef . current = null ;
213
206
} else {
214
- console . log ( 'ccccccccccccc' ) ;
215
207
const index = listRef . current . modify . indexOf ( from . item ) ;
216
208
// 还原成未加工状态
217
209
updateChildrenOf ( from . children , index ) ;
@@ -225,7 +217,6 @@ export function useDraggableChildren({
225
217
item,
226
218
id,
227
219
} ;
228
- console . log ( '-' . repeat ( 20 ) ) ;
229
220
} ,
230
221
onDragOver ( e : DragEvent ) {
231
222
if ( el . props . draggable === false ) return ;
@@ -249,7 +240,6 @@ export function useDraggableChildren({
249
240
forceUpdate ( ) ;
250
241
}
251
242
function moveFromGroup ( item : unknown , children : ReactElement , to : number ) {
252
- console . log ( 'moveFromGroup' , item , to , item ) ;
253
243
children = cloneAndAddClassName ( children ) ;
254
244
const temp = modifyChildrenRef . current . slice ( ) ;
255
245
insertToArray ( children , to , temp ) ;
0 commit comments