@fiduswriter/books-document 0.1.28 → 0.1.29

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 (31) hide show
  1. package/dist/ui/book_dialog/dialog.d.ts +98 -0
  2. package/dist/ui/book_dialog/dialog.d.ts.map +1 -0
  3. package/dist/ui/book_dialog/dialog.js +590 -0
  4. package/dist/ui/book_dialog/dialog.js.map +1 -0
  5. package/dist/ui/book_dialog/export.d.ts +81 -0
  6. package/dist/ui/book_dialog/export.d.ts.map +1 -0
  7. package/dist/ui/book_dialog/export.js +184 -0
  8. package/dist/ui/book_dialog/export.js.map +1 -0
  9. package/dist/ui/book_dialog/index.d.ts +38 -0
  10. package/dist/ui/book_dialog/index.d.ts.map +1 -0
  11. package/dist/ui/book_dialog/index.js +36 -0
  12. package/dist/ui/book_dialog/index.js.map +1 -0
  13. package/dist/ui/book_dialog/sanity_check.d.ts +22 -0
  14. package/dist/ui/book_dialog/sanity_check.d.ts.map +1 -0
  15. package/dist/ui/book_dialog/sanity_check.js +109 -0
  16. package/dist/ui/book_dialog/sanity_check.js.map +1 -0
  17. package/dist/ui/book_dialog/templates.d.ts +74 -0
  18. package/dist/ui/book_dialog/templates.d.ts.map +1 -0
  19. package/dist/ui/book_dialog/templates.js +526 -0
  20. package/dist/ui/book_dialog/templates.js.map +1 -0
  21. package/dist/ui/book_dialog/types.d.ts +165 -0
  22. package/dist/ui/book_dialog/types.d.ts.map +1 -0
  23. package/dist/ui/book_dialog/types.js +15 -0
  24. package/dist/ui/book_dialog/types.js.map +1 -0
  25. package/package.json +5 -1
  26. package/src/ui/book_dialog/dialog.ts +765 -0
  27. package/src/ui/book_dialog/export.ts +398 -0
  28. package/src/ui/book_dialog/index.ts +81 -0
  29. package/src/ui/book_dialog/sanity_check.ts +208 -0
  30. package/src/ui/book_dialog/templates.ts +705 -0
  31. package/src/ui/book_dialog/types.ts +180 -0
@@ -0,0 +1,180 @@
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
+ ChapterLoader,
22
+ CSL,
23
+ DocumentListEntry,
24
+ E2EEStrategy,
25
+ User
26
+ } from "../../types.js"
27
+
28
+ /** One tab of the book dialog. */
29
+ export interface BookDialogPart {
30
+ title: string
31
+ description: string
32
+ template: (bookInfo: BookDialogInfo) => string
33
+ }
34
+
35
+ /**
36
+ * The image database entries a book dialog renders cover previews from.
37
+ *
38
+ * The dialog adds the book's own cover image to the host's image database
39
+ * before rendering, so this is a plain record rather than an image manager
40
+ * instance.
41
+ */
42
+ export interface BookDialogImageDB {
43
+ db: Record<number, {image?: string; [key: string]: unknown}>
44
+ }
45
+
46
+ /** The bundle every book-dialog tab template receives. */
47
+ export interface BookDialogInfo {
48
+ book: Book
49
+ documentList: DocumentListEntry[]
50
+ citationStyles: Array<{id: string; title?: string}>
51
+ bookStyleList: BookStyle[]
52
+ imageDB: BookDialogImageDB
53
+ }
54
+
55
+ /** A cover image the user picked through the host's image picker. */
56
+ export interface BookDialogCoverImage {
57
+ /** Id of the picked image. */
58
+ id: number
59
+ /** The image database entry, so the dialog can render a preview. */
60
+ data: BookCoverImage
61
+ }
62
+
63
+ /** Hands a finished export to the user. */
64
+ export type BookExportDeliverer = (
65
+ blob: Blob,
66
+ filename: string,
67
+ options: {description?: string; mimeType?: string; extensions?: string[]}
68
+ ) => unknown
69
+
70
+ /**
71
+ * Host-specific operations the book dialog needs in order to persist what the
72
+ * user edits.
73
+ *
74
+ * Everything except {@link BookDialogBackend.saveBook} is optional. A host
75
+ * that does not implement `selectCoverImage`, `saveDocxTemplate` or
76
+ * `saveOdtTemplate` simply does not get the corresponding buttons or tabs in
77
+ * the dialog, which is what a local-file host without template support wants.
78
+ */
79
+ export interface BookDialogBackend {
80
+ /**
81
+ * Persist the edited book record.
82
+ *
83
+ * @param book - The book as edited in the dialog. The dialog hands over
84
+ * its working copy, so hosts must not rely on the object staying
85
+ * unmodified afterwards.
86
+ * @returns A promise resolving to the stored book record. Its `id`,
87
+ * `added` and `updated` fields are copied back onto the dialog's book.
88
+ */
89
+ saveBook(book: Book): Promise<Book>
90
+
91
+ /**
92
+ * Open the host's image picker so the user can choose a book cover.
93
+ *
94
+ * @param currentCoverImageId - The currently selected cover image id, or
95
+ * `false` when the book has none, so the picker can preselect it.
96
+ * @returns A promise resolving to the picked image, or to `null`/`false`
97
+ * when the user removed the cover image.
98
+ */
99
+ selectCoverImage?(
100
+ currentCoverImageId: number | false
101
+ ): Promise<BookDialogCoverImage | null | false>
102
+
103
+ /**
104
+ * Upload a DOCX template file and attach it to the book.
105
+ *
106
+ * @returns A promise resolving to the stored template's URL, or `null`
107
+ * when the upload was not stored.
108
+ */
109
+ saveDocxTemplate?(book: Book, file: File): Promise<string | null>
110
+
111
+ /**
112
+ * Upload an ODT template file and attach it to the book.
113
+ *
114
+ * @returns A promise resolving to the stored template's URL, or `null`
115
+ * when the upload was not stored.
116
+ */
117
+ saveOdtTemplate?(book: Book, file: File): Promise<string | null>
118
+ }
119
+
120
+ /**
121
+ * What a host must supply to run a book sanity check.
122
+ *
123
+ * Both members are the same seams the book exporters already accept, so a
124
+ * host that can export a book can run a sanity check without extra wiring.
125
+ */
126
+ export interface BookDataContext {
127
+ /** ProseMirror schema used to parse decrypted chapter content. */
128
+ schema: Schema
129
+ /** Loads chapters whose content is not in the document list yet. */
130
+ chapterLoader: ChapterLoader
131
+ /** Decrypts end-to-end encrypted chapters. */
132
+ e2ee: E2EEStrategy
133
+ }
134
+
135
+ /**
136
+ * What a host must additionally supply to run a book export.
137
+ *
138
+ * The dialog only offers its export menu when a context of this shape is
139
+ * passed, so hosts that merely want a metadata editor can leave it out.
140
+ */
141
+ export interface BookExportContext extends BookDataContext {
142
+ /** Citation style engine used by the exporters. */
143
+ csl: CSL
144
+ /** Book styles used by the epub and print exporters. */
145
+ bookStyles: BookStyles
146
+ /** The logged-in user, stamped into the export. */
147
+ user: User
148
+ /** Hands the finished export to the user. */
149
+ deliver: BookExportDeliverer
150
+ }
151
+
152
+ /** Constructor options of the book dialog. */
153
+ export interface BookDialogOptions extends BookDataContext {
154
+ /**
155
+ * The book to edit. Omit it to create a new book.
156
+ *
157
+ * The dialog works on a shallow copy of the record (with the metadata
158
+ * block merged onto a complete one), leaving the host's own copy intact.
159
+ * The `chapters` array is shared with the original, exactly as the Django
160
+ * backend's dialog behaved.
161
+ */
162
+ book?: Book
163
+ /** Documents the user may add as chapters. */
164
+ documentList: DocumentListEntry[]
165
+ /** Persists the dialog's changes and provides host-only pickers. */
166
+ backend: BookDialogBackend
167
+ /**
168
+ * Export inputs. When omitted, the dialog renders without its export
169
+ * dropdown.
170
+ */
171
+ exportContext?: BookExportContext
172
+ /** Citation styles offered in the bibliography tab. */
173
+ citationStyles?: Array<{id: string; title?: string}>
174
+ /** Folder a newly created book is placed in. */
175
+ path?: string
176
+ /** The host's image database, used to render cover previews. */
177
+ imageDB?: BookDialogImageDB
178
+ /** Callbacks invoked after every successful save. */
179
+ onSave?: Array<(book: Book) => Promise<unknown> | unknown>
180
+ }