@momentum-design/components 0.122.5 → 0.122.7
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 +428 -409
- package/dist/browser/index.js.map +4 -4
- package/dist/components/list/list.component.d.ts +12 -17
- package/dist/components/list/list.component.js +29 -39
- package/dist/components/listitem/listitem.component.d.ts +10 -0
- package/dist/components/listitem/listitem.component.js +7 -0
- package/dist/components/popover/popover.component.d.ts +7 -0
- package/dist/components/popover/popover.component.js +13 -0
- package/dist/components/popover/popover.constants.d.ts +1 -0
- package/dist/components/popover/popover.constants.js +1 -0
- package/dist/components/virtualizedlist/virtualizedlist.component.d.ts +244 -41
- package/dist/components/virtualizedlist/virtualizedlist.component.js +597 -78
- package/dist/components/virtualizedlist/virtualizedlist.constants.d.ts +7 -4
- package/dist/components/virtualizedlist/virtualizedlist.constants.js +7 -4
- package/dist/components/virtualizedlist/virtualizedlist.styles.js +17 -3
- package/dist/components/virtualizedlist/virtualizedlist.types.d.ts +12 -10
- package/dist/components/virtualizedlist/virtualizedlist.utils.d.ts +11 -0
- package/dist/components/virtualizedlist/virtualizedlist.utils.js +23 -0
- package/dist/custom-elements.json +2778 -1975
- package/dist/react/index.d.ts +7 -7
- package/dist/react/index.js +7 -7
- package/dist/react/virtualizedlist/index.d.ts +44 -6
- package/dist/react/virtualizedlist/index.js +44 -6
- package/dist/utils/mixins/AutoFocusOnMountMixin.js +2 -2
- package/dist/utils/mixins/ListNavigationMixin.d.ts +5 -2
- package/dist/utils/mixins/ListNavigationMixin.js +77 -68
- package/dist/utils/mixins/lifecycle/LifeCycleMixin.js +4 -0
- package/dist/utils/mixins/lifecycle/lifecycle.contants.d.ts +1 -0
- package/dist/utils/mixins/lifecycle/lifecycle.contants.js +1 -0
- package/dist/utils/range.d.ts +40 -0
- package/dist/utils/range.js +66 -0
- package/dist/utils/virtualIndexArray.d.ts +27 -0
- package/dist/utils/virtualIndexArray.js +42 -0
- package/package.json +2 -2
- package/dist/components/virtualizedlist/virtualizedlist.helper.test.d.ts +0 -22
- package/dist/components/virtualizedlist/virtualizedlist.helper.test.js +0 -82
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A wrapper around an array that applies a "virtual" index to the index when accessing items.
|
|
3
|
+
* This is useful when the array is just a view of the real data and the real data has gaps in the indexes.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* const originalArray = [{realIndex: 2, value: 10}, {realIndex: 3, value: 20}];
|
|
8
|
+
* const offsetArray = new OffsetArray(originalArray, (item) => item.realIndex);
|
|
9
|
+
*
|
|
10
|
+
* console.log(offsetArray.at(0)); // Output: undefined
|
|
11
|
+
* console.log(offsetArray.at(2).value); // Output: 10
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
export class VirtualIndexArray {
|
|
15
|
+
constructor(items, getIndex, length) {
|
|
16
|
+
this.getIndex = () => 0;
|
|
17
|
+
this.items = items;
|
|
18
|
+
this.getIndex = getIndex;
|
|
19
|
+
this.lengthFn = length;
|
|
20
|
+
}
|
|
21
|
+
get length() {
|
|
22
|
+
return this.lengthFn();
|
|
23
|
+
}
|
|
24
|
+
at(index) {
|
|
25
|
+
return this.items.find(item => this.getIndex(item) === index);
|
|
26
|
+
}
|
|
27
|
+
map(cb, thisArg) {
|
|
28
|
+
return this.items.map((value, _index, array) => cb.call(thisArg, value, this.getIndex(value), array));
|
|
29
|
+
}
|
|
30
|
+
forEach(cb, thisArg) {
|
|
31
|
+
this.items.forEach((value, _index, array) => {
|
|
32
|
+
cb.call(thisArg, value, this.getIndex(value), array);
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
findIndex(predicate, thisArg) {
|
|
36
|
+
const item = this.items.find((value, _index, obj) => predicate.call(thisArg, value, this.getIndex(value), obj));
|
|
37
|
+
return !item ? -1 : this.getIndex(item);
|
|
38
|
+
}
|
|
39
|
+
find(predicate, thisArg) {
|
|
40
|
+
return this.items.find((value, _index, obj) => predicate.call(thisArg, value, this.getIndex(value), obj));
|
|
41
|
+
}
|
|
42
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@momentum-design/components",
|
|
3
3
|
"packageManager": "yarn@3.2.4",
|
|
4
|
-
"version": "0.122.
|
|
4
|
+
"version": "0.122.7",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=20.0.0",
|
|
7
7
|
"npm": ">=8.0.0"
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"@momentum-design/fonts": "*",
|
|
38
38
|
"@momentum-design/icons": "*",
|
|
39
39
|
"@momentum-design/tokens": "*",
|
|
40
|
-
"@tanstack/lit-virtual": "^3.
|
|
40
|
+
"@tanstack/lit-virtual": "^3.13.2",
|
|
41
41
|
"lit": "^3.2.0",
|
|
42
42
|
"lottie-web": "^5.12.2",
|
|
43
43
|
"uuid": "^11.0.5"
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { CSSResult, PropertyValues, TemplateResult } from 'lit';
|
|
2
|
-
import { Component } from '../../models';
|
|
3
|
-
import { VirtualizerProps } from './virtualizedlist.types';
|
|
4
|
-
declare class VirtualizedWrapper extends Component {
|
|
5
|
-
onscroll: ((this: GlobalEventHandlers, ev: Event) => void) | null;
|
|
6
|
-
virtualizerProps: VirtualizerProps;
|
|
7
|
-
list: TemplateResult<1>;
|
|
8
|
-
listItemTexts: string[];
|
|
9
|
-
constructor();
|
|
10
|
-
update(changedProperties: PropertyValues): void;
|
|
11
|
-
connectedCallback(): void;
|
|
12
|
-
private updateListItemTextArray;
|
|
13
|
-
private setListData;
|
|
14
|
-
render(): TemplateResult<1>;
|
|
15
|
-
static styles: Array<CSSResult>;
|
|
16
|
-
}
|
|
17
|
-
declare global {
|
|
18
|
-
interface HTMLElementTagNameMap {
|
|
19
|
-
['mdc-virtualizedwrapper']: VirtualizedWrapper;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
export {};
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
8
|
-
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
|
-
};
|
|
10
|
-
import { html } from 'lit';
|
|
11
|
-
import { property, state } from 'lit/decorators.js';
|
|
12
|
-
import { ref } from 'lit/directives/ref.js';
|
|
13
|
-
import { styleMap } from 'lit/directives/style-map.js';
|
|
14
|
-
import { Component } from '../../models';
|
|
15
|
-
class VirtualizedWrapper extends Component {
|
|
16
|
-
constructor() {
|
|
17
|
-
super();
|
|
18
|
-
this.virtualizerProps = { count: 100, estimateSize: () => 100, overscan: 60 };
|
|
19
|
-
this.list = html ``;
|
|
20
|
-
this.listItemTexts = new Array(this.virtualizerProps.count).fill(true).map((_, index) => `list item number ${index}`);
|
|
21
|
-
this.onscroll = null;
|
|
22
|
-
this.setListData = this.setListData.bind(this);
|
|
23
|
-
}
|
|
24
|
-
update(changedProperties) {
|
|
25
|
-
super.update(changedProperties);
|
|
26
|
-
if (changedProperties.get('virtualizerProps')) {
|
|
27
|
-
this.updateListItemTextArray();
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
connectedCallback() {
|
|
31
|
-
var _a;
|
|
32
|
-
super.connectedCallback();
|
|
33
|
-
if ((_a = this.virtualizerProps) === null || _a === void 0 ? void 0 : _a.count) {
|
|
34
|
-
this.updateListItemTextArray();
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
updateListItemTextArray() {
|
|
38
|
-
var _a;
|
|
39
|
-
this.listItemTexts = new Array((_a = this.virtualizerProps) === null || _a === void 0 ? void 0 : _a.count)
|
|
40
|
-
.fill(true)
|
|
41
|
-
.map((_, index) => `list item number ${index}`);
|
|
42
|
-
}
|
|
43
|
-
setListData({ virtualItems, measureElement, listStyle }) {
|
|
44
|
-
if (virtualItems) {
|
|
45
|
-
this.list = html `<ul style="margin: 0;${styleMap(listStyle)}">
|
|
46
|
-
${virtualItems.map((virtualItem) => html `<li role="listitem" key=${virtualItem.key} data-index=${virtualItem.index} ref=${ref(measureElement)}>
|
|
47
|
-
${this.listItemTexts[virtualItem.index]}
|
|
48
|
-
</li>`)}
|
|
49
|
-
</ul>`;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
render() {
|
|
53
|
-
return html `
|
|
54
|
-
<div style="height: 500px; width: 500px;">
|
|
55
|
-
<mdc-virtualizedlist
|
|
56
|
-
@scroll=${this.onscroll}
|
|
57
|
-
.virtualizerProps=${this.virtualizerProps}
|
|
58
|
-
.setlistdata=${this.setListData}
|
|
59
|
-
>${this.list}</mdc-virtualizedlist
|
|
60
|
-
>
|
|
61
|
-
</div>
|
|
62
|
-
`;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
VirtualizedWrapper.styles = Component.styles;
|
|
66
|
-
__decorate([
|
|
67
|
-
property({ type: Function, attribute: 'onscroll' }),
|
|
68
|
-
__metadata("design:type", Object)
|
|
69
|
-
], VirtualizedWrapper.prototype, "onscroll", void 0);
|
|
70
|
-
__decorate([
|
|
71
|
-
property({ type: Object, attribute: 'virtualizerprops' }),
|
|
72
|
-
__metadata("design:type", Object)
|
|
73
|
-
], VirtualizedWrapper.prototype, "virtualizerProps", void 0);
|
|
74
|
-
__decorate([
|
|
75
|
-
state(),
|
|
76
|
-
__metadata("design:type", Object)
|
|
77
|
-
], VirtualizedWrapper.prototype, "list", void 0);
|
|
78
|
-
__decorate([
|
|
79
|
-
state(),
|
|
80
|
-
__metadata("design:type", Object)
|
|
81
|
-
], VirtualizedWrapper.prototype, "listItemTexts", void 0);
|
|
82
|
-
VirtualizedWrapper.register('mdc-virtualizedwrapper');
|