@dualbox/editor 1.0.1 → 1.0.2
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/src/GraphEditor.js +159 -0
- package/js/src/c/GraphController.js +646 -0
- package/js/src/libs/CodeMirror.js +8 -0
- package/js/src/libs/fontawesome.js +1 -0
- package/js/src/libs/jsoneditor.css +2 -0
- package/js/src/libs/jsoneditor.js +4 -0
- package/js/src/m/DualboxUtils.js +35 -0
- package/js/src/m/GraphModel.js +2167 -0
- package/js/src/m/History.js +94 -0
- package/js/src/m/Merger.js +357 -0
- package/js/src/v/AppManager.js +61 -0
- package/js/src/v/CanvasSizeHandler.js +136 -0
- package/js/src/v/ContextMenu.css +45 -0
- package/js/src/v/ContextMenu.js +239 -0
- package/js/src/v/GraphView.js +928 -0
- package/js/src/v/PlumbStyle.js +254 -0
- package/js/src/v/Selector.js +239 -0
- package/js/src/v/TemplateManager.js +79 -0
- package/js/src/v/Translater.js +174 -0
- package/js/src/v/Utils.js +7 -0
- package/js/src/v/Zoomer.js +201 -0
- package/js/src/v/templates/addNode.css +45 -0
- package/js/src/v/templates/addNode.html +62 -0
- package/js/src/v/templates/addNode.js +34 -0
- package/js/src/v/templates/debugNodeInfos.css +5 -0
- package/js/src/v/templates/debugNodeInfos.html +336 -0
- package/js/src/v/templates/debugNodeInfos.js +31 -0
- package/js/src/v/templates/editMainSettings.css +67 -0
- package/js/src/v/templates/editMainSettings.html +265 -0
- package/js/src/v/templates/editMainSettings.js +240 -0
- package/js/src/v/templates/editNodeSettings.css +86 -0
- package/js/src/v/templates/editNodeSettings.html +539 -0
- package/js/src/v/templates/editNodeSettings.js +356 -0
- package/js/src/v/templates/graphNode.css +333 -0
- package/js/src/v/templates/graphNode.html +227 -0
- package/js/src/v/templates/graphNode.js +412 -0
- package/js/src/v/templates/main.css +353 -0
- package/js/src/v/templates/main.html +149 -0
- package/js/src/v/templates/main.js +511 -0
- package/js/src/v/templates/searchResults.css +50 -0
- package/js/src/v/templates/searchResults.html +46 -0
- package/js/src/v/templates/searchResults.js +176 -0
- package/package.json +4 -3
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
const _ = require('lodash');
|
|
2
|
+
|
|
3
|
+
const GraphModel = require('./m/GraphModel');
|
|
4
|
+
const GraphView = require('./v/GraphView');
|
|
5
|
+
const GraphController = require('./c/GraphController');
|
|
6
|
+
const AppParser = require('@dualbox/dualbox-lib-appparser');
|
|
7
|
+
|
|
8
|
+
const jsplumbjs = require('jsplumb');
|
|
9
|
+
//const jsplumbcss = require('jsplumb/css/jsplumbtoolkit-defaults.css');
|
|
10
|
+
|
|
11
|
+
// Display dependencies
|
|
12
|
+
require('@dualbox/dualbox-lib-bootstrap'); // not working yet... why?
|
|
13
|
+
require('@dualbox/dualbox-lib-font-awesome');
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Main class of the Graph Editor
|
|
17
|
+
*/
|
|
18
|
+
class DualboxEditor {
|
|
19
|
+
// div: selector or jquery div
|
|
20
|
+
constructor(div, attrs) {
|
|
21
|
+
this.div = $(div);
|
|
22
|
+
this.attrs = attrs;
|
|
23
|
+
|
|
24
|
+
// MVC model
|
|
25
|
+
this.m = new GraphModel(this);
|
|
26
|
+
this.v = new GraphView(this, div, attrs);
|
|
27
|
+
this.c = new GraphController(this);
|
|
28
|
+
|
|
29
|
+
// bind links
|
|
30
|
+
this.v.m = this.c.m = this.m;
|
|
31
|
+
this.v.c = this.m.c = this.c;
|
|
32
|
+
this.c.v = this.m.v = this.v;
|
|
33
|
+
|
|
34
|
+
// cache for packages
|
|
35
|
+
this.packages = {};
|
|
36
|
+
|
|
37
|
+
// the function to search for modules
|
|
38
|
+
// attr.search signature: search( text, cb )
|
|
39
|
+
// callback signature: cb( err, packages ), packages is an array of package.json
|
|
40
|
+
this.search = (text) => {
|
|
41
|
+
return new Promise((resolve, reject) => {
|
|
42
|
+
attrs.search(text, (err, packages) => {
|
|
43
|
+
if( err ) {
|
|
44
|
+
reject(err);
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
// cache packages in this.packages
|
|
48
|
+
_.each(packages, (r) => {
|
|
49
|
+
if( !this.packages[r.name] ) {
|
|
50
|
+
this.packages[r.name] = r;
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
this.searchResults = packages;
|
|
55
|
+
resolve(packages);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
this.searchResults = null;
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
// the function to find module by name and version (with cache)
|
|
64
|
+
// signature: find( name, version ), return a Promise which, when resolved, is a package.json
|
|
65
|
+
this.loadPackage = (name, version) => {
|
|
66
|
+
version = version || "*";
|
|
67
|
+
return new Promise((resolve, reject) => {
|
|
68
|
+
if( this.packages[name] ) {
|
|
69
|
+
resolve(this.packages[name]);
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
// mark the package as beeing resolved
|
|
73
|
+
attrs.find(name, version, (err, result) => {
|
|
74
|
+
if( err ) {
|
|
75
|
+
reject(err);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
this.packages[name] = result; // cache result
|
|
79
|
+
resolve(result);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
})
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// the function to require a dualbox module
|
|
87
|
+
this.require = (name, version, cb) => {
|
|
88
|
+
return require(name); // TODO: local only for now
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// export itself top window
|
|
92
|
+
window.dualboxEditor = this;
|
|
93
|
+
|
|
94
|
+
// Safety when the user leave the page,
|
|
95
|
+
// if not already defined externally
|
|
96
|
+
if(!window.onbeforeunload){
|
|
97
|
+
window.onbeforeunload = function() {
|
|
98
|
+
return "Unsaved changes will be lost, are you sure you want to leave the editor?";
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
this.loadCorePackages();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
loadCorePackages() {
|
|
106
|
+
this.loadPackage('@dualbox/dualbox');
|
|
107
|
+
this.loadPackage('dualbox-core-if');
|
|
108
|
+
this.loadPackage('dualbox-core-value');
|
|
109
|
+
this.loadPackage('dualbox-core-from-json');
|
|
110
|
+
this.loadPackage('dualbox-core-to-json');
|
|
111
|
+
this.loadPackage('dualbox-core-script');
|
|
112
|
+
this.loadPackage('dualbox-core-switch');
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
setApp(json) {
|
|
116
|
+
this.c.load(json);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
getApp() {
|
|
120
|
+
this.m.get();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// load all packages needed in the json
|
|
124
|
+
// return a Promise
|
|
125
|
+
loadPackages(json) {
|
|
126
|
+
var promises = []; // array of promises
|
|
127
|
+
|
|
128
|
+
var parser = new AppParser(json);
|
|
129
|
+
parser.eachPackage((name, version) => {
|
|
130
|
+
promises.push( this.loadPackage(name, version) );
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
// also load core nodes
|
|
134
|
+
promises.push( this.loadPackage('dualbox-core-if', '*') );
|
|
135
|
+
promises.push( this.loadPackage('dualbox-core-value', '*') );
|
|
136
|
+
promises.push( this.loadPackage('dualbox-core-from-json', '*') );
|
|
137
|
+
promises.push( this.loadPackage('dualbox-core-to-json', '*') );
|
|
138
|
+
promises.push( this.loadPackage('dualbox-core-script', '*') );
|
|
139
|
+
promises.push( this.loadPackage('dualbox-core-switch', '*') );
|
|
140
|
+
|
|
141
|
+
return Promise.all(promises);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// sync version of this.loadPackage. Will crash if the package has not been loaded yet
|
|
145
|
+
getPackage(name, version) {
|
|
146
|
+
if( this.packages[name] === undefined ) throw "Package " + name + " has not been loaded yet.";
|
|
147
|
+
return this.packages[name];
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// try to export in window if in browser context
|
|
152
|
+
try {
|
|
153
|
+
window.DualboxEditor = DualboxEditor;
|
|
154
|
+
}
|
|
155
|
+
catch(e) {};
|
|
156
|
+
|
|
157
|
+
// node.js export
|
|
158
|
+
module.exports = DualboxEditor;
|
|
159
|
+
|