Skip to content

Commit

Permalink
update to the mindmap and mindhive nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Gerrit Riessen committed Nov 14, 2024
1 parent 000120a commit 69c8136
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 428 deletions.
391 changes: 1 addition & 390 deletions nodes/nodes.html
Original file line number Diff line number Diff line change
Expand Up @@ -4121,396 +4121,7 @@ <h4>Using environment variables</h4>

<!-- --- [red-module:@gorenje/node-red-mindmap/base] --- -->
<script type="text/javascript">
/*
* ~~Can use https://colordesigner.io/gradient-generator to generate gradient
* steps~~
*
* Use https://online-free-tools.com/en/css_color_hex_gradient instead, gradient
* generator is broken shit.
*/
window.wmPaletteColours = {
"50-topic": '#d0c9f6',

"30-observation": '#f4adf3',
"32-question": '#e0a4f3',
"35-thought": '#cb9cf3',

"25-idea": '#88baff',
"26-dream": '#86BDFF',
"41-metaphor": '#85C0FF',
"45-aphorism": '#84C3FF',
"20-poesie": '#82C6FF',
"22-humour": '#81C9FF',
"23-treasure": '#80CCFF',

"37-consequence": '#f6c1cc',
"38-advantage": '#efacbf',
"39-disadvantage": '#e796b1',

"05-text": '#c8ffb5',
"10-blog-post": '#CDFEBC',
"12-image": '#CDFEBC',
"15-comment": '#D2FDC3',
"55-code-base": '#D7FCCB',
"57-art": '#DCFBD2',
"47-learning": '#e1fbda',

"60-inspiration": '#dfdfb6',
"65-quote": '#E3E3BE',
"70-definition": '#E7E8C6',
"74-bookmark": '#ECECCE',
"75-book": '#F0F1D6',
"80-author": '#f5f6de',
};

/*
window.wmPaletteColours = {
"50-topic": '#fdfdfa',
"30-observation": '#fdfdfa',
"32-question": '#fdfdfa',
"35-thought": '#fdfdfa',
"25-idea": '#fdfdfa',
"40-analogy": '#fdfdfa',
"45-aphorism": '#fdfdfa',
"20-poesie": '#fdfdfa',
"22-humour": '#fdfdfa',
"23-treasure": '#fdfdfa',
"37-consequence": '#fdfdfa',
"38-advantage": '#fdfdfa',
"39-disadvantage": '#fdfdfa',
"05-text": '#fdfdfa',
"10-blog-post": '#fdfdfa',
"15-comment": '#fdfdfa',
"55-code-base": '#fdfdfa',
"56-sketch": '#fdfdfa',
"60-inspiration": '#fdfdfa',
"65-quote": '#fdfdfa',
"70-definition": '#fdfdfa',
"75-book": '#fdfdfa',
"80-author": '#fdfdfa',
};
*/
window.mmDefaults = {
category: 'mindmap',
_collection: 'writermap',
defaults: {
name: {
value:""
},
info: {
value:""
},

sumPass: {
value: false
},
sumPassPrio: {
value: 0,
},
sumPassNodeId: {
value: ""
},

/* createdAt and updatedAt are "internal" attributes that track just
that: when the node was created and the last time it was updated.
These aren't shown in the edit window because they are maintained
internally. These are managed by event handling in the sidebar JS
code.
*/
createdAt: {
value: "",
},
updatedAt: {
value: "",
},
},

inputs:1,
outputs:1,

labelStyle: function() {
return (this.name || this.info) ? "node_label_italic" : "";
},

info: function() {
return this.name ? "# "+this.name+"\n\n---\n\n" : "";
},

label: function() {
return ( (this.name ||
this.info.replace(/(.{40,60})([ \n\t])/g,"$1\\n$2")) ||
this._def.paletteLabel || this.type) +
(this.sumPassPrio && parseInt(this.sumPassPrio) != 0 ? " (" + this.sumPassPrio + ")" : "") +
(this.sumPass ? " ⭄" : "");
},

oneditprepare: function() {
var that = this;

this.editor = RED.editor.createEditor({
id: 'node-input-info-editor',
mode: 'ace/mode/markdown',
value: $("#node-input-info").val()
});
this.editor.focus();

writerMapUtils.fillSumPassPrioSelection(that);

if ( $('#node-input-sumPass').is(":checked") ) {
writerMapUtils.fillSumPassNodeSelection(that);
$('#sumpass-node-selection').show()
$('#node-input-sumPassNodeId').val(that.sumPassNodeId);
} else {
$('#sumpass-node-selection').hide()
}

$('#node-input-sumPass').on( 'change', function() {
if ( $('#node-input-sumPass').is(":checked") ) {
writerMapUtils.fillSumPassNodeSelection(that);
$('#sumpass-node-selection').show()
$('#node-input-sumPassNodeId').val(that.sumPassNodeId);
} else {
$('#sumpass-node-selection').hide()
}
});

$('#node-input-wordCount').html(
that.info ? that.info.split(/\s+/).filter(word => word !== '').length : 0
)

writerMapUtils.fillTypeDropDown(that);
},

oneditsave: function() {
$("#node-input-info").val(this.editor.getValue());
this.editor.destroy();
delete this.editor;

var newType = $('#node-input-typeDropdown').val();
if ( newType && newType != this.type ) {
var nde = RED.nodes.node(this.id);
nde.type = newType;

this.changed = true;
nde.dirty = true;

RED.nodes.dirty(true)
RED.view.redraw()
}
},

oneditcancel: function() {
this.editor.destroy();
delete this.editor;
},

oneditresize: function(size) {
var rows = $("#dialog-form>div:not(.node-text-editor-row)");
var height = $("#dialog-form").height();
for (var i=0; i<rows.length; i++) {
height -= $(rows[i]).outerHeight(true);
}
var editorRow = $("#dialog-form>div.node-text-editor-row");
height -= (parseInt(editorRow.css("marginTop"))+parseInt(editorRow.css("marginBottom")));
$(".node-text-editor").css("height",height+"px");
this.editor.resize();
}
};


const writerMapUtils = {
one: undefined,

fillSumPassPrioSelection: (that) => {
var sltObj = $('#node-input-sumPassPrio');
sltObj.html("");

for ( var idx = 20; idx > -21; idx-- ) {
sltObj.append($('<option></option>').val(idx).html(idx));
};

sltObj.val(that.sumPassPrio || 0);
},

fillSumPassNodeSelection: (nde) => {
var sltObj = $('#node-input-sumPassNodeId');
sltObj.html("");

sltObj.append(
$('<option></option>').val("").html(" -- All -- ")
);

RED.nodes.eachLink( function(lnk) {
if ( lnk.source.id == nde.id &&
lnk.target.d != true ) {
sltObj.append(
$('<option></option>').val(lnk.target.id).html(
( ( typeof lnk.target._def.label == "function") ?
lnk.target._def.label.call(lnk.target) :
"NO LABEL FOR " + lnk.target.id
)
)
);
}
});
},

addTargetToExternalLinks: function(el) {
$(el).find("a").each(function(el) {
var href = $(this).attr('href');
if (/^https?:/.test(href)) {
$(this).attr('target','_blank');
}
});
return el;
},

setInfoText: function(infoText,target) {
var info = writerMapUtils.addTargetToExternalLinks($('<div class="red-ui-help"><span class="red-ui-text-bidi-aware" dir=\"'+RED.text.bidi.resolveBaseTextDir(infoText)+'">'+infoText+'</span></div>')).appendTo(target);
info.find(".red-ui-text-bidi-aware").contents().filter(function() { return this.nodeType === 3 && this.textContent.trim() !== "" }).wrap( "<span></span>" );
var foldingHeader = "H3";
info.find(foldingHeader).wrapInner('<a class="red-ui-help-info-header expanded" href="#"></a>')
.find("a").prepend('<i class="fa fa-angle-right">').on("click", function(e) {
e.preventDefault();
var isExpanded = $(this).hasClass('expanded');
var el = $(this).parent().next();
while(el.length === 1 && el[0].nodeName !== foldingHeader) {
el.toggle(!isExpanded);
el = el.next();
}
$(this).toggleClass('expanded',!isExpanded);
})
},

allWriterMapTypes: function () {
var tes = []

RED.nodes.registry.getNodeList().forEach( nd => {
nd.types.forEach( typ => {
let typDef = RED.nodes.registry.getNodeType(typ) || {};
if ( typDef._collection == "writermap" ) {
tes.push( typ )
}
})
})

return tes;
},

fillTypeDropDown: function (nde) {
var sltObj = $('#node-input-typeDropdown');
sltObj.html("");

writerMapUtils.allWriterMapTypes().sort( (a,b) => a > b ).forEach( (typ) => {
sltObj.append(
$('<option></option>').val(typ).html(typ)
)
});

sltObj.val(nde.type);
}
};

// Hide the tip box underneath the info box - no one needs it!
setTimeout(function () {
if ( $(".red-ui-sidebar-info").hasClass('show-tips') ) {
RED.actions.invoke("core:toggle-show-tips")
}
}, 1250);

// This event is triggered once a node is highlighted or unhighlighted. Use
// it to show a popup (only on mobile) containing the info of the writermap
// node. On a desktop it shows the info box and makes it larger so that
// so the info is highlighted.
// To ensure that the "popup" with info is readable, the node is pushed to
// the front, causing the deploy button to become active. This is a hack
// to ensure that the popup is above other nodes. The popup is attached to the
// node in SVG so that the popup comes along when moving a node.
RED.events.on("view:selection-changed", function(selection) {
if ( writerMapUtils['one'] ) {
document.getElementById(writerMapUtils['one']).remove()
delete writerMapUtils['one'];
}

if ( selection.nodes && selection.nodes.length == 1 &&
selection.nodes[0]._def &&
selection.nodes[0]._def._collection == 'writermap' ) {

if ( !(RED.utils.getBrowserInfo().mobile > 0) && !window.matchMedia('only screen and (max-width: 890px)').matches ) {
// open the info box on desktop, only mobile shows the info box under
// the node.
// RED.sidebar.info.show()
$($('.red-ui-sidebar-info-stack > .red-ui-panel')[0]).css(
'height', '150px'
)
return;
}

var nde = selection.nodes[0];

var container = document.getElementById(nde.id);
if ( !container ) {
return
}

var bbbox = container.getBoundingClientRect();
var newDiv = document.createElement("div")

writerMapUtils['one'] = 'writermap-info-box-' + nde.id;

newDiv.setAttribute('class', 'red-ui-editor red-ui-panel')
newDiv.setAttribute('style', "flex: 1 1 auto; overflow-y: scroll;");
newDiv.setAttribute('xmlns', "http://www.w3.org/1999/xhtml" );
newDiv.setAttribute('pointer-events',"all");

$(newDiv).css('display', 'flex')

$(newDiv).css('height', '290')
$(newDiv).css('color', 'rgb(85,85,85)')
$(newDiv).css('border', '1px solid rgb(85,85,85)')
$(newDiv).css('background-color', 'white')

$(newDiv).css('border-radius', '6px');
$(newDiv).css('padding-bottom', '3px');
$(newDiv).css('padding-left', '6px');
$(newDiv).css('padding-right', '3px');
$(newDiv).css('padding-top', '3px');

var forObj = document.createElementNS("http://www.w3.org/2000/svg",
'foreignObject')
forObj.setAttribute('id', writerMapUtils['one'])
forObj.setAttribute('x', '0')
forObj.setAttribute('y', bbbox.height + 2)
forObj.setAttribute('width', bbbox.width );
forObj.setAttribute('height', "300" );
forObj.setAttribute('pointer-events',"all");

var infoText = "";

if (nde._def && nde._def.info) {
var info = nde._def.info;
var textInfo = (typeof info === "function" ? info.call(nde) : info);
infoText = infoText + RED.utils.renderMarkdown(textInfo);
}
if (nde.info) {
infoText = infoText + RED.utils.renderMarkdown(nde.info || "")
}

writerMapUtils.setInfoText(infoText, newDiv);

forObj.appendChild( newDiv );

// we add the foreignObject to the node container so that if the node
// is moved, the foreignObject is moved along with it. Alternative
// would be that if the node is moved while the popup div is being
// shown, the node would move and the popup would stay - not a good look.
container.insertBefore(forObj, container.lastChild.nextSibling)

// ensure that the popup is not obscured by other nodes, push the parent
// node to the front, making it be above all other nodes.
RED.actions.invoke("core:move-selection-to-front")
}
})
window.wmPaletteColours={"50-topic":"#d0c9f6","30-observation":"#f4adf3","32-question":"#e0a4f3","35-thought":"#cb9cf3","25-idea":"#88baff","26-dream":"#86BDFF","41-metaphor":"#85C0FF","45-aphorism":"#84C3FF","20-poesie":"#82C6FF","22-humour":"#81C9FF","23-treasure":"#80CCFF","37-consequence":"#f6c1cc","38-advantage":"#efacbf","39-disadvantage":"#e796b1","05-text":"#c8ffb5","10-blog-post":"#CDFEBC","12-image":"#CDFEBC","15-comment":"#D2FDC3","55-code-base":"#D7FCCB","57-art":"#DCFBD2","47-learning":"#e1fbda","60-inspiration":"#dfdfb6","65-quote":"#E3E3BE","70-definition":"#E7E8C6","74-bookmark":"#ECECCE","75-book":"#F0F1D6","80-author":"#f5f6de"},window.mmDefaults={category:"mindmap",_collection:"writermap",defaults:{name:{value:""},info:{value:""},sumPass:{value:!1},sumPassPrio:{value:0},sumPassNodeId:{value:""},createdAt:{value:""},updatedAt:{value:""}},inputs:1,outputs:1,labelStyle:function(){return this.name||this.info?"node_label_italic":""},info:function(){return this.name?"# "+this.name+"\n\n---\n\n":""},label:function(){return(this.name||this.info.replace(/(.{40,60})([ \n\t])/g,"$1\\n$2")||this._def.paletteLabel||this.type)+(this.sumPassPrio&&0!=parseInt(this.sumPassPrio)?" ("+this.sumPassPrio+")":"")+(this.sumPass?" ⭄":"")},oneditprepare:function(){var t=this;this.editor=RED.editor.createEditor({id:"node-input-info-editor",mode:"ace/mode/markdown",value:$("#node-input-info").val()}),this.editor.focus(),writerMapUtils.fillSumPassPrioSelection(t),$("#node-input-sumPass").is(":checked")?(writerMapUtils.fillSumPassNodeSelection(t),$("#sumpass-node-selection").show(),$("#node-input-sumPassNodeId").val(t.sumPassNodeId)):$("#sumpass-node-selection").hide(),$("#node-input-sumPass").on("change",function(){$("#node-input-sumPass").is(":checked")?(writerMapUtils.fillSumPassNodeSelection(t),$("#sumpass-node-selection").show(),$("#node-input-sumPassNodeId").val(t.sumPassNodeId)):$("#sumpass-node-selection").hide()}),$("#node-input-wordCount").html(t.info?t.info.split(/\s+/).filter(e=>""!==e).length:0),writerMapUtils.fillTypeDropDown(t),$("#node-input-typeDropdown").on("change",e=>{e&&e.preventDefault(),"Image"==$("#node-input-typeDropdown").val()&&(t.editor.getValue()||"").trim().match(/^https?:\/\/[^\t\s ]+$/)&&t.editor.setValue(`![img](${t.editor.getValue().trim()})`)})},oneditsave:function(){$("#node-input-info").val(this.editor.getValue()),this.editor.destroy(),delete this.editor;var e,t=$("#node-input-typeDropdown").val();t&&t!=this.type&&((e=RED.nodes.node(this.id)).type=t,this.changed=!0,e.dirty=!0,RED.nodes.dirty(!0),RED.view.redraw())},oneditcancel:function(){this.editor.destroy(),delete this.editor},oneditresize:function(e){for(var t=$("#dialog-form>div:not(.node-text-editor-row)"),i=$("#dialog-form").height(),o=0;o<t.length;o++)i-=$(t[o]).outerHeight(!0);var n=$("#dialog-form>div.node-text-editor-row");i-=parseInt(n.css("marginTop"))+parseInt(n.css("marginBottom")),$(".node-text-editor").css("height",i+"px"),this.editor.resize()}};let writerMapUtils={one:void 0,fillSumPassPrioSelection:e=>{var t=$("#node-input-sumPassPrio");t.html("");for(var i=20;-21<i;i--)t.append($("<option></option>").val(i).html(i));t.val(e.sumPassPrio||0)},fillSumPassNodeSelection:t=>{var i=$("#node-input-sumPassNodeId");i.html(""),i.append($("<option></option>").val("").html(" -- All -- ")),RED.nodes.eachLink(function(e){e.source.id==t.id&&1!=e.target.d&&i.append($("<option></option>").val(e.target.id).html("function"==typeof e.target._def.label?e.target._def.label.call(e.target):"NO LABEL FOR "+e.target.id))})},addTargetToExternalLinks:function(e){return $(e).find("a").each(function(e){var t=$(this).attr("href");/^https?:/.test(t)&&$(this).attr("target","_blank")}),e},setInfoText:function(e,t){e=writerMapUtils.addTargetToExternalLinks($('<div class="red-ui-help"><span class="red-ui-text-bidi-aware" dir="'+RED.text.bidi.resolveBaseTextDir(e)+'">'+e+"</span></div>")).appendTo(t);e.find(".red-ui-text-bidi-aware").contents().filter(function(){return 3===this.nodeType&&""!==this.textContent.trim()}).wrap("<span></span>");e.find("H3").wrapInner('<a class="red-ui-help-info-header expanded" href="#"></a>').find("a").prepend('<i class="fa fa-angle-right">').on("click",function(e){e.preventDefault();for(var t=$(this).hasClass("expanded"),i=$(this).parent().next();1===i.length&&"H3"!==i[0].nodeName;)i.toggle(!t),i=i.next();$(this).toggleClass("expanded",!t)})},allWriterMapTypes:function(){var t=[];return RED.nodes.registry.getNodeList().forEach(e=>{e.types.forEach(e=>{"writermap"==(RED.nodes.registry.getNodeType(e)||{})._collection&&t.push(e)})}),t},fillTypeDropDown:function(e){var t=$("#node-input-typeDropdown");t.html(""),writerMapUtils.allWriterMapTypes().sort((e,t)=>t<e).forEach(e=>{t.append($("<option></option>").val(e).html(e))}),t.val(e.type)}};setTimeout(function(){$(".red-ui-sidebar-info").hasClass("show-tips")&&RED.actions.invoke("core:toggle-show-tips")},1250),RED.events.on("view:selection-changed",function(e){var t,i,o,n,s;writerMapUtils.one&&(document.getElementById(writerMapUtils.one).remove(),delete writerMapUtils.one),e.nodes&&1==e.nodes.length&&e.nodes[0]._def&&"writermap"==e.nodes[0]._def._collection&&(0<RED.utils.getBrowserInfo().mobile||window.matchMedia("only screen and (max-width: 890px)").matches?(e=e.nodes[0],(t=document.getElementById(e.id))&&(n=t.getBoundingClientRect(),i=document.createElement("div"),writerMapUtils.one="writermap-info-box-"+e.id,i.setAttribute("class","red-ui-editor red-ui-panel"),i.setAttribute("style","flex: 1 1 auto; overflow-y: scroll;"),i.setAttribute("xmlns","http://www.w3.org/1999/xhtml"),i.setAttribute("pointer-events","all"),$(i).css("display","flex"),$(i).css("height","290"),$(i).css("color","rgb(85,85,85)"),$(i).css("border","1px solid rgb(85,85,85)"),$(i).css("background-color","white"),$(i).css("border-radius","6px"),$(i).css("padding-bottom","3px"),$(i).css("padding-left","6px"),$(i).css("padding-right","3px"),$(i).css("padding-top","3px"),(o=document.createElementNS("http://www.w3.org/2000/svg","foreignObject")).setAttribute("id",writerMapUtils.one),o.setAttribute("x","0"),o.setAttribute("y",n.height+2),o.setAttribute("width",n.width),o.setAttribute("height","300"),o.setAttribute("pointer-events","all"),n="",e._def&&e._def.info&&(s="function"==typeof(s=e._def.info)?s.call(e):s,n+=RED.utils.renderMarkdown(s)),e.info&&(n+=RED.utils.renderMarkdown(e.info||"")),writerMapUtils.setInfoText(n,i),o.appendChild(i),t.insertBefore(o,t.lastChild.nextSibling),RED.actions.invoke("core:move-selection-to-front"))):$($(".red-ui-sidebar-info-stack > .red-ui-panel")[0]).css("height","150px"))});
</script>

<!-- --- [red-module:@gorenje/node-red-mindmap/topic] --- -->
Expand Down
Loading

0 comments on commit 69c8136

Please sign in to comment.