Skip to content

Commit 13f6daf

Browse files
committed
chore(dev): upgrade webpack & flow
1 parent e776dfb commit 13f6daf

File tree

13 files changed

+251
-220
lines changed

13 files changed

+251
-220
lines changed

.flowconfig

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,8 @@ lib/
66
index.js
77

88
[options]
9-
suppress_comment=\\(.\\|\n\\)*\\s*\\$FlowFixMe.*
10-
suppress_comment=\\(.\\|\n\\)*\\s*\\$FlowBug.*
11-
suppress_comment=\\(.\\|\n\\)*\\s*\\$FlowIgnore.*
12-
suppress_comment=\\(.\\|\n\\)*\\s*\\$FlowNewLine.*
13-
suppress_comment=\\(.\\|\n\\)*\\s*\\$FlowIssue
149
esproposal.class_instance_fields=enable
1510
esproposal.class_static_fields=enable
1611
sharedmemory.heap_size=3221225472
12+
esproposal.optional_chaining=enable
13+
exact_by_default=true

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ install link:
2929
@yarn $@
3030

3131
test: $(BIN)
32-
@NODE_ENV=test $(BIN)/karma start
32+
@$(BIN)/karma start
3333

3434
test-phantom: $(BIN)
35-
@NODE_ENV=test $(BIN)/karma start karma-phantomjs.conf.js
35+
@$(BIN)/karma start karma-phantomjs.conf.js
3636

3737
dev: $(BIN) clean
38-
env DRAGGABLE_DEBUG=1 $(BIN)/webpack-dev-server
38+
env DRAGGABLE_DEBUG=1 $(BIN)/webpack serve --mode=development
3939

4040
node_modules/.bin: install
4141

karma.conf.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
const _ = require('lodash');
44
const webpack = require('webpack');
5-
process.env.NODE_ENV = 'test';
5+
process.env.NODE_ENV = 'development';
66
process.env.CHROME_BIN = require('puppeteer').executablePath();
77

88
module.exports = function(config) {
99
const webpackConfig = _.merge(
1010
require('./webpack.config.js')({}, {}),
1111
{
12-
mode: 'production',
12+
mode: 'development',
1313
// Remove source maps: *speeeeeed*
1414
devtool: false,
1515
cache: true,
@@ -23,6 +23,7 @@ module.exports = function(config) {
2323

2424
delete webpackConfig.entry; // karma-webpack complains
2525
delete webpackConfig.output; // karma-webpack complains
26+
// Make sure `process.env` is present as an object
2627
webpackConfig.plugins.push(new webpack.DefinePlugin({
2728
process: {env: {}},
2829
}));

lib/Draggable.js

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {createCSSTransform, createSVGTransform} from './utils/domFns';
77
import {canDragX, canDragY, createDraggableData, getBoundPosition} from './utils/positionFns';
88
import {dontSetMe} from './utils/shims';
99
import DraggableCore from './DraggableCore';
10-
import type {ControlPosition, PositionOffsetControlPosition, DraggableCoreProps} from './DraggableCore';
10+
import type {ControlPosition, PositionOffsetControlPosition, DraggableCoreProps, DraggableCoreDefaultProps} from './DraggableCore';
1111
import log from './utils/log';
1212
import type {Bounds, DraggableEventHandler} from './utils/types';
1313
import type {Element as ReactElement} from 'react';
@@ -21,18 +21,22 @@ type DraggableState = {
2121
prevPropsPosition: ?ControlPosition,
2222
};
2323

24-
export type DraggableProps = {
25-
...$Exact<DraggableCoreProps>,
24+
export type DraggableDefaultProps = {
25+
...DraggableCoreDefaultProps,
2626
axis: 'both' | 'x' | 'y' | 'none',
2727
bounds: Bounds | string | false,
2828
defaultClassName: string,
2929
defaultClassNameDragging: string,
3030
defaultClassNameDragged: string,
3131
defaultPosition: ControlPosition,
32-
nodeRef?: ?React.ElementRef<any>,
32+
scale: number,
33+
};
34+
35+
export type DraggableProps = {
36+
...DraggableCoreProps,
37+
...DraggableDefaultProps,
3338
positionOffset: PositionOffsetControlPosition,
3439
position: ControlPosition,
35-
scale: number
3640
};
3741

3842
//
@@ -41,7 +45,7 @@ export type DraggableProps = {
4145

4246
class Draggable extends React.Component<DraggableProps, DraggableState> {
4347

44-
static displayName = 'Draggable';
48+
static displayName: ?string = 'Draggable';
4549

4650
static propTypes = {
4751
// Accepts all props <DraggableCore> accepts.
@@ -162,32 +166,31 @@ class Draggable extends React.Component<DraggableProps, DraggableState> {
162166
transform: dontSetMe
163167
};
164168

165-
static defaultProps = {
169+
static defaultProps: DraggableDefaultProps = {
166170
...DraggableCore.defaultProps,
167171
axis: 'both',
168172
bounds: false,
169173
defaultClassName: 'react-draggable',
170174
defaultClassNameDragging: 'react-draggable-dragging',
171175
defaultClassNameDragged: 'react-draggable-dragged',
172176
defaultPosition: {x: 0, y: 0},
173-
position: null,
174177
scale: 1
175178
};
176179

177180
// React 16.3+
178181
// Arity (props, state)
179-
static getDerivedStateFromProps({position}: DraggableProps, {prevPropsPosition}: DraggableState) {
182+
static getDerivedStateFromProps({position}: DraggableProps, {prevPropsPosition}: DraggableState): ?$Shape<DraggableState> {
180183
// Set x/y if a new position is provided in props that is different than the previous.
181184
if (
182185
position &&
183-
(!prevPropsPosition ||
186+
(!prevPropsPosition ||
184187
position.x !== prevPropsPosition.x || position.y !== prevPropsPosition.y
185188
)
186189
) {
187190
log('Draggable: getDerivedStateFromProps %j', {position, prevPropsPosition});
188191
return {
189-
x: position.x,
190-
y: position.y,
192+
x: position.x,
193+
y: position.y,
191194
prevPropsPosition: {...position}
192195
};
193196
}
@@ -239,7 +242,7 @@ class Draggable extends React.Component<DraggableProps, DraggableState> {
239242
// React Strict Mode compatibility: if `nodeRef` is passed, we will use it instead of trying to find
240243
// the underlying DOM node ourselves. See the README for more information.
241244
findDOMNode(): ?HTMLElement {
242-
return this.props.nodeRef ? this.props.nodeRef.current : ReactDOM.findDOMNode(this);
245+
return this.props?.nodeRef?.current ?? ReactDOM.findDOMNode(this);
243246
}
244247

245248
onDragStart: DraggableEventHandler = (e, coreData) => {

lib/DraggableCore.js

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -42,28 +42,32 @@ export type DraggableData = {
4242
lastX: number, lastY: number,
4343
};
4444

45-
export type DraggableEventHandler = (e: MouseEvent, data: DraggableData) => void;
45+
export type DraggableEventHandler = (e: MouseEvent, data: DraggableData) => void | false;
4646

4747
export type ControlPosition = {x: number, y: number};
4848
export type PositionOffsetControlPosition = {x: number|string, y: number|string};
4949

50-
export type DraggableCoreProps = {
50+
export type DraggableCoreDefaultProps = {
5151
allowAnyClick: boolean,
52-
cancel: string,
53-
children: ReactElement<any>,
5452
disabled: boolean,
5553
enableUserSelectHack: boolean,
56-
offsetParent: HTMLElement,
57-
grid: [number, number],
58-
handle: string,
59-
nodeRef?: ?React.ElementRef<any>,
6054
onStart: DraggableEventHandler,
6155
onDrag: DraggableEventHandler,
6256
onStop: DraggableEventHandler,
6357
onMouseDown: (e: MouseEvent) => void,
6458
scale: number,
6559
};
6660

61+
export type DraggableCoreProps = {
62+
...DraggableCoreDefaultProps,
63+
cancel: string,
64+
children: ReactElement<any>,
65+
offsetParent: HTMLElement,
66+
grid: [number, number],
67+
handle: string,
68+
nodeRef?: ?React.ElementRef<any>,
69+
};
70+
6771
//
6872
// Define <DraggableCore>.
6973
//
@@ -73,7 +77,7 @@ export type DraggableCoreProps = {
7377

7478
export default class DraggableCore extends React.Component<DraggableCoreProps, DraggableCoreState> {
7579

76-
static displayName = 'DraggableCore';
80+
static displayName: ?string = 'DraggableCore';
7781

7882
static propTypes = {
7983
/**
@@ -111,7 +115,7 @@ export default class DraggableCore extends React.Component<DraggableCoreProps, D
111115
* `grid` specifies the x and y that dragging should snap to.
112116
*/
113117
grid: PropTypes.arrayOf(PropTypes.number),
114-
118+
115119
/**
116120
* `handle` specifies a selector to be used as the handle that initiates drag.
117121
*
@@ -212,30 +216,25 @@ export default class DraggableCore extends React.Component<DraggableCoreProps, D
212216
transform: dontSetMe
213217
};
214218

215-
static defaultProps = {
219+
static defaultProps: DraggableCoreDefaultProps = {
216220
allowAnyClick: false, // by default only accept left click
217-
cancel: null,
218221
disabled: false,
219222
enableUserSelectHack: true,
220-
offsetParent: null,
221-
handle: null,
222-
grid: null,
223-
transform: null,
224223
onStart: function(){},
225224
onDrag: function(){},
226225
onStop: function(){},
227226
onMouseDown: function(){},
228227
scale: 1,
229228
};
230229

231-
state = {
230+
state: DraggableCoreState = {
232231
dragging: false,
233232
// Used while dragging to determine deltas.
234233
lastX: NaN, lastY: NaN,
235234
touchIdentifier: null
236235
};
237236

238-
mounted = false;
237+
mounted: boolean = false;
239238

240239
componentDidMount() {
241240
this.mounted = true;
@@ -266,7 +265,7 @@ export default class DraggableCore extends React.Component<DraggableCoreProps, D
266265
// React Strict Mode compatibility: if `nodeRef` is passed, we will use it instead of trying to find
267266
// the underlying DOM node ourselves. See the README for more information.
268267
findDOMNode(): ?HTMLElement {
269-
return this.props.nodeRef ? this.props.nodeRef.current : ReactDOM.findDOMNode(this);
268+
return this.props?.nodeRef?.current ?? ReactDOM.findDOMNode(this);
270269
}
271270

272271
handleDragStart: EventHandler<MouseTouchEvent> = (e) => {
@@ -441,7 +440,7 @@ export default class DraggableCore extends React.Component<DraggableCoreProps, D
441440
return this.handleDragStop(e);
442441
};
443442

444-
render() {
443+
render(): React.Element<any> {
445444
// Reuse the child provided
446445
// This makes it flexible to use whatever element is wanted (div, ul, etc)
447446
return React.cloneElement(React.Children.only(this.props.children), {
@@ -450,7 +449,7 @@ export default class DraggableCore extends React.Component<DraggableCoreProps, D
450449
onMouseDown: this.onMouseDown,
451450
onMouseUp: this.onMouseUp,
452451
// onTouchStart is added on `componentDidMount` so they can be added with
453-
// {passive: false}, which allows it to cancel. See
452+
// {passive: false}, which allows it to cancel. See
454453
// https://developers.google.com/web/updates/2017/01/scrolling-intervention
455454
onTouchEnd: this.onTouchEnd
456455
});

lib/utils/domFns.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ export function innerWidth(node: HTMLElement): number {
101101
}
102102

103103
// Get from offsetParent
104-
export function offsetXYFromParent(evt: {clientX: number, clientY: number}, offsetParent: HTMLElement, scale: number): ControlPosition {
104+
export function offsetXYFromParent(evt: {clientX: number, clientY: number, ...}, offsetParent: HTMLElement, scale: number): ControlPosition {
105105
const isBody = offsetParent === offsetParent.ownerDocument.body;
106106
const offsetParentRect = isBody ? {left: 0, top: 0} : offsetParent.getBoundingClientRect();
107107

lib/utils/getPrefix.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@ function kebabToTitleCase(str: string): string {
4444
// Default export is the prefix itself, like 'Moz', 'Webkit', etc
4545
// Note that you may have to re-test for certain things; for instance, Chrome 50
4646
// can handle unprefixed `transform`, but not unprefixed `user-select`
47-
export default getPrefix();
47+
export default (getPrefix(): string);

lib/utils/positionFns.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,16 @@ export function getBoundPosition(draggable: Draggable, x: number, y: number): [n
2727
if (!(boundNode instanceof ownerWindow.HTMLElement)) {
2828
throw new Error('Bounds selector "' + bounds + '" could not find an element.');
2929
}
30+
const boundNodeEl: HTMLElement = boundNode; // for Flow, can't seem to refine correctly
3031
const nodeStyle = ownerWindow.getComputedStyle(node);
31-
const boundNodeStyle = ownerWindow.getComputedStyle(boundNode);
32+
const boundNodeStyle = ownerWindow.getComputedStyle(boundNodeEl);
3233
// Compute bounds. This is a pain with padding and offsets but this gets it exactly right.
3334
bounds = {
3435
left: -node.offsetLeft + int(boundNodeStyle.paddingLeft) + int(nodeStyle.marginLeft),
3536
top: -node.offsetTop + int(boundNodeStyle.paddingTop) + int(nodeStyle.marginTop),
36-
right: innerWidth(boundNode) - outerWidth(node) - node.offsetLeft +
37+
right: innerWidth(boundNodeEl) - outerWidth(node) - node.offsetLeft +
3738
int(boundNodeStyle.paddingRight) - int(nodeStyle.marginRight),
38-
bottom: innerHeight(boundNode) - outerHeight(node) - node.offsetTop +
39+
bottom: innerHeight(boundNodeEl) - outerHeight(node) - node.offsetTop +
3940
int(boundNodeStyle.paddingBottom) - int(nodeStyle.marginBottom)
4041
};
4142
}

lib/utils/shims.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function int(a: string): number {
1818
return parseInt(a, 10);
1919
}
2020

21-
export function dontSetMe(props: Object, propName: string, componentName: string) {
21+
export function dontSetMe(props: Object, propName: string, componentName: string): ?Error {
2222
if (props[propName]) {
2323
return new Error(`Invalid prop ${propName} passed to ${componentName} - do not set this, set it on the child.`);
2424
}

package.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@
3939
},
4040
"homepage": "https://github.com/mzabriskie/react-draggable",
4141
"devDependencies": {
42-
"@babel/cli": "^7.8.4",
43-
"@babel/core": "^7.9.6",
42+
"@babel/cli": "^7.13.10",
43+
"@babel/core": "^7.13.10",
4444
"@babel/plugin-proposal-class-properties": "^7.8.3",
4545
"@babel/plugin-transform-flow-comments": "^7.8.3",
46-
"@babel/preset-env": "^7.9.6",
46+
"@babel/preset-env": "^7.13.12",
4747
"@babel/preset-flow": "^7.9.0",
4848
"@babel/preset-react": "^7.9.4",
4949
"@types/react": "^16.9.35",
@@ -52,11 +52,11 @@
5252
"babel-eslint": "^10.1.0",
5353
"babel-loader": "^8.1.0",
5454
"babel-plugin-transform-inline-environment-variables": "^0.4.3",
55-
"eslint": "^7.0.0",
55+
"eslint": "^7.22.0",
5656
"eslint-plugin-react": "^7.20.0",
57-
"flow-bin": "^0.125.1",
58-
"jasmine-core": "^3.5.0",
59-
"karma": "^6.1.1",
57+
"flow-bin": "^0.147.0",
58+
"jasmine-core": "^3.7.1",
59+
"karma": "^6.2.0",
6060
"karma-chrome-launcher": "^3.1.0",
6161
"karma-cli": "2.0.0",
6262
"karma-firefox-launcher": "^2.1.0",
@@ -77,7 +77,7 @@
7777
"semver": "^7.3.2",
7878
"static-server": "^3.0.0",
7979
"typescript": "^3.9.3",
80-
"webpack": "^5.24.3",
80+
"webpack": "^5.27.2",
8181
"webpack-cli": "^4.5.0",
8282
"webpack-dev-server": "^3.11.0"
8383
},

0 commit comments

Comments
 (0)