it-tools/src/tools/json-diff/json-diff.vue
Marvin ba4876d0d5
refacor(transformers): use monospace font for JSON and SQL text areas (#476)
* feat(c-input): Add monospace prop

* feat: use monospace input for json and sql inputs
2023-06-23 16:51:52 +02:00

48 lines
1.2 KiB
Vue

<script setup lang="ts">
import JSON5 from 'json5';
import DiffsViewer from './diff-viewer/diff-viewer.vue';
import { withDefaultOnError } from '@/utils/defaults';
import { isNotThrowing } from '@/utils/boolean';
const rawLeftJson = ref('');
const rawRightJson = ref('');
const leftJson = computed(() => withDefaultOnError(() => JSON5.parse(rawLeftJson.value), undefined));
const rightJson = computed(() => withDefaultOnError(() => JSON5.parse(rawRightJson.value), undefined));
const jsonValidationRules = [
{
validator: (value: string) => value === '' || isNotThrowing(() => JSON5.parse(value)),
message: 'Invalid JSON format',
},
];
</script>
<template>
<c-input-text
v-model:value="rawLeftJson"
:validation-rules="jsonValidationRules"
label="Your first JSON"
placeholder="Paste your first JSON here..."
rows="20"
multiline
test-id="leftJson"
raw-text
monospace
/>
<c-input-text
v-model:value="rawRightJson"
:validation-rules="jsonValidationRules"
label="Your JSON to compare"
placeholder="Paste your JSON to compare here..."
rows="20"
multiline
test-id="rightJson"
raw-text
monospace
/>
<DiffsViewer :left-json="leftJson" :right-json="rightJson" />
</template>