From c140d2c37c66a38dcb48f59e50969bcdb670d5fb Mon Sep 17 00:00:00 2001 From: Dolan Date: Tue, 25 Sep 2018 21:09:30 +0100 Subject: [PATCH] ITableOfContentsProperties to ITableOfContentsOptions --- demo/demo28.ts | 2 +- .../table-of-contents-instruction.ts | 15 ++++++++++----- .../table-of-contents-properties.ts | 2 +- .../table-of-contents/table-of-contents.spec.ts | 4 ++-- src/file/table-of-contents/table-of-contents.ts | 4 ++-- 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/demo/demo28.ts b/demo/demo28.ts index ce545b986c..d13acf5b46 100644 --- a/demo/demo28.ts +++ b/demo/demo28.ts @@ -21,7 +21,7 @@ doc.Styles.createParagraphStyle("MySpectacularStyle", "My Spectacular Style") const toc = new TableOfContents("Summary", { hyperlink: true, headingStyleRange: "1-5", - stylesWithLevels: [new StyleLevel("MySpectacularStyle", 1)] + stylesWithLevels: [new StyleLevel("MySpectacularStyle", 1)], }); doc.addTableOfContents(toc); diff --git a/src/file/table-of-contents/table-of-contents-instruction.ts b/src/file/table-of-contents/table-of-contents-instruction.ts index c73a439861..1183ebd3de 100644 --- a/src/file/table-of-contents/table-of-contents-instruction.ts +++ b/src/file/table-of-contents/table-of-contents-instruction.ts @@ -1,19 +1,24 @@ import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; -import { ITableOfContentsProperties } from "./table-of-contents-properties"; +import { ITableOfContentsOptions } from "./table-of-contents-properties"; -class TextAttributes extends XmlAttributeComponent<{ space: "default" | "preserve" }> { +enum SpaceType { + DEFAULT = "default", + PRESERVE = "preserve", +} + +class TextAttributes extends XmlAttributeComponent<{ space: SpaceType }> { protected xmlKeys = { space: "xml:space" }; } export class TableOfContentsInstruction extends XmlComponent { - private readonly properties: ITableOfContentsProperties; + private readonly properties: ITableOfContentsOptions; - constructor(properties: ITableOfContentsProperties = {}) { + constructor(properties: ITableOfContentsOptions = {}) { super("w:instrText"); this.properties = properties; - this.root.push(new TextAttributes({ space: "preserve" })); + this.root.push(new TextAttributes({ space: SpaceType.PRESERVE })); let instruction = "TOC"; if (this.properties.captionLabel) { diff --git a/src/file/table-of-contents/table-of-contents-properties.ts b/src/file/table-of-contents/table-of-contents-properties.ts index 21b1c5ec40..bc312429af 100644 --- a/src/file/table-of-contents/table-of-contents-properties.ts +++ b/src/file/table-of-contents/table-of-contents-properties.ts @@ -16,7 +16,7 @@ export class StyleLevel { * Short Guide: * http://officeopenxml.com/WPtableOfContents.php */ -export interface ITableOfContentsProperties { +export interface ITableOfContentsOptions { /** * \a option - Includes captioned items, but omits caption labels and numbers. * The identifier designated by text in this switch's field-argument corresponds to the caption label. diff --git a/src/file/table-of-contents/table-of-contents.spec.ts b/src/file/table-of-contents/table-of-contents.spec.ts index 0d5554fe2b..7d7d4a55b6 100644 --- a/src/file/table-of-contents/table-of-contents.spec.ts +++ b/src/file/table-of-contents/table-of-contents.spec.ts @@ -1,7 +1,7 @@ import { expect } from "chai"; import { Formatter } from "../../export/formatter"; -import { ITableOfContentsProperties, StyleLevel, TableOfContents } from "./"; +import { ITableOfContentsOptions, StyleLevel, TableOfContents } from "./"; describe("Table of Contents", () => { describe("#constructor", () => { @@ -12,7 +12,7 @@ describe("Table of Contents", () => { }); it("should construct a TOC with all the options and alias", () => { - const props: ITableOfContentsProperties = {}; + const props: ITableOfContentsOptions = {}; props.captionLabel = "A"; props.entriesFromBookmark = "B"; diff --git a/src/file/table-of-contents/table-of-contents.ts b/src/file/table-of-contents/table-of-contents.ts index a7fa85f85f..fb7b709c4f 100644 --- a/src/file/table-of-contents/table-of-contents.ts +++ b/src/file/table-of-contents/table-of-contents.ts @@ -5,10 +5,10 @@ import { XmlComponent } from "file/xml-components"; import { SdtContent } from "./sdt-content"; import { SdtProperties } from "./sdt-properties"; import { TableOfContentsInstruction } from "./table-of-contents-instruction"; -import { ITableOfContentsProperties } from "./table-of-contents-properties"; +import { ITableOfContentsOptions } from "./table-of-contents-properties"; export class TableOfContents extends XmlComponent { - constructor(alias: string = "Table of Contents", properties?: ITableOfContentsProperties) { + constructor(alias: string = "Table of Contents", properties?: ITableOfContentsOptions) { super("w:sdt"); this.root.push(new SdtProperties(alias));