@fiduswriter/books 0.0.0-stage → 0.2.0

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 (188) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +87 -2
  3. package/css/book.css +219 -0
  4. package/dist/exporter/bits/index.d.ts +42 -0
  5. package/dist/exporter/bits/index.d.ts.map +1 -0
  6. package/dist/exporter/bits/index.js +113 -0
  7. package/dist/exporter/bits/index.js.map +1 -0
  8. package/dist/exporter/bits/templates.d.ts +7 -0
  9. package/dist/exporter/bits/templates.d.ts.map +1 -0
  10. package/dist/exporter/bits/templates.js +78 -0
  11. package/dist/exporter/bits/templates.js.map +1 -0
  12. package/dist/exporter/docx/index.d.ts +33 -0
  13. package/dist/exporter/docx/index.d.ts.map +1 -0
  14. package/dist/exporter/docx/index.js +139 -0
  15. package/dist/exporter/docx/index.js.map +1 -0
  16. package/dist/exporter/docx/render.d.ts +19 -0
  17. package/dist/exporter/docx/render.d.ts.map +1 -0
  18. package/dist/exporter/docx/render.js +123 -0
  19. package/dist/exporter/docx/render.js.map +1 -0
  20. package/dist/exporter/epub/index.d.ts +70 -0
  21. package/dist/exporter/epub/index.d.ts.map +1 -0
  22. package/dist/exporter/epub/index.js +310 -0
  23. package/dist/exporter/epub/index.js.map +1 -0
  24. package/dist/exporter/epub/templates.d.ts +65 -0
  25. package/dist/exporter/epub/templates.d.ts.map +1 -0
  26. package/dist/exporter/epub/templates.js +224 -0
  27. package/dist/exporter/epub/templates.js.map +1 -0
  28. package/dist/exporter/epub/tools.d.ts +5 -0
  29. package/dist/exporter/epub/tools.d.ts.map +1 -0
  30. package/dist/exporter/epub/tools.js +59 -0
  31. package/dist/exporter/epub/tools.js.map +1 -0
  32. package/dist/exporter/html/index.d.ts +70 -0
  33. package/dist/exporter/html/index.d.ts.map +1 -0
  34. package/dist/exporter/html/index.js +320 -0
  35. package/dist/exporter/html/index.js.map +1 -0
  36. package/dist/exporter/html/templates.d.ts +40 -0
  37. package/dist/exporter/html/templates.d.ts.map +1 -0
  38. package/dist/exporter/html/templates.js +225 -0
  39. package/dist/exporter/html/templates.js.map +1 -0
  40. package/dist/exporter/html/tools.d.ts +2 -0
  41. package/dist/exporter/html/tools.d.ts.map +1 -0
  42. package/dist/exporter/html/tools.js +23 -0
  43. package/dist/exporter/html/tools.js.map +1 -0
  44. package/dist/exporter/latex/index.d.ts +36 -0
  45. package/dist/exporter/latex/index.d.ts.map +1 -0
  46. package/dist/exporter/latex/index.js +116 -0
  47. package/dist/exporter/latex/index.js.map +1 -0
  48. package/dist/exporter/latex/templates.d.ts +4 -0
  49. package/dist/exporter/latex/templates.d.ts.map +1 -0
  50. package/dist/exporter/latex/templates.js +26 -0
  51. package/dist/exporter/latex/templates.js.map +1 -0
  52. package/dist/exporter/native/index.d.ts +22 -0
  53. package/dist/exporter/native/index.d.ts.map +1 -0
  54. package/dist/exporter/native/index.js +141 -0
  55. package/dist/exporter/native/index.js.map +1 -0
  56. package/dist/exporter/odt/index.d.ts +33 -0
  57. package/dist/exporter/odt/index.d.ts.map +1 -0
  58. package/dist/exporter/odt/index.js +133 -0
  59. package/dist/exporter/odt/index.js.map +1 -0
  60. package/dist/exporter/odt/render.d.ts +21 -0
  61. package/dist/exporter/odt/render.d.ts.map +1 -0
  62. package/dist/exporter/odt/render.js +126 -0
  63. package/dist/exporter/odt/render.js.map +1 -0
  64. package/dist/exporter/pretty.d.ts +17 -0
  65. package/dist/exporter/pretty.d.ts.map +1 -0
  66. package/dist/exporter/pretty.js +55 -0
  67. package/dist/exporter/pretty.js.map +1 -0
  68. package/dist/exporter/print/index.d.ts +25 -0
  69. package/dist/exporter/print/index.d.ts.map +1 -0
  70. package/dist/exporter/print/index.js +46 -0
  71. package/dist/exporter/print/index.js.map +1 -0
  72. package/dist/exporter/print/templates.d.ts +2 -0
  73. package/dist/exporter/print/templates.d.ts.map +1 -0
  74. package/dist/exporter/print/templates.js +5 -0
  75. package/dist/exporter/print/templates.js.map +1 -0
  76. package/dist/exporter/tools.d.ts +31 -0
  77. package/dist/exporter/tools.d.ts.map +1 -0
  78. package/dist/exporter/tools.js +177 -0
  79. package/dist/exporter/tools.js.map +1 -0
  80. package/dist/i18n.d.ts +7 -0
  81. package/dist/i18n.d.ts.map +1 -0
  82. package/dist/i18n.js +918 -0
  83. package/dist/i18n.js.map +1 -0
  84. package/dist/ids.d.ts +19 -0
  85. package/dist/ids.d.ts.map +1 -0
  86. package/dist/ids.js +27 -0
  87. package/dist/ids.js.map +1 -0
  88. package/dist/importer/native/index.d.ts +45 -0
  89. package/dist/importer/native/index.d.ts.map +1 -0
  90. package/dist/importer/native/index.js +166 -0
  91. package/dist/importer/native/index.js.map +1 -0
  92. package/dist/importer/native/reader.d.ts +32 -0
  93. package/dist/importer/native/reader.d.ts.map +1 -0
  94. package/dist/importer/native/reader.js +170 -0
  95. package/dist/importer/native/reader.js.map +1 -0
  96. package/dist/index.d.ts +4 -0
  97. package/dist/index.d.ts.map +1 -0
  98. package/dist/index.js +3 -0
  99. package/dist/index.js.map +1 -0
  100. package/dist/schema/index.d.ts +7 -0
  101. package/dist/schema/index.d.ts.map +1 -0
  102. package/dist/schema/index.js +8 -0
  103. package/dist/schema/index.js.map +1 -0
  104. package/dist/types.d.ts +171 -0
  105. package/dist/types.d.ts.map +1 -0
  106. package/dist/types.js +5 -0
  107. package/dist/types.js.map +1 -0
  108. package/dist/ui/book_dialog/dialog.d.ts +161 -0
  109. package/dist/ui/book_dialog/dialog.d.ts.map +1 -0
  110. package/dist/ui/book_dialog/dialog.js +750 -0
  111. package/dist/ui/book_dialog/dialog.js.map +1 -0
  112. package/dist/ui/book_dialog/export.d.ts +95 -0
  113. package/dist/ui/book_dialog/export.d.ts.map +1 -0
  114. package/dist/ui/book_dialog/export.js +217 -0
  115. package/dist/ui/book_dialog/export.js.map +1 -0
  116. package/dist/ui/book_dialog/index.d.ts +38 -0
  117. package/dist/ui/book_dialog/index.d.ts.map +1 -0
  118. package/dist/ui/book_dialog/index.js +36 -0
  119. package/dist/ui/book_dialog/index.js.map +1 -0
  120. package/dist/ui/book_dialog/sanity_check.d.ts +22 -0
  121. package/dist/ui/book_dialog/sanity_check.d.ts.map +1 -0
  122. package/dist/ui/book_dialog/sanity_check.js +109 -0
  123. package/dist/ui/book_dialog/sanity_check.js.map +1 -0
  124. package/dist/ui/book_dialog/templates.d.ts +76 -0
  125. package/dist/ui/book_dialog/templates.d.ts.map +1 -0
  126. package/dist/ui/book_dialog/templates.js +542 -0
  127. package/dist/ui/book_dialog/templates.js.map +1 -0
  128. package/dist/ui/book_dialog/types.d.ts +258 -0
  129. package/dist/ui/book_dialog/types.d.ts.map +1 -0
  130. package/dist/ui/book_dialog/types.js +15 -0
  131. package/dist/ui/book_dialog/types.js.map +1 -0
  132. package/locale/ar/messages.json +49 -0
  133. package/locale/bg/messages.json +49 -0
  134. package/locale/cs/messages.json +49 -0
  135. package/locale/da/messages.json +49 -0
  136. package/locale/de/messages.json +49 -0
  137. package/locale/en/messages.json +49 -0
  138. package/locale/en_US/messages.json +49 -0
  139. package/locale/es/messages.json +49 -0
  140. package/locale/fr/messages.json +49 -0
  141. package/locale/it/messages.json +49 -0
  142. package/locale/ja/messages.json +49 -0
  143. package/locale/ko/messages.json +49 -0
  144. package/locale/nb/messages.json +49 -0
  145. package/locale/nl/messages.json +49 -0
  146. package/locale/pl/messages.json +49 -0
  147. package/locale/pt_BR/messages.json +49 -0
  148. package/locale/pt_PT/messages.json +49 -0
  149. package/locale/ru/messages.json +49 -0
  150. package/locale/sv/messages.json +49 -0
  151. package/locale/tr/messages.json +49 -0
  152. package/locale/zh_Hans/messages.json +49 -0
  153. package/logo.svg +10 -0
  154. package/package.json +150 -5
  155. package/src/exporter/bits/index.ts +184 -0
  156. package/src/exporter/bits/templates.ts +107 -0
  157. package/src/exporter/docx/index.ts +258 -0
  158. package/src/exporter/docx/render.ts +177 -0
  159. package/src/exporter/epub/index.ts +496 -0
  160. package/src/exporter/epub/templates.ts +403 -0
  161. package/src/exporter/epub/tools.ts +68 -0
  162. package/src/exporter/html/index.ts +479 -0
  163. package/src/exporter/html/templates.ts +362 -0
  164. package/src/exporter/html/tools.ts +26 -0
  165. package/src/exporter/latex/index.ts +190 -0
  166. package/src/exporter/latex/templates.ts +35 -0
  167. package/src/exporter/native/index.ts +238 -0
  168. package/src/exporter/odt/index.ts +230 -0
  169. package/src/exporter/odt/render.ts +181 -0
  170. package/src/exporter/pretty.ts +75 -0
  171. package/src/exporter/print/index.ts +76 -0
  172. package/src/exporter/print/templates.ts +8 -0
  173. package/src/exporter/tools.ts +270 -0
  174. package/src/global.d.ts +2 -0
  175. package/src/i18n.ts +936 -0
  176. package/src/ids.ts +27 -0
  177. package/src/importer/native/index.ts +269 -0
  178. package/src/importer/native/reader.ts +247 -0
  179. package/src/index.ts +20 -0
  180. package/src/modules.d.ts +7 -0
  181. package/src/schema/index.ts +8 -0
  182. package/src/types.ts +208 -0
  183. package/src/ui/book_dialog/dialog.ts +940 -0
  184. package/src/ui/book_dialog/export.ts +449 -0
  185. package/src/ui/book_dialog/index.ts +84 -0
  186. package/src/ui/book_dialog/sanity_check.ts +208 -0
  187. package/src/ui/book_dialog/templates.ts +736 -0
  188. package/src/ui/book_dialog/types.ts +283 -0
@@ -0,0 +1,736 @@
1
+ /**
2
+ * HTML templates of the book dialog.
3
+ *
4
+ * One function per dialog pane plus the tab strip that holds them. Field ids
5
+ * are fixed: the dialog reads them back in `./dialog.js` when saving.
6
+ */
7
+
8
+ import {LANGUAGES} from "@fiduswriter/document/schema/const"
9
+ import {escapeText, gettext, longFilePath} from "fwtoolkit"
10
+ import type {Book, BookStyle, Chapter, DocumentListEntry} from "../../types.js"
11
+ import type {BookDialogInfo, BookDialogPart} from "./types.js"
12
+
13
+ /*
14
+ * The `rights` field is a Django-backend notion. A book that has no access
15
+ * rights at all -- a local `.fidusbook` file, say -- is editable, so the
16
+ * templates only disable fields for an explicitly read-only book.
17
+ */
18
+ const isReadOnly = (book: Book): boolean => book.rights === "read"
19
+
20
+ /** A template for the basic info book template pane */
21
+ export const bookBasicInfoTemplate = ({book}: {book: Book}) =>
22
+ `<table class="fw-dialog-table">
23
+ <tbody>
24
+ <tr>
25
+ <th>
26
+ <h4 class="fw-tablerow-title">${gettext("Title")}</h4>
27
+ </th>
28
+ <td>
29
+ <input class="entry-form" type="text" id="book-title"
30
+ value="${escapeText(book.title)}"
31
+ ${isReadOnly(book) ? 'disabled="disabled"' : ""}
32
+ >
33
+ </td>
34
+ </tr>
35
+ <tr>
36
+ <th>
37
+ <h4 class="fw-tablerow-title">${gettext("Author")}</h4>
38
+ </th>
39
+ <td>
40
+ <input class="entry-form" type="text" id="book-metadata-author"
41
+ value="${escapeText(book.metadata.author ?? "")}"
42
+ ${isReadOnly(book) ? 'disabled="disabled"' : ""}
43
+ >
44
+ </td>
45
+ </tr>
46
+ <tr>
47
+ <th>
48
+ <h4 class="fw-tablerow-title">${gettext("Subtitle")}</h4>
49
+ </th>
50
+ <td>
51
+ <input class="entry-form" type="text" id="book-metadata-subtitle"
52
+ value="${escapeText(book.metadata.subtitle ?? "")}"
53
+ ${isReadOnly(book) ? 'disabled="disabled"' : ""}
54
+ >
55
+ </td>
56
+ </tr>
57
+ <tr>
58
+ <th>
59
+ <h4 class="fw-tablerow-title">${gettext("Version")}</h4>
60
+ </th>
61
+ <td>
62
+ <input class="entry-form" type="text" id="book-metadata-version"
63
+ value="${escapeText(book.metadata.version ?? "")}"
64
+ ${isReadOnly(book) ? 'disabled="disabled"' : ""}
65
+ >
66
+ </td>
67
+ </tr>
68
+ <tr>
69
+ <th>
70
+ <h4 class="fw-tablerow-title">${gettext("Language")}</h4>
71
+ </th>
72
+ <td>
73
+ <div class="fw-select-container">
74
+ <select class="entry-form dk fw-button fw-light fw-large" name="book-settings-language"
75
+ title="${gettext("Select language")}"
76
+ id="book-settings-language"
77
+ ${isReadOnly(book) ? 'disabled="disabled"' : ""}
78
+ >
79
+ ${LANGUAGES.map(
80
+ language =>
81
+ `<option value="${language[0]}"
82
+ ${
83
+ language[0] ===
84
+ book.settings.language
85
+ ? "selected"
86
+ : ""
87
+ }
88
+ >
89
+ ${escapeText(language[1])}
90
+ </option>`
91
+ ).join("")}
92
+ </select>
93
+ <div class="fw-select-arrow fa fa-caret-down"></div>
94
+ </div>
95
+ </td>
96
+ </tr>
97
+ <tr>
98
+ <th>
99
+ <h4 class="fw-tablerow-title">${gettext("Publisher")}</h4>
100
+ </th>
101
+ <td>
102
+ <input class="entry-form" type="text" id="book-metadata-publisher"
103
+ value="${escapeText(book.metadata.publisher ?? "")}"
104
+ ${isReadOnly(book) ? 'disabled="disabled"' : ""}
105
+ >
106
+ </td>
107
+ </tr>
108
+ <tr>
109
+ <th>
110
+ <h4 class="fw-tablerow-title">${gettext(
111
+ "Copyright notice"
112
+ )}</h4>
113
+ </th>
114
+ <td>
115
+ <input class="entry-form" type="text" id="book-metadata-copyright"
116
+ value="${escapeText(book.metadata.copyright ?? "")}"
117
+ ${isReadOnly(book) ? 'disabled="disabled"' : ""}
118
+ >
119
+ </td>
120
+ </tr>
121
+ <tr>
122
+ <th>
123
+ <h4 class="fw-tablerow-title" title="${gettext(
124
+ "Comma separated keywords"
125
+ )}">
126
+ ${gettext("Keywords")}
127
+ </h4>
128
+ </th>
129
+ <td>
130
+ <input class="entry-form" type="text" id="book-metadata-keywords"
131
+ value="${book.metadata.keywords}"
132
+ ${isReadOnly(book) ? 'disabled="disabled"' : ""}
133
+ >
134
+ </td>
135
+ </tr>
136
+ <tr>
137
+ <th>
138
+ <h4 class="fw-tablerow-title">${gettext("Description")}</h4>
139
+ </th>
140
+ <td>
141
+ <textarea class="entry-form" id="book-metadata-description" rows="4"
142
+ ${isReadOnly(book) ? 'disabled="disabled"' : ""}
143
+ >${escapeText(book.metadata.description ?? "")}</textarea>
144
+ </td>
145
+ </tr>
146
+ <tr>
147
+ <th>
148
+ <h4 class="fw-tablerow-title">${gettext("ISBN")}</h4>
149
+ </th>
150
+ <td>
151
+ <input class="entry-form" type="text" id="book-metadata-isbn"
152
+ value="${escapeText(book.metadata.isbn ?? "")}"
153
+ ${isReadOnly(book) ? 'disabled="disabled"' : ""}
154
+ >
155
+ </td>
156
+ </tr>
157
+ <tr>
158
+ <th>
159
+ <h4 class="fw-tablerow-title" title="${gettext("E.g.: 2024 or January 2024")}">
160
+ ${gettext("Publication date")}
161
+ </h4>
162
+ </th>
163
+ <td>
164
+ <input class="entry-form" type="text" id="book-metadata-publication-date"
165
+ value="${escapeText(book.metadata.publication_date ?? "")}"
166
+ placeholder="${gettext("E.g.: 2024")}"
167
+ ${isReadOnly(book) ? 'disabled="disabled"' : ""}
168
+ >
169
+ </td>
170
+ </tr>
171
+ <tr>
172
+ <th>
173
+ <h4 class="fw-tablerow-title">${gettext("Series title")}</h4>
174
+ </th>
175
+ <td>
176
+ <input class="entry-form" type="text" id="book-metadata-series-title"
177
+ value="${escapeText(book.metadata.series_title ?? "")}"
178
+ ${isReadOnly(book) ? 'disabled="disabled"' : ""}
179
+ >
180
+ </td>
181
+ </tr>
182
+ <tr>
183
+ <th>
184
+ <h4 class="fw-tablerow-title">${gettext("Series position")}</h4>
185
+ </th>
186
+ <td>
187
+ <input class="entry-form" type="text" id="book-metadata-series-position"
188
+ value="${escapeText(book.metadata.series_position ?? "")}"
189
+ ${isReadOnly(book) ? 'disabled="disabled"' : ""}
190
+ >
191
+ </td>
192
+ </tr>
193
+ </tbody>
194
+ </table>`
195
+
196
+ /** A template for the citation style pane of the book dialog */
197
+ export const bookBibliographyDataTemplate = ({
198
+ book,
199
+ citationStyles
200
+ }: {
201
+ book: Book
202
+ /** Citation style catalog: style id → human-readable title. */
203
+ citationStyles: Record<string, string>
204
+ }) =>
205
+ `<table class="fw-dialog-table">
206
+ <tbody>
207
+ <tr>
208
+ <th>
209
+ <h4 class="fw-tablerow-title">${gettext("Citation style")}</h4>
210
+ </th>
211
+ <td>
212
+ <div class="fw-select-container">
213
+ <select class="entry-form dk fw-button fw-light fw-large" name="book-settings-citationstyle"
214
+ title="${gettext(
215
+ "Select citation style for the book"
216
+ )}"
217
+ id="book-settings-citationstyle"
218
+ ${isReadOnly(book) ? 'disabled="disabled"' : ""}
219
+ >
220
+ ${Object.entries(citationStyles)
221
+ .map(
222
+ ([key, value]) =>
223
+ `<option value="${key}" ${
224
+ key === book.settings.citationstyle
225
+ ? "selected"
226
+ : ""
227
+ }>
228
+ ${value}
229
+ </option>`
230
+ )
231
+ .join("")}
232
+ </select>
233
+ <div class="fw-select-arrow fa fa-caret-down"></div>
234
+ </div>
235
+ </td>
236
+ </tr>
237
+ </tbody>
238
+ </table>`
239
+
240
+ const paperSizes = [
241
+ ["folio", gettext("Folio (15 x 12 inch)")],
242
+ ["quarto", gettext("Quarto (12 × 9 inch)")],
243
+ ["octavo", gettext("Octavo (9 x 6 inch)")],
244
+ ["a5", gettext("A5")],
245
+ ["a4", gettext("A4")]
246
+ ]
247
+
248
+ /** A template for the print related data pane of the book dialog */
249
+ export const bookPrintDataTemplate = ({
250
+ book,
251
+ bookStyleList
252
+ }: {
253
+ book: Book
254
+ bookStyleList: BookStyle[]
255
+ }) =>
256
+ `<table class="fw-dialog-table">
257
+ <tbody>
258
+ <tr>
259
+ <th>
260
+ <h4 class="fw-tablerow-title">${gettext("Book style")}</h4>
261
+ </th>
262
+ <td>
263
+ <div class="fw-select-container">
264
+ <select class="entry-form dk fw-button fw-light fw-large" name="book-settings-bookstyle"
265
+ title="${gettext(
266
+ "Select stylesheet for the book"
267
+ )}"
268
+ id="book-settings-bookstyle"
269
+ ${
270
+ isReadOnly(book) || !bookStyleList.length
271
+ ? 'disabled="disabled"'
272
+ : ""
273
+ }
274
+ >
275
+ ${bookStyleList
276
+ .map(
277
+ (bookStyle: BookStyle) =>
278
+ `<option value="${bookStyle.slug}"
279
+ ${
280
+ bookStyle.slug ===
281
+ book.settings.book_style
282
+ ? "selected"
283
+ : ""
284
+ }
285
+ >
286
+ ${escapeText((bookStyle.title as string) ?? "")}
287
+ </option>`
288
+ )
289
+ .join("")}
290
+ </select>
291
+ <div class="fw-select-arrow fa fa-caret-down"></div>
292
+ </div>
293
+ </td>
294
+ </tr>
295
+ <tr>
296
+ <th>
297
+ <h4 class="fw-tablerow-title">${gettext("Paper size")}</h4>
298
+ </th>
299
+ <td>
300
+ <div class="fw-select-container">
301
+ <select class="entry-form dk fw-button fw-light fw-large" name="book-settings-papersize"
302
+ title="${gettext(
303
+ "Select paper size for the book"
304
+ )}"
305
+ id="book-settings-papersize"
306
+ ${isReadOnly(book) ? 'disabled="disabled"' : ""}
307
+ >
308
+ ${paperSizes
309
+ .map(
310
+ size =>
311
+ `<option value="${size[0]}" ${
312
+ size[0] ===
313
+ book.settings.papersize
314
+ ? "selected"
315
+ : ""
316
+ }>
317
+ ${size[1]}
318
+ </option>`
319
+ )
320
+ .join("")}
321
+ </select>
322
+ <div class="fw-select-arrow fa fa-caret-down"></div>
323
+ </div>
324
+ </td>
325
+ </tr>
326
+ </tbody>
327
+ </table>`
328
+
329
+ /** A template for the cover image input on the epub pane of the book dialog. */
330
+ export const bookEpubDataCoverTemplate = ({
331
+ book,
332
+ imageDB
333
+ }: {
334
+ book: Book
335
+ imageDB: BookDialogInfo["imageDB"]
336
+ }) =>
337
+ `<th class="figure-preview-row">
338
+ <h4 class="fw-tablerow-title">${gettext("Cover image")}</h4>
339
+ </th>
340
+ <td>
341
+ ${
342
+ book.cover_image
343
+ ? `<div class="img" style="background-image: url(${
344
+ imageDB.db[book.cover_image].image
345
+ });" title="${gettext("Cover image")}"></div>`
346
+ : ""
347
+ }
348
+ </td>
349
+ ${
350
+ isReadOnly(book)
351
+ ? ""
352
+ : `<td class="figure-preview-row">
353
+ <button type="button" class="fw-dialog-titlebar-button ui-widget ui-state-default
354
+ ui-corner-all ui-button-text-only fw-button fw-dark"
355
+ id="select-cover-image-button" role="button" aria-disabled="false" title="${gettext(
356
+ "Select a cover image"
357
+ )}">
358
+ <span class="ui-button-text">${gettext("Select Image")}</span>
359
+ </button>
360
+ ${
361
+ book.cover_image
362
+ ? `<button type="button" class="fw-dialog-titlebar-button ui-widget ui-state-default
363
+ ui-corner-all ui-button-text-only fw-button fw-orange"
364
+ id="remove-cover-image-button" role="button" aria-disabled="false" title="${gettext(
365
+ "Remove cover image"
366
+ )}">
367
+ <span class="ui-button-text">${gettext("Remove Image")}</span>
368
+ </button>`
369
+ : ""
370
+ }
371
+ </td>`
372
+ }`
373
+
374
+ /** A template for the epub related data pane of the book dialog */
375
+ export const bookEpubDataTemplate = ({
376
+ book,
377
+ imageDB
378
+ }: {
379
+ book: Book
380
+ imageDB: BookDialogInfo["imageDB"]
381
+ }) =>
382
+ `<table class="fw-dialog-table fw-media-uploader">
383
+ <tbody>
384
+ <tr id="cover-preview-row">
385
+ ${bookEpubDataCoverTemplate({
386
+ book,
387
+ imageDB
388
+ })}
389
+ </tr>
390
+ </tbody>
391
+ </table>`
392
+
393
+ /** A template for the ODT template row of the book dialog. */
394
+ export const bookODTDataRowTemplate = ({book}: {book: Book}) =>
395
+ `<th class="odt-file-row">
396
+ <h4 class="fw-tablerow-title">${gettext("ODT Template")}</h4>
397
+ </th>
398
+ <td>
399
+ ${
400
+ book.odt_template
401
+ ? `<a href="${book.odt_template}" id="odt-template-file-url" download>${escapeText(
402
+ book.odt_template
403
+ )}</a>`
404
+ : ""
405
+ }
406
+ </td>
407
+ ${
408
+ isReadOnly(book)
409
+ ? ""
410
+ : `<td class="odt-template-row">
411
+ <button type="button" class="fw-dialog-titlebar-button ui-widget ui-state-default
412
+ ui-corner-all ui-button-text-only fw-button fw-dark"
413
+ id="select-odt-template" role="button" aria-disabled="false"
414
+ title="${gettext("Select an ODT template file")}">
415
+ <span class="ui-button-text">${gettext(
416
+ "Select ODT template file"
417
+ )}</span>
418
+ </button>
419
+ <input type="file" id="input-odt-template" accept=".odt" class="fw-media-file-input">
420
+ ${
421
+ book.odt_template
422
+ ? `<button type="button" class="fw-dialog-titlebar-button ui-widget ui-state-default
423
+ ui-corner-all ui-button-text-only fw-button fw-orange"
424
+ id="remove-odt-template-button" role="button" aria-disabled="false"
425
+ title="${gettext("Remove ODT template file")}">
426
+ <span class="ui-button-text">
427
+ ${gettext("Remove ODT template file")}
428
+ </span>
429
+ </button>`
430
+ : ""
431
+ }
432
+ </td>`
433
+ }`
434
+
435
+ /** A template for the ODT related data pane of the book dialog */
436
+ export const bookODTDataTemplate = ({book}: {book: Book}) =>
437
+ `<table class="fw-dialog-table">
438
+ <tbody>
439
+ <tr id="odt-template-row">
440
+ ${bookODTDataRowTemplate({book})}
441
+ </tr>
442
+ </tbody>
443
+ </table>`
444
+
445
+ /** A template for the DOCX template row of the book dialog. */
446
+ export const bookDOCXDataRowTemplate = ({book}: {book: Book}) =>
447
+ `<th class="docx-file-row">
448
+ <h4 class="fw-tablerow-title">${gettext("DOCX Template")}</h4>
449
+ </th>
450
+ <td>
451
+ ${
452
+ book.docx_template
453
+ ? `<a href="${book.docx_template}" id="docx-template-file-url" download>${escapeText(
454
+ book.docx_template
455
+ )}</a>`
456
+ : ""
457
+ }
458
+ </td>
459
+ ${
460
+ isReadOnly(book)
461
+ ? ""
462
+ : `<td class="docx-template-row">
463
+ <button type="button" class="fw-dialog-titlebar-button ui-widget ui-state-default
464
+ ui-corner-all ui-button-text-only fw-button fw-dark"
465
+ id="select-docx-template" role="button" aria-disabled="false"
466
+ title="${gettext("Select an DOCX template file")}">
467
+ <span class="ui-button-text">${gettext(
468
+ "Select DOCX template file"
469
+ )}</span>
470
+ </button>
471
+ <input type="file" id="input-docx-template" accept=".docx" class="fw-media-file-input">
472
+ ${
473
+ book.docx_template
474
+ ? `<button type="button" class="fw-dialog-titlebar-button ui-widget ui-state-default
475
+ ui-corner-all ui-button-text-only fw-button fw-orange"
476
+ id="remove-docx-template-button" role="button" aria-disabled="false"
477
+ title="${gettext("Remove DOCX template file")}">
478
+ <span class="ui-button-text">
479
+ ${gettext("Remove DOCX template file")}
480
+ </span>
481
+ </button>`
482
+ : ""
483
+ }
484
+ </td>`
485
+ }`
486
+
487
+ /** A template for the DOCX related data pane of the book dialog */
488
+ export const bookDOCXDataTemplate = ({book}: {book: Book}) =>
489
+ `<table class="fw-dialog-table">
490
+ <tbody>
491
+ <tr id="docx-template-row">
492
+ ${bookDOCXDataRowTemplate({book})}
493
+ </tr>
494
+ </tbody>
495
+ </table>`
496
+
497
+ /** A template for the sanity check pane of the book dialog */
498
+ export const bookSanityCheckTemplate = () =>
499
+ `<table class="fw-dialog-table">
500
+ <tbody>
501
+ <tr>
502
+ <th>
503
+ <button type="button" id="perform-sanity-check-button" class="fw-dialog-titlebar-button fw-button fw-dark">${gettext(
504
+ "Perform sanity check"
505
+ )}</button>
506
+ </th>
507
+ <td id="sanity-check-output"></td>
508
+ </tr>
509
+ </tbody>
510
+ </table>`
511
+
512
+ /** A template for the book dialog. */
513
+ export const bookDialogTemplate = ({
514
+ title,
515
+ bookInfo,
516
+ dialogParts
517
+ }: {
518
+ title: string
519
+ bookInfo: BookDialogInfo
520
+ dialogParts: BookDialogPart[]
521
+ }) =>
522
+ `<div id="book-dialog" title="${title}">
523
+ <div id="bookoptions-tab">
524
+ <ul class="fw-tabs-nav">
525
+ ${dialogParts
526
+ .map(
527
+ (part, index) =>
528
+ `<li class="fw-tab-link ${index === 0 ? "fw-current-tab" : ""}">
529
+ <a href="#optionTab${index}" class="fw-tab-link-inner" title="${escapeText(
530
+ part.description
531
+ )}">
532
+ ${escapeText(part.title)}
533
+ </a>
534
+ </li>`
535
+ )
536
+ .join("")}
537
+ </ul>
538
+ ${dialogParts
539
+ .map(
540
+ (part, index) =>
541
+ `<div class="tab-content fw-tabs-panel" id="optionTab${index}" title="${escapeText(
542
+ part.description
543
+ )}">
544
+ ${part.template(bookInfo)}
545
+ </div>`
546
+ )
547
+ .join("")}
548
+ </div>
549
+ </div>`
550
+
551
+ /** A template for the chapter pane of the book dialog. */
552
+ export const bookDialogChaptersTemplate = ({
553
+ book,
554
+ documentList,
555
+ canPickChapters,
556
+ canOpenChapters,
557
+ chapterCatalog
558
+ }: {
559
+ book: Book
560
+ documentList: DocumentListEntry[]
561
+ canPickChapters?: boolean
562
+ canOpenChapters?: boolean
563
+ chapterCatalog?: boolean
564
+ }) => {
565
+ const hasEncryptedChapters = book.chapters.some(
566
+ chapter => documentList.find(doc => doc.id === chapter.text)?.e2ee
567
+ )
568
+ return `${
569
+ isReadOnly(book)
570
+ ? ""
571
+ : chapterCatalog
572
+ ? `<div class="fw-ar-container">
573
+ <h3 class="fw-green-title">${gettext("My documents")}</h3>
574
+ <div id="book-document-list"></div>
575
+ </div>
576
+ <span id="add-chapter" class="fw-button fw-large fw-square fw-light fw-ar-button">
577
+ <i class="fas fa-caret-right"></i>
578
+ </span>${
579
+ canPickChapters
580
+ ? `<span id="add-chapter-file" class="fw-button fw-large fw-square fw-light fw-ar-button" title="${gettext("Pick document files and add them as chapters")}">
581
+ <i class="fas fa-file-circle-plus"></i>
582
+ </span>`
583
+ : ""
584
+ }`
585
+ : canPickChapters
586
+ ? `<div class="fw-ar-container">
587
+ <span id="add-chapter-file" class="fw-button fw-light">
588
+ <i class="fas fa-plus"></i>&nbsp;${gettext("Add chapters from files")}
589
+ </span>
590
+ </div>`
591
+ : ""
592
+ }
593
+ <div class="fw-ar-container">
594
+ <h3 class="fw-green-title">${gettext("Book chapters")}</h3>
595
+ <table class="fw-data-table">
596
+ <thead class="fw-data-table-header">
597
+ <tr>
598
+ <th colspan="2">${gettext("Title")}</th>
599
+ <th colspan="2">${gettext("Sort")}</th>
600
+ ${isReadOnly(book) ? "" : "<th>&emsp;</th>"}
601
+ </tr>
602
+ </thead>
603
+ <tbody class="fw-data-table-body fw-small" id="book-chapter-list">
604
+ ${bookChapterListTemplate({
605
+ book,
606
+ documentList,
607
+ canOpenChapters
608
+ })}
609
+ </tbody>
610
+ </table>
611
+ ${
612
+ hasEncryptedChapters
613
+ ? `<p class="fw-note e2ee-chapter-notice">
614
+ <i class="fas fa-lock"></i>
615
+ ${gettext("This book contains encrypted chapters. A personal passphrase is required to export or run a sanity check on this book.")}
616
+ </p>`
617
+ : ""
618
+ }
619
+ </div>`
620
+ }
621
+
622
+ /** A template for the chapter list on the chapter pane the book dialog. */
623
+ export const bookChapterListTemplate = ({
624
+ book,
625
+ documentList,
626
+ canOpenChapters
627
+ }: {
628
+ book: Book
629
+ documentList: DocumentListEntry[]
630
+ canOpenChapters?: boolean
631
+ }) => {
632
+ let partCounter = 1
633
+ return book.chapters
634
+ .slice()
635
+ .sort((a: Chapter, b: Chapter) => a.number - b.number)
636
+ .map((chapter: Chapter, index: number, array: Chapter[]) => {
637
+ const doc = documentList.find(doc => doc.id === chapter.text)
638
+ return `<tr
639
+ ${doc ? "" : 'class="noaccess"'}
640
+ >
641
+ <td width="222" data-id="${
642
+ chapter.text
643
+ }" class="fw-checkable-td" ${
644
+ doc
645
+ ? `title="${longFilePath(
646
+ doc.title ?? "",
647
+ doc.path ?? ""
648
+ )}"`
649
+ : ""
650
+ }>
651
+ <span class="fw-inline">
652
+ ${doc ? "" : '<i class="fas fa-minus-circle"></i>'}
653
+ ${doc && doc.missing ? `<i class="fas fa-triangle-exclamation missing-chapter-icon" title="${gettext("The chapter's source file could not be found")}"></i>` : ""}
654
+ ${doc && doc.e2ee ? `<i class="fas fa-lock e2ee-chapter-icon" title="${gettext("Encrypted document")}"></i>` : ""}
655
+ ${
656
+ (chapter.part ?? "").length
657
+ ? `<b class="part">
658
+ ${partCounter++}. ${gettext("Book part")}:
659
+ ${escapeText(chapter.part ?? "")}
660
+ </b>
661
+ <br>`
662
+ : ""
663
+ }
664
+ ${chapter.number}
665
+ ${
666
+ doc
667
+ ? `<span${
668
+ canOpenChapters && !doc.missing
669
+ ? ` class="open-chapter fw-link-text" data-id="${chapter.text}" title="${gettext("Open document")}"`
670
+ : ""
671
+ }>${
672
+ doc.title
673
+ ? escapeText(doc.title)
674
+ : gettext("Untitled")
675
+ }</span>`
676
+ : gettext("No access")
677
+ }
678
+ </span>
679
+ </td>
680
+ ${
681
+ isReadOnly(book)
682
+ ? ""
683
+ : `<td width="30" data-id="${chapter.text}" class="edit-chapter">
684
+ <i class="fas fa-pencil-alt fw-link-text"></i>
685
+ </td>
686
+ ${
687
+ index === 0
688
+ ? '<td width="10"></td>'
689
+ : `<td width="10" class="book-sort-up" data-id="${chapter.text}">
690
+ <i class="fas fa-sort-up"></i>
691
+ </td>`
692
+ }
693
+ ${
694
+ index + 1 === array.length
695
+ ? '<td width="10"></td>'
696
+ : `<td width="10" class="book-sort-down" data-id="${chapter.text}">
697
+ <i class="fas fa-sort-down"></i>
698
+ </td>`
699
+ }
700
+ <td width="50" align="center">
701
+ <span class="delete-chapter fw-inline" data-id="${
702
+ chapter.text
703
+ }">
704
+ <i class="fas fa-trash-alt fw-link-text"></i>
705
+ </span>
706
+ </td>`
707
+ }${
708
+ isReadOnly(book)
709
+ ? `<td width="30"></td>
710
+ <td width="10"></td>
711
+ <td width="10"></td>
712
+ <td width="50"></td>`
713
+ : ""
714
+ }
715
+ </tr>`
716
+ })
717
+ .join("")
718
+ }
719
+
720
+ /** A template for the chapter dialog for books */
721
+ export const bookChapterDialogTemplate = ({chapter}: {chapter: Chapter}) =>
722
+ `<table class="fw-dialog-table">
723
+ <tr>
724
+ <th>
725
+ <h4 title="${gettext(
726
+ "If this chapter starts a part of the book, specify the title of that part here"
727
+ )}">
728
+ ${gettext("Book part title")}
729
+ </h4>
730
+ </th>
731
+ <td>
732
+ <input type="text" id="book-chapter-part"
733
+ value="${escapeText(chapter.part ?? "")}">
734
+ </td>
735
+ </tr>
736
+ </table>`