@salesforcedevs/docs-components 0.49.1 → 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.
Files changed (27) hide show
  1. package/lwc.config.json +6 -2
  2. package/package.json +16 -2
  3. package/src/modules/base-elements/lightningElementWithState/lightningElementWithState.ts +93 -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 +874 -0
  7. package/src/modules/doc/amfReference/route-meta.ts +22 -0
  8. package/src/modules/doc/amfReference/types.ts +88 -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 +117 -0
  15. package/src/modules/doc/content/content.ts +156 -162
  16. package/src/modules/doc/contentLayout/contentLayout.css +100 -0
  17. package/src/modules/doc/contentLayout/contentLayout.html +55 -0
  18. package/src/modules/doc/contentLayout/contentLayout.ts +242 -0
  19. package/src/modules/doc/xmlContent/types.ts +119 -0
  20. package/src/modules/doc/xmlContent/utils.ts +163 -0
  21. package/src/modules/doc/xmlContent/xmlContent.css +25 -0
  22. package/src/modules/doc/xmlContent/xmlContent.html +34 -0
  23. package/src/modules/doc/xmlContent/xmlContent.ts +553 -0
  24. package/src/modules/helpers/amfStyle/amfStyle.css +390 -0
  25. package/src/modules/helpers/phaseContentLayout/phaseContentLayout.css +37 -0
  26. package/src/modules/utils/SearchSyncer/SearchSyncer.ts +80 -0
  27. package/LICENSE +0 -12
@@ -0,0 +1,94 @@
1
+ import { LightningElement, api } from "lwc";
2
+ import {
3
+ createDocumentationElement,
4
+ createEndpointElement,
5
+ createMethodElement,
6
+ createSecurityElement,
7
+ createSummaryElement,
8
+ createTypeElement
9
+ } from "./utils";
10
+ import type { TopicModel } from "./types";
11
+
12
+ export default class AmfTopic extends LightningElement {
13
+ private _model;
14
+ private amf;
15
+ private type;
16
+
17
+ @api
18
+ get model(): TopicModel {
19
+ return this._model;
20
+ }
21
+
22
+ set model(value: TopicModel) {
23
+ if (
24
+ !this.amf ||
25
+ (value && this._model && value.amf !== this._model?.amf)
26
+ ) {
27
+ this.amf = value && clone(value.amf);
28
+ }
29
+ if (
30
+ !this.type ||
31
+ (value && this._model && value.type !== this._model?.type)
32
+ ) {
33
+ this.type = value && clone(value.type);
34
+ }
35
+
36
+ this._model = value;
37
+ if (this._model) {
38
+ this.update();
39
+ }
40
+ // else { Remove child? No model, seems like no component should be shown. }
41
+ }
42
+
43
+ update(): void {
44
+ const container = this.template.querySelector("div.topic-container");
45
+ const { id } = this.model;
46
+ const type = this.type;
47
+ const amf = this.amf;
48
+ const { parser } = this.model;
49
+ let element;
50
+
51
+ if (type === "summary") {
52
+ element = createSummaryElement(amf);
53
+ } else if (type === "endpoint") {
54
+ const endpointModel = parser.computeEndpointApiModel(amf, id);
55
+ element = createEndpointElement(amf, endpointModel, id);
56
+ } else if (type === "method") {
57
+ const endpointMethodModel = parser.computeEndpointApiMethodModel(
58
+ amf,
59
+ id
60
+ );
61
+ const methodModel = parser.computeMethodApiModel(amf, id);
62
+ element = createMethodElement(
63
+ amf,
64
+ endpointMethodModel,
65
+ methodModel
66
+ );
67
+ } else if (type === "security") {
68
+ const securityModel = parser.computeSecurityApiModel(amf, id);
69
+ element = createSecurityElement(amf, securityModel);
70
+ } else if (type === "type") {
71
+ const mediaTypes = parser.computeApiMediaTypes(amf);
72
+ const typeModel = parser.computeTypeApiModel(amf, id);
73
+ element = createTypeElement(amf, typeModel, mediaTypes);
74
+ } else if (type === "documentation") {
75
+ const docsModel = parser.computeDocsApiModel(amf, id);
76
+ element = createDocumentationElement(amf, docsModel);
77
+ }
78
+
79
+ if (container.firstChild) {
80
+ container.firstChild.remove();
81
+ }
82
+ container.appendChild(element);
83
+ }
84
+ }
85
+
86
+ /**
87
+ * The underlying web components we use from api-console mutate their models we pass in.
88
+ * Since LWC makes them Read Only, we need to copy them before passing to the Web Component.
89
+ * @param value JSON Serializable object to clone.
90
+ * @returns A copy of Value. One that has been serialized and parsed via JSON. (Functions, Regex, etc are not preserved.)
91
+ */
92
+ function clone(value): object {
93
+ return JSON.parse(JSON.stringify(value));
94
+ }
@@ -0,0 +1,54 @@
1
+ import { Json } from "@lwrjs/types";
2
+
3
+ export type ApiSummaryElement = HTMLElement & {
4
+ amf: Json;
5
+ hideToc: boolean;
6
+ titleLevel: string;
7
+ };
8
+
9
+ export type ApiEndpointElement = HTMLElement & {
10
+ amf: Json;
11
+ inlineMethods: boolean;
12
+ noNavigation: boolean;
13
+ selected: string;
14
+ endpoint: Json;
15
+ noTryIt: boolean;
16
+ };
17
+
18
+ export type ApiMethodElement = HTMLElement & {
19
+ amf: Json;
20
+ noNavigation: boolean;
21
+ endpoint: Json;
22
+ method: Json;
23
+ noTryIt: boolean;
24
+ };
25
+
26
+ export type ApiSecurityElement = HTMLElement & {
27
+ amf: Json;
28
+ security: Json;
29
+ };
30
+
31
+ export type ApiTypeElement = HTMLElement & {
32
+ amf: Json;
33
+ type: Json;
34
+ mediaTypes: Json;
35
+ };
36
+
37
+ export type ApiDocElement = HTMLElement & {
38
+ amf: Json;
39
+ shape: Json;
40
+ };
41
+
42
+ export type AmfModel = Json;
43
+
44
+ export interface AmfParser {
45
+ parse(): void;
46
+ parsedModel: any;
47
+ }
48
+
49
+ export interface TopicModel {
50
+ id: string;
51
+ type: string;
52
+ amf: AmfModel;
53
+ parser: AmfParser;
54
+ }
@@ -0,0 +1,117 @@
1
+ import type {
2
+ ApiDocElement,
3
+ ApiEndpointElement,
4
+ ApiMethodElement,
5
+ ApiSecurityElement,
6
+ ApiSummaryElement,
7
+ ApiTypeElement
8
+ } from "./types";
9
+
10
+ import { Json } from "@lwrjs/types";
11
+
12
+ export function createSummaryElement(amf: Json): HTMLElement {
13
+ const summaryElement: ApiSummaryElement = document.createElement(
14
+ "api-summary"
15
+ ) as ApiSummaryElement;
16
+ summaryElement.amf = amf;
17
+ summaryElement.hideToc = true;
18
+ summaryElement.titleLevel = "1";
19
+ summaryElement.setAttribute(
20
+ "exportparts",
21
+ [
22
+ "api-title",
23
+ "api-title-label",
24
+ "api-version",
25
+ "marked-description",
26
+ "info-section",
27
+ "info-inline-desc",
28
+ "license-section",
29
+ "separator",
30
+ "toc"
31
+ ].join(",")
32
+ );
33
+ return summaryElement;
34
+ }
35
+
36
+ /**
37
+ * Creates a `api-endpoint-documentation` web element from web API and current selection.
38
+ */
39
+ export function createEndpointElement(
40
+ amf: Json,
41
+ endpointModel: Json,
42
+ selected: string
43
+ ): HTMLElement {
44
+ const el: ApiEndpointElement = document.createElement(
45
+ "api-endpoint-documentation"
46
+ ) as ApiEndpointElement;
47
+ el.amf = amf;
48
+ el.inlineMethods = false;
49
+ el.noNavigation = true;
50
+ el.selected = selected;
51
+ el.endpoint = endpointModel;
52
+ el.noTryIt = true;
53
+ return el;
54
+ }
55
+
56
+ /**
57
+ * Creates a `api-method-documentation` web element from web API and current selection.
58
+ */
59
+ export function createMethodElement(
60
+ amf: Json,
61
+ endpointMethodModel: Json,
62
+ methodModel: Json
63
+ ): HTMLElement {
64
+ const el: ApiMethodElement = document.createElement(
65
+ "api-method-documentation"
66
+ ) as ApiMethodElement;
67
+ el.amf = amf;
68
+ el.noNavigation = true;
69
+ el.endpoint = endpointMethodModel;
70
+ el.method = methodModel;
71
+ el.noTryIt = true;
72
+ el.setAttribute("renderSecurity", "");
73
+ el.setAttribute("renderCodeSnippets", "");
74
+ return el;
75
+ }
76
+
77
+ /**
78
+ * Creates a documentation element for Security AMF type
79
+ *
80
+ */
81
+ export function createSecurityElement(amf: Json, securityModel: Json): HTMLElement {
82
+ const el: ApiSecurityElement = document.createElement(
83
+ "api-security-documentation"
84
+ ) as ApiSecurityElement;
85
+ el.setAttribute("exportparts", ["security-title"].join(","));
86
+ el.amf = amf;
87
+ el.security = securityModel;
88
+ return el;
89
+ }
90
+
91
+ /**
92
+ * Creates a documentation element for Type AMF type
93
+ *
94
+ * @param {string} amfId Reference ID as passed in from amfConfig
95
+ * @param {string} selected Currently selected `@id`.
96
+ */
97
+ export function createTypeElement(amf: Json, typeModel: Json, mediaTypes: Json): HTMLElement {
98
+ const el: ApiTypeElement = document.createElement("api-type-documentation") as ApiTypeElement;
99
+ el.setAttribute("exportparts", ["type-title"].join(","));
100
+ el.amf = amf;
101
+ el.type = typeModel;
102
+ el.mediaTypes = mediaTypes;
103
+ return el;
104
+ }
105
+
106
+ /**
107
+ * Creates a documentation element for Docs AMF type
108
+ *
109
+ * @param {string} amfId Reference ID as passed in from amfConfig
110
+ * @param {string} selected Currently selected `@id`.
111
+ */
112
+ export function createDocumentationElement(amf: Json, docsModel: Json): HTMLElement {
113
+ const el: ApiDocElement = document.createElement("api-documentation-document") as ApiDocElement;
114
+ el.amf = amf;
115
+ el.shape = docsModel;
116
+ return el;
117
+ }
@@ -109,180 +109,174 @@ export default class Content extends LightningElement {
109
109
  insertDocHtml(docContent?: string) {
110
110
  const divEl = this.getCleanContainer();
111
111
 
112
- // Some simple data mutation to make Prism work on-the-fly with the existing datasource
113
- const templateEl = document.createElement("template");
114
- // eslint-disable-next-line no-use-before-define
115
- templateEl.innerHTML = docContent || this.docContent;
116
-
117
- // Query the code blocks and create a dx-code-block component that contains the code
118
- const codeBlockEls =
119
- templateEl.content.querySelectorAll(".codeSection");
120
- codeBlockEls.forEach((codeBlockEl) => {
121
- codeBlockEl.setAttribute("lwc:dom", "manual");
122
- const classList = codeBlockEl.firstChild.classList;
123
- let language = "";
124
- for (const key in classList) {
125
- if (typeof classList[key] === "string") {
126
- const className = classList[key];
127
- if (className.startsWith("brush:")) {
128
- language = className.split(":")[1];
112
+ if (divEl) {
113
+ divEl.innerHTML = docContent || this.docContent;
114
+
115
+ // Query the code blocks and create a dx-code-block component that contains the code
116
+ const codeBlockEls = divEl.querySelectorAll(".codeSection");
117
+ codeBlockEls.forEach((codeBlockEl) => {
118
+ codeBlockEl.setAttribute("lwc:dom", "manual");
119
+ const classList = codeBlockEl.firstChild.classList;
120
+ let language = "";
121
+ for (const key in classList) {
122
+ if (typeof classList[key] === "string") {
123
+ const className = classList[key];
124
+ if (className.startsWith("brush:")) {
125
+ language = className.split(":")[1];
126
+ }
129
127
  }
130
128
  }
131
- }
132
- const blockCmp = createElement("dx-code-block", { is: CodeBlock });
133
- Object.assign(blockCmp, {
134
- codeBlock: codeBlockEl.innerHTML,
135
- // ! Hot fix for incoming html tags from couchdb for xml blocks, fix me soon please
136
- language: LANGUAGE_MAP[language] || language,
137
- theme: this.codeBlockTheme,
138
- title: "", // Default no title.
139
- variant: this.codeBlockType,
140
- isEncoded: true
129
+ const blockCmp = createElement("dx-code-block", {
130
+ is: CodeBlock
131
+ });
132
+ Object.assign(blockCmp, {
133
+ codeBlock: codeBlockEl.innerHTML,
134
+ // ! Hot fix for incoming html tags from couchdb for xml blocks, fix me soon please
135
+ language: LANGUAGE_MAP[language] || language,
136
+ theme: this.codeBlockTheme,
137
+ title: "", // Default no title.
138
+ variant: this.codeBlockType,
139
+ isEncoded: true
140
+ });
141
+ // eslint-disable-next-line no-use-before-define
142
+ codeBlockEl.innerHTML = "";
143
+ codeBlockEl.appendChild(blockCmp);
141
144
  });
142
- // eslint-disable-next-line no-use-before-define
143
- codeBlockEl.innerHTML = "";
144
- codeBlockEl.appendChild(blockCmp);
145
- });
146
145
 
147
- // Query the callouts and create a doc-content-callout component that contains the code
148
- const calloutEls = templateEl.content.querySelectorAll(".message");
149
- calloutEls.forEach((calloutEl) => {
150
- const calloutCompEl = createElement("doc-content-callout", {
151
- is: ContentCallout
152
- });
153
- const detailEls = calloutEl.querySelectorAll(
154
- "p, div.data, ol, ul, .codeSection, .mediaBd > span.ph"
155
- );
156
- detailEls.forEach((detailEl) => {
157
- calloutCompEl.appendChild(detailEl);
158
- });
159
- const type = calloutEl.querySelector("h4").textContent;
160
- const typeLower = type.toLowerCase();
161
- Object.assign(calloutCompEl, {
162
- title: type,
163
- variant: typeLower
146
+ // Query the callouts and create a doc-content-callout component that contains the code
147
+ const calloutEls = divEl.querySelectorAll(".message");
148
+ calloutEls.forEach((calloutEl) => {
149
+ const calloutCompEl = createElement("doc-content-callout", {
150
+ is: ContentCallout
151
+ });
152
+ const detailEls = calloutEl.querySelectorAll(
153
+ "p, div.data, ol, ul, .codeSection, .mediaBd > span.ph"
154
+ );
155
+ detailEls.forEach((detailEl) => {
156
+ calloutCompEl.appendChild(detailEl);
157
+ });
158
+ const type = calloutEl.querySelector("h4").textContent;
159
+ const typeLower = type.toLowerCase();
160
+ Object.assign(calloutCompEl, {
161
+ title: type,
162
+ variant: typeLower
163
+ });
164
+ // eslint-disable-next-line no-use-before-define
165
+ calloutEl.innerHTML = "";
166
+ calloutEl.appendChild(calloutCompEl);
164
167
  });
165
- // eslint-disable-next-line no-use-before-define
166
- calloutEl.innerHTML = "";
167
- calloutEl.appendChild(calloutCompEl);
168
- });
169
168
 
170
- // Modify links to work with any domain, links that start with "#" are excluded
171
- const anchorEls =
172
- templateEl.content.querySelectorAll("a:not([href^='#'])");
173
-
174
- anchorEls.forEach((anchorEl) => {
175
- if (
176
- anchorEl.textContent.includes("Next ") ||
177
- anchorEl.textContent.includes("← Previous")
178
- ) {
179
- if (this.showPaginationButtons) {
180
- this.renderPaginationButton(anchorEl);
181
- } else {
182
- anchorEl.remove();
183
- }
184
- }
185
-
186
- // ! This is a hack
187
- // Normalize urls in case it doesn't come complete.
188
- if (anchorEl.href.startsWith("atlas.")) {
189
- anchorEl.href = "/docs/" + anchorEl.href;
190
- }
191
-
192
- const href = anchorEl.href.split("/");
193
- if (
194
- (href[3] === this.pageReference.docId && this.isStorybook) ||
195
- href[4] === this.pageReference.docId ||
196
- href[6] === this.pageReference.docId
197
- ) {
198
- let updatedURL;
199
- switch (href.length) {
200
- case 8:
201
- updatedURL = href.splice(5).join("/");
202
- break;
203
- case 7:
204
- updatedURL = href.splice(4).join("/");
205
- break;
206
- case 6:
207
- updatedURL = href.splice(3).join("/");
208
- break;
209
- default:
210
- updatedURL = href.splice(6).join("/");
211
- break;
169
+ // Modify links to work with any domain, links that start with "#" are excluded
170
+ const anchorEls = divEl.querySelectorAll("a:not([href^='#'])");
171
+
172
+ anchorEls.forEach((anchorEl) => {
173
+ if (
174
+ anchorEl.textContent.includes("Next →") ||
175
+ anchorEl.textContent.includes(" Previous")
176
+ ) {
177
+ if (this.showPaginationButtons) {
178
+ this.renderPaginationButton(anchorEl);
179
+ } else {
180
+ anchorEl.remove();
181
+ }
212
182
  }
213
- anchorEl.addEventListener(
214
- "click",
215
- // eslint-disable-next-line no-use-before-define
216
- this.handleNavClick.bind(this)
217
- );
218
- // anchor href event is not propagated here as we want SPA nature.
219
- // But in prerender.io - as javascript is not executed, we want the anchor links are proper (absolute urls).
220
- anchorEl.setAttribute("href", "/docs/" + updatedURL);
221
- anchorEl.setAttribute("data-id", "docs/" + updatedURL);
222
- return;
223
- }
224
-
225
- anchorEl.setAttribute("data-id", anchorEl.href);
226
- });
227
183
 
228
- // Modify image src to work with any domain and replace images/iframes with doc-content-media
229
- const imgEls = templateEl.content.querySelectorAll("img, iframe");
230
-
231
- imgEls.forEach((mediaEl) => {
232
- const isImage = mediaEl.nodeName === "IMG";
233
- let src = mediaEl.getAttribute("src");
234
- if (!src) {
235
- return;
236
- }
237
- const alt = mediaEl.getAttribute("alt");
238
- const title = mediaEl.getAttribute("title");
239
- const label = mediaEl.getAttribute("label");
240
- const width = mediaEl.getAttribute("width");
241
- const height = mediaEl.getAttribute("height");
242
-
243
- if (isImage) {
244
- src = src.startsWith("/")
245
- ? `https://developer.salesforce.com${src}`
246
- : src.replace(
247
- window.location.origin,
248
- "https://developer.salesforce.com"
249
- );
250
-
251
- const img: HTMLImageElement = document.createElement("img");
252
- img.src = src;
253
- if (alt) {
254
- img.alt = alt;
184
+ // ! This is a hack
185
+ // Normalize urls in case it doesn't come complete.
186
+ if (anchorEl.href.startsWith("atlas.")) {
187
+ anchorEl.href = "/docs/" + anchorEl.href;
255
188
  }
256
- if (title) {
257
- img.title = title;
258
- }
259
- if (height) {
260
- img.height = parseFloat(height);
261
- }
262
- if (width) {
263
- img.width = parseFloat(width);
189
+
190
+ const href = anchorEl.href.split("/");
191
+ if (
192
+ (href[3] === this.pageReference.docId &&
193
+ this.isStorybook) ||
194
+ href[4] === this.pageReference.docId ||
195
+ href[6] === this.pageReference.docId
196
+ ) {
197
+ let updatedURL;
198
+ switch (href.length) {
199
+ case 8:
200
+ updatedURL = href.splice(5).join("/");
201
+ break;
202
+ case 7:
203
+ updatedURL = href.splice(4).join("/");
204
+ break;
205
+ case 6:
206
+ updatedURL = href.splice(3).join("/");
207
+ break;
208
+ default:
209
+ updatedURL = href.splice(6).join("/");
210
+ break;
211
+ }
212
+ anchorEl.addEventListener(
213
+ "click",
214
+ // eslint-disable-next-line no-use-before-define
215
+ this.handleNavClick.bind(this)
216
+ );
217
+ // anchor href event is not propagated here as we want SPA nature.
218
+ // But in prerender.io - as javascript is not executed, we want the anchor links are proper (absolute urls).
219
+ anchorEl.setAttribute("href", "/docs/" + updatedURL);
220
+ anchorEl.setAttribute("data-id", "docs/" + updatedURL);
221
+ return;
264
222
  }
265
223
 
266
- img.className = "content-image";
267
- mediaEl.parentNode!.insertBefore(img, mediaEl);
268
- } else {
269
- const contentMediaEl = createElement("doc-content-media", {
270
- is: ContentMedia
271
- });
272
- Object.assign(contentMediaEl, {
273
- contentType: "iframe",
274
- contentSrc: src,
275
- mediaTitle: alt || title || label
276
- });
277
- mediaEl.parentNode!.insertBefore(contentMediaEl, mediaEl);
278
- }
279
- mediaEl.remove();
280
- });
224
+ anchorEl.setAttribute("data-id", anchorEl.href);
225
+ });
281
226
 
282
- if (divEl) {
283
- // eslint-disable-next-line no-use-before-define
284
- divEl.innerHTML = "";
285
- divEl.append(templateEl.content);
227
+ // Modify image src to work with any domain and replace images/iframes with doc-content-media
228
+ const imgEls = divEl.querySelectorAll("img, iframe");
229
+
230
+ imgEls.forEach((mediaEl) => {
231
+ const isImage = mediaEl.nodeName === "IMG";
232
+ let src = mediaEl.getAttribute("src");
233
+ if (!src) {
234
+ return;
235
+ }
236
+ const alt = mediaEl.getAttribute("alt");
237
+ const title = mediaEl.getAttribute("title");
238
+ const label = mediaEl.getAttribute("label");
239
+ const width = mediaEl.getAttribute("width");
240
+ const height = mediaEl.getAttribute("height");
241
+
242
+ if (isImage) {
243
+ src = src.startsWith("/")
244
+ ? `https://developer.salesforce.com${src}`
245
+ : src.replace(
246
+ window.location.origin,
247
+ "https://developer.salesforce.com"
248
+ );
249
+
250
+ const img: HTMLImageElement = document.createElement("img");
251
+ img.src = src;
252
+ if (alt) {
253
+ img.alt = alt;
254
+ }
255
+ if (title) {
256
+ img.title = title;
257
+ }
258
+ if (height) {
259
+ img.height = parseFloat(height);
260
+ }
261
+ if (width) {
262
+ img.width = parseFloat(width);
263
+ }
264
+
265
+ img.className = "content-image";
266
+ mediaEl.parentNode!.insertBefore(img, mediaEl);
267
+ } else {
268
+ const contentMediaEl = createElement("doc-content-media", {
269
+ is: ContentMedia
270
+ });
271
+ Object.assign(contentMediaEl, {
272
+ contentType: "iframe",
273
+ contentSrc: src,
274
+ mediaTitle: alt || title || label
275
+ });
276
+ mediaEl.parentNode!.insertBefore(contentMediaEl, mediaEl);
277
+ }
278
+ mediaEl.remove();
279
+ });
286
280
  }
287
281
 
288
282
  // Once the html has been corectly modified, naviage to the page reference on the page