@momentum-design/components 0.28.5 → 0.28.6
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/dist/browser/index.js +18 -18
- package/dist/browser/index.js.map +3 -3
- package/dist/components/virtualizedlist/virtualizedlist.component.d.ts +13 -3
- package/dist/components/virtualizedlist/virtualizedlist.component.js +42 -24
- package/dist/components/virtualizedlist/virtualizedlist.helper.test.d.ts +2 -2
- package/dist/components/virtualizedlist/virtualizedlist.helper.test.js +7 -7
- package/dist/custom-elements.json +383 -467
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.js +1 -1
- package/package.json +1 -1
- package/dist/components/virtualizedlist/virtualizedlist.test.component.d.ts +0 -17
- package/dist/components/virtualizedlist/virtualizedlist.test.component.js +0 -79
@@ -1,5 +1,5 @@
|
|
1
1
|
import { CSSResult, PropertyValues, TemplateResult } from 'lit';
|
2
|
-
import { Virtualizer } from '@tanstack/virtual-core';
|
2
|
+
import { Virtualizer, VirtualItem } from '@tanstack/virtual-core';
|
3
3
|
import { Ref } from 'lit/directives/ref.js';
|
4
4
|
import { Component } from '../../models';
|
5
5
|
import { SetListDataProps, VirtualizerProps } from './virtualizedlist.types';
|
@@ -24,7 +24,7 @@ declare class VirtualizedList extends Component {
|
|
24
24
|
* handling logic related when the user scrolls to the top or bottom of a list.
|
25
25
|
* @default undefined
|
26
26
|
*/
|
27
|
-
onscroll: ((this: GlobalEventHandlers, ev: Event) =>
|
27
|
+
onscroll: ((this: GlobalEventHandlers, ev: Event) => void) | null;
|
28
28
|
/**
|
29
29
|
* Object that sets and updates the virtualizer with any relevant props.
|
30
30
|
* There are two required object props in order to get virtualization to work properly.
|
@@ -39,7 +39,7 @@ declare class VirtualizedList extends Component {
|
|
39
39
|
* [Tanstack Virtualizer API Docs](https://tanstack.com/virtual/latest/docs/api/virtualizer)
|
40
40
|
*
|
41
41
|
*/
|
42
|
-
|
42
|
+
virtualizerProps: VirtualizerProps;
|
43
43
|
/**
|
44
44
|
* Callback that gets envoked when updates to the virtualizer interally occur.
|
45
45
|
* This must be implemented in such a way that this function will trigger update to parent.
|
@@ -57,6 +57,7 @@ declare class VirtualizedList extends Component {
|
|
57
57
|
private virtualizerController;
|
58
58
|
scrollElementRef: Ref<HTMLDivElement>;
|
59
59
|
virtualizer: Virtualizer<Element, Element> | null;
|
60
|
+
virtualItems: Array<VirtualItem>;
|
60
61
|
constructor();
|
61
62
|
/**
|
62
63
|
* This override is necessary to update the virtualizer with relevant props
|
@@ -64,6 +65,15 @@ declare class VirtualizedList extends Component {
|
|
64
65
|
* this way ensures we don't initialize a new virtualizer upon very prop change.
|
65
66
|
*/
|
66
67
|
update(changedProperties: PropertyValues): void;
|
68
|
+
/**
|
69
|
+
* This is needed in order to ensure the initial render happens
|
70
|
+
*/
|
71
|
+
firstUpdated(changedProperties: PropertyValues): void;
|
72
|
+
/**
|
73
|
+
* @internal
|
74
|
+
* Update virtuailzer with the union of the two virtualizer options (current, passed in).
|
75
|
+
*/
|
76
|
+
private setVirtualizerOptions;
|
67
77
|
connectedCallback(): void;
|
68
78
|
/**
|
69
79
|
* @internal
|
@@ -45,8 +45,9 @@ class VirtualizedList extends Component {
|
|
45
45
|
* [Tanstack Virtualizer API Docs](https://tanstack.com/virtual/latest/docs/api/virtualizer)
|
46
46
|
*
|
47
47
|
*/
|
48
|
-
this.
|
48
|
+
this.virtualizerProps = DEFAULTS.VIRTUALIZER_PROPS;
|
49
49
|
this.scrollElementRef = createRef();
|
50
|
+
this.virtualItems = [];
|
50
51
|
this.virtualizerController = null;
|
51
52
|
this.virtualizer = null;
|
52
53
|
this.setlistdata = null;
|
@@ -58,22 +59,34 @@ class VirtualizedList extends Component {
|
|
58
59
|
* this way ensures we don't initialize a new virtualizer upon very prop change.
|
59
60
|
*/
|
60
61
|
update(changedProperties) {
|
61
|
-
var _a;
|
62
62
|
super.update(changedProperties);
|
63
|
-
|
64
|
-
|
65
|
-
if (changedProperties.get('virtualizerprops')) {
|
66
|
-
(_a = this.virtualizer) === null || _a === void 0 ? void 0 : _a.setOptions({ ...this.virtualizer.options, ...this.virtualizerprops });
|
67
|
-
this.requestUpdate();
|
63
|
+
if (changedProperties.get('virtualizerProps')) {
|
64
|
+
this.setVirtualizerOptions();
|
68
65
|
}
|
69
66
|
}
|
67
|
+
/**
|
68
|
+
* This is needed in order to ensure the initial render happens
|
69
|
+
*/
|
70
|
+
firstUpdated(changedProperties) {
|
71
|
+
super.firstUpdated(changedProperties);
|
72
|
+
this.setVirtualizerOptions();
|
73
|
+
}
|
74
|
+
/**
|
75
|
+
* @internal
|
76
|
+
* Update virtuailzer with the union of the two virtualizer options (current, passed in).
|
77
|
+
*/
|
78
|
+
setVirtualizerOptions() {
|
79
|
+
var _a;
|
80
|
+
(_a = this.virtualizer) === null || _a === void 0 ? void 0 : _a.setOptions({ ...this.virtualizer.options, ...this.virtualizerProps });
|
81
|
+
this.requestUpdate();
|
82
|
+
}
|
70
83
|
connectedCallback() {
|
71
84
|
var _a;
|
72
85
|
this.virtualizerController = new VirtualizerController(this, {
|
73
|
-
count: this.
|
74
|
-
estimateSize: (_a = this.
|
86
|
+
count: this.virtualizerProps.count,
|
87
|
+
estimateSize: (_a = this.virtualizerProps) === null || _a === void 0 ? void 0 : _a.estimateSize,
|
75
88
|
getScrollElement: () => this.scrollElementRef.value || null,
|
76
|
-
...this.
|
89
|
+
...this.virtualizerProps,
|
77
90
|
});
|
78
91
|
super.connectedCallback();
|
79
92
|
}
|
@@ -89,19 +102,24 @@ class VirtualizedList extends Component {
|
|
89
102
|
getVirtualizedListWrapper(virtualizerController) {
|
90
103
|
var _a, _b;
|
91
104
|
this.virtualizer = virtualizerController.getVirtualizer();
|
92
|
-
const { getVirtualItems, measureElement
|
93
|
-
const
|
94
|
-
//
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
+
const { getTotalSize, getVirtualItems, measureElement } = this.virtualizer;
|
106
|
+
const newVirtualItems = getVirtualItems();
|
107
|
+
// Only update client if there's a difference in virtual items
|
108
|
+
if (newVirtualItems !== this.virtualItems) {
|
109
|
+
this.virtualItems = newVirtualItems;
|
110
|
+
const virtualItems = getVirtualItems();
|
111
|
+
// this style is required to be rendered by the client side list in order to handle scrolling properly
|
112
|
+
const listStyle = {
|
113
|
+
position: 'absolute',
|
114
|
+
top: 0,
|
115
|
+
left: 0,
|
116
|
+
width: '100%',
|
117
|
+
transform: `translateY(${(_b = (_a = virtualItems[0]) === null || _a === void 0 ? void 0 : _a.start) !== null && _b !== void 0 ? _b : 0}px)`,
|
118
|
+
};
|
119
|
+
// pass back data to client for rendering
|
120
|
+
if (this.setlistdata) {
|
121
|
+
this.setlistdata({ virtualItems, measureElement, listStyle });
|
122
|
+
}
|
105
123
|
}
|
106
124
|
return html `<div
|
107
125
|
part="container"
|
@@ -129,7 +147,7 @@ __decorate([
|
|
129
147
|
__decorate([
|
130
148
|
property({ type: Object, attribute: 'virtualizerprops' }),
|
131
149
|
__metadata("design:type", Object)
|
132
|
-
], VirtualizedList.prototype, "
|
150
|
+
], VirtualizedList.prototype, "virtualizerProps", void 0);
|
133
151
|
__decorate([
|
134
152
|
property({ type: Function, attribute: 'setlistdata' }),
|
135
153
|
__metadata("design:type", Object)
|
@@ -2,8 +2,8 @@ import { CSSResult, PropertyValues, TemplateResult } from 'lit';
|
|
2
2
|
import { VirtualizerProps } from './virtualizedlist.types';
|
3
3
|
import { Component } from '../../models';
|
4
4
|
declare class VirtualizedWrapper extends Component {
|
5
|
-
onscroll: ((this: GlobalEventHandlers, ev: Event) =>
|
6
|
-
|
5
|
+
onscroll: ((this: GlobalEventHandlers, ev: Event) => void) | null;
|
6
|
+
virtualizerProps: VirtualizerProps;
|
7
7
|
list: TemplateResult<1>;
|
8
8
|
listItemTexts: string[];
|
9
9
|
constructor();
|
@@ -15,9 +15,9 @@ import { Component } from '../../models';
|
|
15
15
|
class VirtualizedWrapper extends Component {
|
16
16
|
constructor() {
|
17
17
|
super();
|
18
|
-
this.
|
18
|
+
this.virtualizerProps = { count: 100, estimateSize: () => 100, overscan: 60 };
|
19
19
|
this.list = html ``;
|
20
|
-
this.listItemTexts = new Array(this.
|
20
|
+
this.listItemTexts = new Array(this.virtualizerProps.count)
|
21
21
|
.fill(true)
|
22
22
|
.map((_, index) => `list item number ${index}`);
|
23
23
|
this.onscroll = null;
|
@@ -25,20 +25,20 @@ class VirtualizedWrapper extends Component {
|
|
25
25
|
}
|
26
26
|
update(changedProperties) {
|
27
27
|
super.update(changedProperties);
|
28
|
-
if (changedProperties.get('
|
28
|
+
if (changedProperties.get('virtualizerProps')) {
|
29
29
|
this.updateListItemTextArray();
|
30
30
|
}
|
31
31
|
}
|
32
32
|
connectedCallback() {
|
33
33
|
var _a;
|
34
34
|
super.connectedCallback();
|
35
|
-
if ((_a = this.
|
35
|
+
if ((_a = this.virtualizerProps) === null || _a === void 0 ? void 0 : _a.count) {
|
36
36
|
this.updateListItemTextArray();
|
37
37
|
}
|
38
38
|
}
|
39
39
|
updateListItemTextArray() {
|
40
40
|
var _a;
|
41
|
-
this.listItemTexts = new Array((_a = this.
|
41
|
+
this.listItemTexts = new Array((_a = this.virtualizerProps) === null || _a === void 0 ? void 0 : _a.count)
|
42
42
|
.fill(true)
|
43
43
|
.map((_, index) => `list item number ${index}`);
|
44
44
|
}
|
@@ -53,7 +53,7 @@ class VirtualizedWrapper extends Component {
|
|
53
53
|
<div style="height: 500px; width: 500px;">
|
54
54
|
<mdc-virtualizedlist
|
55
55
|
.onscroll=${this.onscroll}
|
56
|
-
.
|
56
|
+
.virtualizerProps=${this.virtualizerProps}
|
57
57
|
.setlistdata=${this.setListData}
|
58
58
|
>${this.list}</mdc-virtualizedlist></div>
|
59
59
|
`;
|
@@ -67,7 +67,7 @@ __decorate([
|
|
67
67
|
__decorate([
|
68
68
|
property({ type: Object, attribute: 'virtualizerprops' }),
|
69
69
|
__metadata("design:type", Object)
|
70
|
-
], VirtualizedWrapper.prototype, "
|
70
|
+
], VirtualizedWrapper.prototype, "virtualizerProps", void 0);
|
71
71
|
__decorate([
|
72
72
|
state(),
|
73
73
|
__metadata("design:type", Object)
|