parent
c992a4bcbf
commit
245da8dcf1
|
@ -63,6 +63,31 @@ jobs:
|
|||
path: ~/.cargo/git
|
||||
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
|
||||
- run: cargo build
|
||||
|
||||
# build-wasm:
|
||||
# runs-on: ubuntu-latest
|
||||
# steps:
|
||||
# - uses: actions/checkout@master
|
||||
# - uses: actions-rs/toolchain@v1
|
||||
# with:
|
||||
# profile: minimal
|
||||
# toolchain: stable
|
||||
# override: true
|
||||
# - name: Cache cargo registry
|
||||
# uses: actions/cache@v1
|
||||
# with:
|
||||
# path: ~/.cargo/registry
|
||||
# key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
|
||||
# - name: Cache cargo index
|
||||
# uses: actions/cache@v1
|
||||
# with:
|
||||
# path: ~/.cargo/git
|
||||
# key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
|
||||
# - run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
|
||||
# - run: cd docx-wasm && yarn install
|
||||
# - run: rustup target add wasm32-unknown-unknown
|
||||
# - run: cd docx-wasm && npm run build
|
||||
|
||||
lint:
|
||||
name: Clippy
|
||||
runs-on: ubuntu-latest
|
||||
|
|
|
@ -51,6 +51,18 @@ impl TableCellBorder {
|
|||
self.border_type = border_type;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn get_size(&self) -> usize {
|
||||
self.size
|
||||
}
|
||||
|
||||
pub fn get_color(&self) -> String {
|
||||
self.color.clone()
|
||||
}
|
||||
|
||||
pub fn get_border_type(&self) -> BorderType {
|
||||
self.border_type
|
||||
}
|
||||
}
|
||||
|
||||
impl BuildXML for TableCellBorder {
|
||||
|
|
|
@ -4,6 +4,7 @@ import { Delete } from "./delete";
|
|||
import { DeleteText } from "./delete-text";
|
||||
import { Table } from "./table";
|
||||
import { TableCell } from "./table-cell";
|
||||
import { BorderType } from "./table-cell-border";
|
||||
import { Run } from "./run";
|
||||
import { Text } from "./text";
|
||||
import { Tab } from "./tab";
|
||||
|
@ -18,6 +19,33 @@ import { DocxJSON } from "./json";
|
|||
|
||||
import * as wasm from "./pkg";
|
||||
|
||||
const convertBorderType = (t: BorderType) => {
|
||||
switch (t) {
|
||||
case "Nil":
|
||||
return wasm.BorderType.Nil;
|
||||
case "None":
|
||||
return wasm.BorderType.None;
|
||||
case "Single":
|
||||
return wasm.BorderType.Single;
|
||||
case "Thick":
|
||||
return wasm.BorderType.Thick;
|
||||
case "Double":
|
||||
return wasm.BorderType.Double;
|
||||
case "Dotted":
|
||||
return wasm.BorderType.Dotted;
|
||||
case "Dashed":
|
||||
return wasm.BorderType.Dashed;
|
||||
case "DotDash":
|
||||
return wasm.BorderType.DotDash;
|
||||
case "DotDotDash":
|
||||
return wasm.BorderType.DotDotDash;
|
||||
case "Triple":
|
||||
return wasm.BorderType.Triple;
|
||||
default:
|
||||
return wasm.BorderType.Single;
|
||||
}
|
||||
};
|
||||
|
||||
export class Docx {
|
||||
children: (Paragraph | Table)[] = [];
|
||||
abstractNumberings: AbstractNumbering[] = [];
|
||||
|
@ -274,54 +302,62 @@ export class Docx {
|
|||
if (c.property.borders.top) {
|
||||
const border = wasm
|
||||
.createTableCellBorder(wasm.BorderPosition.Top)
|
||||
.size(c.property.borders.top.size)
|
||||
.color(c.property.borders.top.color)
|
||||
.border_type(c.property.borders.top.border_type);
|
||||
.size(c.property.borders.top._size)
|
||||
.color(c.property.borders.top._color)
|
||||
.border_type(convertBorderType(c.property.borders.top._border_type));
|
||||
cell = cell.set_border(border);
|
||||
}
|
||||
|
||||
if (c.property.borders.right) {
|
||||
const border = wasm
|
||||
.createTableCellBorder(wasm.BorderPosition.Right)
|
||||
.size(c.property.borders.right.size)
|
||||
.color(c.property.borders.right.color)
|
||||
.border_type(c.property.borders.right.border_type);
|
||||
.size(c.property.borders.right._size)
|
||||
.color(c.property.borders.right._color)
|
||||
.border_type(
|
||||
convertBorderType(c.property.borders.right._border_type)
|
||||
);
|
||||
cell = cell.set_border(border);
|
||||
}
|
||||
|
||||
if (c.property.borders.bottom) {
|
||||
const border = wasm
|
||||
.createTableCellBorder(wasm.BorderPosition.Bottom)
|
||||
.size(c.property.borders.bottom.size)
|
||||
.color(c.property.borders.bottom.color)
|
||||
.border_type(c.property.borders.bottom.border_type);
|
||||
.size(c.property.borders.bottom._size)
|
||||
.color(c.property.borders.bottom._color)
|
||||
.border_type(
|
||||
convertBorderType(c.property.borders.bottom._border_type)
|
||||
);
|
||||
cell = cell.set_border(border);
|
||||
}
|
||||
|
||||
if (c.property.borders.left) {
|
||||
const border = wasm
|
||||
.createTableCellBorder(wasm.BorderPosition.Left)
|
||||
.size(c.property.borders.left.size)
|
||||
.color(c.property.borders.left.color)
|
||||
.border_type(c.property.borders.left.border_type);
|
||||
.size(c.property.borders.left._size)
|
||||
.color(c.property.borders.left._color)
|
||||
.border_type(convertBorderType(c.property.borders.left._border_type));
|
||||
cell = cell.set_border(border);
|
||||
}
|
||||
|
||||
if (c.property.borders.insideH) {
|
||||
const border = wasm
|
||||
.createTableCellBorder(wasm.BorderPosition.InsideH)
|
||||
.size(c.property.borders.insideH.size)
|
||||
.color(c.property.borders.insideH.color)
|
||||
.border_type(c.property.borders.insideH.border_type);
|
||||
.size(c.property.borders.insideH._size)
|
||||
.color(c.property.borders.insideH._color)
|
||||
.border_type(
|
||||
convertBorderType(c.property.borders.insideH._border_type)
|
||||
);
|
||||
cell = cell.set_border(border);
|
||||
}
|
||||
|
||||
if (c.property.borders.insideV) {
|
||||
const border = wasm
|
||||
.createTableCellBorder(wasm.BorderPosition.InsideV)
|
||||
.size(c.property.borders.insideV.size)
|
||||
.color(c.property.borders.insideV.color)
|
||||
.border_type(c.property.borders.insideV.border_type);
|
||||
.size(c.property.borders.insideV._size)
|
||||
.color(c.property.borders.insideV._color)
|
||||
.border_type(
|
||||
convertBorderType(c.property.borders.insideV._border_type)
|
||||
);
|
||||
cell = cell.set_border(border);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,13 @@
|
|||
import { BorderPosition, TableCellBorder } from "./table-cell-border";
|
||||
|
||||
export type PositionKeys =
|
||||
| "top"
|
||||
| "left"
|
||||
| "bottom"
|
||||
| "right"
|
||||
| "insideH"
|
||||
| "insideV";
|
||||
|
||||
export class TableCellBorders {
|
||||
top: TableCellBorder | null = new TableCellBorder("Top");
|
||||
left: TableCellBorder | null = new TableCellBorder("Left");
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Paragraph } from "./paragraph";
|
||||
import { TableCellBorders } from "./table-cell-borders";
|
||||
import { TableCellBorders, PositionKeys } from "./table-cell-borders";
|
||||
import { BorderPosition, TableCellBorder } from "./table-cell-border";
|
||||
|
||||
export type VMergeType = "restart" | "continue";
|
||||
|
@ -7,7 +7,7 @@ export type VMergeType = "restart" | "continue";
|
|||
export type VAlignType = "top" | "center" | "bottom";
|
||||
|
||||
export type CellProperty = {
|
||||
borders?: TableCellBorders;
|
||||
borders: TableCellBorders;
|
||||
verticalMerge?: VMergeType;
|
||||
verticalAlign?: VAlignType;
|
||||
gridSpan?: number;
|
||||
|
@ -16,7 +16,9 @@ export type CellProperty = {
|
|||
|
||||
export class TableCell {
|
||||
children: Paragraph[] = [];
|
||||
property: CellProperty = {};
|
||||
property: CellProperty = {
|
||||
borders: new TableCellBorders(),
|
||||
};
|
||||
|
||||
addParagraph(p: Paragraph) {
|
||||
this.children.push(p);
|
||||
|
@ -44,14 +46,14 @@ export class TableCell {
|
|||
}
|
||||
|
||||
setBorder(position: BorderPosition, border: TableCellBorder) {
|
||||
this.property.borders[position] = border;
|
||||
this.property.borders[position.toLowerCase() as PositionKeys] = border;
|
||||
return this;
|
||||
}
|
||||
|
||||
clearBorder(position: BorderPosition) {
|
||||
this.property.borders[position] = new TableCellBorder(position).border_type(
|
||||
"Nil"
|
||||
);
|
||||
this.property.borders[
|
||||
position.toLowerCase() as PositionKeys
|
||||
] = new TableCellBorder(position).border_type("Nil");
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "docx-wasm",
|
||||
"version": "0.0.62",
|
||||
"version": "0.0.63",
|
||||
"main": "dist/node/index.js",
|
||||
"browser": "dist/web/index.js",
|
||||
"author": "bokuweb <bokuweb12@gmail.com>",
|
||||
|
|
|
@ -17,6 +17,11 @@ impl TableCellBorder {
|
|||
|
||||
#[wasm_bindgen]
|
||||
impl TableCellBorder {
|
||||
pub fn size(mut self, size: usize) -> TableCellBorder {
|
||||
self.0.size = size;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn color(mut self, color: String) -> TableCellBorder {
|
||||
self.0.color = color;
|
||||
self
|
||||
|
@ -26,4 +31,16 @@ impl TableCellBorder {
|
|||
self.0.border_type = border_type;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn get_size(&self) -> usize {
|
||||
self.0.get_size()
|
||||
}
|
||||
|
||||
pub fn get_color(&self) -> String {
|
||||
self.0.get_color()
|
||||
}
|
||||
|
||||
pub fn get_border_type(&self) -> docx_rs::BorderType {
|
||||
self.0.get_border_type()
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue