@fiduswriter/bibliography-manager 0.1.6 → 0.1.8
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/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 -27
- package/dist/overview/index.d.ts.map +1 -1
- package/dist/overview/index.js +59 -23
- 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 +1 -1
- 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} +150 -81
- 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,6 +1,23 @@
|
|
|
1
1
|
import {BibFieldTypes, BibTypes} from "bibliojson"
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
Dialog,
|
|
4
|
+
DialogTabs,
|
|
5
|
+
InfoRow,
|
|
6
|
+
addAlert
|
|
7
|
+
} from "fwtoolkit"
|
|
8
|
+
import type {DialogButtonSpec} from "fwtoolkit/dialog"
|
|
3
9
|
import {dateToYear, litToText, nameToText} from "../tools.js"
|
|
10
|
+
import type {
|
|
11
|
+
BibDBCollection,
|
|
12
|
+
BibDBEntry,
|
|
13
|
+
BibliographyApp,
|
|
14
|
+
FieldForm,
|
|
15
|
+
FieldFormConstructor,
|
|
16
|
+
FieldFormsMap,
|
|
17
|
+
FormValue,
|
|
18
|
+
IdTranslation,
|
|
19
|
+
NameDictObject
|
|
20
|
+
} from "../types/biblio.js"
|
|
4
21
|
import {CatsForm} from "./cats.js"
|
|
5
22
|
import {DateFieldForm} from "./fields/date.js"
|
|
6
23
|
import {KeyFieldForm} from "./fields/key.js"
|
|
@@ -22,32 +39,61 @@ import {
|
|
|
22
39
|
} from "./strings.js"
|
|
23
40
|
import {bibDialog} from "./templates.js"
|
|
24
41
|
|
|
25
|
-
const FIELD_FORMS = {
|
|
26
|
-
f_date: DateFieldForm,
|
|
27
|
-
f_integer: LiteralFieldForm,
|
|
28
|
-
f_literal: LiteralFieldForm,
|
|
29
|
-
l_literal: LiteralListForm,
|
|
30
|
-
f_long_literal: LiteralLongFieldForm,
|
|
31
|
-
f_key: KeyFieldForm,
|
|
32
|
-
l_key: KeyListForm,
|
|
33
|
-
l_name: NameListForm,
|
|
34
|
-
l_range: RangeListForm,
|
|
35
|
-
l_tag: TagListForm,
|
|
36
|
-
f_title: TitleFieldForm,
|
|
37
|
-
f_uri: URIFieldForm,
|
|
38
|
-
f_verbatim: VerbatimFieldForm
|
|
42
|
+
const FIELD_FORMS: FieldFormsMap = {
|
|
43
|
+
f_date: DateFieldForm as FieldFormConstructor,
|
|
44
|
+
f_integer: LiteralFieldForm as FieldFormConstructor,
|
|
45
|
+
f_literal: LiteralFieldForm as FieldFormConstructor,
|
|
46
|
+
l_literal: LiteralListForm as FieldFormConstructor,
|
|
47
|
+
f_long_literal: LiteralLongFieldForm as FieldFormConstructor,
|
|
48
|
+
f_key: KeyFieldForm as FieldFormConstructor,
|
|
49
|
+
l_key: KeyListForm as FieldFormConstructor,
|
|
50
|
+
l_name: NameListForm as FieldFormConstructor,
|
|
51
|
+
l_range: RangeListForm as FieldFormConstructor,
|
|
52
|
+
l_tag: TagListForm as FieldFormConstructor,
|
|
53
|
+
f_title: TitleFieldForm as FieldFormConstructor,
|
|
54
|
+
f_uri: URIFieldForm as FieldFormConstructor,
|
|
55
|
+
f_verbatim: VerbatimFieldForm as FieldFormConstructor
|
|
39
56
|
}
|
|
40
57
|
|
|
58
|
+
export {BibFieldHelp, BibFieldTitles, BibTypeTitles, getBibFieldTitle}
|
|
59
|
+
|
|
41
60
|
export class BibEntryForm {
|
|
42
|
-
|
|
61
|
+
bibDB: BibDBCollection
|
|
62
|
+
itemId: number | false
|
|
63
|
+
app: BibliographyApp | false
|
|
64
|
+
fields: Record<string, FieldForm>
|
|
65
|
+
currentValues: {
|
|
66
|
+
bib_type: string | false
|
|
67
|
+
cats: number[]
|
|
68
|
+
entry_key: string
|
|
69
|
+
fields: Record<string, unknown>
|
|
70
|
+
}
|
|
71
|
+
dialog?: Dialog
|
|
72
|
+
dialogHeader?: string
|
|
73
|
+
dialogTabs?: DialogTabs
|
|
74
|
+
catsForm?: CatsForm
|
|
75
|
+
entryKeyAutoGenerate = false
|
|
76
|
+
programmaticallySettingKey = false
|
|
77
|
+
lastAutoGeneratedKey: string | null = null
|
|
78
|
+
|
|
79
|
+
constructor(
|
|
80
|
+
bibDB: BibDBCollection,
|
|
81
|
+
app: BibliographyApp | false = false,
|
|
82
|
+
itemId: number | false = false
|
|
83
|
+
) {
|
|
43
84
|
this.bibDB = bibDB
|
|
44
85
|
this.itemId = itemId
|
|
45
86
|
this.app = app
|
|
46
87
|
this.fields = {}
|
|
47
|
-
this.currentValues = {
|
|
88
|
+
this.currentValues = {
|
|
89
|
+
bib_type: false,
|
|
90
|
+
cats: [],
|
|
91
|
+
entry_key: "",
|
|
92
|
+
fields: {}
|
|
93
|
+
}
|
|
48
94
|
}
|
|
49
95
|
|
|
50
|
-
init() {
|
|
96
|
+
init(): Promise<IdTranslation[] | void> {
|
|
51
97
|
if (this.app && this.app.isOffline()) {
|
|
52
98
|
// Diable the editing of main user bibliography , since Document bibliography is stored in Editor/Document.
|
|
53
99
|
addAlert(
|
|
@@ -74,9 +120,9 @@ export class BibEntryForm {
|
|
|
74
120
|
return this.createForm()
|
|
75
121
|
}
|
|
76
122
|
|
|
77
|
-
addDialogToDOM() {
|
|
123
|
+
addDialogToDOM(): Promise<IdTranslation[] | void> {
|
|
78
124
|
// Add form to DOM
|
|
79
|
-
const buttons = [
|
|
125
|
+
const buttons: DialogButtonSpec[] = [
|
|
80
126
|
{
|
|
81
127
|
type: "close"
|
|
82
128
|
}
|
|
@@ -89,7 +135,7 @@ export class BibEntryForm {
|
|
|
89
135
|
click: () => {
|
|
90
136
|
if (this.check()) {
|
|
91
137
|
const returnValue = this.save()
|
|
92
|
-
this.dialog
|
|
138
|
+
this.dialog!.close()
|
|
93
139
|
resolve(returnValue)
|
|
94
140
|
}
|
|
95
141
|
}
|
|
@@ -106,7 +152,7 @@ export class BibEntryForm {
|
|
|
106
152
|
width: 940,
|
|
107
153
|
body: bibDialog({
|
|
108
154
|
bib_type: this.currentValues.bib_type,
|
|
109
|
-
BibTypes,
|
|
155
|
+
bibTypes: BibTypes,
|
|
110
156
|
hasCats
|
|
111
157
|
}),
|
|
112
158
|
buttons
|
|
@@ -138,11 +184,13 @@ export class BibEntryForm {
|
|
|
138
184
|
],
|
|
139
185
|
{containerId: "bib-dialog-tabs"}
|
|
140
186
|
)
|
|
141
|
-
this.dialogTabs
|
|
142
|
-
this.dialog.dialogEl.querySelector("#bib-dialog-tabs")
|
|
187
|
+
this.dialogTabs!.bind(
|
|
188
|
+
this.dialog.dialogEl.querySelector("#bib-dialog-tabs") as HTMLElement
|
|
143
189
|
)
|
|
144
190
|
|
|
145
|
-
const entryKeyInput = document.getElementById(
|
|
191
|
+
const entryKeyInput = document.getElementById(
|
|
192
|
+
"entry-key"
|
|
193
|
+
) as HTMLInputElement | null
|
|
146
194
|
if (entryKeyInput) {
|
|
147
195
|
entryKeyInput.value = this.currentValues.entry_key || ""
|
|
148
196
|
entryKeyInput.addEventListener("input", () => {
|
|
@@ -163,17 +211,16 @@ export class BibEntryForm {
|
|
|
163
211
|
})
|
|
164
212
|
}
|
|
165
213
|
|
|
166
|
-
document
|
|
167
|
-
.getElementById("select-bibtype")
|
|
214
|
+
;(document.getElementById("select-bibtype") as HTMLElement)
|
|
168
215
|
.addEventListener("change", () => resolve(this.changeBibType()))
|
|
169
216
|
})
|
|
170
217
|
}
|
|
171
218
|
|
|
172
|
-
addField(fieldName, dom) {
|
|
219
|
+
addField(fieldName: string, dom: HTMLElement): void {
|
|
173
220
|
const fieldType = BibFieldTypes[fieldName]
|
|
174
221
|
const fieldTitleText = getBibFieldTitle(
|
|
175
222
|
fieldName,
|
|
176
|
-
this.currentValues.bib_type
|
|
223
|
+
this.currentValues.bib_type || null
|
|
177
224
|
)
|
|
178
225
|
|
|
179
226
|
const row = new InfoRow({
|
|
@@ -182,7 +229,7 @@ export class BibEntryForm {
|
|
|
182
229
|
fieldClass: fieldName
|
|
183
230
|
})
|
|
184
231
|
dom.insertAdjacentHTML("beforeend", row.html())
|
|
185
|
-
const fieldDOM = dom.lastChild
|
|
232
|
+
const fieldDOM = dom.lastChild!.lastChild as HTMLElement
|
|
186
233
|
const FieldClass = FIELD_FORMS[fieldType.type]
|
|
187
234
|
if (FieldClass) {
|
|
188
235
|
const fieldHandler = new FieldClass(
|
|
@@ -196,22 +243,22 @@ export class BibEntryForm {
|
|
|
196
243
|
}
|
|
197
244
|
}
|
|
198
245
|
|
|
199
|
-
createForm() {
|
|
246
|
+
createForm(): Promise<IdTranslation[] | void> {
|
|
200
247
|
const dialogPromise = this.addDialogToDOM()
|
|
201
248
|
if (this.currentValues.bib_type !== false) {
|
|
202
|
-
const eitherOrFields = document.getElementById("eo-fields")
|
|
249
|
+
const eitherOrFields = document.getElementById("eo-fields")!
|
|
203
250
|
BibTypes[this.currentValues.bib_type].eitheror.forEach(
|
|
204
251
|
fieldName => {
|
|
205
252
|
this.addField(fieldName, eitherOrFields)
|
|
206
253
|
}
|
|
207
254
|
)
|
|
208
|
-
const reqFields = document.getElementById("req-fields")
|
|
255
|
+
const reqFields = document.getElementById("req-fields")!
|
|
209
256
|
BibTypes[this.currentValues.bib_type].required.forEach(
|
|
210
257
|
fieldName => {
|
|
211
258
|
this.addField(fieldName, reqFields)
|
|
212
259
|
}
|
|
213
260
|
)
|
|
214
|
-
const optFields = document.getElementById("opt-fields")
|
|
261
|
+
const optFields = document.getElementById("opt-fields")!
|
|
215
262
|
BibTypes[this.currentValues.bib_type].optional.forEach(
|
|
216
263
|
fieldName => {
|
|
217
264
|
this.addField(fieldName, optFields)
|
|
@@ -230,36 +277,36 @@ export class BibEntryForm {
|
|
|
230
277
|
return dialogPromise
|
|
231
278
|
}
|
|
232
279
|
|
|
233
|
-
changeBibType() {
|
|
280
|
+
changeBibType(): Promise<IdTranslation[] | void> {
|
|
234
281
|
// Add all current values into temporary currentValues, in case the
|
|
235
282
|
// user still wants them.
|
|
236
283
|
const formValue = this.value
|
|
237
284
|
Object.assign(this.currentValues.fields, formValue.fields)
|
|
238
|
-
this.currentValues.cats = formValue.cats
|
|
285
|
+
this.currentValues.cats = formValue.cats as number[]
|
|
239
286
|
this.currentValues.bib_type = formValue.bib_type
|
|
240
287
|
// Reset fields and close dialog.
|
|
241
288
|
this.fields = {}
|
|
242
|
-
this.dialog
|
|
289
|
+
this.dialog!.close()
|
|
243
290
|
return this.createForm()
|
|
244
291
|
}
|
|
245
292
|
|
|
246
|
-
createEntryKey(bibItem) {
|
|
293
|
+
createEntryKey(bibItem: FormValue): void {
|
|
247
294
|
// We attempt to create a biblatex compatible entry key if there is no entry
|
|
248
295
|
// key so far.
|
|
249
296
|
let entryKey = ""
|
|
250
297
|
if (bibItem.fields.author) {
|
|
251
|
-
entryKey += nameToText(bibItem.fields.author).replace(
|
|
252
|
-
/\s
|
|
298
|
+
entryKey += nameToText(bibItem.fields.author as NameDictObject[]).replace(
|
|
299
|
+
/\s|,|=|;|:|\{|}/g,
|
|
253
300
|
""
|
|
254
301
|
)
|
|
255
302
|
} else if (bibItem.fields.editor) {
|
|
256
|
-
entryKey += nameToText(bibItem.fields.editor).replace(
|
|
257
|
-
/\s
|
|
303
|
+
entryKey += nameToText(bibItem.fields.editor as NameDictObject[]).replace(
|
|
304
|
+
/\s|,|=|;|:|\{|}/g,
|
|
258
305
|
""
|
|
259
306
|
)
|
|
260
307
|
}
|
|
261
308
|
if (bibItem.fields.date) {
|
|
262
|
-
entryKey += bibItem.fields.date
|
|
309
|
+
entryKey += (bibItem.fields.date as string)
|
|
263
310
|
.split("/")[0]
|
|
264
311
|
.replace(/\?|\*|u|~|-/g, "")
|
|
265
312
|
}
|
|
@@ -268,11 +315,11 @@ export class BibEntryForm {
|
|
|
268
315
|
}
|
|
269
316
|
}
|
|
270
317
|
|
|
271
|
-
maybeAutoGenerateEntryKey() {
|
|
318
|
+
maybeAutoGenerateEntryKey(): void {
|
|
272
319
|
if (!this.entryKeyAutoGenerate) {
|
|
273
320
|
return
|
|
274
321
|
}
|
|
275
|
-
const input = document.getElementById("entry-key")
|
|
322
|
+
const input = document.getElementById("entry-key") as HTMLInputElement | null
|
|
276
323
|
if (!input) {
|
|
277
324
|
return
|
|
278
325
|
}
|
|
@@ -283,8 +330,12 @@ export class BibEntryForm {
|
|
|
283
330
|
|
|
284
331
|
let lastName = ""
|
|
285
332
|
const nameField = this.fields.author || this.fields.editor
|
|
286
|
-
if (
|
|
287
|
-
|
|
333
|
+
if (
|
|
334
|
+
nameField &&
|
|
335
|
+
nameField.value &&
|
|
336
|
+
(nameField.value as unknown[]).length
|
|
337
|
+
) {
|
|
338
|
+
const firstAuthor = (nameField.value as NameDictObject[])[0]
|
|
288
339
|
if (firstAuthor.family && firstAuthor.family.length) {
|
|
289
340
|
lastName = litToText(firstAuthor.family)
|
|
290
341
|
} else if (firstAuthor.literal && firstAuthor.literal.length) {
|
|
@@ -295,7 +346,7 @@ export class BibEntryForm {
|
|
|
295
346
|
|
|
296
347
|
let year = ""
|
|
297
348
|
if (this.fields.date && this.fields.date.value) {
|
|
298
|
-
const yearStr = dateToYear(this.fields.date.value)
|
|
349
|
+
const yearStr = dateToYear(this.fields.date.value as string)
|
|
299
350
|
const yearMatch = yearStr.match(/-?(\d+)/)
|
|
300
351
|
year = yearMatch ? yearMatch[1] : ""
|
|
301
352
|
}
|
|
@@ -311,7 +362,7 @@ export class BibEntryForm {
|
|
|
311
362
|
.filter(
|
|
312
363
|
([id]) =>
|
|
313
364
|
Number.parseInt(id) !==
|
|
314
|
-
Number.parseInt(this.itemId || 0)
|
|
365
|
+
Number.parseInt((this.itemId || 0) as unknown as string)
|
|
315
366
|
)
|
|
316
367
|
.map(([, entry]) => entry.entry_key)
|
|
317
368
|
)
|
|
@@ -337,8 +388,8 @@ export class BibEntryForm {
|
|
|
337
388
|
this.checkEntryKey()
|
|
338
389
|
}
|
|
339
390
|
|
|
340
|
-
checkEntryKey() {
|
|
341
|
-
const input = document.getElementById("entry-key")
|
|
391
|
+
checkEntryKey(): void {
|
|
392
|
+
const input = document.getElementById("entry-key") as HTMLInputElement | null
|
|
342
393
|
const warningEl = document.getElementById("entry-key-warning")
|
|
343
394
|
if (!input || !warningEl) {
|
|
344
395
|
return
|
|
@@ -359,7 +410,8 @@ export class BibEntryForm {
|
|
|
359
410
|
const duplicate = Object.entries(this.bibDB.db).find(
|
|
360
411
|
([id, entry]) =>
|
|
361
412
|
entry.entry_key === value &&
|
|
362
|
-
Number.parseInt(id) !==
|
|
413
|
+
Number.parseInt(id) !==
|
|
414
|
+
Number.parseInt((this.itemId || 0) as unknown as string)
|
|
363
415
|
)
|
|
364
416
|
if (duplicate) {
|
|
365
417
|
warningEl.textContent = gettext(
|
|
@@ -370,13 +422,14 @@ export class BibEntryForm {
|
|
|
370
422
|
}
|
|
371
423
|
}
|
|
372
424
|
|
|
373
|
-
get value() {
|
|
374
|
-
const entryKeyInput = document.querySelector("#entry-key")
|
|
425
|
+
get value(): FormValue {
|
|
426
|
+
const entryKeyInput = document.querySelector("#entry-key") as HTMLInputElement | null
|
|
375
427
|
const entryKey = entryKeyInput
|
|
376
428
|
? entryKeyInput.value.trim()
|
|
377
429
|
: this.currentValues.entry_key
|
|
378
|
-
const returnObj = {
|
|
379
|
-
bib_type: document.querySelector("#select-bibtype")
|
|
430
|
+
const returnObj: FormValue = {
|
|
431
|
+
bib_type: (document.querySelector("#select-bibtype") as HTMLSelectElement)
|
|
432
|
+
.value,
|
|
380
433
|
cats: this.catsForm ? this.catsForm.value : [],
|
|
381
434
|
entry_key: entryKey,
|
|
382
435
|
fields: {}
|
|
@@ -390,7 +443,7 @@ export class BibEntryForm {
|
|
|
390
443
|
return returnObj
|
|
391
444
|
}
|
|
392
445
|
|
|
393
|
-
save() {
|
|
446
|
+
save(): Promise<IdTranslation[]> {
|
|
394
447
|
const isNew = this.itemId === false ? true : false,
|
|
395
448
|
itemId = this.itemId === false ? 0 : this.itemId,
|
|
396
449
|
item = this.value
|
|
@@ -398,12 +451,12 @@ export class BibEntryForm {
|
|
|
398
451
|
if (!item.entry_key) {
|
|
399
452
|
this.createEntryKey(item)
|
|
400
453
|
}
|
|
401
|
-
const saveObj = {}
|
|
402
|
-
saveObj[itemId] = item
|
|
454
|
+
const saveObj: Record<number, BibDBEntry> = {}
|
|
455
|
+
saveObj[itemId] = item as unknown as BibDBEntry
|
|
403
456
|
return this.bibDB.saveBibEntries(saveObj, isNew)
|
|
404
457
|
}
|
|
405
458
|
|
|
406
|
-
check() {
|
|
459
|
+
check(): boolean {
|
|
407
460
|
let passed = true
|
|
408
461
|
if (!this.currentValues.bib_type) {
|
|
409
462
|
return false
|
|
@@ -8,14 +8,16 @@ import {
|
|
|
8
8
|
getOtherOptionTitle,
|
|
9
9
|
getTypeTitle
|
|
10
10
|
} from "bibliojson"
|
|
11
|
+
import type {Locale} from "bibliojson"
|
|
12
|
+
import type {BibFieldType} from "../types/biblio.js"
|
|
11
13
|
|
|
12
14
|
// Cache for the current locale to avoid repeated lookups
|
|
13
|
-
let cachedLocale = null
|
|
14
|
-
let cachedLang = null
|
|
15
|
+
let cachedLocale: Locale | null = null
|
|
16
|
+
let cachedLang: string | null = null
|
|
15
17
|
|
|
16
|
-
function getCachedLocale() {
|
|
18
|
+
function getCachedLocale(): Locale {
|
|
17
19
|
const lang = document.documentElement.lang || "en"
|
|
18
|
-
if (lang !== cachedLang) {
|
|
20
|
+
if (lang !== cachedLang || !cachedLocale) {
|
|
19
21
|
cachedLocale = getLocale(lang)
|
|
20
22
|
cachedLang = lang
|
|
21
23
|
}
|
|
@@ -23,13 +25,13 @@ function getCachedLocale() {
|
|
|
23
25
|
}
|
|
24
26
|
|
|
25
27
|
// Dynamic field title getter that uses bibliojson's i18n
|
|
26
|
-
export function getBibFieldTitle(fieldKey, bibType = null) {
|
|
28
|
+
export function getBibFieldTitle(fieldKey: string, bibType: string | null = null): string {
|
|
27
29
|
const locale = getCachedLocale()
|
|
28
30
|
if (bibType && BibTypes[bibType]) {
|
|
29
31
|
return getFieldTitle(locale, bibType, fieldKey)
|
|
30
32
|
}
|
|
31
33
|
// Fallback to generic field title
|
|
32
|
-
const fieldType = BibFieldTypes[fieldKey]
|
|
34
|
+
const fieldType = BibFieldTypes[fieldKey] as BibFieldType
|
|
33
35
|
if (fieldType && fieldType.title) {
|
|
34
36
|
return fieldType.title
|
|
35
37
|
}
|
|
@@ -37,25 +39,25 @@ export function getBibFieldTitle(fieldKey, bibType = null) {
|
|
|
37
39
|
}
|
|
38
40
|
|
|
39
41
|
// Dynamic type title getter
|
|
40
|
-
export function getBibTypeTitle(typeKey) {
|
|
42
|
+
export function getBibTypeTitle(typeKey: string): string {
|
|
41
43
|
const locale = getCachedLocale()
|
|
42
44
|
return getTypeTitle(locale, typeKey)
|
|
43
45
|
}
|
|
44
46
|
|
|
45
47
|
// Dynamic field help getter
|
|
46
|
-
export function getBibFieldHelp(fieldKey) {
|
|
48
|
+
export function getBibFieldHelp(fieldKey: string): string | undefined {
|
|
47
49
|
const locale = getCachedLocale()
|
|
48
50
|
return getFieldHelp(locale, fieldKey)
|
|
49
51
|
}
|
|
50
52
|
|
|
51
53
|
// Dynamic option title getter (for editortype, pagination, pubstate, etc.)
|
|
52
|
-
export function getBibOptionTitle(optionKey) {
|
|
54
|
+
export function getBibOptionTitle(optionKey: string): string {
|
|
53
55
|
const locale = getCachedLocale()
|
|
54
56
|
return getOtherOptionTitle(locale, optionKey)
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
// Dynamic langid title getter
|
|
58
|
-
export function getBibLangidTitle(langidKey) {
|
|
60
|
+
export function getBibLangidTitle(langidKey: string): string {
|
|
59
61
|
const locale = getCachedLocale()
|
|
60
62
|
return getLangidTitle(locale, langidKey)
|
|
61
63
|
}
|
|
@@ -63,45 +65,45 @@ export function getBibLangidTitle(langidKey) {
|
|
|
63
65
|
// For backward compatibility, create proxy objects that dynamically return translations
|
|
64
66
|
// These should be used sparingly - prefer using the function versions above
|
|
65
67
|
export const BibFieldTitles = new Proxy(
|
|
66
|
-
{},
|
|
68
|
+
{} as Record<string, string>,
|
|
67
69
|
{
|
|
68
70
|
get(_target, prop) {
|
|
69
|
-
return getBibFieldTitle(prop)
|
|
71
|
+
return getBibFieldTitle(String(prop))
|
|
70
72
|
}
|
|
71
73
|
}
|
|
72
74
|
)
|
|
73
75
|
|
|
74
76
|
export const BibTypeTitles = new Proxy(
|
|
75
|
-
{},
|
|
77
|
+
{} as Record<string, string>,
|
|
76
78
|
{
|
|
77
79
|
get(_target, prop) {
|
|
78
|
-
return getBibTypeTitle(prop)
|
|
80
|
+
return getBibTypeTitle(String(prop))
|
|
79
81
|
}
|
|
80
82
|
}
|
|
81
83
|
)
|
|
82
84
|
|
|
83
85
|
export const BibFieldHelp = new Proxy(
|
|
84
|
-
{},
|
|
86
|
+
{} as Record<string, string | undefined>,
|
|
85
87
|
{
|
|
86
88
|
get(_target, prop) {
|
|
87
|
-
return getBibFieldHelp(prop)
|
|
89
|
+
return getBibFieldHelp(String(prop))
|
|
88
90
|
}
|
|
89
91
|
}
|
|
90
92
|
)
|
|
91
93
|
|
|
92
94
|
export const BibOptionTitles = new Proxy(
|
|
93
|
-
{},
|
|
95
|
+
{} as Record<string, string>,
|
|
94
96
|
{
|
|
95
97
|
get(_target, prop) {
|
|
96
|
-
return getBibOptionTitle(prop)
|
|
98
|
+
return getBibOptionTitle(String(prop))
|
|
97
99
|
}
|
|
98
100
|
}
|
|
99
101
|
)
|
|
100
102
|
|
|
101
103
|
// Export a function to get all type titles as an object (for templates that need to map all types)
|
|
102
|
-
export function getAllTypeTitles() {
|
|
104
|
+
export function getAllTypeTitles(): Record<string, string> {
|
|
103
105
|
const locale = getCachedLocale()
|
|
104
|
-
const titles = {}
|
|
106
|
+
const titles: Record<string, string> = {}
|
|
105
107
|
Object.keys(BibTypes).forEach(typeKey => {
|
|
106
108
|
titles[typeKey] = getTypeTitle(locale, typeKey)
|
|
107
109
|
})
|
|
@@ -109,9 +111,9 @@ export function getAllTypeTitles() {
|
|
|
109
111
|
}
|
|
110
112
|
|
|
111
113
|
// Export a function to get all field help texts
|
|
112
|
-
export function getAllFieldHelp() {
|
|
114
|
+
export function getAllFieldHelp(): Record<string, string> {
|
|
113
115
|
const locale = getCachedLocale()
|
|
114
|
-
const help = {}
|
|
116
|
+
const help: Record<string, string> = {}
|
|
115
117
|
Object.keys(BibFieldTypes).forEach(fieldKey => {
|
|
116
118
|
const helpText = getFieldHelp(locale, fieldKey)
|
|
117
119
|
if (helpText) {
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
/** A template for the bibliography item edit dialog. */
|
|
2
2
|
import {DialogTabs} from "fwtoolkit"
|
|
3
|
+
import {BibTypes} from "bibliojson"
|
|
3
4
|
import {getAllTypeTitles} from "./strings.js"
|
|
4
5
|
|
|
5
|
-
const requiredFieldsTemplate = () =>
|
|
6
|
+
const requiredFieldsTemplate = (): string =>
|
|
6
7
|
`<table class="fw-dialog-table"><tbody id="eo-fields"></tbody></table>
|
|
7
8
|
<table class="fw-dialog-table"><tbody id="req-fields"></tbody></table>`
|
|
8
9
|
|
|
9
|
-
const optionalFieldsTemplate = () =>
|
|
10
|
+
const optionalFieldsTemplate = (): string =>
|
|
10
11
|
`<table class="fw-dialog-table"><tbody id="opt-fields"></tbody></table>`
|
|
11
12
|
|
|
12
|
-
const categoriesTemplate = () =>
|
|
13
|
+
const categoriesTemplate = (): string =>
|
|
13
14
|
`<table class="fw-dialog-table">
|
|
14
15
|
<tbody>
|
|
15
16
|
<tr>
|
|
@@ -19,7 +20,15 @@ const categoriesTemplate = () =>
|
|
|
19
20
|
</tbody>
|
|
20
21
|
</table>`
|
|
21
22
|
|
|
22
|
-
export const bibDialog = ({
|
|
23
|
+
export const bibDialog = ({
|
|
24
|
+
bib_type,
|
|
25
|
+
bibTypes,
|
|
26
|
+
hasCats
|
|
27
|
+
}: {
|
|
28
|
+
bib_type: string | false
|
|
29
|
+
bibTypes: typeof BibTypes
|
|
30
|
+
hasCats: boolean
|
|
31
|
+
}): string => {
|
|
23
32
|
const typeTitles = getAllTypeTitles()
|
|
24
33
|
const tabs = [
|
|
25
34
|
{
|
|
@@ -49,7 +58,7 @@ export const bibDialog = ({bib_type, BibTypes, hasCats}) => {
|
|
|
49
58
|
? `<option class="fw-placeholder" selected disabled value="">${gettext("Select source type")}</option>`
|
|
50
59
|
: ""
|
|
51
60
|
}
|
|
52
|
-
${Object.keys(
|
|
61
|
+
${Object.keys(bibTypes)
|
|
53
62
|
.map(
|
|
54
63
|
key =>
|
|
55
64
|
`<option value="${key}"
|
package/src/global.d.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// Ambient declarations for dependencies without bundled types.
|
|
2
|
+
|
|
3
|
+
declare module "tokenfield" {
|
|
4
|
+
export interface TokenFieldItem {
|
|
5
|
+
id: number
|
|
6
|
+
name: string
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface TokenFieldOptions {
|
|
10
|
+
el: HTMLInputElement
|
|
11
|
+
setItems?: TokenFieldItem[]
|
|
12
|
+
keys?: Record<number, string>
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default class TokenField {
|
|
16
|
+
constructor(options: TokenFieldOptions)
|
|
17
|
+
getItems(): TokenFieldItem[]
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
declare module "fix-utf8" {
|
|
22
|
+
function fixUTF8(str: string): string
|
|
23
|
+
export default fixUTF8
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
declare module "downloadjs" {
|
|
27
|
+
function download(
|
|
28
|
+
data: Blob | string,
|
|
29
|
+
filename: string,
|
|
30
|
+
mimeType?: string
|
|
31
|
+
): void
|
|
32
|
+
export default download
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
declare module "fwtoolkit/file/zip" {
|
|
36
|
+
export interface ZipFileSpec {
|
|
37
|
+
filename: string
|
|
38
|
+
contents: string
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export class ZipFileCreator {
|
|
42
|
+
constructor(files: ZipFileSpec[])
|
|
43
|
+
init(): Promise<Blob>
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
declare module "@fiduswriter/common" {
|
|
48
|
+
export function baseBodyTemplate(...args: unknown[]): string
|
|
49
|
+
export class FeedbackTab {
|
|
50
|
+
init(): void
|
|
51
|
+
}
|
|
52
|
+
export class SiteMenu {
|
|
53
|
+
constructor(app: unknown, section: string)
|
|
54
|
+
init(): void
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Globals provided by the Fidus Writer host page.
|
|
59
|
+
|
|
60
|
+
declare function gettext(msgid: string): string
|
|
61
|
+
|
|
62
|
+
declare function interpolate(
|
|
63
|
+
fmt: string,
|
|
64
|
+
args: unknown[],
|
|
65
|
+
named?: boolean
|
|
66
|
+
): string
|
|
67
|
+
|
|
68
|
+
declare function staticUrl(path: string): string
|
|
69
|
+
|
|
70
|
+
declare const settings: Record<string, unknown>
|
|
71
|
+
|
|
72
|
+
interface Window {
|
|
73
|
+
settings?: Record<string, unknown>
|
|
74
|
+
csrfToken?: string
|
|
75
|
+
}
|