@salesforcedevs/dx-components 0.17.0 → 0.18.3

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 (43) hide show
  1. package/lwc.config.json +1 -0
  2. package/package.json +3 -3
  3. package/src/assets/svg/sidebar-loading.svg +34 -0
  4. package/src/modules/dx/header/__tests__/mockProps.ts +7 -1
  5. package/src/modules/dx/headerSearch/__tests__/headerSearch.test.ts +24 -39
  6. package/src/modules/dx/headerSearch/__tests__/mockProps.ts +2 -7
  7. package/src/modules/dx/headerSearch/headerSearch.ts +13 -19
  8. package/src/modules/dx/lazy/lazy.ts +0 -7
  9. package/src/modules/dx/sidebar/__tests__/mockSearchChangeEmptyEvent.ts +6 -0
  10. package/src/modules/dx/sidebar/__tests__/mockSearchChangeEvent.ts +527 -0
  11. package/src/modules/dx/sidebar/__tests__/sidebar.test.ts +210 -247
  12. package/src/modules/dx/sidebar/sidebar.css +68 -34
  13. package/src/modules/dx/sidebar/sidebar.html +58 -34
  14. package/src/modules/dx/sidebar/sidebar.stories.ts +50 -4
  15. package/src/modules/dx/sidebar/sidebar.ts +141 -73
  16. package/src/modules/dx/sidebarOld/__tests__/mockProps.ts +178 -0
  17. package/src/modules/dx/sidebarOld/__tests__/sidebarOld.test.ts +574 -0
  18. package/src/modules/dx/sidebarOld/sidebarOld.css +160 -0
  19. package/src/modules/dx/sidebarOld/sidebarOld.html +70 -0
  20. package/src/modules/dx/sidebarOld/sidebarOld.stories.ts +139 -0
  21. package/src/modules/dx/sidebarOld/sidebarOld.ts +187 -0
  22. package/src/modules/dx/sidebarSearch/__tests__/mockPreloadedState.ts +1678 -0
  23. package/src/modules/dx/sidebarSearch/__tests__/sidebarSearch.test.ts +113 -0
  24. package/src/modules/dx/sidebarSearch/sidebarSearch.css +3 -0
  25. package/src/modules/dx/sidebarSearch/sidebarSearch.html +26 -0
  26. package/src/modules/dx/sidebarSearch/sidebarSearch.ts +427 -0
  27. package/src/modules/dx/sidebarSearchResult/__tests__/sidebarSearchResult.test.ts +55 -0
  28. package/src/modules/dx/sidebarSearchResult/sidebarSearchResult.css +36 -0
  29. package/src/modules/dx/sidebarSearchResult/sidebarSearchResult.html +14 -0
  30. package/src/modules/dx/sidebarSearchResult/sidebarSearchResult.ts +56 -0
  31. package/src/modules/dx/treeTile/__tests__/treeTile.test.ts +27 -38
  32. package/src/modules/dx/treeTile/treeTile.css +3 -19
  33. package/src/modules/dx/treeTile/treeTile.html +4 -1
  34. package/src/modules/dx/treeTile/treeTile.ts +2 -2
  35. package/src/modules/helpers/sidebar/sidebar.css +21 -0
  36. package/src/modules/utils/coveo/coveo.ts +69 -0
  37. package/src/modules/utils/highlight/__tests__/highlight.test.ts +108 -0
  38. package/src/modules/utils/highlight/__tests__/mockProps.ts +45 -0
  39. package/src/modules/utils/highlight/highlight.ts +2 -1
  40. package/src/modules/utils/jest/jest.ts +35 -0
  41. package/src/modules/utils/recentSearches/__tests__/recentSearches.test.ts +79 -0
  42. package/src/modules/utils/recentSearches/recentSearches.ts +57 -0
  43. package/src/modules/utils/tests/tests.ts +18 -11
package/lwc.config.json CHANGED
@@ -60,6 +60,7 @@
60
60
  "dx/sectionSmall",
61
61
  "dx/select",
62
62
  "dx/sidebar",
63
+ "dx/sidebarOld",
63
64
  "dx/socials",
64
65
  "dx/toc",
65
66
  "dx/tree",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforcedevs/dx-components",
3
- "version": "0.17.0",
3
+ "version": "0.18.3",
4
4
  "description": "DX Lightning web components",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -14,7 +14,7 @@
14
14
  "access": "public"
15
15
  },
16
16
  "dependencies": {
17
- "@coveo/headless": "0.1.0-alpha.33",
17
+ "@coveo/headless": "^1.32.0",
18
18
  "@popperjs/core": "2.9.1",
19
19
  "@sfdocs-internal/wires": "^0.6.3",
20
20
  "classnames": "^2.2.6",
@@ -29,5 +29,5 @@
29
29
  "@types/debounce": "^1.2.0",
30
30
  "@types/lodash.get": "^4.4.6"
31
31
  },
32
- "gitHead": "b7a26c9e46cee9298b3ebc7cbea85930320b83a0"
32
+ "gitHead": "52ca593aa106591201218495916da5169e0e9470"
33
33
  }
@@ -0,0 +1,34 @@
1
+
2
+ <svg width="100%" height="374px" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
3
+ <g id="Scoped-Search" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
4
+ <g id="Docs-–-Search-Results-Loading" transform="translate(-52.000000, -240.000000)" fill="#DAD8D7">
5
+ <g id="Group-12" transform="translate(52.000000, 240.000000)">
6
+ <g id="Group-5">
7
+ <rect id="Rectangle" x="0" y="0" width="90%" height="10" rx="5"></rect>
8
+ <rect id="Rectangle" x="0" y="26" width="80%" height="10" rx="5"></rect>
9
+ <rect id="Rectangle" x="0" y="52" width="70%" height="10" rx="5"></rect>
10
+ </g>
11
+ <g id="Group-5" opacity="0.8" transform="translate(0.000000, 78.000000)">
12
+ <rect id="Rectangle" x="0" y="0" width="90%" height="10" rx="5"></rect>
13
+ <rect id="Rectangle" x="0" y="26" width="80%" height="10" rx="5"></rect>
14
+ <rect id="Rectangle" x="0" y="52" width="70%" height="10" rx="5"></rect>
15
+ </g>
16
+ <g id="Group-5" opacity="0.6" transform="translate(0.000000, 156.000000)">
17
+ <rect id="Rectangle" x="0" y="0" width="90%" height="10" rx="5"></rect>
18
+ <rect id="Rectangle" x="0" y="26" width="80%" height="10" rx="5"></rect>
19
+ <rect id="Rectangle" x="0" y="52" width="70%" height="10" rx="5"></rect>
20
+ </g>
21
+ <g id="Group-5" opacity="0.4" transform="translate(0.000000, 234.000000)">
22
+ <rect id="Rectangle" x="0" y="0" width="90%" height="10" rx="5"></rect>
23
+ <rect id="Rectangle" x="0" y="26" width="80%" height="10" rx="5"></rect>
24
+ <rect id="Rectangle" x="0" y="52" width="70%" height="10" rx="5"></rect>
25
+ </g>
26
+ <g id="Group-5" opacity="0.197206577" transform="translate(0.000000, 312.000000)">
27
+ <rect id="Rectangle" x="0" y="0" width="90%" height="10" rx="5"></rect>
28
+ <rect id="Rectangle" x="0" y="26" width="80%" height="10" rx="5"></rect>
29
+ <rect id="Rectangle" x="0" y="52" width="70%" height="10" rx="5"></rect>
30
+ </g>
31
+ </g>
32
+ </g>
33
+ </g>
34
+ </svg>
@@ -13,7 +13,13 @@ import {
13
13
  mockNavAnalytics
14
14
  } from "./mockNavs";
15
15
  import mockNavDevelopers from "./mockNavDevelopers";
16
- import { coveoConfig } from "../../headerSearch/__tests__/mockProps";
16
+
17
+ export const coveoConfig = {
18
+ coveoOrganizationId: "coveosalesforcetestakshatha",
19
+ coveoPublicAccessToken: "xx114e9d50-bc6b-40f1-b25b-fa5a06c7e168",
20
+ coveoSearchPipeline: "salesforcedevdoc",
21
+ coveoSearchHub: "salesforcedevdoc2"
22
+ };
17
23
 
18
24
  const versions = JSON.stringify([
19
25
  {
@@ -1,27 +1,23 @@
1
- import {
2
- HeadlessEngine,
3
- buildStandaloneSearchBox,
4
- searchAppReducers
5
- } from "@coveo/headless";
1
+ import { buildSearchEngine, buildStandaloneSearchBox } from "@coveo/headless";
6
2
  import Input from "dx/input";
7
3
  import Button from "dx/button";
8
4
  import Dropdown from "dx/dropdown";
9
5
  import HeaderSearch from "dx/headerSearch";
10
6
  import { PopoverRequestCloseType } from "typings/custom";
11
7
  import { createRenderComponent } from "utils/tests";
8
+ import { coveoHeaderConfig } from "utils/coveo";
12
9
  import { MOCK_SUGGESTIONS } from "./mockData";
13
- import mockProps, { coveoConfig } from "./mockProps";
10
+ import mockProps from "./mockProps";
14
11
 
15
12
  const COVEO_CONFIG = {
16
13
  configuration: {
17
- organizationId: coveoConfig.coveoOrganizationId,
18
- accessToken: coveoConfig.coveoPublicAccessToken,
14
+ organizationId: coveoHeaderConfig.coveoOrganizationId,
15
+ accessToken: coveoHeaderConfig.coveoPublicAccessToken,
19
16
  search: {
20
- pipeline: coveoConfig.coveoSearchPipeline,
21
- searchHub: coveoConfig.coveoSearchHub
17
+ pipeline: coveoHeaderConfig.coveoSearchPipeline,
18
+ searchHub: coveoHeaderConfig.coveoSearchHub
22
19
  }
23
- },
24
- reducers: searchAppReducers
20
+ }
25
21
  };
26
22
 
27
23
  const REDIRECT_URL = "https://developer.salesforce.com";
@@ -37,9 +33,8 @@ const mockUpdateText = jest.fn();
37
33
 
38
34
  jest.mock("@coveo/headless", () => {
39
35
  return {
40
- HeadlessEngine: jest.fn(),
41
- buildStandaloneSearchBox: jest.fn(),
42
- searchAppReducers: jest.fn()
36
+ buildSearchEngine: jest.fn(),
37
+ buildStandaloneSearchBox: jest.fn()
43
38
  };
44
39
  });
45
40
 
@@ -68,14 +63,11 @@ const expectMobileToDefaultRender = ({
68
63
  };
69
64
 
70
65
  const expectSearchToInit = () => {
71
- expect(HeadlessEngine).toHaveBeenCalledTimes(1);
72
- expect(HeadlessEngine).toHaveBeenCalledWith(COVEO_CONFIG);
66
+ expect(buildSearchEngine).toHaveBeenCalledTimes(1);
67
+ expect(buildSearchEngine).toHaveBeenCalledWith(COVEO_CONFIG);
73
68
  expect(buildStandaloneSearchBox).toHaveBeenCalledTimes(1);
74
- const [
75
- engine,
76
- options
77
- ] = (buildStandaloneSearchBox as jest.Mock).mock.calls[0];
78
- expect(engine).toBeInstanceOf(HeadlessEngine);
69
+ const options = (buildStandaloneSearchBox as jest.Mock).mock.calls[0][1];
70
+
79
71
  expect(options).toEqual({
80
72
  options: {
81
73
  numberOfSuggestions: 3,
@@ -85,8 +77,6 @@ const expectSearchToInit = () => {
85
77
  expect(mockSubscribe).toHaveBeenCalledTimes(1);
86
78
  expect(subscribeCallback).not.toBeNull();
87
79
  expect(subscribeCallback).toBeInstanceOf(Function);
88
- expect(mockUpdateText).toHaveBeenCalledTimes(1);
89
- expect(mockUpdateText).toHaveBeenCalledWith("");
90
80
  };
91
81
 
92
82
  describe(TAG, () => {
@@ -113,9 +103,8 @@ describe(TAG, () => {
113
103
  expect(container).not.toBeNull();
114
104
  expect(container.classList).toContain("desktop_search-container");
115
105
 
116
- const suggestionsDropdown: Dropdown = element.shadowRoot.querySelector(
117
- "dx-dropdown"
118
- );
106
+ const suggestionsDropdown: Dropdown =
107
+ element.shadowRoot.querySelector("dx-dropdown");
119
108
  expect(suggestionsDropdown.options).toHaveLength(0);
120
109
  expect(suggestionsDropdown.open).toBe(false);
121
110
 
@@ -132,21 +121,18 @@ describe(TAG, () => {
132
121
 
133
122
  it("renders as mobile view", () => {
134
123
  const element = render({ ...mockProps, mobile: true });
135
- const container: HTMLElement = element.shadowRoot.querySelector(
136
- "div"
137
- );
124
+ const container: HTMLElement =
125
+ element.shadowRoot.querySelector("div");
138
126
  expect(container).not.toBeNull();
139
127
  expect(container.classList).toHaveLength(0);
140
128
 
141
- const dropdowns: Dropdown[] = element.shadowRoot.querySelectorAll(
142
- "dx-dropdown"
143
- );
129
+ const dropdowns: Dropdown[] =
130
+ element.shadowRoot.querySelectorAll("dx-dropdown");
144
131
  expect(dropdowns).toHaveLength(1);
145
132
  const [dropdown] = dropdowns;
146
133
  const input: Input = element.shadowRoot.querySelector("dx-input");
147
- const button: Button = element.shadowRoot.querySelector(
148
- "dx-button"
149
- );
134
+ const button: Button =
135
+ element.shadowRoot.querySelector("dx-button");
150
136
  expectMobileToDefaultRender({
151
137
  input,
152
138
  dropdown,
@@ -165,9 +151,8 @@ describe(TAG, () => {
165
151
  const element = render({ ...mockProps, mobile: true });
166
152
 
167
153
  const input: Input = element.shadowRoot.querySelector("dx-input");
168
- const dropdown: Dropdown = element.shadowRoot.querySelector(
169
- "dx-dropdown"
170
- );
154
+ const dropdown: Dropdown =
155
+ element.shadowRoot.querySelector("dx-dropdown");
171
156
  const button = element.shadowRoot.querySelector("dx-button");
172
157
  button.click();
173
158
 
@@ -1,11 +1,6 @@
1
- export const coveoConfig = {
2
- coveoOrganizationId: "coveosalesforcetestakshatha",
3
- coveoPublicAccessToken: "xx8d9c92ef-1018-4d92-a3c7-647dff01c21c",
4
- coveoSearchPipeline: "salesforcedevdoc",
5
- coveoSearchHub: "salesforcedevdoc"
6
- };
1
+ import { coveoHeaderConfig } from "utils/coveo";
7
2
 
8
3
  export default {
9
4
  mobile: false,
10
- ...coveoConfig
5
+ ...coveoHeaderConfig
11
6
  };
@@ -1,13 +1,12 @@
1
1
  import { LightningElement, api } from "lwc";
2
2
  import cx from "classnames";
3
3
  import { PopoverRequestCloseType, Option } from "typings/custom";
4
+ import { buildSearchEngine } from "utils/coveo";
4
5
  import {
5
- HeadlessEngine,
6
6
  StandaloneSearchBox as StandaloneSearchBoxType,
7
- StandaloneSearchBoxOptions,
8
7
  StandaloneSearchBoxState,
9
8
  buildStandaloneSearchBox,
10
- searchAppReducers
9
+ StandaloneSearchBoxOptions
11
10
  } from "@coveo/headless";
12
11
 
13
12
  const baseSearchHref = `/search`;
@@ -32,11 +31,11 @@ export default class HeaderSearch extends LightningElement {
32
31
  private get suggestions(): Option[] {
33
32
  if (this.searchState) {
34
33
  return this.searchState.suggestions.map(
35
- ({ value }: { value: string }) => ({
36
- id: value,
37
- label: value,
34
+ ({ highlightedValue }: { highlightedValue: string }) => ({
35
+ id: highlightedValue,
36
+ label: highlightedValue,
38
37
  link: {
39
- href: this.createSearchHref(value),
38
+ href: this.createSearchHref(highlightedValue),
40
39
  target: null
41
40
  }
42
41
  })
@@ -83,25 +82,20 @@ export default class HeaderSearch extends LightningElement {
83
82
  redirectionUrl: "https://developer.salesforce.com"
84
83
  };
85
84
 
86
- const engine = new HeadlessEngine({
87
- configuration: {
88
- organizationId: this.coveoOrganizationId,
89
- accessToken: this.coveoPublicAccessToken,
90
- search: {
91
- pipeline: this.coveoSearchPipeline,
92
- searchHub: this.coveoSearchHub
93
- }
94
- },
95
- reducers: searchAppReducers
85
+ const engine = buildSearchEngine({
86
+ organizationId: this.coveoOrganizationId,
87
+ publicAccessToken: this.coveoPublicAccessToken,
88
+ searchPipeline: this.coveoSearchPipeline,
89
+ searchHub: this.coveoSearchHub
96
90
  });
97
91
 
98
92
  this.searchBox = buildStandaloneSearchBox(engine, { options });
99
- this.searchBox.subscribe(() => {
93
+
94
+ this.searchBox?.subscribe(() => {
100
95
  if (this.searchBox) {
101
96
  this.searchState = this.searchBox.state;
102
97
  }
103
98
  });
104
- this.searchBox.updateText("");
105
99
  }
106
100
 
107
101
  private createSearchHref = (value: string | null = "") => {
@@ -2,13 +2,6 @@ import { LightningElement, api } from "lwc";
2
2
 
3
3
  import { LazyMode } from "typings/custom";
4
4
 
5
- declare global {
6
- interface Window {
7
- requestIdleCallback: any;
8
- cancelIdleCallback: any;
9
- }
10
- }
11
-
12
5
  /**
13
6
  * Defines a fallback for BackgroundTasksAPI for browsers that doesn't support it.
14
7
  * Currently BackgroundTasksAPI is supported by all major browsers
@@ -0,0 +1,6 @@
1
+ export default {
2
+ detail: {
3
+ value: "pwa",
4
+ results: []
5
+ }
6
+ };