@dualbox/editor 1.0.1 → 1.0.3

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.
Files changed (43) hide show
  1. package/js/src/GraphEditor.js +159 -0
  2. package/js/src/c/GraphController.js +646 -0
  3. package/js/src/libs/CodeMirror.js +8 -0
  4. package/js/src/libs/fontawesome.js +1 -0
  5. package/js/src/libs/jsoneditor.css +2 -0
  6. package/js/src/libs/jsoneditor.js +4 -0
  7. package/js/src/m/DualboxUtils.js +35 -0
  8. package/js/src/m/GraphModel.js +2167 -0
  9. package/js/src/m/History.js +94 -0
  10. package/js/src/m/Merger.js +357 -0
  11. package/js/src/v/AppManager.js +61 -0
  12. package/js/src/v/CanvasSizeHandler.js +136 -0
  13. package/js/src/v/ContextMenu.css +45 -0
  14. package/js/src/v/ContextMenu.js +239 -0
  15. package/js/src/v/GraphView.js +928 -0
  16. package/js/src/v/PlumbStyle.js +254 -0
  17. package/js/src/v/Selector.js +239 -0
  18. package/js/src/v/TemplateManager.js +79 -0
  19. package/js/src/v/Translater.js +174 -0
  20. package/js/src/v/Utils.js +7 -0
  21. package/js/src/v/Zoomer.js +201 -0
  22. package/js/src/v/templates/addNode.css +45 -0
  23. package/js/src/v/templates/addNode.html +62 -0
  24. package/js/src/v/templates/addNode.js +34 -0
  25. package/js/src/v/templates/debugNodeInfos.css +5 -0
  26. package/js/src/v/templates/debugNodeInfos.html +336 -0
  27. package/js/src/v/templates/debugNodeInfos.js +31 -0
  28. package/js/src/v/templates/editMainSettings.css +67 -0
  29. package/js/src/v/templates/editMainSettings.html +265 -0
  30. package/js/src/v/templates/editMainSettings.js +240 -0
  31. package/js/src/v/templates/editNodeSettings.css +86 -0
  32. package/js/src/v/templates/editNodeSettings.html +539 -0
  33. package/js/src/v/templates/editNodeSettings.js +356 -0
  34. package/js/src/v/templates/graphNode.css +333 -0
  35. package/js/src/v/templates/graphNode.html +227 -0
  36. package/js/src/v/templates/graphNode.js +412 -0
  37. package/js/src/v/templates/main.css +353 -0
  38. package/js/src/v/templates/main.html +149 -0
  39. package/js/src/v/templates/main.js +511 -0
  40. package/js/src/v/templates/searchResults.css +50 -0
  41. package/js/src/v/templates/searchResults.html +46 -0
  42. package/js/src/v/templates/searchResults.js +176 -0
  43. package/package.json +3 -2
@@ -0,0 +1,254 @@
1
+
2
+ /**
3
+ * Style of JSPlumb
4
+ */
5
+
6
+ class GraphStyle {
7
+ constructor(v) {
8
+ this.v = v;
9
+
10
+ this.eventConnectorData = {
11
+ connector: [
12
+ "Straight",//"Flowchart",
13
+ { curviness:60, stub: 5, gap: 0, cornerRadius: 5, alwaysRespectStubs: false }
14
+ ],
15
+ paintStyle : {
16
+ lineWidth: 2,
17
+ strokeStyle: "#004d00",
18
+ joinstyle: "round",
19
+ outlineWidth: 0
20
+ },
21
+ hoverStyle :{
22
+ lineWidth: 2,
23
+ strokeStyle: "#003300"
24
+ },
25
+ overlays:[
26
+ //[ "Arrow", { width:10, length:30, location:1, id:"arrow" } ],
27
+ ]
28
+ }
29
+
30
+ // This should be all put in a connector type, but I don't manage to
31
+ // make it work in plumb..
32
+ this.connectorData = {
33
+ connector: [
34
+ "Bezier",//"Flowchart",
35
+ { curviness:60, stub: 5, gap: 0, cornerRadius: 5, alwaysRespectStubs: false }
36
+ ],
37
+ paintStyle : {
38
+ lineWidth: 4,
39
+ strokeStyle: "#88898a",
40
+ joinstyle: "round",
41
+ outlineWidth: 0
42
+ },
43
+ hoverStyle :{
44
+ lineWidth: 4,
45
+ strokeStyle: "#0079bf"
46
+ }
47
+ };
48
+
49
+ this.splittedConnectorData = {
50
+ connector: [
51
+ "Straight",//"Flowchart",
52
+ { curviness:60, stub: 5, gap: 0, cornerRadius: 5, alwaysRespectStubs: false }
53
+ ],
54
+ paintStyle : {
55
+ lineWidth: 4,
56
+ strokeStyle: "#88898a",
57
+ joinstyle: "round",
58
+ outlineWidth: 0
59
+ },
60
+ hoverStyle :{
61
+ lineWidth: 4,
62
+ strokeStyle: "#0079bf"
63
+ }
64
+ }
65
+
66
+ this.endpointData = {
67
+ hoverStyle : {
68
+ fillStyle: "#c2c2c2",
69
+ strokeStyle: "#727272"
70
+ }
71
+ };
72
+
73
+ this.eventEndpointData = {
74
+ hoverStyle : {
75
+ fillStyle: "#c2c2c2",
76
+ strokeStyle: "#003300"
77
+ }
78
+ };
79
+
80
+ this.inputEndpoint = {
81
+ endpoint: "Dot",
82
+ paintStyle: {
83
+ fillStyle: "#ffffff",
84
+ radius: 5,
85
+ strokeStyle: "#727272",
86
+ lineWidth: 2
87
+ },
88
+ //connector: this.connectorData.connector,
89
+ connectorOverlays:this.connectorData.overlays,
90
+ connectorStyle: this.connectorData.paintStyle,
91
+ connectorHoverStyle: this.connectorData.hoverStyle,
92
+ hoverPaintStyle: this.endpointData.hoverStyle,
93
+ connectorClass: 'data-connection',
94
+ cssClass: 'data-connection',
95
+ maxConnections: 1,
96
+ dropOptions: { hoverClass: "hover", activeClass: "active" },
97
+ overlays: [
98
+ [ "Label",
99
+ { location: [1, 1],
100
+ id:"tip",
101
+ label: "Type : -type- /n Descrpition : -desc-",
102
+ cssClass: "alert alert-warning fade show inoutEndpointLabel",
103
+ visible:false
104
+ }
105
+ ]
106
+ ]
107
+ };
108
+
109
+ this.outputEndpoint = {
110
+ endpoint: "Dot",
111
+ paintStyle: {
112
+ fillStyle: "#ffffff",
113
+ radius: 5,
114
+ strokeStyle: "#727272",
115
+ lineWidth: 2
116
+ },
117
+ //connector: this.connectorData.connector,
118
+ connectorOverlays:this.connectorData.overlays,
119
+ connectorStyle: this.connectorData.paintStyle,
120
+ connectorHoverStyle: this.connectorData.hoverStyle,
121
+ connectorClass: 'data-connection',
122
+ cssClass: 'data-connection',
123
+ hoverPaintStyle: this.endpointData.hoverStyle,
124
+ maxConnections: -1,
125
+ dragOptions: {},
126
+ overlays: [
127
+ [ "Label",
128
+ { location: [1, 1],
129
+ id:"tip",
130
+ label: "Type : -type- /n Descrpition : -desc-",
131
+ cssClass: "alert alert-warning fade show inoutEndpointLabel",
132
+ visible:false
133
+ }
134
+ ]
135
+ ]
136
+ };
137
+
138
+ this.eventEndpoint = {
139
+ endpoint: "Dot",
140
+ anchors: [ "Perimeter", { shape:"Square" } ],
141
+ paintStyle: {
142
+ fillStyle: "#fff",
143
+ radius: 5,
144
+ strokeStyle: "#004d00",
145
+ lineWidth: 2
146
+ },
147
+ connector: this.eventConnectorData.connector,
148
+ connectorOverlays:this.eventConnectorData.overlays,
149
+ connectorStyle: this.eventConnectorData.paintStyle,
150
+ connectorHoverStyle: this.eventConnectorData.hoverStyle,
151
+ connectorClass: 'endpoint-connection',
152
+ cssClass: 'endpoint-connection',
153
+ hoverPaintStyle: this.eventEndpointData.hoverStyle,
154
+ maxConnections: -1,
155
+ dragOptions: {},
156
+ overlays: [
157
+ [ "Label",
158
+ { location: [1, 1],
159
+ id:"tip",
160
+ label: "Type : -type- /n Descrpition : -desc-",
161
+ cssClass: "alert alert-warning fade show inoutEndpointLabel",
162
+ visible:false
163
+ }
164
+ ]
165
+ ]
166
+ }
167
+
168
+ this.dataLineSplitterEndpoint = {
169
+ endpoint: "Dot",
170
+ paintStyle: {
171
+ fillStyle: "#727272",
172
+ radius: 3,
173
+ strokeStyle: "#727272",
174
+ lineWidth: 2
175
+ },
176
+ hoverPaintStyle: this.endpointData.hoverStyle,
177
+ maxConnections: 1,
178
+ };
179
+
180
+ this.eventLineSplitterEndpoint = {
181
+ endpoint: "Dot",
182
+ paintStyle: {
183
+ fillStyle: "#004d00",
184
+ radius: 3,
185
+ strokeStyle: "#004d00",
186
+ lineWidth: 2
187
+ },
188
+ hoverPaintStyle: this.eventEndpointData.hoverStyle,
189
+ maxConnections: 1,
190
+ }
191
+
192
+ }
193
+
194
+ // default settings for jsPlumb
195
+ setDefault() {
196
+ this.v.jsPlumbInstance.importDefaults({
197
+ Connector: [
198
+ "Bezier",//"Flowchart",
199
+ { curviness:50, stub: 5, gap: 0, cornerRadius: 5, alwaysRespectStubs: false }
200
+ ],
201
+ });
202
+ }
203
+
204
+ hideType( arg ) {
205
+ if( typeof arg === "string" ) {
206
+ var endpoint = this.v.jsPlumbInstance.getEndpoint(arg);
207
+ }
208
+ else {
209
+ var endpoint = arg;
210
+ }
211
+
212
+ if( endpoint === undefined ) {
213
+ console.log('Endpoint ' + arg + ' is undefined');
214
+ throw "nique";
215
+ }
216
+
217
+ // show source output type
218
+ var divId, type, key; [divId, type, key] = endpoint.getUuid().split('#');
219
+ if( endpoint.isSource ) {
220
+ $('#' + divId + ' .box-outputs .type[data-key="' + key + '"]').addClass('opacity0');
221
+ }
222
+ else {
223
+ $('#' + divId + ' .box-inputs .type[data-key="' + key + '"]').addClass('opacity0');
224
+ }
225
+ }
226
+
227
+ showType( arg ) {
228
+ if( typeof arg === "string" ) {
229
+ var endpoint = this.v.jsPlumbInstance.getEndpoint(arg);
230
+ }
231
+ else {
232
+ var endpoint = arg;
233
+ }
234
+
235
+ // show source output type
236
+ var divId, type, key; [divId, type, key] = endpoint.getUuid().split('#');
237
+ if( endpoint.isSource ) {
238
+ $('#' + divId + ' .box-outputs .type[data-key="' + key + '"]').removeClass('opacity0');
239
+ }
240
+ else {
241
+ $('#' + divId + ' .box-inputs .type[data-key="' + key + '"]').removeClass('opacity0');
242
+ }
243
+ }
244
+
245
+ showEventName( ep ) {
246
+ ep.getOverlay("label").setLabel( ep.getParameters().event );
247
+ }
248
+
249
+ hideEventName( ep ) {
250
+ ep.getOverlay("label").setLabel("");
251
+ }
252
+ }
253
+
254
+ module.exports = GraphStyle;
@@ -0,0 +1,239 @@
1
+ class Selector {
2
+ constructor(view, container) {
3
+ this.view = view;
4
+ this.container = container;
5
+ // translateZ(0) avoid paint glitches in chrome as it forces a repaint every time
6
+ this.div = $('<div/>', { id: 'selector', hidden: true, style: "border: 1px dotted #000; position: absolute; z-index: 100; transform: translateZ(0);" });
7
+ this.x1 = 0;
8
+ this.x2 = 0;
9
+ this.y1 = 0;
10
+ this.y2 = 0;
11
+
12
+ this.startEventHandler = this.onSelectionStart.bind(this);
13
+ this.moveEventHandler = this.onSelectionMove.bind(this);
14
+ this.stopEventHandler = this.onSelectionStop.bind(this);
15
+
16
+ // offset difference relative to pageX/Y
17
+ // we can't use offsetX and offsetY directly cause their value will be 0
18
+ // if we go over another div
19
+ this.diffX = null;
20
+ this.diffY = null;
21
+
22
+ this.onSelectCb = null;
23
+ this.onSelectingCb = null;
24
+ this.onDeselectCb = null;
25
+
26
+ this.selection = []; // list of selected divs
27
+
28
+ this.initialize();
29
+ }
30
+
31
+ initialize() {
32
+ this.container.append(this.div);
33
+ this.container.off('mousedown', this.startEventHandler);
34
+ this.container.off('mousemove', this.moveEventHandler);
35
+ this.container.off('mouseup', this.stopEventHandler);
36
+ this.container.on('mousedown', this.startEventHandler);
37
+ this.container.on('mousemove', this.moveEventHandler);
38
+ this.container.on('mouseup', this.stopEventHandler);
39
+ }
40
+
41
+ getSelection() {
42
+ return this.selection;
43
+ }
44
+
45
+ deselect() {
46
+ this.onDeselectCb(this.selection);
47
+ this.selection = [];
48
+ }
49
+
50
+ isSelected(div) {
51
+ var selected = false;
52
+ _.each(this.selection, (selectedDiv) => {
53
+ if( $(div).is( $(selectedDiv) ) ) {
54
+ selected = true;
55
+ return false; // end of loop
56
+ }
57
+ });
58
+ return selected;
59
+ }
60
+
61
+ addToSelection(div) {
62
+ this.selection.push(div);
63
+ this.onSelectCb(this.selection);
64
+ }
65
+
66
+ removeFromSelection(div) {
67
+ var i = 0;
68
+
69
+ // find the index
70
+ _.each(this.selection, (selectedDiv, index) => {
71
+ if( $(div).is( $(selectedDiv) ) ) {
72
+ i = index;
73
+ return false; // end of loop
74
+ }
75
+ });
76
+
77
+ this.selection.splice(i, 1);
78
+ this.onDeselectCb([div]);
79
+ }
80
+
81
+ toggleSelection(div) {
82
+ if( this.isSelected(div) ) {
83
+ this.removeFromSelection(div);
84
+ }
85
+ else {
86
+ this.addToSelection(div);
87
+ }
88
+ this.handleSelectionMenu();
89
+ }
90
+
91
+ onSelect( cb ) {
92
+ this.onSelectCb = cb;
93
+ }
94
+
95
+ onSelecting( cb ) {
96
+ this.onSelectingCb = cb;
97
+ }
98
+
99
+ onDeselect( cb ) {
100
+ this.onDeselectCb = cb;
101
+ }
102
+
103
+ reCalc() {
104
+ var x3 = Math.min(this.x1,this.x2);
105
+ var x4 = Math.max(this.x1,this.x2);
106
+ var y3 = Math.min(this.y1,this.y2);
107
+ var y4 = Math.max(this.y1,this.y2);
108
+
109
+ this.div[0].style.left = (x3 - this.diffX) + 'px';
110
+ this.div[0].style.top = (y3 - this.diffY) + 'px';
111
+ this.div[0].style.width = (x4 - x3) + 'px';
112
+ this.div[0].style.height = (y4 - y3) + 'px';
113
+ }
114
+
115
+ onSelectionStart(e) {
116
+ // capture only if:
117
+ // - it's left click
118
+ // - it's over the container
119
+ // - it's not over a container's button
120
+ // - it's not over a "capture-left-click" item
121
+ if( e.which === 1 &&
122
+ this.container.find('.btn:hover').length == 0 &&
123
+ this.container.find('.nodrag:hover').length == 0 &&
124
+ this.container.find('.jsplumb-connector:hover').length == 0 &&
125
+ this.container.find('.capture-left-click:hover').length == 0
126
+ ) {
127
+ if( this.container.is(':hover') ) {
128
+ // we're starting a selection
129
+ e.preventDefault();
130
+ e.stopPropagation();
131
+
132
+ // remove previous selection
133
+ if( this.onDeselectCb ) {
134
+ this.onDeselectCb(this.selection);
135
+ this.selection = [];
136
+ }
137
+
138
+ this.selecting = true;
139
+ this.div[0].hidden = 0;
140
+ this.x1 = this.x2 = e.pageX;
141
+ this.y1 = this.y2 = e.pageY;
142
+
143
+
144
+ var rect = e.currentTarget.getBoundingClientRect();
145
+ this.diffX = rect.left;
146
+ this.diffY = rect.top;
147
+ this.reCalc();
148
+ }
149
+ }
150
+ }
151
+
152
+ onSelectionMove(e) {
153
+ if( this.selecting ) {
154
+ e.preventDefault();
155
+ e.stopPropagation();
156
+
157
+ //console.log('[SELECTION] moving');
158
+ this.x2 = e.pageX;
159
+ this.y2 = e.pageY;
160
+ this.reCalc();
161
+
162
+ if( this.onSelectingCb ) {
163
+ // now we have our area, find all divs in it and return
164
+ // result to the onSelectCb
165
+ this.findCardDivs({
166
+ left : Math.min(this.x1, this.x2),
167
+ right : Math.max(this.x1, this.x2),
168
+ top : Math.min(this.y1, this.y2),
169
+ bottom : Math.max(this.y1, this.y2)
170
+ }, (divs) => {
171
+ this.selection = divs;
172
+ this.handleSelectionMenu();
173
+ this.onSelectingCb(this.selection);
174
+ });
175
+ }
176
+ }
177
+ }
178
+
179
+ onSelectionStop(e) {
180
+ if( this.selecting && e.which === 1 ) {
181
+ e.preventDefault();
182
+ e.stopPropagation();
183
+
184
+ //console.log('[SELECTION] stop');
185
+ this.selecting = false;
186
+ this.div[0].hidden = 1;
187
+
188
+ if( this.onSelectCb ) {
189
+ // now we have our area, find all divs in it and return
190
+ // result to the onSelectCb
191
+ this.findCardDivs({
192
+ left : Math.min(this.x1, this.x2),
193
+ right : Math.max(this.x1, this.x2),
194
+ top : Math.min(this.y1, this.y2),
195
+ bottom : Math.max(this.y1, this.y2)
196
+ }, (divs) => {
197
+ this.selection = divs;
198
+ this.handleSelectionMenu();
199
+ this.onSelectCb(this.selection);
200
+ });
201
+ }
202
+ }
203
+ }
204
+
205
+ findCardDivs( area, cb ) {
206
+ var self = this;
207
+ var selectedCards = [];
208
+ this.container.find('.card, .connection-control').each(function() {
209
+ if( self._intersects( $(this), area ) ) {
210
+ selectedCards.push($(this));
211
+ }
212
+ });
213
+
214
+ cb(selectedCards);
215
+ }
216
+
217
+ // utilities
218
+ _intersects( div, area ) {
219
+ var r1 = $(div)[0].getBoundingClientRect();
220
+ var r2 = area;
221
+ var res = !(r2.left > r1.right ||
222
+ r2.right < r1.left ||
223
+ r2.top > r1.bottom ||
224
+ r2.bottom < r1.top);
225
+ return res;
226
+ }
227
+
228
+ // show/hide the selection menu if we have more than 2 divs selected
229
+ handleSelectionMenu() {
230
+ if( this.selection.length > 1 ) {
231
+ this.view.div.find('.selection-menu').show();
232
+ }
233
+ else {
234
+ this.view.div.find('.selection-menu').hide();
235
+ }
236
+ }
237
+ }
238
+
239
+ module.exports = Selector;
@@ -0,0 +1,79 @@
1
+ // don't call this, just tricking browserify into thinking we use thoses
2
+ // It allows use to make dynamic require later (see appendTemplate)
3
+ function trickBrowserify() {
4
+ //require('./templates/*', { glob: true }); - don't work with es2015
5
+ require('./templates/addNode.css');
6
+ require('./templates/addNode.html');
7
+ require('./templates/addNode.js');
8
+
9
+ require('./templates/graphNode.css');
10
+ require('./templates/graphNode.html');
11
+ require('./templates/graphNode.js');
12
+
13
+ require('./templates/main.css');
14
+ require('./templates/main.html');
15
+ require('./templates/main.js');
16
+
17
+ require('./templates/searchResults.css');
18
+ require('./templates/searchResults.html');
19
+ require('./templates/searchResults.js');
20
+
21
+ require('./templates/editNodeSettings.css');
22
+ require('./templates/editNodeSettings.html');
23
+ require('./templates/editNodeSettings.js');
24
+
25
+ require('./templates/editMainSettings.css');
26
+ require('./templates/editMainSettings.html');
27
+ require('./templates/editMainSettings.js');
28
+
29
+ require('./templates/debugNodeInfos.css');
30
+ require('./templates/debugNodeInfos.html');
31
+ require('./templates/debugNodeInfos.js');
32
+ }
33
+
34
+ /**
35
+ * Class that handle loading/reloading of templates
36
+ */
37
+ class TemplateManager {
38
+ constructor(view) {
39
+ this.view = view;
40
+ this.templates = {};
41
+ }
42
+
43
+ appendTemplate(container, templateName, templateData, cb) {
44
+ if( !this.templates[templateName] ) {
45
+ this.templates[templateName] = {
46
+ "cssLoaded" : false
47
+ }
48
+ }
49
+
50
+ // load the HTML
51
+ var templateHTML = require('./templates/' + templateName + '.html');
52
+
53
+ // load css if necessary
54
+ if( !this.templates[templateName].cssLoaded ) {
55
+ require('./templates/' + templateName + '.css'); // require is enough to inject css
56
+ this.templates[templateName].cssLoaded = true;
57
+ }
58
+
59
+ // append the HTML to the selected container
60
+ var div = $(templateHTML(templateData))
61
+ container.append( div );
62
+ container.ready(() => {
63
+ // now load the .js file to bind behaviors
64
+ var templateJs = require('./templates/' + templateName + '.js');
65
+ templateJs(this.view, div, templateData); // run all the binds (give the view as parameter)
66
+
67
+ if( cb ) cb(div);
68
+ });
69
+ }
70
+
71
+ replaceTemplate(container, templateName, templateData, cb) {
72
+ container.empty();
73
+ this.appendTemplate(container, templateName, templateData, cb);
74
+ }
75
+
76
+
77
+ }
78
+
79
+ module.exports = TemplateManager;