Skip to content

Commit

Permalink
Fixes for ztoolkit upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
daeh committed Oct 9, 2024
1 parent 53e71d1 commit e399db9
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 49 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

<!-- [![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) -->

<!-- [![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) -->
<!-- [![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) -->

<!-- [![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) -->
<!-- [![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) -->

<!-- [![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) -->

Expand Down Expand Up @@ -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]
Expand Down
21 changes: 13 additions & 8 deletions addon/chrome/content/preferences.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,13 @@
><html:code>/i</html:code></html:span
>
</hbox>
<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>
<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>
<!--<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>-->
<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>
<description class="mdbc-pref-description-indent"
>E.g. the default citekey-capturing RegExp uses the non-whitespace characters after the leading '<html:code>@</html:code>' as the BBT citekey:</description
>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
>
<description class="mdbc-pref-description-indent"><html:code class="mdbc-pref-code-indent">^@(\S+).*\.md$</html:code></description>
<description class="mdbc-pref-description-indent"><html:code class="mdbc-pref-code-indent">/^@(\S+).*\.md$/i</html:code></description>
<!--<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>-->
</html:div>
</radiogroup>
</groupbox>
Expand Down Expand Up @@ -139,7 +140,8 @@

<!--<separator />-->

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

<!--<separator />-->

<label>Required: Specify a RegExp to match the Zotero-Item-Key from the markdown contents</label>
<label>(e.g. match '<html:code>ABCD1234</html:code>' in <html:code>zotero://select/library/items/ABCD1234</html:code>)</label>
<description>Required: Specify a RegExp to match the Zotero-Item-Key from the markdown contents.</description>
<hbox class="mdbc-pref-hbox-indent">
<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
><html:input
Expand All @@ -226,6 +227,10 @@
><html:code>/m</html:code></html:span
>
</hbox>
<description class="mdbc-pref-description-indent"
>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:
'<html:code>ABCD1234</html:code>'.</description
>
<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>
</html:div>
</groupbox>
Expand Down
4 changes: 3 additions & 1 deletion src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BasicTool } from 'zotero-plugin-toolkit/dist/basic'
import { BasicTool } from 'zotero-plugin-toolkit'

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

Expand Down
4 changes: 2 additions & 2 deletions src/modules/mdbcScan.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
4 changes: 2 additions & 2 deletions src/modules/mdbcStartupHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/modules/monkey-patch.ts
Original file line number Diff line number Diff line change
@@ -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[] = []
Expand Down
8 changes: 4 additions & 4 deletions src/modules/preferenceScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}!`)
})
}
*/
11 changes: 10 additions & 1 deletion src/utils/locale.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { config } from '../../package.json'

export { initLocale, getString }
export { initLocale, getString, getLocaleID }

/**
* Initialize locale data
Expand Down Expand Up @@ -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}`
}
2 changes: 1 addition & 1 deletion src/utils/wait.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down
23 changes: 2 additions & 21 deletions src/utils/ztoolkit.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -25,23 +26,3 @@ function initZToolkit(_ztoolkit: ReturnType<typeof createZToolkit>) {
_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)
}
}
4 changes: 2 additions & 2 deletions update-beta.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"[email protected]": {
"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",
Expand Down
4 changes: 2 additions & 2 deletions update.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"[email protected]": {
"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"
Expand Down

0 comments on commit e399db9

Please sign in to comment.