Skip to content

Commit 2d1f434

Browse files
committed
Merge branch 'feat/yaml-viewer-enh' into chore/all-my-stuffs
# Conflicts: # components.d.ts # package.json # pnpm-lock.yaml
2 parents e15b421 + e68f743 commit 2d1f434

File tree

4 files changed

+87
-57
lines changed

4 files changed

+87
-57
lines changed

pnpm-lock.yaml

Lines changed: 5 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
declare module 'composeverter' {
2+
interface Configuration {
3+
expandVolumes?: boolean;
4+
expandPorts?: boolean;
5+
indent?: number;
6+
}
7+
interface DockerComposeValidatioError {
8+
line?: number;
9+
message: string;
10+
helpLink?: string;
11+
}
12+
export function validateDockerComposeToCommonSpec(content: string): DockerComposeValidatioError[];
13+
export function migrateFromV2xToV3x(content: string, configuration?: Configuration = null): string;
14+
export function migrateFromV3xToV2x(content: string, configuration?: Configuration = null): string;
15+
export function migrateFromV1ToV2x(content: string, configuration?: Configuration = null): string;
16+
export function migrateToCommonSpec(content: string, configuration?: Configuration = null): string;
17+
export function migrateFromV2xToV3x(content: string, configuration?: Configuration = null): string;
18+
export function getDockerComposeSchemaWithoutFormats(): object;
19+
export function yamlParse(content: string): object;
20+
}

src/tools/yaml-viewer/yaml-models.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { type MaybeRef, get } from '@vueuse/core';
2-
2+
import { yamlParse } from 'composeverter';
33
import yaml from 'yaml';
44

55
export { formatYaml };
@@ -13,7 +13,7 @@ function formatYaml({
1313
sortKeys?: MaybeRef<boolean>
1414
indentSize?: MaybeRef<number>
1515
}) {
16-
const parsedYaml = yaml.parse(get(rawYaml));
16+
const parsedYaml = yamlParse(get(rawYaml));
1717

1818
const formattedYAML = yaml.stringify(parsedYaml, {
1919
sortMapEntries: get(sortKeys),

src/tools/yaml-viewer/yaml-viewer.vue

Lines changed: 60 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,80 @@
11
<script setup lang="ts">
2-
import yaml from 'yaml';
32
import { useStorage } from '@vueuse/core';
43
import { formatYaml } from './yaml-models';
5-
import { withDefaultOnError } from '@/utils/defaults';
6-
import { useValidation } from '@/composable/validation';
74
import TextareaCopyable from '@/components/TextareaCopyable.vue';
85
9-
const inputElement = ref<HTMLElement>();
10-
116
const rawYaml = useStorage('yaml-prettify:raw-yaml', '');
127
const indentSize = useStorage('yaml-prettify:indent-size', 2);
138
const sortKeys = useStorage('yaml-prettify:sort-keys', false);
149
15-
const cleanYaml = computed(() => withDefaultOnError(() => formatYaml({ rawYaml, indentSize, sortKeys }), ''));
16-
17-
const rawYamlValidation = useValidation({
18-
source: rawYaml,
19-
rules: [
20-
{
21-
validator: v => v === '' || yaml.parse(v),
22-
message: 'Provided YAML is not valid.',
23-
},
24-
],
10+
const yamlFormattingResult = computed(() => {
11+
try {
12+
return { yaml: formatYaml({ rawYaml, indentSize, sortKeys }), errors: [] };
13+
}
14+
catch (e: any) {
15+
return { yaml: '#see error messages', errors: e.toString().split('\n') };
16+
}
2517
});
18+
const errors = computed(() => yamlFormattingResult.value.errors);
19+
const cleanYaml = computed(() => yamlFormattingResult.value.yaml);
20+
21+
const MONACO_EDITOR_OPTIONS = {
22+
automaticLayout: true,
23+
formatOnType: true,
24+
formatOnPaste: true,
25+
};
2626
</script>
2727

2828
<template>
29-
<div style="flex: 0 0 100%">
30-
<div style="margin: 0 auto; max-width: 600px" flex justify-center gap-3>
31-
<n-form-item label="Sort keys :" label-placement="left" label-width="100">
32-
<n-switch v-model:value="sortKeys" />
33-
</n-form-item>
34-
<n-form-item label="Indent size :" label-placement="left" label-width="100" :show-feedback="false">
35-
<n-input-number v-model:value="indentSize" min="1" max="10" style="width: 100px" />
36-
</n-form-item>
29+
<div max-w-600>
30+
<div style="flex: 0 0 100%">
31+
<div style="margin: 0 auto; max-width: 600px" flex justify-center gap-3>
32+
<n-form-item label="Sort keys :" label-placement="left" label-width="100">
33+
<n-switch v-model:value="sortKeys" />
34+
</n-form-item>
35+
<n-form-item label="Indent size :" label-placement="left" label-width="100" :show-feedback="false">
36+
<n-input-number v-model:value="indentSize" min="1" max="10" style="width: 100px" />
37+
</n-form-item>
38+
</div>
3739
</div>
38-
</div>
3940

40-
<n-form-item
41-
label="Your raw YAML"
42-
:feedback="rawYamlValidation.message"
43-
:validation-status="rawYamlValidation.status"
44-
>
45-
<c-input-text
46-
ref="inputElement"
47-
v-model:value="rawYaml"
48-
placeholder="Paste your raw YAML here..."
49-
rows="20"
50-
multiline
51-
autocomplete="off"
52-
autocorrect="off"
53-
autocapitalize="off"
54-
spellcheck="false"
55-
monospace
56-
/>
57-
</n-form-item>
58-
<n-form-item label="Prettified version of your YAML">
59-
<TextareaCopyable :value="cleanYaml" language="yaml" :follow-height-of="inputElement" />
60-
</n-form-item>
41+
<c-label label="Your raw YAML:">
42+
<div relative w-full>
43+
<c-monaco-editor
44+
v-model:value="rawYaml"
45+
theme="vs-dark"
46+
language="yaml"
47+
height="250px"
48+
:options="MONACO_EDITOR_OPTIONS"
49+
/>
50+
</div>
51+
</c-label>
52+
53+
<div v-if="errors.length > 0">
54+
<n-alert title="The following errors occured" type="error" mt-5>
55+
<ul>
56+
<li v-for="(message, index) of errors" :key="index">
57+
{{ message }}
58+
</li>
59+
</ul>
60+
</n-alert>
61+
</div>
62+
63+
<n-divider />
64+
65+
<n-form-item label="Prettified version of your YAML">
66+
<TextareaCopyable :value="cleanYaml" language="yaml" />
67+
</n-form-item>
68+
</div>
6169
</template>
6270

63-
<style lang="less" scoped>
64-
.result-card {
65-
position: relative;
66-
.copy-button {
71+
<style lang="less" scoped>
72+
.result-card {
73+
position: relative;
74+
.copy-button {
6775
position: absolute;
6876
top: 10px;
6977
right: 10px;
70-
}
71-
}
72-
</style>
78+
}
79+
}
80+
</style>

0 commit comments

Comments
 (0)