diff --git a/client/src/lib/sandboxed-ckeditor-root.js b/client/src/lib/sandboxed-ckeditor-root.js
index cb78b30f..b0bfc114 100644
--- a/client/src/lib/sandboxed-ckeditor-root.js
+++ b/client/src/lib/sandboxed-ckeditor-root.js
@@ -43,25 +43,32 @@ class CKEditorSandbox extends Component {
const trustedUrlBase = getTrustedUrl();
const sandboxUrlBase = getSandboxUrl();
const publicUrlBase = getPublicUrl();
- const html = this.props.initialHtml && base(this.props.initialHtml, trustedUrlBase, sandboxUrlBase, publicUrlBase);
+ const source = this.props.initialSource && base(this.props.initialSource, trustedUrlBase, sandboxUrlBase, publicUrlBase);
this.state = {
- html
+ source
};
}
static propTypes = {
entityTypeId: PropTypes.string,
entityId: PropTypes.number,
- initialHtml: PropTypes.string
+ initialSource: PropTypes.string
}
async exportState(method, params) {
const trustedUrlBase = getTrustedUrl();
const sandboxUrlBase = getSandboxUrl();
const publicUrlBase = getPublicUrl();
+
+ const preHtml = '
';
+ const postHtml = '';
+
+ const unbasedSource = unbase(this.state.source, trustedUrlBase, sandboxUrlBase, publicUrlBase, true);
+
return {
- html: unbase(this.state.html, trustedUrlBase, sandboxUrlBase, publicUrlBase, true)
+ source: unbasedSource,
+ html: preHtml + unbasedSource + postHtml
};
}
@@ -119,9 +126,9 @@ class CKEditorSandbox extends Component {
return (
this.node = node}
- content={this.state.html}
+ content={this.state.source}
events={{
- change: evt => this.setState({html: evt.editor.getData()}),
+ change: evt => this.setState({source: evt.editor.getData()}),
}}
config={config}
/>
diff --git a/client/src/lib/sandboxed-ckeditor.js b/client/src/lib/sandboxed-ckeditor.js
index 8f684351..7b724c9b 100644
--- a/client/src/lib/sandboxed-ckeditor.js
+++ b/client/src/lib/sandboxed-ckeditor.js
@@ -29,8 +29,9 @@ export class CKEditorHost extends Component {
static propTypes = {
entityTypeId: PropTypes.string,
entity: PropTypes.object,
- initialHtml: PropTypes.string,
+ initialSource: PropTypes.string,
title: PropTypes.string,
+ onTestSend: PropTypes.func,
onFullscreenAsync: PropTypes.func
}
@@ -75,7 +76,7 @@ export class CKEditorHost extends Component {
const editorData = {
entityTypeId: this.props.entityTypeId,
entityId: this.props.entity.id,
- initialHtml: this.props.initialHtml
+ initialSource: this.props.initialSource
};
const tokenData = {
@@ -89,6 +90,7 @@ export class CKEditorHost extends Component {
{this.state.fullscreen &&
}
{this.props.title}
+
this.contentNode = node} className={styles.host} singleToken={true} contentProps={editorData} contentSrc="ckeditor/editor" tokenMethod="ckeditor" tokenParams={editorData}/>
diff --git a/client/src/lib/sandboxed-codeeditor-root.js b/client/src/lib/sandboxed-codeeditor-root.js
index 7a6c3b97..3d17063f 100644
--- a/client/src/lib/sandboxed-codeeditor-root.js
+++ b/client/src/lib/sandboxed-codeeditor-root.js
@@ -39,6 +39,8 @@ import {CodeEditorSourceType} from "./sandboxed-codeeditor-shared";
import mjml2html from "mjml4-in-browser";
import juice from "juice";
+const refreshTimeout = 1000;
+
@translate(null, { withRef: true })
class CodeEditorSandbox extends Component {
constructor(props) {
@@ -85,6 +87,12 @@ class CodeEditorSandbox extends Component {
source,
preview: props.initialPreview
};
+ this.state.previewContents = this.getHtml();
+
+ this.onCodeChangedHandler = ::this.onCodeChanged;
+
+ this.refreshHandler = ::this.refresh;
+ this.refreshTimeoutId = null;
}
static propTypes = {
@@ -100,6 +108,7 @@ class CodeEditorSandbox extends Component {
const sandboxUrlBase = getSandboxUrl();
const publicUrlBase = getPublicUrl();
return {
+ html: unbase(this.getHtml(), trustedUrlBase, sandboxUrlBase, publicUrlBase, true),
source: unbase(this.state.source, trustedUrlBase, sandboxUrlBase, publicUrlBase, true)
};
}
@@ -115,9 +124,12 @@ class CodeEditorSandbox extends Component {
parentRPC.setMethodHandler('setPreview', ::this.setPreview);
}
- render() {
- let previewContents;
+ componentWillUnmount() {
+ clearTimeout(this.refreshTimeoutId);
+ }
+ getHtml() {
+ let previewContents;
if (this.props.sourceType === CodeEditorSourceType.MJML) {
const res = mjml2html(this.state.source);
previewContents = res.html;
@@ -125,6 +137,28 @@ class CodeEditorSandbox extends Component {
previewContents = juice(this.state.source);
}
+ return previewContents;
+ }
+
+ onCodeChanged(data) {
+ this.setState({
+ source: data
+ });
+
+ if (!this.refreshTimeoutId) {
+ this.refreshTimeoutId = setTimeout(() => this.refresh(), refreshTimeout);
+ }
+ }
+
+ refresh() {
+ this.refreshTimeoutId = null;
+
+ this.setState({
+ previewContents: this.getHtml()
+ });
+ }
+
+ render() {
return (
@@ -133,7 +167,7 @@ class CodeEditorSandbox extends Component {
theme="github"
width="100%"
height="100%"
- onChange={data => this.setState({source: data})}
+ onChange={this.onCodeChangedHandler}
fontSize={12}
showPrintMargin={false}
value={this.state.source}
@@ -144,7 +178,7 @@ class CodeEditorSandbox extends Component {
{
this.state.preview &&
-
+
}
diff --git a/client/src/lib/sandboxed-codeeditor.js b/client/src/lib/sandboxed-codeeditor.js
index aed4caff..62bc1750 100644
--- a/client/src/lib/sandboxed-codeeditor.js
+++ b/client/src/lib/sandboxed-codeeditor.js
@@ -28,6 +28,7 @@ export class CodeEditorHost extends Component {
initialSource: PropTypes.string,
sourceType: PropTypes.string,
title: PropTypes.string,
+ onTestSend: PropTypes.func,
onFullscreenAsync: PropTypes.func
}
@@ -47,6 +48,7 @@ export class CodeEditorHost extends Component {
await this.contentNode.ask('setPreview', preview);
}
+
async exportState() {
return await this.contentNode.ask('exportState');
}
@@ -73,6 +75,7 @@ export class CodeEditorHost extends Component {
{this.state.fullscreen &&
}/)
}
{this.props.title}
+
this.contentNode = node} className={styles.host} singleToken={true} contentProps={editorData} contentSrc="codeeditor/editor" tokenMethod="codeeditor" tokenParams={tokenData}/>
diff --git a/client/src/lib/sandboxed-grapesjs-root.js b/client/src/lib/sandboxed-grapesjs-root.js
index 2a4451e5..e53a1dfc 100644
--- a/client/src/lib/sandboxed-grapesjs-root.js
+++ b/client/src/lib/sandboxed-grapesjs-root.js
@@ -107,7 +107,11 @@ export class GrapesJSSandbox extends Component {
const commandManager = editor.Commands;
const cmdGetCode = commandManager.get('gjs-get-inlined-html');
- html = cmdGetCode.run(editor);
+ const htmlBody = cmdGetCode.run(editor);
+
+ const preHtml = '';
+ const postHtml = '';
+ html = preHtml + unbase(htmlBody, trustedUrlBase, sandboxUrlBase, publicUrlBase, true) + postHtml;
}
diff --git a/client/src/lib/sandboxed-grapesjs.js b/client/src/lib/sandboxed-grapesjs.js
index 49a91239..5788f06a 100644
--- a/client/src/lib/sandboxed-grapesjs.js
+++ b/client/src/lib/sandboxed-grapesjs.js
@@ -28,6 +28,7 @@ export class GrapesJSHost extends Component {
initialStyle: PropTypes.string,
sourceType: PropTypes.string,
title: PropTypes.string,
+ onTestSend: PropTypes.func,
onFullscreenAsync: PropTypes.func
}
@@ -65,6 +66,7 @@ export class GrapesJSHost extends Component {
{this.state.fullscreen &&
}
{this.props.title}
+