@ngutil/floating 0.0.62 → 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.
- package/README.md +28 -13
- package/esm2022/index.mjs +15 -2
- package/esm2022/layer/child-ref.mjs +19 -10
- package/esm2022/layer/external-ref.mjs +4 -0
- package/esm2022/layer/index.mjs +2 -1
- package/esm2022/layer/layer-container.mjs +110 -0
- package/esm2022/layer/layer.service.mjs +35 -118
- package/fesm2022/ngutil-floating.mjs +162 -129
- package/fesm2022/ngutil-floating.mjs.map +1 -1
- package/index.d.ts +5 -1
- package/layer/child-ref.d.ts +18 -3
- package/layer/external-ref.d.ts +3 -0
- package/layer/index.d.ts +1 -0
- package/layer/layer-container.d.ts +22 -0
- package/layer/layer.service.d.ts +10 -21
- package/package.json +4 -4
- package/esm2022/floating.module.mjs +0 -16
- package/floating.module.d.ts +0 -6
|
@@ -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,
|
|
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
|
-
|
|
528
|
+
/**
|
|
529
|
+
* Modals
|
|
530
|
+
*/
|
|
526
531
|
AlwaysOnTop[AlwaysOnTop["Modal"] = 2] = "Modal";
|
|
527
|
-
|
|
528
|
-
|
|
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,99 +651,22 @@ class BackdropRef extends ChildRef {
|
|
|
642
651
|
}
|
|
643
652
|
}
|
|
644
653
|
|
|
645
|
-
class
|
|
646
|
-
constructor(options) {
|
|
647
|
-
super(options);
|
|
648
|
-
this.injectorName = "PortalRef";
|
|
649
|
-
this.outlet = new DomPortalOutlet(this.nativeElement, undefined, undefined, this.injector);
|
|
650
|
-
this.state.on("disposed", () => {
|
|
651
|
-
this.outlet.dispose();
|
|
652
|
-
delete this.outlet;
|
|
653
|
-
});
|
|
654
|
-
}
|
|
655
|
-
getProviders() {
|
|
656
|
-
return [...super.getProviders(), { provide: PortalRef, useValue: this }];
|
|
657
|
-
}
|
|
658
|
-
}
|
|
659
|
-
class ComponentPortalRef extends PortalRef {
|
|
660
|
-
constructor(component, options) {
|
|
661
|
-
super(options);
|
|
662
|
-
this.component = component;
|
|
663
|
-
this.injectorName = "ComponentPortalRef";
|
|
664
|
-
const resolver = this.injector.get(ComponentFactoryResolver);
|
|
665
|
-
const vcr = this.injector.get(ViewContainerRef);
|
|
666
|
-
this.portal = new ComponentPortal(component, options.viewContainerRef || vcr, this.injector, resolver);
|
|
667
|
-
this.outlet.attach(this.portal);
|
|
668
|
-
this.state.on("disposed", () => {
|
|
669
|
-
this.portal.isAttached && this.portal.detach();
|
|
670
|
-
delete this.portal;
|
|
671
|
-
});
|
|
672
|
-
}
|
|
673
|
-
getProviders() {
|
|
674
|
-
return [...super.getProviders(), { provide: ComponentPortalRef, useValue: this }];
|
|
675
|
-
}
|
|
676
|
-
}
|
|
677
|
-
class TemplatePortalRef extends PortalRef {
|
|
678
|
-
constructor(template, options) {
|
|
679
|
-
super(options);
|
|
680
|
-
this.template = template;
|
|
681
|
-
this.injectorName = "TemplatePortalRef";
|
|
682
|
-
this.portal = new TemplatePortal(template, options.viewContainerRef, options.context);
|
|
683
|
-
this.outlet.attach(this.portal);
|
|
684
|
-
this.state.on("disposed", () => {
|
|
685
|
-
this.portal.isAttached && this.portal.detach();
|
|
686
|
-
delete this.portal;
|
|
687
|
-
});
|
|
688
|
-
}
|
|
689
|
-
getProviders() {
|
|
690
|
-
return [...super.getProviders(), { provide: TemplatePortalRef, useValue: this }];
|
|
691
|
-
}
|
|
654
|
+
class ExternalRef extends ChildRef {
|
|
692
655
|
}
|
|
693
656
|
|
|
694
|
-
const
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
#injector = inject(Injector);
|
|
700
|
-
#children = [];
|
|
701
|
-
#zIndexStart;
|
|
702
|
-
constructor(zIndexStart) {
|
|
703
|
-
if (zIndexStart != null) {
|
|
704
|
-
this.#zIndexStart = zIndexStart;
|
|
705
|
-
}
|
|
706
|
-
else {
|
|
707
|
-
this.#zIndexStart = 10000;
|
|
708
|
-
}
|
|
709
|
-
}
|
|
710
|
-
newComponentPortal(component, options) {
|
|
711
|
-
if (!options.injector) {
|
|
712
|
-
options = { ...options, injector: this.#injector };
|
|
713
|
-
}
|
|
714
|
-
return this.append(new ComponentPortalRef(component, options));
|
|
715
|
-
}
|
|
716
|
-
newTemplatePortal(tpl, options) {
|
|
717
|
-
if (!options.injector) {
|
|
718
|
-
options = { ...options, injector: this.#injector };
|
|
719
|
-
}
|
|
720
|
-
return this.append(new TemplatePortalRef(tpl, options));
|
|
721
|
-
}
|
|
722
|
-
newContainer(options) {
|
|
723
|
-
if (!options.injector) {
|
|
724
|
-
options = { ...options, injector: this.#injector };
|
|
725
|
-
}
|
|
726
|
-
return this.append(new ContainerRef(options));
|
|
727
|
-
}
|
|
728
|
-
newBackdrop(under, options) {
|
|
729
|
-
const coverRef = this.#cover.create(this.root, options);
|
|
730
|
-
return this.append(new BackdropRef(coverRef, under, options));
|
|
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);
|
|
731
662
|
}
|
|
663
|
+
#children;
|
|
732
664
|
append(ref) {
|
|
733
665
|
if (!this.#children.includes(ref)) {
|
|
734
666
|
this.#children.push(ref);
|
|
735
667
|
this.#update();
|
|
736
668
|
this.root.appendChild(ref.nativeElement);
|
|
737
|
-
ref.state.on("
|
|
669
|
+
ref.state.on("disposing", () => this.#remove(ref));
|
|
738
670
|
}
|
|
739
671
|
return ref;
|
|
740
672
|
}
|
|
@@ -747,7 +679,7 @@ class LayerService {
|
|
|
747
679
|
}
|
|
748
680
|
#update() {
|
|
749
681
|
const children = toSorted(this.#children, sortChildren2);
|
|
750
|
-
let zIndex = this
|
|
682
|
+
let zIndex = this.zIndexStart;
|
|
751
683
|
for (const child of children) {
|
|
752
684
|
child.zIndex = zIndex;
|
|
753
685
|
zIndex += 1;
|
|
@@ -761,42 +693,36 @@ class LayerService {
|
|
|
761
693
|
}
|
|
762
694
|
}
|
|
763
695
|
}
|
|
764
|
-
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.6", ngImport: i0, type:
|
|
765
|
-
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "18.2.6", type:
|
|
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 }); }
|
|
766
698
|
}
|
|
767
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.6", ngImport: i0, type:
|
|
699
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.6", ngImport: i0, type: LayerContainer, decorators: [{
|
|
768
700
|
type: Directive
|
|
769
|
-
}]
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
}] }] });
|
|
775
|
-
class RootLayer extends LayerService {
|
|
776
|
-
#doc = inject(DOCUMENT);
|
|
777
|
-
get root() {
|
|
778
|
-
return this.#doc.body;
|
|
701
|
+
}] });
|
|
702
|
+
class RootLayer extends LayerContainer {
|
|
703
|
+
constructor() {
|
|
704
|
+
super(...arguments);
|
|
705
|
+
this.root = inject(DOCUMENT).body;
|
|
779
706
|
}
|
|
780
707
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.6", ngImport: i0, type: RootLayer, deps: null, target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
781
|
-
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.6", ngImport: i0, type: RootLayer
|
|
708
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.6", ngImport: i0, type: RootLayer }); }
|
|
782
709
|
}
|
|
783
710
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.6", ngImport: i0, type: RootLayer, decorators: [{
|
|
784
|
-
type: Injectable
|
|
785
|
-
args: [{ providedIn: "root" }]
|
|
711
|
+
type: Injectable
|
|
786
712
|
}] });
|
|
787
|
-
class IndividualLayer extends
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
713
|
+
class IndividualLayer extends LayerContainer {
|
|
714
|
+
constructor() {
|
|
715
|
+
super(...arguments);
|
|
716
|
+
this.root = inject(ElementRef).nativeElement;
|
|
791
717
|
}
|
|
792
718
|
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.6", ngImport: i0, type: IndividualLayer, deps: null, target: i0.ɵɵFactoryTarget.Directive }); }
|
|
793
|
-
static { this.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "18.2.6", type: IndividualLayer, isStandalone: true, providers: [{ provide:
|
|
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 }); }
|
|
794
720
|
}
|
|
795
721
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.6", ngImport: i0, type: IndividualLayer, decorators: [{
|
|
796
722
|
type: Directive,
|
|
797
723
|
args: [{
|
|
798
724
|
standalone: true,
|
|
799
|
-
providers: [{ provide:
|
|
725
|
+
providers: [{ provide: LayerContainer, useExisting: IndividualLayer }]
|
|
800
726
|
}]
|
|
801
727
|
}] });
|
|
802
728
|
function sortChildren2(a, b) {
|
|
@@ -832,6 +758,112 @@ function getAlwaysOnTop(child) {
|
|
|
832
758
|
}
|
|
833
759
|
}
|
|
834
760
|
|
|
761
|
+
class PortalRef extends ContainerRef {
|
|
762
|
+
constructor(options) {
|
|
763
|
+
super(options);
|
|
764
|
+
this.injectorName = "PortalRef";
|
|
765
|
+
this.outlet = new DomPortalOutlet(this.nativeElement, undefined, undefined, this.injector);
|
|
766
|
+
this.state.on("disposed", () => {
|
|
767
|
+
this.outlet.dispose();
|
|
768
|
+
delete this.outlet;
|
|
769
|
+
});
|
|
770
|
+
}
|
|
771
|
+
getProviders() {
|
|
772
|
+
return [...super.getProviders(), { provide: PortalRef, useValue: this }];
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
class ComponentPortalRef extends PortalRef {
|
|
776
|
+
constructor(component, options) {
|
|
777
|
+
super(options);
|
|
778
|
+
this.component = component;
|
|
779
|
+
this.injectorName = "ComponentPortalRef";
|
|
780
|
+
const resolver = this.injector.get(ComponentFactoryResolver);
|
|
781
|
+
const vcr = this.injector.get(ViewContainerRef);
|
|
782
|
+
this.portal = new ComponentPortal(component, options.viewContainerRef || vcr, this.injector, resolver);
|
|
783
|
+
this.outlet.attach(this.portal);
|
|
784
|
+
this.state.on("disposed", () => {
|
|
785
|
+
this.portal.isAttached && this.portal.detach();
|
|
786
|
+
delete this.portal;
|
|
787
|
+
});
|
|
788
|
+
}
|
|
789
|
+
getProviders() {
|
|
790
|
+
return [...super.getProviders(), { provide: ComponentPortalRef, useValue: this }];
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
class TemplatePortalRef extends PortalRef {
|
|
794
|
+
constructor(template, options) {
|
|
795
|
+
super(options);
|
|
796
|
+
this.template = template;
|
|
797
|
+
this.injectorName = "TemplatePortalRef";
|
|
798
|
+
this.portal = new TemplatePortal(template, options.viewContainerRef, options.context);
|
|
799
|
+
this.outlet.attach(this.portal);
|
|
800
|
+
this.state.on("disposed", () => {
|
|
801
|
+
this.portal.isAttached && this.portal.detach();
|
|
802
|
+
delete this.portal;
|
|
803
|
+
});
|
|
804
|
+
}
|
|
805
|
+
getProviders() {
|
|
806
|
+
return [...super.getProviders(), { provide: TemplatePortalRef, useValue: this }];
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
|
|
810
|
+
// TODO: ELEVATION_STEP config with injection
|
|
811
|
+
// TODO: ELEVATION_START config with injection
|
|
812
|
+
class LayerService {
|
|
813
|
+
#container = inject(LayerContainer);
|
|
814
|
+
#cover = inject(CoverService);
|
|
815
|
+
#injector = inject(Injector);
|
|
816
|
+
#appRef = inject(ApplicationRef);
|
|
817
|
+
get root() {
|
|
818
|
+
return this.#container.root;
|
|
819
|
+
}
|
|
820
|
+
constructor() {
|
|
821
|
+
console.log(this.#appRef);
|
|
822
|
+
// console.log(this.#appRef.)
|
|
823
|
+
}
|
|
824
|
+
newComponentPortal(component, options) {
|
|
825
|
+
// console.log(this.getRootViewContainerRef())
|
|
826
|
+
if (!options.injector) {
|
|
827
|
+
options = { ...options, injector: this.#getInjector() };
|
|
828
|
+
}
|
|
829
|
+
return this.#container.append(new ComponentPortalRef(component, options));
|
|
830
|
+
}
|
|
831
|
+
newTemplatePortal(tpl, options) {
|
|
832
|
+
if (!options.injector) {
|
|
833
|
+
options = { ...options, injector: this.#getInjector() };
|
|
834
|
+
}
|
|
835
|
+
return this.#container.append(new TemplatePortalRef(tpl, options));
|
|
836
|
+
}
|
|
837
|
+
newContainer(options) {
|
|
838
|
+
if (!options.injector) {
|
|
839
|
+
options = { ...options, injector: this.#getInjector() };
|
|
840
|
+
}
|
|
841
|
+
return this.#container.append(new ContainerRef(options));
|
|
842
|
+
}
|
|
843
|
+
newBackdrop(under, options) {
|
|
844
|
+
const coverRef = this.#cover.create(this.root, options);
|
|
845
|
+
return this.#container.append(new BackdropRef(coverRef, under, options));
|
|
846
|
+
}
|
|
847
|
+
addExternal(element, alwaysOnTop = AlwaysOnTop.None) {
|
|
848
|
+
return this.#container.append(new ExternalRef(coerceElement(element), alwaysOnTop));
|
|
849
|
+
}
|
|
850
|
+
#getInjector() {
|
|
851
|
+
try {
|
|
852
|
+
this.#injector.get(ViewContainerRef);
|
|
853
|
+
return this.#injector;
|
|
854
|
+
// eslint-disable-next-line no-empty
|
|
855
|
+
}
|
|
856
|
+
catch (err) { }
|
|
857
|
+
const root = this.#appRef.components[0];
|
|
858
|
+
return root.injector;
|
|
859
|
+
}
|
|
860
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.6", ngImport: i0, type: LayerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
861
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.6", ngImport: i0, type: LayerService }); }
|
|
862
|
+
}
|
|
863
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.6", ngImport: i0, type: LayerService, decorators: [{
|
|
864
|
+
type: Injectable
|
|
865
|
+
}], ctorParameters: () => [] });
|
|
866
|
+
|
|
835
867
|
const TRAITS = new InjectionToken("TRAITS");
|
|
836
868
|
let UID_COUNTER = 0;
|
|
837
869
|
class FloatingRef {
|
|
@@ -1058,21 +1090,22 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.6", ngImpor
|
|
|
1058
1090
|
type: Injectable
|
|
1059
1091
|
}] });
|
|
1060
1092
|
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
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
|
+
];
|
|
1065
1104
|
}
|
|
1066
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.6", ngImport: i0, type: NuFloating, decorators: [{
|
|
1067
|
-
type: NgModule,
|
|
1068
|
-
args: [{
|
|
1069
|
-
providers: [FloatingService, { provide: LayerService, useClass: RootLayer }]
|
|
1070
|
-
}]
|
|
1071
|
-
}] });
|
|
1072
1105
|
|
|
1073
1106
|
/**
|
|
1074
1107
|
* Generated bundle index. Do not edit.
|
|
1075
1108
|
*/
|
|
1076
1109
|
|
|
1077
|
-
export { AlwaysOnTop, AnimationTrait, AttributeTrait, BackdropRef, BackdropTrait, ChildRef, ComponentPortalRef, ContainerRef, DimensionConstraintTrait, DropAnimation, FadeAnimation, FallAnimation, FloatingAnchorRef, FloatingComponentFactory, FloatingFactory, FloatingPlacementRef, FloatingPosition, FloatingRef, FloatingService, FloatingTemplateFactory, FocusTrait, IndividualLayer,
|
|
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 };
|
|
1078
1111
|
//# sourceMappingURL=ngutil-floating.mjs.map
|