@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,449 @@
1
+ /**
2
+ * Book export initiation.
3
+ *
4
+ * Wraps every book exporter of this package in the chapter-data preloading
5
+ * and progress reporting the dialog's export menu needs, and delivers the
6
+ * resulting Blob through the host-supplied
7
+ * {@link BookExportContext.deliver}.
8
+ *
9
+ * The exporters themselves are environment-agnostic: they load chapter data
10
+ * through injected strategies (defaulting to no-ops) and simply return the
11
+ * produced Blob. Preloading here with the host's `chapterLoader`/`e2ee` makes
12
+ * the exporters' own internal `getMissingChapterData` call a no-op.
13
+ */
14
+
15
+ import type {ProgressCallback} from "@fiduswriter/document/exporter/tools/progress"
16
+ import {BITSBookExporter} from "../../exporter/bits/index.js"
17
+ import {DOCXBookExporter} from "../../exporter/docx/index.js"
18
+ import {EpubBookExporter} from "../../exporter/epub/index.js"
19
+ import {HTMLBookExporter} from "../../exporter/html/index.js"
20
+ import {LatexBookExporter} from "../../exporter/latex/index.js"
21
+ import {NativeBookExporter} from "../../exporter/native/index.js"
22
+ import {ODTBookExporter} from "../../exporter/odt/index.js"
23
+ import {PrintBookExporter} from "../../exporter/print/index.js"
24
+ import {getMissingChapterData} from "../../exporter/tools.js"
25
+ import type {Book, DocumentListEntry} from "../../types.js"
26
+ import {addAlert, addProgress, gettext} from "fwtoolkit"
27
+ import type {ContentMenuInit} from "fwtoolkit/content_menu"
28
+ import type {BookExportContext} from "./types.js"
29
+
30
+ /**
31
+ * The subset of a book exporter this module needs. Every exporter of
32
+ * `@fiduswriter/books` exposes these members; the declared return
33
+ * type of `init()` differs slightly between them (some return `false`, some
34
+ * `void`, instead of a Blob), so it is kept loose here. `mimeType` likewise
35
+ * only exists on the DOCX/ODT exporters, which read it off the instance.
36
+ */
37
+ export interface BookExporterLike {
38
+ book: Book
39
+ defaultFilename: string
40
+ // Declared inconsistently across the exporters: some resolve to `false`
41
+ // or nothing, and BITS/DOCX/ODT can return `false` synchronously.
42
+ init(
43
+ progressCallback?: ProgressCallback
44
+ ): Promise<Blob | false | void> | false
45
+ }
46
+
47
+ /**
48
+ * Arguments passed to the callbacks of the single-book export menu. The
49
+ * dialog assembles them once and hands them to every entry.
50
+ */
51
+ export interface BookExportMenuArgs {
52
+ /**
53
+ * Persist the book before exporting. Receives the id of the export that
54
+ * triggered it; a host that hands the session to a new window on the
55
+ * first save (untitled book promotion) resolves falsy there and resumes
56
+ * the export itself, so the menu must not run it again in this window.
57
+ */
58
+ saveBook: (exportId?: string) => Promise<unknown>
59
+ book: Book
60
+ documentList: DocumentListEntry[]
61
+ context: BookExportContext
62
+ }
63
+
64
+ /** Ids of the book export menu entries, stable across translations. */
65
+ export type BookExportId =
66
+ | "bits"
67
+ | "epub"
68
+ | "html"
69
+ | "unified-html"
70
+ | "latex"
71
+ | "docx"
72
+ | "odt"
73
+ | "print"
74
+ | "fidusbook"
75
+
76
+ /**
77
+ * Run the export behind a menu entry, looked up by id. Hosts that resume an
78
+ * export after an untitled-book promotion use this to re-run the chosen
79
+ * export in the new window.
80
+ */
81
+ export const runBookExportAction = (
82
+ id: BookExportId,
83
+ args: BookExportMenuArgs
84
+ ): void => {
85
+ const {book, documentList, context} = args
86
+ switch (id) {
87
+ case "bits":
88
+ exportBITS(book, documentList, context)
89
+ break
90
+ case "epub":
91
+ exportEpub(book, documentList, context)
92
+ break
93
+ case "html":
94
+ exportHTML(book, documentList, context, true)
95
+ break
96
+ case "unified-html":
97
+ exportSingleHTML(book, documentList, context)
98
+ break
99
+ case "latex":
100
+ exportLatex(book, documentList, context)
101
+ break
102
+ case "docx":
103
+ exportDOCX(book, documentList, context)
104
+ break
105
+ case "odt":
106
+ exportODT(book, documentList, context)
107
+ break
108
+ case "print":
109
+ exportPrint(book, documentList, context)
110
+ break
111
+ case "fidusbook":
112
+ exportFidusbook(book, documentList, context)
113
+ break
114
+ }
115
+ }
116
+
117
+ /** One export menu entry: persists the book, then exports (unless the save
118
+ * resolved falsy, meaning a host handed the session over and resumes the
119
+ * export in the new window itself). */
120
+ const exportAction =
121
+ (id: BookExportId) =>
122
+ (page: unknown): void => {
123
+ const args = page as BookExportMenuArgs
124
+ args.saveBook(id).then(result => {
125
+ if (result) {
126
+ runBookExportAction(id, args)
127
+ }
128
+ })
129
+ }
130
+
131
+ /** Model of the book dialog's export menu (a content menu of actions). */
132
+ export type BookExportMenu = ContentMenuInit
133
+
134
+ /**
135
+ * Load any missing chapter data (fetching content lazily and decrypting E2EE
136
+ * chapters), run the given exporter, then hand the resulting Blob to the
137
+ * host's `deliver`.
138
+ *
139
+ * @param exporter - A constructed book exporter instance.
140
+ * @param documentList - Document entries for the book's chapters.
141
+ * @param context - The host's schema, chapter loader, E2EE strategy and
142
+ * delivery callback.
143
+ * @param mimeType - MIME type of the produced file.
144
+ * @param rawContent - Whether the exporter needs doc.rawContent.
145
+ */
146
+ export const runBookExport = (
147
+ exporter: BookExporterLike,
148
+ documentList: DocumentListEntry[],
149
+ context: BookExportContext,
150
+ mimeType: string,
151
+ rawContent = false
152
+ ): Promise<unknown> => {
153
+ const {schema, chapterLoader, e2ee, deliver} = context
154
+ const formatName =
155
+ exporter.defaultFilename.split(".").pop()?.toUpperCase() ||
156
+ gettext("Book")
157
+ const task = addProgress(
158
+ "info",
159
+ `${exporter.book.title}: ${gettext("Exporting")} ${formatName}...`,
160
+ {autoClose: 6000}
161
+ )
162
+ const progressCallback: ProgressCallback = (message, percentage) =>
163
+ task.update(percentage ?? null, message)
164
+
165
+ return getMissingChapterData(exporter.book, documentList, schema, {
166
+ rawContent,
167
+ loader: chapterLoader,
168
+ e2ee,
169
+ progressCallback
170
+ })
171
+ .then(() => exporter.init(progressCallback))
172
+ .then(blob => {
173
+ task.update(100, gettext("Export complete."))
174
+ if (blob) {
175
+ const extension = `.${exporter.defaultFilename.split(".").pop()}`
176
+ deliver(blob, exporter.defaultFilename, {
177
+ description: exporter.book.title,
178
+ mimeType,
179
+ extensions: [extension]
180
+ })
181
+ }
182
+ return blob
183
+ })
184
+ .catch((error: unknown) => {
185
+ task.close()
186
+ // fwtoolkit's `get` rejects with the Response itself on HTTP
187
+ // errors, which carries no message; surface something useful.
188
+ const message =
189
+ error instanceof Error
190
+ ? error.message
191
+ : error instanceof Response
192
+ ? `${gettext("Could not load")} ${error.url || "resource"} (HTTP ${error.status}).`
193
+ : String(error ?? "")
194
+ addAlert("error", message || gettext("Book export failed."))
195
+ })
196
+ }
197
+
198
+ /** Export a book as an Epub file. */
199
+ export const exportEpub = (
200
+ book: Book,
201
+ documentList: DocumentListEntry[],
202
+ context: BookExportContext
203
+ ) =>
204
+ runBookExport(
205
+ new EpubBookExporter(
206
+ context.schema,
207
+ context.csl,
208
+ context.bookStyles,
209
+ book,
210
+ context.user,
211
+ documentList,
212
+ bookUpdated(book)
213
+ ),
214
+ documentList,
215
+ context,
216
+ "application/epub+zip"
217
+ )
218
+
219
+ /** Export a book as a BITS (Book Interchange Tag Set) file. */
220
+ export const exportBITS = (
221
+ book: Book,
222
+ documentList: DocumentListEntry[],
223
+ context: BookExportContext
224
+ ) =>
225
+ runBookExport(
226
+ new BITSBookExporter(
227
+ context.schema,
228
+ context.csl,
229
+ book,
230
+ context.user,
231
+ documentList,
232
+ bookUpdated(book)
233
+ ),
234
+ documentList,
235
+ context,
236
+ "application/zip"
237
+ )
238
+
239
+ /** Export a book as a multi-file HTML archive. */
240
+ export const exportHTML = (
241
+ book: Book,
242
+ documentList: DocumentListEntry[],
243
+ context: BookExportContext,
244
+ multiDoc = true
245
+ ) =>
246
+ runBookExport(
247
+ new HTMLBookExporter(
248
+ context.schema,
249
+ context.csl,
250
+ context.bookStyles,
251
+ book,
252
+ context.user,
253
+ documentList,
254
+ bookUpdated(book),
255
+ multiDoc
256
+ ),
257
+ documentList,
258
+ context,
259
+ "application/zip"
260
+ )
261
+
262
+ /** Export a book as a single-file HTML archive. */
263
+ export const exportSingleHTML = (
264
+ book: Book,
265
+ documentList: DocumentListEntry[],
266
+ context: BookExportContext
267
+ ) => exportHTML(book, documentList, context, false)
268
+
269
+ /** Export a book as LaTeX. */
270
+ export const exportLatex = (
271
+ book: Book,
272
+ documentList: DocumentListEntry[],
273
+ context: BookExportContext
274
+ ) =>
275
+ runBookExport(
276
+ new LatexBookExporter(
277
+ context.schema,
278
+ book,
279
+ context.user,
280
+ documentList,
281
+ bookUpdated(book)
282
+ ),
283
+ documentList,
284
+ context,
285
+ "application/zip"
286
+ )
287
+
288
+ /** Export a book as DOCX, using the book's DOCX template. */
289
+ export const exportDOCX = (
290
+ book: Book,
291
+ documentList: DocumentListEntry[],
292
+ context: BookExportContext
293
+ ) => {
294
+ const exporter = new DOCXBookExporter(
295
+ context.schema,
296
+ context.csl,
297
+ book,
298
+ context.user,
299
+ documentList,
300
+ bookUpdated(book)
301
+ )
302
+ return runBookExport(
303
+ exporter,
304
+ documentList,
305
+ context,
306
+ exporter.mimeType,
307
+ true
308
+ )
309
+ }
310
+
311
+ /** Export a book as ODT, using the book's ODT template. */
312
+ export const exportODT = (
313
+ book: Book,
314
+ documentList: DocumentListEntry[],
315
+ context: BookExportContext
316
+ ) => {
317
+ const exporter = new ODTBookExporter(
318
+ context.schema,
319
+ context.csl,
320
+ book,
321
+ context.user,
322
+ documentList,
323
+ bookUpdated(book)
324
+ )
325
+ return runBookExport(
326
+ exporter,
327
+ documentList,
328
+ context,
329
+ exporter.mimeType,
330
+ true
331
+ )
332
+ }
333
+
334
+ /** Open a book's print/PDF view. */
335
+ export const exportPrint = (
336
+ book: Book,
337
+ documentList: DocumentListEntry[],
338
+ context: BookExportContext
339
+ ) =>
340
+ runBookExport(
341
+ new PrintBookExporter(
342
+ context.schema,
343
+ context.csl,
344
+ context.bookStyles,
345
+ book,
346
+ context.user,
347
+ documentList
348
+ ),
349
+ documentList,
350
+ context,
351
+ "text/html"
352
+ )
353
+
354
+ /** Export a book as a native `.fidusbook` file. */
355
+ export const exportFidusbook = (
356
+ book: Book,
357
+ documentList: DocumentListEntry[],
358
+ context: BookExportContext
359
+ ) =>
360
+ runBookExport(
361
+ new NativeBookExporter(
362
+ context.schema,
363
+ book,
364
+ context.user,
365
+ documentList,
366
+ bookUpdated(book)
367
+ ),
368
+ documentList,
369
+ context,
370
+ "application/vnd.fiduswriter.book+zip"
371
+ )
372
+
373
+
374
+ /** Timestamp for export archives: the book's `updated` when the host
375
+ * maintains it, otherwise now. Passing 0 (the desktop's fresh books) made
376
+ * every zip entry 1970-01-01, which zip tooling then misreads as a date in
377
+ * 2098 (DOS dates cannot represent pre-1980). */
378
+ const bookUpdated = (book: Book): number =>
379
+ book.updated || Math.floor(Date.now() / 1000)
380
+
381
+ /**
382
+ * Model of the book dialog's export menu.
383
+ *
384
+ * Every entry saves the book first, so an export always reflects what is on
385
+ * screen. The DOCX and ODT entries are disabled while the book has no
386
+ * matching template.
387
+ */
388
+ export const bookExportMenuModel = (): BookExportMenu => ({
389
+ content: [
390
+ {
391
+ type: "action",
392
+ title: gettext("Export as BITS"),
393
+ tooltip: gettext("Export book as Book Interchange Tag Set."),
394
+ action: exportAction("bits")
395
+ },
396
+ {
397
+ type: "action",
398
+ title: gettext("Export as Epub"),
399
+ tooltip: gettext("Export book as Epub."),
400
+ action: exportAction("epub")
401
+ },
402
+ {
403
+ type: "action",
404
+ title: gettext("Export as HTML"),
405
+ tooltip: gettext("Export book as HTML."),
406
+ action: exportAction("html")
407
+ },
408
+ {
409
+ type: "action",
410
+ title: gettext("Export as Unified HTML"),
411
+ tooltip: gettext("Export book as Single-file HTML."),
412
+ action: exportAction("unified-html")
413
+ },
414
+ {
415
+ type: "action",
416
+ title: gettext("Export as LaTeX"),
417
+ tooltip: gettext("Export book as LaTeX."),
418
+ action: exportAction("latex")
419
+ },
420
+ {
421
+ type: "action",
422
+ title: gettext("Export as DOCX"),
423
+ tooltip: gettext("Export book as DOCX."),
424
+ action: exportAction("docx"),
425
+ disabled: (page: unknown) => !(page as BookExportMenuArgs).book.docx_template
426
+ },
427
+ {
428
+ type: "action",
429
+ title: gettext("Export as ODT"),
430
+ tooltip: gettext("Export book as ODT."),
431
+ action: exportAction("odt"),
432
+ disabled: (page: unknown) => !(page as BookExportMenuArgs).book.odt_template
433
+ },
434
+ {
435
+ type: "action",
436
+ title: gettext("Export to Print/PDF"),
437
+ tooltip: gettext("Export book to the print dialog."),
438
+ action: exportAction("print")
439
+ },
440
+ {
441
+ type: "action",
442
+ title: gettext("Export as Fidusbook"),
443
+ tooltip: gettext(
444
+ "Export book as a .fidusbook file (for moving to another server)."
445
+ ),
446
+ action: exportAction("fidusbook")
447
+ }
448
+ ]
449
+ })
@@ -0,0 +1,84 @@
1
+ /**
2
+ * The book edit dialog.
3
+ *
4
+ * A reusable, backend-agnostic tabbed dialog for editing a book's metadata,
5
+ * settings, cover image and chapter list, running a sanity check and starting
6
+ * an export. Import it from the `@fiduswriter/books/ui/book_dialog`
7
+ * subpath so that the main entry stays free of DOM code and remains usable
8
+ * from Node (as `@fiduswriter/cli` needs).
9
+ *
10
+ * ```js
11
+ * import {BookDialog} from "@fiduswriter/books/ui/book_dialog"
12
+ *
13
+ * new BookDialog({
14
+ * book, // omit to create a new book
15
+ * documentList,
16
+ * schema,
17
+ * chapterLoader, // @fiduswriter/books
18
+ * e2ee, // @fiduswriter/books
19
+ * backend: {
20
+ * saveBook: book => postJson("/api/book/save/", {book}),
21
+ * selectCoverImage: id => showImagePicker(id),
22
+ * saveDocxTemplate: (book, file) => uploadTemplate(book, file)
23
+ * },
24
+ * exportContext: {schema, chapterLoader, e2ee, csl, bookStyles, user, deliver: saveFile}
25
+ * }).open()
26
+ * ```
27
+ *
28
+ * `ChapterLoader` and `E2EEStrategy` are the same interfaces the book
29
+ * exporters already accept, so a host that can export a book needs no extra
30
+ * wiring to run a sanity check.
31
+ */
32
+
33
+ export {BookDialog} from "./dialog.js"
34
+ export {
35
+ bookSanityCheck
36
+ } from "./sanity_check.js"
37
+ export {
38
+ bookBasicInfoTemplate,
39
+ bookBibliographyDataTemplate,
40
+ bookChapterDialogTemplate,
41
+ bookChapterListTemplate,
42
+ bookDialogChaptersTemplate,
43
+ bookDialogTemplate,
44
+ bookDOCXDataRowTemplate,
45
+ bookDOCXDataTemplate,
46
+ bookEpubDataCoverTemplate,
47
+ bookEpubDataTemplate,
48
+ bookODTDataRowTemplate,
49
+ bookODTDataTemplate,
50
+ bookPrintDataTemplate,
51
+ bookSanityCheckTemplate
52
+ } from "./templates.js"
53
+ export {
54
+ bookExportMenuModel,
55
+ exportBITS,
56
+ exportDOCX,
57
+ exportEpub,
58
+ exportFidusbook,
59
+ exportHTML,
60
+ exportLatex,
61
+ exportODT,
62
+ exportPrint,
63
+ exportSingleHTML,
64
+ runBookExport,
65
+ runBookExportAction
66
+ } from "./export.js"
67
+ export type {
68
+ BookExportId,
69
+ BookExportMenu,
70
+ BookExportMenuArgs,
71
+ BookExporterLike
72
+ } from "./export.js"
73
+ export type {
74
+ BookDataContext,
75
+ BookDialogBackend,
76
+ BookDialogButton,
77
+ BookDialogCoverImage,
78
+ BookDialogImageDB,
79
+ BookDialogInfo,
80
+ BookDialogOptions,
81
+ BookDialogPart,
82
+ BookExportContext,
83
+ BookExportDeliverer
84
+ } from "./types.js"