Fix shd type (#253)
* fix: Add camelcase * update * update * 0.0.161 * fix: add type * 0.0.162 * fix: typemain
parent
b17819ad18
commit
f0894c412c
|
@ -17,6 +17,7 @@ use super::errors;
|
|||
|
||||
#[wasm_bindgen]
|
||||
#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub enum SectionType {
|
||||
NextPage,
|
||||
NextColumn,
|
||||
|
|
|
@ -48,6 +48,7 @@ use super::errors;
|
|||
*/
|
||||
#[wasm_bindgen]
|
||||
#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub enum ShdType {
|
||||
Nil,
|
||||
Clear,
|
||||
|
|
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
|
@ -487,7 +487,11 @@ export class Docx {
|
|||
}
|
||||
|
||||
if (typeof c.property.shading !== "undefined") {
|
||||
cell = cell.shading(c.property.shading._color, c.property.shading._fill);
|
||||
cell = cell.shading(
|
||||
c.property.shading._type,
|
||||
c.property.shading._color,
|
||||
c.property.shading._fill
|
||||
);
|
||||
}
|
||||
|
||||
return cell;
|
||||
|
|
|
@ -53,6 +53,7 @@ export * from "./run";
|
|||
export * from "./table";
|
||||
export * from "./numbering";
|
||||
export * from "./drawing";
|
||||
export * from "./shading";
|
||||
export * from "./comment";
|
||||
export * from "./textbox-content";
|
||||
export * from "./section-property";
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
export type ShadingJSON = {
|
||||
shd_type: string | null;
|
||||
shdType: string;
|
||||
color: string;
|
||||
fill: string;
|
||||
};
|
||||
|
|
|
@ -3,6 +3,10 @@ export class Shading {
|
|||
_color: string = "auto";
|
||||
_fill: string = "FFFFFF";
|
||||
|
||||
type(t: string) {
|
||||
this._type = t;
|
||||
}
|
||||
|
||||
color(c: string) {
|
||||
this._color = c;
|
||||
}
|
||||
|
|
|
@ -103,10 +103,11 @@ export class TableCell {
|
|||
return this;
|
||||
}
|
||||
|
||||
shading(color: string, fill: string) {
|
||||
shading(type: string, color: string, fill: string) {
|
||||
const s = new Shading();
|
||||
s.color(color);
|
||||
s.fill(fill);
|
||||
s.type(type);
|
||||
this.property.shading = s;
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "docx-wasm",
|
||||
"version": "0.0.159",
|
||||
"version": "0.0.163",
|
||||
"main": "dist/node/index.js",
|
||||
"browser": "dist/web/index.js",
|
||||
"author": "bokuweb <bokuweb12@gmail.com>",
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
use std::str::FromStr;
|
||||
|
||||
use super::*;
|
||||
use docx_rs::Shading;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
@ -53,9 +55,11 @@ impl TableCell {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn shading(mut self, color: &str, fill: &str) -> TableCell {
|
||||
// INFO: Now shd_type is fixed to `clear` from js
|
||||
let s = Shading::new().color(color).fill(fill);
|
||||
pub fn shading(mut self, t: &str, color: &str, fill: &str) -> TableCell {
|
||||
let mut s = Shading::new().color(color).fill(fill);
|
||||
if let Ok(t) = docx_rs::ShdType::from_str(t) {
|
||||
s = s.shd_type(t);
|
||||
}
|
||||
self.0.property = self.0.property.shading(s);
|
||||
self
|
||||
}
|
||||
|
|
|
@ -1096,7 +1096,7 @@ Object {
|
|||
"shading": Object {
|
||||
"color": "auto",
|
||||
"fill": "auto",
|
||||
"shdType": "Clear",
|
||||
"shdType": "clear",
|
||||
},
|
||||
"textDirection": null,
|
||||
"verticalAlign": "center",
|
||||
|
@ -1179,7 +1179,7 @@ Object {
|
|||
"shading": Object {
|
||||
"color": "auto",
|
||||
"fill": "auto",
|
||||
"shdType": "Clear",
|
||||
"shdType": "clear",
|
||||
},
|
||||
"textDirection": null,
|
||||
"verticalAlign": "center",
|
||||
|
@ -1273,7 +1273,7 @@ Object {
|
|||
"shading": Object {
|
||||
"color": "auto",
|
||||
"fill": "auto",
|
||||
"shdType": "Clear",
|
||||
"shdType": "clear",
|
||||
},
|
||||
"textDirection": null,
|
||||
"verticalAlign": "center",
|
||||
|
@ -1356,7 +1356,7 @@ Object {
|
|||
"shading": Object {
|
||||
"color": "auto",
|
||||
"fill": "auto",
|
||||
"shdType": "Clear",
|
||||
"shdType": "clear",
|
||||
},
|
||||
"textDirection": null,
|
||||
"verticalAlign": "center",
|
||||
|
@ -1450,7 +1450,7 @@ Object {
|
|||
"shading": Object {
|
||||
"color": "auto",
|
||||
"fill": "auto",
|
||||
"shdType": "Clear",
|
||||
"shdType": "clear",
|
||||
},
|
||||
"textDirection": null,
|
||||
"verticalAlign": null,
|
||||
|
@ -1533,7 +1533,7 @@ Object {
|
|||
"shading": Object {
|
||||
"color": "auto",
|
||||
"fill": "auto",
|
||||
"shdType": "Clear",
|
||||
"shdType": "clear",
|
||||
},
|
||||
"textDirection": null,
|
||||
"verticalAlign": null,
|
||||
|
@ -1627,7 +1627,7 @@ Object {
|
|||
"shading": Object {
|
||||
"color": "auto",
|
||||
"fill": "auto",
|
||||
"shdType": "Clear",
|
||||
"shdType": "clear",
|
||||
},
|
||||
"textDirection": null,
|
||||
"verticalAlign": null,
|
||||
|
@ -1710,7 +1710,7 @@ Object {
|
|||
"shading": Object {
|
||||
"color": "auto",
|
||||
"fill": "auto",
|
||||
"shdType": "Clear",
|
||||
"shdType": "clear",
|
||||
},
|
||||
"textDirection": null,
|
||||
"verticalAlign": null,
|
||||
|
@ -1804,7 +1804,7 @@ Object {
|
|||
"shading": Object {
|
||||
"color": "auto",
|
||||
"fill": "auto",
|
||||
"shdType": "Clear",
|
||||
"shdType": "clear",
|
||||
},
|
||||
"textDirection": null,
|
||||
"verticalAlign": null,
|
||||
|
@ -1887,7 +1887,7 @@ Object {
|
|||
"shading": Object {
|
||||
"color": "auto",
|
||||
"fill": "auto",
|
||||
"shdType": "Clear",
|
||||
"shdType": "clear",
|
||||
},
|
||||
"textDirection": null,
|
||||
"verticalAlign": null,
|
||||
|
@ -1970,7 +1970,7 @@ Object {
|
|||
"shading": Object {
|
||||
"color": "auto",
|
||||
"fill": "auto",
|
||||
"shdType": "Clear",
|
||||
"shdType": "clear",
|
||||
},
|
||||
"textDirection": null,
|
||||
"verticalAlign": null,
|
||||
|
@ -2064,7 +2064,7 @@ Object {
|
|||
"shading": Object {
|
||||
"color": "auto",
|
||||
"fill": "auto",
|
||||
"shdType": "Clear",
|
||||
"shdType": "clear",
|
||||
},
|
||||
"textDirection": null,
|
||||
"verticalAlign": null,
|
||||
|
@ -2147,7 +2147,7 @@ Object {
|
|||
"shading": Object {
|
||||
"color": "auto",
|
||||
"fill": "auto",
|
||||
"shdType": "Clear",
|
||||
"shdType": "clear",
|
||||
},
|
||||
"textDirection": null,
|
||||
"verticalAlign": null,
|
||||
|
@ -2230,7 +2230,7 @@ Object {
|
|||
"shading": Object {
|
||||
"color": "auto",
|
||||
"fill": "auto",
|
||||
"shdType": "Clear",
|
||||
"shdType": "clear",
|
||||
},
|
||||
"textDirection": null,
|
||||
"verticalAlign": null,
|
||||
|
@ -2318,7 +2318,7 @@ Object {
|
|||
"shading": Object {
|
||||
"color": "auto",
|
||||
"fill": "auto",
|
||||
"shdType": "Clear",
|
||||
"shdType": "clear",
|
||||
},
|
||||
"textDirection": null,
|
||||
"verticalAlign": null,
|
||||
|
@ -2395,7 +2395,7 @@ Object {
|
|||
"shading": Object {
|
||||
"color": "auto",
|
||||
"fill": "auto",
|
||||
"shdType": "Clear",
|
||||
"shdType": "clear",
|
||||
},
|
||||
"textDirection": null,
|
||||
"verticalAlign": null,
|
||||
|
@ -2478,7 +2478,7 @@ Object {
|
|||
"shading": Object {
|
||||
"color": "auto",
|
||||
"fill": "auto",
|
||||
"shdType": "Clear",
|
||||
"shdType": "clear",
|
||||
},
|
||||
"textDirection": null,
|
||||
"verticalAlign": null,
|
||||
|
@ -2572,7 +2572,7 @@ Object {
|
|||
"shading": Object {
|
||||
"color": "auto",
|
||||
"fill": "auto",
|
||||
"shdType": "Clear",
|
||||
"shdType": "clear",
|
||||
},
|
||||
"textDirection": null,
|
||||
"verticalAlign": null,
|
||||
|
@ -2655,7 +2655,7 @@ Object {
|
|||
"shading": Object {
|
||||
"color": "auto",
|
||||
"fill": "auto",
|
||||
"shdType": "Clear",
|
||||
"shdType": "clear",
|
||||
},
|
||||
"textDirection": null,
|
||||
"verticalAlign": null,
|
||||
|
@ -2738,7 +2738,7 @@ Object {
|
|||
"shading": Object {
|
||||
"color": "auto",
|
||||
"fill": "auto",
|
||||
"shdType": "Clear",
|
||||
"shdType": "clear",
|
||||
},
|
||||
"textDirection": null,
|
||||
"verticalAlign": null,
|
||||
|
|
|
@ -138,7 +138,7 @@ describe("writer", () => {
|
|||
const p = new w.Paragraph().addRun(new w.Run().addText("Hello!!"));
|
||||
const table = new w.Table().addRow(
|
||||
new w.TableRow().addCell(
|
||||
new w.TableCell().addParagraph(p).shading("auto", "FF0000")
|
||||
new w.TableCell().addParagraph(p).shading("clear", "auto", "FF0000")
|
||||
)
|
||||
);
|
||||
const buffer = new w.Docx().addTable(table).build();
|
||||
|
|
Loading…
Reference in New Issue