diff --git a/ts/docx/document/body/columns.ts b/ts/docx/document/body/columns.ts index 12a0f0ae80..9614f3c75a 100644 --- a/ts/docx/document/body/columns.ts +++ b/ts/docx/document/body/columns.ts @@ -1,15 +1,10 @@ import {XmlComponent, Attributes} from "../../xml-components"; -export class Columns implements XmlComponent { - private cols: Array; - - xmlKeys = { - cols: 'w:cols' - } +export class Columns extends XmlComponent { constructor() { - this.cols = new Array(); - this.cols.push(new Attributes({ + super("w:cols"); + this.root.push(new Attributes({ space: "708" })); } diff --git a/ts/docx/document/body/doc-grid.ts b/ts/docx/document/body/doc-grid.ts index 66104790c7..5c2c0509c3 100644 --- a/ts/docx/document/body/doc-grid.ts +++ b/ts/docx/document/body/doc-grid.ts @@ -1,15 +1,10 @@ import {XmlComponent, Attributes} from "../../xml-components"; -export class DocumentGrid implements XmlComponent { - private docGrid: Array; - - xmlKeys = { - docGrid: 'w:docGrid' - } +export class DocumentGrid extends XmlComponent { constructor() { - this.docGrid = new Array(); - this.docGrid.push(new Attributes({ + super("w:docGrid"); + this.root.push(new Attributes({ linePitch: "360" })); } diff --git a/ts/docx/document/body/index.ts b/ts/docx/document/body/index.ts index a157928dbf..bca20ebdc2 100644 --- a/ts/docx/document/body/index.ts +++ b/ts/docx/document/body/index.ts @@ -1,20 +1,15 @@ import {XmlComponent, Attributes} from "../../xml-components"; import {SectionProperties} from "./section-properties"; -export class Body implements XmlComponent { - private body: Array; - - xmlKeys = { - body: 'w:body' - } +export class Body extends XmlComponent { constructor() { - this.body = new Array(); - //this.body.push(new SectionProperties()); not actually needed + super("w:body"); + //this.root.push(new SectionProperties()); not actually needed } push(component: XmlComponent) { - //this.body.splice(this.body.length - 1, 0, component); - this.body.push(component); + //this.root.splice(this.body.length - 1, 0, component); + this.root.push(component); } } diff --git a/ts/docx/document/body/page-margin.ts b/ts/docx/document/body/page-margin.ts index 891c6b037b..b98525d988 100644 --- a/ts/docx/document/body/page-margin.ts +++ b/ts/docx/document/body/page-margin.ts @@ -1,15 +1,10 @@ import {XmlComponent, Attributes} from "../../xml-components"; -export class PageMargin implements XmlComponent { - private pgMar: Array; - - xmlKeys = { - pgMar: 'w:pgMar' - } +export class PageMargin extends XmlComponent { constructor() { - this.pgMar = new Array(); - this.pgMar.push(new Attributes({ + super("w:pgMar"); + this.root.push(new Attributes({ top: "1440", right: "1440", bottom: "1440", diff --git a/ts/docx/document/body/page-size.ts b/ts/docx/document/body/page-size.ts index fa824f1b9a..9ed44cdf34 100644 --- a/ts/docx/document/body/page-size.ts +++ b/ts/docx/document/body/page-size.ts @@ -1,15 +1,10 @@ import {XmlComponent, Attributes} from "../../xml-components"; -export class PageSize implements XmlComponent { - private pgSz: Array; - - xmlKeys = { - pgSz: 'w:pgSz' - } +export class PageSize extends XmlComponent { constructor() { - this.pgSz = new Array(); - this.pgSz.push(new Attributes({ + super("w:pgSz"); + this.root.push(new Attributes({ w: "11906", h: "16838" })); diff --git a/ts/docx/document/body/section-properties.ts b/ts/docx/document/body/section-properties.ts index 86f4e67fcd..0f6d9a123b 100644 --- a/ts/docx/document/body/section-properties.ts +++ b/ts/docx/document/body/section-properties.ts @@ -4,23 +4,18 @@ import {PageMargin} from "./page-margin"; import {Columns} from "./columns"; import {DocumentGrid} from "./doc-grid"; -export class SectionProperties implements XmlComponent { - private sectPr: Array; - - xmlKeys = { - sectPr: 'w:sectPr' - } +export class SectionProperties extends XmlComponent { constructor() { - this.sectPr = new Array(); - this.sectPr.push(new Attributes({ + super("w:sectPr"); + this.root.push(new Attributes({ rsidR: "00B64E8F", rsidRPr: "00D842E4", rsidSect: "000A6AD0" })); - this.sectPr.push(new PageSize()); - this.sectPr.push(new PageMargin()); - this.sectPr.push(new Columns()); - this.sectPr.push(new DocumentGrid()); + this.root.push(new PageSize()); + this.root.push(new PageMargin()); + this.root.push(new Columns()); + this.root.push(new DocumentGrid()); } } \ No newline at end of file diff --git a/ts/docx/document/index.ts b/ts/docx/document/index.ts index e9d89e1395..fc96b34a53 100644 --- a/ts/docx/document/index.ts +++ b/ts/docx/document/index.ts @@ -3,8 +3,7 @@ import {DocumentAttributes} from "../xml-components/document-attributes" import {Body} from "./body"; import {Paragraph} from "../paragraph"; -export class Document implements XmlComponent { - private document: Array; +export class Document extends XmlComponent { private body: Body; xmlKeys = { @@ -13,8 +12,8 @@ export class Document implements XmlComponent { }; constructor() { - this.document = new Array(); - this.document.push(new DocumentAttributes({ + super("w:document"); + 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', @@ -34,7 +33,7 @@ export class Document implements XmlComponent { Ignorable: 'w14 w15 wp14' })); this.body = new Body(); - this.document.push(this.body); + this.root.push(this.body); } addParagraph(paragraph: Paragraph) { diff --git a/ts/docx/paragraph/border.ts b/ts/docx/paragraph/border.ts index 6b3c1b1fb6..79f96b078b 100644 --- a/ts/docx/paragraph/border.ts +++ b/ts/docx/paragraph/border.ts @@ -1,15 +1,10 @@ import {XmlComponent, Attributes} from "../xml-components"; -class Border implements XmlComponent { - private bottom: Array; - - xmlKeys = { - bottom: 'w:bottom' - } +class Border extends XmlComponent { constructor() { - this.bottom = new Array(); - this.bottom.push(new Attributes({ + super("w:bottom"); + this.root.push(new Attributes({ color: "auto", space: "1", val: "single", @@ -18,15 +13,10 @@ class Border implements XmlComponent { } } -export class ThematicBreak implements XmlComponent { - private pBdr: Array; - - xmlKeys = { - pBdr: 'w:pBdr' - } +export class ThematicBreak extends XmlComponent { constructor() { - this.pBdr = new Array(); - this.pBdr.push(new Border()); + super("w:pBdr"); + this.root.push(new Border()); } } \ No newline at end of file diff --git a/ts/docx/paragraph/index.ts b/ts/docx/paragraph/index.ts index 79b70a2d6b..fa16b00970 100644 --- a/ts/docx/paragraph/index.ts +++ b/ts/docx/paragraph/index.ts @@ -7,39 +7,29 @@ import {TabStop} from "../tab-stop"; import {Style} from "./style"; import {NumberProperties} from "./unordered-list"; -class Alignment implements XmlComponent { - private jc: Array; - - xmlKeys = { - jc: 'w:jc' - } +class Alignment extends XmlComponent { constructor(type: string) { - this.jc = new Array(); - this.jc.push(new Attributes({ + super("w:jc"); + this.root.push(new Attributes({ val: type })); } } -export class Paragraph implements XmlComponent { - private p: Array; +export class Paragraph extends XmlComponent { private properties: ParagraphProperties; - xmlKeys = { - p: 'w:p' - } - constructor(text?: string) { - this.p = new Array(); - this.p.push(new Attributes()); + super("w:p"); + this.root.push(new Attributes()); this.properties = new ParagraphProperties(); - this.p.push(this.properties); - this.p.push(new TextRun(text)); + this.root.push(this.properties); + this.root.push(new TextRun(text)); } addText(run: TextRun): Paragraph { - this.p.push(run); + this.root.push(run); return this; } diff --git a/ts/docx/paragraph/page-break.ts b/ts/docx/paragraph/page-break.ts index a40e5a8ee8..c7bf5811a0 100644 --- a/ts/docx/paragraph/page-break.ts +++ b/ts/docx/paragraph/page-break.ts @@ -1,18 +1,13 @@ import {XmlComponent, Attributes} from "../xml-components"; import {Run} from "../run"; -class Break implements XmlComponent { - private br: Array; - - xmlKeys = { - br: 'w:br' - } +class Break extends XmlComponent { constructor() { - this.br = new Array(); - this.br.push(new Attributes({ + super("w:br"); + this.root.push(new Attributes({ type: "page" - })) + })); } } @@ -20,6 +15,6 @@ export class PageBreak extends Run { constructor() { super(); - this.r.push(new Break()); + this.root.push(new Break()); } } \ No newline at end of file diff --git a/ts/docx/paragraph/properties.ts b/ts/docx/paragraph/properties.ts index a47e1f550c..5675a472cf 100644 --- a/ts/docx/paragraph/properties.ts +++ b/ts/docx/paragraph/properties.ts @@ -1,18 +1,13 @@ import {XmlComponent, Attributes} from "../xml-components"; -export class ParagraphProperties implements XmlComponent { - private pPr: Array; - - xmlKeys = { - pPr: 'w:rPr' - } +export class ParagraphProperties extends XmlComponent { constructor() { - this.pPr = new Array(); - this.pPr.push(new Attributes()); + super("w:rPr"); + this.root.push(new Attributes()); } push(item: XmlComponent): void { - this.pPr.push(item); + this.root.push(item); } } \ No newline at end of file diff --git a/ts/docx/paragraph/style.ts b/ts/docx/paragraph/style.ts index fe41f6ee5d..b47c6989b4 100644 --- a/ts/docx/paragraph/style.ts +++ b/ts/docx/paragraph/style.ts @@ -1,15 +1,10 @@ import {XmlComponent, Attributes} from "../xml-components"; -export class Style implements XmlComponent { - private pStyle: Array; - - xmlKeys = { - pStyle: 'w:pStyle' - } +export class Style extends XmlComponent { constructor(type: string) { - this.pStyle = new Array(); - this.pStyle.push(new Attributes({ + super("w:pStyle"); + this.root.push(new Attributes({ val: type })); } diff --git a/ts/docx/paragraph/unordered-list.ts b/ts/docx/paragraph/unordered-list.ts index c29421c8aa..b6d1e52a8f 100644 --- a/ts/docx/paragraph/unordered-list.ts +++ b/ts/docx/paragraph/unordered-list.ts @@ -1,45 +1,29 @@ import {XmlComponent, Attributes} from "../xml-components"; import {Style} from "./style"; -export class NumberProperties implements XmlComponent { - private numPr: Array; - - xmlKeys = { - numPr: 'w:numPr' - } - +export class NumberProperties extends XmlComponent { + constructor() { - this.numPr = new Array(); - this.numPr.push(new IndentLevel(0)); - this.numPr.push(new NumberId(1)); + super("w:numPr"); + this.root.push(new IndentLevel(0)); + this.root.push(new NumberId(1)); } } -export class IndentLevel implements XmlComponent { - private ilvl: Array; - - xmlKeys = { - ilvl: 'w:ilvl' - } +export class IndentLevel extends XmlComponent { constructor(level: number) { - this.ilvl = new Array(); - this.ilvl.push(new Attributes({ + super("w:ilvl"); + this.root.push(new Attributes({ val: level })); } } -export class NumberId implements XmlComponent { - private ilvl: Array; - - xmlKeys = { - ilvl: 'w:ilvl' - } - +export class NumberId extends XmlComponent { constructor(id: number) { - this.ilvl = new Array(); - this.ilvl.push(new Attributes({ + super("w:numId"); + this.root.push(new Attributes({ val: id })); } diff --git a/ts/docx/run/emphasis.ts b/ts/docx/run/emphasis.ts index f5478404e3..88338fa6ce 100644 --- a/ts/docx/run/emphasis.ts +++ b/ts/docx/run/emphasis.ts @@ -1,45 +1,30 @@ import {XmlComponent, Attributes} from "../xml-components"; -export class Bold implements XmlComponent { - private b: Array; - - xmlKeys = { - b: 'w:b' - } - +export class Bold extends XmlComponent { + constructor() { - this.b = new Array(); - this.b.push(new Attributes({ + super("w:b"); + this.root.push(new Attributes({ val: true })); } } -export class Italics { - private i: Array; - - xmlKeys = { - i: 'w:i' - } +export class Italics extends XmlComponent { constructor() { - this.i = new Array(); - this.i.push(new Attributes({ + super("w:i"); + this.root.push(new Attributes({ val: true })); } } -export class Underline { - private u: Array; - - xmlKeys = { - u: 'w:u' - } +export class Underline extends XmlComponent { constructor() { - this.u = new Array(); - this.u.push(new Attributes({ + super("w:u"); + this.root.push(new Attributes({ val: true })); } diff --git a/ts/docx/run/index.ts b/ts/docx/run/index.ts index 6080dbd483..21d94920df 100644 --- a/ts/docx/run/index.ts +++ b/ts/docx/run/index.ts @@ -2,18 +2,14 @@ import {XmlComponent, Attributes} from "../xml-components"; import {RunProperties} from "./properties"; import {Bold, Italics, Underline} from "./emphasis"; -export class Run implements XmlComponent { - protected r: Array; +export class Run extends XmlComponent { private properties: RunProperties; - xmlKeys = { - r: 'w:r' - } constructor() { - this.r = new Array(); + super("w:r"); this.properties = new RunProperties(); - this.r.push(this.properties); + this.root.push(this.properties); } bold(): Run { diff --git a/ts/docx/run/properties.ts b/ts/docx/run/properties.ts index 35567b81e4..1c65a2ba59 100644 --- a/ts/docx/run/properties.ts +++ b/ts/docx/run/properties.ts @@ -1,17 +1,12 @@ import {XmlComponent, Attributes} from "../xml-components"; -export class RunProperties implements XmlComponent { - private rPr: Array; - - xmlKeys = { - rPr: 'w:rPr' - } +export class RunProperties extends XmlComponent { constructor() { - this.rPr = new Array(); + super("w:rPr"); } push(item: XmlComponent): void { - this.rPr.push(item); + this.root.push(item); } } diff --git a/ts/docx/run/text-run.ts b/ts/docx/run/text-run.ts index 2b46a802f6..e179f33874 100644 --- a/ts/docx/run/text-run.ts +++ b/ts/docx/run/text-run.ts @@ -5,6 +5,6 @@ export class TextRun extends Run { constructor(text: string) { super(); - this.r.push(new Text(text)); + this.root.push(new Text(text)); } } \ No newline at end of file diff --git a/ts/docx/tab-stop.ts b/ts/docx/tab-stop.ts index d258672621..9c2e9f55c8 100644 --- a/ts/docx/tab-stop.ts +++ b/ts/docx/tab-stop.ts @@ -1,5 +1,5 @@ import {XmlComponent, Attributes} from "./xml-components"; -export class TabStop implements XmlComponent{ +export class TabStop extends XmlComponent{ xmlKeys = {} } diff --git a/ts/docx/xml-components/base-attributes.ts b/ts/docx/xml-components/base-attributes.ts index 7a7615fea3..172a6fcb69 100644 --- a/ts/docx/xml-components/base-attributes.ts +++ b/ts/docx/xml-components/base-attributes.ts @@ -1,11 +1,12 @@ import {XmlComponent} from "./"; -export abstract class BaseAttributes implements XmlComponent { +export abstract class BaseAttributes extends XmlComponent { private _attr: Object; xmlKeys = {}; constructor(xmlKeys: Object, properties?: any) { + super("_attr"); this._attr = properties if (!properties) { diff --git a/ts/docx/xml-components/document-attributes.ts b/ts/docx/xml-components/document-attributes.ts index b10a05749a..40603ed8d8 100644 --- a/ts/docx/xml-components/document-attributes.ts +++ b/ts/docx/xml-components/document-attributes.ts @@ -26,7 +26,7 @@ interface DocumentAttributesProperties { type?: string; } -export class DocumentAttributes implements XmlComponent { +export class DocumentAttributes extends XmlComponent { private _attr: Object; xmlKeys = { @@ -56,6 +56,7 @@ export class DocumentAttributes implements XmlComponent { }; constructor(properties?: DocumentAttributesProperties) { + super("_attr"); this._attr = properties if (!properties) { diff --git a/ts/docx/xml-components/index.ts b/ts/docx/xml-components/index.ts index b76235c6a0..b31ed77147 100644 --- a/ts/docx/xml-components/index.ts +++ b/ts/docx/xml-components/index.ts @@ -1,5 +1,11 @@ -export interface XmlComponent { - xmlKeys: Object; +export abstract class XmlComponent { + protected root: Array; + protected rootKey: string; + + constructor(rootKey: string) { + this.root = new Array(); + this.rootKey = rootKey; + } } interface AttributesProperties { @@ -23,7 +29,7 @@ interface AttributesProperties { linePitch?: string; } -export class Attributes implements XmlComponent { +export class Attributes extends XmlComponent { private _attr: Object; xmlKeys = { @@ -48,6 +54,7 @@ export class Attributes implements XmlComponent { }; constructor(properties?: AttributesProperties) { + super("_attr"); this._attr = properties if (!properties) { @@ -58,7 +65,7 @@ export class Attributes implements XmlComponent { } } -export class Text implements XmlComponent { +export class Text extends XmlComponent { private t: string; xmlKeys = { @@ -66,6 +73,7 @@ export class Text implements XmlComponent { } constructor(text: string) { + super("w:t"); this.t = text; } } \ No newline at end of file diff --git a/ts/properties/components.ts b/ts/properties/components.ts index 5ab5ab6654..1aebf5c3ab 100644 --- a/ts/properties/components.ts +++ b/ts/properties/components.ts @@ -1,114 +1,74 @@ import {XmlComponent} from "../docx/xml-components"; import {DocumentAttributes} from "../docx/xml-components/document-attributes"; -abstract class Component { - protected createNullBlockOrValue(value: string): Object { - if (value === undefined) { +abstract class Component extends XmlComponent { + protected createNullBlockOrValue(value: string): XmlComponent { + /*if (value === undefined) { return [{}]; } else { return value; - } + }*/ + return null; } } -export class Title extends Component implements XmlComponent { - private title: Object; - - xmlKeys = { - title: "dc:title" - } +export class Title extends Component { constructor(value: string) { - super(); - var title = this.createNullBlockOrValue(value); - this.title = title; + super("dc:title"); + this.root.push(this.createNullBlockOrValue(value)); } } -export class Subject extends Component implements XmlComponent { - private subject: Object; - - xmlKeys = { - subject: "dc:subject" - } +export class Subject extends Component { constructor(value: string) { - super(); - var subject = this.createNullBlockOrValue(value); - this.subject = subject; + super("dc:subject"); + this.root.push(this.createNullBlockOrValue(value)); } } -export class Creator extends Component implements XmlComponent { - private creator: Object; - - xmlKeys = { - creator: "dc:creator" - } +export class Creator extends Component { constructor(value: string) { - super(); - var creator = this.createNullBlockOrValue(value); - this.creator = creator; + super("dc:creator"); + this.root.push(this.createNullBlockOrValue(value)); } } -export class Keywords extends Component implements XmlComponent { - private keywords: Object; - - xmlKeys = { - keywords: "cp:keywords" - } +export class Keywords extends Component { constructor(value: string) { - super(); - var keywords = this.createNullBlockOrValue(value); - this.keywords = keywords; + super("cp:keywords"); + this.root.push(this.createNullBlockOrValue(value)); } } -export class Description extends Component implements XmlComponent { - private description: Object; - - xmlKeys = { - description: "dc:description" - } +export class Description extends Component { constructor(value: string) { - super(); - var description = this.createNullBlockOrValue(value); - this.description = description; + super("dc:description"); + this.root.push(this.createNullBlockOrValue(value)); } } -export class LastModifiedBy extends Component implements XmlComponent { - private lastModifiedBy: Object; - - xmlKeys = { - lastModifiedBy: "cp:lastModifiedBy" - } - +export class LastModifiedBy extends Component { + constructor(value: string) { - super(); - var lastModifiedBy = this.createNullBlockOrValue(value); - this.lastModifiedBy = lastModifiedBy; + super("cp:lastModifiedBy"); + this.root.push(this.createNullBlockOrValue(value)); } } -export class Revision extends Component implements XmlComponent { - private revision: Object; - - xmlKeys = { - revision: "cp:revision" - } +export class Revision extends Component { constructor(value: string) { - super(); + super("cp:revision"); var revision = this.createNullBlockOrValue(value); - this.revision = revision; + this.root.push(this.createNullBlockOrValue(value)); } } -abstract class DateComponent { +abstract class DateComponent extends XmlComponent { protected getCurrentDate(): any { var date = new Date(), year = date.getFullYear(), @@ -122,36 +82,24 @@ abstract class DateComponent { } } -export class Created extends DateComponent implements XmlComponent { - private created: Array; - - xmlKeys = { - created: "dcterms:created" - } +export class Created extends DateComponent { constructor() { - super(); - this.created = new Array(); - this.created.push(new DocumentAttributes({ + super("dcterms:created"); + this.root.push(new DocumentAttributes({ type: "dcterms:W3CDTF" })); - this.created.push(this.getCurrentDate()); + this.root.push(this.getCurrentDate()); } } export class Modified extends DateComponent implements XmlComponent { - private modified: Array; - - xmlKeys = { - modified: "dcterms:modified" - } constructor() { - super(); - this.modified = new Array(); - this.modified.push(new DocumentAttributes({ + super("dcterms:modified"); + this.root.push(new DocumentAttributes({ type: "dcterms:W3CDTF" })); - this.modified.push(this.getCurrentDate()); + this.root.push(this.getCurrentDate()); } } \ No newline at end of file diff --git a/ts/properties/index.ts b/ts/properties/index.ts index 251b83404e..e637c028a3 100644 --- a/ts/properties/index.ts +++ b/ts/properties/index.ts @@ -12,30 +12,25 @@ interface PropertiesOptions { revision?: string; } -export class Properties implements XmlComponent { - private coreProperties: Array; - - xmlKeys = { - coreProperties: "cp:coreProperties" - } +export class Properties extends XmlComponent { constructor(options: PropertiesOptions) { - this.coreProperties = new Array(); - this.coreProperties.push(new DocumentAttributes({ + super("cp:coreProperties"); + this.root.push(new DocumentAttributes({ cp: "http://schemas.openxmlformats.org/package/2006/metadata/core-properties", dc: "http://purl.org/dc/elements/1.1/", dcterms: "http://purl.org/dc/terms/", dcmitype: "http://purl.org/dc/dcmitype/", xsi: "http://www.w3.org/2001/XMLSchema-instance" })); - this.coreProperties.push(new Title(options.title)); - this.coreProperties.push(new Subject(options.subject)); - this.coreProperties.push(new Creator(options.creator)); - this.coreProperties.push(new Keywords(options.keywords)); - this.coreProperties.push(new Description(options.description)); - this.coreProperties.push(new LastModifiedBy(options.lastModifiedBy)); - this.coreProperties.push(new Revision(options.revision)); - this.coreProperties.push(new Created()); - this.coreProperties.push(new Modified()); + this.root.push(new Title(options.title)); + this.root.push(new Subject(options.subject)); + this.root.push(new Creator(options.creator)); + this.root.push(new Keywords(options.keywords)); + this.root.push(new Description(options.description)); + this.root.push(new LastModifiedBy(options.lastModifiedBy)); + this.root.push(new Revision(options.revision)); + this.root.push(new Created()); + this.root.push(new Modified()); } } \ No newline at end of file diff --git a/ts/styles/defaults/index.ts b/ts/styles/defaults/index.ts index 77204a8bde..be03e40908 100644 --- a/ts/styles/defaults/index.ts +++ b/ts/styles/defaults/index.ts @@ -2,16 +2,11 @@ import {XmlComponent} from "../../docx/xml-components"; import {ParagraphPropertiesDefaults} from "./paragraph-properties"; import {RunPropertiesDefaults} from "./run-properties"; -export class DocumentDefaults implements XmlComponent { - private docDefaults: Array; - - xmlKeys = { - docDefaults: "w:docDefaults" - } +export class DocumentDefaults extends XmlComponent { constructor() { - this.docDefaults = new Array(); - this.docDefaults.push(new RunPropertiesDefaults()); - this.docDefaults.push(new ParagraphPropertiesDefaults()); + super("w:docDefaults"); + this.root.push(new RunPropertiesDefaults()); + this.root.push(new ParagraphPropertiesDefaults()); } } \ No newline at end of file diff --git a/ts/styles/defaults/paragraph-properties.ts b/ts/styles/defaults/paragraph-properties.ts index 0e3b031e0b..43d1d4c4cf 100644 --- a/ts/styles/defaults/paragraph-properties.ts +++ b/ts/styles/defaults/paragraph-properties.ts @@ -1,15 +1,10 @@ import {XmlComponent} from "../../docx/xml-components"; import {ParagraphProperties} from "../../docx/paragraph/properties"; -export class ParagraphPropertiesDefaults implements XmlComponent { - private pPrDefault: Array; - - xmlKeys = { - pPrDefault: "w:pPrDefault" - } +export class ParagraphPropertiesDefaults extends XmlComponent { constructor() { - this.pPrDefault = new Array(); - this.pPrDefault.push(new ParagraphProperties()); + super("w:pPrDefault"); + this.root.push(new ParagraphProperties()); } } \ No newline at end of file diff --git a/ts/styles/defaults/run-properties.ts b/ts/styles/defaults/run-properties.ts index eb22772fcf..7b76728083 100644 --- a/ts/styles/defaults/run-properties.ts +++ b/ts/styles/defaults/run-properties.ts @@ -1,15 +1,10 @@ import {XmlComponent} from "../../docx/xml-components"; import {RunProperties} from "../../docx/run/properties"; -export class RunPropertiesDefaults implements XmlComponent { - private rPrDefault: Array; - - xmlKeys = { - rPrDefault: "w:rPrDefault" - } - +export class RunPropertiesDefaults extends XmlComponent { + constructor() { - this.rPrDefault = new Array(); - this.rPrDefault.push(new RunProperties()); + super("w:rPrDefault"); + this.root.push(new RunProperties()); } } \ No newline at end of file diff --git a/ts/styles/index.ts b/ts/styles/index.ts index f54231f7c5..704d68cb5c 100644 --- a/ts/styles/index.ts +++ b/ts/styles/index.ts @@ -5,16 +5,11 @@ import {LatentStyles} from "./latent-styles"; import {LatentStyleException} from "./latent-styles/exceptions"; import {LatentStyleExceptionAttributes} from "./latent-styles/exceptions/attributes"; -export class Styles implements XmlComponent { - private styles: Array; - - xmlKeys = { - styles: 'w:styles' - } +export class Styles extends XmlComponent { constructor() { - this.styles = new Array(); - this.styles.push(new DocumentAttributes({ + super("w:styles"); + this.root.push(new DocumentAttributes({ mc: 'http://schemas.openxmlformats.org/markup-compatibility/2006', r: 'http://schemas.openxmlformats.org/officeDocument/2006/relationships', w: 'http://schemas.openxmlformats.org/wordprocessingml/2006/main', @@ -22,15 +17,15 @@ export class Styles implements XmlComponent { w15: 'http://schemas.microsoft.com/office/word/2012/wordml', Ignorable: 'w14 w15' })) - this.styles.push(new DocumentDefaults()); + this.root.push(new DocumentDefaults()); var latentStyles = new LatentStyles(); //latentStyles.push(new LatentStyleException(new LatentStyleExceptionAttributes({ // name: "Normal" //}))); - this.styles.push(latentStyles); + this.root.push(latentStyles); } push(style: XmlComponent): void { - this.styles.push(style); + this.root.push(style); } } \ No newline at end of file diff --git a/ts/styles/latent-styles/exceptions/attributes.ts b/ts/styles/latent-styles/exceptions/attributes.ts index 31c4aa1d35..72e3862934 100644 --- a/ts/styles/latent-styles/exceptions/attributes.ts +++ b/ts/styles/latent-styles/exceptions/attributes.ts @@ -8,7 +8,7 @@ interface LatentStyleExceptionAttributesProperties { unhideWhenUsed?: string } -export class LatentStyleExceptionAttributes implements XmlComponent { +export class LatentStyleExceptionAttributes extends XmlComponent { private _attr: Object; xmlKeys = { @@ -20,6 +20,7 @@ export class LatentStyleExceptionAttributes implements XmlComponent { }; constructor(properties?: LatentStyleExceptionAttributesProperties) { + super("_attr"); this._attr = properties if (!properties) { diff --git a/ts/styles/latent-styles/exceptions/index.ts b/ts/styles/latent-styles/exceptions/index.ts index c52cd0ceca..685440b3ee 100644 --- a/ts/styles/latent-styles/exceptions/index.ts +++ b/ts/styles/latent-styles/exceptions/index.ts @@ -1,15 +1,10 @@ import {XmlComponent} from "../../../docx/xml-components"; import {LatentStyleExceptionAttributes} from "./attributes"; -export class LatentStyleException implements XmlComponent { - private lsdException: Array; - - xmlKeys = { - lsdException: "w:lsdException" - } +export class LatentStyleException extends XmlComponent { constructor(attributes: LatentStyleExceptionAttributes) { - this.lsdException = new Array(); - this.lsdException.push(attributes); + super("w:lsdException"); + this.root.push(attributes); } } \ No newline at end of file diff --git a/ts/styles/latent-styles/index.ts b/ts/styles/latent-styles/index.ts index 47ad8db6ba..f6b5c9f617 100644 --- a/ts/styles/latent-styles/index.ts +++ b/ts/styles/latent-styles/index.ts @@ -1,18 +1,13 @@ import {XmlComponent} from "../../docx/xml-components"; import {LatentStyleException} from "./exceptions"; -export class LatentStyles implements XmlComponent { - private latentStyles: Array; - - xmlKeys = { - latentStyles: "w:latentStyles" - } +export class LatentStyles extends XmlComponent { constructor() { - this.latentStyles = new Array(); + super("w:latentStyles"); } push(latentException: LatentStyleException): void { - this.latentStyles.push(latentException); + this.root.push(latentException); } } \ No newline at end of file diff --git a/ts/styles/style/attributes.ts b/ts/styles/style/attributes.ts index 32fd27baa5..85f0f23195 100644 --- a/ts/styles/style/attributes.ts +++ b/ts/styles/style/attributes.ts @@ -7,7 +7,7 @@ interface StyleAttributesProperties { customStyle?: string; } -export class StyleAttributes implements XmlComponent { +export class StyleAttributes extends XmlComponent { private _attr: Object; xmlKeys = { @@ -18,6 +18,7 @@ export class StyleAttributes implements XmlComponent { }; constructor(properties?: StyleAttributesProperties) { + super("_attr"); this._attr = properties if (!properties) { diff --git a/ts/styles/style/components.ts b/ts/styles/style/components.ts index 164a31ee15..4440e38750 100644 --- a/ts/styles/style/components.ts +++ b/ts/styles/style/components.ts @@ -1,14 +1,9 @@ import {XmlComponent} from "../../docx/xml-components"; -export class Name implements XmlComponent { - private name: Array; - - xmlKeys = { - - } +export class Name extends XmlComponent { constructor() { - this.name = new Array(); + super("w:name"); } } diff --git a/ts/styles/style/index.ts b/ts/styles/style/index.ts index b212311584..6a2f6687d8 100644 --- a/ts/styles/style/index.ts +++ b/ts/styles/style/index.ts @@ -1,19 +1,14 @@ import {XmlComponent} from "../../docx/xml-components"; import {StyleAttributes} from "./attributes"; -export class Style implements XmlComponent { - private style: Array; - - xmlKeys = { - style: "w:style" - } +export class Style extends XmlComponent { constructor(attributes: StyleAttributes) { - this.style = new Array(); - this.style.push(attributes); + super("w:style"); + this.root.push(attributes); } push(styleSegment: XmlComponent): void { - this.style.push(styleSegment); + this.root.push(styleSegment); } } \ No newline at end of file