@cas-smartdesign/virtual-list 7.0.1 → 7.1.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/dist/virtual-list.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { LitElement as p, unsafeCSS as b, css as _, html as x } from "lit";
|
|
2
|
-
import { property as
|
|
2
|
+
import { property as l } from "lit/decorators/property.js";
|
|
3
3
|
import f, { generator as g } from "@cas-smartdesign/list-item";
|
|
4
4
|
class C {
|
|
5
|
-
getOffsetForIndexAndAlignment(
|
|
6
|
-
const m = Math.max(0,
|
|
7
|
-
switch (
|
|
5
|
+
getOffsetForIndexAndAlignment(t, e, i, n, s, r) {
|
|
6
|
+
const m = Math.max(0, r * n), u = Math.min(m, t * n), c = Math.max(0, t * n - s + n);
|
|
7
|
+
switch (e) {
|
|
8
8
|
case "start":
|
|
9
9
|
return u;
|
|
10
10
|
case "end":
|
|
@@ -19,22 +19,22 @@ class C {
|
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
21
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
22
|
-
debounce(
|
|
23
|
-
let
|
|
22
|
+
debounce(t) {
|
|
23
|
+
let e;
|
|
24
24
|
return (...i) => {
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
e && window.cancelAnimationFrame(e), e = window.requestAnimationFrame(() => {
|
|
26
|
+
t(...i), e = null;
|
|
27
27
|
});
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
const w = new C();
|
|
32
32
|
class T {
|
|
33
|
-
constructor(
|
|
34
|
-
this.pageSize =
|
|
33
|
+
constructor(t = 100, e = 5) {
|
|
34
|
+
this.pageSize = t, this.preloadedItemsCount = e, this._finalSizeIsKnown = !1, this._itemCache = [], this._lastRequestedFirstIndex = 0, this._lastRequestedLastIndex = 0, this._lastLoadedIndex = 0, this.handleListDataRequest = (i) => {
|
|
35
35
|
const { startIndex: n, stopIndex: s } = i.detail;
|
|
36
36
|
this._lastRequestedFirstIndex = n, this._lastRequestedLastIndex = s, this._list.items = this._itemCache.slice(n, s + 1), !this.finalSizeIsKnown && this._lastLoadedIndex < s + this.preloadedItemsCount && this.requestData();
|
|
37
|
-
}, this.itemCount =
|
|
37
|
+
}, this.itemCount = t;
|
|
38
38
|
}
|
|
39
39
|
get currentPage() {
|
|
40
40
|
return this.items.length == 0 && this.finalSizeIsKnown ? 0 : Math.floor((this.items.length - 1) / this.pageSize);
|
|
@@ -42,26 +42,26 @@ class T {
|
|
|
42
42
|
get finalSizeIsKnown() {
|
|
43
43
|
return this._finalSizeIsKnown;
|
|
44
44
|
}
|
|
45
|
-
set finalSizeIsKnown(
|
|
46
|
-
this._finalSizeIsKnown =
|
|
45
|
+
set finalSizeIsKnown(t) {
|
|
46
|
+
this._finalSizeIsKnown = t, t && (this.itemCount = this._itemCache.length), this._list && (this._list.finalSizeIsKnown = t);
|
|
47
47
|
}
|
|
48
48
|
get itemCount() {
|
|
49
49
|
return this._itemCount;
|
|
50
50
|
}
|
|
51
|
-
set itemCount(
|
|
52
|
-
this._itemCount =
|
|
51
|
+
set itemCount(t) {
|
|
52
|
+
this._itemCount = t, this._list && (this._list.itemCount = t);
|
|
53
53
|
}
|
|
54
54
|
get items() {
|
|
55
55
|
return this._itemCache;
|
|
56
56
|
}
|
|
57
|
-
set items(
|
|
58
|
-
this._itemCache =
|
|
57
|
+
set items(t) {
|
|
58
|
+
this._itemCache = t, this.onItemsChange();
|
|
59
59
|
}
|
|
60
|
-
addItems(
|
|
61
|
-
this._itemCache = this._itemCache.concat(
|
|
60
|
+
addItems(t) {
|
|
61
|
+
this._itemCache = this._itemCache.concat(t), this.onItemsChange();
|
|
62
62
|
}
|
|
63
|
-
connectList(
|
|
64
|
-
this._list && this._list.removeEventListener("data-request", this.handleListDataRequest), this._list =
|
|
63
|
+
connectList(t) {
|
|
64
|
+
this._list && this._list.removeEventListener("data-request", this.handleListDataRequest), this._list = t, t.itemCount = this.itemCount, t.addEventListener("data-request", this.handleListDataRequest), t.finalSizeIsKnown = this._finalSizeIsKnown;
|
|
65
65
|
}
|
|
66
66
|
onItemsChange() {
|
|
67
67
|
this._pendingDataRequest = !1, this._lastLoadedIndex = this._itemCache.length - 1, this.finalSizeIsKnown ? this.itemCount = this._itemCache.length : this._lastLoadedIndex > this.itemCount && (this.itemCount = this._lastLoadedIndex), this._list && (this._list.items = this._itemCache.slice(this._lastRequestedFirstIndex, this._lastRequestedLastIndex + 1));
|
|
@@ -76,23 +76,23 @@ class T {
|
|
|
76
76
|
);
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
|
-
const
|
|
80
|
-
var
|
|
81
|
-
for (var n = i > 1 ? void 0 : i ? A(
|
|
82
|
-
(
|
|
83
|
-
return i && n &&
|
|
79
|
+
const v = ":host{display:block;position:relative;contain:layout;--sd-virtual-list-focus-highlight-color: #1467ba;--sd-virtual-list-item-separator-color: #d9d9d9}:host(:focus){outline:none}:host(:focus-visible) ::slotted([focused]){box-shadow:0 0 0 1px var(--sd-virtual-list-focus-highlight-color) inset}.container{width:100%}.container>::slotted(*){width:100%;position:absolute;box-sizing:border-box}.container>::slotted(:not([last])){border-bottom:1px solid var(--sd-virtual-list-item-separator-color)}";
|
|
80
|
+
var S = Object.defineProperty, A = Object.getOwnPropertyDescriptor, d = (h, t, e, i) => {
|
|
81
|
+
for (var n = i > 1 ? void 0 : i ? A(t, e) : t, s = h.length - 1, r; s >= 0; s--)
|
|
82
|
+
(r = h[s]) && (n = (i ? r(t, e, n) : r(n)) || n);
|
|
83
|
+
return i && n && S(t, e, n), n;
|
|
84
84
|
}, y = /* @__PURE__ */ ((h) => (h.TriggerOnly = "trigger-only", h.Single = "single", h.Multi = "multi", h))(y || {});
|
|
85
85
|
let L = 0;
|
|
86
|
-
var
|
|
87
|
-
const o = (
|
|
86
|
+
var a;
|
|
87
|
+
const o = (a = class extends p {
|
|
88
88
|
constructor() {
|
|
89
|
-
super(), this.items = [], this.selectionType = "trigger-only", this.id =
|
|
89
|
+
super(), this.items = [], this.selectionType = "trigger-only", this.id = a.ID + "_" + L++, this.role = "listbox", this.itemGenerator = g, this._lastKnownScrollTop = 0, this._lastRenderedScrollTop = 0, this._itemsRenderData = [], this._elementCache = /* @__PURE__ */ new Map(), this._visibleItemsNum = 0, this._selectedIndices = [], this._focusIndex = -1, this._lastKnownHeight = 0, this.onScroll = () => {
|
|
90
90
|
this._lastKnownScrollTop = this.scrollTop;
|
|
91
|
-
const
|
|
92
|
-
Math.abs(
|
|
93
|
-
}, this.handleKeyDown = (
|
|
94
|
-
let
|
|
95
|
-
switch (
|
|
91
|
+
const t = this._lastRenderedScrollTop - this._lastKnownScrollTop;
|
|
92
|
+
Math.abs(t) >= this.itemHeight && (this._lastRenderedScrollTop = this._lastKnownScrollTop, this.requestUpdate());
|
|
93
|
+
}, this.handleKeyDown = (t) => {
|
|
94
|
+
let e = !0;
|
|
95
|
+
switch (t.key) {
|
|
96
96
|
case "Down":
|
|
97
97
|
case "ArrowDown":
|
|
98
98
|
this.focusIndex = (this.focusIndex + 1) % this.itemCount;
|
|
@@ -102,7 +102,7 @@ const o = (r = class extends p {
|
|
|
102
102
|
this.focusIndex > 0 ? this.focusIndex-- : this.finalSizeIsKnown && (this.focusIndex = this.itemCount - 1);
|
|
103
103
|
break;
|
|
104
104
|
case "Enter":
|
|
105
|
-
this.handleSelection(this.focusIndex,
|
|
105
|
+
this.handleSelection(this.focusIndex, t);
|
|
106
106
|
break;
|
|
107
107
|
case "End":
|
|
108
108
|
this.focusIndex = this.itemCount - 1;
|
|
@@ -117,10 +117,10 @@ const o = (r = class extends p {
|
|
|
117
117
|
this.focusIndex = this.normalizeIndex(this.focusIndex - this._visibleItemsNum + 1);
|
|
118
118
|
break;
|
|
119
119
|
default:
|
|
120
|
-
|
|
120
|
+
e = !1;
|
|
121
121
|
break;
|
|
122
122
|
}
|
|
123
|
-
|
|
123
|
+
e && (t.preventDefault(), t.stopPropagation());
|
|
124
124
|
}, this._resizeObserver = new ResizeObserver(() => {
|
|
125
125
|
this._lastKnownHeight !== this.offsetHeight && (this._lastKnownHeight = this.offsetHeight, this.requestUpdate());
|
|
126
126
|
});
|
|
@@ -128,36 +128,36 @@ const o = (r = class extends p {
|
|
|
128
128
|
get focusTarget() {
|
|
129
129
|
return this.hasAttribute("focus-target");
|
|
130
130
|
}
|
|
131
|
-
set focusTarget(
|
|
132
|
-
this.toggleAttribute("focus-target",
|
|
131
|
+
set focusTarget(t) {
|
|
132
|
+
this.toggleAttribute("focus-target", t);
|
|
133
133
|
}
|
|
134
134
|
get focusIndex() {
|
|
135
135
|
return this._focusIndex;
|
|
136
136
|
}
|
|
137
|
-
set focusIndex(
|
|
138
|
-
if (
|
|
139
|
-
const
|
|
140
|
-
this._focusIndex =
|
|
137
|
+
set focusIndex(t) {
|
|
138
|
+
if (t >= -1 && t < this.itemCount) {
|
|
139
|
+
const e = this._focusIndex;
|
|
140
|
+
this._focusIndex = t, (t <= this._firstVisibleIndex || this._lastVisibleIndex <= t) && this.scrollToItem(t), e != t && (t == -1 && this.removeAttribute("aria-activedescendant"), this.requestUpdate("focusIndex", e));
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
143
|
get selectedIndices() {
|
|
144
144
|
return this._selectedIndices;
|
|
145
145
|
}
|
|
146
|
-
set selectedIndices(
|
|
147
|
-
|
|
146
|
+
set selectedIndices(t) {
|
|
147
|
+
t ? this._selectedIndices = t.map((e) => Number(e)) : this._selectedIndices = [], this.requestUpdate("selectedIndices");
|
|
148
148
|
}
|
|
149
|
-
scrollToItem(
|
|
149
|
+
scrollToItem(t, e = "auto") {
|
|
150
150
|
this.scrollTop = w.getOffsetForIndexAndAlignment(
|
|
151
|
-
this.normalizeIndex(
|
|
152
|
-
|
|
151
|
+
this.normalizeIndex(t),
|
|
152
|
+
e,
|
|
153
153
|
this.scrollTop,
|
|
154
154
|
this.itemHeight,
|
|
155
155
|
this.height,
|
|
156
156
|
this.itemCount
|
|
157
157
|
), this._lastKnownScrollTop = this.scrollTop;
|
|
158
158
|
}
|
|
159
|
-
getListItem(
|
|
160
|
-
return !this.shadowRoot ||
|
|
159
|
+
getListItem(t) {
|
|
160
|
+
return !this.shadowRoot || t < this._firstVisibleIndex || this._lastVisibleIndex < t ? null : this.querySelector(`[item-index="${t}"]`);
|
|
161
161
|
}
|
|
162
162
|
connectedCallback() {
|
|
163
163
|
super.connectedCallback(), this._resizeObserver.observe(this), this.scrollTop !== this._lastKnownScrollTop && (this.scrollTop = this._lastKnownScrollTop, this.requestUpdate());
|
|
@@ -165,9 +165,9 @@ const o = (r = class extends p {
|
|
|
165
165
|
disconnectedCallback() {
|
|
166
166
|
super.disconnectedCallback(), this._resizeObserver.disconnect();
|
|
167
167
|
}
|
|
168
|
-
firstUpdated(
|
|
169
|
-
super.firstUpdated(
|
|
170
|
-
|
|
168
|
+
firstUpdated(t) {
|
|
169
|
+
super.firstUpdated(t), this.addEventListener("scroll", this.onScroll), this.addEventListener("keydown", this.handleKeyDown), this.addEventListener("click", this.handleClick), this.addEventListener("mousedown", (e) => {
|
|
170
|
+
e.button == 1 && e.preventDefault();
|
|
171
171
|
}), this.addEventListener("auxclick", this.handleClick), this.addEventListener("focus", () => {
|
|
172
172
|
this.matches(":focus-visible") && (this.focusIndex == -1 ? (this.selectedIndices && (this.focusIndex = this.selectedIndices[0]), this.focusIndex == -1 && this.itemCount > 0 && (this.focusIndex = 0)) : this.updateFocusedItemAttributes());
|
|
173
173
|
}), this.addEventListener("blur", () => {
|
|
@@ -175,13 +175,13 @@ const o = (r = class extends p {
|
|
|
175
175
|
}), this.selectedIndices.length > 0 && this.scrollToItem(this.selectedIndices[0], "center");
|
|
176
176
|
}
|
|
177
177
|
updateFocusedItemAttributes() {
|
|
178
|
-
const
|
|
179
|
-
|
|
178
|
+
const t = this.getListItem(this.focusIndex);
|
|
179
|
+
t && (this.focusTarget || document.activeElement == this ? (t.setAttribute("focused", ""), this.setAttribute("aria-activedescendant", t.id)) : (t.removeAttribute("focused"), this.removeAttribute("aria-activedescendant")));
|
|
180
180
|
}
|
|
181
181
|
static get styles() {
|
|
182
182
|
return [
|
|
183
183
|
_`
|
|
184
|
-
${b(
|
|
184
|
+
${b(v)}
|
|
185
185
|
`
|
|
186
186
|
];
|
|
187
187
|
}
|
|
@@ -192,39 +192,39 @@ const o = (r = class extends p {
|
|
|
192
192
|
</div>
|
|
193
193
|
`;
|
|
194
194
|
}
|
|
195
|
-
updated(
|
|
196
|
-
if (super.updated(
|
|
195
|
+
updated(t) {
|
|
196
|
+
if (super.updated(t), this._lastRenderedScrollTop = this._lastKnownScrollTop, this.updateItems(), (this._increaseWidthOnNextRenderIfNeeded || this._reachedMaxWidth) && //
|
|
197
197
|
this._firstVisibleIndex < this._lastVisibleIndex)
|
|
198
198
|
if (this.querySelector("[item-index]"))
|
|
199
199
|
this.adjustWidthIfNeeded();
|
|
200
200
|
else {
|
|
201
|
-
const
|
|
202
|
-
this.adjustWidthIfNeeded(),
|
|
201
|
+
const e = new MutationObserver(() => {
|
|
202
|
+
this.adjustWidthIfNeeded(), e.disconnect();
|
|
203
203
|
});
|
|
204
|
-
|
|
204
|
+
e.observe(this);
|
|
205
205
|
}
|
|
206
206
|
}
|
|
207
207
|
adjustWidthIfNeeded() {
|
|
208
208
|
this._increaseWidthOnNextRenderIfNeeded ? (this._increaseWidthOnNextRenderIfNeeded = !1, window.requestAnimationFrame(() => {
|
|
209
|
-
const
|
|
210
|
-
if (
|
|
209
|
+
const t = Number.parseInt(getComputedStyle(this).maxWidth) - this.offsetWidth;
|
|
210
|
+
if (t == 0)
|
|
211
211
|
this._reachedMaxWidth = !0, this.enableLineClampOnItemsIfNeeded();
|
|
212
212
|
else {
|
|
213
213
|
this._reachedMaxWidth = !1;
|
|
214
|
-
const
|
|
214
|
+
const e = [...this.querySelectorAll("[item-index]")].map((n) => {
|
|
215
215
|
if (n instanceof f) {
|
|
216
216
|
n.enableLineClamp = !1;
|
|
217
217
|
const s = n.missingWidthForTexts;
|
|
218
|
-
return s >
|
|
218
|
+
return s > t && (n.enableLineClamp = !0), s;
|
|
219
219
|
}
|
|
220
|
-
}), i = Math.max(...
|
|
220
|
+
}), i = Math.max(...e);
|
|
221
221
|
i > 0 && (this.style.width = `${this.offsetWidth + i}px`);
|
|
222
222
|
}
|
|
223
223
|
})) : this._reachedMaxWidth && this.enableLineClampOnItemsIfNeeded();
|
|
224
224
|
}
|
|
225
225
|
enableLineClampOnItemsIfNeeded() {
|
|
226
|
-
this.querySelectorAll("[item-index]").forEach((
|
|
227
|
-
|
|
226
|
+
this.querySelectorAll("[item-index]").forEach((t) => {
|
|
227
|
+
t instanceof f && (t.enableLineClamp = t.enableLineClamp || t.missingWidthForTexts > 0);
|
|
228
228
|
});
|
|
229
229
|
}
|
|
230
230
|
/**
|
|
@@ -237,122 +237,122 @@ const o = (r = class extends p {
|
|
|
237
237
|
this._increaseWidthOnNextRenderIfNeeded = !0;
|
|
238
238
|
}
|
|
239
239
|
updateItems() {
|
|
240
|
-
const
|
|
240
|
+
const t = [...this.querySelectorAll("[item-index]")], e = /* @__PURE__ */ new Map(), i = document.createDocumentFragment();
|
|
241
241
|
for (const n of this._itemsRenderData) {
|
|
242
242
|
const s = this.renderItem(n);
|
|
243
|
-
s.parentElement || i.appendChild(s),
|
|
244
|
-
const
|
|
245
|
-
|
|
243
|
+
s.parentElement || i.appendChild(s), e.set(n.dataHash, s);
|
|
244
|
+
const r = t.indexOf(s);
|
|
245
|
+
r !== -1 && t.splice(r, 1);
|
|
246
246
|
}
|
|
247
247
|
this.appendChild(i);
|
|
248
|
-
for (const n of
|
|
248
|
+
for (const n of t)
|
|
249
249
|
n instanceof f && (n.enableLineClamp = !1), this.removeChild(n);
|
|
250
|
-
|
|
250
|
+
e.forEach((n, s) => {
|
|
251
251
|
this._elementCache.set(s, n);
|
|
252
252
|
});
|
|
253
253
|
}
|
|
254
|
-
renderItem({ index:
|
|
254
|
+
renderItem({ index: t, top: e, dataHash: i, data: n }) {
|
|
255
255
|
let s;
|
|
256
|
-
return n ? this._elementCache.has(i) ? (s = this._elementCache.get(i), this._elementCache.delete(i)) : (s = this.itemGenerator(n,
|
|
257
|
-
transform: `translateY(${
|
|
256
|
+
return n ? this._elementCache.has(i) ? (s = this._elementCache.get(i), this._elementCache.delete(i)) : (s = this.itemGenerator(n, t), s.setAttribute("slot", "items")) : (s = document.createElement("div"), s.setAttribute("placeholder-item", ""), s.setAttribute("slot", "items")), Object.assign(s.style, {
|
|
257
|
+
transform: `translateY(${e}px)`,
|
|
258
258
|
height: `${this.itemHeight}px`
|
|
259
|
-
}), s.setAttribute("item-index",
|
|
259
|
+
}), s.setAttribute("item-index", t.toString()), s.setAttribute("aria-setsize", String(this.finalSizeIsKnown ? this.itemCount : -1)), s.setAttribute("aria-posinset", String(t + 1)), (!s.id || s.id.startsWith(this.id + "_item_")) && (s.id = this.id + "_item_" + t), this.itemCount - 1 == t ? s.setAttribute("last", "") : s.removeAttribute("last"), this.updateSelectedAttribute(t, s), this.updateFocusedAttribute(t, s), s;
|
|
260
260
|
}
|
|
261
|
-
updateFocusedAttribute(
|
|
262
|
-
this.focusIndex ==
|
|
261
|
+
updateFocusedAttribute(t, e) {
|
|
262
|
+
this.focusIndex == t && (this.focusTarget || document.activeElement == this) ? (e.setAttribute("focused", ""), this.setAttribute("aria-activedescendant", e.id)) : e.removeAttribute("focused");
|
|
263
263
|
}
|
|
264
|
-
updateSelectedAttribute(
|
|
265
|
-
const i = this.selectedIndices.indexOf(
|
|
266
|
-
i ?
|
|
264
|
+
updateSelectedAttribute(t, e) {
|
|
265
|
+
const i = this.selectedIndices.indexOf(t) !== -1;
|
|
266
|
+
i ? e.setAttribute("selected", "") : e.removeAttribute("selected"), e.setAttribute("aria-selected", String(i));
|
|
267
267
|
}
|
|
268
268
|
updateItemsRenderData() {
|
|
269
269
|
if (this._itemsRenderData = [], this._visibleItemsNum = Math.min(Math.ceil(this.height / this.itemHeight), this.itemCount), this._visibleItemsNum > 0) {
|
|
270
270
|
this._firstVisibleIndex = this.normalizeIndex(Math.floor(this._lastKnownScrollTop / this.itemHeight)), this._lastVisibleIndex = this.normalizeIndex(this._firstVisibleIndex + this._visibleItemsNum);
|
|
271
|
-
const
|
|
272
|
-
this.requestData(
|
|
273
|
-
for (let i =
|
|
274
|
-
const n = i -
|
|
275
|
-
let
|
|
276
|
-
s ?
|
|
271
|
+
const t = this.normalizeIndex(this._firstVisibleIndex - 2), e = this.normalizeIndex(this._lastVisibleIndex + 2);
|
|
272
|
+
this.requestData(t, e);
|
|
273
|
+
for (let i = t; i <= e; i++) {
|
|
274
|
+
const n = i - t, s = this.items[n];
|
|
275
|
+
let r;
|
|
276
|
+
s ? r = JSON.stringify(s) : r = `placeholder-${n}`, this._itemsRenderData.push({
|
|
277
277
|
index: i,
|
|
278
278
|
top: this.itemHeight * i,
|
|
279
279
|
physicalIndex: n,
|
|
280
|
-
dataHash:
|
|
280
|
+
dataHash: r,
|
|
281
281
|
data: s
|
|
282
282
|
});
|
|
283
283
|
}
|
|
284
284
|
} else
|
|
285
285
|
this._firstVisibleIndex = 0, this._lastVisibleIndex = 0;
|
|
286
286
|
}
|
|
287
|
-
normalizeIndex(
|
|
288
|
-
return Math.max(0, Math.min(
|
|
287
|
+
normalizeIndex(t) {
|
|
288
|
+
return Math.max(0, Math.min(t, this.itemCount - 1));
|
|
289
289
|
}
|
|
290
290
|
get height() {
|
|
291
291
|
return this.offsetHeight;
|
|
292
292
|
}
|
|
293
|
-
requestData(
|
|
294
|
-
!Number.isNaN(
|
|
293
|
+
requestData(t, e) {
|
|
294
|
+
!Number.isNaN(t) && !Number.isNaN(e) && this.dispatchEvent(
|
|
295
295
|
new CustomEvent("data-request", {
|
|
296
296
|
detail: {
|
|
297
|
-
startIndex:
|
|
298
|
-
stopIndex:
|
|
297
|
+
startIndex: t,
|
|
298
|
+
stopIndex: e
|
|
299
299
|
}
|
|
300
300
|
})
|
|
301
301
|
);
|
|
302
302
|
}
|
|
303
|
-
handleSelection(
|
|
304
|
-
if (
|
|
303
|
+
handleSelection(t, e) {
|
|
304
|
+
if (t < 0 || this.itemCount <= t)
|
|
305
305
|
return;
|
|
306
|
-
const i = this.getListItem(
|
|
306
|
+
const i = this.getListItem(t);
|
|
307
307
|
if (i.getAttribute("aria-disabled") == "true" || i.hasAttribute("disabled"))
|
|
308
308
|
return;
|
|
309
309
|
let n = !0;
|
|
310
310
|
if (this.selectionType !== "trigger-only") {
|
|
311
|
-
const s = this.selectedIndices.indexOf(
|
|
312
|
-
n = s == -1, n ? this.selectionType === "single" ? this.selectedIndices = [
|
|
311
|
+
const s = this.selectedIndices.indexOf(t);
|
|
312
|
+
n = s == -1, n ? this.selectionType === "single" ? this.selectedIndices = [t] : this.selectedIndices.push(t) : this.selectedIndices.splice(s, 1), this.requestUpdate("selectedIndices");
|
|
313
313
|
}
|
|
314
|
-
this.focusIndex =
|
|
314
|
+
this.focusIndex = t, this.dispatchSelectionEvent(t, n, e);
|
|
315
315
|
}
|
|
316
|
-
dispatchSelectionEvent(
|
|
316
|
+
dispatchSelectionEvent(t, e, i) {
|
|
317
317
|
this.dispatchEvent(
|
|
318
318
|
new CustomEvent("selection", {
|
|
319
|
-
detail: { index:
|
|
319
|
+
detail: { index: t, selected: e, originalEvent: i }
|
|
320
320
|
})
|
|
321
321
|
);
|
|
322
322
|
}
|
|
323
|
-
handleClick(
|
|
324
|
-
const
|
|
325
|
-
if (
|
|
326
|
-
const i = parseInt(
|
|
327
|
-
Number.isInteger(i) && ((
|
|
323
|
+
handleClick(t) {
|
|
324
|
+
const e = t.composedPath().find((i) => i.hasAttribute && i.hasAttribute("item-index"));
|
|
325
|
+
if (e) {
|
|
326
|
+
const i = parseInt(e.getAttribute("item-index"));
|
|
327
|
+
Number.isInteger(i) && ((t.button == 0 || t.button == 1) && this.handleSelection(i, t), this.focusIndex = i);
|
|
328
328
|
}
|
|
329
329
|
}
|
|
330
|
-
},
|
|
331
|
-
f.ensureDefined(), customElements.get(
|
|
332
|
-
},
|
|
333
|
-
|
|
334
|
-
|
|
330
|
+
}, a.ID = "sd-virtual-list", a.ensureDefined = () => {
|
|
331
|
+
f.ensureDefined(), customElements.get(a.ID) || customElements.define(a.ID, a);
|
|
332
|
+
}, a);
|
|
333
|
+
d([
|
|
334
|
+
l({ type: Number, attribute: "item-height", reflect: !0 })
|
|
335
335
|
], o.prototype, "itemHeight", 2);
|
|
336
|
-
|
|
337
|
-
|
|
336
|
+
d([
|
|
337
|
+
l({ type: Number })
|
|
338
338
|
], o.prototype, "itemCount", 2);
|
|
339
|
-
|
|
340
|
-
|
|
339
|
+
d([
|
|
340
|
+
l({ type: Array, attribute: !1 })
|
|
341
341
|
], o.prototype, "items", 2);
|
|
342
|
-
|
|
343
|
-
|
|
342
|
+
d([
|
|
343
|
+
l({ type: String, attribute: "selection-type", reflect: !0, noAccessor: !0 })
|
|
344
344
|
], o.prototype, "selectionType", 2);
|
|
345
|
-
|
|
346
|
-
|
|
345
|
+
d([
|
|
346
|
+
l({ type: String, attribute: !0, reflect: !0 })
|
|
347
347
|
], o.prototype, "id", 2);
|
|
348
|
-
|
|
349
|
-
|
|
348
|
+
d([
|
|
349
|
+
l({ type: String, reflect: !0 })
|
|
350
350
|
], o.prototype, "role", 2);
|
|
351
|
-
|
|
352
|
-
|
|
351
|
+
d([
|
|
352
|
+
l({ type: Number, attribute: "focus-index", reflect: !0 })
|
|
353
353
|
], o.prototype, "focusIndex", 1);
|
|
354
|
-
|
|
355
|
-
|
|
354
|
+
d([
|
|
355
|
+
l({ type: Array, attribute: !1 })
|
|
356
356
|
], o.prototype, "selectedIndices", 1);
|
|
357
357
|
let D = o;
|
|
358
358
|
D.ensureDefined();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cas-smartdesign/virtual-list",
|
|
3
|
-
"version": "7.0
|
|
3
|
+
"version": "7.1.0",
|
|
4
4
|
"description": "A virtualized list element with SmartDesign look and feel.",
|
|
5
5
|
"main": "dist/virtual-list-with-externals.js",
|
|
6
6
|
"module": "dist/virtual-list.mjs",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"types": "dist/virtual-list.d.ts",
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"lit": "^3.3.1",
|
|
11
|
-
"@cas-smartdesign/list-item": "^7.
|
|
11
|
+
"@cas-smartdesign/list-item": "^7.5.0"
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {
|
|
14
14
|
"@cas-smartdesign/element-preview": "^0.3.1",
|
package/readme.md
CHANGED
|
@@ -35,6 +35,13 @@ The following properties are available:
|
|
|
35
35
|
- `selectedIndices` **_number[] (default=empty)_**
|
|
36
36
|
- Contains the indices of the selected items.
|
|
37
37
|
|
|
38
|
+
## CSS Custom Properties
|
|
39
|
+
|
|
40
|
+
- `--sd-virtual-list-focus-highlight-color`
|
|
41
|
+
- Defines the focus highlight color for list items, defaults to #1467ba
|
|
42
|
+
- `--sd-virtual-list-item-separator-color`
|
|
43
|
+
- Defines the separator color for list items, defaults to #d9d9d9
|
|
44
|
+
|
|
38
45
|
## Custom events
|
|
39
46
|
|
|
40
47
|
- `data-request`
|
|
@@ -43,7 +50,7 @@ The following properties are available:
|
|
|
43
50
|
- `selection`
|
|
44
51
|
- Dispatched when one of the items is selected/deselected
|
|
45
52
|
- Contains the index of the item and a `selected` flag which is when false indicates that the item is deselected
|
|
46
|
-
- The `
|
|
53
|
+
- The `originalEvent` a mouse or keyboard event that triggered the selection event.
|
|
47
54
|
|
|
48
55
|
## Public methods
|
|
49
56
|
|