Skip to content

Commit 06d19e2

Browse files
committed
chore(pkg): New Flow React bindings, webpack 3, react-draggable 3
1 parent 8f0182e commit 06d19e2

File tree

10 files changed

+1177
-776
lines changed

10 files changed

+1177
-776
lines changed

examples/1.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
display: block;
4444
}
4545
</style>
46+
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.6.1/react.min.js"></script>
47+
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.6.1/react-dom.min.js"></script>
4648
<script src="/bundle.js"></script>
4749
<title>React-Resizable</title>
4850
</head>

lib/Resizable.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// @flow
2-
import React from 'react';
2+
import * as React from 'react';
33
import PropTypes from 'prop-types';
44
import {DraggableCore} from 'react-draggable';
55
import cloneElement from './cloneElement';
@@ -29,14 +29,13 @@ export type Props = {
2929
axis: Axis,
3030
minConstraints: [number, number],
3131
maxConstraints: [number, number],
32-
onResizeStop?: ?(e: SyntheticEvent, data: ResizeCallbackData) => any,
33-
onResizeStart?: ?(e: SyntheticEvent, data: ResizeCallbackData) => any,
34-
onResize?: ?(e: SyntheticEvent, data: ResizeCallbackData) => any,
32+
onResizeStop?: ?(e: SyntheticEvent<>, data: ResizeCallbackData) => any,
33+
onResizeStart?: ?(e: SyntheticEvent<>, data: ResizeCallbackData) => any,
34+
onResize?: ?(e: SyntheticEvent<>, data: ResizeCallbackData) => any,
3535
draggableOpts?: ?Object
3636
};
3737

38-
export default class Resizable extends React.Component {
39-
38+
export default class Resizable extends React.Component<Props, State> {
4039
static propTypes = {
4140
//
4241
// Required Props
@@ -78,7 +77,6 @@ export default class Resizable extends React.Component {
7877
// These will be passed wholesale to react-draggable's DraggableCore
7978
draggableOpts: PropTypes.object
8079
};
81-
props: Props;
8280

8381
static defaultProps = {
8482
handleSize: [20, 20],
@@ -158,7 +156,7 @@ export default class Resizable extends React.Component {
158156
* @return {Function} Handler function.
159157
*/
160158
resizeHandler(handlerName: string): Function {
161-
return (e: SyntheticEvent | MouseEvent, {node, deltaX, deltaY}: DragCallbackData) => {
159+
return (e: SyntheticEvent<> | MouseEvent, {node, deltaX, deltaY}: DragCallbackData) => {
162160

163161
// Axis restrictions
164162
const canDragX = this.props.axis === 'both' || this.props.axis === 'x';
@@ -198,7 +196,7 @@ export default class Resizable extends React.Component {
198196
};
199197
}
200198

201-
render(): React.Element<any> {
199+
render(): React.Node {
202200
// eslint-disable-next-line no-unused-vars
203201
const {children, draggableOpts, width, height, handleSize,
204202
lockAspectRatio, axis, minConstraints, maxConstraints, onResize,

lib/ResizableBox.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
// @flow
2-
import React from 'react';
2+
import * as React from 'react';
33
import PropTypes from 'prop-types';
44
import Resizable from './Resizable';
55
import type {Props as ResizableProps, ResizeCallbackData} from './Resizable';
66

77
type State = {width: number, height: number};
88

99
// An example use of Resizable.
10-
export default class ResizableBox extends React.Component {
10+
export default class ResizableBox extends React.Component<ResizableProps, State> {
1111
static propTypes = {
1212
height: PropTypes.number,
1313
width: PropTypes.number
1414
};
15-
props: ResizableProps;
1615

1716
static defaultProps = {
1817
handleSize: [20,20]
@@ -23,7 +22,7 @@ export default class ResizableBox extends React.Component {
2322
height: this.props.height,
2423
};
2524

26-
onResize = (e: SyntheticEvent, data: ResizeCallbackData) => {
25+
onResize = (e: SyntheticEvent<>, data: ResizeCallbackData) => {
2726
const {size} = data;
2827
const {width, height} = size;
2928

@@ -44,14 +43,13 @@ export default class ResizableBox extends React.Component {
4443
}
4544
}
4645

47-
render(): React.Element<any> {
46+
render(): React.Node {
4847
// Basic wrapper around a Resizable instance.
4948
// If you use Resizable directly, you are responsible for updating the child component
5049
// with a new width and height.
5150
const {handleSize, onResize, onResizeStart, onResizeStop, draggableOpts,
5251
minConstraints, maxConstraints, lockAspectRatio, axis, width, height, ...props} = this.props;
5352
return (
54-
// $FlowIgnore children & defaultProps bug (https://github.com/facebook/flow/issues/1964)
5553
<Resizable
5654
handleSize={handleSize}
5755
width={this.state.width}

lib/cloneElement.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// @flow
2-
import React from 'react';
2+
import * as React from 'react';
33

44
// React.addons.cloneWithProps look-alike that merges style & className.
55
module.exports = function cloneElement(element: React.Element<any>, props: Object): React.Element<any> {

package.json

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"test": "echo \"Error: no test specified\" && exit 1",
99
"build": "bash build.sh",
1010
"build-example": "webpack",
11-
"dev": "echo 'Open http://localhost:4003/examples/1.html' && cross-env NODE_ENV=test webpack-dev-server --config webpack-dev-server.config.js --progress --hot --inline",
11+
"dev": "webpack-dev-server --open --open-page=examples/1.html",
12+
"watch": "webpack --progress --watch",
1213
"prepublish": "npm run build",
1314
"validate": "yarn list",
1415
"preversion": "npm run lint",
@@ -31,30 +32,30 @@
3132
},
3233
"homepage": "https://github.com/STRML/react-resizable",
3334
"devDependencies": {
34-
"babel-cli": "^6.24.1",
35-
"babel-core": "^6.24.1",
35+
"babel-cli": "^6.26.0",
36+
"babel-core": "^6.26.0",
3637
"babel-eslint": "^7.2.3",
37-
"babel-loader": "^7.0.0",
38+
"babel-loader": "^7.1.2",
3839
"babel-plugin-transform-class-properties": "^6.24.1",
39-
"babel-plugin-transform-object-rest-spread": "^6.23.0",
40+
"babel-plugin-transform-object-rest-spread": "^6.26.0",
4041
"babel-preset-es2015": "^6.24.1",
4142
"babel-preset-react": "^6.24.1",
42-
"cross-env": "^5.0.0",
43-
"css-loader": "^0.28.0",
44-
"eslint": "^3.19.0",
45-
"eslint-plugin-react": "^7.0.1",
46-
"flow-bin": "^0.46.0",
43+
"cross-env": "^5.0.5",
44+
"css-loader": "^0.28.5",
45+
"eslint": "^4.5.0",
46+
"eslint-plugin-react": "^7.2.1",
47+
"flow-bin": "^0.53.1",
4748
"lodash": "^4.3.0",
4849
"pre-commit": "^1.1.2",
49-
"react": "^15.5.4",
50-
"react-dom": "^15.5.4",
51-
"style-loader": "^0.18.1",
52-
"webpack": "^2.4.1",
53-
"webpack-dev-server": "^2.4.5"
50+
"react": "^15.6.1",
51+
"react-dom": "^15.6.1",
52+
"style-loader": "^0.18.2",
53+
"webpack": "^3.5.5",
54+
"webpack-dev-server": "^2.7.1"
5455
},
5556
"dependencies": {
5657
"prop-types": "^15.5.8",
57-
"react-draggable": "^2.2.6"
58+
"react-draggable": "^2.2.6 || ^3.0.0"
5859
},
5960
"peerDependencies": {
6061
"react": "^0.14.0 || ^15.0.0",

test/TestLayout.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import React from 'react';
1+
import * as React from 'react';
22
import Resizable from '../lib/Resizable';
33
import ResizableBox from '../lib/ResizableBox';
44
import 'style-loader!css-loader!../css/styles.css';
55

6-
export default class TestLayout extends React.Component {
6+
export default class TestLayout extends React.Component<{}, {width: number, height: number}> {
77
state = {width: 200, height: 200};
88

99
onClick = () => {

test/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import TestLayout from './TestLayout';
2-
import React from 'react';
2+
import * as React from 'react';
33
import ReactDOM from 'react-dom';
44

55
document.addEventListener("DOMContentLoaded", function(event) {

webpack-dev-server.config.js

Lines changed: 0 additions & 33 deletions
This file was deleted.

webpack.config.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ module.exports = {
1010
path: path.join(__dirname, "dist"),
1111
filename: "bundle.js",
1212
sourceMapFilename: "[file].map",
13+
library: 'ReactResizable',
14+
libraryTarget: 'umd'
1315
},
1416
externals: {
1517
'react': {
@@ -24,14 +26,23 @@ module.exports = {
2426
'commonjs2': 'react-dom',
2527
'amd': 'react-dom',
2628
'root': 'ReactDOM'
27-
},
29+
}
2830
},
2931
module: {
30-
loaders: [
32+
rules: [
3133
{test: /\.jsx?$/, exclude: /node_modules/, loader: 'babel-loader?cacheDirectory=true'},
3234
]
3335
},
3436
resolve: {
3537
extensions: [".js"]
3638
},
39+
devServer: {
40+
contentBase: __dirname,
41+
compress: true,
42+
port: 4003,
43+
},
44+
plugins: [
45+
// Scope hoisting
46+
new webpack.optimize.ModuleConcatenationPlugin(),
47+
]
3748
};

0 commit comments

Comments
 (0)