@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.
@@ -1,10 +1,10 @@
1
1
  import { LitElement as p, unsafeCSS as b, css as _, html as x } from "lit";
2
- import { property as d } from "lit/decorators/property.js";
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(e, t, i, n, s, a) {
6
- const m = Math.max(0, a * n), u = Math.min(m, e * n), c = Math.max(0, e * n - s + n);
7
- switch (t) {
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(e) {
23
- let t;
22
+ debounce(t) {
23
+ let e;
24
24
  return (...i) => {
25
- t && window.cancelAnimationFrame(t), t = window.requestAnimationFrame(() => {
26
- e(...i), t = null;
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(e = 100, t = 5) {
34
- this.pageSize = e, this.preloadedItemsCount = t, this._finalSizeIsKnown = !1, this._itemCache = [], this._lastRequestedFirstIndex = 0, this._lastRequestedLastIndex = 0, this._lastLoadedIndex = 0, this.handleListDataRequest = (i) => {
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 = e;
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(e) {
46
- this._finalSizeIsKnown = e, e && (this.itemCount = this._itemCache.length), this._list && (this._list.finalSizeIsKnown = e);
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(e) {
52
- this._itemCount = e, this._list && (this._list.itemCount = e);
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(e) {
58
- this._itemCache = e, this.onItemsChange();
57
+ set items(t) {
58
+ this._itemCache = t, this.onItemsChange();
59
59
  }
60
- addItems(e) {
61
- this._itemCache = this._itemCache.concat(e), this.onItemsChange();
60
+ addItems(t) {
61
+ this._itemCache = this._itemCache.concat(t), this.onItemsChange();
62
62
  }
63
- connectList(e) {
64
- this._list && this._list.removeEventListener("data-request", this.handleListDataRequest), this._list = e, e.itemCount = this.itemCount, e.addEventListener("data-request", this.handleListDataRequest), e.finalSizeIsKnown = this._finalSizeIsKnown;
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 S = ":host{display:block;position:relative;contain:layout}:host(:focus){outline:none}:host(:focus-visible) ::slotted([focused]){box-shadow:0 0 0 1px #1467ba inset}.container{width:100%}.container>::slotted(*){width:100%;position:absolute;box-sizing:border-box}.container>::slotted(:not([last])){border-bottom:1px solid #d9d9d9}";
80
- var v = Object.defineProperty, A = Object.getOwnPropertyDescriptor, l = (h, e, t, i) => {
81
- for (var n = i > 1 ? void 0 : i ? A(e, t) : e, s = h.length - 1, a; s >= 0; s--)
82
- (a = h[s]) && (n = (i ? a(e, t, n) : a(n)) || n);
83
- return i && n && v(e, t, n), 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 r;
87
- const o = (r = class extends p {
86
+ var a;
87
+ const o = (a = class extends p {
88
88
  constructor() {
89
- super(), this.items = [], this.selectionType = "trigger-only", this.id = r.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 = () => {
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 e = this._lastRenderedScrollTop - this._lastKnownScrollTop;
92
- Math.abs(e) >= this.itemHeight && (this._lastRenderedScrollTop = this._lastKnownScrollTop, this.requestUpdate());
93
- }, this.handleKeyDown = (e) => {
94
- let t = !0;
95
- switch (e.key) {
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, e);
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
- t = !1;
120
+ e = !1;
121
121
  break;
122
122
  }
123
- t && (e.preventDefault(), e.stopPropagation());
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(e) {
132
- this.toggleAttribute("focus-target", e);
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(e) {
138
- if (e >= -1 && e < this.itemCount) {
139
- const t = this._focusIndex;
140
- this._focusIndex = e, (e <= this._firstVisibleIndex || this._lastVisibleIndex <= e) && this.scrollToItem(e), t != e && (e == -1 && this.removeAttribute("aria-activedescendant"), this.requestUpdate("focusIndex", t));
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(e) {
147
- e ? this._selectedIndices = e.map((t) => Number(t)) : this._selectedIndices = [], this.requestUpdate("selectedIndices");
146
+ set selectedIndices(t) {
147
+ t ? this._selectedIndices = t.map((e) => Number(e)) : this._selectedIndices = [], this.requestUpdate("selectedIndices");
148
148
  }
149
- scrollToItem(e, t = "auto") {
149
+ scrollToItem(t, e = "auto") {
150
150
  this.scrollTop = w.getOffsetForIndexAndAlignment(
151
- this.normalizeIndex(e),
152
- t,
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(e) {
160
- return !this.shadowRoot || e < this._firstVisibleIndex || this._lastVisibleIndex < e ? null : this.querySelector(`[item-index="${e}"]`);
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(e) {
169
- super.firstUpdated(e), this.addEventListener("scroll", this.onScroll), this.addEventListener("keydown", this.handleKeyDown), this.addEventListener("click", this.handleClick), this.addEventListener("mousedown", (t) => {
170
- t.button == 1 && t.preventDefault();
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 e = this.getListItem(this.focusIndex);
179
- e && (this.focusTarget || document.activeElement == this ? (e.setAttribute("focused", ""), this.setAttribute("aria-activedescendant", e.id)) : (e.removeAttribute("focused"), this.removeAttribute("aria-activedescendant")));
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(S)}
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(e) {
196
- if (super.updated(e), this._lastRenderedScrollTop = this._lastKnownScrollTop, this.updateItems(), (this._increaseWidthOnNextRenderIfNeeded || this._reachedMaxWidth) && //
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 t = new MutationObserver(() => {
202
- this.adjustWidthIfNeeded(), t.disconnect();
201
+ const e = new MutationObserver(() => {
202
+ this.adjustWidthIfNeeded(), e.disconnect();
203
203
  });
204
- t.observe(this);
204
+ e.observe(this);
205
205
  }
206
206
  }
207
207
  adjustWidthIfNeeded() {
208
208
  this._increaseWidthOnNextRenderIfNeeded ? (this._increaseWidthOnNextRenderIfNeeded = !1, window.requestAnimationFrame(() => {
209
- const e = Number.parseInt(getComputedStyle(this).maxWidth) - this.offsetWidth;
210
- if (e == 0)
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 t = [...this.querySelectorAll("[item-index]")].map((n) => {
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 > e && (n.enableLineClamp = !0), s;
218
+ return s > t && (n.enableLineClamp = !0), s;
219
219
  }
220
- }), i = Math.max(...t);
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((e) => {
227
- e instanceof f && (e.enableLineClamp = e.enableLineClamp || e.missingWidthForTexts > 0);
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 e = [...this.querySelectorAll("[item-index]")], t = /* @__PURE__ */ new Map(), i = document.createDocumentFragment();
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), t.set(n.dataHash, s);
244
- const a = e.indexOf(s);
245
- a !== -1 && e.splice(a, 1);
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 e)
248
+ for (const n of t)
249
249
  n instanceof f && (n.enableLineClamp = !1), this.removeChild(n);
250
- t.forEach((n, s) => {
250
+ e.forEach((n, s) => {
251
251
  this._elementCache.set(s, n);
252
252
  });
253
253
  }
254
- renderItem({ index: e, top: t, dataHash: i, data: n }) {
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, e), s.setAttribute("slot", "items")) : (s = document.createElement("div"), s.setAttribute("placeholder-item", ""), s.setAttribute("slot", "items")), Object.assign(s.style, {
257
- transform: `translateY(${t}px)`,
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", e.toString()), s.setAttribute("aria-setsize", String(this.finalSizeIsKnown ? this.itemCount : -1)), s.setAttribute("aria-posinset", String(e + 1)), (!s.id || s.id.startsWith(this.id + "_item_")) && (s.id = this.id + "_item_" + e), this.itemCount - 1 == e ? s.setAttribute("last", "") : s.removeAttribute("last"), this.updateSelectedAttribute(e, s), this.updateFocusedAttribute(e, s), s;
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(e, t) {
262
- this.focusIndex == e && (this.focusTarget || document.activeElement == this) ? (t.setAttribute("focused", ""), this.setAttribute("aria-activedescendant", t.id)) : t.removeAttribute("focused");
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(e, t) {
265
- const i = this.selectedIndices.indexOf(e) !== -1;
266
- i ? t.setAttribute("selected", "") : t.removeAttribute("selected"), t.setAttribute("aria-selected", String(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 e = this.normalizeIndex(this._firstVisibleIndex - 2), t = this.normalizeIndex(this._lastVisibleIndex + 2);
272
- this.requestData(e, t);
273
- for (let i = e; i <= t; i++) {
274
- const n = i - e, s = this.items[n];
275
- let a;
276
- s ? a = JSON.stringify(s) : a = `placeholder-${n}`, this._itemsRenderData.push({
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: a,
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(e) {
288
- return Math.max(0, Math.min(e, this.itemCount - 1));
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(e, t) {
294
- !Number.isNaN(e) && !Number.isNaN(t) && this.dispatchEvent(
293
+ requestData(t, e) {
294
+ !Number.isNaN(t) && !Number.isNaN(e) && this.dispatchEvent(
295
295
  new CustomEvent("data-request", {
296
296
  detail: {
297
- startIndex: e,
298
- stopIndex: t
297
+ startIndex: t,
298
+ stopIndex: e
299
299
  }
300
300
  })
301
301
  );
302
302
  }
303
- handleSelection(e, t) {
304
- if (e < 0 || this.itemCount <= e)
303
+ handleSelection(t, e) {
304
+ if (t < 0 || this.itemCount <= t)
305
305
  return;
306
- const i = this.getListItem(e);
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(e);
312
- n = s == -1, n ? this.selectionType === "single" ? this.selectedIndices = [e] : this.selectedIndices.push(e) : this.selectedIndices.splice(s, 1), this.requestUpdate("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 = e, this.dispatchSelectionEvent(e, n, t);
314
+ this.focusIndex = t, this.dispatchSelectionEvent(t, n, e);
315
315
  }
316
- dispatchSelectionEvent(e, t, i) {
316
+ dispatchSelectionEvent(t, e, i) {
317
317
  this.dispatchEvent(
318
318
  new CustomEvent("selection", {
319
- detail: { index: e, selected: t, originalEvent: i }
319
+ detail: { index: t, selected: e, originalEvent: i }
320
320
  })
321
321
  );
322
322
  }
323
- handleClick(e) {
324
- const t = e.composedPath().find((i) => i.hasAttribute && i.hasAttribute("item-index"));
325
- if (t) {
326
- const i = parseInt(t.getAttribute("item-index"));
327
- Number.isInteger(i) && ((e.button == 0 || e.button == 1) && this.handleSelection(i, e), this.focusIndex = 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
- }, r.ID = "sd-virtual-list", r.ensureDefined = () => {
331
- f.ensureDefined(), customElements.get(r.ID) || customElements.define(r.ID, r);
332
- }, r);
333
- l([
334
- d({ type: Number, attribute: "item-height", reflect: !0 })
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
- l([
337
- d({ type: Number })
336
+ d([
337
+ l({ type: Number })
338
338
  ], o.prototype, "itemCount", 2);
339
- l([
340
- d({ type: Array, attribute: !1 })
339
+ d([
340
+ l({ type: Array, attribute: !1 })
341
341
  ], o.prototype, "items", 2);
342
- l([
343
- d({ type: String, attribute: "selection-type", reflect: !0, noAccessor: !0 })
342
+ d([
343
+ l({ type: String, attribute: "selection-type", reflect: !0, noAccessor: !0 })
344
344
  ], o.prototype, "selectionType", 2);
345
- l([
346
- d({ type: String, attribute: !0, reflect: !0 })
345
+ d([
346
+ l({ type: String, attribute: !0, reflect: !0 })
347
347
  ], o.prototype, "id", 2);
348
- l([
349
- d({ type: String, reflect: !0 })
348
+ d([
349
+ l({ type: String, reflect: !0 })
350
350
  ], o.prototype, "role", 2);
351
- l([
352
- d({ type: Number, attribute: "focus-index", reflect: !0 })
351
+ d([
352
+ l({ type: Number, attribute: "focus-index", reflect: !0 })
353
353
  ], o.prototype, "focusIndex", 1);
354
- l([
355
- d({ type: Array, attribute: !1 })
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.1",
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.4.4"
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 `hasModifier` property is true if mouse wheel or ctrl/meta key is down while selection. Note that the auto scroll feature is disabled while middle mouse click.
53
+ - The `originalEvent` a mouse or keyboard event that triggered the selection event.
47
54
 
48
55
  ## Public methods
49
56