@fiduswriter/bibliography-manager 0.1.7 → 0.1.9
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/README.md +53 -12
- package/dist/database/index.d.ts +12 -11
- package/dist/database/index.d.ts.map +1 -1
- package/dist/database/index.js +22 -16
- package/dist/database/index.js.map +1 -1
- package/dist/database/server_connector.d.ts +14 -15
- package/dist/database/server_connector.d.ts.map +1 -1
- package/dist/database/server_connector.js +17 -9
- package/dist/database/server_connector.js.map +1 -1
- package/dist/export/index.d.ts +6 -4
- package/dist/export/index.d.ts.map +1 -1
- package/dist/export/index.js +7 -1
- package/dist/export/index.js.map +1 -1
- package/dist/form/cats.d.ts +5 -4
- package/dist/form/cats.d.ts.map +1 -1
- package/dist/form/cats.js +2 -0
- package/dist/form/cats.js.map +1 -1
- package/dist/form/fields/date.d.ts +4 -4
- package/dist/form/fields/date.d.ts.map +1 -1
- package/dist/form/fields/date.js +5 -1
- package/dist/form/fields/date.js.map +1 -1
- package/dist/form/fields/key.d.ts +11 -9
- package/dist/form/fields/key.d.ts.map +1 -1
- package/dist/form/fields/key.js +13 -6
- package/dist/form/fields/key.js.map +1 -1
- package/dist/form/fields/key_list.d.ts +10 -8
- package/dist/form/fields/key_list.d.ts.map +1 -1
- package/dist/form/fields/key_list.js +4 -0
- package/dist/form/fields/key_list.js.map +1 -1
- package/dist/form/fields/literal.d.ts +4 -4
- package/dist/form/fields/literal.d.ts.map +1 -1
- package/dist/form/fields/literal.js +2 -1
- package/dist/form/fields/literal.js.map +1 -1
- package/dist/form/fields/literal_list.d.ts +8 -7
- package/dist/form/fields/literal_list.d.ts.map +1 -1
- package/dist/form/fields/literal_list.js +3 -0
- package/dist/form/fields/literal_list.js.map +1 -1
- package/dist/form/fields/literal_long.d.ts +4 -4
- package/dist/form/fields/literal_long.d.ts.map +1 -1
- package/dist/form/fields/literal_long.js +1 -0
- package/dist/form/fields/literal_long.js.map +1 -1
- package/dist/form/fields/name.d.ts +10 -27
- package/dist/form/fields/name.d.ts.map +1 -1
- package/dist/form/fields/name.js +22 -18
- package/dist/form/fields/name.js.map +1 -1
- package/dist/form/fields/name_list.d.ts +9 -7
- package/dist/form/fields/name_list.d.ts.map +1 -1
- package/dist/form/fields/name_list.js +5 -2
- package/dist/form/fields/name_list.js.map +1 -1
- package/dist/form/fields/range.d.ts +10 -8
- package/dist/form/fields/range.d.ts.map +1 -1
- package/dist/form/fields/range.js +13 -9
- package/dist/form/fields/range.js.map +1 -1
- package/dist/form/fields/range_list.d.ts +9 -7
- package/dist/form/fields/range_list.d.ts.map +1 -1
- package/dist/form/fields/range_list.js +3 -0
- package/dist/form/fields/range_list.js.map +1 -1
- package/dist/form/fields/tag_list.d.ts +7 -6
- package/dist/form/fields/tag_list.d.ts.map +1 -1
- package/dist/form/fields/tag_list.js +3 -0
- package/dist/form/fields/tag_list.js.map +1 -1
- package/dist/form/fields/title.d.ts +4 -4
- package/dist/form/fields/title.d.ts.map +1 -1
- package/dist/form/fields/title.js +1 -0
- package/dist/form/fields/title.js.map +1 -1
- package/dist/form/fields/uri.d.ts +4 -4
- package/dist/form/fields/uri.d.ts.map +1 -1
- package/dist/form/fields/uri.js +5 -1
- package/dist/form/fields/uri.js.map +1 -1
- package/dist/form/fields/verbatim.d.ts +4 -4
- package/dist/form/fields/verbatim.d.ts.map +1 -1
- package/dist/form/fields/verbatim.js +5 -1
- package/dist/form/fields/verbatim.js.map +1 -1
- package/dist/form/index.d.ts +32 -30
- package/dist/form/index.d.ts.map +1 -1
- package/dist/form/index.js +33 -11
- package/dist/form/index.js.map +1 -1
- package/dist/form/strings.d.ts +11 -11
- package/dist/form/strings.d.ts.map +1 -1
- package/dist/form/strings.js +5 -5
- package/dist/form/strings.js.map +1 -1
- package/dist/form/templates.d.ts +6 -5
- package/dist/form/templates.d.ts.map +1 -1
- package/dist/form/templates.js +2 -2
- package/dist/form/templates.js.map +1 -1
- package/dist/import/bibliography_import.d.ts +20 -7
- package/dist/import/bibliography_import.d.ts.map +1 -1
- package/dist/import/bibliography_import.js +15 -7
- package/dist/import/bibliography_import.js.map +1 -1
- package/dist/import/dialog.d.ts +6 -5
- package/dist/import/dialog.d.ts.map +1 -1
- package/dist/import/dialog.js +27 -12
- package/dist/import/dialog.js.map +1 -1
- package/dist/import/index.d.ts +2 -0
- package/dist/import/index.d.ts.map +1 -1
- package/dist/import/index.js +5 -0
- package/dist/import/index.js.map +1 -1
- package/dist/import/templates.d.ts +2 -1
- package/dist/import/templates.d.ts.map +1 -1
- package/dist/import/templates.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/overview/index.d.ts +43 -28
- package/dist/overview/index.d.ts.map +1 -1
- package/dist/overview/index.js +55 -20
- package/dist/overview/index.js.map +1 -1
- package/dist/overview/menu.d.ts +13 -12
- package/dist/overview/menu.d.ts.map +1 -1
- package/dist/overview/menu.js +13 -10
- package/dist/overview/menu.js.map +1 -1
- package/dist/overview/templates.d.ts +5 -3
- package/dist/overview/templates.d.ts.map +1 -1
- package/dist/overview/templates.js.map +1 -1
- package/dist/plugins/bibliography_overview/index.d.ts +1 -1
- package/dist/plugins/bibliography_overview/index.d.ts.map +1 -1
- package/dist/plugins/bibliography_overview/index.js.map +1 -1
- package/dist/schema/csl_bib.d.ts +1 -1
- package/dist/schema/literal.d.ts +1 -1
- package/dist/schema/literal.d.ts.map +1 -1
- package/dist/schema/literal.js.map +1 -1
- package/dist/schema/literal_long.d.ts +1 -1
- package/dist/schema/literal_long.d.ts.map +1 -1
- package/dist/schema/literal_long.js +1 -7
- package/dist/schema/literal_long.js.map +1 -1
- package/dist/schema/title.d.ts +1 -1
- package/dist/schema/title.d.ts.map +1 -1
- package/dist/schema/title.js.map +1 -1
- package/dist/tools.d.ts +4 -3
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js.map +1 -1
- package/dist/types/biblio.d.ts +138 -0
- package/dist/types/biblio.d.ts.map +1 -0
- package/dist/types/biblio.js +2 -0
- package/dist/types/biblio.js.map +1 -0
- package/package.json +88 -74
- package/src/database/{index.js → index.ts} +60 -38
- package/src/database/server_connector.ts +92 -0
- package/src/export/{index.js → index.ts} +16 -4
- package/src/form/{cats.js → cats.ts} +11 -3
- package/src/form/fields/{date.js → date.ts} +10 -5
- package/src/form/fields/{key.js → key.ts} +37 -19
- package/src/form/fields/{key_list.js → key_list.ts} +18 -7
- package/src/form/fields/{literal.js → literal.ts} +11 -5
- package/src/form/fields/{literal_list.js → literal_list.ts} +19 -10
- package/src/form/fields/{literal_long.js → literal_long.ts} +6 -4
- package/src/form/fields/{name.js → name.ts} +53 -39
- package/src/form/fields/name_list.ts +49 -0
- package/src/form/fields/{range.js → range.ts} +34 -22
- package/src/form/fields/{range_list.js → range_list.ts} +17 -10
- package/src/form/fields/{tag_list.js → tag_list.ts} +9 -5
- package/src/form/fields/{title.js → title.ts} +6 -4
- package/src/form/fields/{uri.js → uri.ts} +11 -6
- package/src/form/fields/{verbatim.js → verbatim.ts} +10 -5
- package/src/form/{index.js → index.ts} +113 -60
- package/src/form/{strings.js → strings.ts} +24 -22
- package/src/form/{templates.js → templates.ts} +14 -5
- package/src/global.d.ts +75 -0
- package/src/import/{bibliography_import.js → bibliography_import.ts} +42 -16
- package/src/import/{dialog.js → dialog.ts} +47 -23
- package/src/import/index.ts +14 -0
- package/src/import/{templates.js → templates.ts} +1 -1
- package/src/overview/{index.js → index.ts} +147 -79
- package/src/overview/{menu.js → menu.ts} +18 -12
- package/src/overview/{templates.js → templates.ts} +3 -2
- package/src/plugins/bibliography_overview/index.ts +1 -0
- package/src/schema/{literal_long.js → literal_long.ts} +3 -8
- package/src/schema/{title.js → title.ts} +1 -1
- package/src/{tools.js → tools.ts} +7 -5
- package/src/types/biblio.ts +189 -0
- package/src/database/server_connector.js +0 -57
- package/src/form/fields/name_list.js +0 -42
- package/src/import/index.js +0 -2
- package/src/plugins/bibliography_overview/index.js +0 -1
- /package/src/{index.js → index.ts} +0 -0
- /package/src/schema/{literal.js → literal.ts} +0 -0
|
@@ -1,7 +1,20 @@
|
|
|
1
1
|
import {sniffFormat} from "bibliojson"
|
|
2
2
|
import {addAlert, makeWorker} from "fwtoolkit"
|
|
3
|
+
import type {BibDBCollection, BibDBEntry, IdTranslation} from "../types/biblio.js"
|
|
3
4
|
|
|
4
|
-
|
|
5
|
+
interface ImportMessage {
|
|
6
|
+
type: string
|
|
7
|
+
errorCode?: string
|
|
8
|
+
errorType?: string
|
|
9
|
+
key?: string
|
|
10
|
+
type_name?: string
|
|
11
|
+
field_name?: string
|
|
12
|
+
entry?: string
|
|
13
|
+
data?: Record<number, BibDBEntry>
|
|
14
|
+
done?: boolean
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const ERROR_MSG: Record<string, string> = {
|
|
5
18
|
no_entries: gettext(
|
|
6
19
|
"No bibliography entries could be found in import file."
|
|
7
20
|
),
|
|
@@ -18,11 +31,17 @@ const ERROR_MSG = {
|
|
|
18
31
|
}
|
|
19
32
|
|
|
20
33
|
export class BibliographyImporter {
|
|
34
|
+
fileContents: string
|
|
35
|
+
bibDB: BibDBCollection
|
|
36
|
+
addToListCall: (ids: number[]) => void
|
|
37
|
+
callback: (() => void) | false | undefined
|
|
38
|
+
showAlerts: boolean
|
|
39
|
+
|
|
21
40
|
constructor(
|
|
22
|
-
fileContents,
|
|
23
|
-
bibDB,
|
|
24
|
-
addToListCall,
|
|
25
|
-
callback,
|
|
41
|
+
fileContents: string,
|
|
42
|
+
bibDB: BibDBCollection,
|
|
43
|
+
addToListCall: (ids: number[]) => void,
|
|
44
|
+
callback: (() => void) | false | undefined,
|
|
26
45
|
showAlerts = true
|
|
27
46
|
) {
|
|
28
47
|
this.fileContents = fileContents
|
|
@@ -32,7 +51,7 @@ export class BibliographyImporter {
|
|
|
32
51
|
this.showAlerts = showAlerts
|
|
33
52
|
}
|
|
34
53
|
|
|
35
|
-
init() {
|
|
54
|
+
init(): void {
|
|
36
55
|
// Detect the format of the input file
|
|
37
56
|
const format = sniffFormat(this.fileContents)
|
|
38
57
|
|
|
@@ -50,19 +69,20 @@ export class BibliographyImporter {
|
|
|
50
69
|
const importWorker = makeWorker(
|
|
51
70
|
staticUrl("js/bibliography_import_worker.js")
|
|
52
71
|
)
|
|
53
|
-
importWorker.onmessage = message => this.onMessage(message.data)
|
|
72
|
+
importWorker.onmessage = message => this.onMessage(message.data as ImportMessage)
|
|
54
73
|
importWorker.postMessage({
|
|
55
74
|
fileContents: this.fileContents,
|
|
56
75
|
format: format
|
|
57
76
|
})
|
|
58
77
|
}
|
|
59
78
|
|
|
60
|
-
onMessage(message) {
|
|
61
|
-
let errorMsg
|
|
79
|
+
onMessage(message: ImportMessage): void {
|
|
80
|
+
let errorMsg: string | undefined
|
|
81
|
+
let data: Record<number, BibDBEntry> | undefined
|
|
62
82
|
switch (message.type) {
|
|
63
83
|
case "error":
|
|
64
84
|
case "warning":
|
|
65
|
-
errorMsg = ERROR_MSG[message.errorCode]
|
|
85
|
+
errorMsg = ERROR_MSG[message.errorCode || ""]
|
|
66
86
|
if (!errorMsg) {
|
|
67
87
|
errorMsg = gettext(
|
|
68
88
|
"There was an issue with the bibliography import"
|
|
@@ -84,20 +104,26 @@ export class BibliographyImporter {
|
|
|
84
104
|
errorMsg += `, entry: ${message.entry}`
|
|
85
105
|
}
|
|
86
106
|
if (this.showAlerts) {
|
|
87
|
-
addAlert(message.type, errorMsg)
|
|
107
|
+
addAlert(message.type as "error" | "warning", errorMsg)
|
|
88
108
|
}
|
|
89
109
|
break
|
|
90
110
|
case "data":
|
|
91
111
|
data = message.data
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
112
|
+
if (data) {
|
|
113
|
+
this.bibDB.saveBibEntries(data, true).then(
|
|
114
|
+
(idTranslations: IdTranslation[]) => {
|
|
115
|
+
const newIds = idTranslations.map(
|
|
116
|
+
idTrans => idTrans[1]
|
|
117
|
+
)
|
|
118
|
+
this.addToListCall(newIds)
|
|
119
|
+
}
|
|
120
|
+
)
|
|
121
|
+
}
|
|
96
122
|
break
|
|
97
123
|
default:
|
|
98
124
|
break
|
|
99
125
|
}
|
|
100
|
-
if (message.done && this.callback) {
|
|
126
|
+
if (message.done && this.callback && typeof this.callback === "function") {
|
|
101
127
|
this.callback()
|
|
102
128
|
}
|
|
103
129
|
}
|
|
@@ -1,18 +1,35 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Dialog,
|
|
3
|
+
activateWait,
|
|
4
|
+
addAlert,
|
|
5
|
+
deactivateWait
|
|
6
|
+
} from "fwtoolkit"
|
|
7
|
+
import type {DialogButtonSpec} from "fwtoolkit/dialog"
|
|
2
8
|
import {importBibFileTemplate} from "./templates.js"
|
|
9
|
+
import type {BibliographyApp, BibDBCollection} from "../types/biblio.js"
|
|
10
|
+
|
|
3
11
|
/** First step of the bibliography file import. Creates a dialog box to specify upload file.
|
|
4
12
|
* Supports multiple formats: BibTeX/BibLaTeX, CSL-JSON, RIS, EndNote, Citavi, NBIB, ODT/DOCX citations.
|
|
5
13
|
*/
|
|
6
14
|
|
|
7
15
|
export class BibliographyFileImportDialog {
|
|
8
|
-
|
|
16
|
+
bibDB: BibDBCollection
|
|
17
|
+
addToListCall: (ids: number[]) => void
|
|
18
|
+
tmpDB: boolean
|
|
19
|
+
app: BibliographyApp
|
|
20
|
+
|
|
21
|
+
constructor(
|
|
22
|
+
bibDB: BibDBCollection,
|
|
23
|
+
addToListCall: (ids: number[]) => void,
|
|
24
|
+
app: BibliographyApp
|
|
25
|
+
) {
|
|
9
26
|
this.bibDB = bibDB
|
|
10
27
|
this.addToListCall = addToListCall
|
|
11
28
|
this.tmpDB = false
|
|
12
29
|
this.app = app
|
|
13
30
|
}
|
|
14
31
|
|
|
15
|
-
init() {
|
|
32
|
+
init(): void {
|
|
16
33
|
if (this.app.isOffline()) {
|
|
17
34
|
addAlert(
|
|
18
35
|
"info",
|
|
@@ -22,16 +39,18 @@ export class BibliographyFileImportDialog {
|
|
|
22
39
|
)
|
|
23
40
|
return
|
|
24
41
|
}
|
|
25
|
-
const buttons = [
|
|
42
|
+
const buttons: DialogButtonSpec[] = [
|
|
26
43
|
{
|
|
27
44
|
text: gettext("Import"),
|
|
28
45
|
classes: "fw-dark submit-import",
|
|
29
46
|
click: () => {
|
|
30
|
-
|
|
31
|
-
|
|
47
|
+
const bibFiles = (document.getElementById(
|
|
48
|
+
"bib-uploader"
|
|
49
|
+
) as HTMLInputElement | null)?.files
|
|
50
|
+
if (!bibFiles || 0 === bibFiles.length) {
|
|
32
51
|
return false
|
|
33
52
|
}
|
|
34
|
-
bibFile =
|
|
53
|
+
const bibFile = bibFiles[0]
|
|
35
54
|
if (10485760 < bibFile.size) {
|
|
36
55
|
return false
|
|
37
56
|
}
|
|
@@ -51,7 +70,7 @@ export class BibliographyFileImportDialog {
|
|
|
51
70
|
import("./bibliography_import.js").then(
|
|
52
71
|
({BibliographyImporter}) => {
|
|
53
72
|
const importer = new BibliographyImporter(
|
|
54
|
-
event.target.result,
|
|
73
|
+
(event.target as FileReader).result as string,
|
|
55
74
|
this.bibDB,
|
|
56
75
|
this.addToListCall,
|
|
57
76
|
() => deactivateWait()
|
|
@@ -62,6 +81,7 @@ export class BibliographyFileImportDialog {
|
|
|
62
81
|
}
|
|
63
82
|
reader.readAsText(bibFile)
|
|
64
83
|
dialog.close()
|
|
84
|
+
return false
|
|
65
85
|
}
|
|
66
86
|
},
|
|
67
87
|
{
|
|
@@ -76,20 +96,24 @@ export class BibliographyFileImportDialog {
|
|
|
76
96
|
buttons
|
|
77
97
|
})
|
|
78
98
|
dialog.open()
|
|
79
|
-
document
|
|
80
|
-
|
|
81
|
-
.addEventListener(
|
|
82
|
-
|
|
83
|
-
()
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
document
|
|
90
|
-
|
|
91
|
-
.addEventListener("click", () =>
|
|
92
|
-
document.getElementById("bib-uploader")
|
|
93
|
-
|
|
99
|
+
const uploader = document.getElementById("bib-uploader")
|
|
100
|
+
if (uploader) {
|
|
101
|
+
uploader.addEventListener("change", () => {
|
|
102
|
+
const input = uploader as HTMLInputElement
|
|
103
|
+
const label = document.getElementById("import-bib-name")
|
|
104
|
+
if (label) {
|
|
105
|
+
label.innerHTML = input.value.replace(/C:\\fakepath\\/i, "")
|
|
106
|
+
}
|
|
107
|
+
})
|
|
108
|
+
}
|
|
109
|
+
const importBtn = document.getElementById("import-bib-btn")
|
|
110
|
+
if (importBtn) {
|
|
111
|
+
importBtn.addEventListener("click", () => {
|
|
112
|
+
const input = document.getElementById("bib-uploader")
|
|
113
|
+
if (input) {
|
|
114
|
+
input.click()
|
|
115
|
+
}
|
|
116
|
+
})
|
|
117
|
+
}
|
|
94
118
|
}
|
|
95
119
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {BibliographyFileImportDialog} from "./dialog.js"
|
|
2
|
+
export {BibliographyFileImportDialog} from "./dialog.js"
|
|
3
|
+
export {BibliographyImporter} from "./bibliography_import.js"
|
|
4
|
+
|
|
5
|
+
import type {BibliographyApp, BibDBCollection} from "../types/biblio.js"
|
|
6
|
+
|
|
7
|
+
export function importBibFile(
|
|
8
|
+
bibDB: BibDBCollection,
|
|
9
|
+
addToListCall: (ids: number[]) => void,
|
|
10
|
+
app: BibliographyApp
|
|
11
|
+
): void {
|
|
12
|
+
const dialog = new BibliographyFileImportDialog(bibDB, addToListCall, app)
|
|
13
|
+
dialog.init()
|
|
14
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** a template for the bibliography file import dialog */
|
|
2
|
-
export const importBibFileTemplate = () =>
|
|
2
|
+
export const importBibFileTemplate = (): string =>
|
|
3
3
|
`<form id="import-bib-form" method="post" enctype="multipart/form-data" class="ajax-upload">
|
|
4
4
|
<input type="file" id="bib-uploader" name="bib" required />
|
|
5
5
|
<span id="import-bib-btn" class="fw-button fw-light fw-large">
|