fix (#496)
* fix * fix * fix * fix * fix * fix * 0.0.271 * fix * 0.0.272 Co-authored-by: bokuweb <bokuweb@bokuwebnombp.lan>main
parent
604bdb85f7
commit
f08cefff0a
15
CHANGELOG.md
15
CHANGELOG.md
|
@ -5,7 +5,20 @@ 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.262 (7. Jun, 2022)
|
## docx-wasm@0.0.271, @0.0.272 (15. Jun, 2022)
|
||||||
|
|
||||||
|
- [Breaking] Remove default `TableCellMargin`. Please specify if needed.
|
||||||
|
- Support table cell margins reader.
|
||||||
|
|
||||||
|
## docx-wasm@0.0.269, @0.0.270 (14. Jun, 2022)
|
||||||
|
|
||||||
|
- Support nested table reader.
|
||||||
|
|
||||||
|
## docx-wasm@0.0.268 (13. Jun, 2022)
|
||||||
|
|
||||||
|
- Add png image converter
|
||||||
|
|
||||||
|
## docx-wasm@0.0.264 (7. Jun, 2022)
|
||||||
|
|
||||||
- Add `imageData` in `Shape` reader.
|
- Add `imageData` in `Shape` reader.
|
||||||
|
|
||||||
|
|
|
@ -163,12 +163,7 @@ mod tests {
|
||||||
let b = Table::new(vec![TableRow::new(vec![])]).build();
|
let b = Table::new(vec![TableRow::new(vec![])]).build();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
str::from_utf8(&b).unwrap(),
|
str::from_utf8(&b).unwrap(),
|
||||||
r#"<w:tbl><w:tblPr><w:tblW w:w="0" w:type="dxa" /><w:jc w:val="left" /><w:tblBorders><w:top w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:left w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:bottom w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:right w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:insideH w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:insideV w:val="single" w:sz="2" w:space="0" w:color="000000" /></w:tblBorders><w:tblCellMar>
|
r#"<w:tbl><w:tblPr><w:tblW w:w="0" w:type="dxa" /><w:jc w:val="left" /><w:tblBorders><w:top w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:left w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:bottom w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:right w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:insideH w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:insideV w:val="single" w:sz="2" w:space="0" w:color="000000" /></w:tblBorders></w:tblPr><w:tblGrid /><w:tr><w:trPr /></w:tr></w:tbl>"#
|
||||||
<w:top w:w="0" w:type="dxa" />
|
|
||||||
<w:left w:w="55" w:type="dxa" />
|
|
||||||
<w:bottom w:w="0" w:type="dxa" />
|
|
||||||
<w:right w:w="55" w:type="dxa" />
|
|
||||||
</w:tblCellMar></w:tblPr><w:tblGrid /><w:tr><w:trPr /></w:tr></w:tbl>"#
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,12 +174,7 @@ mod tests {
|
||||||
.build();
|
.build();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
str::from_utf8(&b).unwrap(),
|
str::from_utf8(&b).unwrap(),
|
||||||
r#"<w:tbl><w:tblPr><w:tblW w:w="0" w:type="dxa" /><w:jc w:val="left" /><w:tblBorders><w:top w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:left w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:bottom w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:right w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:insideH w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:insideV w:val="single" w:sz="2" w:space="0" w:color="000000" /></w:tblBorders><w:tblCellMar>
|
r#"<w:tbl><w:tblPr><w:tblW w:w="0" w:type="dxa" /><w:jc w:val="left" /><w:tblBorders><w:top w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:left w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:bottom w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:right w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:insideH w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:insideV w:val="single" w:sz="2" w:space="0" w:color="000000" /></w:tblBorders></w:tblPr><w:tblGrid>
|
||||||
<w:top w:w="0" w:type="dxa" />
|
|
||||||
<w:left w:w="55" w:type="dxa" />
|
|
||||||
<w:bottom w:w="0" w:type="dxa" />
|
|
||||||
<w:right w:w="55" w:type="dxa" />
|
|
||||||
</w:tblCellMar></w:tblPr><w:tblGrid>
|
|
||||||
<w:gridCol w:w="100" w:type="dxa" />
|
<w:gridCol w:w="100" w:type="dxa" />
|
||||||
<w:gridCol w:w="200" w:type="dxa" />
|
<w:gridCol w:w="200" w:type="dxa" />
|
||||||
</w:tblGrid><w:tr><w:trPr /></w:tr></w:tbl>"#
|
</w:tblGrid><w:tr><w:trPr /></w:tr></w:tbl>"#
|
||||||
|
@ -196,7 +186,7 @@ mod tests {
|
||||||
let t = Table::new(vec![]).set_grid(vec![100, 200, 300]);
|
let t = Table::new(vec![]).set_grid(vec![100, 200, 300]);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
serde_json::to_string(&t).unwrap(),
|
serde_json::to_string(&t).unwrap(),
|
||||||
r#"{"rows":[],"grid":[100,200,300],"hasNumbering":false,"property":{"width":{"width":0,"widthType":"auto"},"justification":"left","borders":{"top":{"borderType":"single","size":2,"color":"000000","position":"top","space":0},"left":{"borderType":"single","size":2,"color":"000000","position":"left","space":0},"bottom":{"borderType":"single","size":2,"color":"000000","position":"bottom","space":0},"right":{"borderType":"single","size":2,"color":"000000","position":"right","space":0},"insideH":{"borderType":"single","size":2,"color":"000000","position":"insideH","space":0},"insideV":{"borderType":"single","size":2,"color":"000000","position":"insideV","space":0}},"margins":{"top":{"val":0,"widthType":"dxa"},"left":{"val":55,"widthType":"dxa"},"bottom":{"val":0,"widthType":"dxa"},"right":{"val":55,"widthType":"dxa"}},"indent":null,"style":null,"layout":null}}"#
|
r#"{"rows":[],"grid":[100,200,300],"hasNumbering":false,"property":{"width":{"width":0,"widthType":"auto"},"justification":"left","borders":{"top":{"borderType":"single","size":2,"color":"000000","position":"top","space":0},"left":{"borderType":"single","size":2,"color":"000000","position":"left","space":0},"bottom":{"borderType":"single","size":2,"color":"000000","position":"bottom","space":0},"right":{"borderType":"single","size":2,"color":"000000","position":"right","space":0},"insideH":{"borderType":"single","size":2,"color":"000000","position":"insideH","space":0},"insideV":{"borderType":"single","size":2,"color":"000000","position":"insideV","space":0}}}}"#
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use wasm_bindgen::prelude::*;
|
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
use wasm_bindgen::prelude::*;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::documents::BuildXML;
|
use crate::documents::BuildXML;
|
||||||
|
@ -13,9 +13,13 @@ pub struct TableProperty {
|
||||||
width: TableWidth,
|
width: TableWidth,
|
||||||
justification: Justification,
|
justification: Justification,
|
||||||
borders: TableBorders,
|
borders: TableBorders,
|
||||||
margins: TableCellMargins,
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
|
margins: Option<TableCellMargins>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
indent: Option<TableIndent>,
|
indent: Option<TableIndent>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
style: Option<TableStyle>,
|
style: Option<TableStyle>,
|
||||||
|
#[serde(skip_serializing_if = "Option::is_none")]
|
||||||
layout: Option<TableLayout>,
|
layout: Option<TableLayout>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +29,7 @@ impl Default for TableProperty {
|
||||||
width: TableWidth::new(0, WidthType::Auto),
|
width: TableWidth::new(0, WidthType::Auto),
|
||||||
justification: Justification::new("left"),
|
justification: Justification::new("left"),
|
||||||
borders: TableBorders::new(),
|
borders: TableBorders::new(),
|
||||||
margins: TableCellMargins::new(),
|
margins: None,
|
||||||
indent: None,
|
indent: None,
|
||||||
style: None,
|
style: None,
|
||||||
layout: None,
|
layout: None,
|
||||||
|
@ -61,27 +65,47 @@ impl TableProperty {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_margins(mut self, margins: TableCellMargins) -> Self {
|
pub fn set_margins(mut self, margins: TableCellMargins) -> Self {
|
||||||
self.margins = margins;
|
self.margins = Some(margins);
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cell_margin_top(mut self, v: usize, t: WidthType) -> Self {
|
pub fn cell_margin_top(mut self, v: usize, t: WidthType) -> Self {
|
||||||
self.margins = self.margins.margin_top(v, t);
|
if let Some(margins) = self.margins {
|
||||||
|
self.margins = Some(margins.margin_top(v, t));
|
||||||
|
} else {
|
||||||
|
let margins = TableCellMargins::new();
|
||||||
|
self.margins = Some(margins.margin_top(v, t));
|
||||||
|
}
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cell_margin_right(mut self, v: usize, t: WidthType) -> Self {
|
pub fn cell_margin_right(mut self, v: usize, t: WidthType) -> Self {
|
||||||
self.margins = self.margins.margin_right(v, t);
|
if let Some(margins) = self.margins {
|
||||||
|
self.margins = Some(margins.margin_right(v, t));
|
||||||
|
} else {
|
||||||
|
let margins = TableCellMargins::new();
|
||||||
|
self.margins = Some(margins.margin_right(v, t));
|
||||||
|
}
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cell_margin_bottom(mut self, v: usize, t: WidthType) -> Self {
|
pub fn cell_margin_bottom(mut self, v: usize, t: WidthType) -> Self {
|
||||||
self.margins = self.margins.margin_bottom(v, t);
|
if let Some(margins) = self.margins {
|
||||||
|
self.margins = Some(margins.margin_bottom(v, t));
|
||||||
|
} else {
|
||||||
|
let margins = TableCellMargins::new();
|
||||||
|
self.margins = Some(margins.margin_bottom(v, t));
|
||||||
|
}
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cell_margin_left(mut self, v: usize, t: WidthType) -> Self {
|
pub fn cell_margin_left(mut self, v: usize, t: WidthType) -> Self {
|
||||||
self.margins = self.margins.margin_left(v, t);
|
if let Some(margins) = self.margins {
|
||||||
|
self.margins = Some(margins.margin_left(v, t));
|
||||||
|
} else {
|
||||||
|
let margins = TableCellMargins::new();
|
||||||
|
self.margins = Some(margins.margin_left(v, t));
|
||||||
|
}
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,7 +147,7 @@ impl BuildXML for TableProperty {
|
||||||
.add_child(&self.width)
|
.add_child(&self.width)
|
||||||
.add_child(&self.justification)
|
.add_child(&self.justification)
|
||||||
.add_child(&self.borders)
|
.add_child(&self.borders)
|
||||||
.add_child(&self.margins)
|
.add_optional_child(&self.margins)
|
||||||
.add_optional_child(&self.indent)
|
.add_optional_child(&self.indent)
|
||||||
.add_optional_child(&self.style)
|
.add_optional_child(&self.style)
|
||||||
.add_optional_child(&self.layout)
|
.add_optional_child(&self.layout)
|
||||||
|
@ -146,12 +170,7 @@ mod tests {
|
||||||
let b = c.build();
|
let b = c.build();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
str::from_utf8(&b).unwrap(),
|
str::from_utf8(&b).unwrap(),
|
||||||
r#"<w:tblPr><w:tblW w:w="0" w:type="dxa" /><w:jc w:val="left" /><w:tblBorders><w:top w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:left w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:bottom w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:right w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:insideH w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:insideV w:val="single" w:sz="2" w:space="0" w:color="000000" /></w:tblBorders><w:tblCellMar>
|
r#"<w:tblPr><w:tblW w:w="0" w:type="dxa" /><w:jc w:val="left" /><w:tblBorders><w:top w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:left w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:bottom w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:right w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:insideH w:val="single" w:sz="2" w:space="0" w:color="000000" /><w:insideV w:val="single" w:sz="2" w:space="0" w:color="000000" /></w:tblBorders></w:tblPr>"#
|
||||||
<w:top w:w="0" w:type="dxa" />
|
|
||||||
<w:left w:w="55" w:type="dxa" />
|
|
||||||
<w:bottom w:w="0" w:type="dxa" />
|
|
||||||
<w:right w:w="55" w:type="dxa" />
|
|
||||||
</w:tblCellMar></w:tblPr>"#
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,7 +179,7 @@ mod tests {
|
||||||
let p = TableProperty::new().indent(100);
|
let p = TableProperty::new().indent(100);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
serde_json::to_string(&p).unwrap(),
|
serde_json::to_string(&p).unwrap(),
|
||||||
r#"{"width":{"width":0,"widthType":"auto"},"justification":"left","borders":{"top":{"borderType":"single","size":2,"color":"000000","position":"top","space":0},"left":{"borderType":"single","size":2,"color":"000000","position":"left","space":0},"bottom":{"borderType":"single","size":2,"color":"000000","position":"bottom","space":0},"right":{"borderType":"single","size":2,"color":"000000","position":"right","space":0},"insideH":{"borderType":"single","size":2,"color":"000000","position":"insideH","space":0},"insideV":{"borderType":"single","size":2,"color":"000000","position":"insideV","space":0}},"margins":{"top":{"val":0,"widthType":"dxa"},"left":{"val":55,"widthType":"dxa"},"bottom":{"val":0,"widthType":"dxa"},"right":{"val":55,"widthType":"dxa"}},"indent":{"width":100,"widthType":"dxa"},"style":null,"layout":null}"#
|
r#"{"width":{"width":0,"widthType":"auto"},"justification":"left","borders":{"top":{"borderType":"single","size":2,"color":"000000","position":"top","space":0},"left":{"borderType":"single","size":2,"color":"000000","position":"left","space":0},"bottom":{"borderType":"single","size":2,"color":"000000","position":"bottom","space":0},"right":{"borderType":"single","size":2,"color":"000000","position":"right","space":0},"insideH":{"borderType":"single","size":2,"color":"000000","position":"insideH","space":0},"insideV":{"borderType":"single","size":2,"color":"000000","position":"insideV","space":0}},"indent":{"width":100,"widthType":"dxa"}}"#
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,8 +16,6 @@ impl ElementReader for TableCell {
|
||||||
attributes, name, ..
|
attributes, name, ..
|
||||||
}) => {
|
}) => {
|
||||||
let e = XMLElement::from_str(&name.local_name).unwrap();
|
let e = XMLElement::from_str(&name.local_name).unwrap();
|
||||||
// FIXME: ignore table in table for now. Please support table in table later.
|
|
||||||
ignore::ignore_element(e.clone(), XMLElement::Table, r);
|
|
||||||
match e {
|
match e {
|
||||||
XMLElement::Paragraph => {
|
XMLElement::Paragraph => {
|
||||||
let p = Paragraph::read(r, &attributes)?;
|
let p = Paragraph::read(r, &attributes)?;
|
||||||
|
@ -30,6 +28,11 @@ impl ElementReader for TableCell {
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
XMLElement::Table => {
|
||||||
|
if let Ok(table) = Table::read(r, &attributes) {
|
||||||
|
cell = cell.add_table(table)
|
||||||
|
}
|
||||||
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,11 +20,19 @@ impl ElementReader for TableProperty {
|
||||||
attributes, name, ..
|
attributes, name, ..
|
||||||
}) => {
|
}) => {
|
||||||
let e = XMLElement::from_str(&name.local_name).unwrap();
|
let e = XMLElement::from_str(&name.local_name).unwrap();
|
||||||
if let XMLElement::TableBorders = e {
|
match e {
|
||||||
|
XMLElement::TableBorders => {
|
||||||
if let Ok(borders) = TableBorders::read(r, &attributes) {
|
if let Ok(borders) = TableBorders::read(r, &attributes) {
|
||||||
tp = tp.set_borders(borders);
|
tp = tp.set_borders(borders);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
XMLElement::TableCellMargin => {
|
||||||
|
if let Ok(margins) = TableCellMargins::read(r, &attributes) {
|
||||||
|
tp = tp.set_margins(margins);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Ok(XmlEvent::EndElement { name, .. }) => {
|
Ok(XmlEvent::EndElement { name, .. }) => {
|
||||||
let e = XMLElement::from_str(&name.local_name).unwrap();
|
let e = XMLElement::from_str(&name.local_name).unwrap();
|
||||||
|
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -6,7 +6,7 @@ import { ShadingJSON } from "./shading";
|
||||||
import { TableLayoutType } from "../table";
|
import { TableLayoutType } from "../table";
|
||||||
import { DeleteJSON, InsertJSON } from "..";
|
import { DeleteJSON, InsertJSON } from "..";
|
||||||
|
|
||||||
export type TableCellChildJSON = ParagraphJSON;
|
export type TableCellChildJSON = ParagraphJSON | TableJSON;
|
||||||
|
|
||||||
export type WidthType = "dxa" | "auto" | "pct" | "nil";
|
export type WidthType = "dxa" | "auto" | "pct" | "nil";
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "docx-wasm",
|
"name": "docx-wasm",
|
||||||
"version": "0.0.268",
|
"version": "0.0.272",
|
||||||
"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>",
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -148,8 +148,8 @@ describe("reader", () => {
|
||||||
expect(json).toMatchSnapshot();
|
expect(json).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("should read imagedata in shape", () => {
|
test("should read nested table", () => {
|
||||||
const buffer = readFileSync("../fixtures/shape/shape.docx");
|
const buffer = readFileSync("../fixtures/nested_table/nested_table.docx");
|
||||||
const json = w.readDocx(buffer);
|
const json = w.readDocx(buffer);
|
||||||
expect(json).toMatchSnapshot();
|
expect(json).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue