Skip to content

Commit 8bcf985

Browse files
authored
Merge pull request #201 from foxglove/jacob/update-dependencies
Upgrade dependencies
2 parents 9434f10 + 4dfd3e3 commit 8bcf985

9 files changed

+1843
-4085
lines changed

package.json

+21-24
Original file line numberDiff line numberDiff line change
@@ -44,63 +44,60 @@
4444
"immutability-helper": "^3.1.1",
4545
"lodash": "^4.17.21",
4646
"prop-types": "^15.8.1",
47-
"react-dnd": "^14.0.5",
48-
"react-dnd-html5-backend": "^14.1.0",
49-
"react-dnd-multi-backend": "^6.0.2",
50-
"react-dnd-touch-backend": "^14.1.1",
51-
"uuid": "^3.4.0"
47+
"rdndmb-html5-to-touch": "^8.0.0",
48+
"react-dnd": "^16.0.1",
49+
"react-dnd-html5-backend": "^16.0.1",
50+
"react-dnd-multi-backend": "^8.0.0",
51+
"react-dnd-touch-backend": "^16.0.1",
52+
"uuid": "^9.0.0"
5253
},
5354
"devDependencies": {
5455
"@blueprintjs/core": "^4.7.0",
5556
"@blueprintjs/icons": "^4.4.0",
5657
"@types/chai": "^4.3.0",
5758
"@types/classnames": "^2.3.1",
5859
"@types/dom4": "^2.0.2",
59-
"@types/html-webpack-plugin": "2.30.2",
6060
"@types/lodash": "^4.14.180",
6161
"@types/mocha": "^5.2.7",
6262
"@types/prop-types": "^15.7.4",
6363
"@types/react": "^18.0.15",
64-
"@types/react-dnd-multi-backend": "^6.0.1",
6564
"@types/react-dom": "^18.0.6",
66-
"@types/react-hot-loader": "^3.0.6",
65+
"@types/react-hot-loader": "^4.1.1",
6766
"@types/uuid": "^3.4.10",
68-
"@types/webpack": "^3.8.21",
67+
"@types/webpack": "^5.28.0",
6968
"chai": "^4.3.6",
70-
"css-loader": "^0.28.11",
71-
"dnd-core": "14.0.1",
72-
"file-loader": "^1.1.11",
73-
"html-loader": "^0.5.5",
74-
"html-webpack-plugin": "^2.30.1",
69+
"css-loader": "^6.7.3",
70+
"dnd-core": "16.0.1",
71+
"file-loader": "^6.2.0",
72+
"html-loader": "^4.2.0",
73+
"html-webpack-plugin": "^5.5.0",
7574
"jsdom": "^15.2.1",
7675
"jsdom-global": "^3.0.2",
7776
"less": "^3.13.1",
78-
"less-loader": "^5.0.0",
77+
"less-loader": "^11.1.0",
7978
"less-plugin-autoprefix": "^2.0.0",
8079
"mocha": "^7.2.0",
8180
"mocha-junit-reporter": "^1.23.3",
8281
"npm-run-all": "^4.1.5",
8382
"prettier": "^2.6.1",
8483
"react": "^18.2.0",
8584
"react-dom": "^18.2.0",
86-
"react-hot-loader": "^3.1.3",
87-
"source-map-loader": "^0.2.4",
88-
"style-loader": "^0.20.3",
89-
"ts-loader": "^3.5.0",
85+
"react-hot-loader": "^4.13.1",
86+
"source-map-loader": "^4.0.1",
87+
"style-loader": "^3.3.1",
88+
"ts-loader": "^9.4.2",
9089
"ts-node": "^8.10.2",
9190
"tslint": "^6.1.3",
9291
"tslint-config-prettier": "^1.18.0",
9392
"tslint-plugin-prettier": "^2.3.0",
9493
"tslint-react": "^5.0.0",
9594
"typescript": "^4.6.3",
96-
"webpack": "^3.12.0",
97-
"webpack-dev-server": "^2.11.5",
95+
"webpack": "^5.75.0",
96+
"webpack-cli": "^5.0.1",
97+
"webpack-dev-server": "^4.11.1",
9898
"yarn-deduplicate": "^3.1.0"
9999
},
100100
"peerDependencies": {
101101
"react": "16 - 18"
102-
},
103-
"resolutions": {
104-
"dnd-core": "14.0.1"
105102
}
106103
}

src/Mosaic.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import { DragDropManager } from 'dnd-core';
33
import countBy from 'lodash/countBy';
44
import keys from 'lodash/keys';
55
import pickBy from 'lodash/pickBy';
6+
import { HTML5toTouch } from 'rdndmb-html5-to-touch';
67
import React from 'react';
78
import { DndProvider } from 'react-dnd';
8-
import MultiBackend from 'react-dnd-multi-backend';
9-
import HTML5ToTouch from 'react-dnd-multi-backend/dist/cjs/HTML5toTouch';
9+
import { MultiBackend } from 'react-dnd-multi-backend';
1010
import { v4 as uuid } from 'uuid';
1111

1212
import { MosaicContext, MosaicRootActions } from './contextTypes';
@@ -224,7 +224,7 @@ export class Mosaic<T extends MosaicKey = string> extends React.PureComponent<Mo
224224
return (
225225
<DndProvider
226226
backend={MultiBackend}
227-
options={HTML5ToTouch}
227+
options={HTML5toTouch}
228228
{...(this.props.dragAndDropManager && { manager: this.props.dragAndDropManager })}
229229
>
230230
<MosaicWithoutDragDropContext<T> {...this.props} />

src/MosaicDropTarget.tsx

+26-47
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import classNames from 'classnames';
2-
import React from 'react';
3-
import { ConnectDropTarget, DropTarget, DropTargetMonitor } from 'react-dnd';
2+
import React, { useContext } from 'react';
3+
import { useDrop } from 'react-dnd';
44

55
import { MosaicContext } from './contextTypes';
66
import { MosaicDragItem, MosaicDropData, MosaicDropTargetPosition } from './internalTypes';
@@ -11,49 +11,28 @@ export interface MosaicDropTargetProps {
1111
path: MosaicPath;
1212
}
1313

14-
interface DropTargetProps {
15-
connectDropTarget: ConnectDropTarget;
16-
isOver: boolean;
17-
draggedMosaicId: string | undefined;
14+
export function MosaicDropTarget({ path, position }: MosaicDropTargetProps) {
15+
const { mosaicId } = useContext(MosaicContext);
16+
const [{ isOver, draggedMosaicId }, connectDropTarget] = useDrop({
17+
accept: MosaicDragType.WINDOW,
18+
drop: (item: MosaicDragItem, _monitor): MosaicDropData => {
19+
if (mosaicId === (item || {}).mosaicId) {
20+
return { path, position };
21+
} else {
22+
return {};
23+
}
24+
},
25+
collect: (monitor) => ({
26+
isOver: monitor.isOver(),
27+
draggedMosaicId: (monitor.getItem() || {}).mosaicId,
28+
}),
29+
});
30+
return (
31+
<div
32+
ref={connectDropTarget}
33+
className={classNames('drop-target', position, {
34+
'drop-target-hover': isOver && draggedMosaicId === mosaicId,
35+
})}
36+
/>
37+
);
1838
}
19-
20-
type Props = MosaicDropTargetProps & DropTargetProps;
21-
22-
const dropTarget = {
23-
drop: (props: Props, monitor: DropTargetMonitor, component: MosaicDropTargetClass): MosaicDropData => {
24-
if (component.context.mosaicId === ((monitor.getItem() || {}) as MosaicDragItem).mosaicId) {
25-
return {
26-
path: props.path,
27-
position: props.position,
28-
};
29-
} else {
30-
return {};
31-
}
32-
},
33-
};
34-
35-
class MosaicDropTargetClass extends React.PureComponent<Props> {
36-
static contextType = MosaicContext;
37-
context!: MosaicContext<any>;
38-
39-
render() {
40-
const { position, isOver, connectDropTarget, draggedMosaicId } = this.props;
41-
return connectDropTarget(
42-
<div
43-
className={classNames('drop-target', position, {
44-
'drop-target-hover': isOver && draggedMosaicId === this.context.mosaicId,
45-
})}
46-
/>,
47-
);
48-
}
49-
}
50-
51-
export const MosaicDropTarget = DropTarget(
52-
MosaicDragType.WINDOW,
53-
dropTarget,
54-
(connect, monitor): DropTargetProps => ({
55-
connectDropTarget: connect.dropTarget(),
56-
isOver: monitor.isOver(),
57-
draggedMosaicId: ((monitor.getItem() || {}) as MosaicDragItem).mosaicId,
58-
}),
59-
)(MosaicDropTargetClass) as any as React.ComponentType<MosaicDropTargetProps>;

src/MosaicWindow.tsx

+70-76
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import dropRight from 'lodash/dropRight';
44
import isEmpty from 'lodash/isEmpty';
55
import isEqual from 'lodash/isEqual';
66
import values from 'lodash/values';
7-
import React from 'react';
7+
import React, { useContext } from 'react';
88
import {
99
ConnectDragPreview,
1010
ConnectDragSource,
1111
ConnectDropTarget,
12-
DragSource,
13-
DragSourceMonitor,
14-
DropTarget,
12+
DropTargetMonitor,
13+
useDrag,
14+
useDrop,
1515
} from 'react-dnd';
1616

1717
import { DEFAULT_CONTROLS_WITHOUT_CREATION, DEFAULT_CONTROLS_WITH_CREATION } from './buttons/defaultToolbarControls';
@@ -245,84 +245,78 @@ export class InternalMosaicWindow<T extends MosaicKey> extends React.Component<
245245
};
246246
}
247247

248-
const dragSource = {
249-
beginDrag: (
250-
props: InternalMosaicWindowProps<any>,
251-
_monitor: DragSourceMonitor,
252-
component: InternalMosaicWindow<any>,
253-
): MosaicDragItem => {
254-
if (props.onDragStart) {
255-
props.onDragStart();
256-
}
257-
// TODO: Actually just delete instead of hiding
258-
// The defer is necessary as the element must be present on start for HTML DnD to not cry
259-
const hideTimer = defer(() => component.context.mosaicActions.hide(component.props.path));
260-
return {
261-
mosaicId: component.context.mosaicId,
262-
hideTimer,
263-
};
264-
},
265-
endDrag: (
266-
props: InternalMosaicWindowProps<any>,
267-
monitor: DragSourceMonitor,
268-
component: InternalMosaicWindow<any>,
269-
) => {
270-
const { hideTimer } = monitor.getItem() as MosaicDragItem;
271-
// If the hide call hasn't happened yet, cancel it
272-
window.clearTimeout(hideTimer);
273-
274-
const ownPath = component.props.path;
275-
const dropResult: MosaicDropData = (monitor.getDropResult() || {}) as MosaicDropData;
276-
const { mosaicActions } = component.context;
277-
const { position, path: destinationPath } = dropResult;
278-
if (position != null && destinationPath != null && !isEqual(destinationPath, ownPath)) {
279-
mosaicActions.updateTree(createDragToUpdates(mosaicActions.getRoot(), ownPath, destinationPath, position));
280-
if (props.onDragEnd) {
281-
props.onDragEnd('drop');
248+
function ConnectedInternalMosaicWindow<T extends MosaicKey = string>(props: InternalMosaicWindowProps<T>) {
249+
const { mosaicActions, mosaicId } = useContext(MosaicContext);
250+
251+
const [, connectDragSource, connectDragPreview] = useDrag<MosaicDragItem>({
252+
type: MosaicDragType.WINDOW,
253+
item: (_monitor): MosaicDragItem | null => {
254+
if (props.onDragStart) {
255+
props.onDragStart();
282256
}
283-
} else {
284-
// TODO: restore node from captured state
285-
mosaicActions.updateTree([
286-
{
287-
path: dropRight(ownPath),
288-
spec: {
289-
splitPercentage: {
290-
$set: null,
257+
// TODO: Actually just delete instead of hiding
258+
// The defer is necessary as the element must be present on start for HTML DnD to not cry
259+
const hideTimer = defer(() => mosaicActions.hide(props.path));
260+
return {
261+
mosaicId: mosaicId,
262+
hideTimer,
263+
};
264+
},
265+
end: (item, monitor) => {
266+
const { hideTimer } = item;
267+
// If the hide call hasn't happened yet, cancel it
268+
window.clearTimeout(hideTimer);
269+
270+
const ownPath = props.path;
271+
const dropResult: MosaicDropData = (monitor.getDropResult() || {}) as MosaicDropData;
272+
const { position, path: destinationPath } = dropResult;
273+
if (position != null && destinationPath != null && !isEqual(destinationPath, ownPath)) {
274+
mosaicActions.updateTree(createDragToUpdates(mosaicActions.getRoot()!, ownPath, destinationPath, position));
275+
if (props.onDragEnd) {
276+
props.onDragEnd('drop');
277+
}
278+
} else {
279+
// TODO: restore node from captured state
280+
mosaicActions.updateTree([
281+
{
282+
path: dropRight(ownPath),
283+
spec: {
284+
splitPercentage: {
285+
$set: undefined,
286+
},
291287
},
292288
},
293-
},
294-
]);
295-
if (props.onDragEnd) {
296-
props.onDragEnd('reset');
289+
]);
290+
if (props.onDragEnd) {
291+
props.onDragEnd('reset');
292+
}
297293
}
298-
}
299-
},
300-
};
301-
302-
const dropTarget = {};
303-
304-
// Each step exported here just to keep react-hot-loader happy
305-
export const SourceConnectedInternalMosaicWindow = DragSource(
306-
MosaicDragType.WINDOW,
307-
dragSource,
308-
(connect, _monitor): InternalDragSourceProps => ({
309-
connectDragSource: connect.dragSource(),
310-
connectDragPreview: connect.dragPreview(),
311-
}),
312-
)(InternalMosaicWindow);
313-
314-
export const SourceDropConnectedInternalMosaicWindow = DropTarget(
315-
MosaicDragType.WINDOW,
316-
dropTarget,
317-
(connect, monitor): InternalDropTargetProps => ({
318-
connectDropTarget: connect.dropTarget(),
319-
isOver: monitor.isOver(),
320-
draggedMosaicId: ((monitor.getItem() || {}) as MosaicDragItem).mosaicId,
321-
}),
322-
)(SourceConnectedInternalMosaicWindow as any);
294+
},
295+
});
296+
297+
const [{ isOver, draggedMosaicId }, connectDropTarget] = useDrop({
298+
accept: MosaicDragType.WINDOW,
299+
collect(monitor: DropTargetMonitor<MosaicDragItem>) {
300+
return {
301+
isOver: monitor.isOver(),
302+
draggedMosaicId: (monitor.getItem() || {}).mosaicId,
303+
};
304+
},
305+
});
306+
return (
307+
<InternalMosaicWindow
308+
{...props}
309+
connectDragPreview={connectDragPreview}
310+
connectDragSource={connectDragSource}
311+
connectDropTarget={connectDropTarget}
312+
isOver={isOver}
313+
draggedMosaicId={draggedMosaicId}
314+
/>
315+
);
316+
}
323317

324318
export class MosaicWindow<T extends MosaicKey = string> extends React.PureComponent<MosaicWindowProps<T>> {
325319
render() {
326-
return <SourceDropConnectedInternalMosaicWindow {...(this.props as InternalMosaicWindowProps<T>)} />;
320+
return <ConnectedInternalMosaicWindow<T> {...(this.props as InternalMosaicWindowProps<T>)} />;
327321
}
328322
}

0 commit comments

Comments
 (0)