@ng-select/ng-select 20.5.0 → 20.6.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,9 +1,10 @@
1
1
  import * as i0 from '@angular/core';
2
- import { inject, ElementRef, input, effect, Directive, TemplateRef, Injectable, Renderer2, NgZone, booleanAttribute, output, viewChild, computed, ViewEncapsulation, ChangeDetectionStrategy, Component, signal, afterNextRender, InjectionToken, HostAttributeToken, ChangeDetectorRef, numberAttribute, model, contentChild, contentChildren, forwardRef, Injector, HostListener, NgModule } from '@angular/core';
2
+ import { inject, ElementRef, input, effect, Directive, TemplateRef, Injectable, Renderer2, NgZone, DestroyRef, booleanAttribute, output, viewChild, computed, ViewEncapsulation, ChangeDetectionStrategy, Component, signal, afterNextRender, InjectionToken, HostAttributeToken, ChangeDetectorRef, numberAttribute, model, contentChild, contentChildren, forwardRef, Injector, HostListener, NgModule } from '@angular/core';
3
3
  import { NG_VALUE_ACCESSOR } from '@angular/forms';
4
- import { animationFrameScheduler, asapScheduler, Subject, fromEvent } from 'rxjs';
5
- import { takeUntil, auditTime, tap, debounceTime, filter, map } from 'rxjs/operators';
4
+ import { animationFrameScheduler, asapScheduler, fromEvent, Subject } from 'rxjs';
5
+ import { auditTime, tap, debounceTime, filter, map } from 'rxjs/operators';
6
6
  import { DOCUMENT, NgTemplateOutlet } from '@angular/common';
7
+ import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
7
8
 
8
9
  const unescapedHTMLExp = /[&<>"']/g;
9
10
  const hasUnescapedHTMLExp = RegExp(unescapedHTMLExp.source);
@@ -1570,11 +1571,32 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.6", ngImpor
1570
1571
  const CSS_POSITIONS = ['top', 'right', 'bottom', 'left'];
1571
1572
  const SCROLL_SCHEDULER = typeof requestAnimationFrame !== 'undefined' ? animationFrameScheduler : asapScheduler;
1572
1573
  class NgDropdownPanelComponent {
1574
+ get currentPosition() {
1575
+ return this._currentPosition;
1576
+ }
1577
+ get itemsLength() {
1578
+ return this._itemsLength;
1579
+ }
1580
+ set itemsLength(value) {
1581
+ if (value !== this._itemsLength) {
1582
+ this._itemsLength = value;
1583
+ this._onItemsLengthChanged();
1584
+ }
1585
+ }
1586
+ get _startOffset() {
1587
+ if (this.markedItem()) {
1588
+ const { itemHeight, panelHeight } = this._panelService.dimensions;
1589
+ const offset = this.markedItem().index * itemHeight;
1590
+ return panelHeight > offset ? 0 : offset;
1591
+ }
1592
+ return 0;
1593
+ }
1573
1594
  constructor() {
1574
1595
  this._renderer = inject(Renderer2);
1575
1596
  this._zone = inject(NgZone);
1576
1597
  this._panelService = inject(NgDropdownPanelService);
1577
1598
  this._document = inject(DOCUMENT, { optional: true });
1599
+ this._destroyRef = inject(DestroyRef);
1578
1600
  this._dropdown = inject((ElementRef)).nativeElement;
1579
1601
  this.items = input([], ...(ngDevMode ? [{ debugName: "items" }] : []));
1580
1602
  this.markedItem = input(undefined, ...(ngDevMode ? [{ debugName: "markedItem" }] : []));
@@ -1597,33 +1619,17 @@ class NgDropdownPanelComponent {
1597
1619
  this.contentElementRef = viewChild('content', ...(ngDevMode ? [{ debugName: "contentElementRef", read: ElementRef }] : [{ read: ElementRef }]));
1598
1620
  this.scrollElementRef = viewChild('scroll', ...(ngDevMode ? [{ debugName: "scrollElementRef", read: ElementRef }] : [{ read: ElementRef }]));
1599
1621
  this.paddingElementRef = viewChild('padding', ...(ngDevMode ? [{ debugName: "paddingElementRef", read: ElementRef }] : [{ read: ElementRef }]));
1600
- this._destroy$ = new Subject();
1601
1622
  this._virtualPadding = computed(() => this.paddingElementRef()?.nativeElement, ...(ngDevMode ? [{ debugName: "_virtualPadding" }] : []));
1602
1623
  this._scrollablePanel = computed(() => this.scrollElementRef()?.nativeElement, ...(ngDevMode ? [{ debugName: "_scrollablePanel" }] : []));
1603
1624
  this._contentPanel = computed(() => this.contentElementRef()?.nativeElement, ...(ngDevMode ? [{ debugName: "_contentPanel" }] : []));
1604
1625
  this._scrollToEndFired = false;
1605
1626
  this._updateScrollHeight = false;
1606
1627
  this._lastScrollPosition = 0;
1607
- }
1608
- get currentPosition() {
1609
- return this._currentPosition;
1610
- }
1611
- get itemsLength() {
1612
- return this._itemsLength;
1613
- }
1614
- set itemsLength(value) {
1615
- if (value !== this._itemsLength) {
1616
- this._itemsLength = value;
1617
- this._onItemsLengthChanged();
1618
- }
1619
- }
1620
- get _startOffset() {
1621
- if (this.markedItem()) {
1622
- const { itemHeight, panelHeight } = this._panelService.dimensions;
1623
- const offset = this.markedItem().index * itemHeight;
1624
- return panelHeight > offset ? 0 : offset;
1625
- }
1626
- return 0;
1628
+ this._destroyRef.onDestroy(() => {
1629
+ if (this.appendTo()) {
1630
+ this._renderer.removeChild(this._dropdown.parentNode, this._dropdown);
1631
+ }
1632
+ });
1627
1633
  }
1628
1634
  ngOnInit() {
1629
1635
  this._select = this._dropdown.parentElement;
@@ -1638,14 +1644,6 @@ class NgDropdownPanelComponent {
1638
1644
  this._onItemsChange(change.currentValue, change.firstChange);
1639
1645
  }
1640
1646
  }
1641
- ngOnDestroy() {
1642
- this._destroy$.next();
1643
- this._destroy$.complete();
1644
- this._destroy$.unsubscribe();
1645
- if (this.appendTo()) {
1646
- this._renderer.removeChild(this._dropdown.parentNode, this._dropdown);
1647
- }
1648
- }
1649
1647
  scrollTo(option, startFromOption = false) {
1650
1648
  if (!option) {
1651
1649
  return;
@@ -1704,7 +1702,7 @@ class NgDropdownPanelComponent {
1704
1702
  return;
1705
1703
  }
1706
1704
  fromEvent(this._scrollablePanel(), 'scroll')
1707
- .pipe(takeUntil(this._destroy$), auditTime(0, SCROLL_SCHEDULER))
1705
+ .pipe(takeUntilDestroyed(this._destroyRef), auditTime(0, SCROLL_SCHEDULER))
1708
1706
  .subscribe((event) => {
1709
1707
  const target = event.target;
1710
1708
  if (target && 'scrollTop' in target) {
@@ -1719,7 +1717,7 @@ class NgDropdownPanelComponent {
1719
1717
  }
1720
1718
  this._zone.runOutsideAngular(() => {
1721
1719
  fromEvent(this._document, this.outsideClickEvent(), { capture: true })
1722
- .pipe(takeUntil(this._destroy$))
1720
+ .pipe(takeUntilDestroyed(this._destroyRef))
1723
1721
  .subscribe(($event) => this._checkToClose($event));
1724
1722
  });
1725
1723
  }
@@ -1900,7 +1898,7 @@ class NgDropdownPanelComponent {
1900
1898
  _setupMousedownListener() {
1901
1899
  this._zone.runOutsideAngular(() => {
1902
1900
  fromEvent(this._dropdown, 'mousedown')
1903
- .pipe(takeUntil(this._destroy$))
1901
+ .pipe(takeUntilDestroyed(this._destroyRef))
1904
1902
  .subscribe((event) => {
1905
1903
  const target = event.target;
1906
1904
  if (target.tagName === 'INPUT') {
@@ -1956,7 +1954,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.6", ngImpor
1956
1954
  `,
1957
1955
  imports: [NgTemplateOutlet],
1958
1956
  }]
1959
- }], propDecorators: { items: [{ type: i0.Input, args: [{ isSignal: true, alias: "items", required: false }] }], markedItem: [{ type: i0.Input, args: [{ isSignal: true, alias: "markedItem", required: false }] }], position: [{ type: i0.Input, args: [{ isSignal: true, alias: "position", required: false }] }], appendTo: [{ type: i0.Input, args: [{ isSignal: true, alias: "appendTo", required: false }] }], bufferAmount: [{ type: i0.Input, args: [{ isSignal: true, alias: "bufferAmount", required: false }] }], virtualScroll: [{ type: i0.Input, args: [{ isSignal: true, alias: "virtualScroll", required: false }] }], headerTemplate: [{ type: i0.Input, args: [{ isSignal: true, alias: "headerTemplate", required: false }] }], footerTemplate: [{ type: i0.Input, args: [{ isSignal: true, alias: "footerTemplate", required: false }] }], filterValue: [{ type: i0.Input, args: [{ isSignal: true, alias: "filterValue", required: false }] }], ariaLabelDropdown: [{ type: i0.Input, args: [{ isSignal: true, alias: "ariaLabelDropdown", required: false }] }], outsideClickEvent: [{ type: i0.Input, args: [{ isSignal: true, alias: "outsideClickEvent", required: false }] }], update: [{ type: i0.Output, args: ["update"] }], scroll: [{ type: i0.Output, args: ["scroll"] }], scrollToEnd: [{ type: i0.Output, args: ["scrollToEnd"] }], outsideClick: [{ type: i0.Output, args: ["outsideClick"] }], contentElementRef: [{ type: i0.ViewChild, args: ['content', { ...{ read: ElementRef }, isSignal: true }] }], scrollElementRef: [{ type: i0.ViewChild, args: ['scroll', { ...{ read: ElementRef }, isSignal: true }] }], paddingElementRef: [{ type: i0.ViewChild, args: ['padding', { ...{ read: ElementRef }, isSignal: true }] }] } });
1957
+ }], ctorParameters: () => [], propDecorators: { items: [{ type: i0.Input, args: [{ isSignal: true, alias: "items", required: false }] }], markedItem: [{ type: i0.Input, args: [{ isSignal: true, alias: "markedItem", required: false }] }], position: [{ type: i0.Input, args: [{ isSignal: true, alias: "position", required: false }] }], appendTo: [{ type: i0.Input, args: [{ isSignal: true, alias: "appendTo", required: false }] }], bufferAmount: [{ type: i0.Input, args: [{ isSignal: true, alias: "bufferAmount", required: false }] }], virtualScroll: [{ type: i0.Input, args: [{ isSignal: true, alias: "virtualScroll", required: false }] }], headerTemplate: [{ type: i0.Input, args: [{ isSignal: true, alias: "headerTemplate", required: false }] }], footerTemplate: [{ type: i0.Input, args: [{ isSignal: true, alias: "footerTemplate", required: false }] }], filterValue: [{ type: i0.Input, args: [{ isSignal: true, alias: "filterValue", required: false }] }], ariaLabelDropdown: [{ type: i0.Input, args: [{ isSignal: true, alias: "ariaLabelDropdown", required: false }] }], outsideClickEvent: [{ type: i0.Input, args: [{ isSignal: true, alias: "outsideClickEvent", required: false }] }], update: [{ type: i0.Output, args: ["update"] }], scroll: [{ type: i0.Output, args: ["scroll"] }], scrollToEnd: [{ type: i0.Output, args: ["scrollToEnd"] }], outsideClick: [{ type: i0.Output, args: ["outsideClick"] }], contentElementRef: [{ type: i0.ViewChild, args: ['content', { ...{ read: ElementRef }, isSignal: true }] }], scrollElementRef: [{ type: i0.ViewChild, args: ['scroll', { ...{ read: ElementRef }, isSignal: true }] }], paddingElementRef: [{ type: i0.ViewChild, args: ['padding', { ...{ read: ElementRef }, isSignal: true }] }] } });
1960
1958
 
1961
1959
  class NgOptionComponent {
1962
1960
  constructor() {
@@ -2079,6 +2077,7 @@ class NgSelectComponent {
2079
2077
  this.config = inject(NgSelectConfig);
2080
2078
  this._cd = inject(ChangeDetectorRef);
2081
2079
  this._console = inject(ConsoleService);
2080
+ this._destroyRef = inject(DestroyRef);
2082
2081
  // signals
2083
2082
  this._disabled = signal(false, ...(ngDevMode ? [{ debugName: "_disabled" }] : []));
2084
2083
  // inputs
@@ -2207,7 +2206,6 @@ class NgSelectComponent {
2207
2206
  this.autoFocus = inject(new HostAttributeToken('autofocus'), { optional: true });
2208
2207
  // private variables
2209
2208
  this._defaultLabel = 'label';
2210
- this._destroy$ = new Subject();
2211
2209
  this._editableSearchTerm = computed(() => this.editableSearchTerm() && !this.multiple(), ...(ngDevMode ? [{ debugName: "_editableSearchTerm" }] : []));
2212
2210
  this._injector = inject(Injector);
2213
2211
  this._isComposing = false;
@@ -2305,10 +2303,6 @@ class NgSelectComponent {
2305
2303
  this.focus();
2306
2304
  }
2307
2305
  }
2308
- ngOnDestroy() {
2309
- this._destroy$.next();
2310
- this._destroy$.complete();
2311
- }
2312
2306
  handleKeyDown($event) {
2313
2307
  const keyName = $event.key;
2314
2308
  if (Object.values(KeyCode).includes(keyName)) {
@@ -2726,7 +2720,7 @@ class NgSelectComponent {
2726
2720
  return;
2727
2721
  }
2728
2722
  this._keyPress$
2729
- .pipe(takeUntil(this._destroy$), tap((letter) => this._pressedKeys.push(letter)), debounceTime(200), filter(() => this._pressedKeys.length > 0), map(() => this._pressedKeys.join('')))
2723
+ .pipe(takeUntilDestroyed(this._destroyRef), tap((letter) => this._pressedKeys.push(letter)), debounceTime(200), filter(() => this._pressedKeys.length > 0), map(() => this._pressedKeys.join('')))
2730
2724
  .subscribe((term) => {
2731
2725
  const item = this.itemsList.findByLabel(term);
2732
2726
  if (item) {