Skip to content

Commit

Permalink
Merge branch 'master' into gh-2898
Browse files Browse the repository at this point in the history
  • Loading branch information
retorquere committed Aug 28, 2024
2 parents fcac20f + 8858fc6 commit ad991da
Show file tree
Hide file tree
Showing 76 changed files with 1,508 additions and 2,104 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ Object.assign(config.rules, {
'no-magic-numbers': 'off',
'max-len': [ 'warn', { code: 320 } ],
'prefer-arrow/prefer-arrow-functions': 'off',
'@stylistic/template-curly-spacing': 'off',
})

const shell = require('shelljs')
Expand Down
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock.json -diff
3 changes: 2 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ jobs:
--minutes 10 ${{ env.slow }} ${{ env.beta }} ${{ env.legacy }}

- name: build ${{ env.beta }} ${{ env.legacy }}
#run: npm run build ${{ env.beta }} ${{ env.legacy }}
run: npm run build
env:
VERSION_WITH_ISSUE: false

- name: publish debug bridge
run: ./util/publish-debug-bridge.py
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/src/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ jobs:
run: ./util/balance.py --durations test/balance/durations.json --bins test/balance/bins.json --minutes 10 ${{ env.slow }} ${{ env.beta }} ${{ env.legacy }}

- name: build ${{ env.beta }} ${{ env.legacy }}
#run: npm run build ${{ env.beta }} ${{ env.legacy }}
run: npm run build
env:
VERSION_WITH_ISSUE: false

- name: publish debug bridge
run: ./util/publish-debug-bridge.py
Expand Down
3 changes: 3 additions & 0 deletions .hgignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
submodules
node_modules
build
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

Better BibTeX (BBT) is an extension for [Zotero](https://www.zotero.org) and [Juris-M](https://juris-m.github.io) that makes it easier to manage bibliographic data, especially for people authoring documents using text-based toolchains (e.g. based on [LaTeX](https://www.latex-project.org) / [Markdown](https://www.markdownguide.org)).

## Zotero 7 beta support: Zotero beta 70+ currently not supported, a fix is underway

[#2829](https://github.com/retorquere/zotero-better-bibtex/issues/2829)
## Zotero 7 support

Better BibTeX is mostly compatible with the Zotero 7 beta; I am awaiting a change by the Zotero team to get to complete support. You can find the status of Zotero 7 support in the first post of [#2522](https://github.com/retorquere/zotero-better-bibtex/issues/2522); if you find new problems (which are not still marked as unresolved in that top post), please report them as *new* issues, not by commenting on #2522.

Expand Down
10 changes: 5 additions & 5 deletions content/ExportOptions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { patch as $patch$, unpatch as $unpatch$, Trampoline } from './monkey-patch'
import { Patcher } from './monkey-patch'
import * as l10n from './l10n'
import { Elements } from './create-element'
import { Events } from './events'
Expand All @@ -23,7 +23,7 @@ Events.on('window-loaded', ({ win, href }: { win: Window; href: string }) => {
})

export class ExportOptions {
private patched: Trampoline[] = []
private $patcher$: Patcher = new Patcher
private elements: Elements

public load(): void {
Expand All @@ -36,11 +36,11 @@ export class ExportOptions {
this.show()

const self = this // eslint-disable-line @typescript-eslint/no-this-alias
$patch$(Zotero_File_Interface_Export, 'updateOptions', original => function(_options) {
this.$patcher$.patch(Zotero_File_Interface_Export, 'updateOptions', original => function(_options) {
// eslint-disable-next-line prefer-rest-params
original.apply(this, arguments)
self.show()
}, this.patched)
})
}

private selected(): any {
Expand Down Expand Up @@ -110,7 +110,7 @@ export class ExportOptions {

public unload(): void {
this.elements.remove()
$unpatch$(this.patched)
this.$patcher$.unpatch()
}

mutex(e?: Event): void {
Expand Down
2 changes: 1 addition & 1 deletion content/Preferences.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ export class PrefPane {
}

public checkCitekeyFormat(): void {
if (!$window || Zotero.BetterBibTeX.ready.isPending()) return // itemTypes not available yet
if (!$window || Zotero.BetterBibTeX.starting) return // itemTypes not available yet

const error = Formatter.update([ Preference.citekeyFormatEditing, Preference.citekeyFormat ])

Expand Down
50 changes: 26 additions & 24 deletions content/Preferences/export/fields.pug
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
html:div
label(bbt:preference="extensions.zotero.translators.better-bibtex.language") &better-bibtex_preferences_export_fields_language;
menulist(preference="extensions.zotero.translators.better-bibtex.language" preference-editable="true")
menupopup
menuitem(value='langid' label='langid')
menuitem(value='language' label='language')
menuitem(value='both' label='&better-bibtex_preferences_export_fields_language_both.label;')
html:div
label(bbt:preference="extensions.zotero.translators.better-bibtex.DOIandURL") &better-bibtex_preferences_export_fields_doi-and-url;
menulist(preference="extensions.zotero.translators.better-bibtex.DOIandURL" preference-editable="true")
menupopup
menuitem(value='both' label='&better-bibtex_preferences_export_fields_doi-and-url_both.label;')
menuitem(value='doi' label='&better-bibtex_preferences_export_fields_doi-and-url_doi.label;')
menuitem(value='url' label='&better-bibtex_preferences_export_fields_doi-and-url_url.label;')
image(tooltip="bbt-tooltip-DOIandURL" src="chrome://zotero-better-bibtex/content/skin/attention.svg" width='16px' height='16px')
html:div
label(bbt:preference="extensions.zotero.translators.better-bibtex.skipFields") &better-bibtex_preferences_export_fields_skip;
textbox(size='30' preference='extensions.zotero.translators.better-bibtex.skipFields')
html:div
label(bbt:preference="extensions.zotero.translators.better-bibtex.jabrefFormat") &better-bibtex_preferences_export_jabref-format;
menulist(preference="extensions.zotero.translators.better-bibtex.jabrefFormat" preference-editable="true")
menupopup
menuitem(value='0' label='&better-bibtex_preferences_export_jabref-format_0.label;')
menuitem(value='3' label='&better-bibtex_preferences_export_jabref-format_3.label;')
menuitem(value='4' label='&better-bibtex_preferences_export_jabref-format_4.label;')
menuitem(value='5' label='&better-bibtex_preferences_export_jabref-format_5.label;')
image(tooltip="bbt-tooltip-jabrefFormat" src="chrome://zotero-better-bibtex/content/skin/attention.svg" width='16px' height='16px')
groupbox
caption BibTeX/BibLaTeX
html:div
label(bbt:preference="extensions.zotero.translators.better-bibtex.language") &better-bibtex_preferences_export_fields_language;
menulist(preference="extensions.zotero.translators.better-bibtex.language" preference-editable="true")
menupopup
menuitem(value='langid' label='langid')
menuitem(value='language' label='language')
menuitem(value='both' label='&better-bibtex_preferences_export_fields_language_both.label;')
html:div
label(bbt:preference="extensions.zotero.translators.better-bibtex.DOIandURL") &better-bibtex_preferences_export_fields_doi-and-url;
menulist(preference="extensions.zotero.translators.better-bibtex.DOIandURL" preference-editable="true")
menupopup
menuitem(value='both' label='&better-bibtex_preferences_export_fields_doi-and-url_both.label;')
menuitem(value='doi' label='&better-bibtex_preferences_export_fields_doi-and-url_doi.label;')
menuitem(value='url' label='&better-bibtex_preferences_export_fields_doi-and-url_url.label;')
image(tooltip="bbt-tooltip-DOIandURL" src="chrome://zotero-better-bibtex/content/skin/attention.svg" width='16px' height='16px')
html:div
label(bbt:preference="extensions.zotero.translators.better-bibtex.jabrefFormat") &better-bibtex_preferences_export_jabref-format;
menulist(preference="extensions.zotero.translators.better-bibtex.jabrefFormat" preference-editable="true")
menupopup
menuitem(value='0' label='&better-bibtex_preferences_export_jabref-format_0.label;')
menuitem(value='3' label='&better-bibtex_preferences_export_jabref-format_3.label;')
menuitem(value='4' label='&better-bibtex_preferences_export_jabref-format_4.label;')
menuitem(value='5' label='&better-bibtex_preferences_export_jabref-format_5.label;')
image(tooltip="bbt-tooltip-jabrefFormat" src="chrome://zotero-better-bibtex/content/skin/attention.svg" width='16px' height='16px')
6 changes: 4 additions & 2 deletions content/ZoteroItemPane.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { patch as $patch$ } from './monkey-patch'
import { Patcher } from './monkey-patch'
import { sentenceCase } from './text'
import * as l10n from './l10n'
import { Elements } from './create-element'
Expand Down Expand Up @@ -30,6 +30,7 @@ export async function newZoteroItemPane(win: Window): Promise<void> {
}

export class ZoteroItemPane {
private $patcher$ = new Patcher
document: Document
elements: Elements
displayed: number
Expand Down Expand Up @@ -70,7 +71,7 @@ export class ZoteroItemPane {
})

const self = this // eslint-disable-line @typescript-eslint/no-this-alias
$patch$(itemBox.__proto__, 'refresh', original => function() {
this.$patcher$.patch(itemBox.__proto__, 'refresh', original => function() {
// eslint-disable-next-line prefer-rest-params
original.apply(this, arguments)

Expand Down Expand Up @@ -114,5 +115,6 @@ export class ZoteroItemPane {
this.elements.remove()
this.done?.()
this.document = undefined
this.$patcher$.unpatch()
}
}
2 changes: 1 addition & 1 deletion content/ZoteroPane.pug
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ overlay#zotero-better-bibtex-zoteroPane-overlay(xmlns="http://www.mozilla.org/ke
script.
(function() {
try {
const startup = Zotero.BetterBibTeX.ready.isPending()
const startup = Zotero.BetterBibTeX.starting
Zotero.debug(`{better-bibtex-startup} script load, ${startup ? 'startup' : 'window-reload'}`)
if (startup) {
window.addEventListener('load', async function() {
Expand Down
16 changes: 8 additions & 8 deletions content/ZoteroPane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { XUL } from '../typings/xul'
import { log } from './logger'
import { TeXstudio } from './tex-studio'
import { Translators } from './translators'
import { patch as $patch$, unpatch as $unpatch$, Trampoline } from './monkey-patch'
import { Patcher } from './monkey-patch'
import { clean_pane_persist } from './clean_pane_persist'
import { Preference } from './prefs'
import { AutoExport } from './auto-export'
Expand All @@ -30,13 +30,13 @@ export async function newZoteroPane(win: XULWindow): Promise<void> {
}

class ZoteroPane {
private patched: Trampoline[] = []
private $patcher$: Patcher = new Patcher
private elements: Elements
private ZoteroPane: any
private window: XULWindow

public unload(): void {
$unpatch$(this.patched)
this.$patcher$.unpatch()
this.elements.remove()
}

Expand Down Expand Up @@ -83,7 +83,7 @@ class ZoteroPane {

const bbt_zotero_pane_helper = this // eslint-disable-line @typescript-eslint/no-this-alias

$patch$(this.ZoteroPane, 'buildItemContextMenu', original => async function ZoteroPane_buildItemContextMenu() {
this.$patcher$.patch(this.ZoteroPane, 'buildItemContextMenu', original => async function ZoteroPane_buildItemContextMenu() {
await original.apply(this, arguments) // eslint-disable-line prefer-rest-params

const id = 'better-bibtex-item-menu'
Expand Down Expand Up @@ -155,7 +155,7 @@ class ZoteroPane {
}))
})

$patch$(this.ZoteroPane, 'buildCollectionContextMenu', original => async function() {
this.$patcher$.patch(this.ZoteroPane, 'buildCollectionContextMenu', original => async function() {
// eslint-disable-next-line prefer-rest-params
await original.apply(this, arguments)

Expand Down Expand Up @@ -248,14 +248,14 @@ class ZoteroPane {
catch (err) {
log.error('ZoteroPane.buildCollectionContextMenu:', err)
}
}, this.patched)
})

// Monkey patch because of https://groups.google.com/forum/#!topic/zotero-dev/zy2fSO1b0aQ
$patch$(this.ZoteroPane, 'serializePersist', original => function() {
this.$patcher$.patch(this.ZoteroPane, 'serializePersist', original => function() {
// eslint-disable-next-line prefer-rest-params
original.apply(this, arguments)
if (Zotero.BetterBibTeX.uninstalled) clean_pane_persist()
}, this.patched)
})

if (!is7) {
if (this.ZoteroPane.itemsView.collectionTreeRow) await this.ZoteroPane.itemsView.refreshAndMaintainSelection()
Expand Down
2 changes: 1 addition & 1 deletion content/ajv.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// 2020 for prefixItems
import AJV from 'ajv/dist/2020'
import { discard, simple as log } from './logger'
import { discard, log } from './logger/simple'

const options = {
strict: false,
Expand Down
35 changes: 33 additions & 2 deletions content/auto-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,11 @@ if (Preference.autoExportDelay < 1) Preference.autoExportDelay = 1
if (Preference.autoExportIdleWait < 1) Preference.autoExportIdleWait = 1
const queue = new class TaskQueue {
private scheduler = new Scheduler<string>('autoExportDelay', 1000)
private held: Set<string>

constructor() {
this.pause('startup')
this.holdDuringSync()
}

public pause(_reason: 'startup' | 'end-of-idle' | 'preference-change') {
Expand All @@ -334,7 +336,27 @@ const queue = new class TaskQueue {
}

public add(path: string) {
this.scheduler.schedule(path, this.run.bind(this, path))
this.cancel(path)
if (this.held) {
this.held.add(path)
}
else {
this.scheduler.schedule(path, this.run.bind(this, path))
}
}

public holdDuringSync() {
if (Events.syncInProgress && !this.held) this.held = new Set
}

public releaseAfterSync() {
if (this.held) {
const held = this.held
this.held = null
for (const path of [...held]) {
this.add(path)
}
}
}

public cancel(path: string) {
Expand All @@ -345,7 +367,7 @@ const queue = new class TaskQueue {
this.runAsync(path).catch(err => log.error('autoexport failed:', { path }, err.message))
}

public async runAsync(path: string) {
private async runAsync(path: string) {
await Zotero.BetterBibTeX.ready

const ae = await AutoExport.get(path)
Expand Down Expand Up @@ -518,6 +540,15 @@ export const AutoExport = new class $AutoExport { // eslint-disable-line @typesc
break
}
})

Events.on('sync', running => {
if (running) {
queue.holdDuringSync()
}
else {
queue.releaseAfterSync()
}
})
},
})
}
Expand Down
Loading

0 comments on commit ad991da

Please sign in to comment.