Skip to content

Commit a79b28c

Browse files
committed
feat: expose a diff event
1 parent 764ba91 commit a79b28c

1 file changed

Lines changed: 24 additions & 2 deletions

File tree

src/CodeDiff.vue

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ interface Props {
2020
filename?: string
2121
}
2222
23+
interface DiffResult {
24+
stat: {
25+
isChanged: boolean
26+
addNum: number
27+
delNum: number
28+
}
29+
}
30+
2331
const props = withDefaults(defineProps<Props>(), {
2432
language: 'plaintext',
2533
context: 10,
@@ -31,6 +39,10 @@ const props = withDefaults(defineProps<Props>(), {
3139
filename: undefined,
3240
})
3341
42+
const emits = defineEmits<{
43+
(e: 'diff', diffResult: DiffResult): void
44+
}>()
45+
3446
const isUnifiedViewer = computed(() => props.outputFormat === 'line-by-line')
3547
3648
const oldString = computed(() => {
@@ -52,9 +64,18 @@ const raw = computed(() =>
5264
: createSplitDiff(oldString.value, newString.value, props.language, props.diffStyle, props.context),
5365
)
5466
const diffChange = ref(raw.value)
67+
const isNotChanged = computed(() => diffChange.value.stat.additionsNum === 0 && diffChange.value.stat.deletionsNum === 0)
68+
5569
watch(() => props, () => {
5670
diffChange.value = raw.value
57-
}, { deep: true })
71+
emits('diff', {
72+
stat: {
73+
isChanged: !isNotChanged.value,
74+
addNum: diffChange.value.stat.additionsNum,
75+
delNum: diffChange.value.stat.deletionsNum,
76+
},
77+
})
78+
}, { deep: true, immediate: true })
5879
</script>
5980

6081
<template>
@@ -73,4 +94,5 @@ watch(() => props, () => {
7394
</div>
7495
</template>
7596

76-
<style lang="scss"></style>
97+
<style lang="scss">
98+
</style>

0 commit comments

Comments
 (0)