@eeacms/volto-citation 1.0.0 → 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 CHANGED
@@ -4,7 +4,25 @@ All notable changes to this project will be documented in this file. Dates are d
4
4
 
5
5
  Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
6
6
 
7
- ### [1.0.0](https://github.com/eea/volto-citation/compare/0.1.5...1.0.0) - 22 April 2024
7
+ ### [2.0.0](https://github.com/eea/volto-citation/compare/1.1.0...2.0.0) - 25 March 2026
8
+
9
+ #### :rocket: New Features
10
+
11
+ - feat: Volto 18 support - refs #287700 [Alin Voinea - [`49034c8`](https://github.com/eea/volto-citation/commit/49034c8e3cb7ae94f4fefeb6f0e510cc2bd768e0)]
12
+
13
+ #### :house: Internal changes
14
+
15
+
16
+ #### :hammer_and_wrench: Others
17
+
18
+ - tests: Fix Sonar Qube tags - refs #297339 [Alin Voinea - [`fdc39bd`](https://github.com/eea/volto-citation/commit/fdc39bd7551f0c8c20581e10fcbde3e464ed01dd)]
19
+ ### [1.1.0](https://github.com/eea/volto-citation/compare/1.0.0...1.1.0) - 21 May 2024
20
+
21
+ #### :bug: Bug Fixes
22
+
23
+ - fix(performance): load citation-js only when used - refs #262122 [ichim-david - [`ccddd2a`](https://github.com/eea/volto-citation/commit/ccddd2aede2df9b445fd3f447c808ef86a2608a3)]
24
+
25
+ ## [1.0.0](https://github.com/eea/volto-citation/compare/0.1.5...1.0.0) - 22 April 2024
8
26
 
9
27
  #### :rocket: New Features
10
28
 
package/DEVELOP.md CHANGED
@@ -26,21 +26,20 @@
26
26
 
27
27
  ### Or add @eeacms/volto-citation to your Volto project
28
28
 
29
- Before starting make sure your development environment is properly set. See [Volto Developer Documentation](https://docs.voltocms.com/getting-started/install/)
29
+ Before starting make sure your development environment is properly set. See the official Plone documentation for [creating a project with Cookieplone](https://6.docs.plone.org/install/create-project-cookieplone.html) and [installing an add-on in development mode in Volto 18 and 19](https://6.docs.plone.org/volto/development/add-ons/install-an-add-on-dev-18.html).
30
30
 
31
- 1. Make sure you have installed `yo`, `@plone/generator-volto` and `mrs-developer`
31
+ For new Volto 18+ projects, use Cookieplone. It includes `mrs-developer` by default.
32
32
 
33
- npm install -g yo @plone/generator-volto mrs-developer
33
+ 1. Create a new Volto project with Cookieplone
34
34
 
35
- 1. Create new volto app
36
-
37
- yo @plone/volto my-volto-project --addon @eeacms/volto-citation --skip-install
38
- cd my-volto-project
35
+ uvx cookieplone project
36
+ cd project-title
39
37
 
40
38
  1. Add the following to `mrs.developer.json`:
41
39
 
42
40
  {
43
41
  "volto-citation": {
42
+ "output": "packages",
44
43
  "url": "https://github.com/eea/volto-citation.git",
45
44
  "package": "@eeacms/volto-citation",
46
45
  "branch": "develop",
@@ -48,28 +47,31 @@ Before starting make sure your development environment is properly set. See [Vol
48
47
  }
49
48
  }
50
49
 
51
- 1. Install
50
+ 1. Add `@eeacms/volto-citation` to the `addons` key in your project `volto.config.js`
51
+
52
+ 1. Install or refresh the project setup
52
53
 
53
- make develop
54
- yarn
54
+ make install
55
55
 
56
- 1. Start backend
56
+ 1. Start backend in one terminal
57
57
 
58
- docker run --pull always -it --rm --name plone -p 8080:8080 -e SITE=Plone plone/plone-backend
58
+ make backend-start
59
59
 
60
- ...wait for backend to setup and start - `Ready to handle requests`:
60
+ ...wait for backend to setup and start, ending with `Ready to handle requests`
61
61
 
62
62
  ...you can also check http://localhost:8080/Plone
63
63
 
64
- 1. Start frontend
64
+ 1. Start frontend in a second terminal
65
65
 
66
- yarn start
66
+ make frontend-start
67
67
 
68
68
  1. Go to http://localhost:3000
69
69
 
70
70
  1. Happy hacking!
71
71
 
72
- cd src/addons/volto-citation/
72
+ cd packages/volto-citation
73
+
74
+ For legacy Volto 17 projects, keep using the yarn-based workflow from the Volto 17 documentation.
73
75
 
74
76
  ## Cypress
75
77
 
@@ -81,7 +83,7 @@ project where you added `volto-citation` to `mrs.developer.json`
81
83
  Go to:
82
84
 
83
85
  ```BASH
84
- cd src/addons/volto-citation/
86
+ cd packages/volto-citation/
85
87
  ```
86
88
 
87
89
  Start:
package/README.md CHANGED
@@ -3,16 +3,16 @@
3
3
  [![Releases](https://img.shields.io/github/v/release/eea/volto-citation)](https://github.com/eea/volto-citation/releases)
4
4
 
5
5
  [![Pipeline](https://ci.eionet.europa.eu/buildStatus/icon?job=volto-addons%2Fvolto-citation%2Fmaster&subject=master)](https://ci.eionet.europa.eu/view/Github/job/volto-addons/job/volto-citation/job/master/display/redirect)
6
- [![Lines of Code](https://sonarqube.eea.europa.eu/api/project_badges/measure?project=volto-citation-master&metric=ncloc)](https://sonarqube.eea.europa.eu/dashboard?id=volto-citation-master)
7
- [![Coverage](https://sonarqube.eea.europa.eu/api/project_badges/measure?project=volto-citation-master&metric=coverage)](https://sonarqube.eea.europa.eu/dashboard?id=volto-citation-master)
8
- [![Bugs](https://sonarqube.eea.europa.eu/api/project_badges/measure?project=volto-citation-master&metric=bugs)](https://sonarqube.eea.europa.eu/dashboard?id=volto-citation-master)
9
- [![Duplicated Lines (%)](https://sonarqube.eea.europa.eu/api/project_badges/measure?project=volto-citation-master&metric=duplicated_lines_density)](https://sonarqube.eea.europa.eu/dashboard?id=volto-citation-master)
6
+ [![Lines of Code](https://sonarqube.eea.europa.eu/api/project_badges/measure?project=volto-citation&metric=ncloc)](https://sonarqube.eea.europa.eu/dashboard?id=volto-citation)
7
+ [![Coverage](https://sonarqube.eea.europa.eu/api/project_badges/measure?project=volto-citation&metric=coverage)](https://sonarqube.eea.europa.eu/dashboard?id=volto-citation)
8
+ [![Bugs](https://sonarqube.eea.europa.eu/api/project_badges/measure?project=volto-citation&metric=bugs)](https://sonarqube.eea.europa.eu/dashboard?id=volto-citation)
9
+ [![Duplicated Lines (%)](https://sonarqube.eea.europa.eu/api/project_badges/measure?project=volto-citation&metric=duplicated_lines_density)](https://sonarqube.eea.europa.eu/dashboard?id=volto-citation)
10
10
 
11
11
  [![Pipeline](https://ci.eionet.europa.eu/buildStatus/icon?job=volto-addons%2Fvolto-citation%2Fdevelop&subject=develop)](https://ci.eionet.europa.eu/view/Github/job/volto-addons/job/volto-citation/job/develop/display/redirect)
12
- [![Lines of Code](https://sonarqube.eea.europa.eu/api/project_badges/measure?project=volto-citation-develop&metric=ncloc)](https://sonarqube.eea.europa.eu/dashboard?id=volto-citation-develop)
13
- [![Coverage](https://sonarqube.eea.europa.eu/api/project_badges/measure?project=volto-citation-develop&metric=coverage)](https://sonarqube.eea.europa.eu/dashboard?id=volto-citation-develop)
14
- [![Bugs](https://sonarqube.eea.europa.eu/api/project_badges/measure?project=volto-citation-develop&metric=bugs)](https://sonarqube.eea.europa.eu/dashboard?id=volto-citation-develop)
15
- [![Duplicated Lines (%)](https://sonarqube.eea.europa.eu/api/project_badges/measure?project=volto-citation-develop&metric=duplicated_lines_density)](https://sonarqube.eea.europa.eu/dashboard?id=volto-citation-develop)
12
+ [![Lines of Code](https://sonarqube.eea.europa.eu/api/project_badges/measure?project=volto-citation&branch=develop&metric=ncloc)](https://sonarqube.eea.europa.eu/dashboard?id=volto-citation&branch=develop)
13
+ [![Coverage](https://sonarqube.eea.europa.eu/api/project_badges/measure?project=volto-citation&branch=develop&metric=coverage)](https://sonarqube.eea.europa.eu/dashboard?id=volto-citation&branch=develop)
14
+ [![Bugs](https://sonarqube.eea.europa.eu/api/project_badges/measure?project=volto-citation&branch=develop&metric=bugs)](https://sonarqube.eea.europa.eu/dashboard?id=volto-citation&branch=develop)
15
+ [![Duplicated Lines (%)](https://sonarqube.eea.europa.eu/api/project_badges/measure?project=volto-citation&branch=develop&metric=duplicated_lines_density)](https://sonarqube.eea.europa.eu/dashboard?id=volto-citation&branch=develop)
16
16
 
17
17
 
18
18
  [Volto](https://github.com/plone/volto) Citation add-on
@@ -34,6 +34,11 @@ Volto Citation shows users how to cite an article. It supports four types of cit
34
34
 
35
35
  Go to http://localhost:3000
36
36
 
37
+ `make start` now defaults to Volto 18. To run the same setup against Volto 17, use:
38
+
39
+ VOLTO_VERSION=17 make
40
+ VOLTO_VERSION=17 make start
41
+
37
42
  ### Add volto-citation to your Volto project
38
43
 
39
44
  1. Make sure you have a [Plone backend](https://plone.org/download) up-and-running at http://localhost:8080/Plone
@@ -47,30 +52,39 @@ Go to http://localhost:3000
47
52
  * If you already have a volto project, just update `package.json`:
48
53
 
49
54
  ```JSON
50
- "addons": [
51
- "@eeacms/volto-citation"
52
- ],
53
-
54
55
  "dependencies": {
55
56
  "@eeacms/volto-citation": "*"
56
57
  }
57
58
  ```
58
59
 
59
- * If not, create one:
60
+ and `volto.config.js`:
61
+
62
+ ```JavaScript
63
+ const addons = ['@eeacms/volto-citation'];
64
+ ```
65
+
66
+ * If not, create one with Cookieplone, as recommended by the official Plone documentation for Volto 18+:
60
67
 
61
68
  ```
62
- npm install -g yo @plone/generator-volto
63
- yo @plone/volto my-volto-project --canary --addon @eeacms/volto-citation
64
- cd my-volto-project
69
+ uvx cookieplone project
70
+ cd project-title
65
71
  ```
66
72
 
67
- 1. Install new add-ons and restart Volto:
73
+ 1. Install or update dependencies, then start the project:
68
74
 
69
75
  ```
70
- yarn
71
- yarn start
76
+ make install
72
77
  ```
73
78
 
79
+ For a Cookieplone project, start the backend and frontend in separate terminals:
80
+
81
+ ```
82
+ make backend-start
83
+ make frontend-start
84
+ ```
85
+
86
+ For a legacy Volto 17 project, install the package with `yarn` and restart the frontend as usual.
87
+
74
88
  1. Go to http://localhost:3000
75
89
 
76
90
  1. Happy editing!
@@ -15,7 +15,7 @@ services:
15
15
  args:
16
16
  ADDON_NAME: "${ADDON_NAME}"
17
17
  ADDON_PATH: "${ADDON_PATH}"
18
- VOLTO_VERSION: ${VOLTO_VERSION:-16}
18
+ VOLTO_VERSION: ${VOLTO_VERSION:-18-yarn}
19
19
  ports:
20
20
  - "3000:3000"
21
21
  - "3001:3001"
@@ -1,5 +1,14 @@
1
1
  require('dotenv').config({ path: __dirname + '/.env' })
2
2
 
3
+ const fs = require('fs')
4
+ const path = require('path')
5
+
6
+ const voltoSlatePath = fs.existsSync(
7
+ path.join(__dirname, '../../../node_modules/@plone/volto-slate/src'),
8
+ )
9
+ ? '<rootDir>/node_modules/@plone/volto-slate/src'
10
+ : '<rootDir>/node_modules/@plone/volto/packages/volto-slate/src'
11
+
3
12
  module.exports = {
4
13
  testMatch: ['**/src/addons/**/?(*.)+(spec|test).[jt]s?(x)'],
5
14
  collectCoverageFrom: [
@@ -17,10 +26,8 @@ module.exports = {
17
26
  '@eeacms/search/(.*)$': '<rootDir>/src/addons/volto-searchlib/searchlib/$1',
18
27
  '@eeacms/search': '<rootDir>/src/addons/volto-searchlib/searchlib',
19
28
  '@eeacms/(.*?)/(.*)$': '<rootDir>/node_modules/@eeacms/$1/src/$2',
20
- '@plone/volto-slate$':
21
- '<rootDir>/node_modules/@plone/volto/packages/volto-slate/src',
22
- '@plone/volto-slate/(.*)$':
23
- '<rootDir>/node_modules/@plone/volto/packages/volto-slate/src/$1',
29
+ '@plone/volto-slate$': voltoSlatePath,
30
+ '@plone/volto-slate/(.*)$': `${voltoSlatePath}/$1`,
24
31
  '~/(.*)$': '<rootDir>/src/$1',
25
32
  'load-volto-addons':
26
33
  '<rootDir>/node_modules/@plone/volto/jest-addons-loader.js',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eeacms/volto-citation",
3
- "version": "1.0.0",
3
+ "version": "2.0.0",
4
4
  "description": "@eeacms/volto-citation: Volto add-on",
5
5
  "main": "src/index.js",
6
6
  "author": "European Environment Agency: IDM2 A-Team",
@@ -24,6 +24,7 @@
24
24
  "@cypress/code-coverage": "^3.10.0",
25
25
  "@plone/scripts": "*",
26
26
  "babel-plugin-transform-class-properties": "^6.24.1",
27
+ "cypress": "13.1.0",
27
28
  "cypress-fail-fast": "^5.0.1",
28
29
  "dotenv": "^16.3.2",
29
30
  "husky": "^8.0.3",
@@ -1,28 +1,39 @@
1
- import React, { useState, useEffect } from 'react';
1
+ import React, { useState, useEffect, useRef } from 'react';
2
2
  import { Tab, Label, Menu } from 'semantic-ui-react';
3
3
  import { useCopyToClipboard } from '@eeacms/volto-citation/helpers';
4
4
  import { Icon } from '@plone/volto/components';
5
-
6
- import Cite from 'citation-js';
5
+ import loadable from '@loadable/component';
7
6
 
8
7
  import copySVG from '@plone/volto/icons/copy.svg';
9
8
  import checkSVG from '@plone/volto/icons/check.svg';
10
9
 
11
10
  import './styles.less';
12
11
 
12
+ const CitationJS = loadable.lib(() => import('citation-js'));
13
+
13
14
  const CopyUrlButton = ({ citation, className }) => {
14
15
  const [copyUrlStatus, copyUrl] = useCopyToClipboard(citation);
15
16
  const [icon, setIcon] = useState(copySVG);
17
+ const timeoutRef = useRef(null);
16
18
 
17
19
  useEffect(() => {
18
20
  if (copyUrlStatus === 'copied') {
19
21
  setIcon(checkSVG);
20
- setTimeout(() => {
22
+ timeoutRef.current = setTimeout(() => {
21
23
  setIcon(copySVG);
22
- }, [5000]);
24
+ }, 5000);
23
25
  }
24
26
  }, [copyUrlStatus]);
25
27
 
28
+ useEffect(() => {
29
+ return () => {
30
+ if (timeoutRef.current) {
31
+ clearTimeout(timeoutRef.current);
32
+ timeoutRef.current = null;
33
+ }
34
+ };
35
+ }, []);
36
+
26
37
  return (
27
38
  <Label
28
39
  floating
@@ -43,44 +54,71 @@ const CopyUrlButton = ({ citation, className }) => {
43
54
  };
44
55
 
45
56
  function Citation({ title, authors, link, type = 'article', year, mode }) {
46
- const cite = (format, subFormat) => {
47
- const citationObject = new Cite({
48
- title: title,
49
- type: type,
50
- author: authors.map((author) => {
51
- return {
52
- literal: author,
53
- };
54
- }),
55
-
56
- issued: { 'date-parts': [[year]] },
57
- URL: link,
58
- });
59
-
60
- if (format === 'html')
61
- return `<blockquote>
57
+ const [htmlCitation, setHtmlCitation] = useState('');
58
+ const [textCitation, setTextCitation] = useState('');
59
+ const [risCitation, setRisCitation] = useState('');
60
+ const [bibtexCitation, setBibtexCitation] = useState('');
61
+
62
+ useEffect(() => {
63
+ let isMounted = true;
64
+
65
+ const loadCitation = async () => {
66
+ const module = await CitationJS.load();
67
+ const { default: Cite } = module;
68
+ const citationObject = new Cite({
69
+ title: title,
70
+ type: type,
71
+ author: authors.map((author) => {
72
+ return {
73
+ literal: author,
74
+ };
75
+ }),
76
+ issued: { 'date-parts': [[year]] },
77
+ URL: link,
78
+ });
79
+
80
+ if (isMounted) {
81
+ setHtmlCitation(`<blockquote>
62
82
  <p>(${year}).</p>
63
83
  <p>${title}</p>
64
84
  <p>${authors.map((author, index) => {
65
- const separator = index < authors.length - 1 ? ', ' : '';
66
- return (author || '') + separator;
67
- })}
85
+ const separator = index < authors.length - 1 ? ', ' : '';
86
+ return (author || '') + separator;
87
+ })}
68
88
  </p>
69
- <a href=${link}>${link}</a>
70
- </blockquote>`;
71
- else
72
- return citationObject
73
- .format(format, {
74
- format: subFormat,
75
- template: 'apa',
76
- })
77
- .replace(/(^[ \t]*\n)/gm, '');
78
- };
79
-
80
- const modes = [
89
+ ${
90
+ mode !== 'edit'
91
+ ? '<a href=' + link + '>' + link + '</a>'
92
+ : '<p>' + link + '</p>'
93
+ }
94
+ </blockquote>`);
95
+
96
+ setTextCitation(
97
+ citationObject
98
+ .format('bibliography', {
99
+ format: 'text',
100
+ template: 'apa',
101
+ })
102
+ .replace(/(^[ \t]*\n)/gm, ''),
103
+ );
104
+
105
+ setRisCitation(citationObject.format('ris'));
106
+ setBibtexCitation(citationObject.format('bibtex'));
107
+ }
108
+ };
109
+
110
+ loadCitation();
111
+
112
+ return () => {
113
+ isMounted = false;
114
+ };
115
+ }, [title, authors, link, type, year, mode]);
116
+
117
+ const tab_panes = [
81
118
  {
82
119
  menuItem: (
83
120
  <Menu.Item
121
+ key="html"
84
122
  tabIndex={0}
85
123
  onKeyDown={(e) => {
86
124
  if (e.key === 'Enter') e.target.click();
@@ -91,26 +129,17 @@ function Citation({ title, authors, link, type = 'article', year, mode }) {
91
129
  ),
92
130
  render: () => (
93
131
  <Tab.Pane attached={false}>
94
- <blockquote className="text">
95
- <p>({year}).</p>
96
- <p>{title}</p>
97
- <p>
98
- {authors.map((author, index) => {
99
- let separator = '';
100
- if (index < authors.length - 1) separator = ', ';
101
- return (author || '') + separator;
102
- })}
103
- </p>
104
- {mode === 'edit' ? <p>{link}</p> : <a href={link}>{link}</a>}
105
-
106
- <CopyUrlButton citation={cite('html')} />
107
- </blockquote>
132
+ <div className="text">
133
+ <div dangerouslySetInnerHTML={{ __html: htmlCitation }} />
134
+ <CopyUrlButton citation={htmlCitation} />
135
+ </div>
108
136
  </Tab.Pane>
109
137
  ),
110
138
  },
111
139
  {
112
140
  menuItem: (
113
141
  <Menu.Item
142
+ key="text"
114
143
  tabIndex={0}
115
144
  onKeyDown={(e) => {
116
145
  if (e.key === 'Enter') e.target.click();
@@ -122,9 +151,8 @@ function Citation({ title, authors, link, type = 'article', year, mode }) {
122
151
  render: () => (
123
152
  <Tab.Pane attached={false}>
124
153
  <div className="text">
125
- <pre>{cite('bibliography', 'text')}</pre>
126
-
127
- <CopyUrlButton citation={cite('bibliography', 'text')} />
154
+ <pre>{textCitation}</pre>
155
+ <CopyUrlButton citation={textCitation} />
128
156
  </div>
129
157
  </Tab.Pane>
130
158
  ),
@@ -132,6 +160,7 @@ function Citation({ title, authors, link, type = 'article', year, mode }) {
132
160
  {
133
161
  menuItem: (
134
162
  <Menu.Item
163
+ key="ris"
135
164
  tabIndex={0}
136
165
  onKeyDown={(e) => {
137
166
  if (e.key === 'Enter') e.target.click();
@@ -143,9 +172,8 @@ function Citation({ title, authors, link, type = 'article', year, mode }) {
143
172
  render: () => (
144
173
  <Tab.Pane attached={false}>
145
174
  <div className="text">
146
- <pre>{cite('ris')}</pre>
147
-
148
- <CopyUrlButton citation={cite('ris')} />
175
+ <pre>{risCitation}</pre>
176
+ <CopyUrlButton citation={risCitation} />
149
177
  </div>
150
178
  </Tab.Pane>
151
179
  ),
@@ -153,6 +181,7 @@ function Citation({ title, authors, link, type = 'article', year, mode }) {
153
181
  {
154
182
  menuItem: (
155
183
  <Menu.Item
184
+ key="bibtex"
156
185
  tabIndex={0}
157
186
  onKeyDown={(e) => {
158
187
  if (e.key === 'Enter') e.target.click();
@@ -164,9 +193,8 @@ function Citation({ title, authors, link, type = 'article', year, mode }) {
164
193
  render: () => (
165
194
  <Tab.Pane attached={false}>
166
195
  <div className="text">
167
- <pre>{cite('bibtex')}</pre>
168
-
169
- <CopyUrlButton citation={cite('bibtex')} />
196
+ <pre>{bibtexCitation}</pre>
197
+ <CopyUrlButton citation={bibtexCitation} />
170
198
  </div>
171
199
  </Tab.Pane>
172
200
  ),
@@ -176,7 +204,7 @@ function Citation({ title, authors, link, type = 'article', year, mode }) {
176
204
  return (
177
205
  <div className="citation-block tabs-block">
178
206
  <Tab
179
- panes={modes}
207
+ panes={tab_panes}
180
208
  menu={{ className: 'ui green fluid pointing secondary menu' }}
181
209
  />
182
210
  </div>
@@ -49,7 +49,6 @@
49
49
 
50
50
  blockquote {
51
51
  position: relative;
52
- width: 80%;
53
52
  padding: 1.2em 30px 1.2em 75px;
54
53
  border-left: 8px solid @secondaryColor;
55
54
  margin: 50px auto;