@salesforcedevs/docs-components 0.8.4-alpha01 → 0.10.1-alpha.117
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 +12 -0
- package/lwc.config.json +2 -1
- 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 +5 -0
- package/src/modules/doc/content/content.stories.ts +40 -0
- package/src/modules/doc/content/content.ts +63 -19
- package/src/modules/doc/header/header.html +10 -0
- package/src/modules/doc/headingAnchor/__tests__/headingAnchor.test.ts +111 -0
- package/src/modules/doc/headingAnchor/headingAnchor.css +33 -0
- package/src/modules/doc/headingAnchor/headingAnchor.html +19 -0
- package/src/modules/doc/headingAnchor/headingAnchor.stories.ts +33 -0
- package/src/modules/doc/headingAnchor/headingAnchor.ts +43 -0
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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforcedevs/docs-components",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.1-alpha.117",
|
|
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": "d2289f6fae864f4763bc892ecd78b6454eae44d6"
|
|
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
|
+
];
|
|
@@ -238,6 +238,7 @@ dd {
|
|
|
238
238
|
color: var(--dx-g-gray-10);
|
|
239
239
|
letter-spacing: 0;
|
|
240
240
|
line-height: var(--dx-g-spacing-lg);
|
|
241
|
+
margin-left: var(--dx-g-spacing-smd);
|
|
241
242
|
}
|
|
242
243
|
|
|
243
244
|
li {
|
|
@@ -367,3 +368,7 @@ samp,
|
|
|
367
368
|
font-family: Menlo, monospace;
|
|
368
369
|
font-size: 1em;
|
|
369
370
|
}
|
|
371
|
+
|
|
372
|
+
mark {
|
|
373
|
+
background-color: var(--dx-g-yellow-vibrant-90);
|
|
374
|
+
}
|
|
@@ -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,14 +1,29 @@
|
|
|
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 HIGHLIGHTABLE_SELECTOR = [
|
|
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
|
+
].join(",");
|
|
8
25
|
|
|
9
26
|
const LANGUAGE_MAP: { [key: string]: string } = {
|
|
10
|
-
xml: "plain",
|
|
11
|
-
html: "plain",
|
|
12
27
|
js: "javascript"
|
|
13
28
|
};
|
|
14
29
|
|
|
@@ -17,31 +32,48 @@ export default class Content extends LightningElement {
|
|
|
17
32
|
@api pageReference!: PageReference;
|
|
18
33
|
@api codeBlockType: string = "card";
|
|
19
34
|
@api showPaginationButtons: boolean = false;
|
|
35
|
+
|
|
20
36
|
@api
|
|
21
37
|
set docsData(value) {
|
|
22
38
|
this._docRendered = false;
|
|
23
|
-
this.docContent = value;
|
|
39
|
+
this.docContent = (value && value.trim()) || "";
|
|
24
40
|
}
|
|
41
|
+
|
|
25
42
|
get docsData() {
|
|
26
43
|
return this.docContent;
|
|
27
44
|
}
|
|
28
|
-
|
|
45
|
+
|
|
29
46
|
@api
|
|
30
47
|
set codeBlockTheme(value) {
|
|
31
48
|
this._codeBlockTheme = value;
|
|
32
49
|
}
|
|
50
|
+
|
|
33
51
|
get codeBlockTheme() {
|
|
34
52
|
return this._codeBlockTheme;
|
|
35
53
|
}
|
|
36
54
|
|
|
37
55
|
@track docContent: DocContent = "";
|
|
56
|
+
_codeBlockTheme: string = "dark";
|
|
38
57
|
_docRendered: boolean = false;
|
|
39
58
|
originalCodeBlockThemeValue: String = "";
|
|
59
|
+
|
|
40
60
|
connectedCallback() {
|
|
41
61
|
this.template.addEventListener(
|
|
42
62
|
"themechange",
|
|
43
63
|
this.updateTheme.bind(this) // eslint-disableline no-use-before-define
|
|
44
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
|
+
);
|
|
45
77
|
}
|
|
46
78
|
|
|
47
79
|
updateTheme() {
|
|
@@ -74,19 +106,17 @@ export default class Content extends LightningElement {
|
|
|
74
106
|
// We don't use any tracked field here. The challenge is that
|
|
75
107
|
// for security reasons you can't pass pure HTML via a class
|
|
76
108
|
// field to the template. Hence we manipulate the DOM manually.
|
|
77
|
-
insertDocHtml() {
|
|
78
|
-
const divEl = this.
|
|
109
|
+
insertDocHtml(docContent?: string) {
|
|
110
|
+
const divEl = this.getCleanContainer();
|
|
79
111
|
|
|
80
112
|
// Some simple data mutation to make Prism work on-the-fly with the existing datasource
|
|
81
113
|
const templateEl = document.createElement("template");
|
|
82
|
-
this.docContent = this.docContent.trim();
|
|
83
114
|
// eslint-disable-next-line no-use-before-define
|
|
84
|
-
templateEl.innerHTML = this.docContent;
|
|
115
|
+
templateEl.innerHTML = docContent || this.docContent;
|
|
85
116
|
|
|
86
117
|
// Query the code blocks and create a dx-code-block component that contains the code
|
|
87
|
-
const codeBlockEls =
|
|
88
|
-
".codeSection"
|
|
89
|
-
);
|
|
118
|
+
const codeBlockEls =
|
|
119
|
+
templateEl.content.querySelectorAll(".codeSection");
|
|
90
120
|
codeBlockEls.forEach((codeBlockEl) => {
|
|
91
121
|
codeBlockEl.setAttribute("lwc:dom", "manual");
|
|
92
122
|
const classList = codeBlockEl.firstChild.classList;
|
|
@@ -106,7 +136,8 @@ export default class Content extends LightningElement {
|
|
|
106
136
|
language: LANGUAGE_MAP[language] || language,
|
|
107
137
|
theme: this.codeBlockTheme,
|
|
108
138
|
title: "", // Default no title.
|
|
109
|
-
variant: this.codeBlockType
|
|
139
|
+
variant: this.codeBlockType,
|
|
140
|
+
isEncoded: true
|
|
110
141
|
});
|
|
111
142
|
// eslint-disable-next-line no-use-before-define
|
|
112
143
|
codeBlockEl.innerHTML = "";
|
|
@@ -137,9 +168,8 @@ export default class Content extends LightningElement {
|
|
|
137
168
|
});
|
|
138
169
|
|
|
139
170
|
// Modify links to work with any domain, links that start with "#" are excluded
|
|
140
|
-
const anchorEls =
|
|
141
|
-
"a:not([href^='#'])"
|
|
142
|
-
);
|
|
171
|
+
const anchorEls =
|
|
172
|
+
templateEl.content.querySelectorAll("a:not([href^='#'])");
|
|
143
173
|
anchorEls.forEach((anchorEl) => {
|
|
144
174
|
if (
|
|
145
175
|
anchorEl.textContent.includes("Next →") ||
|
|
@@ -254,6 +284,15 @@ export default class Content extends LightningElement {
|
|
|
254
284
|
}
|
|
255
285
|
}
|
|
256
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
|
+
|
|
257
296
|
isSamePage(reference: PageReference): boolean {
|
|
258
297
|
return (
|
|
259
298
|
this.pageReference.contentDocumentId ===
|
|
@@ -268,9 +307,8 @@ export default class Content extends LightningElement {
|
|
|
268
307
|
event.preventDefault();
|
|
269
308
|
// eslint-disable-next-line no-use-before-define
|
|
270
309
|
const target = event.currentTarget.dataset.id;
|
|
271
|
-
const [page, docId, deliverable, tempContentDocumentId] =
|
|
272
|
-
"/"
|
|
273
|
-
);
|
|
310
|
+
const [page, docId, deliverable, tempContentDocumentId] =
|
|
311
|
+
target.split("/");
|
|
274
312
|
const [contentDocumentId, hash] = tempContentDocumentId.split("#");
|
|
275
313
|
const newPageReference = {
|
|
276
314
|
page: page,
|
|
@@ -294,6 +332,12 @@ export default class Content extends LightningElement {
|
|
|
294
332
|
}
|
|
295
333
|
}
|
|
296
334
|
|
|
335
|
+
updateHighlighted = (event: any) =>
|
|
336
|
+
highlightTerms(
|
|
337
|
+
this.template.querySelectorAll(HIGHLIGHTABLE_SELECTOR),
|
|
338
|
+
event.detail
|
|
339
|
+
);
|
|
340
|
+
|
|
297
341
|
@api
|
|
298
342
|
public navigateToHash(hash: String) {
|
|
299
343
|
const splitHash = hash.split("#");
|
|
@@ -33,6 +33,16 @@
|
|
|
33
33
|
onstatechange={handleStateChange}
|
|
34
34
|
></dx-header-search>
|
|
35
35
|
</div>
|
|
36
|
+
<div if:true={showSignup} class="header-login-signup">
|
|
37
|
+
<dx-button
|
|
38
|
+
aria-label="Sign Up For Salesforce Developer Edition"
|
|
39
|
+
size="small"
|
|
40
|
+
href={signupLink}
|
|
41
|
+
onclick={handleSignUpClick}
|
|
42
|
+
>
|
|
43
|
+
Sign Up
|
|
44
|
+
</dx-button>
|
|
45
|
+
</div>
|
|
36
46
|
<dx-header-mobile-nav-menu
|
|
37
47
|
if:true={hasNavItems}
|
|
38
48
|
nav-items={navItems}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import HeadingAnchor from "doc/headingAnchor";
|
|
2
|
+
import { createRenderComponent } from "utils/tests";
|
|
3
|
+
|
|
4
|
+
const TAG = "doc-heading-anchor";
|
|
5
|
+
const render = createRenderComponent(TAG, HeadingAnchor);
|
|
6
|
+
|
|
7
|
+
describe(TAG, () => {
|
|
8
|
+
const originalClipboard = { ...global.navigator.clipboard };
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
Object.defineProperty(global.navigator, "clipboard", {
|
|
11
|
+
value: { writeText: jest.fn() },
|
|
12
|
+
configurable: true
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
afterEach(() => {
|
|
17
|
+
jest.resetAllMocks();
|
|
18
|
+
Object.defineProperty(global.navigator, "clipboard", {
|
|
19
|
+
value: originalClipboard,
|
|
20
|
+
configurable: true
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
it("renders an Anchor element", () => {
|
|
24
|
+
const element = render({
|
|
25
|
+
ariaLabel: "Default",
|
|
26
|
+
iconSize: "override",
|
|
27
|
+
iconSymbol: "link",
|
|
28
|
+
title: "Anchor Component",
|
|
29
|
+
urlText: "anchor-component"
|
|
30
|
+
});
|
|
31
|
+
const iconEl = element.shadowRoot.querySelector("dx-icon");
|
|
32
|
+
|
|
33
|
+
expect(element.getAttribute("class")).toBeDefined();
|
|
34
|
+
expect(iconEl.classList).toContain("icon-container");
|
|
35
|
+
return expect(element).toBeAccessible();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("renders Anchor defaults if no overrides are specified", () => {
|
|
39
|
+
const element = render({ ariaLabel: "Default" });
|
|
40
|
+
|
|
41
|
+
const buttonEl = element.shadowRoot.querySelector("button");
|
|
42
|
+
const buttonAriaLabel = buttonEl.getAttribute("aria-label");
|
|
43
|
+
|
|
44
|
+
expect(buttonEl.getAttribute("class")).toBeFalsy();
|
|
45
|
+
expect(buttonAriaLabel).toBe("Default");
|
|
46
|
+
expect(buttonAriaLabel).not.toContain("copy");
|
|
47
|
+
return expect(element).toBeAccessible();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("can display an icon with the expected settings", () => {
|
|
51
|
+
const iconSize = "large";
|
|
52
|
+
const iconSymbol = "automate";
|
|
53
|
+
const ariaLabel = "Automate";
|
|
54
|
+
const element = render({
|
|
55
|
+
ariaLabel,
|
|
56
|
+
iconSize,
|
|
57
|
+
iconSymbol,
|
|
58
|
+
title: "Anchor Component",
|
|
59
|
+
urlText: "anchor-component"
|
|
60
|
+
});
|
|
61
|
+
const iconEl = element.shadowRoot.querySelector("dx-icon");
|
|
62
|
+
|
|
63
|
+
expect(iconEl).not.toBeNull();
|
|
64
|
+
expect(iconEl.sprite).toBe("utility");
|
|
65
|
+
expect(iconEl.size).toBe(iconSize);
|
|
66
|
+
expect(iconEl.symbol).toBe(iconSymbol);
|
|
67
|
+
return expect(element).toBeAccessible();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("renders an tooltip label on keydown of enter", () => {
|
|
71
|
+
const element = render({
|
|
72
|
+
ariaLabel: "Default",
|
|
73
|
+
iconSize: "override",
|
|
74
|
+
iconSymbol: "link",
|
|
75
|
+
title: "Anchor Component",
|
|
76
|
+
urlText: "anchor-component"
|
|
77
|
+
});
|
|
78
|
+
const mockData = "http://localhost/#anchor-component";
|
|
79
|
+
|
|
80
|
+
return Promise.resolve().then(() => {
|
|
81
|
+
const buttonEl = element.shadowRoot.querySelector("button");
|
|
82
|
+
const event = new KeyboardEvent("keydown", { key: "Enter" });
|
|
83
|
+
buttonEl.dispatchEvent(event);
|
|
84
|
+
const tooltipEl = element.shadowRoot.querySelector("dx-tooltip");
|
|
85
|
+
expect(navigator.clipboard.writeText).toHaveBeenCalledWith(
|
|
86
|
+
mockData
|
|
87
|
+
);
|
|
88
|
+
return expect(tooltipEl).toBeAccessible();
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("renders an tooltip label on click of icon", async () => {
|
|
93
|
+
const element = render({
|
|
94
|
+
ariaLabel: "Default",
|
|
95
|
+
iconSize: "override",
|
|
96
|
+
iconSymbol: "link",
|
|
97
|
+
title: "Anchor Component",
|
|
98
|
+
urlText: "anchor-component"
|
|
99
|
+
});
|
|
100
|
+
const mockData = "http://localhost/#anchor-component";
|
|
101
|
+
|
|
102
|
+
return Promise.resolve().then(() => {
|
|
103
|
+
element.shadowRoot.querySelector("dx-icon").click();
|
|
104
|
+
const tooltipEl = element.shadowRoot.querySelector("dx-tooltip");
|
|
105
|
+
expect(navigator.clipboard.writeText).toHaveBeenCalledWith(
|
|
106
|
+
mockData
|
|
107
|
+
);
|
|
108
|
+
return expect(tooltipEl).toBeAccessible();
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
@import "helpers/reset";
|
|
2
|
+
|
|
3
|
+
button {
|
|
4
|
+
opacity: 0;
|
|
5
|
+
color: rgb(11, 92, 171);
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
button:hover {
|
|
9
|
+
opacity: 1;
|
|
10
|
+
outline: none;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
button:focus {
|
|
14
|
+
opacity: 1;
|
|
15
|
+
outline: none;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
button:focus-visible {
|
|
19
|
+
border-radius: 4px;
|
|
20
|
+
border: 2px solid rgb(11, 92, 171);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.icon-wrapper {
|
|
24
|
+
height: 32px;
|
|
25
|
+
width: 32px;
|
|
26
|
+
display: flex;
|
|
27
|
+
justify-content: center;
|
|
28
|
+
align-items: center;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.icon-container {
|
|
32
|
+
--dx-c-icon-size: 18px;
|
|
33
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<dx-tooltip placement="top" label={label}>
|
|
3
|
+
<button
|
|
4
|
+
onclick={onIconClick}
|
|
5
|
+
aria-label={ariaLabel}
|
|
6
|
+
onkeydown={onKeyDown}
|
|
7
|
+
part="headingAnchorIcon"
|
|
8
|
+
>
|
|
9
|
+
<div class="icon-wrapper">
|
|
10
|
+
<dx-icon
|
|
11
|
+
sprite={iconSprite}
|
|
12
|
+
size={iconSize}
|
|
13
|
+
symbol={iconSymbol}
|
|
14
|
+
class="icon-container"
|
|
15
|
+
></dx-icon>
|
|
16
|
+
</div>
|
|
17
|
+
</button>
|
|
18
|
+
</dx-tooltip>
|
|
19
|
+
</template>
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { html } from "lit-html";
|
|
2
|
+
|
|
3
|
+
export default {
|
|
4
|
+
title: "docs/doc-heading-anchor",
|
|
5
|
+
component: "doc-heading-anchor"
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
// prettier-ignore
|
|
9
|
+
const createStyles = () => html`
|
|
10
|
+
<style>
|
|
11
|
+
h2 {
|
|
12
|
+
display: inline;
|
|
13
|
+
color: rgb(11, 92, 171);
|
|
14
|
+
font-weight: bold;
|
|
15
|
+
}
|
|
16
|
+
h2:hover + doc-heading-anchor::part(headingAnchorIcon) {
|
|
17
|
+
opacity: 1;
|
|
18
|
+
}
|
|
19
|
+
</style>`;
|
|
20
|
+
|
|
21
|
+
// prettier-ignore
|
|
22
|
+
export const Inline = () => html` ${createStyles()}
|
|
23
|
+
<h1>
|
|
24
|
+
<strong>A button/icon is hidden by default which is placed beside the title. It is used to copy the naviagtion link generated for the corresponding H2 heading</strong>
|
|
25
|
+
</h1>
|
|
26
|
+
<h2>Anchor Component</h2>
|
|
27
|
+
<doc-heading-anchor
|
|
28
|
+
icon-size="override"
|
|
29
|
+
icon-symbol="link"
|
|
30
|
+
title="Anchor Component"
|
|
31
|
+
url-text="anchor-component"
|
|
32
|
+
></doc-heading-anchor>
|
|
33
|
+
`;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { LightningElement, api } from "lwc";
|
|
2
|
+
import { IconSprite, IconSize, IconSymbol } from "typings/custom";
|
|
3
|
+
|
|
4
|
+
export default class HeadingAnchor extends LightningElement {
|
|
5
|
+
@api ariaLabel: string = "copy";
|
|
6
|
+
@api iconSize?: IconSize = "override";
|
|
7
|
+
@api iconSprite?: IconSprite = "utility";
|
|
8
|
+
@api iconSymbol?: IconSymbol;
|
|
9
|
+
@api title: string = "";
|
|
10
|
+
@api urlText: string = "";
|
|
11
|
+
|
|
12
|
+
label: string = "Copy link to clipboard";
|
|
13
|
+
|
|
14
|
+
private async onIconClick() {
|
|
15
|
+
await this.iconClickHandler();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
private async iconClickHandler() {
|
|
19
|
+
this.label = "Copied";
|
|
20
|
+
setTimeout(() => {
|
|
21
|
+
this.label = "Copy link to clipboard";
|
|
22
|
+
}, 2000);
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
if (this.title && this.urlText) {
|
|
26
|
+
const [hostUrl] = window.location.href.split("#");
|
|
27
|
+
const url = `${hostUrl}#${this.urlText}`;
|
|
28
|
+
await navigator.clipboard.writeText(url);
|
|
29
|
+
}
|
|
30
|
+
} catch (error) {
|
|
31
|
+
console.error(error);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
private async onKeyDown(e: KeyboardEvent) {
|
|
36
|
+
switch (e.key) {
|
|
37
|
+
case "Enter":
|
|
38
|
+
await this.iconClickHandler();
|
|
39
|
+
break;
|
|
40
|
+
default:
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|