blob: 55352821f66a058493df48cfa0a6e3edcd23190d (
plain) (
blame)
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
66
|
<template>
<n-card>
<n-form-item
label="Your raw json:"
:feedback="rawJsonValidation.message"
:validation-status="rawJsonValidation.status"
>
<n-input
v-model:value="rawJson"
class="json-input"
type="textarea"
placeholder="Paste your raw json here..."
autocomplete="off"
autocorrect="off"
autocapitalize="off"
spellcheck="false"
/>
</n-form-item>
<n-space justify="center">
<n-button secondary @click="rawJson = ''">Clear</n-button>
</n-space>
</n-card>
<n-card v-if="cleanJson.length > 0">
<n-scrollbar :x-scrollable="true">
<n-config-provider :hljs="hljs">
<n-code :code="cleanJson" language="json" />
</n-config-provider>
</n-scrollbar>
</n-card>
</template>
<script setup lang="ts">
import { ref, computed } from 'vue';
import hljs from 'highlight.js/lib/core';
import json from 'highlight.js/lib/languages/json';
import { useValidation } from '@/composable/validation';
hljs.registerLanguage('json', json);
const rawJson = ref('');
const cleanJson = computed(() => {
try {
return JSON.stringify(JSON.parse(rawJson.value), null, 3);
} catch (_) {
return '';
}
});
const rawJsonValidation = useValidation({
source: rawJson,
rules: [
{
validator: (v) => v === '' || JSON.parse(v),
message: 'Invalid json string',
},
],
});
</script>
<style lang="less" scoped>
.json-input ::v-deep(.n-input-wrapper) {
resize: both !important;
}
</style>
|