@dualbox/editor 1.0.78 → 1.0.80

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.
@@ -1012,6 +1012,29 @@ class GraphNode {
1012
1012
  }
1013
1013
  }
1014
1014
 
1015
+ checkTypeMatch(type, val) {
1016
+ let lowercaseType = type.toLowerCase();
1017
+ switch (lowercaseType) {
1018
+ case "string":
1019
+ if (typeof val !== "string") {
1020
+ throw "Expected string type but got " + type;
1021
+ }
1022
+ break;
1023
+ case "number":
1024
+ if (typeof val !== "number") {
1025
+ throw "Expected number type but got " + type;
1026
+ }
1027
+ break;
1028
+ case "boolean":
1029
+ if (typeof val !== "boolean") {
1030
+ throw "Expected boolean type but got " + type;
1031
+ }
1032
+ break;
1033
+ default:
1034
+ break;
1035
+ }
1036
+ }
1037
+
1015
1038
  getInputDefaultValue(inputName) {
1016
1039
  var pkg = this.getPackage();
1017
1040
  var pkgDefault = pkg && pkg.dualbox && pkg.dualbox.input && pkg.dualbox.input[inputName] && pkg.dualbox.input[inputName].value;
@@ -1025,6 +1048,7 @@ class GraphNode {
1025
1048
  }
1026
1049
 
1027
1050
  setInputDefaultValue(inputName, val) {
1051
+ this.checkTypeMatch(this.getInputType(inputName), val);
1028
1052
  this.def.defaultInputs = this.def.defaultInputs || {};
1029
1053
  this.def.defaultInputs[inputName] = val;
1030
1054
  this.m.save();
@@ -1103,6 +1127,7 @@ class GraphNode {
1103
1127
  }
1104
1128
 
1105
1129
  setAttributeValue(attrName, val) {
1130
+ this.checkTypeMatch(this.getAttributeType(attrName), val);
1106
1131
  this.def.attr = this.def.attr || {};
1107
1132
  this.def.attr[attrName] = val;
1108
1133
  this.m.save();
@@ -1901,34 +1926,78 @@ class GraphNode {
1901
1926
  // Deep search and replaces the given property value "prevVal" with "newVal"
1902
1927
 
1903
1928
  // remove the ui of id "id" from interface
1904
- var removeFromInterface = (o, id) => {
1905
- let newObject = _.clone(o);
1906
- let remove = false;
1907
-
1908
- _.each(o, (val, key) => {
1909
- if (key == "node" && val === id) {
1910
- remove = true;
1911
- } else if (typeof(val) === 'object' || typeof(val) === 'array') {
1912
- var cleaned = removeFromInterface(val, id);
1913
- if (cleaned === "remove") {
1914
- if (key === "dataset" || key === "attributes") {
1915
- remove = true; // delete 1 more upper level
1916
- } else {
1917
- _.remove(newObject, (v, k) => k == key);
1918
- }
1929
+ // var removeFromInterface = (o, id) => {
1930
+ // let newObject = _.clone(o);
1931
+
1932
+ // if (typeof o === "object" || typeof o === "array") {
1933
+ // for (let [key, val] of Object.entries(o)) {
1934
+ // let nodeId = _.get(val, ["attributes", "dataset", "node"]);
1935
+ // if (nodeId == id) {
1936
+ // _.unset(newObject, key);
1937
+ // } else {
1938
+ // newObject[key] = removeFromInterface(val, id);
1939
+ // }
1940
+ // }
1941
+ // }
1942
+
1943
+ // return newObject;
1944
+ // }
1945
+ // app.interface = removeFromInterface(app.interface, this.id);
1946
+
1947
+ var getUIPath = (o, id, path = []) => {
1948
+ let p = _.clone(path);
1949
+ let identification = ["attributes", "dataset", "node"];
1950
+
1951
+ if (typeof o === "object" || typeof o === "array") {
1952
+ for (let [key, val] of Object.entries(o)) {
1953
+ let nodeId = _.get(val, identification);
1954
+ if (nodeId == id) {
1955
+ return path.concat(key);
1919
1956
  } else {
1920
- newObject[key] = cleaned;
1957
+ let fullpath = getUIPath(val, id, path.concat(key));
1958
+ if (fullpath !== null) {
1959
+ return fullpath;
1960
+ }
1921
1961
  }
1922
1962
  }
1923
- });
1963
+ } else {
1964
+ return null;
1965
+ }
1924
1966
 
1925
- if (remove) {
1926
- return "remove";
1967
+ // if we arrive here, we didn't find a valid path parcouring children nodes
1968
+ return null;
1969
+ }
1970
+
1971
+ var removePath = (json, path) => {
1972
+ if (isNaN(parseInt(_.last(path)))) {
1973
+ _.unset(json, path); // not an array
1927
1974
  } else {
1928
- return newObject;
1975
+ // Check if it's an object or an element in an array
1976
+ if (path.length > 1) {
1977
+ let p = _.clone(path);
1978
+ let last = p.pop();
1979
+
1980
+ let parent = _.get(json, p);
1981
+ if (Array.isArray(parent)) {
1982
+ // Array, use _.remove instead
1983
+ _.remove(parent, (v, k) => k == last);
1984
+ _.set(json, p, parent);
1985
+ } else {
1986
+ _.unset(json, path); // not an array
1987
+ }
1988
+ } else {
1989
+ _.unset(json, path); // not an array
1990
+ }
1929
1991
  }
1992
+
1993
+ return json;
1994
+ }
1995
+
1996
+ let UIFullPath = getUIPath(app.interface, this.id);
1997
+ console.log("Found UI " + this.id + " at path " + UIFullPath);
1998
+ if (UIFullPath !== null) {
1999
+ app.interface = removePath(app.interface, UIFullPath);
1930
2000
  }
1931
- app.interface = removeFromInterface(app.interface, this.id);
1932
2001
 
1933
2002
  // remove this node from all app events (API) using it
1934
2003
  var removeFromAppEvents = (o, id) => {