@slickgrid-universal/text-export 5.10.2 → 5.12.0

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slickgrid-universal/text-export",
3
- "version": "5.10.2",
3
+ "version": "5.12.0",
4
4
  "description": "Export to Text File (csv/txt) Service.",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "types": "./dist/types/index.d.ts",
@@ -38,13 +38,13 @@
38
38
  "not dead"
39
39
  ],
40
40
  "dependencies": {
41
- "@slickgrid-universal/common": "~5.10.2",
42
- "@slickgrid-universal/utils": "~5.10.2",
41
+ "@slickgrid-universal/common": "~5.12.0",
42
+ "@slickgrid-universal/utils": "~5.12.0",
43
43
  "text-encoding-utf-8": "^1.0.2"
44
44
  },
45
45
  "funding": {
46
46
  "type": "ko_fi",
47
47
  "url": "https://ko-fi.com/ghiscoding"
48
48
  },
49
- "gitHead": "61dcfac0074bedede5bed92faa49c2d42d551f4c"
49
+ "gitHead": "d7e892ebc1727d7c83cc1e5cc80db8302eef4f63"
50
50
  }
@@ -56,10 +56,10 @@ export class TextExportService implements ExternalResource, BaseTextExportServic
56
56
  /** ExcelExportService class name which is use to find service instance in the external registered services */
57
57
  readonly className = 'TextExportService';
58
58
 
59
- constructor() { }
59
+ constructor() {}
60
60
 
61
61
  protected get _datasetIdPropName(): string {
62
- return this._gridOptions && this._gridOptions.datasetIdPropertyName || 'id';
62
+ return (this._gridOptions && this._gridOptions.datasetIdPropertyName) || 'id';
63
63
  }
64
64
 
65
65
  /** Getter of SlickGrid DataView object */
@@ -69,7 +69,7 @@ export class TextExportService implements ExternalResource, BaseTextExportServic
69
69
 
70
70
  /** Getter for the Grid Options pulled through the Grid Object */
71
71
  protected get _gridOptions(): GridOption {
72
- return this._grid?.getOptions() ?? {} as GridOption;
72
+ return this._grid?.getOptions() ?? ({} as GridOption);
73
73
  }
74
74
 
75
75
  dispose(): void {
@@ -86,11 +86,13 @@ export class TextExportService implements ExternalResource, BaseTextExportServic
86
86
  this._pubSubService = containerService.get<PubSubService>('PubSubService');
87
87
 
88
88
  // get locales provided by user in main file or else use default English locales via the Constants
89
- this._locales = this._gridOptions && this._gridOptions.locales || Constants.locales;
89
+ this._locales = (this._gridOptions && this._gridOptions.locales) || Constants.locales;
90
90
  this._translaterService = this._gridOptions?.translater;
91
91
 
92
92
  if (this._gridOptions.enableTranslate && (!this._translaterService || !this._translaterService.translate)) {
93
- throw new Error('[Slickgrid-Universal] requires a Translate Service to be passed in the "translater" Grid Options when "enableTranslate" is enabled. (example: this.gridOptions = { enableTranslate: true, translater: this.translaterService })');
93
+ throw new Error(
94
+ '[Slickgrid-Universal] requires a Translate Service to be passed in the "translater" Grid Options when "enableTranslate" is enabled. (example: this.gridOptions = { enableTranslate: true, translater: this.translaterService })'
95
+ );
94
96
  }
95
97
  }
96
98
 
@@ -105,10 +107,12 @@ export class TextExportService implements ExternalResource, BaseTextExportServic
105
107
  */
106
108
  exportToFile(options?: TextExportOption): Promise<boolean> {
107
109
  if (!this._grid || !this._dataView || !this._pubSubService) {
108
- throw new Error('[Slickgrid-Universal] it seems that the SlickGrid & DataView objects and/or PubSubService are not initialized did you forget to enable the grid option flag "enableTextExport"?');
110
+ throw new Error(
111
+ '[Slickgrid-Universal] it seems that the SlickGrid & DataView objects and/or PubSubService are not initialized did you forget to enable the grid option flag "enableTextExport"?'
112
+ );
109
113
  }
110
114
 
111
- return new Promise(resolve => {
115
+ return new Promise((resolve) => {
112
116
  this._pubSubService?.publish(`onBeforeExportToTextFile`, true);
113
117
  this._exportOptions = extend(true, {}, { ...DEFAULT_EXPORT_OPTIONS, ...this._gridOptions.textExportOptions, ...options });
114
118
  this._delimiter = this._exportOptions.delimiterOverride || this._exportOptions.delimiter || '';
@@ -124,7 +128,8 @@ export class TextExportService implements ExternalResource, BaseTextExportServic
124
128
  filename: `${this._exportOptions.filename}.${this._fileFormat}`,
125
129
  format: this._fileFormat || FileType.csv,
126
130
  mimeType: this._exportOptions.mimeType || 'text/plain',
127
- useUtf8WithBom: (this._exportOptions && this._exportOptions.hasOwnProperty('useUtf8WithBom')) ? this._exportOptions.useUtf8WithBom : true
131
+ // prettier-ignore
132
+ useUtf8WithBom: (this._exportOptions && this._exportOptions.hasOwnProperty('useUtf8WithBom')) ? this._exportOptions.useUtf8WithBom : true,
128
133
  };
129
134
 
130
135
  // start downloading but add the content property only on the start download not on the event itself
@@ -158,7 +163,7 @@ export class TextExportService implements ExternalResource, BaseTextExportServic
158
163
 
159
164
  // create a Blob object for the download
160
165
  const blob = new Blob([options.useUtf8WithBom ? '\uFEFF' : '', outputData], {
161
- type: options.mimeType
166
+ type: options.mimeType,
162
167
  });
163
168
 
164
169
  // when using IE/Edge, then use different download call
@@ -193,14 +198,19 @@ export class TextExportService implements ExternalResource, BaseTextExportServic
193
198
 
194
199
  // Group By text, it could be set in the export options or from translation or if nothing is found then use the English constant text
195
200
  let groupByColumnHeader = this._exportOptions.groupingColumnHeaderTitle;
196
- if (!groupByColumnHeader && this._gridOptions.enableTranslate && this._translaterService?.translate && this._translaterService?.getCurrentLanguage?.()) {
201
+ if (
202
+ !groupByColumnHeader &&
203
+ this._gridOptions.enableTranslate &&
204
+ this._translaterService?.translate &&
205
+ this._translaterService?.getCurrentLanguage?.()
206
+ ) {
197
207
  groupByColumnHeader = this._translaterService.translate(`${getTranslationPrefix(this._gridOptions)}GROUP_BY`);
198
208
  } else if (!groupByColumnHeader) {
199
209
  groupByColumnHeader = this._locales && this._locales.TEXT_GROUP_BY;
200
210
  }
201
211
 
202
212
  // a CSV needs double quotes wrapper, the other types do not need any wrapper
203
- this._exportQuoteWrapper = (this._fileFormat === FileType.csv) ? '"' : '';
213
+ this._exportQuoteWrapper = this._fileFormat === FileType.csv ? '"' : '';
204
214
 
205
215
  // data variable which will hold all the fields data of a row
206
216
  let outputDataString = '';
@@ -210,7 +220,8 @@ export class TextExportService implements ExternalResource, BaseTextExportServic
210
220
  const grouping = this._dataView.getGrouping();
211
221
  if (grouping && Array.isArray(grouping) && grouping.length > 0) {
212
222
  this._hasGroupedItems = true;
213
- outputDataString += (this._fileFormat === FileType.csv) ? `"${groupByColumnHeader}"${this._delimiter}` : `${groupByColumnHeader}${this._delimiter}`;
223
+ outputDataString +=
224
+ this._fileFormat === FileType.csv ? `"${groupByColumnHeader}"${this._delimiter}` : `${groupByColumnHeader}${this._delimiter}`;
214
225
  } else {
215
226
  this._hasGroupedItems = false;
216
227
  }
@@ -220,8 +231,10 @@ export class TextExportService implements ExternalResource, BaseTextExportServic
220
231
  this._groupedColumnHeaders = this.getColumnGroupedHeaderTitles(columns) || [];
221
232
  if (this._groupedColumnHeaders && Array.isArray(this._groupedColumnHeaders) && this._groupedColumnHeaders.length > 0) {
222
233
  // add the header row + add a new line at the end of the row
223
- const outputGroupedHeaderTitles = this._groupedColumnHeaders.map((header) => `${this._exportQuoteWrapper}${header.title}${this._exportQuoteWrapper}`);
224
- outputDataString += (outputGroupedHeaderTitles.join(this._delimiter) + this._lineCarriageReturn);
234
+ const outputGroupedHeaderTitles = this._groupedColumnHeaders.map(
235
+ (header) => `${this._exportQuoteWrapper}${header.title}${this._exportQuoteWrapper}`
236
+ );
237
+ outputDataString += outputGroupedHeaderTitles.join(this._delimiter) + this._lineCarriageReturn;
225
238
  }
226
239
  }
227
240
 
@@ -229,8 +242,10 @@ export class TextExportService implements ExternalResource, BaseTextExportServic
229
242
  this._columnHeaders = this.getColumnHeaders(columns) || [];
230
243
  if (this._columnHeaders && Array.isArray(this._columnHeaders) && this._columnHeaders.length > 0) {
231
244
  // add the header row + add a new line at the end of the row
232
- const outputHeaderTitles = this._columnHeaders.map((header) => stripTags(`${this._exportQuoteWrapper}${header.title}${this._exportQuoteWrapper}`));
233
- outputDataString += (outputHeaderTitles.join(this._delimiter) + this._lineCarriageReturn);
245
+ const outputHeaderTitles = this._columnHeaders.map((header) =>
246
+ stripTags(`${this._exportQuoteWrapper}${header.title}${this._exportQuoteWrapper}`)
247
+ );
248
+ outputDataString += outputHeaderTitles.join(this._delimiter) + this._lineCarriageReturn;
234
249
  }
235
250
 
236
251
  // Populate the rest of the Grid Data
@@ -281,7 +296,12 @@ export class TextExportService implements ExternalResource, BaseTextExportServic
281
296
  // Populate the Grouped Column Header, pull the columnGroup(Key) defined
282
297
  columns.forEach((columnDef) => {
283
298
  let groupedHeaderTitle = '';
284
- if (columnDef.columnGroupKey && this._gridOptions.enableTranslate && this._translaterService?.translate && this._translaterService?.getCurrentLanguage?.()) {
299
+ if (
300
+ columnDef.columnGroupKey &&
301
+ this._gridOptions.enableTranslate &&
302
+ this._translaterService?.translate &&
303
+ this._translaterService?.getCurrentLanguage?.()
304
+ ) {
285
305
  groupedHeaderTitle = this._translaterService.translate(columnDef.columnGroupKey);
286
306
  } else {
287
307
  groupedHeaderTitle = columnDef.columnGroup || '';
@@ -292,7 +312,7 @@ export class TextExportService implements ExternalResource, BaseTextExportServic
292
312
  if ((columnDef.width === undefined || columnDef.width > 0) && !skippedField) {
293
313
  groupedColumnHeaders.push({
294
314
  key: (columnDef.field || columnDef.id) as string,
295
- title: groupedHeaderTitle || ''
315
+ title: groupedHeaderTitle || '',
296
316
  });
297
317
  }
298
318
  });
@@ -311,8 +331,13 @@ export class TextExportService implements ExternalResource, BaseTextExportServic
311
331
  // Populate the Column Header, pull the name defined
312
332
  columns.forEach((columnDef) => {
313
333
  let headerTitle = '';
314
- if ((columnDef.nameKey || columnDef.nameKey) && this._gridOptions.enableTranslate && this._translaterService?.translate && this._translaterService?.getCurrentLanguage?.()) {
315
- headerTitle = this._translaterService.translate((columnDef.nameKey || columnDef.nameKey));
334
+ if (
335
+ (columnDef.nameKey || columnDef.nameKey) &&
336
+ this._gridOptions.enableTranslate &&
337
+ this._translaterService?.translate &&
338
+ this._translaterService?.getCurrentLanguage?.()
339
+ ) {
340
+ headerTitle = this._translaterService.translate(columnDef.nameKey || columnDef.nameKey);
316
341
  } else {
317
342
  headerTitle = getHtmlStringOutput(columnDef.name || '', 'innerHTML') || titleCase(columnDef.field);
318
343
  }
@@ -322,7 +347,7 @@ export class TextExportService implements ExternalResource, BaseTextExportServic
322
347
  if ((columnDef.width === undefined || columnDef.width > 0) && !skippedField) {
323
348
  columnHeaders.push({
324
349
  key: (columnDef.field || columnDef.id) as string,
325
- title: headerTitle || ''
350
+ title: headerTitle || '',
326
351
  });
327
352
  }
328
353
  });
@@ -371,9 +396,9 @@ export class TextExportService implements ExternalResource, BaseTextExportServic
371
396
  }
372
397
  }
373
398
 
374
- if ((prevColspan === '*' && col > 0) || ((!isNaN(prevColspan as number) && +prevColspan > 1) && columnDef.id !== colspanColumnId)) {
399
+ if ((prevColspan === '*' && col > 0) || (!isNaN(prevColspan as number) && +prevColspan > 1 && columnDef.id !== colspanColumnId)) {
375
400
  rowOutputStrings.push('');
376
- if ((!isNaN(prevColspan as number) && +prevColspan > 1)) {
401
+ if (!isNaN(prevColspan as number) && +prevColspan > 1) {
377
402
  (prevColspan as number)--;
378
403
  }
379
404
  } else {