@salesforcedevs/dx-components 0.44.1 → 0.45.0
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 +2 -2
- package/src/modules/base-elements/sidebarBase/sidebarBase.ts +65 -0
- package/src/modules/dx/sidebar/sidebar.html +1 -0
- package/src/modules/dx/sidebar/sidebar.ts +5 -2
- package/src/modules/dx/sidebarOld/sidebarOld.html +2 -1
- package/src/modules/dx/sidebarOld/sidebarOld.ts +8 -2
- package/src/modules/dx/treeItem/treeItem.ts +20 -0
- package/src/modules/utils/browser/browser.ts +17 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforcedevs/dx-components",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.45.0",
|
|
4
4
|
"description": "DX Lightning web components",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"engines": {
|
|
@@ -28,5 +28,5 @@
|
|
|
28
28
|
"@types/lodash.get": "^4.4.6",
|
|
29
29
|
"@types/vimeo__player": "^2.16.2"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "6e38daa55ef9ef7e43b71be5c08b5be1aab534b7"
|
|
32
32
|
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { LightningElement } from "lwc";
|
|
2
|
+
|
|
3
|
+
export const HEIGHT_OF_SIDEBAR_ITEM = 32;
|
|
4
|
+
export const WAIT_TIME_BEFORE_SCROLL_IN_MS = 500;
|
|
5
|
+
|
|
6
|
+
export class SidebarBase extends LightningElement {
|
|
7
|
+
_sidebarContent: HTMLElement | null = null;
|
|
8
|
+
|
|
9
|
+
selectedElement: HTMLElement | null = null;
|
|
10
|
+
timerId: ReturnType<typeof setTimeout> | null = null;
|
|
11
|
+
|
|
12
|
+
get sidebarContent() {
|
|
13
|
+
if (!this._sidebarContent) {
|
|
14
|
+
this._sidebarContent = this.template.querySelector(
|
|
15
|
+
".sidebar-content-tree"
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
return this._sidebarContent;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
renderedCallback(): void {
|
|
22
|
+
/**
|
|
23
|
+
* Implementing debouncing kind of logic here to scroll to selected element once tree rendering is done
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
if (this.timerId) {
|
|
27
|
+
clearTimeout(this.timerId);
|
|
28
|
+
}
|
|
29
|
+
this.timerId = setTimeout(
|
|
30
|
+
this.renderedCallbackWithTimeout,
|
|
31
|
+
WAIT_TIME_BEFORE_SCROLL_IN_MS
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
disconnectedCallback(): void {
|
|
36
|
+
if (this.timerId) {
|
|
37
|
+
clearTimeout(this.timerId);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
renderedCallbackWithTimeout = () => {
|
|
42
|
+
this.scrollToSelectedItem();
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
private onSelectedItemRendered = (event: CustomEvent) => {
|
|
46
|
+
event.stopPropagation();
|
|
47
|
+
this.selectedElement = event.detail.element;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/*Scroll to selected tree item */
|
|
51
|
+
private scrollToSelectedItem() {
|
|
52
|
+
if (this.selectedElement && this.sidebarContent) {
|
|
53
|
+
const scrollHeight: number =
|
|
54
|
+
this.selectedElement.getBoundingClientRect().bottom -
|
|
55
|
+
this.sidebarContent.getBoundingClientRect().bottom + // We need to remove parent bottom
|
|
56
|
+
HEIGHT_OF_SIDEBAR_ITEM * 3 + // add height of 3 more items so that user can see at least three more items after selected item
|
|
57
|
+
this.sidebarContent.offsetTop; // We need to add sidebar offsetTop value as scrollTo will consider it
|
|
58
|
+
this.sidebarContent.scrollTo({
|
|
59
|
+
top: scrollHeight,
|
|
60
|
+
behavior: "smooth"
|
|
61
|
+
});
|
|
62
|
+
this.selectedElement = null;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import cx from "classnames";
|
|
2
2
|
import { track as trackAnalytics } from "dx/instrumentation";
|
|
3
|
-
import {
|
|
3
|
+
import { api, track } from "lwc";
|
|
4
4
|
import {
|
|
5
5
|
TreeNode,
|
|
6
6
|
SidebarGtmAction,
|
|
@@ -9,11 +9,12 @@ import {
|
|
|
9
9
|
import { getSidebarSearchParams } from "utils/coveo";
|
|
10
10
|
import { toJson } from "utils/normalizers";
|
|
11
11
|
import SidebarSearch from "dx/sidebarSearch";
|
|
12
|
+
import { SidebarBase } from "base-elements/sidebarBase";
|
|
12
13
|
|
|
13
14
|
const MOBILE_SIZE_MATCH = "768px";
|
|
14
15
|
const TOGGLE_BUTTON_LABEL = "Toggle Sidebar";
|
|
15
16
|
|
|
16
|
-
export default class Sidebar extends
|
|
17
|
+
export default class Sidebar extends SidebarBase {
|
|
17
18
|
@api coveoOrganizationId!: string;
|
|
18
19
|
@api coveoPublicAccessToken!: string;
|
|
19
20
|
@api coveoSearchHub!: string;
|
|
@@ -144,6 +145,7 @@ export default class Sidebar extends LightningElement {
|
|
|
144
145
|
}
|
|
145
146
|
|
|
146
147
|
renderedCallback() {
|
|
148
|
+
super.renderedCallback()
|
|
147
149
|
this.initializeSearchScrollPosition();
|
|
148
150
|
}
|
|
149
151
|
|
|
@@ -158,6 +160,7 @@ export default class Sidebar extends LightningElement {
|
|
|
158
160
|
}
|
|
159
161
|
|
|
160
162
|
disconnectedCallback() {
|
|
163
|
+
super.disconnectedCallback()
|
|
161
164
|
this.matchMedia.removeEventListener("change", this.onMediaChange);
|
|
162
165
|
}
|
|
163
166
|
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
></dx-input>
|
|
50
50
|
</div>
|
|
51
51
|
</div>
|
|
52
|
-
<div class="sidebar-content" if:true={anyResultMatch}>
|
|
52
|
+
<div class="sidebar-content sidebar-content-tree" if:true={anyResultMatch}>
|
|
53
53
|
<dx-tree
|
|
54
54
|
for:each={filteredTrees}
|
|
55
55
|
for:item="tree"
|
|
@@ -57,6 +57,7 @@
|
|
|
57
57
|
tree-root={tree.tree}
|
|
58
58
|
onselect={onSelect}
|
|
59
59
|
value={value}
|
|
60
|
+
onselecteditemrendered={onSelectedItemRendered}
|
|
60
61
|
></dx-tree>
|
|
61
62
|
</div>
|
|
62
63
|
<dx-empty-state
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import cx from "classnames";
|
|
2
2
|
import { track } from "dx/instrumentation";
|
|
3
|
-
import {
|
|
3
|
+
import { api } from "lwc";
|
|
4
4
|
|
|
5
5
|
import { TreeNode, SidebarGtmAction } from "typings/custom";
|
|
6
6
|
import { toJson } from "utils/normalizers";
|
|
7
|
+
import { SidebarBase } from "base-elements/sidebarBase";
|
|
7
8
|
|
|
8
9
|
const WAIT_TIME = 500;
|
|
9
10
|
const MOBILE_SIZE_MATCH = "768px";
|
|
10
11
|
const TOGGLE_BUTTON_LABEL = "Toggle Sidebar";
|
|
11
12
|
|
|
12
|
-
export default class Sidebar extends
|
|
13
|
+
export default class Sidebar extends SidebarBase {
|
|
13
14
|
@api header: string = "";
|
|
14
15
|
|
|
15
16
|
@api
|
|
@@ -80,7 +81,12 @@ export default class Sidebar extends LightningElement {
|
|
|
80
81
|
this.matchMedia.addEventListener("change", this.onMediaChange);
|
|
81
82
|
}
|
|
82
83
|
|
|
84
|
+
renderedCallback() {
|
|
85
|
+
super.renderedCallback();
|
|
86
|
+
}
|
|
87
|
+
|
|
83
88
|
disconnectedCallback() {
|
|
89
|
+
super.disconnectedCallback()
|
|
84
90
|
this.matchMedia.removeEventListener("change", this.onMediaChange);
|
|
85
91
|
}
|
|
86
92
|
|
|
@@ -2,6 +2,7 @@ import { LightningElement, api } from "lwc";
|
|
|
2
2
|
import { InternalTreeNode } from "typings/custom";
|
|
3
3
|
import { track } from "dx/instrumentation";
|
|
4
4
|
import { SidebarGtmAction } from "typings/custom";
|
|
5
|
+
import { isInViewport } from "utils/browser";
|
|
5
6
|
|
|
6
7
|
const DEFAULT_TARGET = "_self";
|
|
7
8
|
|
|
@@ -61,6 +62,25 @@ export default class TreeItem extends LightningElement {
|
|
|
61
62
|
}
|
|
62
63
|
}
|
|
63
64
|
|
|
65
|
+
renderedCallback(): void {
|
|
66
|
+
this.sendEventToParentIfSelected();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
private sendEventToParentIfSelected(): void {
|
|
70
|
+
/**
|
|
71
|
+
* This is to send selected element reference to parent if it's not visible in the viewport
|
|
72
|
+
* Parent component will use the elements offsetTop scrollTo that element's position
|
|
73
|
+
*/
|
|
74
|
+
if (this.isSelected) {
|
|
75
|
+
const element = this.template.querySelector("dx-tree-tile");
|
|
76
|
+
if (element && !isInViewport(element)) {
|
|
77
|
+
this.fireEvent("selecteditemrendered", {
|
|
78
|
+
element
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
64
84
|
private onIconClick(event: CustomEvent): void {
|
|
65
85
|
const isSelectAction = false;
|
|
66
86
|
this.doExpand(isSelectAction);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns whether given element is in browser viewport or not
|
|
3
|
+
*/
|
|
4
|
+
function isInViewport(element: HTMLElement): boolean {
|
|
5
|
+
const rect = element?.getBoundingClientRect();
|
|
6
|
+
return (
|
|
7
|
+
rect &&
|
|
8
|
+
rect.top >= 0 &&
|
|
9
|
+
rect.left >= 0 &&
|
|
10
|
+
rect.bottom <=
|
|
11
|
+
(window.innerHeight || document.documentElement.clientHeight) &&
|
|
12
|
+
rect.right <=
|
|
13
|
+
(window.innerWidth || document.documentElement.clientWidth)
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export { isInViewport };
|