ng-zorro-antd-space.mjs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. import { Directionality } from '@angular/cdk/bidi';
  2. import * as i0 from '@angular/core';
  3. import { InjectionToken, input, booleanAttribute, inject, ElementRef, signal, ChangeDetectionStrategy, Component, computed, afterNextRender, Directive, TemplateRef, ContentChildren, Input, NgModule } from '@angular/core';
  4. import { toSignal } from '@angular/core/rxjs-interop';
  5. import { __esDecorate, __runInitializers } from 'tslib';
  6. import { NgTemplateOutlet } from '@angular/common';
  7. import { Subject } from 'rxjs';
  8. import { takeUntil } from 'rxjs/operators';
  9. import * as i1 from 'ng-zorro-antd/core/config';
  10. import { WithConfig } from 'ng-zorro-antd/core/config';
  11. import { NzStringTemplateOutletDirective } from 'ng-zorro-antd/core/outlet';
  12. /**
  13. * Use of this source code is governed by an MIT-style license that can be
  14. * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
  15. */
  16. const NZ_SPACE_COMPACT_SIZE = new InjectionToken('NZ_SPACE_COMPACT_SIZE');
  17. const NZ_SPACE_COMPACT_ITEMS = new InjectionToken('NZ_SPACE_COMPACT_ITEMS');
  18. const NZ_SPACE_COMPACT_ITEM_TYPE = new InjectionToken('NZ_SPACE_COMPACT_ITEM_TYPE');
  19. /**
  20. * Use of this source code is governed by an MIT-style license that can be
  21. * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
  22. */
  23. class NzSpaceCompactComponent {
  24. nzBlock = input(false, { transform: booleanAttribute });
  25. nzDirection = input('horizontal');
  26. nzSize = input('default');
  27. elementRef = inject(ElementRef);
  28. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzSpaceCompactComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
  29. static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "19.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-block": "nzBlock()", "class.ant-space-compact-vertical": "nzDirection() === 'vertical'" }, classAttribute: "ant-space-compact" }, providers: [
  30. { provide: NZ_SPACE_COMPACT_SIZE, useFactory: () => inject(NzSpaceCompactComponent).nzSize },
  31. { provide: NZ_SPACE_COMPACT_ITEMS, useFactory: () => signal([]) }
  32. ], exportAs: ["nzSpaceCompact"], ngImport: i0, template: `<ng-content></ng-content>`, isInline: true, changeDetection: i0.ChangeDetectionStrategy.OnPush });
  33. }
  34. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzSpaceCompactComponent, decorators: [{
  35. type: Component,
  36. args: [{
  37. selector: 'nz-space-compact',
  38. exportAs: 'nzSpaceCompact',
  39. template: `<ng-content></ng-content>`,
  40. host: {
  41. class: 'ant-space-compact',
  42. '[class.ant-space-compact-block]': `nzBlock()`,
  43. '[class.ant-space-compact-vertical]': `nzDirection() === 'vertical'`
  44. },
  45. providers: [
  46. { provide: NZ_SPACE_COMPACT_SIZE, useFactory: () => inject(NzSpaceCompactComponent).nzSize },
  47. { provide: NZ_SPACE_COMPACT_ITEMS, useFactory: () => signal([]) }
  48. ],
  49. changeDetection: ChangeDetectionStrategy.OnPush
  50. }]
  51. }] });
  52. /**
  53. * Use of this source code is governed by an MIT-style license that can be
  54. * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
  55. */
  56. class NzSpaceCompactItemDirective {
  57. /**
  58. * Ancestor component injected from the parent.
  59. * Note that it is not necessarily the direct parent component.
  60. */
  61. spaceCompactCmp = inject(NzSpaceCompactComponent, { host: true, optional: true });
  62. items = inject(NZ_SPACE_COMPACT_ITEMS, { host: true, optional: true });
  63. type = inject(NZ_SPACE_COMPACT_ITEM_TYPE);
  64. elementRef = inject(ElementRef);
  65. directionality = inject(Directionality);
  66. dir = toSignal(this.directionality.change, { initialValue: this.directionality.value });
  67. get parentElement() {
  68. return this.elementRef.nativeElement?.parentElement;
  69. }
  70. class = computed(() => {
  71. // Only handle when the parent is space compact component
  72. if (!this.spaceCompactCmp || !this.items)
  73. return null;
  74. // Ensure that the injected ancestor component's elements are parent elements
  75. if (this.parentElement !== this.spaceCompactCmp.elementRef.nativeElement)
  76. return null;
  77. const items = this.items();
  78. const direction = this.spaceCompactCmp.nzDirection();
  79. const classes = [compactItemClassOf(this.type, direction, this.dir() === 'rtl')];
  80. const index = items.indexOf(this);
  81. const firstIndex = items.findIndex(element => element);
  82. // Array [empty, item]
  83. // In this case, the index of the first valid element is not 0,
  84. // so we need to use findIndex to find the index value of the first valid element.
  85. if (index === firstIndex) {
  86. classes.push(compactFirstItemClassOf(this.type, direction));
  87. }
  88. else if (index === items.length - 1) {
  89. classes.push(compactLastItemClassOf(this.type, direction));
  90. }
  91. return classes;
  92. });
  93. constructor() {
  94. if (!this.spaceCompactCmp || !this.items)
  95. return;
  96. afterNextRender(() => {
  97. // Ensure that the injected ancestor component's elements are parent elements
  98. if (this.parentElement === this.spaceCompactCmp.elementRef.nativeElement) {
  99. const index = Array.from(this.parentElement.children).indexOf(this.elementRef.nativeElement);
  100. this.items.update(value => {
  101. const newValue = value.slice();
  102. newValue.splice(index, 0, this);
  103. return newValue;
  104. });
  105. }
  106. });
  107. }
  108. ngOnDestroy() {
  109. this.items?.update(value => value.filter(o => o !== this));
  110. }
  111. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzSpaceCompactItemDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
  112. static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.2", type: NzSpaceCompactItemDirective, isStandalone: true, host: { properties: { "class": "class()" } }, exportAs: ["nzSpaceCompactItem"], ngImport: i0 });
  113. }
  114. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzSpaceCompactItemDirective, decorators: [{
  115. type: Directive,
  116. args: [{
  117. exportAs: 'nzSpaceCompactItem',
  118. host: {
  119. '[class]': 'class()'
  120. }
  121. }]
  122. }], ctorParameters: () => [] });
  123. function generateCompactClass(type, direction, position) {
  124. const directionPrefix = direction === 'vertical' ? 'vertical-' : '';
  125. return `ant-${type}-compact-${directionPrefix}${position}`;
  126. }
  127. function compactItemClassOf(type, direction, rtl) {
  128. const rtlSuffix = rtl ? '-rtl' : '';
  129. return `${generateCompactClass(type, direction, 'item')}${rtlSuffix}`;
  130. }
  131. function compactFirstItemClassOf(type, direction) {
  132. return generateCompactClass(type, direction, 'first-item');
  133. }
  134. function compactLastItemClassOf(type, direction) {
  135. return generateCompactClass(type, direction, 'last-item');
  136. }
  137. /**
  138. * Use of this source code is governed by an MIT-style license that can be
  139. * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
  140. */
  141. class NzSpaceItemDirective {
  142. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzSpaceItemDirective, deps: [], target: i0.ɵɵFactoryTarget.Directive });
  143. static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.2", type: NzSpaceItemDirective, isStandalone: true, selector: "[nzSpaceItem]", ngImport: i0 });
  144. }
  145. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzSpaceItemDirective, decorators: [{
  146. type: Directive,
  147. args: [{
  148. selector: '[nzSpaceItem]'
  149. }]
  150. }] });
  151. const NZ_CONFIG_MODULE_NAME = 'space';
  152. const SPACE_SIZE = {
  153. small: 8,
  154. middle: 16,
  155. large: 24
  156. };
  157. let NzSpaceComponent = (() => {
  158. let _nzSize_decorators;
  159. let _nzSize_initializers = [];
  160. let _nzSize_extraInitializers = [];
  161. return class NzSpaceComponent {
  162. static {
  163. const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
  164. _nzSize_decorators = [WithConfig()];
  165. __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);
  166. if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
  167. }
  168. nzConfigService;
  169. cdr;
  170. _nzModuleName = NZ_CONFIG_MODULE_NAME;
  171. nzDirection = 'horizontal';
  172. nzAlign;
  173. nzSplit = null;
  174. nzWrap = false;
  175. nzSize = __runInitializers(this, _nzSize_initializers, 'small');
  176. items = __runInitializers(this, _nzSize_extraInitializers);
  177. mergedAlign;
  178. spaceSize = SPACE_SIZE.small;
  179. destroy$ = new Subject();
  180. constructor(nzConfigService, cdr) {
  181. this.nzConfigService = nzConfigService;
  182. this.cdr = cdr;
  183. }
  184. updateSpaceItems() {
  185. const numberSize = typeof this.nzSize === 'string' ? SPACE_SIZE[this.nzSize] : this.nzSize;
  186. this.spaceSize = numberSize / (this.nzSplit ? 2 : 1);
  187. this.cdr.markForCheck();
  188. }
  189. ngOnChanges() {
  190. this.updateSpaceItems();
  191. this.mergedAlign = this.nzAlign === undefined && this.nzDirection === 'horizontal' ? 'center' : this.nzAlign;
  192. }
  193. ngOnDestroy() {
  194. this.destroy$.next(true);
  195. this.destroy$.complete();
  196. }
  197. ngAfterContentInit() {
  198. this.updateSpaceItems();
  199. this.items.changes.pipe(takeUntil(this.destroy$)).subscribe(() => {
  200. this.cdr.markForCheck();
  201. });
  202. }
  203. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzSpaceComponent, deps: [{ token: i1.NzConfigService }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Component });
  204. static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.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-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" }, classAttribute: "ant-space" }, queries: [{ propertyName: "items", predicate: NzSpaceItemDirective, read: TemplateRef }], exportAs: ["nzSpace"], usesOnChanges: true, ngImport: i0, template: `
  205. <ng-content></ng-content>
  206. @for (item of items; track item; let last = $last; let index = $index) {
  207. <div
  208. class="ant-space-item"
  209. [style.margin-block-end.px]="nzDirection === 'vertical' ? (last ? null : spaceSize) : null"
  210. [style.margin-inline-end.px]="nzDirection === 'horizontal' ? (last ? null : spaceSize) : null"
  211. >
  212. <ng-container [ngTemplateOutlet]="item"></ng-container>
  213. </div>
  214. @if (nzSplit && !last) {
  215. <span
  216. class="ant-space-split"
  217. [style.margin-block-end.px]="nzDirection === 'vertical' ? (last ? null : spaceSize) : null"
  218. [style.margin-inline-end.px]="nzDirection === 'horizontal' ? (last ? null : spaceSize) : null"
  219. >
  220. <ng-template [nzStringTemplateOutlet]="nzSplit" [nzStringTemplateOutletContext]="{ $implicit: index }">{{
  221. nzSplit
  222. }}</ng-template>
  223. </span>
  224. }
  225. }
  226. `, isInline: true, dependencies: [{ kind: "directive", type: NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet", "ngTemplateOutletInjector"] }, { kind: "directive", type: NzStringTemplateOutletDirective, selector: "[nzStringTemplateOutlet]", inputs: ["nzStringTemplateOutletContext", "nzStringTemplateOutlet"], exportAs: ["nzStringTemplateOutlet"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
  227. };
  228. })();
  229. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzSpaceComponent, decorators: [{
  230. type: Component,
  231. args: [{
  232. selector: 'nz-space, [nz-space]',
  233. exportAs: 'nzSpace',
  234. changeDetection: ChangeDetectionStrategy.OnPush,
  235. template: `
  236. <ng-content></ng-content>
  237. @for (item of items; track item; let last = $last; let index = $index) {
  238. <div
  239. class="ant-space-item"
  240. [style.margin-block-end.px]="nzDirection === 'vertical' ? (last ? null : spaceSize) : null"
  241. [style.margin-inline-end.px]="nzDirection === 'horizontal' ? (last ? null : spaceSize) : null"
  242. >
  243. <ng-container [ngTemplateOutlet]="item"></ng-container>
  244. </div>
  245. @if (nzSplit && !last) {
  246. <span
  247. class="ant-space-split"
  248. [style.margin-block-end.px]="nzDirection === 'vertical' ? (last ? null : spaceSize) : null"
  249. [style.margin-inline-end.px]="nzDirection === 'horizontal' ? (last ? null : spaceSize) : null"
  250. >
  251. <ng-template [nzStringTemplateOutlet]="nzSplit" [nzStringTemplateOutletContext]="{ $implicit: index }">{{
  252. nzSplit
  253. }}</ng-template>
  254. </span>
  255. }
  256. }
  257. `,
  258. host: {
  259. class: 'ant-space',
  260. '[class.ant-space-horizontal]': 'nzDirection === "horizontal"',
  261. '[class.ant-space-vertical]': 'nzDirection === "vertical"',
  262. '[class.ant-space-align-start]': 'mergedAlign === "start"',
  263. '[class.ant-space-align-end]': 'mergedAlign === "end"',
  264. '[class.ant-space-align-center]': 'mergedAlign === "center"',
  265. '[class.ant-space-align-baseline]': 'mergedAlign === "baseline"',
  266. '[style.flex-wrap]': 'nzWrap ? "wrap" : null'
  267. },
  268. imports: [NgTemplateOutlet, NzStringTemplateOutletDirective]
  269. }]
  270. }], ctorParameters: () => [{ type: i1.NzConfigService }, { type: i0.ChangeDetectorRef }], propDecorators: { nzDirection: [{
  271. type: Input
  272. }], nzAlign: [{
  273. type: Input
  274. }], nzSplit: [{
  275. type: Input
  276. }], nzWrap: [{
  277. type: Input,
  278. args: [{ transform: booleanAttribute }]
  279. }], nzSize: [{
  280. type: Input
  281. }], items: [{
  282. type: ContentChildren,
  283. args: [NzSpaceItemDirective, { read: TemplateRef }]
  284. }] } });
  285. /**
  286. * Use of this source code is governed by an MIT-style license that can be
  287. * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
  288. */
  289. class NzSpaceModule {
  290. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzSpaceModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
  291. static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.2.2", ngImport: i0, type: NzSpaceModule, imports: [NzSpaceComponent, NzSpaceItemDirective, NzSpaceCompactComponent], exports: [NzSpaceComponent, NzSpaceItemDirective, NzSpaceCompactComponent] });
  292. static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzSpaceModule });
  293. }
  294. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzSpaceModule, decorators: [{
  295. type: NgModule,
  296. args: [{
  297. imports: [NzSpaceComponent, NzSpaceItemDirective, NzSpaceCompactComponent],
  298. exports: [NzSpaceComponent, NzSpaceItemDirective, NzSpaceCompactComponent]
  299. }]
  300. }] });
  301. /**
  302. * Use of this source code is governed by an MIT-style license that can be
  303. * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
  304. */
  305. /**
  306. * Use of this source code is governed by an MIT-style license that can be
  307. * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
  308. */
  309. /**
  310. * Generated bundle index. Do not edit.
  311. */
  312. export { NZ_SPACE_COMPACT_ITEMS, NZ_SPACE_COMPACT_ITEM_TYPE, NZ_SPACE_COMPACT_SIZE, NzSpaceCompactComponent, NzSpaceCompactItemDirective, NzSpaceComponent, NzSpaceItemDirective, NzSpaceModule };
  313. //# sourceMappingURL=ng-zorro-antd-space.mjs.map