@salesforcedevs/dx-components 1.37.2 → 1.39.0-alpha1

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 CHANGED
@@ -72,6 +72,7 @@
72
72
  "dx/iconBadge",
73
73
  "dx/imageAndLabel",
74
74
  "dx/input",
75
+ "dx/instrumentation",
75
76
  "dx/interactiveImage",
76
77
  "dx/logo",
77
78
  "dx/mainContentHeader",
package/package.json CHANGED
@@ -1,48 +1,48 @@
1
1
  {
2
- "name": "@salesforcedevs/dx-components",
3
- "version": "1.37.2",
4
- "description": "DX Lightning web components",
5
- "license": "MIT",
6
- "engines": {
7
- "node": "22.x"
8
- },
9
- "publishConfig": {
10
- "access": "public"
11
- },
12
- "dependencies": {
13
- "@coveo/headless": "3.22.2",
14
- "@floating-ui/dom": "1.5.1",
15
- "@optimizely/optimizely-sdk": "5.3.0",
16
- "@shikijs/colorized-brackets": "^3.12.2",
17
- "@types/throttle-debounce": "5.0.2",
18
- "@vimeo/player": "2.22.0",
19
- "classnames": "2.5.1",
20
- "composed-offset-position": "0.0.4",
21
- "coveo-search-ui": "2.10113.0",
22
- "debounce": "1.2.1",
23
- "js-cookie": "3.0.5",
24
- "lodash.defaults": "4.2.0",
25
- "lodash.get": "4.4.2",
26
- "lodash.kebabcase": "4.1.1",
27
- "memoize-one": "6.0.0",
28
- "microtip": "0.2.2",
29
- "shiki": "^3.12.2",
30
- "throttle-debounce": "5.0.0",
31
- "uuid": "9.0.1"
32
- },
33
- "devDependencies": {
34
- "@types/classnames": "2.3.1",
35
- "@types/debounce": "1.2.4",
36
- "@types/js-cookie": "3.0.6",
37
- "@types/lodash.defaults": "4.2.9",
38
- "@types/lodash.get": "4.4.9",
39
- "@types/lodash.kebabcase": "4.1.9",
40
- "@types/luxon": "3.4.2",
41
- "@types/uuid": "8.3.4",
42
- "@types/vimeo__player": "2.18.3",
43
- "eventsourcemock": "2.0.0",
44
- "luxon": "3.4.4",
45
- "msw": "^2.12.4"
46
- },
47
- "gitHead": "ca79eefb9b9ec80bb48c96a091fd0ce558bda710"
48
- }
2
+ "name": "@salesforcedevs/dx-components",
3
+ "version": "1.39.0-alpha1",
4
+ "description": "DX Lightning web components",
5
+ "license": "MIT",
6
+ "engines": {
7
+ "node": "22.x"
8
+ },
9
+ "publishConfig": {
10
+ "access": "public"
11
+ },
12
+ "dependencies": {
13
+ "@coveo/headless": "3.22.2",
14
+ "@floating-ui/dom": "1.5.1",
15
+ "@optimizely/optimizely-sdk": "5.3.0",
16
+ "@shikijs/colorized-brackets": "^3.12.2",
17
+ "@types/throttle-debounce": "5.0.2",
18
+ "@vimeo/player": "2.22.0",
19
+ "classnames": "2.5.1",
20
+ "composed-offset-position": "0.0.4",
21
+ "coveo-search-ui": "2.10113.0",
22
+ "debounce": "1.2.1",
23
+ "js-cookie": "3.0.5",
24
+ "lodash.defaults": "4.2.0",
25
+ "lodash.get": "4.4.2",
26
+ "lodash.kebabcase": "4.1.1",
27
+ "memoize-one": "6.0.0",
28
+ "microtip": "0.2.2",
29
+ "shiki": "^3.12.2",
30
+ "throttle-debounce": "5.0.0",
31
+ "uuid": "9.0.1"
32
+ },
33
+ "devDependencies": {
34
+ "@types/classnames": "2.3.1",
35
+ "@types/debounce": "1.2.4",
36
+ "@types/js-cookie": "3.0.6",
37
+ "@types/lodash.defaults": "4.2.9",
38
+ "@types/lodash.get": "4.4.9",
39
+ "@types/lodash.kebabcase": "4.1.9",
40
+ "@types/luxon": "3.4.2",
41
+ "@types/uuid": "8.3.4",
42
+ "@types/vimeo__player": "2.18.3",
43
+ "eventsourcemock": "2.0.0",
44
+ "luxon": "3.4.4",
45
+ "msw": "^2.12.4"
46
+ },
47
+ "stableVersion": "1.39.0"
48
+ }
@@ -103,7 +103,9 @@ class Footer extends LightningElement {
103
103
  // This encapsulates the old non-MFE footer functionality that should be removed once the footer MFE supports rendering in non-full-width contexts.
104
104
  // It's encapsulated like this solely for ease of deletion later.
105
105
  function augmentWithNonMFEFooterFunctionality(FooterClass: typeof Footer) {
106
- const baseSocialIconUrl = `/assets/icons/brand-sprite/svg/symbols.svg`;
106
+ // Prefix with the deploy asset base path (e.g. "/PR-123"); empty in local dev.
107
+ const assetBasePath = (globalThis as any)?.LWR?.env?.assetBasePath || "";
108
+ const baseSocialIconUrl = `${assetBasePath}/assets/icons/brand-sprite/svg/symbols.svg`;
107
109
 
108
110
  return class NonMFEFooter extends FooterClass {
109
111
  private didRequestFooterConfig = false;
@@ -40,7 +40,10 @@ export default class Icon extends LightningElement {
40
40
  }
41
41
 
42
42
  private get assetUrl() {
43
- return `/assets/icons/${this.sprite}-sprite/svg/symbols.svg`;
43
+ // Prefix with the deploy asset base path (e.g. "/PR-123") so icons resolve
44
+ // when the site is served under a sub-path. Empty in local dev, so no-op there.
45
+ const assetBasePath = (globalThis as any)?.LWR?.env?.assetBasePath || "";
46
+ return `${assetBasePath}/assets/icons/${this.sprite}-sprite/svg/symbols.svg`;
44
47
  }
45
48
 
46
49
  private get href() {
@@ -0,0 +1 @@
1
+ <template></template>
@@ -0,0 +1,200 @@
1
+ import { LightningElement, api } from "lwc";
2
+ import {
3
+ TRACKING_EVENT_NAME as DX_TRACKING_EVENT_NAME,
4
+ LISTENER_QUEUE as DX_LISTENER_QUEUE,
5
+ LISTENER_INDICATOR as DX_LISTENER_INDICATOR,
6
+ track as dxTrack
7
+ } from "dxUtils/analytics";
8
+
9
+ // Architect ("architectssite_track") namespace. These mirror the constants used
10
+ // by <arch-instrumentation> in @salesforcedevs/arch-components. They are declared
11
+ // locally rather than imported because dx-components does not depend on
12
+ // arch-components.
13
+ const ARCH_TRACKING_EVENT_NAME = "architectssite_track";
14
+ const ARCH_LISTENER_QUEUE = "__TDS_INSTRUMENTATION_QUEUE__";
15
+ const ARCH_LISTENER_INDICATOR = "__TDS_INSTRUMENTATION_IS_INITIALIZED__";
16
+
17
+ // Arch-namespace equivalent of dxUtils/analytics `track`: either dispatch the
18
+ // architect tracking event (once the listener is mounted) or queue it. Used to
19
+ // replay events that were queued in __TDS_INSTRUMENTATION_QUEUE__ before this
20
+ // component mounted.
21
+ function archTrack(
22
+ element: EventTarget,
23
+ event: string,
24
+ payload: Record<string, unknown>
25
+ ): void {
26
+ const detail = { event, payload };
27
+ if ((window as any)[ARCH_LISTENER_INDICATOR] === undefined) {
28
+ (window as any)[ARCH_LISTENER_QUEUE] =
29
+ (window as any)[ARCH_LISTENER_QUEUE] || [];
30
+ (window as any)[ARCH_LISTENER_QUEUE].push(detail);
31
+ } else {
32
+ const e = new CustomEvent(ARCH_TRACKING_EVENT_NAME, {
33
+ bubbles: true,
34
+ composed: true,
35
+ detail
36
+ });
37
+ element.dispatchEvent(e);
38
+ }
39
+ }
40
+
41
+ interface NamespaceConfig {
42
+ eventName: string;
43
+ queue: string;
44
+ indicator: string;
45
+ replay: (
46
+ element: EventTarget,
47
+ event: string,
48
+ payload: Record<string, unknown>
49
+ ) => void;
50
+ }
51
+
52
+ // The two tracking-event namespaces dx-instrumentation can bridge. Keyed by the
53
+ // values accepted by the `namespaces` attribute.
54
+ const NAMESPACE_CONFIGS: Record<"developer" | "architect", NamespaceConfig> = {
55
+ developer: {
56
+ eventName: DX_TRACKING_EVENT_NAME,
57
+ queue: DX_LISTENER_QUEUE,
58
+ indicator: DX_LISTENER_INDICATOR,
59
+ replay: dxTrack
60
+ },
61
+ architect: {
62
+ eventName: ARCH_TRACKING_EVENT_NAME,
63
+ queue: ARCH_LISTENER_QUEUE,
64
+ indicator: ARCH_LISTENER_INDICATOR,
65
+ replay: archTrack
66
+ }
67
+ };
68
+
69
+ // Maps the `namespaces` attribute to the configs it activates.
70
+ function resolveNamespaceConfigs(namespaces: string): NamespaceConfig[] {
71
+ switch (namespaces) {
72
+ case "developer":
73
+ return [NAMESPACE_CONFIGS.developer];
74
+ case "architect":
75
+ return [NAMESPACE_CONFIGS.architect];
76
+ case "both":
77
+ default:
78
+ return [NAMESPACE_CONFIGS.developer, NAMESPACE_CONFIGS.architect];
79
+ }
80
+ }
81
+
82
+ const googleTagManager = {
83
+ track: function (e: Event) {
84
+ if ((window as any).dataLayer === undefined) {
85
+ (window as any).dataLayer = [];
86
+ }
87
+ const { event, payload } = (e as CustomEvent).detail;
88
+ (window as any).dataLayer.push({ ...payload, event });
89
+ }
90
+ };
91
+
92
+ interface TrackEventListener {
93
+ add: () => void;
94
+ remove: () => void;
95
+ }
96
+
97
+ /**
98
+ * Attaches a listener for each of the given tracking event names (e.g.
99
+ * `developerwebsite_track` and/or `architectssite_track`), forwarding every
100
+ * caught event to every tracker function. A single component can therefore
101
+ * bridge one or both event namespaces into the dataLayer.
102
+ */
103
+ export function instrumentationTrackEventListener(
104
+ trackerFns: { track: (e: Event) => void }[] = [],
105
+ eventNames: string[] = [DX_TRACKING_EVENT_NAME, ARCH_TRACKING_EVENT_NAME]
106
+ ): TrackEventListener {
107
+ if (trackerFns.length === 0) {
108
+ throw new Error("No tracker functions passed");
109
+ }
110
+
111
+ const handleTrackEvent = (e: Event) => {
112
+ trackerFns.forEach((tracker) => {
113
+ tracker.track(e);
114
+ });
115
+ };
116
+
117
+ const attachEventListener = () => {
118
+ eventNames.forEach((eventName) => {
119
+ document.addEventListener(eventName, handleTrackEvent);
120
+ });
121
+ };
122
+
123
+ const removeEventListener = () => {
124
+ eventNames.forEach((eventName) => {
125
+ document.removeEventListener(eventName, handleTrackEvent);
126
+ });
127
+ };
128
+
129
+ return {
130
+ add: attachEventListener,
131
+ remove: removeEventListener
132
+ };
133
+ }
134
+
135
+ /**
136
+ * Unified instrumentation bridge. Mount a single <dx-instrumentation> to forward
137
+ * developer-website and/or architect-website tracking events into the GTM
138
+ * dataLayer. Renders nothing.
139
+ *
140
+ * By default (`namespaces="both"`) it bridges both the developer
141
+ * (`developerwebsite_track`) and architect (`architectssite_track`) namespaces,
142
+ * replacing the need to mount <dw-instrumentation> and <arch-instrumentation>
143
+ * separately. Set `namespaces="developer"` (or `"architect"`) to bridge only one
144
+ * — e.g. on a site whose header analytics already reach the dataLayer through
145
+ * another path, so draining the architect queue here would double-count.
146
+ */
147
+ export default class Instrumentation extends LightningElement {
148
+ @api useGoogleTagManager = false;
149
+
150
+ // "both" (default) | "developer" | "architect"
151
+ @api namespaces = "both";
152
+
153
+ private tracker: TrackEventListener | null = null;
154
+
155
+ private setupTracker() {
156
+ const configs = resolveNamespaceConfigs(this.namespaces);
157
+ const trackerFunctions = this.useGoogleTagManager
158
+ ? [googleTagManager]
159
+ : [];
160
+ this.tracker = instrumentationTrackEventListener(
161
+ trackerFunctions,
162
+ configs.map((c) => c.eventName)
163
+ );
164
+ this.tracker.add();
165
+ // Mark each active namespace initialized so track() calls from that
166
+ // stack dispatch live events instead of queueing.
167
+ configs.forEach((c) => {
168
+ (window as any)[c.indicator] = true;
169
+ });
170
+ }
171
+
172
+ private dispatchQueuedEvents() {
173
+ resolveNamespaceConfigs(this.namespaces).forEach((config) => {
174
+ const queue = (window as any)[config.queue];
175
+ if (Array.isArray(queue)) {
176
+ while (queue.length > 0) {
177
+ const event = queue.pop() as {
178
+ event: string;
179
+ payload: Record<string, unknown>;
180
+ };
181
+ config.replay(this, event.event, event.payload);
182
+ }
183
+ }
184
+ });
185
+ }
186
+
187
+ renderedCallback() {
188
+ if (this.tracker === null) {
189
+ this.setupTracker();
190
+ this.dispatchQueuedEvents();
191
+ }
192
+ }
193
+
194
+ disconnectedCallback() {
195
+ if (this.tracker !== null) {
196
+ this.tracker.remove();
197
+ this.tracker = null;
198
+ }
199
+ }
200
+ }
@@ -5,6 +5,9 @@
5
5
  */
6
6
  const html = String.raw;
7
7
 
8
+ // Prefix hardcoded asset URLs with the deploy asset base path (e.g. "/PR-123"); empty in local dev.
9
+ const assetBasePath = (globalThis && globalThis.LWR && globalThis.LWR.env && globalThis.LWR.env.assetBasePath) || "";
10
+
8
11
  export default html`
9
12
  <div class="coveo-show-if-no-results">
10
13
  <div class="no-results">
@@ -70,7 +73,7 @@ export default html`
70
73
  >
71
74
  <%- title %>
72
75
  <% if (!raw.uri.includes('developer.salesforce.com') && !raw.uri.includes('developer-website-s.herokuapp.com')) { %>
73
- <svg xmlns="http://www.w3.org/2000/svg" style="display: inline; vertical-align: baseline;" fill="var(--dx-g-blue-vibrant-20)" width="20" height="20" part="svg" aria-hidden="true"><use xlink:href="/assets/icons/utility-sprite/svg/symbols.svg#new_window"></use></svg>
76
+ <svg xmlns="http://www.w3.org/2000/svg" style="display: inline; vertical-align: baseline;" fill="var(--dx-g-blue-vibrant-20)" width="20" height="20" part="svg" aria-hidden="true"><use xlink:href="${assetBasePath}/assets/icons/utility-sprite/svg/symbols.svg#new_window"></use></svg>
74
77
  <% } %>
75
78
  </a>
76
79
  <span class="CoveoFieldValue" data-field="@sflastmodifieddate" data-helper="postedDate" data-html-value="true"></span>
@@ -121,7 +124,7 @@ export default html`
121
124
  <%- uri %>
122
125
  <% } %>
123
126
  <% if (!raw.uri.includes('developer.salesforce.com') && !raw.uri.includes('developer-website-s.herokuapp.com')) { %>
124
- <svg xmlns="http://www.w3.org/2000/svg" style="display: inline; vertical-align: baseline;" fill="var(--dx-g-blue-vibrant-20)" width="20" height="20" part="svg" aria-hidden="true"><use xlink:href="/assets/icons/utility-sprite/svg/symbols.svg#new_window"></use></svg>
127
+ <svg xmlns="http://www.w3.org/2000/svg" style="display: inline; vertical-align: baseline;" fill="var(--dx-g-blue-vibrant-20)" width="20" height="20" part="svg" aria-hidden="true"><use xlink:href="${assetBasePath}/assets/icons/utility-sprite/svg/symbols.svg#new_window"></use></svg>
125
128
  <% } %>
126
129
  </a>
127
130
  <span class="CoveoFieldValue" data-field="@sflastmodifieddate" data-helper="postedDate" data-html-value="true"></span>
@@ -54,6 +54,8 @@ const buildTemplateHelperBadge = (value: keyof typeof CONTENT_TYPE_LABELS) => {
54
54
  const style = getContentTypeColorVariables(value);
55
55
  const label = CONTENT_TYPE_LABELS[value];
56
56
  const { iconSprite, iconSymbol } = CONTENT_TYPE_ICONS[value];
57
+ // Prefix with the deploy asset base path (e.g. "/PR-123"); empty in local dev.
58
+ const assetBasePath = (globalThis as any)?.LWR?.env?.assetBasePath || "";
57
59
  return `
58
60
  <div style="${style}" class="dx-badge">
59
61
  <svg
@@ -317,9 +317,12 @@ export default class SidebarSearch extends LightningElement {
317
317
 
318
318
  // discussion about this normalization here: https://salesforce-internal.slack.com/archives/C020S6784JX/p1639506238376600
319
319
 
320
+ // Deploy base path (e.g. "/PR-123"); empty in local dev. window.location.pathname
321
+ // is served under this prefix, so route hrefs and comparisons must include it.
322
+ const basePath = (globalThis as any)?.LWR?.env?.basePath || "";
320
323
  let pathname, queryParam;
321
324
  if (sfhtml_url__c) {
322
- pathname = `/docs/${sfhtml_url__c}`;
325
+ pathname = `${basePath}/docs/${sfhtml_url__c}`;
323
326
  } else {
324
327
  const isNestedGuide = clickUri.includes("/guide/");
325
328
  const url = new URL(clickUri);
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.