UNPKG

node-red-contrib-uibuilder

Version:

Easily create web UI's for Node-RED using any (or no) front-end library. VueJS and bootstrap-vue included but change as desired.

40 lines (36 loc) 1.44 kB
/* jshint browser: true, esversion: 5, asi: true */ /* globals uibuilder */ // @ts-nocheck // return formatted HTML version of JSON object function syntaxHighlight(json) { json = JSON.stringify(json, undefined, 4) json = json.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;') json = json.replace(/("(\\u[a-zA-Z0-9]{4}|\\[^u]|[^\\"])*"(\s*:)?|\b(true|false|null)\b|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?)/g, function (match) { var cls = 'number' if (/^"/.test(match)) { if (/:$/.test(match)) { cls = 'key' } else { cls = 'string' } } else if (/true|false/.test(match)) { cls = 'boolean' } else if (/null/.test(match)) { cls = 'null' } return '<span class="' + cls + '">' + match + '</span>' }) return json } // --- End of syntaxHighlight --- // // run this function when the document is loaded window.onload = function() { // Start up uibuilder - see the docs for the optional parameters uibuilder.start() // Listen for incoming messages from Node-RED uibuilder.onChange('msg', function(msg){ console.info('[indexjs:uibuilder.onChange] msg received from Node-RED server:', msg) // dump the msg as text to the "msg" html element const eMsg = document.getElementById('msg') eMsg.innerHTML = syntaxHighlight(msg) }) }