react-cheminfo 0.59.0 → 0.61.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 (140) hide show
  1. package/README.md +36 -2
  2. package/lib/about/ui/AboutBuildDetails.d.ts +15 -0
  3. package/lib/about/ui/AboutBuildDetails.d.ts.map +1 -0
  4. package/lib/about/ui/AboutBuildDetails.js +17 -0
  5. package/lib/about/ui/AboutBuildDetails.js.map +1 -0
  6. package/lib/about/ui/AboutPage.d.ts +8 -0
  7. package/lib/about/ui/AboutPage.d.ts.map +1 -1
  8. package/lib/about/ui/AboutPage.js +12 -3
  9. package/lib/about/ui/AboutPage.js.map +1 -1
  10. package/lib/about/ui/AboutSignIn.d.ts +33 -0
  11. package/lib/about/ui/AboutSignIn.d.ts.map +1 -0
  12. package/lib/about/ui/AboutSignIn.js +28 -0
  13. package/lib/about/ui/AboutSignIn.js.map +1 -0
  14. package/lib/about/ui/AboutVersion.d.ts +4 -2
  15. package/lib/about/ui/AboutVersion.d.ts.map +1 -1
  16. package/lib/about/ui/AboutVersion.js +21 -3
  17. package/lib/about/ui/AboutVersion.js.map +1 -1
  18. package/lib/about/ui/index.d.ts +2 -2
  19. package/lib/about/ui/index.d.ts.map +1 -1
  20. package/lib/about/ui/index.js +1 -1
  21. package/lib/about/ui/index.js.map +1 -1
  22. package/lib/chrome/ui/NavEntry.d.ts +16 -0
  23. package/lib/chrome/ui/NavEntry.d.ts.map +1 -0
  24. package/lib/chrome/ui/NavEntry.js +27 -0
  25. package/lib/chrome/ui/NavEntry.js.map +1 -0
  26. package/lib/chrome/ui/SiteHeader.d.ts +11 -4
  27. package/lib/chrome/ui/SiteHeader.d.ts.map +1 -1
  28. package/lib/chrome/ui/SiteHeader.js +4 -26
  29. package/lib/chrome/ui/SiteHeader.js.map +1 -1
  30. package/lib/core.d.ts +1 -0
  31. package/lib/core.d.ts.map +1 -1
  32. package/lib/core.js +1 -0
  33. package/lib/core.js.map +1 -1
  34. package/lib/i18n/core/chromeCatalog.d.ts +1 -1
  35. package/lib/i18n/core/chromeCatalog.d.ts.map +1 -1
  36. package/lib/locales/de.json +11 -3
  37. package/lib/locales/en.json +11 -3
  38. package/lib/locales/es.json +11 -3
  39. package/lib/locales/fr.json +11 -3
  40. package/lib/locales/it.json +11 -3
  41. package/lib/moleculesSources/core/index.d.ts +3 -0
  42. package/lib/moleculesSources/core/index.d.ts.map +1 -0
  43. package/lib/moleculesSources/core/index.js +2 -0
  44. package/lib/moleculesSources/core/index.js.map +1 -0
  45. package/lib/moleculesSources/core/moleculesSources.d.ts +55 -0
  46. package/lib/moleculesSources/core/moleculesSources.d.ts.map +1 -0
  47. package/lib/moleculesSources/core/moleculesSources.js +63 -0
  48. package/lib/moleculesSources/core/moleculesSources.js.map +1 -0
  49. package/lib/moleculesSources/ui/MoleculesSourceBadge.d.ts +18 -0
  50. package/lib/moleculesSources/ui/MoleculesSourceBadge.d.ts.map +1 -0
  51. package/lib/moleculesSources/ui/MoleculesSourceBadge.js +22 -0
  52. package/lib/moleculesSources/ui/MoleculesSourceBadge.js.map +1 -0
  53. package/lib/moleculesSources/ui/SourceBadge.d.ts +57 -0
  54. package/lib/moleculesSources/ui/SourceBadge.d.ts.map +1 -0
  55. package/lib/moleculesSources/ui/SourceBadge.js +29 -0
  56. package/lib/moleculesSources/ui/SourceBadge.js.map +1 -0
  57. package/lib/moleculesSources/ui/index.d.ts +7 -0
  58. package/lib/moleculesSources/ui/index.d.ts.map +1 -0
  59. package/lib/moleculesSources/ui/index.js +4 -0
  60. package/lib/moleculesSources/ui/index.js.map +1 -0
  61. package/lib/moleculesSources/ui/useSourceLooks.d.ts +24 -0
  62. package/lib/moleculesSources/ui/useSourceLooks.d.ts.map +1 -0
  63. package/lib/moleculesSources/ui/useSourceLooks.js +53 -0
  64. package/lib/moleculesSources/ui/useSourceLooks.js.map +1 -0
  65. package/lib/moleculesToken/core/index.d.ts +1 -0
  66. package/lib/moleculesToken/core/index.d.ts.map +1 -1
  67. package/lib/moleculesToken/core/index.js +1 -0
  68. package/lib/moleculesToken/core/index.js.map +1 -1
  69. package/lib/moleculesToken/core/tokenFix.d.ts +18 -0
  70. package/lib/moleculesToken/core/tokenFix.d.ts.map +1 -0
  71. package/lib/moleculesToken/core/tokenFix.js +27 -0
  72. package/lib/moleculesToken/core/tokenFix.js.map +1 -0
  73. package/lib/moleculesToken/ui/MoleculesTokenFix.d.ts +22 -0
  74. package/lib/moleculesToken/ui/MoleculesTokenFix.d.ts.map +1 -0
  75. package/lib/moleculesToken/ui/MoleculesTokenFix.js +35 -0
  76. package/lib/moleculesToken/ui/MoleculesTokenFix.js.map +1 -0
  77. package/lib/moleculesToken/ui/MoleculesTokenTable.d.ts +6 -1
  78. package/lib/moleculesToken/ui/MoleculesTokenTable.d.ts.map +1 -1
  79. package/lib/moleculesToken/ui/MoleculesTokenTable.js +7 -75
  80. package/lib/moleculesToken/ui/MoleculesTokenTable.js.map +1 -1
  81. package/lib/moleculesToken/ui/index.d.ts +2 -0
  82. package/lib/moleculesToken/ui/index.d.ts.map +1 -1
  83. package/lib/moleculesToken/ui/index.js +1 -0
  84. package/lib/moleculesToken/ui/index.js.map +1 -1
  85. package/lib/moleculesToken/ui/tokenDetails.d.ts +13 -0
  86. package/lib/moleculesToken/ui/tokenDetails.d.ts.map +1 -0
  87. package/lib/moleculesToken/ui/tokenDetails.js +73 -0
  88. package/lib/moleculesToken/ui/tokenDetails.js.map +1 -0
  89. package/lib/server/siteFiles.d.ts +28 -0
  90. package/lib/server/siteFiles.d.ts.map +1 -0
  91. package/lib/server/siteFiles.js +57 -0
  92. package/lib/server/siteFiles.js.map +1 -0
  93. package/lib/server/staticSite.d.ts +42 -0
  94. package/lib/server/staticSite.d.ts.map +1 -0
  95. package/lib/server/staticSite.js +114 -0
  96. package/lib/server/staticSite.js.map +1 -0
  97. package/lib/server.d.ts +4 -0
  98. package/lib/server.d.ts.map +1 -0
  99. package/lib/server.js +3 -0
  100. package/lib/server.js.map +1 -0
  101. package/lib/ui.d.ts +1 -0
  102. package/lib/ui.d.ts.map +1 -1
  103. package/lib/ui.js +1 -0
  104. package/lib/ui.js.map +1 -1
  105. package/package.json +12 -1
  106. package/src/about/ui/AboutBuildDetails.tsx +45 -0
  107. package/src/about/ui/AboutPage.tsx +27 -13
  108. package/src/about/ui/AboutSignIn.tsx +63 -0
  109. package/src/about/ui/AboutVersion.tsx +27 -9
  110. package/src/about/ui/index.ts +2 -2
  111. package/src/chrome/ui/NavEntry.tsx +41 -0
  112. package/src/chrome/ui/SiteHeader.tsx +15 -41
  113. package/src/core.ts +1 -0
  114. package/src/locales/de.json +11 -3
  115. package/src/locales/en.json +11 -3
  116. package/src/locales/es.json +11 -3
  117. package/src/locales/fr.json +11 -3
  118. package/src/locales/it.json +11 -3
  119. package/src/moleculesSources/core/index.ts +11 -0
  120. package/src/moleculesSources/core/moleculesSources.ts +102 -0
  121. package/src/moleculesSources/ui/MoleculesSourceBadge.tsx +44 -0
  122. package/src/moleculesSources/ui/SourceBadge.tsx +117 -0
  123. package/src/moleculesSources/ui/index.ts +6 -0
  124. package/src/moleculesSources/ui/useSourceLooks.ts +70 -0
  125. package/src/moleculesToken/core/index.ts +1 -0
  126. package/src/moleculesToken/core/tokenFix.ts +37 -0
  127. package/src/moleculesToken/ui/MoleculesTokenFix.tsx +95 -0
  128. package/src/moleculesToken/ui/MoleculesTokenTable.tsx +20 -94
  129. package/src/moleculesToken/ui/index.ts +2 -0
  130. package/src/moleculesToken/ui/tokenDetails.tsx +91 -0
  131. package/src/server/siteFiles.ts +64 -0
  132. package/src/server/staticSite.ts +188 -0
  133. package/src/server.ts +7 -0
  134. package/src/ui.ts +1 -0
  135. package/styles/chrome.css +159 -0
  136. package/lib/about/ui/AboutBuild.d.ts +0 -18
  137. package/lib/about/ui/AboutBuild.d.ts.map +0 -1
  138. package/lib/about/ui/AboutBuild.js +0 -37
  139. package/lib/about/ui/AboutBuild.js.map +0 -1
  140. package/src/about/ui/AboutBuild.tsx +0 -54
@@ -10,7 +10,7 @@ import { SiteMark } from '../../ecosystem/ui/marks.tsx';
10
10
  import { useLanguage } from '../../i18n/ui/useLanguage.ts';
11
11
  import { useChromeT } from '../../i18n/ui/useT.ts';
12
12
 
13
- import { NavLink } from './NavLink.tsx';
13
+ import { NavEntry } from './NavEntry.tsx';
14
14
  import { NavMenuButton } from './NavMenuButton.tsx';
15
15
  import type { NavItem } from './navItem.ts';
16
16
  import { isModifiedClick } from './navItem.ts';
@@ -42,13 +42,20 @@ export interface SiteHeaderProps {
42
42
  */
43
43
  activeId?: string;
44
44
  /**
45
- * The utilities pushed to the right edge — About, Cite, Tools, the language,
46
- * sign in; Share has a prop of its own, so it always comes last. They
47
- * arrive dressed as bar items, so a plain `nav-link` and a `CiteButton` read
48
- * alike beside each other.
45
+ * The utilities pushed to the right edge — About, Cite, Tools, the language;
46
+ * Share and the account have props of their own, so they always come last.
47
+ * They arrive dressed as bar items, so a plain `nav-link` and a `CiteButton`
48
+ * read alike beside each other.
49
49
  * @default undefined
50
50
  */
51
51
  actions?: ReactNode;
52
+ /**
53
+ * Who is signed in, drawn at the extreme right, after Share — usually an
54
+ * `AccountButton`. A site passes it only while somebody is signed in: signing
55
+ * in starts on the About (`AboutPage`'s `signIn`), never in the bar.
56
+ * @default undefined
57
+ */
58
+ account?: ReactNode;
52
59
  /**
53
60
  * The Share entry, which closes the utilities on every site, after the
54
61
  * Contact entry. A site passes its own when it wraps the shared `ShareButton`
@@ -133,6 +140,7 @@ export function SiteHeader(props: SiteHeaderProps): ReactElement | null {
133
140
  activeId,
134
141
  actions,
135
142
  share,
143
+ account,
136
144
  contact,
137
145
  renderNavItem,
138
146
  embedded = false,
@@ -195,6 +203,7 @@ export function SiteHeader(props: SiteHeaderProps): ReactElement | null {
195
203
  <span className="spacer" />
196
204
  {actions === undefined &&
197
205
  share === undefined &&
206
+ account === undefined &&
198
207
  contactForm === '' ? null : (
199
208
  <div className="app-header-actions">
200
209
  {actions}
@@ -202,6 +211,7 @@ export function SiteHeader(props: SiteHeaderProps): ReactElement | null {
202
211
  <ContactButton siteId={site.id} formUrl={contactForm} />
203
212
  )}
204
213
  {share}
214
+ {account}
205
215
  </div>
206
216
  )}
207
217
  </div>
@@ -209,42 +219,6 @@ export function SiteHeader(props: SiteHeaderProps): ReactElement | null {
209
219
  );
210
220
  }
211
221
 
212
- /**
213
- * One page of the bar: a link, or the menu it opens when the entry folds pages
214
- * of its own. A menu stands where its pages would, among them and not among the
215
- * utilities, because picking one of them changes what the page shows.
216
- * @param props - The entry and the page on show.
217
- * @param props.item - The entry.
218
- * @param props.activeId - The page on show.
219
- * @returns The entry.
220
- */
221
- function NavEntry(props: {
222
- item: NavItem;
223
- activeId: string | undefined;
224
- }): ReactElement {
225
- const { item, activeId } = props;
226
- if (item.items === undefined) {
227
- return <NavLink item={item} active={item.id === activeId} />;
228
- }
229
-
230
- return (
231
- <NavMenuButton
232
- label={menuLabel(item)}
233
- icon={typeof item.icon === 'string' ? item.icon : undefined}
234
- items={item.items}
235
- activeId={activeId}
236
- placement="bottom-start"
237
- />
238
- );
239
- }
240
-
241
- // The trigger names itself to a screen reader, so an entry drawn as a glyph
242
- // alone says what it opens through its title rather than through its id.
243
- function menuLabel(item: NavItem): string {
244
- if (typeof item.label === 'string') return item.label;
245
- return item.title ?? item.id;
246
- }
247
-
248
222
  /** The two widths the bar's contents run at, as the classes that set them. */
249
223
  const INNER_CLASS = {
250
224
  page: 'app-header__inner',
package/src/core.ts CHANGED
@@ -14,6 +14,7 @@ export * from './error/core/index.ts';
14
14
  export * from './format/core/index.ts';
15
15
  export * from './i18n/core/index.ts';
16
16
  export * from './language/core/index.ts';
17
+ export * from './moleculesSources/core/index.ts';
17
18
  export * from './moleculesToken/core/index.ts';
18
19
  export * from './number/core/index.ts';
19
20
  export * from './orbital/core/index.ts';
@@ -107,10 +107,11 @@
107
107
  "about.providedBy": "Bereitgestellt von",
108
108
  "about.whatYouCanDo": "Was Sie hier tun können",
109
109
  "about.builtOn": "Aufgebaut auf",
110
+ "about.buildVersion": "Version {version}",
111
+ "about.buildBuilt": "Erstellt",
112
+ "about.buildCommit": "Commit",
110
113
  "about.howToCite": "Wie zu zitieren",
111
114
  "about.citeWork": "{what} zitieren",
112
- "about.built": "Erstellt {builtAt}.",
113
- "about.builtFromCommit": "Erstellt {builtAt} aus Commit {commit}.",
114
115
  "about.nameList": "{names} und {last}",
115
116
  "help.label": "Hilfe",
116
117
  "help.learnMore": "Mehr erfahren",
@@ -618,5 +619,12 @@
618
619
  "moleculesToken.refusedDetail": "nie ausgestellt oder widerrufen",
619
620
  "moleculesToken.unsetDetail": "Setzen Sie {variable} in der .env des Servers.",
620
621
  "moleculesToken.uncheckableDetail": "Dieses molecules.cheminfo.org kann noch keine Tokens prüfen.",
621
- "moleculesToken.howToChange": "Ein Token wird in der .env des Servers geändert und beim Neustart des Dienstes neu gelesen. molecules.cheminfo.org stellt einen neuen aus mit"
622
+ "moleculesToken.howToChange": "Ein Token wird in der .env des Servers geändert und beim Neustart des Dienstes neu gelesen. molecules.cheminfo.org stellt einen neuen aus mit",
623
+ "moleculesToken.fix.title": "Setzen Sie ein gültiges Token in {variables}",
624
+ "moleculesToken.fix.issueOne": "Stellen Sie ein Token auf der Admin-Seite von molecules.cheminfo.org aus:",
625
+ "moleculesToken.fix.issueMany": "Stellen Sie ein Token pro Quelle auf der Admin-Seite von molecules.cheminfo.org aus:",
626
+ "moleculesToken.fix.issueOnServer": "Oder auf dem Server von molecules.cheminfo.org:",
627
+ "moleculesToken.fix.envOne": "Tragen Sie es in die .env des Servers dieser Website ein:",
628
+ "moleculesToken.fix.envMany": "Tragen Sie sie in die .env des Servers dieser Website ein:",
629
+ "moleculesToken.fix.restart": "Starten Sie die Dienste neu, da sie die .env nur beim Start lesen:"
622
630
  }
@@ -107,10 +107,11 @@
107
107
  "about.providedBy": "Provided by",
108
108
  "about.whatYouCanDo": "What you can do here",
109
109
  "about.builtOn": "Built on",
110
+ "about.buildVersion": "Version {version}",
111
+ "about.buildBuilt": "Built",
112
+ "about.buildCommit": "Commit",
110
113
  "about.howToCite": "How to cite",
111
114
  "about.citeWork": "Cite {what}",
112
- "about.built": "Built {builtAt}.",
113
- "about.builtFromCommit": "Built {builtAt} from commit {commit}.",
114
115
  "about.nameList": "{names} and {last}",
115
116
  "credits.openbabel.description": "reads and writes the chemical file formats, and does the conversion itself.",
116
117
  "credits.openchemlib.description": "reads and writes structures, and computes their properties in the browser.",
@@ -618,5 +619,12 @@
618
619
  "moleculesToken.refusedDetail": "never issued, or revoked",
619
620
  "moleculesToken.unsetDetail": "Set {variable} in the server's .env.",
620
621
  "moleculesToken.uncheckableDetail": "This molecules.cheminfo.org cannot check a token yet.",
621
- "moleculesToken.howToChange": "A token is changed in the server's .env and read again when the service restarts. molecules.cheminfo.org issues a new one with"
622
+ "moleculesToken.howToChange": "A token is changed in the server's .env and read again when the service restarts. molecules.cheminfo.org issues a new one with",
623
+ "moleculesToken.fix.title": "Set a valid token in {variables}",
624
+ "moleculesToken.fix.issueOne": "Issue a token on the Admin page of molecules.cheminfo.org:",
625
+ "moleculesToken.fix.issueMany": "Issue one token per source on the Admin page of molecules.cheminfo.org:",
626
+ "moleculesToken.fix.issueOnServer": "Or, on the server of molecules.cheminfo.org:",
627
+ "moleculesToken.fix.envOne": "Write it in the .env of this site's server:",
628
+ "moleculesToken.fix.envMany": "Write them in the .env of this site's server:",
629
+ "moleculesToken.fix.restart": "Restart the services, which read the .env only when they start:"
622
630
  }
@@ -107,10 +107,11 @@
107
107
  "about.providedBy": "Ofrecido por",
108
108
  "about.whatYouCanDo": "Lo que puede hacer aquí",
109
109
  "about.builtOn": "Construido sobre",
110
+ "about.buildVersion": "Versión {version}",
111
+ "about.buildBuilt": "Compilado",
112
+ "about.buildCommit": "Commit",
110
113
  "about.howToCite": "Cómo citar",
111
114
  "about.citeWork": "Citar {what}",
112
- "about.built": "Compilado {builtAt}.",
113
- "about.builtFromCommit": "Compilado {builtAt} desde el commit {commit}.",
114
115
  "about.nameList": "{names} y {last}",
115
116
  "help.label": "Ayuda",
116
117
  "help.learnMore": "Saber más",
@@ -618,5 +619,12 @@
618
619
  "moleculesToken.refusedDetail": "nunca emitido, o revocado",
619
620
  "moleculesToken.unsetDetail": "Defina {variable} en el .env del servidor.",
620
621
  "moleculesToken.uncheckableDetail": "Este molecules.cheminfo.org aún no puede comprobar un token.",
621
- "moleculesToken.howToChange": "Un token se cambia en el .env del servidor y se vuelve a leer cuando el servicio se reinicia. molecules.cheminfo.org emite uno nuevo con"
622
+ "moleculesToken.howToChange": "Un token se cambia en el .env del servidor y se vuelve a leer cuando el servicio se reinicia. molecules.cheminfo.org emite uno nuevo con",
623
+ "moleculesToken.fix.title": "Defina un token válido en {variables}",
624
+ "moleculesToken.fix.issueOne": "Emita un token en la página Admin de molecules.cheminfo.org:",
625
+ "moleculesToken.fix.issueMany": "Emita un token por fuente en la página Admin de molecules.cheminfo.org:",
626
+ "moleculesToken.fix.issueOnServer": "O, en el servidor de molecules.cheminfo.org:",
627
+ "moleculesToken.fix.envOne": "Escríbalo en el .env del servidor de este sitio:",
628
+ "moleculesToken.fix.envMany": "Escríbalos en el .env del servidor de este sitio:",
629
+ "moleculesToken.fix.restart": "Reinicie los servicios, que solo leen el .env al arrancar:"
622
630
  }
@@ -107,10 +107,11 @@
107
107
  "about.providedBy": "Proposé par",
108
108
  "about.whatYouCanDo": "Ce que vous pouvez faire ici",
109
109
  "about.builtOn": "Construit sur",
110
+ "about.buildVersion": "Version {version}",
111
+ "about.buildBuilt": "Compilé",
112
+ "about.buildCommit": "Commit",
110
113
  "about.howToCite": "Comment citer",
111
114
  "about.citeWork": "Citer {what}",
112
- "about.built": "Compilé {builtAt}.",
113
- "about.builtFromCommit": "Compilé {builtAt} depuis le commit {commit}.",
114
115
  "about.nameList": "{names} et {last}",
115
116
  "help.label": "Aide",
116
117
  "help.learnMore": "En savoir plus",
@@ -618,5 +619,12 @@
618
619
  "moleculesToken.refusedDetail": "jamais émis, ou révoqué",
619
620
  "moleculesToken.unsetDetail": "Définissez {variable} dans le fichier .env du serveur.",
620
621
  "moleculesToken.uncheckableDetail": "Ce molecules.cheminfo.org ne sait pas encore vérifier un jeton.",
621
- "moleculesToken.howToChange": "Un jeton se change dans le fichier .env du serveur, et est relu au redémarrage du service. molecules.cheminfo.org en émet un nouveau avec"
622
+ "moleculesToken.howToChange": "Un jeton se change dans le fichier .env du serveur, et est relu au redémarrage du service. molecules.cheminfo.org en émet un nouveau avec",
623
+ "moleculesToken.fix.title": "Définissez un jeton valide dans {variables}",
624
+ "moleculesToken.fix.issueOne": "Émettez un jeton sur la page Admin de molecules.cheminfo.org :",
625
+ "moleculesToken.fix.issueMany": "Émettez un jeton par source sur la page Admin de molecules.cheminfo.org :",
626
+ "moleculesToken.fix.issueOnServer": "Ou, sur le serveur de molecules.cheminfo.org :",
627
+ "moleculesToken.fix.envOne": "Écrivez-le dans le fichier .env du serveur de ce site :",
628
+ "moleculesToken.fix.envMany": "Écrivez-les dans le fichier .env du serveur de ce site :",
629
+ "moleculesToken.fix.restart": "Redémarrez les services, qui ne lisent le fichier .env qu'à leur démarrage :"
622
630
  }
@@ -107,10 +107,11 @@
107
107
  "about.providedBy": "Offerto da",
108
108
  "about.whatYouCanDo": "Cosa si può fare qui",
109
109
  "about.builtOn": "Costruito su",
110
+ "about.buildVersion": "Versione {version}",
111
+ "about.buildBuilt": "Compilato",
112
+ "about.buildCommit": "Commit",
110
113
  "about.howToCite": "Come citare",
111
114
  "about.citeWork": "Citare {what}",
112
- "about.built": "Compilato {builtAt}.",
113
- "about.builtFromCommit": "Compilato {builtAt} dal commit {commit}.",
114
115
  "about.nameList": "{names} e {last}",
115
116
  "credits.openbabel.description": "legge e scrive i formati di file chimici, ed esegue la conversione stessa.",
116
117
  "credits.openchemlib.description": "legge e scrive strutture, e ne calcola le proprietà nel browser.",
@@ -618,5 +619,12 @@
618
619
  "moleculesToken.refusedDetail": "mai emesso, o revocato",
619
620
  "moleculesToken.unsetDetail": "Impostare {variable} nel file .env del server.",
620
621
  "moleculesToken.uncheckableDetail": "Questo molecules.cheminfo.org non sa ancora verificare un token.",
621
- "moleculesToken.howToChange": "Un token si cambia nel file .env del server e viene riletto al riavvio del servizio. molecules.cheminfo.org ne emette uno nuovo con"
622
+ "moleculesToken.howToChange": "Un token si cambia nel file .env del server e viene riletto al riavvio del servizio. molecules.cheminfo.org ne emette uno nuovo con",
623
+ "moleculesToken.fix.title": "Impostare un token valido in {variables}",
624
+ "moleculesToken.fix.issueOne": "Emettere un token nella pagina Admin di molecules.cheminfo.org:",
625
+ "moleculesToken.fix.issueMany": "Emettere un token per fonte nella pagina Admin di molecules.cheminfo.org:",
626
+ "moleculesToken.fix.issueOnServer": "Oppure, sul server di molecules.cheminfo.org:",
627
+ "moleculesToken.fix.envOne": "Scriverlo nel file .env del server di questo sito:",
628
+ "moleculesToken.fix.envMany": "Scriverli nel file .env del server di questo sito:",
629
+ "moleculesToken.fix.restart": "Riavviare i servizi, che leggono il file .env solo all'avvio:"
622
630
  }
@@ -0,0 +1,11 @@
1
+ export type {
2
+ FetchSourceLooksOptions,
3
+ SourceLook,
4
+ SourceLooks,
5
+ } from './moleculesSources.ts';
6
+ export {
7
+ MOLECULES_URL,
8
+ fetchSourceLooks,
9
+ readSourceLooks,
10
+ sourceLook,
11
+ } from './moleculesSources.ts';
@@ -0,0 +1,102 @@
1
+ /** Where molecules.cheminfo.org answers, which holds the family's sources. */
2
+ export const MOLECULES_URL = 'https://molecules.cheminfo.org';
3
+
4
+ /**
5
+ * How a source is drawn wherever the family names it — PubChem, ChEBI, COCONUT
6
+ * — as molecules.cheminfo.org publishes it. molecules is where a source's
7
+ * colour and logo are kept and edited, so every site reads them from there
8
+ * rather than keeping a copy that drifts the first time one is changed.
9
+ */
10
+ export interface SourceLook {
11
+ /** What the source is called, as molecules writes it: `ChEBI`. */
12
+ name: string;
13
+ /** The colour its badges are drawn in, as `#rrggbb`; null for none. */
14
+ color: string | null;
15
+ /** The absolute address of its little logo; null when it has none. */
16
+ logo: string | null;
17
+ }
18
+
19
+ /** Every source molecules publishes, by its name in lower case. */
20
+ export type SourceLooks = ReadonlyMap<string, SourceLook>;
21
+
22
+ /**
23
+ * The sources a `/v1/sources` answer describes, each logo made absolute
24
+ * against the address it was read from, so the badge draws it on any site.
25
+ * Anything not shaped like a source is left out rather than trusted.
26
+ * @param body - The parsed answer of `/v1/sources`.
27
+ * @param baseUrl - Where it was read from.
28
+ * @returns The looks, by lower-case name.
29
+ */
30
+ export function readSourceLooks(body: unknown, baseUrl: string): SourceLooks {
31
+ const looks = new Map<string, SourceLook>();
32
+ const sources = isRecord(body) ? body.sources : undefined;
33
+ if (!Array.isArray(sources)) return looks;
34
+ for (const source of sources) {
35
+ if (!isRecord(source) || typeof source.name !== 'string') continue;
36
+ const { name, color, logo } = source;
37
+ looks.set(name.toLowerCase(), {
38
+ name,
39
+ color: typeof color === 'string' && HEX_COLOR.test(color) ? color : null,
40
+ logo: typeof logo === 'string' ? absolute(logo, baseUrl) : null,
41
+ });
42
+ }
43
+ return looks;
44
+ }
45
+
46
+ /**
47
+ * The look of one source, named in any case.
48
+ * @param looks - What molecules publishes, or null while it is being read.
49
+ * @param name - The source's name or key: `chebi`, `ChEBI`.
50
+ * @returns Its look, or `undefined` when molecules does not know it (yet).
51
+ */
52
+ export function sourceLook(
53
+ looks: SourceLooks | null,
54
+ name: string,
55
+ ): SourceLook | undefined {
56
+ return looks?.get(name.toLowerCase());
57
+ }
58
+
59
+ /** Where and how {@link fetchSourceLooks} reads. */
60
+ export interface FetchSourceLooksOptions {
61
+ /**
62
+ * Where molecules answers.
63
+ * @default MOLECULES_URL
64
+ */
65
+ url?: string;
66
+ /**
67
+ * Aborts the read.
68
+ * @default undefined
69
+ */
70
+ signal?: AbortSignal;
71
+ }
72
+
73
+ /**
74
+ * Read every source's look from molecules.cheminfo.org.
75
+ * @param options - See {@link FetchSourceLooksOptions}.
76
+ * @returns The looks, by lower-case name.
77
+ * @throws {Error} When molecules does not answer, or answers with an error.
78
+ */
79
+ export async function fetchSourceLooks(
80
+ options: FetchSourceLooksOptions = {},
81
+ ): Promise<SourceLooks> {
82
+ const { url = MOLECULES_URL, signal } = options;
83
+ const response = await fetch(`${url}/v1/sources`, { signal });
84
+ if (!response.ok) {
85
+ throw new Error(`${url} answered ${response.status} for its sources`);
86
+ }
87
+ return readSourceLooks(await response.json(), url);
88
+ }
89
+
90
+ const HEX_COLOR = /^#[\da-f]{6}$/i;
91
+
92
+ function absolute(address: string, baseUrl: string): string | null {
93
+ try {
94
+ return new URL(address, baseUrl).href;
95
+ } catch {
96
+ return null;
97
+ }
98
+ }
99
+
100
+ function isRecord(value: unknown): value is Record<string, unknown> {
101
+ return typeof value === 'object' && value !== null;
102
+ }
@@ -0,0 +1,44 @@
1
+ import type { ReactElement } from 'react';
2
+
3
+ import { MOLECULES_URL, sourceLook } from '../core/moleculesSources.ts';
4
+
5
+ import type { SourceBadgeProps } from './SourceBadge.tsx';
6
+ import { SourceBadge } from './SourceBadge.tsx';
7
+ import { useSourceLooks } from './useSourceLooks.ts';
8
+
9
+ export interface MoleculesSourceBadgeProps extends Omit<
10
+ SourceBadgeProps,
11
+ 'color' | 'logo'
12
+ > {
13
+ /**
14
+ * Where molecules answers, for a site that reads another instance.
15
+ * @default MOLECULES_URL
16
+ */
17
+ moleculesUrl?: string;
18
+ }
19
+
20
+ /**
21
+ * A source named by a site that does not keep its look: the colour and the
22
+ * logo come from molecules.cheminfo.org, where they are edited. A source
23
+ * molecules does not know — or until it has answered — is drawn neutral.
24
+ * @param props - The source, by its name in any case, and the entry it holds.
25
+ * @returns The badge.
26
+ */
27
+ export function MoleculesSourceBadge(
28
+ props: MoleculesSourceBadgeProps,
29
+ ): ReactElement {
30
+ const { moleculesUrl = MOLECULES_URL, ...badge } = props;
31
+ const look = sourceLook(useSourceLooks(moleculesUrl), badge.name);
32
+ if (look === undefined) return <SourceBadge {...badge} />;
33
+
34
+ return (
35
+ <SourceBadge
36
+ {...badge}
37
+ label={badge.label ?? look.name}
38
+ // A source molecules draws in no colour of its own is drawn neutral
39
+ // here: the site naming it is not that source.
40
+ color={look.color ?? undefined}
41
+ logo={look.logo}
42
+ />
43
+ );
44
+ }
@@ -0,0 +1,117 @@
1
+ import type { CSSProperties, ReactElement, ReactNode } from 'react';
2
+
3
+ export interface SourceBadgeProps {
4
+ /** What the source is called, read in the badge's tooltip. */
5
+ name: string;
6
+ /**
7
+ * What the badge says.
8
+ * @default name
9
+ */
10
+ label?: ReactNode;
11
+ /**
12
+ * The source's own colour, as `#rrggbb`. `null` draws it in the site's own
13
+ * colour, which is how a site marks a source that is itself.
14
+ * @default undefined — a neutral grey, for a source with no look
15
+ */
16
+ color?: string | null;
17
+ /**
18
+ * The absolute address of its little logo.
19
+ * @default null
20
+ */
21
+ logo?: string | null;
22
+ /**
23
+ * The entry's identifier there, written after the name.
24
+ * @default null
25
+ */
26
+ identifier?: string | null;
27
+ /**
28
+ * How many entries the source holds, written after the name when more than
29
+ * one.
30
+ * @default 1
31
+ */
32
+ count?: number;
33
+ /**
34
+ * Where the badge leads, opened in a new tab.
35
+ * @default null — the badge names the source and leads nowhere
36
+ */
37
+ href?: string | null;
38
+ /**
39
+ * The tooltip.
40
+ * @default the name, then the identifier
41
+ */
42
+ title?: string;
43
+ /**
44
+ * The smaller badge of a dense list, whose identifier goes in the tooltip
45
+ * only.
46
+ * @default false
47
+ */
48
+ compact?: boolean;
49
+ }
50
+
51
+ /**
52
+ * A source, as a badge: its name in its own colour, its little logo on a white
53
+ * chip, and the entry it holds — the same badge on every site of the family
54
+ * that names where a molecule comes from.
55
+ * @param props - See {@link SourceBadgeProps}.
56
+ * @returns The badge.
57
+ */
58
+ export function SourceBadge(props: SourceBadgeProps): ReactElement {
59
+ const {
60
+ name,
61
+ label = name,
62
+ color,
63
+ logo = null,
64
+ identifier = null,
65
+ count = 1,
66
+ href = null,
67
+ compact = false,
68
+ } = props;
69
+ const title =
70
+ props.title ?? (identifier === null ? name : `${name} ${identifier}`);
71
+ const className = [
72
+ 'source-badge',
73
+ compact ? 'source-badge--compact' : '',
74
+ color === undefined ? 'source-badge--neutral' : '',
75
+ ]
76
+ .filter(Boolean)
77
+ .join(' ');
78
+ // A source with no colour of its own takes the site's, from the stylesheet.
79
+ const style =
80
+ typeof color === 'string'
81
+ ? ({ '--source': color } as CSSProperties)
82
+ : undefined;
83
+ const content = (
84
+ <>
85
+ {logo === null ? null : (
86
+ <span className="source-badge__logo">
87
+ <img src={logo} alt="" />
88
+ </span>
89
+ )}
90
+ <span className="source-badge__name">{label}</span>
91
+ {compact || identifier === null ? null : (
92
+ <span className="source-badge__id">{identifier}</span>
93
+ )}
94
+ {count > 1 ? <span className="source-badge__count">{count}</span> : null}
95
+ </>
96
+ );
97
+
98
+ if (href === null) {
99
+ return (
100
+ <span className={className} style={style} title={title}>
101
+ {content}
102
+ </span>
103
+ );
104
+ }
105
+ return (
106
+ <a
107
+ className={className}
108
+ style={style}
109
+ href={href}
110
+ target="_blank"
111
+ rel="noopener noreferrer"
112
+ title={title}
113
+ >
114
+ {content}
115
+ </a>
116
+ );
117
+ }
@@ -0,0 +1,6 @@
1
+ export type { MoleculesSourceBadgeProps } from './MoleculesSourceBadge.tsx';
2
+ export { MoleculesSourceBadge } from './MoleculesSourceBadge.tsx';
3
+ export type { SourceBadgeProps } from './SourceBadge.tsx';
4
+ export { SourceBadge } from './SourceBadge.tsx';
5
+ export type { SourceLooksStore } from './useSourceLooks.ts';
6
+ export { sourceLooksStore, useSourceLooks } from './useSourceLooks.ts';
@@ -0,0 +1,70 @@
1
+ import { useSyncExternalStore } from 'react';
2
+
3
+ import type { SourceLooks } from '../core/moleculesSources.ts';
4
+ import { MOLECULES_URL, fetchSourceLooks } from '../core/moleculesSources.ts';
5
+
6
+ /**
7
+ * Every source's look, read from molecules.cheminfo.org once per page however
8
+ * many badges ask for it.
9
+ * @param url - Where molecules answers.
10
+ * @returns The looks by lower-case name, or null until molecules has answered;
11
+ * an empty map when it could not be read, so the badges stop waiting and stay
12
+ * neutral.
13
+ */
14
+ export function useSourceLooks(
15
+ url: string = MOLECULES_URL,
16
+ ): SourceLooks | null {
17
+ const store = sourceLooksStore(url);
18
+ return useSyncExternalStore(store.subscribe, store.read, notYet);
19
+ }
20
+
21
+ /** The one read of a molecules address, shared by every badge on the page. */
22
+ export interface SourceLooksStore {
23
+ /** Follow the read, starting it on the first call. */
24
+ subscribe: (listener: () => void) => () => void;
25
+ /** What has been read so far. */
26
+ read: () => SourceLooks | null;
27
+ }
28
+
29
+ /**
30
+ * The store behind {@link useSourceLooks}: one per address, read once.
31
+ * @param url - Where molecules answers.
32
+ * @returns The store.
33
+ */
34
+ export function sourceLooksStore(url: string): SourceLooksStore {
35
+ let store = STORES.get(url);
36
+ if (store === undefined) {
37
+ store = createStore(url);
38
+ STORES.set(url, store);
39
+ }
40
+ return store;
41
+ }
42
+
43
+ const STORES = new Map<string, SourceLooksStore>();
44
+
45
+ function createStore(url: string): SourceLooksStore {
46
+ let looks: SourceLooks | null = null;
47
+ let started = false;
48
+ const listeners = new Set<() => void>();
49
+
50
+ function settle(value: SourceLooks): void {
51
+ looks = value;
52
+ for (const listener of listeners) listener();
53
+ }
54
+
55
+ return {
56
+ subscribe(listener) {
57
+ listeners.add(listener);
58
+ if (!started) {
59
+ started = true;
60
+ fetchSourceLooks({ url }).then(settle, () => settle(new Map()));
61
+ }
62
+ return () => listeners.delete(listener);
63
+ },
64
+ read: () => looks,
65
+ };
66
+ }
67
+
68
+ function notYet(): null {
69
+ return null;
70
+ }
@@ -9,3 +9,4 @@ export {
9
9
  checkMoleculesTokens,
10
10
  publicTokenCheck,
11
11
  } from './moleculesToken.ts';
12
+ export { issueTokenCommand, tokensToFix } from './tokenFix.ts';
@@ -0,0 +1,37 @@
1
+ import type {
2
+ MoleculesTokenCheck,
3
+ MoleculesTokenVerdict,
4
+ } from './moleculesToken.ts';
5
+
6
+ /** The verdicts only a new token, written in the server's `.env`, fixes. */
7
+ const NEEDS_NEW_TOKEN: ReadonlySet<MoleculesTokenVerdict> = new Set([
8
+ 'unset',
9
+ 'refused',
10
+ 'otherSource',
11
+ ]);
12
+
13
+ /**
14
+ * The checks whose token has to be replaced: none is set, molecules.cheminfo.org
15
+ * refuses it, or it was issued for another source. A token that could not be
16
+ * checked is not among them, since nothing written in the `.env` fixes that.
17
+ * @param checks - The last checks.
18
+ * @returns Those to fix, in the order given.
19
+ */
20
+ export function tokensToFix(
21
+ checks: readonly MoleculesTokenCheck[],
22
+ ): MoleculesTokenCheck[] {
23
+ return checks.filter((check) => NEEDS_NEW_TOKEN.has(check.verdict));
24
+ }
25
+
26
+ /**
27
+ * The command molecules.cheminfo.org issues a check's token with, on its
28
+ * server. The source is quoted, since a name like `NP Atlas` holds a space;
29
+ * the email is left for the reader to write.
30
+ * @param check - The check, whose first source the token is issued for.
31
+ * @returns The command.
32
+ */
33
+ export function issueTokenCommand(
34
+ check: Pick<MoleculesTokenCheck, 'sources'>,
35
+ ): string {
36
+ return `npm run tokens -- issue '${check.sources[0] ?? 'SOURCE'}' EMAIL`;
37
+ }