@abi-software/map-utilities 1.3.2 → 1.3.3-beta.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abi-software/map-utilities",
3
- "version": "1.3.2",
3
+ "version": "1.3.3-beta.0",
4
4
  "files": [
5
5
  "dist/*",
6
6
  "src/*",
@@ -30,6 +30,11 @@
30
30
  },
31
31
  "dependencies": {
32
32
  "@abi-software/svg-sprite": "^1.0.1",
33
+ "@citation-js/core": "^0.7.14",
34
+ "@citation-js/plugin-bibtex": "^0.7.17",
35
+ "@citation-js/plugin-csl": "^0.7.14",
36
+ "@citation-js/plugin-doi": "^0.7.16",
37
+ "@citation-js/plugin-pubmed": "^0.3.0",
33
38
  "@element-plus/icons-vue": "^2.3.1",
34
39
  "cytoscape": "^3.30.2",
35
40
  "element-plus": "2.8.4",
@@ -6,7 +6,7 @@
6
6
  <CopyToClipboard label="Copy list to clipboard" :content="referecesListContent" />
7
7
  </div>
8
8
  </div>
9
- <div class="citation-tabs" v-if="referencesWithDOI">
9
+ <div class="citation-tabs" v-if="useDOIFormatter ? referencesWithDOI : pubMedReferences.length">
10
10
  <el-button
11
11
  link
12
12
  v-for="citationOption of citationOptions"
@@ -21,7 +21,10 @@
21
21
  <li
22
22
  v-for="reference of pubMedReferences"
23
23
  :key="reference.id"
24
- :class="{'loading': reference.citation && !reference.citation.error && reference.citation[citationType] === ''}"
24
+ :class="{
25
+ 'loading': reference.citation && !reference.citation.error && reference.citation[citationType] === '',
26
+ 'error': reference.citation && reference.citation.error
27
+ }"
25
28
  >
26
29
  <template v-if="reference.citation">
27
30
 
@@ -66,7 +69,7 @@
66
69
 
67
70
  <script>
68
71
  import CopyToClipboard from '../CopyToClipboard/CopyToClipboard.vue';
69
- import { delay } from '../utilities';
72
+ import { delay, getCitationById } from '../utilities';
70
73
 
71
74
  const CROSSCITE_API_HOST = 'https://citation.doi.org';
72
75
  const CITATION_OPTIONS = [
@@ -92,11 +95,18 @@ const LOADING_DELAY = 600;
92
95
 
93
96
  export default {
94
97
  name: "ExternalResourceCard",
98
+ components: {
99
+ CopyToClipboard,
100
+ },
95
101
  props: {
96
102
  resources: {
97
103
  type: Array,
98
104
  default: () => [],
99
105
  },
106
+ useDOIFormatter: {
107
+ type: Boolean,
108
+ default: true,
109
+ }
100
110
  },
101
111
  data: function () {
102
112
  return {
@@ -288,7 +298,14 @@ export default {
288
298
 
289
299
  if (type === 'doi' || doi) {
290
300
  const doiID = type === 'doi' ? id : doi;
291
- this.getCitationTextByDOI(doiID).then((text) => {
301
+ const fetchCitationFromAPI = this.useDOIFormatter ?
302
+ this.getCitationTextByDOI(doiID) :
303
+ getCitationById(doiID, {
304
+ type: 'doi',
305
+ format: citationType
306
+ });
307
+
308
+ fetchCitationFromAPI.then((text) => {
292
309
  const formattedText = this.replaceLinkInText(text);
293
310
  reference.citation[citationType] = formattedText;
294
311
  this.updateCopyContents();
@@ -299,45 +316,61 @@ export default {
299
316
  };
300
317
  });
301
318
  } else if (type === 'pmid') {
302
- this.getDOIFromPubMedID(id).then((data) => {
303
- if (data?.result) {
304
- const resultObj = data.result[id];
305
- const articleIDs = resultObj?.articleids || [];
306
- const doiObj = articleIDs.find((item) => item.idtype === 'doi');
307
- const doiID = doiObj?.value;
308
-
309
- if (doiID) {
310
- reference['doi'] = doiID;
311
- this.getCitationTextByDOI(doiID).then((text) => {
312
- const formattedText = this.replaceLinkInText(text);
319
+ if (this.useDOIFormatter) {
320
+ this.getDOIFromPubMedID(id).then((data) => {
321
+ if (data?.result) {
322
+ const resultObj = data.result[id];
323
+ const articleIDs = resultObj?.articleids || [];
324
+ const doiObj = articleIDs.find((item) => item.idtype === 'doi');
325
+ const doiID = doiObj?.value;
326
+
327
+ if (doiID) {
328
+ reference['doi'] = doiID;
329
+ this.getCitationTextByDOI(doiID).then((text) => {
330
+ const formattedText = this.replaceLinkInText(text);
331
+ reference.citation[citationType] = formattedText;
332
+ this.updateCopyContents();
333
+ }).catch((error) => {
334
+ reference.citation['error'] = {
335
+ type: citationType,
336
+ ref: 'doi',
337
+ };
338
+ });
339
+ } else {
340
+ // If there has no doi in PubMed
341
+ const { title, pubdate, authors } = resultObj;
342
+ const authorNames = authors ? authors.map((author) => author.name) : [];
343
+ const formattedText = this.formatCopyReference({
344
+ title: title || '',
345
+ date: pubdate || '',
346
+ authors: authorNames,
347
+ url: `https://pubmed.ncbi.nlm.nih.gov/${id}`,
348
+ });
313
349
  reference.citation[citationType] = formattedText;
314
350
  this.updateCopyContents();
315
- }).catch((error) => {
316
- reference.citation['error'] = {
317
- type: citationType,
318
- ref: 'doi',
319
- };
320
- });
321
- } else {
322
- // If there has no doi in PubMed
323
- const { title, pubdate, authors } = resultObj;
324
- const authorNames = authors ? authors.map((author) => author.name) : [];
325
- const formattedText = this.formatCopyReference({
326
- title: title || '',
327
- date: pubdate || '',
328
- authors: authorNames,
329
- url: `https://pubmed.ncbi.nlm.nih.gov/${id}`,
330
- });
331
- reference.citation[citationType] = formattedText;
332
- this.updateCopyContents();
351
+ }
333
352
  }
334
- }
335
- }).catch((error) => {
336
- reference.citation['error'] = {
337
- type: citationType,
338
- ref: 'pubmed',
339
- };
340
- });
353
+ }).catch((error) => {
354
+ reference.citation['error'] = {
355
+ type: citationType,
356
+ ref: 'pubmed',
357
+ };
358
+ });
359
+ } else {
360
+ getCitationById(id, {
361
+ type: 'pmid',
362
+ format: citationType
363
+ }).then((text) => {
364
+ const formattedText = this.replaceLinkInText(text);
365
+ reference.citation[citationType] = formattedText;
366
+ this.updateCopyContents();
367
+ }).catch((error) => {
368
+ reference.citation['error'] = {
369
+ type: citationType,
370
+ ref: 'pubmed',
371
+ };
372
+ });
373
+ }
341
374
  }
342
375
  }
343
376
  },
@@ -582,6 +615,13 @@ export default {
582
615
  }
583
616
  }
584
617
 
618
+ &.error {
619
+ font-style: italic;
620
+ color: var(--el-color-info);
621
+ border: 1px dotted red;
622
+ background-color: transparent;
623
+ }
624
+
585
625
  :deep(.copy-clipboard-button) {
586
626
  position: absolute;
587
627
  bottom: 0.25rem;
@@ -1,3 +1,9 @@
1
+ import { Cite, plugins } from '@citation-js/core';
2
+ import '@citation-js/plugin-doi';
3
+ import '@citation-js/plugin-csl';
4
+ import '@citation-js/plugin-bibtex';
5
+ import '@citation-js/plugin-pubmed';
6
+
1
7
  const capitalise = term => {
2
8
  if (term)
3
9
  return term.charAt(0).toUpperCase() + term.slice(1);
@@ -48,8 +54,42 @@ const delay = (ms) => {
48
54
  return new Promise(resolve => setTimeout(resolve, ms));
49
55
  };
50
56
 
57
+ /**
58
+ * @param {id} id - DOI or PMID
59
+ * @param {options:type} type - type of the ID, e.g., 'pmid'
60
+ * @param {options:format} format - 'apa' (default), 'chicago', 'ieee', 'bibtex', etc.
61
+ * @returns {citation} formatted citation text
62
+ */
63
+ const getCitationById = async (id, { type, format }) => {
64
+ // because 'chicago' and 'ieee' are not in citation.js default styles
65
+ if ((format !== 'bibtex') && (format !== 'apa')) {
66
+ const xml = `https://raw.githubusercontent.com/citation-style-language/styles/refs/heads/master/${format}.csl`;
67
+ const response = await fetch(xml);
68
+ const template = await response.text();
69
+ let config = plugins.config.get('@csl');
70
+ config.templates.add(format, template);
71
+ }
72
+
73
+ const option = {};
74
+
75
+ if (type === 'pmid') {
76
+ option['forceType'] = '@pubmed/id';
77
+ }
78
+
79
+ const cite = await Cite.async(id, option);
80
+ const citation = (format === 'bibtex') ?
81
+ cite.format(format) :
82
+ cite.format('bibliography', {
83
+ format: 'html',
84
+ template: format || 'apa', // default as 'apa' style
85
+ lang: 'en-US'
86
+ })
87
+ return citation;
88
+ };
89
+
51
90
  export {
52
91
  capitalise,
53
92
  xmlToJSON,
54
93
  delay,
94
+ getCitationById,
55
95
  };