parent
e886c72c58
commit
75e6b77d4a
|
@ -143,7 +143,7 @@ checksum = "0e25ea47919b1560c4e3b7fe0aaab9becf5b84a10325ddf7db0f0ba5e1026499"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "docx-rs"
|
name = "docx-rs"
|
||||||
version = "0.4.11"
|
version = "0.4.13"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"base64",
|
"base64",
|
||||||
"image",
|
"image",
|
||||||
|
|
|
@ -245,6 +245,13 @@ impl Paragraph {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn tabs(mut self, tabs: &[Tab]) -> Self {
|
||||||
|
for tab in tabs {
|
||||||
|
self.property = self.property.add_tab(tab.clone());
|
||||||
|
}
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn indent(
|
pub fn indent(
|
||||||
mut self,
|
mut self,
|
||||||
left: Option<i32>,
|
left: Option<i32>,
|
||||||
|
|
|
@ -5,6 +5,8 @@ use crate::types::*;
|
||||||
use crate::xml_builder::*;
|
use crate::xml_builder::*;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Default)]
|
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Default)]
|
||||||
|
#[cfg_attr(feature = "wasm", derive(ts_rs::TS))]
|
||||||
|
#[cfg_attr(feature = "wasm", ts(export))]
|
||||||
pub struct Tab {
|
pub struct Tab {
|
||||||
pub val: Option<TabValueType>,
|
pub val: Option<TabValueType>,
|
||||||
pub leader: Option<TabLeaderType>,
|
pub leader: Option<TabLeaderType>,
|
||||||
|
|
|
@ -8,6 +8,8 @@ use wasm_bindgen::prelude::*;
|
||||||
use super::errors;
|
use super::errors;
|
||||||
|
|
||||||
#[cfg_attr(feature = "wasm", wasm_bindgen)]
|
#[cfg_attr(feature = "wasm", wasm_bindgen)]
|
||||||
|
#[cfg_attr(feature = "wasm", derive(ts_rs::TS))]
|
||||||
|
#[cfg_attr(feature = "wasm", ts(export))]
|
||||||
#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq)]
|
#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub enum TabLeaderType {
|
pub enum TabLeaderType {
|
||||||
|
|
|
@ -8,6 +8,8 @@ use wasm_bindgen::prelude::*;
|
||||||
use super::errors;
|
use super::errors;
|
||||||
|
|
||||||
#[cfg_attr(feature = "wasm", wasm_bindgen)]
|
#[cfg_attr(feature = "wasm", wasm_bindgen)]
|
||||||
|
#[cfg_attr(feature = "wasm", derive(ts_rs::TS))]
|
||||||
|
#[cfg_attr(feature = "wasm", ts(export))]
|
||||||
#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq)]
|
#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq)]
|
||||||
#[serde(rename_all = "camelCase")]
|
#[serde(rename_all = "camelCase")]
|
||||||
pub enum TabValueType {
|
pub enum TabValueType {
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
|
||||||
import type { TabLeaderType } from "./TabLeaderType";
|
import type { TabLeaderType } from "./TabLeaderType";
|
||||||
import type { TabValueType } from "./TabValueType";
|
import type { TabValueType } from "./TabValueType";
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,2 @@
|
||||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
|
||||||
|
|
||||||
export type TabLeaderType = "dot" | "heavy" | "hyphen" | "middledot" | "none" | "underscore";
|
export type TabLeaderType = "dot" | "heavy" | "hyphen" | "middleDot" | "none" | "underscore";
|
|
@ -1,3 +1,2 @@
|
||||||
// This file was generated by [ts-rs](https://github.com/Aleph-Alpha/ts-rs). Do not edit this file manually.
|
|
||||||
|
|
||||||
export type TabValueType = "bar" | "center" | "clear" | "decimal" | "end" | "right" | "num" | "start" | "left";
|
export type TabValueType = "bar" | "center" | "clear" | "decimal" | "end" | "right" | "num" | "start" | "left";
|
|
@ -2,6 +2,7 @@ import { RunProperty, createDefaultRunProperty } from "./run";
|
||||||
|
|
||||||
import * as wasm from "./pkg";
|
import * as wasm from "./pkg";
|
||||||
import { TextAlignmentType } from "./json/bindings/TextAlignmentType";
|
import { TextAlignmentType } from "./json/bindings/TextAlignmentType";
|
||||||
|
import { Tab } from "./json/bindings/Tab";
|
||||||
|
|
||||||
export type AlignmentType =
|
export type AlignmentType =
|
||||||
| "center"
|
| "center"
|
||||||
|
@ -73,6 +74,7 @@ export type ParagraphProperty = {
|
||||||
paragraphPropertyChange?: ParagraphPropertyChange;
|
paragraphPropertyChange?: ParagraphPropertyChange;
|
||||||
outlineLvl?: number | null;
|
outlineLvl?: number | null;
|
||||||
adjustRightInd?: number;
|
adjustRightInd?: number;
|
||||||
|
tabs?: Tab[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export const createDefaultParagraphProperty = (): ParagraphProperty => {
|
export const createDefaultParagraphProperty = (): ParagraphProperty => {
|
||||||
|
@ -338,5 +340,66 @@ export const setParagraphProperty = <T extends wasm.Paragraph | wasm.Style>(
|
||||||
target = target.outline_lvl(property.outlineLvl) as T;
|
target = target.outline_lvl(property.outlineLvl) as T;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (property.tabs) {
|
||||||
|
for (const tab of property.tabs) {
|
||||||
|
let val: wasm.TabValueType | undefined;
|
||||||
|
let leader: wasm.TabLeaderType | undefined;
|
||||||
|
switch (tab.val) {
|
||||||
|
case "bar":
|
||||||
|
val = wasm.TabValueType.Bar;
|
||||||
|
break;
|
||||||
|
case "bar":
|
||||||
|
val = wasm.TabValueType.Bar;
|
||||||
|
break;
|
||||||
|
case "center":
|
||||||
|
val = wasm.TabValueType.Center;
|
||||||
|
break;
|
||||||
|
case "clear":
|
||||||
|
val = wasm.TabValueType.Clear;
|
||||||
|
break;
|
||||||
|
case "decimal":
|
||||||
|
val = wasm.TabValueType.Decimal;
|
||||||
|
break;
|
||||||
|
case "end":
|
||||||
|
val = wasm.TabValueType.End;
|
||||||
|
break;
|
||||||
|
case "right":
|
||||||
|
val = wasm.TabValueType.Right;
|
||||||
|
break;
|
||||||
|
case "num":
|
||||||
|
val = wasm.TabValueType.Num;
|
||||||
|
break;
|
||||||
|
case "start":
|
||||||
|
val = wasm.TabValueType.Start;
|
||||||
|
break;
|
||||||
|
case "left":
|
||||||
|
val = wasm.TabValueType.Left;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (tab.leader) {
|
||||||
|
case "dot":
|
||||||
|
leader = wasm.TabLeaderType.Dot;
|
||||||
|
break;
|
||||||
|
case "heavy":
|
||||||
|
leader = wasm.TabLeaderType.Heavy;
|
||||||
|
break;
|
||||||
|
case "hyphen":
|
||||||
|
leader = wasm.TabLeaderType.Hyphen;
|
||||||
|
break;
|
||||||
|
case "middleDot":
|
||||||
|
leader = wasm.TabLeaderType.MiddleDot;
|
||||||
|
break;
|
||||||
|
case "none":
|
||||||
|
leader = wasm.TabLeaderType.None;
|
||||||
|
break;
|
||||||
|
case "underscore":
|
||||||
|
leader = wasm.TabLeaderType.None;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
target = target.add_tab(val, leader, tab.pos ?? undefined) as T;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return target;
|
return target;
|
||||||
};
|
};
|
||||||
|
|
|
@ -15,6 +15,8 @@ import { Comment } from "./comment";
|
||||||
import { CommentEnd } from "./comment-end";
|
import { CommentEnd } from "./comment-end";
|
||||||
import { Hyperlink } from "./hyperlink";
|
import { Hyperlink } from "./hyperlink";
|
||||||
import { TextAlignmentType } from "./json/bindings/TextAlignmentType";
|
import { TextAlignmentType } from "./json/bindings/TextAlignmentType";
|
||||||
|
import { TabValueType } from "./json/bindings/TabValueType";
|
||||||
|
import { TabLeaderType } from "./json/bindings/TabLeaderType";
|
||||||
|
|
||||||
export type ParagraphChild =
|
export type ParagraphChild =
|
||||||
| Run
|
| Run
|
||||||
|
@ -71,6 +73,17 @@ export class Paragraph {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tabs(
|
||||||
|
tabs: {
|
||||||
|
val: TabValueType | null;
|
||||||
|
leader: TabLeaderType | null;
|
||||||
|
pos: number | null;
|
||||||
|
}[]
|
||||||
|
) {
|
||||||
|
this.property.tabs = tabs;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
align(type: AlignmentType) {
|
align(type: AlignmentType) {
|
||||||
this.property.align = type;
|
this.property.align = type;
|
||||||
return this;
|
return this;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "docx-wasm",
|
"name": "docx-wasm",
|
||||||
"version": "0.4.13",
|
"version": "0.4.14-beta2",
|
||||||
"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>",
|
||||||
|
|
|
@ -233,6 +233,16 @@ impl Paragraph {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn add_tab(
|
||||||
|
mut self,
|
||||||
|
val: Option<docx_rs::TabValueType>,
|
||||||
|
leader: Option<docx_rs::TabLeaderType>,
|
||||||
|
pos: Option<usize>,
|
||||||
|
) -> Self {
|
||||||
|
self.0 = self.0.add_tab(docx_rs::Tab { val, leader, pos });
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn paragraph_property_change(mut self, p: ParagraphPropertyChange) -> Self {
|
pub fn paragraph_property_change(mut self, p: ParagraphPropertyChange) -> Self {
|
||||||
self.0.property = self.0.property.paragraph_property_change(p.take());
|
self.0.property = self.0.property.paragraph_property_change(p.take());
|
||||||
self
|
self
|
||||||
|
|
|
@ -114,6 +114,19 @@ impl Style {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn add_tab(
|
||||||
|
mut self,
|
||||||
|
val: Option<docx_rs::TabValueType>,
|
||||||
|
leader: Option<docx_rs::TabLeaderType>,
|
||||||
|
pos: Option<usize>,
|
||||||
|
) -> Self {
|
||||||
|
self.0.paragraph_property =
|
||||||
|
self.0
|
||||||
|
.paragraph_property
|
||||||
|
.add_tab(docx_rs::Tab { val, leader, pos });
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn indent(
|
pub fn indent(
|
||||||
mut self,
|
mut self,
|
||||||
left: i32,
|
left: i32,
|
||||||
|
|
Loading…
Reference in New Issue