cozy-viewer 1.1.1 → 2.0.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 +21 -0
- package/babel.config.js +3 -0
- package/dist/NoViewer/DownloadButton.js +8 -4
- package/dist/ViewersByFile/PdfMobileViewer.js +11 -2
- package/dist/components/Toolbar.js +9 -4
- package/dist/helpers.d.ts +0 -5
- package/dist/helpers.js +9 -47
- package/dist/stylesheet.css +77 -53
- package/package.json +5 -4
- package/src/NoViewer/DownloadButton.jsx +4 -3
- package/src/ViewersByFile/PdfMobileViewer.jsx +5 -2
- package/src/components/Toolbar.jsx +4 -2
- package/src/helpers.js +0 -7
- package/src/helpers.spec.js +0 -25
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,27 @@
|
|
|
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.0.0](https://github.com/cozy/cozy-libs/compare/cozy-viewer@1.1.2...cozy-viewer@2.0.0) (2024-09-24)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- **cozy-viewer:** Upgrade cozy-client peerDependency to `49.0.0` ([113b598](https://github.com/cozy/cozy-libs/commit/113b598c40b3bbffa911955ce71be86a36e59f43)), closes [cozy/cozy-client#1507](https://github.com/cozy/cozy-client/issues/1507)
|
|
11
|
+
- **cozy-viewer:** Use new `downloadFile()` method from cozy-client ([d654334](https://github.com/cozy/cozy-libs/commit/d6543349a7f4b7248d971ab52f1a7dacf41225ac)), closes [cozy/cozy-client#1518](https://github.com/cozy/cozy-client/issues/1518)
|
|
12
|
+
|
|
13
|
+
### BREAKING CHANGES
|
|
14
|
+
|
|
15
|
+
- **cozy-viewer:** `downloadFile()` method has been removed from
|
|
16
|
+
`cozy-viewer/src/helpers.js`. Use the one from
|
|
17
|
+
`cozy-client/dist/models/file` instead
|
|
18
|
+
- **cozy-viewer:** cozy-viewer now requires cozy-client >= 49.0.0 (used
|
|
19
|
+
for offline support)
|
|
20
|
+
|
|
21
|
+
## [1.1.2](https://github.com/cozy/cozy-libs/compare/cozy-viewer@1.1.1...cozy-viewer@1.1.2) (2024-09-12)
|
|
22
|
+
|
|
23
|
+
### Bug Fixes
|
|
24
|
+
|
|
25
|
+
- **Viewer:** Css wasn't publish with hash on classes ([eb050b9](https://github.com/cozy/cozy-libs/commit/eb050b92018631e322b7c76eaceda07a835d31af))
|
|
26
|
+
|
|
6
27
|
## [1.1.1](https://github.com/cozy/cozy-libs/compare/cozy-viewer@1.1.0...cozy-viewer@1.1.1) (2024-09-12)
|
|
7
28
|
|
|
8
29
|
### Bug Fixes
|
package/babel.config.js
CHANGED
|
@@ -13,14 +13,16 @@ var _react = _interopRequireDefault(require("react"));
|
|
|
13
13
|
|
|
14
14
|
var _cozyClient = require("cozy-client");
|
|
15
15
|
|
|
16
|
+
var _file = require("cozy-client/dist/models/file");
|
|
17
|
+
|
|
18
|
+
var _cozyIntent = require("cozy-intent");
|
|
19
|
+
|
|
16
20
|
var _Button = _interopRequireDefault(require("cozy-ui/transpiled/react/deprecated/Button"));
|
|
17
21
|
|
|
18
22
|
var _proptypes = require("cozy-ui/transpiled/react/proptypes");
|
|
19
23
|
|
|
20
24
|
var _I18n = require("cozy-ui/transpiled/react/providers/I18n");
|
|
21
25
|
|
|
22
|
-
var _helpers = require("../helpers");
|
|
23
|
-
|
|
24
26
|
var DownloadButton = function DownloadButton(_ref) {
|
|
25
27
|
var client = _ref.client,
|
|
26
28
|
file = _ref.file,
|
|
@@ -29,12 +31,14 @@ var DownloadButton = function DownloadButton(_ref) {
|
|
|
29
31
|
var _useI18n = (0, _I18n.useI18n)(),
|
|
30
32
|
t = _useI18n.t;
|
|
31
33
|
|
|
34
|
+
var webviewIntent = (0, _cozyIntent.useWebviewIntent)();
|
|
32
35
|
return /*#__PURE__*/_react.default.createElement(_Button.default, {
|
|
33
36
|
onClick: function onClick() {
|
|
34
|
-
return (0,
|
|
37
|
+
return (0, _file.downloadFile)({
|
|
35
38
|
client: client,
|
|
36
39
|
file: file,
|
|
37
|
-
url: url
|
|
40
|
+
url: url,
|
|
41
|
+
webviewIntent: webviewIntent
|
|
38
42
|
});
|
|
39
43
|
},
|
|
40
44
|
label: t('Viewer.download')
|
|
@@ -19,6 +19,10 @@ var _react = _interopRequireWildcard(require("react"));
|
|
|
19
19
|
|
|
20
20
|
var _cozyClient = require("cozy-client");
|
|
21
21
|
|
|
22
|
+
var _file = require("cozy-client/dist/models/file");
|
|
23
|
+
|
|
24
|
+
var _cozyIntent = require("cozy-intent");
|
|
25
|
+
|
|
22
26
|
var _FileImageLoader = _interopRequireDefault(require("cozy-ui/transpiled/react/FileImageLoader"));
|
|
23
27
|
|
|
24
28
|
var _Spinner = _interopRequireDefault(require("cozy-ui/transpiled/react/Spinner"));
|
|
@@ -76,6 +80,7 @@ var PdfMobileViewer = function PdfMobileViewer(_ref) {
|
|
|
76
80
|
showAlert = _useAlert.showAlert;
|
|
77
81
|
|
|
78
82
|
var client = (0, _cozyClient.useClient)();
|
|
83
|
+
var webviewIntent = (0, _cozyIntent.useWebviewIntent)();
|
|
79
84
|
|
|
80
85
|
var onImageError = function onImageError() {
|
|
81
86
|
setLoading(false);
|
|
@@ -94,7 +99,11 @@ var PdfMobileViewer = function PdfMobileViewer(_ref) {
|
|
|
94
99
|
case 0:
|
|
95
100
|
_context.prev = 0;
|
|
96
101
|
_context.next = 3;
|
|
97
|
-
return
|
|
102
|
+
return (0, _file.downloadFile)({
|
|
103
|
+
client: client,
|
|
104
|
+
file: file,
|
|
105
|
+
webviewIntent: webviewIntent
|
|
106
|
+
});
|
|
98
107
|
|
|
99
108
|
case 3:
|
|
100
109
|
_context.next = 8;
|
|
@@ -121,7 +130,7 @@ var PdfMobileViewer = function PdfMobileViewer(_ref) {
|
|
|
121
130
|
return function (_x) {
|
|
122
131
|
return _ref2.apply(this, arguments);
|
|
123
132
|
};
|
|
124
|
-
}(), [client, showAlert, t]);
|
|
133
|
+
}(), [client, showAlert, t, webviewIntent]);
|
|
125
134
|
(0, _react.useEffect)(function () {
|
|
126
135
|
if (gestures) {
|
|
127
136
|
gestures.get('pinch').set({
|
|
@@ -17,6 +17,10 @@ var _react = _interopRequireDefault(require("react"));
|
|
|
17
17
|
|
|
18
18
|
var _cozyClient = require("cozy-client");
|
|
19
19
|
|
|
20
|
+
var _file = require("cozy-client/dist/models/file");
|
|
21
|
+
|
|
22
|
+
var _cozyIntent = require("cozy-intent");
|
|
23
|
+
|
|
20
24
|
var _Icon = _interopRequireDefault(require("cozy-ui/transpiled/react/Icon"));
|
|
21
25
|
|
|
22
26
|
var _IconButton = _interopRequireDefault(require("cozy-ui/transpiled/react/IconButton"));
|
|
@@ -41,8 +45,6 @@ var _ToolbarFilePath = require("./ToolbarFilePath");
|
|
|
41
45
|
|
|
42
46
|
var _helpers = require("../Footer/helpers");
|
|
43
47
|
|
|
44
|
-
var _helpers2 = require("../helpers");
|
|
45
|
-
|
|
46
48
|
var _EncryptedProvider = require("../providers/EncryptedProvider");
|
|
47
49
|
|
|
48
50
|
var styles = {
|
|
@@ -82,6 +84,8 @@ var Toolbar = function Toolbar(_ref) {
|
|
|
82
84
|
var _useI18n = (0, _I18n.useI18n)(),
|
|
83
85
|
t = _useI18n.t;
|
|
84
86
|
|
|
87
|
+
var webviewIntent = (0, _cozyIntent.useWebviewIntent)();
|
|
88
|
+
|
|
85
89
|
var _useEncrypted = (0, _EncryptedProvider.useEncrypted)(),
|
|
86
90
|
url = _useEncrypted.url;
|
|
87
91
|
|
|
@@ -121,10 +125,11 @@ var Toolbar = function Toolbar(_ref) {
|
|
|
121
125
|
className: "u-white",
|
|
122
126
|
"aria-label": t('Viewer.download'),
|
|
123
127
|
onClick: function onClick() {
|
|
124
|
-
return (0,
|
|
128
|
+
return (0, _file.downloadFile)({
|
|
125
129
|
client: client,
|
|
126
130
|
file: file,
|
|
127
|
-
url: url
|
|
131
|
+
url: url,
|
|
132
|
+
webviewIntent: webviewIntent
|
|
128
133
|
});
|
|
129
134
|
}
|
|
130
135
|
}, /*#__PURE__*/_react.default.createElement(_Icon.default, {
|
package/dist/helpers.d.ts
CHANGED
|
@@ -2,11 +2,6 @@ export function getCurrentModel(metadataName: any): "information" | "contact" |
|
|
|
2
2
|
export function isValidForPanel({ file }: {
|
|
3
3
|
file: IOCozyFile;
|
|
4
4
|
}): boolean;
|
|
5
|
-
export function downloadFile({ client, file, url }: {
|
|
6
|
-
client: any;
|
|
7
|
-
file: any;
|
|
8
|
-
url: any;
|
|
9
|
-
}): Promise<any>;
|
|
10
5
|
export function isFileEncrypted(file: any): any;
|
|
11
6
|
export function formatDate({ f, lang, date }: {
|
|
12
7
|
f: any;
|
package/dist/helpers.js
CHANGED
|
@@ -5,14 +5,10 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.removeFilenameFromPath = exports.normalizeAndSpreadAttributes = exports.makeWebLink = exports.isValidForPanel = exports.isFileEncrypted = exports.isEditableAttribute = exports.getCurrentModel = exports.formatDate = exports.
|
|
9
|
-
|
|
10
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
8
|
+
exports.removeFilenameFromPath = exports.normalizeAndSpreadAttributes = exports.makeWebLink = exports.isValidForPanel = exports.isFileEncrypted = exports.isEditableAttribute = exports.getCurrentModel = exports.formatDate = exports.buildEditAttributePath = void 0;
|
|
11
9
|
|
|
12
10
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
13
11
|
|
|
14
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
15
|
-
|
|
16
12
|
var _cozyClient = require("cozy-client");
|
|
17
13
|
|
|
18
14
|
var _file = require("cozy-client/dist/models/file");
|
|
@@ -58,50 +54,16 @@ var isValidForPanel = function isValidForPanel(_ref) {
|
|
|
58
54
|
|
|
59
55
|
exports.isValidForPanel = isValidForPanel;
|
|
60
56
|
|
|
61
|
-
var downloadFile = /*#__PURE__*/function () {
|
|
62
|
-
var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(_ref2) {
|
|
63
|
-
var client, file, url;
|
|
64
|
-
return _regenerator.default.wrap(function _callee$(_context) {
|
|
65
|
-
while (1) {
|
|
66
|
-
switch (_context.prev = _context.next) {
|
|
67
|
-
case 0:
|
|
68
|
-
client = _ref2.client, file = _ref2.file, url = _ref2.url;
|
|
69
|
-
|
|
70
|
-
if (!(0, _file.isEncrypted)(file)) {
|
|
71
|
-
_context.next = 3;
|
|
72
|
-
break;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return _context.abrupt("return", client.collection('io.cozy.files').forceFileDownload(url, file.name));
|
|
76
|
-
|
|
77
|
-
case 3:
|
|
78
|
-
return _context.abrupt("return", client.collection('io.cozy.files').download(file));
|
|
79
|
-
|
|
80
|
-
case 4:
|
|
81
|
-
case "end":
|
|
82
|
-
return _context.stop();
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}, _callee);
|
|
86
|
-
}));
|
|
87
|
-
|
|
88
|
-
return function downloadFile(_x) {
|
|
89
|
-
return _ref3.apply(this, arguments);
|
|
90
|
-
};
|
|
91
|
-
}();
|
|
92
|
-
|
|
93
|
-
exports.downloadFile = downloadFile;
|
|
94
|
-
|
|
95
57
|
var isFileEncrypted = function isFileEncrypted(file) {
|
|
96
58
|
return (0, _file.isEncrypted)(file);
|
|
97
59
|
};
|
|
98
60
|
|
|
99
61
|
exports.isFileEncrypted = isFileEncrypted;
|
|
100
62
|
|
|
101
|
-
var formatDate = function formatDate(
|
|
102
|
-
var f =
|
|
103
|
-
lang =
|
|
104
|
-
date =
|
|
63
|
+
var formatDate = function formatDate(_ref2) {
|
|
64
|
+
var f = _ref2.f,
|
|
65
|
+
lang = _ref2.lang,
|
|
66
|
+
date = _ref2.date;
|
|
105
67
|
|
|
106
68
|
if (lang === 'en') {
|
|
107
69
|
return f(date, 'MM/DD/YYYY');
|
|
@@ -151,10 +113,10 @@ var normalizeAndSpreadAttributes = function normalizeAndSpreadAttributes(rawFile
|
|
|
151
113
|
|
|
152
114
|
exports.normalizeAndSpreadAttributes = normalizeAndSpreadAttributes;
|
|
153
115
|
|
|
154
|
-
var makeWebLink = function makeWebLink(
|
|
155
|
-
var client =
|
|
156
|
-
slug =
|
|
157
|
-
path =
|
|
116
|
+
var makeWebLink = function makeWebLink(_ref3) {
|
|
117
|
+
var client = _ref3.client,
|
|
118
|
+
slug = _ref3.slug,
|
|
119
|
+
path = _ref3.path;
|
|
158
120
|
|
|
159
121
|
try {
|
|
160
122
|
var cozyURL = new URL(client.getStackClient().uri);
|
package/dist/stylesheet.css
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/* imported from styles.styl */
|
|
2
2
|
|
|
3
|
-
.
|
|
4
|
-
.
|
|
5
|
-
.
|
|
6
|
-
.
|
|
7
|
-
.
|
|
8
|
-
.
|
|
9
|
-
.
|
|
3
|
+
.styles__viewer-imageviewer___2O8pW,
|
|
4
|
+
.styles__viewer-noviewer___3HRGf,
|
|
5
|
+
.styles__viewer-audioviewer___dpxUM,
|
|
6
|
+
.styles__viewer-videoviewer___3yUQ5,
|
|
7
|
+
.styles__viewer-pdfviewer___3MJPk,
|
|
8
|
+
.styles__viewer-textviewer___1fl1c,
|
|
9
|
+
.styles__viewer-canceled___3KRBk {
|
|
10
10
|
position: relative;
|
|
11
11
|
display: flex;
|
|
12
12
|
width: 60%;
|
|
@@ -16,111 +16,135 @@
|
|
|
16
16
|
flex-direction: column;
|
|
17
17
|
margin-top: 4rem;
|
|
18
18
|
}
|
|
19
|
-
.
|
|
20
|
-
.
|
|
21
|
-
.
|
|
22
|
-
.
|
|
23
|
-
.
|
|
24
|
-
.
|
|
25
|
-
.
|
|
19
|
+
.styles__viewer-imageviewer___2O8pW h2,
|
|
20
|
+
.styles__viewer-noviewer___3HRGf h2,
|
|
21
|
+
.styles__viewer-audioviewer___dpxUM h2,
|
|
22
|
+
.styles__viewer-videoviewer___3yUQ5 h2,
|
|
23
|
+
.styles__viewer-pdfviewer___3MJPk h2,
|
|
24
|
+
.styles__viewer-textviewer___1fl1c h2,
|
|
25
|
+
.styles__viewer-canceled___3KRBk h2 {
|
|
26
26
|
max-width: 90%;
|
|
27
27
|
}
|
|
28
28
|
@media (max-width: 63.938rem) {
|
|
29
|
-
.
|
|
30
|
-
.
|
|
31
|
-
.
|
|
32
|
-
.
|
|
33
|
-
.
|
|
34
|
-
.
|
|
35
|
-
.
|
|
29
|
+
.styles__viewer-imageviewer___2O8pW,
|
|
30
|
+
.styles__viewer-noviewer___3HRGf,
|
|
31
|
+
.styles__viewer-audioviewer___dpxUM,
|
|
32
|
+
.styles__viewer-videoviewer___3yUQ5,
|
|
33
|
+
.styles__viewer-pdfviewer___3MJPk,
|
|
34
|
+
.styles__viewer-textviewer___1fl1c,
|
|
35
|
+
.styles__viewer-canceled___3KRBk {
|
|
36
36
|
margin-left: 0;
|
|
37
37
|
width: 100%;
|
|
38
38
|
max-height: calc(100% - 6.5rem);
|
|
39
39
|
margin-top: -0.5rem;
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
|
-
.
|
|
42
|
+
.styles__viewer-videoviewer___3yUQ5 video {
|
|
43
43
|
width: 100%;
|
|
44
44
|
max-width: 31.25rem;
|
|
45
45
|
height: auto;
|
|
46
46
|
}
|
|
47
|
-
.
|
|
47
|
+
.styles__viewer-textviewer___1fl1c .styles__viewer-textviewer-content___30dhP {
|
|
48
48
|
white-space: pre-line;
|
|
49
49
|
width: 100%;
|
|
50
50
|
max-height: 70%;
|
|
51
51
|
overflow: auto;
|
|
52
52
|
}
|
|
53
|
-
.
|
|
53
|
+
.styles__viewer-textviewer___1fl1c a {
|
|
54
54
|
color: var(--azure);
|
|
55
55
|
}
|
|
56
56
|
@media (max-width: 63.938rem) {
|
|
57
|
-
.
|
|
57
|
+
.styles__viewer-textviewer___1fl1c {
|
|
58
58
|
width: 90%;
|
|
59
59
|
margin-left: 5%;
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
|
-
.
|
|
62
|
+
.styles__viewer-filename___1-DIz {
|
|
63
63
|
max-width: 90%;
|
|
64
64
|
text-overflow: ellipsis;
|
|
65
65
|
overflow: hidden;
|
|
66
66
|
}
|
|
67
|
-
.
|
|
67
|
+
.styles__viewer-pdfviewer-pdf___3R4jL {
|
|
68
68
|
overflow: auto;
|
|
69
69
|
width: 100%;
|
|
70
70
|
}
|
|
71
|
-
.
|
|
71
|
+
.styles__viewer-pdfviewer-page___VvOF3 > * {
|
|
72
72
|
margin: auto;
|
|
73
73
|
}
|
|
74
|
-
.
|
|
74
|
+
.styles__viewer-pdfviewer-toolbar___2Eat3 {
|
|
75
75
|
position: absolute;
|
|
76
76
|
bottom: 2rem;
|
|
77
77
|
background: var(--charcoalGrey);
|
|
78
78
|
color: var(--white);
|
|
79
79
|
border-radius: 0.5rem;
|
|
80
80
|
}
|
|
81
|
-
.
|
|
81
|
+
.styles__viewer-imageviewer___2O8pW {
|
|
82
82
|
flex: 1 1 100%;
|
|
83
83
|
width: auto;
|
|
84
84
|
max-width: 100%;
|
|
85
85
|
}
|
|
86
|
-
.
|
|
86
|
+
.styles__viewer-imageviewer___2O8pW img {
|
|
87
87
|
display: block;
|
|
88
88
|
max-width: 100%;
|
|
89
89
|
max-height: 100%;
|
|
90
90
|
box-shadow: 0 0.375rem 1.5rem 0 rgba(0,0,0,0.5);
|
|
91
91
|
}
|
|
92
|
-
.
|
|
92
|
+
.styles__viewer-pdfMobile___ym7we {
|
|
93
93
|
width: 100%;
|
|
94
94
|
height: calc(100% - 6.5rem - var(--flagship-top-height));
|
|
95
95
|
margin-top: calc(var(--flagship-top-height, 0rem) + -0.5rem);
|
|
96
96
|
}
|
|
97
|
-
.
|
|
97
|
+
.styles__viewer-pdfMobile--image___3_zsS {
|
|
98
98
|
width: 100%;
|
|
99
99
|
}
|
|
100
100
|
/* imported from styles.styl */
|
|
101
101
|
|
|
102
|
-
.
|
|
102
|
+
.styles__ActionMenuDesktop-ActionMenu___xxTwZ a {
|
|
103
103
|
padding: 0 !important;
|
|
104
104
|
}
|
|
105
|
-
.
|
|
105
|
+
.styles__ActionMenuDesktop-ActionMenu___xxTwZ .styles__ActionMenuDesktop-ActionMenu-link-disabled___93DWz > div {
|
|
106
106
|
cursor: default;
|
|
107
107
|
}
|
|
108
|
-
.
|
|
108
|
+
.styles__ActionMenuDesktop-ActionMenu___xxTwZ .styles__ActionMenuDesktop-ActionMenu-link-disabled___93DWz > div:hover {
|
|
109
109
|
background-color: initial;
|
|
110
110
|
}
|
|
111
|
-
.
|
|
111
|
+
.styles__ActionMenuDesktop-ActionMenu___xxTwZ .styles__ActionMenuDesktop-ActionMenu-link-disabled___93DWz > div > div svg {
|
|
112
112
|
fill: var(--disabledTextColor);
|
|
113
113
|
}
|
|
114
|
-
.
|
|
114
|
+
.styles__ActionMenuDesktop-ActionMenu___xxTwZ .styles__ActionMenuDesktop-ActionMenu-link-disabled___93DWz > div > div p {
|
|
115
115
|
color: var(--disabledTextColor);
|
|
116
116
|
}
|
|
117
117
|
/* imported from styles.styl */
|
|
118
118
|
|
|
119
|
+
.styles__viewer-wrapper___OkRf5 {
|
|
120
|
+
position: absolute;
|
|
121
|
+
left: 0;
|
|
122
|
+
right: 0;
|
|
123
|
+
top: 0;
|
|
124
|
+
bottom: 0;
|
|
125
|
+
z-index: var(--zIndex-overlay);
|
|
126
|
+
overflow: hidden;
|
|
127
|
+
background: var(--charcoalGrey);
|
|
128
|
+
color: var(--white);
|
|
129
|
+
display: flex;
|
|
130
|
+
}
|
|
131
|
+
.styles__flagship-app___2EqfW .styles__viewer-wrapper___OkRf5 {
|
|
132
|
+
padding-top: var(--flagship-top-height);
|
|
133
|
+
padding-bottom: var(--flagship-bottom-height);
|
|
134
|
+
}
|
|
135
|
+
@media (max-width: 63.938rem) {
|
|
136
|
+
.styles__viewer-wrapper___OkRf5 {
|
|
137
|
+
color: var(--primaryTextColor);
|
|
138
|
+
background: var(--paperBackgroundColor);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
/* imported from styles.styl */
|
|
142
|
+
|
|
119
143
|
@media (max-width: 48rem) {
|
|
120
144
|
}
|
|
121
145
|
@media (max-width: 63.938rem) {
|
|
122
146
|
}
|
|
123
|
-
.
|
|
147
|
+
.styles__viewer-nav___3V03k {
|
|
124
148
|
position: absolute;
|
|
125
149
|
top: 4rem;
|
|
126
150
|
bottom: 0;
|
|
@@ -135,34 +159,34 @@
|
|
|
135
159
|
justify-content: center;
|
|
136
160
|
flex-direction: column;
|
|
137
161
|
}
|
|
138
|
-
.
|
|
162
|
+
.styles__viewer-nav--visible___4GLTe:hover {
|
|
139
163
|
opacity: 1;
|
|
140
164
|
transition: none;
|
|
141
165
|
}
|
|
142
|
-
.
|
|
166
|
+
.styles__viewer-nav--previous___2LsMS {
|
|
143
167
|
left: 0;
|
|
144
168
|
}
|
|
145
|
-
.
|
|
169
|
+
.styles__viewer-nav--previous___2LsMS .styles__viewer-nav-arrow___Z0ykc {
|
|
146
170
|
align-self: flex-start;
|
|
147
171
|
margin-left: 2.5rem;
|
|
148
172
|
transform: rotate(180deg);
|
|
149
173
|
}
|
|
150
|
-
.
|
|
174
|
+
.styles__viewer-nav--next___3mBHi {
|
|
151
175
|
right: 0;
|
|
152
176
|
}
|
|
153
|
-
.
|
|
177
|
+
.styles__viewer-nav--next___3mBHi .styles__viewer-nav-arrow___Z0ykc {
|
|
154
178
|
align-self: flex-end;
|
|
155
179
|
margin-right: 2.5rem;
|
|
156
180
|
}
|
|
157
181
|
@media (max-width: 63.938rem) {
|
|
158
|
-
.
|
|
182
|
+
.styles__viewer-nav___3V03k {
|
|
159
183
|
display: none;
|
|
160
184
|
}
|
|
161
185
|
}
|
|
162
|
-
.
|
|
186
|
+
.styles__viewer-nav-arrow___Z0ykc {
|
|
163
187
|
opacity: 0.7;
|
|
164
188
|
}
|
|
165
|
-
.
|
|
189
|
+
.styles__viewer-controls___2lf-z {
|
|
166
190
|
position: relative;
|
|
167
191
|
display: flex;
|
|
168
192
|
flex-direction: column;
|
|
@@ -171,17 +195,17 @@
|
|
|
171
195
|
width: 100%;
|
|
172
196
|
height: 100%;
|
|
173
197
|
}
|
|
174
|
-
.
|
|
198
|
+
.styles__viewer-controls___2lf-z.styles__--expanded___1sp4Q .styles__viewer-nav___3V03k {
|
|
175
199
|
margin-top: 0;
|
|
176
200
|
width: 40%;
|
|
177
201
|
}
|
|
178
202
|
@media (max-width: 63.938rem) {
|
|
179
|
-
.
|
|
203
|
+
.styles__viewer-controls--display-content-top___3wszk {
|
|
180
204
|
justify-content: flex-start;
|
|
181
205
|
padding-top: 4.5rem;
|
|
182
206
|
}
|
|
183
207
|
}
|
|
184
|
-
.
|
|
208
|
+
.styles__viewer-toolbar___1GLOA {
|
|
185
209
|
position: absolute;
|
|
186
210
|
top: 0;
|
|
187
211
|
z-index: var(--zIndex-modal-toolbar);
|
|
@@ -195,11 +219,11 @@
|
|
|
195
219
|
justify-content: flex-start;
|
|
196
220
|
align-items: center;
|
|
197
221
|
}
|
|
198
|
-
.
|
|
222
|
+
.styles__viewer-toolbar--hidden___Zq97m {
|
|
199
223
|
opacity: 0;
|
|
200
224
|
}
|
|
201
225
|
@media (max-width: 63.938rem) {
|
|
202
|
-
.
|
|
226
|
+
.styles__viewer-toolbar___1GLOA {
|
|
203
227
|
height: 3rem;
|
|
204
228
|
width: 100%;
|
|
205
229
|
padding: var(--flagship-top-height) 1rem 0 0;
|
|
@@ -207,7 +231,7 @@
|
|
|
207
231
|
border-bottom: 1px solid var(--dividerColor);
|
|
208
232
|
}
|
|
209
233
|
}
|
|
210
|
-
.
|
|
234
|
+
.styles__viewer-footer___iGv8J {
|
|
211
235
|
position: fixed;
|
|
212
236
|
bottom: 0;
|
|
213
237
|
z-index: var(--zIndex-modal-footer);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cozy-viewer",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.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",
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
"scripts": {
|
|
16
16
|
"build": "rm -rf ./dist && tsc -p tsconfig-build.json && env BABEL_ENV=transpilation babel --extensions .ts,.tsx,.js,.jsx,.md,.styl,.json,.snap ./src -d ./dist --copy-files --no-copy-ignored --verbose",
|
|
17
17
|
"start": "yarn build --watch",
|
|
18
|
-
"
|
|
18
|
+
"prepublishOnly": "yarn build",
|
|
19
|
+
"test": "env NODE_ENV=test jest",
|
|
19
20
|
"lint": "cd .. && yarn eslint --ext js,jsx packages/cozy-viewer"
|
|
20
21
|
},
|
|
21
22
|
"devDependencies": {
|
|
@@ -49,7 +50,7 @@
|
|
|
49
50
|
"react-pdf": "^5.7.2"
|
|
50
51
|
},
|
|
51
52
|
"peerDependencies": {
|
|
52
|
-
"cozy-client": ">=
|
|
53
|
+
"cozy-client": ">=49.0.0",
|
|
53
54
|
"cozy-device-helper": ">=2.0.0",
|
|
54
55
|
"cozy-harvest-lib": ">=6.7.3",
|
|
55
56
|
"cozy-intent": ">=1.16.1",
|
|
@@ -59,5 +60,5 @@
|
|
|
59
60
|
"react": ">=16.12.0",
|
|
60
61
|
"react-dom": ">=16.12.0"
|
|
61
62
|
},
|
|
62
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "85c208a18eabf2e7502b04362dc67342a30a6713"
|
|
63
64
|
}
|
|
@@ -2,18 +2,19 @@ import PropTypes from 'prop-types'
|
|
|
2
2
|
import React from 'react'
|
|
3
3
|
|
|
4
4
|
import { withClient } from 'cozy-client'
|
|
5
|
+
import { downloadFile } from 'cozy-client/dist/models/file'
|
|
6
|
+
import { useWebviewIntent } from 'cozy-intent'
|
|
5
7
|
import Button from 'cozy-ui/transpiled/react/deprecated/Button'
|
|
6
8
|
import { FileDoctype } from 'cozy-ui/transpiled/react/proptypes'
|
|
7
9
|
import { useI18n } from 'cozy-ui/transpiled/react/providers/I18n'
|
|
8
10
|
|
|
9
|
-
import { downloadFile } from '../helpers'
|
|
10
|
-
|
|
11
11
|
const DownloadButton = ({ client, file, url }) => {
|
|
12
12
|
const { t } = useI18n()
|
|
13
|
+
const webviewIntent = useWebviewIntent()
|
|
13
14
|
|
|
14
15
|
return (
|
|
15
16
|
<Button
|
|
16
|
-
onClick={() => downloadFile({ client, file, url })}
|
|
17
|
+
onClick={() => downloadFile({ client, file, url, webviewIntent })}
|
|
17
18
|
label={t('Viewer.download')}
|
|
18
19
|
/>
|
|
19
20
|
)
|
|
@@ -2,6 +2,8 @@ import PropTypes from 'prop-types'
|
|
|
2
2
|
import React, { useState, useEffect, useRef, useCallback } from 'react'
|
|
3
3
|
|
|
4
4
|
import { useClient } from 'cozy-client'
|
|
5
|
+
import { downloadFile } from 'cozy-client/dist/models/file'
|
|
6
|
+
import { useWebviewIntent } from 'cozy-intent'
|
|
5
7
|
import FileImageLoader from 'cozy-ui/transpiled/react/FileImageLoader'
|
|
6
8
|
import Spinner from 'cozy-ui/transpiled/react/Spinner'
|
|
7
9
|
import { FileDoctype } from 'cozy-ui/transpiled/react/proptypes'
|
|
@@ -19,6 +21,7 @@ export const PdfMobileViewer = ({ file, url, t, gestures }) => {
|
|
|
19
21
|
const { showAlert } = useAlert()
|
|
20
22
|
|
|
21
23
|
const client = useClient()
|
|
24
|
+
const webviewIntent = useWebviewIntent()
|
|
22
25
|
|
|
23
26
|
const onImageError = () => {
|
|
24
27
|
setLoading(false)
|
|
@@ -32,7 +35,7 @@ export const PdfMobileViewer = ({ file, url, t, gestures }) => {
|
|
|
32
35
|
const handleOnClick = useCallback(
|
|
33
36
|
async file => {
|
|
34
37
|
try {
|
|
35
|
-
await client
|
|
38
|
+
await downloadFile({ client, file, webviewIntent })
|
|
36
39
|
} catch (error) {
|
|
37
40
|
showAlert({
|
|
38
41
|
message: t('Viewer.error.generic'),
|
|
@@ -42,7 +45,7 @@ export const PdfMobileViewer = ({ file, url, t, gestures }) => {
|
|
|
42
45
|
})
|
|
43
46
|
}
|
|
44
47
|
},
|
|
45
|
-
[client, showAlert, t]
|
|
48
|
+
[client, showAlert, t, webviewIntent]
|
|
46
49
|
)
|
|
47
50
|
|
|
48
51
|
useEffect(() => {
|
|
@@ -3,6 +3,8 @@ import PropTypes from 'prop-types'
|
|
|
3
3
|
import React from 'react'
|
|
4
4
|
|
|
5
5
|
import { useClient } from 'cozy-client'
|
|
6
|
+
import { downloadFile } from 'cozy-client/dist/models/file'
|
|
7
|
+
import { useWebviewIntent } from 'cozy-intent'
|
|
6
8
|
import Icon from 'cozy-ui/transpiled/react/Icon'
|
|
7
9
|
import IconButton from 'cozy-ui/transpiled/react/IconButton'
|
|
8
10
|
import DownloadIcon from 'cozy-ui/transpiled/react/Icons/Download'
|
|
@@ -17,7 +19,6 @@ import PrintButton from './PrintButton'
|
|
|
17
19
|
import { ToolbarFilePath } from './ToolbarFilePath'
|
|
18
20
|
import styles from './styles.styl'
|
|
19
21
|
import { extractChildrenCompByName } from '../Footer/helpers'
|
|
20
|
-
import { downloadFile } from '../helpers'
|
|
21
22
|
import { useEncrypted } from '../providers/EncryptedProvider'
|
|
22
23
|
|
|
23
24
|
const useClasses = makeStyles(theme => ({
|
|
@@ -42,6 +43,7 @@ const Toolbar = ({
|
|
|
42
43
|
const client = useClient()
|
|
43
44
|
const classes = useClasses()
|
|
44
45
|
const { t } = useI18n()
|
|
46
|
+
const webviewIntent = useWebviewIntent()
|
|
45
47
|
|
|
46
48
|
const { url } = useEncrypted()
|
|
47
49
|
|
|
@@ -88,7 +90,7 @@ const Toolbar = ({
|
|
|
88
90
|
<IconButton
|
|
89
91
|
className="u-white"
|
|
90
92
|
aria-label={t('Viewer.download')}
|
|
91
|
-
onClick={() => downloadFile({ client, file, url })}
|
|
93
|
+
onClick={() => downloadFile({ client, file, url, webviewIntent })}
|
|
92
94
|
>
|
|
93
95
|
<Icon icon={DownloadIcon} />
|
|
94
96
|
</IconButton>
|
package/src/helpers.js
CHANGED
|
@@ -46,13 +46,6 @@ export const isValidForPanel = ({ file }) => {
|
|
|
46
46
|
)
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
export const downloadFile = async ({ client, file, url }) => {
|
|
50
|
-
if (isEncrypted(file)) {
|
|
51
|
-
return client.collection('io.cozy.files').forceFileDownload(url, file.name)
|
|
52
|
-
}
|
|
53
|
-
return client.collection('io.cozy.files').download(file)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
49
|
export const isFileEncrypted = file => isEncrypted(file)
|
|
57
50
|
|
|
58
51
|
export const formatDate = ({ f, lang, date }) => {
|
package/src/helpers.spec.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import { createMockClient } from 'cozy-client'
|
|
2
1
|
import {
|
|
3
2
|
KNOWN_DATE_METADATA_NAMES,
|
|
4
3
|
KNOWN_INFORMATION_METADATA_NAMES
|
|
5
4
|
} from 'cozy-client/dist/models/paper'
|
|
6
5
|
|
|
7
6
|
import {
|
|
8
|
-
downloadFile,
|
|
9
7
|
getCurrentModel,
|
|
10
8
|
buildEditAttributePath,
|
|
11
9
|
isEditableAttribute,
|
|
@@ -13,29 +11,6 @@ import {
|
|
|
13
11
|
} from './helpers'
|
|
14
12
|
|
|
15
13
|
describe('helpers', () => {
|
|
16
|
-
describe('download', () => {
|
|
17
|
-
const client = new createMockClient({})
|
|
18
|
-
const mockDownload = jest.fn()
|
|
19
|
-
const mockForceFileDownload = jest.fn()
|
|
20
|
-
client.collection = jest.fn(() => ({
|
|
21
|
-
download: mockDownload,
|
|
22
|
-
forceFileDownload: mockForceFileDownload
|
|
23
|
-
}))
|
|
24
|
-
|
|
25
|
-
it('should call download when file is not encrypted', async () => {
|
|
26
|
-
const file = { name: 'toto.txt' }
|
|
27
|
-
|
|
28
|
-
await downloadFile({ client, file })
|
|
29
|
-
expect(mockDownload).toHaveBeenCalledWith(file)
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
it('should call forceFileDownload when file is encrypted', async () => {
|
|
33
|
-
const file = { name: 'encrypted-toto.txt', encrypted: true }
|
|
34
|
-
const url = 'blob:http://thedecryptedtoto'
|
|
35
|
-
await downloadFile({ client, file, url })
|
|
36
|
-
expect(mockForceFileDownload).toHaveBeenCalledWith(url, file.name)
|
|
37
|
-
})
|
|
38
|
-
})
|
|
39
14
|
describe('getCurrentModel', () => {
|
|
40
15
|
const expected = 'information'
|
|
41
16
|
it.each([
|