@salesforcedevs/dx-components 1.3.224 → 1.3.227

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.3.224",
3
+ "version": "1.3.227",
4
4
  "description": "DX Lightning web components",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -44,5 +44,5 @@
44
44
  "volta": {
45
45
  "node": "16.19.1"
46
46
  },
47
- "gitHead": "d5ff886eb27dbd4b076db913c1c4efbdf188bf57"
47
+ "gitHead": "ca4d2f11924db69bc1e872fb61587af9bb78cdde"
48
48
  }
@@ -8,6 +8,9 @@ import {
8
8
  import { getContentTypeColorVariables } from "dxUtils/contentTypes";
9
9
  import { pollUntil } from "dxUtils/async";
10
10
 
11
+ // Max height for breadcrumb without wrapping
12
+ const MAX_BREADCRUMB_HEIGHT = 16;
13
+
11
14
  interface CoveoSearch {
12
15
  state: typeof CoveoSDK.state;
13
16
  get: typeof CoveoSDK.get;
@@ -141,10 +144,10 @@ const processParts = (parts: string[], internalFlag = false) => {
141
144
  return parts.filter(filterFn).map((part) => {
142
145
  // Remove special characters & .htm/.xml extension
143
146
  part = part
144
- .replace(/_/g, " ")
145
- .replace(/-/g, " ")
146
- .replace(/.html*/g, " ")
147
- .replace(/.xml/g, " ")
147
+ .replace(/_/g, "")
148
+ .replace(/-/g, "")
149
+ .replace(/.html*/g, "")
150
+ .replace(/.xml/g, "")
148
151
  .replace(/b2c/g, "B2C");
149
152
 
150
153
  // Capitalize first letter of each word
@@ -367,17 +370,16 @@ export default class SearchResults extends LightningElement {
367
370
  1000
368
371
  );
369
372
 
370
- this.processBreadcrumbs(this.root!);
373
+ this.processBreadcrumbs(root);
371
374
 
372
375
  window.onresize = () => this.processBreadcrumbs(root);
373
376
  });
374
377
  }
375
378
 
376
- // Checks if text is wrapping by comparing it with an element's text that doesn't wrap
377
- private isTextWrapping = (
378
- elementOne: HTMLElement,
379
- elementTwo: HTMLElement
380
- ) => elementOne.offsetHeight > elementTwo.offsetHeight;
379
+ // check if the breadcrumb is overflowing or not based on the height of a single character in the text element
380
+ private isTextWrapping = (element: HTMLElement) => {
381
+ return element.offsetHeight > MAX_BREADCRUMB_HEIGHT;
382
+ };
381
383
 
382
384
  private truncateBreadcrumbText = (breadcrumbItems: HTMLElement[]) => {
383
385
  breadcrumbItems.forEach((breadcrumbItem: HTMLElement) => {
@@ -396,12 +398,29 @@ export default class SearchResults extends LightningElement {
396
398
  breadcrumb: HTMLElement
397
399
  ) => {
398
400
  for (let i = 1; i < breadcrumbItems.length; i++) {
399
- if (this.isTextWrapping(breadcrumb, breadcrumbItems[0])) {
400
- breadcrumbItems[i].textContent = "...";
401
+ if (this.isTextWrapping(breadcrumb)) {
402
+ // if the previous element is an ellipsis, make it empty (in order to avoid multiple grouped ellipsis)
403
+ if (breadcrumbItems[i - 1]?.textContent === "...") {
404
+ breadcrumbItems[i].innerHTML = "";
405
+ } else {
406
+ breadcrumbItems[i].textContent = "...";
407
+ }
401
408
  } else {
402
409
  break; // Exit the loop if the breadcrumb is no longer overflowing
403
410
  }
404
411
  }
412
+
413
+ // remove any empty breadcrumb items
414
+ breadcrumb.innerHTML = breadcrumb.innerHTML
415
+ .replace(
416
+ / ?\/ +<span class="breadcrumb-item"><\/span> +\/ ?/g,
417
+ " / "
418
+ )
419
+ // when first loading the page on mobile, the breadcrumb items are not grouped correctly
420
+ .replace(
421
+ `<span class="breadcrumb-item">...</span> / <span class="breadcrumb-item">...</span>`,
422
+ `<span class="breadcrumb-item">...</span>`
423
+ );
405
424
  };
406
425
 
407
426
  private formatBreadcrumbs = (breadcrumbs: HTMLElement[]) => {
@@ -411,7 +430,7 @@ export default class SearchResults extends LightningElement {
411
430
  breadcrumb.querySelectorAll(".breadcrumb-item");
412
431
 
413
432
  // Check if the breadcrumb is overflowing by comparing it's height to the height of the first breadcrumb item
414
- if (this.isTextWrapping(breadcrumb, breadcrumbItems[0])) {
433
+ if (this.isTextWrapping(breadcrumb)) {
415
434
  // it is overflowing, so we need to truncate long titles to 30 characters
416
435
  this.truncateBreadcrumbText(breadcrumbItems);
417
436
 
@@ -419,7 +438,7 @@ export default class SearchResults extends LightningElement {
419
438
  this.addBreadcrumbEllipsis(breadcrumbItems, breadcrumb);
420
439
 
421
440
  // After processing all breadcrumb items, if it's still overflowing, hide the breadcrumb element
422
- if (this.isTextWrapping(breadcrumb, breadcrumbItems[0])) {
441
+ if (this.isTextWrapping(breadcrumb)) {
423
442
  breadcrumb.style.display = "none";
424
443
  }
425
444
  }