From 74fbc715e9e41be0c191e4a4edcb820d07a142e5 Mon Sep 17 00:00:00 2001 From: Dolan Miu Date: Thu, 2 Dec 2021 17:24:19 +0000 Subject: [PATCH 1/6] #1324 Fixes Bi-directional re-factor issue --- src/file/paragraph/properties.spec.ts | 26 ++++++++++++++++++++++++++ src/file/paragraph/properties.ts | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/file/paragraph/properties.spec.ts b/src/file/paragraph/properties.spec.ts index e8961ceea6..8779b49e4c 100644 --- a/src/file/paragraph/properties.spec.ts +++ b/src/file/paragraph/properties.spec.ts @@ -91,5 +91,31 @@ describe("ParagraphProperties", () => { ], }); }); + + it("should create with bidirectional", () => { + const properties = new ParagraphProperties({ + bidirectional: true, + }); + const tree = new Formatter().format(properties, { + // tslint:disable-next-line: no-object-literal-type-assertion + file: { + Numbering: { + createConcreteNumberingInstance: (_: string, __: number) => { + return; + }, + }, + } as File, + // tslint:disable-next-line: no-object-literal-type-assertion + viewWrapper: new DocumentWrapper({ background: {} }), + }); + + expect(tree).to.deep.equal({ + "w:pPr": [ + { + "w:bidi": {}, + }, + ], + }); + }); }); }); diff --git a/src/file/paragraph/properties.ts b/src/file/paragraph/properties.ts index 8b09819233..fd1e18c826 100644 --- a/src/file/paragraph/properties.ts +++ b/src/file/paragraph/properties.ts @@ -146,7 +146,7 @@ export class ParagraphProperties extends IgnoreIfEmptyXmlComponent { } if (options.bidirectional !== undefined) { - this.push(new OnOffElement("w:bidi", options.contextualSpacing)); + this.push(new OnOffElement("w:bidi", options.bidirectional)); } if (options.spacing) { From 5ad7fd8a15cac50eae6836a6249742d2da60440a Mon Sep 17 00:00:00 2001 From: Dolan Miu Date: Thu, 2 Dec 2021 17:27:00 +0000 Subject: [PATCH 2/6] Add more tests --- src/file/paragraph/properties.spec.ts | 58 +++++++++++++++------------ 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/src/file/paragraph/properties.spec.ts b/src/file/paragraph/properties.spec.ts index 8779b49e4c..dbf2021e8a 100644 --- a/src/file/paragraph/properties.spec.ts +++ b/src/file/paragraph/properties.spec.ts @@ -70,18 +70,7 @@ describe("ParagraphProperties", () => { const properties = new ParagraphProperties({ widowControl: true, }); - const tree = new Formatter().format(properties, { - // tslint:disable-next-line: no-object-literal-type-assertion - file: { - Numbering: { - createConcreteNumberingInstance: (_: string, __: number) => { - return; - }, - }, - } as File, - // tslint:disable-next-line: no-object-literal-type-assertion - viewWrapper: new DocumentWrapper({ background: {} }), - }); + const tree = new Formatter().format(properties); expect(tree).to.deep.equal({ "w:pPr": [ @@ -92,22 +81,11 @@ describe("ParagraphProperties", () => { }); }); - it("should create with bidirectional", () => { + it("should create with the bidirectional property", () => { const properties = new ParagraphProperties({ bidirectional: true, }); - const tree = new Formatter().format(properties, { - // tslint:disable-next-line: no-object-literal-type-assertion - file: { - Numbering: { - createConcreteNumberingInstance: (_: string, __: number) => { - return; - }, - }, - } as File, - // tslint:disable-next-line: no-object-literal-type-assertion - viewWrapper: new DocumentWrapper({ background: {} }), - }); + const tree = new Formatter().format(properties); expect(tree).to.deep.equal({ "w:pPr": [ @@ -117,5 +95,35 @@ describe("ParagraphProperties", () => { ], }); }); + + it("should create with the contextualSpacing property", () => { + const properties = new ParagraphProperties({ + contextualSpacing: true, + }); + const tree = new Formatter().format(properties); + + expect(tree).to.deep.equal({ + "w:pPr": [ + { + "w:contextualSpacing": {}, + }, + ], + }); + }); + + it("should create with the suppressLineNumbers property", () => { + const properties = new ParagraphProperties({ + suppressLineNumbers: true, + }); + const tree = new Formatter().format(properties); + + expect(tree).to.deep.equal({ + "w:pPr": [ + { + "w:suppressLineNumbers": {}, + }, + ], + }); + }); }); }); From d808b287a71648a1b39f27e159ad9e245845359a Mon Sep 17 00:00:00 2001 From: Dolan Miu Date: Thu, 2 Dec 2021 17:37:27 +0000 Subject: [PATCH 3/6] Simplify code --- src/export/packer/next-compiler.ts | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/export/packer/next-compiler.ts b/src/export/packer/next-compiler.ts index 24cf9d3186..2afe0fde98 100644 --- a/src/export/packer/next-compiler.ts +++ b/src/export/packer/next-compiler.ts @@ -44,14 +44,9 @@ export class Compiler { public compile(file: File, prettifyXml?: boolean): JSZip { const zip = new JSZip(); const xmlifiedFileMapping = this.xmlifyFile(file, prettifyXml); + const map = new Map(Object.entries(xmlifiedFileMapping)); - for (const key in xmlifiedFileMapping) { - if (!xmlifiedFileMapping[key]) { - continue; - } - - const obj = xmlifiedFileMapping[key] as IXmlifyedFile | IXmlifyedFile[]; - + for (const [, obj] of map) { if (Array.isArray(obj)) { for (const subFile of obj) { zip.file(subFile.path, subFile.data); From 5289ea8e1c848b94997676c16d93292ea861dc19 Mon Sep 17 00:00:00 2001 From: Dolan Miu Date: Thu, 2 Dec 2021 18:06:22 +0000 Subject: [PATCH 4/6] Re-order statements to be more friendly --- .nycrc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.nycrc b/.nycrc index 3b51f5a7bf..785b724a8c 100644 --- a/.nycrc +++ b/.nycrc @@ -1,9 +1,9 @@ { "check-coverage": true, - "lines": 99.32, - "functions": 99.11, - "branches": 96.27, "statements": 99.32, + "branches": 96.27, + "functions": 99.11, + "lines": 99.32, "include": [ "src/**/*.ts" ], From e50a6edbedb2e870873869a305fa1e29d8c22f92 Mon Sep 17 00:00:00 2001 From: Dolan Miu Date: Fri, 3 Dec 2021 02:23:03 +0000 Subject: [PATCH 5/6] Disable demo 19 --- .github/workflows/demos.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/demos.yml b/.github/workflows/demos.yml index c0f0330b04..319081e5de 100644 --- a/.github/workflows/demos.yml +++ b/.github/workflows/demos.yml @@ -204,11 +204,12 @@ jobs: run: npm run ts-node -- ./demo/19-export-to-base64.ts - name: Extract Word Document run: npm run extract - - name: Validate XML - uses: ChristophWurst/xmllint-action@v1 - with: - xml-file: build/extracted-doc/word/document.xml - xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd + # Base 64 No longer works, abruptly. Node issue? + # - name: Validate XML + # uses: ChristophWurst/xmllint-action@v1 + # with: + # xml-file: build/extracted-doc/word/document.xml + # xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd - name: Run Demo run: npm run ts-node -- ./demo/20-table-cell-borders.ts - name: Extract Word Document From 3a022c4d2a62bc669e817fa615aca48d1a38f4c5 Mon Sep 17 00:00:00 2001 From: Dolan Miu Date: Fri, 3 Dec 2021 03:34:17 +0000 Subject: [PATCH 6/6] Remove extraction --- .github/workflows/demos.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/demos.yml b/.github/workflows/demos.yml index 319081e5de..f2a2ec6ade 100644 --- a/.github/workflows/demos.yml +++ b/.github/workflows/demos.yml @@ -202,9 +202,9 @@ jobs: xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd - name: Run Demo run: npm run ts-node -- ./demo/19-export-to-base64.ts - - name: Extract Word Document - run: npm run extract # Base 64 No longer works, abruptly. Node issue? + # - name: Extract Word Document + # run: npm run extract # - name: Validate XML # uses: ChristophWurst/xmllint-action@v1 # with: