1
- import { Component , onMounted , useState } from "@odoo/owl" ;
1
+ import { Component , onMounted , onWillUpdateProps , useState } from "@odoo/owl" ;
2
2
import { ComponentsImportance , MIN_FIG_SIZE } from "../../../constants" ;
3
3
import { isDefined } from "../../../helpers" ;
4
4
import { rectIntersection , rectUnion } from "../../../helpers/rectangle" ;
@@ -43,6 +43,7 @@ interface DndState {
43
43
draggedFigure ?: Figure ;
44
44
horizontalSnap ?: Snap < HFigureAxisType > ;
45
45
verticalSnap ?: Snap < VFigureAxisType > ;
46
+ cancelDnd : ( ( ) => void ) | undefined ;
46
47
}
47
48
48
49
css /*SCSS*/ `
@@ -135,6 +136,7 @@ export class FiguresContainer extends Component<Props, SpreadsheetChildEnv> {
135
136
draggedFigure : undefined ,
136
137
horizontalSnap : undefined ,
137
138
verticalSnap : undefined ,
139
+ cancelDnd : undefined ,
138
140
} ) ;
139
141
140
142
setup ( ) {
@@ -148,6 +150,19 @@ export class FiguresContainer extends Component<Props, SpreadsheetChildEnv> {
148
150
// new rendering
149
151
this . render ( ) ;
150
152
} ) ;
153
+ onWillUpdateProps ( ( ) => {
154
+ const sheetId = this . env . model . getters . getActiveSheetId ( ) ;
155
+ const draggedFigureId = this . dnd . draggedFigure ?. id ;
156
+ if ( draggedFigureId && ! this . env . model . getters . getFigure ( sheetId , draggedFigureId ) ) {
157
+ if ( this . dnd . cancelDnd ) {
158
+ this . dnd . cancelDnd ( ) ;
159
+ }
160
+ this . dnd . draggedFigure = undefined ;
161
+ this . dnd . horizontalSnap = undefined ;
162
+ this . dnd . verticalSnap = undefined ;
163
+ this . dnd . cancelDnd = undefined ;
164
+ }
165
+ } ) ;
151
166
}
152
167
153
168
private getVisibleFigures ( ) : Figure [ ] {
@@ -156,12 +171,13 @@ export class FiguresContainer extends Component<Props, SpreadsheetChildEnv> {
156
171
this . dnd . draggedFigure &&
157
172
! visibleFigures . some ( ( figure ) => figure . id === this . dnd . draggedFigure ?. id )
158
173
) {
159
- visibleFigures . push (
160
- this . env . model . getters . getFigure (
161
- this . env . model . getters . getActiveSheetId ( ) ,
162
- this . dnd . draggedFigure ?. id
163
- ) !
174
+ const draggedFigure = this . env . model . getters . getFigure (
175
+ this . env . model . getters . getActiveSheetId ( ) ,
176
+ this . dnd . draggedFigure ?. id
164
177
) ;
178
+ if ( draggedFigure ) {
179
+ visibleFigures . push ( draggedFigure ) ;
180
+ }
165
181
}
166
182
return visibleFigures ;
167
183
}
@@ -314,7 +330,7 @@ export class FiguresContainer extends Component<Props, SpreadsheetChildEnv> {
314
330
this . dnd . verticalSnap = undefined ;
315
331
this . env . model . dispatch ( "UPDATE_FIGURE" , { sheetId, id : figure . id , x, y } ) ;
316
332
} ;
317
- startDnd ( onMouseMove , onMouseUp ) ;
333
+ this . dnd . cancelDnd = startDnd ( onMouseMove , onMouseUp ) ;
318
334
}
319
335
320
336
/**
@@ -382,7 +398,7 @@ export class FiguresContainer extends Component<Props, SpreadsheetChildEnv> {
382
398
this . dnd . horizontalSnap = undefined ;
383
399
this . dnd . verticalSnap = undefined ;
384
400
} ;
385
- startDnd ( onMouseMove , onMouseUp ) ;
401
+ this . dnd . cancelDnd = startDnd ( onMouseMove , onMouseUp ) ;
386
402
}
387
403
388
404
private getOtherFigures ( figId : UID ) : Figure [ ] {
0 commit comments