From 44a236e6c03b961063773469ec147803ade00493 Mon Sep 17 00:00:00 2001 From: bokuweb Date: Tue, 13 Dec 2022 23:05:37 +0900 Subject: [PATCH] fix: expose outline level (#590) * fix: expose outline level * fix: js method for style * fix * fix --- CHANGELOG.md | 4 ++++ docx-core/src/documents/elements/paragraph_property.rs | 2 ++ docx-wasm/js/paragraph-property.ts | 5 +++++ docx-wasm/js/paragraph.ts | 5 +++++ docx-wasm/js/style.ts | 5 +++++ docx-wasm/package.json | 2 +- docx-wasm/src/paragraph.rs | 5 +++++ 7 files changed, 27 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e101ce5..ae15eda 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## docx-wasm@0.0.276 (13. Dec, 2022) + +- Support outline_level in Paragraph and style. + ## docx-wasm@0.0.276-rc39 (13. Dec, 2022) - Support before/after contents in ToC. diff --git a/docx-core/src/documents/elements/paragraph_property.rs b/docx-core/src/documents/elements/paragraph_property.rs index 6f9eed3..5aec4ba 100644 --- a/docx-core/src/documents/elements/paragraph_property.rs +++ b/docx-core/src/documents/elements/paragraph_property.rs @@ -97,6 +97,8 @@ impl ParagraphProperty { pub fn outline_lvl(mut self, v: usize) -> Self { if v >= 10 { + // clamped + self.outline_lvl = Some(OutlineLvl::new(9)); return self; } self.outline_lvl = Some(OutlineLvl::new(v)); diff --git a/docx-wasm/js/paragraph-property.ts b/docx-wasm/js/paragraph-property.ts index ae6a749..3bf2639 100644 --- a/docx-wasm/js/paragraph-property.ts +++ b/docx-wasm/js/paragraph-property.ts @@ -68,6 +68,7 @@ export type ParagraphProperty = { pageBreakBefore: boolean; widowControl: boolean; paragraphPropertyChange?: ParagraphPropertyChange; + outlineLvl?: number | null; }; export const createDefaultParagraphProperty = (): ParagraphProperty => { @@ -280,5 +281,9 @@ export const setParagraphProperty = ( target = target.widow_control(true) as T; } + if (property.outlineLvl != null) { + target = target.outline_lvl(property.outlineLvl) as T; + } + return target; }; diff --git a/docx-wasm/js/paragraph.ts b/docx-wasm/js/paragraph.ts index d75f3b0..73c1644 100644 --- a/docx-wasm/js/paragraph.ts +++ b/docx-wasm/js/paragraph.ts @@ -154,6 +154,11 @@ export class Paragraph { return this; } + outlineLevel(v: number) { + this.property = { ...this.property, outlineLvl: v }; + return this; + } + paragraphPropertyChange(propertyChange: ParagraphPropertyChange) { this.property.paragraphPropertyChange = propertyChange; return this; diff --git a/docx-wasm/js/style.ts b/docx-wasm/js/style.ts index d9ff625..a5ab8f8 100644 --- a/docx-wasm/js/style.ts +++ b/docx-wasm/js/style.ts @@ -207,6 +207,11 @@ export class Style { return this; } + outlineLevel(v: number) { + this._paragraphProperty = { ...this._paragraphProperty, outlineLvl: v }; + return this; + } + // tableProperty = (n: TableProperty) => { // this._tableProperty = n; // return this; diff --git a/docx-wasm/package.json b/docx-wasm/package.json index 585968d..03294af 100644 --- a/docx-wasm/package.json +++ b/docx-wasm/package.json @@ -1,6 +1,6 @@ { "name": "docx-wasm", - "version": "0.0.276-rc39", + "version": "0.0.276", "main": "dist/node/index.js", "browser": "dist/web/index.js", "author": "bokuweb ", diff --git a/docx-wasm/src/paragraph.rs b/docx-wasm/src/paragraph.rs index 0da8eb6..aebce75 100644 --- a/docx-wasm/src/paragraph.rs +++ b/docx-wasm/src/paragraph.rs @@ -131,6 +131,11 @@ impl Paragraph { self } + pub fn outline_lvl(mut self, level: usize) -> Paragraph { + self.0.property = self.0.property.outline_lvl(level); + self + } + pub fn style(mut self, style_id: &str) -> Paragraph { self.0.property = self.0.property.style(style_id); self