ng-zorro-antd-grid.mjs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. import * as i0 from '@angular/core';
  2. import { Input, Directive, inject, NgModule } from '@angular/core';
  3. import { ReplaySubject, Subject } from 'rxjs';
  4. import { takeUntil } from 'rxjs/operators';
  5. import * as i3 from 'ng-zorro-antd/core/services';
  6. import { gridResponsiveMap } from 'ng-zorro-antd/core/services';
  7. import * as i1 from '@angular/cdk/layout';
  8. import * as i2 from '@angular/cdk/platform';
  9. import * as i4 from '@angular/cdk/bidi';
  10. import { isNotNil } from 'ng-zorro-antd/core/util';
  11. class NzRowDirective {
  12. elementRef;
  13. renderer;
  14. mediaMatcher;
  15. ngZone;
  16. platform;
  17. breakpointService;
  18. directionality;
  19. nzAlign = null;
  20. nzJustify = null;
  21. nzGutter = null;
  22. actualGutter$ = new ReplaySubject(1);
  23. dir = 'ltr';
  24. destroy$ = new Subject();
  25. getGutter() {
  26. const results = [null, null];
  27. const gutter = this.nzGutter || 0;
  28. const normalizedGutter = Array.isArray(gutter) ? gutter : [gutter, null];
  29. normalizedGutter.forEach((g, index) => {
  30. if (typeof g === 'object' && g !== null) {
  31. results[index] = null;
  32. Object.keys(gridResponsiveMap).map((screen) => {
  33. const bp = screen;
  34. if (this.mediaMatcher.matchMedia(gridResponsiveMap[bp]).matches && g[bp]) {
  35. results[index] = g[bp];
  36. }
  37. });
  38. }
  39. else {
  40. results[index] = Number(g) || null;
  41. }
  42. });
  43. return results;
  44. }
  45. setGutterStyle() {
  46. const [horizontalGutter, verticalGutter] = this.getGutter();
  47. this.actualGutter$.next([horizontalGutter, verticalGutter]);
  48. const renderGutter = (name, gutter) => {
  49. const nativeElement = this.elementRef.nativeElement;
  50. if (gutter !== null) {
  51. this.renderer.setStyle(nativeElement, name, `-${gutter / 2}px`);
  52. }
  53. };
  54. renderGutter('margin-left', horizontalGutter);
  55. renderGutter('margin-right', horizontalGutter);
  56. renderGutter('margin-top', verticalGutter);
  57. renderGutter('margin-bottom', verticalGutter);
  58. }
  59. constructor(elementRef, renderer, mediaMatcher, ngZone, platform, breakpointService, directionality) {
  60. this.elementRef = elementRef;
  61. this.renderer = renderer;
  62. this.mediaMatcher = mediaMatcher;
  63. this.ngZone = ngZone;
  64. this.platform = platform;
  65. this.breakpointService = breakpointService;
  66. this.directionality = directionality;
  67. }
  68. ngOnInit() {
  69. this.dir = this.directionality.value;
  70. this.directionality.change?.pipe(takeUntil(this.destroy$)).subscribe((direction) => {
  71. this.dir = direction;
  72. });
  73. this.setGutterStyle();
  74. }
  75. ngOnChanges(changes) {
  76. if (changes.nzGutter) {
  77. this.setGutterStyle();
  78. }
  79. }
  80. ngAfterViewInit() {
  81. if (this.platform.isBrowser) {
  82. this.breakpointService
  83. .subscribe(gridResponsiveMap)
  84. .pipe(takeUntil(this.destroy$))
  85. .subscribe(() => {
  86. this.setGutterStyle();
  87. });
  88. }
  89. }
  90. ngOnDestroy() {
  91. this.destroy$.next(true);
  92. this.destroy$.complete();
  93. }
  94. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzRowDirective, deps: [{ token: i0.ElementRef }, { token: i0.Renderer2 }, { token: i1.MediaMatcher }, { token: i0.NgZone }, { token: i2.Platform }, { token: i3.NzBreakpointService }, { token: i4.Directionality }], target: i0.ɵɵFactoryTarget.Directive });
  95. static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.2", type: NzRowDirective, isStandalone: true, selector: "[nz-row],nz-row,nz-form-item", inputs: { nzAlign: "nzAlign", nzJustify: "nzJustify", nzGutter: "nzGutter" }, host: { properties: { "class.ant-row-top": "nzAlign === 'top'", "class.ant-row-middle": "nzAlign === 'middle'", "class.ant-row-bottom": "nzAlign === 'bottom'", "class.ant-row-start": "nzJustify === 'start'", "class.ant-row-end": "nzJustify === 'end'", "class.ant-row-center": "nzJustify === 'center'", "class.ant-row-space-around": "nzJustify === 'space-around'", "class.ant-row-space-between": "nzJustify === 'space-between'", "class.ant-row-space-evenly": "nzJustify === 'space-evenly'", "class.ant-row-rtl": "dir === \"rtl\"" }, classAttribute: "ant-row" }, exportAs: ["nzRow"], usesOnChanges: true, ngImport: i0 });
  96. }
  97. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzRowDirective, decorators: [{
  98. type: Directive,
  99. args: [{
  100. selector: '[nz-row],nz-row,nz-form-item',
  101. exportAs: 'nzRow',
  102. host: {
  103. class: 'ant-row',
  104. '[class.ant-row-top]': `nzAlign === 'top'`,
  105. '[class.ant-row-middle]': `nzAlign === 'middle'`,
  106. '[class.ant-row-bottom]': `nzAlign === 'bottom'`,
  107. '[class.ant-row-start]': `nzJustify === 'start'`,
  108. '[class.ant-row-end]': `nzJustify === 'end'`,
  109. '[class.ant-row-center]': `nzJustify === 'center'`,
  110. '[class.ant-row-space-around]': `nzJustify === 'space-around'`,
  111. '[class.ant-row-space-between]': `nzJustify === 'space-between'`,
  112. '[class.ant-row-space-evenly]': `nzJustify === 'space-evenly'`,
  113. '[class.ant-row-rtl]': `dir === "rtl"`
  114. }
  115. }]
  116. }], ctorParameters: () => [{ type: i0.ElementRef }, { type: i0.Renderer2 }, { type: i1.MediaMatcher }, { type: i0.NgZone }, { type: i2.Platform }, { type: i3.NzBreakpointService }, { type: i4.Directionality }], propDecorators: { nzAlign: [{
  117. type: Input
  118. }], nzJustify: [{
  119. type: Input
  120. }], nzGutter: [{
  121. type: Input
  122. }] } });
  123. class NzColDirective {
  124. elementRef;
  125. renderer;
  126. directionality;
  127. classMap = {};
  128. destroy$ = new Subject();
  129. hostFlexStyle = null;
  130. dir = 'ltr';
  131. nzFlex = null;
  132. nzSpan = null;
  133. nzOrder = null;
  134. nzOffset = null;
  135. nzPush = null;
  136. nzPull = null;
  137. nzXs = null;
  138. nzSm = null;
  139. nzMd = null;
  140. nzLg = null;
  141. nzXl = null;
  142. nzXXl = null;
  143. setHostClassMap() {
  144. const hostClassMap = {
  145. ['ant-col']: true,
  146. [`ant-col-${this.nzSpan}`]: isNotNil(this.nzSpan),
  147. [`ant-col-order-${this.nzOrder}`]: isNotNil(this.nzOrder),
  148. [`ant-col-offset-${this.nzOffset}`]: isNotNil(this.nzOffset),
  149. [`ant-col-pull-${this.nzPull}`]: isNotNil(this.nzPull),
  150. [`ant-col-push-${this.nzPush}`]: isNotNil(this.nzPush),
  151. ['ant-col-rtl']: this.dir === 'rtl',
  152. ...this.generateClass()
  153. };
  154. for (const i in this.classMap) {
  155. if (this.classMap.hasOwnProperty(i)) {
  156. this.renderer.removeClass(this.elementRef.nativeElement, i);
  157. }
  158. }
  159. this.classMap = { ...hostClassMap };
  160. for (const i in this.classMap) {
  161. if (this.classMap.hasOwnProperty(i) && this.classMap[i]) {
  162. this.renderer.addClass(this.elementRef.nativeElement, i);
  163. }
  164. }
  165. }
  166. setHostFlexStyle() {
  167. this.hostFlexStyle = this.parseFlex(this.nzFlex);
  168. }
  169. parseFlex(flex) {
  170. if (typeof flex === 'number') {
  171. return `${flex} ${flex} auto`;
  172. }
  173. else if (typeof flex === 'string') {
  174. if (/^\d+(\.\d+)?(px|em|rem|%)$/.test(flex)) {
  175. return `0 0 ${flex}`;
  176. }
  177. }
  178. return flex;
  179. }
  180. generateClass() {
  181. const listOfSizeInputName = ['nzXs', 'nzSm', 'nzMd', 'nzLg', 'nzXl', 'nzXXl'];
  182. const listClassMap = {};
  183. listOfSizeInputName.forEach(name => {
  184. const sizeName = name.replace('nz', '').toLowerCase();
  185. if (isNotNil(this[name])) {
  186. if (typeof this[name] === 'number' || typeof this[name] === 'string') {
  187. listClassMap[`ant-col-${sizeName}-${this[name]}`] = true;
  188. }
  189. else {
  190. const embedded = this[name];
  191. const prefixArray = ['span', 'pull', 'push', 'offset', 'order'];
  192. prefixArray.forEach(prefix => {
  193. const prefixClass = prefix === 'span' ? '-' : `-${prefix}-`;
  194. listClassMap[`ant-col-${sizeName}${prefixClass}${embedded[prefix]}`] =
  195. embedded && isNotNil(embedded[prefix]);
  196. });
  197. }
  198. }
  199. });
  200. return listClassMap;
  201. }
  202. nzRowDirective = inject(NzRowDirective, { host: true, optional: true });
  203. constructor(elementRef, renderer, directionality) {
  204. this.elementRef = elementRef;
  205. this.renderer = renderer;
  206. this.directionality = directionality;
  207. }
  208. ngOnInit() {
  209. this.dir = this.directionality.value;
  210. this.directionality.change?.pipe(takeUntil(this.destroy$)).subscribe((direction) => {
  211. this.dir = direction;
  212. this.setHostClassMap();
  213. });
  214. this.setHostClassMap();
  215. this.setHostFlexStyle();
  216. }
  217. ngOnChanges(changes) {
  218. this.setHostClassMap();
  219. const { nzFlex } = changes;
  220. if (nzFlex) {
  221. this.setHostFlexStyle();
  222. }
  223. }
  224. ngAfterViewInit() {
  225. if (this.nzRowDirective) {
  226. this.nzRowDirective.actualGutter$
  227. .pipe(takeUntil(this.destroy$))
  228. .subscribe(([horizontalGutter, verticalGutter]) => {
  229. const renderGutter = (name, gutter) => {
  230. const nativeElement = this.elementRef.nativeElement;
  231. if (gutter !== null) {
  232. this.renderer.setStyle(nativeElement, name, `${gutter / 2}px`);
  233. }
  234. };
  235. renderGutter('padding-left', horizontalGutter);
  236. renderGutter('padding-right', horizontalGutter);
  237. renderGutter('padding-top', verticalGutter);
  238. renderGutter('padding-bottom', verticalGutter);
  239. });
  240. }
  241. }
  242. ngOnDestroy() {
  243. this.destroy$.next(true);
  244. this.destroy$.complete();
  245. }
  246. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzColDirective, deps: [{ token: i0.ElementRef }, { token: i0.Renderer2 }, { token: i4.Directionality }], target: i0.ɵɵFactoryTarget.Directive });
  247. static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.2", type: NzColDirective, isStandalone: true, selector: "[nz-col],nz-col,nz-form-control,nz-form-label", inputs: { nzFlex: "nzFlex", nzSpan: "nzSpan", nzOrder: "nzOrder", nzOffset: "nzOffset", nzPush: "nzPush", nzPull: "nzPull", nzXs: "nzXs", nzSm: "nzSm", nzMd: "nzMd", nzLg: "nzLg", nzXl: "nzXl", nzXXl: "nzXXl" }, host: { properties: { "style.flex": "hostFlexStyle" } }, exportAs: ["nzCol"], usesOnChanges: true, ngImport: i0 });
  248. }
  249. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzColDirective, decorators: [{
  250. type: Directive,
  251. args: [{
  252. selector: '[nz-col],nz-col,nz-form-control,nz-form-label',
  253. exportAs: 'nzCol',
  254. host: {
  255. '[style.flex]': 'hostFlexStyle'
  256. }
  257. }]
  258. }], ctorParameters: () => [{ type: i0.ElementRef }, { type: i0.Renderer2 }, { type: i4.Directionality }], propDecorators: { nzFlex: [{
  259. type: Input
  260. }], nzSpan: [{
  261. type: Input
  262. }], nzOrder: [{
  263. type: Input
  264. }], nzOffset: [{
  265. type: Input
  266. }], nzPush: [{
  267. type: Input
  268. }], nzPull: [{
  269. type: Input
  270. }], nzXs: [{
  271. type: Input
  272. }], nzSm: [{
  273. type: Input
  274. }], nzMd: [{
  275. type: Input
  276. }], nzLg: [{
  277. type: Input
  278. }], nzXl: [{
  279. type: Input
  280. }], nzXXl: [{
  281. type: Input
  282. }] } });
  283. /**
  284. * Use of this source code is governed by an MIT-style license that can be
  285. * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
  286. */
  287. class NzGridModule {
  288. static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzGridModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
  289. static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.2.2", ngImport: i0, type: NzGridModule, imports: [NzColDirective, NzRowDirective], exports: [NzColDirective, NzRowDirective] });
  290. static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzGridModule });
  291. }
  292. i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.2", ngImport: i0, type: NzGridModule, decorators: [{
  293. type: NgModule,
  294. args: [{
  295. imports: [NzColDirective, NzRowDirective],
  296. exports: [NzColDirective, NzRowDirective]
  297. }]
  298. }] });
  299. /**
  300. * Use of this source code is governed by an MIT-style license that can be
  301. * found in the LICENSE file at https://github.com/NG-ZORRO/ng-zorro-antd/blob/master/LICENSE
  302. */
  303. /**
  304. * Generated bundle index. Do not edit.
  305. */
  306. export { NzColDirective, NzGridModule, NzRowDirective };
  307. //# sourceMappingURL=ng-zorro-antd-grid.mjs.map