update: deps

This commit is contained in:
windingwind 2024-10-23 20:29:15 +02:00
parent 6332ef73c1
commit 4dbb34819d
20 changed files with 108 additions and 99 deletions

44
package-lock.json generated
View File

@ -64,7 +64,7 @@
"typescript": "^5.3.3",
"xslt3": "^2.6.0",
"zotero-plugin-scaffold": "^0.1.6",
"zotero-types": "^2.0.1"
"zotero-types": "^3.0.0"
}
},
"node_modules/@aashutoshrathi/word-wrap": {
@ -3751,9 +3751,9 @@
}
},
"node_modules/core-js": {
"version": "3.37.0",
"resolved": "https://registry.npmjs.org/core-js/-/core-js-3.37.0.tgz",
"integrity": "sha512-fu5vHevQ8ZG4og+LXug8ulUtVxjOcEYvifJr7L5Bfq9GOztVqsKd9/59hUk2ZSbCrS3BqUr3EpaYGIYzq7g3Ug==",
"version": "3.38.1",
"resolved": "https://registry.npmjs.org/core-js/-/core-js-3.38.1.tgz",
"integrity": "sha512-OP35aUorbU3Zvlx7pjsFdu1rGNnD4pgw/CWoYzRY3t2EzoVT7shKHY1dlAy3f41cGIO7ZDPQimhGFTlEYkG/Hw==",
"hasInstallScript": true,
"funding": {
"type": "opencollective",
@ -9157,9 +9157,9 @@
}
},
"node_modules/nan": {
"version": "2.20.0",
"resolved": "https://registry.npmjs.org/nan/-/nan-2.20.0.tgz",
"integrity": "sha512-bk3gXBZDGILuuo/6sKtr0DQmSThYHLtNCdSdXk9YkxD/jK6X2vmCyyXBBxyqZ4XcnzTyYEAThfX3DCEnLf6igw==",
"version": "2.22.0",
"resolved": "https://registry.npmjs.org/nan/-/nan-2.22.0.tgz",
"integrity": "sha512-nbajikzWTMwsW+eSsNm3QwlOs7het9gGJU5dDZzRTQGk03vyBOauxgI4VakDzE0PtsGTmXPsXTbbjVhRwR5mpw==",
"optional": true
},
"node_modules/natural-compare": {
@ -9856,9 +9856,9 @@
"dev": true
},
"node_modules/pdfjs-dist": {
"version": "4.6.82",
"resolved": "https://registry.npmjs.org/pdfjs-dist/-/pdfjs-dist-4.6.82.tgz",
"integrity": "sha512-BUOryeRFwvbLe0lOU6NhkJNuVQUp06WxlJVVCsxdmJ4y5cU3O3s3/0DunVdK1PMm7v2MUw52qKYaidhDH1Z9+w==",
"version": "4.7.76",
"resolved": "https://registry.npmjs.org/pdfjs-dist/-/pdfjs-dist-4.7.76.tgz",
"integrity": "sha512-8y6wUgC/Em35IumlGjaJOCm3wV4aY/6sqnIT3fVW/67mXsOZ9HWBn8GDKmJUK0GSzpbmX3gQqwfoFayp78Mtqw==",
"engines": {
"node": ">=18"
},
@ -12215,9 +12215,9 @@
"integrity": "sha512-Xni35NKzjgMrwevysHTCArtLDpPvye8zV/0E4EyYn43P7/7qvQwPh9BGkHewbMulVntbigmcT7rdX3BNo9wRJg=="
},
"node_modules/type": {
"version": "2.7.2",
"resolved": "https://registry.npmjs.org/type/-/type-2.7.2.tgz",
"integrity": "sha512-dzlvlNlt6AXU7EBSfpAscydQ7gXB+pPGsPnfJnZpiNJBDj7IaJzQlBZYGdEi4R9HmPdBv2XmWJ6YUtoTa7lmCw=="
"version": "2.7.3",
"resolved": "https://registry.npmjs.org/type/-/type-2.7.3.tgz",
"integrity": "sha512-8j+1QmAbPvLZow5Qpi6NCaN8FB60p/6x8/vfNqOk/hC+HuvFZhL4+WfekuhQLiqFZXOgQdrs3B+XxEmCc6b3FQ=="
},
"node_modules/type-check": {
"version": "0.4.0",
@ -13598,10 +13598,22 @@
"node": ">=18"
}
},
"node_modules/zotero-plugin-toolkit/node_modules/zotero-types": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/zotero-types/-/zotero-types-2.2.1.tgz",
"integrity": "sha512-alsjWn7i3pJq7b9+2XT2WbxZtWk4WWH4EIUi6o+Xx7/uz8TQDA0PFY2mS91gL8VXWKXMrSBJKYEbkvMMR6KuKA==",
"dependencies": {
"@types/bluebird": "^3.5.42",
"@types/react": "18.3.1",
"epubjs": "^0.3.93",
"pdfjs-dist": "^4.4.0"
}
},
"node_modules/zotero-types": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/zotero-types/-/zotero-types-2.2.0.tgz",
"integrity": "sha512-Th63hgO+OhWgCy3rSQOSTnEIuhK5gPUsG/No8jqxSGKKksd7b6DQ/V7glmdXieoZEJpzoV0bWyZEQflWU5obHQ==",
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/zotero-types/-/zotero-types-3.0.0.tgz",
"integrity": "sha512-1v8O4FKJhjrGTdwc4EmHMvpDClHO5Au4b62EuiZtcoJSjEJDUdbI3Dy2CQLXlaDWuTE6MeBY+lB77C3z48aaSg==",
"dev": true,
"dependencies": {
"@types/bluebird": "^3.5.42",
"@types/react": "18.3.1",

View File

@ -85,7 +85,7 @@
"typescript": "^5.3.3",
"xslt3": "^2.6.0",
"zotero-plugin-scaffold": "^0.1.6",
"zotero-types": "^2.0.1"
"zotero-types": "^3.0.0"
},
"eslintConfig": {
"env": {

View File

@ -51,7 +51,7 @@ export class PluginCEBase extends XULElementBase {
const selector = `#${this._wrapID(key)}`;
return (this.querySelector(selector) ||
this.shadowRoot?.querySelector(selector)) as
| XUL.Element
| XULElement
| HTMLElement
| null;
}

View File

@ -22,7 +22,7 @@ export class NotePicker extends PluginCEBase {
openedNotesView!: VirtualizedTableHelper;
recentNotesView!: VirtualizedTableHelper;
_collectionsList!: XUL.Box;
_collectionsList!: XULBoxElement;
openedNotes: Zotero.Item[] = [];
@ -101,7 +101,7 @@ export class NotePicker extends PluginCEBase {
this._collectionsList = this.querySelector(
"#zotero-collections-tree-container",
) as XUL.Box;
) as XULBoxElement;
this._restoreState();
@ -459,7 +459,7 @@ export class NotePicker extends PluginCEBase {
_persistState() {
let state = getPrefJSON(persistKey);
const collectionsListWidth = getComputedStyle(this._collectionsList).width;
const collectionsListWidth = getComputedStyle(this._collectionsList)?.width;
if (state?.collectionsListWidth === collectionsListWidth) {
return;
}
@ -477,7 +477,7 @@ export class NotePicker extends PluginCEBase {
if (
typeof state.collectionsListWidth === "string" &&
state.collectionsListWidth !==
Number(getComputedStyle(this._collectionsList).width)
Number(getComputedStyle(this._collectionsList)?.width)
) {
this._collectionsList.style.width = state.collectionsListWidth;
}

View File

@ -236,7 +236,7 @@ export class OutlinePane extends PluginCEBase {
// Update set outline menu
this._queryID("setOutlinePopup")?.childNodes.forEach((elem) =>
(elem as XUL.MenuItem).removeAttribute("checked"),
(elem as XULMenuItemElement).removeAttribute("checked"),
);
this._queryID(
Object.keys(OutlinePane.outlineMenuIDs)[this.outlineType],
@ -268,7 +268,7 @@ export class OutlinePane extends PluginCEBase {
toolbarButtonCommandHandler = async (ev: Event) => {
if (!this.item) return;
const type = this._unwrapID((ev.target as XUL.ToolBarButton).id);
const type = this._unwrapID((ev.target as XULToolBarButtonElement).id);
switch (type) {
case "useTreeView":
case "useMindMap":

View File

@ -21,11 +21,11 @@ export class Workspace extends PluginCEBase {
_editorElement!: EditorElement;
_outline!: OutlinePane;
_editorContainer!: XUL.Box;
_editorContainer!: XULBoxElement;
_context!: ContextPane;
_leftSplitter!: XUL.Splitter;
_rightSplitter!: XUL.Splitter;
_leftSplitter!: XULSplitterElement;
_rightSplitter!: XULSplitterElement;
resizeOb!: ResizeObserver;
@ -93,14 +93,14 @@ export class Workspace extends PluginCEBase {
this._outline = this._queryID("left-container") as unknown as OutlinePane;
this._editorContainer = this._queryID("center-container") as XUL.Box;
this._editorContainer = this._queryID("center-container") as XULBoxElement;
this._editorElement = this._queryID("editor-main") as EditorElement;
this._outline._editorElement = this._editorElement;
this._context = this._queryID("right-container") as unknown as ContextPane;
this._leftSplitter = this._queryID("left-splitter") as XUL.Splitter;
this._rightSplitter = this._queryID("right-splitter") as XUL.Splitter;
this._leftSplitter = this._queryID("left-splitter") as XULSplitterElement;
this._rightSplitter = this._queryID("right-splitter") as XULSplitterElement;
this._leftSplitter.addEventListener("mouseup", () => {
this._persistState();

View File

@ -2,7 +2,7 @@ import { getPref, setPref } from "../utils/prefs";
import { InboundCreator } from "../elements/linkCreator/inboundCreator";
import { OutboundCreator } from "../elements/linkCreator/outboundCreator";
let tabbox: XUL.TabBox;
let tabbox: XULTabBoxElement;
let inboundCreator: InboundCreator;
let outboundCreator: OutboundCreator;

View File

@ -5,12 +5,12 @@ export function initEditorImagePreviewer(editor: Zotero.EditorInstance) {
const imgs = editor._iframeWindow.document
.querySelector(".primary-editor")
?.querySelectorAll("img");
if (!imgs) {
if (!imgs?.length) {
return;
}
const imageList = Array.from(imgs);
addon.hooks.onShowImageViewer(
imageList.map((elem) => elem.src),
imageList.map((elem) => (elem as HTMLImageElement)?.src),
imageList.indexOf(e.target as HTMLImageElement),
editor._item.getNoteTitle(),
);

View File

@ -14,10 +14,10 @@ export function initEditorMenu(editor: Zotero.EditorInstance) {
return;
}
editor._popup.setAttribute("bn-init", addon.data.uid);
(editor._popup as XUL.Menu).addEventListener("popupshowing", (ev) => {
(editor._popup as XULMenuElement).addEventListener("popupshowing", (ev) => {
const menuitemID = makeId("resizeImage");
if (
!(editor._popup as XUL.Menu).querySelector(`#${menuitemID}`) &&
!(editor._popup as XULMenuElement).querySelector(`#${menuitemID}`) &&
isImageAtCursor(editor)
) {
ztoolkit.Menu.register(editor._popup, {

View File

@ -153,7 +153,7 @@ async function updateEditorLinkPopup(editor: Zotero.EditorInstance) {
linkPopup?.append(insertButton, updateButton, openButton);
} else {
Array.from(_window.document.querySelectorAll(".link-popup-extra")).forEach(
(elem) => elem.remove(),
(elem) => (elem as HTMLElement)?.remove(),
);
}
}
@ -184,7 +184,7 @@ function updateEditorImagePopup(editor: Zotero.EditorInstance) {
}
const imageList = Array.from(imgs);
addon.hooks.onShowImageViewer(
imageList.map((elem) => elem.src),
imageList.map((elem) => (elem as HTMLImageElement)?.src),
imageList.indexOf(
editor._iframeWindow.document
.querySelector(".primary-editor")

View File

@ -221,9 +221,9 @@ async function embedLinkedNotes(noteItem: Zotero.Item): Promise<string> {
for (const i in noteLines) {
newLines.push(noteLines[i]);
const doc = parser.parseFromString(noteLines[i], "text/html");
const linkParams = Array.from(doc.querySelectorAll("a"))
.filter((a) => a.href.startsWith("zotero://note/"))
.map((a) => getNoteLinkParams(a.href))
const linkParams = (Array.from(doc.querySelectorAll("a")) as HTMLAnchorElement[])
.filter((a) => a?.href.startsWith("zotero://note/"))
.map((a) => getNoteLinkParams(a?.href))
.filter((p) => p.noteItem && !p.ignore);
for (const linkParam of linkParams) {
const html = await addon.api.template.runTemplate(
@ -248,11 +248,10 @@ async function embedLinkedNotes(noteItem: Zotero.Item): Promise<string> {
seenCitationItemIDs.push(currentID);
}
}
return `<div data-schema-version="${
globalCitationData.schemaVersion
}" data-citation-items="${encodeURIComponent(
JSON.stringify(finalCitationItems),
)}">${newLines.join("\n")}</div>`;
return `<div data-schema-version="${globalCitationData.schemaVersion
}" data-citation-items="${encodeURIComponent(
JSON.stringify(finalCitationItems),
)}">${newLines.join("\n")}</div>`;
}
function getNoteCitationData(noteItem: Zotero.Item) {

View File

@ -49,7 +49,7 @@ async function parseDocxFields(html: string, worker: HTMLIFrameElement) {
const mathCache = {} as MathCache;
for (const elem of Array.from(doc.querySelectorAll("math"))) {
for (const elem of (Array.from(doc.querySelectorAll("math")) as MathMLElement[])) {
let str = (await sendWorkerTask(
worker,
"parseMML",
@ -101,7 +101,7 @@ async function parseDocxFields(html: string, worker: HTMLIFrameElement) {
);
const citationElements = Array.from(
doc.querySelectorAll(".citation[data-citation]"),
);
) as HTMLElement[];
for (let i = 0; i < citationElements.length; i++) {
const elem = citationElements[i];
/*
@ -122,9 +122,8 @@ async function parseDocxFields(html: string, worker: HTMLIFrameElement) {
citationItems.push(item);
}
const properties = citation.properties;
const formattedCitation = `${
elem.textContent || "Zotero Citation"
} - Please click Zotero - Refresh in Word/LibreOffice to update all fields.`;
const formattedCitation = `${elem.textContent || "Zotero Citation"
} - Please click Zotero - Refresh in Word/LibreOffice to update all fields.`;
properties.formattedCitation = formattedCitation;
properties.plainCitation = formattedCitation + " ";
properties.noteIndex = 0;

View File

@ -59,7 +59,7 @@ export async function showExportNoteOptions(
}
}
Array.from(doc.querySelectorAll('input[name="linkMode"]')).forEach((elem) =>
elem.addEventListener("change", updateSyncCheckbox),
(elem as HTMLInputElement).addEventListener("change", updateSyncCheckbox),
);
updateSyncCheckbox();
};
@ -177,11 +177,11 @@ function makeCheckboxLine(dataKey: string, callback?: (ev: Event) => void) {
},
listeners: callback
? [
{
type: "change",
listener: callback,
},
]
{
type: "change",
listener: callback,
},
]
: [],
},
],
@ -223,11 +223,11 @@ function makeRadioLine(
},
listeners: callback
? [
{
type: "change",
listener: callback,
},
]
{
type: "change",
listener: callback,
},
]
: [],
},
],

View File

@ -45,7 +45,7 @@ export function registerMenus(win: Window) {
// menuFile
const menuFileAnchor = win.document.querySelector(
"#menu_newCollection",
) as XUL.MenuItem;
) as XULMenuItemElement;
ztoolkit.Menu.register(
"menuFile",
@ -105,7 +105,7 @@ export function registerMenus(win: Window) {
// create note menu in library
const newNoteMenu = win.document
.querySelector("#zotero-tb-note-add")
?.querySelector("menupopup") as XUL.MenuPopup;
?.querySelector("menupopup") as XULMenuPopupElement;
ztoolkit.Menu.register(newNoteMenu, {
tag: "menuitem",
label: getString("menuAddNote.newTemplateStandaloneNote"),
@ -130,7 +130,7 @@ export function registerMenus(win: Window) {
ztoolkit.Menu.register(
win.document.querySelector(
"#context-pane-add-child-note-button-popup",
) as XUL.MenuPopup,
) as XULMenuPopupElement,
{
tag: "menuitem",
label: getString("menuAddReaderNote.newTemplateNote"),

View File

@ -191,7 +191,7 @@ export async function showTemplateEditor() {
_window.document
.querySelector("#editor-type")
?.addEventListener("command", (ev) => {
updateSnippets((ev.target as XUL.MenuList)?.value);
updateSnippets((ev.target as XULMenuListElement)?.value);
});
addon.data.template.editor.window?.focus();
const editorWin = (_window.document.querySelector("#editor") as any)
@ -278,15 +278,15 @@ function updateEditor() {
const templateType = win.document.querySelector(
"#editor-type",
) as XUL.MenuList;
) as XULMenuListElement;
const templateName = win.document.querySelector(
"#editor-name",
) as HTMLInputElement;
const editor = win?.document.getElementById("editor") as HTMLIFrameElement;
const saveTemplate = win?.document.getElementById("save") as XUL.Button;
const deleteTemplate = win?.document.getElementById("delete") as XUL.Button;
const resetTemplate = win?.document.getElementById("reset") as XUL.Button;
const shareTemplate = win?.document.getElementById("share") as XUL.Button;
const saveTemplate = win?.document.getElementById("save") as XULButtonElement | null;
const deleteTemplate = win?.document.getElementById("delete") as XULButtonElement | null;
const resetTemplate = win?.document.getElementById("reset") as XULButtonElement | null;
const shareTemplate = win?.document.getElementById("share") as XULButtonElement | null;
const formats = win?.document.getElementById(
"formats-container",
) as HTMLDivElement;
@ -299,11 +299,11 @@ function updateEditor() {
templateName.value = "";
templateName.setAttribute("disabled", "true");
editor.hidden = true;
saveTemplate.setAttribute("disabled", "true");
deleteTemplate.setAttribute("disabled", "true");
deleteTemplate.hidden = false;
shareTemplate.setAttribute("disabled", "true");
resetTemplate.hidden = true;
saveTemplate?.setAttribute("disabled", "true");
deleteTemplate?.setAttribute("disabled", "true");
deleteTemplate && (deleteTemplate.hidden = false);
shareTemplate?.setAttribute("disabled", "true");
resetTemplate && (resetTemplate.hidden = true);
formats.hidden = true;
snippets.hidden = true;
} else {
@ -312,20 +312,20 @@ function updateEditor() {
if (!addon.api.template.SYSTEM_TEMPLATE_NAMES.includes(name)) {
templateType.removeAttribute("disabled");
templateName.removeAttribute("disabled");
deleteTemplate.hidden = false;
resetTemplate.hidden = true;
deleteTemplate && (deleteTemplate.hidden = false);
resetTemplate && (resetTemplate.hidden = true);
} else {
templateType.setAttribute("disabled", "true");
templateName.setAttribute("disabled", "true");
deleteTemplate.setAttribute("disabled", "true");
deleteTemplate.hidden = true;
resetTemplate.hidden = false;
deleteTemplate?.setAttribute("disabled", "true");
deleteTemplate && (deleteTemplate.hidden = true);
resetTemplate && (resetTemplate.hidden = false);
}
addon.data.template.editor.editor.setValue(templateText);
editor.hidden = false;
saveTemplate.removeAttribute("disabled");
deleteTemplate.removeAttribute("disabled");
shareTemplate.removeAttribute("disabled");
saveTemplate?.removeAttribute("disabled");
deleteTemplate?.removeAttribute("disabled");
shareTemplate?.removeAttribute("disabled");
formats.hidden = false;
snippets.hidden = false;
updateSnippets(
@ -534,7 +534,7 @@ function saveSelectedTemplate() {
const templateType = win.document.querySelector(
"#editor-type",
) as XUL.MenuList;
) as XULMenuListElement;
const templateName = win.document.querySelector(
"#editor-name",
) as HTMLInputElement;
@ -608,7 +608,7 @@ function resetSelectedTemplate() {
if (addon.api.template.SYSTEM_TEMPLATE_NAMES.includes(name)) {
addon.data.template.editor.editor.setValue(
addon.api.template.DEFAULT_TEMPLATES.find((t) => t.name === name)?.text ||
"",
"",
);
showHint(`Template ${name} is reset. Please save before leaving.`);
}
@ -631,9 +631,9 @@ pluginVersion: "${version}"
savedAt: "${new Date().toISOString()}"
content: |-
${content
.split("\n")
.map((line) => ` ${line}`)
.join("\n")}
.split("\n")
.map((line) => ` ${line}`)
.join("\n")}
`;
new ztoolkit.Clipboard().addText(yaml, "text/plain").copy();
showHint(

View File

@ -1,7 +1,7 @@
import { Workspace } from "../../elements/workspace/workspace";
import { waitUtilAsync } from "../../utils/wait";
export async function initWorkspace(container: XUL.Box, item: Zotero.Item) {
export async function initWorkspace(container: XULBoxElement, item: Zotero.Item) {
if (!container) {
return;
}

View File

@ -17,7 +17,7 @@ export async function openWorkspaceWindow(
const container = win.document.querySelector(
"#workspace-container",
) as XUL.Box;
) as XULBoxElement;
const workspace = await addon.hooks.onInitWorkspace(container, item);
workspace?.scrollEditorTo(options);

View File

@ -95,13 +95,13 @@ export function getLinkedNotesRecursively(
return [];
}
const doc = new DOMParser().parseFromString(noteItem.getNote(), "text/html");
const links = Array.from(doc.querySelectorAll("a"));
const links = Array.from(doc.querySelectorAll("a")) as HTMLAnchorElement[];
return links.reduce(
(acc, link) => {
const linkParams = getNoteLinkParams(link.href);
const linkParams = getNoteLinkParams(link?.href);
if (linkParams.noteItem) {
acc.push(linkParams.noteItem.id);
acc.push(...getLinkedNotesRecursively(link.href, acc));
acc.push(...getLinkedNotesRecursively(link?.href, acc));
}
return acc;
},

View File

@ -58,8 +58,7 @@ async function setLinesToNote(note: Zotero.Item, lines: string[]) {
} else {
const noteHead = noteText.substring(0, containerIndex);
note.setNote(
`${noteHead}data-schema-version="${
config.dataSchemaVersion
`${noteHead}data-schema-version="${config.dataSchemaVersion
}">${lines.join("\n")}</div>`,
);
}
@ -167,7 +166,7 @@ async function renderNoteHTML(
const bgNodes = doc.querySelectorAll(
"span[style]",
) as NodeListOf<HTMLElement>;
for (const node of Array.from(bgNodes)) {
for (const node of Array.from(bgNodes) as HTMLSpanElement[]) {
// Browser converts #RRGGBBAA hex color to rgba function, and we convert it to rgb function,
// because word processors don't understand colors with alpha channel
if (
@ -359,7 +358,7 @@ async function copyEmbeddedImagesInHTML(
if (await attachment.fileExists()) {
const nodes = Array.from(
doc.querySelectorAll(`img[data-attachment-key="${attachment.key}"]`),
);
) as HTMLImageElement[];
if (nodes.length) {
let copiedAttachment: Zotero.Item;
await Zotero.DB.executeTransaction(async () => {
@ -370,7 +369,7 @@ async function copyEmbeddedImagesInHTML(
});
});
nodes.forEach((node) =>
node.setAttribute("data-attachment-key", copiedAttachment.key),
node?.setAttribute("data-attachment-key", copiedAttachment.key), Node
);
}
}

2
typings/editor.d.ts vendored
View File

@ -43,7 +43,7 @@ declare interface EditorCore {
declare type EditorAPI =
typeof import("../src/extras/editorScript").BetterNotesEditorAPI;
declare interface EditorElement extends XUL.Box {
declare interface EditorElement extends XULBoxElement {
_iframe: HTMLIFrameElement;
_editorInstance: Zotero.EditorInstance;
_initialized?: boolean;