diff --git a/ts/docx/xml-components/attributes.ts b/ts/docx/xml-components/attributes.ts new file mode 100644 index 0000000000..06e6aec788 --- /dev/null +++ b/ts/docx/xml-components/attributes.ts @@ -0,0 +1,49 @@ +import {XmlAttributeComponent} from "./default-attributes"; + +interface AttributesProperties { + val?: any; + color?: string; + space?: string; + sz?: string; + type?: string; + rsidR?: string; + rsidRPr?: string; + rsidSect?: string; + w?: string; + h?: string; + top?: string; + right?: string; + bottom?: string; + left?: string; + header?: string; + footer?: string; + gutter?: string; + linePitch?: string; + pos?: string; +} + +export class Attributes extends XmlAttributeComponent { + + constructor(properties?: AttributesProperties) { + super({ + val: "w:val", + color: "w:color", + space: "w:space", + sz: "w:sz", + type: "w:type", + rsidR: "w:rsidR", + rsidRPr: "w:rsidRPr", + rsidSect: "w:rsidSect", + w: "w:w", + h: "w:h", + top: "w:top", + right: "w:right", + bottom: "w:bottom", + left: "w:left", + header: "w:header", + footer: "w:footer", + gutter: "w:gutter", + linePitch: "w:linePitch" + }, properties); + } +} \ No newline at end of file diff --git a/ts/docx/xml-components/base.ts b/ts/docx/xml-components/base.ts new file mode 100644 index 0000000000..b9058f10ab --- /dev/null +++ b/ts/docx/xml-components/base.ts @@ -0,0 +1,11 @@ +export abstract class BaseXmlComponent { + protected rootKey: string; + + constructor(rootKey: string) { + this.rootKey = rootKey; + } + + abstract replaceKey(): void; + clearVariables(): void { + }; +} \ No newline at end of file diff --git a/ts/docx/xml-components/default-attributes.ts b/ts/docx/xml-components/default-attributes.ts new file mode 100644 index 0000000000..d7110f2ac9 --- /dev/null +++ b/ts/docx/xml-components/default-attributes.ts @@ -0,0 +1,29 @@ +import {BaseXmlComponent} from "./base"; + +export abstract class XmlAttributeComponent extends BaseXmlComponent { + protected root: Object; + private xmlKeys: Object; + + constructor(xmlKeys: Object, properties: Object) { + super("_attr"); + this.xmlKeys = xmlKeys; + + this.root = properties + + if (!properties) { + this.root = {}; + } + } + + replaceKey(): void { + if (this.root !== undefined) { + _.forOwn(this.root, (value, key) => { + var newKey = this.xmlKeys[key]; + this.root[newKey] = value; + delete this.root[key]; + }); + this[this.rootKey] = this.root; + delete this.root; + } + } +} \ No newline at end of file diff --git a/ts/docx/xml-components/index.ts b/ts/docx/xml-components/index.ts index 10578a0b6b..7a92cfb907 100644 --- a/ts/docx/xml-components/index.ts +++ b/ts/docx/xml-components/index.ts @@ -1,18 +1,6 @@ import * as _ from "lodash"; -import {ParagraphProperties} from "../paragraph/properties"; -import {RunProperties} from "../run/properties"; +import {BaseXmlComponent} from "./base"; -export abstract class BaseXmlComponent { - protected rootKey: string; - - constructor(rootKey: string) { - this.rootKey = rootKey; - } - - abstract replaceKey(): void; - clearVariables(): void { - }; -} export abstract class XmlComponent extends BaseXmlComponent { protected root: Array; @@ -37,147 +25,7 @@ export abstract class XmlComponent extends BaseXmlComponent { } } -export abstract class XmlUnitComponent extends BaseXmlComponent { - protected root: string; - - constructor(rootKey: string) { - super(rootKey); - } - - replaceKey(): void { - if (this.root !== undefined) { - this[this.rootKey] = this.root; - delete this.root; - } - } -} - -export abstract class XmlAttributeComponent extends BaseXmlComponent { - protected root: Object; - private xmlKeys: Object; - - constructor(xmlKeys: Object, properties: Object) { - super("_attr"); - this.xmlKeys = xmlKeys; - - this.root = properties - - if (!properties) { - this.root = {}; - } - } - - replaceKey(): void { - if (this.root !== undefined) { - _.forOwn(this.root, (value, key) => { - var newKey = this.xmlKeys[key]; - this.root[newKey] = value; - delete this.root[key]; - }); - this[this.rootKey] = this.root; - delete this.root; - } - } -} - -interface AttributesProperties { - val?: any; - color?: string; - space?: string; - sz?: string; - type?: string; - rsidR?: string; - rsidRPr?: string; - rsidSect?: string; - w?: string; - h?: string; - top?: string; - right?: string; - bottom?: string; - left?: string; - header?: string; - footer?: string; - gutter?: string; - linePitch?: string; - pos?: string; -} - -export class Attributes extends XmlAttributeComponent { - - constructor(properties?: AttributesProperties) { - super({ - val: "w:val", - color: "w:color", - space: "w:space", - sz: "w:sz", - type: "w:type", - rsidR: "w:rsidR", - rsidRPr: "w:rsidRPr", - rsidSect: "w:rsidSect", - w: "w:w", - h: "w:h", - top: "w:top", - right: "w:right", - bottom: "w:bottom", - left: "w:left", - header: "w:header", - footer: "w:footer", - gutter: "w:gutter", - linePitch: "w:linePitch" - }, properties); - } -} - -export class ParagraphPropertyXmlComponent extends XmlComponent { - private paragraphProperties: ParagraphProperties; - - constructor(rootKey) { - super(rootKey); - this.paragraphProperties = new ParagraphProperties(); - this.root.push(this.paragraphProperties); - } - - clearVariables(): void { - this.paragraphProperties.clearVariables(); - - delete this.paragraphProperties; - } -} - -export class RunPropertyXmlComponent extends XmlComponent { - private runProperties: RunProperties; - - constructor(rootKey) { - super(rootKey); - this.runProperties = new RunProperties(); - this.root.push(this.runProperties); - } - - clearVariables(): void { - this.runProperties.clearVariables(); - - delete this.runProperties; - } -} - -export class MultiPropertyXmlComponent extends XmlComponent { - private runProperties: RunProperties; - private paragraphProperties: ParagraphProperties; - - constructor(rootKey) { - super(rootKey); - this.runProperties = new RunProperties(); - this.root.push(this.runProperties); - - this.paragraphProperties = new ParagraphProperties(); - this.root.push(this.paragraphProperties); - } - - clearVariables(): void { - this.runProperties.clearVariables(); - this.paragraphProperties.clearVariables(); - - delete this.runProperties; - delete this.paragraphProperties; - } -} \ No newline at end of file +export * from "./attributes" +export * from "./default-attributes"; +export * from "./unit"; +export * from "./property"; \ No newline at end of file diff --git a/ts/docx/xml-components/property.ts b/ts/docx/xml-components/property.ts new file mode 100644 index 0000000000..fdb6087900 --- /dev/null +++ b/ts/docx/xml-components/property.ts @@ -0,0 +1,57 @@ +import {XmlComponent} from "./" +import {ParagraphProperties} from "../paragraph/properties"; +import {RunProperties} from "../run/properties"; + +export class ParagraphPropertyXmlComponent extends XmlComponent { + private paragraphProperties: ParagraphProperties; + + constructor(rootKey) { + super(rootKey); + this.paragraphProperties = new ParagraphProperties(); + this.root.push(this.paragraphProperties); + } + + clearVariables(): void { + this.paragraphProperties.clearVariables(); + + delete this.paragraphProperties; + } +} + +export class RunPropertyXmlComponent extends XmlComponent { + private runProperties: RunProperties; + + constructor(rootKey) { + super(rootKey); + this.runProperties = new RunProperties(); + this.root.push(this.runProperties); + } + + clearVariables(): void { + this.runProperties.clearVariables(); + + delete this.runProperties; + } +} + +export class MultiPropertyXmlComponent extends XmlComponent { + private runProperties: RunProperties; + private paragraphProperties: ParagraphProperties; + + constructor(rootKey) { + super(rootKey); + this.runProperties = new RunProperties(); + this.root.push(this.runProperties); + + this.paragraphProperties = new ParagraphProperties(); + this.root.push(this.paragraphProperties); + } + + clearVariables(): void { + this.runProperties.clearVariables(); + this.paragraphProperties.clearVariables(); + + delete this.runProperties; + delete this.paragraphProperties; + } +} \ No newline at end of file diff --git a/ts/docx/xml-components/unit.ts b/ts/docx/xml-components/unit.ts new file mode 100644 index 0000000000..e462fd4132 --- /dev/null +++ b/ts/docx/xml-components/unit.ts @@ -0,0 +1,16 @@ +import {BaseXmlComponent} from "./base"; + +export abstract class XmlUnitComponent extends BaseXmlComponent { + protected root: string; + + constructor(rootKey: string) { + super(rootKey); + } + + replaceKey(): void { + if (this.root !== undefined) { + this[this.rootKey] = this.root; + delete this.root; + } + } +} \ No newline at end of file