|
4 | 4 | <div class="unlayerControls flex"> |
5 | 5 | <button |
6 | 6 | 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" |
8 | 8 | @click="toggleFullscreen" |
9 | 9 | type="button"> |
10 | 10 | {{ fullscreenButtonText.on }} |
|
112 | 112 | window.unlayer.loadDesign(this.value); |
113 | 113 | } |
114 | 114 |
|
| 115 | + /** @see https://docs.unlayer.com/docs/events */ |
115 | 116 | window.unlayer.addEventListener('design:loaded', this.designLoaded); |
116 | 117 | window.unlayer.addEventListener('design:updated', this.designUpdated); |
| 118 | + window.unlayer.addEventListener('onImageUpload', this.imageUpload); |
117 | 119 | }, |
118 | 120 |
|
119 | 121 | /** |
120 | 122 | * @param {{design: Object}} loadedDesign |
121 | 123 | */ |
122 | 124 | designLoaded(loadedDesign) { |
| 125 | + Nova.$emit('unlayer:design:loaded', { |
| 126 | + inputName: this.field.attribute, |
| 127 | + payload: loadedDesign, |
| 128 | + }); |
| 129 | +
|
123 | 130 | window.unlayer.exportHtml((editorData) => { |
124 | 131 | this.finalHtml = editorData.html; |
125 | 132 | this.value = editorData.design; |
|
130 | 137 | * @param {{item: Object, type: string}} changeLog |
131 | 138 | */ |
132 | 139 | 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() { |
133 | 152 | window.unlayer.exportHtml((editorData) => { |
134 | 153 | this.finalHtml = editorData.html; |
135 | 154 | 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, |
136 | 170 | }); |
137 | 171 | }, |
138 | 172 | }, |
|
0 commit comments