Skip to content

Commit abd8229

Browse files
authored
Merge pull request #58 from vue-styleguidist/fix-acorn-instead-of-recast
fix: use acorn instead of recast
2 parents fa128c8 + 0741179 commit abd8229

File tree

11 files changed

+516
-215
lines changed

11 files changed

+516
-215
lines changed

README.md

Lines changed: 254 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,260 @@ module.exports = {
100100
};
101101
```
102102

103+
## Events
104+
105+
### `@error`
106+
107+
When the template compilation or the script evaluation fail, errors are returned in this box. Hooking on these errors will not prevent them from displaying on the preview panel but will allow you to provide more info to your users about how to fix what they see.
108+
109+
```vue
110+
<template>
111+
<VueLive
112+
code="<h1>make this example {{ fail }}</h1>"
113+
@error="(e) => log('Error on first example', e)"
114+
/>
115+
</template>
116+
```
117+
118+
## Props
119+
120+
### `code`
121+
122+
**Type** String
123+
124+
Specifies the initial code to be evaluated
125+
126+
```vue
127+
<template>
128+
<VueLive code="<button>test</button>" />
129+
</template>
130+
```
131+
132+
### `layout`
133+
134+
**Type** vue component
135+
136+
Layout to be used for displaying the
137+
138+
Example
139+
140+
```vue
141+
<template>
142+
<VueLive :layout="layout" />
143+
</template>
144+
<script>
145+
import layout from "./Layout.vue";
146+
147+
export default {
148+
data() {
149+
return { layout };
150+
},
151+
};
152+
</script>
153+
```
154+
155+
`layout.vue`
156+
157+
```vue
158+
<template>
159+
<div class="my-vuelive">
160+
<div class="my-vuelive-editor">
161+
<slot name="editor"></slot>
162+
</div>
163+
<div class="my-vuelive-preview">
164+
<slot name="preview"></slot>
165+
</div>
166+
</div>
167+
</template>
168+
<style>
169+
.my-vuelive {
170+
border: 1px solid #ccc;
171+
border-radius: 10px;
172+
}
173+
174+
.my-vuelive-editor {
175+
margin: 8px;
176+
}
177+
178+
.my-vuelive-preview {
179+
margin: 8px;
180+
}
181+
</style>
182+
```
183+
184+
### `components`
185+
186+
**Type** Object:
187+
188+
- key: registration name
189+
- value: VueJs component object
190+
191+
Register some components to be used in the vue-live instance.
192+
193+
Example
194+
195+
```vue
196+
<template>
197+
<VueLive :components="registeredComponents" code="<DatePicker />" />
198+
</template>
199+
<script>
200+
import DatePicker from "./DatePicker.vue";
201+
202+
export default {
203+
data() {
204+
return {
205+
registeredComponents: {
206+
DatePicker,
207+
},
208+
};
209+
},
210+
};
211+
</script>
212+
```
213+
214+
### `requires`
215+
216+
**Type** Object:
217+
218+
- key: query in the require/import statement
219+
- value: value returned by an es5 reauire statement
220+
221+
To allow require statements on a code evaluated in the browser, we have to pre-package all dependencies. This allows bundlers to know in advance what external dependencies will be allowed in the code.
222+
223+
Example
224+
225+
```vue
226+
<template>
227+
<VueLive :requires="preRequiredObjects" :code="code" />
228+
</template>
229+
<script>
230+
import DatePicker from "./DatePicker.vue";
231+
232+
export default {
233+
data() {
234+
return {
235+
// lodash can be pre-packaged by the bundler
236+
// so it can be required at runtime
237+
preRequiredObjects: {
238+
lodash: require("lodash"),
239+
},
240+
code: `
241+
import _ from 'lodash'
242+
243+
const val = _.each({1,2,3}, (i, v) => {
244+
return \`\${i} value \${v}\`
245+
})
246+
247+
<li v-for="v in val">
248+
v : {{v}}
249+
</li>
250+
`,
251+
};
252+
},
253+
};
254+
</script>
255+
```
256+
257+
### `jsx`
258+
259+
**Type** Boolean
260+
261+
JSX does not always play nice with vue templates. If you want to expose vue templates, leave this option off. If you plan on using render functions with JSX, you will have to turn this option on.
262+
263+
Example
264+
265+
```vue
266+
<template>
267+
<vue-live :code="code" jsx />
268+
</template>
269+
<script>
270+
export default {
271+
data() {
272+
return {
273+
code: `
274+
const args = {
275+
type: "button",
276+
value: "update me"
277+
};
278+
279+
export default {
280+
render() {
281+
return <input {...args} />;
282+
}
283+
};
284+
`,
285+
};
286+
},
287+
};
288+
</script>
289+
```
290+
291+
### `delay`
292+
293+
**Type** Number
294+
295+
Time between a change in the code and its effect in the preview.
296+
297+
> **Note** If a change happens before the prview has changed, the timer is reset.
298+
299+
### `editorProps`
300+
301+
**Type** Object
302+
303+
Props passed directly to [vue-prism-editor](https://github.com/koca/vue-prism-editor) as a spread
304+
305+
### `dataScope`
306+
307+
**Type** Object
308+
309+
Data object that wil be merged with the output data of the preview.
310+
311+
Example
312+
313+
````vue
314+
```vue
315+
<template>
316+
<VueLive
317+
:components="registeredComponents"
318+
:data-scope="dataScope"
319+
code="<DatePicker :value='today' />{{ today }}"
320+
/>
321+
</template>
322+
<script>
323+
import DatePicker from "./DatePicker.vue";
324+
325+
export default {
326+
data() {
327+
return {
328+
registeredComponents: {
329+
DatePicker,
330+
},
331+
// Without this variable declaration,
332+
// today will not have a value when entering the
333+
// particularly useful when examples or only a template
334+
dataScope: {
335+
today: new Date(),
336+
},
337+
};
338+
},
339+
};
340+
</script>
341+
````
342+
343+
### `checkVariableAvailability`
344+
345+
**Type** Boolean
346+
347+
Makes sure that every variable in the template actually exists when the user starts editing.
348+
349+
Throws an error in te preview field when the variable dont exist.
350+
351+
### `squiggles`
352+
353+
**Type** Boolean default: `true`
354+
355+
Shows a red indicator when the parser errors with the code given.
356+
103357
## How to contribute
104358

105359
```sh

demo/App.vue

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,19 @@
8282
<h2>Separate components for Editor and Preview</h2>
8383
<div class="separate">
8484
<div class="preview-separate">
85-
<VueLivePreview :code="separateCode" />
85+
<VueLivePreview
86+
:code="separateCode"
87+
@error="(e) => (error = e)"
88+
@success="error = undefined"
89+
/>
8690
</div>
8791
<hr style="width: 950px" />
8892
<p>Edit the code here</p>
89-
<VueLiveEditor :code="separateCode" @change="updateCode" />
93+
<VueLiveEditor
94+
:code="separateCode"
95+
@change="updateCode"
96+
:error="error"
97+
/>
9098
<div class="button-bar"><button>Save</button></div>
9199
</div>
92100
</div>
@@ -128,6 +136,7 @@ export default {
128136
realjsx,
129137
separateCode: codeSfc,
130138
openExamples: false,
139+
error: undefined,
131140
};
132141
},
133142
methods: {

0 commit comments

Comments
 (0)