@shival99/z-ui 1.0.15 → 1.0.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,9 @@
1
+ import { ZFormatNumExcelOptions } from '@shival99/z-ui/utils';
2
+ import * as i0 from '@angular/core';
3
+ import { InjectionToken } from '@angular/core';
1
4
  import { HttpHeaders, HttpContext, HttpParams, HttpClient } from '@angular/common/http';
2
5
  import { Router } from '@angular/router';
3
6
  import { Observable } from 'rxjs';
4
- import * as i0 from '@angular/core';
5
- import { InjectionToken } from '@angular/core';
6
7
  import { TranslationObject, TranslateService } from '@ngx-translate/core';
7
8
 
8
9
  interface ZCacheEntry<T = unknown> {
@@ -67,6 +68,182 @@ declare class ZCacheService {
67
68
  static keys(): string[];
68
69
  }
69
70
 
71
+ type ZExcelAlign = 'left' | 'center' | 'right';
72
+ interface ZExcelTableColumnConfig<T = unknown> {
73
+ id: string;
74
+ visible?: boolean | (() => boolean);
75
+ accessorKey?: keyof T & string;
76
+ accessorFn?: (row: T) => unknown;
77
+ header?: string | {
78
+ content?: string | (() => string);
79
+ align?: ZExcelAlign;
80
+ };
81
+ size?: number;
82
+ columns?: ZExcelTableColumnConfig<T>[];
83
+ }
84
+ interface ZExcelTableHeaderConfig {
85
+ content?: string | (() => string);
86
+ class?: string;
87
+ style?: Record<string, string>;
88
+ align?: string;
89
+ tooltip?: string | object;
90
+ rowSpan?: number;
91
+ colSpan?: number;
92
+ }
93
+ interface ZExcelCell {
94
+ value: unknown;
95
+ font?: {
96
+ name?: string;
97
+ size?: number;
98
+ bold?: boolean;
99
+ italic?: boolean;
100
+ color?: {
101
+ argb?: string;
102
+ };
103
+ };
104
+ fill?: {
105
+ type?: string;
106
+ pattern?: string;
107
+ fgColor?: {
108
+ argb?: string;
109
+ };
110
+ };
111
+ alignment?: {
112
+ horizontal?: 'left' | 'center' | 'right';
113
+ vertical?: 'top' | 'middle' | 'bottom';
114
+ wrapText?: boolean;
115
+ };
116
+ border?: {
117
+ top?: {
118
+ style?: string;
119
+ };
120
+ left?: {
121
+ style?: string;
122
+ };
123
+ bottom?: {
124
+ style?: string;
125
+ };
126
+ right?: {
127
+ style?: string;
128
+ };
129
+ };
130
+ note?: string;
131
+ numFmt?: string;
132
+ }
133
+ interface ZExcelCellContext<T> {
134
+ row: T;
135
+ rowIndex: number;
136
+ data: T[];
137
+ cell: ZExcelCell;
138
+ }
139
+ interface ZExcelHeaderContext {
140
+ colIndex: number;
141
+ cell: ZExcelCell;
142
+ }
143
+ interface ZExcelColumnConfig<T = unknown> {
144
+ id: string;
145
+ header?: string;
146
+ accessorKey?: keyof T & string;
147
+ accessorFn?: (row: T, rowIndex: number, data: T[]) => unknown;
148
+ width?: number;
149
+ autoFit?: boolean;
150
+ align?: ZExcelAlign;
151
+ headerAlign?: ZExcelAlign;
152
+ rowSpan?: number | ((row: T, rowIndex: number, data: T[]) => number);
153
+ colSpan?: number | ((row: T, rowIndex: number, data: T[]) => number);
154
+ headerRowSpan?: number;
155
+ headerColSpan?: number;
156
+ format?: (context: ZExcelCellContext<T>) => void;
157
+ formatNum?: ZFormatNumExcelOptions;
158
+ formatHeader?: (cell: ZExcelCell) => void;
159
+ note?: (row: T, rowIndex: number, data: T[]) => string | undefined;
160
+ columns?: ZExcelColumnConfig<T>[];
161
+ visible?: boolean;
162
+ }
163
+ interface ZExcelSheetSource<T = unknown> {
164
+ sheetName?: string;
165
+ data: T[];
166
+ }
167
+ interface ZExcelConfig<T = unknown> {
168
+ fileName?: string;
169
+ columns: ZExcelColumnConfig<T>[];
170
+ source: ZExcelSheetSource<T>[];
171
+ }
172
+ interface ZExcelToastHandler {
173
+ success?: (message: string) => void;
174
+ error?: (message: string) => void;
175
+ }
176
+ interface ZExcelExportOptions {
177
+ addTimestamp?: boolean;
178
+ showNotification?: boolean;
179
+ /**
180
+ * Optional toast handler for showing success/error notifications.
181
+ * If not provided, no notifications will be shown.
182
+ */
183
+ toast?: ZExcelToastHandler;
184
+ }
185
+ interface ZExcelExportResult {
186
+ buffer: ArrayBuffer;
187
+ fileName: string;
188
+ }
189
+ interface ZExcelFontConfig {
190
+ name: string;
191
+ size: number;
192
+ bold?: boolean;
193
+ }
194
+ interface ZExcelHeaderColors {
195
+ level0: string;
196
+ level1: string;
197
+ [key: string]: string;
198
+ }
199
+ interface ZExcelDefaultConfig {
200
+ font: ZExcelFontConfig;
201
+ headerFont: ZExcelFontConfig;
202
+ headerColors: ZExcelHeaderColors;
203
+ }
204
+ type ZTableToExcelColumn<T> = Omit<ZExcelColumnConfig<T>, 'header'> & {
205
+ header?: string | ((col: ZExcelTableColumnConfig<T>) => string);
206
+ };
207
+ interface ZExcelFromTableConfig<T = unknown> {
208
+ fileName?: string;
209
+ tableColumns: ZExcelTableColumnConfig<T>[];
210
+ excelOverrides?: Partial<Record<string, Partial<ZExcelColumnConfig<T>>>>;
211
+ source: ZExcelSheetSource<T>[];
212
+ excludeColumns?: string[];
213
+ headerResolver?: (col: ZExcelTableColumnConfig<T>) => string;
214
+ }
215
+
216
+ declare class ZExcelService {
217
+ private static _isHeaderConfig;
218
+ private static _getHeaderConfig;
219
+ exportExcel<T = unknown>(config: ZExcelConfig<T>, options?: ZExcelExportOptions): Promise<void>;
220
+ exportFromTable<T = unknown>(config: ZExcelFromTableConfig<T>, options?: ZExcelExportOptions): Promise<void>;
221
+ exportFromElement(elementId: string, fileName?: string, options?: ZExcelExportOptions): Promise<void>;
222
+ exportFromElementXlsx(elementId: string, fileName?: string, options?: ZExcelExportOptions): Promise<void>;
223
+ static exportExcelStatic<T = unknown>(config: ZExcelConfig<T>): Promise<ZExcelExportResult>;
224
+ static exportFromElementStatic(elementId: string, fileName?: string): Promise<ZExcelExportResult>;
225
+ private _saveFile;
226
+ private _convertTableColumnsToExcel;
227
+ private static _flattenColumns;
228
+ private static _calculateHeaderLevels;
229
+ private static _createHeaderRows;
230
+ private static _buildHeaderStructure;
231
+ private static _getLeafCount;
232
+ private static _getCellValue;
233
+ private static _processMergeRegions;
234
+ private static _applyAutoFitWidth;
235
+ private static _applyAutoFitWidthForTable;
236
+ private static _calculateCellWidth;
237
+ private static _processTableElement;
238
+ private static _parseContentValue;
239
+ private static _applyCellFormatFromHTML;
240
+ private static _getExcelAlignment;
241
+ private static _getExcelVerticalAlignment;
242
+ private static _formatTimestamp;
243
+ static ɵfac: i0.ɵɵFactoryDeclaration<ZExcelService, never>;
244
+ static ɵprov: i0.ɵɵInjectableDeclaration<ZExcelService>;
245
+ }
246
+
70
247
  type ZHttpParamsType<T> = {
71
248
  [K in keyof T]: string | number | boolean | ReadonlyArray<string | number | boolean>;
72
249
  };
@@ -397,6 +574,62 @@ declare class ZThemeService {
397
574
  static ɵprov: i0.ɵɵInjectableDeclaration<ZThemeService>;
398
575
  }
399
576
 
577
+ declare const Z_EXCEL_COLORS: {
578
+ readonly 'green-50': "FFF0FDF4";
579
+ readonly 'green-100': "FFDCFCE7";
580
+ readonly 'green-200': "FFBBF7D0";
581
+ readonly 'green-300': "FF86EFAC";
582
+ readonly 'green-400': "FF4ADE80";
583
+ readonly 'green-500': "FF22C55E";
584
+ readonly 'blue-50': "FFEFF6FF";
585
+ readonly 'blue-100': "FFDBEAFE";
586
+ readonly 'blue-200': "FFBFDBFE";
587
+ readonly 'blue-300': "FF93C5FD";
588
+ readonly 'blue-400': "FF60A5FA";
589
+ readonly 'blue-500': "FF3B82F6";
590
+ readonly 'gray-50': "FFF9FAFB";
591
+ readonly 'gray-100': "FFF3F4F6";
592
+ readonly 'gray-200': "FFE5E7EB";
593
+ readonly 'gray-300': "FFD1D5DB";
594
+ readonly 'gray-400': "FF9CA3AF";
595
+ readonly 'gray-500': "FF6B7280";
596
+ readonly 'yellow-50': "FFFFFBEB";
597
+ readonly 'yellow-100': "FFFEF3C7";
598
+ readonly 'yellow-200': "FFFDE68A";
599
+ readonly 'yellow-300': "FFFCD34D";
600
+ readonly 'red-50': "FFFEF2F2";
601
+ readonly 'red-100': "FFFEE2E2";
602
+ readonly 'red-200': "FFFECACA";
603
+ readonly 'red-300': "FFFCA5A5";
604
+ readonly white: "FFFFFFFF";
605
+ readonly black: "FF000000";
606
+ readonly transparent: "00000000";
607
+ };
608
+ declare const Z_EXCEL_DEFAULT_CONFIG: ZExcelDefaultConfig;
609
+ declare const Z_EXCEL_BORDER_THIN: {
610
+ top: {
611
+ style: "thin";
612
+ };
613
+ left: {
614
+ style: "thin";
615
+ };
616
+ bottom: {
617
+ style: "thin";
618
+ };
619
+ right: {
620
+ style: "thin";
621
+ };
622
+ };
623
+ declare const Z_EXCEL_CHAR_WIDTH_MAP: Record<string, number>;
624
+ declare const Z_EXCEL_FONT_MULTIPLIERS: Record<string, number>;
625
+ declare const Z_EXCEL_WIDTH_LIMITS: {
626
+ min: number;
627
+ max: number;
628
+ tableMin: number;
629
+ tableMax: number;
630
+ default: number;
631
+ };
632
+
400
633
  interface ZTranslateConfig {
401
634
  /** Default language */
402
635
  defaultLang?: string;
@@ -412,5 +645,5 @@ interface ZTranslateI18nConfig {
412
645
  availableLangs?: string[];
413
646
  }
414
647
 
415
- export { ZCacheService, ZHttpAbstractService, ZIndexDbService, ZSubjectService, ZThemeService, ZTranslateService, Z_DARK_MODE_CACHE_KEY, Z_DEFAULT_THEME, Z_THEME_CACHE_KEY, Z_THEME_CONFIG, Z_THEME_CSS_MAP };
416
- export type { ZCacheConfig, ZCacheEntry, ZHttpBaseOptions, ZHttpCacheEntry, ZHttpConfig, ZHttpContentType, ZHttpError, ZHttpNetworkCheck, ZHttpOptions, ZHttpParamsType, ZIndexDbConfig, ZIndexDbStoreConfig, ZThemeConfig, ZThemeName, ZTranslateConfig, ZTranslateI18nConfig };
648
+ export { ZCacheService, ZExcelService, ZHttpAbstractService, ZIndexDbService, ZSubjectService, ZThemeService, ZTranslateService, Z_DARK_MODE_CACHE_KEY, Z_DEFAULT_THEME, Z_EXCEL_BORDER_THIN, Z_EXCEL_CHAR_WIDTH_MAP, Z_EXCEL_COLORS, Z_EXCEL_DEFAULT_CONFIG, Z_EXCEL_FONT_MULTIPLIERS, Z_EXCEL_WIDTH_LIMITS, Z_THEME_CACHE_KEY, Z_THEME_CONFIG, Z_THEME_CSS_MAP };
649
+ export type { ZCacheConfig, ZCacheEntry, ZExcelAlign, ZExcelCell, ZExcelCellContext, ZExcelColumnConfig, ZExcelConfig, ZExcelDefaultConfig, ZExcelExportOptions, ZExcelExportResult, ZExcelFontConfig, ZExcelFromTableConfig, ZExcelHeaderColors, ZExcelHeaderContext, ZExcelSheetSource, ZExcelTableColumnConfig, ZExcelTableHeaderConfig, ZExcelToastHandler, ZHttpBaseOptions, ZHttpCacheEntry, ZHttpConfig, ZHttpContentType, ZHttpError, ZHttpNetworkCheck, ZHttpOptions, ZHttpParamsType, ZIndexDbConfig, ZIndexDbStoreConfig, ZTableToExcelColumn, ZThemeConfig, ZThemeName, ZTranslateConfig, ZTranslateI18nConfig };
@@ -1,5 +1,6 @@
1
1
  import { WritableSignal } from '@angular/core';
2
2
  import { ClassValue } from 'clsx';
3
+ import * as ExcelJS from 'exceljs';
3
4
  import { Observable } from 'rxjs';
4
5
  import { FormGroup, FormArray } from '@angular/forms';
5
6
 
@@ -33,20 +34,28 @@ interface ZFormatNumOptions {
33
34
  locale?: 'vi' | 'en';
34
35
  placeholder?: string;
35
36
  }
37
+ declare const Z_EXCEL_NUMBER_FORMAT_MAP: Record<string, string>;
38
+ interface ZFormatNumExcelOptions {
39
+ divide?: ZNumberDivide;
40
+ format?: string;
41
+ percent?: boolean;
42
+ emptyCheck?: ZEmptyCheck;
43
+ }
36
44
  declare global {
37
45
  interface Navigator {
38
46
  userAgentData?: ZNavigatorUAData;
39
47
  }
40
48
  }
49
+ type ZCapitalizeType = 'all' | 'sentence' | 'first';
41
50
 
42
51
  declare const zMergeClasses: (...inputs: ClassValue[]) => string;
43
52
  declare const zTransform: (value: boolean | string) => boolean;
44
53
  declare const zGenerateId: (prefix?: string) => string;
45
54
  declare const zNoop: () => undefined;
46
55
  declare const zFormatNum: (value: unknown, options?: ZFormatNumOptions) => string;
56
+ declare const zFormatNumExcel: (cell: ExcelJS.Cell | undefined, value: unknown, options?: ZFormatNumExcelOptions) => number | undefined;
47
57
  declare const zUuid: () => string;
48
- declare const zCapitalCase: (text: string) => string;
49
- declare const zIsTextTruncated: (el: HTMLElement) => Promise<boolean>;
58
+ declare const zCapitalCase: (text: string, type?: ZCapitalizeType) => string;
50
59
  declare const zDecodeUnicode: (str: string) => string;
51
60
  declare const zRandomColor: () => {
52
61
  hex: string;
@@ -106,5 +115,5 @@ interface ZFormDebugOptions {
106
115
  logLevel?: 'error' | 'warn' | 'log';
107
116
  }
108
117
 
109
- export { VIETNAMESE_MAP, Z_DIVIDE_SCALE, Z_LOCALE_MAP, debugFormInvalid, submitForm, zCapitalCase, zCleanObject, zConvertColorToArgb, zDebugFormInvalid, zDecodeUnicode, zDetectBrowser, zFormatNum, zGenerateId, zIsTextTruncated, zMergeClasses, zMiniSearch, zMiniSearch$, zNoop, zRandomColor, zRegisterEchartsTheme, zRemoveVietnamese, zSubmitForm, zTransform, zTreeBuild, zTreeFlatten, zUuid };
110
- export type { ZBrowserInfo, ZBrowserName, ZDeviceType, ZEchartsThemeOptions, ZEmptyCheck, ZFormDebugOptions, ZFormSubmitResult, ZFormatNumOptions, ZNavigatorUABrandVersion, ZNavigatorUAData, ZNumberDivide };
118
+ export { VIETNAMESE_MAP, Z_DIVIDE_SCALE, Z_EXCEL_NUMBER_FORMAT_MAP, Z_LOCALE_MAP, debugFormInvalid, submitForm, zCapitalCase, zCleanObject, zConvertColorToArgb, zDebugFormInvalid, zDecodeUnicode, zDetectBrowser, zFormatNum, zFormatNumExcel, zGenerateId, zMergeClasses, zMiniSearch, zMiniSearch$, zNoop, zRandomColor, zRegisterEchartsTheme, zRemoveVietnamese, zSubmitForm, zTransform, zTreeBuild, zTreeFlatten, zUuid };
119
+ export type { ZBrowserInfo, ZBrowserName, ZCapitalizeType, ZDeviceType, ZEchartsThemeOptions, ZEmptyCheck, ZFormDebugOptions, ZFormSubmitResult, ZFormatNumExcelOptions, ZFormatNumOptions, ZNavigatorUABrandVersion, ZNavigatorUAData, ZNumberDivide };