v-code-diff 1.5.0 → 1.6.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,16 +1,16 @@
1
1
  {
2
2
  "name": "v-code-diff",
3
- "version": "1.5.0",
3
+ "version": "1.6.0",
4
4
  "description": "template component for vue-demi, can dev and build",
5
- "main": "dist/index.cjs",
6
- "module": "dist/index.es.js",
7
- "types": "./types/index.d.ts",
8
5
  "exports": {
9
6
  ".": {
10
- "import": "./dist/index.es.js",
11
- "require": "./dist/index.cjs.js"
7
+ "require": "./dist/index.cjs.js",
8
+ "import": "./dist/index.es.js"
12
9
  }
13
10
  },
11
+ "main": "dist/index.cjs",
12
+ "module": "dist/index.es.js",
13
+ "types": "./types/index.d.ts",
14
14
  "files": [
15
15
  "scripts",
16
16
  "dist",
@@ -31,20 +31,12 @@
31
31
  "dev:2.7": "vue-demi-switch 2.7 vue2 && pnpm --filter vue2.7-playground dev",
32
32
  "dev:3": "vue-demi-switch 3 vue3 && pnpm --filter vue3-playground dev",
33
33
  "dev:demo": "vue-demi-switch 3 vue3 && pnpm --filter demo dev",
34
- "lint:fix": "eslint . --ext .vue,.js,.jsx,.ts,.tsx --fix --ignore-path .gitignore",
34
+ "lint": "eslint .",
35
+ "lint:fix": "eslint . --ext .vue,.js,.jsx,.ts,.tsx,json --fix --ignore-path .gitignore",
35
36
  "postinstall": "node scripts/postinstall.js",
36
37
  "prepublishOnly": "npm run build",
37
38
  "release": "bumpp --commit --no-push --tag && npm publish"
38
39
  },
39
- "author": "Shimada666<649940882@qq.com>",
40
- "license": "MIT",
41
- "bugs": {
42
- "url": "https://github.com/Shimada666/v-code-diff/issues"
43
- },
44
- "repository": {
45
- "type": "git",
46
- "url": "git+https://github.com/Shimada666/v-code-diff.git"
47
- },
48
40
  "peerDependencies": {
49
41
  "@vue/composition-api": "^1.4.9",
50
42
  "vue": "^2.6.0 || >=3.0.0"
@@ -61,18 +53,19 @@
61
53
  "vue-demi": "^0.13.11"
62
54
  },
63
55
  "devDependencies": {
64
- "@antfu/eslint-config": "^0.34.0",
56
+ "@antfu/eslint-config": "^0.39.8",
65
57
  "@types/diff": "^5.0.0",
66
58
  "@types/diff-match-patch": "^1.0.32",
67
59
  "@types/node": "^18.11.18",
68
60
  "bumpp": "^8.2.1",
69
- "eslint": "^8.31.0",
61
+ "eslint": "^8.45.0",
70
62
  "npm-run-all": "^4.1.5",
71
63
  "rimraf": "^3.0.2",
72
- "sass": "^1.57.1",
64
+ "sass": "^1.63.6",
73
65
  "typescript": "~4.7.4",
74
- "vite": "^4.0.4",
66
+ "vite": "^4.4.4",
75
67
  "vite-plugin-css-injected-by-js": "^2.4.0",
68
+ "vue": "^3.3.4",
76
69
  "vue-tsc": "^0.40.13",
77
70
  "vue2": "npm:vue@2",
78
71
  "vue3": "npm:vue@3"
@@ -1,8 +1,12 @@
1
+ const fs = require('node:fs')
1
2
  const { switchVersion, loadModule } = require('./utils')
2
3
 
3
4
  const Vue = loadModule('vue')
4
5
 
5
- if (!Vue || typeof Vue.version !== 'string')
6
+ if (fs.existsSync('.local'))
7
+ console.log('Currently, it is the local development environment, not doing anything.')
8
+
9
+ else if (!Vue || typeof Vue.version !== 'string')
6
10
  console.warn('[v-code-diff] Vue is not found. Please run "npm install vue" to install.')
7
11
 
8
12
  else if (Vue.version.startsWith('2.7.'))
@@ -14,5 +18,4 @@ else if (Vue.version.startsWith('2.'))
14
18
  else if (Vue.version.startsWith('3.'))
15
19
  switchVersion('3')
16
20
 
17
- else
18
- console.warn(`[v-code-diff] Vue version v${Vue.version} is not suppported.`)
21
+ else console.warn(`[v-code-diff] Vue version v${Vue.version} is not suppported.`)
package/scripts/utils.js CHANGED
@@ -1,5 +1,5 @@
1
- const fs = require('fs')
2
- const path = require('path')
1
+ const fs = require('node:fs')
2
+ const path = require('node:path')
3
3
 
4
4
  const dir = path.resolve(__dirname, '..', 'dist')
5
5
 
package/src/CodeDiff.vue CHANGED
@@ -20,6 +20,14 @@ interface Props {
20
20
  filename?: string
21
21
  }
22
22
 
23
+ interface DiffResult {
24
+ stat: {
25
+ isChanged: boolean
26
+ addNum: number
27
+ delNum: number
28
+ }
29
+ }
30
+
23
31
  const props = withDefaults(defineProps<Props>(), {
24
32
  language: 'plaintext',
25
33
  context: 10,
@@ -31,15 +39,23 @@ const props = withDefaults(defineProps<Props>(), {
31
39
  filename: undefined,
32
40
  })
33
41
 
42
+ const emits = defineEmits<{
43
+ (e: 'diff', diffResult: DiffResult): void
44
+ }>()
45
+
34
46
  const isUnifiedViewer = computed(() => props.outputFormat === 'line-by-line')
35
47
 
36
48
  const oldString = computed(() => {
37
- const value = props.trim ? props.oldString.trim() : props.oldString
38
- return props.noDiffLineFeed ? value.replace(/(\r\n)/g, '\n') : value
49
+ let value = props.oldString || ''
50
+ value = props.trim ? value.trim() : value
51
+ value = props.noDiffLineFeed ? value.replace(/(\r\n)/g, '\n') : value
52
+ return value
39
53
  })
40
54
  const newString = computed(() => {
41
- const value = props.trim ? props.newString.trim() : props.newString
42
- return props.noDiffLineFeed ? value.replace(/(\r\n)/g, '\n') : value
55
+ let value = props.newString || ''
56
+ value = props.trim ? value.trim() : value
57
+ value = props.noDiffLineFeed ? value.replace(/(\r\n)/g, '\n') : value
58
+ return value
43
59
  })
44
60
 
45
61
  const raw = computed(() =>
@@ -48,9 +64,18 @@ const raw = computed(() =>
48
64
  : createSplitDiff(oldString.value, newString.value, props.language, props.diffStyle, props.context),
49
65
  )
50
66
  const diffChange = ref(raw.value)
67
+ const isNotChanged = computed(() => diffChange.value.stat.additionsNum === 0 && diffChange.value.stat.deletionsNum === 0)
68
+
51
69
  watch(() => props, () => {
52
70
  diffChange.value = raw.value
53
- }, { deep: true })
71
+ emits('diff', {
72
+ stat: {
73
+ isChanged: !isNotChanged.value,
74
+ addNum: diffChange.value.stat.additionsNum,
75
+ delNum: diffChange.value.stat.deletionsNum,
76
+ },
77
+ })
78
+ }, { deep: true, immediate: true })
54
79
  </script>
55
80
 
56
81
  <template>
@@ -69,4 +94,5 @@ watch(() => props, () => {
69
94
  </div>
70
95
  </template>
71
96
 
72
- <style lang="scss"></style>
97
+ <style lang="scss">
98
+ </style>
package/src/global.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import CodeDiff from './CodeDiff.vue'
2
2
  import hljs from './highlight'
3
3
 
4
- const install = (app: any) => {
4
+ function install(app: any) {
5
5
  app.component('CodeDiff', CodeDiff)
6
6
  }
7
7
 
package/src/index.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import CodeDiff from './CodeDiff.vue'
2
2
  import hljs from './highlight'
3
3
 
4
- const install = (app: any) => {
4
+ function install(app: any) {
5
5
  app.component('CodeDiff', CodeDiff)
6
6
  }
7
7
 
@@ -2,12 +2,13 @@
2
2
  import { DiffType } from '../types'
3
3
  import type { SplitLineChange } from '../types'
4
4
 
5
- const props = defineProps<{
5
+ defineProps<{
6
6
  splitLine: SplitLineChange
7
7
  }>()
8
+
8
9
  const emit = defineEmits(['expand'])
9
10
 
10
- const getCodeMarker = (type: DiffType) => {
11
+ function getCodeMarker(type: DiffType) {
11
12
  if (type === DiffType.DELETE)
12
13
  return '-'
13
14
  if (type === DiffType.ADD)
package/src/types.ts CHANGED
@@ -1,4 +1,4 @@
1
- export const enum DiffType {
1
+ export enum DiffType {
2
2
  EQUAL = 'equal',
3
3
  DELETE = 'removed',
4
4
  ADD = 'added',
@@ -2,12 +2,12 @@
2
2
  import type { UnifiedLineChange } from '../types'
3
3
  import { DiffType } from '../types'
4
4
 
5
- const props = defineProps<{
5
+ defineProps<{
6
6
  line: UnifiedLineChange
7
7
  }>()
8
8
  const emit = defineEmits(['expand'])
9
9
 
10
- const getCodeMarker = (type: DiffType) => {
10
+ function getCodeMarker(type: DiffType) {
11
11
  if (type === DiffType.DELETE)
12
12
  return '-'
13
13
  if (type === DiffType.ADD)
package/src/utils.ts CHANGED
@@ -11,7 +11,7 @@ const MODIFIED_CLOSE_TAG = '</code-diff-modified>'
11
11
  const startEntity = MODIFIED_START_TAG.replace('<', '&lt;').replace('>', '&gt;')
12
12
  const closeEntity = MODIFIED_CLOSE_TAG.replace('<', '&lt;').replace('>', '&gt;')
13
13
 
14
- const lineType = (diff: Diff.Change): DiffType => {
14
+ function lineType(diff: Diff.Change): DiffType {
15
15
  if (diff === undefined)
16
16
  return DiffType.EQUAL
17
17
  if (diff.added)
@@ -21,7 +21,7 @@ const lineType = (diff: Diff.Change): DiffType => {
21
21
  return DiffType.EQUAL
22
22
  }
23
23
 
24
- const renderWords = (prev?: string, current?: string, diffStyle = 'word'): string => {
24
+ function renderWords(prev?: string, current?: string, diffStyle = 'word'): string {
25
25
  if (typeof prev === 'undefined')
26
26
  return current!
27
27
  if (typeof current === 'undefined')
@@ -58,7 +58,7 @@ function diffLines(prev: string, current: string) {
58
58
  })
59
59
  }
60
60
 
61
- const getHighlightCode = (language: string, code: string) => {
61
+ function getHighlightCode(language: string, code: string) {
62
62
  const hasModifiedTags = code.match(new RegExp(`(${MODIFIED_START_TAG}|${MODIFIED_CLOSE_TAG})`, 'g'))
63
63
 
64
64
  if (!hasModifiedTags)