@salesforcedevs/docs-components 1.20.7-redoc-ref1 → 1.20.7

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.
package/LICENSE ADDED
@@ -0,0 +1,12 @@
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.
package/lwc.config.json CHANGED
@@ -20,7 +20,6 @@
20
20
  "doc/headingAnchor",
21
21
  "doc/overview",
22
22
  "doc/phase",
23
- "doc/redocReference",
24
23
  "doc/specificationContent",
25
24
  "doc/versionPicker",
26
25
  "doc/xmlContent",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforcedevs/docs-components",
3
- "version": "1.20.7-redoc-ref1",
3
+ "version": "1.20.7",
4
4
  "description": "Docs Lightning web components for DSC",
5
5
  "license": "MIT",
6
6
  "main": "index.js",
@@ -25,7 +25,7 @@
25
25
  "@types/lodash.orderby": "4.6.9",
26
26
  "@types/lodash.uniqby": "4.7.9"
27
27
  },
28
- "gitHead": "4629fdd9ca18a13480044ad43515b91945d16aad",
28
+ "gitHead": "fffbef4d7b536a321824457c6a987e53830a78f1",
29
29
  "volta": {
30
30
  "node": "20.19.0",
31
31
  "yarn": "1.22.19"
@@ -9,6 +9,7 @@ import {
9
9
  } from "./utils";
10
10
  import type { TopicModel } from "./types";
11
11
  import { Json } from "typings/custom";
12
+ import { buildDocLinkClickHandler } from "dxUtils/analytics";
12
13
 
13
14
  const TABLE_SIZE_MATCH = "769px";
14
15
 
@@ -16,6 +17,15 @@ export default class AmfTopic extends LightningElement {
16
17
  private _model: TopicModel | undefined;
17
18
  private amf: Json;
18
19
  private type: string | undefined;
20
+ private handleLinkClick = buildDocLinkClickHandler();
21
+
22
+ disconnectedCallback(): void {
23
+ // Remove link click handler
24
+ const container = this.template.querySelector(".topic-container");
25
+ if (container) {
26
+ container.removeEventListener("click", this.handleLinkClick);
27
+ }
28
+ }
19
29
 
20
30
  @api
21
31
  get model(): TopicModel | undefined {
@@ -92,6 +102,12 @@ export default class AmfTopic extends LightningElement {
92
102
  }
93
103
  container?.appendChild(element as Node);
94
104
 
105
+ // Add click handler for all links in the dynamically loaded content
106
+ if (container) {
107
+ container.removeEventListener("click", this.handleLinkClick);
108
+ container.addEventListener("click", this.handleLinkClick);
109
+ }
110
+
95
111
  const isTabletOrDesktop = window.matchMedia(
96
112
  `(min-width: ${TABLE_SIZE_MATCH})`
97
113
  ).matches;
@@ -6,6 +6,7 @@ import Button from "dx/button";
6
6
  import { highlightTerms } from "dxUtils/highlight";
7
7
  import ContentCallout from "doc/contentCallout";
8
8
  import ContentMedia from "doc/contentMedia";
9
+ import { buildDocLinkClickHandler } from "dxUtils/analytics";
9
10
 
10
11
  const HIGHLIGHTABLE_SELECTOR = [
11
12
  "p",
@@ -160,6 +161,8 @@ export default class Content extends LightningElement {
160
161
  const anchorEls = divEl.querySelectorAll("a:not([href^='#'])");
161
162
 
162
163
  anchorEls.forEach((anchorEl: any) => {
164
+ // Add click handler to track link clicks
165
+ anchorEl.addEventListener("click", buildDocLinkClickHandler());
163
166
  if (
164
167
  anchorEl.textContent!.includes("Next →") ||
165
168
  anchorEl.textContent!.includes("← Previous")
@@ -1,10 +1,11 @@
1
1
  /* eslint-disable @lwc/lwc/no-document-query */
2
- import { LightningElement, api, track } from "lwc";
2
+ import { LightningElement, api } from "lwc";
3
3
  import { closest } from "kagekiri";
4
4
  import { toJson } from "dxUtils/normalizers";
5
5
  import { highlightTerms } from "dxUtils/highlight";
6
6
  import { SearchSyncer } from "docUtils/searchSyncer";
7
7
  import type { OptionWithLink } from "typings/custom";
8
+ import { buildDocLinkClickHandler } from "dxUtils/analytics";
8
9
 
9
10
  type AnchorMap = { [key: string]: { intersect: boolean; id: string } };
10
11
 
@@ -80,12 +81,10 @@ export default class ContentLayout extends LightningElement {
80
81
  );
81
82
  }
82
83
 
83
- @track
84
84
  protected _sidebarContent: unknown;
85
85
 
86
86
  protected _breadcrumbs = null;
87
87
 
88
- @track
89
88
  protected _tocOptions!: Array<unknown>;
90
89
 
91
90
  protected tocOptionIdsSet = new Set();
@@ -119,6 +118,7 @@ export default class ContentLayout extends LightningElement {
119
118
  protected observerTimerId?: NodeJS.Timeout;
120
119
  protected didScrollToSelectedHash = false;
121
120
  protected _scrollInterval = 0;
121
+ protected handleLinkClick = buildDocLinkClickHandler();
122
122
 
123
123
  get showToc(): boolean {
124
124
  return this.tocOptions && this.tocOptions.length > 0;
@@ -147,6 +147,9 @@ export default class ContentLayout extends LightningElement {
147
147
  );
148
148
  this.searchSyncer.init();
149
149
  }
150
+
151
+ // Add click handler for all links
152
+ this.template.addEventListener("click", this.handleLinkClick);
150
153
  }
151
154
 
152
155
  // Placeholder for childs renderedCallback
@@ -188,6 +191,9 @@ export default class ContentLayout extends LightningElement {
188
191
  this.clearRenderObserverTimer();
189
192
 
190
193
  window.clearInterval(this._scrollInterval);
194
+
195
+ // Remove link click handler
196
+ this.template.removeEventListener("click", this.handleLinkClick);
191
197
  }
192
198
 
193
199
  restoreScroll() {
@@ -1,8 +0,0 @@
1
- <template>
2
- <slot></slot>
3
- <dx-error-fallback
4
- if:true={showError}
5
- title="API Documentation Unavailable"
6
- description="This API reference is currently unavailable. Please try again later."
7
- ></dx-error-fallback>
8
- </template>
@@ -1,183 +0,0 @@
1
- import { createElement, LightningElement, api } from "lwc";
2
- import DocPhase from "doc/phase";
3
- import DxFooter from "dx/footer";
4
-
5
- declare global {
6
- interface Window {
7
- Redoc: any;
8
- }
9
- }
10
-
11
- type ReferenceItem = {
12
- source: string;
13
- href: string;
14
- isSelected?: boolean;
15
- docPhase?: any;
16
- };
17
-
18
- type ReferenceConfig = {
19
- refList: ReferenceItem[];
20
- };
21
-
22
- export default class RedocReference extends LightningElement {
23
- private _referenceConfig: ReferenceConfig = { refList: [] };
24
- private _parentDocPhaseInfo: string | null = null;
25
-
26
- private redocTimeoutId: number | null = null;
27
- private layoutTimeoutId: number | null = null;
28
-
29
- showError = false;
30
-
31
- @api
32
- get referenceConfig(): ReferenceConfig {
33
- return this._referenceConfig;
34
- }
35
-
36
- set referenceConfig(value: string | ReferenceConfig) {
37
- try {
38
- const refConfig =
39
- typeof value === "string" ? JSON.parse(value) : value;
40
- this._referenceConfig = refConfig;
41
- } catch (e) {
42
- this._referenceConfig = { refList: [] };
43
- }
44
- }
45
-
46
- @api
47
- get docPhaseInfo(): string | null {
48
- return this._parentDocPhaseInfo;
49
- }
50
-
51
- set docPhaseInfo(value: string) {
52
- this._parentDocPhaseInfo = value;
53
- }
54
-
55
- connectedCallback(): void {
56
- this.initializeRedoc();
57
- }
58
-
59
- disconnectedCallback(): void {
60
- if (this.redocTimeoutId) {
61
- clearTimeout(this.redocTimeoutId);
62
- this.redocTimeoutId = null;
63
- }
64
- if (this.layoutTimeoutId) {
65
- clearTimeout(this.layoutTimeoutId);
66
- this.layoutTimeoutId = null;
67
- }
68
- }
69
-
70
- @api
71
- setDocPhaseInfo(docPhaseInfo: string): void {
72
- this._parentDocPhaseInfo = docPhaseInfo;
73
- }
74
-
75
- private getDocPhaseInfo(): string | null {
76
- if (this._parentDocPhaseInfo) {
77
- return this._parentDocPhaseInfo;
78
- }
79
- const selectedRef = this.getSelectedReference();
80
- return selectedRef?.docPhase
81
- ? JSON.stringify(selectedRef.docPhase)
82
- : null;
83
- }
84
-
85
- private getSelectedReference(): ReferenceItem | null {
86
- return this._referenceConfig?.refList?.length
87
- ? this._referenceConfig.refList.find((ref) => ref.isSelected) ||
88
- this._referenceConfig.refList[0]
89
- : null;
90
- }
91
-
92
- private getRedocContainer(): HTMLElement | null {
93
- // eslint-disable-next-line @lwc/lwc/no-document-query
94
- return document.querySelector(".redoc-container");
95
- }
96
-
97
- private updateUrlWithReference(selectedRef: ReferenceItem): void {
98
- if (selectedRef?.href) {
99
- const parentReferencePath = selectedRef.href;
100
- const currentUrl = window.location;
101
- const existingParams = currentUrl.search + currentUrl.hash;
102
-
103
- window.history.pushState(
104
- {},
105
- "",
106
- `${parentReferencePath}${existingParams}`
107
- );
108
- }
109
- }
110
-
111
- private initializeRedoc(): void {
112
- if (!window.Redoc) {
113
- this.redocTimeoutId = window.setTimeout(
114
- () => this.initializeRedoc(),
115
- 100
116
- );
117
- } else {
118
- const selectedRef = this.getSelectedReference();
119
- if (selectedRef) {
120
- this.updateUrlWithReference(selectedRef);
121
-
122
- const specUrl = selectedRef.source;
123
- const redocContainer = this.getRedocContainer();
124
- if (specUrl && redocContainer) {
125
- window.Redoc.init(
126
- specUrl,
127
- {
128
- expandResponses: "200,400",
129
- scrollYOffset: 155
130
- },
131
- redocContainer,
132
- () => {
133
- this.insertCustomLayoutElements();
134
- }
135
- );
136
- } else {
137
- this.showError = true;
138
- }
139
- }
140
- }
141
- }
142
-
143
- private insertCustomLayoutElements(): void {
144
- const redocContainer = this.getRedocContainer();
145
- const apiContentDiv = redocContainer?.querySelector(".api-content");
146
- if (apiContentDiv) {
147
- (apiContentDiv as HTMLElement).setAttribute("lwc:dom", "manual");
148
-
149
- try {
150
- const docPhaseInfo = this.getDocPhaseInfo();
151
- if (docPhaseInfo) {
152
- this.insertDocPhase(
153
- apiContentDiv as HTMLElement,
154
- docPhaseInfo
155
- );
156
- }
157
- this.insertFooter(apiContentDiv as HTMLElement);
158
- } catch (error) {
159
- console.error(
160
- "Error showing banner and footer elements",
161
- error
162
- );
163
- }
164
- } else {
165
- this.layoutTimeoutId = window.setTimeout(
166
- () => this.insertCustomLayoutElements(),
167
- 100
168
- );
169
- }
170
- }
171
-
172
- private insertDocPhase(container: HTMLElement, docPhaseInfo: string): void {
173
- const docPhaseElement = createElement("doc-phase", { is: DocPhase });
174
- Object.assign(docPhaseElement, { docPhaseInfo });
175
- container.insertBefore(docPhaseElement, container.firstChild);
176
- }
177
-
178
- private insertFooter(container: HTMLElement): void {
179
- const footerElement = createElement("dx-footer", { is: DxFooter });
180
- Object.assign(footerElement, { variant: "no-signup" });
181
- container.appendChild(footerElement);
182
- }
183
- }