From e399db9dc578125b847e36729a33539a939015d0 Mon Sep 17 00:00:00 2001 From: Dae Houlihan Date: Tue, 8 Oct 2024 20:28:59 -0400 Subject: [PATCH] Fixes for ztoolkit upgrade --- README.md | 6 +++--- addon/chrome/content/preferences.xhtml | 21 +++++++++++++-------- src/hooks.ts | 4 +++- src/index.ts | 2 +- src/modules/mdbcScan.ts | 4 ++-- src/modules/mdbcStartupHelpers.ts | 4 ++-- src/modules/monkey-patch.ts | 2 +- src/modules/preferenceScript.ts | 8 ++++---- src/utils/locale.ts | 11 ++++++++++- src/utils/wait.ts | 2 +- src/utils/ztoolkit.ts | 23 ++--------------------- update-beta.json | 4 ++-- update.json | 4 ++-- 13 files changed, 46 insertions(+), 49 deletions(-) diff --git a/README.md b/README.md index 605d5c2..308f6e8 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,9 @@ - + - + @@ -39,7 +39,7 @@ Opens an existing markdown note in [Obsidian](https://obsidian.md), [logseq](htt - Open Zotero (version 7.x) - From `Tools -> Plugins` - Select `Install Add-on From File...` from the gear icon ⛭ -- Choose the `.xpi` file you downloaded (e.g. `mark-db-connect.xpi`) +- Choose the `.xpi` file you downloaded (e.g. `markdb-connect.xpi`) - Restart Zotero > [!NOTE] diff --git a/addon/chrome/content/preferences.xhtml b/addon/chrome/content/preferences.xhtml index 0e36cb3..ded8c99 100644 --- a/addon/chrome/content/preferences.xhtml +++ b/addon/chrome/content/preferences.xhtml @@ -104,12 +104,13 @@ >/i - The default file filter looks for Markdown files beginning with '@' : /^@.+\.md$/i - N.B. If the BBT citekey is present in the filename pattern, you can include one capturing group to match it. + + If the BBT citekey is present in the filename pattern, you can include one capturing group to match it. E.g. the default citekey-capturing RegExp uses the non-whitespace characters after the leading '@' as the BBT citekey:E.g. the default RegExp filters for MarkDown files that begin with @ and attempts to use the subsequent non-whitespace characters as the BBT citekey: - ^@(\S+).*\.md$ + /^@(\S+).*\.md$/i + @@ -139,7 +140,8 @@ - Markdown YAML Metadata Keyword (optional if BBT citkey is in title, required otherwise) + + Specify the markdown YAML metadata keyword (optional if BBT citkey is in title, required otherwise). YAML keyword: - + - - + Required: Specify a RegExp to match the Zotero-Item-Key from the markdown contents. RegExp://m + E.g. for a Zotero item that can be opened with this URI zotero://select/library/items/ABCD1234 the RegExp should return a single match: + 'ABCD1234'. N.B. The Zotero-Item-Key is assigned automatically by Zotero. It is not the same as the BetterBibTeX citekey. diff --git a/src/hooks.ts b/src/hooks.ts index 1288619..d4d2abb 100644 --- a/src/hooks.ts +++ b/src/hooks.ts @@ -29,7 +29,9 @@ async function onStartup() { // registerPreferenceStyleSheet() - await onMainWindowLoad(window) + // await onMainWindowLoad(window) + + await Promise.all(Zotero.getMainWindows().map((win) => onMainWindowLoad(win))) } async function onMainWindowLoad(win: Window): Promise { diff --git a/src/index.ts b/src/index.ts index 57e4936..dd2d822 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,4 @@ -import { BasicTool } from 'zotero-plugin-toolkit/dist/basic' +import { BasicTool } from 'zotero-plugin-toolkit' import { config } from '../package.json' diff --git a/src/modules/mdbcScan.ts b/src/modules/mdbcScan.ts index a705a88..919f697 100644 --- a/src/modules/mdbcScan.ts +++ b/src/modules/mdbcScan.ts @@ -2408,8 +2408,8 @@ export class BasicExampleFactory { src: rootURI + 'chrome/content/preferences.xhtml', label: getString('prefs-title'), image: favIcon, - defaultXUL: true, + // defaultXUL: true, } - ztoolkit.PreferencePane.register(prefOptions) + Zotero.PreferencePanes.register(prefOptions) } } diff --git a/src/modules/mdbcStartupHelpers.ts b/src/modules/mdbcStartupHelpers.ts index 8c58438..a7d4da0 100644 --- a/src/modules/mdbcStartupHelpers.ts +++ b/src/modules/mdbcStartupHelpers.ts @@ -59,7 +59,7 @@ export class wrappers { release: '', str: version, } - const versionThis_rematch = version.match(version_re) + const versionThis_rematch = version_re.exec(version) if (versionThis_rematch?.groups) { configurationVersionThis.major = parseInt(versionThis_rematch.groups.major) configurationVersionThis.minor = parseInt(versionThis_rematch.groups.minor) @@ -81,7 +81,7 @@ export class wrappers { configurationVersionPrevious.str = configurationVersionPreviousStr } if (typeof configurationVersionPreviousStr === 'string' && version_re.test(configurationVersionPreviousStr)) { - const version_rematch = configurationVersionPreviousStr.match(version_re) + const version_rematch = version_re.exec(configurationVersionPreviousStr) if (version_rematch?.groups) { configurationVersionPrevious.major = parseInt(version_rematch.groups.major) configurationVersionPrevious.minor = parseInt(version_rematch.groups.minor) diff --git a/src/modules/monkey-patch.ts b/src/modules/monkey-patch.ts index c542108..e6f58c6 100644 --- a/src/modules/monkey-patch.ts +++ b/src/modules/monkey-patch.ts @@ -1,4 +1,4 @@ -/* eslint-disable @typescript-eslint/ban-types, prefer-rest-params, @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-unsafe-return */ +/* eslint-disable @typescript-eslint/no-unsafe-function-type */ export type Trampoline = Function & { disabled?: boolean } const trampolines: Trampoline[] = [] diff --git a/src/modules/preferenceScript.ts b/src/modules/preferenceScript.ts index e430ba8..6f30fc5 100644 --- a/src/modules/preferenceScript.ts +++ b/src/modules/preferenceScript.ts @@ -91,7 +91,7 @@ async function updatePrefsUI() { // Returning false to prevent default event. .setProp('onKeyDown', (event: KeyboardEvent) => { if (event.key == 'Delete' || (Zotero.isMac && event.key == 'Backspace')) { - addon.data.prefs.rows = + addon.data.prefs!.rows = addon.data.prefs?.rows.filter((v, i) => !tableHelper.treeInstance.selection.isSelected(i)) || [] tableHelper.render() return false @@ -109,18 +109,18 @@ async function updatePrefsUI() { } function bindPrefEvents() { - addon.data.prefs.window.document + addon.data.prefs!.window.document .querySelector(`#zotero-prefpane-${config.addonRef}-enable`) ?.addEventListener('command', (e) => { ztoolkit.log(e) addon.data.prefs.window.alert(`Successfully changed to ${(e.target as XUL.Checkbox).checked}!`) }) - addon.data.prefs.window.document + addon.data.prefs!.window.document .querySelector(`#zotero-prefpane-${config.addonRef}-input`) ?.addEventListener('change', (e) => { ztoolkit.log(e) - addon.data.prefs.window.alert(`Successfully changed to ${(e.target as HTMLInputElement).value}!`) + addon.data.prefs!.window.alert(`Successfully changed to ${(e.target as HTMLInputElement).value}!`) }) } */ diff --git a/src/utils/locale.ts b/src/utils/locale.ts index b21dafd..1b2a4d5 100644 --- a/src/utils/locale.ts +++ b/src/utils/locale.ts @@ -1,6 +1,6 @@ import { config } from '../../package.json' -export { initLocale, getString } +export { initLocale, getString, getLocaleID } /** * Initialize locale data @@ -69,8 +69,17 @@ function _getString( return localStringWithPrefix } if (branch && pattern.attributes) { + for (const attr of pattern.attributes) { + if (attr.name === branch) { + return attr.value + } + } return pattern.attributes[branch] || localStringWithPrefix } else { return pattern.value || localStringWithPrefix } } + +function getLocaleID(id: string) { + return `${config.addonRef}-${id}` +} diff --git a/src/utils/wait.ts b/src/utils/wait.ts index 344e1a9..faa7462 100644 --- a/src/utils/wait.ts +++ b/src/utils/wait.ts @@ -33,7 +33,7 @@ export function waitUtilAsync(condition: () => boolean, interval = 100, timeout resolve() } else if (Date.now() - start > timeout) { ztoolkit.getGlobal('clearInterval')(intervalId) - reject() + reject(new Error('waitUtilAsync: something bad happened')) } }, interval) }) diff --git a/src/utils/ztoolkit.ts b/src/utils/ztoolkit.ts index ca53f63..728e4eb 100644 --- a/src/utils/ztoolkit.ts +++ b/src/utils/ztoolkit.ts @@ -1,4 +1,5 @@ -import ZoteroToolkit from 'zotero-plugin-toolkit' +// @ts-ignore +import { BasicTool, UITool, unregister, ZoteroToolkit } from 'zotero-plugin-toolkit' import { config } from '../../package.json' @@ -25,23 +26,3 @@ function initZToolkit(_ztoolkit: ReturnType) { _ztoolkit.basicOptions.api.pluginID = config.addonID _ztoolkit.ProgressWindow.setIconURI('default', `chrome://${config.addonRef}/content/icons/favicon.png`) } - -import { BasicTool, unregister } from 'zotero-plugin-toolkit/dist/basic' -import { PreferencePaneManager } from 'zotero-plugin-toolkit/dist/managers/preferencePane' -import { UITool } from 'zotero-plugin-toolkit/dist/tools/ui' - -// @ts-ignore -class MyToolkit extends BasicTool { - UI: UITool - PreferencePane: PreferencePaneManager - - constructor() { - super() - this.UI = new UITool(this) - this.PreferencePane = new PreferencePaneManager(this) - } - - unregisterAll() { - unregister(this) - } -} diff --git a/update-beta.json b/update-beta.json index 4e7bccc..0cf584c 100644 --- a/update-beta.json +++ b/update-beta.json @@ -3,8 +3,8 @@ "daeda@mit.edu": { "updates": [ { - "version": "0.1.1", - "update_link": "https://github.com/daeh/zotero-markdb-connect/releases/download/v0.1.1/mark-db-connect.xpi", + "version": "0.1.2", + "update_link": "https://github.com/daeh/zotero-markdb-connect/releases/download/v0.1.2/markdb-connect.xpi", "applications": { "zotero": { "strict_min_version": "6.999", diff --git a/update.json b/update.json index 594c6d9..1aa456d 100644 --- a/update.json +++ b/update.json @@ -3,8 +3,8 @@ "daeda@mit.edu": { "updates": [ { - "version": "0.1.1", - "update_link": "https://github.com/daeh/zotero-markdb-connect/releases/latest/download/mark-db-connect.xpi", + "version": "0.1.2", + "update_link": "https://github.com/daeh/zotero-markdb-connect/releases/latest/download/markdb-connect.xpi", "applications": { "zotero": { "strict_min_version": "6.999"