ng-diff-match-patch
Advanced tools
Comparing version 1.0.3 to 1.1.0
{ | ||
"name": "ng-diff-match-patch", | ||
"version": "1.0.3", | ||
"version": "1.1.0", | ||
"description": "A Diff-Match-Patch component for your Angular 2 + applications", | ||
"main": "diffMatchPatch.bundle.js", | ||
"module": "diffMatchPatch.module.js", | ||
"jsnext:main": "diffMatchPatch.module.js", | ||
"types": "diffMatchPatch.module.d.ts", | ||
"scripts": { | ||
"build": "rm -rf dist && ngc && mv src/*.ngfactory.ts dist/", | ||
"build": "rm -rf dist && tsc -p tsconfig-esm.json && rollup -c rollup.config.js dist/diffMatchPatch.module.js > dist/diffMatchPatch.bundle.js && cp package.json dist && ngc && cp README.md dist", | ||
"test": "karma start karma.conf.js" | ||
@@ -24,2 +28,5 @@ }, | ||
"homepage": "https://github.com/elliotforbes/ng-diff-match-patch#readme", | ||
"peerDependencies": { | ||
"@angular/core": ">=2.0.0" | ||
}, | ||
"devDependencies": { | ||
@@ -34,2 +41,3 @@ "@angular/common": "^2.1.1", | ||
"@angular/platform-server": "^2.1.1", | ||
"@types/jasmine": "^2.2.34", | ||
"core-js": "^2.4.1", | ||
@@ -42,9 +50,8 @@ "http-server": "^0.9.0", | ||
"reflect-metadata": "^0.1.8", | ||
"rxjs": "5.0.0-beta.12", | ||
"rollup": "^0.42.0", | ||
"rxjs": "^5.0.1", | ||
"systemjs": "0.19.39", | ||
"typescript": "^2.0.3", | ||
"zone.js": "^0.6.25", | ||
"@types/es6-shim": "^0.31.32", | ||
"@types/jasmine": "^2.2.34" | ||
"zone.js": "^0.7.2" | ||
} | ||
} |
@@ -23,3 +23,3 @@ Ng-Diff-Match-Patch | ||
// import our necessary module and components here | ||
import { DiffMatchPatchModule, DiffDirective } from 'ng-diff-match-patch'; | ||
import { DiffMatchPatchModule } from 'ng-diff-match-patch'; | ||
@@ -26,0 +26,0 @@ @NgModule({ |
import { Directive, ElementRef, Input } from '@angular/core'; | ||
import { DiffMatchPatchService } from './diffMatchPatch.service'; | ||
import { Diff, DiffOp } from './diffMatchPatch'; | ||
@@ -15,27 +16,24 @@ @Directive({ | ||
ngOnInit () { | ||
var diffs = this.dmp.getDiff(this.left, this.right); | ||
this.el.nativeElement.innerHTML = this.createHtml(this.dmp.getDiff(this.left, this.right)); | ||
} | ||
createHtml (diffs) { | ||
var html: string; | ||
html = "<div>" | ||
createHtml (diffs: Array<Diff>) { | ||
let html: string; | ||
html = '<div>'; | ||
for(let diff of diffs) { | ||
diff[1] = diff[1].replace(/\n/g, '<br/>'); | ||
if(diff[0] == 0) { | ||
if(diff[0] === DiffOp.Equal) { | ||
html += diff[1]; | ||
} | ||
if(diff[0] == -1) { | ||
html += "<del>" + diff[1] + "</del>"; | ||
if(diff[0] === DiffOp.Delete) { | ||
html += '<del>' + diff[1] + '</del>'; | ||
} | ||
if(diff[0] == 1) { | ||
html += "<ins>" + diff[1] + "</ins>"; | ||
if(diff[0] === DiffOp.Insert) { | ||
html += '<ins>' + diff[1] + '</ins>'; | ||
} | ||
} | ||
html += "</div>" | ||
html += '</div>'; | ||
return html; | ||
} | ||
} | ||
} |
import { Injectable } from '@angular/core'; | ||
import { DiffMatchPatch } from './diffMatchPatch'; | ||
import { DiffMatchPatch, DiffOp } from './diffMatchPatch'; | ||
@@ -18,3 +18,3 @@ @Injectable() | ||
getSemanticDiff(left: string, right: string) { | ||
var diffs = this.dmp.diff_main(left, right); | ||
const diffs = this.dmp.diff_main(left, right); | ||
this.dmp.diff_cleanupSemantic(diffs); | ||
@@ -25,3 +25,3 @@ return diffs; | ||
getProcessingDiff(left: string, right: string) { | ||
var diffs = this.dmp.diff_main(left, right); | ||
const diffs = this.dmp.diff_main(left, right); | ||
this.dmp.diff_cleanupEfficiency(diffs); | ||
@@ -32,4 +32,4 @@ return diffs; | ||
getLineDiff(left: string, right: string) { | ||
var chars = this.dmp.diff_linesToChars_(left, right); | ||
var diffs = this.dmp.diff_main(chars.chars1, chars.chars2, false); | ||
const chars = this.dmp.diff_linesToChars_(left, right); | ||
const diffs = this.dmp.diff_main(chars.chars1, chars.chars2, false); | ||
this.dmp.diff_charsToLines_(diffs, chars.lineArray); | ||
@@ -36,0 +36,0 @@ return diffs; |
import { Directive, ElementRef, Input } from '@angular/core'; | ||
import { DiffMatchPatchService } from './diffMatchPatch.service'; | ||
import { Diff, DiffOp } from './diffMatchPatch'; | ||
@Directive({ | ||
selector: '[lineDiff]', | ||
}) | ||
export class LineDiffDirective { | ||
@Input() left: string; | ||
@Input() right: string; | ||
@Input() left: string | number | boolean; | ||
@Input() right: string | number | boolean; | ||
@@ -15,2 +15,4 @@ constructor(private el: ElementRef, private dmp: DiffMatchPatchService) { } | ||
ngOnInit () { | ||
if(typeof this.left === 'number' || typeof this.left === 'boolean') this.left = this.left.toString(); | ||
if(typeof this.right === 'number' || typeof this.right === 'boolean') this.right = this.right.toString(); | ||
this.el.nativeElement.innerHTML = this.createHtml(this.dmp.getLineDiff(this.left, this.right)); | ||
@@ -20,19 +22,19 @@ } | ||
// TODO: Need to fix this for line diffs | ||
createHtml (diffs) { | ||
var html: string; | ||
html = "<div>" | ||
createHtml (diffs: Array<Diff>) { | ||
let html: string; | ||
html = '<div>'; | ||
for(let diff of diffs) { | ||
if(diff[0] == 0) { | ||
if(diff[0] === DiffOp.Equal) { | ||
html += diff[1]; | ||
} | ||
if(diff[0] == -1) { | ||
html += "<del> - " + diff[1] + "</del>\n"; | ||
if(diff[0] === DiffOp.Delete) { | ||
html += '<div class=\"del\"> - <del>' + diff[1] + '</del></div>\n'; | ||
} | ||
if(diff[0] == 1) { | ||
html += "<ins> + " + diff[1] + "</ins>\n"; | ||
if(diff[0] === DiffOp.Insert) { | ||
html += '<div class=\"ins\"> + <ins>' + diff[1] + '</ins></div>\n'; | ||
} | ||
} | ||
html += "</div>" | ||
html += '</div>'; | ||
return html; | ||
} | ||
} | ||
} |
import { Directive, ElementRef, Input } from '@angular/core'; | ||
import { DiffMatchPatchService } from './diffMatchPatch.service'; | ||
import { Diff, DiffOp } from './diffMatchPatch'; | ||
@@ -18,22 +19,21 @@ @Directive({ | ||
// TODO: Need to fix this for line diffs | ||
createHtml (diffs) { | ||
var html: string; | ||
html = "<div>" | ||
createHtml (diffs: Array<Diff>) { | ||
let html: string; | ||
html = '<div>'; | ||
for(let diff of diffs) { | ||
diff[1] = diff[1].replace(/\n/g, '<br/>'); | ||
if(diff[0] == 0) { | ||
if(diff[0] === DiffOp.Equal) { | ||
html += diff[1]; | ||
} | ||
if(diff[0] == -1) { | ||
html += "<del>" + diff[1] + "</del>"; | ||
if(diff[0] === DiffOp.Delete) { | ||
html += '<del>' + diff[1] + '</del>'; | ||
} | ||
if(diff[0] == 1) { | ||
html += "<ins>" + diff[1] + "</ins>"; | ||
if(diff[0] === DiffOp.Insert) { | ||
html += '<ins>' + diff[1] + '</ins>'; | ||
} | ||
} | ||
html += "</div>" | ||
html += '</div>'; | ||
return html; | ||
} | ||
} | ||
} |
import { Directive, ElementRef, Input } from '@angular/core'; | ||
import { DiffMatchPatchService } from './diffMatchPatch.service'; | ||
import { Diff, DiffOp } from './diffMatchPatch'; | ||
@@ -8,4 +9,4 @@ @Directive({ | ||
export class SemanticDiffDirective { | ||
@Input() left: string; | ||
@Input() right: string; | ||
@Input() left: string | number | boolean; | ||
@Input() right: string | number | boolean; | ||
@@ -15,2 +16,6 @@ constructor(private el: ElementRef, private dmp: DiffMatchPatchService) { } | ||
ngOnInit () { | ||
if(!this.left) this.left = ""; | ||
if(!this.right) this.right = ""; | ||
if(typeof this.left === 'number' || typeof this.left === 'boolean') this.left = this.left.toString(); | ||
if(typeof this.right === 'number' || typeof this.right === 'boolean') this.right = this.right.toString(); | ||
this.el.nativeElement.innerHTML = this.createHtml(this.dmp.getSemanticDiff(this.left, this.right)); | ||
@@ -20,22 +25,21 @@ } | ||
// TODO: Need to fix this for line diffs | ||
createHtml (diffs) { | ||
var html: string; | ||
html = "<div>" | ||
createHtml (diffs: Array<Diff>) { | ||
let html: string; | ||
html = '<div>'; | ||
for(let diff of diffs) { | ||
diff[1] = diff[1].replace(/\n/g, '<br/>'); | ||
if(diff[0] == 0) { | ||
if(diff[0] === DiffOp.Equal) { | ||
html += diff[1]; | ||
} | ||
if(diff[0] == -1) { | ||
html += "<del>" + diff[1] + "</del>"; | ||
if(diff[0] === DiffOp.Delete) { | ||
html += '<del>' + diff[1] + '</del>'; | ||
} | ||
if(diff[0] == 1) { | ||
html += "<ins>" + diff[1] + "</ins>"; | ||
if(diff[0] === DiffOp.Insert) { | ||
html += '<ins>' + diff[1] + '</ins>'; | ||
} | ||
} | ||
html += "</div>" | ||
html += '</div>'; | ||
return html; | ||
} | ||
} | ||
} |
Sorry, the diff of this file is too big to display
91171
14
2254
1