@dualbox/editor 1.0.90 → 1.0.92

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.
@@ -18065,31 +18065,21 @@ class History {
18065
18065
  }
18066
18066
 
18067
18067
  // execute the callback and save the history as 1 change
18068
- batch(cb) {
18069
- let ret = this.ignore(cb);
18070
- if (ret && ret.then) {
18071
- // its a promise
18072
- return Promise.resolve(ret).then(() => {
18073
- return this.save();
18074
- });
18075
- } else {
18076
- return this.save();
18077
- }
18068
+ async batch(cb) {
18069
+ await this.ignore(cb);
18070
+ return this.save();
18078
18071
  }
18079
18072
 
18080
18073
  // ignore history saves during the time of the callback
18081
18074
  // if cb return a promise, wait until it's resolved and return a Promise
18082
- ignore(cb) {
18075
+ async ignore(cb) {
18083
18076
  this.holdSaving(true);
18084
18077
  let ret = cb();
18085
- if (ret && ret.then) {
18086
- // its a promise
18087
- return Promise.resolve(ret).then(() => {
18088
- this.holdSaving(false);
18089
- });
18090
- } else {
18091
- this.holdSaving(false);
18092
- }
18078
+
18079
+ // if cb returns a promise, wait for it
18080
+ let result = ret && ret.then ? await ret : ret;
18081
+ this.holdSaving(false);
18082
+ return result;
18093
18083
  }
18094
18084
  }
18095
18085
 
@@ -43719,20 +43709,12 @@ class GraphModel {
43719
43709
 
43720
43710
  // batch all changes in a function into one (for history save)
43721
43711
  // if cb returns a Promise, return a Promise that will be resolved once it's all done
43722
- batch(cb) {
43723
- var ret = this.history.batch(cb);
43724
- if (ret && ret.then) {
43725
- // it's a promise, wait for it
43726
- return Promise.resolve(ret).then((diff) => {
43727
- if (this.onChangeCb) {
43728
- this.onChangeCb(diff);
43729
- }
43730
- });
43731
- } else {
43732
- // not a promise, ret is our diff
43733
- let diff = ret;
43712
+ async batch(cb) {
43713
+ let diffChange = await this.history.batch(cb);
43714
+ if (diffChange && diffChange.diff && diffChange.hash) {
43715
+ let { diff, hash } = diffChange;
43734
43716
  if (this.onChangeCb) {
43735
- this.onChangeCb(diff);
43717
+ this.onChangeCb(diff, hash);
43736
43718
  }
43737
43719
  }
43738
43720
  }
@@ -43918,8 +43900,8 @@ class GraphModel {
43918
43900
  }
43919
43901
 
43920
43902
  // add pkg dependencies (lib, types, etc) to app graph
43921
- addDependencies(pkg) {
43922
- lodash.each(pkg.dependencies, async (dependencyVersion, dependencyName) => {
43903
+ async addDependencies(pkg) {
43904
+ for (const dependencyName of Object.keys(pkg.dependencies)) {
43923
43905
  if (utils.isLibrary(dependencyName) || utils.isType(dependencyName)) {
43924
43906
  console.log('[*] Adding dependency: ' + dependencyName);
43925
43907
  // await this.e.loadPackage(dependencyName, dependencyVersion); // Is this better ?
@@ -43928,10 +43910,10 @@ class GraphModel {
43928
43910
  this.data.root.libs[pkg.name] = pkg.version;
43929
43911
  await this.addDependencies(pkg);
43930
43912
  }
43931
- });
43913
+ }
43932
43914
  }
43933
43915
 
43934
- addNode(id, pkg) {
43916
+ async addNode(id, pkg) {
43935
43917
  console.log('adding node: ' + id);
43936
43918
 
43937
43919
  var desc = {
@@ -43946,7 +43928,7 @@ class GraphModel {
43946
43928
  return false;
43947
43929
  }
43948
43930
  var node = this.getCurrentMetanode().modules[id] = desc;
43949
- this.addDependencies(pkg); // async but no pb
43931
+ await this.addDependencies(pkg); // async but no pb
43950
43932
  } else if (utils.isUI(pkg.name)) {
43951
43933
  this.ensure('ui');
43952
43934
  if (this.getCurrentMetanode().ui[id]) {
@@ -43954,7 +43936,7 @@ class GraphModel {
43954
43936
  return false;
43955
43937
  }
43956
43938
  var node = this.getCurrentMetanode().ui[id] = desc;
43957
- this.addDependencies(pkg); // async but no pb
43939
+ await this.addDependencies(pkg); // async but no pb
43958
43940
  } else {
43959
43941
  // may be a metanode
43960
43942
  var nodeDef = idx_1(this.getCurrentMetanode(), o => o.metanodes[pkg.name]);
@@ -45788,8 +45770,6 @@ class GraphNode {
45788
45770
  });
45789
45771
  }
45790
45772
  });
45791
-
45792
- this.m.save();
45793
45773
  }
45794
45774
  }
45795
45775
 
@@ -90677,7 +90657,7 @@ class GraphController {
90677
90657
  }
90678
90658
 
90679
90659
  // Add a node from the search results
90680
- addNewBox(packageName, pos = null) {
90660
+ async addNewBox(packageName, pos = null) {
90681
90661
  // first, make sure the package is loaded
90682
90662
  this.e.loadPackage(packageName).then(async () => {
90683
90663
  var id = this.createId(packageName);
@@ -90692,8 +90672,8 @@ class GraphController {
90692
90672
  if (pkg) {
90693
90673
  // first, add node in the model
90694
90674
  // batch it so add node + set position + register to UI is 1 history change only
90695
- this.m.batch(async () => {
90696
- var nodeInfo = this.m.addNode(id, pkg);
90675
+ await this.m.batch(async () => {
90676
+ var nodeInfo = await this.m.addNode(id, pkg);
90697
90677
  if (nodeInfo) {
90698
90678
  if (pos) {
90699
90679
  var node = this.m.getNode(nodeInfo.id);
@@ -90717,7 +90697,7 @@ class GraphController {
90717
90697
  }
90718
90698
 
90719
90699
  // create a new metabox
90720
- addNewMetabox(name, json = {}, pos) {
90700
+ async addNewMetabox(name, json = {}, pos) {
90721
90701
  if (this.m.hasMetanode(name)) {
90722
90702
  sweetalert2_all("Can't add metabox", "metabox with name '" + name + "' already exists.", "error");
90723
90703
  } else {
@@ -90727,7 +90707,7 @@ class GraphController {
90727
90707
  // add 1 node of this metabox on the graph
90728
90708
  var id = this.createId(name);
90729
90709
 
90730
- this.m.addNode(id, {
90710
+ await this.m.addNode(id, {
90731
90711
  "name": name,
90732
90712
  "version": "*"
90733
90713
  });
@@ -91275,8 +91255,8 @@ class GraphController {
91275
91255
  return await navigator.clipboard.readText();
91276
91256
  }
91277
91257
 
91278
- deleteSelection() {
91279
- this.m.batch(() => {
91258
+ async deleteSelection() {
91259
+ await this.m.batch(() => {
91280
91260
  var selectedDivs = this.v.selector.getSelection();
91281
91261
  lodash.each(selectedDivs, (div) => {
91282
91262
  this.m.getNode($(div).attr('id')).remove();
@@ -78,7 +78,7 @@ class GraphController {
78
78
  }
79
79
 
80
80
  // Add a node from the search results
81
- addNewBox(packageName, pos = null) {
81
+ async addNewBox(packageName, pos = null) {
82
82
  // first, make sure the package is loaded
83
83
  this.e.loadPackage(packageName).then(async () => {
84
84
  var id = this.createId(packageName);
@@ -93,8 +93,8 @@ class GraphController {
93
93
  if (pkg) {
94
94
  // first, add node in the model
95
95
  // batch it so add node + set position + register to UI is 1 history change only
96
- this.m.batch(async () => {
97
- var nodeInfo = this.m.addNode(id, pkg);
96
+ await this.m.batch(async () => {
97
+ var nodeInfo = await this.m.addNode(id, pkg);
98
98
  if (nodeInfo) {
99
99
  if (pos) {
100
100
  var node = this.m.getNode(nodeInfo.id);
@@ -118,7 +118,7 @@ class GraphController {
118
118
  }
119
119
 
120
120
  // create a new metabox
121
- addNewMetabox(name, json = {}, pos) {
121
+ async addNewMetabox(name, json = {}, pos) {
122
122
  if (this.m.hasMetanode(name)) {
123
123
  swal("Can't add metabox", "metabox with name '" + name + "' already exists.", "error");
124
124
  } else {
@@ -128,7 +128,7 @@ class GraphController {
128
128
  // add 1 node of this metabox on the graph
129
129
  var id = this.createId(name);
130
130
 
131
- this.m.addNode(id, {
131
+ await this.m.addNode(id, {
132
132
  "name": name,
133
133
  "version": "*"
134
134
  });
@@ -676,8 +676,8 @@ class GraphController {
676
676
  return await navigator.clipboard.readText();
677
677
  }
678
678
 
679
- deleteSelection() {
680
- this.m.batch(() => {
679
+ async deleteSelection() {
680
+ await this.m.batch(() => {
681
681
  var selectedDivs = this.v.selector.getSelection();
682
682
  _.each(selectedDivs, (div) => {
683
683
  this.m.getNode($(div).attr('id')).remove();
@@ -217,20 +217,12 @@ class GraphModel {
217
217
 
218
218
  // batch all changes in a function into one (for history save)
219
219
  // if cb returns a Promise, return a Promise that will be resolved once it's all done
220
- batch(cb) {
221
- var ret = this.history.batch(cb);
222
- if (ret && ret.then) {
223
- // it's a promise, wait for it
224
- return Promise.resolve(ret).then((diff) => {
225
- if (this.onChangeCb) {
226
- this.onChangeCb(diff);
227
- }
228
- });
229
- } else {
230
- // not a promise, ret is our diff
231
- let diff = ret;
220
+ async batch(cb) {
221
+ let diffChange = await this.history.batch(cb);
222
+ if (diffChange && diffChange.diff && diffChange.hash) {
223
+ let { diff, hash } = diffChange;
232
224
  if (this.onChangeCb) {
233
- this.onChangeCb(diff);
225
+ this.onChangeCb(diff, hash);
234
226
  }
235
227
  }
236
228
  }
@@ -416,8 +408,8 @@ class GraphModel {
416
408
  }
417
409
 
418
410
  // add pkg dependencies (lib, types, etc) to app graph
419
- addDependencies(pkg) {
420
- _.each(pkg.dependencies, async (dependencyVersion, dependencyName) => {
411
+ async addDependencies(pkg) {
412
+ for (const dependencyName of Object.keys(pkg.dependencies)) {
421
413
  if (utils.isLibrary(dependencyName) || utils.isType(dependencyName)) {
422
414
  console.log('[*] Adding dependency: ' + dependencyName);
423
415
  // await this.e.loadPackage(dependencyName, dependencyVersion); // Is this better ?
@@ -426,10 +418,10 @@ class GraphModel {
426
418
  this.data.root.libs[pkg.name] = pkg.version;
427
419
  await this.addDependencies(pkg);
428
420
  }
429
- });
421
+ }
430
422
  }
431
423
 
432
- addNode(id, pkg) {
424
+ async addNode(id, pkg) {
433
425
  console.log('adding node: ' + id);
434
426
 
435
427
  var desc = {
@@ -444,7 +436,7 @@ class GraphModel {
444
436
  return false;
445
437
  }
446
438
  var node = this.getCurrentMetanode().modules[id] = desc;
447
- this.addDependencies(pkg); // async but no pb
439
+ await this.addDependencies(pkg); // async but no pb
448
440
  } else if (utils.isUI(pkg.name)) {
449
441
  this.ensure('ui');
450
442
  if (this.getCurrentMetanode().ui[id]) {
@@ -452,7 +444,7 @@ class GraphModel {
452
444
  return false;
453
445
  }
454
446
  var node = this.getCurrentMetanode().ui[id] = desc;
455
- this.addDependencies(pkg); // async but no pb
447
+ await this.addDependencies(pkg); // async but no pb
456
448
  } else {
457
449
  // may be a metanode
458
450
  var nodeDef = idx(this.getCurrentMetanode(), o => o.metanodes[pkg.name]);
@@ -2286,8 +2278,6 @@ class GraphNode {
2286
2278
  });
2287
2279
  }
2288
2280
  });
2289
-
2290
- this.m.save();
2291
2281
  }
2292
2282
  }
2293
2283
 
@@ -141,31 +141,21 @@ class History {
141
141
  }
142
142
 
143
143
  // execute the callback and save the history as 1 change
144
- batch(cb) {
145
- let ret = this.ignore(cb);
146
- if (ret && ret.then) {
147
- // its a promise
148
- return Promise.resolve(ret).then(() => {
149
- return this.save();
150
- });
151
- } else {
152
- return this.save();
153
- }
144
+ async batch(cb) {
145
+ await this.ignore(cb);
146
+ return this.save();
154
147
  }
155
148
 
156
149
  // ignore history saves during the time of the callback
157
150
  // if cb return a promise, wait until it's resolved and return a Promise
158
- ignore(cb) {
151
+ async ignore(cb) {
159
152
  this.holdSaving(true);
160
153
  let ret = cb();
161
- if (ret && ret.then) {
162
- // its a promise
163
- return Promise.resolve(ret).then(() => {
164
- this.holdSaving(false);
165
- });
166
- } else {
167
- this.holdSaving(false);
168
- }
154
+
155
+ // if cb returns a promise, wait for it
156
+ let result = ret && ret.then ? await ret : ret;
157
+ this.holdSaving(false);
158
+ return result;
169
159
  }
170
160
  }
171
161
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dualbox/editor",
3
- "version": "1.0.90",
3
+ "version": "1.0.92",
4
4
  "description": "Editor of Dualbox apps",
5
5
  "browser": "js/dist/GraphEditor.js",
6
6
  "main": "js/dist/GraphEditor.js",