@salesforcedevs/docs-components 0.14.1 → 0.16.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.
- package/package.json +2 -2
- package/src/modules/doc/content/__tests__/content.test.ts +201 -9
- package/src/modules/doc/content/__tests__/mockDocContent.ts +56 -0
- package/src/modules/doc/content/__tests__/mockSidebar.ts +81 -0
- package/src/modules/doc/content/content.css +4 -0
- package/src/modules/doc/content/content.stories.ts +40 -0
- package/src/modules/doc/content/content.ts +63 -16
- package/src/modules/doc/header/__tests__/header.test.ts +24 -1
- package/src/modules/doc/header/__tests__/mockProps.ts +3 -0
- package/src/modules/doc/header/header.html +4 -1
- package/src/modules/doc/header/header.stories.ts +30 -0
- package/src/modules/doc/header/header.ts +3 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforcedevs/docs-components",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.2",
|
|
4
4
|
"description": "Docs Lightning web components for DSC",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "index.js",
|
|
@@ -14,5 +14,5 @@
|
|
|
14
14
|
"publishConfig": {
|
|
15
15
|
"access": "public"
|
|
16
16
|
},
|
|
17
|
-
"gitHead": "
|
|
17
|
+
"gitHead": "4695c8e7dc16a958beb7717cfe01e432c57f5872"
|
|
18
18
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import CodeBlock from "dx/codeBlock";
|
|
1
2
|
import { createRenderComponent } from "utils/tests";
|
|
2
3
|
import Content from "../content";
|
|
3
4
|
import * as mockContent from "./mockDocContent";
|
|
@@ -34,9 +35,8 @@ describe("doc-content", () => {
|
|
|
34
35
|
pageReference: mockPageReference,
|
|
35
36
|
_isStorybook: false
|
|
36
37
|
});
|
|
37
|
-
const empty_dx_buttons =
|
|
38
|
-
"dx-button"
|
|
39
|
-
);
|
|
38
|
+
const empty_dx_buttons =
|
|
39
|
+
c_no_buttons.shadowRoot.querySelectorAll("dx-button");
|
|
40
40
|
expect(empty_dx_buttons.length).toEqual(0);
|
|
41
41
|
});
|
|
42
42
|
|
|
@@ -52,9 +52,8 @@ describe("doc-content", () => {
|
|
|
52
52
|
expect(contentEl).not.toBeNull();
|
|
53
53
|
const images = component.shadowRoot.querySelectorAll("img");
|
|
54
54
|
expect(images.length).toEqual(3);
|
|
55
|
-
const contentMediaEls =
|
|
56
|
-
"doc-content-media"
|
|
57
|
-
);
|
|
55
|
+
const contentMediaEls =
|
|
56
|
+
component.shadowRoot.querySelectorAll("doc-content-media");
|
|
58
57
|
expect(contentMediaEls.length).toEqual(0);
|
|
59
58
|
});
|
|
60
59
|
|
|
@@ -70,9 +69,8 @@ describe("doc-content", () => {
|
|
|
70
69
|
expect(contentEl).not.toBeNull();
|
|
71
70
|
const images = component.shadowRoot.querySelectorAll("iframe");
|
|
72
71
|
expect(images.length).toEqual(0);
|
|
73
|
-
const contentMediaEls =
|
|
74
|
-
"doc-content-media"
|
|
75
|
-
);
|
|
72
|
+
const contentMediaEls =
|
|
73
|
+
component.shadowRoot.querySelectorAll("doc-content-media");
|
|
76
74
|
expect(contentMediaEls.length).toEqual(2);
|
|
77
75
|
contentMediaEls.forEach((contentMedia) => {
|
|
78
76
|
expect(contentMedia.contentType).toEqual("iframe");
|
|
@@ -117,4 +115,198 @@ describe("doc-content", () => {
|
|
|
117
115
|
expect(notes[2].querySelector("ol")).not.toBeNull();
|
|
118
116
|
expect(notes[3].querySelector("dx-code-block")).not.toBeNull();
|
|
119
117
|
});
|
|
118
|
+
|
|
119
|
+
it("highlights text that matches search criteria", () => {
|
|
120
|
+
const component = render({
|
|
121
|
+
docsData: mockContent.content,
|
|
122
|
+
pageReference: mockPageReference,
|
|
123
|
+
isStorybook: true
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
const contentEl = component.shadowRoot.querySelector(
|
|
127
|
+
'[data-name="content"]'
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
expect(contentEl.querySelectorAll("mark")).toHaveLength(0);
|
|
131
|
+
|
|
132
|
+
contentEl.dispatchEvent(
|
|
133
|
+
new CustomEvent("highlightedtermchange", {
|
|
134
|
+
detail: "apex",
|
|
135
|
+
composed: true,
|
|
136
|
+
bubbles: true
|
|
137
|
+
})
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
expect(contentEl.querySelectorAll("mark")).toHaveLength(14);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it("doesn't highlight elements that contains dx/docs components", () => {
|
|
144
|
+
const searchTerm = "customreport";
|
|
145
|
+
|
|
146
|
+
const component = render({
|
|
147
|
+
docsData: mockContent.sampleCodeBlockAndNote,
|
|
148
|
+
pageReference: mockPageReference,
|
|
149
|
+
isStorybook: true
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
const contentEl = component.shadowRoot.querySelector(
|
|
153
|
+
'[data-name="content"]'
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
expect(contentEl.querySelectorAll("mark")).toHaveLength(0);
|
|
157
|
+
|
|
158
|
+
contentEl.dispatchEvent(
|
|
159
|
+
new CustomEvent("highlightedtermchange", {
|
|
160
|
+
detail: searchTerm,
|
|
161
|
+
composed: true,
|
|
162
|
+
bubbles: true
|
|
163
|
+
})
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
const marks: Array<HTMLElement> = contentEl.querySelectorAll("mark");
|
|
167
|
+
|
|
168
|
+
expect(marks).toHaveLength(0);
|
|
169
|
+
|
|
170
|
+
const code: CodeBlock = contentEl.querySelector("dx-code-block");
|
|
171
|
+
expect(code).not.toBeNull();
|
|
172
|
+
expect(code.codeBlock).toBeTruthy();
|
|
173
|
+
expect(contentEl.querySelector("doc-content-callout")).not.toBeNull();
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
it("doesn't highlight terms separated by html tags", () => {
|
|
177
|
+
const searchTerm = "loadData within";
|
|
178
|
+
|
|
179
|
+
const component = render({
|
|
180
|
+
docsData: mockContent.sampleCodeBlockAndNote,
|
|
181
|
+
pageReference: mockPageReference,
|
|
182
|
+
isStorybook: true
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
const contentEl = component.shadowRoot.querySelector(
|
|
186
|
+
'[data-name="content"]'
|
|
187
|
+
);
|
|
188
|
+
|
|
189
|
+
contentEl.dispatchEvent(
|
|
190
|
+
new CustomEvent("highlightedtermchange", {
|
|
191
|
+
detail: searchTerm,
|
|
192
|
+
composed: true,
|
|
193
|
+
bubbles: true
|
|
194
|
+
})
|
|
195
|
+
);
|
|
196
|
+
|
|
197
|
+
const marks: Array<HTMLElement> =
|
|
198
|
+
component.shadowRoot.querySelectorAll("mark");
|
|
199
|
+
expect(marks).toHaveLength(0);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it("escapes regex especial characters", () => {
|
|
203
|
+
const searchTerm = "used.+";
|
|
204
|
+
|
|
205
|
+
const component = render({
|
|
206
|
+
docsData: mockContent.sampleCodeBlockAndNote,
|
|
207
|
+
pageReference: mockPageReference,
|
|
208
|
+
isStorybook: true
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
const contentEl = component.shadowRoot.querySelector(
|
|
212
|
+
'[data-name="content"]'
|
|
213
|
+
);
|
|
214
|
+
|
|
215
|
+
contentEl.dispatchEvent(
|
|
216
|
+
new CustomEvent("highlightedtermchange", {
|
|
217
|
+
detail: searchTerm,
|
|
218
|
+
composed: true,
|
|
219
|
+
bubbles: true
|
|
220
|
+
})
|
|
221
|
+
);
|
|
222
|
+
|
|
223
|
+
const marks: Array<HTMLElement> =
|
|
224
|
+
component.shadowRoot.querySelectorAll("mark");
|
|
225
|
+
expect(marks).toHaveLength(0);
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
it("cleans previous search result before searching for a new term", () => {
|
|
229
|
+
const firstSearch = "verify";
|
|
230
|
+
const secondSearch = "sObject";
|
|
231
|
+
|
|
232
|
+
const component = render({
|
|
233
|
+
docsData: mockContent.sampleCodeBlockAndNote,
|
|
234
|
+
pageReference: mockPageReference,
|
|
235
|
+
isStorybook: true
|
|
236
|
+
});
|
|
237
|
+
|
|
238
|
+
const contentEl = component.shadowRoot.querySelector(
|
|
239
|
+
'[data-name="content"]'
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
contentEl.dispatchEvent(
|
|
243
|
+
new CustomEvent("highlightedtermchange", {
|
|
244
|
+
detail: firstSearch,
|
|
245
|
+
composed: true,
|
|
246
|
+
bubbles: true
|
|
247
|
+
})
|
|
248
|
+
);
|
|
249
|
+
|
|
250
|
+
const firstMarks: Array<HTMLElement> =
|
|
251
|
+
component.shadowRoot.querySelectorAll("mark");
|
|
252
|
+
expect(firstMarks).toHaveLength(2);
|
|
253
|
+
firstMarks.forEach(({ textContent }) =>
|
|
254
|
+
expect(textContent).toBe(firstSearch)
|
|
255
|
+
);
|
|
256
|
+
|
|
257
|
+
contentEl.dispatchEvent(
|
|
258
|
+
new CustomEvent("highlightedtermchange", {
|
|
259
|
+
detail: secondSearch,
|
|
260
|
+
composed: true,
|
|
261
|
+
bubbles: true
|
|
262
|
+
})
|
|
263
|
+
);
|
|
264
|
+
|
|
265
|
+
const secondMarks: Array<HTMLElement> =
|
|
266
|
+
component.shadowRoot.querySelectorAll("mark");
|
|
267
|
+
expect(secondMarks).toHaveLength(1);
|
|
268
|
+
secondMarks.forEach(({ textContent }) =>
|
|
269
|
+
expect(textContent).toBe(secondSearch)
|
|
270
|
+
);
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
it("cleans all marks if the search term is empty string", () => {
|
|
274
|
+
const firstSearch = "verify";
|
|
275
|
+
const secondSearch = "";
|
|
276
|
+
|
|
277
|
+
const component = render({
|
|
278
|
+
docsData: mockContent.sampleCodeBlockAndNote,
|
|
279
|
+
pageReference: mockPageReference,
|
|
280
|
+
isStorybook: true
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
const contentEl = component.shadowRoot.querySelector(
|
|
284
|
+
'[data-name="content"]'
|
|
285
|
+
);
|
|
286
|
+
|
|
287
|
+
contentEl.dispatchEvent(
|
|
288
|
+
new CustomEvent("highlightedtermchange", {
|
|
289
|
+
detail: firstSearch,
|
|
290
|
+
composed: true,
|
|
291
|
+
bubbles: true
|
|
292
|
+
})
|
|
293
|
+
);
|
|
294
|
+
|
|
295
|
+
const firstMarks: Array<HTMLElement> =
|
|
296
|
+
component.shadowRoot.querySelectorAll("mark");
|
|
297
|
+
expect(firstMarks).toHaveLength(2);
|
|
298
|
+
firstMarks.forEach(({ textContent }) =>
|
|
299
|
+
expect(textContent).toBe(firstSearch)
|
|
300
|
+
);
|
|
301
|
+
|
|
302
|
+
contentEl.dispatchEvent(
|
|
303
|
+
new CustomEvent("highlightedtermchange", {
|
|
304
|
+
detail: secondSearch,
|
|
305
|
+
composed: true,
|
|
306
|
+
bubbles: true
|
|
307
|
+
})
|
|
308
|
+
);
|
|
309
|
+
|
|
310
|
+
expect(component.shadowRoot.querySelectorAll("mark")).toHaveLength(0);
|
|
311
|
+
});
|
|
120
312
|
});
|
|
@@ -173,6 +173,35 @@ export const withTable = `<table>
|
|
|
173
173
|
<td>X</td>
|
|
174
174
|
<td>The password of the SSO user account</td>
|
|
175
175
|
</tr>
|
|
176
|
+
<tr>
|
|
177
|
+
<td><code>list</code></td>
|
|
178
|
+
<td>X</td>
|
|
179
|
+
<td class="with-list">
|
|
180
|
+
The items in this list should not have larger text than normal:
|
|
181
|
+
<ul>
|
|
182
|
+
<li class="li">Item one</li>
|
|
183
|
+
<li class="li">Item two</li>
|
|
184
|
+
</ul>
|
|
185
|
+
</td>
|
|
186
|
+
</tr>
|
|
187
|
+
<tr>
|
|
188
|
+
<td><a href="#">link</a></td>
|
|
189
|
+
<td>X</td>
|
|
190
|
+
<td class="with-link-and-p">
|
|
191
|
+
The link text should not be larger than normal.
|
|
192
|
+
<p>Paragraph text should not be larger either.</p>
|
|
193
|
+
</td>
|
|
194
|
+
</tr>
|
|
195
|
+
<tr>
|
|
196
|
+
<td><code>callout</code></td>
|
|
197
|
+
<td></td>
|
|
198
|
+
<td class="with-callout">
|
|
199
|
+
This callout should still have larger text:
|
|
200
|
+
<doc-content-callout title="Callout test" variant="note">
|
|
201
|
+
<p>The text here should *not* be the same size as other table text.</p>
|
|
202
|
+
</doc-content-callout>
|
|
203
|
+
</td>
|
|
204
|
+
</tr>
|
|
176
205
|
</tbody>
|
|
177
206
|
</table>`;
|
|
178
207
|
|
|
@@ -284,6 +313,33 @@ const noteWithCodeBlock = `<div class='box message info'>
|
|
|
284
313
|
</div>
|
|
285
314
|
</div>`;
|
|
286
315
|
|
|
316
|
+
export const sampleCodeBlockAndNote = `
|
|
317
|
+
<h1 class='helpHead1'>Using the instanceof Keyword</h1>
|
|
318
|
+
<p class="p">If you need to verify at run time whether an object is actually an instance of a particular class, use the
|
|
319
|
+
<samp class="codeph apex_code"><span class="statement">instanceof</span></samp> keyword.
|
|
320
|
+
The <samp class="codeph apex_code"><span class="statement">instanceof</span></samp> keyword can only be used to
|
|
321
|
+
verify if the target type in the expression on the right of the keyword is a viable
|
|
322
|
+
alternative for the declared type of the expression on the left.
|
|
323
|
+
</p>
|
|
324
|
+
<div class="p">You could add the following check to the <samp class="codeph apex_code">Report</samp>class in the <a class="xref" href="atlas.en-us.apexcode.meta/apexcode/apex_classes_casting.htm" title="In general, all type information is available at run time. This means that Apex enables casting, that is, a data type of one class can be assigned to a data type of another class, but only if one class is a subclass of the other class. Use casting when you want to convert an object from one data type to another.">classes and casting example</a> before you cast the item back into a <samp class="codeph apex_code">CustomReport</samp> object.
|
|
325
|
+
<div class="codeSection apex_code">
|
|
326
|
+
<pre class="codeblock brush:apex">If (Reports.get(0) <span class="statement">instanceof</span> CustomReport) {\n <span class="onelineComment">// Can safely cast it back to a custom report object</span>\n CustomReport c = (CustomReport) Reports.get(0);\n} Else {\n <span class="onelineComment">// Do something with the non-custom-report.</span>\n}</pre>
|
|
327
|
+
</div>
|
|
328
|
+
</div>
|
|
329
|
+
${noteWithOrderedList}
|
|
330
|
+
<div class="p">
|
|
331
|
+
Follow these steps:
|
|
332
|
+
<ol class="ol enumList">
|
|
333
|
+
<li class="li">Add the data in a .csv file.</li>
|
|
334
|
+
<li class="li">Create a static resource for this file.</li>
|
|
335
|
+
<li class="li">
|
|
336
|
+
Call <samp class="codeph apex_code">Test.loadData</samp> within your test
|
|
337
|
+
method and passing it the sObject type token and the static resource name.
|
|
338
|
+
</li>
|
|
339
|
+
</ol>
|
|
340
|
+
</div>
|
|
341
|
+
`;
|
|
342
|
+
|
|
287
343
|
export const withNotes = `<div>
|
|
288
344
|
${noteWithTable}
|
|
289
345
|
${noteWithUnorderedList}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
export default [
|
|
2
|
+
{
|
|
3
|
+
label: "Getting started",
|
|
4
|
+
name: "started",
|
|
5
|
+
isExpanded: true,
|
|
6
|
+
children: [
|
|
7
|
+
{
|
|
8
|
+
label: "Introduction",
|
|
9
|
+
name: "introduction"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
label: "Getting started",
|
|
13
|
+
name: "started-child"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
label: "Authentication",
|
|
17
|
+
name: "authentication"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
label: "Token",
|
|
21
|
+
name: "token"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
label: "Error",
|
|
25
|
+
name: "error"
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
label: "Limits",
|
|
29
|
+
name: "limit"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
label: "Release note",
|
|
33
|
+
name: "release-note"
|
|
34
|
+
}
|
|
35
|
+
]
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
label: "Einstein Vision",
|
|
39
|
+
name: "einstein-vision",
|
|
40
|
+
children: [
|
|
41
|
+
{
|
|
42
|
+
label: "Introduction",
|
|
43
|
+
name: "einstein-introduction"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
label: "Terminology",
|
|
47
|
+
name: "terminology"
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
label: "Object detection quickstart for beginner",
|
|
51
|
+
name: "object-quickstart",
|
|
52
|
+
isExpanded: true,
|
|
53
|
+
children: [
|
|
54
|
+
{
|
|
55
|
+
label: "Scenario: this block is intended to show how a large text looks like in the sidebar",
|
|
56
|
+
name: "scenario",
|
|
57
|
+
isExpanded: true,
|
|
58
|
+
children: [
|
|
59
|
+
{
|
|
60
|
+
label: "Scenario A: this block is intended to show how a large text looks like in the sidebar",
|
|
61
|
+
name: "scenario-a"
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
label: "Scenario B",
|
|
65
|
+
name: "scenario-b"
|
|
66
|
+
}
|
|
67
|
+
]
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
label: "Prerequisites",
|
|
71
|
+
name: "prerequisites"
|
|
72
|
+
}
|
|
73
|
+
]
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
label: "Best Practices",
|
|
77
|
+
name: "best-practices"
|
|
78
|
+
}
|
|
79
|
+
]
|
|
80
|
+
}
|
|
81
|
+
];
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as mockDocContent from "./__tests__/mockDocContent";
|
|
2
2
|
import mockPageReference from "./__tests__/mockPageReference";
|
|
3
|
+
import mockSidebar from "./__tests__/mockSidebar";
|
|
3
4
|
import { html } from "lit-html";
|
|
4
5
|
|
|
5
6
|
export default {
|
|
@@ -106,3 +107,42 @@ PaginationButtons.args = {
|
|
|
106
107
|
showPaginationButtons: false,
|
|
107
108
|
docsData: mockDocContent.withButtons
|
|
108
109
|
};
|
|
110
|
+
|
|
111
|
+
export const HighlightedTerm = ({ docsData, trees }: any) => html`
|
|
112
|
+
<style>
|
|
113
|
+
.sb-show-main.sb-main-padded {
|
|
114
|
+
padding: 0;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
.container {
|
|
118
|
+
display: flex;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
dx-sidebar {
|
|
122
|
+
--dx-c-sidebar-min-height: 100vh;
|
|
123
|
+
margin-right: 16px;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
doc-content {
|
|
127
|
+
margin: 16px 16px;
|
|
128
|
+
}
|
|
129
|
+
</style>
|
|
130
|
+
|
|
131
|
+
<div class="container">
|
|
132
|
+
<dx-sidebar
|
|
133
|
+
header="Guides"
|
|
134
|
+
trees="${JSON.stringify(trees)}"
|
|
135
|
+
></dx-sidebar>
|
|
136
|
+
<doc-content
|
|
137
|
+
is-storybook="true"
|
|
138
|
+
page-reference="${JSON.stringify(mockPageReference)}"
|
|
139
|
+
docs-data="${docsData}"
|
|
140
|
+
></doc-content>
|
|
141
|
+
</div>
|
|
142
|
+
`;
|
|
143
|
+
|
|
144
|
+
HighlightedTerm.args = {
|
|
145
|
+
...defaultArgs,
|
|
146
|
+
docsData: mockDocContent.sampleCodeBlockAndNote,
|
|
147
|
+
trees: mockSidebar
|
|
148
|
+
};
|
|
@@ -1,10 +1,27 @@
|
|
|
1
1
|
/* eslint-disable @lwc/lwc/no-inner-html */
|
|
2
2
|
import { createElement, LightningElement, api, track } from "lwc";
|
|
3
|
-
import { DocContent, PageReference } from "
|
|
3
|
+
import { DocContent, PageReference } from "typings/custom";
|
|
4
4
|
import ContentCallout from "doc/contentCallout";
|
|
5
5
|
import CodeBlock from "dx/codeBlock";
|
|
6
6
|
import ContentMedia from "doc/contentMedia";
|
|
7
7
|
import Button from "dx/button";
|
|
8
|
+
import { highlightTerms } from "utils/highlight";
|
|
9
|
+
|
|
10
|
+
const ALLOWED_ELEMENTS = [
|
|
11
|
+
"p",
|
|
12
|
+
".p",
|
|
13
|
+
".shortdesc",
|
|
14
|
+
"h1",
|
|
15
|
+
"h2",
|
|
16
|
+
"h3",
|
|
17
|
+
"h4",
|
|
18
|
+
"h5",
|
|
19
|
+
"h6",
|
|
20
|
+
"li",
|
|
21
|
+
"dl",
|
|
22
|
+
"th",
|
|
23
|
+
"td"
|
|
24
|
+
];
|
|
8
25
|
|
|
9
26
|
const LANGUAGE_MAP: { [key: string]: string } = {
|
|
10
27
|
js: "javascript"
|
|
@@ -15,31 +32,48 @@ export default class Content extends LightningElement {
|
|
|
15
32
|
@api pageReference!: PageReference;
|
|
16
33
|
@api codeBlockType: string = "card";
|
|
17
34
|
@api showPaginationButtons: boolean = false;
|
|
35
|
+
|
|
18
36
|
@api
|
|
19
37
|
set docsData(value) {
|
|
20
38
|
this._docRendered = false;
|
|
21
|
-
this.docContent = value;
|
|
39
|
+
this.docContent = (value && value.trim()) || "";
|
|
22
40
|
}
|
|
41
|
+
|
|
23
42
|
get docsData() {
|
|
24
43
|
return this.docContent;
|
|
25
44
|
}
|
|
26
|
-
|
|
45
|
+
|
|
27
46
|
@api
|
|
28
47
|
set codeBlockTheme(value) {
|
|
29
48
|
this._codeBlockTheme = value;
|
|
30
49
|
}
|
|
50
|
+
|
|
31
51
|
get codeBlockTheme() {
|
|
32
52
|
return this._codeBlockTheme;
|
|
33
53
|
}
|
|
34
54
|
|
|
35
55
|
@track docContent: DocContent = "";
|
|
56
|
+
_codeBlockTheme: string = "dark";
|
|
36
57
|
_docRendered: boolean = false;
|
|
37
58
|
originalCodeBlockThemeValue: String = "";
|
|
59
|
+
|
|
38
60
|
connectedCallback() {
|
|
39
61
|
this.template.addEventListener(
|
|
40
62
|
"themechange",
|
|
41
63
|
this.updateTheme.bind(this) // eslint-disableline no-use-before-define
|
|
42
64
|
);
|
|
65
|
+
|
|
66
|
+
window.addEventListener(
|
|
67
|
+
"highlightedtermchange",
|
|
68
|
+
this.updateHighlighted
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
disconnectedCallback(): void {
|
|
73
|
+
window.removeEventListener(
|
|
74
|
+
"highlightedtermchange",
|
|
75
|
+
this.updateHighlighted
|
|
76
|
+
);
|
|
43
77
|
}
|
|
44
78
|
|
|
45
79
|
updateTheme() {
|
|
@@ -72,19 +106,17 @@ export default class Content extends LightningElement {
|
|
|
72
106
|
// We don't use any tracked field here. The challenge is that
|
|
73
107
|
// for security reasons you can't pass pure HTML via a class
|
|
74
108
|
// field to the template. Hence we manipulate the DOM manually.
|
|
75
|
-
insertDocHtml() {
|
|
76
|
-
const divEl = this.
|
|
109
|
+
insertDocHtml(docContent?: string) {
|
|
110
|
+
const divEl = this.getCleanContainer();
|
|
77
111
|
|
|
78
112
|
// Some simple data mutation to make Prism work on-the-fly with the existing datasource
|
|
79
113
|
const templateEl = document.createElement("template");
|
|
80
|
-
this.docContent = this.docContent.trim();
|
|
81
114
|
// eslint-disable-next-line no-use-before-define
|
|
82
|
-
templateEl.innerHTML = this.docContent;
|
|
115
|
+
templateEl.innerHTML = docContent || this.docContent;
|
|
83
116
|
|
|
84
117
|
// Query the code blocks and create a dx-code-block component that contains the code
|
|
85
|
-
const codeBlockEls =
|
|
86
|
-
".codeSection"
|
|
87
|
-
);
|
|
118
|
+
const codeBlockEls =
|
|
119
|
+
templateEl.content.querySelectorAll(".codeSection");
|
|
88
120
|
codeBlockEls.forEach((codeBlockEl) => {
|
|
89
121
|
codeBlockEl.setAttribute("lwc:dom", "manual");
|
|
90
122
|
const classList = codeBlockEl.firstChild.classList;
|
|
@@ -136,9 +168,8 @@ export default class Content extends LightningElement {
|
|
|
136
168
|
});
|
|
137
169
|
|
|
138
170
|
// Modify links to work with any domain, links that start with "#" are excluded
|
|
139
|
-
const anchorEls =
|
|
140
|
-
"a:not([href^='#'])"
|
|
141
|
-
);
|
|
171
|
+
const anchorEls =
|
|
172
|
+
templateEl.content.querySelectorAll("a:not([href^='#'])");
|
|
142
173
|
anchorEls.forEach((anchorEl) => {
|
|
143
174
|
if (
|
|
144
175
|
anchorEl.textContent.includes("Next →") ||
|
|
@@ -253,6 +284,15 @@ export default class Content extends LightningElement {
|
|
|
253
284
|
}
|
|
254
285
|
}
|
|
255
286
|
|
|
287
|
+
private getCleanContainer(): HTMLElement | null {
|
|
288
|
+
const divEl = this.template.querySelector("div");
|
|
289
|
+
if (divEl?.hasChildNodes()) {
|
|
290
|
+
divEl.removeChild(divEl.firstChild!);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
return divEl;
|
|
294
|
+
}
|
|
295
|
+
|
|
256
296
|
isSamePage(reference: PageReference): boolean {
|
|
257
297
|
return (
|
|
258
298
|
this.pageReference.contentDocumentId ===
|
|
@@ -267,9 +307,8 @@ export default class Content extends LightningElement {
|
|
|
267
307
|
event.preventDefault();
|
|
268
308
|
// eslint-disable-next-line no-use-before-define
|
|
269
309
|
const target = event.currentTarget.dataset.id;
|
|
270
|
-
const [page, docId, deliverable, tempContentDocumentId] =
|
|
271
|
-
"/"
|
|
272
|
-
);
|
|
310
|
+
const [page, docId, deliverable, tempContentDocumentId] =
|
|
311
|
+
target.split("/");
|
|
273
312
|
const [contentDocumentId, hash] = tempContentDocumentId.split("#");
|
|
274
313
|
const newPageReference = {
|
|
275
314
|
page: page,
|
|
@@ -293,6 +332,14 @@ export default class Content extends LightningElement {
|
|
|
293
332
|
}
|
|
294
333
|
}
|
|
295
334
|
|
|
335
|
+
updateHighlighted = (event: any) =>
|
|
336
|
+
highlightTerms(
|
|
337
|
+
Array.from(
|
|
338
|
+
this.template.querySelectorAll(ALLOWED_ELEMENTS.join(","))
|
|
339
|
+
),
|
|
340
|
+
event.detail
|
|
341
|
+
);
|
|
342
|
+
|
|
296
343
|
@api
|
|
297
344
|
public navigateToHash(hash: String) {
|
|
298
345
|
const splitHash = hash.split("#");
|
|
@@ -104,7 +104,7 @@ describe(TAG, () => {
|
|
|
104
104
|
expect(headerEl).not.toBeNull();
|
|
105
105
|
expect(headerEl.classList).toHaveLength(0);
|
|
106
106
|
|
|
107
|
-
expect(headerEl.querySelector("dx-
|
|
107
|
+
expect(headerEl.querySelector("dx-banner")).not.toBeNull();
|
|
108
108
|
|
|
109
109
|
const logo = element.shadowRoot.querySelector("dx-logo");
|
|
110
110
|
expect(logo).not.toBeNull();
|
|
@@ -307,6 +307,29 @@ describe(TAG, () => {
|
|
|
307
307
|
clickText: SIGN_UP_LABEL
|
|
308
308
|
});
|
|
309
309
|
});
|
|
310
|
+
|
|
311
|
+
it("hides signup button when signupLink property is empty", () => {
|
|
312
|
+
const updatedMockPropsDevelopers = {
|
|
313
|
+
...mockPropsDevelopers,
|
|
314
|
+
signupLink:""
|
|
315
|
+
};
|
|
316
|
+
const element = render(updatedMockPropsDevelopers);
|
|
317
|
+
const signupButtonContainer: HTMLElement =
|
|
318
|
+
element.shadowRoot.querySelector(".header-login-signup");
|
|
319
|
+
expect(signupButtonContainer).toBeNull();
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
it("hides banner when banner markup is empty", () => {
|
|
323
|
+
const bannerMarkup = "";
|
|
324
|
+
const updatedMockPropsDevelopers = {
|
|
325
|
+
...mockPropsDevelopers,
|
|
326
|
+
bannerMarkup
|
|
327
|
+
};
|
|
328
|
+
const element = render(updatedMockPropsDevelopers);
|
|
329
|
+
const bannerElement: HTMLElement =
|
|
330
|
+
element.shadowRoot.querySelector("dx-banner");
|
|
331
|
+
expect(bannerElement).toBeNull();
|
|
332
|
+
});
|
|
310
333
|
});
|
|
311
334
|
|
|
312
335
|
describe("tablet", () => {
|
|
@@ -32,6 +32,9 @@ export const mockPropsDevelopers = {
|
|
|
32
32
|
title: "Salesforce Developers",
|
|
33
33
|
subtitle: "Apex Developer Guides",
|
|
34
34
|
languages,
|
|
35
|
+
signupLink: "/sign-up",
|
|
36
|
+
bannerMarkup:
|
|
37
|
+
'<span><a href="https://forms.gle/TdSyKFPHXoBx7seM9" target="blank">Share your feedback</a>about our new site.</span>',
|
|
35
38
|
...coveoConfig
|
|
36
39
|
};
|
|
37
40
|
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<dx-brand-theme-provider brand={brand}>
|
|
3
3
|
<header class={className}>
|
|
4
|
-
<dx-
|
|
4
|
+
<dx-banner
|
|
5
|
+
if:true={bannerMarkup}
|
|
6
|
+
banner-markup={bannerMarkup}
|
|
7
|
+
></dx-banner>
|
|
5
8
|
<div class="header_l1">
|
|
6
9
|
<div if:true={showMenuButton} class="nav_menu-ctas">
|
|
7
10
|
<dx-button
|
|
@@ -101,6 +101,8 @@ const headerStoryGenerator = (
|
|
|
101
101
|
bail-label="${args.bailLabel}"
|
|
102
102
|
brand="${brand}"
|
|
103
103
|
onclick="headerClick(event)"
|
|
104
|
+
signup-link="${mockProps.signupLink}"
|
|
105
|
+
banner-markup="${mockProps.bannerMarkup}"
|
|
104
106
|
></doc-header>`;
|
|
105
107
|
|
|
106
108
|
export const Base = (args: any) => html`
|
|
@@ -158,3 +160,31 @@ export const Service = (args: any) =>
|
|
|
158
160
|
|
|
159
161
|
export const Analytics = (args: any) =>
|
|
160
162
|
headerStoryGenerator(mockPropsAnalytics, "analytics", args);
|
|
163
|
+
|
|
164
|
+
export const AnalyticsWithoutSignup = (args: any) =>
|
|
165
|
+
headerStoryGenerator(
|
|
166
|
+
{ ...mockPropsAnalytics, signupLink:"" },
|
|
167
|
+
"analytics",
|
|
168
|
+
args
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
export const AnalyticsWithCustomBannerText = (args: any) =>
|
|
172
|
+
headerStoryGenerator(
|
|
173
|
+
{
|
|
174
|
+
...mockPropsMarketing,
|
|
175
|
+
bannerMarkup:
|
|
176
|
+
'Salesforce Subscription Management API ("the API") is available as a developer preview. The API is not generally available unless or until Salesforce announces its general availability in documentation or in press releases or public statements. All components of the API including request names, parameters, objects, and fields are subject to change or deprecation at any time, with or without notice. Do not use the API with real data or in a production environment.'
|
|
177
|
+
},
|
|
178
|
+
"analytics",
|
|
179
|
+
args
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
export const AnalyticsWithoutBanner = (args: any) =>
|
|
183
|
+
headerStoryGenerator(
|
|
184
|
+
{
|
|
185
|
+
...mockPropsMarketing,
|
|
186
|
+
bannerMarkup: ""
|
|
187
|
+
},
|
|
188
|
+
"analytics",
|
|
189
|
+
args
|
|
190
|
+
);
|
|
@@ -63,7 +63,9 @@ export default class Header extends HeaderBase {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
private get showSignup(): boolean {
|
|
66
|
-
return
|
|
66
|
+
return this.signupLink
|
|
67
|
+
? (this.tablet && !this.isSearchOpen) || !this.tablet
|
|
68
|
+
: false;
|
|
67
69
|
}
|
|
68
70
|
|
|
69
71
|
private get hasLanguages(): boolean {
|