Skip to content

Commit

Permalink
Cleanup diff html.
Browse files Browse the repository at this point in the history
  • Loading branch information
Damnae committed Apr 12, 2024
1 parent edbdad6 commit ce2a311
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 46 deletions.
4 changes: 2 additions & 2 deletions src/views/diff/AnyDiff.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
import ObjectDiff from '@/views/diff/ObjectDiff.vue';
import ArrayDiff from '@/views/diff/ArrayDiff.vue';
import ValueDiff from '@/views/diff/ValueDiff.vue';
defineProps<{diffNode:DiffNode, prefix?:string}>()
defineProps<{diffNode:DiffNode, prefix?:string|number}>()
</script>

<template>
<span :class="`diff-node change-${diffNode.Change}`" :title="`${diffNode.Change} ${diffNode.Type}`">
<template v-if="prefix">
{{ prefix }}
{{ prefix }}:
</template>

<template v-if="diffNode.Type == DiffNodeType.Value">
Expand Down
10 changes: 5 additions & 5 deletions src/views/diff/AnyPlain.vue
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
<script setup lang="ts">
defineProps<{value:any, prefix?:string}>()
defineProps<{value:any, prefix?:string|number}>()
</script>

<template>
<span class="diff-node">
<span class="diff-node plain">
<template v-if="prefix">
{{ prefix }}
{{ prefix }}:
</template>

<span class="diff-array" v-if="Array.isArray(value)">
[
<span class="array-item block" v-for="entry, _key in value">
<AnyPlain :value="entry" />
<AnyPlain :value="entry" />
</span>
]
</span>
<span class="diff-object" v-else-if="typeof value === 'object'">
{
<span class="object-item block" v-for="entry, key in value">
<AnyPlain :value="entry" :prefix="`${key}: `" />
<AnyPlain :value="entry" :prefix="key" />
</span>
}
</span>
Expand Down
26 changes: 12 additions & 14 deletions src/views/diff/ArrayDiff.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,19 @@
</script>

<template>
<span class="diff-array">
<template v-if="values && values.length > 0">
[
<span class="array-item block" v-for="node, _key in values">
<AnyDiff :diffNode="node" />
</span>
]
</template>
<span class="array-item" v-else-if="diffNode.Change == DiffNodeChange.Removed">
<AnyPlain :value="diffNode.FromValue" />
</span>
<span class="array-item" v-else>
<AnyPlain :value="diffNode.ToValue" />
</span>
<span class="diff-array" v-if="values && values.length > 0">
[
<span class="array-item block" v-for="node, _key in values">
<AnyDiff :diffNode="node" />
</span>
]
</span>
<template v-else-if="diffNode.Change == DiffNodeChange.Removed">
<AnyPlain :value="diffNode.FromValue" />
</template>
<template v-else>
<AnyPlain :value="diffNode.ToValue" />
</template>
</template>

<style scoped>
Expand Down
26 changes: 12 additions & 14 deletions src/views/diff/ObjectDiff.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,19 @@
</script>

<template>
<span class="diff-object">
<template v-if="properties && Object.keys(properties).length > 0">
{
<span class="object-item block" v-for="node, key in properties">
<AnyDiff :diffNode="node" :prefix="`${key}: `" />
</span>
}
</template>
<span class="object-item" v-else-if="diffNode.Change == DiffNodeChange.Removed">
<AnyPlain :value="diffNode.FromValue" />
</span>
<span class="object-item" v-else>
<AnyPlain :value="diffNode.ToValue" />
</span>
<span class="diff-object" v-if="properties && Object.keys(properties).length > 0">
{
<span class="object-item block" v-for="node, key in properties">
<AnyDiff :diffNode="node" :prefix="key" />
</span>
}
</span>
<template v-else-if="diffNode.Change == DiffNodeChange.Removed">
<AnyPlain :value="diffNode.FromValue" />
</template>
<template v-else>
<AnyPlain :value="diffNode.ToValue" />
</template>
</template>

<style scoped>
Expand Down
18 changes: 8 additions & 10 deletions src/views/diff/ValueDiff.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@
</script>

<template>
<span class="diff-value">
<template v-if="diffNode.Change == DiffNodeChange.Replaced">
<span class="change-Removed">{{ diffNode.FromValue }}</span> <span class="change-Added">{{ diffNode.ToValue }}</span>
</template>
<template v-else-if="diffNode.Change == DiffNodeChange.Removed">
<AnyPlain :value="diffNode.FromValue" />
</template>
<template v-else>
<AnyPlain :value="diffNode.ToValue" />
</template>
<span class="diff-value" v-if="diffNode.Change == DiffNodeChange.Replaced">
<span class="change-Removed">{{ diffNode.FromValue }}</span> <span class="change-Added">{{ diffNode.ToValue }}</span>
</span>
<template v-else-if="diffNode.Change == DiffNodeChange.Removed">
<AnyPlain :value="diffNode.FromValue" />
</template>
<template v-else>
<AnyPlain :value="diffNode.ToValue" />
</template>
</template>

<style scoped>
Expand Down
1 change: 0 additions & 1 deletion src/views/diff/diff.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import translate from "@/common/translate"

export enum DiffNodeType
{
Expand Down

0 comments on commit ce2a311

Please sign in to comment.