Merge pull request #310 from nickgeorgiou/feat/margin-spelling-fix
Fix spelling of "margin"
This commit is contained in:
@ -25,7 +25,7 @@ table = doc.createTable({
|
|||||||
table
|
table
|
||||||
.getCell(0, 0)
|
.getCell(0, 0)
|
||||||
.addParagraph(new Paragraph("World"))
|
.addParagraph(new Paragraph("World"))
|
||||||
.setMargains({
|
.setMargins({
|
||||||
top: 1000,
|
top: 1000,
|
||||||
bottom: 1000,
|
bottom: 1000,
|
||||||
left: 1000,
|
left: 1000,
|
||||||
@ -40,7 +40,7 @@ table = doc.createTable({
|
|||||||
columns: 4,
|
columns: 4,
|
||||||
width: 7000,
|
width: 7000,
|
||||||
widthUnitType: WidthType.DXA,
|
widthUnitType: WidthType.DXA,
|
||||||
margains: {
|
margins: {
|
||||||
top: 400,
|
top: 400,
|
||||||
bottom: 400,
|
bottom: 400,
|
||||||
right: 400,
|
right: 400,
|
||||||
|
@ -112,7 +112,7 @@ _Source: https://github.com/dolanmiu/docx/blob/master/demo/demo18.ts_
|
|||||||
|
|
||||||
## Margins
|
## Margins
|
||||||
|
|
||||||
Example showing how to set custom margains
|
Example showing how to set custom margins
|
||||||
|
|
||||||
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo6.ts ':include')
|
[Example](https://raw.githubusercontent.com/dolanmiu/docx/master/demo/demo6.ts ':include')
|
||||||
|
|
||||||
|
@ -1,21 +0,0 @@
|
|||||||
// http://officeopenxml.com/WPtableCellProperties-Margins.php
|
|
||||||
import { XmlComponent } from "file/xml-components";
|
|
||||||
|
|
||||||
import { BottomCellMargain, LeftCellMargain, RightCellMargain, TopCellMargain } from "./cell-margain";
|
|
||||||
|
|
||||||
export interface ITableCellMargainOptions {
|
|
||||||
readonly top?: number;
|
|
||||||
readonly left?: number;
|
|
||||||
readonly bottom?: number;
|
|
||||||
readonly right?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class TableCellMargain extends XmlComponent {
|
|
||||||
constructor({ top = 0, left = 0, right = 0, bottom = 0 }: ITableCellMargainOptions) {
|
|
||||||
super("w:tcMar");
|
|
||||||
this.root.push(new TopCellMargain(top));
|
|
||||||
this.root.push(new BottomCellMargain(bottom));
|
|
||||||
this.root.push(new RightCellMargain(right));
|
|
||||||
this.root.push(new LeftCellMargain(left));
|
|
||||||
}
|
|
||||||
}
|
|
@ -2,13 +2,13 @@ import { expect } from "chai";
|
|||||||
|
|
||||||
import { Formatter } from "export/formatter";
|
import { Formatter } from "export/formatter";
|
||||||
|
|
||||||
import { BottomCellMargain, LeftCellMargain, RightCellMargain, TopCellMargain } from "./cell-margain";
|
import { BottomCellMargin, LeftCellMargin, RightCellMargin, TopCellMargin } from "./cell-margin";
|
||||||
|
|
||||||
describe("TopCellMargain", () => {
|
describe("TopCellMargin", () => {
|
||||||
describe("#constructor", () => {
|
describe("#constructor", () => {
|
||||||
it("should create", () => {
|
it("should create", () => {
|
||||||
const cellMargain = new TopCellMargain(1);
|
const cellMargin = new TopCellMargin(1);
|
||||||
const tree = new Formatter().format(cellMargain);
|
const tree = new Formatter().format(cellMargin);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:top": {
|
"w:top": {
|
||||||
_attr: {
|
_attr: {
|
||||||
@ -21,11 +21,11 @@ describe("TopCellMargain", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("BottomCellMargain", () => {
|
describe("BottomCellMargin", () => {
|
||||||
describe("#constructor", () => {
|
describe("#constructor", () => {
|
||||||
it("should create", () => {
|
it("should create", () => {
|
||||||
const cellMargain = new BottomCellMargain(1);
|
const cellMargin = new BottomCellMargin(1);
|
||||||
const tree = new Formatter().format(cellMargain);
|
const tree = new Formatter().format(cellMargin);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:bottom": {
|
"w:bottom": {
|
||||||
_attr: {
|
_attr: {
|
||||||
@ -38,11 +38,11 @@ describe("BottomCellMargain", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("LeftCellMargain", () => {
|
describe("LeftCellMargin", () => {
|
||||||
describe("#constructor", () => {
|
describe("#constructor", () => {
|
||||||
it("should create", () => {
|
it("should create", () => {
|
||||||
const cellMargain = new LeftCellMargain(1);
|
const cellMargin = new LeftCellMargin(1);
|
||||||
const tree = new Formatter().format(cellMargain);
|
const tree = new Formatter().format(cellMargin);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:start": {
|
"w:start": {
|
||||||
_attr: {
|
_attr: {
|
||||||
@ -55,11 +55,11 @@ describe("LeftCellMargain", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("RightCellMargain", () => {
|
describe("RightCellMargin", () => {
|
||||||
describe("#constructor", () => {
|
describe("#constructor", () => {
|
||||||
it("should create", () => {
|
it("should create", () => {
|
||||||
const cellMargain = new RightCellMargain(1);
|
const cellMargin = new RightCellMargin(1);
|
||||||
const tree = new Formatter().format(cellMargain);
|
const tree = new Formatter().format(cellMargin);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:end": {
|
"w:end": {
|
||||||
_attr: {
|
_attr: {
|
@ -1,21 +1,21 @@
|
|||||||
// http://officeopenxml.com/WPtableCellProperties-Margins.php
|
// http://officeopenxml.com/WPtableCellProperties-Margins.php
|
||||||
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
import { XmlAttributeComponent, XmlComponent } from "file/xml-components";
|
||||||
|
|
||||||
export interface ICellMargainProperties {
|
export interface ICellMarginProperties {
|
||||||
readonly type: string;
|
readonly type: string;
|
||||||
readonly width: number;
|
readonly width: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
class CellMargainAttributes extends XmlAttributeComponent<ICellMargainProperties> {
|
class CellMarginAttributes extends XmlAttributeComponent<ICellMarginProperties> {
|
||||||
protected readonly xmlKeys = { width: "w:w", type: "w:type" };
|
protected readonly xmlKeys = { width: "w:w", type: "w:type" };
|
||||||
}
|
}
|
||||||
|
|
||||||
export class TopCellMargain extends XmlComponent {
|
export class TopCellMargin extends XmlComponent {
|
||||||
constructor(value: number) {
|
constructor(value: number) {
|
||||||
super("w:top");
|
super("w:top");
|
||||||
|
|
||||||
this.root.push(
|
this.root.push(
|
||||||
new CellMargainAttributes({
|
new CellMarginAttributes({
|
||||||
width: value,
|
width: value,
|
||||||
type: "dxa",
|
type: "dxa",
|
||||||
}),
|
}),
|
||||||
@ -23,12 +23,12 @@ export class TopCellMargain extends XmlComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class BottomCellMargain extends XmlComponent {
|
export class BottomCellMargin extends XmlComponent {
|
||||||
constructor(value: number) {
|
constructor(value: number) {
|
||||||
super("w:bottom");
|
super("w:bottom");
|
||||||
|
|
||||||
this.root.push(
|
this.root.push(
|
||||||
new CellMargainAttributes({
|
new CellMarginAttributes({
|
||||||
width: value,
|
width: value,
|
||||||
type: "dxa",
|
type: "dxa",
|
||||||
}),
|
}),
|
||||||
@ -36,12 +36,12 @@ export class BottomCellMargain extends XmlComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class LeftCellMargain extends XmlComponent {
|
export class LeftCellMargin extends XmlComponent {
|
||||||
constructor(value: number) {
|
constructor(value: number) {
|
||||||
super("w:start");
|
super("w:start");
|
||||||
|
|
||||||
this.root.push(
|
this.root.push(
|
||||||
new CellMargainAttributes({
|
new CellMarginAttributes({
|
||||||
width: value,
|
width: value,
|
||||||
type: "dxa",
|
type: "dxa",
|
||||||
}),
|
}),
|
||||||
@ -49,12 +49,12 @@ export class LeftCellMargain extends XmlComponent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class RightCellMargain extends XmlComponent {
|
export class RightCellMargin extends XmlComponent {
|
||||||
constructor(value: number) {
|
constructor(value: number) {
|
||||||
super("w:end");
|
super("w:end");
|
||||||
|
|
||||||
this.root.push(
|
this.root.push(
|
||||||
new CellMargainAttributes({
|
new CellMarginAttributes({
|
||||||
width: value,
|
width: value,
|
||||||
type: "dxa",
|
type: "dxa",
|
||||||
}),
|
}),
|
@ -2,13 +2,13 @@ import { expect } from "chai";
|
|||||||
|
|
||||||
import { Formatter } from "export/formatter";
|
import { Formatter } from "export/formatter";
|
||||||
|
|
||||||
import { TableCellMargain } from "./table-cell-margains";
|
import { TableCellMargin } from "./table-cell-margins";
|
||||||
|
|
||||||
describe("TableCellMargain", () => {
|
describe("TableCellMargin", () => {
|
||||||
describe("#constructor", () => {
|
describe("#constructor", () => {
|
||||||
it("should create with default values", () => {
|
it("should create with default values", () => {
|
||||||
const cellMargain = new TableCellMargain({});
|
const cellMargin = new TableCellMargin({});
|
||||||
const tree = new Formatter().format(cellMargain);
|
const tree = new Formatter().format(cellMargin);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:tcMar": [
|
"w:tcMar": [
|
||||||
{
|
{
|
||||||
@ -48,13 +48,13 @@ describe("TableCellMargain", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should create with values", () => {
|
it("should create with values", () => {
|
||||||
const cellMargain = new TableCellMargain({
|
const cellMargin = new TableCellMargin({
|
||||||
top: 5,
|
top: 5,
|
||||||
bottom: 5,
|
bottom: 5,
|
||||||
left: 5,
|
left: 5,
|
||||||
right: 5,
|
right: 5,
|
||||||
});
|
});
|
||||||
const tree = new Formatter().format(cellMargain);
|
const tree = new Formatter().format(cellMargin);
|
||||||
expect(tree).to.deep.equal({
|
expect(tree).to.deep.equal({
|
||||||
"w:tcMar": [
|
"w:tcMar": [
|
||||||
{
|
{
|
21
src/file/table/table-cell/cell-margin/table-cell-margins.ts
Normal file
21
src/file/table/table-cell/cell-margin/table-cell-margins.ts
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
// http://officeopenxml.com/WPtableCellProperties-Margins.php
|
||||||
|
import { XmlComponent } from "file/xml-components";
|
||||||
|
|
||||||
|
import { BottomCellMargin, LeftCellMargin, RightCellMargin, TopCellMargin } from "./cell-margin";
|
||||||
|
|
||||||
|
export interface ITableCellMarginOptions {
|
||||||
|
readonly top?: number;
|
||||||
|
readonly left?: number;
|
||||||
|
readonly bottom?: number;
|
||||||
|
readonly right?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export class TableCellMargin extends XmlComponent {
|
||||||
|
constructor({ top = 0, left = 0, right = 0, bottom = 0 }: ITableCellMarginOptions) {
|
||||||
|
super("w:tcMar");
|
||||||
|
this.root.push(new TopCellMargin(top));
|
||||||
|
this.root.push(new BottomCellMargin(bottom));
|
||||||
|
this.root.push(new RightCellMargin(right));
|
||||||
|
this.root.push(new LeftCellMargin(left));
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,7 @@
|
|||||||
import { IgnoreIfEmptyXmlComponent } from "file/xml-components";
|
import { IgnoreIfEmptyXmlComponent } from "file/xml-components";
|
||||||
|
|
||||||
import { ITableShadingAttributesProperties, TableShading } from "../shading";
|
import { ITableShadingAttributesProperties, TableShading } from "../shading";
|
||||||
import { ITableCellMargainOptions, TableCellMargain } from "./cell-margain/table-cell-margains";
|
import { ITableCellMarginOptions, TableCellMargin } from "./cell-margin/table-cell-margins";
|
||||||
import { GridSpan, TableCellBorders, TableCellWidth, VAlign, VerticalAlign, VMerge, VMergeType, WidthType } from "./table-cell-components";
|
import { GridSpan, TableCellBorders, TableCellWidth, VAlign, VerticalAlign, VMerge, VMergeType, WidthType } from "./table-cell-components";
|
||||||
|
|
||||||
export class TableCellProperties extends IgnoreIfEmptyXmlComponent {
|
export class TableCellProperties extends IgnoreIfEmptyXmlComponent {
|
||||||
@ -47,8 +47,8 @@ export class TableCellProperties extends IgnoreIfEmptyXmlComponent {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public addMargains(options: ITableCellMargainOptions): TableCellProperties {
|
public addMargins(options: ITableCellMarginOptions): TableCellProperties {
|
||||||
this.root.push(new TableCellMargain(options));
|
this.root.push(new TableCellMargin(options));
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ import { IXmlableObject, XmlComponent } from "file/xml-components";
|
|||||||
|
|
||||||
import { ITableShadingAttributesProperties } from "../shading";
|
import { ITableShadingAttributesProperties } from "../shading";
|
||||||
import { Table } from "../table";
|
import { Table } from "../table";
|
||||||
import { ITableCellMargainOptions } from "./cell-margain/table-cell-margains";
|
import { ITableCellMarginOptions } from "./cell-margin/table-cell-margins";
|
||||||
import { TableCellBorders, VerticalAlign, VMergeType } from "./table-cell-components";
|
import { TableCellBorders, VerticalAlign, VMergeType } from "./table-cell-components";
|
||||||
import { TableCellProperties } from "./table-cell-properties";
|
import { TableCellProperties } from "./table-cell-properties";
|
||||||
|
|
||||||
@ -61,8 +61,8 @@ export class TableCell extends XmlComponent {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public setMargains(margains: ITableCellMargainOptions): TableCell {
|
public setMargins(margins: ITableCellMarginOptions): TableCell {
|
||||||
this.properties.addMargains(margains);
|
this.properties.addMargins(margins);
|
||||||
|
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -8,43 +8,43 @@ import { TableCellMargin } from "./table-cell-margin";
|
|||||||
describe("TableCellMargin", () => {
|
describe("TableCellMargin", () => {
|
||||||
describe("#constructor", () => {
|
describe("#constructor", () => {
|
||||||
it("should throw an error if theres no child elements", () => {
|
it("should throw an error if theres no child elements", () => {
|
||||||
const cellMargain = new TableCellMargin();
|
const cellMargin = new TableCellMargin();
|
||||||
expect(() => new Formatter().format(cellMargain)).to.throw();
|
expect(() => new Formatter().format(cellMargin)).to.throw();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#addTopMargin", () => {
|
describe("#addTopMargin", () => {
|
||||||
it("adds a table cell top margin", () => {
|
it("adds a table cell top margin", () => {
|
||||||
const cellMargain = new TableCellMargin();
|
const cellMargin = new TableCellMargin();
|
||||||
cellMargain.addTopMargin(1234, WidthType.DXA);
|
cellMargin.addTopMargin(1234, WidthType.DXA);
|
||||||
const tree = new Formatter().format(cellMargain);
|
const tree = new Formatter().format(cellMargin);
|
||||||
expect(tree).to.deep.equal({ "w:tblCellMar": [{ "w:top": { _attr: { "w:type": "dxa", "w:w": 1234 } } }] });
|
expect(tree).to.deep.equal({ "w:tblCellMar": [{ "w:top": { _attr: { "w:type": "dxa", "w:w": 1234 } } }] });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#addLeftMargin", () => {
|
describe("#addLeftMargin", () => {
|
||||||
it("adds a table cell left margin", () => {
|
it("adds a table cell left margin", () => {
|
||||||
const cellMargain = new TableCellMargin();
|
const cellMargin = new TableCellMargin();
|
||||||
cellMargain.addLeftMargin(1234, WidthType.DXA);
|
cellMargin.addLeftMargin(1234, WidthType.DXA);
|
||||||
const tree = new Formatter().format(cellMargain);
|
const tree = new Formatter().format(cellMargin);
|
||||||
expect(tree).to.deep.equal({ "w:tblCellMar": [{ "w:left": { _attr: { "w:type": "dxa", "w:w": 1234 } } }] });
|
expect(tree).to.deep.equal({ "w:tblCellMar": [{ "w:left": { _attr: { "w:type": "dxa", "w:w": 1234 } } }] });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#addBottomMargin", () => {
|
describe("#addBottomMargin", () => {
|
||||||
it("adds a table cell bottom margin", () => {
|
it("adds a table cell bottom margin", () => {
|
||||||
const cellMargain = new TableCellMargin();
|
const cellMargin = new TableCellMargin();
|
||||||
cellMargain.addBottomMargin(1234, WidthType.DXA);
|
cellMargin.addBottomMargin(1234, WidthType.DXA);
|
||||||
const tree = new Formatter().format(cellMargain);
|
const tree = new Formatter().format(cellMargin);
|
||||||
expect(tree).to.deep.equal({ "w:tblCellMar": [{ "w:bottom": { _attr: { "w:type": "dxa", "w:w": 1234 } } }] });
|
expect(tree).to.deep.equal({ "w:tblCellMar": [{ "w:bottom": { _attr: { "w:type": "dxa", "w:w": 1234 } } }] });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("#addRightMargin", () => {
|
describe("#addRightMargin", () => {
|
||||||
it("adds a table cell right margin", () => {
|
it("adds a table cell right margin", () => {
|
||||||
const cellMargain = new TableCellMargin();
|
const cellMargin = new TableCellMargin();
|
||||||
cellMargain.addRightMargin(1234, WidthType.DXA);
|
cellMargin.addRightMargin(1234, WidthType.DXA);
|
||||||
const tree = new Formatter().format(cellMargain);
|
const tree = new Formatter().format(cellMargin);
|
||||||
expect(tree).to.deep.equal({ "w:tblCellMar": [{ "w:right": { _attr: { "w:type": "dxa", "w:w": 1234 } } }] });
|
expect(tree).to.deep.equal({ "w:tblCellMar": [{ "w:right": { _attr: { "w:type": "dxa", "w:w": 1234 } } }] });
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -22,8 +22,8 @@ export interface ITableOptions {
|
|||||||
readonly width?: number;
|
readonly width?: number;
|
||||||
readonly widthUnitType?: WidthType;
|
readonly widthUnitType?: WidthType;
|
||||||
readonly columnWidths?: number[];
|
readonly columnWidths?: number[];
|
||||||
readonly margains?: {
|
readonly margins?: {
|
||||||
readonly margainUnitType?: WidthType;
|
readonly marginUnitType?: WidthType;
|
||||||
readonly top?: number;
|
readonly top?: number;
|
||||||
readonly bottom?: number;
|
readonly bottom?: number;
|
||||||
readonly right?: number;
|
readonly right?: number;
|
||||||
@ -42,7 +42,7 @@ export class Table extends XmlComponent {
|
|||||||
width = 100,
|
width = 100,
|
||||||
widthUnitType = WidthType.AUTO,
|
widthUnitType = WidthType.AUTO,
|
||||||
columnWidths = Array<number>(columns).fill(100),
|
columnWidths = Array<number>(columns).fill(100),
|
||||||
margains: { margainUnitType, top, bottom, right, left } = { margainUnitType: WidthType.AUTO, top: 0, bottom: 0, right: 0, left: 0 },
|
margins: { marginUnitType, top, bottom, right, left } = { marginUnitType: WidthType.AUTO, top: 0, bottom: 0, right: 0, left: 0 },
|
||||||
float,
|
float,
|
||||||
}: ITableOptions) {
|
}: ITableOptions) {
|
||||||
super("w:tbl");
|
super("w:tbl");
|
||||||
@ -50,10 +50,10 @@ export class Table extends XmlComponent {
|
|||||||
this.root.push(this.properties);
|
this.root.push(this.properties);
|
||||||
this.properties.setBorder();
|
this.properties.setBorder();
|
||||||
this.properties.setWidth(width, widthUnitType);
|
this.properties.setWidth(width, widthUnitType);
|
||||||
this.properties.CellMargin.addBottomMargin(bottom || 0, margainUnitType);
|
this.properties.CellMargin.addBottomMargin(bottom || 0, marginUnitType);
|
||||||
this.properties.CellMargin.addTopMargin(top || 0, margainUnitType);
|
this.properties.CellMargin.addTopMargin(top || 0, marginUnitType);
|
||||||
this.properties.CellMargin.addLeftMargin(left || 0, margainUnitType);
|
this.properties.CellMargin.addLeftMargin(left || 0, marginUnitType);
|
||||||
this.properties.CellMargin.addRightMargin(right || 0, margainUnitType);
|
this.properties.CellMargin.addRightMargin(right || 0, marginUnitType);
|
||||||
const grid = new TableGrid(columnWidths);
|
const grid = new TableGrid(columnWidths);
|
||||||
|
|
||||||
this.root.push(grid);
|
this.root.push(grid);
|
||||||
|
Reference in New Issue
Block a user