From ea730e6947237bdb63d3af24a20a23558c93db5d Mon Sep 17 00:00:00 2001 From: windingwind <33902321+windingwind@users.noreply.github.com> Date: Mon, 6 May 2024 21:14:22 +0800 Subject: [PATCH] update: zotero-types 2.0.0 --- package.json | 2 +- scripts/build.mjs | 2 +- src/elements/base.ts | 4 +--- src/elements/linkCreator/notePicker.ts | 2 +- src/extras/customElements.ts | 4 ++-- src/extras/linkCreator.ts | 1 - src/extras/workspaceWindow.ts | 1 - src/modules/noteLink.ts | 1 + src/modules/sync/api.ts | 6 +++--- src/utils/window.ts | 4 ++-- 10 files changed, 12 insertions(+), 15 deletions(-) diff --git a/package.json b/package.json index 9346721..3466f44 100644 --- a/package.json +++ b/package.json @@ -90,7 +90,7 @@ "replace-in-file": "^7.0.2", "typescript": "^5.3.3", "xslt3": "^2.6.0", - "zotero-types": "^1.3.24" + "zotero-types": "^2.0.0" }, "eslintConfig": { "env": { diff --git a/scripts/build.mjs b/scripts/build.mjs index eaf5951..6141731 100644 --- a/scripts/build.mjs +++ b/scripts/build.mjs @@ -1,4 +1,4 @@ -import details from "../package.json" assert { type: "json" }; +import details from "../package.json" with { type: "json" }; import { Logger, clearFolder, diff --git a/src/elements/base.ts b/src/elements/base.ts index 881a510..e1a5852 100644 --- a/src/elements/base.ts +++ b/src/elements/base.ts @@ -13,7 +13,7 @@ export class PluginCEBase extends XULElementBase { } this.attachShadow({ mode: "open" }); // Following the connectedCallback from XULElementBase - let content = this.content; + let content: Node = this.content; if (content) { content = document.importNode(content, true); this.shadowRoot?.append(content); @@ -21,9 +21,7 @@ export class PluginCEBase extends XULElementBase { MozXULElement.insertFTLIfNeeded("branding/brand.ftl"); MozXULElement.insertFTLIfNeeded("zotero.ftl"); - // @ts-ignore if (document.l10n && this.shadowRoot) { - // @ts-ignore document.l10n.connectRoot(this.shadowRoot); } diff --git a/src/elements/linkCreator/notePicker.ts b/src/elements/linkCreator/notePicker.ts index 3fcfe1e..d1a9fca 100644 --- a/src/elements/linkCreator/notePicker.ts +++ b/src/elements/linkCreator/notePicker.ts @@ -136,7 +136,6 @@ export class NotePicker extends PluginCEBase { } loadQuickSearch() { - // @ts-ignore const searchBox = document.createXULElement("quick-search-textbox"); searchBox.id = "zotero-tb-search"; searchBox.setAttribute("timeout", "250"); @@ -146,6 +145,7 @@ export class NotePicker extends PluginCEBase { searchBox, ); + // @ts-ignore searchBox.updateMode(); } diff --git a/src/extras/customElements.ts b/src/extras/customElements.ts index 4ee11ea..c363511 100644 --- a/src/extras/customElements.ts +++ b/src/extras/customElements.ts @@ -12,7 +12,7 @@ import { OutboundCreator } from "../elements/linkCreator/outboundCreator"; const elements = { "bn-context": ContextPane, "bn-outline": OutlinePane, - "bn-details": DetailsPane as unknown as CustomElementConstructor, + "bn-details": DetailsPane, "bn-workspace": Workspace, "bn-note-picker": NotePicker, "bn-note-outline": OutlinePicker, @@ -20,7 +20,7 @@ const elements = { "bn-inbound-creator": InboundCreator, "bn-outbound-creator": OutboundCreator, "bn-related-box": NoteRelatedBox, -}; +} as unknown as Record; for (const [key, constructor] of Object.entries(elements)) { if (!customElements.get(key)) { diff --git a/src/extras/linkCreator.ts b/src/extras/linkCreator.ts index 7767394..7c082fd 100644 --- a/src/extras/linkCreator.ts +++ b/src/extras/linkCreator.ts @@ -48,7 +48,6 @@ function init() { window.resizeTo(Number(size[0] || "800"), Number(size[1] || "600")); }, 0); - // @ts-ignore io = window.arguments[0]; tabbox = document.querySelector("#top-container")!; diff --git a/src/extras/workspaceWindow.ts b/src/extras/workspaceWindow.ts index 6fed4df..2a7aa4f 100644 --- a/src/extras/workspaceWindow.ts +++ b/src/extras/workspaceWindow.ts @@ -18,7 +18,6 @@ window.addEventListener("DOMContentLoaded", () => { { once: true }, ); - // @ts-ignore window.arguments[0]._initPromise.resolve(); }); diff --git a/src/modules/noteLink.ts b/src/modules/noteLink.ts index 368e724..db3b7f0 100644 --- a/src/modules/noteLink.ts +++ b/src/modules/noteLink.ts @@ -16,6 +16,7 @@ export function registerNoteLinkProxyHandler() { this.doAction(uri); }, }; + // @ts-ignore Services.io.getProtocolHandler("zotero").wrappedJSObject._extensions[ "zotero://note" ] = openNoteExtension; diff --git a/src/modules/sync/api.ts b/src/modules/sync/api.ts index 91f88d9..4a2d23d 100644 --- a/src/modules/sync/api.ts +++ b/src/modules/sync/api.ts @@ -158,7 +158,7 @@ async function getMDStatus( ret.filedir = formatPath(pathSplit.slice(0, -1).join("/")); ret.filename = pathSplit.pop() || ""; const stat = await IOUtils.stat(filepath); - ret.lastmodify = new Date(stat.lastModified); + ret.lastmodify = new Date(stat.lastModified || 0); } } catch (e) { ztoolkit.log(e); @@ -191,9 +191,9 @@ async function getMDFileName(noteId: number, searchDir?: string) { entry.name.split(".").shift()?.split("-").pop() === noteItem.key ) { const stat = await IOUtils.stat(entry.path); - if (stat.lastModified > matchedDate) { + if (stat.lastModified || 0 > matchedDate) { matchedFileName = entry.name; - matchedDate = stat.lastModified; + matchedDate = stat.lastModified || 0; } } } diff --git a/src/utils/window.ts b/src/utils/window.ts index 179d9ec..16b6c64 100644 --- a/src/utils/window.ts +++ b/src/utils/window.ts @@ -5,9 +5,9 @@ function isWindowAlive(win?: Window) { } function getFocusedWindow() { - const wins = Services.wm.getEnumerator(null) as Window[]; + const wins = Services.wm.getEnumerator("") as unknown as Window[]; for (const win of wins) { - if (win.document.hasFocus()) { + if (win.document?.hasFocus()) { return win; } }