Files
docx-js/ts/numbering/level.ts

99 lines
2.4 KiB
TypeScript
Raw Normal View History

2017-03-08 17:13:27 +01:00
import { ParagraphProperties } from "../docx/paragraph/properties";
import { RunProperties } from "../docx/run/properties";
import { Attributes, MultiPropertyXmlComponent, XmlAttributeComponent, XmlComponent } from "../docx/xml-components";
2016-05-19 22:42:23 +01:00
2017-03-08 17:13:27 +01:00
interface ILevelAttributesProperties {
2016-05-26 15:08:34 +01:00
ilvl?: number;
tentative?: number;
2016-05-19 22:42:23 +01:00
}
class LevelAttributes extends XmlAttributeComponent {
2017-03-08 17:13:27 +01:00
constructor(properties: ILevelAttributesProperties) {
2016-05-19 22:42:23 +01:00
super({
ilvl: "w:ilvl",
2017-03-08 17:13:27 +01:00
tentative: "w15:tentative",
2016-05-19 22:42:23 +01:00
}, properties);
}
}
class Start extends XmlComponent {
constructor(value: number) {
super("w:start");
this.root.push(new Attributes({
2017-03-08 17:13:27 +01:00
val: value,
2016-05-19 22:42:23 +01:00
}));
}
}
class NumberFormat extends XmlComponent {
constructor(value: string) {
super("w:numFmt");
this.root.push(new Attributes({
2017-03-08 17:13:27 +01:00
val: value,
2016-05-19 22:42:23 +01:00
}));
}
}
class LevelText extends XmlComponent {
constructor(value: string) {
super("w:lvlText");
this.root.push(new Attributes({
2017-03-08 17:13:27 +01:00
val: value,
2016-05-19 22:42:23 +01:00
}));
}
}
class LevelJc extends XmlComponent {
constructor(value: string) {
super("w:lvlJc");
this.root.push(new Attributes({
2017-03-08 17:13:27 +01:00
val: value,
2016-05-19 22:42:23 +01:00
}));
}
}
export class Level extends XmlComponent {
private paragraphProperties: ParagraphProperties;
private runProperties: RunProperties;
constructor(level: number, numberFormat: string, levelText: string, lvlJc: string) {
super("w:lvl");
this.root.push(new LevelAttributes({
ilvl: level,
2017-03-08 17:13:27 +01:00
tentative: 1,
2016-05-19 22:42:23 +01:00
}));
this.root.push(new Start(1));
this.root.push(new NumberFormat(numberFormat));
this.root.push(new LevelText(levelText));
this.root.push(new LevelJc(lvlJc));
this.paragraphProperties = new ParagraphProperties();
this.runProperties = new RunProperties();
this.root.push(this.paragraphProperties);
this.root.push(this.runProperties);
}
2017-03-08 17:13:27 +01:00
public clearVariables(): void {
2016-05-19 22:42:23 +01:00
this.paragraphProperties.clearVariables();
this.runProperties.clearVariables();
delete this.paragraphProperties;
delete this.runProperties;
}
2016-05-23 22:23:05 +01:00
2017-03-08 17:13:27 +01:00
public addParagraphProperty(property: XmlComponent): void {
2016-05-19 22:42:23 +01:00
this.paragraphProperties.push(property);
}
2017-03-08 17:13:27 +01:00
public addRunProperty(property: XmlComponent): void {
2016-05-19 22:42:23 +01:00
this.runProperties.push(property);
}
2017-03-08 17:13:27 +01:00
}