@salesforcedevs/docs-components 1.30.1-node22-2 → 1.30.1
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/lwc.config.json +3 -0
- package/package.json +3 -7
- package/src/modules/doc/amfReference/amfReference.html +1 -0
- package/src/modules/doc/amfReference/amfReference.ts +54 -10
- package/src/modules/doc/amfReference/types.ts +5 -0
- package/src/modules/doc/banner/banner.css +88 -0
- package/src/modules/doc/banner/banner.html +47 -0
- package/src/modules/doc/banner/banner.ts +73 -0
- package/src/modules/doc/contentActionToolbar/contentActionToolbar.css +31 -0
- package/src/modules/doc/contentActionToolbar/contentActionToolbar.html +53 -0
- package/src/modules/doc/contentActionToolbar/contentActionToolbar.ts +151 -0
- package/src/modules/doc/contentActionToolbar/contentActionToolbarMocks.ts +48 -0
- package/src/modules/doc/contentLayout/contentLayout.html +1 -1
- package/src/modules/doc/contentLayout/contentLayout.ts +103 -2
- package/src/modules/doc/header/header.html +0 -1
- package/src/modules/doc/localeBanner/localeBanner.css +3 -0
- package/src/modules/doc/localeBanner/localeBanner.html +9 -0
- package/src/modules/doc/localeBanner/localeBanner.ts +195 -0
- package/src/modules/doc/lwcContentLayout/lwcContentLayout.html +5 -2
- package/src/modules/doc/redocReference/redocReference.ts +157 -2
- package/src/modules/doc/xmlContent/xmlContent.html +1 -1
- package/src/modules/doc/xmlContent/xmlContent.ts +28 -1
package/lwc.config.json
CHANGED
package/package.json
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforcedevs/docs-components",
|
|
3
|
-
"version": "1.30.1
|
|
3
|
+
"version": "1.30.1",
|
|
4
4
|
"description": "Docs Lightning web components for DSC",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"engines": {
|
|
8
|
-
"node": "
|
|
9
|
-
},
|
|
10
|
-
"volta": {
|
|
11
|
-
"node": "22.22.0",
|
|
12
|
-
"yarn": "1.22.22"
|
|
8
|
+
"node": "22.x"
|
|
13
9
|
},
|
|
14
10
|
"publishConfig": {
|
|
15
11
|
"access": "public"
|
|
@@ -29,5 +25,5 @@
|
|
|
29
25
|
"@types/lodash.orderby": "4.6.9",
|
|
30
26
|
"@types/lodash.uniqby": "4.7.9"
|
|
31
27
|
},
|
|
32
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "1ef01ecd6afcd77c06384577bbf7afa48907d82a"
|
|
33
29
|
}
|
|
@@ -37,6 +37,7 @@ type NavigationItem = {
|
|
|
37
37
|
isExpanded: boolean;
|
|
38
38
|
children: ParsedMarkdownTopic[];
|
|
39
39
|
isChildrenLoading: boolean;
|
|
40
|
+
showForwardArrow?: boolean;
|
|
40
41
|
};
|
|
41
42
|
|
|
42
43
|
export default class AmfReference extends LightningElement {
|
|
@@ -72,6 +73,8 @@ export default class AmfReference extends LightningElement {
|
|
|
72
73
|
return this.isSpecBasedReference(this._currentReferenceId);
|
|
73
74
|
}
|
|
74
75
|
|
|
76
|
+
@api showContentActionToolbar = false;
|
|
77
|
+
|
|
75
78
|
@api
|
|
76
79
|
get referenceSetConfig(): ReferenceSetConfig {
|
|
77
80
|
return this._referenceSetConfig;
|
|
@@ -204,6 +207,7 @@ export default class AmfReference extends LightningElement {
|
|
|
204
207
|
|
|
205
208
|
_boundOnApiNavigationChanged;
|
|
206
209
|
_boundUpdateSelectedItemFromUrlQuery;
|
|
210
|
+
_boundOnPageShow;
|
|
207
211
|
|
|
208
212
|
constructor() {
|
|
209
213
|
super();
|
|
@@ -212,6 +216,7 @@ export default class AmfReference extends LightningElement {
|
|
|
212
216
|
this.onApiNavigationChanged.bind(this);
|
|
213
217
|
this._boundUpdateSelectedItemFromUrlQuery =
|
|
214
218
|
this.updateSelectedItemFromUrlQuery.bind(this);
|
|
219
|
+
this._boundOnPageShow = this.onPageShow.bind(this);
|
|
215
220
|
}
|
|
216
221
|
|
|
217
222
|
connectedCallback(): void {
|
|
@@ -223,6 +228,7 @@ export default class AmfReference extends LightningElement {
|
|
|
223
228
|
"popstate",
|
|
224
229
|
this._boundUpdateSelectedItemFromUrlQuery
|
|
225
230
|
);
|
|
231
|
+
window.addEventListener("pageshow", this._boundOnPageShow);
|
|
226
232
|
}
|
|
227
233
|
|
|
228
234
|
disconnectedCallback(): void {
|
|
@@ -234,6 +240,22 @@ export default class AmfReference extends LightningElement {
|
|
|
234
240
|
"popstate",
|
|
235
241
|
this._boundUpdateSelectedItemFromUrlQuery
|
|
236
242
|
);
|
|
243
|
+
window.removeEventListener("pageshow", this._boundOnPageShow);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* On bfcache restore, reset the sidebar selection so the tree re-syncs
|
|
248
|
+
* its highlighted tile with the current URL.
|
|
249
|
+
*/
|
|
250
|
+
protected onPageShow(event: PageTransitionEvent): void {
|
|
251
|
+
if (!event.persisted) {
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
const currentPath = window.location.pathname;
|
|
255
|
+
this.selectedSidebarValue = "";
|
|
256
|
+
Promise.resolve().then(() => {
|
|
257
|
+
this.selectedSidebarValue = currentPath;
|
|
258
|
+
});
|
|
237
259
|
}
|
|
238
260
|
|
|
239
261
|
renderedCallback(): void {
|
|
@@ -443,16 +465,21 @@ export default class AmfReference extends LightningElement {
|
|
|
443
465
|
let navItemChildren = [] as ParsedMarkdownTopic[];
|
|
444
466
|
let isChildrenLoading = false;
|
|
445
467
|
if (amfConfig.referenceType !== REFERENCE_TYPES.markdown) {
|
|
446
|
-
if (amfConfig.
|
|
447
|
-
|
|
448
|
-
(
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
468
|
+
if (amfConfig.amf) {
|
|
469
|
+
if (amfConfig.isSelected) {
|
|
470
|
+
const amfPromise = this.fetchAmf(amfConfig).then(
|
|
471
|
+
(amfJson) => {
|
|
472
|
+
this.updateModel(amfConfig.id, amfJson);
|
|
473
|
+
this.assignNavigationItemsFromAmf(
|
|
474
|
+
amfConfig,
|
|
475
|
+
index
|
|
476
|
+
);
|
|
477
|
+
}
|
|
478
|
+
);
|
|
479
|
+
this.amfFetchPromiseMap[amfConfig.id] = amfPromise;
|
|
480
|
+
}
|
|
481
|
+
isChildrenLoading = true;
|
|
454
482
|
}
|
|
455
|
-
isChildrenLoading = true;
|
|
456
483
|
} else {
|
|
457
484
|
const isExpandChildrenEnabled = this.isExpandChildrenEnabled(
|
|
458
485
|
amfConfig.id
|
|
@@ -473,13 +500,30 @@ export default class AmfReference extends LightningElement {
|
|
|
473
500
|
amfConfig.isSelected ||
|
|
474
501
|
this.isExpandChildrenEnabled(amfConfig.id),
|
|
475
502
|
children: navItemChildren,
|
|
476
|
-
isChildrenLoading
|
|
503
|
+
isChildrenLoading,
|
|
504
|
+
showForwardArrow: this.resolveNavRenderWith(amfConfig)
|
|
477
505
|
};
|
|
478
506
|
this.parentReferenceUrls.push(amfConfig.href);
|
|
479
507
|
}
|
|
480
508
|
this.navigation = navAmfOrder;
|
|
481
509
|
}
|
|
482
510
|
|
|
511
|
+
/**
|
|
512
|
+
* Determines whether the sidebar tile should render a forward arrow for
|
|
513
|
+
* this reference. Honors `redoc` set on the config, and also infers it
|
|
514
|
+
* for non-markdown references that have no AMF URL (i.e. those rendered
|
|
515
|
+
* by Redoc).
|
|
516
|
+
*/
|
|
517
|
+
private resolveNavRenderWith(amfConfig: AmfConfig): boolean {
|
|
518
|
+
if (amfConfig.renderWith) {
|
|
519
|
+
return amfConfig.renderWith === "redoc";
|
|
520
|
+
}
|
|
521
|
+
return (
|
|
522
|
+
amfConfig.referenceType !== REFERENCE_TYPES.markdown &&
|
|
523
|
+
!amfConfig.amf
|
|
524
|
+
);
|
|
525
|
+
}
|
|
526
|
+
|
|
483
527
|
/**
|
|
484
528
|
* Returns a boolean indicating whether the children should be expanded or not.
|
|
485
529
|
*/
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
@import "dxHelpers/reset";
|
|
2
|
+
@import "dxHelpers/text";
|
|
3
|
+
|
|
4
|
+
:host {
|
|
5
|
+
display: block;
|
|
6
|
+
|
|
7
|
+
--doc-banner-padding-left: var(--dx-g-spacing-2xl);
|
|
8
|
+
--doc-banner-padding-right: var(--dx-g-spacing-lg);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.container {
|
|
12
|
+
display: flex;
|
|
13
|
+
align-items: flex-start;
|
|
14
|
+
background: var(--dx-g-gray-90);
|
|
15
|
+
padding: 0 var(--doc-banner-padding-right) 0 var(--doc-banner-padding-left);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.icon {
|
|
19
|
+
--dx-c-icon-size: var(--dx-g-icon-size-lg);
|
|
20
|
+
|
|
21
|
+
flex-shrink: 0;
|
|
22
|
+
margin-top: var(--dx-g-spacing-smd);
|
|
23
|
+
margin-right: var(--dx-g-spacing-sm);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
.main {
|
|
27
|
+
flex: 1;
|
|
28
|
+
min-width: 0;
|
|
29
|
+
display: flex;
|
|
30
|
+
flex-wrap: wrap;
|
|
31
|
+
align-items: flex-start;
|
|
32
|
+
column-gap: var(--dx-g-spacing-md);
|
|
33
|
+
padding: calc((var(--dx-g-spacing-xs) + var(--dx-g-spacing-sm)) / 2) 0;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.message {
|
|
37
|
+
flex: 0 1 auto;
|
|
38
|
+
font-size: var(--dx-g-text-sm);
|
|
39
|
+
color: var(--dx-g-gray-10);
|
|
40
|
+
padding: calc((var(--dx-g-spacing-xs) + var(--dx-g-spacing-sm)) / 2) 0;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.message a {
|
|
44
|
+
color: var(--dx-g-cloud-blue-vibrant-50);
|
|
45
|
+
text-decoration: underline;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.actions {
|
|
49
|
+
flex: 0 0 auto;
|
|
50
|
+
display: flex;
|
|
51
|
+
align-items: center;
|
|
52
|
+
gap: var(--dx-g-spacing-smd);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.actions dx-button {
|
|
56
|
+
--dx-c-button-font-size: var(--dx-g-text-sm);
|
|
57
|
+
--dx-c-button-font-weight: var(--dx-g-font-normal);
|
|
58
|
+
|
|
59
|
+
flex: 0 0 auto;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.close {
|
|
63
|
+
--dx-c-icon-size: var(--dx-g-icon-size-lg);
|
|
64
|
+
|
|
65
|
+
flex-shrink: 0;
|
|
66
|
+
align-self: flex-start;
|
|
67
|
+
width: calc(var(--dx-g-spacing-3xl) + var(--dx-g-spacing-xs));
|
|
68
|
+
height: calc(var(--dx-g-spacing-2xl) + var(--dx-g-spacing-xs));
|
|
69
|
+
margin-left: auto;
|
|
70
|
+
display: flex;
|
|
71
|
+
align-items: center;
|
|
72
|
+
justify-content: center;
|
|
73
|
+
cursor: pointer;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
@media (max-width: 1279px) {
|
|
77
|
+
:host {
|
|
78
|
+
--doc-banner-padding-left: var(--dx-g-spacing-xl);
|
|
79
|
+
--doc-banner-padding-right: var(--dx-g-spacing-md);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
@media (max-width: 768px) {
|
|
84
|
+
:host {
|
|
85
|
+
--doc-banner-padding-left: var(--dx-g-spacing-lg);
|
|
86
|
+
--doc-banner-padding-right: var(--dx-g-spacing-sm);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<template lwc:if={showBanner}>
|
|
3
|
+
<div class="container" part="container">
|
|
4
|
+
<dx-icon
|
|
5
|
+
class="icon"
|
|
6
|
+
symbol="info"
|
|
7
|
+
size="override"
|
|
8
|
+
color="gray-50"
|
|
9
|
+
part="icon"
|
|
10
|
+
></dx-icon>
|
|
11
|
+
<div class="main">
|
|
12
|
+
<div class="message" part="message" lwc:dom="manual"></div>
|
|
13
|
+
<div class="actions" part="actions">
|
|
14
|
+
<template lwc:if={hasPrimaryButton}>
|
|
15
|
+
<dx-button
|
|
16
|
+
href={buttonHref}
|
|
17
|
+
variant="primary"
|
|
18
|
+
size="small"
|
|
19
|
+
part="button"
|
|
20
|
+
>
|
|
21
|
+
{buttonLabel}
|
|
22
|
+
</dx-button>
|
|
23
|
+
</template>
|
|
24
|
+
<template lwc:if={hasSecondaryAction}>
|
|
25
|
+
<dx-button
|
|
26
|
+
variant="inline"
|
|
27
|
+
onclick={handleSecondaryClick}
|
|
28
|
+
part="secondary"
|
|
29
|
+
>
|
|
30
|
+
{secondaryLabel}
|
|
31
|
+
</dx-button>
|
|
32
|
+
</template>
|
|
33
|
+
</div>
|
|
34
|
+
</div>
|
|
35
|
+
<dx-button
|
|
36
|
+
class="close"
|
|
37
|
+
variant="icon-only"
|
|
38
|
+
icon-symbol="close"
|
|
39
|
+
icon-size="override"
|
|
40
|
+
icon-color="gray-50"
|
|
41
|
+
aria-label="Close"
|
|
42
|
+
onclick={handleCloseClick}
|
|
43
|
+
part="close"
|
|
44
|
+
></dx-button>
|
|
45
|
+
</div>
|
|
46
|
+
</template>
|
|
47
|
+
</template>
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { LightningElement, api } from "lwc";
|
|
2
|
+
|
|
3
|
+
const BANNER_STORAGE_PREFIX = "doc-banner-";
|
|
4
|
+
|
|
5
|
+
export default class Banner extends LightningElement {
|
|
6
|
+
@api message = "";
|
|
7
|
+
|
|
8
|
+
@api buttonLabel = "";
|
|
9
|
+
|
|
10
|
+
@api buttonHref = "";
|
|
11
|
+
|
|
12
|
+
@api secondaryLabel = "";
|
|
13
|
+
|
|
14
|
+
@api dismissStorageKey = "";
|
|
15
|
+
|
|
16
|
+
private _dismissed = false;
|
|
17
|
+
|
|
18
|
+
connectedCallback() {
|
|
19
|
+
if (this.dismissStorageKey && window?.sessionStorage) {
|
|
20
|
+
this._dismissed =
|
|
21
|
+
window.sessionStorage.getItem(
|
|
22
|
+
`${BANNER_STORAGE_PREFIX}${this.dismissStorageKey}`
|
|
23
|
+
) === "true";
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
renderedCallback() {
|
|
28
|
+
if (this.message) {
|
|
29
|
+
const messageElement = this.template.querySelector(".message");
|
|
30
|
+
if (messageElement) {
|
|
31
|
+
messageElement.innerHTML = this.message;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
get showBanner(): boolean {
|
|
37
|
+
return !this._dismissed;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
get hasPrimaryButton(): boolean {
|
|
41
|
+
return !!(this.buttonLabel && this.buttonHref);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
get hasSecondaryAction(): boolean {
|
|
45
|
+
return !!this.secondaryLabel;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
private dismissBanner() {
|
|
49
|
+
if (this.dismissStorageKey && window?.sessionStorage) {
|
|
50
|
+
window.sessionStorage.setItem(
|
|
51
|
+
`${BANNER_STORAGE_PREFIX}${this.dismissStorageKey}`,
|
|
52
|
+
"true"
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
this._dismissed = true;
|
|
56
|
+
this.dispatchEvent(
|
|
57
|
+
new CustomEvent("dismissbanner", {
|
|
58
|
+
bubbles: true,
|
|
59
|
+
composed: true
|
|
60
|
+
})
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
@api
|
|
65
|
+
handleSecondaryClick() {
|
|
66
|
+
this.dismissBanner();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
@api
|
|
70
|
+
handleCloseClick() {
|
|
71
|
+
this.dismissBanner();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
@import "dxHelpers/reset";
|
|
2
|
+
|
|
3
|
+
:host {
|
|
4
|
+
display: block;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
.toolbar {
|
|
8
|
+
display: flex;
|
|
9
|
+
align-items: center;
|
|
10
|
+
gap: var(--dx-g-spacing-smd);
|
|
11
|
+
margin-bottom: var(--dx-g-spacing-lg);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.toolbar-button {
|
|
15
|
+
--dx-c-button-font-weight: var(--dx-g-font-demi);
|
|
16
|
+
--dx-c-button-line-height: var(--dx-g-spacing-mlg);
|
|
17
|
+
--dx-c-button-letter-spacing: 0.005em;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.divider {
|
|
21
|
+
width: 1px;
|
|
22
|
+
height: var(--dx-g-spacing-md);
|
|
23
|
+
background-color: var(--dx-g-gray-70);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
@media screen and (max-width: 480px) {
|
|
27
|
+
.toolbar-button_copy-url,
|
|
28
|
+
.divider_copy-url {
|
|
29
|
+
display: none;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="toolbar" lwc:if={markdownUrl}>
|
|
3
|
+
<dx-tooltip placement="top-right" label={copyMarkdownLabel}>
|
|
4
|
+
<dx-button
|
|
5
|
+
class="toolbar-button"
|
|
6
|
+
variant="inline"
|
|
7
|
+
size="small"
|
|
8
|
+
icon-sprite="utility"
|
|
9
|
+
icon-symbol="copy"
|
|
10
|
+
icon-size="medium"
|
|
11
|
+
icon-position="right"
|
|
12
|
+
aria-label={copyMarkdownButtonText}
|
|
13
|
+
onclick={handleCopyMarkdown}
|
|
14
|
+
>
|
|
15
|
+
{copyMarkdownButtonText}
|
|
16
|
+
</dx-button>
|
|
17
|
+
</dx-tooltip>
|
|
18
|
+
|
|
19
|
+
<div class="divider"></div>
|
|
20
|
+
|
|
21
|
+
<dx-button
|
|
22
|
+
class="toolbar-button"
|
|
23
|
+
variant="inline"
|
|
24
|
+
size="small"
|
|
25
|
+
icon-sprite="utility"
|
|
26
|
+
icon-symbol="new_window"
|
|
27
|
+
icon-size="medium"
|
|
28
|
+
icon-position="right"
|
|
29
|
+
aria-label={viewMarkdownButtonText}
|
|
30
|
+
onclick={handleViewMarkdown}
|
|
31
|
+
>
|
|
32
|
+
{viewMarkdownButtonText}
|
|
33
|
+
</dx-button>
|
|
34
|
+
|
|
35
|
+
<div class="divider divider_copy-url"></div>
|
|
36
|
+
|
|
37
|
+
<dx-tooltip placement="top-right" label={copyUrlLabel}>
|
|
38
|
+
<dx-button
|
|
39
|
+
class="toolbar-button toolbar-button_copy-url"
|
|
40
|
+
variant="inline"
|
|
41
|
+
size="small"
|
|
42
|
+
icon-sprite="utility"
|
|
43
|
+
icon-symbol="link"
|
|
44
|
+
icon-size="medium"
|
|
45
|
+
icon-position="right"
|
|
46
|
+
aria-label={copyUrlButtonText}
|
|
47
|
+
onclick={handleCopyUrl}
|
|
48
|
+
>
|
|
49
|
+
{copyUrlButtonText}
|
|
50
|
+
</dx-button>
|
|
51
|
+
</dx-tooltip>
|
|
52
|
+
</div>
|
|
53
|
+
</template>
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { LightningElement, api } from "lwc";
|
|
2
|
+
import { track } from "dxUtils/analytics";
|
|
3
|
+
|
|
4
|
+
const DEFAULT_COPY_TOOLTIP_LABEL = "Click to copy";
|
|
5
|
+
const COPIED_TOOLTIP_LABEL = "Copied!";
|
|
6
|
+
const COPIED_TOOLTIP_RESET_MS = 1000;
|
|
7
|
+
|
|
8
|
+
const ANALYTICS_CONTENT_CATEGORY = "content action toolbar";
|
|
9
|
+
const COPY_MARKDOWN_LABEL = "Copy as Markdown";
|
|
10
|
+
const VIEW_MARKDOWN_LABEL = "View as Markdown";
|
|
11
|
+
const COPY_URL_LABEL = "Copy URL to Markdown";
|
|
12
|
+
|
|
13
|
+
export default class ContentActionToolbar extends LightningElement {
|
|
14
|
+
@api
|
|
15
|
+
get pageUrl(): string | undefined {
|
|
16
|
+
return this._pageUrl;
|
|
17
|
+
}
|
|
18
|
+
set pageUrl(value: string | undefined) {
|
|
19
|
+
if (this._pageUrl === value) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
this._pageUrl = value;
|
|
23
|
+
}
|
|
24
|
+
private _pageUrl?: string;
|
|
25
|
+
|
|
26
|
+
copyMarkdownLabel: string = DEFAULT_COPY_TOOLTIP_LABEL;
|
|
27
|
+
copyUrlLabel: string = DEFAULT_COPY_TOOLTIP_LABEL;
|
|
28
|
+
|
|
29
|
+
private copyTooltipResetTimeout: number | null = null;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Returns the `.md` equivalent of `pageUrl` with any hash and query
|
|
33
|
+
* string stripped, or `null` when `pageUrl` is not set or does not end
|
|
34
|
+
* with `.html`.
|
|
35
|
+
*/
|
|
36
|
+
get markdownUrl(): string | null {
|
|
37
|
+
if (!this.pageUrl) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const url = new URL(this.pageUrl, window.location.href);
|
|
42
|
+
url.hash = "";
|
|
43
|
+
url.search = "";
|
|
44
|
+
|
|
45
|
+
if (!url.pathname.endsWith(".html")) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
url.pathname = url.pathname.replace(/\.html$/, ".md");
|
|
50
|
+
return url.toString();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
get copyMarkdownButtonText(): string {
|
|
54
|
+
return COPY_MARKDOWN_LABEL;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
get viewMarkdownButtonText(): string {
|
|
58
|
+
return VIEW_MARKDOWN_LABEL;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
get copyUrlButtonText(): string {
|
|
62
|
+
return COPY_URL_LABEL;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async handleCopyMarkdown(event: Event) {
|
|
66
|
+
if (!this.markdownUrl) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
this.trackToolbarEvent(
|
|
71
|
+
event,
|
|
72
|
+
"custEv_linkClick",
|
|
73
|
+
COPY_MARKDOWN_LABEL,
|
|
74
|
+
this.markdownUrl
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
try {
|
|
78
|
+
const response = await fetch(this.markdownUrl);
|
|
79
|
+
if (!response.ok) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const markdown = await response.text();
|
|
83
|
+
await navigator.clipboard.writeText(markdown);
|
|
84
|
+
this.flashCopied("copyMarkdownLabel");
|
|
85
|
+
} catch (error) {
|
|
86
|
+
console.error(error);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
handleViewMarkdown(event: Event) {
|
|
91
|
+
if (!this.markdownUrl) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
this.trackToolbarEvent(
|
|
96
|
+
event,
|
|
97
|
+
"custEv_linkClick",
|
|
98
|
+
VIEW_MARKDOWN_LABEL,
|
|
99
|
+
this.markdownUrl
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
window.open(this.markdownUrl, "_blank", "noopener,noreferrer");
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
async handleCopyUrl(event: Event) {
|
|
106
|
+
if (!this.markdownUrl) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
this.trackToolbarEvent(
|
|
111
|
+
event,
|
|
112
|
+
"custEv_linkClick",
|
|
113
|
+
COPY_URL_LABEL,
|
|
114
|
+
this.markdownUrl
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
try {
|
|
118
|
+
await navigator.clipboard.writeText(this.markdownUrl);
|
|
119
|
+
this.flashCopied("copyUrlLabel");
|
|
120
|
+
} catch (error) {
|
|
121
|
+
console.error(error);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
private trackToolbarEvent(
|
|
126
|
+
event: Event,
|
|
127
|
+
eventName: "custEv_linkClick",
|
|
128
|
+
label: string,
|
|
129
|
+
url: string
|
|
130
|
+
): void {
|
|
131
|
+
track(event.currentTarget!, eventName, {
|
|
132
|
+
click_text: label,
|
|
133
|
+
click_url: url,
|
|
134
|
+
element_type: "button_link",
|
|
135
|
+
element_title: label,
|
|
136
|
+
content_category: ANALYTICS_CONTENT_CATEGORY
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
private flashCopied(labelKey: "copyMarkdownLabel" | "copyUrlLabel") {
|
|
141
|
+
if (this.copyTooltipResetTimeout !== null) {
|
|
142
|
+
window.clearTimeout(this.copyTooltipResetTimeout);
|
|
143
|
+
}
|
|
144
|
+
this[labelKey] = COPIED_TOOLTIP_LABEL;
|
|
145
|
+
this.copyTooltipResetTimeout = window.setTimeout(() => {
|
|
146
|
+
this.copyMarkdownLabel = DEFAULT_COPY_TOOLTIP_LABEL;
|
|
147
|
+
this.copyUrlLabel = DEFAULT_COPY_TOOLTIP_LABEL;
|
|
148
|
+
this.copyTooltipResetTimeout = null;
|
|
149
|
+
}, COPIED_TOOLTIP_RESET_MS);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { http, HttpResponse } from "msw";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Mocks for the content action toolbar so stories never hit the real
|
|
5
|
+
* docs backend. Any story rendering `doc-content-action-toolbar` (directly or
|
|
6
|
+
* via `doc-content-layout`) must register `contentActionToolbarMswHandlers`
|
|
7
|
+
* and call `interceptWindowOpenForContentActionToolbar()`.
|
|
8
|
+
*/
|
|
9
|
+
export const DUMMY_MARKDOWN_CONTENT = `# Dummy Markdown
|
|
10
|
+
|
|
11
|
+
Storybook serves this placeholder content in place of the real markdown
|
|
12
|
+
that the docs backend would return for the current page. It exists so
|
|
13
|
+
the "Copied" tooltip, the "View as Markdown" new tab, and the
|
|
14
|
+
"Copy URL to Markdown" clipboard behavior are all exercisable in
|
|
15
|
+
storybook without hitting the live backend.
|
|
16
|
+
|
|
17
|
+
- Item 1
|
|
18
|
+
- Item 2
|
|
19
|
+
- Item 3
|
|
20
|
+
`;
|
|
21
|
+
|
|
22
|
+
export const DUMMY_MARKDOWN_DATA_URL = `data:text/markdown;charset=utf-8,${encodeURIComponent(
|
|
23
|
+
DUMMY_MARKDOWN_CONTENT
|
|
24
|
+
)}`;
|
|
25
|
+
|
|
26
|
+
/** Intercepts any `.md` GET request and returns the dummy markdown. */
|
|
27
|
+
export const contentActionToolbarMswHandlers = [
|
|
28
|
+
http.get(/\.md(\?.*)?$/, () => HttpResponse.text(DUMMY_MARKDOWN_CONTENT))
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
let windowOpenIntercepted = false;
|
|
32
|
+
|
|
33
|
+
/** Redirects `window.open` calls for `.md` URLs to the dummy markdown data URL (MSW does not cover new tabs). */
|
|
34
|
+
export function interceptWindowOpenForContentActionToolbar() {
|
|
35
|
+
if (windowOpenIntercepted) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
windowOpenIntercepted = true;
|
|
39
|
+
|
|
40
|
+
const originalOpen = window.open.bind(window);
|
|
41
|
+
window.open = ((url?: string | URL, target?: string, features?: string) => {
|
|
42
|
+
const stringUrl = url?.toString() ?? "";
|
|
43
|
+
if (stringUrl.endsWith(".md")) {
|
|
44
|
+
return originalOpen(DUMMY_MARKDOWN_DATA_URL, target, features);
|
|
45
|
+
}
|
|
46
|
+
return originalOpen(url ?? "", target, features);
|
|
47
|
+
}) as typeof window.open;
|
|
48
|
+
}
|