Change to new header API

This commit is contained in:
Dolan
2018-10-05 01:33:17 +01:00
parent 3508fd97ec
commit 97f76fb62c
4 changed files with 215 additions and 100 deletions

View File

@ -2,7 +2,13 @@ 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 { FooterReferenceType, HeaderReference, HeaderReferenceType, SectionPropertiesOptions } from "./document/body/section-properties";
import {
FooterReferenceType,
HeaderReference,
HeaderReferenceType,
IHeaderFooterGroup,
SectionPropertiesOptions,
} from "./document/body/section-properties";
import { IFileProperties } from "./file-properties";
import { FooterWrapper, IDocumentFooter } from "./footer-wrapper";
import { FootNotes } from "./footnotes";
@ -91,14 +97,8 @@ export class File {
sectionPropertiesOptions = {
...sectionPropertiesOptions,
headers: this.headers.map((header) => ({
headerId: header.header.Header.ReferenceId,
headerType: header.type,
})),
footers: this.footers.map((footer) => ({
footerId: footer.footer.Footer.ReferenceId,
footerType: footer.type,
})),
headers: this.groupHeaders(this.headers, sectionPropertiesOptions.headers),
footers: this.groupFooters(this.footers, sectionPropertiesOptions.footers),
};
this.document = new Document(sectionPropertiesOptions);
@ -273,6 +273,68 @@ export class File {
);
}
private groupHeaders(headers: IDocumentHeader[], group: IHeaderFooterGroup<HeaderWrapper> = {}): IHeaderFooterGroup<HeaderWrapper> {
let newGroup = group;
for (const header of headers) {
switch (header.type) {
case HeaderReferenceType.DEFAULT:
newGroup = {
...newGroup,
default: header.header,
};
case HeaderReferenceType.FIRST:
newGroup = {
...newGroup,
first: header.header,
};
case HeaderReferenceType.EVEN:
newGroup = {
...newGroup,
even: header.header,
};
default:
newGroup = {
...newGroup,
default: header.header,
};
}
}
return newGroup;
}
private groupFooters(footers: IDocumentFooter[], group: IHeaderFooterGroup<FooterWrapper> = {}): IHeaderFooterGroup<FooterWrapper> {
let newGroup = group;
for (const footer of footers) {
switch (footer.type) {
case FooterReferenceType.DEFAULT:
newGroup = {
...newGroup,
default: footer.footer,
};
case FooterReferenceType.FIRST:
newGroup = {
...newGroup,
first: footer.footer,
};
case FooterReferenceType.EVEN:
newGroup = {
...newGroup,
even: footer.footer,
};
default:
newGroup = {
...newGroup,
default: footer.footer,
};
}
}
return newGroup;
}
public get Document(): Document {
return this.document;
}