Skip to content

Commit 3202194

Browse files
committed
Proxy unlayer events to the app
1 parent 0b3053a commit 3202194

File tree

3 files changed

+37
-3
lines changed

3 files changed

+37
-3
lines changed

dist/js/field.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/mix-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"/js/field.js": "/js/field.js?id=e129313c871cae23c196"
2+
"/js/field.js": "/js/field.js?id=a9e4b55019bad3275d91"
33
}

resources/js/components/FormField.vue

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<div class="unlayerControls flex">
55
<button
66
id="fullscreenToggleButton"
7-
class="text-xs bg-90 hover:bg-black text-white font-semibold rounded-sm px-4 py-1 m-1 border"
7+
class="text-xs bg-90 hover:bg-black text-white font-semibold rounded-sm px-4 py-1 m-1 form-input-bordered"
88
@click="toggleFullscreen"
99
type="button">
1010
{{ fullscreenButtonText.on }}
@@ -112,14 +112,21 @@
112112
window.unlayer.loadDesign(this.value);
113113
}
114114
115+
/** @see https://docs.unlayer.com/docs/events */
115116
window.unlayer.addEventListener('design:loaded', this.designLoaded);
116117
window.unlayer.addEventListener('design:updated', this.designUpdated);
118+
window.unlayer.addEventListener('onImageUpload', this.imageUpload);
117119
},
118120
119121
/**
120122
* @param {{design: Object}} loadedDesign
121123
*/
122124
designLoaded(loadedDesign) {
125+
Nova.$emit('unlayer:design:loaded', {
126+
inputName: this.field.attribute,
127+
payload: loadedDesign,
128+
});
129+
123130
window.unlayer.exportHtml((editorData) => {
124131
this.finalHtml = editorData.html;
125132
this.value = editorData.design;
@@ -130,9 +137,36 @@
130137
* @param {{item: Object, type: string}} changeLog
131138
*/
132139
designUpdated(changeLog) {
140+
Nova.$emit('unlayer:design:updated', {
141+
inputName: this.field.attribute,
142+
payload: changeLog,
143+
});
144+
145+
this.exportHtml();
146+
},
147+
148+
/**
149+
* Build HTML based on current JSON config
150+
*/
151+
exportHtml() {
133152
window.unlayer.exportHtml((editorData) => {
134153
this.finalHtml = editorData.html;
135154
this.value = editorData.design;
155+
156+
Nova.$emit('unlayer:html:exported', {
157+
inputName: this.field.attribute,
158+
payload: editorData,
159+
});
160+
});
161+
},
162+
163+
/**
164+
* @param {Object} imageData
165+
*/
166+
imageUpload(imageData) {
167+
Nova.$emit('unlayer:image:uploaded', {
168+
inputName: this.field.attribute,
169+
payload: imageData,
136170
});
137171
},
138172
},

0 commit comments

Comments
 (0)