ITableOfContentsProperties to ITableOfContentsOptions
This commit is contained in:
@ -21,7 +21,7 @@ doc.Styles.createParagraphStyle("MySpectacularStyle", "My Spectacular Style")
|
|||||||
const toc = new TableOfContents("Summary", {
|
const toc = new TableOfContents("Summary", {
|
||||||
hyperlink: true,
|
hyperlink: true,
|
||||||
headingStyleRange: "1-5",
|
headingStyleRange: "1-5",
|
||||||
stylesWithLevels: [new StyleLevel("MySpectacularStyle", 1)]
|
stylesWithLevels: [new StyleLevel("MySpectacularStyle", 1)],
|
||||||
});
|
});
|
||||||
|
|
||||||
doc.addTableOfContents(toc);
|
doc.addTableOfContents(toc);
|
||||||
|
@ -1,19 +1,24 @@
|
|||||||
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
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" };
|
protected xmlKeys = { space: "xml:space" };
|
||||||
}
|
}
|
||||||
|
|
||||||
export class TableOfContentsInstruction extends XmlComponent {
|
export class TableOfContentsInstruction extends XmlComponent {
|
||||||
private readonly properties: ITableOfContentsProperties;
|
private readonly properties: ITableOfContentsOptions;
|
||||||
|
|
||||||
constructor(properties: ITableOfContentsProperties = {}) {
|
constructor(properties: ITableOfContentsOptions = {}) {
|
||||||
super("w:instrText");
|
super("w:instrText");
|
||||||
|
|
||||||
this.properties = properties;
|
this.properties = properties;
|
||||||
|
|
||||||
this.root.push(new TextAttributes({ space: "preserve" }));
|
this.root.push(new TextAttributes({ space: SpaceType.PRESERVE }));
|
||||||
let instruction = "TOC";
|
let instruction = "TOC";
|
||||||
|
|
||||||
if (this.properties.captionLabel) {
|
if (this.properties.captionLabel) {
|
||||||
|
@ -16,7 +16,7 @@ export class StyleLevel {
|
|||||||
* Short Guide:
|
* Short Guide:
|
||||||
* http://officeopenxml.com/WPtableOfContents.php
|
* http://officeopenxml.com/WPtableOfContents.php
|
||||||
*/
|
*/
|
||||||
export interface ITableOfContentsProperties {
|
export interface ITableOfContentsOptions {
|
||||||
/**
|
/**
|
||||||
* \a option - Includes captioned items, but omits caption labels and numbers.
|
* \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.
|
* The identifier designated by text in this switch's field-argument corresponds to the caption label.
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { expect } from "chai";
|
import { expect } from "chai";
|
||||||
|
|
||||||
import { Formatter } from "../../export/formatter";
|
import { Formatter } from "../../export/formatter";
|
||||||
import { ITableOfContentsProperties, StyleLevel, TableOfContents } from "./";
|
import { ITableOfContentsOptions, StyleLevel, TableOfContents } from "./";
|
||||||
|
|
||||||
describe("Table of Contents", () => {
|
describe("Table of Contents", () => {
|
||||||
describe("#constructor", () => {
|
describe("#constructor", () => {
|
||||||
@ -12,7 +12,7 @@ describe("Table of Contents", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should construct a TOC with all the options and alias", () => {
|
it("should construct a TOC with all the options and alias", () => {
|
||||||
const props: ITableOfContentsProperties = {};
|
const props: ITableOfContentsOptions = {};
|
||||||
|
|
||||||
props.captionLabel = "A";
|
props.captionLabel = "A";
|
||||||
props.entriesFromBookmark = "B";
|
props.entriesFromBookmark = "B";
|
||||||
|
@ -5,10 +5,10 @@ import { XmlComponent } from "file/xml-components";
|
|||||||
import { SdtContent } from "./sdt-content";
|
import { SdtContent } from "./sdt-content";
|
||||||
import { SdtProperties } from "./sdt-properties";
|
import { SdtProperties } from "./sdt-properties";
|
||||||
import { TableOfContentsInstruction } from "./table-of-contents-instruction";
|
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 {
|
export class TableOfContents extends XmlComponent {
|
||||||
constructor(alias: string = "Table of Contents", properties?: ITableOfContentsProperties) {
|
constructor(alias: string = "Table of Contents", properties?: ITableOfContentsOptions) {
|
||||||
super("w:sdt");
|
super("w:sdt");
|
||||||
this.root.push(new SdtProperties(alias));
|
this.root.push(new SdtProperties(alias));
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user