Work on moving Document into its own wrapper

This commit is contained in:
Dolan
2021-02-28 16:04:21 +00:00
parent e750735fa4
commit 655b40d418
15 changed files with 157 additions and 65 deletions

View File

@ -1,7 +1,7 @@
import { AppProperties } from "./app-properties/app-properties";
import { ContentTypes } from "./content-types/content-types";
import { CoreProperties, IPropertiesOptions } from "./core-properties";
import { Document } from "./document";
import { DocumentWrapper } from "./document-wrapper";
import {
FooterReferenceType,
HeaderReferenceType,
@ -46,10 +46,9 @@ export class File {
// tslint:disable-next-line:readonly-keyword
private currentRelationshipId: number = 1;
private readonly document: Document;
private readonly documentWrapper: DocumentWrapper;
private readonly headers: IDocumentHeader[] = [];
private readonly footers: IDocumentFooter[] = [];
private readonly docRelationships: Relationships;
private readonly coreProperties: CoreProperties;
private readonly numbering: Numbering;
private readonly media: Media;
@ -77,12 +76,12 @@ export class File {
config: [],
},
);
this.docRelationships = new Relationships();
// this.documentWrapper.Relationships = new Relationships();
this.fileRelationships = new Relationships();
this.appProperties = new AppProperties();
this.footNotes = new FootNotes();
this.contentTypes = new ContentTypes();
this.document = new Document({ background: options.background || {} });
this.documentWrapper = new DocumentWrapper({ background: options.background || {} });
this.settings = new Settings({
compatabilityModeVersion: options.compatabilityModeVersion,
});
@ -130,10 +129,10 @@ export class File {
}
for (const section of sections) {
this.document.Body.addSection(section.properties ? section.properties : {});
this.documentWrapper.View.Body.addSection(section.properties ? section.properties : {});
for (const child of section.children) {
this.document.add(child);
this.documentWrapper.View.add(child);
}
}
@ -158,7 +157,7 @@ export class File {
properties,
children,
}: ISectionOptions): void {
this.document.Body.addSection({
this.documentWrapper.View.Body.addSection({
...properties,
headers: {
default: headers.default ? this.createHeader(headers.default) : this.createHeader(new Header()),
@ -175,12 +174,12 @@ export class File {
});
for (const child of children) {
this.document.add(child);
this.documentWrapper.View.add(child);
}
}
public verifyUpdateFields(): void {
if (this.document.getTablesOfContents().length) {
if (this.documentWrapper.View.getTablesOfContents().length) {
this.settings.addUpdateFields();
}
}
@ -209,8 +208,8 @@ export class File {
private addHeaderToDocument(header: HeaderWrapper, type: HeaderReferenceType = HeaderReferenceType.DEFAULT): void {
this.headers.push({ header, type });
this.docRelationships.createRelationship(
header.Header.ReferenceId,
this.documentWrapper.Relationships.createRelationship(
header.View.ReferenceId,
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/header",
`header${this.headers.length}.xml`,
);
@ -219,8 +218,8 @@ export class File {
private addFooterToDocument(footer: FooterWrapper, type: FooterReferenceType = FooterReferenceType.DEFAULT): void {
this.footers.push({ footer, type });
this.docRelationships.createRelationship(
footer.Footer.ReferenceId,
this.documentWrapper.Relationships.createRelationship(
footer.View.ReferenceId,
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer",
`footer${this.footers.length}.xml`,
);
@ -244,30 +243,30 @@ export class File {
"docProps/app.xml",
);
this.docRelationships.createRelationship(
this.documentWrapper.Relationships.createRelationship(
this.currentRelationshipId++,
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles",
"styles.xml",
);
this.docRelationships.createRelationship(
this.documentWrapper.Relationships.createRelationship(
this.currentRelationshipId++,
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering",
"numbering.xml",
);
this.docRelationships.createRelationship(
this.documentWrapper.Relationships.createRelationship(
this.currentRelationshipId++,
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/footnotes",
"footnotes.xml",
);
this.docRelationships.createRelationship(
this.documentWrapper.Relationships.createRelationship(
this.currentRelationshipId++,
"http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings",
"settings.xml",
);
}
public get Document(): Document {
return this.document;
public get Document(): DocumentWrapper {
return this.documentWrapper;
}
public get Styles(): Styles {
@ -286,10 +285,6 @@ export class File {
return this.media;
}
public get DocumentRelationships(): Relationships {
return this.docRelationships;
}
public get FileRelationships(): Relationships {
return this.fileRelationships;
}