@salesforcedevs/docs-components 0.53.6 → 0.54.0-alpha01

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,119 @@
1
+ export type CoveoAdvancedQueryXMLConfig = {
2
+ objecttype?: string;
3
+ sflocale__c?: string;
4
+ sfrelease__c?: string;
5
+ sfdelivarable__c?: string;
6
+ source?: string;
7
+ };
8
+
9
+ export type PageReference = {
10
+ domain?: string;
11
+ page?: string;
12
+ docId?: string;
13
+ deliverable?: string;
14
+ contentDocumentId?: string;
15
+ hash?: string;
16
+ search?: string;
17
+ };
18
+
19
+ export enum HistoryState {
20
+ PUSH_STATE = "pushState",
21
+ REPLACE_STATE = "replaceState"
22
+ }
23
+
24
+ export type Labels = {
25
+ language_english: string;
26
+ language_japanese: string;
27
+ toc_title: string;
28
+ };
29
+
30
+ export type TreeNode = {
31
+ label: string;
32
+ name: string;
33
+ children?: Array<TreeNode>;
34
+ isExpanded?: boolean;
35
+ };
36
+
37
+ type DropdownOption = {
38
+ id: string;
39
+ label: string;
40
+ };
41
+
42
+ export type DocVersion = DropdownOption & {
43
+ releaseVersion: string;
44
+ url: string;
45
+ };
46
+
47
+ export type DocLanguage = DropdownOption & {
48
+ code: string;
49
+ url: string;
50
+ };
51
+
52
+ export type ApiDocVersion = {
53
+ version_text: string;
54
+ release_version: string;
55
+ doc_version: string;
56
+ version_url: string;
57
+ };
58
+
59
+ export type ApiDocLanguage = {
60
+ code: string;
61
+ label: string;
62
+ locale: string;
63
+ url: string;
64
+ };
65
+
66
+ export interface Header extends Element {
67
+ subtitle: string;
68
+ bailHref: string;
69
+ bailLabel: string;
70
+ languages: Array<DocLanguage>;
71
+ language: string;
72
+ headerHref: string;
73
+ }
74
+
75
+ export type ApiNavItem = {
76
+ children: Array<ApiNavItem>;
77
+ text: string;
78
+ a_attr: {
79
+ href: string;
80
+ };
81
+ id: string;
82
+ };
83
+
84
+ export type ApiDocData = {
85
+ available_languages: Array<ApiDocLanguage>;
86
+ available_versions: Array<ApiDocVersion>;
87
+ content: string;
88
+ content_document_id: string;
89
+ deliverable: string;
90
+ doc_title: string;
91
+ language: ApiDocLanguage;
92
+ title: string;
93
+ toc: Array<ApiNavItem>;
94
+ version: ApiDocVersion;
95
+ pdf_url: string;
96
+ };
97
+
98
+ export type ContentData = {
99
+ content: string;
100
+ id: string;
101
+ title: string;
102
+ };
103
+
104
+ export type DocumentData = ContentData & {
105
+ availableLanguages: Array<DocLanguage>;
106
+ availableVersions: Array<DocVersion>;
107
+ deliverable: string;
108
+ docTitle: string;
109
+ language: DocLanguage;
110
+ toc: Array<TreeNode>;
111
+ tocMap: { [key: string]: TreeNode };
112
+ version: DocVersion;
113
+ pdfUrl: string;
114
+ };
115
+
116
+ export type ContentApiOptions = {
117
+ version: string;
118
+ language: string;
119
+ };
@@ -0,0 +1,163 @@
1
+ import {
2
+ ApiDocData,
3
+ ApiDocLanguage,
4
+ ApiDocVersion,
5
+ ApiNavItem,
6
+ ContentApiOptions,
7
+ ContentData,
8
+ DocumentData,
9
+ DocLanguage,
10
+ DocVersion,
11
+ Labels,
12
+ TreeNode
13
+ } from "./types";
14
+
15
+ const LOCALE_TO_LABEL = {
16
+ "en-us": "language_english",
17
+ "ja-jp": "language_japanese"
18
+ };
19
+
20
+ export class FetchContent {
21
+ private apiDomain: string;
22
+ private labels: Labels;
23
+
24
+ constructor(apiDomain: string, labels: Labels) {
25
+ this.apiDomain = apiDomain;
26
+ this.labels = labels;
27
+ }
28
+
29
+ async fetchDocumentData(docId: string): Promise<DocumentData | null> {
30
+ try {
31
+ const {
32
+ available_languages,
33
+ available_versions,
34
+ toc,
35
+ content,
36
+ version,
37
+ language,
38
+ content_document_id,
39
+ title,
40
+ doc_title,
41
+ pdf_url,
42
+ deliverable
43
+ } = await this.fetchResource<ApiDocData>(
44
+ `${this.apiDomain}/docs/get_document/${docId}`
45
+ );
46
+
47
+ const { normalizedToc, tocMap } = this.normalizeToc(toc);
48
+ return {
49
+ availableLanguages:
50
+ available_languages &&
51
+ available_languages.map(this.normalizeLanguage.bind(this)),
52
+ availableVersions:
53
+ available_versions &&
54
+ available_versions.map(this.normalizeVersion.bind(this)),
55
+ content,
56
+ version: this.normalizeVersion(version),
57
+ id: content_document_id,
58
+ language: this.normalizeLanguage(language),
59
+ title,
60
+ toc: normalizedToc,
61
+ tocMap,
62
+ docTitle: doc_title,
63
+ pdfUrl: pdf_url,
64
+ deliverable
65
+ };
66
+ } catch (error) {
67
+ console.log(error);
68
+ return null;
69
+ }
70
+ }
71
+
72
+ fetchContent(
73
+ deliverable: string,
74
+ contentId: string,
75
+ options: ContentApiOptions
76
+ ): Promise<ContentData> {
77
+ return this.fetchResource<ContentData>(
78
+ `${this.apiDomain}/docs/get_document_content/${deliverable}/${contentId}/${options.language}/${options.version}`
79
+ );
80
+ }
81
+
82
+ private async fetchResource<T>(url: string): Promise<T> {
83
+ const response = await fetch(url);
84
+ if (!response.ok) {
85
+ throw new Error(response.statusText);
86
+ }
87
+
88
+ const json = await response.json();
89
+
90
+ return json;
91
+ }
92
+
93
+ private normalizeToc(apiToc: Array<ApiNavItem>): {
94
+ tocMap: { [key: string]: TreeNode };
95
+ normalizedToc: Array<TreeNode>;
96
+ } {
97
+ const tocMap = {};
98
+ const normalizedToc =
99
+ apiToc &&
100
+ apiToc.map((navItem) => this.normalizeNavItem(navItem, tocMap));
101
+
102
+ return { normalizedToc, tocMap };
103
+ }
104
+
105
+ private normalizeNavItem(
106
+ navItem: ApiNavItem,
107
+ tocMap: { [key: string]: TreeNode }
108
+ ): TreeNode {
109
+ const name = this.calculateNavItemName(navItem, tocMap);
110
+ const node: TreeNode = {
111
+ label: navItem.text,
112
+ name
113
+ };
114
+ if (name) {
115
+ tocMap[name] = node;
116
+ }
117
+ node.children = navItem.children?.map((child) =>
118
+ this.normalizeNavItem(child, tocMap)
119
+ );
120
+ return node;
121
+ }
122
+
123
+ private calculateNavItemName(
124
+ navItem: ApiNavItem,
125
+ tocMap: { [key: string]: TreeNode }
126
+ ): string {
127
+ let href = navItem.a_attr?.href || "";
128
+ if (href.includes("#")) {
129
+ const [pathUrl] = href.split("#");
130
+ href = pathUrl in tocMap ? href : pathUrl;
131
+ }
132
+ return href || navItem.id;
133
+ }
134
+
135
+ private normalizeVersion(version: ApiDocVersion): DocVersion {
136
+ return (
137
+ version && {
138
+ label: version.version_text,
139
+ releaseVersion:
140
+ version.release_version &&
141
+ !version.release_version.startsWith("v")
142
+ ? `v${version.release_version}`
143
+ : version.release_version,
144
+ id: version.doc_version,
145
+ url: version.version_url
146
+ }
147
+ );
148
+ }
149
+
150
+ private normalizeLanguage(language: ApiDocLanguage): DocLanguage {
151
+ const labelKey = language.locale && LOCALE_TO_LABEL[language.locale];
152
+ return (
153
+ language && {
154
+ label:
155
+ (labelKey && this.labels && this.labels[labelKey]) ||
156
+ language.label,
157
+ id: language.locale,
158
+ code: language.code,
159
+ url: language.url
160
+ }
161
+ );
162
+ }
163
+ }
@@ -0,0 +1,25 @@
1
+ :host {
2
+ --button-primary-color: var(--dx-g-blue-vibrant-50);
3
+ --button-primary-color-hover: var(--dx-g-blue-vibrant-40);
4
+ }
5
+
6
+ dx-dropdown {
7
+ --dx-c-dropdown-option-font-size: var(--dx-g-text-sm);
8
+ }
9
+
10
+ dx-dropdown > dx-button {
11
+ --dx-c-button-primary-color: var(--button-primary-color);
12
+ --dx-c-button-primary-color-hover: var(--button-primary-color-hover);
13
+ --border-color: var(--button-primary-color);
14
+
15
+ border-bottom: 1px dashed var(--border-color);
16
+ }
17
+
18
+ dx-dropdown > dx-button:hover {
19
+ --border-color: var(--button-primary-color-hover);
20
+ }
21
+
22
+ .document-pickers {
23
+ margin-left: auto;
24
+ margin-right: var(--dx-g-spacing-sm);
25
+ }
@@ -0,0 +1,34 @@
1
+ <template>
2
+ <doc-content-layout
3
+ if:true={loaded}
4
+ coveo-organization-id={coveoOrganizationId}
5
+ coveo-public-access-token={coveoPublicAccessToken}
6
+ coveo-search-hub="Developer_Docs_SS"
7
+ coveo-advanced-query-config={coveoAdvancedQueryConfig}
8
+ sidebar-header="Pages"
9
+ sidebar-content={sidebarContent}
10
+ sidebar-value={sidebarValue}
11
+ onselect={handleSelect}
12
+ use-old-sidebar
13
+ >
14
+ <div slot="sidebar-header" class="document-pickers">
15
+ <dx-dropdown
16
+ data-type="version"
17
+ suppress-gtm-nav-headings
18
+ analytics-event={analyticsEvent}
19
+ options={versionOptions}
20
+ value={version.id}
21
+ width="290px"
22
+ >
23
+ <dx-button variant="inline" disabled={disableVersion}>
24
+ {version.releaseVersion}
25
+ </dx-button>
26
+ </dx-dropdown>
27
+ </div>
28
+ <doc-content
29
+ docs-data={docContent}
30
+ page-reference={pageReference}
31
+ onnavclick={handleNavClick}
32
+ ></doc-content>
33
+ </doc-content-layout>
34
+ </template>