Skip to content

Commit 89a6485

Browse files
authored
Merge pull request #43 from unlayer/feat/editor-id
Ability to pass a custom editorId
2 parents a73c0fd + 17d7fb9 commit 89a6485

File tree

2 files changed

+73
-77
lines changed

2 files changed

+73
-77
lines changed

README.md

Lines changed: 55 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Vue Email Editor
22

3-
The excellent drag-n-drop email editor by [Unlayer](https://unlayer.com/embed) as a [Vue](https://vuejs.org/) *wrapper component*. This is the most powerful and developer friendly visual email builder for your app.
3+
The excellent drag-n-drop email editor by [Unlayer](https://unlayer.com/embed) as a [Vue](https://vuejs.org/) _wrapper component_. This is the most powerful and developer friendly visual email builder for your app.
44

5-
Video Overview |
6-
:---: |
7-
[![Vue Email Editor](https://unroll-assets.s3.amazonaws.com/unlayervideotour.png)](https://www.youtube.com/watch?v=MIWhX-NF3j8) |
8-
*Watch video overview: https://youtu.be/MIWhX-NF3j8* |
5+
| Video Overview |
6+
| :-----------------------------------------------------------------------------------------------------------------------------: |
7+
| [![Vue Email Editor](https://unroll-assets.s3.amazonaws.com/unlayervideotour.png)](https://www.youtube.com/watch?v=MIWhX-NF3j8) |
8+
| _Watch video overview: https://youtu.be/MIWhX-NF3j8_ |
99

1010
## Live Demo
1111

@@ -48,60 +48,59 @@ Next, you'll need to import the Email Editor component to your app.
4848
</template>
4949

5050
<script>
51-
import { EmailEditor } from 'vue-email-editor'
52-
51+
import { EmailEditor } from 'vue-email-editor';
52+
5353
export default {
5454
name: 'app',
5555
components: {
56-
EmailEditor
56+
EmailEditor,
5757
},
5858
methods: {
5959
editorLoaded() {
6060
// Pass the template JSON here
6161
// this.$refs.emailEditor.editor.loadDesign({});
6262
},
6363
saveDesign() {
64-
this.$refs.emailEditor.editor.saveDesign(
65-
(design) => {
66-
console.log('saveDesign', design);
67-
}
68-
)
64+
this.$refs.emailEditor.editor.saveDesign((design) => {
65+
console.log('saveDesign', design);
66+
});
6967
},
7068
exportHtml() {
71-
this.$refs.emailEditor.editor.exportHtml(
72-
(data) => {
73-
console.log('exportHtml', data);
74-
}
75-
)
76-
}
77-
}
78-
}
69+
this.$refs.emailEditor.editor.exportHtml((data) => {
70+
console.log('exportHtml', data);
71+
});
72+
},
73+
},
74+
};
7975
</script>
8076
```
8177

8278
### Methods
83-
| method | params | description |
84-
| --------------- | ------------------------ | -------------------------------------------------------------- |
85-
| **loadDesign** | `Object data` | Takes the design JSON and loads it in the editor |
86-
| **saveDesign** | `Function callback` | Returns the design JSON in a callback function |
87-
| **exportHtml** | `Function callback` | Returns the design HTML and JSON in a callback function |
79+
80+
| method | params | description |
81+
| -------------- | ------------------- | ------------------------------------------------------- |
82+
| **loadDesign** | `Object data` | Takes the design JSON and loads it in the editor |
83+
| **saveDesign** | `Function callback` | Returns the design JSON in a callback function |
84+
| **exportHtml** | `Function callback` | Returns the design HTML and JSON in a callback function |
8885

8986
See the [example source](https://github.com/unlayer/vue-email-editor/tree/master/src) for a reference implementation.
9087

9188
### Properties
9289

93-
* `minHeight` `String` minimum height to initialize the editor with (default 500px)
94-
* `options` `Object` options passed to the Unlayer editor instance (default {})
95-
* `tools` `Object` configuration for the built-in and custom tools (default {})
96-
* `appearance` `Object` configuration for appearance and theme (default {})
97-
* `projectId` `Integer` Unlayer project ID (optional)
98-
* `locale` `String` translations string (default en-US)
90+
- `editorId` `String` HTML div id of the container where the editor will be embedded (optional)
91+
- `minHeight` `String` minimum height to initialize the editor with (default 500px)
92+
- `options` `Object` options passed to the Unlayer editor instance (default {})
93+
- `tools` `Object` configuration for the built-in and custom tools (default {})
94+
- `appearance` `Object` configuration for appearance and theme (default {})
95+
- `projectId` `Integer` Unlayer project ID (optional)
96+
- `locale` `String` translations string (default en-US)
9997

10098
See the [Unlayer Docs](https://docs.unlayer.com/) for all available options.
10199

102100
Here's an example using the above properties...
103101

104-
**App.vue**
102+
**App.vue**
103+
105104
```html
106105
<template>
107106
<div id="app">
@@ -123,62 +122,57 @@ Here's an example using the above properties...
123122
ref="emailEditor"
124123
v-on:load="editorLoaded"
125124
/>
126-
127125
</div>
128126
</div>
129127
</template>
130128

131129
<script>
132-
import { EmailEditor } from 'vue-email-editor'
133-
130+
import { EmailEditor } from 'vue-email-editor';
131+
134132
export default {
135133
name: 'app',
136134
components: {
137-
EmailEditor
135+
EmailEditor,
138136
},
139-
data() {
140-
return {
141-
minHeight: "1000px",
142-
locale: "en",
137+
data() {
138+
return {
139+
minHeight: '1000px',
140+
locale: 'en',
143141
projectId: 0, // replace with your project id
144142
tools: {
145143
// disable image tool
146144
image: {
147-
enabled: false
148-
}
145+
enabled: false,
146+
},
149147
},
150148
options: {},
151149
appearance: {
152150
theme: 'dark',
153151
panels: {
154152
tools: {
155-
dock: 'right'
156-
}
157-
}
158-
}
159-
}
153+
dock: 'right',
154+
},
155+
},
156+
},
157+
};
160158
},
161159
methods: {
162160
editorLoaded() {
163161
// Pass your template JSON here
164162
// this.$refs.emailEditor.editor.loadDesign({});
165163
},
166164
saveDesign() {
167-
this.$refs.emailEditor.editor.saveDesign(
168-
(design) => {
169-
console.log('saveDesign', design);
170-
}
171-
)
165+
this.$refs.emailEditor.editor.saveDesign((design) => {
166+
console.log('saveDesign', design);
167+
});
172168
},
173169
exportHtml() {
174-
this.$refs.emailEditor.editor.exportHtml(
175-
(data) => {
176-
console.log('exportHtml', data);
177-
}
178-
)
179-
}
180-
}
181-
}
170+
this.$refs.emailEditor.editor.exportHtml((data) => {
171+
console.log('exportHtml', data);
172+
});
173+
},
174+
},
175+
};
182176
</script>
183177
```
184178

@@ -188,7 +182,6 @@ Custom tools can help you add your own content blocks to the editor. Every appli
188182

189183
[![Custom Tools](https://unroll-assets.s3.amazonaws.com/custom_tools.png)](https://docs.unlayer.com/docs/custom-tools)
190184

191-
192185
## Localization
193186

194187
You can submit new language translations by creating a PR on this GitHub repo: https://github.com/unlayer/translations. Translations managed by [PhraseApp](https://phraseapp.com)

src/components/EmailEditor.vue

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
<template>
2-
<div v-bind:id="editorId" class="unlayer-editor" v-bind:style="{ minHeight: minHeight }"></div>
2+
<div
3+
v-bind:id="id"
4+
class="unlayer-editor"
5+
v-bind:style="{ minHeight: minHeight }"
6+
></div>
37
</template>
48

59
<script>
@@ -11,6 +15,7 @@ let lastEditorId = 0;
1115
export default {
1216
name: 'EmailEditor',
1317
props: {
18+
editorId: String,
1419
options: Object,
1520
projectId: Number,
1621
tools: Object,
@@ -22,11 +27,9 @@ export default {
2227
},
2328
},
2429
computed: {
25-
editorId() {
26-
return `editor-${++lastEditorId}`;
27-
}
28-
},
29-
created() {
30+
id() {
31+
return this.editorId || `editor-${++lastEditorId}`;
32+
},
3033
},
3134
mounted() {
3235
loadScript(this.loadEditor.bind(this));
@@ -36,25 +39,25 @@ export default {
3639
const options = this.options || {};
3740
3841
if (this.projectId) {
39-
options.projectId = this.projectId
42+
options.projectId = this.projectId;
4043
}
4144
4245
if (this.tools) {
43-
options.tools = this.tools
46+
options.tools = this.tools;
4447
}
45-
48+
4649
if (this.appearance) {
47-
options.appearance = this.appearance
50+
options.appearance = this.appearance;
4851
}
4952
5053
if (this.locale) {
51-
options.locale = this.locale
54+
options.locale = this.locale;
5255
}
5356
5457
/* global unlayer */
5558
this.editor = unlayer.createEditor({
5659
...options,
57-
id: this.editorId,
60+
id: this.id,
5861
displayMode: 'email',
5962
source: {
6063
name: pkg.name,
@@ -72,14 +75,14 @@ export default {
7275
},
7376
exportHtml(callback) {
7477
this.editor.exportHtml(callback);
75-
}
78+
},
7679
},
77-
}
80+
};
7881
</script>
7982

8083
<style scoped>
8184
.unlayer-editor {
8285
flex: 1;
8386
display: flex;
8487
}
85-
</style>
88+
</style>

0 commit comments

Comments
 (0)