@eeacms/volto-citation 1.0.0 → 1.1.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 +7 -1
- package/package.json +2 -1
- package/src/Citation/Citation.jsx +88 -60
- package/src/Citation/styles.less +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,7 +4,13 @@ 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.
|
|
7
|
+
### [1.1.0](https://github.com/eea/volto-citation/compare/1.0.0...1.1.0) - 21 May 2024
|
|
8
|
+
|
|
9
|
+
#### :bug: Bug Fixes
|
|
10
|
+
|
|
11
|
+
- fix(performance): load citation-js only when used - refs #262122 [ichim-david - [`ccddd2a`](https://github.com/eea/volto-citation/commit/ccddd2aede2df9b445fd3f447c808ef86a2608a3)]
|
|
12
|
+
|
|
13
|
+
## [1.0.0](https://github.com/eea/volto-citation/compare/0.1.5...1.0.0) - 22 April 2024
|
|
8
14
|
|
|
9
15
|
#### :rocket: New Features
|
|
10
16
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eeacms/volto-citation",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.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
|
-
},
|
|
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
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
|
|
66
|
-
|
|
67
|
-
|
|
85
|
+
const separator = index < authors.length - 1 ? ', ' : '';
|
|
86
|
+
return (author || '') + separator;
|
|
87
|
+
})}
|
|
68
88
|
</p>
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
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
|
-
<
|
|
95
|
-
<
|
|
96
|
-
<
|
|
97
|
-
|
|
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>{
|
|
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>{
|
|
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>{
|
|
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={
|
|
207
|
+
panes={tab_panes}
|
|
180
208
|
menu={{ className: 'ui green fluid pointing secondary menu' }}
|
|
181
209
|
/>
|
|
182
210
|
</div>
|