Skip to content

Commit 1573261

Browse files
committed
draggable.toolbar.SortZone: adjustProxyRectToParent, itemMargin configs #6332
1 parent b68a3ad commit 1573261

2 files changed

Lines changed: 28 additions & 79 deletions

File tree

Lines changed: 9 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import BaseSortZone from '../../../toolbar/SortZone.mjs';
2-
import VDomUtil from '../../../../util/VDom.mjs';
32

43
/**
54
* @class Neo.draggable.grid.header.toolbar.SortZone
@@ -17,6 +16,15 @@ class SortZone extends BaseSortZone {
1716
* @protected
1817
*/
1918
ntype: 'grid-header-toolbar-sortzone',
19+
/**
20+
* @member {Boolean} adjustProxyRectToParent=true
21+
*/
22+
adjustProxyRectToParent: true,
23+
/**
24+
* @member {String|null} itemMargin=null
25+
* @protected
26+
*/
27+
itemMargin: '1px',
2028
/**
2129
* @member {Boolean} moveVertical=false
2230
*/
@@ -40,84 +48,6 @@ class SortZone extends BaseSortZone {
4048

4149
owner.parent.view.createViewData()
4250
}
43-
44-
/**
45-
* @param {Object} data
46-
*/
47-
onDragStart(data) {
48-
let me = this,
49-
button = Neo.getComponent(data.path[0].id),
50-
{owner} = me,
51-
itemStyles = me.itemStyles = [],
52-
{layout} = owner,
53-
ownerStyle = owner.style || {},
54-
index, indexMap, itemStyle, ownerRect, rect;
55-
56-
if (owner.sortable) {
57-
index = owner.indexOf(button.id);
58-
indexMap = {};
59-
60-
Object.assign(me, {
61-
currentIndex : index,
62-
dragElement : VDomUtil.find(owner.vdom, button.id).vdom,
63-
dragProxyConfig : {...me.dragProxyConfig, cls : [...owner.cls]},
64-
indexMap : indexMap,
65-
ownerStyle : {height: ownerStyle.height, width : ownerStyle.width},
66-
reversedLayoutDirection: layout.direction === 'column-reverse' || layout.direction === 'row-reverse',
67-
sortDirection : owner.layout.ntype === 'layout-vbox' ? 'vertical' : 'horizontal',
68-
startIndex : index
69-
});
70-
71-
me.dragStart(data); // we do not want to trigger the super class call here
72-
73-
owner.items.forEach((item, index) => {
74-
indexMap[index] = index;
75-
76-
itemStyles.push({
77-
height: item.height ? `${item.height}px` : item.style?.height,
78-
width : item.width ? `${item.width}px` : item.style?.width
79-
})
80-
});
81-
82-
owner.getDomRect([owner.id].concat(owner.items.map(e => e.id))).then(itemRects => {
83-
me.ownerRect = ownerRect = itemRects[0];
84-
85-
ownerStyle.height = `${itemRects[0].height}px`;
86-
ownerStyle.width = `${itemRects[0].width}px`;
87-
88-
// the only reason we are adjusting the toolbar style is that there is no min height or width present.
89-
// removing items from the layout could trigger a change in size.
90-
owner.style = ownerStyle;
91-
92-
itemRects.shift();
93-
me.itemRects = itemRects;
94-
95-
owner.items.forEach((item, index) => {
96-
itemStyle = item.style || {};
97-
rect = itemRects[index];
98-
99-
rect.x = rect.x - ownerRect.x - 1;
100-
rect.y = rect.y - ownerRect.y - 1;
101-
102-
item.style = Object.assign(itemStyle, {
103-
height : `${rect.height}px`,
104-
left : `${rect.left}px`,
105-
margin : '1px',
106-
position: 'absolute',
107-
top : `${rect.top}px`,
108-
width : `${rect.width}px`
109-
})
110-
});
111-
112-
// we need to add a short (1 frame) delay to ensure the item has switched to an absolute position
113-
me.timeout(5).then(() => {
114-
itemStyle = button.style || {};
115-
itemStyle.visibility = 'hidden';
116-
button.style = itemStyle
117-
})
118-
})
119-
}
120-
}
12151
}
12252

12353
export default Neo.setupClass(SortZone);

src/draggable/toolbar/SortZone.mjs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ class SortZone extends DragZone {
1717
* @protected
1818
*/
1919
ntype: 'toolbar-sortzone',
20+
/**
21+
* Depending on the parent tree positioning (especially using position: relative),
22+
* it might be required to subtract the parent height & width from the proxy element position.
23+
* draggable.grid.header.toolbar.SortZone needs it
24+
* draggable.tab.header.toolbar.SortZone does not need it
25+
* @member {Boolean} adjustProxyRectToParent=false
26+
*/
27+
adjustProxyRectToParent: false,
2028
/**
2129
* @member {Boolean} alwaysFireDragMove=true
2230
*/
@@ -31,6 +39,11 @@ class SortZone extends DragZone {
3139
* @protected
3240
*/
3341
indexMap: null,
42+
/**
43+
* @member {String|null} itemMargin=null
44+
* @protected
45+
*/
46+
itemMargin: null,
3447
/**
3548
* @member {Array|null} itemRects=null
3649
* @protected
@@ -225,9 +238,15 @@ class SortZone extends DragZone {
225238
itemStyle = item.style || {};
226239
rect = itemRects[index];
227240

241+
if (me.adjustProxyRectToParent) {
242+
rect.x = rect.x - me.ownerRect.x - 1;
243+
rect.y = rect.y - me.ownerRect.y - 1
244+
}
245+
228246
item.style = Object.assign(itemStyle, {
229247
height : `${rect.height}px`,
230248
left : `${rect.left}px`,
249+
margin : me.itemMargin,
231250
position: 'absolute',
232251
top : `${rect.top}px`,
233252
width : `${rect.width}px`

0 commit comments

Comments
 (0)