Add comments

This commit is contained in:
GogoVega 2024-11-09 22:30:45 +01:00
parent 4339016bac
commit 8395ef6e26
No known key found for this signature in database
GPG Key ID: E1E048B63AC5AC2B

View File

@ -72,6 +72,7 @@ RED.history = (function () {
dirty: RED.nodes.dirty()
};
// Remove each node and if the node is in a group remove it from the group
if (ev.nodes) {
inverseEv.nodes = [];
for (let i = 0; i < ev.nodes.length; i++) {
@ -87,11 +88,13 @@ RED.history = (function () {
if (index !== -1) {
group.nodes.splice(index, 1);
RED.group.markDirty(group);
// TODO: no change event?
}
}
}
}
// Remove each links
if (ev.links) {
inverseEv.links = [];
for (let i = 0; i < ev.links.length; i++) {
@ -100,6 +103,7 @@ RED.history = (function () {
}
}
// Remove each junction and if the junction is in a group remove it from the group
if (ev.junctions) {
inverseEv.junctions = [];
for (let i = 0; i < ev.junctions.length; i++) {
@ -111,11 +115,13 @@ RED.history = (function () {
if (index !== -1) {
group.nodes.splice(index, 1);
RED.group.markDirty(group);
// TODO: no change event?
}
}
}
}
// Remove each group
if (ev.groups) {
inverseEv.groups = [];
for (let i = ev.groups.length - 1; i >= 0; i--) {
@ -128,10 +134,12 @@ RED.history = (function () {
}
}
// Remove each workspace
if (ev.workspaces) {
inverseEv.workspaces = [];
for (let i = 0; i < ev.workspaces.length; i++) {
const workspaceOrder = RED.nodes.getWorkspaceOrder();
// Save the current index for the redo event
ev.workspaces[i]._index = workspaceOrder.indexOf(ev.workspaces[i].id);
inverseEv.workspaces.push(ev.workspaces[i]);
RED.nodes.removeWorkspace(ev.workspaces[i].id);
@ -139,6 +147,7 @@ RED.history = (function () {
}
}
// Remove each subflow (tab)
if (ev.subflows) {
inverseEv.subflows = [];
for (let i = 0; i < ev.subflows.length; i++) {
@ -148,6 +157,8 @@ RED.history = (function () {
}
}
// Mark each nodes which use this subflow has changed
// TODO: why?
if (ev.subflow) {
inverseEv.subflow = {};
if (ev.subflow.instances) {
@ -170,6 +181,7 @@ RED.history = (function () {
}
}
// Add links previously removed (in other delete event)
if (ev.removedLinks) {
inverseEv.createdLinks = [];
for (let i = 0; i < ev.removedLinks.length; i++) {
@ -208,6 +220,7 @@ RED.history = (function () {
dirty: RED.nodes.dirty()
};
// Add each workspace
if (ev.workspaces) {
inverseEv.workspaces = [];
for (let i = 0; i < ev.workspaces.length; i++) {
@ -223,6 +236,7 @@ RED.history = (function () {
for (let i = 0; i < ev.subflows.length; i++) {
inverseEv.subflows.push(ev.subflows[i]);
RED.nodes.addSubflow(ev.subflows[i]);
// TODO: add to workspace?
}
}
@ -281,6 +295,7 @@ RED.history = (function () {
});
}
// For each group, create the group and add nodes to it
if (ev.groups) {
inverseEv.groups = [];
const groupsToAdd = {};
@ -306,6 +321,7 @@ RED.history = (function () {
}
}
// Add each nodes, if the node has a group add to it
if (ev.nodes) {
inverseEv.nodes = [];
for (let i = 0; i < ev.nodes.length; i++) {
@ -321,6 +337,8 @@ RED.history = (function () {
}
}
}
// Add each junctions, if the junction has a group add to it
if (ev.junctions) {
inverseEv.junctions = [];
for (let i = 0; i < ev.junctions.length; i++) {
@ -336,6 +354,7 @@ RED.history = (function () {
}
}
// Add each links
if (ev.links) {
inverseEv.links = [];
for (let i = 0; i < ev.links.length; i++) {
@ -344,6 +363,7 @@ RED.history = (function () {
}
}
// Remove each links
if (ev.createdLinks) {
inverseEv.removedLinks = [];
for (let i = 0; i < ev.createdLinks.length; i++) {
@ -352,6 +372,8 @@ RED.history = (function () {
}
}
// Apply chanes to each nodes
// { [nodeId]: object - changes to apply}
if (ev.changes) {
for (const i in ev.changes) {
if (ev.changes.hasOwnProperty(i)) {
@ -394,6 +416,7 @@ RED.history = (function () {
dirty: RED.nodes.dirty()
};
// Move each nodes
for (let i = 0; i < ev.nodes.length; i++) {
const n = ev.nodes[i];
const rn = { n: n.n, ox: n.n.x, oy: n.n.y, dirty: true, moved: n.n.moved };
@ -405,6 +428,7 @@ RED.history = (function () {
}
// A move could have caused a link splice
// So remove each links then readd them
if (ev.links) {
inverseEv.removedLinks = [];
for (let i = 0; i < ev.links.length; i++) {
@ -421,11 +445,13 @@ RED.history = (function () {
}
}
// Remove each nodes from the group
if (ev.addToGroup) {
RED.group.removeFromGroup(ev.addToGroup, ev.nodes.map(function (n) { return n.n }), false);
inverseEv.removeFromGroup = ev.addToGroup;
}
// Add each nodes to the group
if (ev.removeFromGroup) {
RED.group.addToGroup(ev.removeFromGroup, ev.nodes.map(function (n) { return n.n }));
inverseEv.addToGroup = ev.removeFromGroup;
@ -452,9 +478,11 @@ RED.history = (function () {
dirty: RED.nodes.dirty()
};
// Remove all nodes from the subflow
if (ev.nodes) {
inverseEv.movedNodes = [];
const z = ev.activeWorkspace;
// Get all nodes from the subflow defiition
let fullNodeList = RED.nodes.filterNodes({ z: ev.subflow.subflow.id });
fullNodeList = fullNodeList.concat(RED.nodes.groups(ev.subflow.subflow.id));
fullNodeList = fullNodeList.concat(RED.nodes.junctions(ev.subflow.subflow.id));
@ -471,6 +499,8 @@ RED.history = (function () {
RED.nodes.remove(ev.nodes[i]);
}
}
// Remove each links
if (ev.links) {
inverseEv.links = [];
for (let i = 0; i < ev.links.length; i++) {
@ -479,10 +509,12 @@ RED.history = (function () {
}
}
// Remove the subflow (tab)
inverseEv.subflow = ev.subflow;
RED.nodes.removeSubflow(ev.subflow.subflow);
RED.workspaces.remove(ev.subflow.subflow);
// Add each links
if (ev.removedLinks) {
inverseEv.createdLinks = [];
for (let i = 0; i < ev.removedLinks.length; i++) {
@ -513,14 +545,17 @@ RED.history = (function () {
dirty: RED.nodes.dirty(),
};
// Add the subflow (tab)
if (ev.subflow) {
RED.nodes.addSubflow(ev.subflow.subflow);
inverseEv.subflow = ev.subflow;
if (ev.subflow.subflow.g) {
// TODO: why?
RED.group.addToGroup(RED.nodes.group(ev.subflow.subflow.g), ev.subflow.subflow);
}
}
// Create all nodes of the subflow
if (ev.subflows) {
inverseEv.nodes = [];
for (let i = 0; i < ev.subflows.length; i++) {
@ -542,6 +577,7 @@ RED.history = (function () {
});
}
// Add each links
if (ev.links) {
inverseEv.links = [];
for (let i = 0; i < ev.links.length; i++) {
@ -550,6 +586,7 @@ RED.history = (function () {
}
}
// Remove each links
if (ev.createdLinks) {
inverseEv.removedLinks = [];
for (let i = 0; i < ev.createdLinks.length; i++) {
@ -609,6 +646,7 @@ RED.history = (function () {
groups: []
};
// For each group, remove each nodes from the group then delete the group
if (ev.groups) {
for (let i = 0; i < ev.groups.length; i++) {
inverseEv.groups.push(ev.groups[i]);
@ -638,9 +676,12 @@ RED.history = (function () {
inverseEv.groups.push(ev.groups[i]);
const nodes = ev.groups[i].nodes.slice();
ev.groups[i].nodes = [];
// Create the group
RED.nodes.addGroup(ev.groups[i]);
// Add each nodes to the created group
RED.group.addToGroup(ev.groups[i], nodes);
if (ev.groups[i].g) {
// If the created group has a parent group, add to it
const parentGroup = RED.nodes.group(ev.groups[i].g);
if (parentGroup) {
RED.group.addToGroup(parentGroup, ev.groups[i]);
@ -670,6 +711,7 @@ RED.history = (function () {
reparent: ev.reparent
};
// Remove each nodes from the group
if (ev.nodes) {
RED.group.removeFromGroup(ev.group, ev.nodes, (ev.hasOwnProperty("reparent") && ev.hasOwnProperty("reparent") !== undefined) ? ev.reparent : true);
}
@ -695,6 +737,7 @@ RED.history = (function () {
reparent: ev.reparent
};
// Add each nodes to the group
if (ev.nodes) {
RED.group.addToGroup(ev.group, ev.nodes);
}
@ -706,12 +749,14 @@ RED.history = (function () {
* Called on the `edit` history event
* @param {object} ev The history event to undo
* @param {"edit"} ev.t The history event type
* @param {boolean} ev.changed
* @param {object} ev.changes
* @param {Array<Link>} [ev.createdLinks]
* @param {Array<Link>} [ev.links]
* @param {Node} ev.node
* @param {object} [ev.outputMap]
* @param {Subflow} [ev.subflow]
* @param {{ instances?: Array<Subflow>; inputCount?: number;
* outputCount?: number; status?: string; }} [ev.subflow]
* @returns {HistoryEvent} The generated history event to redo
*/
function onEdit(ev) {
@ -719,10 +764,12 @@ RED.history = (function () {
t: "edit",
changes: {},
changed: ev.node.changed,
dirty: RED.nodes.dirty()
dirty: RED.nodes.dirty(),
node: ev.node
};
inverseEv.node = ev.node;
// Apply old values to the current node
// And saves values changed by old values
for (const i in ev.changes) {
if (ev.changes.hasOwnProperty(i)) {
inverseEv.changes[i] = ev.node[i];
@ -757,6 +804,9 @@ RED.history = (function () {
ev.node[i] = ev.changes[i];
}
}
// The value of ev.node.changed is true (setted before to add to the history)
// During the undo, need to set the value the property had before it was set to true
ev.node.dirty = true;
ev.node.changed = ev.changed;
@ -768,13 +818,16 @@ RED.history = (function () {
default: eventType = "nodes"; break;
}
// Trigger the event after modifying the node
eventType += ":change";
RED.events.emit(eventType, ev.node);
// If it is a tab, show or hide the disabled icon
if (ev.node.type === "tab" && ev.changes.hasOwnProperty("disabled")) {
$("#red-ui-tab-" + (ev.node.id.replace(".", "-"))).toggleClass("red-ui-workspace-disabled", !!ev.node.disabled);
}
// If it is a tab, show or hide the locked icon
if (ev.node.type === "tab" && ev.changes.hasOwnProperty("locked")) {
$("#red-ui-tab-" + (ev.node.id.replace(".", "-"))).toggleClass("red-ui-workspace-locked", !!ev.node.locked);
}
@ -813,13 +866,16 @@ RED.history = (function () {
});
}
// Delete the current subflow status
if (ev.subflow.hasOwnProperty("status")) {
if (ev.subflow.status) {
delete ev.node.status;
}
}
// Validate the subflow (tab)
RED.editor.validateNode(ev.node);
// Update each subflow node and validate it
RED.nodes.filterNodes({ type: "subflow:" + ev.node.id }).forEach(function (n) {
n.inputs = ev.node.in.length;
n.outputs = ev.node.out.length;
@ -843,6 +899,7 @@ RED.history = (function () {
RED.editor.validateNode(ev.node);
}
// Add links previously removed (undo)
if (ev.links) {
inverseEv.createdLinks = [];
for (let i = 0; i < ev.links.length; i++) {
@ -851,6 +908,7 @@ RED.history = (function () {
}
}
// Remove links previously created (undo)
if (ev.createdLinks) {
inverseEv.links = [];
for (let i = 0; i < ev.createdLinks.length; i++) {