generated from akrisrn/v-no-script-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Sandbox.vue
65 lines (58 loc) · 1.69 KB
/
Sandbox.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<template>
<div id="sandbox">
<div id="preview" v-html="html"></div>
<div id="separator"></div>
<!--suppress HtmlFormInputWithoutLabel -->
<textarea ref="textarea" v-model="text" class="ipt"></textarea>
</div>
</template>
<script lang="ts">
import { updateAsyncScript } from '@/utils';
@vno.VPD.Component({ el: '#sandbox' })
export default class Sandbox extends vno.Vue {
// noinspection JSUnusedGlobalSymbols
$refs!: {
textarea: HTMLTextAreaElement
};
text = '';
html = '';
enableLS = true;
key = 'sandbox';
// noinspection JSUnusedGlobalSymbols
created() {
const data = document.querySelector('#sandbox')?.getAttribute('data');
if (data) {
this.enableLS = false;
this.text = decodeURIComponent(data);
} else {
this.text = vno.storage.getItem(this.key) || '';
}
vno.addEventListener(document, vno.EEvent.rendered, () => updateAsyncScript());
}
@vno.VPD.Watch('text')
onTextChanged() {
this.resize();
vno.renderMD(vno.filePath, vno.title, this.text, false, vno.articleSelf.asyncResults).then(html => {
this.html = html;
this.$nextTick(() => {
if (!updateAsyncScript()) {
vno.updateDom();
}
});
});
if (!this.enableLS) {
return;
}
if (this.text) {
vno.storage.setItem(this.key, this.text);
} else {
vno.storage.removeItem(this.key);
}
}
resize() {
this.$refs.textarea.style.height = '';
this.$refs.textarea.style.height = `${this.$refs.textarea.scrollHeight}px`;
}
}
</script>
<style lang="scss" scoped>@import "../styles/sandbox";</style>