@salesforcedevs/docs-components 0.56.2 → 0.57.1-flex-ref1

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;
@@ -10,6 +11,7 @@ export interface AmfTopicType {
10
11
  export interface AmfMetadataTopic extends AmfTopicType {
11
12
  meta: string;
12
13
  identifier: string;
14
+ navTitle?: string;
13
15
  }
14
16
 
15
17
  export interface AmfMetaTopicType extends AmfTopicType {
@@ -53,11 +55,37 @@ export type DocPhaseEntry = {
53
55
  body: string;
54
56
  };
55
57
 
56
- export interface AmfConfig extends AmfModelRecord {
58
+ export type ReferenceType = "markdown" | "rest-raml" | "rest-oa2" | "rest-oa3";
59
+
60
+ /**
61
+ * Represents parsed topic for the sidebar.
62
+ */
63
+ export interface ParsedMarkdownTopic {
64
+ label: string;
65
+ name: string;
66
+ children: ParsedMarkdownTopic[];
67
+ link?: {
68
+ href: string;
69
+ target?: string;
70
+ };
71
+ }
72
+
73
+ export interface AmfConfig {
57
74
  id: string;
58
- amf: string;
59
75
  version?: string;
60
76
  docPhase?: DocPhaseEntry;
77
+ title: string;
78
+ href: string;
79
+ referenceType: ReferenceType;
80
+
81
+ // determines if a reference config is the current active and selected one.
82
+ isSelected: boolean;
83
+
84
+ // required for spec based references
85
+ amf?: string;
86
+
87
+ // required for markdown based references
88
+ topic?: ParsedMarkdownTopic;
61
89
  }
62
90
 
63
91
  export interface ParsedTopicModel {
@@ -84,10 +112,22 @@ export interface ReferenceVersion {
84
112
  label: string;
85
113
  deprecated?: boolean;
86
114
  selected?: boolean;
115
+ link: {
116
+ href: string;
117
+ };
87
118
  }
88
119
 
89
120
  export interface ReferenceSetConfig {
121
+ refId?: string;
90
122
  versionToRefMap?: Map<string, Array<AmfConfig>>;
91
123
  refList: Array<AmfConfig>;
92
- versions?: Array<ReferenceVersion>;
124
+ versions: Array<ReferenceVersion>;
125
+ }
126
+
127
+ export interface RouteMeta {
128
+ meta: string;
129
+ referenceId: string;
130
+ topicId: string;
131
+ //type is only for spec based references
132
+ type?: string;
93
133
  }
@@ -1,5 +1,5 @@
1
1
  <template>
2
2
  <dx-icon if:true={isBackArrowVariant} symbol="back"></dx-icon>
3
- <a if:true={href} href={href}>{label}</a>
3
+ <a if:true={href} href={href} onclick={onLinkClick}>{label}</a>
4
4
  <span if:false={href}>{label}</span>
5
5
  </template>
@@ -1,5 +1,6 @@
1
+ import { track } from "dxUtils/analytics";
1
2
  import { LightningElement, api } from "lwc";
2
- import { BreadcrumbItemVariant } from "typings/custom";
3
+ import { AnalyticsPayload, BreadcrumbItemVariant } from "typings/custom";
3
4
 
4
5
  const BREADCRUMB_LONG = "breadcrumb_long";
5
6
  const BREADCRUMB_BACK_ARROW = "breadcrumb_back-arrow";
@@ -7,6 +8,8 @@ const BREADCRUMB_BACK_ARROW = "breadcrumb_back-arrow";
7
8
  const LONG_LABEL_NUMBER = 30;
8
9
  export default class BreadcrumbItem extends LightningElement {
9
10
  @api href?: string;
11
+ @api analyticsEvent!: string;
12
+ @api analyticsBasePayload!: AnalyticsPayload;
10
13
 
11
14
  @api
12
15
  get label() {
@@ -46,4 +49,17 @@ export default class BreadcrumbItem extends LightningElement {
46
49
  private get isBackArrowVariant(): boolean {
47
50
  return this._variant === "back-arrow";
48
51
  }
52
+
53
+ private onLinkClick(event: Event): void {
54
+ if (!this.analyticsEvent) {
55
+ return;
56
+ }
57
+
58
+ track(event.target!, this.analyticsEvent, {
59
+ ...this.analyticsBasePayload,
60
+ clickText: this.label,
61
+ itemTitle: this.label,
62
+ pageLocation: window.location.pathname
63
+ });
64
+ }
49
65
  }
@@ -9,7 +9,6 @@
9
9
  nav {
10
10
  display: flex;
11
11
  align-items: center;
12
- height: 100%;
13
12
  position: relative;
14
13
  gap: var(--dx-g-spacing-sm);
15
14
  }
@@ -17,3 +16,10 @@ nav {
17
16
  .breadcrumb-item_slash {
18
17
  min-width: fit-content;
19
18
  }
19
+
20
+ dx-dropdown {
21
+ --dx-c-dropdown-option-font-size: var(--dx-g-text-sm);
22
+ --dx-c-dropdown-option-label-color: var(
23
+ --dx-c-breadcrumbs-breadcrumb-color
24
+ );
25
+ }
@@ -3,6 +3,8 @@
3
3
  <template if:false={renderSmallVariant}>
4
4
  <template if:true={renderFirstCrumb}>
5
5
  <doc-breadcrumb-item
6
+ analytics-event={analyticsEventName}
7
+ analytics-base-payload={analyticsBasePayload}
6
8
  href={firstCrumb.href}
7
9
  label={firstCrumb.label}
8
10
  ></doc-breadcrumb-item>
@@ -11,10 +13,14 @@
11
13
  <template if:true={renderDropdown}>
12
14
  <dx-dropdown
13
15
  if:true={renderDropdown}
16
+ analytics-event={analyticsEventName}
17
+ analytics-base-payload={analyticsBasePayload}
14
18
  options={dropdownOptions}
15
19
  open-on-hover
16
20
  placement="bottom"
17
- width="200px"
21
+ suppress-gtm-nav-headings
22
+ variant="indented"
23
+ width="fit-content"
18
24
  >
19
25
  <dx-button
20
26
  aria-label="Open Breadcrumbs Dropdown"
@@ -27,6 +33,8 @@
27
33
  </template>
28
34
  <template for:each={breadcrumbItems} for:item="breadcrumb">
29
35
  <doc-breadcrumb-item
36
+ analytics-event={analyticsEventName}
37
+ analytics-base-payload={analyticsBasePayload}
30
38
  href={breadcrumb.href}
31
39
  key={breadcrumb.label}
32
40
  label={breadcrumb.label}
@@ -39,6 +47,8 @@
39
47
  </template>
40
48
  <template if:true={renderSmallVariant}>
41
49
  <doc-breadcrumb-item
50
+ analytics-event={analyticsEventName}
51
+ analytics-base-payload={analyticsBasePayload}
42
52
  href={lastLinkCrump.href}
43
53
  label={lastLinkCrump.label}
44
54
  variant="back-arrow"
@@ -15,6 +15,13 @@ const CONSTANTS = {
15
15
  dropdownWidth: 32
16
16
  };
17
17
 
18
+ export const ANALYTICS_EVENT_NAME = "custEv_breadcrumbClick";
19
+ export const ANALYTICS_BASE_PAYLOAD = {
20
+ elementType: "breadcrumb",
21
+ locationOnPage: "breadcrumb",
22
+ ctaClick: true
23
+ };
24
+
18
25
  export default class Breadcrumbs extends LightningElement {
19
26
  @api ariaLabel: string = "Documentation Breadcrumbs";
20
27
 
@@ -84,6 +91,14 @@ export default class Breadcrumbs extends LightningElement {
84
91
  return this.breadcrumbs[this.breadcrumbs.length - 1];
85
92
  }
86
93
 
94
+ private get analyticsEventName() {
95
+ return ANALYTICS_EVENT_NAME;
96
+ }
97
+
98
+ private get analyticsBasePayload() {
99
+ return ANALYTICS_BASE_PAYLOAD;
100
+ }
101
+
87
102
  renderedCallback(): void {
88
103
  if (!this.observer) {
89
104
  this.observer = new ResizeObserver((entries) => {
@@ -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
  }
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
- }