From 8b169c632c6d7cfb050273f42662d636b7a9034c Mon Sep 17 00:00:00 2001 From: bokuweb Date: Fri, 4 Feb 2022 18:37:04 +0900 Subject: [PATCH] Support table row ins (#431) * fix: support table row ins * 0.0.242 --- CHANGELOG.md | 4 ++++ docx-core/src/documents/elements/table_row.rs | 7 ++++++- .../src/documents/elements/table_row_property.rs | 11 ++++++++++- docx-core/src/reader/table_row.rs | 10 ++++++++++ docx-wasm/js/index.ts | 4 ++++ docx-wasm/js/json/table.ts | 3 ++- docx-wasm/js/table-row.ts | 6 ++++++ docx-wasm/package.json | 2 +- docx-wasm/src/table_row.rs | 7 +++++++ 9 files changed, 50 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c371002..64afbd5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ 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.242 (4. February, 2022) + +- Support `ins` in table row property + ## docx-wasm@0.0.235 (25. January, 2022) - Support `del` in table row property diff --git a/docx-core/src/documents/elements/table_row.rs b/docx-core/src/documents/elements/table_row.rs index 0d85304..67dbedf 100644 --- a/docx-core/src/documents/elements/table_row.rs +++ b/docx-core/src/documents/elements/table_row.rs @@ -1,7 +1,7 @@ use serde::ser::{SerializeStruct, Serializer}; use serde::Serialize; -use super::{TableCell, TableRowProperty, Delete}; +use super::{Delete, Insert, TableCell, TableRowProperty}; use crate::xml_builder::*; use crate::{documents::BuildXML, HeightRule}; @@ -72,6 +72,11 @@ impl TableRow { self.property = self.property.delete(d); self } + + pub fn insert(mut self, i: Insert) -> TableRow { + self.property = self.property.insert(i); + self + } } impl BuildXML for TableRow { diff --git a/docx-core/src/documents/elements/table_row_property.rs b/docx-core/src/documents/elements/table_row_property.rs index 3bd880d..e43f055 100644 --- a/docx-core/src/documents/elements/table_row_property.rs +++ b/docx-core/src/documents/elements/table_row_property.rs @@ -15,6 +15,8 @@ pub struct TableRowProperty { height_rule: Option, #[serde(skip_serializing_if = "Option::is_none")] pub del: Option, + #[serde(skip_serializing_if = "Option::is_none")] + pub ins: Option, } impl TableRowProperty { @@ -56,6 +58,11 @@ impl TableRowProperty { self.del = Some(d); self } + + pub fn insert(mut self, i: Insert) -> Self { + self.ins = Some(i); + self + } } impl Default for TableRowProperty { @@ -68,6 +75,7 @@ impl Default for TableRowProperty { row_height: None, height_rule: None, del: None, + ins: None, } } } @@ -76,7 +84,8 @@ impl BuildXML for TableRowProperty { fn build(&self) -> Vec { let mut b = XMLBuilder::new() .open_table_row_property() - .add_optional_child(&self.del); + .add_optional_child(&self.del) + .add_optional_child(&self.ins); if let Some(h) = self.row_height { b = b.table_row_height( &format!("{}", h), diff --git a/docx-core/src/reader/table_row.rs b/docx-core/src/reader/table_row.rs index 66bd93f..cc5a0a8 100644 --- a/docx-core/src/reader/table_row.rs +++ b/docx-core/src/reader/table_row.rs @@ -18,6 +18,7 @@ impl ElementReader for TableRow { let mut width_before = None; let mut row_height = None; let mut del = None; + let mut ins = None; let mut height_rule = Some(HeightRule::AtLeast); loop { let e = r.next(); @@ -74,6 +75,11 @@ impl ElementReader for TableRow { del = Some(d); } } + XMLElement::Insert => { + if let Ok(i) = Insert::read(r, &attributes) { + ins = Some(i); + } + } _ => {} } } @@ -109,6 +115,10 @@ impl ElementReader for TableRow { row = row.delete(del); } + if let Some(ins) = ins { + row = row.insert(ins); + } + return Ok(row); } } diff --git a/docx-wasm/js/index.ts b/docx-wasm/js/index.ts index dc0b382..bd4657f 100644 --- a/docx-wasm/js/index.ts +++ b/docx-wasm/js/index.ts @@ -658,6 +658,10 @@ export class Docx { row = row.delete(r.del.author, r.del.date); } + if (r.ins) { + row = row.insert(r.ins.author, r.ins.date); + } + if (r.hRule) { switch (r.hRule) { case "auto": { diff --git a/docx-wasm/js/json/table.ts b/docx-wasm/js/json/table.ts index 795affc..83a7683 100644 --- a/docx-wasm/js/json/table.ts +++ b/docx-wasm/js/json/table.ts @@ -4,7 +4,7 @@ import { HeightRule } from "../table-row"; import { TextDirectionType } from "../table-cell"; import { ShadingJSON } from "./shading"; import { TableLayoutType } from "../table"; -import { DeleteJSON } from ".."; +import { DeleteJSON, InsertJSON } from ".."; export type TableCellChildJSON = ParagraphJSON; @@ -35,6 +35,7 @@ export type TableRowPropertyJSON = { widthAfter: number | null; widthBefore: number | null; del?: DeleteJSON["data"]; + ins?: InsertJSON["data"]; }; export type TableCellJSON = { diff --git a/docx-wasm/js/table-row.ts b/docx-wasm/js/table-row.ts index 194093b..0ad8774 100644 --- a/docx-wasm/js/table-row.ts +++ b/docx-wasm/js/table-row.ts @@ -8,6 +8,7 @@ export class TableRow { height: number | null = null; hRule: HeightRule = "atLeast"; del: { author: string; date: string } | null = null; + ins: { author: string; date: string } | null = null; addCell(cell: TableCell) { if (cell.hasNumberings) { @@ -31,4 +32,9 @@ export class TableRow { this.del = { author, date }; return this; } + + insert(author: string, date: string) { + this.ins = { author, date }; + return this; + } } diff --git a/docx-wasm/package.json b/docx-wasm/package.json index 25a219b..28e0b25 100644 --- a/docx-wasm/package.json +++ b/docx-wasm/package.json @@ -1,6 +1,6 @@ { "name": "docx-wasm", - "version": "0.0.241", + "version": "0.0.242", "main": "dist/node/index.js", "browser": "dist/web/index.js", "author": "bokuweb ", diff --git a/docx-wasm/src/table_row.rs b/docx-wasm/src/table_row.rs index d14093e..dd1a2f6 100644 --- a/docx-wasm/src/table_row.rs +++ b/docx-wasm/src/table_row.rs @@ -41,4 +41,11 @@ impl TableRow { .delete(docx_rs::Delete::new().author(author).date(date)); self } + + pub fn insert(mut self, author: &str, date: &str) -> Self { + self.0 = self + .0 + .insert(docx_rs::Insert::new_with_empty().author(author).date(date)); + self + } }