From 0cae3269837e17dee7fefd9de96c3e2846f2fd0a Mon Sep 17 00:00:00 2001 From: Dominic D Date: Mon, 19 Aug 2024 19:59:35 +0000 Subject: [PATCH] Fix localisation in external windows by passing in global `addon` instance (#283) --- src/cita/sourceItemWrapper.ts | 4 ++-- src/cita/wikidata.ts | 2 +- src/components/itemPane/citationsBox.tsx | 2 +- src/dialogs/citation-importer/index.tsx | 5 +++-- src/dialogs/editor/CitationEditor.tsx | 2 +- src/dialogs/editor/index.tsx | 7 +++---- src/dialogs/identifier-importer/index.tsx | 3 ++- src/dialogs/selector/index.tsx | 8 ++++++-- 8 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/cita/sourceItemWrapper.ts b/src/cita/sourceItemWrapper.ts index 99217cf..b164387 100644 --- a/src/cita/sourceItemWrapper.ts +++ b/src/cita/sourceItemWrapper.ts @@ -623,7 +623,7 @@ class SourceItemWrapper extends ItemWrapper { async importCitations() { // open a new window where the user can paste in bibliographic text, or select a file const args = { - Wikicite: Wikicite, + addon: addon, }; const retVals: { text?: string; path?: string } = {}; window.openDialog( @@ -776,7 +776,7 @@ class SourceItemWrapper extends ItemWrapper { async addCitationsByIdentifier() { // open a new window where the user can paste in identifier strings const args = { - Wikicite: Wikicite, + addon: addon, }; const retVals: { text?: string } = {}; window.openDialog( diff --git a/src/cita/wikidata.ts b/src/cita/wikidata.ts index 8c1d860..6441ee3 100644 --- a/src/cita/wikidata.ts +++ b/src/cita/wikidata.ts @@ -347,7 +347,7 @@ export default class { Zotero.ItemTypes.getLocalizedString(item.type), ], ), - Wikicite: Wikicite, + addon: addon, }; const selection: { value?: number } = {}; window.openDialog( diff --git a/src/components/itemPane/citationsBox.tsx b/src/components/itemPane/citationsBox.tsx index 473369d..42aef0a 100644 --- a/src/components/itemPane/citationsBox.tsx +++ b/src/components/itemPane/citationsBox.tsx @@ -84,7 +84,7 @@ function CitationsBox(props: { function openEditor(citation: Citation): Zotero.Item | undefined { const args = { citation: citation, - Wikicite: Wikicite, + addon: addon, }; const retVals: { [key: string]: any } = {}; window.openDialog( diff --git a/src/dialogs/citation-importer/index.tsx b/src/dialogs/citation-importer/index.tsx index 09b4ec6..6925459 100644 --- a/src/dialogs/citation-importer/index.tsx +++ b/src/dialogs/citation-importer/index.tsx @@ -1,8 +1,9 @@ import CitationImporter from "./CitationImporter"; import * as React from "react"; import { createRoot } from "react-dom/client"; +import Wikicite from "../../cita/wikicite"; -const { Wikicite } = (window as any).arguments[0]; +({ addon: window.addon } = (window as any).arguments[0]); const retVals: { path?: string; text?: string } = (window as any).arguments[1]; function onCancel() { @@ -33,7 +34,7 @@ async function onImportFile() { window.close(); } -function onImportText(text) { +function onImportText(text: string) { retVals.text = text; window.close(); } diff --git a/src/dialogs/editor/CitationEditor.tsx b/src/dialogs/editor/CitationEditor.tsx index fc660e7..7b7726c 100644 --- a/src/dialogs/editor/CitationEditor.tsx +++ b/src/dialogs/editor/CitationEditor.tsx @@ -10,7 +10,7 @@ const visibleBaseFieldNames = ["title", "publicationTitle", "date"]; // consider providing at least some read only information about the citation // such as label of the source item, OCIs, and Zotero link status const CitationEditor = (props: { - checkCitationPID: (type: string, value: string) => boolean; + checkCitationPID: (type: PIDType, value: string) => boolean; item: ItemWrapper; itemBox: any; getString: (name: string) => string; diff --git a/src/dialogs/editor/index.tsx b/src/dialogs/editor/index.tsx index 0dd31cd..4dee29e 100644 --- a/src/dialogs/editor/index.tsx +++ b/src/dialogs/editor/index.tsx @@ -3,12 +3,11 @@ import ItemWrapper from "../../cita/itemWrapper"; import * as React from "react"; import { createRoot } from "react-dom/client"; import Citation from "../../cita/citation"; +import Wikicite from "../../cita/wikicite"; let citation: Citation; -let Wikicite: any; -({ citation, Wikicite } = (window as any).arguments[0]); +({ citation, addon: window.addon } = (window as any).arguments[0]); const retVals: { item?: Zotero.Item } = (window as any).arguments[1]; - let newItem: ItemWrapper; function onCancel() { @@ -27,7 +26,7 @@ function onSave() { window.close(); } -function checkPID(type: string, value: string) { +function checkPID(type: PIDType, value: string) { return citation.source.checkPID(type, value, { alert: true, parentWindow: window, diff --git a/src/dialogs/identifier-importer/index.tsx b/src/dialogs/identifier-importer/index.tsx index ee4ca60..e461555 100644 --- a/src/dialogs/identifier-importer/index.tsx +++ b/src/dialogs/identifier-importer/index.tsx @@ -1,8 +1,9 @@ import IdentifierImporter from "./IdentifierImporter"; import * as React from "react"; import { createRoot } from "react-dom/client"; +import Wikicite from "../../cita/wikicite"; -const { Wikicite } = (window as any).arguments[0]; +({ addon: window.addon } = (window as any).arguments[0]); const retVals: { text?: string } = (window as any).arguments[1]; function onCancel() { diff --git a/src/dialogs/selector/index.tsx b/src/dialogs/selector/index.tsx index 91d49b8..db6b35a 100644 --- a/src/dialogs/selector/index.tsx +++ b/src/dialogs/selector/index.tsx @@ -1,11 +1,15 @@ import Selector from "./Selector"; import * as React from "react"; import { createRoot } from "react-dom/client"; +import Wikicite from "../../cita/wikicite"; let choices: string[]; let message: string; -let Wikicite: any; -({ choices: choices, message, Wikicite } = (window as any).arguments[0]); +({ + choices: choices, + message, + addon: window.addon, +} = (window as any).arguments[0]); const retVals: { value?: number } = (window as any).arguments[1]; function onCancel() {