From 4b39a44ec394d255085438a3dc74709bf2d38639 Mon Sep 17 00:00:00 2001 From: Philipp Fromme Date: Thu, 21 Jan 2021 10:02:07 +0100 Subject: [PATCH] feat: align to origin after serialization --- lib/BaseViewer.js | 15 ++++++++------- package-lock.json | 8 ++++++++ package.json | 1 + test/spec/ModelerSpec.js | 15 +++++++++++++-- 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/lib/BaseViewer.js b/lib/BaseViewer.js index 81136697..c902db33 100644 --- a/lib/BaseViewer.js +++ b/lib/BaseViewer.js @@ -376,20 +376,21 @@ BaseViewer.prototype.saveXML = wrapForCompatibility(function saveXML(options) { var xml = result.xml; try { - xml = self._emit('saveXML.serialized', { + self._emit('saveXML.serialized', { error: null, xml: xml - }) || xml; + }).then(function(result) { + self._emit('saveXML.done', { + error: null, + xml: result.xml + }); - self._emit('saveXML.done', { - error: null, - xml: xml + return resolve({ xml: result.xml }); }); + } catch (e) { console.error('error in saveXML life-cycle listener', e); } - - return resolve({ xml: xml }); }).catch(function(err) { return reject(err); diff --git a/package-lock.json b/package-lock.json index 19e43d40..df0061f4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1308,6 +1308,14 @@ "integrity": "sha512-RO1ibKvd27e6FEShVFfPALuHI3WjSVNeK5FIsmme/LYRNxjKuNj+Dt7bucLa6NdSv3JcVTyMlm9kGR84z1XpaQ==", "dev": true }, + "align-to-origin-xml": { + "version": "git://github.com/philippfromme/align-to-origin-xml.git#1d958138e2fbe36b5ac6c5cad610c4b1af06220e", + "from": "git://github.com/philippfromme/align-to-origin-xml.git", + "requires": { + "bpmn-moddle": "^7.0.4", + "min-dash": "^3.5.2" + } + }, "ansi-colors": { "version": "3.2.4", "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-3.2.4.tgz", diff --git a/package.json b/package.json index d892051e..af3236d2 100644 --- a/package.json +++ b/package.json @@ -86,6 +86,7 @@ "webpack": "^4.44.2" }, "dependencies": { + "align-to-origin-xml": "git://github.com/philippfromme/align-to-origin-xml.git", "bpmn-moddle": "^7.0.4", "css.escape": "^1.5.1", "diagram-js": "^7.0.0", diff --git a/test/spec/ModelerSpec.js b/test/spec/ModelerSpec.js index 2e266156..e58f9af5 100644 --- a/test/spec/ModelerSpec.js +++ b/test/spec/ModelerSpec.js @@ -14,6 +14,8 @@ import { collectTranslations } from 'test/TestHelper'; +import AlignToOrigin from 'align-to-origin-xml'; + var singleStart = window.__env__ && window.__env__.SINGLE_START === 'modeler'; @@ -36,7 +38,10 @@ describe('Modeler', function() { container: container, keyboard: { bindTo: document - } + }, + additionalModules: [ + AlignToOrigin + ] }); setBpmnJS(modeler); @@ -49,11 +54,17 @@ describe('Modeler', function() { } - (singleStart ? it.only : it)('should import simple process', function() { + it.only('should import simple process', function() { var xml = require('../fixtures/bpmn/simple.bpmn'); return createModeler(xml).then(function(result) { expect(result.error).not.to.exist; + + result.modeler.on('commandStack.changed', function() { + result.modeler.saveXML({ format: true }).then(function(result) { + console.log(result.xml); + }); + }) }); });