@pie-lib/plot 4.0.21 → 4.0.22-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +0 -79
- package/lib/__tests__/draggable.test.js +48 -0
- package/lib/__tests__/grid-draggable-drag-end.test.js +168 -0
- package/lib/__tests__/grid-draggable.test.js +738 -0
- package/lib/__tests__/root.test.js +285 -0
- package/lib/__tests__/trig.test.js +168 -0
- package/lib/__tests__/utils.test.js +296 -0
- package/lib/draggable.js +28 -8
- package/lib/draggable.js.map +1 -1
- package/lib/grid-draggable.js +3 -12
- package/lib/grid-draggable.js.map +1 -1
- package/package.json +7 -7
- package/src/__tests__/draggable.test.jsx +23 -20
- package/src/draggable.jsx +7 -8
- package/src/grid-draggable.jsx +3 -9
- package/LICENSE.md +0 -5
- package/src/__tests__/grid-draggable-drag-end.test.jsx +0 -97
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { render } from '@testing-library/react';
|
|
3
|
-
import
|
|
4
|
-
import Draggable, { DraggableCore } from '../draggable';
|
|
3
|
+
import Draggable from '../draggable';
|
|
5
4
|
|
|
6
5
|
describe('draggable', () => {
|
|
7
6
|
it('renders with children', () => {
|
|
@@ -13,26 +12,30 @@ describe('draggable', () => {
|
|
|
13
12
|
expect(container.firstChild).toBeInTheDocument();
|
|
14
13
|
});
|
|
15
14
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
<div data-testid="draggable-child">content</div>
|
|
25
|
-
</Draggable>
|
|
26
|
-
);
|
|
15
|
+
describe('local', () => {
|
|
16
|
+
it('resets position state when receiving new props', () => {
|
|
17
|
+
// Render with initial props
|
|
18
|
+
const { rerender, container } = render(
|
|
19
|
+
<Draggable position={{ x: 100, y: 100 }}>
|
|
20
|
+
<div data-testid="draggable-child">content</div>
|
|
21
|
+
</Draggable>,
|
|
22
|
+
);
|
|
27
23
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
expect(child.style.transform).toBe('translate(100px,100px)');
|
|
24
|
+
// Verify initial render
|
|
25
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
31
26
|
|
|
32
|
-
|
|
33
|
-
|
|
27
|
+
// Update props - this triggers componentWillReceiveProps
|
|
28
|
+
// which should reset internal x/y state to 0
|
|
29
|
+
rerender(
|
|
30
|
+
<Draggable position={{ x: 200, y: 200 }}>
|
|
31
|
+
<div data-testid="draggable-child">content</div>
|
|
32
|
+
</Draggable>,
|
|
33
|
+
);
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
// The component should still render correctly after prop change
|
|
36
|
+
// The internal state reset is tested by ensuring no errors occur
|
|
37
|
+
// and the component continues to function properly
|
|
38
|
+
expect(container.firstChild).toBeInTheDocument();
|
|
39
|
+
});
|
|
37
40
|
});
|
|
38
41
|
});
|
package/src/draggable.jsx
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import Draggable, { DraggableCore } from 'react-draggable';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
export default Draggable;
|
|
3
|
+
export default class LocalDraggable extends Draggable {
|
|
4
|
+
componentWillReceiveProps(next) {
|
|
5
|
+
super.componentWillReceiveProps(next);
|
|
6
|
+
//Remove the x/y state as these values have now been updated and will come through as props.
|
|
7
|
+
this.setState({ x: 0, y: 0 });
|
|
8
|
+
}
|
|
9
|
+
}
|
|
11
10
|
|
|
12
11
|
export { DraggableCore };
|
package/src/grid-draggable.jsx
CHANGED
|
@@ -252,13 +252,6 @@ export const gridDraggable = (opts) => (Comp) => {
|
|
|
252
252
|
return opts.fromDelta(this.props, delta);
|
|
253
253
|
};
|
|
254
254
|
|
|
255
|
-
/**
|
|
256
|
-
* Must not return false. react-draggable v4 treats a false return as "keep dragging"
|
|
257
|
-
* and bails out of handleDragStop before it detaches the document mousemove/mouseup
|
|
258
|
-
* listeners, so the handle would keep following the pointer after release - and every
|
|
259
|
-
* previously dragged handle would move along with the next one. (v3 ignored the
|
|
260
|
-
* return value and always detached, which is why returning false used to look inert.)
|
|
261
|
-
*/
|
|
262
255
|
onStop = (e, dd) => {
|
|
263
256
|
log('[onStop] dd:', dd);
|
|
264
257
|
const { onDragStop, onClick, disabled } = this.props;
|
|
@@ -297,11 +290,12 @@ export const gridDraggable = (opts) => (Comp) => {
|
|
|
297
290
|
}
|
|
298
291
|
}
|
|
299
292
|
|
|
300
|
-
|
|
301
|
-
return;
|
|
293
|
+
return false;
|
|
302
294
|
}
|
|
303
295
|
|
|
304
296
|
this.setState({ startX: null, startY: null });
|
|
297
|
+
// return false to prevent state updates in the underlying draggable - a move will have triggered an update already.
|
|
298
|
+
return false;
|
|
305
299
|
};
|
|
306
300
|
|
|
307
301
|
render() {
|
package/LICENSE.md
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
Copyright 2019 CoreSpring Inc
|
|
2
|
-
|
|
3
|
-
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
|
|
4
|
-
|
|
5
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { fireEvent, render } from '@testing-library/react';
|
|
3
|
-
import { scaleLinear } from 'd3-scale';
|
|
4
|
-
import { gridDraggable } from '../grid-draggable';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* react-draggable v4 honours the value returned from DraggableCore's `onStop` and bails
|
|
8
|
-
* out of handleDragStop before it detaches the document mousemove/mouseup listeners.
|
|
9
|
-
* v3 ignored that return value and always detached them. If gridDraggable's onStop
|
|
10
|
-
* returns false, every dragged handle stays subscribed to document mousemove forever,
|
|
11
|
-
* so later pointer movement keeps dragging marks that the user is no longer holding.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
const Handle = ({ onMouseDown, onMouseUp, onTouchStart, onTouchEnd, style, testid }) => (
|
|
15
|
-
<div
|
|
16
|
-
data-testid={testid}
|
|
17
|
-
onMouseDown={onMouseDown}
|
|
18
|
-
onMouseUp={onMouseUp}
|
|
19
|
-
onTouchStart={onTouchStart}
|
|
20
|
-
onTouchEnd={onTouchEnd}
|
|
21
|
-
style={style}
|
|
22
|
-
/>
|
|
23
|
-
);
|
|
24
|
-
|
|
25
|
-
const Draggable = gridDraggable({
|
|
26
|
-
anchorPoint: (props) => ({ x: props.x, y: props.y }),
|
|
27
|
-
fromDelta: (props, delta) => ({ x: props.x + delta.x, y: props.y + delta.y }),
|
|
28
|
-
bounds: () => ({ left: -1000, right: 1000, top: -1000, bottom: 1000 }),
|
|
29
|
-
})(Handle);
|
|
30
|
-
|
|
31
|
-
const graphProps = (rootNode) => ({
|
|
32
|
-
scale: {
|
|
33
|
-
x: scaleLinear().domain([0, 10]).range([0, 400]),
|
|
34
|
-
y: scaleLinear().domain([0, 10]).range([400, 0]),
|
|
35
|
-
},
|
|
36
|
-
snap: { x: (n) => n, y: (n) => n },
|
|
37
|
-
domain: { min: 0, max: 10, step: 1 },
|
|
38
|
-
range: { min: 0, max: 10, step: 1 },
|
|
39
|
-
size: { width: 400, height: 400 },
|
|
40
|
-
getRootNode: () => rootNode,
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
// grid() resolves to [40, -40] for these scales, so a move must clear 20px to register.
|
|
44
|
-
const drag = (node, to) => {
|
|
45
|
-
fireEvent.mouseDown(node, { clientX: 0, clientY: 0, button: 0 });
|
|
46
|
-
fireEvent.mouseMove(document, { clientX: to, clientY: 0 });
|
|
47
|
-
fireEvent.mouseUp(document, { clientX: to, clientY: 0 });
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
describe('gridDraggable drag end', () => {
|
|
51
|
-
let root;
|
|
52
|
-
|
|
53
|
-
beforeEach(() => {
|
|
54
|
-
root = document.createElement('div');
|
|
55
|
-
document.body.appendChild(root);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
afterEach(() => {
|
|
59
|
-
document.body.removeChild(root);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it('stops dragging a handle once the mouse is released', () => {
|
|
63
|
-
const onDrag = jest.fn();
|
|
64
|
-
const { getByTestId } = render(
|
|
65
|
-
<Draggable testid="a" x={2} y={2} graphProps={graphProps(root)} onDrag={onDrag} />,
|
|
66
|
-
);
|
|
67
|
-
|
|
68
|
-
drag(getByTestId('a'), 40);
|
|
69
|
-
expect(onDrag).toHaveBeenCalled();
|
|
70
|
-
|
|
71
|
-
const callsAtRelease = onDrag.mock.calls.length;
|
|
72
|
-
fireEvent.mouseMove(document, { clientX: 240, clientY: 120 });
|
|
73
|
-
expect(onDrag).toHaveBeenCalledTimes(callsAtRelease);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it('does not drag a previously released handle when another one is dragged', () => {
|
|
77
|
-
const onDragA = jest.fn();
|
|
78
|
-
const onDragB = jest.fn();
|
|
79
|
-
const { getByTestId } = render(
|
|
80
|
-
<>
|
|
81
|
-
<Draggable testid="a" x={2} y={2} graphProps={graphProps(root)} onDrag={onDragA} />
|
|
82
|
-
<Draggable testid="b" x={6} y={6} graphProps={graphProps(root)} onDragB onDrag={onDragB} />
|
|
83
|
-
</>,
|
|
84
|
-
);
|
|
85
|
-
|
|
86
|
-
drag(getByTestId('a'), 40);
|
|
87
|
-
expect(onDragA).toHaveBeenCalled();
|
|
88
|
-
onDragA.mockClear();
|
|
89
|
-
|
|
90
|
-
// Now drag b. a has been released, so it must not move with it.
|
|
91
|
-
fireEvent.mouseDown(getByTestId('b'), { clientX: 0, clientY: 0, button: 0 });
|
|
92
|
-
fireEvent.mouseMove(document, { clientX: 80, clientY: 0 });
|
|
93
|
-
|
|
94
|
-
expect(onDragB).toHaveBeenCalled();
|
|
95
|
-
expect(onDragA).not.toHaveBeenCalled();
|
|
96
|
-
});
|
|
97
|
-
});
|