Rename variables

This commit is contained in:
Dolan
2018-09-26 02:17:39 +01:00
parent e08c7cbbfb
commit 2da3ba0262
4 changed files with 13 additions and 9 deletions

View File

@ -0,0 +1,76 @@
// http://officeopenxml.com/WPfieldInstructions.php
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
import { ITableOfContentsOptions } from "./table-of-contents-properties";
enum SpaceType {
DEFAULT = "default",
PRESERVE = "preserve",
}
class TextAttributes extends XmlAttributeComponent<{ space: SpaceType }> {
protected xmlKeys = { space: "xml:space" };
}
export class FieldInstruction extends XmlComponent {
private readonly properties: ITableOfContentsOptions;
constructor(properties: ITableOfContentsOptions = {}) {
super("w:instrText");
this.properties = properties;
this.root.push(new TextAttributes({ space: SpaceType.PRESERVE }));
let instruction = "TOC";
if (this.properties.captionLabel) {
instruction = `${instruction} \\a "${this.properties.captionLabel}"`;
}
if (this.properties.entriesFromBookmark) {
instruction = `${instruction} \\b "${this.properties.entriesFromBookmark}"`;
}
if (this.properties.captionLabelIncludingNumbers) {
instruction = `${instruction} \\c "${this.properties.captionLabelIncludingNumbers}"`;
}
if (this.properties.sequenceAndPageNumbersSeparator) {
instruction = `${instruction} \\d "${this.properties.sequenceAndPageNumbersSeparator}"`;
}
if (this.properties.tcFieldIdentifier) {
instruction = `${instruction} \\f "${this.properties.tcFieldIdentifier}"`;
}
if (this.properties.hyperlink) {
instruction = `${instruction} \\h`;
}
if (this.properties.tcFieldLevelRange) {
instruction = `${instruction} \\l "${this.properties.tcFieldLevelRange}`;
}
if (this.properties.pageNumbersEntryLevelsRange) {
instruction = `${instruction} \\n "${this.properties.pageNumbersEntryLevelsRange}`;
}
if (this.properties.headingStyleRange) {
instruction = `${instruction} \\o "${this.properties.headingStyleRange}`;
}
if (this.properties.entryAndPageNumberSeparator) {
instruction = `${instruction} \\p "${this.properties.entryAndPageNumberSeparator}`;
}
if (this.properties.seqFieldIdentifierForPrefix) {
instruction = `${instruction} \\s "${this.properties.seqFieldIdentifierForPrefix}`;
}
if (this.properties.stylesWithLevels && this.properties.stylesWithLevels.length) {
const styles = this.properties.stylesWithLevels.map((sl) => `${sl.styleName},${sl.level}`).join(",");
instruction = `${instruction} \\t "${styles}"`;
}
if (this.properties.useAppliedParagraphOutlineLevel) {
instruction = `${instruction} \\u`;
}
if (this.properties.preserveTabInEntries) {
instruction = `${instruction} \\w`;
}
if (this.properties.preserveNewLineInEntries) {
instruction = `${instruction} \\x`;
}
if (this.properties.hideTabAndPageNumbersInWebView) {
instruction = `${instruction} \\z`;
}
this.root.push(instruction);
}
}