@salesforcedevs/dx-components 0.24.1 → 0.25.2-alpha.30

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.
Files changed (143) hide show
  1. package/lwc.config.json +3 -1
  2. package/package.json +2 -3
  3. package/src/.DS_Store +0 -0
  4. package/src/modules/.DS_Store +0 -0
  5. package/src/modules/dx/.DS_Store +0 -0
  6. package/src/modules/dx/banner/__tests__/banner.test.ts +11 -9
  7. package/src/modules/dx/brandThemeProvider/__tests__/brandThemeProvider.test.ts +1 -1
  8. package/src/modules/dx/breadcrumbs/__tests__/breadcrumbs.test.ts +7 -10
  9. package/src/modules/dx/button/__tests__/button.test.ts +2 -2
  10. package/src/modules/dx/cardBlogPost/__tests__/cardBlogPost.test.ts +3 -4
  11. package/src/modules/dx/cardBlogPostProvider/__tests__/cardBlogPostProvider.test.ts +1 -1
  12. package/src/modules/dx/cardBlogPostProvider/cardBlogPostProvider.ts +1 -1
  13. package/src/modules/dx/cardCallout/__tests__/cardCallout.test.ts +4 -7
  14. package/src/modules/dx/cardCallout/cardCallout.ts +1 -1
  15. package/src/modules/dx/cardContent/__tests__/cardContent.test.ts +27 -39
  16. package/src/modules/dx/cardContent/cardContent.ts +2 -2
  17. package/src/modules/dx/cardDocs/__tests__/cardDocs.test.ts +3 -3
  18. package/src/modules/dx/cardDocs/cardDocs.ts +1 -1
  19. package/src/modules/dx/cardEvent/__tests__/cardEvent.test.ts +9 -13
  20. package/src/modules/dx/cardExpanded/__tests__/cardExpanded.test.ts +2 -2
  21. package/src/modules/dx/cardExpanded/cardExpanded.ts +1 -1
  22. package/src/modules/dx/cardMinimal/__tests__/cardMinimal.test.ts +2 -2
  23. package/src/modules/dx/cardMinimal/cardMinimal.ts +1 -1
  24. package/src/modules/dx/cardNews/__tests__/cardNews.test.ts +3 -4
  25. package/src/modules/dx/cardNews/cardNews.ts +1 -1
  26. package/src/modules/dx/cardPodcastEpisode/__tests__/cardPodcastEpisode.test.ts +5 -7
  27. package/src/modules/dx/cardPodcastEpisodeProvider/__tests__/cardPodcastEpisodeProvider.test.ts +1 -1
  28. package/src/modules/dx/cardPodcastEpisodeProvider/cardPodcastEpisodeProvider.ts +1 -1
  29. package/src/modules/dx/cardSmall/__tests__/cardSmall.test.ts +10 -14
  30. package/src/modules/dx/cardSmall/cardSmall.ts +1 -1
  31. package/src/modules/dx/cardTitle/__tests__/cardTitle.test.ts +1 -1
  32. package/src/modules/dx/cardTrailheadModule/__tests__/cardTrailheadModule.test.ts +1 -1
  33. package/src/modules/dx/cardVideoPreview/__tests__/cardVideoPreview.test.ts +1 -1
  34. package/src/modules/dx/checkbox/__tests__/checkbox.test.ts +3 -4
  35. package/src/modules/dx/checkboxGroup/__tests__/checkboxGroup.test.ts +1 -1
  36. package/src/modules/dx/codeBlock/__tests__/codeBlock.test.ts +3 -3
  37. package/src/modules/dx/codeBlock/codeBlock.ts +1 -1
  38. package/src/modules/dx/dropdown/__tests__/dropdown.test.ts +16 -23
  39. package/src/modules/dx/dropdown/dropdown.ts +6 -6
  40. package/src/modules/dx/dropdownOption/__tests__/dropdownOption.test.ts +1 -1
  41. package/src/modules/dx/emptyState/__tests__/emptyState.test.ts +1 -1
  42. package/src/modules/dx/feature/__tests__/feature.test.ts +6 -5
  43. package/src/modules/dx/featureGrid/__tests__/featureGrid.test.ts +2 -2
  44. package/src/modules/dx/featuredContentHeader/__tests__/featuredContentHeader.test.ts +27 -40
  45. package/src/modules/dx/featuredContentHeader/featuredContentHeader.ts +1 -1
  46. package/src/modules/dx/featuresList/__tests__/featuresList.test.ts +9 -13
  47. package/src/modules/dx/footer/__tests__/footer.test.ts +1 -1
  48. package/src/modules/dx/footerOption/__tests__/footerOption.test.ts +1 -1
  49. package/src/modules/dx/formattedDateTime/__tests__/formattedDateTime.test.ts +1 -1
  50. package/src/modules/dx/grid/__tests__/grid.test.ts +1 -1
  51. package/src/modules/dx/groupBio/__tests__/groupBio.test.ts +1 -1
  52. package/src/modules/dx/groupText/__tests__/groupText.test.ts +9 -13
  53. package/src/modules/dx/groupText/groupText.stories.ts +1 -1
  54. package/src/modules/dx/groupText/groupText.ts +1 -1
  55. package/src/modules/dx/header/__tests__/header.test.ts +3 -3
  56. package/src/modules/dx/header/__tests__/mockProps.ts +1 -1
  57. package/src/modules/dx/header/header.ts +1 -1
  58. package/src/modules/dx/headerMobileNavMenu/__tests__/headerMobileNavMenu.test.ts +2 -2
  59. package/src/modules/dx/headerMobileNavMenu/headerMobileNavMenu.ts +1 -1
  60. package/src/modules/dx/headerMobileNavMenuOption/__tests__/headerMobileNavMenuOption.test.ts +1 -1
  61. package/src/modules/dx/headerNav/__tests__/headerNav.test.ts +1 -1
  62. package/src/modules/dx/headerSearch/__tests__/headerSearch.test.ts +2 -2
  63. package/src/modules/dx/headerSearch/__tests__/mockProps.ts +1 -1
  64. package/src/modules/dx/headerSearch/headerSearch.ts +1 -1
  65. package/src/modules/dx/helmet/__tests__/helmet.test.ts +3 -4
  66. package/src/modules/dx/hr/__tests__/hr.test.ts +1 -1
  67. package/src/modules/dx/icon/__tests__/icon.test.ts +1 -1
  68. package/src/modules/dx/icon/icon.ts +1 -1
  69. package/src/modules/dx/iconBadge/__tests__/iconBadge.test.ts +1 -1
  70. package/src/modules/dx/iconBadge/iconBadge.ts +1 -1
  71. package/src/modules/dx/imageAndLabel/__tests__/imageAndLabel.test.ts +1 -1
  72. package/src/modules/dx/input/__tests__/input.test.ts +23 -34
  73. package/src/modules/dx/input/input.ts +1 -1
  74. package/src/modules/dx/instrumentation/__tests__/instrumentation.test.ts +2 -2
  75. package/src/modules/dx/interactiveImage/__tests__/interactiveImage.test.ts +7 -10
  76. package/src/modules/dx/lazy/__tests__/lazy.test.ts +1 -1
  77. package/src/modules/dx/pagination/__tests__/pagination.test.ts +1 -1
  78. package/src/modules/dx/podcastHost/__tests__/podcastHost.test.ts +1 -1
  79. package/src/modules/dx/podcastPlayer/__tests__/podcastPlayer.test.ts +1 -1
  80. package/src/modules/dx/podcastSubscription/__tests__/podcastSubscription.test.ts +1 -1
  81. package/src/modules/dx/popover/__tests__/popover.test.ts +5 -2
  82. package/src/modules/dx/popover/popover.ts +1 -1
  83. package/src/modules/dx/radioGroup/__tests__/radioGroup.test.ts +1 -1
  84. package/src/modules/dx/relativeDateTime/__tests__/relativeDateTime.test.ts +1 -1
  85. package/src/modules/dx/section/__tests__/section.test.ts +1 -1
  86. package/src/modules/dx/section/section.ts +1 -1
  87. package/src/modules/dx/sectionSignup/__tests__/sectionSignup.test.ts +1 -1
  88. package/src/modules/dx/sidebar/__tests__/sidebar.test.ts +3 -3
  89. package/src/modules/dx/sidebar/sidebar.stories.ts +4 -1
  90. package/src/modules/dx/sidebar/sidebar.ts +1 -1
  91. package/src/modules/dx/sidebarOld/__tests__/sidebarOld.test.ts +2 -2
  92. package/src/modules/dx/sidebarOld/sidebarOld.ts +22 -7
  93. package/src/modules/dx/sidebarSearch/__tests__/sidebarSearch.test.ts +3 -60
  94. package/src/modules/dx/sidebarSearch/sidebarSearch.ts +48 -23
  95. package/src/modules/dx/sidebarSearchResult/__tests__/sidebarSearchResult.test.ts +1 -1
  96. package/src/modules/dx/slackButton/__tests__/slackButton.test.ts +1 -1
  97. package/src/modules/dx/slackCta/__tests__/slackCta.test.ts +1 -1
  98. package/src/modules/dx/socials/__tests__/socials.test.ts +1 -1
  99. package/src/modules/dx/spinner/__tests__/spinner.test.ts +1 -1
  100. package/src/modules/dx/tab/__tests__/tab.test.ts +1 -1
  101. package/src/modules/dx/toc/__tests__/mockProps.ts +6 -0
  102. package/src/modules/dx/toc/__tests__/toc.test.ts +13 -19
  103. package/src/modules/dx/toc/toc.css +1 -0
  104. package/src/modules/dx/tooltip/__tests__/tooltip.test.ts +3 -4
  105. package/src/modules/dx/topics/__tests__/topics.test.ts +1 -1
  106. package/src/modules/dx/tree/__tests__/tree.test.ts +1 -1
  107. package/src/modules/dx/treeItem/__tests__/treeItem.test.ts +1 -1
  108. package/src/modules/dx/treeTile/__tests__/treeTile.test.ts +1 -1
  109. package/src/modules/dx/typeBadge/__tests__/typeBadge.test.ts +1 -1
  110. package/src/modules/dx/typeBadge/typeBadge.ts +1 -1
  111. package/src/modules/dx/typeBadgeGroup/__tests__/typeBadgeGroup.test.ts +9 -13
  112. package/src/modules/{tests → test-components}/buttonTest/buttonTest.html +0 -0
  113. package/src/modules/{tests → test-components}/buttonTest/buttonTest.ts +0 -0
  114. package/src/modules/{tests → test-components}/codeBlockTest/codeBlockTest.js +0 -0
  115. package/src/modules/{tests → test-components}/featureGridTest/featureGridTest.html +0 -0
  116. package/src/modules/{tests → test-components}/featureGridTest/featureGridTest.ts +0 -0
  117. package/src/modules/{tests → test-components}/instrumentationTest/instrumentationTest.html +0 -0
  118. package/src/modules/{tests → test-components}/instrumentationTest/instrumentationTest.ts +0 -0
  119. package/src/modules/{tests → test-components}/popoverTest/popoverTest.html +0 -0
  120. package/src/modules/{tests → test-components}/popoverTest/popoverTest.ts +0 -0
  121. package/src/modules/utils/highlight/__tests__/highlight.test.ts +45 -43
  122. package/src/modules/utils/highlight/highlight.ts +28 -15
  123. package/src/modules/{utils → utils-internal}/archiveCard/archiveCard.ts +0 -0
  124. package/src/modules/{utils → utils-internal}/coveo/coveo.ts +0 -0
  125. package/src/modules/{utils → utils-internal}/css/css.ts +0 -0
  126. package/src/modules/{utils → utils-internal}/devices/devices.ts +0 -0
  127. package/src/modules/{utils → utils-internal}/headerBase/headerBase.ts +1 -2
  128. package/src/modules/{utils → utils-internal}/jest/jest.ts +0 -0
  129. package/src/modules/{utils → utils-internal}/options/options.ts +0 -0
  130. package/src/modules/{utils → utils-internal}/prismjs/prismjs.html +0 -0
  131. package/src/modules/{utils → utils-internal}/prismjs/prismjs.ts +220 -124
  132. package/src/modules/{utils → utils-internal}/recentSearches/__tests__/recentSearches.test.ts +5 -1
  133. package/src/modules/{utils → utils-internal}/recentSearches/recentSearches.ts +0 -0
  134. package/src/modules/utils-internal/regexps/regexps.ts +12 -0
  135. package/src/modules/{utils → utils-internal}/seo/seo.ts +0 -0
  136. package/src/modules/{utils → utils-internal}/slot/slot.ts +0 -0
  137. package/src/modules/utils-internal/storybook/storybook.ts +32 -0
  138. package/src/modules/{utils → utils-internal}/tests/tests.ts +0 -0
  139. package/src/modules/{utils → utils-internal}/wordpress/__tests__/wordpress.test.ts +0 -0
  140. package/src/modules/{utils → utils-internal}/wordpress/wordpress.ts +0 -0
  141. package/LICENSE +0 -12
  142. package/src/modules/utils/regexps/regexps.ts +0 -5
  143. package/src/modules/utils/storybook/storybook.ts +0 -33
@@ -1,5 +1,5 @@
1
1
  import Spinner from "dx/spinner";
2
- import { createRenderComponent } from "utils/tests";
2
+ import { createRenderComponent } from "utils-internal/tests";
3
3
 
4
4
  const TAG = "dx-spinner";
5
5
  const render = createRenderComponent(TAG, Spinner);
@@ -1,7 +1,7 @@
1
1
  import Tab from "dx/tab";
2
2
  import Icon from "dx/icon";
3
3
  import { track } from "dx/instrumentation";
4
- import { createRenderComponent } from "utils/tests";
4
+ import { createRenderComponent } from "utils-internal/tests";
5
5
 
6
6
  jest.mock("dx/instrumentation");
7
7
 
@@ -17,6 +17,12 @@ export default {
17
17
  "Why build on Quip? This is an extra long blurb to test the toc wrapping ability",
18
18
  id: "quip",
19
19
  anchor: "#test3"
20
+ },
21
+ {
22
+ label:
23
+ "SomeLongExampleWordWithoutAnyBreaks and Then a Word",
24
+ id: "long-word",
25
+ anchor: "#test4"
20
26
  }
21
27
  ]
22
28
  };
@@ -1,6 +1,6 @@
1
1
  import Button from "dx/button";
2
2
  import Toc from "dx/toc";
3
- import { createRenderComponent } from "utils/tests";
3
+ import { createRenderComponent } from "utils-internal/tests";
4
4
  import mockProps from "./mockProps";
5
5
 
6
6
  const TAG = "dx-toc";
@@ -11,12 +11,10 @@ describe(TAG, () => {
11
11
  const element = render(mockProps);
12
12
 
13
13
  const container: HTMLElement = element.shadowRoot.querySelector(".toc");
14
- const renderedTitle: HTMLElement = element.shadowRoot.querySelector(
15
- "h2"
16
- );
17
- const button: Button = element.shadowRoot.querySelector(
18
- ".toggle-button"
19
- );
14
+ const renderedTitle: HTMLElement =
15
+ element.shadowRoot.querySelector("h2");
16
+ const button: Button =
17
+ element.shadowRoot.querySelector(".toggle-button");
20
18
  expect(renderedTitle).not.toBeNull();
21
19
  expect(container).not.toBeNull();
22
20
  expect(renderedTitle.textContent).toEqual(mockProps.title);
@@ -27,9 +25,8 @@ describe(TAG, () => {
27
25
  it("renders table of contents buttons, and the first one is selected", () => {
28
26
  const element = render(mockProps);
29
27
 
30
- const optionsListComponent: Array<HTMLElement> = element.shadowRoot.querySelectorAll(
31
- "a"
32
- );
28
+ const optionsListComponent: Array<HTMLElement> =
29
+ element.shadowRoot.querySelectorAll("a");
33
30
  expect(optionsListComponent).toHaveLength(mockProps.options.length);
34
31
  expect(optionsListComponent[0].className).toEqual(
35
32
  "content-button selected"
@@ -59,9 +56,8 @@ describe(TAG, () => {
59
56
  const element = render({ ...mockProps });
60
57
 
61
58
  return Promise.resolve().then(() => {
62
- const optionsListComponent: Array<HTMLElement> = element.shadowRoot.querySelectorAll(
63
- "a"
64
- );
59
+ const optionsListComponent: Array<HTMLElement> =
60
+ element.shadowRoot.querySelectorAll("a");
65
61
  optionsListComponent.forEach((e) => {
66
62
  if (e.getAttribute("contentid") === mockProps.value) {
67
63
  expect(e.className).toEqual("content-button selected");
@@ -75,9 +71,8 @@ describe(TAG, () => {
75
71
  const element = render({ ...mockProps, value: undefined });
76
72
 
77
73
  return Promise.resolve().then(() => {
78
- const buttons: Array<HTMLElement> = element.shadowRoot.querySelectorAll(
79
- "a"
80
- );
74
+ const buttons: Array<HTMLElement> =
75
+ element.shadowRoot.querySelectorAll("a");
81
76
  expect(buttons[0].className).toEqual("content-button selected");
82
77
  return expect(element).toBeAccessible();
83
78
  });
@@ -105,9 +100,8 @@ describe(TAG, () => {
105
100
  });
106
101
 
107
102
  return Promise.resolve().then(() => {
108
- const optionListComponent: Array<HTMLElement> = element.shadowRoot.querySelectorAll(
109
- "a"
110
- );
103
+ const optionListComponent: Array<HTMLElement> =
104
+ element.shadowRoot.querySelectorAll("a");
111
105
  expect(optionListComponent).toHaveLength(element.options.length);
112
106
  return expect(element).toBeAccessible();
113
107
  });
@@ -9,6 +9,7 @@
9
9
  display: flex;
10
10
  flex-direction: row-reverse;
11
11
  width: var(--dx-c-toc-width);
12
+ word-break: break-word;
12
13
  }
13
14
 
14
15
  .toc_collapsed {
@@ -1,5 +1,5 @@
1
1
  import Tooltip from "dx/tooltip";
2
- import { createRenderComponent } from "utils/tests";
2
+ import { createRenderComponent } from "utils-internal/tests";
3
3
 
4
4
  const TAG = "dx-tooltip";
5
5
  const render = createRenderComponent(TAG, Tooltip);
@@ -8,9 +8,8 @@ describe(TAG, () => {
8
8
  it("calls tippy constructor with correct parameters", () => {
9
9
  const element = render({ label: "First Label", placement: "top" });
10
10
 
11
- const slotContainer: HTMLElement = element.shadowRoot.querySelector(
12
- "div"
13
- );
11
+ const slotContainer: HTMLElement =
12
+ element.shadowRoot.querySelector("div");
14
13
 
15
14
  expect(slotContainer).not.toBeNull();
16
15
  expect(slotContainer.getAttribute("data-microtip-position")).toEqual(
@@ -1,5 +1,5 @@
1
1
  import Topics from "dx/topics";
2
- import { createRenderComponent } from "utils/tests";
2
+ import { createRenderComponent } from "utils-internal/tests";
3
3
  import mockProps from "./mockProps";
4
4
 
5
5
  const TAG = "dx-topics";
@@ -1,6 +1,6 @@
1
1
  import Tree from "dx/tree";
2
2
  import TreeItem from "dx/treeItem";
3
- import { createRenderComponent } from "utils/tests";
3
+ import { createRenderComponent } from "utils-internal/tests";
4
4
  import { TreeHandler } from "../treeHandler";
5
5
  import {
6
6
  INITIALIZE_MOCK_PARAMETER,
@@ -6,7 +6,7 @@ import {
6
6
  import { track } from "dx/instrumentation";
7
7
  import TreeItem from "dx/treeItem";
8
8
  import TreeTile from "dx/treeTile";
9
- import { createRenderComponent } from "utils/tests";
9
+ import { createRenderComponent } from "utils-internal/tests";
10
10
 
11
11
  const TAG = "dx-tree-item";
12
12
  const renderComponent = createRenderComponent(TAG, TreeItem);
@@ -1,6 +1,6 @@
1
1
  import TreeTile from "dx/treeTile";
2
2
  import Icon from "dx/icon";
3
- import { createRenderComponent } from "utils/tests";
3
+ import { createRenderComponent } from "utils-internal/tests";
4
4
 
5
5
  import { SINGLE_NODE, SINGLE_NODE_WITH_METHOD } from "./mockProps";
6
6
 
@@ -1,5 +1,5 @@
1
1
  import TypeBadge from "dx/typeBadge";
2
- import { createRenderComponent } from "utils/tests";
2
+ import { createRenderComponent } from "utils-internal/tests";
3
3
  import { TypeBadgeSize, BadgeType } from "typings/custom";
4
4
 
5
5
  const TAG = "dx-type-badge";
@@ -7,7 +7,7 @@ import {
7
7
  BadgeType,
8
8
  Brand
9
9
  } from "typings/custom";
10
- import { colorToDxColors } from "utils/css";
10
+ import { colorToDxColors } from "utils-internal/css";
11
11
 
12
12
  const DEFAULT_TYPE = "typebadge_metadata";
13
13
  const VALID_BRANDS: Array<Brand> = [
@@ -1,7 +1,7 @@
1
1
  import TypeBadge from "dx/typeBadge";
2
2
  import TypeBadgeGroup from "dx/typeBadgeGroup";
3
3
  import { TypeBadgeSize } from "typings/custom";
4
- import { createRenderComponent } from "utils/tests";
4
+ import { createRenderComponent } from "utils-internal/tests";
5
5
  import mockProps, { badges } from "./mockProps";
6
6
 
7
7
  const TAG = "dx-type-badge-group";
@@ -12,9 +12,8 @@ describe(TAG, () => {
12
12
  const expectedSize: TypeBadgeSize = "medium";
13
13
  const element = render(mockProps);
14
14
 
15
- const els: Array<TypeBadge> = element.shadowRoot.querySelectorAll(
16
- "dx-type-badge"
17
- );
15
+ const els: Array<TypeBadge> =
16
+ element.shadowRoot.querySelectorAll("dx-type-badge");
18
17
  expect(els).toHaveLength(badges.length);
19
18
  els.forEach((el, index) => {
20
19
  expect(el.value).toBe(badges[index]);
@@ -31,9 +30,8 @@ describe(TAG, () => {
31
30
  size: expectedSize
32
31
  });
33
32
 
34
- const els: Array<TypeBadge> = element.shadowRoot.querySelectorAll(
35
- "dx-type-badge"
36
- );
33
+ const els: Array<TypeBadge> =
34
+ element.shadowRoot.querySelectorAll("dx-type-badge");
37
35
  expect(els).toHaveLength(3);
38
36
  els.forEach((el) => expect(el.size).toBe(expectedSize));
39
37
  expect(els[0].value).toBe("test1");
@@ -47,9 +45,8 @@ describe(TAG, () => {
47
45
  const expectedBadge = "testsinglebadge";
48
46
  const element = render({ badges: expectedBadge });
49
47
 
50
- const els: Array<TypeBadge> = element.shadowRoot.querySelectorAll(
51
- "dx-type-badge"
52
- );
48
+ const els: Array<TypeBadge> =
49
+ element.shadowRoot.querySelectorAll("dx-type-badge");
53
50
  expect(els).toHaveLength(1);
54
51
  expect(els[0].value).toBe(expectedBadge);
55
52
 
@@ -59,9 +56,8 @@ describe(TAG, () => {
59
56
  it("can render a regular array of string", () => {
60
57
  const element = render({ badges });
61
58
 
62
- const els: Array<TypeBadge> = element.shadowRoot.querySelectorAll(
63
- "dx-type-badge"
64
- );
59
+ const els: Array<TypeBadge> =
60
+ element.shadowRoot.querySelectorAll("dx-type-badge");
65
61
  expect(els).toHaveLength(badges.length);
66
62
  els.forEach((el, index) => expect(el.value).toBe(badges[index]));
67
63
 
@@ -10,99 +10,101 @@ describe("highlight utility", () => {
10
10
 
11
11
  it("highlights text that matches search criteria", () => {
12
12
  container.innerHTML = mockContent;
13
- highlightTerms(
14
- container.querySelectorAll(allowedTags.join(",")),
15
- "apex"
16
- );
13
+ highlightTerms(container.querySelectorAll(allowedTags.join(",")), {
14
+ query: "apex",
15
+ termsToHighlight: ["apex"]
16
+ });
17
17
  expect(container.querySelectorAll("mark")).toHaveLength(14);
18
18
  });
19
19
 
20
20
  it("doesn't highlight elements that contains dx/docs components", () => {
21
- const searchTerm = "customreport";
21
+ const query = "customreport";
22
22
  const codeBlock = createElement("dx-code-block", { is: CodeBlock });
23
23
  Object.assign(codeBlock, {
24
- codeBlock: searchTerm,
24
+ codeBlock: query,
25
25
  language: "text"
26
26
  });
27
27
  container.appendChild(document.createElement("p"));
28
28
  container.firstElementChild?.appendChild(codeBlock);
29
- highlightTerms(
30
- container.querySelectorAll(allowedTags.join(",")),
31
- searchTerm
32
- );
29
+ highlightTerms(container.querySelectorAll(allowedTags.join(",")), {
30
+ query,
31
+ termsToHighlight: [query]
32
+ });
33
33
  expect(container.querySelectorAll("mark")).toHaveLength(0);
34
- expect(codeBlock.shadowRoot.innerHTML).toMatch(searchTerm); // sanity check
34
+ expect(codeBlock.shadowRoot.innerHTML).toMatch(query); // sanity check
35
35
  });
36
36
 
37
37
  it("doesn't highlight terms separated by html tags", () => {
38
+ const query = "loadDatawithin";
38
39
  container.innerHTML = "<p>loadData<span>within</span></p>";
39
- highlightTerms(
40
- container.querySelectorAll(allowedTags.join(",")),
41
- "loadDatawithin"
42
- );
40
+ highlightTerms(container.querySelectorAll(allowedTags.join(",")), {
41
+ query,
42
+ termsToHighlight: [query]
43
+ });
43
44
  expect(container.querySelectorAll("mark")).toHaveLength(0);
44
45
  });
45
46
 
46
47
  it("escapes regex especial characters", () => {
48
+ const query = "apex.+";
47
49
  container.innerHTML = mockContent;
48
- highlightTerms(
49
- container.querySelectorAll(allowedTags.join(",")),
50
- "apex.+"
51
- );
50
+ highlightTerms(container.querySelectorAll(allowedTags.join(",")), {
51
+ query,
52
+ termsToHighlight: [query]
53
+ });
52
54
  expect(container.querySelectorAll("mark")).toHaveLength(0);
53
55
  });
54
56
 
55
57
  it("cleans previous search result before searching for a new term", () => {
56
- const firstSearch = "apex";
57
- const secondSearch = "salesforce";
58
+ const firstQuery = "apex";
59
+ const secondQuery = "salesforce";
58
60
 
59
61
  container.innerHTML = mockContent;
60
62
 
61
- highlightTerms(
62
- container.querySelectorAll(allowedTags.join(",")),
63
- firstSearch
64
- );
63
+ highlightTerms(container.querySelectorAll(allowedTags.join(",")), {
64
+ query: firstQuery,
65
+ termsToHighlight: [firstQuery]
66
+ });
65
67
  const firstMarks = container.querySelectorAll("mark");
66
68
  expect(firstMarks).toHaveLength(14);
67
69
  firstMarks.forEach(({ textContent }) =>
68
- expect(textContent?.toLowerCase()).toBe(firstSearch)
70
+ expect(textContent?.toLowerCase()).toBe(firstQuery)
69
71
  );
70
72
 
71
- highlightTerms(
72
- container.querySelectorAll(allowedTags.join(",")),
73
- secondSearch
74
- );
73
+ highlightTerms(container.querySelectorAll(allowedTags.join(",")), {
74
+ query: secondQuery,
75
+ termsToHighlight: [secondQuery]
76
+ });
75
77
  const secondMarks = container.querySelectorAll("mark");
76
78
  expect(secondMarks).toHaveLength(4);
77
79
  secondMarks.forEach(({ textContent }) =>
78
- expect(textContent?.toLowerCase()).toBe(secondSearch)
80
+ expect(textContent?.toLowerCase()).toBe(secondQuery)
79
81
  );
80
82
  });
81
83
 
82
84
  it("cleans all marks if the search term is empty string", () => {
83
- const firstSearch = "apex";
84
- const secondSearch = "";
85
+ const firstQuery = "apex";
86
+ const secondQuery = "";
85
87
 
86
88
  container.innerHTML = mockContent;
87
89
 
88
- highlightTerms(
89
- container.querySelectorAll(allowedTags.join(",")),
90
- firstSearch
91
- );
90
+ highlightTerms(container.querySelectorAll(allowedTags.join(",")), {
91
+ query: firstQuery,
92
+ termsToHighlight: [firstQuery]
93
+ });
92
94
  const firstMarks = container.querySelectorAll("mark");
93
95
  expect(firstMarks).toHaveLength(14);
94
96
  firstMarks.forEach(({ textContent }) =>
95
- expect(textContent?.toLowerCase()).toBe(firstSearch)
97
+ expect(textContent?.toLowerCase()).toBe(firstQuery)
96
98
  );
97
99
 
98
- highlightTerms(
99
- container.querySelectorAll(allowedTags.join(",")),
100
- secondSearch
101
- );
100
+ highlightTerms(container.querySelectorAll(allowedTags.join(",")), {
101
+ query: secondQuery,
102
+ termsToHighlight: [secondQuery]
103
+ });
102
104
  const secondMarks = container.querySelectorAll("mark");
103
105
  expect(secondMarks).toHaveLength(0);
104
106
  secondMarks.forEach(({ textContent }) =>
105
- expect(textContent?.toLowerCase()).toBe(secondSearch)
107
+ expect(textContent?.toLowerCase()).toBe(secondQuery)
106
108
  );
107
109
  });
108
110
  });
@@ -1,14 +1,16 @@
1
- import { createSearchRegExp } from "utils/regexps";
1
+ import { createSearchRegExp } from "utils-internal/regexps";
2
2
 
3
- const MARK_TAGS = /<\/?mark>/gi;
3
+ const MARK_TAGS = /<\/?mark[^>]*>/gi;
4
+
5
+ // mark tags dif color on ref page
4
6
 
5
7
  export const highlightTerms = (
6
8
  // eslint-disable-next-line no-undef
7
- elements: NodeListOf<Element>,
8
- searchTerm: string
9
+ elements: NodeListOf<HTMLElement>,
10
+ { query, termsToHighlight }: { query: string; termsToHighlight: string[] }
9
11
  ): void => {
10
- searchTerm = searchTerm.trim();
11
- const searchExp = createSearchRegExp(searchTerm);
12
+ const searchExp = createSearchRegExp(termsToHighlight);
13
+ let scrolled = false;
12
14
  elements.forEach((element) => {
13
15
  if (
14
16
  element?.innerHTML.includes("<dx-") ||
@@ -17,16 +19,27 @@ export const highlightTerms = (
17
19
  return;
18
20
  }
19
21
 
20
- let innerHtml = element.innerHTML.replace(
21
- // Remove previously added mark tags
22
- MARK_TAGS,
23
- ""
24
- );
25
-
26
- if (searchTerm) {
27
- innerHtml = innerHtml.replace(searchExp, "<mark>$&</mark>");
22
+ try {
23
+ if (element.innerHTML.match(MARK_TAGS)) {
24
+ // Remove previously added mark tags
25
+ element.innerHTML = element.innerHTML.replace(MARK_TAGS, "");
26
+ }
27
+ if (element.innerHTML.match(searchExp) && query) {
28
+ element.innerHTML = element.innerHTML.replace(
29
+ searchExp,
30
+ '<mark style="background-color:var(--dx-g-yellow-vibrant-90)">$&</mark>'
31
+ );
32
+ }
33
+ } catch (e) {
34
+ console.error(
35
+ `${element} could not be parsed by the highlight utility: ${e}`
36
+ );
28
37
  }
29
38
 
30
- element.innerHTML = innerHtml;
39
+ const mark = element.querySelector("mark");
40
+ if (mark && !scrolled) {
41
+ scrolled = true;
42
+ mark.scrollIntoView({ block: "nearest" });
43
+ }
31
44
  });
32
45
  };
File without changes
@@ -43,7 +43,6 @@ export abstract class HeaderBase extends LightningElement {
43
43
  @api bannerMarkup =
44
44
  '<span><a href="https://forms.gle/TdSyKFPHXoBx7seM9" target="blank">Share your feedback</a>about our new site.</span>';
45
45
 
46
-
47
46
  @api
48
47
  get navItems() {
49
48
  return this._navItems;
@@ -193,7 +192,7 @@ export abstract class HeaderBase extends LightningElement {
193
192
  private handleSignUpClick(e: PointerEvent) {
194
193
  track(e.currentTarget!, "custEv_signupStart", {
195
194
  ...ANALYTICS_INFO,
196
- clickUrl: this.signupLink,
195
+ clickUrl: this.signupLink
197
196
  });
198
197
  }
199
198