@gregoriusrippenstein/node-red-contrib-introspection 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md
CHANGED
|
@@ -67,7 +67,7 @@ This is a hack that uses the `onpaletteadd` callback to do its magic. If this fu
|
|
|
67
67
|
|
|
68
68
|
### DrawSVG
|
|
69
69
|
|
|
70
|
-
A node for inserting an SVG image into the workspace. The image is layered above the grid but below nodes and their connections.
|
|
70
|
+
A node for inserting an SVG image into the workspace. The image is layered above the grid but below nodes and their connections. The input message must contain SVG data (in string form) in the `payload` attribute.
|
|
71
71
|
|
|
72
72
|
## Examples
|
|
73
73
|
|
|
@@ -76,6 +76,7 @@ There are [example flows](/examples) contained in the package, examples can also
|
|
|
76
76
|
- [Orphans](https://demo.openmindmap.org/omm/#flow/3ebb65fdbecb182e/n/2be3f8794979d47b) - node is top left of flow or search for `type:Orphans`
|
|
77
77
|
- [Seeker](https://demo.openmindmap.org/omm/#flow/40ea5f2aea6592ae/n/b5f189a78d829197) - top left and the [Sink](https://demo.openmindmap.org/omm/#flow/459c271a96458c7c/n/e3262d9d2791ab78) - top right
|
|
78
78
|
- [Screenshot](https://demo.openmindmap.org/omm/#flow/4e2d8c13066b705e/n/499b1383580831aa) - top left
|
|
79
|
+
- [DrawSVG](https://demo.openmindmap.org/omm/#flow/6c8ce462533a1da4/n/248f2edd3d8acd96)
|
|
79
80
|
|
|
80
81
|
Example screenshot:
|
|
81
82
|
|
|
Binary file
|
package/nodes/15-screenshot.html
CHANGED
|
@@ -5,11 +5,22 @@
|
|
|
5
5
|
//
|
|
6
6
|
var origSvg = $($('svg')[0]);
|
|
7
7
|
|
|
8
|
+
// the DOMParser of Firefox does not like foreignObjects, so remove them.
|
|
9
|
+
// Correction: DOMParser doesn't mind foreignObjects as long as there is
|
|
10
|
+
// any HTML/<img>-tags in the foreignObjects.,,, of course, image tags
|
|
11
|
+
// rarely occur but nonetheless. foreighObjects are used to display divs
|
|
12
|
+
// within SVGs that contain html code to be displayed in the browser. So
|
|
13
|
+
// we assume that the foreignObject is not relevant for exporting as its
|
|
14
|
+
// content is specifically for the browser user.
|
|
15
|
+
var preParseSvg = origSvg.clone();
|
|
16
|
+
preParseSvg.find("foreignObject").remove();
|
|
17
|
+
|
|
8
18
|
var hwAttrs = (
|
|
9
19
|
'width="' + origSvg.attr('width') + '" height="' +
|
|
10
20
|
origSvg.attr('height') + '"'
|
|
11
21
|
);
|
|
12
22
|
|
|
23
|
+
// redefine the svgHeader because we need to include the xml namespaces
|
|
13
24
|
var svgHeader = (
|
|
14
25
|
'<?xml version="1.0" standalone="no"?>\r\n' +
|
|
15
26
|
'<svg ' + hwAttrs + ' pointer-events="all" style="cursor: crosshair; '+
|
|
@@ -17,9 +28,10 @@
|
|
|
17
28
|
'xmlns:xlink="http://www.w3.org/1999/xlink">\r\n'
|
|
18
29
|
);
|
|
19
30
|
|
|
20
|
-
var svgBody =
|
|
31
|
+
var svgBody = preParseSvg.html();
|
|
21
32
|
|
|
22
33
|
var parser = new DOMParser();
|
|
34
|
+
|
|
23
35
|
var doc = parser.parseFromString(svgHeader + svgBody + '\r\n</svg>',
|
|
24
36
|
"image/svg+xml");
|
|
25
37
|
|
|
@@ -50,7 +62,7 @@
|
|
|
50
62
|
opa: rgb4[4]
|
|
51
63
|
}
|
|
52
64
|
} else {
|
|
53
|
-
console.log( "Screenshot node:
|
|
65
|
+
console.log( "Screenshot node: returned unknown color: " + rgb );
|
|
54
66
|
return rgb;
|
|
55
67
|
}
|
|
56
68
|
}
|
|
@@ -216,6 +228,44 @@
|
|
|
216
228
|
}
|
|
217
229
|
};
|
|
218
230
|
|
|
231
|
+
/*
|
|
232
|
+
When the server side of this node is triggered, it posts a message on
|
|
233
|
+
the communication channel. The frontend node captures that message,
|
|
234
|
+
generates an SVG and posts that to the POST endpoint (that is assumed)
|
|
235
|
+
to be running. If not, there will be a console error.
|
|
236
|
+
*/
|
|
237
|
+
RED.comms.subscribe('introspect:screenshot-timer-tripped', (event,data) => {
|
|
238
|
+
if ( data.msg == "timer-tripped" ) {
|
|
239
|
+
|
|
240
|
+
if ( data.notification != "off" ) {
|
|
241
|
+
RED.notify("Screenshot triggered", { type: "warning" });
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
var notification = data.notification;
|
|
245
|
+
nr_intro_generate_svg( (svgdata) => {
|
|
246
|
+
// TODO the post will hit a 'Request too large' limit with the
|
|
247
|
+
// TODO SVG gets larger than XX-MB (got this when an svg of 5.5MB
|
|
248
|
+
// TODO but an svg with 4.1MB went through). No immediate fix, would
|
|
249
|
+
// TODO good to create parts that can be manually joined using the
|
|
250
|
+
// TODO 'join' node.
|
|
251
|
+
$.ajax({
|
|
252
|
+
type: "POST",
|
|
253
|
+
url: "/screenshot",
|
|
254
|
+
data: {
|
|
255
|
+
...data,
|
|
256
|
+
d: svgdata
|
|
257
|
+
},
|
|
258
|
+
complete: (_ignore) => {
|
|
259
|
+
if ( notification != "off" ) {
|
|
260
|
+
RED.notify("Screenshot posted", { type: "success" });
|
|
261
|
+
}
|
|
262
|
+
},
|
|
263
|
+
dataType: "image/svg+xml;charset=utf-8"
|
|
264
|
+
});
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
|
|
219
269
|
RED.nodes.registerType('Screenshot',{
|
|
220
270
|
color: '#e5e4ef',
|
|
221
271
|
icon: "font-awesome/fa-camera",
|
|
@@ -237,47 +287,6 @@
|
|
|
237
287
|
},
|
|
238
288
|
|
|
239
289
|
labelStyle: function() {
|
|
240
|
-
/*
|
|
241
|
-
because there is not a better hook to connect up the event
|
|
242
|
-
listener, misuse the label styling for this. Also don't register a
|
|
243
|
-
new listener each time, maintain only one listener by removing and
|
|
244
|
-
readding.
|
|
245
|
-
*/
|
|
246
|
-
var that = this;
|
|
247
|
-
var functName = "introspect:" + that.id;
|
|
248
|
-
|
|
249
|
-
if ( !window[functName] ) {
|
|
250
|
-
window[functName] = (e,m) => {
|
|
251
|
-
if ( m.msg == "timer-tripped" ) {
|
|
252
|
-
|
|
253
|
-
if ( m.notification != "off" ) {
|
|
254
|
-
RED.notify("Screenshot triggered", { type: "warning" });
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
var notification = m.notification;
|
|
258
|
-
nr_intro_generate_svg( (svgdata) => {
|
|
259
|
-
$.ajax({
|
|
260
|
-
type: "POST",
|
|
261
|
-
url: "/screenshot",
|
|
262
|
-
data: {
|
|
263
|
-
...m,
|
|
264
|
-
d: svgdata
|
|
265
|
-
},
|
|
266
|
-
complete: (data) => {
|
|
267
|
-
if ( notification != "off" ) {
|
|
268
|
-
RED.notify("Screenshot posted", { type: "success" });
|
|
269
|
-
}
|
|
270
|
-
},
|
|
271
|
-
dataType: "image/svg+xml;charset=utf-8"
|
|
272
|
-
});
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
RED.comms.unsubscribe(functName, window[functName]);
|
|
279
|
-
RED.comms.subscribe(functName, window[functName] );
|
|
280
|
-
|
|
281
290
|
return this.name?"node_label_italic":"";
|
|
282
291
|
},
|
|
283
292
|
|
package/nodes/15-screenshot.js
CHANGED
|
@@ -10,10 +10,12 @@ module.exports = function(RED) {
|
|
|
10
10
|
});
|
|
11
11
|
|
|
12
12
|
node.on("input", function(msg, send, done) {
|
|
13
|
-
RED.comms.publish("introspect:"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
RED.comms.publish("introspect:screenshot-timer-tripped",
|
|
14
|
+
RED.util.encodeObject({
|
|
15
|
+
...msg,
|
|
16
|
+
msg: "timer-tripped",
|
|
17
|
+
})
|
|
18
|
+
);
|
|
17
19
|
|
|
18
20
|
node.status({ fill: "green", shape: "dot", text: "Taking screenshot" });
|
|
19
21
|
setTimeout( () => { node.status({}) }, 1432 );
|
package/nodes/40-drawsvg.html
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
<script type="text/javascript">
|
|
2
|
+
RED.comms.subscribe("introspect:drawsvg", (event,data) => {
|
|
3
|
+
if ( data.msg == "svgdata" ) {
|
|
4
|
+
$($($('svg')[0]).find('> g > g > g')[2]).append(data.payload);
|
|
5
|
+
}
|
|
6
|
+
});
|
|
7
|
+
|
|
2
8
|
RED.nodes.registerType('DrawSVG',{
|
|
3
9
|
color: '#e5e4ef',
|
|
4
10
|
icon: "font-awesome/fa-image",
|
|
@@ -16,26 +22,6 @@
|
|
|
16
22
|
},
|
|
17
23
|
|
|
18
24
|
labelStyle: function() {
|
|
19
|
-
/*
|
|
20
|
-
because there is not a better hook to connect up the event
|
|
21
|
-
listener, misuse the label styling for this. Also don't register a
|
|
22
|
-
new listener each time, maintain only one listener by removing and
|
|
23
|
-
readding.
|
|
24
|
-
*/
|
|
25
|
-
var that = this;
|
|
26
|
-
var functName = "introspect:" + that.id;
|
|
27
|
-
|
|
28
|
-
if ( !window[functName] ) {
|
|
29
|
-
window[functName] = (e,m) => {
|
|
30
|
-
if ( m.msg == "svgdata" ) {
|
|
31
|
-
$($($('svg')[0]).find('> g > g > g')[2]).append(m.payload);
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
RED.comms.unsubscribe(functName, window[functName]);
|
|
37
|
-
RED.comms.subscribe(functName, window[functName] );
|
|
38
|
-
|
|
39
25
|
return this.name?"node_label_italic":"";
|
|
40
26
|
},
|
|
41
27
|
});
|
package/nodes/40-drawsvg.js
CHANGED
|
@@ -10,7 +10,7 @@ module.exports = function(RED) {
|
|
|
10
10
|
});
|
|
11
11
|
|
|
12
12
|
node.on("input", function(msg, send, done) {
|
|
13
|
-
RED.comms.publish("introspect:"
|
|
13
|
+
RED.comms.publish("introspect:drawsvg", RED.util.encodeObject({
|
|
14
14
|
...msg,
|
|
15
15
|
msg: "svgdata",
|
|
16
16
|
}));
|