Skip to content

Commit b415efd

Browse files
committed
#7204 popup drag:move events (WIP)
1 parent e081555 commit b415efd

4 files changed

Lines changed: 104 additions & 18 deletions

File tree

apps/colors/view/ViewportController.mjs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,19 @@ class ViewportController extends Controller {
115115
* @param {Object} data
116116
*/
117117
async onDragBoundaryExit(data) {
118-
let {draggedItem, proxyRect} = data,
119-
widgetName = draggedItem.reference.replace('-panel', '');
118+
let {draggedItem, proxyRect, sortZone} = data,
119+
widgetName = draggedItem.reference.replace('-panel', ''),
120+
popupData;
120121

121-
await this.#openWidgetInPopup(widgetName, proxyRect);
122+
// Prohibit the size reduction inside #openWidgetInPopup().
123+
proxyRect.height += 50;
124+
125+
popupData = await this.#openWidgetInPopup(widgetName, proxyRect);
126+
127+
sortZone.startWindowDrag({
128+
dragData: data,
129+
...popupData
130+
});
122131
}
123132

124133
/**
@@ -271,7 +280,9 @@ class ViewportController extends Controller {
271280
url,
272281
windowFeatures: `height=${popupHeight},left=${popupLeft},top=${popupTop},width=${width}`,
273282
windowName : name
274-
})
283+
});
284+
285+
return {popupHeight, popupLeft, popupTop, popupWidth: width, windowName: name}
275286
}
276287

277288
/**

src/dashboard/Container.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class Container extends BaseContainer {
4343
allowOverdrag : true,
4444
appName : me.appName,
4545
boundaryContainerId: me.id,
46+
enableProxyToPopup : true,
4647
owner : me,
4748
windowId : me.windowId,
4849
listeners : {

src/draggable/container/SortZone.mjs

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ class SortZone extends DragZone {
4040
* @member {String|null} dragHandleSelector=null
4141
*/
4242
dragHandleSelector: null,
43+
/**
44+
* @member {Boolean} enableProxyToPopup=false
45+
*/
46+
enableProxyToPopup: false,
4347
/**
4448
* @member {Object} indexMap=null
4549
* @protected
@@ -218,24 +222,30 @@ class SortZone extends DragZone {
218222
return
219223
}
220224

221-
if (me.dragProxy && !me.isWindowDragging) {
225+
if (me.dragProxy && me.enableProxyToPopup) {
222226
const {proxyRect} = data;
223-
227+
console.log(proxyRect);
224228
if (proxyRect && me.boundaryContainerRect) {
225229
const
226230
boundaryRect = me.boundaryContainerRect,
227231
intersection = Rectangle.getIntersection(proxyRect, boundaryRect),
228232
proxyArea = proxyRect.width * proxyRect.height,
229233
intersectionArea = intersection ? intersection.width * intersection.height : 0;
230234

231-
if (proxyArea > 0 && (intersectionArea / proxyArea) < 0.5) {
232-
me.isWindowDragging = true; // Set flag to prevent re-entry
235+
if (!me.isWindowDragging) {
236+
if (proxyArea > 0 && (intersectionArea / proxyArea) < 0.5) {
237+
me.isWindowDragging = true; // Set flag to prevent re-entry
233238

234-
me.fire('dragBoundaryExit', {
235-
draggedItem: Neo.getComponent(me.dragElement.id),
236-
proxyRect
237-
});
238-
return // Stop further processing in onDragMove
239+
me.fire('dragBoundaryExit', {
240+
draggedItem: Neo.getComponent(me.dragElement.id),
241+
proxyRect,
242+
sortZone : me
243+
});
244+
return // Stop further processing in onDragMove
245+
}
246+
} else if (me.isWindowDragging) {
247+
console.log(proxyArea, intersectionArea, (intersectionArea / proxyArea) > 0.51);
248+
return;
239249
}
240250
}
241251
}
@@ -433,6 +443,23 @@ class SortZone extends DragZone {
433443
me.isScrolling = false
434444
}
435445

446+
/**
447+
* @param {Object} data
448+
*/
449+
startWindowDrag(data) {
450+
let me = this,
451+
{popupHeight, popupWidth, windowName} = data;
452+
453+
// Hide the drag proxy since the window is now the visual indicator
454+
me.dragProxy.hidden = true;
455+
456+
Neo.main.addon.DragDrop.startWindowDrag({
457+
popupHeight,
458+
popupName: windowName,
459+
popupWidth
460+
});
461+
}
462+
436463
/**
437464
* @param {Number} index1
438465
* @param {Number} index2

src/main/addon/DragDrop.mjs

Lines changed: 52 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ class DragDrop extends Base {
8787
* @member {Number} initialScrollTop=0
8888
*/
8989
initialScrollTop: 0,
90+
/**
91+
* @member {Boolean} isWindowDragging=false
92+
* @protected
93+
*/
94+
isWindowDragging: false,
9095
/**
9196
* @member {Boolean} moveHorizontal=true
9297
*/
@@ -103,6 +108,11 @@ class DragDrop extends Base {
103108
* @member {Number} offsetY=0
104109
*/
105110
offsetY: 0,
111+
/**
112+
* @member {String|null} popupName=null
113+
* @protected
114+
*/
115+
popupName: null,
106116
/**
107117
* Remote method access for other workers
108118
* @member {Object} remote
@@ -112,7 +122,8 @@ class DragDrop extends Base {
112122
app: [
113123
'requestWindowManagementPermission',
114124
'setConfigs',
115-
'setDragProxyElement'
125+
'setDragProxyElement',
126+
'startWindowDrag'
116127
]
117128
},
118129
/**
@@ -247,24 +258,50 @@ class DragDrop extends Base {
247258
dropZoneIdentifier : null,
248259
initialScrollLeft : 0,
249260
initialScrollTop : 0,
261+
isWindowDragging : false,
250262
moveHorizontal : true,
251263
moveVertical : true,
264+
popupHeight : null,
265+
popupName : null,
266+
popupWidth : null,
252267
scrollContainerElement: null,
253268
scrollContainerRect : null,
254269
setScrollFactorLeft : 1,
255-
scrollFactorTop : 1
270+
scrollFactorTop : 1,
271+
windowName : null
256272
})
257273
}
258274

259275
/**
260276
* @param {Event} event
261277
*/
262278
onDragMove(event) {
263-
let me = this,
264-
proxyRect = me.dragProxyRect,
265-
rect = me.boundaryContainerRect,
279+
let me = this,
280+
{originalEvent} = event.detail,
281+
proxyRect = me.dragProxyRect,
282+
rect = me.boundaryContainerRect,
266283
data, left, top;
267284

285+
if (me.isWindowDragging) {
286+
const
287+
x = originalEvent.screenX - (me.offsetX || 0),
288+
y = originalEvent.screenY - (me.offsetY || 0);
289+
290+
Neo.Main.windowMoveTo({windowName: me.popupName, x, y});
291+
292+
DomEvents.sendMessageToApp({
293+
...me.getEventData(event),
294+
offsetX : me.offsetX,
295+
offsetY : me.offsetY,
296+
proxyRect: new DOMRect(x, y, me.popupWidth, me.popupHeight),
297+
screenX : originalEvent.screenX,
298+
screenY : originalEvent.screenY,
299+
type : 'drag:move'
300+
});
301+
302+
return
303+
}
304+
268305
if (me.scrollContainerElement) {
269306
data = me.scrollContainer({
270307
clientX: event.detail.clientX,
@@ -542,6 +579,16 @@ class DragDrop extends Base {
542579
setDragProxyElement(data) {
543580
this.dragProxyElement = document.getElementById(data.id)
544581
}
582+
583+
/**
584+
* @param {Object} data
585+
* @param {String} data.popupHeight
586+
* @param {String} data.popupName
587+
* @param {String} data.popupWidth
588+
*/
589+
startWindowDrag({popupHeight, popupName, popupWidth}) {
590+
Object.assign(this, {isWindowDragging: true, popupHeight, popupName, popupWidth})
591+
}
545592
}
546593

547594
export default Neo.setupClass(DragDrop);

0 commit comments

Comments
 (0)