@fiduswriter/books 0.0.0-stage → 0.2.1
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.
- package/LICENSE +661 -0
- package/README.md +87 -2
- package/css/book.css +219 -0
- package/dist/exporter/bits/index.d.ts +42 -0
- package/dist/exporter/bits/index.d.ts.map +1 -0
- package/dist/exporter/bits/index.js +113 -0
- package/dist/exporter/bits/index.js.map +1 -0
- package/dist/exporter/bits/templates.d.ts +7 -0
- package/dist/exporter/bits/templates.d.ts.map +1 -0
- package/dist/exporter/bits/templates.js +78 -0
- package/dist/exporter/bits/templates.js.map +1 -0
- package/dist/exporter/docx/index.d.ts +33 -0
- package/dist/exporter/docx/index.d.ts.map +1 -0
- package/dist/exporter/docx/index.js +139 -0
- package/dist/exporter/docx/index.js.map +1 -0
- package/dist/exporter/docx/render.d.ts +19 -0
- package/dist/exporter/docx/render.d.ts.map +1 -0
- package/dist/exporter/docx/render.js +123 -0
- package/dist/exporter/docx/render.js.map +1 -0
- package/dist/exporter/epub/index.d.ts +70 -0
- package/dist/exporter/epub/index.d.ts.map +1 -0
- package/dist/exporter/epub/index.js +310 -0
- package/dist/exporter/epub/index.js.map +1 -0
- package/dist/exporter/epub/templates.d.ts +65 -0
- package/dist/exporter/epub/templates.d.ts.map +1 -0
- package/dist/exporter/epub/templates.js +224 -0
- package/dist/exporter/epub/templates.js.map +1 -0
- package/dist/exporter/epub/tools.d.ts +5 -0
- package/dist/exporter/epub/tools.d.ts.map +1 -0
- package/dist/exporter/epub/tools.js +59 -0
- package/dist/exporter/epub/tools.js.map +1 -0
- package/dist/exporter/html/index.d.ts +70 -0
- package/dist/exporter/html/index.d.ts.map +1 -0
- package/dist/exporter/html/index.js +320 -0
- package/dist/exporter/html/index.js.map +1 -0
- package/dist/exporter/html/templates.d.ts +40 -0
- package/dist/exporter/html/templates.d.ts.map +1 -0
- package/dist/exporter/html/templates.js +225 -0
- package/dist/exporter/html/templates.js.map +1 -0
- package/dist/exporter/html/tools.d.ts +2 -0
- package/dist/exporter/html/tools.d.ts.map +1 -0
- package/dist/exporter/html/tools.js +23 -0
- package/dist/exporter/html/tools.js.map +1 -0
- package/dist/exporter/latex/index.d.ts +36 -0
- package/dist/exporter/latex/index.d.ts.map +1 -0
- package/dist/exporter/latex/index.js +116 -0
- package/dist/exporter/latex/index.js.map +1 -0
- package/dist/exporter/latex/templates.d.ts +4 -0
- package/dist/exporter/latex/templates.d.ts.map +1 -0
- package/dist/exporter/latex/templates.js +26 -0
- package/dist/exporter/latex/templates.js.map +1 -0
- package/dist/exporter/native/index.d.ts +22 -0
- package/dist/exporter/native/index.d.ts.map +1 -0
- package/dist/exporter/native/index.js +141 -0
- package/dist/exporter/native/index.js.map +1 -0
- package/dist/exporter/odt/index.d.ts +33 -0
- package/dist/exporter/odt/index.d.ts.map +1 -0
- package/dist/exporter/odt/index.js +133 -0
- package/dist/exporter/odt/index.js.map +1 -0
- package/dist/exporter/odt/render.d.ts +21 -0
- package/dist/exporter/odt/render.d.ts.map +1 -0
- package/dist/exporter/odt/render.js +126 -0
- package/dist/exporter/odt/render.js.map +1 -0
- package/dist/exporter/pretty.d.ts +17 -0
- package/dist/exporter/pretty.d.ts.map +1 -0
- package/dist/exporter/pretty.js +55 -0
- package/dist/exporter/pretty.js.map +1 -0
- package/dist/exporter/print/index.d.ts +25 -0
- package/dist/exporter/print/index.d.ts.map +1 -0
- package/dist/exporter/print/index.js +46 -0
- package/dist/exporter/print/index.js.map +1 -0
- package/dist/exporter/print/templates.d.ts +2 -0
- package/dist/exporter/print/templates.d.ts.map +1 -0
- package/dist/exporter/print/templates.js +5 -0
- package/dist/exporter/print/templates.js.map +1 -0
- package/dist/exporter/tools.d.ts +31 -0
- package/dist/exporter/tools.d.ts.map +1 -0
- package/dist/exporter/tools.js +177 -0
- package/dist/exporter/tools.js.map +1 -0
- package/dist/i18n.d.ts +7 -0
- package/dist/i18n.d.ts.map +1 -0
- package/dist/i18n.js +918 -0
- package/dist/i18n.js.map +1 -0
- package/dist/ids.d.ts +19 -0
- package/dist/ids.d.ts.map +1 -0
- package/dist/ids.js +27 -0
- package/dist/ids.js.map +1 -0
- package/dist/importer/native/index.d.ts +45 -0
- package/dist/importer/native/index.d.ts.map +1 -0
- package/dist/importer/native/index.js +166 -0
- package/dist/importer/native/index.js.map +1 -0
- package/dist/importer/native/reader.d.ts +32 -0
- package/dist/importer/native/reader.d.ts.map +1 -0
- package/dist/importer/native/reader.js +170 -0
- package/dist/importer/native/reader.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/schema/index.d.ts +7 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +8 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/types.d.ts +171 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/dist/ui/book_dialog/dialog.d.ts +161 -0
- package/dist/ui/book_dialog/dialog.d.ts.map +1 -0
- package/dist/ui/book_dialog/dialog.js +750 -0
- package/dist/ui/book_dialog/dialog.js.map +1 -0
- package/dist/ui/book_dialog/export.d.ts +95 -0
- package/dist/ui/book_dialog/export.d.ts.map +1 -0
- package/dist/ui/book_dialog/export.js +217 -0
- package/dist/ui/book_dialog/export.js.map +1 -0
- package/dist/ui/book_dialog/index.d.ts +38 -0
- package/dist/ui/book_dialog/index.d.ts.map +1 -0
- package/dist/ui/book_dialog/index.js +36 -0
- package/dist/ui/book_dialog/index.js.map +1 -0
- package/dist/ui/book_dialog/sanity_check.d.ts +22 -0
- package/dist/ui/book_dialog/sanity_check.d.ts.map +1 -0
- package/dist/ui/book_dialog/sanity_check.js +109 -0
- package/dist/ui/book_dialog/sanity_check.js.map +1 -0
- package/dist/ui/book_dialog/templates.d.ts +76 -0
- package/dist/ui/book_dialog/templates.d.ts.map +1 -0
- package/dist/ui/book_dialog/templates.js +542 -0
- package/dist/ui/book_dialog/templates.js.map +1 -0
- package/dist/ui/book_dialog/types.d.ts +258 -0
- package/dist/ui/book_dialog/types.d.ts.map +1 -0
- package/dist/ui/book_dialog/types.js +15 -0
- package/dist/ui/book_dialog/types.js.map +1 -0
- package/locale/ar/messages.json +49 -0
- package/locale/bg/messages.json +49 -0
- package/locale/cs/messages.json +49 -0
- package/locale/da/messages.json +49 -0
- package/locale/de/messages.json +49 -0
- package/locale/en/messages.json +49 -0
- package/locale/en_US/messages.json +49 -0
- package/locale/es/messages.json +49 -0
- package/locale/fr/messages.json +49 -0
- package/locale/it/messages.json +49 -0
- package/locale/ja/messages.json +49 -0
- package/locale/ko/messages.json +49 -0
- package/locale/nb/messages.json +49 -0
- package/locale/nl/messages.json +49 -0
- package/locale/pl/messages.json +49 -0
- package/locale/pt_BR/messages.json +49 -0
- package/locale/pt_PT/messages.json +49 -0
- package/locale/ru/messages.json +49 -0
- package/locale/sv/messages.json +49 -0
- package/locale/tr/messages.json +49 -0
- package/locale/zh_Hans/messages.json +49 -0
- package/logo.svg +10 -0
- package/package.json +150 -5
- package/src/exporter/bits/index.ts +184 -0
- package/src/exporter/bits/templates.ts +107 -0
- package/src/exporter/docx/index.ts +258 -0
- package/src/exporter/docx/render.ts +177 -0
- package/src/exporter/epub/index.ts +496 -0
- package/src/exporter/epub/templates.ts +403 -0
- package/src/exporter/epub/tools.ts +68 -0
- package/src/exporter/html/index.ts +479 -0
- package/src/exporter/html/templates.ts +362 -0
- package/src/exporter/html/tools.ts +26 -0
- package/src/exporter/latex/index.ts +190 -0
- package/src/exporter/latex/templates.ts +35 -0
- package/src/exporter/native/index.ts +238 -0
- package/src/exporter/odt/index.ts +230 -0
- package/src/exporter/odt/render.ts +181 -0
- package/src/exporter/pretty.ts +75 -0
- package/src/exporter/print/index.ts +76 -0
- package/src/exporter/print/templates.ts +8 -0
- package/src/exporter/tools.ts +270 -0
- package/src/global.d.ts +2 -0
- package/src/i18n.ts +936 -0
- package/src/ids.ts +27 -0
- package/src/importer/native/index.ts +269 -0
- package/src/importer/native/reader.ts +247 -0
- package/src/index.ts +20 -0
- package/src/modules.d.ts +7 -0
- package/src/schema/index.ts +8 -0
- package/src/types.ts +208 -0
- package/src/ui/book_dialog/dialog.ts +940 -0
- package/src/ui/book_dialog/export.ts +449 -0
- package/src/ui/book_dialog/index.ts +84 -0
- package/src/ui/book_dialog/sanity_check.ts +208 -0
- package/src/ui/book_dialog/templates.ts +736 -0
- 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"
|