From b47eaf739e9fd752f0d761b97a22682a8030c778 Mon Sep 17 00:00:00 2001 From: Dolan Miu Date: Thu, 19 May 2016 22:42:23 +0100 Subject: [PATCH] added numbering files --- ts/docx/xml-components/index.ts | 10 ++- ts/numbering/abstract-numbering.ts | 28 ++++++++ ts/numbering/index.ts | 28 ++++++++ ts/numbering/level.ts | 101 +++++++++++++++++++++++++++++ 4 files changed, 166 insertions(+), 1 deletion(-) create mode 100644 ts/numbering/abstract-numbering.ts create mode 100644 ts/numbering/index.ts create mode 100644 ts/numbering/level.ts diff --git a/ts/docx/xml-components/index.ts b/ts/docx/xml-components/index.ts index 818994bdbc..38ad807364 100644 --- a/ts/docx/xml-components/index.ts +++ b/ts/docx/xml-components/index.ts @@ -1,4 +1,6 @@ import * as _ from "lodash"; +import {ParagraphProperties} from "../paragraph/properties"; +import {RunProperties} from "../run/properties"; export abstract class BaseXmlComponent { protected rootKey: string; @@ -54,9 +56,15 @@ export abstract class XmlAttributeComponent extends BaseXmlComponent { protected root: Object; private xmlKeys: Object; - constructor(xmlKeys: Object) { + constructor(xmlKeys: Object, properties: Object) { super("_attr"); this.xmlKeys = xmlKeys; + + this.root = properties + + if (!properties) { + this.root = {}; + } } replaceKey(): void { diff --git a/ts/numbering/abstract-numbering.ts b/ts/numbering/abstract-numbering.ts new file mode 100644 index 0000000000..12bd98ee08 --- /dev/null +++ b/ts/numbering/abstract-numbering.ts @@ -0,0 +1,28 @@ +import {XmlComponent} from "../docx/xml-components"; +import {XmlAttributeComponent} from "../docx/xml-components"; + +interface AbstractNumberingAttributesProperties { + abstractNumId?: Number, + restartNumberingAfterBreak?: Number +} + +class AbstractNumberingAttributes extends XmlAttributeComponent { + + constructor(properties: AbstractNumberingAttributesProperties) { + super({ + abstractNumId: "w:abstractNumId", + restartNumberingAfterBreak: "w15:restartNumberingAfterBreak" + }, properties); + } +} + +export class AbstractNumbering extends XmlComponent { + + constructor() { + super("w:abstractNum"); + this.root.push(new AbstractNumberingAttributes({ + abstractNumId: 0, + restartNumberingAfterBreak: 0 + })); + } +} \ No newline at end of file diff --git a/ts/numbering/index.ts b/ts/numbering/index.ts new file mode 100644 index 0000000000..4917561a41 --- /dev/null +++ b/ts/numbering/index.ts @@ -0,0 +1,28 @@ +import {XmlComponent} from "../docx/xml-components"; +import {DocumentAttributes} from "../docx/document/document-attributes" + +export class Numbering extends XmlComponent { + + constructor() { + super("w:numbering"); + this.root.push(new DocumentAttributes({ + wpc: "http://schemas.microsoft.com/office/word/2010/wordprocessingCanvas", + mc: "http://schemas.openxmlformats.org/markup-compatibility/2006", + o: "urn:schemas-microsoft-com:office:office", + r: "http://schemas.openxmlformats.org/officeDocument/2006/relationships", + m: "http://schemas.openxmlformats.org/officeDocument/2006/math", + v: "urn:schemas-microsoft-com:vml", + wp14: "http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing", + wp: "http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing", + w10: "urn:schemas-microsoft-com:office:word", + w: "http://schemas.openxmlformats.org/wordprocessingml/2006/main", + w14: "http://schemas.microsoft.com/office/word/2010/wordml", + w15: "http://schemas.microsoft.com/office/word/2012/wordml", + wpg: "http://schemas.microsoft.com/office/word/2010/wordprocessingGroup", + wpi: "http://schemas.microsoft.com/office/word/2010/wordprocessingInk", + wne: "http://schemas.microsoft.com/office/word/2006/wordml", + wps: "http://schemas.microsoft.com/office/word/2010/wordprocessingShape", + Ignorable: "w14 w15 wp14" + })); + } +} \ No newline at end of file diff --git a/ts/numbering/level.ts b/ts/numbering/level.ts new file mode 100644 index 0000000000..b6199f7758 --- /dev/null +++ b/ts/numbering/level.ts @@ -0,0 +1,101 @@ +import {XmlComponent, Attributes, MultiPropertyXmlComponent} from "../docx/xml-components"; +import {XmlAttributeComponent} from "../docx/xml-components"; +import {RunProperties} from "../docx/run/properties"; +import {ParagraphProperties} from "../docx/paragraph/properties"; + +interface LevelAttributesProperties { + ilvl?: number, + tentative?: number +} + +class LevelAttributes extends XmlAttributeComponent { + + constructor(properties: LevelAttributesProperties) { + super({ + ilvl: "w:ilvl", + tentative: "w15:tentative" + }, properties); + } + + properties +} + +class Start extends XmlComponent { + + constructor(value: number) { + super("w:start"); + this.root.push(new Attributes({ + val: value + })); + } +} + +class NumberFormat extends XmlComponent { + + constructor(value: string) { + super("w:numFmt"); + this.root.push(new Attributes({ + val: value + })); + } +} + +class LevelText extends XmlComponent { + + constructor(value: string) { + super("w:lvlText"); + this.root.push(new Attributes({ + val: value + })); + } +} + +class LevelJc extends XmlComponent { + + constructor(value: string) { + super("w:lvlJc"); + this.root.push(new Attributes({ + val: value + })); + } +} + +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, + tentative: 1 + })); + + 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); + } + + clearVariables(): void { + this.paragraphProperties.clearVariables(); + this.runProperties.clearVariables(); + + delete this.paragraphProperties; + delete this.runProperties; + } + + addParagraphProperty(property: XmlComponent): void { + this.paragraphProperties.push(property); + } + + addRunProperty(property: XmlComponent): void { + this.runProperties.push(property); + } +} \ No newline at end of file