@ngutil/floating 0.0.61 → 0.0.63

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.
@@ -6,7 +6,7 @@ import { KeystrokeService, FocusService } from '@ngutil/aria';
6
6
  import { coerceElement, isElementInput, Lifecycle, toSorted } from '@ngutil/common';
7
7
  import { clamp } from 'lodash';
8
8
  import * as i0 from '@angular/core';
9
- import { ElementRef, Injector, ComponentFactoryResolver, ViewContainerRef, InjectionToken, inject, Injectable, Inject, Optional, Directive, TemplateRef, NgModule } from '@angular/core';
9
+ import { ElementRef, Injector, InjectionToken, inject, Directive, Injectable, ComponentFactoryResolver, ViewContainerRef, ApplicationRef, Inject, TemplateRef } from '@angular/core';
10
10
  import { DOCUMENT } from '@angular/common';
11
11
  import { DomPortalOutlet, ComponentPortal, TemplatePortal } from '@angular/cdk/portal';
12
12
 
@@ -521,11 +521,26 @@ function attribute(attrs) {
521
521
 
522
522
  var AlwaysOnTop;
523
523
  (function (AlwaysOnTop) {
524
+ /**
525
+ * Display as open order
526
+ */
524
527
  AlwaysOnTop[AlwaysOnTop["None"] = 0] = "None";
525
- AlwaysOnTop[AlwaysOnTop["Normal"] = 1] = "Normal";
528
+ /**
529
+ * Modals
530
+ */
526
531
  AlwaysOnTop[AlwaysOnTop["Modal"] = 2] = "Modal";
527
- AlwaysOnTop[AlwaysOnTop["Toast"] = 3] = "Toast";
528
- AlwaysOnTop[AlwaysOnTop["UAC"] = 100] = "UAC";
532
+ /**
533
+ * User access control
534
+ */
535
+ AlwaysOnTop[AlwaysOnTop["UAC"] = 3] = "UAC";
536
+ /**
537
+ * Toast...
538
+ */
539
+ AlwaysOnTop[AlwaysOnTop["Toast"] = 4] = "Toast";
540
+ /**
541
+ * Like select drop down, tooltip, stb...
542
+ */
543
+ AlwaysOnTop[AlwaysOnTop["Control"] = 5] = "Control";
529
544
  })(AlwaysOnTop || (AlwaysOnTop = {}));
530
545
  // TODO: disposing, disposed
531
546
  class ChildRef extends ElementRef {
@@ -557,12 +572,6 @@ class ChildRef extends ElementRef {
557
572
  this.state.destroy();
558
573
  delete this.state;
559
574
  });
560
- // this.state.current$.subscribe(state => {
561
- // console.log(this, state)
562
- // })
563
- // this.state.status$.subscribe(status => {
564
- // console.log(this.nativeElement, status)
565
- // })
566
575
  }
567
576
  dispose() {
568
577
  if (this.state == null) {
@@ -642,6 +651,113 @@ class BackdropRef extends ChildRef {
642
651
  }
643
652
  }
644
653
 
654
+ class ExternalRef extends ChildRef {
655
+ }
656
+
657
+ const LAYER_CONTAINER_ZINDEX_START = new InjectionToken("LAYER_CONTAINER_ZINDEX_START");
658
+ class LayerContainer {
659
+ constructor() {
660
+ this.#children = [];
661
+ this.zIndexStart = inject(LAYER_CONTAINER_ZINDEX_START);
662
+ }
663
+ #children;
664
+ append(ref) {
665
+ if (!this.#children.includes(ref)) {
666
+ this.#children.push(ref);
667
+ this.#update();
668
+ this.root.appendChild(ref.nativeElement);
669
+ ref.state.on("disposing", () => this.#remove(ref));
670
+ }
671
+ return ref;
672
+ }
673
+ #remove(ref) {
674
+ const idx = this.#children.indexOf(ref);
675
+ if (idx > -1) {
676
+ this.#children.splice(idx, 1);
677
+ this.#update();
678
+ }
679
+ }
680
+ #update() {
681
+ const children = toSorted(this.#children, sortChildren2);
682
+ let zIndex = this.zIndexStart;
683
+ for (const child of children) {
684
+ child.zIndex = zIndex;
685
+ zIndex += 1;
686
+ }
687
+ children.sort(sortByZIndexDesc);
688
+ let hasBackdrop = false;
689
+ for (const child of children) {
690
+ if (child instanceof BackdropRef && child.options.color !== "transparent") {
691
+ child.visible = !hasBackdrop;
692
+ hasBackdrop = true;
693
+ }
694
+ }
695
+ }
696
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.6", ngImport: i0, type: LayerContainer, deps: [], target: i0.ɵɵFactoryTarget.Directive }); }
697
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "18.2.6", type: LayerContainer, ngImport: i0 }); }
698
+ }
699
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.6", ngImport: i0, type: LayerContainer, decorators: [{
700
+ type: Directive
701
+ }] });
702
+ class RootLayer extends LayerContainer {
703
+ constructor() {
704
+ super(...arguments);
705
+ this.root = inject(DOCUMENT).body;
706
+ }
707
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.6", ngImport: i0, type: RootLayer, deps: null, target: i0.ɵɵFactoryTarget.Injectable }); }
708
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.6", ngImport: i0, type: RootLayer }); }
709
+ }
710
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.6", ngImport: i0, type: RootLayer, decorators: [{
711
+ type: Injectable
712
+ }] });
713
+ class IndividualLayer extends LayerContainer {
714
+ constructor() {
715
+ super(...arguments);
716
+ this.root = inject(ElementRef).nativeElement;
717
+ }
718
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.6", ngImport: i0, type: IndividualLayer, deps: null, target: i0.ɵɵFactoryTarget.Directive }); }
719
+ static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "18.2.6", type: IndividualLayer, isStandalone: true, providers: [{ provide: LayerContainer, useExisting: IndividualLayer }], usesInheritance: true, ngImport: i0 }); }
720
+ }
721
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.6", ngImport: i0, type: IndividualLayer, decorators: [{
722
+ type: Directive,
723
+ args: [{
724
+ standalone: true,
725
+ providers: [{ provide: LayerContainer, useExisting: IndividualLayer }]
726
+ }]
727
+ }] });
728
+ function sortChildren2(a, b) {
729
+ const alwaysOnTop = sortByAlwaysOnTop(a, b);
730
+ if (alwaysOnTop === 0) {
731
+ return sortByBackdrop(a, b);
732
+ }
733
+ else {
734
+ return alwaysOnTop;
735
+ }
736
+ }
737
+ function sortByBackdrop(a, b) {
738
+ if (a instanceof BackdropRef && a.under === b) {
739
+ return -1;
740
+ }
741
+ else if (b instanceof BackdropRef && b.under === a) {
742
+ return 1;
743
+ }
744
+ return 0;
745
+ }
746
+ function sortByZIndexDesc(a, b) {
747
+ return b.zIndex - a.zIndex;
748
+ }
749
+ function sortByAlwaysOnTop(a, b) {
750
+ return getAlwaysOnTop(a) - getAlwaysOnTop(b);
751
+ }
752
+ function getAlwaysOnTop(child) {
753
+ if (child instanceof BackdropRef) {
754
+ return child.under.alwaysOnTop || AlwaysOnTop.None;
755
+ }
756
+ else {
757
+ return child.alwaysOnTop || AlwaysOnTop.None;
758
+ }
759
+ }
760
+
645
761
  class PortalRef extends ContainerRef {
646
762
  constructor(options) {
647
763
  super(options);
@@ -691,149 +807,62 @@ class TemplatePortalRef extends PortalRef {
691
807
  }
692
808
  }
693
809
 
694
- const LAYER_ZINDEX_START = new InjectionToken("LAYER_ZINDEX_START");
695
810
  // TODO: ELEVATION_STEP config with injection
696
811
  // TODO: ELEVATION_START config with injection
697
812
  class LayerService {
813
+ #container = inject(LayerContainer);
698
814
  #cover = inject(CoverService);
699
815
  #injector = inject(Injector);
700
- #document = inject(DOCUMENT);
701
- #el = inject(ElementRef, { optional: true, self: true });
816
+ #appRef = inject(ApplicationRef);
702
817
  get root() {
703
- return (this.#el && this.#el.nativeElement) || this.#document.body;
704
- }
705
- // readonly #el = this.root.nativeElement
706
- #children = [];
707
- #zIndexStart;
708
- // readonly #backdrop: Map<>
709
- constructor(zIndexStart) {
710
- if (zIndexStart != null) {
711
- this.#zIndexStart = zIndexStart;
712
- }
713
- else {
714
- this.#zIndexStart = 10000;
715
- }
818
+ return this.#container.root;
819
+ }
820
+ constructor() {
821
+ console.log(this.#appRef);
822
+ // console.log(this.#appRef.)
716
823
  }
717
824
  newComponentPortal(component, options) {
825
+ // console.log(this.getRootViewContainerRef())
718
826
  if (!options.injector) {
719
- options = { ...options, injector: this.#injector };
827
+ options = { ...options, injector: this.#getInjector() };
720
828
  }
721
- return this.append(new ComponentPortalRef(component, options));
829
+ return this.#container.append(new ComponentPortalRef(component, options));
722
830
  }
723
831
  newTemplatePortal(tpl, options) {
724
832
  if (!options.injector) {
725
- options = { ...options, injector: this.#injector };
833
+ options = { ...options, injector: this.#getInjector() };
726
834
  }
727
- return this.append(new TemplatePortalRef(tpl, options));
835
+ return this.#container.append(new TemplatePortalRef(tpl, options));
728
836
  }
729
837
  newContainer(options) {
730
838
  if (!options.injector) {
731
- options = { ...options, injector: this.#injector };
839
+ options = { ...options, injector: this.#getInjector() };
732
840
  }
733
- return this.append(new ContainerRef(options));
841
+ return this.#container.append(new ContainerRef(options));
734
842
  }
735
843
  newBackdrop(under, options) {
736
844
  const coverRef = this.#cover.create(this.root, options);
737
- return this.append(new BackdropRef(coverRef, under, options));
845
+ return this.#container.append(new BackdropRef(coverRef, under, options));
738
846
  }
739
- append(ref) {
740
- if (!this.#children.includes(ref)) {
741
- this.#children.push(ref);
742
- this.#update();
743
- this.root.appendChild(ref.nativeElement);
744
- ref.state.on("disposed", () => this.#remove(ref));
745
- }
746
- return ref;
747
- }
748
- #remove(ref) {
749
- const idx = this.#children.indexOf(ref);
750
- if (idx > -1) {
751
- this.#children.splice(idx, 1);
752
- this.#update();
753
- }
847
+ addExternal(element, alwaysOnTop = AlwaysOnTop.None) {
848
+ return this.#container.append(new ExternalRef(coerceElement(element), alwaysOnTop));
754
849
  }
755
- #update() {
756
- const children = toSorted(this.#children, sortChildren2);
757
- let zIndex = this.#zIndexStart;
758
- for (const child of children) {
759
- child.zIndex = zIndex;
760
- zIndex += 1;
761
- }
762
- children.sort(sortByZIndexDesc);
763
- let hasBackdrop = false;
764
- for (const child of children) {
765
- if (child instanceof BackdropRef && child.options.color !== "transparent") {
766
- child.visible = !hasBackdrop;
767
- hasBackdrop = true;
768
- }
850
+ #getInjector() {
851
+ try {
852
+ this.#injector.get(ViewContainerRef);
853
+ return this.#injector;
854
+ // eslint-disable-next-line no-empty
769
855
  }
856
+ catch (err) { }
857
+ const root = this.#appRef.components[0];
858
+ return root.injector;
770
859
  }
771
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.6", ngImport: i0, type: LayerService, deps: [{ token: LAYER_ZINDEX_START, optional: true }], target: i0.ɵɵFactoryTarget.Injectable }); }
860
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.6", ngImport: i0, type: LayerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
772
861
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.6", ngImport: i0, type: LayerService }); }
773
862
  }
774
863
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.6", ngImport: i0, type: LayerService, decorators: [{
775
864
  type: Injectable
776
- }], ctorParameters: () => [{ type: undefined, decorators: [{
777
- type: Inject,
778
- args: [LAYER_ZINDEX_START]
779
- }, {
780
- type: Optional
781
- }] }] });
782
- class RootLayer extends LayerService {
783
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.6", ngImport: i0, type: RootLayer, deps: null, target: i0.ɵɵFactoryTarget.Directive }); }
784
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "18.2.6", type: RootLayer, isStandalone: true, selector: "body", providers: [{ provide: LayerService, useExisting: RootLayer }], usesInheritance: true, ngImport: i0 }); }
785
- }
786
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.6", ngImport: i0, type: RootLayer, decorators: [{
787
- type: Directive,
788
- args: [{
789
- selector: "body",
790
- standalone: true,
791
- providers: [{ provide: LayerService, useExisting: RootLayer }]
792
- }]
793
- }] });
794
- class IndividualLayer extends LayerService {
795
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.6", ngImport: i0, type: IndividualLayer, deps: null, target: i0.ɵɵFactoryTarget.Directive }); }
796
- static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "18.2.6", type: IndividualLayer, isStandalone: true, providers: [{ provide: LayerService, useExisting: IndividualLayer }], usesInheritance: true, ngImport: i0 }); }
797
- }
798
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.6", ngImport: i0, type: IndividualLayer, decorators: [{
799
- type: Directive,
800
- args: [{
801
- standalone: true,
802
- providers: [{ provide: LayerService, useExisting: IndividualLayer }]
803
- }]
804
- }] });
805
- function sortChildren2(a, b) {
806
- const alwaysOnTop = sortByAlwaysOnTop(a, b);
807
- if (alwaysOnTop === 0) {
808
- return sortByBackdrop(a, b);
809
- }
810
- else {
811
- return alwaysOnTop;
812
- }
813
- }
814
- function sortByBackdrop(a, b) {
815
- if (a instanceof BackdropRef && a.under === b) {
816
- return -1;
817
- }
818
- else if (b instanceof BackdropRef && b.under === a) {
819
- return 1;
820
- }
821
- return 0;
822
- }
823
- function sortByZIndexDesc(a, b) {
824
- return b.zIndex - a.zIndex;
825
- }
826
- function sortByAlwaysOnTop(a, b) {
827
- return getAlwaysOnTop(a) - getAlwaysOnTop(b);
828
- }
829
- function getAlwaysOnTop(child) {
830
- if (child instanceof BackdropRef) {
831
- return child.under.alwaysOnTop || AlwaysOnTop.None;
832
- }
833
- else {
834
- return child.alwaysOnTop || AlwaysOnTop.None;
835
- }
836
- }
865
+ }], ctorParameters: () => [] });
837
866
 
838
867
  const TRAITS = new InjectionToken("TRAITS");
839
868
  let UID_COUNTER = 0;
@@ -1061,23 +1090,22 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.6", ngImpor
1061
1090
  type: Injectable
1062
1091
  }] });
1063
1092
 
1064
- class NuFloating {
1065
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.6", ngImport: i0, type: NuFloating, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
1066
- static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.2.6", ngImport: i0, type: NuFloating, imports: [RootLayer], exports: [RootLayer] }); }
1067
- static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.2.6", ngImport: i0, type: NuFloating, providers: [FloatingService] }); }
1093
+ const DEFAULTS = {
1094
+ zIndexStart: 10000
1095
+ };
1096
+ function provideFloating(options = {}) {
1097
+ const opts = { ...DEFAULTS, ...options };
1098
+ return [
1099
+ { provide: LAYER_CONTAINER_ZINDEX_START, useValue: opts.zIndexStart },
1100
+ { provide: LayerContainer, useClass: RootLayer },
1101
+ LayerService,
1102
+ FloatingService
1103
+ ];
1068
1104
  }
1069
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.6", ngImport: i0, type: NuFloating, decorators: [{
1070
- type: NgModule,
1071
- args: [{
1072
- providers: [FloatingService],
1073
- imports: [RootLayer],
1074
- exports: [RootLayer]
1075
- }]
1076
- }] });
1077
1105
 
1078
1106
  /**
1079
1107
  * Generated bundle index. Do not edit.
1080
1108
  */
1081
1109
 
1082
- export { AlwaysOnTop, AnimationTrait, AttributeTrait, BackdropRef, BackdropTrait, ChildRef, ComponentPortalRef, ContainerRef, DimensionConstraintTrait, DropAnimation, FadeAnimation, FallAnimation, FloatingAnchorRef, FloatingComponentFactory, FloatingFactory, FloatingPlacementRef, FloatingPosition, FloatingRef, FloatingService, FloatingTemplateFactory, FocusTrait, IndividualLayer, LAYER_ZINDEX_START, LayerService, NuFloating, PortalRef, PositionTrait, RootLayer, StyleTrait, TRAITS, TemplatePortalRef, attribute, backdrop, closeTrigger, computePosition, dropAnimation, fadeAnimation, fallAnimation, focus, maxHeight, maxWidth, minHeight, minWidth, modal, position, style };
1110
+ export { AlwaysOnTop, AnimationTrait, AttributeTrait, BackdropRef, BackdropTrait, ChildRef, ComponentPortalRef, ContainerRef, DimensionConstraintTrait, DropAnimation, FadeAnimation, FallAnimation, FloatingAnchorRef, FloatingComponentFactory, FloatingFactory, FloatingPlacementRef, FloatingPosition, FloatingRef, FloatingService, FloatingTemplateFactory, FocusTrait, IndividualLayer, LAYER_CONTAINER_ZINDEX_START, LayerContainer, LayerService, PortalRef, PositionTrait, RootLayer, StyleTrait, TRAITS, TemplatePortalRef, attribute, backdrop, closeTrigger, computePosition, dropAnimation, fadeAnimation, fallAnimation, focus, maxHeight, maxWidth, minHeight, minWidth, modal, position, provideFloating, style };
1083
1111
  //# sourceMappingURL=ngutil-floating.mjs.map