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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "v-code-diff",
3
- "version": "1.6.1",
3
+ "version": "1.7.0",
4
4
  "description": "template component for vue-demi, can dev and build",
5
5
  "exports": {
6
6
  ".": {
package/scripts/utils.js CHANGED
@@ -1,5 +1,7 @@
1
- const fs = require('node:fs')
2
- const path = require('node:path')
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>
@@ -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 class="blob-num" :class="{
38
- 'blob-num-deletion': line.type === DiffType.DELETE,
39
- 'blob-num-addition': line.type === DiffType.ADD,
40
- 'blob-num-context': line.type === DiffType.EQUAL,
41
- 'blob-num-hunk': splitLine.hide !== undefined,
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 class="blob-code" :class="{
47
- 'blob-code-deletion': line.type === DiffType.DELETE,
48
- 'blob-code-addition': line.type === DiffType.ADD,
49
- 'blob-code-context': line.type === DiffType.EQUAL,
50
- 'blob-code-hunk': splitLine.hide !== undefined,
51
-
52
- }">
53
- <span class="blob-code-inner blob-code-marker" :data-code-marker="getCodeMarker(line.type)"
54
- v-html="line.code" />
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
-