diff --git a/docx-core/src/documents/elements/page_num.rs b/docx-core/src/documents/elements/page_num.rs index 8e0c22f..c9210ff 100644 --- a/docx-core/src/documents/elements/page_num.rs +++ b/docx-core/src/documents/elements/page_num.rs @@ -7,6 +7,7 @@ use crate::xml_builder::*; #[derive(Serialize, Debug, Clone, PartialEq)] pub struct PageNum { pub instr: InstrPAGE, + #[serde(skip_serializing_if = "Option::is_none")] pub frame_property: Option, } @@ -14,14 +15,7 @@ impl Default for PageNum { fn default() -> Self { Self { instr: InstrPAGE {}, - frame_property: Some(FrameProperty { - wrap: Some("none".to_owned()), - v_anchor: Some("text".to_owned()), - h_anchor: Some("margin".to_owned()), - x_align: Some("right".to_owned()), - y: Some(1), - ..Default::default() - }), + frame_property: None, } } } @@ -180,7 +174,7 @@ mod tests { let b = PageNum::new().build(); assert_eq!( str::from_utf8(&b).unwrap(), - r#"PAGE1 + r#"PAGE1 "# ); } @@ -190,7 +184,7 @@ mod tests { let b = PageNum::new().wrap("none").x_align("left").build(); assert_eq!( str::from_utf8(&b).unwrap(), - r#"PAGE1 + r#"PAGE1 "# ); } diff --git a/docx-core/src/types/alignment_type.rs b/docx-core/src/types/alignment_type.rs index d050b34..ff80e28 100644 --- a/docx-core/src/types/alignment_type.rs +++ b/docx-core/src/types/alignment_type.rs @@ -1,3 +1,4 @@ +use serde::Serialize; use std::fmt; use std::str::FromStr; #[cfg(feature = "wasm")] @@ -6,7 +7,10 @@ use wasm_bindgen::prelude::*; use super::errors; #[cfg_attr(feature = "wasm", wasm_bindgen)] -#[derive(Copy, Clone, Debug)] +#[cfg_attr(feature = "wasm", derive(ts_rs::TS))] +#[cfg_attr(feature = "wasm", ts(export))] +#[derive(Copy, Clone, Debug, Serialize)] +#[serde(rename_all = "camelCase")] pub enum AlignmentType { Both, Center, @@ -16,7 +20,6 @@ pub enum AlignmentType { Left, Right, Justified, - Unsupported, } impl fmt::Display for AlignmentType { @@ -30,7 +33,6 @@ impl fmt::Display for AlignmentType { AlignmentType::End => write!(f, "end"), AlignmentType::Both => write!(f, "both"), AlignmentType::Justified => write!(f, "justified"), - _ => write!(f, "unsupported"), } } } @@ -47,7 +49,7 @@ impl FromStr for AlignmentType { "start" => Ok(AlignmentType::Start), "end" => Ok(AlignmentType::End), "justified" => Ok(AlignmentType::Justified), - _ => Ok(AlignmentType::Unsupported), + _ => Ok(AlignmentType::Left), } } } diff --git a/docx-wasm/js/json/bindings/AlignmentType.ts b/docx-wasm/js/json/bindings/AlignmentType.ts new file mode 100644 index 0000000..40227c3 --- /dev/null +++ b/docx-wasm/js/json/bindings/AlignmentType.ts @@ -0,0 +1,2 @@ + +export type AlignmentType = "both" | "center" | "distribute" | "start" | "end" | "left" | "right" | "justified"; \ No newline at end of file diff --git a/docx-wasm/js/json/paragraph.ts b/docx-wasm/js/json/paragraph.ts index 56457b4..521c5a3 100644 --- a/docx-wasm/js/json/paragraph.ts +++ b/docx-wasm/js/json/paragraph.ts @@ -8,6 +8,7 @@ import { import { LineSpacingJSON } from "./line_spacing"; import { FrameProperty as FramePropertyJSON } from "./bindings/FrameProperty"; import { TextAlignmentType } from "./bindings/TextAlignmentType"; +import { AlignmentType } from "./bindings/AlignmentType"; export { FrameProperty as FramePropertyJSON } from "./bindings/FrameProperty"; @@ -56,15 +57,7 @@ export type ParagraphPropertyJSON = { runProperty: RunPropertyJSON; style?: string | null; numberingProperty?: NumberingPropertyJSON | null; - alignment?: - | "left" - | "center" - | "right" - | "justified" - | "both" - | "start" - | "end" - | "unsupported"; + alignment?: AlignmentType; textAlignment?: TextAlignmentType; adjustRightInd?: number; indent?: IndentJSON | null; diff --git a/docx-wasm/package.json b/docx-wasm/package.json index cd38ff4..59c325f 100644 --- a/docx-wasm/package.json +++ b/docx-wasm/package.json @@ -1,6 +1,6 @@ { "name": "docx-wasm", - "version": "0.4.14-beta2", + "version": "0.4.14-beta4", "main": "dist/node/index.js", "browser": "dist/web/index.js", "author": "bokuweb ",