Skip to content

Commit 5aeeef4

Browse files
authored
Update deps (#782)
* update deps * env: Add workflow * chore: format * fix: callback position when dragAxis specified * fix: ci * fix: spec * fix: callback data * update deps * fix:ci * update deps * remove circleci
1 parent 0d71c71 commit 5aeeef4

17 files changed

+3867
-3791
lines changed

.circleci/config.yml

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

.github/workflows/ci.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Continuous Integration
2+
on: [push, pull_request]
3+
4+
jobs:
5+
lint:
6+
runs-on: ubuntu-18.04
7+
steps:
8+
- uses: actions/checkout@master
9+
- uses: actions/setup-node@master
10+
with:
11+
node-version: 12
12+
- name: yarn
13+
run: yarn --frozen-lockfile
14+
- name: lint
15+
run: yarn lint
16+
17+
tsc:
18+
runs-on: ubuntu-18.04
19+
steps:
20+
- uses: actions/checkout@master
21+
- uses: actions/setup-node@master
22+
with:
23+
node-version: 12
24+
- name: yarn
25+
run: yarn --frozen-lockfile
26+
- name: tsc
27+
run: yarn tsc
28+
29+
test:
30+
runs-on: ubuntu-18.04
31+
steps:
32+
- uses: actions/checkout@master
33+
- uses: actions/setup-node@master
34+
with:
35+
node-version: 12
36+
- name: yarn
37+
run: yarn --frozen-lockfile
38+
- name: test
39+
run: |
40+
export DISPLAY=:99
41+
Xvfb -ac :99 -screen 0 1280x1024x24 >/dev/null 2>&1 &
42+
yarn run test

package.json

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,28 +40,28 @@
4040
},
4141
"homepage": "https://github.com/bokuweb/react-rnd",
4242
"devDependencies": {
43-
"@babel/cli": "7.12.8",
44-
"@babel/core": "7.12.9",
45-
"@babel/plugin-proposal-class-properties": "7.12.1",
46-
"@babel/plugin-transform-modules-commonjs": "7.12.1",
47-
"@babel/preset-react": "7.12.7",
48-
"@babel/preset-typescript": "7.12.7",
49-
"@babel/traverse": "7.12.9",
50-
"@babel/types": "7.12.7",
51-
"@emotion/core": "10.0.28",
52-
"@storybook/addon-actions": "5.3.18",
53-
"@storybook/addon-info": "5.3.18",
54-
"@storybook/addon-links": "5.3.18",
55-
"@storybook/addon-options": "5.3.18",
56-
"@storybook/react": "5.3.18",
43+
"@babel/cli": "7.14.3",
44+
"@babel/core": "7.14.3",
45+
"@babel/plugin-proposal-class-properties": "7.13.0",
46+
"@babel/plugin-transform-modules-commonjs": "7.14.0",
47+
"@babel/preset-react": "7.13.13",
48+
"@babel/preset-typescript": "7.13.0",
49+
"@babel/traverse": "7.14.2",
50+
"@babel/types": "7.14.2",
51+
"@emotion/core": "11.0.0",
52+
"@storybook/addon-actions": "6.2.9",
53+
"@storybook/addon-info": "5.3.21",
54+
"@storybook/addon-links": "6.2.9",
55+
"@storybook/addon-options": "5.3.21",
56+
"@storybook/react": "6.2.9",
5757
"@types/enzyme": "3.1.16",
5858
"@types/enzyme-adapter-react-16": "1.0.6",
59-
"@types/node": "^12.0.10",
59+
"@types/node": "^15.3.1",
6060
"@types/react": "16.4.1",
6161
"@types/react-dom": "16.0.11",
6262
"@types/sinon": "9.0.0",
63-
"@types/storybook__addon-actions": "3.4.3",
64-
"@types/storybook__react": "4.0.2",
63+
"@types/storybook__addon-actions": "5.2.1",
64+
"@types/storybook__react": "5.2.1",
6565
"avaron": "0.2.0",
6666
"babel-core": "7.0.0-bridge.0",
6767
"babel-eslint": "10.1.0",
@@ -73,7 +73,7 @@
7373
"gh-pages": "2.2.0",
7474
"light-ts-loader": "1.1.2",
7575
"npm-run-all": "4.1.5",
76-
"prettier": "2.0.4",
76+
"prettier": "2.3.0",
7777
"react": "16.14.0",
7878
"react-dom": "16.14.0",
7979
"react-test-renderer": "16.14.0",
@@ -90,7 +90,7 @@
9090
"tslint-eslint-rules": "5.4.0",
9191
"tslint-plugin-prettier": "2.3.0",
9292
"tslint-react": "5.0.0",
93-
"typescript": "3.8.3"
93+
"typescript": "4.2.4"
9494
},
9595
"files": [
9696
"lib"
@@ -101,6 +101,6 @@
101101
"dependencies": {
102102
"re-resizable": "6.9.0",
103103
"react-draggable": "4.4.3",
104-
"tslib": "2.0.3"
104+
"tslib": "2.2.0"
105105
}
106106
}

src/index.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ test("should dragging disabled when axis equals none", async (t) => {
160160
});
161161
rnd.find("div").at(0).simulate("mousedown", { clientX: 0, clientY: 0 });
162162
mouseMove(200, 220);
163-
t.is(onDrag.callCount, 1);
163+
t.is(onDrag.callCount, 0);
164164
t.not((rnd.getDOMNode().getAttribute("style") || "").indexOf("transform: translate(100px, 100px)"), -1);
165165
});
166166

src/index.tsx

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ type Size = {
5555
};
5656

5757
type State = {
58-
original: Position;
5958
bounds: {
6059
top: number;
6160
right: number;
@@ -214,14 +213,11 @@ export class Rnd extends React.PureComponent<Props, State> {
214213
resizingPosition = { x: 0, y: 0 };
215214
offsetFromParent = { left: 0, top: 0 };
216215
resizableElement: { current: HTMLElement | null } = { current: null };
216+
originalPosition = { x: 0, y: 0 };
217217

218218
constructor(props: Props) {
219219
super(props);
220220
this.state = {
221-
original: {
222-
x: 0,
223-
y: 0,
224-
},
225221
bounds: {
226222
top: 0,
227223
right: 0,
@@ -305,6 +301,8 @@ export class Rnd extends React.PureComponent<Props, State> {
305301
if (this.props.onDragStart) {
306302
this.props.onDragStart(e, data);
307303
}
304+
const pos = this.getDraggablePosition();
305+
this.originalPosition = pos;
308306
if (!this.props.bounds) return;
309307
const parent = this.getParent();
310308
const scale = this.props.scale as number;
@@ -359,16 +357,26 @@ export class Rnd extends React.PureComponent<Props, State> {
359357
}
360358

361359
onDrag(e: RndDragEvent, data: DraggableData) {
362-
if (this.props.onDrag) {
363-
const offset = this.offsetFromParent;
364-
return this.props.onDrag(e, { ...data, x: data.x - offset.left, y: data.y - offset.top });
360+
if (!this.props.onDrag) return;
361+
const { left, top } = this.offsetFromParent;
362+
if (!this.props.dragAxis || this.props.dragAxis === "both") {
363+
return this.props.onDrag(e, { ...data, x: data.x - left, y: data.y - top });
364+
} else if (this.props.dragAxis === "x") {
365+
return this.props.onDrag(e, { ...data, x: data.x + left, y: this.originalPosition.y + top, deltaY: 0 });
366+
} else if (this.props.dragAxis === "y") {
367+
return this.props.onDrag(e, { ...data, x: this.originalPosition.x + left, y: data.y + top, deltaX: 0 });
365368
}
366369
}
367370

368371
onDragStop(e: RndDragEvent, data: DraggableData) {
369-
if (this.props.onDragStop) {
370-
const { left, top } = this.offsetFromParent;
372+
if (!this.props.onDragStop) return;
373+
const { left, top } = this.offsetFromParent;
374+
if (!this.props.dragAxis || this.props.dragAxis === "both") {
371375
return this.props.onDragStop(e, { ...data, x: data.x + left, y: data.y + top });
376+
} else if (this.props.dragAxis === "x") {
377+
return this.props.onDragStop(e, { ...data, x: data.x + left, y: this.originalPosition.y + top, deltaY: 0 });
378+
} else if (this.props.dragAxis === "y") {
379+
return this.props.onDragStop(e, { ...data, x: this.originalPosition.x + left, y: data.y + top, deltaX: 0 });
372380
}
373381
}
374382

@@ -384,9 +392,7 @@ export class Rnd extends React.PureComponent<Props, State> {
384392
const offset = this.offsetFromParent;
385393
const pos = this.getDraggablePosition();
386394
this.resizingPosition = { x: pos.x + offset.left, y: pos.y + offset.top };
387-
this.setState({
388-
original: pos,
389-
});
395+
this.originalPosition = pos;
390396
if (this.props.bounds) {
391397
const parent = this.getParent();
392398
let boundary;
@@ -477,7 +483,7 @@ export class Rnd extends React.PureComponent<Props, State> {
477483
delta: { height: number; width: number },
478484
) {
479485
// INFO: Apply x and y position adjustments caused by resizing to draggable
480-
const newPos = { x: this.state.original.x, y: this.state.original.y };
486+
const newPos = { x: this.originalPosition.x, y: this.originalPosition.y };
481487
const left = -delta.width;
482488
const top = -delta.height;
483489
const directions = ["top", "left", "topLeft", "bottomLeft", "topRight"];

stories/basic/controlled.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export default class Example extends React.Component<{}, State> {
3939
this.setState({
4040
width: ref.offsetWidth,
4141
height: ref.offsetHeight,
42-
...position
42+
...position,
4343
});
4444
}}
4545
>

stories/basic/multi-controlled.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default class Example extends React.Component<{}, State> {
1515
constructor(props) {
1616
super(props);
1717
this.state = {
18-
rnds: [0, 1, 2].map(i => ({
18+
rnds: [0, 1, 2].map((i) => ({
1919
width: 200,
2020
height: 200,
2121
x: i * 100,
@@ -27,7 +27,7 @@ export default class Example extends React.Component<{}, State> {
2727
render() {
2828
return (
2929
<>
30-
{[0, 1, 2].map(i => (
30+
{[0, 1, 2].map((i) => (
3131
<Rnd
3232
key={`rnd${i}`}
3333
style={style}

stories/basic/multi-uncontrolled.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { style } from "../styles";
44

55
export default () => (
66
<>
7-
{[0, 1, 2].map(i => (
7+
{[0, 1, 2].map((i) => (
88
<Rnd
99
style={{
1010
...style,

stories/customization/resizeHandleComponent.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const SouthEastArrow = () => (
88
</svg>
99
);
1010

11-
const CustomHandle = props => (
11+
const CustomHandle = (props) => (
1212
<div
1313
style={{
1414
background: "#fff",

0 commit comments

Comments
 (0)