diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ef01fc..c62073d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,7 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## docx-wasm@0.0.226 (17. January, 2022) +## docx-wasm@0.0.226, 0.0.227 (17. January, 2022) - Add `paragraphPropertyChange` api for JS. diff --git a/docx-wasm/js/index.ts b/docx-wasm/js/index.ts index 0bbe33a..9f4dd9a 100644 --- a/docx-wasm/js/index.ts +++ b/docx-wasm/js/index.ts @@ -620,6 +620,7 @@ export class Docx { p.property.paragraphPropertyChange._property.numbering.level ); } + // TODO: add style, indent, alignment paragraph = paragraph.paragraph_property_change(change); } diff --git a/docx-wasm/js/paragraph-property.ts b/docx-wasm/js/paragraph-property.ts index cdbd680..910f1f2 100644 --- a/docx-wasm/js/paragraph-property.ts +++ b/docx-wasm/js/paragraph-property.ts @@ -93,8 +93,27 @@ export class ParagraphPropertyChange { return this; } - property(p: ParagraphProperty) { - this._property = p; + align(type: AlignmentType) { + this._property.align = type; + return this; + } + + style(id: string) { + this._property.styleId = id; + return this; + } + + indent( + left: number, + specialIndentKind?: SpecialIndentKind, + specialIndentSize?: number + ) { + this._property.indent = { left, specialIndentKind, specialIndentSize }; + return this; + } + + numbering(id: number, level: number) { + this._property.numbering = { id, level }; return this; } } diff --git a/docx-wasm/package.json b/docx-wasm/package.json index 0bef168..abab6d2 100644 --- a/docx-wasm/package.json +++ b/docx-wasm/package.json @@ -1,6 +1,6 @@ { "name": "docx-wasm", - "version": "0.0.226", + "version": "0.0.227", "main": "dist/node/index.js", "browser": "dist/web/index.js", "author": "bokuweb ", diff --git a/docx-wasm/src/paragraph.rs b/docx-wasm/src/paragraph.rs index fdb0d3f..127df7a 100644 --- a/docx-wasm/src/paragraph.rs +++ b/docx-wasm/src/paragraph.rs @@ -28,6 +28,31 @@ impl ParagraphPropertyChange { self.0.property = Box::new(self.0.property.numbering(id, level)); self } + + pub fn align(mut self, alignment_type: docx_rs::AlignmentType) -> Self { + self.0.property = Box::new(self.0.property.align(alignment_type)); + self + } + + pub fn style(mut self, style_id: &str) -> Self { + self.0.property = Box::new(self.0.property.style(style_id)); + self + } + + pub fn indent( + mut self, + left: i32, + special_indent_kind: Option, + special_indent_size: Option, + ) -> Self { + let special_indent = create_special_indent(special_indent_kind, special_indent_size); + self.0.property = Box::new( + self.0 + .property + .indent(Some(left), special_indent, None, None), + ); + self + } } impl ParagraphPropertyChange { diff --git a/docx-wasm/test/__snapshots__/index.test.js.snap b/docx-wasm/test/__snapshots__/index.test.js.snap index 7413f1b..3f17ace 100644 --- a/docx-wasm/test/__snapshots__/index.test.js.snap +++ b/docx-wasm/test/__snapshots__/index.test.js.snap @@ -22583,6 +22583,32 @@ exports[`writer should write nested table 3`] = ` " `; +exports[`writer should write pPrChange with deleted numbering 1`] = ` +" + + + + + +" +`; + +exports[`writer should write pPrChange with deleted numbering 2`] = ` +" + + Hello world!! +" +`; + +exports[`writer should write pPrChange with deleted numbering 3`] = ` +" + + + + +" +`; + exports[`writer should write pPrChange with inserted numbering 1`] = ` " diff --git a/docx-wasm/test/index.test.js b/docx-wasm/test/index.test.js index df2a388..8ac3f0f 100644 --- a/docx-wasm/test/index.test.js +++ b/docx-wasm/test/index.test.js @@ -620,4 +620,27 @@ describe("writer", () => { } } }); + + test("should write pPrChange with deleted numbering", () => { + const p = new w.Paragraph() + .addRun(new w.Run().addText("Hello world!!")) + .paragraphPropertyChange( + new w.ParagraphPropertyChange().author("bokuweb").numbering(1, 0) + ); + + const num = new w.Numbering(1, 0); + const buffer = new w.Docx().addParagraph(p).addNumbering(num).build(); + + writeFileSync( + "../output/js/pprchange_with_deleted_numbering.docx", + buffer + ); + + const z = new Zip(Buffer.from(buffer)); + for (const e of z.getEntries()) { + if (e.entryName.match(/document.xml|numbering.xml/)) { + expect(z.readAsText(e)).toMatchSnapshot(); + } + } + }); });