Introduce some functional programming techniques
This commit is contained in:
@ -1,23 +1,23 @@
|
||||
import { XmlAttributeComponent } from "file/xml-components";
|
||||
|
||||
export interface IBookmarkStartAttributesProperties {
|
||||
id: string;
|
||||
name: string;
|
||||
readonly id: string;
|
||||
readonly name: string;
|
||||
}
|
||||
|
||||
export class BookmarkStartAttributes extends XmlAttributeComponent<IBookmarkStartAttributesProperties> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
id: "w:id",
|
||||
name: "w:name",
|
||||
};
|
||||
}
|
||||
|
||||
export interface IBookmarkEndAttributesProperties {
|
||||
id: string;
|
||||
readonly id: string;
|
||||
}
|
||||
|
||||
export class BookmarkEndAttributes extends XmlAttributeComponent<IBookmarkEndAttributesProperties> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
id: "w:id",
|
||||
};
|
||||
}
|
||||
|
@ -1,16 +1,12 @@
|
||||
// http://officeopenxml.com/WPbookmark.php
|
||||
|
||||
import { XmlComponent } from "file/xml-components";
|
||||
import { TextRun } from "../run";
|
||||
import { BookmarkEndAttributes, BookmarkStartAttributes } from "./bookmark-attributes";
|
||||
|
||||
export class Bookmark {
|
||||
public linkId: number;
|
||||
|
||||
public readonly linkId: number;
|
||||
public readonly start: BookmarkStart;
|
||||
|
||||
public readonly text: TextRun;
|
||||
|
||||
public readonly end: BookmarkEnd;
|
||||
|
||||
constructor(name: string, text: string, relationshipsCount: number) {
|
||||
@ -23,7 +19,7 @@ export class Bookmark {
|
||||
}
|
||||
|
||||
export class BookmarkStart extends XmlComponent {
|
||||
public linkId: number;
|
||||
public readonly linkId: number;
|
||||
|
||||
constructor(name: string, relationshipsCount: number) {
|
||||
super("w:bookmarkStart");
|
||||
@ -39,7 +35,7 @@ export class BookmarkStart extends XmlComponent {
|
||||
}
|
||||
|
||||
export class BookmarkEnd extends XmlComponent {
|
||||
public linkId: number;
|
||||
public readonly linkId: number;
|
||||
|
||||
constructor(relationshipsCount: number) {
|
||||
super("w:bookmarkEnd");
|
||||
|
@ -1,13 +1,13 @@
|
||||
import { XmlAttributeComponent } from "file/xml-components";
|
||||
|
||||
export interface IHyperlinkAttributesProperties {
|
||||
id?: string;
|
||||
anchor?: string;
|
||||
history: number;
|
||||
readonly id?: string;
|
||||
readonly anchor?: string;
|
||||
readonly history: number;
|
||||
}
|
||||
|
||||
export class HyperlinkAttributes extends XmlAttributeComponent<IHyperlinkAttributesProperties> {
|
||||
protected xmlKeys = {
|
||||
protected readonly xmlKeys = {
|
||||
id: "r:id",
|
||||
history: "w:history",
|
||||
anchor: "w:anchor",
|
||||
|
@ -1,11 +1,10 @@
|
||||
// http://officeopenxml.com/WPhyperlink.php
|
||||
|
||||
import { XmlComponent } from "file/xml-components";
|
||||
import { TextRun } from "../run";
|
||||
import { HyperlinkAttributes, IHyperlinkAttributesProperties } from "./hyperlink-attributes";
|
||||
|
||||
export class Hyperlink extends XmlComponent {
|
||||
public linkId: number;
|
||||
public readonly linkId: number;
|
||||
|
||||
constructor(text: string, relationshipsCount: number, anchor?: string) {
|
||||
super("w:hyperlink");
|
||||
@ -14,14 +13,10 @@ export class Hyperlink extends XmlComponent {
|
||||
|
||||
const props: IHyperlinkAttributesProperties = {
|
||||
history: 1,
|
||||
anchor: anchor ? anchor : undefined,
|
||||
id: !anchor ? `rId${this.linkId}` : undefined,
|
||||
};
|
||||
|
||||
if (anchor) {
|
||||
props.anchor = anchor;
|
||||
} else {
|
||||
props.id = `rId${this.linkId}`;
|
||||
}
|
||||
|
||||
const attributes = new HyperlinkAttributes(props);
|
||||
this.root.push(attributes);
|
||||
this.root.push(new TextRun(text).style("Hyperlink"));
|
||||
|
Reference in New Issue
Block a user