ng-zorro-antd-dropdown.mjs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. import { __esDecorate, __runInitializers } from 'tslib';
  2. import { ESCAPE, hasModifierKey } from '@angular/cdk/keycodes';
  3. import * as i1$2 from '@angular/cdk/overlay';
  4. import { Overlay, ConnectionPositionPair } from '@angular/cdk/overlay';
  5. import { TemplatePortal } from '@angular/cdk/portal';
  6. import * as i0 from '@angular/core';
  7. import { inject, ElementRef, EventEmitter, booleanAttribute, Output, Input, Directive, NgModule, TemplateRef, ViewChild, ChangeDetectionStrategy, ViewEncapsulation, Component, Injectable } from '@angular/core';
  8. import { Subject, BehaviorSubject, merge, fromEvent, EMPTY, combineLatest, Subscription } from 'rxjs';
  9. import { map, switchMap, filter, auditTime, distinctUntilChanged, takeUntil, first } from 'rxjs/operators';
  10. import * as i1 from 'ng-zorro-antd/core/config';
  11. import { WithConfig } from 'ng-zorro-antd/core/config';
  12. import { POSITION_MAP } from 'ng-zorro-antd/core/overlay';
  13. import * as i2 from '@angular/cdk/platform';
  14. import { MenuService, NzIsMenuInsideDropDownToken, NzMenuModule } from 'ng-zorro-antd/menu';
  15. import { NzButtonGroupComponent } from 'ng-zorro-antd/button';
  16. import { slideMotion } from 'ng-zorro-antd/core/animation';
  17. import { NzNoAnimationDirective } from 'ng-zorro-antd/core/no-animation';
  18. import * as i1$1 from '@angular/cdk/bidi';
  19. import { fromEventOutsideAngular } from 'ng-zorro-antd/core/util';
  20. const NZ_CONFIG_MODULE_NAME = 'dropDown';
  21. const listOfPositions = [
  22. POSITION_MAP.bottomLeft,
  23. POSITION_MAP.bottomRight,
  24. POSITION_MAP.topRight,
  25. POSITION_MAP.topLeft
  26. ];
  27. let NzDropDownDirective = (() => {
  28. let _nzBackdrop_decorators;
  29. let _nzBackdrop_initializers = [];
  30. let _nzBackdrop_extraInitializers = [];
  31. return class NzDropDownDirective {
  32. static {
  33. const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
  34. _nzBackdrop_decorators = [WithConfig()];
  35. __esDecorate(null, null, _nzBackdrop_decorators, { kind: "field", name: "nzBackdrop", static: false, private: false, access: { has: obj => "nzBackdrop" in obj, get: obj => obj.nzBackdrop, set: (obj, value) => { obj.nzBackdrop = value; } }, metadata: _metadata }, _nzBackdrop_initializers, _nzBackdrop_extraInitializers);
  36. if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
  37. }
  38. nzConfigService;
  39. renderer;
  40. viewContainerRef;
  41. platform;
  42. _nzModuleName = NZ_CONFIG_MODULE_NAME;
  43. elementRef = inject(ElementRef);
  44. overlay = inject(Overlay);
  45. portal;
  46. overlayRef = null;
  47. destroy$ = new Subject();
  48. positionStrategy = this.overlay
  49. .position()
  50. .flexibleConnectedTo(this.elementRef.nativeElement)
  51. .withLockedPosition()
  52. .withTransformOriginOn('.ant-dropdown');
  53. inputVisible$ = new BehaviorSubject(false);
  54. nzTrigger$ = new BehaviorSubject('hover');
  55. overlayClose$ = new Subject();
  56. nzDropdownMenu = null;
  57. nzTrigger = 'hover';
  58. nzMatchWidthElement = null;
  59. nzBackdrop = __runInitializers(this, _nzBackdrop_initializers, false);
  60. nzClickHide = (__runInitializers(this, _nzBackdrop_extraInitializers), true);
  61. nzDisabled = false;
  62. nzVisible = false;
  63. nzOverlayClassName = '';
  64. nzOverlayStyle = {};
  65. nzPlacement = 'bottomLeft';
  66. nzVisibleChange = new EventEmitter();
  67. setDropdownMenuValue(key, value) {
  68. if (this.nzDropdownMenu) {
  69. this.nzDropdownMenu.setValue(key, value);
  70. }
  71. }
  72. constructor(nzConfigService, renderer, viewContainerRef, platform) {
  73. this.nzConfigService = nzConfigService;
  74. this.renderer = renderer;
  75. this.viewContainerRef = viewContainerRef;
  76. this.platform = platform;
  77. }
  78. ngAfterViewInit() {
  79. if (this.nzDropdownMenu) {
  80. const nativeElement = this.elementRef.nativeElement;
  81. /** host mouse state **/
  82. const hostMouseState$ = merge(fromEvent(nativeElement, 'mouseenter').pipe(map(() => true)), fromEvent(nativeElement, 'mouseleave').pipe(map(() => false)));
  83. /** menu mouse state **/
  84. const menuMouseState$ = this.nzDropdownMenu.mouseState$;
  85. /** merged mouse state **/
  86. const mergedMouseState$ = merge(menuMouseState$, hostMouseState$);
  87. /** host click state **/
  88. const hostClickState$ = fromEvent(nativeElement, 'click').pipe(map(() => !this.nzVisible));
  89. /** visible state switch by nzTrigger **/
  90. const visibleStateByTrigger$ = this.nzTrigger$.pipe(switchMap(trigger => {
  91. if (trigger === 'hover') {
  92. return mergedMouseState$;
  93. }
  94. else if (trigger === 'click') {
  95. return hostClickState$;
  96. }
  97. else {
  98. return EMPTY;
  99. }
  100. }));
  101. const descendantMenuItemClick$ = this.nzDropdownMenu.descendantMenuItemClick$.pipe(filter(() => this.nzClickHide), map(() => false));
  102. const domTriggerVisible$ = merge(visibleStateByTrigger$, descendantMenuItemClick$, this.overlayClose$).pipe(filter(() => !this.nzDisabled));
  103. const visible$ = merge(this.inputVisible$, domTriggerVisible$);
  104. combineLatest([visible$, this.nzDropdownMenu.isChildSubMenuOpen$])
  105. .pipe(map(([visible, sub]) => visible || sub), auditTime(150), distinctUntilChanged(), filter(() => this.platform.isBrowser), takeUntil(this.destroy$))
  106. .subscribe((visible) => {
  107. const element = this.nzMatchWidthElement ? this.nzMatchWidthElement.nativeElement : nativeElement;
  108. const triggerWidth = element.getBoundingClientRect().width;
  109. if (this.nzVisible !== visible) {
  110. this.nzVisibleChange.emit(visible);
  111. }
  112. this.nzVisible = visible;
  113. if (visible) {
  114. /** set up overlayRef **/
  115. if (!this.overlayRef) {
  116. /** new overlay **/
  117. this.overlayRef = this.overlay.create({
  118. positionStrategy: this.positionStrategy,
  119. minWidth: triggerWidth,
  120. disposeOnNavigation: true,
  121. hasBackdrop: this.nzBackdrop && this.nzTrigger === 'click',
  122. scrollStrategy: this.overlay.scrollStrategies.reposition()
  123. });
  124. merge(this.overlayRef.backdropClick(), this.overlayRef.detachments(), this.overlayRef
  125. .outsidePointerEvents()
  126. .pipe(filter((e) => !this.elementRef.nativeElement.contains(e.target))), this.overlayRef.keydownEvents().pipe(filter(e => e.keyCode === ESCAPE && !hasModifierKey(e))))
  127. .pipe(takeUntil(this.destroy$))
  128. .subscribe(() => {
  129. this.overlayClose$.next(false);
  130. });
  131. }
  132. else {
  133. /** update overlay config **/
  134. const overlayConfig = this.overlayRef.getConfig();
  135. overlayConfig.minWidth = triggerWidth;
  136. }
  137. /** open dropdown with animation **/
  138. this.positionStrategy.withPositions([POSITION_MAP[this.nzPlacement], ...listOfPositions]);
  139. /** reset portal if needed **/
  140. if (!this.portal || this.portal.templateRef !== this.nzDropdownMenu.templateRef) {
  141. this.portal = new TemplatePortal(this.nzDropdownMenu.templateRef, this.viewContainerRef);
  142. }
  143. this.overlayRef.attach(this.portal);
  144. }
  145. else {
  146. /** detach overlayRef if needed **/
  147. if (this.overlayRef) {
  148. this.overlayRef.detach();
  149. }
  150. }
  151. });
  152. this.nzDropdownMenu.animationStateChange$.pipe(takeUntil(this.destroy$)).subscribe(event => {
  153. if (event.toState === 'void') {
  154. if (this.overlayRef) {
  155. this.overlayRef.dispose();
  156. }
  157. this.overlayRef = null;
  158. }
  159. });
  160. }
  161. }
  162. ngOnDestroy() {
  163. this.destroy$.next(true);
  164. this.destroy$.complete();
  165. if (this.overlayRef) {
  166. this.overlayRef.dispose();
  167. this.overlayRef = null;
  168. }
  169. }
  170. ngOnChanges(changes) {
  171. const { nzVisible, nzDisabled, nzOverlayClassName, nzOverlayStyle, nzTrigger } = changes;
  172. if (nzTrigger) {
  173. this.nzTrigger$.next(this.nzTrigger);
  174. }
  175. if (nzVisible) {
  176. this.inputVisible$.next(this.nzVisible);
  177. }
  178. if (nzDisabled) {
  179. const nativeElement = this.elementRef.nativeElement;
  180. if (this.nzDisabled) {
  181. this.renderer.setAttribute(nativeElement, 'disabled', '');
  182. this.inputVisible$.next(false);
  183. }
  184. else {
  185. this.renderer.removeAttribute(nativeElement, 'disabled');
  186. }
  187. }
  188. if (nzOverlayClassName) {
  189. this.setDropdownMenuValue('nzOverlayClassName', this.nzOverlayClassName);
  190. }
  191. if (nzOverlayStyle) {
  192. this.setDropdownMenuValue('nzOverlayStyle', this.nzOverlayStyle);
  193. }
  194. }
  195. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzDropDownDirective, deps: [{ token: i1.NzConfigService }, { token: i0.Renderer2 }, { token: i0.ViewContainerRef }, { token: i2.Platform }], target: i0.ɵɵFactoryTarget.Directive });
  196. static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "16.1.0", version: "19.2.2", type: NzDropDownDirective, isStandalone: true, selector: "[nz-dropdown]", inputs: { nzDropdownMenu: "nzDropdownMenu", nzTrigger: "nzTrigger", nzMatchWidthElement: "nzMatchWidthElement", nzBackdrop: ["nzBackdrop", "nzBackdrop", booleanAttribute], nzClickHide: ["nzClickHide", "nzClickHide", booleanAttribute], nzDisabled: ["nzDisabled", "nzDisabled", booleanAttribute], nzVisible: ["nzVisible", "nzVisible", booleanAttribute], nzOverlayClassName: "nzOverlayClassName", nzOverlayStyle: "nzOverlayStyle", nzPlacement: "nzPlacement" }, outputs: { nzVisibleChange: "nzVisibleChange" }, host: { classAttribute: "ant-dropdown-trigger" }, exportAs: ["nzDropdown"], usesOnChanges: true, ngImport: i0 });
  197. };
  198. })();
  199. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzDropDownDirective, decorators: [{
  200. type: Directive,
  201. args: [{
  202. selector: '[nz-dropdown]',
  203. exportAs: 'nzDropdown',
  204. host: {
  205. class: 'ant-dropdown-trigger'
  206. }
  207. }]
  208. }], ctorParameters: () => [{ type: i1.NzConfigService }, { type: i0.Renderer2 }, { type: i0.ViewContainerRef }, { type: i2.Platform }], propDecorators: { nzDropdownMenu: [{
  209. type: Input
  210. }], nzTrigger: [{
  211. type: Input
  212. }], nzMatchWidthElement: [{
  213. type: Input
  214. }], nzBackdrop: [{
  215. type: Input,
  216. args: [{ transform: booleanAttribute }]
  217. }], nzClickHide: [{
  218. type: Input,
  219. args: [{ transform: booleanAttribute }]
  220. }], nzDisabled: [{
  221. type: Input,
  222. args: [{ transform: booleanAttribute }]
  223. }], nzVisible: [{
  224. type: Input,
  225. args: [{ transform: booleanAttribute }]
  226. }], nzOverlayClassName: [{
  227. type: Input
  228. }], nzOverlayStyle: [{
  229. type: Input
  230. }], nzPlacement: [{
  231. type: Input
  232. }], nzVisibleChange: [{
  233. type: Output
  234. }] } });
  235. /**
  236. * Use of this source code is governed by an MIT-style license that can be
  237. * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
  238. */
  239. class NzContextMenuServiceModule {
  240. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzContextMenuServiceModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
  241. static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.2.2", ngImport: i0, type: NzContextMenuServiceModule });
  242. static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzContextMenuServiceModule });
  243. }
  244. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzContextMenuServiceModule, decorators: [{
  245. type: NgModule
  246. }] });
  247. /**
  248. * Use of this source code is governed by an MIT-style license that can be
  249. * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
  250. */
  251. class NzDropDownADirective {
  252. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzDropDownADirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
  253. static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.2", type: NzDropDownADirective, isStandalone: true, selector: "a[nz-dropdown]", host: { classAttribute: "ant-dropdown-link" }, ngImport: i0 });
  254. }
  255. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzDropDownADirective, decorators: [{
  256. type: Directive,
  257. args: [{
  258. selector: 'a[nz-dropdown]',
  259. host: {
  260. class: 'ant-dropdown-link'
  261. }
  262. }]
  263. }] });
  264. /**
  265. * Use of this source code is governed by an MIT-style license that can be
  266. * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
  267. */
  268. class NzDropdownButtonDirective {
  269. renderer;
  270. elementRef;
  271. nzButtonGroupComponent = inject(NzButtonGroupComponent, { host: true, optional: true });
  272. constructor(renderer, elementRef) {
  273. this.renderer = renderer;
  274. this.elementRef = elementRef;
  275. }
  276. ngAfterViewInit() {
  277. const parentElement = this.renderer.parentNode(this.elementRef.nativeElement);
  278. if (this.nzButtonGroupComponent && parentElement) {
  279. this.renderer.addClass(parentElement, 'ant-dropdown-button');
  280. }
  281. }
  282. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzDropdownButtonDirective, deps: [{ token: i0.Renderer2 }, { token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Directive });
  283. static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.2", type: NzDropdownButtonDirective, isStandalone: true, selector: "[nz-button][nz-dropdown]", ngImport: i0 });
  284. }
  285. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzDropdownButtonDirective, decorators: [{
  286. type: Directive,
  287. args: [{
  288. selector: '[nz-button][nz-dropdown]'
  289. }]
  290. }], ctorParameters: () => [{ type: i0.Renderer2 }, { type: i0.ElementRef }] });
  291. class NzDropdownMenuComponent {
  292. cdr;
  293. elementRef;
  294. renderer;
  295. viewContainerRef;
  296. directionality;
  297. mouseState$ = new BehaviorSubject(false);
  298. nzMenuService = inject(MenuService);
  299. isChildSubMenuOpen$ = this.nzMenuService.isChildSubMenuOpen$;
  300. descendantMenuItemClick$ = this.nzMenuService.descendantMenuItemClick$;
  301. animationStateChange$ = new EventEmitter();
  302. nzOverlayClassName = '';
  303. nzOverlayStyle = {};
  304. templateRef;
  305. dir = 'ltr';
  306. destroy$ = new Subject();
  307. onAnimationEvent(event) {
  308. this.animationStateChange$.emit(event);
  309. }
  310. setMouseState(visible) {
  311. this.mouseState$.next(visible);
  312. }
  313. setValue(key, value) {
  314. this[key] = value;
  315. this.cdr.markForCheck();
  316. }
  317. noAnimation = inject(NzNoAnimationDirective, { host: true, optional: true });
  318. constructor(cdr, elementRef, renderer, viewContainerRef, directionality) {
  319. this.cdr = cdr;
  320. this.elementRef = elementRef;
  321. this.renderer = renderer;
  322. this.viewContainerRef = viewContainerRef;
  323. this.directionality = directionality;
  324. }
  325. ngOnInit() {
  326. this.directionality.change?.pipe(takeUntil(this.destroy$)).subscribe((direction) => {
  327. this.dir = direction;
  328. this.cdr.detectChanges();
  329. });
  330. this.dir = this.directionality.value;
  331. }
  332. ngAfterContentInit() {
  333. this.renderer.removeChild(this.renderer.parentNode(this.elementRef.nativeElement), this.elementRef.nativeElement);
  334. }
  335. ngOnDestroy() {
  336. this.destroy$.next();
  337. this.destroy$.complete();
  338. }
  339. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzDropdownMenuComponent, deps: [{ token: i0.ChangeDetectorRef }, { token: i0.ElementRef }, { token: i0.Renderer2 }, { token: i0.ViewContainerRef }, { token: i1$1.Directionality }], target: i0.ɵɵFactoryTarget.Component });
  340. static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.2", type: NzDropdownMenuComponent, isStandalone: true, selector: "nz-dropdown-menu", providers: [
  341. MenuService,
  342. /** menu is inside dropdown-menu component **/
  343. {
  344. provide: NzIsMenuInsideDropDownToken,
  345. useValue: true
  346. }
  347. ], viewQueries: [{ propertyName: "templateRef", first: true, predicate: TemplateRef, descendants: true, static: true }], exportAs: ["nzDropdownMenu"], ngImport: i0, template: `
  348. <ng-template>
  349. <div
  350. class="ant-dropdown"
  351. [class.ant-dropdown-rtl]="dir === 'rtl'"
  352. [class]="nzOverlayClassName"
  353. [style]="nzOverlayStyle"
  354. @slideMotion
  355. (@slideMotion.done)="onAnimationEvent($event)"
  356. [@.disabled]="!!noAnimation?.nzNoAnimation"
  357. [nzNoAnimation]="noAnimation?.nzNoAnimation"
  358. (mouseenter)="setMouseState(true)"
  359. (mouseleave)="setMouseState(false)"
  360. >
  361. <ng-content></ng-content>
  362. </div>
  363. </ng-template>
  364. `, isInline: true, dependencies: [{ kind: "directive", type: NzNoAnimationDirective, selector: "[nzNoAnimation]", inputs: ["nzNoAnimation"], exportAs: ["nzNoAnimation"] }], animations: [slideMotion], changeDetection: i0.ChangeDetectionStrategy.OnPush, encapsulation: i0.ViewEncapsulation.None });
  365. }
  366. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzDropdownMenuComponent, decorators: [{
  367. type: Component,
  368. args: [{
  369. selector: `nz-dropdown-menu`,
  370. exportAs: `nzDropdownMenu`,
  371. animations: [slideMotion],
  372. providers: [
  373. MenuService,
  374. /** menu is inside dropdown-menu component **/
  375. {
  376. provide: NzIsMenuInsideDropDownToken,
  377. useValue: true
  378. }
  379. ],
  380. template: `
  381. <ng-template>
  382. <div
  383. class="ant-dropdown"
  384. [class.ant-dropdown-rtl]="dir === 'rtl'"
  385. [class]="nzOverlayClassName"
  386. [style]="nzOverlayStyle"
  387. @slideMotion
  388. (@slideMotion.done)="onAnimationEvent($event)"
  389. [@.disabled]="!!noAnimation?.nzNoAnimation"
  390. [nzNoAnimation]="noAnimation?.nzNoAnimation"
  391. (mouseenter)="setMouseState(true)"
  392. (mouseleave)="setMouseState(false)"
  393. >
  394. <ng-content></ng-content>
  395. </div>
  396. </ng-template>
  397. `,
  398. preserveWhitespaces: false,
  399. encapsulation: ViewEncapsulation.None,
  400. changeDetection: ChangeDetectionStrategy.OnPush,
  401. imports: [NzNoAnimationDirective]
  402. }]
  403. }], ctorParameters: () => [{ type: i0.ChangeDetectorRef }, { type: i0.ElementRef }, { type: i0.Renderer2 }, { type: i0.ViewContainerRef }, { type: i1$1.Directionality }], propDecorators: { templateRef: [{
  404. type: ViewChild,
  405. args: [TemplateRef, { static: true }]
  406. }] } });
  407. /**
  408. * Use of this source code is governed by an MIT-style license that can be
  409. * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
  410. */
  411. class NzDropDownModule {
  412. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzDropDownModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
  413. static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.2.2", ngImport: i0, type: NzDropDownModule, imports: [NzDropDownDirective,
  414. NzDropDownADirective,
  415. NzDropdownMenuComponent,
  416. NzDropdownButtonDirective,
  417. NzContextMenuServiceModule], exports: [NzMenuModule, NzDropDownDirective, NzDropDownADirective, NzDropdownMenuComponent, NzDropdownButtonDirective] });
  418. static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzDropDownModule, imports: [NzContextMenuServiceModule, NzMenuModule] });
  419. }
  420. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzDropDownModule, decorators: [{
  421. type: NgModule,
  422. args: [{
  423. imports: [
  424. NzDropDownDirective,
  425. NzDropDownADirective,
  426. NzDropdownMenuComponent,
  427. NzDropdownButtonDirective,
  428. NzContextMenuServiceModule
  429. ],
  430. exports: [NzMenuModule, NzDropDownDirective, NzDropDownADirective, NzDropdownMenuComponent, NzDropdownButtonDirective]
  431. }]
  432. }] });
  433. /**
  434. * Use of this source code is governed by an MIT-style license that can be
  435. * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
  436. */
  437. const LIST_OF_POSITIONS = [
  438. new ConnectionPositionPair({ originX: 'start', originY: 'top' }, { overlayX: 'start', overlayY: 'top' }),
  439. new ConnectionPositionPair({ originX: 'start', originY: 'top' }, { overlayX: 'start', overlayY: 'bottom' }),
  440. new ConnectionPositionPair({ originX: 'start', originY: 'top' }, { overlayX: 'end', overlayY: 'bottom' }),
  441. new ConnectionPositionPair({ originX: 'start', originY: 'top' }, { overlayX: 'end', overlayY: 'top' })
  442. ];
  443. class NzContextMenuService {
  444. ngZone;
  445. overlay;
  446. overlayRef = null;
  447. closeSubscription = Subscription.EMPTY;
  448. constructor(ngZone, overlay) {
  449. this.ngZone = ngZone;
  450. this.overlay = overlay;
  451. }
  452. create($event, nzDropdownMenuComponent) {
  453. this.close(true);
  454. const { x, y } = $event;
  455. if ($event instanceof MouseEvent) {
  456. $event.preventDefault();
  457. }
  458. const positionStrategy = this.overlay
  459. .position()
  460. .flexibleConnectedTo({ x, y })
  461. .withPositions(LIST_OF_POSITIONS)
  462. .withTransformOriginOn('.ant-dropdown');
  463. this.overlayRef = this.overlay.create({
  464. positionStrategy,
  465. disposeOnNavigation: true,
  466. scrollStrategy: this.overlay.scrollStrategies.close()
  467. });
  468. this.closeSubscription = new Subscription();
  469. this.closeSubscription.add(nzDropdownMenuComponent.descendantMenuItemClick$.subscribe(() => this.close()));
  470. this.closeSubscription.add(merge(fromEventOutsideAngular(document, 'click').pipe(filter(event => !!this.overlayRef && !this.overlayRef.overlayElement.contains(event.target)),
  471. /** handle firefox contextmenu event **/
  472. filter(event => event.button !== 2)), fromEventOutsideAngular(document, 'keydown').pipe(filter(event => event.key === 'Escape')))
  473. .pipe(first())
  474. .subscribe(() => this.ngZone.run(() => this.close())));
  475. return this.overlayRef.attach(new TemplatePortal(nzDropdownMenuComponent.templateRef, nzDropdownMenuComponent.viewContainerRef));
  476. }
  477. close(clear = false) {
  478. if (this.overlayRef) {
  479. this.overlayRef.detach();
  480. if (clear) {
  481. this.overlayRef.dispose();
  482. }
  483. this.overlayRef = null;
  484. this.closeSubscription.unsubscribe();
  485. }
  486. }
  487. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzContextMenuService, deps: [{ token: i0.NgZone }, { token: i1$2.Overlay }], target: i0.ɵɵFactoryTarget.Injectable });
  488. static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzContextMenuService, providedIn: NzContextMenuServiceModule });
  489. }
  490. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzContextMenuService, decorators: [{
  491. type: Injectable,
  492. args: [{
  493. providedIn: NzContextMenuServiceModule
  494. }]
  495. }], ctorParameters: () => [{ type: i0.NgZone }, { type: i1$2.Overlay }] });
  496. /**
  497. * Use of this source code is governed by an MIT-style license that can be
  498. * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
  499. */
  500. /**
  501. * Generated bundle index. Do not edit.
  502. */
  503. export { NzContextMenuService, NzContextMenuServiceModule, NzDropDownADirective, NzDropDownDirective, NzDropDownModule, NzDropdownButtonDirective, NzDropdownMenuComponent };
  504. //# sourceMappingURL=ng-zorro-antd-dropdown.mjs.map