Skip to content

Commit 306205d

Browse files
committed
Replace react-mosaic with mirador-mosaic
1 parent 417493b commit 306205d

File tree

16 files changed

+152
-403
lines changed

16 files changed

+152
-403
lines changed

__tests__/src/components/Workspace.test.js

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { shallow } from 'enzyme';
22
import Typography from '@material-ui/core/Typography';
3-
import WorkspaceMosaic from '../../../src/containers/WorkspaceMosaic';
43
import WorkspaceElastic from '../../../src/containers/WorkspaceElastic';
54
import Window from '../../../src/containers/Window';
65
import { Workspace } from '../../../src/components/Workspace';
@@ -17,7 +16,7 @@ function createWrapper(props) {
1716
isWorkspaceControlPanelVisible
1817
windowIds={['1', '2']}
1918
workspaceId="foo"
20-
workspaceType="mosaic"
19+
workspaceType="elastic"
2120
t={k => k}
2221
{...props}
2322
/>,
@@ -39,20 +38,6 @@ describe('Workspace', () => {
3938
)).toBe(true);
4039
});
4140
});
42-
describe('if workspace type is mosaic', () => {
43-
it('should render <WorkspaceMosaic/> properly', () => {
44-
const wrapper = createWrapper();
45-
46-
expect(wrapper.matchesElement(
47-
<IIIFDropTarget>
48-
<div className="mirador-workspace-viewport mirador-workspace-with-control-panel">
49-
<Typography>miradorViewer</Typography>
50-
<WorkspaceMosaic />
51-
</div>
52-
</IIIFDropTarget>,
53-
)).toBe(true);
54-
});
55-
});
5641
describe('if workspace type is unknown', () => {
5742
it('should render <Window/> components as list', () => {
5843
const wrapper = createWrapper({ workspaceType: 'bubu' });

__tests__/src/components/WorkspaceMosaic.test.js

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

package.json

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,20 @@
4747
"jss-rtl": "^0.3.0",
4848
"lodash": "^4.17.11",
4949
"manifesto.js": "^4.2.0",
50+
"mirador-mosaic": "^0.0.1",
5051
"normalize-url": "^4.5.0",
5152
"openseadragon": "^2.4.2 || ^3.0.0 || ^4.0.0",
5253
"prop-types": "^15.6.2",
5354
"re-reselect": "^4.0.0",
5455
"react-copy-to-clipboard": "^5.0.1",
55-
"react-dnd": "^10.0.2",
56-
"react-dnd-html5-backend": "^10.0.2",
57-
"react-dnd-multi-backend": "^5.0.0",
58-
"react-dnd-touch-backend": "^10.0.2",
56+
"react-dnd": "^16.0.1",
57+
"react-dnd-html5-backend": "^16.0.1",
58+
"react-dnd-multi-backend": "^8.0.0",
59+
"react-dnd-touch-backend": "^16.0.1",
5960
"react-full-screen": "^1.1.1",
6061
"react-i18next": "^11.7.0 || ^12.0.0",
6162
"react-image": "^4.0.1",
6263
"react-intersection-observer": "^9.0.0",
63-
"react-mosaic-component": "^4.0.1",
6464
"react-redux": "^7.1.0 || ^8.0.0",
6565
"react-resize-observer": "^1.1.1",
6666
"react-rnd": "^10.1",
@@ -114,8 +114,9 @@
114114
"jsdom": "^21.0.0",
115115
"puppeteer": "^19.0.0",
116116
"raf": "^3.4.1",
117-
"react": "^16.14.0",
118-
"react-dom": "^16.14.0",
117+
"rdndmb-html5-to-touch": "^8.0.0",
118+
"react": "^17.0.0",
119+
"react-dom": "^17.0.0",
119120
"react-refresh": "^0.14.0",
120121
"redux-mock-store": "^1.5.1",
121122
"redux-saga-test-plan": "^4.0.0-rc.3",
@@ -125,7 +126,7 @@
125126
"webpack-dev-server": "^4.7.4"
126127
},
127128
"peerDependencies": {
128-
"react": "^16.14.0",
129-
"react-dom": "^16.14.0"
129+
"react": "^17.0.0",
130+
"react-dom": "^17.0.0"
130131
}
131132
}

src/components/AppProviders.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import {
66
ThemeProvider, StylesProvider, createTheme, jssPreset, createGenerateClassName,
77
} from '@material-ui/core/styles';
88
import { DndContext, DndProvider } from 'react-dnd';
9-
import MultiBackend from 'react-dnd-multi-backend';
10-
import HTML5toTouch from 'react-dnd-multi-backend/dist/cjs/HTML5toTouch';
9+
import { MultiBackend } from 'react-dnd-multi-backend';
10+
import { HTML5toTouch } from 'rdndmb-html5-to-touch';
1111
import { create } from 'jss';
1212
import rtl from 'jss-rtl';
1313
import createI18nInstance from '../i18n';

src/components/Window.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { Component } from 'react';
22
import PropTypes from 'prop-types';
33
import cn from 'classnames';
44
import Paper from '@material-ui/core/Paper';
5-
import { MosaicWindowContext } from 'react-mosaic-component/lib/contextTypes';
65
import ns from '../config/css-ns';
76
import WindowTopBar from '../containers/WindowTopBar';
87
import PrimaryWindow from '../containers/PrimaryWindow';
@@ -35,24 +34,19 @@ export class Window extends Component {
3534
*/
3635
wrappedTopBar() {
3736
const {
38-
windowId, workspaceType, windowDraggable,
37+
dragHandle, windowId, workspaceType, windowDraggable,
3938
} = this.props;
4039

4140
const topBar = (
42-
<div>
41+
<div ref={dragHandle}>
4342
<WindowTopBar
4443
windowId={windowId}
4544
windowDraggable={windowDraggable}
45+
dragHandle={dragHandle}
4646
/>
4747
<IIIFAuthentication windowId={windowId} />
4848
</div>
4949
);
50-
if (workspaceType === 'mosaic' && windowDraggable) {
51-
const { mosaicWindowActions } = this.context;
52-
return mosaicWindowActions.connectDragSource(
53-
topBar,
54-
);
55-
}
5650
return topBar;
5751
}
5852

@@ -119,10 +113,12 @@ export class Window extends Component {
119113
}
120114
}
121115

122-
Window.contextType = MosaicWindowContext;
123-
124116
Window.propTypes = {
125117
classes: PropTypes.objectOf(PropTypes.string),
118+
dragHandle: PropTypes.oneOfType([
119+
PropTypes.func,
120+
PropTypes.shape({ current: PropTypes.instanceOf(Element) }),
121+
]),
126122
focusWindow: PropTypes.func,
127123
isFetching: PropTypes.bool,
128124
label: PropTypes.string,
@@ -138,6 +134,7 @@ Window.propTypes = {
138134

139135
Window.defaultProps = {
140136
classes: {},
137+
dragHandle: null,
141138
focusWindow: () => {},
142139
isFetching: false,
143140
label: null,

src/components/Workspace.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import classNames from 'classnames';
44
import Grid from '@material-ui/core/Grid';
55
import Typography from '@material-ui/core/Typography';
66
import Window from '../containers/Window';
7-
import WorkspaceMosaic from '../containers/WorkspaceMosaic';
87
import WorkspaceElastic from '../containers/WorkspaceElastic';
8+
import WorkspaceGrid from '../containers/WorkspaceGrid';
99
import ns from '../config/css-ns';
1010
import { IIIFDropTarget } from './IIIFDropTarget';
1111

@@ -45,8 +45,8 @@ export class Workspace extends Component {
4545
switch (workspaceType) {
4646
case 'elastic':
4747
return <WorkspaceElastic />;
48-
case 'mosaic':
49-
return <WorkspaceMosaic />;
48+
case 'grid':
49+
return <WorkspaceGrid />;
5050
default:
5151
return windowIds.map(windowId => (
5252
<Window

src/components/WorkspaceGrid.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { Component, useContext, useCallback } from 'react';
2+
import PropTypes from 'prop-types';
3+
import { DndContext } from 'react-dnd';
4+
import { Grid, GridContext, GridDispatchContext } from 'mirador-mosaic';
5+
import Window from '../containers/Window';
6+
import { useDispatch } from 'react-redux'
7+
8+
/**
9+
* Represents a work area that contains any number of windows
10+
* @memberof Workspace
11+
* @private
12+
*/
13+
const WorkspaceGrid = ({ gridTemplate, windowIds }) => {
14+
const dndContext = useContext(DndContext);
15+
const dispatch = useDispatch();
16+
17+
const wrappedDispatch = useCallback((action) => {
18+
dispatch({ ...action, type: `mirador/grid/${action.type}` });
19+
}, [dispatch]);
20+
21+
return (
22+
<div style={{ position: 'relative', width: '100%', height: '100%' }}>
23+
<GridContext.Provider value={gridTemplate}>
24+
<GridDispatchContext.Provider value={wrappedDispatch}>
25+
<Grid dragAndDropManager={dndContext.dragDropManager}>
26+
{
27+
windowIds.map(windowId => (
28+
<Window
29+
id={windowId}
30+
key={windowId}
31+
windowId={windowId}
32+
/>
33+
))
34+
}
35+
</Grid>
36+
</GridDispatchContext.Provider>
37+
</GridContext.Provider>
38+
</div>
39+
);
40+
}
41+
42+
43+
WorkspaceGrid.propTypes = {
44+
gridTemplate: PropTypes.object,
45+
windowIds: PropTypes.arrayOf(PropTypes.string).isRequired,
46+
};
47+
48+
export default WorkspaceGrid;

0 commit comments

Comments
 (0)