@dualbox/editor 1.0.61 → 1.0.62
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/js/dist/GraphEditor.js +107 -111
- package/js/dist/GraphEditor.min.js +106 -110
- package/js/src/c/GraphController.js +35 -43
- package/js/src/m/GraphModel.js +50 -46
- package/js/src/m/History.js +16 -16
- package/js/src/m/Merger.js +6 -6
- package/package.json +1 -1
|
@@ -47,8 +47,7 @@ class GraphController {
|
|
|
47
47
|
this.v.repaint();
|
|
48
48
|
}
|
|
49
49
|
});
|
|
50
|
-
}
|
|
51
|
-
else {
|
|
50
|
+
} else {
|
|
52
51
|
var options = {};
|
|
53
52
|
_.each(this.m.getPanels(), (name) => options[name] = name);
|
|
54
53
|
|
|
@@ -81,7 +80,16 @@ class GraphController {
|
|
|
81
80
|
var pkg = this.e.packages[packageName];
|
|
82
81
|
if (pkg) {
|
|
83
82
|
// first, add node in the model
|
|
84
|
-
|
|
83
|
+
// batch it so add node + set position is 1 history change only
|
|
84
|
+
var nodeInfo;
|
|
85
|
+
this.m.batch(() => {
|
|
86
|
+
nodeInfo = this.m.addNode(id, pkg);
|
|
87
|
+
if (nodeInfo && pos) {
|
|
88
|
+
var node = this.m.getNode(nodeInfo.id);
|
|
89
|
+
node.setPosition(pos);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
|
|
85
93
|
if (nodeInfo) {
|
|
86
94
|
if (pos) {
|
|
87
95
|
var node = this.m.getNode(nodeInfo.id);
|
|
@@ -98,8 +106,7 @@ class GraphController {
|
|
|
98
106
|
this.registerNodeToInterface(id);
|
|
99
107
|
}
|
|
100
108
|
}
|
|
101
|
-
}
|
|
102
|
-
else {
|
|
109
|
+
} else {
|
|
103
110
|
console.error('Package ' + packageName + ' not found');
|
|
104
111
|
}
|
|
105
112
|
});
|
|
@@ -109,8 +116,7 @@ class GraphController {
|
|
|
109
116
|
addNewMetabox(name, json = {}, pos) {
|
|
110
117
|
if (this.m.hasMetanode(name)) {
|
|
111
118
|
swal("Can't add metabox", "metabox with name '" + name + "' already exists.", "error");
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
119
|
+
} else {
|
|
114
120
|
// add metabox def
|
|
115
121
|
this.m.addMetanode(name, json);
|
|
116
122
|
|
|
@@ -121,7 +127,7 @@ class GraphController {
|
|
|
121
127
|
"name": name,
|
|
122
128
|
"version": "*"
|
|
123
129
|
});
|
|
124
|
-
if(
|
|
130
|
+
if (pos) {
|
|
125
131
|
var n = this.m.getNode(id);
|
|
126
132
|
n.setPosition(pos);
|
|
127
133
|
}
|
|
@@ -157,8 +163,7 @@ class GraphController {
|
|
|
157
163
|
// if it's an UI, we need to register it to a panel
|
|
158
164
|
if (type === "ui") {
|
|
159
165
|
this.registerNodeToInterface(newId); // will repaint
|
|
160
|
-
}
|
|
161
|
-
else {
|
|
166
|
+
} else {
|
|
162
167
|
this.v.repaint();
|
|
163
168
|
}
|
|
164
169
|
}
|
|
@@ -168,8 +173,7 @@ class GraphController {
|
|
|
168
173
|
if (node.isInputConnected(input) && !visible) {
|
|
169
174
|
swal('Not yet', 'Please remove all connections to this input before changing its visibility', 'error');
|
|
170
175
|
return false;
|
|
171
|
-
}
|
|
172
|
-
else {
|
|
176
|
+
} else {
|
|
173
177
|
node.setInputVisibility(input, visible);
|
|
174
178
|
this.v.repaint();
|
|
175
179
|
return true;
|
|
@@ -181,8 +185,7 @@ class GraphController {
|
|
|
181
185
|
if (node.isOutputConnected(output) && !visible) {
|
|
182
186
|
swal('Not yet', 'Please remove all connections to this output before changing its visibility', 'error');
|
|
183
187
|
return false;
|
|
184
|
-
}
|
|
185
|
-
else {
|
|
188
|
+
} else {
|
|
186
189
|
node.setOutputVisibility(output, visible);
|
|
187
190
|
this.v.repaint();
|
|
188
191
|
return true;
|
|
@@ -230,12 +233,10 @@ class GraphController {
|
|
|
230
233
|
if (type == "input") {
|
|
231
234
|
oldId = this.m.inputPrefix + oldId;
|
|
232
235
|
newId = this.m.inputPrefix + newId;
|
|
233
|
-
}
|
|
234
|
-
else if (type == "output") {
|
|
236
|
+
} else if (type == "output") {
|
|
235
237
|
oldId = this.m.outputPrefix + oldId;
|
|
236
238
|
newId = this.m.outputPrefix + newId;
|
|
237
|
-
}
|
|
238
|
-
else {
|
|
239
|
+
} else {
|
|
239
240
|
if (newId.startsWith(this.m.inputPrefix) ||
|
|
240
241
|
newId.startsWith(this.m.outputPrefix)) {
|
|
241
242
|
swal('Breaking convention', 'Only input boxes and output boxes can have a name that starts with "' + this.m.inputPrefix + '" or "' + this.m.outputPrefix + '".', "error");
|
|
@@ -276,12 +277,10 @@ class GraphController {
|
|
|
276
277
|
var eventName = id.split('-')[id.split('-').length - 1];
|
|
277
278
|
var def = this.m.getCurrentApp().getEventIn(eventName)[index];
|
|
278
279
|
def[prop] = val;
|
|
279
|
-
}
|
|
280
|
-
else if (id.startsWith("#application-events-out")) {
|
|
280
|
+
} else if (id.startsWith("#application-events-out")) {
|
|
281
281
|
var def = this.m.getCurrentApp().getEventOut();
|
|
282
282
|
def[prop] = val;
|
|
283
|
-
}
|
|
284
|
-
else {
|
|
283
|
+
} else {
|
|
285
284
|
var def = this.m.getNode(id).getEvent(index);
|
|
286
285
|
def[prop] = val;
|
|
287
286
|
this.m.getNode(id).setEvent(index, def);
|
|
@@ -365,35 +364,32 @@ class GraphController {
|
|
|
365
364
|
var nodeIndex = -1;
|
|
366
365
|
var eventIndex = -1;
|
|
367
366
|
|
|
368
|
-
var iterateToNextEvent = function
|
|
367
|
+
var iterateToNextEvent = function() {
|
|
369
368
|
if (eventIndex + 1 < eventNames.length) {
|
|
370
369
|
eventIndex++;
|
|
371
370
|
eventName = eventNames[eventIndex];
|
|
372
371
|
return eventName;
|
|
373
|
-
}
|
|
374
|
-
else {
|
|
372
|
+
} else {
|
|
375
373
|
return null;
|
|
376
374
|
}
|
|
377
375
|
}
|
|
378
376
|
|
|
379
|
-
var iterateToNextNode = function
|
|
377
|
+
var iterateToNextNode = function() {
|
|
380
378
|
if (nodeIndex + 1 < nodes.length) {
|
|
381
379
|
nodeIndex++;
|
|
382
380
|
node = nodes[nodeIndex];
|
|
383
381
|
eventNames = node.getEventsNames();
|
|
384
382
|
if (eventNames.length !== 0) {
|
|
385
383
|
return node;
|
|
386
|
-
}
|
|
387
|
-
else {
|
|
384
|
+
} else {
|
|
388
385
|
return iterateToNextNode();
|
|
389
386
|
}
|
|
390
|
-
}
|
|
391
|
-
else {
|
|
387
|
+
} else {
|
|
392
388
|
return null;
|
|
393
389
|
}
|
|
394
390
|
}
|
|
395
391
|
|
|
396
|
-
var iterate = function
|
|
392
|
+
var iterate = function() {
|
|
397
393
|
var n, e;
|
|
398
394
|
e = iterateToNextEvent();
|
|
399
395
|
if (e === null) n = iterateToNextNode();
|
|
@@ -424,8 +420,7 @@ class GraphController {
|
|
|
424
420
|
if (node != null) {
|
|
425
421
|
var evtName = node.getEventsNames()[0];
|
|
426
422
|
this.m.getCurrentApp().addSubEvent(name, node.getGraphId(), evtName);
|
|
427
|
-
}
|
|
428
|
-
else {
|
|
423
|
+
} else {
|
|
429
424
|
this.m.getCurrentApp().addSubEvent(name, null, null);
|
|
430
425
|
}
|
|
431
426
|
this.v.setMainMenu();
|
|
@@ -444,7 +439,7 @@ class GraphController {
|
|
|
444
439
|
addInput(name, type, desc, pos) {
|
|
445
440
|
var input = this.m.addInput(name, type, desc);
|
|
446
441
|
if (pos) {
|
|
447
|
-
var node = this.m.getNode("in-"+name);
|
|
442
|
+
var node = this.m.getNode("in-" + name);
|
|
448
443
|
node.setPosition(pos);
|
|
449
444
|
}
|
|
450
445
|
this.v.repaint();
|
|
@@ -453,7 +448,7 @@ class GraphController {
|
|
|
453
448
|
addOutput(name, type, desc, pos) {
|
|
454
449
|
var output = this.m.addOutput(name, type, desc);
|
|
455
450
|
if (pos) {
|
|
456
|
-
var node = this.m.getNode("out-"+name);
|
|
451
|
+
var node = this.m.getNode("out-" + name);
|
|
457
452
|
node.setPosition(pos);
|
|
458
453
|
}
|
|
459
454
|
this.v.repaint();
|
|
@@ -465,8 +460,7 @@ class GraphController {
|
|
|
465
460
|
confirmButtonText: 'Next →',
|
|
466
461
|
showCancelButton: true,
|
|
467
462
|
progressSteps: ['1', '2']
|
|
468
|
-
}).queue([
|
|
469
|
-
{
|
|
463
|
+
}).queue([{
|
|
470
464
|
input: 'text',
|
|
471
465
|
title: 'Enter the input name',
|
|
472
466
|
},
|
|
@@ -503,8 +497,7 @@ class GraphController {
|
|
|
503
497
|
confirmButtonText: 'Next →',
|
|
504
498
|
showCancelButton: true,
|
|
505
499
|
progressSteps: ['1', '2']
|
|
506
|
-
}).queue([
|
|
507
|
-
{
|
|
500
|
+
}).queue([{
|
|
508
501
|
input: 'text',
|
|
509
502
|
title: 'Enter the output name',
|
|
510
503
|
},
|
|
@@ -544,7 +537,7 @@ class GraphController {
|
|
|
544
537
|
|
|
545
538
|
unsetIterator(id, input) {
|
|
546
539
|
var node = this.m.getNode(id);
|
|
547
|
-
node.detachInput(input);
|
|
540
|
+
node.detachInput(input); // this connection is invalid now
|
|
548
541
|
node.unsetIterator(input);
|
|
549
542
|
this.v.repaint();
|
|
550
543
|
}
|
|
@@ -675,8 +668,7 @@ class GraphController {
|
|
|
675
668
|
confirmButtonText: 'Next →',
|
|
676
669
|
showCancelButton: true,
|
|
677
670
|
progressSteps: ['1', '2']
|
|
678
|
-
}).queue([
|
|
679
|
-
{
|
|
671
|
+
}).queue([{
|
|
680
672
|
input: 'text',
|
|
681
673
|
title: 'Enter the metabox name',
|
|
682
674
|
},
|
|
@@ -710,4 +702,4 @@ class GraphController {
|
|
|
710
702
|
}
|
|
711
703
|
}
|
|
712
704
|
|
|
713
|
-
export default GraphController;
|
|
705
|
+
export default GraphController;
|
package/js/src/m/GraphModel.js
CHANGED
|
@@ -31,6 +31,7 @@ class GraphModel {
|
|
|
31
31
|
// Pointer that changes when we view/edit metanodes
|
|
32
32
|
// All methodes are relative to this pointer, so we just need to change it
|
|
33
33
|
// to enter/exit a metanode
|
|
34
|
+
// Path to the current metanode. Use this.getCurrentMetanode() to resolve it
|
|
34
35
|
app: null,
|
|
35
36
|
|
|
36
37
|
// Array of pointers to manage navigation between metanodes
|
|
@@ -40,14 +41,14 @@ class GraphModel {
|
|
|
40
41
|
// w[2] = view state (result of zoomer.saveState())
|
|
41
42
|
windows: null
|
|
42
43
|
};
|
|
43
|
-
this.data.app =
|
|
44
|
+
this.data.app = null;
|
|
44
45
|
this.data.windows = [
|
|
45
|
-
[this.e.rootAppName,
|
|
46
|
+
[this.e.rootAppName, null]
|
|
46
47
|
];
|
|
47
48
|
|
|
48
49
|
// An object to save/restore different states of this.data (ctrl-z/ctrl-y)
|
|
49
50
|
this.history = new History(this);
|
|
50
|
-
this.history.setOrigin(_.cloneDeep(this.data));
|
|
51
|
+
this.history.setOrigin(_.cloneDeep(this.data.root));
|
|
51
52
|
|
|
52
53
|
this.inputPrefix = "in-";
|
|
53
54
|
this.outputPrefix = "out-";
|
|
@@ -64,14 +65,14 @@ class GraphModel {
|
|
|
64
65
|
this.check(json);
|
|
65
66
|
|
|
66
67
|
this.data.root = json;
|
|
67
|
-
this.data.app =
|
|
68
|
+
this.data.app = null; // reset ptr
|
|
68
69
|
this.data.windows = [
|
|
69
|
-
[this.e.rootAppName,
|
|
70
|
+
[this.e.rootAppName, null]
|
|
70
71
|
];
|
|
71
72
|
|
|
72
73
|
await this.addNativeTypes();
|
|
73
74
|
|
|
74
|
-
this.history.setOrigin(_.cloneDeep(this.data));
|
|
75
|
+
this.history.setOrigin(_.cloneDeep(this.data.root));
|
|
75
76
|
}
|
|
76
77
|
|
|
77
78
|
addNativeTypes() {
|
|
@@ -115,7 +116,11 @@ class GraphModel {
|
|
|
115
116
|
}
|
|
116
117
|
|
|
117
118
|
getCurrentMetanode() {
|
|
118
|
-
|
|
119
|
+
if (this.data.app === null) {
|
|
120
|
+
return this.data.root
|
|
121
|
+
} else {
|
|
122
|
+
return _.get(this.data.root, this.data.app);
|
|
123
|
+
}
|
|
119
124
|
}
|
|
120
125
|
|
|
121
126
|
getCurrentMetanodeName() {
|
|
@@ -189,10 +194,6 @@ class GraphModel {
|
|
|
189
194
|
return this.data.windows;
|
|
190
195
|
}
|
|
191
196
|
|
|
192
|
-
getCurrentWindow() {
|
|
193
|
-
return this.data.app;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
197
|
getPanels() {
|
|
197
198
|
return _.keys(this.data.root.interface);
|
|
198
199
|
}
|
|
@@ -263,20 +264,20 @@ class GraphModel {
|
|
|
263
264
|
* Json security methods
|
|
264
265
|
*/
|
|
265
266
|
ensure(field) {
|
|
266
|
-
this.
|
|
267
|
+
this.getCurrentMetanode()[field] = this.getCurrentMetanode()[field] || {};
|
|
267
268
|
}
|
|
268
269
|
|
|
269
270
|
/**
|
|
270
271
|
* Metanodes navigation
|
|
271
272
|
*/
|
|
272
273
|
enterMetanode(id, viewState) {
|
|
273
|
-
var node = this.
|
|
274
|
+
var node = this.getCurrentMetanode().modules[id];
|
|
274
275
|
if (!node) {
|
|
275
276
|
throw "couldn't find node " + id;
|
|
276
277
|
}
|
|
277
278
|
|
|
278
279
|
var name = node.module;
|
|
279
|
-
var metanode = this.
|
|
280
|
+
var metanode = this.getCurrentMetanode().metanodes[name];
|
|
280
281
|
if (!metanode) {
|
|
281
282
|
throw "couldn't find definition for metanode " + name;
|
|
282
283
|
}
|
|
@@ -285,7 +286,7 @@ class GraphModel {
|
|
|
285
286
|
this.data.windows[this.data.windows.length - 1][2] = viewState;
|
|
286
287
|
|
|
287
288
|
// switch to the next window
|
|
288
|
-
this.data.app =
|
|
289
|
+
this.data.app = ["metanodes", name];
|
|
289
290
|
this.data.windows.push([name, metanode]);
|
|
290
291
|
this.save();
|
|
291
292
|
}
|
|
@@ -295,7 +296,7 @@ class GraphModel {
|
|
|
295
296
|
*/
|
|
296
297
|
addMetanode(name, def) {
|
|
297
298
|
this.ensure('metanodes');
|
|
298
|
-
this.
|
|
299
|
+
this.getCurrentMetanode().metanodes[name] = def;
|
|
299
300
|
}
|
|
300
301
|
|
|
301
302
|
addInput(name, type, desc) {
|
|
@@ -304,7 +305,7 @@ class GraphModel {
|
|
|
304
305
|
"desc": desc
|
|
305
306
|
};
|
|
306
307
|
this.ensure('input');
|
|
307
|
-
this.
|
|
308
|
+
this.getCurrentMetanode().input[name] = input;
|
|
308
309
|
this.save();
|
|
309
310
|
return input;
|
|
310
311
|
}
|
|
@@ -315,13 +316,13 @@ class GraphModel {
|
|
|
315
316
|
"desc": desc
|
|
316
317
|
};
|
|
317
318
|
this.ensure('output');
|
|
318
|
-
this.
|
|
319
|
+
this.getCurrentMetanode().output[name] = output;
|
|
319
320
|
this.save();
|
|
320
321
|
return output;
|
|
321
322
|
}
|
|
322
323
|
|
|
323
324
|
hasMetanode(name) {
|
|
324
|
-
return
|
|
325
|
+
return _.get(this.getCurrentMetanode(), ["metanodes", name]) !== undefined;
|
|
325
326
|
}
|
|
326
327
|
|
|
327
328
|
isRootApp(app) {
|
|
@@ -331,7 +332,7 @@ class GraphModel {
|
|
|
331
332
|
getMetanodeInstances(app) {
|
|
332
333
|
// first identify metanode name
|
|
333
334
|
var metanodeName = null;
|
|
334
|
-
_.each(this.
|
|
335
|
+
_.each(this.getCurrentMetanode().metanodes, (metanode, name) => {
|
|
335
336
|
if (app == metanode) {
|
|
336
337
|
metanodeName = name;
|
|
337
338
|
return false;
|
|
@@ -339,7 +340,7 @@ class GraphModel {
|
|
|
339
340
|
});
|
|
340
341
|
|
|
341
342
|
var instances = [];
|
|
342
|
-
_.each(this.
|
|
343
|
+
_.each(this.getCurrentMetanode().modules, (json, id) => {
|
|
343
344
|
if (json.module == metanodeName) {
|
|
344
345
|
instances.push(this.getNode(id));
|
|
345
346
|
}
|
|
@@ -358,24 +359,24 @@ class GraphModel {
|
|
|
358
359
|
}
|
|
359
360
|
if (utils.isModule(pkg.name)) {
|
|
360
361
|
this.ensure('modules');
|
|
361
|
-
if (this.
|
|
362
|
+
if (this.getCurrentMetanode().modules[id]) {
|
|
362
363
|
console.error('Could not add module ' + id + ': already exists');
|
|
363
364
|
return false;
|
|
364
365
|
}
|
|
365
|
-
var node = this.
|
|
366
|
+
var node = this.getCurrentMetanode().modules[id] = desc;
|
|
366
367
|
} else if (utils.isUI(pkg.name)) {
|
|
367
368
|
this.ensure('ui');
|
|
368
|
-
if (this.
|
|
369
|
+
if (this.getCurrentMetanode().ui[id]) {
|
|
369
370
|
console.error('Could not add ui ' + id + ': already exists');
|
|
370
371
|
return false;
|
|
371
372
|
}
|
|
372
|
-
var node = this.
|
|
373
|
+
var node = this.getCurrentMetanode().ui[id] = desc;
|
|
373
374
|
} else {
|
|
374
375
|
// may be a metanode
|
|
375
|
-
var nodeDef = idx(this.
|
|
376
|
+
var nodeDef = idx(this.getCurrentMetanode(), o => o.metanodes[pkg.name]);
|
|
376
377
|
if (nodeDef) {
|
|
377
378
|
this.ensure('modules');
|
|
378
|
-
var node = this.
|
|
379
|
+
var node = this.getCurrentMetanode().modules[id] = desc;
|
|
379
380
|
return node;
|
|
380
381
|
} else {
|
|
381
382
|
throw pkg.name + " is not module or ui, can't add node !";
|
|
@@ -417,11 +418,11 @@ class GraphModel {
|
|
|
417
418
|
switch (type) {
|
|
418
419
|
case "module":
|
|
419
420
|
this.ensure('modules');
|
|
420
|
-
this.
|
|
421
|
+
this.getCurrentMetanode().modules[id] = def;
|
|
421
422
|
break;
|
|
422
423
|
case "ui":
|
|
423
424
|
this.ensure('ui');
|
|
424
|
-
this.
|
|
425
|
+
this.getCurrentMetanode().ui[id] = def;
|
|
425
426
|
break;
|
|
426
427
|
default:
|
|
427
428
|
throw type + " is not module or ui, error";
|
|
@@ -467,7 +468,7 @@ class GraphModel {
|
|
|
467
468
|
// check if metanode def is used by at least 1 module
|
|
468
469
|
isMetanodeUsed(name) {
|
|
469
470
|
var stillUsed = false;
|
|
470
|
-
_.each(this.
|
|
471
|
+
_.each(this.getCurrentMetanode().modules, (n) => {
|
|
471
472
|
if (n.module === name) {
|
|
472
473
|
stillUsed = true;
|
|
473
474
|
return false; // eol
|
|
@@ -505,25 +506,25 @@ class GraphModel {
|
|
|
505
506
|
var keys = null;
|
|
506
507
|
switch (type) {
|
|
507
508
|
case "input":
|
|
508
|
-
keys = _.keys(this.
|
|
509
|
+
keys = _.keys(this.getCurrentMetanode().input);
|
|
509
510
|
keys = _.map(keys, k => this.inputPrefix + k);
|
|
510
511
|
break;
|
|
511
512
|
case "output":
|
|
512
|
-
keys = _.keys(this.
|
|
513
|
+
keys = _.keys(this.getCurrentMetanode().output);
|
|
513
514
|
keys = _.map(keys, k => this.outputPrefix + k);
|
|
514
515
|
break;
|
|
515
516
|
case "modules":
|
|
516
|
-
keys = _.keys(this.
|
|
517
|
+
keys = _.keys(this.getCurrentMetanode().modules);
|
|
517
518
|
break;
|
|
518
519
|
case "ui":
|
|
519
|
-
keys = _.keys(this.
|
|
520
|
+
keys = _.keys(this.getCurrentMetanode().ui);
|
|
520
521
|
break;
|
|
521
522
|
default:
|
|
522
523
|
if (type === undefined) {
|
|
523
|
-
keys = [].concat(_.map(_.keys(this.
|
|
524
|
-
.concat(_.map(_.keys(this.
|
|
525
|
-
.concat(_.keys(this.
|
|
526
|
-
.concat(_.keys(this.
|
|
524
|
+
keys = [].concat(_.map(_.keys(this.getCurrentMetanode().input), k => this.inputPrefix + k))
|
|
525
|
+
.concat(_.map(_.keys(this.getCurrentMetanode().output), k => this.outputPrefix + k))
|
|
526
|
+
.concat(_.keys(this.getCurrentMetanode().modules))
|
|
527
|
+
.concat(_.keys(this.getCurrentMetanode().ui));
|
|
527
528
|
} else {
|
|
528
529
|
throw new Error('unknown node type: ' + type);
|
|
529
530
|
}
|
|
@@ -629,7 +630,7 @@ class GraphModel {
|
|
|
629
630
|
class GraphNode {
|
|
630
631
|
constructor(m, id, example = false) {
|
|
631
632
|
this.m = m;
|
|
632
|
-
this.app = this.m.
|
|
633
|
+
this.app = this.m.getCurrentMetanode();
|
|
633
634
|
this.id = id;
|
|
634
635
|
this.uniqId = this.m.getCurrentMetanodePath() + '->' + this.id;
|
|
635
636
|
|
|
@@ -1446,10 +1447,10 @@ class GraphNode {
|
|
|
1446
1447
|
var collectInputLinks = (def, id) => collectLinks(def, this.m.inputPrefix + id);
|
|
1447
1448
|
var collectOutputLinks = (def, id) => collectLinks(def, this.m.outputPrefix + id);
|
|
1448
1449
|
|
|
1449
|
-
_.each(this.m.
|
|
1450
|
-
_.each(this.m.
|
|
1451
|
-
_.each(this.m.
|
|
1452
|
-
_.each(this.m.
|
|
1450
|
+
_.each(this.m.getCurrentMetanode().modules, collectLinks);
|
|
1451
|
+
_.each(this.m.getCurrentMetanode().ui, collectLinks);
|
|
1452
|
+
_.each(this.m.getCurrentMetanode().input, collectInputLinks);
|
|
1453
|
+
_.each(this.m.getCurrentMetanode().output, collectOutputLinks);
|
|
1453
1454
|
return links;
|
|
1454
1455
|
}
|
|
1455
1456
|
|
|
@@ -1464,7 +1465,7 @@ class GraphNode {
|
|
|
1464
1465
|
}
|
|
1465
1466
|
});
|
|
1466
1467
|
};
|
|
1467
|
-
_.each(this.m.
|
|
1468
|
+
_.each(this.m.getCurrentMetanode().ui, collectEvents);
|
|
1468
1469
|
return events;
|
|
1469
1470
|
}
|
|
1470
1471
|
|
|
@@ -1579,8 +1580,11 @@ class GraphNode {
|
|
|
1579
1580
|
// pos: { top: Integer, left: Integer }
|
|
1580
1581
|
setPosition(pos) {
|
|
1581
1582
|
this.def.graph = this.def.graph || {};
|
|
1582
|
-
this.def.graph.position
|
|
1583
|
-
|
|
1583
|
+
var curPos = this.def.graph.position;
|
|
1584
|
+
if (!curPos || curPos.top != pos.top || curPos.left != pos.left) {
|
|
1585
|
+
this.def.graph.position = pos;
|
|
1586
|
+
this.m.save();
|
|
1587
|
+
}
|
|
1584
1588
|
}
|
|
1585
1589
|
|
|
1586
1590
|
getPosition() {
|
package/js/src/m/History.js
CHANGED
|
@@ -14,7 +14,7 @@ class History {
|
|
|
14
14
|
this.states = []; // all states, save as json diffs
|
|
15
15
|
|
|
16
16
|
this._holdSaving = false; // if true, save() will have no effect
|
|
17
|
-
this.maxStates =
|
|
17
|
+
this.maxStates = 100; // to be changed accordingly
|
|
18
18
|
|
|
19
19
|
this.current = -1;
|
|
20
20
|
this.lastState = null;
|
|
@@ -49,6 +49,7 @@ class History {
|
|
|
49
49
|
this.states = [];
|
|
50
50
|
this.current = -1;
|
|
51
51
|
this.origin = origin;
|
|
52
|
+
this.lastState = origin;
|
|
52
53
|
}
|
|
53
54
|
|
|
54
55
|
getState(n) {
|
|
@@ -63,26 +64,27 @@ class History {
|
|
|
63
64
|
return this.getState(this.current);
|
|
64
65
|
}
|
|
65
66
|
|
|
67
|
+
clone(o) {
|
|
68
|
+
return JSON.parse(JSON.stringify(o));
|
|
69
|
+
}
|
|
70
|
+
|
|
66
71
|
save() {
|
|
67
72
|
if (!this._holdSaving) {
|
|
68
|
-
|
|
69
|
-
var
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
var currentAppClone = this.clone(this.m.data);
|
|
74
|
+
var diff = patcher.diff(this.lastState, currentAppClone);
|
|
75
|
+
if (diff) {
|
|
76
|
+
this.lastState = currentAppClone;
|
|
77
|
+
this.pushState(diff);
|
|
78
|
+
this.current++;
|
|
79
|
+
return this.clone(diff);
|
|
80
|
+
}
|
|
76
81
|
}
|
|
77
82
|
}
|
|
78
83
|
|
|
79
84
|
undo() {
|
|
80
85
|
if (this.current >= 0) {
|
|
81
|
-
console.time('undo');
|
|
82
86
|
patcher.unpatch(this.lastState, this.states[this.current]);
|
|
83
|
-
this.m.data =
|
|
84
|
-
//this.setState(this.current);
|
|
85
|
-
console.timeEnd('undo');
|
|
87
|
+
this.m.data = this.clone(this.lastState);
|
|
86
88
|
}
|
|
87
89
|
|
|
88
90
|
if (this.current >= 0) {
|
|
@@ -96,10 +98,8 @@ class History {
|
|
|
96
98
|
}
|
|
97
99
|
|
|
98
100
|
if (this.current >= 0) {
|
|
99
|
-
console.time('redo');
|
|
100
101
|
patcher.patch(this.lastState, this.states[this.current]);
|
|
101
|
-
this.m.data =
|
|
102
|
-
console.timeEnd('undo');
|
|
102
|
+
this.m.data = this.clone(this.lastState);
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
|
package/js/src/m/Merger.js
CHANGED
|
@@ -63,11 +63,11 @@ class Merger {
|
|
|
63
63
|
this._bindOutputs();
|
|
64
64
|
|
|
65
65
|
// 5. Our metanode definition is ready, add it to the app
|
|
66
|
-
this.m.
|
|
67
|
-
this.m.
|
|
66
|
+
this.m.getCurrentMetanode().metanodes = this.m.getCurrentMetanode().metanodes || {};
|
|
67
|
+
this.m.getCurrentMetanode().metanodes[metaboxName] = this.def;
|
|
68
68
|
|
|
69
69
|
// 6. Create a new node from this def
|
|
70
|
-
this.m.
|
|
70
|
+
this.m.getCurrentMetanode().modules[this.id] = {
|
|
71
71
|
"module": metaboxName,
|
|
72
72
|
"version": "*",
|
|
73
73
|
"graph": {
|
|
@@ -254,13 +254,13 @@ class Merger {
|
|
|
254
254
|
}
|
|
255
255
|
|
|
256
256
|
// move the node module definition (preserving the links between metabox's node)
|
|
257
|
-
this.def.modules[node.id] = this.m.
|
|
258
|
-
delete this.m.
|
|
257
|
+
this.def.modules[node.id] = this.m.getCurrentMetanode().modules[node.id];
|
|
258
|
+
delete this.m.getCurrentMetanode().modules[node.id];
|
|
259
259
|
|
|
260
260
|
if (node.isMetanode()) {
|
|
261
261
|
// if the metanode isn't still in use in the main app, remove def from here
|
|
262
262
|
if (!this.m.isMetanodeUsed(node.def.module)) {
|
|
263
|
-
delete this.m.
|
|
263
|
+
delete this.m.getCurrentMetanode().metanodes[node.def.module];
|
|
264
264
|
}
|
|
265
265
|
}
|
|
266
266
|
});
|