mirador-dl-plugin 0.13.0 → 1.0.0-alpha.2

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.
@@ -1,113 +0,0 @@
1
- var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
2
-
3
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
4
-
5
- function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
6
-
7
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
8
-
9
- import React, { Component } from 'react';
10
- import PropTypes from 'prop-types';
11
- import ListItemIcon from '@material-ui/core/ListItemIcon';
12
- import ListItemText from '@material-ui/core/ListItemText';
13
- import MenuItem from '@material-ui/core/MenuItem';
14
- import DownloadIcon from '@material-ui/icons/VerticalAlignBottomSharp';
15
-
16
- var downloadDialogReducer = function downloadDialogReducer() {
17
- var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
18
- var action = arguments[1];
19
-
20
- if (action.type === 'OPEN_WINDOW_DIALOG') {
21
- var _extends2;
22
-
23
- return _extends({}, state, (_extends2 = {}, _extends2[action.windowId] = {
24
- openDialog: action.dialogType
25
- }, _extends2));
26
- }
27
-
28
- if (action.type === 'CLOSE_WINDOW_DIALOG') {
29
- var _extends3;
30
-
31
- return _extends({}, state, (_extends3 = {}, _extends3[action.windowId] = {
32
- openDialog: null
33
- }, _extends3));
34
- }
35
- return state;
36
- };
37
-
38
- var mapDispatchToProps = function mapDispatchToProps(dispatch, _ref) {
39
- var windowId = _ref.windowId;
40
- return {
41
- openDownloadDialog: function openDownloadDialog() {
42
- return dispatch({ type: 'OPEN_WINDOW_DIALOG', windowId: windowId, dialogType: 'download' });
43
- }
44
- };
45
- };
46
-
47
- var MiradorDownload = function (_Component) {
48
- _inherits(MiradorDownload, _Component);
49
-
50
- function MiradorDownload() {
51
- _classCallCheck(this, MiradorDownload);
52
-
53
- return _possibleConstructorReturn(this, _Component.apply(this, arguments));
54
- }
55
-
56
- MiradorDownload.prototype.openDialogAndCloseMenu = function openDialogAndCloseMenu() {
57
- var _props = this.props,
58
- handleClose = _props.handleClose,
59
- openDownloadDialog = _props.openDownloadDialog;
60
-
61
-
62
- openDownloadDialog();
63
- handleClose();
64
- };
65
-
66
- MiradorDownload.prototype.render = function render() {
67
- var _this2 = this;
68
-
69
- return React.createElement(
70
- React.Fragment,
71
- null,
72
- React.createElement(
73
- MenuItem,
74
- { onClick: function onClick() {
75
- return _this2.openDialogAndCloseMenu();
76
- } },
77
- React.createElement(
78
- ListItemIcon,
79
- null,
80
- React.createElement(DownloadIcon, null)
81
- ),
82
- React.createElement(
83
- ListItemText,
84
- { primaryTypographyProps: { variant: 'body1' } },
85
- 'Download'
86
- )
87
- )
88
- );
89
- };
90
-
91
- return MiradorDownload;
92
- }(Component);
93
-
94
- MiradorDownload.propTypes = process.env.NODE_ENV !== "production" ? {
95
- handleClose: PropTypes.func,
96
- openDownloadDialog: PropTypes.func
97
- } : {};
98
-
99
- MiradorDownload.defaultProps = {
100
- handleClose: function handleClose() {},
101
- openDownloadDialog: function openDownloadDialog() {}
102
- };
103
-
104
- export default {
105
- target: 'WindowTopBarPluginMenu',
106
- mode: 'add',
107
- name: 'MiradorDownloadPlugin',
108
- component: MiradorDownload,
109
- mapDispatchToProps: mapDispatchToProps,
110
- reducers: {
111
- windowDialogs: downloadDialogReducer
112
- }
113
- };
@@ -1,284 +0,0 @@
1
- 'use strict';
2
-
3
- exports.__esModule = true;
4
- exports.default = undefined;
5
-
6
- var _react = require('react');
7
-
8
- var _react2 = _interopRequireDefault(_react);
9
-
10
- var _propTypes = require('prop-types');
11
-
12
- var _propTypes2 = _interopRequireDefault(_propTypes);
13
-
14
- var _Typography = require('@material-ui/core/Typography');
15
-
16
- var _Typography2 = _interopRequireDefault(_Typography);
17
-
18
- var _Link = require('@material-ui/core/Link');
19
-
20
- var _Link2 = _interopRequireDefault(_Link);
21
-
22
- var _List = require('@material-ui/core/List');
23
-
24
- var _List2 = _interopRequireDefault(_List);
25
-
26
- var _ListItem = require('@material-ui/core/ListItem');
27
-
28
- var _ListItem2 = _interopRequireDefault(_ListItem);
29
-
30
- var _uniqBy = require('lodash/uniqBy');
31
-
32
- var _uniqBy2 = _interopRequireDefault(_uniqBy);
33
-
34
- var _OSDReferences = require('mirador/dist/es/src/plugins/OSDReferences');
35
-
36
- var _RenderingDownloadLink = require('./RenderingDownloadLink');
37
-
38
- var _RenderingDownloadLink2 = _interopRequireDefault(_RenderingDownloadLink);
39
-
40
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
41
-
42
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
43
-
44
- function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
45
-
46
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
47
-
48
- /**
49
- * CanvasDownloadLinks ~
50
- */
51
- var CanvasDownloadLinks = function (_Component) {
52
- _inherits(CanvasDownloadLinks, _Component);
53
-
54
- function CanvasDownloadLinks() {
55
- _classCallCheck(this, CanvasDownloadLinks);
56
-
57
- return _possibleConstructorReturn(this, _Component.apply(this, arguments));
58
- }
59
-
60
- CanvasDownloadLinks.prototype.zoomedImageLabel = function zoomedImageLabel() {
61
- var bounds = this.currentBounds();
62
- return 'Zoomed region (' + Math.floor(bounds.width) + ' x ' + Math.floor(bounds.height) + 'px)';
63
- };
64
-
65
- CanvasDownloadLinks.prototype.fullImageLabel = function fullImageLabel() {
66
- var canvas = this.props.canvas;
67
-
68
-
69
- return 'Whole image (' + canvas.getWidth() + ' x ' + canvas.getHeight() + 'px)';
70
- };
71
-
72
- CanvasDownloadLinks.prototype.smallImageLabel = function smallImageLabel() {
73
- var canvas = this.props.canvas;
74
-
75
-
76
- return 'Whole image (1000 x ' + Math.floor(1000 * canvas.getHeight() / canvas.getWidth()) + 'px)';
77
- };
78
-
79
- CanvasDownloadLinks.prototype.zoomedImageUrl = function zoomedImageUrl() {
80
- var canvas = this.props.canvas;
81
-
82
- var bounds = this.currentBounds();
83
- var boundsUrl = canvas.getCanonicalImageUri().replace(/\/full\/.*\/0\//, '/' + bounds.x + ',' + bounds.y + ',' + bounds.width + ',' + bounds.height + '/full/0/');
84
-
85
- return boundsUrl + '?download=true';
86
- };
87
-
88
- CanvasDownloadLinks.prototype.imageUrlForSize = function imageUrlForSize(size) {
89
- var canvas = this.props.canvas;
90
-
91
-
92
- return canvas.getCanonicalImageUri(size.width) + '?download=true';
93
- };
94
-
95
- CanvasDownloadLinks.prototype.fullImageUrl = function fullImageUrl() {
96
- var canvas = this.props.canvas;
97
-
98
-
99
- return canvas.getCanonicalImageUri().replace(/\/full\/.*\/0\//, '/full/full/0/') + '?download=true';
100
- };
101
-
102
- CanvasDownloadLinks.prototype.thousandPixelWideImage = function thousandPixelWideImage() {
103
- var canvas = this.props.canvas;
104
-
105
-
106
- return canvas.getCanonicalImageUri('1000') + '?download=true';
107
- };
108
-
109
- CanvasDownloadLinks.prototype.osdViewport = function osdViewport() {
110
- var windowId = this.props.windowId;
111
-
112
-
113
- return _OSDReferences.OSDReferences.get(windowId).current.viewport;
114
- };
115
-
116
- CanvasDownloadLinks.prototype.currentBounds = function currentBounds() {
117
- var bounds = this.osdViewport().getBounds();
118
-
119
- return Object.keys(bounds).reduce(function (object, key) {
120
- object[key] = Math.ceil(bounds[key]); // eslint-disable-line no-param-reassign
121
- return object;
122
- }, {});
123
- };
124
-
125
- CanvasDownloadLinks.prototype.definedSizesRestrictsDownload = function definedSizesRestrictsDownload() {
126
- var infoResponse = this.props.infoResponse;
127
-
128
- if (!infoResponse.json) return false;
129
- var _infoResponse$json = infoResponse.json,
130
- height = _infoResponse$json.height,
131
- width = _infoResponse$json.width;
132
-
133
-
134
- if (this.definedSizes().length !== 1) return false;
135
-
136
- return this.definedSizes()[0].width <= width && this.definedSizes()[0].height <= height;
137
- };
138
-
139
- CanvasDownloadLinks.prototype.displayCurrentZoomLink = function displayCurrentZoomLink() {
140
- var _props = this.props,
141
- restrictDownloadOnSizeDefinition = _props.restrictDownloadOnSizeDefinition,
142
- infoResponse = _props.infoResponse,
143
- viewType = _props.viewType;
144
-
145
-
146
- if (viewType !== 'single') return false;
147
- if (restrictDownloadOnSizeDefinition && this.definedSizesRestrictsDownload()) return false;
148
- if (!(infoResponse && infoResponse.json)) return false;
149
-
150
- var bounds = this.currentBounds();
151
- return bounds.height < infoResponse.json.height && bounds.width < infoResponse.json.width && bounds.x >= 0 && bounds.y >= 0;
152
- };
153
-
154
- /**
155
- * This only returns unique sizes
156
- */
157
-
158
-
159
- CanvasDownloadLinks.prototype.definedSizes = function definedSizes() {
160
- var infoResponse = this.props.infoResponse;
161
-
162
- if (!(infoResponse && infoResponse.json && infoResponse.json.sizes)) return [];
163
-
164
- return (0, _uniqBy2.default)(infoResponse.json.sizes, function (size) {
165
- return '' + size.width + size.height;
166
- });
167
- };
168
-
169
- CanvasDownloadLinks.prototype.fullImageLink = function fullImageLink() {
170
- return _react2.default.createElement(
171
- _ListItem2.default,
172
- { disableGutters: true, divider: true, key: this.fullImageUrl() },
173
- _react2.default.createElement(
174
- _Link2.default,
175
- { href: this.fullImageUrl(), rel: 'noopener noreferrer', target: '_blank', variant: 'body1' },
176
- this.fullImageLabel()
177
- )
178
- );
179
- };
180
-
181
- CanvasDownloadLinks.prototype.thousandPixelWideLink = function thousandPixelWideLink() {
182
- var canvas = this.props.canvas;
183
-
184
-
185
- if (canvas.getWidth() < 1000) return '';
186
-
187
- return _react2.default.createElement(
188
- _ListItem2.default,
189
- { disableGutters: true, divider: true, key: this.thousandPixelWideImage() },
190
- _react2.default.createElement(
191
- _Link2.default,
192
- { href: this.thousandPixelWideImage(), rel: 'noopener noreferrer', target: '_blank', variant: 'body1' },
193
- this.smallImageLabel()
194
- )
195
- );
196
- };
197
-
198
- CanvasDownloadLinks.prototype.linksForDefinedSizes = function linksForDefinedSizes() {
199
- var _this2 = this;
200
-
201
- return this.definedSizes().map(function (size) {
202
- return _react2.default.createElement(
203
- _ListItem2.default,
204
- { disableGutters: true, divider: true, key: '' + size.width + size.height },
205
- _react2.default.createElement(
206
- _Link2.default,
207
- { href: _this2.imageUrlForSize(size), rel: 'noopener noreferrer', target: '_blank', variant: 'body1' },
208
- 'Whole image (' + size.width + ' x ' + size.height + 'px)'
209
- )
210
- );
211
- });
212
- };
213
-
214
- /**
215
- * Returns the rendered component
216
- */
217
-
218
-
219
- CanvasDownloadLinks.prototype.render = function render() {
220
- var _props2 = this.props,
221
- canvas = _props2.canvas,
222
- canvasLabel = _props2.canvasLabel,
223
- classes = _props2.classes;
224
-
225
-
226
- return _react2.default.createElement(
227
- _react2.default.Fragment,
228
- null,
229
- _react2.default.createElement(
230
- _Typography2.default,
231
- { noWrap: true, variant: 'h3', className: classes.h3 },
232
- canvasLabel
233
- ),
234
- _react2.default.createElement(
235
- _List2.default,
236
- null,
237
- this.displayCurrentZoomLink() && _react2.default.createElement(
238
- _ListItem2.default,
239
- { disableGutters: true, divider: true },
240
- _react2.default.createElement(
241
- _Link2.default,
242
- { href: this.zoomedImageUrl(), rel: 'noopener noreferrer', target: '_blank', variant: 'body1' },
243
- this.zoomedImageLabel()
244
- )
245
- ),
246
- this.definedSizes().length === 0 && [this.fullImageLink(), this.thousandPixelWideLink()],
247
- this.definedSizes().length > 0 && this.linksForDefinedSizes(),
248
- canvas.getRenderings().map(function (rendering) {
249
- return _react2.default.createElement(_RenderingDownloadLink2.default, { rendering: rendering, key: rendering.id });
250
- })
251
- )
252
- );
253
- };
254
-
255
- return CanvasDownloadLinks;
256
- }(_react.Component);
257
-
258
- exports.default = CanvasDownloadLinks;
259
-
260
-
261
- CanvasDownloadLinks.propTypes = process.env.NODE_ENV !== "production" ? {
262
- canvas: _propTypes2.default.shape({
263
- id: _propTypes2.default.string.isRequired,
264
- getCanonicalImageUri: _propTypes2.default.func.isRequired,
265
- getHeight: _propTypes2.default.func.isRequired,
266
- getRenderings: _propTypes2.default.func.isRequired,
267
- getWidth: _propTypes2.default.func.isRequired
268
- }).isRequired,
269
- canvasLabel: _propTypes2.default.string.isRequired, // canvasLabel is passed because we need access to redux
270
- classes: _propTypes2.default.shape({
271
- h3: _propTypes2.default.string
272
- }).isRequired,
273
- infoResponse: _propTypes2.default.shape({
274
- json: _propTypes2.default.shape({
275
- height: _propTypes2.default.number,
276
- sizes: _propTypes2.default.arrayOf(_propTypes2.default.shape({ height: _propTypes2.default.number, width: _propTypes2.default.number })),
277
- width: _propTypes2.default.number
278
- })
279
- }).isRequired,
280
- restrictDownloadOnSizeDefinition: _propTypes2.default.bool.isRequired,
281
- viewType: _propTypes2.default.string.isRequired,
282
- windowId: _propTypes2.default.string.isRequired
283
- } : {};
284
- module.exports = exports['default'];
@@ -1,85 +0,0 @@
1
- 'use strict';
2
-
3
- exports.__esModule = true;
4
- exports.default = undefined;
5
-
6
- var _react = require('react');
7
-
8
- var _react2 = _interopRequireDefault(_react);
9
-
10
- var _propTypes = require('prop-types');
11
-
12
- var _propTypes2 = _interopRequireDefault(_propTypes);
13
-
14
- var _List = require('@material-ui/core/List');
15
-
16
- var _List2 = _interopRequireDefault(_List);
17
-
18
- var _Typography = require('@material-ui/core/Typography');
19
-
20
- var _Typography2 = _interopRequireDefault(_Typography);
21
-
22
- var _RenderingDownloadLink = require('./RenderingDownloadLink');
23
-
24
- var _RenderingDownloadLink2 = _interopRequireDefault(_RenderingDownloadLink);
25
-
26
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
27
-
28
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
29
-
30
- function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
31
-
32
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
33
-
34
- /**
35
- * ManifestDownloadLinks ~
36
- */
37
- var ManifestDownloadLinks = function (_Component) {
38
- _inherits(ManifestDownloadLinks, _Component);
39
-
40
- function ManifestDownloadLinks() {
41
- _classCallCheck(this, ManifestDownloadLinks);
42
-
43
- return _possibleConstructorReturn(this, _Component.apply(this, arguments));
44
- }
45
-
46
- /**
47
- * Returns the rendered component
48
- */
49
- ManifestDownloadLinks.prototype.render = function render() {
50
- var _props = this.props,
51
- classes = _props.classes,
52
- renderings = _props.renderings;
53
-
54
-
55
- return _react2.default.createElement(
56
- _react2.default.Fragment,
57
- null,
58
- _react2.default.createElement(
59
- _Typography2.default,
60
- { variant: 'h3', className: classes.h3 },
61
- 'Other download options'
62
- ),
63
- _react2.default.createElement(
64
- _List2.default,
65
- null,
66
- renderings.map(function (rendering) {
67
- return _react2.default.createElement(_RenderingDownloadLink2.default, { rendering: rendering, key: rendering.id });
68
- })
69
- )
70
- );
71
- };
72
-
73
- return ManifestDownloadLinks;
74
- }(_react.Component);
75
-
76
- exports.default = ManifestDownloadLinks;
77
-
78
-
79
- ManifestDownloadLinks.propTypes = process.env.NODE_ENV !== "production" ? {
80
- classes: _propTypes2.default.shape({
81
- h3: _propTypes2.default.string
82
- }).isRequired,
83
- renderings: _propTypes2.default.array.isRequired // eslint-disable-line react/forbid-prop-types
84
- } : {};
85
- module.exports = exports['default'];