v-code-diff 1.6.1 → 1.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/v2/index.cjs.js +12 -12
- package/dist/v2/index.es.js +258 -230
- package/dist/v2/index.umd.js +13 -13
- package/dist/v2.7/index.cjs.js +8 -8
- package/dist/v2.7/index.es.js +290 -276
- package/dist/v2.7/index.umd.js +5 -5
- package/dist/v3/index.cjs.js +11 -11
- package/dist/v3/index.es.js +358 -339
- package/dist/v3/index.umd.js +11 -11
- package/package.json +1 -1
- package/scripts/utils.js +4 -2
- package/src/CodeDiff.vue +6 -2
- package/src/split/SplitLine.vue +39 -17
- package/src/style.scss +4 -1
package/package.json
CHANGED
package/scripts/utils.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
const
|
|
1
|
+
// eslint-disable-next-line unicorn/prefer-node-protocol
|
|
2
|
+
const fs = require('fs')
|
|
3
|
+
// eslint-disable-next-line unicorn/prefer-node-protocol
|
|
4
|
+
const path = require('path')
|
|
3
5
|
|
|
4
6
|
const dir = path.resolve(__dirname, '..', 'dist')
|
|
5
7
|
|
package/src/CodeDiff.vue
CHANGED
|
@@ -18,6 +18,8 @@ interface Props {
|
|
|
18
18
|
noDiffLineFeed?: boolean
|
|
19
19
|
maxHeight?: string
|
|
20
20
|
filename?: string
|
|
21
|
+
hideHeader: boolean
|
|
22
|
+
hideStat: boolean
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
interface DiffResult {
|
|
@@ -37,6 +39,8 @@ const props = withDefaults(defineProps<Props>(), {
|
|
|
37
39
|
noDiffLineFeed: false,
|
|
38
40
|
maxHeight: undefined,
|
|
39
41
|
filename: undefined,
|
|
42
|
+
hideHeader: false,
|
|
43
|
+
hideStat: false,
|
|
40
44
|
})
|
|
41
45
|
|
|
42
46
|
const emits = defineEmits<{
|
|
@@ -80,10 +84,10 @@ watch(() => props, () => {
|
|
|
80
84
|
|
|
81
85
|
<template>
|
|
82
86
|
<div class="code-diff-view" :style="{ maxHeight }">
|
|
83
|
-
<div class="file-header">
|
|
87
|
+
<div v-if="!hideHeader" class="file-header">
|
|
84
88
|
<div class="file-info">
|
|
85
89
|
<span class="filename">{{ filename }}</span>
|
|
86
|
-
<span class="diff-stat">
|
|
90
|
+
<span v-if="!hideStat" class="diff-stat">
|
|
87
91
|
<span class="diff-stat-added">+{{ diffChange.stat.additionsNum }} additions</span>
|
|
88
92
|
<span class="diff-stat-deleted" style="margin-left: 8px;">-{{ diffChange.stat.deletionsNum }} deletions</span>
|
|
89
93
|
</span>
|
package/src/split/SplitLine.vue
CHANGED
|
@@ -15,6 +15,19 @@ function getCodeMarker(type: DiffType) {
|
|
|
15
15
|
return '+'
|
|
16
16
|
return ''
|
|
17
17
|
}
|
|
18
|
+
|
|
19
|
+
function onSplitLineMousedown(side: 'left' | 'right') {
|
|
20
|
+
window.getSelection()!.removeAllRanges()
|
|
21
|
+
|
|
22
|
+
const leftElements = document.querySelectorAll('.file-diff-split .split-side-left')!
|
|
23
|
+
const rightElements = document.querySelectorAll('.file-diff-split .split-side-right')!
|
|
24
|
+
|
|
25
|
+
for (const el of rightElements)
|
|
26
|
+
el.classList.toggle('no-select', side === 'left')
|
|
27
|
+
|
|
28
|
+
for (const el of leftElements)
|
|
29
|
+
el.classList.toggle('no-select', side === 'right')
|
|
30
|
+
}
|
|
18
31
|
</script>
|
|
19
32
|
|
|
20
33
|
<template>
|
|
@@ -27,31 +40,40 @@ function getCodeMarker(type: DiffType) {
|
|
|
27
40
|
</td>
|
|
28
41
|
</tr>
|
|
29
42
|
<tr v-else-if="!splitLine.hide">
|
|
30
|
-
<template v-for="line in [splitLine.left, splitLine.right]">
|
|
43
|
+
<template v-for="(line, index) in [splitLine.left, splitLine.right]">
|
|
31
44
|
<!-- eslint-disable -->
|
|
32
45
|
<template v-if="line.type === DiffType.EMPTY">
|
|
33
46
|
<td class="blob-num blob-num-empty empty-cell" />
|
|
34
47
|
<td class="blob-code blob-code-empty empty-cell" />
|
|
35
48
|
</template>
|
|
36
49
|
<template v-else>
|
|
37
|
-
<td
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
50
|
+
<td
|
|
51
|
+
class="blob-num"
|
|
52
|
+
:class="{
|
|
53
|
+
'blob-num-deletion': line.type === DiffType.DELETE,
|
|
54
|
+
'blob-num-addition': line.type === DiffType.ADD,
|
|
55
|
+
'blob-num-context': line.type === DiffType.EQUAL,
|
|
56
|
+
'blob-num-hunk': splitLine.hide !== undefined,
|
|
57
|
+
}"
|
|
58
|
+
>
|
|
44
59
|
{{ line.num }}
|
|
45
60
|
</td>
|
|
46
|
-
<td
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
61
|
+
<td
|
|
62
|
+
class="blob-code"
|
|
63
|
+
:class="{
|
|
64
|
+
'blob-code-deletion': line.type === DiffType.DELETE,
|
|
65
|
+
'blob-code-addition': line.type === DiffType.ADD,
|
|
66
|
+
'blob-code-context': line.type === DiffType.EQUAL,
|
|
67
|
+
'blob-code-hunk': splitLine.hide !== undefined,
|
|
68
|
+
'split-side-left': index === 0,
|
|
69
|
+
'split-side-right': index === 1,
|
|
70
|
+
}"
|
|
71
|
+
@mousedown="onSplitLineMousedown(index === 0 ? 'left' : 'right')"
|
|
72
|
+
>
|
|
73
|
+
<span
|
|
74
|
+
class="blob-code-inner blob-code-marker" :data-code-marker="getCodeMarker(line.type)"
|
|
75
|
+
v-html="line.code"
|
|
76
|
+
/>
|
|
55
77
|
</td>
|
|
56
78
|
</template>
|
|
57
79
|
<!-- eslint-enable -->
|
package/src/style.scss
CHANGED
|
@@ -140,6 +140,10 @@
|
|
|
140
140
|
.blob-code + .blob-num {
|
|
141
141
|
border-left: 1px solid var(--color-border-muted);
|
|
142
142
|
}
|
|
143
|
+
|
|
144
|
+
.no-select {
|
|
145
|
+
user-select: none;
|
|
146
|
+
}
|
|
143
147
|
}
|
|
144
148
|
|
|
145
149
|
.empty-cell {
|
|
@@ -148,4 +152,3 @@
|
|
|
148
152
|
border-right-color: var(--color-border-muted);
|
|
149
153
|
}
|
|
150
154
|
}
|
|
151
|
-
|