cozy-viewer 2.1.0 → 2.3.0
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.
- package/CHANGELOG.md +22 -0
- package/dist/ViewersByFile/PdfMobileViewer.js +50 -41
- package/package.json +12 -12
- package/src/ViewersByFile/PdfMobileViewer.jsx +24 -17
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,28 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# 2.3.0 (2024-10-30)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* Update deps for cozy-viewer ([b2e103a](https://github.com/cozy/cozy-libs/commit/b2e103a1280182881ae1133860c0a09650271920))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# 2.2.0 (2024-10-30)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
* Download file on mobile viewer on press ([3c38062](https://github.com/cozy/cozy-libs/commit/3c38062e2c83d5b8f7d0065323c18d45b5ce9564))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
6
28
|
# 2.1.0 (2024-10-25)
|
|
7
29
|
|
|
8
30
|
|
|
@@ -13,6 +13,8 @@ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/
|
|
|
13
13
|
|
|
14
14
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
15
15
|
|
|
16
|
+
var _throttle = _interopRequireDefault(require("lodash/throttle"));
|
|
17
|
+
|
|
16
18
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
17
19
|
|
|
18
20
|
var _react = _interopRequireWildcard(require("react"));
|
|
@@ -91,58 +93,65 @@ var PdfMobileViewer = function PdfMobileViewer(_ref) {
|
|
|
91
93
|
setLoading(false);
|
|
92
94
|
};
|
|
93
95
|
|
|
94
|
-
var handleOnClick = (0, _react.
|
|
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
|
-
|
|
96
|
+
var handleOnClick = (0, _react.useMemo)(function () {
|
|
97
|
+
return (0, _throttle.default)( /*#__PURE__*/function () {
|
|
98
|
+
var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(file) {
|
|
99
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
100
|
+
while (1) {
|
|
101
|
+
switch (_context.prev = _context.next) {
|
|
102
|
+
case 0:
|
|
103
|
+
_context.prev = 0;
|
|
104
|
+
_context.next = 3;
|
|
105
|
+
return (0, _file.downloadFile)({
|
|
106
|
+
client: client,
|
|
107
|
+
file: file,
|
|
108
|
+
webviewIntent: webviewIntent
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
case 3:
|
|
112
|
+
_context.next = 8;
|
|
113
|
+
break;
|
|
114
|
+
|
|
115
|
+
case 5:
|
|
116
|
+
_context.prev = 5;
|
|
117
|
+
_context.t0 = _context["catch"](0);
|
|
118
|
+
showAlert({
|
|
119
|
+
message: t('Viewer.error.generic'),
|
|
120
|
+
severity: 'error',
|
|
121
|
+
variant: 'filled',
|
|
122
|
+
icon: false
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
case 8:
|
|
126
|
+
case "end":
|
|
127
|
+
return _context.stop();
|
|
128
|
+
}
|
|
125
129
|
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}));
|
|
130
|
+
}, _callee, null, [[0, 5]]);
|
|
131
|
+
}));
|
|
129
132
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
133
|
+
return function (_x) {
|
|
134
|
+
return _ref2.apply(this, arguments);
|
|
135
|
+
};
|
|
136
|
+
}(), 1000, {
|
|
137
|
+
trailing: false
|
|
138
|
+
});
|
|
139
|
+
}, [client, showAlert, t, webviewIntent]);
|
|
134
140
|
(0, _react.useEffect)(function () {
|
|
135
141
|
if (gestures) {
|
|
136
142
|
gestures.get('pinch').set({
|
|
137
143
|
enable: true
|
|
138
144
|
});
|
|
139
|
-
gestures.
|
|
140
|
-
|
|
145
|
+
gestures.get('press').set({
|
|
146
|
+
time: 1
|
|
147
|
+
});
|
|
148
|
+
gestures.on('pinchend press', function (evt) {
|
|
149
|
+
if ((evt.type === 'pinchend' || evt.type === 'press') && evt.target === imgRef.current) {
|
|
141
150
|
handleOnClick(file);
|
|
142
151
|
}
|
|
143
152
|
});
|
|
144
153
|
return function () {
|
|
145
|
-
gestures.off('pinchend
|
|
154
|
+
gestures.off('pinchend press');
|
|
146
155
|
};
|
|
147
156
|
}
|
|
148
157
|
}, [client, gestures, file, handleOnClick]);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cozy-viewer",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"description": "Cozy-Viewer provides a component to show files in a viewer.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"license": "MIT",
|
|
@@ -24,14 +24,14 @@
|
|
|
24
24
|
"@testing-library/react": "11.2.7",
|
|
25
25
|
"@testing-library/react-hooks": "^3.2.1",
|
|
26
26
|
"babel-plugin-inline-json-import": "0.3.2",
|
|
27
|
-
"babel-preset-cozy-app": "^2.
|
|
28
|
-
"cozy-client": "
|
|
27
|
+
"babel-preset-cozy-app": "^2.5.0",
|
|
28
|
+
"cozy-client": "50.0.0",
|
|
29
29
|
"cozy-device-helper": "2.0.0",
|
|
30
|
-
"cozy-harvest-lib": "^
|
|
31
|
-
"cozy-intent": "^
|
|
32
|
-
"cozy-logger": "^1.
|
|
30
|
+
"cozy-harvest-lib": "^30.3.0",
|
|
31
|
+
"cozy-intent": "^2.26.0",
|
|
32
|
+
"cozy-logger": "^1.13.0",
|
|
33
33
|
"cozy-sharing": "14.1.0",
|
|
34
|
-
"cozy-ui": "^112.
|
|
34
|
+
"cozy-ui": "^112.2.0",
|
|
35
35
|
"enzyme": "3.11.0",
|
|
36
36
|
"enzyme-adapter-react-16": "1.15.6",
|
|
37
37
|
"enzyme-to-json": "3.6.2",
|
|
@@ -50,15 +50,15 @@
|
|
|
50
50
|
"react-pdf": "^5.7.2"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
|
-
"cozy-client": ">=
|
|
53
|
+
"cozy-client": ">=50.0.0",
|
|
54
54
|
"cozy-device-helper": ">=2.0.0",
|
|
55
|
-
"cozy-harvest-lib": ">=
|
|
56
|
-
"cozy-intent": ">=
|
|
55
|
+
"cozy-harvest-lib": ">=30.2.0",
|
|
56
|
+
"cozy-intent": ">=2.25.0",
|
|
57
57
|
"cozy-logger": ">=1.9.0",
|
|
58
58
|
"cozy-sharing": ">=14.1.0",
|
|
59
|
-
"cozy-ui": ">=112.
|
|
59
|
+
"cozy-ui": ">=112.2.0",
|
|
60
60
|
"react": ">=16.12.0",
|
|
61
61
|
"react-dom": ">=16.12.0"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "84e64cbf96c0274bc4490eb2e8ec87c410fc9a84"
|
|
64
64
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import throttle from 'lodash/throttle'
|
|
1
2
|
import PropTypes from 'prop-types'
|
|
2
|
-
import React, { useState, useEffect, useRef,
|
|
3
|
+
import React, { useState, useEffect, useRef, useMemo } from 'react'
|
|
3
4
|
|
|
4
5
|
import { useClient } from 'cozy-client'
|
|
5
6
|
import { downloadFile } from 'cozy-client/dist/models/file'
|
|
@@ -32,28 +33,34 @@ export const PdfMobileViewer = ({ file, url, t, gestures }) => {
|
|
|
32
33
|
setLoading(false)
|
|
33
34
|
}
|
|
34
35
|
|
|
35
|
-
const handleOnClick =
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
36
|
+
const handleOnClick = useMemo(
|
|
37
|
+
() =>
|
|
38
|
+
throttle(
|
|
39
|
+
async file => {
|
|
40
|
+
try {
|
|
41
|
+
await downloadFile({ client, file, webviewIntent })
|
|
42
|
+
} catch (error) {
|
|
43
|
+
showAlert({
|
|
44
|
+
message: t('Viewer.error.generic'),
|
|
45
|
+
severity: 'error',
|
|
46
|
+
variant: 'filled',
|
|
47
|
+
icon: false
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
1000,
|
|
52
|
+
{ trailing: false }
|
|
53
|
+
),
|
|
48
54
|
[client, showAlert, t, webviewIntent]
|
|
49
55
|
)
|
|
50
56
|
|
|
51
57
|
useEffect(() => {
|
|
52
58
|
if (gestures) {
|
|
53
59
|
gestures.get('pinch').set({ enable: true })
|
|
54
|
-
gestures.
|
|
60
|
+
gestures.get('press').set({ time: 1 })
|
|
61
|
+
gestures.on('pinchend press', evt => {
|
|
55
62
|
if (
|
|
56
|
-
(evt.type === 'pinchend' || evt.
|
|
63
|
+
(evt.type === 'pinchend' || evt.type === 'press') &&
|
|
57
64
|
evt.target === imgRef.current
|
|
58
65
|
) {
|
|
59
66
|
handleOnClick(file)
|
|
@@ -61,7 +68,7 @@ export const PdfMobileViewer = ({ file, url, t, gestures }) => {
|
|
|
61
68
|
})
|
|
62
69
|
|
|
63
70
|
return () => {
|
|
64
|
-
gestures.off('pinchend
|
|
71
|
+
gestures.off('pinchend press')
|
|
65
72
|
}
|
|
66
73
|
}
|
|
67
74
|
}, [client, gestures, file, handleOnClick])
|