@fiduswriter/bibliography-manager 0.1.14 → 0.1.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bibliojson.d.ts +2 -0
- package/dist/bibliojson.d.ts.map +1 -0
- package/dist/bibliojson.js +2 -0
- package/dist/bibliojson.js.map +1 -0
- package/dist/import/bibliography_import.d.ts.map +1 -1
- package/dist/import/bibliography_import.js +2 -0
- package/dist/import/bibliography_import.js.map +1 -1
- package/dist/import/workers/bibliography_import_worker.js +150 -1
- package/dist/import/workers/bibliography_import_worker.js.map +1 -1
- package/package.json +8 -3
- package/src/bibliojson.ts +1 -0
- package/src/import/bibliography_import.ts +2 -0
- package/src/import/workers/bibliography_import_worker.ts +177 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bibliojson.d.ts","sourceRoot":"","sources":["../src/bibliojson.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bibliojson.js","sourceRoot":"","sources":["../src/bibliojson.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bibliography_import.d.ts","sourceRoot":"","sources":["../../src/import/bibliography_import.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAC,eAAe,EAAE,UAAU,EAAgB,MAAM,oBAAoB,CAAA;AAElF,UAAU,aAAa;IACnB,IAAI,EAAE,MAAM,CAAA;IACZ,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU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AK,IAAI,CAAA;IACtC,QAAQ,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,KAAK,GAAG,SAAS,CAAA;IAC1C,UAAU,EAAE,OAAO,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;gBAGb,YAAY,EAAE,MAAM,EACpB,KAAK,EAAE,eAAe,EACtB,aAAa,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,IAAI,EACtC,QAAQ,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,KAAK,GAAG,SAAS,EAC1C,UAAU,UAAO,EACjB,SAAS,CAAC,EAAE,MAAM;IAiBtB,IAAI,IAAI,IAAI;IAuBZ,SAAS,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI;CAmD1C"}
|
|
@@ -17,6 +17,7 @@ export class BibliographyImporter {
|
|
|
17
17
|
showAlerts;
|
|
18
18
|
workerURL;
|
|
19
19
|
constructor(fileContents, bibDB, addToListCall, callback, showAlerts = true, workerURL) {
|
|
20
|
+
console.log(`BibliographyImporter constructor called with workerURL: ${workerURL}`);
|
|
20
21
|
this.fileContents = fileContents;
|
|
21
22
|
this.bibDB = bibDB;
|
|
22
23
|
this.addToListCall = addToListCall;
|
|
@@ -25,6 +26,7 @@ export class BibliographyImporter {
|
|
|
25
26
|
this.workerURL =
|
|
26
27
|
workerURL ||
|
|
27
28
|
new URL("./workers/bibliography_import_worker.js", import.meta.url).href;
|
|
29
|
+
console.log(`this.workerURL: ${this.workerURL}`);
|
|
28
30
|
}
|
|
29
31
|
init() {
|
|
30
32
|
// Detect the format of the input file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bibliography_import.js","sourceRoot":"","sources":["../../src/import/bibliography_import.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAC,MAAM,YAAY,CAAA;AACtC,OAAO,EAAC,QAAQ,EAAC,MAAM,WAAW,CAAA;AAelC,MAAM,SAAS,GAA2B;IACtC,UAAU,EAAE,OAAO,CACf,wDAAwD,CAC3D;IACD,WAAW,EAAE,OAAO,CAAC,qDAAqD,CAAC;IAC3E,aAAa,EAAE,OAAO,CAClB,qEAAqE,CACxE;IACD,YAAY,EAAE,OAAO,CACjB,+EAA+E,CAClF;IACD,YAAY,EAAE,OAAO,CAAC,6CAA6C,CAAC;IACpE,WAAW,EAAE,OAAO,CAAC,uCAAuC,CAAC;IAC7D,kBAAkB,EAAE,OAAO,CAAC,0CAA0C,CAAC;CAC1E,CAAA;AAED,MAAM,OAAO,oBAAoB;IAC7B,YAAY,CAAQ;IACpB,KAAK,CAAiB;IACtB,aAAa,CAAyB;IACtC,QAAQ,CAAkC;IAC1C,UAAU,CAAS;IACnB,SAAS,CAAQ;IAEjB,YACI,YAAoB,EACpB,KAAsB,EACtB,aAAsC,EACtC,QAA0C,EAC1C,UAAU,GAAG,IAAI,EACjB,SAAkB;QAElB,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;QAChC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;QAClB,IAAI,CAAC,aAAa,GAAG,aAAa,CAAA;QAClC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAA;QACxB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC5B,IAAI,CAAC,SAAS;YACV,SAAS;gBACT,IAAI,GAAG,CACH,yCAAyC,EACzC,MAAM,CAAC,IAAI,CAAC,GAAG,CAClB,CAAC,IAAI,CAAA;
|
|
1
|
+
{"version":3,"file":"bibliography_import.js","sourceRoot":"","sources":["../../src/import/bibliography_import.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,WAAW,EAAC,MAAM,YAAY,CAAA;AACtC,OAAO,EAAC,QAAQ,EAAC,MAAM,WAAW,CAAA;AAelC,MAAM,SAAS,GAA2B;IACtC,UAAU,EAAE,OAAO,CACf,wDAAwD,CAC3D;IACD,WAAW,EAAE,OAAO,CAAC,qDAAqD,CAAC;IAC3E,aAAa,EAAE,OAAO,CAClB,qEAAqE,CACxE;IACD,YAAY,EAAE,O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AI,YAAY,OAAO,CAAC,KAAK,EAAE,CAAA;gBAC3C,CAAC;gBACD,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;oBAClB,QAAQ,CAAC,OAAO,CAAC,IAA2B,EAAE,QAAQ,CAAC,CAAA;gBAC3D,CAAC;gBACD,MAAK;YACT,KAAK,MAAM;gBACP,IAAI,GAAG,OAAO,CAAC,IAAI,CAAA;gBACnB,IAAI,IAAI,EAAE,CAAC;oBACP,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,IAAI,CACtC,CAAC,cAA+B,EAAE,EAAE;wBAChC,MAAM,MAAM,GAAG,cAAc,CAAC,GAAG,CAC7B,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,CACxB,CAAA;wBACD,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CAAA;oBAC9B,CAAC,CACJ,CAAA;gBACL,CAAC;gBACD,MAAK;YACT;gBACI,MAAK;QACb,CAAC;QACD,IAAI,OAAO,CAAC,IAAI,IAAI,IAAI,CAAC,QAAQ,IAAI,OAAO,IAAI,CAAC,QAAQ,KAAK,UAAU,EAAE,CAAC;YACvE,IAAI,CAAC,QAAQ,EAAE,CAAA;QACnB,CAAC;IACL,CAAC;CACJ"}
|
|
@@ -1,4 +1,153 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BibLatexParser, CSLParser, CitaviParser, CitaviXmlParser, DocxCitationsParser, ENWParser, EndNoteParser, NBIBParser, OdtCitationsParser, RISParser, sniffFormat } from "bibliojson";
|
|
2
|
+
class BibliographyImportWorker {
|
|
3
|
+
fileContents;
|
|
4
|
+
sendMessage;
|
|
5
|
+
format;
|
|
6
|
+
tmpDB = {};
|
|
7
|
+
bibKeys = [];
|
|
8
|
+
totalChunks = 0;
|
|
9
|
+
currentChunkNumber = 0;
|
|
10
|
+
constructor(fileContents, sendMessage, format = null) {
|
|
11
|
+
this.fileContents = fileContents;
|
|
12
|
+
this.sendMessage = sendMessage;
|
|
13
|
+
this.format = format;
|
|
14
|
+
}
|
|
15
|
+
init() {
|
|
16
|
+
const detectedFormat = this.format || sniffFormat(this.fileContents);
|
|
17
|
+
if (!detectedFormat) {
|
|
18
|
+
this.sendMessage({
|
|
19
|
+
type: "error",
|
|
20
|
+
errorCode: "unsupported_format",
|
|
21
|
+
done: true
|
|
22
|
+
});
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
let parser;
|
|
26
|
+
let parseResult;
|
|
27
|
+
try {
|
|
28
|
+
switch (detectedFormat) {
|
|
29
|
+
case "biblatex":
|
|
30
|
+
parser = new BibLatexParser(this.fileContents);
|
|
31
|
+
parseResult = parser.parse();
|
|
32
|
+
break;
|
|
33
|
+
case "csl_json":
|
|
34
|
+
parser = new CSLParser(this.fileContents);
|
|
35
|
+
parseResult = parser.parse();
|
|
36
|
+
break;
|
|
37
|
+
case "ris":
|
|
38
|
+
parser = new RISParser(this.fileContents);
|
|
39
|
+
parseResult = parser.parse();
|
|
40
|
+
break;
|
|
41
|
+
case "enw":
|
|
42
|
+
parser = new ENWParser(this.fileContents);
|
|
43
|
+
parseResult = parser.parse();
|
|
44
|
+
break;
|
|
45
|
+
case "nbib":
|
|
46
|
+
parser = new NBIBParser(this.fileContents);
|
|
47
|
+
parseResult = parser.parse();
|
|
48
|
+
break;
|
|
49
|
+
case "endnote_xml":
|
|
50
|
+
parser = new EndNoteParser(this.fileContents);
|
|
51
|
+
parseResult = parser.parse();
|
|
52
|
+
break;
|
|
53
|
+
case "citavi_xml":
|
|
54
|
+
parser = new CitaviXmlParser(this.fileContents);
|
|
55
|
+
parseResult = parser.parse();
|
|
56
|
+
break;
|
|
57
|
+
case "citavi_json":
|
|
58
|
+
parser = new CitaviParser(this.fileContents);
|
|
59
|
+
parseResult = parser.parse();
|
|
60
|
+
break;
|
|
61
|
+
case "odt_citations":
|
|
62
|
+
parser = new OdtCitationsParser(this.fileContents);
|
|
63
|
+
parseResult = parser.parse();
|
|
64
|
+
break;
|
|
65
|
+
case "docx_citations":
|
|
66
|
+
parser = new DocxCitationsParser(this.fileContents);
|
|
67
|
+
parseResult = parser.parse();
|
|
68
|
+
break;
|
|
69
|
+
default:
|
|
70
|
+
this.sendMessage({
|
|
71
|
+
type: "error",
|
|
72
|
+
errorCode: "unsupported_format",
|
|
73
|
+
done: true
|
|
74
|
+
});
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
this.tmpDB = parseResult.entries || {};
|
|
78
|
+
this.bibKeys = Object.keys(this.tmpDB);
|
|
79
|
+
if (!this.bibKeys.length) {
|
|
80
|
+
this.sendMessage({
|
|
81
|
+
type: "error",
|
|
82
|
+
errorCode: "no_entries",
|
|
83
|
+
done: true
|
|
84
|
+
});
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
this.bibKeys.forEach(bibKey => {
|
|
88
|
+
const bibEntry = this.tmpDB[bibKey];
|
|
89
|
+
bibEntry.cats = [];
|
|
90
|
+
if (!bibEntry.fields.title) {
|
|
91
|
+
bibEntry.fields.title = [];
|
|
92
|
+
}
|
|
93
|
+
if (!bibEntry.fields.date) {
|
|
94
|
+
bibEntry.fields.date = "uuuu";
|
|
95
|
+
}
|
|
96
|
+
if (!bibEntry.fields.author && !bibEntry.fields.editor) {
|
|
97
|
+
bibEntry.fields.author = [{ literal: [] }];
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
if (parser.errors) {
|
|
101
|
+
parser.errors.forEach((error) => {
|
|
102
|
+
this.sendMessage({
|
|
103
|
+
type: "error",
|
|
104
|
+
errorCode: "entry_error",
|
|
105
|
+
errorType: error.type || "unknown",
|
|
106
|
+
key: error.key,
|
|
107
|
+
entry: error.entry,
|
|
108
|
+
...error
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
if (parser.warnings) {
|
|
113
|
+
parser.warnings.forEach((warning) => {
|
|
114
|
+
this.sendMessage({
|
|
115
|
+
type: "warning",
|
|
116
|
+
errorCode: warning.type || "unknown",
|
|
117
|
+
...warning
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
this.totalChunks = Math.ceil(this.bibKeys.length / 50);
|
|
122
|
+
this.currentChunkNumber = 0;
|
|
123
|
+
this.processChunk();
|
|
124
|
+
}
|
|
125
|
+
catch (error) {
|
|
126
|
+
this.sendMessage({
|
|
127
|
+
type: "error",
|
|
128
|
+
errorCode: "parse_error",
|
|
129
|
+
errorType: error.message || "unknown",
|
|
130
|
+
done: true
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
processChunk() {
|
|
135
|
+
if (this.currentChunkNumber < this.totalChunks) {
|
|
136
|
+
const fromNumber = this.currentChunkNumber * 50;
|
|
137
|
+
const toNumber = fromNumber + 50;
|
|
138
|
+
const currentChunk = {};
|
|
139
|
+
this.bibKeys.slice(fromNumber, toNumber).forEach(bibKey => {
|
|
140
|
+
currentChunk[bibKey] = this.tmpDB[bibKey];
|
|
141
|
+
});
|
|
142
|
+
this.sendMessage({ type: "data", data: currentChunk });
|
|
143
|
+
this.currentChunkNumber++;
|
|
144
|
+
this.processChunk();
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
this.sendMessage({ type: "ok", done: true });
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
2
151
|
addEventListener("message", message => {
|
|
3
152
|
const { fileContents, format } = message.data;
|
|
4
153
|
const worker = new BibliographyImportWorker(fileContents, postMessage.bind(self), format);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bibliography_import_worker.js","sourceRoot":"","sources":["../../../src/import/workers/bibliography_import_worker.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"bibliography_import_worker.js","sourceRoot":"","sources":["../../../src/import/workers/bibliography_import_worker.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,cAAc,EACd,SAAS,EACT,YAAY,EACZ,eAAe,EACf,m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,EAAE,QAAQ,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE;gBACtD,YAAY,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;YAC7C,CAAC,CAAC,CAAA;YACF,IAAI,CAAC,WAAW,CAAC,EAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,YAAY,EAAC,CAAC,CAAA;YACpD,IAAI,CAAC,kBAAkB,EAAE,CAAA;YACzB,IAAI,CAAC,YAAY,EAAE,CAAA;QACvB,CAAC;aAAM,CAAC;YACJ,IAAI,CAAC,WAAW,CAAC,EAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAC,CAAC,CAAA;QAC9C,CAAC;IACL,CAAC;CACJ;AAED,gBAAgB,CAAC,SAAS,EAAE,OAAO,CAAC,EAAE;IAClC,MAAM,EAAC,YAAY,EAAE,MAAM,EAAC,GAAG,OAAO,CAAC,IAAI,CAAA;IAC3C,MAAM,MAAM,GAAG,IAAI,wBAAwB,CACvC,YAAY,EACZ,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,EACtB,MAAM,CACT,CAAA;IACD,MAAM,CAAC,IAAI,EAAE,CAAA;AACjB,CAAC,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fiduswriter/bibliography-manager",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.17",
|
|
4
4
|
"description": "Fidus Writer bibliography manager",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -40,6 +40,10 @@
|
|
|
40
40
|
"types": "./dist/schema/*.d.ts",
|
|
41
41
|
"default": "./dist/schema/*.js"
|
|
42
42
|
},
|
|
43
|
+
"./bibliojson": {
|
|
44
|
+
"types": "./dist/bibliojson.d.ts",
|
|
45
|
+
"default": "./dist/bibliojson.js"
|
|
46
|
+
},
|
|
43
47
|
"./*": {
|
|
44
48
|
"types": "./dist/*.d.ts",
|
|
45
49
|
"default": "./dist/*.js"
|
|
@@ -64,7 +68,7 @@
|
|
|
64
68
|
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js --config jest.config.js"
|
|
65
69
|
},
|
|
66
70
|
"dependencies": {
|
|
67
|
-
"bibliojson": "
|
|
71
|
+
"bibliojson": "4.0.3",
|
|
68
72
|
"fix-utf8": "2.0.1",
|
|
69
73
|
"fwtoolkit": "^0.1.9",
|
|
70
74
|
"prosemirror-model": "^1.25.0",
|
|
@@ -89,7 +93,8 @@
|
|
|
89
93
|
"prettier --write"
|
|
90
94
|
],
|
|
91
95
|
"*.{ts,js,mjs}": [
|
|
92
|
-
"eslint --fix"
|
|
96
|
+
"eslint --fix",
|
|
97
|
+
"sh -c 'npm run typecheck'"
|
|
93
98
|
]
|
|
94
99
|
}
|
|
95
100
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "bibliojson"
|
|
@@ -46,6 +46,7 @@ export class BibliographyImporter {
|
|
|
46
46
|
showAlerts = true,
|
|
47
47
|
workerURL?: string
|
|
48
48
|
) {
|
|
49
|
+
console.log(`BibliographyImporter constructor called with workerURL: ${workerURL}`)
|
|
49
50
|
this.fileContents = fileContents
|
|
50
51
|
this.bibDB = bibDB
|
|
51
52
|
this.addToListCall = addToListCall
|
|
@@ -57,6 +58,7 @@ export class BibliographyImporter {
|
|
|
57
58
|
"./workers/bibliography_import_worker.js",
|
|
58
59
|
import.meta.url
|
|
59
60
|
).href
|
|
61
|
+
console.log(`this.workerURL: ${this.workerURL}`)
|
|
60
62
|
}
|
|
61
63
|
|
|
62
64
|
init(): void {
|
|
@@ -1,4 +1,180 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
BibLatexParser,
|
|
3
|
+
CSLParser,
|
|
4
|
+
CitaviParser,
|
|
5
|
+
CitaviXmlParser,
|
|
6
|
+
DocxCitationsParser,
|
|
7
|
+
ENWParser,
|
|
8
|
+
EndNoteParser,
|
|
9
|
+
NBIBParser,
|
|
10
|
+
OdtCitationsParser,
|
|
11
|
+
RISParser,
|
|
12
|
+
sniffFormat
|
|
13
|
+
} from "bibliojson"
|
|
14
|
+
|
|
15
|
+
class BibliographyImportWorker {
|
|
16
|
+
fileContents: string
|
|
17
|
+
sendMessage: (msg: any) => void
|
|
18
|
+
format: string | null
|
|
19
|
+
tmpDB: Record<string, any> = {}
|
|
20
|
+
bibKeys: string[] = []
|
|
21
|
+
totalChunks = 0
|
|
22
|
+
currentChunkNumber = 0
|
|
23
|
+
|
|
24
|
+
constructor(
|
|
25
|
+
fileContents: string,
|
|
26
|
+
sendMessage: (msg: any) => void,
|
|
27
|
+
format: string | null = null
|
|
28
|
+
) {
|
|
29
|
+
this.fileContents = fileContents
|
|
30
|
+
this.sendMessage = sendMessage
|
|
31
|
+
this.format = format
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
init(): void {
|
|
35
|
+
const detectedFormat = this.format || sniffFormat(this.fileContents)
|
|
36
|
+
|
|
37
|
+
if (!detectedFormat) {
|
|
38
|
+
this.sendMessage({
|
|
39
|
+
type: "error",
|
|
40
|
+
errorCode: "unsupported_format",
|
|
41
|
+
done: true
|
|
42
|
+
})
|
|
43
|
+
return
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
let parser: any
|
|
47
|
+
let parseResult: {entries?: Record<string, any>}
|
|
48
|
+
|
|
49
|
+
try {
|
|
50
|
+
switch (detectedFormat) {
|
|
51
|
+
case "biblatex":
|
|
52
|
+
parser = new BibLatexParser(this.fileContents)
|
|
53
|
+
parseResult = parser.parse()
|
|
54
|
+
break
|
|
55
|
+
case "csl_json":
|
|
56
|
+
parser = new (CSLParser as any)(this.fileContents)
|
|
57
|
+
parseResult = parser.parse()
|
|
58
|
+
break
|
|
59
|
+
case "ris":
|
|
60
|
+
parser = new RISParser(this.fileContents)
|
|
61
|
+
parseResult = parser.parse()
|
|
62
|
+
break
|
|
63
|
+
case "enw":
|
|
64
|
+
parser = new ENWParser(this.fileContents)
|
|
65
|
+
parseResult = parser.parse()
|
|
66
|
+
break
|
|
67
|
+
case "nbib":
|
|
68
|
+
parser = new NBIBParser(this.fileContents)
|
|
69
|
+
parseResult = parser.parse()
|
|
70
|
+
break
|
|
71
|
+
case "endnote_xml":
|
|
72
|
+
parser = new (EndNoteParser as any)(this.fileContents)
|
|
73
|
+
parseResult = parser.parse()
|
|
74
|
+
break
|
|
75
|
+
case "citavi_xml":
|
|
76
|
+
parser = new CitaviXmlParser(this.fileContents)
|
|
77
|
+
parseResult = parser.parse()
|
|
78
|
+
break
|
|
79
|
+
case "citavi_json":
|
|
80
|
+
parser = new (CitaviParser as any)(this.fileContents)
|
|
81
|
+
parseResult = parser.parse()
|
|
82
|
+
break
|
|
83
|
+
case "odt_citations":
|
|
84
|
+
parser = new OdtCitationsParser(this.fileContents)
|
|
85
|
+
parseResult = parser.parse()
|
|
86
|
+
break
|
|
87
|
+
case "docx_citations":
|
|
88
|
+
parser = new DocxCitationsParser(this.fileContents)
|
|
89
|
+
parseResult = parser.parse()
|
|
90
|
+
break
|
|
91
|
+
default:
|
|
92
|
+
this.sendMessage({
|
|
93
|
+
type: "error",
|
|
94
|
+
errorCode: "unsupported_format",
|
|
95
|
+
done: true
|
|
96
|
+
})
|
|
97
|
+
return
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
this.tmpDB = parseResult.entries || {}
|
|
101
|
+
this.bibKeys = Object.keys(this.tmpDB)
|
|
102
|
+
|
|
103
|
+
if (!this.bibKeys.length) {
|
|
104
|
+
this.sendMessage({
|
|
105
|
+
type: "error",
|
|
106
|
+
errorCode: "no_entries",
|
|
107
|
+
done: true
|
|
108
|
+
})
|
|
109
|
+
return
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
this.bibKeys.forEach(bibKey => {
|
|
113
|
+
const bibEntry = this.tmpDB[bibKey]
|
|
114
|
+
bibEntry.cats = []
|
|
115
|
+
if (!bibEntry.fields.title) {
|
|
116
|
+
bibEntry.fields.title = []
|
|
117
|
+
}
|
|
118
|
+
if (!bibEntry.fields.date) {
|
|
119
|
+
bibEntry.fields.date = "uuuu"
|
|
120
|
+
}
|
|
121
|
+
if (!bibEntry.fields.author && !bibEntry.fields.editor) {
|
|
122
|
+
bibEntry.fields.author = [{literal: []}]
|
|
123
|
+
}
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
if (parser.errors) {
|
|
127
|
+
parser.errors.forEach((error: any) => {
|
|
128
|
+
this.sendMessage({
|
|
129
|
+
type: "error",
|
|
130
|
+
errorCode: "entry_error",
|
|
131
|
+
errorType: error.type || "unknown",
|
|
132
|
+
key: error.key,
|
|
133
|
+
entry: error.entry,
|
|
134
|
+
...error
|
|
135
|
+
})
|
|
136
|
+
})
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (parser.warnings) {
|
|
140
|
+
parser.warnings.forEach((warning: any) => {
|
|
141
|
+
this.sendMessage({
|
|
142
|
+
type: "warning",
|
|
143
|
+
errorCode: warning.type || "unknown",
|
|
144
|
+
...warning
|
|
145
|
+
})
|
|
146
|
+
})
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
this.totalChunks = Math.ceil(this.bibKeys.length / 50)
|
|
150
|
+
this.currentChunkNumber = 0
|
|
151
|
+
this.processChunk()
|
|
152
|
+
} catch (error: any) {
|
|
153
|
+
this.sendMessage({
|
|
154
|
+
type: "error",
|
|
155
|
+
errorCode: "parse_error",
|
|
156
|
+
errorType: error.message || "unknown",
|
|
157
|
+
done: true
|
|
158
|
+
})
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
processChunk(): void {
|
|
163
|
+
if (this.currentChunkNumber < this.totalChunks) {
|
|
164
|
+
const fromNumber = this.currentChunkNumber * 50
|
|
165
|
+
const toNumber = fromNumber + 50
|
|
166
|
+
const currentChunk: Record<string, any> = {}
|
|
167
|
+
this.bibKeys.slice(fromNumber, toNumber).forEach(bibKey => {
|
|
168
|
+
currentChunk[bibKey] = this.tmpDB[bibKey]
|
|
169
|
+
})
|
|
170
|
+
this.sendMessage({type: "data", data: currentChunk})
|
|
171
|
+
this.currentChunkNumber++
|
|
172
|
+
this.processChunk()
|
|
173
|
+
} else {
|
|
174
|
+
this.sendMessage({type: "ok", done: true})
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
2
178
|
|
|
3
179
|
addEventListener("message", message => {
|
|
4
180
|
const {fileContents, format} = message.data
|