@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,283 @@
1
+ /**
2
+ * Host-injected types for the book dialog.
3
+ *
4
+ * The dialog is browser-only but backend-agnostic: everything that differs
5
+ * between the Django backend, a Nextcloud install and a local `.fidusbook`
6
+ * file is described by the interfaces in this module.
7
+ *
8
+ * `ChapterLoader` and `E2EEStrategy` are the seams the exporters already use
9
+ * (see `../../types.js`); the remaining host-specific concerns -- persisting
10
+ * the edited book, picking a cover image, uploading a DOCX/ODT template and
11
+ * handing a finished export to the user -- are declared here, following the
12
+ * same injection pattern.
13
+ */
14
+
15
+ import type {Schema} from "prosemirror-model"
16
+ import type {
17
+ Book,
18
+ BookCoverImage,
19
+ BookStyle,
20
+ BookStyles,
21
+ Chapter,
22
+ ChapterLoader,
23
+ CSL,
24
+ DocumentListEntry,
25
+ E2EEStrategy,
26
+ User
27
+ } from "../../types.js"
28
+
29
+ /** One tab of the book dialog. */
30
+ export interface BookDialogPart {
31
+ title: string
32
+ description: string
33
+ template: (bookInfo: BookDialogInfo) => string
34
+ }
35
+
36
+ /**
37
+ * The image database entries a book dialog renders cover previews from.
38
+ *
39
+ * The dialog adds the book's own cover image to the host's image database
40
+ * before rendering, so this is a plain record rather than an image manager
41
+ * instance.
42
+ */
43
+ export interface BookDialogImageDB {
44
+ db: Record<number, {image?: string; [key: string]: unknown}>
45
+ }
46
+
47
+ /** The bundle every book-dialog tab template receives. */
48
+ export interface BookDialogInfo {
49
+ book: Book
50
+ documentList: DocumentListEntry[]
51
+ /** Citation style catalog: style id → human-readable title. */
52
+ citationStyles: Record<string, string>
53
+ bookStyleList: BookStyle[]
54
+ imageDB: BookDialogImageDB
55
+ /**
56
+ * The host offers a picker for standalone files
57
+ * (`backend.pickChapters`), so the chapters tab renders its button.
58
+ */
59
+ canPickChapters?: boolean
60
+ /**
61
+ * The host can open a chapter's source document
62
+ * (`backend.openChapter`), so chapter titles render as links.
63
+ */
64
+ canOpenChapters?: boolean
65
+ /**
66
+ * The chapters tab shows the server-style document catalog ("My
67
+ * documents" tree with the add-arrow). File-based hosts that add
68
+ * chapters exclusively through the picker turn it off.
69
+ */
70
+ chapterCatalog?: boolean
71
+ }
72
+
73
+ /** A cover image the user picked through the host's image picker. */
74
+ export interface BookDialogCoverImage {
75
+ /** Id of the picked image. */
76
+ id: number
77
+ /** The image database entry, so the dialog can render a preview. */
78
+ data: BookCoverImage
79
+ }
80
+
81
+ /** Hands a finished export to the user. */
82
+ export type BookExportDeliverer = (
83
+ blob: Blob,
84
+ filename: string,
85
+ options: {description?: string; mimeType?: string; extensions?: string[]}
86
+ ) => unknown
87
+
88
+ /**
89
+ * Host-specific operations the book dialog needs in order to persist what the
90
+ * user edits.
91
+ *
92
+ * Everything except {@link BookDialogBackend.saveBook} is optional. A host
93
+ * that does not implement `selectCoverImage`, `saveDocxTemplate` or
94
+ * `saveOdtTemplate` simply does not get the corresponding buttons or tabs in
95
+ * the dialog, which is what a local-file host without template support wants.
96
+ */
97
+ export interface BookDialogBackend {
98
+ /**
99
+ * Persist the edited book record.
100
+ *
101
+ * @param book - The book as edited in the dialog. The dialog hands over
102
+ * its working copy, so hosts must not rely on the object staying
103
+ * unmodified afterwards.
104
+ * @param exportId - Set when the save precedes a book export (the export
105
+ * menu passes the id of the export that triggered it). Hosts whose
106
+ * first save hands the session over to a new window (an untitled book
107
+ * being promoted to a real path) use it to resume that export in the
108
+ * new window instead of dropping it; hosts without such a flow ignore
109
+ * it.
110
+ * @returns A promise resolving to the stored book record. Its `id`,
111
+ * `added` and `updated` fields are copied back onto the dialog's book.
112
+ * Resolve to `false` when the save handed the session over to a new
113
+ * window (an untitled book promoted to its real path) and the export
114
+ * that triggered it is resumed there — the caller must then not run
115
+ * the export in this window.
116
+ */
117
+ saveBook(book: Book, exportId?: string): Promise<Book | false>
118
+
119
+ /**
120
+ * Open the host's image picker so the user can choose a book cover.
121
+ *
122
+ * @param currentCoverImageId - The currently selected cover image id, or
123
+ * `false` when the book has none, so the picker can preselect it.
124
+ * @returns A promise resolving to the picked image, or to `null`/`false`
125
+ * when the user removed the cover image.
126
+ */
127
+ selectCoverImage?(
128
+ currentCoverImageId: number | false
129
+ ): Promise<BookDialogCoverImage | null | false>
130
+
131
+ /**
132
+ * Upload a DOCX template file and attach it to the book.
133
+ *
134
+ * @returns A promise resolving to the stored template's URL, or `null`
135
+ * when the upload was not stored.
136
+ */
137
+ saveDocxTemplate?(book: Book, file: File): Promise<string | null>
138
+
139
+ /**
140
+ * Upload an ODT template file and attach it to the book.
141
+ *
142
+ * @returns A promise resolving to the stored template's URL, or `null`
143
+ * when the upload was not stored.
144
+ */
145
+ saveOdtTemplate?(book: Book, file: File): Promise<string | null>
146
+
147
+ /**
148
+ * Let the user pick standalone documents to add as chapters through the
149
+ * host's own picker (a native file dialog, a WebDAV file picker, …).
150
+ *
151
+ * This is the file-based equivalent of the server's document catalog: a
152
+ * host without a document database cannot list "all documents the user
153
+ * has access to" up front, so it offers a picker instead.
154
+ *
155
+ * @returns A promise resolving to one stub entry per picked file --
156
+ * `id`, `title`, `path`, `external: true` and no content. The dialog
157
+ * merges the entries into its document list and adds them as chapters
158
+ * with the matching `path`; the host resolves the content when the book
159
+ * is saved or exported.
160
+ */
161
+ pickChapters?(): Promise<DocumentListEntry[]>
162
+
163
+ /**
164
+ * Open a chapter's source document for editing.
165
+ *
166
+ * Only file-based hosts implement this: the desktop opens the chapter's
167
+ * `.fidus` file in a new editor window. When absent, chapter titles in
168
+ * the chapter list are rendered as plain text.
169
+ */
170
+ openChapter?(chapter: Chapter): void
171
+ }
172
+
173
+ /**
174
+ * What a host must supply to run a book sanity check.
175
+ *
176
+ * Both members are the same seams the book exporters already accept, so a
177
+ * host that can export a book can run a sanity check without extra wiring.
178
+ */
179
+ export interface BookDataContext {
180
+ /** ProseMirror schema used to parse decrypted chapter content. */
181
+ schema: Schema
182
+ /** Loads chapters whose content is not in the document list yet. */
183
+ chapterLoader: ChapterLoader
184
+ /** Decrypts end-to-end encrypted chapters. */
185
+ e2ee: E2EEStrategy
186
+ }
187
+
188
+ /**
189
+ * What a host must additionally supply to run a book export.
190
+ *
191
+ * The dialog only offers its export menu when a context of this shape is
192
+ * passed, so hosts that merely want a metadata editor can leave it out.
193
+ */
194
+ export interface BookExportContext extends BookDataContext {
195
+ /** Citation style engine used by the exporters. */
196
+ csl: CSL
197
+ /** Book styles used by the epub and print exporters. */
198
+ bookStyles: BookStyles
199
+ /** The logged-in user, stamped into the export. */
200
+ user: User
201
+ /** Hands the finished export to the user. */
202
+ deliver: BookExportDeliverer
203
+ }
204
+
205
+ /**
206
+ * One button in the book dialog's button row.
207
+ *
208
+ * Hosts that render the dialog as a full-window interface (the desktop app,
209
+ * a Nextcloud tab) replace the default Submit/Cancel pair with their own
210
+ * actions and labels. `click` receives the dialog instance, so a button can
211
+ * call `saveBook()`, open the export menu or run host-side logic; by default
212
+ * the dialog closes after the click unless `keepOpen` is set.
213
+ */
214
+ export interface BookDialogButton {
215
+ /** Renders the framework's Cancel or Close button (no custom action). */
216
+ type?: "cancel" | "close"
217
+ text?: string
218
+ classes?: string
219
+ icon?: string
220
+ /** Render with a dropdown arrow; the click handler opens the menu. */
221
+ dropdown?: boolean
222
+ /**
223
+ * Keep the dialog open after the click. Defaults to closing it, which
224
+ * is what a confirming button (the default Save) wants.
225
+ */
226
+ keepOpen?: boolean
227
+ click?: (dialog: import("./dialog.js").BookDialog, event?: Event) => unknown
228
+ }
229
+
230
+ /** Constructor options of the book dialog. */
231
+ export interface BookDialogOptions extends BookDataContext {
232
+ /**
233
+ * The book to edit. Omit it to create a new book.
234
+ *
235
+ * The dialog works on a shallow copy of the record (with the metadata
236
+ * block merged onto a complete one), leaving the host's own copy intact.
237
+ * The `chapters` array is shared with the original, exactly as the Django
238
+ * backend's dialog behaved.
239
+ */
240
+ book?: Book
241
+ /** Documents the user may add as chapters. */
242
+ documentList: DocumentListEntry[]
243
+ /** Persists the dialog's changes and provides host-only pickers. */
244
+ backend: BookDialogBackend
245
+ /**
246
+ * Export inputs. When omitted, the dialog renders without its export
247
+ * dropdown.
248
+ */
249
+ exportContext?: BookExportContext
250
+ /** Citation style catalog offered in the bibliography tab: id → title. */
251
+ citationStyles?: Record<string, string>
252
+ /** Folder a newly created book is placed in. */
253
+ path?: string
254
+ /** The host's image database, used to render cover previews. */
255
+ imageDB?: BookDialogImageDB
256
+ /** Callbacks invoked after every successful save. */
257
+ onSave?: Array<(book: Book) => Promise<unknown> | unknown>
258
+ /**
259
+ * Show the server-style document catalog ("My documents" tree with an
260
+ * add-arrow) next to the chapter list. Defaults to `true`; file-based
261
+ * hosts that add chapters exclusively through `backend.pickChapters`
262
+ * set it to `false`, which collapses the tab to the chapter table plus
263
+ * an "Add chapters" button.
264
+ */
265
+ chapterCatalog?: boolean
266
+ /**
267
+ * The dialog's buttons. When omitted, the dialog builds its classic row:
268
+ * an Export dropdown (when an export context is given), Save (closing
269
+ * the dialog) and Cancel -- or just Close for a read-only book.
270
+ *
271
+ * Hosts that keep the dialog open as a workspace (desktop, Nextcloud)
272
+ * supply their own row, e.g. Save / Save as… / Close.
273
+ */
274
+ buttons?: BookDialogButton[]
275
+ /** Render the dialog filling the window rather than as a modal box. */
276
+ fullScreen?: boolean
277
+ /** Whether the dialog shows its title-bar close button. */
278
+ canClose?: boolean
279
+ /** Whether Escape closes the dialog. */
280
+ canEscape?: boolean
281
+ /** Called when the dialog has been closed. */
282
+ onClose?: () => void
283
+ }