Skip to content

Commit

Permalink
feat: add onContentChange to synchronize the result with style-panel
Browse files Browse the repository at this point in the history
  • Loading branch information
unimu-cic authored and MrCoder committed Oct 20, 2023
1 parent 53d9ac6 commit a6fab6d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
12 changes: 12 additions & 0 deletions src/components/ContentWrap.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,20 @@ export default class ContentWrap extends Component {
}
componentDidMount() {
this.props.onRef(this);
window.addEventListener('message', this.handleMessageCodeUpdate.bind(this));
}

componentWillUnmount() {
window.removeEventListener('message', this.handleMessageCodeUpdate.bind(this));
}

handleMessageCodeUpdate(e) {
const code = e.data && e.data.code;
if (code) {
this.cm.js.setValue(code);
this.cm.js.refresh();
}
}
onHtmlCodeChange(editor, change) {
this.cmCodes.html = editor.getValue();
this.props.onCodeChange(
Expand Down
4 changes: 3 additions & 1 deletion src/computes.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,9 @@ export function computeJs(
const cursor = e.data && e.data.cursor;
if (code && app) {
app.render(code, { enableMultiTheme: false });
app.render(code, { enableMultiTheme: false, onContentChange: (code) => {
window.parent.postMessage({ code })
}});
}
if(app && (cursor !== null || cursor !== undefined)) {
Expand Down
10 changes: 7 additions & 3 deletions src/extension/script.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
window.addEventListener("load", function (event) {
console.log("window loaded");
window.addEventListener('load', function(event) {
console.log('window loaded');
window.app = new window.zenuml.default('#mounting-point');
});
window.addEventListener('message', (e) => {
const code = e.data && e.data.code;
const cursor = e.data && e.data.cursor;

if (code && app) {
app.render(code, { enableMultiTheme: false });
app.render(code, {
enableMultiTheme: false, onContentChange: (code) => {
window.parent.postMessage({ code });
}
});
}

if (app && (cursor !== null || cursor !== undefined)) {
Expand Down

0 comments on commit a6fab6d

Please sign in to comment.