summaryrefslogtreecommitdiff
path: root/src/client/components/form/object-view.vue
blob: 59fb62b5e695e2d787f2de05e8fdeb76cba46cbc (plain)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<template>
<FormGroup class="_formItem">
	<template #label><slot></slot></template>
	<div class="drooglns _formItem" :class="{ tall }">
		<div class="input _formPanel">
			<textarea class="_monospace"
				v-model="v"
				readonly
				:spellcheck="false"
			></textarea>
		</div>
	</div>
	<template #caption><slot name="desc"></slot></template>
</FormGroup>
</template>

<script lang="ts">
import { defineComponent, ref, toRefs, watch } from 'vue';
import * as JSON5 from 'json5';
import './form.scss';
import FormGroup from './group.vue';

export default defineComponent({
	components: {
		FormGroup,
	},
	props: {
		value: {
			required: false
		},
		tall: {
			type: Boolean,
			required: false,
			default: false
		},
		pre: {
			type: Boolean,
			required: false,
			default: false
		},
		manualSave: {
			type: Boolean,
			required: false,
			default: false
		},
	},
	setup(props, context) {
		const { value } = toRefs(props);
		const v = ref('');

		watch(() => value, newValue => {
			v.value = JSON5.stringify(newValue.value, null, '\t');
		}, {
			immediate: true
		});

		return {
			v,
		};
	}
});
</script>

<style lang="scss" scoped>
.drooglns {
	position: relative;

	> .input {
		position: relative;
	
		> textarea {
			display: block;
			width: 100%;
			min-width: 100%;
			max-width: 100%;
			min-height: 130px;
			margin: 0;
			padding: 16px var(--formContentHMargin);
			box-sizing: border-box;
			font: inherit;
			font-weight: normal;
			font-size: 1em;
			background: transparent;
			border: none;
			border-radius: 0;
			outline: none;
			box-shadow: none;
			color: var(--fg);
			tab-size: 2;
			white-space: pre;
		}
	}

	&.tall {
		> .input {
			> textarea {
				min-height: 200px;
			}
		}
	}
}
</style>