@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.
Files changed (176) hide show
  1. package/README.md +53 -12
  2. package/dist/database/index.d.ts +12 -11
  3. package/dist/database/index.d.ts.map +1 -1
  4. package/dist/database/index.js +22 -16
  5. package/dist/database/index.js.map +1 -1
  6. package/dist/database/server_connector.d.ts +14 -15
  7. package/dist/database/server_connector.d.ts.map +1 -1
  8. package/dist/database/server_connector.js +17 -9
  9. package/dist/database/server_connector.js.map +1 -1
  10. package/dist/export/index.d.ts +6 -4
  11. package/dist/export/index.d.ts.map +1 -1
  12. package/dist/export/index.js +7 -1
  13. package/dist/export/index.js.map +1 -1
  14. package/dist/form/cats.d.ts +5 -4
  15. package/dist/form/cats.d.ts.map +1 -1
  16. package/dist/form/cats.js +2 -0
  17. package/dist/form/cats.js.map +1 -1
  18. package/dist/form/fields/date.d.ts +4 -4
  19. package/dist/form/fields/date.d.ts.map +1 -1
  20. package/dist/form/fields/date.js +5 -1
  21. package/dist/form/fields/date.js.map +1 -1
  22. package/dist/form/fields/key.d.ts +11 -9
  23. package/dist/form/fields/key.d.ts.map +1 -1
  24. package/dist/form/fields/key.js +13 -6
  25. package/dist/form/fields/key.js.map +1 -1
  26. package/dist/form/fields/key_list.d.ts +10 -8
  27. package/dist/form/fields/key_list.d.ts.map +1 -1
  28. package/dist/form/fields/key_list.js +4 -0
  29. package/dist/form/fields/key_list.js.map +1 -1
  30. package/dist/form/fields/literal.d.ts +4 -4
  31. package/dist/form/fields/literal.d.ts.map +1 -1
  32. package/dist/form/fields/literal.js +2 -1
  33. package/dist/form/fields/literal.js.map +1 -1
  34. package/dist/form/fields/literal_list.d.ts +8 -7
  35. package/dist/form/fields/literal_list.d.ts.map +1 -1
  36. package/dist/form/fields/literal_list.js +3 -0
  37. package/dist/form/fields/literal_list.js.map +1 -1
  38. package/dist/form/fields/literal_long.d.ts +4 -4
  39. package/dist/form/fields/literal_long.d.ts.map +1 -1
  40. package/dist/form/fields/literal_long.js +1 -0
  41. package/dist/form/fields/literal_long.js.map +1 -1
  42. package/dist/form/fields/name.d.ts +10 -27
  43. package/dist/form/fields/name.d.ts.map +1 -1
  44. package/dist/form/fields/name.js +22 -18
  45. package/dist/form/fields/name.js.map +1 -1
  46. package/dist/form/fields/name_list.d.ts +9 -7
  47. package/dist/form/fields/name_list.d.ts.map +1 -1
  48. package/dist/form/fields/name_list.js +5 -2
  49. package/dist/form/fields/name_list.js.map +1 -1
  50. package/dist/form/fields/range.d.ts +10 -8
  51. package/dist/form/fields/range.d.ts.map +1 -1
  52. package/dist/form/fields/range.js +13 -9
  53. package/dist/form/fields/range.js.map +1 -1
  54. package/dist/form/fields/range_list.d.ts +9 -7
  55. package/dist/form/fields/range_list.d.ts.map +1 -1
  56. package/dist/form/fields/range_list.js +3 -0
  57. package/dist/form/fields/range_list.js.map +1 -1
  58. package/dist/form/fields/tag_list.d.ts +7 -6
  59. package/dist/form/fields/tag_list.d.ts.map +1 -1
  60. package/dist/form/fields/tag_list.js +3 -0
  61. package/dist/form/fields/tag_list.js.map +1 -1
  62. package/dist/form/fields/title.d.ts +4 -4
  63. package/dist/form/fields/title.d.ts.map +1 -1
  64. package/dist/form/fields/title.js +1 -0
  65. package/dist/form/fields/title.js.map +1 -1
  66. package/dist/form/fields/uri.d.ts +4 -4
  67. package/dist/form/fields/uri.d.ts.map +1 -1
  68. package/dist/form/fields/uri.js +5 -1
  69. package/dist/form/fields/uri.js.map +1 -1
  70. package/dist/form/fields/verbatim.d.ts +4 -4
  71. package/dist/form/fields/verbatim.d.ts.map +1 -1
  72. package/dist/form/fields/verbatim.js +5 -1
  73. package/dist/form/fields/verbatim.js.map +1 -1
  74. package/dist/form/index.d.ts +32 -30
  75. package/dist/form/index.d.ts.map +1 -1
  76. package/dist/form/index.js +33 -11
  77. package/dist/form/index.js.map +1 -1
  78. package/dist/form/strings.d.ts +11 -11
  79. package/dist/form/strings.d.ts.map +1 -1
  80. package/dist/form/strings.js +5 -5
  81. package/dist/form/strings.js.map +1 -1
  82. package/dist/form/templates.d.ts +6 -5
  83. package/dist/form/templates.d.ts.map +1 -1
  84. package/dist/form/templates.js +2 -2
  85. package/dist/form/templates.js.map +1 -1
  86. package/dist/import/bibliography_import.d.ts +20 -7
  87. package/dist/import/bibliography_import.d.ts.map +1 -1
  88. package/dist/import/bibliography_import.js +15 -7
  89. package/dist/import/bibliography_import.js.map +1 -1
  90. package/dist/import/dialog.d.ts +6 -5
  91. package/dist/import/dialog.d.ts.map +1 -1
  92. package/dist/import/dialog.js +27 -12
  93. package/dist/import/dialog.js.map +1 -1
  94. package/dist/import/index.d.ts +2 -0
  95. package/dist/import/index.d.ts.map +1 -1
  96. package/dist/import/index.js +5 -0
  97. package/dist/import/index.js.map +1 -1
  98. package/dist/import/templates.d.ts +2 -1
  99. package/dist/import/templates.d.ts.map +1 -1
  100. package/dist/import/templates.js.map +1 -1
  101. package/dist/index.d.ts +2 -0
  102. package/dist/index.d.ts.map +1 -1
  103. package/dist/index.js.map +1 -1
  104. package/dist/overview/index.d.ts +43 -28
  105. package/dist/overview/index.d.ts.map +1 -1
  106. package/dist/overview/index.js +55 -20
  107. package/dist/overview/index.js.map +1 -1
  108. package/dist/overview/menu.d.ts +13 -12
  109. package/dist/overview/menu.d.ts.map +1 -1
  110. package/dist/overview/menu.js +13 -10
  111. package/dist/overview/menu.js.map +1 -1
  112. package/dist/overview/templates.d.ts +5 -3
  113. package/dist/overview/templates.d.ts.map +1 -1
  114. package/dist/overview/templates.js.map +1 -1
  115. package/dist/plugins/bibliography_overview/index.d.ts +1 -1
  116. package/dist/plugins/bibliography_overview/index.d.ts.map +1 -1
  117. package/dist/plugins/bibliography_overview/index.js.map +1 -1
  118. package/dist/schema/csl_bib.d.ts +1 -1
  119. package/dist/schema/literal.d.ts +1 -1
  120. package/dist/schema/literal.d.ts.map +1 -1
  121. package/dist/schema/literal.js.map +1 -1
  122. package/dist/schema/literal_long.d.ts +1 -1
  123. package/dist/schema/literal_long.d.ts.map +1 -1
  124. package/dist/schema/literal_long.js +1 -7
  125. package/dist/schema/literal_long.js.map +1 -1
  126. package/dist/schema/title.d.ts +1 -1
  127. package/dist/schema/title.d.ts.map +1 -1
  128. package/dist/schema/title.js.map +1 -1
  129. package/dist/tools.d.ts +4 -3
  130. package/dist/tools.d.ts.map +1 -1
  131. package/dist/tools.js.map +1 -1
  132. package/dist/types/biblio.d.ts +138 -0
  133. package/dist/types/biblio.d.ts.map +1 -0
  134. package/dist/types/biblio.js +2 -0
  135. package/dist/types/biblio.js.map +1 -0
  136. package/package.json +88 -74
  137. package/src/database/{index.js → index.ts} +60 -38
  138. package/src/database/server_connector.ts +92 -0
  139. package/src/export/{index.js → index.ts} +16 -4
  140. package/src/form/{cats.js → cats.ts} +11 -3
  141. package/src/form/fields/{date.js → date.ts} +10 -5
  142. package/src/form/fields/{key.js → key.ts} +37 -19
  143. package/src/form/fields/{key_list.js → key_list.ts} +18 -7
  144. package/src/form/fields/{literal.js → literal.ts} +11 -5
  145. package/src/form/fields/{literal_list.js → literal_list.ts} +19 -10
  146. package/src/form/fields/{literal_long.js → literal_long.ts} +6 -4
  147. package/src/form/fields/{name.js → name.ts} +53 -39
  148. package/src/form/fields/name_list.ts +49 -0
  149. package/src/form/fields/{range.js → range.ts} +34 -22
  150. package/src/form/fields/{range_list.js → range_list.ts} +17 -10
  151. package/src/form/fields/{tag_list.js → tag_list.ts} +9 -5
  152. package/src/form/fields/{title.js → title.ts} +6 -4
  153. package/src/form/fields/{uri.js → uri.ts} +11 -6
  154. package/src/form/fields/{verbatim.js → verbatim.ts} +10 -5
  155. package/src/form/{index.js → index.ts} +113 -60
  156. package/src/form/{strings.js → strings.ts} +24 -22
  157. package/src/form/{templates.js → templates.ts} +14 -5
  158. package/src/global.d.ts +75 -0
  159. package/src/import/{bibliography_import.js → bibliography_import.ts} +42 -16
  160. package/src/import/{dialog.js → dialog.ts} +47 -23
  161. package/src/import/index.ts +14 -0
  162. package/src/import/{templates.js → templates.ts} +1 -1
  163. package/src/overview/{index.js → index.ts} +147 -79
  164. package/src/overview/{menu.js → menu.ts} +18 -12
  165. package/src/overview/{templates.js → templates.ts} +3 -2
  166. package/src/plugins/bibliography_overview/index.ts +1 -0
  167. package/src/schema/{literal_long.js → literal_long.ts} +3 -8
  168. package/src/schema/{title.js → title.ts} +1 -1
  169. package/src/{tools.js → tools.ts} +7 -5
  170. package/src/types/biblio.ts +189 -0
  171. package/src/database/server_connector.js +0 -57
  172. package/src/form/fields/name_list.js +0 -42
  173. package/src/import/index.js +0 -2
  174. package/src/plugins/bibliography_overview/index.js +0 -1
  175. /package/src/{index.js → index.ts} +0 -0
  176. /package/src/schema/{literal.js → literal.ts} +0 -0
@@ -1,10 +1,23 @@
1
1
  import {activateWait, addAlert, deactivateWait} from "fwtoolkit"
2
2
  import {BibliographyDBServerConnector} from "./server_connector.js"
3
+ import type {
4
+ BibCategory,
5
+ BibDBEntry,
6
+ BibliographyApp,
7
+ IdTranslation,
8
+ SaveCategoriesRequest,
9
+ ServerBibItem
10
+ } from "../types/biblio.js"
3
11
 
4
12
  const FW_LOCALSTORAGE_VERSION = "1.2"
5
13
 
6
14
  export class BibliographyDB {
7
- constructor(app) {
15
+ app: BibliographyApp
16
+ db: Record<number, BibDBEntry>
17
+ cats: BibCategory[]
18
+ sc: BibliographyDBServerConnector
19
+
20
+ constructor(app: BibliographyApp) {
8
21
  this.app = app
9
22
  this.db = {}
10
23
  this.cats = []
@@ -15,16 +28,16 @@ export class BibliographyDB {
15
28
  * @function getDB
16
29
  */
17
30
 
18
- getDB() {
31
+ getDB(): Promise<void> {
19
32
  const localStorageVersion = window.localStorage.getItem("version")
20
33
  let lastModified = Number.parseInt(
21
- window.localStorage.getItem("last_modified_biblist")
34
+ window.localStorage.getItem("last_modified_biblist") || ""
22
35
  ),
23
36
  numberOfEntries = Number.parseInt(
24
- window.localStorage.getItem("number_of_entries")
37
+ window.localStorage.getItem("number_of_entries") || ""
25
38
  ),
26
39
  localStorageOwnerId = Number.parseInt(
27
- window.localStorage.getItem("owner_id")
40
+ window.localStorage.getItem("owner_id") || ""
28
41
  )
29
42
 
30
43
  // A dictionary to look up bib fields by their fw type name.
@@ -54,35 +67,32 @@ export class BibliographyDB {
54
67
  .then(
55
68
  ({bibCats, bibList, lastModified, numberOfEntries, userId}) => {
56
69
  bibCats.forEach(bibCat => this.cats.push(bibCat))
70
+ let bibListItems: ServerBibItem[]
57
71
  if (bibList) {
58
- try {
59
- window.localStorage.setItem(
60
- "biblist",
61
- JSON.stringify(bibList)
62
- )
63
- window.localStorage.setItem(
64
- "last_modified_biblist",
65
- lastModified
66
- )
67
- window.localStorage.setItem(
68
- "number_of_entries",
69
- numberOfEntries
70
- )
71
- window.localStorage.setItem("owner_id", userId)
72
- window.localStorage.setItem(
73
- "version",
74
- FW_LOCALSTORAGE_VERSION
75
- )
76
- } catch (error) {
77
- // The local storage was likely too small
78
- throw error
79
- }
72
+ bibListItems = bibList
73
+ window.localStorage.setItem(
74
+ "biblist",
75
+ JSON.stringify(bibListItems)
76
+ )
77
+ window.localStorage.setItem(
78
+ "last_modified_biblist",
79
+ String(lastModified)
80
+ )
81
+ window.localStorage.setItem(
82
+ "number_of_entries",
83
+ String(numberOfEntries)
84
+ )
85
+ window.localStorage.setItem("owner_id", String(userId))
86
+ window.localStorage.setItem(
87
+ "version",
88
+ FW_LOCALSTORAGE_VERSION
89
+ )
80
90
  } else {
81
- bibList = JSON.parse(
82
- window.localStorage.getItem("biblist")
91
+ bibListItems = JSON.parse(
92
+ window.localStorage.getItem("biblist") || "[]"
83
93
  )
84
94
  }
85
- bibList.forEach(({id, bibDBEntry}) => {
95
+ bibListItems.forEach(({id, bibDBEntry}) => {
86
96
  this.db[id] = bibDBEntry
87
97
  })
88
98
  deactivateWait()
@@ -100,7 +110,10 @@ export class BibliographyDB {
100
110
  * @function saveBibEntries
101
111
  * @param tmpDB The bibliography DB with temporary IDs to be send to the server.
102
112
  */
103
- saveBibEntries(tmpDB, isNew) {
113
+ saveBibEntries(
114
+ tmpDB: Record<number, BibDBEntry>,
115
+ isNew: boolean
116
+ ): Promise<IdTranslation[]> {
104
117
  return this.sc
105
118
  .saveBibEntries(tmpDB, isNew)
106
119
  .then(idTranslations =>
@@ -121,10 +134,14 @@ export class BibliographyDB {
121
134
  } else {
122
135
  throw error
123
136
  }
137
+ return []
124
138
  })
125
139
  }
126
140
 
127
- updateLocalBibEntries(tmpDB, idTranslations) {
141
+ updateLocalBibEntries(
142
+ tmpDB: Record<number, BibDBEntry>,
143
+ idTranslations: IdTranslation[]
144
+ ): IdTranslation[] {
128
145
  idTranslations.forEach(bibTrans => {
129
146
  this.db[bibTrans[1]] = tmpDB[bibTrans[0]]
130
147
  })
@@ -136,7 +153,7 @@ export class BibliographyDB {
136
153
  * @function saveCategories
137
154
  * @param cats The category objects to add.
138
155
  */
139
- saveCategories(cats) {
156
+ saveCategories(cats: SaveCategoriesRequest): Promise<BibCategory[]> {
140
157
  activateWait()
141
158
 
142
159
  return this.sc
@@ -147,7 +164,10 @@ export class BibliographyDB {
147
164
  this.cats.pop()
148
165
  }
149
166
  while (bibCats.length > 0) {
150
- this.cats.push(bibCats.pop())
167
+ const cat = bibCats.pop()
168
+ if (cat) {
169
+ this.cats.push(cat)
170
+ }
151
171
  }
152
172
  addAlert("success", gettext("The categories have been updated"))
153
173
  deactivateWait()
@@ -169,6 +189,7 @@ export class BibliographyDB {
169
189
  } else {
170
190
  throw error
171
191
  }
192
+ return []
172
193
  })
173
194
  }
174
195
 
@@ -176,10 +197,10 @@ export class BibliographyDB {
176
197
  * @function deleteCategory
177
198
  * @param ids A list of ids to delete.
178
199
  */
179
- deleteCategory(ids) {
200
+ deleteCategory(ids: number[]): Promise<number[]> {
180
201
  return this.sc.deleteCategory(ids).then(() => {
181
202
  const deletedPks = ids.slice()
182
- const deletedBibCats = []
203
+ const deletedBibCats: BibCategory[] = []
183
204
  this.cats.forEach(bibCat => {
184
205
  if (ids.indexOf(bibCat.id) !== -1) {
185
206
  deletedBibCats.push(bibCat)
@@ -197,9 +218,9 @@ export class BibliographyDB {
197
218
  * @function deleteBibEntries
198
219
  * @param ids A list of bibliography item ids that are to be deleted.
199
220
  */
200
- deleteBibEntries(ids) {
221
+ deleteBibEntries(ids: number[]): Promise<number[]> {
201
222
  activateWait()
202
- ids = ids.map(id => Number.parseInt(id))
223
+ ids = ids.map(id => Number.parseInt(String(id)))
203
224
  return this.sc
204
225
  .deleteBibEntries(ids)
205
226
  .then(() => {
@@ -229,6 +250,7 @@ export class BibliographyDB {
229
250
  } else {
230
251
  throw error
231
252
  }
253
+ return []
232
254
  })
233
255
  }
234
256
  }
@@ -0,0 +1,92 @@
1
+ import {post, postJson} from "fwtoolkit/network"
2
+ import type {
3
+ BibCategory,
4
+ BibDBEntry,
5
+ BiblistResponse,
6
+ DeleteBibEntriesRequest,
7
+ DeleteCategoryRequest,
8
+ IdTranslation,
9
+ SaveCategoriesRequest,
10
+ SaveCategoriesResponse,
11
+ SaveBibEntriesRequest,
12
+ ServerBibItem
13
+ } from "../types/biblio.js"
14
+
15
+ // class for server calls of BibliographyDB.
16
+ export class BibliographyDBServerConnector {
17
+ constructor() {}
18
+
19
+ getDB(
20
+ lastModified: number,
21
+ numberOfEntries: number,
22
+ localStorageOwnerId: number
23
+ ): Promise<{
24
+ bibCats: BibCategory[]
25
+ bibList: ServerBibItem[] | false
26
+ lastModified: number
27
+ numberOfEntries: number
28
+ userId: number
29
+ }> {
30
+ return postJson("/api/bibliography/biblist/", {
31
+ last_modified: lastModified,
32
+ number_of_entries: numberOfEntries,
33
+ user_id: localStorageOwnerId
34
+ }).then(({json}) => {
35
+ const response = json as BiblistResponse
36
+ return {
37
+ bibCats: response["bib_categories"],
38
+ bibList: response.hasOwnProperty("bib_list")
39
+ ? (response["bib_list"] as BibDBEntry[]).map(item =>
40
+ this.serverBibItemToBibDB(item)
41
+ )
42
+ : false,
43
+ lastModified: response["last_modified"],
44
+ numberOfEntries: response["number_of_entries"],
45
+ userId: response["user_id"]
46
+ }
47
+ })
48
+ }
49
+
50
+ /** Converts a bibliography item as it arrives from the server to a BibDB object.
51
+ * @function serverBibItemToBibDB
52
+ * @param item The bibliography item from the server.
53
+ */
54
+ serverBibItemToBibDB(bibDBEntry: BibDBEntry): ServerBibItem {
55
+ return {
56
+ id: (bibDBEntry as BibDBEntry & {id: number}).id,
57
+ bibDBEntry
58
+ }
59
+ }
60
+
61
+ saveBibEntries(
62
+ tmpDB: Record<number, BibDBEntry>,
63
+ isNew: boolean
64
+ ): Promise<IdTranslation[]> {
65
+ return postJson("/api/bibliography/save/", {
66
+ is_new: isNew,
67
+ bibs: tmpDB
68
+ } as SaveBibEntriesRequest & Record<string, unknown>).then(
69
+ ({json}) => (json as {id_translations: IdTranslation[]})["id_translations"]
70
+ )
71
+ }
72
+
73
+ saveCategories(cats: SaveCategoriesRequest): Promise<BibCategory[]> {
74
+ return postJson("/api/bibliography/save_category/", cats as unknown as Record<string, unknown>).then(
75
+ ({json}) => {
76
+ return (json as SaveCategoriesResponse).entries
77
+ }
78
+ )
79
+ }
80
+
81
+ deleteCategory(ids: number[]): Promise<Response> {
82
+ return post("/api/bibliography/delete_category/", {
83
+ ids
84
+ } as DeleteCategoryRequest & Record<string, unknown>)
85
+ }
86
+
87
+ deleteBibEntries(ids: number[]): Promise<Response> {
88
+ return post("/api/bibliography/delete/", {
89
+ ids
90
+ } as DeleteBibEntriesRequest & Record<string, unknown>)
91
+ }
92
+ }
@@ -1,20 +1,27 @@
1
1
  import {ZipFileCreator} from "fwtoolkit/file/zip"
2
2
  import download from "downloadjs"
3
+ import type {BibDBCollection} from "../types/biblio.js"
3
4
 
4
5
  export class BibLatexFileExporter {
5
- constructor(bibDB, pks) {
6
+ pks: number[]
7
+ bibDB: BibDBCollection
8
+
9
+ constructor(bibDB: BibDBCollection, pks: number[]) {
6
10
  this.pks = pks // A list of pk values of the bibliography items to be exported.
7
11
  this.bibDB = bibDB // The bibliography database to export from.
8
12
  }
9
13
 
10
- init() {
14
+ init(): void {
11
15
  import("bibliojson").then(({BibLatexExporter}) => {
12
- const exporter = new BibLatexExporter(this.bibDB.db, this.pks)
16
+ const exporter = new BibLatexExporter(
17
+ this.bibDB.db,
18
+ this.pks.map(String)
19
+ )
13
20
 
14
21
  const zipper = new ZipFileCreator([
15
22
  {
16
23
  filename: "bibliography.bib",
17
- contents: exporter.output
24
+ contents: (exporter as unknown as {output: string}).output
18
25
  }
19
26
  ])
20
27
  zipper
@@ -25,3 +32,8 @@ export class BibLatexFileExporter {
25
32
  })
26
33
  }
27
34
  }
35
+
36
+ export function exportBibFile(bibDB: BibDBCollection, pks: number[]): void {
37
+ const exporter = new BibLatexFileExporter(bibDB, pks)
38
+ exporter.init()
39
+ }
@@ -1,7 +1,15 @@
1
1
  import {CheckableList} from "fwtoolkit"
2
+ import type {BibCategory} from "../types/biblio.js"
2
3
 
3
4
  export class CatsForm {
4
- constructor(dom, initialValue = [], options = []) {
5
+ dom: HTMLElement
6
+ checkableList: CheckableList
7
+
8
+ constructor(
9
+ dom: HTMLElement,
10
+ initialValue: (string | number)[] = [],
11
+ options: BibCategory[] = []
12
+ ) {
5
13
  this.dom = dom
6
14
  this.checkableList = new CheckableList({
7
15
  dom,
@@ -14,11 +22,11 @@ export class CatsForm {
14
22
  })
15
23
  }
16
24
 
17
- init() {
25
+ init(): void {
18
26
  // CheckableList is already rendered by the constructor.
19
27
  }
20
28
 
21
- get value() {
29
+ get value(): (string | number)[] {
22
30
  return this.checkableList.value
23
31
  }
24
32
  }
@@ -1,23 +1,28 @@
1
1
  import {edtfParse} from "bibliojson"
2
2
 
3
3
  export class DateFieldForm {
4
- constructor(dom, initialValue = "", placeHolder = "") {
4
+ dom: HTMLElement
5
+ initialValue: string
6
+ placeHolder: string
7
+
8
+ constructor(dom: HTMLElement, initialValue = "", placeHolder = "") {
5
9
  this.dom = dom
6
10
  this.initialValue = initialValue
7
11
  this.placeHolder = placeHolder
8
12
  }
9
13
 
10
- init() {
14
+ init(): void {
11
15
  this.dom.innerHTML = `<input class="fw-date" type="text" value="${this.initialValue}" placeholder="${this.placeHolder}">`
12
16
  }
13
17
 
14
- get value() {
15
- const formValue = this.dom.querySelector("input.fw-date").value
18
+ get value(): string | false {
19
+ const formValue = (this.dom.querySelector("input.fw-date") as HTMLInputElement)
20
+ .value
16
21
  // If the form has not been filled out, don't consider this form
17
22
  return formValue.length > 0 ? formValue : false
18
23
  }
19
24
 
20
- check() {
25
+ check(): boolean {
21
26
  const formValue = this.value
22
27
  if (formValue) {
23
28
  const checkValue = edtfParse(formValue).valid
@@ -1,9 +1,22 @@
1
1
  import {TypeSwitch} from "fwtoolkit"
2
2
  import {getBibOptionTitle} from "../strings.js"
3
3
  import {LiteralFieldForm} from "./literal.js"
4
+ import type {BibFieldType} from "../../types/biblio.js"
4
5
 
5
6
  export class KeyFieldForm {
6
- constructor(dom, initialValue, _unused, fieldType = undefined) {
7
+ currentValue: Record<string, unknown>
8
+ dom: HTMLElement
9
+ fieldType: BibFieldType | undefined
10
+ predefined: boolean
11
+ typeSwitch!: TypeSwitch
12
+ fields: Record<string, LiteralFieldForm> = {}
13
+
14
+ constructor(
15
+ dom: HTMLElement,
16
+ initialValue: unknown,
17
+ _unused?: unknown,
18
+ fieldType: BibFieldType | undefined = undefined
19
+ ) {
7
20
  this.currentValue = {}
8
21
  this.dom = dom
9
22
  this.fieldType = fieldType
@@ -17,13 +30,13 @@ export class KeyFieldForm {
17
30
  }
18
31
  }
19
32
 
20
- init() {
33
+ init(): void {
21
34
  this.typeSwitch = new TypeSwitch({
22
35
  dom: this.dom,
23
36
  label1: gettext("From list"),
24
37
  label2: gettext("Custom"),
25
38
  initialMode: this.predefined ? 1 : 2,
26
- disabled: this.fieldType.strict,
39
+ disabled: this.fieldType?.strict,
27
40
  beforeChange: () => {
28
41
  const formValue = this.value
29
42
  if (formValue) {
@@ -42,7 +55,7 @@ export class KeyFieldForm {
42
55
  this.drawForm()
43
56
  }
44
57
 
45
- drawForm() {
58
+ drawForm(): void {
46
59
  if (this.predefined) {
47
60
  this.drawSelectionListForm()
48
61
  } else {
@@ -50,22 +63,24 @@ export class KeyFieldForm {
50
63
  }
51
64
  }
52
65
 
53
- drawSelectionListForm() {
66
+ drawSelectionListForm(): void {
54
67
  this.typeSwitch.innerElement.innerHTML = `
55
68
  <select class='key-selection'><option value=''></option></select>
56
69
  <div class="fw-select-arrow fa fa-caret-down"></div>
57
70
  `
58
- const selectEl =
59
- this.typeSwitch.innerElement.querySelector(".key-selection")
60
- if (Array.isArray(this.fieldType.options)) {
61
- this.fieldType.options.forEach(option => {
71
+ const selectEl = this.typeSwitch.innerElement.querySelector(
72
+ ".key-selection"
73
+ ) as HTMLSelectElement
74
+ const options = this.fieldType?.options
75
+ if (Array.isArray(options)) {
76
+ options.forEach(option => {
62
77
  selectEl.insertAdjacentHTML(
63
78
  "beforeend",
64
79
  `<option value="${option}">${getBibOptionTitle(option)}</option>`
65
80
  )
66
81
  })
67
- } else {
68
- Object.keys(this.fieldType.options).forEach(option => {
82
+ } else if (options) {
83
+ Object.keys(options).forEach(option => {
69
84
  selectEl.insertAdjacentHTML(
70
85
  "beforeend",
71
86
  `<option value="${option}">${getBibOptionTitle(option)}</option>`
@@ -74,24 +89,27 @@ export class KeyFieldForm {
74
89
  }
75
90
 
76
91
  if (this.currentValue["predefined"]) {
77
- selectEl.value = this.currentValue["predefined"]
92
+ selectEl.value = String(this.currentValue["predefined"])
78
93
  }
79
94
  }
80
95
 
81
- drawCustomInputForm() {
96
+ drawCustomInputForm(): void {
82
97
  this.fields = {}
83
98
  this.typeSwitch.innerElement.innerHTML = `<div class='custom-input field-part field-part-single'></div>`
84
99
  this.fields["custom"] = new LiteralFieldForm(
85
- this.typeSwitch.innerElement.querySelector(".custom-input"),
86
- this.currentValue["custom"]
100
+ this.typeSwitch.innerElement.querySelector(
101
+ ".custom-input"
102
+ ) as HTMLElement,
103
+ this.currentValue["custom"] as Record<string, unknown>[]
87
104
  )
88
105
  this.fields.custom.init()
89
106
  }
90
107
 
91
- get value() {
108
+ get value(): string | Record<string, unknown>[] | false {
92
109
  if (this.predefined) {
93
- const selectEl =
94
- this.typeSwitch.innerElement.querySelector(".key-selection")
110
+ const selectEl = this.typeSwitch.innerElement.querySelector(
111
+ ".key-selection"
112
+ ) as HTMLSelectElement
95
113
  const selectionValue =
96
114
  selectEl.options[selectEl.selectedIndex].value
97
115
  if (selectionValue === "") {
@@ -107,7 +125,7 @@ export class KeyFieldForm {
107
125
  }
108
126
  }
109
127
 
110
- check() {
128
+ check(): boolean {
111
129
  return true
112
130
  }
113
131
  }
@@ -1,12 +1,23 @@
1
1
  import {InputList} from "fwtoolkit"
2
2
  import {KeyFieldForm} from "./key.js"
3
+ import type {BibFieldType} from "../../types/biblio.js"
3
4
 
4
5
  export class KeyListForm {
5
- constructor(dom, initialValue = [""], _unused, fieldType = undefined) {
6
+ dom: HTMLElement
7
+ fieldType: BibFieldType | undefined
8
+ fieldHandlers: WeakMap<HTMLElement, KeyFieldForm>
9
+ inputList: InputList<unknown>
10
+
11
+ constructor(
12
+ dom: HTMLElement,
13
+ initialValue: unknown[] = [""],
14
+ _unused?: unknown,
15
+ fieldType: BibFieldType | undefined = undefined
16
+ ) {
6
17
  this.dom = dom
7
18
  this.fieldType = fieldType
8
19
  this.fieldHandlers = new WeakMap()
9
- this.inputList = new InputList({
20
+ this.inputList = new InputList<unknown>({
10
21
  dom,
11
22
  initialValues: initialValue,
12
23
  emptyValue: "",
@@ -14,7 +25,7 @@ export class KeyListForm {
14
25
  html: `<div class="key-field"></div>`,
15
26
  bind: el => {
16
27
  const fieldHandler = new KeyFieldForm(
17
- el.firstElementChild,
28
+ el.firstElementChild as HTMLElement,
18
29
  value,
19
30
  false,
20
31
  this.fieldType
@@ -23,15 +34,15 @@ export class KeyListForm {
23
34
  this.fieldHandlers.set(el, fieldHandler)
24
35
  }
25
36
  }),
26
- getValue: el => this.fieldHandlers.get(el).value
37
+ getValue: el => this.fieldHandlers.get(el)!.value
27
38
  })
28
39
  }
29
40
 
30
- init() {
41
+ init(): void {
31
42
  // InputList is already rendered by the constructor.
32
43
  }
33
44
 
34
- get value() {
45
+ get value(): unknown[] | false {
35
46
  const formValue = this.inputList.values.filter(value => value !== false)
36
47
  if (formValue.length === 0) {
37
48
  return false
@@ -39,7 +50,7 @@ export class KeyListForm {
39
50
  return formValue
40
51
  }
41
52
 
42
- check() {
53
+ check(): boolean {
43
54
  return true
44
55
  }
45
56
  }
@@ -5,12 +5,18 @@ import {InlineInput, icon} from "fwtoolkit"
5
5
  import {litSchema} from "../../schema/literal.js"
6
6
 
7
7
  export class LiteralFieldForm {
8
- constructor(dom, initialValue = [], placeHolder = false) {
8
+ inlineInput: InlineInput
9
+
10
+ constructor(
11
+ dom: HTMLElement,
12
+ initialValue: Record<string, unknown>[] = [],
13
+ placeHolder: string | false = false
14
+ ) {
9
15
  this.inlineInput = new InlineInput(dom, {
10
16
  schema: litSchema,
11
17
  nodeType: "literal",
12
18
  initialValue,
13
- placeholder: placeHolder,
19
+ placeholder: placeHolder || undefined,
14
20
  tools: [
15
21
  {
16
22
  command: toggleMark(litSchema.marks.strong),
@@ -36,13 +42,13 @@ export class LiteralFieldForm {
36
42
  })
37
43
  }
38
44
 
39
- init() {}
45
+ init(): void {}
40
46
 
41
- get value() {
47
+ get value(): Record<string, unknown>[] | false {
42
48
  return this.inlineInput.value
43
49
  }
44
50
 
45
- check() {
51
+ check(): boolean {
46
52
  return this.inlineInput.check()
47
53
  }
48
54
  }
@@ -2,41 +2,50 @@ import {InputList} from "fwtoolkit"
2
2
  import {LiteralFieldForm} from "./literal.js"
3
3
 
4
4
  export class LiteralListForm {
5
- constructor(dom, initialValue = [[]]) {
5
+ dom: HTMLElement
6
+ fieldHandlers: WeakMap<HTMLElement, LiteralFieldForm>
7
+ inputList: InputList<unknown>
8
+
9
+ constructor(
10
+ dom: HTMLElement,
11
+ initialValue: Record<string, unknown>[][] = [[]]
12
+ ) {
6
13
  this.dom = dom
7
14
  this.fieldHandlers = new WeakMap()
8
- this.inputList = new InputList({
15
+ this.inputList = new InputList<unknown>({
9
16
  dom,
10
- initialValues: initialValue,
17
+ initialValues: initialValue as unknown[],
11
18
  emptyValue: [],
12
19
  renderItem: value => ({
13
20
  html: `<div class="literal-field"></div>`,
14
21
  bind: el => {
15
22
  const fieldHandler = new LiteralFieldForm(
16
- el.firstElementChild,
17
- value
23
+ el.firstElementChild as HTMLElement,
24
+ value as Record<string, unknown>[]
18
25
  )
19
26
  fieldHandler.init()
20
27
  this.fieldHandlers.set(el, fieldHandler)
21
28
  }
22
29
  }),
23
- getValue: el => this.fieldHandlers.get(el).value
30
+ getValue: el => this.fieldHandlers.get(el)!.value
24
31
  })
25
32
  }
26
33
 
27
- init() {
34
+ init(): void {
28
35
  // InputList is already rendered by the constructor.
29
36
  }
30
37
 
31
- get value() {
32
- const formValue = this.inputList.values.filter(value => value !== false)
38
+ get value(): Record<string, unknown>[][] | false {
39
+ const formValue = this.inputList.values.filter(
40
+ value => value !== false
41
+ ) as Record<string, unknown>[][]
33
42
  if (formValue.length === 0) {
34
43
  return false
35
44
  }
36
45
  return formValue
37
46
  }
38
47
 
39
- check() {
48
+ check(): boolean {
40
49
  return true
41
50
  }
42
51
  }