@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,171 @@
1
+ /**
2
+ * Core types for the @fiduswriter/books package.
3
+ */
4
+ import type { Schema } from "prosemirror-model";
5
+ import type { BibDB, CSL, ExportDoc, ExportMetadata, ImageDB, User } from "@fiduswriter/document";
6
+ export type { CSL, User } from "@fiduswriter/document";
7
+ /** A single chapter entry inside a book. */
8
+ export interface Chapter {
9
+ /** Document ID of the chapter. */
10
+ text: number;
11
+ /** Display number / order of the chapter. */
12
+ number: number;
13
+ /** Optional part title. */
14
+ part?: string;
15
+ /** Archive storage index (used by the native importer). */
16
+ chapter_index?: number;
17
+ /**
18
+ * Location of the chapter's source `.fidus` file.
19
+ *
20
+ * File-based hosts (desktop app, WebDAV) reference chapters as standalone
21
+ * files rather than database documents; the embedded chapter data inside a
22
+ * `.fidusbook` container is then a snapshot of that file. Hosts without a
23
+ * filesystem (the Django server) leave this unset.
24
+ */
25
+ path?: string;
26
+ }
27
+ /** Book metadata block. */
28
+ export interface BookMetadata {
29
+ subtitle?: string;
30
+ author?: string;
31
+ version?: string;
32
+ publisher?: string;
33
+ copyright?: string;
34
+ description?: string;
35
+ isbn?: string;
36
+ publication_date?: string;
37
+ series_title?: string;
38
+ series_position?: string;
39
+ keywords?: string;
40
+ [key: string]: unknown;
41
+ }
42
+ /** Book settings block. */
43
+ export interface BookSettings {
44
+ language: string;
45
+ book_style?: string;
46
+ papersize?: string;
47
+ [key: string]: unknown;
48
+ }
49
+ /** A book record. */
50
+ export interface Book {
51
+ id?: number;
52
+ title: string;
53
+ path?: string;
54
+ metadata: BookMetadata;
55
+ settings: BookSettings;
56
+ chapters: Chapter[];
57
+ cover_image?: number;
58
+ cover_image_data?: BookCoverImage;
59
+ updated?: number;
60
+ added?: number;
61
+ docx_template?: string;
62
+ odt_template?: string;
63
+ rights?: string;
64
+ [key: string]: unknown;
65
+ }
66
+ /** Cover image description stored in a book. */
67
+ export interface BookCoverImage {
68
+ title?: string;
69
+ checksum?: string;
70
+ file_type?: string;
71
+ image?: string;
72
+ [key: string]: unknown;
73
+ }
74
+ /** A single book style with its associated media files. */
75
+ export interface BookStyle {
76
+ slug: string;
77
+ contents: string;
78
+ bookstylefile_set: Array<[string, string]>;
79
+ [key: string]: unknown;
80
+ }
81
+ export type BookStyles = BookStyle[];
82
+ /** A document entry as held in the book's document list. */
83
+ export interface DocumentListEntry extends ExportDoc {
84
+ /** Raw ProseMirror content (used by DOCX/ODT exporters). */
85
+ rawContent?: Record<string, unknown>;
86
+ /** Whether the document is end-to-end encrypted. */
87
+ e2ee?: boolean;
88
+ /** Base64-encoded salt for E2EE key derivation. */
89
+ e2ee_salt?: string;
90
+ /** PBKDF2 iterations for E2EE key derivation. */
91
+ e2ee_iterations?: number;
92
+ images?: ImageDB["db"];
93
+ bibliography?: BibDB["db"];
94
+ /**
95
+ * The document lives outside the book as a standalone file; `path` holds
96
+ * its location. The book's chapter then carries the same `path`.
97
+ */
98
+ external?: boolean;
99
+ /**
100
+ * The document's source could not be read (a referenced file is missing
101
+ * and no snapshot is embedded). Such entries render as inaccessible and
102
+ * are skipped by exporters.
103
+ */
104
+ missing?: boolean;
105
+ }
106
+ /** Options shared by book exporters. */
107
+ export interface BookExporterOptions {
108
+ /** ProseMirror schema used for E2EE decryption. */
109
+ schema?: Schema;
110
+ /** CSL engine provider. */
111
+ csl?: CSL;
112
+ /** Book styles data. */
113
+ bookStyles?: BookStyles;
114
+ /** Logged-in user. */
115
+ user?: User;
116
+ /** Document list entries for the book's chapters. */
117
+ documentList?: DocumentListEntry[];
118
+ /** Last-modified timestamp (seconds since epoch). */
119
+ updated?: number;
120
+ /** Whether to produce multiple HTML files (HTML exporter only). */
121
+ multiDoc?: boolean;
122
+ /** Use relative URLs for linked assets (HTML exporter only). */
123
+ relativeUrls?: boolean;
124
+ }
125
+ /** Strategy for loading missing chapter data before export. */
126
+ export interface ChapterLoader {
127
+ loadChapters(chapterIds: number[], documentList: DocumentListEntry[], schema?: Schema, rawContent?: boolean): Promise<void>;
128
+ }
129
+ /** Strategy for handling end-to-end encrypted chapters. */
130
+ export interface E2EEStrategy {
131
+ ensurePassphraseUnlocked(): Promise<boolean>;
132
+ getDocumentPassword(docId: number): Promise<string | null>;
133
+ resolvePasswordToKey(password: string, salt: Uint8Array, iterations: number): Promise<CryptoKey>;
134
+ decryptObject(encrypted: string, key: CryptoKey): Promise<unknown>;
135
+ decryptImageToUrl(encrypted: string, key: CryptoKey): Promise<string>;
136
+ storePasswordInSession?(docId: number, password: string): void;
137
+ }
138
+ /** Backend used by NativeBookImporter to create the book record. */
139
+ export interface BookImporterBackend {
140
+ /**
141
+ * Create a book record from the imported book data and chapter documents.
142
+ *
143
+ * @param bookData - The raw book object from book.json.
144
+ * @param chapters - The chapters with their final document IDs.
145
+ * @param coverImageId - ID of the imported cover image, or false.
146
+ * @returns A promise resolving to the created book record.
147
+ */
148
+ createBook(bookData: Record<string, unknown>, chapters: Chapter[], coverImageId: number | false): Promise<Book>;
149
+ }
150
+ /** Raw archive content returned by FidusBookReader. */
151
+ export interface FidusBookArchive {
152
+ book: Record<string, unknown>;
153
+ documentList: DocumentListEntry[];
154
+ }
155
+ /** Parameters passed to the book.tex template. */
156
+ export interface BookTexTemplateParams {
157
+ book: Book;
158
+ preamble: string;
159
+ epilogue: string;
160
+ }
161
+ /** Parameters passed to the BITS book template. */
162
+ export interface BitsTemplateParams {
163
+ front: string;
164
+ body: string;
165
+ back: string;
166
+ }
167
+ /** Base metadata used by DOCX/ODT book exporters. */
168
+ export interface BookBaseMetadata extends ExportMetadata {
169
+ language: string;
170
+ }
171
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,mBAAmB,CAAA;AAC7C,OAAO,KAAK,EACR,KAAK,EACL,GAAG,EACH,SAAS,EACT,cAAc,EACd,OAAO,EACP,IAAI,EACP,MAAM,uBAAuB,CAAA;AAE9B,YAAY,EAAC,GAAG,EAAE,IAAI,EAAC,MAAM,uBAAuB,CAAA;AAEpD,4CAA4C;AAC5C,MAAM,WAAW,OAAO;IACpB,kCAAkC;IAClC,IAAI,EAAE,MAAM,CAAA;IACZ,6CAA6C;IAC7C,MAAM,EAAE,MAAM,CAAA;IACd,2BAA2B;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,2DAA2D;IAC3D,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB;;;;;;;OAOG;IACH,IAAI,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,2BAA2B;AAC3B,MAAM,WAAW,YAAY;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAA;IAC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W,gBAAgB;IAC7B,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC7B,YAAY,EAAE,iBAAiB,EAAE,CAAA;CACpC;AAED,kDAAkD;AAClD,MAAM,WAAW,qBAAqB;IAClC,IAAI,EAAE,IAAI,CAAA;IACV,QAAQ,EAAE,MAAM,CAAA;IAChB,QAAQ,EAAE,MAAM,CAAA;CACnB;AAED,mDAAmD;AACnD,MAAM,WAAW,kBAAkB;IAC/B,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;CACf;AAED,qDAAqD;AACrD,MAAM,WAAW,gBAAiB,SAAQ,cAAc;IACpD,QAAQ,EAAE,MAAM,CAAA;CACnB"}
package/dist/types.js ADDED
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Core types for the @fiduswriter/books package.
3
+ */
4
+ export {};
5
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG"}
@@ -0,0 +1,161 @@
1
+ /**
2
+ * The book edit dialog.
3
+ *
4
+ * A tabbed dialog that edits a book's metadata and settings, manages its
5
+ * chapter list (add/remove/reorder, part grouping and per-chapter part
6
+ * titles), picks the cover image, triggers a sanity check and starts an
7
+ * export.
8
+ *
9
+ * Everything host-specific is injected: see `./types.js`. The book *overview*
10
+ * page -- its datatable, bulk actions, sharing, copy and delete -- is not
11
+ * part of this component and stays with the host.
12
+ */
13
+ import type { Book, Chapter, DocumentListEntry } from "../../types.js";
14
+ import { Dialog, FileSelector } from "fwtoolkit";
15
+ import type { DialogButtonSpec } from "fwtoolkit";
16
+ import type { BookExportMenu } from "./export.js";
17
+ import type { BookDialogButton, BookDialogImageDB, BookDialogInfo, BookDialogOptions, BookDialogPart } from "./types.js";
18
+ /** The tabbed book editor. */
19
+ export declare class BookDialog {
20
+ options: BookDialogOptions;
21
+ /** Whether this dialog creates a new book or edits an existing one. */
22
+ isNew: boolean;
23
+ /** The book being edited. A working copy, not the host's own record. */
24
+ book: Book;
25
+ documentList: BookDialogOptions["documentList"];
26
+ exportMenu: BookExportMenu;
27
+ /** Callbacks invoked after the book has been saved. */
28
+ onSave: Array<(book: Book) => Promise<unknown> | unknown>;
29
+ dialogParts: BookDialogPart[];
30
+ /** Cover images that are not part of the host's image database. */
31
+ bookImageDB: BookDialogImageDB;
32
+ dialog: Dialog | null;
33
+ /** The chapters tab's file selector, once the dialog is open. */
34
+ fileSelector: FileSelector | null;
35
+ constructor(options: BookDialogOptions);
36
+ /** The image database the dialog renders cover previews from. */
37
+ imageDB(): BookDialogImageDB;
38
+ /** The dialog's root element, or the document before it is opened. */
39
+ root(): ParentNode;
40
+ /** The bundle the tab templates are rendered from. */
41
+ bookInfo(): BookDialogInfo;
42
+ /** A brand new book with the dialog's default metadata and settings. */
43
+ createEmptyBook(): Book;
44
+ /**
45
+ * The dialog's working copy of an existing book.
46
+ *
47
+ * The record is copied shallowly -- the `chapters` array stays shared with
48
+ * the host's record, exactly as the Django backend's dialog behaved -- and
49
+ * the metadata block is merged onto a complete one so every form field
50
+ * has something to read back.
51
+ */
52
+ workingCopy(book: Book): Book;
53
+ /**
54
+ * The dialog's buttons, from the host's `buttons` option or the classic
55
+ * default row (Export dropdown, Save, Cancel -- or Close for a read-only
56
+ * book).
57
+ */
58
+ buildButtons(): DialogButtonSpec[];
59
+ /** The classic button row, used when the host supplies none. */
60
+ defaultButtons(): BookDialogButton[];
61
+ /** Run a button's action, closing the dialog unless it wants to stay. */
62
+ runButton(spec: BookDialogButton, event?: Event): unknown;
63
+ /**
64
+ * Open the export dropdown menu at the position of the triggering event.
65
+ *
66
+ * Exposed for hosts that build their own button row: the Export button
67
+ * is just a dropdown-styled button whose click calls this. Does nothing
68
+ * when no export context was given.
69
+ */
70
+ openExportMenu(event?: Event): unknown;
71
+ /** Render and open the dialog. */
72
+ open(): void;
73
+ /** Whether the book is only readable, i.e. not editable. */
74
+ readOnly(): boolean;
75
+ /**
76
+ * Let the user pick a DOCX/ODT template file and hand it to the host.
77
+ *
78
+ * The book is saved first, because a freshly created book has no id the
79
+ * host could attach a template to.
80
+ */
81
+ bindTemplateInput(dialog: Dialog, inputId: string, rowId: string, applyTemplate: (book: Book, template: string) => void, saveTemplate?: (book: Book, file: File) => Promise<string | null>): void;
82
+ /** Replace the markup of one of the dialog's rows. */
83
+ refreshRow(rowId: string, html: string): void;
84
+ /**
85
+ * (Re-)build the chapters tab's file selector from the document list.
86
+ *
87
+ * Hosts can extend the list after the dialog opened -- the desktop adds
88
+ * the files the user picked through its native file dialog -- so the
89
+ * selector is rebuilt rather than created only in `open()`.
90
+ */
91
+ refreshFileSelector(): void;
92
+ /**
93
+ * Replace the document list the dialog's catalog and chapter rows read
94
+ * from, and refresh the affected parts of the dialog.
95
+ */
96
+ setDocumentList(documentList: BookDialogOptions["documentList"]): void;
97
+ /** Re-render the chapter list. */
98
+ refreshChapterList(): void;
99
+ /**
100
+ * Add or remove the encrypted-chapters notice that lives alongside the
101
+ * chapter list. Called after any operation that changes book.chapters so
102
+ * the notice stays in sync.
103
+ */
104
+ updateChapterNotice(): void;
105
+ /** Open a sub-dialog to edit a chapter's part title. */
106
+ editChapterDialog(chapter: Chapter): void;
107
+ /** Let the user pick the cover image through the host's image picker. */
108
+ selectCoverImage(): Promise<void>;
109
+ /**
110
+ * Read the form fields into the book record without persisting.
111
+ *
112
+ * Chapter and part edits live in `this.book` directly, but the metadata
113
+ * and settings fields are only read back on save. Hosts that write the
114
+ * book from outside the dialog -- a window-close flush, a Save-as in the
115
+ * host UI -- call this first so the edited state is complete. A no-op
116
+ * when the dialog is closed or the book is read-only.
117
+ *
118
+ * @returns The dialog's book record with the form fields applied.
119
+ */
120
+ syncEdits(): Book;
121
+ /**
122
+ * Persist the edited book through the host and notify the save callbacks.
123
+ *
124
+ * Must only be called while the dialog is open.
125
+ */
126
+ saveBook(exportId?: string): Promise<unknown>;
127
+ /**
128
+ * Move a chapter one position up or down the list.
129
+ *
130
+ * @param docId - Id of the chapter document to move.
131
+ * @param offset - `-1` to move up, `1` to move down.
132
+ */
133
+ moveChapter(docId: number, offset: number): void;
134
+ /** Remove a chapter from the book and close the numbering gap. */
135
+ removeChapter(docId: number): void;
136
+ /**
137
+ * Add a document as the book's next chapter.
138
+ *
139
+ * External documents (standalone files the host picked) carry their file
140
+ * location onto the chapter, so file-based hosts can re-resolve the live
141
+ * document on the next load.
142
+ */
143
+ addChapter(doc: DocumentListEntry): void;
144
+ /** Append the documents selected in the file selector as new chapters. */
145
+ addChapters(fileSelector: FileSelector): void;
146
+ /**
147
+ * Let the user pick standalone documents through the host and add them as
148
+ * chapters.
149
+ *
150
+ * The host returns stub entries for the picked files; the dialog merges
151
+ * them into the catalog so they show up in the file selector, and adds
152
+ * each as a chapter. The chapter content itself is resolved by the host
153
+ * when the book is saved or exported.
154
+ */
155
+ addPickedChapters(): Promise<void>;
156
+ /** Handle a click anywhere inside the dialog. */
157
+ handleDialogClick(event: Event): void;
158
+ /** Save the book and render its sanity check report in place. */
159
+ performSanityCheck(): Promise<void>;
160
+ }
161
+ //# sourceMappingURL=dialog.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dialog.d.ts","sourceRoot":"","sources":["../../../src/ui/book_dialog/dialog.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAC,IAAI,EAAgB,OAAO,EAAE,iBAAiB,EAAC,MAAM,gBAAgB,CAAA;AAClF,OAAO,EAEH,MAAM,EACN,YAAY,EAIf,MAAM,WAAW,CAAA;AAClB,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,WAAW,CAAA;AAE/C,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,aAAa,CAAA;AAkB/C,OAAO,KAAK,EACR,gBAAgB,EAChB,iBAAiB,EACjB,cAAc,EACd,iBAAiB,EACjB,cAAc,EACjB,MAA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