-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove ReactDataGrid dependency from addons bundle #1272
Changes from 6 commits
5134c89
955d673
be93dad
a189f4a
24a0e7d
3560fb5
12764bf
0f5bdeb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import * as CellNavigationMode from './CellNavigationMode'; | ||
import * as EventTypes from './EventTypes'; | ||
import keyMirror from 'keymirror'; | ||
|
||
|
||
const UpdateActions = keyMirror({ | ||
CELL_UPDATE: null, | ||
COLUMN_FILL: null, | ||
COPY_PASTE: null, | ||
CELL_DRAG: null | ||
}); | ||
|
||
const DragItemTypes = { | ||
Column: 'column' | ||
}; | ||
|
||
const CellExpand = { | ||
DOWN_TRIANGLE: String.fromCharCode(9660), | ||
RIGHT_TRIANGLE: String.fromCharCode(9654) | ||
}; | ||
|
||
|
||
export { | ||
CellNavigationMode, | ||
EventTypes, | ||
UpdateActions, | ||
CellExpand, | ||
DragItemTypes | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export default { | ||
CELL_MASK: 5, | ||
EDITOR_CONTAINER: 10, | ||
FROZEN_CELL_MASK: 15, | ||
FROZEN_EDITOR_CONTAINER: 20 | ||
}; | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,17 @@ | ||
import ColumnMetrics from './ColumnMetrics'; | ||
|
||
export const shouldRowUpdate = (nextProps, currentProps) => { | ||
return !(ColumnMetrics.sameColumns(currentProps.columns, nextProps.columns, ColumnMetrics.sameColumn)) || | ||
nextProps.row !== currentProps.row || | ||
currentProps.colOverscanStartIdx !== nextProps.colOverscanStartIdx || | ||
currentProps.colOverscanEndIdx !== nextProps.colOverscanEndIdx || | ||
currentProps.colVisibleStartIdx !== nextProps.colVisibleStartIdx || | ||
currentProps.colVisibleEndIdx !== nextProps.colVisibleEndIdx || | ||
currentProps.isSelected !== nextProps.isSelected || | ||
currentProps.isScrolling !== nextProps.isScrolling || | ||
nextProps.height !== currentProps.height || | ||
currentProps.isOver !== nextProps.isOver || | ||
currentProps.expandedRows !== nextProps.expandedRows || | ||
currentProps.canDrop !== nextProps.canDrop || | ||
currentProps.forceUpdate === true || | ||
currentProps.extraClasses !== nextProps.extraClasses; | ||
}; | ||
|
||
export default shouldRowUpdate; | ||
export default function shouldRowUpdate(nextProps, currentProps) { | ||
return currentProps.columns !== nextProps.columns || | ||
nextProps.row !== currentProps.row || | ||
currentProps.colOverscanStartIdx !== nextProps.colOverscanStartIdx || | ||
currentProps.colOverscanEndIdx !== nextProps.colOverscanEndIdx || | ||
currentProps.colVisibleStartIdx !== nextProps.colVisibleStartIdx || | ||
currentProps.colVisibleEndIdx !== nextProps.colVisibleEndIdx || | ||
currentProps.isSelected !== nextProps.isSelected || | ||
currentProps.isScrolling !== nextProps.isScrolling || | ||
nextProps.height !== currentProps.height || | ||
currentProps.isOver !== nextProps.isOver || | ||
currentProps.expandedRows !== nextProps.expandedRows || | ||
currentProps.canDrop !== nextProps.canDrop || | ||
currentProps.forceUpdate === true || | ||
currentProps.extraClasses !== nextProps.extraClasses; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { List, Iterable, Map } from 'immutable'; | ||
|
||
export const isColumnsImmutable = (columns) => { | ||
return (typeof Immutable !== 'undefined' && (columns instanceof Immutable.List)); | ||
}; | ||
|
||
export const isEmptyArray = (obj) => { | ||
return Array.isArray(obj) && obj.length === 0; | ||
}; | ||
|
||
export const isFunction = (functionToCheck) => { | ||
let getType = {}; | ||
return functionToCheck && getType.toString.call(functionToCheck) === '[object Function]'; | ||
}; | ||
|
||
export const isEmptyObject = (obj) => { | ||
return Object.keys(obj).length === 0 && obj.constructor === Object; | ||
}; | ||
|
||
export const isImmutableCollection = objToVerify => { | ||
return Iterable.isIterable(objToVerify); | ||
}; | ||
|
||
export const getMixedTypeValueRetriever = (isImmutable) => { | ||
let retObj = {}; | ||
const retriever = (item, key) => { return item[key]; }; | ||
const immutableRetriever = (immutable, key) => { return immutable.get(key); }; | ||
|
||
retObj.getValue = isImmutable ? immutableRetriever : retriever; | ||
|
||
return retObj; | ||
}; | ||
|
||
export const isImmutableMap = Map.isMap; | ||
|
||
export const last = arrayOrList => { | ||
if (arrayOrList == null) { | ||
throw new Error('arrayOrCollection is null'); | ||
} | ||
|
||
if (List.isList(arrayOrList)) { | ||
return arrayOrList.last(); | ||
} | ||
|
||
if (Array.isArray(arrayOrList)) { | ||
return arrayOrList[arrayOrList.length - 1]; | ||
} | ||
|
||
throw new Error('Cant get last of: ' + typeof(arrayOrList)); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,41 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { DragSource, DropTarget } from 'react-dnd'; | ||
import { HeaderCell } from 'react-data-grid'; | ||
|
||
class HeaderCell extends React.Component { | ||
static propTypes = { | ||
column: PropTypes.isRequired, | ||
height: PropTypes.number.isRequired, | ||
className: PropTypes.string | ||
}; | ||
|
||
getStyle() { | ||
return { | ||
width: this.props.column.width, | ||
left: this.props.column.left, | ||
display: 'inline-block', | ||
position: 'absolute', | ||
height: this.props.height, | ||
margin: 0, | ||
textOverflow: 'ellipsis', | ||
whiteSpace: 'nowrap' | ||
}; | ||
} | ||
|
||
setScrollLeft = (scrollLeft) => { | ||
let node = ReactDOM.findDOMNode(this); | ||
node.style.webkitTransform = `translate3d(${scrollLeft}px, 0px, 0px)`; | ||
node.style.transform = `translate3d(${scrollLeft}px, 0px, 0px)`; | ||
}; | ||
|
||
render() { | ||
return ( | ||
<div className="react-grid-HeaderCell" style={this.getStyle()}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can add a |
||
{this.props.column.name} | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
class DraggableHeaderCell extends React.Component { | ||
render() { | ||
|
@@ -26,7 +60,7 @@ class DraggableHeaderCell extends React.Component { | |
style={{ width: 0, cursor: 'move', opacity }} | ||
className={isOver && canDrop ? 'rdg-can-drop' : ''} | ||
> | ||
<HeaderCell {...this.props} /> | ||
<HeaderCell {...this.props}/> | ||
</div> | ||
) | ||
); | ||
|
@@ -84,7 +118,8 @@ DraggableHeaderCell.propTypes = { | |
connectDropTarget: PropTypes.func.isRequired, | ||
isDragging: PropTypes.bool.isRequired, | ||
isOver: PropTypes.bool, | ||
canDrop: PropTypes.bool | ||
canDrop: PropTypes.bool, | ||
renderHeaderCell: PropTypes.fund | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typo There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Needs to be fixed |
||
}; | ||
|
||
DraggableHeaderCell = DropTarget('Column', target, targetCollect)( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use individual exports for better error checking, treeshaking
https://medium.com/@rauschma/note-that-default-exporting-objects-is-usually-an-anti-pattern-if-you-want-to-export-the-cf674423ac38
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would agree but it is a very small file, and I think it is clearer to reference
zIndexes.CELL_MASK
rather than justCELL_MASK