diff --git a/Gruntfile.js b/Gruntfile.js
index 05890225d..abe69aadd 100644
--- a/Gruntfile.js
+++ b/Gruntfile.js
@@ -116,6 +116,7 @@ module.exports = function(grunt) {
"editor/js/ui/common/searchBox.js",
"editor/js/ui/common/tabs.js",
"editor/js/ui/common/typedInput.js",
+ "editor/js/ui/utils.js",
"editor/js/ui/deploy.js",
"editor/js/ui/keyboard.js",
"editor/js/ui/workspaces.js",
diff --git a/editor/js/ui/utils.js b/editor/js/ui/utils.js
new file mode 100644
index 000000000..18eac2973
--- /dev/null
+++ b/editor/js/ui/utils.js
@@ -0,0 +1,271 @@
+/**
+ * Copyright 2016 IBM Corp.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ **/
+
+RED.utils = (function() {
+
+ function formatString(str) {
+ return str.replace(/\r?\n/g,"↵").replace(/\t/g,"→");
+ }
+
+ function buildMessageSummaryValue(value) {
+ var result;
+ if (Array.isArray(value)) {
+ result = $('').html('array['+value.length+']');
+ } else if (value === null) {
+ result = $('null');
+ } else if (typeof value === 'object') {
+ if (value.hasOwnProperty('type') && value.type === 'Buffer' && value.hasOwnProperty('data')) {
+ result = $('').html('buffer['+value.data.length+']');
+ } else if (value.hasOwnProperty('type') && value.type === 'array' && value.hasOwnProperty('data')) {
+ result = $('').html('array['+value.length+']');
+ } else {
+ result = $('object');
+ }
+ } else if (typeof value === 'string') {
+ subvalue = value;
+ if (subvalue.length > 30) {
+ subvalue = subvalue.substring(0,30)+"…";
+ }
+ result = $('').html('"'+formatString(subvalue)+'"');
+ } else {
+ result = $('').text(""+value);
+ }
+ return result;
+ }
+ function makeExpandable(el,onexpand) {
+ el.addClass("debug-message-expandable");
+ el.click(function(e) {
+ var parent = $(this).parent();
+ if (parent.hasClass('collapsed')) {
+ if (onexpand && !parent.hasClass('built')) {
+ onexpand();
+ parent.addClass('built');
+ }
+ parent.removeClass('collapsed');
+ } else {
+ parent.addClass('collapsed');
+ }
+ e.preventDefault();
+ });
+ }
+
+ function buildMessageElement(obj,key,typeHint,hideKey) {
+ var i;
+ var e;
+ var entryObj;
+ var header;
+ var headerHead;
+ var value,subvalue;
+ var element = $('');
+ if (!key) {
+ element.addClass("debug-message-top-level");
+ }
+
+ header = $('').appendTo(element);
+
+ if (key && !hideKey) {
+ $('').text(key).appendTo(header);
+ $(': ').appendTo(header);
+ }
+ entryObj = $('').appendTo(header);
+
+ var isArray = Array.isArray(obj);
+ var isArrayObject = false;
+ if (obj && typeof obj === 'object' && obj.hasOwnProperty('type') && obj.hasOwnProperty('data')) {
+ isArray = true;
+ isArrayObject = true;
+ }
+
+ if (obj === null || obj === undefined) {
+ $(''+obj+'').appendTo(entryObj);
+ } else if (typeof obj === 'string') {
+ element.addClass('collapsed');
+ $(' ').prependTo(header);
+ $('').html('"'+formatString(obj)+'"').appendTo(entryObj);
+ makeExpandable(header, function() {
+ $('').html(typeHint||'string').appendTo(header);
+ var row = $('
').appendTo(element);
+ $('').html(obj).appendTo(row);
+ });
+
+
+ } else if (typeof obj === 'number') {
+ e = $('').text(""+obj).appendTo(entryObj);
+ e.click(function(evt) {
+ var format = $(this).data('format');
+ if (format === 'hex') {
+ $(this).text(""+obj).data('format','dec');
+ } else {
+ $(this).text("0x"+(obj).toString(16)).data('format','hex');
+ }
+ evt.preventDefault();
+ });
+ } else if (isArray) {
+ element.addClass('collapsed');
+
+ var originalLength = obj.length;
+ if (typeHint) {
+ var m = /\[(\d+)\]/.exec(typeHint);
+ if (m) {
+ originalLength = parseInt(m[1]);
+ }
+ }
+ var data = obj;
+ var type = 'array';
+ if (isArrayObject) {
+ data = obj.data;
+ if (originalLength === undefined) {
+ originalLength = data.length;
+ }
+ type = obj.type.toLowerCase();
+ } else if (/buffer/.test(typeHint)) {
+ type = 'buffer';
+ }
+ var fullLength = data.length;
+
+ if (originalLength > 0) {
+ $(' ').prependTo(header);
+ var arrayRows = $('').appendTo(element);
+ element.addClass('debug-message-buffer-raw');
+ makeExpandable(header,function() {
+ if (!key) {
+ headerHead = $('').html(typeHint||(type+'['+originalLength+']')).appendTo(header);
+ }
+ if (type === 'buffer') {
+ var stringRow = $('').appendTo(element);
+ var sr = $('').appendTo(stringRow);
+ var stringEncoding = "";
+ try {
+ stringEncoding = String.fromCharCode.apply(null, new Uint16Array(data))
+ } catch(err) {
+ console.log(err);
+ }
+ $('').html(stringEncoding).appendTo(sr);
+ var bufferOpts = $('').appendTo(headerHead);
+ $('').addClass('selected').html('raw').appendTo(bufferOpts).click(function(e) {
+ if ($(this).text() === 'raw') {
+ $(this).text('string');
+ element.addClass('debug-message-buffer-string').removeClass('debug-message-buffer-raw');
+ } else {
+ $(this).text('raw');
+ element.removeClass('debug-message-buffer-string').addClass('debug-message-buffer-raw');
+ }
+ e.preventDefault();
+ e.stopPropagation();
+ })
+ }
+ var row;
+ if (fullLength <= 10) {
+ for (i=0;i').appendTo(arrayRows);
+ buildMessageElement(data[i],""+i,false).appendTo(row);
+ }
+ } else {
+ for (i=0;i').appendTo(arrayRows);
+ header = $('').appendTo(row);
+ $(' ').appendTo(header);
+ makeExpandable(header, (function() {
+ var min = minRange;
+ var max = Math.min(fullLength-1,(minRange+9));
+ var parent = row;
+ return function() {
+ for (var i=min;i<=max;i++) {
+ var row = $('').appendTo(parent);
+ buildMessageElement(data[i],""+i,false).appendTo(row);
+ }
+ }
+ })());
+ $('').html("["+minRange+" … "+Math.min(fullLength-1,(minRange+9))+"]").appendTo(header);
+ }
+ if (fullLength < originalLength) {
+ $('['+fullLength+' … '+originalLength+']
').appendTo(arrayRows);
+ }
+ }
+ });
+ }
+ if (key) {
+ headerHead = $('').html(typeHint||(type+'['+originalLength+']')).appendTo(entryObj);
+ } else {
+ headerHead = $('').appendTo(entryObj);
+ $('[ ').appendTo(headerHead);
+ var arrayLength = Math.min(originalLength,10);
+ for (i=0;i, ').appendTo(headerHead);
+ }
+ }
+ if (originalLength > arrayLength) {
+ $(' …').appendTo(headerHead);
+ }
+ if (arrayLength === 0) {
+ $('empty').appendTo(headerHead);
+ }
+ $(' ]').appendTo(headerHead);
+ }
+
+ } else if (typeof obj === 'object') {
+ element.addClass('collapsed');
+ var keys = Object.keys(obj);
+ if (key || keys.length > 0) {
+ $(' ').prependTo(header);
+ makeExpandable(header, function() {
+ if (!key) {
+ $('').html('object').appendTo(header);
+ }
+ for (i=0;i').appendTo(element);
+ buildMessageElement(obj[keys[i]],keys[i],false).appendTo(row);
+ }
+ if (keys.length === 0) {
+ $('').text("empty").appendTo(element);
+ }
+ });
+ }
+ if (key) {
+ $('').html('object').appendTo(entryObj);
+ } else {
+ headerHead = $('').appendTo(entryObj);
+ $('{ ').appendTo(headerHead);
+ var keysLength = Math.min(keys.length,5);
+ for (i=0;i').text(keys[i]).appendTo(headerHead);
+ $(': ').appendTo(headerHead);
+ buildMessageSummaryValue(obj[keys[i]]).appendTo(headerHead);
+ if (i < keysLength-1) {
+ $(', ').appendTo(headerHead);
+ }
+ }
+ if (keys.length > keysLength) {
+ $(' …').appendTo(headerHead);
+ }
+ if (keysLength === 0) {
+ $('empty').appendTo(headerHead);
+ }
+ $(' }').appendTo(headerHead);
+ }
+ } else {
+ $('').text(""+obj).appendTo(entryObj);
+ }
+ return element;
+ }
+
+ return {
+ createObjectElement: buildMessageElement,
+ }
+})();
diff --git a/nodes/core/core/lib/debug/style.css b/editor/sass/debug.scss
similarity index 86%
rename from nodes/core/core/lib/debug/style.css
rename to editor/sass/debug.scss
index 9cdb27d54..dcc72ce8a 100644
--- a/nodes/core/core/lib/debug/style.css
+++ b/editor/sass/debug.scss
@@ -1,3 +1,19 @@
+/**
+ * Copyright 2016 IBM Corp.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ **/
+
.debug-window {
padding:0;
margin:0;
diff --git a/editor/sass/style.scss b/editor/sass/style.scss
index 7479744ee..449849bf0 100644
--- a/editor/sass/style.scss
+++ b/editor/sass/style.scss
@@ -53,6 +53,7 @@
@import "keyboard";
+@import "debug";
body {
font-size: 14px;
diff --git a/nodes/core/core/58-debug.html b/nodes/core/core/58-debug.html
index c17e487a3..45d00f909 100644
--- a/nodes/core/core/58-debug.html
+++ b/nodes/core/core/58-debug.html
@@ -187,11 +187,9 @@
$("#debug-tab-open").click(function(e) {
e.preventDefault();
subWindow = window.open(document.location.toString().replace(/#.*$/,"")+"debug/view/view.html","nodeREDDebugView","menubar=no,location=no,toolbar=no,chrome,height=500,width=600");
- /*
- * Message format:
- *
- *
- */
+ subWindow.onload = function() {
+ subWindow.postMessage({event:"workspaceChange",activeWorkspace:RED.workspaces.active()},"*");
+ }
});
$(window).unload(function() {
@@ -256,4 +254,3 @@
});
})();
-
diff --git a/nodes/core/core/lib/debug/debug-utils.js b/nodes/core/core/lib/debug/debug-utils.js
index 5466622a4..edb1d6c37 100644
--- a/nodes/core/core/lib/debug/debug-utils.js
+++ b/nodes/core/core/lib/debug/debug-utils.js
@@ -1,3 +1,19 @@
+/**
+ * Copyright 2016 IBM Corp.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ **/
+
if (!RED) {
var RED = {}
}
@@ -12,13 +28,6 @@ RED.debug = (function() {
var sbc;
var activeWorkspace;
- /**
- * messageMouseEnter
- * messageMouseLeave
- * messageSourceClick
- * clear
- *
- */
function init(_config) {
config = _config;
@@ -169,251 +178,6 @@ RED.debug = (function() {
return str.replace(/\n/g,"↵").replace(/\t/g,"→");
}
- function buildMessageSummaryValue(value) {
- var result;
- if (Array.isArray(value)) {
- result = $('').html('array['+value.length+']');
- } else if (value === null) {
- result = $('null');
- } else if (typeof value === 'object') {
- if (value.hasOwnProperty('type') && value.type === 'Buffer' && value.hasOwnProperty('data')) {
- result = $('').html('buffer['+value.data.length+']');
- } else if (value.hasOwnProperty('type') && value.type === 'array' && value.hasOwnProperty('data')) {
- result = $('').html('array['+value.length+']');
- } else {
- result = $('object');
- }
- } else if (typeof value === 'string') {
- subvalue = value;
- if (subvalue.length > 30) {
- subvalue = subvalue.substring(0,30)+"…";
- }
- result = $('').html('"'+formatString(subvalue)+'"');
- } else {
- result = $('').text(""+value);
- }
- return result;
- }
- function makeExpandable(el,onexpand) {
- el.addClass("debug-message-expandable");
- el.click(function(e) {
- var parent = $(this).parent();
- if (parent.hasClass('collapsed')) {
- if (onexpand && !parent.hasClass('built')) {
- onexpand();
- parent.addClass('built');
- }
- parent.removeClass('collapsed');
- } else {
- parent.addClass('collapsed');
- }
- e.preventDefault();
- });
- }
-
- function buildMessageElement(obj,key,typeHint,hideKey) {
- var i;
- var e;
- var entryObj;
- var header;
- var headerHead;
- var value,subvalue;
- var element = $('');
- if (!key) {
- element.addClass("debug-message-top-level");
- }
-
- header = $('').appendTo(element);
-
- if (key && !hideKey) {
- $('').text(key).appendTo(header);
- $(': ').appendTo(header);
- }
- entryObj = $('').appendTo(header);
-
- var isArray = Array.isArray(obj);
- var isArrayObject = false;
- if (obj && typeof obj === 'object' && obj.hasOwnProperty('type') && obj.hasOwnProperty('data')) {
- isArray = true;
- isArrayObject = true;
- }
-
- if (obj === null || obj === undefined) {
- $(''+obj+'').appendTo(entryObj);
- } else if (typeof obj === 'string') {
- element.addClass('collapsed');
- $(' ').prependTo(header);
- $('').html('"'+formatString(obj)+'"').appendTo(entryObj);
- makeExpandable(header, function() {
- $('').html(typeHint||'string').appendTo(header);
- var row = $('').appendTo(element);
- $('').html(obj).appendTo(row);
- });
-
-
- } else if (typeof obj === 'number') {
- e = $('').text(""+obj).appendTo(entryObj);
- e.click(function(evt) {
- var format = $(this).data('format');
- if (format === 'hex') {
- $(this).text(""+obj).data('format','dec');
- } else {
- $(this).text("0x"+(obj).toString(16)).data('format','hex');
- }
- evt.preventDefault();
- });
- } else if (isArray) {
- element.addClass('collapsed');
-
- var originalLength = obj.length;
- if (typeHint) {
- var m = /\[(\d+)\]/.exec(typeHint);
- if (m) {
- originalLength = parseInt(m[1]);
- }
- }
- var data = obj;
- var type = 'array';
- if (isArrayObject) {
- data = obj.data;
- if (originalLength === undefined) {
- originalLength = data.length;
- }
- type = obj.type.toLowerCase();
- } else if (/buffer/.test(typeHint)) {
- type = 'buffer';
- }
- var fullLength = data.length;
-
- if (originalLength > 0) {
- $(' ').prependTo(header);
- var arrayRows = $('').appendTo(element);
- element.addClass('debug-message-buffer-raw');
- makeExpandable(header,function() {
- if (!key) {
- headerHead = $('').html(typeHint||(type+'['+originalLength+']')).appendTo(header);
- }
- if (type === 'buffer') {
- var stringRow = $('').appendTo(element);
- var sr = $('').appendTo(stringRow);
- var stringEncoding = "";
- try {
- stringEncoding = String.fromCharCode.apply(null, new Uint16Array(data))
- } catch(err) {
- console.log(err);
- }
- $('').html(stringEncoding).appendTo(sr);
- var bufferOpts = $('').appendTo(headerHead);
- $('').addClass('selected').html('raw').appendTo(bufferOpts).click(function(e) {
- if ($(this).text() === 'raw') {
- $(this).text('string');
- element.addClass('debug-message-buffer-string').removeClass('debug-message-buffer-raw');
- } else {
- $(this).text('raw');
- element.removeClass('debug-message-buffer-string').addClass('debug-message-buffer-raw');
- }
- e.preventDefault();
- e.stopPropagation();
- })
- }
- var row;
- if (fullLength <= 10) {
- for (i=0;i').appendTo(arrayRows);
- buildMessageElement(data[i],""+i,false).appendTo(row);
- }
- } else {
- for (i=0;i').appendTo(arrayRows);
- header = $('').appendTo(row);
- $(' ').appendTo(header);
- makeExpandable(header, (function() {
- var min = minRange;
- var max = Math.min(fullLength-1,(minRange+9));
- var parent = row;
- return function() {
- for (var i=min;i<=max;i++) {
- var row = $('').appendTo(parent);
- buildMessageElement(data[i],""+i,false).appendTo(row);
- }
- }
- })());
- $('').html("["+minRange+" … "+Math.min(fullLength-1,(minRange+9))+"]").appendTo(header);
- }
- if (fullLength < originalLength) {
- $('['+fullLength+' … '+originalLength+']
').appendTo(arrayRows);
- }
- }
- });
- }
- if (key) {
- headerHead = $('').html(typeHint||(type+'['+originalLength+']')).appendTo(entryObj);
- } else {
- headerHead = $('').appendTo(entryObj);
- $('[ ').appendTo(headerHead);
- var arrayLength = Math.min(originalLength,10);
- for (i=0;i, ').appendTo(headerHead);
- }
- }
- if (originalLength > arrayLength) {
- $(' …').appendTo(headerHead);
- }
- if (arrayLength === 0) {
- $('empty').appendTo(headerHead);
- }
- $(' ]').appendTo(headerHead);
- }
-
- } else if (typeof obj === 'object') {
- element.addClass('collapsed');
- var keys = Object.keys(obj);
- if (key || keys.length > 0) {
- $(' ').prependTo(header);
- makeExpandable(header, function() {
- if (!key) {
- $('').html('object').appendTo(header);
- }
- for (i=0;i').appendTo(element);
- buildMessageElement(obj[keys[i]],keys[i],false).appendTo(row);
- }
- if (keys.length === 0) {
- $('').text("empty").appendTo(element);
- }
- });
- }
- if (key) {
- $('').html('object').appendTo(entryObj);
- } else {
- headerHead = $('').appendTo(entryObj);
- $('{ ').appendTo(headerHead);
- var keysLength = Math.min(keys.length,5);
- for (i=0;i').text(keys[i]).appendTo(headerHead);
- $(': ').appendTo(headerHead);
- buildMessageSummaryValue(obj[keys[i]]).appendTo(headerHead);
- if (i < keysLength-1) {
- $(', ').appendTo(headerHead);
- }
- }
- if (keys.length > keysLength) {
- $(' …').appendTo(headerHead);
- }
- if (keysLength === 0) {
- $('empty').appendTo(headerHead);
- }
- $(' }').appendTo(headerHead);
- }
- } else {
- $('').text(""+obj).appendTo(entryObj);
- }
- return element;
- }
-
function handleDebugMessage(o) {
var msg = document.createElement("div");
@@ -479,7 +243,7 @@ RED.debug = (function() {
}
}
var el = $('').appendTo(msg);
- buildMessageElement(payload,/*true*/null,format).appendTo(el);
+ RED.utils.createObjectElement(payload,/*true*/null,format).appendTo(el);
var atBottom = (sbc.scrollHeight-messageList.height()-sbc.scrollTop) < 5;
var m = {
el: msg
@@ -514,7 +278,6 @@ RED.debug = (function() {
}
return {
init: init,
- buildMessageElement: buildMessageElement,
refreshMessageList:refreshMessageList,
handleDebugMessage: handleDebugMessage
}
diff --git a/nodes/core/core/lib/debug/view.html b/nodes/core/core/lib/debug/view.html
index e63be7aad..964f633f5 100644
--- a/nodes/core/core/lib/debug/view.html
+++ b/nodes/core/core/lib/debug/view.html
@@ -1,13 +1,13 @@
-
Node-RED Debug Tools
-
+
+