@dualbox/editor 1.0.9 → 1.0.11
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/html/editor.html +1 -0
- package/js/dist/GraphEditor.js +70 -21
- package/js/src/GraphEditor.js +12 -1
- package/js/src/v/GraphView.js +57 -19
- package/package.json +1 -1
package/js/src/GraphEditor.js
CHANGED
|
@@ -66,6 +66,10 @@ class DualboxEditor {
|
|
|
66
66
|
// signature: find( name, version ), return a Promise which, when resolved, is a package.json
|
|
67
67
|
this.loadPackage = (name, version) => {
|
|
68
68
|
version = version || "*";
|
|
69
|
+
if( name.startsWith('dualbox-core') ) {
|
|
70
|
+
name = "@dualbox/dualbox";
|
|
71
|
+
}
|
|
72
|
+
|
|
69
73
|
return new Promise((resolve, reject) => {
|
|
70
74
|
if( this.packages[name] ) {
|
|
71
75
|
resolve(this.packages[name]);
|
|
@@ -104,10 +108,17 @@ class DualboxEditor {
|
|
|
104
108
|
this.loadCorePackages();
|
|
105
109
|
|
|
106
110
|
if( attrs.json ) {
|
|
107
|
-
this.
|
|
111
|
+
this.onReady(() => {
|
|
112
|
+
this.setApp(attrs.json);
|
|
113
|
+
});
|
|
108
114
|
}
|
|
109
115
|
}
|
|
110
116
|
|
|
117
|
+
// call cb when the editor is initialized
|
|
118
|
+
onReady(cb) {
|
|
119
|
+
this.v.onReady(cb);
|
|
120
|
+
}
|
|
121
|
+
|
|
111
122
|
loadCorePackages() {
|
|
112
123
|
this.loadPackage('@dualbox/dualbox');
|
|
113
124
|
this.loadPackage('dualbox-core-if');
|
package/js/src/v/GraphView.js
CHANGED
|
@@ -60,6 +60,8 @@ class GraphView {
|
|
|
60
60
|
this.cssCode = null;
|
|
61
61
|
|
|
62
62
|
// load the main template
|
|
63
|
+
this.initialized = false;
|
|
64
|
+
this.initializing = false;
|
|
63
65
|
this.initialize();
|
|
64
66
|
}
|
|
65
67
|
|
|
@@ -77,29 +79,65 @@ class GraphView {
|
|
|
77
79
|
});
|
|
78
80
|
}
|
|
79
81
|
|
|
82
|
+
onReady(cb) {
|
|
83
|
+
if( this.initialized ) {
|
|
84
|
+
if(cb) cb();
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
setTimeout(() => {
|
|
88
|
+
this.onReady(cb);
|
|
89
|
+
}, 100);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
80
93
|
initialize() {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
94
|
+
if( !this.initializing && !this.initialized ) {
|
|
95
|
+
this.initializing = true;
|
|
96
|
+
|
|
97
|
+
var templates = { "main": false, "addNode" : false };
|
|
98
|
+
var templateInitialized = (name) => {
|
|
99
|
+
if( templates[name] == false ) templates[name] = true;
|
|
100
|
+
|
|
101
|
+
var allInitialized = true;
|
|
102
|
+
_.each(templates, (initialized, name) => {
|
|
103
|
+
if( !initialized ) {
|
|
104
|
+
allInitialized = false;
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
if( allInitialized ) {
|
|
109
|
+
this.initializing = false;
|
|
110
|
+
this.initialized = true;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// add main template
|
|
115
|
+
this.templateMgr.appendTemplate(this.div, "main", {showLoadSaveButtons: this.attrs.showLoadSaveButtons}, () => {
|
|
116
|
+
// for convenience, define thoses once the main div is ready
|
|
117
|
+
this.div.ready(() => {
|
|
118
|
+
this.graphContainer = this.div.find('.dualbox-graph-container');
|
|
119
|
+
this.canvas = this.div.find('.dualbox-graph-canvas');
|
|
120
|
+
this.selector = new Selector(this, this.graphContainer);
|
|
121
|
+
this.translater = new Translater(this, this.graphContainer, this.canvas);
|
|
122
|
+
this.zoomer = new Zoomer(this, this.graphContainer, this.canvas);
|
|
123
|
+
this.jsPlumbInstance = jsPlumb.getInstance({
|
|
124
|
+
DragOptions: { cursor: 'pointer', zIndex: 2500 }, // default drag options
|
|
125
|
+
Container: "dualbox-graph-canvas"
|
|
126
|
+
});
|
|
127
|
+
this.style.setDefault();
|
|
128
|
+
this.initializeListeners();
|
|
129
|
+
this.setNavigation();
|
|
130
|
+
this.canvasSizeHandler = new CanvasSizeHandler(this, this.canvas);
|
|
131
|
+
this.appManager = new AppManager(this, this.div.find('.application') );
|
|
132
|
+
|
|
133
|
+
templateInitialized("main");
|
|
93
134
|
});
|
|
94
|
-
this.style.setDefault();
|
|
95
|
-
this.initializeListeners();
|
|
96
|
-
this.setNavigation();
|
|
97
|
-
this.canvasSizeHandler = new CanvasSizeHandler(this, this.canvas);
|
|
98
|
-
this.appManager = new AppManager(this, this.div.find('.application') );
|
|
99
135
|
});
|
|
100
|
-
});
|
|
101
136
|
|
|
102
|
-
|
|
137
|
+
this.templateMgr.appendTemplate(this.div, "addNode", {}, () => {
|
|
138
|
+
templateInitialized("addNode");
|
|
139
|
+
}); // "add node" modal
|
|
140
|
+
}
|
|
103
141
|
}
|
|
104
142
|
|
|
105
143
|
// bind jsplumb events
|