@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
@@ -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
  }
@@ -1,14 +1,21 @@
1
1
  import {TypeSwitch, getFocusIndex, setFocusIndex} from "fwtoolkit"
2
2
  import {LiteralFieldForm} from "./literal.js"
3
+ import type {NameDictObject, NodeArray} from "../../types/biblio.js"
3
4
 
4
5
  // There are only name lists, no name fields in the data format. The separation
5
6
  // between NameFieldForm and NameListForm is for keeping consistency with other fields
6
7
  // and lists.
7
8
 
8
9
  export class NameFieldForm {
10
+ currentValue: NameDictObject
11
+ dom: HTMLElement
12
+ realPerson: boolean
13
+ typeSwitch!: TypeSwitch
14
+ fields: Record<string, LiteralFieldForm> = {}
15
+
9
16
  constructor(
10
- dom,
11
- initialValue = {
17
+ dom: HTMLElement,
18
+ initialValue: NameDictObject = {
12
19
  given: [],
13
20
  family: [],
14
21
  prefix: [],
@@ -27,7 +34,7 @@ export class NameFieldForm {
27
34
  }
28
35
  }
29
36
 
30
- init() {
37
+ init(): void {
31
38
  this.typeSwitch = new TypeSwitch({
32
39
  dom: this.dom,
33
40
  label1: gettext("Person"),
@@ -49,7 +56,7 @@ export class NameFieldForm {
49
56
  this.drawForm()
50
57
  }
51
58
 
52
- drawForm() {
59
+ drawForm(): void {
53
60
  if (this.realPerson) {
54
61
  this.drawPersonForm()
55
62
  } else {
@@ -57,7 +64,7 @@ export class NameFieldForm {
57
64
  }
58
65
  }
59
66
 
60
- drawPersonForm() {
67
+ drawPersonForm(): void {
61
68
  this.fields = {}
62
69
  this.typeSwitch.innerElement.innerHTML = `
63
70
  <div class='given field-part field-part-long'></div>
@@ -71,82 +78,89 @@ export class NameFieldForm {
71
78
  </div>
72
79
  `
73
80
  this.fields["given"] = new LiteralFieldForm(
74
- this.typeSwitch.innerElement.querySelector(".given"),
75
- this.currentValue.given,
81
+ this.typeSwitch.innerElement.querySelector(".given") as HTMLElement,
82
+ this.currentValue.given as unknown as unknown as Record<string, unknown>[],
76
83
  gettext("First name")
77
84
  )
78
85
  this.fields.given.init()
79
86
  this.fields["prefix"] = new LiteralFieldForm(
80
- this.typeSwitch.innerElement.querySelector(".prefix"),
81
- this.currentValue.prefix,
87
+ this.typeSwitch.innerElement.querySelector(
88
+ ".prefix"
89
+ ) as HTMLElement,
90
+ this.currentValue.prefix as unknown as Record<string, unknown>[],
82
91
  gettext("Prefix")
83
92
  )
84
93
  this.fields.prefix.init()
85
94
  this.fields["family"] = new LiteralFieldForm(
86
- this.typeSwitch.innerElement.querySelector(".family"),
87
- this.currentValue.family,
95
+ this.typeSwitch.innerElement.querySelector(
96
+ ".family"
97
+ ) as HTMLElement,
98
+ this.currentValue.family as unknown as Record<string, unknown>[],
88
99
  gettext("Last name")
89
100
  )
90
101
  this.fields.family.init()
91
102
  this.fields["suffix"] = new LiteralFieldForm(
92
- this.typeSwitch.innerElement.querySelector(".suffix"),
93
- this.currentValue.suffix,
103
+ this.typeSwitch.innerElement.querySelector(
104
+ ".suffix"
105
+ ) as HTMLElement,
106
+ this.currentValue.suffix as unknown as Record<string, unknown>[],
94
107
  gettext("Suffix")
95
108
  )
96
109
  this.fields.suffix.init()
97
110
  }
98
111
 
99
- drawOrganizationForm() {
112
+ drawOrganizationForm(): void {
100
113
  this.fields = {}
101
114
  this.typeSwitch.innerElement.innerHTML = `<div class='literal-text field-part field-part-single'></div>`
102
115
  this.fields["literal"] = new LiteralFieldForm(
103
- this.typeSwitch.innerElement.querySelector(".literal-text"),
104
- this.currentValue.literal,
116
+ this.typeSwitch.innerElement.querySelector(
117
+ ".literal-text"
118
+ ) as HTMLElement,
119
+ this.currentValue.literal as unknown as Record<string, unknown>[],
105
120
  gettext("Organization name")
106
121
  )
107
122
  this.fields.literal.init()
108
123
  }
109
124
 
110
- get value() {
125
+ get value(): NameDictObject | false {
111
126
  if (this.realPerson) {
112
- if (
113
- !this.fields.family.value &&
114
- !this.fields.given.value &&
115
- !this.fields.prefix.value &&
116
- !this.fields.suffix.value
117
- ) {
127
+ const familyValue = this.fields.family.value as NodeArray | false
128
+ const givenValue = this.fields.given.value as NodeArray | false
129
+ const prefixValue = this.fields.prefix.value as NodeArray | false
130
+ const suffixValue = this.fields.suffix.value as NodeArray | false
131
+ if (!familyValue && !givenValue && !prefixValue && !suffixValue) {
118
132
  return false
119
133
  }
120
- const returnObject = {
121
- family: this.fields.family.value
122
- ? this.fields.family.value
123
- : [],
124
- given: this.fields.given.value ? this.fields.given.value : []
134
+ const returnObject: NameDictObject = {
135
+ family: familyValue ? familyValue : [],
136
+ given: givenValue ? givenValue : []
125
137
  }
126
- if (this.fields.prefix.value) {
127
- returnObject["prefix"] = this.fields.prefix.value
128
- returnObject["useprefix"] =
138
+ if (prefixValue) {
139
+ returnObject["prefix"] = prefixValue
140
+ returnObject["useprefix"] = (
129
141
  this.typeSwitch.innerElement.querySelector(
130
142
  "input.useprefix"
131
- ).checked
132
- ? true
133
- : false
143
+ ) as HTMLInputElement
144
+ ).checked
145
+ ? true
146
+ : false
134
147
  }
135
- if (this.fields.suffix.value) {
136
- returnObject["suffix"] = this.fields.suffix.value
148
+ if (suffixValue) {
149
+ returnObject["suffix"] = suffixValue
137
150
  }
138
151
  return returnObject
139
152
  } else {
140
- if (!this.fields.literal.value) {
153
+ const literalValue = this.fields.literal.value as NodeArray | false
154
+ if (!literalValue) {
141
155
  return false
142
156
  }
143
157
  return {
144
- literal: this.fields.literal.value
158
+ literal: literalValue
145
159
  }
146
160
  }
147
161
  }
148
162
 
149
- check() {
163
+ check(): boolean {
150
164
  return true
151
165
  }
152
166
  }
@@ -0,0 +1,49 @@
1
+ import {InputList} from "fwtoolkit"
2
+ import {NameFieldForm} from "./name.js"
3
+ import type {NameDictObject} from "../../types/biblio.js"
4
+
5
+ export class NameListForm {
6
+ dom: HTMLElement
7
+ fieldHandlers: WeakMap<HTMLElement, NameFieldForm>
8
+ inputList: InputList<unknown>
9
+
10
+ constructor(dom: HTMLElement, initialValue: NameDictObject[] = []) {
11
+ this.dom = dom
12
+ this.fieldHandlers = new WeakMap()
13
+ this.inputList = new InputList<unknown>({
14
+ dom,
15
+ initialValues: initialValue as unknown[],
16
+ emptyValue: {} as NameDictObject as unknown,
17
+ renderItem: value => ({
18
+ html: `<div class="name-field"></div>`,
19
+ bind: el => {
20
+ const fieldHandler = new NameFieldForm(
21
+ el.firstElementChild as HTMLElement,
22
+ value as NameDictObject
23
+ )
24
+ fieldHandler.init()
25
+ this.fieldHandlers.set(el, fieldHandler)
26
+ }
27
+ }),
28
+ getValue: el => this.fieldHandlers.get(el)!.value
29
+ })
30
+ }
31
+
32
+ init(): void {
33
+ // InputList is already rendered by the constructor.
34
+ }
35
+
36
+ get value(): NameDictObject[] | false {
37
+ const formValue = this.inputList.values.filter(
38
+ value => value !== false
39
+ ) as NameDictObject[]
40
+ if (formValue.length === 0) {
41
+ return false
42
+ }
43
+ return formValue
44
+ }
45
+
46
+ check(): boolean {
47
+ return true
48
+ }
49
+ }
@@ -1,12 +1,19 @@
1
1
  import {TypeSwitch, getFocusIndex, setFocusIndex} from "fwtoolkit"
2
2
  import {LiteralFieldForm} from "./literal.js"
3
+ import type {NodeArray, RangeArray} from "../../types/biblio.js"
3
4
 
4
5
  // There are only range lists, no range fields in the data format. The separation
5
6
  // between RangeFieldForm and RangeListForm is for keeping consistency with other fields
6
7
  // and lists.
7
8
 
8
9
  export class RangeFieldForm {
9
- constructor(dom, initialValue = [[]]) {
10
+ currentValue: NodeArray[]
11
+ dom: HTMLElement
12
+ range: boolean
13
+ typeSwitch!: TypeSwitch
14
+ fields: Record<string, LiteralFieldForm> = {}
15
+
16
+ constructor(dom: HTMLElement, initialValue: NodeArray[] = [[]]) {
10
17
  this.currentValue = initialValue
11
18
  this.dom = dom
12
19
  // We set the mode based on whether there is one or two initial values.
@@ -17,7 +24,7 @@ export class RangeFieldForm {
17
24
  }
18
25
  }
19
26
 
20
- init() {
27
+ init(): void {
21
28
  this.typeSwitch = new TypeSwitch({
22
29
  dom: this.dom,
23
30
  label1: gettext("Single value"),
@@ -39,7 +46,7 @@ export class RangeFieldForm {
39
46
  this.drawForm()
40
47
  }
41
48
 
42
- drawForm() {
49
+ drawForm(): void {
43
50
  if (this.range) {
44
51
  this.drawRangeForm()
45
52
  } else {
@@ -47,58 +54,63 @@ export class RangeFieldForm {
47
54
  }
48
55
  }
49
56
 
50
- drawSingleValueForm() {
57
+ drawSingleValueForm(): void {
51
58
  this.fields = {}
52
59
  this.typeSwitch.innerElement.innerHTML = `<div class='single-value field-part field-part-single'></div>`
53
60
  this.fields["single"] = new LiteralFieldForm(
54
- this.typeSwitch.innerElement.querySelector(".single-value"),
55
- this.currentValue[0]
61
+ this.typeSwitch.innerElement.querySelector(
62
+ ".single-value"
63
+ ) as HTMLElement,
64
+ this.currentValue[0] as unknown as Record<string, unknown>[]
56
65
  )
57
66
  this.fields.single.init()
58
67
  }
59
68
 
60
- drawRangeForm() {
69
+ drawRangeForm(): void {
61
70
  this.fields = {}
62
71
  this.typeSwitch.innerElement.innerHTML = `
63
72
  <div class='range-from field-part field-part-huge'></div>
64
73
  <div class='range-to field-part field-part-huge'></div>
65
74
  `
66
75
  this.fields["from"] = new LiteralFieldForm(
67
- this.typeSwitch.innerElement.querySelector(".range-from"),
68
- this.currentValue[0],
76
+ this.typeSwitch.innerElement.querySelector(
77
+ ".range-from"
78
+ ) as HTMLElement,
79
+ this.currentValue[0] as unknown as Record<string, unknown>[],
69
80
  gettext("From")
70
81
  )
71
82
  this.fields.from.init()
72
83
  this.fields["to"] = new LiteralFieldForm(
73
- this.typeSwitch.innerElement.querySelector(".range-to"),
74
- this.currentValue[1],
84
+ this.typeSwitch.innerElement.querySelector(
85
+ ".range-to"
86
+ ) as HTMLElement,
87
+ this.currentValue[1] as unknown as Record<string, unknown>[],
75
88
  gettext("To")
76
89
  )
77
90
  this.fields.to.init()
78
91
  }
79
92
 
80
- get value() {
93
+ get value(): RangeArray | false {
81
94
  if (this.range) {
82
- if (!this.fields.from.value && !this.fields.to.value) {
95
+ const fromValue = this.fields.from.value as NodeArray | false
96
+ const toValue = this.fields.to.value as NodeArray | false
97
+ if (!fromValue && !toValue) {
83
98
  return false
84
99
  }
85
100
  return [
86
- this.fields.from.value
87
- ? this.fields.from.value
88
- : [{type: "text", text: ""}],
89
- this.fields.to.value
90
- ? this.fields.to.value
91
- : [{type: "text", text: ""}]
101
+ fromValue ? fromValue : ([{type: "text", text: ""}] as NodeArray),
102
+ toValue ? toValue : ([{type: "text", text: ""}] as NodeArray)
92
103
  ]
93
104
  } else {
94
- if (!this.fields.single.value) {
105
+ const singleValue = this.fields.single.value as NodeArray | false
106
+ if (!singleValue) {
95
107
  return false
96
108
  }
97
- return [this.fields.single.value]
109
+ return [singleValue]
98
110
  }
99
111
  }
100
112
 
101
- check() {
113
+ check(): boolean {
102
114
  return true
103
115
  }
104
116
  }
@@ -1,42 +1,49 @@
1
1
  import {InputList} from "fwtoolkit"
2
2
  import {RangeFieldForm} from "./range.js"
3
+ import type {NodeArray, RangeArray} from "../../types/biblio.js"
3
4
 
4
5
  export class RangeListForm {
5
- constructor(dom, initialValue = [[]]) {
6
+ dom: HTMLElement
7
+ fieldHandlers: WeakMap<HTMLElement, RangeFieldForm>
8
+ inputList: InputList<unknown>
9
+
10
+ constructor(dom: HTMLElement, initialValue: NodeArray[][] = [[]]) {
6
11
  this.dom = dom
7
12
  this.fieldHandlers = new WeakMap()
8
- this.inputList = new InputList({
13
+ this.inputList = new InputList<unknown>({
9
14
  dom,
10
- initialValues: initialValue,
15
+ initialValues: initialValue as unknown[],
11
16
  emptyValue: [],
12
17
  renderItem: value => ({
13
18
  html: `<div class="range-field"></div>`,
14
19
  bind: el => {
15
20
  const fieldHandler = new RangeFieldForm(
16
- el.firstElementChild,
17
- value
21
+ el.firstElementChild as HTMLElement,
22
+ value as NodeArray[]
18
23
  )
19
24
  fieldHandler.init()
20
25
  this.fieldHandlers.set(el, fieldHandler)
21
26
  }
22
27
  }),
23
- getValue: el => this.fieldHandlers.get(el).value
28
+ getValue: el => this.fieldHandlers.get(el)!.value
24
29
  })
25
30
  }
26
31
 
27
- init() {
32
+ init(): void {
28
33
  // InputList is already rendered by the constructor.
29
34
  }
30
35
 
31
- get value() {
32
- const formValue = this.inputList.values.filter(value => value !== false)
36
+ get value(): RangeArray[] | false {
37
+ const formValue = this.inputList.values.filter(
38
+ value => value !== false
39
+ ) as RangeArray[]
33
40
  if (formValue.length === 0) {
34
41
  return false
35
42
  }
36
43
  return formValue
37
44
  }
38
45
 
39
- check() {
46
+ check(): boolean {
40
47
  return true
41
48
  }
42
49
  }
@@ -1,15 +1,19 @@
1
1
  import TokenField from "tokenfield"
2
2
 
3
3
  export class TagListForm {
4
- constructor(dom, initialValue = []) {
4
+ dom: HTMLElement
5
+ initialValue: string[]
6
+ tokenInput!: TokenField
7
+
8
+ constructor(dom: HTMLElement, initialValue: string[] = []) {
5
9
  this.dom = dom
6
10
  this.initialValue = initialValue
7
11
  }
8
12
 
9
- init() {
13
+ init(): void {
10
14
  this.dom.innerHTML = '<input class="tags" type="text">'
11
15
  this.tokenInput = new TokenField({
12
- el: this.dom.querySelector(".tags"),
16
+ el: this.dom.querySelector(".tags") as HTMLInputElement,
13
17
  setItems: this.initialValue.map((key, index) => {
14
18
  return {id: index, name: key}
15
19
  }),
@@ -19,7 +23,7 @@ export class TagListForm {
19
23
  })
20
24
  }
21
25
 
22
- get value() {
26
+ get value(): string[] | false {
23
27
  const formValue = this.tokenInput.getItems().map(item => {
24
28
  return item.name
25
29
  })
@@ -27,7 +31,7 @@ export class TagListForm {
27
31
  return formValue.length > 0 ? formValue : false
28
32
  }
29
33
 
30
- check() {
34
+ check(): boolean {
31
35
  return true
32
36
  }
33
37
  }
@@ -5,7 +5,9 @@ import {InlineInput, icon} from "fwtoolkit"
5
5
  import {titleSchema} from "../../schema/title.js"
6
6
 
7
7
  export class TitleFieldForm {
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: titleSchema,
11
13
  nodeType: "literal",
@@ -39,13 +41,13 @@ export class TitleFieldForm {
39
41
  })
40
42
  }
41
43
 
42
- init() {}
44
+ init(): void {}
43
45
 
44
- get value() {
46
+ get value(): Record<string, unknown>[] | false {
45
47
  return this.inlineInput.value
46
48
  }
47
49
 
48
- check() {
50
+ check(): boolean {
49
51
  return this.inlineInput.check()
50
52
  }
51
53
  }
@@ -1,7 +1,7 @@
1
1
  // Simple regex to check for a basic URL structure
2
2
  const simpleUrlRegex = /^(https?:\/\/)?[\w.-]+\.[a-z]{2,}(\/\S*)?$/i
3
3
 
4
- function isValidUrl(string) {
4
+ function isValidUrl(string: string): boolean {
5
5
  if (simpleUrlRegex.test(string)) {
6
6
  try {
7
7
  new URL(string)
@@ -14,23 +14,28 @@ function isValidUrl(string) {
14
14
  }
15
15
 
16
16
  export class URIFieldForm {
17
- constructor(dom, initialValue = "", placeHolder = "") {
17
+ dom: HTMLElement
18
+ initialValue: string
19
+ placeHolder: string
20
+
21
+ constructor(dom: HTMLElement, initialValue = "", placeHolder = "") {
18
22
  this.dom = dom
19
23
  this.initialValue = initialValue
20
24
  this.placeHolder = placeHolder
21
25
  }
22
26
 
23
- init() {
27
+ init(): void {
24
28
  this.dom.innerHTML = `<input class="uri" type="text" value="${this.initialValue}" placeholder="${this.placeHolder}">`
25
29
  }
26
30
 
27
- get value() {
28
- const formValue = this.dom.querySelector("input.uri").value
31
+ get value(): string | false {
32
+ const formValue = (this.dom.querySelector("input.uri") as HTMLInputElement)
33
+ .value
29
34
  // If the form has not been filled out, don't consider this form
30
35
  return formValue.length > 0 ? formValue : false
31
36
  }
32
37
 
33
- check() {
38
+ check(): boolean {
34
39
  const formValue = this.value
35
40
  if (formValue) {
36
41
  if (!isValidUrl(formValue)) {
@@ -1,21 +1,26 @@
1
1
  export class VerbatimFieldForm {
2
- constructor(dom, initialValue = "", placeHolder = "") {
2
+ dom: HTMLElement
3
+ initialValue: string
4
+ placeHolder: string
5
+
6
+ constructor(dom: HTMLElement, initialValue = "", placeHolder = "") {
3
7
  this.dom = dom
4
8
  this.initialValue = initialValue
5
9
  this.placeHolder = placeHolder
6
10
  }
7
11
 
8
- init() {
12
+ init(): void {
9
13
  this.dom.innerHTML = `<input class="verbatim" type="text" value="${this.initialValue}" placeholder="${this.placeHolder}">`
10
14
  }
11
15
 
12
- get value() {
13
- const formValue = this.dom.querySelector("input.verbatim").value
16
+ get value(): string | false {
17
+ const formValue = (this.dom.querySelector("input.verbatim") as HTMLInputElement)
18
+ .value
14
19
  // If the form has not been filled out, don't consider this form
15
20
  return formValue.length > 0 ? formValue : false
16
21
  }
17
22
 
18
- check() {
23
+ check(): boolean {
19
24
  return true
20
25
  }
21
26
  }