Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<title>Sample App</title>
</head>
<body>
<h1>Sample App</h1>
<div id='root'>
</div>
<script src="/static/bundle.js"></script>
Expand Down
47 changes: 43 additions & 4 deletions lib/RegionSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,16 @@ var RegionSelect = function (_Component) {
height: height,
isChanging: true
};
this.props.onChange([].concat(_toConsumableArray(this.props.regions.slice(0, index)), [(0, _objectAssign2.default)({}, updatingRegion, rect)], _toConsumableArray(this.props.regions.slice(index + 1))));
/**
Add event with resize and region
**/

this.props.onChange([].concat(_toConsumableArray(this.props.regions.slice(0, index)), [(0, _objectAssign2.default)({}, updatingRegion, rect)], _toConsumableArray(this.props.regions.slice(index + 1))), {
event: 'resize',
source: event,
region: updatingRegion,
index: index
});
}
}, {
key: 'onDocMouseTouchEnd',
Expand All @@ -170,7 +179,17 @@ var RegionSelect = function (_Component) {
};
this.regionChangeIndex = null;
this.regionChangeData = null;
this.props.onChange([].concat(_toConsumableArray(this.props.regions.slice(0, index)), [(0, _objectAssign2.default)({}, updatingRegion, changes)], _toConsumableArray(this.props.regions.slice(index + 1))));

/**
Add event with end and region
**/

this.props.onChange([].concat(_toConsumableArray(this.props.regions.slice(0, index)), [(0, _objectAssign2.default)({}, updatingRegion, changes)], _toConsumableArray(this.props.regions.slice(index + 1))), {
event: 'end',
source: event,
region: updatingRegion,
index: index
});
}
}
}, {
Expand All @@ -197,6 +216,7 @@ var RegionSelect = function (_Component) {
isChanging: true
};
this.regionCounter += 1;

this.regionChangeData = {
imageOffsetLeft: imageOffset.left,
imageOffsetTop: imageOffset.top,
Expand All @@ -208,10 +228,29 @@ var RegionSelect = function (_Component) {
};

if (this.props.regions.length < this.props.maxRegions) {
this.props.onChange(this.props.regions.concat(rect));
/**
Add event with start
**/
this.props.onChange(this.props.regions.concat(rect), {
event: 'start',
source: event,
data: rect.data,
index: this.props.regions.length
});

this.regionChangeIndex = this.props.regions.length;
} else {
this.props.onChange([].concat(_toConsumableArray(this.props.regions.slice(0, this.props.maxRegions - 1)), [rect]));
/**
Add event with start
**/

this.props.onChange([].concat(_toConsumableArray(this.props.regions.slice(0, this.props.maxRegions - 1)), [rect]), {
event: 'start',
source: event,
data: rect.data,
index: this.props.regions.length
});

this.regionChangeIndex = this.props.maxRegions - 1;
}
}
Expand Down
48 changes: 44 additions & 4 deletions src/RegionSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,20 @@ class RegionSelect extends Component {
height: height,
isChanging: true
};
/**
Add event with resize and region
**/

this.props.onChange([
...this.props.regions.slice(0, index),
objectAssign({}, updatingRegion, rect),
...this.props.regions.slice(index + 1)
]);
], {
event: 'resize',
source: event,
region: updatingRegion,
index: index
});
}
onDocMouseTouchEnd () {
if (this.isChanging) {
Expand All @@ -108,11 +117,22 @@ class RegionSelect extends Component {
};
this.regionChangeIndex = null;
this.regionChangeData = null;

/**
Add event with end and region
**/


this.props.onChange([
...this.props.regions.slice(0, index),
objectAssign({}, updatingRegion, changes),
...this.props.regions.slice(index + 1)
]);
], {
event: 'end',
source: event,
region: updatingRegion,
index: index
});
}
}
onComponentMouseTouchDown (event) {
Expand All @@ -135,6 +155,7 @@ class RegionSelect extends Component {
isChanging: true
};
this.regionCounter += 1;

this.regionChangeData = {
imageOffsetLeft: imageOffset.left,
imageOffsetTop: imageOffset.top,
Expand All @@ -146,13 +167,32 @@ class RegionSelect extends Component {
};

if (this.props.regions.length < this.props.maxRegions) {
this.props.onChange(this.props.regions.concat(rect));
/**
Add event with start
**/
this.props.onChange(this.props.regions.concat(rect), {
event: 'start',
source: event,
data: rect.data,
index: this.props.regions.length
});

this.regionChangeIndex = this.props.regions.length;
} else {
/**
Add event with start
**/

this.props.onChange([
...this.props.regions.slice(0, this.props.maxRegions - 1),
rect
]);
], {
event: 'start',
source: event,
data: rect.data,
index: this.props.regions.length
});

this.regionChangeIndex = this.props.maxRegions - 1;
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/example/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class App extends Component {
regions: []
};
}
onChange (regions) {
onChange (regions, event) {
console.log('onchange', [event]);
this.setState({
regions: regions
});
Expand Down