Skip to content
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

Backend mousemove 1.0 #70

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
91fd2c5
remove legacy api
Feb 11, 2015
79ec44a
Merge pull request #68 from nelix/remove-legacy-api
gaearon Feb 11, 2015
b6a72f9
Get started with experiments
gaearon Nov 2, 2014
93f7573
Continue experimenting
gaearon Nov 20, 2014
8589017
Signal awesome
gaearon Nov 20, 2014
f15ce68
Update caption
gaearon Nov 20, 2014
2dbe7e1
fix DragDropMixin in firefox
Feb 3, 2015
98f0b98
rage quit
Feb 4, 2015
1a8c6cf
Remove HTML5-specific code from mousemove backend
gaearon Feb 6, 2015
7ee8d47
Remove mousemove
gaearon Feb 6, 2015
72e0d95
Rename files
gaearon Feb 6, 2015
8f4b5c7
Refactor, move some HTML5-specific code into its backend
gaearon Feb 6, 2015
1ebfac1
Store current component
gaearon Feb 6, 2015
95a00ea
Dragging works!
gaearon Feb 6, 2015
3516af7
Fix errors
gaearon Feb 6, 2015
eaae443
Fix dropping
gaearon Feb 6, 2015
48def6a
Make backend configurable
gaearon Feb 6, 2015
7843a59
Fix coordinates on all browsers
gaearon Feb 6, 2015
4cc7032
Don't expose backends directly
gaearon Feb 6, 2015
484773f
Add barebone slow Touch backend
gaearon Feb 6, 2015
6474f66
fix initial drag position in experiment example
Feb 7, 2015
adf5c50
block scrolling in touch backend
Feb 7, 2015
a1bce0d
fix touch backend client offset
Feb 7, 2015
4b0ed64
drag a grabbing hand while dragging
Feb 7, 2015
5e7dd68
sortable example using mouse backend
Feb 7, 2015
47f2f82
use getMouseCoordinates, for portability
Feb 8, 2015
5f704ce
Fix precedence
gaearon Feb 9, 2015
d6904c1
update mouse backend sortable to use static api
Feb 12, 2015
7ef2b92
send the current component to backend at all stages
Feb 12, 2015
576d9cc
fix up the experimental example
Feb 12, 2015
8139b9e
normalise the arguments in the mouse and touch backends to match html5
Feb 12, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
83 changes: 83 additions & 0 deletions examples/_drag-around-experimental/Box.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/** @jsx React.DOM */
'use strict';

var React = require('react'),
ItemTypes = require('./ItemTypes'),
getEmptyImage = require('./getEmptyImage'),
{ PropTypes } = React,
{ MouseDragDropMixin, DropEffects } = require('react-dnd');

var Box = React.createClass({
mixins: [MouseDragDropMixin],

propTypes: {
id: PropTypes.any.isRequired,
isDragFeedback: PropTypes.bool,
left: PropTypes.number.isRequired,
top: PropTypes.number.isRequired
},

getInitialState() {
return {
tickTock: false
};
},

componentDidMount() {
this.interval = setInterval(() => {
this.setState({ tickTock: !this.state.tickTock });
}, 200);
},

componentWillUnmount() {
clearInterval(this.interval);
},

statics: {
configureDragDrop(registerType) {
registerType(ItemTypes.BOX, {
dragSource: {
beginDrag(component, e) {
return {
effectAllowed: DropEffects.MOVE,
dragPreview: getEmptyImage(),
item: {
id: component.props.id,
children: component.props.children,
startLeft: component.props.left,
startTop: component.props.top,
startClientX: e.clientX,
startClientY: e.clientY
}
};
}
}
});
}
},

render() {
var { isDragging } = this.getDragState(ItemTypes.BOX),
{ isDragFeedback } = this.props,
transform = `translate3d(${this.props.left}px, ${this.props.top}px, 0)`;

return (
<div {...this.dragSourceFor(ItemTypes.BOX)}
style={{
WebkitTransform: transform,
transform: transform,
opacity: isDragging ? 0 : 1,
position: 'absolute',
backgroundColor: isDragFeedback && this.state.tickTock ? 'yellow' : 'white',
top: 0,
left: 0,
border: '1px dashed gray',
padding: '0.5rem'
}}>
{this.props.children}
</div>
);
}
});

module.exports = Box;
87 changes: 87 additions & 0 deletions examples/_drag-around-experimental/Container.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/** @jsx React.DOM */
'use strict';

var React = require('react'),
update = require('react/lib/update'),
ItemTypes = require('./ItemTypes'),
Box = require('./Box'),
{ PropTypes } = React,
{ MouseDragDropMixin } = require('react-dnd');

var Container = React.createClass({
mixins: [MouseDragDropMixin],

getInitialState() {
return {
boxes: {
'a': { top: 20, left: 80, title: 'Drag me around' },
'b': { top: 180, left: 20, title: 'Drag me too' },
}
};
},

statics: {
configureDragDrop(registerType) {
registerType(ItemTypes.BOX, {
dropTarget: {
acceptDrop(component, item, e) {
var left = Math.round(item.startLeft + (e.clientX - item.startClientX)),
top = Math.round(item.startTop + (e.clientY - item.startClientY));

component.moveBox(item.id, left, top);
}
}
});
}
},

moveBox(id, left, top) {
var stateUpdate = {
boxes: {}
};

stateUpdate.boxes[id] = {
$merge: {
left: left,
top: top
}
};

this.setState(update(this.state, stateUpdate));
},

render() {
var cursor;
if (this.state.draggedItemType === 'box') {
cursor = '-webkit-grabbing';
}

return (
<div {...this.dropTargetFor(ItemTypes.BOX)}
style={{
cursor: cursor,
width: 300,
height: 300,
border: '1px solid black',
position: 'relative'
}}>

{Object.keys(this.state.boxes).map(key => {
var box = this.state.boxes[key];

return (
<Box key={key}
id={key}
left={box.left}
top={box.top}>
{box.title}
</Box>
);
})}

</div>
);
}
});

module.exports = Container;
57 changes: 57 additions & 0 deletions examples/_drag-around-experimental/DragLayer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/** @jsx React.DOM */
'use strict';

var React = require('react'),
Box = require('./Box'),
{ DragFeedbackMixin } = require('react-dnd');

var DragLayer = React.createClass({
mixins: [DragFeedbackMixin],

render() {
var {
x,
y,
draggedItem,
isDragging
} = this.state;

var transform;
if (isDragging) {
transform = `translate3d(${x}px, ${y}px, 0)`;
}

return (
<div style={{
position: 'absolute',
pointerEvents: 'none',
zIndex: 100,
left: 0,
top: 0,
width:'100%',
height: '100%'
}}>
{isDragging &&
<div style={{
position: 'fixed',
left: 0,
top: 0,
transform: transform,
WebkitTransform: transform,
width: '100%',
height: '100%'
}}>
<Box left={0}
top={0}
id={draggedItem.id}
isDragFeedback>
{draggedItem.children}
</Box>
</div>
}
</div>
);
}
});

module.exports = DragLayer;
5 changes: 5 additions & 0 deletions examples/_drag-around-experimental/ItemTypes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

module.exports = {
BOX: 'box'
};
12 changes: 12 additions & 0 deletions examples/_drag-around-experimental/getEmptyImage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

var TRANSPARENT_PIXEL_SRC = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==',
emptyImg = document.createElement('img');

emptyImg.src = TRANSPARENT_PIXEL_SRC;

function getEmptyImage() {
return emptyImg;
}

module.exports = getEmptyImage;
27 changes: 27 additions & 0 deletions examples/_drag-around-experimental/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/** @jsx React.DOM */
'use strict';

var React = require('react'),
Container = require('./Container'),
DragLayer = require('./DragLayer'),
LinkedStateMixin = require('react/lib/LinkedStateMixin');

var DragAroundExperimental = React.createClass({
render() {
return (
<div>
<Container />
<DragLayer />
<hr />
<p>
Try dragging an item. It will change while being animated.
</p>
<p>
<b>This is experimental and is <i>not</i> available in master yet.</b> I'll be working on making this possible in next release.
</p>
</div>
);
}
});

module.exports = DragAroundExperimental;
58 changes: 58 additions & 0 deletions examples/_sortable-mouse/Card.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
'use strict';

var React = require('react'),
ItemTypes = require('./ItemTypes'),
{ PropTypes } = React,
{ MouseDragDropMixin, DropEffects } = require('react-dnd');

var Card = React.createClass({
mixins: [MouseDragDropMixin],

propTypes: {
id: PropTypes.any.isRequired,
text: PropTypes.string.isRequired,
moveCard: PropTypes.func.isRequired
},
statics: {
configureDragDrop(registerType) {
registerType(ItemTypes.CARD, {
dragSource: {
beginDrag(component) {
return {
item: {
id: component.props.id,
children: <Card {...this.props}/>
}
};
}
},

dropTarget: {
over(component, item) {
component.props.moveCard(item.id, this.props.id);
}
}
});
}
},

render() {
var { isDragging } = this.getDragState(ItemTypes.CARD);

return (
<div {...this.dragSourceFor(ItemTypes.CARD)}
{...this.dropTargetFor(ItemTypes.CARD)}
style={{
border: '1px dashed gray',
backgroundColor: 'white',
padding: '0.5rem',
margin: '0.5rem',
opacity: isDragging ? 0 : 1
}}>
{this.props.text}
</div>
);
}
});

module.exports = Card;