cozy-viewer 1.1.2 → 2.0.1

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 CHANGED
@@ -3,6 +3,29 @@
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.1](https://github.com/cozy/cozy-libs/compare/cozy-viewer@2.0.0...cozy-viewer@2.0.1) (2024-10-15)
7
+
8
+ **Note:** Version bump only for package cozy-viewer
9
+
10
+
11
+
12
+
13
+
14
+ # [2.0.0](https://github.com/cozy/cozy-libs/compare/cozy-viewer@1.1.2...cozy-viewer@2.0.0) (2024-09-24)
15
+
16
+ ### Features
17
+
18
+ - **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)
19
+ - **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)
20
+
21
+ ### BREAKING CHANGES
22
+
23
+ - **cozy-viewer:** `downloadFile()` method has been removed from
24
+ `cozy-viewer/src/helpers.js`. Use the one from
25
+ `cozy-client/dist/models/file` instead
26
+ - **cozy-viewer:** cozy-viewer now requires cozy-client >= 49.0.0 (used
27
+ for offline support)
28
+
6
29
  ## [1.1.2](https://github.com/cozy/cozy-libs/compare/cozy-viewer@1.1.1...cozy-viewer@1.1.2) (2024-09-12)
7
30
 
8
31
  ### Bug Fixes
@@ -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, _helpers.downloadFile)({
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 client.collection('io.cozy.files').download(file);
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, _helpers2.downloadFile)({
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.downloadFile = exports.buildEditAttributePath = void 0;
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(_ref4) {
102
- var f = _ref4.f,
103
- lang = _ref4.lang,
104
- date = _ref4.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(_ref5) {
155
- var client = _ref5.client,
156
- slug = _ref5.slug,
157
- path = _ref5.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-viewer",
3
- "version": "1.1.2",
3
+ "version": "2.0.1",
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,7 +24,7 @@
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.1.0",
27
+ "babel-preset-cozy-app": "^2.2.0",
28
28
  "cozy-client": "48.8.0",
29
29
  "cozy-device-helper": "2.0.0",
30
30
  "cozy-harvest-lib": "^6.7.3",
@@ -50,7 +50,7 @@
50
50
  "react-pdf": "^5.7.2"
51
51
  },
52
52
  "peerDependencies": {
53
- "cozy-client": ">=48.8.0",
53
+ "cozy-client": ">=49.0.0",
54
54
  "cozy-device-helper": ">=2.0.0",
55
55
  "cozy-harvest-lib": ">=6.7.3",
56
56
  "cozy-intent": ">=1.16.1",
@@ -60,5 +60,5 @@
60
60
  "react": ">=16.12.0",
61
61
  "react-dom": ">=16.12.0"
62
62
  },
63
- "gitHead": "0a9671a836c3831f788d59d3ec7a8307ec0724da"
63
+ "gitHead": "e9dcaac26718732ec692e8ac9eceed87fea22548"
64
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.collection('io.cozy.files').download(file)
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 }) => {
@@ -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([