@salesforcedevs/docs-components 0.56.0 → 0.56.2-comp-flex-ref-2

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,76 @@
1
+ const NAVIGATION_ITEMS = [
2
+ {
3
+ label: "Summary",
4
+ name: "summary",
5
+ childrenPropertyName: undefined,
6
+ type: "summary"
7
+ },
8
+ {
9
+ label: "Endpoints",
10
+ name: "endpoints",
11
+ childrenPropertyName: "endpoints",
12
+ type: "endpoint"
13
+ },
14
+ {
15
+ label: "Documentation",
16
+ name: "documentation",
17
+ childrenPropertyName: "docs",
18
+ type: "documentation"
19
+ },
20
+ {
21
+ label: "Types",
22
+ name: "types",
23
+ childrenPropertyName: "types",
24
+ type: "type"
25
+ },
26
+ {
27
+ label: "Security",
28
+ name: "security",
29
+ childrenPropertyName: "security",
30
+ type: "security"
31
+ }
32
+ ];
33
+
34
+ const URL_CONFIG = {
35
+ summary: {
36
+ urlIdentifer: "label"
37
+ },
38
+ endpoint: {
39
+ urlIdentifer: "path"
40
+ },
41
+ method: {
42
+ urlIdentifer: "label"
43
+ },
44
+ documentation: {
45
+ urlIdentifer: "label"
46
+ },
47
+ type: {
48
+ urlIdentifer: "label",
49
+ prefix: "type:"
50
+ },
51
+ security: {
52
+ urlIdentifer: "label",
53
+ prefix: "security:"
54
+ }
55
+ };
56
+
57
+ export const REFERENCE_TYPES = {
58
+ markdown: "markdown",
59
+ raml: "rest-raml",
60
+ oa2: "rest-oa2",
61
+ oa3: "rest-oa3"
62
+ };
63
+
64
+ const oldReferenceIdNewReferenceIdMap: Record<string, string> = {
65
+ "commerce-api-assignments": "assignments",
66
+ "commerce-api-campaigns": "campaigns",
67
+ "commerce-api-catalogs": "catalogs",
68
+ "cdn-zones": "cdn-api-process-apis",
69
+ "inventory-impex": "impex",
70
+ "inventory-reservations": "inventory-reservation-service",
71
+ "shopper-login-and-api-access-service": "shopper-login",
72
+ "shopper-login-and-api-access-service-admin": "slas-admin",
73
+ "einstein-recommendations": "einstein-api-quick-start-guide"
74
+ };
75
+
76
+ export { NAVIGATION_ITEMS, URL_CONFIG, oldReferenceIdNewReferenceIdMap };
@@ -2,6 +2,7 @@ import { Json } from "typings/custom";
2
2
 
3
3
  export interface AmfTopicType {
4
4
  referenceId: string;
5
+ parentReferencePath: string;
5
6
  amfId: string;
6
7
  elementId: string;
7
8
  type: string;
@@ -53,11 +54,37 @@ export type DocPhaseEntry = {
53
54
  body: string;
54
55
  };
55
56
 
56
- export interface AmfConfig extends AmfModelRecord {
57
+ export type ReferenceType = "markdown" | "rest-raml" | "rest-oa2" | "rest-oa3";
58
+
59
+ /**
60
+ * Represents parsed topic for the sidebar.
61
+ */
62
+ export interface ParsedMarkdownTopic {
63
+ label: string;
64
+ name: string;
65
+ children: ParsedMarkdownTopic[];
66
+ link?: {
67
+ href: string;
68
+ target?: string;
69
+ };
70
+ }
71
+
72
+ export interface AmfConfig {
57
73
  id: string;
58
- amf: string;
59
74
  version?: string;
60
75
  docPhase?: DocPhaseEntry;
76
+ title: string;
77
+ href: string;
78
+ referenceType: ReferenceType;
79
+
80
+ // determines if a reference config is the current active and selected one.
81
+ isSelected: boolean;
82
+
83
+ // required for spec based references
84
+ amf?: string;
85
+
86
+ // required for markdown based references
87
+ topic?: ParsedMarkdownTopic;
61
88
  }
62
89
 
63
90
  export interface ParsedTopicModel {
@@ -84,10 +111,22 @@ export interface ReferenceVersion {
84
111
  label: string;
85
112
  deprecated?: boolean;
86
113
  selected?: boolean;
114
+ link: {
115
+ href: string;
116
+ };
87
117
  }
88
118
 
89
119
  export interface ReferenceSetConfig {
120
+ refId?: string;
90
121
  versionToRefMap?: Map<string, Array<AmfConfig>>;
91
122
  refList: Array<AmfConfig>;
92
- versions?: Array<ReferenceVersion>;
123
+ versions: Array<ReferenceVersion>;
124
+ }
125
+
126
+ export interface RouteMeta {
127
+ meta: string;
128
+ referenceId: string;
129
+ topicId: string;
130
+ //type is only for spec based references
131
+ type?: string;
93
132
  }
@@ -20,6 +20,7 @@ const HIGHLIGHTABLE_SELECTOR = [
20
20
  "th",
21
21
  "td"
22
22
  ].join(",");
23
+ const OBSERVER_ATTACH_WAIT_TIME = 500;
23
24
 
24
25
  export default class ContentLayout extends LightningElement {
25
26
  @api sidebarValue: string;
@@ -95,6 +96,8 @@ export default class ContentLayout extends LightningElement {
95
96
  target: window
96
97
  });
97
98
  private tocValue?: string = undefined;
99
+ private observerTimerId = null;
100
+ private didScrollToSelectedHash = false;
98
101
 
99
102
  get showToc(): boolean {
100
103
  return this.tocOptions && this.tocOptions.length > 0;
@@ -119,6 +122,18 @@ export default class ContentLayout extends LightningElement {
119
122
  }
120
123
  }
121
124
 
125
+ renderedCallback(): void {
126
+ /**
127
+ * Note: We are adding timeout because chrome is optimizing and not triggering recent renderedCallback though elements reference is changed
128
+ * Also we are considering recent renderedCallback
129
+ */
130
+ this.clearRenderObserverTimer();
131
+ this.observerTimerId = setTimeout(
132
+ this.attachInteractionObserver,
133
+ OBSERVER_ATTACH_WAIT_TIME
134
+ );
135
+ }
136
+
122
137
  disconnectedCallback(): void {
123
138
  this.disconnectObserver();
124
139
  window.removeEventListener(
@@ -126,19 +141,25 @@ export default class ContentLayout extends LightningElement {
126
141
  this.updateHighlighted
127
142
  );
128
143
  this.searchSyncer.dispose();
144
+ this.clearRenderObserverTimer();
129
145
  }
130
146
 
147
+ clearRenderObserverTimer = () => {
148
+ if (this.observerTimerId) {
149
+ clearTimeout(this.observerTimerId);
150
+ }
151
+ };
152
+
131
153
  updateHighlighted = (event: Event): void =>
132
154
  highlightTerms(
133
155
  this.querySelectorAll(HIGHLIGHTABLE_SELECTOR),
134
156
  (event as CustomEvent<string>).detail
135
157
  );
136
158
 
137
- onSlotChange(event: Event): void {
159
+ attachInteractionObserver = (): void => {
138
160
  if (!this.enableSlotChange) {
139
161
  return;
140
162
  }
141
-
142
163
  this.disconnectObserver();
143
164
  this.observer = new IntersectionObserver((entries) => {
144
165
  entries.forEach(
@@ -150,30 +171,54 @@ export default class ContentLayout extends LightningElement {
150
171
  this.calculateActualSection();
151
172
  });
152
173
 
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");
174
+ // Note: We are doing document.querySelectorAll as a quick fix as we are not getting heading elements reference this.querySelectorAll
175
+ const headingElements = document.querySelectorAll(TOC_HEADER_TAG);
176
+ for (const headingElement of headingElements) {
177
+ // Add headingElements to intersectionObserver for highlighting respective RNB item when user scroll
178
+ const id = headingElement.getAttribute("id");
171
179
  this.anchoredElements[id] = {
172
180
  id,
173
181
  intersect: false
174
182
  };
175
- this.observer.observe(section);
176
- });
183
+ this.observer.observe(headingElement);
184
+ }
185
+ if (!this.didScrollToSelectedHash) {
186
+ this.didScrollToSelectedHash = true;
187
+ this.scrollToHash(headingElements);
188
+ }
189
+ };
190
+
191
+ onSlotChange(event: Event): void {
192
+ const slotElements = (
193
+ event.target as HTMLSlotElement
194
+ ).assignedElements();
195
+
196
+ if (slotElements.length) {
197
+ const slotContentElement = slotElements[0];
198
+ const headingElements =
199
+ slotContentElement.ownerDocument?.getElementsByTagName(
200
+ TOC_HEADER_TAG
201
+ );
202
+ for (const headingElement of headingElements) {
203
+ // Sometimes elements hash is not being set when slot content is wrapped with div
204
+ headingElement.hash =
205
+ headingElement.attributes.hash?.nodeValue;
206
+ }
207
+ const tocOptions = [];
208
+ for (const headingElement of headingElements) {
209
+ headingElement.id = headingElement.hash;
210
+
211
+ // Update tocOptions from anchorTags
212
+ const tocItem = {
213
+ anchor: `#${headingElement.hash}`,
214
+ id: headingElement.id,
215
+ label: headingElement.title
216
+ };
217
+ tocOptions.push(tocItem);
218
+ }
219
+
220
+ this._tocOptions = tocOptions;
221
+ }
177
222
  }
178
223
 
179
224
  private disconnectObserver(): void {
@@ -183,16 +228,16 @@ export default class ContentLayout extends LightningElement {
183
228
  }
184
229
  }
185
230
 
186
- private scrollToHash(anchoredTags: Array<Element>): void {
231
+ // eslint-disable-next-line no-undef
232
+ private scrollToHash(headingElements: NodeListOf<Element>): void {
187
233
  let { hash } = window.location;
188
-
189
234
  if (hash) {
190
235
  hash = hash.substr(1);
191
- const toScrollElement = anchoredTags.find(
192
- (element) => element.getAttribute("id") === hash
193
- );
194
- if (toScrollElement) {
195
- toScrollElement.scrollIntoView({ behavior: "auto" });
236
+ for (const headingElement of headingElements) {
237
+ if (headingElement.getAttribute("id") === hash) {
238
+ headingElement.scrollIntoView({ behavior: "auto" });
239
+ break;
240
+ }
196
241
  }
197
242
  }
198
243
  }
@@ -19,12 +19,6 @@ export enum HistoryState {
19
19
  REPLACE_STATE = "replaceState"
20
20
  }
21
21
 
22
- export type Labels = {
23
- language_english: string;
24
- language_japanese: string;
25
- toc_title: string;
26
- };
27
-
28
22
  export type TreeNode = {
29
23
  label: string;
30
24
  name: string;
@@ -8,22 +8,18 @@ import {
8
8
  DocumentData,
9
9
  DocLanguage,
10
10
  DocVersion,
11
- Labels,
12
11
  TreeNode
13
12
  } from "./types";
14
-
15
- const LOCALE_TO_LABEL = {
16
- "en-us": "language_english",
17
- "ja-jp": "language_japanese"
18
- };
13
+ import { Language } from "typings/custom";
14
+ import { getLanguageDisplayTextById } from "dxUtils/language";
19
15
 
20
16
  export class FetchContent {
21
17
  private apiDomain: string;
22
- private labels: Labels;
18
+ private languages: Array<Language> = [];
23
19
 
24
- constructor(apiDomain: string, labels: Labels) {
20
+ constructor(apiDomain: string, languages: Array<Language>) {
25
21
  this.apiDomain = apiDomain;
26
- this.labels = labels;
22
+ this.languages = languages;
27
23
  }
28
24
 
29
25
  async fetchDocumentData(docId: string): Promise<DocumentData | null> {
@@ -148,11 +144,10 @@ export class FetchContent {
148
144
  }
149
145
 
150
146
  private normalizeLanguage(language: ApiDocLanguage): DocLanguage {
151
- const labelKey = language.locale && LOCALE_TO_LABEL[language.locale];
147
+
152
148
  return (
153
149
  language && {
154
- label:
155
- (labelKey && this.labels && this.labels[labelKey]) ||
150
+ label: getLanguageDisplayTextById(this.languages, language.locale) ||
156
151
  language.label,
157
152
  id: language.locale,
158
153
  code: language.code,
@@ -1,11 +1,10 @@
1
1
  import { api, track } from "lwc";
2
- import { normalizeBoolean, toJson } from "dxUtils/normalizers";
2
+ import { normalizeBoolean } from "dxUtils/normalizers";
3
3
  import { FetchContent } from "./utils";
4
4
  import {
5
5
  CoveoAdvancedQueryXMLConfig,
6
6
  DocLanguage,
7
7
  DocVersion,
8
- Labels,
9
8
  TreeNode,
10
9
  Header,
11
10
  HistoryState,
@@ -13,6 +12,8 @@ import {
13
12
  } from "./types";
14
13
  import { SearchSyncer } from "docUtils/SearchSyncer";
15
14
  import { LightningElementWithState } from "docBaseElements/lightningElementWithState";
15
+ import { Language } from "typings/custom";
16
+ import { DEFAULT_LANGUAGES } from "dxUtils/constants";
16
17
 
17
18
  // TODO: Imitating from actual implementation as doc-content use it like this. We should refactor it later.
18
19
  const handleContentError = (error): void => console.log(error);
@@ -27,12 +28,14 @@ export default class DocXmlContent extends LightningElementWithState<{
27
28
  @api coveoPublicAccessToken!: string;
28
29
 
29
30
  @api
30
- get labels() {
31
- return this._labels;
31
+ get allLanguages(): Array<Language> {
32
+ return this._allLanguages;
32
33
  }
33
34
 
34
- set labels(value) {
35
- this._labels = toJson(value);
35
+ set allLanguages(value: string) {
36
+ if (value) {
37
+ this._allLanguages = JSON.parse(value);
38
+ }
36
39
  }
37
40
 
38
41
  @api
@@ -44,7 +47,6 @@ export default class DocXmlContent extends LightningElementWithState<{
44
47
  this._enableCoveo = normalizeBoolean(value);
45
48
  }
46
49
 
47
- private _labels: Labels = null;
48
50
  private availableLanguages: Array<DocLanguage> = [];
49
51
  private availableVersions: Array<DocVersion> = [];
50
52
  private contentProvider: FetchContent;
@@ -98,6 +100,7 @@ export default class DocXmlContent extends LightningElementWithState<{
98
100
  shouldStopPropagation: true,
99
101
  target: window
100
102
  });
103
+ private _allLanguages: Array<Language> = DEFAULT_LANGUAGES;
101
104
 
102
105
  @track private pageReference: PageReference = {};
103
106
 
@@ -120,8 +123,10 @@ export default class DocXmlContent extends LightningElementWithState<{
120
123
  window.location.href = "/docs";
121
124
  return;
122
125
  }
123
-
124
- this.contentProvider = new FetchContent(this.apiDomain, this._labels);
126
+ this.contentProvider = new FetchContent(
127
+ this.apiDomain,
128
+ this.allLanguages
129
+ );
125
130
  this.fetchDocument().then(() => (this.loaded = true));
126
131
  window.addEventListener("popstate", this.handlePopState);
127
132
 
package/LICENSE DELETED
@@ -1,12 +0,0 @@
1
- Copyright (c) 2020, Salesforce.com, Inc.
2
- All rights reserved.
3
-
4
- Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5
-
6
- * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7
-
8
- * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9
-
10
- * Neither the name of Salesforce.com nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
11
-
12
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -1,22 +0,0 @@
1
- /**
2
- * Represents the URL reference meta on Reference page.
3
- * Contains information on selected Reference ID, Topic ID, and Topic Type
4
- * separated by ":"
5
- */
6
- export class RouteMeta {
7
- meta: string;
8
- referenceId = "";
9
- topicId = "";
10
- type = "";
11
-
12
- constructor(meta: string) {
13
- this.meta = meta;
14
-
15
- if (meta && meta.includes(":")) {
16
- const [referenceId, type, topicId] = meta.split(":");
17
- this.referenceId = referenceId;
18
- this.topicId = topicId || type;
19
- this.type = type;
20
- }
21
- }
22
- }