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