@fiduswriter/bibliography-manager 0.1.14 → 0.1.16
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.
|
@@ -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,mBAAmB,EACnB,SAAS,EACT,aAAa,EACb,UAAU,EACV,kBAAkB,EAClB,SAAS,EACT,WAAW,EACd,MAAM,YAAY,CAAA;AAEnB,MAAM,wBAAwB;IAC1B,YAAY,CAAQ;IACpB,WAAW,CAAoB;IAC/B,MAAM,CAAe;IACrB,KAAK,GAAwB,EAAE,CAAA;IAC/B,OAAO,GAAa,EAAE,CAAA;IACtB,WAAW,GAAG,CAAC,CAAA;IACf,kBAAkB,GAAG,CAAC,CAAA;IAEtB,YACI,YAAoB,EACpB,WAA+B,EAC/B,SAAwB,IAAI;QAE5B,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;QAChC,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACxB,CAAC;IAED,IAAI;QACA,MAAM,cAAc,GAAG,IAAI,CAAC,MAAM,IAAI,WAAW,CAAC,IAAI,CAAC,YAAY,CAAC,CAAA;QAEpE,IAAI,CAAC,cAAc,EAAE,CAAC;YAClB,IAAI,CAAC,WAAW,CAAC;gBACb,IAAI,EAAE,OA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AAI,CAAC,EACtB,MAAM,CACT,CAAA;IACD,MAAM,CAAC,IAAI,EAAE,CAAA;AACjB,CAAC,CAAC,CAAA"}
|
package/package.json
CHANGED
|
@@ -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
|