UNPKG

ng-zorro-antd

Version:

An enterprise-class UI components based on Ant Design and Angular

521 lines (520 loc) • 15.4 kB
import { Directionality } from "@angular/cdk/bidi"; import * as i0 from "@angular/core"; import { ChangeDetectorRef, Component, ContentChildren, DestroyRef, Directive, ElementRef, InjectionToken, Input, NgModule, TemplateRef, afterNextRender, booleanAttribute, computed, inject, input, signal } from "@angular/core"; import { NZ_FORM_SIZE } from "ng-zorro-antd/core/form"; import { __esDecorate, __runInitializers } from "tslib"; import { NgTemplateOutlet } from "@angular/common"; import { takeUntilDestroyed } from "@angular/core/rxjs-interop"; import { WithConfig } from "ng-zorro-antd/core/config"; import { NzStringTemplateOutletDirective } from "ng-zorro-antd/core/outlet"; const NZ_SPACE_COMPACT_SIZE = new InjectionToken(typeof ngDevMode !== "undefined" && ngDevMode ? "nz-space-compact-size" : ""); const NZ_SPACE_COMPACT_ITEMS = new InjectionToken(typeof ngDevMode !== "undefined" && ngDevMode ? "nz-space-compact-items" : ""); const NZ_SPACE_COMPACT_ITEM_TYPE = new InjectionToken(typeof ngDevMode !== "undefined" && ngDevMode ? "nz-space-compact-item-type" : ""); var NzSpaceCompactComponent = class NzSpaceCompactComponent { dir = inject(Directionality).valueSignal; formSize = inject(NZ_FORM_SIZE, { optional: true }); elementRef = inject(ElementRef); nzBlock = input(false, { ...ngDevMode ? { debugName: "nzBlock" } : /* istanbul ignore next */ {}, transform: booleanAttribute }); nzDirection = input("horizontal", ...ngDevMode ? [{ debugName: "nzDirection" }] : /* istanbul ignore next */ []); nzSize = input("default", ...ngDevMode ? [{ debugName: "nzSize" }] : /* istanbul ignore next */ []); finalSize = computed(() => this.formSize?.() || this.nzSize(), ...ngDevMode ? [{ debugName: "finalSize" }] : /* istanbul ignore next */ []); static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzSpaceCompactComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "22.2.2", type: NzSpaceCompactComponent, isStandalone: true, selector: "nz-space-compact", inputs: { nzBlock: { classPropertyName: "nzBlock", publicName: "nzBlock", isSignal: true, isRequired: false, transformFunction: null }, nzDirection: { classPropertyName: "nzDirection", publicName: "nzDirection", isSignal: true, isRequired: false, transformFunction: null }, nzSize: { classPropertyName: "nzSize", publicName: "nzSize", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "class.ant-space-compact-rtl": "dir() === 'rtl'", "class.ant-space-compact-block": "nzBlock()", "class.ant-space-compact-vertical": "nzDirection() === 'vertical'" }, classAttribute: "ant-space-compact" }, providers: [{ provide: NZ_SPACE_COMPACT_SIZE, useFactory: () => inject(NzSpaceCompactComponent).finalSize }, { provide: NZ_SPACE_COMPACT_ITEMS, useFactory: () => signal([]) }], exportAs: ["nzSpaceCompact"], ngImport: i0, template: `<ng-content />`, isInline: true }); }; i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzSpaceCompactComponent, decorators: [{ type: Component, args: [{ selector: "nz-space-compact", exportAs: "nzSpaceCompact", template: `<ng-content />`, host: { class: "ant-space-compact", "[class.ant-space-compact-rtl]": `dir() === 'rtl'`, "[class.ant-space-compact-block]": `nzBlock()`, "[class.ant-space-compact-vertical]": `nzDirection() === 'vertical'` }, providers: [{ provide: NZ_SPACE_COMPACT_SIZE, useFactory: () => inject(NzSpaceCompactComponent).finalSize }, { provide: NZ_SPACE_COMPACT_ITEMS, useFactory: () => signal([]) }] }] }], propDecorators: { nzBlock: [{ type: i0.Input, args: [{ isSignal: true, alias: "nzBlock", required: false }] }], nzDirection: [{ type: i0.Input, args: [{ isSignal: true, alias: "nzDirection", required: false }] }], nzSize: [{ type: i0.Input, args: [{ isSignal: true, alias: "nzSize", required: false }] }] } }); var NzSpaceCompactItemDirective = class NzSpaceCompactItemDirective { spaceCompactCmp = inject(NzSpaceCompactComponent, { host: true, optional: true }); items = inject(NZ_SPACE_COMPACT_ITEMS, { host: true, optional: true }); type = inject(NZ_SPACE_COMPACT_ITEM_TYPE); elementRef = inject(ElementRef); dir = inject(Directionality).valueSignal; get parentElement() { return this.elementRef.nativeElement?.parentElement; } class = computed(() => { if (!this.spaceCompactCmp || !this.items) return null; if (this.parentElement !== this.spaceCompactCmp.elementRef.nativeElement) return null; const items = this.items(); const direction = this.spaceCompactCmp.nzDirection(); const classes = [compactItemClassOf(this.type, direction)]; if (this.dir() === "rtl") classes.push(compactItemRtlClassOf(this.type, direction)); const index = items.indexOf(this); if (index === items.findIndex((element) => element)) classes.push(compactFirstItemClassOf(this.type, direction)); if (index === items.length - 1) classes.push(compactLastItemClassOf(this.type, direction)); return classes; }, ...ngDevMode ? [{ debugName: "class" }] : /* istanbul ignore next */ []); constructor() { if (!this.spaceCompactCmp || !this.items) return; afterNextRender(() => { if (this.parentElement === this.spaceCompactCmp.elementRef.nativeElement) { const index = Array.from(this.parentElement.children).indexOf(this.elementRef.nativeElement); this.items.update((value) => { const newValue = value.slice(); newValue.splice(index, 0, this); return newValue; }); } }); inject(DestroyRef).onDestroy(() => { this.items?.update((value) => value.filter((o) => o !== this)); }); } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzSpaceCompactItemDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "22.2.2", type: NzSpaceCompactItemDirective, isStandalone: true, host: { properties: { "class": "class()" } }, exportAs: ["nzSpaceCompactItem"], ngImport: i0 }); }; i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzSpaceCompactItemDirective, decorators: [{ type: Directive, args: [{ exportAs: "nzSpaceCompactItem", host: { "[class]": "class()" } }] }], ctorParameters: () => [] }); function generateCompactClass(type, direction, position) { return `ant-${type}-compact-${direction === "vertical" ? "vertical-" : ""}${position}`; } function compactItemClassOf(type, direction) { return generateCompactClass(type, direction, "item"); } function compactItemRtlClassOf(type, direction) { return `${compactItemClassOf(type, direction)}-rtl`; } function compactFirstItemClassOf(type, direction) { return generateCompactClass(type, direction, "first-item"); } function compactLastItemClassOf(type, direction) { return generateCompactClass(type, direction, "last-item"); } var NzSpaceItemDirective = class NzSpaceItemDirective { static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzSpaceItemDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive }); static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "22.2.2", type: NzSpaceItemDirective, isStandalone: true, selector: "[nzSpaceItem]", ngImport: i0 }); }; i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzSpaceItemDirective, decorators: [{ type: Directive, args: [{ selector: "[nzSpaceItem]" }] }] }); const NZ_CONFIG_MODULE_NAME = "space"; const SPACE_SIZE = { small: 8, middle: 16, large: 24 }; let NzSpaceComponent = (() => { let _nzSize_decorators; let _nzSize_initializers = []; let _nzSize_extraInitializers = []; return class NzSpaceComponent { static { const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0; _nzSize_decorators = [WithConfig()]; __esDecorate(null, null, _nzSize_decorators, { kind: "field", name: "nzSize", static: false, private: false, access: { has: (obj) => "nzSize" in obj, get: (obj) => obj.nzSize, set: (obj, value) => { obj.nzSize = value; } }, metadata: _metadata }, _nzSize_initializers, _nzSize_extraInitializers); if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata }); } _nzModuleName = NZ_CONFIG_MODULE_NAME; dir = inject(Directionality).valueSignal; cdr = inject(ChangeDetectorRef); destroyRef = inject(DestroyRef); nzDirection = "horizontal"; nzAlign; nzSplit = null; nzWrap = false; nzSize = __runInitializers(this, _nzSize_initializers, "small"); items = __runInitializers(this, _nzSize_extraInitializers); mergedAlign; horizontalSize; verticalSize; constructor() { this.updateSpaceSize(); } ngOnChanges(changes) { const { nzSize } = changes; if (nzSize) this.updateSpaceSize(); this.mergedAlign = this.nzAlign === void 0 && this.nzDirection === "horizontal" ? "center" : this.nzAlign; } ngAfterContentInit() { this.items.changes.pipe(takeUntilDestroyed(this.destroyRef)).subscribe(() => { this.cdr.markForCheck(); }); } updateSpaceSize() { const { horizontalSize, verticalSize } = normalizeSpaceSize(this.nzSize); this.horizontalSize = horizontalSize; this.verticalSize = verticalSize; } static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzSpaceComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.2.2", type: NzSpaceComponent, isStandalone: true, selector: "nz-space, [nz-space]", inputs: { nzDirection: "nzDirection", nzAlign: "nzAlign", nzSplit: "nzSplit", nzWrap: [ "nzWrap", "nzWrap", booleanAttribute ], nzSize: "nzSize" }, host: { properties: { "class.ant-space-rtl": "dir() === 'rtl'", "class.ant-space-horizontal": "nzDirection === \"horizontal\"", "class.ant-space-vertical": "nzDirection === \"vertical\"", "class.ant-space-align-start": "mergedAlign === \"start\"", "class.ant-space-align-end": "mergedAlign === \"end\"", "class.ant-space-align-center": "mergedAlign === \"center\"", "class.ant-space-align-baseline": "mergedAlign === \"baseline\"", "style.flex-wrap": "nzWrap ? \"wrap\" : null", "style.column-gap.px": "horizontalSize", "style.row-gap.px": "verticalSize" }, classAttribute: "ant-space" }, queries: [{ propertyName: "items", predicate: NzSpaceItemDirective, read: TemplateRef }], exportAs: ["nzSpace"], usesOnChanges: true, ngImport: i0, template: ` <ng-content /> @for (item of items; track item) { <div class="ant-space-item"> <ng-container [ngTemplateOutlet]="item" /> </div> @if (nzSplit && !$last) { <span class="ant-space-split"> <ng-template [nzStringTemplateOutlet]="nzSplit" [nzStringTemplateOutletContext]="{ $implicit: $index }">{{ nzSplit }}</ng-template> </span> } } `, isInline: true, dependencies: [{ kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: [ "ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector" ] }, { kind: "directive", type: NzStringTemplateOutletDirective, selector: "[nzStringTemplateOutlet]", inputs: ["nzStringTemplateOutletContext", "nzStringTemplateOutlet"], exportAs: ["nzStringTemplateOutlet"] }] }); }; })(); i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzSpaceComponent, decorators: [{ type: Component, args: [{ selector: "nz-space, [nz-space]", exportAs: "nzSpace", template: ` <ng-content /> @for (item of items; track item) { <div class="ant-space-item"> <ng-container [ngTemplateOutlet]="item" /> </div> @if (nzSplit && !$last) { <span class="ant-space-split"> <ng-template [nzStringTemplateOutlet]="nzSplit" [nzStringTemplateOutletContext]="{ $implicit: $index }">{{ nzSplit }}</ng-template> </span> } } `, host: { class: "ant-space", "[class.ant-space-rtl]": `dir() === 'rtl'`, "[class.ant-space-horizontal]": "nzDirection === \"horizontal\"", "[class.ant-space-vertical]": "nzDirection === \"vertical\"", "[class.ant-space-align-start]": "mergedAlign === \"start\"", "[class.ant-space-align-end]": "mergedAlign === \"end\"", "[class.ant-space-align-center]": "mergedAlign === \"center\"", "[class.ant-space-align-baseline]": "mergedAlign === \"baseline\"", "[style.flex-wrap]": "nzWrap ? \"wrap\" : null", "[style.column-gap.px]": "horizontalSize", "[style.row-gap.px]": "verticalSize" }, imports: [NgTemplateOutlet, NzStringTemplateOutletDirective] }] }], ctorParameters: () => [], propDecorators: { nzDirection: [{ type: Input }], nzAlign: [{ type: Input }], nzSplit: [{ type: Input }], nzWrap: [{ type: Input, args: [{ transform: booleanAttribute }] }], nzSize: [{ type: Input }], items: [{ type: ContentChildren, args: [NzSpaceItemDirective, { read: TemplateRef }] }] } }); function normalizeSpaceSize(size) { const [horizontalSize, verticalSize] = (Array.isArray(size) ? size : [size, size]).map((s) => typeof s === "number" ? s : SPACE_SIZE[s]); return { horizontalSize, verticalSize }; } var NzSpaceModule = class NzSpaceModule { static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzSpaceModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "22.2.2", ngImport: i0, type: NzSpaceModule, imports: [ NzSpaceComponent, NzSpaceItemDirective, NzSpaceCompactComponent ], exports: [ NzSpaceComponent, NzSpaceItemDirective, NzSpaceCompactComponent ] }); static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzSpaceModule }); }; i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.2", ngImport: i0, type: NzSpaceModule, decorators: [{ type: NgModule, args: [{ imports: [ NzSpaceComponent, NzSpaceItemDirective, NzSpaceCompactComponent ], exports: [ NzSpaceComponent, NzSpaceItemDirective, NzSpaceCompactComponent ] }] }] }); export { NZ_SPACE_COMPACT_ITEMS, NZ_SPACE_COMPACT_ITEM_TYPE, NZ_SPACE_COMPACT_SIZE, NzSpaceCompactComponent, NzSpaceCompactItemDirective, NzSpaceComponent, NzSpaceItemDirective, NzSpaceModule }; //# sourceMappingURL=ng-zorro-antd-space.mjs.map