mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
[groups] Overhaul group drag handling for empty groups
This commit is contained in:
parent
ef9db701f8
commit
1bdbd31b96
@ -209,8 +209,8 @@ RED.history = (function() {
|
|||||||
for (i=0;i<ev.groups.length;i++) {
|
for (i=0;i<ev.groups.length;i++) {
|
||||||
RED.nodes.addGroup(ev.groups[i])
|
RED.nodes.addGroup(ev.groups[i])
|
||||||
modifiedTabs[ev.groups[i].z] = true;
|
modifiedTabs[ev.groups[i].z] = true;
|
||||||
inverseEv.groups.push(ev.groups[i].id);
|
inverseEv.groups.push(ev.groups[i]);
|
||||||
if (!groupsToAdd.has(ev.groups[i].g)) {
|
if (ev.groups[i].g && !groupsToAdd.has(ev.groups[i].g)) {
|
||||||
group = RED.nodes.group(ev.groups[i].g);
|
group = RED.nodes.group(ev.groups[i].g);
|
||||||
if (group.nodes.indexOf(ev.groups[i]) === -1) {
|
if (group.nodes.indexOf(ev.groups[i]) === -1) {
|
||||||
group.nodes.push(ev.groups[i]);
|
group.nodes.push(ev.groups[i]);
|
||||||
|
@ -566,6 +566,10 @@ RED.nodes = (function() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (n.type === "group") {
|
if (n.type === "group") {
|
||||||
|
node.x = n.x;
|
||||||
|
node.y = n.y;
|
||||||
|
node.w = n.w;
|
||||||
|
node.h = n.h;
|
||||||
node.nodes = node.nodes.map(function(n) { return n.id });
|
node.nodes = node.nodes.map(function(n) { return n.id });
|
||||||
}
|
}
|
||||||
if (n._def.category != "config") {
|
if (n._def.category != "config") {
|
||||||
|
@ -31,6 +31,7 @@ RED.group = (function() {
|
|||||||
// '<label style="width: 70px;margin-right: 10px " for="node-input-style-fill" data-i18n="editor:common.label.fill"></label>'+
|
// '<label style="width: 70px;margin-right: 10px " for="node-input-style-fill" data-i18n="editor:common.label.fill"></label>'+
|
||||||
// '</span>'+
|
// '</span>'+
|
||||||
// '</div>'+
|
// '</div>'+
|
||||||
|
'<div class="node-input-group-style-tools"><span class="button-group"><button class="red-ui-button red-ui-button-small">Use default style</button><button class="red-ui-button red-ui-button-small">Set as default style</button></span></div>'+
|
||||||
|
|
||||||
'<div class="form-row" id="node-input-row-style-stroke">'+
|
'<div class="form-row" id="node-input-row-style-stroke">'+
|
||||||
'<label>Style</label>'+
|
'<label>Style</label>'+
|
||||||
@ -535,9 +536,8 @@ RED.group = (function() {
|
|||||||
function getNodes(group,recursive) {
|
function getNodes(group,recursive) {
|
||||||
var nodes = [];
|
var nodes = [];
|
||||||
group.nodes.forEach(function(n) {
|
group.nodes.forEach(function(n) {
|
||||||
if (!recursive || n.type !== 'group') {
|
nodes.push(n);
|
||||||
nodes.push(n);
|
if (recursive && n.type === 'group') {
|
||||||
} else {
|
|
||||||
nodes = nodes.concat(getNodes(n,recursive))
|
nodes = nodes.concat(getNodes(n,recursive))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -67,9 +67,16 @@ RED.view.tools = (function() {
|
|||||||
|
|
||||||
function moveSelection(dx,dy) {
|
function moveSelection(dx,dy) {
|
||||||
if (moving_set === null) {
|
if (moving_set === null) {
|
||||||
|
moving_set = [];
|
||||||
var selection = RED.view.selection();
|
var selection = RED.view.selection();
|
||||||
if (selection.nodes) {
|
if (selection.nodes) {
|
||||||
moving_set = selection.nodes.map(function(n) { return {n:n}});
|
while (selection.nodes.length > 0) {
|
||||||
|
var n = selection.nodes.shift();
|
||||||
|
moving_set.push({n:n});
|
||||||
|
if (n.type === "group") {
|
||||||
|
selection.nodes = selection.nodes.concat(n.nodes);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (moving_set && moving_set.length > 0) {
|
if (moving_set && moving_set.length > 0) {
|
||||||
@ -93,6 +100,9 @@ RED.view.tools = (function() {
|
|||||||
node.n.x += dx;
|
node.n.x += dx;
|
||||||
node.n.y += dy;
|
node.n.y += dy;
|
||||||
node.n.dirty = true;
|
node.n.dirty = true;
|
||||||
|
if (node.n.type === "group") {
|
||||||
|
RED.group.markDirty(node.n);
|
||||||
|
}
|
||||||
minX = Math.min(node.n.x-node.n.w/2-5,minX);
|
minX = Math.min(node.n.x-node.n.w/2-5,minX);
|
||||||
minY = Math.min(node.n.y-node.n.h/2-5,minY);
|
minY = Math.min(node.n.y-node.n.h/2-5,minY);
|
||||||
}
|
}
|
||||||
|
@ -415,7 +415,7 @@ RED.view = (function() {
|
|||||||
moving_set.push({n:nn});
|
moving_set.push({n:nn});
|
||||||
if (group) {
|
if (group) {
|
||||||
selectGroup(group,false);
|
selectGroup(group,false);
|
||||||
group.active = true;
|
enterActiveGroup(group);
|
||||||
activeGroup = group;
|
activeGroup = group;
|
||||||
}
|
}
|
||||||
updateActiveNodes();
|
updateActiveNodes();
|
||||||
@ -790,10 +790,8 @@ if (DEBUG_EVENTS) { console.warn("canvasMouseDown", mouse_mode); }
|
|||||||
|
|
||||||
function showQuickAddDialog(point, spliceLink, targetGroup) {
|
function showQuickAddDialog(point, spliceLink, targetGroup) {
|
||||||
if (targetGroup && !targetGroup.active) {
|
if (targetGroup && !targetGroup.active) {
|
||||||
targetGroup.active = true;
|
|
||||||
targetGroup.dirty = true;
|
|
||||||
selectGroup(targetGroup,false);
|
selectGroup(targetGroup,false);
|
||||||
activeGroup = targetGroup;
|
enterActiveGroup(targetGroup);
|
||||||
RED.view.redraw();
|
RED.view.redraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1068,9 +1066,7 @@ if (DEBUG_EVENTS) { console.warn("canvasMouseDown", mouse_mode); }
|
|||||||
nn.selected = true;
|
nn.selected = true;
|
||||||
if (targetGroup) {
|
if (targetGroup) {
|
||||||
selectGroup(targetGroup,false);
|
selectGroup(targetGroup,false);
|
||||||
targetGroup.active = true
|
enterActiveGroup(targetGroup);
|
||||||
targetGroup.dirty = true;
|
|
||||||
activeGroup = targetGroup;
|
|
||||||
}
|
}
|
||||||
moving_set.push({n:nn});
|
moving_set.push({n:nn});
|
||||||
updateActiveNodes();
|
updateActiveNodes();
|
||||||
@ -1294,10 +1290,18 @@ if (DEBUG_EVENTS) { console.warn("canvasMouseDown", mouse_mode); }
|
|||||||
node.n.x = mousePos[0]+node.dx;
|
node.n.x = mousePos[0]+node.dx;
|
||||||
node.n.y = mousePos[1]+node.dy;
|
node.n.y = mousePos[1]+node.dy;
|
||||||
node.n.dirty = true;
|
node.n.dirty = true;
|
||||||
minX = Math.min(node.n.x-node.n.w/2-5,minX);
|
if (node.n.type === "group") {
|
||||||
minY = Math.min(node.n.y-node.n.h/2-5,minY);
|
RED.group.markDirty(node.n);
|
||||||
maxX = Math.max(node.n.x+node.n.w/2+5,maxX);
|
minX = Math.min(node.n.x-5,minX);
|
||||||
maxY = Math.max(node.n.y+node.n.h/2+5,maxY);
|
minY = Math.min(node.n.y-5,minY);
|
||||||
|
maxX = Math.max(node.n.x+node.n.w+5,maxX);
|
||||||
|
maxY = Math.max(node.n.y+node.n.h+5,maxY);
|
||||||
|
} else {
|
||||||
|
minX = Math.min(node.n.x-node.n.w/2-5,minX);
|
||||||
|
minY = Math.min(node.n.y-node.n.h/2-5,minY);
|
||||||
|
maxX = Math.max(node.n.x+node.n.w/2+5,maxX);
|
||||||
|
maxY = Math.max(node.n.y+node.n.h/2+5,maxY);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (minX !== 0 || minY !== 0) {
|
if (minX !== 0 || minY !== 0) {
|
||||||
for (i = 0; i<moving_set.length; i++) {
|
for (i = 0; i<moving_set.length; i++) {
|
||||||
@ -1318,11 +1322,23 @@ if (DEBUG_EVENTS) { console.warn("canvasMouseDown", mouse_mode); }
|
|||||||
// mousedown_group.y = mousePos[1] + mousedown_group.dy;
|
// mousedown_group.y = mousePos[1] + mousedown_group.dy;
|
||||||
// mousedown_group.dirty = true;
|
// mousedown_group.dirty = true;
|
||||||
// }
|
// }
|
||||||
|
var gridOffset = [0,0];
|
||||||
if (snapGrid != d3.event.shiftKey && moving_set.length > 0) {
|
if (snapGrid != d3.event.shiftKey && moving_set.length > 0) {
|
||||||
var gridOffset = [0,0];
|
var i = 0;
|
||||||
node = moving_set[0];
|
|
||||||
gridOffset[0] = node.n.x-(gridSize*Math.floor((node.n.x-node.n.w/2)/gridSize)+node.n.w/2);
|
// Prefer to snap nodes to the grid if there is one in the selection
|
||||||
gridOffset[1] = node.n.y-(gridSize*Math.floor(node.n.y/gridSize));
|
do {
|
||||||
|
node = moving_set[i++];
|
||||||
|
} while(i<moving_set.length && node.n.type === "group")
|
||||||
|
|
||||||
|
if (node.n.type === "group") {
|
||||||
|
// TODO: Group snap to grid
|
||||||
|
gridOffset[0] = node.n.x-(gridSize*Math.floor(node.n.x/gridSize))-gridSize/2;
|
||||||
|
gridOffset[1] = node.n.y-(gridSize*Math.floor(node.n.y/gridSize))-gridSize/2;
|
||||||
|
} else {
|
||||||
|
gridOffset[0] = node.n.x-(gridSize*Math.floor((node.n.x-node.n.w/2)/gridSize)+node.n.w/2);
|
||||||
|
gridOffset[1] = node.n.y-(gridSize*Math.floor(node.n.y/gridSize));
|
||||||
|
}
|
||||||
if (gridOffset[0] !== 0 || gridOffset[1] !== 0) {
|
if (gridOffset[0] !== 0 || gridOffset[1] !== 0) {
|
||||||
for (i = 0; i<moving_set.length; i++) {
|
for (i = 0; i<moving_set.length; i++) {
|
||||||
node = moving_set[i];
|
node = moving_set[i];
|
||||||
@ -1334,7 +1350,9 @@ if (DEBUG_EVENTS) { console.warn("canvasMouseDown", mouse_mode); }
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ((mouse_mode == RED.state.MOVING_ACTIVE || mouse_mode == RED.state.IMPORT_DRAGGING) && moving_set.length === 1) {
|
|
||||||
|
// Check link splice or group-add
|
||||||
|
if (moving_set.length === 1 && moving_set[0].n.type !== "group") {
|
||||||
node = moving_set[0];
|
node = moving_set[0];
|
||||||
if (spliceActive) {
|
if (spliceActive) {
|
||||||
if (!spliceTimer) {
|
if (!spliceTimer) {
|
||||||
@ -1450,6 +1468,19 @@ if (DEBUG_EVENTS) { console.warn("canvasMouseUp", mouse_mode); }
|
|||||||
if (!d3.event.shiftKey) {
|
if (!d3.event.shiftKey) {
|
||||||
clearSelection();
|
clearSelection();
|
||||||
}
|
}
|
||||||
|
activeGroups.forEach(function(g) {
|
||||||
|
if (!g.selected) {
|
||||||
|
if (g.x > x && g.x+g.w < x2 && g.y > y && g.y+g.h < y2) {
|
||||||
|
while (g.g) {
|
||||||
|
g = RED.nodes.group(g.g);
|
||||||
|
}
|
||||||
|
if (!g.selected) {
|
||||||
|
selectGroup(g,true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
activeNodes.forEach(function(n) {
|
activeNodes.forEach(function(n) {
|
||||||
if (!n.selected) {
|
if (!n.selected) {
|
||||||
if (n.x > x && n.x < x2 && n.y > y && n.y < y2) {
|
if (n.x > x && n.x < x2 && n.y > y && n.y < y2) {
|
||||||
@ -1469,6 +1500,9 @@ if (DEBUG_EVENTS) { console.warn("canvasMouseUp", mouse_mode); }
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// var selectionChanged = false;
|
// var selectionChanged = false;
|
||||||
// do {
|
// do {
|
||||||
// selectionChanged = false;
|
// selectionChanged = false;
|
||||||
@ -1521,11 +1555,9 @@ if (DEBUG_EVENTS) { console.warn("canvasMouseUp", mouse_mode); }
|
|||||||
addedToGroup = activeHoverGroup;
|
addedToGroup = activeHoverGroup;
|
||||||
|
|
||||||
activeHoverGroup.hovered = false;
|
activeHoverGroup.hovered = false;
|
||||||
activeHoverGroup.dirty = true;
|
enterActiveGroup(activeHoverGroup)
|
||||||
activeHoverGroup.active = true;
|
// TODO: check back whether this should add to moving_set
|
||||||
activeGroup = activeHoverGroup;
|
|
||||||
activeGroup.selected = true;
|
activeGroup.selected = true;
|
||||||
|
|
||||||
activeHoverGroup = null;
|
activeHoverGroup = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1538,6 +1570,7 @@ if (DEBUG_EVENTS) { console.warn("canvasMouseUp", mouse_mode); }
|
|||||||
n.n.moved = true;
|
n.n.moved = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ns.length > 0) {
|
if (ns.length > 0) {
|
||||||
historyEvent = {t:"move",nodes:ns,dirty:RED.nodes.dirty()};
|
historyEvent = {t:"move",nodes:ns,dirty:RED.nodes.dirty()};
|
||||||
if (activeSpliceLink) {
|
if (activeSpliceLink) {
|
||||||
@ -1817,6 +1850,8 @@ if (DEBUG_EVENTS) { console.warn("clearSelection", mouse_mode); }
|
|||||||
var node = moving_set[0].n;
|
var node = moving_set[0].n;
|
||||||
if (node.type === "subflow") {
|
if (node.type === "subflow") {
|
||||||
RED.editor.editSubflow(activeSubflow);
|
RED.editor.editSubflow(activeSubflow);
|
||||||
|
} else if (node.type === "group") {
|
||||||
|
RED.editor.editGroup(node);
|
||||||
} else {
|
} else {
|
||||||
RED.editor.edit(node);
|
RED.editor.edit(node);
|
||||||
}
|
}
|
||||||
@ -1882,11 +1917,14 @@ if (DEBUG_EVENTS) { console.warn("clearSelection", mouse_mode); }
|
|||||||
|
|
||||||
var startDirty = RED.nodes.dirty();
|
var startDirty = RED.nodes.dirty();
|
||||||
var startChanged = false;
|
var startChanged = false;
|
||||||
|
var selectedGroups = [];
|
||||||
if (moving_set.length > 0) {
|
if (moving_set.length > 0) {
|
||||||
for (var i=0;i<moving_set.length;i++) {
|
for (var i=0;i<moving_set.length;i++) {
|
||||||
var node = moving_set[i].n;
|
var node = moving_set[i].n;
|
||||||
node.selected = false;
|
node.selected = false;
|
||||||
if (node.type != "subflow") {
|
if (node.type === "group") {
|
||||||
|
selectedGroups.push(node);
|
||||||
|
} else if (node.type != "subflow") {
|
||||||
if (node.x < 0) {
|
if (node.x < 0) {
|
||||||
node.x = 25
|
node.x = 25
|
||||||
}
|
}
|
||||||
@ -1912,7 +1950,6 @@ if (DEBUG_EVENTS) { console.warn("clearSelection", mouse_mode); }
|
|||||||
node.dirty = true;
|
node.dirty = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var selectedGroups = activeGroups.filter(function(g) { return !g.active && g.selected });
|
|
||||||
while (selectedGroups.length > 0) {
|
while (selectedGroups.length > 0) {
|
||||||
var g = selectedGroups.shift();
|
var g = selectedGroups.shift();
|
||||||
if (removedGroups.indexOf(g) === -1) {
|
if (removedGroups.indexOf(g) === -1) {
|
||||||
@ -2040,24 +2077,31 @@ if (DEBUG_EVENTS) { console.warn("clearSelection", mouse_mode); }
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
if (moving_set.length > 0) {
|
selection = RED.view.selection();
|
||||||
nodes = moving_set.map(function(n) { return n.n });
|
if (selection.nodes) {
|
||||||
}
|
selection.nodes.forEach(function(n) {
|
||||||
var groups = activeGroups.filter(function(g) { return g.selected && !g.active });
|
nodes.push(n);
|
||||||
while (groups.length > 0) {
|
if (n.type === 'group') {
|
||||||
var group = groups.shift();
|
nodes = nodes.concat(RED.group.getNodes(n,true));
|
||||||
nodes.push(group);
|
}
|
||||||
groups = groups.concat(group.nodes.filter(function(n) { return n.type === "group" }))
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nodes.length > 0) {
|
if (nodes.length > 0) {
|
||||||
var nns = [];
|
var nns = [];
|
||||||
|
var nodeCount = 0;
|
||||||
|
var groupCount = 0;
|
||||||
for (var n=0;n<nodes.length;n++) {
|
for (var n=0;n<nodes.length;n++) {
|
||||||
var node = nodes[n];
|
var node = nodes[n];
|
||||||
// The only time a node.type == subflow can be selected is the
|
// The only time a node.type == subflow can be selected is the
|
||||||
// input/output "proxy" nodes. They cannot be copied.
|
// input/output "proxy" nodes. They cannot be copied.
|
||||||
if (node.type != "subflow") {
|
if (node.type != "subflow") {
|
||||||
|
if (node.type === "group") {
|
||||||
|
groupCount++;
|
||||||
|
} else {
|
||||||
|
nodeCount++;
|
||||||
|
}
|
||||||
for (var d in node._def.defaults) {
|
for (var d in node._def.defaults) {
|
||||||
if (node._def.defaults.hasOwnProperty(d)) {
|
if (node._def.defaults.hasOwnProperty(d)) {
|
||||||
if (node._def.defaults[d].type) {
|
if (node._def.defaults[d].type) {
|
||||||
@ -2105,7 +2149,7 @@ if (DEBUG_EVENTS) { console.warn("clearSelection", mouse_mode); }
|
|||||||
textDimensionPlaceholder[className].textContent = (str||"");
|
textDimensionPlaceholder[className].textContent = (str||"");
|
||||||
var w = textDimensionPlaceholder[className].offsetWidth;
|
var w = textDimensionPlaceholder[className].offsetWidth;
|
||||||
var h = textDimensionPlaceholder[className].offsetHeight;
|
var h = textDimensionPlaceholder[className].offsetHeight;
|
||||||
return [offsetW+w,offsetH+h];
|
return [(offsetW||0)+w,(offsetH||0)+h];
|
||||||
}
|
}
|
||||||
|
|
||||||
var separateTextByLineBreak = [];
|
var separateTextByLineBreak = [];
|
||||||
@ -2555,11 +2599,10 @@ if (DEBUG_EVENTS) { console.warn("nodeMouseUp", mouse_mode,d); }
|
|||||||
// Moving primed, but not active.
|
// Moving primed, but not active.
|
||||||
if (!groupNodeSelectPrimed && !d.selected && d.g && RED.nodes.group(d.g).selected) {
|
if (!groupNodeSelectPrimed && !d.selected && d.g && RED.nodes.group(d.g).selected) {
|
||||||
clearSelection();
|
clearSelection();
|
||||||
activeGroup = RED.nodes.group(d.g);
|
|
||||||
activeGroup.active = true;
|
|
||||||
activeGroup.dirty = true;
|
|
||||||
|
|
||||||
selectGroup(RED.nodes.group(d.g), false);
|
selectGroup(RED.nodes.group(d.g), false);
|
||||||
|
enterActiveGroup(RED.nodes.group(d.g))
|
||||||
|
|
||||||
mousedown_node.selected = true;
|
mousedown_node.selected = true;
|
||||||
moving_set.push({n:mousedown_node});
|
moving_set.push({n:mousedown_node});
|
||||||
var mouse = d3.touches(this)[0]||d3.mouse(this);
|
var mouse = d3.touches(this)[0]||d3.mouse(this);
|
||||||
@ -2603,6 +2646,7 @@ if (DEBUG_EVENTS) { console.warn("nodeMouseUp", mouse_mode,d); }
|
|||||||
moving_set[i].dx = moving_set[i].n.x-mouse[0];
|
moving_set[i].dx = moving_set[i].n.x-mouse[0];
|
||||||
moving_set[i].dy = moving_set[i].n.y-mouse[1];
|
moving_set[i].dy = moving_set[i].n.y-mouse[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
mouse_offset = d3.mouse(document.body);
|
mouse_offset = d3.mouse(document.body);
|
||||||
if (isNaN(mouse_offset[0])) {
|
if (isNaN(mouse_offset[0])) {
|
||||||
mouse_offset = d3.touches(document.body)[0];
|
mouse_offset = d3.touches(document.body)[0];
|
||||||
@ -2900,6 +2944,7 @@ if (DEBUG_EVENTS) { console.warn("nodeMouseDown", mouse_mode,d); }
|
|||||||
g.selected = true;
|
g.selected = true;
|
||||||
g.dirty = true;
|
g.dirty = true;
|
||||||
}
|
}
|
||||||
|
moving_set.push({n:g});
|
||||||
if (includeNodes) {
|
if (includeNodes) {
|
||||||
var currentSet = new Set(moving_set.map(function(n) { return n.n }));
|
var currentSet = new Set(moving_set.map(function(n) { return n.n }));
|
||||||
var allNodes = RED.group.getNodes(g,true);
|
var allNodes = RED.group.getNodes(g,true);
|
||||||
@ -2912,6 +2957,20 @@ if (DEBUG_EVENTS) { console.warn("nodeMouseDown", mouse_mode,d); }
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
function enterActiveGroup(group) {
|
||||||
|
if (activeGroup) {
|
||||||
|
exitActiveGroup();
|
||||||
|
}
|
||||||
|
group.active = true;
|
||||||
|
group.dirty = true;
|
||||||
|
activeGroup = group;
|
||||||
|
for (var i = moving_set.length-1; i >= 0; i -= 1) {
|
||||||
|
if (moving_set[i].n === group) {
|
||||||
|
moving_set.splice(i,1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
function exitActiveGroup() {
|
function exitActiveGroup() {
|
||||||
if (activeGroup) {
|
if (activeGroup) {
|
||||||
activeGroup.active = false;
|
activeGroup.active = false;
|
||||||
@ -2927,8 +2986,9 @@ if (DEBUG_EVENTS) { console.warn("nodeMouseDown", mouse_mode,d); }
|
|||||||
g.dirty = true;
|
g.dirty = true;
|
||||||
}
|
}
|
||||||
var nodeSet = new Set(g.nodes);
|
var nodeSet = new Set(g.nodes);
|
||||||
|
nodeSet.add(g);
|
||||||
for (var i = moving_set.length-1; i >= 0; i -= 1) {
|
for (var i = moving_set.length-1; i >= 0; i -= 1) {
|
||||||
if (nodeSet.has(moving_set[i].n)) {
|
if (nodeSet.has(moving_set[i].n) || moving_set[i].n === g) {
|
||||||
moving_set[i].n.selected = false;
|
moving_set[i].n.selected = false;
|
||||||
moving_set[i].n.dirty = true;
|
moving_set[i].n.dirty = true;
|
||||||
moving_set.splice(i,1);
|
moving_set.splice(i,1);
|
||||||
@ -4072,30 +4132,48 @@ if (DEBUG_EVENTS) { console.warn("nodeMouseDown", mouse_mode,d); }
|
|||||||
group[0].reverse();
|
group[0].reverse();
|
||||||
|
|
||||||
group.each(function(d,i) {
|
group.each(function(d,i) {
|
||||||
|
if (d.resize) {
|
||||||
|
d.minWidth = 0;
|
||||||
|
delete d.resize;
|
||||||
|
}
|
||||||
if (d.dirty || dirtyGroups[d.id]) {
|
if (d.dirty || dirtyGroups[d.id]) {
|
||||||
var g = d3.select(this);
|
var g = d3.select(this);
|
||||||
var minX = Number.POSITIVE_INFINITY;
|
if (d.nodes.length > 0) {
|
||||||
var minY = Number.POSITIVE_INFINITY;
|
var minX = Number.POSITIVE_INFINITY;
|
||||||
var maxX = 0;
|
var minY = Number.POSITIVE_INFINITY;
|
||||||
var maxY = 0;
|
var maxX = 0;
|
||||||
d.nodes.forEach(function(n) {
|
var maxY = 0;
|
||||||
if (n.type !== "group") {
|
d.nodes.forEach(function(n) {
|
||||||
minX = Math.min(minX,n.x-n.w/2-25-((n._def.button && n._def.align!=="right")?20:0));
|
if (n.type !== "group") {
|
||||||
minY = Math.min(minY,n.y-n.h/2-25);
|
minX = Math.min(minX,n.x-n.w/2-25-((n._def.button && n._def.align!=="right")?20:0));
|
||||||
maxX = Math.max(maxX,n.x+n.w/2+25+((n._def.button && n._def.align=="right")?20:0));
|
minY = Math.min(minY,n.y-n.h/2-25);
|
||||||
maxY = Math.max(maxY,n.y+n.h/2+25);
|
maxX = Math.max(maxX,n.x+n.w/2+25+((n._def.button && n._def.align=="right")?20:0));
|
||||||
} else {
|
maxY = Math.max(maxY,n.y+n.h/2+25);
|
||||||
minX = Math.min(minX,n.x-25)
|
} else {
|
||||||
minY = Math.min(minY,n.y-25)
|
minX = Math.min(minX,n.x-25)
|
||||||
maxX = Math.max(maxX,n.x+n.w+25)
|
minY = Math.min(minY,n.y-25)
|
||||||
maxY = Math.max(maxY,n.y+n.h+25)
|
maxX = Math.max(maxX,n.x+n.w+25)
|
||||||
}
|
maxY = Math.max(maxY,n.y+n.h+25)
|
||||||
});
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
d.x = minX;
|
||||||
|
d.y = minY;
|
||||||
|
d.w = maxX - minX;
|
||||||
|
d.h = maxY - minY;
|
||||||
|
} else {
|
||||||
|
d.w = 40;
|
||||||
|
d.h = 40;
|
||||||
|
}
|
||||||
|
if (!d.minWidth) {
|
||||||
|
if (d.style.label && d.name) {
|
||||||
|
d.minWidth = calculateTextWidth(d.name||"","red-ui-flow-group-label",8);
|
||||||
|
} else {
|
||||||
|
d.minWidth = 40;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
d.w = Math.max(d.minWidth,d.w);
|
||||||
|
|
||||||
d.x = minX;
|
|
||||||
d.y = minY;
|
|
||||||
d.w = maxX - minX;
|
|
||||||
d.h = maxY - minY;
|
|
||||||
|
|
||||||
g.attr("transform","translate("+d.x+","+d.y+")")
|
g.attr("transform","translate("+d.x+","+d.y+")")
|
||||||
.classed("red-ui-flow-group-hovered",d.hovered);
|
.classed("red-ui-flow-group-hovered",d.hovered);
|
||||||
@ -4113,10 +4191,10 @@ if (DEBUG_EVENTS) { console.warn("nodeMouseDown", mouse_mode,d); }
|
|||||||
g.selectAll(".red-ui-flow-group-body")
|
g.selectAll(".red-ui-flow-group-body")
|
||||||
.attr("width",d.w)
|
.attr("width",d.w)
|
||||||
.attr("height",d.h)
|
.attr("height",d.h)
|
||||||
.style("stroke", d.style.stroke || "none")
|
.style("stroke", d.style.stroke || "")
|
||||||
.style("stroke-opacity", d.style.hasOwnProperty('stroke-opacity') ? d.style['stroke-opacity'] : 1)
|
.style("stroke-opacity", d.style.hasOwnProperty('stroke-opacity') ? d.style['stroke-opacity'] : "")
|
||||||
.style("fill", d.style.fill || "none")
|
.style("fill", d.style.fill || "")
|
||||||
.style("fill-opacity", d.style.hasOwnProperty('fill-opacity') ? d.style['fill-opacity'] : 1)
|
.style("fill-opacity", d.style.hasOwnProperty('fill-opacity') ? d.style['fill-opacity'] : "")
|
||||||
|
|
||||||
var label = g.selectAll(".red-ui-flow-group-label");
|
var label = g.selectAll(".red-ui-flow-group-label");
|
||||||
label.classed("hide",!!!d.style.label)
|
label.classed("hide",!!!d.style.label)
|
||||||
@ -4210,22 +4288,29 @@ if (DEBUG_EVENTS) { console.warn("nodeMouseDown", mouse_mode,d); }
|
|||||||
RED.workspaces.show(new_default_workspace.id);
|
RED.workspaces.show(new_default_workspace.id);
|
||||||
}
|
}
|
||||||
var new_ms = new_nodes.filter(function(n) { return n.hasOwnProperty("x") && n.hasOwnProperty("y") && n.z == RED.workspaces.active() }).map(function(n) { return {n:n};});
|
var new_ms = new_nodes.filter(function(n) { return n.hasOwnProperty("x") && n.hasOwnProperty("y") && n.z == RED.workspaces.active() }).map(function(n) { return {n:n};});
|
||||||
|
new_ms = new_ms.concat(new_groups.map(function(g) { return {n:g}}))
|
||||||
var new_node_ids = new_nodes.map(function(n){ n.changed = true; return n.id; });
|
var new_node_ids = new_nodes.map(function(n){ n.changed = true; return n.id; });
|
||||||
|
// var new_gs = new_groups.filter(function(g) { console.log(g.id,g.x,g.y); return g.nodes.length === 0}).map(function(g) { return {n:g}})
|
||||||
// TODO: pick a more sensible root node
|
// TODO: pick a more sensible root node
|
||||||
if (new_ms.length > 0) {
|
if (new_ms.length > 0 /* || new_gs.length > 0*/) {
|
||||||
var root_node = new_ms[0].n;
|
|
||||||
var dx = root_node.x;
|
|
||||||
var dy = root_node.y;
|
|
||||||
|
|
||||||
if (mouse_position == null) {
|
if (mouse_position == null) {
|
||||||
mouse_position = [0,0];
|
mouse_position = [0,0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var dx = mouse_position[0];
|
||||||
|
var dy = mouse_position[1];
|
||||||
|
if (new_ms.length > 0) {
|
||||||
|
var root_node = new_ms[0].n;
|
||||||
|
dx = root_node.x;
|
||||||
|
dy = root_node.y;
|
||||||
|
}
|
||||||
|
|
||||||
var minX = 0;
|
var minX = 0;
|
||||||
var minY = 0;
|
var minY = 0;
|
||||||
var i;
|
var i;
|
||||||
var node;
|
var node,group;
|
||||||
|
|
||||||
for (i=0;i<new_ms.length;i++) {
|
for (i=0;i<new_ms.length;i++) {
|
||||||
node = new_ms[i];
|
node = new_ms[i];
|
||||||
@ -4236,8 +4321,13 @@ if (DEBUG_EVENTS) { console.warn("nodeMouseDown", mouse_mode,d); }
|
|||||||
node.n.y -= dy - mouse_position[1];
|
node.n.y -= dy - mouse_position[1];
|
||||||
node.dx = node.n.x - mouse_position[0];
|
node.dx = node.n.x - mouse_position[0];
|
||||||
node.dy = node.n.y - mouse_position[1];
|
node.dy = node.n.y - mouse_position[1];
|
||||||
minX = Math.min(node.n.x-node_width/2-5,minX);
|
if (node.n.type === "group") {
|
||||||
minY = Math.min(node.n.y-node_height/2-5,minY);
|
minX = Math.min(node.n.x-5,minX);
|
||||||
|
minY = Math.min(node.n.y-5,minY);
|
||||||
|
} else {
|
||||||
|
minX = Math.min(node.n.x-node_width/2-5,minX);
|
||||||
|
minY = Math.min(node.n.y-node_height/2-5,minY);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for (i=0;i<new_ms.length;i++) {
|
for (i=0;i<new_ms.length;i++) {
|
||||||
node = new_ms[i];
|
node = new_ms[i];
|
||||||
@ -4254,6 +4344,18 @@ if (DEBUG_EVENTS) { console.warn("nodeMouseDown", mouse_mode,d); }
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
// for (i=0;i<new_gs.length;i++) {
|
||||||
|
// group = new_gs[i];
|
||||||
|
// group.n.selected = true;
|
||||||
|
// group.n.x -= dx - mouse_position[0];
|
||||||
|
// group.n.y -= dy - mouse_position[1];
|
||||||
|
// group.dx = group.n.x - mouse_position[0];
|
||||||
|
// group.dy = group.n.y - mouse_position[1];
|
||||||
|
// group.n.x -= minX;
|
||||||
|
// group.n.y -= minY;
|
||||||
|
// group.dx -= minX;
|
||||||
|
// group.dy -= minY;
|
||||||
|
// }
|
||||||
if (!touchImport) {
|
if (!touchImport) {
|
||||||
mouse_mode = RED.state.IMPORT_DRAGGING;
|
mouse_mode = RED.state.IMPORT_DRAGGING;
|
||||||
spliceActive = false;
|
spliceActive = false;
|
||||||
@ -4372,22 +4474,24 @@ if (DEBUG_EVENTS) { console.warn("nodeMouseDown", mouse_mode,d); }
|
|||||||
var historyEvents = [];
|
var historyEvents = [];
|
||||||
for (var i=0;i<moving_set.length;i++) {
|
for (var i=0;i<moving_set.length;i++) {
|
||||||
var node = moving_set[i].n;
|
var node = moving_set[i].n;
|
||||||
if (isDisabled != node.d) {
|
if (node.type !== "group" && node.type !== "subflow") {
|
||||||
historyEvents.push({
|
if (isDisabled != node.d) {
|
||||||
t: "edit",
|
historyEvents.push({
|
||||||
node: node,
|
t: "edit",
|
||||||
changed: node.changed,
|
node: node,
|
||||||
changes: {
|
changed: node.changed,
|
||||||
d: node.d
|
changes: {
|
||||||
|
d: node.d
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (isDisabled) {
|
||||||
|
node.d = true;
|
||||||
|
} else {
|
||||||
|
delete node.d;
|
||||||
}
|
}
|
||||||
});
|
node.dirty = true;
|
||||||
if (isDisabled) {
|
node.changed = true;
|
||||||
node.d = true;
|
|
||||||
} else {
|
|
||||||
delete node.d;
|
|
||||||
}
|
}
|
||||||
node.dirty = true;
|
|
||||||
node.changed = true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (historyEvents.length > 0) {
|
if (historyEvents.length > 0) {
|
||||||
@ -4402,8 +4506,6 @@ if (DEBUG_EVENTS) { console.warn("nodeMouseDown", mouse_mode,d); }
|
|||||||
RED.view.redraw();
|
RED.view.redraw();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function getSelection() {
|
function getSelection() {
|
||||||
var selection = {};
|
var selection = {};
|
||||||
|
|
||||||
@ -4411,10 +4513,12 @@ if (DEBUG_EVENTS) { console.warn("nodeMouseDown", mouse_mode,d); }
|
|||||||
|
|
||||||
if (moving_set.length > 0) {
|
if (moving_set.length > 0) {
|
||||||
moving_set.forEach(function(n) {
|
moving_set.forEach(function(n) {
|
||||||
allNodes.add(n.n);
|
if (n.n.type !== 'group') {
|
||||||
|
allNodes.add(n.n);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
var selectedGroups = activeGroups.filter(function(g) { return g.selected && !g.active });
|
var selectedGroups = activeGroups.filter(function(g) { return g.selected && !g.active });
|
||||||
if (selectedGroups.length > 0) {
|
if (selectedGroups.length > 0) {
|
||||||
if (selectedGroups.length === 1 && selectedGroups[0].active) {
|
if (selectedGroups.length === 1 && selectedGroups[0].active) {
|
||||||
// Let nodes be nodes
|
// Let nodes be nodes
|
||||||
|
Loading…
Reference in New Issue
Block a user