@salesforcedevs/dx-components 1.32.1-alpha.2 → 1.32.1-alpha.4

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/dx-components",
3
- "version": "1.32.1-alpha.2",
3
+ "version": "1.32.1-alpha.4",
4
4
  "description": "DX Lightning web components",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -44,5 +44,5 @@
44
44
  "luxon": "3.4.4",
45
45
  "msw": "^2.12.4"
46
46
  },
47
- "gitHead": "4288b70a2675c017c7107686bace5802189e9d44"
47
+ "gitHead": "e64bce535a62d5e89c1c3bfe226c424e99d28379"
48
48
  }
@@ -1,37 +1,18 @@
1
1
  /* eslint-disable @lwc/lwc/no-document-query */
2
2
  import { LightningElement, api } from "lwc";
3
+ import { waitUntilResolved } from "dxUtils/async";
3
4
 
4
5
  const HOSTED_MIAW_UI_TAG = "page-builder-miaw-ui";
5
6
  const SCRIPT_SRC =
6
7
  "https://a.sfdcstatic.com/digital/@sfdc-www-emu/page-builder-miaw-ui/v1-stable/page-builder-miaw-ui.js";
7
8
  const DEFINE_TIMEOUT_MS = 60000;
9
+ const WHEN_DEFINED_TIMEOUT_MESSAGE =
10
+ `MIAW UI embed (${HOSTED_MIAW_UI_TAG}) did not register within ${
11
+ DEFINE_TIMEOUT_MS / 1000
12
+ }s. ` +
13
+ "Confirm the script loads (network tab), your origin is allowed, and CSP permits this script.";
8
14
 
9
- let miawInitPromise: Promise<void> | null = null;
10
-
11
- function waitUntilHostedMiawUiDefined(): Promise<void> {
12
- const message =
13
- `MIAW UI embed (${HOSTED_MIAW_UI_TAG}) did not register within ${
14
- DEFINE_TIMEOUT_MS / 1000
15
- }s. ` +
16
- "Confirm the script loads (network tab), your origin is allowed, and CSP permits this script.";
17
-
18
- return new Promise((resolve, reject) => {
19
- const timeoutId = window.setTimeout(() => {
20
- reject(new Error(message));
21
- }, DEFINE_TIMEOUT_MS);
22
-
23
- customElements.whenDefined(HOSTED_MIAW_UI_TAG).then(
24
- () => {
25
- window.clearTimeout(timeoutId);
26
- resolve();
27
- },
28
- (err: unknown) => {
29
- window.clearTimeout(timeoutId);
30
- reject(err);
31
- }
32
- );
33
- });
34
- }
15
+ let scriptLoaded: Promise<void> | null = null;
35
16
 
36
17
  async function ensureMiawScriptAndDefinition(): Promise<void> {
37
18
  if (customElements.get(HOSTED_MIAW_UI_TAG)) {
@@ -43,7 +24,11 @@ async function ensureMiawScriptAndDefinition(): Promise<void> {
43
24
  ) as HTMLScriptElement | null;
44
25
 
45
26
  if (script) {
46
- await waitUntilHostedMiawUiDefined();
27
+ await waitUntilResolved(
28
+ customElements.whenDefined(HOSTED_MIAW_UI_TAG),
29
+ DEFINE_TIMEOUT_MS,
30
+ WHEN_DEFINED_TIMEOUT_MESSAGE
31
+ );
47
32
  return;
48
33
  }
49
34
 
@@ -66,20 +51,19 @@ async function ensureMiawScriptAndDefinition(): Promise<void> {
66
51
  document.head.appendChild(script!);
67
52
  });
68
53
 
69
- await waitUntilHostedMiawUiDefined();
54
+ await waitUntilResolved(
55
+ customElements.whenDefined(HOSTED_MIAW_UI_TAG),
56
+ DEFINE_TIMEOUT_MS,
57
+ WHEN_DEFINED_TIMEOUT_MESSAGE
58
+ );
70
59
  }
71
60
 
72
- function loadMiawUi(): Promise<void> {
73
- if (miawInitPromise) {
74
- return miawInitPromise;
61
+ /** Loads the MIAW UI script if it is not already loaded. This occurs only once per module instance. */
62
+ function loadMiawUiScript(): Promise<void> {
63
+ if (!scriptLoaded) {
64
+ scriptLoaded = ensureMiawScriptAndDefinition();
75
65
  }
76
-
77
- miawInitPromise = ensureMiawScriptAndDefinition().catch((e) => {
78
- miawInitPromise = null;
79
- throw e;
80
- });
81
-
82
- return miawInitPromise;
66
+ return scriptLoaded;
83
67
  }
84
68
 
85
69
  export default class AgentMiawUi extends LightningElement {
@@ -90,92 +74,81 @@ export default class AgentMiawUi extends LightningElement {
90
74
  @api deploymentDevName = "page_builder_miaw_ui";
91
75
  @api richComponentVersion = "v1-stable";
92
76
  @api routingAttributes?: string;
77
+ /**
78
+ * JSON array of suggested prompt strings for the MIAW UI (e.g.
79
+ * `["Show me an Agentforce demo","Help me build a business case"]`); forwarded as `prompts` on the embed.
80
+ */
81
+ @api prompts?: string;
82
+ /** When set, forwarded to the embed as `welcome-text` (greeting / headline copy). */
83
+ @api welcomeText?: string;
93
84
  /**
94
85
  * When set, bar gradient start (CSS color); sets `--wes-color-af-bar-gradient-from` on the
95
- * `.miaw-host` container and on the embed when present (LWC may reset `this.style` on the host).
86
+ * hosted `page-builder-miaw-ui` element when it exists.
96
87
  */
97
88
  @api gradientFrom?: string;
98
89
  /**
99
- * When set, bar gradient end (CSS color); sets `--wes-color-af-bar-gradient-to` the same way.
90
+ * When set, bar gradient end (CSS color); sets `--wes-color-af-bar-gradient-to` on that element.
100
91
  */
101
92
  @api gradientTo?: string;
102
93
 
94
+ /** After first mount attempt is scheduled, we do not run it again for this instance. */
95
+ private hasRendered = false;
96
+
103
97
  renderedCallback(): void {
104
- this.syncGradientToMiawSubtree();
98
+ if (!this.hasRendered) {
99
+ this.hasRendered = true;
100
+ this.mountMiawHost();
101
+ }
105
102
  }
106
103
 
107
- /** Applies gradient custom properties where the embed can see them (not on `this` LWC can clear host inline styles). */
108
- private syncGradientToMiawSubtree(): void {
104
+ private setGradientColors(element: HTMLElement | null): void {
109
105
  const from = this.gradientFrom?.trim();
110
106
  const to = this.gradientTo?.trim();
111
- if (!from && !to) {
112
- return;
113
- }
114
107
 
115
- const container = this.template.querySelector(
116
- ".miaw-host"
117
- ) as HTMLElement | null;
118
- if (!container) {
119
- return;
108
+ if (from) {
109
+ element?.style?.setProperty(
110
+ "--wes-color-af-bar-gradient-from",
111
+ from!
112
+ );
120
113
  }
121
-
122
- const embed = container.querySelector(
123
- HOSTED_MIAW_UI_TAG
124
- ) as HTMLElement | null;
125
- const targets = embed ? [container, embed] : [container];
126
-
127
- for (const node of targets) {
128
- if (from) {
129
- node.style.setProperty(
130
- "--wes-color-af-bar-gradient-from",
131
- from
132
- );
133
- }
134
- if (to) {
135
- node.style.setProperty("--wes-color-af-bar-gradient-to", to);
136
- }
114
+ if (to) {
115
+ element?.style?.setProperty("--wes-color-af-bar-gradient-to", to!);
137
116
  }
138
117
  }
139
118
 
140
- connectedCallback(): void {
141
- // Past the connect flush so `this.template` includes `.miaw-host`; parent supplies `@api` in markup.
142
- queueMicrotask(() => {
143
- this.mountMiawHost();
144
- });
145
- }
146
-
147
- private mountMiawHost(): void {
148
- if (!this.orgId || !this.messagingUrl) {
149
- return;
150
- }
151
- (async () => {
152
- try {
153
- await loadMiawUi();
154
- const container = this.template.querySelector(".miaw-host");
155
- if (!container || container.querySelector(HOSTED_MIAW_UI_TAG)) {
156
- return;
157
- }
158
-
159
- const el = document.createElement(HOSTED_MIAW_UI_TAG);
160
- el.setAttribute("org-id", this.orgId);
161
- el.setAttribute("messaging-url", this.messagingUrl);
162
- el.setAttribute("deployment-dev-name", this.deploymentDevName);
163
- el.setAttribute("input-variant", "mini-sidebar");
119
+ private async mountMiawHost(): Promise<void> {
120
+ try {
121
+ await loadMiawUiScript();
122
+ const container = this.template.querySelector(".miaw-host");
123
+ if (!container) {
124
+ return;
125
+ }
126
+ const el = document.createElement(HOSTED_MIAW_UI_TAG);
127
+ el.setAttribute("org-id", this.orgId);
128
+ el.setAttribute("messaging-url", this.messagingUrl);
129
+ el.setAttribute("deployment-dev-name", this.deploymentDevName);
130
+ el.setAttribute("input-variant", "mini-sidebar");
131
+ el.setAttribute("is-on-digital-domain", "false");
132
+ el.setAttribute(
133
+ "rich-component-version",
134
+ this.richComponentVersion
135
+ );
136
+ if (this.routingAttributes) {
164
137
  el.setAttribute(
165
- "rich-component-version",
166
- this.richComponentVersion
138
+ "routing-attributes",
139
+ this.routingAttributes
167
140
  );
168
- if (this.routingAttributes) {
169
- el.setAttribute(
170
- "routing-attributes",
171
- this.routingAttributes
172
- );
173
- }
174
- container.appendChild(el);
175
- this.syncGradientToMiawSubtree();
176
- } catch (e) {
177
- console.error(e);
178
141
  }
179
- })();
142
+ if (this.prompts) {
143
+ el.setAttribute("prompts", this.prompts);
144
+ }
145
+ if (this.welcomeText) {
146
+ el.setAttribute("welcome-text", this.welcomeText);
147
+ }
148
+ container.appendChild(el);
149
+ this.setGradientColors(el);
150
+ } catch (e) {
151
+ console.error(e);
152
+ }
180
153
  }
181
154
  }
@@ -8,7 +8,7 @@ class Footer extends LightningElement {
8
8
  private _variant: FooterVariant = "small-signup";
9
9
  private isSlotEmpty = true;
10
10
  private signupUrl =
11
- "https://www.salesforce.com/form/other/role-based-newsletter/?Developer=true";
11
+ "https://www.salesforce.com/company/newsletter-subscribe/?topics=Developer";
12
12
 
13
13
  @api
14
14
  mfeHomeHref: string = `/${window.location.host}`; // ugly hack: ideally this wouldn't be necessary, but the only way to remove the "See all ways to contact us" link from the footer MFE is to set this to a non-empty value other than "us"; and given the way that the footer works, the non-empty value needs to be something that can be appended to `/` and work correctly
@@ -151,7 +151,10 @@ function augmentWithNonMFEFooterFunctionality(FooterClass: typeof Footer) {
151
151
  private buildFooterConfigLookupTables(config: any[]) {
152
152
  config.forEach((item: any) => {
153
153
  // attr_title is preferable to title because it is not language-specific
154
- this.configItemTitleToItemLookup.set(item.attr_title || item.title, item);
154
+ this.configItemTitleToItemLookup.set(
155
+ item.attr_title || item.title,
156
+ item
157
+ );
155
158
  if (item.menu_item_parent) {
156
159
  const parentId = parseInt(item.menu_item_parent, 10);
157
160
  const children =
@@ -188,26 +191,26 @@ function augmentWithNonMFEFooterFunctionality(FooterClass: typeof Footer) {
188
191
  return;
189
192
  }
190
193
 
191
- this.socialLinks =
192
- socialLinksItems.map((child: any) => {
193
- const childTitle: string = child.attr_title || child.title || ""; // attr_title is preferable to title because it is not language-specific
194
- const iconSymbol =
195
- childTitle === "LinkedIn"
196
- ? "linked-in"
197
- : childTitle.toLocaleLowerCase();
198
- const iconUrlHash =
199
- iconSymbol === "twitter"
200
- ? "#twitter-x"
201
- : `#themed-${iconSymbol}`;
202
-
203
- return {
204
- href: child.url,
205
- iconSprite: "brand",
206
- iconURL: `${baseSocialIconUrl}${iconUrlHash}`,
207
- label: child.title,
208
- iconSymbol
209
- };
210
- });
194
+ this.socialLinks = socialLinksItems.map((child: any) => {
195
+ const childTitle: string =
196
+ child.attr_title || child.title || ""; // attr_title is preferable to title because it is not language-specific
197
+ const iconSymbol =
198
+ childTitle === "LinkedIn"
199
+ ? "linked-in"
200
+ : childTitle.toLocaleLowerCase();
201
+ const iconUrlHash =
202
+ iconSymbol === "twitter"
203
+ ? "#twitter-x"
204
+ : `#themed-${iconSymbol}`;
205
+
206
+ return {
207
+ href: child.url,
208
+ iconSprite: "brand",
209
+ iconURL: `${baseSocialIconUrl}${iconUrlHash}`,
210
+ label: child.title,
211
+ iconSymbol
212
+ };
213
+ });
211
214
  }
212
215
 
213
216
  private setGeneralLinks() {
@@ -234,10 +237,14 @@ function augmentWithNonMFEFooterFunctionality(FooterClass: typeof Footer) {
234
237
 
235
238
  const generalLinks: any[] = [];
236
239
  generalLinksHeadingsItems.forEach((item: any) => {
237
- const childrenItems = this.configItemParentToChildrenLookup.get(item.ID);
240
+ const childrenItems = this.configItemParentToChildrenLookup.get(
241
+ item.ID
242
+ );
238
243
 
239
244
  if (!childrenItems) {
240
- console.error(`General links children items not found for item with title "${item.title}"`);
245
+ console.error(
246
+ `General links children items not found for item with title "${item.title}"`
247
+ );
241
248
  return;
242
249
  }
243
250
 
@@ -260,16 +267,24 @@ function augmentWithNonMFEFooterFunctionality(FooterClass: typeof Footer) {
260
267
  }
261
268
 
262
269
  private setLegalFooter() {
263
- const copyrightNoticeItem = this.configItemTitleToItemLookup.get("All rights reserved");
270
+ const copyrightNoticeItem = this.configItemTitleToItemLookup.get(
271
+ "All rights reserved"
272
+ );
264
273
 
265
274
  if (!copyrightNoticeItem) {
266
- console.error("All rights reserved item not found in footer config");
275
+ console.error(
276
+ "All rights reserved item not found in footer config"
277
+ );
267
278
  return;
268
279
  }
269
280
 
270
281
  const { url, description } = copyrightNoticeItem;
271
- const copyrightNoticeInnerHtml = description.replace("{{All rights reserved}}", `<a href="${url}">All rights reserved</a>`);
272
- const copyrightNoticeEl = this.template.querySelector(".copyright-notice")!;
282
+ const copyrightNoticeInnerHtml = description.replace(
283
+ "{{All rights reserved}}",
284
+ `<a href="${url}">All rights reserved</a>`
285
+ );
286
+ const copyrightNoticeEl =
287
+ this.template.querySelector(".copyright-notice")!;
273
288
  copyrightNoticeEl.innerHTML = copyrightNoticeInnerHtml;
274
289
  const copyrightLink = copyrightNoticeEl.querySelector("a");
275
290
  if (copyrightLink) {
@@ -278,10 +293,14 @@ function augmentWithNonMFEFooterFunctionality(FooterClass: typeof Footer) {
278
293
  );
279
294
  }
280
295
 
281
- const legalLinksItems = this.configItemParentToChildrenLookup.get(copyrightNoticeItem.ID);
296
+ const legalLinksItems = this.configItemParentToChildrenLookup.get(
297
+ copyrightNoticeItem.ID
298
+ );
282
299
 
283
300
  if (!legalLinksItems) {
284
- console.error("Legal links children items not found in footer config");
301
+ console.error(
302
+ "Legal links children items not found in footer config"
303
+ );
285
304
  return;
286
305
  }
287
306
 
@@ -298,7 +317,8 @@ function augmentWithNonMFEFooterFunctionality(FooterClass: typeof Footer) {
298
317
  link.href = "#";
299
318
  link.onclick = this.handleCookiePreferencesClick;
300
319
  } else if (itemTitle === "Your Privacy Choices") {
301
- link.img = "https://developer.salesforce.com/ns-assets/privacyoptions.svg";
320
+ link.img =
321
+ "https://developer.salesforce.com/ns-assets/privacyoptions.svg";
302
322
  }
303
323
 
304
324
  return link;
@@ -306,7 +326,10 @@ function augmentWithNonMFEFooterFunctionality(FooterClass: typeof Footer) {
306
326
  }
307
327
 
308
328
  private openOneTrustInfoDisplay() {
309
- if ((window as any).OneTrust && (window as any).OneTrust.ToggleInfoDisplay) {
329
+ if (
330
+ (window as any).OneTrust &&
331
+ (window as any).OneTrust.ToggleInfoDisplay
332
+ ) {
310
333
  (window as any).OneTrust.ToggleInfoDisplay();
311
334
  }
312
335
  }
@@ -43,3 +43,35 @@ export function pollUntil(
43
43
  }
44
44
  });
45
45
  }
46
+
47
+ /**
48
+ * Returns the same settled value or rejection as `promise`, or rejects after `forMaximumMs`
49
+ * if it does not settle in time. When `forMaximumMs` is omitted or non-positive, returns
50
+ * `promise` unchanged. Clears the timeout when `promise` settles first.
51
+ */
52
+ export function waitUntilResolved<T>(
53
+ promise: Promise<T>,
54
+ forMaximumMs?: number,
55
+ timeoutMessage = "Timed out waiting for promise to settle."
56
+ ): Promise<T> {
57
+ if (forMaximumMs == null || forMaximumMs <= 0) {
58
+ return promise;
59
+ }
60
+
61
+ return new Promise<T>((resolve, reject) => {
62
+ const timeoutId = setTimeout(() => {
63
+ reject(new Error(timeoutMessage));
64
+ }, forMaximumMs);
65
+
66
+ promise.then(
67
+ (value) => {
68
+ clearTimeout(timeoutId);
69
+ resolve(value);
70
+ },
71
+ (reason: unknown) => {
72
+ clearTimeout(timeoutId);
73
+ reject(reason);
74
+ }
75
+ );
76
+ });
77
+ }