Skip to content

Commit 37ab912

Browse files
committed
add options example
1 parent 2de058d commit 37ab912

File tree

3 files changed

+90
-5
lines changed

3 files changed

+90
-5
lines changed

src/examples/Examples.vue

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,18 @@ import data from './data.json'
66
const store = new ReplStore()
77
88
// TODO make dynamic
9-
const preference = 'composition'
9+
const preference = document.documentElement.classList.contains(
10+
'prefer-composition'
11+
)
12+
? 'composition'
13+
: 'options'
1014
11-
window.addEventListener('hashchange', () => {
12-
const newHash = ___location.hash.slice(1)
13-
store.setFiles(data[newHash][preference])
14-
})
15+
function updateExample() {
16+
const hash = ___location.hash.slice(1)
17+
store.setFiles(data[hash][preference])
18+
}
19+
20+
window.addEventListener('hashchange', updateExample)
1521
</script>
1622

1723
<template>
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<script>
2+
import marked from 'marked'
3+
4+
export default {
5+
data: () => ({
6+
input: '# hello'
7+
}),
8+
computed: {
9+
output() {
10+
return marked(this.input, { sanitize: true })
11+
}
12+
},
13+
methods: {
14+
update: debounce(function (e) {
15+
this.input = e.target.value
16+
}, 100)
17+
}
18+
}
19+
20+
function debounce(fn, delay) {
21+
let handle
22+
return (...args) => {
23+
if (handle) clearTimeout(handle)
24+
handle = setTimeout(() => {
25+
fn(...args)
26+
}, delay)
27+
}
28+
}
29+
</script>
30+
31+
<template>
32+
<div id="editor">
33+
<textarea class="input" :value="input" @input="update"></textarea>
34+
<div class="output" v-html="output"></div>
35+
</div>
36+
</template>
37+
38+
<style>
39+
body {
40+
margin: 0;
41+
height: 100%;
42+
font-family: 'Helvetica Neue', Arial, sans-serif;
43+
color: #333;
44+
}
45+
46+
#editor {
47+
height: 100vh;
48+
display: flex;
49+
}
50+
51+
.input,
52+
.output {
53+
overflow: auto;
54+
width: 50%;
55+
height: 100%;
56+
box-sizing: border-box;
57+
padding: 0 20px;
58+
}
59+
60+
.input {
61+
border: none;
62+
border-right: 1px solid #ccc;
63+
resize: none;
64+
outline: none;
65+
background-color: #f6f6f6;
66+
font-size: 14px;
67+
font-family: 'Monaco', courier, monospace;
68+
padding: 20px;
69+
}
70+
71+
code {
72+
color: #f66;
73+
}
74+
</style>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"imports": {
3+
"marked": "https://unpkg.com/[email protected]/lib/marked.esm.js"
4+
}
5+
}

0 commit comments

Comments
 (0)