99 :components =" components"
1010 >
1111 <template v-slot :editor >
12- <PrismEditor
13- v-model =" stableCode"
12+ <Editor
13+ :code =" stableCode"
14+ :delay =" delay"
15+ :prism-lang =" prismLang"
16+ :editor-props =" editorProps"
1417 @change =" updatePreview"
15- :language =" prismLang"
16- v-bind =" editorProps"
1718 />
1819 </template >
1920 <template v-slot :preview >
2930 </component >
3031</template >
3132<script >
32- // load prism somewhere
33- import " prismjs" ;
34- import " prismjs/components/prism-jsx.min" ;
35-
36- import PrismEditor from " vue-prism-editor" ;
3733import hash from " hash-sum" ;
38- import debounce from " debounce" ;
3934
4035import Preview from " ./Preview.vue" ;
36+ import Editor from ' ./Editor.vue' ;
4137import VueLiveDefaultLayout from " ./VueLiveDefaultLayout.vue" ;
4238
4339const LANG_TO_PRISM = {
@@ -49,7 +45,7 @@ const UPDATE_DELAY = 300;
4945
5046export default {
5147 name: " VueLivePreview" ,
52- components: { PrismEditor, Preview },
48+ components: { Preview, Editor },
5349 props: {
5450 /**
5551 * code rendered in the preview and the editor
@@ -122,7 +118,6 @@ export default {
122118 lang: " vue" ,
123119 prismLang: " html" ,
124120 VueLiveDefaultLayout,
125- updatePreview : () => {},
126121 /**
127122 * this data only gets changed when changing language.
128123 * it allows for copy and pasting without having the code
@@ -131,11 +126,6 @@ export default {
131126 stableCode: this .code
132127 };
133128 },
134- created () {
135- this .updatePreview = debounce (value => {
136- this .model = value;
137- }, this .delay );
138- },
139129 computed: {
140130 codeKey () {
141131 return hash (this .model );
@@ -148,6 +138,12 @@ export default {
148138 }
149139 },
150140 methods: {
141+ updatePreview (code ) {
142+ this .stableCode = code;
143+ this .model = code;
144+
145+ this .$emit (' change' , code);
146+ },
151147 switchLanguage (newLang ) {
152148 this .lang = newLang;
153149 const newPrismLang = LANG_TO_PRISM [newLang];
0 commit comments