@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.
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 -27
  104. package/dist/overview/index.d.ts.map +1 -1
  105. package/dist/overview/index.js +59 -23
  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} +150 -81
  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
@@ -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
  }
@@ -5,7 +5,9 @@ import {InlineInput, icon} from "fwtoolkit"
5
5
  import {longLitSchema} from "../../schema/literal_long.js"
6
6
 
7
7
  export class LiteralLongFieldForm {
8
- constructor(dom, initialValue = []) {
8
+ inlineInput: InlineInput
9
+
10
+ constructor(dom: HTMLElement, initialValue: Record<string, unknown>[] = []) {
9
11
  this.inlineInput = new InlineInput(dom, {
10
12
  schema: longLitSchema,
11
13
  nodeType: "longliteral",
@@ -35,13 +37,13 @@ export class LiteralLongFieldForm {
35
37
  })
36
38
  }
37
39
 
38
- init() {}
40
+ init(): void {}
39
41
 
40
- get value() {
42
+ get value(): Record<string, unknown>[] | false {
41
43
  return this.inlineInput.value
42
44
  }
43
45
 
44
- check() {
46
+ check(): boolean {
45
47
  return this.inlineInput.check()
46
48
  }
47
49
  }