|
1 | 1 | # vue-diff |
2 | 2 |
|
3 | | -## Project setup |
4 | | -``` |
5 | | -npm install |
6 | | -``` |
| 3 | +Vue diff viewer plugin |
7 | 4 |
|
8 | | -### Compiles and hot-reloads for development |
9 | | -``` |
10 | | -npm run serve |
11 | | -``` |
| 5 | +> ⚠️ This plugin supports only Vue3 |
12 | 6 |
|
13 | | -### Compiles and minifies for production |
14 | | -``` |
15 | | -npm run build |
16 | | -``` |
| 7 | +## Table of Contents |
| 8 | + |
| 9 | +- [Introduction](#introduction) |
| 10 | +- [Features](#features) |
| 11 | +- [Install plugin](#install-plugin) |
| 12 | + * [Options](#options) |
| 13 | +- [Usage modal](#usage-modal) |
| 14 | + * [props](#props) |
| 15 | + + [props.options](#propsoptions) |
| 16 | + * [slot arguments](#slot-arguments) |
| 17 | +- [Handle global CSS](#handle-global-css) |
| 18 | +- [Example](#example) |
| 19 | + |
| 20 | +## Introduction |
| 21 | + |
| 22 | +<img src="https://user-images.githubusercontent.com/25652218/104695609-60533c80-5750-11eb-85dd-0e7d0d79d5ac.png" alt="screenshot" style="max-width:100%;"> |
17 | 23 |
|
18 | | -### Run your unit tests |
| 24 | +You can see the difference between the two codes with the `vue-diff` plugin. |
| 25 | +This plugin dependent on <a href="https://github.com/kpdecker/jsdiff">diff</a> and <a href="https://github.com/highlightjs/highlight.js/">highlight.js</a>, shows similar results to other diff viewers (e.g., Github Desktop). |
| 26 | +Please see the <a href="https://hoiheart.github.io/vue-diff/demo/index.html" target="_blank" style="font-size: 1.2em; text-decoration: underline;">demo</a> |
| 27 | + |
| 28 | +## Features |
| 29 | + |
| 30 | +* [x] Support split / unified mode |
| 31 | +* [x] Support some languages and can be extended |
| 32 | +* [X] Support two themes (dark / light) and can be customized |
| 33 | +* [ ] Support IE11 (IE 11 support for Vue@3 is still pending) |
| 34 | + |
| 35 | +## Install plugin |
| 36 | + |
| 37 | +```bash |
| 38 | +npm install vue-diff |
19 | 39 | ``` |
20 | | -npm run test:unit |
| 40 | + |
| 41 | +install plugin in vue application |
| 42 | + |
| 43 | +```ts |
| 44 | +import VueDiff from 'vue-diff' |
| 45 | +// import VueDiff from 'vue-diff/dist/index.es5' // If need to use es5 build |
| 46 | +import 'vue-diff/dist/index.css' |
| 47 | + |
| 48 | +app.use(VueDiff) |
21 | 49 | ``` |
| 50 | +### Options |
22 | 51 |
|
23 | | -### Run your end-to-end tests |
| 52 | +```ts |
| 53 | +app.use(VueDiff, { |
| 54 | + componentName: 'VueDiff' |
| 55 | +}) |
24 | 56 | ``` |
25 | | -npm run test:e2e |
| 57 | + |
| 58 | +| name | type | detault | description | |
| 59 | +|- | - | - | - | |
| 60 | +| componentName | `string` | `'Diff'` | Global diff component name | |
| 61 | + |
| 62 | +## Usage diff viewer |
| 63 | + |
| 64 | +Insert the diff component with props. |
| 65 | + |
| 66 | +```vue |
| 67 | +<template> |
| 68 | + <Diff |
| 69 | + :mode="mode" |
| 70 | + :theme="theme" |
| 71 | + :language="language" |
| 72 | + :prev="prev" |
| 73 | + :current="current" |
| 74 | + /> |
| 75 | +</template> |
26 | 76 | ``` |
27 | 77 |
|
28 | | -### Lints and fixes files |
| 78 | +### props |
| 79 | + |
| 80 | +| name | type | detault | values | description |
| 81 | +|- | - | - | - |- | |
| 82 | +| mode | `string` | `split` | `split`, `unified` | |
| 83 | +| theme | `string` | `dark` | `dark`, `light` | See <a href="#custom-theme">Custom theme</a> |
| 84 | +| language | `string` | `plaintext` | | See <a href="#extend-languages">Extend languages</a> |
| 85 | +| prev | `string` | `''` | | Prev code | |
| 86 | +| current | `string` | `''` | | Current Code | |
| 87 | + |
| 88 | +### Custom theme |
| 89 | + |
| 90 | +`vue-diff` uses the following <a href="https://github.com/highlightjs/highlight.js/tree/master/src/styles">highlight.js themes</a> and can be customized. |
| 91 | + |
| 92 | +* dark: `highlight.js/scss/monokai.scss` |
| 93 | +* light: `highlight.js/scss/vs.scss` |
| 94 | + |
| 95 | +```bash |
| 96 | +npm install highlight.js |
29 | 97 | ``` |
30 | | -npm run lint |
| 98 | + |
| 99 | +```vue |
| 100 | +<template> |
| 101 | + <Diff |
| 102 | + :mode="mode" |
| 103 | + theme="custom" |
| 104 | + :language="language" |
| 105 | + :prev="prev" |
| 106 | + :current="current" |
| 107 | + /> |
| 108 | +</template> |
| 109 | +
|
| 110 | +<style lang="scss"> |
| 111 | +.vue-diff-theme-custom { |
| 112 | + @import 'highlight.js/scss/vs2015.scss'; // import theme |
| 113 | +
|
| 114 | + background-color: #000; // Set background color |
| 115 | +} |
| 116 | +</style> |
31 | 117 | ``` |
32 | 118 |
|
33 | | -### Customize configuration |
34 | | -See [Configuration Reference](https://cli.vuejs.org/config/). |
| 119 | +## Extend languages |
| 120 | + |
| 121 | +`vue-diff` supports the following languages and can be extended through <a href="https://github.com/highlightjs/highlight.js/#es6-modules">highlight.js language registration.</a> |
| 122 | + |
| 123 | +* `css` |
| 124 | +* `xml` |
| 125 | +* `markdown` |
| 126 | +* `javascript` |
| 127 | +* `json` |
| 128 | +* `plaintext` |
| 129 | +* `typescript` |
| 130 | + |
| 131 | +```ts |
| 132 | +import VueDiff from 'vue-diff' |
| 133 | +import 'vue-diff/dist/index.css' |
| 134 | + |
| 135 | +// extend yaml language |
| 136 | +import yaml from 'highlight.js/lib/languages/yaml' |
| 137 | + |
| 138 | +VueDiff.hljs.registerLanguage('yaml', yaml) |
| 139 | + |
| 140 | +app.use(VueDiff) |
| 141 | +``` |
0 commit comments