parent
c992a4bcbf
commit
245da8dcf1
|
@ -63,6 +63,31 @@ jobs:
|
||||||
path: ~/.cargo/git
|
path: ~/.cargo/git
|
||||||
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
|
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
|
||||||
- run: cargo build
|
- 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:
|
lint:
|
||||||
name: Clippy
|
name: Clippy
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
|
@ -51,6 +51,18 @@ impl TableCellBorder {
|
||||||
self.border_type = border_type;
|
self.border_type = border_type;
|
||||||
self
|
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 {
|
impl BuildXML for TableCellBorder {
|
||||||
|
|
|
@ -4,6 +4,7 @@ import { Delete } from "./delete";
|
||||||
import { DeleteText } from "./delete-text";
|
import { DeleteText } from "./delete-text";
|
||||||
import { Table } from "./table";
|
import { Table } from "./table";
|
||||||
import { TableCell } from "./table-cell";
|
import { TableCell } from "./table-cell";
|
||||||
|
import { BorderType } from "./table-cell-border";
|
||||||
import { Run } from "./run";
|
import { Run } from "./run";
|
||||||
import { Text } from "./text";
|
import { Text } from "./text";
|
||||||
import { Tab } from "./tab";
|
import { Tab } from "./tab";
|
||||||
|
@ -18,6 +19,33 @@ import { DocxJSON } from "./json";
|
||||||
|
|
||||||
import * as wasm from "./pkg";
|
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 {
|
export class Docx {
|
||||||
children: (Paragraph | Table)[] = [];
|
children: (Paragraph | Table)[] = [];
|
||||||
abstractNumberings: AbstractNumbering[] = [];
|
abstractNumberings: AbstractNumbering[] = [];
|
||||||
|
@ -274,54 +302,62 @@ export class Docx {
|
||||||
if (c.property.borders.top) {
|
if (c.property.borders.top) {
|
||||||
const border = wasm
|
const border = wasm
|
||||||
.createTableCellBorder(wasm.BorderPosition.Top)
|
.createTableCellBorder(wasm.BorderPosition.Top)
|
||||||
.size(c.property.borders.top.size)
|
.size(c.property.borders.top._size)
|
||||||
.color(c.property.borders.top.color)
|
.color(c.property.borders.top._color)
|
||||||
.border_type(c.property.borders.top.border_type);
|
.border_type(convertBorderType(c.property.borders.top._border_type));
|
||||||
cell = cell.set_border(border);
|
cell = cell.set_border(border);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c.property.borders.right) {
|
if (c.property.borders.right) {
|
||||||
const border = wasm
|
const border = wasm
|
||||||
.createTableCellBorder(wasm.BorderPosition.Right)
|
.createTableCellBorder(wasm.BorderPosition.Right)
|
||||||
.size(c.property.borders.right.size)
|
.size(c.property.borders.right._size)
|
||||||
.color(c.property.borders.right.color)
|
.color(c.property.borders.right._color)
|
||||||
.border_type(c.property.borders.right.border_type);
|
.border_type(
|
||||||
|
convertBorderType(c.property.borders.right._border_type)
|
||||||
|
);
|
||||||
cell = cell.set_border(border);
|
cell = cell.set_border(border);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c.property.borders.bottom) {
|
if (c.property.borders.bottom) {
|
||||||
const border = wasm
|
const border = wasm
|
||||||
.createTableCellBorder(wasm.BorderPosition.Bottom)
|
.createTableCellBorder(wasm.BorderPosition.Bottom)
|
||||||
.size(c.property.borders.bottom.size)
|
.size(c.property.borders.bottom._size)
|
||||||
.color(c.property.borders.bottom.color)
|
.color(c.property.borders.bottom._color)
|
||||||
.border_type(c.property.borders.bottom.border_type);
|
.border_type(
|
||||||
|
convertBorderType(c.property.borders.bottom._border_type)
|
||||||
|
);
|
||||||
cell = cell.set_border(border);
|
cell = cell.set_border(border);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c.property.borders.left) {
|
if (c.property.borders.left) {
|
||||||
const border = wasm
|
const border = wasm
|
||||||
.createTableCellBorder(wasm.BorderPosition.Left)
|
.createTableCellBorder(wasm.BorderPosition.Left)
|
||||||
.size(c.property.borders.left.size)
|
.size(c.property.borders.left._size)
|
||||||
.color(c.property.borders.left.color)
|
.color(c.property.borders.left._color)
|
||||||
.border_type(c.property.borders.left.border_type);
|
.border_type(convertBorderType(c.property.borders.left._border_type));
|
||||||
cell = cell.set_border(border);
|
cell = cell.set_border(border);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c.property.borders.insideH) {
|
if (c.property.borders.insideH) {
|
||||||
const border = wasm
|
const border = wasm
|
||||||
.createTableCellBorder(wasm.BorderPosition.InsideH)
|
.createTableCellBorder(wasm.BorderPosition.InsideH)
|
||||||
.size(c.property.borders.insideH.size)
|
.size(c.property.borders.insideH._size)
|
||||||
.color(c.property.borders.insideH.color)
|
.color(c.property.borders.insideH._color)
|
||||||
.border_type(c.property.borders.insideH.border_type);
|
.border_type(
|
||||||
|
convertBorderType(c.property.borders.insideH._border_type)
|
||||||
|
);
|
||||||
cell = cell.set_border(border);
|
cell = cell.set_border(border);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c.property.borders.insideV) {
|
if (c.property.borders.insideV) {
|
||||||
const border = wasm
|
const border = wasm
|
||||||
.createTableCellBorder(wasm.BorderPosition.InsideV)
|
.createTableCellBorder(wasm.BorderPosition.InsideV)
|
||||||
.size(c.property.borders.insideV.size)
|
.size(c.property.borders.insideV._size)
|
||||||
.color(c.property.borders.insideV.color)
|
.color(c.property.borders.insideV._color)
|
||||||
.border_type(c.property.borders.insideV.border_type);
|
.border_type(
|
||||||
|
convertBorderType(c.property.borders.insideV._border_type)
|
||||||
|
);
|
||||||
cell = cell.set_border(border);
|
cell = cell.set_border(border);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,13 @@
|
||||||
import { BorderPosition, TableCellBorder } from "./table-cell-border";
|
import { BorderPosition, TableCellBorder } from "./table-cell-border";
|
||||||
|
|
||||||
|
export type PositionKeys =
|
||||||
|
| "top"
|
||||||
|
| "left"
|
||||||
|
| "bottom"
|
||||||
|
| "right"
|
||||||
|
| "insideH"
|
||||||
|
| "insideV";
|
||||||
|
|
||||||
export class TableCellBorders {
|
export class TableCellBorders {
|
||||||
top: TableCellBorder | null = new TableCellBorder("Top");
|
top: TableCellBorder | null = new TableCellBorder("Top");
|
||||||
left: TableCellBorder | null = new TableCellBorder("Left");
|
left: TableCellBorder | null = new TableCellBorder("Left");
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { Paragraph } from "./paragraph";
|
import { Paragraph } from "./paragraph";
|
||||||
import { TableCellBorders } from "./table-cell-borders";
|
import { TableCellBorders, PositionKeys } from "./table-cell-borders";
|
||||||
import { BorderPosition, TableCellBorder } from "./table-cell-border";
|
import { BorderPosition, TableCellBorder } from "./table-cell-border";
|
||||||
|
|
||||||
export type VMergeType = "restart" | "continue";
|
export type VMergeType = "restart" | "continue";
|
||||||
|
@ -7,7 +7,7 @@ export type VMergeType = "restart" | "continue";
|
||||||
export type VAlignType = "top" | "center" | "bottom";
|
export type VAlignType = "top" | "center" | "bottom";
|
||||||
|
|
||||||
export type CellProperty = {
|
export type CellProperty = {
|
||||||
borders?: TableCellBorders;
|
borders: TableCellBorders;
|
||||||
verticalMerge?: VMergeType;
|
verticalMerge?: VMergeType;
|
||||||
verticalAlign?: VAlignType;
|
verticalAlign?: VAlignType;
|
||||||
gridSpan?: number;
|
gridSpan?: number;
|
||||||
|
@ -16,7 +16,9 @@ export type CellProperty = {
|
||||||
|
|
||||||
export class TableCell {
|
export class TableCell {
|
||||||
children: Paragraph[] = [];
|
children: Paragraph[] = [];
|
||||||
property: CellProperty = {};
|
property: CellProperty = {
|
||||||
|
borders: new TableCellBorders(),
|
||||||
|
};
|
||||||
|
|
||||||
addParagraph(p: Paragraph) {
|
addParagraph(p: Paragraph) {
|
||||||
this.children.push(p);
|
this.children.push(p);
|
||||||
|
@ -44,14 +46,14 @@ export class TableCell {
|
||||||
}
|
}
|
||||||
|
|
||||||
setBorder(position: BorderPosition, border: TableCellBorder) {
|
setBorder(position: BorderPosition, border: TableCellBorder) {
|
||||||
this.property.borders[position] = border;
|
this.property.borders[position.toLowerCase() as PositionKeys] = border;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
clearBorder(position: BorderPosition) {
|
clearBorder(position: BorderPosition) {
|
||||||
this.property.borders[position] = new TableCellBorder(position).border_type(
|
this.property.borders[
|
||||||
"Nil"
|
position.toLowerCase() as PositionKeys
|
||||||
);
|
] = new TableCellBorder(position).border_type("Nil");
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "docx-wasm",
|
"name": "docx-wasm",
|
||||||
"version": "0.0.62",
|
"version": "0.0.63",
|
||||||
"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>",
|
||||||
|
|
|
@ -17,6 +17,11 @@ impl TableCellBorder {
|
||||||
|
|
||||||
#[wasm_bindgen]
|
#[wasm_bindgen]
|
||||||
impl TableCellBorder {
|
impl TableCellBorder {
|
||||||
|
pub fn size(mut self, size: usize) -> TableCellBorder {
|
||||||
|
self.0.size = size;
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
pub fn color(mut self, color: String) -> TableCellBorder {
|
pub fn color(mut self, color: String) -> TableCellBorder {
|
||||||
self.0.color = color;
|
self.0.color = color;
|
||||||
self
|
self
|
||||||
|
@ -26,4 +31,16 @@ impl TableCellBorder {
|
||||||
self.0.border_type = border_type;
|
self.0.border_type = border_type;
|
||||||
self
|
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