@dualbox/editor 1.0.35 → 1.0.37
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 +231 -227
- package/js/dist/GraphEditor.min.js +230 -226
- package/js/src/GraphEditor.js +246 -242
- package/package.json +1 -1
|
@@ -103812,267 +103812,271 @@ var jsplumb_6 = jsplumb.jsPlumb;
|
|
|
103812
103812
|
* Main class of the Graph Editor
|
|
103813
103813
|
*/
|
|
103814
103814
|
class DualboxEditor {
|
|
103815
|
-
|
|
103816
|
-
|
|
103817
|
-
|
|
103818
|
-
|
|
103819
|
-
|
|
103820
|
-
|
|
103821
|
-
|
|
103822
|
-
|
|
103823
|
-
|
|
103824
|
-
|
|
103825
|
-
|
|
103826
|
-
|
|
103827
|
-
|
|
103828
|
-
|
|
103829
|
-
|
|
103830
|
-
|
|
103831
|
-
|
|
103832
|
-
|
|
103833
|
-
|
|
103834
|
-
|
|
103835
|
-
|
|
103836
|
-
|
|
103837
|
-
|
|
103838
|
-
|
|
103839
|
-
|
|
103840
|
-
|
|
103841
|
-
|
|
103842
|
-
|
|
103843
|
-
|
|
103844
|
-
|
|
103845
|
-
|
|
103846
|
-
|
|
103847
|
-
|
|
103848
|
-
|
|
103849
|
-
|
|
103850
|
-
|
|
103851
|
-
|
|
103852
|
-
|
|
103853
|
-
|
|
103815
|
+
// div: selector or jquery div
|
|
103816
|
+
constructor(div, attrs) {
|
|
103817
|
+
this.div = $(div);
|
|
103818
|
+
this.div.addClass("main-editor-div");
|
|
103819
|
+
this.attrs = attrs;
|
|
103820
|
+
|
|
103821
|
+
// export itself top window
|
|
103822
|
+
window.dualboxEditor = this;
|
|
103823
|
+
|
|
103824
|
+
this.rootAppName = attrs.name ? attrs.name : "Application";
|
|
103825
|
+
|
|
103826
|
+
// MVC model
|
|
103827
|
+
this.m = new GraphModel(this);
|
|
103828
|
+
this.v = new GraphView(this, div, attrs);
|
|
103829
|
+
this.c = new GraphController(this);
|
|
103830
|
+
|
|
103831
|
+
// bind links
|
|
103832
|
+
this.v.m = this.c.m = this.m;
|
|
103833
|
+
this.v.c = this.m.c = this.c;
|
|
103834
|
+
this.c.v = this.m.v = this.v;
|
|
103835
|
+
|
|
103836
|
+
// cache for packages
|
|
103837
|
+
this.packages = {};
|
|
103838
|
+
this.DualBox = null; // local dualbox, for editor use
|
|
103839
|
+
|
|
103840
|
+
// the function to search for modules
|
|
103841
|
+
// attr.search signature: search( text, cb )
|
|
103842
|
+
// callback signature: cb( err, packages ), packages is an array of package.json
|
|
103843
|
+
this.search = (text, type) => {
|
|
103844
|
+
return new Promise((resolve, reject) => {
|
|
103845
|
+
attrs.search(text, (err, packages) => {
|
|
103846
|
+
if (err) {
|
|
103847
|
+
reject(err);
|
|
103848
|
+
} else {
|
|
103849
|
+
// cache packages in this.packages
|
|
103850
|
+
lodash.each(packages, r => {
|
|
103851
|
+
if (!this.packages[r.name]) {
|
|
103852
|
+
this.packages[r.name] = r;
|
|
103853
|
+
}
|
|
103854
|
+
});
|
|
103855
|
+
|
|
103856
|
+
if (type) {
|
|
103857
|
+
packages = lodash.filter(packages, o => {
|
|
103858
|
+
return (
|
|
103859
|
+
o.name.startsWith("@dualbox/dualbox-" + type) ||
|
|
103860
|
+
(type == "module" && o.name.startsWith("dualbox-core"))
|
|
103861
|
+
);
|
|
103862
|
+
});
|
|
103863
|
+
}
|
|
103864
|
+
resolve(packages);
|
|
103865
|
+
}
|
|
103866
|
+
});
|
|
103854
103867
|
});
|
|
103868
|
+
};
|
|
103855
103869
|
|
|
103856
|
-
|
|
103857
|
-
|
|
103858
|
-
|
|
103859
|
-
|
|
103860
|
-
|
|
103861
|
-
|
|
103862
|
-
|
|
103870
|
+
this.types = [];
|
|
103871
|
+
this.getRootTypes = function () {
|
|
103872
|
+
if (lodash.isEmpty(this.types)) {
|
|
103873
|
+
return new Promise((resolve, reject) => {
|
|
103874
|
+
this.search("dualbox-type-")
|
|
103875
|
+
.then(packages => {
|
|
103876
|
+
this.types = lodash.filter(packages, p => {
|
|
103877
|
+
var isType = p.name.startsWith("@dualbox/dualbox-type");
|
|
103878
|
+
var hasTypeDef = lodash.get(p, "dualbox.type");
|
|
103879
|
+
|
|
103880
|
+
if (isType && !hasTypeDef) {
|
|
103881
|
+
console.error(
|
|
103882
|
+
"Type package " +
|
|
103883
|
+
p.name +
|
|
103884
|
+
" has no dualbox Type description.\n" +
|
|
103885
|
+
"Type was not imported"
|
|
103886
|
+
);
|
|
103887
|
+
}
|
|
103888
|
+
return isType && hasTypeDef;
|
|
103889
|
+
});
|
|
103890
|
+
resolve(this.types);
|
|
103891
|
+
})
|
|
103892
|
+
.catch(e => {
|
|
103893
|
+
reject(e);
|
|
103894
|
+
});
|
|
103895
|
+
});
|
|
103896
|
+
} else {
|
|
103897
|
+
return Promise.resolve(this.types);
|
|
103863
103898
|
}
|
|
103864
|
-
|
|
103865
|
-
}
|
|
103866
|
-
});
|
|
103867
|
-
});
|
|
103868
|
-
};
|
|
103899
|
+
};
|
|
103869
103900
|
|
|
103870
|
-
|
|
103871
|
-
|
|
103872
|
-
|
|
103873
|
-
|
|
103874
|
-
this.search("dualbox-type-")
|
|
103875
|
-
.then(packages => {
|
|
103876
|
-
this.types = lodash.filter(packages, p => {
|
|
103877
|
-
var isType = p.name.startsWith("@dualbox/dualbox-type");
|
|
103878
|
-
var hasTypeDef = lodash.get(p, "dualbox.type");
|
|
103879
|
-
|
|
103880
|
-
if (isType && !hasTypeDef) {
|
|
103881
|
-
console.error(
|
|
103882
|
-
"Type package " +
|
|
103883
|
-
p.name +
|
|
103884
|
-
" has no dualbox Type description.\n" +
|
|
103885
|
-
"Type was not imported"
|
|
103886
|
-
);
|
|
103887
|
-
}
|
|
103888
|
-
return isType && hasTypeDef;
|
|
103889
|
-
});
|
|
103890
|
-
resolve(this.types);
|
|
103891
|
-
})
|
|
103892
|
-
.catch(e => {
|
|
103893
|
-
reject(e);
|
|
103894
|
-
});
|
|
103895
|
-
});
|
|
103896
|
-
} else {
|
|
103897
|
-
return Promise.resolve(this.types);
|
|
103898
|
-
}
|
|
103899
|
-
};
|
|
103901
|
+
this.getAvailableTypes = async function () {
|
|
103902
|
+
var types = await this.getRootTypes();
|
|
103903
|
+
return lodash.map(types, t => lodash.get(t, "dualbox.type.name"));
|
|
103904
|
+
};
|
|
103900
103905
|
|
|
103901
|
-
|
|
103902
|
-
|
|
103903
|
-
|
|
103904
|
-
|
|
103906
|
+
// the function to find module by name and version (with cache)
|
|
103907
|
+
// signature: find( name, version ), return a Promise which, when resolved, is a package.json
|
|
103908
|
+
this.loadPackage = (name, version) => {
|
|
103909
|
+
version = version || "*";
|
|
103910
|
+
|
|
103911
|
+
return new Promise((resolve, reject) => {
|
|
103912
|
+
if (name.startsWith("dualbox-core")) {
|
|
103913
|
+
var pkg = null;
|
|
103914
|
+
lodash.each(this.DualBox.core, corePackage => {
|
|
103915
|
+
if (corePackage.name == name) {
|
|
103916
|
+
pkg = corePackage;
|
|
103917
|
+
return false;
|
|
103918
|
+
}
|
|
103919
|
+
});
|
|
103905
103920
|
|
|
103906
|
-
|
|
103907
|
-
|
|
103908
|
-
|
|
103909
|
-
|
|
103921
|
+
if (pkg) {
|
|
103922
|
+
this.packages[name] = pkg;
|
|
103923
|
+
resolve(pkg);
|
|
103924
|
+
} else {
|
|
103925
|
+
reject("Couldn't resolve core package: " + name);
|
|
103926
|
+
}
|
|
103927
|
+
return;
|
|
103928
|
+
}
|
|
103910
103929
|
|
|
103911
|
-
|
|
103912
|
-
|
|
103913
|
-
|
|
103914
|
-
|
|
103915
|
-
|
|
103916
|
-
|
|
103917
|
-
|
|
103918
|
-
|
|
103919
|
-
|
|
103930
|
+
var loadScript = (pkg, cb) => {
|
|
103931
|
+
if (attrs.load) {
|
|
103932
|
+
attrs.load(pkg.name, pkg.version, cb);
|
|
103933
|
+
} else {
|
|
103934
|
+
// Local editor. Bind the callback on the local script load
|
|
103935
|
+
var script = $('script[data-pkg="' + pkg.name + '"]');
|
|
103936
|
+
if (!script) {
|
|
103937
|
+
throw "Couldn't find script in the current document: " +
|
|
103938
|
+
pkg.name +
|
|
103939
|
+
". Did you forget gulp link-editor ?";
|
|
103940
|
+
}
|
|
103920
103941
|
|
|
103921
|
-
|
|
103922
|
-
|
|
103923
|
-
|
|
103924
|
-
|
|
103925
|
-
|
|
103926
|
-
|
|
103927
|
-
|
|
103928
|
-
}
|
|
103942
|
+
if (script.attr("data-loaded") === "true") {
|
|
103943
|
+
cb();
|
|
103944
|
+
return;
|
|
103945
|
+
} else {
|
|
103946
|
+
script[0].addEventListener("error", function () {
|
|
103947
|
+
throw "Failed to load script " + pkg.name;
|
|
103948
|
+
});
|
|
103929
103949
|
|
|
103930
|
-
|
|
103931
|
-
|
|
103932
|
-
|
|
103933
|
-
|
|
103934
|
-
|
|
103935
|
-
|
|
103936
|
-
|
|
103937
|
-
|
|
103938
|
-
|
|
103939
|
-
|
|
103940
|
-
}
|
|
103950
|
+
var timeout = setTimeout(function () {
|
|
103951
|
+
cb("Failed to load " + pkg.name + " after 5 seconds");
|
|
103952
|
+
}, 5000);
|
|
103953
|
+
script[0].addEventListener("load", () => {
|
|
103954
|
+
clearTimeout(timeout);
|
|
103955
|
+
cb();
|
|
103956
|
+
});
|
|
103957
|
+
}
|
|
103958
|
+
}
|
|
103959
|
+
};
|
|
103941
103960
|
|
|
103942
|
-
|
|
103943
|
-
|
|
103944
|
-
|
|
103945
|
-
|
|
103946
|
-
|
|
103947
|
-
|
|
103948
|
-
|
|
103949
|
-
|
|
103950
|
-
|
|
103951
|
-
|
|
103952
|
-
|
|
103953
|
-
|
|
103954
|
-
|
|
103955
|
-
|
|
103956
|
-
|
|
103957
|
-
|
|
103958
|
-
|
|
103961
|
+
var onLoadedScript = err => {
|
|
103962
|
+
if (err) {
|
|
103963
|
+
reject(err);
|
|
103964
|
+
} else {
|
|
103965
|
+
window.require(name); // make sure the package is required at least once
|
|
103966
|
+
resolve(this.packages[name]);
|
|
103967
|
+
}
|
|
103968
|
+
};
|
|
103969
|
+
|
|
103970
|
+
// we need to find the package.json and make sure the script is loaded
|
|
103971
|
+
if (this.packages[name]) {
|
|
103972
|
+
try {
|
|
103973
|
+
loadScript(this.packages[name], onLoadedScript);
|
|
103974
|
+
} catch (e) {
|
|
103975
|
+
reject(e);
|
|
103976
|
+
}
|
|
103977
|
+
} else {
|
|
103978
|
+
// mark the package as beeing resolved
|
|
103979
|
+
attrs.find(name, version, (err, result) => {
|
|
103980
|
+
if (err) {
|
|
103981
|
+
reject(err);
|
|
103982
|
+
} else {
|
|
103983
|
+
this.packages[name] = result; // cache result
|
|
103984
|
+
loadScript(this.packages[name], onLoadedScript);
|
|
103985
|
+
}
|
|
103986
|
+
});
|
|
103987
|
+
}
|
|
103988
|
+
});
|
|
103959
103989
|
};
|
|
103960
103990
|
|
|
103961
|
-
|
|
103962
|
-
|
|
103963
|
-
|
|
103964
|
-
} else {
|
|
103965
|
-
require(name); // make sure the package is required at least once
|
|
103966
|
-
resolve(this.packages[name]);
|
|
103967
|
-
}
|
|
103991
|
+
// the function to require a dualbox module
|
|
103992
|
+
this.require = (name, version, cb) => {
|
|
103993
|
+
return require(name); // TODO: local only for now
|
|
103968
103994
|
};
|
|
103969
103995
|
|
|
103970
|
-
//
|
|
103971
|
-
if
|
|
103972
|
-
|
|
103973
|
-
|
|
103974
|
-
|
|
103975
|
-
|
|
103976
|
-
}
|
|
103977
|
-
} else {
|
|
103978
|
-
// mark the package as beeing resolved
|
|
103979
|
-
attrs.find(name, version, (err, result) => {
|
|
103980
|
-
if (err) {
|
|
103981
|
-
reject(err);
|
|
103982
|
-
} else {
|
|
103983
|
-
this.packages[name] = result; // cache result
|
|
103984
|
-
loadScript(this.packages[name], onLoadedScript);
|
|
103985
|
-
}
|
|
103986
|
-
});
|
|
103996
|
+
// Safety when the user leave the page,
|
|
103997
|
+
// if not already defined externally
|
|
103998
|
+
if (!window.onbeforeunload) {
|
|
103999
|
+
window.onbeforeunload = function () {
|
|
104000
|
+
return "Unsaved changes will be lost, are you sure you want to leave the editor?";
|
|
104001
|
+
};
|
|
103987
104002
|
}
|
|
103988
|
-
});
|
|
103989
|
-
};
|
|
103990
|
-
|
|
103991
|
-
// the function to require a dualbox module
|
|
103992
|
-
this.require = (name, version, cb) => {
|
|
103993
|
-
return require(name); // TODO: local only for now
|
|
103994
|
-
};
|
|
103995
|
-
|
|
103996
|
-
// Safety when the user leave the page,
|
|
103997
|
-
// if not already defined externally
|
|
103998
|
-
if (!window.onbeforeunload) {
|
|
103999
|
-
window.onbeforeunload = function() {
|
|
104000
|
-
return "Unsaved changes will be lost, are you sure you want to leave the editor?";
|
|
104001
|
-
};
|
|
104002
|
-
}
|
|
104003
104003
|
|
|
104004
|
-
|
|
104004
|
+
this.loadCorePackages();
|
|
104005
104005
|
|
|
104006
|
-
|
|
104007
|
-
|
|
104008
|
-
|
|
104009
|
-
|
|
104010
|
-
|
|
104006
|
+
if (attrs.json) {
|
|
104007
|
+
this.onReady(() => {
|
|
104008
|
+
var p = this.setApp(attrs.json);
|
|
104009
|
+
if (attrs.onLoaded) {
|
|
104010
|
+
p.then(attrs.onLoaded);
|
|
104011
|
+
}
|
|
104012
|
+
});
|
|
104011
104013
|
}
|
|
104012
|
-
});
|
|
104013
104014
|
}
|
|
104014
|
-
}
|
|
104015
104015
|
|
|
104016
|
-
|
|
104017
|
-
|
|
104018
|
-
|
|
104019
|
-
|
|
104016
|
+
// call cb when the editor is initialized
|
|
104017
|
+
onReady(cb) {
|
|
104018
|
+
this.v.onReady(cb);
|
|
104019
|
+
}
|
|
104020
104020
|
|
|
104021
|
-
|
|
104021
|
+
async loadCorePackages() {
|
|
104022
104022
|
|
|
104023
|
-
|
|
104024
|
-
|
|
104025
|
-
|
|
104026
|
-
|
|
104027
|
-
|
|
104028
|
-
|
|
104023
|
+
await this.loadPackage("@dualbox/dualbox");
|
|
104024
|
+
if (!window.DualBox && window.DualBox.start) {
|
|
104025
|
+
this.DualBox = window.DualBox = this.require("@dualbox/dualbox");
|
|
104026
|
+
} else {
|
|
104027
|
+
this.DualBox = window.DualBox;
|
|
104028
|
+
}
|
|
104029
|
+
lodash.each(this.DualBox.core, async corePackage => {
|
|
104030
|
+
await this.loadPackage(corePackage.name);
|
|
104031
|
+
});
|
|
104032
|
+
}
|
|
104029
104033
|
|
|
104030
|
-
|
|
104031
|
-
|
|
104032
|
-
|
|
104034
|
+
setApp(json) {
|
|
104035
|
+
return this.c.load(json);
|
|
104036
|
+
}
|
|
104033
104037
|
|
|
104034
|
-
|
|
104035
|
-
|
|
104036
|
-
|
|
104038
|
+
getApp() {
|
|
104039
|
+
this.m.get();
|
|
104040
|
+
}
|
|
104037
104041
|
|
|
104038
|
-
|
|
104039
|
-
|
|
104040
|
-
|
|
104041
|
-
|
|
104042
|
-
|
|
104042
|
+
// load all packages needed in the json
|
|
104043
|
+
// return a Promise
|
|
104044
|
+
loadPackages(json) {
|
|
104045
|
+
var promises = []; // array of promises
|
|
104046
|
+
this.promises = promises;
|
|
104043
104047
|
|
|
104044
|
-
|
|
104045
|
-
|
|
104046
|
-
|
|
104047
|
-
|
|
104048
|
+
var parser = new AppParser_1(json);
|
|
104049
|
+
parser.eachComponent((name, version) => {
|
|
104050
|
+
promises.push(this.loadPackage(name, version));
|
|
104051
|
+
});
|
|
104048
104052
|
|
|
104049
|
-
|
|
104050
|
-
|
|
104051
|
-
|
|
104052
|
-
|
|
104053
|
-
|
|
104054
|
-
|
|
104055
|
-
|
|
104056
|
-
|
|
104057
|
-
|
|
104053
|
+
/*
|
|
104054
|
+
// also load core nodes
|
|
104055
|
+
promises.push(this.loadPackage('dualbox-core-if', '*'));
|
|
104056
|
+
promises.push(this.loadPackage('dualbox-core-value', '*'));
|
|
104057
|
+
promises.push(this.loadPackage('dualbox-core-from-json', '*'));
|
|
104058
|
+
promises.push(this.loadPackage('dualbox-core-to-json', '*'));
|
|
104059
|
+
promises.push(this.loadPackage('dualbox-core-script', '*'));
|
|
104060
|
+
promises.push(this.loadPackage('dualbox-core-switch', '*'));
|
|
104061
|
+
*/
|
|
104058
104062
|
|
|
104059
|
-
|
|
104060
|
-
|
|
104063
|
+
return Promise.all(promises);
|
|
104064
|
+
}
|
|
104061
104065
|
|
|
104062
|
-
|
|
104063
|
-
|
|
104064
|
-
|
|
104065
|
-
|
|
104066
|
+
// sync version of this.loadPackage. Will crash if the package has not been loaded yet
|
|
104067
|
+
getPackage(name, version) {
|
|
104068
|
+
if (this.packages[name] === undefined) {
|
|
104069
|
+
throw "Package " + name + " has not been loaded yet.";
|
|
104070
|
+
}
|
|
104071
|
+
return this.packages[name];
|
|
104066
104072
|
}
|
|
104067
|
-
return this.packages[name];
|
|
104068
|
-
}
|
|
104069
104073
|
}
|
|
104070
104074
|
|
|
104071
104075
|
// try to export in window if in browser context
|
|
104072
104076
|
try {
|
|
104073
|
-
|
|
104077
|
+
window.DualboxEditor = DualboxEditor;
|
|
104074
104078
|
} catch (e) {
|
|
104075
|
-
|
|
104079
|
+
console.log("Could not export to window: " + e);
|
|
104076
104080
|
}
|
|
104077
104081
|
|
|
104078
104082
|
//export default DualboxEditor;
|