v-code-diff 1.13.2 → 1.14.1
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/README.md +51 -55
- package/dist/v2/index.cjs +28 -19
- package/dist/v2/index.es.js +1609 -1506
- package/dist/v2/index.umd.js +28 -19
- package/dist/v2.7/index.cjs +28 -19
- package/dist/v2.7/index.es.js +1434 -1377
- package/dist/v2.7/index.umd.js +28 -19
- package/dist/v3/index.cjs +28 -19
- package/dist/v3/index.es.js +1634 -1555
- package/dist/v3/index.umd.js +28 -19
- package/package.json +7 -2
- package/src/CodeDiff.vue +4 -4
- package/src/split/SplitViewer.vue +34 -2
- package/src/style.scss +18 -0
- package/src/types.ts +2 -0
- package/src/unified/UnifiedViewer.vue +34 -2
- package/src/utils.ts +153 -55
- package/types/index.d.ts +60 -12
package/README.md
CHANGED
|
@@ -4,18 +4,19 @@
|
|
|
4
4
|
[](https://opensource.org/licenses/MIT)
|
|
5
5
|
[](https://www.npmjs.com/package/v-code-diff)
|
|
6
6
|
|
|
7
|
-
> A code diff
|
|
7
|
+
> A code diff viewer for Vue 2.6, Vue 2.7, and Vue 3.
|
|
8
8
|
|
|
9
9
|
<p align='center'>
|
|
10
10
|
<b>English</b> | <a href="https://github.com/Shimada666/v-code-diff/blob/main/README-zh.md">简体中文</a>
|
|
11
11
|
</p>
|
|
12
12
|
|
|
13
|
-
Old
|
|
13
|
+
Old version:
|
|
14
14
|
|
|
15
|
-
0.x
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
The 0.x line ended at 0.3.12 and is no longer maintained. It was based on
|
|
16
|
+
[vue-code-diff](https://github.com/ddchef/vue-code-diff). Version 1.x aims to preserve its core behavior while keeping
|
|
17
|
+
migration straightforward.
|
|
18
|
+
|
|
19
|
+
This project draws inspiration from the following projects. Thanks to their original authors:
|
|
19
20
|
|
|
20
21
|
- [vue-diff](https://github.com/hoiheart/vue-diff)
|
|
21
22
|
- [vue-code-diff](https://github.com/ddchef/vue-code-diff)
|
|
@@ -34,7 +35,7 @@ This project references the following projects, and I would like to express my g
|
|
|
34
35
|
|
|
35
36
|
## Install
|
|
36
37
|
|
|
37
|
-
|
|
38
|
+
Install `v-code-diff`:
|
|
38
39
|
|
|
39
40
|
```bash
|
|
40
41
|
# npm
|
|
@@ -47,25 +48,26 @@ yarn add v-code-diff
|
|
|
47
48
|
pnpm add v-code-diff
|
|
48
49
|
```
|
|
49
50
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
scripts:
|
|
53
|
-
|
|
54
|
-
| Vue version | Import path |
|
|
55
|
-
| --- | --- |
|
|
56
|
-
| Vue 2.6 | `v-code-diff/vue2` |
|
|
57
|
-
| Vue 2.7 | `v-code-diff/vue2.7` |
|
|
58
|
-
| Vue 3 | `v-code-diff/vue3` |
|
|
51
|
+
`v-code-diff` uses `postinstall` to select the build for your Vue version. Do not install it with `--ignore-scripts`.
|
|
52
|
+
If pnpm reports that the build script was blocked, approve it and let pnpm run the script:
|
|
59
53
|
|
|
60
|
-
|
|
61
|
-
|
|
54
|
+
```shell
|
|
55
|
+
pnpm approve-builds v-code-diff
|
|
56
|
+
```
|
|
62
57
|
|
|
63
|
-
|
|
58
|
+
Vue 2.6 users must also install and register `@vue/composition-api`:
|
|
64
59
|
|
|
65
60
|
```shell
|
|
66
61
|
pnpm add @vue/composition-api
|
|
67
62
|
```
|
|
68
63
|
|
|
64
|
+
```ts
|
|
65
|
+
import Vue from 'vue'
|
|
66
|
+
import VueCompositionAPI from '@vue/composition-api'
|
|
67
|
+
|
|
68
|
+
Vue.use(VueCompositionAPI)
|
|
69
|
+
```
|
|
70
|
+
|
|
69
71
|
## Getting Started
|
|
70
72
|
|
|
71
73
|
### Vue3
|
|
@@ -74,7 +76,7 @@ pnpm add @vue/composition-api
|
|
|
74
76
|
> Recommend using local registration for better tree-shaking support.
|
|
75
77
|
```vue
|
|
76
78
|
<script setup>
|
|
77
|
-
import { CodeDiff } from 'v-code-diff
|
|
79
|
+
import { CodeDiff } from 'v-code-diff'
|
|
78
80
|
</script>
|
|
79
81
|
|
|
80
82
|
<template>
|
|
@@ -92,14 +94,13 @@ import { CodeDiff } from 'v-code-diff/vue3'
|
|
|
92
94
|
|
|
93
95
|
```ts
|
|
94
96
|
import { createApp } from 'vue'
|
|
95
|
-
import CodeDiff from 'v-code-diff
|
|
97
|
+
import CodeDiff from 'v-code-diff'
|
|
98
|
+
import App from './App.vue'
|
|
96
99
|
|
|
97
|
-
app
|
|
98
|
-
.use(CodeDiff)
|
|
99
|
-
.mount('#app')
|
|
100
|
+
createApp(App).use(CodeDiff).mount('#app')
|
|
100
101
|
```
|
|
101
102
|
|
|
102
|
-
|
|
103
|
+
Then use the component in any template:
|
|
103
104
|
|
|
104
105
|
```vue
|
|
105
106
|
<template>
|
|
@@ -117,8 +118,7 @@ then
|
|
|
117
118
|
> Recommend using local registration for better tree-shaking support.
|
|
118
119
|
```vue
|
|
119
120
|
<script>
|
|
120
|
-
|
|
121
|
-
import { CodeDiff } from 'v-code-diff/vue2'
|
|
121
|
+
import { CodeDiff } from 'v-code-diff'
|
|
122
122
|
export default {
|
|
123
123
|
components: {
|
|
124
124
|
CodeDiff
|
|
@@ -139,8 +139,7 @@ export default {
|
|
|
139
139
|
#### Register globally
|
|
140
140
|
```ts
|
|
141
141
|
import Vue from 'vue'
|
|
142
|
-
|
|
143
|
-
import CodeDiff from 'v-code-diff/vue2'
|
|
142
|
+
import CodeDiff from 'v-code-diff'
|
|
144
143
|
|
|
145
144
|
Vue.use(CodeDiff)
|
|
146
145
|
```
|
|
@@ -157,15 +156,15 @@ Vue.use(CodeDiff)
|
|
|
157
156
|
|
|
158
157
|
| Prop | Description | Type | Optional Values | Default Value |
|
|
159
158
|
|---------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------|---------------------------|---------------|
|
|
160
|
-
| language |
|
|
159
|
+
| language | Syntax-highlighting language, such as javascript. Defaults to plain text. | string | - | plaintext |
|
|
161
160
|
| oldString | Old string | string | - | - |
|
|
162
161
|
| newString | New string | string | - | - |
|
|
163
|
-
| context |
|
|
164
|
-
| outputFormat | Display mode | string | line-by-line
|
|
165
|
-
| diffStyle |
|
|
166
|
-
|forceInlineComparison| Force inline comparison (word or char level)
|
|
162
|
+
| context | Number of unchanged lines shown around each change | number | - | 10 |
|
|
163
|
+
| outputFormat | Display mode | string | line-by-line, side-by-side | line-by-line |
|
|
164
|
+
| diffStyle | Inline difference granularity: words or characters | string | word, char | word |
|
|
165
|
+
| forceInlineComparison | Force inline comparison (word or char level) | boolean | - | false |
|
|
167
166
|
| trim | Remove blank characters at the beginning and end of the string | boolean | - | false |
|
|
168
|
-
| noDiffLineFeed |
|
|
167
|
+
| noDiffLineFeed | Normalize Windows (CRLF) and Unix (LF) line endings before comparison | boolean | - | false |
|
|
169
168
|
| maxHeight | Maximum height of component, for example: 300px | string | - | undefined |
|
|
170
169
|
| filename | Filename | string | - | undefined |
|
|
171
170
|
| newFilename | New filename | string | - | undefined |
|
|
@@ -178,18 +177,17 @@ Vue.use(CodeDiff)
|
|
|
178
177
|
|
|
179
178
|
| Name | Description | Type |
|
|
180
179
|
| ---- | --------------------------- | ------------------------------------------------------------------------------- |
|
|
181
|
-
| diff |
|
|
180
|
+
| diff | Emitted after the diff is calculated | (result: {stat: { isChanged: boolean, addNum: number, delNum: number}}) => void |
|
|
182
181
|
|
|
183
182
|
## Slot
|
|
184
183
|
|
|
185
184
|
| Name | Description |
|
|
186
185
|
| ---- | ----------------------------------------------------------- |
|
|
187
|
-
| stat | Custom
|
|
186
|
+
| stat | Custom statistics content. The slot prop is `{ stat }`. |
|
|
188
187
|
|
|
189
188
|
## Extend languages
|
|
190
189
|
|
|
191
|
-
|
|
192
|
-
default.
|
|
190
|
+
To keep the bundle small, the following languages are registered by default:
|
|
193
191
|
|
|
194
192
|
- plaintext
|
|
195
193
|
- xml/html
|
|
@@ -201,7 +199,7 @@ default.
|
|
|
201
199
|
- bash
|
|
202
200
|
- sql
|
|
203
201
|
|
|
204
|
-
|
|
202
|
+
To use another language, import and register its highlighting module manually.
|
|
205
203
|
|
|
206
204
|
```shell
|
|
207
205
|
pnpm add highlight.js
|
|
@@ -244,17 +242,16 @@ CodeDiff.hljs.registerLanguage('c', c)
|
|
|
244
242
|
|
|
245
243
|
## Migrate from 0.x version
|
|
246
244
|
|
|
247
|
-
|
|
248
|
-
version. And we will try to align the functions with the 0.x version as much as possible to reduce your migration cost.
|
|
245
|
+
Version 1.x has a smaller bundle and better performance than 0.x while preserving its core behavior.
|
|
249
246
|
|
|
250
247
|
Key points:
|
|
251
248
|
|
|
252
|
-
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
-
|
|
256
|
-
|
|
257
|
-
|
|
249
|
+
- Version 1.x no longer detects or highlights languages automatically. Set the language explicitly, such as
|
|
250
|
+
`language="python"`; if omitted, it defaults to `plaintext` without syntax highlighting.
|
|
251
|
+
- The legacy `before-render` and `after-render` events were removed. The `diff` event remains available.
|
|
252
|
+
- Large results render 1,000 lines at a time. Use the load-more control to reveal the next batch.
|
|
253
|
+
- Inline word/character markers are skipped when a changed line pair exceeds 10,000 characters. Set
|
|
254
|
+
`force-inline-comparison` to keep detailed markers when the extra processing time is acceptable.
|
|
258
255
|
- In the 1.x version, the following component properties (Prop) have been changed:
|
|
259
256
|
- highlight - removed
|
|
260
257
|
- drawFileList - removed
|
|
@@ -262,19 +259,18 @@ Key points:
|
|
|
262
259
|
- newFilename - new
|
|
263
260
|
- theme - new
|
|
264
261
|
|
|
265
|
-
|
|
262
|
+
The tables below summarize the migration details.
|
|
266
263
|
|
|
267
|
-
###
|
|
264
|
+
### Event changes
|
|
268
265
|
|
|
269
|
-
The
|
|
270
|
-
simultaneously.
|
|
266
|
+
The legacy `before-render` and `after-render` events are no longer provided in 1.x.
|
|
271
267
|
|
|
272
268
|
| Event Name | Change Status |
|
|
273
269
|
| ------------- | ------------------ |
|
|
274
270
|
| before-render | No longer provided |
|
|
275
271
|
| after-render | No longer provided |
|
|
276
272
|
|
|
277
|
-
###
|
|
273
|
+
### Prop changes
|
|
278
274
|
|
|
279
275
|
| Prop | Description | Change Status |
|
|
280
276
|
| ---------------------- | --------------------------------------------------------------------------- | ----------------------------------------------- |
|
|
@@ -287,8 +283,8 @@ simultaneously.
|
|
|
287
283
|
| diffStyle | Difference style, word-level differences or letter-level differences | None |
|
|
288
284
|
| drawFileList | Display file comparison list | Removed in version 1.x |
|
|
289
285
|
| renderNothingWhenEmpty | Do not render when there is no comparison | Removed in version 1.x |
|
|
290
|
-
| fileName | File name |
|
|
291
|
-
| newFilename |
|
|
286
|
+
| fileName | File name | Renamed to `filename` in 1.x |
|
|
287
|
+
| newFilename | New file name | Added in 1.x |
|
|
292
288
|
| isShowNoChange | Display source code when there is no comparison | Removed as it became the default in version 1.x |
|
|
293
289
|
| trim | Remove blank characters at the beginning and end of the string | None |
|
|
294
290
|
| noDiffLineFeed | Don't diff Windows line feed (CRLF) and Linux line feed (LF) | None |
|