ng-virtual-list 0.5.2 → 0.6.1

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/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  # NgVirtualList
2
- Fast, optimized rendering of extremely large numbers of list items
2
+ Maximum performance for extremely large lists.
3
+ It is based on algorithms for virtualization of screen objects.
3
4
 
4
5
  Angular version 19.X.X.
5
6
 
@@ -262,11 +263,7 @@ Template
262
263
 
263
264
  Component
264
265
  ```ts
265
- import { Component, viewChild } from '@angular/core';
266
- import { NgVirtualListComponent } from '../../projects/ng-virtual-list/src/public-api';
267
- import { IVirtualListCollection } from '../../projects/ng-virtual-list/src/lib/models';
268
- import { FormsModule } from '@angular/forms';
269
- import { Id } from '../../projects/ng-virtual-list/src/lib/types';
266
+ import { NgVirtualListComponent, IVirtualListCollection, Id } from 'ng-virtual-list';
270
267
 
271
268
  const MAX_ITEMS = 1000000;
272
269
 
@@ -298,6 +295,72 @@ export class AppComponent {
298
295
 
299
296
  ```
300
297
 
298
+ ### Virtual list (with dynamic item size)
299
+
300
+ Experimental functionality
301
+
302
+ ![preview](https://github.com/user-attachments/assets/7f2bd405-033e-457d-a713-368f066ee4a2)
303
+
304
+ Template
305
+ ```html
306
+ <ng-virtual-list class="list" [items]="dynamicItems" [itemRenderer]="itemRenderer" [itemsOffset]="0"
307
+ [dynamicSize]="true" [snap]="false"></ng-virtual-list>
308
+
309
+ <ng-template #itemRenderer let-data="data">
310
+ @if (data) {
311
+ <div class="list__container">
312
+ <span>{{data.name}}</span>
313
+ </div>
314
+ }
315
+ </ng-template>
316
+ ```
317
+
318
+ Component
319
+ ```ts
320
+ import { NgVirtualListComponent, IVirtualListCollection } from 'ng-virtual-list';
321
+
322
+ const CHARS = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
323
+
324
+ const generateLetter = () => {
325
+ return CHARS[Math.round(Math.random() * CHARS.length)];
326
+ }
327
+
328
+ const generateWord = () => {
329
+ const length = 5 + Math.floor(Math.random() * 50), result = [];
330
+ while (result.length < length) {
331
+ result.push(generateLetter());
332
+ }
333
+ return `${result.join('')}`;
334
+ };
335
+
336
+ const generateText = () => {
337
+ const length = 2 + Math.floor(Math.random() * 10), result = [];
338
+ while (result.length < length) {
339
+ result.push(generateWord());
340
+ }
341
+ result[0] = result[0].toUpperCase();
342
+ return `${result.join(' ')}.`;
343
+ };
344
+
345
+ const DYNAMIC_ITEMS: IVirtualListCollection = [];
346
+
347
+ const t = generateText();
348
+ for (let i = 0, l = 100; i < l; i++) {
349
+ const id = i + 1;
350
+ DYNAMIC_ITEMS.push({ id, type, name: `${id}. ${generateText()}` });
351
+ }
352
+
353
+ @Component({
354
+ selector: 'app-root',
355
+ imports: [FormsModule, NgVirtualListComponent],
356
+ templateUrl: './app.component.html',
357
+ styleUrl: './app.component.scss'
358
+ })
359
+ export class AppComponent {
360
+ dynamicItems = DYNAMIC_ITEMS;
361
+ }
362
+ ```
363
+
301
364
  ## Stylization
302
365
 
303
366
  List items are encapsulated in shadowDOM, so to override default styles you need to use ::part access
@@ -362,13 +425,14 @@ Inputs
362
425
  |---|---|---|
363
426
  | id | number | Readonly. Returns the unique identifier of the component. |
364
427
  | items | [IVirtualListCollection](https://github.com/DjonnyX/ng-virtual-list/blob/main/projects/ng-virtual-list/src/lib/models/collection.model.ts) | Collection of list items. |
365
- | itemSize | number | If direction = 'vertical', then the height of a typical element. If direction = 'horizontal', then the width of a typical element. |
366
- | itemsOffset | number? | Number of elements outside the scope of visibility. Default value is 2. |
428
+ | itemSize | number? = 24 | If direction = 'vertical', then the height of a typical element. If direction = 'horizontal', then the width of a typical element. Ignored if the dynamicSize property is true. |
429
+ | itemsOffset | number? = 2 | Number of elements outside the scope of visibility. Default value is 2. |
367
430
  | itemRenderer | TemplateRef | Rendering element template. |
368
431
  | stickyMap | [IVirtualListStickyMap?](https://github.com/DjonnyX/ng-virtual-list/blob/main/projects/ng-virtual-list/src/lib/models/sticky-map.model.ts) | Dictionary zIndex by id of the list element. If the value is not set or equal to 0, then a simple element is displayed, if the value is greater than 0, then the sticky position mode is enabled for the element. |
369
- | snap | boolean? | Determines whether elements will snap. Default value is "false". |
370
- | snapToItem | boolean? | Determines whether scroll positions will be snapped to the element. Default value is "false". |
371
- | direction | [Direction](https://github.com/DjonnyX/ng-virtual-list/blob/main/projects/ng-virtual-list/src/lib/enums/direction.ts) | Determines the direction in which elements are placed. Default value is "vertical". |
432
+ | snap | boolean? = false | Determines whether elements will snap. Default value is "false". |
433
+ | snapToItem | boolean? = false | Determines whether scroll positions will be snapped to the element. Default value is "false". |
434
+ | direction | [Direction? = 'vertical'](https://github.com/DjonnyX/ng-virtual-list/blob/main/projects/ng-virtual-list/src/lib/enums/direction.ts) | Determines the direction in which elements are placed. Default value is "vertical". |
435
+ | dynamicSize | boolean? = false | ${\color{red}EXPERIMENTAL!}$ If true then the items in the list can have different sizes and the itemSize property is ignored. If false then the items in the list have a fixed size specified by the itemSize property. The default value is false. |
372
436
 
373
437
  <br/>
374
438
 
@@ -385,4 +449,4 @@ Methods
385
449
 
386
450
  | Method | Type | Description |
387
451
  |--|--|--|
388
- | scrollTo | (id: [Id](https://github.com/DjonnyX/ng-virtual-list/blob/main/projects/ng-virtual-list/src/lib/types/id.ts), behavior: ScrollBehavior = 'auto') => number | The method scrolls the list to the element with the given id and returns the value of the scrolled area. Behavior accepts the values ​​"auto", "instant" and "smooth". |
452
+ | scrollTo | (id: [Id](https://github.com/DjonnyX/ng-virtual-list/blob/main/projects/ng-virtual-list/src/lib/types/id.ts), behavior: ScrollBehavior = 'auto') => number | The method scrolls the list to the element with the given id and returns the value of the scrolled area. Behavior accepts the values ​​"auto", "instant" and "smooth". |