fix: sync bug when item id re-assigned
This commit is contained in:
parent
cdb69c2f1a
commit
27e67c39c6
|
|
@ -63,6 +63,6 @@
|
|||
"cross-env": "^7.0.3",
|
||||
"esbuild": "^0.14.34",
|
||||
"release-it": "^14.14.0",
|
||||
"zotero-types": "^0.1.2"
|
||||
"zotero-types": "^1.0.9"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ class EditorController extends AddonBase {
|
|||
instance: Zotero.EditorInstance;
|
||||
time: number;
|
||||
}>;
|
||||
editorPromise: _ZoteroPromiseObject;
|
||||
editorPromise: _ZoteroTypes.PromiseObject;
|
||||
activeEditor: Zotero.EditorInstance;
|
||||
|
||||
constructor(parent: BetterNotes) {
|
||||
|
|
|
|||
|
|
@ -262,7 +262,7 @@ class EditorViews extends AddonBase {
|
|||
{
|
||||
id: `knowledge-addcitation-popup-${topItem.id}`,
|
||||
rank: 0,
|
||||
text: topItem.getField("title"),
|
||||
text: topItem.getField("title") as string,
|
||||
eventType: "insertCitation",
|
||||
},
|
||||
],
|
||||
|
|
@ -699,7 +699,7 @@ class EditorViews extends AddonBase {
|
|||
);
|
||||
newLines.push(templateText);
|
||||
const newLineString = newLines.join("\n");
|
||||
const notifyFlag: _ZoteroPromiseObject = Zotero.Promise.defer();
|
||||
const notifyFlag: _ZoteroTypes.PromiseObject = Zotero.Promise.defer();
|
||||
const notifierName = "insertLinkWait";
|
||||
this._Addon.ZoteroNotifies.registerNotifyListener(
|
||||
notifierName,
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ class NoteExport extends AddonBase {
|
|||
note: Zotero.Item;
|
||||
filename: string;
|
||||
}>;
|
||||
_pdfPrintPromise: _ZoteroPromiseObject;
|
||||
_docxPromise: _ZoteroPromiseObject;
|
||||
_pdfPrintPromise: _ZoteroTypes.PromiseObject;
|
||||
_docxPromise: _ZoteroTypes.PromiseObject;
|
||||
_docxBlob: Blob;
|
||||
|
||||
constructor(parent: BetterNotes) {
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ class NoteImport extends AddonBase {
|
|||
} catch (e) {
|
||||
this._Addon.toolkit.Tool.log(`Import: ${String(e)}`);
|
||||
}
|
||||
if (!options.ignoreVersion && mdStatus.meta?.version < noteItem?._version) {
|
||||
if (!options.ignoreVersion && mdStatus.meta?.version < noteItem?.version) {
|
||||
if (
|
||||
!confirm(
|
||||
`The target note seems to be newer than the file ${file}. Are you sure you want to import it anyway?`
|
||||
|
|
|
|||
|
|
@ -306,7 +306,7 @@ class NoteUtils extends AddonBase {
|
|||
} = { ignore: false, withLine: false }
|
||||
) {
|
||||
let libraryID = note.libraryID;
|
||||
let library = Zotero.Libraries.get(libraryID);
|
||||
let library = Zotero.Libraries.get(libraryID) as Zotero.Library;
|
||||
let groupID: string;
|
||||
if (library.libraryType === "user") {
|
||||
groupID = "u";
|
||||
|
|
@ -346,7 +346,7 @@ class NoteUtils extends AddonBase {
|
|||
|
||||
const attachment = annotation.parentItem;
|
||||
let libraryID = attachment.libraryID;
|
||||
let library = Zotero.Libraries.get(libraryID);
|
||||
let library = Zotero.Libraries.get(libraryID) as Zotero.Library;
|
||||
if (library.libraryType === "user") {
|
||||
openURI = `zotero://open-pdf/library/items/${attachment.key}`;
|
||||
} else if (library.libraryType === "group") {
|
||||
|
|
@ -691,10 +691,10 @@ class NoteUtils extends AddonBase {
|
|||
};
|
||||
}
|
||||
this._Addon.toolkit.Tool.log(params);
|
||||
let item: Zotero.Item = await Zotero.Items.getByLibraryAndKeyAsync(
|
||||
let item: Zotero.Item = (await Zotero.Items.getByLibraryAndKeyAsync(
|
||||
params.libraryID,
|
||||
params.noteKey
|
||||
);
|
||||
)) as Zotero.Item;
|
||||
if (!item || !item.isNote()) {
|
||||
return {
|
||||
item: undefined,
|
||||
|
|
@ -775,7 +775,9 @@ class NoteUtils extends AddonBase {
|
|||
}
|
||||
}
|
||||
}
|
||||
this._Addon.toolkit.Tool.log(`line ${currentLineIndex} of item ${itemID} selected.`);
|
||||
this._Addon.toolkit.Tool.log(
|
||||
`line ${currentLineIndex} of item ${itemID} selected.`
|
||||
);
|
||||
// Don't use the instance._item.id, as it might not be updated.
|
||||
this.currentLine[itemID] = currentLineIndex;
|
||||
if (realElement.tagName === "A") {
|
||||
|
|
|
|||
|
|
@ -16,7 +16,9 @@ class SyncController extends AddonBase {
|
|||
|
||||
getSyncNoteIds(): number[] {
|
||||
const ids = Zotero.Prefs.get("Knowledge4Zotero.syncNoteIds") as string;
|
||||
return ids.split(",").map((id: string) => Number(id));
|
||||
return Zotero.Items.get(ids.split(",").map((id: string) => Number(id)))
|
||||
.filter((item) => item.isNote())
|
||||
.map((item) => item.id);
|
||||
}
|
||||
|
||||
isSyncNote(note: Zotero.Item): boolean {
|
||||
|
|
@ -95,7 +97,7 @@ class SyncController extends AddonBase {
|
|||
}
|
||||
// Note version doesn't match (note side change)
|
||||
// This might be unreliable when Zotero account is not login
|
||||
if (Number(MDStatus.meta.version) !== noteItem._version) {
|
||||
if (Number(MDStatus.meta.version) !== noteItem.version) {
|
||||
noteAhead = true;
|
||||
}
|
||||
if (noteAhead && MDAhead) {
|
||||
|
|
@ -139,7 +141,7 @@ class SyncController extends AddonBase {
|
|||
let progress;
|
||||
// Wrap the code in try...catch so that the lock can be released anyway
|
||||
try {
|
||||
this._Addon.toolkit.Tool.log("sync start")
|
||||
this._Addon.toolkit.Tool.log("sync start");
|
||||
this.sycnLock = true;
|
||||
if (!items || !items.length) {
|
||||
items = Zotero.Items.get(this.getSyncNoteIds());
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ class SyncUtils extends AddonBase {
|
|||
}
|
||||
|
||||
async _getDataURL(item: Zotero.Item) {
|
||||
let path = await item.getFilePathAsync();
|
||||
let path = (await item.getFilePathAsync()) as string;
|
||||
let buf = new Uint8Array((await OS.File.read(path, {})) as Uint8Array)
|
||||
.buffer;
|
||||
return (
|
||||
|
|
@ -890,7 +890,13 @@ class SyncUtils extends AddonBase {
|
|||
imgKey
|
||||
);
|
||||
this._Addon.toolkit.Tool.log(attachmentItem);
|
||||
this._Addon.toolkit.Tool.log("image", libraryID, imgKey, attachmentItem, node);
|
||||
this._Addon.toolkit.Tool.log(
|
||||
"image",
|
||||
libraryID,
|
||||
imgKey,
|
||||
attachmentItem,
|
||||
node
|
||||
);
|
||||
if (!attachmentItem) {
|
||||
continue;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,13 +7,13 @@ import { EditorMessage, OutlineType } from "../utils";
|
|||
import AddonBase from "../module";
|
||||
|
||||
class WorkspaceWindow extends AddonBase {
|
||||
private _initIframe: _ZoteroPromiseObject;
|
||||
private _initIframe: _ZoteroTypes.PromiseObject;
|
||||
public workspaceWindow: Window;
|
||||
public workspaceTabId: string;
|
||||
public workspaceNoteEditor: Zotero.EditorInstance | undefined;
|
||||
public previewItemID: number;
|
||||
private _firstInit: boolean;
|
||||
public _workspacePromise: _ZoteroPromiseObject;
|
||||
public _workspacePromise: _ZoteroTypes.PromiseObject;
|
||||
private _DOMParser: any;
|
||||
|
||||
constructor(parent: BetterNotes) {
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@ class ZoteroEvents extends AddonBase {
|
|||
});
|
||||
}
|
||||
|
||||
private async onEditorInstanceCreated(instance: _ZoteroEditorInstance) {
|
||||
private async onEditorInstanceCreated(instance: Zotero.EditorInstance) {
|
||||
await instance._initPromise;
|
||||
instance._knowledgeUIInitialized = false;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue