@salesforcedevs/docs-components 1.34.0 → 1.34.1-ai-toolbar-action-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/package.json +29 -28
- package/src/modules/doc/contentActionToolbar/contentActionToolbar.css +71 -4
- package/src/modules/doc/contentActionToolbar/contentActionToolbar.html +60 -28
- package/src/modules/doc/contentActionToolbar/contentActionToolbar.ts +261 -56
- package/src/modules/doc/contentActionToolbar/contentActionToolbarMocks.ts +1 -1
- package/src/modules/doc/contentLayout/contentLayout.ts +2 -1
- package/src/modules/doc/header/header.ts +14 -3
- package/src/modules/doc/unifiedContentLayout/unifiedContentLayout.ts +46 -8
- package/LICENSE +0 -12
package/package.json
CHANGED
|
@@ -1,29 +1,30 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
2
|
+
"name": "@salesforcedevs/docs-components",
|
|
3
|
+
"version": "1.34.1-ai-toolbar-action-1",
|
|
4
|
+
"description": "Docs Lightning web components for DSC",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"engines": {
|
|
8
|
+
"node": "22.x"
|
|
9
|
+
},
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@api-components/amf-helper-mixin": "4.5.29",
|
|
15
|
+
"classnames": "2.5.1",
|
|
16
|
+
"dompurify": "3.2.4",
|
|
17
|
+
"kagekiri": "1.4.2",
|
|
18
|
+
"lodash.orderby": "4.6.0",
|
|
19
|
+
"lodash.uniqby": "4.7.0",
|
|
20
|
+
"query-string": "7.1.3",
|
|
21
|
+
"sentence-case": "3.0.4"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@types/classnames": "2.3.1",
|
|
25
|
+
"@types/lodash.orderby": "4.6.9",
|
|
26
|
+
"@types/lodash.uniqby": "4.7.9"
|
|
27
|
+
},
|
|
28
|
+
"gitHead": "4629fdd9ca18a13480044ad43515b91945d16aad",
|
|
29
|
+
"stableVersion": "1.34.1"
|
|
30
|
+
}
|
|
@@ -24,9 +24,76 @@
|
|
|
24
24
|
background-color: var(--dx-g-gray-70);
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
.toolbar-button_view-markdown,
|
|
28
|
+
.divider_view-markdown,
|
|
29
|
+
.toolbar-button_view-llms,
|
|
30
|
+
.divider_view-llms {
|
|
31
|
+
display: none;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.toolbar_no-markdown .toolbar-button_view-llms {
|
|
35
|
+
display: inline-flex;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.toolbar:not(.toolbar_no-markdown) .divider_menu {
|
|
39
|
+
display: none;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.menu-trigger-wrap {
|
|
43
|
+
position: relative;
|
|
44
|
+
display: inline-flex;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.menu-trigger {
|
|
48
|
+
--dx-c-button-custom-color: var(--dx-g-blue-vibrant-50);
|
|
49
|
+
--dx-c-button-custom-color-hover: var(--dx-g-blue-vibrant-30);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.menu-trigger::part(container) {
|
|
53
|
+
box-sizing: border-box;
|
|
54
|
+
width: var(--dx-g-spacing-xl);
|
|
55
|
+
height: var(--dx-g-spacing-xl);
|
|
56
|
+
padding: 0;
|
|
57
|
+
border: 2px solid var(--dx-g-blue-vibrant-50);
|
|
58
|
+
border-radius: var(--dx-g-spacing-xs);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.menu-trigger:hover::part(container),
|
|
62
|
+
.menu-trigger[aria-expanded="true"]::part(container) {
|
|
63
|
+
border-color: var(--dx-g-blue-vibrant-30);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.menu-trigger-copied {
|
|
67
|
+
position: absolute;
|
|
68
|
+
bottom: 100%;
|
|
69
|
+
right: calc(-1 * var(--dx-g-spacing-xs));
|
|
70
|
+
margin-bottom: var(--dx-g-spacing-xs);
|
|
71
|
+
padding: var(--dx-g-spacing-2xs) var(--dx-g-spacing-sm);
|
|
72
|
+
background: var(--dx-g-gray-50);
|
|
73
|
+
color: white;
|
|
74
|
+
font-family: var(--dx-g-font-sans);
|
|
75
|
+
font-size: var(--dx-g-text-xs);
|
|
76
|
+
border-radius: 4px;
|
|
77
|
+
pointer-events: none;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
@media screen and (min-width: 480px) {
|
|
81
|
+
.toolbar-button_view-markdown,
|
|
82
|
+
.divider_view-markdown {
|
|
83
|
+
display: inline-flex;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.toolbar:not(.toolbar_no-markdown) .divider_menu {
|
|
87
|
+
display: block;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
@media screen and (min-width: 768px) {
|
|
92
|
+
.toolbar-button_view-llms {
|
|
93
|
+
display: inline-flex;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
.toolbar:not(.toolbar_no-markdown) .divider_view-llms {
|
|
97
|
+
display: inline-flex;
|
|
31
98
|
}
|
|
32
99
|
}
|
|
@@ -1,53 +1,85 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<div class=
|
|
3
|
-
<
|
|
2
|
+
<div class={toolbarClass}>
|
|
3
|
+
<template lwc:if={hasMarkdown}>
|
|
4
|
+
<dx-tooltip placement="top-right" label={copyMarkdownTooltipLabel}>
|
|
5
|
+
<dx-button
|
|
6
|
+
class="toolbar-button"
|
|
7
|
+
variant="inline"
|
|
8
|
+
size="small"
|
|
9
|
+
icon-sprite="utility"
|
|
10
|
+
icon-symbol="copy"
|
|
11
|
+
icon-size="medium"
|
|
12
|
+
icon-position="right"
|
|
13
|
+
aria-label={copyMarkdownButtonText}
|
|
14
|
+
onclick={handleCopyMarkdown}
|
|
15
|
+
>
|
|
16
|
+
{copyMarkdownButtonText}
|
|
17
|
+
</dx-button>
|
|
18
|
+
</dx-tooltip>
|
|
19
|
+
|
|
20
|
+
<div class="divider divider_view-markdown"></div>
|
|
21
|
+
|
|
4
22
|
<dx-button
|
|
5
|
-
class="toolbar-button"
|
|
23
|
+
class="toolbar-button toolbar-button_view-markdown"
|
|
6
24
|
variant="inline"
|
|
7
25
|
size="small"
|
|
8
26
|
icon-sprite="utility"
|
|
9
|
-
icon-symbol="
|
|
27
|
+
icon-symbol="new_window"
|
|
10
28
|
icon-size="medium"
|
|
11
29
|
icon-position="right"
|
|
12
|
-
aria-label={
|
|
13
|
-
onclick={
|
|
30
|
+
aria-label={viewMarkdownButtonText}
|
|
31
|
+
onclick={handleViewMarkdown}
|
|
14
32
|
>
|
|
15
|
-
{
|
|
33
|
+
{viewMarkdownButtonText}
|
|
16
34
|
</dx-button>
|
|
17
|
-
</
|
|
35
|
+
</template>
|
|
18
36
|
|
|
19
|
-
<div class="divider"></div>
|
|
37
|
+
<div class="divider divider_view-llms"></div>
|
|
20
38
|
|
|
21
39
|
<dx-button
|
|
22
|
-
class="toolbar-button"
|
|
40
|
+
class="toolbar-button toolbar-button_view-llms"
|
|
23
41
|
variant="inline"
|
|
24
42
|
size="small"
|
|
25
43
|
icon-sprite="utility"
|
|
26
44
|
icon-symbol="new_window"
|
|
27
45
|
icon-size="medium"
|
|
28
46
|
icon-position="right"
|
|
29
|
-
aria-label={
|
|
30
|
-
onclick={
|
|
47
|
+
aria-label={viewLlmsButtonText}
|
|
48
|
+
onclick={handleViewLlms}
|
|
31
49
|
>
|
|
32
|
-
{
|
|
50
|
+
{viewLlmsButtonText}
|
|
33
51
|
</dx-button>
|
|
34
52
|
|
|
35
|
-
<div class="divider
|
|
53
|
+
<div class="divider divider_menu"></div>
|
|
36
54
|
|
|
37
|
-
<
|
|
38
|
-
<dx-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
55
|
+
<span class="menu-trigger-wrap">
|
|
56
|
+
<dx-tooltip placement="top-right" label={moreActionsLabel}>
|
|
57
|
+
<dx-dropdown
|
|
58
|
+
class="toolbar-menu"
|
|
59
|
+
options={menuOptions}
|
|
60
|
+
placement="bottom-end"
|
|
61
|
+
width-mode="fit-content"
|
|
62
|
+
aria-label={moreActionsLabel}
|
|
63
|
+
onchange={handleMenuSelect}
|
|
64
|
+
>
|
|
65
|
+
<dx-button
|
|
66
|
+
class="menu-trigger"
|
|
67
|
+
variant="icon-only"
|
|
68
|
+
size="small"
|
|
69
|
+
icon-sprite="utility"
|
|
70
|
+
icon-symbol="threedots"
|
|
71
|
+
icon-size="medium"
|
|
72
|
+
aria-label={moreActionsLabel}
|
|
73
|
+
></dx-button>
|
|
74
|
+
</dx-dropdown>
|
|
75
|
+
</dx-tooltip>
|
|
76
|
+
<span
|
|
77
|
+
class="menu-trigger-copied"
|
|
78
|
+
if:true={showCopiedFlash}
|
|
79
|
+
role="status"
|
|
48
80
|
>
|
|
49
|
-
{
|
|
50
|
-
</
|
|
51
|
-
</
|
|
81
|
+
{copiedLabel}
|
|
82
|
+
</span>
|
|
83
|
+
</span>
|
|
52
84
|
</div>
|
|
53
85
|
</template>
|
|
@@ -1,14 +1,53 @@
|
|
|
1
1
|
import { LightningElement, api } from "lwc";
|
|
2
|
+
import cx from "classnames";
|
|
3
|
+
import { OptionWithNested } from "typings/custom";
|
|
2
4
|
import { track } from "dxUtils/analytics";
|
|
3
5
|
|
|
4
|
-
const
|
|
6
|
+
const DEFAULT_TOOLTIP_LABEL = "Click to copy";
|
|
5
7
|
const COPIED_TOOLTIP_LABEL = "Copied!";
|
|
6
|
-
const
|
|
8
|
+
const COPIED_RESET_MS = 1000;
|
|
7
9
|
|
|
8
10
|
const ANALYTICS_CONTENT_CATEGORY = "content action toolbar";
|
|
11
|
+
const MORE_ACTIONS_LABEL = "More actions";
|
|
12
|
+
|
|
9
13
|
const COPY_MARKDOWN_LABEL = "Copy as Markdown";
|
|
10
14
|
const VIEW_MARKDOWN_LABEL = "View as Markdown";
|
|
11
|
-
const
|
|
15
|
+
const COPY_MARKDOWN_URL_LABEL = "Copy URL to Markdown";
|
|
16
|
+
const VIEW_LLMS_LABEL = "View llms.txt";
|
|
17
|
+
const COPY_LLMS_URL_LABEL = "Copy URL to llms.txt";
|
|
18
|
+
const OPEN_CHATGPT_LABEL = "Open in ChatGPT";
|
|
19
|
+
const OPEN_CLAUDE_LABEL = "Open in Claude";
|
|
20
|
+
const OPEN_PERPLEXITY_LABEL = "Open in Perplexity";
|
|
21
|
+
|
|
22
|
+
const LLMS_TXT_PATH = "/docs/llms.txt";
|
|
23
|
+
const CHATGPT_URL = "https://chatgpt.com/";
|
|
24
|
+
const CLAUDE_URL = "https://claude.ai/new";
|
|
25
|
+
const PERPLEXITY_URL = "https://www.perplexity.ai/search";
|
|
26
|
+
|
|
27
|
+
const LLMS_TXT_CONTEXT_URL = "https://developer.salesforce.com/docs/llms.txt";
|
|
28
|
+
|
|
29
|
+
const ACTION_COPY_MARKDOWN = "copy-markdown";
|
|
30
|
+
const ACTION_VIEW_MARKDOWN = "view-markdown";
|
|
31
|
+
const ACTION_COPY_MARKDOWN_URL = "copy-markdown-url";
|
|
32
|
+
const ACTION_VIEW_LLMS = "view-llms";
|
|
33
|
+
const ACTION_COPY_LLMS_URL = "copy-llms-url";
|
|
34
|
+
const ACTION_OPEN_CHATGPT = "open-chatgpt";
|
|
35
|
+
const ACTION_OPEN_CLAUDE = "open-claude";
|
|
36
|
+
const ACTION_OPEN_PERPLEXITY = "open-perplexity";
|
|
37
|
+
|
|
38
|
+
const AI_ASSISTANTS = [
|
|
39
|
+
{
|
|
40
|
+
action: ACTION_OPEN_CHATGPT,
|
|
41
|
+
base: CHATGPT_URL,
|
|
42
|
+
label: OPEN_CHATGPT_LABEL
|
|
43
|
+
},
|
|
44
|
+
{ action: ACTION_OPEN_CLAUDE, base: CLAUDE_URL, label: OPEN_CLAUDE_LABEL },
|
|
45
|
+
{
|
|
46
|
+
action: ACTION_OPEN_PERPLEXITY,
|
|
47
|
+
base: PERPLEXITY_URL,
|
|
48
|
+
label: OPEN_PERPLEXITY_LABEL
|
|
49
|
+
}
|
|
50
|
+
] as const;
|
|
12
51
|
|
|
13
52
|
export default class ContentActionToolbar extends LightningElement {
|
|
14
53
|
@api
|
|
@@ -23,17 +62,15 @@ export default class ContentActionToolbar extends LightningElement {
|
|
|
23
62
|
}
|
|
24
63
|
private _pageUrl?: string;
|
|
25
64
|
|
|
26
|
-
|
|
27
|
-
copyUrlLabel: string = DEFAULT_COPY_TOOLTIP_LABEL;
|
|
65
|
+
@api pageTitle?: string;
|
|
28
66
|
|
|
29
|
-
|
|
67
|
+
copyMarkdownTooltipLabel: string = DEFAULT_TOOLTIP_LABEL;
|
|
68
|
+
copiedLabel: string | null = null;
|
|
30
69
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
*/
|
|
36
|
-
get markdownUrl(): string | null {
|
|
70
|
+
private copyMarkdownResetTimeout: number | null = null;
|
|
71
|
+
private menuCopiedResetTimeout: number | null = null;
|
|
72
|
+
|
|
73
|
+
private get absolutePageUrl(): string | null {
|
|
37
74
|
if (!this.pageUrl) {
|
|
38
75
|
return null;
|
|
39
76
|
}
|
|
@@ -41,7 +78,15 @@ export default class ContentActionToolbar extends LightningElement {
|
|
|
41
78
|
const url = new URL(this.pageUrl, window.location.href);
|
|
42
79
|
url.hash = "";
|
|
43
80
|
url.search = "";
|
|
81
|
+
return url.toString();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
get markdownUrl(): string | null {
|
|
85
|
+
if (!this.absolutePageUrl) {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
44
88
|
|
|
89
|
+
const url = new URL(this.absolutePageUrl);
|
|
45
90
|
if (!url.pathname.endsWith(".html")) {
|
|
46
91
|
return null;
|
|
47
92
|
}
|
|
@@ -50,6 +95,45 @@ export default class ContentActionToolbar extends LightningElement {
|
|
|
50
95
|
return url.toString();
|
|
51
96
|
}
|
|
52
97
|
|
|
98
|
+
get llmsUrl(): string {
|
|
99
|
+
return new URL(LLMS_TXT_PATH, window.location.href).toString();
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
private buildAiAssistantUrl(base: string): string | null {
|
|
103
|
+
if (!this.absolutePageUrl) {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const title = this.pageTitle?.trim();
|
|
108
|
+
const intro = title
|
|
109
|
+
? `I'm reading "${title}" at ${this.absolutePageUrl}.`
|
|
110
|
+
: `I'm reading ${this.absolutePageUrl}.`;
|
|
111
|
+
|
|
112
|
+
const url = new URL(base);
|
|
113
|
+
url.searchParams.set(
|
|
114
|
+
"q",
|
|
115
|
+
`${intro} Read this page so I can ask questions about it. ` +
|
|
116
|
+
`For broader context, see ${LLMS_TXT_CONTEXT_URL}`
|
|
117
|
+
);
|
|
118
|
+
return url.toString();
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
get hasMarkdown(): boolean {
|
|
122
|
+
return Boolean(this.markdownUrl);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
get toolbarClass(): string {
|
|
126
|
+
return cx("toolbar", !this.hasMarkdown && "toolbar_no-markdown");
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
get moreActionsLabel(): string {
|
|
130
|
+
return MORE_ACTIONS_LABEL;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
get showCopiedFlash(): boolean {
|
|
134
|
+
return this.copiedLabel !== null;
|
|
135
|
+
}
|
|
136
|
+
|
|
53
137
|
get copyMarkdownButtonText(): string {
|
|
54
138
|
return COPY_MARKDOWN_LABEL;
|
|
55
139
|
}
|
|
@@ -58,98 +142,219 @@ export default class ContentActionToolbar extends LightningElement {
|
|
|
58
142
|
return VIEW_MARKDOWN_LABEL;
|
|
59
143
|
}
|
|
60
144
|
|
|
61
|
-
get
|
|
62
|
-
return
|
|
145
|
+
get viewLlmsButtonText(): string {
|
|
146
|
+
return VIEW_LLMS_LABEL;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
get menuOptions(): OptionWithNested[] {
|
|
150
|
+
const groups: OptionWithNested[] = [];
|
|
151
|
+
|
|
152
|
+
if (this.hasMarkdown) {
|
|
153
|
+
groups.push({
|
|
154
|
+
id: "this-page",
|
|
155
|
+
label: "This Page",
|
|
156
|
+
options: [
|
|
157
|
+
{
|
|
158
|
+
id: ACTION_COPY_MARKDOWN,
|
|
159
|
+
label: COPY_MARKDOWN_LABEL,
|
|
160
|
+
iconSprite: "utility",
|
|
161
|
+
iconSymbol: "copy"
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
id: ACTION_VIEW_MARKDOWN,
|
|
165
|
+
label: VIEW_MARKDOWN_LABEL,
|
|
166
|
+
iconSprite: "utility",
|
|
167
|
+
iconSymbol: "new_window"
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
id: ACTION_COPY_MARKDOWN_URL,
|
|
171
|
+
label: COPY_MARKDOWN_URL_LABEL,
|
|
172
|
+
iconSprite: "utility",
|
|
173
|
+
iconSymbol: "link"
|
|
174
|
+
},
|
|
175
|
+
...AI_ASSISTANTS.map(({ action, label }) => ({
|
|
176
|
+
id: action,
|
|
177
|
+
label,
|
|
178
|
+
iconSprite: "utility",
|
|
179
|
+
iconSymbol: "new_window"
|
|
180
|
+
}))
|
|
181
|
+
]
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
groups.push({
|
|
186
|
+
id: "all-documentation",
|
|
187
|
+
label: "All Documentation",
|
|
188
|
+
options: [
|
|
189
|
+
{
|
|
190
|
+
id: ACTION_VIEW_LLMS,
|
|
191
|
+
label: VIEW_LLMS_LABEL,
|
|
192
|
+
iconSprite: "utility",
|
|
193
|
+
iconSymbol: "new_window"
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
id: ACTION_COPY_LLMS_URL,
|
|
197
|
+
label: COPY_LLMS_URL_LABEL,
|
|
198
|
+
iconSprite: "utility",
|
|
199
|
+
iconSymbol: "link"
|
|
200
|
+
}
|
|
201
|
+
]
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
return groups;
|
|
63
205
|
}
|
|
64
206
|
|
|
65
207
|
async handleCopyMarkdown(event: Event) {
|
|
208
|
+
if (await this.copyMarkdown(event)) {
|
|
209
|
+
this.flashCopyMarkdownTooltip();
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
handleViewMarkdown(event: Event) {
|
|
66
214
|
if (!this.markdownUrl) {
|
|
67
215
|
return;
|
|
68
216
|
}
|
|
69
217
|
|
|
70
|
-
this.trackToolbarEvent(
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
);
|
|
218
|
+
this.trackToolbarEvent(event, VIEW_MARKDOWN_LABEL, this.markdownUrl);
|
|
219
|
+
window.open(this.markdownUrl, "_blank", "noopener,noreferrer");
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
handleViewLlms(event: Event) {
|
|
223
|
+
this.trackToolbarEvent(event, VIEW_LLMS_LABEL, this.llmsUrl);
|
|
224
|
+
window.open(this.llmsUrl, "_blank", "noopener,noreferrer");
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
private handleOpenAiAssistant(
|
|
228
|
+
event: Event,
|
|
229
|
+
label: string,
|
|
230
|
+
url: string | null
|
|
231
|
+
) {
|
|
232
|
+
if (!url) {
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
this.trackToolbarEvent(event, label, url);
|
|
237
|
+
window.open(url, "_blank", "noopener,noreferrer");
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
async handleMenuSelect(event: CustomEvent) {
|
|
241
|
+
switch (event.detail) {
|
|
242
|
+
case ACTION_COPY_MARKDOWN:
|
|
243
|
+
if (await this.copyMarkdown(event)) {
|
|
244
|
+
this.flashMenuCopied();
|
|
245
|
+
}
|
|
246
|
+
return;
|
|
247
|
+
case ACTION_VIEW_MARKDOWN:
|
|
248
|
+
this.handleViewMarkdown(event);
|
|
249
|
+
return;
|
|
250
|
+
case ACTION_COPY_MARKDOWN_URL:
|
|
251
|
+
await this.handleCopyMarkdownUrl(event);
|
|
252
|
+
return;
|
|
253
|
+
case ACTION_VIEW_LLMS:
|
|
254
|
+
this.handleViewLlms(event);
|
|
255
|
+
return;
|
|
256
|
+
case ACTION_COPY_LLMS_URL:
|
|
257
|
+
await this.handleCopyLlmsUrl(event);
|
|
258
|
+
return;
|
|
259
|
+
default: {
|
|
260
|
+
const assistant = AI_ASSISTANTS.find(
|
|
261
|
+
({ action }) => action === event.detail
|
|
262
|
+
);
|
|
263
|
+
if (assistant) {
|
|
264
|
+
this.handleOpenAiAssistant(
|
|
265
|
+
event,
|
|
266
|
+
assistant.label,
|
|
267
|
+
this.buildAiAssistantUrl(assistant.base)
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
private async copyMarkdown(event: Event): Promise<boolean> {
|
|
275
|
+
if (!this.markdownUrl) {
|
|
276
|
+
return false;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
this.trackToolbarEvent(event, COPY_MARKDOWN_LABEL, this.markdownUrl);
|
|
76
280
|
|
|
77
281
|
try {
|
|
78
282
|
const response = await fetch(this.markdownUrl);
|
|
79
283
|
if (!response.ok) {
|
|
80
|
-
return;
|
|
284
|
+
return false;
|
|
81
285
|
}
|
|
82
286
|
const markdown = await response.text();
|
|
83
287
|
await navigator.clipboard.writeText(markdown);
|
|
84
|
-
|
|
288
|
+
return true;
|
|
85
289
|
} catch (error) {
|
|
86
290
|
console.error(error);
|
|
291
|
+
return false;
|
|
87
292
|
}
|
|
88
293
|
}
|
|
89
294
|
|
|
90
|
-
|
|
295
|
+
private async handleCopyMarkdownUrl(event: Event) {
|
|
91
296
|
if (!this.markdownUrl) {
|
|
92
297
|
return;
|
|
93
298
|
}
|
|
94
299
|
|
|
95
300
|
this.trackToolbarEvent(
|
|
96
301
|
event,
|
|
97
|
-
|
|
98
|
-
VIEW_MARKDOWN_LABEL,
|
|
302
|
+
COPY_MARKDOWN_URL_LABEL,
|
|
99
303
|
this.markdownUrl
|
|
100
304
|
);
|
|
101
305
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
return;
|
|
306
|
+
try {
|
|
307
|
+
await navigator.clipboard.writeText(this.markdownUrl);
|
|
308
|
+
this.flashMenuCopied();
|
|
309
|
+
} catch (error) {
|
|
310
|
+
console.error(error);
|
|
108
311
|
}
|
|
312
|
+
}
|
|
109
313
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
"custEv_linkClick",
|
|
113
|
-
COPY_URL_LABEL,
|
|
114
|
-
this.markdownUrl
|
|
115
|
-
);
|
|
314
|
+
private async handleCopyLlmsUrl(event: Event) {
|
|
315
|
+
this.trackToolbarEvent(event, COPY_LLMS_URL_LABEL, this.llmsUrl);
|
|
116
316
|
|
|
117
317
|
try {
|
|
118
|
-
await navigator.clipboard.writeText(this.
|
|
119
|
-
this.
|
|
318
|
+
await navigator.clipboard.writeText(this.llmsUrl);
|
|
319
|
+
this.flashMenuCopied();
|
|
120
320
|
} catch (error) {
|
|
121
321
|
console.error(error);
|
|
122
322
|
}
|
|
123
323
|
}
|
|
124
324
|
|
|
125
|
-
private trackToolbarEvent(
|
|
126
|
-
event
|
|
127
|
-
eventName: "custEv_linkClick",
|
|
128
|
-
label: string,
|
|
129
|
-
url: string
|
|
130
|
-
): void {
|
|
131
|
-
track(event.currentTarget!, eventName, {
|
|
325
|
+
private trackToolbarEvent(event: Event, label: string, url: string): void {
|
|
326
|
+
track(event.currentTarget!, "custEv_linkClick", {
|
|
132
327
|
click_text: label,
|
|
133
328
|
click_url: url,
|
|
134
329
|
element_type: "button_link",
|
|
135
330
|
element_title: label,
|
|
136
331
|
content_category: ANALYTICS_CONTENT_CATEGORY,
|
|
137
332
|
// Source page the CTA was clicked from; `click_url` above is the
|
|
138
|
-
//
|
|
333
|
+
// destination. Uses the same `page_path` expression as the
|
|
139
334
|
// amfReference doc_page_view events.
|
|
140
335
|
page_path: window.location.pathname + window.location.search
|
|
141
336
|
});
|
|
142
337
|
}
|
|
143
338
|
|
|
144
|
-
private
|
|
145
|
-
if (this.
|
|
146
|
-
window.clearTimeout(this.
|
|
339
|
+
private flashCopyMarkdownTooltip() {
|
|
340
|
+
if (this.copyMarkdownResetTimeout !== null) {
|
|
341
|
+
window.clearTimeout(this.copyMarkdownResetTimeout);
|
|
342
|
+
}
|
|
343
|
+
this.copyMarkdownTooltipLabel = COPIED_TOOLTIP_LABEL;
|
|
344
|
+
this.copyMarkdownResetTimeout = window.setTimeout(() => {
|
|
345
|
+
this.copyMarkdownTooltipLabel = DEFAULT_TOOLTIP_LABEL;
|
|
346
|
+
this.copyMarkdownResetTimeout = null;
|
|
347
|
+
}, COPIED_RESET_MS);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
private flashMenuCopied() {
|
|
351
|
+
if (this.menuCopiedResetTimeout !== null) {
|
|
352
|
+
window.clearTimeout(this.menuCopiedResetTimeout);
|
|
147
353
|
}
|
|
148
|
-
this
|
|
149
|
-
this.
|
|
150
|
-
this.
|
|
151
|
-
this.
|
|
152
|
-
|
|
153
|
-
}, COPIED_TOOLTIP_RESET_MS);
|
|
354
|
+
this.copiedLabel = COPIED_TOOLTIP_LABEL;
|
|
355
|
+
this.menuCopiedResetTimeout = window.setTimeout(() => {
|
|
356
|
+
this.copiedLabel = null;
|
|
357
|
+
this.menuCopiedResetTimeout = null;
|
|
358
|
+
}, COPIED_RESET_MS);
|
|
154
359
|
}
|
|
155
360
|
}
|
|
@@ -40,7 +40,7 @@ export function interceptWindowOpenForContentActionToolbar() {
|
|
|
40
40
|
const originalOpen = window.open.bind(window);
|
|
41
41
|
window.open = ((url?: string | URL, target?: string, features?: string) => {
|
|
42
42
|
const stringUrl = url?.toString() ?? "";
|
|
43
|
-
if (stringUrl.endsWith(".md")) {
|
|
43
|
+
if (stringUrl.endsWith(".md") || stringUrl.endsWith("/llms.txt")) {
|
|
44
44
|
return originalOpen(DUMMY_MARKDOWN_DATA_URL, target, features);
|
|
45
45
|
}
|
|
46
46
|
return originalOpen(url ?? "", target, features);
|
|
@@ -307,9 +307,10 @@ export default class ContentLayout extends LightningElement {
|
|
|
307
307
|
const toolbar = (this.contentActionToolbarElement ??
|
|
308
308
|
createElement(CONTENT_ACTION_TOOLBAR_TAG, {
|
|
309
309
|
is: ContentActionToolbar
|
|
310
|
-
})) as HTMLElement & { pageUrl?: string };
|
|
310
|
+
})) as HTMLElement & { pageUrl?: string; pageTitle?: string };
|
|
311
311
|
|
|
312
312
|
toolbar.pageUrl = this.sidebarValue;
|
|
313
|
+
toolbar.pageTitle = heading.textContent?.trim() || undefined;
|
|
313
314
|
|
|
314
315
|
if (toolbar.previousElementSibling !== heading) {
|
|
315
316
|
heading.parentNode?.insertBefore(toolbar, heading.nextSibling);
|
|
@@ -74,6 +74,13 @@ export default class Header extends HeaderBase {
|
|
|
74
74
|
return (this.hideDocHeader && !this.mobile) || this.showDocDivider;
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
+
private get isDocsPath(): boolean {
|
|
78
|
+
return (
|
|
79
|
+
window.location.pathname.includes("/docs/") &&
|
|
80
|
+
window.location.pathname !== "/docs/apis"
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
77
84
|
connectedCallback(): void {
|
|
78
85
|
super.connectedCallback();
|
|
79
86
|
this.tabletMatchMedia = window.matchMedia(
|
|
@@ -83,9 +90,7 @@ export default class Header extends HeaderBase {
|
|
|
83
90
|
this.tabletMatchMedia.addEventListener("change", this.onTabletChange);
|
|
84
91
|
|
|
85
92
|
if (
|
|
86
|
-
(!this.shouldHideHeader &&
|
|
87
|
-
window.location.pathname.includes("/docs/") &&
|
|
88
|
-
window.location.pathname !== "/docs/apis") ||
|
|
93
|
+
(!this.shouldHideHeader && this.isDocsPath) ||
|
|
89
94
|
window.location.pathname ===
|
|
90
95
|
"/tableau/embedding-playground/overview" ||
|
|
91
96
|
isStorybook()
|
|
@@ -109,6 +114,12 @@ export default class Header extends HeaderBase {
|
|
|
109
114
|
);
|
|
110
115
|
}
|
|
111
116
|
|
|
117
|
+
renderedCallback(): void {
|
|
118
|
+
if (this.hideDocHeader) {
|
|
119
|
+
this.shouldRender = !this.shouldHideHeader && this.isDocsPath;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
112
123
|
private onTabletChange = (e: MediaQueryListEvent | MediaQueryList) =>
|
|
113
124
|
(this.tablet = e.matches);
|
|
114
125
|
|
|
@@ -10,11 +10,38 @@ import type { OptionWithLink, TreeNode } from "typings/custom";
|
|
|
10
10
|
*/
|
|
11
11
|
const TOPIC_TYPE_SPEC = "spec";
|
|
12
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Walks down the first-child chain and returns the first markdown content
|
|
15
|
+
* page found, descending through nested content-less parents. Returns
|
|
16
|
+
* undefined if the chain breaks on a spec or external link before reaching a
|
|
17
|
+
* content page.
|
|
18
|
+
*/
|
|
19
|
+
function firstChildContentPage(node: TreeNode): TreeNode | undefined {
|
|
20
|
+
const firstChild = node.children?.[0];
|
|
21
|
+
if (!firstChild) {
|
|
22
|
+
return undefined;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const isSpec =
|
|
26
|
+
(firstChild as { topicType?: string }).topicType === TOPIC_TYPE_SPEC;
|
|
27
|
+
const isExternal = firstChild.link?.target === "_blank";
|
|
28
|
+
if (isSpec || isExternal) {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (firstChild.link?.href) {
|
|
33
|
+
return firstChild;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return firstChildContentPage(firstChild);
|
|
37
|
+
}
|
|
38
|
+
|
|
13
39
|
/**
|
|
14
40
|
* Translates per-topic `topicType` into the generic `showForwardArrow` flag
|
|
15
|
-
* that `dx-tree-tile` reads (spec topics get the forward arrow icon for Redoc)
|
|
41
|
+
* that `dx-tree-tile` reads (spec topics get the forward arrow icon for Redoc),
|
|
42
|
+
* and redirects content-less parent topics whose first child is a content page
|
|
16
43
|
*/
|
|
17
|
-
function
|
|
44
|
+
function decorateTopics(
|
|
18
45
|
topics: Array<TreeNode & { topicType?: string }> | undefined
|
|
19
46
|
): TreeNode[] | undefined {
|
|
20
47
|
return topics?.map((topic) => {
|
|
@@ -23,10 +50,23 @@ function decorateTopicsWithForwardArrow(
|
|
|
23
50
|
decorated.showForwardArrow = true;
|
|
24
51
|
}
|
|
25
52
|
if (decorated.children) {
|
|
26
|
-
decorated.children =
|
|
27
|
-
decorated.children
|
|
28
|
-
);
|
|
53
|
+
decorated.children = decorateTopics(decorated.children);
|
|
29
54
|
}
|
|
55
|
+
|
|
56
|
+
/** Redirect a parent that has no content of its own to its first child
|
|
57
|
+
* but only when that first child is itself a content page
|
|
58
|
+
*/
|
|
59
|
+
const isContentlessParent =
|
|
60
|
+
!!decorated.children?.length && !decorated.link?.href;
|
|
61
|
+
|
|
62
|
+
if (isContentlessParent) {
|
|
63
|
+
decorated.redirectToChild = true;
|
|
64
|
+
const firstChild = firstChildContentPage(topic);
|
|
65
|
+
if (firstChild?.link) {
|
|
66
|
+
decorated.link = { ...firstChild.link };
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
30
70
|
return decorated;
|
|
31
71
|
});
|
|
32
72
|
}
|
|
@@ -77,9 +117,7 @@ export default class UnifiedContentLayout extends LightningElement {
|
|
|
77
117
|
}
|
|
78
118
|
|
|
79
119
|
set sidebarContent(value: string) {
|
|
80
|
-
this._sidebarContent =
|
|
81
|
-
toJson(value)?.topics
|
|
82
|
-
);
|
|
120
|
+
this._sidebarContent = decorateTopics(toJson(value)?.topics);
|
|
83
121
|
}
|
|
84
122
|
|
|
85
123
|
private get enableFooter(): boolean {
|
package/LICENSE
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
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.
|