v-code-diff 1.0.0 → 1.2.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.0.0",
3
+ "version": "1.2.0",
4
4
  "description": "template component for vue-demi, can dev and build",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.es.js",
@@ -23,9 +23,11 @@
23
23
  "build:2.7": "vue-demi-switch 2.7 vue2 && pnpm --filter vue2.7-playground build",
24
24
  "build:3": "vue-demi-switch 3 vue3 && pnpm --filter vue3-playground build",
25
25
  "clean": "rimraf ./dist",
26
+ "deploy:demo": "pnpm --filter demo gh-pages",
26
27
  "dev:2": "vue-demi-switch 2 vue2 && pnpm --filter vue2-playground dev",
27
28
  "dev:2.7": "vue-demi-switch 2.7 vue2 && pnpm --filter vue2.7-playground dev",
28
29
  "dev:3": "vue-demi-switch 3 vue3 && pnpm --filter vue3-playground dev",
30
+ "dev:demo": "vue-demi-switch 3 vue3 && pnpm --filter demo dev",
29
31
  "lint:fix": "eslint . --ext .vue,.js,.jsx,.ts,.tsx --fix --ignore-path .gitignore",
30
32
  "postinstall": "node scripts/postinstall.js",
31
33
  "prepublishOnly": "npm run build",
@@ -33,8 +35,12 @@
33
35
  },
34
36
  "author": "Shimada666<649940882@qq.com>",
35
37
  "license": "MIT",
38
+ "bugs": {
39
+ "url": "https://github.com/Shimada666/v-code-diff/issues"
40
+ },
36
41
  "repository": {
37
- "type": "git"
42
+ "type": "git",
43
+ "url": "git+https://github.com/Shimada666/v-code-diff.git"
38
44
  },
39
45
  "peerDependencies": {
40
46
  "@vue/composition-api": "^1.4.9",
@@ -48,7 +54,7 @@
48
54
  "dependencies": {
49
55
  "diff": "^5.0.0",
50
56
  "highlight.js": "^11.6.0",
51
- "vue-demi": "latest"
57
+ "vue-demi": "^0.13.11"
52
58
  },
53
59
  "devDependencies": {
54
60
  "@antfu/eslint-config": "^0.34.0",
@@ -3,7 +3,7 @@ const { switchVersion, loadModule } = require('./utils')
3
3
  const Vue = loadModule('vue')
4
4
 
5
5
  if (!Vue || typeof Vue.version !== 'string')
6
- console.warn('[vue-demi-sfc-component-template] Vue is not found. Please run "npm install vue" to install.')
6
+ console.warn('[v-code-diff] Vue is not found. Please run "npm install vue" to install.')
7
7
 
8
8
  else if (Vue.version.startsWith('2.7.'))
9
9
  switchVersion('2.7')
@@ -15,4 +15,4 @@ else if (Vue.version.startsWith('3.'))
15
15
  switchVersion('3')
16
16
 
17
17
  else
18
- console.warn(`[vue-demi-sfc-component-template] Vue version v${Vue.version} is not suppported.`)
18
+ console.warn(`[v-code-diff] Vue version v${Vue.version} is not suppported.`)
package/src/CodeDiff.vue CHANGED
@@ -16,6 +16,8 @@ interface Props {
16
16
  outputFormat?: 'line-by-line' | 'side-by-side'
17
17
  trim?: boolean
18
18
  noDiffLineFeed?: boolean
19
+ maxHeight?: number
20
+ filename?: string
19
21
  }
20
22
 
21
23
  const props = withDefaults(defineProps<Props>(), {
@@ -25,6 +27,8 @@ const props = withDefaults(defineProps<Props>(), {
25
27
  outputFormat: 'line-by-line',
26
28
  trim: false,
27
29
  noDiffLineFeed: false,
30
+ maxHeight: undefined,
31
+ filename: undefined,
28
32
  })
29
33
 
30
34
  const isUnifiedViewer = computed(() => props.outputFormat === 'line-by-line')
@@ -46,9 +50,18 @@ const diffChange = computed(() =>
46
50
  </script>
47
51
 
48
52
  <template>
49
- <div class="code-diff-view">
50
- <UnifiedViewer v-if="isUnifiedViewer" :diff-change="diffChange" />
51
- <SplitViewer v-else :diff-change="diffChange" />
53
+ <div class="code-diff-view" :style="{ maxHeight }">
54
+ <div class="file-header">
55
+ <div class="file-info">
56
+ <span class="filename">{{ filename }}</span>
57
+ <span class="diff-stat">
58
+ <span class="diff-stat-added">+{{ diffChange.stat.additionsNum }} additions</span>
59
+ <span class="diff-stat-deleted" style="margin-left: 8px;">-{{ diffChange.stat.deletionsNum }} deletions</span>
60
+ </span>
61
+ </div>
62
+ </div>
63
+ <UnifiedViewer v-if="isUnifiedViewer" :diff-change="diffChange.changes" />
64
+ <SplitViewer v-else :diff-change="diffChange.changes" />
52
65
  </div>
53
66
  </template>
54
67
 
@@ -17,10 +17,10 @@ const getCodeMarker = (type: DiffType) => {
17
17
 
18
18
  <template>
19
19
  <tr v-if="splitLine.fold">
20
- <td class="blob-num blob-num-empty empty-cell" colspan="1">
20
+ <td class="blob-num blob-num-hunk" colspan="1">
21
21
  >
22
22
  </td>
23
- <td class="blob-code blob-code-empty empty-cell" colspan="3" align="left">
23
+ <td class="blob-code blob-code-inner blob-code-hunk" colspan="3" align="left">
24
24
 
25
25
  </td>
26
26
  </tr>
@@ -8,19 +8,17 @@ const props = defineProps<{
8
8
  </script>
9
9
 
10
10
  <template>
11
- <div class="file">
12
- <table class="file-diff-split diff-table">
13
- <colgroup>
14
- <col width="44">
15
- <col>
16
- <col width="44">
17
- <col>
18
- </colgroup>
19
- <tbody>
20
- <SplitLine v-for="(item, index) in diffChange" :key="index" :split-line="item" />
21
- </tbody>
22
- </table>
23
- </div>
11
+ <table class="file-diff-split diff-table">
12
+ <colgroup>
13
+ <col width="44">
14
+ <col>
15
+ <col width="44">
16
+ <col>
17
+ </colgroup>
18
+ <tbody>
19
+ <SplitLine v-for="(item, index) in diffChange" :key="index" :split-line="item" />
20
+ </tbody>
21
+ </table>
24
22
  </template>
25
23
 
26
24
  <style scoped></style>
package/src/style.scss CHANGED
@@ -5,110 +5,146 @@
5
5
  position: static;
6
6
  }
7
7
 
8
- .file {
9
- position: relative;
10
- margin-top: 16px;
11
- margin-bottom: 16px;
12
- border: 1px solid var(--color-border-default, #ddd);
13
- border-radius: 2px;
14
-
15
- table {
16
- border-spacing: 0;
17
- }
18
- .diff-table {
19
- width: 100%;
20
-
21
- .blob-num {
22
- position: relative;
23
- width: 1%;
24
- min-width: 50px;
25
- padding-right: 10px;
26
- padding-left: 10px;
27
- font-family: ui-monospace, SFMono-Regular, SF Mono, Menlo, Consolas, Liberation Mono, monospace;
28
- font-size: 12px;
29
- line-height: 20px;
30
- color: var(--color-fg-subtle);
31
- text-align: right;
32
- white-space: nowrap;
33
- vertical-align: top;
34
- cursor: pointer;
35
- -webkit-user-select: none;
36
- user-select: none;
37
- }
38
- .blob-num-deletion {
39
- color: var(--color-diff-blob-deletion-num-text);
40
- background-color: var(--color-diff-blob-deletion-num-bg);
41
- border-color: var(--color-danger-emphasis);
42
- }
43
- .blob-num-addition {
44
- color: var(--color-diff-blob-addition-num-text);
45
- background-color: var(--color-diff-blob-addition-num-bg);
46
- border-color: var(--color-success-emphasis);
47
- }
8
+ position: relative;
9
+ margin-top: 16px;
10
+ margin-bottom: 16px;
11
+ border: 1px solid var(--color-border-default, #ddd);
12
+ border-radius: 6px;
48
13
 
49
- .blob-code {
50
- position: relative;
51
- padding-right: 10px;
52
- padding-left: 10px;
53
- line-height: 20px;
54
- vertical-align: top;
55
- .blob-code-inner {
56
- display: table-cell;
57
- overflow: visible;
58
- font-family: ui-monospace, SFMono-Regular, SF Mono, Menlo, Consolas, Liberation Mono, monospace;
59
- font-size: 12px;
60
- color: var(--color-fg-default);
61
- word-wrap: anywhere;
62
- white-space: pre-wrap;
63
- }
64
- }
65
- .blob-code-deletion {
66
- background-color: var(--color-diff-blob-deletion-line-bg);
67
- outline: 1px dashed transparent;
14
+ overflow-y: auto;
15
+
16
+ .file-header {
17
+ background-color: var(--color-canvas-subtle);
18
+ border-bottom: 1px solid var(--color-border-default);
19
+ padding: 8px 16px;
20
+ font-size: 12px;
21
+ font-family: ui-monospace,SFMono-Regular,SF Mono,Menlo,Consolas,Liberation Mono,monospace;
68
22
 
69
- .x {
70
- color: var(--color-diff-blob-deletion-fg);
71
- background-color: var(--color-diff-blob-deletion-word-bg);
23
+ .file-info {
24
+ display: flex;
25
+ justify-content: space-between;
26
+ align-items: center;
27
+ margin-left: 8px;
28
+ height: 24px;
29
+
30
+ .filename {
31
+ font-size: 13px;
32
+ color: var(--color-fg-default);
33
+ }
34
+ .diff-stat {
35
+ .diff-stat-added {
36
+ color: var(--color-diffstat-addition-bg)
37
+ }
38
+ .diff-stat-deleted {
39
+ color: var(--color-danger-emphasis)
72
40
  }
73
41
  }
74
- .blob-code-addition {
75
- background-color: var(--color-diff-blob-addition-line-bg);
76
- outline: 1px dotted transparent;
42
+ }
43
+ }
77
44
 
78
- .x {
79
- color: var(--color-diff-blob-addition-fg);
80
- background-color: var(--color-diff-blob-addition-word-bg);
81
- }
45
+ table {
46
+ border-spacing: 0;
47
+ }
48
+ .diff-table {
49
+ width: 100%;
50
+
51
+ .blob-num {
52
+ position: relative;
53
+ width: 1%;
54
+ min-width: 50px;
55
+ padding-right: 10px;
56
+ padding-left: 10px;
57
+ font-family: ui-monospace, SFMono-Regular, SF Mono, Menlo, Consolas, Liberation Mono, monospace;
58
+ font-size: 12px;
59
+ line-height: 20px;
60
+ color: var(--color-fg-subtle);
61
+ text-align: right;
62
+ white-space: nowrap;
63
+ vertical-align: top;
64
+ cursor: pointer;
65
+ -webkit-user-select: none;
66
+ user-select: none;
67
+ }
68
+ .blob-num-deletion {
69
+ color: var(--color-diff-blob-deletion-num-text);
70
+ background-color: var(--color-diff-blob-deletion-num-bg);
71
+ border-color: var(--color-danger-emphasis);
72
+ }
73
+ .blob-num-addition {
74
+ color: var(--color-diff-blob-addition-num-text);
75
+ background-color: var(--color-diff-blob-addition-num-bg);
76
+ border-color: var(--color-success-emphasis);
77
+ }
78
+
79
+ .blob-code {
80
+ position: relative;
81
+ padding-right: 10px;
82
+ padding-left: 10px;
83
+ line-height: 20px;
84
+ vertical-align: top;
85
+ .blob-code-inner {
86
+ display: table-cell;
87
+ overflow: visible;
88
+ font-family: ui-monospace, SFMono-Regular, SF Mono, Menlo, Consolas, Liberation Mono, monospace;
89
+ font-size: 12px;
90
+ color: var(--color-fg-default);
91
+ word-wrap: anywhere;
92
+ white-space: pre-wrap;
82
93
  }
94
+ }
95
+ .blob-code-deletion {
96
+ background-color: var(--color-diff-blob-deletion-line-bg);
97
+ outline: 1px dashed transparent;
83
98
 
84
- .blob-code-context,
85
- .blob-code-addition,
86
- .blob-code-deletion {
87
- padding-left: 22px !important;
99
+ .x {
100
+ color: var(--color-diff-blob-deletion-fg);
101
+ background-color: var(--color-diff-blob-deletion-word-bg);
88
102
  }
103
+ }
104
+ .blob-code-addition {
105
+ background-color: var(--color-diff-blob-addition-line-bg);
106
+ outline: 1px dotted transparent;
89
107
 
90
- .blob-code-marker::before {
91
- position: absolute;
92
- top: 1px;
93
- left: 8px;
94
- padding-right: 8px;
95
- content: attr(data-code-marker);
108
+ .x {
109
+ color: var(--color-diff-blob-addition-fg);
110
+ background-color: var(--color-diff-blob-addition-word-bg);
96
111
  }
97
112
  }
98
113
 
99
- .file-diff-split {
100
- table-layout: fixed;
114
+ .blob-code-context,
115
+ .blob-code-addition,
116
+ .blob-code-deletion {
117
+ padding-left: 22px !important;
118
+ }
101
119
 
102
- .blob-code + .blob-num {
103
- border-left: 1px solid var(--color-border-muted);
104
- }
120
+ .blob-code-marker::before {
121
+ position: absolute;
122
+ top: 1px;
123
+ left: 8px;
124
+ padding-right: 8px;
125
+ content: attr(data-code-marker);
126
+ }
127
+
128
+ .blob-num-hunk {
129
+ background-color: var(--color-diff-blob-hunk-num-bg);
130
+ }
131
+ .blob-code-hunk {
132
+ background-color: var(--color-accent-subtle);
105
133
  }
134
+ }
135
+
136
+ .file-diff-split {
137
+ table-layout: fixed;
106
138
 
107
- .empty-cell {
108
- cursor: default;
109
- background-color: var(--color-neutral-subtle);
110
- border-right-color: var(--color-border-muted);
139
+ .blob-code + .blob-num {
140
+ border-left: 1px solid var(--color-border-muted);
111
141
  }
112
142
  }
113
143
 
144
+ .empty-cell {
145
+ cursor: default;
146
+ background-color: var(--color-neutral-subtle);
147
+ border-right-color: var(--color-border-muted);
148
+ }
114
149
  }
150
+
package/src/types.ts CHANGED
@@ -25,5 +25,16 @@ export interface UnifiedLine {
25
25
  addNum?: number
26
26
  }
27
27
 
28
- export type SplitViewerChange = SplitDiffLine[]
29
- export type UnifiedViewerChange = UnifiedLine[]
28
+ export interface DiffStat {
29
+ additionsNum: number
30
+ deletionsNum: number
31
+ }
32
+ export interface SplitViewerChange {
33
+ changes: SplitDiffLine[]
34
+ stat: DiffStat
35
+ }
36
+
37
+ export interface UnifiedViewerChange {
38
+ changes: UnifiedLine[]
39
+ stat: DiffStat
40
+ }
@@ -17,13 +17,13 @@ const getCodeMarker = (type: DiffType) => {
17
17
 
18
18
  <template>
19
19
  <tr v-if="line.fold">
20
- <td class="blob-num blob-num-empty empty-cell">
20
+ <td class="blob-num blob-num-hunk">
21
21
  >
22
22
  </td>
23
- <td class="blob-num blob-num-empty empty-cell">
23
+ <td class="blob-num blob-num-hunk">
24
24
  >
25
25
  </td>
26
- <td class="blob-code blob-code-empty empty-cell" align="left">
26
+ <td class="blob-code blob-code-hunk" align="left">
27
27
 
28
28
  </td>
29
29
  </tr>
@@ -8,13 +8,11 @@ const props = defineProps<{
8
8
  </script>
9
9
 
10
10
  <template>
11
- <div class="file">
12
- <table class="diff-table">
13
- <tbody>
14
- <UnifiedLine v-for="(item, index) in diffChange" :key="index" :line="item" />
15
- </tbody>
16
- </table>
17
- </div>
11
+ <table class="diff-table">
12
+ <tbody>
13
+ <UnifiedLine v-for="(item, index) in diffChange" :key="index" :line="item" />
14
+ </tbody>
15
+ </table>
18
16
  </template>
19
17
 
20
18
  <style scoped></style>