react-diff-view
Advanced tools
Comparing version 3.2.0 to 3.2.1
@@ -72,3 +72,3 @@ import parser from 'gitdiff-parser'; | ||
export function parseDiff(text, options = {}) { | ||
const diffText = normalizeDiffText(text.trim()); | ||
const diffText = normalizeDiffText(text.trimStart()); | ||
const files = parser.parse(diffText); | ||
@@ -75,0 +75,0 @@ return files.map(file => mapFile(file, options)); |
{ | ||
"name": "react-diff-view", | ||
"version": "3.2.0", | ||
"version": "3.2.1", | ||
"description": "A git diff component to consume the git unified diff output.", | ||
@@ -127,3 +127,3 @@ "main": "./cjs/index.js", | ||
], | ||
"packageManager": "yarn@4.0.1" | ||
"packageManager": "yarn@4.1.0+sha256.81a00df816059803e6b5148acf03ce313cad36b7f6e5af6efa040a15981a6ffb" | ||
} |
@@ -100,9 +100,7 @@ # react-diff-view | ||
```jsx | ||
```tsx | ||
import {parseDiff, Diff, Hunk} from 'react-diff-view'; | ||
const App = ({diffText}) => { | ||
const files = parseDiff(diffText); | ||
const renderFile = ({oldRevision, newRevision, type, hunks}) => ( | ||
function renderFile({oldRevision, newRevision, type, hunks}) { | ||
return ( | ||
<Diff key={oldRevision + '-' + newRevision} viewType="split" diffType={type} hunks={hunks}> | ||
@@ -112,3 +110,7 @@ {hunks => hunks.map(hunk => <Hunk key={hunk.content} hunk={hunk} />)} | ||
); | ||
} | ||
function App({diffText}) { | ||
const files = parseDiff(diffText); | ||
return ( | ||
@@ -119,3 +121,3 @@ <div> | ||
); | ||
}; | ||
} | ||
``` | ||
@@ -251,3 +253,3 @@ | ||
...widgets, | ||
[changeKey]: <span className="error">Line too long</span> | ||
[changeKey]: <span className="error">Line too long</span>, | ||
}; | ||
@@ -380,36 +382,38 @@ }, | ||
```javascript | ||
import {PureComponent} from 'react'; | ||
import {bind} from 'lodash-decorators'; | ||
import {Diff} from 'react-diff-view'; | ||
```jsx | ||
import {useState, useCallback, useMemo} from 'react'; | ||
class File extends PureComponent { | ||
state = { | ||
selectedChanges: [], | ||
gutterEvents: { | ||
onClick: this.selectChange | ||
function File({hunks, diffType}) { | ||
const [selectedChanges, setSelectedChanges] = useState([]); | ||
const selectChange = useCallback( | ||
({change}) => { | ||
const toggle = selectedChanges => { | ||
const index = selectedChanges.indexOf(change); | ||
if (index >= 0) { | ||
return [ | ||
...selectedChanges.slice(0, index), | ||
...selectedChanges.slice(index + 1), | ||
]; | ||
} | ||
return [...selectedChanges, change]; | ||
}; | ||
setSelectedChanges(toggle); | ||
}, | ||
codeEvents: { | ||
onClick: this.selectChange | ||
} | ||
}; | ||
[] | ||
); | ||
const diffProps = useMemo( | ||
() => { | ||
return { | ||
gutterEvents: {onClick: selectChange}, | ||
codeEvents: {onClick: selectChange}, | ||
}; | ||
}, | ||
[selectChange] | ||
); | ||
@bind() | ||
selectChange({change}) { | ||
const {selectedChanges} = this.state; | ||
const selected = selectedChanges.includes(change); | ||
this.setState({selectedChanges: selected ? without(selectedChanges, change) : [...selectedChanges, change]}); | ||
} | ||
render() { | ||
const {hunks, diffType} = this.props; | ||
const {gutterEvents, codeEvents} = this.state; | ||
const hunkProps = {gutterEvents, codeEvents}; | ||
return ( | ||
<Diff viewType="split" diffType={diffType}> | ||
{hunk.map(hunk => <Hunk key={hunk.content} hunk={hunk} {...hunkProps} />)} | ||
</Diff> | ||
); | ||
} | ||
return ( | ||
<Diff viewType="split" diffType={diffType} hunks={hunks} {...diffProps}> | ||
{hunks => hunks.map(hunk => <Hunk key={hunk.content} hunk={hunk} />)} | ||
</Diff> | ||
); | ||
} | ||
@@ -502,4 +506,4 @@ ``` | ||
markWord('\t', 'tab'), | ||
markEdits(hunks) | ||
] | ||
markEdits(hunks), | ||
], | ||
}; | ||
@@ -506,0 +510,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1292232
759