react-cheminfo 0.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.
Files changed (113) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +210 -0
  3. package/lib/citation/core/clipboard.d.ts +14 -0
  4. package/lib/citation/core/clipboard.d.ts.map +1 -0
  5. package/lib/citation/core/clipboard.js +25 -0
  6. package/lib/citation/core/clipboard.js.map +1 -0
  7. package/lib/citation/core/download.d.ts +11 -0
  8. package/lib/citation/core/download.d.ts.map +1 -0
  9. package/lib/citation/core/download.js +20 -0
  10. package/lib/citation/core/download.js.map +1 -0
  11. package/lib/citation/core/formats.d.ts +91 -0
  12. package/lib/citation/core/formats.d.ts.map +1 -0
  13. package/lib/citation/core/formats.js +125 -0
  14. package/lib/citation/core/formats.js.map +1 -0
  15. package/lib/citation/core/index.d.ts +10 -0
  16. package/lib/citation/core/index.d.ts.map +1 -0
  17. package/lib/citation/core/index.js +7 -0
  18. package/lib/citation/core/index.js.map +1 -0
  19. package/lib/citation/core/reference.d.ts +30 -0
  20. package/lib/citation/core/reference.d.ts.map +1 -0
  21. package/lib/citation/core/reference.js +9 -0
  22. package/lib/citation/core/reference.js.map +1 -0
  23. package/lib/citation/core/render.d.ts +21 -0
  24. package/lib/citation/core/render.d.ts.map +1 -0
  25. package/lib/citation/core/render.js +74 -0
  26. package/lib/citation/core/render.js.map +1 -0
  27. package/lib/citation/core/segments.d.ts +47 -0
  28. package/lib/citation/core/segments.d.ts.map +1 -0
  29. package/lib/citation/core/segments.js +134 -0
  30. package/lib/citation/core/segments.js.map +1 -0
  31. package/lib/citation/ui/CitationMenu.d.ts +14 -0
  32. package/lib/citation/ui/CitationMenu.d.ts.map +1 -0
  33. package/lib/citation/ui/CitationMenu.js +63 -0
  34. package/lib/citation/ui/CitationMenu.js.map +1 -0
  35. package/lib/citation/ui/CitationPreview.d.ts +18 -0
  36. package/lib/citation/ui/CitationPreview.d.ts.map +1 -0
  37. package/lib/citation/ui/CitationPreview.js +55 -0
  38. package/lib/citation/ui/CitationPreview.js.map +1 -0
  39. package/lib/citation/ui/CiteButton.d.ts +22 -0
  40. package/lib/citation/ui/CiteButton.d.ts.map +1 -0
  41. package/lib/citation/ui/CiteButton.js +15 -0
  42. package/lib/citation/ui/CiteButton.js.map +1 -0
  43. package/lib/citation/ui/entries.d.ts +45 -0
  44. package/lib/citation/ui/entries.d.ts.map +1 -0
  45. package/lib/citation/ui/entries.js +52 -0
  46. package/lib/citation/ui/entries.js.map +1 -0
  47. package/lib/citation/ui/index.d.ts +7 -0
  48. package/lib/citation/ui/index.d.ts.map +1 -0
  49. package/lib/citation/ui/index.js +4 -0
  50. package/lib/citation/ui/index.js.map +1 -0
  51. package/lib/core.d.ts +3 -0
  52. package/lib/core.d.ts.map +1 -0
  53. package/lib/core.js +3 -0
  54. package/lib/core.js.map +1 -0
  55. package/lib/ecosystem/core/index.d.ts +3 -0
  56. package/lib/ecosystem/core/index.d.ts.map +1 -0
  57. package/lib/ecosystem/core/index.js +2 -0
  58. package/lib/ecosystem/core/index.js.map +1 -0
  59. package/lib/ecosystem/core/sites.d.ts +57 -0
  60. package/lib/ecosystem/core/sites.d.ts.map +1 -0
  61. package/lib/ecosystem/core/sites.js +105 -0
  62. package/lib/ecosystem/core/sites.js.map +1 -0
  63. package/lib/ecosystem/ui/EcosystemButton.d.ts +24 -0
  64. package/lib/ecosystem/ui/EcosystemButton.d.ts.map +1 -0
  65. package/lib/ecosystem/ui/EcosystemButton.js +14 -0
  66. package/lib/ecosystem/ui/EcosystemButton.js.map +1 -0
  67. package/lib/ecosystem/ui/EcosystemMenu.d.ts +17 -0
  68. package/lib/ecosystem/ui/EcosystemMenu.d.ts.map +1 -0
  69. package/lib/ecosystem/ui/EcosystemMenu.js +112 -0
  70. package/lib/ecosystem/ui/EcosystemMenu.js.map +1 -0
  71. package/lib/ecosystem/ui/index.d.ts +7 -0
  72. package/lib/ecosystem/ui/index.d.ts.map +1 -0
  73. package/lib/ecosystem/ui/index.js +4 -0
  74. package/lib/ecosystem/ui/index.js.map +1 -0
  75. package/lib/ecosystem/ui/marks.d.ts +18 -0
  76. package/lib/ecosystem/ui/marks.d.ts.map +1 -0
  77. package/lib/ecosystem/ui/marks.js +43 -0
  78. package/lib/ecosystem/ui/marks.js.map +1 -0
  79. package/lib/shared/ui/MenuButton.d.ts +34 -0
  80. package/lib/shared/ui/MenuButton.d.ts.map +1 -0
  81. package/lib/shared/ui/MenuButton.js +18 -0
  82. package/lib/shared/ui/MenuButton.js.map +1 -0
  83. package/lib/shared/ui/index.d.ts +2 -0
  84. package/lib/shared/ui/index.d.ts.map +1 -0
  85. package/lib/shared/ui/index.js +2 -0
  86. package/lib/shared/ui/index.js.map +1 -0
  87. package/lib/ui.d.ts +4 -0
  88. package/lib/ui.d.ts.map +1 -0
  89. package/lib/ui.js +4 -0
  90. package/lib/ui.js.map +1 -0
  91. package/package.json +79 -0
  92. package/src/citation/core/clipboard.ts +32 -0
  93. package/src/citation/core/download.ts +27 -0
  94. package/src/citation/core/formats.ts +169 -0
  95. package/src/citation/core/index.ts +23 -0
  96. package/src/citation/core/reference.ts +33 -0
  97. package/src/citation/core/render.ts +78 -0
  98. package/src/citation/core/segments.ts +170 -0
  99. package/src/citation/ui/CitationMenu.tsx +132 -0
  100. package/src/citation/ui/CitationPreview.tsx +84 -0
  101. package/src/citation/ui/CiteButton.tsx +39 -0
  102. package/src/citation/ui/entries.tsx +144 -0
  103. package/src/citation/ui/index.ts +6 -0
  104. package/src/core.ts +2 -0
  105. package/src/ecosystem/core/index.ts +7 -0
  106. package/src/ecosystem/core/sites.ts +164 -0
  107. package/src/ecosystem/ui/EcosystemButton.tsx +41 -0
  108. package/src/ecosystem/ui/EcosystemMenu.tsx +191 -0
  109. package/src/ecosystem/ui/index.ts +6 -0
  110. package/src/ecosystem/ui/marks.tsx +207 -0
  111. package/src/shared/ui/MenuButton.tsx +67 -0
  112. package/src/shared/ui/index.ts +1 -0
  113. package/src/ui.ts +3 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../../src/citation/core/render.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAErD;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,SAAS,eAAe,EAAE,GAAG,MAAM,CAMvE;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,SAAS,eAAe,EAAE,GAAG,MAAM,CAqBvE;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,SAAS,eAAe,EAAE,GAAG,MAAM,CAqB3E"}
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Write the segments as they read in an email or a manuscript.
3
+ * @param segments - Segments of the citation.
4
+ * @returns The citation, with no markup at all.
5
+ */
6
+ export function renderText(segments) {
7
+ let result = '';
8
+ for (const segment of segments) {
9
+ result += segment.kind === 'link' ? segment.href : segment.text;
10
+ }
11
+ return result;
12
+ }
13
+ /**
14
+ * Write the segments as HTML, so a paste into Word or a web page keeps the
15
+ * italics and the bold the style asks for.
16
+ * @param segments - Segments of the citation.
17
+ * @returns The citation as one line of HTML.
18
+ */
19
+ export function renderHtml(segments) {
20
+ let result = '';
21
+ for (const segment of segments) {
22
+ switch (segment.kind) {
23
+ case 'italic':
24
+ result += `<em>${escapeHtml(segment.text)}</em>`;
25
+ break;
26
+ case 'bold':
27
+ result += `<strong>${escapeHtml(segment.text)}</strong>`;
28
+ break;
29
+ case 'link':
30
+ result += `<a href="${escapeHtml(segment.href)}">${escapeHtml(segment.text)}</a>`;
31
+ break;
32
+ case 'text':
33
+ result += escapeHtml(segment.text);
34
+ break;
35
+ default:
36
+ break;
37
+ }
38
+ }
39
+ return result;
40
+ }
41
+ /**
42
+ * Write the segments as Markdown, for a README or an issue.
43
+ * @param segments - Segments of the citation.
44
+ * @returns The citation as one line of Markdown.
45
+ */
46
+ export function renderMarkdown(segments) {
47
+ let result = '';
48
+ for (const segment of segments) {
49
+ switch (segment.kind) {
50
+ case 'italic':
51
+ result += `*${segment.text}*`;
52
+ break;
53
+ case 'bold':
54
+ result += `**${segment.text}**`;
55
+ break;
56
+ case 'link':
57
+ result += `[${segment.text}](${segment.href})`;
58
+ break;
59
+ case 'text':
60
+ result += segment.text;
61
+ break;
62
+ default:
63
+ break;
64
+ }
65
+ }
66
+ return result;
67
+ }
68
+ function escapeHtml(value) {
69
+ return value
70
+ .replaceAll('&', '&amp;')
71
+ .replaceAll('<', '&lt;')
72
+ .replaceAll('>', '&gt;');
73
+ }
74
+ //# sourceMappingURL=render.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render.js","sourceRoot":"","sources":["../../../src/citation/core/render.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,QAAoC;IAC7D,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,MAAM,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC;IAClE,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,UAAU,CAAC,QAAoC;IAC7D,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,QAAQ,OAAO,CAAC,IAAI,EAAE,CAAC;YACrB,KAAK,QAAQ;gBACX,MAAM,IAAI,OAAO,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC;gBACjD,MAAM;YACR,KAAK,MAAM;gBACT,MAAM,IAAI,WAAW,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC;gBACzD,MAAM;YACR,KAAK,MAAM;gBACT,MAAM,IAAI,YAAY,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC;gBAClF,MAAM;YACR,KAAK,MAAM;gBACT,MAAM,IAAI,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;gBACnC,MAAM;YACR;gBACE,MAAM;QACV,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,QAAoC;IACjE,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;QAC/B,QAAQ,OAAO,CAAC,IAAI,EAAE,CAAC;YACrB,KAAK,QAAQ;gBACX,MAAM,IAAI,IAAI,OAAO,CAAC,IAAI,GAAG,CAAC;gBAC9B,MAAM;YACR,KAAK,MAAM;gBACT,MAAM,IAAI,KAAK,OAAO,CAAC,IAAI,IAAI,CAAC;gBAChC,MAAM;YACR,KAAK,MAAM;gBACT,MAAM,IAAI,IAAI,OAAO,CAAC,IAAI,KAAK,OAAO,CAAC,IAAI,GAAG,CAAC;gBAC/C,MAAM;YACR,KAAK,MAAM;gBACT,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;gBACvB,MAAM;YACR;gBACE,MAAM;QACV,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,UAAU,CAAC,KAAa;IAC/B,OAAO,KAAK;SACT,UAAU,CAAC,GAAG,EAAE,OAAO,CAAC;SACxB,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC;SACvB,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;AAC7B,CAAC"}
@@ -0,0 +1,47 @@
1
+ import type { Reference } from './reference.ts';
2
+ /** One piece of a written reference, with the emphasis its style asks for. */
3
+ export type CitationSegment = {
4
+ kind: 'text' | 'italic' | 'bold';
5
+ text: string;
6
+ } | {
7
+ kind: 'link';
8
+ text: string;
9
+ href: string;
10
+ };
11
+ /** The journal styles the reference can be written in. */
12
+ export type CitationStyleId = 'acs' | 'nature' | 'rsc' | 'wiley';
13
+ /** One entry of the style submenu. */
14
+ export interface CitationStyle {
15
+ id: CitationStyleId;
16
+ /** Name of the style. */
17
+ label: string;
18
+ /** Journals that ask for it, shown on the right of the entry. */
19
+ hint: string;
20
+ }
21
+ /** Every style offered, in the order the menu lists them. */
22
+ export declare const CITATION_STYLES: readonly [{
23
+ readonly id: "acs";
24
+ readonly label: "ACS";
25
+ readonly hint: "JACS, Org. Lett.";
26
+ }, {
27
+ readonly id: "nature";
28
+ readonly label: "Nature";
29
+ readonly hint: "Nature, Nat. Chem.";
30
+ }, {
31
+ readonly id: "rsc";
32
+ readonly label: "RSC";
33
+ readonly hint: "Chem. Sci., Green Chem.";
34
+ }, {
35
+ readonly id: "wiley";
36
+ readonly label: "Wiley";
37
+ readonly hint: "Angew. Chem., Chem. Eur. J.";
38
+ }];
39
+ /**
40
+ * Write a reference in one journal style, as the pieces every output format
41
+ * then renders with its own emphasis.
42
+ * @param reference - Reference to write.
43
+ * @param style - Style to write it in.
44
+ * @returns The segments of the citation, in reading order.
45
+ */
46
+ export declare function citationSegments(reference: Reference, style: CitationStyleId): CitationSegment[];
47
+ //# sourceMappingURL=segments.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"segments.d.ts","sourceRoot":"","sources":["../../../src/citation/core/segments.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAGhD,8EAA8E;AAC9E,MAAM,MAAM,eAAe,GACvB;IAAE,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAClD;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAEjD,0DAA0D;AAC1D,MAAM,MAAM,eAAe,GAAG,KAAK,GAAG,QAAQ,GAAG,KAAK,GAAG,OAAO,CAAC;AAEjE,sCAAsC;AACtC,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,eAAe,CAAC;IACpB,yBAAyB;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,iEAAiE;IACjE,IAAI,EAAE,MAAM,CAAC;CACd;AAED,6DAA6D;AAC7D,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;EAKiB,CAAC;AAE9C;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE,eAAe,GACrB,eAAe,EAAE,CAanB"}
@@ -0,0 +1,134 @@
1
+ import { doiUrl } from "./reference.js";
2
+ /** Every style offered, in the order the menu lists them. */
3
+ export const CITATION_STYLES = [
4
+ { id: 'acs', label: 'ACS', hint: 'JACS, Org. Lett.' },
5
+ { id: 'nature', label: 'Nature', hint: 'Nature, Nat. Chem.' },
6
+ { id: 'rsc', label: 'RSC', hint: 'Chem. Sci., Green Chem.' },
7
+ { id: 'wiley', label: 'Wiley', hint: 'Angew. Chem., Chem. Eur. J.' },
8
+ ];
9
+ /**
10
+ * Write a reference in one journal style, as the pieces every output format
11
+ * then renders with its own emphasis.
12
+ * @param reference - Reference to write.
13
+ * @param style - Style to write it in.
14
+ * @returns The segments of the citation, in reading order.
15
+ */
16
+ export function citationSegments(reference, style) {
17
+ switch (style) {
18
+ case 'acs':
19
+ return acs(reference);
20
+ case 'nature':
21
+ return nature(reference);
22
+ case 'rsc':
23
+ return rsc(reference);
24
+ case 'wiley':
25
+ return wiley(reference);
26
+ default:
27
+ throw new Error(`unknown citation style: ${String(style)}`);
28
+ }
29
+ }
30
+ function acs(reference) {
31
+ const { title, journalAbbreviation, year, volume } = reference;
32
+ return [
33
+ text(`${familyFirst(reference, '; ')} ${title}. `),
34
+ italic(journalAbbreviation),
35
+ text(' '),
36
+ bold(String(year)),
37
+ text(', '),
38
+ italic(volume),
39
+ text(`, ${pageRange(reference)}. `),
40
+ doiLink(reference),
41
+ ];
42
+ }
43
+ function nature(reference) {
44
+ const { title, journalAbbreviation, year, volume } = reference;
45
+ return [
46
+ text(`${familyFirstAmpersand(reference)} ${title}. `),
47
+ italic(journalAbbreviation),
48
+ text(' '),
49
+ bold(volume),
50
+ text(`, ${pageRange(reference)} (${year}). `),
51
+ doiLink(reference),
52
+ ];
53
+ }
54
+ function rsc(reference) {
55
+ const { journalAbbreviation, year, volume } = reference;
56
+ return [
57
+ text(`${initialsFirst(reference, ' and ')}, `),
58
+ italic(journalAbbreviation),
59
+ text(`, ${year}, `),
60
+ bold(volume),
61
+ text(`, ${pageRange(reference)}. `),
62
+ doiLink(reference),
63
+ ];
64
+ }
65
+ function wiley(reference) {
66
+ const { journalAbbreviation, year, volume } = reference;
67
+ return [
68
+ text(`${initialsFirst(reference, ', ')}, `),
69
+ italic(journalAbbreviation),
70
+ text(' '),
71
+ bold(String(year)),
72
+ text(', '),
73
+ italic(volume),
74
+ text(`, ${pageRange(reference)}. `),
75
+ doiLink(reference),
76
+ ];
77
+ }
78
+ function text(value) {
79
+ return { kind: 'text', text: value };
80
+ }
81
+ function italic(value) {
82
+ return { kind: 'italic', text: value };
83
+ }
84
+ function bold(value) {
85
+ return { kind: 'bold', text: value };
86
+ }
87
+ function doiLink(reference) {
88
+ return {
89
+ kind: 'link',
90
+ text: `doi:${reference.doi}`,
91
+ href: doiUrl(reference),
92
+ };
93
+ }
94
+ /**
95
+ * `Vanderveen, J. R.; Patiny, L.` — the family name leads.
96
+ * @param reference - The work being written.
97
+ * @param separator - What goes between two authors.
98
+ * @returns The authors, as one string.
99
+ */
100
+ function familyFirst(reference, separator) {
101
+ return reference.authors
102
+ .map((author) => `${author.family}, ${author.given}`)
103
+ .join(separator);
104
+ }
105
+ /**
106
+ * The same, with the last author introduced by an ampersand.
107
+ * @param reference - The work being written.
108
+ * @returns The authors, as one string.
109
+ */
110
+ function familyFirstAmpersand(reference) {
111
+ const names = reference.authors.map((author) => `${author.family}, ${author.given}`);
112
+ const last = names.at(-1);
113
+ if (names.length < 2 || last === undefined)
114
+ return names.join(', ');
115
+ return `${names.slice(0, -1).join(', ')} & ${last}`;
116
+ }
117
+ /**
118
+ * `J. R. Vanderveen, L. Patiny` — the initials lead.
119
+ * @param reference - The work being written.
120
+ * @param lastSeparator - What introduces the last author.
121
+ * @returns The authors, as one string.
122
+ */
123
+ function initialsFirst(reference, lastSeparator) {
124
+ const names = reference.authors.map((author) => `${author.given} ${author.family}`);
125
+ const last = names.at(-1);
126
+ if (names.length < 2 || last === undefined)
127
+ return names.join(', ');
128
+ return `${names.slice(0, -1).join(', ')}${lastSeparator}${last}`;
129
+ }
130
+ function pageRange(reference) {
131
+ // En dash: what every style asks for in a page range.
132
+ return `${reference.firstPage}–${reference.lastPage}`;
133
+ }
134
+ //# sourceMappingURL=segments.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"segments.js","sourceRoot":"","sources":["../../../src/citation/core/segments.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAmBxC,6DAA6D;AAC7D,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,kBAAkB,EAAE;IACrD,EAAE,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,oBAAoB,EAAE;IAC7D,EAAE,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,yBAAyB,EAAE;IAC5D,EAAE,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,6BAA6B,EAAE;CACzB,CAAC;AAE9C;;;;;;GAMG;AACH,MAAM,UAAU,gBAAgB,CAC9B,SAAoB,EACpB,KAAsB;IAEtB,QAAQ,KAAK,EAAE,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,KAAK,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1B,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,IAAI,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACpE,OAAO,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,aAAa,GAAG,IAAI,EAAE,CAAC;AACnE,CAAC;AAED,SAAS,SAAS,CAAC,SAAoB;IACrC,sDAAsD;IACtD,OAAO,GAAG,SAAS,CAAC,SAAS,IAAI,SAAS,CAAC,QAAQ,EAAE,CAAC;AACxD,CAAC"}
@@ -0,0 +1,14 @@
1
+ import type { ReactElement } from 'react';
2
+ import type { Reference } from '../core/reference.ts';
3
+ export interface CitationMenuProps {
4
+ /** The work being cited. */
5
+ reference: Reference;
6
+ }
7
+ /**
8
+ * What the Cite button opens: the article at its DOI, the reference copied in
9
+ * the style a journal asks for, and the files a reference manager imports.
10
+ * @param props - The work being cited.
11
+ * @returns The citation menu.
12
+ */
13
+ export declare function CitationMenu(props: CitationMenuProps): ReactElement;
14
+ //# sourceMappingURL=CitationMenu.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CitationMenu.d.ts","sourceRoot":"","sources":["../../../src/citation/ui/CitationMenu.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAiB,YAAY,EAAE,MAAM,OAAO,CAAC;AAMzD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AActD,MAAM,WAAW,iBAAiB;IAChC,4BAA4B;IAC5B,SAAS,EAAE,SAAS,CAAC;CACtB;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,GAAG,YAAY,CA2FnE"}
@@ -0,0 +1,63 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Menu, MenuDivider, MenuItem } from '@blueprintjs/core';
3
+ import { SvgLogoDoi } from 'cheminfo-font';
4
+ import { useEffect, useRef, useState } from 'react';
5
+ import { copyCitation } from "../core/clipboard.js";
6
+ import { CITATION_DOWNLOADS, CITATION_FORMATS } from "../core/formats.js";
7
+ import { doiUrl } from "../core/reference.js";
8
+ import { CITATION_STYLES } from "../core/segments.js";
9
+ import { CopyEntry, DownloadEntry } from "./entries.js";
10
+ // How long the tick replaces the clipboard glyph of an entry after a copy.
11
+ const FEEDBACK_MS = 1500;
12
+ const MENU_STYLE = { minWidth: 240 };
13
+ const DOI_ICON_STYLE = { width: 16, height: 16 };
14
+ /**
15
+ * What the Cite button opens: the article at its DOI, the reference copied in
16
+ * the style a journal asks for, and the files a reference manager imports.
17
+ * @param props - The work being cited.
18
+ * @returns The citation menu.
19
+ */
20
+ export function CitationMenu(props) {
21
+ const { reference } = props;
22
+ // Which entry showed feedback last, keyed `format` or `format:style`.
23
+ const [copied, setCopied] = useState(null);
24
+ const [hasFailed, setHasFailed] = useState(false);
25
+ const timeout = useRef(null);
26
+ useEffect(() => {
27
+ return () => {
28
+ if (timeout.current !== null)
29
+ window.clearTimeout(timeout.current);
30
+ };
31
+ }, []);
32
+ function announce(key, failed) {
33
+ setCopied(key);
34
+ setHasFailed(failed);
35
+ if (timeout.current !== null)
36
+ window.clearTimeout(timeout.current);
37
+ timeout.current = window.setTimeout(() => {
38
+ setCopied(null);
39
+ setHasFailed(false);
40
+ }, FEEDBACK_MS);
41
+ }
42
+ function copy(format, style) {
43
+ const key = style === undefined ? format.id : `${format.id}:${style.id}`;
44
+ copyCitation(reference, format.id, style?.id).then(() => {
45
+ announce(key, false);
46
+ }, () => {
47
+ // A denied clipboard permission is the usual cause, and the menu is the
48
+ // only place the user can be told about it.
49
+ announce(key, true);
50
+ });
51
+ }
52
+ function stateOf(key) {
53
+ return copied === key ? feedback(hasFailed) : null;
54
+ }
55
+ return (_jsxs(Menu, { className: "citation-menu", style: MENU_STYLE, children: [_jsx(MenuItem, { icon: _jsx(SvgLogoDoi, { style: DOI_ICON_STYLE }), text: `${reference.journalAbbreviation} ${reference.year}`, label: reference.doi, href: doiUrl(reference), target: "_blank", rel: "noreferrer" }), _jsx(MenuDivider, { title: "Copy the reference as" }), CITATION_FORMATS.map((format) => format.styled ? (_jsx(MenuItem, { icon: "clipboard", text: format.label, label: format.hint, children: CITATION_STYLES.map((style) => (_jsx(CopyEntry, { reference: reference, format: format, style: style, state: stateOf(`${format.id}:${style.id}`), onCopy: copy }, style.id))) }, format.id)) : (_jsx(CopyEntry, { reference: reference, format: format, state: stateOf(format.id), onCopy: copy }, format.id))), _jsx(MenuDivider, { title: "Import into a reference manager" }), CITATION_DOWNLOADS.map((download) => (_jsx(DownloadEntry, { reference: reference, download: download }, download.format)))] }));
56
+ }
57
+ function feedback(failed) {
58
+ if (failed) {
59
+ return { icon: 'cross', intent: 'danger', label: 'copy failed' };
60
+ }
61
+ return { icon: 'tick', intent: 'success', label: 'copied' };
62
+ }
63
+ //# sourceMappingURL=CitationMenu.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CitationMenu.js","sourceRoot":"","sources":["../../../src/citation/ui/CitationMenu.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEpD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAEpD,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAE1E,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAE9C,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAGtD,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,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AC,CAAC,KAAK,EAAE,EAAE,CAAC,CAC9B,KAAC,SAAS,IAER,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,KAAK,EACZ,KAAK,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,EAAE,IAAI,KAAK,CAAC,EAAE,EAAE,CAAC,EAC1C,MAAM,EAAE,IAAI,IALP,KAAK,CAAC,EAAE,CAMb,CACH,CAAC,IAdG,MAAM,CAAC,EAAE,CAeL,CACZ,CAAC,CAAC,CAAC,CACF,KAAC,SAAS,IAER,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,EACzB,MAAM,EAAE,IAAI,IAJP,MAAM,CAAC,EAAE,CAKd,CACH,CACF,EACD,KAAC,WAAW,IAAC,KAAK,EAAC,iCAAiC,GAAG,EACtD,kBAAkB,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CACpC,KAAC,aAAa,IAEZ,SAAS,EAAE,SAAS,EACpB,QAAQ,EAAE,QAAQ,IAFb,QAAQ,CAAC,MAAM,CAGpB,CACH,CAAC,IACG,CACR,CAAC;AACJ,CAAC;AAED,SAAS,QAAQ,CAAC,MAAe;IAC/B,IAAI,MAAM,EAAE,CAAC;QACX,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,EAAE,aAAa,EAAE,CAAC;IACnE,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC;AAC9D,CAAC"}
@@ -0,0 +1,18 @@
1
+ import type { ReactElement } from 'react';
2
+ import type { CitationFormatId } from '../core/formats.ts';
3
+ import type { Reference } from '../core/reference.ts';
4
+ import type { CitationStyleId } from '../core/segments.ts';
5
+ export interface CitationPreviewProps {
6
+ reference: Reference;
7
+ format: CitationFormatId;
8
+ /** Journal style, for the formats that have one. */
9
+ style?: CitationStyleId;
10
+ }
11
+ /**
12
+ * What a copy of the reference puts on the clipboard, as it will read once
13
+ * pasted: the emphasis of the style for HTML, the source itself otherwise.
14
+ * @param props - Reference, format and style to preview.
15
+ * @returns The body of the preview tooltip.
16
+ */
17
+ export declare function CitationPreview(props: CitationPreviewProps): ReactElement;
18
+ //# sourceMappingURL=CitationPreview.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CitationPreview.d.ts","sourceRoot":"","sources":["../../../src/citation/ui/CitationPreview.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAiB,YAAY,EAAE,MAAM,OAAO,CAAC;AAEzD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAE3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AA2B3D,MAAM,WAAW,oBAAoB;IACnC,SAAS,EAAE,SAAS,CAAC;IACrB,MAAM,EAAE,gBAAgB,CAAC;IACzB,oDAAoD;IACpD,KAAK,CAAC,EAAE,eAAe,CAAC;CACzB;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,GAAG,YAAY,CAoBzE"}
@@ -0,0 +1,55 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { formatCitation } from "../core/formats.js";
3
+ import { citationSegments } from "../core/segments.js";
4
+ // A BibTeX entry and a one-line citation share this box, so the text wraps and
5
+ // the box never grows past what a tooltip can hold. The height is the last
6
+ // resort, for a window too short to show an entry whole.
7
+ const PREVIEW_STYLE = {
8
+ maxWidth: 440,
9
+ maxHeight: '70vh',
10
+ overflow: 'auto',
11
+ margin: 0,
12
+ color: '#e5e8eb',
13
+ fontFamily: 'ui-monospace, SFMono-Regular, Menlo, monospace',
14
+ fontSize: 11.5,
15
+ lineHeight: 1.45,
16
+ whiteSpace: 'pre-wrap',
17
+ overflowWrap: 'anywhere',
18
+ };
19
+ // HTML is previewed as it reads once pasted, so it takes the reading font.
20
+ const RICH_STYLE = {
21
+ maxWidth: 440,
22
+ color: '#e5e8eb',
23
+ fontSize: 12,
24
+ lineHeight: 1.45,
25
+ };
26
+ const LINK_STYLE = { color: '#8abbff' };
27
+ /**
28
+ * What a copy of the reference puts on the clipboard, as it will read once
29
+ * pasted: the emphasis of the style for HTML, the source itself otherwise.
30
+ * @param props - Reference, format and style to preview.
31
+ * @returns The body of the preview tooltip.
32
+ */
33
+ export function CitationPreview(props) {
34
+ const { reference, format, style } = props;
35
+ if (format === 'html' && style !== undefined) {
36
+ return (_jsx("div", { className: "citation-preview", style: RICH_STYLE, children: citationSegments(reference, style).map((segment, index) => (_jsx(Segment, { segment: segment }, index))) }));
37
+ }
38
+ return (_jsx("pre", { className: "citation-preview", style: PREVIEW_STYLE, children: formatCitation(reference, format, style) }));
39
+ }
40
+ function Segment(props) {
41
+ const { segment } = props;
42
+ switch (segment.kind) {
43
+ case 'italic':
44
+ return _jsx("em", { children: segment.text });
45
+ case 'bold':
46
+ return _jsx("strong", { children: segment.text });
47
+ case 'link':
48
+ return _jsx("span", { style: LINK_STYLE, children: segment.text });
49
+ case 'text':
50
+ return _jsx("span", { children: segment.text });
51
+ default:
52
+ return _jsx("span", {});
53
+ }
54
+ }
55
+ //# sourceMappingURL=CitationPreview.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CitationPreview.js","sourceRoot":"","sources":["../../../src/citation/ui/CitationPreview.tsx"],"names":[],"mappings":";AAGA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAGpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD,+EAA+E;AAC/E,2EAA2E;AAC3E,yDAAyD;AACzD,MAAM,aAAa,GAAkB;IACnC,QAAQ,EAAE,GAAG;IACb,SAAS,EAAE,MAAM;IACjB,QAAQ,E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T,OAAO,2BAAS,OAAO,CAAC,IAAI,GAAU,CAAC;QACzC,KAAK,MAAM;YACT,OAAO,eAAM,KAAK,EAAE,UAAU,YAAG,OAAO,CAAC,IAAI,GAAQ,CAAC;QACxD,KAAK,MAAM;YACT,OAAO,yBAAO,OAAO,CAAC,IAAI,GAAQ,CAAC;QACrC;YACE,OAAO,gBAAQ,CAAC;IACpB,CAAC;AACH,CAAC"}
@@ -0,0 +1,22 @@
1
+ import type { ReactElement } from 'react';
2
+ import type { HeaderButtonProps } from '../../shared/ui/MenuButton.tsx';
3
+ import type { Reference } from '../core/reference.ts';
4
+ export interface CiteButtonProps extends HeaderButtonProps {
5
+ /** The work the site asks to be cited. */
6
+ reference: Reference;
7
+ /**
8
+ * Text of the button. In a compact bar it is not written, but it stays what
9
+ * the pointer and a screen reader are told.
10
+ * @default 'Cite'
11
+ */
12
+ label?: string;
13
+ }
14
+ /**
15
+ * The Cite entry of a site header: one button opening the article at its DOI,
16
+ * the reference in the style a journal asks for, and the files a reference
17
+ * manager imports.
18
+ * @param props - The work being cited, and how the menu opens.
19
+ * @returns The button and its menu.
20
+ */
21
+ export declare function CiteButton(props: CiteButtonProps): ReactElement;
22
+ //# sourceMappingURL=CiteButton.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CiteButton.d.ts","sourceRoot":"","sources":["../../../src/citation/ui/CiteButton.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAE1C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AAExE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAItD,MAAM,WAAW,eAAgB,SAAQ,iBAAiB;IACxD,0CAA0C;IAC1C,SAAS,EAAE,SAAS,CAAC;IACrB;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,YAAY,CAY/D"}
@@ -0,0 +1,15 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { MenuButton } from "../../shared/ui/MenuButton.js";
3
+ import { CitationMenu } from "./CitationMenu.js";
4
+ /**
5
+ * The Cite entry of a site header: one button opening the article at its DOI,
6
+ * the reference in the style a journal asks for, and the files a reference
7
+ * manager imports.
8
+ * @param props - The work being cited, and how the menu opens.
9
+ * @returns The button and its menu.
10
+ */
11
+ export function CiteButton(props) {
12
+ const { reference, label = 'Cite', ...rest } = props;
13
+ return (_jsx(MenuButton, { ...rest, className: "citation-button", icon: "citation", label: label, menu: _jsx(CitationMenu, { reference: reference }) }));
14
+ }
15
+ //# sourceMappingURL=CiteButton.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CiteButton.js","sourceRoot":"","sources":["../../../src/citation/ui/CiteButton.tsx"],"names":[],"mappings":";AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,+BAAgC,CAAC;AAG5D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAoB,CAAC;AAalD;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAAC,KAAsB;IAC/C,MAAM,EAAE,SAAS,EAAE,KAAK,GAAG,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,KAAK,CAAC;IAErD,OAAO,CACL,KAAC,UAAU,OACL,IAAI,EACR,SAAS,EAAC,iBAAiB,EAC3B,IAAI,EAAC,UAAU,EACf,KAAK,EAAE,KAAK,EACZ,IAAI,EAAE,KAAC,YAAY,IAAC,SAAS,EAAE,SAAS,GAAI,GAC5C,CACH,CAAC;AACJ,CAAC"}
@@ -0,0 +1,45 @@
1
+ import type { IconName, Intent } from '@blueprintjs/core';
2
+ import type { ReactElement } from 'react';
3
+ import type { CitationDownload, CitationFormat } from '../core/formats.ts';
4
+ import type { Reference } from '../core/reference.ts';
5
+ import type { CitationStyle } from '../core/segments.ts';
6
+ /** Feedback shown on an entry just after it was clicked. */
7
+ export interface CopyState {
8
+ icon: IconName;
9
+ intent: Intent;
10
+ label: string;
11
+ }
12
+ export interface CopyEntryProps {
13
+ /** The work being cited. */
14
+ reference: Reference;
15
+ /** The format the entry copies. */
16
+ format: CitationFormat;
17
+ /**
18
+ * Style of the entry, when it sits in the submenu of a styled format.
19
+ * @default undefined
20
+ */
21
+ style?: CitationStyle;
22
+ /** Feedback of the last copy, while it is showing. */
23
+ state: CopyState | null;
24
+ /** Called with what the entry copies. */
25
+ onCopy: (format: CitationFormat, style?: CitationStyle) => void;
26
+ }
27
+ /**
28
+ * One entry that copies, previewing on hover what it puts on the clipboard.
29
+ * @param props - The reference, the format, and the feedback showing.
30
+ * @returns The menu entry.
31
+ */
32
+ export declare function CopyEntry(props: CopyEntryProps): ReactElement;
33
+ export interface DownloadEntryProps {
34
+ /** The work being saved. */
35
+ reference: Reference;
36
+ /** The file to write, from `CITATION_DOWNLOADS`. */
37
+ download: CitationDownload;
38
+ }
39
+ /**
40
+ * One entry saving the file a reference manager imports.
41
+ * @param props - The entry options.
42
+ * @returns The menu entry.
43
+ */
44
+ export declare function DownloadEntry(props: DownloadEntryProps): ReactElement;
45
+ //# sourceMappingURL=entries.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entries.d.ts","sourceRoot":"","sources":["../../../src/citation/ui/entries.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE1D,OAAO,KAAK,EAAiB,YAAY,EAAE,MAAM,OAAO,CAAC;AAGzD,OAAO,KAAK,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAC3E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAczD,4DAA4D;AAC5D,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,QAAQ,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,cAAc;IAC7B,4BAA4B;IAC5B,SAAS,EAAE,SAAS,CAAC;IACrB,mCAAmC;IACnC,MAAM,EAAE,cAAc,CAAC;IACvB;;;OAGG;IACH,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,sDAAsD;IACtD,KAAK,EAAE,SAAS,GAAG,IAAI,CAAC;IACxB,yCAAyC;IACzC,MAAM,EAAE,CAAC,MAAM,EAAE,cAAc,EAAE,KAAK,CAAC,EAAE,aAAa,KAAK,IAAI,CAAC;CACjE;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,GAAG,YAAY,CA6B7D;AAED,MAAM,WAAW,kBAAkB;IACjC,4BAA4B;IAC5B,SAAS,EAAE,SAAS,CAAC;IACrB,oDAAoD;IACpD,QAAQ,EAAE,gBAAgB,CAAC;CAC5B;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,kBAAkB,GAAG,YAAY,CAkBrE"}
@@ -0,0 +1,52 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { MenuItem, Tooltip } from '@blueprintjs/core';
3
+ import { downloadCitation } from "../core/download.js";
4
+ import { CitationPreview } from "./CitationPreview.js";
5
+ // An entry carrying its preview tooltip is also a popover target, and
6
+ // Blueprint's `.bp6-submenu .bp6-popover-target` then turns the row into a
7
+ // block, stacking the icon, the name and the journals. An inline rule outranks
8
+ // any selector, so the row survives wherever the entry is used.
9
+ const ENTRY_STYLE = { display: 'flex' };
10
+ // Journal names are set in italic, as every one of these styles asks for.
11
+ const JOURNALS_STYLE = { fontStyle: 'italic' };
12
+ // Long enough that running the pointer down the menu opens no preview.
13
+ const PREVIEW_OPEN_DELAY = 400;
14
+ /**
15
+ * One entry that copies, previewing on hover what it puts on the clipboard.
16
+ * @param props - The reference, the format, and the feedback showing.
17
+ * @returns The menu entry.
18
+ */
19
+ export function CopyEntry(props) {
20
+ const { reference, format, style, state, onCopy } = props;
21
+ const entry = style ?? format;
22
+ return (_jsx(PreviewTooltip, { reference: reference, format: format.id, style: style, children: (targetProps) => (_jsx(MenuItem, { ...targetProps, style: ENTRY_STYLE, icon: state?.icon ?? 'clipboard', intent: state?.intent, text: entry.label, labelElement:
23
+ // The hint of a style entry is a list of journals, in italic.
24
+ style !== undefined && state === null ? (_jsx("span", { style: JOURNALS_STYLE, children: entry.hint })) : ((state?.label ?? entry.hint)), shouldDismissPopover: false, onClick: () => {
25
+ onCopy(format, style);
26
+ } })) }));
27
+ }
28
+ /**
29
+ * One entry saving the file a reference manager imports.
30
+ * @param props - The entry options.
31
+ * @returns The menu entry.
32
+ */
33
+ export function DownloadEntry(props) {
34
+ const { reference, download } = props;
35
+ return (_jsx(PreviewTooltip, { reference: reference, format: download.format, children: (targetProps) => (_jsx(MenuItem, { ...targetProps, style: ENTRY_STYLE, icon: "download", text: download.label, labelElement: download.hint, onClick: () => {
36
+ downloadCitation(reference, download);
37
+ } })) }));
38
+ }
39
+ /**
40
+ * The hover preview of what an entry copies or saves.
41
+ * @param props - The preview options.
42
+ * @param props.reference - The work being written.
43
+ * @param props.format - The format the entry produces.
44
+ * @param props.style - The journal style, for a format that has one.
45
+ * @param props.children - The entry the preview is anchored on.
46
+ * @returns The entry, wrapped in its preview tooltip.
47
+ */
48
+ function PreviewTooltip(props) {
49
+ const { reference, format, style, children } = props;
50
+ return (_jsx(Tooltip, { placement: "left", popoverClassName: "citation-tooltip", hoverOpenDelay: PREVIEW_OPEN_DELAY, content: _jsx(CitationPreview, { reference: reference, format: format, style: style?.id }), renderTarget: ({ isOpen, ...targetProps }) => children(targetProps) }));
51
+ }
52
+ //# sourceMappingURL=entries.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entries.js","sourceRoot":"","sources":["../../../src/citation/ui/entries.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,mBAA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,CAAC,CAAC;YACxB,CAAC,GACD,CACH,GACc,CAClB,CAAC;AACJ,CAAC;AASD;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,KAAyB;IACrD,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IACtC,OAAO,CACL,KAAC,cAAc,IAAC,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,CAAC,MAAM,YAC1D,CAAC,WAAW,EAAE,EAAE,CAAC,CAChB,KAAC,QAAQ,OACH,WAAW,EACf,KAAK,EAAE,WAAW,EAClB,IAAI,EAAC,UAAU,EACf,IAAI,EAAE,QAAQ,CAAC,KAAK,EACpB,YAAY,EAAE,QAAQ,CAAC,IAAI,EAC3B,OAAO,EAAE,GAAG,EAAE;gBACZ,gBAAgB,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;YACxC,CAAC,GACD,CACH,GACc,CAClB,CAAC;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,SAAS,cAAc,CAAC,KAKvB;IACC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IACrD,OAAO,CACL,KAAC,OAAO,IACN,SAAS,EAAC,MAAM,EAChB,gBAAgB,EAAC,kBAAkB,EACnC,cAAc,EAAE,kBAAkB,EAClC,OAAO,EACL,KAAC,eAAe,IACd,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,KAAK,EAAE,EAAE,GAChB,EAEJ,YAAY,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,WAAW,EAAE,EAAE,EAAE,CAAC,QAAQ,CAAC,WAAW,CAAC,GACnE,CACH,CAAC;AACJ,CAAC"}
@@ -0,0 +1,7 @@
1
+ export type { CitationMenuProps } from './CitationMenu.tsx';
2
+ export { CitationMenu } from './CitationMenu.tsx';
3
+ export type { CitationPreviewProps } from './CitationPreview.tsx';
4
+ export { CitationPreview } from './CitationPreview.tsx';
5
+ export type { CiteButtonProps } from './CiteButton.tsx';
6
+ export { CiteButton } from './CiteButton.tsx';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/citation/ui/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,YAAY,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,YAAY,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { CitationMenu } from "./CitationMenu.js";
2
+ export { CitationPreview } from "./CitationPreview.js";
3
+ export { CiteButton } from "./CiteButton.js";
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/citation/ui/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAoB,CAAC;AAElD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAuB,CAAC;AAExD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAkB,CAAC"}
package/lib/core.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './citation/core/index.ts';
2
+ export * from './ecosystem/core/index.ts';
3
+ //# sourceMappingURL=core.d.ts.map