Support table row ins (#431)

* fix: support table row ins

* 0.0.242
main
bokuweb 2022-02-04 18:37:04 +09:00 committed by GitHub
parent 4e55970831
commit 8b169c632c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 50 additions and 4 deletions

View File

@ -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/), 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). 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) ## docx-wasm@0.0.235 (25. January, 2022)
- Support `del` in table row property - Support `del` in table row property

View File

@ -1,7 +1,7 @@
use serde::ser::{SerializeStruct, Serializer}; use serde::ser::{SerializeStruct, Serializer};
use serde::Serialize; use serde::Serialize;
use super::{TableCell, TableRowProperty, Delete}; use super::{Delete, Insert, TableCell, TableRowProperty};
use crate::xml_builder::*; use crate::xml_builder::*;
use crate::{documents::BuildXML, HeightRule}; use crate::{documents::BuildXML, HeightRule};
@ -72,6 +72,11 @@ impl TableRow {
self.property = self.property.delete(d); self.property = self.property.delete(d);
self self
} }
pub fn insert(mut self, i: Insert) -> TableRow {
self.property = self.property.insert(i);
self
}
} }
impl BuildXML for TableRow { impl BuildXML for TableRow {

View File

@ -15,6 +15,8 @@ pub struct TableRowProperty {
height_rule: Option<HeightRule>, height_rule: Option<HeightRule>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub del: Option<Delete>, pub del: Option<Delete>,
#[serde(skip_serializing_if = "Option::is_none")]
pub ins: Option<Insert>,
} }
impl TableRowProperty { impl TableRowProperty {
@ -56,6 +58,11 @@ impl TableRowProperty {
self.del = Some(d); self.del = Some(d);
self self
} }
pub fn insert(mut self, i: Insert) -> Self {
self.ins = Some(i);
self
}
} }
impl Default for TableRowProperty { impl Default for TableRowProperty {
@ -68,6 +75,7 @@ impl Default for TableRowProperty {
row_height: None, row_height: None,
height_rule: None, height_rule: None,
del: None, del: None,
ins: None,
} }
} }
} }
@ -76,7 +84,8 @@ impl BuildXML for TableRowProperty {
fn build(&self) -> Vec<u8> { fn build(&self) -> Vec<u8> {
let mut b = XMLBuilder::new() let mut b = XMLBuilder::new()
.open_table_row_property() .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 { if let Some(h) = self.row_height {
b = b.table_row_height( b = b.table_row_height(
&format!("{}", h), &format!("{}", h),

View File

@ -18,6 +18,7 @@ impl ElementReader for TableRow {
let mut width_before = None; let mut width_before = None;
let mut row_height = None; let mut row_height = None;
let mut del = None; let mut del = None;
let mut ins = None;
let mut height_rule = Some(HeightRule::AtLeast); let mut height_rule = Some(HeightRule::AtLeast);
loop { loop {
let e = r.next(); let e = r.next();
@ -74,6 +75,11 @@ impl ElementReader for TableRow {
del = Some(d); 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); row = row.delete(del);
} }
if let Some(ins) = ins {
row = row.insert(ins);
}
return Ok(row); return Ok(row);
} }
} }

View File

@ -658,6 +658,10 @@ export class Docx {
row = row.delete(r.del.author, r.del.date); row = row.delete(r.del.author, r.del.date);
} }
if (r.ins) {
row = row.insert(r.ins.author, r.ins.date);
}
if (r.hRule) { if (r.hRule) {
switch (r.hRule) { switch (r.hRule) {
case "auto": { case "auto": {

View File

@ -4,7 +4,7 @@ import { HeightRule } from "../table-row";
import { TextDirectionType } from "../table-cell"; import { TextDirectionType } from "../table-cell";
import { ShadingJSON } from "./shading"; import { ShadingJSON } from "./shading";
import { TableLayoutType } from "../table"; import { TableLayoutType } from "../table";
import { DeleteJSON } from ".."; import { DeleteJSON, InsertJSON } from "..";
export type TableCellChildJSON = ParagraphJSON; export type TableCellChildJSON = ParagraphJSON;
@ -35,6 +35,7 @@ export type TableRowPropertyJSON = {
widthAfter: number | null; widthAfter: number | null;
widthBefore: number | null; widthBefore: number | null;
del?: DeleteJSON["data"]; del?: DeleteJSON["data"];
ins?: InsertJSON["data"];
}; };
export type TableCellJSON = { export type TableCellJSON = {

View File

@ -8,6 +8,7 @@ export class TableRow {
height: number | null = null; height: number | null = null;
hRule: HeightRule = "atLeast"; hRule: HeightRule = "atLeast";
del: { author: string; date: string } | null = null; del: { author: string; date: string } | null = null;
ins: { author: string; date: string } | null = null;
addCell(cell: TableCell) { addCell(cell: TableCell) {
if (cell.hasNumberings) { if (cell.hasNumberings) {
@ -31,4 +32,9 @@ export class TableRow {
this.del = { author, date }; this.del = { author, date };
return this; return this;
} }
insert(author: string, date: string) {
this.ins = { author, date };
return this;
}
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "docx-wasm", "name": "docx-wasm",
"version": "0.0.241", "version": "0.0.242",
"main": "dist/node/index.js", "main": "dist/node/index.js",
"browser": "dist/web/index.js", "browser": "dist/web/index.js",
"author": "bokuweb <bokuweb12@gmail.com>", "author": "bokuweb <bokuweb12@gmail.com>",

View File

@ -41,4 +41,11 @@ impl TableRow {
.delete(docx_rs::Delete::new().author(author).date(date)); .delete(docx_rs::Delete::new().author(author).date(date));
self 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
}
} }