-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extract difference viewer to a component
+ add synchronized scrolling - Ticket: SUITEDEV-26331
- Loading branch information
Showing
4 changed files
with
64 additions
and
33 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
src/renderer/components/save-confirmation-dialog/difference/difference.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<div v-html="content"></div> |
55 changes: 55 additions & 0 deletions
55
src/renderer/components/save-confirmation-dialog/difference/difference.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { isNil } from 'lodash'; | ||
import { createPatch } from 'diff'; | ||
import * as Diff2Html from 'diff2html'; | ||
|
||
export default { | ||
name: 'difference', | ||
template: require('./difference.html'), | ||
props: { | ||
label: String, | ||
originalValue: String, | ||
currentValue: String | ||
}, | ||
computed: { | ||
content() { | ||
const changeType = !isNil(this.originalValue) && !isNil(this.currentValue) | ||
? 'CHANGED' | ||
: isNil(this.originalValue) | ||
? 'ADDED' | ||
: 'REMOVED'; | ||
|
||
const patch = createPatch(this.label, this.originalValue || '', this.currentValue || ''); | ||
const diffJson = Diff2Html.parse(patch); | ||
return Diff2Html.html(diffJson, { | ||
drawFileList: false, | ||
matching: 'lines', | ||
outputFormat: 'side-by-side', | ||
rawTemplates: { | ||
'generic-file-path': | ||
`<span>${this.label}</span><span class="e-padding-left-l text-color-gray-400">${changeType}</span>`, | ||
'generic-empty-diff': | ||
`<tr> | ||
<td class="{{CSSLineClass.INFO}}"> | ||
<div class="{{contentClass}} {{CSSLineClass.INFO}}"> | ||
Value is empty | ||
</div> | ||
</td> | ||
</tr>` | ||
} | ||
}); | ||
} | ||
}, | ||
methods: { | ||
enableSynchronizedScrolling() { | ||
const [originalSide, currentSide] = this.$el.querySelectorAll('.d2h-file-side-diff'); | ||
originalSide.addEventListener('scroll', () => currentSide.scrollLeft = originalSide.scrollLeft); | ||
currentSide.addEventListener('scroll', () => originalSide.scrollLeft = currentSide.scrollLeft); | ||
} | ||
}, | ||
mounted() { | ||
this.enableSynchronizedScrolling(); | ||
}, | ||
updated() { | ||
this.enableSynchronizedScrolling(); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters