-
Notifications
You must be signed in to change notification settings - Fork 264
Expand file tree
/
Copy pathWindow.jsx
More file actions
147 lines (135 loc) · 4.49 KB
/
Window.jsx
File metadata and controls
147 lines (135 loc) · 4.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import { useContext, useCallback } from 'react';
import PropTypes from 'prop-types';
import { styled } from '@mui/material/styles';
import Paper from '@mui/material/Paper';
import { MosaicWindowContext } from '@lonli-lokli/react-mosaic-component';
import { ErrorBoundary } from 'react-error-boundary';
import { useTranslation } from 'react-i18next';
import ns from '../config/css-ns';
import WindowTopBar from '../containers/WindowTopBar';
import PrimaryWindow from '../containers/PrimaryWindow';
import CompanionArea from '../containers/CompanionArea';
import MinimalWindow from '../containers/MinimalWindow';
import ErrorContent from '../containers/ErrorContent';
import IIIFAuthentication from '../containers/IIIFAuthentication';
import { PluginHook } from './PluginHook';
const rowMixin = {
display: 'flex',
flex: '1',
flexDirection: 'row',
minHeight: 0,
};
const columnMixin = {
display: 'flex',
flex: '1',
flexDirection: 'column',
minHeight: 0,
};
const Root = styled(Paper, { name: 'Window', slot: 'root' })(({ ownerState, theme }) => ({
...columnMixin,
backgroundColor: theme.palette.shades?.dark,
borderRadius: 0,
height: '100%',
overflow: 'hidden',
width: '100%',
...(ownerState?.maximized && {
left: 0,
position: 'absolute',
top: 0,
zIndex: theme.zIndex.modal - 1,
}),
}));
const ContentRow = styled('div', { name: 'Window', slot: 'row' })(() => ({
...rowMixin,
}));
const ContentColumn = styled('div', { name: 'Window', slot: 'column' })(() => ({
...columnMixin,
}));
const StyledPrimaryWindow = styled(PrimaryWindow, { name: 'Window', slot: 'primary' })(() => ({
...rowMixin,
height: '300px',
position: 'relative',
}));
const StyledCompanionAreaBottom = styled(CompanionArea, { name: 'Window', slot: 'bottom' })(() => ({
...rowMixin,
flex: '0',
flexBasis: 'auto',
}));
const StyledCompanionAreaRight = styled('div', { name: 'Window', slot: 'right' })(() => ({
...rowMixin,
flex: '0 1 auto',
}));
/** Window title bar wrapper for drag controls in the mosaic view */
const DraggableNavBar = ({ children, ...props }) => {
const { mosaicWindowActions } = useContext(MosaicWindowContext);
return mosaicWindowActions.connectDragSource(
<nav {...props}>{children}</nav>,
);
};
/**
* Represents a Window in the mirador workspace
* @param {object} window
*/
export function Window({
focusWindow = () => {}, label = null, isFetching = false, sideBarOpen = false,
view = undefined, windowDraggable = null, windowId, workspaceType = null,
manifestError = null,
}) {
const { t } = useTranslation();
const ownerState = arguments[0]; // eslint-disable-line prefer-rest-params
const ErrorWindow = useCallback(({ error }) => (
<MinimalWindow windowId={windowId}>
<ErrorContent error={error} windowId={windowId} />
</MinimalWindow>
), [windowId]);
return (
<ErrorBoundary FallbackComponent={ErrorWindow}>
<Root
onFocus={focusWindow}
ownerState={ownerState}
component="section"
elevation={1}
id={windowId}
className={ns('window')}
aria-label={t('window', { label })}
>
<WindowTopBar
component={workspaceType === 'mosaic' && windowDraggable ? DraggableNavBar : undefined}
windowId={windowId}
windowDraggable={windowDraggable}
/>
<IIIFAuthentication windowId={windowId} />
{ manifestError && <ErrorContent error={{ stack: manifestError }} windowId={windowId} /> }
<ContentRow>
<ContentColumn>
<StyledPrimaryWindow
view={view}
windowId={windowId}
isFetching={isFetching}
sideBarOpen={sideBarOpen}
/>
<StyledCompanionAreaBottom windowId={windowId} position="bottom" />
</ContentColumn>
<StyledCompanionAreaRight>
<CompanionArea windowId={windowId} position="right" />
<CompanionArea windowId={windowId} position="far-right" />
</StyledCompanionAreaRight>
</ContentRow>
<CompanionArea windowId={windowId} position="far-bottom" />
<PluginHook targetName="Window" {...ownerState} />
</Root>
</ErrorBoundary>
);
}
Window.propTypes = {
focusWindow: PropTypes.func,
isFetching: PropTypes.bool,
label: PropTypes.string,
manifestError: PropTypes.string,
maximized: PropTypes.bool,
sideBarOpen: PropTypes.bool,
view: PropTypes.string,
windowDraggable: PropTypes.bool,
windowId: PropTypes.string.isRequired,
workspaceType: PropTypes.string,
};