import * as ko from "knockout"; import { PageContract } from "@paperbits/common/pages/pageContract"; import { HyperlinkModel } from "@paperbits/common/permalinks"; import { SocialShareData } from "@paperbits/common/pages/socialShareData"; import { NavigationTarget } from "@paperbits/common/html"; export class AnchorItem { public title: string; public shortTitle: string; public elementId: string; public isSelected: ko.Observable; constructor() { this.isSelected = ko.observable(); } } export class PageItem { public key: string; public contentKey?: string; public readonly permalink: ko.Observable; public readonly title: ko.Observable; public readonly description: ko.Observable; public readonly keywords: ko.Observable; public readonly jsonLd: ko.Observable; public readonly socialShareData: ko.Observable; public readonly anchorsLoaded: ko.Observable; public readonly anchors: ko.ObservableArray; public selectedAnchor?: AnchorItem; constructor(page: PageContract) { this.contentKey = page.contentKey; this.key = page.key; this.title = ko.observable(page.title); this.description = ko.observable(page.description); this.keywords = ko.observable(page.keywords); this.jsonLd = ko.observable(page.jsonLd); this.permalink = ko.observable(page.permalink); this.anchors = ko.observableArray(); this.socialShareData = ko.observable(page.socialShareData); this.anchorsLoaded = ko.observable(false); } public getHyperlink(): HyperlinkModel { const hyperlinkModel = new HyperlinkModel(); hyperlinkModel.title = this.title(); hyperlinkModel.target = NavigationTarget.Self; hyperlinkModel.targetKey = this.key; hyperlinkModel.href = this.permalink(); if (this.selectedAnchor) { hyperlinkModel.anchor = this.selectedAnchor.elementId; hyperlinkModel.anchorName = this.selectedAnchor.shortTitle; } return hyperlinkModel; } public toContract(): PageContract { return { key: this.key, title: this.title(), description: this.description(), keywords: this.keywords(), jsonLd: this.jsonLd(), contentKey: this.contentKey, permalink: this.permalink(), socialShareData: this.socialShareData() }; } }