cozy-viewer 30.0.55 → 31.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 CHANGED
@@ -3,6 +3,21 @@
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
+ # [31.0.0](https://github.com/cozy/cozy-libs/compare/cozy-viewer@30.0.55...cozy-viewer@31.0.0) (2026-10-05)
7
+
8
+ ### Bug Fixes
9
+
10
+ - **cozy-viewer:** Keep the text viewer scrollbar clickable ([d1a743e](https://github.com/cozy/cozy-libs/commit/d1a743e8428d5f7c15391037d135750ddfd5559c))
11
+ - **cozy-viewer:** Upgrade react-markdown to 6.0.3 ([13cb65f](https://github.com/cozy/cozy-libs/commit/13cb65f912a8fdea6be4a7c1e1fc05bfb066935e))
12
+
13
+ ### Features
14
+
15
+ - **cozy-viewer:** Upgrade react-pdf to 9.2.1 ([844097e](https://github.com/cozy/cozy-libs/commit/844097ed521349bc1c574da522beca047a7ada43))
16
+
17
+ ### BREAKING CHANGES
18
+
19
+ - **cozy-viewer:** react-pdf 9 requires React >= 16.14.0 and no longer ships the webpack entries that configured the pdf.js worker. Remove any `react-pdf$` alias and set `pdfjs.GlobalWorkerOptions.workerSrc` in your app, see the cozy-viewer Readme.
20
+
6
21
  ## [30.0.55](https://github.com/cozy/cozy-libs/compare/cozy-viewer@30.0.54...cozy-viewer@30.0.55) (2026-10-05)
7
22
 
8
23
  **Note:** Version bump only for package cozy-viewer
@@ -71,9 +71,8 @@ var styles = {
71
71
  var MarkdownRenderer = function MarkdownRenderer(_ref) {
72
72
  var text = _ref.text;
73
73
  return /*#__PURE__*/_react.default.createElement(_reactMarkdown.default, {
74
- className: (0, _classnames.default)(styles['viewer-textviewer-content'], 'u-p-1'),
75
- source: text
76
- });
74
+ className: (0, _classnames.default)(styles['viewer-textviewer-content'], 'u-p-1')
75
+ }, text);
77
76
  };
78
77
 
79
78
  var PlainTextRenderer = function PlainTextRenderer(_ref2) {
@@ -63,6 +63,7 @@
63
63
  }
64
64
  .styles__viewer-textviewer___1fl1c .styles__viewer-textviewer-content___30dhP {
65
65
  white-space: pre-line;
66
+ box-sizing: border-box;
66
67
  width: 100%;
67
68
  max-height: 70%;
68
69
  overflow: auto;
package/jest.config.js CHANGED
@@ -9,7 +9,8 @@ module.exports = {
9
9
  moduleNameMapper: {
10
10
  '\\.(png|gif|jpe?g|svg)$': '<rootDir>/test/__mocks__/fileMock.js',
11
11
  '\\.styl$': 'identity-obj-proxy',
12
- 'react-pdf/dist/esm/entry.webpack': 'react-pdf',
12
+ // react-pdf needs react/jsx-runtime, missing from the monorepo's React 16.12
13
+ '^react-pdf$': '<rootDir>/test/__mocks__/react-pdf.js',
13
14
  '^cozy-client/src/(.*)$': '<rootDir>/node_modules/cozy-client/dist/$1',
14
15
  '^cozy-client$': '<rootDir>/node_modules/cozy-client/dist/index',
15
16
  '^cozy-client/dist/(.*)$': '<rootDir>/node_modules/cozy-client/dist/$1',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-viewer",
3
- "version": "30.0.55",
3
+ "version": "31.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",
@@ -53,8 +53,8 @@
53
53
  "classnames": "^2.5.1",
54
54
  "hammerjs": "^2.0.8",
55
55
  "lodash": "^4.17.21",
56
- "react-markdown": "^4.0.8",
57
- "react-pdf": "^5.7.2"
56
+ "react-markdown": "^6.0.3",
57
+ "react-pdf": "^9.2.1"
58
58
  },
59
59
  "peerDependencies": {
60
60
  "@linagora/twake-icons": ">=2.6.6",
@@ -66,10 +66,10 @@
66
66
  "cozy-sharing": ">=30.0.0",
67
67
  "cozy-ui": ">=138.1.0",
68
68
  "cozy-ui-plus": ">=6.0.0",
69
- "react": ">=16.12.0",
70
- "react-dom": ">=16.12.0",
69
+ "react": ">=16.14.0",
70
+ "react-dom": ">=16.14.0",
71
71
  "react-router-dom": ">=6.14.2",
72
72
  "twake-i18n": ">=0.3.0"
73
73
  },
74
- "gitHead": "17bfcc354f9462050e38fa5c826b4e2cc91fedd3"
74
+ "gitHead": "4f5afde6a7bb139332739a93efc455ea9e088b81"
75
75
  }
package/src/Readme.md CHANGED
@@ -297,42 +297,39 @@ const onFileChange = (file, nextIndex) => setState({ currentIndex: nextIndex, cu
297
297
 
298
298
  ### Using a worker for pdfjs
299
299
 
300
- For performance reasons, it is important to use a web worker when showing PDF files in the viewer. If you use webpack, you should add the following alias in your configuration :
301
-
302
- ```diff
303
- + resolve: {
304
- + alias: {
305
- + 'react-pdf$' : 'react-pdf/dist/esm/entry.webpack'
306
- + }
307
- + }
308
- ```
309
-
310
- With this alias, a specific JS file for the worker will be created in the build directory. By design, this directory is only accessible (ie. served by the stack) if you are logged in. If you need the viewer on a public page, you must tell webpack to create the worker in a public folder, that will be served by the stack even if the user is not logged in.
311
-
312
- One way to do this is to explicitly load the web worker in your application like this:
300
+ The PDF viewer relies on [react-pdf](https://github.com/wojtekmaj/react-pdf), which needs the pdf.js worker to be configured by your application, once, before a PDF is shown:
313
301
 
314
302
  ```js static
315
- import createWorker from 'react-pdf/dist/esm/pdf.worker.entry';
316
- import { pdfjs } from 'react-pdf';
303
+ import { pdfjs } from 'react-pdf'
317
304
 
318
- pdfjs.GlobalWorkerOptions.workerPort = createWorker();
305
+ pdfjs.GlobalWorkerOptions.workerSrc = new URL(
306
+ 'pdfjs-dist/legacy/build/pdf.worker.min.mjs',
307
+ import.meta.url
308
+ ).toString()
319
309
  ```
320
310
 
321
- And then configure the [webpack worker-loader](https://github.com/webpack-contrib/worker-loader) to output the file in a publicly served directory:
311
+ With Webpack 5 or Rspack, also add this configuration:
322
312
 
323
313
  ```js static
324
- {
325
- test: /\.worker\.entry\.js$/,
326
- issuer: { not: [/node_modules\//] }, // only for the worker loaded by the app, leave the workers created by dependencies alone
327
- use: [{
328
- loader: 'worker-loader',
329
- options: {
330
- name: 'public-folder/[name].[hash].worker.js'
331
- }
332
- }]
314
+ resolve: {
315
+ alias: {
316
+ 'react-pdf$': 'react-pdf/dist/esm/index.js',
317
+ 'pdfjs-dist$': 'pdfjs-dist/legacy/build/pdf.mjs'
318
+ }
319
+ },
320
+ module: {
321
+ rules: [
322
+ { test: /react-pdf[\\/]dist[\\/]esm[\\/]index\.js$/, sideEffects: true }
323
+ ]
333
324
  }
334
325
  ```
335
326
 
327
+ - react-pdf resets `workerSrc` to `'pdf.worker.mjs'` when it loads. cozy-viewer requires its CommonJS build while your app imports the ESM one: the `react-pdf$` alias keeps a single build, so it cannot load again after your setup.
328
+ - react-pdf declares no side effects, so the bundler may skip its index when you import `pdfjs` and run it later. The `sideEffects` rule runs it first.
329
+ - The `legacy` build of pdf.js supports browsers without `Promise.withResolvers` (iOS and Safari before 17.4), in the main thread and in the worker.
330
+
331
+ The worker is emitted as an asset. If the viewer is used on a public page, make sure it is written to a folder served by the stack without authentication (for example with `output.assetModuleFilename: 'static/resource/[hash][ext][query]'`).
332
+
336
333
  ### Only works with React
337
334
 
338
335
  The `Viewer` can be used only in a `React` Application. You can't use it with `Preact`.
@@ -13,10 +13,9 @@ import { isFileEncrypted } from '../helpers'
13
13
  import withFileUrl from '../hoc/withFileUrl'
14
14
 
15
15
  const MarkdownRenderer = ({ text }) => (
16
- <ReactMarkdown
17
- className={cx(styles['viewer-textviewer-content'], 'u-p-1')}
18
- source={text}
19
- />
16
+ <ReactMarkdown className={cx(styles['viewer-textviewer-content'], 'u-p-1')}>
17
+ {text}
18
+ </ReactMarkdown>
20
19
  )
21
20
 
22
21
  const PlainTextRenderer = ({ text }) => (
@@ -52,6 +52,7 @@
52
52
  .viewer-textviewer
53
53
  .viewer-textviewer-content
54
54
  white-space pre-line
55
+ box-sizing border-box
55
56
  width 100%
56
57
  max-height 70%
57
58
  overflow auto
@@ -0,0 +1,5 @@
1
+ module.exports = {
2
+ Document: ({ children }) => children,
3
+ Page: () => null,
4
+ pdfjs: { GlobalWorkerOptions: {} }
5
+ }