react-diff-view
Advanced tools
Comparing version 1.6.0 to 1.6.1
{ | ||
"name": "react-diff-view", | ||
"version": "1.6.0", | ||
"version": "1.6.1", | ||
"description": "A git diff component to consume the git unified diff output.", | ||
@@ -16,3 +16,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"classnames": "^2.2.5", | ||
"classnames": "^2.2.6", | ||
"gitdiff-parser": "0.0.8", | ||
@@ -27,3 +27,3 @@ "leven": "^2.1.0", | ||
"@ecomfe/eslint-config": "^1.0.0", | ||
"antd": "^3.2.3", | ||
"antd": "^3.6.2", | ||
"babel-core": "^6.26.0", | ||
@@ -48,3 +48,3 @@ "babel-eslint": "^8.2.2", | ||
"eslint-plugin-import": "^2.12.0", | ||
"eslint-plugin-react": "^7.7.0", | ||
"eslint-plugin-react": "^7.9.1", | ||
"extract-text-webpack-plugin": "^4.0.0-beta.0", | ||
@@ -69,6 +69,5 @@ "html-webpack-plugin": "^3.0.6", | ||
"short-hash": "^1.0.0", | ||
"sinon": "^5.0.10", | ||
"style-loader": "^0.21.0", | ||
"svg-react-loader": "^0.4.5", | ||
"webpack": "^4.1.0", | ||
"webpack": "^4.12.0", | ||
"webpack-cli": "^2.1.5", | ||
@@ -75,0 +74,0 @@ "webpack-dev-server": "^3.1.4", |
@@ -537,1 +537,5 @@ # react-diff-view | ||
- Enable optimized selection to select only one side in split view, a `optimizeSelection` prop is added. | ||
### 1.6.1 | ||
- Optimize performance of column selection. |
@@ -9,2 +9,4 @@ import {PureComponent, Children, cloneElement} from 'react'; | ||
const noop = () => {}; // eslint-disable-line no-empty-function | ||
const findClosest = (target, className) => { | ||
@@ -18,2 +20,10 @@ while (target && target.classList && !target.classList.contains(className)) { | ||
const setUserSelectStyle = (element, selectable) => { | ||
const value = selectable ? 'auto' : 'none'; | ||
if (element.style.userSelect !== value) { | ||
element.style.userSelect = value; // eslint-disable-line no-param-reassign | ||
} | ||
}; | ||
export default class Diff extends PureComponent { | ||
@@ -50,8 +60,2 @@ | ||
enableColumnSelection({target}) { | ||
const {viewType, optimizeSelection} = this.props; | ||
if (viewType !== 'split' || !optimizeSelection) { | ||
return; | ||
} | ||
const closestCell = findClosest(target, 'diff-code'); | ||
@@ -71,19 +75,17 @@ | ||
/* eslint-disable no-param-reassign */ | ||
[...this.root.querySelectorAll('.diff-line > td')].forEach(cell => (cell.style.userSelect = 'auto')); | ||
for (let i = 1; i <= 4; i++) { | ||
if (i === index + 1) { | ||
continue; | ||
} | ||
const cells = [...this.root.querySelectorAll(`.diff-line > td:nth-child(${i})`)]; | ||
cells.forEach(cell => (cell.style.userSelect = 'none')); | ||
const lines = this.root.querySelectorAll('.diff-line'); | ||
for (const line of lines) { | ||
const cells = line.children; | ||
setUserSelectStyle(cells[1], index === 1); | ||
setUserSelectStyle(cells[3], index === 3); | ||
} | ||
/* eslint-enable no-param-reassign */ | ||
} | ||
render() { | ||
const {diffType, hunks, children, className, ...props} = this.props; | ||
const {diffType, hunks, children, className, optimizeSelection, ...props} = this.props; | ||
const {hideGutter, viewType} = props; | ||
const monotonous = diffType === 'add' || diffType === 'delete'; | ||
const {hideGutter} = props; | ||
const onTableMouseDown = (viewType === 'split' && !monotonous && optimizeSelection) | ||
? this.enableColumnSelection | ||
: noop; | ||
const cols = ((viewType, monotonous) => { | ||
@@ -126,3 +128,3 @@ if (viewType === 'unified') { | ||
className={classNames('diff', className)} | ||
onMouseDown={this.enableColumnSelection} | ||
onMouseDown={onTableMouseDown} | ||
> | ||
@@ -129,0 +131,0 @@ {cols} |
Sorry, the diff of this file is too big to display
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
1171067
47
2199
541
Updatedclassnames@^2.2.6