1.3.1 • Published 1 year ago

v-code-diff-custom v1.3.1

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

v-code-diff

NPM version License: MIT Downloads

A code diff display plugin, available for Vue2 / Vue3.

Old Version:

0.x version, latest version 0.3.12 (traditional version, improved based on vue-code-diff, is no longer maintained. We will try to align the functionality of 0.x version in 1.x version and minimize migration cost as much as possible). This project references the following projects, and I would like to express my gratitude to the original authors!

Contents

Install

install v-code-diff

# npm
npm i v-code-diff

# yarn
yarn add v-code-diff

# pnpm
pnpm add v-code-diff

Vue2 developers need install composition-api

pnpm add @vue/composition-api

Getting Started

Vue3

Register globally

import {createApp} from 'vue'
import CodeDiff from 'v-code-diff'

app
  .use(CodeDiff)
  .mount('#app')

然后

<template>
  <code-diff
    :old-string="'12345'"
    :new-string="'3456'"
    output-format="side-by-side"/>
</template>

Register locally

Not recommended, but the relevant capabilities are retained to facilitate migration for 0.x users.

Vue2

Register globally

import Vue from 'vue';
import CodeDiff from 'v-code-diff'

Vue.use(CodeDiff);

Register locally

Not recommended, but the relevant capabilities are retained to facilitate migration for 0.x users.

Props

PropDescriptionTypeOptional ValuesDefault Value
languageCode language, such as typescript, defaults to plain text. View all supported languagesstring-plaintext
oldStringOld stringstring--
newStringNew stringstring--
contextThe number of lines to separate different parts so that they are not hiddennumber-10
outputFormatDisplay modestringline-by-line,side-by-sideline-by-line
diffStyleDifference style, word-level differences or letter-level differencesstringword, charword
trimRemove blank characters at the beginning and end of the stringboolean-false
noDiffLineFeedDon't diff Windows line feed (CRLF) and Linux line feed (LF)boolean-false
maxHeightMaximum height of component, for example: 300pxstring-undefined
filenameFilenamestring-undefined

Extend languages

In order to reduce the size of the packaged file, the system only supports the following commonly used languages by default.

  • plaintext
  • xml/html
  • javascript
  • json
  • yaml
  • python
  • java
  • bash
  • sql

If the language you need is not included, you can manually import the relevant language highlighting module.

pnpm add highlight.js
import CodeDiff from 'v-code-diff';
// Extend C language
import c from 'highlight.js/lib/languages/c';

CodeDiff.hljs.registerLanguage('c', c);

Migrate from 0.x version

The v-code-diff 1.x version has features such as reduced packaging size and improved performance compared to the 0.x version. And we will try to align the functions with the 0.x version as much as possible to reduce your migration cost.

Key points:

  • In the 1.x version, language recognition and highlighting will no longer be automatically performed, you need to manually specify the language type, such as language="python", if not specified, it will default to plaintext and will not be highlighted.
  • In the 1.x version, due to the fact that rendering and highlighting are performed at the same time, the component events have been removed.
  • In the 1.x version, the following component properties (Prop) have been changed:
    • highlight - removed
    • drawFileList - removed
    • fileName - rename to "filename"

Below is a detailed comparison of the two versions, you can refer to it to complete the migration.

The difference of event.

The component events are no longer provided in the 1.x version as rendering and highlighting are carried out simultaneously.

Event NameChange Status
before-renderNo longer provided
after-renderNo longer provided

The difference of prop.

PropDescriptionChange Status
highlightControl code highlightingRemoved in version 1.x
languageCode languageNone
oldStringOld stringNone
newStringNew stringNone
contextThe number of lines to separate different parts so that they are not hiddenNone
output-formatDisplay modeNone
diffStyleDifference style, word-level differences or letter-level differencesNone
drawFileListDisplay file comparison listRemoved in version 1.x
renderNothingWhenEmptyDo not render when there is no comparisonRemoved in version 1.x
fileNameFile nameTo be determined, not under development
isShowNoChangeDisplay source code when there is no comparisonRemoved as it became the default in version 1.x
trimRemove blank characters at the beginning and end of the stringNone
noDiffLineFeedDon't diff Windows line feed (CRLF) and Linux line feed (LF)None

ChangeLog

1.0.0-alpha.0

  1. Remove the diff2html dependency and draw the UI by self. By getting rid of the diff2html dependency, many styling problems have been resolved.
  2. More accurate syntax highlighting and faster highlighting speed.

0.3.12

  1. Remove prop syncScroll due to bug. Synchronized scrolling is now enabled by default

0.3.11

  1. Add prop syncScroll to control whether the horizontal scroll bar needs to be scrolled synchronously

0.3.10

  1. Fixed type error when exporting

0.3.9

  1. Make the imported highlight.js style take effect only in .d2h-wrapper div

0.3.8

  1. Style adjustment, hide css d2h-file-header, same as vue-code-diff
  2. Add prop noDiffLineFeed, do not diff windows line feed (CRLF) and linux line feed (LF)

0.3.7

  1. Fix the problem of displaying "File Without Change..." when isShowNoChange is true and the old and new codes are different, then show all the source code

0.3.6

  1. Add prop language, make highlighting more accurate

0.3.5

  1. In the side-by-side mode, support left and right synchronous scrolling

0.3.4

  1. Add Prop trim, it will remove the blank characters before and after the string

0.3.3

  1. Fixed the problem of highlight failure.

0.3.2

  1. Fixed the warning for vue2 users in console

0.3.1

  1. Fix incorrect style when comparing text

0.3.0

  1. Performance optimization, now rendering has better performance
  2. Add Prop diffStyle to control whether to display word-level differences or char-level differences

0.2.1

  1. Use the function of asynchronous rendering of the highlight code, without blocking the ui, greatly improving the page rendering speed
  2. Add hook function (before rendering, after rendering): before-render, after-render

0.1.0

  1. Add prop highlight to control whether to highlight the code.

0.0.4

  1. Fix the problem of abnormal rendering in some browsers (such as safari)

0.0.3

  1. Prop: context default value changed from 5 to 10
  2. fix possible line-height conflict(such as antd.css in antd-vue)

0.0.1

First Version.

LICENCE

MIT License

Copyright (c) 2021 Shimada666

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

1.3.1

1 year ago