@salesforcedevs/docs-components 0.54.0 → 0.54.7-alpha

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.
Files changed (40) hide show
  1. package/lwc.config.json +6 -2
  2. package/package.json +12 -4
  3. package/src/modules/README.md +41 -0
  4. package/src/modules/doc/amfReference/amfReference.css +5 -0
  5. package/src/modules/doc/amfReference/amfReference.html +39 -0
  6. package/src/modules/doc/amfReference/amfReference.ts +813 -0
  7. package/src/modules/doc/amfReference/route-meta.ts +22 -0
  8. package/src/modules/doc/amfReference/types.ts +93 -0
  9. package/src/modules/doc/amfReference/utils.ts +669 -0
  10. package/src/modules/doc/amfTopic/amfTopic.css +1 -0
  11. package/src/modules/doc/amfTopic/amfTopic.html +3 -0
  12. package/src/modules/doc/amfTopic/amfTopic.ts +94 -0
  13. package/src/modules/doc/amfTopic/types.ts +54 -0
  14. package/src/modules/doc/amfTopic/utils.ts +130 -0
  15. package/src/modules/doc/breadcrumbItem/breadcrumbItem.css +2 -2
  16. package/src/modules/doc/breadcrumbs/breadcrumbs.css +2 -2
  17. package/src/modules/doc/breadcrumbs/breadcrumbs.ts +3 -3
  18. package/src/modules/doc/content/content.css +4 -4
  19. package/src/modules/doc/content/content.ts +1 -1
  20. package/src/modules/doc/contentCallout/contentCallout.css +4 -4
  21. package/src/modules/doc/contentLayout/contentLayout.css +100 -0
  22. package/src/modules/doc/contentLayout/contentLayout.html +55 -0
  23. package/src/modules/doc/contentLayout/contentLayout.ts +242 -0
  24. package/src/modules/doc/header/header.css +1 -1
  25. package/src/modules/doc/header/header.ts +5 -5
  26. package/src/modules/doc/headingAnchor/headingAnchor.css +1 -1
  27. package/src/modules/doc/headingContent/headingContent.css +1 -1
  28. package/src/modules/doc/phase/phase.css +3 -3
  29. package/src/modules/doc/phase/phase.ts +1 -1
  30. package/src/modules/doc/xmlContent/types.ts +113 -0
  31. package/src/modules/doc/xmlContent/utils.ts +158 -0
  32. package/src/modules/doc/xmlContent/xmlContent.css +25 -0
  33. package/src/modules/doc/xmlContent/xmlContent.html +34 -0
  34. package/src/modules/doc/xmlContent/xmlContent.ts +568 -0
  35. package/src/modules/docBaseElements/lightningElementWithState/lightningElementWithState.ts +93 -0
  36. package/src/modules/docHelpers/amfStyle/amfStyle.css +390 -0
  37. package/src/modules/docHelpers/phaseContentLayout/phaseContentLayout.css +39 -0
  38. package/src/modules/{helpers → docHelpers}/status/status.css +0 -0
  39. package/src/modules/docUtils/SearchSyncer/SearchSyncer.ts +85 -0
  40. package/LICENSE +0 -12
@@ -0,0 +1,242 @@
1
+ import { LightningElement, api, track } from "lwc";
2
+ import { closest } from "kagekiri";
3
+ import { toJson } from "dxUtils/normalizers";
4
+ import { highlightTerms } from "dxUtils/highlight";
5
+ import { SearchSyncer } from "docUtils/SearchSyncer";
6
+
7
+ type AnchorMap = { [key: string]: { intersect: boolean; id: string } };
8
+
9
+ const TOC_HEADER_TAG = "DOC-HEADING";
10
+ const HIGHLIGHTABLE_SELECTOR = [
11
+ "p",
12
+ "h1",
13
+ "h2",
14
+ "h3",
15
+ "h4",
16
+ "h5",
17
+ "h6",
18
+ "li",
19
+ "dl",
20
+ "th",
21
+ "td"
22
+ ].join(",");
23
+
24
+ export default class ContentLayout extends LightningElement {
25
+ @api sidebarValue: string;
26
+ @api sidebarHeader: string;
27
+ @api tocTitle: string;
28
+ @api enableSlotChange = false;
29
+ @api coveoOrganizationId!: string;
30
+ @api coveoPublicAccessToken!: string;
31
+ @api coveoSearchHub!: string;
32
+ @api coveoAdvancedQueryConfig!: string;
33
+ @api useOldSidebar?: boolean = false;
34
+
35
+ @api
36
+ get breadcrumbs() {
37
+ return this._breadcrumbs;
38
+ }
39
+
40
+ set breadcrumbs(value) {
41
+ if (value) {
42
+ this._breadcrumbs = toJson(value);
43
+ }
44
+ }
45
+
46
+ @api
47
+ get sidebarContent() {
48
+ return this._sidebarContent;
49
+ }
50
+
51
+ set sidebarContent(value) {
52
+ this._sidebarContent = toJson(value);
53
+ }
54
+
55
+ @api
56
+ get tocOptions() {
57
+ return this._tocOptions;
58
+ }
59
+
60
+ set tocOptions(value) {
61
+ this._tocOptions = toJson(value);
62
+ }
63
+
64
+ @api
65
+ setSidebarInputValue(searchTerm: string): void {
66
+ this.template.querySelector("dx-sidebar")?.setInputValue(searchTerm);
67
+ }
68
+
69
+ @track
70
+ private _sidebarContent: unknown;
71
+
72
+ private _breadcrumbs = null;
73
+
74
+ @track
75
+ private _tocOptions: Array<unknown>;
76
+
77
+ private anchoredElements: AnchorMap = {};
78
+ private lastScrollPosition: number;
79
+ private observer?: IntersectionObserver;
80
+ private searchSyncer = new SearchSyncer({
81
+ callbacks: {
82
+ onUrlChange: (nextSearchString: string): void => {
83
+ this.updateHighlightsAndSearch(nextSearchString);
84
+ },
85
+ onSearchChange: (nextSearchString: string): void => {
86
+ this.dispatchHighlightChange(
87
+ new URLSearchParams(nextSearchString).get("q") || ""
88
+ );
89
+ }
90
+ },
91
+ eventName: "sidebarsearchchange",
92
+ historyMethod: window.history.pushState,
93
+ searchParam: "q",
94
+ shouldStopPropagation: true,
95
+ target: window
96
+ });
97
+ private tocValue?: string = undefined;
98
+
99
+ get showToc(): boolean {
100
+ return this.tocOptions && this.tocOptions.length > 0;
101
+ }
102
+
103
+ // ? This could be a good default for pathname in dx-breadcrumbs. Using this getter for now as a workaround.
104
+ get pathname(): string {
105
+ return window.location.pathname;
106
+ }
107
+
108
+ connectedCallback(): void {
109
+ const hasParentHighlightListener = closest(
110
+ "doc-xml-content",
111
+ this.template.host
112
+ );
113
+ if (!hasParentHighlightListener) {
114
+ window.addEventListener(
115
+ "highlightedtermchange",
116
+ this.updateHighlighted
117
+ );
118
+ this.searchSyncer.init();
119
+ }
120
+ }
121
+
122
+ disconnectedCallback(): void {
123
+ this.disconnectObserver();
124
+ window.removeEventListener(
125
+ "highlightedtermchange",
126
+ this.updateHighlighted
127
+ );
128
+ this.searchSyncer.dispose();
129
+ }
130
+
131
+ updateHighlighted = (event: Event): void =>
132
+ highlightTerms(
133
+ this.querySelectorAll(HIGHLIGHTABLE_SELECTOR),
134
+ (event as CustomEvent<string>).detail
135
+ );
136
+
137
+ onSlotChange(event: Event): void {
138
+ if (!this.enableSlotChange) {
139
+ return;
140
+ }
141
+
142
+ this.disconnectObserver();
143
+ this.observer = new IntersectionObserver((entries) => {
144
+ entries.forEach(
145
+ (entry) =>
146
+ (this.anchoredElements[
147
+ entry.target.getAttribute("id")
148
+ ].intersect = entry.isIntersecting)
149
+ );
150
+ this.calculateActualSection();
151
+ });
152
+
153
+ const anchoredTags = (event.target as HTMLSlotElement)
154
+ .assignedElements()
155
+ .filter(({ tagName }) => tagName === TOC_HEADER_TAG)
156
+ .map((tag) => {
157
+ tag.id = tag.hash;
158
+ return tag;
159
+ });
160
+
161
+ this._tocOptions = anchoredTags.map((tag) => ({
162
+ anchor: `#${tag.hash}`,
163
+ id: tag.id,
164
+ label: tag.title
165
+ }));
166
+
167
+ this.scrollToHash(anchoredTags);
168
+
169
+ anchoredTags.forEach((section) => {
170
+ const id = section.getAttribute("id");
171
+ this.anchoredElements[id] = {
172
+ id,
173
+ intersect: false
174
+ };
175
+ this.observer.observe(section);
176
+ });
177
+ }
178
+
179
+ private disconnectObserver(): void {
180
+ if (this.observer) {
181
+ this.observer.disconnect();
182
+ this.observer = null;
183
+ }
184
+ }
185
+
186
+ private scrollToHash(anchoredTags: Array<Element>): void {
187
+ let { hash } = window.location;
188
+
189
+ if (hash) {
190
+ hash = hash.substr(1);
191
+ const toScrollElement = anchoredTags.find(
192
+ (element) => element.getAttribute("id") === hash
193
+ );
194
+ if (toScrollElement) {
195
+ toScrollElement.scrollIntoView({ behavior: "auto" });
196
+ }
197
+ }
198
+ }
199
+
200
+ private calculateActualSection(): void {
201
+ const currentScrollPosition = document.documentElement.scrollTop;
202
+ const id = Object.keys(this.anchoredElements).find(
203
+ (_id) => this.anchoredElements[_id].intersect
204
+ );
205
+ if (id) {
206
+ this.assignElementId(id);
207
+ } else if (currentScrollPosition < this.lastScrollPosition) {
208
+ // The user has scroll up since last update
209
+ this.assignElementId(this.calculatePreviousElementId());
210
+ }
211
+
212
+ this.lastScrollPosition = currentScrollPosition;
213
+ }
214
+
215
+ private calculatePreviousElementId(): string {
216
+ const keys = Object.keys(this.anchoredElements);
217
+ const currentIndex = keys.findIndex((id) => this.tocValue === id);
218
+
219
+ return currentIndex > 0 ? keys[currentIndex - 1] : undefined;
220
+ }
221
+
222
+ private assignElementId(id: string): void {
223
+ this.tocValue = id;
224
+ }
225
+
226
+ private dispatchHighlightChange(term: string): void {
227
+ this.dispatchEvent(
228
+ new CustomEvent("highlightedtermchange", {
229
+ detail: term,
230
+ bubbles: true,
231
+ composed: true
232
+ })
233
+ );
234
+ }
235
+
236
+ private updateHighlightsAndSearch(nextSearchString: string): void {
237
+ const nextSearchParam =
238
+ new URLSearchParams(nextSearchString).get("q") || "";
239
+ this.setSidebarInputValue(nextSearchParam);
240
+ this.dispatchHighlightChange(nextSearchParam);
241
+ }
242
+ }
@@ -1,4 +1,4 @@
1
- @import "helpers/commonHeader";
1
+ @import "dxHelpers/commonHeader";
2
2
 
3
3
  dx-logo {
4
4
  min-width: fit-content;
@@ -1,8 +1,8 @@
1
1
  import { api } from "lwc";
2
2
  import cx from "classnames";
3
- import type { Option } from "typings/custom";
4
- import { HeaderBase } from "base-elements/headerBase";
5
- import { toJson } from "utils/normalizers";
3
+ import type { OptionWithNested, OptionWithLink } from "typings/custom";
4
+ import { HeaderBase } from "dxBaseElements/headerBase";
5
+ import { toJson } from "dxUtils/normalizers";
6
6
  import get from "lodash.get";
7
7
 
8
8
  const TABLET_MATCH = "980px";
@@ -43,8 +43,8 @@ export default class Header extends HeaderBase {
43
43
  }
44
44
 
45
45
  private _language: string | null = null;
46
- private _languages!: Option[];
47
- private _scopedNavItems!: Option[];
46
+ private _languages!: OptionWithLink[];
47
+ private _scopedNavItems!: OptionWithNested[];
48
48
  private smallMobile = false;
49
49
  private smallMobileMatchMedia!: MediaQueryList;
50
50
  private tablet = false;
@@ -1,4 +1,4 @@
1
- @import "helpers/reset";
1
+ @import "dxHelpers/reset";
2
2
 
3
3
  button {
4
4
  opacity: 0;
@@ -1,4 +1,4 @@
1
- @import "helpers/reset";
1
+ @import "dxHelpers/reset";
2
2
 
3
3
  :host {
4
4
  --doc-c-heading-anchor-button-bottom: 0;
@@ -1,6 +1,6 @@
1
- @import "helpers/reset";
2
- @import "helpers/text";
3
- @import "helpers/status";
1
+ @import "dxHelpers/reset";
2
+ @import "dxHelpers/text";
3
+ @import "docHelpers/status";
4
4
 
5
5
  .doc-phase-container {
6
6
  display: flex;
@@ -2,7 +2,7 @@ import { LightningElement, api } from "lwc";
2
2
  import cx from "classnames";
3
3
 
4
4
  import { DocPhaseInfo } from "typings/custom";
5
- import { toJson } from "utils/normalizers";
5
+ import { toJson } from "dxUtils/normalizers";
6
6
 
7
7
  export default class Phase extends LightningElement {
8
8
  _docPhaseInfo: DocPhaseInfo | null = null;
@@ -0,0 +1,113 @@
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 TreeNode = {
25
+ label: string;
26
+ name: string;
27
+ children?: Array<TreeNode>;
28
+ isExpanded?: boolean;
29
+ };
30
+
31
+ type DropdownOption = {
32
+ id: string;
33
+ label: string;
34
+ };
35
+
36
+ export type DocVersion = DropdownOption & {
37
+ releaseVersion: string;
38
+ url: string;
39
+ };
40
+
41
+ export type DocLanguage = DropdownOption & {
42
+ code: string;
43
+ url: string;
44
+ };
45
+
46
+ export type ApiDocVersion = {
47
+ version_text: string;
48
+ release_version: string;
49
+ doc_version: string;
50
+ version_url: string;
51
+ };
52
+
53
+ export type ApiDocLanguage = {
54
+ code: string;
55
+ label: string;
56
+ locale: string;
57
+ url: string;
58
+ };
59
+
60
+ export interface Header extends Element {
61
+ subtitle: string;
62
+ bailHref: string;
63
+ bailLabel: string;
64
+ languages: Array<DocLanguage>;
65
+ language: string;
66
+ headerHref: string;
67
+ }
68
+
69
+ export type ApiNavItem = {
70
+ children: Array<ApiNavItem>;
71
+ text: string;
72
+ a_attr: {
73
+ href: string;
74
+ };
75
+ id: string;
76
+ };
77
+
78
+ export type ApiDocData = {
79
+ available_languages: Array<ApiDocLanguage>;
80
+ available_versions: Array<ApiDocVersion>;
81
+ content: string;
82
+ content_document_id: string;
83
+ deliverable: string;
84
+ doc_title: string;
85
+ language: ApiDocLanguage;
86
+ title: string;
87
+ toc: Array<ApiNavItem>;
88
+ version: ApiDocVersion;
89
+ pdf_url: string;
90
+ };
91
+
92
+ export type ContentData = {
93
+ content: string;
94
+ id: string;
95
+ title: string;
96
+ };
97
+
98
+ export type DocumentData = ContentData & {
99
+ availableLanguages: Array<DocLanguage>;
100
+ availableVersions: Array<DocVersion>;
101
+ deliverable: string;
102
+ docTitle: string;
103
+ language: DocLanguage;
104
+ toc: Array<TreeNode>;
105
+ tocMap: { [key: string]: TreeNode };
106
+ version: DocVersion;
107
+ pdfUrl: string;
108
+ };
109
+
110
+ export type ContentApiOptions = {
111
+ version: string;
112
+ language: string;
113
+ };
@@ -0,0 +1,158 @@
1
+ import {
2
+ ApiDocData,
3
+ ApiDocLanguage,
4
+ ApiDocVersion,
5
+ ApiNavItem,
6
+ ContentApiOptions,
7
+ ContentData,
8
+ DocumentData,
9
+ DocLanguage,
10
+ DocVersion,
11
+ TreeNode
12
+ } from "./types";
13
+ import { Language } from "typings/custom";
14
+ import { getLanguageDisplayTextById } from "dxUtils/language";
15
+
16
+ export class FetchContent {
17
+ private apiDomain: string;
18
+ private languages: Array<Language> = [];
19
+
20
+ constructor(apiDomain: string, languages: Array<Language>) {
21
+ this.apiDomain = apiDomain;
22
+ this.languages = languages;
23
+ }
24
+
25
+ async fetchDocumentData(docId: string): Promise<DocumentData | null> {
26
+ try {
27
+ const {
28
+ available_languages,
29
+ available_versions,
30
+ toc,
31
+ content,
32
+ version,
33
+ language,
34
+ content_document_id,
35
+ title,
36
+ doc_title,
37
+ pdf_url,
38
+ deliverable
39
+ } = await this.fetchResource<ApiDocData>(
40
+ `${this.apiDomain}/docs/get_document/${docId}`
41
+ );
42
+
43
+ const { normalizedToc, tocMap } = this.normalizeToc(toc);
44
+ return {
45
+ availableLanguages:
46
+ available_languages &&
47
+ available_languages.map(this.normalizeLanguage.bind(this)),
48
+ availableVersions:
49
+ available_versions &&
50
+ available_versions.map(this.normalizeVersion.bind(this)),
51
+ content,
52
+ version: this.normalizeVersion(version),
53
+ id: content_document_id,
54
+ language: this.normalizeLanguage(language),
55
+ title,
56
+ toc: normalizedToc,
57
+ tocMap,
58
+ docTitle: doc_title,
59
+ pdfUrl: pdf_url,
60
+ deliverable
61
+ };
62
+ } catch (error) {
63
+ console.log(error);
64
+ return null;
65
+ }
66
+ }
67
+
68
+ fetchContent(
69
+ deliverable: string,
70
+ contentId: string,
71
+ options: ContentApiOptions
72
+ ): Promise<ContentData> {
73
+ return this.fetchResource<ContentData>(
74
+ `${this.apiDomain}/docs/get_document_content/${deliverable}/${contentId}/${options.language}/${options.version}`
75
+ );
76
+ }
77
+
78
+ private async fetchResource<T>(url: string): Promise<T> {
79
+ const response = await fetch(url);
80
+ if (!response.ok) {
81
+ throw new Error(response.statusText);
82
+ }
83
+
84
+ const json = await response.json();
85
+
86
+ return json;
87
+ }
88
+
89
+ private normalizeToc(apiToc: Array<ApiNavItem>): {
90
+ tocMap: { [key: string]: TreeNode };
91
+ normalizedToc: Array<TreeNode>;
92
+ } {
93
+ const tocMap = {};
94
+ const normalizedToc =
95
+ apiToc &&
96
+ apiToc.map((navItem) => this.normalizeNavItem(navItem, tocMap));
97
+
98
+ return { normalizedToc, tocMap };
99
+ }
100
+
101
+ private normalizeNavItem(
102
+ navItem: ApiNavItem,
103
+ tocMap: { [key: string]: TreeNode }
104
+ ): TreeNode {
105
+ const name = this.calculateNavItemName(navItem, tocMap);
106
+ const node: TreeNode = {
107
+ label: navItem.text,
108
+ name
109
+ };
110
+ if (name) {
111
+ tocMap[name] = node;
112
+ }
113
+ node.children = navItem.children?.map((child) =>
114
+ this.normalizeNavItem(child, tocMap)
115
+ );
116
+ return node;
117
+ }
118
+
119
+ private calculateNavItemName(
120
+ navItem: ApiNavItem,
121
+ tocMap: { [key: string]: TreeNode }
122
+ ): string {
123
+ let href = navItem.a_attr?.href || "";
124
+ if (href.includes("#")) {
125
+ const [pathUrl] = href.split("#");
126
+ href = pathUrl in tocMap ? href : pathUrl;
127
+ }
128
+ return href || navItem.id;
129
+ }
130
+
131
+ private normalizeVersion(version: ApiDocVersion): DocVersion {
132
+ return (
133
+ version && {
134
+ label: version.version_text,
135
+ releaseVersion:
136
+ version.release_version &&
137
+ !version.release_version.startsWith("v")
138
+ ? `v${version.release_version}`
139
+ : version.release_version,
140
+ id: version.doc_version,
141
+ url: version.version_url
142
+ }
143
+ );
144
+ }
145
+
146
+ private normalizeLanguage(language: ApiDocLanguage): DocLanguage {
147
+
148
+ return (
149
+ language && {
150
+ label: getLanguageDisplayTextById(this.languages, language.locale) ||
151
+ language.label,
152
+ id: language.locale,
153
+ code: language.code,
154
+ url: language.url
155
+ }
156
+ );
157
+ }
158
+ }
@@ -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>