Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 39 additions & 2 deletions monaco-editor-iframe.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
constructor(iframe, editorReference) {
this._iframe_ = iframe;
this._editorReference_ = editorReference;
this._messageFlowActive_ = false;
this._delayedMessages_ = [];
this.languages.json.jsonDefaults.setDiagnosticsOptions;
}
get languages() {
Expand Down Expand Up @@ -47,7 +49,21 @@
}
postMessage(msg) {
msg.editorReference = this._editorReference_;
this._iframe_.contentWindow.postMessage(msg, document.location.href);
if (this._messageFlowActive_) {
this._iframe_.contentWindow.postMessage(msg, document.location.href);
}
else {
this._delayedMessages_.push(msg);
}
}
setMessageFlowActive(value) {
this._messageFlowActive_ = value;
if (value) {
for (let msg of this._delayedMessages_) {
this._iframe_.contentWindow.postMessage(msg, document.location.href);
}
this._delayedMessages_ = [];
}
}
get editor() {
return {
Expand Down Expand Up @@ -103,11 +119,28 @@
constructor(iframe, editorReference) {
this._iframe_ = iframe;
this._editorReference_ = editorReference;
this._messageFlowActive_ = false;
this._delayedMessages_ = [];
}

postMessage(msg) {
msg.editorReference = this._editorReference_;
this._iframe_.contentWindow.postMessage(msg, document.location.href);
if (this._messageFlowActive_) {
this._iframe_.contentWindow.postMessage(msg, document.location.href);
}
else {
this._delayedMessages_.push(msg);
}
}

setMessageFlowActive(value) {
this._messageFlowActive_ = value;
if (value) {
for (let msg of this._delayedMessages_) {
this._iframe_.contentWindow.postMessage(msg, document.location.href);
}
this._delayedMessages_ = [];
}
}

updateOptions(opts) {
Expand Down Expand Up @@ -171,6 +204,10 @@
get proxy() {
return this._proxy_;
}
activateMessageFlow() {
this.editor.setMessageFlowActive(true);
this.monaco.setMessageFlowActive(true);
}
resize(w, h) {
this.node.style.height = h;
this.node.style.width = w;
Expand Down
3 changes: 2 additions & 1 deletion monaco-editor.html
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@
}

_initIFrame() {
var iframe = new PolymerVis.monaco.MonacoIFrame(this.shadowRoot);
window.addEventListener('message', ({data}) => {
if(data.editorReference !== this.editorReference) return;
if (data.event === 'value-changed') {
Expand All @@ -602,10 +603,10 @@

if (data.event === 'editor-message-handler-ready') {
this._valueChanged(this.value);
iframe.activateMessageFlow();
};
});

var iframe = new PolymerVis.monaco.MonacoIFrame(this.shadowRoot);
iframe.resize(this.clientWidth, this.clientHeight);
iframe.init(
this.libPath,
Expand Down