mirror of
https://github.com/documize/community.git
synced 2025-07-26 00:29:47 +02:00
Fix Draw.io integratoin timing issue
This commit is contained in:
parent
63ce324eae
commit
39891a0758
1 changed files with 31 additions and 22 deletions
|
@ -30,19 +30,6 @@ export default Component.extend({
|
||||||
return `flowchart-editor-${page.id}`;
|
return `flowchart-editor-${page.id}`;
|
||||||
}),
|
}),
|
||||||
|
|
||||||
goSave: observer('readyToSave', function() {
|
|
||||||
if (this.get('readyToSave')) {
|
|
||||||
let page = this.get('page');
|
|
||||||
let meta = this.get('meta');
|
|
||||||
meta.set('rawBody', this.get('diagram'));
|
|
||||||
page.set('title', this.get('title'));
|
|
||||||
|
|
||||||
this.set('waiting', false);
|
|
||||||
this.teardownEditor();
|
|
||||||
this.get('onAction')(page, meta);
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
|
|
||||||
didReceiveAttrs() {
|
didReceiveAttrs() {
|
||||||
this._super(...arguments);
|
this._super(...arguments);
|
||||||
|
|
||||||
|
@ -71,10 +58,12 @@ export default Component.extend({
|
||||||
console.log('draw.io component destroyed'); // eslint-disable-line no-console
|
console.log('draw.io component destroyed'); // eslint-disable-line no-console
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (evt.origin !== 'https://www.draw.io') {
|
// if (evt.origin !== 'https://www.draw.io') {
|
||||||
// console.log('draw.io incorrect message source: ' + evt.source); // eslint-disable-line no-console
|
// console.log('draw.io incorrect message source: ' + evt.source); // eslint-disable-line no-console
|
||||||
// return;
|
// return;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
if (evt.data.length === 0) {
|
if (evt.data.length === 0) {
|
||||||
console.log('draw.io no event data'); // eslint-disable-line no-console
|
console.log('draw.io no event data'); // eslint-disable-line no-console
|
||||||
return;
|
return;
|
||||||
|
@ -91,13 +80,12 @@ export default Component.extend({
|
||||||
|
|
||||||
case 'save':
|
case 'save':
|
||||||
self.set('diagramXML', msg.xml);
|
self.set('diagramXML', msg.xml);
|
||||||
// Trigger onAction() callback using sneaky trick.
|
self.invokeExport();
|
||||||
Mousetrap.trigger('ctrl+s');
|
break;
|
||||||
break;
|
|
||||||
|
|
||||||
case 'autosave':
|
case 'autosave':
|
||||||
self.set('diagramXML', msg.xml);
|
self.set('diagramXML', msg.xml);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'load':
|
case 'load':
|
||||||
break;
|
break;
|
||||||
|
@ -121,6 +109,31 @@ export default Component.extend({
|
||||||
window.removeEventListener('message', this.get('flowCallback'));
|
window.removeEventListener('message', this.get('flowCallback'));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
invokeExport() {
|
||||||
|
let editorFrame = document.getElementById(this.get('editorId'));
|
||||||
|
editorFrame.contentWindow.postMessage(
|
||||||
|
JSON.stringify(
|
||||||
|
{
|
||||||
|
action: 'export',
|
||||||
|
format: 'xmlpng',
|
||||||
|
xml: this.get('diagramXML'),
|
||||||
|
spin: 'Updating'
|
||||||
|
}
|
||||||
|
), '*');
|
||||||
|
},
|
||||||
|
|
||||||
|
goSave: observer('readyToSave', function() {
|
||||||
|
if (this.get('readyToSave')) {
|
||||||
|
let page = this.get('page');
|
||||||
|
let meta = this.get('meta');
|
||||||
|
meta.set('rawBody', this.get('diagram'));
|
||||||
|
page.set('title', this.get('title'));
|
||||||
|
|
||||||
|
this.set('waiting', false);
|
||||||
|
this.get('onAction')(page, meta);
|
||||||
|
}
|
||||||
|
}),
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
isDirty() {
|
isDirty() {
|
||||||
return this.get('isDirty') || (this.get('diagram') !== this.get('meta.rawBody'));
|
return this.get('isDirty') || (this.get('diagram') !== this.get('meta.rawBody'));
|
||||||
|
@ -134,11 +147,7 @@ export default Component.extend({
|
||||||
onAction(title) {
|
onAction(title) {
|
||||||
this.set('waiting', true);
|
this.set('waiting', true);
|
||||||
this.set('title', title);
|
this.set('title', title);
|
||||||
|
this.invokeExport();
|
||||||
let editorFrame = document.getElementById(this.get('editorId'));
|
|
||||||
editorFrame.contentWindow.postMessage(
|
|
||||||
JSON.stringify({action: 'export', format: 'xmlpng',
|
|
||||||
xml: this.get('diagramXML'), spin: 'Updating'}), '*');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue