Skip to content
This repository was archived by the owner on Feb 10, 2025. It is now read-only.

Commit 5362acd

Browse files
committed
Merge branch 'develop'
2 parents f438b3c + b920da0 commit 5362acd

22 files changed

+45342
-378
lines changed

.eslintrc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module.exports = {
1414
rules: {
1515
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
1616
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
17+
'no-unused-expressions': 'off',
1718
'@typescript-eslint/ban-ts-ignore': 'off'
1819
},
1920
overrides: [

README.md

Lines changed: 50 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
# vue-diff
22

3-
Vue diff viewer plugin
3+
Vue diff viewer plugin
4+
<a href="https://hoiheart.github.io/vue-diff/demo/index.html" target="_blank">demo</a>
45

5-
> ⚠️ This plugin supports only Vue3
6-
> Vue2 doesn't have a support plan yet.
6+
> ⚠️ This plugin does not support Vue2
77
88
## Table of Contents
99

10-
- [Introduction](#introduction)
11-
- [Features](#features)
12-
- [Install plugin](#install-plugin)
13-
* [Options](#options)
14-
- [Usage diff viewer](#usage-diff-viewer)
15-
* [props](#props)
16-
- [Custom theme](#custom-theme)
17-
- [Extend languages](#extend-languages)
18-
- [Large text comparison](#large-text-comparison)
10+
* [Table of Contents](#table-of-contents)
11+
* [Introduction](#introduction)
12+
* [Features](#features)
13+
* [Install plugin](#install-plugin)
14+
+ [Options](#options)
15+
* [Usage diff viewer](#usage-diff-viewer)
16+
+ [Settings with default props](#settings-with-default-props)
17+
+ [Settings with full props](#settings-with-full-props)
18+
+ [Props](#props)
19+
* [Custom theme](#custom-theme)
20+
* [Extend languages](#extend-languages)
21+
+ [Default supported languages and values](#default-supported-languages-and-values)
22+
* [Virtual scroll](#virtual-scroll)
23+
- [Object props](#object-props)
1924

2025
## Introduction
2126

@@ -30,7 +35,7 @@ Here is the <a href="https://hoiheart.github.io/vue-diff/demo/index.html" target
3035
* [x] Support split / unified mode
3136
* [x] Support multiple languages and can be extended
3237
* [X] Support two themes (dark / light) and can be customized
33-
* [ ] Virtual scroll for large text comparison
38+
* [X] Virtual scroll for large text comparison (*Performance improvements are still needed.*)
3439
* [ ] Support IE11 (IE 11 support for Vue@3 is still pending)
3540

3641
## Install plugin
@@ -63,6 +68,20 @@ app.use(VueDiff, {
6368
## Usage diff viewer
6469

6570
Insert the diff component with props.
71+
### Settings with default props
72+
```vue
73+
<template>
74+
<Diff
75+
:mode="mode"
76+
:theme="theme"
77+
:language="language"
78+
:prev="prev"
79+
:current="current"
80+
/>
81+
</template>
82+
```
83+
84+
### Settings with full props
6685

6786
```vue
6887
<template>
@@ -72,11 +91,13 @@ Insert the diff component with props.
7291
:language="language"
7392
:prev="prev"
7493
:current="current"
94+
:input-delay="0"
95+
:virtual-scroll="{ height: 500, lineMinHeight: 24, delay: 100 }"
7596
/>
7697
</template>
7798
```
7899

79-
### props
100+
### Props
80101

81102
| name | type | detault | values | description
82103
|- | - | - | - |- |
@@ -85,6 +106,8 @@ Insert the diff component with props.
85106
| language | `string` | `plaintext` | | See <a href="#extend-languages">Extend languages</a>
86107
| prev | `string` | `''` | | Prev code |
87108
| current | `string` | `''` | | Current Code |
109+
| inputDelay | `number` | `0` | | Setting up rendering debounce for changes for performance benefit (mode, prev, curr) |
110+
| virtualScroll | `boolean\|object` | `false` | | *Default value when setting true :*<br>`{ height: 500, lineMinHeight: 24, delay: 100 }`<br>See <a href="#virtual-scroll">virtual scroll</a> |
88111

89112
## Custom theme
90113

@@ -149,6 +172,17 @@ app.use(VueDiff)
149172

150173
> <a href="https://github.com/highlightjs/highlight.js/blob/master/SUPPORTED_LANGUAGES.md">Check supported languages of Highlight.js</a>
151174
152-
## Large text comparison
175+
## Virtual scroll
176+
177+
Comparing text from many lines can slow down performance.<br>
178+
With virtualScroll props, virtualScroll applies. (Self-made for this plug-in.)
179+
180+
#### Object property value
181+
182+
When using virtual scroll, the css of all code lines is changed to the absolute position, which requires detailed settings.
153183

154-
⚠️ It's still hard to compare large texts. Virtual scroll for Vue3 must be created or found.
184+
* height (`number`): Diff box height (Applies only to px values)
185+
* lineMinHeight (`number`): minimum height of line
186+
> Minimum height value of line is required for visible area calculation.<br>The default is 24, but you can set it yourself if you need to adjust it according to the page's front-size, line-height, etc.
187+
* delay (`number`): re-rendering delay when scrolling or resizing
188+
> Performance problems occur when too often a re-rendering function is invoked based on scrolling or resizing<br>This setting applies a delay using throttle.

dev/App.vue

Lines changed: 57 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<template>
22
<div class="form text-gray-100 mt-8">
3-
<label for="language" class="mr-2">Language:</label>
4-
<select v-model="language" id="language" class="bg-gray-900 w-40 py-1 px-3 mr-4 rounded border border-gray-500 text-gray-300">
5-
<option :key="val" v-for="val in languages">{{ val }}</option>
3+
<label for="language" class="mr-2">Type:</label>
4+
<select v-model="selected" id="language" class="bg-gray-900 w-40 py-1 px-3 mr-4 rounded border border-gray-500 text-gray-300">
5+
<option :key="item.title" :value="item" v-for="item in list">{{ item.title }}</option>
66
</select>
77
<label for="mode" class="mr-2">Mode:</label>
88
<select v-model="mode" id="mode" class="bg-gray-900 w-40 py-1 px-3 mr-4 rounded border border-gray-500 text-gray-300">
@@ -29,12 +29,17 @@
2929
<div class="viewer">
3030
<section class="mt-8">
3131
<h2 class="text-2xl font-bold text-gray-100 mb-4">Diff</h2>
32+
<p class="text-gray-100 mb-4">
33+
inputDelay and virtualScroll option are set for large text diff.
34+
</p>
3235
<Diff
3336
:mode="mode"
3437
:theme="theme"
35-
:language="language"
38+
:language="selected.language"
3639
:prev="prev"
3740
:current="current"
41+
:input-delay="0"
42+
:virtual-scroll="{ height: 500, lineMinHeight: 24, delay: 100 }"
3843
/>
3944
</section>
4045
</div>
@@ -49,19 +54,60 @@ export default defineComponent({
4954
setup () {
5055
const modes = ref(['split', 'unified'])
5156
const mode = ref('split')
52-
const languages = ref(['javascript', 'html', 'css', 'yaml'])
53-
const language = ref('javascript')
57+
const selected = ref<null|{}>(null)
5458
const themes = ref(['dark', 'light', 'custom'])
5559
const theme = ref('dark')
60+
const list = ref([
61+
{
62+
key: 'javascript',
63+
title: 'javascript',
64+
language: 'javascript',
65+
inputDelay: 0,
66+
virtualScroll: false
67+
},
68+
{
69+
key: 'html',
70+
title: 'html',
71+
language: 'html',
72+
inputDelay: 0,
73+
virtualScroll: false
74+
},
75+
{
76+
key: 'css',
77+
title: 'css',
78+
language: 'css',
79+
inputDelay: 0,
80+
virtualScroll: false
81+
},
82+
{
83+
key: 'yaml',
84+
title: 'yaml',
85+
language: 'yaml',
86+
inputDelay: 0,
87+
virtualScroll: false
88+
},
89+
{
90+
key: 'jquery',
91+
title: 'large text',
92+
language: 'javascript',
93+
inputDelay: 100,
94+
virtualScroll: {
95+
height: 500,
96+
lineMinHeight: 24,
97+
delay: 100
98+
}
99+
}
100+
])
56101
57102
const prev = ref('')
58103
const current = ref('')
104+
selected.value = list.value[0]
59105
60-
watch(() => language.value, () => {
106+
watch(() => selected.value, () => {
61107
// @ts-ignore
62-
prev.value = template[`${language.value}1`]
108+
prev.value = template[`${selected?.value.key}1`]
63109
// @ts-ignore
64-
current.value = template[`${language.value}2`]
110+
current.value = template[`${selected?.value.key}2`]
65111
}, {
66112
immediate: true
67113
})
@@ -76,10 +122,10 @@ export default defineComponent({
76122
return {
77123
modes,
78124
mode,
79-
languages,
80-
language,
81125
themes,
82126
theme,
127+
list,
128+
selected,
83129
prev,
84130
current
85131
}

0 commit comments

Comments
 (0)