-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathindex.jsx
98 lines (90 loc) · 2.11 KB
/
index.jsx
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
import PropTypes from 'prop-types';
import React from 'react';
import { cloneDeep } from 'lodash';
import VideoPlayer from './video-player';
import AudioPlayer from './audio-player';
import TextViewer from './text-viewer';
import ImageViewer from './image-viewer';
import CanvasViewer from './canvas-viewer';
function DefaultViewer(props) {
return (
<p>
Unknown file type: {props.type}
</p>
);
}
DefaultViewer.propTypes = {
type: PropTypes.string
};
const VIEWERS = {
image: ImageViewer,
text: TextViewer,
video: VideoPlayer,
audio: AudioPlayer,
application: CanvasViewer
};
function subjectViewerSelector(props) {
if (Array.isArray(props.type)) {
if (props.type.includes('audio')) {
return VIEWERS.audio;
}
// ... add other here if necessary
}
return VIEWERS[props.type] || DefaultViewer;
}
function FileViewer(props) {
const Viewer = subjectViewerSelector(props);
const viewerProps = {
className: props.className,
style: props.style,
src: props.src,
type: props.type,
format: props.format,
frame: props.frame,
onLoad: props.onLoad,
onFocus: props.onFocus,
onBlur: props.onBlur
};
if (props.type === 'application') {
Object.assign(
viewerProps,
{
annotation: cloneDeep(props.annotation),
annotations: props.annotations,
subject: props.subject,
viewBoxDimensions: props.viewBoxDimensions
}
);
}
return (
<Viewer {...viewerProps} />
);
}
FileViewer.propTypes = {
annotation: PropTypes.object,
className: PropTypes.string,
annotations: PropTypes.arrayOf(PropTypes.object),
format: PropTypes.oneOfType([
PropTypes.array,
PropTypes.string
]),
frame: PropTypes.number,
onBlur: PropTypes.func,
onFocus: PropTypes.func,
onLoad: PropTypes.func,
src: PropTypes.oneOfType([
PropTypes.array,
PropTypes.string
]),
style: PropTypes.object,
subject: PropTypes.object,
type: PropTypes.oneOfType([
PropTypes.array,
PropTypes.string
]),
viewBoxDimensions: PropTypes.object
};
FileViewer.defaultProps = {
annotations: []
}
export default FileViewer;