@salesforcedevs/docs-components 1.34.1-ai-toolbar-action → 1.34.1-ai-toolbar-action-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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforcedevs/docs-components",
3
- "version": "1.34.1-ai-toolbar-action",
3
+ "version": "1.34.1-ai-toolbar-action-2",
4
4
  "description": "Docs Lightning web components for DSC",
5
5
  "license": "MIT",
6
6
  "main": "index.js",
@@ -39,29 +39,23 @@
39
39
  display: none;
40
40
  }
41
41
 
42
- .menu-trigger-wrap {
43
- position: relative;
44
- display: inline-flex;
42
+ .menu-trigger {
43
+ --dx-c-button-custom-color: var(--dx-g-blue-vibrant-50);
44
+ --dx-c-button-custom-color-hover: var(--dx-g-blue-vibrant-30);
45
45
  }
46
46
 
47
- .menu-trigger {
48
- --dx-c-button-custom-color: var(--dx-g-gray-50);
49
- --dx-c-button-custom-color-hover: var(--dx-g-gray-10);
47
+ .menu-trigger::part(container) {
48
+ box-sizing: border-box;
49
+ width: var(--dx-g-spacing-xl);
50
+ height: var(--dx-g-spacing-xl);
51
+ padding: 0;
52
+ border: 2px solid var(--dx-g-blue-vibrant-50);
53
+ border-radius: var(--dx-g-spacing-xs);
50
54
  }
51
55
 
52
- .menu-trigger-copied {
53
- position: absolute;
54
- bottom: 100%;
55
- right: calc(-1 * var(--dx-g-spacing-xs));
56
- margin-bottom: var(--dx-g-spacing-xs);
57
- padding: var(--dx-g-spacing-2xs) var(--dx-g-spacing-sm);
58
- background: var(--dx-g-gray-50);
59
- color: white;
60
- font-family: var(--dx-g-font-sans);
61
- font-size: var(--dx-g-text-xs);
62
- white-space: nowrap;
63
- border-radius: 4px;
64
- pointer-events: none;
56
+ .menu-trigger:hover::part(container),
57
+ .menu-trigger[aria-expanded="true"]::part(container) {
58
+ border-color: var(--dx-g-blue-vibrant-30);
65
59
  }
66
60
 
67
61
  @media screen and (min-width: 480px) {
@@ -52,34 +52,29 @@
52
52
 
53
53
  <div class="divider divider_menu"></div>
54
54
 
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"
55
+ <dx-tooltip
56
+ placement="top-right"
57
+ label={menuTooltipLabel}
58
+ visible={menuTooltipVisible}
59
+ >
60
+ <dx-dropdown
61
+ class="toolbar-menu"
62
+ options={menuOptions}
63
+ placement="bottom-end"
64
+ width-mode="fit-content"
65
+ aria-label={moreActionsLabel}
66
+ onchange={handleMenuSelect}
80
67
  >
81
- {copiedLabel}
82
- </span>
83
- </span>
68
+ <dx-button
69
+ class="menu-trigger"
70
+ variant="icon-only"
71
+ size="small"
72
+ icon-sprite="utility"
73
+ icon-symbol="threedots"
74
+ icon-size="medium"
75
+ aria-label={moreActionsLabel}
76
+ ></dx-button>
77
+ </dx-dropdown>
78
+ </dx-tooltip>
84
79
  </div>
85
80
  </template>
@@ -35,6 +35,20 @@ const ACTION_OPEN_CHATGPT = "open-chatgpt";
35
35
  const ACTION_OPEN_CLAUDE = "open-claude";
36
36
  const ACTION_OPEN_PERPLEXITY = "open-perplexity";
37
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;
51
+
38
52
  export default class ContentActionToolbar extends LightningElement {
39
53
  @api
40
54
  get pageUrl(): string | undefined {
@@ -51,10 +65,10 @@ export default class ContentActionToolbar extends LightningElement {
51
65
  @api pageTitle?: string;
52
66
 
53
67
  copyMarkdownTooltipLabel: string = DEFAULT_TOOLTIP_LABEL;
54
- copiedLabel: string | null = null;
68
+ menuTooltipLabel?: string;
69
+ menuTooltipVisible: boolean = false;
55
70
 
56
- private copyMarkdownResetTimeout: number | null = null;
57
- private menuCopiedResetTimeout: number | null = null;
71
+ private tooltipResetTimeout: number | null = null;
58
72
 
59
73
  private get absolutePageUrl(): string | null {
60
74
  if (!this.pageUrl) {
@@ -85,18 +99,6 @@ export default class ContentActionToolbar extends LightningElement {
85
99
  return new URL(LLMS_TXT_PATH, window.location.href).toString();
86
100
  }
87
101
 
88
- get chatGptUrl(): string | null {
89
- return this.buildAiAssistantUrl(CHATGPT_URL);
90
- }
91
-
92
- get claudeUrl(): string | null {
93
- return this.buildAiAssistantUrl(CLAUDE_URL);
94
- }
95
-
96
- get perplexityUrl(): string | null {
97
- return this.buildAiAssistantUrl(PERPLEXITY_URL);
98
- }
99
-
100
102
  private buildAiAssistantUrl(base: string): string | null {
101
103
  if (!this.absolutePageUrl) {
102
104
  return null;
@@ -128,10 +130,6 @@ export default class ContentActionToolbar extends LightningElement {
128
130
  return MORE_ACTIONS_LABEL;
129
131
  }
130
132
 
131
- get showCopiedFlash(): boolean {
132
- return this.copiedLabel !== null;
133
- }
134
-
135
133
  get copyMarkdownButtonText(): string {
136
134
  return COPY_MARKDOWN_LABEL;
137
135
  }
@@ -170,24 +168,12 @@ export default class ContentActionToolbar extends LightningElement {
170
168
  iconSprite: "utility",
171
169
  iconSymbol: "link"
172
170
  },
173
- {
174
- id: ACTION_OPEN_CHATGPT,
175
- label: OPEN_CHATGPT_LABEL,
176
- iconSprite: "utility",
177
- iconSymbol: "new_window"
178
- },
179
- {
180
- id: ACTION_OPEN_CLAUDE,
181
- label: OPEN_CLAUDE_LABEL,
182
- iconSprite: "utility",
183
- iconSymbol: "new_window"
184
- },
185
- {
186
- id: ACTION_OPEN_PERPLEXITY,
187
- label: OPEN_PERPLEXITY_LABEL,
171
+ ...AI_ASSISTANTS.map(({ action, label }) => ({
172
+ id: action,
173
+ label,
188
174
  iconSprite: "utility",
189
175
  iconSymbol: "new_window"
190
- }
176
+ }))
191
177
  ]
192
178
  });
193
179
  }
@@ -266,28 +252,18 @@ export default class ContentActionToolbar extends LightningElement {
266
252
  case ACTION_COPY_LLMS_URL:
267
253
  await this.handleCopyLlmsUrl(event);
268
254
  return;
269
- case ACTION_OPEN_CHATGPT:
270
- this.handleOpenAiAssistant(
271
- event,
272
- OPEN_CHATGPT_LABEL,
273
- this.chatGptUrl
255
+ default: {
256
+ const assistant = AI_ASSISTANTS.find(
257
+ ({ action }) => action === event.detail
274
258
  );
275
- return;
276
- case ACTION_OPEN_CLAUDE:
277
- this.handleOpenAiAssistant(
278
- event,
279
- OPEN_CLAUDE_LABEL,
280
- this.claudeUrl
281
- );
282
- return;
283
- case ACTION_OPEN_PERPLEXITY:
284
- this.handleOpenAiAssistant(
285
- event,
286
- OPEN_PERPLEXITY_LABEL,
287
- this.perplexityUrl
288
- );
289
- break;
290
- default:
259
+ if (assistant) {
260
+ this.handleOpenAiAssistant(
261
+ event,
262
+ assistant.label,
263
+ this.buildAiAssistantUrl(assistant.base)
264
+ );
265
+ }
266
+ }
291
267
  }
292
268
  }
293
269
 
@@ -323,23 +299,22 @@ export default class ContentActionToolbar extends LightningElement {
323
299
  this.markdownUrl
324
300
  );
325
301
 
326
- try {
327
- await navigator.clipboard.writeText(this.markdownUrl);
328
- this.flashMenuCopied();
329
- } catch (error) {
330
- console.error(error);
331
- }
302
+ await this.copyToClipboard(this.markdownUrl);
332
303
  }
333
304
 
334
305
  private async handleCopyLlmsUrl(event: Event) {
335
306
  this.trackToolbarEvent(event, COPY_LLMS_URL_LABEL, this.llmsUrl);
336
307
 
308
+ await this.copyToClipboard(this.llmsUrl);
309
+ }
310
+
311
+ private async copyToClipboard(text: string) {
337
312
  try {
338
- await navigator.clipboard.writeText(this.llmsUrl);
339
- this.flashMenuCopied();
313
+ await navigator.clipboard.writeText(text);
340
314
  } catch (error) {
341
315
  console.error(error);
342
316
  }
317
+ this.flashMenuCopied();
343
318
  }
344
319
 
345
320
  private trackToolbarEvent(event: Event, label: string, url: string): void {
@@ -357,24 +332,28 @@ export default class ContentActionToolbar extends LightningElement {
357
332
  }
358
333
 
359
334
  private flashCopyMarkdownTooltip() {
360
- if (this.copyMarkdownResetTimeout !== null) {
361
- window.clearTimeout(this.copyMarkdownResetTimeout);
362
- }
363
335
  this.copyMarkdownTooltipLabel = COPIED_TOOLTIP_LABEL;
364
- this.copyMarkdownResetTimeout = window.setTimeout(() => {
336
+ this.flashCopied(() => {
365
337
  this.copyMarkdownTooltipLabel = DEFAULT_TOOLTIP_LABEL;
366
- this.copyMarkdownResetTimeout = null;
367
- }, COPIED_RESET_MS);
338
+ });
368
339
  }
369
340
 
370
341
  private flashMenuCopied() {
371
- if (this.menuCopiedResetTimeout !== null) {
372
- window.clearTimeout(this.menuCopiedResetTimeout);
342
+ this.menuTooltipLabel = COPIED_TOOLTIP_LABEL;
343
+ this.menuTooltipVisible = true;
344
+ this.flashCopied(() => {
345
+ this.menuTooltipVisible = false;
346
+ this.menuTooltipLabel = undefined;
347
+ });
348
+ }
349
+
350
+ private flashCopied(reset: () => void) {
351
+ if (this.tooltipResetTimeout !== null) {
352
+ window.clearTimeout(this.tooltipResetTimeout);
373
353
  }
374
- this.copiedLabel = COPIED_TOOLTIP_LABEL;
375
- this.menuCopiedResetTimeout = window.setTimeout(() => {
376
- this.copiedLabel = null;
377
- this.menuCopiedResetTimeout = null;
354
+ this.tooltipResetTimeout = window.setTimeout(() => {
355
+ reset();
356
+ this.tooltipResetTimeout = null;
378
357
  }, COPIED_RESET_MS);
379
358
  }
380
359
  }