@fiduswriter/bibliography-manager 0.1.7 → 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.
Files changed (175) hide show
  1. package/dist/database/index.d.ts +12 -11
  2. package/dist/database/index.d.ts.map +1 -1
  3. package/dist/database/index.js +22 -16
  4. package/dist/database/index.js.map +1 -1
  5. package/dist/database/server_connector.d.ts +14 -15
  6. package/dist/database/server_connector.d.ts.map +1 -1
  7. package/dist/database/server_connector.js +17 -9
  8. package/dist/database/server_connector.js.map +1 -1
  9. package/dist/export/index.d.ts +6 -4
  10. package/dist/export/index.d.ts.map +1 -1
  11. package/dist/export/index.js +7 -1
  12. package/dist/export/index.js.map +1 -1
  13. package/dist/form/cats.d.ts +5 -4
  14. package/dist/form/cats.d.ts.map +1 -1
  15. package/dist/form/cats.js +2 -0
  16. package/dist/form/cats.js.map +1 -1
  17. package/dist/form/fields/date.d.ts +4 -4
  18. package/dist/form/fields/date.d.ts.map +1 -1
  19. package/dist/form/fields/date.js +5 -1
  20. package/dist/form/fields/date.js.map +1 -1
  21. package/dist/form/fields/key.d.ts +11 -9
  22. package/dist/form/fields/key.d.ts.map +1 -1
  23. package/dist/form/fields/key.js +13 -6
  24. package/dist/form/fields/key.js.map +1 -1
  25. package/dist/form/fields/key_list.d.ts +10 -8
  26. package/dist/form/fields/key_list.d.ts.map +1 -1
  27. package/dist/form/fields/key_list.js +4 -0
  28. package/dist/form/fields/key_list.js.map +1 -1
  29. package/dist/form/fields/literal.d.ts +4 -4
  30. package/dist/form/fields/literal.d.ts.map +1 -1
  31. package/dist/form/fields/literal.js +2 -1
  32. package/dist/form/fields/literal.js.map +1 -1
  33. package/dist/form/fields/literal_list.d.ts +8 -7
  34. package/dist/form/fields/literal_list.d.ts.map +1 -1
  35. package/dist/form/fields/literal_list.js +3 -0
  36. package/dist/form/fields/literal_list.js.map +1 -1
  37. package/dist/form/fields/literal_long.d.ts +4 -4
  38. package/dist/form/fields/literal_long.d.ts.map +1 -1
  39. package/dist/form/fields/literal_long.js +1 -0
  40. package/dist/form/fields/literal_long.js.map +1 -1
  41. package/dist/form/fields/name.d.ts +10 -27
  42. package/dist/form/fields/name.d.ts.map +1 -1
  43. package/dist/form/fields/name.js +22 -18
  44. package/dist/form/fields/name.js.map +1 -1
  45. package/dist/form/fields/name_list.d.ts +9 -7
  46. package/dist/form/fields/name_list.d.ts.map +1 -1
  47. package/dist/form/fields/name_list.js +5 -2
  48. package/dist/form/fields/name_list.js.map +1 -1
  49. package/dist/form/fields/range.d.ts +10 -8
  50. package/dist/form/fields/range.d.ts.map +1 -1
  51. package/dist/form/fields/range.js +13 -9
  52. package/dist/form/fields/range.js.map +1 -1
  53. package/dist/form/fields/range_list.d.ts +9 -7
  54. package/dist/form/fields/range_list.d.ts.map +1 -1
  55. package/dist/form/fields/range_list.js +3 -0
  56. package/dist/form/fields/range_list.js.map +1 -1
  57. package/dist/form/fields/tag_list.d.ts +7 -6
  58. package/dist/form/fields/tag_list.d.ts.map +1 -1
  59. package/dist/form/fields/tag_list.js +3 -0
  60. package/dist/form/fields/tag_list.js.map +1 -1
  61. package/dist/form/fields/title.d.ts +4 -4
  62. package/dist/form/fields/title.d.ts.map +1 -1
  63. package/dist/form/fields/title.js +1 -0
  64. package/dist/form/fields/title.js.map +1 -1
  65. package/dist/form/fields/uri.d.ts +4 -4
  66. package/dist/form/fields/uri.d.ts.map +1 -1
  67. package/dist/form/fields/uri.js +5 -1
  68. package/dist/form/fields/uri.js.map +1 -1
  69. package/dist/form/fields/verbatim.d.ts +4 -4
  70. package/dist/form/fields/verbatim.d.ts.map +1 -1
  71. package/dist/form/fields/verbatim.js +5 -1
  72. package/dist/form/fields/verbatim.js.map +1 -1
  73. package/dist/form/index.d.ts +32 -30
  74. package/dist/form/index.d.ts.map +1 -1
  75. package/dist/form/index.js +33 -11
  76. package/dist/form/index.js.map +1 -1
  77. package/dist/form/strings.d.ts +11 -11
  78. package/dist/form/strings.d.ts.map +1 -1
  79. package/dist/form/strings.js +5 -5
  80. package/dist/form/strings.js.map +1 -1
  81. package/dist/form/templates.d.ts +6 -5
  82. package/dist/form/templates.d.ts.map +1 -1
  83. package/dist/form/templates.js +2 -2
  84. package/dist/form/templates.js.map +1 -1
  85. package/dist/import/bibliography_import.d.ts +20 -7
  86. package/dist/import/bibliography_import.d.ts.map +1 -1
  87. package/dist/import/bibliography_import.js +15 -7
  88. package/dist/import/bibliography_import.js.map +1 -1
  89. package/dist/import/dialog.d.ts +6 -5
  90. package/dist/import/dialog.d.ts.map +1 -1
  91. package/dist/import/dialog.js +27 -12
  92. package/dist/import/dialog.js.map +1 -1
  93. package/dist/import/index.d.ts +2 -0
  94. package/dist/import/index.d.ts.map +1 -1
  95. package/dist/import/index.js +5 -0
  96. package/dist/import/index.js.map +1 -1
  97. package/dist/import/templates.d.ts +2 -1
  98. package/dist/import/templates.d.ts.map +1 -1
  99. package/dist/import/templates.js.map +1 -1
  100. package/dist/index.d.ts +2 -0
  101. package/dist/index.d.ts.map +1 -1
  102. package/dist/index.js.map +1 -1
  103. package/dist/overview/index.d.ts +43 -28
  104. package/dist/overview/index.d.ts.map +1 -1
  105. package/dist/overview/index.js +55 -20
  106. package/dist/overview/index.js.map +1 -1
  107. package/dist/overview/menu.d.ts +13 -12
  108. package/dist/overview/menu.d.ts.map +1 -1
  109. package/dist/overview/menu.js +13 -10
  110. package/dist/overview/menu.js.map +1 -1
  111. package/dist/overview/templates.d.ts +5 -3
  112. package/dist/overview/templates.d.ts.map +1 -1
  113. package/dist/overview/templates.js.map +1 -1
  114. package/dist/plugins/bibliography_overview/index.d.ts +1 -1
  115. package/dist/plugins/bibliography_overview/index.d.ts.map +1 -1
  116. package/dist/plugins/bibliography_overview/index.js.map +1 -1
  117. package/dist/schema/csl_bib.d.ts +1 -1
  118. package/dist/schema/literal.d.ts +1 -1
  119. package/dist/schema/literal.d.ts.map +1 -1
  120. package/dist/schema/literal.js.map +1 -1
  121. package/dist/schema/literal_long.d.ts +1 -1
  122. package/dist/schema/literal_long.d.ts.map +1 -1
  123. package/dist/schema/literal_long.js +1 -7
  124. package/dist/schema/literal_long.js.map +1 -1
  125. package/dist/schema/title.d.ts +1 -1
  126. package/dist/schema/title.d.ts.map +1 -1
  127. package/dist/schema/title.js.map +1 -1
  128. package/dist/tools.d.ts +4 -3
  129. package/dist/tools.d.ts.map +1 -1
  130. package/dist/tools.js.map +1 -1
  131. package/dist/types/biblio.d.ts +138 -0
  132. package/dist/types/biblio.d.ts.map +1 -0
  133. package/dist/types/biblio.js +2 -0
  134. package/dist/types/biblio.js.map +1 -0
  135. package/package.json +1 -1
  136. package/src/database/{index.js → index.ts} +60 -38
  137. package/src/database/server_connector.ts +92 -0
  138. package/src/export/{index.js → index.ts} +16 -4
  139. package/src/form/{cats.js → cats.ts} +11 -3
  140. package/src/form/fields/{date.js → date.ts} +10 -5
  141. package/src/form/fields/{key.js → key.ts} +37 -19
  142. package/src/form/fields/{key_list.js → key_list.ts} +18 -7
  143. package/src/form/fields/{literal.js → literal.ts} +11 -5
  144. package/src/form/fields/{literal_list.js → literal_list.ts} +19 -10
  145. package/src/form/fields/{literal_long.js → literal_long.ts} +6 -4
  146. package/src/form/fields/{name.js → name.ts} +53 -39
  147. package/src/form/fields/name_list.ts +49 -0
  148. package/src/form/fields/{range.js → range.ts} +34 -22
  149. package/src/form/fields/{range_list.js → range_list.ts} +17 -10
  150. package/src/form/fields/{tag_list.js → tag_list.ts} +9 -5
  151. package/src/form/fields/{title.js → title.ts} +6 -4
  152. package/src/form/fields/{uri.js → uri.ts} +11 -6
  153. package/src/form/fields/{verbatim.js → verbatim.ts} +10 -5
  154. package/src/form/{index.js → index.ts} +113 -60
  155. package/src/form/{strings.js → strings.ts} +24 -22
  156. package/src/form/{templates.js → templates.ts} +14 -5
  157. package/src/global.d.ts +75 -0
  158. package/src/import/{bibliography_import.js → bibliography_import.ts} +42 -16
  159. package/src/import/{dialog.js → dialog.ts} +47 -23
  160. package/src/import/index.ts +14 -0
  161. package/src/import/{templates.js → templates.ts} +1 -1
  162. package/src/overview/{index.js → index.ts} +147 -79
  163. package/src/overview/{menu.js → menu.ts} +18 -12
  164. package/src/overview/{templates.js → templates.ts} +3 -2
  165. package/src/plugins/bibliography_overview/index.ts +1 -0
  166. package/src/schema/{literal_long.js → literal_long.ts} +3 -8
  167. package/src/schema/{title.js → title.ts} +1 -1
  168. package/src/{tools.js → tools.ts} +7 -5
  169. package/src/types/biblio.ts +189 -0
  170. package/src/database/server_connector.js +0 -57
  171. package/src/form/fields/name_list.js +0 -42
  172. package/src/import/index.js +0 -2
  173. package/src/plugins/bibliography_overview/index.js +0 -1
  174. /package/src/{index.js → index.ts} +0 -0
  175. /package/src/schema/{literal.js → literal.ts} +0 -0
@@ -14,7 +14,7 @@ import {marks} from "prosemirror-schema-basic"
14
14
  const nocase = {
15
15
  parseDOM: [{tag: "span.nocase"}],
16
16
  toDOM() {
17
- return ["span", {class: "nocase"}]
17
+ return ["span", {class: "nocase"}] as const
18
18
  }
19
19
  }
20
20
 
@@ -1,6 +1,8 @@
1
+ import type {NameDictObject, NodeArray, TextNodeObject} from "./types/biblio.js"
2
+
1
3
  // Extract a display year from an EDTF date string.
2
4
  // Handles simple years, ranges (2023/2024), uncertainty (?, *, u), and open-ended dates.
3
- export function dateToYear(dateStr) {
5
+ export function dateToYear(dateStr: string): string {
4
6
  if (!dateStr) {
5
7
  return ""
6
8
  }
@@ -11,17 +13,17 @@ export function dateToYear(dateStr) {
11
13
  }
12
14
 
13
15
  // Takes any richtext text field as used in bibliography and returns the text contents
14
- export function litToText(litStringArray) {
16
+ export function litToText(litStringArray: NodeArray): string {
15
17
  let outText = ""
16
18
  litStringArray.forEach(litString => {
17
19
  if (litString.type === "text") {
18
- outText += litString.text
20
+ outText += (litString as TextNodeObject).text
19
21
  }
20
22
  })
21
23
  return outText
22
24
  }
23
25
 
24
- function nameListItemToString(nameListItem) {
26
+ function nameListItemToString(nameListItem: NameDictObject): string {
25
27
  let nameString = ""
26
28
  if (nameListItem["family"]) {
27
29
  nameString += litToText(nameListItem["family"])
@@ -34,7 +36,7 @@ function nameListItemToString(nameListItem) {
34
36
  return nameString
35
37
  }
36
38
 
37
- export function nameToText(nameList) {
39
+ export function nameToText(nameList: NameDictObject[]): string {
38
40
  let nameString
39
41
  switch (nameList.length) {
40
42
  case 0:
@@ -0,0 +1,189 @@
1
+ import {BibFieldTypes, BibTypes} from "bibliojson"
2
+ import type {BibDB as BiblioBibDB} from "bibliojson"
3
+
4
+ // Derive bibliojson's `EntryObject` from its exported `BibDB` type so we can
5
+ // extend it without importing the unexported `EntryObject` symbol.
6
+ export type EntryObject = BiblioBibDB[number]
7
+
8
+ // Derive the bibliojson field/type descriptors from their runtime objects.
9
+ export type BibFieldType = (typeof BibFieldTypes)[string] & {title?: string}
10
+ export type BibType = (typeof BibTypes)[string]
11
+
12
+ // Local types that mirror the shapes declared by bibliojson but are not
13
+ // exported from that package.
14
+
15
+ export interface MarkObject {
16
+ type: string
17
+ }
18
+
19
+ export interface TextNodeObject {
20
+ type: "text"
21
+ text: string
22
+ marks?: MarkObject[]
23
+ attrs?: Record<string, unknown>
24
+ }
25
+
26
+ export interface OtherNodeObject {
27
+ type: string
28
+ marks?: MarkObject[]
29
+ attrs?: Record<string, unknown>
30
+ }
31
+
32
+ export type NodeObject = OtherNodeObject | TextNodeObject
33
+
34
+ export type NodeArray = NodeObject[]
35
+
36
+ export type NameDictObject = {
37
+ literal?: NodeArray
38
+ family?: NodeArray
39
+ given?: NodeArray
40
+ prefix?: NodeArray
41
+ suffix?: NodeArray
42
+ useprefix?: boolean
43
+ }
44
+
45
+ export type RangeArray = [NodeArray, NodeArray] | [NodeArray]
46
+
47
+ /** A single bibliography category stored on the client. */
48
+ export interface BibCategory {
49
+ id: number
50
+ category_title: string
51
+ }
52
+
53
+ /** Client-side bibliography entry.
54
+ *
55
+ * Composes bibliojson's `EntryObject` with the extra `cats` field and the
56
+ * server-side `id` the Fidus Writer backend attaches to each entry.
57
+ */
58
+ export interface BibDBEntry extends EntryObject {
59
+ /** Categories the entry belongs to. */
60
+ cats: number[]
61
+ /** Server-side primary key (present in entries received from the server). */
62
+ id?: number
63
+ }
64
+
65
+ /** Client-side bibliography database, keyed by server id. */
66
+ export type BibDB = Record<number, BibDBEntry>
67
+
68
+ /** Translation of a temporary client-side id to the server-side id. */
69
+ export type IdTranslation = [number, number]
70
+
71
+ /** Single bibliography item as returned in the server's `bib_list` array. */
72
+ export interface ServerBibItem {
73
+ id: number
74
+ bibDBEntry: BibDBEntry
75
+ }
76
+
77
+ /** Shape of the response from `POST /api/bibliography/biblist/`. */
78
+ export interface BiblistResponse {
79
+ bib_categories: BibCategory[]
80
+ bib_list?: BibDBEntry[]
81
+ last_modified: number
82
+ number_of_entries: number
83
+ user_id: number
84
+ }
85
+
86
+ /** Shape of the request body for `POST /api/bibliography/save/`. */
87
+ export interface SaveBibEntriesRequest {
88
+ is_new: boolean
89
+ bibs: Record<number, BibDBEntry>
90
+ }
91
+
92
+ /** Shape of the response from `POST /api/bibliography/save/`. */
93
+ export interface SaveBibEntriesResponse {
94
+ id_translations: IdTranslation[]
95
+ }
96
+
97
+ /** Shape of the request body for `POST /api/bibliography/save_category/`. */
98
+ export interface SaveCategoriesRequest {
99
+ ids: number[]
100
+ titles: string[]
101
+ }
102
+
103
+ /** Shape of the response from `POST /api/bibliography/save_category/`. */
104
+ export interface SaveCategoriesResponse {
105
+ entries: BibCategory[]
106
+ }
107
+
108
+ /** Shape of the request body for `POST /api/bibliography/delete_category/`. */
109
+ export interface DeleteCategoryRequest {
110
+ ids: number[]
111
+ }
112
+
113
+ /** Shape of the request body for `POST /api/bibliography/delete/`. */
114
+ export interface DeleteBibEntriesRequest {
115
+ ids: number[]
116
+ }
117
+
118
+ /** Union of all possible field values handled by the form field classes. */
119
+ export type FieldValue =
120
+ | string
121
+ | number
122
+ | boolean
123
+ | NodeArray
124
+ | NameDictObject[]
125
+ | RangeArray[]
126
+ | string[]
127
+ | number[]
128
+
129
+ /** Common interface implemented by every bibliography form field class. */
130
+ export interface FieldForm {
131
+ init(): void
132
+ readonly value: unknown
133
+ check(): boolean
134
+ }
135
+
136
+ /** Constructor signature for a class that implements `FieldForm`. */
137
+ export interface FieldFormConstructor {
138
+ new (
139
+ dom: HTMLElement,
140
+ initialValue?: unknown,
141
+ placeHolder?: string | false,
142
+ fieldType?: BibFieldType
143
+ ): FieldForm
144
+ }
145
+
146
+ /** Map from `BibFieldType.type` to the form field class that renders it. */
147
+ export type FieldFormsMap = Record<string, FieldFormConstructor | undefined>
148
+
149
+ /** Object describing the current values of a bibliography entry being edited. */
150
+ export interface CurrentBibValues {
151
+ bib_type: string | false
152
+ cats: number[]
153
+ entry_key: string
154
+ fields: Record<string, unknown>
155
+ }
156
+
157
+ /** Shape returned by `BibEntryForm.value`. */
158
+ export interface FormValue {
159
+ bib_type: string
160
+ cats: (string | number)[]
161
+ entry_key: string
162
+ fields: Record<string, unknown>
163
+ }
164
+
165
+ /** Operations exposed by the bibliography database manager. */
166
+ export interface BibDBCollection {
167
+ db: BibDB
168
+ cats: BibCategory[]
169
+ saveBibEntries(
170
+ tmpDB: Record<number, BibDBEntry>,
171
+ isNew: boolean
172
+ ): Promise<IdTranslation[]>
173
+ saveCategories(cats: SaveCategoriesRequest): Promise<BibCategory[]>
174
+ deleteBibEntries(ids: number[]): Promise<number[]>
175
+ }
176
+
177
+ /** Subset of the main Fidus Writer app object used by bibliography code. */
178
+ export interface BibliographyApp {
179
+ bibDB: BibDBCollection
180
+ isOffline: () => boolean
181
+ settings: {
182
+ APPS: string[]
183
+ }
184
+ name: string
185
+ }
186
+
187
+ // Maintain the legacy `BibDB` alias for bibliojson's type as well, but export
188
+ // our own BibDB as the primary type.
189
+ export type {BiblioBibDB}
@@ -1,57 +0,0 @@
1
- import {post, postJson} from "fwtoolkit/network"
2
-
3
- // class for server calls of BibliographyDB.
4
- export class BibliographyDBServerConnector {
5
- constructor() {}
6
-
7
- getDB(lastModified, numberOfEntries, localStorageOwnerId) {
8
- return postJson("/api/bibliography/biblist/", {
9
- last_modified: lastModified,
10
- number_of_entries: numberOfEntries,
11
- user_id: localStorageOwnerId
12
- }).then(({json}) => {
13
- return {
14
- bibCats: json["bib_categories"],
15
- bibList: json.hasOwnProperty("bib_list")
16
- ? json["bib_list"].map(item =>
17
- this.serverBibItemToBibDB(item)
18
- )
19
- : false,
20
- lastModified: json["last_modified"],
21
- numberOfEntries: json["number_of_entries"],
22
- userId: json["user_id"]
23
- }
24
- })
25
- }
26
-
27
- /** Converts a bibliography item as it arrives from the server to a BibDB object.
28
- * @function serverBibItemToBibDB
29
- * @param item The bibliography item from the server.
30
- */
31
- serverBibItemToBibDB(bibDBEntry) {
32
- return {id: bibDBEntry["id"], bibDBEntry}
33
- }
34
-
35
- saveBibEntries(tmpDB, isNew) {
36
- return postJson("/api/bibliography/save/", {
37
- is_new: isNew,
38
- bibs: tmpDB
39
- }).then(({json}) => json["id_translations"])
40
- }
41
-
42
- saveCategories(cats) {
43
- return postJson("/api/bibliography/save_category/", cats).then(
44
- ({json}) => {
45
- return json.entries
46
- }
47
- )
48
- }
49
-
50
- deleteCategory(ids) {
51
- return post("/api/bibliography/delete_category/", {ids})
52
- }
53
-
54
- deleteBibEntries(ids) {
55
- return post("/api/bibliography/delete/", {ids})
56
- }
57
- }
@@ -1,42 +0,0 @@
1
- import {InputList} from "fwtoolkit"
2
- import {NameFieldForm} from "./name.js"
3
-
4
- export class NameListForm {
5
- constructor(dom, initialValue = [[]]) {
6
- this.dom = dom
7
- this.fieldHandlers = new WeakMap()
8
- this.inputList = new InputList({
9
- dom,
10
- initialValues: initialValue,
11
- emptyValue: [],
12
- renderItem: value => ({
13
- html: `<div class="name-field"></div>`,
14
- bind: el => {
15
- const fieldHandler = new NameFieldForm(
16
- el.firstElementChild,
17
- value
18
- )
19
- fieldHandler.init()
20
- this.fieldHandlers.set(el, fieldHandler)
21
- }
22
- }),
23
- getValue: el => this.fieldHandlers.get(el).value
24
- })
25
- }
26
-
27
- init() {
28
- // InputList is already rendered by the constructor.
29
- }
30
-
31
- get value() {
32
- const formValue = this.inputList.values.filter(value => value !== false)
33
- if (formValue.length === 0) {
34
- return false
35
- }
36
- return formValue
37
- }
38
-
39
- check() {
40
- return true
41
- }
42
- }
@@ -1,2 +0,0 @@
1
- export {BibliographyFileImportDialog} from "./dialog.js"
2
- export {BibliographyImporter} from "./bibliography_import.js"
@@ -1 +0,0 @@
1
- export const plugins = []
File without changes
File without changes