FIX: added legacy support for TabStop

This commit is contained in:
Ronit Ramdam BK
2022-10-14 17:01:41 +05:45
parent 629c586014
commit d053baef03

View File

@ -8,8 +8,11 @@ export interface TabStopDefinition {
} }
export class TabStop extends XmlComponent { export class TabStop extends XmlComponent {
public constructor(tabDefs: (TabStopDefinition[] | TabStopDefinition)) { public constructor(tabDefs: (TabStopDefinition[] | TabStopDefinition | TabStopType), position?: number, leader?: LeaderType) {
super("w:tabs"); super("w:tabs");
if (typeof tabDefs === "string"){
this.root.push(new TabStopItem(tabDefs, position, leader));
} else {
if (Array.isArray(tabDefs)) { if (Array.isArray(tabDefs)) {
tabDefs.forEach((function(tabDef) { tabDefs.forEach((function(tabDef) {
this.root.push(new TabStopItem(tabDef)); this.root.push(new TabStopItem(tabDef));
@ -19,6 +22,7 @@ export class TabStop extends XmlComponent {
} }
} }
} }
}
export enum TabStopType { export enum TabStopType {
LEFT = "left", LEFT = "left",
@ -53,8 +57,19 @@ export class TabAttributes extends XmlAttributeComponent<{
} }
export class TabStopItem extends XmlComponent { export class TabStopItem extends XmlComponent {
public constructor(tabDef: TabStopDefinition) { public constructor(tabDef: (TabStopDefinition | TabStopType), position?: number, leader?: LeaderType) {
super("w:tab"); super("w:tab");
if (typeof tabDef === "string") {
if (typeof position === "number")
this.root.push(
new TabAttributes({
val: tabDef,
pos: position,
leader,
}),
);
else throw Error("Undefined position: " + position);
} else {
this.root.push( this.root.push(
new TabAttributes({ new TabAttributes({
val: tabDef.type, val: tabDef.type,
@ -64,3 +79,4 @@ export class TabStopItem extends XmlComponent {
); );
} }
} }
}