@fiduswriter/books-document 0.1.7 → 0.1.8
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/README.md +69 -10
- package/dist/exporter/bits/index.d.ts +2 -2
- package/dist/exporter/bits/index.d.ts.map +1 -1
- package/dist/exporter/bits/index.js +1 -1
- package/dist/exporter/bits/index.js.map +1 -1
- package/dist/exporter/docx/index.d.ts +9 -5
- package/dist/exporter/docx/index.d.ts.map +1 -1
- package/dist/exporter/docx/index.js +2 -1
- package/dist/exporter/docx/index.js.map +1 -1
- package/dist/exporter/docx/render.d.ts +12 -7
- package/dist/exporter/docx/render.d.ts.map +1 -1
- package/dist/exporter/docx/render.js +18 -11
- package/dist/exporter/docx/render.js.map +1 -1
- package/dist/exporter/epub/index.d.ts.map +1 -1
- package/dist/exporter/epub/index.js +3 -3
- package/dist/exporter/epub/index.js.map +1 -1
- package/dist/exporter/html/index.d.ts +6 -6
- package/dist/exporter/html/index.d.ts.map +1 -1
- package/dist/exporter/html/index.js +4 -4
- package/dist/exporter/html/index.js.map +1 -1
- package/dist/exporter/latex/index.d.ts +2 -2
- package/dist/exporter/latex/index.d.ts.map +1 -1
- package/dist/exporter/latex/index.js +1 -1
- package/dist/exporter/latex/index.js.map +1 -1
- package/dist/exporter/native/index.d.ts +2 -2
- package/dist/exporter/native/index.d.ts.map +1 -1
- package/dist/exporter/native/index.js +1 -1
- package/dist/exporter/native/index.js.map +1 -1
- package/dist/exporter/odt/index.d.ts +9 -5
- package/dist/exporter/odt/index.d.ts.map +1 -1
- package/dist/exporter/odt/index.js +2 -1
- package/dist/exporter/odt/index.js.map +1 -1
- package/dist/exporter/odt/render.d.ts +14 -8
- package/dist/exporter/odt/render.d.ts.map +1 -1
- package/dist/exporter/odt/render.js +22 -15
- package/dist/exporter/odt/render.js.map +1 -1
- package/dist/exporter/print/index.d.ts.map +1 -1
- package/dist/exporter/print/index.js +3 -1
- package/dist/exporter/print/index.js.map +1 -1
- package/dist/exporter/tools.d.ts.map +1 -1
- package/dist/exporter/tools.js.map +1 -1
- package/dist/importer/native/index.js.map +1 -1
- package/package.json +9 -1
- package/src/exporter/bits/index.ts +3 -3
- package/src/exporter/docx/index.ts +26 -22
- package/src/exporter/docx/render.ts +51 -29
- package/src/exporter/epub/index.ts +25 -16
- package/src/exporter/html/index.ts +28 -16
- package/src/exporter/latex/index.ts +12 -11
- package/src/exporter/native/index.ts +5 -4
- package/src/exporter/odt/index.ts +23 -19
- package/src/exporter/odt/render.ts +54 -31
- package/src/exporter/print/index.ts +3 -1
- package/src/exporter/tools.ts +5 -4
- package/src/importer/native/index.ts +6 -6
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
import type {Schema} from "prosemirror-model"
|
|
6
|
-
import type {CSL, User} from "@fiduswriter/document"
|
|
6
|
+
import type {CSL, ExportMetadata, FidusNode, User} from "@fiduswriter/document"
|
|
7
7
|
import type {ProgressCallback} from "@fiduswriter/document/exporter/tools/progress"
|
|
8
8
|
import {
|
|
9
9
|
fixTables,
|
|
@@ -33,7 +33,7 @@ export class ODTBookExporter {
|
|
|
33
33
|
user: User
|
|
34
34
|
docList: DocumentListEntry[]
|
|
35
35
|
templateUrl: string
|
|
36
|
-
updated:
|
|
36
|
+
updated: number
|
|
37
37
|
textFiles: Array<Record<string, unknown>>
|
|
38
38
|
httpFiles: Array<Record<string, unknown>>
|
|
39
39
|
mimeType: string
|
|
@@ -45,7 +45,7 @@ export class ODTBookExporter {
|
|
|
45
45
|
book: Book,
|
|
46
46
|
user: User,
|
|
47
47
|
docList: DocumentListEntry[],
|
|
48
|
-
updated:
|
|
48
|
+
updated: number
|
|
49
49
|
) {
|
|
50
50
|
this.schema = schema
|
|
51
51
|
this.csl = csl
|
|
@@ -83,14 +83,15 @@ export class ODTBookExporter {
|
|
|
83
83
|
this.progressCallback?.(gettext("Preparing ODT book..."), 10)
|
|
84
84
|
this.book.chapters.sort((a, b) => (a.number > b.number ? 1 : -1))
|
|
85
85
|
const xml = new XmlZip(this.templateUrl, this.mimeType)
|
|
86
|
-
const styles = new ODTExporterStyles(xml
|
|
87
|
-
const math = new ODTExporterMath(xml
|
|
88
|
-
const tracks = new ODTExporterTracks(xml
|
|
89
|
-
const render = new ODTBookExporterRender(xml
|
|
86
|
+
const styles = new ODTExporterStyles(xml)
|
|
87
|
+
const math = new ODTExporterMath(xml)
|
|
88
|
+
const tracks = new ODTExporterTracks(xml)
|
|
89
|
+
const render = new ODTBookExporterRender(xml, styles)
|
|
90
90
|
const metadata = new ODTExporterMetadata(
|
|
91
|
-
xml
|
|
91
|
+
xml,
|
|
92
92
|
styles,
|
|
93
|
-
this.getBaseMetadata()
|
|
93
|
+
this.getBaseMetadata(),
|
|
94
|
+
this.csl
|
|
94
95
|
)
|
|
95
96
|
|
|
96
97
|
return xml
|
|
@@ -100,7 +101,7 @@ export class ODTBookExporter {
|
|
|
100
101
|
.then(() => render.init())
|
|
101
102
|
.then(() => metadata.init())
|
|
102
103
|
.then(() => math.init())
|
|
103
|
-
.then(() => this.exportChapters(xml
|
|
104
|
+
.then(() => this.exportChapters(xml, render, styles, math, tracks))
|
|
104
105
|
.then(() => {
|
|
105
106
|
this.progressCallback?.(gettext("Finalizing ODT book..."), 90)
|
|
106
107
|
return xml.prepareBlob()
|
|
@@ -115,11 +116,11 @@ export class ODTBookExporter {
|
|
|
115
116
|
}
|
|
116
117
|
|
|
117
118
|
exportChapters(
|
|
118
|
-
xml:
|
|
119
|
+
xml: XmlZip,
|
|
119
120
|
render: ODTBookExporterRender,
|
|
120
|
-
styles:
|
|
121
|
-
math:
|
|
122
|
-
tracks:
|
|
121
|
+
styles: ODTExporterStyles,
|
|
122
|
+
math: ODTExporterMath,
|
|
123
|
+
tracks: ODTExporterTracks
|
|
123
124
|
): Promise<void> {
|
|
124
125
|
return this.book.chapters
|
|
125
126
|
.map((chapter, chapterIndex) => {
|
|
@@ -129,10 +130,12 @@ export class ODTBookExporter {
|
|
|
129
130
|
return Promise.resolve()
|
|
130
131
|
}
|
|
131
132
|
const docContent = fixTables(
|
|
132
|
-
removeHidden(
|
|
133
|
-
|
|
133
|
+
removeHidden(
|
|
134
|
+
doc.rawContent as unknown as FidusNode
|
|
135
|
+
) as FidusNode
|
|
136
|
+
)
|
|
134
137
|
const citations = new ODTExporterCitations(
|
|
135
|
-
docContent
|
|
138
|
+
docContent,
|
|
136
139
|
doc.settings,
|
|
137
140
|
styles,
|
|
138
141
|
{db: doc.bibliography || {}},
|
|
@@ -169,7 +172,7 @@ export class ODTBookExporter {
|
|
|
169
172
|
.then(() => {
|
|
170
173
|
const pmBib = footnotes.pmBib || citations.pmBib
|
|
171
174
|
render.render(
|
|
172
|
-
docContent
|
|
175
|
+
docContent,
|
|
173
176
|
pmBib,
|
|
174
177
|
doc.settings,
|
|
175
178
|
richtext,
|
|
@@ -199,7 +202,7 @@ export class ODTBookExporter {
|
|
|
199
202
|
.then(() => render.assemble())
|
|
200
203
|
}
|
|
201
204
|
|
|
202
|
-
getBaseMetadata():
|
|
205
|
+
getBaseMetadata(): ExportMetadata {
|
|
203
206
|
const authors = this.book.metadata.author?.length
|
|
204
207
|
? [{institution: this.book.metadata.author}]
|
|
205
208
|
: []
|
|
@@ -210,6 +213,7 @@ export class ODTBookExporter {
|
|
|
210
213
|
: []
|
|
211
214
|
return {
|
|
212
215
|
authors,
|
|
216
|
+
contributors: [],
|
|
213
217
|
keywords,
|
|
214
218
|
title: this.book.title,
|
|
215
219
|
language: this.book.settings.language
|
|
@@ -1,14 +1,20 @@
|
|
|
1
|
+
import type {DocSettings, FidusNode} from "@fiduswriter/document"
|
|
2
|
+
import {XMLElement} from "@fiduswriter/document/exporter/tools/xml"
|
|
3
|
+
import type {XmlZip} from "@fiduswriter/document/exporter/tools/xml_zip"
|
|
4
|
+
import {ODTExporterCitations} from "@fiduswriter/document/exporter/odt/citations"
|
|
1
5
|
import {ODTExporterRender} from "@fiduswriter/document/exporter/odt/render"
|
|
6
|
+
import {ODTExporterRichtext} from "@fiduswriter/document/exporter/odt/richtext"
|
|
7
|
+
import type {ODTExporterStyles} from "@fiduswriter/document/exporter/odt/styles"
|
|
2
8
|
|
|
3
9
|
export class ODTBookExporterRender extends ODTExporterRender {
|
|
4
|
-
styles:
|
|
5
|
-
preamble:
|
|
6
|
-
bodyTemplate:
|
|
7
|
-
postamble:
|
|
8
|
-
bodyParts:
|
|
9
|
-
fileXml:
|
|
10
|
+
styles: ODTExporterStyles
|
|
11
|
+
preamble: XMLElement | null
|
|
12
|
+
bodyTemplate: XMLElement | null
|
|
13
|
+
postamble: XMLElement | null
|
|
14
|
+
bodyParts: XMLElement[]
|
|
15
|
+
fileXml: XMLElement | null
|
|
10
16
|
|
|
11
|
-
constructor(xml:
|
|
17
|
+
constructor(xml: XmlZip, styles: ODTExporterStyles) {
|
|
12
18
|
super(xml)
|
|
13
19
|
|
|
14
20
|
this.styles = styles
|
|
@@ -22,16 +28,18 @@ export class ODTBookExporterRender extends ODTExporterRender {
|
|
|
22
28
|
}
|
|
23
29
|
|
|
24
30
|
init(): Promise<void> {
|
|
25
|
-
return this.xml.getXml(this.filePath).then(
|
|
31
|
+
return this.xml.getXml(this.filePath).then(xml => {
|
|
26
32
|
this.fileXml = xml
|
|
27
|
-
const text = xml.query("office:text")
|
|
33
|
+
const text = xml.query("office:text") as XMLElement
|
|
28
34
|
this.preamble = text.cloneNode(false)
|
|
29
35
|
this.bodyTemplate = text.cloneNode(false)
|
|
30
36
|
this.postamble = text.cloneNode(false)
|
|
31
|
-
let currentSection:
|
|
32
|
-
const textChildren = Array.from(text.children)
|
|
33
|
-
|
|
34
|
-
|
|
37
|
+
let currentSection: XMLElement | null = null
|
|
38
|
+
const textChildren = Array.from(text.children).filter(
|
|
39
|
+
(node): node is XMLElement => node instanceof XMLElement
|
|
40
|
+
)
|
|
41
|
+
textChildren.forEach(node => {
|
|
42
|
+
if (node.tagName && ["text:p", "text:h"].includes(node.tagName)) {
|
|
35
43
|
const bookmark = node.query("text:bookmark")
|
|
36
44
|
if (bookmark) {
|
|
37
45
|
const sectionName = String(
|
|
@@ -58,10 +66,17 @@ export class ODTBookExporterRender extends ODTExporterRender {
|
|
|
58
66
|
})
|
|
59
67
|
}
|
|
60
68
|
|
|
61
|
-
render(
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
69
|
+
render(
|
|
70
|
+
docContent: FidusNode,
|
|
71
|
+
pmBib: unknown,
|
|
72
|
+
settings: DocSettings,
|
|
73
|
+
richtext: ODTExporterRichtext,
|
|
74
|
+
citations: ODTExporterCitations,
|
|
75
|
+
chapterIndex = 0
|
|
76
|
+
): void {
|
|
77
|
+
this.text = this.bodyTemplate!.cloneNode(true)
|
|
78
|
+
const textEl = this.text as XMLElement
|
|
79
|
+
const bodyBookmark = textEl.query("text:bookmark", {
|
|
65
80
|
"text:name": "body"
|
|
66
81
|
})
|
|
67
82
|
if (bodyBookmark) {
|
|
@@ -104,12 +119,18 @@ export class ODTBookExporterRender extends ODTExporterRender {
|
|
|
104
119
|
{title: "book.series_title", content: series_title},
|
|
105
120
|
{title: "book.series_position", content: series_position}
|
|
106
121
|
]
|
|
107
|
-
const usedTags:
|
|
108
|
-
|
|
122
|
+
const usedTags: Array<{
|
|
123
|
+
title: string
|
|
124
|
+
content?: unknown
|
|
125
|
+
block: XMLElement
|
|
126
|
+
}> = []
|
|
127
|
+
const ambles = [this.preamble, this.postamble].filter(
|
|
128
|
+
(amble): amble is XMLElement => amble !== null
|
|
129
|
+
)
|
|
109
130
|
ambles.forEach(amble => {
|
|
110
131
|
const blocks = amble.queryAll(["text:p", "text:h"])
|
|
111
|
-
blocks.forEach(
|
|
112
|
-
if (block.parentElement
|
|
132
|
+
blocks.forEach(block => {
|
|
133
|
+
if (block.parentElement?.tagName === "text:deletion") {
|
|
113
134
|
return
|
|
114
135
|
}
|
|
115
136
|
const text = block.textContent
|
|
@@ -126,21 +147,23 @@ export class ODTBookExporterRender extends ODTExporterRender {
|
|
|
126
147
|
|
|
127
148
|
assemble(): void {
|
|
128
149
|
this.styles.addPageBreakStyle()
|
|
129
|
-
const text = this.fileXml
|
|
130
|
-
Array.from(this.preamble
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
this.bodyParts.forEach((bodyPart
|
|
134
|
-
const children = bodyPart.children
|
|
135
|
-
|
|
150
|
+
const text = this.fileXml!.query("office:text") as XMLElement
|
|
151
|
+
Array.from(this.preamble!.children)
|
|
152
|
+
.filter((node): node is XMLElement => node instanceof XMLElement)
|
|
153
|
+
.forEach(node => text.appendChild(node))
|
|
154
|
+
this.bodyParts.forEach((bodyPart, index) => {
|
|
155
|
+
const children = bodyPart.children
|
|
156
|
+
.slice()
|
|
157
|
+
.filter((node): node is XMLElement => node instanceof XMLElement)
|
|
158
|
+
children.forEach(node => {
|
|
136
159
|
text.appendChild(node)
|
|
137
160
|
})
|
|
138
161
|
if (index < this.bodyParts.length - 1) {
|
|
139
162
|
text.appendXML('<text:p text:style-name="PageBreak"/>')
|
|
140
163
|
}
|
|
141
164
|
})
|
|
142
|
-
Array.from(this.postamble
|
|
143
|
-
|
|
144
|
-
|
|
165
|
+
Array.from(this.postamble!.children)
|
|
166
|
+
.filter((node): node is XMLElement => node instanceof XMLElement)
|
|
167
|
+
.forEach(node => text.appendChild(node))
|
|
145
168
|
}
|
|
146
169
|
}
|
|
@@ -54,7 +54,9 @@ export class PrintBookExporter extends HTMLBookExporter {
|
|
|
54
54
|
if (!htmlDoc) {
|
|
55
55
|
return
|
|
56
56
|
}
|
|
57
|
-
const config:
|
|
57
|
+
const config: {title: string; printCallback?: (iframeWin: Window) => void} = {
|
|
58
|
+
title: this.book.title
|
|
59
|
+
}
|
|
58
60
|
|
|
59
61
|
if (navigator.userAgent.includes("Gecko/")) {
|
|
60
62
|
config.printCallback = (iframeWin: Window) => {
|
package/src/exporter/tools.ts
CHANGED
|
@@ -7,11 +7,12 @@
|
|
|
7
7
|
* decrypt end-to-end encrypted chapters.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import type {Schema} from "prosemirror-model"
|
|
10
|
+
import type {Node, Schema} from "prosemirror-model"
|
|
11
11
|
import {getSettings} from "@fiduswriter/document/schema/convert"
|
|
12
12
|
import {acceptAllNoInsertions} from "@fiduswriter/document/transform"
|
|
13
13
|
import {gettext} from "fwtoolkit"
|
|
14
14
|
import type {ProgressCallback} from "@fiduswriter/document/exporter/tools/progress"
|
|
15
|
+
import type {FidusDoc} from "@fiduswriter/document"
|
|
15
16
|
|
|
16
17
|
import type {
|
|
17
18
|
ChapterLoader,
|
|
@@ -172,13 +173,13 @@ async function decryptE2EEChapters(
|
|
|
172
173
|
// Parse ProseMirror content.
|
|
173
174
|
if (rawContent) {
|
|
174
175
|
doc.rawContent = JSON.parse(
|
|
175
|
-
JSON.stringify(schema.nodeFromJSON(decryptedContent as Record<string, unknown>).toJSON())
|
|
176
|
+
JSON.stringify(schema.nodeFromJSON(decryptedContent as unknown as Record<string, unknown>).toJSON())
|
|
176
177
|
)
|
|
177
178
|
}
|
|
178
179
|
doc.content = acceptAllNoInsertions(
|
|
179
|
-
schema.nodeFromJSON(decryptedContent as Record<string, unknown>)
|
|
180
|
+
schema.nodeFromJSON(decryptedContent as unknown as Record<string, unknown>) as Node
|
|
180
181
|
).toJSON()
|
|
181
|
-
doc.settings = getSettings(doc.content)
|
|
182
|
+
doc.settings = getSettings(doc.content as unknown as FidusDoc)
|
|
182
183
|
|
|
183
184
|
// Decrypt encrypted images.
|
|
184
185
|
const encryptedImageEntries = Object.entries(doc.images || {}).filter(
|
|
@@ -167,7 +167,7 @@ export class NativeBookImporter {
|
|
|
167
167
|
|
|
168
168
|
const bookData = JSON.parse(
|
|
169
169
|
textFiles.find(f => f.filename === "book.json")?.content || "{}"
|
|
170
|
-
) as Record<string,
|
|
170
|
+
) as Record<string, unknown>
|
|
171
171
|
|
|
172
172
|
const sortedChapters = [...(bookData.chapters as Array<{chapter_index: number; number: number; part?: string}>)].sort(
|
|
173
173
|
(a, b) => a.chapter_index - b.chapter_index
|
|
@@ -197,9 +197,9 @@ export class NativeBookImporter {
|
|
|
197
197
|
throw new Error(`Missing chapter data for index ${ci}`)
|
|
198
198
|
}
|
|
199
199
|
|
|
200
|
-
const docJson = JSON.parse(docFile.content) as Record<string,
|
|
201
|
-
const imagesJson = JSON.parse(imagesFile.content) as Record<string,
|
|
202
|
-
const bibJson = JSON.parse(bibFile.content) as Record<string,
|
|
200
|
+
const docJson = JSON.parse(docFile.content) as Record<string, unknown>
|
|
201
|
+
const imagesJson = JSON.parse(imagesFile.content) as Record<string, unknown>
|
|
202
|
+
const bibJson = JSON.parse(bibFile.content) as Record<string, unknown>
|
|
203
203
|
|
|
204
204
|
const chapterPrefix = `chapters/${ci}/images/`
|
|
205
205
|
const chapterOtherFiles = binaryFiles
|
|
@@ -220,7 +220,7 @@ export class NativeBookImporter {
|
|
|
220
220
|
const importer = new NativeImporter(
|
|
221
221
|
docJson,
|
|
222
222
|
bibJson,
|
|
223
|
-
{db: imagesJson},
|
|
223
|
+
{db: imagesJson as unknown as import("@fiduswriter/document").ImageDB["db"]},
|
|
224
224
|
chapterOtherFiles,
|
|
225
225
|
this.user,
|
|
226
226
|
this.nativeBackend,
|
|
@@ -256,7 +256,7 @@ export class NativeBookImporter {
|
|
|
256
256
|
part: chapter.part || ""
|
|
257
257
|
}))
|
|
258
258
|
|
|
259
|
-
const book = await this.bookBackend.createBook(bookData
|
|
259
|
+
const book = await this.bookBackend.createBook(bookData, chapters, false)
|
|
260
260
|
this.bookId = book.id || null
|
|
261
261
|
this.ok = true
|
|
262
262
|
this.statusText = `"${bookData.title}" ${gettext("successfully imported.")}`
|