Merge branch 'feat/yaml-viewer-enh' into chore/all-my-stuffs

# Conflicts:
#	components.d.ts
#	package.json
#	pnpm-lock.yaml
This commit is contained in:
ShareVB committed 2024-11-03 23:13:46 +01:00
commit 2d1f43475e
4 files changed
+87 -57

No files matched your search

+5 -3
View File
@@ -5697,7 +5697,7 @@ packages:
/@types/lodash-es@4.17.10: /@types/lodash-es@4.17.10:
resolution: {integrity: sha512-YJP+w/2khSBwbUSFdGsSqmDvmnN3cCKoPOL7Zjle6s30ZtemkkqhjVfFqGwPN7ASil5VyjE2GtyU/yqYY6mC0A==} resolution: {integrity: sha512-YJP+w/2khSBwbUSFdGsSqmDvmnN3cCKoPOL7Zjle6s30ZtemkkqhjVfFqGwPN7ASil5VyjE2GtyU/yqYY6mC0A==}
dependencies: dependencies:
'@types/lodash': 4.14.192 '@types/lodash': 4.14.200
dev: false dev: false
/@types/lodash.defaultsdeep@4.6.9: /@types/lodash.defaultsdeep@4.6.9:
@@ -5720,6 +5720,7 @@ packages:
/@types/lodash@4.14.192: /@types/lodash@4.14.192:
resolution: {integrity: sha512-km+Vyn3BYm5ytMO13k9KTp27O75rbQ0NFw+U//g+PX7VZyjCioXaRFisqSIJRECljcTv73G3i6BpglNGHgUQ5A==} resolution: {integrity: sha512-km+Vyn3BYm5ytMO13k9KTp27O75rbQ0NFw+U//g+PX7VZyjCioXaRFisqSIJRECljcTv73G3i6BpglNGHgUQ5A==}
dev: true
/@types/lodash@4.14.200: /@types/lodash@4.14.200:
resolution: {integrity: sha512-YI/M/4HRImtNf3pJgbF+W6FrXovqj+T+/HpENLTooK9PnkacBsDpeP3IpHab40CClUfhNmdM2WTNP2sa2dni5Q==} resolution: {integrity: sha512-YI/M/4HRImtNf3pJgbF+W6FrXovqj+T+/HpENLTooK9PnkacBsDpeP3IpHab40CClUfhNmdM2WTNP2sa2dni5Q==}
@@ -6934,6 +6935,7 @@ packages:
resolution: {integrity: sha512-F0SAmZ8iUtS//m8DmCTA0jlh6TDKkHQyK6xc6V4KDTyZKA9dnvX9/3sRTVQrWm79glUAZbnmmNcdYwUIHWVybw==} resolution: {integrity: sha512-F0SAmZ8iUtS//m8DmCTA0jlh6TDKkHQyK6xc6V4KDTyZKA9dnvX9/3sRTVQrWm79glUAZbnmmNcdYwUIHWVybw==}
engines: {node: '>=0.4.0'} engines: {node: '>=0.4.0'}
hasBin: true hasBin: true
dev: true
/acorn@8.11.2: /acorn@8.11.2:
resolution: {integrity: sha512-nc0Axzp/0FILLEVsm4fNwLCwMttvhEI263QtVPQcbpfZZ3ts0hLsZGOpE6czNlid7CJ9MlyH8reXkpsf3YUY4w==} resolution: {integrity: sha512-nc0Axzp/0FILLEVsm4fNwLCwMttvhEI263QtVPQcbpfZZ3ts0hLsZGOpE6czNlid7CJ9MlyH8reXkpsf3YUY4w==}
@@ -15514,7 +15516,7 @@ packages:
/unimport@3.0.8(rollup@2.79.1): /unimport@3.0.8(rollup@2.79.1):
resolution: {integrity: sha512-AOt6xj3QMwqcTZRPB+NhFkyVEjCKnpTVoPm5x6424zz2NYYtCfym2bpJofzPHIJKPNIh5ko2/t2q46ZIMgdmbw==} resolution: {integrity: sha512-AOt6xj3QMwqcTZRPB+NhFkyVEjCKnpTVoPm5x6424zz2NYYtCfym2bpJofzPHIJKPNIh5ko2/t2q46ZIMgdmbw==}
dependencies: dependencies:
'@rollup/pluginutils': 5.0.2(rollup@2.79.1) '@rollup/pluginutils': 5.0.5(rollup@2.79.1)
escape-string-regexp: 5.0.0 escape-string-regexp: 5.0.0
fast-glob: 3.3.1 fast-glob: 3.3.1
local-pkg: 0.4.3 local-pkg: 0.4.3
@@ -15729,7 +15731,7 @@ packages:
/unplugin@1.4.0: /unplugin@1.4.0:
resolution: {integrity: sha512-5x4eIEL6WgbzqGtF9UV8VEC/ehKptPXDS6L2b0mv4FRMkJxRtjaJfOWDd6a8+kYbqsjklix7yWP0N3SUepjXcg==} resolution: {integrity: sha512-5x4eIEL6WgbzqGtF9UV8VEC/ehKptPXDS6L2b0mv4FRMkJxRtjaJfOWDd6a8+kYbqsjklix7yWP0N3SUepjXcg==}
dependencies: dependencies:
acorn: 8.10.0 acorn: 8.11.2
chokidar: 3.5.3 chokidar: 3.5.3
webpack-sources: 3.2.3 webpack-sources: 3.2.3
webpack-virtual-modules: 0.5.0 webpack-virtual-modules: 0.5.0
+20
View File
@@ -0,0 +1,20 @@
declare module 'composeverter' {
interface Configuration {
expandVolumes?: boolean;
expandPorts?: boolean;
indent?: number;
}
interface DockerComposeValidatioError {
line?: number;
message: string;
helpLink?: string;
}
export function validateDockerComposeToCommonSpec(content: string): DockerComposeValidatioError[];
export function migrateFromV2xToV3x(content: string, configuration?: Configuration = null): string;
export function migrateFromV3xToV2x(content: string, configuration?: Configuration = null): string;
export function migrateFromV1ToV2x(content: string, configuration?: Configuration = null): string;
export function migrateToCommonSpec(content: string, configuration?: Configuration = null): string;
export function migrateFromV2xToV3x(content: string, configuration?: Configuration = null): string;
export function getDockerComposeSchemaWithoutFormats(): object;
export function yamlParse(content: string): object;
}
+2 -2
View File
@@ -1,5 +1,5 @@
import { type MaybeRef, get } from '@vueuse/core'; import { type MaybeRef, get } from '@vueuse/core';
import { yamlParse } from 'composeverter';
import yaml from 'yaml'; import yaml from 'yaml';
export { formatYaml }; export { formatYaml };
@@ -13,7 +13,7 @@ function formatYaml({
sortKeys?: MaybeRef<boolean> sortKeys?: MaybeRef<boolean>
indentSize?: MaybeRef<number> indentSize?: MaybeRef<number>
}) { }) {
const parsedYaml = yaml.parse(get(rawYaml)); const parsedYaml = yamlParse(get(rawYaml));
const formattedYAML = yaml.stringify(parsedYaml, { const formattedYAML = yaml.stringify(parsedYaml, {
sortMapEntries: get(sortKeys), sortMapEntries: get(sortKeys),
+60 -52
View File
@@ -1,72 +1,80 @@
<script setup lang="ts"> <script setup lang="ts">
import yaml from 'yaml';
import { useStorage } from '@vueuse/core'; import { useStorage } from '@vueuse/core';
import { formatYaml } from './yaml-models'; import { formatYaml } from './yaml-models';
import { withDefaultOnError } from '@/utils/defaults';
import { useValidation } from '@/composable/validation';
import TextareaCopyable from '@/components/TextareaCopyable.vue'; import TextareaCopyable from '@/components/TextareaCopyable.vue';
const inputElement = ref<HTMLElement>();
const rawYaml = useStorage('yaml-prettify:raw-yaml', ''); const rawYaml = useStorage('yaml-prettify:raw-yaml', '');
const indentSize = useStorage('yaml-prettify:indent-size', 2); const indentSize = useStorage('yaml-prettify:indent-size', 2);
const sortKeys = useStorage('yaml-prettify:sort-keys', false); const sortKeys = useStorage('yaml-prettify:sort-keys', false);
const cleanYaml = computed(() => withDefaultOnError(() => formatYaml({ rawYaml, indentSize, sortKeys }), '')); const yamlFormattingResult = computed(() => {
try {
const rawYamlValidation = useValidation({ return { yaml: formatYaml({ rawYaml, indentSize, sortKeys }), errors: [] };
source: rawYaml, }
rules: [ catch (e: any) {
{ return { yaml: '#see error messages', errors: e.toString().split('\n') };
validator: v => v === '' || yaml.parse(v), }
message: 'Provided YAML is not valid.',
},
],
}); });
const errors = computed(() => yamlFormattingResult.value.errors);
const cleanYaml = computed(() => yamlFormattingResult.value.yaml);
const MONACO_EDITOR_OPTIONS = {
automaticLayout: true,
formatOnType: true,
formatOnPaste: true,
};
</script> </script>
<template> <template>
<div style="flex: 0 0 100%"> <div max-w-600>
<div style="margin: 0 auto; max-width: 600px" flex justify-center gap-3> <div style="flex: 0 0 100%">
<n-form-item label="Sort keys :" label-placement="left" label-width="100"> <div style="margin: 0 auto; max-width: 600px" flex justify-center gap-3>
<n-switch v-model:value="sortKeys" /> <n-form-item label="Sort keys :" label-placement="left" label-width="100">
</n-form-item> <n-switch v-model:value="sortKeys" />
<n-form-item label="Indent size :" label-placement="left" label-width="100" :show-feedback="false"> </n-form-item>
<n-input-number v-model:value="indentSize" min="1" max="10" style="width: 100px" /> <n-form-item label="Indent size :" label-placement="left" label-width="100" :show-feedback="false">
</n-form-item> <n-input-number v-model:value="indentSize" min="1" max="10" style="width: 100px" />
</n-form-item>
</div>
</div> </div>
</div>
<n-form-item <c-label label="Your raw YAML:">
label="Your raw YAML" <div relative w-full>
:feedback="rawYamlValidation.message" <c-monaco-editor
:validation-status="rawYamlValidation.status" v-model:value="rawYaml"
> theme="vs-dark"
<c-input-text language="yaml"
ref="inputElement" height="250px"
v-model:value="rawYaml" :options="MONACO_EDITOR_OPTIONS"
placeholder="Paste your raw YAML here..." />
rows="20" </div>
multiline </c-label>
autocomplete="off"
autocorrect="off" <div v-if="errors.length > 0">
autocapitalize="off" <n-alert title="The following errors occured" type="error" mt-5>
spellcheck="false" <ul>
monospace <li v-for="(message, index) of errors" :key="index">
/> {{ message }}
</n-form-item> </li>
<n-form-item label="Prettified version of your YAML"> </ul>
<TextareaCopyable :value="cleanYaml" language="yaml" :follow-height-of="inputElement" /> </n-alert>
</n-form-item> </div>
<n-divider />
<n-form-item label="Prettified version of your YAML">
<TextareaCopyable :value="cleanYaml" language="yaml" />
</n-form-item>
</div>
</template> </template>
<style lang="less" scoped> <style lang="less" scoped>
.result-card { .result-card {
position: relative; position: relative;
.copy-button { .copy-button {
position: absolute; position: absolute;
top: 10px; top: 10px;
right: 10px; right: 10px;
} }
} }
</style> </style>