Skip to content

Commit e399db9

Browse files
committed
Fixes for ztoolkit upgrade
1 parent 53e71d1 commit e399db9

File tree

13 files changed

+46
-49
lines changed

13 files changed

+46
-49
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
<!-- [![GitHub Downloads release (by tag)](https://img.shields.io/github/downloads/daeh/zotero-markdb-connect/v0.0.25/total?style=for-the-badge)](https://github.com/daeh/zotero-markdb-connect/releases/tag/v0.0.27) -->
44

5-
<!-- [![GitHub release (with filter)](https://img.shields.io/github/v/release/daeh/zotero-markdb-connect?style=for-the-badge&filter=*v0.1.1*)](https://github.com/daeh/zotero-markdb-connect/releases/tag/v0.1.1) [![GitHub all releases](https://img.shields.io/github/downloads/daeh/zotero-markdb-connect/total?style=for-the-badge&color=forestgreen)](https://github.com/daeh/zotero-markdb-connect/releases/tag/v0.1.1) -->
5+
<!-- [![GitHub release (with filter)](https://img.shields.io/github/v/release/daeh/zotero-markdb-connect?style=for-the-badge&filter=*v0.1.2*)](https://github.com/daeh/zotero-markdb-connect/releases/tag/v0.1.2) [![GitHub all releases](https://img.shields.io/github/downloads/daeh/zotero-markdb-connect/total?style=for-the-badge&color=forestgreen)](https://github.com/daeh/zotero-markdb-connect/releases/tag/v0.1.2) -->
66

7-
<!-- [![GitHub release (latest by SemVer including pre-releases)](https://img.shields.io/github/downloads-pre/daeh/zotero-markdb-connect/latest/total?style=for-the-badge&label=downloads@prerelease)](https://github.com/daeh/zotero-markdb-connect/releases/tag/v0.1.1) [![GitHub release (by tag)](https://img.shields.io/github/downloads/daeh/zotero-markdb-connect/v0.0.25/total?style=for-the-badge)](https://github.com/daeh/zotero-markdb-connect/releases/tag/v0.0.27) -->
7+
<!-- [![GitHub release (latest by SemVer including pre-releases)](https://img.shields.io/github/downloads-pre/daeh/zotero-markdb-connect/latest/total?style=for-the-badge&label=downloads@prerelease)](https://github.com/daeh/zotero-markdb-connect/releases/tag/v0.1.2) [![GitHub release (by tag)](https://img.shields.io/github/downloads/daeh/zotero-markdb-connect/v0.0.25/total?style=for-the-badge)](https://github.com/daeh/zotero-markdb-connect/releases/tag/v0.0.27) -->
88

99
<!-- [![GitHub release (latest by date)](https://img.shields.io/github/v/release/daeh/zotero-markdb-connect?style=for-the-badge)](https://github.com/daeh/zotero-markdb-connect/releases/latest) [![GitHub all releases](https://img.shields.io/github/downloads/daeh/zotero-markdb-connect/total?style=for-the-badge&color=forestgreen)](https://github.com/daeh/zotero-markdb-connect/releases/latest) -->
1010

@@ -39,7 +39,7 @@ Opens an existing markdown note in [Obsidian](https://obsidian.md), [logseq](htt
3939
- Open Zotero (version 7.x)
4040
- From `Tools -> Plugins`
4141
- Select `Install Add-on From File...` from the gear icon ⛭
42-
- Choose the `.xpi` file you downloaded (e.g. `mark-db-connect.xpi`)
42+
- Choose the `.xpi` file you downloaded (e.g. `markdb-connect.xpi`)
4343
- Restart Zotero
4444

4545
> [!NOTE]

addon/chrome/content/preferences.xhtml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,13 @@
104104
><html:code>/i</html:code></html:span
105105
>
106106
</hbox>
107-
<description class="mdbc-pref-explication-minor">The default file filter looks for Markdown files beginning with '<html:code>@</html:code>' : <html:code>/^@.+\.md$/i</html:code> </description>
108-
<description class="mdbc-pref-description-indent">N.B. If the BBT citekey is present in the filename pattern, you can include one capturing group to match it.</description>
107+
<!--<description class="mdbc-pref-explication-minor">The default file filter looks for Markdown files beginning with '<html:code>@</html:code>' : <html:code>/^@.+\.md$/i</html:code> </description>-->
108+
<description class="mdbc-pref-description-indent">If the BBT citekey is present in the filename pattern, you can include one capturing group to match it.</description>
109109
<description class="mdbc-pref-description-indent"
110-
>E.g. the default citekey-capturing RegExp uses the non-whitespace characters after the leading '<html:code>@</html:code>' as the BBT citekey:</description
110+
>E.g. the default RegExp filters for MarkDown files that begin with <html:code>@</html:code> and attempts to use the subsequent non-whitespace characters as the BBT citekey:</description
111111
>
112-
<description class="mdbc-pref-description-indent"><html:code class="mdbc-pref-code-indent">^@(\S+).*\.md$</html:code></description>
112+
<description class="mdbc-pref-description-indent"><html:code class="mdbc-pref-code-indent">/^@(\S+).*\.md$/i</html:code></description>
113+
<!--<description class="mdbc-pref-description-indent">E.g. to simply filter for MarkDown files beginning with <html:code>@</html:code>: <html:code>/^@.+\.md$/i</html:code></description>-->
113114
</html:div>
114115
</radiogroup>
115116
</groupbox>
@@ -139,7 +140,8 @@
139140

140141
<!--<separator />-->
141142

142-
<description>Markdown YAML Metadata Keyword (optional if BBT citkey is in title, required otherwise)</description>
143+
<!-- WIP TEMP DEBUG TODO not finished editing pref instructions -->
144+
<description>Specify the markdown YAML metadata keyword (optional if BBT citkey is in title, required otherwise).</description>
143145
<hbox class="mdbc-pref-hbox-indent">
144146
<html:span class="mdbc-pref-options-span-first">YAML keyword: </html:span
145147
><html:input
@@ -209,12 +211,11 @@
209211
<html:div
210212
class="mdbc-pref-options-div"
211213
id="zotero-prefpane-__addonRef__-matchstrategy-zotid-options">
212-
<label>__addonName__ will search for a Zotero-Item-Key in the file's contents. </label>
214+
<label>__addonName__ will search for a Zotero-Item-Key in the note's contents.</label>
213215

214216
<!--<separator />-->
215217

216-
<label>Required: Specify a RegExp to match the Zotero-Item-Key from the markdown contents</label>
217-
<label>(e.g. match '<html:code>ABCD1234</html:code>' in <html:code>zotero://select/library/items/ABCD1234</html:code>)</label>
218+
<description>Required: Specify a RegExp to match the Zotero-Item-Key from the markdown contents.</description>
218219
<hbox class="mdbc-pref-hbox-indent">
219220
<html:span class="mdbc-pref-options-span-first">RegExp:</html:span><html:span class="mdbc-pref-options-span-left mdbc-pref-options-code-span"><html:code>/</html:code></html:span
220221
><html:input
@@ -226,6 +227,10 @@
226227
><html:code>/m</html:code></html:span
227228
>
228229
</hbox>
230+
<description class="mdbc-pref-description-indent"
231+
>E.g. for a Zotero item that can be opened with this URI <html:code>zotero://select/library/items/ABCD1234</html:code> the RegExp should return a single match:
232+
'<html:code>ABCD1234</html:code>'.</description
233+
>
229234
<description class="mdbc-pref-description-indent">N.B. The Zotero-Item-Key is assigned automatically by Zotero. It is not the same as the BetterBibTeX citekey.</description>
230235
</html:div>
231236
</groupbox>

src/hooks.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ async function onStartup() {
2929

3030
// registerPreferenceStyleSheet()
3131

32-
await onMainWindowLoad(window)
32+
// await onMainWindowLoad(window)
33+
34+
await Promise.all(Zotero.getMainWindows().map((win) => onMainWindowLoad(win)))
3335
}
3436

3537
async function onMainWindowLoad(win: Window): Promise<void> {

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BasicTool } from 'zotero-plugin-toolkit/dist/basic'
1+
import { BasicTool } from 'zotero-plugin-toolkit'
22

33
import { config } from '../package.json'
44

src/modules/mdbcScan.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2408,8 +2408,8 @@ export class BasicExampleFactory {
24082408
src: rootURI + 'chrome/content/preferences.xhtml',
24092409
label: getString('prefs-title'),
24102410
image: favIcon,
2411-
defaultXUL: true,
2411+
// defaultXUL: true,
24122412
}
2413-
ztoolkit.PreferencePane.register(prefOptions)
2413+
Zotero.PreferencePanes.register(prefOptions)
24142414
}
24152415
}

src/modules/mdbcStartupHelpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export class wrappers {
5959
release: '',
6060
str: version,
6161
}
62-
const versionThis_rematch = version.match(version_re)
62+
const versionThis_rematch = version_re.exec(version)
6363
if (versionThis_rematch?.groups) {
6464
configurationVersionThis.major = parseInt(versionThis_rematch.groups.major)
6565
configurationVersionThis.minor = parseInt(versionThis_rematch.groups.minor)
@@ -81,7 +81,7 @@ export class wrappers {
8181
configurationVersionPrevious.str = configurationVersionPreviousStr
8282
}
8383
if (typeof configurationVersionPreviousStr === 'string' && version_re.test(configurationVersionPreviousStr)) {
84-
const version_rematch = configurationVersionPreviousStr.match(version_re)
84+
const version_rematch = version_re.exec(configurationVersionPreviousStr)
8585
if (version_rematch?.groups) {
8686
configurationVersionPrevious.major = parseInt(version_rematch.groups.major)
8787
configurationVersionPrevious.minor = parseInt(version_rematch.groups.minor)

src/modules/monkey-patch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* eslint-disable @typescript-eslint/ban-types, prefer-rest-params, @typescript-eslint/explicit-module-boundary-types, @typescript-eslint/no-unsafe-return */
1+
/* eslint-disable @typescript-eslint/no-unsafe-function-type */
22

33
export type Trampoline = Function & { disabled?: boolean }
44
const trampolines: Trampoline[] = []

src/modules/preferenceScript.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ async function updatePrefsUI() {
9191
// Returning false to prevent default event.
9292
.setProp('onKeyDown', (event: KeyboardEvent) => {
9393
if (event.key == 'Delete' || (Zotero.isMac && event.key == 'Backspace')) {
94-
addon.data.prefs.rows =
94+
addon.data.prefs!.rows =
9595
addon.data.prefs?.rows.filter((v, i) => !tableHelper.treeInstance.selection.isSelected(i)) || []
9696
tableHelper.render()
9797
return false
@@ -109,18 +109,18 @@ async function updatePrefsUI() {
109109
}
110110
111111
function bindPrefEvents() {
112-
addon.data.prefs.window.document
112+
addon.data.prefs!.window.document
113113
.querySelector(`#zotero-prefpane-${config.addonRef}-enable`)
114114
?.addEventListener('command', (e) => {
115115
ztoolkit.log(e)
116116
addon.data.prefs.window.alert(`Successfully changed to ${(e.target as XUL.Checkbox).checked}!`)
117117
})
118118
119-
addon.data.prefs.window.document
119+
addon.data.prefs!.window.document
120120
.querySelector(`#zotero-prefpane-${config.addonRef}-input`)
121121
?.addEventListener('change', (e) => {
122122
ztoolkit.log(e)
123-
addon.data.prefs.window.alert(`Successfully changed to ${(e.target as HTMLInputElement).value}!`)
123+
addon.data.prefs!.window.alert(`Successfully changed to ${(e.target as HTMLInputElement).value}!`)
124124
})
125125
}
126126
*/

src/utils/locale.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { config } from '../../package.json'
22

3-
export { initLocale, getString }
3+
export { initLocale, getString, getLocaleID }
44

55
/**
66
* Initialize locale data
@@ -69,8 +69,17 @@ function _getString(
6969
return localStringWithPrefix
7070
}
7171
if (branch && pattern.attributes) {
72+
for (const attr of pattern.attributes) {
73+
if (attr.name === branch) {
74+
return attr.value
75+
}
76+
}
7277
return pattern.attributes[branch] || localStringWithPrefix
7378
} else {
7479
return pattern.value || localStringWithPrefix
7580
}
7681
}
82+
83+
function getLocaleID(id: string) {
84+
return `${config.addonRef}-${id}`
85+
}

src/utils/wait.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export function waitUtilAsync(condition: () => boolean, interval = 100, timeout
3333
resolve()
3434
} else if (Date.now() - start > timeout) {
3535
ztoolkit.getGlobal('clearInterval')(intervalId)
36-
reject()
36+
reject(new Error('waitUtilAsync: something bad happened'))
3737
}
3838
}, interval)
3939
})

src/utils/ztoolkit.ts

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
import ZoteroToolkit from 'zotero-plugin-toolkit'
1+
// @ts-ignore
2+
import { BasicTool, UITool, unregister, ZoteroToolkit } from 'zotero-plugin-toolkit'
23

34
import { config } from '../../package.json'
45

@@ -25,23 +26,3 @@ function initZToolkit(_ztoolkit: ReturnType<typeof createZToolkit>) {
2526
_ztoolkit.basicOptions.api.pluginID = config.addonID
2627
_ztoolkit.ProgressWindow.setIconURI('default', `chrome://${config.addonRef}/content/icons/favicon.png`)
2728
}
28-
29-
import { BasicTool, unregister } from 'zotero-plugin-toolkit/dist/basic'
30-
import { PreferencePaneManager } from 'zotero-plugin-toolkit/dist/managers/preferencePane'
31-
import { UITool } from 'zotero-plugin-toolkit/dist/tools/ui'
32-
33-
// @ts-ignore
34-
class MyToolkit extends BasicTool {
35-
UI: UITool
36-
PreferencePane: PreferencePaneManager
37-
38-
constructor() {
39-
super()
40-
this.UI = new UITool(this)
41-
this.PreferencePane = new PreferencePaneManager(this)
42-
}
43-
44-
unregisterAll() {
45-
unregister(this)
46-
}
47-
}

update-beta.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"daeda@mit.edu": {
44
"updates": [
55
{
6-
"version": "0.1.1",
7-
"update_link": "https://github.com/daeh/zotero-markdb-connect/releases/download/v0.1.1/mark-db-connect.xpi",
6+
"version": "0.1.2",
7+
"update_link": "https://github.com/daeh/zotero-markdb-connect/releases/download/v0.1.2/markdb-connect.xpi",
88
"applications": {
99
"zotero": {
1010
"strict_min_version": "6.999",

update.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"daeda@mit.edu": {
44
"updates": [
55
{
6-
"version": "0.1.1",
7-
"update_link": "https://github.com/daeh/zotero-markdb-connect/releases/latest/download/mark-db-connect.xpi",
6+
"version": "0.1.2",
7+
"update_link": "https://github.com/daeh/zotero-markdb-connect/releases/latest/download/markdb-connect.xpi",
88
"applications": {
99
"zotero": {
1010
"strict_min_version": "6.999"

0 commit comments

Comments
 (0)