ng-zorro-antd
Version:
An enterprise-class UI components based on Ant Design and Angular
1 lines • 15.7 kB
Source Map (JSON)
{"version":3,"file":"ng-zorro-antd-core-overlay.mjs","names":[],"sources":["../../components/core/overlay/overlay-position.ts","../../components/core/overlay/nz-connected-overlay.ts","../../components/core/overlay/nz-overlay.module.ts","../../components/core/overlay/overlay-z-index.ts"],"sourcesContent":["/**\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE\n */\n\nimport { ConnectedOverlayPositionChange, ConnectionPositionPair } from '@angular/cdk/overlay';\n\nexport const POSITION_MAP = {\n top: new ConnectionPositionPair({ originX: 'center', originY: 'top' }, { overlayX: 'center', overlayY: 'bottom' }),\n topCenter: new ConnectionPositionPair(\n { originX: 'center', originY: 'top' },\n { overlayX: 'center', overlayY: 'bottom' }\n ),\n topLeft: new ConnectionPositionPair({ originX: 'start', originY: 'top' }, { overlayX: 'start', overlayY: 'bottom' }),\n topRight: new ConnectionPositionPair({ originX: 'end', originY: 'top' }, { overlayX: 'end', overlayY: 'bottom' }),\n right: new ConnectionPositionPair({ originX: 'end', originY: 'center' }, { overlayX: 'start', overlayY: 'center' }),\n rightTop: new ConnectionPositionPair({ originX: 'end', originY: 'top' }, { overlayX: 'start', overlayY: 'top' }),\n rightBottom: new ConnectionPositionPair(\n { originX: 'end', originY: 'bottom' },\n { overlayX: 'start', overlayY: 'bottom' }\n ),\n bottom: new ConnectionPositionPair({ originX: 'center', originY: 'bottom' }, { overlayX: 'center', overlayY: 'top' }),\n bottomCenter: new ConnectionPositionPair(\n { originX: 'center', originY: 'bottom' },\n { overlayX: 'center', overlayY: 'top' }\n ),\n bottomLeft: new ConnectionPositionPair(\n { originX: 'start', originY: 'bottom' },\n { overlayX: 'start', overlayY: 'top' }\n ),\n bottomRight: new ConnectionPositionPair({ originX: 'end', originY: 'bottom' }, { overlayX: 'end', overlayY: 'top' }),\n left: new ConnectionPositionPair({ originX: 'start', originY: 'center' }, { overlayX: 'end', overlayY: 'center' }),\n leftTop: new ConnectionPositionPair({ originX: 'start', originY: 'top' }, { overlayX: 'end', overlayY: 'top' }),\n leftBottom: new ConnectionPositionPair(\n { originX: 'start', originY: 'bottom' },\n { overlayX: 'end', overlayY: 'bottom' }\n )\n};\nexport type POSITION_TYPE = keyof typeof POSITION_MAP;\nexport type POSITION_TYPE_HORIZONTAL = Extract<\n POSITION_TYPE,\n 'bottomLeft' | 'bottomCenter' | 'bottomRight' | 'topLeft' | 'topCenter' | 'topRight'\n>;\n\n/**\n * @internal\n * @param offset offset in pixels which should not be less than 0.\n * The default value is `12`, which means `(arrow-size / 2) + 4`\n */\nconst positionOffsetMapFactory = (offset: number = 12): Record<string, [number, number]> => ({\n top: [0, -offset],\n topCenter: [0, -offset],\n topLeft: [0, -offset],\n topRight: [0, -offset],\n right: [offset, 0],\n rightTop: [offset, 0],\n rightBottom: [offset, 0],\n bottom: [0, offset],\n bottomCenter: [0, offset],\n bottomLeft: [0, offset],\n bottomRight: [0, offset],\n left: [-offset, 0],\n leftTop: [-offset, 0],\n leftBottom: [-offset, 0]\n});\n\nexport const TOOLTIP_OFFSET_MAP = positionOffsetMapFactory();\n\nexport const DEFAULT_TOOLTIP_POSITIONS = [\n setConnectedPositionOffset(POSITION_MAP.top, TOOLTIP_OFFSET_MAP.top),\n setConnectedPositionOffset(POSITION_MAP.right, TOOLTIP_OFFSET_MAP.right),\n setConnectedPositionOffset(POSITION_MAP.bottom, TOOLTIP_OFFSET_MAP.bottom),\n setConnectedPositionOffset(POSITION_MAP.left, TOOLTIP_OFFSET_MAP.left)\n];\n\nexport const DEFAULT_CASCADER_POSITIONS = [\n POSITION_MAP.bottomLeft,\n POSITION_MAP.bottomRight,\n POSITION_MAP.topLeft,\n POSITION_MAP.topRight\n];\n\nexport const DEFAULT_MENTION_TOP_POSITIONS = [\n new ConnectionPositionPair({ originX: 'start', originY: 'bottom' }, { overlayX: 'start', overlayY: 'bottom' }),\n new ConnectionPositionPair({ originX: 'start', originY: 'bottom' }, { overlayX: 'end', overlayY: 'bottom' })\n];\n\nexport const DEFAULT_MENTION_BOTTOM_POSITIONS = [\n POSITION_MAP.bottomLeft,\n new ConnectionPositionPair({ originX: 'start', originY: 'bottom' }, { overlayX: 'end', overlayY: 'top' })\n];\n\nexport function getPlacementName(position: ConnectedOverlayPositionChange): string | undefined {\n for (const placement in POSITION_MAP) {\n if (\n position.connectionPair.originX === POSITION_MAP[placement as POSITION_TYPE].originX &&\n position.connectionPair.originY === POSITION_MAP[placement as POSITION_TYPE].originY &&\n position.connectionPair.overlayX === POSITION_MAP[placement as POSITION_TYPE].overlayX &&\n position.connectionPair.overlayY === POSITION_MAP[placement as POSITION_TYPE].overlayY\n ) {\n return placement;\n }\n }\n return undefined;\n}\n\nexport const DATE_PICKER_POSITION_MAP = {\n bottomLeft: new ConnectionPositionPair(\n { originX: 'start', originY: 'bottom' },\n { overlayX: 'start', overlayY: 'top' },\n undefined,\n 2\n ),\n topLeft: new ConnectionPositionPair(\n { originX: 'start', originY: 'top' },\n { overlayX: 'start', overlayY: 'bottom' },\n undefined,\n -2\n ),\n bottomRight: new ConnectionPositionPair(\n { originX: 'end', originY: 'bottom' },\n { overlayX: 'end', overlayY: 'top' },\n undefined,\n 2\n ),\n topRight: new ConnectionPositionPair(\n { originX: 'end', originY: 'top' },\n { overlayX: 'end', overlayY: 'bottom' },\n undefined,\n -2\n )\n};\n\nexport const DEFAULT_DATE_PICKER_POSITIONS = [\n DATE_PICKER_POSITION_MAP.bottomLeft,\n DATE_PICKER_POSITION_MAP.topLeft,\n DATE_PICKER_POSITION_MAP.bottomRight,\n DATE_PICKER_POSITION_MAP.topRight\n];\n\nexport function normalizeConnectedPositionOffset(offset: number | [number, number]): [number, number] {\n return Array.isArray(offset) ? offset : [offset, offset];\n}\n\nexport function setConnectedPositionOffset(\n position: ConnectionPositionPair,\n offset: number | [number, number]\n): ConnectionPositionPair {\n const [offsetX, offsetY] = normalizeConnectedPositionOffset(offset);\n // return new object\n return {\n ...position,\n offsetX: offsetX,\n offsetY: offsetY\n };\n}\n","/**\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE\n */\n\nimport {\n CdkConnectedOverlay,\n CdkOverlayOrigin,\n ConnectedOverlayPositionChange,\n FlexibleConnectedPositionStrategyOrigin\n} from '@angular/cdk/overlay';\nimport { Directive, ElementRef, Input, booleanAttribute, inject } from '@angular/core';\nimport { takeUntilDestroyed } from '@angular/core/rxjs-interop';\n\nimport { getPlacementName } from './overlay-position';\n\n/** Equivalent of `DOMRect` without some of the properties we don't care about. */\ntype Dimensions = Omit<DOMRect, 'x' | 'y' | 'toJSON'>;\n\n@Directive({\n selector: '[cdkConnectedOverlay][nzConnectedOverlay]',\n exportAs: 'nzConnectedOverlay'\n})\nexport class NzConnectedOverlayDirective {\n private readonly cdkConnectedOverlay = inject(CdkConnectedOverlay);\n @Input({ transform: booleanAttribute }) nzArrowPointAtCenter: boolean = false;\n\n constructor() {\n this.cdkConnectedOverlay.backdropClass = 'nz-overlay-transparent-backdrop';\n\n this.cdkConnectedOverlay.positionChange.pipe(takeUntilDestroyed()).subscribe(position => {\n if (this.nzArrowPointAtCenter) {\n this.updateArrowPosition(position);\n }\n });\n }\n\n private updateArrowPosition(position: ConnectedOverlayPositionChange): void {\n const originRect = this.getOriginRect();\n const placement = getPlacementName(position);\n\n let offsetX: number | undefined = 0;\n let offsetY: number | undefined = 0;\n\n if (placement === 'topLeft' || placement === 'bottomLeft') {\n offsetX = originRect.width / 2 - 14;\n } else if (placement === 'topRight' || placement === 'bottomRight') {\n offsetX = -(originRect.width / 2 - 14);\n } else if (placement === 'leftTop' || placement === 'rightTop') {\n offsetY = originRect.height / 2 - 10;\n } else if (placement === 'leftBottom' || placement === 'rightBottom') {\n offsetY = -(originRect.height / 2 - 10);\n }\n\n if (this.cdkConnectedOverlay.offsetX !== offsetX || this.cdkConnectedOverlay.offsetY !== offsetY) {\n this.cdkConnectedOverlay.offsetY = offsetY;\n this.cdkConnectedOverlay.offsetX = offsetX;\n this.cdkConnectedOverlay.overlayRef.updatePosition();\n }\n }\n\n private getFlexibleConnectedPositionStrategyOrigin(): FlexibleConnectedPositionStrategyOrigin {\n if (this.cdkConnectedOverlay.origin instanceof CdkOverlayOrigin) {\n return this.cdkConnectedOverlay.origin.elementRef;\n } else {\n return this.cdkConnectedOverlay.origin;\n }\n }\n\n private getOriginRect(): Dimensions {\n const origin = this.getFlexibleConnectedPositionStrategyOrigin();\n\n if (origin instanceof ElementRef) {\n return origin.nativeElement.getBoundingClientRect();\n }\n\n // Check for Element so SVG elements are also supported.\n if (origin instanceof Element) {\n return origin.getBoundingClientRect();\n }\n\n const width = origin.width || 0;\n const height = origin.height || 0;\n\n // If the origin is a point, return a client rect as if it was a 0x0 element at the point.\n return {\n top: origin.y,\n bottom: origin.y + height,\n left: origin.x,\n right: origin.x + width,\n height,\n width\n };\n }\n}\n","/**\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE\n */\n\nimport { NgModule } from '@angular/core';\n\nimport { NzConnectedOverlayDirective } from './nz-connected-overlay';\n\n@NgModule({\n imports: [NzConnectedOverlayDirective],\n exports: [NzConnectedOverlayDirective]\n})\nexport class NzOverlayModule {}\n","/**\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE\n */\n\nimport { OverlayRef } from '@angular/cdk/overlay';\n\nexport function overlayZIndexSetter(overlayRef: OverlayRef, zIndex?: number): void {\n (overlayRef['_host'] as HTMLElement).style.zIndex = zIndex === undefined ? '' : `${zIndex}`;\n}\n"],"mappings":";;;;AAOA,MAAa,eAAe;CAC1B,KAAK,IAAI,uBAAuB;EAAE,SAAS;EAAU,SAAS;CAAK,GAAI;EAAE,UAAU;EAAU,UAAU;CAAQ,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