Skip to content

Commit 0bcd7a7

Browse files
author
Barthelemy Ledoux
committed
fix: repair default layout
1 parent ba6b981 commit 0bcd7a7

File tree

5 files changed

+58
-15
lines changed

5 files changed

+58
-15
lines changed

demo/App.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
<VueLive :code="codeJs" :layout="CustomLayout"/>
1313
<h2>Use the requires prop to make libraries and packages available in the browser</h2>
1414
<VueLive :code="codeChicago" :layout="CustomLayout" :requires="chicagoRequires"/>
15+
<h2>Default Layout</h2>
16+
<VueLive :code="`<input type='button' value='I am Groot'>`"/>
1517
<link href="https://fonts.googleapis.com/css?family=Roboto+Mono" rel="stylesheet">
1618
</main>
1719
</template>
@@ -47,5 +49,8 @@ body {
4749
font-family: "Roboto Mono", monospace;
4850
background-color: #ded;
4951
}
52+
53+
body .prism-editor__line-numbers {
54+
box-sizing: border-box;
55+
}
5056
</style>
51-
>

src/Preview.vue

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,28 @@ export default {
1515
name: "VueLivePreviewComponent",
1616
components: {},
1717
props: {
18+
/**
19+
* code rendered
20+
*/
1821
code: {
1922
type: String,
2023
required: true
2124
},
25+
/**
26+
* Hashtable of auto-registered components
27+
* @example { DatePicker: VueDatePicker }
28+
* @example { VueDatePicker }
29+
*/
2230
components: {
2331
type: Object,
2432
default: () => {}
2533
},
34+
/**
35+
* Hashtable of modules available in require and import statements
36+
* in the code prop
37+
* @example { lodash: require("lodash") }
38+
* @example { moment: require("moment") }
39+
*/
2640
requires: {
2741
type: Object,
2842
default: () => {}
@@ -38,6 +52,10 @@ export default {
3852
this.renderComponent(this.code.trim());
3953
},
4054
methods: {
55+
/**
56+
* Generates the Scope Id attribute value. It will be added to each
57+
* tag if a style is applied to scope the style only to this example
58+
*/
4159
generateScope() {
4260
return "v-xxxxxxxx".replace(/[xy]/g, c => {
4361
const r = (Math.random() * 16) | 0;

src/VueLive.vue

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
2-
<VueLiveLayout>
2+
<component :is="this.layout ? this.layout : VueLiveDefaultLayout">
33
<template v-slot:editor>
4-
<PrismEditor :code="model" @change="updatePreview" :language="prismLang" :lineNumbers="true"/>
4+
<PrismEditor :code="model" @change="updatePreview" :language="prismLang"/>
55
</template>
66
<template v-slot:preview>
77
<Preview
@@ -12,7 +12,7 @@
1212
:requires="requires"
1313
/>
1414
</template>
15-
</VueLiveLayout>
15+
</component>
1616
</template>
1717
<script>
1818
//load prism somewhere
@@ -27,7 +27,7 @@ import hash from "hash-sum";
2727
import debounce from "lodash.debounce";
2828
2929
import Preview from "./Preview.vue";
30-
import VueLiveLayout from "./VueLiveDefaultLayout.vue";
30+
import VueLiveDefaultLayout from "./VueLiveDefaultLayout.vue";
3131
3232
const LANG_TO_PRISM = {
3333
vue: "html",
@@ -36,20 +36,37 @@ const LANG_TO_PRISM = {
3636
3737
export default {
3838
name: "VueLivePreview",
39-
components: { PrismEditor, Preview, VueLiveLayout },
39+
components: { PrismEditor, Preview },
4040
props: {
41+
/**
42+
* code rendered in the preview and the editor
43+
*/
4144
code: {
4245
type: String,
4346
required: true
4447
},
48+
/**
49+
* Layout vue component with 2 slots named `editor` & `preview`
50+
*/
4551
layout: {
4652
type: Object,
4753
default: undefined
4854
},
55+
/**
56+
* Hashtable of auto-registered components
57+
* @example { DatePicker: VueDatePicker }
58+
* @example { VueDatePicker }
59+
*/
4960
components: {
5061
type: Object,
5162
default: () => {}
5263
},
64+
/**
65+
* Hashtable of modules available in require and import statements
66+
* in the Preview component
67+
* @example { lodash: require("lodash") }
68+
* @example { moment: require("moment") }
69+
*/
5370
requires: {
5471
type: Object,
5572
default: () => {}
@@ -58,14 +75,10 @@ export default {
5875
data() {
5976
return {
6077
model: this.code,
61-
prismLang: "html"
78+
prismLang: "html",
79+
VueLiveDefaultLayout
6280
};
6381
},
64-
created() {
65-
if (this.layout) {
66-
this.$options.components.VueLiveLayout = this.layout;
67-
}
68-
},
6982
computed: {
7083
codeKey() {
7184
return hash(this.model);

src/VueLiveDefaultLayout.vue

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
<template functional>
2-
<div class="vue-live-container">
3-
<div>
2+
<div
3+
class="vue-live-container"
4+
style="display:flex; width:950px; max-width:95vw; margin:20px auto;"
5+
>
6+
<div style="width:50%;">
47
<slot name="editor"></slot>
58
</div>
6-
<div>
9+
<div style="background-color:white;width:50%;padding:20px;">
710
<slot name="preview"></slot>
811
</div>
912
</div>

src/utils/addScopedStyle.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { scoper } from "./styleScoper";
22

3+
/**
4+
* Add a style block to the head to load the styles.
5+
* uses the suffix to scope the styles
6+
*/
37
export default function addScopedStyle(css, suffix) {
48
const head = document.head || document.getElementsByTagName("head")[0];
59
const newstyle = document.createElement("style");

0 commit comments

Comments
 (0)