2018-05-06 22:20:56 -05:00
|
|
|
// http://officeopenxml.com/WPhyperlink.php
|
2021-03-12 03:58:05 +00:00
|
|
|
import { uniqueId } from "convenience-functions";
|
2018-05-06 22:20:56 -05:00
|
|
|
import { XmlComponent } from "file/xml-components";
|
2021-02-27 19:23:29 +00:00
|
|
|
|
|
|
|
import { ParagraphChild } from "../paragraph";
|
2018-07-24 15:56:13 -04:00
|
|
|
import { HyperlinkAttributes, IHyperlinkAttributesProperties } from "./hyperlink-attributes";
|
2018-05-06 22:20:56 -05:00
|
|
|
|
2019-12-21 03:31:09 +00:00
|
|
|
export enum HyperlinkType {
|
|
|
|
INTERNAL = "INTERNAL",
|
|
|
|
EXTERNAL = "EXTERNAL",
|
|
|
|
}
|
|
|
|
|
2021-02-27 19:23:29 +00:00
|
|
|
export class ConcreteHyperlink extends XmlComponent {
|
2019-11-08 10:50:18 +01:00
|
|
|
public readonly linkId: string;
|
2018-05-06 22:20:56 -05:00
|
|
|
|
2021-08-27 16:53:11 -06:00
|
|
|
constructor(children: ParagraphChild[], relationshipId: string, anchor?: string) {
|
2018-05-06 22:20:56 -05:00
|
|
|
super("w:hyperlink");
|
|
|
|
|
2019-11-08 10:50:18 +01:00
|
|
|
this.linkId = relationshipId;
|
2018-07-24 15:56:13 -04:00
|
|
|
|
|
|
|
const props: IHyperlinkAttributesProperties = {
|
2018-05-06 22:20:56 -05:00
|
|
|
history: 1,
|
2018-11-02 02:51:57 +00:00
|
|
|
anchor: anchor ? anchor : undefined,
|
|
|
|
id: !anchor ? `rId${this.linkId}` : undefined,
|
2018-07-24 15:56:13 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
const attributes = new HyperlinkAttributes(props);
|
2018-05-06 23:18:00 -05:00
|
|
|
this.root.push(attributes);
|
2021-08-27 16:53:11 -06:00
|
|
|
children.forEach((child) => {
|
|
|
|
this.root.push(child);
|
|
|
|
});
|
2019-02-26 13:26:01 +01:00
|
|
|
}
|
2021-02-27 19:23:29 +00:00
|
|
|
}
|
2019-02-26 13:26:01 +01:00
|
|
|
|
2021-02-27 19:23:29 +00:00
|
|
|
export class InternalHyperlink extends ConcreteHyperlink {
|
2021-08-31 19:54:33 -06:00
|
|
|
constructor(options: { readonly children: ParagraphChild[]; readonly anchor: string }) {
|
|
|
|
super(options.children, uniqueId(), options.anchor);
|
2018-05-06 22:20:56 -05:00
|
|
|
}
|
|
|
|
}
|
2021-02-27 19:23:29 +00:00
|
|
|
|
|
|
|
export class ExternalHyperlink {
|
2021-08-27 16:53:11 -06:00
|
|
|
constructor(public readonly options: { readonly children: ParagraphChild[]; readonly link: string }) {}
|
2021-02-27 19:23:29 +00:00
|
|
|
}
|