@dualbox/editor 1.0.54 → 1.0.56

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.
@@ -53,7 +53,7 @@ class GraphModel {
53
53
  this.outputPrefix = "out-";
54
54
 
55
55
  // on json change callback
56
- this.onChange = null;
56
+ this.onChangeCb = null;
57
57
  }
58
58
 
59
59
  /***
@@ -209,6 +209,13 @@ class GraphModel {
209
209
  }
210
210
  }
211
211
 
212
+ batch(cb) {
213
+ var diff = this.history.batch(cb);
214
+ if (this.onChangeCb) {
215
+ this.onChangeCb(diff);
216
+ }
217
+ }
218
+
212
219
  setWindow(name) {
213
220
  var newWindows = [];
214
221
  _.each(this.data.windows, (w) => {
@@ -1768,7 +1775,7 @@ class GraphNode {
1768
1775
  }
1769
1776
 
1770
1777
  rename(newId) {
1771
- this.m.history.batch(() => {
1778
+ this.m.batch(() => {
1772
1779
  // change the target name according to type (ex: if input: "size" -> "in-size")
1773
1780
  var newGraphId;
1774
1781
  if (this.isInput()) {
@@ -114,7 +114,7 @@ class History {
114
114
  // execute the callback and save the history as 1 change
115
115
  batch(cb) {
116
116
  this.ignore(cb);
117
- this.save();
117
+ return this.save();
118
118
  }
119
119
 
120
120
  ignore(cb) {
@@ -23,24 +23,24 @@ class Merger {
23
23
 
24
24
  this.nodes = [];
25
25
  _.each(ids, (id) => {
26
- this.nodes.push( this.m.getNode(id) );
26
+ this.nodes.push(this.m.getNode(id));
27
27
  });
28
28
 
29
29
  this.id = null;
30
30
 
31
31
  // links from and to outside
32
32
  this.inboundLinksFromOutside = [];
33
- this.outboundLinksToOutside = [];
33
+ this.outboundLinksToOutside = [];
34
34
  }
35
35
 
36
36
  // merge all divs into a metabox
37
37
  // ids: array of ids from the boxes to be merged
38
38
  // metaboxName: name of the new metabox
39
39
  // metaboxDesc: description of the new metabox
40
- merge( metaboxName, metaboxDesc ) {
40
+ merge(metaboxName, metaboxDesc) {
41
41
  this.def.desc = metaboxDesc;
42
42
 
43
- this.m.history.batch( () => {
43
+ this.m.batch(() => {
44
44
  // 0. create a new ID for our metanode
45
45
  this.id = metaboxName + '-' + utils.randomString(8);
46
46
 
@@ -64,16 +64,16 @@ class Merger {
64
64
 
65
65
  // 5. Our metanode definition is ready, add it to the app
66
66
  this.m.data.app.metanodes = this.m.data.app.metanodes || {};
67
- this.m.data.app.metanodes[ metaboxName ] = this.def;
67
+ this.m.data.app.metanodes[metaboxName] = this.def;
68
68
 
69
69
  // 6. Create a new node from this def
70
70
  this.m.data.app.modules[this.id] = {
71
- "module" : metaboxName,
71
+ "module": metaboxName,
72
72
  "version": "*",
73
- "graph" : {
74
- "position" : {
75
- top : (bbox.top + bbox.bottom) / 2,
76
- left : (bbox.left + bbox.right) / 2
73
+ "graph": {
74
+ "position": {
75
+ top: (bbox.top + bbox.bottom) / 2,
76
+ left: (bbox.left + bbox.right) / 2
77
77
  }
78
78
  }
79
79
  };
@@ -85,13 +85,13 @@ class Merger {
85
85
  }
86
86
 
87
87
  _debug() {
88
- console.log( this.def );
88
+ console.log(this.def);
89
89
  }
90
90
 
91
- _isInMetanode( id ) {
91
+ _isInMetanode(id) {
92
92
  var inGroup = false;
93
- _.each( this.nodes, (node) => {
94
- if( node.id === id ) {
93
+ _.each(this.nodes, (node) => {
94
+ if (node.id === id) {
95
95
  inGroup = true;
96
96
  return false; // eol
97
97
  }
@@ -101,36 +101,35 @@ class Merger {
101
101
 
102
102
  // find the links from and to outside the metanode
103
103
  _collectAndDetachExternalLinks() {
104
- _.each( this.nodes, (node) => {
104
+ _.each(this.nodes, (node) => {
105
105
  var links = node.getInboundLinks();
106
- _.each( links, (link) => {
107
- if( !this._isInMetanode(link.sourceId) ) {
106
+ _.each(links, (link) => {
107
+ if (!this._isInMetanode(link.sourceId)) {
108
108
  link.detach(); // we don't need this link anymore
109
- this.inboundLinksFromOutside.push( link );
109
+ this.inboundLinksFromOutside.push(link);
110
110
  }
111
111
  });
112
112
 
113
113
  var links = node.getOutboundLinks();
114
- _.each( links, (link) => {
115
- if( !this._isInMetanode(link.targetId) ) {
114
+ _.each(links, (link) => {
115
+ if (!this._isInMetanode(link.targetId)) {
116
116
  link.detach();
117
- this.outboundLinksToOutside.push( link );
117
+ this.outboundLinksToOutside.push(link);
118
118
  }
119
119
  });
120
120
  });
121
121
  }
122
122
 
123
123
  // transform "cond" into "cond2", or "cond3" if cond2 is taken, etc.
124
- _nextName( type, name ) {
124
+ _nextName(type, name) {
125
125
  // find the appropriate number end (that is not taken already)
126
126
  var ending = 2;
127
- if( type == "input" ) {
128
- while( this.def.input[ name + "-" + ending ] ) ending++;
127
+ if (type == "input") {
128
+ while (this.def.input[name + "-" + ending]) ending++;
129
+ } else {
130
+ while (this.def.output[name + "-" + ending]) ending++;
129
131
  }
130
- else {
131
- while( this.def.output[ name + "-" + ending ] ) ending++;
132
- }
133
- return name+"-"+ending;
132
+ return name + "-" + ending;
134
133
  }
135
134
 
136
135
  // find and create the metabox inputs
@@ -143,7 +142,7 @@ class Merger {
143
142
  var getInputNameForThisLink = function(l) {
144
143
  var r = null;
145
144
  _.each(inputToLinks, (link, inputName) => {
146
- if( link.sourceId == l.sourceId && link.sourceOutput == l.sourceOutput ) {
145
+ if (link.sourceId == l.sourceId && link.sourceOutput == l.sourceOutput) {
147
146
  r = inputName;
148
147
  return false;
149
148
  }
@@ -157,7 +156,7 @@ class Merger {
157
156
 
158
157
  // get the original input name, rename if necessary
159
158
  var inputName = link.targetInput;
160
- if( this.def.input[inputName] ) {
159
+ if (this.def.input[inputName]) {
161
160
  // the input already exists. Check if the link that led to the creation of this
162
161
  // input have the same source that 'link'. Otherwise, we create another input.
163
162
  var l = inputToLinks[inputName];
@@ -168,8 +167,8 @@ class Merger {
168
167
  inputName = lookupInputName ? lookupInputName : this._nextName("input", inputName);
169
168
  }
170
169
 
171
- this.def.input[ inputName ] = {
172
- type: targetNode.getInputType( link.targetInput ),
170
+ this.def.input[inputName] = {
171
+ type: targetNode.getInputType(link.targetInput),
173
172
  graph: {
174
173
  position: this._computeInputSmartPosition(index)
175
174
  }
@@ -181,7 +180,7 @@ class Merger {
181
180
  link.nextTargetInput = inputName;
182
181
 
183
182
  // save our link in the dictionary
184
- inputToLinks[ inputName ] = link;
183
+ inputToLinks[inputName] = link;
185
184
  });
186
185
  }
187
186
 
@@ -192,13 +191,13 @@ class Merger {
192
191
  var sourceNode = link.getSourceNode();
193
192
 
194
193
  var outputName = link.sourceOutput;
195
- if( this.def.output[ outputName ] ) {
194
+ if (this.def.output[outputName]) {
196
195
  // check if the source of the output is the same as this link
197
196
  var outputLink = this.def.output[outputName].link;
198
197
  var sourceId = _.keys(outputLink)[0];
199
198
  var sourceOutput = outputLink[sourceId];
200
199
 
201
- if( !(link.sourceId == sourceId && link.sourceOutput == sourceOutput) ) {
200
+ if (!(link.sourceId == sourceId && link.sourceOutput == sourceOutput)) {
202
201
  // the output already exists. we need to create another one.
203
202
  outputName = this._nextName("output", outputName);
204
203
  }
@@ -206,8 +205,8 @@ class Merger {
206
205
 
207
206
  var l = {};
208
207
  l[link.sourceId] = link.sourceOutput;
209
- this.def.output[ outputName ] = {
210
- type: sourceNode.getOutputType( link.sourceOutput ),
208
+ this.def.output[outputName] = {
209
+ type: sourceNode.getOutputType(link.sourceOutput),
211
210
  graph: {
212
211
  position: this._computeOutputSmartPosition(index)
213
212
  },
@@ -227,15 +226,15 @@ class Merger {
227
226
  var left = Number.MAX_SAFE_INTEGER;
228
227
  _.each(this.nodes, (node) => {
229
228
  var pos = node.getPosition();
230
- if( pos.top < top ) top = pos.top;
231
- if( pos.left < left ) left = pos.left;
229
+ if (pos.top < top) top = pos.top;
230
+ if (pos.left < left) left = pos.left;
232
231
  });
233
232
 
234
233
  // we want to put theses node to 50px top and 50px left, so compute the diff
235
234
  var topdiff = top - 50;
236
235
  var leftdiff = left - 250;
237
- if( topdiff < 0 ) topdiff = 0;
238
- if( leftdiff < 0 ) leftdiff = 0;
236
+ if (topdiff < 0) topdiff = 0;
237
+ if (leftdiff < 0) leftdiff = 0;
239
238
 
240
239
  // reposition all nodes
241
240
  _.each(this.nodes, (node) => {
@@ -249,18 +248,18 @@ class Merger {
249
248
  _moveNodes() {
250
249
  // move the nodes into the Metamodule def
251
250
  _.each(this.nodes, (node) => {
252
- if( node.isMetanode() ) {
251
+ if (node.isMetanode()) {
253
252
  // move the metanode definition too
254
- this.def.metanodes[ node.def.module ] = node.getMetanodeDefinition();
253
+ this.def.metanodes[node.def.module] = node.getMetanodeDefinition();
255
254
  }
256
255
 
257
256
  // move the node module definition (preserving the links between metabox's node)
258
- this.def.modules[node.id] = this.m.data.app.modules[ node.id ];
257
+ this.def.modules[node.id] = this.m.data.app.modules[node.id];
259
258
  delete this.m.data.app.modules[node.id];
260
259
 
261
- if( node.isMetanode() ) {
260
+ if (node.isMetanode()) {
262
261
  // if the metanode isn't still in use in the main app, remove def from here
263
- if( !this.m.isMetanodeUsed(node.def.module) ) {
262
+ if (!this.m.isMetanodeUsed(node.def.module)) {
264
263
  delete this.m.data.app.metanodes[node.def.module];
265
264
  }
266
265
  }
@@ -270,7 +269,7 @@ class Merger {
270
269
  _bindInputs() {
271
270
  _.each(this.inboundLinksFromOutside, (link) => {
272
271
  // we created an input with the same name, bind it to it
273
- this.def.modules[link.targetId].links[link.targetInput] = { "input" : link.nextTargetInput };
272
+ this.def.modules[link.targetId].links[link.targetInput] = { "input": link.nextTargetInput };
274
273
  });
275
274
  }
276
275
 
@@ -302,18 +301,18 @@ class Merger {
302
301
  // compute the bbox of all divs beeing merged, position the new div in the middle
303
302
  _computeBbox() {
304
303
  var most = {
305
- top: +Infinity,
304
+ top: +Infinity,
306
305
  bottom: -Infinity,
307
- left: +Infinity,
308
- right: -Infinity
306
+ left: +Infinity,
307
+ right: -Infinity
309
308
  };
310
309
 
311
- _.each( this.nodes, (node) => {
310
+ _.each(this.nodes, (node) => {
312
311
  var pos = node.getPosition();
313
- if( pos.top < most.top ) most.top = pos.top;
314
- if( pos.top > most.bottom ) most.bottom = pos.top;
315
- if( pos.left < most.left ) most.left = pos.left;
316
- if( pos.left > most.right ) most.right = pos.left;
312
+ if (pos.top < most.top) most.top = pos.top;
313
+ if (pos.top > most.bottom) most.bottom = pos.top;
314
+ if (pos.left < most.left) most.left = pos.left;
315
+ if (pos.left > most.right) most.right = pos.left;
317
316
  });
318
317
 
319
318
  return most;
@@ -322,11 +321,11 @@ class Merger {
322
321
  _getPositioningValues() {
323
322
  // todo: get a better system with the real bbox
324
323
  return {
325
- width : 100,
326
- height : 80,
327
- hMargin : 80,
328
- vMargin : 20,
329
- divAvgWidth : 150
324
+ width: 100,
325
+ height: 80,
326
+ hMargin: 80,
327
+ vMargin: 20,
328
+ divAvgWidth: 150
330
329
  }
331
330
  }
332
331
 
@@ -351,7 +350,4 @@ class Merger {
351
350
  }
352
351
  }
353
352
 
354
- export default Merger;
355
-
356
-
357
-
353
+ export default Merger;
@@ -6,11 +6,11 @@
6
6
  import _ from 'lodash';
7
7
 
8
8
  var editorView = null;
9
- $.fn.savePosition = function( selector ) {
9
+ $.fn.savePosition = function(selector) {
10
10
  var id = $(this).attr('id');
11
- if( id ) {
11
+ if (id) {
12
12
  var jsPlumbElement = editorView.jsPlumbInstance.getElement(id);
13
- if( jsPlumbElement ) {
13
+ if (jsPlumbElement) {
14
14
  var pos = editorView.jsPlumbInstance.getPosition(jsPlumbElement);
15
15
  editorView.view.m.getNode(id).setPosition(pos);
16
16
  }
@@ -21,7 +21,7 @@ class CanvasSizeHandler {
21
21
  constructor(parent, canvas) {
22
22
  this.parent = editorView = parent;
23
23
  this.canvas = canvas;
24
- this.minWidth = this.width = this.canvas.width();
24
+ this.minWidth = this.width = this.canvas.width();
25
25
  this.minHeight = this.height = this.canvas.height();
26
26
 
27
27
  // arbitrary: number of pixels to expand/shrink the canvas for 1 step
@@ -35,41 +35,41 @@ class CanvasSizeHandler {
35
35
  this.z = 0; // current zoom
36
36
  }
37
37
 
38
- refreshZoom( z ) {
38
+ refreshZoom(z) {
39
39
  this.z = z;
40
40
  }
41
41
 
42
42
  // set the current width and height to the new canvas
43
43
  apply() {
44
44
  var offset = this.canvas.offset();
45
- var oldWidth = this.canvas.width();
45
+ var oldWidth = this.canvas.width();
46
46
  var oldHeight = this.canvas.height();
47
47
 
48
- if( oldWidth !== this.width ) {
48
+ if (oldWidth !== this.width) {
49
49
  console.log('setting canvas width: %s -> %s', this.canvas.width(), this.width);
50
50
  this.canvas.width(this.width);
51
51
  }
52
- if( oldHeight !== this.height ) {
52
+ if (oldHeight !== this.height) {
53
53
  console.log('setting canvas height: %s -> %s', this.canvas.height(), this.height);
54
54
  this.canvas.height(this.height);
55
55
  }
56
56
 
57
57
  // If we are in a zoomed state, we need to update the transform-origin so we stay at the same position
58
- if( this.z !== 1 ) {
59
- // transform-origin is defined in % in the debugger, but for some reason, jquery seems to give us offset when
58
+ if (this.z !== 1) {
59
+ // transform-origin is defined in % in the debugger, but for some reason, jquery seems to give us offset when
60
60
  // we integrate it
61
61
  var oldTO = this.canvas.css('transform-origin');
62
62
  var oldTOX = parseFloat(oldTO);
63
63
  var oldTOY = parseFloat(oldTO.split(' ')[1]);
64
64
  var newTOX = oldTOX; // init thoses at the old value
65
- var newTOY = oldTOY;
65
+ var newTOY = oldTOY;
66
66
 
67
- if( oldWidth !== this.width ) {
67
+ if (oldWidth !== this.width) {
68
68
  var xRatioChange = this.width / oldWidth;
69
69
  var newTOX = oldTOX * xRatioChange;
70
70
  }
71
71
 
72
- if( oldHeight !== this.height ) {
72
+ if (oldHeight !== this.height) {
73
73
  var yRatioChange = this.height / oldHeight;
74
74
  var newTOY = oldTOY * yRatioChange;
75
75
  }
@@ -85,21 +85,21 @@ class CanvasSizeHandler {
85
85
  // dont trigger save
86
86
  this.parent.view.m.history.ignore(() => {
87
87
  // refresh zoom value, zoom affects width, height and offset calculations
88
- this.refreshZoom( this.parent.zoomer.getZoom() );
88
+ this.refreshZoom(this.parent.zoomer.getZoom());
89
89
 
90
90
  // find the coord of the 2d box bounding all divs
91
91
  var most = {
92
- top: +Infinity,
92
+ top: +Infinity,
93
93
  bottom: -Infinity,
94
- left: +Infinity,
95
- right: -Infinity
94
+ left: +Infinity,
95
+ right: -Infinity
96
96
  };
97
97
  this.canvas.find('.card').each(function() {
98
98
  var rect = this.getBoundingClientRect();
99
- if( rect.top < most.top ) most.top = Math.floor(rect.top);
100
- if( rect.bottom > most.bottom ) most.bottom = Math.ceil(rect.bottom);
101
- if( rect.left < most.left ) most.left = Math.floor(rect.left);
102
- if( rect.right > most.right ) most.right = Math.ceil(rect.right);
99
+ if (rect.top < most.top) most.top = Math.floor(rect.top);
100
+ if (rect.bottom > most.bottom) most.bottom = Math.ceil(rect.bottom);
101
+ if (rect.left < most.left) most.left = Math.floor(rect.left);
102
+ if (rect.right > most.right) most.right = Math.ceil(rect.right);
103
103
  });
104
104
 
105
105
  // compare to the canvas coord
@@ -107,24 +107,24 @@ class CanvasSizeHandler {
107
107
  var tresholdAdapted = this.treshold * this.z;
108
108
 
109
109
  var r = {
110
- top: ((canvasRect.top + tresholdAdapted) - most.top) / this.z,
110
+ top: ((canvasRect.top + tresholdAdapted) - most.top) / this.z,
111
111
  bottom: (most.bottom - (canvasRect.bottom - tresholdAdapted)) / this.z,
112
- left: ((canvasRect.left + tresholdAdapted) - most.left) / this.z,
113
- right: (most.right - (canvasRect.right - tresholdAdapted)) / this.z
112
+ left: ((canvasRect.left + tresholdAdapted) - most.left) / this.z,
113
+ right: (most.right - (canvasRect.right - tresholdAdapted)) / this.z
114
114
  }
115
115
 
116
116
  // avoid to resize for some pixel roundup
117
- if( Math.abs(r.top) > 2 || Math.abs(r.left) > 2 || Math.abs(r.bottom) > 2 || Math.abs(r.right) > 2 ) {
117
+ if (Math.abs(r.top) > 2 || Math.abs(r.left) > 2 || Math.abs(r.bottom) > 2 || Math.abs(r.right) > 2) {
118
118
  // resize width and height
119
119
  this.width += r.left + r.right;
120
120
  this.height += r.top + r.bottom;
121
- if( this.width < this.minWidth ) this.width = this.minWidth;
122
- if( this.height < this.minHeight ) this.height = this.minHeight;
121
+ if (this.width < this.minWidth) this.width = this.minWidth;
122
+ if (this.height < this.minHeight) this.height = this.minHeight;
123
123
  this.apply();
124
124
 
125
125
  // if we're expanding to the top or shrinking back, move the non-selected divs
126
126
  // in the opposite direction
127
- if( r.top > 0 || (r.top < 0 && this.height > this.minHeight) ) {
127
+ if (r.top > 0 || (r.top < 0 && this.height > this.minHeight)) {
128
128
  // move the non-selected divs to the bottom
129
129
  this.canvas.find('.card:not(.selected)').each(function() {
130
130
  var offset = $(this).offset();
@@ -140,7 +140,7 @@ class CanvasSizeHandler {
140
140
  }
141
141
 
142
142
  // same for left
143
- if( r.left > 0 || (r.left < 0 && this.width > this.minWidth) ) {
143
+ if (r.left > 0 || (r.left < 0 && this.width > this.minWidth)) {
144
144
  // move the non-selected divs to the right
145
145
  this.canvas.find('.card:not(.selected)').each(function() {
146
146
  var offset = $(this).offset();
@@ -174,4 +174,4 @@ class CanvasSizeHandler {
174
174
  }
175
175
  }
176
176
 
177
- export default CanvasSizeHandler;
177
+ export default CanvasSizeHandler;
@@ -927,7 +927,7 @@ export default {
927
927
 
928
928
  if( self.$parent.selector.isMultipleSelectionActive() ) {
929
929
  // We just dropped a bunch of divs, ajust all their positions
930
- self.view.m.history.batch(() => {
930
+ self.view.m.batch(() => {
931
931
  self.$parent.selector.each(div => {
932
932
  var pos = self.$parent.jsPlumbInstance.getPosition(div);
933
933
  view.m.getNode($(div).attr('id')).setPosition(pos);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dualbox/editor",
3
- "version": "1.0.54",
3
+ "version": "1.0.56",
4
4
  "description": "Editor of Dualbox apps",
5
5
  "browser": "js/dist/GraphEditor.js",
6
6
  "main": "js/dist/GraphEditor.js",