Merge pull request #4666 from node-red/multiplayer-2

[multiplayer] Add user presence indicators
This commit is contained in:
Nick O'Leary
2024-05-03 16:52:50 +01:00
committed by GitHub
12 changed files with 590 additions and 156 deletions

View File

@@ -445,9 +445,12 @@ RED.popover = (function() {
return {
create: createPopover,
tooltip: function(target,content, action) {
tooltip: function(target,content, action, interactive) {
var label = function() {
var label = content;
if (typeof content === 'function') {
label = content()
}
if (action) {
var shortcut = RED.keyboard.getShortcut(action);
if (shortcut && shortcut.key) {
@@ -463,6 +466,7 @@ RED.popover = (function() {
size: "small",
direction: "bottom",
content: label,
interactive,
delay: { show: 750, hide: 50 }
});
popover.setContent = function(newContent) {

View File

@@ -112,16 +112,23 @@ RED.deploy = (function() {
RED.actions.add("core:set-deploy-type-to-modified-nodes",function() { RED.menu.setSelected("deploymenu-item-node",true); });
}
window.addEventListener('beforeunload', function (event) {
if (RED.nodes.dirty()) {
event.preventDefault();
event.stopImmediatePropagation()
event.returnValue = RED._("deploy.confirm.undeployedChanges");
return
}
})
RED.events.on('workspace:dirty',function(state) {
if (state.dirty) {
window.onbeforeunload = function() {
return RED._("deploy.confirm.undeployedChanges");
}
// window.onbeforeunload = function() {
// return
// }
$("#red-ui-header-button-deploy").removeClass("disabled");
} else {
window.onbeforeunload = null;
// window.onbeforeunload = null;
$("#red-ui-header-button-deploy").addClass("disabled");
}
});

View File

@@ -9,14 +9,27 @@ RED.view.annotations = (function() {
addAnnotation(evt.node.__pendingAnnotation__,evt);
delete evt.node.__pendingAnnotation__;
}
var badgeDX = 0;
var controlDX = 0;
for (var i=0,l=evt.el.__annotations__.length;i<l;i++) {
var annotation = evt.el.__annotations__[i];
let badgeRDX = 0;
let badgeLDX = 0;
for (let i=0,l=evt.el.__annotations__.length;i<l;i++) {
const annotation = evt.el.__annotations__[i];
if (annotations.hasOwnProperty(annotation.id)) {
var opts = annotations[annotation.id];
var showAnnotation = true;
var isBadge = opts.type === 'badge';
const opts = annotations[annotation.id];
let showAnnotation = true;
const isBadge = opts.type === 'badge';
if (opts.refresh !== undefined) {
let refreshAnnotation = false
if (typeof opts.refresh === "string") {
refreshAnnotation = !!evt.node[opts.refresh]
delete evt.node[opts.refresh]
} else if (typeof opts.refresh === "function") {
refreshAnnotation = opts.refresh(evnt.node)
}
if (refreshAnnotation) {
refreshAnnotationElement(annotation.id, annotation.node, annotation.element)
}
}
if (opts.show !== undefined) {
if (typeof opts.show === "string") {
showAnnotation = !!evt.node[opts.show]
@@ -29,17 +42,24 @@ RED.view.annotations = (function() {
}
if (isBadge) {
if (showAnnotation) {
var rect = annotation.element.getBoundingClientRect();
badgeDX += rect.width;
annotation.element.setAttribute("transform", "translate("+(evt.node.w-3-badgeDX)+", -8)");
badgeDX += 4;
}
} else {
if (showAnnotation) {
var rect = annotation.element.getBoundingClientRect();
annotation.element.setAttribute("transform", "translate("+(3+controlDX)+", -12)");
controlDX += rect.width + 4;
const rect = annotation.element.getBoundingClientRect();
let annotationX
if (!opts.align || opts.align === 'right') {
annotationX = evt.node.w - 3 - badgeRDX - rect.width
badgeRDX += rect.width + 4;
} else if (opts.align === 'left') {
annotationX = 3 + badgeLDX
badgeLDX += rect.width + 4;
}
annotation.element.setAttribute("transform", "translate("+annotationX+", -8)");
}
// } else {
// if (showAnnotation) {
// var rect = annotation.element.getBoundingClientRect();
// annotation.element.setAttribute("transform", "translate("+(3+controlDX)+", -12)");
// controlDX += rect.width + 4;
// }
}
} else {
annotation.element.parentNode.removeChild(annotation.element);
@@ -95,15 +115,25 @@ RED.view.annotations = (function() {
annotationGroup.setAttribute("class",opts.class || "");
evt.el.__annotations__.push({
id:id,
node: evt.node,
element: annotationGroup
});
var annotation = opts.element(evt.node);
refreshAnnotationElement(id, evt.node, annotationGroup)
evt.el.appendChild(annotationGroup);
}
function refreshAnnotationElement(id, node, annotationGroup) {
const opts = annotations[id];
const annotation = opts.element(node);
if (opts.tooltip) {
annotation.addEventListener("mouseenter", getAnnotationMouseEnter(annotation,evt.node,opts.tooltip));
annotation.addEventListener("mouseenter", getAnnotationMouseEnter(annotation, node, opts.tooltip));
annotation.addEventListener("mouseleave", annotationMouseLeave);
}
if (annotationGroup.hasChildNodes()) {
annotationGroup.removeChild(annotationGroup.firstChild)
}
annotationGroup.appendChild(annotation);
evt.el.appendChild(annotationGroup);
}

View File

@@ -401,6 +401,7 @@ RED.workspaces = (function() {
if (tab.type === "tab") {
workspaceTabCount--;
} else {
RED.events.emit("workspace:close",{workspace: tab.id})
hideStack.push(tab.id);
}
RED.menu.setDisabled("menu-item-workspace-delete",activeWorkspace === 0 || workspaceTabCount <= 1);