Skip to content

Commit b40fa07

Browse files
Merge pull request #118 from unlayer/UN-2093
2.1.5: Add wrapper to serialize event listeners (fixes postMessage issue with event listeners)
2 parents dc91e95 + 36ca3dd commit b40fa07

File tree

3 files changed

+33
-17
lines changed

3 files changed

+33
-17
lines changed

Diff for: package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-email-editor",
3-
"version": "2.1.2",
3+
"version": "2.1.5",
44
"main": "dist/vue-email-editor.es",
55
"types": "dist/vue-email-editor.d.ts",
66
"scripts": {
@@ -19,8 +19,8 @@
1919
"devDependencies": {
2020
"@babel/types": "^7.24.7",
2121
"@vitejs/plugin-vue": "^5.0.5",
22-
"@vue/cli-service": "~5.0.0",
2322
"@vue/cli-plugin-typescript": "~5.0.0",
23+
"@vue/cli-service": "~5.0.0",
2424
"typescript": "^5.2.2",
2525
"vite": "^5.3.1",
2626
"vue-dts-gen": "^0.3.0",

Diff for: src/components/EmailEditor.vue

+29-13
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77
</template>
88

99
<script lang="ts">
10-
import { defineComponent, toRaw } from 'vue';
10+
import { defineComponent, shallowRef, toRaw } from 'vue';
1111
import pkg from '../../package.json';
1212
import { loadScript } from './loadScript';
1313
import { EmailEditorProps } from './types';
14-
import { ref } from 'vue';
1514
let lastEditorId = 0;
1615
1716
export default defineComponent({
@@ -51,11 +50,27 @@ export default defineComponent({
5150
},
5251
},
5352
setup() {
54-
// shallowRef is used to avoid window.postMessage error
55-
const editor = ref<EmailEditorProps['editor'] | null>(null); // Creates a reactive reference
53+
const editor = shallowRef<EmailEditorProps['editor'] | null>(null);
54+
55+
const createSerializedEditor = (originalEditor: any) => {
56+
if (!originalEditor) return null;
57+
58+
return {
59+
...originalEditor,
60+
registerCallback: (event: string, callback: Function) => {
61+
originalEditor.registerCallback(event, (data: any, done: Function) => {
62+
callback(data, (result: any) => {
63+
const rawResult = toRaw(result);
64+
done(rawResult);
65+
});
66+
});
67+
}
68+
};
69+
};
5670
5771
return {
58-
editor, // Makes editor available to the template
72+
editor,
73+
createSerializedEditor,
5974
};
6075
},
6176
mounted() {
@@ -64,11 +79,9 @@ export default defineComponent({
6479
methods: {
6580
loadEditor() {
6681
const options = toRaw(this.options) || {};
67-
const appearance = toRaw(this.appearance) || null;
68-
const tools = toRaw(this.tools) || null;
6982
70-
if (appearance) {
71-
options.appearance = appearance;
83+
if (this.appearance) {
84+
options.appearance = toRaw(this.appearance);
7285
}
7386
7487
if (this.locale) {
@@ -79,11 +92,11 @@ export default defineComponent({
7992
options.projectId = this.projectId;
8093
}
8194
82-
if (tools) {
83-
options.tools = tools;
95+
if (this.tools) {
96+
options.tools = toRaw(this.tools);
8497
}
8598
86-
this.editor = unlayer.createEditor({
99+
const rawEditor = unlayer.createEditor({
87100
...options,
88101
id: this.id,
89102
source: {
@@ -92,8 +105,11 @@ export default defineComponent({
92105
},
93106
});
94107
108+
// Wrap the editor with serialization handling
109+
this.editor = this.createSerializedEditor(rawEditor);
110+
95111
this.$emit('load');
96-
this.editor.addEventListener('editor:ready', () => {
112+
this.editor?.addEventListener('editor:ready', () => {
97113
this.$emit('ready');
98114
});
99115
},

0 commit comments

Comments
 (0)