v-code-diff 1.10.0 → 1.11.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,7 +1,7 @@
1
1
  {
2
2
  "name": "v-code-diff",
3
3
  "type": "module",
4
- "version": "1.10.0",
4
+ "version": "1.11.0",
5
5
  "description": "template component for vue-demi, can dev and build",
6
6
  "license": "MIT",
7
7
  "exports": {
@@ -53,7 +53,8 @@
53
53
  "diff": "^5.1.0",
54
54
  "diff-match-patch": "^1.0.5",
55
55
  "highlight.js": "^11.9.0",
56
- "vue-demi": "^0.14.6"
56
+ "vue-demi": "^0.14.6",
57
+ "vue-i18n": "9"
57
58
  },
58
59
  "devDependencies": {
59
60
  "@antfu/eslint-config": "^2.4.5",
package/src/CodeDiff.vue CHANGED
@@ -12,6 +12,7 @@ interface Props {
12
12
  language?: string
13
13
  context?: number
14
14
  diffStyle?: 'word' | 'char'
15
+ forceInlineComparison?: boolean
15
16
  outputFormat?: 'line-by-line' | 'side-by-side'
16
17
  trim?: boolean
17
18
  noDiffLineFeed?: boolean
@@ -29,6 +30,7 @@ const props = withDefaults(defineProps<Props>(), {
29
30
  language: 'plaintext',
30
31
  context: 10,
31
32
  diffStyle: 'word',
33
+ forceInlineComparison: false,
32
34
  outputFormat: 'line-by-line',
33
35
  trim: false,
34
36
  noDiffLineFeed: false,
@@ -70,8 +72,8 @@ const newString = computed(() => {
70
72
 
71
73
  const raw = computed(() =>
72
74
  isUnifiedViewer.value
73
- ? createUnifiedDiff(oldString.value, newString.value, props.language, props.diffStyle, props.context, props.ignoreMatchingLines)
74
- : createSplitDiff(oldString.value, newString.value, props.language, props.diffStyle, props.context, props.ignoreMatchingLines),
75
+ ? createUnifiedDiff(oldString.value, newString.value, props.language, props.diffStyle, props.forceInlineComparison, props.context, props.ignoreMatchingLines)
76
+ : createSplitDiff(oldString.value, newString.value, props.language, props.diffStyle, props.forceInlineComparison, props.context, props.ignoreMatchingLines),
75
77
  )
76
78
  const diffChange = ref(raw.value)
77
79
  const isNotChanged = computed(() => diffChange.value.stat.additionsNum === 0 && diffChange.value.stat.deletionsNum === 0)
package/src/utils.ts CHANGED
@@ -170,6 +170,7 @@ export function createSplitDiff(
170
170
  newString: string,
171
171
  language = 'plaintext',
172
172
  diffStyle = 'word',
173
+ forceInlineComparison = false,
173
174
  context = 10,
174
175
  ignoreMatchingLines?: string,
175
176
  ): SplitViewerChange {
@@ -270,9 +271,9 @@ export function createSplitDiff(
270
271
  addNum++
271
272
 
272
273
  const [curLine, nextLine] = [curLines[j], nextLines[j]]
273
-
274
- const leftLine = curLines.length === nextLines.length ? renderWords(nextLine, curLine, diffStyle) : curLine
275
- const rightLine = curLines.length === nextLines.length ? renderWords(curLine, nextLine, diffStyle) : nextLine
274
+ const shouldRenderWords = forceInlineComparison || curLines.length === nextLines.length
275
+ const leftLine = shouldRenderWords ? renderWords(nextLine, curLine, diffStyle) : curLine
276
+ const rightLine = shouldRenderWords ? renderWords(curLine, nextLine, diffStyle) : nextLine
276
277
 
277
278
  // 忽略匹配的行等价于相等
278
279
  const leftDiffType = ignoreRegex?.test(curLine) ? DiffType.EQUAL : DiffType.DELETE
@@ -361,6 +362,7 @@ export function createUnifiedDiff(
361
362
  newString: string,
362
363
  language = 'plaintext',
363
364
  diffStyle = 'word',
365
+ forceInlineComparison = false,
364
366
  context = 10,
365
367
  ignoreMatchingLines?: string,
366
368
  ): UnifiedViewerChange {
@@ -430,7 +432,7 @@ export function createUnifiedDiff(
430
432
  // 处理当前 diff 为删除的情况
431
433
  if (curType === DiffType.DELETE) {
432
434
  // 下一处差异为新增,且删除与新增行数相同时,对每行依次 diff
433
- if (nextType === DiffType.ADD && curLines.length === nextLines.length) {
435
+ if (nextType === DiffType.ADD && (curLines.length === nextLines.length || forceInlineComparison)) {
434
436
  for (let j = 0; j < curLines.length; j++) {
435
437
  const curLine = curLines[j]
436
438
  const nextLine = nextLines[j]