@ship-ui/core 0.15.22 → 0.15.24

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,7 +1,6 @@
1
1
  import * as i0 from '@angular/core';
2
2
  import { inject, ElementRef, Renderer2, ChangeDetectionStrategy, Component, signal, DestroyRef, InjectionToken, input, computed, viewChild, effect, HostListener, NgModule, Injectable, DOCUMENT, model, output, ApplicationRef, createComponent, isSignal, OutputEmitterRef, PLATFORM_ID, ViewChild, contentChild, contentChildren, afterNextRender, assertInInjectionContext, Injector, HostBinding, TemplateRef, runInInjectionContext, Directive, ChangeDetectorRef, viewChildren, ViewContainerRef, EnvironmentInjector } from '@angular/core';
3
3
  import { isPlatformBrowser, JsonPipe, DatePipe, NgTemplateOutlet } from '@angular/common';
4
- import { ShipCardComponent as ShipCardComponent$1, ShipIconComponent as ShipIconComponent$1, ShipButtonComponent as ShipButtonComponent$1 } from 'ship-ui';
5
4
  import { NgModel } from '@angular/forms';
6
5
  import { SIGNAL } from '@angular/core/primitives/signals';
7
6
 
@@ -1509,13 +1508,13 @@ class ShipBlueprintComponent {
1509
1508
  </div>
1510
1509
  }
1511
1510
  </div>
1512
- `, isInline: true, dependencies: [{ kind: "component", type: ShipCardComponent$1, selector: "sh-card" }, { kind: "component", type: ShipIconComponent$1, selector: "sh-icon" }, { kind: "component", type: ShipButtonComponent$1, selector: "[shButton]" }, { kind: "pipe", type: JsonPipe, name: "json" }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
1511
+ `, isInline: true, dependencies: [{ kind: "component", type: ShipCardComponent, selector: "sh-card" }, { kind: "component", type: ShipIconComponent, selector: "sh-icon" }, { kind: "component", type: ShipButtonComponent, selector: "[shButton]" }, { kind: "pipe", type: JsonPipe, name: "json" }], changeDetection: i0.ChangeDetectionStrategy.OnPush }); }
1513
1512
  }
1514
1513
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.3.0", ngImport: i0, type: ShipBlueprintComponent, decorators: [{
1515
1514
  type: Component,
1516
1515
  args: [{
1517
1516
  selector: 'sh-blueprint',
1518
- imports: [ShipCardComponent$1, ShipIconComponent$1, JsonPipe, ShipButtonComponent$1],
1517
+ imports: [ShipCardComponent, ShipIconComponent, JsonPipe, ShipButtonComponent],
1519
1518
  template: `
1520
1519
  <div
1521
1520
  class="canvas-container"
@@ -3594,6 +3593,7 @@ function observeChildren(parentEl, elementTags) {
3594
3593
 
3595
3594
  class ShipMenuComponent {
3596
3595
  constructor() {
3596
+ this.#document = inject(DOCUMENT);
3597
3597
  this.#renderer = inject(Renderer2);
3598
3598
  this.asMultiLayer = input(false, ...(ngDevMode ? [{ debugName: "asMultiLayer" }] : []));
3599
3599
  this.openIndicator = input(false, ...(ngDevMode ? [{ debugName: "openIndicator" }] : []));
@@ -3612,17 +3612,26 @@ class ShipMenuComponent {
3612
3612
  this.inputValue = createInputSignal(this.inputRef);
3613
3613
  this.abortController = null;
3614
3614
  this.optionsEffect = effect(() => {
3615
- if (!this.isOpen())
3616
- return;
3617
- if (this.abortController) {
3615
+ if (this.abortController !== null) {
3618
3616
  this.abortController.abort();
3619
3617
  this.abortController = null;
3620
3618
  }
3619
+ if (!this.isOpen())
3620
+ return;
3621
3621
  this.abortController = new AbortController();
3622
+ const searchable = this.searchable();
3623
+ if (!searchable) {
3624
+ this.#document.documentElement.addEventListener('keydown', this.keyDownEventListener, {
3625
+ signal: this.abortController.signal,
3626
+ });
3627
+ }
3622
3628
  const inputEl = this.inputRef()?.nativeElement;
3623
3629
  if (!inputEl)
3624
3630
  return;
3625
3631
  queueMicrotask(() => inputEl.focus());
3632
+ inputEl.addEventListener('keydown', this.keyDownEventListener, {
3633
+ signal: this.abortController.signal,
3634
+ });
3626
3635
  if (!this.closeOnClick()) {
3627
3636
  const optionRef = this.optionsRef()?.nativeElement;
3628
3637
  optionRef?.addEventListener('click', (e) => {
@@ -3640,31 +3649,29 @@ class ShipMenuComponent {
3640
3649
  }
3641
3650
  });
3642
3651
  }
3643
- inputEl.addEventListener('keydown', (e) => {
3644
- const activeOptionIndex = this.activeOptionIndex();
3645
- if (e.key === 'ArrowDown') {
3646
- e.preventDefault();
3647
- this.activeOptionIndex.set(this.nextActiveIndex(activeOptionIndex));
3648
- }
3649
- else if (e.key === 'ArrowUp') {
3650
- e.preventDefault();
3651
- this.activeOptionIndex.set(this.prevActiveIndex(activeOptionIndex));
3652
- }
3653
- else if (e.key === 'Enter') {
3654
- e.preventDefault();
3655
- if (activeOptionIndex > -1) {
3656
- this.activeElements()[activeOptionIndex].click();
3657
- queueMicrotask(() => this.close('active'));
3658
- }
3659
- }
3660
- else if (e.key === 'Tab') {
3661
- e.preventDefault();
3662
- this.close('closed');
3663
- }
3664
- }, {
3665
- signal: this.abortController.signal,
3666
- });
3667
3652
  }, ...(ngDevMode ? [{ debugName: "optionsEffect" }] : []));
3653
+ this.keyDownEventListener = (e) => {
3654
+ const activeOptionIndex = this.activeOptionIndex();
3655
+ if (e.key === 'ArrowDown') {
3656
+ e.preventDefault();
3657
+ this.activeOptionIndex.set(this.nextActiveIndex(activeOptionIndex));
3658
+ }
3659
+ else if (e.key === 'ArrowUp') {
3660
+ e.preventDefault();
3661
+ this.activeOptionIndex.set(this.prevActiveIndex(activeOptionIndex));
3662
+ }
3663
+ else if (e.key === 'Enter') {
3664
+ e.preventDefault();
3665
+ if (activeOptionIndex > -1) {
3666
+ this.activeElements()[activeOptionIndex].click();
3667
+ queueMicrotask(() => this.close('active'));
3668
+ }
3669
+ }
3670
+ else if (e.key === 'Tab') {
3671
+ e.preventDefault();
3672
+ this.close('closed');
3673
+ }
3674
+ };
3668
3675
  this._lastElementList = [];
3669
3676
  this.activeElements = signal([], ...(ngDevMode ? [{ debugName: "activeElements" }] : []));
3670
3677
  this.lastInputValue = '';
@@ -3674,6 +3681,15 @@ class ShipMenuComponent {
3674
3681
  return;
3675
3682
  const inputValue = (this.inputValue() ?? '').toLowerCase();
3676
3683
  this.#resetActiveOption();
3684
+ if (!inputValue || inputValue === '') {
3685
+ const allOptions = this.optionsEl();
3686
+ this.activeElements.set(allOptions);
3687
+ this._lastElementList = allOptions;
3688
+ for (let i = 0; i < allOptions.length; i++) {
3689
+ this.#renderer.removeStyle(allOptions[i], 'order');
3690
+ }
3691
+ return;
3692
+ }
3677
3693
  if (!inputValue || inputValue === '')
3678
3694
  return;
3679
3695
  let optionElements = this._lastElementList.length && inputValue.length > this.lastInputValue.length
@@ -3707,6 +3723,7 @@ class ShipMenuComponent {
3707
3723
  }
3708
3724
  }, ...(ngDevMode ? [{ debugName: "activeOptionIndexEffect" }] : []));
3709
3725
  }
3726
+ #document;
3710
3727
  #renderer;
3711
3728
  toggleIsOpen(event) {
3712
3729
  event.preventDefault();